blob: e9134451da9337d88e478db8609bed5c8785c085 [file] [log] [blame]
Dan Talayco942f5302012-04-12 22:32:34 -07001"""
2Prototype test cases related to operation under load
3
4It is recommended that these definitions be kept in their own
5namespace as different groups of tests will likely define
6similar identifiers.
7
Rich Lane477f4812012-10-04 22:49:00 -07008The switch is actively attempting to contact the controller at the address
9indicated in config.
Dan Talayco942f5302012-04-12 22:32:34 -070010
11In general these test cases make some assumption about the external
12configuration of the switch under test. For now, the assumption is
13that the first two OF ports are connected by a loopback cable.
14"""
15
16import copy
17
18import logging
19
20import unittest
21
Rich Lane477f4812012-10-04 22:49:00 -070022from oftest import config
Dan Talayco942f5302012-04-12 22:32:34 -070023import oftest.controller as controller
24import oftest.cstruct as ofp
25import oftest.message as message
26import oftest.dataplane as dataplane
27import oftest.action as action
28import oftest.parse as parse
Rich Laneb90a1c42012-10-05 09:16:05 -070029import oftest.base_tests as base_tests
Dan Talayco942f5302012-04-12 22:32:34 -070030import time
31
Rich Laneda3b5ad2012-10-03 09:05:32 -070032from oftest.testutils import *
Dan Talayco942f5302012-04-12 22:32:34 -070033
Rich Laneb90a1c42012-10-05 09:16:05 -070034class LoadBarrier(base_tests.SimpleProtocol):
Dan Talayco942f5302012-04-12 22:32:34 -070035 """
36 Test barrier under load with loopback
37
38 This test assumes there is a pair of ports on the switch with
39 a loopback cable connected and that spanning tree is disabled.
40 A flow is installed to cause a storm of packet-in messages
41 when a packet is sent to the loopbacked interface. After causing
42 this storm, a barrier request is sent.
43
44 The test succeeds if the barrier response is received. Otherwise
45 the test fails.
46 """
Rich Laned1d9c282012-10-04 22:07:10 -070047
48 priority = -1
49
Dan Talayco942f5302012-04-12 22:32:34 -070050 def runTest(self):
51 # Set up flow to send from port 1 to port 2 and copy to CPU
52 # Test parameter gives LB port base (assumes consecutive)
Rich Lane2014f9b2012-10-05 15:29:40 -070053 lb_port = test_param_get('lb_port', default=1)
54 barrier_count = test_param_get('barrier_count',
Dan Talayco942f5302012-04-12 22:32:34 -070055 default=10)
56
57 # Set controller to filter packet ins
58 self.controller.filter_packet_in = True
59 self.controller.pkt_in_filter_limit = 10
60
61 pkt = simple_tcp_packet()
Ed Swierk99a74de2012-08-22 06:40:54 -070062 match = packet_to_flow_match(self, pkt)
Dan Talayco942f5302012-04-12 22:32:34 -070063 match.wildcards &= ~ofp.OFPFW_IN_PORT
64 match.in_port = lb_port
65 act = action.action_output()
66 act.port = lb_port + 1
67
68 request = message.flow_mod()
69 request.match = match
70 request.hard_timeout = 2 * barrier_count
71
72 request.buffer_id = 0xffffffff
73 self.assertTrue(request.actions.add(act), "Could not add action")
74
75 act = action.action_output()
76 act.port = ofp.OFPP_CONTROLLER
77 self.assertTrue(request.actions.add(act), "Could not add action")
78
79 rv = self.controller.message_send(request)
80 self.assertTrue(rv != -1, "Error installing flow mod")
81 self.assertEqual(do_barrier(self.controller), 0, "Barrier failed")
82
83 # Create packet out and send to port lb_port + 1
84 msg = message.packet_out()
85 msg.data = str(pkt)
86 act = action.action_output()
87 act.port = lb_port + 1
88 self.assertTrue(msg.actions.add(act), 'Could not add action to msg')
Rich Lane9a003812012-10-04 17:17:59 -070089 logging.info("Sleeping before starting storm")
Dan Talayco942f5302012-04-12 22:32:34 -070090 time.sleep(1) # Root causing issue with fast disconnects
Rich Lane9a003812012-10-04 17:17:59 -070091 logging.info("Sending packet out to %d" % (lb_port + 1))
Dan Talayco942f5302012-04-12 22:32:34 -070092 rv = self.controller.message_send(msg)
93 self.assertTrue(rv == 0, "Error sending out message")
94
95 for idx in range(0, barrier_count):
96 self.assertEqual(do_barrier(self.controller), 0, "Barrier failed")
97 # To do: Add some interesting functionality here
Rich Lane9a003812012-10-04 17:17:59 -070098 logging.info("Barrier %d completed" % idx)
Dan Talayco942f5302012-04-12 22:32:34 -070099
100 # Clear the flow table when done
Rich Lane9a003812012-10-04 17:17:59 -0700101 logging.debug("Deleting all flows from switch")
102 rc = delete_all_flows(self.controller)
Dan Talayco942f5302012-04-12 22:32:34 -0700103 self.assertEqual(rc, 0, "Failed to delete all flows")