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 * It represents the most common IP protocols numbers
17 * It provides the binding between IP protocol names and numbers
18 * and provides APIs to read and parse them in either of the two forms
23 // Openflow 1.0 supports the IP Proto match only for ICMP, TCP and UDP
24 public enum IPProtocols {
26 /* HOPOPT("HOPOPT",0),
36 BBNRCCMON("BBN-RCC-MON",10),
45 DCNMEAS("DCN-MEAS",19),
58 MERITINP("MERIT-INP",32),
64 IDPRCMTP("IDPR-CMTP",38),
65 TPPLUSPLUS("TP++",39),
69 IPV6Route("IPv6-Route",43),
70 IPV6Frag("IPv6-Frag",44),
84 */IPV6ICMP("IPv6-ICMP", 58);
85 /* IPV6NoNxt("IPv6-NoNxt",59),
86 IPV6Opts("IPv6-Opts",60),
87 ANYHOST("ANY-HOST",61),
89 ANYNETWORK("ANY-NETWORK",63),
90 SATEXPAK("SAT-EXPAK",64),
91 KRYPTOLAN("KRYPTOLAN",65),
94 ANYDISTFS("ANY-DIST-FS",68),
102 BRSATMON("BR-SAT-MON",76),
105 WBEXPAK("WB-EXPAK",79),
108 SECUREVMTP("SECURE-VMTP",82),
112 NSFNETIGP("NSFNET-IGP",85),
116 OSPFIGP("OSPFIGP",89),
117 SPRITERPC("Sprite-RPC",90),
124 ETHERIP("ETHERIP",97),
126 ANYENC("ANY-ENC",99),
135 IPComp("IPComp",108),
137 COMPAQPEER("Compaq-Peer",110),
138 IPXINIP("IPX-in-IP",111),
141 ANY0HOP("ANY-0-HOP",114),
155 SSCOPMCE("SSCOPMCE",128),
161 RSVPE2EIGNORE("RSVP-E2E-IGNORE",134),
162 MOBILITYHEADER("Mobility Header",135),
163 UDPLITE("UDPLite",136),
164 MPLSINIP("MPLS-in-IP",137),
171 private static final String regexNumberString = "^[0-9]+$";
172 private String protocolName;
173 private int protocolNumber;
175 private IPProtocols(String name, int number) {
177 protocolNumber = number;
180 public int intValue() {
181 return protocolNumber;
184 public short shortValue() {
185 return ((Integer) protocolNumber).shortValue();
188 public byte byteValue() {
189 return ((Integer) protocolNumber).byteValue();
192 public String toString() {
196 public static String getProtocolName(int number) {
197 return getProtocolNameInternal(number);
200 public static String getProtocolName(short number) {
201 return getProtocolNameInternal((int) number & 0xffff);
204 public static String getProtocolName(byte number) {
205 return getProtocolNameInternal((int) number & 0xff);
208 private static String getProtocolNameInternal(int number) {
209 for (IPProtocols proto : IPProtocols.values()) {
210 if (proto.protocolNumber == number) {
211 return proto.toString();
214 return "0x" + Integer.toHexString(number);
217 public static short getProtocolNumberShort(String name) {
218 if (name.matches(regexNumberString)) {
219 return Short.valueOf(name);
221 for (IPProtocols proto : IPProtocols.values()) {
222 if (proto.protocolName.equalsIgnoreCase(name)) {
223 return proto.shortValue();
229 public static int getProtocolNumberInt(String name) {
230 if (name.matches(regexNumberString)) {
231 return Integer.valueOf(name);
233 for (IPProtocols proto : IPProtocols.values()) {
234 if (proto.protocolName.equalsIgnoreCase(name)) {
235 return proto.intValue();
241 public static byte getProtocolNumberByte(String name) {
242 if (name.matches(regexNumberString)) {
243 return Integer.valueOf(name).byteValue();
245 for (IPProtocols proto : IPProtocols.values()) {
246 if (proto.protocolName.equalsIgnoreCase(name)) {
247 return proto.byteValue();
253 public static List<String> getProtocolNameList() {
254 List<String> protoList = new ArrayList<String>();
255 for (IPProtocols proto : IPProtocols.values()) {
256 protoList.add(proto.toString());