package org.eclipse.linuxtools.internal.pcap.core.protocol;
import java.util.ArrayList;
-import java.util.Arrays;
+import java.util.Collection;
import java.util.List;
/**
* The Pcap Protocol is not a real protocol but is used as an helper to
* generate Pcap packets.
*/
- PCAP("Packet Capture", "pcap", PcapProtocolValues.LAYER_0, false), //$NON-NLS-1$ //$NON-NLS-2$
+ PCAP("Packet Capture", "pcap", Layer.LAYER_0, false), //$NON-NLS-1$ //$NON-NLS-2$
// Layer 1
// Should always be empty.
/**
* The description of the Ethernet II Protocol.
*/
- ETHERNET_II("Ethernet II", "eth", PcapProtocolValues.LAYER_2, true), //$NON-NLS-1$ //$NON-NLS-2$
+ ETHERNET_II("Ethernet II", "eth", Layer.LAYER_2, true), //$NON-NLS-1$ //$NON-NLS-2$
// Layer 3
/**
* The description of the Internet Protocol Version 4.
*/
- IPV4("Internet Protocol Version 4", "ipv4", PcapProtocolValues.LAYER_3, true), //$NON-NLS-1$ //$NON-NLS-2$
+ IPV4("Internet Protocol Version 4", "ipv4", Layer.LAYER_3, true), //$NON-NLS-1$ //$NON-NLS-2$
// Layer 4
/**
* The description of the Transmission Control Protocol.
*/
- TCP("Transmission Control Protocol", "tcp", PcapProtocolValues.LAYER_4, true), //$NON-NLS-1$ //$NON-NLS-2$
+ TCP("Transmission Control Protocol", "tcp", Layer.LAYER_4, true), //$NON-NLS-1$ //$NON-NLS-2$
/**
* The description of the User Datagram Protocol.
*/
- UDP("User Datagram Protocol", "udp", PcapProtocolValues.LAYER_4, true), //$NON-NLS-1$ //$NON-NLS-2$
+ UDP("User Datagram Protocol", "udp", Layer.LAYER_4, true), //$NON-NLS-1$ //$NON-NLS-2$
// Layer 5
* a "payload packet". This is considered to be on layer 7 since its always
* the most encapsulated packet if present.
*/
- UNKNOWN("Payload", "???", PcapProtocolValues.LAYER_7, false); //$NON-NLS-1$ //$NON-NLS-2$
+ UNKNOWN("Payload", "???", Layer.LAYER_7, false); //$NON-NLS-1$ //$NON-NLS-2$
+
+
+ /**
+ * Enum that lists constants related to protocols/layers.
+ *
+ * See http://en.wikipedia.org/wiki/OSI_model#Description_of_OSI_layers.
+ *
+ * @author Vincent Perot
+ */
+ public static enum Layer {
+
+ /**
+ * Layer 0. This layer is not an OSI layer but is used as an helper to store
+ * the pseudo-protocol PCAP.
+ */
+ LAYER_0,
+
+ /** Layer 1 of the OSI model */
+ LAYER_1,
+
+ /** Layer 2 of the OSI model */
+ LAYER_2,
+
+ /** Layer 3 of the OSI model */
+ LAYER_3,
+
+ /** Layer 4 of the OSI model */
+ LAYER_4,
+
+ /** Layer 5 of the OSI model */
+ LAYER_5,
+
+ /** Layer 6 of the OSI model */
+ LAYER_6,
+
+ /** Layer 7 of the OSI model */
+ LAYER_7;
+ }
+
// Fields
private final String fName;
private final String fShortName;
- private final int fLayer;
+ private final Layer fLayer;
private final boolean fSupportsStream;
- private PcapProtocol(String name, String shortName, int layer, boolean supportsStream) {
+ private PcapProtocol(String name, String shortName, Layer layer, boolean supportsStream) {
fName = name;
fShortName = shortName;
fLayer = layer;
*
* @return The layer of the protocol.
*/
- public int getLayer() {
+ public Layer getLayer() {
return fLayer;
}
* The layer of the protocols.
* @return The protocols on that layer.
*/
- public static List<PcapProtocol> getProtocolsOnLayer(int layer) {
-
- if (layer > PcapProtocolValues.LAYER_7 || layer < PcapProtocolValues.LAYER_0) {
- throw new IllegalArgumentException("The layer is invalid."); //$NON-NLS-1$
- }
-
+ public static Collection<PcapProtocol> getProtocolsOnLayer(Layer layer) {
List<PcapProtocol> protocolsOnLayer = new ArrayList<>();
for (PcapProtocol p : PcapProtocol.values()) {
if (p.getLayer() == layer) {
}
return protocolsOnLayer;
}
-
- /**
- * Method that returns all the protocol defined.
- *
- * @return A list containing all the protocols.
- */
- public static List<PcapProtocol> getAllProtocols() {
- return new ArrayList<>(Arrays.asList(PcapProtocol.values()));
- }
}