blob: c4d8036353e919838593a0de1b9b2395820d252b [file] [log] [blame]
Dan Talaycodba244e2010-02-15 14:08:53 -08001"""
Dan Talayco79f36082010-03-11 16:53:53 -08002Basic protocol and dataplane test cases
Dan Talaycodba244e2010-02-15 14:08:53 -08003
Dan Talayco48370102010-03-03 15:17:33 -08004It is recommended that these definitions be kept in their own
5namespace as different groups of tests will likely define
6similar identifiers.
7
Dan Talaycodba244e2010-02-15 14:08:53 -08008Current Assumptions:
9
Dan Talayco41eae8b2010-03-10 13:57:06 -080010 The function test_set_init is called with a complete configuration
11dictionary prior to the invocation of any tests from this file.
12
Dan Talaycodba244e2010-02-15 14:08:53 -080013 The switch is actively attempting to contact the controller at the address
14indicated oin oft_config
15
16"""
17
Dan Talaycodba244e2010-02-15 14:08:53 -080018import time
Dan Talayco710438c2010-02-18 15:16:07 -080019import signal
Dan Talaycodba244e2010-02-15 14:08:53 -080020import sys
Dan Talayco48370102010-03-03 15:17:33 -080021import logging
Dan Talaycodba244e2010-02-15 14:08:53 -080022
Dan Talayco2c0dba32010-03-06 22:47:06 -080023import unittest
Ken Chiang1bf01602012-04-04 10:48:23 -070024import random
Dan Talayco2c0dba32010-03-06 22:47:06 -080025
26import oftest.controller as controller
27import oftest.cstruct as ofp
28import oftest.message as message
29import oftest.dataplane as dataplane
30import oftest.action as action
31
Dan Talayco6ce963a2010-03-07 21:58:13 -080032from testutils import *
33
34#@var basic_port_map Local copy of the configuration map from OF port
35# numbers to OS interfaces
Dan Talayco48370102010-03-03 15:17:33 -080036basic_port_map = None
Dan Talayco6ce963a2010-03-07 21:58:13 -080037#@var basic_logger Local logger object
Dan Talayco48370102010-03-03 15:17:33 -080038basic_logger = None
Dan Talayco6ce963a2010-03-07 21:58:13 -080039#@var basic_config Local copy of global configuration data
Dan Talayco48370102010-03-03 15:17:33 -080040basic_config = None
41
Dan Talaycoc24aaae2010-07-08 14:05:24 -070042test_prio = {}
43
Dan Talayco48370102010-03-03 15:17:33 -080044def test_set_init(config):
45 """
46 Set up function for basic test classes
47
48 @param config The configuration dictionary; see oft
Dan Talayco48370102010-03-03 15:17:33 -080049 """
50
51 global basic_port_map
52 global basic_logger
53 global basic_config
54
55 basic_logger = logging.getLogger("basic")
56 basic_logger.info("Initializing test set")
57 basic_port_map = config["port_map"]
58 basic_config = config
Dan Talayco48370102010-03-03 15:17:33 -080059
Dan Talayco6ce963a2010-03-07 21:58:13 -080060class SimpleProtocol(unittest.TestCase):
Dan Talaycodba244e2010-02-15 14:08:53 -080061 """
62 Root class for setting up the controller
63 """
64
Dan Talaycoef701f42010-05-07 09:22:35 -070065 def sig_handler(self, v1, v2):
Dan Talayco48370102010-03-03 15:17:33 -080066 basic_logger.critical("Received interrupt signal; exiting")
Dan Talayco710438c2010-02-18 15:16:07 -080067 print "Received interrupt signal; exiting"
Dan Talayco2c0dba32010-03-06 22:47:06 -080068 self.clean_shutdown = False
69 self.tearDown()
Rich Lane58cf05f2012-07-11 16:41:47 -070070 raise KeyboardInterrupt
Dan Talayco710438c2010-02-18 15:16:07 -080071
Dan Talaycodba244e2010-02-15 14:08:53 -080072 def setUp(self):
Dan Talayco551befa2010-07-15 17:05:32 -070073 self.logger = basic_logger
Dan Talayco285a8382010-07-20 14:06:55 -070074 self.config = basic_config
Ed Swierk022d02e2012-08-22 06:26:36 -070075 #@todo Test cases shouldn't monkey with signals; move SIGINT handler
76 # to top-level oft
77 try:
78 signal.signal(signal.SIGINT, self.sig_handler)
79 except ValueError, e:
80 basic_logger.info("Could not set SIGINT handler: %s" % e)
Dan Talayco9f47f4d2010-06-03 13:54:37 -070081 basic_logger.info("** START TEST CASE " + str(self))
Dan Talayco2c0dba32010-03-06 22:47:06 -080082 self.controller = controller.Controller(
83 host=basic_config["controller_host"],
84 port=basic_config["controller_port"])
Dan Talaycof8f41402010-03-12 22:17:39 -080085 # clean_shutdown should be set to False to force quit app
Dan Talayco2c0dba32010-03-06 22:47:06 -080086 self.clean_shutdown = True
Dan Talayco710438c2010-02-18 15:16:07 -080087 self.controller.start()
Dan Talaycoef701f42010-05-07 09:22:35 -070088 #@todo Add an option to wait for a pkt transaction to ensure version
89 # compatibilty?
Dan Talayco710438c2010-02-18 15:16:07 -080090 self.controller.connect(timeout=20)
Dan Talaycoef701f42010-05-07 09:22:35 -070091 if not self.controller.active:
Rich Lane58cf05f2012-07-11 16:41:47 -070092 raise Exception("Controller startup failed")
Dan Talayco677c0b72011-08-23 22:53:38 -070093 if self.controller.switch_addr is None:
Rich Lane58cf05f2012-07-11 16:41:47 -070094 raise Exception("Controller startup failed (no switch addr)")
Dan Talayco48370102010-03-03 15:17:33 -080095 basic_logger.info("Connected " + str(self.controller.switch_addr))
Dan Talaycodba244e2010-02-15 14:08:53 -080096
Dan Talayco677cc112012-03-27 10:28:58 -070097 def inheritSetup(self, parent):
98 """
99 Inherit the setup of a parent
100
101 This allows running at test from within another test. Do the
102 following:
103
104 sub_test = SomeTestClass() # Create an instance of the test class
105 sub_test.inheritSetup(self) # Inherit setup of parent
106 sub_test.runTest() # Run the test
107
108 Normally, only the parent's setUp and tearDown are called and
109 the state after the sub_test is run must be taken into account
110 by subsequent operations.
111 """
112 self.logger = parent.logger
113 self.config = parent.config
114 basic_logger.info("** Setup " + str(self) + " inheriting from "
115 + str(parent))
116 self.controller = parent.controller
117
Dan Talaycodba244e2010-02-15 14:08:53 -0800118 def tearDown(self):
Dan Talayco9f47f4d2010-06-03 13:54:37 -0700119 basic_logger.info("** END TEST CASE " + str(self))
Dan Talaycodba244e2010-02-15 14:08:53 -0800120 self.controller.shutdown()
Dan Talayco2c0dba32010-03-06 22:47:06 -0800121 #@todo Review if join should be done on clean_shutdown
Dan Talaycof8f41402010-03-12 22:17:39 -0800122 if self.clean_shutdown:
123 self.controller.join()
Dan Talaycodba244e2010-02-15 14:08:53 -0800124
125 def runTest(self):
Dan Talayco710438c2010-02-18 15:16:07 -0800126 # Just a simple sanity check as illustration
Dan Talayco48370102010-03-03 15:17:33 -0800127 basic_logger.info("Running simple proto test")
Dan Talayco710438c2010-02-18 15:16:07 -0800128 self.assertTrue(self.controller.switch_socket is not None,
Dan Talaycodba244e2010-02-15 14:08:53 -0800129 str(self) + 'No connection to switch')
130
Dan Talayco9f47f4d2010-06-03 13:54:37 -0700131 def assertTrue(self, cond, msg):
132 if not cond:
133 basic_logger.error("** FAILED ASSERTION: " + msg)
134 unittest.TestCase.assertTrue(self, cond, msg)
135
Dan Talaycoc24aaae2010-07-08 14:05:24 -0700136test_prio["SimpleProtocol"] = 1
137
Dan Talayco6ce963a2010-03-07 21:58:13 -0800138class SimpleDataPlane(SimpleProtocol):
Dan Talaycodba244e2010-02-15 14:08:53 -0800139 """
140 Root class that sets up the controller and dataplane
141 """
142 def setUp(self):
Dan Talayco6ce963a2010-03-07 21:58:13 -0800143 SimpleProtocol.setUp(self)
Jeffrey Townsend4d5ca922012-07-11 11:37:35 -0700144 self.dataplane = dataplane.DataPlane(self.config)
Dan Talayco48370102010-03-03 15:17:33 -0800145 for of_port, ifname in basic_port_map.items():
Dan Talaycodba244e2010-02-15 14:08:53 -0800146 self.dataplane.port_add(ifname, of_port)
147
Dan Talayco677cc112012-03-27 10:28:58 -0700148 def inheritSetup(self, parent):
149 """
150 Inherit the setup of a parent
151
152 See SimpleProtocol.inheritSetup
153 """
154 SimpleProtocol.inheritSetup(self, parent)
155 self.dataplane = parent.dataplane
156
Dan Talaycodba244e2010-02-15 14:08:53 -0800157 def tearDown(self):
Dan Talayco48370102010-03-03 15:17:33 -0800158 basic_logger.info("Teardown for simple dataplane test")
Dan Talayco6ce963a2010-03-07 21:58:13 -0800159 SimpleProtocol.tearDown(self)
Rich Lane58cf05f2012-07-11 16:41:47 -0700160 if hasattr(self, 'dataplane'):
161 self.dataplane.kill(join_threads=self.clean_shutdown)
Dan Talayco48370102010-03-03 15:17:33 -0800162 basic_logger.info("Teardown done")
Dan Talaycodba244e2010-02-15 14:08:53 -0800163
164 def runTest(self):
Dan Talayco710438c2010-02-18 15:16:07 -0800165 self.assertTrue(self.controller.switch_socket is not None,
Dan Talaycodba244e2010-02-15 14:08:53 -0800166 str(self) + 'No connection to switch')
167 # self.dataplane.show()
168 # Would like an assert that checks the data plane
169
Dan Talayco551befa2010-07-15 17:05:32 -0700170class DataPlaneOnly(unittest.TestCase):
171 """
172 Root class that sets up only the dataplane
173 """
174
175 def sig_handler(self, v1, v2):
176 basic_logger.critical("Received interrupt signal; exiting")
177 print "Received interrupt signal; exiting"
178 self.clean_shutdown = False
179 self.tearDown()
Rich Lane58cf05f2012-07-11 16:41:47 -0700180 raise KeyboardInterrupt
Dan Talayco551befa2010-07-15 17:05:32 -0700181
182 def setUp(self):
Shudong Zhoue3582a52012-08-03 20:46:50 -0700183 self.clean_shutdown = True
Dan Talayco551befa2010-07-15 17:05:32 -0700184 self.logger = basic_logger
Dan Talayco285a8382010-07-20 14:06:55 -0700185 self.config = basic_config
Ed Swierk022d02e2012-08-22 06:26:36 -0700186 #@todo Test cases shouldn't monkey with signals; move SIGINT handler
187 # to top-level oft
188 try:
189 signal.signal(signal.SIGINT, self.sig_handler)
190 except ValueError, e:
191 basic_logger.info("Could not set SIGINT handler: %s" % e)
Dan Talayco551befa2010-07-15 17:05:32 -0700192 basic_logger.info("** START DataPlaneOnly CASE " + str(self))
Jeffrey Townsend4d5ca922012-07-11 11:37:35 -0700193 self.dataplane = dataplane.DataPlane(self.config)
Dan Talayco551befa2010-07-15 17:05:32 -0700194 for of_port, ifname in basic_port_map.items():
195 self.dataplane.port_add(ifname, of_port)
196
197 def tearDown(self):
198 basic_logger.info("Teardown for simple dataplane test")
199 self.dataplane.kill(join_threads=self.clean_shutdown)
200 basic_logger.info("Teardown done")
201
202 def runTest(self):
Dan Talaycoba4fd4f2010-07-21 21:49:41 -0700203 basic_logger.info("DataPlaneOnly")
Dan Talayco285a8382010-07-20 14:06:55 -0700204 # self.dataplane.show()
Dan Talayco551befa2010-07-15 17:05:32 -0700205 # Would like an assert that checks the data plane
206
Dan Talayco6ce963a2010-03-07 21:58:13 -0800207class Echo(SimpleProtocol):
Dan Talaycodba244e2010-02-15 14:08:53 -0800208 """
209 Test echo response with no data
210 """
211 def runTest(self):
Dan Talayco2c0dba32010-03-06 22:47:06 -0800212 request = message.echo_request()
Dan Talaycoe226eb12010-02-18 23:06:30 -0800213 response, pkt = self.controller.transact(request)
Dan Talayco2c0dba32010-03-06 22:47:06 -0800214 self.assertEqual(response.header.type, ofp.OFPT_ECHO_REPLY,
Dan Talaycoa92e75b2010-02-16 20:53:56 -0800215 'response is not echo_reply')
Dan Talaycodba244e2010-02-15 14:08:53 -0800216 self.assertEqual(request.header.xid, response.header.xid,
217 'response xid != request xid')
218 self.assertEqual(len(response.data), 0, 'response data non-empty')
219
Dan Talayco6ce963a2010-03-07 21:58:13 -0800220class EchoWithData(SimpleProtocol):
Dan Talaycodba244e2010-02-15 14:08:53 -0800221 """
222 Test echo response with short string data
223 """
224 def runTest(self):
Dan Talayco2c0dba32010-03-06 22:47:06 -0800225 request = message.echo_request()
Dan Talaycodba244e2010-02-15 14:08:53 -0800226 request.data = 'OpenFlow Will Rule The World'
Dan Talaycoe226eb12010-02-18 23:06:30 -0800227 response, pkt = self.controller.transact(request)
Dan Talayco2c0dba32010-03-06 22:47:06 -0800228 self.assertEqual(response.header.type, ofp.OFPT_ECHO_REPLY,
Dan Talaycoa92e75b2010-02-16 20:53:56 -0800229 'response is not echo_reply')
Dan Talaycodba244e2010-02-15 14:08:53 -0800230 self.assertEqual(request.header.xid, response.header.xid,
231 'response xid != request xid')
232 self.assertEqual(request.data, response.data,
233 'response data does not match request')
234
Dan Talayco6ce963a2010-03-07 21:58:13 -0800235class PacketIn(SimpleDataPlane):
Dan Talaycodba244e2010-02-15 14:08:53 -0800236 """
237 Test packet in function
Dan Talayco6ce963a2010-03-07 21:58:13 -0800238
239 Send a packet to each dataplane port and verify that a packet
240 in message is received from the controller for each
Dan Talaycodba244e2010-02-15 14:08:53 -0800241 """
242 def runTest(self):
243 # Construct packet to send to dataplane
Dan Talaycoe226eb12010-02-18 23:06:30 -0800244 # Send packet to dataplane, once to each port
Dan Talaycodba244e2010-02-15 14:08:53 -0800245 # Poll controller with expect message type packet in
Dan Talaycoe226eb12010-02-18 23:06:30 -0800246
Dan Talayco6ce963a2010-03-07 21:58:13 -0800247 rc = delete_all_flows(self.controller, basic_logger)
248 self.assertEqual(rc, 0, "Failed to delete all flows")
Dan Talayco0fc08bd2012-04-09 16:56:18 -0700249 self.assertEqual(do_barrier(self.controller), 0, "Barrier failed")
Dan Talayco6ce963a2010-03-07 21:58:13 -0800250
Dan Talayco48370102010-03-03 15:17:33 -0800251 for of_port in basic_port_map.keys():
Ed Swierk0aeff8c2012-03-23 20:27:18 -0700252 for pkt, pt in [
253 (simple_tcp_packet(), "simple TCP packet"),
254 (simple_eth_packet(), "simple Ethernet packet"),
255 (simple_eth_packet(pktlen=40), "tiny Ethernet packet")]:
Dan Talaycodba244e2010-02-15 14:08:53 -0800256
Ed Swierk0aeff8c2012-03-23 20:27:18 -0700257 basic_logger.info("PKT IN test with %s, port %s" % (pt, of_port))
258 self.dataplane.send(of_port, str(pkt))
259 #@todo Check for unexpected messages?
260 count = 0
261 while True:
262 (response, raw) = self.controller.poll(ofp.OFPT_PACKET_IN, 2)
263 if not response: # Timeout
264 break
Ed Swierk506614a2012-03-29 08:16:59 -0700265 if dataplane.match_exp_pkt(pkt, response.data): # Got match
Ed Swierk0aeff8c2012-03-23 20:27:18 -0700266 break
267 if not basic_config["relax"]: # Only one attempt to match
268 break
269 count += 1
270 if count > 10: # Too many tries
271 break
Dan Talayco48370102010-03-03 15:17:33 -0800272
Ed Swierk0aeff8c2012-03-23 20:27:18 -0700273 self.assertTrue(response is not None,
274 'Packet in message not received on port ' +
275 str(of_port))
Ed Swierk506614a2012-03-29 08:16:59 -0700276 if not dataplane.match_exp_pkt(pkt, response.data):
Dan Talayco2baf8b52012-03-30 09:55:42 -0700277 basic_logger.debug("Sent %s" % format_packet(pkt))
278 basic_logger.debug("Resp %s" % format_packet(response.data))
Ed Swierk0aeff8c2012-03-23 20:27:18 -0700279 self.assertTrue(False,
280 'Response packet does not match send packet' +
281 ' for port ' + str(of_port))
Dan Talaycodba244e2010-02-15 14:08:53 -0800282
Jeffrey Townsend4d5ca922012-07-11 11:37:35 -0700283
Dan Talayco1f648cb2012-05-03 09:37:56 -0700284class PacketInBroadcastCheck(SimpleDataPlane):
285 """
286 Check if bcast pkts leak when no flows are present
287
288 Clear the flow table
289 Send in a broadcast pkt
290 Look for the packet on other dataplane ports.
291 """
292 def runTest(self):
293 # Need at least two ports
294 self.assertTrue(len(basic_port_map) > 1, "Too few ports for test")
295
296 rc = delete_all_flows(self.controller, basic_logger)
297 self.assertEqual(rc, 0, "Failed to delete all flows")
298 self.assertEqual(do_barrier(self.controller), 0, "Barrier failed")
299
300 of_ports = basic_port_map.keys()
301 d_port = of_ports[0]
302 pkt = simple_eth_packet(dl_dst='ff:ff:ff:ff:ff:ff')
303
304 basic_logger.info("BCast Leak Test, send to port %s" % d_port)
305 self.dataplane.send(d_port, str(pkt))
306
Rich Lanec8aaa3e2012-07-26 19:28:02 -0700307 (of_port, pkt_in, pkt_time) = self.dataplane.poll(exp_pkt=pkt)
Dan Talayco1f648cb2012-05-03 09:37:56 -0700308 self.assertTrue(pkt_in is None,
309 'BCast packet received on port ' + str(of_port))
310
311test_prio["PacketInBroadcastCheck"] = -1
312
Dan Talayco6ce963a2010-03-07 21:58:13 -0800313class PacketOut(SimpleDataPlane):
Dan Talaycodba244e2010-02-15 14:08:53 -0800314 """
315 Test packet out function
Dan Talayco6ce963a2010-03-07 21:58:13 -0800316
317 Send packet out message to controller for each dataplane port and
318 verify the packet appears on the appropriate dataplane port
Dan Talaycodba244e2010-02-15 14:08:53 -0800319 """
320 def runTest(self):
321 # Construct packet to send to dataplane
322 # Send packet to dataplane
323 # Poll controller with expect message type packet in
Dan Talayco41eae8b2010-03-10 13:57:06 -0800324
325 rc = delete_all_flows(self.controller, basic_logger)
326 self.assertEqual(rc, 0, "Failed to delete all flows")
Dan Talaycodba244e2010-02-15 14:08:53 -0800327
328 # These will get put into function
Dan Talayco48370102010-03-03 15:17:33 -0800329 of_ports = basic_port_map.keys()
330 of_ports.sort()
331 for dp_port in of_ports:
Ed Swierk0aeff8c2012-03-23 20:27:18 -0700332 for outpkt, opt in [
333 (simple_tcp_packet(), "simple TCP packet"),
334 (simple_eth_packet(), "simple Ethernet packet"),
335 (simple_eth_packet(pktlen=40), "tiny Ethernet packet")]:
Dan Talaycodba244e2010-02-15 14:08:53 -0800336
Ed Swierk0aeff8c2012-03-23 20:27:18 -0700337 basic_logger.info("PKT OUT test with %s, port %s" % (opt, dp_port))
338 msg = message.packet_out()
339 msg.data = str(outpkt)
340 act = action.action_output()
341 act.port = dp_port
342 self.assertTrue(msg.actions.add(act), 'Could not add action to msg')
Dan Talaycodba244e2010-02-15 14:08:53 -0800343
Ed Swierk0aeff8c2012-03-23 20:27:18 -0700344 basic_logger.info("PacketOut to: " + str(dp_port))
345 rv = self.controller.message_send(msg)
346 self.assertTrue(rv == 0, "Error sending out message")
Dan Talaycodba244e2010-02-15 14:08:53 -0800347
Ed Swierk0aeff8c2012-03-23 20:27:18 -0700348 exp_pkt_arg = None
349 exp_port = None
350 if basic_config["relax"]:
351 exp_pkt_arg = outpkt
352 exp_port = dp_port
Rich Lanec8aaa3e2012-07-26 19:28:02 -0700353 (of_port, pkt, pkt_time) = self.dataplane.poll(port_number=exp_port,
Ed Swierk0aeff8c2012-03-23 20:27:18 -0700354 exp_pkt=exp_pkt_arg)
355
356 self.assertTrue(pkt is not None, 'Packet not received')
357 basic_logger.info("PacketOut: got pkt from " + str(of_port))
358 if of_port is not None:
359 self.assertEqual(of_port, dp_port, "Unexpected receive port")
Ed Swierk506614a2012-03-29 08:16:59 -0700360 if not dataplane.match_exp_pkt(outpkt, pkt):
Dan Talayco2baf8b52012-03-30 09:55:42 -0700361 basic_logger.debug("Sent %s" % format_packet(outpkt))
362 basic_logger.debug("Resp %s" % format_packet(
363 str(pkt)[:len(str(outpkt))]))
Dan Talaycodc6fca32012-03-30 10:05:49 -0700364 self.assertEqual(str(outpkt), str(pkt)[:len(str(outpkt))],
365 'Response packet does not match send packet')
Dan Talaycodba244e2010-02-15 14:08:53 -0800366
Ken Chiang1bf01602012-04-04 10:48:23 -0700367class PacketOutMC(SimpleDataPlane):
368 """
369 Test packet out to multiple output ports
370
371 Send packet out message to controller for 1 to N dataplane ports and
372 verify the packet appears on the appropriate ports
373 """
374 def runTest(self):
375 # Construct packet to send to dataplane
376 # Send packet to dataplane
377 # Poll controller with expect message type packet in
378
379 rc = delete_all_flows(self.controller, basic_logger)
380 self.assertEqual(rc, 0, "Failed to delete all flows")
381
382 # These will get put into function
383 of_ports = basic_port_map.keys()
384 random.shuffle(of_ports)
385 for num_ports in range(1,len(of_ports)+1):
386 for outpkt, opt in [
387 (simple_tcp_packet(), "simple TCP packet"),
388 (simple_eth_packet(), "simple Ethernet packet"),
389 (simple_eth_packet(pktlen=40), "tiny Ethernet packet")]:
390
391 dp_ports = of_ports[0:num_ports]
392 basic_logger.info("PKT OUT test with " + opt +
393 ", ports " + str(dp_ports))
394 msg = message.packet_out()
395 msg.data = str(outpkt)
396 act = action.action_output()
397 for i in range(0,num_ports):
398 act.port = dp_ports[i]
399 self.assertTrue(msg.actions.add(act),
400 'Could not add action to msg')
401
402 basic_logger.info("PacketOut to: " + str(dp_ports))
403 rv = self.controller.message_send(msg)
404 self.assertTrue(rv == 0, "Error sending out message")
405
406 receive_pkt_check(self.dataplane, outpkt, dp_ports,
407 set(of_ports).difference(dp_ports),
408 self, basic_logger, basic_config)
409
Dan Talayco6ce963a2010-03-07 21:58:13 -0800410class FlowStatsGet(SimpleProtocol):
411 """
412 Get stats
Dan Talayco2c0dba32010-03-06 22:47:06 -0800413
Dan Talayco6ce963a2010-03-07 21:58:13 -0800414 Simply verify stats get transaction
415 """
416 def runTest(self):
417 basic_logger.info("Running StatsGet")
Dan Talayco41eae8b2010-03-10 13:57:06 -0800418 basic_logger.info("Inserting trial flow")
Dan Talayco677c0b72011-08-23 22:53:38 -0700419 request = flow_mod_gen(basic_port_map, True)
Dan Talayco41eae8b2010-03-10 13:57:06 -0800420 rv = self.controller.message_send(request)
421 self.assertTrue(rv != -1, "Failed to insert test flow")
422
423 basic_logger.info("Sending flow request")
Dan Talayco6ce963a2010-03-07 21:58:13 -0800424 request = message.flow_stats_request()
425 request.out_port = ofp.OFPP_NONE
Dan Talayco41eae8b2010-03-10 13:57:06 -0800426 request.table_id = 0xff
427 request.match.wildcards = 0 # ofp.OFPFW_ALL
Rich Lanec8aaa3e2012-07-26 19:28:02 -0700428 response, pkt = self.controller.transact(request)
Dan Talayco6ce963a2010-03-07 21:58:13 -0800429 self.assertTrue(response is not None, "Did not get response")
Dan Talaycob3f43fe2010-05-13 14:24:20 -0700430 basic_logger.debug(response.show())
Dan Talayco6ce963a2010-03-07 21:58:13 -0800431
Dan Talayco677c0b72011-08-23 22:53:38 -0700432test_prio["FlowStatsGet"] = -1
433
Dan Talayco79c6c4d2010-06-08 14:01:53 -0700434class TableStatsGet(SimpleProtocol):
435 """
436 Get table stats
437
438 Simply verify table stats get transaction
439 """
440 def runTest(self):
441 basic_logger.info("Running TableStatsGet")
442 basic_logger.info("Inserting trial flow")
Dan Talayco677c0b72011-08-23 22:53:38 -0700443 request = flow_mod_gen(basic_port_map, True)
Dan Talayco79c6c4d2010-06-08 14:01:53 -0700444 rv = self.controller.message_send(request)
445 self.assertTrue(rv != -1, "Failed to insert test flow")
446
447 basic_logger.info("Sending table stats request")
448 request = message.table_stats_request()
Rich Lanec8aaa3e2012-07-26 19:28:02 -0700449 response, pkt = self.controller.transact(request)
Dan Talayco79c6c4d2010-06-08 14:01:53 -0700450 self.assertTrue(response is not None, "Did not get response")
451 basic_logger.debug(response.show())
452
Ed Swierkae74c362012-04-02 08:21:41 -0700453class DescStatsGet(SimpleProtocol):
454 """
455 Get stats
456
457 Simply verify stats get transaction
458 """
459 def runTest(self):
460 basic_logger.info("Running DescStatsGet")
461
462 basic_logger.info("Sending stats request")
463 request = message.desc_stats_request()
Rich Lanec8aaa3e2012-07-26 19:28:02 -0700464 response, pkt = self.controller.transact(request)
Ed Swierkae74c362012-04-02 08:21:41 -0700465 self.assertTrue(response is not None, "Did not get response")
466 basic_logger.debug(response.show())
467
Dan Talayco6ce963a2010-03-07 21:58:13 -0800468class FlowMod(SimpleProtocol):
469 """
470 Insert a flow
471
472 Simple verification of a flow mod transaction
473 """
474
475 def runTest(self):
476 basic_logger.info("Running " + str(self))
Dan Talayco677c0b72011-08-23 22:53:38 -0700477 request = flow_mod_gen(basic_port_map, True)
Dan Talayco6ce963a2010-03-07 21:58:13 -0800478 rv = self.controller.message_send(request)
Dan Talayco41eae8b2010-03-10 13:57:06 -0800479 self.assertTrue(rv != -1, "Error installing flow mod")
480
Dan Talaycob3f43fe2010-05-13 14:24:20 -0700481class PortConfigMod(SimpleProtocol):
482 """
483 Modify a bit in port config and verify changed
484
485 Get the switch configuration, modify the port configuration
486 and write it back; get the config again and verify changed.
487 Then set it back to the way it was.
488 """
489
490 def runTest(self):
491 basic_logger.info("Running " + str(self))
Dan Talayco9f47f4d2010-06-03 13:54:37 -0700492 for of_port, ifname in basic_port_map.items(): # Grab first port
493 break
Dan Talaycob3f43fe2010-05-13 14:24:20 -0700494
Dan Talayco9f47f4d2010-06-03 13:54:37 -0700495 (hw_addr, config, advert) = \
496 port_config_get(self.controller, of_port, basic_logger)
497 self.assertTrue(config is not None, "Did not get port config")
498
499 basic_logger.debug("No flood bit port " + str(of_port) + " is now " +
500 str(config & ofp.OFPPC_NO_FLOOD))
501
502 rv = port_config_set(self.controller, of_port,
503 config ^ ofp.OFPPC_NO_FLOOD, ofp.OFPPC_NO_FLOOD,
504 basic_logger)
Dan Talaycob3f43fe2010-05-13 14:24:20 -0700505 self.assertTrue(rv != -1, "Error sending port mod")
506
507 # Verify change took place with same feature request
Dan Talayco9f47f4d2010-06-03 13:54:37 -0700508 (hw_addr, config2, advert) = \
509 port_config_get(self.controller, of_port, basic_logger)
510 basic_logger.debug("No flood bit port " + str(of_port) + " is now " +
511 str(config2 & ofp.OFPPC_NO_FLOOD))
512 self.assertTrue(config2 is not None, "Did not get port config2")
513 self.assertTrue(config2 & ofp.OFPPC_NO_FLOOD !=
514 config & ofp.OFPPC_NO_FLOOD,
515 "Bit change did not take")
Dan Talaycob3f43fe2010-05-13 14:24:20 -0700516 # Set it back
Dan Talayco9f47f4d2010-06-03 13:54:37 -0700517 rv = port_config_set(self.controller, of_port, config,
518 ofp.OFPPC_NO_FLOOD, basic_logger)
519 self.assertTrue(rv != -1, "Error sending port mod")
Dan Talaycob3f43fe2010-05-13 14:24:20 -0700520
Dan Talaycodba244e2010-02-15 14:08:53 -0800521if __name__ == "__main__":
Dan Talayco2c0dba32010-03-06 22:47:06 -0800522 print "Please run through oft script: ./oft --test_spec=basic"