import pyloxi @ 39ed7a3
diff --git a/src/python/loxi/of10/__init__.py b/src/python/loxi/of10/__init__.py
new file mode 100644
index 0000000..9b3bf53
--- /dev/null
+++ b/src/python/loxi/of10/__init__.py
@@ -0,0 +1,22 @@
+#
+# Copyright 2012, 2013, Big Switch Networks, Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+
+# Automatically generated by LOXI from template init.py
+# Do not modify
+
+import action, common, const, message
+from const import *
+from common import *
+from loxi import ProtocolError
diff --git a/src/python/loxi/of10/action.py b/src/python/loxi/of10/action.py
new file mode 100644
index 0000000..c6129a5
--- /dev/null
+++ b/src/python/loxi/of10/action.py
@@ -0,0 +1,1029 @@
+#
+# Copyright 2012, 2013, Big Switch Networks, Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+
+# Automatically generated by LOXI from template action.py
+# Do not modify
+
+import struct
+import const
+import util
+import loxi
+
+def unpack_list(buf):
+ if len(buf) % 8 != 0: raise loxi.ProtocolError("action list length not a multiple of 8")
+ actions = []
+ offset = 0
+ while offset < len(buf):
+ type, length = struct.unpack_from("!HH", buf, offset)
+ if length == 0: raise loxi.ProtocolError("action length is 0")
+ if length % 8 != 0: raise loxi.ProtocolError("action length not a multiple of 8")
+ if offset + length > len(buf): raise loxi.ProtocolError("action length overruns list length")
+ parser = parsers.get(type)
+ if not parser: raise loxi.ProtocolError("unknown action type %d" % type)
+ actions.append(parser(buffer(buf, offset, length)))
+ offset += length
+ return actions
+
+class Action(object):
+ type = None # override in subclass
+ pass
+
+class bsn_mirror(Action):
+ type = const.OFPAT_VENDOR
+ experimenter = 0x5c16c7
+ subtype = 1
+
+ def __init__(self, dest_port=None, vlan_tag=None, copy_stage=None, pad=None):
+ if dest_port != None:
+ self.dest_port = dest_port
+ else:
+ self.dest_port = 0
+ if vlan_tag != None:
+ self.vlan_tag = vlan_tag
+ else:
+ self.vlan_tag = 0
+ if copy_stage != None:
+ self.copy_stage = copy_stage
+ else:
+ self.copy_stage = 0
+ if pad != None:
+ self.pad = pad
+ else:
+ self.pad = [0,0,0]
+
+ def pack(self):
+ packed = []
+ packed.append(struct.pack("!H", self.type))
+ packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
+ packed.append(struct.pack("!L", self.experimenter))
+ packed.append(struct.pack("!L", self.subtype))
+ packed.append(struct.pack("!L", self.dest_port))
+ packed.append(struct.pack("!L", self.vlan_tag))
+ packed.append(struct.pack("!B", self.copy_stage))
+ packed.append(struct.pack("!3B", *self.pad))
+ length = sum([len(x) for x in packed])
+ packed[1] = struct.pack("!H", length)
+ return ''.join(packed)
+
+ @staticmethod
+ def unpack(buf):
+ obj = bsn_mirror()
+ type = struct.unpack_from('!H', buf, 0)[0]
+ assert(type == const.OFPAT_VENDOR)
+ _length = struct.unpack_from('!H', buf, 2)[0]
+ assert(_length == len(buf))
+ if _length != 24: raise loxi.ProtocolError("bsn_mirror length is %d, should be 24" % _length)
+ experimenter = struct.unpack_from('!L', buf, 4)[0]
+ assert(experimenter == 0x5c16c7)
+ subtype = struct.unpack_from('!L', buf, 8)[0]
+ assert(subtype == 1)
+ obj.dest_port = struct.unpack_from('!L', buf, 12)[0]
+ obj.vlan_tag = struct.unpack_from('!L', buf, 16)[0]
+ obj.copy_stage = struct.unpack_from('!B', buf, 20)[0]
+ obj.pad = list(struct.unpack_from('!3B', buf, 21))
+ return obj
+
+ def __eq__(self, other):
+ if type(self) != type(other): return False
+ if self.type != other.type: return False
+ if self.dest_port != other.dest_port: return False
+ if self.vlan_tag != other.vlan_tag: return False
+ if self.copy_stage != other.copy_stage: return False
+ if self.pad != other.pad: return False
+ return True
+
+ def __ne__(self, other):
+ return not self.__eq__(other)
+
+ def show(self):
+ import loxi.pp
+ return loxi.pp.pp(self)
+
+ def pretty_print(self, q):
+ q.text("bsn_mirror {")
+ with q.group():
+ with q.indent(2):
+ q.breakable()
+ q.text("dest_port = ");
+ q.text("%#x" % self.dest_port)
+ q.text(","); q.breakable()
+ q.text("vlan_tag = ");
+ q.text("%#x" % self.vlan_tag)
+ q.text(","); q.breakable()
+ q.text("copy_stage = ");
+ q.text("%#x" % self.copy_stage)
+ q.text(","); q.breakable()
+ q.text("pad = ");
+ q.pp(self.pad)
+ q.breakable()
+ q.text('}')
+
+class bsn_set_tunnel_dst(Action):
+ type = const.OFPAT_VENDOR
+ experimenter = 0x5c16c7
+ subtype = 2
+
+ def __init__(self, dst=None):
+ if dst != None:
+ self.dst = dst
+ else:
+ self.dst = 0
+
+ def pack(self):
+ packed = []
+ packed.append(struct.pack("!H", self.type))
+ packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
+ packed.append(struct.pack("!L", self.experimenter))
+ packed.append(struct.pack("!L", self.subtype))
+ packed.append(struct.pack("!L", self.dst))
+ length = sum([len(x) for x in packed])
+ packed[1] = struct.pack("!H", length)
+ return ''.join(packed)
+
+ @staticmethod
+ def unpack(buf):
+ obj = bsn_set_tunnel_dst()
+ type = struct.unpack_from('!H', buf, 0)[0]
+ assert(type == const.OFPAT_VENDOR)
+ _length = struct.unpack_from('!H', buf, 2)[0]
+ assert(_length == len(buf))
+ if _length != 16: raise loxi.ProtocolError("bsn_set_tunnel_dst length is %d, should be 16" % _length)
+ experimenter = struct.unpack_from('!L', buf, 4)[0]
+ assert(experimenter == 0x5c16c7)
+ subtype = struct.unpack_from('!L', buf, 8)[0]
+ assert(subtype == 2)
+ obj.dst = struct.unpack_from('!L', buf, 12)[0]
+ return obj
+
+ def __eq__(self, other):
+ if type(self) != type(other): return False
+ if self.type != other.type: return False
+ if self.dst != other.dst: return False
+ return True
+
+ def __ne__(self, other):
+ return not self.__eq__(other)
+
+ def show(self):
+ import loxi.pp
+ return loxi.pp.pp(self)
+
+ def pretty_print(self, q):
+ q.text("bsn_set_tunnel_dst {")
+ with q.group():
+ with q.indent(2):
+ q.breakable()
+ q.text("dst = ");
+ q.text("%#x" % self.dst)
+ q.breakable()
+ q.text('}')
+
+class enqueue(Action):
+ type = const.OFPAT_ENQUEUE
+
+ def __init__(self, port=None, pad=None, queue_id=None):
+ if port != None:
+ self.port = port
+ else:
+ self.port = 0
+ if pad != None:
+ self.pad = pad
+ else:
+ self.pad = [0,0,0,0,0,0]
+ if queue_id != None:
+ self.queue_id = queue_id
+ else:
+ self.queue_id = 0
+
+ def pack(self):
+ packed = []
+ packed.append(struct.pack("!H", self.type))
+ packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
+ packed.append(struct.pack("!H", self.port))
+ packed.append(struct.pack("!6B", *self.pad))
+ packed.append(struct.pack("!L", self.queue_id))
+ length = sum([len(x) for x in packed])
+ packed[1] = struct.pack("!H", length)
+ return ''.join(packed)
+
+ @staticmethod
+ def unpack(buf):
+ obj = enqueue()
+ type = struct.unpack_from('!H', buf, 0)[0]
+ assert(type == const.OFPAT_ENQUEUE)
+ _length = struct.unpack_from('!H', buf, 2)[0]
+ assert(_length == len(buf))
+ if _length != 16: raise loxi.ProtocolError("enqueue length is %d, should be 16" % _length)
+ obj.port = struct.unpack_from('!H', buf, 4)[0]
+ obj.pad = list(struct.unpack_from('!6B', buf, 6))
+ obj.queue_id = struct.unpack_from('!L', buf, 12)[0]
+ return obj
+
+ def __eq__(self, other):
+ if type(self) != type(other): return False
+ if self.type != other.type: return False
+ if self.port != other.port: return False
+ if self.pad != other.pad: return False
+ if self.queue_id != other.queue_id: return False
+ return True
+
+ def __ne__(self, other):
+ return not self.__eq__(other)
+
+ def show(self):
+ import loxi.pp
+ return loxi.pp.pp(self)
+
+ def pretty_print(self, q):
+ q.text("enqueue {")
+ with q.group():
+ with q.indent(2):
+ q.breakable()
+ q.text("port = ");
+ q.text(util.pretty_port(self.port))
+ q.text(","); q.breakable()
+ q.text("pad = ");
+ q.pp(self.pad)
+ q.text(","); q.breakable()
+ q.text("queue_id = ");
+ q.text("%#x" % self.queue_id)
+ q.breakable()
+ q.text('}')
+
+class nicira_dec_ttl(Action):
+ type = const.OFPAT_VENDOR
+ experimenter = 0x2320
+ subtype = 18
+
+ def __init__(self, pad=None, pad2=None):
+ if pad != None:
+ self.pad = pad
+ else:
+ self.pad = 0
+ if pad2 != None:
+ self.pad2 = pad2
+ else:
+ self.pad2 = 0
+
+ def pack(self):
+ packed = []
+ packed.append(struct.pack("!H", self.type))
+ packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
+ packed.append(struct.pack("!L", self.experimenter))
+ packed.append(struct.pack("!H", self.subtype))
+ packed.append(struct.pack("!H", self.pad))
+ packed.append(struct.pack("!L", self.pad2))
+ length = sum([len(x) for x in packed])
+ packed[1] = struct.pack("!H", length)
+ return ''.join(packed)
+
+ @staticmethod
+ def unpack(buf):
+ obj = nicira_dec_ttl()
+ type = struct.unpack_from('!H', buf, 0)[0]
+ assert(type == const.OFPAT_VENDOR)
+ _length = struct.unpack_from('!H', buf, 2)[0]
+ assert(_length == len(buf))
+ if _length != 16: raise loxi.ProtocolError("nicira_dec_ttl length is %d, should be 16" % _length)
+ experimenter = struct.unpack_from('!L', buf, 4)[0]
+ assert(experimenter == 0x2320)
+ subtype = struct.unpack_from('!H', buf, 8)[0]
+ assert(subtype == 18)
+ obj.pad = struct.unpack_from('!H', buf, 10)[0]
+ obj.pad2 = struct.unpack_from('!L', buf, 12)[0]
+ return obj
+
+ def __eq__(self, other):
+ if type(self) != type(other): return False
+ if self.type != other.type: return False
+ if self.pad != other.pad: return False
+ if self.pad2 != other.pad2: return False
+ return True
+
+ def __ne__(self, other):
+ return not self.__eq__(other)
+
+ def show(self):
+ import loxi.pp
+ return loxi.pp.pp(self)
+
+ def pretty_print(self, q):
+ q.text("nicira_dec_ttl {")
+ with q.group():
+ with q.indent(2):
+ q.breakable()
+ q.text("pad = ");
+ q.text("%#x" % self.pad)
+ q.text(","); q.breakable()
+ q.text("pad2 = ");
+ q.text("%#x" % self.pad2)
+ q.breakable()
+ q.text('}')
+
+class output(Action):
+ type = const.OFPAT_OUTPUT
+
+ def __init__(self, port=None, max_len=None):
+ if port != None:
+ self.port = port
+ else:
+ self.port = 0
+ if max_len != None:
+ self.max_len = max_len
+ else:
+ self.max_len = 0
+
+ def pack(self):
+ packed = []
+ packed.append(struct.pack("!H", self.type))
+ packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
+ packed.append(struct.pack("!H", self.port))
+ packed.append(struct.pack("!H", self.max_len))
+ length = sum([len(x) for x in packed])
+ packed[1] = struct.pack("!H", length)
+ return ''.join(packed)
+
+ @staticmethod
+ def unpack(buf):
+ obj = output()
+ type = struct.unpack_from('!H', buf, 0)[0]
+ assert(type == const.OFPAT_OUTPUT)
+ _length = struct.unpack_from('!H', buf, 2)[0]
+ assert(_length == len(buf))
+ if _length != 8: raise loxi.ProtocolError("output length is %d, should be 8" % _length)
+ obj.port = struct.unpack_from('!H', buf, 4)[0]
+ obj.max_len = struct.unpack_from('!H', buf, 6)[0]
+ return obj
+
+ def __eq__(self, other):
+ if type(self) != type(other): return False
+ if self.type != other.type: return False
+ if self.port != other.port: return False
+ if self.max_len != other.max_len: return False
+ return True
+
+ def __ne__(self, other):
+ return not self.__eq__(other)
+
+ def show(self):
+ import loxi.pp
+ return loxi.pp.pp(self)
+
+ def pretty_print(self, q):
+ q.text("output {")
+ with q.group():
+ with q.indent(2):
+ q.breakable()
+ q.text("port = ");
+ q.text(util.pretty_port(self.port))
+ q.text(","); q.breakable()
+ q.text("max_len = ");
+ q.text("%#x" % self.max_len)
+ q.breakable()
+ q.text('}')
+
+class set_dl_dst(Action):
+ type = const.OFPAT_SET_DL_DST
+
+ def __init__(self, dl_addr=None, pad=None):
+ if dl_addr != None:
+ self.dl_addr = dl_addr
+ else:
+ self.dl_addr = [0,0,0,0,0,0]
+ if pad != None:
+ self.pad = pad
+ else:
+ self.pad = [0,0,0,0,0,0]
+
+ def pack(self):
+ packed = []
+ packed.append(struct.pack("!H", self.type))
+ packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
+ packed.append(struct.pack("!6B", *self.dl_addr))
+ packed.append(struct.pack("!6B", *self.pad))
+ length = sum([len(x) for x in packed])
+ packed[1] = struct.pack("!H", length)
+ return ''.join(packed)
+
+ @staticmethod
+ def unpack(buf):
+ obj = set_dl_dst()
+ type = struct.unpack_from('!H', buf, 0)[0]
+ assert(type == const.OFPAT_SET_DL_DST)
+ _length = struct.unpack_from('!H', buf, 2)[0]
+ assert(_length == len(buf))
+ if _length != 16: raise loxi.ProtocolError("set_dl_dst length is %d, should be 16" % _length)
+ obj.dl_addr = list(struct.unpack_from('!6B', buf, 4))
+ obj.pad = list(struct.unpack_from('!6B', buf, 10))
+ return obj
+
+ def __eq__(self, other):
+ if type(self) != type(other): return False
+ if self.type != other.type: return False
+ if self.dl_addr != other.dl_addr: return False
+ if self.pad != other.pad: return False
+ return True
+
+ def __ne__(self, other):
+ return not self.__eq__(other)
+
+ def show(self):
+ import loxi.pp
+ return loxi.pp.pp(self)
+
+ def pretty_print(self, q):
+ q.text("set_dl_dst {")
+ with q.group():
+ with q.indent(2):
+ q.breakable()
+ q.text("dl_addr = ");
+ q.text(util.pretty_mac(self.dl_addr))
+ q.text(","); q.breakable()
+ q.text("pad = ");
+ q.pp(self.pad)
+ q.breakable()
+ q.text('}')
+
+class set_dl_src(Action):
+ type = const.OFPAT_SET_DL_SRC
+
+ def __init__(self, dl_addr=None, pad=None):
+ if dl_addr != None:
+ self.dl_addr = dl_addr
+ else:
+ self.dl_addr = [0,0,0,0,0,0]
+ if pad != None:
+ self.pad = pad
+ else:
+ self.pad = [0,0,0,0,0,0]
+
+ def pack(self):
+ packed = []
+ packed.append(struct.pack("!H", self.type))
+ packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
+ packed.append(struct.pack("!6B", *self.dl_addr))
+ packed.append(struct.pack("!6B", *self.pad))
+ length = sum([len(x) for x in packed])
+ packed[1] = struct.pack("!H", length)
+ return ''.join(packed)
+
+ @staticmethod
+ def unpack(buf):
+ obj = set_dl_src()
+ type = struct.unpack_from('!H', buf, 0)[0]
+ assert(type == const.OFPAT_SET_DL_SRC)
+ _length = struct.unpack_from('!H', buf, 2)[0]
+ assert(_length == len(buf))
+ if _length != 16: raise loxi.ProtocolError("set_dl_src length is %d, should be 16" % _length)
+ obj.dl_addr = list(struct.unpack_from('!6B', buf, 4))
+ obj.pad = list(struct.unpack_from('!6B', buf, 10))
+ return obj
+
+ def __eq__(self, other):
+ if type(self) != type(other): return False
+ if self.type != other.type: return False
+ if self.dl_addr != other.dl_addr: return False
+ if self.pad != other.pad: return False
+ return True
+
+ def __ne__(self, other):
+ return not self.__eq__(other)
+
+ def show(self):
+ import loxi.pp
+ return loxi.pp.pp(self)
+
+ def pretty_print(self, q):
+ q.text("set_dl_src {")
+ with q.group():
+ with q.indent(2):
+ q.breakable()
+ q.text("dl_addr = ");
+ q.text(util.pretty_mac(self.dl_addr))
+ q.text(","); q.breakable()
+ q.text("pad = ");
+ q.pp(self.pad)
+ q.breakable()
+ q.text('}')
+
+class set_nw_dst(Action):
+ type = const.OFPAT_SET_NW_DST
+
+ def __init__(self, nw_addr=None):
+ if nw_addr != None:
+ self.nw_addr = nw_addr
+ else:
+ self.nw_addr = 0
+
+ def pack(self):
+ packed = []
+ packed.append(struct.pack("!H", self.type))
+ packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
+ packed.append(struct.pack("!L", self.nw_addr))
+ length = sum([len(x) for x in packed])
+ packed[1] = struct.pack("!H", length)
+ return ''.join(packed)
+
+ @staticmethod
+ def unpack(buf):
+ obj = set_nw_dst()
+ type = struct.unpack_from('!H', buf, 0)[0]
+ assert(type == const.OFPAT_SET_NW_DST)
+ _length = struct.unpack_from('!H', buf, 2)[0]
+ assert(_length == len(buf))
+ if _length != 8: raise loxi.ProtocolError("set_nw_dst length is %d, should be 8" % _length)
+ obj.nw_addr = struct.unpack_from('!L', buf, 4)[0]
+ return obj
+
+ def __eq__(self, other):
+ if type(self) != type(other): return False
+ if self.type != other.type: return False
+ if self.nw_addr != other.nw_addr: return False
+ return True
+
+ def __ne__(self, other):
+ return not self.__eq__(other)
+
+ def show(self):
+ import loxi.pp
+ return loxi.pp.pp(self)
+
+ def pretty_print(self, q):
+ q.text("set_nw_dst {")
+ with q.group():
+ with q.indent(2):
+ q.breakable()
+ q.text("nw_addr = ");
+ q.text("%#x" % self.nw_addr)
+ q.breakable()
+ q.text('}')
+
+class set_nw_src(Action):
+ type = const.OFPAT_SET_NW_SRC
+
+ def __init__(self, nw_addr=None):
+ if nw_addr != None:
+ self.nw_addr = nw_addr
+ else:
+ self.nw_addr = 0
+
+ def pack(self):
+ packed = []
+ packed.append(struct.pack("!H", self.type))
+ packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
+ packed.append(struct.pack("!L", self.nw_addr))
+ length = sum([len(x) for x in packed])
+ packed[1] = struct.pack("!H", length)
+ return ''.join(packed)
+
+ @staticmethod
+ def unpack(buf):
+ obj = set_nw_src()
+ type = struct.unpack_from('!H', buf, 0)[0]
+ assert(type == const.OFPAT_SET_NW_SRC)
+ _length = struct.unpack_from('!H', buf, 2)[0]
+ assert(_length == len(buf))
+ if _length != 8: raise loxi.ProtocolError("set_nw_src length is %d, should be 8" % _length)
+ obj.nw_addr = struct.unpack_from('!L', buf, 4)[0]
+ return obj
+
+ def __eq__(self, other):
+ if type(self) != type(other): return False
+ if self.type != other.type: return False
+ if self.nw_addr != other.nw_addr: return False
+ return True
+
+ def __ne__(self, other):
+ return not self.__eq__(other)
+
+ def show(self):
+ import loxi.pp
+ return loxi.pp.pp(self)
+
+ def pretty_print(self, q):
+ q.text("set_nw_src {")
+ with q.group():
+ with q.indent(2):
+ q.breakable()
+ q.text("nw_addr = ");
+ q.text("%#x" % self.nw_addr)
+ q.breakable()
+ q.text('}')
+
+class set_nw_tos(Action):
+ type = const.OFPAT_SET_NW_TOS
+
+ def __init__(self, nw_tos=None, pad=None):
+ if nw_tos != None:
+ self.nw_tos = nw_tos
+ else:
+ self.nw_tos = 0
+ if pad != None:
+ self.pad = pad
+ else:
+ self.pad = [0,0,0]
+
+ def pack(self):
+ packed = []
+ packed.append(struct.pack("!H", self.type))
+ packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
+ packed.append(struct.pack("!B", self.nw_tos))
+ packed.append(struct.pack("!3B", *self.pad))
+ length = sum([len(x) for x in packed])
+ packed[1] = struct.pack("!H", length)
+ return ''.join(packed)
+
+ @staticmethod
+ def unpack(buf):
+ obj = set_nw_tos()
+ type = struct.unpack_from('!H', buf, 0)[0]
+ assert(type == const.OFPAT_SET_NW_TOS)
+ _length = struct.unpack_from('!H', buf, 2)[0]
+ assert(_length == len(buf))
+ if _length != 8: raise loxi.ProtocolError("set_nw_tos length is %d, should be 8" % _length)
+ obj.nw_tos = struct.unpack_from('!B', buf, 4)[0]
+ obj.pad = list(struct.unpack_from('!3B', buf, 5))
+ return obj
+
+ def __eq__(self, other):
+ if type(self) != type(other): return False
+ if self.type != other.type: return False
+ if self.nw_tos != other.nw_tos: return False
+ if self.pad != other.pad: return False
+ return True
+
+ def __ne__(self, other):
+ return not self.__eq__(other)
+
+ def show(self):
+ import loxi.pp
+ return loxi.pp.pp(self)
+
+ def pretty_print(self, q):
+ q.text("set_nw_tos {")
+ with q.group():
+ with q.indent(2):
+ q.breakable()
+ q.text("nw_tos = ");
+ q.text("%#x" % self.nw_tos)
+ q.text(","); q.breakable()
+ q.text("pad = ");
+ q.pp(self.pad)
+ q.breakable()
+ q.text('}')
+
+class set_tp_dst(Action):
+ type = const.OFPAT_SET_TP_DST
+
+ def __init__(self, tp_port=None, pad=None):
+ if tp_port != None:
+ self.tp_port = tp_port
+ else:
+ self.tp_port = 0
+ if pad != None:
+ self.pad = pad
+ else:
+ self.pad = [0,0]
+
+ def pack(self):
+ packed = []
+ packed.append(struct.pack("!H", self.type))
+ packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
+ packed.append(struct.pack("!H", self.tp_port))
+ packed.append(struct.pack("!2B", *self.pad))
+ length = sum([len(x) for x in packed])
+ packed[1] = struct.pack("!H", length)
+ return ''.join(packed)
+
+ @staticmethod
+ def unpack(buf):
+ obj = set_tp_dst()
+ type = struct.unpack_from('!H', buf, 0)[0]
+ assert(type == const.OFPAT_SET_TP_DST)
+ _length = struct.unpack_from('!H', buf, 2)[0]
+ assert(_length == len(buf))
+ if _length != 8: raise loxi.ProtocolError("set_tp_dst length is %d, should be 8" % _length)
+ obj.tp_port = struct.unpack_from('!H', buf, 4)[0]
+ obj.pad = list(struct.unpack_from('!2B', buf, 6))
+ return obj
+
+ def __eq__(self, other):
+ if type(self) != type(other): return False
+ if self.type != other.type: return False
+ if self.tp_port != other.tp_port: return False
+ if self.pad != other.pad: return False
+ return True
+
+ def __ne__(self, other):
+ return not self.__eq__(other)
+
+ def show(self):
+ import loxi.pp
+ return loxi.pp.pp(self)
+
+ def pretty_print(self, q):
+ q.text("set_tp_dst {")
+ with q.group():
+ with q.indent(2):
+ q.breakable()
+ q.text("tp_port = ");
+ q.text("%#x" % self.tp_port)
+ q.text(","); q.breakable()
+ q.text("pad = ");
+ q.pp(self.pad)
+ q.breakable()
+ q.text('}')
+
+class set_tp_src(Action):
+ type = const.OFPAT_SET_TP_SRC
+
+ def __init__(self, tp_port=None, pad=None):
+ if tp_port != None:
+ self.tp_port = tp_port
+ else:
+ self.tp_port = 0
+ if pad != None:
+ self.pad = pad
+ else:
+ self.pad = [0,0]
+
+ def pack(self):
+ packed = []
+ packed.append(struct.pack("!H", self.type))
+ packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
+ packed.append(struct.pack("!H", self.tp_port))
+ packed.append(struct.pack("!2B", *self.pad))
+ length = sum([len(x) for x in packed])
+ packed[1] = struct.pack("!H", length)
+ return ''.join(packed)
+
+ @staticmethod
+ def unpack(buf):
+ obj = set_tp_src()
+ type = struct.unpack_from('!H', buf, 0)[0]
+ assert(type == const.OFPAT_SET_TP_SRC)
+ _length = struct.unpack_from('!H', buf, 2)[0]
+ assert(_length == len(buf))
+ if _length != 8: raise loxi.ProtocolError("set_tp_src length is %d, should be 8" % _length)
+ obj.tp_port = struct.unpack_from('!H', buf, 4)[0]
+ obj.pad = list(struct.unpack_from('!2B', buf, 6))
+ return obj
+
+ def __eq__(self, other):
+ if type(self) != type(other): return False
+ if self.type != other.type: return False
+ if self.tp_port != other.tp_port: return False
+ if self.pad != other.pad: return False
+ return True
+
+ def __ne__(self, other):
+ return not self.__eq__(other)
+
+ def show(self):
+ import loxi.pp
+ return loxi.pp.pp(self)
+
+ def pretty_print(self, q):
+ q.text("set_tp_src {")
+ with q.group():
+ with q.indent(2):
+ q.breakable()
+ q.text("tp_port = ");
+ q.text("%#x" % self.tp_port)
+ q.text(","); q.breakable()
+ q.text("pad = ");
+ q.pp(self.pad)
+ q.breakable()
+ q.text('}')
+
+class set_vlan_pcp(Action):
+ type = const.OFPAT_SET_VLAN_PCP
+
+ def __init__(self, vlan_pcp=None, pad=None):
+ if vlan_pcp != None:
+ self.vlan_pcp = vlan_pcp
+ else:
+ self.vlan_pcp = 0
+ if pad != None:
+ self.pad = pad
+ else:
+ self.pad = [0,0,0]
+
+ def pack(self):
+ packed = []
+ packed.append(struct.pack("!H", self.type))
+ packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
+ packed.append(struct.pack("!B", self.vlan_pcp))
+ packed.append(struct.pack("!3B", *self.pad))
+ length = sum([len(x) for x in packed])
+ packed[1] = struct.pack("!H", length)
+ return ''.join(packed)
+
+ @staticmethod
+ def unpack(buf):
+ obj = set_vlan_pcp()
+ type = struct.unpack_from('!H', buf, 0)[0]
+ assert(type == const.OFPAT_SET_VLAN_PCP)
+ _length = struct.unpack_from('!H', buf, 2)[0]
+ assert(_length == len(buf))
+ if _length != 8: raise loxi.ProtocolError("set_vlan_pcp length is %d, should be 8" % _length)
+ obj.vlan_pcp = struct.unpack_from('!B', buf, 4)[0]
+ obj.pad = list(struct.unpack_from('!3B', buf, 5))
+ return obj
+
+ def __eq__(self, other):
+ if type(self) != type(other): return False
+ if self.type != other.type: return False
+ if self.vlan_pcp != other.vlan_pcp: return False
+ if self.pad != other.pad: return False
+ return True
+
+ def __ne__(self, other):
+ return not self.__eq__(other)
+
+ def show(self):
+ import loxi.pp
+ return loxi.pp.pp(self)
+
+ def pretty_print(self, q):
+ q.text("set_vlan_pcp {")
+ with q.group():
+ with q.indent(2):
+ q.breakable()
+ q.text("vlan_pcp = ");
+ q.text("%#x" % self.vlan_pcp)
+ q.text(","); q.breakable()
+ q.text("pad = ");
+ q.pp(self.pad)
+ q.breakable()
+ q.text('}')
+
+class set_vlan_vid(Action):
+ type = const.OFPAT_SET_VLAN_VID
+
+ def __init__(self, vlan_vid=None, pad=None):
+ if vlan_vid != None:
+ self.vlan_vid = vlan_vid
+ else:
+ self.vlan_vid = 0
+ if pad != None:
+ self.pad = pad
+ else:
+ self.pad = [0,0]
+
+ def pack(self):
+ packed = []
+ packed.append(struct.pack("!H", self.type))
+ packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
+ packed.append(struct.pack("!H", self.vlan_vid))
+ packed.append(struct.pack("!2B", *self.pad))
+ length = sum([len(x) for x in packed])
+ packed[1] = struct.pack("!H", length)
+ return ''.join(packed)
+
+ @staticmethod
+ def unpack(buf):
+ obj = set_vlan_vid()
+ type = struct.unpack_from('!H', buf, 0)[0]
+ assert(type == const.OFPAT_SET_VLAN_VID)
+ _length = struct.unpack_from('!H', buf, 2)[0]
+ assert(_length == len(buf))
+ if _length != 8: raise loxi.ProtocolError("set_vlan_vid length is %d, should be 8" % _length)
+ obj.vlan_vid = struct.unpack_from('!H', buf, 4)[0]
+ obj.pad = list(struct.unpack_from('!2B', buf, 6))
+ return obj
+
+ def __eq__(self, other):
+ if type(self) != type(other): return False
+ if self.type != other.type: return False
+ if self.vlan_vid != other.vlan_vid: return False
+ if self.pad != other.pad: return False
+ return True
+
+ def __ne__(self, other):
+ return not self.__eq__(other)
+
+ def show(self):
+ import loxi.pp
+ return loxi.pp.pp(self)
+
+ def pretty_print(self, q):
+ q.text("set_vlan_vid {")
+ with q.group():
+ with q.indent(2):
+ q.breakable()
+ q.text("vlan_vid = ");
+ q.text("%#x" % self.vlan_vid)
+ q.text(","); q.breakable()
+ q.text("pad = ");
+ q.pp(self.pad)
+ q.breakable()
+ q.text('}')
+
+class strip_vlan(Action):
+ type = const.OFPAT_STRIP_VLAN
+
+ def __init__(self, pad=None):
+ if pad != None:
+ self.pad = pad
+ else:
+ self.pad = [0,0,0,0]
+
+ def pack(self):
+ packed = []
+ packed.append(struct.pack("!H", self.type))
+ packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
+ packed.append(struct.pack("!4B", *self.pad))
+ length = sum([len(x) for x in packed])
+ packed[1] = struct.pack("!H", length)
+ return ''.join(packed)
+
+ @staticmethod
+ def unpack(buf):
+ obj = strip_vlan()
+ type = struct.unpack_from('!H', buf, 0)[0]
+ assert(type == const.OFPAT_STRIP_VLAN)
+ _length = struct.unpack_from('!H', buf, 2)[0]
+ assert(_length == len(buf))
+ if _length != 8: raise loxi.ProtocolError("strip_vlan length is %d, should be 8" % _length)
+ obj.pad = list(struct.unpack_from('!4B', buf, 4))
+ return obj
+
+ def __eq__(self, other):
+ if type(self) != type(other): return False
+ if self.type != other.type: return False
+ if self.pad != other.pad: return False
+ return True
+
+ def __ne__(self, other):
+ return not self.__eq__(other)
+
+ def show(self):
+ import loxi.pp
+ return loxi.pp.pp(self)
+
+ def pretty_print(self, q):
+ q.text("strip_vlan {")
+ with q.group():
+ with q.indent(2):
+ q.breakable()
+ q.text("pad = ");
+ q.pp(self.pad)
+ q.breakable()
+ q.text('}')
+
+
+def parse_vendor(buf):
+ if len(buf) < 16:
+ raise loxi.ProtocolError("experimenter action too short")
+
+ experimenter, = struct.unpack_from("!L", buf, 4)
+ if experimenter == 0x005c16c7: # Big Switch Networks
+ subtype, = struct.unpack_from("!L", buf, 8)
+ elif experimenter == 0x00002320: # Nicira
+ subtype, = struct.unpack_from("!H", buf, 8)
+ else:
+ raise loxi.ProtocolError("unexpected experimenter id %#x" % experimenter)
+
+ if subtype in experimenter_parsers[experimenter]:
+ return experimenter_parsers[experimenter][subtype](buf)
+ else:
+ raise loxi.ProtocolError("unexpected BSN experimenter subtype %#x" % subtype)
+
+parsers = {
+ const.OFPAT_ENQUEUE : enqueue.unpack,
+ const.OFPAT_OUTPUT : output.unpack,
+ const.OFPAT_SET_DL_DST : set_dl_dst.unpack,
+ const.OFPAT_SET_DL_SRC : set_dl_src.unpack,
+ const.OFPAT_SET_NW_DST : set_nw_dst.unpack,
+ const.OFPAT_SET_NW_SRC : set_nw_src.unpack,
+ const.OFPAT_SET_NW_TOS : set_nw_tos.unpack,
+ const.OFPAT_SET_TP_DST : set_tp_dst.unpack,
+ const.OFPAT_SET_TP_SRC : set_tp_src.unpack,
+ const.OFPAT_SET_VLAN_PCP : set_vlan_pcp.unpack,
+ const.OFPAT_SET_VLAN_VID : set_vlan_vid.unpack,
+ const.OFPAT_STRIP_VLAN : strip_vlan.unpack,
+ const.OFPAT_VENDOR : parse_vendor,
+}
+
+experimenter_parsers = {
+ 0x2320 : {
+ 18: nicira_dec_ttl.unpack,
+ },
+ 0x5c16c7 : {
+ 1: bsn_mirror.unpack,
+ 2: bsn_set_tunnel_dst.unpack,
+ },
+}
diff --git a/src/python/loxi/of10/common.py b/src/python/loxi/of10/common.py
new file mode 100644
index 0000000..07c41d0
--- /dev/null
+++ b/src/python/loxi/of10/common.py
@@ -0,0 +1,1136 @@
+#
+# Copyright 2012, 2013, Big Switch Networks, Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+
+# Automatically generated by LOXI from template common.py
+# Do not modify
+
+import sys
+import struct
+import action
+import const
+import util
+
+# HACK make this module visible as 'common' to simplify code generation
+common = sys.modules[__name__]
+
+def unpack_list_flow_stats_entry(buf):
+ entries = []
+ offset = 0
+ while offset < len(buf):
+ length, = struct.unpack_from("!H", buf, offset)
+ if length == 0: raise loxi.ProtocolError("entry length is 0")
+ if offset + length > len(buf): raise loxi.ProtocolError("entry length overruns list length")
+ entries.append(flow_stats_entry.unpack(buffer(buf, offset, length)))
+ offset += length
+ return entries
+
+def unpack_list_queue_prop(buf):
+ entries = []
+ offset = 0
+ while offset < len(buf):
+ type, length, = struct.unpack_from("!HH", buf, offset)
+ if length == 0: raise loxi.ProtocolError("entry length is 0")
+ if offset + length > len(buf): raise loxi.ProtocolError("entry length overruns list length")
+ if type == const.OFPQT_MIN_RATE:
+ entry = queue_prop_min_rate.unpack(buffer(buf, offset, length))
+ else:
+ raise loxi.ProtocolError("unknown queue prop %d" % type)
+ entries.append(entry)
+ offset += length
+ return entries
+
+def unpack_list_packet_queue(buf):
+ entries = []
+ offset = 0
+ while offset < len(buf):
+ _, length, = struct.unpack_from("!LH", buf, offset)
+ if length == 0: raise loxi.ProtocolError("entry length is 0")
+ if offset + length > len(buf): raise loxi.ProtocolError("entry length overruns list length")
+ entries.append(packet_queue.unpack(buffer(buf, offset, length)))
+ offset += length
+ return entries
+
+class bsn_interface(object):
+
+ def __init__(self, hw_addr=None, pad=None, name=None, ipv4_addr=None, ipv4_netmask=None):
+ if hw_addr != None:
+ self.hw_addr = hw_addr
+ else:
+ self.hw_addr = [0,0,0,0,0,0]
+ if pad != None:
+ self.pad = pad
+ else:
+ self.pad = 0
+ if name != None:
+ self.name = name
+ else:
+ self.name = ""
+ if ipv4_addr != None:
+ self.ipv4_addr = ipv4_addr
+ else:
+ self.ipv4_addr = 0
+ if ipv4_netmask != None:
+ self.ipv4_netmask = ipv4_netmask
+ else:
+ self.ipv4_netmask = 0
+
+ def pack(self):
+ packed = []
+ packed.append(struct.pack("!6B", *self.hw_addr))
+ packed.append(struct.pack("!H", self.pad))
+ packed.append(struct.pack("!16s", self.name))
+ packed.append(struct.pack("!L", self.ipv4_addr))
+ packed.append(struct.pack("!L", self.ipv4_netmask))
+ return ''.join(packed)
+
+ @staticmethod
+ def unpack(buf):
+ assert(len(buf) >= 32) # Should be verified by caller
+ obj = bsn_interface()
+ obj.hw_addr = list(struct.unpack_from('!6B', buf, 0))
+ obj.pad = struct.unpack_from('!H', buf, 6)[0]
+ obj.name = str(buffer(buf, 8, 16)).rstrip("\x00")
+ obj.ipv4_addr = struct.unpack_from('!L', buf, 24)[0]
+ obj.ipv4_netmask = struct.unpack_from('!L', buf, 28)[0]
+ return obj
+
+ def __eq__(self, other):
+ if type(self) != type(other): return False
+ if self.hw_addr != other.hw_addr: return False
+ if self.pad != other.pad: return False
+ if self.name != other.name: return False
+ if self.ipv4_addr != other.ipv4_addr: return False
+ if self.ipv4_netmask != other.ipv4_netmask: return False
+ return True
+
+ def __ne__(self, other):
+ return not self.__eq__(other)
+
+ def show(self):
+ import loxi.pp
+ return loxi.pp.pp(self)
+
+ def pretty_print(self, q):
+ q.text("bsn_interface {")
+ with q.group():
+ with q.indent(2):
+ q.breakable()
+ q.text("hw_addr = ");
+ q.text(util.pretty_mac(self.hw_addr))
+ q.text(","); q.breakable()
+ q.text("pad = ");
+ q.text("%#x" % self.pad)
+ q.text(","); q.breakable()
+ q.text("name = ");
+ q.pp(self.name)
+ q.text(","); q.breakable()
+ q.text("ipv4_addr = ");
+ q.text(util.pretty_ipv4(self.ipv4_addr))
+ q.text(","); q.breakable()
+ q.text("ipv4_netmask = ");
+ q.text(util.pretty_ipv4(self.ipv4_netmask))
+ q.breakable()
+ q.text('}')
+
+class flow_stats_entry(object):
+
+ def __init__(self, table_id=None, pad=None, match=None, duration_sec=None, duration_nsec=None, priority=None, idle_timeout=None, hard_timeout=None, pad2=None, cookie=None, packet_count=None, byte_count=None, actions=None):
+ if table_id != None:
+ self.table_id = table_id
+ else:
+ self.table_id = 0
+ if pad != None:
+ self.pad = pad
+ else:
+ self.pad = 0
+ if match != None:
+ self.match = match
+ else:
+ self.match = common.match()
+ if duration_sec != None:
+ self.duration_sec = duration_sec
+ else:
+ self.duration_sec = 0
+ if duration_nsec != None:
+ self.duration_nsec = duration_nsec
+ else:
+ self.duration_nsec = 0
+ if priority != None:
+ self.priority = priority
+ else:
+ self.priority = 0
+ if idle_timeout != None:
+ self.idle_timeout = idle_timeout
+ else:
+ self.idle_timeout = 0
+ if hard_timeout != None:
+ self.hard_timeout = hard_timeout
+ else:
+ self.hard_timeout = 0
+ if pad2 != None:
+ self.pad2 = pad2
+ else:
+ self.pad2 = [0,0,0,0,0,0]
+ if cookie != None:
+ self.cookie = cookie
+ else:
+ self.cookie = 0
+ if packet_count != None:
+ self.packet_count = packet_count
+ else:
+ self.packet_count = 0
+ if byte_count != None:
+ self.byte_count = byte_count
+ else:
+ self.byte_count = 0
+ if actions != None:
+ self.actions = actions
+ else:
+ self.actions = []
+
+ def pack(self):
+ packed = []
+ packed.append(struct.pack("!H", 0)) # placeholder for length at index 0
+ packed.append(struct.pack("!B", self.table_id))
+ packed.append(struct.pack("!B", self.pad))
+ packed.append(self.match.pack())
+ packed.append(struct.pack("!L", self.duration_sec))
+ packed.append(struct.pack("!L", self.duration_nsec))
+ packed.append(struct.pack("!H", self.priority))
+ packed.append(struct.pack("!H", self.idle_timeout))
+ packed.append(struct.pack("!H", self.hard_timeout))
+ packed.append(struct.pack("!6B", *self.pad2))
+ packed.append(struct.pack("!Q", self.cookie))
+ packed.append(struct.pack("!Q", self.packet_count))
+ packed.append(struct.pack("!Q", self.byte_count))
+ packed.append("".join([x.pack() for x in self.actions]))
+ length = sum([len(x) for x in packed])
+ packed[0] = struct.pack("!H", length)
+ return ''.join(packed)
+
+ @staticmethod
+ def unpack(buf):
+ assert(len(buf) >= 88) # Should be verified by caller
+ obj = flow_stats_entry()
+ _length = struct.unpack_from('!H', buf, 0)[0]
+ assert(_length == len(buf))
+ if _length < 88: raise loxi.ProtocolError("flow_stats_entry length is %d, should be at least 88" % _length)
+ obj.table_id = struct.unpack_from('!B', buf, 2)[0]
+ obj.pad = struct.unpack_from('!B', buf, 3)[0]
+ obj.match = common.match.unpack(buffer(buf, 4))
+ obj.duration_sec = struct.unpack_from('!L', buf, 44)[0]
+ obj.duration_nsec = struct.unpack_from('!L', buf, 48)[0]
+ obj.priority = struct.unpack_from('!H', buf, 52)[0]
+ obj.idle_timeout = struct.unpack_from('!H', buf, 54)[0]
+ obj.hard_timeout = struct.unpack_from('!H', buf, 56)[0]
+ obj.pad2 = list(struct.unpack_from('!6B', buf, 58))
+ obj.cookie = struct.unpack_from('!Q', buf, 64)[0]
+ obj.packet_count = struct.unpack_from('!Q', buf, 72)[0]
+ obj.byte_count = struct.unpack_from('!Q', buf, 80)[0]
+ obj.actions = action.unpack_list(buffer(buf, 88))
+ return obj
+
+ def __eq__(self, other):
+ if type(self) != type(other): return False
+ if self.table_id != other.table_id: return False
+ if self.pad != other.pad: return False
+ if self.match != other.match: return False
+ if self.duration_sec != other.duration_sec: return False
+ if self.duration_nsec != other.duration_nsec: return False
+ if self.priority != other.priority: return False
+ if self.idle_timeout != other.idle_timeout: return False
+ if self.hard_timeout != other.hard_timeout: return False
+ if self.pad2 != other.pad2: return False
+ if self.cookie != other.cookie: return False
+ if self.packet_count != other.packet_count: return False
+ if self.byte_count != other.byte_count: return False
+ if self.actions != other.actions: return False
+ return True
+
+ def __ne__(self, other):
+ return not self.__eq__(other)
+
+ def show(self):
+ import loxi.pp
+ return loxi.pp.pp(self)
+
+ def pretty_print(self, q):
+ q.text("flow_stats_entry {")
+ with q.group():
+ with q.indent(2):
+ q.breakable()
+ q.text("table_id = ");
+ q.text("%#x" % self.table_id)
+ q.text(","); q.breakable()
+ q.text("pad = ");
+ q.text("%#x" % self.pad)
+ q.text(","); q.breakable()
+ q.text("match = ");
+ q.pp(self.match)
+ q.text(","); q.breakable()
+ q.text("duration_sec = ");
+ q.text("%#x" % self.duration_sec)
+ q.text(","); q.breakable()
+ q.text("duration_nsec = ");
+ q.text("%#x" % self.duration_nsec)
+ q.text(","); q.breakable()
+ q.text("priority = ");
+ q.text("%#x" % self.priority)
+ q.text(","); q.breakable()
+ q.text("idle_timeout = ");
+ q.text("%#x" % self.idle_timeout)
+ q.text(","); q.breakable()
+ q.text("hard_timeout = ");
+ q.text("%#x" % self.hard_timeout)
+ q.text(","); q.breakable()
+ q.text("pad2 = ");
+ q.pp(self.pad2)
+ q.text(","); q.breakable()
+ q.text("cookie = ");
+ q.text("%#x" % self.cookie)
+ q.text(","); q.breakable()
+ q.text("packet_count = ");
+ q.text("%#x" % self.packet_count)
+ q.text(","); q.breakable()
+ q.text("byte_count = ");
+ q.text("%#x" % self.byte_count)
+ q.text(","); q.breakable()
+ q.text("actions = ");
+ q.pp(self.actions)
+ q.breakable()
+ q.text('}')
+
+class match_v1(object):
+
+ def __init__(self, wildcards=None, in_port=None, eth_src=None, eth_dst=None, vlan_vid=None, vlan_pcp=None, pad1=None, eth_type=None, ip_dscp=None, ip_proto=None, pad2=None, ipv4_src=None, ipv4_dst=None, tcp_src=None, tcp_dst=None):
+ if wildcards != None:
+ self.wildcards = wildcards
+ else:
+ self.wildcards = const.OFPFW_ALL
+ if in_port != None:
+ self.in_port = in_port
+ else:
+ self.in_port = 0
+ if eth_src != None:
+ self.eth_src = eth_src
+ else:
+ self.eth_src = [0,0,0,0,0,0]
+ if eth_dst != None:
+ self.eth_dst = eth_dst
+ else:
+ self.eth_dst = [0,0,0,0,0,0]
+ if vlan_vid != None:
+ self.vlan_vid = vlan_vid
+ else:
+ self.vlan_vid = 0
+ if vlan_pcp != None:
+ self.vlan_pcp = vlan_pcp
+ else:
+ self.vlan_pcp = 0
+ if pad1 != None:
+ self.pad1 = pad1
+ else:
+ self.pad1 = 0
+ if eth_type != None:
+ self.eth_type = eth_type
+ else:
+ self.eth_type = 0
+ if ip_dscp != None:
+ self.ip_dscp = ip_dscp
+ else:
+ self.ip_dscp = 0
+ if ip_proto != None:
+ self.ip_proto = ip_proto
+ else:
+ self.ip_proto = 0
+ if pad2 != None:
+ self.pad2 = pad2
+ else:
+ self.pad2 = [0,0]
+ if ipv4_src != None:
+ self.ipv4_src = ipv4_src
+ else:
+ self.ipv4_src = 0
+ if ipv4_dst != None:
+ self.ipv4_dst = ipv4_dst
+ else:
+ self.ipv4_dst = 0
+ if tcp_src != None:
+ self.tcp_src = tcp_src
+ else:
+ self.tcp_src = 0
+ if tcp_dst != None:
+ self.tcp_dst = tcp_dst
+ else:
+ self.tcp_dst = 0
+
+ def pack(self):
+ packed = []
+ packed.append(struct.pack("!L", self.wildcards))
+ packed.append(struct.pack("!H", self.in_port))
+ packed.append(struct.pack("!6B", *self.eth_src))
+ packed.append(struct.pack("!6B", *self.eth_dst))
+ packed.append(struct.pack("!H", self.vlan_vid))
+ packed.append(struct.pack("!B", self.vlan_pcp))
+ packed.append(struct.pack("!B", self.pad1))
+ packed.append(struct.pack("!H", self.eth_type))
+ packed.append(struct.pack("!B", self.ip_dscp))
+ packed.append(struct.pack("!B", self.ip_proto))
+ packed.append(struct.pack("!2B", *self.pad2))
+ packed.append(struct.pack("!L", self.ipv4_src))
+ packed.append(struct.pack("!L", self.ipv4_dst))
+ packed.append(struct.pack("!H", self.tcp_src))
+ packed.append(struct.pack("!H", self.tcp_dst))
+ return ''.join(packed)
+
+ @staticmethod
+ def unpack(buf):
+ assert(len(buf) >= 40) # Should be verified by caller
+ obj = match_v1()
+ obj.wildcards = struct.unpack_from('!L', buf, 0)[0]
+ obj.in_port = struct.unpack_from('!H', buf, 4)[0]
+ obj.eth_src = list(struct.unpack_from('!6B', buf, 6))
+ obj.eth_dst = list(struct.unpack_from('!6B', buf, 12))
+ obj.vlan_vid = struct.unpack_from('!H', buf, 18)[0]
+ obj.vlan_pcp = struct.unpack_from('!B', buf, 20)[0]
+ obj.pad1 = struct.unpack_from('!B', buf, 21)[0]
+ obj.eth_type = struct.unpack_from('!H', buf, 22)[0]
+ obj.ip_dscp = struct.unpack_from('!B', buf, 24)[0]
+ obj.ip_proto = struct.unpack_from('!B', buf, 25)[0]
+ obj.pad2 = list(struct.unpack_from('!2B', buf, 26))
+ obj.ipv4_src = struct.unpack_from('!L', buf, 28)[0]
+ obj.ipv4_dst = struct.unpack_from('!L', buf, 32)[0]
+ obj.tcp_src = struct.unpack_from('!H', buf, 36)[0]
+ obj.tcp_dst = struct.unpack_from('!H', buf, 38)[0]
+ return obj
+
+ def __eq__(self, other):
+ if type(self) != type(other): return False
+ if self.wildcards != other.wildcards: return False
+ if self.in_port != other.in_port: return False
+ if self.eth_src != other.eth_src: return False
+ if self.eth_dst != other.eth_dst: return False
+ if self.vlan_vid != other.vlan_vid: return False
+ if self.vlan_pcp != other.vlan_pcp: return False
+ if self.pad1 != other.pad1: return False
+ if self.eth_type != other.eth_type: return False
+ if self.ip_dscp != other.ip_dscp: return False
+ if self.ip_proto != other.ip_proto: return False
+ if self.pad2 != other.pad2: return False
+ if self.ipv4_src != other.ipv4_src: return False
+ if self.ipv4_dst != other.ipv4_dst: return False
+ if self.tcp_src != other.tcp_src: return False
+ if self.tcp_dst != other.tcp_dst: return False
+ return True
+
+ def __ne__(self, other):
+ return not self.__eq__(other)
+
+ def show(self):
+ import loxi.pp
+ return loxi.pp.pp(self)
+
+ def pretty_print(self, q):
+ q.text("match_v1 {")
+ with q.group():
+ with q.indent(2):
+ q.breakable()
+ q.text("wildcards = ");
+ q.text(util.pretty_wildcards(self.wildcards))
+ q.text(","); q.breakable()
+ q.text("in_port = ");
+ q.text(util.pretty_port(self.in_port))
+ q.text(","); q.breakable()
+ q.text("eth_src = ");
+ q.text(util.pretty_mac(self.eth_src))
+ q.text(","); q.breakable()
+ q.text("eth_dst = ");
+ q.text(util.pretty_mac(self.eth_dst))
+ q.text(","); q.breakable()
+ q.text("vlan_vid = ");
+ q.text("%#x" % self.vlan_vid)
+ q.text(","); q.breakable()
+ q.text("vlan_pcp = ");
+ q.text("%#x" % self.vlan_pcp)
+ q.text(","); q.breakable()
+ q.text("pad1 = ");
+ q.text("%#x" % self.pad1)
+ q.text(","); q.breakable()
+ q.text("eth_type = ");
+ q.text("%#x" % self.eth_type)
+ q.text(","); q.breakable()
+ q.text("ip_dscp = ");
+ q.text("%#x" % self.ip_dscp)
+ q.text(","); q.breakable()
+ q.text("ip_proto = ");
+ q.text("%#x" % self.ip_proto)
+ q.text(","); q.breakable()
+ q.text("pad2 = ");
+ q.pp(self.pad2)
+ q.text(","); q.breakable()
+ q.text("ipv4_src = ");
+ q.text(util.pretty_ipv4(self.ipv4_src))
+ q.text(","); q.breakable()
+ q.text("ipv4_dst = ");
+ q.text(util.pretty_ipv4(self.ipv4_dst))
+ q.text(","); q.breakable()
+ q.text("tcp_src = ");
+ q.text("%#x" % self.tcp_src)
+ q.text(","); q.breakable()
+ q.text("tcp_dst = ");
+ q.text("%#x" % self.tcp_dst)
+ q.breakable()
+ q.text('}')
+
+match = match_v1
+
+class packet_queue(object):
+
+ def __init__(self, queue_id=None, pad=None, properties=None):
+ if queue_id != None:
+ self.queue_id = queue_id
+ else:
+ self.queue_id = 0
+ if pad != None:
+ self.pad = pad
+ else:
+ self.pad = [0,0]
+ if properties != None:
+ self.properties = properties
+ else:
+ self.properties = []
+
+ def pack(self):
+ packed = []
+ packed.append(struct.pack("!L", self.queue_id))
+ packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
+ packed.append(struct.pack("!2B", *self.pad))
+ packed.append("".join([x.pack() for x in self.properties]))
+ length = sum([len(x) for x in packed])
+ packed[1] = struct.pack("!H", length)
+ return ''.join(packed)
+
+ @staticmethod
+ def unpack(buf):
+ assert(len(buf) >= 8) # Should be verified by caller
+ obj = packet_queue()
+ obj.queue_id = struct.unpack_from('!L', buf, 0)[0]
+ _length = struct.unpack_from('!H', buf, 4)[0]
+ assert(_length == len(buf))
+ if _length < 8: raise loxi.ProtocolError("packet_queue length is %d, should be at least 8" % _length)
+ obj.pad = list(struct.unpack_from('!2B', buf, 6))
+ obj.properties = common.unpack_list_queue_prop(buffer(buf, 8))
+ return obj
+
+ def __eq__(self, other):
+ if type(self) != type(other): return False
+ if self.queue_id != other.queue_id: return False
+ if self.pad != other.pad: return False
+ if self.properties != other.properties: return False
+ return True
+
+ def __ne__(self, other):
+ return not self.__eq__(other)
+
+ def show(self):
+ import loxi.pp
+ return loxi.pp.pp(self)
+
+ def pretty_print(self, q):
+ q.text("packet_queue {")
+ with q.group():
+ with q.indent(2):
+ q.breakable()
+ q.text("queue_id = ");
+ q.text("%#x" % self.queue_id)
+ q.text(","); q.breakable()
+ q.text("pad = ");
+ q.pp(self.pad)
+ q.text(","); q.breakable()
+ q.text("properties = ");
+ q.pp(self.properties)
+ q.breakable()
+ q.text('}')
+
+class port_desc(object):
+
+ def __init__(self, port_no=None, hw_addr=None, name=None, config=None, state=None, curr=None, advertised=None, supported=None, peer=None):
+ if port_no != None:
+ self.port_no = port_no
+ else:
+ self.port_no = 0
+ if hw_addr != None:
+ self.hw_addr = hw_addr
+ else:
+ self.hw_addr = [0,0,0,0,0,0]
+ if name != None:
+ self.name = name
+ else:
+ self.name = ""
+ if config != None:
+ self.config = config
+ else:
+ self.config = 0
+ if state != None:
+ self.state = state
+ else:
+ self.state = 0
+ if curr != None:
+ self.curr = curr
+ else:
+ self.curr = 0
+ if advertised != None:
+ self.advertised = advertised
+ else:
+ self.advertised = 0
+ if supported != None:
+ self.supported = supported
+ else:
+ self.supported = 0
+ if peer != None:
+ self.peer = peer
+ else:
+ self.peer = 0
+
+ def pack(self):
+ packed = []
+ packed.append(struct.pack("!H", self.port_no))
+ packed.append(struct.pack("!6B", *self.hw_addr))
+ packed.append(struct.pack("!16s", self.name))
+ packed.append(struct.pack("!L", self.config))
+ packed.append(struct.pack("!L", self.state))
+ packed.append(struct.pack("!L", self.curr))
+ packed.append(struct.pack("!L", self.advertised))
+ packed.append(struct.pack("!L", self.supported))
+ packed.append(struct.pack("!L", self.peer))
+ return ''.join(packed)
+
+ @staticmethod
+ def unpack(buf):
+ assert(len(buf) >= 48) # Should be verified by caller
+ obj = port_desc()
+ obj.port_no = struct.unpack_from('!H', buf, 0)[0]
+ obj.hw_addr = list(struct.unpack_from('!6B', buf, 2))
+ obj.name = str(buffer(buf, 8, 16)).rstrip("\x00")
+ obj.config = struct.unpack_from('!L', buf, 24)[0]
+ obj.state = struct.unpack_from('!L', buf, 28)[0]
+ obj.curr = struct.unpack_from('!L', buf, 32)[0]
+ obj.advertised = struct.unpack_from('!L', buf, 36)[0]
+ obj.supported = struct.unpack_from('!L', buf, 40)[0]
+ obj.peer = struct.unpack_from('!L', buf, 44)[0]
+ return obj
+
+ def __eq__(self, other):
+ if type(self) != type(other): return False
+ if self.port_no != other.port_no: return False
+ if self.hw_addr != other.hw_addr: return False
+ if self.name != other.name: return False
+ if self.config != other.config: return False
+ if self.state != other.state: return False
+ if self.curr != other.curr: return False
+ if self.advertised != other.advertised: return False
+ if self.supported != other.supported: return False
+ if self.peer != other.peer: return False
+ return True
+
+ def __ne__(self, other):
+ return not self.__eq__(other)
+
+ def show(self):
+ import loxi.pp
+ return loxi.pp.pp(self)
+
+ def pretty_print(self, q):
+ q.text("port_desc {")
+ with q.group():
+ with q.indent(2):
+ q.breakable()
+ q.text("port_no = ");
+ q.text(util.pretty_port(self.port_no))
+ q.text(","); q.breakable()
+ q.text("hw_addr = ");
+ q.text(util.pretty_mac(self.hw_addr))
+ q.text(","); q.breakable()
+ q.text("name = ");
+ q.pp(self.name)
+ q.text(","); q.breakable()
+ q.text("config = ");
+ q.text("%#x" % self.config)
+ q.text(","); q.breakable()
+ q.text("state = ");
+ q.text("%#x" % self.state)
+ q.text(","); q.breakable()
+ q.text("curr = ");
+ q.text("%#x" % self.curr)
+ q.text(","); q.breakable()
+ q.text("advertised = ");
+ q.text("%#x" % self.advertised)
+ q.text(","); q.breakable()
+ q.text("supported = ");
+ q.text("%#x" % self.supported)
+ q.text(","); q.breakable()
+ q.text("peer = ");
+ q.text("%#x" % self.peer)
+ q.breakable()
+ q.text('}')
+
+class port_stats_entry(object):
+
+ def __init__(self, port_no=None, pad=None, rx_packets=None, tx_packets=None, rx_bytes=None, tx_bytes=None, rx_dropped=None, tx_dropped=None, rx_errors=None, tx_errors=None, rx_frame_err=None, rx_over_err=None, rx_crc_err=None, collisions=None):
+ if port_no != None:
+ self.port_no = port_no
+ else:
+ self.port_no = 0
+ if pad != None:
+ self.pad = pad
+ else:
+ self.pad = [0,0,0,0,0,0]
+ if rx_packets != None:
+ self.rx_packets = rx_packets
+ else:
+ self.rx_packets = 0
+ if tx_packets != None:
+ self.tx_packets = tx_packets
+ else:
+ self.tx_packets = 0
+ if rx_bytes != None:
+ self.rx_bytes = rx_bytes
+ else:
+ self.rx_bytes = 0
+ if tx_bytes != None:
+ self.tx_bytes = tx_bytes
+ else:
+ self.tx_bytes = 0
+ if rx_dropped != None:
+ self.rx_dropped = rx_dropped
+ else:
+ self.rx_dropped = 0
+ if tx_dropped != None:
+ self.tx_dropped = tx_dropped
+ else:
+ self.tx_dropped = 0
+ if rx_errors != None:
+ self.rx_errors = rx_errors
+ else:
+ self.rx_errors = 0
+ if tx_errors != None:
+ self.tx_errors = tx_errors
+ else:
+ self.tx_errors = 0
+ if rx_frame_err != None:
+ self.rx_frame_err = rx_frame_err
+ else:
+ self.rx_frame_err = 0
+ if rx_over_err != None:
+ self.rx_over_err = rx_over_err
+ else:
+ self.rx_over_err = 0
+ if rx_crc_err != None:
+ self.rx_crc_err = rx_crc_err
+ else:
+ self.rx_crc_err = 0
+ if collisions != None:
+ self.collisions = collisions
+ else:
+ self.collisions = 0
+
+ def pack(self):
+ packed = []
+ packed.append(struct.pack("!H", self.port_no))
+ packed.append(struct.pack("!6B", *self.pad))
+ packed.append(struct.pack("!Q", self.rx_packets))
+ packed.append(struct.pack("!Q", self.tx_packets))
+ packed.append(struct.pack("!Q", self.rx_bytes))
+ packed.append(struct.pack("!Q", self.tx_bytes))
+ packed.append(struct.pack("!Q", self.rx_dropped))
+ packed.append(struct.pack("!Q", self.tx_dropped))
+ packed.append(struct.pack("!Q", self.rx_errors))
+ packed.append(struct.pack("!Q", self.tx_errors))
+ packed.append(struct.pack("!Q", self.rx_frame_err))
+ packed.append(struct.pack("!Q", self.rx_over_err))
+ packed.append(struct.pack("!Q", self.rx_crc_err))
+ packed.append(struct.pack("!Q", self.collisions))
+ return ''.join(packed)
+
+ @staticmethod
+ def unpack(buf):
+ assert(len(buf) >= 104) # Should be verified by caller
+ obj = port_stats_entry()
+ obj.port_no = struct.unpack_from('!H', buf, 0)[0]
+ obj.pad = list(struct.unpack_from('!6B', buf, 2))
+ obj.rx_packets = struct.unpack_from('!Q', buf, 8)[0]
+ obj.tx_packets = struct.unpack_from('!Q', buf, 16)[0]
+ obj.rx_bytes = struct.unpack_from('!Q', buf, 24)[0]
+ obj.tx_bytes = struct.unpack_from('!Q', buf, 32)[0]
+ obj.rx_dropped = struct.unpack_from('!Q', buf, 40)[0]
+ obj.tx_dropped = struct.unpack_from('!Q', buf, 48)[0]
+ obj.rx_errors = struct.unpack_from('!Q', buf, 56)[0]
+ obj.tx_errors = struct.unpack_from('!Q', buf, 64)[0]
+ obj.rx_frame_err = struct.unpack_from('!Q', buf, 72)[0]
+ obj.rx_over_err = struct.unpack_from('!Q', buf, 80)[0]
+ obj.rx_crc_err = struct.unpack_from('!Q', buf, 88)[0]
+ obj.collisions = struct.unpack_from('!Q', buf, 96)[0]
+ return obj
+
+ def __eq__(self, other):
+ if type(self) != type(other): return False
+ if self.port_no != other.port_no: return False
+ if self.pad != other.pad: return False
+ if self.rx_packets != other.rx_packets: return False
+ if self.tx_packets != other.tx_packets: return False
+ if self.rx_bytes != other.rx_bytes: return False
+ if self.tx_bytes != other.tx_bytes: return False
+ if self.rx_dropped != other.rx_dropped: return False
+ if self.tx_dropped != other.tx_dropped: return False
+ if self.rx_errors != other.rx_errors: return False
+ if self.tx_errors != other.tx_errors: return False
+ if self.rx_frame_err != other.rx_frame_err: return False
+ if self.rx_over_err != other.rx_over_err: return False
+ if self.rx_crc_err != other.rx_crc_err: return False
+ if self.collisions != other.collisions: return False
+ return True
+
+ def __ne__(self, other):
+ return not self.__eq__(other)
+
+ def show(self):
+ import loxi.pp
+ return loxi.pp.pp(self)
+
+ def pretty_print(self, q):
+ q.text("port_stats_entry {")
+ with q.group():
+ with q.indent(2):
+ q.breakable()
+ q.text("port_no = ");
+ q.text(util.pretty_port(self.port_no))
+ q.text(","); q.breakable()
+ q.text("pad = ");
+ q.pp(self.pad)
+ q.text(","); q.breakable()
+ q.text("rx_packets = ");
+ q.text("%#x" % self.rx_packets)
+ q.text(","); q.breakable()
+ q.text("tx_packets = ");
+ q.text("%#x" % self.tx_packets)
+ q.text(","); q.breakable()
+ q.text("rx_bytes = ");
+ q.text("%#x" % self.rx_bytes)
+ q.text(","); q.breakable()
+ q.text("tx_bytes = ");
+ q.text("%#x" % self.tx_bytes)
+ q.text(","); q.breakable()
+ q.text("rx_dropped = ");
+ q.text("%#x" % self.rx_dropped)
+ q.text(","); q.breakable()
+ q.text("tx_dropped = ");
+ q.text("%#x" % self.tx_dropped)
+ q.text(","); q.breakable()
+ q.text("rx_errors = ");
+ q.text("%#x" % self.rx_errors)
+ q.text(","); q.breakable()
+ q.text("tx_errors = ");
+ q.text("%#x" % self.tx_errors)
+ q.text(","); q.breakable()
+ q.text("rx_frame_err = ");
+ q.text("%#x" % self.rx_frame_err)
+ q.text(","); q.breakable()
+ q.text("rx_over_err = ");
+ q.text("%#x" % self.rx_over_err)
+ q.text(","); q.breakable()
+ q.text("rx_crc_err = ");
+ q.text("%#x" % self.rx_crc_err)
+ q.text(","); q.breakable()
+ q.text("collisions = ");
+ q.text("%#x" % self.collisions)
+ q.breakable()
+ q.text('}')
+
+class queue_prop_min_rate(object):
+ type = const.OFPQT_MIN_RATE
+
+ def __init__(self, pad=None, rate=None, pad2=None):
+ if pad != None:
+ self.pad = pad
+ else:
+ self.pad = [0,0,0,0]
+ if rate != None:
+ self.rate = rate
+ else:
+ self.rate = 0
+ if pad2 != None:
+ self.pad2 = pad2
+ else:
+ self.pad2 = [0,0,0,0,0,0]
+
+ def pack(self):
+ packed = []
+ packed.append(struct.pack("!H", self.type))
+ packed.append(struct.pack("!H", 0)) # placeholder for len at index 1
+ packed.append(struct.pack("!4B", *self.pad))
+ packed.append(struct.pack("!H", self.rate))
+ packed.append(struct.pack("!6B", *self.pad2))
+ length = sum([len(x) for x in packed])
+ packed[1] = struct.pack("!H", length)
+ return ''.join(packed)
+
+ @staticmethod
+ def unpack(buf):
+ assert(len(buf) >= 16) # Should be verified by caller
+ obj = queue_prop_min_rate()
+ type = struct.unpack_from('!H', buf, 0)[0]
+ assert(type == const.OFPQT_MIN_RATE)
+ _length = struct.unpack_from('!H', buf, 2)[0]
+ assert(_length == len(buf))
+ if _length != 16: raise loxi.ProtocolError("queue_prop_min_rate length is %d, should be 16" % _length)
+ obj.pad = list(struct.unpack_from('!4B', buf, 4))
+ obj.rate = struct.unpack_from('!H', buf, 8)[0]
+ obj.pad2 = list(struct.unpack_from('!6B', buf, 10))
+ return obj
+
+ def __eq__(self, other):
+ if type(self) != type(other): return False
+ if self.pad != other.pad: return False
+ if self.rate != other.rate: return False
+ if self.pad2 != other.pad2: return False
+ return True
+
+ def __ne__(self, other):
+ return not self.__eq__(other)
+
+ def show(self):
+ import loxi.pp
+ return loxi.pp.pp(self)
+
+ def pretty_print(self, q):
+ q.text("queue_prop_min_rate {")
+ with q.group():
+ with q.indent(2):
+ q.breakable()
+ q.text("pad = ");
+ q.pp(self.pad)
+ q.text(","); q.breakable()
+ q.text("rate = ");
+ q.text("%#x" % self.rate)
+ q.text(","); q.breakable()
+ q.text("pad2 = ");
+ q.pp(self.pad2)
+ q.breakable()
+ q.text('}')
+
+class queue_stats_entry(object):
+
+ def __init__(self, port_no=None, pad=None, queue_id=None, tx_bytes=None, tx_packets=None, tx_errors=None):
+ if port_no != None:
+ self.port_no = port_no
+ else:
+ self.port_no = 0
+ if pad != None:
+ self.pad = pad
+ else:
+ self.pad = [0,0]
+ if queue_id != None:
+ self.queue_id = queue_id
+ else:
+ self.queue_id = 0
+ if tx_bytes != None:
+ self.tx_bytes = tx_bytes
+ else:
+ self.tx_bytes = 0
+ if tx_packets != None:
+ self.tx_packets = tx_packets
+ else:
+ self.tx_packets = 0
+ if tx_errors != None:
+ self.tx_errors = tx_errors
+ else:
+ self.tx_errors = 0
+
+ def pack(self):
+ packed = []
+ packed.append(struct.pack("!H", self.port_no))
+ packed.append(struct.pack("!2B", *self.pad))
+ packed.append(struct.pack("!L", self.queue_id))
+ packed.append(struct.pack("!Q", self.tx_bytes))
+ packed.append(struct.pack("!Q", self.tx_packets))
+ packed.append(struct.pack("!Q", self.tx_errors))
+ return ''.join(packed)
+
+ @staticmethod
+ def unpack(buf):
+ assert(len(buf) >= 32) # Should be verified by caller
+ obj = queue_stats_entry()
+ obj.port_no = struct.unpack_from('!H', buf, 0)[0]
+ obj.pad = list(struct.unpack_from('!2B', buf, 2))
+ obj.queue_id = struct.unpack_from('!L', buf, 4)[0]
+ obj.tx_bytes = struct.unpack_from('!Q', buf, 8)[0]
+ obj.tx_packets = struct.unpack_from('!Q', buf, 16)[0]
+ obj.tx_errors = struct.unpack_from('!Q', buf, 24)[0]
+ return obj
+
+ def __eq__(self, other):
+ if type(self) != type(other): return False
+ if self.port_no != other.port_no: return False
+ if self.pad != other.pad: return False
+ if self.queue_id != other.queue_id: return False
+ if self.tx_bytes != other.tx_bytes: return False
+ if self.tx_packets != other.tx_packets: return False
+ if self.tx_errors != other.tx_errors: return False
+ return True
+
+ def __ne__(self, other):
+ return not self.__eq__(other)
+
+ def show(self):
+ import loxi.pp
+ return loxi.pp.pp(self)
+
+ def pretty_print(self, q):
+ q.text("queue_stats_entry {")
+ with q.group():
+ with q.indent(2):
+ q.breakable()
+ q.text("port_no = ");
+ q.text(util.pretty_port(self.port_no))
+ q.text(","); q.breakable()
+ q.text("pad = ");
+ q.pp(self.pad)
+ q.text(","); q.breakable()
+ q.text("queue_id = ");
+ q.text("%#x" % self.queue_id)
+ q.text(","); q.breakable()
+ q.text("tx_bytes = ");
+ q.text("%#x" % self.tx_bytes)
+ q.text(","); q.breakable()
+ q.text("tx_packets = ");
+ q.text("%#x" % self.tx_packets)
+ q.text(","); q.breakable()
+ q.text("tx_errors = ");
+ q.text("%#x" % self.tx_errors)
+ q.breakable()
+ q.text('}')
+
+class table_stats_entry(object):
+
+ def __init__(self, table_id=None, pad=None, name=None, wildcards=None, max_entries=None, active_count=None, lookup_count=None, matched_count=None):
+ if table_id != None:
+ self.table_id = table_id
+ else:
+ self.table_id = 0
+ if pad != None:
+ self.pad = pad
+ else:
+ self.pad = [0,0,0]
+ if name != None:
+ self.name = name
+ else:
+ self.name = ""
+ if wildcards != None:
+ self.wildcards = wildcards
+ else:
+ self.wildcards = const.OFPFW_ALL
+ if max_entries != None:
+ self.max_entries = max_entries
+ else:
+ self.max_entries = 0
+ if active_count != None:
+ self.active_count = active_count
+ else:
+ self.active_count = 0
+ if lookup_count != None:
+ self.lookup_count = lookup_count
+ else:
+ self.lookup_count = 0
+ if matched_count != None:
+ self.matched_count = matched_count
+ else:
+ self.matched_count = 0
+
+ def pack(self):
+ packed = []
+ packed.append(struct.pack("!B", self.table_id))
+ packed.append(struct.pack("!3B", *self.pad))
+ packed.append(struct.pack("!32s", self.name))
+ packed.append(struct.pack("!L", self.wildcards))
+ packed.append(struct.pack("!L", self.max_entries))
+ packed.append(struct.pack("!L", self.active_count))
+ packed.append(struct.pack("!Q", self.lookup_count))
+ packed.append(struct.pack("!Q", self.matched_count))
+ return ''.join(packed)
+
+ @staticmethod
+ def unpack(buf):
+ assert(len(buf) >= 64) # Should be verified by caller
+ obj = table_stats_entry()
+ obj.table_id = struct.unpack_from('!B', buf, 0)[0]
+ obj.pad = list(struct.unpack_from('!3B', buf, 1))
+ obj.name = str(buffer(buf, 4, 32)).rstrip("\x00")
+ obj.wildcards = struct.unpack_from('!L', buf, 36)[0]
+ obj.max_entries = struct.unpack_from('!L', buf, 40)[0]
+ obj.active_count = struct.unpack_from('!L', buf, 44)[0]
+ obj.lookup_count = struct.unpack_from('!Q', buf, 48)[0]
+ obj.matched_count = struct.unpack_from('!Q', buf, 56)[0]
+ return obj
+
+ def __eq__(self, other):
+ if type(self) != type(other): return False
+ if self.table_id != other.table_id: return False
+ if self.pad != other.pad: return False
+ if self.name != other.name: return False
+ if self.wildcards != other.wildcards: return False
+ if self.max_entries != other.max_entries: return False
+ if self.active_count != other.active_count: return False
+ if self.lookup_count != other.lookup_count: return False
+ if self.matched_count != other.matched_count: return False
+ return True
+
+ def __ne__(self, other):
+ return not self.__eq__(other)
+
+ def show(self):
+ import loxi.pp
+ return loxi.pp.pp(self)
+
+ def pretty_print(self, q):
+ q.text("table_stats_entry {")
+ with q.group():
+ with q.indent(2):
+ q.breakable()
+ q.text("table_id = ");
+ q.text("%#x" % self.table_id)
+ q.text(","); q.breakable()
+ q.text("pad = ");
+ q.pp(self.pad)
+ q.text(","); q.breakable()
+ q.text("name = ");
+ q.pp(self.name)
+ q.text(","); q.breakable()
+ q.text("wildcards = ");
+ q.text(util.pretty_wildcards(self.wildcards))
+ q.text(","); q.breakable()
+ q.text("max_entries = ");
+ q.text("%#x" % self.max_entries)
+ q.text(","); q.breakable()
+ q.text("active_count = ");
+ q.text("%#x" % self.active_count)
+ q.text(","); q.breakable()
+ q.text("lookup_count = ");
+ q.text("%#x" % self.lookup_count)
+ q.text(","); q.breakable()
+ q.text("matched_count = ");
+ q.text("%#x" % self.matched_count)
+ q.breakable()
+ q.text('}')
+
diff --git a/src/python/loxi/of10/const.py b/src/python/loxi/of10/const.py
new file mode 100644
index 0000000..e269071
--- /dev/null
+++ b/src/python/loxi/of10/const.py
@@ -0,0 +1,476 @@
+#
+# Copyright 2012, 2013, Big Switch Networks, Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+
+# Automatically generated by LOXI from template const.py
+# Do not modify
+
+OFP_VERSION = 1
+
+# Identifiers from group macro_definitions
+OFP_FLOW_PERMANENT = 0
+OFP_ETH_ALEN = 6
+OFP_MAX_PORT_NAME_LEN = 16
+OFP_MAX_TABLE_NAME_LEN = 32
+SERIAL_NUM_LEN = 32
+OFPFW_ICMP_TYPE = (1 << 6)
+OFPFW_ICMP_CODE = (1 << 7)
+OFP_DEFAULT_MISS_SEND_LEN = 128
+DESC_STR_LEN = 256
+OFP_DL_TYPE_NOT_ETH_TYPE = 0x05ff
+OFP_DL_TYPE_ETH2_CUTOFF = 0x0600
+OFP_TCP_PORT = 6633
+OFP_SSL_PORT = 6633
+OFP_DEFAULT_PRIORITY = 0x8000
+OFPQ_MIN_RATE_UNCFG = 0xffff
+OFP_VLAN_NONE = 0xffff
+OFPQ_ALL = 0xffffffff
+
+# Identifiers from group ofp_action_type
+OFPAT_OUTPUT = 0
+OFPAT_SET_VLAN_VID = 1
+OFPAT_SET_VLAN_PCP = 2
+OFPAT_STRIP_VLAN = 3
+OFPAT_SET_DL_SRC = 4
+OFPAT_SET_DL_DST = 5
+OFPAT_SET_NW_SRC = 6
+OFPAT_SET_NW_DST = 7
+OFPAT_SET_NW_TOS = 8
+OFPAT_SET_TP_SRC = 9
+OFPAT_SET_TP_DST = 10
+OFPAT_ENQUEUE = 11
+OFPAT_VENDOR = 0xffff
+
+ofp_action_type_map = {
+ 0: 'OFPAT_OUTPUT',
+ 1: 'OFPAT_SET_VLAN_VID',
+ 2: 'OFPAT_SET_VLAN_PCP',
+ 3: 'OFPAT_STRIP_VLAN',
+ 4: 'OFPAT_SET_DL_SRC',
+ 5: 'OFPAT_SET_DL_DST',
+ 6: 'OFPAT_SET_NW_SRC',
+ 7: 'OFPAT_SET_NW_DST',
+ 8: 'OFPAT_SET_NW_TOS',
+ 9: 'OFPAT_SET_TP_SRC',
+ 10: 'OFPAT_SET_TP_DST',
+ 11: 'OFPAT_ENQUEUE',
+ 0xffff: 'OFPAT_VENDOR',
+}
+
+# Identifiers from group ofp_bad_action_code
+OFPBAC_BAD_TYPE = 0
+OFPBAC_BAD_LEN = 1
+OFPBAC_BAD_VENDOR = 2
+OFPBAC_BAD_VENDOR_TYPE = 3
+OFPBAC_BAD_OUT_PORT = 4
+OFPBAC_BAD_ARGUMENT = 5
+OFPBAC_EPERM = 6
+OFPBAC_TOO_MANY = 7
+OFPBAC_BAD_QUEUE = 8
+
+ofp_bad_action_code_map = {
+ 0: 'OFPBAC_BAD_TYPE',
+ 1: 'OFPBAC_BAD_LEN',
+ 2: 'OFPBAC_BAD_VENDOR',
+ 3: 'OFPBAC_BAD_VENDOR_TYPE',
+ 4: 'OFPBAC_BAD_OUT_PORT',
+ 5: 'OFPBAC_BAD_ARGUMENT',
+ 6: 'OFPBAC_EPERM',
+ 7: 'OFPBAC_TOO_MANY',
+ 8: 'OFPBAC_BAD_QUEUE',
+}
+
+# Identifiers from group ofp_bad_request_code
+OFPBRC_BAD_VERSION = 0
+OFPBRC_BAD_TYPE = 1
+OFPBRC_BAD_STAT = 2
+OFPBRC_BAD_VENDOR = 3
+OFPBRC_BAD_SUBTYPE = 4
+OFPBRC_EPERM = 5
+OFPBRC_BAD_LEN = 6
+OFPBRC_BUFFER_EMPTY = 7
+OFPBRC_BUFFER_UNKNOWN = 8
+
+ofp_bad_request_code_map = {
+ 0: 'OFPBRC_BAD_VERSION',
+ 1: 'OFPBRC_BAD_TYPE',
+ 2: 'OFPBRC_BAD_STAT',
+ 3: 'OFPBRC_BAD_VENDOR',
+ 4: 'OFPBRC_BAD_SUBTYPE',
+ 5: 'OFPBRC_EPERM',
+ 6: 'OFPBRC_BAD_LEN',
+ 7: 'OFPBRC_BUFFER_EMPTY',
+ 8: 'OFPBRC_BUFFER_UNKNOWN',
+}
+
+# Identifiers from group ofp_capabilities
+OFPC_FLOW_STATS = 1 << 0
+OFPC_TABLE_STATS = 1 << 1
+OFPC_PORT_STATS = 1 << 2
+OFPC_STP = 1 << 3
+OFPC_RESERVED = 1 << 4
+OFPC_IP_REASM = 1 << 5
+OFPC_QUEUE_STATS = 1 << 6
+OFPC_ARP_MATCH_IP = 1 << 7
+
+ofp_capabilities_map = {
+ 1 << 0: 'OFPC_FLOW_STATS',
+ 1 << 1: 'OFPC_TABLE_STATS',
+ 1 << 2: 'OFPC_PORT_STATS',
+ 1 << 3: 'OFPC_STP',
+ 1 << 4: 'OFPC_RESERVED',
+ 1 << 5: 'OFPC_IP_REASM',
+ 1 << 6: 'OFPC_QUEUE_STATS',
+ 1 << 7: 'OFPC_ARP_MATCH_IP',
+}
+
+# Identifiers from group ofp_config_flags
+OFPC_FRAG_NORMAL = 0
+OFPC_FRAG_DROP = 1
+OFPC_FRAG_REASM = 2
+OFPC_FRAG_MASK = 3
+
+ofp_config_flags_map = {
+ 0: 'OFPC_FRAG_NORMAL',
+ 1: 'OFPC_FRAG_DROP',
+ 2: 'OFPC_FRAG_REASM',
+ 3: 'OFPC_FRAG_MASK',
+}
+
+# Identifiers from group ofp_error_type
+OFPET_HELLO_FAILED = 0
+OFPET_BAD_REQUEST = 1
+OFPET_BAD_ACTION = 2
+OFPET_FLOW_MOD_FAILED = 3
+OFPET_PORT_MOD_FAILED = 4
+OFPET_QUEUE_OP_FAILED = 5
+
+ofp_error_type_map = {
+ 0: 'OFPET_HELLO_FAILED',
+ 1: 'OFPET_BAD_REQUEST',
+ 2: 'OFPET_BAD_ACTION',
+ 3: 'OFPET_FLOW_MOD_FAILED',
+ 4: 'OFPET_PORT_MOD_FAILED',
+ 5: 'OFPET_QUEUE_OP_FAILED',
+}
+
+# Identifiers from group ofp_flow_mod_command
+OFPFC_ADD = 0
+OFPFC_MODIFY = 1
+OFPFC_MODIFY_STRICT = 2
+OFPFC_DELETE = 3
+OFPFC_DELETE_STRICT = 4
+
+ofp_flow_mod_command_map = {
+ 0: 'OFPFC_ADD',
+ 1: 'OFPFC_MODIFY',
+ 2: 'OFPFC_MODIFY_STRICT',
+ 3: 'OFPFC_DELETE',
+ 4: 'OFPFC_DELETE_STRICT',
+}
+
+# Identifiers from group ofp_flow_mod_failed_code
+OFPFMFC_ALL_TABLES_FULL = 0
+OFPFMFC_OVERLAP = 1
+OFPFMFC_EPERM = 2
+OFPFMFC_BAD_EMERG_TIMEOUT = 3
+OFPFMFC_BAD_COMMAND = 4
+OFPFMFC_UNSUPPORTED = 5
+
+ofp_flow_mod_failed_code_map = {
+ 0: 'OFPFMFC_ALL_TABLES_FULL',
+ 1: 'OFPFMFC_OVERLAP',
+ 2: 'OFPFMFC_EPERM',
+ 3: 'OFPFMFC_BAD_EMERG_TIMEOUT',
+ 4: 'OFPFMFC_BAD_COMMAND',
+ 5: 'OFPFMFC_UNSUPPORTED',
+}
+
+# Identifiers from group ofp_flow_mod_flags
+OFPFF_SEND_FLOW_REM = 1 << 0
+OFPFF_CHECK_OVERLAP = 1 << 1
+OFPFF_EMERG = 1 << 2
+
+ofp_flow_mod_flags_map = {
+ 1 << 0: 'OFPFF_SEND_FLOW_REM',
+ 1 << 1: 'OFPFF_CHECK_OVERLAP',
+ 1 << 2: 'OFPFF_EMERG',
+}
+
+# Identifiers from group ofp_flow_removed_reason
+OFPRR_IDLE_TIMEOUT = 0
+OFPRR_HARD_TIMEOUT = 1
+OFPRR_DELETE = 2
+
+ofp_flow_removed_reason_map = {
+ 0: 'OFPRR_IDLE_TIMEOUT',
+ 1: 'OFPRR_HARD_TIMEOUT',
+ 2: 'OFPRR_DELETE',
+}
+
+# Identifiers from group ofp_flow_wildcards
+OFPFW_IN_PORT = 1 << 0
+OFPFW_DL_VLAN = 1 << 1
+OFPFW_DL_SRC = 1 << 2
+OFPFW_NW_DST_BITS = 6
+OFPFW_NW_SRC_BITS = 6
+OFPFW_NW_SRC_SHIFT = 8
+OFPFW_DL_DST = 1 << 3
+OFPFW_NW_DST_SHIFT = 14
+OFPFW_DL_TYPE = 1 << 4
+OFPFW_NW_PROTO = 1 << 5
+OFPFW_TP_SRC = 1 << 6
+OFPFW_TP_DST = 1 << 7
+OFPFW_NW_SRC_ALL = 32 << (8)
+OFPFW_NW_SRC_MASK = ((1 << (6)) - 1) << (8)
+OFPFW_NW_DST_ALL = 32 << (14)
+OFPFW_NW_DST_MASK = ((1 << (6)) - 1) << (14)
+OFPFW_DL_VLAN_PCP = 1 << 20
+OFPFW_NW_TOS = 1 << 21
+OFPFW_ALL = ((1 << 22) - 1)
+
+ofp_flow_wildcards_map = {
+ 1 << 0: 'OFPFW_IN_PORT',
+ 1 << 1: 'OFPFW_DL_VLAN',
+ 1 << 2: 'OFPFW_DL_SRC',
+ 1 << 3: 'OFPFW_DL_DST',
+ 1 << 4: 'OFPFW_DL_TYPE',
+ 1 << 5: 'OFPFW_NW_PROTO',
+ 1 << 6: 'OFPFW_TP_SRC',
+ 1 << 7: 'OFPFW_TP_DST',
+ 1 << 20: 'OFPFW_DL_VLAN_PCP',
+ 1 << 21: 'OFPFW_NW_TOS',
+}
+
+# Identifiers from group ofp_hello_failed_code
+OFPHFC_INCOMPATIBLE = 0
+OFPHFC_EPERM = 1
+
+ofp_hello_failed_code_map = {
+ 0: 'OFPHFC_INCOMPATIBLE',
+ 1: 'OFPHFC_EPERM',
+}
+
+# Identifiers from group ofp_packet_in_reason
+OFPR_NO_MATCH = 0
+OFPR_ACTION = 1
+
+ofp_packet_in_reason_map = {
+ 0: 'OFPR_NO_MATCH',
+ 1: 'OFPR_ACTION',
+}
+
+# Identifiers from group ofp_port
+OFPP_MAX = 0xff00
+OFPP_IN_PORT = 0xfff8
+OFPP_TABLE = 0xfff9
+OFPP_NORMAL = 0xfffa
+OFPP_FLOOD = 0xfffb
+OFPP_ALL = 0xfffc
+OFPP_CONTROLLER = 0xfffd
+OFPP_LOCAL = 0xfffe
+OFPP_NONE = 0xffff
+
+ofp_port_map = {
+ 0xff00: 'OFPP_MAX',
+ 0xfff8: 'OFPP_IN_PORT',
+ 0xfff9: 'OFPP_TABLE',
+ 0xfffa: 'OFPP_NORMAL',
+ 0xfffb: 'OFPP_FLOOD',
+ 0xfffc: 'OFPP_ALL',
+ 0xfffd: 'OFPP_CONTROLLER',
+ 0xfffe: 'OFPP_LOCAL',
+ 0xffff: 'OFPP_NONE',
+}
+
+# Identifiers from group ofp_port_config
+OFPPC_PORT_DOWN = 1 << 0
+OFPPC_NO_STP = 1 << 1
+OFPPC_NO_RECV = 1 << 2
+OFPPC_NO_RECV_STP = 1 << 3
+OFPPC_NO_FLOOD = 1 << 4
+OFPPC_NO_FWD = 1 << 5
+OFPPC_NO_PACKET_IN = 1 << 6
+
+ofp_port_config_map = {
+ 1 << 0: 'OFPPC_PORT_DOWN',
+ 1 << 1: 'OFPPC_NO_STP',
+ 1 << 2: 'OFPPC_NO_RECV',
+ 1 << 3: 'OFPPC_NO_RECV_STP',
+ 1 << 4: 'OFPPC_NO_FLOOD',
+ 1 << 5: 'OFPPC_NO_FWD',
+ 1 << 6: 'OFPPC_NO_PACKET_IN',
+}
+
+# Identifiers from group ofp_port_features
+OFPPF_10MB_HD = 1 << 0
+OFPPF_10MB_FD = 1 << 1
+OFPPF_100MB_HD = 1 << 2
+OFPPF_100MB_FD = 1 << 3
+OFPPF_1GB_HD = 1 << 4
+OFPPF_1GB_FD = 1 << 5
+OFPPF_10GB_FD = 1 << 6
+OFPPF_COPPER = 1 << 7
+OFPPF_FIBER = 1 << 8
+OFPPF_AUTONEG = 1 << 9
+OFPPF_PAUSE = 1 << 10
+OFPPF_PAUSE_ASYM = 1 << 11
+
+ofp_port_features_map = {
+ 1 << 0: 'OFPPF_10MB_HD',
+ 1 << 1: 'OFPPF_10MB_FD',
+ 1 << 2: 'OFPPF_100MB_HD',
+ 1 << 3: 'OFPPF_100MB_FD',
+ 1 << 4: 'OFPPF_1GB_HD',
+ 1 << 5: 'OFPPF_1GB_FD',
+ 1 << 6: 'OFPPF_10GB_FD',
+ 1 << 7: 'OFPPF_COPPER',
+ 1 << 8: 'OFPPF_FIBER',
+ 1 << 9: 'OFPPF_AUTONEG',
+ 1 << 10: 'OFPPF_PAUSE',
+ 1 << 11: 'OFPPF_PAUSE_ASYM',
+}
+
+# Identifiers from group ofp_port_mod_failed_code
+OFPPMFC_BAD_PORT = 0
+OFPPMFC_BAD_HW_ADDR = 1
+
+ofp_port_mod_failed_code_map = {
+ 0: 'OFPPMFC_BAD_PORT',
+ 1: 'OFPPMFC_BAD_HW_ADDR',
+}
+
+# Identifiers from group ofp_port_reason
+OFPPR_ADD = 0
+OFPPR_DELETE = 1
+OFPPR_MODIFY = 2
+
+ofp_port_reason_map = {
+ 0: 'OFPPR_ADD',
+ 1: 'OFPPR_DELETE',
+ 2: 'OFPPR_MODIFY',
+}
+
+# Identifiers from group ofp_port_state
+OFPPS_STP_LISTEN = 0 << 8
+OFPPS_LINK_DOWN = 1 << 0
+OFPPS_STP_LEARN = 1 << 8
+OFPPS_STP_FORWARD = 2 << 8
+OFPPS_STP_BLOCK = 3 << 8
+OFPPS_STP_MASK = 3 << 8
+
+ofp_port_state_map = {
+ 0 << 8: 'OFPPS_STP_LISTEN',
+ 1 << 0: 'OFPPS_LINK_DOWN',
+ 1 << 8: 'OFPPS_STP_LEARN',
+ 2 << 8: 'OFPPS_STP_FORWARD',
+ 3 << 8: 'OFPPS_STP_BLOCK',
+ 3 << 8: 'OFPPS_STP_MASK',
+}
+
+# Identifiers from group ofp_queue_op_failed_code
+OFPQOFC_BAD_PORT = 0
+OFPQOFC_BAD_QUEUE = 1
+OFPQOFC_EPERM = 2
+
+ofp_queue_op_failed_code_map = {
+ 0: 'OFPQOFC_BAD_PORT',
+ 1: 'OFPQOFC_BAD_QUEUE',
+ 2: 'OFPQOFC_EPERM',
+}
+
+# Identifiers from group ofp_queue_properties
+OFPQT_NONE = 0
+OFPQT_MIN_RATE = 1
+
+ofp_queue_properties_map = {
+ 0: 'OFPQT_NONE',
+ 1: 'OFPQT_MIN_RATE',
+}
+
+# Identifiers from group ofp_stats_reply_flags
+OFPSF_REPLY_MORE = 1 << 0
+
+ofp_stats_reply_flags_map = {
+ 1 << 0: 'OFPSF_REPLY_MORE',
+}
+
+# Identifiers from group ofp_stats_types
+OFPST_DESC = 0
+OFPST_FLOW = 1
+OFPST_AGGREGATE = 2
+OFPST_TABLE = 3
+OFPST_PORT = 4
+OFPST_QUEUE = 5
+OFPST_VENDOR = 0xffff
+
+ofp_stats_types_map = {
+ 0: 'OFPST_DESC',
+ 1: 'OFPST_FLOW',
+ 2: 'OFPST_AGGREGATE',
+ 3: 'OFPST_TABLE',
+ 4: 'OFPST_PORT',
+ 5: 'OFPST_QUEUE',
+ 0xffff: 'OFPST_VENDOR',
+}
+
+# Identifiers from group ofp_type
+OFPT_HELLO = 0
+OFPT_ERROR = 1
+OFPT_ECHO_REQUEST = 2
+OFPT_ECHO_REPLY = 3
+OFPT_VENDOR = 4
+OFPT_FEATURES_REQUEST = 5
+OFPT_FEATURES_REPLY = 6
+OFPT_GET_CONFIG_REQUEST = 7
+OFPT_GET_CONFIG_REPLY = 8
+OFPT_SET_CONFIG = 9
+OFPT_PACKET_IN = 10
+OFPT_FLOW_REMOVED = 11
+OFPT_PORT_STATUS = 12
+OFPT_PACKET_OUT = 13
+OFPT_FLOW_MOD = 14
+OFPT_PORT_MOD = 15
+OFPT_STATS_REQUEST = 16
+OFPT_STATS_REPLY = 17
+OFPT_BARRIER_REQUEST = 18
+OFPT_BARRIER_REPLY = 19
+OFPT_QUEUE_GET_CONFIG_REQUEST = 20
+OFPT_QUEUE_GET_CONFIG_REPLY = 21
+
+ofp_type_map = {
+ 0: 'OFPT_HELLO',
+ 1: 'OFPT_ERROR',
+ 2: 'OFPT_ECHO_REQUEST',
+ 3: 'OFPT_ECHO_REPLY',
+ 4: 'OFPT_VENDOR',
+ 5: 'OFPT_FEATURES_REQUEST',
+ 6: 'OFPT_FEATURES_REPLY',
+ 7: 'OFPT_GET_CONFIG_REQUEST',
+ 8: 'OFPT_GET_CONFIG_REPLY',
+ 9: 'OFPT_SET_CONFIG',
+ 10: 'OFPT_PACKET_IN',
+ 11: 'OFPT_FLOW_REMOVED',
+ 12: 'OFPT_PORT_STATUS',
+ 13: 'OFPT_PACKET_OUT',
+ 14: 'OFPT_FLOW_MOD',
+ 15: 'OFPT_PORT_MOD',
+ 16: 'OFPT_STATS_REQUEST',
+ 17: 'OFPT_STATS_REPLY',
+ 18: 'OFPT_BARRIER_REQUEST',
+ 19: 'OFPT_BARRIER_REPLY',
+ 20: 'OFPT_QUEUE_GET_CONFIG_REQUEST',
+ 21: 'OFPT_QUEUE_GET_CONFIG_REPLY',
+}
+
diff --git a/src/python/loxi/of10/message.py b/src/python/loxi/of10/message.py
new file mode 100644
index 0000000..d80dac3
--- /dev/null
+++ b/src/python/loxi/of10/message.py
@@ -0,0 +1,5098 @@
+#
+# Copyright 2012, 2013, Big Switch Networks, Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+
+# Automatically generated by LOXI from template message.py
+# Do not modify
+
+import struct
+import loxi
+import const
+import common
+import action # for unpack_list
+import util
+
+class Message(object):
+ version = const.OFP_VERSION
+ type = None # override in subclass
+ xid = None
+
+class aggregate_stats_reply(Message):
+ version = const.OFP_VERSION
+ type = const.OFPT_STATS_REPLY
+ stats_type = const.OFPST_AGGREGATE
+
+ def __init__(self, xid=None, flags=None, packet_count=None, byte_count=None, flow_count=None, pad=None):
+ self.xid = xid
+ if flags != None:
+ self.flags = flags
+ else:
+ self.flags = 0
+ if packet_count != None:
+ self.packet_count = packet_count
+ else:
+ self.packet_count = 0
+ if byte_count != None:
+ self.byte_count = byte_count
+ else:
+ self.byte_count = 0
+ if flow_count != None:
+ self.flow_count = flow_count
+ else:
+ self.flow_count = 0
+ if pad != None:
+ self.pad = pad
+ else:
+ self.pad = [0,0,0,0]
+
+ def pack(self):
+ packed = []
+ packed.append(struct.pack("!B", self.version))
+ packed.append(struct.pack("!B", self.type))
+ packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
+ packed.append(struct.pack("!L", self.xid))
+ packed.append(struct.pack("!H", self.stats_type))
+ packed.append(struct.pack("!H", self.flags))
+ packed.append(struct.pack("!Q", self.packet_count))
+ packed.append(struct.pack("!Q", self.byte_count))
+ packed.append(struct.pack("!L", self.flow_count))
+ packed.append(struct.pack("!4B", *self.pad))
+ length = sum([len(x) for x in packed])
+ packed[2] = struct.pack("!H", length)
+ return ''.join(packed)
+
+ @staticmethod
+ def unpack(buf):
+ if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
+ obj = aggregate_stats_reply()
+ version = struct.unpack_from('!B', buf, 0)[0]
+ assert(version == const.OFP_VERSION)
+ type = struct.unpack_from('!B', buf, 1)[0]
+ assert(type == const.OFPT_STATS_REPLY)
+ _length = struct.unpack_from('!H', buf, 2)[0]
+ assert(_length == len(buf))
+ if _length != 36: raise loxi.ProtocolError("aggregate_stats_reply length is %d, should be 36" % _length)
+ obj.xid = struct.unpack_from('!L', buf, 4)[0]
+ stats_type = struct.unpack_from('!H', buf, 8)[0]
+ assert(stats_type == const.OFPST_AGGREGATE)
+ obj.flags = struct.unpack_from('!H', buf, 10)[0]
+ obj.packet_count = struct.unpack_from('!Q', buf, 12)[0]
+ obj.byte_count = struct.unpack_from('!Q', buf, 20)[0]
+ obj.flow_count = struct.unpack_from('!L', buf, 28)[0]
+ obj.pad = list(struct.unpack_from('!4B', buf, 32))
+ return obj
+
+ def __eq__(self, other):
+ if type(self) != type(other): return False
+ if self.version != other.version: return False
+ if self.type != other.type: return False
+ if self.xid != other.xid: return False
+ if self.flags != other.flags: return False
+ if self.packet_count != other.packet_count: return False
+ if self.byte_count != other.byte_count: return False
+ if self.flow_count != other.flow_count: return False
+ if self.pad != other.pad: return False
+ return True
+
+ def __ne__(self, other):
+ return not self.__eq__(other)
+
+ def __str__(self):
+ return self.show()
+
+ def show(self):
+ import loxi.pp
+ return loxi.pp.pp(self)
+
+ def pretty_print(self, q):
+ q.text("aggregate_stats_reply {")
+ with q.group():
+ with q.indent(2):
+ q.breakable()
+ q.text("xid = ");
+ if self.xid != None:
+ q.text("%#x" % self.xid)
+ else:
+ q.text('None')
+ q.text(","); q.breakable()
+ q.text("flags = ");
+ q.text("%#x" % self.flags)
+ q.text(","); q.breakable()
+ q.text("packet_count = ");
+ q.text("%#x" % self.packet_count)
+ q.text(","); q.breakable()
+ q.text("byte_count = ");
+ q.text("%#x" % self.byte_count)
+ q.text(","); q.breakable()
+ q.text("flow_count = ");
+ q.text("%#x" % self.flow_count)
+ q.text(","); q.breakable()
+ q.text("pad = ");
+ q.pp(self.pad)
+ q.breakable()
+ q.text('}')
+
+class aggregate_stats_request(Message):
+ version = const.OFP_VERSION
+ type = const.OFPT_STATS_REQUEST
+ stats_type = const.OFPST_AGGREGATE
+
+ def __init__(self, xid=None, flags=None, match=None, table_id=None, pad=None, out_port=None):
+ self.xid = xid
+ if flags != None:
+ self.flags = flags
+ else:
+ self.flags = 0
+ if match != None:
+ self.match = match
+ else:
+ self.match = common.match()
+ if table_id != None:
+ self.table_id = table_id
+ else:
+ self.table_id = 0
+ if pad != None:
+ self.pad = pad
+ else:
+ self.pad = 0
+ if out_port != None:
+ self.out_port = out_port
+ else:
+ self.out_port = 0
+
+ def pack(self):
+ packed = []
+ packed.append(struct.pack("!B", self.version))
+ packed.append(struct.pack("!B", self.type))
+ packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
+ packed.append(struct.pack("!L", self.xid))
+ packed.append(struct.pack("!H", self.stats_type))
+ packed.append(struct.pack("!H", self.flags))
+ packed.append(self.match.pack())
+ packed.append(struct.pack("!B", self.table_id))
+ packed.append(struct.pack("!B", self.pad))
+ packed.append(struct.pack("!H", self.out_port))
+ length = sum([len(x) for x in packed])
+ packed[2] = struct.pack("!H", length)
+ return ''.join(packed)
+
+ @staticmethod
+ def unpack(buf):
+ if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
+ obj = aggregate_stats_request()
+ version = struct.unpack_from('!B', buf, 0)[0]
+ assert(version == const.OFP_VERSION)
+ type = struct.unpack_from('!B', buf, 1)[0]
+ assert(type == const.OFPT_STATS_REQUEST)
+ _length = struct.unpack_from('!H', buf, 2)[0]
+ assert(_length == len(buf))
+ if _length != 56: raise loxi.ProtocolError("aggregate_stats_request length is %d, should be 56" % _length)
+ obj.xid = struct.unpack_from('!L', buf, 4)[0]
+ stats_type = struct.unpack_from('!H', buf, 8)[0]
+ assert(stats_type == const.OFPST_AGGREGATE)
+ obj.flags = struct.unpack_from('!H', buf, 10)[0]
+ obj.match = common.match.unpack(buffer(buf, 12))
+ obj.table_id = struct.unpack_from('!B', buf, 52)[0]
+ obj.pad = struct.unpack_from('!B', buf, 53)[0]
+ obj.out_port = struct.unpack_from('!H', buf, 54)[0]
+ return obj
+
+ def __eq__(self, other):
+ if type(self) != type(other): return False
+ if self.version != other.version: return False
+ if self.type != other.type: return False
+ if self.xid != other.xid: return False
+ if self.flags != other.flags: return False
+ if self.match != other.match: return False
+ if self.table_id != other.table_id: return False
+ if self.pad != other.pad: return False
+ if self.out_port != other.out_port: return False
+ return True
+
+ def __ne__(self, other):
+ return not self.__eq__(other)
+
+ def __str__(self):
+ return self.show()
+
+ def show(self):
+ import loxi.pp
+ return loxi.pp.pp(self)
+
+ def pretty_print(self, q):
+ q.text("aggregate_stats_request {")
+ with q.group():
+ with q.indent(2):
+ q.breakable()
+ q.text("xid = ");
+ if self.xid != None:
+ q.text("%#x" % self.xid)
+ else:
+ q.text('None')
+ q.text(","); q.breakable()
+ q.text("flags = ");
+ q.text("%#x" % self.flags)
+ q.text(","); q.breakable()
+ q.text("match = ");
+ q.pp(self.match)
+ q.text(","); q.breakable()
+ q.text("table_id = ");
+ q.text("%#x" % self.table_id)
+ q.text(","); q.breakable()
+ q.text("pad = ");
+ q.text("%#x" % self.pad)
+ q.text(","); q.breakable()
+ q.text("out_port = ");
+ q.text(util.pretty_port(self.out_port))
+ q.breakable()
+ q.text('}')
+
+class barrier_reply(Message):
+ version = const.OFP_VERSION
+ type = const.OFPT_BARRIER_REPLY
+
+ def __init__(self, xid=None):
+ self.xid = xid
+
+ def pack(self):
+ packed = []
+ packed.append(struct.pack("!B", self.version))
+ packed.append(struct.pack("!B", self.type))
+ packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
+ packed.append(struct.pack("!L", self.xid))
+ length = sum([len(x) for x in packed])
+ packed[2] = struct.pack("!H", length)
+ return ''.join(packed)
+
+ @staticmethod
+ def unpack(buf):
+ if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
+ obj = barrier_reply()
+ version = struct.unpack_from('!B', buf, 0)[0]
+ assert(version == const.OFP_VERSION)
+ type = struct.unpack_from('!B', buf, 1)[0]
+ assert(type == const.OFPT_BARRIER_REPLY)
+ _length = struct.unpack_from('!H', buf, 2)[0]
+ assert(_length == len(buf))
+ if _length != 8: raise loxi.ProtocolError("barrier_reply length is %d, should be 8" % _length)
+ obj.xid = struct.unpack_from('!L', buf, 4)[0]
+ return obj
+
+ def __eq__(self, other):
+ if type(self) != type(other): return False
+ if self.version != other.version: return False
+ if self.type != other.type: return False
+ if self.xid != other.xid: return False
+ return True
+
+ def __ne__(self, other):
+ return not self.__eq__(other)
+
+ def __str__(self):
+ return self.show()
+
+ def show(self):
+ import loxi.pp
+ return loxi.pp.pp(self)
+
+ def pretty_print(self, q):
+ q.text("barrier_reply {")
+ with q.group():
+ with q.indent(2):
+ q.breakable()
+ q.text("xid = ");
+ if self.xid != None:
+ q.text("%#x" % self.xid)
+ else:
+ q.text('None')
+ q.breakable()
+ q.text('}')
+
+class barrier_request(Message):
+ version = const.OFP_VERSION
+ type = const.OFPT_BARRIER_REQUEST
+
+ def __init__(self, xid=None):
+ self.xid = xid
+
+ def pack(self):
+ packed = []
+ packed.append(struct.pack("!B", self.version))
+ packed.append(struct.pack("!B", self.type))
+ packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
+ packed.append(struct.pack("!L", self.xid))
+ length = sum([len(x) for x in packed])
+ packed[2] = struct.pack("!H", length)
+ return ''.join(packed)
+
+ @staticmethod
+ def unpack(buf):
+ if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
+ obj = barrier_request()
+ version = struct.unpack_from('!B', buf, 0)[0]
+ assert(version == const.OFP_VERSION)
+ type = struct.unpack_from('!B', buf, 1)[0]
+ assert(type == const.OFPT_BARRIER_REQUEST)
+ _length = struct.unpack_from('!H', buf, 2)[0]
+ assert(_length == len(buf))
+ if _length != 8: raise loxi.ProtocolError("barrier_request length is %d, should be 8" % _length)
+ obj.xid = struct.unpack_from('!L', buf, 4)[0]
+ return obj
+
+ def __eq__(self, other):
+ if type(self) != type(other): return False
+ if self.version != other.version: return False
+ if self.type != other.type: return False
+ if self.xid != other.xid: return False
+ return True
+
+ def __ne__(self, other):
+ return not self.__eq__(other)
+
+ def __str__(self):
+ return self.show()
+
+ def show(self):
+ import loxi.pp
+ return loxi.pp.pp(self)
+
+ def pretty_print(self, q):
+ q.text("barrier_request {")
+ with q.group():
+ with q.indent(2):
+ q.breakable()
+ q.text("xid = ");
+ if self.xid != None:
+ q.text("%#x" % self.xid)
+ else:
+ q.text('None')
+ q.breakable()
+ q.text('}')
+
+class bsn_get_interfaces_reply(Message):
+ version = const.OFP_VERSION
+ type = const.OFPT_VENDOR
+ experimenter = 0x5c16c7
+ subtype = 10
+
+ def __init__(self, xid=None, interfaces=None):
+ self.xid = xid
+ if interfaces != None:
+ self.interfaces = interfaces
+ else:
+ self.interfaces = []
+
+ def pack(self):
+ packed = []
+ packed.append(struct.pack("!B", self.version))
+ packed.append(struct.pack("!B", self.type))
+ packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
+ packed.append(struct.pack("!L", self.xid))
+ packed.append(struct.pack("!L", self.experimenter))
+ packed.append(struct.pack("!L", self.subtype))
+ packed.append("".join([x.pack() for x in self.interfaces]))
+ length = sum([len(x) for x in packed])
+ packed[2] = struct.pack("!H", length)
+ return ''.join(packed)
+
+ @staticmethod
+ def unpack(buf):
+ if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
+ obj = bsn_get_interfaces_reply()
+ version = struct.unpack_from('!B', buf, 0)[0]
+ assert(version == const.OFP_VERSION)
+ type = struct.unpack_from('!B', buf, 1)[0]
+ assert(type == const.OFPT_VENDOR)
+ _length = struct.unpack_from('!H', buf, 2)[0]
+ assert(_length == len(buf))
+ if _length < 16: raise loxi.ProtocolError("bsn_get_interfaces_reply length is %d, should be at least 16" % _length)
+ obj.xid = struct.unpack_from('!L', buf, 4)[0]
+ experimenter = struct.unpack_from('!L', buf, 8)[0]
+ assert(experimenter == 0x5c16c7)
+ subtype = struct.unpack_from('!L', buf, 12)[0]
+ assert(subtype == 10)
+ obj.interfaces = util.unpack_array(common.bsn_interface.unpack, 32, buffer(buf, 16))
+ return obj
+
+ def __eq__(self, other):
+ if type(self) != type(other): return False
+ if self.version != other.version: return False
+ if self.type != other.type: return False
+ if self.xid != other.xid: return False
+ if self.interfaces != other.interfaces: return False
+ return True
+
+ def __ne__(self, other):
+ return not self.__eq__(other)
+
+ def __str__(self):
+ return self.show()
+
+ def show(self):
+ import loxi.pp
+ return loxi.pp.pp(self)
+
+ def pretty_print(self, q):
+ q.text("bsn_get_interfaces_reply {")
+ with q.group():
+ with q.indent(2):
+ q.breakable()
+ q.text("xid = ");
+ if self.xid != None:
+ q.text("%#x" % self.xid)
+ else:
+ q.text('None')
+ q.text(","); q.breakable()
+ q.text("interfaces = ");
+ q.pp(self.interfaces)
+ q.breakable()
+ q.text('}')
+
+class bsn_get_interfaces_request(Message):
+ version = const.OFP_VERSION
+ type = const.OFPT_VENDOR
+ experimenter = 0x5c16c7
+ subtype = 9
+
+ def __init__(self, xid=None):
+ self.xid = xid
+
+ def pack(self):
+ packed = []
+ packed.append(struct.pack("!B", self.version))
+ packed.append(struct.pack("!B", self.type))
+ packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
+ packed.append(struct.pack("!L", self.xid))
+ packed.append(struct.pack("!L", self.experimenter))
+ packed.append(struct.pack("!L", self.subtype))
+ length = sum([len(x) for x in packed])
+ packed[2] = struct.pack("!H", length)
+ return ''.join(packed)
+
+ @staticmethod
+ def unpack(buf):
+ if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
+ obj = bsn_get_interfaces_request()
+ version = struct.unpack_from('!B', buf, 0)[0]
+ assert(version == const.OFP_VERSION)
+ type = struct.unpack_from('!B', buf, 1)[0]
+ assert(type == const.OFPT_VENDOR)
+ _length = struct.unpack_from('!H', buf, 2)[0]
+ assert(_length == len(buf))
+ if _length != 16: raise loxi.ProtocolError("bsn_get_interfaces_request length is %d, should be 16" % _length)
+ obj.xid = struct.unpack_from('!L', buf, 4)[0]
+ experimenter = struct.unpack_from('!L', buf, 8)[0]
+ assert(experimenter == 0x5c16c7)
+ subtype = struct.unpack_from('!L', buf, 12)[0]
+ assert(subtype == 9)
+ return obj
+
+ def __eq__(self, other):
+ if type(self) != type(other): return False
+ if self.version != other.version: return False
+ if self.type != other.type: return False
+ if self.xid != other.xid: return False
+ return True
+
+ def __ne__(self, other):
+ return not self.__eq__(other)
+
+ def __str__(self):
+ return self.show()
+
+ def show(self):
+ import loxi.pp
+ return loxi.pp.pp(self)
+
+ def pretty_print(self, q):
+ q.text("bsn_get_interfaces_request {")
+ with q.group():
+ with q.indent(2):
+ q.breakable()
+ q.text("xid = ");
+ if self.xid != None:
+ q.text("%#x" % self.xid)
+ else:
+ q.text('None')
+ q.breakable()
+ q.text('}')
+
+class bsn_get_ip_mask_reply(Message):
+ version = const.OFP_VERSION
+ type = const.OFPT_VENDOR
+ experimenter = 0x5c16c7
+ subtype = 2
+
+ def __init__(self, xid=None, index=None, pad=None, mask=None):
+ self.xid = xid
+ if index != None:
+ self.index = index
+ else:
+ self.index = 0
+ if pad != None:
+ self.pad = pad
+ else:
+ self.pad = [0,0,0]
+ if mask != None:
+ self.mask = mask
+ else:
+ self.mask = 0
+
+ def pack(self):
+ packed = []
+ packed.append(struct.pack("!B", self.version))
+ packed.append(struct.pack("!B", self.type))
+ packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
+ packed.append(struct.pack("!L", self.xid))
+ packed.append(struct.pack("!L", self.experimenter))
+ packed.append(struct.pack("!L", self.subtype))
+ packed.append(struct.pack("!B", self.index))
+ packed.append(struct.pack("!3B", *self.pad))
+ packed.append(struct.pack("!L", self.mask))
+ length = sum([len(x) for x in packed])
+ packed[2] = struct.pack("!H", length)
+ return ''.join(packed)
+
+ @staticmethod
+ def unpack(buf):
+ if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
+ obj = bsn_get_ip_mask_reply()
+ version = struct.unpack_from('!B', buf, 0)[0]
+ assert(version == const.OFP_VERSION)
+ type = struct.unpack_from('!B', buf, 1)[0]
+ assert(type == const.OFPT_VENDOR)
+ _length = struct.unpack_from('!H', buf, 2)[0]
+ assert(_length == len(buf))
+ if _length != 24: raise loxi.ProtocolError("bsn_get_ip_mask_reply length is %d, should be 24" % _length)
+ obj.xid = struct.unpack_from('!L', buf, 4)[0]
+ experimenter = struct.unpack_from('!L', buf, 8)[0]
+ assert(experimenter == 0x5c16c7)
+ subtype = struct.unpack_from('!L', buf, 12)[0]
+ assert(subtype == 2)
+ obj.index = struct.unpack_from('!B', buf, 16)[0]
+ obj.pad = list(struct.unpack_from('!3B', buf, 17))
+ obj.mask = struct.unpack_from('!L', buf, 20)[0]
+ return obj
+
+ def __eq__(self, other):
+ if type(self) != type(other): return False
+ if self.version != other.version: return False
+ if self.type != other.type: return False
+ if self.xid != other.xid: return False
+ if self.index != other.index: return False
+ if self.pad != other.pad: return False
+ if self.mask != other.mask: return False
+ return True
+
+ def __ne__(self, other):
+ return not self.__eq__(other)
+
+ def __str__(self):
+ return self.show()
+
+ def show(self):
+ import loxi.pp
+ return loxi.pp.pp(self)
+
+ def pretty_print(self, q):
+ q.text("bsn_get_ip_mask_reply {")
+ with q.group():
+ with q.indent(2):
+ q.breakable()
+ q.text("xid = ");
+ if self.xid != None:
+ q.text("%#x" % self.xid)
+ else:
+ q.text('None')
+ q.text(","); q.breakable()
+ q.text("index = ");
+ q.text("%#x" % self.index)
+ q.text(","); q.breakable()
+ q.text("pad = ");
+ q.pp(self.pad)
+ q.text(","); q.breakable()
+ q.text("mask = ");
+ q.text("%#x" % self.mask)
+ q.breakable()
+ q.text('}')
+
+class bsn_get_ip_mask_request(Message):
+ version = const.OFP_VERSION
+ type = const.OFPT_VENDOR
+ experimenter = 0x5c16c7
+ subtype = 1
+
+ def __init__(self, xid=None, index=None, pad=None):
+ self.xid = xid
+ if index != None:
+ self.index = index
+ else:
+ self.index = 0
+ if pad != None:
+ self.pad = pad
+ else:
+ self.pad = [0,0,0,0,0,0,0]
+
+ def pack(self):
+ packed = []
+ packed.append(struct.pack("!B", self.version))
+ packed.append(struct.pack("!B", self.type))
+ packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
+ packed.append(struct.pack("!L", self.xid))
+ packed.append(struct.pack("!L", self.experimenter))
+ packed.append(struct.pack("!L", self.subtype))
+ packed.append(struct.pack("!B", self.index))
+ packed.append(struct.pack("!7B", *self.pad))
+ length = sum([len(x) for x in packed])
+ packed[2] = struct.pack("!H", length)
+ return ''.join(packed)
+
+ @staticmethod
+ def unpack(buf):
+ if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
+ obj = bsn_get_ip_mask_request()
+ version = struct.unpack_from('!B', buf, 0)[0]
+ assert(version == const.OFP_VERSION)
+ type = struct.unpack_from('!B', buf, 1)[0]
+ assert(type == const.OFPT_VENDOR)
+ _length = struct.unpack_from('!H', buf, 2)[0]
+ assert(_length == len(buf))
+ if _length != 24: raise loxi.ProtocolError("bsn_get_ip_mask_request length is %d, should be 24" % _length)
+ obj.xid = struct.unpack_from('!L', buf, 4)[0]
+ experimenter = struct.unpack_from('!L', buf, 8)[0]
+ assert(experimenter == 0x5c16c7)
+ subtype = struct.unpack_from('!L', buf, 12)[0]
+ assert(subtype == 1)
+ obj.index = struct.unpack_from('!B', buf, 16)[0]
+ obj.pad = list(struct.unpack_from('!7B', buf, 17))
+ return obj
+
+ def __eq__(self, other):
+ if type(self) != type(other): return False
+ if self.version != other.version: return False
+ if self.type != other.type: return False
+ if self.xid != other.xid: return False
+ if self.index != other.index: return False
+ if self.pad != other.pad: return False
+ return True
+
+ def __ne__(self, other):
+ return not self.__eq__(other)
+
+ def __str__(self):
+ return self.show()
+
+ def show(self):
+ import loxi.pp
+ return loxi.pp.pp(self)
+
+ def pretty_print(self, q):
+ q.text("bsn_get_ip_mask_request {")
+ with q.group():
+ with q.indent(2):
+ q.breakable()
+ q.text("xid = ");
+ if self.xid != None:
+ q.text("%#x" % self.xid)
+ else:
+ q.text('None')
+ q.text(","); q.breakable()
+ q.text("index = ");
+ q.text("%#x" % self.index)
+ q.text(","); q.breakable()
+ q.text("pad = ");
+ q.pp(self.pad)
+ q.breakable()
+ q.text('}')
+
+class bsn_get_mirroring_reply(Message):
+ version = const.OFP_VERSION
+ type = const.OFPT_VENDOR
+ experimenter = 0x5c16c7
+ subtype = 5
+
+ def __init__(self, xid=None, report_mirror_ports=None, pad=None):
+ self.xid = xid
+ if report_mirror_ports != None:
+ self.report_mirror_ports = report_mirror_ports
+ else:
+ self.report_mirror_ports = 0
+ if pad != None:
+ self.pad = pad
+ else:
+ self.pad = [0,0,0]
+
+ def pack(self):
+ packed = []
+ packed.append(struct.pack("!B", self.version))
+ packed.append(struct.pack("!B", self.type))
+ packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
+ packed.append(struct.pack("!L", self.xid))
+ packed.append(struct.pack("!L", self.experimenter))
+ packed.append(struct.pack("!L", self.subtype))
+ packed.append(struct.pack("!B", self.report_mirror_ports))
+ packed.append(struct.pack("!3B", *self.pad))
+ length = sum([len(x) for x in packed])
+ packed[2] = struct.pack("!H", length)
+ return ''.join(packed)
+
+ @staticmethod
+ def unpack(buf):
+ if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
+ obj = bsn_get_mirroring_reply()
+ version = struct.unpack_from('!B', buf, 0)[0]
+ assert(version == const.OFP_VERSION)
+ type = struct.unpack_from('!B', buf, 1)[0]
+ assert(type == const.OFPT_VENDOR)
+ _length = struct.unpack_from('!H', buf, 2)[0]
+ assert(_length == len(buf))
+ if _length != 20: raise loxi.ProtocolError("bsn_get_mirroring_reply length is %d, should be 20" % _length)
+ obj.xid = struct.unpack_from('!L', buf, 4)[0]
+ experimenter = struct.unpack_from('!L', buf, 8)[0]
+ assert(experimenter == 0x5c16c7)
+ subtype = struct.unpack_from('!L', buf, 12)[0]
+ assert(subtype == 5)
+ obj.report_mirror_ports = struct.unpack_from('!B', buf, 16)[0]
+ obj.pad = list(struct.unpack_from('!3B', buf, 17))
+ return obj
+
+ def __eq__(self, other):
+ if type(self) != type(other): return False
+ if self.version != other.version: return False
+ if self.type != other.type: return False
+ if self.xid != other.xid: return False
+ if self.report_mirror_ports != other.report_mirror_ports: return False
+ if self.pad != other.pad: return False
+ return True
+
+ def __ne__(self, other):
+ return not self.__eq__(other)
+
+ def __str__(self):
+ return self.show()
+
+ def show(self):
+ import loxi.pp
+ return loxi.pp.pp(self)
+
+ def pretty_print(self, q):
+ q.text("bsn_get_mirroring_reply {")
+ with q.group():
+ with q.indent(2):
+ q.breakable()
+ q.text("xid = ");
+ if self.xid != None:
+ q.text("%#x" % self.xid)
+ else:
+ q.text('None')
+ q.text(","); q.breakable()
+ q.text("report_mirror_ports = ");
+ q.text("%#x" % self.report_mirror_ports)
+ q.text(","); q.breakable()
+ q.text("pad = ");
+ q.pp(self.pad)
+ q.breakable()
+ q.text('}')
+
+class bsn_get_mirroring_request(Message):
+ version = const.OFP_VERSION
+ type = const.OFPT_VENDOR
+ experimenter = 0x5c16c7
+ subtype = 4
+
+ def __init__(self, xid=None, report_mirror_ports=None, pad=None):
+ self.xid = xid
+ if report_mirror_ports != None:
+ self.report_mirror_ports = report_mirror_ports
+ else:
+ self.report_mirror_ports = 0
+ if pad != None:
+ self.pad = pad
+ else:
+ self.pad = [0,0,0]
+
+ def pack(self):
+ packed = []
+ packed.append(struct.pack("!B", self.version))
+ packed.append(struct.pack("!B", self.type))
+ packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
+ packed.append(struct.pack("!L", self.xid))
+ packed.append(struct.pack("!L", self.experimenter))
+ packed.append(struct.pack("!L", self.subtype))
+ packed.append(struct.pack("!B", self.report_mirror_ports))
+ packed.append(struct.pack("!3B", *self.pad))
+ length = sum([len(x) for x in packed])
+ packed[2] = struct.pack("!H", length)
+ return ''.join(packed)
+
+ @staticmethod
+ def unpack(buf):
+ if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
+ obj = bsn_get_mirroring_request()
+ version = struct.unpack_from('!B', buf, 0)[0]
+ assert(version == const.OFP_VERSION)
+ type = struct.unpack_from('!B', buf, 1)[0]
+ assert(type == const.OFPT_VENDOR)
+ _length = struct.unpack_from('!H', buf, 2)[0]
+ assert(_length == len(buf))
+ if _length != 20: raise loxi.ProtocolError("bsn_get_mirroring_request length is %d, should be 20" % _length)
+ obj.xid = struct.unpack_from('!L', buf, 4)[0]
+ experimenter = struct.unpack_from('!L', buf, 8)[0]
+ assert(experimenter == 0x5c16c7)
+ subtype = struct.unpack_from('!L', buf, 12)[0]
+ assert(subtype == 4)
+ obj.report_mirror_ports = struct.unpack_from('!B', buf, 16)[0]
+ obj.pad = list(struct.unpack_from('!3B', buf, 17))
+ return obj
+
+ def __eq__(self, other):
+ if type(self) != type(other): return False
+ if self.version != other.version: return False
+ if self.type != other.type: return False
+ if self.xid != other.xid: return False
+ if self.report_mirror_ports != other.report_mirror_ports: return False
+ if self.pad != other.pad: return False
+ return True
+
+ def __ne__(self, other):
+ return not self.__eq__(other)
+
+ def __str__(self):
+ return self.show()
+
+ def show(self):
+ import loxi.pp
+ return loxi.pp.pp(self)
+
+ def pretty_print(self, q):
+ q.text("bsn_get_mirroring_request {")
+ with q.group():
+ with q.indent(2):
+ q.breakable()
+ q.text("xid = ");
+ if self.xid != None:
+ q.text("%#x" % self.xid)
+ else:
+ q.text('None')
+ q.text(","); q.breakable()
+ q.text("report_mirror_ports = ");
+ q.text("%#x" % self.report_mirror_ports)
+ q.text(","); q.breakable()
+ q.text("pad = ");
+ q.pp(self.pad)
+ q.breakable()
+ q.text('}')
+
+class bsn_set_ip_mask(Message):
+ version = const.OFP_VERSION
+ type = const.OFPT_VENDOR
+ experimenter = 0x5c16c7
+ subtype = 0
+
+ def __init__(self, xid=None, index=None, pad=None, mask=None):
+ self.xid = xid
+ if index != None:
+ self.index = index
+ else:
+ self.index = 0
+ if pad != None:
+ self.pad = pad
+ else:
+ self.pad = [0,0,0]
+ if mask != None:
+ self.mask = mask
+ else:
+ self.mask = 0
+
+ def pack(self):
+ packed = []
+ packed.append(struct.pack("!B", self.version))
+ packed.append(struct.pack("!B", self.type))
+ packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
+ packed.append(struct.pack("!L", self.xid))
+ packed.append(struct.pack("!L", self.experimenter))
+ packed.append(struct.pack("!L", self.subtype))
+ packed.append(struct.pack("!B", self.index))
+ packed.append(struct.pack("!3B", *self.pad))
+ packed.append(struct.pack("!L", self.mask))
+ length = sum([len(x) for x in packed])
+ packed[2] = struct.pack("!H", length)
+ return ''.join(packed)
+
+ @staticmethod
+ def unpack(buf):
+ if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
+ obj = bsn_set_ip_mask()
+ version = struct.unpack_from('!B', buf, 0)[0]
+ assert(version == const.OFP_VERSION)
+ type = struct.unpack_from('!B', buf, 1)[0]
+ assert(type == const.OFPT_VENDOR)
+ _length = struct.unpack_from('!H', buf, 2)[0]
+ assert(_length == len(buf))
+ if _length != 24: raise loxi.ProtocolError("bsn_set_ip_mask length is %d, should be 24" % _length)
+ obj.xid = struct.unpack_from('!L', buf, 4)[0]
+ experimenter = struct.unpack_from('!L', buf, 8)[0]
+ assert(experimenter == 0x5c16c7)
+ subtype = struct.unpack_from('!L', buf, 12)[0]
+ assert(subtype == 0)
+ obj.index = struct.unpack_from('!B', buf, 16)[0]
+ obj.pad = list(struct.unpack_from('!3B', buf, 17))
+ obj.mask = struct.unpack_from('!L', buf, 20)[0]
+ return obj
+
+ def __eq__(self, other):
+ if type(self) != type(other): return False
+ if self.version != other.version: return False
+ if self.type != other.type: return False
+ if self.xid != other.xid: return False
+ if self.index != other.index: return False
+ if self.pad != other.pad: return False
+ if self.mask != other.mask: return False
+ return True
+
+ def __ne__(self, other):
+ return not self.__eq__(other)
+
+ def __str__(self):
+ return self.show()
+
+ def show(self):
+ import loxi.pp
+ return loxi.pp.pp(self)
+
+ def pretty_print(self, q):
+ q.text("bsn_set_ip_mask {")
+ with q.group():
+ with q.indent(2):
+ q.breakable()
+ q.text("xid = ");
+ if self.xid != None:
+ q.text("%#x" % self.xid)
+ else:
+ q.text('None')
+ q.text(","); q.breakable()
+ q.text("index = ");
+ q.text("%#x" % self.index)
+ q.text(","); q.breakable()
+ q.text("pad = ");
+ q.pp(self.pad)
+ q.text(","); q.breakable()
+ q.text("mask = ");
+ q.text("%#x" % self.mask)
+ q.breakable()
+ q.text('}')
+
+class bsn_set_mirroring(Message):
+ version = const.OFP_VERSION
+ type = const.OFPT_VENDOR
+ experimenter = 0x5c16c7
+ subtype = 3
+
+ def __init__(self, xid=None, report_mirror_ports=None, pad=None):
+ self.xid = xid
+ if report_mirror_ports != None:
+ self.report_mirror_ports = report_mirror_ports
+ else:
+ self.report_mirror_ports = 0
+ if pad != None:
+ self.pad = pad
+ else:
+ self.pad = [0,0,0]
+
+ def pack(self):
+ packed = []
+ packed.append(struct.pack("!B", self.version))
+ packed.append(struct.pack("!B", self.type))
+ packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
+ packed.append(struct.pack("!L", self.xid))
+ packed.append(struct.pack("!L", self.experimenter))
+ packed.append(struct.pack("!L", self.subtype))
+ packed.append(struct.pack("!B", self.report_mirror_ports))
+ packed.append(struct.pack("!3B", *self.pad))
+ length = sum([len(x) for x in packed])
+ packed[2] = struct.pack("!H", length)
+ return ''.join(packed)
+
+ @staticmethod
+ def unpack(buf):
+ if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
+ obj = bsn_set_mirroring()
+ version = struct.unpack_from('!B', buf, 0)[0]
+ assert(version == const.OFP_VERSION)
+ type = struct.unpack_from('!B', buf, 1)[0]
+ assert(type == const.OFPT_VENDOR)
+ _length = struct.unpack_from('!H', buf, 2)[0]
+ assert(_length == len(buf))
+ if _length != 20: raise loxi.ProtocolError("bsn_set_mirroring length is %d, should be 20" % _length)
+ obj.xid = struct.unpack_from('!L', buf, 4)[0]
+ experimenter = struct.unpack_from('!L', buf, 8)[0]
+ assert(experimenter == 0x5c16c7)
+ subtype = struct.unpack_from('!L', buf, 12)[0]
+ assert(subtype == 3)
+ obj.report_mirror_ports = struct.unpack_from('!B', buf, 16)[0]
+ obj.pad = list(struct.unpack_from('!3B', buf, 17))
+ return obj
+
+ def __eq__(self, other):
+ if type(self) != type(other): return False
+ if self.version != other.version: return False
+ if self.type != other.type: return False
+ if self.xid != other.xid: return False
+ if self.report_mirror_ports != other.report_mirror_ports: return False
+ if self.pad != other.pad: return False
+ return True
+
+ def __ne__(self, other):
+ return not self.__eq__(other)
+
+ def __str__(self):
+ return self.show()
+
+ def show(self):
+ import loxi.pp
+ return loxi.pp.pp(self)
+
+ def pretty_print(self, q):
+ q.text("bsn_set_mirroring {")
+ with q.group():
+ with q.indent(2):
+ q.breakable()
+ q.text("xid = ");
+ if self.xid != None:
+ q.text("%#x" % self.xid)
+ else:
+ q.text('None')
+ q.text(","); q.breakable()
+ q.text("report_mirror_ports = ");
+ q.text("%#x" % self.report_mirror_ports)
+ q.text(","); q.breakable()
+ q.text("pad = ");
+ q.pp(self.pad)
+ q.breakable()
+ q.text('}')
+
+class bsn_shell_command(Message):
+ version = const.OFP_VERSION
+ type = const.OFPT_VENDOR
+ experimenter = 0x5c16c7
+ subtype = 6
+
+ def __init__(self, xid=None, service=None, data=None):
+ self.xid = xid
+ if service != None:
+ self.service = service
+ else:
+ self.service = 0
+ if data != None:
+ self.data = data
+ else:
+ self.data = ""
+
+ def pack(self):
+ packed = []
+ packed.append(struct.pack("!B", self.version))
+ packed.append(struct.pack("!B", self.type))
+ packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
+ packed.append(struct.pack("!L", self.xid))
+ packed.append(struct.pack("!L", self.experimenter))
+ packed.append(struct.pack("!L", self.subtype))
+ packed.append(struct.pack("!L", self.service))
+ packed.append(self.data)
+ length = sum([len(x) for x in packed])
+ packed[2] = struct.pack("!H", length)
+ return ''.join(packed)
+
+ @staticmethod
+ def unpack(buf):
+ if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
+ obj = bsn_shell_command()
+ version = struct.unpack_from('!B', buf, 0)[0]
+ assert(version == const.OFP_VERSION)
+ type = struct.unpack_from('!B', buf, 1)[0]
+ assert(type == const.OFPT_VENDOR)
+ _length = struct.unpack_from('!H', buf, 2)[0]
+ assert(_length == len(buf))
+ if _length < 20: raise loxi.ProtocolError("bsn_shell_command length is %d, should be at least 20" % _length)
+ obj.xid = struct.unpack_from('!L', buf, 4)[0]
+ experimenter = struct.unpack_from('!L', buf, 8)[0]
+ assert(experimenter == 0x5c16c7)
+ subtype = struct.unpack_from('!L', buf, 12)[0]
+ assert(subtype == 6)
+ obj.service = struct.unpack_from('!L', buf, 16)[0]
+ obj.data = buf[20:]
+ return obj
+
+ def __eq__(self, other):
+ if type(self) != type(other): return False
+ if self.version != other.version: return False
+ if self.type != other.type: return False
+ if self.xid != other.xid: return False
+ if self.service != other.service: return False
+ if self.data != other.data: return False
+ return True
+
+ def __ne__(self, other):
+ return not self.__eq__(other)
+
+ def __str__(self):
+ return self.show()
+
+ def show(self):
+ import loxi.pp
+ return loxi.pp.pp(self)
+
+ def pretty_print(self, q):
+ q.text("bsn_shell_command {")
+ with q.group():
+ with q.indent(2):
+ q.breakable()
+ q.text("xid = ");
+ if self.xid != None:
+ q.text("%#x" % self.xid)
+ else:
+ q.text('None')
+ q.text(","); q.breakable()
+ q.text("service = ");
+ q.text("%#x" % self.service)
+ q.text(","); q.breakable()
+ q.text("data = ");
+ q.pp(self.data)
+ q.breakable()
+ q.text('}')
+
+class bsn_shell_output(Message):
+ version = const.OFP_VERSION
+ type = const.OFPT_VENDOR
+ experimenter = 0x5c16c7
+ subtype = 7
+
+ def __init__(self, xid=None, data=None):
+ self.xid = xid
+ if data != None:
+ self.data = data
+ else:
+ self.data = ""
+
+ def pack(self):
+ packed = []
+ packed.append(struct.pack("!B", self.version))
+ packed.append(struct.pack("!B", self.type))
+ packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
+ packed.append(struct.pack("!L", self.xid))
+ packed.append(struct.pack("!L", self.experimenter))
+ packed.append(struct.pack("!L", self.subtype))
+ packed.append(self.data)
+ length = sum([len(x) for x in packed])
+ packed[2] = struct.pack("!H", length)
+ return ''.join(packed)
+
+ @staticmethod
+ def unpack(buf):
+ if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
+ obj = bsn_shell_output()
+ version = struct.unpack_from('!B', buf, 0)[0]
+ assert(version == const.OFP_VERSION)
+ type = struct.unpack_from('!B', buf, 1)[0]
+ assert(type == const.OFPT_VENDOR)
+ _length = struct.unpack_from('!H', buf, 2)[0]
+ assert(_length == len(buf))
+ if _length < 16: raise loxi.ProtocolError("bsn_shell_output length is %d, should be at least 16" % _length)
+ obj.xid = struct.unpack_from('!L', buf, 4)[0]
+ experimenter = struct.unpack_from('!L', buf, 8)[0]
+ assert(experimenter == 0x5c16c7)
+ subtype = struct.unpack_from('!L', buf, 12)[0]
+ assert(subtype == 7)
+ obj.data = buf[16:]
+ return obj
+
+ def __eq__(self, other):
+ if type(self) != type(other): return False
+ if self.version != other.version: return False
+ if self.type != other.type: return False
+ if self.xid != other.xid: return False
+ if self.data != other.data: return False
+ return True
+
+ def __ne__(self, other):
+ return not self.__eq__(other)
+
+ def __str__(self):
+ return self.show()
+
+ def show(self):
+ import loxi.pp
+ return loxi.pp.pp(self)
+
+ def pretty_print(self, q):
+ q.text("bsn_shell_output {")
+ with q.group():
+ with q.indent(2):
+ q.breakable()
+ q.text("xid = ");
+ if self.xid != None:
+ q.text("%#x" % self.xid)
+ else:
+ q.text('None')
+ q.text(","); q.breakable()
+ q.text("data = ");
+ q.pp(self.data)
+ q.breakable()
+ q.text('}')
+
+class bsn_shell_status(Message):
+ version = const.OFP_VERSION
+ type = const.OFPT_VENDOR
+ experimenter = 0x5c16c7
+ subtype = 8
+
+ def __init__(self, xid=None, status=None):
+ self.xid = xid
+ if status != None:
+ self.status = status
+ else:
+ self.status = 0
+
+ def pack(self):
+ packed = []
+ packed.append(struct.pack("!B", self.version))
+ packed.append(struct.pack("!B", self.type))
+ packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
+ packed.append(struct.pack("!L", self.xid))
+ packed.append(struct.pack("!L", self.experimenter))
+ packed.append(struct.pack("!L", self.subtype))
+ packed.append(struct.pack("!L", self.status))
+ length = sum([len(x) for x in packed])
+ packed[2] = struct.pack("!H", length)
+ return ''.join(packed)
+
+ @staticmethod
+ def unpack(buf):
+ if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
+ obj = bsn_shell_status()
+ version = struct.unpack_from('!B', buf, 0)[0]
+ assert(version == const.OFP_VERSION)
+ type = struct.unpack_from('!B', buf, 1)[0]
+ assert(type == const.OFPT_VENDOR)
+ _length = struct.unpack_from('!H', buf, 2)[0]
+ assert(_length == len(buf))
+ if _length != 20: raise loxi.ProtocolError("bsn_shell_status length is %d, should be 20" % _length)
+ obj.xid = struct.unpack_from('!L', buf, 4)[0]
+ experimenter = struct.unpack_from('!L', buf, 8)[0]
+ assert(experimenter == 0x5c16c7)
+ subtype = struct.unpack_from('!L', buf, 12)[0]
+ assert(subtype == 8)
+ obj.status = struct.unpack_from('!L', buf, 16)[0]
+ return obj
+
+ def __eq__(self, other):
+ if type(self) != type(other): return False
+ if self.version != other.version: return False
+ if self.type != other.type: return False
+ if self.xid != other.xid: return False
+ if self.status != other.status: return False
+ return True
+
+ def __ne__(self, other):
+ return not self.__eq__(other)
+
+ def __str__(self):
+ return self.show()
+
+ def show(self):
+ import loxi.pp
+ return loxi.pp.pp(self)
+
+ def pretty_print(self, q):
+ q.text("bsn_shell_status {")
+ with q.group():
+ with q.indent(2):
+ q.breakable()
+ q.text("xid = ");
+ if self.xid != None:
+ q.text("%#x" % self.xid)
+ else:
+ q.text('None')
+ q.text(","); q.breakable()
+ q.text("status = ");
+ q.text("%#x" % self.status)
+ q.breakable()
+ q.text('}')
+
+class desc_stats_reply(Message):
+ version = const.OFP_VERSION
+ type = const.OFPT_STATS_REPLY
+ stats_type = const.OFPST_DESC
+
+ def __init__(self, xid=None, flags=None, mfr_desc=None, hw_desc=None, sw_desc=None, serial_num=None, dp_desc=None):
+ self.xid = xid
+ if flags != None:
+ self.flags = flags
+ else:
+ self.flags = 0
+ if mfr_desc != None:
+ self.mfr_desc = mfr_desc
+ else:
+ self.mfr_desc = ""
+ if hw_desc != None:
+ self.hw_desc = hw_desc
+ else:
+ self.hw_desc = ""
+ if sw_desc != None:
+ self.sw_desc = sw_desc
+ else:
+ self.sw_desc = ""
+ if serial_num != None:
+ self.serial_num = serial_num
+ else:
+ self.serial_num = ""
+ if dp_desc != None:
+ self.dp_desc = dp_desc
+ else:
+ self.dp_desc = ""
+
+ def pack(self):
+ packed = []
+ packed.append(struct.pack("!B", self.version))
+ packed.append(struct.pack("!B", self.type))
+ packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
+ packed.append(struct.pack("!L", self.xid))
+ packed.append(struct.pack("!H", self.stats_type))
+ packed.append(struct.pack("!H", self.flags))
+ packed.append(struct.pack("!256s", self.mfr_desc))
+ packed.append(struct.pack("!256s", self.hw_desc))
+ packed.append(struct.pack("!256s", self.sw_desc))
+ packed.append(struct.pack("!32s", self.serial_num))
+ packed.append(struct.pack("!256s", self.dp_desc))
+ length = sum([len(x) for x in packed])
+ packed[2] = struct.pack("!H", length)
+ return ''.join(packed)
+
+ @staticmethod
+ def unpack(buf):
+ if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
+ obj = desc_stats_reply()
+ version = struct.unpack_from('!B', buf, 0)[0]
+ assert(version == const.OFP_VERSION)
+ type = struct.unpack_from('!B', buf, 1)[0]
+ assert(type == const.OFPT_STATS_REPLY)
+ _length = struct.unpack_from('!H', buf, 2)[0]
+ assert(_length == len(buf))
+ if _length != 1068: raise loxi.ProtocolError("desc_stats_reply length is %d, should be 1068" % _length)
+ obj.xid = struct.unpack_from('!L', buf, 4)[0]
+ stats_type = struct.unpack_from('!H', buf, 8)[0]
+ assert(stats_type == const.OFPST_DESC)
+ obj.flags = struct.unpack_from('!H', buf, 10)[0]
+ obj.mfr_desc = str(buffer(buf, 12, 256)).rstrip("\x00")
+ obj.hw_desc = str(buffer(buf, 268, 256)).rstrip("\x00")
+ obj.sw_desc = str(buffer(buf, 524, 256)).rstrip("\x00")
+ obj.serial_num = str(buffer(buf, 780, 32)).rstrip("\x00")
+ obj.dp_desc = str(buffer(buf, 812, 256)).rstrip("\x00")
+ return obj
+
+ def __eq__(self, other):
+ if type(self) != type(other): return False
+ if self.version != other.version: return False
+ if self.type != other.type: return False
+ if self.xid != other.xid: return False
+ if self.flags != other.flags: return False
+ if self.mfr_desc != other.mfr_desc: return False
+ if self.hw_desc != other.hw_desc: return False
+ if self.sw_desc != other.sw_desc: return False
+ if self.serial_num != other.serial_num: return False
+ if self.dp_desc != other.dp_desc: return False
+ return True
+
+ def __ne__(self, other):
+ return not self.__eq__(other)
+
+ def __str__(self):
+ return self.show()
+
+ def show(self):
+ import loxi.pp
+ return loxi.pp.pp(self)
+
+ def pretty_print(self, q):
+ q.text("desc_stats_reply {")
+ with q.group():
+ with q.indent(2):
+ q.breakable()
+ q.text("xid = ");
+ if self.xid != None:
+ q.text("%#x" % self.xid)
+ else:
+ q.text('None')
+ q.text(","); q.breakable()
+ q.text("flags = ");
+ q.text("%#x" % self.flags)
+ q.text(","); q.breakable()
+ q.text("mfr_desc = ");
+ q.pp(self.mfr_desc)
+ q.text(","); q.breakable()
+ q.text("hw_desc = ");
+ q.pp(self.hw_desc)
+ q.text(","); q.breakable()
+ q.text("sw_desc = ");
+ q.pp(self.sw_desc)
+ q.text(","); q.breakable()
+ q.text("serial_num = ");
+ q.pp(self.serial_num)
+ q.text(","); q.breakable()
+ q.text("dp_desc = ");
+ q.pp(self.dp_desc)
+ q.breakable()
+ q.text('}')
+
+class desc_stats_request(Message):
+ version = const.OFP_VERSION
+ type = const.OFPT_STATS_REQUEST
+ stats_type = const.OFPST_DESC
+
+ def __init__(self, xid=None, flags=None):
+ self.xid = xid
+ if flags != None:
+ self.flags = flags
+ else:
+ self.flags = 0
+
+ def pack(self):
+ packed = []
+ packed.append(struct.pack("!B", self.version))
+ packed.append(struct.pack("!B", self.type))
+ packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
+ packed.append(struct.pack("!L", self.xid))
+ packed.append(struct.pack("!H", self.stats_type))
+ packed.append(struct.pack("!H", self.flags))
+ length = sum([len(x) for x in packed])
+ packed[2] = struct.pack("!H", length)
+ return ''.join(packed)
+
+ @staticmethod
+ def unpack(buf):
+ if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
+ obj = desc_stats_request()
+ version = struct.unpack_from('!B', buf, 0)[0]
+ assert(version == const.OFP_VERSION)
+ type = struct.unpack_from('!B', buf, 1)[0]
+ assert(type == const.OFPT_STATS_REQUEST)
+ _length = struct.unpack_from('!H', buf, 2)[0]
+ assert(_length == len(buf))
+ if _length != 12: raise loxi.ProtocolError("desc_stats_request length is %d, should be 12" % _length)
+ obj.xid = struct.unpack_from('!L', buf, 4)[0]
+ stats_type = struct.unpack_from('!H', buf, 8)[0]
+ assert(stats_type == const.OFPST_DESC)
+ obj.flags = struct.unpack_from('!H', buf, 10)[0]
+ return obj
+
+ def __eq__(self, other):
+ if type(self) != type(other): return False
+ if self.version != other.version: return False
+ if self.type != other.type: return False
+ if self.xid != other.xid: return False
+ if self.flags != other.flags: return False
+ return True
+
+ def __ne__(self, other):
+ return not self.__eq__(other)
+
+ def __str__(self):
+ return self.show()
+
+ def show(self):
+ import loxi.pp
+ return loxi.pp.pp(self)
+
+ def pretty_print(self, q):
+ q.text("desc_stats_request {")
+ with q.group():
+ with q.indent(2):
+ q.breakable()
+ q.text("xid = ");
+ if self.xid != None:
+ q.text("%#x" % self.xid)
+ else:
+ q.text('None')
+ q.text(","); q.breakable()
+ q.text("flags = ");
+ q.text("%#x" % self.flags)
+ q.breakable()
+ q.text('}')
+
+class echo_reply(Message):
+ version = const.OFP_VERSION
+ type = const.OFPT_ECHO_REPLY
+
+ def __init__(self, xid=None, data=None):
+ self.xid = xid
+ if data != None:
+ self.data = data
+ else:
+ self.data = ""
+
+ def pack(self):
+ packed = []
+ packed.append(struct.pack("!B", self.version))
+ packed.append(struct.pack("!B", self.type))
+ packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
+ packed.append(struct.pack("!L", self.xid))
+ packed.append(self.data)
+ length = sum([len(x) for x in packed])
+ packed[2] = struct.pack("!H", length)
+ return ''.join(packed)
+
+ @staticmethod
+ def unpack(buf):
+ if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
+ obj = echo_reply()
+ version = struct.unpack_from('!B', buf, 0)[0]
+ assert(version == const.OFP_VERSION)
+ type = struct.unpack_from('!B', buf, 1)[0]
+ assert(type == const.OFPT_ECHO_REPLY)
+ _length = struct.unpack_from('!H', buf, 2)[0]
+ assert(_length == len(buf))
+ if _length < 8: raise loxi.ProtocolError("echo_reply length is %d, should be at least 8" % _length)
+ obj.xid = struct.unpack_from('!L', buf, 4)[0]
+ obj.data = buf[8:]
+ return obj
+
+ def __eq__(self, other):
+ if type(self) != type(other): return False
+ if self.version != other.version: return False
+ if self.type != other.type: return False
+ if self.xid != other.xid: return False
+ if self.data != other.data: return False
+ return True
+
+ def __ne__(self, other):
+ return not self.__eq__(other)
+
+ def __str__(self):
+ return self.show()
+
+ def show(self):
+ import loxi.pp
+ return loxi.pp.pp(self)
+
+ def pretty_print(self, q):
+ q.text("echo_reply {")
+ with q.group():
+ with q.indent(2):
+ q.breakable()
+ q.text("xid = ");
+ if self.xid != None:
+ q.text("%#x" % self.xid)
+ else:
+ q.text('None')
+ q.text(","); q.breakable()
+ q.text("data = ");
+ q.pp(self.data)
+ q.breakable()
+ q.text('}')
+
+class echo_request(Message):
+ version = const.OFP_VERSION
+ type = const.OFPT_ECHO_REQUEST
+
+ def __init__(self, xid=None, data=None):
+ self.xid = xid
+ if data != None:
+ self.data = data
+ else:
+ self.data = ""
+
+ def pack(self):
+ packed = []
+ packed.append(struct.pack("!B", self.version))
+ packed.append(struct.pack("!B", self.type))
+ packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
+ packed.append(struct.pack("!L", self.xid))
+ packed.append(self.data)
+ length = sum([len(x) for x in packed])
+ packed[2] = struct.pack("!H", length)
+ return ''.join(packed)
+
+ @staticmethod
+ def unpack(buf):
+ if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
+ obj = echo_request()
+ version = struct.unpack_from('!B', buf, 0)[0]
+ assert(version == const.OFP_VERSION)
+ type = struct.unpack_from('!B', buf, 1)[0]
+ assert(type == const.OFPT_ECHO_REQUEST)
+ _length = struct.unpack_from('!H', buf, 2)[0]
+ assert(_length == len(buf))
+ if _length < 8: raise loxi.ProtocolError("echo_request length is %d, should be at least 8" % _length)
+ obj.xid = struct.unpack_from('!L', buf, 4)[0]
+ obj.data = buf[8:]
+ return obj
+
+ def __eq__(self, other):
+ if type(self) != type(other): return False
+ if self.version != other.version: return False
+ if self.type != other.type: return False
+ if self.xid != other.xid: return False
+ if self.data != other.data: return False
+ return True
+
+ def __ne__(self, other):
+ return not self.__eq__(other)
+
+ def __str__(self):
+ return self.show()
+
+ def show(self):
+ import loxi.pp
+ return loxi.pp.pp(self)
+
+ def pretty_print(self, q):
+ q.text("echo_request {")
+ with q.group():
+ with q.indent(2):
+ q.breakable()
+ q.text("xid = ");
+ if self.xid != None:
+ q.text("%#x" % self.xid)
+ else:
+ q.text('None')
+ q.text(","); q.breakable()
+ q.text("data = ");
+ q.pp(self.data)
+ q.breakable()
+ q.text('}')
+
+class error_msg(Message):
+ version = const.OFP_VERSION
+ type = const.OFPT_ERROR
+
+ def __init__(self, xid=None, err_type=None, code=None, data=None):
+ self.xid = xid
+ if err_type != None:
+ self.err_type = err_type
+ else:
+ self.err_type = 0
+ if code != None:
+ self.code = code
+ else:
+ self.code = 0
+ if data != None:
+ self.data = data
+ else:
+ self.data = ""
+
+ def pack(self):
+ packed = []
+ packed.append(struct.pack("!B", self.version))
+ packed.append(struct.pack("!B", self.type))
+ packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
+ packed.append(struct.pack("!L", self.xid))
+ packed.append(struct.pack("!H", self.err_type))
+ packed.append(struct.pack("!H", self.code))
+ packed.append(self.data)
+ length = sum([len(x) for x in packed])
+ packed[2] = struct.pack("!H", length)
+ return ''.join(packed)
+
+ @staticmethod
+ def unpack(buf):
+ if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
+ obj = error_msg()
+ version = struct.unpack_from('!B', buf, 0)[0]
+ assert(version == const.OFP_VERSION)
+ type = struct.unpack_from('!B', buf, 1)[0]
+ assert(type == const.OFPT_ERROR)
+ _length = struct.unpack_from('!H', buf, 2)[0]
+ assert(_length == len(buf))
+ if _length < 12: raise loxi.ProtocolError("error_msg length is %d, should be at least 12" % _length)
+ obj.xid = struct.unpack_from('!L', buf, 4)[0]
+ obj.err_type = struct.unpack_from('!H', buf, 8)[0]
+ obj.code = struct.unpack_from('!H', buf, 10)[0]
+ obj.data = buf[12:]
+ return obj
+
+ def __eq__(self, other):
+ if type(self) != type(other): return False
+ if self.version != other.version: return False
+ if self.type != other.type: return False
+ if self.xid != other.xid: return False
+ if self.err_type != other.err_type: return False
+ if self.code != other.code: return False
+ if self.data != other.data: return False
+ return True
+
+ def __ne__(self, other):
+ return not self.__eq__(other)
+
+ def __str__(self):
+ return self.show()
+
+ def show(self):
+ import loxi.pp
+ return loxi.pp.pp(self)
+
+ def pretty_print(self, q):
+ q.text("error_msg {")
+ with q.group():
+ with q.indent(2):
+ q.breakable()
+ q.text("xid = ");
+ if self.xid != None:
+ q.text("%#x" % self.xid)
+ else:
+ q.text('None')
+ q.text(","); q.breakable()
+ q.text("err_type = ");
+ q.text("%#x" % self.err_type)
+ q.text(","); q.breakable()
+ q.text("code = ");
+ q.text("%#x" % self.code)
+ q.text(","); q.breakable()
+ q.text("data = ");
+ q.pp(self.data)
+ q.breakable()
+ q.text('}')
+
+class experimenter_stats_reply(Message):
+ version = const.OFP_VERSION
+ type = const.OFPT_STATS_REPLY
+ stats_type = const.OFPST_VENDOR
+
+ def __init__(self, xid=None, flags=None, experimenter=None, data=None):
+ self.xid = xid
+ if flags != None:
+ self.flags = flags
+ else:
+ self.flags = 0
+ if experimenter != None:
+ self.experimenter = experimenter
+ else:
+ self.experimenter = 0
+ if data != None:
+ self.data = data
+ else:
+ self.data = ""
+
+ def pack(self):
+ packed = []
+ packed.append(struct.pack("!B", self.version))
+ packed.append(struct.pack("!B", self.type))
+ packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
+ packed.append(struct.pack("!L", self.xid))
+ packed.append(struct.pack("!H", self.stats_type))
+ packed.append(struct.pack("!H", self.flags))
+ packed.append(struct.pack("!L", self.experimenter))
+ packed.append(self.data)
+ length = sum([len(x) for x in packed])
+ packed[2] = struct.pack("!H", length)
+ return ''.join(packed)
+
+ @staticmethod
+ def unpack(buf):
+ if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
+ obj = experimenter_stats_reply()
+ version = struct.unpack_from('!B', buf, 0)[0]
+ assert(version == const.OFP_VERSION)
+ type = struct.unpack_from('!B', buf, 1)[0]
+ assert(type == const.OFPT_STATS_REPLY)
+ _length = struct.unpack_from('!H', buf, 2)[0]
+ assert(_length == len(buf))
+ if _length < 16: raise loxi.ProtocolError("experimenter_stats_reply length is %d, should be at least 16" % _length)
+ obj.xid = struct.unpack_from('!L', buf, 4)[0]
+ stats_type = struct.unpack_from('!H', buf, 8)[0]
+ assert(stats_type == const.OFPST_VENDOR)
+ obj.flags = struct.unpack_from('!H', buf, 10)[0]
+ obj.experimenter = struct.unpack_from('!L', buf, 12)[0]
+ obj.data = buf[16:]
+ return obj
+
+ def __eq__(self, other):
+ if type(self) != type(other): return False
+ if self.version != other.version: return False
+ if self.type != other.type: return False
+ if self.xid != other.xid: return False
+ if self.flags != other.flags: return False
+ if self.experimenter != other.experimenter: return False
+ if self.data != other.data: return False
+ return True
+
+ def __ne__(self, other):
+ return not self.__eq__(other)
+
+ def __str__(self):
+ return self.show()
+
+ def show(self):
+ import loxi.pp
+ return loxi.pp.pp(self)
+
+ def pretty_print(self, q):
+ q.text("experimenter_stats_reply {")
+ with q.group():
+ with q.indent(2):
+ q.breakable()
+ q.text("xid = ");
+ if self.xid != None:
+ q.text("%#x" % self.xid)
+ else:
+ q.text('None')
+ q.text(","); q.breakable()
+ q.text("flags = ");
+ q.text("%#x" % self.flags)
+ q.text(","); q.breakable()
+ q.text("experimenter = ");
+ q.text("%#x" % self.experimenter)
+ q.text(","); q.breakable()
+ q.text("data = ");
+ q.pp(self.data)
+ q.breakable()
+ q.text('}')
+
+class experimenter_stats_request(Message):
+ version = const.OFP_VERSION
+ type = const.OFPT_STATS_REQUEST
+ stats_type = const.OFPST_VENDOR
+
+ def __init__(self, xid=None, flags=None, experimenter=None, data=None):
+ self.xid = xid
+ if flags != None:
+ self.flags = flags
+ else:
+ self.flags = 0
+ if experimenter != None:
+ self.experimenter = experimenter
+ else:
+ self.experimenter = 0
+ if data != None:
+ self.data = data
+ else:
+ self.data = ""
+
+ def pack(self):
+ packed = []
+ packed.append(struct.pack("!B", self.version))
+ packed.append(struct.pack("!B", self.type))
+ packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
+ packed.append(struct.pack("!L", self.xid))
+ packed.append(struct.pack("!H", self.stats_type))
+ packed.append(struct.pack("!H", self.flags))
+ packed.append(struct.pack("!L", self.experimenter))
+ packed.append(self.data)
+ length = sum([len(x) for x in packed])
+ packed[2] = struct.pack("!H", length)
+ return ''.join(packed)
+
+ @staticmethod
+ def unpack(buf):
+ if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
+ obj = experimenter_stats_request()
+ version = struct.unpack_from('!B', buf, 0)[0]
+ assert(version == const.OFP_VERSION)
+ type = struct.unpack_from('!B', buf, 1)[0]
+ assert(type == const.OFPT_STATS_REQUEST)
+ _length = struct.unpack_from('!H', buf, 2)[0]
+ assert(_length == len(buf))
+ if _length < 16: raise loxi.ProtocolError("experimenter_stats_request length is %d, should be at least 16" % _length)
+ obj.xid = struct.unpack_from('!L', buf, 4)[0]
+ stats_type = struct.unpack_from('!H', buf, 8)[0]
+ assert(stats_type == const.OFPST_VENDOR)
+ obj.flags = struct.unpack_from('!H', buf, 10)[0]
+ obj.experimenter = struct.unpack_from('!L', buf, 12)[0]
+ obj.data = buf[16:]
+ return obj
+
+ def __eq__(self, other):
+ if type(self) != type(other): return False
+ if self.version != other.version: return False
+ if self.type != other.type: return False
+ if self.xid != other.xid: return False
+ if self.flags != other.flags: return False
+ if self.experimenter != other.experimenter: return False
+ if self.data != other.data: return False
+ return True
+
+ def __ne__(self, other):
+ return not self.__eq__(other)
+
+ def __str__(self):
+ return self.show()
+
+ def show(self):
+ import loxi.pp
+ return loxi.pp.pp(self)
+
+ def pretty_print(self, q):
+ q.text("experimenter_stats_request {")
+ with q.group():
+ with q.indent(2):
+ q.breakable()
+ q.text("xid = ");
+ if self.xid != None:
+ q.text("%#x" % self.xid)
+ else:
+ q.text('None')
+ q.text(","); q.breakable()
+ q.text("flags = ");
+ q.text("%#x" % self.flags)
+ q.text(","); q.breakable()
+ q.text("experimenter = ");
+ q.text("%#x" % self.experimenter)
+ q.text(","); q.breakable()
+ q.text("data = ");
+ q.pp(self.data)
+ q.breakable()
+ q.text('}')
+
+class features_reply(Message):
+ version = const.OFP_VERSION
+ type = const.OFPT_FEATURES_REPLY
+
+ def __init__(self, xid=None, datapath_id=None, n_buffers=None, n_tables=None, pad=None, capabilities=None, actions=None, ports=None):
+ self.xid = xid
+ if datapath_id != None:
+ self.datapath_id = datapath_id
+ else:
+ self.datapath_id = 0
+ if n_buffers != None:
+ self.n_buffers = n_buffers
+ else:
+ self.n_buffers = 0
+ if n_tables != None:
+ self.n_tables = n_tables
+ else:
+ self.n_tables = 0
+ if pad != None:
+ self.pad = pad
+ else:
+ self.pad = [0,0,0]
+ if capabilities != None:
+ self.capabilities = capabilities
+ else:
+ self.capabilities = 0
+ if actions != None:
+ self.actions = actions
+ else:
+ self.actions = 0
+ if ports != None:
+ self.ports = ports
+ else:
+ self.ports = []
+
+ def pack(self):
+ packed = []
+ packed.append(struct.pack("!B", self.version))
+ packed.append(struct.pack("!B", self.type))
+ packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
+ packed.append(struct.pack("!L", self.xid))
+ packed.append(struct.pack("!Q", self.datapath_id))
+ packed.append(struct.pack("!L", self.n_buffers))
+ packed.append(struct.pack("!B", self.n_tables))
+ packed.append(struct.pack("!3B", *self.pad))
+ packed.append(struct.pack("!L", self.capabilities))
+ packed.append(struct.pack("!L", self.actions))
+ packed.append("".join([x.pack() for x in self.ports]))
+ length = sum([len(x) for x in packed])
+ packed[2] = struct.pack("!H", length)
+ return ''.join(packed)
+
+ @staticmethod
+ def unpack(buf):
+ if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
+ obj = features_reply()
+ version = struct.unpack_from('!B', buf, 0)[0]
+ assert(version == const.OFP_VERSION)
+ type = struct.unpack_from('!B', buf, 1)[0]
+ assert(type == const.OFPT_FEATURES_REPLY)
+ _length = struct.unpack_from('!H', buf, 2)[0]
+ assert(_length == len(buf))
+ if _length < 32: raise loxi.ProtocolError("features_reply length is %d, should be at least 32" % _length)
+ obj.xid = struct.unpack_from('!L', buf, 4)[0]
+ obj.datapath_id = struct.unpack_from('!Q', buf, 8)[0]
+ obj.n_buffers = struct.unpack_from('!L', buf, 16)[0]
+ obj.n_tables = struct.unpack_from('!B', buf, 20)[0]
+ obj.pad = list(struct.unpack_from('!3B', buf, 21))
+ obj.capabilities = struct.unpack_from('!L', buf, 24)[0]
+ obj.actions = struct.unpack_from('!L', buf, 28)[0]
+ obj.ports = util.unpack_array(common.port_desc.unpack, 48, buffer(buf, 32))
+ return obj
+
+ def __eq__(self, other):
+ if type(self) != type(other): return False
+ if self.version != other.version: return False
+ if self.type != other.type: return False
+ if self.xid != other.xid: return False
+ if self.datapath_id != other.datapath_id: return False
+ if self.n_buffers != other.n_buffers: return False
+ if self.n_tables != other.n_tables: return False
+ if self.pad != other.pad: return False
+ if self.capabilities != other.capabilities: return False
+ if self.actions != other.actions: return False
+ if self.ports != other.ports: return False
+ return True
+
+ def __ne__(self, other):
+ return not self.__eq__(other)
+
+ def __str__(self):
+ return self.show()
+
+ def show(self):
+ import loxi.pp
+ return loxi.pp.pp(self)
+
+ def pretty_print(self, q):
+ q.text("features_reply {")
+ with q.group():
+ with q.indent(2):
+ q.breakable()
+ q.text("xid = ");
+ if self.xid != None:
+ q.text("%#x" % self.xid)
+ else:
+ q.text('None')
+ q.text(","); q.breakable()
+ q.text("datapath_id = ");
+ q.text("%#x" % self.datapath_id)
+ q.text(","); q.breakable()
+ q.text("n_buffers = ");
+ q.text("%#x" % self.n_buffers)
+ q.text(","); q.breakable()
+ q.text("n_tables = ");
+ q.text("%#x" % self.n_tables)
+ q.text(","); q.breakable()
+ q.text("pad = ");
+ q.pp(self.pad)
+ q.text(","); q.breakable()
+ q.text("capabilities = ");
+ q.text("%#x" % self.capabilities)
+ q.text(","); q.breakable()
+ q.text("actions = ");
+ q.text("%#x" % self.actions)
+ q.text(","); q.breakable()
+ q.text("ports = ");
+ q.pp(self.ports)
+ q.breakable()
+ q.text('}')
+
+class features_request(Message):
+ version = const.OFP_VERSION
+ type = const.OFPT_FEATURES_REQUEST
+
+ def __init__(self, xid=None):
+ self.xid = xid
+
+ def pack(self):
+ packed = []
+ packed.append(struct.pack("!B", self.version))
+ packed.append(struct.pack("!B", self.type))
+ packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
+ packed.append(struct.pack("!L", self.xid))
+ length = sum([len(x) for x in packed])
+ packed[2] = struct.pack("!H", length)
+ return ''.join(packed)
+
+ @staticmethod
+ def unpack(buf):
+ if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
+ obj = features_request()
+ version = struct.unpack_from('!B', buf, 0)[0]
+ assert(version == const.OFP_VERSION)
+ type = struct.unpack_from('!B', buf, 1)[0]
+ assert(type == const.OFPT_FEATURES_REQUEST)
+ _length = struct.unpack_from('!H', buf, 2)[0]
+ assert(_length == len(buf))
+ if _length != 8: raise loxi.ProtocolError("features_request length is %d, should be 8" % _length)
+ obj.xid = struct.unpack_from('!L', buf, 4)[0]
+ return obj
+
+ def __eq__(self, other):
+ if type(self) != type(other): return False
+ if self.version != other.version: return False
+ if self.type != other.type: return False
+ if self.xid != other.xid: return False
+ return True
+
+ def __ne__(self, other):
+ return not self.__eq__(other)
+
+ def __str__(self):
+ return self.show()
+
+ def show(self):
+ import loxi.pp
+ return loxi.pp.pp(self)
+
+ def pretty_print(self, q):
+ q.text("features_request {")
+ with q.group():
+ with q.indent(2):
+ q.breakable()
+ q.text("xid = ");
+ if self.xid != None:
+ q.text("%#x" % self.xid)
+ else:
+ q.text('None')
+ q.breakable()
+ q.text('}')
+
+class flow_add(Message):
+ version = const.OFP_VERSION
+ type = const.OFPT_FLOW_MOD
+ _command = const.OFPFC_ADD
+
+ 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):
+ self.xid = xid
+ if match != None:
+ self.match = match
+ else:
+ self.match = common.match()
+ if cookie != None:
+ self.cookie = cookie
+ else:
+ self.cookie = 0
+ if idle_timeout != None:
+ self.idle_timeout = idle_timeout
+ else:
+ self.idle_timeout = 0
+ if hard_timeout != None:
+ self.hard_timeout = hard_timeout
+ else:
+ self.hard_timeout = 0
+ if priority != None:
+ self.priority = priority
+ else:
+ self.priority = 0
+ if buffer_id != None:
+ self.buffer_id = buffer_id
+ else:
+ self.buffer_id = 0
+ if out_port != None:
+ self.out_port = out_port
+ else:
+ self.out_port = 0
+ if flags != None:
+ self.flags = flags
+ else:
+ self.flags = 0
+ if actions != None:
+ self.actions = actions
+ else:
+ self.actions = []
+
+ def pack(self):
+ packed = []
+ packed.append(struct.pack("!B", self.version))
+ packed.append(struct.pack("!B", self.type))
+ packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
+ packed.append(struct.pack("!L", self.xid))
+ packed.append(self.match.pack())
+ packed.append(struct.pack("!Q", self.cookie))
+ packed.append(struct.pack("!H", self._command))
+ packed.append(struct.pack("!H", self.idle_timeout))
+ packed.append(struct.pack("!H", self.hard_timeout))
+ packed.append(struct.pack("!H", self.priority))
+ packed.append(struct.pack("!L", self.buffer_id))
+ packed.append(struct.pack("!H", self.out_port))
+ packed.append(struct.pack("!H", self.flags))
+ packed.append("".join([x.pack() for x in self.actions]))
+ length = sum([len(x) for x in packed])
+ packed[2] = struct.pack("!H", length)
+ return ''.join(packed)
+
+ @staticmethod
+ def unpack(buf):
+ if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
+ obj = flow_add()
+ version = struct.unpack_from('!B', buf, 0)[0]
+ assert(version == const.OFP_VERSION)
+ type = struct.unpack_from('!B', buf, 1)[0]
+ assert(type == const.OFPT_FLOW_MOD)
+ _length = struct.unpack_from('!H', buf, 2)[0]
+ assert(_length == len(buf))
+ if _length < 72: raise loxi.ProtocolError("flow_add length is %d, should be at least 72" % _length)
+ obj.xid = struct.unpack_from('!L', buf, 4)[0]
+ obj.match = common.match.unpack(buffer(buf, 8))
+ obj.cookie = struct.unpack_from('!Q', buf, 48)[0]
+ _command = struct.unpack_from('!H', buf, 56)[0]
+ assert(_command == const.OFPFC_ADD)
+ obj.idle_timeout = struct.unpack_from('!H', buf, 58)[0]
+ obj.hard_timeout = struct.unpack_from('!H', buf, 60)[0]
+ obj.priority = struct.unpack_from('!H', buf, 62)[0]
+ obj.buffer_id = struct.unpack_from('!L', buf, 64)[0]
+ obj.out_port = struct.unpack_from('!H', buf, 68)[0]
+ obj.flags = struct.unpack_from('!H', buf, 70)[0]
+ obj.actions = action.unpack_list(buffer(buf, 72))
+ return obj
+
+ def __eq__(self, other):
+ if type(self) != type(other): return False
+ if self.version != other.version: return False
+ if self.type != other.type: return False
+ if self.xid != other.xid: return False
+ if self.match != other.match: return False
+ if self.cookie != other.cookie: return False
+ if self.idle_timeout != other.idle_timeout: return False
+ if self.hard_timeout != other.hard_timeout: return False
+ if self.priority != other.priority: return False
+ if self.buffer_id != other.buffer_id: return False
+ if self.out_port != other.out_port: return False
+ if self.flags != other.flags: return False
+ if self.actions != other.actions: return False
+ return True
+
+ def __ne__(self, other):
+ return not self.__eq__(other)
+
+ def __str__(self):
+ return self.show()
+
+ def show(self):
+ import loxi.pp
+ return loxi.pp.pp(self)
+
+ def pretty_print(self, q):
+ q.text("flow_add {")
+ with q.group():
+ with q.indent(2):
+ q.breakable()
+ q.text("xid = ");
+ if self.xid != None:
+ q.text("%#x" % self.xid)
+ else:
+ q.text('None')
+ q.text(","); q.breakable()
+ q.text("match = ");
+ q.pp(self.match)
+ q.text(","); q.breakable()
+ q.text("cookie = ");
+ q.text("%#x" % self.cookie)
+ q.text(","); q.breakable()
+ q.text("idle_timeout = ");
+ q.text("%#x" % self.idle_timeout)
+ q.text(","); q.breakable()
+ q.text("hard_timeout = ");
+ q.text("%#x" % self.hard_timeout)
+ q.text(","); q.breakable()
+ q.text("priority = ");
+ q.text("%#x" % self.priority)
+ q.text(","); q.breakable()
+ q.text("buffer_id = ");
+ q.text("%#x" % self.buffer_id)
+ q.text(","); q.breakable()
+ q.text("out_port = ");
+ q.text(util.pretty_port(self.out_port))
+ q.text(","); q.breakable()
+ q.text("flags = ");
+ q.text("%#x" % self.flags)
+ q.text(","); q.breakable()
+ q.text("actions = ");
+ q.pp(self.actions)
+ q.breakable()
+ q.text('}')
+
+class flow_delete(Message):
+ version = const.OFP_VERSION
+ type = const.OFPT_FLOW_MOD
+ _command = const.OFPFC_DELETE
+
+ 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):
+ self.xid = xid
+ if match != None:
+ self.match = match
+ else:
+ self.match = common.match()
+ if cookie != None:
+ self.cookie = cookie
+ else:
+ self.cookie = 0
+ if idle_timeout != None:
+ self.idle_timeout = idle_timeout
+ else:
+ self.idle_timeout = 0
+ if hard_timeout != None:
+ self.hard_timeout = hard_timeout
+ else:
+ self.hard_timeout = 0
+ if priority != None:
+ self.priority = priority
+ else:
+ self.priority = 0
+ if buffer_id != None:
+ self.buffer_id = buffer_id
+ else:
+ self.buffer_id = 0
+ if out_port != None:
+ self.out_port = out_port
+ else:
+ self.out_port = 0
+ if flags != None:
+ self.flags = flags
+ else:
+ self.flags = 0
+ if actions != None:
+ self.actions = actions
+ else:
+ self.actions = []
+
+ def pack(self):
+ packed = []
+ packed.append(struct.pack("!B", self.version))
+ packed.append(struct.pack("!B", self.type))
+ packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
+ packed.append(struct.pack("!L", self.xid))
+ packed.append(self.match.pack())
+ packed.append(struct.pack("!Q", self.cookie))
+ packed.append(struct.pack("!H", self._command))
+ packed.append(struct.pack("!H", self.idle_timeout))
+ packed.append(struct.pack("!H", self.hard_timeout))
+ packed.append(struct.pack("!H", self.priority))
+ packed.append(struct.pack("!L", self.buffer_id))
+ packed.append(struct.pack("!H", self.out_port))
+ packed.append(struct.pack("!H", self.flags))
+ packed.append("".join([x.pack() for x in self.actions]))
+ length = sum([len(x) for x in packed])
+ packed[2] = struct.pack("!H", length)
+ return ''.join(packed)
+
+ @staticmethod
+ def unpack(buf):
+ if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
+ obj = flow_delete()
+ version = struct.unpack_from('!B', buf, 0)[0]
+ assert(version == const.OFP_VERSION)
+ type = struct.unpack_from('!B', buf, 1)[0]
+ assert(type == const.OFPT_FLOW_MOD)
+ _length = struct.unpack_from('!H', buf, 2)[0]
+ assert(_length == len(buf))
+ if _length < 72: raise loxi.ProtocolError("flow_delete length is %d, should be at least 72" % _length)
+ obj.xid = struct.unpack_from('!L', buf, 4)[0]
+ obj.match = common.match.unpack(buffer(buf, 8))
+ obj.cookie = struct.unpack_from('!Q', buf, 48)[0]
+ _command = struct.unpack_from('!H', buf, 56)[0]
+ assert(_command == const.OFPFC_DELETE)
+ obj.idle_timeout = struct.unpack_from('!H', buf, 58)[0]
+ obj.hard_timeout = struct.unpack_from('!H', buf, 60)[0]
+ obj.priority = struct.unpack_from('!H', buf, 62)[0]
+ obj.buffer_id = struct.unpack_from('!L', buf, 64)[0]
+ obj.out_port = struct.unpack_from('!H', buf, 68)[0]
+ obj.flags = struct.unpack_from('!H', buf, 70)[0]
+ obj.actions = action.unpack_list(buffer(buf, 72))
+ return obj
+
+ def __eq__(self, other):
+ if type(self) != type(other): return False
+ if self.version != other.version: return False
+ if self.type != other.type: return False
+ if self.xid != other.xid: return False
+ if self.match != other.match: return False
+ if self.cookie != other.cookie: return False
+ if self.idle_timeout != other.idle_timeout: return False
+ if self.hard_timeout != other.hard_timeout: return False
+ if self.priority != other.priority: return False
+ if self.buffer_id != other.buffer_id: return False
+ if self.out_port != other.out_port: return False
+ if self.flags != other.flags: return False
+ if self.actions != other.actions: return False
+ return True
+
+ def __ne__(self, other):
+ return not self.__eq__(other)
+
+ def __str__(self):
+ return self.show()
+
+ def show(self):
+ import loxi.pp
+ return loxi.pp.pp(self)
+
+ def pretty_print(self, q):
+ q.text("flow_delete {")
+ with q.group():
+ with q.indent(2):
+ q.breakable()
+ q.text("xid = ");
+ if self.xid != None:
+ q.text("%#x" % self.xid)
+ else:
+ q.text('None')
+ q.text(","); q.breakable()
+ q.text("match = ");
+ q.pp(self.match)
+ q.text(","); q.breakable()
+ q.text("cookie = ");
+ q.text("%#x" % self.cookie)
+ q.text(","); q.breakable()
+ q.text("idle_timeout = ");
+ q.text("%#x" % self.idle_timeout)
+ q.text(","); q.breakable()
+ q.text("hard_timeout = ");
+ q.text("%#x" % self.hard_timeout)
+ q.text(","); q.breakable()
+ q.text("priority = ");
+ q.text("%#x" % self.priority)
+ q.text(","); q.breakable()
+ q.text("buffer_id = ");
+ q.text("%#x" % self.buffer_id)
+ q.text(","); q.breakable()
+ q.text("out_port = ");
+ q.text(util.pretty_port(self.out_port))
+ q.text(","); q.breakable()
+ q.text("flags = ");
+ q.text("%#x" % self.flags)
+ q.text(","); q.breakable()
+ q.text("actions = ");
+ q.pp(self.actions)
+ q.breakable()
+ q.text('}')
+
+class flow_delete_strict(Message):
+ version = const.OFP_VERSION
+ type = const.OFPT_FLOW_MOD
+ _command = const.OFPFC_DELETE_STRICT
+
+ 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):
+ self.xid = xid
+ if match != None:
+ self.match = match
+ else:
+ self.match = common.match()
+ if cookie != None:
+ self.cookie = cookie
+ else:
+ self.cookie = 0
+ if idle_timeout != None:
+ self.idle_timeout = idle_timeout
+ else:
+ self.idle_timeout = 0
+ if hard_timeout != None:
+ self.hard_timeout = hard_timeout
+ else:
+ self.hard_timeout = 0
+ if priority != None:
+ self.priority = priority
+ else:
+ self.priority = 0
+ if buffer_id != None:
+ self.buffer_id = buffer_id
+ else:
+ self.buffer_id = 0
+ if out_port != None:
+ self.out_port = out_port
+ else:
+ self.out_port = 0
+ if flags != None:
+ self.flags = flags
+ else:
+ self.flags = 0
+ if actions != None:
+ self.actions = actions
+ else:
+ self.actions = []
+
+ def pack(self):
+ packed = []
+ packed.append(struct.pack("!B", self.version))
+ packed.append(struct.pack("!B", self.type))
+ packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
+ packed.append(struct.pack("!L", self.xid))
+ packed.append(self.match.pack())
+ packed.append(struct.pack("!Q", self.cookie))
+ packed.append(struct.pack("!H", self._command))
+ packed.append(struct.pack("!H", self.idle_timeout))
+ packed.append(struct.pack("!H", self.hard_timeout))
+ packed.append(struct.pack("!H", self.priority))
+ packed.append(struct.pack("!L", self.buffer_id))
+ packed.append(struct.pack("!H", self.out_port))
+ packed.append(struct.pack("!H", self.flags))
+ packed.append("".join([x.pack() for x in self.actions]))
+ length = sum([len(x) for x in packed])
+ packed[2] = struct.pack("!H", length)
+ return ''.join(packed)
+
+ @staticmethod
+ def unpack(buf):
+ if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
+ obj = flow_delete_strict()
+ version = struct.unpack_from('!B', buf, 0)[0]
+ assert(version == const.OFP_VERSION)
+ type = struct.unpack_from('!B', buf, 1)[0]
+ assert(type == const.OFPT_FLOW_MOD)
+ _length = struct.unpack_from('!H', buf, 2)[0]
+ assert(_length == len(buf))
+ if _length < 72: raise loxi.ProtocolError("flow_delete_strict length is %d, should be at least 72" % _length)
+ obj.xid = struct.unpack_from('!L', buf, 4)[0]
+ obj.match = common.match.unpack(buffer(buf, 8))
+ obj.cookie = struct.unpack_from('!Q', buf, 48)[0]
+ _command = struct.unpack_from('!H', buf, 56)[0]
+ assert(_command == const.OFPFC_DELETE_STRICT)
+ obj.idle_timeout = struct.unpack_from('!H', buf, 58)[0]
+ obj.hard_timeout = struct.unpack_from('!H', buf, 60)[0]
+ obj.priority = struct.unpack_from('!H', buf, 62)[0]
+ obj.buffer_id = struct.unpack_from('!L', buf, 64)[0]
+ obj.out_port = struct.unpack_from('!H', buf, 68)[0]
+ obj.flags = struct.unpack_from('!H', buf, 70)[0]
+ obj.actions = action.unpack_list(buffer(buf, 72))
+ return obj
+
+ def __eq__(self, other):
+ if type(self) != type(other): return False
+ if self.version != other.version: return False
+ if self.type != other.type: return False
+ if self.xid != other.xid: return False
+ if self.match != other.match: return False
+ if self.cookie != other.cookie: return False
+ if self.idle_timeout != other.idle_timeout: return False
+ if self.hard_timeout != other.hard_timeout: return False
+ if self.priority != other.priority: return False
+ if self.buffer_id != other.buffer_id: return False
+ if self.out_port != other.out_port: return False
+ if self.flags != other.flags: return False
+ if self.actions != other.actions: return False
+ return True
+
+ def __ne__(self, other):
+ return not self.__eq__(other)
+
+ def __str__(self):
+ return self.show()
+
+ def show(self):
+ import loxi.pp
+ return loxi.pp.pp(self)
+
+ def pretty_print(self, q):
+ q.text("flow_delete_strict {")
+ with q.group():
+ with q.indent(2):
+ q.breakable()
+ q.text("xid = ");
+ if self.xid != None:
+ q.text("%#x" % self.xid)
+ else:
+ q.text('None')
+ q.text(","); q.breakable()
+ q.text("match = ");
+ q.pp(self.match)
+ q.text(","); q.breakable()
+ q.text("cookie = ");
+ q.text("%#x" % self.cookie)
+ q.text(","); q.breakable()
+ q.text("idle_timeout = ");
+ q.text("%#x" % self.idle_timeout)
+ q.text(","); q.breakable()
+ q.text("hard_timeout = ");
+ q.text("%#x" % self.hard_timeout)
+ q.text(","); q.breakable()
+ q.text("priority = ");
+ q.text("%#x" % self.priority)
+ q.text(","); q.breakable()
+ q.text("buffer_id = ");
+ q.text("%#x" % self.buffer_id)
+ q.text(","); q.breakable()
+ q.text("out_port = ");
+ q.text(util.pretty_port(self.out_port))
+ q.text(","); q.breakable()
+ q.text("flags = ");
+ q.text("%#x" % self.flags)
+ q.text(","); q.breakable()
+ q.text("actions = ");
+ q.pp(self.actions)
+ q.breakable()
+ q.text('}')
+
+class flow_modify(Message):
+ version = const.OFP_VERSION
+ type = const.OFPT_FLOW_MOD
+ _command = const.OFPFC_MODIFY
+
+ 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):
+ self.xid = xid
+ if match != None:
+ self.match = match
+ else:
+ self.match = common.match()
+ if cookie != None:
+ self.cookie = cookie
+ else:
+ self.cookie = 0
+ if idle_timeout != None:
+ self.idle_timeout = idle_timeout
+ else:
+ self.idle_timeout = 0
+ if hard_timeout != None:
+ self.hard_timeout = hard_timeout
+ else:
+ self.hard_timeout = 0
+ if priority != None:
+ self.priority = priority
+ else:
+ self.priority = 0
+ if buffer_id != None:
+ self.buffer_id = buffer_id
+ else:
+ self.buffer_id = 0
+ if out_port != None:
+ self.out_port = out_port
+ else:
+ self.out_port = 0
+ if flags != None:
+ self.flags = flags
+ else:
+ self.flags = 0
+ if actions != None:
+ self.actions = actions
+ else:
+ self.actions = []
+
+ def pack(self):
+ packed = []
+ packed.append(struct.pack("!B", self.version))
+ packed.append(struct.pack("!B", self.type))
+ packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
+ packed.append(struct.pack("!L", self.xid))
+ packed.append(self.match.pack())
+ packed.append(struct.pack("!Q", self.cookie))
+ packed.append(struct.pack("!H", self._command))
+ packed.append(struct.pack("!H", self.idle_timeout))
+ packed.append(struct.pack("!H", self.hard_timeout))
+ packed.append(struct.pack("!H", self.priority))
+ packed.append(struct.pack("!L", self.buffer_id))
+ packed.append(struct.pack("!H", self.out_port))
+ packed.append(struct.pack("!H", self.flags))
+ packed.append("".join([x.pack() for x in self.actions]))
+ length = sum([len(x) for x in packed])
+ packed[2] = struct.pack("!H", length)
+ return ''.join(packed)
+
+ @staticmethod
+ def unpack(buf):
+ if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
+ obj = flow_modify()
+ version = struct.unpack_from('!B', buf, 0)[0]
+ assert(version == const.OFP_VERSION)
+ type = struct.unpack_from('!B', buf, 1)[0]
+ assert(type == const.OFPT_FLOW_MOD)
+ _length = struct.unpack_from('!H', buf, 2)[0]
+ assert(_length == len(buf))
+ if _length < 72: raise loxi.ProtocolError("flow_modify length is %d, should be at least 72" % _length)
+ obj.xid = struct.unpack_from('!L', buf, 4)[0]
+ obj.match = common.match.unpack(buffer(buf, 8))
+ obj.cookie = struct.unpack_from('!Q', buf, 48)[0]
+ _command = struct.unpack_from('!H', buf, 56)[0]
+ assert(_command == const.OFPFC_MODIFY)
+ obj.idle_timeout = struct.unpack_from('!H', buf, 58)[0]
+ obj.hard_timeout = struct.unpack_from('!H', buf, 60)[0]
+ obj.priority = struct.unpack_from('!H', buf, 62)[0]
+ obj.buffer_id = struct.unpack_from('!L', buf, 64)[0]
+ obj.out_port = struct.unpack_from('!H', buf, 68)[0]
+ obj.flags = struct.unpack_from('!H', buf, 70)[0]
+ obj.actions = action.unpack_list(buffer(buf, 72))
+ return obj
+
+ def __eq__(self, other):
+ if type(self) != type(other): return False
+ if self.version != other.version: return False
+ if self.type != other.type: return False
+ if self.xid != other.xid: return False
+ if self.match != other.match: return False
+ if self.cookie != other.cookie: return False
+ if self.idle_timeout != other.idle_timeout: return False
+ if self.hard_timeout != other.hard_timeout: return False
+ if self.priority != other.priority: return False
+ if self.buffer_id != other.buffer_id: return False
+ if self.out_port != other.out_port: return False
+ if self.flags != other.flags: return False
+ if self.actions != other.actions: return False
+ return True
+
+ def __ne__(self, other):
+ return not self.__eq__(other)
+
+ def __str__(self):
+ return self.show()
+
+ def show(self):
+ import loxi.pp
+ return loxi.pp.pp(self)
+
+ def pretty_print(self, q):
+ q.text("flow_modify {")
+ with q.group():
+ with q.indent(2):
+ q.breakable()
+ q.text("xid = ");
+ if self.xid != None:
+ q.text("%#x" % self.xid)
+ else:
+ q.text('None')
+ q.text(","); q.breakable()
+ q.text("match = ");
+ q.pp(self.match)
+ q.text(","); q.breakable()
+ q.text("cookie = ");
+ q.text("%#x" % self.cookie)
+ q.text(","); q.breakable()
+ q.text("idle_timeout = ");
+ q.text("%#x" % self.idle_timeout)
+ q.text(","); q.breakable()
+ q.text("hard_timeout = ");
+ q.text("%#x" % self.hard_timeout)
+ q.text(","); q.breakable()
+ q.text("priority = ");
+ q.text("%#x" % self.priority)
+ q.text(","); q.breakable()
+ q.text("buffer_id = ");
+ q.text("%#x" % self.buffer_id)
+ q.text(","); q.breakable()
+ q.text("out_port = ");
+ q.text(util.pretty_port(self.out_port))
+ q.text(","); q.breakable()
+ q.text("flags = ");
+ q.text("%#x" % self.flags)
+ q.text(","); q.breakable()
+ q.text("actions = ");
+ q.pp(self.actions)
+ q.breakable()
+ q.text('}')
+
+class flow_modify_strict(Message):
+ version = const.OFP_VERSION
+ type = const.OFPT_FLOW_MOD
+ _command = const.OFPFC_MODIFY_STRICT
+
+ 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):
+ self.xid = xid
+ if match != None:
+ self.match = match
+ else:
+ self.match = common.match()
+ if cookie != None:
+ self.cookie = cookie
+ else:
+ self.cookie = 0
+ if idle_timeout != None:
+ self.idle_timeout = idle_timeout
+ else:
+ self.idle_timeout = 0
+ if hard_timeout != None:
+ self.hard_timeout = hard_timeout
+ else:
+ self.hard_timeout = 0
+ if priority != None:
+ self.priority = priority
+ else:
+ self.priority = 0
+ if buffer_id != None:
+ self.buffer_id = buffer_id
+ else:
+ self.buffer_id = 0
+ if out_port != None:
+ self.out_port = out_port
+ else:
+ self.out_port = 0
+ if flags != None:
+ self.flags = flags
+ else:
+ self.flags = 0
+ if actions != None:
+ self.actions = actions
+ else:
+ self.actions = []
+
+ def pack(self):
+ packed = []
+ packed.append(struct.pack("!B", self.version))
+ packed.append(struct.pack("!B", self.type))
+ packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
+ packed.append(struct.pack("!L", self.xid))
+ packed.append(self.match.pack())
+ packed.append(struct.pack("!Q", self.cookie))
+ packed.append(struct.pack("!H", self._command))
+ packed.append(struct.pack("!H", self.idle_timeout))
+ packed.append(struct.pack("!H", self.hard_timeout))
+ packed.append(struct.pack("!H", self.priority))
+ packed.append(struct.pack("!L", self.buffer_id))
+ packed.append(struct.pack("!H", self.out_port))
+ packed.append(struct.pack("!H", self.flags))
+ packed.append("".join([x.pack() for x in self.actions]))
+ length = sum([len(x) for x in packed])
+ packed[2] = struct.pack("!H", length)
+ return ''.join(packed)
+
+ @staticmethod
+ def unpack(buf):
+ if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
+ obj = flow_modify_strict()
+ version = struct.unpack_from('!B', buf, 0)[0]
+ assert(version == const.OFP_VERSION)
+ type = struct.unpack_from('!B', buf, 1)[0]
+ assert(type == const.OFPT_FLOW_MOD)
+ _length = struct.unpack_from('!H', buf, 2)[0]
+ assert(_length == len(buf))
+ if _length < 72: raise loxi.ProtocolError("flow_modify_strict length is %d, should be at least 72" % _length)
+ obj.xid = struct.unpack_from('!L', buf, 4)[0]
+ obj.match = common.match.unpack(buffer(buf, 8))
+ obj.cookie = struct.unpack_from('!Q', buf, 48)[0]
+ _command = struct.unpack_from('!H', buf, 56)[0]
+ assert(_command == const.OFPFC_MODIFY_STRICT)
+ obj.idle_timeout = struct.unpack_from('!H', buf, 58)[0]
+ obj.hard_timeout = struct.unpack_from('!H', buf, 60)[0]
+ obj.priority = struct.unpack_from('!H', buf, 62)[0]
+ obj.buffer_id = struct.unpack_from('!L', buf, 64)[0]
+ obj.out_port = struct.unpack_from('!H', buf, 68)[0]
+ obj.flags = struct.unpack_from('!H', buf, 70)[0]
+ obj.actions = action.unpack_list(buffer(buf, 72))
+ return obj
+
+ def __eq__(self, other):
+ if type(self) != type(other): return False
+ if self.version != other.version: return False
+ if self.type != other.type: return False
+ if self.xid != other.xid: return False
+ if self.match != other.match: return False
+ if self.cookie != other.cookie: return False
+ if self.idle_timeout != other.idle_timeout: return False
+ if self.hard_timeout != other.hard_timeout: return False
+ if self.priority != other.priority: return False
+ if self.buffer_id != other.buffer_id: return False
+ if self.out_port != other.out_port: return False
+ if self.flags != other.flags: return False
+ if self.actions != other.actions: return False
+ return True
+
+ def __ne__(self, other):
+ return not self.__eq__(other)
+
+ def __str__(self):
+ return self.show()
+
+ def show(self):
+ import loxi.pp
+ return loxi.pp.pp(self)
+
+ def pretty_print(self, q):
+ q.text("flow_modify_strict {")
+ with q.group():
+ with q.indent(2):
+ q.breakable()
+ q.text("xid = ");
+ if self.xid != None:
+ q.text("%#x" % self.xid)
+ else:
+ q.text('None')
+ q.text(","); q.breakable()
+ q.text("match = ");
+ q.pp(self.match)
+ q.text(","); q.breakable()
+ q.text("cookie = ");
+ q.text("%#x" % self.cookie)
+ q.text(","); q.breakable()
+ q.text("idle_timeout = ");
+ q.text("%#x" % self.idle_timeout)
+ q.text(","); q.breakable()
+ q.text("hard_timeout = ");
+ q.text("%#x" % self.hard_timeout)
+ q.text(","); q.breakable()
+ q.text("priority = ");
+ q.text("%#x" % self.priority)
+ q.text(","); q.breakable()
+ q.text("buffer_id = ");
+ q.text("%#x" % self.buffer_id)
+ q.text(","); q.breakable()
+ q.text("out_port = ");
+ q.text(util.pretty_port(self.out_port))
+ q.text(","); q.breakable()
+ q.text("flags = ");
+ q.text("%#x" % self.flags)
+ q.text(","); q.breakable()
+ q.text("actions = ");
+ q.pp(self.actions)
+ q.breakable()
+ q.text('}')
+
+class flow_removed(Message):
+ version = const.OFP_VERSION
+ type = const.OFPT_FLOW_REMOVED
+
+ def __init__(self, xid=None, match=None, cookie=None, priority=None, reason=None, pad=None, duration_sec=None, duration_nsec=None, idle_timeout=None, pad2=None, packet_count=None, byte_count=None):
+ self.xid = xid
+ if match != None:
+ self.match = match
+ else:
+ self.match = common.match()
+ if cookie != None:
+ self.cookie = cookie
+ else:
+ self.cookie = 0
+ if priority != None:
+ self.priority = priority
+ else:
+ self.priority = 0
+ if reason != None:
+ self.reason = reason
+ else:
+ self.reason = 0
+ if pad != None:
+ self.pad = pad
+ else:
+ self.pad = 0
+ if duration_sec != None:
+ self.duration_sec = duration_sec
+ else:
+ self.duration_sec = 0
+ if duration_nsec != None:
+ self.duration_nsec = duration_nsec
+ else:
+ self.duration_nsec = 0
+ if idle_timeout != None:
+ self.idle_timeout = idle_timeout
+ else:
+ self.idle_timeout = 0
+ if pad2 != None:
+ self.pad2 = pad2
+ else:
+ self.pad2 = [0,0]
+ if packet_count != None:
+ self.packet_count = packet_count
+ else:
+ self.packet_count = 0
+ if byte_count != None:
+ self.byte_count = byte_count
+ else:
+ self.byte_count = 0
+
+ def pack(self):
+ packed = []
+ packed.append(struct.pack("!B", self.version))
+ packed.append(struct.pack("!B", self.type))
+ packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
+ packed.append(struct.pack("!L", self.xid))
+ packed.append(self.match.pack())
+ packed.append(struct.pack("!Q", self.cookie))
+ packed.append(struct.pack("!H", self.priority))
+ packed.append(struct.pack("!B", self.reason))
+ packed.append(struct.pack("!B", self.pad))
+ packed.append(struct.pack("!L", self.duration_sec))
+ packed.append(struct.pack("!L", self.duration_nsec))
+ packed.append(struct.pack("!H", self.idle_timeout))
+ packed.append(struct.pack("!2B", *self.pad2))
+ packed.append(struct.pack("!Q", self.packet_count))
+ packed.append(struct.pack("!Q", self.byte_count))
+ length = sum([len(x) for x in packed])
+ packed[2] = struct.pack("!H", length)
+ return ''.join(packed)
+
+ @staticmethod
+ def unpack(buf):
+ if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
+ obj = flow_removed()
+ version = struct.unpack_from('!B', buf, 0)[0]
+ assert(version == const.OFP_VERSION)
+ type = struct.unpack_from('!B', buf, 1)[0]
+ assert(type == const.OFPT_FLOW_REMOVED)
+ _length = struct.unpack_from('!H', buf, 2)[0]
+ assert(_length == len(buf))
+ if _length != 88: raise loxi.ProtocolError("flow_removed length is %d, should be 88" % _length)
+ obj.xid = struct.unpack_from('!L', buf, 4)[0]
+ obj.match = common.match.unpack(buffer(buf, 8))
+ obj.cookie = struct.unpack_from('!Q', buf, 48)[0]
+ obj.priority = struct.unpack_from('!H', buf, 56)[0]
+ obj.reason = struct.unpack_from('!B', buf, 58)[0]
+ obj.pad = struct.unpack_from('!B', buf, 59)[0]
+ obj.duration_sec = struct.unpack_from('!L', buf, 60)[0]
+ obj.duration_nsec = struct.unpack_from('!L', buf, 64)[0]
+ obj.idle_timeout = struct.unpack_from('!H', buf, 68)[0]
+ obj.pad2 = list(struct.unpack_from('!2B', buf, 70))
+ obj.packet_count = struct.unpack_from('!Q', buf, 72)[0]
+ obj.byte_count = struct.unpack_from('!Q', buf, 80)[0]
+ return obj
+
+ def __eq__(self, other):
+ if type(self) != type(other): return False
+ if self.version != other.version: return False
+ if self.type != other.type: return False
+ if self.xid != other.xid: return False
+ if self.match != other.match: return False
+ if self.cookie != other.cookie: return False
+ if self.priority != other.priority: return False
+ if self.reason != other.reason: return False
+ if self.pad != other.pad: return False
+ if self.duration_sec != other.duration_sec: return False
+ if self.duration_nsec != other.duration_nsec: return False
+ if self.idle_timeout != other.idle_timeout: return False
+ if self.pad2 != other.pad2: return False
+ if self.packet_count != other.packet_count: return False
+ if self.byte_count != other.byte_count: return False
+ return True
+
+ def __ne__(self, other):
+ return not self.__eq__(other)
+
+ def __str__(self):
+ return self.show()
+
+ def show(self):
+ import loxi.pp
+ return loxi.pp.pp(self)
+
+ def pretty_print(self, q):
+ q.text("flow_removed {")
+ with q.group():
+ with q.indent(2):
+ q.breakable()
+ q.text("xid = ");
+ if self.xid != None:
+ q.text("%#x" % self.xid)
+ else:
+ q.text('None')
+ q.text(","); q.breakable()
+ q.text("match = ");
+ q.pp(self.match)
+ q.text(","); q.breakable()
+ q.text("cookie = ");
+ q.text("%#x" % self.cookie)
+ q.text(","); q.breakable()
+ q.text("priority = ");
+ q.text("%#x" % self.priority)
+ q.text(","); q.breakable()
+ q.text("reason = ");
+ q.text("%#x" % self.reason)
+ q.text(","); q.breakable()
+ q.text("pad = ");
+ q.text("%#x" % self.pad)
+ q.text(","); q.breakable()
+ q.text("duration_sec = ");
+ q.text("%#x" % self.duration_sec)
+ q.text(","); q.breakable()
+ q.text("duration_nsec = ");
+ q.text("%#x" % self.duration_nsec)
+ q.text(","); q.breakable()
+ q.text("idle_timeout = ");
+ q.text("%#x" % self.idle_timeout)
+ q.text(","); q.breakable()
+ q.text("pad2 = ");
+ q.pp(self.pad2)
+ q.text(","); q.breakable()
+ q.text("packet_count = ");
+ q.text("%#x" % self.packet_count)
+ q.text(","); q.breakable()
+ q.text("byte_count = ");
+ q.text("%#x" % self.byte_count)
+ q.breakable()
+ q.text('}')
+
+class flow_stats_reply(Message):
+ version = const.OFP_VERSION
+ type = const.OFPT_STATS_REPLY
+ stats_type = const.OFPST_FLOW
+
+ def __init__(self, xid=None, flags=None, entries=None):
+ self.xid = xid
+ if flags != None:
+ self.flags = flags
+ else:
+ self.flags = 0
+ if entries != None:
+ self.entries = entries
+ else:
+ self.entries = []
+
+ def pack(self):
+ packed = []
+ packed.append(struct.pack("!B", self.version))
+ packed.append(struct.pack("!B", self.type))
+ packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
+ packed.append(struct.pack("!L", self.xid))
+ packed.append(struct.pack("!H", self.stats_type))
+ packed.append(struct.pack("!H", self.flags))
+ packed.append("".join([x.pack() for x in self.entries]))
+ length = sum([len(x) for x in packed])
+ packed[2] = struct.pack("!H", length)
+ return ''.join(packed)
+
+ @staticmethod
+ def unpack(buf):
+ if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
+ obj = flow_stats_reply()
+ version = struct.unpack_from('!B', buf, 0)[0]
+ assert(version == const.OFP_VERSION)
+ type = struct.unpack_from('!B', buf, 1)[0]
+ assert(type == const.OFPT_STATS_REPLY)
+ _length = struct.unpack_from('!H', buf, 2)[0]
+ assert(_length == len(buf))
+ if _length < 12: raise loxi.ProtocolError("flow_stats_reply length is %d, should be at least 12" % _length)
+ obj.xid = struct.unpack_from('!L', buf, 4)[0]
+ stats_type = struct.unpack_from('!H', buf, 8)[0]
+ assert(stats_type == const.OFPST_FLOW)
+ obj.flags = struct.unpack_from('!H', buf, 10)[0]
+ obj.entries = common.unpack_list_flow_stats_entry(buffer(buf, 12))
+ return obj
+
+ def __eq__(self, other):
+ if type(self) != type(other): return False
+ if self.version != other.version: return False
+ if self.type != other.type: return False
+ if self.xid != other.xid: return False
+ if self.flags != other.flags: return False
+ if self.entries != other.entries: return False
+ return True
+
+ def __ne__(self, other):
+ return not self.__eq__(other)
+
+ def __str__(self):
+ return self.show()
+
+ def show(self):
+ import loxi.pp
+ return loxi.pp.pp(self)
+
+ def pretty_print(self, q):
+ q.text("flow_stats_reply {")
+ with q.group():
+ with q.indent(2):
+ q.breakable()
+ q.text("xid = ");
+ if self.xid != None:
+ q.text("%#x" % self.xid)
+ else:
+ q.text('None')
+ q.text(","); q.breakable()
+ q.text("flags = ");
+ q.text("%#x" % self.flags)
+ q.text(","); q.breakable()
+ q.text("entries = ");
+ q.pp(self.entries)
+ q.breakable()
+ q.text('}')
+
+class flow_stats_request(Message):
+ version = const.OFP_VERSION
+ type = const.OFPT_STATS_REQUEST
+ stats_type = const.OFPST_FLOW
+
+ def __init__(self, xid=None, flags=None, match=None, table_id=None, pad=None, out_port=None):
+ self.xid = xid
+ if flags != None:
+ self.flags = flags
+ else:
+ self.flags = 0
+ if match != None:
+ self.match = match
+ else:
+ self.match = common.match()
+ if table_id != None:
+ self.table_id = table_id
+ else:
+ self.table_id = 0
+ if pad != None:
+ self.pad = pad
+ else:
+ self.pad = 0
+ if out_port != None:
+ self.out_port = out_port
+ else:
+ self.out_port = 0
+
+ def pack(self):
+ packed = []
+ packed.append(struct.pack("!B", self.version))
+ packed.append(struct.pack("!B", self.type))
+ packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
+ packed.append(struct.pack("!L", self.xid))
+ packed.append(struct.pack("!H", self.stats_type))
+ packed.append(struct.pack("!H", self.flags))
+ packed.append(self.match.pack())
+ packed.append(struct.pack("!B", self.table_id))
+ packed.append(struct.pack("!B", self.pad))
+ packed.append(struct.pack("!H", self.out_port))
+ length = sum([len(x) for x in packed])
+ packed[2] = struct.pack("!H", length)
+ return ''.join(packed)
+
+ @staticmethod
+ def unpack(buf):
+ if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
+ obj = flow_stats_request()
+ version = struct.unpack_from('!B', buf, 0)[0]
+ assert(version == const.OFP_VERSION)
+ type = struct.unpack_from('!B', buf, 1)[0]
+ assert(type == const.OFPT_STATS_REQUEST)
+ _length = struct.unpack_from('!H', buf, 2)[0]
+ assert(_length == len(buf))
+ if _length != 56: raise loxi.ProtocolError("flow_stats_request length is %d, should be 56" % _length)
+ obj.xid = struct.unpack_from('!L', buf, 4)[0]
+ stats_type = struct.unpack_from('!H', buf, 8)[0]
+ assert(stats_type == const.OFPST_FLOW)
+ obj.flags = struct.unpack_from('!H', buf, 10)[0]
+ obj.match = common.match.unpack(buffer(buf, 12))
+ obj.table_id = struct.unpack_from('!B', buf, 52)[0]
+ obj.pad = struct.unpack_from('!B', buf, 53)[0]
+ obj.out_port = struct.unpack_from('!H', buf, 54)[0]
+ return obj
+
+ def __eq__(self, other):
+ if type(self) != type(other): return False
+ if self.version != other.version: return False
+ if self.type != other.type: return False
+ if self.xid != other.xid: return False
+ if self.flags != other.flags: return False
+ if self.match != other.match: return False
+ if self.table_id != other.table_id: return False
+ if self.pad != other.pad: return False
+ if self.out_port != other.out_port: return False
+ return True
+
+ def __ne__(self, other):
+ return not self.__eq__(other)
+
+ def __str__(self):
+ return self.show()
+
+ def show(self):
+ import loxi.pp
+ return loxi.pp.pp(self)
+
+ def pretty_print(self, q):
+ q.text("flow_stats_request {")
+ with q.group():
+ with q.indent(2):
+ q.breakable()
+ q.text("xid = ");
+ if self.xid != None:
+ q.text("%#x" % self.xid)
+ else:
+ q.text('None')
+ q.text(","); q.breakable()
+ q.text("flags = ");
+ q.text("%#x" % self.flags)
+ q.text(","); q.breakable()
+ q.text("match = ");
+ q.pp(self.match)
+ q.text(","); q.breakable()
+ q.text("table_id = ");
+ q.text("%#x" % self.table_id)
+ q.text(","); q.breakable()
+ q.text("pad = ");
+ q.text("%#x" % self.pad)
+ q.text(","); q.breakable()
+ q.text("out_port = ");
+ q.text(util.pretty_port(self.out_port))
+ q.breakable()
+ q.text('}')
+
+class get_config_reply(Message):
+ version = const.OFP_VERSION
+ type = const.OFPT_GET_CONFIG_REPLY
+
+ def __init__(self, xid=None, flags=None, miss_send_len=None):
+ self.xid = xid
+ if flags != None:
+ self.flags = flags
+ else:
+ self.flags = 0
+ if miss_send_len != None:
+ self.miss_send_len = miss_send_len
+ else:
+ self.miss_send_len = 0
+
+ def pack(self):
+ packed = []
+ packed.append(struct.pack("!B", self.version))
+ packed.append(struct.pack("!B", self.type))
+ packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
+ packed.append(struct.pack("!L", self.xid))
+ packed.append(struct.pack("!H", self.flags))
+ packed.append(struct.pack("!H", self.miss_send_len))
+ length = sum([len(x) for x in packed])
+ packed[2] = struct.pack("!H", length)
+ return ''.join(packed)
+
+ @staticmethod
+ def unpack(buf):
+ if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
+ obj = get_config_reply()
+ version = struct.unpack_from('!B', buf, 0)[0]
+ assert(version == const.OFP_VERSION)
+ type = struct.unpack_from('!B', buf, 1)[0]
+ assert(type == const.OFPT_GET_CONFIG_REPLY)
+ _length = struct.unpack_from('!H', buf, 2)[0]
+ assert(_length == len(buf))
+ if _length != 12: raise loxi.ProtocolError("get_config_reply length is %d, should be 12" % _length)
+ obj.xid = struct.unpack_from('!L', buf, 4)[0]
+ obj.flags = struct.unpack_from('!H', buf, 8)[0]
+ obj.miss_send_len = struct.unpack_from('!H', buf, 10)[0]
+ return obj
+
+ def __eq__(self, other):
+ if type(self) != type(other): return False
+ if self.version != other.version: return False
+ if self.type != other.type: return False
+ if self.xid != other.xid: return False
+ if self.flags != other.flags: return False
+ if self.miss_send_len != other.miss_send_len: return False
+ return True
+
+ def __ne__(self, other):
+ return not self.__eq__(other)
+
+ def __str__(self):
+ return self.show()
+
+ def show(self):
+ import loxi.pp
+ return loxi.pp.pp(self)
+
+ def pretty_print(self, q):
+ q.text("get_config_reply {")
+ with q.group():
+ with q.indent(2):
+ q.breakable()
+ q.text("xid = ");
+ if self.xid != None:
+ q.text("%#x" % self.xid)
+ else:
+ q.text('None')
+ q.text(","); q.breakable()
+ q.text("flags = ");
+ q.text("%#x" % self.flags)
+ q.text(","); q.breakable()
+ q.text("miss_send_len = ");
+ q.text("%#x" % self.miss_send_len)
+ q.breakable()
+ q.text('}')
+
+class get_config_request(Message):
+ version = const.OFP_VERSION
+ type = const.OFPT_GET_CONFIG_REQUEST
+
+ def __init__(self, xid=None):
+ self.xid = xid
+
+ def pack(self):
+ packed = []
+ packed.append(struct.pack("!B", self.version))
+ packed.append(struct.pack("!B", self.type))
+ packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
+ packed.append(struct.pack("!L", self.xid))
+ length = sum([len(x) for x in packed])
+ packed[2] = struct.pack("!H", length)
+ return ''.join(packed)
+
+ @staticmethod
+ def unpack(buf):
+ if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
+ obj = get_config_request()
+ version = struct.unpack_from('!B', buf, 0)[0]
+ assert(version == const.OFP_VERSION)
+ type = struct.unpack_from('!B', buf, 1)[0]
+ assert(type == const.OFPT_GET_CONFIG_REQUEST)
+ _length = struct.unpack_from('!H', buf, 2)[0]
+ assert(_length == len(buf))
+ if _length != 8: raise loxi.ProtocolError("get_config_request length is %d, should be 8" % _length)
+ obj.xid = struct.unpack_from('!L', buf, 4)[0]
+ return obj
+
+ def __eq__(self, other):
+ if type(self) != type(other): return False
+ if self.version != other.version: return False
+ if self.type != other.type: return False
+ if self.xid != other.xid: return False
+ return True
+
+ def __ne__(self, other):
+ return not self.__eq__(other)
+
+ def __str__(self):
+ return self.show()
+
+ def show(self):
+ import loxi.pp
+ return loxi.pp.pp(self)
+
+ def pretty_print(self, q):
+ q.text("get_config_request {")
+ with q.group():
+ with q.indent(2):
+ q.breakable()
+ q.text("xid = ");
+ if self.xid != None:
+ q.text("%#x" % self.xid)
+ else:
+ q.text('None')
+ q.breakable()
+ q.text('}')
+
+class hello(Message):
+ version = const.OFP_VERSION
+ type = const.OFPT_HELLO
+
+ def __init__(self, xid=None):
+ self.xid = xid
+
+ def pack(self):
+ packed = []
+ packed.append(struct.pack("!B", self.version))
+ packed.append(struct.pack("!B", self.type))
+ packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
+ packed.append(struct.pack("!L", self.xid))
+ length = sum([len(x) for x in packed])
+ packed[2] = struct.pack("!H", length)
+ return ''.join(packed)
+
+ @staticmethod
+ def unpack(buf):
+ if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
+ obj = hello()
+ version = struct.unpack_from('!B', buf, 0)[0]
+ assert(version == const.OFP_VERSION)
+ type = struct.unpack_from('!B', buf, 1)[0]
+ assert(type == const.OFPT_HELLO)
+ _length = struct.unpack_from('!H', buf, 2)[0]
+ assert(_length == len(buf))
+ if _length != 8: raise loxi.ProtocolError("hello length is %d, should be 8" % _length)
+ obj.xid = struct.unpack_from('!L', buf, 4)[0]
+ return obj
+
+ def __eq__(self, other):
+ if type(self) != type(other): return False
+ if self.version != other.version: return False
+ if self.type != other.type: return False
+ if self.xid != other.xid: return False
+ return True
+
+ def __ne__(self, other):
+ return not self.__eq__(other)
+
+ def __str__(self):
+ return self.show()
+
+ def show(self):
+ import loxi.pp
+ return loxi.pp.pp(self)
+
+ def pretty_print(self, q):
+ q.text("hello {")
+ with q.group():
+ with q.indent(2):
+ q.breakable()
+ q.text("xid = ");
+ if self.xid != None:
+ q.text("%#x" % self.xid)
+ else:
+ q.text('None')
+ q.breakable()
+ q.text('}')
+
+class nicira_controller_role_reply(Message):
+ version = const.OFP_VERSION
+ type = const.OFPT_VENDOR
+ experimenter = 0x2320
+ subtype = 11
+
+ def __init__(self, xid=None, role=None):
+ self.xid = xid
+ if role != None:
+ self.role = role
+ else:
+ self.role = 0
+
+ def pack(self):
+ packed = []
+ packed.append(struct.pack("!B", self.version))
+ packed.append(struct.pack("!B", self.type))
+ packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
+ packed.append(struct.pack("!L", self.xid))
+ packed.append(struct.pack("!L", self.experimenter))
+ packed.append(struct.pack("!L", self.subtype))
+ packed.append(struct.pack("!L", self.role))
+ length = sum([len(x) for x in packed])
+ packed[2] = struct.pack("!H", length)
+ return ''.join(packed)
+
+ @staticmethod
+ def unpack(buf):
+ if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
+ obj = nicira_controller_role_reply()
+ version = struct.unpack_from('!B', buf, 0)[0]
+ assert(version == const.OFP_VERSION)
+ type = struct.unpack_from('!B', buf, 1)[0]
+ assert(type == const.OFPT_VENDOR)
+ _length = struct.unpack_from('!H', buf, 2)[0]
+ assert(_length == len(buf))
+ if _length != 20: raise loxi.ProtocolError("nicira_controller_role_reply length is %d, should be 20" % _length)
+ obj.xid = struct.unpack_from('!L', buf, 4)[0]
+ experimenter = struct.unpack_from('!L', buf, 8)[0]
+ assert(experimenter == 0x2320)
+ subtype = struct.unpack_from('!L', buf, 12)[0]
+ assert(subtype == 11)
+ obj.role = struct.unpack_from('!L', buf, 16)[0]
+ return obj
+
+ def __eq__(self, other):
+ if type(self) != type(other): return False
+ if self.version != other.version: return False
+ if self.type != other.type: return False
+ if self.xid != other.xid: return False
+ if self.role != other.role: return False
+ return True
+
+ def __ne__(self, other):
+ return not self.__eq__(other)
+
+ def __str__(self):
+ return self.show()
+
+ def show(self):
+ import loxi.pp
+ return loxi.pp.pp(self)
+
+ def pretty_print(self, q):
+ q.text("nicira_controller_role_reply {")
+ with q.group():
+ with q.indent(2):
+ q.breakable()
+ q.text("xid = ");
+ if self.xid != None:
+ q.text("%#x" % self.xid)
+ else:
+ q.text('None')
+ q.text(","); q.breakable()
+ q.text("role = ");
+ q.text("%#x" % self.role)
+ q.breakable()
+ q.text('}')
+
+class nicira_controller_role_request(Message):
+ version = const.OFP_VERSION
+ type = const.OFPT_VENDOR
+ experimenter = 0x2320
+ subtype = 10
+
+ def __init__(self, xid=None, role=None):
+ self.xid = xid
+ if role != None:
+ self.role = role
+ else:
+ self.role = 0
+
+ def pack(self):
+ packed = []
+ packed.append(struct.pack("!B", self.version))
+ packed.append(struct.pack("!B", self.type))
+ packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
+ packed.append(struct.pack("!L", self.xid))
+ packed.append(struct.pack("!L", self.experimenter))
+ packed.append(struct.pack("!L", self.subtype))
+ packed.append(struct.pack("!L", self.role))
+ length = sum([len(x) for x in packed])
+ packed[2] = struct.pack("!H", length)
+ return ''.join(packed)
+
+ @staticmethod
+ def unpack(buf):
+ if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
+ obj = nicira_controller_role_request()
+ version = struct.unpack_from('!B', buf, 0)[0]
+ assert(version == const.OFP_VERSION)
+ type = struct.unpack_from('!B', buf, 1)[0]
+ assert(type == const.OFPT_VENDOR)
+ _length = struct.unpack_from('!H', buf, 2)[0]
+ assert(_length == len(buf))
+ if _length != 20: raise loxi.ProtocolError("nicira_controller_role_request length is %d, should be 20" % _length)
+ obj.xid = struct.unpack_from('!L', buf, 4)[0]
+ experimenter = struct.unpack_from('!L', buf, 8)[0]
+ assert(experimenter == 0x2320)
+ subtype = struct.unpack_from('!L', buf, 12)[0]
+ assert(subtype == 10)
+ obj.role = struct.unpack_from('!L', buf, 16)[0]
+ return obj
+
+ def __eq__(self, other):
+ if type(self) != type(other): return False
+ if self.version != other.version: return False
+ if self.type != other.type: return False
+ if self.xid != other.xid: return False
+ if self.role != other.role: return False
+ return True
+
+ def __ne__(self, other):
+ return not self.__eq__(other)
+
+ def __str__(self):
+ return self.show()
+
+ def show(self):
+ import loxi.pp
+ return loxi.pp.pp(self)
+
+ def pretty_print(self, q):
+ q.text("nicira_controller_role_request {")
+ with q.group():
+ with q.indent(2):
+ q.breakable()
+ q.text("xid = ");
+ if self.xid != None:
+ q.text("%#x" % self.xid)
+ else:
+ q.text('None')
+ q.text(","); q.breakable()
+ q.text("role = ");
+ q.text("%#x" % self.role)
+ q.breakable()
+ q.text('}')
+
+class packet_in(Message):
+ version = const.OFP_VERSION
+ type = const.OFPT_PACKET_IN
+
+ def __init__(self, xid=None, buffer_id=None, total_len=None, in_port=None, reason=None, pad=None, data=None):
+ self.xid = xid
+ if buffer_id != None:
+ self.buffer_id = buffer_id
+ else:
+ self.buffer_id = 0
+ if total_len != None:
+ self.total_len = total_len
+ else:
+ self.total_len = 0
+ if in_port != None:
+ self.in_port = in_port
+ else:
+ self.in_port = 0
+ if reason != None:
+ self.reason = reason
+ else:
+ self.reason = 0
+ if pad != None:
+ self.pad = pad
+ else:
+ self.pad = 0
+ if data != None:
+ self.data = data
+ else:
+ self.data = ""
+
+ def pack(self):
+ packed = []
+ packed.append(struct.pack("!B", self.version))
+ packed.append(struct.pack("!B", self.type))
+ packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
+ packed.append(struct.pack("!L", self.xid))
+ packed.append(struct.pack("!L", self.buffer_id))
+ packed.append(struct.pack("!H", self.total_len))
+ packed.append(struct.pack("!H", self.in_port))
+ packed.append(struct.pack("!B", self.reason))
+ packed.append(struct.pack("!B", self.pad))
+ packed.append(self.data)
+ length = sum([len(x) for x in packed])
+ packed[2] = struct.pack("!H", length)
+ return ''.join(packed)
+
+ @staticmethod
+ def unpack(buf):
+ if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
+ obj = packet_in()
+ version = struct.unpack_from('!B', buf, 0)[0]
+ assert(version == const.OFP_VERSION)
+ type = struct.unpack_from('!B', buf, 1)[0]
+ assert(type == const.OFPT_PACKET_IN)
+ _length = struct.unpack_from('!H', buf, 2)[0]
+ assert(_length == len(buf))
+ if _length < 18: raise loxi.ProtocolError("packet_in length is %d, should be at least 18" % _length)
+ obj.xid = struct.unpack_from('!L', buf, 4)[0]
+ obj.buffer_id = struct.unpack_from('!L', buf, 8)[0]
+ obj.total_len = struct.unpack_from('!H', buf, 12)[0]
+ obj.in_port = struct.unpack_from('!H', buf, 14)[0]
+ obj.reason = struct.unpack_from('!B', buf, 16)[0]
+ obj.pad = struct.unpack_from('!B', buf, 17)[0]
+ obj.data = buf[18:]
+ return obj
+
+ def __eq__(self, other):
+ if type(self) != type(other): return False
+ if self.version != other.version: return False
+ if self.type != other.type: return False
+ if self.xid != other.xid: return False
+ if self.buffer_id != other.buffer_id: return False
+ if self.total_len != other.total_len: return False
+ if self.in_port != other.in_port: return False
+ if self.reason != other.reason: return False
+ if self.pad != other.pad: return False
+ if self.data != other.data: return False
+ return True
+
+ def __ne__(self, other):
+ return not self.__eq__(other)
+
+ def __str__(self):
+ return self.show()
+
+ def show(self):
+ import loxi.pp
+ return loxi.pp.pp(self)
+
+ def pretty_print(self, q):
+ q.text("packet_in {")
+ with q.group():
+ with q.indent(2):
+ q.breakable()
+ q.text("xid = ");
+ if self.xid != None:
+ q.text("%#x" % self.xid)
+ else:
+ q.text('None')
+ q.text(","); q.breakable()
+ q.text("buffer_id = ");
+ q.text("%#x" % self.buffer_id)
+ q.text(","); q.breakable()
+ q.text("total_len = ");
+ q.text("%#x" % self.total_len)
+ q.text(","); q.breakable()
+ q.text("in_port = ");
+ q.text(util.pretty_port(self.in_port))
+ q.text(","); q.breakable()
+ q.text("reason = ");
+ q.text("%#x" % self.reason)
+ q.text(","); q.breakable()
+ q.text("pad = ");
+ q.text("%#x" % self.pad)
+ q.text(","); q.breakable()
+ q.text("data = ");
+ q.pp(self.data)
+ q.breakable()
+ q.text('}')
+
+class packet_out(Message):
+ version = const.OFP_VERSION
+ type = const.OFPT_PACKET_OUT
+
+ def __init__(self, xid=None, buffer_id=None, in_port=None, actions=None, data=None):
+ self.xid = xid
+ if buffer_id != None:
+ self.buffer_id = buffer_id
+ else:
+ self.buffer_id = 0
+ if in_port != None:
+ self.in_port = in_port
+ else:
+ self.in_port = 0
+ if actions != None:
+ self.actions = actions
+ else:
+ self.actions = []
+ if data != None:
+ self.data = data
+ else:
+ self.data = ""
+
+ def pack(self):
+ packed = []
+ packed.append(struct.pack("!B", self.version))
+ packed.append(struct.pack("!B", self.type))
+ packed.append(struct.pack("!H", 0)) # placeholder for length at index 3
+ packed.append(struct.pack("!L", self.xid))
+ packed.append(struct.pack("!L", self.buffer_id))
+ packed.append(struct.pack("!H", self.in_port))
+ packed_actions = "".join([x.pack() for x in self.actions])
+ packed.append(struct.pack("!H", len(packed_actions)))
+ packed.append(packed_actions)
+ packed.append(self.data)
+ length = sum([len(x) for x in packed])
+ packed[2] = struct.pack("!H", length)
+ return ''.join(packed)
+
+ @staticmethod
+ def unpack(buf):
+ if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
+ obj = packet_out()
+ version = struct.unpack_from('!B', buf, 0)[0]
+ assert(version == const.OFP_VERSION)
+ type = struct.unpack_from('!B', buf, 1)[0]
+ assert(type == const.OFPT_PACKET_OUT)
+ _length = struct.unpack_from('!H', buf, 2)[0]
+ assert(_length == len(buf))
+ if _length < 16: raise loxi.ProtocolError("packet_out length is %d, should be at least 16" % _length)
+ obj.xid = struct.unpack_from('!L', buf, 4)[0]
+ obj.buffer_id = struct.unpack_from('!L', buf, 8)[0]
+ obj.in_port = struct.unpack_from('!H', buf, 12)[0]
+ actions_len = struct.unpack_from('!H', buf, 14)[0]
+ obj.actions = action.unpack_list(buffer(buf, 16, actions_len))
+ obj.data = str(buffer(buf, 16+actions_len))
+ return obj
+
+ def __eq__(self, other):
+ if type(self) != type(other): return False
+ if self.version != other.version: return False
+ if self.type != other.type: return False
+ if self.xid != other.xid: return False
+ if self.buffer_id != other.buffer_id: return False
+ if self.in_port != other.in_port: return False
+ if self.actions != other.actions: return False
+ if self.data != other.data: return False
+ return True
+
+ def __ne__(self, other):
+ return not self.__eq__(other)
+
+ def __str__(self):
+ return self.show()
+
+ def show(self):
+ import loxi.pp
+ return loxi.pp.pp(self)
+
+ def pretty_print(self, q):
+ q.text("packet_out {")
+ with q.group():
+ with q.indent(2):
+ q.breakable()
+ q.text("xid = ");
+ if self.xid != None:
+ q.text("%#x" % self.xid)
+ else:
+ q.text('None')
+ q.text(","); q.breakable()
+ q.text("buffer_id = ");
+ q.text("%#x" % self.buffer_id)
+ q.text(","); q.breakable()
+ q.text("in_port = ");
+ q.text(util.pretty_port(self.in_port))
+ q.text(","); q.breakable()
+ q.text("actions = ");
+ q.pp(self.actions)
+ q.text(","); q.breakable()
+ q.text("data = ");
+ q.pp(self.data)
+ q.breakable()
+ q.text('}')
+
+class port_mod(Message):
+ version = const.OFP_VERSION
+ type = const.OFPT_PORT_MOD
+
+ def __init__(self, xid=None, port_no=None, hw_addr=None, config=None, mask=None, advertise=None, pad=None):
+ self.xid = xid
+ if port_no != None:
+ self.port_no = port_no
+ else:
+ self.port_no = 0
+ if hw_addr != None:
+ self.hw_addr = hw_addr
+ else:
+ self.hw_addr = [0,0,0,0,0,0]
+ if config != None:
+ self.config = config
+ else:
+ self.config = 0
+ if mask != None:
+ self.mask = mask
+ else:
+ self.mask = 0
+ if advertise != None:
+ self.advertise = advertise
+ else:
+ self.advertise = 0
+ if pad != None:
+ self.pad = pad
+ else:
+ self.pad = [0,0,0,0]
+
+ def pack(self):
+ packed = []
+ packed.append(struct.pack("!B", self.version))
+ packed.append(struct.pack("!B", self.type))
+ packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
+ packed.append(struct.pack("!L", self.xid))
+ packed.append(struct.pack("!H", self.port_no))
+ packed.append(struct.pack("!6B", *self.hw_addr))
+ packed.append(struct.pack("!L", self.config))
+ packed.append(struct.pack("!L", self.mask))
+ packed.append(struct.pack("!L", self.advertise))
+ packed.append(struct.pack("!4B", *self.pad))
+ length = sum([len(x) for x in packed])
+ packed[2] = struct.pack("!H", length)
+ return ''.join(packed)
+
+ @staticmethod
+ def unpack(buf):
+ if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
+ obj = port_mod()
+ version = struct.unpack_from('!B', buf, 0)[0]
+ assert(version == const.OFP_VERSION)
+ type = struct.unpack_from('!B', buf, 1)[0]
+ assert(type == const.OFPT_PORT_MOD)
+ _length = struct.unpack_from('!H', buf, 2)[0]
+ assert(_length == len(buf))
+ if _length != 32: raise loxi.ProtocolError("port_mod length is %d, should be 32" % _length)
+ obj.xid = struct.unpack_from('!L', buf, 4)[0]
+ obj.port_no = struct.unpack_from('!H', buf, 8)[0]
+ obj.hw_addr = list(struct.unpack_from('!6B', buf, 10))
+ obj.config = struct.unpack_from('!L', buf, 16)[0]
+ obj.mask = struct.unpack_from('!L', buf, 20)[0]
+ obj.advertise = struct.unpack_from('!L', buf, 24)[0]
+ obj.pad = list(struct.unpack_from('!4B', buf, 28))
+ return obj
+
+ def __eq__(self, other):
+ if type(self) != type(other): return False
+ if self.version != other.version: return False
+ if self.type != other.type: return False
+ if self.xid != other.xid: return False
+ if self.port_no != other.port_no: return False
+ if self.hw_addr != other.hw_addr: return False
+ if self.config != other.config: return False
+ if self.mask != other.mask: return False
+ if self.advertise != other.advertise: return False
+ if self.pad != other.pad: return False
+ return True
+
+ def __ne__(self, other):
+ return not self.__eq__(other)
+
+ def __str__(self):
+ return self.show()
+
+ def show(self):
+ import loxi.pp
+ return loxi.pp.pp(self)
+
+ def pretty_print(self, q):
+ q.text("port_mod {")
+ with q.group():
+ with q.indent(2):
+ q.breakable()
+ q.text("xid = ");
+ if self.xid != None:
+ q.text("%#x" % self.xid)
+ else:
+ q.text('None')
+ q.text(","); q.breakable()
+ q.text("port_no = ");
+ q.text(util.pretty_port(self.port_no))
+ q.text(","); q.breakable()
+ q.text("hw_addr = ");
+ q.text(util.pretty_mac(self.hw_addr))
+ q.text(","); q.breakable()
+ q.text("config = ");
+ q.text("%#x" % self.config)
+ q.text(","); q.breakable()
+ q.text("mask = ");
+ q.text("%#x" % self.mask)
+ q.text(","); q.breakable()
+ q.text("advertise = ");
+ q.text("%#x" % self.advertise)
+ q.text(","); q.breakable()
+ q.text("pad = ");
+ q.pp(self.pad)
+ q.breakable()
+ q.text('}')
+
+class port_stats_reply(Message):
+ version = const.OFP_VERSION
+ type = const.OFPT_STATS_REPLY
+ stats_type = const.OFPST_PORT
+
+ def __init__(self, xid=None, flags=None, entries=None):
+ self.xid = xid
+ if flags != None:
+ self.flags = flags
+ else:
+ self.flags = 0
+ if entries != None:
+ self.entries = entries
+ else:
+ self.entries = []
+
+ def pack(self):
+ packed = []
+ packed.append(struct.pack("!B", self.version))
+ packed.append(struct.pack("!B", self.type))
+ packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
+ packed.append(struct.pack("!L", self.xid))
+ packed.append(struct.pack("!H", self.stats_type))
+ packed.append(struct.pack("!H", self.flags))
+ packed.append("".join([x.pack() for x in self.entries]))
+ length = sum([len(x) for x in packed])
+ packed[2] = struct.pack("!H", length)
+ return ''.join(packed)
+
+ @staticmethod
+ def unpack(buf):
+ if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
+ obj = port_stats_reply()
+ version = struct.unpack_from('!B', buf, 0)[0]
+ assert(version == const.OFP_VERSION)
+ type = struct.unpack_from('!B', buf, 1)[0]
+ assert(type == const.OFPT_STATS_REPLY)
+ _length = struct.unpack_from('!H', buf, 2)[0]
+ assert(_length == len(buf))
+ if _length < 12: raise loxi.ProtocolError("port_stats_reply length is %d, should be at least 12" % _length)
+ obj.xid = struct.unpack_from('!L', buf, 4)[0]
+ stats_type = struct.unpack_from('!H', buf, 8)[0]
+ assert(stats_type == const.OFPST_PORT)
+ obj.flags = struct.unpack_from('!H', buf, 10)[0]
+ obj.entries = util.unpack_array(common.port_stats_entry.unpack, 104, buffer(buf, 12))
+ return obj
+
+ def __eq__(self, other):
+ if type(self) != type(other): return False
+ if self.version != other.version: return False
+ if self.type != other.type: return False
+ if self.xid != other.xid: return False
+ if self.flags != other.flags: return False
+ if self.entries != other.entries: return False
+ return True
+
+ def __ne__(self, other):
+ return not self.__eq__(other)
+
+ def __str__(self):
+ return self.show()
+
+ def show(self):
+ import loxi.pp
+ return loxi.pp.pp(self)
+
+ def pretty_print(self, q):
+ q.text("port_stats_reply {")
+ with q.group():
+ with q.indent(2):
+ q.breakable()
+ q.text("xid = ");
+ if self.xid != None:
+ q.text("%#x" % self.xid)
+ else:
+ q.text('None')
+ q.text(","); q.breakable()
+ q.text("flags = ");
+ q.text("%#x" % self.flags)
+ q.text(","); q.breakable()
+ q.text("entries = ");
+ q.pp(self.entries)
+ q.breakable()
+ q.text('}')
+
+class port_stats_request(Message):
+ version = const.OFP_VERSION
+ type = const.OFPT_STATS_REQUEST
+ stats_type = const.OFPST_PORT
+
+ def __init__(self, xid=None, flags=None, port_no=None, pad=None):
+ self.xid = xid
+ if flags != None:
+ self.flags = flags
+ else:
+ self.flags = 0
+ if port_no != None:
+ self.port_no = port_no
+ else:
+ self.port_no = 0
+ if pad != None:
+ self.pad = pad
+ else:
+ self.pad = [0,0,0,0,0,0]
+
+ def pack(self):
+ packed = []
+ packed.append(struct.pack("!B", self.version))
+ packed.append(struct.pack("!B", self.type))
+ packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
+ packed.append(struct.pack("!L", self.xid))
+ packed.append(struct.pack("!H", self.stats_type))
+ packed.append(struct.pack("!H", self.flags))
+ packed.append(struct.pack("!H", self.port_no))
+ packed.append(struct.pack("!6B", *self.pad))
+ length = sum([len(x) for x in packed])
+ packed[2] = struct.pack("!H", length)
+ return ''.join(packed)
+
+ @staticmethod
+ def unpack(buf):
+ if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
+ obj = port_stats_request()
+ version = struct.unpack_from('!B', buf, 0)[0]
+ assert(version == const.OFP_VERSION)
+ type = struct.unpack_from('!B', buf, 1)[0]
+ assert(type == const.OFPT_STATS_REQUEST)
+ _length = struct.unpack_from('!H', buf, 2)[0]
+ assert(_length == len(buf))
+ if _length != 20: raise loxi.ProtocolError("port_stats_request length is %d, should be 20" % _length)
+ obj.xid = struct.unpack_from('!L', buf, 4)[0]
+ stats_type = struct.unpack_from('!H', buf, 8)[0]
+ assert(stats_type == const.OFPST_PORT)
+ obj.flags = struct.unpack_from('!H', buf, 10)[0]
+ obj.port_no = struct.unpack_from('!H', buf, 12)[0]
+ obj.pad = list(struct.unpack_from('!6B', buf, 14))
+ return obj
+
+ def __eq__(self, other):
+ if type(self) != type(other): return False
+ if self.version != other.version: return False
+ if self.type != other.type: return False
+ if self.xid != other.xid: return False
+ if self.flags != other.flags: return False
+ if self.port_no != other.port_no: return False
+ if self.pad != other.pad: return False
+ return True
+
+ def __ne__(self, other):
+ return not self.__eq__(other)
+
+ def __str__(self):
+ return self.show()
+
+ def show(self):
+ import loxi.pp
+ return loxi.pp.pp(self)
+
+ def pretty_print(self, q):
+ q.text("port_stats_request {")
+ with q.group():
+ with q.indent(2):
+ q.breakable()
+ q.text("xid = ");
+ if self.xid != None:
+ q.text("%#x" % self.xid)
+ else:
+ q.text('None')
+ q.text(","); q.breakable()
+ q.text("flags = ");
+ q.text("%#x" % self.flags)
+ q.text(","); q.breakable()
+ q.text("port_no = ");
+ q.text(util.pretty_port(self.port_no))
+ q.text(","); q.breakable()
+ q.text("pad = ");
+ q.pp(self.pad)
+ q.breakable()
+ q.text('}')
+
+class port_status(Message):
+ version = const.OFP_VERSION
+ type = const.OFPT_PORT_STATUS
+
+ def __init__(self, xid=None, reason=None, pad=None, desc=None):
+ self.xid = xid
+ if reason != None:
+ self.reason = reason
+ else:
+ self.reason = 0
+ if pad != None:
+ self.pad = pad
+ else:
+ self.pad = [0,0,0,0,0,0,0]
+ if desc != None:
+ self.desc = desc
+ else:
+ self.desc = common.port_desc()
+
+ def pack(self):
+ packed = []
+ packed.append(struct.pack("!B", self.version))
+ packed.append(struct.pack("!B", self.type))
+ packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
+ packed.append(struct.pack("!L", self.xid))
+ packed.append(struct.pack("!B", self.reason))
+ packed.append(struct.pack("!7B", *self.pad))
+ packed.append(self.desc.pack())
+ length = sum([len(x) for x in packed])
+ packed[2] = struct.pack("!H", length)
+ return ''.join(packed)
+
+ @staticmethod
+ def unpack(buf):
+ if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
+ obj = port_status()
+ version = struct.unpack_from('!B', buf, 0)[0]
+ assert(version == const.OFP_VERSION)
+ type = struct.unpack_from('!B', buf, 1)[0]
+ assert(type == const.OFPT_PORT_STATUS)
+ _length = struct.unpack_from('!H', buf, 2)[0]
+ assert(_length == len(buf))
+ if _length != 64: raise loxi.ProtocolError("port_status length is %d, should be 64" % _length)
+ obj.xid = struct.unpack_from('!L', buf, 4)[0]
+ obj.reason = struct.unpack_from('!B', buf, 8)[0]
+ obj.pad = list(struct.unpack_from('!7B', buf, 9))
+ obj.desc = common.port_desc.unpack(buffer(buf, 16))
+ return obj
+
+ def __eq__(self, other):
+ if type(self) != type(other): return False
+ if self.version != other.version: return False
+ if self.type != other.type: return False
+ if self.xid != other.xid: return False
+ if self.reason != other.reason: return False
+ if self.pad != other.pad: return False
+ if self.desc != other.desc: return False
+ return True
+
+ def __ne__(self, other):
+ return not self.__eq__(other)
+
+ def __str__(self):
+ return self.show()
+
+ def show(self):
+ import loxi.pp
+ return loxi.pp.pp(self)
+
+ def pretty_print(self, q):
+ q.text("port_status {")
+ with q.group():
+ with q.indent(2):
+ q.breakable()
+ q.text("xid = ");
+ if self.xid != None:
+ q.text("%#x" % self.xid)
+ else:
+ q.text('None')
+ q.text(","); q.breakable()
+ q.text("reason = ");
+ q.text("%#x" % self.reason)
+ q.text(","); q.breakable()
+ q.text("pad = ");
+ q.pp(self.pad)
+ q.text(","); q.breakable()
+ q.text("desc = ");
+ q.pp(self.desc)
+ q.breakable()
+ q.text('}')
+
+class queue_get_config_reply(Message):
+ version = const.OFP_VERSION
+ type = const.OFPT_QUEUE_GET_CONFIG_REPLY
+
+ def __init__(self, xid=None, port=None, pad=None, queues=None):
+ self.xid = xid
+ if port != None:
+ self.port = port
+ else:
+ self.port = 0
+ if pad != None:
+ self.pad = pad
+ else:
+ self.pad = [0,0,0,0,0,0]
+ if queues != None:
+ self.queues = queues
+ else:
+ self.queues = []
+
+ def pack(self):
+ packed = []
+ packed.append(struct.pack("!B", self.version))
+ packed.append(struct.pack("!B", self.type))
+ packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
+ packed.append(struct.pack("!L", self.xid))
+ packed.append(struct.pack("!H", self.port))
+ packed.append(struct.pack("!6B", *self.pad))
+ packed.append("".join([x.pack() for x in self.queues]))
+ length = sum([len(x) for x in packed])
+ packed[2] = struct.pack("!H", length)
+ return ''.join(packed)
+
+ @staticmethod
+ def unpack(buf):
+ if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
+ obj = queue_get_config_reply()
+ version = struct.unpack_from('!B', buf, 0)[0]
+ assert(version == const.OFP_VERSION)
+ type = struct.unpack_from('!B', buf, 1)[0]
+ assert(type == const.OFPT_QUEUE_GET_CONFIG_REPLY)
+ _length = struct.unpack_from('!H', buf, 2)[0]
+ assert(_length == len(buf))
+ if _length < 16: raise loxi.ProtocolError("queue_get_config_reply length is %d, should be at least 16" % _length)
+ obj.xid = struct.unpack_from('!L', buf, 4)[0]
+ obj.port = struct.unpack_from('!H', buf, 8)[0]
+ obj.pad = list(struct.unpack_from('!6B', buf, 10))
+ obj.queues = common.unpack_list_packet_queue(buffer(buf, 16))
+ return obj
+
+ def __eq__(self, other):
+ if type(self) != type(other): return False
+ if self.version != other.version: return False
+ if self.type != other.type: return False
+ if self.xid != other.xid: return False
+ if self.port != other.port: return False
+ if self.pad != other.pad: return False
+ if self.queues != other.queues: return False
+ return True
+
+ def __ne__(self, other):
+ return not self.__eq__(other)
+
+ def __str__(self):
+ return self.show()
+
+ def show(self):
+ import loxi.pp
+ return loxi.pp.pp(self)
+
+ def pretty_print(self, q):
+ q.text("queue_get_config_reply {")
+ with q.group():
+ with q.indent(2):
+ q.breakable()
+ q.text("xid = ");
+ if self.xid != None:
+ q.text("%#x" % self.xid)
+ else:
+ q.text('None')
+ q.text(","); q.breakable()
+ q.text("port = ");
+ q.text(util.pretty_port(self.port))
+ q.text(","); q.breakable()
+ q.text("pad = ");
+ q.pp(self.pad)
+ q.text(","); q.breakable()
+ q.text("queues = ");
+ q.pp(self.queues)
+ q.breakable()
+ q.text('}')
+
+class queue_get_config_request(Message):
+ version = const.OFP_VERSION
+ type = const.OFPT_QUEUE_GET_CONFIG_REQUEST
+
+ def __init__(self, xid=None, port=None, pad=None):
+ self.xid = xid
+ if port != None:
+ self.port = port
+ else:
+ self.port = 0
+ if pad != None:
+ self.pad = pad
+ else:
+ self.pad = [0,0]
+
+ def pack(self):
+ packed = []
+ packed.append(struct.pack("!B", self.version))
+ packed.append(struct.pack("!B", self.type))
+ packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
+ packed.append(struct.pack("!L", self.xid))
+ packed.append(struct.pack("!H", self.port))
+ packed.append(struct.pack("!2B", *self.pad))
+ length = sum([len(x) for x in packed])
+ packed[2] = struct.pack("!H", length)
+ return ''.join(packed)
+
+ @staticmethod
+ def unpack(buf):
+ if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
+ obj = queue_get_config_request()
+ version = struct.unpack_from('!B', buf, 0)[0]
+ assert(version == const.OFP_VERSION)
+ type = struct.unpack_from('!B', buf, 1)[0]
+ assert(type == const.OFPT_QUEUE_GET_CONFIG_REQUEST)
+ _length = struct.unpack_from('!H', buf, 2)[0]
+ assert(_length == len(buf))
+ if _length != 12: raise loxi.ProtocolError("queue_get_config_request length is %d, should be 12" % _length)
+ obj.xid = struct.unpack_from('!L', buf, 4)[0]
+ obj.port = struct.unpack_from('!H', buf, 8)[0]
+ obj.pad = list(struct.unpack_from('!2B', buf, 10))
+ return obj
+
+ def __eq__(self, other):
+ if type(self) != type(other): return False
+ if self.version != other.version: return False
+ if self.type != other.type: return False
+ if self.xid != other.xid: return False
+ if self.port != other.port: return False
+ if self.pad != other.pad: return False
+ return True
+
+ def __ne__(self, other):
+ return not self.__eq__(other)
+
+ def __str__(self):
+ return self.show()
+
+ def show(self):
+ import loxi.pp
+ return loxi.pp.pp(self)
+
+ def pretty_print(self, q):
+ q.text("queue_get_config_request {")
+ with q.group():
+ with q.indent(2):
+ q.breakable()
+ q.text("xid = ");
+ if self.xid != None:
+ q.text("%#x" % self.xid)
+ else:
+ q.text('None')
+ q.text(","); q.breakable()
+ q.text("port = ");
+ q.text(util.pretty_port(self.port))
+ q.text(","); q.breakable()
+ q.text("pad = ");
+ q.pp(self.pad)
+ q.breakable()
+ q.text('}')
+
+class queue_stats_reply(Message):
+ version = const.OFP_VERSION
+ type = const.OFPT_STATS_REPLY
+ stats_type = const.OFPST_QUEUE
+
+ def __init__(self, xid=None, flags=None, entries=None):
+ self.xid = xid
+ if flags != None:
+ self.flags = flags
+ else:
+ self.flags = 0
+ if entries != None:
+ self.entries = entries
+ else:
+ self.entries = []
+
+ def pack(self):
+ packed = []
+ packed.append(struct.pack("!B", self.version))
+ packed.append(struct.pack("!B", self.type))
+ packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
+ packed.append(struct.pack("!L", self.xid))
+ packed.append(struct.pack("!H", self.stats_type))
+ packed.append(struct.pack("!H", self.flags))
+ packed.append("".join([x.pack() for x in self.entries]))
+ length = sum([len(x) for x in packed])
+ packed[2] = struct.pack("!H", length)
+ return ''.join(packed)
+
+ @staticmethod
+ def unpack(buf):
+ if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
+ obj = queue_stats_reply()
+ version = struct.unpack_from('!B', buf, 0)[0]
+ assert(version == const.OFP_VERSION)
+ type = struct.unpack_from('!B', buf, 1)[0]
+ assert(type == const.OFPT_STATS_REPLY)
+ _length = struct.unpack_from('!H', buf, 2)[0]
+ assert(_length == len(buf))
+ if _length < 12: raise loxi.ProtocolError("queue_stats_reply length is %d, should be at least 12" % _length)
+ obj.xid = struct.unpack_from('!L', buf, 4)[0]
+ stats_type = struct.unpack_from('!H', buf, 8)[0]
+ assert(stats_type == const.OFPST_QUEUE)
+ obj.flags = struct.unpack_from('!H', buf, 10)[0]
+ obj.entries = util.unpack_array(common.queue_stats_entry.unpack, 32, buffer(buf, 12))
+ return obj
+
+ def __eq__(self, other):
+ if type(self) != type(other): return False
+ if self.version != other.version: return False
+ if self.type != other.type: return False
+ if self.xid != other.xid: return False
+ if self.flags != other.flags: return False
+ if self.entries != other.entries: return False
+ return True
+
+ def __ne__(self, other):
+ return not self.__eq__(other)
+
+ def __str__(self):
+ return self.show()
+
+ def show(self):
+ import loxi.pp
+ return loxi.pp.pp(self)
+
+ def pretty_print(self, q):
+ q.text("queue_stats_reply {")
+ with q.group():
+ with q.indent(2):
+ q.breakable()
+ q.text("xid = ");
+ if self.xid != None:
+ q.text("%#x" % self.xid)
+ else:
+ q.text('None')
+ q.text(","); q.breakable()
+ q.text("flags = ");
+ q.text("%#x" % self.flags)
+ q.text(","); q.breakable()
+ q.text("entries = ");
+ q.pp(self.entries)
+ q.breakable()
+ q.text('}')
+
+class queue_stats_request(Message):
+ version = const.OFP_VERSION
+ type = const.OFPT_STATS_REQUEST
+ stats_type = const.OFPST_QUEUE
+
+ def __init__(self, xid=None, flags=None, port_no=None, pad=None, queue_id=None):
+ self.xid = xid
+ if flags != None:
+ self.flags = flags
+ else:
+ self.flags = 0
+ if port_no != None:
+ self.port_no = port_no
+ else:
+ self.port_no = 0
+ if pad != None:
+ self.pad = pad
+ else:
+ self.pad = [0,0]
+ if queue_id != None:
+ self.queue_id = queue_id
+ else:
+ self.queue_id = 0
+
+ def pack(self):
+ packed = []
+ packed.append(struct.pack("!B", self.version))
+ packed.append(struct.pack("!B", self.type))
+ packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
+ packed.append(struct.pack("!L", self.xid))
+ packed.append(struct.pack("!H", self.stats_type))
+ packed.append(struct.pack("!H", self.flags))
+ packed.append(struct.pack("!H", self.port_no))
+ packed.append(struct.pack("!2B", *self.pad))
+ packed.append(struct.pack("!L", self.queue_id))
+ length = sum([len(x) for x in packed])
+ packed[2] = struct.pack("!H", length)
+ return ''.join(packed)
+
+ @staticmethod
+ def unpack(buf):
+ if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
+ obj = queue_stats_request()
+ version = struct.unpack_from('!B', buf, 0)[0]
+ assert(version == const.OFP_VERSION)
+ type = struct.unpack_from('!B', buf, 1)[0]
+ assert(type == const.OFPT_STATS_REQUEST)
+ _length = struct.unpack_from('!H', buf, 2)[0]
+ assert(_length == len(buf))
+ if _length != 20: raise loxi.ProtocolError("queue_stats_request length is %d, should be 20" % _length)
+ obj.xid = struct.unpack_from('!L', buf, 4)[0]
+ stats_type = struct.unpack_from('!H', buf, 8)[0]
+ assert(stats_type == const.OFPST_QUEUE)
+ obj.flags = struct.unpack_from('!H', buf, 10)[0]
+ obj.port_no = struct.unpack_from('!H', buf, 12)[0]
+ obj.pad = list(struct.unpack_from('!2B', buf, 14))
+ obj.queue_id = struct.unpack_from('!L', buf, 16)[0]
+ return obj
+
+ def __eq__(self, other):
+ if type(self) != type(other): return False
+ if self.version != other.version: return False
+ if self.type != other.type: return False
+ if self.xid != other.xid: return False
+ if self.flags != other.flags: return False
+ if self.port_no != other.port_no: return False
+ if self.pad != other.pad: return False
+ if self.queue_id != other.queue_id: return False
+ return True
+
+ def __ne__(self, other):
+ return not self.__eq__(other)
+
+ def __str__(self):
+ return self.show()
+
+ def show(self):
+ import loxi.pp
+ return loxi.pp.pp(self)
+
+ def pretty_print(self, q):
+ q.text("queue_stats_request {")
+ with q.group():
+ with q.indent(2):
+ q.breakable()
+ q.text("xid = ");
+ if self.xid != None:
+ q.text("%#x" % self.xid)
+ else:
+ q.text('None')
+ q.text(","); q.breakable()
+ q.text("flags = ");
+ q.text("%#x" % self.flags)
+ q.text(","); q.breakable()
+ q.text("port_no = ");
+ q.text(util.pretty_port(self.port_no))
+ q.text(","); q.breakable()
+ q.text("pad = ");
+ q.pp(self.pad)
+ q.text(","); q.breakable()
+ q.text("queue_id = ");
+ q.text("%#x" % self.queue_id)
+ q.breakable()
+ q.text('}')
+
+class set_config(Message):
+ version = const.OFP_VERSION
+ type = const.OFPT_SET_CONFIG
+
+ def __init__(self, xid=None, flags=None, miss_send_len=None):
+ self.xid = xid
+ if flags != None:
+ self.flags = flags
+ else:
+ self.flags = 0
+ if miss_send_len != None:
+ self.miss_send_len = miss_send_len
+ else:
+ self.miss_send_len = 0
+
+ def pack(self):
+ packed = []
+ packed.append(struct.pack("!B", self.version))
+ packed.append(struct.pack("!B", self.type))
+ packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
+ packed.append(struct.pack("!L", self.xid))
+ packed.append(struct.pack("!H", self.flags))
+ packed.append(struct.pack("!H", self.miss_send_len))
+ length = sum([len(x) for x in packed])
+ packed[2] = struct.pack("!H", length)
+ return ''.join(packed)
+
+ @staticmethod
+ def unpack(buf):
+ if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
+ obj = set_config()
+ version = struct.unpack_from('!B', buf, 0)[0]
+ assert(version == const.OFP_VERSION)
+ type = struct.unpack_from('!B', buf, 1)[0]
+ assert(type == const.OFPT_SET_CONFIG)
+ _length = struct.unpack_from('!H', buf, 2)[0]
+ assert(_length == len(buf))
+ if _length != 12: raise loxi.ProtocolError("set_config length is %d, should be 12" % _length)
+ obj.xid = struct.unpack_from('!L', buf, 4)[0]
+ obj.flags = struct.unpack_from('!H', buf, 8)[0]
+ obj.miss_send_len = struct.unpack_from('!H', buf, 10)[0]
+ return obj
+
+ def __eq__(self, other):
+ if type(self) != type(other): return False
+ if self.version != other.version: return False
+ if self.type != other.type: return False
+ if self.xid != other.xid: return False
+ if self.flags != other.flags: return False
+ if self.miss_send_len != other.miss_send_len: return False
+ return True
+
+ def __ne__(self, other):
+ return not self.__eq__(other)
+
+ def __str__(self):
+ return self.show()
+
+ def show(self):
+ import loxi.pp
+ return loxi.pp.pp(self)
+
+ def pretty_print(self, q):
+ q.text("set_config {")
+ with q.group():
+ with q.indent(2):
+ q.breakable()
+ q.text("xid = ");
+ if self.xid != None:
+ q.text("%#x" % self.xid)
+ else:
+ q.text('None')
+ q.text(","); q.breakable()
+ q.text("flags = ");
+ q.text("%#x" % self.flags)
+ q.text(","); q.breakable()
+ q.text("miss_send_len = ");
+ q.text("%#x" % self.miss_send_len)
+ q.breakable()
+ q.text('}')
+
+class table_mod(Message):
+ version = const.OFP_VERSION
+ type = 22
+
+ def __init__(self, xid=None, table_id=None, pad=None, config=None):
+ self.xid = xid
+ if table_id != None:
+ self.table_id = table_id
+ else:
+ self.table_id = 0
+ if pad != None:
+ self.pad = pad
+ else:
+ self.pad = [0,0,0]
+ if config != None:
+ self.config = config
+ else:
+ self.config = 0
+
+ def pack(self):
+ packed = []
+ packed.append(struct.pack("!B", self.version))
+ packed.append(struct.pack("!B", self.type))
+ packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
+ packed.append(struct.pack("!L", self.xid))
+ packed.append(struct.pack("!B", self.table_id))
+ packed.append(struct.pack("!3B", *self.pad))
+ packed.append(struct.pack("!L", self.config))
+ length = sum([len(x) for x in packed])
+ packed[2] = struct.pack("!H", length)
+ return ''.join(packed)
+
+ @staticmethod
+ def unpack(buf):
+ if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
+ obj = table_mod()
+ version = struct.unpack_from('!B', buf, 0)[0]
+ assert(version == const.OFP_VERSION)
+ type = struct.unpack_from('!B', buf, 1)[0]
+ assert(type == 22)
+ _length = struct.unpack_from('!H', buf, 2)[0]
+ assert(_length == len(buf))
+ if _length != 16: raise loxi.ProtocolError("table_mod length is %d, should be 16" % _length)
+ obj.xid = struct.unpack_from('!L', buf, 4)[0]
+ obj.table_id = struct.unpack_from('!B', buf, 8)[0]
+ obj.pad = list(struct.unpack_from('!3B', buf, 9))
+ obj.config = struct.unpack_from('!L', buf, 12)[0]
+ return obj
+
+ def __eq__(self, other):
+ if type(self) != type(other): return False
+ if self.version != other.version: return False
+ if self.type != other.type: return False
+ if self.xid != other.xid: return False
+ if self.table_id != other.table_id: return False
+ if self.pad != other.pad: return False
+ if self.config != other.config: return False
+ return True
+
+ def __ne__(self, other):
+ return not self.__eq__(other)
+
+ def __str__(self):
+ return self.show()
+
+ def show(self):
+ import loxi.pp
+ return loxi.pp.pp(self)
+
+ def pretty_print(self, q):
+ q.text("table_mod {")
+ with q.group():
+ with q.indent(2):
+ q.breakable()
+ q.text("xid = ");
+ if self.xid != None:
+ q.text("%#x" % self.xid)
+ else:
+ q.text('None')
+ q.text(","); q.breakable()
+ q.text("table_id = ");
+ q.text("%#x" % self.table_id)
+ q.text(","); q.breakable()
+ q.text("pad = ");
+ q.pp(self.pad)
+ q.text(","); q.breakable()
+ q.text("config = ");
+ q.text("%#x" % self.config)
+ q.breakable()
+ q.text('}')
+
+class table_stats_reply(Message):
+ version = const.OFP_VERSION
+ type = const.OFPT_STATS_REPLY
+ stats_type = const.OFPST_TABLE
+
+ def __init__(self, xid=None, flags=None, entries=None):
+ self.xid = xid
+ if flags != None:
+ self.flags = flags
+ else:
+ self.flags = 0
+ if entries != None:
+ self.entries = entries
+ else:
+ self.entries = []
+
+ def pack(self):
+ packed = []
+ packed.append(struct.pack("!B", self.version))
+ packed.append(struct.pack("!B", self.type))
+ packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
+ packed.append(struct.pack("!L", self.xid))
+ packed.append(struct.pack("!H", self.stats_type))
+ packed.append(struct.pack("!H", self.flags))
+ packed.append("".join([x.pack() for x in self.entries]))
+ length = sum([len(x) for x in packed])
+ packed[2] = struct.pack("!H", length)
+ return ''.join(packed)
+
+ @staticmethod
+ def unpack(buf):
+ if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
+ obj = table_stats_reply()
+ version = struct.unpack_from('!B', buf, 0)[0]
+ assert(version == const.OFP_VERSION)
+ type = struct.unpack_from('!B', buf, 1)[0]
+ assert(type == const.OFPT_STATS_REPLY)
+ _length = struct.unpack_from('!H', buf, 2)[0]
+ assert(_length == len(buf))
+ if _length < 12: raise loxi.ProtocolError("table_stats_reply length is %d, should be at least 12" % _length)
+ obj.xid = struct.unpack_from('!L', buf, 4)[0]
+ stats_type = struct.unpack_from('!H', buf, 8)[0]
+ assert(stats_type == const.OFPST_TABLE)
+ obj.flags = struct.unpack_from('!H', buf, 10)[0]
+ obj.entries = util.unpack_array(common.table_stats_entry.unpack, 64, buffer(buf, 12))
+ return obj
+
+ def __eq__(self, other):
+ if type(self) != type(other): return False
+ if self.version != other.version: return False
+ if self.type != other.type: return False
+ if self.xid != other.xid: return False
+ if self.flags != other.flags: return False
+ if self.entries != other.entries: return False
+ return True
+
+ def __ne__(self, other):
+ return not self.__eq__(other)
+
+ def __str__(self):
+ return self.show()
+
+ def show(self):
+ import loxi.pp
+ return loxi.pp.pp(self)
+
+ def pretty_print(self, q):
+ q.text("table_stats_reply {")
+ with q.group():
+ with q.indent(2):
+ q.breakable()
+ q.text("xid = ");
+ if self.xid != None:
+ q.text("%#x" % self.xid)
+ else:
+ q.text('None')
+ q.text(","); q.breakable()
+ q.text("flags = ");
+ q.text("%#x" % self.flags)
+ q.text(","); q.breakable()
+ q.text("entries = ");
+ q.pp(self.entries)
+ q.breakable()
+ q.text('}')
+
+class table_stats_request(Message):
+ version = const.OFP_VERSION
+ type = const.OFPT_STATS_REQUEST
+ stats_type = const.OFPST_TABLE
+
+ def __init__(self, xid=None, flags=None):
+ self.xid = xid
+ if flags != None:
+ self.flags = flags
+ else:
+ self.flags = 0
+
+ def pack(self):
+ packed = []
+ packed.append(struct.pack("!B", self.version))
+ packed.append(struct.pack("!B", self.type))
+ packed.append(struct.pack("!H", 0)) # placeholder for length at index 2
+ packed.append(struct.pack("!L", self.xid))
+ packed.append(struct.pack("!H", self.stats_type))
+ packed.append(struct.pack("!H", self.flags))
+ length = sum([len(x) for x in packed])
+ packed[2] = struct.pack("!H", length)
+ return ''.join(packed)
+
+ @staticmethod
+ def unpack(buf):
+ if len(buf) < 8: raise loxi.ProtocolError("buffer too short to contain an OpenFlow message")
+ obj = table_stats_request()
+ version = struct.unpack_from('!B', buf, 0)[0]
+ assert(version == const.OFP_VERSION)
+ type = struct.unpack_from('!B', buf, 1)[0]
+ assert(type == const.OFPT_STATS_REQUEST)
+ _length = struct.unpack_from('!H', buf, 2)[0]
+ assert(_length == len(buf))
+ if _length != 12: raise loxi.ProtocolError("table_stats_request length is %d, should be 12" % _length)
+ obj.xid = struct.unpack_from('!L', buf, 4)[0]
+ stats_type = struct.unpack_from('!H', buf, 8)[0]
+ assert(stats_type == const.OFPST_TABLE)
+ obj.flags = struct.unpack_from('!H', buf, 10)[0]
+ return obj
+
+ def __eq__(self, other):
+ if type(self) != type(other): return False
+ if self.version != other.version: return False
+ if self.type != other.type: return False
+ if self.xid != other.xid: return False
+ if self.flags != other.flags: return False
+ return True
+
+ def __ne__(self, other):
+ return not self.__eq__(other)
+
+ def __str__(self):
+ return self.show()
+
+ def show(self):
+ import loxi.pp
+ return loxi.pp.pp(self)
+
+ def pretty_print(self, q):
+ q.text("table_stats_request {")
+ with q.group():
+ with q.indent(2):
+ q.breakable()
+ q.text("xid = ");
+ if self.xid != None:
+ q.text("%#x" % self.xid)
+ else:
+ q.text('None')
+ q.text(","); q.breakable()
+ q.text("flags = ");
+ q.text("%#x" % self.flags)
+ q.breakable()
+ q.text('}')
+
+
+def parse_header(buf):
+ if len(buf) < 8:
+ raise loxi.ProtocolError("too short to be an OpenFlow message")
+ return struct.unpack_from("!BBHL", buf)
+
+def parse_message(buf):
+ msg_ver, msg_type, msg_len, msg_xid = parse_header(buf)
+ if msg_ver != const.OFP_VERSION and msg_type != ofp.OFPT_HELLO:
+ raise loxi.ProtocolError("wrong OpenFlow version")
+ if len(buf) != msg_len:
+ raise loxi.ProtocolError("incorrect message size")
+ if msg_type in parsers:
+ return parsers[msg_type](buf)
+ else:
+ raise loxi.ProtocolError("unexpected message type")
+
+def parse_flow_mod(buf):
+ if len(buf) < 56 + 2:
+ raise loxi.ProtocolError("message too short")
+ cmd, = struct.unpack_from("!H", buf, 56)
+ if cmd in flow_mod_parsers:
+ return flow_mod_parsers[cmd](buf)
+ else:
+ raise loxi.ProtocolError("unexpected flow mod cmd %u" % cmd)
+
+def parse_stats_reply(buf):
+ if len(buf) < 8 + 2:
+ raise loxi.ProtocolError("message too short")
+ stats_type, = struct.unpack_from("!H", buf, 8)
+ if stats_type in stats_reply_parsers:
+ return stats_reply_parsers[stats_type](buf)
+ else:
+ raise loxi.ProtocolError("unexpected stats type %u" % stats_type)
+
+def parse_stats_request(buf):
+ if len(buf) < 8 + 2:
+ raise loxi.ProtocolError("message too short")
+ stats_type, = struct.unpack_from("!H", buf, 8)
+ if stats_type in stats_request_parsers:
+ return stats_request_parsers[stats_type](buf)
+ else:
+ raise loxi.ProtocolError("unexpected stats type %u" % stats_type)
+
+def parse_vendor(buf):
+ if len(buf) < 16:
+ raise loxi.ProtocolError("experimenter message too short")
+
+ experimenter, = struct.unpack_from("!L", buf, 8)
+ if experimenter == 0x005c16c7: # Big Switch Networks
+ subtype, = struct.unpack_from("!L", buf, 12)
+ elif experimenter == 0x00002320: # Nicira
+ subtype, = struct.unpack_from("!L", buf, 12)
+ else:
+ raise loxi.ProtocolError("unexpected experimenter id %#x" % experimenter)
+
+ if subtype in experimenter_parsers[experimenter]:
+ return experimenter_parsers[experimenter][subtype](buf)
+ else:
+ raise loxi.ProtocolError("unexpected experimenter %#x subtype %#x" % (experimenter, subtype))
+
+parsers = {
+ 22 : table_mod.unpack,
+ const.OFPT_BARRIER_REPLY : barrier_reply.unpack,
+ const.OFPT_BARRIER_REQUEST : barrier_request.unpack,
+ const.OFPT_ECHO_REPLY : echo_reply.unpack,
+ const.OFPT_ECHO_REQUEST : echo_request.unpack,
+ const.OFPT_ERROR : error_msg.unpack,
+ const.OFPT_FEATURES_REPLY : features_reply.unpack,
+ const.OFPT_FEATURES_REQUEST : features_request.unpack,
+ const.OFPT_FLOW_MOD : parse_flow_mod,
+ const.OFPT_FLOW_REMOVED : flow_removed.unpack,
+ const.OFPT_GET_CONFIG_REPLY : get_config_reply.unpack,
+ const.OFPT_GET_CONFIG_REQUEST : get_config_request.unpack,
+ const.OFPT_HELLO : hello.unpack,
+ const.OFPT_PACKET_IN : packet_in.unpack,
+ const.OFPT_PACKET_OUT : packet_out.unpack,
+ const.OFPT_PORT_MOD : port_mod.unpack,
+ const.OFPT_PORT_STATUS : port_status.unpack,
+ const.OFPT_QUEUE_GET_CONFIG_REPLY : queue_get_config_reply.unpack,
+ const.OFPT_QUEUE_GET_CONFIG_REQUEST : queue_get_config_request.unpack,
+ const.OFPT_SET_CONFIG : set_config.unpack,
+ const.OFPT_STATS_REPLY : parse_stats_reply,
+ const.OFPT_STATS_REQUEST : parse_stats_request,
+ const.OFPT_VENDOR : parse_vendor,
+}
+
+flow_mod_parsers = {
+ const.OFPFC_ADD : flow_add.unpack,
+ const.OFPFC_MODIFY : flow_modify.unpack,
+ const.OFPFC_MODIFY_STRICT : flow_modify_strict.unpack,
+ const.OFPFC_DELETE : flow_delete.unpack,
+ const.OFPFC_DELETE_STRICT : flow_delete_strict.unpack,
+}
+
+stats_reply_parsers = {
+ const.OFPST_DESC : desc_stats_reply.unpack,
+ const.OFPST_FLOW : flow_stats_reply.unpack,
+ const.OFPST_AGGREGATE : aggregate_stats_reply.unpack,
+ const.OFPST_TABLE : table_stats_reply.unpack,
+ const.OFPST_PORT : port_stats_reply.unpack,
+ const.OFPST_QUEUE : queue_stats_reply.unpack,
+ const.OFPST_VENDOR : experimenter_stats_reply.unpack,
+}
+
+stats_request_parsers = {
+ const.OFPST_DESC : desc_stats_request.unpack,
+ const.OFPST_FLOW : flow_stats_request.unpack,
+ const.OFPST_AGGREGATE : aggregate_stats_request.unpack,
+ const.OFPST_TABLE : table_stats_request.unpack,
+ const.OFPST_PORT : port_stats_request.unpack,
+ const.OFPST_QUEUE : queue_stats_request.unpack,
+ const.OFPST_VENDOR : experimenter_stats_request.unpack,
+}
+
+experimenter_parsers = {
+ 0x2320 : {
+ 11: nicira_controller_role_reply.unpack,
+ 10: nicira_controller_role_request.unpack,
+ },
+ 0x5c16c7 : {
+ 10: bsn_get_interfaces_reply.unpack,
+ 9: bsn_get_interfaces_request.unpack,
+ 2: bsn_get_ip_mask_reply.unpack,
+ 1: bsn_get_ip_mask_request.unpack,
+ 5: bsn_get_mirroring_reply.unpack,
+ 4: bsn_get_mirroring_request.unpack,
+ 0: bsn_set_ip_mask.unpack,
+ 3: bsn_set_mirroring.unpack,
+ 6: bsn_shell_command.unpack,
+ 7: bsn_shell_output.unpack,
+ 8: bsn_shell_status.unpack,
+ },
+}
diff --git a/src/python/loxi/of10/util.py b/src/python/loxi/of10/util.py
new file mode 100644
index 0000000..713d5cb
--- /dev/null
+++ b/src/python/loxi/of10/util.py
@@ -0,0 +1,64 @@
+#
+# Copyright 2012, 2013, Big Switch Networks, Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+
+# Automatically generated by LOXI from template util.py
+# Do not modify
+
+import loxi
+import const
+
+def unpack_array(deserializer, element_size, buf):
+ """
+ Deserialize an array of fixed length elements.
+ The deserializer function should take a buffer and return the new object.
+ """
+ if len(buf) % element_size != 0: raise loxi.ProtocolError("invalid array length")
+ n = len(buf) / element_size
+ return [deserializer(buffer(buf, i*element_size, element_size)) for i in range(n)]
+
+def pretty_mac(mac):
+ return ':'.join(["%02x" % x for x in mac])
+
+def pretty_ipv4(v):
+ return "%d.%d.%d.%d" % ((v >> 24) & 0xFF, (v >> 16) & 0xFF, (v >> 8) & 0xFF, v & 0xFF)
+
+def pretty_flags(v, flag_names):
+ set_flags = []
+ for flag_name in flag_names:
+ flag_value = getattr(const, flag_name)
+ if v & flag_value == flag_value:
+ set_flags.append(flag_name)
+ elif v & flag_value:
+ set_flags.append('%s&%#x' % (flag_name, v & flag_value))
+ v &= ~flag_value
+ if v:
+ set_flags.append("%#x" % v)
+ return '|'.join(set_flags) or '0'
+
+def pretty_wildcards(v):
+ if v == const.OFPFW_ALL:
+ return 'OFPFW_ALL'
+ flag_names = ['OFPFW_IN_PORT', 'OFPFW_DL_VLAN', 'OFPFW_DL_SRC', 'OFPFW_DL_DST',
+ 'OFPFW_DL_TYPE', 'OFPFW_NW_PROTO', 'OFPFW_TP_SRC', 'OFPFW_TP_DST',
+ 'OFPFW_NW_SRC_MASK', 'OFPFW_NW_DST_MASK', 'OFPFW_DL_VLAN_PCP',
+ 'OFPFW_NW_TOS']
+ return pretty_flags(v, flag_names)
+
+def pretty_port(v):
+ named_ports = [(k,v2) for (k,v2) in const.__dict__.iteritems() if k.startswith('OFPP_')]
+ for (k, v2) in named_ports:
+ if v == v2:
+ return k
+ return v