3 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
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
10 package org.opendaylight.controller.sal.utils;
12 import java.util.ArrayList;
13 import java.util.List;
16 * The enum contains the most common 802.3 ethernet types and 802.2 + SNAP protocol ids
21 public enum EtherTypes {
22 PVSTP("PVSTP", 0x010B), // 802.2 + SNAP (Spanning Tree)
23 CDP("CDP", 0x2000), // 802.2 + SNAP
24 VTP("VTP", 0x2003), // 802.2 + SNAP
25 IPv4("IPv4", 0x800), ARP("ARP", 0x806), RARP("Reverse ARP", 0x8035), VLANTAGGED(
26 "VLAN Tagged", 0x8100), // 802.1Q
27 IPv6("IPv6", 0x86DD), MPLSUCAST("MPLS Unicast", 0x8847), MPLSMCAST(
28 "MPLS Multicast", 0x8848), QINQ("QINQ", 0x88A8), // Standard 802.1ad QinQ
29 LLDP("LLDP", 0x88CC), OLDQINQ("Old QINQ", 0x9100), // Old non-standard QinQ
30 CISCOQINQ("Cisco QINQ", 0x9200); // Cisco non-standard QinQ
32 private static final String regexNumberString = "^[0-9]+$";
33 private String description;
36 private EtherTypes(String description, int number) {
37 this.description = description;
41 public String toString() {
45 public int intValue() {
49 public short shortValue() {
50 return ((Integer) number).shortValue();
53 public static String getEtherTypeName(int number) {
54 return getEtherTypeInternal(number);
57 public static String getEtherTypeName(short number) {
58 return getEtherTypeInternal((int) number & 0xffff);
61 public static String getEtherTypeName(byte number) {
62 return getEtherTypeInternal((int) number & 0xff);
65 private static String getEtherTypeInternal(int number) {
66 for (EtherTypes type : EtherTypes.values()) {
67 if (type.number == number) {
68 return type.toString();
71 return "0x" + Integer.toHexString(number);
74 public static short getEtherTypeNumberShort(String name) {
75 if (name.matches(regexNumberString)) {
76 return Short.valueOf(name);
78 for (EtherTypes type : EtherTypes.values()) {
79 if (type.description.equalsIgnoreCase(name)) {
80 return type.shortValue();
86 public static int getEtherTypeNumberInt(String name) {
87 if (name.matches(regexNumberString)) {
88 return Integer.valueOf(name);
90 for (EtherTypes type : EtherTypes.values()) {
91 if (type.description.equalsIgnoreCase(name)) {
92 return type.intValue();
98 public static List<String> getEtherTypesNameList() {
99 List<String> ethertypesList = new ArrayList<String>();
100 for (EtherTypes type : EtherTypes.values()) {
101 ethertypesList.add(type.toString());
103 return ethertypesList;
106 public static EtherTypes loadFromString(String string) {
107 int intType = Integer.parseInt(string);
109 for (EtherTypes type : EtherTypes.values()) {
110 if (type.number == intType) {