blob: b9eae680e5a67ae85a1d1437abfd141498232aa1 [file] [log] [blame]
Yotam Harcholf3f11152013-09-05 16:47:16 -07001package org.projectfloodlight.openflow.types;
2
3import org.jboss.netty.buffer.ChannelBuffer;
4
Andreas Wundsam85c961f2013-09-29 21:22:12 -07005import com.google.common.primitives.Shorts;
6
Yotam Harcholf3f11152013-09-05 16:47:16 -07007/**
8 * IP-Protocol field representation
Andreas Wundsamb75c4ad2013-09-23 14:45:35 -07009 *
Yotam Harcholf3f11152013-09-05 16:47:16 -070010 * @author Yotam Harchol (yotam.harchol@bigswitch.com)
11 */
12public class IpProtocol implements OFValueType<IpProtocol> {
13
14 static final short MAX_PROTO = 0xFF;
15 static final int LENGTH = 1;
16
17 private final short proto;
18
Andreas Wundsam520c8802013-10-08 22:05:23 -070019 static final short NUM_HOPOPT = 0x00;
20 static final short NUM_ICMP = 0x01;
21 static final short NUM_IGMP = 0x02;
22 static final short NUM_GGP = 0x03;
23 static final short NUM_IPv4 = 0x04;
24 static final short NUM_ST = 0x05;
25 static final short NUM_TCP = 0x06;
26 static final short NUM_CBT = 0x07;
27 static final short NUM_EGP = 0x08;
28 static final short NUM_IGP = 0x09;
29 static final short NUM_BBN_RCC_MON = 0x0A;
30 static final short NUM_NVP_II = 0x0B;
31 static final short NUM_PUP = 0x0C;
32 static final short NUM_ARGUS = 0x0D;
33 static final short NUM_EMCON = 0x0E;
34 static final short NUM_XNET = 0x0F;
35 static final short NUM_CHAOS = 0x10;
36 static final short NUM_UDP = 0x11;
37 static final short NUM_MUX = 0x12;
38 static final short NUM_DCN_MEAS = 0x13;
39 static final short NUM_HMP = 0x14;
40 static final short NUM_PRM = 0x15;
41 static final short NUM_XNS_IDP = 0x16;
42 static final short NUM_TRUNK_1 = 0x17;
43 static final short NUM_TRUNK_2 = 0x18;
44 static final short NUM_LEAF_1 = 0x19;
45 static final short NUM_LEAF_2 = 0x1A;
46 static final short NUM_RDP = 0x1B;
47 static final short NUM_IRTP = 0x1C;
48 static final short NUM_ISO_TP4 = 0x1D;
49 static final short NUM_NETBLT = 0x1E;
50 static final short NUM_MFE_NSP = 0x1F;
51 static final short NUM_MERIT_INP = 0x20;
52 static final short NUM_DCCP = 0x21;
53 static final short NUM_3PC = 0x22;
54 static final short NUM_IDPR = 0x23;
55 static final short NUM_XTP = 0x24;
56 static final short NUM_DDP = 0x25;
57 static final short NUM_IDPR_CMTP = 0x26;
58 static final short NUM_TP_PP = 0x27;
59 static final short NUM_IL = 0x28;
60 static final short NUM_IPv6 = 0x29;
61 static final short NUM_SDRP = 0x2A;
62 static final short NUM_IPv6_ROUTE = 0x2B;
63 static final short NUM_IPv6_FRAG = 0x2C;
64 static final short NUM_IDRP = 0x2D;
65 static final short NUM_RSVP = 0x2E;
66 static final short NUM_GRE = 0x2F;
67 static final short NUM_MHRP = 0x30;
68 static final short NUM_BNA = 0x31;
69 static final short NUM_ESP = 0x32;
70 static final short NUM_AH = 0x33;
71 static final short NUM_I_NLSP = 0x34;
72 static final short NUM_SWIPE = 0x35;
73 static final short NUM_NARP = 0x36;
74 static final short NUM_MOBILE = 0x37;
75 static final short NUM_TLSP = 0x38;
76 static final short NUM_SKIP = 0x39;
77 static final short NUM_IPv6_ICMP = 0x3A;
78 static final short NUM_IPv6_NO_NXT = 0x3B;
79 static final short NUM_IPv6_OPTS = 0x3C;
80 static final short NUM_HOST_INTERNAL = 0x3D;
81 static final short NUM_CFTP = 0x3E;
82 static final short NUM_LOCAL_NET = 0x3F;
83 static final short NUM_SAT_EXPAK = 0x40;
84 static final short NUM_KRYPTOLAN = 0x41;
85 static final short NUM_RVD = 0x42;
86 static final short NUM_IPPC = 0x43;
87 static final short NUM_DIST_FS = 0x44;
88 static final short NUM_SAT_MON = 0x45;
89 static final short NUM_VISA = 0x46;
90 static final short NUM_IPCV = 0x47;
91 static final short NUM_CPNX = 0x48;
92 static final short NUM_CPHB = 0x49;
93 static final short NUM_WSN = 0x4A;
94 static final short NUM_PVP = 0x4B;
95 static final short NUM_BR_SAT_MON = 0x4C;
96 static final short NUM_SUN_ND = 0x4D;
97 static final short NUM_WB_MON = 0x4E;
98 static final short NUM_WB_EXPAK = 0x4F;
99 static final short NUM_ISO_IP = 0x50;
100 static final short NUM_VMTP = 0x51;
101 static final short NUM_SECURE_VMTP = 0x52;
102 static final short NUM_VINES = 0x53;
103 static final short NUM_TTP_IPTM = 0x54;
104 static final short NUM_NSFNET_IGP = 0x55;
105 static final short NUM_DGP = 0x56;
106 static final short NUM_TCF = 0x57;
107 static final short NUM_EIGRP = 0x58;
108 static final short NUM_OSPF = 0x59;
109 static final short NUM_Sprite_RPC = 0x5A;
110 static final short NUM_LARP = 0x5B;
111 static final short NUM_MTP = 0x5C;
112 static final short NUM_AX_25 = 0x5D;
113 static final short NUM_IPIP = 0x5E;
114 static final short NUM_MICP = 0x5F;
115 static final short NUM_SCC_SP = 0x60;
116 static final short NUM_ETHERIP = 0x61;
117 static final short NUM_ENCAP = 0x62;
118 static final short NUM_PRIVATE_ENCRYPT = 0x63;
119 static final short NUM_GMTP = 0x64;
120 static final short NUM_IFMP = 0x65;
121 static final short NUM_PNNI = 0x66;
122 static final short NUM_PIM = 0x67;
123 static final short NUM_ARIS = 0x68;
124 static final short NUM_SCPS = 0x69;
125 static final short NUM_QNX = 0x6A;
126 static final short NUM_A_N = 0x6B;
127 static final short NUM_IP_COMP = 0x6C;
128 static final short NUM_SNP = 0x6D;
129 static final short NUM_COMPAQ_PEER = 0x6E;
130 static final short NUM_IPX_IN_IP = 0x6F;
131 static final short NUM_VRRP = 0x70;
132 static final short NUM_PGM = 0x71;
133 static final short NUM_ZERO_HOP = 0x72;
134 static final short NUM_L2TP = 0x73;
135 static final short NUM_DDX = 0x74;
136 static final short NUM_IATP = 0x75;
137 static final short NUM_STP = 0x76;
138 static final short NUM_SRP = 0x77;
139 static final short NUM_UTI = 0x78;
140 static final short NUM_SMP = 0x79;
141 static final short NUM_SM = 0x7A;
142 static final short NUM_PTP = 0x7B;
143 static final short NUM_IS_IS_OVER_IPv4 = 0x7C;
144 static final short NUM_FIRE = 0x7D;
145 static final short NUM_CRTP = 0x7E;
146 static final short NUM_CRUDP = 0x7F;
147 static final short NUM_SSCOPMCE = 0x80;
148 static final short NUM_IPLT = 0x81;
149 static final short NUM_SPS = 0x82;
150 static final short NUM_PIPE = 0x83;
151 static final short NUM_SCTP = 0x84;
152 static final short NUM_FC = 0x85;
153 static final short NUM_RSVP_E2E_IGNORE = 0x86;
154 static final short NUM_MOBILITY_HEADER = 0x87;
155 static final short NUM_UDP_LITE = 0x88;
156 static final short NUM_MPLS_IN_IP = 0x89;
157 static final short NUM_MANET = 0x8A;
158 static final short NUM_HIP = 0x8B;
159 static final short NUM_SHIM6 = 0x8C;
Yotam Harcholf3f11152013-09-05 16:47:16 -0700160
Andreas Wundsam520c8802013-10-08 22:05:23 -0700161 public static final IpProtocol HOPOPT = new IpProtocol(NUM_HOPOPT);
162 public static final IpProtocol ICMP = new IpProtocol(NUM_ICMP);
163 public static final IpProtocol IGMP = new IpProtocol(NUM_IGMP);
164 public static final IpProtocol GGP = new IpProtocol(NUM_GGP);
165 public static final IpProtocol IPv4 = new IpProtocol(NUM_IPv4);
166 public static final IpProtocol ST = new IpProtocol(NUM_ST);
167 public static final IpProtocol TCP = new IpProtocol(NUM_TCP);
168 public static final IpProtocol CBT = new IpProtocol(NUM_CBT);
169 public static final IpProtocol EGP = new IpProtocol(NUM_EGP);
170 public static final IpProtocol IGP = new IpProtocol(NUM_IGP);
171 public static final IpProtocol BBN_RCC_MON = new IpProtocol(NUM_BBN_RCC_MON);
172 public static final IpProtocol NVP_II = new IpProtocol(NUM_NVP_II);
173 public static final IpProtocol PUP = new IpProtocol(NUM_PUP);
174 public static final IpProtocol ARGUS = new IpProtocol(NUM_ARGUS);
175 public static final IpProtocol EMCON = new IpProtocol(NUM_EMCON);
176 public static final IpProtocol XNET = new IpProtocol(NUM_XNET);
177 public static final IpProtocol CHAOS = new IpProtocol(NUM_CHAOS);
178 public static final IpProtocol UDP = new IpProtocol(NUM_UDP);
179 public static final IpProtocol MUX = new IpProtocol(NUM_MUX);
180 public static final IpProtocol DCN_MEAS = new IpProtocol(NUM_DCN_MEAS);
181 public static final IpProtocol HMP = new IpProtocol(NUM_HMP);
182 public static final IpProtocol PRM = new IpProtocol(NUM_PRM);
183 public static final IpProtocol XNS_IDP = new IpProtocol(NUM_XNS_IDP);
184 public static final IpProtocol TRUNK_1 = new IpProtocol(NUM_TRUNK_1);
185 public static final IpProtocol TRUNK_2 = new IpProtocol(NUM_TRUNK_2);
186 public static final IpProtocol LEAF_1 = new IpProtocol(NUM_LEAF_1);
187 public static final IpProtocol LEAF_2 = new IpProtocol(NUM_LEAF_2);
188 public static final IpProtocol RDP = new IpProtocol(NUM_RDP);
189 public static final IpProtocol IRTP = new IpProtocol(NUM_IRTP);
190 public static final IpProtocol ISO_TP4 = new IpProtocol(NUM_ISO_TP4);
191 public static final IpProtocol NETBLT = new IpProtocol(NUM_NETBLT);
192 public static final IpProtocol MFE_NSP = new IpProtocol(NUM_MFE_NSP);
193 public static final IpProtocol MERIT_INP = new IpProtocol(NUM_MERIT_INP);
194 public static final IpProtocol DCCP = new IpProtocol(NUM_DCCP);
195 public static final IpProtocol _3PC = new IpProtocol(NUM_3PC);
196 public static final IpProtocol IDPR = new IpProtocol(NUM_IDPR);
197 public static final IpProtocol XTP = new IpProtocol(NUM_XTP);
198 public static final IpProtocol DDP = new IpProtocol(NUM_DDP);
199 public static final IpProtocol IDPR_CMTP = new IpProtocol(NUM_IDPR_CMTP);
200 public static final IpProtocol TP_PP = new IpProtocol(NUM_TP_PP);
201 public static final IpProtocol IL = new IpProtocol(NUM_IL);
202 public static final IpProtocol IPv6 = new IpProtocol(NUM_IPv6);
203 public static final IpProtocol SDRP = new IpProtocol(NUM_SDRP);
204 public static final IpProtocol IPv6_ROUTE = new IpProtocol(NUM_IPv6_ROUTE);
205 public static final IpProtocol IPv6_FRAG = new IpProtocol(NUM_IPv6_FRAG);
206 public static final IpProtocol IDRP = new IpProtocol(NUM_IDRP);
207 public static final IpProtocol RSVP = new IpProtocol(NUM_RSVP);
208 public static final IpProtocol GRE = new IpProtocol(NUM_GRE);
209 public static final IpProtocol MHRP = new IpProtocol(NUM_MHRP);
210 public static final IpProtocol BNA = new IpProtocol(NUM_BNA);
211 public static final IpProtocol ESP = new IpProtocol(NUM_ESP);
212 public static final IpProtocol AH = new IpProtocol(NUM_AH);
213 public static final IpProtocol I_NLSP = new IpProtocol(NUM_I_NLSP);
214 public static final IpProtocol SWIPE = new IpProtocol(NUM_SWIPE);
215 public static final IpProtocol NARP = new IpProtocol(NUM_NARP);
216 public static final IpProtocol MOBILE = new IpProtocol(NUM_MOBILE);
217 public static final IpProtocol TLSP = new IpProtocol(NUM_TLSP);
218 public static final IpProtocol SKIP = new IpProtocol(NUM_SKIP);
219 public static final IpProtocol IPv6_ICMP = new IpProtocol(NUM_IPv6_ICMP);
220 public static final IpProtocol IPv6_NO_NXT = new IpProtocol(NUM_IPv6_NO_NXT);
221 public static final IpProtocol IPv6_OPTS = new IpProtocol(NUM_IPv6_OPTS);
222 public static final IpProtocol HOST_INTERNAL = new IpProtocol(NUM_HOST_INTERNAL);
223 public static final IpProtocol CFTP = new IpProtocol(NUM_CFTP);
224 public static final IpProtocol LOCAL_NET = new IpProtocol(NUM_LOCAL_NET);
225 public static final IpProtocol SAT_EXPAK = new IpProtocol(NUM_SAT_EXPAK);
226 public static final IpProtocol KRYPTOLAN = new IpProtocol(NUM_KRYPTOLAN);
227 public static final IpProtocol RVD = new IpProtocol(NUM_RVD);
228 public static final IpProtocol IPPC = new IpProtocol(NUM_IPPC);
229 public static final IpProtocol DIST_FS = new IpProtocol(NUM_DIST_FS);
230 public static final IpProtocol SAT_MON = new IpProtocol(NUM_SAT_MON);
231 public static final IpProtocol VISA = new IpProtocol(NUM_VISA);
232 public static final IpProtocol IPCV = new IpProtocol(NUM_IPCV);
233 public static final IpProtocol CPNX = new IpProtocol(NUM_CPNX);
234 public static final IpProtocol CPHB = new IpProtocol(NUM_CPHB);
235 public static final IpProtocol WSN = new IpProtocol(NUM_WSN);
236 public static final IpProtocol PVP = new IpProtocol(NUM_PVP);
237 public static final IpProtocol BR_SAT_MON = new IpProtocol(NUM_BR_SAT_MON);
238 public static final IpProtocol SUN_ND = new IpProtocol(NUM_SUN_ND);
239 public static final IpProtocol WB_MON = new IpProtocol(NUM_WB_MON);
240 public static final IpProtocol WB_EXPAK = new IpProtocol(NUM_WB_EXPAK);
241 public static final IpProtocol ISO_IP = new IpProtocol(NUM_ISO_IP);
242 public static final IpProtocol VMTP = new IpProtocol(NUM_VMTP);
243 public static final IpProtocol SECURE_VMTP = new IpProtocol(NUM_SECURE_VMTP);
244 public static final IpProtocol VINES = new IpProtocol(NUM_VINES);
245 public static final IpProtocol TTP_IPTM = new IpProtocol(NUM_TTP_IPTM);
246 public static final IpProtocol NSFNET_IGP = new IpProtocol(NUM_NSFNET_IGP);
247 public static final IpProtocol DGP = new IpProtocol(NUM_DGP);
248 public static final IpProtocol TCF = new IpProtocol(NUM_TCF);
249 public static final IpProtocol EIGRP = new IpProtocol(NUM_EIGRP);
250 public static final IpProtocol OSPF = new IpProtocol(NUM_OSPF);
251 public static final IpProtocol Sprite_RPC = new IpProtocol(NUM_Sprite_RPC);
252 public static final IpProtocol LARP = new IpProtocol(NUM_LARP);
253 public static final IpProtocol MTP = new IpProtocol(NUM_MTP);
254 public static final IpProtocol AX_25 = new IpProtocol(NUM_AX_25);
255 public static final IpProtocol IPIP = new IpProtocol(NUM_IPIP);
256 public static final IpProtocol MICP = new IpProtocol(NUM_MICP);
257 public static final IpProtocol SCC_SP = new IpProtocol(NUM_SCC_SP);
258 public static final IpProtocol ETHERIP = new IpProtocol(NUM_ETHERIP);
259 public static final IpProtocol ENCAP = new IpProtocol(NUM_ENCAP);
260 public static final IpProtocol PRIVATE_ENCRYPT = new IpProtocol(NUM_PRIVATE_ENCRYPT);
261 public static final IpProtocol GMTP = new IpProtocol(NUM_GMTP);
262 public static final IpProtocol IFMP = new IpProtocol(NUM_IFMP);
263 public static final IpProtocol PNNI = new IpProtocol(NUM_PNNI);
264 public static final IpProtocol PIM = new IpProtocol(NUM_PIM);
265 public static final IpProtocol ARIS = new IpProtocol(NUM_ARIS);
266 public static final IpProtocol SCPS = new IpProtocol(NUM_SCPS);
267 public static final IpProtocol QNX = new IpProtocol(NUM_QNX);
268 public static final IpProtocol A_N = new IpProtocol(NUM_A_N);
269 public static final IpProtocol IP_COMP = new IpProtocol(NUM_IP_COMP);
270 public static final IpProtocol SNP = new IpProtocol(NUM_SNP);
271 public static final IpProtocol COMPAQ_PEER = new IpProtocol(NUM_COMPAQ_PEER);
272 public static final IpProtocol IPX_IN_IP = new IpProtocol(NUM_IPX_IN_IP);
273 public static final IpProtocol VRRP = new IpProtocol(NUM_VRRP);
274 public static final IpProtocol PGM = new IpProtocol(NUM_PGM);
275 public static final IpProtocol ZERO_HOP = new IpProtocol(NUM_ZERO_HOP);
276 public static final IpProtocol L2TP = new IpProtocol(NUM_L2TP);
277 public static final IpProtocol DDX = new IpProtocol(NUM_DDX);
278 public static final IpProtocol IATP = new IpProtocol(NUM_IATP);
279 public static final IpProtocol STP = new IpProtocol(NUM_STP);
280 public static final IpProtocol SRP = new IpProtocol(NUM_SRP);
281 public static final IpProtocol UTI = new IpProtocol(NUM_UTI);
282 public static final IpProtocol SMP = new IpProtocol(NUM_SMP);
283 public static final IpProtocol SM = new IpProtocol(NUM_SM);
284 public static final IpProtocol PTP = new IpProtocol(NUM_PTP);
285 public static final IpProtocol IS_IS_OVER_IPv4 = new IpProtocol(NUM_IS_IS_OVER_IPv4);
286 public static final IpProtocol FIRE = new IpProtocol(NUM_FIRE);
287 public static final IpProtocol CRTP = new IpProtocol(NUM_CRTP);
288 public static final IpProtocol CRUDP = new IpProtocol(NUM_CRUDP);
289 public static final IpProtocol SSCOPMCE = new IpProtocol(NUM_SSCOPMCE);
290 public static final IpProtocol IPLT = new IpProtocol(NUM_IPLT);
291 public static final IpProtocol SPS = new IpProtocol(NUM_SPS);
292 public static final IpProtocol PIPE = new IpProtocol(NUM_PIPE);
293 public static final IpProtocol SCTP = new IpProtocol(NUM_SCTP);
294 public static final IpProtocol FC = new IpProtocol(NUM_FC);
295 public static final IpProtocol RSVP_E2E_IGNORE = new IpProtocol(NUM_RSVP_E2E_IGNORE);
296 public static final IpProtocol MOBILITY_HEADER = new IpProtocol(NUM_MOBILITY_HEADER);
297 public static final IpProtocol UDP_LITE = new IpProtocol(NUM_UDP_LITE);
298 public static final IpProtocol MPLS_IN_IP = new IpProtocol(NUM_MPLS_IN_IP);
299 public static final IpProtocol MANET = new IpProtocol(NUM_MANET);
300 public static final IpProtocol HIP = new IpProtocol(NUM_HIP);
301 public static final IpProtocol SHIM6 = new IpProtocol(NUM_SHIM6);
Yotam Harcholf3f11152013-09-05 16:47:16 -0700302
Andreas Wundsam520c8802013-10-08 22:05:23 -0700303 public static final IpProtocol NONE = HOPOPT;
Andreas Wundsamb75c4ad2013-09-23 14:45:35 -0700304
Andreas Wundsam520c8802013-10-08 22:05:23 -0700305 public static final IpProtocol NO_MASK = HOPOPT;
Yotam Harcholf3f11152013-09-05 16:47:16 -0700306 public static final IpProtocol FULL_MASK = new IpProtocol((short)0x0000);
307
308 private IpProtocol(short version) {
309 this.proto = version;
310 }
311
312
313 @Override
314 public int getLength() {
315 return LENGTH;
316 }
317
318 public static IpProtocol of(short proto) {
319 switch (proto) {
Andreas Wundsam520c8802013-10-08 22:05:23 -0700320 case NUM_HOPOPT:
321 return HOPOPT;
322 case NUM_ICMP:
323 return ICMP;
324 case NUM_IGMP:
325 return IGMP;
326 case NUM_GGP:
327 return GGP;
328 case NUM_IPv4:
329 return IPv4;
330 case NUM_ST:
331 return ST;
332 case NUM_TCP:
333 return TCP;
334 case NUM_CBT:
335 return CBT;
336 case NUM_EGP:
337 return EGP;
338 case NUM_IGP:
339 return IGP;
340 case NUM_BBN_RCC_MON:
341 return BBN_RCC_MON;
342 case NUM_NVP_II:
343 return NVP_II;
344 case NUM_PUP:
345 return PUP;
346 case NUM_ARGUS:
347 return ARGUS;
348 case NUM_EMCON:
349 return EMCON;
350 case NUM_XNET:
351 return XNET;
352 case NUM_CHAOS:
353 return CHAOS;
354 case NUM_UDP:
355 return UDP;
356 case NUM_MUX:
357 return MUX;
358 case NUM_DCN_MEAS:
359 return DCN_MEAS;
360 case NUM_HMP:
361 return HMP;
362 case NUM_PRM:
363 return PRM;
364 case NUM_XNS_IDP:
365 return XNS_IDP;
366 case NUM_TRUNK_1:
367 return TRUNK_1;
368 case NUM_TRUNK_2:
369 return TRUNK_2;
370 case NUM_LEAF_1:
371 return LEAF_1;
372 case NUM_LEAF_2:
373 return LEAF_2;
374 case NUM_RDP:
375 return RDP;
376 case NUM_IRTP:
377 return IRTP;
378 case NUM_ISO_TP4:
379 return ISO_TP4;
380 case NUM_NETBLT:
381 return NETBLT;
382 case NUM_MFE_NSP:
383 return MFE_NSP;
384 case NUM_MERIT_INP:
385 return MERIT_INP;
386 case NUM_DCCP:
387 return DCCP;
388 case NUM_3PC:
389 return _3PC;
390 case NUM_IDPR:
391 return IDPR;
392 case NUM_XTP:
393 return XTP;
394 case NUM_DDP:
395 return DDP;
396 case NUM_IDPR_CMTP:
397 return IDPR_CMTP;
398 case NUM_TP_PP:
399 return TP_PP;
400 case NUM_IL:
401 return IL;
402 case NUM_IPv6:
403 return IPv6;
404 case NUM_SDRP:
405 return SDRP;
406 case NUM_IPv6_ROUTE:
407 return IPv6_ROUTE;
408 case NUM_IPv6_FRAG:
409 return IPv6_FRAG;
410 case NUM_IDRP:
411 return IDRP;
412 case NUM_RSVP:
413 return RSVP;
414 case NUM_GRE:
415 return GRE;
416 case NUM_MHRP:
417 return MHRP;
418 case NUM_BNA:
419 return BNA;
420 case NUM_ESP:
421 return ESP;
422 case NUM_AH:
423 return AH;
424 case NUM_I_NLSP:
425 return I_NLSP;
426 case NUM_SWIPE:
427 return SWIPE;
428 case NUM_NARP:
429 return NARP;
430 case NUM_MOBILE:
431 return MOBILE;
432 case NUM_TLSP:
433 return TLSP;
434 case NUM_SKIP:
435 return SKIP;
436 case NUM_IPv6_ICMP:
437 return IPv6_ICMP;
438 case NUM_IPv6_NO_NXT:
439 return IPv6_NO_NXT;
440 case NUM_IPv6_OPTS:
441 return IPv6_OPTS;
442 case NUM_HOST_INTERNAL:
443 return HOST_INTERNAL;
444 case NUM_CFTP:
445 return CFTP;
446 case NUM_LOCAL_NET:
447 return LOCAL_NET;
448 case NUM_SAT_EXPAK:
449 return SAT_EXPAK;
450 case NUM_KRYPTOLAN:
451 return KRYPTOLAN;
452 case NUM_RVD:
453 return RVD;
454 case NUM_IPPC:
455 return IPPC;
456 case NUM_DIST_FS:
457 return DIST_FS;
458 case NUM_SAT_MON:
459 return SAT_MON;
460 case NUM_VISA:
461 return VISA;
462 case NUM_IPCV:
463 return IPCV;
464 case NUM_CPNX:
465 return CPNX;
466 case NUM_CPHB:
467 return CPHB;
468 case NUM_WSN:
469 return WSN;
470 case NUM_PVP:
471 return PVP;
472 case NUM_BR_SAT_MON:
473 return BR_SAT_MON;
474 case NUM_SUN_ND:
475 return SUN_ND;
476 case NUM_WB_MON:
477 return WB_MON;
478 case NUM_WB_EXPAK:
479 return WB_EXPAK;
480 case NUM_ISO_IP:
481 return ISO_IP;
482 case NUM_VMTP:
483 return VMTP;
484 case NUM_SECURE_VMTP:
485 return SECURE_VMTP;
486 case NUM_VINES:
487 return VINES;
488 case NUM_TTP_IPTM:
489 return TTP_IPTM;
490 case NUM_NSFNET_IGP:
491 return NSFNET_IGP;
492 case NUM_DGP:
493 return DGP;
494 case NUM_TCF:
495 return TCF;
496 case NUM_EIGRP:
497 return EIGRP;
498 case NUM_OSPF:
499 return OSPF;
500 case NUM_Sprite_RPC:
501 return Sprite_RPC;
502 case NUM_LARP:
503 return LARP;
504 case NUM_MTP:
505 return MTP;
506 case NUM_AX_25:
507 return AX_25;
508 case NUM_IPIP:
509 return IPIP;
510 case NUM_MICP:
511 return MICP;
512 case NUM_SCC_SP:
513 return SCC_SP;
514 case NUM_ETHERIP:
515 return ETHERIP;
516 case NUM_ENCAP:
517 return ENCAP;
518 case NUM_PRIVATE_ENCRYPT:
519 return PRIVATE_ENCRYPT;
520 case NUM_GMTP:
521 return GMTP;
522 case NUM_IFMP:
523 return IFMP;
524 case NUM_PNNI:
525 return PNNI;
526 case NUM_PIM:
527 return PIM;
528 case NUM_ARIS:
529 return ARIS;
530 case NUM_SCPS:
531 return SCPS;
532 case NUM_QNX:
533 return QNX;
534 case NUM_A_N:
535 return A_N;
536 case NUM_IP_COMP:
537 return IP_COMP;
538 case NUM_SNP:
539 return SNP;
540 case NUM_COMPAQ_PEER:
541 return COMPAQ_PEER;
542 case NUM_IPX_IN_IP:
543 return IPX_IN_IP;
544 case NUM_VRRP:
545 return VRRP;
546 case NUM_PGM:
547 return PGM;
548 case NUM_ZERO_HOP:
549 return ZERO_HOP;
550 case NUM_L2TP:
551 return L2TP;
552 case NUM_DDX:
553 return DDX;
554 case NUM_IATP:
555 return IATP;
556 case NUM_STP:
557 return STP;
558 case NUM_SRP:
559 return SRP;
560 case NUM_UTI:
561 return UTI;
562 case NUM_SMP:
563 return SMP;
564 case NUM_SM:
565 return SM;
566 case NUM_PTP:
567 return PTP;
568 case NUM_IS_IS_OVER_IPv4:
569 return IS_IS_OVER_IPv4;
570 case NUM_FIRE:
571 return FIRE;
572 case NUM_CRTP:
573 return CRTP;
574 case NUM_CRUDP:
575 return CRUDP;
576 case NUM_SSCOPMCE:
577 return SSCOPMCE;
578 case NUM_IPLT:
579 return IPLT;
580 case NUM_SPS:
581 return SPS;
582 case NUM_PIPE:
583 return PIPE;
584 case NUM_SCTP:
585 return SCTP;
586 case NUM_FC:
587 return FC;
588 case NUM_RSVP_E2E_IGNORE:
589 return RSVP_E2E_IGNORE;
590 case NUM_MOBILITY_HEADER:
591 return MOBILITY_HEADER;
592 case NUM_UDP_LITE:
593 return UDP_LITE;
594 case NUM_MPLS_IN_IP:
595 return MPLS_IN_IP;
596 case NUM_MANET:
597 return MANET;
598 case NUM_HIP:
599 return HIP;
600 case NUM_SHIM6:
601 return SHIM6;
Yotam Harcholf3f11152013-09-05 16:47:16 -0700602 default:
603 if (proto >= MAX_PROTO) {
604 throw new IllegalArgumentException("Illegal IP protocol number: "
605 + proto);
606 } else {
607 return new IpProtocol(proto);
608 }
609 }
610 }
611
612 @Override
Yotam Harcholf3f11152013-09-05 16:47:16 -0700613 public String toString() {
614 return Integer.toHexString(proto);
615 }
Andreas Wundsamb75c4ad2013-09-23 14:45:35 -0700616
Yotam Harcholf3f11152013-09-05 16:47:16 -0700617 public void writeByte(ChannelBuffer c) {
618 c.writeByte(this.proto);
619 }
620
621 public static IpProtocol readByte(ChannelBuffer c) {
622 return IpProtocol.of(c.readUnsignedByte());
623 }
624
625 @Override
626 public IpProtocol applyMask(IpProtocol mask) {
627 return IpProtocol.of((short)(this.proto & mask.proto));
628 }
629
630 public short getIpProtocolNumber() {
631 return proto;
632 }
Andreas Wundsamb75c4ad2013-09-23 14:45:35 -0700633
Andreas Wundsam85c961f2013-09-29 21:22:12 -0700634 @Override
635 public boolean equals(Object obj) {
636 if (!(obj instanceof IpProtocol))
637 return false;
638 IpProtocol o = (IpProtocol)obj;
639 if (o.proto != this.proto)
640 return false;
641 return true;
642 }
643
644 @Override
645 public int hashCode() {
646 final int prime = 37;
647 int result = 1;
648 result = prime * result + proto;
649 return result;
650 }
651
652
653 @Override
654 public int compareTo(IpProtocol o) {
655 return Shorts.compare(proto, o.proto);
656 }
657
658}