blob: 5220b26846937720ee6313136ade3149d39f4c3f [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
Dan Talayco710438c2010-02-18 15:16:07 -080075 signal.signal(signal.SIGINT, self.sig_handler)
Dan Talayco9f47f4d2010-06-03 13:54:37 -070076 basic_logger.info("** START TEST CASE " + str(self))
Dan Talayco2c0dba32010-03-06 22:47:06 -080077 self.controller = controller.Controller(
78 host=basic_config["controller_host"],
79 port=basic_config["controller_port"])
Dan Talaycof8f41402010-03-12 22:17:39 -080080 # clean_shutdown should be set to False to force quit app
Dan Talayco2c0dba32010-03-06 22:47:06 -080081 self.clean_shutdown = True
Dan Talayco710438c2010-02-18 15:16:07 -080082 self.controller.start()
Dan Talaycoef701f42010-05-07 09:22:35 -070083 #@todo Add an option to wait for a pkt transaction to ensure version
84 # compatibilty?
Dan Talayco710438c2010-02-18 15:16:07 -080085 self.controller.connect(timeout=20)
Dan Talaycoef701f42010-05-07 09:22:35 -070086 if not self.controller.active:
Rich Lane58cf05f2012-07-11 16:41:47 -070087 raise Exception("Controller startup failed")
Dan Talayco677c0b72011-08-23 22:53:38 -070088 if self.controller.switch_addr is None:
Rich Lane58cf05f2012-07-11 16:41:47 -070089 raise Exception("Controller startup failed (no switch addr)")
Dan Talayco48370102010-03-03 15:17:33 -080090 basic_logger.info("Connected " + str(self.controller.switch_addr))
Dan Talaycodba244e2010-02-15 14:08:53 -080091
Dan Talayco677cc112012-03-27 10:28:58 -070092 def inheritSetup(self, parent):
93 """
94 Inherit the setup of a parent
95
96 This allows running at test from within another test. Do the
97 following:
98
99 sub_test = SomeTestClass() # Create an instance of the test class
100 sub_test.inheritSetup(self) # Inherit setup of parent
101 sub_test.runTest() # Run the test
102
103 Normally, only the parent's setUp and tearDown are called and
104 the state after the sub_test is run must be taken into account
105 by subsequent operations.
106 """
107 self.logger = parent.logger
108 self.config = parent.config
109 basic_logger.info("** Setup " + str(self) + " inheriting from "
110 + str(parent))
111 self.controller = parent.controller
112
Dan Talaycodba244e2010-02-15 14:08:53 -0800113 def tearDown(self):
Dan Talayco9f47f4d2010-06-03 13:54:37 -0700114 basic_logger.info("** END TEST CASE " + str(self))
Dan Talaycodba244e2010-02-15 14:08:53 -0800115 self.controller.shutdown()
Dan Talayco2c0dba32010-03-06 22:47:06 -0800116 #@todo Review if join should be done on clean_shutdown
Dan Talaycof8f41402010-03-12 22:17:39 -0800117 if self.clean_shutdown:
118 self.controller.join()
Dan Talaycodba244e2010-02-15 14:08:53 -0800119
120 def runTest(self):
Dan Talayco710438c2010-02-18 15:16:07 -0800121 # Just a simple sanity check as illustration
Dan Talayco48370102010-03-03 15:17:33 -0800122 basic_logger.info("Running simple proto test")
Dan Talayco710438c2010-02-18 15:16:07 -0800123 self.assertTrue(self.controller.switch_socket is not None,
Dan Talaycodba244e2010-02-15 14:08:53 -0800124 str(self) + 'No connection to switch')
125
Dan Talayco9f47f4d2010-06-03 13:54:37 -0700126 def assertTrue(self, cond, msg):
127 if not cond:
128 basic_logger.error("** FAILED ASSERTION: " + msg)
129 unittest.TestCase.assertTrue(self, cond, msg)
130
Dan Talaycoc24aaae2010-07-08 14:05:24 -0700131test_prio["SimpleProtocol"] = 1
132
Dan Talayco6ce963a2010-03-07 21:58:13 -0800133class SimpleDataPlane(SimpleProtocol):
Dan Talaycodba244e2010-02-15 14:08:53 -0800134 """
135 Root class that sets up the controller and dataplane
136 """
137 def setUp(self):
Dan Talayco6ce963a2010-03-07 21:58:13 -0800138 SimpleProtocol.setUp(self)
Jeffrey Townsend4d5ca922012-07-11 11:37:35 -0700139 self.dataplane = dataplane.DataPlane(self.config)
Dan Talayco48370102010-03-03 15:17:33 -0800140 for of_port, ifname in basic_port_map.items():
Dan Talaycodba244e2010-02-15 14:08:53 -0800141 self.dataplane.port_add(ifname, of_port)
142
Dan Talayco677cc112012-03-27 10:28:58 -0700143 def inheritSetup(self, parent):
144 """
145 Inherit the setup of a parent
146
147 See SimpleProtocol.inheritSetup
148 """
149 SimpleProtocol.inheritSetup(self, parent)
150 self.dataplane = parent.dataplane
151
Dan Talaycodba244e2010-02-15 14:08:53 -0800152 def tearDown(self):
Dan Talayco48370102010-03-03 15:17:33 -0800153 basic_logger.info("Teardown for simple dataplane test")
Dan Talayco6ce963a2010-03-07 21:58:13 -0800154 SimpleProtocol.tearDown(self)
Rich Lane58cf05f2012-07-11 16:41:47 -0700155 if hasattr(self, 'dataplane'):
156 self.dataplane.kill(join_threads=self.clean_shutdown)
Dan Talayco48370102010-03-03 15:17:33 -0800157 basic_logger.info("Teardown done")
Dan Talaycodba244e2010-02-15 14:08:53 -0800158
159 def runTest(self):
Dan Talayco710438c2010-02-18 15:16:07 -0800160 self.assertTrue(self.controller.switch_socket is not None,
Dan Talaycodba244e2010-02-15 14:08:53 -0800161 str(self) + 'No connection to switch')
162 # self.dataplane.show()
163 # Would like an assert that checks the data plane
164
Dan Talayco551befa2010-07-15 17:05:32 -0700165class DataPlaneOnly(unittest.TestCase):
166 """
167 Root class that sets up only the dataplane
168 """
169
170 def sig_handler(self, v1, v2):
171 basic_logger.critical("Received interrupt signal; exiting")
172 print "Received interrupt signal; exiting"
173 self.clean_shutdown = False
174 self.tearDown()
Rich Lane58cf05f2012-07-11 16:41:47 -0700175 raise KeyboardInterrupt
Dan Talayco551befa2010-07-15 17:05:32 -0700176
177 def setUp(self):
178 self.clean_shutdown = False
179 self.logger = basic_logger
Dan Talayco285a8382010-07-20 14:06:55 -0700180 self.config = basic_config
Dan Talayco551befa2010-07-15 17:05:32 -0700181 signal.signal(signal.SIGINT, self.sig_handler)
182 basic_logger.info("** START DataPlaneOnly CASE " + str(self))
Jeffrey Townsend4d5ca922012-07-11 11:37:35 -0700183 self.dataplane = dataplane.DataPlane(self.config)
Dan Talayco551befa2010-07-15 17:05:32 -0700184 for of_port, ifname in basic_port_map.items():
185 self.dataplane.port_add(ifname, of_port)
186
187 def tearDown(self):
188 basic_logger.info("Teardown for simple dataplane test")
189 self.dataplane.kill(join_threads=self.clean_shutdown)
190 basic_logger.info("Teardown done")
191
192 def runTest(self):
Dan Talaycoba4fd4f2010-07-21 21:49:41 -0700193 basic_logger.info("DataPlaneOnly")
Dan Talayco285a8382010-07-20 14:06:55 -0700194 # self.dataplane.show()
Dan Talayco551befa2010-07-15 17:05:32 -0700195 # Would like an assert that checks the data plane
196
Dan Talayco6ce963a2010-03-07 21:58:13 -0800197class Echo(SimpleProtocol):
Dan Talaycodba244e2010-02-15 14:08:53 -0800198 """
199 Test echo response with no data
200 """
201 def runTest(self):
Dan Talayco2c0dba32010-03-06 22:47:06 -0800202 request = message.echo_request()
Dan Talaycoe226eb12010-02-18 23:06:30 -0800203 response, pkt = self.controller.transact(request)
Dan Talayco2c0dba32010-03-06 22:47:06 -0800204 self.assertEqual(response.header.type, ofp.OFPT_ECHO_REPLY,
Dan Talaycoa92e75b2010-02-16 20:53:56 -0800205 'response is not echo_reply')
Dan Talaycodba244e2010-02-15 14:08:53 -0800206 self.assertEqual(request.header.xid, response.header.xid,
207 'response xid != request xid')
208 self.assertEqual(len(response.data), 0, 'response data non-empty')
209
Dan Talayco6ce963a2010-03-07 21:58:13 -0800210class EchoWithData(SimpleProtocol):
Dan Talaycodba244e2010-02-15 14:08:53 -0800211 """
212 Test echo response with short string data
213 """
214 def runTest(self):
Dan Talayco2c0dba32010-03-06 22:47:06 -0800215 request = message.echo_request()
Dan Talaycodba244e2010-02-15 14:08:53 -0800216 request.data = 'OpenFlow Will Rule The World'
Dan Talaycoe226eb12010-02-18 23:06:30 -0800217 response, pkt = self.controller.transact(request)
Dan Talayco2c0dba32010-03-06 22:47:06 -0800218 self.assertEqual(response.header.type, ofp.OFPT_ECHO_REPLY,
Dan Talaycoa92e75b2010-02-16 20:53:56 -0800219 'response is not echo_reply')
Dan Talaycodba244e2010-02-15 14:08:53 -0800220 self.assertEqual(request.header.xid, response.header.xid,
221 'response xid != request xid')
222 self.assertEqual(request.data, response.data,
223 'response data does not match request')
224
Dan Talayco6ce963a2010-03-07 21:58:13 -0800225class PacketIn(SimpleDataPlane):
Dan Talaycodba244e2010-02-15 14:08:53 -0800226 """
227 Test packet in function
Dan Talayco6ce963a2010-03-07 21:58:13 -0800228
229 Send a packet to each dataplane port and verify that a packet
230 in message is received from the controller for each
Dan Talaycodba244e2010-02-15 14:08:53 -0800231 """
232 def runTest(self):
233 # Construct packet to send to dataplane
Dan Talaycoe226eb12010-02-18 23:06:30 -0800234 # Send packet to dataplane, once to each port
Dan Talaycodba244e2010-02-15 14:08:53 -0800235 # Poll controller with expect message type packet in
Dan Talaycoe226eb12010-02-18 23:06:30 -0800236
Dan Talayco6ce963a2010-03-07 21:58:13 -0800237 rc = delete_all_flows(self.controller, basic_logger)
238 self.assertEqual(rc, 0, "Failed to delete all flows")
Dan Talayco0fc08bd2012-04-09 16:56:18 -0700239 self.assertEqual(do_barrier(self.controller), 0, "Barrier failed")
Dan Talayco6ce963a2010-03-07 21:58:13 -0800240
Dan Talayco48370102010-03-03 15:17:33 -0800241 for of_port in basic_port_map.keys():
Ed Swierk0aeff8c2012-03-23 20:27:18 -0700242 for pkt, pt in [
243 (simple_tcp_packet(), "simple TCP packet"),
244 (simple_eth_packet(), "simple Ethernet packet"),
245 (simple_eth_packet(pktlen=40), "tiny Ethernet packet")]:
Dan Talaycodba244e2010-02-15 14:08:53 -0800246
Ed Swierk0aeff8c2012-03-23 20:27:18 -0700247 basic_logger.info("PKT IN test with %s, port %s" % (pt, of_port))
248 self.dataplane.send(of_port, str(pkt))
249 #@todo Check for unexpected messages?
250 count = 0
251 while True:
252 (response, raw) = self.controller.poll(ofp.OFPT_PACKET_IN, 2)
253 if not response: # Timeout
254 break
Ed Swierk506614a2012-03-29 08:16:59 -0700255 if dataplane.match_exp_pkt(pkt, response.data): # Got match
Ed Swierk0aeff8c2012-03-23 20:27:18 -0700256 break
257 if not basic_config["relax"]: # Only one attempt to match
258 break
259 count += 1
260 if count > 10: # Too many tries
261 break
Dan Talayco48370102010-03-03 15:17:33 -0800262
Ed Swierk0aeff8c2012-03-23 20:27:18 -0700263 self.assertTrue(response is not None,
264 'Packet in message not received on port ' +
265 str(of_port))
Ed Swierk506614a2012-03-29 08:16:59 -0700266 if not dataplane.match_exp_pkt(pkt, response.data):
Dan Talayco2baf8b52012-03-30 09:55:42 -0700267 basic_logger.debug("Sent %s" % format_packet(pkt))
268 basic_logger.debug("Resp %s" % format_packet(response.data))
Ed Swierk0aeff8c2012-03-23 20:27:18 -0700269 self.assertTrue(False,
270 'Response packet does not match send packet' +
271 ' for port ' + str(of_port))
Dan Talaycodba244e2010-02-15 14:08:53 -0800272
Jeffrey Townsend4d5ca922012-07-11 11:37:35 -0700273
Dan Talayco1f648cb2012-05-03 09:37:56 -0700274class PacketInBroadcastCheck(SimpleDataPlane):
275 """
276 Check if bcast pkts leak when no flows are present
277
278 Clear the flow table
279 Send in a broadcast pkt
280 Look for the packet on other dataplane ports.
281 """
282 def runTest(self):
283 # Need at least two ports
284 self.assertTrue(len(basic_port_map) > 1, "Too few ports for test")
285
286 rc = delete_all_flows(self.controller, basic_logger)
287 self.assertEqual(rc, 0, "Failed to delete all flows")
288 self.assertEqual(do_barrier(self.controller), 0, "Barrier failed")
289
290 of_ports = basic_port_map.keys()
291 d_port = of_ports[0]
292 pkt = simple_eth_packet(dl_dst='ff:ff:ff:ff:ff:ff')
293
294 basic_logger.info("BCast Leak Test, send to port %s" % d_port)
295 self.dataplane.send(d_port, str(pkt))
296
297 (of_port, pkt_in, pkt_time) = self.dataplane.poll(timeout=2,
298 exp_pkt=pkt)
299 self.assertTrue(pkt_in is None,
300 'BCast packet received on port ' + str(of_port))
301
302test_prio["PacketInBroadcastCheck"] = -1
303
Dan Talayco6ce963a2010-03-07 21:58:13 -0800304class PacketOut(SimpleDataPlane):
Dan Talaycodba244e2010-02-15 14:08:53 -0800305 """
306 Test packet out function
Dan Talayco6ce963a2010-03-07 21:58:13 -0800307
308 Send packet out message to controller for each dataplane port and
309 verify the packet appears on the appropriate dataplane port
Dan Talaycodba244e2010-02-15 14:08:53 -0800310 """
311 def runTest(self):
312 # Construct packet to send to dataplane
313 # Send packet to dataplane
314 # Poll controller with expect message type packet in
Dan Talayco41eae8b2010-03-10 13:57:06 -0800315
316 rc = delete_all_flows(self.controller, basic_logger)
317 self.assertEqual(rc, 0, "Failed to delete all flows")
Dan Talaycodba244e2010-02-15 14:08:53 -0800318
319 # These will get put into function
Dan Talayco48370102010-03-03 15:17:33 -0800320 of_ports = basic_port_map.keys()
321 of_ports.sort()
322 for dp_port in of_ports:
Ed Swierk0aeff8c2012-03-23 20:27:18 -0700323 for outpkt, opt in [
324 (simple_tcp_packet(), "simple TCP packet"),
325 (simple_eth_packet(), "simple Ethernet packet"),
326 (simple_eth_packet(pktlen=40), "tiny Ethernet packet")]:
Dan Talaycodba244e2010-02-15 14:08:53 -0800327
Ed Swierk0aeff8c2012-03-23 20:27:18 -0700328 basic_logger.info("PKT OUT test with %s, port %s" % (opt, dp_port))
329 msg = message.packet_out()
330 msg.data = str(outpkt)
331 act = action.action_output()
332 act.port = dp_port
333 self.assertTrue(msg.actions.add(act), 'Could not add action to msg')
Dan Talaycodba244e2010-02-15 14:08:53 -0800334
Ed Swierk0aeff8c2012-03-23 20:27:18 -0700335 basic_logger.info("PacketOut to: " + str(dp_port))
336 rv = self.controller.message_send(msg)
337 self.assertTrue(rv == 0, "Error sending out message")
Dan Talaycodba244e2010-02-15 14:08:53 -0800338
Ed Swierk0aeff8c2012-03-23 20:27:18 -0700339 exp_pkt_arg = None
340 exp_port = None
341 if basic_config["relax"]:
342 exp_pkt_arg = outpkt
343 exp_port = dp_port
344 (of_port, pkt, pkt_time) = self.dataplane.poll(timeout=1,
345 port_number=exp_port,
346 exp_pkt=exp_pkt_arg)
347
348 self.assertTrue(pkt is not None, 'Packet not received')
349 basic_logger.info("PacketOut: got pkt from " + str(of_port))
350 if of_port is not None:
351 self.assertEqual(of_port, dp_port, "Unexpected receive port")
Ed Swierk506614a2012-03-29 08:16:59 -0700352 if not dataplane.match_exp_pkt(outpkt, pkt):
Dan Talayco2baf8b52012-03-30 09:55:42 -0700353 basic_logger.debug("Sent %s" % format_packet(outpkt))
354 basic_logger.debug("Resp %s" % format_packet(
355 str(pkt)[:len(str(outpkt))]))
Dan Talaycodc6fca32012-03-30 10:05:49 -0700356 self.assertEqual(str(outpkt), str(pkt)[:len(str(outpkt))],
357 'Response packet does not match send packet')
Dan Talaycodba244e2010-02-15 14:08:53 -0800358
Ken Chiang1bf01602012-04-04 10:48:23 -0700359class PacketOutMC(SimpleDataPlane):
360 """
361 Test packet out to multiple output ports
362
363 Send packet out message to controller for 1 to N dataplane ports and
364 verify the packet appears on the appropriate ports
365 """
366 def runTest(self):
367 # Construct packet to send to dataplane
368 # Send packet to dataplane
369 # Poll controller with expect message type packet in
370
371 rc = delete_all_flows(self.controller, basic_logger)
372 self.assertEqual(rc, 0, "Failed to delete all flows")
373
374 # These will get put into function
375 of_ports = basic_port_map.keys()
376 random.shuffle(of_ports)
377 for num_ports in range(1,len(of_ports)+1):
378 for outpkt, opt in [
379 (simple_tcp_packet(), "simple TCP packet"),
380 (simple_eth_packet(), "simple Ethernet packet"),
381 (simple_eth_packet(pktlen=40), "tiny Ethernet packet")]:
382
383 dp_ports = of_ports[0:num_ports]
384 basic_logger.info("PKT OUT test with " + opt +
385 ", ports " + str(dp_ports))
386 msg = message.packet_out()
387 msg.data = str(outpkt)
388 act = action.action_output()
389 for i in range(0,num_ports):
390 act.port = dp_ports[i]
391 self.assertTrue(msg.actions.add(act),
392 'Could not add action to msg')
393
394 basic_logger.info("PacketOut to: " + str(dp_ports))
395 rv = self.controller.message_send(msg)
396 self.assertTrue(rv == 0, "Error sending out message")
397
398 receive_pkt_check(self.dataplane, outpkt, dp_ports,
399 set(of_ports).difference(dp_ports),
400 self, basic_logger, basic_config)
401
Dan Talayco6ce963a2010-03-07 21:58:13 -0800402class FlowStatsGet(SimpleProtocol):
403 """
404 Get stats
Dan Talayco2c0dba32010-03-06 22:47:06 -0800405
Dan Talayco6ce963a2010-03-07 21:58:13 -0800406 Simply verify stats get transaction
407 """
408 def runTest(self):
409 basic_logger.info("Running StatsGet")
Dan Talayco41eae8b2010-03-10 13:57:06 -0800410 basic_logger.info("Inserting trial flow")
Dan Talayco677c0b72011-08-23 22:53:38 -0700411 request = flow_mod_gen(basic_port_map, True)
Dan Talayco41eae8b2010-03-10 13:57:06 -0800412 rv = self.controller.message_send(request)
413 self.assertTrue(rv != -1, "Failed to insert test flow")
414
415 basic_logger.info("Sending flow request")
Dan Talayco6ce963a2010-03-07 21:58:13 -0800416 request = message.flow_stats_request()
417 request.out_port = ofp.OFPP_NONE
Dan Talayco41eae8b2010-03-10 13:57:06 -0800418 request.table_id = 0xff
419 request.match.wildcards = 0 # ofp.OFPFW_ALL
Dan Talayco6ce963a2010-03-07 21:58:13 -0800420 response, pkt = self.controller.transact(request, timeout=2)
421 self.assertTrue(response is not None, "Did not get response")
Dan Talaycob3f43fe2010-05-13 14:24:20 -0700422 basic_logger.debug(response.show())
Dan Talayco6ce963a2010-03-07 21:58:13 -0800423
Dan Talayco677c0b72011-08-23 22:53:38 -0700424test_prio["FlowStatsGet"] = -1
425
Dan Talayco79c6c4d2010-06-08 14:01:53 -0700426class TableStatsGet(SimpleProtocol):
427 """
428 Get table stats
429
430 Simply verify table stats get transaction
431 """
432 def runTest(self):
433 basic_logger.info("Running TableStatsGet")
434 basic_logger.info("Inserting trial flow")
Dan Talayco677c0b72011-08-23 22:53:38 -0700435 request = flow_mod_gen(basic_port_map, True)
Dan Talayco79c6c4d2010-06-08 14:01:53 -0700436 rv = self.controller.message_send(request)
437 self.assertTrue(rv != -1, "Failed to insert test flow")
438
439 basic_logger.info("Sending table stats request")
440 request = message.table_stats_request()
441 response, pkt = self.controller.transact(request, timeout=2)
442 self.assertTrue(response is not None, "Did not get response")
443 basic_logger.debug(response.show())
444
Ed Swierkae74c362012-04-02 08:21:41 -0700445class DescStatsGet(SimpleProtocol):
446 """
447 Get stats
448
449 Simply verify stats get transaction
450 """
451 def runTest(self):
452 basic_logger.info("Running DescStatsGet")
453
454 basic_logger.info("Sending stats request")
455 request = message.desc_stats_request()
456 response, pkt = self.controller.transact(request, timeout=2)
457 self.assertTrue(response is not None, "Did not get response")
458 basic_logger.debug(response.show())
459
Dan Talayco6ce963a2010-03-07 21:58:13 -0800460class FlowMod(SimpleProtocol):
461 """
462 Insert a flow
463
464 Simple verification of a flow mod transaction
465 """
466
467 def runTest(self):
468 basic_logger.info("Running " + str(self))
Dan Talayco677c0b72011-08-23 22:53:38 -0700469 request = flow_mod_gen(basic_port_map, True)
Dan Talayco6ce963a2010-03-07 21:58:13 -0800470 rv = self.controller.message_send(request)
Dan Talayco41eae8b2010-03-10 13:57:06 -0800471 self.assertTrue(rv != -1, "Error installing flow mod")
472
Dan Talaycob3f43fe2010-05-13 14:24:20 -0700473class PortConfigMod(SimpleProtocol):
474 """
475 Modify a bit in port config and verify changed
476
477 Get the switch configuration, modify the port configuration
478 and write it back; get the config again and verify changed.
479 Then set it back to the way it was.
480 """
481
482 def runTest(self):
483 basic_logger.info("Running " + str(self))
Dan Talayco9f47f4d2010-06-03 13:54:37 -0700484 for of_port, ifname in basic_port_map.items(): # Grab first port
485 break
Dan Talaycob3f43fe2010-05-13 14:24:20 -0700486
Dan Talayco9f47f4d2010-06-03 13:54:37 -0700487 (hw_addr, config, advert) = \
488 port_config_get(self.controller, of_port, basic_logger)
489 self.assertTrue(config is not None, "Did not get port config")
490
491 basic_logger.debug("No flood bit port " + str(of_port) + " is now " +
492 str(config & ofp.OFPPC_NO_FLOOD))
493
494 rv = port_config_set(self.controller, of_port,
495 config ^ ofp.OFPPC_NO_FLOOD, ofp.OFPPC_NO_FLOOD,
496 basic_logger)
Dan Talaycob3f43fe2010-05-13 14:24:20 -0700497 self.assertTrue(rv != -1, "Error sending port mod")
498
499 # Verify change took place with same feature request
Dan Talayco9f47f4d2010-06-03 13:54:37 -0700500 (hw_addr, config2, advert) = \
501 port_config_get(self.controller, of_port, basic_logger)
502 basic_logger.debug("No flood bit port " + str(of_port) + " is now " +
503 str(config2 & ofp.OFPPC_NO_FLOOD))
504 self.assertTrue(config2 is not None, "Did not get port config2")
505 self.assertTrue(config2 & ofp.OFPPC_NO_FLOOD !=
506 config & ofp.OFPPC_NO_FLOOD,
507 "Bit change did not take")
Dan Talaycob3f43fe2010-05-13 14:24:20 -0700508 # Set it back
Dan Talayco9f47f4d2010-06-03 13:54:37 -0700509 rv = port_config_set(self.controller, of_port, config,
510 ofp.OFPPC_NO_FLOOD, basic_logger)
511 self.assertTrue(rv != -1, "Error sending port mod")
Dan Talaycob3f43fe2010-05-13 14:24:20 -0700512
Dan Talaycodba244e2010-02-15 14:08:53 -0800513if __name__ == "__main__":
Dan Talayco2c0dba32010-03-06 22:47:06 -0800514 print "Please run through oft script: ./oft --test_spec=basic"