add basic OF 1.3 tests
Many of these tests were ported from the CPqD fork of oftest.
I've been running them against ofsoftswitch13. All pass except for
PacketInMiss.
diff --git a/tests-1.3/basic.py b/tests-1.3/basic.py
index f096940..37618ae 100644
--- a/tests-1.3/basic.py
+++ b/tests-1.3/basic.py
@@ -1,9 +1,16 @@
+# Distributed under the OpenFlow Software License (see LICENSE)
+# Copyright (c) 2010 The Board of Trustees of The Leland Stanford Junior University
+# Copyright (c) 2012, 2013 Big Switch Networks, Inc.
+# Copyright (c) 2012, 2013 CPqD
+# Copyright (c) 2012, 2013 Ericsson
"""
Basic test cases
Test cases in other modules depend on this functionality.
"""
+import logging
+
from oftest import config
import oftest.base_tests as base_tests
import ofp
@@ -25,3 +32,446 @@
self.assertEqual(request.xid, response.xid,
'response xid != request xid')
self.assertEqual(len(response.data), 0, 'response data non-empty')
+
+class EchoWithData(base_tests.SimpleProtocol):
+ """
+ Test echo response with short string data
+ """
+ def runTest(self):
+ data = 'OpenFlow Will Rule The World'
+ request = ofp.message.echo_request(data=data)
+ response, _ = self.controller.transact(request)
+ self.assertTrue(response is not None,
+ "Did not get echo reply")
+ self.assertEqual(response.type, ofp.OFPT_ECHO_REPLY,
+ 'response is not echo_reply')
+ self.assertEqual(request.xid, response.xid,
+ 'response xid != request xid')
+ self.assertEqual(request.data, response.data,
+ 'response data != request data')
+
+class FeaturesRequest(base_tests.SimpleProtocol):
+ """
+ Test features_request to make sure we get a response
+
+ Does NOT test the contents; just that we get a response
+ """
+ def runTest(self):
+ request = ofp.message.features_request()
+ response,_ = self.controller.transact(request)
+ self.assertTrue(response is not None,
+ 'Did not get features reply')
+
+class OutputExact(base_tests.SimpleDataPlane):
+ """
+ Test output function for an exact-match flow
+
+ For each port A, adds a flow directing matching packets to that port.
+ Then, for all other ports B, verifies that sending a matching packet
+ to B results in an output to A.
+ """
+ def runTest(self):
+ ports = sorted(config["port_map"].keys())
+
+ delete_all_flows(self.controller)
+
+ parsed_pkt = simple_tcp_packet()
+ pkt = str(parsed_pkt)
+ match = packet_to_flow_match(self, parsed_pkt)
+
+ for out_port in ports:
+ request = ofp.message.flow_add(
+ table_id=0,
+ cookie=42,
+ match=match,
+ instructions=[
+ ofp.instruction.apply_actions(
+ actions=[
+ ofp.action.output(
+ port=out_port,
+ max_len=ofp.OFPCML_NO_BUFFER)])],
+ buffer_id=0xffffffff,
+ priority=1000)
+
+ logging.info("Inserting flow sending matching packets to port %d", out_port)
+ self.controller.message_send(request)
+ do_barrier(self.controller)
+
+ for in_port in ports:
+ if in_port == out_port:
+ continue
+ logging.info("OutputExact test, ports %d to %d", in_port, out_port)
+ self.dataplane.send(in_port, pkt)
+ receive_pkt_verify(self, [out_port], pkt, in_port)
+
+class PacketInExact(base_tests.SimpleDataPlane):
+ """
+ Test packet in function for an exact-match flow
+
+ Send a packet to each dataplane port and verify that a packet
+ in message is received from the controller for each
+ """
+ def runTest(self):
+ delete_all_flows(self.controller)
+
+ parsed_pkt = simple_tcp_packet()
+ pkt = str(parsed_pkt)
+ match = packet_to_flow_match(self, parsed_pkt)
+
+ request = ofp.message.flow_add(
+ table_id=0,
+ cookie=42,
+ match=match,
+ instructions=[
+ ofp.instruction.apply_actions(
+ actions=[
+ ofp.action.output(
+ port=ofp.OFPP_CONTROLLER,
+ max_len=ofp.OFPCML_NO_BUFFER)])],
+ buffer_id=0xffffffff,
+ priority=1000)
+
+ logging.info("Inserting flow sending matching packets to controller")
+ self.controller.message_send(request)
+ do_barrier(self.controller)
+
+ for of_port in config["port_map"].keys():
+ logging.info("PacketInExact test, port %d", of_port)
+ self.dataplane.send(of_port, pkt)
+ verify_packet_in(self, pkt, of_port, ofp.OFPR_ACTION)
+
+class PacketInMiss(base_tests.SimpleDataPlane):
+ """
+ Test packet in function for a table-miss flow
+
+ Send a packet to each dataplane port and verify that a packet
+ in message is received from the controller for each
+ """
+ def runTest(self):
+ delete_all_flows(self.controller)
+
+ parsed_pkt = simple_tcp_packet()
+ pkt = str(parsed_pkt)
+
+ request = ofp.message.flow_add(
+ table_id=0,
+ cookie=42,
+ instructions=[
+ ofp.instruction.apply_actions(
+ actions=[
+ ofp.action.output(
+ port=ofp.OFPP_CONTROLLER,
+ max_len=ofp.OFPCML_NO_BUFFER)])],
+ buffer_id=0xffffffff,
+ priority=0)
+
+ logging.info("Inserting table-miss flow sending all packets to controller")
+ self.controller.message_send(request)
+ do_barrier(self.controller)
+
+ for of_port in config["port_map"].keys():
+ logging.info("PacketInMiss test, port %d", of_port)
+ self.dataplane.send(of_port, pkt)
+ verify_packet_in(self, pkt, of_port, ofp.OFPR_NO_MATCH)
+
+class PacketOut(base_tests.SimpleDataPlane):
+ """
+ Test packet out function
+
+ Send packet out message to controller for each dataplane port and
+ verify the packet appears on the appropriate dataplane port
+ """
+ def runTest(self):
+ pkt = str(simple_tcp_packet())
+
+ for of_port in config["port_map"].keys():
+ msg = ofp.message.packet_out(
+ in_port=ofp.OFPP_CONTROLLER,
+ actions=[ofp.action.output(port=of_port)],
+ buffer_id=ofp.OFP_NO_BUFFER,
+ data=pkt)
+
+ logging.info("PacketOut test, port %d", of_port)
+ self.controller.message_send(msg)
+ receive_pkt_verify(self, [of_port], pkt, ofp.OFPP_CONTROLLER)
+
+class FlowRemoveAll(base_tests.SimpleProtocol):
+ """
+ Remove all flows; required for almost all tests
+
+ Add a bunch of flows, remove them, and then make sure there are no flows left
+ This is an intentionally naive test to see if the baseline functionality works
+ and should be a precondition to any more complicated deletion test (e.g.,
+ delete_strict vs. delete)
+ """
+ def runTest(self):
+ for i in range(1,5):
+ logging.debug("Adding flow %d", i)
+ request = ofp.message.flow_add(
+ buffer_id=ofp.OFP_NO_BUFFER,
+ priority=i*1000)
+ self.controller.message_send(request)
+ do_barrier(self.controller)
+
+ delete_all_flows(self.controller)
+
+ logging.info("Sending flow stats request")
+ stats = get_flow_stats(self, ofp.match())
+ self.assertEqual(len(stats), 0, "Expected empty flow stats reply")
+
+
+## Multipart messages
+
+class DescStats(base_tests.SimpleProtocol):
+ """
+ Switch description multipart transaction
+
+ Only verifies we get a single reply.
+ """
+ def runTest(self):
+ request = ofp.message.desc_stats_request()
+ logging.info("Sending desc stats request")
+ response, _ = self.controller.transact(request)
+ self.assertTrue(response != None, "No response to desc stats request")
+ logging.info(response.show())
+ self.assertEquals(response.flags, 0, "Unexpected bit set in desc stats reply flags")
+
+class FlowStats(base_tests.SimpleProtocol):
+ """
+ Flow stats multipart transaction
+
+ Only verifies we get a reply.
+ """
+ def runTest(self):
+ logging.info("Sending flow stats request")
+ stats = get_flow_stats(self, ofp.match())
+ logging.info("Received %d flow stats entries", len(stats))
+ for entry in stats:
+ logging.info(entry.show())
+
+class AggregateStats(base_tests.SimpleProtocol):
+ """
+ Aggregate flow stats multipart transaction
+
+ Only verifies we get a single reply.
+ """
+ def runTest(self):
+ request = ofp.message.aggregate_stats_request(
+ table_id=ofp.OFPTT_ALL,
+ out_port=ofp.OFPP_ANY,
+ out_group=ofp.OFPG_ANY,
+ cookie=0,
+ cookie_mask=0)
+ logging.info("Sending aggregate flow stats request")
+ response, _ = self.controller.transact(request)
+ self.assertTrue(response != None, "No response to aggregate stats request")
+ logging.info(response.show())
+ self.assertEquals(response.flags, 0, "Unexpected bit set in aggregate stats reply flags")
+
+class TableStats(base_tests.SimpleProtocol):
+ """
+ Table stats multipart transaction
+
+ Only verifies we get a reply.
+ """
+ def runTest(self):
+ logging.info("Sending table stats request")
+ stats = get_stats(self, ofp.message.table_stats_request())
+ logging.info("Received %d table stats entries", len(stats))
+ for entry in stats:
+ logging.info(entry.show())
+
+class PortStats(base_tests.SimpleProtocol):
+ """
+ Port stats multipart transaction
+
+ Only verifies we get a reply.
+ """
+ def runTest(self):
+ request = ofp.message.port_stats_request(port_no=ofp.OFPP_ANY)
+ logging.info("Sending port stats request")
+ stats = get_stats(self, request)
+ logging.info("Received %d port stats entries", len(stats))
+ for entry in stats:
+ logging.info(entry.show())
+
+class QueueStats(base_tests.SimpleProtocol):
+ """
+ Queue stats multipart transaction
+
+ Only verifies we get a reply.
+ """
+ def runTest(self):
+ request = ofp.message.queue_stats_request(port_no=ofp.OFPP_ANY,
+ queue_id=ofp.OFPQ_ALL)
+ logging.info("Sending queue stats request")
+ stats = get_stats(self, request)
+ logging.info("Received %d queue stats entries", len(stats))
+ for entry in stats:
+ logging.info(entry.show())
+
+class GroupStats(base_tests.SimpleProtocol):
+ """
+ Group stats multipart transaction
+
+ Only verifies we get a reply.
+ """
+ def runTest(self):
+ request = ofp.message.group_stats_request(group_id=ofp.OFPG_ALL)
+ logging.info("Sending group stats request")
+ stats = get_stats(self, request)
+ logging.info("Received %d group stats entries", len(stats))
+ for entry in stats:
+ logging.info(entry.show())
+
+class GroupDescStats(base_tests.SimpleProtocol):
+ """
+ Group description multipart transaction
+
+ Only verifies we get a reply.
+ """
+ def runTest(self):
+ request = ofp.message.group_desc_stats_request()
+ logging.info("Sending group desc stats request")
+ stats = get_stats(self, request)
+ logging.info("Received %d group desc stats entries", len(stats))
+ for entry in stats:
+ logging.info(entry.show())
+
+class GroupFeaturesStats(base_tests.SimpleProtocol):
+ """
+ Group features multipart transaction
+
+ Only verifies we get a single reply.
+ """
+ def runTest(self):
+ request = ofp.message.group_features_stats_request()
+ logging.info("Sending group features stats request")
+ response, _ = self.controller.transact(request)
+ self.assertTrue(response != None, "No response to group features stats request")
+ logging.info(response.show())
+ self.assertEquals(response.flags, 0, "Unexpected bit set in group features stats reply flags")
+
+class MeterStats(base_tests.SimpleProtocol):
+ """
+ Meter stats multipart transaction
+
+ Only verifies we get a reply.
+ """
+ def runTest(self):
+ request = ofp.message.meter_stats_request(meter_id=ofp.OFPM_ALL)
+ logging.info("Sending meter stats request")
+ stats = get_stats(self, request)
+ logging.info("Received %d meter stats entries", len(stats))
+ for entry in stats:
+ logging.info(entry.show())
+
+class MeterConfigStats(base_tests.SimpleProtocol):
+ """
+ Meter config multipart transaction
+
+ Only verifies we get a reply.
+ """
+ def runTest(self):
+ request = ofp.message.meter_config_stats_request(meter_id=ofp.OFPM_ALL)
+ logging.info("Sending meter config stats request")
+ stats = get_stats(self, request)
+ logging.info("Received %d meter config stats entries", len(stats))
+ for entry in stats:
+ logging.info(entry.show())
+
+class MeterFeaturesStats(base_tests.SimpleProtocol):
+ """
+ Meter features multipart transaction
+
+ Only verifies we get a single reply.
+ """
+ def runTest(self):
+ request = ofp.message.meter_features_stats_request()
+ logging.info("Sending meter features stats request")
+ response, _ = self.controller.transact(request)
+ self.assertTrue(response != None, "No response to meter features stats request")
+ logging.info(response.show())
+ self.assertEquals(response.flags, 0, "Unexpected bit set in meter features stats reply flags")
+
+@disabled # pyloxi does not yet support table features
+class TableFeaturesStats(base_tests.SimpleProtocol):
+ """
+ Table features multipart transaction
+
+ Only verifies we get a reply.
+ """
+ def runTest(self):
+ logging.info("Sending table features stats request")
+ stats = get_stats(self, ofp.message.table_features_stats_request())
+ logging.info("Received %d table features stats entries", len(stats))
+ for entry in stats:
+ logging.info(entry.show())
+
+class PortDescStats(base_tests.SimpleProtocol):
+ """
+ Port description multipart transaction
+
+ Only verifies we get a reply.
+ """
+ def runTest(self):
+ logging.info("Sending port desc stats request")
+ stats = get_stats(self, ofp.message.port_desc_stats_request())
+ logging.info("Received %d port desc stats entries", len(stats))
+ for entry in stats:
+ logging.info(entry.show())
+
+class PortConfigMod(base_tests.SimpleProtocol):
+ """
+ Modify a bit in port config and verify changed
+
+ Get the switch configuration, modify the port configuration
+ and write it back; get the config again and verify changed.
+ Then set it back to the way it was.
+ """
+
+ def runTest(self):
+ logging.info("Running " + str(self))
+ for of_port, _ in config["port_map"].items(): # Grab first port
+ break
+
+ (_, config1, _) = \
+ port_config_get(self.controller, of_port)
+ self.assertTrue(config is not None, "Did not get port config")
+
+ logging.debug("No flood bit port " + str(of_port) + " is now " +
+ str(config1 & ofp.OFPPC_NO_PACKET_IN))
+
+ rv = port_config_set(self.controller, of_port,
+ config1 ^ ofp.OFPPC_NO_PACKET_IN,
+ ofp.OFPPC_NO_PACKET_IN)
+ self.assertTrue(rv != -1, "Error sending port mod")
+
+ # Verify change took place with same feature request
+ (_, config2, _) = port_config_get(self.controller, of_port)
+ self.assertTrue(config2 is not None, "Did not get port config2")
+ logging.debug("No packet_in bit port " + str(of_port) + " is now " +
+ str(config2 & ofp.OFPPC_NO_PACKET_IN))
+ self.assertTrue(config2 & ofp.OFPPC_NO_PACKET_IN !=
+ config1 & ofp.OFPPC_NO_PACKET_IN,
+ "Bit change did not take")
+ # Set it back
+ rv = port_config_set(self.controller, of_port, config1,
+ ofp.OFPPC_NO_PACKET_IN)
+ self.assertTrue(rv != -1, "Error sending port mod")
+
+class AsyncConfigGet(base_tests.SimpleProtocol):
+ """
+ Verify initial async config
+
+ Other tests rely on connections starting with these values.
+ """
+
+ def runTest(self):
+ logging.info("Sending get async config request")
+ response, _ = self.controller.transact(ofp.message.async_get_request())
+ self.assertTrue(response != None, "No response to get async config request")
+ logging.info(response.show())
+ self.assertEquals(response.packet_in_mask_equal_master & 0x07, 0x07)
+ self.assertEquals(response.port_status_mask_equal_master & 0x07, 0x07)
+ self.assertEquals(response.flow_removed_mask_equal_master & 0x0f, 0x0f)