diff --git a/Makefile b/Makefile
index 02e144d..1016c2d 100644
--- a/Makefile
+++ b/Makefile
@@ -31,8 +31,6 @@
 DOCKER_TAG                 ?= ${VERSION}$(shell [[ ${DOCKER_LABEL_VCS_DIRTY} == "true" ]] && echo "-dirty" || true)
 RWCORE_IMAGENAME           := ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}voltha-rw-core
 ROCORE_IMAGENAME           := ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}voltha-ro-core
-OFAGENT_IMAGENAME          := ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}voltha-ofagent
-CLI_IMAGENAME              := ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}voltha-cli
 
 ## Docker labels. Only set ref and commit date if committed
 DOCKER_LABEL_VCS_URL       ?= $(shell git remote get-url $(shell git remote))
@@ -57,10 +55,9 @@
 	--build-arg org_opencord_vcs_dirty="${DOCKER_LABEL_VCS_DIRTY}"
 
 DOCKER_BUILD_ARGS_LOCAL ?= ${DOCKER_BUILD_ARGS} \
-	--build-arg LOCAL_PYVOLTHA=${LOCAL_PYVOLTHA} \
 	--build-arg LOCAL_PROTOS=${LOCAL_PROTOS}
 
-.PHONY: rw_core ro_core local-protos local-pyvoltha
+.PHONY: rw_core ro_core local-protos
 
 # This should to be the first and default target in this Makefile
 help:
@@ -71,11 +68,8 @@
 	@echo "                         - If this is the first time you are building, choose 'make build' option."
 	@echo "rw_core              : Build the rw_core docker image"
 	@echo "ro_core              : Build the ro_core docker image"
-	@echo "ofagent              : Build the openflow agent docker image"
-	@echo "cli                  : Build the voltha CLI docker image"
-	@echo "venv                 : Build local Python virtualenv"
 	@echo "clean                : Remove files created by the build and tests"
-	@echo "distclean            : Remove venv directory"
+	@echo "distclean            : Remove sca directory and clean"
 	@echo "docker-push          : Push the docker images to an external repository"
 	@echo "lint-dockerfile      : Perform static analysis on Dockerfiles"
 	@echo "lint-style           : Verify code is properly gofmt-ed"
@@ -88,13 +82,9 @@
 
 ## Local Development Helpers
 local-protos:
-	@mkdir -p python/local_imports
 ifdef LOCAL_PROTOS
 	mkdir -p vendor/github.com/opencord/voltha-protos/v2/go
 	cp -r ${LOCAL_PROTOS}/go/* vendor/github.com/opencord/voltha-protos/v2/go
-	rm -rf python/local_imports/voltha-protos
-	mkdir -p python/local_imports/voltha-protos/dist
-	cp ${LOCAL_PROTOS}/dist/*.tar.gz python/local_imports/voltha-protos/dist/
 endif
 
 ## Local Development Helpers
@@ -104,37 +94,11 @@
 	cp -r ${LOCAL_LIB_GO}/pkg/* vendor/github.com/opencord/voltha-lib-go/v2/pkg/
 endif
 
-local-pyvoltha:
-	@mkdir -p python/local_imports
-ifdef LOCAL_PYVOLTHA
-	rm -rf python/local_imports/pyvoltha
-	mkdir -p python/local_imports/pyvoltha/dist
-	cp ${LOCAL_PYVOLTHA}/dist/*.tar.gz python/local_imports/pyvoltha/dist/
-endif
-
-## Python venv dev environment
-
-VENVDIR := python/venv-volthago
-
-venv: distclean local-protos local-pyvoltha
-	virtualenv ${VENVDIR};\
-	source ./${VENVDIR}/bin/activate ; set -u ;\
-	rm -f ${VENVDIR}/local/bin ${VENVDIR}/local/lib ${VENVDIR}/local/include ;\
-	pip install -r python/requirements.txt
-ifdef LOCAL_PYVOLTHA
-	source ./${VENVDIR}/bin/activate ; set -u ;\
-	pip install python/local_imports/pyvoltha/dist/*.tar.gz
-endif
-ifdef LOCAL_PROTOS
-	source ./${VENVDIR}/bin/activate ; set -u ;\
-	pip install python/local_imports/voltha-protos/dist/*.tar.gz
-endif
-
 ## Docker targets
 
 build: docker-build
 
-docker-build: rw_core ro_core ofagent cli
+docker-build: rw_core ro_core
 
 rw_core: local-protos local-lib-go
 	docker build $(DOCKER_BUILD_ARGS) -t ${RWCORE_IMAGENAME}:${DOCKER_TAG} -t ${RWCORE_IMAGENAME}:latest -f docker/Dockerfile.rw_core .
@@ -142,17 +106,9 @@
 ro_core: local-protos local-lib-go
 	docker build $(DOCKER_BUILD_ARGS) -t ${ROCORE_IMAGENAME}:${DOCKER_TAG} -t ${ROCORE_IMAGENAME}:latest -f docker/Dockerfile.ro_core .
 
-ofagent: local-protos local-pyvoltha
-	docker build $(DOCKER_BUILD_ARGS_LOCAL) -t ${OFAGENT_IMAGENAME}:${DOCKER_TAG} -t ${OFAGENT_IMAGENAME}:latest -f python/docker/Dockerfile.ofagent python
-
-cli: local-protos local-pyvoltha
-	docker build $(DOCKER_BUILD_ARGS_LOCAL) -t ${CLI_IMAGENAME}:${DOCKER_TAG} -t ${CLI_IMAGENAME}:latest -f python/docker/Dockerfile.cli python
-
 docker-push:
 	docker push ${RWCORE_IMAGENAME}:${DOCKER_TAG}
 	docker push ${ROCORE_IMAGENAME}:${DOCKER_TAG}
-	docker push ${OFAGENT_IMAGENAME}:${DOCKER_TAG}
-	docker push ${CLI_IMAGENAME}:${DOCKER_TAG}
 
 ## lint and unit tests
 
@@ -238,7 +194,7 @@
 sca: golangci_lint_tool_install
 	rm -rf ./sca-report
 	@mkdir -p ./sca-report
-	$(GOLANGCI_LINT_TOOL) run -E golint -D structcheck --out-format junit-xml ./cli/... ./rw_core/... ./ro_core/... ./tests/... ./common/... 2>&1 | tee ./sca-report/sca-report.xml
+	$(GOLANGCI_LINT_TOOL) run -E golint -D structcheck --out-format junit-xml ./rw_core/... ./ro_core/... ./tests/... ./common/... 2>&1 | tee ./sca-report/sca-report.xml
 
 test: go_junit_install gocover_cobertura_install local-lib-go
 	@mkdir -p ./tests/results
@@ -249,11 +205,9 @@
 	exit $$RETURN
 
 clean:
-	rm -rf python/local_imports
-	find python -name '*.pyc' | xargs rm -f
 
 distclean: clean
-	rm -rf ${VENVDIR} ./sca_report
+	rm -rf ./sca_report
 
 mod-update:
 	go mod tidy
diff --git a/python/__init__.py b/python/__init__.py
deleted file mode 100644
index cfcdc97..0000000
--- a/python/__init__.py
+++ /dev/null
@@ -1,15 +0,0 @@
-#
-# Copyright 2017 the original author or authors.
-#
-# 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.
-#
\ No newline at end of file
diff --git a/python/adapters/BUILD_ENV.md b/python/adapters/BUILD_ENV.md
deleted file mode 100644
index e445141..0000000
--- a/python/adapters/BUILD_ENV.md
+++ /dev/null
@@ -1,53 +0,0 @@
-
-Build Environment for Ubuntu
-============================
-
-1. The following commands were executed on a Ubuntu 16.04 (b4 bits) VM with following configuation (OpenStack Flavor: m1.medium):
-	- vCPUs - 2
-	- RAM - 4 GB
-	- HDD - 40 GB
-	- Network - Floating IP attached to Internal IP NIC. Internet access available
-
-
-2. login as root as docker command needs root access. When logged-in as root 'sudo' becomes optional in each command below
-
-git clone https://gerrit.opencord.org/voltha-go
-sudo apt-get install make
-sudo apt-get install python
-sudo apt-get install virtualenv
-sudo apt-get install gcc
-sudo apt-get install python-dev
-sudo apt-get install g++
-sudo apt-get install libpcap-dev
-sudo apt-get install apt-utils
-sudo apt-get install docker-compose
-
-
-3. Install docker CE for Ubuntu as mentioned in this link: https://docs.docker.com/install/linux/docker-ce/ubuntu/#set-up-the-repository. These are commands executed to install docker
-
-sudo apt-get update
-
-sudo apt-get install \
-    apt-transport-https \
-    ca-certificates \
-    curl \
-    software-properties-common
-
-curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
-
-sudo apt-key fingerprint 0EBFCD88
-
-sudo add-apt-repository \
-   "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
-   $(lsb_release -cs) \
-   stable"
-
-sudo apt-get update
-
-sudo apt-get install docker-ce
-
-
-4. Verify that Docker CE is installed correctly by running the hello-world image. The following command downloads a test image and runs it in a container. When the container runs, it prints an informational message and exits.
-
-sudo docker run hello-world
-
diff --git a/python/adapters/README.md b/python/adapters/README.md
deleted file mode 100644
index 49e4a7e..0000000
--- a/python/adapters/README.md
+++ /dev/null
@@ -1,116 +0,0 @@
-# How to Build and Run a Voltha Adapter
-
-The build and development environment of a Voltha Adapter is left to the developer's choice.  The 
-environment used below is the macOS. 
-
-# Create fresh build setup
-When creating a fresh build setup various packages, applications and libraries are required to Build successfully.
-Please refer BUILD_ENV.md for details to create fresh setup on your choice of OS.
-This file will increment as new setups are created on difference OSes.
-
-### Build
-
-To build the adapters (so far Ponsim OLT and Ponsim ONU adapters) and dependent containers follow 
-the commands below. The base directory is voltha-go. 
-
-```
-cd python
-source env.sh
-VOLTHA_BUILD=docker make build
-```
-
-The above build command generates a few docker images. An example is below:
-
-```
-$ docker images
-REPOSITORY                  TAG                                        IMAGE ID            CREATED             SIZE
-voltha-adapter-ponsim-onu   latest                                     3638b16b5262        36 seconds ago      774MB
-voltha-adapter-ponsim-olt   latest                                     9e98a3a8e1aa        58 seconds ago      775MB
-voltha-base                 latest                                     40ed93942a6a        23 minutes ago      771MB
-voltha-protos               latest                                     d458a391cc81        12 days ago         2.66MB
-voltha-protoc               latest                                     a67dda73f695        2 months ago        1.41GB
-```
-
-Now build the Voltha Core from the voltha-go directory
-```
-make rw_core
-```
-
-Now build the Voltha CLI image from the voltha-go/python directory (used below for provisioning)
-```
-make cli
-```
-
-This will create the following images:
-```
-REPOSITORY                   TAG                                        IMAGE ID            CREATED             SIZE
-voltha-rw-core               latest                                     eab4b288adea        47 seconds ago      36.8MB
-voltha-cli                   latest                                     a0a4b8f25373        About an hour ago   827MB
-```
-
-### Run the Adapters locally (development environment)
-
-We will use Ponsim as the example.  Ponsim has two containers, one being the Ponsim OLT Adapter and 
-the other one the Ponsim ONU Adapter. We will use the docker-compose command to run these containers locally 
-as it is straight forward.
-
-#### Setup
-Since an adapter communicates with the Voltha Core via the Kafka bus and uses the Etcd KV store then we 
-need to have these containers running as well.   There is no dependency in the order in which they need to 
-start as an adapter must be able to handle this scenario. 
- 
-First run the dependent containers from the voltha-go directory. In the commands below, replace the IP 
-with the IP of the host.
-```
-DOCKER_HOST_IP=<Host IP> docker-compose -f compose/docker-compose-zk-kafka-test.yml up -d
-DOCKER_HOST_IP=<Host IP> docker-compose -f compose/docker-compose-etcd.yml up -d
-DOCKER_HOST_IP=<Host IP> docker-compose -f compose/rw_core.yml up -d
-DOCKER_HOST_IP=<Host IP> docker-compose -f compose/cli.yml up -d
-```
-#### Running the Ponsim Adapters
-
-Start the Ponsim OLT and ONU adapters
-```
-DOCKER_HOST_IP=<Host IP> docker-compose -f compose/adapters-ponsim.yml up -d
-```
-
-Start also the Ponsim OLT and ONU containers.  We are using only PonsimV2. You may want to change the 
-image names from the yml files below if you are pulling the Ponsim OLT and ONU images from somewhere else.
-
-```
-docker-compose -f compose/ponsim_olt.yml up -d
-docker-compose -f compose/ponsim_onu.yml up -d
-```
-
-#### Provisioning a device
-
-First get the IP address of the Ponsim OLT container by using the docker inspect command.
-
-Now, start the CLI. Password for 'voltha' user is 'admin'. Please see Dockerfile.cli for passwords
-
-```shell
-ssh -p 5022 voltha@localhost
-```
-
-Perform the provisioning
-
-```shell
-preprovision_olt -t ponsim_olt -H <IP of Ponsim OLT>:50060
-enable <deviceId>  // Use the device ID returned in the previous command
-```
-
-At this point you can send flows to the devices using the test option in the CLI. 
-```shell
-test
-install_eapol_flow <logical_device_id>
-install_dhcp_flows  <logical_device_id>
-install_all_controller_bound_flows <logical_device_id>
-install_all_sample_flows <logical_device_id>
-```
-
-You can also see the metrics the Ponsim OLT and ONU adapters are pushing onto the kafka bus.
-
-```shell
-kafkacat -b <host IP>:9092 -t voltha.kpis -p 0  -o beginning
-```
-
diff --git a/python/adapters/__init__.py b/python/adapters/__init__.py
deleted file mode 100644
index 58aca1e..0000000
--- a/python/adapters/__init__.py
+++ /dev/null
@@ -1,13 +0,0 @@
-# Copyright 2018 the original author or authors.
-#
-# 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.
diff --git a/python/cli/__init__.py b/python/cli/__init__.py
deleted file mode 100644
index b0fb0b2..0000000
--- a/python/cli/__init__.py
+++ /dev/null
@@ -1,13 +0,0 @@
-# Copyright 2017-present Open Networking Foundation
-#
-# 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.
diff --git a/python/cli/alarm_filters.py b/python/cli/alarm_filters.py
deleted file mode 100644
index 57a782f..0000000
--- a/python/cli/alarm_filters.py
+++ /dev/null
@@ -1,236 +0,0 @@
-#!/usr/bin/env python
-#
-# Copyright 2017 the original author or authors.
-#
-# 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.
-#
-
-"""
-Alarm filter CLI commands
-"""
-from optparse import make_option, OptionValueError
-
-from cmd2 import Cmd, options
-from google.protobuf.empty_pb2 import Empty
-
-from table import print_pb_list_as_table
-from voltha_protos import voltha_pb2
-from voltha_protos.events_pb2 import AlarmEventType, AlarmEventSeverity, AlarmEventCategory
-
-
-
-class AlarmFiltersCli(Cmd):
-    def __init__(self, get_stub):
-        Cmd.__init__(self)
-        self.get_stub = get_stub
-        self.prompt = '(' + self.colorize(
-            self.colorize('alarm_filters', 'red'), 'bold') + ') '
-
-    def cmdloop(self):
-        self._cmdloop()
-
-    def help_show(self):
-        self.poutput(
-'''
-Display the list of configured filters.
-
-Valid options:
-
--i FILTER_ID | --filter-id=FILTER_ID                Display the filter rules for a specific filter id (OPTIONAL)
-
-'''
-        )
-
-    @options([
-        make_option('-i', '--filter-id', action="store", dest='filter_id')
-    ])
-    def do_show(self, line, opts):
-        stub = self.get_stub()
-
-        if not opts.filter_id:
-            result = stub.ListAlarmFilters(Empty())
-            print_pb_list_as_table("Alarm Filters:", result.filters, {}, self.poutput)
-        else:
-            result = stub.GetAlarmFilter(voltha_pb2.ID(id=opts.filter_id))
-            print_pb_list_as_table("Rules for Filter ID = {}:".format(opts.filter_id),
-                                   result.rules, {}, self.poutput)
-
-    @staticmethod
-    def construct_rule(raw_rule):
-        rule = dict()
-
-        rule_kv = raw_rule.strip().split(':')
-
-        if len(rule_kv) == 2:
-            rule['key'] = rule_kv[0].lower()
-            rule['value'] = rule_kv[1].lower()
-        else:
-            raise OptionValueError("Error: A rule must be a colon separated key/value pair")
-
-        return rule
-
-    def parse_filter_rules(option, opt_str, value, parser):
-        rules = getattr(parser.values, option.dest)
-        if rules is None:
-            rules = list()
-            rules.append(AlarmFiltersCli.construct_rule(value))
-
-            for arg in parser.rargs:
-                if (arg[:2] == "--" and len(arg) > 2) or (arg[:1] == "-" and len(arg) > 1 and arg[1] != "-"):
-                    break
-                else:
-                    rules.append(AlarmFiltersCli.construct_rule(arg))
-
-            setattr(parser.values, option.dest, rules)
-        else:
-            raise OptionValueError('Warning: The filter rule option can only be specified once')
-
-    def help_create(self):
-        types = list(
-            k for k, v in
-            AlarmEventType.DESCRIPTOR.enum_values_by_name.items())
-        categories = list(
-            k for k, v in
-            AlarmEventCategory.DESCRIPTOR.enum_values_by_name.items())
-        severities = list(
-            k for k, v in
-            AlarmEventSeverity.DESCRIPTOR.enum_values_by_name.items())
-
-        alarm_types = types
-        alarm_categories = categories
-        alarm_severities = severities
-
-        usage = '''
-Create a new alarm filter.
-
-Valid options:
-
--r rule:value ... | --filter-rules rule:value ...   Specify one or more filter rules as key/value pairs (REQUIRED)
-
-Valid rule keys and expected values:
-
-id          : Identifier of an incoming alarm
-type        : Type of an incoming alarm {}
-category    : Category of an incoming alarm {}
-severity    : Severity of an incoming alarm {}
-resource_id : Resource identifier of an incoming alarm
-device_id   : Device identifier of an incoming alarm
-
-Example:
-
-# Filter any alarm that matches the following criteria
-
-create -r type:environment severity:indeterminate
-create -r device_id:754f9dcbe4a6
-
-'''.format(alarm_types, alarm_categories, alarm_severities)
-
-        self.poutput(usage)
-
-    @options([
-        make_option('-r', '--filter-rules', help='<key>:<value>...', action="callback",
-                    callback=parse_filter_rules, type='string', dest='filter_rules'),
-    ])
-    def do_create(self, line, opts):
-        if opts.filter_rules:
-            stub = self.get_stub()
-            result = stub.CreateAlarmFilter(voltha_pb2.AlarmFilter(rules=opts.filter_rules))
-            print_pb_list_as_table("Rules for Filter ID = {}:".format(result.id),
-                                   result.rules, {}, self.poutput)
-
-    def help_delete(self):
-        self.poutput(
-'''
-Delete a specific alarm filter entry.
-
-Valid options:
-
--i FILTER_ID | --filter-id=FILTER_ID                Display the filter rules for a specific filter id (REQUIRED)
-
-'''
-        )
-
-    @options([
-        make_option('-i', '--filter-id', action="store", dest='filter_id')
-    ])
-    def do_delete(self, line, opts):
-        if not opts.filter_id:
-            self.poutput(self.colorize('Error: ', 'red') + 'Specify ' + \
-                         self.colorize(self.colorize('"filter id"', 'blue'),
-                                       'bold') + ' to update')
-            return
-
-        stub = self.get_stub()
-        stub.DeleteAlarmFilter(voltha_pb2.ID(id=opts.filter_id))
-
-    def help_update(self):
-        types = list(
-            k for k, v in
-            AlarmEventType.DESCRIPTOR.enum_values_by_name.items())
-        categories = list(
-            k for k, v in
-            AlarmEventCategory.DESCRIPTOR.enum_values_by_name.items())
-        severities = list(
-            k for k, v in
-            AlarmEventSeverity.DESCRIPTOR.enum_values_by_name.items())
-
-        alarm_types = types
-        alarm_categories = categories
-        alarm_severities = severities
-
-        usage = '''
-Update the filter rules for an existing alarm filter.
-
-Valid options:
-
--i FILTER_ID | --filter-id=FILTER_ID                Indicate the alarm filter identifier to update (REQUIRED)
--r rule:value ... | --filter-rules rule:value ...   Specify one or more filter rules as key/value pairs (REQUIRED)
-
-Valid rule keys and expected values:
-
-id          : Identifier of an incoming alarm
-type        : Type of an incoming alarm {}
-category    : Category of an incoming alarm {}
-severity    : Severity of an incoming alarm {}
-resource_id : Resource identifier of an incoming alarm
-device_id   : Device identifier of an incoming alarm
-
-Example:
-
-# Filter any alarm that matches the following criteria
-
-update -i 9da115b900bc -r type:environment severity:indeterminate resource_id:1554b0517a07
-
-'''.format(alarm_types, alarm_categories, alarm_severities)
-
-        self.poutput(usage)
-
-    @options([
-        make_option('-r', '--filter-rules', help='<key>:<value>...', action="callback",
-                    callback=parse_filter_rules, type='string', dest='filter_rules'),
-        make_option('-i', '--filter-id', action="store", dest='filter_id')
-    ])
-    def do_update(self, line, opts):
-        if not opts.filter_id:
-            self.poutput(self.colorize('Error: ', 'red') + 'Specify ' + \
-                         self.colorize(self.colorize('"filter id"', 'blue'),
-                                       'bold') + ' to update')
-            return
-
-        if opts.filter_rules:
-            stub = self.get_stub()
-            result = stub.UpdateAlarmFilter(
-                voltha_pb2.AlarmFilter(id=opts.filter_id, rules=opts.filter_rules)
-            )
-            print_pb_list_as_table("Rules for Filter ID = {}:".format(result.id),
-                                   result.rules, {}, self.poutput)
diff --git a/python/cli/device.py b/python/cli/device.py
deleted file mode 100755
index 25ad72b..0000000
--- a/python/cli/device.py
+++ /dev/null
@@ -1,705 +0,0 @@
-#!/usr/bin/env python
-#
-# Copyright 2016 the original author or authors.
-#
-# 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.
-#
-
-"""
-Device level CLI commands
-"""
-from optparse import make_option
-from cmd2 import Cmd, options
-from simplejson import dumps
-
-from table import print_pb_as_table, print_pb_list_as_table
-from utils import print_flows, pb2dict, enum2name
-
-from voltha_protos import voltha_pb2, common_pb2
-import sys
-import json
-from google.protobuf.json_format import MessageToDict
-
-# Since proto3 won't send fields that are set to 0/false/"" any object that
-# might have those values set in them needs to be replicated here such that the
-# fields can be adequately
-
-
-class DeviceCli(Cmd):
-
-    def __init__(self, device_id, get_stub):
-        Cmd.__init__(self)
-        self.get_stub = get_stub
-        self.device_id = device_id
-        self.prompt = '(' + self.colorize(
-            self.colorize('device {}'.format(device_id), 'red'), 'bold') + ') '
-        self.pm_config_last = None
-        self.pm_config_dirty = False
-
-    def cmdloop(self):
-        self._cmdloop()
-
-    def get_device(self, depth=0):
-        stub = self.get_stub()
-        res = stub.GetDevice(voltha_pb2.ID(id=self.device_id),
-                             metadata=(('get-depth', str(depth)), ))
-        return res
-
-    do_exit = Cmd.do_quit
-
-    def do_quit(self, line):
-        if self.pm_config_dirty:
-            self.poutput("Uncommited changes for " + \
-                         self.colorize(
-                             self.colorize("perf_config,", "blue"),
-                             "bold") + " please either " + self.colorize(
-                             self.colorize("commit", "blue"), "bold") + \
-                         " or " + self.colorize(
-                             self.colorize("reset", "blue"), "bold") + \
-                         " your changes using " + \
-                         self.colorize(
-                             self.colorize("perf_config", "blue"), "bold"))
-            return False
-        else:
-            return self._STOP_AND_EXIT
-
-    def do_show(self, line):
-        """Show detailed device information"""
-        print_pb_as_table('Device {}'.format(self.device_id),
-                          self.get_device(depth=-1))
-
-    def do_ports(self, line):
-        """Show ports of device"""
-        device = self.get_device(depth=-1)
-        omit_fields = {
-        }
-        print_pb_list_as_table('Device ports:', device.ports,
-                               omit_fields, self.poutput)
-
-    def complete_perf_config(self, text, line, begidx, endidx):
-        sub_cmds = {"show", "set", "commit", "reset"}
-        sub_opts = {"-f", "-e", "-d", "-o"}
-        # Help the interpreter complete the paramters.
-        completions = []
-        if not self.pm_config_last:
-            device = self.get_device(depth=-1)
-            self.pm_config_last = device.pm_configs
-        m_names = [d.name for d in self.pm_config_last.metrics]
-        cur_cmd = line.strip().split(" ")
-        try:
-            if not text and len(cur_cmd) == 1:
-                completions = ("show", "set", "commit", "reset")
-            elif len(cur_cmd) == 2:
-                if "set" == cur_cmd[1]:
-                    completions = [d for d in sub_opts]
-                else:
-                    completions = [d for d in sub_cmds if d.startswith(text)]
-            elif len(cur_cmd) > 2 and cur_cmd[1] == "set":
-                if cur_cmd[len(cur_cmd)-1] == "-":
-                    completions = [list(d)[1] for d in sub_opts]
-                elif cur_cmd[len(cur_cmd)-1] == "-f":
-                    completions = ("\255","Please enter a sampling frequency in 10ths of a second")
-                elif cur_cmd[len(cur_cmd)-2] == "-f":
-                    completions = [d for d in sub_opts]
-                elif cur_cmd[len(cur_cmd)-1] in {"-e","-d","-o"}:
-                    if self.pm_config_last.grouped:
-                        pass
-                    else:
-                        completions = [d.name for d in self.pm_config_last.metrics]
-                elif cur_cmd[len(cur_cmd)-2] in {"-e","-d"}:
-                    if text and text not in m_names:
-                        completions = [d for d in m_names if d.startswith(text)]
-                    else:
-                        completions = [d for d in sub_opts]
-                elif cur_cmd[len(cur_cmd)-2] == "-o":
-                    if cur_cmd[len(cur_cmd)-1] in [d.name for d in self.pm_config_last.metrics]:
-                        completions = ("\255","Please enter a sampling frequency in 10ths of a second")
-                    else:
-                        completions = [d for d in m_names if d.startswith(text)]
-                elif cur_cmd[len(cur_cmd)-3] == "-o":
-                    completions = [d for d in sub_opts]
-        except:
-            e = sys.exc_info()
-            print(e)
-        return completions
-
-
-    def help_perf_config(self):
-        self.poutput(
-'''
-perf_config [show | set | commit | reset] [-f <default frequency>] [{-e <metric/group
-            name>}] [{-d <metric/group name>}] [{-o <metric/group name> <override
-            frequency>}]
-
-show: displays the performance configuration of the device
-set: changes the parameters specified with -e, -d, and -o
-reset: reverts any changes made since the last commit
-commit: commits any changes made which applies them to the device.
-
--e: enable collection of the specified metric, more than one -e may be
-            specified.
--d: disable collection of the specified metric, more than on -d may be
-            specified.
--o: override the collection frequency of the specified metric, more than one -o
-            may be specified. Note that -o isn't valid unless
-            frequency_override is set to True for the device.
-
-Changes made by set are held locally until a commit or reset command is issued.
-A commit command will write the configuration to the device and it takes effect
-immediately. The reset command will undo any changes since the start of the
-device session.
-
-If grouped is true then the -d, -e and -o commands refer to groups and not
-individual metrics.
-'''
-        )
-
-    @options([
-        make_option('-f', '--default_freq', action="store", dest='default_freq',
-                    type='long', default=None),
-        make_option('-e', '--enable', action='append', dest='enable',
-                    default=None),
-        make_option('-d', '--disable', action='append', dest='disable',
-                    default=None),
-        make_option('-o', '--override', action='append', dest='override',
-                    nargs=2, default=None, type='string'),
-    ])
-    def do_perf_config(self, line, opts):
-        """Show and set the performance monitoring configuration of the device"""
-
-        device = self.get_device(depth=-1)
-        if not self.pm_config_last:
-            self.pm_config_last = device.pm_configs
-
-        # Ensure that a valid sub-command was provided
-        if line.strip() not in {"set", "show", "commit", "reset", ""}:
-                self.poutput(self.colorize('Error: ', 'red') +
-                             self.colorize(self.colorize(line.strip(), 'blue'),
-                                           'bold') + ' is not recognized')
-                return
-
-        # Ensure no options are provided when requesting to view the config
-        if line.strip() == "show" or line.strip() == "":
-            if opts.default_freq or opts.enable or opts.disable:
-                self.poutput(opts.disable)
-                self.poutput(self.colorize('Error: ', 'red') + 'use ' +
-                             self.colorize(self.colorize('"set"', 'blue'),
-                                           'bold') + ' to change settings')
-                return
-
-        if line.strip() == "set":  # Set the supplied values
-            metric_list = set()
-            if opts.enable is not None:
-                metric_list |= {metric for metric in opts.enable}
-            if opts.disable is not None:
-                metric_list |= {metric for metric in opts.disable}
-            if opts.override is not None:
-                metric_list |= {metric for metric, _ in opts.override}
-
-            # The default frequency
-            if opts.default_freq:
-                self.pm_config_last.default_freq = opts.default_freq
-                self.pm_config_dirty = True
-
-            # Field or group visibility
-            if self.pm_config_last.grouped:
-                for g in self.pm_config_last.groups:
-                    if opts.enable:
-                        if g.group_name in opts.enable:
-                            g.enabled = True
-                            self.pm_config_dirty = True
-                            metric_list.discard(g.group_name)
-                for g in self.pm_config_last.groups:
-                    if opts.disable:
-                        if g.group_name in opts.disable:
-                            g.enabled = False
-                            self.pm_config_dirty = True
-                            metric_list.discard(g.group_name)
-            else:
-                for m in self.pm_config_last.metrics:
-                    if opts.enable:
-                        if m.name in opts.enable:
-                            m.enabled = True
-                            self.pm_config_dirty = True
-                            metric_list.discard(m.name)
-                for m in self.pm_config_last.metrics:
-                    if opts.disable:
-                        if m.name in opts.disable:
-                            m.enabled = False
-                            self.pm_config_dirty = True
-                            metric_list.discard(m.name)
-
-            # Frequency overrides.
-            if opts.override:
-                if self.pm_config_last.freq_override:
-                    oo = dict()
-                    for o in opts.override:
-                        oo[o[0]] = o[1]
-                    if self.pm_config_last.grouped:
-                        for g in self.pm_config_last.groups:
-                            if g.group_name in oo:
-                                try:
-                                    g.group_freq = int(oo[g.group_name])
-                                except ValueError:
-                                    self.poutput(self.colorize('Warning: ',
-                                                               'yellow') +
-                                                 self.colorize(oo[g.group_name],
-                                                               'blue') +
-                                                 " is not an integer... ignored")
-                                del oo[g.group_name]
-                                self.pm_config_dirty = True
-                                metric_list.discard(g.group_name)
-                    else:
-                        for m in self.pm_config_last.metrics:
-                            if m.name in oo:
-                                try:
-                                    m.sample_freq = int(oo[m.name])
-                                except ValueError:
-                                    self.poutput(self.colorize('Warning: ',
-                                                               'yellow') +
-                                                 self.colorize(oo[m.name],
-                                                               'blue') +
-                                                 " is not an integer... ignored")
-                                del oo[m.name]
-                                self.pm_config_dirty = True
-                                metric_list.discard(m.name)
-
-                    # If there's anything left the input was typoed
-                    if self.pm_config_last.grouped:
-                        field = 'group'
-                    else:
-                        field = 'metric'
-                    for o in oo:
-                        self.poutput(self.colorize('Warning: ', 'yellow') +
-                                     'the parameter' + ' ' +
-                                     self.colorize(o, 'blue') + ' is not ' +
-                                     'a ' + field + ' name... ignored')
-                    if oo:
-                        return
-
-                else:  # Frequency overrides not enabled
-                    self.poutput(self.colorize('Error: ', 'red') +
-                                 'Individual overrides are only ' +
-                                 'supported if ' +
-                                 self.colorize('freq_override', 'blue') +
-                                 ' is set to ' + self.colorize('True', 'blue'))
-                    return
-
-            if len(metric_list):
-                metric_name_list = ", ".join(str(metric) for metric in metric_list)
-                self.poutput(self.colorize('Error: ', 'red') +
-                             'Metric/Metric Group{} '.format('s' if len(metric_list) > 1 else '') +
-                             self.colorize(metric_name_list, 'blue') +
-                             ' {} not found'.format('were' if len(metric_list) > 1 else 'was'))
-                return
-
-            self.poutput("Success")
-            return
-
-        elif line.strip() == "commit" and self.pm_config_dirty:
-            stub = self.get_stub()
-            stub.UpdateDevicePmConfigs(self.pm_config_last)
-            self.pm_config_last = self.get_device(depth=-1).pm_configs
-            self.pm_config_dirty = False
-
-        elif line.strip() == "reset" and self.pm_config_dirty:
-            self.pm_config_last = self.get_device(depth=-1).pm_configs
-            self.pm_config_dirty = False
-
-        omit_fields = {'groups', 'metrics', 'id'}
-        print_pb_as_table('PM Config:', self.pm_config_last, omit_fields,
-                          self.poutput,show_nulls=True)
-        if self.pm_config_last.grouped:
-            #self.poutput("Supported metric groups:")
-            for g in self.pm_config_last.groups:
-                if self.pm_config_last.freq_override:
-                    omit_fields = {'metrics'}
-                else:
-                    omit_fields = {'group_freq','metrics'}
-                print_pb_as_table('', g, omit_fields, self.poutput,
-                                  show_nulls=True)
-                if g.enabled:
-                    state = 'enabled'
-                else:
-                    state = 'disabled'
-                print_pb_list_as_table(
-                    'Metric group {} is {}'.format(g.group_name,state),
-                    g.metrics, {'enabled', 'sample_freq'}, self.poutput,
-                    dividers=100, show_nulls=True)
-        else:
-            if self.pm_config_last.freq_override:
-                omit_fields = {}
-            else:
-                omit_fields = {'sample_freq'}
-            print_pb_list_as_table('Supported metrics:', self.pm_config_last.metrics,
-                                   omit_fields, self.poutput, dividers=100,
-                                   show_nulls=True)
-
-    def do_flows(self, line):
-        """Show flow table for device"""
-        device = pb2dict(self.get_device(-1))
-        print_flows(
-            'Device',
-            self.device_id,
-            type=device['type'],
-            flows=device['flows']['items'],
-            groups=device['flow_groups']['items']
-        )
-
-    def do_images(self, line):
-        """Show software images on the device"""
-        device = self.get_device(depth=-1)
-        omit_fields = {}
-        print_pb_list_as_table('Software Images:', device.images.image,
-                               omit_fields, self.poutput, show_nulls=True)
-
-    @options([
-        make_option('-u', '--url', action='store', dest='url',
-                    help="URL to get sw image"),
-        make_option('-n', '--name', action='store', dest='name',
-                    help="Image name"),
-        make_option('-c', '--crc', action='store', dest='crc',
-                    help="CRC code to verify with", default=0),
-        make_option('-v', '--version', action='store', dest='version',
-                    help="Image version", default=0),
-    ])
-    def do_img_dnld_request(self, line, opts):
-        """
-        Request image download to a device
-        """
-        device = self.get_device(depth=-1)
-        self.poutput('device_id {}'.format(device.id))
-        self.poutput('name {}'.format(opts.name))
-        self.poutput('url {}'.format(opts.url))
-        self.poutput('crc {}'.format(opts.crc))
-        self.poutput('version {}'.format(opts.version))
-        try:
-            device_id = device.id
-            if device_id and opts.name and opts.url:
-                kw = dict(id=device_id)
-                kw['name'] = opts.name
-                kw['url'] = opts.url
-            else:
-                self.poutput('Device ID and URL are needed')
-                raise Exception('Device ID and URL are needed')
-        except Exception as e:
-            self.poutput('Error request img dnld {}.  Error:{}'.format(device_id, e))
-            return
-        kw['crc'] = long(opts.crc)
-        kw['image_version'] = opts.version
-        response = None
-        try:
-            request = voltha_pb2.ImageDownload(**kw)
-            stub = self.get_stub()
-            response = stub.DownloadImage(request)
-        except Exception as e:
-            self.poutput('Error download image {}. Error:{}'.format(kw['id'], e))
-            return
-        name = enum2name(common_pb2.OperationResp,
-                        'OperationReturnCode', response.code)
-        self.poutput('response: {}'.format(name))
-        self.poutput('{}'.format(response))
-
-    @options([
-        make_option('-n', '--name', action='store', dest='name',
-                    help="Image name"),
-    ])
-    def do_img_dnld_status(self, line, opts):
-        """
-        Get a image download status
-        """
-        device = self.get_device(depth=-1)
-        self.poutput('device_id {}'.format(device.id))
-        self.poutput('name {}'.format(opts.name))
-        try:
-            device_id = device.id
-            if device_id and opts.name:
-                kw = dict(id=device_id)
-                kw['name'] = opts.name
-            else:
-                self.poutput('Device ID, Image Name are needed')
-                raise Exception('Device ID, Image Name are needed')
-        except Exception as e:
-            self.poutput('Error get img dnld status {}.  Error:{}'.format(device_id, e))
-            return
-        status = None
-        try:
-            img_dnld = voltha_pb2.ImageDownload(**kw)
-            stub = self.get_stub()
-            status = stub.GetImageDownloadStatus(img_dnld)
-        except Exception as e:
-            self.poutput('Error get img dnld status {}. Error:{}'.format(device_id, e))
-            return
-        fields_to_omit = {
-              'crc',
-              'local_dir',
-        }
-        try:
-            print_pb_as_table('ImageDownload Status:', status, fields_to_omit, self.poutput)
-        except Exception, e:
-            self.poutput('Error {}.  Error:{}'.format(device_id, e))
-
-    def do_img_dnld_list(self, line):
-        """
-        List all image download records for a given device
-        """
-        device = self.get_device(depth=-1)
-        device_id = device.id
-        self.poutput('Get all img dnld records {}'.format(device_id))
-        try:
-            stub = self.get_stub()
-            img_dnlds = stub.ListImageDownloads(voltha_pb2.ID(id=device_id))
-        except Exception, e:
-            self.poutput('Error list img dnlds {}.  Error:{}'.format(device_id, e))
-            return
-        fields_to_omit = {
-              'crc',
-              'local_dir',
-        }
-        try:
-            print_pb_list_as_table('ImageDownloads:', img_dnlds.items, fields_to_omit, self.poutput)
-        except Exception, e:
-            self.poutput('Error {}.  Error:{}'.format(device_id, e))
-
-
-    @options([
-        make_option('-n', '--name', action='store', dest='name',
-                    help="Image name"),
-    ])
-    def do_img_dnld_cancel(self, line, opts):
-        """
-        Cancel a requested image download
-        """
-        device = self.get_device(depth=-1)
-        self.poutput('device_id {}'.format(device.id))
-        self.poutput('name {}'.format(opts.name))
-        device_id = device.id
-        try:
-            if device_id and opts.name:
-                kw = dict(id=device_id)
-                kw['name'] = opts.name
-            else:
-                self.poutput('Device ID, Image Name are needed')
-                raise Exception('Device ID, Image Name are needed')
-        except Exception as e:
-            self.poutput('Error cancel sw dnld {}. Error:{}'.format(device_id, e))
-            return
-        response = None
-        try:
-            img_dnld = voltha_pb2.ImageDownload(**kw)
-            stub = self.get_stub()
-            img_dnld = stub.GetImageDownload(img_dnld)
-            response = stub.CancelImageDownload(img_dnld)
-        except Exception as e:
-            self.poutput('Error cancel sw dnld {}. Error:{}'.format(device_id, e))
-            return
-        name = enum2name(common_pb2.OperationResp,
-                        'OperationReturnCode', response.code)
-        self.poutput('response: {}'.format(name))
-        self.poutput('{}'.format(response))
-
-    def help_simulate_alarm(self):
-        self.poutput(
-'''
-simulate_alarm <alarm_name> [-b <bit rate>] [-c] [-d <drift>] [-e <eqd>]
-            [-i <interface id>] [-o <onu device id>] [-p <port type name>]
-
-<name> is the name of the alarm to raise. Other rguments are alarm specific
-and only have meaning in the context of a particular alarm. Below is a list
-of the alarms that may be raised:
-
-simulate_alarm los -i <interface_id> -p <port_type_name>
-simulate_alarm dying_gasp -i <interface_id> -o <onu_device_id>
-simulate_alarm onu_los -i <interface_id> -o <onu_device_id>
-simulate_alarm onu_lopc_miss -i <interface_id> -o <onu_device_id>
-simulate_alarm onu_lopc_mic -i <interface_id> -o <onu_device_id>
-simulate_alarm onu_lob -i <interface_id> -o <onu_device_id>
-simulate_alarm onu_signal_degrade -i <interface_id> -o <onu_device_id>
-               -b <bit_rate>
-simulate_alarm onu_drift_of_window -i <interface_id>
-               -o <onu_device_id> -d <drift> -e <eqd>
-simulate_alarm onu_signal_fail -i <interface_id> -o <onu_device_id>
-               -b <bit_rate>
-simulate_alarm onu_activation -i <interface_id> -o <onu_device_id>
-simulate_alarm onu_startup -i <interface_id> -o <onu_device_id>
-simulate_alarm onu_discovery -i <interface_id> -s <onu_serial_number>
-
-If the -c option is specified then the alarm will be cleared. By default,
-it will be raised. Note that only some alarms can be cleared.
-'''
-        )
-
-    @options([
-        make_option('-c', '--clear', action='store_true', default=False,
-                    help="Clear alarm instead of raising"),
-        make_option('-b', '--inverse_bit_error_rate', action='store', dest='inverse_bit_error_rate',
-                    help="Inverse bit error rate", default=0, type="int"),
-        make_option('-d', '--drift', action='store', dest='drift',
-                    help="Drift", default=0, type="int"),
-        make_option('-e', '--new_eqd', action='store', dest='new_eqd',
-                    help="New EQD", default=0, type="int"),
-        make_option('-i', '--intf_id', action='store', dest='intf_id',
-                    help="Interface ID", default=""),
-        make_option('-o', '--onu_device_id', action='store', dest='onu_device_id',
-                    help="ONU device ID", default=""),
-        make_option('-p', '--port_type_name', action='store', dest='port_type_name',
-                    help="Port type name", default=""),
-        make_option('-s', '--onu_serial_number', action='store', dest='onu_serial_number',
-                    help="ONU Serial Number", default=""),
-    ])
-    def do_simulate_alarm(self, line, opts):
-        indicator = line
-        device = self.get_device(depth=-1)
-        device_id = device.id
-
-        alarm_args = {"los": ["intf_id", "port_type_name"],
-                      "dying_gasp": ["intf_id", "onu_device_id"],
-                      "onu_los": ["intf_id", "onu_device_id"],
-                      "onu_lopc_miss": ["intf_id", "onu_device_id"],
-                      "onu_lopc_mic": ["intf_id", "onu_device_id"],
-                      "onu_lob": ["intf_id", "onu_device_id"],
-                      "onu_signal_degrade": ["intf_id", "onu_device_id", "inverse_bit_error_rate"],
-                      "onu_drift_of_window": ["intf_id", "onu_device_id", "drift", "new_eqd"],
-                      "onu_signal_fail": ["intf_id", "onu_device_id", "inverse_bit_error_rate"],
-                      "onu_activation": ["intf_id", "onu_device_id"],
-                      "onu_startup": ["intf_id", "onu_device_id"],
-                      "onu_discovery": ["intf_id", "onu_serial_number"]
-                      }
-        try:
-            if indicator not in alarm_args:
-                self.poutput("Unknown alarm indicator %s. Valid choices are %s." % (indicator,
-                                                                                    ", ".join(alarm_args.keys())))
-                raise Exception("Unknown alarm indicator %s" % indicator)
-
-            for arg_name in alarm_args[indicator]:
-                if not getattr(opts, arg_name):
-                    self.poutput("Option %s is required for alarm %s. See help." % (arg_name, indicator))
-                    raise Exception("Option %s is required for alarm %s" % (arg_name, indicator))
-
-            # TODO: check for required arguments
-            kw = dict(id=device_id)
-
-            kw["indicator"] = indicator
-            kw["intf_id"] = opts.intf_id
-            kw["onu_device_id"] = opts.onu_device_id
-            kw["port_type_name"] = opts.port_type_name
-            kw["inverse_bit_error_rate"] = opts.inverse_bit_error_rate
-            kw["drift"] = opts.drift
-            kw["new_eqd"] = opts.new_eqd
-            kw["onu_serial_number"] = opts.onu_serial_number
-
-            if opts.clear:
-                kw["operation"] = voltha_pb2.SimulateAlarmRequest.CLEAR
-            else:
-                kw["operation"] = voltha_pb2.SimulateAlarmRequest.RAISE
-        except Exception as e:
-            self.poutput('Error simulate alarm {}. Error:{}'.format(device_id, e))
-            return
-        response = None
-        try:
-            simulate_alarm = voltha_pb2.SimulateAlarmRequest(**kw)
-            stub = self.get_stub()
-            response = stub.SimulateAlarm(simulate_alarm)
-        except Exception as e:
-            self.poutput('Error simulate alarm {}. Error:{}'.format(kw['id'], e))
-            return
-        name = enum2name(common_pb2.OperationResp,
-                        'OperationReturnCode', response.code)
-        self.poutput('response: {}'.format(name))
-        self.poutput('{}'.format(response))
-
-    @options([
-        make_option('-n', '--name', action='store', dest='name',
-                    help="Image name"),
-        make_option('-s', '--save', action='store', dest='save_config',
-                    help="Save Config", default="True"),
-        make_option('-d', '--dir', action='store', dest='local_dir',
-                    help="Image on device location"),
-    ])
-    def do_img_activate(self, line, opts):
-        """
-        Activate an image update on device
-        """
-        device = self.get_device(depth=-1)
-        device_id = device.id
-        try:
-            if device_id and opts.name and opts.local_dir:
-                kw = dict(id=device_id)
-                kw['name'] = opts.name
-                kw['local_dir'] = opts.local_dir
-            else:
-                self.poutput('Device ID, Image Name, and Location are needed')
-                raise Exception('Device ID, Image Name, and Location are needed')
-        except Exception as e:
-            self.poutput('Error activate image {}. Error:{}'.format(device_id, e))
-            return
-        kw['save_config'] = json.loads(opts.save_config.lower())
-        self.poutput('activate image update {} {} {} {}'.format( \
-                    kw['id'], kw['name'],
-                    kw['local_dir'], kw['save_config']))
-        response = None
-        try:
-            img_dnld = voltha_pb2.ImageDownload(**kw)
-            stub = self.get_stub()
-            img_dnld = stub.GetImageDownload(img_dnld)
-            response = stub.ActivateImageUpdate(img_dnld)
-        except Exception as e:
-            self.poutput('Error activate image {}. Error:{}'.format(kw['id'], e))
-            return
-        name = enum2name(common_pb2.OperationResp,
-                        'OperationReturnCode', response.code)
-        self.poutput('response: {}'.format(name))
-        self.poutput('{}'.format(response))
-
-    @options([
-        make_option('-n', '--name', action='store', dest='name',
-                    help="Image name"),
-        make_option('-s', '--save', action='store', dest='save_config',
-                    help="Save Config", default="True"),
-        make_option('-d', '--dir', action='store', dest='local_dir',
-                    help="Image on device location"),
-    ])
-    def do_img_revert(self, line, opts):
-        """
-        Revert an image update on device
-        """
-        device = self.get_device(depth=-1)
-        device_id = device.id
-        try:
-            if device_id and opts.name and opts.local_dir:
-                kw = dict(id=device_id)
-                kw['name'] = opts.name
-                kw['local_dir'] = opts.local_dir
-            else:
-                self.poutput('Device ID, Image Name, and Location are needed')
-                raise Exception('Device ID, Image Name, and Location are needed')
-        except Exception as e:
-            self.poutput('Error revert image {}. Error:{}'.format(device_id, e))
-            return
-        kw['save_config'] = json.loads(opts.save_config.lower())
-        self.poutput('revert image update {} {} {} {}'.format( \
-                    kw['id'], kw['name'],
-                    kw['local_dir'], kw['save_config']))
-        response = None
-        try:
-            img_dnld = voltha_pb2.ImageDownload(**kw)
-            stub = self.get_stub()
-            img_dnld = stub.GetImageDownload(img_dnld)
-            response = stub.RevertImageUpdate(img_dnld)
-        except Exception as e:
-            self.poutput('Error revert image {}. Error:{}'.format(kw['id'], e))
-            return
-        name = enum2name(common_pb2.OperationResp,
-                        'OperationReturnCode', response.code)
-        self.poutput('response: {}'.format(name))
-        self.poutput('{}'.format(response))
diff --git a/python/cli/docs/README.md b/python/cli/docs/README.md
deleted file mode 100644
index e09f60e..0000000
--- a/python/cli/docs/README.md
+++ /dev/null
@@ -1,116 +0,0 @@
-# Voltha CLI (~/cli)
-
-## Overview
-
-The Voltha CLI allows a user to manage OLT and ONU devices along with their corresponding logical devices.   
-
-
-## Building the CLI
-
-From the voltha-go directory:
-```
-cd python
-source env.sh
-make cli
-```
-
-## Usage
-
-#### Setup (Development Mode)
-Since the CLI does not do much by itself, then to fully use it, you will need a somewhat complete 
-set of dependent containers running as well.  These will include the rw_core, OLT/ONU adapters and the actual OLT
- and ONU devices. For the examples below we will use ponsim as the adapters and ponsimv2 as the devices.  In order to get 
- everything running we also need Kafka (with zookeeper) and the Etcd KV store. 
- 
-First run the dependent containers from the voltha-go directory. In the commands below, replace the IP 
-with the IP of the host.
-```
-DOCKER_HOST_IP=<Host IP> docker-compose -f compose/docker-compose-zk-kafka-test.yml up -d
-DOCKER_HOST_IP=<Host IP> docker-compose -f compose/docker-compose-etcd.yml up -d
-DOCKER_HOST_IP=<Host IP> docker-compose -f compose/rw_core.yml up -d
-DOCKER_HOST_IP=<Host IP> docker-compose -f compose/cli.yml up -d
-DOCKER_HOST_IP=<Host IP> docker-compose -f compose/adapters-ponsim.yml up -d
-REPOSITORY=voltha/ docker-compose -f compose/ponsim_olt.yml up -d
-REPOSITORY=voltha/ docker-compose -f compose/ponsim_onu.yml up -d
-```
-
-#### Starting the CLI
-
-Now, start the CLI. Password for 'voltha' user is 'admin'. Please see Dockerfile.cli for passwords
-
-```shell
-tput rmam // If you are running on MAC for a clean output
-ssh -p 5022 voltha@localhost
-```
-
-At the prompt, if you type ```help``` you will see all the supported commands and sub-commands.
-
-####Provisioning and activating an OLT device
-
-Run the following at the prompt
-
-```shell
-preprovision_olt -t ponsim_olt -H <IP of Ponsim OLT>:50060 // Note this is the actial ponsim_olt container IP
-enable <deviceId>  // Use the device ID returned in the previous command
-```
-
-The ```enable``` command returns the logical device Id assigned to that OLT.  It is typically the MAC address 
-(without the ```:```) of the OLT device.
-
-Now go and try out the commands and sub-commands of the CLI.
-
-####Changing the logging level of the RW Core via the CLI
-
-You can dynamically change the logging level on the Voltha RW Core.  The change can be done at a package 
-level or for the entire RW Core.  
-
-The syntax to change log level is as follows:
-
-```
-log -p [package_name] -l log_level
-
-where 
-    package_name (optional) is one of:
-        db/kvstore
-        db/model
-        kafka
-        rw_core/core
-        rw_core/flow_decomposition
-        rw_core/graph
-    
-    log_level is one of:
-        DEBUG
-        INFO
-        WARNING
-        ERROR
-        CRITICAL
-        FATAL 
-```
-
-Below are some examples.
-```shell
-log -l ERROR // This sets the entire RW_CORE to output ERROR and above logs for all packages
-log -p rw_core/core -l DEBUG // This sets the rw_core/core package to debug level
-```
-
-Typically, if you want to debug, say something with the kvstore, then you would set the log level for
-the entire RW Core to error followed by setting the log level to debug for the kvstore as shown below.
-```shell
-log -l ERROR // This sets the entire RW_CORE to output ERROR and above logs for all packages
-log -p db/kvstore -l DEBUG // This sets the db/kvstore package to debug level
-```
-
-###Future CLI improvements
-
-* Add auto-completion for most common args like device and logical device ids
-* Add consistent argument checking
-* Unify code that retrieves data from gRPC
-* Unify code that prints out data/response, to allow:
-  * Selectable output mode:
-    * JSON
-    * Tabular
-* Organize history per sub context so that in each context the commands 
-  entered in that context will show
-* Metaprogramming [BIG ONE]: Make large part of the commands come from annotations embedded in
-  the protobuf files and have corresponding handler auto-generated by protoc
-* Package CLI as docker container, bake it into composition
diff --git a/python/cli/logical_device.py b/python/cli/logical_device.py
deleted file mode 100644
index a49f6f8..0000000
--- a/python/cli/logical_device.py
+++ /dev/null
@@ -1,127 +0,0 @@
-#!/usr/bin/env python
-#
-# Copyright 2016 the original author or authors.
-#
-# 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.
-#
-
-"""
-Logical device level CLI commands
-"""
-from cmd2 import Cmd
-from simplejson import dumps
-
-from table import print_pb_as_table, print_pb_list_as_table
-from utils import pb2dict
-from utils import print_flows, print_groups
-from google.protobuf.empty_pb2 import Empty
-
-from voltha_protos import voltha_pb2
-
-
-class LogicalDeviceCli(Cmd):
-
-    def __init__(self, logical_device_id, get_stub):
-        Cmd.__init__(self)
-        self.get_stub = get_stub
-        self.logical_device_id = logical_device_id
-        self.prompt = '(' + self.colorize(
-            self.colorize('logical device {}'.format(logical_device_id), 'red'),
-            'bold') + ') '
-
-    def cmdloop(self):
-        self._cmdloop()
-
-    def get_logical_device(self, depth=0):
-        stub = self.get_stub()
-        res = stub.GetLogicalDevice(voltha_pb2.ID(id=self.logical_device_id),
-                                    metadata=(('get-depth', str(depth)), ))
-        return res
-
-    def get_device(self, id):
-        stub = self.get_stub()
-        return stub.GetDevice(voltha_pb2.ID(id=id))
-
-    def get_devices(self):
-        stub = self.get_stub()
-        res = stub.ListDevices(Empty())
-        return res.items
-
-    do_exit = Cmd.do_quit
-
-    def do_show(self, _):
-        """Show detailed logical device information"""
-        print_pb_as_table('Logical device {}'.format(self.logical_device_id),
-                          self.get_logical_device(depth=-1))
-
-    def do_ports(self, _):
-        """Show ports of logical device"""
-        device = self.get_logical_device(depth=-1)
-        omit_fields = {
-            'ofp_port.advertised',
-            'ofp_port.peer',
-            'ofp_port.max_speed'
-        }
-        print_pb_list_as_table('Logical device ports:', device.ports,
-                               omit_fields, self.poutput)
-
-    def do_flows(self, _):
-        """Show flow table for logical device"""
-        logical_device = pb2dict(self.get_logical_device(-1))
-        print_flows(
-            'Logical Device',
-            self.logical_device_id,
-            type='n/a',
-            flows=logical_device['flows']['items'],
-            groups=logical_device['flow_groups']['items']
-        )
-
-    def do_groups(self, _):
-        """Show flow group table for logical device"""
-        logical_device = pb2dict(self.get_logical_device(-1))
-        print_groups(
-            'Logical Device',
-            self.logical_device_id,
-            type='n/a',
-            groups=logical_device['flow_groups']['items']
-        )
-
-    def do_meters(self, _):
-        """Show flow meter table for logical device"""
-        logical_device = pb2dict(self.get_logical_device(-1))
-        print_meters(
-            'Logical Device',
-            self.logical_device_id,
-            type='n/a',
-            meters=logical_device['meters']['items']
-        )
-
-    def do_devices(self, line):
-        """List devices that belong to this logical device"""
-        logical_device = self.get_logical_device()
-        root_device_id = logical_device.root_device_id
-        devices = [self.get_device(root_device_id)]
-        for d in self.get_devices():
-            if d.parent_id == root_device_id:
-                devices.append(d)
-        omit_fields = {
-            'adapter',
-            'vendor',
-            'model',
-            'hardware_version',
-            'software_version',
-            'firmware_version',
-            'serial_number'
-        }
-        print_pb_list_as_table('Devices:', devices, omit_fields, self.poutput)
-
diff --git a/python/cli/main.py b/python/cli/main.py
deleted file mode 100755
index d8ef9f8..0000000
--- a/python/cli/main.py
+++ /dev/null
@@ -1,945 +0,0 @@
-#!/usr/bin/env python
-#
-# Copyright 2016 the original author or authors.
-#
-# 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.
-#
-import argparse
-import os
-import readline
-import sys
-from optparse import make_option
-from time import sleep, time
-
-import grpc
-import requests
-from cmd2 import Cmd, options
-from consul import Consul
-from google.protobuf.empty_pb2 import Empty
-from simplejson import dumps
-
-from device import DeviceCli
-from omci import OmciCli
-from alarm_filters import AlarmFiltersCli
-from logical_device import LogicalDeviceCli
-from table import print_pb_list_as_table
-from pyvoltha.common.openflow.utils import *
-from voltha_protos import voltha_pb2
-from voltha_protos import voltha_pb2_grpc
-from voltha_protos.openflow_13_pb2 import FlowTableUpdate, FlowGroupTableUpdate
-
-from python.cli.utils import pb2dict
-
-defs = dict(
-    # config=os.environ.get('CONFIG', './cli.yml'),
-    consul=os.environ.get('CONSUL', 'localhost:8500'),
-    voltha_grpc_endpoint=os.environ.get('VOLTHA_GRPC_ENDPOINT',
-                                        'localhost:50057'),
-    voltha_sim_rest_endpoint=os.environ.get('VOLTHA_SIM_REST_ENDPOINT',
-                                            'localhost:18880'),
-    global_request=os.environ.get('GLOBAL_REQUEST', False)
-)
-
-banner = """\
-         _ _   _            ___ _    ___
-__ _____| | |_| |_  __ _   / __| |  |_ _|
-\ V / _ \ |  _| ' \/ _` | | (__| |__ | |
- \_/\___/_|\__|_||_\__,_|  \___|____|___|
-(to exit type quit or hit Ctrl-D)
-"""
-
-
-class VolthaCli(Cmd):
-    prompt = 'voltha'
-    history_file_name = '.voltha_cli_history'
-
-    # Settable CLI parameters
-    voltha_grpc = 'localhost:50057'
-    voltha_sim_rest = 'localhost:18880'
-    global_request = False
-    max_history_lines = 500
-    default_device_id = None
-    default_logical_device_id = None
-
-    Cmd.settable.update(dict(
-        voltha_grpc='Voltha GRPC endpoint in form of <host>:<port>',
-        voltha_sim_rest='Voltha simulation back door for testing in form '
-                        'of <host>:<port>',
-        max_history_lines='Maximum number of history lines stored across '
-                          'sessions',
-        default_device_id='Device id used when no device id is specified',
-        default_logical_device_id='Logical device id used when no device id '
-                                  'is specified',
-    ))
-
-    # cleanup of superfluous commands from cmd2
-    del Cmd.do_cmdenvironment
-    del Cmd.do_load
-    del Cmd.do__relative_load
-
-    def __init__(self, voltha_grpc, voltha_sim_rest, global_request=False):
-
-        VolthaCli.voltha_grpc = voltha_grpc
-        VolthaCli.voltha_sim_rest = voltha_sim_rest
-        VolthaCli.global_request = global_request
-        Cmd.__init__(self)
-        self.prompt = '(' + self.colorize(
-            self.colorize(self.prompt, 'blue'), 'bold') + ') '
-        self.channel = None
-        self.stub = None
-        self.device_ids_cache = None
-        self.device_ids_cache_ts = time()
-        self.logical_device_ids_cache = None
-        self.logical_device_ids_cache_ts = time()
-
-    # we override cmd2's method to avoid its optparse conflicting with our
-    # command line parsing
-    def cmdloop(self):
-        self._cmdloop()
-
-    def load_history(self):
-        """Load saved command history from local history file"""
-        try:
-            with file(self.history_file_name, 'r') as f:
-                for line in f.readlines():
-                    stripped_line = line.strip()
-                    self.history.append(stripped_line)
-                    readline.add_history(stripped_line)
-        except IOError:
-            pass  # ignore if file cannot be read
-
-    def save_history(self):
-        try:
-            with open(self.history_file_name, 'w') as f:
-                f.write('\n'.join(self.history[-self.max_history_lines:]))
-        except IOError as e:
-            self.perror('Could not save history in {}: {}'.format(
-                self.history_file_name, e))
-        else:
-            self.poutput('History saved as {}'.format(
-                self.history_file_name))
-
-    def perror(self, errmsg, statement=None):
-        # Touch it up to make sure error is prefixed and colored
-        Cmd.perror(self, self.colorize('***ERROR: ', 'red') + errmsg,
-                   statement)
-
-    def get_channel(self):
-        if self.channel is None:
-            self.channel = grpc.insecure_channel(self.voltha_grpc)
-        return self.channel
-
-    def get_stub(self):
-        if self.stub is None:
-            self.stub = voltha_pb2_grpc.VolthaServiceStub(self.get_channel())
-            # self.stub = \
-            #     voltha_pb2.VolthaGlobalServiceStub(self.get_channel()) \
-            #         if self.global_request else \
-            #             voltha_pb2.VolthaLocalServiceStub(self.get_channel())
-        return self.stub
-
-    # ~~~~~~~~~~~~~~~~~ ACTUAL COMMAND IMPLEMENTATIONS ~~~~~~~~~~~~~~~~~~~~~~~~
-
-    def do_reset_history(self, line):
-        """Reset CLI history"""
-        while self.history:
-            self.history.pop()
-
-    @options([
-        make_option('-p', '--package', action="store", dest='package',
-                    help="Package Name"),
-        make_option('-l', '--level', action='store', dest='level'),
-    ])
-    def do_log(self, line, opts):
-
-        def logLevel(level):
-            switcher= {
-                "DEBUG": 0,
-                "INFO":1,
-                "WARNING":2,
-                "ERROR":3,
-                "CRITICAL":4,
-                "FATAL":5
-            }
-            return switcher.get(level, 3)
-
-        if opts.level is None:
-            return
-
-        stub = self.get_stub()
-        kw = dict()
-        if opts.package:
-            kw['package_name'] = "github.com/opencord/voltha-go/" + opts.package
-
-        kw['level'] = logLevel(opts.level.upper())
-
-        try:
-            logging = voltha_pb2.Logging(**kw)
-            stub.UpdateLogLevel(logging)
-            self.poutput('success')
-        except Exception as e:
-            self.poutput('Exception - {})'.format(e))
-
-    def do_launch(self, line):
-        """If Voltha is not running yet, launch it"""
-        raise NotImplementedError('not implemented yet')
-
-    def do_restart(self, line):
-        """Launch Voltha, but if it is already running, terminate it first"""
-        pass
-
-    def do_adapters(self, line):
-        """List loaded adapter"""
-        stub = self.get_stub()
-        res = stub.ListAdapters(Empty())
-        omit_fields = {'config.log_level', 'logical_device_ids'}
-        print_pb_list_as_table('Adapters:', res.items, omit_fields, self.poutput)
-
-    def get_devices(self):
-        stub = self.get_stub()
-        res = stub.ListDevices(Empty())
-        return res.items
-
-    def get_logical_devices(self):
-        stub = self.get_stub()
-        res = stub.ListLogicalDevices(Empty())
-        return res.items
-
-    def do_devices(self, line):
-        """List devices registered in Voltha"""
-        devices = self.get_devices()
-        omit_fields = {
-            'adapter',
-            'vendor',
-            'model',
-            'hardware_version',
-            'images',
-            'firmware_version',
-            'vendor_id',
-            'flows',
-            'pm_configs',
-            'proxy_address',
-            'ports',
-            'vlan'
-        }
-        print_pb_list_as_table('Devices:', devices, omit_fields, self.poutput)
-
-    def do_logical_devices(self, line):
-        """List logical devices in Voltha"""
-        stub = self.get_stub()
-        res = stub.ListLogicalDevices(Empty())
-        omit_fields = {
-            'desc.mfr_desc',
-            'desc.hw_desc',
-            'desc.sw_desc',
-            'desc.dp_desc',
-            'desc.serial_number',
-            'switch_features.capabilities'
-        }
-        presfns = {
-            'datapath_id': lambda x: "{0:0{1}x}".format(int(x), 16)
-        }
-        print_pb_list_as_table('Logical devices:', res.items, omit_fields,
-                               self.poutput, presfns=presfns)
-
-    def do_device(self, line):
-        """Enter device level command mode"""
-        device_id = line.strip() or self.default_device_id
-        if not device_id:
-            raise Exception('<device-id> parameter needed')
-        if device_id not in self.device_ids():
-            self.poutput( self.colorize('Error: ', 'red') +
-                            'There is no such device')
-            raise Exception('<device-id> is not a valid one')
-        sub = DeviceCli(device_id, self.get_stub)
-        sub.cmdloop()
-
-    def do_logical_device(self, line):
-        """Enter logical device level command mode"""
-        logical_device_id = line.strip() or self.default_logical_device_id
-        if not logical_device_id:
-            raise Exception('<logical-device-id> parameter needed')
-        if logical_device_id not in self.logical_device_ids():
-            self.poutput( self.colorize('Error: ', 'red') +
-                            'There is no such device')
-            raise Exception('<logical-device-id> is not a valid one')
-        sub = LogicalDeviceCli(logical_device_id, self.get_stub)
-        sub.cmdloop()
-
-    def device_ids(self, force_refresh=False):
-        if force_refresh or self.device_ids is None or \
-                        (time() - self.device_ids_cache_ts) > 1:
-            self.device_ids_cache = [d.id for d in self.get_devices()]
-            self.device_ids_cache_ts = time()
-        return self.device_ids_cache
-
-    def logical_device_ids(self, force_refresh=False):
-        if force_refresh or self.logical_device_ids is None or \
-                        (time() - self.logical_device_ids_cache_ts) > 1:
-            self.logical_device_ids_cache = [d.id for d
-                                             in self.get_logical_devices()]
-            self.logical_device_ids_cache_ts = time()
-        return self.logical_device_ids_cache
-
-    def complete_device(self, text, line, begidx, endidx):
-        if not text:
-            completions = self.device_ids()[:]
-        else:
-            completions = [d for d in self.device_ids() if d.startswith(text)]
-        return completions
-
-    def complete_logical_device(self, text, line, begidx, endidx):
-        if not text:
-            completions = self.logical_device_ids()[:]
-        else:
-            completions = [d for d in self.logical_device_ids()
-                           if d.startswith(text)]
-        return completions
-
-    def do_omci(self, line):
-        """omci <device_ID> - Enter OMCI level command mode"""
-
-        device_id = line.strip() or self.default_device_id
-        if not device_id:
-            raise Exception('<device-id> parameter needed')
-        sub = OmciCli(device_id, self.get_stub)
-        sub.cmdloop()
-
-    def do_pdb(self, line):
-        """Launch PDB debug prompt in CLI (for CLI development)"""
-        from pdb import set_trace
-        set_trace()
-
-    def do_version(self, line):
-        """Show the VOLTHA core version"""
-        stub = self.get_stub()
-        voltha = stub.GetVoltha(Empty())
-        self.poutput('{}'.format(voltha.version))
-
-    def do_health(self, line):
-        """Show connectivity status to Voltha status"""
-        stub = voltha_pb2.HealthServiceStub(self.get_channel())
-        res = stub.GetHealthStatus(Empty())
-        self.poutput(dumps(pb2dict(res), indent=4))
-
-    @options([
-        make_option('-t', '--device-type', action="store", dest='device_type',
-                    help="Device type", default='simulated_olt'),
-        make_option('-m', '--mac-address', action='store', dest='mac_address',
-                    default='00:0c:e2:31:40:00'),
-        make_option('-i', '--ip-address', action='store', dest='ip_address'),
-        make_option('-H', '--host_and_port', action='store',
-                    dest='host_and_port'),
-    ])
-    def do_preprovision_olt(self, line, opts):
-        """Preprovision a new OLT with given device type"""
-        stub = self.get_stub()
-        kw = dict(type=opts.device_type)
-        if opts.host_and_port:
-            kw['host_and_port'] = opts.host_and_port
-        elif opts.ip_address:
-            kw['ipv4_address'] = opts.ip_address
-        elif opts.mac_address:
-            kw['mac_address'] = opts.mac_address.lower()
-        else:
-            raise Exception('Either IP address or Mac Address is needed')
-        # Pass any extra arguments past '--' to the device as custom arguments
-        kw['extra_args'] = line
-
-        device = voltha_pb2.Device(**kw)
-        device = stub.CreateDevice(device)
-        self.poutput('success (device id = {})'.format(device.id))
-        self.default_device_id = device.id
-
-    def do_enable(self, line):
-        """
-        Enable a device. If the <id> is not provided, it will be on the last
-        pre-provisioned device.
-        """
-        device_id = line or self.default_device_id
-        if device_id not in self.device_ids():
-            self.poutput('Error: There is no such preprovisioned device')
-            return
-
-        try:
-            stub = self.get_stub()
-            device = stub.GetDevice(voltha_pb2.ID(id=device_id))
-            if device.admin_state == voltha_pb2.AdminState.ENABLED:
-                if device.oper_status != voltha_pb2.OperStatus.ACTIVATING:
-                    self.poutput('Error: Device is already enabled')
-                    return
-            else:
-                stub.EnableDevice(voltha_pb2.ID(id=device_id))
-                self.poutput('enabling {}'.format(device_id))
-
-            while True:
-                device = stub.GetDevice(voltha_pb2.ID(id=device_id))
-                # If this is an OLT then acquire logical device id
-                if device.oper_status == voltha_pb2.OperStatus.ACTIVE:
-                    if device.type.endswith('_olt'):
-                        assert device.parent_id
-                        self.default_logical_device_id = device.parent_id
-                        self.poutput('success (logical device id = {})'.format(
-                            self.default_logical_device_id))
-                    else:
-                        self.poutput('success (device id = {})'.format(device.id))
-                    break
-                self.poutput('waiting for device to be enabled...')
-                sleep(.5)
-        except Exception as e:
-            self.poutput('Error enabling {}.  Error:{}'.format(device_id, e))
-
-    complete_activate_olt = complete_device
-
-    def do_reboot(self, line):
-        """
-        Rebooting a device. ID of the device needs to be provided
-        """
-        device_id = line or self.default_device_id
-        self.poutput('rebooting {}'.format(device_id))
-        try:
-            stub = self.get_stub()
-            stub.RebootDevice(voltha_pb2.ID(id=device_id))
-            self.poutput('rebooted {}'.format(device_id))
-        except Exception as e:
-            self.poutput('Error rebooting {}.  Error:{}'.format(device_id, e))
-
-    def do_self_test(self, line):
-        """
-        Self Test a device. ID of the device needs to be provided
-        """
-        device_id = line or self.default_device_id
-        self.poutput('Self Testing {}'.format(device_id))
-        try:
-            stub = self.get_stub()
-            res = stub.SelfTest(voltha_pb2.ID(id=device_id))
-            self.poutput('Self Tested {}'.format(device_id))
-            self.poutput(dumps(pb2dict(res), indent=4))
-        except Exception as e:
-            self.poutput('Error in self test {}.  Error:{}'.format(device_id, e))
-
-    def do_delete(self, line):
-        """
-        Deleting a device. ID of the device needs to be provided
-        """
-        device_id = line or self.default_device_id
-        self.poutput('deleting {}'.format(device_id))
-        try:
-            stub = self.get_stub()
-            stub.DeleteDevice(voltha_pb2.ID(id=device_id))
-            self.poutput('deleted {}'.format(device_id))
-        except Exception as e:
-            self.poutput('Error deleting {}.  Error:{}'.format(device_id, e))
-
-    def do_disable(self, line):
-        """
-        Disable a device. ID of the device needs to be provided
-        """
-        device_id = line
-        if device_id not in self.device_ids():
-            self.poutput('Error: There is no such device')
-            return
-        try:
-            stub = self.get_stub()
-            device = stub.GetDevice(voltha_pb2.ID(id=device_id))
-            if device.admin_state == voltha_pb2.AdminState.DISABLED:
-                self.poutput('Error: Device is already disabled')
-                return
-            stub.DisableDevice(voltha_pb2.ID(id=device_id))
-            self.poutput('disabling {}'.format(device_id))
-
-            # Do device query and verify that the device admin status is
-            # DISABLED and Operational Status is unknown
-            device = stub.GetDevice(voltha_pb2.ID(id=device_id))
-            if device.admin_state == voltha_pb2.AdminState.DISABLED:
-                self.poutput('disabled successfully {}'.format(device_id))
-            else:
-                self.poutput('disabling failed {}.  Admin State:{} '
-                             'Operation State: {}'.format(device_id,
-                                                          device.admin_state,
-                                                          device.oper_status))
-        except Exception as e:
-            self.poutput('Error disabling {}.  Error:{}'.format(device_id, e))
-
-    def do_test(self, line):
-        """Enter test mode, which makes a bunch on new commands available"""
-        sub = TestCli(self.history, self.voltha_grpc,
-                      self.get_stub, self.voltha_sim_rest)
-        sub.cmdloop()
-
-    def do_alarm_filters(self, line):
-        sub = AlarmFiltersCli(self.get_stub)
-        sub.cmdloop()
-
-
-class TestCli(VolthaCli):
-    def __init__(self, history, voltha_grpc, get_stub, voltha_sim_rest):
-        VolthaCli.__init__(self, voltha_grpc, voltha_sim_rest)
-        self.history = history
-        self.get_stub = get_stub
-        self.prompt = '(' + self.colorize(self.colorize('test', 'cyan'),
-                                          'bold') + ') '
-
-    def get_device(self, device_id, depth=0):
-        stub = self.get_stub()
-        res = stub.GetDevice(voltha_pb2.ID(id=device_id),
-                             metadata=(('get-depth', str(depth)),))
-        return res
-
-    def do_arrive_onus(self, line):
-        """
-        Simulate the arrival of ONUs (available only on simulated_olt)
-        """
-        device_id = line or self.default_device_id
-
-        # verify that device is of type simulated_olt
-        device = self.get_device(device_id)
-        assert device.type == 'simulated_olt', (
-            'Cannot use it on this device type (only on simulated_olt type)')
-
-        requests.get('http://{}/devices/{}/detect_onus'.format(
-            self.voltha_sim_rest, device_id
-        ))
-
-    complete_arrive_onus = VolthaCli.complete_device
-
-    def get_logical_ports(self, logical_device_id):
-        """
-        Return the NNI port number and the first usable UNI port of logical
-        device, and the vlan associated with the latter.
-        """
-        stub = self.get_stub()
-        ports = stub.ListLogicalDevicePorts(
-            voltha_pb2.ID(id=logical_device_id)).items
-        nni = None
-        unis = []
-        for port in ports:
-            if port.root_port:
-                assert nni is None, "There shall be only one root port"
-                nni = port.ofp_port.port_no
-            else:
-                uni = port.ofp_port.port_no
-                uni_device = self.get_device(port.device_id)
-                vlan = uni_device.vlan
-                unis.append((uni, vlan))
-
-        assert nni is not None, "No NNI port found"
-        assert unis, "Not a single UNI?"
-
-        return nni, unis
-
-    def do_install_eapol_flow(self, line):
-        """
-        Install an EAPOL flow on the given logical device. If device is not
-        given, it will be applied to logical device of the last pre-provisioned
-        OLT device.
-        """
-
-        logical_device_id = line or self.default_logical_device_id
-
-        # gather NNI and UNI port IDs
-        nni_port_no, unis = self.get_logical_ports(logical_device_id)
-
-        # construct and push flow rule
-        stub = self.get_stub()
-        print "I am now here", unis
-        for uni_port_no, _ in unis:
-            update = FlowTableUpdate(
-                id=logical_device_id,
-                flow_mod=mk_simple_flow_mod(
-                    priority=2000,
-                    match_fields=[in_port(uni_port_no), eth_type(0x888e)],
-                    actions=[
-                        # push_vlan(0x8100),
-                        # set_field(vlan_vid(4096 + 4000)),
-                        output(ofp.OFPP_CONTROLLER)
-                    ]
-                )
-            )
-            print "I am now here"
-            res = stub.UpdateLogicalDeviceFlowTable(update)
-            self.poutput('success for uni {} ({})'.format(uni_port_no, res))
-
-    complete_install_eapol_flow = VolthaCli.complete_logical_device
-
-    def do_install_all_controller_bound_flows(self, line):
-        """
-        Install all flow rules for controller bound flows, including EAPOL,
-        IGMP and DHCP. If device is not given, it will be applied to logical
-        device of the last pre-provisioned OLT device.
-        """
-        logical_device_id = line or self.default_logical_device_id
-
-        # gather NNI and UNI port IDs
-        nni_port_no, unis = self.get_logical_ports(logical_device_id)
-
-        # construct and push flow rules
-        stub = self.get_stub()
-
-        for uni_port_no, _ in unis:
-            stub.UpdateLogicalDeviceFlowTable(FlowTableUpdate(
-                id=logical_device_id,
-                flow_mod=mk_simple_flow_mod(
-                    priority=2000,
-                    match_fields=[
-                        in_port(uni_port_no),
-                        eth_type(0x888e)
-                    ],
-                    actions=[output(ofp.OFPP_CONTROLLER)]
-                )
-            ))
-            stub.UpdateLogicalDeviceFlowTable(FlowTableUpdate(
-                id=logical_device_id,
-                flow_mod=mk_simple_flow_mod(
-                    priority=1000,
-                    match_fields=[
-                        in_port(uni_port_no),
-                        eth_type(0x800),
-                        ip_proto(2)
-                    ],
-                    actions=[output(ofp.OFPP_CONTROLLER)]
-                )
-            ))
-            stub.UpdateLogicalDeviceFlowTable(FlowTableUpdate(
-                id=logical_device_id,
-                flow_mod=mk_simple_flow_mod(
-                    priority=1000,
-                    match_fields=[
-                        in_port(uni_port_no),
-                        eth_type(0x800),
-                        ip_proto(17),
-                        udp_dst(67)
-                    ],
-                    actions=[output(ofp.OFPP_CONTROLLER)]
-                )
-            ))
-        self.poutput('success')
-
-    complete_install_all_controller_bound_flows = \
-        VolthaCli.complete_logical_device
-
-    def do_install_all_sample_flows(self, line):
-        """
-        Install all flows that are representative of the virtualized access
-        scenario in a PON network.
-        """
-        logical_device_id = line or self.default_logical_device_id
-
-        # gather NNI and UNI port IDs
-        nni_port_no, unis = self.get_logical_ports(logical_device_id)
-
-        # construct and push flow rules
-        stub = self.get_stub()
-
-        for uni_port_no, c_vid in unis:
-            # Controller-bound flows
-            stub.UpdateLogicalDeviceFlowTable(FlowTableUpdate(
-                id=logical_device_id,
-                flow_mod=mk_simple_flow_mod(
-                    priority=2000,
-                    match_fields=[in_port(uni_port_no), eth_type(0x888e)],
-                    actions=[
-                        # push_vlan(0x8100),
-                        # set_field(vlan_vid(4096 + 4000)),
-                        output(ofp.OFPP_CONTROLLER)
-                    ]
-                )
-            ))
-            stub.UpdateLogicalDeviceFlowTable(FlowTableUpdate(
-                id=logical_device_id,
-                flow_mod=mk_simple_flow_mod(
-                    priority=1000,
-                    match_fields=[eth_type(0x800), ip_proto(2)],
-                    actions=[output(ofp.OFPP_CONTROLLER)]
-                )
-            ))
-            stub.UpdateLogicalDeviceFlowTable(FlowTableUpdate(
-                id=logical_device_id,
-                flow_mod=mk_simple_flow_mod(
-                    priority=1000,
-                    match_fields=[eth_type(0x800), ip_proto(17), udp_dst(67)],
-                    actions=[output(ofp.OFPP_CONTROLLER)]
-                )
-            ))
-
-            # Unicast flows:
-            # Downstream flow 1
-            stub.UpdateLogicalDeviceFlowTable(FlowTableUpdate(
-                id=logical_device_id,
-                flow_mod=mk_simple_flow_mod(
-                    priority=500,
-                    match_fields=[
-                        in_port(nni_port_no),
-                        vlan_vid(4096 + 1000),
-                        metadata(c_vid)  # here to mimic an ONOS artifact
-                    ],
-                    actions=[pop_vlan()],
-                    next_table_id=1
-                )
-            ))
-            # Downstream flow 2
-            stub.UpdateLogicalDeviceFlowTable(FlowTableUpdate(
-                id=logical_device_id,
-                flow_mod=mk_simple_flow_mod(
-                    priority=500,
-                    table_id=1,
-                    match_fields=[in_port(nni_port_no), vlan_vid(4096 + c_vid)],
-                    actions=[set_field(vlan_vid(4096 + 0)), output(uni_port_no)]
-                )
-            ))
-            # Upstream flow 1 for 0-tagged case
-            stub.UpdateLogicalDeviceFlowTable(FlowTableUpdate(
-                id=logical_device_id,
-                flow_mod=mk_simple_flow_mod(
-                    priority=500,
-                    match_fields=[in_port(uni_port_no), vlan_vid(4096 + 0)],
-                    actions=[set_field(vlan_vid(4096 + c_vid))],
-                    next_table_id=1
-                )
-            ))
-            # Upstream flow 1 for untagged case
-            stub.UpdateLogicalDeviceFlowTable(FlowTableUpdate(
-                id=logical_device_id,
-                flow_mod=mk_simple_flow_mod(
-                    priority=500,
-                    match_fields=[in_port(uni_port_no), vlan_vid(0)],
-                    actions=[push_vlan(0x8100), set_field(vlan_vid(4096 + c_vid))],
-                    next_table_id=1
-                )
-            ))
-            # Upstream flow 2 for s-tag
-            stub.UpdateLogicalDeviceFlowTable(FlowTableUpdate(
-                id=logical_device_id,
-                flow_mod=mk_simple_flow_mod(
-                    priority=500,
-                    table_id=1,
-                    match_fields=[in_port(uni_port_no), vlan_vid(4096 + c_vid)],
-                    actions=[
-                        push_vlan(0x8100),
-                        set_field(vlan_vid(4096 + 1000)),
-                        output(nni_port_no)
-                    ]
-                )
-            ))
-
-        # Push a few multicast flows
-        # 1st with one bucket for our uni 0
-        stub.UpdateLogicalDeviceFlowGroupTable(FlowGroupTableUpdate(
-            id=logical_device_id,
-            group_mod=mk_multicast_group_mod(
-                group_id=1,
-                buckets=[
-                    ofp.ofp_bucket(actions=[
-                        pop_vlan(),
-                        output(unis[0][0])
-                    ])
-                ]
-            )
-        ))
-        stub.UpdateLogicalDeviceFlowTable(FlowTableUpdate(
-            id=logical_device_id,
-            flow_mod=mk_simple_flow_mod(
-                priority=1000,
-                match_fields=[
-                    in_port(nni_port_no),
-                    eth_type(0x800),
-                    vlan_vid(4096 + 140),
-                    ipv4_dst(0xe4010101)
-                ],
-                actions=[group(1)]
-            )
-        ))
-
-        # 2nd with one bucket for uni 0 and 1
-        stub.UpdateLogicalDeviceFlowGroupTable(FlowGroupTableUpdate(
-            id=logical_device_id,
-            group_mod=mk_multicast_group_mod(
-                group_id=2,
-                buckets=[
-                    ofp.ofp_bucket(actions=[pop_vlan(), output(unis[0][0])])
-                    #                    ofp.ofp_bucket(actions=[pop_vlan(), output(unis[1][0])])
-                ]
-            )
-        ))
-        stub.UpdateLogicalDeviceFlowTable(FlowTableUpdate(
-            id=logical_device_id,
-            flow_mod=mk_simple_flow_mod(
-                priority=1000,
-                match_fields=[
-                    in_port(nni_port_no),
-                    eth_type(0x800),
-                    vlan_vid(4096 + 140),
-                    ipv4_dst(0xe4020202)
-                ],
-                actions=[group(2)]
-            )
-        ))
-
-        # 3rd with empty bucket
-        stub.UpdateLogicalDeviceFlowGroupTable(FlowGroupTableUpdate(
-            id=logical_device_id,
-            group_mod=mk_multicast_group_mod(
-                group_id=3,
-                buckets=[]
-            )
-        ))
-        stub.UpdateLogicalDeviceFlowTable(FlowTableUpdate(
-            id=logical_device_id,
-            flow_mod=mk_simple_flow_mod(
-                priority=1000,
-                match_fields=[
-                    in_port(nni_port_no),
-                    eth_type(0x800),
-                    vlan_vid(4096 + 140),
-                    ipv4_dst(0xe4030303)
-                ],
-                actions=[group(3)]
-            )
-        ))
-
-        self.poutput('success')
-
-    complete_install_all_sample_flows = VolthaCli.complete_logical_device
-
-    def do_install_dhcp_flows(self, line):
-        """
-        Install all dhcp flows that are representative of the virtualized access
-        scenario in a PON network.
-        """
-        logical_device_id = line or self.default_logical_device_id
-
-        # gather NNI and UNI port IDs
-        nni_port_no, unis = self.get_logical_ports(logical_device_id)
-
-        # construct and push flow rules
-        stub = self.get_stub()
-
-        # Controller-bound flows
-        for uni_port_no, _ in unis:
-            stub.UpdateLogicalDeviceFlowTable(FlowTableUpdate(
-                id=logical_device_id,
-                flow_mod=mk_simple_flow_mod(
-                    priority=1000,
-                    match_fields=[
-                        in_port(uni_port_no),
-                        eth_type(0x800),
-                        ip_proto(17),
-                        udp_dst(67)
-                    ],
-                    actions=[output(ofp.OFPP_CONTROLLER)]
-                )
-            ))
-
-        self.poutput('success')
-
-    complete_install_dhcp_flows = VolthaCli.complete_logical_device
-
-    def do_delete_all_flows(self, line):
-        """
-        Remove all flows and flow groups from given logical device
-        """
-        logical_device_id = line or self.default_logical_device_id
-        stub = self.get_stub()
-        stub.UpdateLogicalDeviceFlowTable(FlowTableUpdate(
-            id=logical_device_id,
-            flow_mod=ofp.ofp_flow_mod(
-                command=ofp.OFPFC_DELETE,
-                table_id=ofp.OFPTT_ALL,
-                cookie_mask=0,
-                out_port=ofp.OFPP_ANY,
-                out_group=ofp.OFPG_ANY
-            )
-        ))
-        stub.UpdateLogicalDeviceFlowGroupTable(FlowGroupTableUpdate(
-            id=logical_device_id,
-            group_mod=ofp.ofp_group_mod(
-                command=ofp.OFPGC_DELETE,
-                group_id=ofp.OFPG_ALL
-            )
-        ))
-        self.poutput('success')
-
-    complete_delete_all_flows = VolthaCli.complete_logical_device
-
-    def do_send_simulated_upstream_eapol(self, line):
-        """
-        Send an EAPOL upstream from a simulated OLT
-        """
-        device_id = line or self.default_device_id
-        requests.get('http://{}/devices/{}/test_eapol_in'.format(
-            self.voltha_sim_rest, device_id
-        ))
-
-    complete_send_simulated_upstream_eapol = VolthaCli.complete_device
-
-    def do_inject_eapol_start(self, line):
-        """
-        Send out an an EAPOL start message into the given Unix interface
-        """
-        pass
-
-
-if __name__ == '__main__':
-
-    parser = argparse.ArgumentParser()
-
-    _help = '<hostname>:<port> to consul agent (default: %s)' % defs['consul']
-    parser.add_argument(
-        '-C', '--consul', action='store', default=defs['consul'], help=_help)
-
-    _help = 'Lookup Voltha endpoints based on service entries in Consul'
-    parser.add_argument(
-        '-L', '--lookup', action='store_true', help=_help)
-
-    _help = 'All requests to the Voltha gRPC service are global'
-    parser.add_argument(
-        '-G', '--global_request', action='store_true', help=_help)
-
-    _help = '<hostname>:<port> of Voltha gRPC service (default={})'.format(
-        defs['voltha_grpc_endpoint'])
-    parser.add_argument('-g', '--grpc-endpoint', action='store',
-                        default=defs['voltha_grpc_endpoint'], help=_help)
-
-    _help = '<hostname>:<port> of Voltha simulated adapter backend for ' \
-            'testing (default={})'.format(
-        defs['voltha_sim_rest_endpoint'])
-    parser.add_argument('-s', '--sim-rest-endpoint', action='store',
-                        default=defs['voltha_sim_rest_endpoint'], help=_help)
-
-    args = parser.parse_args()
-
-    if args.lookup:
-        host = args.consul.split(':')[0].strip()
-        port = int(args.consul.split(':')[1].strip())
-        consul = Consul(host=host, port=port)
-
-        _, services = consul.catalog.service('voltha-grpc')
-        if not services:
-            print('No voltha-grpc service registered in consul; exiting')
-            sys.exit(1)
-        args.grpc_endpoint = '{}:{}'.format(services[0]['ServiceAddress'],
-                                            services[0]['ServicePort'])
-
-        _, services = consul.catalog.service('voltha-sim-rest')
-        if not services:
-            print('No voltha-sim-rest service registered in consul; exiting')
-            sys.exit(1)
-        args.sim_rest_endpoint = '{}:{}'.format(services[0]['ServiceAddress'],
-                                                services[0]['ServicePort'])
-
-    c = VolthaCli(args.grpc_endpoint, args.sim_rest_endpoint,
-                  args.global_request)
-    c.poutput(banner)
-    c.load_history()
-    c.cmdloop()
-    c.save_history()
diff --git a/python/cli/omci.py b/python/cli/omci.py
deleted file mode 100755
index e1ed4b1..0000000
--- a/python/cli/omci.py
+++ /dev/null
@@ -1,356 +0,0 @@
-#!/usr/bin/env python
-#
-# Copyright 2018 the original author or authors.
-#
-# 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.
-#
-
-"""
-OpenOMCI level CLI commands
-"""
-from optparse import make_option
-from cmd2 import Cmd, options
-from datetime import datetime
-from google.protobuf.empty_pb2 import Empty
-from table import print_pb_list_as_table
-from voltha_protos import voltha_pb2
-from voltha_protos.omci_mib_db_pb2 import MibDeviceData, MibClassData, \
-    MibInstanceData
-from voltha_protos.omci_alarm_db_pb2 import AlarmDeviceData, AlarmClassData, \
-    AlarmInstanceData
-from os import linesep
-
-
-
-class OmciCli(Cmd):
-    CREATED_KEY = 'created'
-    MODIFIED_KEY = 'modified'
-    MDS_KEY = 'mib_data_sync'
-    LAST_SYNC_KEY = 'last_mib_sync'
-    VERSION_KEY = 'version'
-    DEVICE_ID_KEY = 'device_id'
-    CLASS_ID_KEY = 'class_id'
-    INSTANCE_ID_KEY = 'instance_id'
-    ATTRIBUTES_KEY = 'attributes'
-    TIME_FORMAT = '%Y%m%d-%H%M%S.%f'
-    ME_KEY = 'managed_entities'
-    MSG_TYPE_KEY = 'message_types'
-
-    MSG_TYPE_TO_NAME = {
-        4: 'Create',
-        5: 'Create Complete',
-        6: 'Delete',
-        8: 'Set',
-        9: 'Get',
-        10: 'Get Complete',
-        11: 'Get All Alarms',
-        12: 'Get All Alarms Next',
-        13: 'Mib Upload',
-        14: 'Mib Upload Next',
-        15: 'Mib Reset',
-        16: 'Alarm Notification',
-        17: 'Attribute Value Change',
-        18: 'Test',
-        19: 'Start Software Download',
-        20: 'Download Section',
-        21: 'End Software Download',
-        22: 'Activate Software',
-        23: 'Commit Software',
-        24: 'Synchronize Time',
-        25: 'Reboot',
-        26: 'Get Next',
-        27: 'Test Result',
-        28: 'Get Current Data',
-        29: 'Set Table'
-    }
-
-    def __init__(self, device_id, get_stub):
-        Cmd.__init__(self)
-        self.get_stub = get_stub
-        self.device_id = device_id
-        self.prompt = '(' + self.colorize(
-            self.colorize('omci {}'.format(device_id), 'green'),
-            'bold') + ') '
-
-    def cmdloop(self, intro=None):
-        self._cmdloop()
-
-    do_exit = Cmd.do_quit
-
-    def do_quit(self, line):
-        return self._STOP_AND_EXIT
-
-    def get_device_mib(self, device_id, depth=-1):
-        stub = self.get_stub()
-
-        try:
-            res = stub.GetMibDeviceData(voltha_pb2.ID(id=device_id),
-                                        metadata=(('get-depth', str(depth)), ))
-        except Exception as e:
-            pass
-
-        return res
-
-    def help_show_mib(self):
-        self.poutput('show_mib [-d <device-id>] [-c <class-id> [-i <instance-id>]]' +
-                     linesep + '-d: <device-id>   ONU Device ID' +
-                     linesep + '-c: <class-id>    Managed Entity Class ID' +
-                     linesep + '-i: <instance-id> ME Instance ID')
-
-    @options([
-        make_option('-d', '--device-id', action="store", dest='device_id', type='string',
-                    help='ONU Device ID', default=None),
-        make_option('-c', '--class-id', action="store", dest='class_id',
-                    type='int', help='Managed Entity Class ID', default=None),
-        make_option('-i', '--instance-id', action="store", dest='instance_id',
-                    type='int', help='ME Instance ID', default=None)
-    ])
-    def do_show_mib(self, _line, opts):
-        """
-        Show OMCI MIB Database Information
-        """
-        device_id = opts.device_id or self.device_id
-
-        if opts.class_id is not None and not 1 <= opts.class_id <= 0xFFFF:
-            self.poutput(self.colorize('Error: ', 'red') +
-                         self.colorize('Class ID must be 1..65535', 'blue'))
-            return
-
-        if opts.instance_id is not None and opts.class_id is None:
-            self.poutput(self.colorize('Error: ', 'red') +
-                         self.colorize('Class ID required if specifying an Instance ID',
-                                       'blue'))
-            return
-
-        if opts.instance_id is not None and not 0 <= opts.instance_id <= 0xFFFF:
-            self.poutput(self.colorize('Error: ', 'red') +
-                         self.colorize('Instance ID must be 0..65535', 'blue'))
-            return
-
-        try:
-            mib_db = self.get_device_mib(device_id, depth=-1)
-
-        except Exception:   # UnboundLocalError if Device ID not found in DB
-            self.poutput(self.colorize('Failed to get MIB database for ONU {}'
-                                       .format(device_id), 'red'))
-            return
-
-        mib = self._device_to_dict(mib_db)
-
-        self.poutput('OpenOMCI MIB Database for ONU {}'.format(device_id))
-
-        if opts.class_id is None and opts.instance_id is None:
-            self.poutput('Version            : {}'.format(mib[OmciCli.VERSION_KEY]))
-            self.poutput('Created            : {}'.format(mib[OmciCli.CREATED_KEY]))
-            self.poutput('Last In-Sync Time  : {}'.format(mib[OmciCli.LAST_SYNC_KEY]))
-            self.poutput('MIB Data Sync Value: {}'.format(mib[OmciCli.MDS_KEY]))
-
-        class_ids = [k for k in mib.iterkeys()
-                     if isinstance(k, int) and
-                     (opts.class_id is None or opts.class_id == k)]
-        class_ids.sort()
-
-        if len(class_ids) == 0 and opts.class_id is not None:
-            self.poutput(self.colorize('Class ID {} not found in MIB Database'
-                                       .format(opts.class_id), 'red'))
-            return
-
-        for cls_id in class_ids:
-            class_data = mib[cls_id]
-            self.poutput('  ----------------------------------------------')
-            self.poutput('  Class ID: {0} - ({0:#x})'.format(cls_id))
-
-            inst_ids = [k for k in class_data.iterkeys()
-                        if isinstance(k, int) and
-                        (opts.instance_id is None or opts.instance_id == k)]
-            inst_ids.sort()
-
-            if len(inst_ids) == 0 and opts.instance_id is not None:
-                self.poutput(self.colorize('Instance ID {} of Class ID {} not ' +
-                                           'found in MIB Database'.
-                                           format(opts.instance_id, opts.class_id),
-                                           'red'))
-                return
-
-            for inst_id in inst_ids:
-                inst_data = class_data[inst_id]
-                self.poutput('    Instance ID: {0} - ({0:#x})'.format(inst_id))
-                self.poutput('    Created    : {}'.format(inst_data[OmciCli.CREATED_KEY]))
-                self.poutput('    Modified   : {}'.format(inst_data[OmciCli.MODIFIED_KEY]))
-
-                attributes = inst_data[OmciCli.ATTRIBUTES_KEY]
-                attr_names = attributes.keys()
-                attr_names.sort()
-                max_len = max([len(attr) for attr in attr_names])
-
-                for attr in attr_names:
-                    name = self._cleanup_attribute_name(attr).ljust(max_len)
-                    value = attributes[attr]
-                    try:
-                        ivalue = int(value)
-                        self.poutput('      {0}: {1} - ({1:#x})'.format(name, ivalue))
-
-                    except ValueError:
-                        self.poutput('      {}: {}'.format(name, value))
-
-                if inst_id is not inst_ids[-1]:
-                    self.poutput(linesep)
-
-    def _cleanup_attribute_name(self, attr):
-        """Change underscore to space and capitalize first character"""
-        return ' '.join([v[0].upper() + v[1:] for v in attr.split('_')])
-
-    def _instance_to_dict(self, instance):
-        if not isinstance(instance, (MibInstanceData, AlarmInstanceData)):
-            raise TypeError('{} is not of type MIB/Alarm Instance Data'.format(type(instance)))
-
-        data = {
-            OmciCli.INSTANCE_ID_KEY: instance.instance_id,
-            OmciCli.CREATED_KEY: self._string_to_time(instance.created),
-            OmciCli.MODIFIED_KEY: self._string_to_time(instance.modified),
-            OmciCli.ATTRIBUTES_KEY: dict()
-        }
-        for attribute in instance.attributes:
-            data[OmciCli.ATTRIBUTES_KEY][attribute.name] = str(attribute.value)
-
-        return data
-
-    def _class_to_dict(self, val):
-        if not isinstance(val, (MibClassData, AlarmClassData)):
-            raise TypeError('{} is not of type MIB/Alarm Class Data'.format(type(val)))
-
-        data = {
-            OmciCli.CLASS_ID_KEY: val.class_id,
-        }
-        for instance in val.instances:
-            data[instance.instance_id] = self._instance_to_dict(instance)
-        return data
-
-    def _device_to_dict(self, val):
-        if not isinstance(val, MibDeviceData):
-            raise TypeError('{} is not of type MibDeviceData'.format(type(val)))
-
-        data = {
-            OmciCli.DEVICE_ID_KEY: val.device_id,
-            OmciCli.CREATED_KEY: self._string_to_time(val.created),
-            OmciCli.LAST_SYNC_KEY: self._string_to_time(val.last_sync_time),
-            OmciCli.MDS_KEY: val.mib_data_sync,
-            OmciCli.VERSION_KEY: val.version,
-            OmciCli.ME_KEY: dict(),
-            OmciCli.MSG_TYPE_KEY: set()
-        }
-        for class_data in val.classes:
-            data[class_data.class_id] = self._class_to_dict(class_data)
-
-        for managed_entity in val.managed_entities:
-            data[OmciCli.ME_KEY][managed_entity.class_id] = managed_entity.name
-
-        for msg_type in val.message_types:
-            data[OmciCli.MSG_TYPE_KEY].add(msg_type.message_type)
-
-        return data
-
-    def _string_to_time(self, time):
-        return datetime.strptime(time, OmciCli.TIME_FORMAT) if len(time) else None
-
-    def help_show_me(self):
-        self.poutput('show_me [-d <device-id>]' +
-                     linesep + '-d: <device-id>   ONU Device ID')
-
-    @options([
-        make_option('-d', '--device-id', action="store", dest='device_id', type='string',
-                    help='ONU Device ID', default=None),
-    ])
-    def do_show_me(self, _line, opts):
-        """ Show supported OMCI Managed Entities"""
-
-        device_id = opts.device_id or self.device_id
-
-        try:
-            mib_db = self.get_device_mib(device_id, depth=1)
-            mib = self._device_to_dict(mib_db)
-
-        except Exception:   # UnboundLocalError if Device ID not found in DB
-            self.poutput(self.colorize('Failed to get supported ME information for ONU {}'
-                                       .format(device_id), 'red'))
-            return
-
-        class_ids = [class_id for class_id in mib[OmciCli.ME_KEY].keys()]
-        class_ids.sort()
-
-        self.poutput('Supported Managed Entities for ONU {}'.format(device_id))
-        for class_id in class_ids:
-            self.poutput('    {0} - ({0:#x}): {1}'.format(class_id,
-                                                          mib[OmciCli.ME_KEY][class_id]))
-
-    def help_show_msg_types(self):
-        self.poutput('show_msg_types [-d <device-id>]' +
-                     linesep + '-d: <device-id>   ONU Device ID')
-
-    @options([
-        make_option('-d', '--device-id', action="store", dest='device_id', type='string',
-                    help='ONU Device ID', default=None),
-    ])
-    def do_show_msg_types(self, _line, opts):
-        """ Show supported OMCI Message Types"""
-        device_id = opts.device_id or self.device_id
-
-        try:
-            mib_db = self.get_device_mib(device_id, depth=1)
-            mib = self._device_to_dict(mib_db)
-
-        except Exception:   # UnboundLocalError if Device ID not found in DB
-            self.poutput(self.colorize('Failed to get supported Message Types for ONU {}'
-                                       .format(device_id), 'red'))
-            return
-
-        msg_types = [msg_type for msg_type in mib[OmciCli.MSG_TYPE_KEY]]
-        msg_types.sort()
-
-        self.poutput('Supported Message Types for ONU {}'.format(device_id))
-        for msg_type in msg_types:
-            self.poutput('    {0} - ({0:#x}): {1}'.
-                         format(msg_type,
-                                OmciCli.MSG_TYPE_TO_NAME.get(msg_type, 'Unknown')))
-
-    def get_devices(self):
-        stub = self.get_stub()
-        res = stub.ListDevices(Empty())
-        return res.items
-
-    def do_devices(self, line):
-        """List devices registered in Voltha reduced for OMCI menu"""
-        devices = self.get_devices()
-        omit_fields = {
-            'adapter',
-            'model',
-            'hardware_version',
-            'images',
-            'firmware_version',
-            'serial_number',
-            'vlan',
-            'root',
-            'extra_args',
-            'proxy_address',
-        }
-        print_pb_list_as_table('Devices:', devices, omit_fields, self.poutput)
-
-    def help_devices(self):
-        self.poutput('TODO: Provide some help')
-
-    def poutput(self, msg):
-        """Convenient shortcut for self.stdout.write(); adds newline if necessary."""
-        if msg:
-            self.stdout.write(msg)
-            if msg[-1] != '\n':
-                self.stdout.write('\n')
diff --git a/python/cli/setup.sh b/python/cli/setup.sh
deleted file mode 100755
index 6cab0bf..0000000
--- a/python/cli/setup.sh
+++ /dev/null
@@ -1,43 +0,0 @@
-#!/bin/bash
-# Copyright 2017-present Open Networking Foundation
-#
-# 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.
-
-while getopts LGC:g:s: option
-do
-    case "${option}"
-    in
-	L) LOOKUP_OPT="-L";;
-	G) GLOBAL_REQUEST_OPT="-G";;
-	C) CONSUL_OPT="-C ${OPTARG}";;
-	g) GRPC_OPT="-g ${OPTARG}";;
-	s) SIM_OPT="-s ${OPTARG}";;
-    esac
-done
-
-if [ -z "$CONSUL_OPT" ]
-then
-    CONSUL_OPT="-C $DOCKER_HOST_IP:8500"
-fi
-
-echo "export DOCKER_HOST_IP=$DOCKER_HOST_IP" > /home/voltha/.bashrc
-echo "export PYTHONPATH=/voltha" >> /home/voltha/.bashrc
-echo "export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" >> /home/voltha/.bashrc
-echo "export DOCKER_HOST_IP=$DOCKER_HOST_IP" > /home/voltha/.bash_profile
-echo "export PYTHONPATH=/voltha" >> /home/voltha/.bash_profile
-echo "export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" >> /home/voltha/.bash_profile
-echo "/voltha/python/cli/main.py $LOOKUP_OPT $GLOBAL_REQUEST_OPT $CONSUL_OPT $GRPC_OPT $SIM_OPT" >> /home/voltha/.bash_profile
-echo "logout" >> /home/voltha/.bash_profile
-chown voltha.voltha /home/voltha/.bash_profile
-/usr/sbin/sshd -D
-
diff --git a/python/cli/table.py b/python/cli/table.py
deleted file mode 100644
index 7e6a4d8..0000000
--- a/python/cli/table.py
+++ /dev/null
@@ -1,204 +0,0 @@
-#
-# Copyright 2016 the original author or authors.
-#
-# 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.
-#
-import sys
-
-from google.protobuf.message import Message
-from termcolor import colored
-
-_printfn = lambda l: sys.stdout.write(l + '\n')
-
-
-class TablePrinter(object):
-    """Simple tabular data printer utility. For usage, see bottom of file"""
-
-    def __init__(self):
-        self.max_field_lengths = {}
-        self.field_names = {}
-        self.cell_values = {}
-
-    def add_cell(self, row_number, field_key, field_name, value):
-        if not isinstance(value, str):
-            value = str(value)
-        self._add_field_type(field_key, field_name)
-        row = self.cell_values.setdefault(row_number, {})
-        row[field_key] = value
-        self._update_max_length(field_key, value)
-
-    def number_of_rows(self):
-        return len(self.cell_values)
-
-    def print_table(self, header=None, printfn=_printfn, dividers=10):
-
-        if header is not None:
-            printfn(header)
-
-        field_keys = sorted(self.field_names.keys())
-
-        if not field_keys:
-            printfn('table empty')
-            return
-
-        def p_sep():
-            printfn('+' + '+'.join(
-                [(self.max_field_lengths[k] + 2) * '-'
-                 for k in field_keys]) + '+')
-
-        p_sep()
-
-        printfn('| ' + ' | '.join(
-            '%%%ds' % self.max_field_lengths[k] % self.field_names[k]
-            for k in field_keys) + ' |')
-        p_sep()
-
-        for i in range(len(self.cell_values)):
-            row = self.cell_values[i]
-            printfn(colored('| ' + ' | '.join(
-                '%%%ds' % self.max_field_lengths[k] % row.get(k, '')
-                for k in field_keys
-            ) + ' |'))
-            if not ((i + 1) % dividers):
-                p_sep()
-
-        if (i + 1) % dividers:
-            p_sep()
-
-    def _update_max_length(self, field_key, string):
-        length = len(string)
-        if length > self.max_field_lengths.get(field_key, 0):
-            self.max_field_lengths[field_key] = length
-
-    def _add_field_type(self, field_key, field_name):
-        if field_key not in self.field_names:
-            self.field_names[field_key] = field_name
-            self._update_max_length(field_key, field_name)
-        else:
-            assert self.field_names[field_key] == field_name
-
-
-def print_pb_list_as_table(header, items, fields_to_omit=None,
-                           printfn=_printfn, dividers=10, show_nulls=False,
-                           presfns={}):
-    from utils import pb2dict
-
-    t = TablePrinter()
-    for row, obj in enumerate(items):
-        assert isinstance(obj, Message)
-
-        def set_row(pd_dict, _row, field, value, t, prefix,
-                      fields_to_omit, number):
-            fname = prefix + field.name
-            if fname in fields_to_omit:
-                return
-            if isinstance(value, Message):
-                add(_row, value, fname + '.',
-                    100 * (number + field.number))
-            else:
-                presentationfn = presfns[fname] if fname in presfns else lambda x: x
-                t.add_cell(_row, number + field.number, fname,
-                           presentationfn(pd_dict.get(field.name)))
-
-        def add(_row, pb, prefix='', number=0):
-            d = pb2dict(pb)
-            if show_nulls:
-                fields = pb.DESCRIPTOR.fields
-                for field in fields:
-                    set_row(d,
-                            _row,
-                            field,
-                            getattr(pb, field.name),
-                            t,
-                            prefix,
-                            fields_to_omit,
-                            number)
-            else:
-                fields = pb.ListFields()
-                for (field, value) in fields:
-                    set_row(d,
-                            _row,
-                            field,
-                            value,
-                            t,
-                            prefix,
-                            fields_to_omit,
-                            number)
-        add(row, obj)
-
-    t.print_table(header, printfn, dividers)
-
-
-def print_pb_as_table(header, pb, fields_to_omit={}, printfn=_printfn,
-                      show_nulls=False):
-
-    from utils import pb2dict
-
-    def is_repeated_item(msg):
-        return hasattr(msg, "extend")
-
-    def set_cell(pb, field, value, t, prefix, fields_to_omit):
-        d = pb2dict(pb)
-        fname = prefix + field.name
-
-        if fname in fields_to_omit:
-            return
-        if isinstance(value, Message):
-            pr(value, fname + '.')
-        elif is_repeated_item(value): # handles any list
-            row = t.number_of_rows()
-            t.add_cell(row, 0, 'field', fname)
-            t.add_cell(row, 1, 'value',
-                       '{} item(s)'.format(len(d.get(field.name))))
-        else:
-            row = t.number_of_rows()
-            t.add_cell(row, 0, 'field', fname)
-            t.add_cell(row, 1, 'value', value)
-
-
-    t = TablePrinter()
-
-    def pr(_pb, prefix=''):
-        if show_nulls:
-            fields = _pb.DESCRIPTOR.fields
-            for field in sorted(fields, key=lambda f: f.number):
-                set_cell(_pb,
-                        field,
-                        getattr(_pb, field.name),
-                        t,
-                        prefix,
-                        fields_to_omit)
-        else:
-            fields = _pb.ListFields()
-            for (field, value) in sorted(fields, key=lambda (f, v): f.number):
-                set_cell(_pb,
-                        field,
-                        value,
-                        t,
-                        prefix,
-                        fields_to_omit)
-
-    pr(pb)
-
-    t.print_table(header, printfn)
-
-
-if __name__ == '__main__':
-    import random
-
-    t = TablePrinter()
-    for row in range(10):
-        t.add_cell(row, 0, 'id', row + 100)
-        t.add_cell(row, 1, 'name', 'Joe Somebody')
-        t.add_cell(row, 2, 'ows', '${}'.format(random.randint(10, 100000)))
-    t.print_table()
diff --git a/python/cli/utils.py b/python/cli/utils.py
deleted file mode 100644
index 7668b7c..0000000
--- a/python/cli/utils.py
+++ /dev/null
@@ -1,213 +0,0 @@
-#
-# Copyright 2016 the original author or authors.
-#
-# 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.
-#
-
-import sys
-
-from google.protobuf.json_format import MessageToDict
-from termcolor import cprint, colored
-
-from table import TablePrinter
-
-
-_printfn = lambda l: sys.stdout.write(l + '\n')
-
-
-def pb2dict(pb_msg):
-    d = MessageToDict(pb_msg, including_default_value_fields=1,
-                      preserving_proto_field_name=1)
-    return d
-
-
-def p_cookie(cookie):
-    cookie =  '%x' % int(cookie)
-    if len(cookie) > 8:
-        return '~' + cookie[len(cookie)-8:]
-    else:
-        return cookie
-
-'''
-    OFPP_NORMAL     = 0x7ffffffa;  /* Forward using non-OpenFlow pipeline. */
-    OFPP_FLOOD      = 0x7ffffffb;  /* Flood using non-OpenFlow pipeline. */
-    OFPP_ALL        = 0x7ffffffc;  /* All standard ports except input port. */
-    OFPP_CONTROLLER = 0x7ffffffd;  /* Send to controller. */
-    OFPP_LOCAL      = 0x7ffffffe;  /* Local openflow "port". */
-    OFPP_ANY        = 0x7fffffff;  /* Special value used in some requests when
-'''
-
-
-def p_port(port):
-    if port & 0x7fffffff == 0x7ffffffa:
-        return 'NORMAL'
-    elif port & 0x7fffffff == 0x7ffffffb:
-        return 'FLOOD'
-    elif port & 0x7fffffff == 0x7ffffffc:
-        return 'ALL'
-    elif port & 0x7fffffff == 0x7ffffffd:
-        return 'CONTROLLER'
-    elif port & 0x7fffffff == 0x7ffffffe:
-        return 'LOCAL'
-    elif port & 0x7fffffff == 0x7fffffff:
-        return 'ANY'
-    else:
-        return str(port)
-
-
-def p_vlan_vid(vlan_vid):
-    if vlan_vid == 0:
-        return 'untagged'
-    assert vlan_vid & 4096 == 4096
-    return str(vlan_vid - 4096)
-
-
-def p_ipv4(x):
-    return '.'.join(str(v) for v in [
-        (x >> 24) & 0xff, (x >> 16) & 0xff, (x >> 8) & 0xff, x & 0xff
-    ])
-
-
-field_printers = {
-    'IN_PORT': lambda f: (100, 'in_port', p_port(f['port'])),
-    'VLAN_VID': lambda f: (101, 'vlan_vid', p_vlan_vid(f['vlan_vid'])),
-    'VLAN_PCP': lambda f: (102, 'vlan_pcp', str(f['vlan_pcp'])),
-    'ETH_TYPE': lambda f: (103, 'eth_type', '%X' % f['eth_type']),
-    'IP_PROTO': lambda f: (104, 'ip_proto', str(f['ip_proto'])),
-    'IPV4_DST': lambda f: (105, 'ipv4_dst', p_ipv4(f['ipv4_dst'])),
-    'UDP_SRC': lambda f: (106, 'udp_src', str(f['udp_src'])),
-    'UDP_DST': lambda f: (107, 'udp_dst', str(f['udp_dst'])),
-    'TCP_SRC': lambda f: (108, 'tcp_src', str(f['tcp_src'])),
-    'TCP_DST': lambda f: (109, 'tcp_dst', str(f['tcp_dst'])),
-    'METADATA': lambda f: (110, 'metadata', str(f['table_metadata'])),
-    'TUNNEL_ID': lambda f: (111, 'tunnel_id', str(f['tunnel_id'])),
-}
-
-
-def p_field(field):
-    assert field['oxm_class'].endswith('OPENFLOW_BASIC')
-    ofb = field['ofb_field']
-    assert not ofb['has_mask']
-    type = ofb['type'][len('OFPXMT_OFB_'):]
-    weight, field_name, value = field_printers[type](ofb)
-    return 1000 + weight, 'set_' + field_name, value
-
-
-action_printers = {
-    'SET_FIELD': lambda a: p_field(a['set_field']['field']),
-    'POP_VLAN': lambda a: (2000, 'pop_vlan', 'Yes'),
-    'PUSH_VLAN': lambda a: (2001, 'push_vlan', '%x' % a['push']['ethertype']),
-    'GROUP': lambda a: (3000, 'group', p_port(a['group']['group_id'])),
-    'OUTPUT': lambda a: (4000, 'output', p_port(a['output']['port'])),
-}
-
-
-def print_flows(what, id, type, flows, groups, printfn=_printfn):
-
-    header = ''.join([
-        '{} '.format(what),
-        colored(id, color='green', attrs=['bold']),
-        ' (type: ',
-        colored(type, color='blue'),
-        ')'
-    ]) + '\nFlows ({}):'.format(len(flows))
-
-    table = TablePrinter()
-    for i, flow in enumerate(flows):
-
-        table.add_cell(i, 0, 'table_id', value=str(flow['table_id']))
-        table.add_cell(i, 1, 'priority', value=str(flow['priority']))
-        table.add_cell(i, 2, 'cookie', p_cookie(flow['cookie']))
-
-        assert flow['match']['type'] == 'OFPMT_OXM'
-        for field in flow['match']['oxm_fields']:
-            assert field['oxm_class'].endswith('OPENFLOW_BASIC')
-            ofb = field['ofb_field']
-            # see CORD-816 (https://jira.opencord.org/browse/CORD-816)
-            assert not ofb['has_mask'], 'masked match not handled yet'
-            type = ofb['type'][len('OFPXMT_OFB_'):]
-            table.add_cell(i, *field_printers[type](ofb))
-
-        for instruction in flow['instructions']:
-            itype = instruction['type']
-            if itype == 4 or itype == 3:
-                for action in instruction['actions']['actions']:
-                    atype = action['type'][len('OFPAT_'):]
-                    table.add_cell(i, *action_printers[atype](action))
-            elif itype == 1:
-                table.add_cell(i, 10000, 'goto-table',
-                               instruction['goto_table']['table_id'])
-            elif itype == 2:
-                table.add_cell(i, 10001, 'write-metadata',
-                               instruction['write_metadata']['metadata'])
-            elif itype == 5:
-                table.add_cell(i, 10002, 'clear-actions', [])
-            elif itype == 6:
-                table.add_cell(i, 10003, 'meter',
-                               instruction['meter']['meter_id'])
-            else:
-                raise NotImplementedError(
-                    'not handling instruction type {}'.format(itype))
-
-    table.print_table(header, printfn)
-
-
-def print_groups(what, id, type, groups, printfn=_printfn):
-    header = ''.join([
-        '{} '.format(what),
-        colored(id, color='green', attrs=['bold']),
-        ' (type: ',
-        colored(type, color='blue'),
-        ')'
-    ]) + '\nGroups ({}):'.format(len(groups))
-
-    table = TablePrinter()
-    for i, group in enumerate(groups):
-        output_ports = []
-        for bucket in group['desc']['buckets']:
-            for action in bucket['actions']:
-                if action['type'] == 'OFPAT_OUTPUT':
-                   output_ports.append(action['output']['port'])
-        table.add_cell(i, 0, 'group_id', value=str(group['desc']['group_id']))
-        table.add_cell(i, 1, 'buckets', value=str(dict(output=output_ports)))
-
-    table.print_table(header, printfn)
-
-def print_meters(what, id, type, meters, printfn=_printfn):
-    header = ''.join([
-        '{} '.format(what),
-        colored(id, color='green', attrs=['bold']),
-        ' (type: ',
-        colored(type, color='blue'),
-        ')'
-    ]) + '\nMeters ({}):'.format(len(meters))
-
-    table = TablePrinter()
-    for i, meter in enumerate(meters):
-        bands = []
-        for meter_band in meter['config']['bands']:
-            bands.append(meter_band)
-        table.add_cell(i, 0, 'meter_id', value=str(meter['config']['meter_id']))
-        table.add_cell(i, 1, 'meter_bands', value=str(dict(bands=bands)))
-
-    table.print_table(header, printfn)
-
-
-def dict2line(d):
-    assert isinstance(d, dict)
-    return ', '.join('{}: {}'.format(k, v) for k, v in sorted(d.items()))
-
-def enum2name(msg_obj, enum_type, enum_value):
-    descriptor = msg_obj.DESCRIPTOR.enum_types_by_name[enum_type]
-    name = descriptor.values_by_number[enum_value].name
-    return name
diff --git a/python/docker/Dockerfile.cli b/python/docker/Dockerfile.cli
deleted file mode 100644
index b00420a..0000000
--- a/python/docker/Dockerfile.cli
+++ /dev/null
@@ -1,80 +0,0 @@
-# Copyright 2016 the original author or authors.
-#
-# 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.
-FROM voltha/voltha-python-base:1.0.0
-
-# Update to have latest images
-RUN apt-get update && \
-    apt-get install -y --no-install-recommends \
-	openssh-server=1:7.2p2-4ubuntu2.8 \
-        && apt-get clean && rm -rf /var/lib/apt/lists/*
-
-# Install adapter requirements.
-COPY requirements.txt /tmp/requirements.txt
-RUN pip install -r /tmp/requirements.txt
-
-ARG LOCAL_PYVOLTHA
-ARG LOCAL_PROTOS
-COPY local_imports/ /local_imports/
-RUN if [ -n "$LOCAL_PYVOLTHA" ] ; then \
-    PYVOLTHA_PATH=$(ls /local_imports/pyvoltha/dist/) ; \
-    printf "/local_imports/pyvoltha/dist/%s\npyvoltha" "$PYVOLTHA_PATH" > pyvoltha-install.txt ; \
-    pip install -r pyvoltha-install.txt ; \
-fi
-
-RUN if [ -n "$LOCAL_PROTOS" ] ; then \
-    PROTOS_PATH=$(ls /local_imports/voltha-protos/dist/) ; \
-    printf "/local_imports/voltha-protos/dist/%s\nvoltha-protos" "$PROTOS_PATH" > protos-install.txt ; \
-    pip install -r protos-install.txt ; \
- fi
-# Bundle app source
-RUN mkdir /voltha && touch /voltha/__init__.py
-ENV PYTHONPATH=/voltha
-COPY cli /voltha/python/cli
-RUN touch /voltha/python/__init__.py
-RUN touch /voltha/python/cli/__init__.py
-
-# Setup the voltha user
-SHELL ["/bin/bash", "-o", "pipefail", "-c"]
-RUN useradd -b /home -d /home/voltha voltha -s /bin/bash
-RUN mkdir /home/voltha
-RUN chown voltha.voltha /home/voltha
-RUN echo "voltha:admin" | chpasswd
-RUN mkdir /var/run/sshd
-RUN echo 'root:screencast' | chpasswd
-RUN sed -i 's/PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config
-
-# SSH login fix. Otherwise user is kicked off after login
-RUN sed 's@session\s*required\s*pam_loginuid.so@session optional pam_loginuid.so@g' -i /etc/pam.d/sshd
-
-ENV NOTVISIBLE "in users profile"
-RUN echo "export VISIBLE=now" >> /etc/profile
-
-EXPOSE 22
-
-CMD ["/voltha/python/cli/setup.sh"]
-
-# Label image
-ARG org_label_schema_version=unknown
-ARG org_label_schema_vcs_url=unknown
-ARG org_label_schema_vcs_ref=unknown
-ARG org_label_schema_build_date=unknown
-ARG org_opencord_vcs_commit_date=unknown
-
-LABEL org.label-schema.schema-version=1.0 \
-      org.label-schema.name=voltha-cli \
-      org.label-schema.version=$org_label_schema_version \
-      org.label-schema.vcs-url=$org_label_schema_vcs_url \
-      org.label-schema.vcs-ref=$org_label_schema_vcs_ref \
-      org.label-schema.build-date=$org_label_schema_build_date \
-      org.opencord.vcs-commit-date=$org_opencord_vcs_commit_date
diff --git a/python/docker/Dockerfile.ofagent b/python/docker/Dockerfile.ofagent
deleted file mode 100644
index 73e8789..0000000
--- a/python/docker/Dockerfile.ofagent
+++ /dev/null
@@ -1,56 +0,0 @@
-# Copyright 2016 the original author or authors.
-#
-# 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.
-FROM voltha/voltha-python-base:1.0.0
-
-# Install adapter requirements.
-COPY requirements.txt /tmp/requirements.txt
-RUN pip install -r /tmp/requirements.txt
-
-ARG LOCAL_PYVOLTHA
-ARG LOCAL_PROTOS
-COPY local_imports/ /local_imports/
-RUN if [ -n "$LOCAL_PYVOLTHA" ] ; then \
-    PYVOLTHA_PATH=$(ls /local_imports/pyvoltha/dist/) ; \
-    printf "/local_imports/pyvoltha/dist/%s\npyvoltha" "$PYVOLTHA_PATH" > pyvoltha-install.txt ; \
-    pip install -r pyvoltha-install.txt ; \
-fi
-
-RUN if [ -n "$LOCAL_PROTOS" ] ; then \
-    PROTOS_PATH=$(ls /local_imports/voltha-protos/dist/) ; \
-    printf "/local_imports/voltha-protos/dist/%s\nvoltha-protos" "$PROTOS_PATH" > protos-install.txt ; \
-    pip install -r protos-install.txt ; \
- fi
-
-# Bundle app source
-RUN mkdir /ofagent  && \
-        touch   /ofagent/__init__.py
-
-ENV PYTHONPATH=/ofagent
-COPY ofagent /ofagent/ofagent
-COPY pki /ofagent/pki
-
-# Label image
-ARG org_label_schema_version=unknown
-ARG org_label_schema_vcs_url=unknown
-ARG org_label_schema_vcs_ref=unknown
-ARG org_label_schema_build_date=unknown
-ARG org_opencord_vcs_commit_date=unknown
-
-LABEL org.label-schema.schema-version=1.0 \
-      org.label-schema.name=voltha-ofagent \
-      org.label-schema.version=$org_label_schema_version \
-      org.label-schema.vcs-url=$org_label_schema_vcs_url \
-      org.label-schema.vcs-ref=$org_label_schema_vcs_ref \
-      org.label-schema.build-date=$org_label_schema_build_date \
-      org.opencord.vcs-commit-date=$org_opencord_vcs_commit_date
diff --git a/python/env.sh b/python/env.sh
deleted file mode 100644
index c9a6245..0000000
--- a/python/env.sh
+++ /dev/null
@@ -1,22 +0,0 @@
-# Copyright 2017-present Open Networking Foundation
-#
-# 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.
-# sourcing this file is needed to make local development and integration testing work
-
-# load local python virtualenv if exists
-VENVDIR="venv-volthago"
-if [ -e "$VENVDIR/bin/activate" ]; then
-    . $VENVDIR/bin/activate
-else
-   echo "Run 'make venv' to setup python development environment"
-fi
diff --git a/python/ofagent/__init__.py b/python/ofagent/__init__.py
deleted file mode 100755
index b0fb0b2..0000000
--- a/python/ofagent/__init__.py
+++ /dev/null
@@ -1,13 +0,0 @@
-# Copyright 2017-present Open Networking Foundation
-#
-# 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.
diff --git a/python/ofagent/agent.py b/python/ofagent/agent.py
deleted file mode 100755
index e4d415d..0000000
--- a/python/ofagent/agent.py
+++ /dev/null
@@ -1,205 +0,0 @@
-#
-# Copyright 2017 the original author or authors.
-#
-# 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.
-#
-
-import sys
-
-import structlog
-import os.path
-from twisted.internet import protocol, reactor, ssl
-from twisted.internet.defer import Deferred, inlineCallbacks
-
-import loxi.of13 as of13
-from pyvoltha.common.utils.asleep import asleep
-from of_connection import OpenFlowConnection
-from of_protocol_handler import OpenFlowProtocolHandler
-
-log = structlog.get_logger()
-
-
-class Agent(protocol.ClientFactory):
-
-    generation_is_defined = False
-    cached_generation_id = None
-
-    def __init__(self,
-                 connection_manager,
-                 controller_endpoint,
-                 datapath_id,
-                 device_id,
-                 enable_tls=False,
-                 key_file=None,
-                 cert_file=None,
-                 conn_retry_interval=1):
-
-        self.controller_endpoint = controller_endpoint
-        self.datapath_id = datapath_id
-        self.device_id = device_id
-        self.connection_manager = connection_manager
-        self.enable_tls = enable_tls
-        self.key_file = key_file
-        self.cert_file = cert_file
-        self.retry_interval = conn_retry_interval
-
-        self.running = False
-        self.connector = None # will be a Connector instance once connected
-        self.d_disconnected = None  # a deferred to signal reconnect loop when
-                                    # TCP connection is lost
-        self.connected = False
-        self.exiting = False
-        self.proto_handler = None
-
-    def get_device_id(self):
-        return self.device_id
-
-    def start(self):
-        log.debug('starting')
-        if self.running:
-            return
-        self.running = True
-        reactor.callLater(0, self.keep_connected)
-        log.info('started')
-        return self
-
-    def stop(self):
-        log.debug('stopping')
-        self.connected = False
-        self.exiting = True
-        self.connector.disconnect()
-        log.info('stopped')
-
-    def resolve_endpoint(self, endpoint):
-        # enable optional resolution via consul;
-        # see https://jira.opencord.org/browse/CORD-820
-        host, port = endpoint.split(':', 2)
-        return host, int(port)
-
-    @inlineCallbacks
-    def keep_connected(self):
-        """Keep reconnecting to the controller"""
-        while not self.exiting:
-            host, port = self.resolve_endpoint(self.controller_endpoint)
-            log.info('connecting', host=host, port=port)
-            if self.enable_tls:
-                try:
-                    # Check that key_file and cert_file is provided and
-                    # the files exist
-                    if self.key_file is None or             \
-                       self.cert_file is None or            \
-                       not os.path.isfile(self.key_file) or \
-                       not os.path.isfile(self.cert_file):
-                        raise Exception('key_file "{}" or cert_file "{}"'
-                                        ' is not found'.
-                                         format(self.key_file, self.cert_file))
-                    with open(self.key_file) as keyFile:
-                        with open(self.cert_file) as certFile:
-                            clientCert = ssl.PrivateCertificate.loadPEM(
-                                keyFile.read() + certFile.read())
-
-                    ctx = clientCert.options()
-                    self.connector = reactor.connectSSL(host, port, self, ctx)
-                    log.info('tls-enabled')
-
-                except Exception as e:
-                    log.exception('failed-to-connect', reason=e)
-            else:
-                self.connector = reactor.connectTCP(host, port, self)
-                log.info('tls-disabled')
-
-            self.d_disconnected = Deferred()
-            yield self.d_disconnected
-            log.debug('reconnect', after_delay=self.retry_interval)
-            yield asleep(self.retry_interval)
-
-    def enter_disconnected(self, event, reason):
-        """Internally signal entering disconnected state"""
-        self.connected = False
-        if not self.exiting:
-            log.error(event, reason=reason)
-            self.d_disconnected.callback(None)
-
-    def enter_connected(self):
-        """Handle transitioning from disconnected to connected state"""
-        log.info('connected')
-        self.connected = True
-        self.read_buffer = None
-        reactor.callLater(0, self.proto_handler.start)
-
-    # protocol.ClientFactory methods
-
-    def protocol(self):
-        cxn = OpenFlowConnection(self)  # Low level message handler
-        self.proto_handler = OpenFlowProtocolHandler(
-            self.datapath_id, self.device_id, self, cxn)
-        return cxn
-
-    def clientConnectionFailed(self, connector, reason):
-        self.enter_disconnected('connection-failed', reason)
-
-    def clientConnectionLost(self, connector, reason):
-        if not self.exiting:
-            log.error('client-connection-lost',
-                      reason=reason, connector=connector)
-
-    def forward_packet_in(self, ofp_packet_in):
-        if self.proto_handler is not None:
-            self.proto_handler.forward_packet_in(ofp_packet_in)
-
-    def forward_change_event(self, event):
-        # assert isinstance(event, ChangeEvent)
-        log.info('got-change-event', change_event=event)
-        if event.HasField("port_status"):
-            if self.proto_handler is not None:
-                self.proto_handler.forward_port_status(event.port_status)
-        else:
-            log.error('unknown-change-event', change_event=event)
-
-if __name__ == '__main__':
-    """Run this to test the agent for N concurrent sessions:
-       python agent [<number-of-desired-instances>]
-    """
-
-    n = 1 if len(sys.argv) < 2 else int(sys.argv[1])
-
-    from utils import mac_str_to_tuple
-
-    class MockRpc(object):
-        @staticmethod
-        def get_port_list(_):
-            ports = []
-            cap = of13.OFPPF_1GB_FD | of13.OFPPF_FIBER
-            for pno, mac, nam, cur, adv, sup, spe in (
-                    (1, '00:00:00:00:00:01', 'onu1', cap, cap, cap,
-                     of13.OFPPF_1GB_FD),
-                    (2, '00:00:00:00:00:02', 'onu2', cap, cap, cap,
-                     of13.OFPPF_1GB_FD),
-                    (129, '00:00:00:00:00:81', 'olt', cap, cap, cap,
-                     of13.OFPPF_1GB_FD)
-            ):
-                port = of13.common.port_desc(pno, mac_str_to_tuple(mac), nam,
-                                             curr=cur, advertised=adv,
-                                             supported=sup,
-                                             curr_speed=spe, max_speed=spe)
-                ports.append(port)
-            return ports
-
-    stub = MockRpc()
-    agents = [Agent('localhost:6653', 256 + i, stub).start() for i in range(n)]
-
-    def shutdown():
-        [a.stop() for a in agents]
-
-    reactor.addSystemEventTrigger('before', 'shutdown', shutdown)
-    reactor.run()
diff --git a/python/ofagent/connection_mgr.py b/python/ofagent/connection_mgr.py
deleted file mode 100755
index 9c64854..0000000
--- a/python/ofagent/connection_mgr.py
+++ /dev/null
@@ -1,349 +0,0 @@
-#
-# Copyright 2017 the original author or authors.
-#
-# 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.
-#
-import os
-
-import sys
-
-from twisted.internet import reactor
-from twisted.internet.defer import Deferred, inlineCallbacks, returnValue
-
-from pyvoltha.common.utils.asleep import asleep
-from pyvoltha.common.utils.consulhelpers import get_endpoint_from_consul
-from structlog import get_logger
-import grpc
-from grpc import StatusCode
-from grpc._channel import _Rendezvous
-from voltha_protos.voltha_pb2 import OfAgentSubscriber
-from grpc_client import GrpcClient
-
-from agent import Agent
-from pyvoltha.common.utils.dockerhelpers import get_my_containers_name
-
-
-log = get_logger()
-# _ = third_party
-
-class ConnectionManager(object):
-    def __init__(self, consul_endpoint,
-                 vcore_endpoint, vcore_grpc_timeout, vcore_binding_key,
-                 vcore_transaction_key, controller_endpoints, instance_id,
-                 enable_tls=False, key_file=None, cert_file=None,
-                 vcore_retry_interval=0.5, devices_refresh_interval=5,
-                 subscription_refresh_interval=5):
-
-        log.info('init-connection-manager')
-        log.info('list-of-controllers', controller_endpoints=controller_endpoints)
-        self.controller_endpoints = controller_endpoints
-        self.consul_endpoint = consul_endpoint
-        self.vcore_endpoint = vcore_endpoint
-        self.grpc_timeout = vcore_grpc_timeout
-        self.core_binding_key = vcore_binding_key
-        self.core_transaction_key = vcore_transaction_key
-        self.instance_id = instance_id
-        self.enable_tls = enable_tls
-        self.key_file = key_file
-        self.cert_file = cert_file
-
-        self.channel = None
-        self.grpc_client = None  # single, shared gRPC client to vcore
-
-        self.agent_map = {}  # (datapath_id, controller_endpoint) -> Agent()
-        self.device_id_to_datapath_id_map = {}
-
-        self.vcore_retry_interval = vcore_retry_interval
-        self.devices_refresh_interval = devices_refresh_interval
-        self.subscription_refresh_interval = subscription_refresh_interval
-        self.subscription = None
-        self.connecting = True
-        self.monitor = True
-
-        self.running = False
-
-    def start(self):
-
-        if self.running:
-            return
-
-        log.debug('starting')
-
-        self.running = True
-
-        # Get a subscription to vcore
-        reactor.callInThread(self.get_vcore_subscription)
-
-        # Start monitoring logical devices and manage agents accordingly
-        reactor.callLater(0, self.monitor_logical_devices)
-
-        log.info('started')
-
-        return self
-
-    def grpc_client_terminated(self):
-        if not self.connecting and self.grpc_client is not None:
-            self.connecting = True
-            self._reset_grpc_attributes()
-            self.delete_all_agents()
-            reactor.callInThread(self.get_vcore_subscription)
-
-    def liveness_probe(self):
-        return self.running
-
-    def readiness_probe(self):
-        # Pod is isolated when readiness condition fails
-        return bool(not self.connecting and self.channel and self.subscription and self.grpc_client)
-
-    def stop(self):
-        log.debug('stopping')
-        self.delete_all_agents()
-        self._reset_grpc_attributes()
-        self.running = False
-        log.info('stopped')
-
-    def resolve_endpoint(self, endpoint):
-        ip_port_endpoint = endpoint
-        if endpoint.startswith('@'):
-            try:
-                ip_port_endpoint = get_endpoint_from_consul(
-                    self.consul_endpoint, endpoint[1:])
-                log.info(
-                    '{}-service-endpoint-found'.format(endpoint), address=ip_port_endpoint)
-            except Exception as e:
-                log.error('{}-service-endpoint-not-found'.format(endpoint), exception=repr(e))
-                log.error('committing-suicide')
-                # Committing suicide in order to let docker restart ofagent
-                os.system("kill -15 {}".format(os.getpid()))
-        if ip_port_endpoint:
-            host, port = ip_port_endpoint.split(':', 2)
-            return host, int(port)
-
-    def _reset_grpc_attributes(self):
-        log.debug('start-reset-grpc-attributes')
-
-        if self.grpc_client is not None:
-            self.grpc_client.stop()
-
-        if self.channel is not None:
-            del self.channel
-
-        self.channel = None
-        self.subscription = None
-        self.grpc_client = None
-
-        log.debug('stop-reset-grpc-attributes')
-
-    def _assign_grpc_attributes(self):
-        log.debug('start-assign-grpc-attributes')
-
-        host, port = self.resolve_endpoint(self.vcore_endpoint)
-        log.info('revolved-vcore-endpoint', endpoint=self.vcore_endpoint, host=host, port=port)
-
-        assert host is not None
-        assert port is not None
-
-        # Establish a connection to the vcore GRPC server
-        self.channel = grpc.insecure_channel('{}:{}'.format(host, port))
-
-        log.debug('stop-assign-grpc-attributes')
-
-    @inlineCallbacks
-    def get_vcore_subscription(self):
-        log.debug('start-get-vcore-subscription')
-
-        self.connecting = True
-        while self.running and self.subscription is None:
-            try:
-                # If a subscription is not yet assigned then establish new GRPC connection
-                # ... otherwise keep using existing connection details
-                if self.subscription is None:
-                    self._assign_grpc_attributes()
-
-                # Send subscription request to register the current ofagent instance
-                container_name = self.instance_id
-                if self.grpc_client is None:
-                    self.grpc_client = GrpcClient(self, self.channel, self.grpc_timeout,
-                                                  self.core_binding_key, self.core_transaction_key)
-                subscription = yield self.grpc_client.subscribe(
-                    OfAgentSubscriber(ofagent_id=container_name))
-
-                # If the subscriber id matches the current instance
-                # ... then the subscription has succeeded
-                if subscription is not None and subscription.ofagent_id == container_name:
-                    if self.subscription is None:
-                        # Keep details on the current GRPC session and subscription
-                        log.debug('subscription-with-vcore-successful', subscription=subscription)
-                        self.subscription = subscription
-                        self.grpc_client.start()
-                        self.connecting = False
-
-                    # Sleep a bit in between each subscribe
-                    yield asleep(self.subscription_refresh_interval)
-
-                    # Move on to next subscribe request
-                    continue
-
-                # The subscription did not succeed, reset and move on
-                else:
-                    log.info('subscription-with-vcore-unavailable', subscription=subscription)
-
-            except _Rendezvous, e:
-                log.error('subscription-with-vcore-terminated',exception=e, status=e.code())
-
-            except Exception as e:
-                log.exception('unexpected-subscription-termination-with-vcore', e=e)
-
-            # Reset grpc details
-            # The vcore instance is either not available for subscription
-            # or a failure occurred with the existing communication.
-            self._reset_grpc_attributes()
-
-            # Sleep for a short period and retry
-            yield asleep(self.vcore_retry_interval)
-
-        log.debug('stop-get-vcore-subscription')
-
-    def get_rpc_client(self):
-        return self.grpc_client if not self.connecting else None
-
-    @inlineCallbacks
-    def get_list_of_logical_devices_from_voltha(self):
-        while self.running:
-            log.info('retrieve-logical-device-list')
-            rpc = self.get_rpc_client()
-            if rpc is not None:
-                try:
-                    devices = yield rpc.list_logical_devices()
-
-                    for device in devices:
-                        log.info("logical-device-entry", id=device.id,
-                                 datapath_id=device.datapath_id)
-
-                    returnValue(devices)
-
-                except _Rendezvous, e:
-                    rpc.stop()
-                    status = e.code()
-                    log.error('vcore-communication-failure', exception=e, status=status)
-
-                except Exception as e:
-                    rpc.stop()
-                    log.exception('logical-devices-retrieval-failure', exception=e)
-
-            log.info('reconnect', after_delay=self.vcore_retry_interval)
-            yield asleep(self.vcore_retry_interval)
-
-    def refresh_agent_connections(self, devices):
-        """
-        Based on the new device list, update the following state in the class:
-        * agent_map
-        * datapath_map
-        * device_id_map
-        :param devices: full device list freshly received from Voltha
-        :return: None
-        """
-
-        # Use datapath ids for deciding what's new and what's obsolete
-        desired_datapath_ids = set(d.datapath_id for d in devices)
-        current_datapath_ids = set(datapath_ids[0] for datapath_ids in self.agent_map.iterkeys())
-
-        # if identical, nothing to do
-        if desired_datapath_ids == current_datapath_ids:
-            return
-
-        # ... otherwise calculate differences
-        to_add = desired_datapath_ids.difference(current_datapath_ids)
-        to_del = current_datapath_ids.difference(desired_datapath_ids)
-
-        # remove what we don't need
-        for datapath_id in to_del:
-            self.delete_agent(datapath_id)
-
-        # start new agents as needed
-        for device in devices:
-            if device.datapath_id in to_add:
-                self.create_agent(device)
-
-        log.debug('updated-agent-list', count=len(self.agent_map))
-        log.debug('updated-device-id-to-datapath-id-map',
-                  map=str(self.device_id_to_datapath_id_map))
-
-    def create_agent(self, device):
-        datapath_id = device.datapath_id
-        device_id = device.id
-        for controller_endpoint in self.controller_endpoints:
-            agent = Agent(self, controller_endpoint, datapath_id,
-                          device_id, self.enable_tls,
-                          self.key_file, self.cert_file)
-            agent.start()
-            self.agent_map[(datapath_id,controller_endpoint)] = agent
-            self.device_id_to_datapath_id_map[device_id] = datapath_id
-
-    def delete_all_agents(self):
-        for agent in self.agent_map.itervalues(): agent.stop()
-        self.agent_map = {}
-        self.device_id_to_datapath_id_map = {}
-
-    def delete_agent(self, datapath_id):
-        for controller_endpoint in self.controller_endpoints:
-            agent = self.agent_map[(datapath_id,controller_endpoint)]
-            device_id = agent.get_device_id()
-            agent.stop()
-            del self.agent_map[(datapath_id,controller_endpoint)]
-            del self.device_id_to_datapath_id_map[device_id]
-
-    @inlineCallbacks
-    def monitor_logical_devices(self):
-        log.debug('start-monitor-logical-devices')
-
-        while self.running:
-            log.info('monitoring-logical-devices')
-
-            # should change to a gRPC streaming call
-            # see https://jira.opencord.org/browse/CORD-821
-
-            try:
-                if self.channel is not None and self.get_rpc_client() is not None and self.subscription is not None:
-                    # get current list from Voltha
-                    devices = yield  self.get_list_of_logical_devices_from_voltha()
-
-                    # update agent list and mapping tables as needed
-                    self.refresh_agent_connections(devices)
-                else:
-                    log.info('vcore-communication-unavailable')
-
-                # wait before next poll
-                yield asleep(self.devices_refresh_interval)
-
-            except _Rendezvous, e:
-                log.error('vcore-communication-failure', exception=repr(e), status=e.code())
-
-            except Exception as e:
-                log.exception('unexpected-vcore-communication-failure', exception=repr(e))
-
-        log.debug('stop-monitor-logical-devices')
-
-    def forward_packet_in(self, device_id, ofp_packet_in):
-        datapath_id = self.device_id_to_datapath_id_map.get(device_id, None)
-        if datapath_id:
-            for controller_endpoint in self.controller_endpoints:
-                agent = self.agent_map[(datapath_id, controller_endpoint)]
-                agent.forward_packet_in(ofp_packet_in)
-
-    def forward_change_event(self, device_id, event):
-        datapath_id = self.device_id_to_datapath_id_map.get(device_id, None)
-        if datapath_id:
-            for controller_endpoint in self.controller_endpoints:
-                agent = self.agent_map[(datapath_id, controller_endpoint)]
-                agent.forward_change_event(event)
diff --git a/python/ofagent/converter.py b/python/ofagent/converter.py
deleted file mode 100755
index 6280331..0000000
--- a/python/ofagent/converter.py
+++ /dev/null
@@ -1,598 +0,0 @@
-#
-# Copyright 2017 the original author or authors.
-#
-# 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.
-#
-
-"""
-Convert loxi objects to openflow_13 messages and back.
-"""
-from copy import copy
-
-from google.protobuf.descriptor import FieldDescriptor
-
-import loxi.of13 as of13
-from protobuf_to_dict import protobuf_to_dict, TYPE_CALLABLE_MAP
-from voltha_protos import openflow_13_pb2 as pb2
-
-
-type_callable_map = copy(TYPE_CALLABLE_MAP)
-type_callable_map.update({
-    FieldDescriptor.TYPE_STRING: str
-})
-
-def pb2dict(pb):
-    """
-    Convert protobuf to a dict of values good for instantiating
-    loxi objects (or any other objects). We specialize the protobuf_to_dict
-    library call with our modified decoders.
-    :param pb: protobuf as loaded into Python
-    :return: dict of values
-    """
-    return protobuf_to_dict(pb, type_callable_map)
-
-def to_loxi(grpc_object):
-    cls = grpc_object.__class__
-    converter = to_loxi_converters[cls.__name__]
-    return converter(grpc_object)
-
-def to_grpc(loxi_object):
-    cls = loxi_object.__class__
-    converter = to_grpc_converters[cls]
-    return converter(loxi_object)
-
-def ofp_port_to_loxi_port_desc(pb):
-    kw = pb2dict(pb)
-    return of13.common.port_desc(**kw)
-
-def ofp_port_status_to_loxi_port_status(pb):
-    return of13.message.port_status(
-        reason=pb.reason,
-        desc=ofp_port_to_loxi_port_desc(pb.desc)
-    )
-
-def ofp_port_stats_to_loxi_port_stats(pb):
-    kw = pb2dict(pb)
-    return of13.port_stats_entry(**kw)
-
-
-def ofp_meter_stats_to_loxi_meter_stats(pb):
-    return of13.meter_stats(
-        meter_id=pb.meter_id,
-        flow_count=pb.flow_count,
-        packet_in_count=pb.packet_in_count,
-        byte_in_count=pb.byte_in_count,
-        duration_sec=pb.duration_sec,
-        duration_nsec=pb.duration_nsec,
-        band_stats=[to_loxi(band_stat) for band_stat in pb.band_stats])
-
-
-def ofp_meter_band_stats_to_loxi_meter_stats(pb):
-    return of13.meter_band_stats(
-        packet_band_count=pb.packet_band_count,
-        byte_band_count=pb.byte_band_count
-    )
-
-def make_loxi_field(oxm_field):
-    assert oxm_field['oxm_class'] == pb2.OFPXMC_OPENFLOW_BASIC
-    ofb_field = oxm_field['ofb_field']
-    field_type = ofb_field.get('type', 0)
-
-    if field_type == pb2.OFPXMT_OFB_ETH_TYPE:
-        return (
-            of13.oxm.eth_type(value=ofb_field['eth_type']))
-
-    elif field_type == pb2.OFPXMT_OFB_IN_PORT:
-        return (
-            of13.oxm.in_port(value=ofb_field['port']))
-
-    elif field_type == pb2.OFPXMT_OFB_IP_PROTO:
-        return (
-            of13.oxm.ip_proto(value=ofb_field['ip_proto']))
-
-    elif field_type == pb2.OFPXMT_OFB_VLAN_VID:
-        return (
-            of13.oxm.vlan_vid(value=ofb_field['vlan_vid']))
-
-    elif field_type == pb2.OFPXMT_OFB_VLAN_PCP:
-        return (
-            of13.oxm.vlan_pcp(value=ofb_field['vlan_pcp']))
-
-    elif field_type == pb2.OFPXMT_OFB_IPV4_SRC:
-        return (
-            of13.oxm.ipv4_src(value=ofb_field['ipv4_src']))
-
-    elif field_type == pb2.OFPXMT_OFB_IPV4_DST:
-        return (
-            of13.oxm.ipv4_dst(value=ofb_field['ipv4_dst']))
-
-    elif field_type == pb2.OFPXMT_OFB_UDP_SRC:
-        return (
-            of13.oxm.udp_src(value=ofb_field['udp_src']))
-
-    elif field_type == pb2.OFPXMT_OFB_UDP_DST:
-        return (
-            of13.oxm.udp_dst(value=ofb_field['udp_dst']))
-
-    elif field_type == pb2.OFPXMT_OFB_METADATA:
-        return (
-            of13.oxm.metadata(value=ofb_field['table_metadata']))
-
-    else:
-        raise NotImplementedError(
-            'OXM match field for type %s' % field_type)
-
-def make_loxi_match(match):
-    assert match.get('type', pb2.OFPMT_STANDARD) == pb2.OFPMT_OXM
-    loxi_match_fields = []
-    for oxm_field in match.get('oxm_fields', []):
-        loxi_match_fields.append(make_loxi_field(oxm_field))
-    return of13.match_v3(oxm_list=loxi_match_fields)
-
-
-def make_loxi_action(a):
-    if type(a) is not dict:
-        a = pb2dict(a)
-
-    typ = a.get('type', 0)
-
-    if typ == pb2.OFPAT_OUTPUT:
-        output_kws = a['output']
-        return of13.action.output(**output_kws)
-
-    elif typ == pb2.OFPAT_POP_VLAN:
-        return of13.action.pop_vlan()
-
-    elif typ == pb2.OFPAT_PUSH_VLAN:
-        push_vlan_kws = a['push']
-        return of13.action.push_vlan(**push_vlan_kws)
-
-    elif typ == pb2.OFPAT_SET_FIELD:
-        loxi_field = make_loxi_field(a['set_field']['field'])
-        return of13.action.set_field(loxi_field)
-
-    elif typ == pb2.OFPAT_GROUP:
-        group_kws = a['group']
-        return of13.action.group(**group_kws)
-
-    else:
-        raise NotImplementedError(
-            'Action decoder for action OFPAT_* %d' % typ)
-
-
-def ofp_flow_stats_to_loxi_flow_stats(pb):
-    kw = pb2dict(pb)
-
-    def make_loxi_instruction(inst):
-        type = inst['type']
-        if type == pb2.OFPIT_APPLY_ACTIONS:
-            return of13.instruction.apply_actions(
-                actions=[make_loxi_action(a)
-                         for a in inst['actions']['actions']])
-        elif type == pb2.OFPIT_CLEAR_ACTIONS:
-            return of13.instruction.clear_actions()
-        elif type == pb2.OFPIT_GOTO_TABLE:
-            return of13.instruction.goto_table(
-                table_id=inst['goto_table']['table_id'])
-        elif type == pb2.OFPIT_WRITE_ACTIONS:
-            return of13.instruction.write_actions(
-                actions=[make_loxi_action(a)
-                         for a in inst['actions']['actions']])
-        elif type == pb2.OFPIT_WRITE_METADATA:
-            if 'metadata' in inst['write_metadata']:
-                return of13.instruction.write_metadata(
-                        metadata=inst['write_metadata']['metadata'])
-            else:
-                return of13.instruction.write_metadata(0)
-        elif type == pb2.OFPIT_METER:
-            return of13.instruction.meter(
-                meter_id=inst['meter']['meter_id'])
-
-        else:
-            raise NotImplementedError('Instruction type %d' % type)
-
-    kw['match'] = make_loxi_match(kw['match'])
-    # if the flow action is drop, then the instruction is not found in the dict
-    if 'instructions' in kw:
-        kw['instructions'] = [make_loxi_instruction(i) for i in kw['instructions']]
-    del kw['id']
-    return of13.flow_stats_entry(**kw)
-
-
-def ofp_packet_in_to_loxi_packet_in(pb):
-    packet_in = of13.message.packet_in(
-        buffer_id=pb.buffer_id,
-        reason=pb.reason,
-        table_id=pb.table_id,
-        cookie=pb.cookie,
-        match=make_loxi_match(pb2dict(pb.match)),
-        data=pb.data
-    )
-    return packet_in
-
-def ofp_group_desc_to_loxi_group_desc(pb):
-    return of13.group_desc_stats_entry(
-        group_type=pb.type,
-        group_id=pb.group_id,
-        buckets=[to_loxi(bucket) for bucket in pb.buckets])
-
-
-def ofp_group_stats_to_loxi_group_stats(pb):
-    return of13.group_stats_entry(
-        group_id=pb.group_id,
-        ref_count=pb.ref_count,
-        packet_count=pb.packet_count,
-        byte_count=pb.byte_count,
-        duration_sec=pb.duration_sec,
-        duration_nsec=pb.duration_nsec,
-        bucket_stats=[to_loxi(bstat) for bstat in pb.bucket_stats])
-
-
-def ofp_bucket_counter_to_loxy_bucket_counter(pb):
-    return of13.bucket_counter(
-        packet_count=pb.packet_count,
-        byte_count=pb.byte_count)
-
-
-def ofp_bucket_to_loxi_bucket(pb):
-    return of13.bucket(
-        weight=pb.weight,
-        watch_port=pb.watch_port,
-        watch_group=pb.watch_group,
-        actions=[to_loxi(action) for action in pb.actions]
-    )
-
-
-to_loxi_converters = {
-    'ofp_port': ofp_port_to_loxi_port_desc,
-    'ofp_port_status': ofp_port_status_to_loxi_port_status,
-    'ofp_flow_stats': ofp_flow_stats_to_loxi_flow_stats,
-    'ofp_packet_in': ofp_packet_in_to_loxi_packet_in,
-    'ofp_group_stats': ofp_group_stats_to_loxi_group_stats,
-    'ofp_group_desc': ofp_group_desc_to_loxi_group_desc,
-    'ofp_bucket_counter': ofp_bucket_counter_to_loxy_bucket_counter,
-    'ofp_bucket': ofp_bucket_to_loxi_bucket,
-    'ofp_action': make_loxi_action,
-    'ofp_port_stats': ofp_port_stats_to_loxi_port_stats,
-    'ofp_meter_stats': ofp_meter_stats_to_loxi_meter_stats,
-    'ofp_meter_band_stats': ofp_meter_band_stats_to_loxi_meter_stats
-}
-
-
-def loxi_flow_mod_to_ofp_flow_mod(lo):
-    return pb2.ofp_flow_mod(
-        cookie=lo.cookie,
-        cookie_mask=lo.cookie_mask,
-        table_id=lo.table_id,
-        command=lo._command,
-        idle_timeout=lo.idle_timeout,
-        hard_timeout=lo.hard_timeout,
-        priority=lo.priority,
-        buffer_id=lo.buffer_id,
-        out_port=lo.out_port,
-        out_group=lo.out_group,
-        flags=lo.flags,
-        match=to_grpc(lo.match),
-        instructions=[to_grpc(i) for i in lo.instructions])
-
-def loxi_meter_mod_to_ofp_meter_mod(lo):
-    return pb2.ofp_meter_mod(
-        command=lo.command,
-        flags=lo.flags,
-        meter_id=lo.meter_id,
-        bands=[to_grpc(i) for i in lo.meters])
-
-
-def loxi_meter_band_drop_to_ofp_meter_band_drop(lo):
-    return pb2.ofp_meter_band_header(
-        type=lo.type,
-        rate=lo.rate,
-        burst_size=lo.burst_size)
-
-
-def loxi_meter_band_dscp_remark_to_ofp_meter_band_dscp_remark(lo):
-    return pb2.ofp_meter_band_header(
-        type=lo.type,
-        rate=lo.rate,
-        burst_size=lo.burst_size,
-        dscp_remark=pb2.ofp_meter_band_dscp_remark(prec_level=lo.prec_level))
-
-
-def loxi_meter_band_experimenter_to_ofp_meter_band_experimenter(lo):
-    return pb2.ofp_meter_band_header(
-        type=lo.type,
-        rate=lo.rate,
-        burst_size=lo.burst_size,
-        experimenter=pb2.ofp_meter_band_experimenter(experimenter=lo.experimenter))
-
-
-def loxi_meter_multipart_request_to_ofp_meter_multipart_request(lo):
-    return pb2.ofp_meter_multipart_request(
-        meter_id=lo.meter_id)
-
-
-def loxi_meter_stats_to_ofp_meter_stats(lo):
-    return pb2.ofp_meter_stats(
-        meter_id=lo.meter_id,
-        flow_count=lo.flow_count,
-        packet_in_count =lo.packet_in_count,
-        byte_in_count=lo.byte_in_count,
-        duration_sec=lo.duration_sec,
-        duration_nsec=lo.duration_nsec,
-        band_stats=lo.band_stats)
-
-
-def loxi_meter_mod_to_ofp_meter_mod(lo):
-    return pb2.ofp_meter_mod(
-        command=lo.command,
-        flags=lo.flags,
-        meter_id=lo.meter_id,
-        bands=[to_grpc(i) for i in lo.meters])
-
-
-def loxi_meter_band_drop_to_ofp_meter_band_drop(lo):
-    return pb2.ofp_meter_band_header(
-        type=lo.type,
-        rate=lo.rate,
-        burst_size=lo.burst_size)
-
-
-def loxi_meter_band_dscp_remark_to_ofp_meter_band_dscp_remark(lo):
-    return pb2.ofp_meter_band_header(
-        type=lo.type,
-        rate=lo.rate,
-        burst_size=lo.burst_size,
-        dscp_remark=pb2.ofp_meter_band_dscp_remark(prec_level=lo.prec_level))
-
-
-def loxi_meter_band_experimenter_to_ofp_meter_band_experimenter(lo):
-    return pb2.ofp_meter_band_header(
-        type=lo.type,
-        rate=lo.rate,
-        burst_size=lo.burst_size,
-        experimenter=pb2.ofp_meter_band_experimenter(experimenter=lo.experimenter))
-
-
-def loxi_meter_multipart_request_to_ofp_meter_multipart_request(lo):
-    return pb2.ofp_meter_multipart_request(
-        meter_id=lo.meter_id)
-
-def loxi_meter_stats_to_ofp_meter_stats(lo):
-    return pb2.ofp_meter_stats(
-        meter_id=lo.meter_id,
-        flow_count=lo.flow_count,
-        packet_in_count =lo.packet_in_count,
-        byte_in_count=lo.byte_in_count,
-        duration_sec=lo.duration_sec,
-        duration_nsec=lo.duration_nsec,
-        band_stats=lo.band_stats)
-
-def loxi_group_mod_to_ofp_group_mod(lo):
-    return pb2.ofp_group_mod(
-        command=lo.command,
-        type=lo.group_type,
-        group_id=lo.group_id,
-        buckets=[to_grpc(b) for b in lo.buckets])
-
-
-def loxi_packet_out_to_ofp_packet_out(lo):
-    return pb2.ofp_packet_out(
-        buffer_id=lo.buffer_id,
-        in_port=lo.in_port,
-        actions=[to_grpc(a) for a in lo.actions],
-        data=lo.data)
-
-
-def loxi_match_v3_to_ofp_match(lo):
-    return pb2.ofp_match(
-        type=pb2.OFPMT_OXM,
-        oxm_fields=[to_grpc(f) for f in lo.oxm_list])
-
-
-def loxi_bucket_to_ofp_bucket(lo):
-    return pb2.ofp_bucket(
-        weight=lo.weight,
-        watch_port=lo.watch_port,
-        watch_group=lo.watch_group,
-        actions=[to_grpc(a) for a in lo.actions])
-
-
-def loxi_oxm_eth_type_to_ofp_oxm(lo):
-    return pb2.ofp_oxm_field(
-        oxm_class=pb2.OFPXMC_OPENFLOW_BASIC,
-        ofb_field=pb2.ofp_oxm_ofb_field(
-            type=pb2.OFPXMT_OFB_ETH_TYPE,
-            eth_type=lo.value))
-
-
-def loxi_oxm_in_port_to_ofp_oxm(lo):
-    return pb2.ofp_oxm_field(
-        oxm_class=pb2.OFPXMC_OPENFLOW_BASIC,
-        ofb_field=pb2.ofp_oxm_ofb_field(
-            type=pb2.OFPXMT_OFB_IN_PORT,
-            port=lo.value))
-
-
-def loxi_oxm_ip_proto_to_ofp_oxm(lo):
-    return pb2.ofp_oxm_field(
-        oxm_class=pb2.OFPXMC_OPENFLOW_BASIC,
-        ofb_field=pb2.ofp_oxm_ofb_field(
-            type=pb2.OFPXMT_OFB_IP_PROTO,
-            ip_proto=lo.value))
-
-
-def loxi_oxm_vlan_vid_to_ofp_oxm(lo):
-    return pb2.ofp_oxm_field(
-        oxm_class=pb2.OFPXMC_OPENFLOW_BASIC,
-        ofb_field=pb2.ofp_oxm_ofb_field(
-            type=pb2.OFPXMT_OFB_VLAN_VID,
-            vlan_vid=lo.value))
-
-
-def loxi_oxm_vlan_pcp_to_ofp_oxm(lo):
-    return pb2.ofp_oxm_field(
-        oxm_class=pb2.OFPXMC_OPENFLOW_BASIC,
-        ofb_field=pb2.ofp_oxm_ofb_field(
-            type=pb2.OFPXMT_OFB_VLAN_PCP,
-            vlan_pcp=lo.value))
-
-
-def loxi_oxm_ipv4_dst_to_ofp_oxm(lo):
-    return pb2.ofp_oxm_field(
-        oxm_class=pb2.OFPXMC_OPENFLOW_BASIC,
-        ofb_field=pb2.ofp_oxm_ofb_field(
-            type=pb2.OFPXMT_OFB_IPV4_DST,
-            ipv4_dst=lo.value))
-
-
-def loxi_oxm_udp_dst_to_ofp_oxm(lo):
-    return pb2.ofp_oxm_field(
-        oxm_class=pb2.OFPXMC_OPENFLOW_BASIC,
-        ofb_field=pb2.ofp_oxm_ofb_field(
-            type=pb2.OFPXMT_OFB_UDP_DST,
-            udp_dst=lo.value))
-
-
-def loxi_oxm_udp_src_to_ofp_oxm(lo):
-    return pb2.ofp_oxm_field(
-        oxm_class=pb2.OFPXMC_OPENFLOW_BASIC,
-        ofb_field=pb2.ofp_oxm_ofb_field(
-            type=pb2.OFPXMT_OFB_UDP_SRC,
-            udp_src=lo.value))
-
-
-def loxi_oxm_metadata_to_ofp_oxm(lo):
-    return pb2.ofp_oxm_field(
-        oxm_class=pb2.OFPXMC_OPENFLOW_BASIC,
-        ofb_field=pb2.ofp_oxm_ofb_field(
-            type=pb2.OFPXMT_OFB_METADATA,
-            table_metadata=lo.value))
-
-
-def loxi_apply_actions_to_ofp_instruction(lo):
-    return pb2.ofp_instruction(
-        type=pb2.OFPIT_APPLY_ACTIONS,
-        actions=pb2.ofp_instruction_actions(
-            actions=[to_grpc(a) for a in lo.actions]))
-
-def loxi_clear_actions_to_ofp_instruction(lo):
-    return pb2.ofp_instruction(
-        type=pb2.OFPIT_CLEAR_ACTIONS)
-
-
-def loxi_goto_table_to_ofp_instruction(lo):
-    return pb2.ofp_instruction(
-        type=pb2.OFPIT_GOTO_TABLE,
-        goto_table=pb2.ofp_instruction_goto_table(table_id=lo.table_id))
-
-
-def loxi_write_metadata_to_ofp_instruction(lo):
-    return pb2.ofp_instruction(
-        type=pb2.OFPIT_WRITE_METADATA,
-        write_metadata=pb2.ofp_instruction_write_metadata(
-            metadata=lo.metadata,
-            metadata_mask=lo.metadata_mask))
-
-
-def loxi_meter_to_ofp_instruction(lo):
-    return pb2.ofp_instruction(
-        type=pb2.OFPIT_METER,
-        meter=pb2.ofp_instruction_meter(meter_id=lo.meter_id))
-
-
-def loxi_output_action_to_ofp_action(lo):
-    return pb2.ofp_action(
-        type=pb2.OFPAT_OUTPUT,
-        output=pb2.ofp_action_output(port=lo.port, max_len=lo.max_len))
-
-
-def loxi_write_actions_to_ofp_instruction(lo):
-    return pb2.ofp_instruction(
-        type=pb2.OFPIT_WRITE_ACTIONS,
-        actions=pb2.ofp_instruction_actions(
-            actions=[to_grpc(a) for a in lo.actions]))
-
-
-def loxi_meter_to_ofp_instruction(lo):
-    return pb2.ofp_instruction(
-        type=pb2.OFPIT_METER,
-        meter=pb2.ofp_instruction_meter(meter_id=lo.meter_id))
-
-
-def loxi_group_action_to_ofp_action(lo):
-    return pb2.ofp_action(
-        type=pb2.OFPAT_GROUP,
-        group=pb2.ofp_action_group(group_id=lo.group_id))
-
-
-def loxi_set_field_action_to_ofp_action(lo):
-    return pb2.ofp_action(
-        type=pb2.OFPAT_SET_FIELD,
-        set_field=pb2.ofp_action_set_field(field=to_grpc(lo.field)))
-
-
-def loxi_pop_vlan_action_to_ofp_action(lo):
-    return pb2.ofp_action(type=pb2.OFPAT_POP_VLAN)
-
-
-def loxi_push_vlan_action_to_ofp_action(lo):
-    return pb2.ofp_action(
-        type=pb2.OFPAT_PUSH_VLAN,
-        push=pb2.ofp_action_push(ethertype=lo.ethertype))
-
-
-to_grpc_converters = {
-
-    of13.message.flow_add: loxi_flow_mod_to_ofp_flow_mod,
-    of13.message.flow_delete: loxi_flow_mod_to_ofp_flow_mod,
-    of13.message.flow_delete_strict: loxi_flow_mod_to_ofp_flow_mod,
-    of13.message.flow_modify: loxi_flow_mod_to_ofp_flow_mod,
-    of13.message.flow_modify_strict: loxi_flow_mod_to_ofp_flow_mod,
-    of13.message.meter_mod: loxi_meter_mod_to_ofp_meter_mod,
-    of13.message.meter_stats_request: loxi_meter_stats_to_ofp_meter_stats,
-
-    of13.message.group_add: loxi_group_mod_to_ofp_group_mod,
-    of13.message.group_delete: loxi_group_mod_to_ofp_group_mod,
-    of13.message.group_modify: loxi_group_mod_to_ofp_group_mod,
-    of13.message.packet_out: loxi_packet_out_to_ofp_packet_out,
-
-    of13.meter_band.drop: loxi_meter_band_drop_to_ofp_meter_band_drop,
-    of13.meter_band.dscp_remark: loxi_meter_band_dscp_remark_to_ofp_meter_band_dscp_remark,
-    of13.meter_band.experimenter: loxi_meter_band_experimenter_to_ofp_meter_band_experimenter,
-
-    of13.common.match_v3: loxi_match_v3_to_ofp_match,
-    of13.common.bucket: loxi_bucket_to_ofp_bucket,
-
-    of13.oxm.eth_type: loxi_oxm_eth_type_to_ofp_oxm,
-    of13.oxm.in_port: loxi_oxm_in_port_to_ofp_oxm,
-    of13.oxm.ip_proto: loxi_oxm_ip_proto_to_ofp_oxm,
-    of13.oxm.vlan_vid: loxi_oxm_vlan_vid_to_ofp_oxm,
-    of13.oxm.vlan_pcp: loxi_oxm_vlan_pcp_to_ofp_oxm,
-    of13.oxm.ipv4_dst: loxi_oxm_ipv4_dst_to_ofp_oxm,
-    of13.oxm.udp_src: loxi_oxm_udp_src_to_ofp_oxm,
-    of13.oxm.udp_dst: loxi_oxm_udp_dst_to_ofp_oxm,
-    of13.oxm.metadata: loxi_oxm_metadata_to_ofp_oxm,
-
-    of13.instruction.apply_actions: loxi_apply_actions_to_ofp_instruction,
-    of13.instruction.clear_actions: loxi_clear_actions_to_ofp_instruction,
-    of13.instruction.write_actions: loxi_write_actions_to_ofp_instruction,
-    of13.instruction.goto_table: loxi_goto_table_to_ofp_instruction,
-    of13.instruction.write_metadata: loxi_write_metadata_to_ofp_instruction,
-    of13.instruction.meter: loxi_meter_to_ofp_instruction,
-
-    of13.action.output: loxi_output_action_to_ofp_action,
-    of13.action.group: loxi_group_action_to_ofp_action,
-    of13.action.set_field: loxi_set_field_action_to_ofp_action,
-    of13.action.pop_vlan: loxi_pop_vlan_action_to_ofp_action,
-    of13.action.push_vlan: loxi_push_vlan_action_to_ofp_action,
-}
diff --git a/python/ofagent/grpc_client.py b/python/ofagent/grpc_client.py
deleted file mode 100755
index 8e7b393..0000000
--- a/python/ofagent/grpc_client.py
+++ /dev/null
@@ -1,344 +0,0 @@
-#
-# Copyright 2017 the original author or authors.
-#
-# 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.
-#
-
-"""
-The gRPC client layer for the OpenFlow agent
-"""
-from Queue import Queue, Empty
-import os
-import uuid
-
-from grpc import StatusCode
-from grpc._channel import _Rendezvous
-from structlog import get_logger
-from twisted.internet import reactor
-from twisted.internet import threads
-from twisted.internet.defer import inlineCallbacks, returnValue, DeferredQueue
-
-from voltha_protos.voltha_pb2_grpc import VolthaServiceStub
-from voltha_protos.voltha_pb2 import ID, FlowTableUpdate, MeterModUpdate, \
-    FlowGroupTableUpdate, PacketOut
-from voltha_protos.logical_device_pb2 import LogicalPortId
-from google.protobuf import empty_pb2
-from binascii import hexlify
-
-
-log = get_logger()
-
-
-class GrpcClient(object):
-
-    def __init__(self, connection_manager, channel, grpc_timeout, core_binding_key, core_transaction_key):
-
-        self.connection_manager = connection_manager
-        self.channel = channel
-        self.grpc_timeout = grpc_timeout
-        self.grpc_stub = VolthaServiceStub(channel)
-
-        # This is the rw-core cluster to which an OFAgent is bound.
-        # It is the affinity router that forwards all OFAgent
-        # requests to a specific rw-core in this back-end cluster.
-        self.core_group_id = ''
-        self.core_group_id_key = core_binding_key
-
-        # Since the api-router binds an OFAgent to two RW Cores in a pair and
-        # transparently forward requests between the two then the onus is on
-        # the OFAgent to fulfill part of the function of the api-server which
-        # involves sending a transaction key to both RW Cores for the latter
-        # to figure out which Core will handle the transaction. To prevent
-        # collision between the api-server ID and the one from OFAgent then the
-        # OFAgent ID will be prefixed with "O-".
-        self.core_transaction_key = core_transaction_key
-
-        self.stopped = False
-
-        self.packet_out_queue = Queue()  # queue to send out PacketOut msgs
-        self.packet_in_queue = DeferredQueue()  # queue to receive PacketIn
-        self.change_event_queue = DeferredQueue()  # queue change events
-
-    def start(self):
-        log.debug('starting', grpc_timeout=self.grpc_timeout,
-                  core_binding_key=self.core_group_id_key,
-                  core_transaction_key=self.core_transaction_key)
-        self.start_packet_out_stream()
-        self.start_packet_in_stream()
-        self.start_change_event_in_stream()
-        reactor.callLater(0, self.packet_in_forwarder_loop)
-        reactor.callLater(0, self.change_event_processing_loop)
-        log.info('started')
-        return self
-
-    def stop(self):
-        log.debug('stop requested')
-        if self.stopped:
-            log.debug('already stopped, no action taken')
-            return
-        log.debug('stopping')
-        self.stopped = True
-        self.connection_manager.grpc_client_terminated()
-        log.info('stopped')
-
-    def get_core_transaction_metadata(self):
-        return (self.core_transaction_key, "O-" + uuid.uuid4().hex)
-
-    def start_packet_out_stream(self):
-
-        def packet_generator():
-            while True:
-                try:
-                    packet = self.packet_out_queue.get(block=True, timeout=1.0)
-                except Empty:
-                    if self.stopped:
-                        return
-                else:
-                    yield packet
-
-        def stream_packets_out():
-            generator = packet_generator()
-            try:
-                self.grpc_stub.StreamPacketsOut(generator,
-                                                metadata=((self.core_group_id_key, self.core_group_id),
-                                                           self.get_core_transaction_metadata(),))
-            except _Rendezvous, e:
-                log.error('grpc-exception', status=e.code())
-                if e.code() == StatusCode.UNAVAILABLE:
-                    self.stop()
-
-        reactor.callInThread(stream_packets_out)
-
-    def start_packet_in_stream(self):
-
-        def receive_packet_in_stream():
-            streaming_rpc_method = self.grpc_stub.ReceivePacketsIn
-            iterator = streaming_rpc_method(empty_pb2.Empty(),
-                                            metadata=((self.core_group_id_key, self.core_group_id),
-                                                      self.get_core_transaction_metadata(),))
-            try:
-                for packet_in in iterator:
-                    reactor.callFromThread(self.packet_in_queue.put,
-                                           packet_in)
-                    log.debug('enqueued-packet-in',
-                              packet_in=packet_in,
-                              queue_len=len(self.packet_in_queue.pending),
-                              packet=hexlify(packet_in.packet_in.data))
-            except _Rendezvous, e:
-                log.error('grpc-exception', status=e.code())
-                if e.code() == StatusCode.UNAVAILABLE:
-                    self.stop()
-
-        reactor.callInThread(receive_packet_in_stream)
-
-    def start_change_event_in_stream(self):
-
-        def receive_change_events():
-            streaming_rpc_method = self.grpc_stub.ReceiveChangeEvents
-            iterator = streaming_rpc_method(empty_pb2.Empty(),
-                                            metadata=((self.core_group_id_key, self.core_group_id),
-                                                      self.get_core_transaction_metadata(),))
-            try:
-                for event in iterator:
-                    reactor.callFromThread(self.change_event_queue.put, event)
-                    log.debug('enqueued-change-event',
-                              change_event=event,
-                              queue_len=len(self.change_event_queue.pending))
-            except _Rendezvous, e:
-                log.error('grpc-exception', status=e.code())
-                if e.code() == StatusCode.UNAVAILABLE:
-                    self.stop()
-
-        reactor.callInThread(receive_change_events)
-
-    @inlineCallbacks
-    def change_event_processing_loop(self):
-        while True:
-            try:
-                event = yield self.change_event_queue.get()
-                device_id = event.id
-                self.connection_manager.forward_change_event(device_id, event)
-            except Exception, e:
-                log.exception('failed-in-packet-in-handler', e=e)
-            if self.stopped:
-                break
-
-    @inlineCallbacks
-    def packet_in_forwarder_loop(self):
-        while True:
-            packet_in = yield self.packet_in_queue.get()
-            device_id = packet_in.id
-            ofp_packet_in = packet_in.packet_in
-            log.debug('grpc client to send packet-in', packet=hexlify(packet_in.packet_in.data))
-            self.connection_manager.forward_packet_in(device_id, ofp_packet_in)
-            if self.stopped:
-                break
-
-    def send_packet_out(self, device_id, packet_out):
-        log.debug('grpc client to send packet-out', packet=hexlify(packet_out.data))
-        packet_out = PacketOut(id=device_id, packet_out=packet_out)
-        self.packet_out_queue.put(packet_out)
-
-    @inlineCallbacks
-    def get_port(self, device_id, port_id):
-        req = LogicalPortId(id=device_id, port_id=port_id)
-        res = yield threads.deferToThread(
-            self.grpc_stub.GetLogicalDevicePort, req, timeout=self.grpc_timeout,
-            metadata=((self.core_group_id_key, self.core_group_id),
-                      self.get_core_transaction_metadata(),))
-        returnValue(res)
-
-    @inlineCallbacks
-    def get_port_list(self, device_id):
-        req = ID(id=device_id)
-        res = yield threads.deferToThread(
-            self.grpc_stub.ListLogicalDevicePorts, req, timeout=self.grpc_timeout,
-            metadata=((self.core_group_id_key, self.core_group_id),
-                      self.get_core_transaction_metadata(),))
-        returnValue(res.items)
-
-    @inlineCallbacks
-    def enable_port(self, device_id, port_id):
-        req = LogicalPortId(
-            id=device_id,
-            port_id=port_id
-        )
-        res = yield threads.deferToThread(
-            self.grpc_stub.EnableLogicalDevicePort, req, timeout=self.grpc_timeout,
-            metadata=((self.core_group_id_key, self.core_group_id),
-                      self.get_core_transaction_metadata(),))
-        returnValue(res)
-
-    @inlineCallbacks
-    def disable_port(self, device_id, port_id):
-        req = LogicalPortId(
-            id=device_id,
-            port_id=port_id
-        )
-        res = yield threads.deferToThread(
-            self.grpc_stub.DisableLogicalDevicePort, req, timeout=self.grpc_timeout,
-            metadata=((self.core_group_id_key, self.core_group_id),
-                      self.get_core_transaction_metadata(),))
-        returnValue(res)
-
-    @inlineCallbacks
-    def get_device_info(self, device_id):
-        req = ID(id=device_id)
-        res = yield threads.deferToThread(
-            self.grpc_stub.GetLogicalDevice, req, timeout=self.grpc_timeout,
-            metadata=((self.core_group_id_key, self.core_group_id),
-                      self.get_core_transaction_metadata(),))
-        returnValue(res)
-
-    @inlineCallbacks
-    def update_flow_table(self, device_id, flow_mod):
-        req = FlowTableUpdate(
-            id=device_id,
-            flow_mod=flow_mod
-        )
-        res = yield threads.deferToThread(
-            self.grpc_stub.UpdateLogicalDeviceFlowTable, req, timeout=self.grpc_timeout,
-            metadata=((self.core_group_id_key, self.core_group_id),
-                      self.get_core_transaction_metadata(),))
-        returnValue(res)
-
-    @inlineCallbacks
-    def update_meter_mod_table(self, device_id, meter_mod):
-        log.debug('In update_meter_mod_table grpc')
-        req = MeterModUpdate(
-            id=device_id,
-            meter_mod=meter_mod
-        )
-        res = yield threads.deferToThread(
-            self.grpc_stub.UpdateLogicalDeviceMeterTable, req, timeout=self.grpc_timeout,
-            metadata=((self.core_group_id_key, self.core_group_id),
-                      self.get_core_transaction_metadata(),))
-        log.debug('update_meter_mod_table grpc done')
-        returnValue(res)
-
-    @inlineCallbacks
-    def update_group_table(self, device_id, group_mod):
-        req = FlowGroupTableUpdate(
-            id=device_id,
-            group_mod=group_mod
-        )
-        res = yield threads.deferToThread(
-            self.grpc_stub.UpdateLogicalDeviceFlowGroupTable, req, timeout=self.grpc_timeout,
-            metadata=((self.core_group_id_key, self.core_group_id),
-                      self.get_core_transaction_metadata(),))
-        returnValue(res)
-
-    @inlineCallbacks
-    def list_flows(self, device_id):
-        req = ID(id=device_id)
-        res = yield threads.deferToThread(
-            self.grpc_stub.ListLogicalDeviceFlows, req, timeout=self.grpc_timeout,
-            metadata=((self.core_group_id_key, self.core_group_id),
-                      self.get_core_transaction_metadata(),))
-        returnValue(res.items)
-
-    @inlineCallbacks
-    def list_groups(self, device_id):
-        req = ID(id=device_id)
-        res = yield threads.deferToThread(
-            self.grpc_stub.ListLogicalDeviceFlowGroups, req, timeout=self.grpc_timeout,
-            metadata=((self.core_group_id_key, self.core_group_id),
-                      self.get_core_transaction_metadata(),))
-        returnValue(res.items)
-
-    @inlineCallbacks
-    def list_ports(self, device_id):
-        req = ID(id=device_id)
-        res = yield threads.deferToThread(
-            self.grpc_stub.ListLogicalDevicePorts, req, timeout=self.grpc_timeout,
-            metadata=((self.core_group_id_key, self.core_group_id),
-                      self.get_core_transaction_metadata(),))
-        returnValue(res.items)
-
-    @inlineCallbacks
-    def list_logical_devices(self):
-        res = yield threads.deferToThread(
-            self.grpc_stub.ListLogicalDevices, empty_pb2.Empty(), timeout=self.grpc_timeout,
-            metadata=((self.core_group_id_key, self.core_group_id),
-                      self.get_core_transaction_metadata(),))
-        returnValue(res.items)
-
-    @inlineCallbacks
-    def subscribe(self, subscriber):
-        res, call = yield threads.deferToThread(
-            self.grpc_stub.Subscribe.with_call, subscriber, timeout=self.grpc_timeout,
-            metadata=((self.core_group_id_key, self.core_group_id),
-                      self.get_core_transaction_metadata(),))
-        returned_metadata = call.initial_metadata()
-
-        # Update the core_group_id if present in the returned metadata
-        if returned_metadata is None:
-            log.debug('header-metadata-missing')
-        else:
-            log.debug('metadata-returned', metadata=returned_metadata)
-            for pair in returned_metadata:
-                if pair[0] == self.core_group_id_key:
-                    self.core_group_id = pair[1]
-                    log.debug('core-binding', core_group=self.core_group_id)
-        returnValue(res)
-
-    @inlineCallbacks
-    def list_meters(self, device_id):
-        log.debug('list_meters')
-        req = ID(id=device_id)
-        res = yield threads.deferToThread(
-            self.grpc_stub.ListLogicalDeviceMeters, req, timeout=self.grpc_timeout,
-            metadata=((self.core_group_id_key, self.core_group_id),
-                      self.get_core_transaction_metadata(),))
-        log.debug('done stat query', resp=res)
-        returnValue(res.items)
diff --git a/python/ofagent/loxi/__init__.py b/python/ofagent/loxi/__init__.py
deleted file mode 100644
index adb067b..0000000
--- a/python/ofagent/loxi/__init__.py
+++ /dev/null
@@ -1,82 +0,0 @@
-# Copyright 2017-present Open Networking Foundation
-#
-# 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.
-# Copyright (c) 2008 The Board of Trustees of The Leland Stanford Junior University
-# Copyright (c) 2011, 2012 Open Networking Foundation
-# Copyright (c) 2012, 2013 Big Switch Networks, Inc.
-# See the file LICENSE.pyloxi which should have been included in the source distribution
-# Automatically generated by LOXI from template toplevel_init.py
-# Do not modify
-
-version_names = {
-    1: "1.0",
-    2: "1.1",
-    3: "1.2",
-    4: "1.3",
-    5: "1.4",
-}
-
-def protocol(ver):
-    """
-    Import and return the protocol module for the given wire version.
-    """
-    if ver == 1:
-        import of10
-        return of10
-
-    if ver == 2:
-        import of11
-        return of11
-
-    if ver == 3:
-        import of12
-        return of12
-
-    if ver == 4:
-        import of13
-        return of13
-
-    if ver == 5:
-        import of14
-        return of14
-
-    raise ValueError
-
-class ProtocolError(Exception):
-    """
-    Raised when failing to deserialize an invalid OpenFlow message.
-    """
-    pass
-
-class Unimplemented(Exception):
-    """
-    Raised when an OpenFlow feature is not yet implemented in PyLoxi.
-    """
-    pass
-
-def unimplemented(msg):
-    raise Unimplemented(msg)
-
-class OFObject(object):
-    """
-    Superclass of all OpenFlow classes
-    """
-    def __init__(self, *args):
-        raise NotImplementedError("cannot instantiate abstract class")
-
-    def __ne__(self, other):
-        return not self.__eq__(other)
-
-    def show(self):
-        import loxi.pp
-        return loxi.pp.pp(self)
diff --git a/python/ofagent/loxi/connection.py b/python/ofagent/loxi/connection.py
deleted file mode 100644
index fc61161..0000000
--- a/python/ofagent/loxi/connection.py
+++ /dev/null
@@ -1,263 +0,0 @@
-# Copyright 2017-present Open Networking Foundation
-#
-# 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.
-# Copyright 2015, Big Switch Networks, Inc.
-
-"""
-OpenFlow connection class
-
-This class creates a thread which continually parses OpenFlow messages off the
-supplied socket and places them in a queue. The class has methods for reading messages
-from the RX queue, sending messages, and higher level operations like request-response
-and multipart transactions.
-"""
-
-import loxi
-import loxi.of14
-import logging
-import time
-import socket
-import errno
-import os
-import select
-from threading import Condition, Lock, Thread
-
-DEFAULT_TIMEOUT = 1
-
-class TransactionError(Exception):
-    def __str__(self):
-        return self.args[0]
-
-    @property
-    def msg(self):
-        return self.args[1]
-
-class ConnectionClosed(Exception):
-    pass
-
-class Connection(Thread):
-    def __init__(self, sock):
-        Thread.__init__(self)
-        self.sock = sock
-        self.logger = logging.getLogger("connection")
-        self.rx = []
-        self.rx_cv = Condition()
-        self.tx_lock = Lock()
-        self.next_xid = 1
-        self.wakeup_rd, self.wakeup_wr = os.pipe()
-        self.finished = False
-        self.read_buffer = None
-
-    def start(self):
-        while not self.finished:
-            try:
-                rd, wr, err = select.select([self.sock, self.wakeup_rd], [], [])
-            except select.error:
-                print 'SELECT ERROR!!!'
-            if self.sock in rd:
-                try:
-                    self.process_read()
-                except ConnectionClosed:
-                    self.logger.info("Connection to controller was dropped")
-                    self.finished = True
-            if self.wakeup_rd in rd:
-                os.read(self.wakeup_rd, 1)
-        self.logger.debug("Exited event loop")
-
-    def process_read(self):
-        recvd = self.sock.recv(4096)
-        if (len(recvd)) == 0:
-            # this indicates that the other end hang up
-            raise ConnectionClosed()
-
-        self.logger.debug("Received %d bytes", len(recvd))
-
-        buf = self.read_buffer
-        if buf:
-            buf += recvd
-        else:
-            buf = recvd
-
-        offset = 0
-        while offset < len(buf):
-            if offset + 8 > len(buf):
-                # Not enough data for the OpenFlow header
-                break
-
-            # Parse the header to get type
-            hdr_version, hdr_type, hdr_msglen, hdr_xid = loxi.of14.message.parse_header(buf[offset:])
-
-            # Use loxi to resolve ofp of matching version
-            ofp = loxi.protocol(hdr_version)
-
-            # Extract the raw message bytes
-            if (offset + hdr_msglen) > len(buf):
-                # Not enough data for the body
-                break
-            rawmsg = buf[offset : offset + hdr_msglen]
-            offset += hdr_msglen
-
-            msg = ofp.message.parse_message(rawmsg)
-            if not msg:
-                self.logger.warn("Could not parse message")
-                continue
-
-            self.logger.debug("Received message %s.%s xid %d length %d",
-                              type(msg).__module__, type(msg).__name__, hdr_xid, hdr_msglen)
-
-            with self.rx_cv:
-                self.rx.append(msg)
-                self.rx_cv.notify_all()
-
-        if offset == len(buf):
-            self.read_buffer = None
-        else:
-            self.read_buffer = buf[offset:]
-            self.logger.debug("%d bytes remaining", len(self.read_buffer))
-
-    def recv(self, predicate, timeout=DEFAULT_TIMEOUT):
-        """
-        Remove and return the first message in the RX queue for
-        which 'predicate' returns true
-        """
-        assert self.is_alive()
-
-        deadline = time.time() + timeout
-        while True:
-            with self.rx_cv:
-                for i, msg in enumerate(self.rx):
-                    if predicate(msg):
-                        return self.rx.pop(i)
-
-                now = time.time()
-                if now > deadline:
-                    return None
-                else:
-                    self.rx_cv.wait(deadline - now)
-
-    def recv_any(self, timeout=DEFAULT_TIMEOUT):
-        """
-        Return the first message in the RX queue
-        """
-        return self.recv(lambda msg: True, timeout)
-
-    def recv_xid(self, xid, timeout=DEFAULT_TIMEOUT):
-        """
-        Return the first message in the RX queue with XID 'xid'
-        """
-        return self.recv(lambda msg: msg.xid == xid, timeout)
-
-    def recv_class(self, klass, timeout=DEFAULT_TIMEOUT):
-        """
-        Return the first message in the RX queue which is an instance of 'klass'
-        """
-        return self.recv(lambda msg: isinstance(msg, klass), timeout)
-
-    def send_raw(self, buf):
-        """
-        Send raw bytes on the socket
-        """
-        assert self.is_alive()
-        self.logger.debug("Sending raw message length %d", len(buf))
-        with self.tx_lock:
-            if self.sock.sendall(buf) is not None:
-                raise RuntimeError("failed to send message to switch")
-
-    def send(self, msg):
-        """
-        Send a message
-        """
-        assert self.is_alive()
-
-        if msg.xid is None:
-            msg.xid = self._gen_xid()
-        buf = msg.pack()
-        self.logger.debug("Sending message %s.%s xid %d length %d",
-                          type(msg).__module__, type(msg).__name__, msg.xid, len(buf))
-        with self.tx_lock:
-            if self.sock.sendall(buf) is not None:
-                raise RuntimeError("failed to send message to switch")
-
-    def transact(self, msg, timeout=DEFAULT_TIMEOUT):
-        """
-        Send a message and return the reply
-        """
-        self.send(msg)
-        reply = self.recv_xid(msg.xid, timeout)
-        if reply is None:
-            raise TransactionError("no reply for %s" % type(msg).__name__, None)
-        elif isinstance(reply, loxi.protocol(reply.version).message.error_msg):
-            raise TransactionError("received %s in response to %s" % (type(reply).__name__, type(msg).__name__), reply)
-        return reply
-
-    def transact_multipart_generator(self, msg, timeout=DEFAULT_TIMEOUT):
-        """
-        Send a multipart request and yield each entry from the replies
-        """
-        self.send(msg)
-        finished = False
-        while not finished:
-            reply = self.recv_xid(msg.xid, timeout)
-            if reply is None:
-                raise TransactionError("no reply for %s" % type(msg).__name__, None)
-            elif not isinstance(reply, loxi.protocol(reply.version).message.stats_reply):
-                raise TransactionError("received %s in response to %s" % (type(reply).__name__, type(msg).__name__), reply)
-            for entry in reply.entries:
-                yield entry
-            finished = reply.flags & loxi.protocol(reply.version).OFPSF_REPLY_MORE == 0
-
-    def transact_multipart(self, msg, timeout=DEFAULT_TIMEOUT):
-        """
-        Send a multipart request and return all entries from the replies
-        """
-        entries = []
-        for entry in self.transact_multipart_generator(msg, timeout):
-            entries.append(entry)
-        return entries
-
-    def stop(self):
-        """
-        Signal the thread to exit and wait for it
-        """
-        assert not self.finished
-        self.logger.debug("Stopping connection")
-        self.finished = True
-        os.write(self.wakeup_wr, "x")
-        self.join()
-        self.sock.close()
-        os.close(self.wakeup_rd)
-        os.close(self.wakeup_wr)
-        self.logger.debug("Stopped connection")
-
-    def _gen_xid(self):
-        xid = self.next_xid
-        self.next_xid += 1
-        return xid
-
-def connect(ip, port=6653, daemon=True, ofp=loxi.of14):
-    """
-    Actively connect to a switch
-    """
-    soc = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
-    soc.connect((ip, port))
-    soc.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, True)
-    cxn = Connection(soc)
-    cxn.daemon = daemon
-    cxn.logger.debug("Connected to %s:%d", ip, port)
-    cxn.start()
-
-    cxn.send(ofp.message.hello())
-    if not cxn.recv(lambda msg: msg.type == ofp.OFPT_HELLO):
-        raise Exception("Did not receive HELLO")
-
-    return cxn
diff --git a/python/ofagent/loxi/generic_util.py b/python/ofagent/loxi/generic_util.py
deleted file mode 100644
index 7cbf32e..0000000
--- a/python/ofagent/loxi/generic_util.py
+++ /dev/null
@@ -1,113 +0,0 @@
-# Copyright 2017-present Open Networking Foundation
-#
-# 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.
-# Copyright (c) 2008 The Board of Trustees of The Leland Stanford Junior University
-# Copyright (c) 2011, 2012 Open Networking Foundation
-# Copyright (c) 2012, 2013 Big Switch Networks, Inc.
-# See the file LICENSE.pyloxi which should have been included in the source distribution
-"""
-Utility functions independent of the protocol version
-"""
-
-# Automatically generated by LOXI from template generic_util.py
-# Do not modify
-
-import loxi
-import struct
-
-def pack_list(values):
-    return "".join([x.pack() for x in values])
-
-def unpack_list(reader, deserializer):
-    """
-    The deserializer function should take an OFReader and return the new object.
-    """
-    entries = []
-    while not reader.is_empty():
-        entries.append(deserializer(reader))
-    return entries
-
-def pad_to(alignment, length):
-    """
-    Return a string of zero bytes that will pad a string of length 'length' to
-    a multiple of 'alignment'.
-    """
-    return "\x00" * ((length + alignment - 1)/alignment*alignment - length)
-
-class OFReader(object):
-    """
-    Cursor over a read-only buffer
-
-    OpenFlow messages are best thought of as a sequence of elements of
-    variable size, rather than a C-style struct with fixed offsets and
-    known field lengths. This class supports efficiently reading
-    fields sequentially and is intended to be used recursively by the
-    parsers of child objects which will implicitly update the offset.
-
-    buf: buffer object
-    start: initial position in the buffer
-    length: number of bytes after start
-    offset: distance from start
-    """
-    def __init__(self, buf, start=0, length=None):
-        self.buf = buf
-        self.start = start
-        if length is None:
-            self.length = len(buf) - start
-        else:
-            self.length = length
-        self.offset = 0
-
-    def read(self, fmt):
-        st = struct.Struct(fmt)
-        if self.offset + st.size > self.length:
-            raise loxi.ProtocolError("Buffer too short")
-        result = st.unpack_from(self.buf, self.start+self.offset)
-        self.offset += st.size
-        return result
-
-    def read_all(self):
-        s = self.buf[(self.start+self.offset):(self.start+self.length)]
-        assert(len(s) == self.length - self.offset)
-        self.offset = self.length
-        return s
-
-    def peek(self, fmt, offset=0):
-        st = struct.Struct(fmt)
-        if self.offset + offset + st.size > self.length:
-            raise loxi.ProtocolError("Buffer too short")
-        result = st.unpack_from(self.buf, self.start + self.offset + offset)
-        return result
-
-    def skip(self, length):
-        if self.offset + length > self.length:
-            raise loxi.ProtocolError("Buffer too short")
-        self.offset += length
-
-    def skip_align(self):
-        new_offset = (self.offset + 7) / 8 * 8
-        if new_offset > self.length:
-            raise loxi.ProtocolError("Buffer too short")
-        self.offset = new_offset
-
-    def is_empty(self):
-        return self.offset == self.length
-
-    # Used when parsing objects that have their own length fields
-    def slice(self, length, rewind=0):
-        if self.offset + length - rewind > self.length:
-            raise loxi.ProtocolError("Buffer too short")
-        reader = OFReader(self.buf, self.start + self.offset - rewind, length)
-        reader.skip(rewind)
-        self.offset += length - rewind
-        return reader
diff --git a/python/ofagent/loxi/of10/__init__.py b/python/ofagent/loxi/of10/__init__.py
deleted file mode 100644
index d4457f5..0000000
--- a/python/ofagent/loxi/of10/__init__.py
+++ /dev/null
@@ -1,28 +0,0 @@
-# Copyright 2017-present Open Networking Foundation
-#
-# 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.
-# Copyright (c) 2008 The Board of Trustees of The Leland Stanford Junior University
-# Copyright (c) 2011, 2012 Open Networking Foundation
-# Copyright (c) 2012, 2013 Big Switch Networks, Inc.
-# See the file LICENSE.pyloxi which should have been included in the source distribution
-
-# Automatically generated by LOXI from template init.py
-# Do not modify
-
-import const
-import action
-import message
-import common
-from const import *
-from common import *
-from loxi import ProtocolError
diff --git a/python/ofagent/loxi/of10/action.py b/python/ofagent/loxi/of10/action.py
deleted file mode 100644
index 43702f0..0000000
--- a/python/ofagent/loxi/of10/action.py
+++ /dev/null
@@ -1,1088 +0,0 @@
-# Copyright 2017-present Open Networking Foundation
-#
-# 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.
-# Copyright (c) 2008 The Board of Trustees of The Leland Stanford Junior University
-# Copyright (c) 2011, 2012 Open Networking Foundation
-# Copyright (c) 2012, 2013 Big Switch Networks, Inc.
-# See the file LICENSE.pyloxi which should have been included in the source distribution
-
-# Automatically generated by LOXI from template module.py
-# Do not modify
-
-import struct
-import loxi
-import util
-import loxi.generic_util
-
-import sys
-ofp = sys.modules['loxi.of10']
-
-class action(loxi.OFObject):
-    subtypes = {}
-
-
-    def __init__(self, type=None):
-        if type != None:
-            self.type = type
-        else:
-            self.type = 0
-        return
-
-    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('\x00' * 4)
-        length = sum([len(x) for x in packed])
-        packed[1] = struct.pack("!H", length)
-        return ''.join(packed)
-
-    @staticmethod
-    def unpack(reader):
-        subtype, = reader.peek('!H', 0)
-        subclass = action.subtypes.get(subtype)
-        if subclass:
-            return subclass.unpack(reader)
-
-        obj = action()
-        obj.type = reader.read("!H")[0]
-        _len = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_len, 4)
-        reader.skip(4)
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): return False
-        if self.type != other.type: return False
-        return True
-
-    def pretty_print(self, q):
-        q.text("action {")
-        with q.group():
-            with q.indent(2):
-                q.breakable()
-            q.breakable()
-        q.text('}')
-
-
-class experimenter(action):
-    subtypes = {}
-
-    type = 65535
-
-    def __init__(self, experimenter=None, data=None):
-        if experimenter != None:
-            self.experimenter = experimenter
-        else:
-            self.experimenter = 0
-        if data != None:
-            self.data = data
-        else:
-            self.data = ''
-        return
-
-    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(self.data)
-        length = sum([len(x) for x in packed])
-        packed[1] = struct.pack("!H", length)
-        return ''.join(packed)
-
-    @staticmethod
-    def unpack(reader):
-        subtype, = reader.peek('!L', 4)
-        subclass = experimenter.subtypes.get(subtype)
-        if subclass:
-            return subclass.unpack(reader)
-
-        obj = experimenter()
-        _type = reader.read("!H")[0]
-        assert(_type == 65535)
-        _len = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_len, 4)
-        obj.experimenter = reader.read("!L")[0]
-        obj.data = str(reader.read_all())
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): return False
-        if self.experimenter != other.experimenter: return False
-        if self.data != other.data: return False
-        return True
-
-    def pretty_print(self, q):
-        q.text("experimenter {")
-        with q.group():
-            with q.indent(2):
-                q.breakable()
-                q.text("data = ");
-                q.pp(self.data)
-            q.breakable()
-        q.text('}')
-
-action.subtypes[65535] = experimenter
-
-class bsn(experimenter):
-    subtypes = {}
-
-    type = 65535
-    experimenter = 6035143
-
-    def __init__(self, subtype=None):
-        if subtype != None:
-            self.subtype = subtype
-        else:
-            self.subtype = 0
-        return
-
-    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('\x00' * 4)
-        length = sum([len(x) for x in packed])
-        packed[1] = struct.pack("!H", length)
-        return ''.join(packed)
-
-    @staticmethod
-    def unpack(reader):
-        subtype, = reader.peek('!L', 8)
-        subclass = bsn.subtypes.get(subtype)
-        if subclass:
-            return subclass.unpack(reader)
-
-        obj = bsn()
-        _type = reader.read("!H")[0]
-        assert(_type == 65535)
-        _len = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_len, 4)
-        _experimenter = reader.read("!L")[0]
-        assert(_experimenter == 6035143)
-        obj.subtype = reader.read("!L")[0]
-        reader.skip(4)
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): return False
-        if self.subtype != other.subtype: return False
-        return True
-
-    def pretty_print(self, q):
-        q.text("bsn {")
-        with q.group():
-            with q.indent(2):
-                q.breakable()
-            q.breakable()
-        q.text('}')
-
-experimenter.subtypes[6035143] = bsn
-
-class bsn_checksum(bsn):
-    type = 65535
-    experimenter = 6035143
-    subtype = 4
-
-    def __init__(self, checksum=None):
-        if checksum != None:
-            self.checksum = checksum
-        else:
-            self.checksum = 0
-        return
-
-    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(util.pack_checksum_128(self.checksum))
-        length = sum([len(x) for x in packed])
-        packed[1] = struct.pack("!H", length)
-        return ''.join(packed)
-
-    @staticmethod
-    def unpack(reader):
-        obj = bsn_checksum()
-        _type = reader.read("!H")[0]
-        assert(_type == 65535)
-        _len = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_len, 4)
-        _experimenter = reader.read("!L")[0]
-        assert(_experimenter == 6035143)
-        _subtype = reader.read("!L")[0]
-        assert(_subtype == 4)
-        obj.checksum = util.unpack_checksum_128(reader)
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): return False
-        if self.checksum != other.checksum: return False
-        return True
-
-    def pretty_print(self, q):
-        q.text("bsn_checksum {")
-        with q.group():
-            with q.indent(2):
-                q.breakable()
-                q.text("checksum = ");
-                q.pp(self.checksum)
-            q.breakable()
-        q.text('}')
-
-bsn.subtypes[4] = bsn_checksum
-
-class bsn_mirror(bsn):
-    type = 65535
-    experimenter = 6035143
-    subtype = 1
-
-    def __init__(self, dest_port=None, vlan_tag=None, copy_stage=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
-        return
-
-    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('\x00' * 3)
-        length = sum([len(x) for x in packed])
-        packed[1] = struct.pack("!H", length)
-        return ''.join(packed)
-
-    @staticmethod
-    def unpack(reader):
-        obj = bsn_mirror()
-        _type = reader.read("!H")[0]
-        assert(_type == 65535)
-        _len = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_len, 4)
-        _experimenter = reader.read("!L")[0]
-        assert(_experimenter == 6035143)
-        _subtype = reader.read("!L")[0]
-        assert(_subtype == 1)
-        obj.dest_port = reader.read("!L")[0]
-        obj.vlan_tag = reader.read("!L")[0]
-        obj.copy_stage = reader.read("!B")[0]
-        reader.skip(3)
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): 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
-        return True
-
-    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.breakable()
-        q.text('}')
-
-bsn.subtypes[1] = bsn_mirror
-
-class bsn_set_tunnel_dst(bsn):
-    type = 65535
-    experimenter = 6035143
-    subtype = 2
-
-    def __init__(self, dst=None):
-        if dst != None:
-            self.dst = dst
-        else:
-            self.dst = 0
-        return
-
-    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(reader):
-        obj = bsn_set_tunnel_dst()
-        _type = reader.read("!H")[0]
-        assert(_type == 65535)
-        _len = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_len, 4)
-        _experimenter = reader.read("!L")[0]
-        assert(_experimenter == 6035143)
-        _subtype = reader.read("!L")[0]
-        assert(_subtype == 2)
-        obj.dst = reader.read("!L")[0]
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): return False
-        if self.dst != other.dst: return False
-        return True
-
-    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('}')
-
-bsn.subtypes[2] = bsn_set_tunnel_dst
-
-class enqueue(action):
-    type = 11
-
-    def __init__(self, port=None, queue_id=None):
-        if port != None:
-            self.port = port
-        else:
-            self.port = 0
-        if queue_id != None:
-            self.queue_id = queue_id
-        else:
-            self.queue_id = 0
-        return
-
-    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(util.pack_port_no(self.port))
-        packed.append('\x00' * 6)
-        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(reader):
-        obj = enqueue()
-        _type = reader.read("!H")[0]
-        assert(_type == 11)
-        _len = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_len, 4)
-        obj.port = util.unpack_port_no(reader)
-        reader.skip(6)
-        obj.queue_id = reader.read("!L")[0]
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): return False
-        if self.port != other.port: return False
-        if self.queue_id != other.queue_id: return False
-        return True
-
-    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("queue_id = ");
-                q.text("%#x" % self.queue_id)
-            q.breakable()
-        q.text('}')
-
-action.subtypes[11] = enqueue
-
-class nicira(experimenter):
-    subtypes = {}
-
-    type = 65535
-    experimenter = 8992
-
-    def __init__(self, subtype=None):
-        if subtype != None:
-            self.subtype = subtype
-        else:
-            self.subtype = 0
-        return
-
-    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('\x00' * 2)
-        packed.append('\x00' * 4)
-        length = sum([len(x) for x in packed])
-        packed[1] = struct.pack("!H", length)
-        return ''.join(packed)
-
-    @staticmethod
-    def unpack(reader):
-        subtype, = reader.peek('!H', 8)
-        subclass = nicira.subtypes.get(subtype)
-        if subclass:
-            return subclass.unpack(reader)
-
-        obj = nicira()
-        _type = reader.read("!H")[0]
-        assert(_type == 65535)
-        _len = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_len, 4)
-        _experimenter = reader.read("!L")[0]
-        assert(_experimenter == 8992)
-        obj.subtype = reader.read("!H")[0]
-        reader.skip(2)
-        reader.skip(4)
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): return False
-        if self.subtype != other.subtype: return False
-        return True
-
-    def pretty_print(self, q):
-        q.text("nicira {")
-        with q.group():
-            with q.indent(2):
-                q.breakable()
-            q.breakable()
-        q.text('}')
-
-experimenter.subtypes[8992] = nicira
-
-class nicira_dec_ttl(nicira):
-    type = 65535
-    experimenter = 8992
-    subtype = 18
-
-    def __init__(self):
-        return
-
-    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('\x00' * 2)
-        packed.append('\x00' * 4)
-        length = sum([len(x) for x in packed])
-        packed[1] = struct.pack("!H", length)
-        return ''.join(packed)
-
-    @staticmethod
-    def unpack(reader):
-        obj = nicira_dec_ttl()
-        _type = reader.read("!H")[0]
-        assert(_type == 65535)
-        _len = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_len, 4)
-        _experimenter = reader.read("!L")[0]
-        assert(_experimenter == 8992)
-        _subtype = reader.read("!H")[0]
-        assert(_subtype == 18)
-        reader.skip(2)
-        reader.skip(4)
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): return False
-        return True
-
-    def pretty_print(self, q):
-        q.text("nicira_dec_ttl {")
-        with q.group():
-            with q.indent(2):
-                q.breakable()
-            q.breakable()
-        q.text('}')
-
-nicira.subtypes[18] = nicira_dec_ttl
-
-class output(action):
-    type = 0
-
-    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
-        return
-
-    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(util.pack_port_no(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(reader):
-        obj = output()
-        _type = reader.read("!H")[0]
-        assert(_type == 0)
-        _len = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_len, 4)
-        obj.port = util.unpack_port_no(reader)
-        obj.max_len = reader.read("!H")[0]
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): return False
-        if self.port != other.port: return False
-        if self.max_len != other.max_len: return False
-        return True
-
-    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('}')
-
-action.subtypes[0] = output
-
-class set_dl_dst(action):
-    type = 5
-
-    def __init__(self, dl_addr=None):
-        if dl_addr != None:
-            self.dl_addr = dl_addr
-        else:
-            self.dl_addr = [0,0,0,0,0,0]
-        return
-
-    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('\x00' * 6)
-        length = sum([len(x) for x in packed])
-        packed[1] = struct.pack("!H", length)
-        return ''.join(packed)
-
-    @staticmethod
-    def unpack(reader):
-        obj = set_dl_dst()
-        _type = reader.read("!H")[0]
-        assert(_type == 5)
-        _len = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_len, 4)
-        obj.dl_addr = list(reader.read('!6B'))
-        reader.skip(6)
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): return False
-        if self.dl_addr != other.dl_addr: return False
-        return True
-
-    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.breakable()
-        q.text('}')
-
-action.subtypes[5] = set_dl_dst
-
-class set_dl_src(action):
-    type = 4
-
-    def __init__(self, dl_addr=None):
-        if dl_addr != None:
-            self.dl_addr = dl_addr
-        else:
-            self.dl_addr = [0,0,0,0,0,0]
-        return
-
-    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('\x00' * 6)
-        length = sum([len(x) for x in packed])
-        packed[1] = struct.pack("!H", length)
-        return ''.join(packed)
-
-    @staticmethod
-    def unpack(reader):
-        obj = set_dl_src()
-        _type = reader.read("!H")[0]
-        assert(_type == 4)
-        _len = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_len, 4)
-        obj.dl_addr = list(reader.read('!6B'))
-        reader.skip(6)
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): return False
-        if self.dl_addr != other.dl_addr: return False
-        return True
-
-    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.breakable()
-        q.text('}')
-
-action.subtypes[4] = set_dl_src
-
-class set_nw_dst(action):
-    type = 7
-
-    def __init__(self, nw_addr=None):
-        if nw_addr != None:
-            self.nw_addr = nw_addr
-        else:
-            self.nw_addr = 0
-        return
-
-    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(reader):
-        obj = set_nw_dst()
-        _type = reader.read("!H")[0]
-        assert(_type == 7)
-        _len = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_len, 4)
-        obj.nw_addr = reader.read("!L")[0]
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): return False
-        if self.nw_addr != other.nw_addr: return False
-        return True
-
-    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('}')
-
-action.subtypes[7] = set_nw_dst
-
-class set_nw_src(action):
-    type = 6
-
-    def __init__(self, nw_addr=None):
-        if nw_addr != None:
-            self.nw_addr = nw_addr
-        else:
-            self.nw_addr = 0
-        return
-
-    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(reader):
-        obj = set_nw_src()
-        _type = reader.read("!H")[0]
-        assert(_type == 6)
-        _len = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_len, 4)
-        obj.nw_addr = reader.read("!L")[0]
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): return False
-        if self.nw_addr != other.nw_addr: return False
-        return True
-
-    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('}')
-
-action.subtypes[6] = set_nw_src
-
-class set_nw_tos(action):
-    type = 8
-
-    def __init__(self, nw_tos=None):
-        if nw_tos != None:
-            self.nw_tos = nw_tos
-        else:
-            self.nw_tos = 0
-        return
-
-    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('\x00' * 3)
-        length = sum([len(x) for x in packed])
-        packed[1] = struct.pack("!H", length)
-        return ''.join(packed)
-
-    @staticmethod
-    def unpack(reader):
-        obj = set_nw_tos()
-        _type = reader.read("!H")[0]
-        assert(_type == 8)
-        _len = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_len, 4)
-        obj.nw_tos = reader.read("!B")[0]
-        reader.skip(3)
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): return False
-        if self.nw_tos != other.nw_tos: return False
-        return True
-
-    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.breakable()
-        q.text('}')
-
-action.subtypes[8] = set_nw_tos
-
-class set_tp_dst(action):
-    type = 10
-
-    def __init__(self, tp_port=None):
-        if tp_port != None:
-            self.tp_port = tp_port
-        else:
-            self.tp_port = 0
-        return
-
-    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('\x00' * 2)
-        length = sum([len(x) for x in packed])
-        packed[1] = struct.pack("!H", length)
-        return ''.join(packed)
-
-    @staticmethod
-    def unpack(reader):
-        obj = set_tp_dst()
-        _type = reader.read("!H")[0]
-        assert(_type == 10)
-        _len = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_len, 4)
-        obj.tp_port = reader.read("!H")[0]
-        reader.skip(2)
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): return False
-        if self.tp_port != other.tp_port: return False
-        return True
-
-    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.breakable()
-        q.text('}')
-
-action.subtypes[10] = set_tp_dst
-
-class set_tp_src(action):
-    type = 9
-
-    def __init__(self, tp_port=None):
-        if tp_port != None:
-            self.tp_port = tp_port
-        else:
-            self.tp_port = 0
-        return
-
-    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('\x00' * 2)
-        length = sum([len(x) for x in packed])
-        packed[1] = struct.pack("!H", length)
-        return ''.join(packed)
-
-    @staticmethod
-    def unpack(reader):
-        obj = set_tp_src()
-        _type = reader.read("!H")[0]
-        assert(_type == 9)
-        _len = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_len, 4)
-        obj.tp_port = reader.read("!H")[0]
-        reader.skip(2)
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): return False
-        if self.tp_port != other.tp_port: return False
-        return True
-
-    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.breakable()
-        q.text('}')
-
-action.subtypes[9] = set_tp_src
-
-class set_vlan_pcp(action):
-    type = 2
-
-    def __init__(self, vlan_pcp=None):
-        if vlan_pcp != None:
-            self.vlan_pcp = vlan_pcp
-        else:
-            self.vlan_pcp = 0
-        return
-
-    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('\x00' * 3)
-        length = sum([len(x) for x in packed])
-        packed[1] = struct.pack("!H", length)
-        return ''.join(packed)
-
-    @staticmethod
-    def unpack(reader):
-        obj = set_vlan_pcp()
-        _type = reader.read("!H")[0]
-        assert(_type == 2)
-        _len = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_len, 4)
-        obj.vlan_pcp = reader.read("!B")[0]
-        reader.skip(3)
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): return False
-        if self.vlan_pcp != other.vlan_pcp: return False
-        return True
-
-    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.breakable()
-        q.text('}')
-
-action.subtypes[2] = set_vlan_pcp
-
-class set_vlan_vid(action):
-    type = 1
-
-    def __init__(self, vlan_vid=None):
-        if vlan_vid != None:
-            self.vlan_vid = vlan_vid
-        else:
-            self.vlan_vid = 0
-        return
-
-    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('\x00' * 2)
-        length = sum([len(x) for x in packed])
-        packed[1] = struct.pack("!H", length)
-        return ''.join(packed)
-
-    @staticmethod
-    def unpack(reader):
-        obj = set_vlan_vid()
-        _type = reader.read("!H")[0]
-        assert(_type == 1)
-        _len = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_len, 4)
-        obj.vlan_vid = reader.read("!H")[0]
-        reader.skip(2)
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): return False
-        if self.vlan_vid != other.vlan_vid: return False
-        return True
-
-    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.breakable()
-        q.text('}')
-
-action.subtypes[1] = set_vlan_vid
-
-class strip_vlan(action):
-    type = 3
-
-    def __init__(self):
-        return
-
-    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('\x00' * 4)
-        length = sum([len(x) for x in packed])
-        packed[1] = struct.pack("!H", length)
-        return ''.join(packed)
-
-    @staticmethod
-    def unpack(reader):
-        obj = strip_vlan()
-        _type = reader.read("!H")[0]
-        assert(_type == 3)
-        _len = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_len, 4)
-        reader.skip(4)
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): return False
-        return True
-
-    def pretty_print(self, q):
-        q.text("strip_vlan {")
-        with q.group():
-            with q.indent(2):
-                q.breakable()
-            q.breakable()
-        q.text('}')
-
-action.subtypes[3] = strip_vlan
-
-
diff --git a/python/ofagent/loxi/of10/common.py b/python/ofagent/loxi/of10/common.py
deleted file mode 100644
index e7bd77d..0000000
--- a/python/ofagent/loxi/of10/common.py
+++ /dev/null
@@ -1,1312 +0,0 @@
-# Copyright 2017-present Open Networking Foundation
-#
-# 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.
-# Copyright (c) 2008 The Board of Trustees of The Leland Stanford Junior University
-# Copyright (c) 2011, 2012 Open Networking Foundation
-# Copyright (c) 2012, 2013 Big Switch Networks, Inc.
-# See the file LICENSE.pyloxi which should have been included in the source distribution
-
-# Automatically generated by LOXI from template module.py
-# Do not modify
-
-import struct
-import loxi
-import util
-import loxi.generic_util
-
-import sys
-ofp = sys.modules['loxi.of10']
-
-class bsn_interface(loxi.OFObject):
-
-    def __init__(self, hw_addr=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 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
-        return
-
-    def pack(self):
-        packed = []
-        packed.append(struct.pack("!6B", *self.hw_addr))
-        packed.append('\x00' * 2)
-        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(reader):
-        obj = bsn_interface()
-        obj.hw_addr = list(reader.read('!6B'))
-        reader.skip(2)
-        obj.name = reader.read("!16s")[0].rstrip("\x00")
-        obj.ipv4_addr = reader.read("!L")[0]
-        obj.ipv4_netmask = reader.read("!L")[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.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 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("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 bsn_vport(loxi.OFObject):
-    subtypes = {}
-
-
-    def __init__(self, type=None):
-        if type != None:
-            self.type = type
-        else:
-            self.type = 0
-        return
-
-    def pack(self):
-        packed = []
-        packed.append(struct.pack("!H", self.type))
-        packed.append(struct.pack("!H", 0)) # placeholder for length at index 1
-        length = sum([len(x) for x in packed])
-        packed[1] = struct.pack("!H", length)
-        return ''.join(packed)
-
-    @staticmethod
-    def unpack(reader):
-        subtype, = reader.peek('!H', 0)
-        subclass = bsn_vport.subtypes.get(subtype)
-        if subclass:
-            return subclass.unpack(reader)
-
-        obj = bsn_vport()
-        obj.type = reader.read("!H")[0]
-        _length = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_length, 4)
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): return False
-        if self.type != other.type: return False
-        return True
-
-    def pretty_print(self, q):
-        q.text("bsn_vport {")
-        with q.group():
-            with q.indent(2):
-                q.breakable()
-            q.breakable()
-        q.text('}')
-
-
-class bsn_vport_l2gre(bsn_vport):
-    type = 1
-
-    def __init__(self, flags=None, port_no=None, loopback_port_no=None, local_mac=None, nh_mac=None, src_ip=None, dst_ip=None, dscp=None, ttl=None, vpn=None, rate_limit=None, if_name=None):
-        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 loopback_port_no != None:
-            self.loopback_port_no = loopback_port_no
-        else:
-            self.loopback_port_no = 0
-        if local_mac != None:
-            self.local_mac = local_mac
-        else:
-            self.local_mac = [0,0,0,0,0,0]
-        if nh_mac != None:
-            self.nh_mac = nh_mac
-        else:
-            self.nh_mac = [0,0,0,0,0,0]
-        if src_ip != None:
-            self.src_ip = src_ip
-        else:
-            self.src_ip = 0
-        if dst_ip != None:
-            self.dst_ip = dst_ip
-        else:
-            self.dst_ip = 0
-        if dscp != None:
-            self.dscp = dscp
-        else:
-            self.dscp = 0
-        if ttl != None:
-            self.ttl = ttl
-        else:
-            self.ttl = 0
-        if vpn != None:
-            self.vpn = vpn
-        else:
-            self.vpn = 0
-        if rate_limit != None:
-            self.rate_limit = rate_limit
-        else:
-            self.rate_limit = 0
-        if if_name != None:
-            self.if_name = if_name
-        else:
-            self.if_name = ""
-        return
-
-    def pack(self):
-        packed = []
-        packed.append(struct.pack("!H", self.type))
-        packed.append(struct.pack("!H", 0)) # placeholder for length at index 1
-        packed.append(struct.pack("!L", self.flags))
-        packed.append(util.pack_port_no(self.port_no))
-        packed.append(util.pack_port_no(self.loopback_port_no))
-        packed.append(struct.pack("!6B", *self.local_mac))
-        packed.append(struct.pack("!6B", *self.nh_mac))
-        packed.append(struct.pack("!L", self.src_ip))
-        packed.append(struct.pack("!L", self.dst_ip))
-        packed.append(struct.pack("!B", self.dscp))
-        packed.append(struct.pack("!B", self.ttl))
-        packed.append('\x00' * 2)
-        packed.append(struct.pack("!L", self.vpn))
-        packed.append(struct.pack("!L", self.rate_limit))
-        packed.append(struct.pack("!16s", self.if_name))
-        length = sum([len(x) for x in packed])
-        packed[1] = struct.pack("!H", length)
-        return ''.join(packed)
-
-    @staticmethod
-    def unpack(reader):
-        obj = bsn_vport_l2gre()
-        _type = reader.read("!H")[0]
-        assert(_type == 1)
-        _length = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_length, 4)
-        obj.flags = reader.read("!L")[0]
-        obj.port_no = util.unpack_port_no(reader)
-        obj.loopback_port_no = util.unpack_port_no(reader)
-        obj.local_mac = list(reader.read('!6B'))
-        obj.nh_mac = list(reader.read('!6B'))
-        obj.src_ip = reader.read("!L")[0]
-        obj.dst_ip = reader.read("!L")[0]
-        obj.dscp = reader.read("!B")[0]
-        obj.ttl = reader.read("!B")[0]
-        reader.skip(2)
-        obj.vpn = reader.read("!L")[0]
-        obj.rate_limit = reader.read("!L")[0]
-        obj.if_name = reader.read("!16s")[0].rstrip("\x00")
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): return False
-        if self.flags != other.flags: return False
-        if self.port_no != other.port_no: return False
-        if self.loopback_port_no != other.loopback_port_no: return False
-        if self.local_mac != other.local_mac: return False
-        if self.nh_mac != other.nh_mac: return False
-        if self.src_ip != other.src_ip: return False
-        if self.dst_ip != other.dst_ip: return False
-        if self.dscp != other.dscp: return False
-        if self.ttl != other.ttl: return False
-        if self.vpn != other.vpn: return False
-        if self.rate_limit != other.rate_limit: return False
-        if self.if_name != other.if_name: return False
-        return True
-
-    def pretty_print(self, q):
-        q.text("bsn_vport_l2gre {")
-        with q.group():
-            with q.indent(2):
-                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("loopback_port_no = ");
-                q.text(util.pretty_port(self.loopback_port_no))
-                q.text(","); q.breakable()
-                q.text("local_mac = ");
-                q.text(util.pretty_mac(self.local_mac))
-                q.text(","); q.breakable()
-                q.text("nh_mac = ");
-                q.text(util.pretty_mac(self.nh_mac))
-                q.text(","); q.breakable()
-                q.text("src_ip = ");
-                q.text(util.pretty_ipv4(self.src_ip))
-                q.text(","); q.breakable()
-                q.text("dst_ip = ");
-                q.text(util.pretty_ipv4(self.dst_ip))
-                q.text(","); q.breakable()
-                q.text("dscp = ");
-                q.text("%#x" % self.dscp)
-                q.text(","); q.breakable()
-                q.text("ttl = ");
-                q.text("%#x" % self.ttl)
-                q.text(","); q.breakable()
-                q.text("vpn = ");
-                q.text("%#x" % self.vpn)
-                q.text(","); q.breakable()
-                q.text("rate_limit = ");
-                q.text("%#x" % self.rate_limit)
-                q.text(","); q.breakable()
-                q.text("if_name = ");
-                q.pp(self.if_name)
-            q.breakable()
-        q.text('}')
-
-bsn_vport.subtypes[1] = bsn_vport_l2gre
-
-class bsn_vport_q_in_q(bsn_vport):
-    type = 0
-
-    def __init__(self, port_no=None, ingress_tpid=None, ingress_vlan_id=None, egress_tpid=None, egress_vlan_id=None, if_name=None):
-        if port_no != None:
-            self.port_no = port_no
-        else:
-            self.port_no = 0
-        if ingress_tpid != None:
-            self.ingress_tpid = ingress_tpid
-        else:
-            self.ingress_tpid = 0
-        if ingress_vlan_id != None:
-            self.ingress_vlan_id = ingress_vlan_id
-        else:
-            self.ingress_vlan_id = 0
-        if egress_tpid != None:
-            self.egress_tpid = egress_tpid
-        else:
-            self.egress_tpid = 0
-        if egress_vlan_id != None:
-            self.egress_vlan_id = egress_vlan_id
-        else:
-            self.egress_vlan_id = 0
-        if if_name != None:
-            self.if_name = if_name
-        else:
-            self.if_name = ""
-        return
-
-    def pack(self):
-        packed = []
-        packed.append(struct.pack("!H", self.type))
-        packed.append(struct.pack("!H", 0)) # placeholder for length at index 1
-        packed.append(struct.pack("!L", self.port_no))
-        packed.append(struct.pack("!H", self.ingress_tpid))
-        packed.append(struct.pack("!H", self.ingress_vlan_id))
-        packed.append(struct.pack("!H", self.egress_tpid))
-        packed.append(struct.pack("!H", self.egress_vlan_id))
-        packed.append(struct.pack("!16s", self.if_name))
-        length = sum([len(x) for x in packed])
-        packed[1] = struct.pack("!H", length)
-        return ''.join(packed)
-
-    @staticmethod
-    def unpack(reader):
-        obj = bsn_vport_q_in_q()
-        _type = reader.read("!H")[0]
-        assert(_type == 0)
-        _length = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_length, 4)
-        obj.port_no = reader.read("!L")[0]
-        obj.ingress_tpid = reader.read("!H")[0]
-        obj.ingress_vlan_id = reader.read("!H")[0]
-        obj.egress_tpid = reader.read("!H")[0]
-        obj.egress_vlan_id = reader.read("!H")[0]
-        obj.if_name = reader.read("!16s")[0].rstrip("\x00")
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): return False
-        if self.port_no != other.port_no: return False
-        if self.ingress_tpid != other.ingress_tpid: return False
-        if self.ingress_vlan_id != other.ingress_vlan_id: return False
-        if self.egress_tpid != other.egress_tpid: return False
-        if self.egress_vlan_id != other.egress_vlan_id: return False
-        if self.if_name != other.if_name: return False
-        return True
-
-    def pretty_print(self, q):
-        q.text("bsn_vport_q_in_q {")
-        with q.group():
-            with q.indent(2):
-                q.breakable()
-                q.text("port_no = ");
-                q.text("%#x" % self.port_no)
-                q.text(","); q.breakable()
-                q.text("ingress_tpid = ");
-                q.text("%#x" % self.ingress_tpid)
-                q.text(","); q.breakable()
-                q.text("ingress_vlan_id = ");
-                q.text("%#x" % self.ingress_vlan_id)
-                q.text(","); q.breakable()
-                q.text("egress_tpid = ");
-                q.text("%#x" % self.egress_tpid)
-                q.text(","); q.breakable()
-                q.text("egress_vlan_id = ");
-                q.text("%#x" % self.egress_vlan_id)
-                q.text(","); q.breakable()
-                q.text("if_name = ");
-                q.pp(self.if_name)
-            q.breakable()
-        q.text('}')
-
-bsn_vport.subtypes[0] = bsn_vport_q_in_q
-
-class flow_stats_entry(loxi.OFObject):
-
-    def __init__(self, table_id=None, match=None, duration_sec=None, duration_nsec=None, priority=None, idle_timeout=None, hard_timeout=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 match != None:
-            self.match = match
-        else:
-            self.match = ofp.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 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 = []
-        return
-
-    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('\x00' * 1)
-        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('\x00' * 6)
-        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(loxi.generic_util.pack_list(self.actions))
-        length = sum([len(x) for x in packed])
-        packed[0] = struct.pack("!H", length)
-        return ''.join(packed)
-
-    @staticmethod
-    def unpack(reader):
-        obj = flow_stats_entry()
-        _length = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_length, 2)
-        obj.table_id = reader.read("!B")[0]
-        reader.skip(1)
-        obj.match = ofp.match.unpack(reader)
-        obj.duration_sec = reader.read("!L")[0]
-        obj.duration_nsec = reader.read("!L")[0]
-        obj.priority = reader.read("!H")[0]
-        obj.idle_timeout = reader.read("!H")[0]
-        obj.hard_timeout = reader.read("!H")[0]
-        reader.skip(6)
-        obj.cookie = reader.read("!Q")[0]
-        obj.packet_count = reader.read("!Q")[0]
-        obj.byte_count = reader.read("!Q")[0]
-        obj.actions = loxi.generic_util.unpack_list(reader, ofp.action.action.unpack)
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): return False
-        if self.table_id != other.table_id: 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.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 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("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("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(loxi.OFObject):
-
-    def __init__(self, wildcards=None, in_port=None, eth_src=None, eth_dst=None, vlan_vid=None, vlan_pcp=None, eth_type=None, ip_dscp=None, ip_proto=None, ipv4_src=None, ipv4_dst=None, tcp_src=None, tcp_dst=None):
-        if wildcards != None:
-            self.wildcards = wildcards
-        else:
-            self.wildcards = util.init_wc_bmap()
-        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 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 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
-        return
-
-    def pack(self):
-        packed = []
-        packed.append(util.pack_wc_bmap(self.wildcards))
-        packed.append(util.pack_port_no(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('\x00' * 1)
-        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('\x00' * 2)
-        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(reader):
-        obj = match_v1()
-        obj.wildcards = util.unpack_wc_bmap(reader)
-        obj.in_port = util.unpack_port_no(reader)
-        obj.eth_src = list(reader.read('!6B'))
-        obj.eth_dst = list(reader.read('!6B'))
-        obj.vlan_vid = reader.read("!H")[0]
-        obj.vlan_pcp = reader.read("!B")[0]
-        reader.skip(1)
-        obj.eth_type = reader.read("!H")[0]
-        obj.ip_dscp = reader.read("!B")[0]
-        obj.ip_proto = reader.read("!B")[0]
-        reader.skip(2)
-        obj.ipv4_src = reader.read("!L")[0]
-        obj.ipv4_dst = reader.read("!L")[0]
-        obj.tcp_src = reader.read("!H")[0]
-        obj.tcp_dst = reader.read("!H")[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.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.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 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("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("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('}')
-
-
-class packet_queue(loxi.OFObject):
-
-    def __init__(self, queue_id=None, properties=None):
-        if queue_id != None:
-            self.queue_id = queue_id
-        else:
-            self.queue_id = 0
-        if properties != None:
-            self.properties = properties
-        else:
-            self.properties = []
-        return
-
-    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('\x00' * 2)
-        packed.append(loxi.generic_util.pack_list(self.properties))
-        length = sum([len(x) for x in packed])
-        packed[1] = struct.pack("!H", length)
-        return ''.join(packed)
-
-    @staticmethod
-    def unpack(reader):
-        obj = packet_queue()
-        obj.queue_id = reader.read("!L")[0]
-        _len = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_len, 6)
-        reader.skip(2)
-        obj.properties = loxi.generic_util.unpack_list(reader, ofp.common.queue_prop.unpack)
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): return False
-        if self.queue_id != other.queue_id: return False
-        if self.properties != other.properties: return False
-        return True
-
-    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("properties = ");
-                q.pp(self.properties)
-            q.breakable()
-        q.text('}')
-
-
-class port_desc(loxi.OFObject):
-
-    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
-        return
-
-    def pack(self):
-        packed = []
-        packed.append(util.pack_port_no(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(reader):
-        obj = port_desc()
-        obj.port_no = util.unpack_port_no(reader)
-        obj.hw_addr = list(reader.read('!6B'))
-        obj.name = reader.read("!16s")[0].rstrip("\x00")
-        obj.config = reader.read("!L")[0]
-        obj.state = reader.read("!L")[0]
-        obj.curr = reader.read("!L")[0]
-        obj.advertised = reader.read("!L")[0]
-        obj.supported = reader.read("!L")[0]
-        obj.peer = reader.read("!L")[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 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(loxi.OFObject):
-
-    def __init__(self, port_no=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 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
-        return
-
-    def pack(self):
-        packed = []
-        packed.append(util.pack_port_no(self.port_no))
-        packed.append('\x00' * 6)
-        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(reader):
-        obj = port_stats_entry()
-        obj.port_no = util.unpack_port_no(reader)
-        reader.skip(6)
-        obj.rx_packets = reader.read("!Q")[0]
-        obj.tx_packets = reader.read("!Q")[0]
-        obj.rx_bytes = reader.read("!Q")[0]
-        obj.tx_bytes = reader.read("!Q")[0]
-        obj.rx_dropped = reader.read("!Q")[0]
-        obj.tx_dropped = reader.read("!Q")[0]
-        obj.rx_errors = reader.read("!Q")[0]
-        obj.tx_errors = reader.read("!Q")[0]
-        obj.rx_frame_err = reader.read("!Q")[0]
-        obj.rx_over_err = reader.read("!Q")[0]
-        obj.rx_crc_err = reader.read("!Q")[0]
-        obj.collisions = reader.read("!Q")[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.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 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("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(loxi.OFObject):
-    subtypes = {}
-
-
-    def __init__(self, type=None):
-        if type != None:
-            self.type = type
-        else:
-            self.type = 0
-        return
-
-    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('\x00' * 4)
-        length = sum([len(x) for x in packed])
-        packed[1] = struct.pack("!H", length)
-        return ''.join(packed)
-
-    @staticmethod
-    def unpack(reader):
-        subtype, = reader.peek('!H', 0)
-        subclass = queue_prop.subtypes.get(subtype)
-        if subclass:
-            return subclass.unpack(reader)
-
-        obj = queue_prop()
-        obj.type = reader.read("!H")[0]
-        _len = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_len, 4)
-        reader.skip(4)
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): return False
-        if self.type != other.type: return False
-        return True
-
-    def pretty_print(self, q):
-        q.text("queue_prop {")
-        with q.group():
-            with q.indent(2):
-                q.breakable()
-            q.breakable()
-        q.text('}')
-
-
-class queue_prop_min_rate(queue_prop):
-    type = 1
-
-    def __init__(self, rate=None):
-        if rate != None:
-            self.rate = rate
-        else:
-            self.rate = 0
-        return
-
-    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('\x00' * 4)
-        packed.append(struct.pack("!H", self.rate))
-        packed.append('\x00' * 6)
-        length = sum([len(x) for x in packed])
-        packed[1] = struct.pack("!H", length)
-        return ''.join(packed)
-
-    @staticmethod
-    def unpack(reader):
-        obj = queue_prop_min_rate()
-        _type = reader.read("!H")[0]
-        assert(_type == 1)
-        _len = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_len, 4)
-        reader.skip(4)
-        obj.rate = reader.read("!H")[0]
-        reader.skip(6)
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): return False
-        if self.rate != other.rate: return False
-        return True
-
-    def pretty_print(self, q):
-        q.text("queue_prop_min_rate {")
-        with q.group():
-            with q.indent(2):
-                q.breakable()
-                q.text("rate = ");
-                q.text("%#x" % self.rate)
-            q.breakable()
-        q.text('}')
-
-queue_prop.subtypes[1] = queue_prop_min_rate
-
-class queue_stats_entry(loxi.OFObject):
-
-    def __init__(self, port_no=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 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
-        return
-
-    def pack(self):
-        packed = []
-        packed.append(util.pack_port_no(self.port_no))
-        packed.append('\x00' * 2)
-        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(reader):
-        obj = queue_stats_entry()
-        obj.port_no = util.unpack_port_no(reader)
-        reader.skip(2)
-        obj.queue_id = reader.read("!L")[0]
-        obj.tx_bytes = reader.read("!Q")[0]
-        obj.tx_packets = reader.read("!Q")[0]
-        obj.tx_errors = reader.read("!Q")[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.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 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("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(loxi.OFObject):
-
-    def __init__(self, table_id=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 name != None:
-            self.name = name
-        else:
-            self.name = ""
-        if wildcards != None:
-            self.wildcards = wildcards
-        else:
-            self.wildcards = util.init_wc_bmap()
-        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
-        return
-
-    def pack(self):
-        packed = []
-        packed.append(struct.pack("!B", self.table_id))
-        packed.append('\x00' * 3)
-        packed.append(struct.pack("!32s", self.name))
-        packed.append(util.pack_wc_bmap(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(reader):
-        obj = table_stats_entry()
-        obj.table_id = reader.read("!B")[0]
-        reader.skip(3)
-        obj.name = reader.read("!32s")[0].rstrip("\x00")
-        obj.wildcards = util.unpack_wc_bmap(reader)
-        obj.max_entries = reader.read("!L")[0]
-        obj.active_count = reader.read("!L")[0]
-        obj.lookup_count = reader.read("!Q")[0]
-        obj.matched_count = reader.read("!Q")[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.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 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("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('}')
-
-
-
-match = match_v1
diff --git a/python/ofagent/loxi/of10/const.py b/python/ofagent/loxi/of10/const.py
deleted file mode 100644
index 01404ee..0000000
--- a/python/ofagent/loxi/of10/const.py
+++ /dev/null
@@ -1,535 +0,0 @@
-# Copyright 2017-present Open Networking Foundation
-#
-# 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.
-# Copyright (c) 2008 The Board of Trustees of The Leland Stanford Junior University
-# Copyright (c) 2011, 2012 Open Networking Foundation
-# Copyright (c) 2012, 2013 Big Switch Networks, Inc.
-# See the file LICENSE.pyloxi which should have been included in the source distribution
-
-# Automatically generated by LOXI from template const.py
-# Do not modify
-
-OFP_VERSION = 1
-
-# Identifiers from group macro_definitions
-OFP_MAX_TABLE_NAME_LEN = 32
-OFP_MAX_PORT_NAME_LEN = 16
-OFP_TCP_PORT = 6653
-OFP_SSL_PORT = 6653
-OFP_ETH_ALEN = 6
-OFP_DEFAULT_MISS_SEND_LEN = 128
-OFP_VLAN_NONE = 65535
-OFPFW_ICMP_TYPE = 64
-OFPFW_ICMP_CODE = 128
-OFP_DL_TYPE_ETH2_CUTOFF = 1536
-OFP_DL_TYPE_NOT_ETH_TYPE = 1535
-OFP_FLOW_PERMANENT = 0
-OFP_DEFAULT_PRIORITY = 32768
-DESC_STR_LEN = 256
-SERIAL_NUM_LEN = 32
-OFPQ_ALL = 4294967295
-OFPQ_MIN_RATE_UNCFG = 65535
-
-# Identifiers from group of_bsn_pdu_slot_num
-BSN_PDU_SLOT_NUM_ANY = 255
-
-of_bsn_pdu_slot_num_map = {
-    255: 'BSN_PDU_SLOT_NUM_ANY',
-}
-
-# 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_EXPERIMENTER = 65535
-
-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',
-    65535: 'OFPAT_EXPERIMENTER',
-}
-
-# Identifiers from group ofp_bad_action_code
-OFPBAC_BAD_TYPE = 0
-OFPBAC_BAD_LEN = 1
-OFPBAC_BAD_EXPERIMENTER = 2
-OFPBAC_BAD_EXPERIMENTER_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_EXPERIMENTER',
-    3: 'OFPBAC_BAD_EXPERIMENTER_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_EXPERIMENTER = 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_EXPERIMENTER',
-    4: 'OFPBRC_BAD_SUBTYPE',
-    5: 'OFPBRC_EPERM',
-    6: 'OFPBRC_BAD_LEN',
-    7: 'OFPBRC_BUFFER_EMPTY',
-    8: 'OFPBRC_BUFFER_UNKNOWN',
-}
-
-# Identifiers from group ofp_bsn_vport_l2gre_flags
-OF_BSN_VPORT_L2GRE_LOCAL_MAC_IS_VALID = 1
-OF_BSN_VPORT_L2GRE_DSCP_ASSIGN = 2
-OF_BSN_VPORT_L2GRE_DSCP_COPY = 4
-OF_BSN_VPORT_L2GRE_LOOPBACK_IS_VALID = 8
-OF_BSN_VPORT_L2GRE_RATE_LIMIT_IS_VALID = 16
-
-ofp_bsn_vport_l2gre_flags_map = {
-    1: 'OF_BSN_VPORT_L2GRE_LOCAL_MAC_IS_VALID',
-    2: 'OF_BSN_VPORT_L2GRE_DSCP_ASSIGN',
-    4: 'OF_BSN_VPORT_L2GRE_DSCP_COPY',
-    8: 'OF_BSN_VPORT_L2GRE_LOOPBACK_IS_VALID',
-    16: 'OF_BSN_VPORT_L2GRE_RATE_LIMIT_IS_VALID',
-}
-
-# Identifiers from group ofp_bsn_vport_q_in_q_untagged
-OF_BSN_VPORT_Q_IN_Q_UNTAGGED = 65535
-
-ofp_bsn_vport_q_in_q_untagged_map = {
-    65535: 'OF_BSN_VPORT_Q_IN_Q_UNTAGGED',
-}
-
-# Identifiers from group ofp_bsn_vport_status
-OF_BSN_VPORT_STATUS_OK = 0
-OF_BSN_VPORT_STATUS_FAILED = 1
-
-ofp_bsn_vport_status_map = {
-    0: 'OF_BSN_VPORT_STATUS_OK',
-    1: 'OF_BSN_VPORT_STATUS_FAILED',
-}
-
-# Identifiers from group ofp_capabilities
-OFPC_FLOW_STATS = 1
-OFPC_TABLE_STATS = 2
-OFPC_PORT_STATS = 4
-OFPC_STP = 8
-OFPC_RESERVED = 16
-OFPC_IP_REASM = 32
-OFPC_QUEUE_STATS = 64
-OFPC_ARP_MATCH_IP = 128
-
-ofp_capabilities_map = {
-    1: 'OFPC_FLOW_STATS',
-    2: 'OFPC_TABLE_STATS',
-    4: 'OFPC_PORT_STATS',
-    8: 'OFPC_STP',
-    16: 'OFPC_RESERVED',
-    32: 'OFPC_IP_REASM',
-    64: 'OFPC_QUEUE_STATS',
-    128: '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
-OFPFF_CHECK_OVERLAP = 2
-OFPFF_EMERG = 4
-
-ofp_flow_mod_flags_map = {
-    1: 'OFPFF_SEND_FLOW_REM',
-    2: 'OFPFF_CHECK_OVERLAP',
-    4: '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
-OFPFW_DL_VLAN = 2
-OFPFW_DL_SRC = 4
-OFPFW_NW_DST_BITS = 6
-OFPFW_NW_SRC_BITS = 6
-OFPFW_NW_SRC_SHIFT = 8
-OFPFW_DL_DST = 8
-OFPFW_NW_DST_SHIFT = 14
-OFPFW_DL_TYPE = 16
-OFPFW_NW_PROTO = 32
-OFPFW_TP_SRC = 64
-OFPFW_TP_DST = 128
-OFPFW_NW_SRC_ALL = 8192
-OFPFW_NW_SRC_MASK = 16128
-OFPFW_NW_DST_ALL = 524288
-OFPFW_NW_DST_MASK = 1032192
-OFPFW_DL_VLAN_PCP = 1048576
-OFPFW_NW_TOS = 2097152
-OFPFW_ALL = 4194303
-
-ofp_flow_wildcards_map = {
-    1: 'OFPFW_IN_PORT',
-    2: 'OFPFW_DL_VLAN',
-    4: 'OFPFW_DL_SRC',
-    8: 'OFPFW_DL_DST',
-    16: 'OFPFW_DL_TYPE',
-    32: 'OFPFW_NW_PROTO',
-    64: 'OFPFW_TP_SRC',
-    128: 'OFPFW_TP_DST',
-    1048576: 'OFPFW_DL_VLAN_PCP',
-    2097152: '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_nicira_controller_role
-NX_ROLE_OTHER = 0
-NX_ROLE_MASTER = 1
-NX_ROLE_SLAVE = 2
-
-ofp_nicira_controller_role_map = {
-    0: 'NX_ROLE_OTHER',
-    1: 'NX_ROLE_MASTER',
-    2: 'NX_ROLE_SLAVE',
-}
-
-# 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
-OFPPC_NO_STP = 2
-OFPPC_NO_RECV = 4
-OFPPC_NO_RECV_STP = 8
-OFPPC_NO_FLOOD = 16
-OFPPC_NO_FWD = 32
-OFPPC_NO_PACKET_IN = 64
-OFPPC_BSN_MIRROR_DEST = 2147483648
-
-ofp_port_config_map = {
-    1: 'OFPPC_PORT_DOWN',
-    2: 'OFPPC_NO_STP',
-    4: 'OFPPC_NO_RECV',
-    8: 'OFPPC_NO_RECV_STP',
-    16: 'OFPPC_NO_FLOOD',
-    32: 'OFPPC_NO_FWD',
-    64: 'OFPPC_NO_PACKET_IN',
-    2147483648: 'OFPPC_BSN_MIRROR_DEST',
-}
-
-# Identifiers from group ofp_port_features
-OFPPF_10MB_HD = 1
-OFPPF_10MB_FD = 2
-OFPPF_100MB_HD = 4
-OFPPF_100MB_FD = 8
-OFPPF_1GB_HD = 16
-OFPPF_1GB_FD = 32
-OFPPF_10GB_FD = 64
-OFPPF_COPPER = 128
-OFPPF_FIBER = 256
-OFPPF_AUTONEG = 512
-OFPPF_PAUSE = 1024
-OFPPF_PAUSE_ASYM = 2048
-
-ofp_port_features_map = {
-    1: 'OFPPF_10MB_HD',
-    2: 'OFPPF_10MB_FD',
-    4: 'OFPPF_100MB_HD',
-    8: 'OFPPF_100MB_FD',
-    16: 'OFPPF_1GB_HD',
-    32: 'OFPPF_1GB_FD',
-    64: 'OFPPF_10GB_FD',
-    128: 'OFPPF_COPPER',
-    256: 'OFPPF_FIBER',
-    512: 'OFPPF_AUTONEG',
-    1024: 'OFPPF_PAUSE',
-    2048: '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_LINK_DOWN = 1
-OFPPS_STP_LISTEN = 0
-OFPPS_STP_LEARN = 256
-OFPPS_STP_FORWARD = 512
-OFPPS_STP_BLOCK = 768
-OFPPS_STP_MASK = 768
-
-ofp_port_state_map = {
-    1: 'OFPPS_LINK_DOWN',
-    0: 'OFPPS_STP_LISTEN',
-    256: 'OFPPS_STP_LEARN',
-    512: 'OFPPS_STP_FORWARD',
-    768: 'OFPPS_STP_BLOCK',
-    768: '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
-
-ofp_stats_reply_flags_map = {
-    1: 'OFPSF_REPLY_MORE',
-}
-
-# Identifiers from group ofp_stats_request_flags
-
-ofp_stats_request_flags_map = {
-}
-
-# Identifiers from group ofp_stats_type
-OFPST_DESC = 0
-OFPST_FLOW = 1
-OFPST_AGGREGATE = 2
-OFPST_TABLE = 3
-OFPST_PORT = 4
-OFPST_QUEUE = 5
-OFPST_EXPERIMENTER = 65535
-
-ofp_stats_type_map = {
-    0: 'OFPST_DESC',
-    1: 'OFPST_FLOW',
-    2: 'OFPST_AGGREGATE',
-    3: 'OFPST_TABLE',
-    4: 'OFPST_PORT',
-    5: 'OFPST_QUEUE',
-    65535: 'OFPST_EXPERIMENTER',
-}
-
-# Identifiers from group ofp_type
-OFPT_HELLO = 0
-OFPT_ERROR = 1
-OFPT_ECHO_REQUEST = 2
-OFPT_ECHO_REPLY = 3
-OFPT_EXPERIMENTER = 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_EXPERIMENTER',
-    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/python/ofagent/loxi/of10/message.py b/python/ofagent/loxi/of10/message.py
deleted file mode 100644
index 8c3d46c..0000000
--- a/python/ofagent/loxi/of10/message.py
+++ /dev/null
@@ -1,7550 +0,0 @@
-# Copyright 2017-present Open Networking Foundation
-#
-# 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.
-# Copyright (c) 2008 The Board of Trustees of The Leland Stanford Junior University
-# Copyright (c) 2011, 2012 Open Networking Foundation
-# Copyright (c) 2012, 2013 Big Switch Networks, Inc.
-# See the file LICENSE.pyloxi which should have been included in the source distribution
-
-# Automatically generated by LOXI from template module.py
-# Do not modify
-
-import struct
-import loxi
-import util
-import loxi.generic_util
-
-import sys
-ofp = sys.modules['loxi.of10']
-
-class message(loxi.OFObject):
-    subtypes = {}
-
-    version = 1
-
-    def __init__(self, type=None, xid=None):
-        if type != None:
-            self.type = type
-        else:
-            self.type = 0
-        if xid != None:
-            self.xid = xid
-        else:
-            self.xid = None
-        return
-
-    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(reader):
-        subtype, = reader.peek('B', 1)
-        subclass = message.subtypes.get(subtype)
-        if subclass:
-            return subclass.unpack(reader)
-
-        obj = message()
-        _version = reader.read("!B")[0]
-        assert(_version == 1)
-        obj.type = reader.read("!B")[0]
-        _length = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_length, 4)
-        obj.xid = reader.read("!L")[0]
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): return False
-        if self.type != other.type: return False
-        if self.xid != other.xid: return False
-        return True
-
-    def pretty_print(self, q):
-        q.text("message {")
-        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 stats_reply(message):
-    subtypes = {}
-
-    version = 1
-    type = 17
-
-    def __init__(self, xid=None, stats_type=None, flags=None):
-        if xid != None:
-            self.xid = xid
-        else:
-            self.xid = None
-        if stats_type != None:
-            self.stats_type = stats_type
-        else:
-            self.stats_type = 0
-        if flags != None:
-            self.flags = flags
-        else:
-            self.flags = 0
-        return
-
-    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(reader):
-        subtype, = reader.peek('!H', 8)
-        subclass = stats_reply.subtypes.get(subtype)
-        if subclass:
-            return subclass.unpack(reader)
-
-        obj = stats_reply()
-        _version = reader.read("!B")[0]
-        assert(_version == 1)
-        _type = reader.read("!B")[0]
-        assert(_type == 17)
-        _length = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_length, 4)
-        obj.xid = reader.read("!L")[0]
-        obj.stats_type = reader.read("!H")[0]
-        obj.flags = reader.read("!H")[0]
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): return False
-        if self.xid != other.xid: return False
-        if self.stats_type != other.stats_type: return False
-        if self.flags != other.flags: return False
-        return True
-
-    def pretty_print(self, q):
-        q.text("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.breakable()
-        q.text('}')
-
-message.subtypes[17] = stats_reply
-
-class aggregate_stats_reply(stats_reply):
-    version = 1
-    type = 17
-    stats_type = 2
-
-    def __init__(self, xid=None, flags=None, packet_count=None, byte_count=None, flow_count=None):
-        if xid != None:
-            self.xid = xid
-        else:
-            self.xid = None
-        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
-        return
-
-    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('\x00' * 4)
-        length = sum([len(x) for x in packed])
-        packed[2] = struct.pack("!H", length)
-        return ''.join(packed)
-
-    @staticmethod
-    def unpack(reader):
-        obj = aggregate_stats_reply()
-        _version = reader.read("!B")[0]
-        assert(_version == 1)
-        _type = reader.read("!B")[0]
-        assert(_type == 17)
-        _length = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_length, 4)
-        obj.xid = reader.read("!L")[0]
-        _stats_type = reader.read("!H")[0]
-        assert(_stats_type == 2)
-        obj.flags = reader.read("!H")[0]
-        obj.packet_count = reader.read("!Q")[0]
-        obj.byte_count = reader.read("!Q")[0]
-        obj.flow_count = reader.read("!L")[0]
-        reader.skip(4)
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): 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
-        return True
-
-    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.breakable()
-        q.text('}')
-
-stats_reply.subtypes[2] = aggregate_stats_reply
-
-class stats_request(message):
-    subtypes = {}
-
-    version = 1
-    type = 16
-
-    def __init__(self, xid=None, stats_type=None, flags=None):
-        if xid != None:
-            self.xid = xid
-        else:
-            self.xid = None
-        if stats_type != None:
-            self.stats_type = stats_type
-        else:
-            self.stats_type = 0
-        if flags != None:
-            self.flags = flags
-        else:
-            self.flags = 0
-        return
-
-    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(reader):
-        subtype, = reader.peek('!H', 8)
-        subclass = stats_request.subtypes.get(subtype)
-        if subclass:
-            return subclass.unpack(reader)
-
-        obj = stats_request()
-        _version = reader.read("!B")[0]
-        assert(_version == 1)
-        _type = reader.read("!B")[0]
-        assert(_type == 16)
-        _length = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_length, 4)
-        obj.xid = reader.read("!L")[0]
-        obj.stats_type = reader.read("!H")[0]
-        obj.flags = reader.read("!H")[0]
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): return False
-        if self.xid != other.xid: return False
-        if self.stats_type != other.stats_type: return False
-        if self.flags != other.flags: return False
-        return True
-
-    def pretty_print(self, q):
-        q.text("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('}')
-
-message.subtypes[16] = stats_request
-
-class aggregate_stats_request(stats_request):
-    version = 1
-    type = 16
-    stats_type = 2
-
-    def __init__(self, xid=None, flags=None, match=None, table_id=None, out_port=None):
-        if xid != None:
-            self.xid = xid
-        else:
-            self.xid = None
-        if flags != None:
-            self.flags = flags
-        else:
-            self.flags = 0
-        if match != None:
-            self.match = match
-        else:
-            self.match = ofp.match()
-        if table_id != None:
-            self.table_id = table_id
-        else:
-            self.table_id = 0
-        if out_port != None:
-            self.out_port = out_port
-        else:
-            self.out_port = 0
-        return
-
-    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('\x00' * 1)
-        packed.append(util.pack_port_no(self.out_port))
-        length = sum([len(x) for x in packed])
-        packed[2] = struct.pack("!H", length)
-        return ''.join(packed)
-
-    @staticmethod
-    def unpack(reader):
-        obj = aggregate_stats_request()
-        _version = reader.read("!B")[0]
-        assert(_version == 1)
-        _type = reader.read("!B")[0]
-        assert(_type == 16)
-        _length = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_length, 4)
-        obj.xid = reader.read("!L")[0]
-        _stats_type = reader.read("!H")[0]
-        assert(_stats_type == 2)
-        obj.flags = reader.read("!H")[0]
-        obj.match = ofp.match.unpack(reader)
-        obj.table_id = reader.read("!B")[0]
-        reader.skip(1)
-        obj.out_port = util.unpack_port_no(reader)
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): 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.out_port != other.out_port: return False
-        return True
-
-    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("out_port = ");
-                q.text(util.pretty_port(self.out_port))
-            q.breakable()
-        q.text('}')
-
-stats_request.subtypes[2] = aggregate_stats_request
-
-class error_msg(message):
-    subtypes = {}
-
-    version = 1
-    type = 1
-
-    def __init__(self, xid=None, err_type=None):
-        if xid != None:
-            self.xid = xid
-        else:
-            self.xid = None
-        if err_type != None:
-            self.err_type = err_type
-        else:
-            self.err_type = 0
-        return
-
-    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))
-        length = sum([len(x) for x in packed])
-        packed[2] = struct.pack("!H", length)
-        return ''.join(packed)
-
-    @staticmethod
-    def unpack(reader):
-        subtype, = reader.peek('!H', 8)
-        subclass = error_msg.subtypes.get(subtype)
-        if subclass:
-            return subclass.unpack(reader)
-
-        obj = error_msg()
-        _version = reader.read("!B")[0]
-        assert(_version == 1)
-        _type = reader.read("!B")[0]
-        assert(_type == 1)
-        _length = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_length, 4)
-        obj.xid = reader.read("!L")[0]
-        obj.err_type = reader.read("!H")[0]
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): return False
-        if self.xid != other.xid: return False
-        if self.err_type != other.err_type: return False
-        return True
-
-    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.breakable()
-        q.text('}')
-
-message.subtypes[1] = error_msg
-
-class bad_action_error_msg(error_msg):
-    version = 1
-    type = 1
-    err_type = 2
-
-    def __init__(self, xid=None, code=None, data=None):
-        if xid != None:
-            self.xid = xid
-        else:
-            self.xid = None
-        if code != None:
-            self.code = code
-        else:
-            self.code = 0
-        if data != None:
-            self.data = data
-        else:
-            self.data = ''
-        return
-
-    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(reader):
-        obj = bad_action_error_msg()
-        _version = reader.read("!B")[0]
-        assert(_version == 1)
-        _type = reader.read("!B")[0]
-        assert(_type == 1)
-        _length = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_length, 4)
-        obj.xid = reader.read("!L")[0]
-        _err_type = reader.read("!H")[0]
-        assert(_err_type == 2)
-        obj.code = reader.read("!H")[0]
-        obj.data = str(reader.read_all())
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): return False
-        if self.xid != other.xid: return False
-        if self.code != other.code: return False
-        if self.data != other.data: return False
-        return True
-
-    def pretty_print(self, q):
-        q.text("bad_action_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("code = ");
-                q.text("%#x" % self.code)
-                q.text(","); q.breakable()
-                q.text("data = ");
-                q.pp(self.data)
-            q.breakable()
-        q.text('}')
-
-error_msg.subtypes[2] = bad_action_error_msg
-
-class bad_request_error_msg(error_msg):
-    version = 1
-    type = 1
-    err_type = 1
-
-    def __init__(self, xid=None, code=None, data=None):
-        if xid != None:
-            self.xid = xid
-        else:
-            self.xid = None
-        if code != None:
-            self.code = code
-        else:
-            self.code = 0
-        if data != None:
-            self.data = data
-        else:
-            self.data = ''
-        return
-
-    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(reader):
-        obj = bad_request_error_msg()
-        _version = reader.read("!B")[0]
-        assert(_version == 1)
-        _type = reader.read("!B")[0]
-        assert(_type == 1)
-        _length = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_length, 4)
-        obj.xid = reader.read("!L")[0]
-        _err_type = reader.read("!H")[0]
-        assert(_err_type == 1)
-        obj.code = reader.read("!H")[0]
-        obj.data = str(reader.read_all())
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): return False
-        if self.xid != other.xid: return False
-        if self.code != other.code: return False
-        if self.data != other.data: return False
-        return True
-
-    def pretty_print(self, q):
-        q.text("bad_request_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("code = ");
-                q.text("%#x" % self.code)
-                q.text(","); q.breakable()
-                q.text("data = ");
-                q.pp(self.data)
-            q.breakable()
-        q.text('}')
-
-error_msg.subtypes[1] = bad_request_error_msg
-
-class barrier_reply(message):
-    version = 1
-    type = 19
-
-    def __init__(self, xid=None):
-        if xid != None:
-            self.xid = xid
-        else:
-            self.xid = None
-        return
-
-    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(reader):
-        obj = barrier_reply()
-        _version = reader.read("!B")[0]
-        assert(_version == 1)
-        _type = reader.read("!B")[0]
-        assert(_type == 19)
-        _length = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_length, 4)
-        obj.xid = reader.read("!L")[0]
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): return False
-        if self.xid != other.xid: return False
-        return True
-
-    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('}')
-
-message.subtypes[19] = barrier_reply
-
-class barrier_request(message):
-    version = 1
-    type = 18
-
-    def __init__(self, xid=None):
-        if xid != None:
-            self.xid = xid
-        else:
-            self.xid = None
-        return
-
-    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(reader):
-        obj = barrier_request()
-        _version = reader.read("!B")[0]
-        assert(_version == 1)
-        _type = reader.read("!B")[0]
-        assert(_type == 18)
-        _length = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_length, 4)
-        obj.xid = reader.read("!L")[0]
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): return False
-        if self.xid != other.xid: return False
-        return True
-
-    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('}')
-
-message.subtypes[18] = barrier_request
-
-class experimenter(message):
-    subtypes = {}
-
-    version = 1
-    type = 4
-
-    def __init__(self, xid=None, experimenter=None, data=None):
-        if xid != None:
-            self.xid = xid
-        else:
-            self.xid = None
-        if experimenter != None:
-            self.experimenter = experimenter
-        else:
-            self.experimenter = 0
-        if data != None:
-            self.data = data
-        else:
-            self.data = ''
-        return
-
-    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(self.data)
-        length = sum([len(x) for x in packed])
-        packed[2] = struct.pack("!H", length)
-        return ''.join(packed)
-
-    @staticmethod
-    def unpack(reader):
-        subtype, = reader.peek('!L', 8)
-        subclass = experimenter.subtypes.get(subtype)
-        if subclass:
-            return subclass.unpack(reader)
-
-        obj = experimenter()
-        _version = reader.read("!B")[0]
-        assert(_version == 1)
-        _type = reader.read("!B")[0]
-        assert(_type == 4)
-        _length = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_length, 4)
-        obj.xid = reader.read("!L")[0]
-        obj.experimenter = reader.read("!L")[0]
-        obj.data = str(reader.read_all())
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): return False
-        if self.xid != other.xid: return False
-        if self.experimenter != other.experimenter: return False
-        if self.data != other.data: return False
-        return True
-
-    def pretty_print(self, q):
-        q.text("experimenter {")
-        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('}')
-
-message.subtypes[4] = experimenter
-
-class bsn_header(experimenter):
-    subtypes = {}
-
-    version = 1
-    type = 4
-    experimenter = 6035143
-
-    def __init__(self, xid=None, subtype=None):
-        if xid != None:
-            self.xid = xid
-        else:
-            self.xid = None
-        if subtype != None:
-            self.subtype = subtype
-        else:
-            self.subtype = 0
-        return
-
-    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(reader):
-        subtype, = reader.peek('!L', 12)
-        subclass = bsn_header.subtypes.get(subtype)
-        if subclass:
-            return subclass.unpack(reader)
-
-        obj = bsn_header()
-        _version = reader.read("!B")[0]
-        assert(_version == 1)
-        _type = reader.read("!B")[0]
-        assert(_type == 4)
-        _length = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_length, 4)
-        obj.xid = reader.read("!L")[0]
-        _experimenter = reader.read("!L")[0]
-        assert(_experimenter == 6035143)
-        obj.subtype = reader.read("!L")[0]
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): return False
-        if self.xid != other.xid: return False
-        if self.subtype != other.subtype: return False
-        return True
-
-    def pretty_print(self, q):
-        q.text("bsn_header {")
-        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('}')
-
-experimenter.subtypes[6035143] = bsn_header
-
-class bsn_bw_clear_data_reply(bsn_header):
-    version = 1
-    type = 4
-    experimenter = 6035143
-    subtype = 22
-
-    def __init__(self, xid=None, status=None):
-        if xid != None:
-            self.xid = xid
-        else:
-            self.xid = None
-        if status != None:
-            self.status = status
-        else:
-            self.status = 0
-        return
-
-    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(reader):
-        obj = bsn_bw_clear_data_reply()
-        _version = reader.read("!B")[0]
-        assert(_version == 1)
-        _type = reader.read("!B")[0]
-        assert(_type == 4)
-        _length = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_length, 4)
-        obj.xid = reader.read("!L")[0]
-        _experimenter = reader.read("!L")[0]
-        assert(_experimenter == 6035143)
-        _subtype = reader.read("!L")[0]
-        assert(_subtype == 22)
-        obj.status = reader.read("!L")[0]
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): return False
-        if self.xid != other.xid: return False
-        if self.status != other.status: return False
-        return True
-
-    def pretty_print(self, q):
-        q.text("bsn_bw_clear_data_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("status = ");
-                q.text("%#x" % self.status)
-            q.breakable()
-        q.text('}')
-
-bsn_header.subtypes[22] = bsn_bw_clear_data_reply
-
-class bsn_bw_clear_data_request(bsn_header):
-    version = 1
-    type = 4
-    experimenter = 6035143
-    subtype = 21
-
-    def __init__(self, xid=None):
-        if xid != None:
-            self.xid = xid
-        else:
-            self.xid = None
-        return
-
-    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(reader):
-        obj = bsn_bw_clear_data_request()
-        _version = reader.read("!B")[0]
-        assert(_version == 1)
-        _type = reader.read("!B")[0]
-        assert(_type == 4)
-        _length = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_length, 4)
-        obj.xid = reader.read("!L")[0]
-        _experimenter = reader.read("!L")[0]
-        assert(_experimenter == 6035143)
-        _subtype = reader.read("!L")[0]
-        assert(_subtype == 21)
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): return False
-        if self.xid != other.xid: return False
-        return True
-
-    def pretty_print(self, q):
-        q.text("bsn_bw_clear_data_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('}')
-
-bsn_header.subtypes[21] = bsn_bw_clear_data_request
-
-class bsn_bw_enable_get_reply(bsn_header):
-    version = 1
-    type = 4
-    experimenter = 6035143
-    subtype = 20
-
-    def __init__(self, xid=None, enabled=None):
-        if xid != None:
-            self.xid = xid
-        else:
-            self.xid = None
-        if enabled != None:
-            self.enabled = enabled
-        else:
-            self.enabled = 0
-        return
-
-    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.enabled))
-        length = sum([len(x) for x in packed])
-        packed[2] = struct.pack("!H", length)
-        return ''.join(packed)
-
-    @staticmethod
-    def unpack(reader):
-        obj = bsn_bw_enable_get_reply()
-        _version = reader.read("!B")[0]
-        assert(_version == 1)
-        _type = reader.read("!B")[0]
-        assert(_type == 4)
-        _length = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_length, 4)
-        obj.xid = reader.read("!L")[0]
-        _experimenter = reader.read("!L")[0]
-        assert(_experimenter == 6035143)
-        _subtype = reader.read("!L")[0]
-        assert(_subtype == 20)
-        obj.enabled = reader.read("!L")[0]
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): return False
-        if self.xid != other.xid: return False
-        if self.enabled != other.enabled: return False
-        return True
-
-    def pretty_print(self, q):
-        q.text("bsn_bw_enable_get_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("enabled = ");
-                q.text("%#x" % self.enabled)
-            q.breakable()
-        q.text('}')
-
-bsn_header.subtypes[20] = bsn_bw_enable_get_reply
-
-class bsn_bw_enable_get_request(bsn_header):
-    version = 1
-    type = 4
-    experimenter = 6035143
-    subtype = 19
-
-    def __init__(self, xid=None):
-        if xid != None:
-            self.xid = xid
-        else:
-            self.xid = None
-        return
-
-    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(reader):
-        obj = bsn_bw_enable_get_request()
-        _version = reader.read("!B")[0]
-        assert(_version == 1)
-        _type = reader.read("!B")[0]
-        assert(_type == 4)
-        _length = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_length, 4)
-        obj.xid = reader.read("!L")[0]
-        _experimenter = reader.read("!L")[0]
-        assert(_experimenter == 6035143)
-        _subtype = reader.read("!L")[0]
-        assert(_subtype == 19)
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): return False
-        if self.xid != other.xid: return False
-        return True
-
-    def pretty_print(self, q):
-        q.text("bsn_bw_enable_get_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('}')
-
-bsn_header.subtypes[19] = bsn_bw_enable_get_request
-
-class bsn_bw_enable_set_reply(bsn_header):
-    version = 1
-    type = 4
-    experimenter = 6035143
-    subtype = 23
-
-    def __init__(self, xid=None, enable=None, status=None):
-        if xid != None:
-            self.xid = xid
-        else:
-            self.xid = None
-        if enable != None:
-            self.enable = enable
-        else:
-            self.enable = 0
-        if status != None:
-            self.status = status
-        else:
-            self.status = 0
-        return
-
-    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.enable))
-        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(reader):
-        obj = bsn_bw_enable_set_reply()
-        _version = reader.read("!B")[0]
-        assert(_version == 1)
-        _type = reader.read("!B")[0]
-        assert(_type == 4)
-        _length = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_length, 4)
-        obj.xid = reader.read("!L")[0]
-        _experimenter = reader.read("!L")[0]
-        assert(_experimenter == 6035143)
-        _subtype = reader.read("!L")[0]
-        assert(_subtype == 23)
-        obj.enable = reader.read("!L")[0]
-        obj.status = reader.read("!L")[0]
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): return False
-        if self.xid != other.xid: return False
-        if self.enable != other.enable: return False
-        if self.status != other.status: return False
-        return True
-
-    def pretty_print(self, q):
-        q.text("bsn_bw_enable_set_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("enable = ");
-                q.text("%#x" % self.enable)
-                q.text(","); q.breakable()
-                q.text("status = ");
-                q.text("%#x" % self.status)
-            q.breakable()
-        q.text('}')
-
-bsn_header.subtypes[23] = bsn_bw_enable_set_reply
-
-class bsn_bw_enable_set_request(bsn_header):
-    version = 1
-    type = 4
-    experimenter = 6035143
-    subtype = 18
-
-    def __init__(self, xid=None, enable=None):
-        if xid != None:
-            self.xid = xid
-        else:
-            self.xid = None
-        if enable != None:
-            self.enable = enable
-        else:
-            self.enable = 0
-        return
-
-    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.enable))
-        length = sum([len(x) for x in packed])
-        packed[2] = struct.pack("!H", length)
-        return ''.join(packed)
-
-    @staticmethod
-    def unpack(reader):
-        obj = bsn_bw_enable_set_request()
-        _version = reader.read("!B")[0]
-        assert(_version == 1)
-        _type = reader.read("!B")[0]
-        assert(_type == 4)
-        _length = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_length, 4)
-        obj.xid = reader.read("!L")[0]
-        _experimenter = reader.read("!L")[0]
-        assert(_experimenter == 6035143)
-        _subtype = reader.read("!L")[0]
-        assert(_subtype == 18)
-        obj.enable = reader.read("!L")[0]
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): return False
-        if self.xid != other.xid: return False
-        if self.enable != other.enable: return False
-        return True
-
-    def pretty_print(self, q):
-        q.text("bsn_bw_enable_set_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("enable = ");
-                q.text("%#x" % self.enable)
-            q.breakable()
-        q.text('}')
-
-bsn_header.subtypes[18] = bsn_bw_enable_set_request
-
-class bsn_get_interfaces_reply(bsn_header):
-    version = 1
-    type = 4
-    experimenter = 6035143
-    subtype = 10
-
-    def __init__(self, xid=None, interfaces=None):
-        if xid != None:
-            self.xid = xid
-        else:
-            self.xid = None
-        if interfaces != None:
-            self.interfaces = interfaces
-        else:
-            self.interfaces = []
-        return
-
-    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(loxi.generic_util.pack_list(self.interfaces))
-        length = sum([len(x) for x in packed])
-        packed[2] = struct.pack("!H", length)
-        return ''.join(packed)
-
-    @staticmethod
-    def unpack(reader):
-        obj = bsn_get_interfaces_reply()
-        _version = reader.read("!B")[0]
-        assert(_version == 1)
-        _type = reader.read("!B")[0]
-        assert(_type == 4)
-        _length = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_length, 4)
-        obj.xid = reader.read("!L")[0]
-        _experimenter = reader.read("!L")[0]
-        assert(_experimenter == 6035143)
-        _subtype = reader.read("!L")[0]
-        assert(_subtype == 10)
-        obj.interfaces = loxi.generic_util.unpack_list(reader, ofp.common.bsn_interface.unpack)
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): return False
-        if self.xid != other.xid: return False
-        if self.interfaces != other.interfaces: return False
-        return True
-
-    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('}')
-
-bsn_header.subtypes[10] = bsn_get_interfaces_reply
-
-class bsn_get_interfaces_request(bsn_header):
-    version = 1
-    type = 4
-    experimenter = 6035143
-    subtype = 9
-
-    def __init__(self, xid=None):
-        if xid != None:
-            self.xid = xid
-        else:
-            self.xid = None
-        return
-
-    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(reader):
-        obj = bsn_get_interfaces_request()
-        _version = reader.read("!B")[0]
-        assert(_version == 1)
-        _type = reader.read("!B")[0]
-        assert(_type == 4)
-        _length = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_length, 4)
-        obj.xid = reader.read("!L")[0]
-        _experimenter = reader.read("!L")[0]
-        assert(_experimenter == 6035143)
-        _subtype = reader.read("!L")[0]
-        assert(_subtype == 9)
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): return False
-        if self.xid != other.xid: return False
-        return True
-
-    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('}')
-
-bsn_header.subtypes[9] = bsn_get_interfaces_request
-
-class bsn_get_ip_mask_reply(bsn_header):
-    version = 1
-    type = 4
-    experimenter = 6035143
-    subtype = 2
-
-    def __init__(self, xid=None, index=None, mask=None):
-        if xid != None:
-            self.xid = xid
-        else:
-            self.xid = None
-        if index != None:
-            self.index = index
-        else:
-            self.index = 0
-        if mask != None:
-            self.mask = mask
-        else:
-            self.mask = 0
-        return
-
-    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('\x00' * 3)
-        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(reader):
-        obj = bsn_get_ip_mask_reply()
-        _version = reader.read("!B")[0]
-        assert(_version == 1)
-        _type = reader.read("!B")[0]
-        assert(_type == 4)
-        _length = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_length, 4)
-        obj.xid = reader.read("!L")[0]
-        _experimenter = reader.read("!L")[0]
-        assert(_experimenter == 6035143)
-        _subtype = reader.read("!L")[0]
-        assert(_subtype == 2)
-        obj.index = reader.read("!B")[0]
-        reader.skip(3)
-        obj.mask = reader.read("!L")[0]
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): return False
-        if self.xid != other.xid: return False
-        if self.index != other.index: return False
-        if self.mask != other.mask: return False
-        return True
-
-    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("mask = ");
-                q.text("%#x" % self.mask)
-            q.breakable()
-        q.text('}')
-
-bsn_header.subtypes[2] = bsn_get_ip_mask_reply
-
-class bsn_get_ip_mask_request(bsn_header):
-    version = 1
-    type = 4
-    experimenter = 6035143
-    subtype = 1
-
-    def __init__(self, xid=None, index=None):
-        if xid != None:
-            self.xid = xid
-        else:
-            self.xid = None
-        if index != None:
-            self.index = index
-        else:
-            self.index = 0
-        return
-
-    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('\x00' * 7)
-        length = sum([len(x) for x in packed])
-        packed[2] = struct.pack("!H", length)
-        return ''.join(packed)
-
-    @staticmethod
-    def unpack(reader):
-        obj = bsn_get_ip_mask_request()
-        _version = reader.read("!B")[0]
-        assert(_version == 1)
-        _type = reader.read("!B")[0]
-        assert(_type == 4)
-        _length = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_length, 4)
-        obj.xid = reader.read("!L")[0]
-        _experimenter = reader.read("!L")[0]
-        assert(_experimenter == 6035143)
-        _subtype = reader.read("!L")[0]
-        assert(_subtype == 1)
-        obj.index = reader.read("!B")[0]
-        reader.skip(7)
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): return False
-        if self.xid != other.xid: return False
-        if self.index != other.index: return False
-        return True
-
-    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.breakable()
-        q.text('}')
-
-bsn_header.subtypes[1] = bsn_get_ip_mask_request
-
-class bsn_get_l2_table_reply(bsn_header):
-    version = 1
-    type = 4
-    experimenter = 6035143
-    subtype = 14
-
-    def __init__(self, xid=None, l2_table_enable=None, l2_table_priority=None):
-        if xid != None:
-            self.xid = xid
-        else:
-            self.xid = None
-        if l2_table_enable != None:
-            self.l2_table_enable = l2_table_enable
-        else:
-            self.l2_table_enable = 0
-        if l2_table_priority != None:
-            self.l2_table_priority = l2_table_priority
-        else:
-            self.l2_table_priority = 0
-        return
-
-    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.l2_table_enable))
-        packed.append('\x00' * 1)
-        packed.append(struct.pack("!H", self.l2_table_priority))
-        packed.append('\x00' * 4)
-        length = sum([len(x) for x in packed])
-        packed[2] = struct.pack("!H", length)
-        return ''.join(packed)
-
-    @staticmethod
-    def unpack(reader):
-        obj = bsn_get_l2_table_reply()
-        _version = reader.read("!B")[0]
-        assert(_version == 1)
-        _type = reader.read("!B")[0]
-        assert(_type == 4)
-        _length = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_length, 4)
-        obj.xid = reader.read("!L")[0]
-        _experimenter = reader.read("!L")[0]
-        assert(_experimenter == 6035143)
-        _subtype = reader.read("!L")[0]
-        assert(_subtype == 14)
-        obj.l2_table_enable = reader.read("!B")[0]
-        reader.skip(1)
-        obj.l2_table_priority = reader.read("!H")[0]
-        reader.skip(4)
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): return False
-        if self.xid != other.xid: return False
-        if self.l2_table_enable != other.l2_table_enable: return False
-        if self.l2_table_priority != other.l2_table_priority: return False
-        return True
-
-    def pretty_print(self, q):
-        q.text("bsn_get_l2_table_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("l2_table_enable = ");
-                q.text("%#x" % self.l2_table_enable)
-                q.text(","); q.breakable()
-                q.text("l2_table_priority = ");
-                q.text("%#x" % self.l2_table_priority)
-            q.breakable()
-        q.text('}')
-
-bsn_header.subtypes[14] = bsn_get_l2_table_reply
-
-class bsn_get_l2_table_request(bsn_header):
-    version = 1
-    type = 4
-    experimenter = 6035143
-    subtype = 13
-
-    def __init__(self, xid=None):
-        if xid != None:
-            self.xid = xid
-        else:
-            self.xid = None
-        return
-
-    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(reader):
-        obj = bsn_get_l2_table_request()
-        _version = reader.read("!B")[0]
-        assert(_version == 1)
-        _type = reader.read("!B")[0]
-        assert(_type == 4)
-        _length = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_length, 4)
-        obj.xid = reader.read("!L")[0]
-        _experimenter = reader.read("!L")[0]
-        assert(_experimenter == 6035143)
-        _subtype = reader.read("!L")[0]
-        assert(_subtype == 13)
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): return False
-        if self.xid != other.xid: return False
-        return True
-
-    def pretty_print(self, q):
-        q.text("bsn_get_l2_table_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('}')
-
-bsn_header.subtypes[13] = bsn_get_l2_table_request
-
-class bsn_get_mirroring_reply(bsn_header):
-    version = 1
-    type = 4
-    experimenter = 6035143
-    subtype = 5
-
-    def __init__(self, xid=None, report_mirror_ports=None):
-        if xid != None:
-            self.xid = xid
-        else:
-            self.xid = None
-        if report_mirror_ports != None:
-            self.report_mirror_ports = report_mirror_ports
-        else:
-            self.report_mirror_ports = 0
-        return
-
-    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('\x00' * 3)
-        length = sum([len(x) for x in packed])
-        packed[2] = struct.pack("!H", length)
-        return ''.join(packed)
-
-    @staticmethod
-    def unpack(reader):
-        obj = bsn_get_mirroring_reply()
-        _version = reader.read("!B")[0]
-        assert(_version == 1)
-        _type = reader.read("!B")[0]
-        assert(_type == 4)
-        _length = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_length, 4)
-        obj.xid = reader.read("!L")[0]
-        _experimenter = reader.read("!L")[0]
-        assert(_experimenter == 6035143)
-        _subtype = reader.read("!L")[0]
-        assert(_subtype == 5)
-        obj.report_mirror_ports = reader.read("!B")[0]
-        reader.skip(3)
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): return False
-        if self.xid != other.xid: return False
-        if self.report_mirror_ports != other.report_mirror_ports: return False
-        return True
-
-    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.breakable()
-        q.text('}')
-
-bsn_header.subtypes[5] = bsn_get_mirroring_reply
-
-class bsn_get_mirroring_request(bsn_header):
-    version = 1
-    type = 4
-    experimenter = 6035143
-    subtype = 4
-
-    def __init__(self, xid=None, report_mirror_ports=None):
-        if xid != None:
-            self.xid = xid
-        else:
-            self.xid = None
-        if report_mirror_ports != None:
-            self.report_mirror_ports = report_mirror_ports
-        else:
-            self.report_mirror_ports = 0
-        return
-
-    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('\x00' * 3)
-        length = sum([len(x) for x in packed])
-        packed[2] = struct.pack("!H", length)
-        return ''.join(packed)
-
-    @staticmethod
-    def unpack(reader):
-        obj = bsn_get_mirroring_request()
-        _version = reader.read("!B")[0]
-        assert(_version == 1)
-        _type = reader.read("!B")[0]
-        assert(_type == 4)
-        _length = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_length, 4)
-        obj.xid = reader.read("!L")[0]
-        _experimenter = reader.read("!L")[0]
-        assert(_experimenter == 6035143)
-        _subtype = reader.read("!L")[0]
-        assert(_subtype == 4)
-        obj.report_mirror_ports = reader.read("!B")[0]
-        reader.skip(3)
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): return False
-        if self.xid != other.xid: return False
-        if self.report_mirror_ports != other.report_mirror_ports: return False
-        return True
-
-    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.breakable()
-        q.text('}')
-
-bsn_header.subtypes[4] = bsn_get_mirroring_request
-
-class bsn_hybrid_get_reply(bsn_header):
-    version = 1
-    type = 4
-    experimenter = 6035143
-    subtype = 28
-
-    def __init__(self, xid=None, hybrid_enable=None, hybrid_version=None):
-        if xid != None:
-            self.xid = xid
-        else:
-            self.xid = None
-        if hybrid_enable != None:
-            self.hybrid_enable = hybrid_enable
-        else:
-            self.hybrid_enable = 0
-        if hybrid_version != None:
-            self.hybrid_version = hybrid_version
-        else:
-            self.hybrid_version = 0
-        return
-
-    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.hybrid_enable))
-        packed.append('\x00' * 1)
-        packed.append(struct.pack("!H", self.hybrid_version))
-        packed.append('\x00' * 4)
-        length = sum([len(x) for x in packed])
-        packed[2] = struct.pack("!H", length)
-        return ''.join(packed)
-
-    @staticmethod
-    def unpack(reader):
-        obj = bsn_hybrid_get_reply()
-        _version = reader.read("!B")[0]
-        assert(_version == 1)
-        _type = reader.read("!B")[0]
-        assert(_type == 4)
-        _length = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_length, 4)
-        obj.xid = reader.read("!L")[0]
-        _experimenter = reader.read("!L")[0]
-        assert(_experimenter == 6035143)
-        _subtype = reader.read("!L")[0]
-        assert(_subtype == 28)
-        obj.hybrid_enable = reader.read("!B")[0]
-        reader.skip(1)
-        obj.hybrid_version = reader.read("!H")[0]
-        reader.skip(4)
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): return False
-        if self.xid != other.xid: return False
-        if self.hybrid_enable != other.hybrid_enable: return False
-        if self.hybrid_version != other.hybrid_version: return False
-        return True
-
-    def pretty_print(self, q):
-        q.text("bsn_hybrid_get_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("hybrid_enable = ");
-                q.text("%#x" % self.hybrid_enable)
-                q.text(","); q.breakable()
-                q.text("hybrid_version = ");
-                q.text("%#x" % self.hybrid_version)
-            q.breakable()
-        q.text('}')
-
-bsn_header.subtypes[28] = bsn_hybrid_get_reply
-
-class bsn_hybrid_get_request(bsn_header):
-    version = 1
-    type = 4
-    experimenter = 6035143
-    subtype = 27
-
-    def __init__(self, xid=None):
-        if xid != None:
-            self.xid = xid
-        else:
-            self.xid = None
-        return
-
-    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(reader):
-        obj = bsn_hybrid_get_request()
-        _version = reader.read("!B")[0]
-        assert(_version == 1)
-        _type = reader.read("!B")[0]
-        assert(_type == 4)
-        _length = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_length, 4)
-        obj.xid = reader.read("!L")[0]
-        _experimenter = reader.read("!L")[0]
-        assert(_experimenter == 6035143)
-        _subtype = reader.read("!L")[0]
-        assert(_subtype == 27)
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): return False
-        if self.xid != other.xid: return False
-        return True
-
-    def pretty_print(self, q):
-        q.text("bsn_hybrid_get_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('}')
-
-bsn_header.subtypes[27] = bsn_hybrid_get_request
-
-class bsn_pdu_rx_reply(bsn_header):
-    version = 1
-    type = 4
-    experimenter = 6035143
-    subtype = 34
-
-    def __init__(self, xid=None, status=None, port_no=None, slot_num=None):
-        if xid != None:
-            self.xid = xid
-        else:
-            self.xid = None
-        if status != None:
-            self.status = status
-        else:
-            self.status = 0
-        if port_no != None:
-            self.port_no = port_no
-        else:
-            self.port_no = 0
-        if slot_num != None:
-            self.slot_num = slot_num
-        else:
-            self.slot_num = 0
-        return
-
-    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))
-        packed.append(util.pack_port_no(self.port_no))
-        packed.append(struct.pack("!B", self.slot_num))
-        length = sum([len(x) for x in packed])
-        packed[2] = struct.pack("!H", length)
-        return ''.join(packed)
-
-    @staticmethod
-    def unpack(reader):
-        obj = bsn_pdu_rx_reply()
-        _version = reader.read("!B")[0]
-        assert(_version == 1)
-        _type = reader.read("!B")[0]
-        assert(_type == 4)
-        _length = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_length, 4)
-        obj.xid = reader.read("!L")[0]
-        _experimenter = reader.read("!L")[0]
-        assert(_experimenter == 6035143)
-        _subtype = reader.read("!L")[0]
-        assert(_subtype == 34)
-        obj.status = reader.read("!L")[0]
-        obj.port_no = util.unpack_port_no(reader)
-        obj.slot_num = reader.read("!B")[0]
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): return False
-        if self.xid != other.xid: return False
-        if self.status != other.status: return False
-        if self.port_no != other.port_no: return False
-        if self.slot_num != other.slot_num: return False
-        return True
-
-    def pretty_print(self, q):
-        q.text("bsn_pdu_rx_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("status = ");
-                q.text("%#x" % self.status)
-                q.text(","); q.breakable()
-                q.text("port_no = ");
-                q.text(util.pretty_port(self.port_no))
-                q.text(","); q.breakable()
-                q.text("slot_num = ");
-                q.text("%#x" % self.slot_num)
-            q.breakable()
-        q.text('}')
-
-bsn_header.subtypes[34] = bsn_pdu_rx_reply
-
-class bsn_pdu_rx_request(bsn_header):
-    version = 1
-    type = 4
-    experimenter = 6035143
-    subtype = 33
-
-    def __init__(self, xid=None, timeout_ms=None, port_no=None, slot_num=None, data=None):
-        if xid != None:
-            self.xid = xid
-        else:
-            self.xid = None
-        if timeout_ms != None:
-            self.timeout_ms = timeout_ms
-        else:
-            self.timeout_ms = 0
-        if port_no != None:
-            self.port_no = port_no
-        else:
-            self.port_no = 0
-        if slot_num != None:
-            self.slot_num = slot_num
-        else:
-            self.slot_num = 0
-        if data != None:
-            self.data = data
-        else:
-            self.data = ''
-        return
-
-    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.timeout_ms))
-        packed.append(util.pack_port_no(self.port_no))
-        packed.append(struct.pack("!B", self.slot_num))
-        packed.append('\x00' * 3)
-        packed.append(self.data)
-        length = sum([len(x) for x in packed])
-        packed[2] = struct.pack("!H", length)
-        return ''.join(packed)
-
-    @staticmethod
-    def unpack(reader):
-        obj = bsn_pdu_rx_request()
-        _version = reader.read("!B")[0]
-        assert(_version == 1)
-        _type = reader.read("!B")[0]
-        assert(_type == 4)
-        _length = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_length, 4)
-        obj.xid = reader.read("!L")[0]
-        _experimenter = reader.read("!L")[0]
-        assert(_experimenter == 6035143)
-        _subtype = reader.read("!L")[0]
-        assert(_subtype == 33)
-        obj.timeout_ms = reader.read("!L")[0]
-        obj.port_no = util.unpack_port_no(reader)
-        obj.slot_num = reader.read("!B")[0]
-        reader.skip(3)
-        obj.data = str(reader.read_all())
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): return False
-        if self.xid != other.xid: return False
-        if self.timeout_ms != other.timeout_ms: return False
-        if self.port_no != other.port_no: return False
-        if self.slot_num != other.slot_num: return False
-        if self.data != other.data: return False
-        return True
-
-    def pretty_print(self, q):
-        q.text("bsn_pdu_rx_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("timeout_ms = ");
-                q.text("%#x" % self.timeout_ms)
-                q.text(","); q.breakable()
-                q.text("port_no = ");
-                q.text(util.pretty_port(self.port_no))
-                q.text(","); q.breakable()
-                q.text("slot_num = ");
-                q.text("%#x" % self.slot_num)
-                q.text(","); q.breakable()
-                q.text("data = ");
-                q.pp(self.data)
-            q.breakable()
-        q.text('}')
-
-bsn_header.subtypes[33] = bsn_pdu_rx_request
-
-class bsn_pdu_rx_timeout(bsn_header):
-    version = 1
-    type = 4
-    experimenter = 6035143
-    subtype = 35
-
-    def __init__(self, xid=None, port_no=None, slot_num=None):
-        if xid != None:
-            self.xid = xid
-        else:
-            self.xid = None
-        if port_no != None:
-            self.port_no = port_no
-        else:
-            self.port_no = 0
-        if slot_num != None:
-            self.slot_num = slot_num
-        else:
-            self.slot_num = 0
-        return
-
-    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(util.pack_port_no(self.port_no))
-        packed.append(struct.pack("!B", self.slot_num))
-        length = sum([len(x) for x in packed])
-        packed[2] = struct.pack("!H", length)
-        return ''.join(packed)
-
-    @staticmethod
-    def unpack(reader):
-        obj = bsn_pdu_rx_timeout()
-        _version = reader.read("!B")[0]
-        assert(_version == 1)
-        _type = reader.read("!B")[0]
-        assert(_type == 4)
-        _length = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_length, 4)
-        obj.xid = reader.read("!L")[0]
-        _experimenter = reader.read("!L")[0]
-        assert(_experimenter == 6035143)
-        _subtype = reader.read("!L")[0]
-        assert(_subtype == 35)
-        obj.port_no = util.unpack_port_no(reader)
-        obj.slot_num = reader.read("!B")[0]
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): return False
-        if self.xid != other.xid: return False
-        if self.port_no != other.port_no: return False
-        if self.slot_num != other.slot_num: return False
-        return True
-
-    def pretty_print(self, q):
-        q.text("bsn_pdu_rx_timeout {")
-        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("slot_num = ");
-                q.text("%#x" % self.slot_num)
-            q.breakable()
-        q.text('}')
-
-bsn_header.subtypes[35] = bsn_pdu_rx_timeout
-
-class bsn_pdu_tx_reply(bsn_header):
-    version = 1
-    type = 4
-    experimenter = 6035143
-    subtype = 32
-
-    def __init__(self, xid=None, status=None, port_no=None, slot_num=None):
-        if xid != None:
-            self.xid = xid
-        else:
-            self.xid = None
-        if status != None:
-            self.status = status
-        else:
-            self.status = 0
-        if port_no != None:
-            self.port_no = port_no
-        else:
-            self.port_no = 0
-        if slot_num != None:
-            self.slot_num = slot_num
-        else:
-            self.slot_num = 0
-        return
-
-    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))
-        packed.append(util.pack_port_no(self.port_no))
-        packed.append(struct.pack("!B", self.slot_num))
-        length = sum([len(x) for x in packed])
-        packed[2] = struct.pack("!H", length)
-        return ''.join(packed)
-
-    @staticmethod
-    def unpack(reader):
-        obj = bsn_pdu_tx_reply()
-        _version = reader.read("!B")[0]
-        assert(_version == 1)
-        _type = reader.read("!B")[0]
-        assert(_type == 4)
-        _length = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_length, 4)
-        obj.xid = reader.read("!L")[0]
-        _experimenter = reader.read("!L")[0]
-        assert(_experimenter == 6035143)
-        _subtype = reader.read("!L")[0]
-        assert(_subtype == 32)
-        obj.status = reader.read("!L")[0]
-        obj.port_no = util.unpack_port_no(reader)
-        obj.slot_num = reader.read("!B")[0]
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): return False
-        if self.xid != other.xid: return False
-        if self.status != other.status: return False
-        if self.port_no != other.port_no: return False
-        if self.slot_num != other.slot_num: return False
-        return True
-
-    def pretty_print(self, q):
-        q.text("bsn_pdu_tx_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("status = ");
-                q.text("%#x" % self.status)
-                q.text(","); q.breakable()
-                q.text("port_no = ");
-                q.text(util.pretty_port(self.port_no))
-                q.text(","); q.breakable()
-                q.text("slot_num = ");
-                q.text("%#x" % self.slot_num)
-            q.breakable()
-        q.text('}')
-
-bsn_header.subtypes[32] = bsn_pdu_tx_reply
-
-class bsn_pdu_tx_request(bsn_header):
-    version = 1
-    type = 4
-    experimenter = 6035143
-    subtype = 31
-
-    def __init__(self, xid=None, tx_interval_ms=None, port_no=None, slot_num=None, data=None):
-        if xid != None:
-            self.xid = xid
-        else:
-            self.xid = None
-        if tx_interval_ms != None:
-            self.tx_interval_ms = tx_interval_ms
-        else:
-            self.tx_interval_ms = 0
-        if port_no != None:
-            self.port_no = port_no
-        else:
-            self.port_no = 0
-        if slot_num != None:
-            self.slot_num = slot_num
-        else:
-            self.slot_num = 0
-        if data != None:
-            self.data = data
-        else:
-            self.data = ''
-        return
-
-    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.tx_interval_ms))
-        packed.append(util.pack_port_no(self.port_no))
-        packed.append(struct.pack("!B", self.slot_num))
-        packed.append('\x00' * 3)
-        packed.append(self.data)
-        length = sum([len(x) for x in packed])
-        packed[2] = struct.pack("!H", length)
-        return ''.join(packed)
-
-    @staticmethod
-    def unpack(reader):
-        obj = bsn_pdu_tx_request()
-        _version = reader.read("!B")[0]
-        assert(_version == 1)
-        _type = reader.read("!B")[0]
-        assert(_type == 4)
-        _length = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_length, 4)
-        obj.xid = reader.read("!L")[0]
-        _experimenter = reader.read("!L")[0]
-        assert(_experimenter == 6035143)
-        _subtype = reader.read("!L")[0]
-        assert(_subtype == 31)
-        obj.tx_interval_ms = reader.read("!L")[0]
-        obj.port_no = util.unpack_port_no(reader)
-        obj.slot_num = reader.read("!B")[0]
-        reader.skip(3)
-        obj.data = str(reader.read_all())
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): return False
-        if self.xid != other.xid: return False
-        if self.tx_interval_ms != other.tx_interval_ms: return False
-        if self.port_no != other.port_no: return False
-        if self.slot_num != other.slot_num: return False
-        if self.data != other.data: return False
-        return True
-
-    def pretty_print(self, q):
-        q.text("bsn_pdu_tx_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("tx_interval_ms = ");
-                q.text("%#x" % self.tx_interval_ms)
-                q.text(","); q.breakable()
-                q.text("port_no = ");
-                q.text(util.pretty_port(self.port_no))
-                q.text(","); q.breakable()
-                q.text("slot_num = ");
-                q.text("%#x" % self.slot_num)
-                q.text(","); q.breakable()
-                q.text("data = ");
-                q.pp(self.data)
-            q.breakable()
-        q.text('}')
-
-bsn_header.subtypes[31] = bsn_pdu_tx_request
-
-class bsn_set_ip_mask(bsn_header):
-    version = 1
-    type = 4
-    experimenter = 6035143
-    subtype = 0
-
-    def __init__(self, xid=None, index=None, mask=None):
-        if xid != None:
-            self.xid = xid
-        else:
-            self.xid = None
-        if index != None:
-            self.index = index
-        else:
-            self.index = 0
-        if mask != None:
-            self.mask = mask
-        else:
-            self.mask = 0
-        return
-
-    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('\x00' * 3)
-        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(reader):
-        obj = bsn_set_ip_mask()
-        _version = reader.read("!B")[0]
-        assert(_version == 1)
-        _type = reader.read("!B")[0]
-        assert(_type == 4)
-        _length = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_length, 4)
-        obj.xid = reader.read("!L")[0]
-        _experimenter = reader.read("!L")[0]
-        assert(_experimenter == 6035143)
-        _subtype = reader.read("!L")[0]
-        assert(_subtype == 0)
-        obj.index = reader.read("!B")[0]
-        reader.skip(3)
-        obj.mask = reader.read("!L")[0]
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): return False
-        if self.xid != other.xid: return False
-        if self.index != other.index: return False
-        if self.mask != other.mask: return False
-        return True
-
-    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("mask = ");
-                q.text("%#x" % self.mask)
-            q.breakable()
-        q.text('}')
-
-bsn_header.subtypes[0] = bsn_set_ip_mask
-
-class bsn_set_l2_table_reply(bsn_header):
-    version = 1
-    type = 4
-    experimenter = 6035143
-    subtype = 24
-
-    def __init__(self, xid=None, l2_table_enable=None, l2_table_priority=None, status=None):
-        if xid != None:
-            self.xid = xid
-        else:
-            self.xid = None
-        if l2_table_enable != None:
-            self.l2_table_enable = l2_table_enable
-        else:
-            self.l2_table_enable = 0
-        if l2_table_priority != None:
-            self.l2_table_priority = l2_table_priority
-        else:
-            self.l2_table_priority = 0
-        if status != None:
-            self.status = status
-        else:
-            self.status = 0
-        return
-
-    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.l2_table_enable))
-        packed.append('\x00' * 1)
-        packed.append(struct.pack("!H", self.l2_table_priority))
-        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(reader):
-        obj = bsn_set_l2_table_reply()
-        _version = reader.read("!B")[0]
-        assert(_version == 1)
-        _type = reader.read("!B")[0]
-        assert(_type == 4)
-        _length = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_length, 4)
-        obj.xid = reader.read("!L")[0]
-        _experimenter = reader.read("!L")[0]
-        assert(_experimenter == 6035143)
-        _subtype = reader.read("!L")[0]
-        assert(_subtype == 24)
-        obj.l2_table_enable = reader.read("!B")[0]
-        reader.skip(1)
-        obj.l2_table_priority = reader.read("!H")[0]
-        obj.status = reader.read("!L")[0]
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): return False
-        if self.xid != other.xid: return False
-        if self.l2_table_enable != other.l2_table_enable: return False
-        if self.l2_table_priority != other.l2_table_priority: return False
-        if self.status != other.status: return False
-        return True
-
-    def pretty_print(self, q):
-        q.text("bsn_set_l2_table_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("l2_table_enable = ");
-                q.text("%#x" % self.l2_table_enable)
-                q.text(","); q.breakable()
-                q.text("l2_table_priority = ");
-                q.text("%#x" % self.l2_table_priority)
-                q.text(","); q.breakable()
-                q.text("status = ");
-                q.text("%#x" % self.status)
-            q.breakable()
-        q.text('}')
-
-bsn_header.subtypes[24] = bsn_set_l2_table_reply
-
-class bsn_set_l2_table_request(bsn_header):
-    version = 1
-    type = 4
-    experimenter = 6035143
-    subtype = 12
-
-    def __init__(self, xid=None, l2_table_enable=None, l2_table_priority=None):
-        if xid != None:
-            self.xid = xid
-        else:
-            self.xid = None
-        if l2_table_enable != None:
-            self.l2_table_enable = l2_table_enable
-        else:
-            self.l2_table_enable = 0
-        if l2_table_priority != None:
-            self.l2_table_priority = l2_table_priority
-        else:
-            self.l2_table_priority = 0
-        return
-
-    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.l2_table_enable))
-        packed.append('\x00' * 1)
-        packed.append(struct.pack("!H", self.l2_table_priority))
-        packed.append('\x00' * 4)
-        length = sum([len(x) for x in packed])
-        packed[2] = struct.pack("!H", length)
-        return ''.join(packed)
-
-    @staticmethod
-    def unpack(reader):
-        obj = bsn_set_l2_table_request()
-        _version = reader.read("!B")[0]
-        assert(_version == 1)
-        _type = reader.read("!B")[0]
-        assert(_type == 4)
-        _length = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_length, 4)
-        obj.xid = reader.read("!L")[0]
-        _experimenter = reader.read("!L")[0]
-        assert(_experimenter == 6035143)
-        _subtype = reader.read("!L")[0]
-        assert(_subtype == 12)
-        obj.l2_table_enable = reader.read("!B")[0]
-        reader.skip(1)
-        obj.l2_table_priority = reader.read("!H")[0]
-        reader.skip(4)
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): return False
-        if self.xid != other.xid: return False
-        if self.l2_table_enable != other.l2_table_enable: return False
-        if self.l2_table_priority != other.l2_table_priority: return False
-        return True
-
-    def pretty_print(self, q):
-        q.text("bsn_set_l2_table_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("l2_table_enable = ");
-                q.text("%#x" % self.l2_table_enable)
-                q.text(","); q.breakable()
-                q.text("l2_table_priority = ");
-                q.text("%#x" % self.l2_table_priority)
-            q.breakable()
-        q.text('}')
-
-bsn_header.subtypes[12] = bsn_set_l2_table_request
-
-class bsn_set_mirroring(bsn_header):
-    version = 1
-    type = 4
-    experimenter = 6035143
-    subtype = 3
-
-    def __init__(self, xid=None, report_mirror_ports=None):
-        if xid != None:
-            self.xid = xid
-        else:
-            self.xid = None
-        if report_mirror_ports != None:
-            self.report_mirror_ports = report_mirror_ports
-        else:
-            self.report_mirror_ports = 0
-        return
-
-    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('\x00' * 3)
-        length = sum([len(x) for x in packed])
-        packed[2] = struct.pack("!H", length)
-        return ''.join(packed)
-
-    @staticmethod
-    def unpack(reader):
-        obj = bsn_set_mirroring()
-        _version = reader.read("!B")[0]
-        assert(_version == 1)
-        _type = reader.read("!B")[0]
-        assert(_type == 4)
-        _length = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_length, 4)
-        obj.xid = reader.read("!L")[0]
-        _experimenter = reader.read("!L")[0]
-        assert(_experimenter == 6035143)
-        _subtype = reader.read("!L")[0]
-        assert(_subtype == 3)
-        obj.report_mirror_ports = reader.read("!B")[0]
-        reader.skip(3)
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): return False
-        if self.xid != other.xid: return False
-        if self.report_mirror_ports != other.report_mirror_ports: return False
-        return True
-
-    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.breakable()
-        q.text('}')
-
-bsn_header.subtypes[3] = bsn_set_mirroring
-
-class bsn_set_pktin_suppression_reply(bsn_header):
-    version = 1
-    type = 4
-    experimenter = 6035143
-    subtype = 25
-
-    def __init__(self, xid=None, status=None):
-        if xid != None:
-            self.xid = xid
-        else:
-            self.xid = None
-        if status != None:
-            self.status = status
-        else:
-            self.status = 0
-        return
-
-    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(reader):
-        obj = bsn_set_pktin_suppression_reply()
-        _version = reader.read("!B")[0]
-        assert(_version == 1)
-        _type = reader.read("!B")[0]
-        assert(_type == 4)
-        _length = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_length, 4)
-        obj.xid = reader.read("!L")[0]
-        _experimenter = reader.read("!L")[0]
-        assert(_experimenter == 6035143)
-        _subtype = reader.read("!L")[0]
-        assert(_subtype == 25)
-        obj.status = reader.read("!L")[0]
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): return False
-        if self.xid != other.xid: return False
-        if self.status != other.status: return False
-        return True
-
-    def pretty_print(self, q):
-        q.text("bsn_set_pktin_suppression_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("status = ");
-                q.text("%#x" % self.status)
-            q.breakable()
-        q.text('}')
-
-bsn_header.subtypes[25] = bsn_set_pktin_suppression_reply
-
-class bsn_set_pktin_suppression_request(bsn_header):
-    version = 1
-    type = 4
-    experimenter = 6035143
-    subtype = 11
-
-    def __init__(self, xid=None, enabled=None, idle_timeout=None, hard_timeout=None, priority=None, cookie=None):
-        if xid != None:
-            self.xid = xid
-        else:
-            self.xid = None
-        if enabled != None:
-            self.enabled = enabled
-        else:
-            self.enabled = 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 cookie != None:
-            self.cookie = cookie
-        else:
-            self.cookie = 0
-        return
-
-    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.enabled))
-        packed.append('\x00' * 1)
-        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("!Q", self.cookie))
-        length = sum([len(x) for x in packed])
-        packed[2] = struct.pack("!H", length)
-        return ''.join(packed)
-
-    @staticmethod
-    def unpack(reader):
-        obj = bsn_set_pktin_suppression_request()
-        _version = reader.read("!B")[0]
-        assert(_version == 1)
-        _type = reader.read("!B")[0]
-        assert(_type == 4)
-        _length = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_length, 4)
-        obj.xid = reader.read("!L")[0]
-        _experimenter = reader.read("!L")[0]
-        assert(_experimenter == 6035143)
-        _subtype = reader.read("!L")[0]
-        assert(_subtype == 11)
-        obj.enabled = reader.read("!B")[0]
-        reader.skip(1)
-        obj.idle_timeout = reader.read("!H")[0]
-        obj.hard_timeout = reader.read("!H")[0]
-        obj.priority = reader.read("!H")[0]
-        obj.cookie = reader.read("!Q")[0]
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): return False
-        if self.xid != other.xid: return False
-        if self.enabled != other.enabled: 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.cookie != other.cookie: return False
-        return True
-
-    def pretty_print(self, q):
-        q.text("bsn_set_pktin_suppression_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("enabled = ");
-                q.text("%#x" % self.enabled)
-                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("cookie = ");
-                q.text("%#x" % self.cookie)
-            q.breakable()
-        q.text('}')
-
-bsn_header.subtypes[11] = bsn_set_pktin_suppression_request
-
-class bsn_shell_command(bsn_header):
-    version = 1
-    type = 4
-    experimenter = 6035143
-    subtype = 6
-
-    def __init__(self, xid=None, service=None, data=None):
-        if xid != None:
-            self.xid = xid
-        else:
-            self.xid = None
-        if service != None:
-            self.service = service
-        else:
-            self.service = 0
-        if data != None:
-            self.data = data
-        else:
-            self.data = ''
-        return
-
-    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(reader):
-        obj = bsn_shell_command()
-        _version = reader.read("!B")[0]
-        assert(_version == 1)
-        _type = reader.read("!B")[0]
-        assert(_type == 4)
-        _length = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_length, 4)
-        obj.xid = reader.read("!L")[0]
-        _experimenter = reader.read("!L")[0]
-        assert(_experimenter == 6035143)
-        _subtype = reader.read("!L")[0]
-        assert(_subtype == 6)
-        obj.service = reader.read("!L")[0]
-        obj.data = str(reader.read_all())
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): 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 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('}')
-
-bsn_header.subtypes[6] = bsn_shell_command
-
-class bsn_shell_output(bsn_header):
-    version = 1
-    type = 4
-    experimenter = 6035143
-    subtype = 7
-
-    def __init__(self, xid=None, data=None):
-        if xid != None:
-            self.xid = xid
-        else:
-            self.xid = None
-        if data != None:
-            self.data = data
-        else:
-            self.data = ''
-        return
-
-    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(reader):
-        obj = bsn_shell_output()
-        _version = reader.read("!B")[0]
-        assert(_version == 1)
-        _type = reader.read("!B")[0]
-        assert(_type == 4)
-        _length = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_length, 4)
-        obj.xid = reader.read("!L")[0]
-        _experimenter = reader.read("!L")[0]
-        assert(_experimenter == 6035143)
-        _subtype = reader.read("!L")[0]
-        assert(_subtype == 7)
-        obj.data = str(reader.read_all())
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): return False
-        if self.xid != other.xid: return False
-        if self.data != other.data: return False
-        return True
-
-    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('}')
-
-bsn_header.subtypes[7] = bsn_shell_output
-
-class bsn_shell_status(bsn_header):
-    version = 1
-    type = 4
-    experimenter = 6035143
-    subtype = 8
-
-    def __init__(self, xid=None, status=None):
-        if xid != None:
-            self.xid = xid
-        else:
-            self.xid = None
-        if status != None:
-            self.status = status
-        else:
-            self.status = 0
-        return
-
-    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(reader):
-        obj = bsn_shell_status()
-        _version = reader.read("!B")[0]
-        assert(_version == 1)
-        _type = reader.read("!B")[0]
-        assert(_type == 4)
-        _length = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_length, 4)
-        obj.xid = reader.read("!L")[0]
-        _experimenter = reader.read("!L")[0]
-        assert(_experimenter == 6035143)
-        _subtype = reader.read("!L")[0]
-        assert(_subtype == 8)
-        obj.status = reader.read("!L")[0]
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): return False
-        if self.xid != other.xid: return False
-        if self.status != other.status: return False
-        return True
-
-    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('}')
-
-bsn_header.subtypes[8] = bsn_shell_status
-
-class experimenter_stats_reply(stats_reply):
-    subtypes = {}
-
-    version = 1
-    type = 17
-    stats_type = 65535
-
-    def __init__(self, xid=None, flags=None, experimenter=None, data=None):
-        if xid != None:
-            self.xid = xid
-        else:
-            self.xid = None
-        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 = ''
-        return
-
-    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(reader):
-        subtype, = reader.peek('!L', 12)
-        subclass = experimenter_stats_reply.subtypes.get(subtype)
-        if subclass:
-            return subclass.unpack(reader)
-
-        obj = experimenter_stats_reply()
-        _version = reader.read("!B")[0]
-        assert(_version == 1)
-        _type = reader.read("!B")[0]
-        assert(_type == 17)
-        _length = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_length, 4)
-        obj.xid = reader.read("!L")[0]
-        _stats_type = reader.read("!H")[0]
-        assert(_stats_type == 65535)
-        obj.flags = reader.read("!H")[0]
-        obj.experimenter = reader.read("!L")[0]
-        obj.data = str(reader.read_all())
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): 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 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("data = ");
-                q.pp(self.data)
-            q.breakable()
-        q.text('}')
-
-stats_reply.subtypes[65535] = experimenter_stats_reply
-
-class bsn_stats_reply(experimenter_stats_reply):
-    subtypes = {}
-
-    version = 1
-    type = 19
-    stats_type = 65535
-    experimenter = 6035143
-
-    def __init__(self, xid=None, flags=None, subtype=None):
-        if xid != None:
-            self.xid = xid
-        else:
-            self.xid = None
-        if flags != None:
-            self.flags = flags
-        else:
-            self.flags = 0
-        if subtype != None:
-            self.subtype = subtype
-        else:
-            self.subtype = 0
-        return
-
-    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('\x00' * 4)
-        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(reader):
-        subtype, = reader.peek('!L', 20)
-        subclass = bsn_stats_reply.subtypes.get(subtype)
-        if subclass:
-            return subclass.unpack(reader)
-
-        obj = bsn_stats_reply()
-        _version = reader.read("!B")[0]
-        assert(_version == 1)
-        _type = reader.read("!B")[0]
-        assert(_type == 19)
-        _length = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_length, 4)
-        obj.xid = reader.read("!L")[0]
-        _stats_type = reader.read("!H")[0]
-        assert(_stats_type == 65535)
-        obj.flags = reader.read("!H")[0]
-        reader.skip(4)
-        _experimenter = reader.read("!L")[0]
-        assert(_experimenter == 6035143)
-        obj.subtype = reader.read("!L")[0]
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): return False
-        if self.xid != other.xid: return False
-        if self.flags != other.flags: return False
-        if self.subtype != other.subtype: return False
-        return True
-
-    def pretty_print(self, q):
-        q.text("bsn_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.breakable()
-        q.text('}')
-
-experimenter_stats_reply.subtypes[6035143] = bsn_stats_reply
-
-class experimenter_stats_request(stats_request):
-    subtypes = {}
-
-    version = 1
-    type = 16
-    stats_type = 65535
-
-    def __init__(self, xid=None, flags=None, experimenter=None, data=None):
-        if xid != None:
-            self.xid = xid
-        else:
-            self.xid = None
-        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 = ''
-        return
-
-    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(reader):
-        subtype, = reader.peek('!L', 12)
-        subclass = experimenter_stats_request.subtypes.get(subtype)
-        if subclass:
-            return subclass.unpack(reader)
-
-        obj = experimenter_stats_request()
-        _version = reader.read("!B")[0]
-        assert(_version == 1)
-        _type = reader.read("!B")[0]
-        assert(_type == 16)
-        _length = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_length, 4)
-        obj.xid = reader.read("!L")[0]
-        _stats_type = reader.read("!H")[0]
-        assert(_stats_type == 65535)
-        obj.flags = reader.read("!H")[0]
-        obj.experimenter = reader.read("!L")[0]
-        obj.data = str(reader.read_all())
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): 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 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("data = ");
-                q.pp(self.data)
-            q.breakable()
-        q.text('}')
-
-stats_request.subtypes[65535] = experimenter_stats_request
-
-class bsn_stats_request(experimenter_stats_request):
-    subtypes = {}
-
-    version = 1
-    type = 18
-    stats_type = 65535
-    experimenter = 6035143
-
-    def __init__(self, xid=None, flags=None, subtype=None):
-        if xid != None:
-            self.xid = xid
-        else:
-            self.xid = None
-        if flags != None:
-            self.flags = flags
-        else:
-            self.flags = 0
-        if subtype != None:
-            self.subtype = subtype
-        else:
-            self.subtype = 0
-        return
-
-    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('\x00' * 4)
-        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(reader):
-        subtype, = reader.peek('!L', 20)
-        subclass = bsn_stats_request.subtypes.get(subtype)
-        if subclass:
-            return subclass.unpack(reader)
-
-        obj = bsn_stats_request()
-        _version = reader.read("!B")[0]
-        assert(_version == 1)
-        _type = reader.read("!B")[0]
-        assert(_type == 18)
-        _length = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_length, 4)
-        obj.xid = reader.read("!L")[0]
-        _stats_type = reader.read("!H")[0]
-        assert(_stats_type == 65535)
-        obj.flags = reader.read("!H")[0]
-        reader.skip(4)
-        _experimenter = reader.read("!L")[0]
-        assert(_experimenter == 6035143)
-        obj.subtype = reader.read("!L")[0]
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): return False
-        if self.xid != other.xid: return False
-        if self.flags != other.flags: return False
-        if self.subtype != other.subtype: return False
-        return True
-
-    def pretty_print(self, q):
-        q.text("bsn_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('}')
-
-experimenter_stats_request.subtypes[6035143] = bsn_stats_request
-
-class bsn_virtual_port_create_reply(bsn_header):
-    version = 1
-    type = 4
-    experimenter = 6035143
-    subtype = 16
-
-    def __init__(self, xid=None, status=None, vport_no=None):
-        if xid != None:
-            self.xid = xid
-        else:
-            self.xid = None
-        if status != None:
-            self.status = status
-        else:
-            self.status = 0
-        if vport_no != None:
-            self.vport_no = vport_no
-        else:
-            self.vport_no = 0
-        return
-
-    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))
-        packed.append(struct.pack("!L", self.vport_no))
-        length = sum([len(x) for x in packed])
-        packed[2] = struct.pack("!H", length)
-        return ''.join(packed)
-
-    @staticmethod
-    def unpack(reader):
-        obj = bsn_virtual_port_create_reply()
-        _version = reader.read("!B")[0]
-        assert(_version == 1)
-        _type = reader.read("!B")[0]
-        assert(_type == 4)
-        _length = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_length, 4)
-        obj.xid = reader.read("!L")[0]
-        _experimenter = reader.read("!L")[0]
-        assert(_experimenter == 6035143)
-        _subtype = reader.read("!L")[0]
-        assert(_subtype == 16)
-        obj.status = reader.read("!L")[0]
-        obj.vport_no = reader.read("!L")[0]
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): return False
-        if self.xid != other.xid: return False
-        if self.status != other.status: return False
-        if self.vport_no != other.vport_no: return False
-        return True
-
-    def pretty_print(self, q):
-        q.text("bsn_virtual_port_create_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("status = ");
-                q.text("%#x" % self.status)
-                q.text(","); q.breakable()
-                q.text("vport_no = ");
-                q.text("%#x" % self.vport_no)
-            q.breakable()
-        q.text('}')
-
-bsn_header.subtypes[16] = bsn_virtual_port_create_reply
-
-class bsn_virtual_port_create_request(bsn_header):
-    version = 1
-    type = 4
-    experimenter = 6035143
-    subtype = 15
-
-    def __init__(self, xid=None, vport=None):
-        if xid != None:
-            self.xid = xid
-        else:
-            self.xid = None
-        if vport != None:
-            self.vport = vport
-        else:
-            self.vport = ofp.bsn_vport()
-        return
-
-    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.vport.pack())
-        length = sum([len(x) for x in packed])
-        packed[2] = struct.pack("!H", length)
-        return ''.join(packed)
-
-    @staticmethod
-    def unpack(reader):
-        obj = bsn_virtual_port_create_request()
-        _version = reader.read("!B")[0]
-        assert(_version == 1)
-        _type = reader.read("!B")[0]
-        assert(_type == 4)
-        _length = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_length, 4)
-        obj.xid = reader.read("!L")[0]
-        _experimenter = reader.read("!L")[0]
-        assert(_experimenter == 6035143)
-        _subtype = reader.read("!L")[0]
-        assert(_subtype == 15)
-        obj.vport = ofp.bsn_vport.unpack(reader)
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): return False
-        if self.xid != other.xid: return False
-        if self.vport != other.vport: return False
-        return True
-
-    def pretty_print(self, q):
-        q.text("bsn_virtual_port_create_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("vport = ");
-                q.pp(self.vport)
-            q.breakable()
-        q.text('}')
-
-bsn_header.subtypes[15] = bsn_virtual_port_create_request
-
-class bsn_virtual_port_remove_reply(bsn_header):
-    version = 1
-    type = 4
-    experimenter = 6035143
-    subtype = 26
-
-    def __init__(self, xid=None, status=None):
-        if xid != None:
-            self.xid = xid
-        else:
-            self.xid = None
-        if status != None:
-            self.status = status
-        else:
-            self.status = 0
-        return
-
-    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(reader):
-        obj = bsn_virtual_port_remove_reply()
-        _version = reader.read("!B")[0]
-        assert(_version == 1)
-        _type = reader.read("!B")[0]
-        assert(_type == 4)
-        _length = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_length, 4)
-        obj.xid = reader.read("!L")[0]
-        _experimenter = reader.read("!L")[0]
-        assert(_experimenter == 6035143)
-        _subtype = reader.read("!L")[0]
-        assert(_subtype == 26)
-        obj.status = reader.read("!L")[0]
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): return False
-        if self.xid != other.xid: return False
-        if self.status != other.status: return False
-        return True
-
-    def pretty_print(self, q):
-        q.text("bsn_virtual_port_remove_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("status = ");
-                q.text("%#x" % self.status)
-            q.breakable()
-        q.text('}')
-
-bsn_header.subtypes[26] = bsn_virtual_port_remove_reply
-
-class bsn_virtual_port_remove_request(bsn_header):
-    version = 1
-    type = 4
-    experimenter = 6035143
-    subtype = 17
-
-    def __init__(self, xid=None, vport_no=None):
-        if xid != None:
-            self.xid = xid
-        else:
-            self.xid = None
-        if vport_no != None:
-            self.vport_no = vport_no
-        else:
-            self.vport_no = 0
-        return
-
-    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.vport_no))
-        length = sum([len(x) for x in packed])
-        packed[2] = struct.pack("!H", length)
-        return ''.join(packed)
-
-    @staticmethod
-    def unpack(reader):
-        obj = bsn_virtual_port_remove_request()
-        _version = reader.read("!B")[0]
-        assert(_version == 1)
-        _type = reader.read("!B")[0]
-        assert(_type == 4)
-        _length = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_length, 4)
-        obj.xid = reader.read("!L")[0]
-        _experimenter = reader.read("!L")[0]
-        assert(_experimenter == 6035143)
-        _subtype = reader.read("!L")[0]
-        assert(_subtype == 17)
-        obj.vport_no = reader.read("!L")[0]
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): return False
-        if self.xid != other.xid: return False
-        if self.vport_no != other.vport_no: return False
-        return True
-
-    def pretty_print(self, q):
-        q.text("bsn_virtual_port_remove_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("vport_no = ");
-                q.text("%#x" % self.vport_no)
-            q.breakable()
-        q.text('}')
-
-bsn_header.subtypes[17] = bsn_virtual_port_remove_request
-
-class desc_stats_reply(stats_reply):
-    version = 1
-    type = 17
-    stats_type = 0
-
-    def __init__(self, xid=None, flags=None, mfr_desc=None, hw_desc=None, sw_desc=None, serial_num=None, dp_desc=None):
-        if xid != None:
-            self.xid = xid
-        else:
-            self.xid = None
-        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 = ""
-        return
-
-    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(reader):
-        obj = desc_stats_reply()
-        _version = reader.read("!B")[0]
-        assert(_version == 1)
-        _type = reader.read("!B")[0]
-        assert(_type == 17)
-        _length = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_length, 4)
-        obj.xid = reader.read("!L")[0]
-        _stats_type = reader.read("!H")[0]
-        assert(_stats_type == 0)
-        obj.flags = reader.read("!H")[0]
-        obj.mfr_desc = reader.read("!256s")[0].rstrip("\x00")
-        obj.hw_desc = reader.read("!256s")[0].rstrip("\x00")
-        obj.sw_desc = reader.read("!256s")[0].rstrip("\x00")
-        obj.serial_num = reader.read("!32s")[0].rstrip("\x00")
-        obj.dp_desc = reader.read("!256s")[0].rstrip("\x00")
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): 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 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('}')
-
-stats_reply.subtypes[0] = desc_stats_reply
-
-class desc_stats_request(stats_request):
-    version = 1
-    type = 16
-    stats_type = 0
-
-    def __init__(self, xid=None, flags=None):
-        if xid != None:
-            self.xid = xid
-        else:
-            self.xid = None
-        if flags != None:
-            self.flags = flags
-        else:
-            self.flags = 0
-        return
-
-    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(reader):
-        obj = desc_stats_request()
-        _version = reader.read("!B")[0]
-        assert(_version == 1)
-        _type = reader.read("!B")[0]
-        assert(_type == 16)
-        _length = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_length, 4)
-        obj.xid = reader.read("!L")[0]
-        _stats_type = reader.read("!H")[0]
-        assert(_stats_type == 0)
-        obj.flags = reader.read("!H")[0]
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): return False
-        if self.xid != other.xid: return False
-        if self.flags != other.flags: return False
-        return True
-
-    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('}')
-
-stats_request.subtypes[0] = desc_stats_request
-
-class echo_reply(message):
-    version = 1
-    type = 3
-
-    def __init__(self, xid=None, data=None):
-        if xid != None:
-            self.xid = xid
-        else:
-            self.xid = None
-        if data != None:
-            self.data = data
-        else:
-            self.data = ''
-        return
-
-    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(reader):
-        obj = echo_reply()
-        _version = reader.read("!B")[0]
-        assert(_version == 1)
-        _type = reader.read("!B")[0]
-        assert(_type == 3)
-        _length = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_length, 4)
-        obj.xid = reader.read("!L")[0]
-        obj.data = str(reader.read_all())
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): return False
-        if self.xid != other.xid: return False
-        if self.data != other.data: return False
-        return True
-
-    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('}')
-
-message.subtypes[3] = echo_reply
-
-class echo_request(message):
-    version = 1
-    type = 2
-
-    def __init__(self, xid=None, data=None):
-        if xid != None:
-            self.xid = xid
-        else:
-            self.xid = None
-        if data != None:
-            self.data = data
-        else:
-            self.data = ''
-        return
-
-    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(reader):
-        obj = echo_request()
-        _version = reader.read("!B")[0]
-        assert(_version == 1)
-        _type = reader.read("!B")[0]
-        assert(_type == 2)
-        _length = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_length, 4)
-        obj.xid = reader.read("!L")[0]
-        obj.data = str(reader.read_all())
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): return False
-        if self.xid != other.xid: return False
-        if self.data != other.data: return False
-        return True
-
-    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('}')
-
-message.subtypes[2] = echo_request
-
-class features_reply(message):
-    version = 1
-    type = 6
-
-    def __init__(self, xid=None, datapath_id=None, n_buffers=None, n_tables=None, capabilities=None, actions=None, ports=None):
-        if xid != None:
-            self.xid = xid
-        else:
-            self.xid = None
-        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 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 = []
-        return
-
-    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('\x00' * 3)
-        packed.append(struct.pack("!L", self.capabilities))
-        packed.append(struct.pack("!L", self.actions))
-        packed.append(loxi.generic_util.pack_list(self.ports))
-        length = sum([len(x) for x in packed])
-        packed[2] = struct.pack("!H", length)
-        return ''.join(packed)
-
-    @staticmethod
-    def unpack(reader):
-        obj = features_reply()
-        _version = reader.read("!B")[0]
-        assert(_version == 1)
-        _type = reader.read("!B")[0]
-        assert(_type == 6)
-        _length = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_length, 4)
-        obj.xid = reader.read("!L")[0]
-        obj.datapath_id = reader.read("!Q")[0]
-        obj.n_buffers = reader.read("!L")[0]
-        obj.n_tables = reader.read("!B")[0]
-        reader.skip(3)
-        obj.capabilities = reader.read("!L")[0]
-        obj.actions = reader.read("!L")[0]
-        obj.ports = loxi.generic_util.unpack_list(reader, ofp.common.port_desc.unpack)
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): 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.capabilities != other.capabilities: return False
-        if self.actions != other.actions: return False
-        if self.ports != other.ports: return False
-        return True
-
-    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("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('}')
-
-message.subtypes[6] = features_reply
-
-class features_request(message):
-    version = 1
-    type = 5
-
-    def __init__(self, xid=None):
-        if xid != None:
-            self.xid = xid
-        else:
-            self.xid = None
-        return
-
-    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(reader):
-        obj = features_request()
-        _version = reader.read("!B")[0]
-        assert(_version == 1)
-        _type = reader.read("!B")[0]
-        assert(_type == 5)
-        _length = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_length, 4)
-        obj.xid = reader.read("!L")[0]
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): return False
-        if self.xid != other.xid: return False
-        return True
-
-    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('}')
-
-message.subtypes[5] = features_request
-
-class flow_mod(message):
-    subtypes = {}
-
-    version = 1
-    type = 14
-
-    def __init__(self, xid=None, match=None, cookie=None, _command=None, idle_timeout=None, hard_timeout=None, priority=None, buffer_id=None, out_port=None, flags=None, actions=None):
-        if xid != None:
-            self.xid = xid
-        else:
-            self.xid = None
-        if match != None:
-            self.match = match
-        else:
-            self.match = ofp.match()
-        if cookie != None:
-            self.cookie = cookie
-        else:
-            self.cookie = 0
-        if _command != None:
-            self._command = _command
-        else:
-            self._command = 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 = []
-        return
-
-    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(util.pack_fm_cmd(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(util.pack_port_no(self.out_port))
-        packed.append(struct.pack("!H", self.flags))
-        packed.append(loxi.generic_util.pack_list(self.actions))
-        length = sum([len(x) for x in packed])
-        packed[2] = struct.pack("!H", length)
-        return ''.join(packed)
-
-    @staticmethod
-    def unpack(reader):
-        subtype, = reader.peek('!H', 56)
-        subclass = flow_mod.subtypes.get(subtype)
-        if subclass:
-            return subclass.unpack(reader)
-
-        obj = flow_mod()
-        _version = reader.read("!B")[0]
-        assert(_version == 1)
-        _type = reader.read("!B")[0]
-        assert(_type == 14)
-        _length = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_length, 4)
-        obj.xid = reader.read("!L")[0]
-        obj.match = ofp.match.unpack(reader)
-        obj.cookie = reader.read("!Q")[0]
-        obj._command = util.unpack_fm_cmd(reader)
-        obj.idle_timeout = reader.read("!H")[0]
-        obj.hard_timeout = reader.read("!H")[0]
-        obj.priority = reader.read("!H")[0]
-        obj.buffer_id = reader.read("!L")[0]
-        obj.out_port = util.unpack_port_no(reader)
-        obj.flags = reader.read("!H")[0]
-        obj.actions = loxi.generic_util.unpack_list(reader, ofp.action.action.unpack)
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): 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._command != other._command: 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 pretty_print(self, q):
-        q.text("flow_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("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('}')
-
-message.subtypes[14] = flow_mod
-
-class flow_add(flow_mod):
-    version = 1
-    type = 14
-    _command = 0
-
-    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):
-        if xid != None:
-            self.xid = xid
-        else:
-            self.xid = None
-        if match != None:
-            self.match = match
-        else:
-            self.match = ofp.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 = []
-        return
-
-    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(util.pack_fm_cmd(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(util.pack_port_no(self.out_port))
-        packed.append(struct.pack("!H", self.flags))
-        packed.append(loxi.generic_util.pack_list(self.actions))
-        length = sum([len(x) for x in packed])
-        packed[2] = struct.pack("!H", length)
-        return ''.join(packed)
-
-    @staticmethod
-    def unpack(reader):
-        obj = flow_add()
-        _version = reader.read("!B")[0]
-        assert(_version == 1)
-        _type = reader.read("!B")[0]
-        assert(_type == 14)
-        _length = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_length, 4)
-        obj.xid = reader.read("!L")[0]
-        obj.match = ofp.match.unpack(reader)
-        obj.cookie = reader.read("!Q")[0]
-        __command = util.unpack_fm_cmd(reader)
-        assert(__command == 0)
-        obj.idle_timeout = reader.read("!H")[0]
-        obj.hard_timeout = reader.read("!H")[0]
-        obj.priority = reader.read("!H")[0]
-        obj.buffer_id = reader.read("!L")[0]
-        obj.out_port = util.unpack_port_no(reader)
-        obj.flags = reader.read("!H")[0]
-        obj.actions = loxi.generic_util.unpack_list(reader, ofp.action.action.unpack)
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): 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 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('}')
-
-flow_mod.subtypes[0] = flow_add
-
-class flow_delete(flow_mod):
-    version = 1
-    type = 14
-    _command = 3
-
-    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):
-        if xid != None:
-            self.xid = xid
-        else:
-            self.xid = None
-        if match != None:
-            self.match = match
-        else:
-            self.match = ofp.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 = []
-        return
-
-    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(util.pack_fm_cmd(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(util.pack_port_no(self.out_port))
-        packed.append(struct.pack("!H", self.flags))
-        packed.append(loxi.generic_util.pack_list(self.actions))
-        length = sum([len(x) for x in packed])
-        packed[2] = struct.pack("!H", length)
-        return ''.join(packed)
-
-    @staticmethod
-    def unpack(reader):
-        obj = flow_delete()
-        _version = reader.read("!B")[0]
-        assert(_version == 1)
-        _type = reader.read("!B")[0]
-        assert(_type == 14)
-        _length = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_length, 4)
-        obj.xid = reader.read("!L")[0]
-        obj.match = ofp.match.unpack(reader)
-        obj.cookie = reader.read("!Q")[0]
-        __command = util.unpack_fm_cmd(reader)
-        assert(__command == 3)
-        obj.idle_timeout = reader.read("!H")[0]
-        obj.hard_timeout = reader.read("!H")[0]
-        obj.priority = reader.read("!H")[0]
-        obj.buffer_id = reader.read("!L")[0]
-        obj.out_port = util.unpack_port_no(reader)
-        obj.flags = reader.read("!H")[0]
-        obj.actions = loxi.generic_util.unpack_list(reader, ofp.action.action.unpack)
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): 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 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('}')
-
-flow_mod.subtypes[3] = flow_delete
-
-class flow_delete_strict(flow_mod):
-    version = 1
-    type = 14
-    _command = 4
-
-    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):
-        if xid != None:
-            self.xid = xid
-        else:
-            self.xid = None
-        if match != None:
-            self.match = match
-        else:
-            self.match = ofp.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 = []
-        return
-
-    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(util.pack_fm_cmd(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(util.pack_port_no(self.out_port))
-        packed.append(struct.pack("!H", self.flags))
-        packed.append(loxi.generic_util.pack_list(self.actions))
-        length = sum([len(x) for x in packed])
-        packed[2] = struct.pack("!H", length)
-        return ''.join(packed)
-
-    @staticmethod
-    def unpack(reader):
-        obj = flow_delete_strict()
-        _version = reader.read("!B")[0]
-        assert(_version == 1)
-        _type = reader.read("!B")[0]
-        assert(_type == 14)
-        _length = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_length, 4)
-        obj.xid = reader.read("!L")[0]
-        obj.match = ofp.match.unpack(reader)
-        obj.cookie = reader.read("!Q")[0]
-        __command = util.unpack_fm_cmd(reader)
-        assert(__command == 4)
-        obj.idle_timeout = reader.read("!H")[0]
-        obj.hard_timeout = reader.read("!H")[0]
-        obj.priority = reader.read("!H")[0]
-        obj.buffer_id = reader.read("!L")[0]
-        obj.out_port = util.unpack_port_no(reader)
-        obj.flags = reader.read("!H")[0]
-        obj.actions = loxi.generic_util.unpack_list(reader, ofp.action.action.unpack)
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): 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 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('}')
-
-flow_mod.subtypes[4] = flow_delete_strict
-
-class flow_mod_failed_error_msg(error_msg):
-    version = 1
-    type = 1
-    err_type = 3
-
-    def __init__(self, xid=None, code=None, data=None):
-        if xid != None:
-            self.xid = xid
-        else:
-            self.xid = None
-        if code != None:
-            self.code = code
-        else:
-            self.code = 0
-        if data != None:
-            self.data = data
-        else:
-            self.data = ''
-        return
-
-    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(reader):
-        obj = flow_mod_failed_error_msg()
-        _version = reader.read("!B")[0]
-        assert(_version == 1)
-        _type = reader.read("!B")[0]
-        assert(_type == 1)
-        _length = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_length, 4)
-        obj.xid = reader.read("!L")[0]
-        _err_type = reader.read("!H")[0]
-        assert(_err_type == 3)
-        obj.code = reader.read("!H")[0]
-        obj.data = str(reader.read_all())
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): return False
-        if self.xid != other.xid: return False
-        if self.code != other.code: return False
-        if self.data != other.data: return False
-        return True
-
-    def pretty_print(self, q):
-        q.text("flow_mod_failed_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("code = ");
-                q.text("%#x" % self.code)
-                q.text(","); q.breakable()
-                q.text("data = ");
-                q.pp(self.data)
-            q.breakable()
-        q.text('}')
-
-error_msg.subtypes[3] = flow_mod_failed_error_msg
-
-class flow_modify(flow_mod):
-    version = 1
-    type = 14
-    _command = 1
-
-    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):
-        if xid != None:
-            self.xid = xid
-        else:
-            self.xid = None
-        if match != None:
-            self.match = match
-        else:
-            self.match = ofp.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 = []
-        return
-
-    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(util.pack_fm_cmd(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(util.pack_port_no(self.out_port))
-        packed.append(struct.pack("!H", self.flags))
-        packed.append(loxi.generic_util.pack_list(self.actions))
-        length = sum([len(x) for x in packed])
-        packed[2] = struct.pack("!H", length)
-        return ''.join(packed)
-
-    @staticmethod
-    def unpack(reader):
-        obj = flow_modify()
-        _version = reader.read("!B")[0]
-        assert(_version == 1)
-        _type = reader.read("!B")[0]
-        assert(_type == 14)
-        _length = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_length, 4)
-        obj.xid = reader.read("!L")[0]
-        obj.match = ofp.match.unpack(reader)
-        obj.cookie = reader.read("!Q")[0]
-        __command = util.unpack_fm_cmd(reader)
-        assert(__command == 1)
-        obj.idle_timeout = reader.read("!H")[0]
-        obj.hard_timeout = reader.read("!H")[0]
-        obj.priority = reader.read("!H")[0]
-        obj.buffer_id = reader.read("!L")[0]
-        obj.out_port = util.unpack_port_no(reader)
-        obj.flags = reader.read("!H")[0]
-        obj.actions = loxi.generic_util.unpack_list(reader, ofp.action.action.unpack)
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): 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 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('}')
-
-flow_mod.subtypes[1] = flow_modify
-
-class flow_modify_strict(flow_mod):
-    version = 1
-    type = 14
-    _command = 2
-
-    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):
-        if xid != None:
-            self.xid = xid
-        else:
-            self.xid = None
-        if match != None:
-            self.match = match
-        else:
-            self.match = ofp.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 = []
-        return
-
-    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(util.pack_fm_cmd(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(util.pack_port_no(self.out_port))
-        packed.append(struct.pack("!H", self.flags))
-        packed.append(loxi.generic_util.pack_list(self.actions))
-        length = sum([len(x) for x in packed])
-        packed[2] = struct.pack("!H", length)
-        return ''.join(packed)
-
-    @staticmethod
-    def unpack(reader):
-        obj = flow_modify_strict()
-        _version = reader.read("!B")[0]
-        assert(_version == 1)
-        _type = reader.read("!B")[0]
-        assert(_type == 14)
-        _length = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_length, 4)
-        obj.xid = reader.read("!L")[0]
-        obj.match = ofp.match.unpack(reader)
-        obj.cookie = reader.read("!Q")[0]
-        __command = util.unpack_fm_cmd(reader)
-        assert(__command == 2)
-        obj.idle_timeout = reader.read("!H")[0]
-        obj.hard_timeout = reader.read("!H")[0]
-        obj.priority = reader.read("!H")[0]
-        obj.buffer_id = reader.read("!L")[0]
-        obj.out_port = util.unpack_port_no(reader)
-        obj.flags = reader.read("!H")[0]
-        obj.actions = loxi.generic_util.unpack_list(reader, ofp.action.action.unpack)
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): 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 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('}')
-
-flow_mod.subtypes[2] = flow_modify_strict
-
-class flow_removed(message):
-    version = 1
-    type = 11
-
-    def __init__(self, xid=None, match=None, cookie=None, priority=None, reason=None, duration_sec=None, duration_nsec=None, idle_timeout=None, packet_count=None, byte_count=None):
-        if xid != None:
-            self.xid = xid
-        else:
-            self.xid = None
-        if match != None:
-            self.match = match
-        else:
-            self.match = ofp.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 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 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
-        return
-
-    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('\x00' * 1)
-        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('\x00' * 2)
-        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(reader):
-        obj = flow_removed()
-        _version = reader.read("!B")[0]
-        assert(_version == 1)
-        _type = reader.read("!B")[0]
-        assert(_type == 11)
-        _length = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_length, 4)
-        obj.xid = reader.read("!L")[0]
-        obj.match = ofp.match.unpack(reader)
-        obj.cookie = reader.read("!Q")[0]
-        obj.priority = reader.read("!H")[0]
-        obj.reason = reader.read("!B")[0]
-        reader.skip(1)
-        obj.duration_sec = reader.read("!L")[0]
-        obj.duration_nsec = reader.read("!L")[0]
-        obj.idle_timeout = reader.read("!H")[0]
-        reader.skip(2)
-        obj.packet_count = reader.read("!Q")[0]
-        obj.byte_count = reader.read("!Q")[0]
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): 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.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.packet_count != other.packet_count: return False
-        if self.byte_count != other.byte_count: return False
-        return True
-
-    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("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("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('}')
-
-message.subtypes[11] = flow_removed
-
-class flow_stats_reply(stats_reply):
-    version = 1
-    type = 17
-    stats_type = 1
-
-    def __init__(self, xid=None, flags=None, entries=None):
-        if xid != None:
-            self.xid = xid
-        else:
-            self.xid = None
-        if flags != None:
-            self.flags = flags
-        else:
-            self.flags = 0
-        if entries != None:
-            self.entries = entries
-        else:
-            self.entries = []
-        return
-
-    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(loxi.generic_util.pack_list(self.entries))
-        length = sum([len(x) for x in packed])
-        packed[2] = struct.pack("!H", length)
-        return ''.join(packed)
-
-    @staticmethod
-    def unpack(reader):
-        obj = flow_stats_reply()
-        _version = reader.read("!B")[0]
-        assert(_version == 1)
-        _type = reader.read("!B")[0]
-        assert(_type == 17)
-        _length = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_length, 4)
-        obj.xid = reader.read("!L")[0]
-        _stats_type = reader.read("!H")[0]
-        assert(_stats_type == 1)
-        obj.flags = reader.read("!H")[0]
-        obj.entries = loxi.generic_util.unpack_list(reader, ofp.common.flow_stats_entry.unpack)
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): 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 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('}')
-
-stats_reply.subtypes[1] = flow_stats_reply
-
-class flow_stats_request(stats_request):
-    version = 1
-    type = 16
-    stats_type = 1
-
-    def __init__(self, xid=None, flags=None, match=None, table_id=None, out_port=None):
-        if xid != None:
-            self.xid = xid
-        else:
-            self.xid = None
-        if flags != None:
-            self.flags = flags
-        else:
-            self.flags = 0
-        if match != None:
-            self.match = match
-        else:
-            self.match = ofp.match()
-        if table_id != None:
-            self.table_id = table_id
-        else:
-            self.table_id = 0
-        if out_port != None:
-            self.out_port = out_port
-        else:
-            self.out_port = 0
-        return
-
-    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('\x00' * 1)
-        packed.append(util.pack_port_no(self.out_port))
-        length = sum([len(x) for x in packed])
-        packed[2] = struct.pack("!H", length)
-        return ''.join(packed)
-
-    @staticmethod
-    def unpack(reader):
-        obj = flow_stats_request()
-        _version = reader.read("!B")[0]
-        assert(_version == 1)
-        _type = reader.read("!B")[0]
-        assert(_type == 16)
-        _length = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_length, 4)
-        obj.xid = reader.read("!L")[0]
-        _stats_type = reader.read("!H")[0]
-        assert(_stats_type == 1)
-        obj.flags = reader.read("!H")[0]
-        obj.match = ofp.match.unpack(reader)
-        obj.table_id = reader.read("!B")[0]
-        reader.skip(1)
-        obj.out_port = util.unpack_port_no(reader)
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): 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.out_port != other.out_port: return False
-        return True
-
-    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("out_port = ");
-                q.text(util.pretty_port(self.out_port))
-            q.breakable()
-        q.text('}')
-
-stats_request.subtypes[1] = flow_stats_request
-
-class get_config_reply(message):
-    version = 1
-    type = 8
-
-    def __init__(self, xid=None, flags=None, miss_send_len=None):
-        if xid != None:
-            self.xid = xid
-        else:
-            self.xid = None
-        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
-        return
-
-    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(reader):
-        obj = get_config_reply()
-        _version = reader.read("!B")[0]
-        assert(_version == 1)
-        _type = reader.read("!B")[0]
-        assert(_type == 8)
-        _length = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_length, 4)
-        obj.xid = reader.read("!L")[0]
-        obj.flags = reader.read("!H")[0]
-        obj.miss_send_len = reader.read("!H")[0]
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): 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 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('}')
-
-message.subtypes[8] = get_config_reply
-
-class get_config_request(message):
-    version = 1
-    type = 7
-
-    def __init__(self, xid=None):
-        if xid != None:
-            self.xid = xid
-        else:
-            self.xid = None
-        return
-
-    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(reader):
-        obj = get_config_request()
-        _version = reader.read("!B")[0]
-        assert(_version == 1)
-        _type = reader.read("!B")[0]
-        assert(_type == 7)
-        _length = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_length, 4)
-        obj.xid = reader.read("!L")[0]
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): return False
-        if self.xid != other.xid: return False
-        return True
-
-    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('}')
-
-message.subtypes[7] = get_config_request
-
-class hello(message):
-    version = 1
-    type = 0
-
-    def __init__(self, xid=None):
-        if xid != None:
-            self.xid = xid
-        else:
-            self.xid = None
-        return
-
-    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(reader):
-        obj = hello()
-        _version = reader.read("!B")[0]
-        assert(_version == 1)
-        _type = reader.read("!B")[0]
-        assert(_type == 0)
-        _length = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_length, 4)
-        obj.xid = reader.read("!L")[0]
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): return False
-        if self.xid != other.xid: return False
-        return True
-
-    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('}')
-
-message.subtypes[0] = hello
-
-class hello_failed_error_msg(error_msg):
-    version = 1
-    type = 1
-    err_type = 0
-
-    def __init__(self, xid=None, code=None, data=None):
-        if xid != None:
-            self.xid = xid
-        else:
-            self.xid = None
-        if code != None:
-            self.code = code
-        else:
-            self.code = 0
-        if data != None:
-            self.data = data
-        else:
-            self.data = ''
-        return
-
-    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(reader):
-        obj = hello_failed_error_msg()
-        _version = reader.read("!B")[0]
-        assert(_version == 1)
-        _type = reader.read("!B")[0]
-        assert(_type == 1)
-        _length = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_length, 4)
-        obj.xid = reader.read("!L")[0]
-        _err_type = reader.read("!H")[0]
-        assert(_err_type == 0)
-        obj.code = reader.read("!H")[0]
-        obj.data = str(reader.read_all())
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): return False
-        if self.xid != other.xid: return False
-        if self.code != other.code: return False
-        if self.data != other.data: return False
-        return True
-
-    def pretty_print(self, q):
-        q.text("hello_failed_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("code = ");
-                q.text("%#x" % self.code)
-                q.text(","); q.breakable()
-                q.text("data = ");
-                q.pp(self.data)
-            q.breakable()
-        q.text('}')
-
-error_msg.subtypes[0] = hello_failed_error_msg
-
-class nicira_header(experimenter):
-    subtypes = {}
-
-    version = 1
-    type = 4
-    experimenter = 8992
-
-    def __init__(self, xid=None, subtype=None):
-        if xid != None:
-            self.xid = xid
-        else:
-            self.xid = None
-        if subtype != None:
-            self.subtype = subtype
-        else:
-            self.subtype = 0
-        return
-
-    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(reader):
-        subtype, = reader.peek('!L', 12)
-        subclass = nicira_header.subtypes.get(subtype)
-        if subclass:
-            return subclass.unpack(reader)
-
-        obj = nicira_header()
-        _version = reader.read("!B")[0]
-        assert(_version == 1)
-        _type = reader.read("!B")[0]
-        assert(_type == 4)
-        _length = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_length, 4)
-        obj.xid = reader.read("!L")[0]
-        _experimenter = reader.read("!L")[0]
-        assert(_experimenter == 8992)
-        obj.subtype = reader.read("!L")[0]
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): return False
-        if self.xid != other.xid: return False
-        if self.subtype != other.subtype: return False
-        return True
-
-    def pretty_print(self, q):
-        q.text("nicira_header {")
-        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('}')
-
-experimenter.subtypes[8992] = nicira_header
-
-class nicira_controller_role_reply(nicira_header):
-    version = 1
-    type = 4
-    experimenter = 8992
-    subtype = 11
-
-    def __init__(self, xid=None, role=None):
-        if xid != None:
-            self.xid = xid
-        else:
-            self.xid = None
-        if role != None:
-            self.role = role
-        else:
-            self.role = 0
-        return
-
-    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(reader):
-        obj = nicira_controller_role_reply()
-        _version = reader.read("!B")[0]
-        assert(_version == 1)
-        _type = reader.read("!B")[0]
-        assert(_type == 4)
-        _length = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_length, 4)
-        obj.xid = reader.read("!L")[0]
-        _experimenter = reader.read("!L")[0]
-        assert(_experimenter == 8992)
-        _subtype = reader.read("!L")[0]
-        assert(_subtype == 11)
-        obj.role = reader.read("!L")[0]
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): return False
-        if self.xid != other.xid: return False
-        if self.role != other.role: return False
-        return True
-
-    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('}')
-
-nicira_header.subtypes[11] = nicira_controller_role_reply
-
-class nicira_controller_role_request(nicira_header):
-    version = 1
-    type = 4
-    experimenter = 8992
-    subtype = 10
-
-    def __init__(self, xid=None, role=None):
-        if xid != None:
-            self.xid = xid
-        else:
-            self.xid = None
-        if role != None:
-            self.role = role
-        else:
-            self.role = 0
-        return
-
-    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(reader):
-        obj = nicira_controller_role_request()
-        _version = reader.read("!B")[0]
-        assert(_version == 1)
-        _type = reader.read("!B")[0]
-        assert(_type == 4)
-        _length = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_length, 4)
-        obj.xid = reader.read("!L")[0]
-        _experimenter = reader.read("!L")[0]
-        assert(_experimenter == 8992)
-        _subtype = reader.read("!L")[0]
-        assert(_subtype == 10)
-        obj.role = reader.read("!L")[0]
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): return False
-        if self.xid != other.xid: return False
-        if self.role != other.role: return False
-        return True
-
-    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('}')
-
-nicira_header.subtypes[10] = nicira_controller_role_request
-
-class packet_in(message):
-    version = 1
-    type = 10
-
-    def __init__(self, xid=None, buffer_id=None, total_len=None, in_port=None, reason=None, data=None):
-        if xid != None:
-            self.xid = xid
-        else:
-            self.xid = None
-        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 data != None:
-            self.data = data
-        else:
-            self.data = ''
-        return
-
-    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(util.pack_port_no(self.in_port))
-        packed.append(struct.pack("!B", self.reason))
-        packed.append('\x00' * 1)
-        packed.append(self.data)
-        length = sum([len(x) for x in packed])
-        packed[2] = struct.pack("!H", length)
-        return ''.join(packed)
-
-    @staticmethod
-    def unpack(reader):
-        obj = packet_in()
-        _version = reader.read("!B")[0]
-        assert(_version == 1)
-        _type = reader.read("!B")[0]
-        assert(_type == 10)
-        _length = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_length, 4)
-        obj.xid = reader.read("!L")[0]
-        obj.buffer_id = reader.read("!L")[0]
-        obj.total_len = reader.read("!H")[0]
-        obj.in_port = util.unpack_port_no(reader)
-        obj.reason = reader.read("!B")[0]
-        reader.skip(1)
-        obj.data = str(reader.read_all())
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): 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.data != other.data: return False
-        return True
-
-    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("data = ");
-                q.pp(self.data)
-            q.breakable()
-        q.text('}')
-
-message.subtypes[10] = packet_in
-
-class packet_out(message):
-    version = 1
-    type = 13
-
-    def __init__(self, xid=None, buffer_id=None, in_port=None, actions=None, data=None):
-        if xid != None:
-            self.xid = xid
-        else:
-            self.xid = None
-        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 = ''
-        return
-
-    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(util.pack_port_no(self.in_port))
-        packed.append(struct.pack("!H", 0)) # placeholder for actions_len at index 6
-        packed.append(loxi.generic_util.pack_list(self.actions))
-        packed[6] = struct.pack("!H", len(packed[-1]))
-        packed.append(self.data)
-        length = sum([len(x) for x in packed])
-        packed[2] = struct.pack("!H", length)
-        return ''.join(packed)
-
-    @staticmethod
-    def unpack(reader):
-        obj = packet_out()
-        _version = reader.read("!B")[0]
-        assert(_version == 1)
-        _type = reader.read("!B")[0]
-        assert(_type == 13)
-        _length = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_length, 4)
-        obj.xid = reader.read("!L")[0]
-        obj.buffer_id = reader.read("!L")[0]
-        obj.in_port = util.unpack_port_no(reader)
-        _actions_len = reader.read("!H")[0]
-        obj.actions = loxi.generic_util.unpack_list(reader.slice(_actions_len), ofp.action.action.unpack)
-        obj.data = str(reader.read_all())
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): 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 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('}')
-
-message.subtypes[13] = packet_out
-
-class port_mod(message):
-    version = 1
-    type = 15
-
-    def __init__(self, xid=None, port_no=None, hw_addr=None, config=None, mask=None, advertise=None):
-        if xid != None:
-            self.xid = xid
-        else:
-            self.xid = 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 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
-        return
-
-    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(util.pack_port_no(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('\x00' * 4)
-        length = sum([len(x) for x in packed])
-        packed[2] = struct.pack("!H", length)
-        return ''.join(packed)
-
-    @staticmethod
-    def unpack(reader):
-        obj = port_mod()
-        _version = reader.read("!B")[0]
-        assert(_version == 1)
-        _type = reader.read("!B")[0]
-        assert(_type == 15)
-        _length = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_length, 4)
-        obj.xid = reader.read("!L")[0]
-        obj.port_no = util.unpack_port_no(reader)
-        obj.hw_addr = list(reader.read('!6B'))
-        obj.config = reader.read("!L")[0]
-        obj.mask = reader.read("!L")[0]
-        obj.advertise = reader.read("!L")[0]
-        reader.skip(4)
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): 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
-        return True
-
-    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.breakable()
-        q.text('}')
-
-message.subtypes[15] = port_mod
-
-class port_mod_failed_error_msg(error_msg):
-    version = 1
-    type = 1
-    err_type = 4
-
-    def __init__(self, xid=None, code=None, data=None):
-        if xid != None:
-            self.xid = xid
-        else:
-            self.xid = None
-        if code != None:
-            self.code = code
-        else:
-            self.code = 0
-        if data != None:
-            self.data = data
-        else:
-            self.data = ''
-        return
-
-    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(reader):
-        obj = port_mod_failed_error_msg()
-        _version = reader.read("!B")[0]
-        assert(_version == 1)
-        _type = reader.read("!B")[0]
-        assert(_type == 1)
-        _length = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_length, 4)
-        obj.xid = reader.read("!L")[0]
-        _err_type = reader.read("!H")[0]
-        assert(_err_type == 4)
-        obj.code = reader.read("!H")[0]
-        obj.data = str(reader.read_all())
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): return False
-        if self.xid != other.xid: return False
-        if self.code != other.code: return False
-        if self.data != other.data: return False
-        return True
-
-    def pretty_print(self, q):
-        q.text("port_mod_failed_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("code = ");
-                q.text("%#x" % self.code)
-                q.text(","); q.breakable()
-                q.text("data = ");
-                q.pp(self.data)
-            q.breakable()
-        q.text('}')
-
-error_msg.subtypes[4] = port_mod_failed_error_msg
-
-class port_stats_reply(stats_reply):
-    version = 1
-    type = 17
-    stats_type = 4
-
-    def __init__(self, xid=None, flags=None, entries=None):
-        if xid != None:
-            self.xid = xid
-        else:
-            self.xid = None
-        if flags != None:
-            self.flags = flags
-        else:
-            self.flags = 0
-        if entries != None:
-            self.entries = entries
-        else:
-            self.entries = []
-        return
-
-    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(loxi.generic_util.pack_list(self.entries))
-        length = sum([len(x) for x in packed])
-        packed[2] = struct.pack("!H", length)
-        return ''.join(packed)
-
-    @staticmethod
-    def unpack(reader):
-        obj = port_stats_reply()
-        _version = reader.read("!B")[0]
-        assert(_version == 1)
-        _type = reader.read("!B")[0]
-        assert(_type == 17)
-        _length = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_length, 4)
-        obj.xid = reader.read("!L")[0]
-        _stats_type = reader.read("!H")[0]
-        assert(_stats_type == 4)
-        obj.flags = reader.read("!H")[0]
-        obj.entries = loxi.generic_util.unpack_list(reader, ofp.common.port_stats_entry.unpack)
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): 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 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('}')
-
-stats_reply.subtypes[4] = port_stats_reply
-
-class port_stats_request(stats_request):
-    version = 1
-    type = 16
-    stats_type = 4
-
-    def __init__(self, xid=None, flags=None, port_no=None):
-        if xid != None:
-            self.xid = xid
-        else:
-            self.xid = None
-        if flags != None:
-            self.flags = flags
-        else:
-            self.flags = 0
-        if port_no != None:
-            self.port_no = port_no
-        else:
-            self.port_no = 0
-        return
-
-    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(util.pack_port_no(self.port_no))
-        packed.append('\x00' * 6)
-        length = sum([len(x) for x in packed])
-        packed[2] = struct.pack("!H", length)
-        return ''.join(packed)
-
-    @staticmethod
-    def unpack(reader):
-        obj = port_stats_request()
-        _version = reader.read("!B")[0]
-        assert(_version == 1)
-        _type = reader.read("!B")[0]
-        assert(_type == 16)
-        _length = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_length, 4)
-        obj.xid = reader.read("!L")[0]
-        _stats_type = reader.read("!H")[0]
-        assert(_stats_type == 4)
-        obj.flags = reader.read("!H")[0]
-        obj.port_no = util.unpack_port_no(reader)
-        reader.skip(6)
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): 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
-        return True
-
-    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.breakable()
-        q.text('}')
-
-stats_request.subtypes[4] = port_stats_request
-
-class port_status(message):
-    version = 1
-    type = 12
-
-    def __init__(self, xid=None, reason=None, desc=None):
-        if xid != None:
-            self.xid = xid
-        else:
-            self.xid = None
-        if reason != None:
-            self.reason = reason
-        else:
-            self.reason = 0
-        if desc != None:
-            self.desc = desc
-        else:
-            self.desc = ofp.port_desc()
-        return
-
-    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('\x00' * 7)
-        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(reader):
-        obj = port_status()
-        _version = reader.read("!B")[0]
-        assert(_version == 1)
-        _type = reader.read("!B")[0]
-        assert(_type == 12)
-        _length = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_length, 4)
-        obj.xid = reader.read("!L")[0]
-        obj.reason = reader.read("!B")[0]
-        reader.skip(7)
-        obj.desc = ofp.port_desc.unpack(reader)
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): return False
-        if self.xid != other.xid: return False
-        if self.reason != other.reason: return False
-        if self.desc != other.desc: return False
-        return True
-
-    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("desc = ");
-                q.pp(self.desc)
-            q.breakable()
-        q.text('}')
-
-message.subtypes[12] = port_status
-
-class queue_get_config_reply(message):
-    version = 1
-    type = 21
-
-    def __init__(self, xid=None, port=None, queues=None):
-        if xid != None:
-            self.xid = xid
-        else:
-            self.xid = None
-        if port != None:
-            self.port = port
-        else:
-            self.port = 0
-        if queues != None:
-            self.queues = queues
-        else:
-            self.queues = []
-        return
-
-    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(util.pack_port_no(self.port))
-        packed.append('\x00' * 6)
-        packed.append(loxi.generic_util.pack_list(self.queues))
-        length = sum([len(x) for x in packed])
-        packed[2] = struct.pack("!H", length)
-        return ''.join(packed)
-
-    @staticmethod
-    def unpack(reader):
-        obj = queue_get_config_reply()
-        _version = reader.read("!B")[0]
-        assert(_version == 1)
-        _type = reader.read("!B")[0]
-        assert(_type == 21)
-        _length = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_length, 4)
-        obj.xid = reader.read("!L")[0]
-        obj.port = util.unpack_port_no(reader)
-        reader.skip(6)
-        obj.queues = loxi.generic_util.unpack_list(reader, ofp.common.packet_queue.unpack)
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): return False
-        if self.xid != other.xid: return False
-        if self.port != other.port: return False
-        if self.queues != other.queues: return False
-        return True
-
-    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("queues = ");
-                q.pp(self.queues)
-            q.breakable()
-        q.text('}')
-
-message.subtypes[21] = queue_get_config_reply
-
-class queue_get_config_request(message):
-    version = 1
-    type = 20
-
-    def __init__(self, xid=None, port=None):
-        if xid != None:
-            self.xid = xid
-        else:
-            self.xid = None
-        if port != None:
-            self.port = port
-        else:
-            self.port = 0
-        return
-
-    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(util.pack_port_no(self.port))
-        packed.append('\x00' * 2)
-        length = sum([len(x) for x in packed])
-        packed[2] = struct.pack("!H", length)
-        return ''.join(packed)
-
-    @staticmethod
-    def unpack(reader):
-        obj = queue_get_config_request()
-        _version = reader.read("!B")[0]
-        assert(_version == 1)
-        _type = reader.read("!B")[0]
-        assert(_type == 20)
-        _length = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_length, 4)
-        obj.xid = reader.read("!L")[0]
-        obj.port = util.unpack_port_no(reader)
-        reader.skip(2)
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): return False
-        if self.xid != other.xid: return False
-        if self.port != other.port: return False
-        return True
-
-    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.breakable()
-        q.text('}')
-
-message.subtypes[20] = queue_get_config_request
-
-class queue_op_failed_error_msg(error_msg):
-    version = 1
-    type = 1
-    err_type = 5
-
-    def __init__(self, xid=None, code=None, data=None):
-        if xid != None:
-            self.xid = xid
-        else:
-            self.xid = None
-        if code != None:
-            self.code = code
-        else:
-            self.code = 0
-        if data != None:
-            self.data = data
-        else:
-            self.data = ''
-        return
-
-    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(reader):
-        obj = queue_op_failed_error_msg()
-        _version = reader.read("!B")[0]
-        assert(_version == 1)
-        _type = reader.read("!B")[0]
-        assert(_type == 1)
-        _length = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_length, 4)
-        obj.xid = reader.read("!L")[0]
-        _err_type = reader.read("!H")[0]
-        assert(_err_type == 5)
-        obj.code = reader.read("!H")[0]
-        obj.data = str(reader.read_all())
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): return False
-        if self.xid != other.xid: return False
-        if self.code != other.code: return False
-        if self.data != other.data: return False
-        return True
-
-    def pretty_print(self, q):
-        q.text("queue_op_failed_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("code = ");
-                q.text("%#x" % self.code)
-                q.text(","); q.breakable()
-                q.text("data = ");
-                q.pp(self.data)
-            q.breakable()
-        q.text('}')
-
-error_msg.subtypes[5] = queue_op_failed_error_msg
-
-class queue_stats_reply(stats_reply):
-    version = 1
-    type = 17
-    stats_type = 5
-
-    def __init__(self, xid=None, flags=None, entries=None):
-        if xid != None:
-            self.xid = xid
-        else:
-            self.xid = None
-        if flags != None:
-            self.flags = flags
-        else:
-            self.flags = 0
-        if entries != None:
-            self.entries = entries
-        else:
-            self.entries = []
-        return
-
-    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(loxi.generic_util.pack_list(self.entries))
-        length = sum([len(x) for x in packed])
-        packed[2] = struct.pack("!H", length)
-        return ''.join(packed)
-
-    @staticmethod
-    def unpack(reader):
-        obj = queue_stats_reply()
-        _version = reader.read("!B")[0]
-        assert(_version == 1)
-        _type = reader.read("!B")[0]
-        assert(_type == 17)
-        _length = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_length, 4)
-        obj.xid = reader.read("!L")[0]
-        _stats_type = reader.read("!H")[0]
-        assert(_stats_type == 5)
-        obj.flags = reader.read("!H")[0]
-        obj.entries = loxi.generic_util.unpack_list(reader, ofp.common.queue_stats_entry.unpack)
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): 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 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('}')
-
-stats_reply.subtypes[5] = queue_stats_reply
-
-class queue_stats_request(stats_request):
-    version = 1
-    type = 16
-    stats_type = 5
-
-    def __init__(self, xid=None, flags=None, port_no=None, queue_id=None):
-        if xid != None:
-            self.xid = xid
-        else:
-            self.xid = None
-        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 queue_id != None:
-            self.queue_id = queue_id
-        else:
-            self.queue_id = 0
-        return
-
-    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(util.pack_port_no(self.port_no))
-        packed.append('\x00' * 2)
-        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(reader):
-        obj = queue_stats_request()
-        _version = reader.read("!B")[0]
-        assert(_version == 1)
-        _type = reader.read("!B")[0]
-        assert(_type == 16)
-        _length = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_length, 4)
-        obj.xid = reader.read("!L")[0]
-        _stats_type = reader.read("!H")[0]
-        assert(_stats_type == 5)
-        obj.flags = reader.read("!H")[0]
-        obj.port_no = util.unpack_port_no(reader)
-        reader.skip(2)
-        obj.queue_id = reader.read("!L")[0]
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): 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.queue_id != other.queue_id: return False
-        return True
-
-    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("queue_id = ");
-                q.text("%#x" % self.queue_id)
-            q.breakable()
-        q.text('}')
-
-stats_request.subtypes[5] = queue_stats_request
-
-class set_config(message):
-    version = 1
-    type = 9
-
-    def __init__(self, xid=None, flags=None, miss_send_len=None):
-        if xid != None:
-            self.xid = xid
-        else:
-            self.xid = None
-        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
-        return
-
-    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(reader):
-        obj = set_config()
-        _version = reader.read("!B")[0]
-        assert(_version == 1)
-        _type = reader.read("!B")[0]
-        assert(_type == 9)
-        _length = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_length, 4)
-        obj.xid = reader.read("!L")[0]
-        obj.flags = reader.read("!H")[0]
-        obj.miss_send_len = reader.read("!H")[0]
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): 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 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('}')
-
-message.subtypes[9] = set_config
-
-class table_mod(message):
-    version = 1
-    type = 22
-
-    def __init__(self, xid=None, table_id=None, config=None):
-        if xid != None:
-            self.xid = xid
-        else:
-            self.xid = None
-        if table_id != None:
-            self.table_id = table_id
-        else:
-            self.table_id = 0
-        if config != None:
-            self.config = config
-        else:
-            self.config = 0
-        return
-
-    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('\x00' * 3)
-        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(reader):
-        obj = table_mod()
-        _version = reader.read("!B")[0]
-        assert(_version == 1)
-        _type = reader.read("!B")[0]
-        assert(_type == 22)
-        _length = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_length, 4)
-        obj.xid = reader.read("!L")[0]
-        obj.table_id = reader.read("!B")[0]
-        reader.skip(3)
-        obj.config = reader.read("!L")[0]
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): return False
-        if self.xid != other.xid: return False
-        if self.table_id != other.table_id: return False
-        if self.config != other.config: return False
-        return True
-
-    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("config = ");
-                q.text("%#x" % self.config)
-            q.breakable()
-        q.text('}')
-
-message.subtypes[22] = table_mod
-
-class table_stats_reply(stats_reply):
-    version = 1
-    type = 17
-    stats_type = 3
-
-    def __init__(self, xid=None, flags=None, entries=None):
-        if xid != None:
-            self.xid = xid
-        else:
-            self.xid = None
-        if flags != None:
-            self.flags = flags
-        else:
-            self.flags = 0
-        if entries != None:
-            self.entries = entries
-        else:
-            self.entries = []
-        return
-
-    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(loxi.generic_util.pack_list(self.entries))
-        length = sum([len(x) for x in packed])
-        packed[2] = struct.pack("!H", length)
-        return ''.join(packed)
-
-    @staticmethod
-    def unpack(reader):
-        obj = table_stats_reply()
-        _version = reader.read("!B")[0]
-        assert(_version == 1)
-        _type = reader.read("!B")[0]
-        assert(_type == 17)
-        _length = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_length, 4)
-        obj.xid = reader.read("!L")[0]
-        _stats_type = reader.read("!H")[0]
-        assert(_stats_type == 3)
-        obj.flags = reader.read("!H")[0]
-        obj.entries = loxi.generic_util.unpack_list(reader, ofp.common.table_stats_entry.unpack)
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): 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 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('}')
-
-stats_reply.subtypes[3] = table_stats_reply
-
-class table_stats_request(stats_request):
-    version = 1
-    type = 16
-    stats_type = 3
-
-    def __init__(self, xid=None, flags=None):
-        if xid != None:
-            self.xid = xid
-        else:
-            self.xid = None
-        if flags != None:
-            self.flags = flags
-        else:
-            self.flags = 0
-        return
-
-    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(reader):
-        obj = table_stats_request()
-        _version = reader.read("!B")[0]
-        assert(_version == 1)
-        _type = reader.read("!B")[0]
-        assert(_type == 16)
-        _length = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_length, 4)
-        obj.xid = reader.read("!L")[0]
-        _stats_type = reader.read("!H")[0]
-        assert(_stats_type == 3)
-        obj.flags = reader.read("!H")[0]
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): return False
-        if self.xid != other.xid: return False
-        if self.flags != other.flags: return False
-        return True
-
-    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('}')
-
-stats_request.subtypes[3] = table_stats_request
-
-
-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 != ofp.OFP_VERSION and msg_type != ofp.OFPT_HELLO:
-        raise loxi.ProtocolError("wrong OpenFlow version (expected %d, got %d)" % (ofp.OFP_VERSION, msg_ver))
-    if len(buf) != msg_len:
-        raise loxi.ProtocolError("incorrect message size")
-    return message.unpack(loxi.generic_util.OFReader(buf))
diff --git a/python/ofagent/loxi/of10/util.py b/python/ofagent/loxi/of10/util.py
deleted file mode 100644
index 28ffba1..0000000
--- a/python/ofagent/loxi/of10/util.py
+++ /dev/null
@@ -1,139 +0,0 @@
-# Copyright 2017-present Open Networking Foundation
-#
-# 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.
-# Copyright (c) 2008 The Board of Trustees of The Leland Stanford Junior University
-# Copyright (c) 2011, 2012 Open Networking Foundation
-# Copyright (c) 2012, 2013 Big Switch Networks, Inc.
-# See the file LICENSE.pyloxi which should have been included in the source distribution
-# Automatically generated by LOXI from template util.py
-# Do not modify
-
-import struct
-import loxi
-import const
-import common
-import action
-
-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
-
-def pack_port_no(value):
-    return struct.pack("!H", value)
-
-def unpack_port_no(reader):
-    return reader.read("!H")[0]
-
-def pack_fm_cmd(value):
-    return struct.pack("!H", value)
-
-def unpack_fm_cmd(reader):
-    return reader.read("!H")[0]
-
-def init_wc_bmap():
-    return const.OFPFW_ALL
-
-def pack_wc_bmap(value):
-    return struct.pack("!L", value)
-
-def unpack_wc_bmap(reader):
-    return reader.read("!L")[0]
-
-def init_match_bmap():
-    return const.OFPFW_ALL
-
-def pack_match_bmap(value):
-    return struct.pack("!L", value)
-
-def unpack_match_bmap(reader):
-    return reader.read("!L")[0]
-
-MASK64 = (1 << 64) - 1
-
-def pack_bitmap_128(value):
-    x = 0l
-    for y in value:
-        x |= 1 << y
-    return struct.pack("!QQ", (x >> 64) & MASK64, x & MASK64)
-
-def unpack_bitmap_128(reader):
-    hi, lo = reader.read("!QQ")
-    x = (hi << 64) | lo
-    i = 0
-    value = set()
-    while x != 0:
-        if x & 1 == 1:
-            value.add(i)
-        i += 1
-        x >>= 1
-    return value
-
-def pack_bitmap_512(value):
-    words = [0] * 8
-    for v in value:
-        assert v < 512
-        words[7-v/64] |= 1 << (v % 64)
-    return struct.pack("!8Q", *words)
-
-def unpack_bitmap_512(reader):
-    words = reader.read("!8Q")
-    x = 0l
-    for word in words:
-        x <<= 64
-        x |= word
-    i = 0
-    value = set()
-    while x != 0:
-        if x & 1 == 1:
-            value.add(i)
-        i += 1
-        x >>= 1
-    return value
-
-def pack_checksum_128(value):
-    return struct.pack("!QQ", (value >> 64) & MASK64, value & MASK64)
-
-def unpack_checksum_128(reader):
-    hi, lo = reader.read("!QQ")
-    return (hi << 64) | lo
diff --git a/python/ofagent/loxi/of11/__init__.py b/python/ofagent/loxi/of11/__init__.py
deleted file mode 100644
index 29d4afe..0000000
--- a/python/ofagent/loxi/of11/__init__.py
+++ /dev/null
@@ -1,29 +0,0 @@
-# Copyright 2017-present Open Networking Foundation
-#
-# 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.
-# Copyright (c) 2008 The Board of Trustees of The Leland Stanford Junior University
-# Copyright (c) 2011, 2012 Open Networking Foundation
-# Copyright (c) 2012, 2013 Big Switch Networks, Inc.
-# See the file LICENSE.pyloxi which should have been included in the source distribution
-
-# Automatically generated by LOXI from template init.py
-# Do not modify
-
-import const
-import action
-import message
-import instruction
-import common
-from const import *
-from common import *
-from loxi import ProtocolError
diff --git a/python/ofagent/loxi/of11/action.py b/python/ofagent/loxi/of11/action.py
deleted file mode 100644
index 79fc2ff..0000000
--- a/python/ofagent/loxi/of11/action.py
+++ /dev/null
@@ -1,1675 +0,0 @@
-# Copyright 2017-present Open Networking Foundation
-#
-# 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.
-# Copyright (c) 2008 The Board of Trustees of The Leland Stanford Junior University
-# Copyright (c) 2011, 2012 Open Networking Foundation
-# Copyright (c) 2012, 2013 Big Switch Networks, Inc.
-# See the file LICENSE.pyloxi which should have been included in the source distribution
-
-# Automatically generated by LOXI from template module.py
-# Do not modify
-
-import struct
-import loxi
-import util
-import loxi.generic_util
-
-import sys
-ofp = sys.modules['loxi.of11']
-
-class action(loxi.OFObject):
-    subtypes = {}
-
-
-    def __init__(self, type=None):
-        if type != None:
-            self.type = type
-        else:
-            self.type = 0
-        return
-
-    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('\x00' * 4)
-        length = sum([len(x) for x in packed])
-        packed[1] = struct.pack("!H", length)
-        return ''.join(packed)
-
-    @staticmethod
-    def unpack(reader):
-        subtype, = reader.peek('!H', 0)
-        subclass = action.subtypes.get(subtype)
-        if subclass:
-            return subclass.unpack(reader)
-
-        obj = action()
-        obj.type = reader.read("!H")[0]
-        _len = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_len, 4)
-        reader.skip(4)
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): return False
-        if self.type != other.type: return False
-        return True
-
-    def pretty_print(self, q):
-        q.text("action {")
-        with q.group():
-            with q.indent(2):
-                q.breakable()
-            q.breakable()
-        q.text('}')
-
-
-class experimenter(action):
-    subtypes = {}
-
-    type = 65535
-
-    def __init__(self, experimenter=None, data=None):
-        if experimenter != None:
-            self.experimenter = experimenter
-        else:
-            self.experimenter = 0
-        if data != None:
-            self.data = data
-        else:
-            self.data = ''
-        return
-
-    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(self.data)
-        length = sum([len(x) for x in packed])
-        packed[1] = struct.pack("!H", length)
-        return ''.join(packed)
-
-    @staticmethod
-    def unpack(reader):
-        subtype, = reader.peek('!L', 4)
-        subclass = experimenter.subtypes.get(subtype)
-        if subclass:
-            return subclass.unpack(reader)
-
-        obj = experimenter()
-        _type = reader.read("!H")[0]
-        assert(_type == 65535)
-        _len = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_len, 4)
-        obj.experimenter = reader.read("!L")[0]
-        obj.data = str(reader.read_all())
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): return False
-        if self.experimenter != other.experimenter: return False
-        if self.data != other.data: return False
-        return True
-
-    def pretty_print(self, q):
-        q.text("experimenter {")
-        with q.group():
-            with q.indent(2):
-                q.breakable()
-                q.text("data = ");
-                q.pp(self.data)
-            q.breakable()
-        q.text('}')
-
-action.subtypes[65535] = experimenter
-
-class bsn(experimenter):
-    subtypes = {}
-
-    type = 65535
-    experimenter = 6035143
-
-    def __init__(self, subtype=None):
-        if subtype != None:
-            self.subtype = subtype
-        else:
-            self.subtype = 0
-        return
-
-    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('\x00' * 4)
-        length = sum([len(x) for x in packed])
-        packed[1] = struct.pack("!H", length)
-        return ''.join(packed)
-
-    @staticmethod
-    def unpack(reader):
-        subtype, = reader.peek('!L', 8)
-        subclass = bsn.subtypes.get(subtype)
-        if subclass:
-            return subclass.unpack(reader)
-
-        obj = bsn()
-        _type = reader.read("!H")[0]
-        assert(_type == 65535)
-        _len = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_len, 4)
-        _experimenter = reader.read("!L")[0]
-        assert(_experimenter == 6035143)
-        obj.subtype = reader.read("!L")[0]
-        reader.skip(4)
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): return False
-        if self.subtype != other.subtype: return False
-        return True
-
-    def pretty_print(self, q):
-        q.text("bsn {")
-        with q.group():
-            with q.indent(2):
-                q.breakable()
-            q.breakable()
-        q.text('}')
-
-experimenter.subtypes[6035143] = bsn
-
-class bsn_checksum(bsn):
-    type = 65535
-    experimenter = 6035143
-    subtype = 4
-
-    def __init__(self, checksum=None):
-        if checksum != None:
-            self.checksum = checksum
-        else:
-            self.checksum = 0
-        return
-
-    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(util.pack_checksum_128(self.checksum))
-        length = sum([len(x) for x in packed])
-        packed[1] = struct.pack("!H", length)
-        return ''.join(packed)
-
-    @staticmethod
-    def unpack(reader):
-        obj = bsn_checksum()
-        _type = reader.read("!H")[0]
-        assert(_type == 65535)
-        _len = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_len, 4)
-        _experimenter = reader.read("!L")[0]
-        assert(_experimenter == 6035143)
-        _subtype = reader.read("!L")[0]
-        assert(_subtype == 4)
-        obj.checksum = util.unpack_checksum_128(reader)
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): return False
-        if self.checksum != other.checksum: return False
-        return True
-
-    def pretty_print(self, q):
-        q.text("bsn_checksum {")
-        with q.group():
-            with q.indent(2):
-                q.breakable()
-                q.text("checksum = ");
-                q.pp(self.checksum)
-            q.breakable()
-        q.text('}')
-
-bsn.subtypes[4] = bsn_checksum
-
-class bsn_mirror(bsn):
-    type = 65535
-    experimenter = 6035143
-    subtype = 1
-
-    def __init__(self, dest_port=None, vlan_tag=None, copy_stage=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
-        return
-
-    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('\x00' * 3)
-        length = sum([len(x) for x in packed])
-        packed[1] = struct.pack("!H", length)
-        return ''.join(packed)
-
-    @staticmethod
-    def unpack(reader):
-        obj = bsn_mirror()
-        _type = reader.read("!H")[0]
-        assert(_type == 65535)
-        _len = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_len, 4)
-        _experimenter = reader.read("!L")[0]
-        assert(_experimenter == 6035143)
-        _subtype = reader.read("!L")[0]
-        assert(_subtype == 1)
-        obj.dest_port = reader.read("!L")[0]
-        obj.vlan_tag = reader.read("!L")[0]
-        obj.copy_stage = reader.read("!B")[0]
-        reader.skip(3)
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): 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
-        return True
-
-    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.breakable()
-        q.text('}')
-
-bsn.subtypes[1] = bsn_mirror
-
-class bsn_set_tunnel_dst(bsn):
-    type = 65535
-    experimenter = 6035143
-    subtype = 2
-
-    def __init__(self, dst=None):
-        if dst != None:
-            self.dst = dst
-        else:
-            self.dst = 0
-        return
-
-    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(reader):
-        obj = bsn_set_tunnel_dst()
-        _type = reader.read("!H")[0]
-        assert(_type == 65535)
-        _len = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_len, 4)
-        _experimenter = reader.read("!L")[0]
-        assert(_experimenter == 6035143)
-        _subtype = reader.read("!L")[0]
-        assert(_subtype == 2)
-        obj.dst = reader.read("!L")[0]
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): return False
-        if self.dst != other.dst: return False
-        return True
-
-    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('}')
-
-bsn.subtypes[2] = bsn_set_tunnel_dst
-
-class copy_ttl_in(action):
-    type = 12
-
-    def __init__(self):
-        return
-
-    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('\x00' * 4)
-        length = sum([len(x) for x in packed])
-        packed[1] = struct.pack("!H", length)
-        return ''.join(packed)
-
-    @staticmethod
-    def unpack(reader):
-        obj = copy_ttl_in()
-        _type = reader.read("!H")[0]
-        assert(_type == 12)
-        _len = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_len, 4)
-        reader.skip(4)
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): return False
-        return True
-
-    def pretty_print(self, q):
-        q.text("copy_ttl_in {")
-        with q.group():
-            with q.indent(2):
-                q.breakable()
-            q.breakable()
-        q.text('}')
-
-action.subtypes[12] = copy_ttl_in
-
-class copy_ttl_out(action):
-    type = 11
-
-    def __init__(self):
-        return
-
-    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('\x00' * 4)
-        length = sum([len(x) for x in packed])
-        packed[1] = struct.pack("!H", length)
-        return ''.join(packed)
-
-    @staticmethod
-    def unpack(reader):
-        obj = copy_ttl_out()
-        _type = reader.read("!H")[0]
-        assert(_type == 11)
-        _len = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_len, 4)
-        reader.skip(4)
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): return False
-        return True
-
-    def pretty_print(self, q):
-        q.text("copy_ttl_out {")
-        with q.group():
-            with q.indent(2):
-                q.breakable()
-            q.breakable()
-        q.text('}')
-
-action.subtypes[11] = copy_ttl_out
-
-class dec_mpls_ttl(action):
-    type = 16
-
-    def __init__(self):
-        return
-
-    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('\x00' * 4)
-        length = sum([len(x) for x in packed])
-        packed[1] = struct.pack("!H", length)
-        return ''.join(packed)
-
-    @staticmethod
-    def unpack(reader):
-        obj = dec_mpls_ttl()
-        _type = reader.read("!H")[0]
-        assert(_type == 16)
-        _len = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_len, 4)
-        reader.skip(4)
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): return False
-        return True
-
-    def pretty_print(self, q):
-        q.text("dec_mpls_ttl {")
-        with q.group():
-            with q.indent(2):
-                q.breakable()
-            q.breakable()
-        q.text('}')
-
-action.subtypes[16] = dec_mpls_ttl
-
-class dec_nw_ttl(action):
-    type = 24
-
-    def __init__(self):
-        return
-
-    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('\x00' * 4)
-        length = sum([len(x) for x in packed])
-        packed[1] = struct.pack("!H", length)
-        return ''.join(packed)
-
-    @staticmethod
-    def unpack(reader):
-        obj = dec_nw_ttl()
-        _type = reader.read("!H")[0]
-        assert(_type == 24)
-        _len = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_len, 4)
-        reader.skip(4)
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): return False
-        return True
-
-    def pretty_print(self, q):
-        q.text("dec_nw_ttl {")
-        with q.group():
-            with q.indent(2):
-                q.breakable()
-            q.breakable()
-        q.text('}')
-
-action.subtypes[24] = dec_nw_ttl
-
-class group(action):
-    type = 22
-
-    def __init__(self, group_id=None):
-        if group_id != None:
-            self.group_id = group_id
-        else:
-            self.group_id = 0
-        return
-
-    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.group_id))
-        length = sum([len(x) for x in packed])
-        packed[1] = struct.pack("!H", length)
-        return ''.join(packed)
-
-    @staticmethod
-    def unpack(reader):
-        obj = group()
-        _type = reader.read("!H")[0]
-        assert(_type == 22)
-        _len = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_len, 4)
-        obj.group_id = reader.read("!L")[0]
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): return False
-        if self.group_id != other.group_id: return False
-        return True
-
-    def pretty_print(self, q):
-        q.text("group {")
-        with q.group():
-            with q.indent(2):
-                q.breakable()
-                q.text("group_id = ");
-                q.text("%#x" % self.group_id)
-            q.breakable()
-        q.text('}')
-
-action.subtypes[22] = group
-
-class nicira(experimenter):
-    subtypes = {}
-
-    type = 65535
-    experimenter = 8992
-
-    def __init__(self, subtype=None):
-        if subtype != None:
-            self.subtype = subtype
-        else:
-            self.subtype = 0
-        return
-
-    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('\x00' * 2)
-        packed.append('\x00' * 4)
-        length = sum([len(x) for x in packed])
-        packed[1] = struct.pack("!H", length)
-        return ''.join(packed)
-
-    @staticmethod
-    def unpack(reader):
-        subtype, = reader.peek('!H', 8)
-        subclass = nicira.subtypes.get(subtype)
-        if subclass:
-            return subclass.unpack(reader)
-
-        obj = nicira()
-        _type = reader.read("!H")[0]
-        assert(_type == 65535)
-        _len = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_len, 4)
-        _experimenter = reader.read("!L")[0]
-        assert(_experimenter == 8992)
-        obj.subtype = reader.read("!H")[0]
-        reader.skip(2)
-        reader.skip(4)
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): return False
-        if self.subtype != other.subtype: return False
-        return True
-
-    def pretty_print(self, q):
-        q.text("nicira {")
-        with q.group():
-            with q.indent(2):
-                q.breakable()
-            q.breakable()
-        q.text('}')
-
-experimenter.subtypes[8992] = nicira
-
-class nicira_dec_ttl(nicira):
-    type = 65535
-    experimenter = 8992
-    subtype = 18
-
-    def __init__(self):
-        return
-
-    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('\x00' * 2)
-        packed.append('\x00' * 4)
-        length = sum([len(x) for x in packed])
-        packed[1] = struct.pack("!H", length)
-        return ''.join(packed)
-
-    @staticmethod
-    def unpack(reader):
-        obj = nicira_dec_ttl()
-        _type = reader.read("!H")[0]
-        assert(_type == 65535)
-        _len = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_len, 4)
-        _experimenter = reader.read("!L")[0]
-        assert(_experimenter == 8992)
-        _subtype = reader.read("!H")[0]
-        assert(_subtype == 18)
-        reader.skip(2)
-        reader.skip(4)
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): return False
-        return True
-
-    def pretty_print(self, q):
-        q.text("nicira_dec_ttl {")
-        with q.group():
-            with q.indent(2):
-                q.breakable()
-            q.breakable()
-        q.text('}')
-
-nicira.subtypes[18] = nicira_dec_ttl
-
-class output(action):
-    type = 0
-
-    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
-        return
-
-    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(util.pack_port_no(self.port))
-        packed.append(struct.pack("!H", self.max_len))
-        packed.append('\x00' * 6)
-        length = sum([len(x) for x in packed])
-        packed[1] = struct.pack("!H", length)
-        return ''.join(packed)
-
-    @staticmethod
-    def unpack(reader):
-        obj = output()
-        _type = reader.read("!H")[0]
-        assert(_type == 0)
-        _len = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_len, 4)
-        obj.port = util.unpack_port_no(reader)
-        obj.max_len = reader.read("!H")[0]
-        reader.skip(6)
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): return False
-        if self.port != other.port: return False
-        if self.max_len != other.max_len: return False
-        return True
-
-    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('}')
-
-action.subtypes[0] = output
-
-class pop_mpls(action):
-    type = 20
-
-    def __init__(self, ethertype=None):
-        if ethertype != None:
-            self.ethertype = ethertype
-        else:
-            self.ethertype = 0
-        return
-
-    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.ethertype))
-        packed.append('\x00' * 2)
-        length = sum([len(x) for x in packed])
-        packed[1] = struct.pack("!H", length)
-        return ''.join(packed)
-
-    @staticmethod
-    def unpack(reader):
-        obj = pop_mpls()
-        _type = reader.read("!H")[0]
-        assert(_type == 20)
-        _len = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_len, 4)
-        obj.ethertype = reader.read("!H")[0]
-        reader.skip(2)
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): return False
-        if self.ethertype != other.ethertype: return False
-        return True
-
-    def pretty_print(self, q):
-        q.text("pop_mpls {")
-        with q.group():
-            with q.indent(2):
-                q.breakable()
-                q.text("ethertype = ");
-                q.text("%#x" % self.ethertype)
-            q.breakable()
-        q.text('}')
-
-action.subtypes[20] = pop_mpls
-
-class pop_vlan(action):
-    type = 18
-
-    def __init__(self):
-        return
-
-    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('\x00' * 4)
-        length = sum([len(x) for x in packed])
-        packed[1] = struct.pack("!H", length)
-        return ''.join(packed)
-
-    @staticmethod
-    def unpack(reader):
-        obj = pop_vlan()
-        _type = reader.read("!H")[0]
-        assert(_type == 18)
-        _len = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_len, 4)
-        reader.skip(4)
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): return False
-        return True
-
-    def pretty_print(self, q):
-        q.text("pop_vlan {")
-        with q.group():
-            with q.indent(2):
-                q.breakable()
-            q.breakable()
-        q.text('}')
-
-action.subtypes[18] = pop_vlan
-
-class push_mpls(action):
-    type = 19
-
-    def __init__(self, ethertype=None):
-        if ethertype != None:
-            self.ethertype = ethertype
-        else:
-            self.ethertype = 0
-        return
-
-    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.ethertype))
-        packed.append('\x00' * 2)
-        length = sum([len(x) for x in packed])
-        packed[1] = struct.pack("!H", length)
-        return ''.join(packed)
-
-    @staticmethod
-    def unpack(reader):
-        obj = push_mpls()
-        _type = reader.read("!H")[0]
-        assert(_type == 19)
-        _len = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_len, 4)
-        obj.ethertype = reader.read("!H")[0]
-        reader.skip(2)
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): return False
-        if self.ethertype != other.ethertype: return False
-        return True
-
-    def pretty_print(self, q):
-        q.text("push_mpls {")
-        with q.group():
-            with q.indent(2):
-                q.breakable()
-                q.text("ethertype = ");
-                q.text("%#x" % self.ethertype)
-            q.breakable()
-        q.text('}')
-
-action.subtypes[19] = push_mpls
-
-class push_vlan(action):
-    type = 17
-
-    def __init__(self, ethertype=None):
-        if ethertype != None:
-            self.ethertype = ethertype
-        else:
-            self.ethertype = 0
-        return
-
-    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.ethertype))
-        packed.append('\x00' * 2)
-        length = sum([len(x) for x in packed])
-        packed[1] = struct.pack("!H", length)
-        return ''.join(packed)
-
-    @staticmethod
-    def unpack(reader):
-        obj = push_vlan()
-        _type = reader.read("!H")[0]
-        assert(_type == 17)
-        _len = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_len, 4)
-        obj.ethertype = reader.read("!H")[0]
-        reader.skip(2)
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): return False
-        if self.ethertype != other.ethertype: return False
-        return True
-
-    def pretty_print(self, q):
-        q.text("push_vlan {")
-        with q.group():
-            with q.indent(2):
-                q.breakable()
-                q.text("ethertype = ");
-                q.text("%#x" % self.ethertype)
-            q.breakable()
-        q.text('}')
-
-action.subtypes[17] = push_vlan
-
-class set_dl_dst(action):
-    type = 4
-
-    def __init__(self, dl_addr=None):
-        if dl_addr != None:
-            self.dl_addr = dl_addr
-        else:
-            self.dl_addr = [0,0,0,0,0,0]
-        return
-
-    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('\x00' * 6)
-        length = sum([len(x) for x in packed])
-        packed[1] = struct.pack("!H", length)
-        return ''.join(packed)
-
-    @staticmethod
-    def unpack(reader):
-        obj = set_dl_dst()
-        _type = reader.read("!H")[0]
-        assert(_type == 4)
-        _len = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_len, 4)
-        obj.dl_addr = list(reader.read('!6B'))
-        reader.skip(6)
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): return False
-        if self.dl_addr != other.dl_addr: return False
-        return True
-
-    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.breakable()
-        q.text('}')
-
-action.subtypes[4] = set_dl_dst
-
-class set_dl_src(action):
-    type = 3
-
-    def __init__(self, dl_addr=None):
-        if dl_addr != None:
-            self.dl_addr = dl_addr
-        else:
-            self.dl_addr = [0,0,0,0,0,0]
-        return
-
-    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('\x00' * 6)
-        length = sum([len(x) for x in packed])
-        packed[1] = struct.pack("!H", length)
-        return ''.join(packed)
-
-    @staticmethod
-    def unpack(reader):
-        obj = set_dl_src()
-        _type = reader.read("!H")[0]
-        assert(_type == 3)
-        _len = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_len, 4)
-        obj.dl_addr = list(reader.read('!6B'))
-        reader.skip(6)
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): return False
-        if self.dl_addr != other.dl_addr: return False
-        return True
-
-    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.breakable()
-        q.text('}')
-
-action.subtypes[3] = set_dl_src
-
-class set_mpls_label(action):
-    type = 13
-
-    def __init__(self, mpls_label=None):
-        if mpls_label != None:
-            self.mpls_label = mpls_label
-        else:
-            self.mpls_label = 0
-        return
-
-    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.mpls_label))
-        length = sum([len(x) for x in packed])
-        packed[1] = struct.pack("!H", length)
-        return ''.join(packed)
-
-    @staticmethod
-    def unpack(reader):
-        obj = set_mpls_label()
-        _type = reader.read("!H")[0]
-        assert(_type == 13)
-        _len = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_len, 4)
-        obj.mpls_label = reader.read("!L")[0]
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): return False
-        if self.mpls_label != other.mpls_label: return False
-        return True
-
-    def pretty_print(self, q):
-        q.text("set_mpls_label {")
-        with q.group():
-            with q.indent(2):
-                q.breakable()
-                q.text("mpls_label = ");
-                q.text("%#x" % self.mpls_label)
-            q.breakable()
-        q.text('}')
-
-action.subtypes[13] = set_mpls_label
-
-class set_mpls_tc(action):
-    type = 14
-
-    def __init__(self, mpls_tc=None):
-        if mpls_tc != None:
-            self.mpls_tc = mpls_tc
-        else:
-            self.mpls_tc = 0
-        return
-
-    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.mpls_tc))
-        packed.append('\x00' * 3)
-        length = sum([len(x) for x in packed])
-        packed[1] = struct.pack("!H", length)
-        return ''.join(packed)
-
-    @staticmethod
-    def unpack(reader):
-        obj = set_mpls_tc()
-        _type = reader.read("!H")[0]
-        assert(_type == 14)
-        _len = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_len, 4)
-        obj.mpls_tc = reader.read("!B")[0]
-        reader.skip(3)
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): return False
-        if self.mpls_tc != other.mpls_tc: return False
-        return True
-
-    def pretty_print(self, q):
-        q.text("set_mpls_tc {")
-        with q.group():
-            with q.indent(2):
-                q.breakable()
-                q.text("mpls_tc = ");
-                q.text("%#x" % self.mpls_tc)
-            q.breakable()
-        q.text('}')
-
-action.subtypes[14] = set_mpls_tc
-
-class set_mpls_ttl(action):
-    type = 15
-
-    def __init__(self, mpls_ttl=None):
-        if mpls_ttl != None:
-            self.mpls_ttl = mpls_ttl
-        else:
-            self.mpls_ttl = 0
-        return
-
-    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.mpls_ttl))
-        packed.append('\x00' * 3)
-        length = sum([len(x) for x in packed])
-        packed[1] = struct.pack("!H", length)
-        return ''.join(packed)
-
-    @staticmethod
-    def unpack(reader):
-        obj = set_mpls_ttl()
-        _type = reader.read("!H")[0]
-        assert(_type == 15)
-        _len = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_len, 4)
-        obj.mpls_ttl = reader.read("!B")[0]
-        reader.skip(3)
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): return False
-        if self.mpls_ttl != other.mpls_ttl: return False
-        return True
-
-    def pretty_print(self, q):
-        q.text("set_mpls_ttl {")
-        with q.group():
-            with q.indent(2):
-                q.breakable()
-                q.text("mpls_ttl = ");
-                q.text("%#x" % self.mpls_ttl)
-            q.breakable()
-        q.text('}')
-
-action.subtypes[15] = set_mpls_ttl
-
-class set_nw_dst(action):
-    type = 6
-
-    def __init__(self, nw_addr=None):
-        if nw_addr != None:
-            self.nw_addr = nw_addr
-        else:
-            self.nw_addr = 0
-        return
-
-    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(reader):
-        obj = set_nw_dst()
-        _type = reader.read("!H")[0]
-        assert(_type == 6)
-        _len = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_len, 4)
-        obj.nw_addr = reader.read("!L")[0]
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): return False
-        if self.nw_addr != other.nw_addr: return False
-        return True
-
-    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('}')
-
-action.subtypes[6] = set_nw_dst
-
-class set_nw_ecn(action):
-    type = 8
-
-    def __init__(self, nw_ecn=None):
-        if nw_ecn != None:
-            self.nw_ecn = nw_ecn
-        else:
-            self.nw_ecn = 0
-        return
-
-    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_ecn))
-        packed.append('\x00' * 3)
-        length = sum([len(x) for x in packed])
-        packed[1] = struct.pack("!H", length)
-        return ''.join(packed)
-
-    @staticmethod
-    def unpack(reader):
-        obj = set_nw_ecn()
-        _type = reader.read("!H")[0]
-        assert(_type == 8)
-        _len = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_len, 4)
-        obj.nw_ecn = reader.read("!B")[0]
-        reader.skip(3)
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): return False
-        if self.nw_ecn != other.nw_ecn: return False
-        return True
-
-    def pretty_print(self, q):
-        q.text("set_nw_ecn {")
-        with q.group():
-            with q.indent(2):
-                q.breakable()
-                q.text("nw_ecn = ");
-                q.text("%#x" % self.nw_ecn)
-            q.breakable()
-        q.text('}')
-
-action.subtypes[8] = set_nw_ecn
-
-class set_nw_src(action):
-    type = 5
-
-    def __init__(self, nw_addr=None):
-        if nw_addr != None:
-            self.nw_addr = nw_addr
-        else:
-            self.nw_addr = 0
-        return
-
-    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(reader):
-        obj = set_nw_src()
-        _type = reader.read("!H")[0]
-        assert(_type == 5)
-        _len = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_len, 4)
-        obj.nw_addr = reader.read("!L")[0]
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): return False
-        if self.nw_addr != other.nw_addr: return False
-        return True
-
-    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('}')
-
-action.subtypes[5] = set_nw_src
-
-class set_nw_tos(action):
-    type = 7
-
-    def __init__(self, nw_tos=None):
-        if nw_tos != None:
-            self.nw_tos = nw_tos
-        else:
-            self.nw_tos = 0
-        return
-
-    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('\x00' * 3)
-        length = sum([len(x) for x in packed])
-        packed[1] = struct.pack("!H", length)
-        return ''.join(packed)
-
-    @staticmethod
-    def unpack(reader):
-        obj = set_nw_tos()
-        _type = reader.read("!H")[0]
-        assert(_type == 7)
-        _len = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_len, 4)
-        obj.nw_tos = reader.read("!B")[0]
-        reader.skip(3)
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): return False
-        if self.nw_tos != other.nw_tos: return False
-        return True
-
-    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.breakable()
-        q.text('}')
-
-action.subtypes[7] = set_nw_tos
-
-class set_nw_ttl(action):
-    type = 23
-
-    def __init__(self, nw_ttl=None):
-        if nw_ttl != None:
-            self.nw_ttl = nw_ttl
-        else:
-            self.nw_ttl = 0
-        return
-
-    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_ttl))
-        packed.append('\x00' * 3)
-        length = sum([len(x) for x in packed])
-        packed[1] = struct.pack("!H", length)
-        return ''.join(packed)
-
-    @staticmethod
-    def unpack(reader):
-        obj = set_nw_ttl()
-        _type = reader.read("!H")[0]
-        assert(_type == 23)
-        _len = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_len, 4)
-        obj.nw_ttl = reader.read("!B")[0]
-        reader.skip(3)
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): return False
-        if self.nw_ttl != other.nw_ttl: return False
-        return True
-
-    def pretty_print(self, q):
-        q.text("set_nw_ttl {")
-        with q.group():
-            with q.indent(2):
-                q.breakable()
-                q.text("nw_ttl = ");
-                q.text("%#x" % self.nw_ttl)
-            q.breakable()
-        q.text('}')
-
-action.subtypes[23] = set_nw_ttl
-
-class set_queue(action):
-    type = 21
-
-    def __init__(self, queue_id=None):
-        if queue_id != None:
-            self.queue_id = queue_id
-        else:
-            self.queue_id = 0
-        return
-
-    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.queue_id))
-        length = sum([len(x) for x in packed])
-        packed[1] = struct.pack("!H", length)
-        return ''.join(packed)
-
-    @staticmethod
-    def unpack(reader):
-        obj = set_queue()
-        _type = reader.read("!H")[0]
-        assert(_type == 21)
-        _len = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_len, 4)
-        obj.queue_id = reader.read("!L")[0]
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): return False
-        if self.queue_id != other.queue_id: return False
-        return True
-
-    def pretty_print(self, q):
-        q.text("set_queue {")
-        with q.group():
-            with q.indent(2):
-                q.breakable()
-                q.text("queue_id = ");
-                q.text("%#x" % self.queue_id)
-            q.breakable()
-        q.text('}')
-
-action.subtypes[21] = set_queue
-
-class set_tp_dst(action):
-    type = 10
-
-    def __init__(self, tp_port=None):
-        if tp_port != None:
-            self.tp_port = tp_port
-        else:
-            self.tp_port = 0
-        return
-
-    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('\x00' * 2)
-        length = sum([len(x) for x in packed])
-        packed[1] = struct.pack("!H", length)
-        return ''.join(packed)
-
-    @staticmethod
-    def unpack(reader):
-        obj = set_tp_dst()
-        _type = reader.read("!H")[0]
-        assert(_type == 10)
-        _len = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_len, 4)
-        obj.tp_port = reader.read("!H")[0]
-        reader.skip(2)
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): return False
-        if self.tp_port != other.tp_port: return False
-        return True
-
-    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.breakable()
-        q.text('}')
-
-action.subtypes[10] = set_tp_dst
-
-class set_tp_src(action):
-    type = 9
-
-    def __init__(self, tp_port=None):
-        if tp_port != None:
-            self.tp_port = tp_port
-        else:
-            self.tp_port = 0
-        return
-
-    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('\x00' * 2)
-        length = sum([len(x) for x in packed])
-        packed[1] = struct.pack("!H", length)
-        return ''.join(packed)
-
-    @staticmethod
-    def unpack(reader):
-        obj = set_tp_src()
-        _type = reader.read("!H")[0]
-        assert(_type == 9)
-        _len = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_len, 4)
-        obj.tp_port = reader.read("!H")[0]
-        reader.skip(2)
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): return False
-        if self.tp_port != other.tp_port: return False
-        return True
-
-    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.breakable()
-        q.text('}')
-
-action.subtypes[9] = set_tp_src
-
-class set_vlan_pcp(action):
-    type = 2
-
-    def __init__(self, vlan_pcp=None):
-        if vlan_pcp != None:
-            self.vlan_pcp = vlan_pcp
-        else:
-            self.vlan_pcp = 0
-        return
-
-    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('\x00' * 3)
-        length = sum([len(x) for x in packed])
-        packed[1] = struct.pack("!H", length)
-        return ''.join(packed)
-
-    @staticmethod
-    def unpack(reader):
-        obj = set_vlan_pcp()
-        _type = reader.read("!H")[0]
-        assert(_type == 2)
-        _len = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_len, 4)
-        obj.vlan_pcp = reader.read("!B")[0]
-        reader.skip(3)
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): return False
-        if self.vlan_pcp != other.vlan_pcp: return False
-        return True
-
-    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.breakable()
-        q.text('}')
-
-action.subtypes[2] = set_vlan_pcp
-
-class set_vlan_vid(action):
-    type = 1
-
-    def __init__(self, vlan_vid=None):
-        if vlan_vid != None:
-            self.vlan_vid = vlan_vid
-        else:
-            self.vlan_vid = 0
-        return
-
-    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('\x00' * 2)
-        length = sum([len(x) for x in packed])
-        packed[1] = struct.pack("!H", length)
-        return ''.join(packed)
-
-    @staticmethod
-    def unpack(reader):
-        obj = set_vlan_vid()
-        _type = reader.read("!H")[0]
-        assert(_type == 1)
-        _len = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_len, 4)
-        obj.vlan_vid = reader.read("!H")[0]
-        reader.skip(2)
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): return False
-        if self.vlan_vid != other.vlan_vid: return False
-        return True
-
-    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.breakable()
-        q.text('}')
-
-action.subtypes[1] = set_vlan_vid
-
-
diff --git a/python/ofagent/loxi/of11/common.py b/python/ofagent/loxi/of11/common.py
deleted file mode 100644
index dadd6bc..0000000
--- a/python/ofagent/loxi/of11/common.py
+++ /dev/null
@@ -1,1744 +0,0 @@
-# Copyright 2017-present Open Networking Foundation
-#
-# 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.
-# Copyright (c) 2008 The Board of Trustees of The Leland Stanford Junior University
-# Copyright (c) 2011, 2012 Open Networking Foundation
-# Copyright (c) 2012, 2013 Big Switch Networks, Inc.
-# See the file LICENSE.pyloxi which should have been included in the source distribution
-
-# Automatically generated by LOXI from template module.py
-# Do not modify
-
-import struct
-import loxi
-import util
-import loxi.generic_util
-
-import sys
-ofp = sys.modules['loxi.of11']
-
-class bsn_interface(loxi.OFObject):
-
-    def __init__(self, hw_addr=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 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
-        return
-
-    def pack(self):
-        packed = []
-        packed.append(struct.pack("!6B", *self.hw_addr))
-        packed.append('\x00' * 2)
-        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(reader):
-        obj = bsn_interface()
-        obj.hw_addr = list(reader.read('!6B'))
-        reader.skip(2)
-        obj.name = reader.read("!16s")[0].rstrip("\x00")
-        obj.ipv4_addr = reader.read("!L")[0]
-        obj.ipv4_netmask = reader.read("!L")[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.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 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("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 bsn_vport(loxi.OFObject):
-    subtypes = {}
-
-
-    def __init__(self, type=None):
-        if type != None:
-            self.type = type
-        else:
-            self.type = 0
-        return
-
-    def pack(self):
-        packed = []
-        packed.append(struct.pack("!H", self.type))
-        packed.append(struct.pack("!H", 0)) # placeholder for length at index 1
-        length = sum([len(x) for x in packed])
-        packed[1] = struct.pack("!H", length)
-        return ''.join(packed)
-
-    @staticmethod
-    def unpack(reader):
-        subtype, = reader.peek('!H', 0)
-        subclass = bsn_vport.subtypes.get(subtype)
-        if subclass:
-            return subclass.unpack(reader)
-
-        obj = bsn_vport()
-        obj.type = reader.read("!H")[0]
-        _length = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_length, 4)
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): return False
-        if self.type != other.type: return False
-        return True
-
-    def pretty_print(self, q):
-        q.text("bsn_vport {")
-        with q.group():
-            with q.indent(2):
-                q.breakable()
-            q.breakable()
-        q.text('}')
-
-
-class bsn_vport_l2gre(bsn_vport):
-    type = 1
-
-    def __init__(self, flags=None, port_no=None, loopback_port_no=None, local_mac=None, nh_mac=None, src_ip=None, dst_ip=None, dscp=None, ttl=None, vpn=None, rate_limit=None, if_name=None):
-        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 loopback_port_no != None:
-            self.loopback_port_no = loopback_port_no
-        else:
-            self.loopback_port_no = 0
-        if local_mac != None:
-            self.local_mac = local_mac
-        else:
-            self.local_mac = [0,0,0,0,0,0]
-        if nh_mac != None:
-            self.nh_mac = nh_mac
-        else:
-            self.nh_mac = [0,0,0,0,0,0]
-        if src_ip != None:
-            self.src_ip = src_ip
-        else:
-            self.src_ip = 0
-        if dst_ip != None:
-            self.dst_ip = dst_ip
-        else:
-            self.dst_ip = 0
-        if dscp != None:
-            self.dscp = dscp
-        else:
-            self.dscp = 0
-        if ttl != None:
-            self.ttl = ttl
-        else:
-            self.ttl = 0
-        if vpn != None:
-            self.vpn = vpn
-        else:
-            self.vpn = 0
-        if rate_limit != None:
-            self.rate_limit = rate_limit
-        else:
-            self.rate_limit = 0
-        if if_name != None:
-            self.if_name = if_name
-        else:
-            self.if_name = ""
-        return
-
-    def pack(self):
-        packed = []
-        packed.append(struct.pack("!H", self.type))
-        packed.append(struct.pack("!H", 0)) # placeholder for length at index 1
-        packed.append(struct.pack("!L", self.flags))
-        packed.append(util.pack_port_no(self.port_no))
-        packed.append(util.pack_port_no(self.loopback_port_no))
-        packed.append(struct.pack("!6B", *self.local_mac))
-        packed.append(struct.pack("!6B", *self.nh_mac))
-        packed.append(struct.pack("!L", self.src_ip))
-        packed.append(struct.pack("!L", self.dst_ip))
-        packed.append(struct.pack("!B", self.dscp))
-        packed.append(struct.pack("!B", self.ttl))
-        packed.append('\x00' * 2)
-        packed.append(struct.pack("!L", self.vpn))
-        packed.append(struct.pack("!L", self.rate_limit))
-        packed.append(struct.pack("!16s", self.if_name))
-        length = sum([len(x) for x in packed])
-        packed[1] = struct.pack("!H", length)
-        return ''.join(packed)
-
-    @staticmethod
-    def unpack(reader):
-        obj = bsn_vport_l2gre()
-        _type = reader.read("!H")[0]
-        assert(_type == 1)
-        _length = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_length, 4)
-        obj.flags = reader.read("!L")[0]
-        obj.port_no = util.unpack_port_no(reader)
-        obj.loopback_port_no = util.unpack_port_no(reader)
-        obj.local_mac = list(reader.read('!6B'))
-        obj.nh_mac = list(reader.read('!6B'))
-        obj.src_ip = reader.read("!L")[0]
-        obj.dst_ip = reader.read("!L")[0]
-        obj.dscp = reader.read("!B")[0]
-        obj.ttl = reader.read("!B")[0]
-        reader.skip(2)
-        obj.vpn = reader.read("!L")[0]
-        obj.rate_limit = reader.read("!L")[0]
-        obj.if_name = reader.read("!16s")[0].rstrip("\x00")
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): return False
-        if self.flags != other.flags: return False
-        if self.port_no != other.port_no: return False
-        if self.loopback_port_no != other.loopback_port_no: return False
-        if self.local_mac != other.local_mac: return False
-        if self.nh_mac != other.nh_mac: return False
-        if self.src_ip != other.src_ip: return False
-        if self.dst_ip != other.dst_ip: return False
-        if self.dscp != other.dscp: return False
-        if self.ttl != other.ttl: return False
-        if self.vpn != other.vpn: return False
-        if self.rate_limit != other.rate_limit: return False
-        if self.if_name != other.if_name: return False
-        return True
-
-    def pretty_print(self, q):
-        q.text("bsn_vport_l2gre {")
-        with q.group():
-            with q.indent(2):
-                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("loopback_port_no = ");
-                q.text(util.pretty_port(self.loopback_port_no))
-                q.text(","); q.breakable()
-                q.text("local_mac = ");
-                q.text(util.pretty_mac(self.local_mac))
-                q.text(","); q.breakable()
-                q.text("nh_mac = ");
-                q.text(util.pretty_mac(self.nh_mac))
-                q.text(","); q.breakable()
-                q.text("src_ip = ");
-                q.text(util.pretty_ipv4(self.src_ip))
-                q.text(","); q.breakable()
-                q.text("dst_ip = ");
-                q.text(util.pretty_ipv4(self.dst_ip))
-                q.text(","); q.breakable()
-                q.text("dscp = ");
-                q.text("%#x" % self.dscp)
-                q.text(","); q.breakable()
-                q.text("ttl = ");
-                q.text("%#x" % self.ttl)
-                q.text(","); q.breakable()
-                q.text("vpn = ");
-                q.text("%#x" % self.vpn)
-                q.text(","); q.breakable()
-                q.text("rate_limit = ");
-                q.text("%#x" % self.rate_limit)
-                q.text(","); q.breakable()
-                q.text("if_name = ");
-                q.pp(self.if_name)
-            q.breakable()
-        q.text('}')
-
-bsn_vport.subtypes[1] = bsn_vport_l2gre
-
-class bsn_vport_q_in_q(bsn_vport):
-    type = 0
-
-    def __init__(self, port_no=None, ingress_tpid=None, ingress_vlan_id=None, egress_tpid=None, egress_vlan_id=None, if_name=None):
-        if port_no != None:
-            self.port_no = port_no
-        else:
-            self.port_no = 0
-        if ingress_tpid != None:
-            self.ingress_tpid = ingress_tpid
-        else:
-            self.ingress_tpid = 0
-        if ingress_vlan_id != None:
-            self.ingress_vlan_id = ingress_vlan_id
-        else:
-            self.ingress_vlan_id = 0
-        if egress_tpid != None:
-            self.egress_tpid = egress_tpid
-        else:
-            self.egress_tpid = 0
-        if egress_vlan_id != None:
-            self.egress_vlan_id = egress_vlan_id
-        else:
-            self.egress_vlan_id = 0
-        if if_name != None:
-            self.if_name = if_name
-        else:
-            self.if_name = ""
-        return
-
-    def pack(self):
-        packed = []
-        packed.append(struct.pack("!H", self.type))
-        packed.append(struct.pack("!H", 0)) # placeholder for length at index 1
-        packed.append(struct.pack("!L", self.port_no))
-        packed.append(struct.pack("!H", self.ingress_tpid))
-        packed.append(struct.pack("!H", self.ingress_vlan_id))
-        packed.append(struct.pack("!H", self.egress_tpid))
-        packed.append(struct.pack("!H", self.egress_vlan_id))
-        packed.append(struct.pack("!16s", self.if_name))
-        length = sum([len(x) for x in packed])
-        packed[1] = struct.pack("!H", length)
-        return ''.join(packed)
-
-    @staticmethod
-    def unpack(reader):
-        obj = bsn_vport_q_in_q()
-        _type = reader.read("!H")[0]
-        assert(_type == 0)
-        _length = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_length, 4)
-        obj.port_no = reader.read("!L")[0]
-        obj.ingress_tpid = reader.read("!H")[0]
-        obj.ingress_vlan_id = reader.read("!H")[0]
-        obj.egress_tpid = reader.read("!H")[0]
-        obj.egress_vlan_id = reader.read("!H")[0]
-        obj.if_name = reader.read("!16s")[0].rstrip("\x00")
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): return False
-        if self.port_no != other.port_no: return False
-        if self.ingress_tpid != other.ingress_tpid: return False
-        if self.ingress_vlan_id != other.ingress_vlan_id: return False
-        if self.egress_tpid != other.egress_tpid: return False
-        if self.egress_vlan_id != other.egress_vlan_id: return False
-        if self.if_name != other.if_name: return False
-        return True
-
-    def pretty_print(self, q):
-        q.text("bsn_vport_q_in_q {")
-        with q.group():
-            with q.indent(2):
-                q.breakable()
-                q.text("port_no = ");
-                q.text("%#x" % self.port_no)
-                q.text(","); q.breakable()
-                q.text("ingress_tpid = ");
-                q.text("%#x" % self.ingress_tpid)
-                q.text(","); q.breakable()
-                q.text("ingress_vlan_id = ");
-                q.text("%#x" % self.ingress_vlan_id)
-                q.text(","); q.breakable()
-                q.text("egress_tpid = ");
-                q.text("%#x" % self.egress_tpid)
-                q.text(","); q.breakable()
-                q.text("egress_vlan_id = ");
-                q.text("%#x" % self.egress_vlan_id)
-                q.text(","); q.breakable()
-                q.text("if_name = ");
-                q.pp(self.if_name)
-            q.breakable()
-        q.text('}')
-
-bsn_vport.subtypes[0] = bsn_vport_q_in_q
-
-class bucket(loxi.OFObject):
-
-    def __init__(self, weight=None, watch_port=None, watch_group=None, actions=None):
-        if weight != None:
-            self.weight = weight
-        else:
-            self.weight = 0
-        if watch_port != None:
-            self.watch_port = watch_port
-        else:
-            self.watch_port = 0
-        if watch_group != None:
-            self.watch_group = watch_group
-        else:
-            self.watch_group = 0
-        if actions != None:
-            self.actions = actions
-        else:
-            self.actions = []
-        return
-
-    def pack(self):
-        packed = []
-        packed.append(struct.pack("!H", 0)) # placeholder for len at index 0
-        packed.append(struct.pack("!H", self.weight))
-        packed.append(util.pack_port_no(self.watch_port))
-        packed.append(struct.pack("!L", self.watch_group))
-        packed.append('\x00' * 4)
-        packed.append(loxi.generic_util.pack_list(self.actions))
-        length = sum([len(x) for x in packed])
-        packed[0] = struct.pack("!H", length)
-        return ''.join(packed)
-
-    @staticmethod
-    def unpack(reader):
-        obj = bucket()
-        _len = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_len, 2)
-        obj.weight = reader.read("!H")[0]
-        obj.watch_port = util.unpack_port_no(reader)
-        obj.watch_group = reader.read("!L")[0]
-        reader.skip(4)
-        obj.actions = loxi.generic_util.unpack_list(reader, ofp.action.action.unpack)
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): return False
-        if self.weight != other.weight: return False
-        if self.watch_port != other.watch_port: return False
-        if self.watch_group != other.watch_group: return False
-        if self.actions != other.actions: return False
-        return True
-
-    def pretty_print(self, q):
-        q.text("bucket {")
-        with q.group():
-            with q.indent(2):
-                q.breakable()
-                q.text("weight = ");
-                q.text("%#x" % self.weight)
-                q.text(","); q.breakable()
-                q.text("watch_port = ");
-                q.text(util.pretty_port(self.watch_port))
-                q.text(","); q.breakable()
-                q.text("watch_group = ");
-                q.text("%#x" % self.watch_group)
-                q.text(","); q.breakable()
-                q.text("actions = ");
-                q.pp(self.actions)
-            q.breakable()
-        q.text('}')
-
-
-class bucket_counter(loxi.OFObject):
-
-    def __init__(self, packet_count=None, byte_count=None):
-        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
-        return
-
-    def pack(self):
-        packed = []
-        packed.append(struct.pack("!Q", self.packet_count))
-        packed.append(struct.pack("!Q", self.byte_count))
-        return ''.join(packed)
-
-    @staticmethod
-    def unpack(reader):
-        obj = bucket_counter()
-        obj.packet_count = reader.read("!Q")[0]
-        obj.byte_count = reader.read("!Q")[0]
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): return False
-        if self.packet_count != other.packet_count: return False
-        if self.byte_count != other.byte_count: return False
-        return True
-
-    def pretty_print(self, q):
-        q.text("bucket_counter {")
-        with q.group():
-            with q.indent(2):
-                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_entry(loxi.OFObject):
-
-    def __init__(self, table_id=None, duration_sec=None, duration_nsec=None, priority=None, idle_timeout=None, hard_timeout=None, cookie=None, packet_count=None, byte_count=None, match=None, instructions=None):
-        if table_id != None:
-            self.table_id = table_id
-        else:
-            self.table_id = 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 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 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 match != None:
-            self.match = match
-        else:
-            self.match = ofp.match()
-        if instructions != None:
-            self.instructions = instructions
-        else:
-            self.instructions = []
-        return
-
-    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('\x00' * 1)
-        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('\x00' * 6)
-        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(self.match.pack())
-        packed.append(loxi.generic_util.pack_list(self.instructions))
-        length = sum([len(x) for x in packed])
-        packed[0] = struct.pack("!H", length)
-        return ''.join(packed)
-
-    @staticmethod
-    def unpack(reader):
-        obj = flow_stats_entry()
-        _length = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_length, 2)
-        obj.table_id = reader.read("!B")[0]
-        reader.skip(1)
-        obj.duration_sec = reader.read("!L")[0]
-        obj.duration_nsec = reader.read("!L")[0]
-        obj.priority = reader.read("!H")[0]
-        obj.idle_timeout = reader.read("!H")[0]
-        obj.hard_timeout = reader.read("!H")[0]
-        reader.skip(6)
-        obj.cookie = reader.read("!Q")[0]
-        obj.packet_count = reader.read("!Q")[0]
-        obj.byte_count = reader.read("!Q")[0]
-        obj.match = ofp.match.unpack(reader)
-        obj.instructions = loxi.generic_util.unpack_list(reader, ofp.instruction.instruction.unpack)
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): return False
-        if self.table_id != other.table_id: 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.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.match != other.match: return False
-        if self.instructions != other.instructions: return False
-        return True
-
-    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("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("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("match = ");
-                q.pp(self.match)
-                q.text(","); q.breakable()
-                q.text("instructions = ");
-                q.pp(self.instructions)
-            q.breakable()
-        q.text('}')
-
-
-class group_desc_stats_entry(loxi.OFObject):
-
-    def __init__(self, group_type=None, group_id=None, buckets=None):
-        if group_type != None:
-            self.group_type = group_type
-        else:
-            self.group_type = 0
-        if group_id != None:
-            self.group_id = group_id
-        else:
-            self.group_id = 0
-        if buckets != None:
-            self.buckets = buckets
-        else:
-            self.buckets = []
-        return
-
-    def pack(self):
-        packed = []
-        packed.append(struct.pack("!H", 0)) # placeholder for length at index 0
-        packed.append(struct.pack("!B", self.group_type))
-        packed.append('\x00' * 1)
-        packed.append(struct.pack("!L", self.group_id))
-        packed.append(loxi.generic_util.pack_list(self.buckets))
-        length = sum([len(x) for x in packed])
-        packed[0] = struct.pack("!H", length)
-        return ''.join(packed)
-
-    @staticmethod
-    def unpack(reader):
-        obj = group_desc_stats_entry()
-        _length = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_length, 2)
-        obj.group_type = reader.read("!B")[0]
-        reader.skip(1)
-        obj.group_id = reader.read("!L")[0]
-        obj.buckets = loxi.generic_util.unpack_list(reader, ofp.common.bucket.unpack)
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): return False
-        if self.group_type != other.group_type: return False
-        if self.group_id != other.group_id: return False
-        if self.buckets != other.buckets: return False
-        return True
-
-    def pretty_print(self, q):
-        q.text("group_desc_stats_entry {")
-        with q.group():
-            with q.indent(2):
-                q.breakable()
-                q.text("group_type = ");
-                q.text("%#x" % self.group_type)
-                q.text(","); q.breakable()
-                q.text("group_id = ");
-                q.text("%#x" % self.group_id)
-                q.text(","); q.breakable()
-                q.text("buckets = ");
-                q.pp(self.buckets)
-            q.breakable()
-        q.text('}')
-
-
-class group_stats_entry(loxi.OFObject):
-
-    def __init__(self, group_id=None, ref_count=None, packet_count=None, byte_count=None, bucket_stats=None):
-        if group_id != None:
-            self.group_id = group_id
-        else:
-            self.group_id = 0
-        if ref_count != None:
-            self.ref_count = ref_count
-        else:
-            self.ref_count = 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 bucket_stats != None:
-            self.bucket_stats = bucket_stats
-        else:
-            self.bucket_stats = []
-        return
-
-    def pack(self):
-        packed = []
-        packed.append(struct.pack("!H", 0)) # placeholder for length at index 0
-        packed.append('\x00' * 2)
-        packed.append(struct.pack("!L", self.group_id))
-        packed.append(struct.pack("!L", self.ref_count))
-        packed.append('\x00' * 4)
-        packed.append(struct.pack("!Q", self.packet_count))
-        packed.append(struct.pack("!Q", self.byte_count))
-        packed.append(loxi.generic_util.pack_list(self.bucket_stats))
-        length = sum([len(x) for x in packed])
-        packed[0] = struct.pack("!H", length)
-        return ''.join(packed)
-
-    @staticmethod
-    def unpack(reader):
-        obj = group_stats_entry()
-        _length = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_length, 2)
-        reader.skip(2)
-        obj.group_id = reader.read("!L")[0]
-        obj.ref_count = reader.read("!L")[0]
-        reader.skip(4)
-        obj.packet_count = reader.read("!Q")[0]
-        obj.byte_count = reader.read("!Q")[0]
-        obj.bucket_stats = loxi.generic_util.unpack_list(reader, ofp.common.bucket_counter.unpack)
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): return False
-        if self.group_id != other.group_id: return False
-        if self.ref_count != other.ref_count: return False
-        if self.packet_count != other.packet_count: return False
-        if self.byte_count != other.byte_count: return False
-        if self.bucket_stats != other.bucket_stats: return False
-        return True
-
-    def pretty_print(self, q):
-        q.text("group_stats_entry {")
-        with q.group():
-            with q.indent(2):
-                q.breakable()
-                q.text("group_id = ");
-                q.text("%#x" % self.group_id)
-                q.text(","); q.breakable()
-                q.text("ref_count = ");
-                q.text("%#x" % self.ref_count)
-                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("bucket_stats = ");
-                q.pp(self.bucket_stats)
-            q.breakable()
-        q.text('}')
-
-
-class match_v2(loxi.OFObject):
-    type = 0
-
-    def __init__(self, in_port=None, wildcards=None, eth_src=None, eth_src_mask=None, eth_dst=None, eth_dst_mask=None, vlan_vid=None, vlan_pcp=None, eth_type=None, ip_dscp=None, ip_proto=None, ipv4_src=None, ipv4_src_mask=None, ipv4_dst=None, ipv4_dst_mask=None, tcp_src=None, tcp_dst=None, mpls_label=None, mpls_tc=None, metadata=None, metadata_mask=None):
-        if in_port != None:
-            self.in_port = in_port
-        else:
-            self.in_port = 0
-        if wildcards != None:
-            self.wildcards = wildcards
-        else:
-            self.wildcards = util.init_wc_bmap()
-        if eth_src != None:
-            self.eth_src = eth_src
-        else:
-            self.eth_src = [0,0,0,0,0,0]
-        if eth_src_mask != None:
-            self.eth_src_mask = eth_src_mask
-        else:
-            self.eth_src_mask = [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 eth_dst_mask != None:
-            self.eth_dst_mask = eth_dst_mask
-        else:
-            self.eth_dst_mask = [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 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 ipv4_src != None:
-            self.ipv4_src = ipv4_src
-        else:
-            self.ipv4_src = 0
-        if ipv4_src_mask != None:
-            self.ipv4_src_mask = ipv4_src_mask
-        else:
-            self.ipv4_src_mask = 0
-        if ipv4_dst != None:
-            self.ipv4_dst = ipv4_dst
-        else:
-            self.ipv4_dst = 0
-        if ipv4_dst_mask != None:
-            self.ipv4_dst_mask = ipv4_dst_mask
-        else:
-            self.ipv4_dst_mask = 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
-        if mpls_label != None:
-            self.mpls_label = mpls_label
-        else:
-            self.mpls_label = 0
-        if mpls_tc != None:
-            self.mpls_tc = mpls_tc
-        else:
-            self.mpls_tc = 0
-        if metadata != None:
-            self.metadata = metadata
-        else:
-            self.metadata = 0
-        if metadata_mask != None:
-            self.metadata_mask = metadata_mask
-        else:
-            self.metadata_mask = 0
-        return
-
-    def pack(self):
-        packed = []
-        packed.append(struct.pack("!H", self.type))
-        packed.append(struct.pack("!H", 0)) # placeholder for length at index 1
-        packed.append(util.pack_port_no(self.in_port))
-        packed.append(util.pack_wc_bmap(self.wildcards))
-        packed.append(struct.pack("!6B", *self.eth_src))
-        packed.append(struct.pack("!6B", *self.eth_src_mask))
-        packed.append(struct.pack("!6B", *self.eth_dst))
-        packed.append(struct.pack("!6B", *self.eth_dst_mask))
-        packed.append(struct.pack("!H", self.vlan_vid))
-        packed.append(struct.pack("!B", self.vlan_pcp))
-        packed.append('\x00' * 1)
-        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("!L", self.ipv4_src))
-        packed.append(struct.pack("!L", self.ipv4_src_mask))
-        packed.append(struct.pack("!L", self.ipv4_dst))
-        packed.append(struct.pack("!L", self.ipv4_dst_mask))
-        packed.append(struct.pack("!H", self.tcp_src))
-        packed.append(struct.pack("!H", self.tcp_dst))
-        packed.append(struct.pack("!L", self.mpls_label))
-        packed.append(struct.pack("!B", self.mpls_tc))
-        packed.append('\x00' * 3)
-        packed.append(struct.pack("!Q", self.metadata))
-        packed.append(struct.pack("!Q", self.metadata_mask))
-        length = sum([len(x) for x in packed])
-        packed[1] = struct.pack("!H", length)
-        return ''.join(packed)
-
-    @staticmethod
-    def unpack(reader):
-        obj = match_v2()
-        _type = reader.read("!H")[0]
-        assert(_type == 0)
-        _length = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_length, 4)
-        obj.in_port = util.unpack_port_no(reader)
-        obj.wildcards = util.unpack_wc_bmap(reader)
-        obj.eth_src = list(reader.read('!6B'))
-        obj.eth_src_mask = list(reader.read('!6B'))
-        obj.eth_dst = list(reader.read('!6B'))
-        obj.eth_dst_mask = list(reader.read('!6B'))
-        obj.vlan_vid = reader.read("!H")[0]
-        obj.vlan_pcp = reader.read("!B")[0]
-        reader.skip(1)
-        obj.eth_type = reader.read("!H")[0]
-        obj.ip_dscp = reader.read("!B")[0]
-        obj.ip_proto = reader.read("!B")[0]
-        obj.ipv4_src = reader.read("!L")[0]
-        obj.ipv4_src_mask = reader.read("!L")[0]
-        obj.ipv4_dst = reader.read("!L")[0]
-        obj.ipv4_dst_mask = reader.read("!L")[0]
-        obj.tcp_src = reader.read("!H")[0]
-        obj.tcp_dst = reader.read("!H")[0]
-        obj.mpls_label = reader.read("!L")[0]
-        obj.mpls_tc = reader.read("!B")[0]
-        reader.skip(3)
-        obj.metadata = reader.read("!Q")[0]
-        obj.metadata_mask = reader.read("!Q")[0]
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): return False
-        if self.in_port != other.in_port: return False
-        if self.wildcards != other.wildcards: return False
-        if self.eth_src != other.eth_src: return False
-        if self.eth_src_mask != other.eth_src_mask: return False
-        if self.eth_dst != other.eth_dst: return False
-        if self.eth_dst_mask != other.eth_dst_mask: return False
-        if self.vlan_vid != other.vlan_vid: return False
-        if self.vlan_pcp != other.vlan_pcp: 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.ipv4_src != other.ipv4_src: return False
-        if self.ipv4_src_mask != other.ipv4_src_mask: return False
-        if self.ipv4_dst != other.ipv4_dst: return False
-        if self.ipv4_dst_mask != other.ipv4_dst_mask: return False
-        if self.tcp_src != other.tcp_src: return False
-        if self.tcp_dst != other.tcp_dst: return False
-        if self.mpls_label != other.mpls_label: return False
-        if self.mpls_tc != other.mpls_tc: return False
-        if self.metadata != other.metadata: return False
-        if self.metadata_mask != other.metadata_mask: return False
-        return True
-
-    def pretty_print(self, q):
-        q.text("match_v2 {")
-        with q.group():
-            with q.indent(2):
-                q.breakable()
-                q.text("in_port = ");
-                q.text(util.pretty_port(self.in_port))
-                q.text(","); q.breakable()
-                q.text("wildcards = ");
-                q.text(util.pretty_wildcards(self.wildcards))
-                q.text(","); q.breakable()
-                q.text("eth_src = ");
-                q.text(util.pretty_mac(self.eth_src))
-                q.text(","); q.breakable()
-                q.text("eth_src_mask = ");
-                q.text(util.pretty_mac(self.eth_src_mask))
-                q.text(","); q.breakable()
-                q.text("eth_dst = ");
-                q.text(util.pretty_mac(self.eth_dst))
-                q.text(","); q.breakable()
-                q.text("eth_dst_mask = ");
-                q.text(util.pretty_mac(self.eth_dst_mask))
-                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("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("ipv4_src = ");
-                q.text(util.pretty_ipv4(self.ipv4_src))
-                q.text(","); q.breakable()
-                q.text("ipv4_src_mask = ");
-                q.text(util.pretty_ipv4(self.ipv4_src_mask))
-                q.text(","); q.breakable()
-                q.text("ipv4_dst = ");
-                q.text(util.pretty_ipv4(self.ipv4_dst))
-                q.text(","); q.breakable()
-                q.text("ipv4_dst_mask = ");
-                q.text(util.pretty_ipv4(self.ipv4_dst_mask))
-                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.text(","); q.breakable()
-                q.text("mpls_label = ");
-                q.text("%#x" % self.mpls_label)
-                q.text(","); q.breakable()
-                q.text("mpls_tc = ");
-                q.text("%#x" % self.mpls_tc)
-                q.text(","); q.breakable()
-                q.text("metadata = ");
-                q.text("%#x" % self.metadata)
-                q.text(","); q.breakable()
-                q.text("metadata_mask = ");
-                q.text("%#x" % self.metadata_mask)
-            q.breakable()
-        q.text('}')
-
-
-class packet_queue(loxi.OFObject):
-
-    def __init__(self, queue_id=None, properties=None):
-        if queue_id != None:
-            self.queue_id = queue_id
-        else:
-            self.queue_id = 0
-        if properties != None:
-            self.properties = properties
-        else:
-            self.properties = []
-        return
-
-    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('\x00' * 2)
-        packed.append(loxi.generic_util.pack_list(self.properties))
-        length = sum([len(x) for x in packed])
-        packed[1] = struct.pack("!H", length)
-        return ''.join(packed)
-
-    @staticmethod
-    def unpack(reader):
-        obj = packet_queue()
-        obj.queue_id = reader.read("!L")[0]
-        _len = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_len, 6)
-        reader.skip(2)
-        obj.properties = loxi.generic_util.unpack_list(reader, ofp.common.queue_prop.unpack)
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): return False
-        if self.queue_id != other.queue_id: return False
-        if self.properties != other.properties: return False
-        return True
-
-    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("properties = ");
-                q.pp(self.properties)
-            q.breakable()
-        q.text('}')
-
-
-class port_desc(loxi.OFObject):
-
-    def __init__(self, port_no=None, hw_addr=None, name=None, config=None, state=None, curr=None, advertised=None, supported=None, peer=None, curr_speed=None, max_speed=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
-        if curr_speed != None:
-            self.curr_speed = curr_speed
-        else:
-            self.curr_speed = 0
-        if max_speed != None:
-            self.max_speed = max_speed
-        else:
-            self.max_speed = 0
-        return
-
-    def pack(self):
-        packed = []
-        packed.append(util.pack_port_no(self.port_no))
-        packed.append('\x00' * 4)
-        packed.append(struct.pack("!6B", *self.hw_addr))
-        packed.append('\x00' * 2)
-        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))
-        packed.append(struct.pack("!L", self.curr_speed))
-        packed.append(struct.pack("!L", self.max_speed))
-        return ''.join(packed)
-
-    @staticmethod
-    def unpack(reader):
-        obj = port_desc()
-        obj.port_no = util.unpack_port_no(reader)
-        reader.skip(4)
-        obj.hw_addr = list(reader.read('!6B'))
-        reader.skip(2)
-        obj.name = reader.read("!16s")[0].rstrip("\x00")
-        obj.config = reader.read("!L")[0]
-        obj.state = reader.read("!L")[0]
-        obj.curr = reader.read("!L")[0]
-        obj.advertised = reader.read("!L")[0]
-        obj.supported = reader.read("!L")[0]
-        obj.peer = reader.read("!L")[0]
-        obj.curr_speed = reader.read("!L")[0]
-        obj.max_speed = reader.read("!L")[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
-        if self.curr_speed != other.curr_speed: return False
-        if self.max_speed != other.max_speed: return False
-        return True
-
-    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.text(","); q.breakable()
-                q.text("curr_speed = ");
-                q.text("%#x" % self.curr_speed)
-                q.text(","); q.breakable()
-                q.text("max_speed = ");
-                q.text("%#x" % self.max_speed)
-            q.breakable()
-        q.text('}')
-
-
-class port_stats_entry(loxi.OFObject):
-
-    def __init__(self, port_no=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 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
-        return
-
-    def pack(self):
-        packed = []
-        packed.append(util.pack_port_no(self.port_no))
-        packed.append('\x00' * 4)
-        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(reader):
-        obj = port_stats_entry()
-        obj.port_no = util.unpack_port_no(reader)
-        reader.skip(4)
-        obj.rx_packets = reader.read("!Q")[0]
-        obj.tx_packets = reader.read("!Q")[0]
-        obj.rx_bytes = reader.read("!Q")[0]
-        obj.tx_bytes = reader.read("!Q")[0]
-        obj.rx_dropped = reader.read("!Q")[0]
-        obj.tx_dropped = reader.read("!Q")[0]
-        obj.rx_errors = reader.read("!Q")[0]
-        obj.tx_errors = reader.read("!Q")[0]
-        obj.rx_frame_err = reader.read("!Q")[0]
-        obj.rx_over_err = reader.read("!Q")[0]
-        obj.rx_crc_err = reader.read("!Q")[0]
-        obj.collisions = reader.read("!Q")[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.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 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("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(loxi.OFObject):
-    subtypes = {}
-
-
-    def __init__(self, type=None):
-        if type != None:
-            self.type = type
-        else:
-            self.type = 0
-        return
-
-    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('\x00' * 4)
-        length = sum([len(x) for x in packed])
-        packed[1] = struct.pack("!H", length)
-        return ''.join(packed)
-
-    @staticmethod
-    def unpack(reader):
-        subtype, = reader.peek('!H', 0)
-        subclass = queue_prop.subtypes.get(subtype)
-        if subclass:
-            return subclass.unpack(reader)
-
-        obj = queue_prop()
-        obj.type = reader.read("!H")[0]
-        _len = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_len, 4)
-        reader.skip(4)
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): return False
-        if self.type != other.type: return False
-        return True
-
-    def pretty_print(self, q):
-        q.text("queue_prop {")
-        with q.group():
-            with q.indent(2):
-                q.breakable()
-            q.breakable()
-        q.text('}')
-
-
-class queue_prop_min_rate(queue_prop):
-    type = 1
-
-    def __init__(self, rate=None):
-        if rate != None:
-            self.rate = rate
-        else:
-            self.rate = 0
-        return
-
-    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('\x00' * 4)
-        packed.append(struct.pack("!H", self.rate))
-        packed.append('\x00' * 6)
-        length = sum([len(x) for x in packed])
-        packed[1] = struct.pack("!H", length)
-        return ''.join(packed)
-
-    @staticmethod
-    def unpack(reader):
-        obj = queue_prop_min_rate()
-        _type = reader.read("!H")[0]
-        assert(_type == 1)
-        _len = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_len, 4)
-        reader.skip(4)
-        obj.rate = reader.read("!H")[0]
-        reader.skip(6)
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): return False
-        if self.rate != other.rate: return False
-        return True
-
-    def pretty_print(self, q):
-        q.text("queue_prop_min_rate {")
-        with q.group():
-            with q.indent(2):
-                q.breakable()
-                q.text("rate = ");
-                q.text("%#x" % self.rate)
-            q.breakable()
-        q.text('}')
-
-queue_prop.subtypes[1] = queue_prop_min_rate
-
-class queue_stats_entry(loxi.OFObject):
-
-    def __init__(self, port_no=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 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
-        return
-
-    def pack(self):
-        packed = []
-        packed.append(util.pack_port_no(self.port_no))
-        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(reader):
-        obj = queue_stats_entry()
-        obj.port_no = util.unpack_port_no(reader)
-        obj.queue_id = reader.read("!L")[0]
-        obj.tx_bytes = reader.read("!Q")[0]
-        obj.tx_packets = reader.read("!Q")[0]
-        obj.tx_errors = reader.read("!Q")[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.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 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("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(loxi.OFObject):
-
-    def __init__(self, table_id=None, name=None, wildcards=None, match=None, instructions=None, write_actions=None, apply_actions=None, config=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 name != None:
-            self.name = name
-        else:
-            self.name = ""
-        if wildcards != None:
-            self.wildcards = wildcards
-        else:
-            self.wildcards = util.init_wc_bmap()
-        if match != None:
-            self.match = match
-        else:
-            self.match = util.init_match_bmap()
-        if instructions != None:
-            self.instructions = instructions
-        else:
-            self.instructions = 0
-        if write_actions != None:
-            self.write_actions = write_actions
-        else:
-            self.write_actions = 0
-        if apply_actions != None:
-            self.apply_actions = apply_actions
-        else:
-            self.apply_actions = 0
-        if config != None:
-            self.config = config
-        else:
-            self.config = 0
-        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
-        return
-
-    def pack(self):
-        packed = []
-        packed.append(struct.pack("!B", self.table_id))
-        packed.append('\x00' * 7)
-        packed.append(struct.pack("!32s", self.name))
-        packed.append(util.pack_wc_bmap(self.wildcards))
-        packed.append(util.pack_match_bmap(self.match))
-        packed.append(struct.pack("!L", self.instructions))
-        packed.append(struct.pack("!L", self.write_actions))
-        packed.append(struct.pack("!L", self.apply_actions))
-        packed.append(struct.pack("!L", self.config))
-        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(reader):
-        obj = table_stats_entry()
-        obj.table_id = reader.read("!B")[0]
-        reader.skip(7)
-        obj.name = reader.read("!32s")[0].rstrip("\x00")
-        obj.wildcards = util.unpack_wc_bmap(reader)
-        obj.match = util.unpack_match_bmap(reader)
-        obj.instructions = reader.read("!L")[0]
-        obj.write_actions = reader.read("!L")[0]
-        obj.apply_actions = reader.read("!L")[0]
-        obj.config = reader.read("!L")[0]
-        obj.max_entries = reader.read("!L")[0]
-        obj.active_count = reader.read("!L")[0]
-        obj.lookup_count = reader.read("!Q")[0]
-        obj.matched_count = reader.read("!Q")[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.name != other.name: return False
-        if self.wildcards != other.wildcards: return False
-        if self.match != other.match: return False
-        if self.instructions != other.instructions: return False
-        if self.write_actions != other.write_actions: return False
-        if self.apply_actions != other.apply_actions: return False
-        if self.config != other.config: 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 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("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("match = ");
-                q.pp(self.match)
-                q.text(","); q.breakable()
-                q.text("instructions = ");
-                q.text("%#x" % self.instructions)
-                q.text(","); q.breakable()
-                q.text("write_actions = ");
-                q.text("%#x" % self.write_actions)
-                q.text(","); q.breakable()
-                q.text("apply_actions = ");
-                q.text("%#x" % self.apply_actions)
-                q.text(","); q.breakable()
-                q.text("config = ");
-                q.text("%#x" % self.config)
-                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('}')
-
-
-
-match = match_v2
diff --git a/python/ofagent/loxi/of11/const.py b/python/ofagent/loxi/of11/const.py
deleted file mode 100644
index 9705d89..0000000
--- a/python/ofagent/loxi/of11/const.py
+++ /dev/null
@@ -1,733 +0,0 @@
-# Copyright 2017-present Open Networking Foundation
-#
-# 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.
-# Copyright (c) 2008 The Board of Trustees of The Leland Stanford Junior University
-# Copyright (c) 2011, 2012 Open Networking Foundation
-# Copyright (c) 2012, 2013 Big Switch Networks, Inc.
-# See the file LICENSE.pyloxi which should have been included in the source distribution
-
-# Automatically generated by LOXI from template const.py
-# Do not modify
-
-OFP_VERSION = 2
-
-# Identifiers from group macro_definitions
-OFP_MAX_TABLE_NAME_LEN = 32
-OFP_MAX_PORT_NAME_LEN = 16
-OFP_TCP_PORT = 6653
-OFP_SSL_PORT = 6653
-OFP_ETH_ALEN = 6
-OFP_DEFAULT_MISS_SEND_LEN = 128
-OFPFW_ICMP_TYPE = 64
-OFPFW_ICMP_CODE = 128
-OFP_DL_TYPE_ETH2_CUTOFF = 1536
-OFP_DL_TYPE_NOT_ETH_TYPE = 1535
-OFP_VLAN_NONE = 0
-OFPMT_STANDARD_LENGTH = 88
-OFP_FLOW_PERMANENT = 0
-OFP_DEFAULT_PRIORITY = 32768
-DESC_STR_LEN = 256
-SERIAL_NUM_LEN = 32
-OFPQ_ALL = 4294967295
-OFPQ_MIN_RATE_UNCFG = 65535
-
-# Identifiers from group of_bsn_pdu_slot_num
-BSN_PDU_SLOT_NUM_ANY = 255
-
-of_bsn_pdu_slot_num_map = {
-    255: 'BSN_PDU_SLOT_NUM_ANY',
-}
-
-# Identifiers from group ofp_action_type
-OFPAT_OUTPUT = 0
-OFPAT_SET_VLAN_VID = 1
-OFPAT_SET_VLAN_PCP = 2
-OFPAT_SET_DL_SRC = 3
-OFPAT_SET_DL_DST = 4
-OFPAT_SET_NW_SRC = 5
-OFPAT_SET_NW_DST = 6
-OFPAT_SET_NW_TOS = 7
-OFPAT_SET_NW_ECN = 8
-OFPAT_SET_TP_SRC = 9
-OFPAT_SET_TP_DST = 10
-OFPAT_COPY_TTL_OUT = 11
-OFPAT_COPY_TTL_IN = 12
-OFPAT_SET_MPLS_LABEL = 13
-OFPAT_SET_MPLS_TC = 14
-OFPAT_SET_MPLS_TTL = 15
-OFPAT_DEC_MPLS_TTL = 16
-OFPAT_PUSH_VLAN = 17
-OFPAT_POP_VLAN = 18
-OFPAT_PUSH_MPLS = 19
-OFPAT_POP_MPLS = 20
-OFPAT_SET_QUEUE = 21
-OFPAT_GROUP = 22
-OFPAT_SET_NW_TTL = 23
-OFPAT_DEC_NW_TTL = 24
-OFPAT_EXPERIMENTER = 65535
-
-ofp_action_type_map = {
-    0: 'OFPAT_OUTPUT',
-    1: 'OFPAT_SET_VLAN_VID',
-    2: 'OFPAT_SET_VLAN_PCP',
-    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_NW_ECN',
-    9: 'OFPAT_SET_TP_SRC',
-    10: 'OFPAT_SET_TP_DST',
-    11: 'OFPAT_COPY_TTL_OUT',
-    12: 'OFPAT_COPY_TTL_IN',
-    13: 'OFPAT_SET_MPLS_LABEL',
-    14: 'OFPAT_SET_MPLS_TC',
-    15: 'OFPAT_SET_MPLS_TTL',
-    16: 'OFPAT_DEC_MPLS_TTL',
-    17: 'OFPAT_PUSH_VLAN',
-    18: 'OFPAT_POP_VLAN',
-    19: 'OFPAT_PUSH_MPLS',
-    20: 'OFPAT_POP_MPLS',
-    21: 'OFPAT_SET_QUEUE',
-    22: 'OFPAT_GROUP',
-    23: 'OFPAT_SET_NW_TTL',
-    24: 'OFPAT_DEC_NW_TTL',
-    65535: 'OFPAT_EXPERIMENTER',
-}
-
-# Identifiers from group ofp_bad_action_code
-OFPBAC_BAD_TYPE = 0
-OFPBAC_BAD_LEN = 1
-OFPBAC_BAD_EXPERIMENTER = 2
-OFPBAC_BAD_EXPERIMENTER_TYPE = 3
-OFPBAC_BAD_OUT_PORT = 4
-OFPBAC_BAD_ARGUMENT = 5
-OFPBAC_EPERM = 6
-OFPBAC_TOO_MANY = 7
-OFPBAC_BAD_QUEUE = 8
-OFPBAC_BAD_OUT_GROUP = 9
-OFPBAC_MATCH_INCONSISTENT = 10
-OFPBAC_UNSUPPORTED_ORDER = 11
-OFPBAC_BAD_TAG = 12
-
-ofp_bad_action_code_map = {
-    0: 'OFPBAC_BAD_TYPE',
-    1: 'OFPBAC_BAD_LEN',
-    2: 'OFPBAC_BAD_EXPERIMENTER',
-    3: 'OFPBAC_BAD_EXPERIMENTER_TYPE',
-    4: 'OFPBAC_BAD_OUT_PORT',
-    5: 'OFPBAC_BAD_ARGUMENT',
-    6: 'OFPBAC_EPERM',
-    7: 'OFPBAC_TOO_MANY',
-    8: 'OFPBAC_BAD_QUEUE',
-    9: 'OFPBAC_BAD_OUT_GROUP',
-    10: 'OFPBAC_MATCH_INCONSISTENT',
-    11: 'OFPBAC_UNSUPPORTED_ORDER',
-    12: 'OFPBAC_BAD_TAG',
-}
-
-# Identifiers from group ofp_bad_instruction_code
-OFPBIC_UNKNOWN_INST = 0
-OFPBIC_UNSUP_INST = 1
-OFPBIC_BAD_TABLE_ID = 2
-OFPBIC_UNSUP_METADATA = 3
-OFPBIC_UNSUP_METADATA_MASK = 4
-OFPBIC_UNSUP_EXP_INST = 5
-
-ofp_bad_instruction_code_map = {
-    0: 'OFPBIC_UNKNOWN_INST',
-    1: 'OFPBIC_UNSUP_INST',
-    2: 'OFPBIC_BAD_TABLE_ID',
-    3: 'OFPBIC_UNSUP_METADATA',
-    4: 'OFPBIC_UNSUP_METADATA_MASK',
-    5: 'OFPBIC_UNSUP_EXP_INST',
-}
-
-# Identifiers from group ofp_bad_match_code
-OFPBMC_BAD_TYPE = 0
-OFPBMC_BAD_LEN = 1
-OFPBMC_BAD_TAG = 2
-OFPBMC_BAD_DL_ADDR_MASK = 3
-OFPBMC_BAD_NW_ADDR_MASK = 4
-OFPBMC_BAD_WILDCARDS = 5
-OFPBMC_BAD_FIELD = 6
-OFPBMC_BAD_VALUE = 7
-
-ofp_bad_match_code_map = {
-    0: 'OFPBMC_BAD_TYPE',
-    1: 'OFPBMC_BAD_LEN',
-    2: 'OFPBMC_BAD_TAG',
-    3: 'OFPBMC_BAD_DL_ADDR_MASK',
-    4: 'OFPBMC_BAD_NW_ADDR_MASK',
-    5: 'OFPBMC_BAD_WILDCARDS',
-    6: 'OFPBMC_BAD_FIELD',
-    7: 'OFPBMC_BAD_VALUE',
-}
-
-# Identifiers from group ofp_bad_request_code
-OFPBRC_BAD_VERSION = 0
-OFPBRC_BAD_TYPE = 1
-OFPBRC_BAD_STAT = 2
-OFPBRC_BAD_EXPERIMENTER = 3
-OFPBRC_BAD_SUBTYPE = 4
-OFPBRC_EPERM = 5
-OFPBRC_BAD_LEN = 6
-OFPBRC_BUFFER_EMPTY = 7
-OFPBRC_BUFFER_UNKNOWN = 8
-OFPBRC_BAD_TABLE_ID = 9
-
-ofp_bad_request_code_map = {
-    0: 'OFPBRC_BAD_VERSION',
-    1: 'OFPBRC_BAD_TYPE',
-    2: 'OFPBRC_BAD_STAT',
-    3: 'OFPBRC_BAD_EXPERIMENTER',
-    4: 'OFPBRC_BAD_SUBTYPE',
-    5: 'OFPBRC_EPERM',
-    6: 'OFPBRC_BAD_LEN',
-    7: 'OFPBRC_BUFFER_EMPTY',
-    8: 'OFPBRC_BUFFER_UNKNOWN',
-    9: 'OFPBRC_BAD_TABLE_ID',
-}
-
-# Identifiers from group ofp_bsn_vport_l2gre_flags
-OF_BSN_VPORT_L2GRE_LOCAL_MAC_IS_VALID = 1
-OF_BSN_VPORT_L2GRE_DSCP_ASSIGN = 2
-OF_BSN_VPORT_L2GRE_DSCP_COPY = 4
-OF_BSN_VPORT_L2GRE_LOOPBACK_IS_VALID = 8
-OF_BSN_VPORT_L2GRE_RATE_LIMIT_IS_VALID = 16
-
-ofp_bsn_vport_l2gre_flags_map = {
-    1: 'OF_BSN_VPORT_L2GRE_LOCAL_MAC_IS_VALID',
-    2: 'OF_BSN_VPORT_L2GRE_DSCP_ASSIGN',
-    4: 'OF_BSN_VPORT_L2GRE_DSCP_COPY',
-    8: 'OF_BSN_VPORT_L2GRE_LOOPBACK_IS_VALID',
-    16: 'OF_BSN_VPORT_L2GRE_RATE_LIMIT_IS_VALID',
-}
-
-# Identifiers from group ofp_bsn_vport_q_in_q_untagged
-OF_BSN_VPORT_Q_IN_Q_UNTAGGED = 65535
-
-ofp_bsn_vport_q_in_q_untagged_map = {
-    65535: 'OF_BSN_VPORT_Q_IN_Q_UNTAGGED',
-}
-
-# Identifiers from group ofp_bsn_vport_status
-OF_BSN_VPORT_STATUS_OK = 0
-OF_BSN_VPORT_STATUS_FAILED = 1
-
-ofp_bsn_vport_status_map = {
-    0: 'OF_BSN_VPORT_STATUS_OK',
-    1: 'OF_BSN_VPORT_STATUS_FAILED',
-}
-
-# Identifiers from group ofp_capabilities
-OFPC_FLOW_STATS = 1
-OFPC_TABLE_STATS = 2
-OFPC_PORT_STATS = 4
-OFPC_GROUP_STATS = 8
-OFPC_IP_REASM = 32
-OFPC_QUEUE_STATS = 64
-OFPC_ARP_MATCH_IP = 128
-
-ofp_capabilities_map = {
-    1: 'OFPC_FLOW_STATS',
-    2: 'OFPC_TABLE_STATS',
-    4: 'OFPC_PORT_STATS',
-    8: 'OFPC_GROUP_STATS',
-    32: 'OFPC_IP_REASM',
-    64: 'OFPC_QUEUE_STATS',
-    128: '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
-OFPC_INVALID_TTL_TO_CONTROLLER = 4
-
-ofp_config_flags_map = {
-    0: 'OFPC_FRAG_NORMAL',
-    1: 'OFPC_FRAG_DROP',
-    2: 'OFPC_FRAG_REASM',
-    3: 'OFPC_FRAG_MASK',
-    4: 'OFPC_INVALID_TTL_TO_CONTROLLER',
-}
-
-# Identifiers from group ofp_error_type
-OFPET_HELLO_FAILED = 0
-OFPET_BAD_REQUEST = 1
-OFPET_BAD_ACTION = 2
-OFPET_BAD_INSTRUCTION = 3
-OFPET_BAD_MATCH = 4
-OFPET_FLOW_MOD_FAILED = 5
-OFPET_GROUP_MOD_FAILED = 6
-OFPET_PORT_MOD_FAILED = 7
-OFPET_TABLE_MOD_FAILED = 8
-OFPET_QUEUE_OP_FAILED = 9
-OFPET_SWITCH_CONFIG_FAILED = 10
-
-ofp_error_type_map = {
-    0: 'OFPET_HELLO_FAILED',
-    1: 'OFPET_BAD_REQUEST',
-    2: 'OFPET_BAD_ACTION',
-    3: 'OFPET_BAD_INSTRUCTION',
-    4: 'OFPET_BAD_MATCH',
-    5: 'OFPET_FLOW_MOD_FAILED',
-    6: 'OFPET_GROUP_MOD_FAILED',
-    7: 'OFPET_PORT_MOD_FAILED',
-    8: 'OFPET_TABLE_MOD_FAILED',
-    9: 'OFPET_QUEUE_OP_FAILED',
-    10: 'OFPET_SWITCH_CONFIG_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_UNKNOWN = 0
-OFPFMFC_TABLE_FULL = 1
-OFPFMFC_BAD_TABLE_ID = 2
-OFPFMFC_OVERLAP = 3
-OFPFMFC_EPERM = 4
-OFPFMFC_BAD_TIMEOUT = 5
-OFPFMFC_BAD_COMMAND = 6
-
-ofp_flow_mod_failed_code_map = {
-    0: 'OFPFMFC_UNKNOWN',
-    1: 'OFPFMFC_TABLE_FULL',
-    2: 'OFPFMFC_BAD_TABLE_ID',
-    3: 'OFPFMFC_OVERLAP',
-    4: 'OFPFMFC_EPERM',
-    5: 'OFPFMFC_BAD_TIMEOUT',
-    6: 'OFPFMFC_BAD_COMMAND',
-}
-
-# Identifiers from group ofp_flow_mod_flags
-OFPFF_SEND_FLOW_REM = 1
-OFPFF_CHECK_OVERLAP = 2
-
-ofp_flow_mod_flags_map = {
-    1: 'OFPFF_SEND_FLOW_REM',
-    2: 'OFPFF_CHECK_OVERLAP',
-}
-
-# Identifiers from group ofp_flow_removed_reason
-OFPRR_IDLE_TIMEOUT = 0
-OFPRR_HARD_TIMEOUT = 1
-OFPRR_DELETE = 2
-OFPRR_GROUP_DELETE = 3
-
-ofp_flow_removed_reason_map = {
-    0: 'OFPRR_IDLE_TIMEOUT',
-    1: 'OFPRR_HARD_TIMEOUT',
-    2: 'OFPRR_DELETE',
-    3: 'OFPRR_GROUP_DELETE',
-}
-
-# Identifiers from group ofp_flow_wildcards
-OFPFW_IN_PORT = 1
-OFPFW_DL_VLAN = 2
-OFPFW_DL_VLAN_PCP = 4
-OFPFW_DL_TYPE = 8
-OFPFW_NW_TOS = 16
-OFPFW_NW_PROTO = 32
-OFPFW_TP_SRC = 64
-OFPFW_TP_DST = 128
-OFPFW_MPLS_LABEL = 256
-OFPFW_MPLS_TC = 512
-OFPFW_ALL = 1023
-
-ofp_flow_wildcards_map = {
-    1: 'OFPFW_IN_PORT',
-    2: 'OFPFW_DL_VLAN',
-    4: 'OFPFW_DL_VLAN_PCP',
-    8: 'OFPFW_DL_TYPE',
-    16: 'OFPFW_NW_TOS',
-    32: 'OFPFW_NW_PROTO',
-    64: 'OFPFW_TP_SRC',
-    128: 'OFPFW_TP_DST',
-    256: 'OFPFW_MPLS_LABEL',
-    512: 'OFPFW_MPLS_TC',
-}
-
-# Identifiers from group ofp_group
-OFPG_MAX = 4294967040
-OFPG_ALL = 4294967292
-OFPG_ANY = 4294967295
-
-ofp_group_map = {
-    4294967040: 'OFPG_MAX',
-    4294967292: 'OFPG_ALL',
-    4294967295: 'OFPG_ANY',
-}
-
-# Identifiers from group ofp_group_mod_command
-OFPGC_ADD = 0
-OFPGC_MODIFY = 1
-OFPGC_DELETE = 2
-
-ofp_group_mod_command_map = {
-    0: 'OFPGC_ADD',
-    1: 'OFPGC_MODIFY',
-    2: 'OFPGC_DELETE',
-}
-
-# Identifiers from group ofp_group_mod_failed_code
-OFPGMFC_GROUP_EXISTS = 0
-OFPGMFC_INVALID_GROUP = 1
-OFPGMFC_WEIGHT_UNSUPPORTED = 2
-OFPGMFC_OUT_OF_GROUPS = 3
-OFPGMFC_OUT_OF_BUCKETS = 4
-OFPGMFC_CHAINING_UNSUPPORTED = 5
-OFPGMFC_WATCH_UNSUPPORTED = 6
-OFPGMFC_LOOP = 7
-OFPGMFC_UNKNOWN_GROUP = 8
-
-ofp_group_mod_failed_code_map = {
-    0: 'OFPGMFC_GROUP_EXISTS',
-    1: 'OFPGMFC_INVALID_GROUP',
-    2: 'OFPGMFC_WEIGHT_UNSUPPORTED',
-    3: 'OFPGMFC_OUT_OF_GROUPS',
-    4: 'OFPGMFC_OUT_OF_BUCKETS',
-    5: 'OFPGMFC_CHAINING_UNSUPPORTED',
-    6: 'OFPGMFC_WATCH_UNSUPPORTED',
-    7: 'OFPGMFC_LOOP',
-    8: 'OFPGMFC_UNKNOWN_GROUP',
-}
-
-# Identifiers from group ofp_group_type
-OFPGT_ALL = 0
-OFPGT_SELECT = 1
-OFPGT_INDIRECT = 2
-OFPGT_FF = 3
-
-ofp_group_type_map = {
-    0: 'OFPGT_ALL',
-    1: 'OFPGT_SELECT',
-    2: 'OFPGT_INDIRECT',
-    3: 'OFPGT_FF',
-}
-
-# 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_instruction_type
-OFPIT_GOTO_TABLE = 1
-OFPIT_WRITE_METADATA = 2
-OFPIT_WRITE_ACTIONS = 3
-OFPIT_APPLY_ACTIONS = 4
-OFPIT_CLEAR_ACTIONS = 5
-OFPIT_EXPERIMENTER = 65535
-
-ofp_instruction_type_map = {
-    1: 'OFPIT_GOTO_TABLE',
-    2: 'OFPIT_WRITE_METADATA',
-    3: 'OFPIT_WRITE_ACTIONS',
-    4: 'OFPIT_APPLY_ACTIONS',
-    5: 'OFPIT_CLEAR_ACTIONS',
-    65535: 'OFPIT_EXPERIMENTER',
-}
-
-# Identifiers from group ofp_match_type
-OFPMT_STANDARD = 0
-
-ofp_match_type_map = {
-    0: 'OFPMT_STANDARD',
-}
-
-# 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 = 4294967040
-OFPP_IN_PORT = 4294967288
-OFPP_TABLE = 4294967289
-OFPP_NORMAL = 4294967290
-OFPP_FLOOD = 4294967291
-OFPP_ALL = 4294967292
-OFPP_CONTROLLER = 4294967293
-OFPP_LOCAL = 4294967294
-OFPP_ANY = 4294967295
-
-ofp_port_map = {
-    4294967040: 'OFPP_MAX',
-    4294967288: 'OFPP_IN_PORT',
-    4294967289: 'OFPP_TABLE',
-    4294967290: 'OFPP_NORMAL',
-    4294967291: 'OFPP_FLOOD',
-    4294967292: 'OFPP_ALL',
-    4294967293: 'OFPP_CONTROLLER',
-    4294967294: 'OFPP_LOCAL',
-    4294967295: 'OFPP_ANY',
-}
-
-# Identifiers from group ofp_port_config
-OFPPC_PORT_DOWN = 1
-OFPPC_NO_RECV = 4
-OFPPC_NO_FWD = 32
-OFPPC_NO_PACKET_IN = 64
-OFPPC_BSN_MIRROR_DEST = 2147483648
-
-ofp_port_config_map = {
-    1: 'OFPPC_PORT_DOWN',
-    4: 'OFPPC_NO_RECV',
-    32: 'OFPPC_NO_FWD',
-    64: 'OFPPC_NO_PACKET_IN',
-    2147483648: 'OFPPC_BSN_MIRROR_DEST',
-}
-
-# Identifiers from group ofp_port_features
-OFPPF_10MB_HD = 1
-OFPPF_10MB_FD = 2
-OFPPF_100MB_HD = 4
-OFPPF_100MB_FD = 8
-OFPPF_1GB_HD = 16
-OFPPF_1GB_FD = 32
-OFPPF_10GB_FD = 64
-OFPPF_40GB_FD = 128
-OFPPF_100GB_FD = 256
-OFPPF_1TB_FD = 512
-OFPPF_OTHER = 1024
-OFPPF_COPPER = 2048
-OFPPF_FIBER = 4096
-OFPPF_AUTONEG = 8192
-OFPPF_PAUSE = 16384
-OFPPF_PAUSE_ASYM = 32768
-
-ofp_port_features_map = {
-    1: 'OFPPF_10MB_HD',
-    2: 'OFPPF_10MB_FD',
-    4: 'OFPPF_100MB_HD',
-    8: 'OFPPF_100MB_FD',
-    16: 'OFPPF_1GB_HD',
-    32: 'OFPPF_1GB_FD',
-    64: 'OFPPF_10GB_FD',
-    128: 'OFPPF_40GB_FD',
-    256: 'OFPPF_100GB_FD',
-    512: 'OFPPF_1TB_FD',
-    1024: 'OFPPF_OTHER',
-    2048: 'OFPPF_COPPER',
-    4096: 'OFPPF_FIBER',
-    8192: 'OFPPF_AUTONEG',
-    16384: 'OFPPF_PAUSE',
-    32768: 'OFPPF_PAUSE_ASYM',
-}
-
-# Identifiers from group ofp_port_mod_failed_code
-OFPPMFC_BAD_PORT = 0
-OFPPMFC_BAD_HW_ADDR = 1
-OFPPMFC_BAD_CONFIG = 2
-OFPPMFC_BAD_ADVERTISE = 3
-
-ofp_port_mod_failed_code_map = {
-    0: 'OFPPMFC_BAD_PORT',
-    1: 'OFPPMFC_BAD_HW_ADDR',
-    2: 'OFPPMFC_BAD_CONFIG',
-    3: 'OFPPMFC_BAD_ADVERTISE',
-}
-
-# 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_LINK_DOWN = 1
-OFPPS_BLOCKED = 2
-OFPPS_LIVE = 4
-
-ofp_port_state_map = {
-    1: 'OFPPS_LINK_DOWN',
-    2: 'OFPPS_BLOCKED',
-    4: 'OFPPS_LIVE',
-}
-
-# 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
-
-ofp_stats_reply_flags_map = {
-    1: 'OFPSF_REPLY_MORE',
-}
-
-# Identifiers from group ofp_stats_request_flags
-
-ofp_stats_request_flags_map = {
-}
-
-# Identifiers from group ofp_stats_type
-OFPST_DESC = 0
-OFPST_FLOW = 1
-OFPST_AGGREGATE = 2
-OFPST_TABLE = 3
-OFPST_PORT = 4
-OFPST_QUEUE = 5
-OFPST_GROUP = 6
-OFPST_GROUP_DESC = 7
-OFPST_EXPERIMENTER = 65535
-
-ofp_stats_type_map = {
-    0: 'OFPST_DESC',
-    1: 'OFPST_FLOW',
-    2: 'OFPST_AGGREGATE',
-    3: 'OFPST_TABLE',
-    4: 'OFPST_PORT',
-    5: 'OFPST_QUEUE',
-    6: 'OFPST_GROUP',
-    7: 'OFPST_GROUP_DESC',
-    65535: 'OFPST_EXPERIMENTER',
-}
-
-# Identifiers from group ofp_switch_config_failed_code
-OFPSCFC_BAD_FLAGS = 0
-OFPSCFC_BAD_LEN = 1
-
-ofp_switch_config_failed_code_map = {
-    0: 'OFPSCFC_BAD_FLAGS',
-    1: 'OFPSCFC_BAD_LEN',
-}
-
-# Identifiers from group ofp_table_config
-OFPTC_TABLE_MISS_CONTROLLER = 0
-OFPTC_TABLE_MISS_CONTINUE = 1
-OFPTC_TABLE_MISS_DROP = 2
-OFPTC_TABLE_MISS_MASK = 3
-
-ofp_table_config_map = {
-    0: 'OFPTC_TABLE_MISS_CONTROLLER',
-    1: 'OFPTC_TABLE_MISS_CONTINUE',
-    2: 'OFPTC_TABLE_MISS_DROP',
-    3: 'OFPTC_TABLE_MISS_MASK',
-}
-
-# Identifiers from group ofp_table_mod_failed_code
-OFPTMFC_BAD_TABLE = 0
-OFPTMFC_BAD_CONFIG = 1
-
-ofp_table_mod_failed_code_map = {
-    0: 'OFPTMFC_BAD_TABLE',
-    1: 'OFPTMFC_BAD_CONFIG',
-}
-
-# Identifiers from group ofp_type
-OFPT_HELLO = 0
-OFPT_ERROR = 1
-OFPT_ECHO_REQUEST = 2
-OFPT_ECHO_REPLY = 3
-OFPT_EXPERIMENTER = 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_GROUP_MOD = 15
-OFPT_PORT_MOD = 16
-OFPT_TABLE_MOD = 17
-OFPT_STATS_REQUEST = 18
-OFPT_STATS_REPLY = 19
-OFPT_BARRIER_REQUEST = 20
-OFPT_BARRIER_REPLY = 21
-OFPT_QUEUE_GET_CONFIG_REQUEST = 22
-OFPT_QUEUE_GET_CONFIG_REPLY = 23
-
-ofp_type_map = {
-    0: 'OFPT_HELLO',
-    1: 'OFPT_ERROR',
-    2: 'OFPT_ECHO_REQUEST',
-    3: 'OFPT_ECHO_REPLY',
-    4: 'OFPT_EXPERIMENTER',
-    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_GROUP_MOD',
-    16: 'OFPT_PORT_MOD',
-    17: 'OFPT_TABLE_MOD',
-    18: 'OFPT_STATS_REQUEST',
-    19: 'OFPT_STATS_REPLY',
-    20: 'OFPT_BARRIER_REQUEST',
-    21: 'OFPT_BARRIER_REPLY',
-    22: 'OFPT_QUEUE_GET_CONFIG_REQUEST',
-    23: 'OFPT_QUEUE_GET_CONFIG_REPLY',
-}
-
-# Identifiers from group ofp_vlan_id
-OFPVID_ANY = 65534
-OFPVID_NONE = 65535
-
-ofp_vlan_id_map = {
-    65534: 'OFPVID_ANY',
-    65535: 'OFPVID_NONE',
-}
-
diff --git a/python/ofagent/loxi/of11/instruction.py b/python/ofagent/loxi/of11/instruction.py
deleted file mode 100644
index 7910aef..0000000
--- a/python/ofagent/loxi/of11/instruction.py
+++ /dev/null
@@ -1,386 +0,0 @@
-# Copyright 2017-present Open Networking Foundation
-#
-# 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.
-# Copyright (c) 2008 The Board of Trustees of The Leland Stanford Junior University
-# Copyright (c) 2011, 2012 Open Networking Foundation
-# Copyright (c) 2012, 2013 Big Switch Networks, Inc.
-# See the file LICENSE.pyloxi which should have been included in the source distribution
-
-# Automatically generated by LOXI from template module.py
-# Do not modify
-
-import struct
-import loxi
-import util
-import loxi.generic_util
-
-import sys
-ofp = sys.modules['loxi.of11']
-
-class instruction(loxi.OFObject):
-    subtypes = {}
-
-
-    def __init__(self, type=None):
-        if type != None:
-            self.type = type
-        else:
-            self.type = 0
-        return
-
-    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('\x00' * 4)
-        length = sum([len(x) for x in packed])
-        packed[1] = struct.pack("!H", length)
-        return ''.join(packed)
-
-    @staticmethod
-    def unpack(reader):
-        subtype, = reader.peek('!H', 0)
-        subclass = instruction.subtypes.get(subtype)
-        if subclass:
-            return subclass.unpack(reader)
-
-        obj = instruction()
-        obj.type = reader.read("!H")[0]
-        _len = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_len, 4)
-        reader.skip(4)
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): return False
-        if self.type != other.type: return False
-        return True
-
-    def pretty_print(self, q):
-        q.text("instruction {")
-        with q.group():
-            with q.indent(2):
-                q.breakable()
-            q.breakable()
-        q.text('}')
-
-
-class apply_actions(instruction):
-    type = 4
-
-    def __init__(self, actions=None):
-        if actions != None:
-            self.actions = actions
-        else:
-            self.actions = []
-        return
-
-    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('\x00' * 4)
-        packed.append(loxi.generic_util.pack_list(self.actions))
-        length = sum([len(x) for x in packed])
-        packed[1] = struct.pack("!H", length)
-        return ''.join(packed)
-
-    @staticmethod
-    def unpack(reader):
-        obj = apply_actions()
-        _type = reader.read("!H")[0]
-        assert(_type == 4)
-        _len = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_len, 4)
-        reader.skip(4)
-        obj.actions = loxi.generic_util.unpack_list(reader, ofp.action.action.unpack)
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): return False
-        if self.actions != other.actions: return False
-        return True
-
-    def pretty_print(self, q):
-        q.text("apply_actions {")
-        with q.group():
-            with q.indent(2):
-                q.breakable()
-                q.text("actions = ");
-                q.pp(self.actions)
-            q.breakable()
-        q.text('}')
-
-instruction.subtypes[4] = apply_actions
-
-class clear_actions(instruction):
-    type = 5
-
-    def __init__(self):
-        return
-
-    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('\x00' * 4)
-        length = sum([len(x) for x in packed])
-        packed[1] = struct.pack("!H", length)
-        return ''.join(packed)
-
-    @staticmethod
-    def unpack(reader):
-        obj = clear_actions()
-        _type = reader.read("!H")[0]
-        assert(_type == 5)
-        _len = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_len, 4)
-        reader.skip(4)
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): return False
-        return True
-
-    def pretty_print(self, q):
-        q.text("clear_actions {")
-        with q.group():
-            with q.indent(2):
-                q.breakable()
-            q.breakable()
-        q.text('}')
-
-instruction.subtypes[5] = clear_actions
-
-class experimenter(instruction):
-    subtypes = {}
-
-    type = 65535
-
-    def __init__(self, experimenter=None, data=None):
-        if experimenter != None:
-            self.experimenter = experimenter
-        else:
-            self.experimenter = 0
-        if data != None:
-            self.data = data
-        else:
-            self.data = ''
-        return
-
-    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(self.data)
-        length = sum([len(x) for x in packed])
-        packed[1] = struct.pack("!H", length)
-        return ''.join(packed)
-
-    @staticmethod
-    def unpack(reader):
-        subtype, = reader.peek('!L', 4)
-        subclass = experimenter.subtypes.get(subtype)
-        if subclass:
-            return subclass.unpack(reader)
-
-        obj = experimenter()
-        _type = reader.read("!H")[0]
-        assert(_type == 65535)
-        _len = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_len, 4)
-        obj.experimenter = reader.read("!L")[0]
-        obj.data = str(reader.read_all())
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): return False
-        if self.experimenter != other.experimenter: return False
-        if self.data != other.data: return False
-        return True
-
-    def pretty_print(self, q):
-        q.text("experimenter {")
-        with q.group():
-            with q.indent(2):
-                q.breakable()
-                q.text("data = ");
-                q.pp(self.data)
-            q.breakable()
-        q.text('}')
-
-instruction.subtypes[65535] = experimenter
-
-class goto_table(instruction):
-    type = 1
-
-    def __init__(self, table_id=None):
-        if table_id != None:
-            self.table_id = table_id
-        else:
-            self.table_id = 0
-        return
-
-    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.table_id))
-        packed.append('\x00' * 3)
-        length = sum([len(x) for x in packed])
-        packed[1] = struct.pack("!H", length)
-        return ''.join(packed)
-
-    @staticmethod
-    def unpack(reader):
-        obj = goto_table()
-        _type = reader.read("!H")[0]
-        assert(_type == 1)
-        _len = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_len, 4)
-        obj.table_id = reader.read("!B")[0]
-        reader.skip(3)
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): return False
-        if self.table_id != other.table_id: return False
-        return True
-
-    def pretty_print(self, q):
-        q.text("goto_table {")
-        with q.group():
-            with q.indent(2):
-                q.breakable()
-                q.text("table_id = ");
-                q.text("%#x" % self.table_id)
-            q.breakable()
-        q.text('}')
-
-instruction.subtypes[1] = goto_table
-
-class write_actions(instruction):
-    type = 3
-
-    def __init__(self, actions=None):
-        if actions != None:
-            self.actions = actions
-        else:
-            self.actions = []
-        return
-
-    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('\x00' * 4)
-        packed.append(loxi.generic_util.pack_list(self.actions))
-        length = sum([len(x) for x in packed])
-        packed[1] = struct.pack("!H", length)
-        return ''.join(packed)
-
-    @staticmethod
-    def unpack(reader):
-        obj = write_actions()
-        _type = reader.read("!H")[0]
-        assert(_type == 3)
-        _len = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_len, 4)
-        reader.skip(4)
-        obj.actions = loxi.generic_util.unpack_list(reader, ofp.action.action.unpack)
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): return False
-        if self.actions != other.actions: return False
-        return True
-
-    def pretty_print(self, q):
-        q.text("write_actions {")
-        with q.group():
-            with q.indent(2):
-                q.breakable()
-                q.text("actions = ");
-                q.pp(self.actions)
-            q.breakable()
-        q.text('}')
-
-instruction.subtypes[3] = write_actions
-
-class write_metadata(instruction):
-    type = 2
-
-    def __init__(self, metadata=None, metadata_mask=None):
-        if metadata != None:
-            self.metadata = metadata
-        else:
-            self.metadata = 0
-        if metadata_mask != None:
-            self.metadata_mask = metadata_mask
-        else:
-            self.metadata_mask = 0
-        return
-
-    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('\x00' * 4)
-        packed.append(struct.pack("!Q", self.metadata))
-        packed.append(struct.pack("!Q", self.metadata_mask))
-        length = sum([len(x) for x in packed])
-        packed[1] = struct.pack("!H", length)
-        return ''.join(packed)
-
-    @staticmethod
-    def unpack(reader):
-        obj = write_metadata()
-        _type = reader.read("!H")[0]
-        assert(_type == 2)
-        _len = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_len, 4)
-        reader.skip(4)
-        obj.metadata = reader.read("!Q")[0]
-        obj.metadata_mask = reader.read("!Q")[0]
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): return False
-        if self.metadata != other.metadata: return False
-        if self.metadata_mask != other.metadata_mask: return False
-        return True
-
-    def pretty_print(self, q):
-        q.text("write_metadata {")
-        with q.group():
-            with q.indent(2):
-                q.breakable()
-                q.text("metadata = ");
-                q.text("%#x" % self.metadata)
-                q.text(","); q.breakable()
-                q.text("metadata_mask = ");
-                q.text("%#x" % self.metadata_mask)
-            q.breakable()
-        q.text('}')
-
-instruction.subtypes[2] = write_metadata
-
-
diff --git a/python/ofagent/loxi/of11/message.py b/python/ofagent/loxi/of11/message.py
deleted file mode 100644
index cb102f8..0000000
--- a/python/ofagent/loxi/of11/message.py
+++ /dev/null
@@ -1,7856 +0,0 @@
-# Copyright 2017-present Open Networking Foundation
-#
-# 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.
-# Copyright (c) 2008 The Board of Trustees of The Leland Stanford Junior University
-# Copyright (c) 2011, 2012 Open Networking Foundation
-# Copyright (c) 2012, 2013 Big Switch Networks, Inc.
-# See the file LICENSE.pyloxi which should have been included in the source distribution
-
-# Automatically generated by LOXI from template module.py
-# Do not modify
-
-import struct
-import loxi
-import util
-import loxi.generic_util
-
-import sys
-ofp = sys.modules['loxi.of11']
-
-class message(loxi.OFObject):
-    subtypes = {}
-
-    version = 2
-
-    def __init__(self, type=None, xid=None):
-        if type != None:
-            self.type = type
-        else:
-            self.type = 0
-        if xid != None:
-            self.xid = xid
-        else:
-            self.xid = None
-        return
-
-    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(reader):
-        subtype, = reader.peek('B', 1)
-        subclass = message.subtypes.get(subtype)
-        if subclass:
-            return subclass.unpack(reader)
-
-        obj = message()
-        _version = reader.read("!B")[0]
-        assert(_version == 2)
-        obj.type = reader.read("!B")[0]
-        _length = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_length, 4)
-        obj.xid = reader.read("!L")[0]
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): return False
-        if self.type != other.type: return False
-        if self.xid != other.xid: return False
-        return True
-
-    def pretty_print(self, q):
-        q.text("message {")
-        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 stats_reply(message):
-    subtypes = {}
-
-    version = 2
-    type = 19
-
-    def __init__(self, xid=None, stats_type=None, flags=None):
-        if xid != None:
-            self.xid = xid
-        else:
-            self.xid = None
-        if stats_type != None:
-            self.stats_type = stats_type
-        else:
-            self.stats_type = 0
-        if flags != None:
-            self.flags = flags
-        else:
-            self.flags = 0
-        return
-
-    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('\x00' * 4)
-        length = sum([len(x) for x in packed])
-        packed[2] = struct.pack("!H", length)
-        return ''.join(packed)
-
-    @staticmethod
-    def unpack(reader):
-        subtype, = reader.peek('!H', 8)
-        subclass = stats_reply.subtypes.get(subtype)
-        if subclass:
-            return subclass.unpack(reader)
-
-        obj = stats_reply()
-        _version = reader.read("!B")[0]
-        assert(_version == 2)
-        _type = reader.read("!B")[0]
-        assert(_type == 19)
-        _length = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_length, 4)
-        obj.xid = reader.read("!L")[0]
-        obj.stats_type = reader.read("!H")[0]
-        obj.flags = reader.read("!H")[0]
-        reader.skip(4)
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): return False
-        if self.xid != other.xid: return False
-        if self.stats_type != other.stats_type: return False
-        if self.flags != other.flags: return False
-        return True
-
-    def pretty_print(self, q):
-        q.text("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.breakable()
-        q.text('}')
-
-message.subtypes[19] = stats_reply
-
-class aggregate_stats_reply(stats_reply):
-    version = 2
-    type = 19
-    stats_type = 2
-
-    def __init__(self, xid=None, flags=None, packet_count=None, byte_count=None, flow_count=None):
-        if xid != None:
-            self.xid = xid
-        else:
-            self.xid = None
-        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
-        return
-
-    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('\x00' * 4)
-        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('\x00' * 4)
-        length = sum([len(x) for x in packed])
-        packed[2] = struct.pack("!H", length)
-        return ''.join(packed)
-
-    @staticmethod
-    def unpack(reader):
-        obj = aggregate_stats_reply()
-        _version = reader.read("!B")[0]
-        assert(_version == 2)
-        _type = reader.read("!B")[0]
-        assert(_type == 19)
-        _length = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_length, 4)
-        obj.xid = reader.read("!L")[0]
-        _stats_type = reader.read("!H")[0]
-        assert(_stats_type == 2)
-        obj.flags = reader.read("!H")[0]
-        reader.skip(4)
-        obj.packet_count = reader.read("!Q")[0]
-        obj.byte_count = reader.read("!Q")[0]
-        obj.flow_count = reader.read("!L")[0]
-        reader.skip(4)
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): 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
-        return True
-
-    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.breakable()
-        q.text('}')
-
-stats_reply.subtypes[2] = aggregate_stats_reply
-
-class stats_request(message):
-    subtypes = {}
-
-    version = 2
-    type = 18
-
-    def __init__(self, xid=None, stats_type=None, flags=None):
-        if xid != None:
-            self.xid = xid
-        else:
-            self.xid = None
-        if stats_type != None:
-            self.stats_type = stats_type
-        else:
-            self.stats_type = 0
-        if flags != None:
-            self.flags = flags
-        else:
-            self.flags = 0
-        return
-
-    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('\x00' * 4)
-        length = sum([len(x) for x in packed])
-        packed[2] = struct.pack("!H", length)
-        return ''.join(packed)
-
-    @staticmethod
-    def unpack(reader):
-        subtype, = reader.peek('!H', 8)
-        subclass = stats_request.subtypes.get(subtype)
-        if subclass:
-            return subclass.unpack(reader)
-
-        obj = stats_request()
-        _version = reader.read("!B")[0]
-        assert(_version == 2)
-        _type = reader.read("!B")[0]
-        assert(_type == 18)
-        _length = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_length, 4)
-        obj.xid = reader.read("!L")[0]
-        obj.stats_type = reader.read("!H")[0]
-        obj.flags = reader.read("!H")[0]
-        reader.skip(4)
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): return False
-        if self.xid != other.xid: return False
-        if self.stats_type != other.stats_type: return False
-        if self.flags != other.flags: return False
-        return True
-
-    def pretty_print(self, q):
-        q.text("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('}')
-
-message.subtypes[18] = stats_request
-
-class aggregate_stats_request(stats_request):
-    version = 2
-    type = 18
-    stats_type = 2
-
-    def __init__(self, xid=None, flags=None, table_id=None, out_port=None, out_group=None, cookie=None, cookie_mask=None, match=None):
-        if xid != None:
-            self.xid = xid
-        else:
-            self.xid = None
-        if flags != None:
-            self.flags = flags
-        else:
-            self.flags = 0
-        if table_id != None:
-            self.table_id = table_id
-        else:
-            self.table_id = 0
-        if out_port != None:
-            self.out_port = out_port
-        else:
-            self.out_port = 0
-        if out_group != None:
-            self.out_group = out_group
-        else:
-            self.out_group = 0
-        if cookie != None:
-            self.cookie = cookie
-        else:
-            self.cookie = 0
-        if cookie_mask != None:
-            self.cookie_mask = cookie_mask
-        else:
-            self.cookie_mask = 0
-        if match != None:
-            self.match = match
-        else:
-            self.match = ofp.match()
-        return
-
-    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('\x00' * 4)
-        packed.append(struct.pack("!B", self.table_id))
-        packed.append('\x00' * 3)
-        packed.append(util.pack_port_no(self.out_port))
-        packed.append(struct.pack("!L", self.out_group))
-        packed.append('\x00' * 4)
-        packed.append(struct.pack("!Q", self.cookie))
-        packed.append(struct.pack("!Q", self.cookie_mask))
-        packed.append(self.match.pack())
-        length = sum([len(x) for x in packed])
-        packed[2] = struct.pack("!H", length)
-        return ''.join(packed)
-
-    @staticmethod
-    def unpack(reader):
-        obj = aggregate_stats_request()
-        _version = reader.read("!B")[0]
-        assert(_version == 2)
-        _type = reader.read("!B")[0]
-        assert(_type == 18)
-        _length = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_length, 4)
-        obj.xid = reader.read("!L")[0]
-        _stats_type = reader.read("!H")[0]
-        assert(_stats_type == 2)
-        obj.flags = reader.read("!H")[0]
-        reader.skip(4)
-        obj.table_id = reader.read("!B")[0]
-        reader.skip(3)
-        obj.out_port = util.unpack_port_no(reader)
-        obj.out_group = reader.read("!L")[0]
-        reader.skip(4)
-        obj.cookie = reader.read("!Q")[0]
-        obj.cookie_mask = reader.read("!Q")[0]
-        obj.match = ofp.match.unpack(reader)
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): return False
-        if self.xid != other.xid: return False
-        if self.flags != other.flags: return False
-        if self.table_id != other.table_id: return False
-        if self.out_port != other.out_port: return False
-        if self.out_group != other.out_group: return False
-        if self.cookie != other.cookie: return False
-        if self.cookie_mask != other.cookie_mask: return False
-        if self.match != other.match: return False
-        return True
-
-    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("table_id = ");
-                q.text("%#x" % self.table_id)
-                q.text(","); q.breakable()
-                q.text("out_port = ");
-                q.text(util.pretty_port(self.out_port))
-                q.text(","); q.breakable()
-                q.text("out_group = ");
-                q.text("%#x" % self.out_group)
-                q.text(","); q.breakable()
-                q.text("cookie = ");
-                q.text("%#x" % self.cookie)
-                q.text(","); q.breakable()
-                q.text("cookie_mask = ");
-                q.text("%#x" % self.cookie_mask)
-                q.text(","); q.breakable()
-                q.text("match = ");
-                q.pp(self.match)
-            q.breakable()
-        q.text('}')
-
-stats_request.subtypes[2] = aggregate_stats_request
-
-class error_msg(message):
-    subtypes = {}
-
-    version = 2
-    type = 1
-
-    def __init__(self, xid=None, err_type=None):
-        if xid != None:
-            self.xid = xid
-        else:
-            self.xid = None
-        if err_type != None:
-            self.err_type = err_type
-        else:
-            self.err_type = 0
-        return
-
-    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))
-        length = sum([len(x) for x in packed])
-        packed[2] = struct.pack("!H", length)
-        return ''.join(packed)
-
-    @staticmethod
-    def unpack(reader):
-        subtype, = reader.peek('!H', 8)
-        subclass = error_msg.subtypes.get(subtype)
-        if subclass:
-            return subclass.unpack(reader)
-
-        obj = error_msg()
-        _version = reader.read("!B")[0]
-        assert(_version == 2)
-        _type = reader.read("!B")[0]
-        assert(_type == 1)
-        _length = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_length, 4)
-        obj.xid = reader.read("!L")[0]
-        obj.err_type = reader.read("!H")[0]
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): return False
-        if self.xid != other.xid: return False
-        if self.err_type != other.err_type: return False
-        return True
-
-    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.breakable()
-        q.text('}')
-
-message.subtypes[1] = error_msg
-
-class bad_action_error_msg(error_msg):
-    version = 2
-    type = 1
-    err_type = 2
-
-    def __init__(self, xid=None, code=None, data=None):
-        if xid != None:
-            self.xid = xid
-        else:
-            self.xid = None
-        if code != None:
-            self.code = code
-        else:
-            self.code = 0
-        if data != None:
-            self.data = data
-        else:
-            self.data = ''
-        return
-
-    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(reader):
-        obj = bad_action_error_msg()
-        _version = reader.read("!B")[0]
-        assert(_version == 2)
-        _type = reader.read("!B")[0]
-        assert(_type == 1)
-        _length = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_length, 4)
-        obj.xid = reader.read("!L")[0]
-        _err_type = reader.read("!H")[0]
-        assert(_err_type == 2)
-        obj.code = reader.read("!H")[0]
-        obj.data = str(reader.read_all())
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): return False
-        if self.xid != other.xid: return False
-        if self.code != other.code: return False
-        if self.data != other.data: return False
-        return True
-
-    def pretty_print(self, q):
-        q.text("bad_action_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("code = ");
-                q.text("%#x" % self.code)
-                q.text(","); q.breakable()
-                q.text("data = ");
-                q.pp(self.data)
-            q.breakable()
-        q.text('}')
-
-error_msg.subtypes[2] = bad_action_error_msg
-
-class bad_instruction_error_msg(error_msg):
-    version = 2
-    type = 1
-    err_type = 3
-
-    def __init__(self, xid=None, code=None, data=None):
-        if xid != None:
-            self.xid = xid
-        else:
-            self.xid = None
-        if code != None:
-            self.code = code
-        else:
-            self.code = 0
-        if data != None:
-            self.data = data
-        else:
-            self.data = ''
-        return
-
-    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(reader):
-        obj = bad_instruction_error_msg()
-        _version = reader.read("!B")[0]
-        assert(_version == 2)
-        _type = reader.read("!B")[0]
-        assert(_type == 1)
-        _length = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_length, 4)
-        obj.xid = reader.read("!L")[0]
-        _err_type = reader.read("!H")[0]
-        assert(_err_type == 3)
-        obj.code = reader.read("!H")[0]
-        obj.data = str(reader.read_all())
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): return False
-        if self.xid != other.xid: return False
-        if self.code != other.code: return False
-        if self.data != other.data: return False
-        return True
-
-    def pretty_print(self, q):
-        q.text("bad_instruction_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("code = ");
-                q.text("%#x" % self.code)
-                q.text(","); q.breakable()
-                q.text("data = ");
-                q.pp(self.data)
-            q.breakable()
-        q.text('}')
-
-error_msg.subtypes[3] = bad_instruction_error_msg
-
-class bad_match_error_msg(error_msg):
-    version = 2
-    type = 1
-    err_type = 4
-
-    def __init__(self, xid=None, code=None, data=None):
-        if xid != None:
-            self.xid = xid
-        else:
-            self.xid = None
-        if code != None:
-            self.code = code
-        else:
-            self.code = 0
-        if data != None:
-            self.data = data
-        else:
-            self.data = ''
-        return
-
-    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(reader):
-        obj = bad_match_error_msg()
-        _version = reader.read("!B")[0]
-        assert(_version == 2)
-        _type = reader.read("!B")[0]
-        assert(_type == 1)
-        _length = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_length, 4)
-        obj.xid = reader.read("!L")[0]
-        _err_type = reader.read("!H")[0]
-        assert(_err_type == 4)
-        obj.code = reader.read("!H")[0]
-        obj.data = str(reader.read_all())
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): return False
-        if self.xid != other.xid: return False
-        if self.code != other.code: return False
-        if self.data != other.data: return False
-        return True
-
-    def pretty_print(self, q):
-        q.text("bad_match_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("code = ");
-                q.text("%#x" % self.code)
-                q.text(","); q.breakable()
-                q.text("data = ");
-                q.pp(self.data)
-            q.breakable()
-        q.text('}')
-
-error_msg.subtypes[4] = bad_match_error_msg
-
-class bad_request_error_msg(error_msg):
-    version = 2
-    type = 1
-    err_type = 1
-
-    def __init__(self, xid=None, code=None, data=None):
-        if xid != None:
-            self.xid = xid
-        else:
-            self.xid = None
-        if code != None:
-            self.code = code
-        else:
-            self.code = 0
-        if data != None:
-            self.data = data
-        else:
-            self.data = ''
-        return
-
-    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(reader):
-        obj = bad_request_error_msg()
-        _version = reader.read("!B")[0]
-        assert(_version == 2)
-        _type = reader.read("!B")[0]
-        assert(_type == 1)
-        _length = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_length, 4)
-        obj.xid = reader.read("!L")[0]
-        _err_type = reader.read("!H")[0]
-        assert(_err_type == 1)
-        obj.code = reader.read("!H")[0]
-        obj.data = str(reader.read_all())
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): return False
-        if self.xid != other.xid: return False
-        if self.code != other.code: return False
-        if self.data != other.data: return False
-        return True
-
-    def pretty_print(self, q):
-        q.text("bad_request_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("code = ");
-                q.text("%#x" % self.code)
-                q.text(","); q.breakable()
-                q.text("data = ");
-                q.pp(self.data)
-            q.breakable()
-        q.text('}')
-
-error_msg.subtypes[1] = bad_request_error_msg
-
-class barrier_reply(message):
-    version = 2
-    type = 21
-
-    def __init__(self, xid=None):
-        if xid != None:
-            self.xid = xid
-        else:
-            self.xid = None
-        return
-
-    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(reader):
-        obj = barrier_reply()
-        _version = reader.read("!B")[0]
-        assert(_version == 2)
-        _type = reader.read("!B")[0]
-        assert(_type == 21)
-        _length = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_length, 4)
-        obj.xid = reader.read("!L")[0]
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): return False
-        if self.xid != other.xid: return False
-        return True
-
-    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('}')
-
-message.subtypes[21] = barrier_reply
-
-class barrier_request(message):
-    version = 2
-    type = 20
-
-    def __init__(self, xid=None):
-        if xid != None:
-            self.xid = xid
-        else:
-            self.xid = None
-        return
-
-    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(reader):
-        obj = barrier_request()
-        _version = reader.read("!B")[0]
-        assert(_version == 2)
-        _type = reader.read("!B")[0]
-        assert(_type == 20)
-        _length = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_length, 4)
-        obj.xid = reader.read("!L")[0]
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): return False
-        if self.xid != other.xid: return False
-        return True
-
-    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('}')
-
-message.subtypes[20] = barrier_request
-
-class experimenter(message):
-    subtypes = {}
-
-    version = 2
-    type = 4
-
-    def __init__(self, xid=None, experimenter=None, data=None):
-        if xid != None:
-            self.xid = xid
-        else:
-            self.xid = None
-        if experimenter != None:
-            self.experimenter = experimenter
-        else:
-            self.experimenter = 0
-        if data != None:
-            self.data = data
-        else:
-            self.data = ''
-        return
-
-    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(self.data)
-        length = sum([len(x) for x in packed])
-        packed[2] = struct.pack("!H", length)
-        return ''.join(packed)
-
-    @staticmethod
-    def unpack(reader):
-        subtype, = reader.peek('!L', 8)
-        subclass = experimenter.subtypes.get(subtype)
-        if subclass:
-            return subclass.unpack(reader)
-
-        obj = experimenter()
-        _version = reader.read("!B")[0]
-        assert(_version == 2)
-        _type = reader.read("!B")[0]
-        assert(_type == 4)
-        _length = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_length, 4)
-        obj.xid = reader.read("!L")[0]
-        obj.experimenter = reader.read("!L")[0]
-        obj.data = str(reader.read_all())
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): return False
-        if self.xid != other.xid: return False
-        if self.experimenter != other.experimenter: return False
-        if self.data != other.data: return False
-        return True
-
-    def pretty_print(self, q):
-        q.text("experimenter {")
-        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('}')
-
-message.subtypes[4] = experimenter
-
-class bsn_header(experimenter):
-    subtypes = {}
-
-    version = 2
-    type = 4
-    experimenter = 6035143
-
-    def __init__(self, xid=None, subtype=None):
-        if xid != None:
-            self.xid = xid
-        else:
-            self.xid = None
-        if subtype != None:
-            self.subtype = subtype
-        else:
-            self.subtype = 0
-        return
-
-    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(reader):
-        subtype, = reader.peek('!L', 12)
-        subclass = bsn_header.subtypes.get(subtype)
-        if subclass:
-            return subclass.unpack(reader)
-
-        obj = bsn_header()
-        _version = reader.read("!B")[0]
-        assert(_version == 2)
-        _type = reader.read("!B")[0]
-        assert(_type == 4)
-        _length = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_length, 4)
-        obj.xid = reader.read("!L")[0]
-        _experimenter = reader.read("!L")[0]
-        assert(_experimenter == 6035143)
-        obj.subtype = reader.read("!L")[0]
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): return False
-        if self.xid != other.xid: return False
-        if self.subtype != other.subtype: return False
-        return True
-
-    def pretty_print(self, q):
-        q.text("bsn_header {")
-        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('}')
-
-experimenter.subtypes[6035143] = bsn_header
-
-class bsn_bw_clear_data_reply(bsn_header):
-    version = 2
-    type = 4
-    experimenter = 6035143
-    subtype = 22
-
-    def __init__(self, xid=None, status=None):
-        if xid != None:
-            self.xid = xid
-        else:
-            self.xid = None
-        if status != None:
-            self.status = status
-        else:
-            self.status = 0
-        return
-
-    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(reader):
-        obj = bsn_bw_clear_data_reply()
-        _version = reader.read("!B")[0]
-        assert(_version == 2)
-        _type = reader.read("!B")[0]
-        assert(_type == 4)
-        _length = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_length, 4)
-        obj.xid = reader.read("!L")[0]
-        _experimenter = reader.read("!L")[0]
-        assert(_experimenter == 6035143)
-        _subtype = reader.read("!L")[0]
-        assert(_subtype == 22)
-        obj.status = reader.read("!L")[0]
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): return False
-        if self.xid != other.xid: return False
-        if self.status != other.status: return False
-        return True
-
-    def pretty_print(self, q):
-        q.text("bsn_bw_clear_data_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("status = ");
-                q.text("%#x" % self.status)
-            q.breakable()
-        q.text('}')
-
-bsn_header.subtypes[22] = bsn_bw_clear_data_reply
-
-class bsn_bw_clear_data_request(bsn_header):
-    version = 2
-    type = 4
-    experimenter = 6035143
-    subtype = 21
-
-    def __init__(self, xid=None):
-        if xid != None:
-            self.xid = xid
-        else:
-            self.xid = None
-        return
-
-    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(reader):
-        obj = bsn_bw_clear_data_request()
-        _version = reader.read("!B")[0]
-        assert(_version == 2)
-        _type = reader.read("!B")[0]
-        assert(_type == 4)
-        _length = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_length, 4)
-        obj.xid = reader.read("!L")[0]
-        _experimenter = reader.read("!L")[0]
-        assert(_experimenter == 6035143)
-        _subtype = reader.read("!L")[0]
-        assert(_subtype == 21)
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): return False
-        if self.xid != other.xid: return False
-        return True
-
-    def pretty_print(self, q):
-        q.text("bsn_bw_clear_data_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('}')
-
-bsn_header.subtypes[21] = bsn_bw_clear_data_request
-
-class bsn_bw_enable_get_reply(bsn_header):
-    version = 2
-    type = 4
-    experimenter = 6035143
-    subtype = 20
-
-    def __init__(self, xid=None, enabled=None):
-        if xid != None:
-            self.xid = xid
-        else:
-            self.xid = None
-        if enabled != None:
-            self.enabled = enabled
-        else:
-            self.enabled = 0
-        return
-
-    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.enabled))
-        length = sum([len(x) for x in packed])
-        packed[2] = struct.pack("!H", length)
-        return ''.join(packed)
-
-    @staticmethod
-    def unpack(reader):
-        obj = bsn_bw_enable_get_reply()
-        _version = reader.read("!B")[0]
-        assert(_version == 2)
-        _type = reader.read("!B")[0]
-        assert(_type == 4)
-        _length = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_length, 4)
-        obj.xid = reader.read("!L")[0]
-        _experimenter = reader.read("!L")[0]
-        assert(_experimenter == 6035143)
-        _subtype = reader.read("!L")[0]
-        assert(_subtype == 20)
-        obj.enabled = reader.read("!L")[0]
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): return False
-        if self.xid != other.xid: return False
-        if self.enabled != other.enabled: return False
-        return True
-
-    def pretty_print(self, q):
-        q.text("bsn_bw_enable_get_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("enabled = ");
-                q.text("%#x" % self.enabled)
-            q.breakable()
-        q.text('}')
-
-bsn_header.subtypes[20] = bsn_bw_enable_get_reply
-
-class bsn_bw_enable_get_request(bsn_header):
-    version = 2
-    type = 4
-    experimenter = 6035143
-    subtype = 19
-
-    def __init__(self, xid=None):
-        if xid != None:
-            self.xid = xid
-        else:
-            self.xid = None
-        return
-
-    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(reader):
-        obj = bsn_bw_enable_get_request()
-        _version = reader.read("!B")[0]
-        assert(_version == 2)
-        _type = reader.read("!B")[0]
-        assert(_type == 4)
-        _length = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_length, 4)
-        obj.xid = reader.read("!L")[0]
-        _experimenter = reader.read("!L")[0]
-        assert(_experimenter == 6035143)
-        _subtype = reader.read("!L")[0]
-        assert(_subtype == 19)
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): return False
-        if self.xid != other.xid: return False
-        return True
-
-    def pretty_print(self, q):
-        q.text("bsn_bw_enable_get_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('}')
-
-bsn_header.subtypes[19] = bsn_bw_enable_get_request
-
-class bsn_bw_enable_set_reply(bsn_header):
-    version = 2
-    type = 4
-    experimenter = 6035143
-    subtype = 23
-
-    def __init__(self, xid=None, enable=None, status=None):
-        if xid != None:
-            self.xid = xid
-        else:
-            self.xid = None
-        if enable != None:
-            self.enable = enable
-        else:
-            self.enable = 0
-        if status != None:
-            self.status = status
-        else:
-            self.status = 0
-        return
-
-    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.enable))
-        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(reader):
-        obj = bsn_bw_enable_set_reply()
-        _version = reader.read("!B")[0]
-        assert(_version == 2)
-        _type = reader.read("!B")[0]
-        assert(_type == 4)
-        _length = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_length, 4)
-        obj.xid = reader.read("!L")[0]
-        _experimenter = reader.read("!L")[0]
-        assert(_experimenter == 6035143)
-        _subtype = reader.read("!L")[0]
-        assert(_subtype == 23)
-        obj.enable = reader.read("!L")[0]
-        obj.status = reader.read("!L")[0]
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): return False
-        if self.xid != other.xid: return False
-        if self.enable != other.enable: return False
-        if self.status != other.status: return False
-        return True
-
-    def pretty_print(self, q):
-        q.text("bsn_bw_enable_set_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("enable = ");
-                q.text("%#x" % self.enable)
-                q.text(","); q.breakable()
-                q.text("status = ");
-                q.text("%#x" % self.status)
-            q.breakable()
-        q.text('}')
-
-bsn_header.subtypes[23] = bsn_bw_enable_set_reply
-
-class bsn_bw_enable_set_request(bsn_header):
-    version = 2
-    type = 4
-    experimenter = 6035143
-    subtype = 18
-
-    def __init__(self, xid=None, enable=None):
-        if xid != None:
-            self.xid = xid
-        else:
-            self.xid = None
-        if enable != None:
-            self.enable = enable
-        else:
-            self.enable = 0
-        return
-
-    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.enable))
-        length = sum([len(x) for x in packed])
-        packed[2] = struct.pack("!H", length)
-        return ''.join(packed)
-
-    @staticmethod
-    def unpack(reader):
-        obj = bsn_bw_enable_set_request()
-        _version = reader.read("!B")[0]
-        assert(_version == 2)
-        _type = reader.read("!B")[0]
-        assert(_type == 4)
-        _length = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_length, 4)
-        obj.xid = reader.read("!L")[0]
-        _experimenter = reader.read("!L")[0]
-        assert(_experimenter == 6035143)
-        _subtype = reader.read("!L")[0]
-        assert(_subtype == 18)
-        obj.enable = reader.read("!L")[0]
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): return False
-        if self.xid != other.xid: return False
-        if self.enable != other.enable: return False
-        return True
-
-    def pretty_print(self, q):
-        q.text("bsn_bw_enable_set_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("enable = ");
-                q.text("%#x" % self.enable)
-            q.breakable()
-        q.text('}')
-
-bsn_header.subtypes[18] = bsn_bw_enable_set_request
-
-class bsn_get_interfaces_reply(bsn_header):
-    version = 2
-    type = 4
-    experimenter = 6035143
-    subtype = 10
-
-    def __init__(self, xid=None, interfaces=None):
-        if xid != None:
-            self.xid = xid
-        else:
-            self.xid = None
-        if interfaces != None:
-            self.interfaces = interfaces
-        else:
-            self.interfaces = []
-        return
-
-    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(loxi.generic_util.pack_list(self.interfaces))
-        length = sum([len(x) for x in packed])
-        packed[2] = struct.pack("!H", length)
-        return ''.join(packed)
-
-    @staticmethod
-    def unpack(reader):
-        obj = bsn_get_interfaces_reply()
-        _version = reader.read("!B")[0]
-        assert(_version == 2)
-        _type = reader.read("!B")[0]
-        assert(_type == 4)
-        _length = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_length, 4)
-        obj.xid = reader.read("!L")[0]
-        _experimenter = reader.read("!L")[0]
-        assert(_experimenter == 6035143)
-        _subtype = reader.read("!L")[0]
-        assert(_subtype == 10)
-        obj.interfaces = loxi.generic_util.unpack_list(reader, ofp.common.bsn_interface.unpack)
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): return False
-        if self.xid != other.xid: return False
-        if self.interfaces != other.interfaces: return False
-        return True
-
-    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('}')
-
-bsn_header.subtypes[10] = bsn_get_interfaces_reply
-
-class bsn_get_interfaces_request(bsn_header):
-    version = 2
-    type = 4
-    experimenter = 6035143
-    subtype = 9
-
-    def __init__(self, xid=None):
-        if xid != None:
-            self.xid = xid
-        else:
-            self.xid = None
-        return
-
-    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(reader):
-        obj = bsn_get_interfaces_request()
-        _version = reader.read("!B")[0]
-        assert(_version == 2)
-        _type = reader.read("!B")[0]
-        assert(_type == 4)
-        _length = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_length, 4)
-        obj.xid = reader.read("!L")[0]
-        _experimenter = reader.read("!L")[0]
-        assert(_experimenter == 6035143)
-        _subtype = reader.read("!L")[0]
-        assert(_subtype == 9)
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): return False
-        if self.xid != other.xid: return False
-        return True
-
-    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('}')
-
-bsn_header.subtypes[9] = bsn_get_interfaces_request
-
-class bsn_get_mirroring_reply(bsn_header):
-    version = 2
-    type = 4
-    experimenter = 6035143
-    subtype = 5
-
-    def __init__(self, xid=None, report_mirror_ports=None):
-        if xid != None:
-            self.xid = xid
-        else:
-            self.xid = None
-        if report_mirror_ports != None:
-            self.report_mirror_ports = report_mirror_ports
-        else:
-            self.report_mirror_ports = 0
-        return
-
-    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('\x00' * 3)
-        length = sum([len(x) for x in packed])
-        packed[2] = struct.pack("!H", length)
-        return ''.join(packed)
-
-    @staticmethod
-    def unpack(reader):
-        obj = bsn_get_mirroring_reply()
-        _version = reader.read("!B")[0]
-        assert(_version == 2)
-        _type = reader.read("!B")[0]
-        assert(_type == 4)
-        _length = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_length, 4)
-        obj.xid = reader.read("!L")[0]
-        _experimenter = reader.read("!L")[0]
-        assert(_experimenter == 6035143)
-        _subtype = reader.read("!L")[0]
-        assert(_subtype == 5)
-        obj.report_mirror_ports = reader.read("!B")[0]
-        reader.skip(3)
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): return False
-        if self.xid != other.xid: return False
-        if self.report_mirror_ports != other.report_mirror_ports: return False
-        return True
-
-    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.breakable()
-        q.text('}')
-
-bsn_header.subtypes[5] = bsn_get_mirroring_reply
-
-class bsn_get_mirroring_request(bsn_header):
-    version = 2
-    type = 4
-    experimenter = 6035143
-    subtype = 4
-
-    def __init__(self, xid=None, report_mirror_ports=None):
-        if xid != None:
-            self.xid = xid
-        else:
-            self.xid = None
-        if report_mirror_ports != None:
-            self.report_mirror_ports = report_mirror_ports
-        else:
-            self.report_mirror_ports = 0
-        return
-
-    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('\x00' * 3)
-        length = sum([len(x) for x in packed])
-        packed[2] = struct.pack("!H", length)
-        return ''.join(packed)
-
-    @staticmethod
-    def unpack(reader):
-        obj = bsn_get_mirroring_request()
-        _version = reader.read("!B")[0]
-        assert(_version == 2)
-        _type = reader.read("!B")[0]
-        assert(_type == 4)
-        _length = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_length, 4)
-        obj.xid = reader.read("!L")[0]
-        _experimenter = reader.read("!L")[0]
-        assert(_experimenter == 6035143)
-        _subtype = reader.read("!L")[0]
-        assert(_subtype == 4)
-        obj.report_mirror_ports = reader.read("!B")[0]
-        reader.skip(3)
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): return False
-        if self.xid != other.xid: return False
-        if self.report_mirror_ports != other.report_mirror_ports: return False
-        return True
-
-    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.breakable()
-        q.text('}')
-
-bsn_header.subtypes[4] = bsn_get_mirroring_request
-
-class bsn_pdu_rx_reply(bsn_header):
-    version = 2
-    type = 4
-    experimenter = 6035143
-    subtype = 34
-
-    def __init__(self, xid=None, status=None, port_no=None, slot_num=None):
-        if xid != None:
-            self.xid = xid
-        else:
-            self.xid = None
-        if status != None:
-            self.status = status
-        else:
-            self.status = 0
-        if port_no != None:
-            self.port_no = port_no
-        else:
-            self.port_no = 0
-        if slot_num != None:
-            self.slot_num = slot_num
-        else:
-            self.slot_num = 0
-        return
-
-    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))
-        packed.append(util.pack_port_no(self.port_no))
-        packed.append(struct.pack("!B", self.slot_num))
-        length = sum([len(x) for x in packed])
-        packed[2] = struct.pack("!H", length)
-        return ''.join(packed)
-
-    @staticmethod
-    def unpack(reader):
-        obj = bsn_pdu_rx_reply()
-        _version = reader.read("!B")[0]
-        assert(_version == 2)
-        _type = reader.read("!B")[0]
-        assert(_type == 4)
-        _length = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_length, 4)
-        obj.xid = reader.read("!L")[0]
-        _experimenter = reader.read("!L")[0]
-        assert(_experimenter == 6035143)
-        _subtype = reader.read("!L")[0]
-        assert(_subtype == 34)
-        obj.status = reader.read("!L")[0]
-        obj.port_no = util.unpack_port_no(reader)
-        obj.slot_num = reader.read("!B")[0]
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): return False
-        if self.xid != other.xid: return False
-        if self.status != other.status: return False
-        if self.port_no != other.port_no: return False
-        if self.slot_num != other.slot_num: return False
-        return True
-
-    def pretty_print(self, q):
-        q.text("bsn_pdu_rx_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("status = ");
-                q.text("%#x" % self.status)
-                q.text(","); q.breakable()
-                q.text("port_no = ");
-                q.text(util.pretty_port(self.port_no))
-                q.text(","); q.breakable()
-                q.text("slot_num = ");
-                q.text("%#x" % self.slot_num)
-            q.breakable()
-        q.text('}')
-
-bsn_header.subtypes[34] = bsn_pdu_rx_reply
-
-class bsn_pdu_rx_request(bsn_header):
-    version = 2
-    type = 4
-    experimenter = 6035143
-    subtype = 33
-
-    def __init__(self, xid=None, timeout_ms=None, port_no=None, slot_num=None, data=None):
-        if xid != None:
-            self.xid = xid
-        else:
-            self.xid = None
-        if timeout_ms != None:
-            self.timeout_ms = timeout_ms
-        else:
-            self.timeout_ms = 0
-        if port_no != None:
-            self.port_no = port_no
-        else:
-            self.port_no = 0
-        if slot_num != None:
-            self.slot_num = slot_num
-        else:
-            self.slot_num = 0
-        if data != None:
-            self.data = data
-        else:
-            self.data = ''
-        return
-
-    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.timeout_ms))
-        packed.append(util.pack_port_no(self.port_no))
-        packed.append(struct.pack("!B", self.slot_num))
-        packed.append('\x00' * 3)
-        packed.append(self.data)
-        length = sum([len(x) for x in packed])
-        packed[2] = struct.pack("!H", length)
-        return ''.join(packed)
-
-    @staticmethod
-    def unpack(reader):
-        obj = bsn_pdu_rx_request()
-        _version = reader.read("!B")[0]
-        assert(_version == 2)
-        _type = reader.read("!B")[0]
-        assert(_type == 4)
-        _length = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_length, 4)
-        obj.xid = reader.read("!L")[0]
-        _experimenter = reader.read("!L")[0]
-        assert(_experimenter == 6035143)
-        _subtype = reader.read("!L")[0]
-        assert(_subtype == 33)
-        obj.timeout_ms = reader.read("!L")[0]
-        obj.port_no = util.unpack_port_no(reader)
-        obj.slot_num = reader.read("!B")[0]
-        reader.skip(3)
-        obj.data = str(reader.read_all())
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): return False
-        if self.xid != other.xid: return False
-        if self.timeout_ms != other.timeout_ms: return False
-        if self.port_no != other.port_no: return False
-        if self.slot_num != other.slot_num: return False
-        if self.data != other.data: return False
-        return True
-
-    def pretty_print(self, q):
-        q.text("bsn_pdu_rx_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("timeout_ms = ");
-                q.text("%#x" % self.timeout_ms)
-                q.text(","); q.breakable()
-                q.text("port_no = ");
-                q.text(util.pretty_port(self.port_no))
-                q.text(","); q.breakable()
-                q.text("slot_num = ");
-                q.text("%#x" % self.slot_num)
-                q.text(","); q.breakable()
-                q.text("data = ");
-                q.pp(self.data)
-            q.breakable()
-        q.text('}')
-
-bsn_header.subtypes[33] = bsn_pdu_rx_request
-
-class bsn_pdu_rx_timeout(bsn_header):
-    version = 2
-    type = 4
-    experimenter = 6035143
-    subtype = 35
-
-    def __init__(self, xid=None, port_no=None, slot_num=None):
-        if xid != None:
-            self.xid = xid
-        else:
-            self.xid = None
-        if port_no != None:
-            self.port_no = port_no
-        else:
-            self.port_no = 0
-        if slot_num != None:
-            self.slot_num = slot_num
-        else:
-            self.slot_num = 0
-        return
-
-    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(util.pack_port_no(self.port_no))
-        packed.append(struct.pack("!B", self.slot_num))
-        length = sum([len(x) for x in packed])
-        packed[2] = struct.pack("!H", length)
-        return ''.join(packed)
-
-    @staticmethod
-    def unpack(reader):
-        obj = bsn_pdu_rx_timeout()
-        _version = reader.read("!B")[0]
-        assert(_version == 2)
-        _type = reader.read("!B")[0]
-        assert(_type == 4)
-        _length = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_length, 4)
-        obj.xid = reader.read("!L")[0]
-        _experimenter = reader.read("!L")[0]
-        assert(_experimenter == 6035143)
-        _subtype = reader.read("!L")[0]
-        assert(_subtype == 35)
-        obj.port_no = util.unpack_port_no(reader)
-        obj.slot_num = reader.read("!B")[0]
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): return False
-        if self.xid != other.xid: return False
-        if self.port_no != other.port_no: return False
-        if self.slot_num != other.slot_num: return False
-        return True
-
-    def pretty_print(self, q):
-        q.text("bsn_pdu_rx_timeout {")
-        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("slot_num = ");
-                q.text("%#x" % self.slot_num)
-            q.breakable()
-        q.text('}')
-
-bsn_header.subtypes[35] = bsn_pdu_rx_timeout
-
-class bsn_pdu_tx_reply(bsn_header):
-    version = 2
-    type = 4
-    experimenter = 6035143
-    subtype = 32
-
-    def __init__(self, xid=None, status=None, port_no=None, slot_num=None):
-        if xid != None:
-            self.xid = xid
-        else:
-            self.xid = None
-        if status != None:
-            self.status = status
-        else:
-            self.status = 0
-        if port_no != None:
-            self.port_no = port_no
-        else:
-            self.port_no = 0
-        if slot_num != None:
-            self.slot_num = slot_num
-        else:
-            self.slot_num = 0
-        return
-
-    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))
-        packed.append(util.pack_port_no(self.port_no))
-        packed.append(struct.pack("!B", self.slot_num))
-        length = sum([len(x) for x in packed])
-        packed[2] = struct.pack("!H", length)
-        return ''.join(packed)
-
-    @staticmethod
-    def unpack(reader):
-        obj = bsn_pdu_tx_reply()
-        _version = reader.read("!B")[0]
-        assert(_version == 2)
-        _type = reader.read("!B")[0]
-        assert(_type == 4)
-        _length = reader.read("!H")[0]
-        orig_reader = reader
-        reader = orig_reader.slice(_length, 4)
-        obj.xid = reader.read("!L")[0]
-        _experimenter = reader.read("!L")[0]
-        assert(_experimenter == 6035143)
-        _subtype = reader.read("!L")[0]
-        assert(_subtype == 32)
-        obj.status = reader.read("!L")[0]
-        obj.port_no = util.unpack_port_no(reader)
-        obj.slot_num = reader.read("!B")[0]
-        return obj
-
-    def __eq__(self, other):
-        if type(self) != type(other): return False
-        if self.xid != other.xid: return False
-        if self.status != other.status: return False
-        if self.port_no != other.port_no: return False
-        if self.slot_num != other.slot_num: return False
-        return True
-
-    def pretty_print(self, q):
-        q.text("bsn_pdu_tx_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("status = ");
-                q.text("%#x" % self.status)
-                q.text(","); q.breakable()
-                q.text("port_no = ");
-                q.text(util.pretty_port(self.port_no))
-                q.text(","); q.breakable()
-                q.text("slot_num = ");
-                q.text("%#x" % self.slot_num)
-            q.breakable()
-        q.text('}')
-
-bsn_header.subtypes[32] = bsn_pdu_tx_reply
-
-class bsn_pdu_tx_request(bsn_header):
-    version = 2
-    type = 4
-    experimenter = 6035143
-    subtype = 31
-
-    def __init__(self, xid=None, tx_interval_ms=None, port_no=None, slot_num=None, data=None):
-        if xid != None:
-            self.xid = xid
-        else:
-            self.xid = None
-        if tx_interval_ms != None:
-            self.tx_interval_ms = tx_interval_ms
-        else:
-            self.tx_interval_ms = 0
-        if port_no != None:
-            self.port_no = port_no
-        else:
-            self.port_no = 0
-        if slot_num != None:
-            self.slot_num = slot_num
-        else:
-            self.slot_num = 0
-        if data != None:
-            self.data = data
-        else:
-            self.data = ''
-        return
-
-    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.tx_interval_ms))
-        packed.append(util.pack_port_no(self.port_no))
-        packed.append(struct.pack("!B", self.slot_num))
-        packed.append('\x00' * 3)
-        packed.append(self.data)
-        length = sum([len(x) for x in packed])
-        packed[2] = struct.pack("!H", length)
-        return ''.join(packed)
-
-    @staticmethod
-    def unpack(reader):
-        obj = bsn_pdu_tx_request()
-        _version = reader.read("!B")[0]
-        assert(_version == 2)
-        _type = reader.read("!B")[0]
-        assert(_type == 4)
-        _length = reader.read("!H")[