Merge pull request #10 from rlane/pyloxi-1.3
PyLoxi 1.3 work
diff --git a/Makefile b/Makefile
index be487ad..55bb35d 100644
--- a/Makefile
+++ b/Makefile
@@ -36,6 +36,7 @@
# Generated files depend on all Loxi code and input files
LOXI_PY_FILES=$(shell find \( -name loxi_output -prune \
-o -name templates -prune \
+ -o -name tests -prune \
-o -true \
\) -a -name '*.py')
LOXI_TEMPLATE_FILES=$(shell find */templates -type f -a \
diff --git a/lang_python.py b/lang_python.py
index 9dd44b2..639cf1a 100644
--- a/lang_python.py
+++ b/lang_python.py
@@ -46,9 +46,11 @@
message.py # Message classes
util.py # Utility functions
of11: ... # (code generation incomplete)
+ instruction.py # Instruction classes
of12: ... # (code generation incomplete)
oxm.py # OXM classes
of13: ... # (code generation incomplete)
+ meter_band.py # Meter band classes
The user will add the pyloxi directory to PYTHONPATH. Then they can
"import loxi" or "import loxi.of10". The idiomatic import is
@@ -74,9 +76,9 @@
modules = {
1: ["action", "common", "const", "message", "util"],
- 2: ["action", "common", "const", "message", "util"],
- 3: ["action", "common", "const", "message", "oxm", "util"],
- 4: ["action", "common", "const", "message", "oxm", "util"],
+ 2: ["action", "common", "const", "instruction", "message", "util"],
+ 3: ["action", "common", "const", "instruction", "message", "oxm", "util"],
+ 4: ["action", "common", "const", "instruction", "message", "meter_band", "oxm", "util"],
}
def make_gen(name, version):
diff --git a/openflow_input/standard-1.3 b/openflow_input/standard-1.3
index 591e254..e7a9812 100644
--- a/openflow_input/standard-1.3
+++ b/openflow_input/standard-1.3
@@ -1320,6 +1320,27 @@
uint8_t[4] pad;
};
+struct ofp_table_stats_request {
+ uint8_t version;
+ uint8_t type;
+ uint16_t length;
+ uint32_t xid;
+ uint16_t stats_type;
+ uint16_t flags;
+ uint8_t[4] pad;
+};
+
+struct ofp_table_stats_reply {
+ uint8_t version;
+ uint8_t type;
+ uint16_t length;
+ uint32_t xid;
+ uint16_t stats_type;
+ uint16_t flags;
+ uint8_t[4] pad;
+ list(of_table_stats_entry_t) entries;
+};
+
// FIXME: These are padded to 8 byte align beyond the length indicated
struct ofp_table_feature_prop {
diff --git a/py_gen/codegen.py b/py_gen/codegen.py
index 7037398..d6d8b32 100644
--- a/py_gen/codegen.py
+++ b/py_gen/codegen.py
@@ -91,6 +91,10 @@
type_values['type'] = 0
elif cls == "of_match_v3":
type_values['type'] = 1
+ elif utils.class_is_meter_band(cls):
+ type_values['type'] = util.constant_for_value(version, "ofp_meter_band_type", util.primary_wire_type(cls, version))
+ elif utils.class_is_instruction(cls):
+ type_values['type'] = util.constant_for_value(version, "ofp_instruction_type", util.primary_wire_type(cls, version))
return type_values
@@ -102,6 +106,8 @@
"of_hello_elem", "of_hello_elem_header"]
ofclasses = []
for cls in of_g.standard_class_order:
+ if type_maps.class_is_virtual(cls):
+ continue
if version not in of_g.unified[cls] or cls in blacklist:
continue
unified_class = util.lookup_unified_class(cls, version)
@@ -111,6 +117,10 @@
pyname = cls[10:]
elif utils.class_is_oxm(cls):
pyname = cls[7:]
+ elif utils.class_is_meter_band(cls):
+ pyname = cls[14:]
+ elif utils.class_is_instruction(cls):
+ pyname = cls[15:]
else:
pyname = cls[3:]
@@ -170,6 +180,8 @@
ofclasses = [x for x in build_ofclasses(version)
if not utils.class_is_message(x.name)
and not utils.class_is_action(x.name)
+ and not utils.class_is_instruction(x.name)
+ and not utils.class_is_meter_band(x.name)
and not utils.class_is_oxm(x.name)
and not utils.class_is_list(x.name)]
util.render_template(out, 'common.py', ofclasses=ofclasses, version=version)
@@ -186,13 +198,23 @@
groups[group] = items
util.render_template(out, 'const.py', version=version, groups=groups)
+def generate_instruction(out, name, version):
+ ofclasses = [x for x in build_ofclasses(version)
+ if utils.class_is_instruction(x.name)]
+ util.render_template(out, 'instruction.py', ofclasses=ofclasses, version=version)
+
def generate_message(out, name, version):
ofclasses = [x for x in build_ofclasses(version)
if utils.class_is_message(x.name)]
util.render_template(out, 'message.py', ofclasses=ofclasses, version=version)
+def generate_meter_band(out, name, version):
+ ofclasses = [x for x in build_ofclasses(version)
+ if utils.class_is_meter_band(x.name)]
+ util.render_template(out, 'meter_band.py', ofclasses=ofclasses, version=version)
+
def generate_pp(out, name, version):
util.render_template(out, 'pp.py')
def generate_util(out, name, version):
- util.render_template(out, 'util.py')
+ util.render_template(out, 'util.py', version=version)
diff --git a/py_gen/oftype.py b/py_gen/oftype.py
index a43a1bb..3f37f57 100644
--- a/py_gen/oftype.py
+++ b/py_gen/oftype.py
@@ -27,6 +27,7 @@
import of_g
import loxi_utils.loxi_utils as utils
+import loxi_front_end.type_maps
import unittest
class OFType(object):
@@ -54,7 +55,15 @@
elif self.base == 'of_ipv6_t':
v = repr('\x00' * 16)
elif self.base == 'of_wc_bmap_t':
- v = 'const.OFPFW_ALL'
+ if self.version in [1,2]:
+ v = 'const.OFPFW_ALL'
+ else:
+ v = 0
+ elif self.base == "of_match_bmap_t":
+ if self.version in [1,2]:
+ v = 'const.OFPFW_ALL'
+ else:
+ v = 0
elif self.base in ['of_octets_t', 'of_port_name_t', 'of_table_name_t',
'of_desc_str_t', 'of_serial_num_t']:
v = '""'
@@ -62,6 +71,8 @@
v = 'common.match()'
elif self.base == 'of_port_desc_t':
v = 'common.port_desc()'
+ elif self.base == 'of_meter_features_t':
+ v = 'common.meter_features()'
else:
v = "None"
@@ -84,7 +95,7 @@
return 'struct.pack("!6B", *%s)' % expr_expr
elif self.base == 'of_ipv6_t':
return 'struct.pack("!16s", %s)' % expr_expr
- elif self.base in ['of_match_t', 'of_port_desc_t']:
+ elif self.base in ['of_match_t', 'of_port_desc_t', 'of_meter_features_t']:
return '%s.pack()' % expr_expr
elif self.base == 'of_port_name_t':
return self._gen_string_pack_expr(16, expr_expr)
@@ -127,15 +138,30 @@
elif self.base == 'of_list_oxm_t':
# HACK need the match_v3 length field
return 'oxm.unpack_list(%s.slice(_length-4))' % (reader_expr)
+ elif self.base == 'of_list_bucket_t':
+ return 'common.unpack_list_bucket(%s)' % (reader_expr)
+ elif self.base == 'of_list_group_desc_stats_entry_t':
+ return 'common.unpack_list_group_desc_stats_entry(%s)' % (reader_expr)
+ elif self.base == 'of_list_group_stats_entry_t':
+ return 'common.unpack_list_group_stats_entry(%s)' % (reader_expr)
+ elif self.base == 'of_list_meter_band_t':
+ return 'meter_band.unpack_list(%s)' % (reader_expr)
+ elif self.base == 'of_list_meter_stats_t':
+ return 'common.unpack_list_meter_stats(%s)' % (reader_expr)
elif self.base == 'of_port_name_t':
return self._gen_string_unpack_expr(reader_expr, 16)
elif self.base == 'of_table_name_t' or self.base == 'of_serial_num_t':
return self._gen_string_unpack_expr(reader_expr, 32)
elif self.base == 'of_desc_str_t':
return self._gen_string_unpack_expr(reader_expr, 256)
+ elif self.base == 'of_meter_features_t':
+ return 'common.meter_features.unpack(%s)' % (reader_expr)
+ elif self.base == 'of_list_instruction_t':
+ return 'instruction.unpack_list(%s)' % (reader_expr)
elif utils.class_is_list(self.base):
element_cls = utils.list_to_entry_type(self.base)[:-2]
- if ((element_cls, self.version) in of_g.is_fixed_length):
+ if ((element_cls, self.version) in of_g.is_fixed_length) \
+ and not element_cls in loxi_front_end.type_maps.inheritance_map:
klass_name = self.base[8:-2]
element_size, = of_g.base_length[(element_cls, self.version)],
return 'loxi.generic_util.unpack_list(%s, common.%s.unpack)' % (reader_expr, klass_name)
diff --git a/py_gen/templates/_pretty_print.py b/py_gen/templates/_pretty_print.py
index 5709227..86cb237 100644
--- a/py_gen/templates/_pretty_print.py
+++ b/py_gen/templates/_pretty_print.py
@@ -48,7 +48,7 @@
q.text(util.pretty_mac(self.${m.name}))
:: elif m.oftype.base == 'uint32_t' and m.name.startswith("ipv4"):
q.text(util.pretty_ipv4(self.${m.name}))
-:: elif m.oftype.base == 'of_wc_bmap_t':
+:: elif m.oftype.base == 'of_wc_bmap_t' and version in [1,2]:
q.text(util.pretty_wildcards(self.${m.name}))
:: elif m.oftype.base == 'of_port_no_t':
q.text(util.pretty_port(self.${m.name}))
diff --git a/py_gen/templates/common.py b/py_gen/templates/common.py
index 19a0d9b..1ab2f68 100644
--- a/py_gen/templates/common.py
+++ b/py_gen/templates/common.py
@@ -32,6 +32,12 @@
import sys
import struct
import action
+:: if version >= 2:
+import instruction # for unpack_list
+:: #endif
+:: if version >= 4:
+import meter_band # for unpack_list
+:: #endif
import const
import util
import loxi.generic_util
@@ -68,6 +74,21 @@
return None
return [x for x in loxi.generic_util.unpack_list_tlv16(reader, deserializer) if x != None]
+def unpack_list_bucket(reader):
+ return loxi.generic_util.unpack_list_lv16(reader, bucket.unpack)
+
+def unpack_list_group_desc_stats_entry(reader):
+ return loxi.generic_util.unpack_list_lv16(reader, group_desc_stats_entry.unpack)
+
+def unpack_list_group_stats_entry(reader):
+ return loxi.generic_util.unpack_list_lv16(reader, group_stats_entry.unpack)
+
+def unpack_list_meter_stats(reader):
+ def wrapper(reader):
+ length, = reader.peek('!4xH')
+ return meter_stats.unpack(reader.slice(length))
+ return loxi.generic_util.unpack_list(reader, wrapper)
+
:: for ofclass in ofclasses:
:: include('_ofclass.py', ofclass=ofclass, superclass="object")
diff --git a/py_gen/templates/init.py b/py_gen/templates/init.py
index 75d52be..f66e62a 100644
--- a/py_gen/templates/init.py
+++ b/py_gen/templates/init.py
@@ -30,9 +30,15 @@
:: include('_autogen.py')
import action, common, const, message
+:: if version >= 2:
+import instruction
+:: #endif
:: if version >= 3:
import oxm
:: #endif
+:: if version >= 4:
+import meter_band
+:: #endif
from const import *
from common import *
from loxi import ProtocolError
diff --git a/py_gen/templates/instruction.py b/py_gen/templates/instruction.py
new file mode 100644
index 0000000..bfa0628
--- /dev/null
+++ b/py_gen/templates/instruction.py
@@ -0,0 +1,68 @@
+:: # Copyright 2013, Big Switch Networks, Inc.
+:: #
+:: # LoxiGen is licensed under the Eclipse Public License, version 1.0 (EPL), with
+:: # the following special exception:
+:: #
+:: # LOXI Exception
+:: #
+:: # As a special exception to the terms of the EPL, you may distribute libraries
+:: # generated by LoxiGen (LoxiGen Libraries) under the terms of your choice, provided
+:: # that copyright and licensing notices generated by LoxiGen are not altered or removed
+:: # from the LoxiGen Libraries and the notice provided below is (i) included in
+:: # the LoxiGen Libraries, if distributed in source code form and (ii) included in any
+:: # documentation for the LoxiGen Libraries, if distributed in binary form.
+:: #
+:: # Notice: "Copyright 2013, Big Switch Networks, Inc. This library was generated by the LoxiGen Compiler."
+:: #
+:: # You may not use this file except in compliance with the EPL or LOXI Exception. You may obtain
+:: # a copy of the EPL at:
+:: #
+:: # http://www.eclipse.org/legal/epl-v10.html
+:: #
+:: # 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
+:: # EPL for the specific language governing permissions and limitations
+:: # under the EPL.
+::
+:: import itertools
+:: import of_g
+:: include('_copyright.py')
+
+:: include('_autogen.py')
+
+import struct
+import action
+import const
+import util
+import loxi.generic_util
+import loxi
+
+def unpack_list(reader):
+ def deserializer(reader, typ):
+ parser = parsers.get(typ)
+ if not parser: raise loxi.ProtocolError("unknown instruction type %d" % typ)
+ return parser(reader)
+ return loxi.generic_util.unpack_list_tlv16(reader, deserializer)
+
+class Instruction(object):
+ type = None # override in subclass
+ pass
+
+:: for ofclass in ofclasses:
+:: include('_ofclass.py', ofclass=ofclass, superclass="Instruction")
+
+:: #endfor
+
+parsers = {
+:: sort_key = lambda x: x.type_members[0].value
+:: msgtype_groups = itertools.groupby(sorted(ofclasses, key=sort_key), sort_key)
+:: for (k, v) in msgtype_groups:
+:: v = list(v)
+:: if len(v) == 1:
+ ${k} : ${v[0].pyname}.unpack,
+:: else:
+ ${k} : parse_${k[12:].lower()},
+:: #endif
+:: #endfor
+}
diff --git a/py_gen/templates/message.py b/py_gen/templates/message.py
index d81d5b7..196cd6c 100644
--- a/py_gen/templates/message.py
+++ b/py_gen/templates/message.py
@@ -36,6 +36,12 @@
import const
import common
import action # for unpack_list
+:: if version >= 2:
+import instruction # for unpack_list
+:: #endif
+:: if version >= 4:
+import meter_band # for unpack_list
+:: #endif
import util
import loxi.generic_util
diff --git a/py_gen/templates/meter_band.py b/py_gen/templates/meter_band.py
new file mode 100644
index 0000000..ca111d5
--- /dev/null
+++ b/py_gen/templates/meter_band.py
@@ -0,0 +1,67 @@
+:: # Copyright 2013, Big Switch Networks, Inc.
+:: #
+:: # LoxiGen is licensed under the Eclipse Public License, version 1.0 (EPL), with
+:: # the following special exception:
+:: #
+:: # LOXI Exception
+:: #
+:: # As a special exception to the terms of the EPL, you may distribute libraries
+:: # generated by LoxiGen (LoxiGen Libraries) under the terms of your choice, provided
+:: # that copyright and licensing notices generated by LoxiGen are not altered or removed
+:: # from the LoxiGen Libraries and the notice provided below is (i) included in
+:: # the LoxiGen Libraries, if distributed in source code form and (ii) included in any
+:: # documentation for the LoxiGen Libraries, if distributed in binary form.
+:: #
+:: # Notice: "Copyright 2013, Big Switch Networks, Inc. This library was generated by the LoxiGen Compiler."
+:: #
+:: # You may not use this file except in compliance with the EPL or LOXI Exception. You may obtain
+:: # a copy of the EPL at:
+:: #
+:: # http://www.eclipse.org/legal/epl-v10.html
+:: #
+:: # 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
+:: # EPL for the specific language governing permissions and limitations
+:: # under the EPL.
+::
+:: import itertools
+:: import of_g
+:: include('_copyright.py')
+
+:: include('_autogen.py')
+
+import struct
+import const
+import util
+import loxi.generic_util
+import loxi
+
+def unpack_list(reader):
+ def deserializer(reader, typ):
+ parser = parsers.get(typ)
+ if not parser: raise loxi.ProtocolError("unknown meter band type %d" % typ)
+ return parser(reader)
+ return loxi.generic_util.unpack_list_tlv16(reader, deserializer)
+
+class MeterBand(object):
+ type = None # override in subclass
+ pass
+
+:: for ofclass in ofclasses:
+:: include('_ofclass.py', ofclass=ofclass, superclass="MeterBand")
+
+:: #endfor
+
+parsers = {
+:: sort_key = lambda x: x.type_members[0].value
+:: msgtype_groups = itertools.groupby(sorted(ofclasses, key=sort_key), sort_key)
+:: for (k, v) in msgtype_groups:
+:: v = list(v)
+:: if len(v) == 1:
+ ${k} : ${v[0].pyname}.unpack,
+:: else:
+ ${k} : parse_${k[12:].lower()},
+:: #endif
+:: #endfor
+}
diff --git a/py_gen/templates/util.py b/py_gen/templates/util.py
index f2f7a96..397c184 100644
--- a/py_gen/templates/util.py
+++ b/py_gen/templates/util.py
@@ -52,6 +52,7 @@
set_flags.append("%#x" % v)
return '|'.join(set_flags) or '0'
+:: if version in [1,2]:
def pretty_wildcards(v):
if v == const.OFPFW_ALL:
return 'OFPFW_ALL'
@@ -60,6 +61,7 @@
'OFPFW_NW_SRC_MASK', 'OFPFW_NW_DST_MASK', 'OFPFW_DL_VLAN_PCP',
'OFPFW_NW_TOS']
return pretty_flags(v, flag_names)
+:: #endif
def pretty_port(v):
named_ports = [(k,v2) for (k,v2) in const.__dict__.iteritems() if k.startswith('OFPP_')]
diff --git a/py_gen/tests/of11.py b/py_gen/tests/of11.py
index 8099586..dd76b0d 100644
--- a/py_gen/tests/of11.py
+++ b/py_gen/tests/of11.py
@@ -69,13 +69,7 @@
self.klasses.sort(key=lambda x: str(x))
def test_serialization(self):
- expected_failures = [
- ofp.common.group_desc_stats_entry,
- ofp.common.table_stats_entry,
- ofp.message.group_desc_stats_reply,
- ofp.message.group_mod,
- ofp.message.group_stats_reply,
- ]
+ expected_failures = []
for klass in self.klasses:
def fn():
obj = klass()
@@ -89,8 +83,7 @@
fn()
def test_show(self):
- expected_failures = [
- ]
+ expected_failures = []
for klass in self.klasses:
def fn():
obj = klass()
diff --git a/py_gen/tests/of12.py b/py_gen/tests/of12.py
index 4a6c7c6..b557730 100644
--- a/py_gen/tests/of12.py
+++ b/py_gen/tests/of12.py
@@ -157,13 +157,7 @@
self.klasses.sort(key=lambda x: str(x))
def test_serialization(self):
- expected_failures = [
- ofp.common.group_desc_stats_entry,
- ofp.common.table_stats_entry,
- ofp.message.group_desc_stats_reply,
- ofp.message.group_mod,
- ofp.message.group_stats_reply,
- ]
+ expected_failures = []
for klass in self.klasses:
def fn():
obj = klass()
@@ -177,9 +171,7 @@
fn()
def test_show(self):
- expected_failures = [
- ofp.common.table_stats_entry,
- ]
+ expected_failures = []
for klass in self.klasses:
def fn():
obj = klass()
diff --git a/py_gen/tests/of13.py b/py_gen/tests/of13.py
index 3d921d2..3c9772f 100644
--- a/py_gen/tests/of13.py
+++ b/py_gen/tests/of13.py
@@ -395,8 +395,59 @@
## Flow-mods
def test_flow_add(self):
- # TODO
- pass
+ obj = ofp.message.flow_add(
+ xid=0x12345678,
+ cookie=0xFEDCBA9876543210,
+ cookie_mask=0xFF00FF00FF00FF00,
+ table_id=3,
+ idle_timeout=5,
+ hard_timeout=10,
+ priority=6000,
+ buffer_id=50,
+ out_port=6,
+ out_group=8,
+ flags=0,
+ match=ofp.match(oxm_list=[]),
+ instructions=[
+ ofp.instruction.goto_table(table_id=4),
+ ofp.instruction.goto_table(table_id=7)])
+ buf = ''.join([
+ '\x04', '\x0e', # version, type
+ '\x00\x48', # length
+ '\x12\x34\x56\x78', # xid
+
+ '\xfe\xdc\xba\x98\x76\x54\x32\x10', # cookie
+
+ '\xff\x00\xff\x00\xff\x00\xff\x00', # cookie_mask
+
+ '\x03', # table_id
+ '\x00', # _command
+ '\x00\x05', # idle_timeout
+ '\x00\x0a', # hard_timeout
+ '\x17\x70', # priority
+
+ '\x00\x00\x00\x32', # buffer_id
+ '\x00\x00\x00\x06', # out_port
+
+ '\x00\x00\x00\x08', # out_group
+ '\x00\x00', # flags
+ '\x00' * 2, # pad
+
+ '\x00\x01', # match.type
+ '\x00\x04', # match.length
+ '\x00' * 4, # pad
+
+ '\x00\x01', # instructions[0].type
+ '\x00\x08', # instructions[0].length
+ '\x04', # instructions[0].table_id
+ '\x00' * 3, # pad
+
+ '\x00\x01', # instructions[1].type
+ '\x00\x08', # instructions[1].length
+ '\x07', # instructions[1].table_id
+ '\x00' * 3, # pad
+ ])
+ test_serialization(obj, buf)
def test_flow_modify(self):
# TODO
@@ -416,8 +467,66 @@
def test_group_mod(self):
- # TODO
- pass
+ obj = ofp.message.group_mod(
+ xid=0x12345678,
+ command=ofp.OFPGC_MODIFY,
+ group_type=ofp.OFPGT_FF,
+ group_id=5,
+ buckets=[
+ ofp.bucket(
+ weight=1,
+ watch_port=5,
+ watch_group=0xffffffff,
+ actions=[
+ ofp.action.output(port=5, max_len=0),
+ ofp.action.output(port=6, max_len=0)]),
+ ofp.bucket(
+ weight=1,
+ watch_port=6,
+ watch_group=0xffffffff,
+ actions=[
+ ofp.action.output(port=5, max_len=0),
+ ofp.action.output(port=6, max_len=0)])])
+ buf = ''.join([
+ '\x04', '\x0f', # version, type
+ '\x00\x70', # length
+ '\x12\x34\x56\x78', # xid
+ '\x00\x01', # command
+ '\x03', # group_type
+ '\x00', # pad
+ '\x00\x00\x00\x05', # group_id
+ '\x00\x30', # buckets[0].len
+ '\x00\x01', # buckets[0].weight
+ '\x00\x00\x00\x05', # buckets[0].watch_port
+ '\xff\xff\xff\xff', # buckets[0].watch_group
+ '\x00' * 4, # pad
+ '\x00\x00', # buckets[0].actions[0].type
+ '\x00\x10', # buckets[0].actions[0].len
+ '\x00\x00\x00\x05', # buckets[0].actions[0].port
+ '\x00\x00', # buckets[0].actions[0].max_len
+ '\x00' * 6, # pad
+ '\x00\x00', # buckets[0].actions[1].type
+ '\x00\x10', # buckets[0].actions[1].len
+ '\x00\x00\x00\x06', # buckets[0].actions[1].port
+ '\x00\x00', # buckets[0].actions[1].max_len
+ '\x00' * 6, # pad
+ '\x00\x30', # buckets[1].len
+ '\x00\x01', # buckets[1].weight
+ '\x00\x00\x00\x06', # buckets[1].watch_port
+ '\xff\xff\xff\xff', # buckets[1].watch_group
+ '\x00' * 4, # pad
+ '\x00\x00', # buckets[1].actions[0].type
+ '\x00\x10', # buckets[1].actions[0].len
+ '\x00\x00\x00\x05', # buckets[1].actions[0].port
+ '\x00\x00', # buckets[1].actions[0].max_len
+ '\x00' * 6, # pad
+ '\x00\x00', # buckets[1].actions[1].type
+ '\x00\x10', # buckets[1].actions[1].len
+ '\x00\x00\x00\x06', # buckets[1].actions[1].port
+ '\x00\x00', # buckets[1].actions[1].max_len
+ '\x00' * 6, # pad
+ ])
+ test_serialization(obj, buf)
def test_port_mod(self):
# TODO
@@ -475,16 +584,135 @@
pass
def test_group_stats_reply(self):
- # TODO
- pass
+ obj = ofp.message.group_stats_reply(
+ xid=0x12345678,
+ flags=0,
+ entries=[
+ ofp.group_stats_entry(
+ group_id=1,
+ ref_count=8,
+ packet_count=16,
+ byte_count=32,
+ duration_sec=20,
+ duration_nsec=100,
+ bucket_stats=[
+ ofp.bucket_counter(packet_count=1, byte_count=2),
+ ofp.bucket_counter(packet_count=3, byte_count=4)]),
+ ofp.group_stats_entry(
+ group_id=1,
+ ref_count=8,
+ packet_count=16,
+ byte_count=32,
+ duration_sec=20,
+ duration_nsec=100,
+ bucket_stats=[])])
+ buf = ''.join([
+ '\x04', '\x13', # version, type
+ '\x00\x80', # length
+ '\x12\x34\x56\x78', # xid
+ '\x00\x06', # stats_type
+ '\x00\x00', # flags
+ '\x00' * 4, # pad
+ '\x00\x48', # entries[0].length
+ '\x00' * 2, # pad
+ '\x00\x00\x00\x01', # entries[0].group_id
+ '\x00\x00\x00\x08', # entries[0].ref_count
+ '\x00' * 4, # pad
+ '\x00\x00\x00\x00\x00\x00\x00\x10', # entries[0].packet_count
+ '\x00\x00\x00\x00\x00\x00\x00\x20', # entries[0].byte_count
+ '\x00\x00\x00\x14', # entries[0].duration_sec
+ '\x00\x00\x00\x64', # entries[0].duration_nsec
+ '\x00\x00\x00\x00\x00\x00\x00\x01', # entries[0].bucket_stats[0].packet_count
+ '\x00\x00\x00\x00\x00\x00\x00\x02', # entries[0].bucket_stats[0].byte_count
+ '\x00\x00\x00\x00\x00\x00\x00\x03', # entries[0].bucket_stats[1].packet_count
+ '\x00\x00\x00\x00\x00\x00\x00\x04', # entries[0].bucket_stats[1].byte_count
+ '\x00\x28', # entries[0].length
+ '\x00' * 2, # pad
+ '\x00\x00\x00\x01', # entries[0].group_id
+ '\x00\x00\x00\x08', # entries[0].ref_count
+ '\x00' * 4, # pad
+ '\x00\x00\x00\x00\x00\x00\x00\x10', # entries[0].packet_count
+ '\x00\x00\x00\x00\x00\x00\x00\x20', # entries[0].byte_count
+ '\x00\x00\x00\x14', # entries[0].duration_sec
+ '\x00\x00\x00\x64', # entries[0].duration_nsec
+ ])
+ test_serialization(obj, buf)
def test_group_desc_stats_request(self):
# TODO
pass
def test_group_desc_stats_reply(self):
- # TODO
- pass
+ obj = ofp.message.group_desc_stats_reply(
+ xid=0x12345678,
+ flags=0,
+ entries=[
+ ofp.group_desc_stats_entry(
+ type=ofp.OFPGT_FF,
+ group_id=1,
+ buckets=[
+ ofp.bucket(
+ weight=1,
+ watch_port=5,
+ watch_group=0xffffffff,
+ actions=[
+ ofp.action.output(port=5, max_len=0),
+ ofp.action.output(port=6, max_len=0)]),
+ ofp.bucket(
+ weight=1,
+ watch_port=6,
+ watch_group=0xffffffff,
+ actions=[
+ ofp.action.output(port=5, max_len=0),
+ ofp.action.output(port=6, max_len=0)])]),
+ ofp.group_desc_stats_entry(type=ofp.OFPGT_FF, group_id=2, buckets=[])])
+ buf = ''.join([
+ '\x04', '\x13', # version, type
+ '\x00\x80', # length
+ '\x12\x34\x56\x78', # xid
+ '\x00\x07', # stats_type
+ '\x00\x00', # flags
+ '\x00' * 4, # pad
+ '\x00\x68', # entries[0].length
+ '\x03', # entries[0].group_type
+ '\x00', # entries[0].pad
+ '\x00\x00\x00\x01', # entries[0].group_id
+ '\x00\x30', # entries[0].buckets[0].len
+ '\x00\x01', # entries[0].buckets[0].weight
+ '\x00\x00\x00\x05', # entries[0].buckets[0].watch_port
+ '\xff\xff\xff\xff', # entries[0].buckets[0].watch_group
+ '\x00' * 4, # entries[0].pad
+ '\x00\x00', # entries[0].buckets[0].actions[0].type
+ '\x00\x10', # entries[0].buckets[0].actions[0].len
+ '\x00\x00\x00\x05', # entries[0].buckets[0].actions[0].port
+ '\x00\x00', # entries[0].buckets[0].actions[0].max_len
+ '\x00' * 6, # entries[0].pad
+ '\x00\x00', # entries[0].buckets[0].actions[1].type
+ '\x00\x10', # entries[0].buckets[0].actions[1].len
+ '\x00\x00\x00\x06', # entries[0].buckets[0].actions[1].port
+ '\x00\x00', # entries[0].buckets[0].actions[1].max_len
+ '\x00' * 6, # entries[0].pad
+ '\x00\x30', # entries[0].buckets[1].len
+ '\x00\x01', # entries[0].buckets[1].weight
+ '\x00\x00\x00\x06', # entries[0].buckets[1].watch_port
+ '\xff\xff\xff\xff', # entries[0].buckets[1].watch_group
+ '\x00' * 4, # entries[0].pad
+ '\x00\x00', # entries[0].buckets[1].actions[0].type
+ '\x00\x10', # entries[0].buckets[1].actions[0].len
+ '\x00\x00\x00\x05', # entries[0].buckets[1].actions[0].port
+ '\x00\x00', # entries[0].buckets[1].actions[0].max_len
+ '\x00' * 6, # entries[0].pad
+ '\x00\x00', # entries[0].buckets[1].actions[1].type
+ '\x00\x10', # entries[0].buckets[1].actions[1].len
+ '\x00\x00\x00\x06', # entries[0].buckets[1].actions[1].port
+ '\x00\x00', # entries[0].buckets[1].actions[1].max_len
+ '\x00' * 6, # entries[0].pad
+ '\x00\x08', # entries[1].length
+ '\x03', # entries[1].group_type
+ '\x00', # entries[1].pad
+ '\x00\x00\x00\x02', # entries[1].group_id
+ ])
+ test_serialization(obj, buf)
def test_group_features_stats_request(self):
# TODO
@@ -499,24 +727,119 @@
pass
def test_meter_stats_reply(self):
- # TODO
- pass
+ obj = ofp.message.meter_stats_reply(
+ xid=0x12345678,
+ flags=0,
+ entries=[
+ ofp.meter_stats(
+ meter_id=1,
+ flow_count=8,
+ packet_in_count=16,
+ byte_in_count=32,
+ duration_sec=20,
+ duration_nsec=100,
+ band_stats=[
+ ofp.meter_band_stats(packet_band_count=1, byte_band_count=2),
+ ofp.meter_band_stats(packet_band_count=3, byte_band_count=4)]),
+ ofp.meter_stats(
+ meter_id=2,
+ flow_count=8,
+ packet_in_count=16,
+ byte_in_count=32,
+ duration_sec=20,
+ duration_nsec=100,
+ band_stats=[])])
+ buf = ''.join([
+ '\x04', '\x13', # version, type
+ '\x00\x80', # length
+ '\x12\x34\x56\x78', # xid
+ '\x00\x09', # stats_type
+ '\x00\x00', # flags
+ '\x00' * 4, # pad
+ '\x00\x00\x00\x01', # entries[0].meter_id
+ '\x00\x48', # entries[0].len
+ '\x00' * 6, # pad
+ '\x00\x00\x00\x08', # entries[0].flow_count
+ '\x00\x00\x00\x00\x00\x00\x00\x10', # entries[0].packet_in_count
+ '\x00\x00\x00\x00\x00\x00\x00\x20', # entries[0].byte_in_count
+ '\x00\x00\x00\x14', # entries[0].duration_sec
+ '\x00\x00\x00\x64', # entries[0].duration_nsec
+ '\x00\x00\x00\x00\x00\x00\x00\x01', # entries[0].band_stats[0].packet_band_count
+ '\x00\x00\x00\x00\x00\x00\x00\x02', # entries[0].band_stats[0].byte_band_count
+ '\x00\x00\x00\x00\x00\x00\x00\x03', # entries[0].band_stats[1].packet_band_count
+ '\x00\x00\x00\x00\x00\x00\x00\x04', # entries[0].band_stats[1].byte_band_count
+ '\x00\x00\x00\x02', # entries[1].meter_id
+ '\x00\x28', # entries[1].len
+ '\x00' * 6, # pad
+ '\x00\x00\x00\x08', # entries[1].flow_count
+ '\x00\x00\x00\x00\x00\x00\x00\x10', # entries[1].packet_in_count
+ '\x00\x00\x00\x00\x00\x00\x00\x20', # entries[1].byte_in_count
+ '\x00\x00\x00\x14', # entries[1].duration_sec
+ '\x00\x00\x00\x64', # entries[1].duration_nsec
+ ])
+ test_serialization(obj, buf)
def test_meter_config_stats_request(self):
# TODO
pass
def test_meter_config_stats_reply(self):
- # TODO
- pass
+ obj = ofp.message.meter_config_stats_reply(
+ xid=0x12345678,
+ flags=0,
+ entries=[
+ ofp.meter_band.drop(rate=1, burst_size=2),
+ ofp.meter_band.dscp_remark(rate=3, burst_size=4, prec_level=5)])
+ buf = ''.join([
+ '\x04', '\x13', # version, type
+ '\x00\x30', # length
+ '\x12\x34\x56\x78', # xid
+ '\x00\x0a', # stats_type
+ '\x00\x00', # flags
+ '\x00' * 4, # pad
+ '\x00\x01', # entries[0].type
+ '\x00\x10', # entries[0].length
+ '\x00\x00\x00\x01', # entries[0].rate
+ '\x00\x00\x00\x02', # entries[0].burst_size
+ '\x00' * 4, # pad
+ '\x00\x02', # entries[1].type
+ '\x00\x10', # entries[1].length
+ '\x00\x00\x00\x03', # entries[1].rate
+ '\x00\x00\x00\x04', # entries[1].burst_size
+ '\x05', # entries[1].prec_level
+ '\x00' * 3, # pad
+ ])
+ test_serialization(obj, buf)
def test_meter_features_stats_request(self):
# TODO
pass
def test_meter_features_stats_reply(self):
- # TODO
- pass
+ obj = ofp.message.meter_features_stats_reply(
+ xid=0x12345678,
+ flags=0,
+ features=ofp.meter_features(
+ max_meter=5,
+ band_types=ofp.OFPMBT_DROP|ofp.OFPMBT_DSCP_REMARK,
+ capabilities=ofp.OFPMF_KBPS|ofp.OFPMF_STATS,
+ max_bands=10,
+ max_color=7))
+ buf = ''.join([
+ '\x04', '\x13', # version, type
+ '\x00\x20', # length
+ '\x12\x34\x56\x78', # xid
+ '\x00\x0b', # stats_type
+ '\x00\x00', # flags
+ '\x00' * 4, # pad
+ '\x00\x00\x00\x05', # max_meter
+ '\x00\x00\x00\x03', # band_types
+ '\x00\x00\x00\x09', # capabilities
+ '\x0a', # max_bands
+ '\x07', # max_color
+ '\x00' * 2, # pad
+ ])
+ test_serialization(obj, buf)
def test_table_features_stats_request(self):
# TODO
@@ -613,6 +936,39 @@
])
self.assertEquals(expected, obj.pack())
+class TestInstructions(unittest.TestCase):
+ def test_goto_table(self):
+ obj = ofp.instruction.goto_table(table_id=5)
+ buf = ''.join([
+ '\x00\x01', # type
+ '\x00\x08', # length
+ '\x05', # table_id
+ '\x00' * 3, # pad
+ ])
+ test_serialization(obj, buf)
+
+ def test_write_metadata(self):
+ # TODO
+ pass
+
+ def test_write_actions(self):
+ # TODO
+ pass
+
+ def test_apply_actions(self):
+ # TODO
+ pass
+
+ def test_clear_actions(self):
+ # TODO
+ pass
+
+ def test_meter(self):
+ # TODO
+ pass
+
+ # TODO test experimenter instructions
+
class TestAllOF13(unittest.TestCase):
"""
Round-trips every class through serialization/deserialization.
@@ -629,12 +985,11 @@
def test_serialization(self):
expected_failures = [
- ofp.common.group_desc_stats_entry,
- ofp.message.group_desc_stats_reply,
- ofp.message.group_mod,
- ofp.message.group_stats_reply,
- ofp.message.meter_stats_reply,
- ofp.message.meter_features_stats_reply,
+ ofp.common.table_feature_prop_apply_actions,
+ ofp.common.table_feature_prop_apply_actions_miss,
+ ofp.common.table_feature_prop_write_actions,
+ ofp.common.table_feature_prop_write_actions_miss,
+ ofp.common.table_features,
ofp.message.table_features_stats_reply,
ofp.message.table_features_stats_request,
]