blob: e7b525e8abfc54f0f3e137bb901f332e45604630 [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()
Dan Talayco710438c2010-02-18 15:16:07 -080070 sys.exit(1)
71
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:
87 print "Controller startup failed; exiting"
88 sys.exit(1)
Dan Talayco677c0b72011-08-23 22:53:38 -070089 if self.controller.switch_addr is None:
90 print "Controller startup failed (no switch addr); exiting"
91 sys.exit(1)
Dan Talayco48370102010-03-03 15:17:33 -080092 basic_logger.info("Connected " + str(self.controller.switch_addr))
Dan Talaycodba244e2010-02-15 14:08:53 -080093
Dan Talayco677cc112012-03-27 10:28:58 -070094 def inheritSetup(self, parent):
95 """
96 Inherit the setup of a parent
97
98 This allows running at test from within another test. Do the
99 following:
100
101 sub_test = SomeTestClass() # Create an instance of the test class
102 sub_test.inheritSetup(self) # Inherit setup of parent
103 sub_test.runTest() # Run the test
104
105 Normally, only the parent's setUp and tearDown are called and
106 the state after the sub_test is run must be taken into account
107 by subsequent operations.
108 """
109 self.logger = parent.logger
110 self.config = parent.config
111 basic_logger.info("** Setup " + str(self) + " inheriting from "
112 + str(parent))
113 self.controller = parent.controller
114
Dan Talaycodba244e2010-02-15 14:08:53 -0800115 def tearDown(self):
Dan Talayco9f47f4d2010-06-03 13:54:37 -0700116 basic_logger.info("** END TEST CASE " + str(self))
Dan Talaycodba244e2010-02-15 14:08:53 -0800117 self.controller.shutdown()
Dan Talayco2c0dba32010-03-06 22:47:06 -0800118 #@todo Review if join should be done on clean_shutdown
Dan Talaycof8f41402010-03-12 22:17:39 -0800119 if self.clean_shutdown:
120 self.controller.join()
Dan Talaycodba244e2010-02-15 14:08:53 -0800121
122 def runTest(self):
Dan Talayco710438c2010-02-18 15:16:07 -0800123 # Just a simple sanity check as illustration
Dan Talayco48370102010-03-03 15:17:33 -0800124 basic_logger.info("Running simple proto test")
Dan Talayco710438c2010-02-18 15:16:07 -0800125 self.assertTrue(self.controller.switch_socket is not None,
Dan Talaycodba244e2010-02-15 14:08:53 -0800126 str(self) + 'No connection to switch')
127
Dan Talayco9f47f4d2010-06-03 13:54:37 -0700128 def assertTrue(self, cond, msg):
129 if not cond:
130 basic_logger.error("** FAILED ASSERTION: " + msg)
131 unittest.TestCase.assertTrue(self, cond, msg)
132
Dan Talaycoc24aaae2010-07-08 14:05:24 -0700133test_prio["SimpleProtocol"] = 1
134
Dan Talayco6ce963a2010-03-07 21:58:13 -0800135class SimpleDataPlane(SimpleProtocol):
Dan Talaycodba244e2010-02-15 14:08:53 -0800136 """
137 Root class that sets up the controller and dataplane
138 """
139 def setUp(self):
Dan Talayco6ce963a2010-03-07 21:58:13 -0800140 SimpleProtocol.setUp(self)
Jeffrey Townsend4d5ca922012-07-11 11:37:35 -0700141 self.dataplane = dataplane.DataPlane(self.config)
Dan Talayco48370102010-03-03 15:17:33 -0800142 for of_port, ifname in basic_port_map.items():
Dan Talaycodba244e2010-02-15 14:08:53 -0800143 self.dataplane.port_add(ifname, of_port)
144
Dan Talayco677cc112012-03-27 10:28:58 -0700145 def inheritSetup(self, parent):
146 """
147 Inherit the setup of a parent
148
149 See SimpleProtocol.inheritSetup
150 """
151 SimpleProtocol.inheritSetup(self, parent)
152 self.dataplane = parent.dataplane
153
Dan Talaycodba244e2010-02-15 14:08:53 -0800154 def tearDown(self):
Dan Talayco48370102010-03-03 15:17:33 -0800155 basic_logger.info("Teardown for simple dataplane test")
Dan Talayco6ce963a2010-03-07 21:58:13 -0800156 SimpleProtocol.tearDown(self)
Dan Talayco2c0dba32010-03-06 22:47:06 -0800157 self.dataplane.kill(join_threads=self.clean_shutdown)
Dan Talayco48370102010-03-03 15:17:33 -0800158 basic_logger.info("Teardown done")
Dan Talaycodba244e2010-02-15 14:08:53 -0800159
160 def runTest(self):
Dan Talayco710438c2010-02-18 15:16:07 -0800161 self.assertTrue(self.controller.switch_socket is not None,
Dan Talaycodba244e2010-02-15 14:08:53 -0800162 str(self) + 'No connection to switch')
163 # self.dataplane.show()
164 # Would like an assert that checks the data plane
165
Dan Talayco551befa2010-07-15 17:05:32 -0700166class DataPlaneOnly(unittest.TestCase):
167 """
168 Root class that sets up only the dataplane
169 """
170
171 def sig_handler(self, v1, v2):
172 basic_logger.critical("Received interrupt signal; exiting")
173 print "Received interrupt signal; exiting"
174 self.clean_shutdown = False
175 self.tearDown()
176 sys.exit(1)
177
178 def setUp(self):
179 self.clean_shutdown = False
180 self.logger = basic_logger
Dan Talayco285a8382010-07-20 14:06:55 -0700181 self.config = basic_config
Dan Talayco551befa2010-07-15 17:05:32 -0700182 signal.signal(signal.SIGINT, self.sig_handler)
183 basic_logger.info("** START DataPlaneOnly CASE " + str(self))
Jeffrey Townsend4d5ca922012-07-11 11:37:35 -0700184 self.dataplane = dataplane.DataPlane(self.config)
Dan Talayco551befa2010-07-15 17:05:32 -0700185 for of_port, ifname in basic_port_map.items():
186 self.dataplane.port_add(ifname, of_port)
187
188 def tearDown(self):
189 basic_logger.info("Teardown for simple dataplane test")
190 self.dataplane.kill(join_threads=self.clean_shutdown)
191 basic_logger.info("Teardown done")
192
193 def runTest(self):
Dan Talaycoba4fd4f2010-07-21 21:49:41 -0700194 basic_logger.info("DataPlaneOnly")
Dan Talayco285a8382010-07-20 14:06:55 -0700195 # self.dataplane.show()
Dan Talayco551befa2010-07-15 17:05:32 -0700196 # Would like an assert that checks the data plane
197
Dan Talayco6ce963a2010-03-07 21:58:13 -0800198class Echo(SimpleProtocol):
Dan Talaycodba244e2010-02-15 14:08:53 -0800199 """
200 Test echo response with no data
201 """
202 def runTest(self):
Dan Talayco2c0dba32010-03-06 22:47:06 -0800203 request = message.echo_request()
Dan Talaycoe226eb12010-02-18 23:06:30 -0800204 response, pkt = self.controller.transact(request)
Dan Talayco2c0dba32010-03-06 22:47:06 -0800205 self.assertEqual(response.header.type, ofp.OFPT_ECHO_REPLY,
Dan Talaycoa92e75b2010-02-16 20:53:56 -0800206 'response is not echo_reply')
Dan Talaycodba244e2010-02-15 14:08:53 -0800207 self.assertEqual(request.header.xid, response.header.xid,
208 'response xid != request xid')
209 self.assertEqual(len(response.data), 0, 'response data non-empty')
210
Dan Talayco6ce963a2010-03-07 21:58:13 -0800211class EchoWithData(SimpleProtocol):
Dan Talaycodba244e2010-02-15 14:08:53 -0800212 """
213 Test echo response with short string data
214 """
215 def runTest(self):
Dan Talayco2c0dba32010-03-06 22:47:06 -0800216 request = message.echo_request()
Dan Talaycodba244e2010-02-15 14:08:53 -0800217 request.data = 'OpenFlow Will Rule The World'
Dan Talaycoe226eb12010-02-18 23:06:30 -0800218 response, pkt = self.controller.transact(request)
Dan Talayco2c0dba32010-03-06 22:47:06 -0800219 self.assertEqual(response.header.type, ofp.OFPT_ECHO_REPLY,
Dan Talaycoa92e75b2010-02-16 20:53:56 -0800220 'response is not echo_reply')
Dan Talaycodba244e2010-02-15 14:08:53 -0800221 self.assertEqual(request.header.xid, response.header.xid,
222 'response xid != request xid')
223 self.assertEqual(request.data, response.data,
224 'response data does not match request')
225
Dan Talayco6ce963a2010-03-07 21:58:13 -0800226class PacketIn(SimpleDataPlane):
Dan Talaycodba244e2010-02-15 14:08:53 -0800227 """
228 Test packet in function
Dan Talayco6ce963a2010-03-07 21:58:13 -0800229
230 Send a packet to each dataplane port and verify that a packet
231 in message is received from the controller for each
Dan Talaycodba244e2010-02-15 14:08:53 -0800232 """
233 def runTest(self):
234 # Construct packet to send to dataplane
Dan Talaycoe226eb12010-02-18 23:06:30 -0800235 # Send packet to dataplane, once to each port
Dan Talaycodba244e2010-02-15 14:08:53 -0800236 # Poll controller with expect message type packet in
Dan Talaycoe226eb12010-02-18 23:06:30 -0800237
Dan Talayco6ce963a2010-03-07 21:58:13 -0800238 rc = delete_all_flows(self.controller, basic_logger)
239 self.assertEqual(rc, 0, "Failed to delete all flows")
Dan Talayco0fc08bd2012-04-09 16:56:18 -0700240 self.assertEqual(do_barrier(self.controller), 0, "Barrier failed")
Dan Talayco6ce963a2010-03-07 21:58:13 -0800241
Dan Talayco48370102010-03-03 15:17:33 -0800242 for of_port in basic_port_map.keys():
Ed Swierk0aeff8c2012-03-23 20:27:18 -0700243 for pkt, pt in [
244 (simple_tcp_packet(), "simple TCP packet"),
245 (simple_eth_packet(), "simple Ethernet packet"),
246 (simple_eth_packet(pktlen=40), "tiny Ethernet packet")]:
Dan Talaycodba244e2010-02-15 14:08:53 -0800247
Ed Swierk0aeff8c2012-03-23 20:27:18 -0700248 basic_logger.info("PKT IN test with %s, port %s" % (pt, of_port))
249 self.dataplane.send(of_port, str(pkt))
250 #@todo Check for unexpected messages?
251 count = 0
252 while True:
253 (response, raw) = self.controller.poll(ofp.OFPT_PACKET_IN, 2)
254 if not response: # Timeout
255 break
Ed Swierk506614a2012-03-29 08:16:59 -0700256 if dataplane.match_exp_pkt(pkt, response.data): # Got match
Ed Swierk0aeff8c2012-03-23 20:27:18 -0700257 break
258 if not basic_config["relax"]: # Only one attempt to match
259 break
260 count += 1
261 if count > 10: # Too many tries
262 break
Dan Talayco48370102010-03-03 15:17:33 -0800263
Ed Swierk0aeff8c2012-03-23 20:27:18 -0700264 self.assertTrue(response is not None,
265 'Packet in message not received on port ' +
266 str(of_port))
Ed Swierk506614a2012-03-29 08:16:59 -0700267 if not dataplane.match_exp_pkt(pkt, response.data):
Dan Talayco2baf8b52012-03-30 09:55:42 -0700268 basic_logger.debug("Sent %s" % format_packet(pkt))
269 basic_logger.debug("Resp %s" % format_packet(response.data))
Ed Swierk0aeff8c2012-03-23 20:27:18 -0700270 self.assertTrue(False,
271 'Response packet does not match send packet' +
272 ' for port ' + str(of_port))
Dan Talaycodba244e2010-02-15 14:08:53 -0800273
Jeffrey Townsend4d5ca922012-07-11 11:37:35 -0700274
Dan Talayco1f648cb2012-05-03 09:37:56 -0700275class PacketInBroadcastCheck(SimpleDataPlane):
276 """
277 Check if bcast pkts leak when no flows are present
278
279 Clear the flow table
280 Send in a broadcast pkt
281 Look for the packet on other dataplane ports.
282 """
283 def runTest(self):
284 # Need at least two ports
285 self.assertTrue(len(basic_port_map) > 1, "Too few ports for test")
286
287 rc = delete_all_flows(self.controller, basic_logger)
288 self.assertEqual(rc, 0, "Failed to delete all flows")
289 self.assertEqual(do_barrier(self.controller), 0, "Barrier failed")
290
291 of_ports = basic_port_map.keys()
292 d_port = of_ports[0]
293 pkt = simple_eth_packet(dl_dst='ff:ff:ff:ff:ff:ff')
294
295 basic_logger.info("BCast Leak Test, send to port %s" % d_port)
296 self.dataplane.send(d_port, str(pkt))
297
298 (of_port, pkt_in, pkt_time) = self.dataplane.poll(timeout=2,
299 exp_pkt=pkt)
300 self.assertTrue(pkt_in is None,
301 'BCast packet received on port ' + str(of_port))
302
303test_prio["PacketInBroadcastCheck"] = -1
304
Dan Talayco6ce963a2010-03-07 21:58:13 -0800305class PacketOut(SimpleDataPlane):
Dan Talaycodba244e2010-02-15 14:08:53 -0800306 """
307 Test packet out function
Dan Talayco6ce963a2010-03-07 21:58:13 -0800308
309 Send packet out message to controller for each dataplane port and
310 verify the packet appears on the appropriate dataplane port
Dan Talaycodba244e2010-02-15 14:08:53 -0800311 """
312 def runTest(self):
313 # Construct packet to send to dataplane
314 # Send packet to dataplane
315 # Poll controller with expect message type packet in
Dan Talayco41eae8b2010-03-10 13:57:06 -0800316
317 rc = delete_all_flows(self.controller, basic_logger)
318 self.assertEqual(rc, 0, "Failed to delete all flows")
Dan Talaycodba244e2010-02-15 14:08:53 -0800319
320 # These will get put into function
Dan Talayco48370102010-03-03 15:17:33 -0800321 of_ports = basic_port_map.keys()
322 of_ports.sort()
323 for dp_port in of_ports:
Ed Swierk0aeff8c2012-03-23 20:27:18 -0700324 for outpkt, opt in [
325 (simple_tcp_packet(), "simple TCP packet"),
326 (simple_eth_packet(), "simple Ethernet packet"),
327 (simple_eth_packet(pktlen=40), "tiny Ethernet packet")]:
Dan Talaycodba244e2010-02-15 14:08:53 -0800328
Ed Swierk0aeff8c2012-03-23 20:27:18 -0700329 basic_logger.info("PKT OUT test with %s, port %s" % (opt, dp_port))
330 msg = message.packet_out()
331 msg.data = str(outpkt)
332 act = action.action_output()
333 act.port = dp_port
334 self.assertTrue(msg.actions.add(act), 'Could not add action to msg')
Dan Talaycodba244e2010-02-15 14:08:53 -0800335
Ed Swierk0aeff8c2012-03-23 20:27:18 -0700336 basic_logger.info("PacketOut to: " + str(dp_port))
337 rv = self.controller.message_send(msg)
338 self.assertTrue(rv == 0, "Error sending out message")
Dan Talaycodba244e2010-02-15 14:08:53 -0800339
Ed Swierk0aeff8c2012-03-23 20:27:18 -0700340 exp_pkt_arg = None
341 exp_port = None
342 if basic_config["relax"]:
343 exp_pkt_arg = outpkt
344 exp_port = dp_port
345 (of_port, pkt, pkt_time) = self.dataplane.poll(timeout=1,
346 port_number=exp_port,
347 exp_pkt=exp_pkt_arg)
348
349 self.assertTrue(pkt is not None, 'Packet not received')
350 basic_logger.info("PacketOut: got pkt from " + str(of_port))
351 if of_port is not None:
352 self.assertEqual(of_port, dp_port, "Unexpected receive port")
Ed Swierk506614a2012-03-29 08:16:59 -0700353 if not dataplane.match_exp_pkt(outpkt, pkt):
Dan Talayco2baf8b52012-03-30 09:55:42 -0700354 basic_logger.debug("Sent %s" % format_packet(outpkt))
355 basic_logger.debug("Resp %s" % format_packet(
356 str(pkt)[:len(str(outpkt))]))
Dan Talaycodc6fca32012-03-30 10:05:49 -0700357 self.assertEqual(str(outpkt), str(pkt)[:len(str(outpkt))],
358 'Response packet does not match send packet')
Dan Talaycodba244e2010-02-15 14:08:53 -0800359
Ken Chiang1bf01602012-04-04 10:48:23 -0700360class PacketOutMC(SimpleDataPlane):
361 """
362 Test packet out to multiple output ports
363
364 Send packet out message to controller for 1 to N dataplane ports and
365 verify the packet appears on the appropriate ports
366 """
367 def runTest(self):
368 # Construct packet to send to dataplane
369 # Send packet to dataplane
370 # Poll controller with expect message type packet in
371
372 rc = delete_all_flows(self.controller, basic_logger)
373 self.assertEqual(rc, 0, "Failed to delete all flows")
374
375 # These will get put into function
376 of_ports = basic_port_map.keys()
377 random.shuffle(of_ports)
378 for num_ports in range(1,len(of_ports)+1):
379 for outpkt, opt in [
380 (simple_tcp_packet(), "simple TCP packet"),
381 (simple_eth_packet(), "simple Ethernet packet"),
382 (simple_eth_packet(pktlen=40), "tiny Ethernet packet")]:
383
384 dp_ports = of_ports[0:num_ports]
385 basic_logger.info("PKT OUT test with " + opt +
386 ", ports " + str(dp_ports))
387 msg = message.packet_out()
388 msg.data = str(outpkt)
389 act = action.action_output()
390 for i in range(0,num_ports):
391 act.port = dp_ports[i]
392 self.assertTrue(msg.actions.add(act),
393 'Could not add action to msg')
394
395 basic_logger.info("PacketOut to: " + str(dp_ports))
396 rv = self.controller.message_send(msg)
397 self.assertTrue(rv == 0, "Error sending out message")
398
399 receive_pkt_check(self.dataplane, outpkt, dp_ports,
400 set(of_ports).difference(dp_ports),
401 self, basic_logger, basic_config)
402
Dan Talayco6ce963a2010-03-07 21:58:13 -0800403class FlowStatsGet(SimpleProtocol):
404 """
405 Get stats
Dan Talayco2c0dba32010-03-06 22:47:06 -0800406
Dan Talayco6ce963a2010-03-07 21:58:13 -0800407 Simply verify stats get transaction
408 """
409 def runTest(self):
410 basic_logger.info("Running StatsGet")
Dan Talayco41eae8b2010-03-10 13:57:06 -0800411 basic_logger.info("Inserting trial flow")
Dan Talayco677c0b72011-08-23 22:53:38 -0700412 request = flow_mod_gen(basic_port_map, True)
Dan Talayco41eae8b2010-03-10 13:57:06 -0800413 rv = self.controller.message_send(request)
414 self.assertTrue(rv != -1, "Failed to insert test flow")
415
416 basic_logger.info("Sending flow request")
Dan Talayco6ce963a2010-03-07 21:58:13 -0800417 request = message.flow_stats_request()
418 request.out_port = ofp.OFPP_NONE
Dan Talayco41eae8b2010-03-10 13:57:06 -0800419 request.table_id = 0xff
420 request.match.wildcards = 0 # ofp.OFPFW_ALL
Dan Talayco6ce963a2010-03-07 21:58:13 -0800421 response, pkt = self.controller.transact(request, timeout=2)
422 self.assertTrue(response is not None, "Did not get response")
Dan Talaycob3f43fe2010-05-13 14:24:20 -0700423 basic_logger.debug(response.show())
Dan Talayco6ce963a2010-03-07 21:58:13 -0800424
Dan Talayco677c0b72011-08-23 22:53:38 -0700425test_prio["FlowStatsGet"] = -1
426
Dan Talayco79c6c4d2010-06-08 14:01:53 -0700427class TableStatsGet(SimpleProtocol):
428 """
429 Get table stats
430
431 Simply verify table stats get transaction
432 """
433 def runTest(self):
434 basic_logger.info("Running TableStatsGet")
435 basic_logger.info("Inserting trial flow")
Dan Talayco677c0b72011-08-23 22:53:38 -0700436 request = flow_mod_gen(basic_port_map, True)
Dan Talayco79c6c4d2010-06-08 14:01:53 -0700437 rv = self.controller.message_send(request)
438 self.assertTrue(rv != -1, "Failed to insert test flow")
439
440 basic_logger.info("Sending table stats request")
441 request = message.table_stats_request()
442 response, pkt = self.controller.transact(request, timeout=2)
443 self.assertTrue(response is not None, "Did not get response")
444 basic_logger.debug(response.show())
445
Ed Swierkae74c362012-04-02 08:21:41 -0700446class DescStatsGet(SimpleProtocol):
447 """
448 Get stats
449
450 Simply verify stats get transaction
451 """
452 def runTest(self):
453 basic_logger.info("Running DescStatsGet")
454
455 basic_logger.info("Sending stats request")
456 request = message.desc_stats_request()
457 response, pkt = self.controller.transact(request, timeout=2)
458 self.assertTrue(response is not None, "Did not get response")
459 basic_logger.debug(response.show())
460
Dan Talayco6ce963a2010-03-07 21:58:13 -0800461class FlowMod(SimpleProtocol):
462 """
463 Insert a flow
464
465 Simple verification of a flow mod transaction
466 """
467
468 def runTest(self):
469 basic_logger.info("Running " + str(self))
Dan Talayco677c0b72011-08-23 22:53:38 -0700470 request = flow_mod_gen(basic_port_map, True)
Dan Talayco6ce963a2010-03-07 21:58:13 -0800471 rv = self.controller.message_send(request)
Dan Talayco41eae8b2010-03-10 13:57:06 -0800472 self.assertTrue(rv != -1, "Error installing flow mod")
473
Dan Talaycob3f43fe2010-05-13 14:24:20 -0700474class PortConfigMod(SimpleProtocol):
475 """
476 Modify a bit in port config and verify changed
477
478 Get the switch configuration, modify the port configuration
479 and write it back; get the config again and verify changed.
480 Then set it back to the way it was.
481 """
482
483 def runTest(self):
484 basic_logger.info("Running " + str(self))
Dan Talayco9f47f4d2010-06-03 13:54:37 -0700485 for of_port, ifname in basic_port_map.items(): # Grab first port
486 break
Dan Talaycob3f43fe2010-05-13 14:24:20 -0700487
Dan Talayco9f47f4d2010-06-03 13:54:37 -0700488 (hw_addr, config, advert) = \
489 port_config_get(self.controller, of_port, basic_logger)
490 self.assertTrue(config is not None, "Did not get port config")
491
492 basic_logger.debug("No flood bit port " + str(of_port) + " is now " +
493 str(config & ofp.OFPPC_NO_FLOOD))
494
495 rv = port_config_set(self.controller, of_port,
496 config ^ ofp.OFPPC_NO_FLOOD, ofp.OFPPC_NO_FLOOD,
497 basic_logger)
Dan Talaycob3f43fe2010-05-13 14:24:20 -0700498 self.assertTrue(rv != -1, "Error sending port mod")
499
500 # Verify change took place with same feature request
Dan Talayco9f47f4d2010-06-03 13:54:37 -0700501 (hw_addr, config2, advert) = \
502 port_config_get(self.controller, of_port, basic_logger)
503 basic_logger.debug("No flood bit port " + str(of_port) + " is now " +
504 str(config2 & ofp.OFPPC_NO_FLOOD))
505 self.assertTrue(config2 is not None, "Did not get port config2")
506 self.assertTrue(config2 & ofp.OFPPC_NO_FLOOD !=
507 config & ofp.OFPPC_NO_FLOOD,
508 "Bit change did not take")
Dan Talaycob3f43fe2010-05-13 14:24:20 -0700509 # Set it back
Dan Talayco9f47f4d2010-06-03 13:54:37 -0700510 rv = port_config_set(self.controller, of_port, config,
511 ofp.OFPPC_NO_FLOOD, basic_logger)
512 self.assertTrue(rv != -1, "Error sending port mod")
Dan Talaycob3f43fe2010-05-13 14:24:20 -0700513
Dan Talaycodba244e2010-02-15 14:08:53 -0800514if __name__ == "__main__":
Dan Talayco2c0dba32010-03-06 22:47:06 -0800515 print "Please run through oft script: ./oft --test_spec=basic"