loxi-prep: rewrite vendor tests to use pyloxi message classes
diff --git a/tests/bsn_ipmask.py b/tests/bsn_ipmask.py
index e640089..8dd603a 100644
--- a/tests/bsn_ipmask.py
+++ b/tests/bsn_ipmask.py
@@ -47,9 +47,7 @@
given wildcard index
"""
logging.info("Setting index %d to mask is %s" % (index, mask))
- m = ofp.message.vendor()
- m.vendor = 0x005c16c7
- m.data = struct.pack("!LBBBBL", 0, index, 0, 0, 0, mask)
+ m = ofp.message.bsn_set_ip_mask(index=index, mask=mask)
self.controller.message_send(m)
def bsn_get_ip_mask(self, index):
@@ -57,16 +55,11 @@
Use the BSN_GET_IP_MASK_REQUEST vendor command to get the current IP mask
for the given wildcard index
"""
- m = ofp.message.vendor()
- m.vendor = 0x005c16c7
- m.data = struct.pack( "!LBBBBL", 1, index, 0, 0, 0, 0 )
- self.controller.message_send(m)
- m, r = self.controller.poll(ofp.OFPT_VENDOR)
- self.assertEqual(m.vendor, 0x005c16c7, "Wrong vendor ID")
- x = struct.unpack("!LBBBBL", m.data)
- self.assertEqual(x[0], 2, "Wrong subtype")
- self.assertEqual(x[1], index, "Wrong index")
- return x[5]
+ request = ofp.message.bsn_get_ip_mask_request(index=index)
+ reply, _ = self.controller.transact(request)
+ self.assertTrue(isinstance(reply, ofp.message.bsn_get_ip_mask_reply), "Wrong reply type")
+ self.assertEqual(reply.index, index, "Wrong index")
+ return reply.mask
def runTest(self):
self.assertFalse(required_wildcards(self) & ofp.OFPFW_NW_DST_ALL,
diff --git a/tests/bsn_mirror.py b/tests/bsn_mirror.py
index 4a6e970..4e4343d 100644
--- a/tests/bsn_mirror.py
+++ b/tests/bsn_mirror.py
@@ -23,9 +23,7 @@
Use the BSN_SET_MIRRORING vendor command to enable/disable
mirror action support
"""
- m = ofp.message.vendor()
- m.vendor = 0x005c16c7
- m.data = struct.pack("!LBBBB", 3, enabled, 0, 0, 0)
+ m = ofp.message.bsn_set_mirroring(report_mirror_ports=enabled)
self.controller.message_send(m)
def bsn_get_mirroring(self):
@@ -33,15 +31,10 @@
Use the BSN_GET_MIRRORING_REQUEST vendor command to get the
enabled/disabled state of mirror action support
"""
- m = ofp.message.vendor()
- m.vendor = 0x005c16c7
- m.data = struct.pack("!LBBBB", 4, 0, 0, 0, 0)
- self.controller.message_send(m)
- m, r = self.controller.poll(ofp.OFPT_VENDOR, 2)
- self.assertEqual(m.vendor, 0x005c16c7, "Wrong vendor ID")
- x = struct.unpack("!LBBBB", m.data)
- self.assertEqual(x[0], 5, "Wrong subtype")
- return x[1]
+ request = ofp.message.bsn_get_mirroring_request()
+ reply, _ = self.controller.transact(request)
+ self.assertTrue(isinstance(reply, ofp.message.bsn_get_mirroring_reply), "Unexpected reply type")
+ return reply.report_mirror_ports
def runTest(self):
mirror_ports = test_param_get("mirror_ports")
diff --git a/tests/bsn_shell.py b/tests/bsn_shell.py
index 8886c80..2ac2f08 100644
--- a/tests/bsn_shell.py
+++ b/tests/bsn_shell.py
@@ -22,23 +22,17 @@
Use the BSN_SHELL_COMMAND vendor command to run the given command
and receive the output
"""
- m = ofp.message.vendor()
- m.vendor = 0x005c16c7
- m.data = struct.pack("!LL", 6, 0) + cmd
- rc = self.controller.message_send(m)
- self.assertNotEqual(rc, -1, "Error sending shell command")
+ m = ofp.message.bsn_shell_command(service=0, data=cmd)
+ self.controller.message_send(m)
out = ""
while True:
- m, r = self.controller.poll(ofp.OFPT_VENDOR, 60)
- self.assertEqual(m.vendor, 0x005c16c7, "Wrong vendor ID")
- subtype = struct.unpack("!L", m.data[:4])[0]
- if subtype == 7:
- out += m.data[4:]
- elif subtype == 8:
- status = struct.unpack("!LL", m.data)[1]
- return status, out
+ m, _ = self.controller.poll(ofp.OFPT_VENDOR, 60)
+ if isinstance(m, ofp.message.bsn_shell_output):
+ out += m.data
+ elif isinstance(m, ofp.message.bsn_shell_status):
+ return m.status, out
else:
- assert False, "Wrong subtype"
+ raise AssertionError("Unexpected message received")
def runTest(self):
status, out = self.bsn_shell_command("echo _one space_")
diff --git a/tests/nicira_role.py b/tests/nicira_role.py
index 24606a2..1122a7b 100644
--- a/tests/nicira_role.py
+++ b/tests/nicira_role.py
@@ -11,12 +11,7 @@
from oftest.testutils import *
-# Nicira vendor extension constants
-NXT_VENDOR = 0x00002320
-
-NXT_ROLE_REQUEST = 10
-
-NXT_ROLE_VALUE = dict( other=0, slave=1, master=2 )
+NX_ROLE_MASTER = 2
@nonstandard
class NiciraRoleRequest(base_tests.SimpleDataPlane):
@@ -24,21 +19,10 @@
Exercise Nicira vendor extension for requesting HA roles
"""
- def nicira_role_request(self, role):
- """
- Use the BSN_SET_IP_MASK vendor command to change the IP mask for the
- given wildcard index
- """
- logging.info("Sending role request %s" % role)
- m = ofp.message.vendor()
- m.vendor = NXT_VENDOR
- m.data = struct.pack("!LL", NXT_ROLE_REQUEST, NXT_ROLE_VALUE[role])
- return m
-
def runTest(self):
'''
For now, we only verify that a response is received.
'''
- request = self.nicira_role_request("master")
+ request = ofp.message.nicira_controller_role_request(role=NX_ROLE_MASTER)
response, pkt = self.controller.transact(request)
self.assertTrue(response is not None, "No reply to Nicira role request")