1 /*******************************************************************************
2 * Copyright (c) 2014 Ericsson
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * Vincent Perot - Initial API and implementation
11 *******************************************************************************/
13 package org
.eclipse
.linuxtools
.pcap
.core
.protocol
;
15 import java
.util
.ArrayList
;
16 import java
.util
.Arrays
;
17 import java
.util
.List
;
20 * Enumeration used for describing the different known protocols.
22 * @author Vincent Perot
24 public enum Protocol
{
28 * The Pcap Protocol is not a real protocol but is used as an helper to
29 * generate Pcap packets.
31 PCAP("Packet Capture", "pcap", ProtocolValues
.LAYER_0
, false), //$NON-NLS-1$ //$NON-NLS-2$
34 // Should always be empty.
38 * The description of the Ethernet II Protocol.
40 ETHERNET_II("Ethernet II", "eth", ProtocolValues
.LAYER_2
, true), //$NON-NLS-1$ //$NON-NLS-2$
44 * The description of the Internet Protocol Version 4.
46 IPV4("Internet Protocol Version 4", "ipv4", ProtocolValues
.LAYER_3
, true), //$NON-NLS-1$ //$NON-NLS-2$
50 * The description of the Transmission Control Protocol.
52 TCP("Transmission Control Protocol", "tcp", ProtocolValues
.LAYER_4
, true), //$NON-NLS-1$ //$NON-NLS-2$
54 * The description of the User Datagram Protocol.
56 UDP("User Datagram Protocol", "udp", ProtocolValues
.LAYER_4
, true), //$NON-NLS-1$ //$NON-NLS-2$
64 * This protocol is used as an helper if the protocol of a packet is not
65 * recognized. Since all its data goes into payload, it can also be seen as
66 * a "payload packet". This is considered to be on layer 7 since its always
67 * the most encapsulated packet if present.
69 UNKNOWN("Payload", "???", ProtocolValues
.LAYER_7
, false); //$NON-NLS-1$ //$NON-NLS-2$
72 private final String fName
;
73 private final String fShortName
;
74 private final int fLayer
;
75 private final boolean fSupportsStream
;
77 private Protocol(String name
, String shortName
, int layer
, boolean supportsStream
) {
79 fShortName
= shortName
;
81 fSupportsStream
= supportsStream
;
85 * Getter method for the long name of the protocol.
87 * @return The long name of the protocol, as a string.
89 public String
getName() {
94 * Getter method for the short name of the protocol.
96 * @return The short name of the protocol, as a string.
98 public String
getShortName() {
103 * Getter method for the OSI layer of the protocol.
105 * @return The layer of the protocol.
107 public int getLayer() {
112 * Getter method that indicates if the protocol supports streams.
114 * @return Whether the protocol supports streams or not.
116 public boolean supportsStream() {
117 return fSupportsStream
;
120 // TODO make an immutable list that holds this data instead of computing it
124 * Method that returns a list of all the protocols included in a certain OSI
128 * The layer of the protocols.
129 * @return The protocols on that layer.
131 public static List
<Protocol
> getProtocolsOnLayer(int layer
) {
133 if (layer
> ProtocolValues
.LAYER_7
|| layer
< ProtocolValues
.LAYER_0
) {
134 throw new IllegalArgumentException("The layer is invalid."); //$NON-NLS-1$
137 List
<Protocol
> protocolsOnLayer
= new ArrayList
<>();
138 for (Protocol p
: Protocol
.values()) {
139 if (p
.getLayer() == layer
) {
140 protocolsOnLayer
.add(p
);
143 return protocolsOnLayer
;
147 * Method that returns all the protocol defined.
149 * @return A list containing all the protocols.
151 public static List
<Protocol
> getAllProtocols() {
152 return new ArrayList
<>(Arrays
.asList(Protocol
.values()));
This page took 0.033364 seconds and 5 git commands to generate.