blob: b95b3c46cbd00f1b36b9b214aa46c2f964bacf17 [file] [log] [blame]
Rich Lanec2ee4b82013-04-24 17:12:38 -07001# Copyright (c) 2008 The Board of Trustees of The Leland Stanford Junior University
2# Copyright (c) 2011, 2012 Open Networking Foundation
3# Copyright (c) 2012, 2013 Big Switch Networks, Inc.
Rich Laneb658ddd2013-03-12 10:15:10 -07004
5# Automatically generated by LOXI from template message.py
6# Do not modify
7
8import struct
9import loxi
10import const
11import common
12import action # for unpack_list
13import util
Rich Lanec2ee4b82013-04-24 17:12:38 -070014import loxi.generic_util
Rich Laneb658ddd2013-03-12 10:15:10 -070015
16class Message(object):
17 version = const.OFP_VERSION
18 type = None # override in subclass
19 xid = None
20
21class aggregate_stats_reply(Message):
22 version = const.OFP_VERSION
23 type = const.OFPT_STATS_REPLY
24 stats_type = const.OFPST_AGGREGATE
25
Rich Lanec2ee4b82013-04-24 17:12:38 -070026 def __init__(self, xid=None, flags=None, packet_count=None, byte_count=None, flow_count=None):
Rich Laneb658ddd2013-03-12 10:15:10 -070027 self.xid = xid
28 if flags != None:
29 self.flags = flags
30 else:
31 self.flags = 0
32 if packet_count != None:
33 self.packet_count = packet_count
34 else:
35 self.packet_count = 0
36 if byte_count != None:
37 self.byte_count = byte_count
38 else:
39 self.byte_count = 0
40 if flow_count != None:
41 self.flow_count = flow_count
42 else:
43 self.flow_count = 0
Rich Laneb658ddd2013-03-12 10:15:10 -070044
45 def pack(self):
46 packed = []
47 packed.append(struct.pack("!B", self.version))
48 packed.append(struct.pack("!B", self.type))
49 packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
50 packed.append(struct.pack("!L", self.xid))
51 packed.append(struct.pack("!H", self.stats_type))
52 packed.append(struct.pack("!H", self.flags))
53 packed.append(struct.pack("!Q", self.packet_count))
54 packed.append(struct.pack("!Q", self.byte_count))
55 packed.append(struct.pack("!L", self.flow_count))
Rich Lanec2ee4b82013-04-24 17:12:38 -070056 packed.append('\x00' * 4)
Rich Laneb658ddd2013-03-12 10:15:10 -070057 length = sum([len(x) for x in packed])
58 packed[2] = struct.pack("!H", length)
59 return ''.join(packed)
60
61 @staticmethod
62 def unpack(buf):
63 if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
64 obj = aggregate_stats_reply()
Rich Lanec2ee4b82013-04-24 17:12:38 -070065 if type(buf) == loxi.generic_util.OFReader:
66 reader = buf
67 else:
68 reader = loxi.generic_util.OFReader(buf)
69 _version = reader.read('!B')[0]
70 assert(_version == const.OFP_VERSION)
71 _type = reader.read('!B')[0]
72 assert(_type == const.OFPT_STATS_REPLY)
73 _length = reader.read('!H')[0]
74 obj.xid = reader.read('!L')[0]
75 _stats_type = reader.read('!H')[0]
76 assert(_stats_type == const.OFPST_AGGREGATE)
77 obj.flags = reader.read('!H')[0]
78 obj.packet_count = reader.read('!Q')[0]
79 obj.byte_count = reader.read('!Q')[0]
80 obj.flow_count = reader.read('!L')[0]
81 reader.skip(4)
Rich Laneb658ddd2013-03-12 10:15:10 -070082 return obj
83
84 def __eq__(self, other):
85 if type(self) != type(other): return False
86 if self.version != other.version: return False
87 if self.type != other.type: return False
88 if self.xid != other.xid: return False
89 if self.flags != other.flags: return False
90 if self.packet_count != other.packet_count: return False
91 if self.byte_count != other.byte_count: return False
92 if self.flow_count != other.flow_count: return False
Rich Laneb658ddd2013-03-12 10:15:10 -070093 return True
94
95 def __ne__(self, other):
96 return not self.__eq__(other)
97
98 def __str__(self):
99 return self.show()
100
101 def show(self):
102 import loxi.pp
103 return loxi.pp.pp(self)
104
105 def pretty_print(self, q):
106 q.text("aggregate_stats_reply {")
107 with q.group():
108 with q.indent(2):
109 q.breakable()
110 q.text("xid = ");
111 if self.xid != None:
112 q.text("%#x" % self.xid)
113 else:
114 q.text('None')
115 q.text(","); q.breakable()
116 q.text("flags = ");
117 q.text("%#x" % self.flags)
118 q.text(","); q.breakable()
119 q.text("packet_count = ");
120 q.text("%#x" % self.packet_count)
121 q.text(","); q.breakable()
122 q.text("byte_count = ");
123 q.text("%#x" % self.byte_count)
124 q.text(","); q.breakable()
125 q.text("flow_count = ");
126 q.text("%#x" % self.flow_count)
Rich Laneb658ddd2013-03-12 10:15:10 -0700127 q.breakable()
128 q.text('}')
129
130class aggregate_stats_request(Message):
131 version = const.OFP_VERSION
132 type = const.OFPT_STATS_REQUEST
133 stats_type = const.OFPST_AGGREGATE
134
Rich Lanec2ee4b82013-04-24 17:12:38 -0700135 def __init__(self, xid=None, flags=None, match=None, table_id=None, out_port=None):
Rich Laneb658ddd2013-03-12 10:15:10 -0700136 self.xid = xid
137 if flags != None:
138 self.flags = flags
139 else:
140 self.flags = 0
141 if match != None:
142 self.match = match
143 else:
144 self.match = common.match()
145 if table_id != None:
146 self.table_id = table_id
147 else:
148 self.table_id = 0
Rich Laneb658ddd2013-03-12 10:15:10 -0700149 if out_port != None:
150 self.out_port = out_port
151 else:
152 self.out_port = 0
153
154 def pack(self):
155 packed = []
156 packed.append(struct.pack("!B", self.version))
157 packed.append(struct.pack("!B", self.type))
158 packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
159 packed.append(struct.pack("!L", self.xid))
160 packed.append(struct.pack("!H", self.stats_type))
161 packed.append(struct.pack("!H", self.flags))
162 packed.append(self.match.pack())
163 packed.append(struct.pack("!B", self.table_id))
Rich Lanec2ee4b82013-04-24 17:12:38 -0700164 packed.append('\x00' * 1)
Rich Laneb658ddd2013-03-12 10:15:10 -0700165 packed.append(struct.pack("!H", self.out_port))
166 length = sum([len(x) for x in packed])
167 packed[2] = struct.pack("!H", length)
168 return ''.join(packed)
169
170 @staticmethod
171 def unpack(buf):
172 if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
173 obj = aggregate_stats_request()
Rich Lanec2ee4b82013-04-24 17:12:38 -0700174 if type(buf) == loxi.generic_util.OFReader:
175 reader = buf
176 else:
177 reader = loxi.generic_util.OFReader(buf)
178 _version = reader.read('!B')[0]
179 assert(_version == const.OFP_VERSION)
180 _type = reader.read('!B')[0]
181 assert(_type == const.OFPT_STATS_REQUEST)
182 _length = reader.read('!H')[0]
183 obj.xid = reader.read('!L')[0]
184 _stats_type = reader.read('!H')[0]
185 assert(_stats_type == const.OFPST_AGGREGATE)
186 obj.flags = reader.read('!H')[0]
187 obj.match = common.match.unpack(reader)
188 obj.table_id = reader.read('!B')[0]
189 reader.skip(1)
190 obj.out_port = reader.read('!H')[0]
Rich Laneb658ddd2013-03-12 10:15:10 -0700191 return obj
192
193 def __eq__(self, other):
194 if type(self) != type(other): return False
195 if self.version != other.version: return False
196 if self.type != other.type: return False
197 if self.xid != other.xid: return False
198 if self.flags != other.flags: return False
199 if self.match != other.match: return False
200 if self.table_id != other.table_id: return False
Rich Laneb658ddd2013-03-12 10:15:10 -0700201 if self.out_port != other.out_port: return False
202 return True
203
204 def __ne__(self, other):
205 return not self.__eq__(other)
206
207 def __str__(self):
208 return self.show()
209
210 def show(self):
211 import loxi.pp
212 return loxi.pp.pp(self)
213
214 def pretty_print(self, q):
215 q.text("aggregate_stats_request {")
216 with q.group():
217 with q.indent(2):
218 q.breakable()
219 q.text("xid = ");
220 if self.xid != None:
221 q.text("%#x" % self.xid)
222 else:
223 q.text('None')
224 q.text(","); q.breakable()
225 q.text("flags = ");
226 q.text("%#x" % self.flags)
227 q.text(","); q.breakable()
228 q.text("match = ");
229 q.pp(self.match)
230 q.text(","); q.breakable()
231 q.text("table_id = ");
232 q.text("%#x" % self.table_id)
233 q.text(","); q.breakable()
Rich Laneb658ddd2013-03-12 10:15:10 -0700234 q.text("out_port = ");
235 q.text(util.pretty_port(self.out_port))
236 q.breakable()
237 q.text('}')
238
239class barrier_reply(Message):
240 version = const.OFP_VERSION
241 type = const.OFPT_BARRIER_REPLY
242
243 def __init__(self, xid=None):
244 self.xid = xid
245
246 def pack(self):
247 packed = []
248 packed.append(struct.pack("!B", self.version))
249 packed.append(struct.pack("!B", self.type))
250 packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
251 packed.append(struct.pack("!L", self.xid))
252 length = sum([len(x) for x in packed])
253 packed[2] = struct.pack("!H", length)
254 return ''.join(packed)
255
256 @staticmethod
257 def unpack(buf):
258 if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
259 obj = barrier_reply()
Rich Lanec2ee4b82013-04-24 17:12:38 -0700260 if type(buf) == loxi.generic_util.OFReader:
261 reader = buf
262 else:
263 reader = loxi.generic_util.OFReader(buf)
264 _version = reader.read('!B')[0]
265 assert(_version == const.OFP_VERSION)
266 _type = reader.read('!B')[0]
267 assert(_type == const.OFPT_BARRIER_REPLY)
268 _length = reader.read('!H')[0]
269 obj.xid = reader.read('!L')[0]
Rich Laneb658ddd2013-03-12 10:15:10 -0700270 return obj
271
272 def __eq__(self, other):
273 if type(self) != type(other): return False
274 if self.version != other.version: return False
275 if self.type != other.type: return False
276 if self.xid != other.xid: return False
277 return True
278
279 def __ne__(self, other):
280 return not self.__eq__(other)
281
282 def __str__(self):
283 return self.show()
284
285 def show(self):
286 import loxi.pp
287 return loxi.pp.pp(self)
288
289 def pretty_print(self, q):
290 q.text("barrier_reply {")
291 with q.group():
292 with q.indent(2):
293 q.breakable()
294 q.text("xid = ");
295 if self.xid != None:
296 q.text("%#x" % self.xid)
297 else:
298 q.text('None')
299 q.breakable()
300 q.text('}')
301
302class barrier_request(Message):
303 version = const.OFP_VERSION
304 type = const.OFPT_BARRIER_REQUEST
305
306 def __init__(self, xid=None):
307 self.xid = xid
308
309 def pack(self):
310 packed = []
311 packed.append(struct.pack("!B", self.version))
312 packed.append(struct.pack("!B", self.type))
313 packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
314 packed.append(struct.pack("!L", self.xid))
315 length = sum([len(x) for x in packed])
316 packed[2] = struct.pack("!H", length)
317 return ''.join(packed)
318
319 @staticmethod
320 def unpack(buf):
321 if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
322 obj = barrier_request()
Rich Lanec2ee4b82013-04-24 17:12:38 -0700323 if type(buf) == loxi.generic_util.OFReader:
324 reader = buf
325 else:
326 reader = loxi.generic_util.OFReader(buf)
327 _version = reader.read('!B')[0]
328 assert(_version == const.OFP_VERSION)
329 _type = reader.read('!B')[0]
330 assert(_type == const.OFPT_BARRIER_REQUEST)
331 _length = reader.read('!H')[0]
332 obj.xid = reader.read('!L')[0]
Rich Laneb658ddd2013-03-12 10:15:10 -0700333 return obj
334
335 def __eq__(self, other):
336 if type(self) != type(other): return False
337 if self.version != other.version: return False
338 if self.type != other.type: return False
339 if self.xid != other.xid: return False
340 return True
341
342 def __ne__(self, other):
343 return not self.__eq__(other)
344
345 def __str__(self):
346 return self.show()
347
348 def show(self):
349 import loxi.pp
350 return loxi.pp.pp(self)
351
352 def pretty_print(self, q):
353 q.text("barrier_request {")
354 with q.group():
355 with q.indent(2):
356 q.breakable()
357 q.text("xid = ");
358 if self.xid != None:
359 q.text("%#x" % self.xid)
360 else:
361 q.text('None')
362 q.breakable()
363 q.text('}')
364
365class bsn_get_interfaces_reply(Message):
366 version = const.OFP_VERSION
367 type = const.OFPT_VENDOR
368 experimenter = 0x5c16c7
369 subtype = 10
370
371 def __init__(self, xid=None, interfaces=None):
372 self.xid = xid
373 if interfaces != None:
374 self.interfaces = interfaces
375 else:
376 self.interfaces = []
377
378 def pack(self):
379 packed = []
380 packed.append(struct.pack("!B", self.version))
381 packed.append(struct.pack("!B", self.type))
382 packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
383 packed.append(struct.pack("!L", self.xid))
384 packed.append(struct.pack("!L", self.experimenter))
385 packed.append(struct.pack("!L", self.subtype))
386 packed.append("".join([x.pack() for x in self.interfaces]))
387 length = sum([len(x) for x in packed])
388 packed[2] = struct.pack("!H", length)
389 return ''.join(packed)
390
391 @staticmethod
392 def unpack(buf):
393 if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
394 obj = bsn_get_interfaces_reply()
Rich Lanec2ee4b82013-04-24 17:12:38 -0700395 if type(buf) == loxi.generic_util.OFReader:
396 reader = buf
397 else:
398 reader = loxi.generic_util.OFReader(buf)
399 _version = reader.read('!B')[0]
400 assert(_version == const.OFP_VERSION)
401 _type = reader.read('!B')[0]
402 assert(_type == const.OFPT_VENDOR)
403 _length = reader.read('!H')[0]
404 obj.xid = reader.read('!L')[0]
405 _experimenter = reader.read('!L')[0]
406 assert(_experimenter == 0x5c16c7)
407 _subtype = reader.read('!L')[0]
408 assert(_subtype == 10)
409 obj.interfaces = loxi.generic_util.unpack_list(reader, common.bsn_interface.unpack)
Rich Laneb658ddd2013-03-12 10:15:10 -0700410 return obj
411
412 def __eq__(self, other):
413 if type(self) != type(other): return False
414 if self.version != other.version: return False
415 if self.type != other.type: return False
416 if self.xid != other.xid: return False
417 if self.interfaces != other.interfaces: return False
418 return True
419
420 def __ne__(self, other):
421 return not self.__eq__(other)
422
423 def __str__(self):
424 return self.show()
425
426 def show(self):
427 import loxi.pp
428 return loxi.pp.pp(self)
429
430 def pretty_print(self, q):
431 q.text("bsn_get_interfaces_reply {")
432 with q.group():
433 with q.indent(2):
434 q.breakable()
435 q.text("xid = ");
436 if self.xid != None:
437 q.text("%#x" % self.xid)
438 else:
439 q.text('None')
440 q.text(","); q.breakable()
441 q.text("interfaces = ");
442 q.pp(self.interfaces)
443 q.breakable()
444 q.text('}')
445
446class bsn_get_interfaces_request(Message):
447 version = const.OFP_VERSION
448 type = const.OFPT_VENDOR
449 experimenter = 0x5c16c7
450 subtype = 9
451
452 def __init__(self, xid=None):
453 self.xid = xid
454
455 def pack(self):
456 packed = []
457 packed.append(struct.pack("!B", self.version))
458 packed.append(struct.pack("!B", self.type))
459 packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
460 packed.append(struct.pack("!L", self.xid))
461 packed.append(struct.pack("!L", self.experimenter))
462 packed.append(struct.pack("!L", self.subtype))
463 length = sum([len(x) for x in packed])
464 packed[2] = struct.pack("!H", length)
465 return ''.join(packed)
466
467 @staticmethod
468 def unpack(buf):
469 if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
470 obj = bsn_get_interfaces_request()
Rich Lanec2ee4b82013-04-24 17:12:38 -0700471 if type(buf) == loxi.generic_util.OFReader:
472 reader = buf
473 else:
474 reader = loxi.generic_util.OFReader(buf)
475 _version = reader.read('!B')[0]
476 assert(_version == const.OFP_VERSION)
477 _type = reader.read('!B')[0]
478 assert(_type == const.OFPT_VENDOR)
479 _length = reader.read('!H')[0]
480 obj.xid = reader.read('!L')[0]
481 _experimenter = reader.read('!L')[0]
482 assert(_experimenter == 0x5c16c7)
483 _subtype = reader.read('!L')[0]
484 assert(_subtype == 9)
Rich Laneb658ddd2013-03-12 10:15:10 -0700485 return obj
486
487 def __eq__(self, other):
488 if type(self) != type(other): return False
489 if self.version != other.version: return False
490 if self.type != other.type: return False
491 if self.xid != other.xid: return False
492 return True
493
494 def __ne__(self, other):
495 return not self.__eq__(other)
496
497 def __str__(self):
498 return self.show()
499
500 def show(self):
501 import loxi.pp
502 return loxi.pp.pp(self)
503
504 def pretty_print(self, q):
505 q.text("bsn_get_interfaces_request {")
506 with q.group():
507 with q.indent(2):
508 q.breakable()
509 q.text("xid = ");
510 if self.xid != None:
511 q.text("%#x" % self.xid)
512 else:
513 q.text('None')
514 q.breakable()
515 q.text('}')
516
517class bsn_get_ip_mask_reply(Message):
518 version = const.OFP_VERSION
519 type = const.OFPT_VENDOR
520 experimenter = 0x5c16c7
521 subtype = 2
522
Rich Lanec2ee4b82013-04-24 17:12:38 -0700523 def __init__(self, xid=None, index=None, mask=None):
Rich Laneb658ddd2013-03-12 10:15:10 -0700524 self.xid = xid
525 if index != None:
526 self.index = index
527 else:
528 self.index = 0
Rich Laneb658ddd2013-03-12 10:15:10 -0700529 if mask != None:
530 self.mask = mask
531 else:
532 self.mask = 0
533
534 def pack(self):
535 packed = []
536 packed.append(struct.pack("!B", self.version))
537 packed.append(struct.pack("!B", self.type))
538 packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
539 packed.append(struct.pack("!L", self.xid))
540 packed.append(struct.pack("!L", self.experimenter))
541 packed.append(struct.pack("!L", self.subtype))
542 packed.append(struct.pack("!B", self.index))
Rich Lanec2ee4b82013-04-24 17:12:38 -0700543 packed.append('\x00' * 3)
Rich Laneb658ddd2013-03-12 10:15:10 -0700544 packed.append(struct.pack("!L", self.mask))
545 length = sum([len(x) for x in packed])
546 packed[2] = struct.pack("!H", length)
547 return ''.join(packed)
548
549 @staticmethod
550 def unpack(buf):
551 if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
552 obj = bsn_get_ip_mask_reply()
Rich Lanec2ee4b82013-04-24 17:12:38 -0700553 if type(buf) == loxi.generic_util.OFReader:
554 reader = buf
555 else:
556 reader = loxi.generic_util.OFReader(buf)
557 _version = reader.read('!B')[0]
558 assert(_version == const.OFP_VERSION)
559 _type = reader.read('!B')[0]
560 assert(_type == const.OFPT_VENDOR)
561 _length = reader.read('!H')[0]
562 obj.xid = reader.read('!L')[0]
563 _experimenter = reader.read('!L')[0]
564 assert(_experimenter == 0x5c16c7)
565 _subtype = reader.read('!L')[0]
566 assert(_subtype == 2)
567 obj.index = reader.read('!B')[0]
568 reader.skip(3)
569 obj.mask = reader.read('!L')[0]
Rich Laneb658ddd2013-03-12 10:15:10 -0700570 return obj
571
572 def __eq__(self, other):
573 if type(self) != type(other): return False
574 if self.version != other.version: return False
575 if self.type != other.type: return False
576 if self.xid != other.xid: return False
577 if self.index != other.index: return False
Rich Laneb658ddd2013-03-12 10:15:10 -0700578 if self.mask != other.mask: return False
579 return True
580
581 def __ne__(self, other):
582 return not self.__eq__(other)
583
584 def __str__(self):
585 return self.show()
586
587 def show(self):
588 import loxi.pp
589 return loxi.pp.pp(self)
590
591 def pretty_print(self, q):
592 q.text("bsn_get_ip_mask_reply {")
593 with q.group():
594 with q.indent(2):
595 q.breakable()
596 q.text("xid = ");
597 if self.xid != None:
598 q.text("%#x" % self.xid)
599 else:
600 q.text('None')
601 q.text(","); q.breakable()
602 q.text("index = ");
603 q.text("%#x" % self.index)
604 q.text(","); q.breakable()
Rich Laneb658ddd2013-03-12 10:15:10 -0700605 q.text("mask = ");
606 q.text("%#x" % self.mask)
607 q.breakable()
608 q.text('}')
609
610class bsn_get_ip_mask_request(Message):
611 version = const.OFP_VERSION
612 type = const.OFPT_VENDOR
613 experimenter = 0x5c16c7
614 subtype = 1
615
Rich Lanec2ee4b82013-04-24 17:12:38 -0700616 def __init__(self, xid=None, index=None):
Rich Laneb658ddd2013-03-12 10:15:10 -0700617 self.xid = xid
618 if index != None:
619 self.index = index
620 else:
621 self.index = 0
Rich Laneb658ddd2013-03-12 10:15:10 -0700622
623 def pack(self):
624 packed = []
625 packed.append(struct.pack("!B", self.version))
626 packed.append(struct.pack("!B", self.type))
627 packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
628 packed.append(struct.pack("!L", self.xid))
629 packed.append(struct.pack("!L", self.experimenter))
630 packed.append(struct.pack("!L", self.subtype))
631 packed.append(struct.pack("!B", self.index))
Rich Lanec2ee4b82013-04-24 17:12:38 -0700632 packed.append('\x00' * 7)
Rich Laneb658ddd2013-03-12 10:15:10 -0700633 length = sum([len(x) for x in packed])
634 packed[2] = struct.pack("!H", length)
635 return ''.join(packed)
636
637 @staticmethod
638 def unpack(buf):
639 if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
640 obj = bsn_get_ip_mask_request()
Rich Lanec2ee4b82013-04-24 17:12:38 -0700641 if type(buf) == loxi.generic_util.OFReader:
642 reader = buf
643 else:
644 reader = loxi.generic_util.OFReader(buf)
645 _version = reader.read('!B')[0]
646 assert(_version == const.OFP_VERSION)
647 _type = reader.read('!B')[0]
648 assert(_type == const.OFPT_VENDOR)
649 _length = reader.read('!H')[0]
650 obj.xid = reader.read('!L')[0]
651 _experimenter = reader.read('!L')[0]
652 assert(_experimenter == 0x5c16c7)
653 _subtype = reader.read('!L')[0]
654 assert(_subtype == 1)
655 obj.index = reader.read('!B')[0]
656 reader.skip(7)
Rich Laneb658ddd2013-03-12 10:15:10 -0700657 return obj
658
659 def __eq__(self, other):
660 if type(self) != type(other): return False
661 if self.version != other.version: return False
662 if self.type != other.type: return False
663 if self.xid != other.xid: return False
664 if self.index != other.index: return False
Rich Laneb658ddd2013-03-12 10:15:10 -0700665 return True
666
667 def __ne__(self, other):
668 return not self.__eq__(other)
669
670 def __str__(self):
671 return self.show()
672
673 def show(self):
674 import loxi.pp
675 return loxi.pp.pp(self)
676
677 def pretty_print(self, q):
678 q.text("bsn_get_ip_mask_request {")
679 with q.group():
680 with q.indent(2):
681 q.breakable()
682 q.text("xid = ");
683 if self.xid != None:
684 q.text("%#x" % self.xid)
685 else:
686 q.text('None')
687 q.text(","); q.breakable()
688 q.text("index = ");
689 q.text("%#x" % self.index)
Rich Laneb658ddd2013-03-12 10:15:10 -0700690 q.breakable()
691 q.text('}')
692
Rich Lane90c961c2013-05-14 09:26:50 -0700693class bsn_get_l2_table_reply(Message):
694 version = const.OFP_VERSION
695 type = const.OFPT_VENDOR
696 experimenter = 0x5c16c7
697 subtype = 14
698
699 def __init__(self, xid=None, l2_table_enable=None, l2_table_priority=None):
700 self.xid = xid
701 if l2_table_enable != None:
702 self.l2_table_enable = l2_table_enable
703 else:
704 self.l2_table_enable = 0
705 if l2_table_priority != None:
706 self.l2_table_priority = l2_table_priority
707 else:
708 self.l2_table_priority = 0
709
710 def pack(self):
711 packed = []
712 packed.append(struct.pack("!B", self.version))
713 packed.append(struct.pack("!B", self.type))
714 packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
715 packed.append(struct.pack("!L", self.xid))
716 packed.append(struct.pack("!L", self.experimenter))
717 packed.append(struct.pack("!L", self.subtype))
718 packed.append(struct.pack("!B", self.l2_table_enable))
719 packed.append('\x00' * 1)
720 packed.append(struct.pack("!H", self.l2_table_priority))
721 packed.append('\x00' * 4)
722 length = sum([len(x) for x in packed])
723 packed[2] = struct.pack("!H", length)
724 return ''.join(packed)
725
726 @staticmethod
727 def unpack(buf):
728 if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
729 obj = bsn_get_l2_table_reply()
730 if type(buf) == loxi.generic_util.OFReader:
731 reader = buf
732 else:
733 reader = loxi.generic_util.OFReader(buf)
734 _version = reader.read('!B')[0]
735 assert(_version == const.OFP_VERSION)
736 _type = reader.read('!B')[0]
737 assert(_type == const.OFPT_VENDOR)
738 _length = reader.read('!H')[0]
739 obj.xid = reader.read('!L')[0]
740 _experimenter = reader.read('!L')[0]
741 assert(_experimenter == 0x5c16c7)
742 _subtype = reader.read('!L')[0]
743 assert(_subtype == 14)
744 obj.l2_table_enable = reader.read('!B')[0]
745 reader.skip(1)
746 obj.l2_table_priority = reader.read('!H')[0]
747 reader.skip(4)
748 return obj
749
750 def __eq__(self, other):
751 if type(self) != type(other): return False
752 if self.version != other.version: return False
753 if self.type != other.type: return False
754 if self.xid != other.xid: return False
755 if self.l2_table_enable != other.l2_table_enable: return False
756 if self.l2_table_priority != other.l2_table_priority: return False
757 return True
758
759 def __ne__(self, other):
760 return not self.__eq__(other)
761
762 def __str__(self):
763 return self.show()
764
765 def show(self):
766 import loxi.pp
767 return loxi.pp.pp(self)
768
769 def pretty_print(self, q):
770 q.text("bsn_get_l2_table_reply {")
771 with q.group():
772 with q.indent(2):
773 q.breakable()
774 q.text("xid = ");
775 if self.xid != None:
776 q.text("%#x" % self.xid)
777 else:
778 q.text('None')
779 q.text(","); q.breakable()
780 q.text("l2_table_enable = ");
781 q.text("%#x" % self.l2_table_enable)
782 q.text(","); q.breakable()
783 q.text("l2_table_priority = ");
784 q.text("%#x" % self.l2_table_priority)
785 q.breakable()
786 q.text('}')
787
788class bsn_get_l2_table_request(Message):
789 version = const.OFP_VERSION
790 type = const.OFPT_VENDOR
791 experimenter = 0x5c16c7
792 subtype = 13
793
794 def __init__(self, xid=None):
795 self.xid = xid
796
797 def pack(self):
798 packed = []
799 packed.append(struct.pack("!B", self.version))
800 packed.append(struct.pack("!B", self.type))
801 packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
802 packed.append(struct.pack("!L", self.xid))
803 packed.append(struct.pack("!L", self.experimenter))
804 packed.append(struct.pack("!L", self.subtype))
805 length = sum([len(x) for x in packed])
806 packed[2] = struct.pack("!H", length)
807 return ''.join(packed)
808
809 @staticmethod
810 def unpack(buf):
811 if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
812 obj = bsn_get_l2_table_request()
813 if type(buf) == loxi.generic_util.OFReader:
814 reader = buf
815 else:
816 reader = loxi.generic_util.OFReader(buf)
817 _version = reader.read('!B')[0]
818 assert(_version == const.OFP_VERSION)
819 _type = reader.read('!B')[0]
820 assert(_type == const.OFPT_VENDOR)
821 _length = reader.read('!H')[0]
822 obj.xid = reader.read('!L')[0]
823 _experimenter = reader.read('!L')[0]
824 assert(_experimenter == 0x5c16c7)
825 _subtype = reader.read('!L')[0]
826 assert(_subtype == 13)
827 return obj
828
829 def __eq__(self, other):
830 if type(self) != type(other): return False
831 if self.version != other.version: return False
832 if self.type != other.type: return False
833 if self.xid != other.xid: return False
834 return True
835
836 def __ne__(self, other):
837 return not self.__eq__(other)
838
839 def __str__(self):
840 return self.show()
841
842 def show(self):
843 import loxi.pp
844 return loxi.pp.pp(self)
845
846 def pretty_print(self, q):
847 q.text("bsn_get_l2_table_request {")
848 with q.group():
849 with q.indent(2):
850 q.breakable()
851 q.text("xid = ");
852 if self.xid != None:
853 q.text("%#x" % self.xid)
854 else:
855 q.text('None')
856 q.breakable()
857 q.text('}')
858
Rich Laneb658ddd2013-03-12 10:15:10 -0700859class bsn_get_mirroring_reply(Message):
860 version = const.OFP_VERSION
861 type = const.OFPT_VENDOR
862 experimenter = 0x5c16c7
863 subtype = 5
864
Rich Lanec2ee4b82013-04-24 17:12:38 -0700865 def __init__(self, xid=None, report_mirror_ports=None):
Rich Laneb658ddd2013-03-12 10:15:10 -0700866 self.xid = xid
867 if report_mirror_ports != None:
868 self.report_mirror_ports = report_mirror_ports
869 else:
870 self.report_mirror_ports = 0
Rich Laneb658ddd2013-03-12 10:15:10 -0700871
872 def pack(self):
873 packed = []
874 packed.append(struct.pack("!B", self.version))
875 packed.append(struct.pack("!B", self.type))
876 packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
877 packed.append(struct.pack("!L", self.xid))
878 packed.append(struct.pack("!L", self.experimenter))
879 packed.append(struct.pack("!L", self.subtype))
880 packed.append(struct.pack("!B", self.report_mirror_ports))
Rich Lanec2ee4b82013-04-24 17:12:38 -0700881 packed.append('\x00' * 3)
Rich Laneb658ddd2013-03-12 10:15:10 -0700882 length = sum([len(x) for x in packed])
883 packed[2] = struct.pack("!H", length)
884 return ''.join(packed)
885
886 @staticmethod
887 def unpack(buf):
888 if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
889 obj = bsn_get_mirroring_reply()
Rich Lanec2ee4b82013-04-24 17:12:38 -0700890 if type(buf) == loxi.generic_util.OFReader:
891 reader = buf
892 else:
893 reader = loxi.generic_util.OFReader(buf)
894 _version = reader.read('!B')[0]
895 assert(_version == const.OFP_VERSION)
896 _type = reader.read('!B')[0]
897 assert(_type == const.OFPT_VENDOR)
898 _length = reader.read('!H')[0]
899 obj.xid = reader.read('!L')[0]
900 _experimenter = reader.read('!L')[0]
901 assert(_experimenter == 0x5c16c7)
902 _subtype = reader.read('!L')[0]
903 assert(_subtype == 5)
904 obj.report_mirror_ports = reader.read('!B')[0]
905 reader.skip(3)
Rich Laneb658ddd2013-03-12 10:15:10 -0700906 return obj
907
908 def __eq__(self, other):
909 if type(self) != type(other): return False
910 if self.version != other.version: return False
911 if self.type != other.type: return False
912 if self.xid != other.xid: return False
913 if self.report_mirror_ports != other.report_mirror_ports: return False
Rich Laneb658ddd2013-03-12 10:15:10 -0700914 return True
915
916 def __ne__(self, other):
917 return not self.__eq__(other)
918
919 def __str__(self):
920 return self.show()
921
922 def show(self):
923 import loxi.pp
924 return loxi.pp.pp(self)
925
926 def pretty_print(self, q):
927 q.text("bsn_get_mirroring_reply {")
928 with q.group():
929 with q.indent(2):
930 q.breakable()
931 q.text("xid = ");
932 if self.xid != None:
933 q.text("%#x" % self.xid)
934 else:
935 q.text('None')
936 q.text(","); q.breakable()
937 q.text("report_mirror_ports = ");
938 q.text("%#x" % self.report_mirror_ports)
Rich Laneb658ddd2013-03-12 10:15:10 -0700939 q.breakable()
940 q.text('}')
941
942class bsn_get_mirroring_request(Message):
943 version = const.OFP_VERSION
944 type = const.OFPT_VENDOR
945 experimenter = 0x5c16c7
946 subtype = 4
947
Rich Lanec2ee4b82013-04-24 17:12:38 -0700948 def __init__(self, xid=None, report_mirror_ports=None):
Rich Laneb658ddd2013-03-12 10:15:10 -0700949 self.xid = xid
950 if report_mirror_ports != None:
951 self.report_mirror_ports = report_mirror_ports
952 else:
953 self.report_mirror_ports = 0
Rich Laneb658ddd2013-03-12 10:15:10 -0700954
955 def pack(self):
956 packed = []
957 packed.append(struct.pack("!B", self.version))
958 packed.append(struct.pack("!B", self.type))
959 packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
960 packed.append(struct.pack("!L", self.xid))
961 packed.append(struct.pack("!L", self.experimenter))
962 packed.append(struct.pack("!L", self.subtype))
963 packed.append(struct.pack("!B", self.report_mirror_ports))
Rich Lanec2ee4b82013-04-24 17:12:38 -0700964 packed.append('\x00' * 3)
Rich Laneb658ddd2013-03-12 10:15:10 -0700965 length = sum([len(x) for x in packed])
966 packed[2] = struct.pack("!H", length)
967 return ''.join(packed)
968
969 @staticmethod
970 def unpack(buf):
971 if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
972 obj = bsn_get_mirroring_request()
Rich Lanec2ee4b82013-04-24 17:12:38 -0700973 if type(buf) == loxi.generic_util.OFReader:
974 reader = buf
975 else:
976 reader = loxi.generic_util.OFReader(buf)
977 _version = reader.read('!B')[0]
978 assert(_version == const.OFP_VERSION)
979 _type = reader.read('!B')[0]
980 assert(_type == const.OFPT_VENDOR)
981 _length = reader.read('!H')[0]
982 obj.xid = reader.read('!L')[0]
983 _experimenter = reader.read('!L')[0]
984 assert(_experimenter == 0x5c16c7)
985 _subtype = reader.read('!L')[0]
986 assert(_subtype == 4)
987 obj.report_mirror_ports = reader.read('!B')[0]
988 reader.skip(3)
Rich Laneb658ddd2013-03-12 10:15:10 -0700989 return obj
990
991 def __eq__(self, other):
992 if type(self) != type(other): return False
993 if self.version != other.version: return False
994 if self.type != other.type: return False
995 if self.xid != other.xid: return False
996 if self.report_mirror_ports != other.report_mirror_ports: return False
Rich Laneb658ddd2013-03-12 10:15:10 -0700997 return True
998
999 def __ne__(self, other):
1000 return not self.__eq__(other)
1001
1002 def __str__(self):
1003 return self.show()
1004
1005 def show(self):
1006 import loxi.pp
1007 return loxi.pp.pp(self)
1008
1009 def pretty_print(self, q):
1010 q.text("bsn_get_mirroring_request {")
1011 with q.group():
1012 with q.indent(2):
1013 q.breakable()
1014 q.text("xid = ");
1015 if self.xid != None:
1016 q.text("%#x" % self.xid)
1017 else:
1018 q.text('None')
1019 q.text(","); q.breakable()
1020 q.text("report_mirror_ports = ");
1021 q.text("%#x" % self.report_mirror_ports)
Rich Laneb658ddd2013-03-12 10:15:10 -07001022 q.breakable()
1023 q.text('}')
1024
1025class bsn_set_ip_mask(Message):
1026 version = const.OFP_VERSION
1027 type = const.OFPT_VENDOR
1028 experimenter = 0x5c16c7
1029 subtype = 0
1030
Rich Lanec2ee4b82013-04-24 17:12:38 -07001031 def __init__(self, xid=None, index=None, mask=None):
Rich Laneb658ddd2013-03-12 10:15:10 -07001032 self.xid = xid
1033 if index != None:
1034 self.index = index
1035 else:
1036 self.index = 0
Rich Laneb658ddd2013-03-12 10:15:10 -07001037 if mask != None:
1038 self.mask = mask
1039 else:
1040 self.mask = 0
1041
1042 def pack(self):
1043 packed = []
1044 packed.append(struct.pack("!B", self.version))
1045 packed.append(struct.pack("!B", self.type))
1046 packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
1047 packed.append(struct.pack("!L", self.xid))
1048 packed.append(struct.pack("!L", self.experimenter))
1049 packed.append(struct.pack("!L", self.subtype))
1050 packed.append(struct.pack("!B", self.index))
Rich Lanec2ee4b82013-04-24 17:12:38 -07001051 packed.append('\x00' * 3)
Rich Laneb658ddd2013-03-12 10:15:10 -07001052 packed.append(struct.pack("!L", self.mask))
1053 length = sum([len(x) for x in packed])
1054 packed[2] = struct.pack("!H", length)
1055 return ''.join(packed)
1056
1057 @staticmethod
1058 def unpack(buf):
1059 if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
1060 obj = bsn_set_ip_mask()
Rich Lanec2ee4b82013-04-24 17:12:38 -07001061 if type(buf) == loxi.generic_util.OFReader:
1062 reader = buf
1063 else:
1064 reader = loxi.generic_util.OFReader(buf)
1065 _version = reader.read('!B')[0]
1066 assert(_version == const.OFP_VERSION)
1067 _type = reader.read('!B')[0]
1068 assert(_type == const.OFPT_VENDOR)
1069 _length = reader.read('!H')[0]
1070 obj.xid = reader.read('!L')[0]
1071 _experimenter = reader.read('!L')[0]
1072 assert(_experimenter == 0x5c16c7)
1073 _subtype = reader.read('!L')[0]
1074 assert(_subtype == 0)
1075 obj.index = reader.read('!B')[0]
1076 reader.skip(3)
1077 obj.mask = reader.read('!L')[0]
Rich Laneb658ddd2013-03-12 10:15:10 -07001078 return obj
1079
1080 def __eq__(self, other):
1081 if type(self) != type(other): return False
1082 if self.version != other.version: return False
1083 if self.type != other.type: return False
1084 if self.xid != other.xid: return False
1085 if self.index != other.index: return False
Rich Laneb658ddd2013-03-12 10:15:10 -07001086 if self.mask != other.mask: return False
1087 return True
1088
1089 def __ne__(self, other):
1090 return not self.__eq__(other)
1091
1092 def __str__(self):
1093 return self.show()
1094
1095 def show(self):
1096 import loxi.pp
1097 return loxi.pp.pp(self)
1098
1099 def pretty_print(self, q):
1100 q.text("bsn_set_ip_mask {")
1101 with q.group():
1102 with q.indent(2):
1103 q.breakable()
1104 q.text("xid = ");
1105 if self.xid != None:
1106 q.text("%#x" % self.xid)
1107 else:
1108 q.text('None')
1109 q.text(","); q.breakable()
1110 q.text("index = ");
1111 q.text("%#x" % self.index)
1112 q.text(","); q.breakable()
Rich Laneb658ddd2013-03-12 10:15:10 -07001113 q.text("mask = ");
1114 q.text("%#x" % self.mask)
1115 q.breakable()
1116 q.text('}')
1117
Rich Lane90c961c2013-05-14 09:26:50 -07001118class bsn_set_l2_table(Message):
1119 version = const.OFP_VERSION
1120 type = const.OFPT_VENDOR
1121 experimenter = 0x5c16c7
1122 subtype = 12
1123
1124 def __init__(self, xid=None, l2_table_enable=None, l2_table_priority=None):
1125 self.xid = xid
1126 if l2_table_enable != None:
1127 self.l2_table_enable = l2_table_enable
1128 else:
1129 self.l2_table_enable = 0
1130 if l2_table_priority != None:
1131 self.l2_table_priority = l2_table_priority
1132 else:
1133 self.l2_table_priority = 0
1134
1135 def pack(self):
1136 packed = []
1137 packed.append(struct.pack("!B", self.version))
1138 packed.append(struct.pack("!B", self.type))
1139 packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
1140 packed.append(struct.pack("!L", self.xid))
1141 packed.append(struct.pack("!L", self.experimenter))
1142 packed.append(struct.pack("!L", self.subtype))
1143 packed.append(struct.pack("!B", self.l2_table_enable))
1144 packed.append('\x00' * 1)
1145 packed.append(struct.pack("!H", self.l2_table_priority))
1146 packed.append('\x00' * 4)
1147 length = sum([len(x) for x in packed])
1148 packed[2] = struct.pack("!H", length)
1149 return ''.join(packed)
1150
1151 @staticmethod
1152 def unpack(buf):
1153 if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
1154 obj = bsn_set_l2_table()
1155 if type(buf) == loxi.generic_util.OFReader:
1156 reader = buf
1157 else:
1158 reader = loxi.generic_util.OFReader(buf)
1159 _version = reader.read('!B')[0]
1160 assert(_version == const.OFP_VERSION)
1161 _type = reader.read('!B')[0]
1162 assert(_type == const.OFPT_VENDOR)
1163 _length = reader.read('!H')[0]
1164 obj.xid = reader.read('!L')[0]
1165 _experimenter = reader.read('!L')[0]
1166 assert(_experimenter == 0x5c16c7)
1167 _subtype = reader.read('!L')[0]
1168 assert(_subtype == 12)
1169 obj.l2_table_enable = reader.read('!B')[0]
1170 reader.skip(1)
1171 obj.l2_table_priority = reader.read('!H')[0]
1172 reader.skip(4)
1173 return obj
1174
1175 def __eq__(self, other):
1176 if type(self) != type(other): return False
1177 if self.version != other.version: return False
1178 if self.type != other.type: return False
1179 if self.xid != other.xid: return False
1180 if self.l2_table_enable != other.l2_table_enable: return False
1181 if self.l2_table_priority != other.l2_table_priority: return False
1182 return True
1183
1184 def __ne__(self, other):
1185 return not self.__eq__(other)
1186
1187 def __str__(self):
1188 return self.show()
1189
1190 def show(self):
1191 import loxi.pp
1192 return loxi.pp.pp(self)
1193
1194 def pretty_print(self, q):
1195 q.text("bsn_set_l2_table {")
1196 with q.group():
1197 with q.indent(2):
1198 q.breakable()
1199 q.text("xid = ");
1200 if self.xid != None:
1201 q.text("%#x" % self.xid)
1202 else:
1203 q.text('None')
1204 q.text(","); q.breakable()
1205 q.text("l2_table_enable = ");
1206 q.text("%#x" % self.l2_table_enable)
1207 q.text(","); q.breakable()
1208 q.text("l2_table_priority = ");
1209 q.text("%#x" % self.l2_table_priority)
1210 q.breakable()
1211 q.text('}')
1212
Rich Laneb658ddd2013-03-12 10:15:10 -07001213class bsn_set_mirroring(Message):
1214 version = const.OFP_VERSION
1215 type = const.OFPT_VENDOR
1216 experimenter = 0x5c16c7
1217 subtype = 3
1218
Rich Lanec2ee4b82013-04-24 17:12:38 -07001219 def __init__(self, xid=None, report_mirror_ports=None):
Rich Laneb658ddd2013-03-12 10:15:10 -07001220 self.xid = xid
1221 if report_mirror_ports != None:
1222 self.report_mirror_ports = report_mirror_ports
1223 else:
1224 self.report_mirror_ports = 0
Rich Laneb658ddd2013-03-12 10:15:10 -07001225
1226 def pack(self):
1227 packed = []
1228 packed.append(struct.pack("!B", self.version))
1229 packed.append(struct.pack("!B", self.type))
1230 packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
1231 packed.append(struct.pack("!L", self.xid))
1232 packed.append(struct.pack("!L", self.experimenter))
1233 packed.append(struct.pack("!L", self.subtype))
1234 packed.append(struct.pack("!B", self.report_mirror_ports))
Rich Lanec2ee4b82013-04-24 17:12:38 -07001235 packed.append('\x00' * 3)
Rich Laneb658ddd2013-03-12 10:15:10 -07001236 length = sum([len(x) for x in packed])
1237 packed[2] = struct.pack("!H", length)
1238 return ''.join(packed)
1239
1240 @staticmethod
1241 def unpack(buf):
1242 if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
1243 obj = bsn_set_mirroring()
Rich Lanec2ee4b82013-04-24 17:12:38 -07001244 if type(buf) == loxi.generic_util.OFReader:
1245 reader = buf
1246 else:
1247 reader = loxi.generic_util.OFReader(buf)
1248 _version = reader.read('!B')[0]
1249 assert(_version == const.OFP_VERSION)
1250 _type = reader.read('!B')[0]
1251 assert(_type == const.OFPT_VENDOR)
1252 _length = reader.read('!H')[0]
1253 obj.xid = reader.read('!L')[0]
1254 _experimenter = reader.read('!L')[0]
1255 assert(_experimenter == 0x5c16c7)
1256 _subtype = reader.read('!L')[0]
1257 assert(_subtype == 3)
1258 obj.report_mirror_ports = reader.read('!B')[0]
1259 reader.skip(3)
Rich Laneb658ddd2013-03-12 10:15:10 -07001260 return obj
1261
1262 def __eq__(self, other):
1263 if type(self) != type(other): return False
1264 if self.version != other.version: return False
1265 if self.type != other.type: return False
1266 if self.xid != other.xid: return False
1267 if self.report_mirror_ports != other.report_mirror_ports: return False
Rich Laneb658ddd2013-03-12 10:15:10 -07001268 return True
1269
1270 def __ne__(self, other):
1271 return not self.__eq__(other)
1272
1273 def __str__(self):
1274 return self.show()
1275
1276 def show(self):
1277 import loxi.pp
1278 return loxi.pp.pp(self)
1279
1280 def pretty_print(self, q):
1281 q.text("bsn_set_mirroring {")
1282 with q.group():
1283 with q.indent(2):
1284 q.breakable()
1285 q.text("xid = ");
1286 if self.xid != None:
1287 q.text("%#x" % self.xid)
1288 else:
1289 q.text('None')
1290 q.text(","); q.breakable()
1291 q.text("report_mirror_ports = ");
1292 q.text("%#x" % self.report_mirror_ports)
Rich Lanec2ee4b82013-04-24 17:12:38 -07001293 q.breakable()
1294 q.text('}')
1295
1296class bsn_set_pktin_suppression(Message):
1297 version = const.OFP_VERSION
1298 type = const.OFPT_VENDOR
1299 experimenter = 0x5c16c7
1300 subtype = 11
1301
1302 def __init__(self, xid=None, enabled=None, idle_timeout=None, hard_timeout=None, priority=None, cookie=None):
1303 self.xid = xid
1304 if enabled != None:
1305 self.enabled = enabled
1306 else:
1307 self.enabled = 0
1308 if idle_timeout != None:
1309 self.idle_timeout = idle_timeout
1310 else:
1311 self.idle_timeout = 0
1312 if hard_timeout != None:
1313 self.hard_timeout = hard_timeout
1314 else:
1315 self.hard_timeout = 0
1316 if priority != None:
1317 self.priority = priority
1318 else:
1319 self.priority = 0
1320 if cookie != None:
1321 self.cookie = cookie
1322 else:
1323 self.cookie = 0
1324
1325 def pack(self):
1326 packed = []
1327 packed.append(struct.pack("!B", self.version))
1328 packed.append(struct.pack("!B", self.type))
1329 packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
1330 packed.append(struct.pack("!L", self.xid))
1331 packed.append(struct.pack("!L", self.experimenter))
1332 packed.append(struct.pack("!L", self.subtype))
1333 packed.append(struct.pack("!B", self.enabled))
1334 packed.append('\x00' * 1)
1335 packed.append(struct.pack("!H", self.idle_timeout))
1336 packed.append(struct.pack("!H", self.hard_timeout))
1337 packed.append(struct.pack("!H", self.priority))
1338 packed.append(struct.pack("!Q", self.cookie))
1339 length = sum([len(x) for x in packed])
1340 packed[2] = struct.pack("!H", length)
1341 return ''.join(packed)
1342
1343 @staticmethod
1344 def unpack(buf):
1345 if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
1346 obj = bsn_set_pktin_suppression()
1347 if type(buf) == loxi.generic_util.OFReader:
1348 reader = buf
1349 else:
1350 reader = loxi.generic_util.OFReader(buf)
1351 _version = reader.read('!B')[0]
1352 assert(_version == const.OFP_VERSION)
1353 _type = reader.read('!B')[0]
1354 assert(_type == const.OFPT_VENDOR)
1355 _length = reader.read('!H')[0]
1356 obj.xid = reader.read('!L')[0]
1357 _experimenter = reader.read('!L')[0]
1358 assert(_experimenter == 0x5c16c7)
1359 _subtype = reader.read('!L')[0]
1360 assert(_subtype == 11)
1361 obj.enabled = reader.read('!B')[0]
1362 reader.skip(1)
1363 obj.idle_timeout = reader.read('!H')[0]
1364 obj.hard_timeout = reader.read('!H')[0]
1365 obj.priority = reader.read('!H')[0]
1366 obj.cookie = reader.read('!Q')[0]
1367 return obj
1368
1369 def __eq__(self, other):
1370 if type(self) != type(other): return False
1371 if self.version != other.version: return False
1372 if self.type != other.type: return False
1373 if self.xid != other.xid: return False
1374 if self.enabled != other.enabled: return False
1375 if self.idle_timeout != other.idle_timeout: return False
1376 if self.hard_timeout != other.hard_timeout: return False
1377 if self.priority != other.priority: return False
1378 if self.cookie != other.cookie: return False
1379 return True
1380
1381 def __ne__(self, other):
1382 return not self.__eq__(other)
1383
1384 def __str__(self):
1385 return self.show()
1386
1387 def show(self):
1388 import loxi.pp
1389 return loxi.pp.pp(self)
1390
1391 def pretty_print(self, q):
1392 q.text("bsn_set_pktin_suppression {")
1393 with q.group():
1394 with q.indent(2):
1395 q.breakable()
1396 q.text("xid = ");
1397 if self.xid != None:
1398 q.text("%#x" % self.xid)
1399 else:
1400 q.text('None')
Rich Laneb658ddd2013-03-12 10:15:10 -07001401 q.text(","); q.breakable()
Rich Lanec2ee4b82013-04-24 17:12:38 -07001402 q.text("enabled = ");
1403 q.text("%#x" % self.enabled)
1404 q.text(","); q.breakable()
1405 q.text("idle_timeout = ");
1406 q.text("%#x" % self.idle_timeout)
1407 q.text(","); q.breakable()
1408 q.text("hard_timeout = ");
1409 q.text("%#x" % self.hard_timeout)
1410 q.text(","); q.breakable()
1411 q.text("priority = ");
1412 q.text("%#x" % self.priority)
1413 q.text(","); q.breakable()
1414 q.text("cookie = ");
1415 q.text("%#x" % self.cookie)
Rich Laneb658ddd2013-03-12 10:15:10 -07001416 q.breakable()
1417 q.text('}')
1418
1419class bsn_shell_command(Message):
1420 version = const.OFP_VERSION
1421 type = const.OFPT_VENDOR
1422 experimenter = 0x5c16c7
1423 subtype = 6
1424
1425 def __init__(self, xid=None, service=None, data=None):
1426 self.xid = xid
1427 if service != None:
1428 self.service = service
1429 else:
1430 self.service = 0
1431 if data != None:
1432 self.data = data
1433 else:
1434 self.data = ""
1435
1436 def pack(self):
1437 packed = []
1438 packed.append(struct.pack("!B", self.version))
1439 packed.append(struct.pack("!B", self.type))
1440 packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
1441 packed.append(struct.pack("!L", self.xid))
1442 packed.append(struct.pack("!L", self.experimenter))
1443 packed.append(struct.pack("!L", self.subtype))
1444 packed.append(struct.pack("!L", self.service))
1445 packed.append(self.data)
1446 length = sum([len(x) for x in packed])
1447 packed[2] = struct.pack("!H", length)
1448 return ''.join(packed)
1449
1450 @staticmethod
1451 def unpack(buf):
1452 if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
1453 obj = bsn_shell_command()
Rich Lanec2ee4b82013-04-24 17:12:38 -07001454 if type(buf) == loxi.generic_util.OFReader:
1455 reader = buf
1456 else:
1457 reader = loxi.generic_util.OFReader(buf)
1458 _version = reader.read('!B')[0]
1459 assert(_version == const.OFP_VERSION)
1460 _type = reader.read('!B')[0]
1461 assert(_type == const.OFPT_VENDOR)
1462 _length = reader.read('!H')[0]
1463 obj.xid = reader.read('!L')[0]
1464 _experimenter = reader.read('!L')[0]
1465 assert(_experimenter == 0x5c16c7)
1466 _subtype = reader.read('!L')[0]
1467 assert(_subtype == 6)
1468 obj.service = reader.read('!L')[0]
1469 obj.data = str(reader.read_all())
Rich Laneb658ddd2013-03-12 10:15:10 -07001470 return obj
1471
1472 def __eq__(self, other):
1473 if type(self) != type(other): return False
1474 if self.version != other.version: return False
1475 if self.type != other.type: return False
1476 if self.xid != other.xid: return False
1477 if self.service != other.service: return False
1478 if self.data != other.data: return False
1479 return True
1480
1481 def __ne__(self, other):
1482 return not self.__eq__(other)
1483
1484 def __str__(self):
1485 return self.show()
1486
1487 def show(self):
1488 import loxi.pp
1489 return loxi.pp.pp(self)
1490
1491 def pretty_print(self, q):
1492 q.text("bsn_shell_command {")
1493 with q.group():
1494 with q.indent(2):
1495 q.breakable()
1496 q.text("xid = ");
1497 if self.xid != None:
1498 q.text("%#x" % self.xid)
1499 else:
1500 q.text('None')
1501 q.text(","); q.breakable()
1502 q.text("service = ");
1503 q.text("%#x" % self.service)
1504 q.text(","); q.breakable()
1505 q.text("data = ");
1506 q.pp(self.data)
1507 q.breakable()
1508 q.text('}')
1509
1510class bsn_shell_output(Message):
1511 version = const.OFP_VERSION
1512 type = const.OFPT_VENDOR
1513 experimenter = 0x5c16c7
1514 subtype = 7
1515
1516 def __init__(self, xid=None, data=None):
1517 self.xid = xid
1518 if data != None:
1519 self.data = data
1520 else:
1521 self.data = ""
1522
1523 def pack(self):
1524 packed = []
1525 packed.append(struct.pack("!B", self.version))
1526 packed.append(struct.pack("!B", self.type))
1527 packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
1528 packed.append(struct.pack("!L", self.xid))
1529 packed.append(struct.pack("!L", self.experimenter))
1530 packed.append(struct.pack("!L", self.subtype))
1531 packed.append(self.data)
1532 length = sum([len(x) for x in packed])
1533 packed[2] = struct.pack("!H", length)
1534 return ''.join(packed)
1535
1536 @staticmethod
1537 def unpack(buf):
1538 if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
1539 obj = bsn_shell_output()
Rich Lanec2ee4b82013-04-24 17:12:38 -07001540 if type(buf) == loxi.generic_util.OFReader:
1541 reader = buf
1542 else:
1543 reader = loxi.generic_util.OFReader(buf)
1544 _version = reader.read('!B')[0]
1545 assert(_version == const.OFP_VERSION)
1546 _type = reader.read('!B')[0]
1547 assert(_type == const.OFPT_VENDOR)
1548 _length = reader.read('!H')[0]
1549 obj.xid = reader.read('!L')[0]
1550 _experimenter = reader.read('!L')[0]
1551 assert(_experimenter == 0x5c16c7)
1552 _subtype = reader.read('!L')[0]
1553 assert(_subtype == 7)
1554 obj.data = str(reader.read_all())
Rich Laneb658ddd2013-03-12 10:15:10 -07001555 return obj
1556
1557 def __eq__(self, other):
1558 if type(self) != type(other): return False
1559 if self.version != other.version: return False
1560 if self.type != other.type: return False
1561 if self.xid != other.xid: return False
1562 if self.data != other.data: return False
1563 return True
1564
1565 def __ne__(self, other):
1566 return not self.__eq__(other)
1567
1568 def __str__(self):
1569 return self.show()
1570
1571 def show(self):
1572 import loxi.pp
1573 return loxi.pp.pp(self)
1574
1575 def pretty_print(self, q):
1576 q.text("bsn_shell_output {")
1577 with q.group():
1578 with q.indent(2):
1579 q.breakable()
1580 q.text("xid = ");
1581 if self.xid != None:
1582 q.text("%#x" % self.xid)
1583 else:
1584 q.text('None')
1585 q.text(","); q.breakable()
1586 q.text("data = ");
1587 q.pp(self.data)
1588 q.breakable()
1589 q.text('}')
1590
1591class bsn_shell_status(Message):
1592 version = const.OFP_VERSION
1593 type = const.OFPT_VENDOR
1594 experimenter = 0x5c16c7
1595 subtype = 8
1596
1597 def __init__(self, xid=None, status=None):
1598 self.xid = xid
1599 if status != None:
1600 self.status = status
1601 else:
1602 self.status = 0
1603
1604 def pack(self):
1605 packed = []
1606 packed.append(struct.pack("!B", self.version))
1607 packed.append(struct.pack("!B", self.type))
1608 packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
1609 packed.append(struct.pack("!L", self.xid))
1610 packed.append(struct.pack("!L", self.experimenter))
1611 packed.append(struct.pack("!L", self.subtype))
1612 packed.append(struct.pack("!L", self.status))
1613 length = sum([len(x) for x in packed])
1614 packed[2] = struct.pack("!H", length)
1615 return ''.join(packed)
1616
1617 @staticmethod
1618 def unpack(buf):
1619 if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
1620 obj = bsn_shell_status()
Rich Lanec2ee4b82013-04-24 17:12:38 -07001621 if type(buf) == loxi.generic_util.OFReader:
1622 reader = buf
1623 else:
1624 reader = loxi.generic_util.OFReader(buf)
1625 _version = reader.read('!B')[0]
1626 assert(_version == const.OFP_VERSION)
1627 _type = reader.read('!B')[0]
1628 assert(_type == const.OFPT_VENDOR)
1629 _length = reader.read('!H')[0]
1630 obj.xid = reader.read('!L')[0]
1631 _experimenter = reader.read('!L')[0]
1632 assert(_experimenter == 0x5c16c7)
1633 _subtype = reader.read('!L')[0]
1634 assert(_subtype == 8)
1635 obj.status = reader.read('!L')[0]
Rich Laneb658ddd2013-03-12 10:15:10 -07001636 return obj
1637
1638 def __eq__(self, other):
1639 if type(self) != type(other): return False
1640 if self.version != other.version: return False
1641 if self.type != other.type: return False
1642 if self.xid != other.xid: return False
1643 if self.status != other.status: return False
1644 return True
1645
1646 def __ne__(self, other):
1647 return not self.__eq__(other)
1648
1649 def __str__(self):
1650 return self.show()
1651
1652 def show(self):
1653 import loxi.pp
1654 return loxi.pp.pp(self)
1655
1656 def pretty_print(self, q):
1657 q.text("bsn_shell_status {")
1658 with q.group():
1659 with q.indent(2):
1660 q.breakable()
1661 q.text("xid = ");
1662 if self.xid != None:
1663 q.text("%#x" % self.xid)
1664 else:
1665 q.text('None')
1666 q.text(","); q.breakable()
1667 q.text("status = ");
1668 q.text("%#x" % self.status)
1669 q.breakable()
1670 q.text('}')
1671
1672class desc_stats_reply(Message):
1673 version = const.OFP_VERSION
1674 type = const.OFPT_STATS_REPLY
1675 stats_type = const.OFPST_DESC
1676
1677 def __init__(self, xid=None, flags=None, mfr_desc=None, hw_desc=None, sw_desc=None, serial_num=None, dp_desc=None):
1678 self.xid = xid
1679 if flags != None:
1680 self.flags = flags
1681 else:
1682 self.flags = 0
1683 if mfr_desc != None:
1684 self.mfr_desc = mfr_desc
1685 else:
1686 self.mfr_desc = ""
1687 if hw_desc != None:
1688 self.hw_desc = hw_desc
1689 else:
1690 self.hw_desc = ""
1691 if sw_desc != None:
1692 self.sw_desc = sw_desc
1693 else:
1694 self.sw_desc = ""
1695 if serial_num != None:
1696 self.serial_num = serial_num
1697 else:
1698 self.serial_num = ""
1699 if dp_desc != None:
1700 self.dp_desc = dp_desc
1701 else:
1702 self.dp_desc = ""
1703
1704 def pack(self):
1705 packed = []
1706 packed.append(struct.pack("!B", self.version))
1707 packed.append(struct.pack("!B", self.type))
1708 packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
1709 packed.append(struct.pack("!L", self.xid))
1710 packed.append(struct.pack("!H", self.stats_type))
1711 packed.append(struct.pack("!H", self.flags))
1712 packed.append(struct.pack("!256s", self.mfr_desc))
1713 packed.append(struct.pack("!256s", self.hw_desc))
1714 packed.append(struct.pack("!256s", self.sw_desc))
1715 packed.append(struct.pack("!32s", self.serial_num))
1716 packed.append(struct.pack("!256s", self.dp_desc))
1717 length = sum([len(x) for x in packed])
1718 packed[2] = struct.pack("!H", length)
1719 return ''.join(packed)
1720
1721 @staticmethod
1722 def unpack(buf):
1723 if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
1724 obj = desc_stats_reply()
Rich Lanec2ee4b82013-04-24 17:12:38 -07001725 if type(buf) == loxi.generic_util.OFReader:
1726 reader = buf
1727 else:
1728 reader = loxi.generic_util.OFReader(buf)
1729 _version = reader.read('!B')[0]
1730 assert(_version == const.OFP_VERSION)
1731 _type = reader.read('!B')[0]
1732 assert(_type == const.OFPT_STATS_REPLY)
1733 _length = reader.read('!H')[0]
1734 obj.xid = reader.read('!L')[0]
1735 _stats_type = reader.read('!H')[0]
1736 assert(_stats_type == const.OFPST_DESC)
1737 obj.flags = reader.read('!H')[0]
1738 obj.mfr_desc = reader.read("!256s")[0].rstrip("\x00")
1739 obj.hw_desc = reader.read("!256s")[0].rstrip("\x00")
1740 obj.sw_desc = reader.read("!256s")[0].rstrip("\x00")
1741 obj.serial_num = reader.read("!32s")[0].rstrip("\x00")
1742 obj.dp_desc = reader.read("!256s")[0].rstrip("\x00")
Rich Laneb658ddd2013-03-12 10:15:10 -07001743 return obj
1744
1745 def __eq__(self, other):
1746 if type(self) != type(other): return False
1747 if self.version != other.version: return False
1748 if self.type != other.type: return False
1749 if self.xid != other.xid: return False
1750 if self.flags != other.flags: return False
1751 if self.mfr_desc != other.mfr_desc: return False
1752 if self.hw_desc != other.hw_desc: return False
1753 if self.sw_desc != other.sw_desc: return False
1754 if self.serial_num != other.serial_num: return False
1755 if self.dp_desc != other.dp_desc: return False
1756 return True
1757
1758 def __ne__(self, other):
1759 return not self.__eq__(other)
1760
1761 def __str__(self):
1762 return self.show()
1763
1764 def show(self):
1765 import loxi.pp
1766 return loxi.pp.pp(self)
1767
1768 def pretty_print(self, q):
1769 q.text("desc_stats_reply {")
1770 with q.group():
1771 with q.indent(2):
1772 q.breakable()
1773 q.text("xid = ");
1774 if self.xid != None:
1775 q.text("%#x" % self.xid)
1776 else:
1777 q.text('None')
1778 q.text(","); q.breakable()
1779 q.text("flags = ");
1780 q.text("%#x" % self.flags)
1781 q.text(","); q.breakable()
1782 q.text("mfr_desc = ");
1783 q.pp(self.mfr_desc)
1784 q.text(","); q.breakable()
1785 q.text("hw_desc = ");
1786 q.pp(self.hw_desc)
1787 q.text(","); q.breakable()
1788 q.text("sw_desc = ");
1789 q.pp(self.sw_desc)
1790 q.text(","); q.breakable()
1791 q.text("serial_num = ");
1792 q.pp(self.serial_num)
1793 q.text(","); q.breakable()
1794 q.text("dp_desc = ");
1795 q.pp(self.dp_desc)
1796 q.breakable()
1797 q.text('}')
1798
1799class desc_stats_request(Message):
1800 version = const.OFP_VERSION
1801 type = const.OFPT_STATS_REQUEST
1802 stats_type = const.OFPST_DESC
1803
1804 def __init__(self, xid=None, flags=None):
1805 self.xid = xid
1806 if flags != None:
1807 self.flags = flags
1808 else:
1809 self.flags = 0
1810
1811 def pack(self):
1812 packed = []
1813 packed.append(struct.pack("!B", self.version))
1814 packed.append(struct.pack("!B", self.type))
1815 packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
1816 packed.append(struct.pack("!L", self.xid))
1817 packed.append(struct.pack("!H", self.stats_type))
1818 packed.append(struct.pack("!H", self.flags))
1819 length = sum([len(x) for x in packed])
1820 packed[2] = struct.pack("!H", length)
1821 return ''.join(packed)
1822
1823 @staticmethod
1824 def unpack(buf):
1825 if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
1826 obj = desc_stats_request()
Rich Lanec2ee4b82013-04-24 17:12:38 -07001827 if type(buf) == loxi.generic_util.OFReader:
1828 reader = buf
1829 else:
1830 reader = loxi.generic_util.OFReader(buf)
1831 _version = reader.read('!B')[0]
1832 assert(_version == const.OFP_VERSION)
1833 _type = reader.read('!B')[0]
1834 assert(_type == const.OFPT_STATS_REQUEST)
1835 _length = reader.read('!H')[0]
1836 obj.xid = reader.read('!L')[0]
1837 _stats_type = reader.read('!H')[0]
1838 assert(_stats_type == const.OFPST_DESC)
1839 obj.flags = reader.read('!H')[0]
Rich Laneb658ddd2013-03-12 10:15:10 -07001840 return obj
1841
1842 def __eq__(self, other):
1843 if type(self) != type(other): return False
1844 if self.version != other.version: return False
1845 if self.type != other.type: return False
1846 if self.xid != other.xid: return False
1847 if self.flags != other.flags: return False
1848 return True
1849
1850 def __ne__(self, other):
1851 return not self.__eq__(other)
1852
1853 def __str__(self):
1854 return self.show()
1855
1856 def show(self):
1857 import loxi.pp
1858 return loxi.pp.pp(self)
1859
1860 def pretty_print(self, q):
1861 q.text("desc_stats_request {")
1862 with q.group():
1863 with q.indent(2):
1864 q.breakable()
1865 q.text("xid = ");
1866 if self.xid != None:
1867 q.text("%#x" % self.xid)
1868 else:
1869 q.text('None')
1870 q.text(","); q.breakable()
1871 q.text("flags = ");
1872 q.text("%#x" % self.flags)
1873 q.breakable()
1874 q.text('}')
1875
1876class echo_reply(Message):
1877 version = const.OFP_VERSION
1878 type = const.OFPT_ECHO_REPLY
1879
1880 def __init__(self, xid=None, data=None):
1881 self.xid = xid
1882 if data != None:
1883 self.data = data
1884 else:
1885 self.data = ""
1886
1887 def pack(self):
1888 packed = []
1889 packed.append(struct.pack("!B", self.version))
1890 packed.append(struct.pack("!B", self.type))
1891 packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
1892 packed.append(struct.pack("!L", self.xid))
1893 packed.append(self.data)
1894 length = sum([len(x) for x in packed])
1895 packed[2] = struct.pack("!H", length)
1896 return ''.join(packed)
1897
1898 @staticmethod
1899 def unpack(buf):
1900 if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
1901 obj = echo_reply()
Rich Lanec2ee4b82013-04-24 17:12:38 -07001902 if type(buf) == loxi.generic_util.OFReader:
1903 reader = buf
1904 else:
1905 reader = loxi.generic_util.OFReader(buf)
1906 _version = reader.read('!B')[0]
1907 assert(_version == const.OFP_VERSION)
1908 _type = reader.read('!B')[0]
1909 assert(_type == const.OFPT_ECHO_REPLY)
1910 _length = reader.read('!H')[0]
1911 obj.xid = reader.read('!L')[0]
1912 obj.data = str(reader.read_all())
Rich Laneb658ddd2013-03-12 10:15:10 -07001913 return obj
1914
1915 def __eq__(self, other):
1916 if type(self) != type(other): return False
1917 if self.version != other.version: return False
1918 if self.type != other.type: return False
1919 if self.xid != other.xid: return False
1920 if self.data != other.data: return False
1921 return True
1922
1923 def __ne__(self, other):
1924 return not self.__eq__(other)
1925
1926 def __str__(self):
1927 return self.show()
1928
1929 def show(self):
1930 import loxi.pp
1931 return loxi.pp.pp(self)
1932
1933 def pretty_print(self, q):
1934 q.text("echo_reply {")
1935 with q.group():
1936 with q.indent(2):
1937 q.breakable()
1938 q.text("xid = ");
1939 if self.xid != None:
1940 q.text("%#x" % self.xid)
1941 else:
1942 q.text('None')
1943 q.text(","); q.breakable()
1944 q.text("data = ");
1945 q.pp(self.data)
1946 q.breakable()
1947 q.text('}')
1948
1949class echo_request(Message):
1950 version = const.OFP_VERSION
1951 type = const.OFPT_ECHO_REQUEST
1952
1953 def __init__(self, xid=None, data=None):
1954 self.xid = xid
1955 if data != None:
1956 self.data = data
1957 else:
1958 self.data = ""
1959
1960 def pack(self):
1961 packed = []
1962 packed.append(struct.pack("!B", self.version))
1963 packed.append(struct.pack("!B", self.type))
1964 packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
1965 packed.append(struct.pack("!L", self.xid))
1966 packed.append(self.data)
1967 length = sum([len(x) for x in packed])
1968 packed[2] = struct.pack("!H", length)
1969 return ''.join(packed)
1970
1971 @staticmethod
1972 def unpack(buf):
1973 if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
1974 obj = echo_request()
Rich Lanec2ee4b82013-04-24 17:12:38 -07001975 if type(buf) == loxi.generic_util.OFReader:
1976 reader = buf
1977 else:
1978 reader = loxi.generic_util.OFReader(buf)
1979 _version = reader.read('!B')[0]
1980 assert(_version == const.OFP_VERSION)
1981 _type = reader.read('!B')[0]
1982 assert(_type == const.OFPT_ECHO_REQUEST)
1983 _length = reader.read('!H')[0]
1984 obj.xid = reader.read('!L')[0]
1985 obj.data = str(reader.read_all())
Rich Laneb658ddd2013-03-12 10:15:10 -07001986 return obj
1987
1988 def __eq__(self, other):
1989 if type(self) != type(other): return False
1990 if self.version != other.version: return False
1991 if self.type != other.type: return False
1992 if self.xid != other.xid: return False
1993 if self.data != other.data: return False
1994 return True
1995
1996 def __ne__(self, other):
1997 return not self.__eq__(other)
1998
1999 def __str__(self):
2000 return self.show()
2001
2002 def show(self):
2003 import loxi.pp
2004 return loxi.pp.pp(self)
2005
2006 def pretty_print(self, q):
2007 q.text("echo_request {")
2008 with q.group():
2009 with q.indent(2):
2010 q.breakable()
2011 q.text("xid = ");
2012 if self.xid != None:
2013 q.text("%#x" % self.xid)
2014 else:
2015 q.text('None')
2016 q.text(","); q.breakable()
2017 q.text("data = ");
2018 q.pp(self.data)
2019 q.breakable()
2020 q.text('}')
2021
2022class error_msg(Message):
2023 version = const.OFP_VERSION
2024 type = const.OFPT_ERROR
2025
2026 def __init__(self, xid=None, err_type=None, code=None, data=None):
2027 self.xid = xid
2028 if err_type != None:
2029 self.err_type = err_type
2030 else:
2031 self.err_type = 0
2032 if code != None:
2033 self.code = code
2034 else:
2035 self.code = 0
2036 if data != None:
2037 self.data = data
2038 else:
2039 self.data = ""
2040
2041 def pack(self):
2042 packed = []
2043 packed.append(struct.pack("!B", self.version))
2044 packed.append(struct.pack("!B", self.type))
2045 packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
2046 packed.append(struct.pack("!L", self.xid))
2047 packed.append(struct.pack("!H", self.err_type))
2048 packed.append(struct.pack("!H", self.code))
2049 packed.append(self.data)
2050 length = sum([len(x) for x in packed])
2051 packed[2] = struct.pack("!H", length)
2052 return ''.join(packed)
2053
2054 @staticmethod
2055 def unpack(buf):
2056 if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
2057 obj = error_msg()
Rich Lanec2ee4b82013-04-24 17:12:38 -07002058 if type(buf) == loxi.generic_util.OFReader:
2059 reader = buf
2060 else:
2061 reader = loxi.generic_util.OFReader(buf)
2062 _version = reader.read('!B')[0]
2063 assert(_version == const.OFP_VERSION)
2064 _type = reader.read('!B')[0]
2065 assert(_type == const.OFPT_ERROR)
2066 _length = reader.read('!H')[0]
2067 obj.xid = reader.read('!L')[0]
2068 obj.err_type = reader.read('!H')[0]
2069 obj.code = reader.read('!H')[0]
2070 obj.data = str(reader.read_all())
Rich Laneb658ddd2013-03-12 10:15:10 -07002071 return obj
2072
2073 def __eq__(self, other):
2074 if type(self) != type(other): return False
2075 if self.version != other.version: return False
2076 if self.type != other.type: return False
2077 if self.xid != other.xid: return False
2078 if self.err_type != other.err_type: return False
2079 if self.code != other.code: return False
2080 if self.data != other.data: return False
2081 return True
2082
2083 def __ne__(self, other):
2084 return not self.__eq__(other)
2085
2086 def __str__(self):
2087 return self.show()
2088
2089 def show(self):
2090 import loxi.pp
2091 return loxi.pp.pp(self)
2092
2093 def pretty_print(self, q):
2094 q.text("error_msg {")
2095 with q.group():
2096 with q.indent(2):
2097 q.breakable()
2098 q.text("xid = ");
2099 if self.xid != None:
2100 q.text("%#x" % self.xid)
2101 else:
2102 q.text('None')
2103 q.text(","); q.breakable()
2104 q.text("err_type = ");
2105 q.text("%#x" % self.err_type)
2106 q.text(","); q.breakable()
2107 q.text("code = ");
2108 q.text("%#x" % self.code)
2109 q.text(","); q.breakable()
2110 q.text("data = ");
2111 q.pp(self.data)
2112 q.breakable()
2113 q.text('}')
2114
2115class experimenter_stats_reply(Message):
2116 version = const.OFP_VERSION
2117 type = const.OFPT_STATS_REPLY
2118 stats_type = const.OFPST_VENDOR
2119
2120 def __init__(self, xid=None, flags=None, experimenter=None, data=None):
2121 self.xid = xid
2122 if flags != None:
2123 self.flags = flags
2124 else:
2125 self.flags = 0
2126 if experimenter != None:
2127 self.experimenter = experimenter
2128 else:
2129 self.experimenter = 0
2130 if data != None:
2131 self.data = data
2132 else:
2133 self.data = ""
2134
2135 def pack(self):
2136 packed = []
2137 packed.append(struct.pack("!B", self.version))
2138 packed.append(struct.pack("!B", self.type))
2139 packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
2140 packed.append(struct.pack("!L", self.xid))
2141 packed.append(struct.pack("!H", self.stats_type))
2142 packed.append(struct.pack("!H", self.flags))
2143 packed.append(struct.pack("!L", self.experimenter))
2144 packed.append(self.data)
2145 length = sum([len(x) for x in packed])
2146 packed[2] = struct.pack("!H", length)
2147 return ''.join(packed)
2148
2149 @staticmethod
2150 def unpack(buf):
2151 if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
2152 obj = experimenter_stats_reply()
Rich Lanec2ee4b82013-04-24 17:12:38 -07002153 if type(buf) == loxi.generic_util.OFReader:
2154 reader = buf
2155 else:
2156 reader = loxi.generic_util.OFReader(buf)
2157 _version = reader.read('!B')[0]
2158 assert(_version == const.OFP_VERSION)
2159 _type = reader.read('!B')[0]
2160 assert(_type == const.OFPT_STATS_REPLY)
2161 _length = reader.read('!H')[0]
2162 obj.xid = reader.read('!L')[0]
2163 _stats_type = reader.read('!H')[0]
2164 assert(_stats_type == const.OFPST_VENDOR)
2165 obj.flags = reader.read('!H')[0]
2166 obj.experimenter = reader.read('!L')[0]
2167 obj.data = str(reader.read_all())
Rich Laneb658ddd2013-03-12 10:15:10 -07002168 return obj
2169
2170 def __eq__(self, other):
2171 if type(self) != type(other): return False
2172 if self.version != other.version: return False
2173 if self.type != other.type: return False
2174 if self.xid != other.xid: return False
2175 if self.flags != other.flags: return False
2176 if self.experimenter != other.experimenter: return False
2177 if self.data != other.data: return False
2178 return True
2179
2180 def __ne__(self, other):
2181 return not self.__eq__(other)
2182
2183 def __str__(self):
2184 return self.show()
2185
2186 def show(self):
2187 import loxi.pp
2188 return loxi.pp.pp(self)
2189
2190 def pretty_print(self, q):
2191 q.text("experimenter_stats_reply {")
2192 with q.group():
2193 with q.indent(2):
2194 q.breakable()
2195 q.text("xid = ");
2196 if self.xid != None:
2197 q.text("%#x" % self.xid)
2198 else:
2199 q.text('None')
2200 q.text(","); q.breakable()
2201 q.text("flags = ");
2202 q.text("%#x" % self.flags)
2203 q.text(","); q.breakable()
2204 q.text("experimenter = ");
2205 q.text("%#x" % self.experimenter)
2206 q.text(","); q.breakable()
2207 q.text("data = ");
2208 q.pp(self.data)
2209 q.breakable()
2210 q.text('}')
2211
2212class experimenter_stats_request(Message):
2213 version = const.OFP_VERSION
2214 type = const.OFPT_STATS_REQUEST
2215 stats_type = const.OFPST_VENDOR
2216
2217 def __init__(self, xid=None, flags=None, experimenter=None, data=None):
2218 self.xid = xid
2219 if flags != None:
2220 self.flags = flags
2221 else:
2222 self.flags = 0
2223 if experimenter != None:
2224 self.experimenter = experimenter
2225 else:
2226 self.experimenter = 0
2227 if data != None:
2228 self.data = data
2229 else:
2230 self.data = ""
2231
2232 def pack(self):
2233 packed = []
2234 packed.append(struct.pack("!B", self.version))
2235 packed.append(struct.pack("!B", self.type))
2236 packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
2237 packed.append(struct.pack("!L", self.xid))
2238 packed.append(struct.pack("!H", self.stats_type))
2239 packed.append(struct.pack("!H", self.flags))
2240 packed.append(struct.pack("!L", self.experimenter))
2241 packed.append(self.data)
2242 length = sum([len(x) for x in packed])
2243 packed[2] = struct.pack("!H", length)
2244 return ''.join(packed)
2245
2246 @staticmethod
2247 def unpack(buf):
2248 if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
2249 obj = experimenter_stats_request()
Rich Lanec2ee4b82013-04-24 17:12:38 -07002250 if type(buf) == loxi.generic_util.OFReader:
2251 reader = buf
2252 else:
2253 reader = loxi.generic_util.OFReader(buf)
2254 _version = reader.read('!B')[0]
2255 assert(_version == const.OFP_VERSION)
2256 _type = reader.read('!B')[0]
2257 assert(_type == const.OFPT_STATS_REQUEST)
2258 _length = reader.read('!H')[0]
2259 obj.xid = reader.read('!L')[0]
2260 _stats_type = reader.read('!H')[0]
2261 assert(_stats_type == const.OFPST_VENDOR)
2262 obj.flags = reader.read('!H')[0]
2263 obj.experimenter = reader.read('!L')[0]
2264 obj.data = str(reader.read_all())
Rich Laneb658ddd2013-03-12 10:15:10 -07002265 return obj
2266
2267 def __eq__(self, other):
2268 if type(self) != type(other): return False
2269 if self.version != other.version: return False
2270 if self.type != other.type: return False
2271 if self.xid != other.xid: return False
2272 if self.flags != other.flags: return False
2273 if self.experimenter != other.experimenter: return False
2274 if self.data != other.data: return False
2275 return True
2276
2277 def __ne__(self, other):
2278 return not self.__eq__(other)
2279
2280 def __str__(self):
2281 return self.show()
2282
2283 def show(self):
2284 import loxi.pp
2285 return loxi.pp.pp(self)
2286
2287 def pretty_print(self, q):
2288 q.text("experimenter_stats_request {")
2289 with q.group():
2290 with q.indent(2):
2291 q.breakable()
2292 q.text("xid = ");
2293 if self.xid != None:
2294 q.text("%#x" % self.xid)
2295 else:
2296 q.text('None')
2297 q.text(","); q.breakable()
2298 q.text("flags = ");
2299 q.text("%#x" % self.flags)
2300 q.text(","); q.breakable()
2301 q.text("experimenter = ");
2302 q.text("%#x" % self.experimenter)
2303 q.text(","); q.breakable()
2304 q.text("data = ");
2305 q.pp(self.data)
2306 q.breakable()
2307 q.text('}')
2308
2309class features_reply(Message):
2310 version = const.OFP_VERSION
2311 type = const.OFPT_FEATURES_REPLY
2312
Rich Lanec2ee4b82013-04-24 17:12:38 -07002313 def __init__(self, xid=None, datapath_id=None, n_buffers=None, n_tables=None, capabilities=None, actions=None, ports=None):
Rich Laneb658ddd2013-03-12 10:15:10 -07002314 self.xid = xid
2315 if datapath_id != None:
2316 self.datapath_id = datapath_id
2317 else:
2318 self.datapath_id = 0
2319 if n_buffers != None:
2320 self.n_buffers = n_buffers
2321 else:
2322 self.n_buffers = 0
2323 if n_tables != None:
2324 self.n_tables = n_tables
2325 else:
2326 self.n_tables = 0
Rich Laneb658ddd2013-03-12 10:15:10 -07002327 if capabilities != None:
2328 self.capabilities = capabilities
2329 else:
2330 self.capabilities = 0
2331 if actions != None:
2332 self.actions = actions
2333 else:
2334 self.actions = 0
2335 if ports != None:
2336 self.ports = ports
2337 else:
2338 self.ports = []
2339
2340 def pack(self):
2341 packed = []
2342 packed.append(struct.pack("!B", self.version))
2343 packed.append(struct.pack("!B", self.type))
2344 packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
2345 packed.append(struct.pack("!L", self.xid))
2346 packed.append(struct.pack("!Q", self.datapath_id))
2347 packed.append(struct.pack("!L", self.n_buffers))
2348 packed.append(struct.pack("!B", self.n_tables))
Rich Lanec2ee4b82013-04-24 17:12:38 -07002349 packed.append('\x00' * 3)
Rich Laneb658ddd2013-03-12 10:15:10 -07002350 packed.append(struct.pack("!L", self.capabilities))
2351 packed.append(struct.pack("!L", self.actions))
2352 packed.append("".join([x.pack() for x in self.ports]))
2353 length = sum([len(x) for x in packed])
2354 packed[2] = struct.pack("!H", length)
2355 return ''.join(packed)
2356
2357 @staticmethod
2358 def unpack(buf):
2359 if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
2360 obj = features_reply()
Rich Lanec2ee4b82013-04-24 17:12:38 -07002361 if type(buf) == loxi.generic_util.OFReader:
2362 reader = buf
2363 else:
2364 reader = loxi.generic_util.OFReader(buf)
2365 _version = reader.read('!B')[0]
2366 assert(_version == const.OFP_VERSION)
2367 _type = reader.read('!B')[0]
2368 assert(_type == const.OFPT_FEATURES_REPLY)
2369 _length = reader.read('!H')[0]
2370 obj.xid = reader.read('!L')[0]
2371 obj.datapath_id = reader.read('!Q')[0]
2372 obj.n_buffers = reader.read('!L')[0]
2373 obj.n_tables = reader.read('!B')[0]
2374 reader.skip(3)
2375 obj.capabilities = reader.read('!L')[0]
2376 obj.actions = reader.read('!L')[0]
2377 obj.ports = loxi.generic_util.unpack_list(reader, common.port_desc.unpack)
Rich Laneb658ddd2013-03-12 10:15:10 -07002378 return obj
2379
2380 def __eq__(self, other):
2381 if type(self) != type(other): return False
2382 if self.version != other.version: return False
2383 if self.type != other.type: return False
2384 if self.xid != other.xid: return False
2385 if self.datapath_id != other.datapath_id: return False
2386 if self.n_buffers != other.n_buffers: return False
2387 if self.n_tables != other.n_tables: return False
Rich Laneb658ddd2013-03-12 10:15:10 -07002388 if self.capabilities != other.capabilities: return False
2389 if self.actions != other.actions: return False
2390 if self.ports != other.ports: return False
2391 return True
2392
2393 def __ne__(self, other):
2394 return not self.__eq__(other)
2395
2396 def __str__(self):
2397 return self.show()
2398
2399 def show(self):
2400 import loxi.pp
2401 return loxi.pp.pp(self)
2402
2403 def pretty_print(self, q):
2404 q.text("features_reply {")
2405 with q.group():
2406 with q.indent(2):
2407 q.breakable()
2408 q.text("xid = ");
2409 if self.xid != None:
2410 q.text("%#x" % self.xid)
2411 else:
2412 q.text('None')
2413 q.text(","); q.breakable()
2414 q.text("datapath_id = ");
2415 q.text("%#x" % self.datapath_id)
2416 q.text(","); q.breakable()
2417 q.text("n_buffers = ");
2418 q.text("%#x" % self.n_buffers)
2419 q.text(","); q.breakable()
2420 q.text("n_tables = ");
2421 q.text("%#x" % self.n_tables)
2422 q.text(","); q.breakable()
Rich Laneb658ddd2013-03-12 10:15:10 -07002423 q.text("capabilities = ");
2424 q.text("%#x" % self.capabilities)
2425 q.text(","); q.breakable()
2426 q.text("actions = ");
2427 q.text("%#x" % self.actions)
2428 q.text(","); q.breakable()
2429 q.text("ports = ");
2430 q.pp(self.ports)
2431 q.breakable()
2432 q.text('}')
2433
2434class features_request(Message):
2435 version = const.OFP_VERSION
2436 type = const.OFPT_FEATURES_REQUEST
2437
2438 def __init__(self, xid=None):
2439 self.xid = xid
2440
2441 def pack(self):
2442 packed = []
2443 packed.append(struct.pack("!B", self.version))
2444 packed.append(struct.pack("!B", self.type))
2445 packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
2446 packed.append(struct.pack("!L", self.xid))
2447 length = sum([len(x) for x in packed])
2448 packed[2] = struct.pack("!H", length)
2449 return ''.join(packed)
2450
2451 @staticmethod
2452 def unpack(buf):
2453 if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
2454 obj = features_request()
Rich Lanec2ee4b82013-04-24 17:12:38 -07002455 if type(buf) == loxi.generic_util.OFReader:
2456 reader = buf
2457 else:
2458 reader = loxi.generic_util.OFReader(buf)
2459 _version = reader.read('!B')[0]
2460 assert(_version == const.OFP_VERSION)
2461 _type = reader.read('!B')[0]
2462 assert(_type == const.OFPT_FEATURES_REQUEST)
2463 _length = reader.read('!H')[0]
2464 obj.xid = reader.read('!L')[0]
Rich Laneb658ddd2013-03-12 10:15:10 -07002465 return obj
2466
2467 def __eq__(self, other):
2468 if type(self) != type(other): return False
2469 if self.version != other.version: return False
2470 if self.type != other.type: return False
2471 if self.xid != other.xid: return False
2472 return True
2473
2474 def __ne__(self, other):
2475 return not self.__eq__(other)
2476
2477 def __str__(self):
2478 return self.show()
2479
2480 def show(self):
2481 import loxi.pp
2482 return loxi.pp.pp(self)
2483
2484 def pretty_print(self, q):
2485 q.text("features_request {")
2486 with q.group():
2487 with q.indent(2):
2488 q.breakable()
2489 q.text("xid = ");
2490 if self.xid != None:
2491 q.text("%#x" % self.xid)
2492 else:
2493 q.text('None')
2494 q.breakable()
2495 q.text('}')
2496
2497class flow_add(Message):
2498 version = const.OFP_VERSION
2499 type = const.OFPT_FLOW_MOD
2500 _command = const.OFPFC_ADD
2501
2502 def __init__(self, xid=None, match=None, cookie=None, idle_timeout=None, hard_timeout=None, priority=None, buffer_id=None, out_port=None, flags=None, actions=None):
2503 self.xid = xid
2504 if match != None:
2505 self.match = match
2506 else:
2507 self.match = common.match()
2508 if cookie != None:
2509 self.cookie = cookie
2510 else:
2511 self.cookie = 0
2512 if idle_timeout != None:
2513 self.idle_timeout = idle_timeout
2514 else:
2515 self.idle_timeout = 0
2516 if hard_timeout != None:
2517 self.hard_timeout = hard_timeout
2518 else:
2519 self.hard_timeout = 0
2520 if priority != None:
2521 self.priority = priority
2522 else:
2523 self.priority = 0
2524 if buffer_id != None:
2525 self.buffer_id = buffer_id
2526 else:
2527 self.buffer_id = 0
2528 if out_port != None:
2529 self.out_port = out_port
2530 else:
2531 self.out_port = 0
2532 if flags != None:
2533 self.flags = flags
2534 else:
2535 self.flags = 0
2536 if actions != None:
2537 self.actions = actions
2538 else:
2539 self.actions = []
2540
2541 def pack(self):
2542 packed = []
2543 packed.append(struct.pack("!B", self.version))
2544 packed.append(struct.pack("!B", self.type))
2545 packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
2546 packed.append(struct.pack("!L", self.xid))
2547 packed.append(self.match.pack())
2548 packed.append(struct.pack("!Q", self.cookie))
2549 packed.append(struct.pack("!H", self._command))
2550 packed.append(struct.pack("!H", self.idle_timeout))
2551 packed.append(struct.pack("!H", self.hard_timeout))
2552 packed.append(struct.pack("!H", self.priority))
2553 packed.append(struct.pack("!L", self.buffer_id))
2554 packed.append(struct.pack("!H", self.out_port))
2555 packed.append(struct.pack("!H", self.flags))
2556 packed.append("".join([x.pack() for x in self.actions]))
2557 length = sum([len(x) for x in packed])
2558 packed[2] = struct.pack("!H", length)
2559 return ''.join(packed)
2560
2561 @staticmethod
2562 def unpack(buf):
2563 if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
2564 obj = flow_add()
Rich Lanec2ee4b82013-04-24 17:12:38 -07002565 if type(buf) == loxi.generic_util.OFReader:
2566 reader = buf
2567 else:
2568 reader = loxi.generic_util.OFReader(buf)
2569 _version = reader.read('!B')[0]
2570 assert(_version == const.OFP_VERSION)
2571 _type = reader.read('!B')[0]
2572 assert(_type == const.OFPT_FLOW_MOD)
2573 _length = reader.read('!H')[0]
2574 obj.xid = reader.read('!L')[0]
2575 obj.match = common.match.unpack(reader)
2576 obj.cookie = reader.read('!Q')[0]
2577 __command = reader.read('!H')[0]
2578 assert(__command == const.OFPFC_ADD)
2579 obj.idle_timeout = reader.read('!H')[0]
2580 obj.hard_timeout = reader.read('!H')[0]
2581 obj.priority = reader.read('!H')[0]
2582 obj.buffer_id = reader.read('!L')[0]
2583 obj.out_port = reader.read('!H')[0]
2584 obj.flags = reader.read('!H')[0]
2585 obj.actions = action.unpack_list(reader)
Rich Laneb658ddd2013-03-12 10:15:10 -07002586 return obj
2587
2588 def __eq__(self, other):
2589 if type(self) != type(other): return False
2590 if self.version != other.version: return False
2591 if self.type != other.type: return False
2592 if self.xid != other.xid: return False
2593 if self.match != other.match: return False
2594 if self.cookie != other.cookie: return False
2595 if self.idle_timeout != other.idle_timeout: return False
2596 if self.hard_timeout != other.hard_timeout: return False
2597 if self.priority != other.priority: return False
2598 if self.buffer_id != other.buffer_id: return False
2599 if self.out_port != other.out_port: return False
2600 if self.flags != other.flags: return False
2601 if self.actions != other.actions: return False
2602 return True
2603
2604 def __ne__(self, other):
2605 return not self.__eq__(other)
2606
2607 def __str__(self):
2608 return self.show()
2609
2610 def show(self):
2611 import loxi.pp
2612 return loxi.pp.pp(self)
2613
2614 def pretty_print(self, q):
2615 q.text("flow_add {")
2616 with q.group():
2617 with q.indent(2):
2618 q.breakable()
2619 q.text("xid = ");
2620 if self.xid != None:
2621 q.text("%#x" % self.xid)
2622 else:
2623 q.text('None')
2624 q.text(","); q.breakable()
2625 q.text("match = ");
2626 q.pp(self.match)
2627 q.text(","); q.breakable()
2628 q.text("cookie = ");
2629 q.text("%#x" % self.cookie)
2630 q.text(","); q.breakable()
2631 q.text("idle_timeout = ");
2632 q.text("%#x" % self.idle_timeout)
2633 q.text(","); q.breakable()
2634 q.text("hard_timeout = ");
2635 q.text("%#x" % self.hard_timeout)
2636 q.text(","); q.breakable()
2637 q.text("priority = ");
2638 q.text("%#x" % self.priority)
2639 q.text(","); q.breakable()
2640 q.text("buffer_id = ");
2641 q.text("%#x" % self.buffer_id)
2642 q.text(","); q.breakable()
2643 q.text("out_port = ");
2644 q.text(util.pretty_port(self.out_port))
2645 q.text(","); q.breakable()
2646 q.text("flags = ");
2647 q.text("%#x" % self.flags)
2648 q.text(","); q.breakable()
2649 q.text("actions = ");
2650 q.pp(self.actions)
2651 q.breakable()
2652 q.text('}')
2653
2654class flow_delete(Message):
2655 version = const.OFP_VERSION
2656 type = const.OFPT_FLOW_MOD
2657 _command = const.OFPFC_DELETE
2658
2659 def __init__(self, xid=None, match=None, cookie=None, idle_timeout=None, hard_timeout=None, priority=None, buffer_id=None, out_port=None, flags=None, actions=None):
2660 self.xid = xid
2661 if match != None:
2662 self.match = match
2663 else:
2664 self.match = common.match()
2665 if cookie != None:
2666 self.cookie = cookie
2667 else:
2668 self.cookie = 0
2669 if idle_timeout != None:
2670 self.idle_timeout = idle_timeout
2671 else:
2672 self.idle_timeout = 0
2673 if hard_timeout != None:
2674 self.hard_timeout = hard_timeout
2675 else:
2676 self.hard_timeout = 0
2677 if priority != None:
2678 self.priority = priority
2679 else:
2680 self.priority = 0
2681 if buffer_id != None:
2682 self.buffer_id = buffer_id
2683 else:
2684 self.buffer_id = 0
2685 if out_port != None:
2686 self.out_port = out_port
2687 else:
2688 self.out_port = 0
2689 if flags != None:
2690 self.flags = flags
2691 else:
2692 self.flags = 0
2693 if actions != None:
2694 self.actions = actions
2695 else:
2696 self.actions = []
2697
2698 def pack(self):
2699 packed = []
2700 packed.append(struct.pack("!B", self.version))
2701 packed.append(struct.pack("!B", self.type))
2702 packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
2703 packed.append(struct.pack("!L", self.xid))
2704 packed.append(self.match.pack())
2705 packed.append(struct.pack("!Q", self.cookie))
2706 packed.append(struct.pack("!H", self._command))
2707 packed.append(struct.pack("!H", self.idle_timeout))
2708 packed.append(struct.pack("!H", self.hard_timeout))
2709 packed.append(struct.pack("!H", self.priority))
2710 packed.append(struct.pack("!L", self.buffer_id))
2711 packed.append(struct.pack("!H", self.out_port))
2712 packed.append(struct.pack("!H", self.flags))
2713 packed.append("".join([x.pack() for x in self.actions]))
2714 length = sum([len(x) for x in packed])
2715 packed[2] = struct.pack("!H", length)
2716 return ''.join(packed)
2717
2718 @staticmethod
2719 def unpack(buf):
2720 if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
2721 obj = flow_delete()
Rich Lanec2ee4b82013-04-24 17:12:38 -07002722 if type(buf) == loxi.generic_util.OFReader:
2723 reader = buf
2724 else:
2725 reader = loxi.generic_util.OFReader(buf)
2726 _version = reader.read('!B')[0]
2727 assert(_version == const.OFP_VERSION)
2728 _type = reader.read('!B')[0]
2729 assert(_type == const.OFPT_FLOW_MOD)
2730 _length = reader.read('!H')[0]
2731 obj.xid = reader.read('!L')[0]
2732 obj.match = common.match.unpack(reader)
2733 obj.cookie = reader.read('!Q')[0]
2734 __command = reader.read('!H')[0]
2735 assert(__command == const.OFPFC_DELETE)
2736 obj.idle_timeout = reader.read('!H')[0]
2737 obj.hard_timeout = reader.read('!H')[0]
2738 obj.priority = reader.read('!H')[0]
2739 obj.buffer_id = reader.read('!L')[0]
2740 obj.out_port = reader.read('!H')[0]
2741 obj.flags = reader.read('!H')[0]
2742 obj.actions = action.unpack_list(reader)
Rich Laneb658ddd2013-03-12 10:15:10 -07002743 return obj
2744
2745 def __eq__(self, other):
2746 if type(self) != type(other): return False
2747 if self.version != other.version: return False
2748 if self.type != other.type: return False
2749 if self.xid != other.xid: return False
2750 if self.match != other.match: return False
2751 if self.cookie != other.cookie: return False
2752 if self.idle_timeout != other.idle_timeout: return False
2753 if self.hard_timeout != other.hard_timeout: return False
2754 if self.priority != other.priority: return False
2755 if self.buffer_id != other.buffer_id: return False
2756 if self.out_port != other.out_port: return False
2757 if self.flags != other.flags: return False
2758 if self.actions != other.actions: return False
2759 return True
2760
2761 def __ne__(self, other):
2762 return not self.__eq__(other)
2763
2764 def __str__(self):
2765 return self.show()
2766
2767 def show(self):
2768 import loxi.pp
2769 return loxi.pp.pp(self)
2770
2771 def pretty_print(self, q):
2772 q.text("flow_delete {")
2773 with q.group():
2774 with q.indent(2):
2775 q.breakable()
2776 q.text("xid = ");
2777 if self.xid != None:
2778 q.text("%#x" % self.xid)
2779 else:
2780 q.text('None')
2781 q.text(","); q.breakable()
2782 q.text("match = ");
2783 q.pp(self.match)
2784 q.text(","); q.breakable()
2785 q.text("cookie = ");
2786 q.text("%#x" % self.cookie)
2787 q.text(","); q.breakable()
2788 q.text("idle_timeout = ");
2789 q.text("%#x" % self.idle_timeout)
2790 q.text(","); q.breakable()
2791 q.text("hard_timeout = ");
2792 q.text("%#x" % self.hard_timeout)
2793 q.text(","); q.breakable()
2794 q.text("priority = ");
2795 q.text("%#x" % self.priority)
2796 q.text(","); q.breakable()
2797 q.text("buffer_id = ");
2798 q.text("%#x" % self.buffer_id)
2799 q.text(","); q.breakable()
2800 q.text("out_port = ");
2801 q.text(util.pretty_port(self.out_port))
2802 q.text(","); q.breakable()
2803 q.text("flags = ");
2804 q.text("%#x" % self.flags)
2805 q.text(","); q.breakable()
2806 q.text("actions = ");
2807 q.pp(self.actions)
2808 q.breakable()
2809 q.text('}')
2810
2811class flow_delete_strict(Message):
2812 version = const.OFP_VERSION
2813 type = const.OFPT_FLOW_MOD
2814 _command = const.OFPFC_DELETE_STRICT
2815
2816 def __init__(self, xid=None, match=None, cookie=None, idle_timeout=None, hard_timeout=None, priority=None, buffer_id=None, out_port=None, flags=None, actions=None):
2817 self.xid = xid
2818 if match != None:
2819 self.match = match
2820 else:
2821 self.match = common.match()
2822 if cookie != None:
2823 self.cookie = cookie
2824 else:
2825 self.cookie = 0
2826 if idle_timeout != None:
2827 self.idle_timeout = idle_timeout
2828 else:
2829 self.idle_timeout = 0
2830 if hard_timeout != None:
2831 self.hard_timeout = hard_timeout
2832 else:
2833 self.hard_timeout = 0
2834 if priority != None:
2835 self.priority = priority
2836 else:
2837 self.priority = 0
2838 if buffer_id != None:
2839 self.buffer_id = buffer_id
2840 else:
2841 self.buffer_id = 0
2842 if out_port != None:
2843 self.out_port = out_port
2844 else:
2845 self.out_port = 0
2846 if flags != None:
2847 self.flags = flags
2848 else:
2849 self.flags = 0
2850 if actions != None:
2851 self.actions = actions
2852 else:
2853 self.actions = []
2854
2855 def pack(self):
2856 packed = []
2857 packed.append(struct.pack("!B", self.version))
2858 packed.append(struct.pack("!B", self.type))
2859 packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
2860 packed.append(struct.pack("!L", self.xid))
2861 packed.append(self.match.pack())
2862 packed.append(struct.pack("!Q", self.cookie))
2863 packed.append(struct.pack("!H", self._command))
2864 packed.append(struct.pack("!H", self.idle_timeout))
2865 packed.append(struct.pack("!H", self.hard_timeout))
2866 packed.append(struct.pack("!H", self.priority))
2867 packed.append(struct.pack("!L", self.buffer_id))
2868 packed.append(struct.pack("!H", self.out_port))
2869 packed.append(struct.pack("!H", self.flags))
2870 packed.append("".join([x.pack() for x in self.actions]))
2871 length = sum([len(x) for x in packed])
2872 packed[2] = struct.pack("!H", length)
2873 return ''.join(packed)
2874
2875 @staticmethod
2876 def unpack(buf):
2877 if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
2878 obj = flow_delete_strict()
Rich Lanec2ee4b82013-04-24 17:12:38 -07002879 if type(buf) == loxi.generic_util.OFReader:
2880 reader = buf
2881 else:
2882 reader = loxi.generic_util.OFReader(buf)
2883 _version = reader.read('!B')[0]
2884 assert(_version == const.OFP_VERSION)
2885 _type = reader.read('!B')[0]
2886 assert(_type == const.OFPT_FLOW_MOD)
2887 _length = reader.read('!H')[0]
2888 obj.xid = reader.read('!L')[0]
2889 obj.match = common.match.unpack(reader)
2890 obj.cookie = reader.read('!Q')[0]
2891 __command = reader.read('!H')[0]
2892 assert(__command == const.OFPFC_DELETE_STRICT)
2893 obj.idle_timeout = reader.read('!H')[0]
2894 obj.hard_timeout = reader.read('!H')[0]
2895 obj.priority = reader.read('!H')[0]
2896 obj.buffer_id = reader.read('!L')[0]
2897 obj.out_port = reader.read('!H')[0]
2898 obj.flags = reader.read('!H')[0]
2899 obj.actions = action.unpack_list(reader)
Rich Laneb658ddd2013-03-12 10:15:10 -07002900 return obj
2901
2902 def __eq__(self, other):
2903 if type(self) != type(other): return False
2904 if self.version != other.version: return False
2905 if self.type != other.type: return False
2906 if self.xid != other.xid: return False
2907 if self.match != other.match: return False
2908 if self.cookie != other.cookie: return False
2909 if self.idle_timeout != other.idle_timeout: return False
2910 if self.hard_timeout != other.hard_timeout: return False
2911 if self.priority != other.priority: return False
2912 if self.buffer_id != other.buffer_id: return False
2913 if self.out_port != other.out_port: return False
2914 if self.flags != other.flags: return False
2915 if self.actions != other.actions: return False
2916 return True
2917
2918 def __ne__(self, other):
2919 return not self.__eq__(other)
2920
2921 def __str__(self):
2922 return self.show()
2923
2924 def show(self):
2925 import loxi.pp
2926 return loxi.pp.pp(self)
2927
2928 def pretty_print(self, q):
2929 q.text("flow_delete_strict {")
2930 with q.group():
2931 with q.indent(2):
2932 q.breakable()
2933 q.text("xid = ");
2934 if self.xid != None:
2935 q.text("%#x" % self.xid)
2936 else:
2937 q.text('None')
2938 q.text(","); q.breakable()
2939 q.text("match = ");
2940 q.pp(self.match)
2941 q.text(","); q.breakable()
2942 q.text("cookie = ");
2943 q.text("%#x" % self.cookie)
2944 q.text(","); q.breakable()
2945 q.text("idle_timeout = ");
2946 q.text("%#x" % self.idle_timeout)
2947 q.text(","); q.breakable()
2948 q.text("hard_timeout = ");
2949 q.text("%#x" % self.hard_timeout)
2950 q.text(","); q.breakable()
2951 q.text("priority = ");
2952 q.text("%#x" % self.priority)
2953 q.text(","); q.breakable()
2954 q.text("buffer_id = ");
2955 q.text("%#x" % self.buffer_id)
2956 q.text(","); q.breakable()
2957 q.text("out_port = ");
2958 q.text(util.pretty_port(self.out_port))
2959 q.text(","); q.breakable()
2960 q.text("flags = ");
2961 q.text("%#x" % self.flags)
2962 q.text(","); q.breakable()
2963 q.text("actions = ");
2964 q.pp(self.actions)
2965 q.breakable()
2966 q.text('}')
2967
2968class flow_modify(Message):
2969 version = const.OFP_VERSION
2970 type = const.OFPT_FLOW_MOD
2971 _command = const.OFPFC_MODIFY
2972
2973 def __init__(self, xid=None, match=None, cookie=None, idle_timeout=None, hard_timeout=None, priority=None, buffer_id=None, out_port=None, flags=None, actions=None):
2974 self.xid = xid
2975 if match != None:
2976 self.match = match
2977 else:
2978 self.match = common.match()
2979 if cookie != None:
2980 self.cookie = cookie
2981 else:
2982 self.cookie = 0
2983 if idle_timeout != None:
2984 self.idle_timeout = idle_timeout
2985 else:
2986 self.idle_timeout = 0
2987 if hard_timeout != None:
2988 self.hard_timeout = hard_timeout
2989 else:
2990 self.hard_timeout = 0
2991 if priority != None:
2992 self.priority = priority
2993 else:
2994 self.priority = 0
2995 if buffer_id != None:
2996 self.buffer_id = buffer_id
2997 else:
2998 self.buffer_id = 0
2999 if out_port != None:
3000 self.out_port = out_port
3001 else:
3002 self.out_port = 0
3003 if flags != None:
3004 self.flags = flags
3005 else:
3006 self.flags = 0
3007 if actions != None:
3008 self.actions = actions
3009 else:
3010 self.actions = []
3011
3012 def pack(self):
3013 packed = []
3014 packed.append(struct.pack("!B", self.version))
3015 packed.append(struct.pack("!B", self.type))
3016 packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
3017 packed.append(struct.pack("!L", self.xid))
3018 packed.append(self.match.pack())
3019 packed.append(struct.pack("!Q", self.cookie))
3020 packed.append(struct.pack("!H", self._command))
3021 packed.append(struct.pack("!H", self.idle_timeout))
3022 packed.append(struct.pack("!H", self.hard_timeout))
3023 packed.append(struct.pack("!H", self.priority))
3024 packed.append(struct.pack("!L", self.buffer_id))
3025 packed.append(struct.pack("!H", self.out_port))
3026 packed.append(struct.pack("!H", self.flags))
3027 packed.append("".join([x.pack() for x in self.actions]))
3028 length = sum([len(x) for x in packed])
3029 packed[2] = struct.pack("!H", length)
3030 return ''.join(packed)
3031
3032 @staticmethod
3033 def unpack(buf):
3034 if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
3035 obj = flow_modify()
Rich Lanec2ee4b82013-04-24 17:12:38 -07003036 if type(buf) == loxi.generic_util.OFReader:
3037 reader = buf
3038 else:
3039 reader = loxi.generic_util.OFReader(buf)
3040 _version = reader.read('!B')[0]
3041 assert(_version == const.OFP_VERSION)
3042 _type = reader.read('!B')[0]
3043 assert(_type == const.OFPT_FLOW_MOD)
3044 _length = reader.read('!H')[0]
3045 obj.xid = reader.read('!L')[0]
3046 obj.match = common.match.unpack(reader)
3047 obj.cookie = reader.read('!Q')[0]
3048 __command = reader.read('!H')[0]
3049 assert(__command == const.OFPFC_MODIFY)
3050 obj.idle_timeout = reader.read('!H')[0]
3051 obj.hard_timeout = reader.read('!H')[0]
3052 obj.priority = reader.read('!H')[0]
3053 obj.buffer_id = reader.read('!L')[0]
3054 obj.out_port = reader.read('!H')[0]
3055 obj.flags = reader.read('!H')[0]
3056 obj.actions = action.unpack_list(reader)
Rich Laneb658ddd2013-03-12 10:15:10 -07003057 return obj
3058
3059 def __eq__(self, other):
3060 if type(self) != type(other): return False
3061 if self.version != other.version: return False
3062 if self.type != other.type: return False
3063 if self.xid != other.xid: return False
3064 if self.match != other.match: return False
3065 if self.cookie != other.cookie: return False
3066 if self.idle_timeout != other.idle_timeout: return False
3067 if self.hard_timeout != other.hard_timeout: return False
3068 if self.priority != other.priority: return False
3069 if self.buffer_id != other.buffer_id: return False
3070 if self.out_port != other.out_port: return False
3071 if self.flags != other.flags: return False
3072 if self.actions != other.actions: return False
3073 return True
3074
3075 def __ne__(self, other):
3076 return not self.__eq__(other)
3077
3078 def __str__(self):
3079 return self.show()
3080
3081 def show(self):
3082 import loxi.pp
3083 return loxi.pp.pp(self)
3084
3085 def pretty_print(self, q):
3086 q.text("flow_modify {")
3087 with q.group():
3088 with q.indent(2):
3089 q.breakable()
3090 q.text("xid = ");
3091 if self.xid != None:
3092 q.text("%#x" % self.xid)
3093 else:
3094 q.text('None')
3095 q.text(","); q.breakable()
3096 q.text("match = ");
3097 q.pp(self.match)
3098 q.text(","); q.breakable()
3099 q.text("cookie = ");
3100 q.text("%#x" % self.cookie)
3101 q.text(","); q.breakable()
3102 q.text("idle_timeout = ");
3103 q.text("%#x" % self.idle_timeout)
3104 q.text(","); q.breakable()
3105 q.text("hard_timeout = ");
3106 q.text("%#x" % self.hard_timeout)
3107 q.text(","); q.breakable()
3108 q.text("priority = ");
3109 q.text("%#x" % self.priority)
3110 q.text(","); q.breakable()
3111 q.text("buffer_id = ");
3112 q.text("%#x" % self.buffer_id)
3113 q.text(","); q.breakable()
3114 q.text("out_port = ");
3115 q.text(util.pretty_port(self.out_port))
3116 q.text(","); q.breakable()
3117 q.text("flags = ");
3118 q.text("%#x" % self.flags)
3119 q.text(","); q.breakable()
3120 q.text("actions = ");
3121 q.pp(self.actions)
3122 q.breakable()
3123 q.text('}')
3124
3125class flow_modify_strict(Message):
3126 version = const.OFP_VERSION
3127 type = const.OFPT_FLOW_MOD
3128 _command = const.OFPFC_MODIFY_STRICT
3129
3130 def __init__(self, xid=None, match=None, cookie=None, idle_timeout=None, hard_timeout=None, priority=None, buffer_id=None, out_port=None, flags=None, actions=None):
3131 self.xid = xid
3132 if match != None:
3133 self.match = match
3134 else:
3135 self.match = common.match()
3136 if cookie != None:
3137 self.cookie = cookie
3138 else:
3139 self.cookie = 0
3140 if idle_timeout != None:
3141 self.idle_timeout = idle_timeout
3142 else:
3143 self.idle_timeout = 0
3144 if hard_timeout != None:
3145 self.hard_timeout = hard_timeout
3146 else:
3147 self.hard_timeout = 0
3148 if priority != None:
3149 self.priority = priority
3150 else:
3151 self.priority = 0
3152 if buffer_id != None:
3153 self.buffer_id = buffer_id
3154 else:
3155 self.buffer_id = 0
3156 if out_port != None:
3157 self.out_port = out_port
3158 else:
3159 self.out_port = 0
3160 if flags != None:
3161 self.flags = flags
3162 else:
3163 self.flags = 0
3164 if actions != None:
3165 self.actions = actions
3166 else:
3167 self.actions = []
3168
3169 def pack(self):
3170 packed = []
3171 packed.append(struct.pack("!B", self.version))
3172 packed.append(struct.pack("!B", self.type))
3173 packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
3174 packed.append(struct.pack("!L", self.xid))
3175 packed.append(self.match.pack())
3176 packed.append(struct.pack("!Q", self.cookie))
3177 packed.append(struct.pack("!H", self._command))
3178 packed.append(struct.pack("!H", self.idle_timeout))
3179 packed.append(struct.pack("!H", self.hard_timeout))
3180 packed.append(struct.pack("!H", self.priority))
3181 packed.append(struct.pack("!L", self.buffer_id))
3182 packed.append(struct.pack("!H", self.out_port))
3183 packed.append(struct.pack("!H", self.flags))
3184 packed.append("".join([x.pack() for x in self.actions]))
3185 length = sum([len(x) for x in packed])
3186 packed[2] = struct.pack("!H", length)
3187 return ''.join(packed)
3188
3189 @staticmethod
3190 def unpack(buf):
3191 if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
3192 obj = flow_modify_strict()
Rich Lanec2ee4b82013-04-24 17:12:38 -07003193 if type(buf) == loxi.generic_util.OFReader:
3194 reader = buf
3195 else:
3196 reader = loxi.generic_util.OFReader(buf)
3197 _version = reader.read('!B')[0]
3198 assert(_version == const.OFP_VERSION)
3199 _type = reader.read('!B')[0]
3200 assert(_type == const.OFPT_FLOW_MOD)
3201 _length = reader.read('!H')[0]
3202 obj.xid = reader.read('!L')[0]
3203 obj.match = common.match.unpack(reader)
3204 obj.cookie = reader.read('!Q')[0]
3205 __command = reader.read('!H')[0]
3206 assert(__command == const.OFPFC_MODIFY_STRICT)
3207 obj.idle_timeout = reader.read('!H')[0]
3208 obj.hard_timeout = reader.read('!H')[0]
3209 obj.priority = reader.read('!H')[0]
3210 obj.buffer_id = reader.read('!L')[0]
3211 obj.out_port = reader.read('!H')[0]
3212 obj.flags = reader.read('!H')[0]
3213 obj.actions = action.unpack_list(reader)
Rich Laneb658ddd2013-03-12 10:15:10 -07003214 return obj
3215
3216 def __eq__(self, other):
3217 if type(self) != type(other): return False
3218 if self.version != other.version: return False
3219 if self.type != other.type: return False
3220 if self.xid != other.xid: return False
3221 if self.match != other.match: return False
3222 if self.cookie != other.cookie: return False
3223 if self.idle_timeout != other.idle_timeout: return False
3224 if self.hard_timeout != other.hard_timeout: return False
3225 if self.priority != other.priority: return False
3226 if self.buffer_id != other.buffer_id: return False
3227 if self.out_port != other.out_port: return False
3228 if self.flags != other.flags: return False
3229 if self.actions != other.actions: return False
3230 return True
3231
3232 def __ne__(self, other):
3233 return not self.__eq__(other)
3234
3235 def __str__(self):
3236 return self.show()
3237
3238 def show(self):
3239 import loxi.pp
3240 return loxi.pp.pp(self)
3241
3242 def pretty_print(self, q):
3243 q.text("flow_modify_strict {")
3244 with q.group():
3245 with q.indent(2):
3246 q.breakable()
3247 q.text("xid = ");
3248 if self.xid != None:
3249 q.text("%#x" % self.xid)
3250 else:
3251 q.text('None')
3252 q.text(","); q.breakable()
3253 q.text("match = ");
3254 q.pp(self.match)
3255 q.text(","); q.breakable()
3256 q.text("cookie = ");
3257 q.text("%#x" % self.cookie)
3258 q.text(","); q.breakable()
3259 q.text("idle_timeout = ");
3260 q.text("%#x" % self.idle_timeout)
3261 q.text(","); q.breakable()
3262 q.text("hard_timeout = ");
3263 q.text("%#x" % self.hard_timeout)
3264 q.text(","); q.breakable()
3265 q.text("priority = ");
3266 q.text("%#x" % self.priority)
3267 q.text(","); q.breakable()
3268 q.text("buffer_id = ");
3269 q.text("%#x" % self.buffer_id)
3270 q.text(","); q.breakable()
3271 q.text("out_port = ");
3272 q.text(util.pretty_port(self.out_port))
3273 q.text(","); q.breakable()
3274 q.text("flags = ");
3275 q.text("%#x" % self.flags)
3276 q.text(","); q.breakable()
3277 q.text("actions = ");
3278 q.pp(self.actions)
3279 q.breakable()
3280 q.text('}')
3281
3282class flow_removed(Message):
3283 version = const.OFP_VERSION
3284 type = const.OFPT_FLOW_REMOVED
3285
Rich Lanec2ee4b82013-04-24 17:12:38 -07003286 def __init__(self, xid=None, match=None, cookie=None, priority=None, reason=None, duration_sec=None, duration_nsec=None, idle_timeout=None, packet_count=None, byte_count=None):
Rich Laneb658ddd2013-03-12 10:15:10 -07003287 self.xid = xid
3288 if match != None:
3289 self.match = match
3290 else:
3291 self.match = common.match()
3292 if cookie != None:
3293 self.cookie = cookie
3294 else:
3295 self.cookie = 0
3296 if priority != None:
3297 self.priority = priority
3298 else:
3299 self.priority = 0
3300 if reason != None:
3301 self.reason = reason
3302 else:
3303 self.reason = 0
Rich Laneb658ddd2013-03-12 10:15:10 -07003304 if duration_sec != None:
3305 self.duration_sec = duration_sec
3306 else:
3307 self.duration_sec = 0
3308 if duration_nsec != None:
3309 self.duration_nsec = duration_nsec
3310 else:
3311 self.duration_nsec = 0
3312 if idle_timeout != None:
3313 self.idle_timeout = idle_timeout
3314 else:
3315 self.idle_timeout = 0
Rich Laneb658ddd2013-03-12 10:15:10 -07003316 if packet_count != None:
3317 self.packet_count = packet_count
3318 else:
3319 self.packet_count = 0
3320 if byte_count != None:
3321 self.byte_count = byte_count
3322 else:
3323 self.byte_count = 0
3324
3325 def pack(self):
3326 packed = []
3327 packed.append(struct.pack("!B", self.version))
3328 packed.append(struct.pack("!B", self.type))
3329 packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
3330 packed.append(struct.pack("!L", self.xid))
3331 packed.append(self.match.pack())
3332 packed.append(struct.pack("!Q", self.cookie))
3333 packed.append(struct.pack("!H", self.priority))
3334 packed.append(struct.pack("!B", self.reason))
Rich Lanec2ee4b82013-04-24 17:12:38 -07003335 packed.append('\x00' * 1)
Rich Laneb658ddd2013-03-12 10:15:10 -07003336 packed.append(struct.pack("!L", self.duration_sec))
3337 packed.append(struct.pack("!L", self.duration_nsec))
3338 packed.append(struct.pack("!H", self.idle_timeout))
Rich Lanec2ee4b82013-04-24 17:12:38 -07003339 packed.append('\x00' * 2)
Rich Laneb658ddd2013-03-12 10:15:10 -07003340 packed.append(struct.pack("!Q", self.packet_count))
3341 packed.append(struct.pack("!Q", self.byte_count))
3342 length = sum([len(x) for x in packed])
3343 packed[2] = struct.pack("!H", length)
3344 return ''.join(packed)
3345
3346 @staticmethod
3347 def unpack(buf):
3348 if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
3349 obj = flow_removed()
Rich Lanec2ee4b82013-04-24 17:12:38 -07003350 if type(buf) == loxi.generic_util.OFReader:
3351 reader = buf
3352 else:
3353 reader = loxi.generic_util.OFReader(buf)
3354 _version = reader.read('!B')[0]
3355 assert(_version == const.OFP_VERSION)
3356 _type = reader.read('!B')[0]
3357 assert(_type == const.OFPT_FLOW_REMOVED)
3358 _length = reader.read('!H')[0]
3359 obj.xid = reader.read('!L')[0]
3360 obj.match = common.match.unpack(reader)
3361 obj.cookie = reader.read('!Q')[0]
3362 obj.priority = reader.read('!H')[0]
3363 obj.reason = reader.read('!B')[0]
3364 reader.skip(1)
3365 obj.duration_sec = reader.read('!L')[0]
3366 obj.duration_nsec = reader.read('!L')[0]
3367 obj.idle_timeout = reader.read('!H')[0]
3368 reader.skip(2)
3369 obj.packet_count = reader.read('!Q')[0]
3370 obj.byte_count = reader.read('!Q')[0]
Rich Laneb658ddd2013-03-12 10:15:10 -07003371 return obj
3372
3373 def __eq__(self, other):
3374 if type(self) != type(other): return False
3375 if self.version != other.version: return False
3376 if self.type != other.type: return False
3377 if self.xid != other.xid: return False
3378 if self.match != other.match: return False
3379 if self.cookie != other.cookie: return False
3380 if self.priority != other.priority: return False
3381 if self.reason != other.reason: return False
Rich Laneb658ddd2013-03-12 10:15:10 -07003382 if self.duration_sec != other.duration_sec: return False
3383 if self.duration_nsec != other.duration_nsec: return False
3384 if self.idle_timeout != other.idle_timeout: return False
Rich Laneb658ddd2013-03-12 10:15:10 -07003385 if self.packet_count != other.packet_count: return False
3386 if self.byte_count != other.byte_count: return False
3387 return True
3388
3389 def __ne__(self, other):
3390 return not self.__eq__(other)
3391
3392 def __str__(self):
3393 return self.show()
3394
3395 def show(self):
3396 import loxi.pp
3397 return loxi.pp.pp(self)
3398
3399 def pretty_print(self, q):
3400 q.text("flow_removed {")
3401 with q.group():
3402 with q.indent(2):
3403 q.breakable()
3404 q.text("xid = ");
3405 if self.xid != None:
3406 q.text("%#x" % self.xid)
3407 else:
3408 q.text('None')
3409 q.text(","); q.breakable()
3410 q.text("match = ");
3411 q.pp(self.match)
3412 q.text(","); q.breakable()
3413 q.text("cookie = ");
3414 q.text("%#x" % self.cookie)
3415 q.text(","); q.breakable()
3416 q.text("priority = ");
3417 q.text("%#x" % self.priority)
3418 q.text(","); q.breakable()
3419 q.text("reason = ");
3420 q.text("%#x" % self.reason)
3421 q.text(","); q.breakable()
Rich Laneb658ddd2013-03-12 10:15:10 -07003422 q.text("duration_sec = ");
3423 q.text("%#x" % self.duration_sec)
3424 q.text(","); q.breakable()
3425 q.text("duration_nsec = ");
3426 q.text("%#x" % self.duration_nsec)
3427 q.text(","); q.breakable()
3428 q.text("idle_timeout = ");
3429 q.text("%#x" % self.idle_timeout)
3430 q.text(","); q.breakable()
Rich Laneb658ddd2013-03-12 10:15:10 -07003431 q.text("packet_count = ");
3432 q.text("%#x" % self.packet_count)
3433 q.text(","); q.breakable()
3434 q.text("byte_count = ");
3435 q.text("%#x" % self.byte_count)
3436 q.breakable()
3437 q.text('}')
3438
3439class flow_stats_reply(Message):
3440 version = const.OFP_VERSION
3441 type = const.OFPT_STATS_REPLY
3442 stats_type = const.OFPST_FLOW
3443
3444 def __init__(self, xid=None, flags=None, entries=None):
3445 self.xid = xid
3446 if flags != None:
3447 self.flags = flags
3448 else:
3449 self.flags = 0
3450 if entries != None:
3451 self.entries = entries
3452 else:
3453 self.entries = []
3454
3455 def pack(self):
3456 packed = []
3457 packed.append(struct.pack("!B", self.version))
3458 packed.append(struct.pack("!B", self.type))
3459 packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
3460 packed.append(struct.pack("!L", self.xid))
3461 packed.append(struct.pack("!H", self.stats_type))
3462 packed.append(struct.pack("!H", self.flags))
3463 packed.append("".join([x.pack() for x in self.entries]))
3464 length = sum([len(x) for x in packed])
3465 packed[2] = struct.pack("!H", length)
3466 return ''.join(packed)
3467
3468 @staticmethod
3469 def unpack(buf):
3470 if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
3471 obj = flow_stats_reply()
Rich Lanec2ee4b82013-04-24 17:12:38 -07003472 if type(buf) == loxi.generic_util.OFReader:
3473 reader = buf
3474 else:
3475 reader = loxi.generic_util.OFReader(buf)
3476 _version = reader.read('!B')[0]
3477 assert(_version == const.OFP_VERSION)
3478 _type = reader.read('!B')[0]
3479 assert(_type == const.OFPT_STATS_REPLY)
3480 _length = reader.read('!H')[0]
3481 obj.xid = reader.read('!L')[0]
3482 _stats_type = reader.read('!H')[0]
3483 assert(_stats_type == const.OFPST_FLOW)
3484 obj.flags = reader.read('!H')[0]
3485 obj.entries = common.unpack_list_flow_stats_entry(reader)
Rich Laneb658ddd2013-03-12 10:15:10 -07003486 return obj
3487
3488 def __eq__(self, other):
3489 if type(self) != type(other): return False
3490 if self.version != other.version: return False
3491 if self.type != other.type: return False
3492 if self.xid != other.xid: return False
3493 if self.flags != other.flags: return False
3494 if self.entries != other.entries: return False
3495 return True
3496
3497 def __ne__(self, other):
3498 return not self.__eq__(other)
3499
3500 def __str__(self):
3501 return self.show()
3502
3503 def show(self):
3504 import loxi.pp
3505 return loxi.pp.pp(self)
3506
3507 def pretty_print(self, q):
3508 q.text("flow_stats_reply {")
3509 with q.group():
3510 with q.indent(2):
3511 q.breakable()
3512 q.text("xid = ");
3513 if self.xid != None:
3514 q.text("%#x" % self.xid)
3515 else:
3516 q.text('None')
3517 q.text(","); q.breakable()
3518 q.text("flags = ");
3519 q.text("%#x" % self.flags)
3520 q.text(","); q.breakable()
3521 q.text("entries = ");
3522 q.pp(self.entries)
3523 q.breakable()
3524 q.text('}')
3525
3526class flow_stats_request(Message):
3527 version = const.OFP_VERSION
3528 type = const.OFPT_STATS_REQUEST
3529 stats_type = const.OFPST_FLOW
3530
Rich Lanec2ee4b82013-04-24 17:12:38 -07003531 def __init__(self, xid=None, flags=None, match=None, table_id=None, out_port=None):
Rich Laneb658ddd2013-03-12 10:15:10 -07003532 self.xid = xid
3533 if flags != None:
3534 self.flags = flags
3535 else:
3536 self.flags = 0
3537 if match != None:
3538 self.match = match
3539 else:
3540 self.match = common.match()
3541 if table_id != None:
3542 self.table_id = table_id
3543 else:
3544 self.table_id = 0
Rich Laneb658ddd2013-03-12 10:15:10 -07003545 if out_port != None:
3546 self.out_port = out_port
3547 else:
3548 self.out_port = 0
3549
3550 def pack(self):
3551 packed = []
3552 packed.append(struct.pack("!B", self.version))
3553 packed.append(struct.pack("!B", self.type))
3554 packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
3555 packed.append(struct.pack("!L", self.xid))
3556 packed.append(struct.pack("!H", self.stats_type))
3557 packed.append(struct.pack("!H", self.flags))
3558 packed.append(self.match.pack())
3559 packed.append(struct.pack("!B", self.table_id))
Rich Lanec2ee4b82013-04-24 17:12:38 -07003560 packed.append('\x00' * 1)
Rich Laneb658ddd2013-03-12 10:15:10 -07003561 packed.append(struct.pack("!H", self.out_port))
3562 length = sum([len(x) for x in packed])
3563 packed[2] = struct.pack("!H", length)
3564 return ''.join(packed)
3565
3566 @staticmethod
3567 def unpack(buf):
3568 if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
3569 obj = flow_stats_request()
Rich Lanec2ee4b82013-04-24 17:12:38 -07003570 if type(buf) == loxi.generic_util.OFReader:
3571 reader = buf
3572 else:
3573 reader = loxi.generic_util.OFReader(buf)
3574 _version = reader.read('!B')[0]
3575 assert(_version == const.OFP_VERSION)
3576 _type = reader.read('!B')[0]
3577 assert(_type == const.OFPT_STATS_REQUEST)
3578 _length = reader.read('!H')[0]
3579 obj.xid = reader.read('!L')[0]
3580 _stats_type = reader.read('!H')[0]
3581 assert(_stats_type == const.OFPST_FLOW)
3582 obj.flags = reader.read('!H')[0]
3583 obj.match = common.match.unpack(reader)
3584 obj.table_id = reader.read('!B')[0]
3585 reader.skip(1)
3586 obj.out_port = reader.read('!H')[0]
Rich Laneb658ddd2013-03-12 10:15:10 -07003587 return obj
3588
3589 def __eq__(self, other):
3590 if type(self) != type(other): return False
3591 if self.version != other.version: return False
3592 if self.type != other.type: return False
3593 if self.xid != other.xid: return False
3594 if self.flags != other.flags: return False
3595 if self.match != other.match: return False
3596 if self.table_id != other.table_id: return False
Rich Laneb658ddd2013-03-12 10:15:10 -07003597 if self.out_port != other.out_port: return False
3598 return True
3599
3600 def __ne__(self, other):
3601 return not self.__eq__(other)
3602
3603 def __str__(self):
3604 return self.show()
3605
3606 def show(self):
3607 import loxi.pp
3608 return loxi.pp.pp(self)
3609
3610 def pretty_print(self, q):
3611 q.text("flow_stats_request {")
3612 with q.group():
3613 with q.indent(2):
3614 q.breakable()
3615 q.text("xid = ");
3616 if self.xid != None:
3617 q.text("%#x" % self.xid)
3618 else:
3619 q.text('None')
3620 q.text(","); q.breakable()
3621 q.text("flags = ");
3622 q.text("%#x" % self.flags)
3623 q.text(","); q.breakable()
3624 q.text("match = ");
3625 q.pp(self.match)
3626 q.text(","); q.breakable()
3627 q.text("table_id = ");
3628 q.text("%#x" % self.table_id)
3629 q.text(","); q.breakable()
Rich Laneb658ddd2013-03-12 10:15:10 -07003630 q.text("out_port = ");
3631 q.text(util.pretty_port(self.out_port))
3632 q.breakable()
3633 q.text('}')
3634
3635class get_config_reply(Message):
3636 version = const.OFP_VERSION
3637 type = const.OFPT_GET_CONFIG_REPLY
3638
3639 def __init__(self, xid=None, flags=None, miss_send_len=None):
3640 self.xid = xid
3641 if flags != None:
3642 self.flags = flags
3643 else:
3644 self.flags = 0
3645 if miss_send_len != None:
3646 self.miss_send_len = miss_send_len
3647 else:
3648 self.miss_send_len = 0
3649
3650 def pack(self):
3651 packed = []
3652 packed.append(struct.pack("!B", self.version))
3653 packed.append(struct.pack("!B", self.type))
3654 packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
3655 packed.append(struct.pack("!L", self.xid))
3656 packed.append(struct.pack("!H", self.flags))
3657 packed.append(struct.pack("!H", self.miss_send_len))
3658 length = sum([len(x) for x in packed])
3659 packed[2] = struct.pack("!H", length)
3660 return ''.join(packed)
3661
3662 @staticmethod
3663 def unpack(buf):
3664 if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
3665 obj = get_config_reply()
Rich Lanec2ee4b82013-04-24 17:12:38 -07003666 if type(buf) == loxi.generic_util.OFReader:
3667 reader = buf
3668 else:
3669 reader = loxi.generic_util.OFReader(buf)
3670 _version = reader.read('!B')[0]
3671 assert(_version == const.OFP_VERSION)
3672 _type = reader.read('!B')[0]
3673 assert(_type == const.OFPT_GET_CONFIG_REPLY)
3674 _length = reader.read('!H')[0]
3675 obj.xid = reader.read('!L')[0]
3676 obj.flags = reader.read('!H')[0]
3677 obj.miss_send_len = reader.read('!H')[0]
Rich Laneb658ddd2013-03-12 10:15:10 -07003678 return obj
3679
3680 def __eq__(self, other):
3681 if type(self) != type(other): return False
3682 if self.version != other.version: return False
3683 if self.type != other.type: return False
3684 if self.xid != other.xid: return False
3685 if self.flags != other.flags: return False
3686 if self.miss_send_len != other.miss_send_len: return False
3687 return True
3688
3689 def __ne__(self, other):
3690 return not self.__eq__(other)
3691
3692 def __str__(self):
3693 return self.show()
3694
3695 def show(self):
3696 import loxi.pp
3697 return loxi.pp.pp(self)
3698
3699 def pretty_print(self, q):
3700 q.text("get_config_reply {")
3701 with q.group():
3702 with q.indent(2):
3703 q.breakable()
3704 q.text("xid = ");
3705 if self.xid != None:
3706 q.text("%#x" % self.xid)
3707 else:
3708 q.text('None')
3709 q.text(","); q.breakable()
3710 q.text("flags = ");
3711 q.text("%#x" % self.flags)
3712 q.text(","); q.breakable()
3713 q.text("miss_send_len = ");
3714 q.text("%#x" % self.miss_send_len)
3715 q.breakable()
3716 q.text('}')
3717
3718class get_config_request(Message):
3719 version = const.OFP_VERSION
3720 type = const.OFPT_GET_CONFIG_REQUEST
3721
3722 def __init__(self, xid=None):
3723 self.xid = xid
3724
3725 def pack(self):
3726 packed = []
3727 packed.append(struct.pack("!B", self.version))
3728 packed.append(struct.pack("!B", self.type))
3729 packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
3730 packed.append(struct.pack("!L", self.xid))
3731 length = sum([len(x) for x in packed])
3732 packed[2] = struct.pack("!H", length)
3733 return ''.join(packed)
3734
3735 @staticmethod
3736 def unpack(buf):
3737 if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
3738 obj = get_config_request()
Rich Lanec2ee4b82013-04-24 17:12:38 -07003739 if type(buf) == loxi.generic_util.OFReader:
3740 reader = buf
3741 else:
3742 reader = loxi.generic_util.OFReader(buf)
3743 _version = reader.read('!B')[0]
3744 assert(_version == const.OFP_VERSION)
3745 _type = reader.read('!B')[0]
3746 assert(_type == const.OFPT_GET_CONFIG_REQUEST)
3747 _length = reader.read('!H')[0]
3748 obj.xid = reader.read('!L')[0]
Rich Laneb658ddd2013-03-12 10:15:10 -07003749 return obj
3750
3751 def __eq__(self, other):
3752 if type(self) != type(other): return False
3753 if self.version != other.version: return False
3754 if self.type != other.type: return False
3755 if self.xid != other.xid: return False
3756 return True
3757
3758 def __ne__(self, other):
3759 return not self.__eq__(other)
3760
3761 def __str__(self):
3762 return self.show()
3763
3764 def show(self):
3765 import loxi.pp
3766 return loxi.pp.pp(self)
3767
3768 def pretty_print(self, q):
3769 q.text("get_config_request {")
3770 with q.group():
3771 with q.indent(2):
3772 q.breakable()
3773 q.text("xid = ");
3774 if self.xid != None:
3775 q.text("%#x" % self.xid)
3776 else:
3777 q.text('None')
3778 q.breakable()
3779 q.text('}')
3780
3781class hello(Message):
3782 version = const.OFP_VERSION
3783 type = const.OFPT_HELLO
3784
3785 def __init__(self, xid=None):
3786 self.xid = xid
3787
3788 def pack(self):
3789 packed = []
3790 packed.append(struct.pack("!B", self.version))
3791 packed.append(struct.pack("!B", self.type))
3792 packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
3793 packed.append(struct.pack("!L", self.xid))
3794 length = sum([len(x) for x in packed])
3795 packed[2] = struct.pack("!H", length)
3796 return ''.join(packed)
3797
3798 @staticmethod
3799 def unpack(buf):
3800 if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
3801 obj = hello()
Rich Lanec2ee4b82013-04-24 17:12:38 -07003802 if type(buf) == loxi.generic_util.OFReader:
3803 reader = buf
3804 else:
3805 reader = loxi.generic_util.OFReader(buf)
3806 _version = reader.read('!B')[0]
3807 assert(_version == const.OFP_VERSION)
3808 _type = reader.read('!B')[0]
3809 assert(_type == const.OFPT_HELLO)
3810 _length = reader.read('!H')[0]
3811 obj.xid = reader.read('!L')[0]
Rich Laneb658ddd2013-03-12 10:15:10 -07003812 return obj
3813
3814 def __eq__(self, other):
3815 if type(self) != type(other): return False
3816 if self.version != other.version: return False
3817 if self.type != other.type: return False
3818 if self.xid != other.xid: return False
3819 return True
3820
3821 def __ne__(self, other):
3822 return not self.__eq__(other)
3823
3824 def __str__(self):
3825 return self.show()
3826
3827 def show(self):
3828 import loxi.pp
3829 return loxi.pp.pp(self)
3830
3831 def pretty_print(self, q):
3832 q.text("hello {")
3833 with q.group():
3834 with q.indent(2):
3835 q.breakable()
3836 q.text("xid = ");
3837 if self.xid != None:
3838 q.text("%#x" % self.xid)
3839 else:
3840 q.text('None')
3841 q.breakable()
3842 q.text('}')
3843
3844class nicira_controller_role_reply(Message):
3845 version = const.OFP_VERSION
3846 type = const.OFPT_VENDOR
3847 experimenter = 0x2320
3848 subtype = 11
3849
3850 def __init__(self, xid=None, role=None):
3851 self.xid = xid
3852 if role != None:
3853 self.role = role
3854 else:
3855 self.role = 0
3856
3857 def pack(self):
3858 packed = []
3859 packed.append(struct.pack("!B", self.version))
3860 packed.append(struct.pack("!B", self.type))
3861 packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
3862 packed.append(struct.pack("!L", self.xid))
3863 packed.append(struct.pack("!L", self.experimenter))
3864 packed.append(struct.pack("!L", self.subtype))
3865 packed.append(struct.pack("!L", self.role))
3866 length = sum([len(x) for x in packed])
3867 packed[2] = struct.pack("!H", length)
3868 return ''.join(packed)
3869
3870 @staticmethod
3871 def unpack(buf):
3872 if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
3873 obj = nicira_controller_role_reply()
Rich Lanec2ee4b82013-04-24 17:12:38 -07003874 if type(buf) == loxi.generic_util.OFReader:
3875 reader = buf
3876 else:
3877 reader = loxi.generic_util.OFReader(buf)
3878 _version = reader.read('!B')[0]
3879 assert(_version == const.OFP_VERSION)
3880 _type = reader.read('!B')[0]
3881 assert(_type == const.OFPT_VENDOR)
3882 _length = reader.read('!H')[0]
3883 obj.xid = reader.read('!L')[0]
3884 _experimenter = reader.read('!L')[0]
3885 assert(_experimenter == 0x2320)
3886 _subtype = reader.read('!L')[0]
3887 assert(_subtype == 11)
3888 obj.role = reader.read('!L')[0]
Rich Laneb658ddd2013-03-12 10:15:10 -07003889 return obj
3890
3891 def __eq__(self, other):
3892 if type(self) != type(other): return False
3893 if self.version != other.version: return False
3894 if self.type != other.type: return False
3895 if self.xid != other.xid: return False
3896 if self.role != other.role: return False
3897 return True
3898
3899 def __ne__(self, other):
3900 return not self.__eq__(other)
3901
3902 def __str__(self):
3903 return self.show()
3904
3905 def show(self):
3906 import loxi.pp
3907 return loxi.pp.pp(self)
3908
3909 def pretty_print(self, q):
3910 q.text("nicira_controller_role_reply {")
3911 with q.group():
3912 with q.indent(2):
3913 q.breakable()
3914 q.text("xid = ");
3915 if self.xid != None:
3916 q.text("%#x" % self.xid)
3917 else:
3918 q.text('None')
3919 q.text(","); q.breakable()
3920 q.text("role = ");
3921 q.text("%#x" % self.role)
3922 q.breakable()
3923 q.text('}')
3924
3925class nicira_controller_role_request(Message):
3926 version = const.OFP_VERSION
3927 type = const.OFPT_VENDOR
3928 experimenter = 0x2320
3929 subtype = 10
3930
3931 def __init__(self, xid=None, role=None):
3932 self.xid = xid
3933 if role != None:
3934 self.role = role
3935 else:
3936 self.role = 0
3937
3938 def pack(self):
3939 packed = []
3940 packed.append(struct.pack("!B", self.version))
3941 packed.append(struct.pack("!B", self.type))
3942 packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
3943 packed.append(struct.pack("!L", self.xid))
3944 packed.append(struct.pack("!L", self.experimenter))
3945 packed.append(struct.pack("!L", self.subtype))
3946 packed.append(struct.pack("!L", self.role))
3947 length = sum([len(x) for x in packed])
3948 packed[2] = struct.pack("!H", length)
3949 return ''.join(packed)
3950
3951 @staticmethod
3952 def unpack(buf):
3953 if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
3954 obj = nicira_controller_role_request()
Rich Lanec2ee4b82013-04-24 17:12:38 -07003955 if type(buf) == loxi.generic_util.OFReader:
3956 reader = buf
3957 else:
3958 reader = loxi.generic_util.OFReader(buf)
3959 _version = reader.read('!B')[0]
3960 assert(_version == const.OFP_VERSION)
3961 _type = reader.read('!B')[0]
3962 assert(_type == const.OFPT_VENDOR)
3963 _length = reader.read('!H')[0]
3964 obj.xid = reader.read('!L')[0]
3965 _experimenter = reader.read('!L')[0]
3966 assert(_experimenter == 0x2320)
3967 _subtype = reader.read('!L')[0]
3968 assert(_subtype == 10)
3969 obj.role = reader.read('!L')[0]
Rich Laneb658ddd2013-03-12 10:15:10 -07003970 return obj
3971
3972 def __eq__(self, other):
3973 if type(self) != type(other): return False
3974 if self.version != other.version: return False
3975 if self.type != other.type: return False
3976 if self.xid != other.xid: return False
3977 if self.role != other.role: return False
3978 return True
3979
3980 def __ne__(self, other):
3981 return not self.__eq__(other)
3982
3983 def __str__(self):
3984 return self.show()
3985
3986 def show(self):
3987 import loxi.pp
3988 return loxi.pp.pp(self)
3989
3990 def pretty_print(self, q):
3991 q.text("nicira_controller_role_request {")
3992 with q.group():
3993 with q.indent(2):
3994 q.breakable()
3995 q.text("xid = ");
3996 if self.xid != None:
3997 q.text("%#x" % self.xid)
3998 else:
3999 q.text('None')
4000 q.text(","); q.breakable()
4001 q.text("role = ");
4002 q.text("%#x" % self.role)
4003 q.breakable()
4004 q.text('}')
4005
4006class packet_in(Message):
4007 version = const.OFP_VERSION
4008 type = const.OFPT_PACKET_IN
4009
Rich Lanec2ee4b82013-04-24 17:12:38 -07004010 def __init__(self, xid=None, buffer_id=None, total_len=None, in_port=None, reason=None, data=None):
Rich Laneb658ddd2013-03-12 10:15:10 -07004011 self.xid = xid
4012 if buffer_id != None:
4013 self.buffer_id = buffer_id
4014 else:
4015 self.buffer_id = 0
4016 if total_len != None:
4017 self.total_len = total_len
4018 else:
4019 self.total_len = 0
4020 if in_port != None:
4021 self.in_port = in_port
4022 else:
4023 self.in_port = 0
4024 if reason != None:
4025 self.reason = reason
4026 else:
4027 self.reason = 0
Rich Laneb658ddd2013-03-12 10:15:10 -07004028 if data != None:
4029 self.data = data
4030 else:
4031 self.data = ""
4032
4033 def pack(self):
4034 packed = []
4035 packed.append(struct.pack("!B", self.version))
4036 packed.append(struct.pack("!B", self.type))
4037 packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
4038 packed.append(struct.pack("!L", self.xid))
4039 packed.append(struct.pack("!L", self.buffer_id))
4040 packed.append(struct.pack("!H", self.total_len))
4041 packed.append(struct.pack("!H", self.in_port))
4042 packed.append(struct.pack("!B", self.reason))
Rich Lanec2ee4b82013-04-24 17:12:38 -07004043 packed.append('\x00' * 1)
Rich Laneb658ddd2013-03-12 10:15:10 -07004044 packed.append(self.data)
4045 length = sum([len(x) for x in packed])
4046 packed[2] = struct.pack("!H", length)
4047 return ''.join(packed)
4048
4049 @staticmethod
4050 def unpack(buf):
4051 if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
4052 obj = packet_in()
Rich Lanec2ee4b82013-04-24 17:12:38 -07004053 if type(buf) == loxi.generic_util.OFReader:
4054 reader = buf
4055 else:
4056 reader = loxi.generic_util.OFReader(buf)
4057 _version = reader.read('!B')[0]
4058 assert(_version == const.OFP_VERSION)
4059 _type = reader.read('!B')[0]
4060 assert(_type == const.OFPT_PACKET_IN)
4061 _length = reader.read('!H')[0]
4062 obj.xid = reader.read('!L')[0]
4063 obj.buffer_id = reader.read('!L')[0]
4064 obj.total_len = reader.read('!H')[0]
4065 obj.in_port = reader.read('!H')[0]
4066 obj.reason = reader.read('!B')[0]
4067 reader.skip(1)
4068 obj.data = str(reader.read_all())
Rich Laneb658ddd2013-03-12 10:15:10 -07004069 return obj
4070
4071 def __eq__(self, other):
4072 if type(self) != type(other): return False
4073 if self.version != other.version: return False
4074 if self.type != other.type: return False
4075 if self.xid != other.xid: return False
4076 if self.buffer_id != other.buffer_id: return False
4077 if self.total_len != other.total_len: return False
4078 if self.in_port != other.in_port: return False
4079 if self.reason != other.reason: return False
Rich Laneb658ddd2013-03-12 10:15:10 -07004080 if self.data != other.data: return False
4081 return True
4082
4083 def __ne__(self, other):
4084 return not self.__eq__(other)
4085
4086 def __str__(self):
4087 return self.show()
4088
4089 def show(self):
4090 import loxi.pp
4091 return loxi.pp.pp(self)
4092
4093 def pretty_print(self, q):
4094 q.text("packet_in {")
4095 with q.group():
4096 with q.indent(2):
4097 q.breakable()
4098 q.text("xid = ");
4099 if self.xid != None:
4100 q.text("%#x" % self.xid)
4101 else:
4102 q.text('None')
4103 q.text(","); q.breakable()
4104 q.text("buffer_id = ");
4105 q.text("%#x" % self.buffer_id)
4106 q.text(","); q.breakable()
4107 q.text("total_len = ");
4108 q.text("%#x" % self.total_len)
4109 q.text(","); q.breakable()
4110 q.text("in_port = ");
4111 q.text(util.pretty_port(self.in_port))
4112 q.text(","); q.breakable()
4113 q.text("reason = ");
4114 q.text("%#x" % self.reason)
4115 q.text(","); q.breakable()
Rich Laneb658ddd2013-03-12 10:15:10 -07004116 q.text("data = ");
4117 q.pp(self.data)
4118 q.breakable()
4119 q.text('}')
4120
4121class packet_out(Message):
4122 version = const.OFP_VERSION
4123 type = const.OFPT_PACKET_OUT
4124
4125 def __init__(self, xid=None, buffer_id=None, in_port=None, actions=None, data=None):
4126 self.xid = xid
4127 if buffer_id != None:
4128 self.buffer_id = buffer_id
4129 else:
Rich Laneff637c92013-04-04 13:57:09 -07004130 self.buffer_id = 0
Rich Laneb658ddd2013-03-12 10:15:10 -07004131 if in_port != None:
4132 self.in_port = in_port
4133 else:
4134 self.in_port = 0
4135 if actions != None:
4136 self.actions = actions
4137 else:
4138 self.actions = []
4139 if data != None:
4140 self.data = data
4141 else:
4142 self.data = ""
4143
4144 def pack(self):
4145 packed = []
4146 packed.append(struct.pack("!B", self.version))
4147 packed.append(struct.pack("!B", self.type))
Rich Lanec2ee4b82013-04-24 17:12:38 -07004148 packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
Rich Laneb658ddd2013-03-12 10:15:10 -07004149 packed.append(struct.pack("!L", self.xid))
4150 packed.append(struct.pack("!L", self.buffer_id))
4151 packed.append(struct.pack("!H", self.in_port))
Rich Lanec2ee4b82013-04-24 17:12:38 -07004152 packed.append(struct.pack("!H", 0)) # placeholder for actions_len at index 6
4153 packed.append("".join([x.pack() for x in self.actions]))
4154 packed[6] = struct.pack("!H", len(packed[-1]))
Rich Laneb658ddd2013-03-12 10:15:10 -07004155 packed.append(self.data)
4156 length = sum([len(x) for x in packed])
4157 packed[2] = struct.pack("!H", length)
4158 return ''.join(packed)
4159
4160 @staticmethod
4161 def unpack(buf):
4162 if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
4163 obj = packet_out()
Rich Lanec2ee4b82013-04-24 17:12:38 -07004164 if type(buf) == loxi.generic_util.OFReader:
4165 reader = buf
4166 else:
4167 reader = loxi.generic_util.OFReader(buf)
4168 _version = reader.read('!B')[0]
4169 assert(_version == const.OFP_VERSION)
4170 _type = reader.read('!B')[0]
4171 assert(_type == const.OFPT_PACKET_OUT)
4172 _length = reader.read('!H')[0]
4173 obj.xid = reader.read('!L')[0]
4174 obj.buffer_id = reader.read('!L')[0]
4175 obj.in_port = reader.read('!H')[0]
4176 _actions_len = reader.read('!H')[0]
4177 obj.actions = action.unpack_list(reader.slice(_actions_len))
4178 obj.data = str(reader.read_all())
Rich Laneb658ddd2013-03-12 10:15:10 -07004179 return obj
4180
4181 def __eq__(self, other):
4182 if type(self) != type(other): return False
4183 if self.version != other.version: return False
4184 if self.type != other.type: return False
4185 if self.xid != other.xid: return False
4186 if self.buffer_id != other.buffer_id: return False
4187 if self.in_port != other.in_port: return False
4188 if self.actions != other.actions: return False
4189 if self.data != other.data: return False
4190 return True
4191
4192 def __ne__(self, other):
4193 return not self.__eq__(other)
4194
4195 def __str__(self):
4196 return self.show()
4197
4198 def show(self):
4199 import loxi.pp
4200 return loxi.pp.pp(self)
4201
4202 def pretty_print(self, q):
4203 q.text("packet_out {")
4204 with q.group():
4205 with q.indent(2):
4206 q.breakable()
4207 q.text("xid = ");
4208 if self.xid != None:
4209 q.text("%#x" % self.xid)
4210 else:
4211 q.text('None')
4212 q.text(","); q.breakable()
4213 q.text("buffer_id = ");
4214 q.text("%#x" % self.buffer_id)
4215 q.text(","); q.breakable()
4216 q.text("in_port = ");
4217 q.text(util.pretty_port(self.in_port))
4218 q.text(","); q.breakable()
4219 q.text("actions = ");
4220 q.pp(self.actions)
4221 q.text(","); q.breakable()
4222 q.text("data = ");
4223 q.pp(self.data)
4224 q.breakable()
4225 q.text('}')
4226
4227class port_mod(Message):
4228 version = const.OFP_VERSION
4229 type = const.OFPT_PORT_MOD
4230
Rich Lanec2ee4b82013-04-24 17:12:38 -07004231 def __init__(self, xid=None, port_no=None, hw_addr=None, config=None, mask=None, advertise=None):
Rich Laneb658ddd2013-03-12 10:15:10 -07004232 self.xid = xid
4233 if port_no != None:
4234 self.port_no = port_no
4235 else:
4236 self.port_no = 0
4237 if hw_addr != None:
4238 self.hw_addr = hw_addr
4239 else:
4240 self.hw_addr = [0,0,0,0,0,0]
4241 if config != None:
4242 self.config = config
4243 else:
4244 self.config = 0
4245 if mask != None:
4246 self.mask = mask
4247 else:
4248 self.mask = 0
4249 if advertise != None:
4250 self.advertise = advertise
4251 else:
4252 self.advertise = 0
Rich Laneb658ddd2013-03-12 10:15:10 -07004253
4254 def pack(self):
4255 packed = []
4256 packed.append(struct.pack("!B", self.version))
4257 packed.append(struct.pack("!B", self.type))
4258 packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
4259 packed.append(struct.pack("!L", self.xid))
4260 packed.append(struct.pack("!H", self.port_no))
4261 packed.append(struct.pack("!6B", *self.hw_addr))
4262 packed.append(struct.pack("!L", self.config))
4263 packed.append(struct.pack("!L", self.mask))
4264 packed.append(struct.pack("!L", self.advertise))
Rich Lanec2ee4b82013-04-24 17:12:38 -07004265 packed.append('\x00' * 4)
Rich Laneb658ddd2013-03-12 10:15:10 -07004266 length = sum([len(x) for x in packed])
4267 packed[2] = struct.pack("!H", length)
4268 return ''.join(packed)
4269
4270 @staticmethod
4271 def unpack(buf):
4272 if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
4273 obj = port_mod()
Rich Lanec2ee4b82013-04-24 17:12:38 -07004274 if type(buf) == loxi.generic_util.OFReader:
4275 reader = buf
4276 else:
4277 reader = loxi.generic_util.OFReader(buf)
4278 _version = reader.read('!B')[0]
4279 assert(_version == const.OFP_VERSION)
4280 _type = reader.read('!B')[0]
4281 assert(_type == const.OFPT_PORT_MOD)
4282 _length = reader.read('!H')[0]
4283 obj.xid = reader.read('!L')[0]
4284 obj.port_no = reader.read('!H')[0]
4285 obj.hw_addr = list(reader.read('!6B'))
4286 obj.config = reader.read('!L')[0]
4287 obj.mask = reader.read('!L')[0]
4288 obj.advertise = reader.read('!L')[0]
4289 reader.skip(4)
Rich Laneb658ddd2013-03-12 10:15:10 -07004290 return obj
4291
4292 def __eq__(self, other):
4293 if type(self) != type(other): return False
4294 if self.version != other.version: return False
4295 if self.type != other.type: return False
4296 if self.xid != other.xid: return False
4297 if self.port_no != other.port_no: return False
4298 if self.hw_addr != other.hw_addr: return False
4299 if self.config != other.config: return False
4300 if self.mask != other.mask: return False
4301 if self.advertise != other.advertise: return False
Rich Laneb658ddd2013-03-12 10:15:10 -07004302 return True
4303
4304 def __ne__(self, other):
4305 return not self.__eq__(other)
4306
4307 def __str__(self):
4308 return self.show()
4309
4310 def show(self):
4311 import loxi.pp
4312 return loxi.pp.pp(self)
4313
4314 def pretty_print(self, q):
4315 q.text("port_mod {")
4316 with q.group():
4317 with q.indent(2):
4318 q.breakable()
4319 q.text("xid = ");
4320 if self.xid != None:
4321 q.text("%#x" % self.xid)
4322 else:
4323 q.text('None')
4324 q.text(","); q.breakable()
4325 q.text("port_no = ");
4326 q.text(util.pretty_port(self.port_no))
4327 q.text(","); q.breakable()
4328 q.text("hw_addr = ");
4329 q.text(util.pretty_mac(self.hw_addr))
4330 q.text(","); q.breakable()
4331 q.text("config = ");
4332 q.text("%#x" % self.config)
4333 q.text(","); q.breakable()
4334 q.text("mask = ");
4335 q.text("%#x" % self.mask)
4336 q.text(","); q.breakable()
4337 q.text("advertise = ");
4338 q.text("%#x" % self.advertise)
Rich Laneb658ddd2013-03-12 10:15:10 -07004339 q.breakable()
4340 q.text('}')
4341
4342class port_stats_reply(Message):
4343 version = const.OFP_VERSION
4344 type = const.OFPT_STATS_REPLY
4345 stats_type = const.OFPST_PORT
4346
4347 def __init__(self, xid=None, flags=None, entries=None):
4348 self.xid = xid
4349 if flags != None:
4350 self.flags = flags
4351 else:
4352 self.flags = 0
4353 if entries != None:
4354 self.entries = entries
4355 else:
4356 self.entries = []
4357
4358 def pack(self):
4359 packed = []
4360 packed.append(struct.pack("!B", self.version))
4361 packed.append(struct.pack("!B", self.type))
4362 packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
4363 packed.append(struct.pack("!L", self.xid))
4364 packed.append(struct.pack("!H", self.stats_type))
4365 packed.append(struct.pack("!H", self.flags))
4366 packed.append("".join([x.pack() for x in self.entries]))
4367 length = sum([len(x) for x in packed])
4368 packed[2] = struct.pack("!H", length)
4369 return ''.join(packed)
4370
4371 @staticmethod
4372 def unpack(buf):
4373 if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
4374 obj = port_stats_reply()
Rich Lanec2ee4b82013-04-24 17:12:38 -07004375 if type(buf) == loxi.generic_util.OFReader:
4376 reader = buf
4377 else:
4378 reader = loxi.generic_util.OFReader(buf)
4379 _version = reader.read('!B')[0]
4380 assert(_version == const.OFP_VERSION)
4381 _type = reader.read('!B')[0]
4382 assert(_type == const.OFPT_STATS_REPLY)
4383 _length = reader.read('!H')[0]
4384 obj.xid = reader.read('!L')[0]
4385 _stats_type = reader.read('!H')[0]
4386 assert(_stats_type == const.OFPST_PORT)
4387 obj.flags = reader.read('!H')[0]
4388 obj.entries = loxi.generic_util.unpack_list(reader, common.port_stats_entry.unpack)
Rich Laneb658ddd2013-03-12 10:15:10 -07004389 return obj
4390
4391 def __eq__(self, other):
4392 if type(self) != type(other): return False
4393 if self.version != other.version: return False
4394 if self.type != other.type: return False
4395 if self.xid != other.xid: return False
4396 if self.flags != other.flags: return False
4397 if self.entries != other.entries: return False
4398 return True
4399
4400 def __ne__(self, other):
4401 return not self.__eq__(other)
4402
4403 def __str__(self):
4404 return self.show()
4405
4406 def show(self):
4407 import loxi.pp
4408 return loxi.pp.pp(self)
4409
4410 def pretty_print(self, q):
4411 q.text("port_stats_reply {")
4412 with q.group():
4413 with q.indent(2):
4414 q.breakable()
4415 q.text("xid = ");
4416 if self.xid != None:
4417 q.text("%#x" % self.xid)
4418 else:
4419 q.text('None')
4420 q.text(","); q.breakable()
4421 q.text("flags = ");
4422 q.text("%#x" % self.flags)
4423 q.text(","); q.breakable()
4424 q.text("entries = ");
4425 q.pp(self.entries)
4426 q.breakable()
4427 q.text('}')
4428
4429class port_stats_request(Message):
4430 version = const.OFP_VERSION
4431 type = const.OFPT_STATS_REQUEST
4432 stats_type = const.OFPST_PORT
4433
Rich Lanec2ee4b82013-04-24 17:12:38 -07004434 def __init__(self, xid=None, flags=None, port_no=None):
Rich Laneb658ddd2013-03-12 10:15:10 -07004435 self.xid = xid
4436 if flags != None:
4437 self.flags = flags
4438 else:
4439 self.flags = 0
4440 if port_no != None:
4441 self.port_no = port_no
4442 else:
4443 self.port_no = 0
Rich Laneb658ddd2013-03-12 10:15:10 -07004444
4445 def pack(self):
4446 packed = []
4447 packed.append(struct.pack("!B", self.version))
4448 packed.append(struct.pack("!B", self.type))
4449 packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
4450 packed.append(struct.pack("!L", self.xid))
4451 packed.append(struct.pack("!H", self.stats_type))
4452 packed.append(struct.pack("!H", self.flags))
4453 packed.append(struct.pack("!H", self.port_no))
Rich Lanec2ee4b82013-04-24 17:12:38 -07004454 packed.append('\x00' * 6)
Rich Laneb658ddd2013-03-12 10:15:10 -07004455 length = sum([len(x) for x in packed])
4456 packed[2] = struct.pack("!H", length)
4457 return ''.join(packed)
4458
4459 @staticmethod
4460 def unpack(buf):
4461 if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
4462 obj = port_stats_request()
Rich Lanec2ee4b82013-04-24 17:12:38 -07004463 if type(buf) == loxi.generic_util.OFReader:
4464 reader = buf
4465 else:
4466 reader = loxi.generic_util.OFReader(buf)
4467 _version = reader.read('!B')[0]
4468 assert(_version == const.OFP_VERSION)
4469 _type = reader.read('!B')[0]
4470 assert(_type == const.OFPT_STATS_REQUEST)
4471 _length = reader.read('!H')[0]
4472 obj.xid = reader.read('!L')[0]
4473 _stats_type = reader.read('!H')[0]
4474 assert(_stats_type == const.OFPST_PORT)
4475 obj.flags = reader.read('!H')[0]
4476 obj.port_no = reader.read('!H')[0]
4477 reader.skip(6)
Rich Laneb658ddd2013-03-12 10:15:10 -07004478 return obj
4479
4480 def __eq__(self, other):
4481 if type(self) != type(other): return False
4482 if self.version != other.version: return False
4483 if self.type != other.type: return False
4484 if self.xid != other.xid: return False
4485 if self.flags != other.flags: return False
4486 if self.port_no != other.port_no: return False
Rich Laneb658ddd2013-03-12 10:15:10 -07004487 return True
4488
4489 def __ne__(self, other):
4490 return not self.__eq__(other)
4491
4492 def __str__(self):
4493 return self.show()
4494
4495 def show(self):
4496 import loxi.pp
4497 return loxi.pp.pp(self)
4498
4499 def pretty_print(self, q):
4500 q.text("port_stats_request {")
4501 with q.group():
4502 with q.indent(2):
4503 q.breakable()
4504 q.text("xid = ");
4505 if self.xid != None:
4506 q.text("%#x" % self.xid)
4507 else:
4508 q.text('None')
4509 q.text(","); q.breakable()
4510 q.text("flags = ");
4511 q.text("%#x" % self.flags)
4512 q.text(","); q.breakable()
4513 q.text("port_no = ");
4514 q.text(util.pretty_port(self.port_no))
Rich Laneb658ddd2013-03-12 10:15:10 -07004515 q.breakable()
4516 q.text('}')
4517
4518class port_status(Message):
4519 version = const.OFP_VERSION
4520 type = const.OFPT_PORT_STATUS
4521
Rich Lanec2ee4b82013-04-24 17:12:38 -07004522 def __init__(self, xid=None, reason=None, desc=None):
Rich Laneb658ddd2013-03-12 10:15:10 -07004523 self.xid = xid
4524 if reason != None:
4525 self.reason = reason
4526 else:
4527 self.reason = 0
Rich Laneb658ddd2013-03-12 10:15:10 -07004528 if desc != None:
4529 self.desc = desc
4530 else:
4531 self.desc = common.port_desc()
4532
4533 def pack(self):
4534 packed = []
4535 packed.append(struct.pack("!B", self.version))
4536 packed.append(struct.pack("!B", self.type))
4537 packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
4538 packed.append(struct.pack("!L", self.xid))
4539 packed.append(struct.pack("!B", self.reason))
Rich Lanec2ee4b82013-04-24 17:12:38 -07004540 packed.append('\x00' * 7)
Rich Laneb658ddd2013-03-12 10:15:10 -07004541 packed.append(self.desc.pack())
4542 length = sum([len(x) for x in packed])
4543 packed[2] = struct.pack("!H", length)
4544 return ''.join(packed)
4545
4546 @staticmethod
4547 def unpack(buf):
4548 if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
4549 obj = port_status()
Rich Lanec2ee4b82013-04-24 17:12:38 -07004550 if type(buf) == loxi.generic_util.OFReader:
4551 reader = buf
4552 else:
4553 reader = loxi.generic_util.OFReader(buf)
4554 _version = reader.read('!B')[0]
4555 assert(_version == const.OFP_VERSION)
4556 _type = reader.read('!B')[0]
4557 assert(_type == const.OFPT_PORT_STATUS)
4558 _length = reader.read('!H')[0]
4559 obj.xid = reader.read('!L')[0]
4560 obj.reason = reader.read('!B')[0]
4561 reader.skip(7)
4562 obj.desc = common.port_desc.unpack(reader)
Rich Laneb658ddd2013-03-12 10:15:10 -07004563 return obj
4564
4565 def __eq__(self, other):
4566 if type(self) != type(other): return False
4567 if self.version != other.version: return False
4568 if self.type != other.type: return False
4569 if self.xid != other.xid: return False
4570 if self.reason != other.reason: return False
Rich Laneb658ddd2013-03-12 10:15:10 -07004571 if self.desc != other.desc: return False
4572 return True
4573
4574 def __ne__(self, other):
4575 return not self.__eq__(other)
4576
4577 def __str__(self):
4578 return self.show()
4579
4580 def show(self):
4581 import loxi.pp
4582 return loxi.pp.pp(self)
4583
4584 def pretty_print(self, q):
4585 q.text("port_status {")
4586 with q.group():
4587 with q.indent(2):
4588 q.breakable()
4589 q.text("xid = ");
4590 if self.xid != None:
4591 q.text("%#x" % self.xid)
4592 else:
4593 q.text('None')
4594 q.text(","); q.breakable()
4595 q.text("reason = ");
4596 q.text("%#x" % self.reason)
4597 q.text(","); q.breakable()
Rich Laneb658ddd2013-03-12 10:15:10 -07004598 q.text("desc = ");
4599 q.pp(self.desc)
4600 q.breakable()
4601 q.text('}')
4602
4603class queue_get_config_reply(Message):
4604 version = const.OFP_VERSION
4605 type = const.OFPT_QUEUE_GET_CONFIG_REPLY
4606
Rich Lanec2ee4b82013-04-24 17:12:38 -07004607 def __init__(self, xid=None, port=None, queues=None):
Rich Laneb658ddd2013-03-12 10:15:10 -07004608 self.xid = xid
4609 if port != None:
4610 self.port = port
4611 else:
4612 self.port = 0
Rich Laneb658ddd2013-03-12 10:15:10 -07004613 if queues != None:
4614 self.queues = queues
4615 else:
4616 self.queues = []
4617
4618 def pack(self):
4619 packed = []
4620 packed.append(struct.pack("!B", self.version))
4621 packed.append(struct.pack("!B", self.type))
4622 packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
4623 packed.append(struct.pack("!L", self.xid))
4624 packed.append(struct.pack("!H", self.port))
Rich Lanec2ee4b82013-04-24 17:12:38 -07004625 packed.append('\x00' * 6)
Rich Laneb658ddd2013-03-12 10:15:10 -07004626 packed.append("".join([x.pack() for x in self.queues]))
4627 length = sum([len(x) for x in packed])
4628 packed[2] = struct.pack("!H", length)
4629 return ''.join(packed)
4630
4631 @staticmethod
4632 def unpack(buf):
4633 if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
4634 obj = queue_get_config_reply()
Rich Lanec2ee4b82013-04-24 17:12:38 -07004635 if type(buf) == loxi.generic_util.OFReader:
4636 reader = buf
4637 else:
4638 reader = loxi.generic_util.OFReader(buf)
4639 _version = reader.read('!B')[0]
4640 assert(_version == const.OFP_VERSION)
4641 _type = reader.read('!B')[0]
4642 assert(_type == const.OFPT_QUEUE_GET_CONFIG_REPLY)
4643 _length = reader.read('!H')[0]
4644 obj.xid = reader.read('!L')[0]
4645 obj.port = reader.read('!H')[0]
4646 reader.skip(6)
4647 obj.queues = common.unpack_list_packet_queue(reader)
Rich Laneb658ddd2013-03-12 10:15:10 -07004648 return obj
4649
4650 def __eq__(self, other):
4651 if type(self) != type(other): return False
4652 if self.version != other.version: return False
4653 if self.type != other.type: return False
4654 if self.xid != other.xid: return False
4655 if self.port != other.port: return False
Rich Laneb658ddd2013-03-12 10:15:10 -07004656 if self.queues != other.queues: return False
4657 return True
4658
4659 def __ne__(self, other):
4660 return not self.__eq__(other)
4661
4662 def __str__(self):
4663 return self.show()
4664
4665 def show(self):
4666 import loxi.pp
4667 return loxi.pp.pp(self)
4668
4669 def pretty_print(self, q):
4670 q.text("queue_get_config_reply {")
4671 with q.group():
4672 with q.indent(2):
4673 q.breakable()
4674 q.text("xid = ");
4675 if self.xid != None:
4676 q.text("%#x" % self.xid)
4677 else:
4678 q.text('None')
4679 q.text(","); q.breakable()
4680 q.text("port = ");
4681 q.text(util.pretty_port(self.port))
4682 q.text(","); q.breakable()
Rich Laneb658ddd2013-03-12 10:15:10 -07004683 q.text("queues = ");
4684 q.pp(self.queues)
4685 q.breakable()
4686 q.text('}')
4687
4688class queue_get_config_request(Message):
4689 version = const.OFP_VERSION
4690 type = const.OFPT_QUEUE_GET_CONFIG_REQUEST
4691
Rich Lanec2ee4b82013-04-24 17:12:38 -07004692 def __init__(self, xid=None, port=None):
Rich Laneb658ddd2013-03-12 10:15:10 -07004693 self.xid = xid
4694 if port != None:
4695 self.port = port
4696 else:
4697 self.port = 0
Rich Laneb658ddd2013-03-12 10:15:10 -07004698
4699 def pack(self):
4700 packed = []
4701 packed.append(struct.pack("!B", self.version))
4702 packed.append(struct.pack("!B", self.type))
4703 packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
4704 packed.append(struct.pack("!L", self.xid))
4705 packed.append(struct.pack("!H", self.port))
Rich Lanec2ee4b82013-04-24 17:12:38 -07004706 packed.append('\x00' * 2)
Rich Laneb658ddd2013-03-12 10:15:10 -07004707 length = sum([len(x) for x in packed])
4708 packed[2] = struct.pack("!H", length)
4709 return ''.join(packed)
4710
4711 @staticmethod
4712 def unpack(buf):
4713 if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
4714 obj = queue_get_config_request()
Rich Lanec2ee4b82013-04-24 17:12:38 -07004715 if type(buf) == loxi.generic_util.OFReader:
4716 reader = buf
4717 else:
4718 reader = loxi.generic_util.OFReader(buf)
4719 _version = reader.read('!B')[0]
4720 assert(_version == const.OFP_VERSION)
4721 _type = reader.read('!B')[0]
4722 assert(_type == const.OFPT_QUEUE_GET_CONFIG_REQUEST)
4723 _length = reader.read('!H')[0]
4724 obj.xid = reader.read('!L')[0]
4725 obj.port = reader.read('!H')[0]
4726 reader.skip(2)
Rich Laneb658ddd2013-03-12 10:15:10 -07004727 return obj
4728
4729 def __eq__(self, other):
4730 if type(self) != type(other): return False
4731 if self.version != other.version: return False
4732 if self.type != other.type: return False
4733 if self.xid != other.xid: return False
4734 if self.port != other.port: return False
Rich Laneb658ddd2013-03-12 10:15:10 -07004735 return True
4736
4737 def __ne__(self, other):
4738 return not self.__eq__(other)
4739
4740 def __str__(self):
4741 return self.show()
4742
4743 def show(self):
4744 import loxi.pp
4745 return loxi.pp.pp(self)
4746
4747 def pretty_print(self, q):
4748 q.text("queue_get_config_request {")
4749 with q.group():
4750 with q.indent(2):
4751 q.breakable()
4752 q.text("xid = ");
4753 if self.xid != None:
4754 q.text("%#x" % self.xid)
4755 else:
4756 q.text('None')
4757 q.text(","); q.breakable()
4758 q.text("port = ");
4759 q.text(util.pretty_port(self.port))
Rich Laneb658ddd2013-03-12 10:15:10 -07004760 q.breakable()
4761 q.text('}')
4762
4763class queue_stats_reply(Message):
4764 version = const.OFP_VERSION
4765 type = const.OFPT_STATS_REPLY
4766 stats_type = const.OFPST_QUEUE
4767
4768 def __init__(self, xid=None, flags=None, entries=None):
4769 self.xid = xid
4770 if flags != None:
4771 self.flags = flags
4772 else:
4773 self.flags = 0
4774 if entries != None:
4775 self.entries = entries
4776 else:
4777 self.entries = []
4778
4779 def pack(self):
4780 packed = []
4781 packed.append(struct.pack("!B", self.version))
4782 packed.append(struct.pack("!B", self.type))
4783 packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
4784 packed.append(struct.pack("!L", self.xid))
4785 packed.append(struct.pack("!H", self.stats_type))
4786 packed.append(struct.pack("!H", self.flags))
4787 packed.append("".join([x.pack() for x in self.entries]))
4788 length = sum([len(x) for x in packed])
4789 packed[2] = struct.pack("!H", length)
4790 return ''.join(packed)
4791
4792 @staticmethod
4793 def unpack(buf):
4794 if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
4795 obj = queue_stats_reply()
Rich Lanec2ee4b82013-04-24 17:12:38 -07004796 if type(buf) == loxi.generic_util.OFReader:
4797 reader = buf
4798 else:
4799 reader = loxi.generic_util.OFReader(buf)
4800 _version = reader.read('!B')[0]
4801 assert(_version == const.OFP_VERSION)
4802 _type = reader.read('!B')[0]
4803 assert(_type == const.OFPT_STATS_REPLY)
4804 _length = reader.read('!H')[0]
4805 obj.xid = reader.read('!L')[0]
4806 _stats_type = reader.read('!H')[0]
4807 assert(_stats_type == const.OFPST_QUEUE)
4808 obj.flags = reader.read('!H')[0]
4809 obj.entries = loxi.generic_util.unpack_list(reader, common.queue_stats_entry.unpack)
Rich Laneb658ddd2013-03-12 10:15:10 -07004810 return obj
4811
4812 def __eq__(self, other):
4813 if type(self) != type(other): return False
4814 if self.version != other.version: return False
4815 if self.type != other.type: return False
4816 if self.xid != other.xid: return False
4817 if self.flags != other.flags: return False
4818 if self.entries != other.entries: return False
4819 return True
4820
4821 def __ne__(self, other):
4822 return not self.__eq__(other)
4823
4824 def __str__(self):
4825 return self.show()
4826
4827 def show(self):
4828 import loxi.pp
4829 return loxi.pp.pp(self)
4830
4831 def pretty_print(self, q):
4832 q.text("queue_stats_reply {")
4833 with q.group():
4834 with q.indent(2):
4835 q.breakable()
4836 q.text("xid = ");
4837 if self.xid != None:
4838 q.text("%#x" % self.xid)
4839 else:
4840 q.text('None')
4841 q.text(","); q.breakable()
4842 q.text("flags = ");
4843 q.text("%#x" % self.flags)
4844 q.text(","); q.breakable()
4845 q.text("entries = ");
4846 q.pp(self.entries)
4847 q.breakable()
4848 q.text('}')
4849
4850class queue_stats_request(Message):
4851 version = const.OFP_VERSION
4852 type = const.OFPT_STATS_REQUEST
4853 stats_type = const.OFPST_QUEUE
4854
Rich Lanec2ee4b82013-04-24 17:12:38 -07004855 def __init__(self, xid=None, flags=None, port_no=None, queue_id=None):
Rich Laneb658ddd2013-03-12 10:15:10 -07004856 self.xid = xid
4857 if flags != None:
4858 self.flags = flags
4859 else:
4860 self.flags = 0
4861 if port_no != None:
4862 self.port_no = port_no
4863 else:
4864 self.port_no = 0
Rich Laneb658ddd2013-03-12 10:15:10 -07004865 if queue_id != None:
4866 self.queue_id = queue_id
4867 else:
4868 self.queue_id = 0
4869
4870 def pack(self):
4871 packed = []
4872 packed.append(struct.pack("!B", self.version))
4873 packed.append(struct.pack("!B", self.type))
4874 packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
4875 packed.append(struct.pack("!L", self.xid))
4876 packed.append(struct.pack("!H", self.stats_type))
4877 packed.append(struct.pack("!H", self.flags))
4878 packed.append(struct.pack("!H", self.port_no))
Rich Lanec2ee4b82013-04-24 17:12:38 -07004879 packed.append('\x00' * 2)
Rich Laneb658ddd2013-03-12 10:15:10 -07004880 packed.append(struct.pack("!L", self.queue_id))
4881 length = sum([len(x) for x in packed])
4882 packed[2] = struct.pack("!H", length)
4883 return ''.join(packed)
4884
4885 @staticmethod
4886 def unpack(buf):
4887 if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
4888 obj = queue_stats_request()
Rich Lanec2ee4b82013-04-24 17:12:38 -07004889 if type(buf) == loxi.generic_util.OFReader:
4890 reader = buf
4891 else:
4892 reader = loxi.generic_util.OFReader(buf)
4893 _version = reader.read('!B')[0]
4894 assert(_version == const.OFP_VERSION)
4895 _type = reader.read('!B')[0]
4896 assert(_type == const.OFPT_STATS_REQUEST)
4897 _length = reader.read('!H')[0]
4898 obj.xid = reader.read('!L')[0]
4899 _stats_type = reader.read('!H')[0]
4900 assert(_stats_type == const.OFPST_QUEUE)
4901 obj.flags = reader.read('!H')[0]
4902 obj.port_no = reader.read('!H')[0]
4903 reader.skip(2)
4904 obj.queue_id = reader.read('!L')[0]
Rich Laneb658ddd2013-03-12 10:15:10 -07004905 return obj
4906
4907 def __eq__(self, other):
4908 if type(self) != type(other): return False
4909 if self.version != other.version: return False
4910 if self.type != other.type: return False
4911 if self.xid != other.xid: return False
4912 if self.flags != other.flags: return False
4913 if self.port_no != other.port_no: return False
Rich Laneb658ddd2013-03-12 10:15:10 -07004914 if self.queue_id != other.queue_id: return False
4915 return True
4916
4917 def __ne__(self, other):
4918 return not self.__eq__(other)
4919
4920 def __str__(self):
4921 return self.show()
4922
4923 def show(self):
4924 import loxi.pp
4925 return loxi.pp.pp(self)
4926
4927 def pretty_print(self, q):
4928 q.text("queue_stats_request {")
4929 with q.group():
4930 with q.indent(2):
4931 q.breakable()
4932 q.text("xid = ");
4933 if self.xid != None:
4934 q.text("%#x" % self.xid)
4935 else:
4936 q.text('None')
4937 q.text(","); q.breakable()
4938 q.text("flags = ");
4939 q.text("%#x" % self.flags)
4940 q.text(","); q.breakable()
4941 q.text("port_no = ");
4942 q.text(util.pretty_port(self.port_no))
4943 q.text(","); q.breakable()
Rich Laneb658ddd2013-03-12 10:15:10 -07004944 q.text("queue_id = ");
4945 q.text("%#x" % self.queue_id)
4946 q.breakable()
4947 q.text('}')
4948
4949class set_config(Message):
4950 version = const.OFP_VERSION
4951 type = const.OFPT_SET_CONFIG
4952
4953 def __init__(self, xid=None, flags=None, miss_send_len=None):
4954 self.xid = xid
4955 if flags != None:
4956 self.flags = flags
4957 else:
4958 self.flags = 0
4959 if miss_send_len != None:
4960 self.miss_send_len = miss_send_len
4961 else:
4962 self.miss_send_len = 0
4963
4964 def pack(self):
4965 packed = []
4966 packed.append(struct.pack("!B", self.version))
4967 packed.append(struct.pack("!B", self.type))
4968 packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
4969 packed.append(struct.pack("!L", self.xid))
4970 packed.append(struct.pack("!H", self.flags))
4971 packed.append(struct.pack("!H", self.miss_send_len))
4972 length = sum([len(x) for x in packed])
4973 packed[2] = struct.pack("!H", length)
4974 return ''.join(packed)
4975
4976 @staticmethod
4977 def unpack(buf):
4978 if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
4979 obj = set_config()
Rich Lanec2ee4b82013-04-24 17:12:38 -07004980 if type(buf) == loxi.generic_util.OFReader:
4981 reader = buf
4982 else:
4983 reader = loxi.generic_util.OFReader(buf)
4984 _version = reader.read('!B')[0]
4985 assert(_version == const.OFP_VERSION)
4986 _type = reader.read('!B')[0]
4987 assert(_type == const.OFPT_SET_CONFIG)
4988 _length = reader.read('!H')[0]
4989 obj.xid = reader.read('!L')[0]
4990 obj.flags = reader.read('!H')[0]
4991 obj.miss_send_len = reader.read('!H')[0]
Rich Laneb658ddd2013-03-12 10:15:10 -07004992 return obj
4993
4994 def __eq__(self, other):
4995 if type(self) != type(other): return False
4996 if self.version != other.version: return False
4997 if self.type != other.type: return False
4998 if self.xid != other.xid: return False
4999 if self.flags != other.flags: return False
5000 if self.miss_send_len != other.miss_send_len: return False
5001 return True
5002
5003 def __ne__(self, other):
5004 return not self.__eq__(other)
5005
5006 def __str__(self):
5007 return self.show()
5008
5009 def show(self):
5010 import loxi.pp
5011 return loxi.pp.pp(self)
5012
5013 def pretty_print(self, q):
5014 q.text("set_config {")
5015 with q.group():
5016 with q.indent(2):
5017 q.breakable()
5018 q.text("xid = ");
5019 if self.xid != None:
5020 q.text("%#x" % self.xid)
5021 else:
5022 q.text('None')
5023 q.text(","); q.breakable()
5024 q.text("flags = ");
5025 q.text("%#x" % self.flags)
5026 q.text(","); q.breakable()
5027 q.text("miss_send_len = ");
5028 q.text("%#x" % self.miss_send_len)
5029 q.breakable()
5030 q.text('}')
5031
5032class table_mod(Message):
5033 version = const.OFP_VERSION
5034 type = 22
5035
Rich Lanec2ee4b82013-04-24 17:12:38 -07005036 def __init__(self, xid=None, table_id=None, config=None):
Rich Laneb658ddd2013-03-12 10:15:10 -07005037 self.xid = xid
5038 if table_id != None:
5039 self.table_id = table_id
5040 else:
5041 self.table_id = 0
Rich Laneb658ddd2013-03-12 10:15:10 -07005042 if config != None:
5043 self.config = config
5044 else:
5045 self.config = 0
5046
5047 def pack(self):
5048 packed = []
5049 packed.append(struct.pack("!B", self.version))
5050 packed.append(struct.pack("!B", self.type))
5051 packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
5052 packed.append(struct.pack("!L", self.xid))
5053 packed.append(struct.pack("!B", self.table_id))
Rich Lanec2ee4b82013-04-24 17:12:38 -07005054 packed.append('\x00' * 3)
Rich Laneb658ddd2013-03-12 10:15:10 -07005055 packed.append(struct.pack("!L", self.config))
5056 length = sum([len(x) for x in packed])
5057 packed[2] = struct.pack("!H", length)
5058 return ''.join(packed)
5059
5060 @staticmethod
5061 def unpack(buf):
5062 if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
5063 obj = table_mod()
Rich Lanec2ee4b82013-04-24 17:12:38 -07005064 if type(buf) == loxi.generic_util.OFReader:
5065 reader = buf
5066 else:
5067 reader = loxi.generic_util.OFReader(buf)
5068 _version = reader.read('!B')[0]
5069 assert(_version == const.OFP_VERSION)
5070 _type = reader.read('!B')[0]
5071 assert(_type == 22)
5072 _length = reader.read('!H')[0]
5073 obj.xid = reader.read('!L')[0]
5074 obj.table_id = reader.read('!B')[0]
5075 reader.skip(3)
5076 obj.config = reader.read('!L')[0]
Rich Laneb658ddd2013-03-12 10:15:10 -07005077 return obj
5078
5079 def __eq__(self, other):
5080 if type(self) != type(other): return False
5081 if self.version != other.version: return False
5082 if self.type != other.type: return False
5083 if self.xid != other.xid: return False
5084 if self.table_id != other.table_id: return False
Rich Laneb658ddd2013-03-12 10:15:10 -07005085 if self.config != other.config: return False
5086 return True
5087
5088 def __ne__(self, other):
5089 return not self.__eq__(other)
5090
5091 def __str__(self):
5092 return self.show()
5093
5094 def show(self):
5095 import loxi.pp
5096 return loxi.pp.pp(self)
5097
5098 def pretty_print(self, q):
5099 q.text("table_mod {")
5100 with q.group():
5101 with q.indent(2):
5102 q.breakable()
5103 q.text("xid = ");
5104 if self.xid != None:
5105 q.text("%#x" % self.xid)
5106 else:
5107 q.text('None')
5108 q.text(","); q.breakable()
5109 q.text("table_id = ");
5110 q.text("%#x" % self.table_id)
5111 q.text(","); q.breakable()
Rich Laneb658ddd2013-03-12 10:15:10 -07005112 q.text("config = ");
5113 q.text("%#x" % self.config)
5114 q.breakable()
5115 q.text('}')
5116
5117class table_stats_reply(Message):
5118 version = const.OFP_VERSION
5119 type = const.OFPT_STATS_REPLY
5120 stats_type = const.OFPST_TABLE
5121
5122 def __init__(self, xid=None, flags=None, entries=None):
5123 self.xid = xid
5124 if flags != None:
5125 self.flags = flags
5126 else:
5127 self.flags = 0
5128 if entries != None:
5129 self.entries = entries
5130 else:
5131 self.entries = []
5132
5133 def pack(self):
5134 packed = []
5135 packed.append(struct.pack("!B", self.version))
5136 packed.append(struct.pack("!B", self.type))
5137 packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
5138 packed.append(struct.pack("!L", self.xid))
5139 packed.append(struct.pack("!H", self.stats_type))
5140 packed.append(struct.pack("!H", self.flags))
5141 packed.append("".join([x.pack() for x in self.entries]))
5142 length = sum([len(x) for x in packed])
5143 packed[2] = struct.pack("!H", length)
5144 return ''.join(packed)
5145
5146 @staticmethod
5147 def unpack(buf):
5148 if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
5149 obj = table_stats_reply()
Rich Lanec2ee4b82013-04-24 17:12:38 -07005150 if type(buf) == loxi.generic_util.OFReader:
5151 reader = buf
5152 else:
5153 reader = loxi.generic_util.OFReader(buf)
5154 _version = reader.read('!B')[0]
5155 assert(_version == const.OFP_VERSION)
5156 _type = reader.read('!B')[0]
5157 assert(_type == const.OFPT_STATS_REPLY)
5158 _length = reader.read('!H')[0]
5159 obj.xid = reader.read('!L')[0]
5160 _stats_type = reader.read('!H')[0]
5161 assert(_stats_type == const.OFPST_TABLE)
5162 obj.flags = reader.read('!H')[0]
5163 obj.entries = loxi.generic_util.unpack_list(reader, common.table_stats_entry.unpack)
Rich Laneb658ddd2013-03-12 10:15:10 -07005164 return obj
5165
5166 def __eq__(self, other):
5167 if type(self) != type(other): return False
5168 if self.version != other.version: return False
5169 if self.type != other.type: return False
5170 if self.xid != other.xid: return False
5171 if self.flags != other.flags: return False
5172 if self.entries != other.entries: return False
5173 return True
5174
5175 def __ne__(self, other):
5176 return not self.__eq__(other)
5177
5178 def __str__(self):
5179 return self.show()
5180
5181 def show(self):
5182 import loxi.pp
5183 return loxi.pp.pp(self)
5184
5185 def pretty_print(self, q):
5186 q.text("table_stats_reply {")
5187 with q.group():
5188 with q.indent(2):
5189 q.breakable()
5190 q.text("xid = ");
5191 if self.xid != None:
5192 q.text("%#x" % self.xid)
5193 else:
5194 q.text('None')
5195 q.text(","); q.breakable()
5196 q.text("flags = ");
5197 q.text("%#x" % self.flags)
5198 q.text(","); q.breakable()
5199 q.text("entries = ");
5200 q.pp(self.entries)
5201 q.breakable()
5202 q.text('}')
5203
5204class table_stats_request(Message):
5205 version = const.OFP_VERSION
5206 type = const.OFPT_STATS_REQUEST
5207 stats_type = const.OFPST_TABLE
5208
5209 def __init__(self, xid=None, flags=None):
5210 self.xid = xid
5211 if flags != None:
5212 self.flags = flags
5213 else:
5214 self.flags = 0
5215
5216 def pack(self):
5217 packed = []
5218 packed.append(struct.pack("!B", self.version))
5219 packed.append(struct.pack("!B", self.type))
5220 packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
5221 packed.append(struct.pack("!L", self.xid))
5222 packed.append(struct.pack("!H", self.stats_type))
5223 packed.append(struct.pack("!H", self.flags))
5224 length = sum([len(x) for x in packed])
5225 packed[2] = struct.pack("!H", length)
5226 return ''.join(packed)
5227
5228 @staticmethod
5229 def unpack(buf):
5230 if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
5231 obj = table_stats_request()
Rich Lanec2ee4b82013-04-24 17:12:38 -07005232 if type(buf) == loxi.generic_util.OFReader:
5233 reader = buf
5234 else:
5235 reader = loxi.generic_util.OFReader(buf)
5236 _version = reader.read('!B')[0]
5237 assert(_version == const.OFP_VERSION)
5238 _type = reader.read('!B')[0]
5239 assert(_type == const.OFPT_STATS_REQUEST)
5240 _length = reader.read('!H')[0]
5241 obj.xid = reader.read('!L')[0]
5242 _stats_type = reader.read('!H')[0]
5243 assert(_stats_type == const.OFPST_TABLE)
5244 obj.flags = reader.read('!H')[0]
Rich Laneb658ddd2013-03-12 10:15:10 -07005245 return obj
5246
5247 def __eq__(self, other):
5248 if type(self) != type(other): return False
5249 if self.version != other.version: return False
5250 if self.type != other.type: return False
5251 if self.xid != other.xid: return False
5252 if self.flags != other.flags: return False
5253 return True
5254
5255 def __ne__(self, other):
5256 return not self.__eq__(other)
5257
5258 def __str__(self):
5259 return self.show()
5260
5261 def show(self):
5262 import loxi.pp
5263 return loxi.pp.pp(self)
5264
5265 def pretty_print(self, q):
5266 q.text("table_stats_request {")
5267 with q.group():
5268 with q.indent(2):
5269 q.breakable()
5270 q.text("xid = ");
5271 if self.xid != None:
5272 q.text("%#x" % self.xid)
5273 else:
5274 q.text('None')
5275 q.text(","); q.breakable()
5276 q.text("flags = ");
5277 q.text("%#x" % self.flags)
5278 q.breakable()
5279 q.text('}')
5280
5281
5282def parse_header(buf):
5283 if len(buf) < 8:
5284 raise loxi.ProtocolError("too short to be an OpenFlow message")
5285 return struct.unpack_from("!BBHL", buf)
5286
5287def parse_message(buf):
5288 msg_ver, msg_type, msg_len, msg_xid = parse_header(buf)
5289 if msg_ver != const.OFP_VERSION and msg_type != ofp.OFPT_HELLO:
5290 raise loxi.ProtocolError("wrong OpenFlow version")
5291 if len(buf) != msg_len:
5292 raise loxi.ProtocolError("incorrect message size")
5293 if msg_type in parsers:
5294 return parsers[msg_type](buf)
5295 else:
5296 raise loxi.ProtocolError("unexpected message type")
5297
5298def parse_flow_mod(buf):
5299 if len(buf) < 56 + 2:
5300 raise loxi.ProtocolError("message too short")
5301 cmd, = struct.unpack_from("!H", buf, 56)
5302 if cmd in flow_mod_parsers:
5303 return flow_mod_parsers[cmd](buf)
5304 else:
5305 raise loxi.ProtocolError("unexpected flow mod cmd %u" % cmd)
5306
5307def parse_stats_reply(buf):
5308 if len(buf) < 8 + 2:
5309 raise loxi.ProtocolError("message too short")
5310 stats_type, = struct.unpack_from("!H", buf, 8)
5311 if stats_type in stats_reply_parsers:
5312 return stats_reply_parsers[stats_type](buf)
5313 else:
5314 raise loxi.ProtocolError("unexpected stats type %u" % stats_type)
5315
5316def parse_stats_request(buf):
5317 if len(buf) < 8 + 2:
5318 raise loxi.ProtocolError("message too short")
5319 stats_type, = struct.unpack_from("!H", buf, 8)
5320 if stats_type in stats_request_parsers:
5321 return stats_request_parsers[stats_type](buf)
5322 else:
5323 raise loxi.ProtocolError("unexpected stats type %u" % stats_type)
5324
5325def parse_vendor(buf):
5326 if len(buf) < 16:
5327 raise loxi.ProtocolError("experimenter message too short")
5328
5329 experimenter, = struct.unpack_from("!L", buf, 8)
5330 if experimenter == 0x005c16c7: # Big Switch Networks
5331 subtype, = struct.unpack_from("!L", buf, 12)
5332 elif experimenter == 0x00002320: # Nicira
5333 subtype, = struct.unpack_from("!L", buf, 12)
5334 else:
5335 raise loxi.ProtocolError("unexpected experimenter id %#x" % experimenter)
5336
5337 if subtype in experimenter_parsers[experimenter]:
5338 return experimenter_parsers[experimenter][subtype](buf)
5339 else:
5340 raise loxi.ProtocolError("unexpected experimenter %#x subtype %#x" % (experimenter, subtype))
5341
5342parsers = {
5343 22 : table_mod.unpack,
5344 const.OFPT_BARRIER_REPLY : barrier_reply.unpack,
5345 const.OFPT_BARRIER_REQUEST : barrier_request.unpack,
5346 const.OFPT_ECHO_REPLY : echo_reply.unpack,
5347 const.OFPT_ECHO_REQUEST : echo_request.unpack,
5348 const.OFPT_ERROR : error_msg.unpack,
5349 const.OFPT_FEATURES_REPLY : features_reply.unpack,
5350 const.OFPT_FEATURES_REQUEST : features_request.unpack,
5351 const.OFPT_FLOW_MOD : parse_flow_mod,
5352 const.OFPT_FLOW_REMOVED : flow_removed.unpack,
5353 const.OFPT_GET_CONFIG_REPLY : get_config_reply.unpack,
5354 const.OFPT_GET_CONFIG_REQUEST : get_config_request.unpack,
5355 const.OFPT_HELLO : hello.unpack,
5356 const.OFPT_PACKET_IN : packet_in.unpack,
5357 const.OFPT_PACKET_OUT : packet_out.unpack,
5358 const.OFPT_PORT_MOD : port_mod.unpack,
5359 const.OFPT_PORT_STATUS : port_status.unpack,
5360 const.OFPT_QUEUE_GET_CONFIG_REPLY : queue_get_config_reply.unpack,
5361 const.OFPT_QUEUE_GET_CONFIG_REQUEST : queue_get_config_request.unpack,
5362 const.OFPT_SET_CONFIG : set_config.unpack,
5363 const.OFPT_STATS_REPLY : parse_stats_reply,
5364 const.OFPT_STATS_REQUEST : parse_stats_request,
5365 const.OFPT_VENDOR : parse_vendor,
5366}
5367
5368flow_mod_parsers = {
5369 const.OFPFC_ADD : flow_add.unpack,
5370 const.OFPFC_MODIFY : flow_modify.unpack,
5371 const.OFPFC_MODIFY_STRICT : flow_modify_strict.unpack,
5372 const.OFPFC_DELETE : flow_delete.unpack,
5373 const.OFPFC_DELETE_STRICT : flow_delete_strict.unpack,
5374}
5375
5376stats_reply_parsers = {
5377 const.OFPST_DESC : desc_stats_reply.unpack,
5378 const.OFPST_FLOW : flow_stats_reply.unpack,
5379 const.OFPST_AGGREGATE : aggregate_stats_reply.unpack,
5380 const.OFPST_TABLE : table_stats_reply.unpack,
5381 const.OFPST_PORT : port_stats_reply.unpack,
5382 const.OFPST_QUEUE : queue_stats_reply.unpack,
5383 const.OFPST_VENDOR : experimenter_stats_reply.unpack,
5384}
5385
5386stats_request_parsers = {
5387 const.OFPST_DESC : desc_stats_request.unpack,
5388 const.OFPST_FLOW : flow_stats_request.unpack,
5389 const.OFPST_AGGREGATE : aggregate_stats_request.unpack,
5390 const.OFPST_TABLE : table_stats_request.unpack,
5391 const.OFPST_PORT : port_stats_request.unpack,
5392 const.OFPST_QUEUE : queue_stats_request.unpack,
5393 const.OFPST_VENDOR : experimenter_stats_request.unpack,
5394}
5395
5396experimenter_parsers = {
5397 0x2320 : {
5398 11: nicira_controller_role_reply.unpack,
5399 10: nicira_controller_role_request.unpack,
5400 },
5401 0x5c16c7 : {
5402 10: bsn_get_interfaces_reply.unpack,
5403 9: bsn_get_interfaces_request.unpack,
5404 2: bsn_get_ip_mask_reply.unpack,
5405 1: bsn_get_ip_mask_request.unpack,
Rich Lane90c961c2013-05-14 09:26:50 -07005406 14: bsn_get_l2_table_reply.unpack,
5407 13: bsn_get_l2_table_request.unpack,
Rich Laneb658ddd2013-03-12 10:15:10 -07005408 5: bsn_get_mirroring_reply.unpack,
5409 4: bsn_get_mirroring_request.unpack,
5410 0: bsn_set_ip_mask.unpack,
Rich Lane90c961c2013-05-14 09:26:50 -07005411 12: bsn_set_l2_table.unpack,
Rich Laneb658ddd2013-03-12 10:15:10 -07005412 3: bsn_set_mirroring.unpack,
Rich Lanec2ee4b82013-04-24 17:12:38 -07005413 11: bsn_set_pktin_suppression.unpack,
Rich Laneb658ddd2013-03-12 10:15:10 -07005414 6: bsn_shell_command.unpack,
5415 7: bsn_shell_output.unpack,
5416 8: bsn_shell_status.unpack,
5417 },
5418}