blob: c7324676174f44571654ed1b8d9248913e193986 [file] [log] [blame]
Rich Lane629393f2013-01-10 15:37:33 -08001
2# Python OpenFlow instruction wrapper classes
3
ederlffdedc072013-01-18 09:32:00 -02004import struct
Rich Lane629393f2013-01-10 15:37:33 -08005import ipaddr
ederlffdedc072013-01-18 09:32:00 -02006import socket
Rich Lane629393f2013-01-10 15:37:33 -08007from cstruct import *
8
9
ederlffdedc072013-01-18 09:32:00 -020010class oxm_tlv(object):
11 def __init__(self, field, hasmask, length, value, mask=None,
12 class_ = 0x8000):
Rich Lane629393f2013-01-10 15:37:33 -080013 self.class_ = class_
14 self.field = field
15 self.hasmask = hasmask
16 self.length = length
17 self.value = value
18 self.mask = mask
19
ederlffdedc072013-01-18 09:32:00 -020020 def __eq__(self, other):
21 return (self.class_ == other.class_ and self.field == other.field
22 and self.hasmask == other.hasmask and
23 self.length == other.length and self.value == other.value and
24 self.mask == self.mask)
25
Rich Lane629393f2013-01-10 15:37:33 -080026 def pack(self, assertstruct=True):
27
28 packed = ""
ederlffdedc072013-01-18 09:32:00 -020029 packed += struct.pack("!I", ((self.class_ << 16) | (self.field << 9) |
30 (self.hasmask << 8) | self.length))
Rich Lane629393f2013-01-10 15:37:33 -080031 if self.length == 1:
32 packed += struct.pack("B", self.value)
33 if self.hasmask:
34 packed += struct.pack("B", self.mask)
35 elif self.length == 2 or (self.length == 4 and self.hasmask == True):
36 packed += struct.pack("!H", self.value)
37 if self.hasmask:
38 packed += struct.pack("!H", self.mask)
39 elif self.length == 4 or (self.length == 8 and self.hasmask == True):
40 packed += struct.pack("!I", self.value)
41 if self.hasmask:
42 packed += struct.pack("!I", self.mask)
43 elif self.length == 6 or self.length == 12:
ederlffdedc072013-01-18 09:32:00 -020044 packed += struct.pack("!BBBBBB", self.value[0],self.value[1],
45 self.value[2],self.value[3],self.value[4],self.value[5])
Rich Lane629393f2013-01-10 15:37:33 -080046 if self.hasmask:
ederlffdedc072013-01-18 09:32:00 -020047 packed += struct.pack("!BBBBBB", self.mask[0],self.mask[1],
48 self.mask[2],self.mask[3],self.mask[4],self.mask[5])
Rich Lane629393f2013-01-10 15:37:33 -080049 elif self.length == 8 or (self.length == 16 and self.hasmask == True):
50 packed += struct.pack("!Q", self.value)
51 if self.hasmask:
52 packed += struct.pack("!Q", self.mask)
53 elif self.length == 16 or self.length == 32:
54 packed += self.value.packed
55 if self.hasmask:
56 packed += self.mask.packed
57 return packed
58
59 def __len__(self):
60 return self.length + 4
61
62 def show(self, prefix=''):
63 return "\n".join(
64# ("oxm_tlv_class=" + hex(self.class_),
ederlffdedc072013-01-18 09:32:00 -020065 (prefix + "oxm_tlv_class=" + hex(self.class_),
66 prefix + "oxm_tlv_field=" + str(self.field),
67 prefix +"oxm_tlv_hasmask=" + str(bool(self.hasmask)),
68 prefix +"oxm_tlv_length: " + str(self.length) + "\n",))
69
70
71 subclasses = {}
72
73 def set_value(self, value):
74 self.value = value
75
76 def set_hasmask(self, hasmask):
77 self.hasmask = hasmask
78
79 def set_mask(self, mask):
80 self.mask = mask
81
82 @staticmethod
83 def factory():
84 for subclass in oxm_tlv.__subclasses__():
85 obj = subclass()
86 oxm_tlv.subclasses[obj.field] = subclass
87
88 @staticmethod
89 def create(field):
90 return oxm_tlv.subclasses[field]()
91
Rich Lane629393f2013-01-10 15:37:33 -080092
93
94def roundup (x,y):
95 return (((x) + ((y) - 1)) / (y) * (y))
96
97class in_port(oxm_tlv):
98 """
99 Wrapper class for in_port match object
100
101 Data members inherited from oxm_tlv:
102 @arg class
103 @arg field
104 @arg hasmask
105 @arg body
106
107 """
ederlffdedc072013-01-18 09:32:00 -0200108 def __init__(self, value=None, hasmask=False):
Rich Lane629393f2013-01-10 15:37:33 -0800109 oxm_tlv.__init__(self, OFPXMT_OFB_IN_PORT , hasmask, 4, value)
110 def show(self, prefix=''):
ederlffdedc072013-01-18 09:32:00 -0200111 outstr = prefix + "name = in_port\n"
112 outstr += oxm_tlv.show(self, prefix)
113 outstr += prefix + "value = " + str(self.value) +"\n"
Rich Lane629393f2013-01-10 15:37:33 -0800114 return outstr
115
116
117class in_phy_port(oxm_tlv):
118 """
119 Wrapper class for in_phy_port match object
120
121 Data members inherited from oxm_tlv:
122 @arg class
123 @arg field
124 @arg hasmask
125 @arg body
126
127 """
ederlffdedc072013-01-18 09:32:00 -0200128 def __init__(self, value=None, hasmask=False):
Rich Lane629393f2013-01-10 15:37:33 -0800129 oxm_tlv.__init__(self,OFPXMT_OFB_IN_PHY_PORT, hasmask, 4, value)
130 def show(self, prefix=''):
ederlffdedc072013-01-18 09:32:00 -0200131 outstr = prefix + "name = in_phy_port\n"
Rich Lane629393f2013-01-10 15:37:33 -0800132 outstr += oxm_tlv.show(self, prefix)
ederlffdedc072013-01-18 09:32:00 -0200133 outstr += prefix + "value = " + str(self.value) +"\n"
Rich Lane629393f2013-01-10 15:37:33 -0800134 return outstr
135
136
137class metadata(oxm_tlv):
138 """
139 Wrapper class for metadata match object
140
141 Data members inherited from oxm_tlv:
142 @arg class
143 @arg field
144 @arg hasmask
145 @arg body
146
147 """
ederlffdedc072013-01-18 09:32:00 -0200148 def __init__(self, value=None, mask =None):
Rich Lane629393f2013-01-10 15:37:33 -0800149 if mask == None:
150 oxm_tlv.__init__(self, OFPXMT_OFB_METADATA, False, 8, value)
151 else:
152 oxm_tlv.__init__(self, OFPXMT_OFB_METADATA, True, 16, value, mask)
153 def show(self, prefix=''):
ederlffdedc072013-01-18 09:32:00 -0200154 outstr = prefix + "name = metadata\n"
Rich Lane629393f2013-01-10 15:37:33 -0800155 outstr += oxm_tlv.show(self, prefix)
ederlffdedc072013-01-18 09:32:00 -0200156 outstr += prefix + "value = " + str(self.value) +"\n"
Rich Lane629393f2013-01-10 15:37:33 -0800157 return outstr
158
159class eth_dst(oxm_tlv):
160 """
161 Wrapper class for eth_dst match object
162
163 Data members inherited from oxm_tlv:
164 @arg class
165 @arg field
166 @arg hasmask
167 @arg body
168
169 """
ederlffdedc072013-01-18 09:32:00 -0200170 def __init__(self, value=None, mask=None):
Rich Lane629393f2013-01-10 15:37:33 -0800171 if mask == None:
172 oxm_tlv.__init__(self, OFPXMT_OFB_ETH_DST, False, 6, value)
173 else:
174 oxm_tlv.__init__(self, OFPXMT_OFB_ETH_DST, True, 12, value, mask)
175 def show(self, prefix=''):
ederlffdedc072013-01-18 09:32:00 -0200176 outstr = prefix + "name = eth_dst\n"
Rich Lane629393f2013-01-10 15:37:33 -0800177 outstr += oxm_tlv.show(self, prefix)
ederlffdedc072013-01-18 09:32:00 -0200178 outstr += prefix + "value = " + ":".join(["%.2x" %x
179 for x in self.value]) +"\n"
Rich Lane629393f2013-01-10 15:37:33 -0800180 return outstr
181
182class eth_src(oxm_tlv):
183 """
184 Wrapper class for eth_src match object
185
186 Data members inherited from oxm_tlv:
187 @arg class
188 @arg field
189 @arg hasmask
190 @arg body
191
192 """
ederlffdedc072013-01-18 09:32:00 -0200193 def __init__(self, value=None, hasmask=False):
Rich Lane629393f2013-01-10 15:37:33 -0800194 if not hasmask:
195 oxm_tlv.__init__(self, OFPXMT_OFB_ETH_SRC, hasmask, 6, value)
196 else:
ederlffdedc072013-01-18 09:32:00 -0200197 oxm_tlv.__init__(self, OFPXMT_OFB_ETH_SRC, hasmask, 12,
198 value, mask)
Rich Lane629393f2013-01-10 15:37:33 -0800199 def show(self, prefix=''):
ederlffdedc072013-01-18 09:32:00 -0200200 outstr = prefix + "name = eth_src\n"
Rich Lane629393f2013-01-10 15:37:33 -0800201 outstr += oxm_tlv.show(self, prefix)
ederlffdedc072013-01-18 09:32:00 -0200202 outstr += prefix + "value = " + ":".join(["%.2x" %x
203 for x in self.value]) +"\n"
Rich Lane629393f2013-01-10 15:37:33 -0800204 return outstr
205
206class eth_type(oxm_tlv):
207 """
208 Wrapper class for eth_type match object
209
210 Data members inherited from oxm_tlv:
211 @arg class
212 @arg field
213 @arg hasmask
214 @arg body
215
216 """
ederlffdedc072013-01-18 09:32:00 -0200217 def __init__(self, value=None, hasmask=False):
Rich Lane629393f2013-01-10 15:37:33 -0800218 oxm_tlv.__init__(self, OFPXMT_OFB_ETH_TYPE, hasmask, 2, value)
219 def show(self, prefix=''):
ederlffdedc072013-01-18 09:32:00 -0200220 outstr = prefix + "name = eth_type\n"
Rich Lane629393f2013-01-10 15:37:33 -0800221 outstr += oxm_tlv.show(self, prefix)
ederlffdedc072013-01-18 09:32:00 -0200222 outstr += prefix + "value = " + hex(self.value) +"\n"
Rich Lane629393f2013-01-10 15:37:33 -0800223 return outstr
224
225class vlan_vid(oxm_tlv):
226 """
227 Wrapper class for vlan_vid match object
228
229 Data members inherited from oxm_tlv:
230 @arg class
231 @arg field
232 @arg hasmask
233 @arg body
234
235 """
ederlffdedc072013-01-18 09:32:00 -0200236 def __init__(self, value=None, hasmask=False):
Rich Lane629393f2013-01-10 15:37:33 -0800237 oxm_tlv.__init__(self, OFPXMT_OFB_VLAN_VID, hasmask, 2, value)
238 def show(self, prefix=''):
ederlffdedc072013-01-18 09:32:00 -0200239 outstr = prefix + "name = vlan_vid\n"
Rich Lane629393f2013-01-10 15:37:33 -0800240 outstr += oxm_tlv.show(self, prefix)
ederlffdedc072013-01-18 09:32:00 -0200241 outstr += prefix + "value = " + str(self.value) +"\n"
Rich Lane629393f2013-01-10 15:37:33 -0800242 return outstr
243
244class vlan_pcp(oxm_tlv):
245 """
246 Wrapper class for vlan_pcp match object
247
248 Data members inherited from oxm_tlv:
249 @arg class
250 @arg field
251 @arg hasmask
252 @arg body
253
254 """
ederlffdedc072013-01-18 09:32:00 -0200255 def __init__(self, value=None, hasmask=False):
Rich Lane629393f2013-01-10 15:37:33 -0800256 oxm_tlv.__init__(self, OFPXMT_OFB_VLAN_PCP, hasmask, 1, value)
257 def show(self, prefix=''):
ederlffdedc072013-01-18 09:32:00 -0200258 outstr = prefix + "name = vlan_pcp\n"
Rich Lane629393f2013-01-10 15:37:33 -0800259 outstr += oxm_tlv.show(self, prefix)
ederlffdedc072013-01-18 09:32:00 -0200260 outstr += prefix + "value = " + str(self.value) +"\n"
Rich Lane629393f2013-01-10 15:37:33 -0800261 return outstr
262
263class ip_dscp(oxm_tlv):
264 """
265 Wrapper class for ip_dscp match object
266
267 Data members inherited from oxm_tlv:
268 @arg class
269 @arg field
270 @arg hasmask
271 @arg body
272
273 """
ederlffdedc072013-01-18 09:32:00 -0200274 def __init__(self, value=None, hasmask=False):
Rich Lane629393f2013-01-10 15:37:33 -0800275 oxm_tlv.__init__(self, OFPXMT_OFB_IP_DSCP, hasmask, 1, value)
276 def show(self, prefix=''):
ederlffdedc072013-01-18 09:32:00 -0200277 outstr = prefix + "name = ip_dscp\n"
Rich Lane629393f2013-01-10 15:37:33 -0800278 outstr += oxm_tlv.show(self, prefix)
ederlffdedc072013-01-18 09:32:00 -0200279 outstr += prefix + "value = " + str(self.value) +"\n"
Rich Lane629393f2013-01-10 15:37:33 -0800280 return outstr
281
282class ip_ecn(oxm_tlv):
283 """
284 Wrapper class for ip_dscp match object
285
286 Data members inherited from oxm_tlv:
287 @arg class
288 @arg field
289 @arg hasmask
290 @arg body
291
292 """
ederlffdedc072013-01-18 09:32:00 -0200293 def __init__(self, value=None, hasmask=False):
Rich Lane629393f2013-01-10 15:37:33 -0800294 oxm_tlv.__init__(self, OFPXMT_OFB_IP_ECN, hasmask, 1, value)
295 def show(self, prefix=''):
ederlffdedc072013-01-18 09:32:00 -0200296 outstr = prefix + "name = ip_ecn\n"
Rich Lane629393f2013-01-10 15:37:33 -0800297 outstr += oxm_tlv.show(self, prefix)
ederlffdedc072013-01-18 09:32:00 -0200298 outstr += prefix + "value = " + str(self.value) +"\n"
Rich Lane629393f2013-01-10 15:37:33 -0800299 return outstr
300
301class ip_proto(oxm_tlv):
302 """
303 Wrapper class for ip_proto match object
304
305 Data members inherited from oxm_tlv:
306 @arg class
307 @arg field
308 @arg hasmask
309 @arg body
310
311 """
ederlffdedc072013-01-18 09:32:00 -0200312 def __init__(self, value=None, hasmask=False):
Rich Lane629393f2013-01-10 15:37:33 -0800313 oxm_tlv.__init__(self, OFPXMT_OFB_IP_PROTO, hasmask, 1, value)
314 def show(self, prefix=''):
ederlffdedc072013-01-18 09:32:00 -0200315 outstr = prefix + "name = ip_proto\n"
Rich Lane629393f2013-01-10 15:37:33 -0800316 outstr += oxm_tlv.show(self, prefix)
ederlffdedc072013-01-18 09:32:00 -0200317 outstr += prefix + "value = " + str(self.value) +"\n"
Rich Lane629393f2013-01-10 15:37:33 -0800318 return outstr
319
320class ipv4_src(oxm_tlv):
321 """
322 Wrapper class for ipv4_src match object
323
324 Data members inherited from oxm_tlv:
325 @arg class
326 @arg field
327 @arg hasmask
328 @arg body
329
330 """
ederlffdedc072013-01-18 09:32:00 -0200331 def __init__(self, value=None, hasmask=False):
Rich Lane629393f2013-01-10 15:37:33 -0800332 if not hasmask:
333 oxm_tlv.__init__(self, OFPXMT_OFB_IPV4_SRC, hasmask, 4, value)
334 else:
335 oxm_tlv.__init__(self, OFPXMT_OFB_IPV4_SRC, hasmask, 4, value, mask)
336 def show(self, prefix=''):
ederlffdedc072013-01-18 09:32:00 -0200337 outstr = prefix + "name = ipv4_src\n"
Rich Lane629393f2013-01-10 15:37:33 -0800338 outstr += oxm_tlv.show(self, prefix)
ederlffdedc072013-01-18 09:32:00 -0200339 #Value can be a long int or a string
340 try:
341 addr = ipaddr.IPv4Address(self.value)
342 except ValueError:
343 addr = ipaddr.IPv4Address(int(self.value, 16))
344 outstr += prefix + "value = " + str(addr) +"\n"
Rich Lane629393f2013-01-10 15:37:33 -0800345 return outstr
346
347class ipv4_dst(oxm_tlv):
348 """
349 Wrapper class for ipv4_dst match object
350
351 Data members inherited from oxm_tlv:
352 @arg class
353 @arg field
354 @arg hasmask
355 @arg body
356
357 """
ederlffdedc072013-01-18 09:32:00 -0200358 def __init__(self, value=None, hasmask=False):
Rich Lane629393f2013-01-10 15:37:33 -0800359 if not hasmask:
360 oxm_tlv.__init__(self, OFPXMT_OFB_IPV4_DST, hasmask, 4, value)
361 else:
362 oxm_tlv.__init__(self, OFPXMT_OFB_IPV4_DST, hasmask, 4, value, mask)
363 def show(self, prefix=''):
ederlffdedc072013-01-18 09:32:00 -0200364 outstr = prefix + "name = ipv4_dst\n"
Rich Lane629393f2013-01-10 15:37:33 -0800365 outstr += oxm_tlv.show(self, prefix)
ederlffdedc072013-01-18 09:32:00 -0200366 #Value can be a long int or a string
367 #try:
368 addr = ipaddr.IPv4Address(self.value)
369 #except ValueError:
370 # addr = ipaddr.IPv4Address(int(self.value, 16))
371 outstr += prefix + "value = " + str(addr) +"\n"
Rich Lane629393f2013-01-10 15:37:33 -0800372 return outstr
373
374class tcp_src(oxm_tlv):
375 """
376 Wrapper class for tcp_src match object
377
378 Data members inherited from oxm_tlv:
379 @arg class
380 @arg field
381 @arg hasmask
382 @arg body
383
384 """
ederlffdedc072013-01-18 09:32:00 -0200385 def __init__(self, value=None, hasmask=False):
Rich Lane629393f2013-01-10 15:37:33 -0800386 oxm_tlv.__init__(self, OFPXMT_OFB_TCP_SRC, hasmask, 2, value)
387 def show(self, prefix=''):
ederlffdedc072013-01-18 09:32:00 -0200388 outstr = prefix + "name = tcp_src\n"
Rich Lane629393f2013-01-10 15:37:33 -0800389 outstr += oxm_tlv.show(self, prefix)
ederlffdedc072013-01-18 09:32:00 -0200390 outstr += prefix + "value = " + str(self.value) +"\n"
Rich Lane629393f2013-01-10 15:37:33 -0800391 return outstr
392
393class tcp_dst(oxm_tlv):
394 """
395 Wrapper class for tcp_src match object
396
397 Data members inherited from oxm_tlv:
398 @arg class
399 @arg field
400 @arg hasmask
401 @arg body
402
403 """
ederlffdedc072013-01-18 09:32:00 -0200404 def __init__(self, value=None, hasmask=False):
Rich Lane629393f2013-01-10 15:37:33 -0800405 oxm_tlv.__init__(self, OFPXMT_OFB_TCP_DST, hasmask, 2, value)
406 def show(self, prefix=''):
ederlffdedc072013-01-18 09:32:00 -0200407 outstr = prefix + "name = tcp_dst\n"
Rich Lane629393f2013-01-10 15:37:33 -0800408 outstr += oxm_tlv.show(self, prefix)
ederlffdedc072013-01-18 09:32:00 -0200409 outstr += prefix + "value = " + str(self.value) +"\n"
Rich Lane629393f2013-01-10 15:37:33 -0800410 return outstr
411
412class udp_src(oxm_tlv):
413 """
414 Wrapper class for udp_src match object
415
416 Data members inherited from oxm_tlv:
417 @arg class
418 @arg field
419 @arg hasmask
420 @arg body
421
422 """
ederlffdedc072013-01-18 09:32:00 -0200423 def __init__(self, value=None, hasmask=False):
Rich Lane629393f2013-01-10 15:37:33 -0800424 oxm_tlv.__init__(self, OFPXMT_OFB_UDP_SRC, hasmask, 2, value)
425 def show(self, prefix=''):
ederlffdedc072013-01-18 09:32:00 -0200426 outstr = prefix + "name = udp_src\n"
Rich Lane629393f2013-01-10 15:37:33 -0800427 outstr += oxm_tlv.show(self, prefix)
ederlffdedc072013-01-18 09:32:00 -0200428 outstr += prefix + "value = " + str(self.value) +"\n"
Rich Lane629393f2013-01-10 15:37:33 -0800429 return outstr
430
431class udp_dst(oxm_tlv):
432 """
433 Wrapper class for udp_dst match object
434
435 Data members inherited from oxm_tlv:
436 @arg class
437 @arg field
438 @arg hasmask
439 @arg body
440
441 """
ederlffdedc072013-01-18 09:32:00 -0200442 def __init__(self, value=None, hasmask=False):
Rich Lane629393f2013-01-10 15:37:33 -0800443 oxm_tlv.__init__(self, OFPXMT_OFB_UDP_DST, hasmask, 2, value)
444 def show(self, prefix=''):
ederlffdedc072013-01-18 09:32:00 -0200445 outstr = prefix + "name = udp_dst\n"
Rich Lane629393f2013-01-10 15:37:33 -0800446 outstr += oxm_tlv.show(self, prefix)
ederlffdedc072013-01-18 09:32:00 -0200447 outstr += prefix + "value = " + str(self.value) +"\n"
Rich Lane629393f2013-01-10 15:37:33 -0800448 return outstr
449
450class sctp_src(oxm_tlv):
451 """
452 Wrapper class for sctp_src match object
453
454 Data members inherited from oxm_tlv:
455 @arg class
456 @arg field
457 @arg hasmask
458 @arg body
459
460 """
ederlffdedc072013-01-18 09:32:00 -0200461 def __init__(self, value=None, hasmask=False):
Rich Lane629393f2013-01-10 15:37:33 -0800462 oxm_tlv.__init__(self, OFPXMT_OFB_SCTP_SRC, hasmask, 2, value)
463 def show(self, prefix=''):
ederlffdedc072013-01-18 09:32:00 -0200464 outstr = prefix + "name = sctp_src\n"
Rich Lane629393f2013-01-10 15:37:33 -0800465 outstr += oxm_tlv.show(self, prefix)
ederlffdedc072013-01-18 09:32:00 -0200466 outstr += prefix + "value = " + str(self.value) +"\n"
Rich Lane629393f2013-01-10 15:37:33 -0800467 return outstr
468
469
470class sctp_dst(oxm_tlv):
471 """
472 Wrapper class for sctp_dst match object
473
474 Data members inherited from oxm_tlv:
475 @arg class
476 @arg field
477 @arg hasmask
478 @arg body
479
480 """
ederlffdedc072013-01-18 09:32:00 -0200481 def __init__(self, value=None, hasmask=False):
Rich Lane629393f2013-01-10 15:37:33 -0800482 oxm_tlv.__init__(self, OFPXMT_OFB_SCTP_DST, hasmask, 2, value)
483 def show(self, prefix=''):
ederlffdedc072013-01-18 09:32:00 -0200484 outstr = prefix + "name = sctp_dst\n"
Rich Lane629393f2013-01-10 15:37:33 -0800485 outstr += oxm_tlv.show(self, prefix)
ederlffdedc072013-01-18 09:32:00 -0200486 outstr += prefix + "value = " + str(self.value) +"\n"
Rich Lane629393f2013-01-10 15:37:33 -0800487 return outstr
488
489class icmpv4_type(oxm_tlv):
490 """
491 Wrapper class for icmpv4_type match object
492
493 Data members inherited from oxm_tlv:
494 @arg class
495 @arg field
496 @arg hasmask
497 @arg body
498
499 """
ederlffdedc072013-01-18 09:32:00 -0200500 def __init__(self, value=None, hasmask=False):
Rich Lane629393f2013-01-10 15:37:33 -0800501 oxm_tlv.__init__(self, OFPXMT_OFB_ICMPV4_TYPE, hasmask, 1, value)
502 def show(self, prefix=''):
ederlffdedc072013-01-18 09:32:00 -0200503 outstr = prefix + "name = icmpv4_type\n"
Rich Lane629393f2013-01-10 15:37:33 -0800504 outstr += oxm_tlv.show(self, prefix)
ederlffdedc072013-01-18 09:32:00 -0200505 outstr += prefix + "value = " + str(self.value) +"\n"
Rich Lane629393f2013-01-10 15:37:33 -0800506 return outstr
507
508class icmpv4_code(oxm_tlv):
509 """
510 Wrapper class for icmpv4_code match object
511
512 Data members inherited from oxm_tlv:
513 @arg class
514 @arg field
515 @arg hasmask
516 @arg body
517
518 """
ederlffdedc072013-01-18 09:32:00 -0200519 def __init__(self, value=None, hasmask=False):
Rich Lane629393f2013-01-10 15:37:33 -0800520 oxm_tlv.__init__(self, OFPXMT_OFB_ICMPV4_CODE, hasmask, 1, value)
521 def show(self, prefix=''):
ederlffdedc072013-01-18 09:32:00 -0200522 outstr = prefix + "name = icmpv4_code\n"
Rich Lane629393f2013-01-10 15:37:33 -0800523 outstr += oxm_tlv.show(self, prefix)
ederlffdedc072013-01-18 09:32:00 -0200524 outstr += prefix + "value = " + str(self.value) +"\n"
Rich Lane629393f2013-01-10 15:37:33 -0800525 return outs
526
527class arp_op(oxm_tlv):
528 """
529 Wrapper class for arp_op match object
530
531 Data members inherited from oxm_tlv:
532 @arg class
533 @arg field
534 @arg hasmask
535 @arg body
536
537 """
ederlffdedc072013-01-18 09:32:00 -0200538 def __init__(self, value=None, hasmask=False):
Rich Lane629393f2013-01-10 15:37:33 -0800539 oxm_tlv.__init__(self, OFPXMT_OFB_ARP_OP, hasmask, 2, value)
540 def show(self, prefix=''):
ederlffdedc072013-01-18 09:32:00 -0200541 outstr = prefix + "name = arp_op\n"
Rich Lane629393f2013-01-10 15:37:33 -0800542 outstr += oxm_tlv.show(self, prefix)
ederlffdedc072013-01-18 09:32:00 -0200543 outstr += prefix + "value = " + str(self.value) +"\n"
Rich Lane629393f2013-01-10 15:37:33 -0800544 return outs
545
546class arp_spa(oxm_tlv):
547 """
548 Wrapper class for arp_spa match object
549
550 Data members inherited from oxm_tlv:
551 @arg class
552 @arg field
553 @arg hasmask
554 @arg body
555
556 """
ederlffdedc072013-01-18 09:32:00 -0200557 def __init__(self, value=None, hasmask=False):
Rich Lane629393f2013-01-10 15:37:33 -0800558 if not hasmask:
559 oxm_tlv.__init__(self, OFPXMT_OFB_ARP_SPA, hasmask, 4, value)
560 else:
561 oxm_tlv.__init__(self, OFPXMT_OFB_ARP_SPA, hasmask, 4, value, mask)
562 def show(self, prefix=''):
ederlffdedc072013-01-18 09:32:00 -0200563 outstr = prefix + "name = arp_spa\n"
564 #Value can be a long int or a string
565 try:
566 addr = ipaddr.IPv4Address(self.value)
567 except ValueError:
568 addr = ipaddr.IPv4Address(int(self.value, 16))
Rich Lane629393f2013-01-10 15:37:33 -0800569 outstr += oxm_tlv.show(self, prefix)
ederlffdedc072013-01-18 09:32:00 -0200570 outstr += prefix + "value = " + str(addr) +"\n"
Rich Lane629393f2013-01-10 15:37:33 -0800571 return outstr
572
573class arp_tpa(oxm_tlv):
574 """
575 Wrapper class for arp_tpa match object
576
577 Data members inherited from oxm_tlv:
578 @arg class
579 @arg field
580 @arg hasmask
581 @arg body
582
583 """
ederlffdedc072013-01-18 09:32:00 -0200584 def __init__(self, value=None, hasmask=False):
Rich Lane629393f2013-01-10 15:37:33 -0800585 if not hasmask:
586 oxm_tlv.__init__(self, OFPXMT_OFB_ARP_TPA, hasmask, 4, value)
587 else:
588 oxm_tlv.__init__(self, OFPXMT_OFB_ARP_TPA, hasmask, 4, value, mask)
589 def show(self, prefix=''):
ederlffdedc072013-01-18 09:32:00 -0200590 outstr = prefix + "name = arp_tpa\n"
591 #Value can be a long int or a string
592 try:
593 addr = ipaddr.IPv4Address(self.value)
594 except ValueError:
595 addr = ipaddr.IPv4Address(int(self.value, 16))
Rich Lane629393f2013-01-10 15:37:33 -0800596 outstr += oxm_tlv.show(self, prefix)
ederlffdedc072013-01-18 09:32:00 -0200597 outstr += prefix + "value = " + ":".join(["%.2x" %x
598 for x in self.value]) +"\n"
Rich Lane629393f2013-01-10 15:37:33 -0800599 return outstr
600
601
602class arp_sha(oxm_tlv):
603 """
604 Wrapper class for arp_sha match object
605
606 Data members inherited from oxm_tlv:
607 @arg class
608 @arg field
609 @arg hasmask
610 @arg body
611
612 """
ederlffdedc072013-01-18 09:32:00 -0200613 def __init__(self, value=None, hasmask=False):
Rich Lane629393f2013-01-10 15:37:33 -0800614 if not hasmask:
615 oxm_tlv.__init__(self, OFPXMT_OFB_ARP_SHA, hasmask, 6, value)
616 else:
617 oxm_tlv.__init__(self, OFPXMT_OFB_ARP_SHA, hasmask, 12, value)
618 def show(self, prefix=''):
ederlffdedc072013-01-18 09:32:00 -0200619 outstr = prefix + "name = arp_sha\n"
Rich Lane629393f2013-01-10 15:37:33 -0800620 outstr += oxm_tlv.show(self, prefix)
ederlffdedc072013-01-18 09:32:00 -0200621 outstr += prefix + "value = " + ":".join(["%.2x" %x
622 for x in self.value]) +"\n"
Rich Lane629393f2013-01-10 15:37:33 -0800623 return outstr
624
625class arp_tha(oxm_tlv):
626 """
627 Wrapper class for arp_tha match object
628
629 Data members inherited from oxm_tlv:
630 @arg class
631 @arg field
632 @arg hasmask
633 @arg body
634
635 """
ederlffdedc072013-01-18 09:32:00 -0200636 def __init__(self, value=None, hasmask=False):
Rich Lane629393f2013-01-10 15:37:33 -0800637 if not hasmask:
638 oxm_tlv.__init__(self, OFPXMT_OFB_ARP_THA, hasmask, 6, value)
639 else:
640 oxm_tlv.__init__(self, OFPXMT_OFB_ARP_THA, hasmask, 12, value)
641 def show(self, prefix=''):
ederlffdedc072013-01-18 09:32:00 -0200642 outstr = prefix + "name = arp_tha\n"
Rich Lane629393f2013-01-10 15:37:33 -0800643 outstr += oxm_tlv.show(self, prefix)
ederlffdedc072013-01-18 09:32:00 -0200644 outstr += prefix + "value = " + str(self.value) +"\n"
Rich Lane629393f2013-01-10 15:37:33 -0800645 return outstr
646
647class ipv6_src(oxm_tlv):
648 """
649 Wrapper class for ipv6_src match object
650
651 Data members inherited from oxm_tlv:
652 @arg class
653 @arg field
654 @arg hasmask
655 @arg body
656
657 """
ederlffdedc072013-01-18 09:32:00 -0200658 def __init__(self, value=None, hasmask=False):
Rich Lane629393f2013-01-10 15:37:33 -0800659 if not hasmask:
660 oxm_tlv.__init__(self, OFPXMT_OFB_IPV6_SRC, False, 16, value)
661 else:
662 oxm_tlv.__init__(self, OFPXMT_OFB_IPV6_SRC, True, 32, value)
663 def show(self, prefix=''):
ederlffdedc072013-01-18 09:32:00 -0200664 outstr = prefix + "name = ipv6_src\n"
665 try:
666 addr = ipaddr.IPv6Address(self.value)
667 except ValueError:
668 addr = ipaddr.IPv6Address(int(self.value, 16))
Rich Lane629393f2013-01-10 15:37:33 -0800669 outstr += oxm_tlv.show(self, prefix)
ederlffdedc072013-01-18 09:32:00 -0200670 outstr += prefix + "value = " + str(addr) +"\n"
Rich Lane629393f2013-01-10 15:37:33 -0800671 return outstr
672
673class ipv6_dst(oxm_tlv):
674 """
675 Wrapper class for ipv6_dst match object
676
677 Data members inherited from oxm_tlv:
678 @arg class
679 @arg field
680 @arg hasmask
681 @arg body
682
683 """
ederlffdedc072013-01-18 09:32:00 -0200684 def __init__(self, value=None, hasmask=False):
Rich Lane629393f2013-01-10 15:37:33 -0800685 if not hasmask:
686 oxm_tlv.__init__(self, OFPXMT_OFB_IPV6_DST, False, 16, value)
687 else:
688 oxm_tlv.__init__(self, OFPXMT_OFB_IPV6_DST, True, 32, value)
689 def show(self, prefix=''):
ederlffdedc072013-01-18 09:32:00 -0200690 outstr = prefix + "name = ipv6_dst\n"
691 try:
692 addr = ipaddr.IPv6Address(self.value)
693 except ValueError:
694 addr = ipaddr.IPv6Address(int(self.value, 16))
Rich Lane629393f2013-01-10 15:37:33 -0800695 outstr += oxm_tlv.show(self, prefix)
ederlffdedc072013-01-18 09:32:00 -0200696 outstr += prefix + "value = " + str(addr) +"\n"
Rich Lane629393f2013-01-10 15:37:33 -0800697 return outstr
698
699class ipv6_flabel(oxm_tlv):
700 """
701 Wrapper class for ipv6_flabel match object
702
703 Data members inherited from oxm_tlv:
704 @arg class
705 @arg field
706 @arg hasmask
707 @arg body
708
709 """
ederlffdedc072013-01-18 09:32:00 -0200710 def __init__(self, value=None, hasmask=False):
Rich Lane629393f2013-01-10 15:37:33 -0800711 if not hasmask:
712 oxm_tlv.__init__(self, OFPXMT_OFB_IPV6_FLABEL, hasmask, 4, value)
713 else:
714 oxm_tlv.__init__(self, OFPXMT_OFB_IPV6_FLABEL, hasmask, 8, value)
715 def show(self, prefix=''):
ederlffdedc072013-01-18 09:32:00 -0200716 outstr = prefix + "name = ipv6_flabel\n"
Rich Lane629393f2013-01-10 15:37:33 -0800717 outstr += oxm_tlv.show(self, prefix)
718 return outstr
719
720class icmpv6_type(oxm_tlv):
721 """
722 Wrapper class for icmpv6_type match object
723
724 Data members inherited from oxm_tlv:
725 @arg class
726 @arg field
727 @arg hasmask
728 @arg body
729
730 """
ederlffdedc072013-01-18 09:32:00 -0200731 def __init__(self, value=None, hasmask=False):
Rich Lane629393f2013-01-10 15:37:33 -0800732 oxm_tlv.__init__(self, OFPXMT_OFB_ICMPV6_TYPE, hasmask, 1, value)
733 def show(self, prefix=''):
ederlffdedc072013-01-18 09:32:00 -0200734 outstr = prefix + "name = icmpv6_type\n"
Rich Lane629393f2013-01-10 15:37:33 -0800735 outstr += oxm_tlv.show(self, prefix)
ederlffdedc072013-01-18 09:32:00 -0200736 outstr += prefix + "value = " + str(self.value) +"\n"
Rich Lane629393f2013-01-10 15:37:33 -0800737 return outstr
738
739class icmpv6_code(oxm_tlv):
740 """
741 Wrapper class for icmpv6_code match object
742
743 Data members inherited from oxm_tlv:
744 @arg class
745 @arg field
746 @arg hasmask
747 @arg body
748
749 """
ederlffdedc072013-01-18 09:32:00 -0200750 def __init__(self, value=None, hasmask=False):
Rich Lane629393f2013-01-10 15:37:33 -0800751 oxm_tlv.__init__(self, OFPXMT_OFB_ICMPV6_CODE, hasmask, 1, value)
752 def show(self, prefix=''):
ederlffdedc072013-01-18 09:32:00 -0200753 outstr = prefix + "name = icmpv6_code\n"
Rich Lane629393f2013-01-10 15:37:33 -0800754 outstr += oxm_tlv.show(self, prefix)
ederlffdedc072013-01-18 09:32:00 -0200755 outstr += prefix + "value = " + str(self.value) +"\n"
Rich Lane629393f2013-01-10 15:37:33 -0800756 return outs
757
758class ipv6_nd_target(oxm_tlv):
759 """
760 Wrapper class for ipv6_nd_target match object
761
762 Data members inherited from oxm_tlv:
763 @arg class
764 @arg field
765 @arg hasmask
766 @arg body
767
768 """
ederlffdedc072013-01-18 09:32:00 -0200769 def __init__(self, value=None, hasmask=False):
Rich Lane629393f2013-01-10 15:37:33 -0800770 oxm_tlv.__init__(self, OFPXMT_OFB_IPV6_ND_TARGET, hasmask, 16, value)
771 def show(self, prefix=''):
ederlffdedc072013-01-18 09:32:00 -0200772 outstr = prefix + "name = ipv6_nd_target\n"
773 try:
774 addr = ipaddr.IPv6Address(self.value)
775 except ValueError:
776 addr = ipaddr.IPv6Address(int(self.value, 16))
Rich Lane629393f2013-01-10 15:37:33 -0800777 outstr += oxm_tlv.show(self, prefix)
ederlffdedc072013-01-18 09:32:00 -0200778 outstr += prefix + "value = " + str(addr) +"\n"
Rich Lane629393f2013-01-10 15:37:33 -0800779 return outstr
780
781class ipv6_nd_sll(oxm_tlv):
782 """
783 Wrapper class for ipv6_nd_sll match object
784
785 Data members inherited from oxm_tlv:
786 @arg class
787 @arg field
788 @arg hasmask
789 @arg body
790
791 """
ederlffdedc072013-01-18 09:32:00 -0200792 def __init__(self, value=None, hasmask=False):
Rich Lane629393f2013-01-10 15:37:33 -0800793 oxm_tlv.__init__(self, OFPXMT_OFB_IPV6_ND_SLL, hasmask, 6, value)
794 def show(self, prefix=''):
ederlffdedc072013-01-18 09:32:00 -0200795 outstr = prefix + "name = ipv6_nd_sll\n"
Rich Lane629393f2013-01-10 15:37:33 -0800796 outstr += oxm_tlv.show(self, prefix)
ederlffdedc072013-01-18 09:32:00 -0200797 outstr += prefix + "value = " + str(self.value) +"\n"
Rich Lane629393f2013-01-10 15:37:33 -0800798 return outstr
799
800class ipv6_nd_tll(oxm_tlv):
801 """
802 Wrapper class for ipv6_nd_tll match object
803
804 Data members inherited from oxm_tlv:
805 @arg class
806 @arg field
807 @arg hasmask
808 @arg body
809
810 """
ederlffdedc072013-01-18 09:32:00 -0200811 def __init__(self, value=None, hasmask=False):
Rich Lane629393f2013-01-10 15:37:33 -0800812 oxm_tlv.__init__(self, OFPXMT_OFB_IPV6_ND_TLL, hasmask, 6, value)
813 def show(self, prefix=''):
ederlffdedc072013-01-18 09:32:00 -0200814 outstr = prefix + "name = ipv6_nd_tll\n"
Rich Lane629393f2013-01-10 15:37:33 -0800815 outstr += oxm_tlv.show(self, prefix)
ederlffdedc072013-01-18 09:32:00 -0200816 outstr += prefix + "value = " + str(self.value) +"\n"
Rich Lane629393f2013-01-10 15:37:33 -0800817 return outstr
818
819class mpls_label(oxm_tlv):
820 """
821 Wrapper class for mpls_label match object
822
823 Data members inherited from oxm_tlv:
824 @arg class
825 @arg field
826 @arg hasmask
827 @arg body
828
829 """
ederlffdedc072013-01-18 09:32:00 -0200830 def __init__(self, value=None, hasmask=False):
Rich Lane629393f2013-01-10 15:37:33 -0800831 oxm_tlv.__init__(self, OFPXMT_OFB_MPLS_LABEL, hasmask, 4, value)
832 def show(self, prefix=''):
ederlffdedc072013-01-18 09:32:00 -0200833 outstr = prefix + "name = mpls_label\n"
Rich Lane629393f2013-01-10 15:37:33 -0800834 outstr += oxm_tlv.show(self, prefix)
ederlffdedc072013-01-18 09:32:00 -0200835 outstr += prefix + "value = " + str(self.value) +"\n"
Rich Lane629393f2013-01-10 15:37:33 -0800836 return outstr
837
838class mpls_tc(oxm_tlv):
839 """
840 Wrapper class for mpls_ltc match object
841
842 Data members inherited from oxm_tlv:
843 @arg class
844 @arg field
845 @arg hasmask
846 @arg body
847
848 """
ederlffdedc072013-01-18 09:32:00 -0200849 def __init__(self, value=None, hasmask=False):
Rich Lane629393f2013-01-10 15:37:33 -0800850 oxm_tlv.__init__(self, OFPXMT_OFB_MPLS_TC, hasmask, 1, value)
851 def show(self, prefix=''):
ederlffdedc072013-01-18 09:32:00 -0200852 outstr = prefix + "name = mpls_tc\n"
Rich Lane629393f2013-01-10 15:37:33 -0800853 outstr += oxm_tlv.show(self, prefix)
ederlffdedc072013-01-18 09:32:00 -0200854 outstr += prefix + "value = " + str(self.value) +"\n"
Rich Lane629393f2013-01-10 15:37:33 -0800855 return outstr
856
857match_class_list = (
858 in_port,
859 in_phy_port,
860 metadata,
861 eth_dst,
862 eth_src,
863 eth_type,
864 vlan_vid,
865 vlan_pcp,
866 ip_dscp,
867 ip_ecn,
868 ip_proto,
869 ipv4_src,
870 ipv4_dst,
871 tcp_src,
872 tcp_dst,
873 udp_src,
874 udp_dst,
875 sctp_src,
876 sctp_dst,
877 icmpv4_type,
878 icmpv4_code,
879 arp_op,
880 arp_spa,
881 arp_tpa,
882 arp_sha,
883 arp_tha,
884 ipv6_src,
885 ipv6_dst,
886 ipv6_flabel,
887 icmpv6_type,
888 icmpv6_code,
889 ipv6_nd_target,
890 ipv6_nd_sll,
891 ipv6_nd_tll,
892 mpls_label,
893 mpls_tc)