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
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
33 private static final String regexNumberString = "^[0-9]+$";
34 private String description;
37 private EtherTypes(String description, int number) {
38 this.description = description;
42 public String toString() {
46 public int intValue() {
50 public short shortValue() {
51 return ((Integer) number).shortValue();
54 public static String getEtherTypeName(int number) {
55 return getEtherTypeInternal(number);
58 public static String getEtherTypeName(short number) {
59 return getEtherTypeInternal((int) number & 0xffff);
62 public static String getEtherTypeName(byte number) {
63 return getEtherTypeInternal((int) number & 0xff);
66 private static String getEtherTypeInternal(int number) {
67 for (EtherTypes type : EtherTypes.values()) {
68 if (type.number == number) {
69 return type.toString();
72 return "0x" + Integer.toHexString(number);
75 public static short getEtherTypeNumberShort(String name) {
76 if (name.matches(regexNumberString)) {
77 return Short.valueOf(name);
79 for (EtherTypes type : EtherTypes.values()) {
80 if (type.description.equalsIgnoreCase(name)) {
81 return type.shortValue();
87 public static int getEtherTypeNumberInt(String name) {
88 if (name.matches(regexNumberString)) {
89 return Integer.valueOf(name);
91 for (EtherTypes type : EtherTypes.values()) {
92 if (type.description.equalsIgnoreCase(name)) {
93 return type.intValue();
99 public static List<String> getEtherTypesNameList() {
100 List<String> ethertypesList = new ArrayList<String>();
101 for (EtherTypes type : EtherTypes.values()) {
102 ethertypesList.add(type.toString());
104 return ethertypesList;
107 public static EtherTypes loadFromString(String string) {
108 int intType = Integer.parseInt(string);
110 for (EtherTypes type : EtherTypes.values()) {
111 if (type.number == intType) {