Merge "neutron now works with jetty"
[controller.git] / opendaylight / adsal / sal / api / src / main / java / org / opendaylight / controller / sal / utils / EtherTypes.java
1
2 /*
3  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
4  *
5  * This program and the accompanying materials are made available under the
6  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
7  * and is available at http://www.eclipse.org/legal/epl-v10.html
8  */
9
10 package org.opendaylight.controller.sal.utils;
11
12 import java.util.ArrayList;
13 import java.util.List;
14
15 /**
16  * The enum contains the most common 802.3 ethernet types and 802.2 + SNAP protocol ids
17  *
18  *
19  *
20  */
21 @Deprecated
22 public enum EtherTypes {
23     PVSTP("PVSTP", 0x010B), // 802.2 + SNAP (Spanning Tree)
24     CDP("CDP", 0x2000), // 802.2 + SNAP
25     VTP("VTP", 0x2003), // 802.2 + SNAP
26     IPv4("IPv4", 0x800), ARP("ARP", 0x806), RARP("Reverse ARP", 0x8035), VLANTAGGED(
27             "VLAN Tagged", 0x8100), // 802.1Q
28     IPv6("IPv6", 0x86DD), MPLSUCAST("MPLS Unicast", 0x8847), MPLSMCAST(
29             "MPLS Multicast", 0x8848), QINQ("QINQ", 0x88A8), // Standard 802.1ad QinQ
30     LLDP("LLDP", 0x88CC), OLDQINQ("Old QINQ", 0x9100), // Old non-standard QinQ
31     CISCOQINQ("Cisco QINQ", 0x9200); // Cisco non-standard QinQ
32
33     private static final String regexNumberString = "^[0-9]+$";
34     private String description;
35     private int number;
36
37     private EtherTypes(String description, int number) {
38         this.description = description;
39         this.number = number;
40     }
41
42     public String toString() {
43         return description;
44     }
45
46     public int intValue() {
47         return number;
48     }
49
50     public short shortValue() {
51         return ((Integer) number).shortValue();
52     }
53
54     public static String getEtherTypeName(int number) {
55         return getEtherTypeInternal(number);
56     }
57
58     public static String getEtherTypeName(short number) {
59         return getEtherTypeInternal((int) number & 0xffff);
60     }
61
62     public static String getEtherTypeName(byte number) {
63         return getEtherTypeInternal((int) number & 0xff);
64     }
65
66     private static String getEtherTypeInternal(int number) {
67         for (EtherTypes type : EtherTypes.values()) {
68             if (type.number == number) {
69                 return type.toString();
70             }
71         }
72         return "0x" + Integer.toHexString(number);
73     }
74
75     public static short getEtherTypeNumberShort(String name) {
76         if (name.matches(regexNumberString)) {
77             return Short.valueOf(name);
78         }
79         for (EtherTypes type : EtherTypes.values()) {
80             if (type.description.equalsIgnoreCase(name)) {
81                 return type.shortValue();
82             }
83         }
84         return 0;
85     }
86
87     public static int getEtherTypeNumberInt(String name) {
88         if (name.matches(regexNumberString)) {
89             return Integer.valueOf(name);
90         }
91         for (EtherTypes type : EtherTypes.values()) {
92             if (type.description.equalsIgnoreCase(name)) {
93                 return type.intValue();
94             }
95         }
96         return 0;
97     }
98
99     public static List<String> getEtherTypesNameList() {
100         List<String> ethertypesList = new ArrayList<String>();
101         for (EtherTypes type : EtherTypes.values()) {
102             ethertypesList.add(type.toString());
103         }
104         return ethertypesList;
105     }
106
107     public static EtherTypes loadFromString(String string) {
108         int intType = Integer.parseInt(string);
109
110         for (EtherTypes type : EtherTypes.values()) {
111             if (type.number == intType) {
112                 return type;
113             }
114         }
115         return null;
116     }
117
118 }