tmf: Rename packages to org.eclipse.tracecompass.*
[deliverable/tracecompass.git] / org.eclipse.tracecompass.tmf.pcap.core / src / org / eclipse / tracecompass / internal / tmf / pcap / core / util / ProtocolConversion.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.tracecompass.internal.tmf.pcap.core.util;
14
15 import org.eclipse.linuxtools.internal.pcap.core.protocol.PcapProtocol;
16 import org.eclipse.tracecompass.internal.tmf.pcap.core.protocol.TmfPcapProtocol;
17
18 /**
19 * Helper class that allows the conversion between Protocol and TmfProtocol.
20 * This is only used by this project and thus is internal (not API).
21 *
22 * @author Vincent Perot
23 */
24 public final class ProtocolConversion {
25
26 private ProtocolConversion() {}
27
28 /**
29 * Wrap a {@link PcapProtocol} into a {@link TmfPcapProtocol}.
30 *
31 * @param protocol
32 * The {@link PcapProtocol} to match
33 * @return The TmfProtocol
34 */
35 public static TmfPcapProtocol wrap(PcapProtocol protocol) {
36 switch (protocol) {
37 case ETHERNET_II:
38 return TmfPcapProtocol.ETHERNET_II;
39 case IPV4:
40 return TmfPcapProtocol.IPV4;
41 case PCAP:
42 return TmfPcapProtocol.PCAP;
43 case TCP:
44 return TmfPcapProtocol.TCP;
45 case UDP:
46 return TmfPcapProtocol.UDP;
47 case UNKNOWN:
48 return TmfPcapProtocol.UNKNOWN;
49 default:
50 throw new IllegalArgumentException();
51 }
52 }
53
54 /**
55 * Unwrap a {@link TmfPcapProtocol} from a {@link PcapProtocol}.
56 *
57 * @param protocol
58 * The TmfProtocol
59 * @return The Protocol
60 */
61 public static PcapProtocol unwrap(TmfPcapProtocol protocol) {
62 switch (protocol) {
63 case ETHERNET_II:
64 return PcapProtocol.ETHERNET_II;
65 case IPV4:
66 return PcapProtocol.IPV4;
67 case PCAP:
68 return PcapProtocol.PCAP;
69 case TCP:
70 return PcapProtocol.TCP;
71 case UDP:
72 return PcapProtocol.UDP;
73 case UNKNOWN:
74 return PcapProtocol.UNKNOWN;
75 default:
76 throw new IllegalArgumentException();
77 }
78 }
79
80 }
This page took 0.033115 seconds and 5 git commands to generate.