Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 0e4330bf3f8afadd03707bc33d429d6c331428d3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
/*******************************************************************************
 * Copyright (c) 2014 Ericsson
 *
 * All rights reserved. This program and the accompanying materials are
 * made available under the terms of the Eclipse Public License v1.0 which
 * accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *   Vincent Perot - Initial API and implementation
 *******************************************************************************/

package org.eclipse.linuxtools.tmf.pcap.core.protocol;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.linuxtools.pcap.core.protocol.Protocol;

/**
 * Enumeration as a TMF wrapper of the different Protocols. To register a
 * protocol in TMF, it must be present in
 * org.eclipse.linuxtools.pcap.core.protocol.Protocol and must have the same
 * name.
 *
 * @author Vincent Perot
 */
public enum TmfProtocol {

    // Layer 0
    /**
     * The Pcap Protocol is not a real protocol but is used as an helper to
     * generate Pcap packets.
     */
    PCAP,

    // Layer 1
    // Should always be empty.

    // Layer 2
    /**
     * The description of the Ethernet II Protocol.
     */
    ETHERNET_II,

    // Layer 3
    /**
     * The description of the Internet Protocol Version 4.
     */
    IPV4,

    // Layer 4
    /**
     * The description of the Transmission Control Protocol.
     */
    TCP,
    /**
     * The description of the User Datagram Protocol.
     */
    UDP,

    // Layer 5

    // Layer 6

    // Layer 7
    /**
     * This protocol is used as an helper if the protocol of a packet is not
     * recognized. Since all its data goes into payload, it can also be seen as
     * a "payload packet". This is considered to be on layer 7 since its always
     * the most encapsulated packet if present.
     */
    UNKNOWN;

    private final String fName;
    private final String fShortName;
    private final int fLayer;
    private final boolean fSupportsStream;

    private TmfProtocol() {
        @SuppressWarnings("null")
        @NonNull String name = this.name();
        fName = Protocol.valueOf(name).getName();
        fShortName = Protocol.valueOf(name).getShortName();
        fLayer = Protocol.valueOf(name).getLayer();
        fSupportsStream = Protocol.valueOf(name).supportsStream();
    }

    /**
     * Getter method for the long name of the protocol.
     *
     * @return The long name of the protocol, as a string.
     */
    public String getName() {
        return fName;
    }

    /**
     * Getter method for the short name of the protocol.
     *
     * @return The short name of the protocol, as a string.
     */
    public String getShortName() {
        return fShortName;
    }

    /**
     * Getter method for the OSI layer of the protocol.
     *
     * @return The layer of the protocol.
     */
    public int getLayer() {
        return fLayer;
    }

    /**
     * Getter method that indicates if the protocol supports streams.
     *
     * @return Whether the protocol supports streams or not.
     */
    public boolean supportsStream() {
        return fSupportsStream;
    }

    /**
     * Method that returns all the protocol defined.
     *
     * @return A list containing all the protocols.
     */
    public static List<TmfProtocol> getAllProtocols() {
        return new ArrayList<>(Arrays.asList(TmfProtocol.values()));
    }

}

Back to the top