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
.tracecompass
.internal
.pcap
.core
.protocol
;
15 import java
.util
.ArrayList
;
16 import java
.util
.Collection
;
17 import java
.util
.List
;
20 * Enumeration used for describing the different known protocols.
22 * @author Vincent Perot
24 public enum PcapProtocol
{
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", Layer
.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", Layer
.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", Layer
.LAYER_3
, true), //$NON-NLS-1$ //$NON-NLS-2$
50 * The description of the Transmission Control Protocol.
52 TCP("Transmission Control Protocol", "tcp", Layer
.LAYER_4
, true), //$NON-NLS-1$ //$NON-NLS-2$
54 * The description of the User Datagram Protocol.
56 UDP("User Datagram Protocol", "udp", Layer
.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", "???", Layer
.LAYER_7
, false); //$NON-NLS-1$ //$NON-NLS-2$
73 * Enum that lists constants related to protocols/layers.
75 * See http://en.wikipedia.org/wiki/OSI_model#Description_of_OSI_layers.
77 * @author Vincent Perot
79 public static enum Layer
{
82 * Layer 0. This layer is not an OSI layer but is used as an helper to store
83 * the pseudo-protocol PCAP.
87 /** Layer 1 of the OSI model */
90 /** Layer 2 of the OSI model */
93 /** Layer 3 of the OSI model */
96 /** Layer 4 of the OSI model */
99 /** Layer 5 of the OSI model */
102 /** Layer 6 of the OSI model */
105 /** Layer 7 of the OSI model */
111 private final String fName
;
112 private final String fShortName
;
113 private final Layer fLayer
;
114 private final boolean fSupportsStream
;
116 private PcapProtocol(String name
, String shortName
, Layer layer
, boolean supportsStream
) {
118 fShortName
= shortName
;
120 fSupportsStream
= supportsStream
;
124 * Getter method for the long name of the protocol.
126 * @return The long name of the protocol, as a string.
128 public String
getName() {
133 * Getter method for the short name of the protocol.
135 * @return The short name of the protocol, as a string.
137 public String
getShortName() {
142 * Getter method for the OSI layer of the protocol.
144 * @return The layer of the protocol.
146 public Layer
getLayer() {
151 * Getter method that indicates if the protocol supports streams.
153 * @return Whether the protocol supports streams or not.
155 public boolean supportsStream() {
156 return fSupportsStream
;
159 // TODO make an immutable list that holds this data instead of computing it
163 * Method that returns a list of all the protocols included in a certain OSI
167 * The layer of the protocols.
168 * @return The protocols on that layer.
170 public static Collection
<PcapProtocol
> getProtocolsOnLayer(Layer layer
) {
171 List
<PcapProtocol
> protocolsOnLayer
= new ArrayList
<>();
172 for (PcapProtocol p
: PcapProtocol
.values()) {
173 if (p
.getLayer() == layer
) {
174 protocolsOnLayer
.add(p
);
177 return protocolsOnLayer
;
This page took 0.034726 seconds and 5 git commands to generate.