tmf: Support + and - keys for histogram zoom
[deliverable/tracecompass.git] / org.eclipse.linuxtools.pcap.core / src / org / eclipse / linuxtools / pcap / core / protocol / Protocol.java
1 /*******************************************************************************
2 * Copyright (c) 2014 Ericsson
3 *
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
8 *
9 * Contributors:
10 * Vincent Perot - Initial API and implementation
11 *******************************************************************************/
12
13 package org.eclipse.linuxtools.pcap.core.protocol;
14
15 import java.util.ArrayList;
16 import java.util.Arrays;
17 import java.util.List;
18
19 /**
20 * Enumeration used for describing the different known protocols.
21 *
22 * @author Vincent Perot
23 */
24 public enum Protocol {
25
26 // Layer 0
27 /**
28 * The Pcap Protocol is not a real protocol but is used as an helper to
29 * generate Pcap packets.
30 */
31 PCAP("Packet Capture", "pcap", ProtocolValues.LAYER_0, false), //$NON-NLS-1$ //$NON-NLS-2$
32
33 // Layer 1
34 // Should always be empty.
35
36 // Layer 2
37 /**
38 * The description of the Ethernet II Protocol.
39 */
40 ETHERNET_II("Ethernet II", "eth", ProtocolValues.LAYER_2, true), //$NON-NLS-1$ //$NON-NLS-2$
41
42 // Layer 3
43 /**
44 * The description of the Internet Protocol Version 4.
45 */
46 IPV4("Internet Protocol Version 4", "ipv4", ProtocolValues.LAYER_3, true), //$NON-NLS-1$ //$NON-NLS-2$
47
48 // Layer 4
49 /**
50 * The description of the Transmission Control Protocol.
51 */
52 TCP("Transmission Control Protocol", "tcp", ProtocolValues.LAYER_4, true), //$NON-NLS-1$ //$NON-NLS-2$
53 /**
54 * The description of the User Datagram Protocol.
55 */
56 UDP("User Datagram Protocol", "udp", ProtocolValues.LAYER_4, true), //$NON-NLS-1$ //$NON-NLS-2$
57
58 // Layer 5
59
60 // Layer 6
61
62 // Layer 7
63 /**
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.
68 */
69 UNKNOWN("Payload", "???", ProtocolValues.LAYER_7, false); //$NON-NLS-1$ //$NON-NLS-2$
70
71 // Fields
72 private final String fName;
73 private final String fShortName;
74 private final int fLayer;
75 private final boolean fSupportsStream;
76
77 private Protocol(String name, String shortName, int layer, boolean supportsStream) {
78 fName = name;
79 fShortName = shortName;
80 fLayer = layer;
81 fSupportsStream = supportsStream;
82 }
83
84 /**
85 * Getter method for the long name of the protocol.
86 *
87 * @return The long name of the protocol, as a string.
88 */
89 public String getName() {
90 return fName;
91 }
92
93 /**
94 * Getter method for the short name of the protocol.
95 *
96 * @return The short name of the protocol, as a string.
97 */
98 public String getShortName() {
99 return fShortName;
100 }
101
102 /**
103 * Getter method for the OSI layer of the protocol.
104 *
105 * @return The layer of the protocol.
106 */
107 public int getLayer() {
108 return fLayer;
109 }
110
111 /**
112 * Getter method that indicates if the protocol supports streams.
113 *
114 * @return Whether the protocol supports streams or not.
115 */
116 public boolean supportsStream() {
117 return fSupportsStream;
118 }
119
120 // TODO make an immutable list that holds this data instead of computing it
121 // everytime.
122
123 /**
124 * Method that returns a list of all the protocols included in a certain OSI
125 * layer.
126 *
127 * @param layer
128 * The layer of the protocols.
129 * @return The protocols on that layer.
130 */
131 public static List<Protocol> getProtocolsOnLayer(int layer) {
132
133 if (layer > ProtocolValues.LAYER_7 || layer < ProtocolValues.LAYER_0) {
134 throw new IllegalArgumentException("The layer is invalid."); //$NON-NLS-1$
135 }
136
137 List<Protocol> protocolsOnLayer = new ArrayList<>();
138 for (Protocol p : Protocol.values()) {
139 if (p.getLayer() == layer) {
140 protocolsOnLayer.add(p);
141 }
142 }
143 return protocolsOnLayer;
144 }
145
146 /**
147 * Method that returns all the protocol defined.
148 *
149 * @return A list containing all the protocols.
150 */
151 public static List<Protocol> getAllProtocols() {
152 return new ArrayList<>(Arrays.asList(Protocol.values()));
153 }
154 }
This page took 0.033364 seconds and 5 git commands to generate.