2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.controller.liblldp;
11 import java.util.ArrayList;
12 import java.util.List;
15 * The enum contains the most common 802.3 ethernet types and 802.2 + SNAP protocol ids
20 public enum EtherTypes {
21 PVSTP("PVSTP", 0x010B), // 802.2 + SNAP (Spanning Tree)
22 CDP("CDP", 0x2000), // 802.2 + SNAP
23 VTP("VTP", 0x2003), // 802.2 + SNAP
24 IPv4("IPv4", 0x800), ARP("ARP", 0x806), RARP("Reverse ARP", 0x8035), VLANTAGGED(
25 "VLAN Tagged", 0x8100), // 802.1Q
26 IPv6("IPv6", 0x86DD), MPLSUCAST("MPLS Unicast", 0x8847), MPLSMCAST(
27 "MPLS Multicast", 0x8848), QINQ("QINQ", 0x88A8), // Standard 802.1ad QinQ
28 LLDP("LLDP", 0x88CC), OLDQINQ("Old QINQ", 0x9100), // Old non-standard QinQ
29 CISCOQINQ("Cisco QINQ", 0x9200); // Cisco non-standard QinQ
31 private static final String regexNumberString = "^[0-9]+$";
32 private String description;
35 private EtherTypes(String description, int number) {
36 this.description = description;
40 public String toString() {
44 public int intValue() {
48 public short shortValue() {
49 return ((Integer) number).shortValue();
52 public static String getEtherTypeName(int number) {
53 return getEtherTypeInternal(number);
56 public static String getEtherTypeName(short number) {
57 return getEtherTypeInternal((int) number & 0xffff);
60 public static String getEtherTypeName(byte number) {
61 return getEtherTypeInternal((int) number & 0xff);
64 private static String getEtherTypeInternal(int number) {
65 for (EtherTypes type : EtherTypes.values()) {
66 if (type.number == number) {
67 return type.toString();
70 return "0x" + Integer.toHexString(number);
73 public static short getEtherTypeNumberShort(String name) {
74 if (name.matches(regexNumberString)) {
75 return Short.valueOf(name);
77 for (EtherTypes type : EtherTypes.values()) {
78 if (type.description.equalsIgnoreCase(name)) {
79 return type.shortValue();
85 public static int getEtherTypeNumberInt(String name) {
86 if (name.matches(regexNumberString)) {
87 return Integer.valueOf(name);
89 for (EtherTypes type : EtherTypes.values()) {
90 if (type.description.equalsIgnoreCase(name)) {
91 return type.intValue();
97 public static List<String> getEtherTypesNameList() {
98 List<String> ethertypesList = new ArrayList<String>();
99 for (EtherTypes type : EtherTypes.values()) {
100 ethertypesList.add(type.toString());
102 return ethertypesList;
105 public static EtherTypes loadFromString(String string) {
106 int intType = Integer.parseInt(string);
108 for (EtherTypes type : EtherTypes.values()) {
109 if (type.number == intType) {