blob: d09608e9598e9446bb830256042145768584d12a [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
8 The function test_set_init is called with a complete configuration
9dictionary prior to the invocation of any tests from this file.
10
11 The switch is actively attempting to contact the controller at the address
12indicated in oft_config
13
14In general these test cases make some assumption about the external
15configuration of the switch under test. For now, the assumption is
16that the first two OF ports are connected by a loopback cable.
17"""
18
19import copy
20
21import logging
22
23import unittest
24
25import oftest.controller as controller
26import oftest.cstruct as ofp
27import oftest.message as message
28import oftest.dataplane as dataplane
29import oftest.action as action
30import oftest.parse as parse
31import basic
32import time
33
Rich Laneda3b5ad2012-10-03 09:05:32 -070034from oftest.testutils import *
Dan Talayco942f5302012-04-12 22:32:34 -070035
36#@var load_port_map Local copy of the configuration map from OF port
37# numbers to OS interfaces
38load_port_map = None
39#@var load_logger Local logger object
40load_logger = None
41#@var load_config Local copy of global configuration data
42load_config = None
43
44# For test priority
45#@var test_prio Set test priority for local tests
46test_prio = {}
47
48
49def test_set_init(config):
50 """
51 Set up function for packet action test classes
52
53 @param config The configuration dictionary; see oft
54 """
55
56 global load_port_map
57 global load_logger
58 global load_config
59
60 load_logger = logging.getLogger("load")
61 load_logger.info("Initializing test set")
62 load_port_map = config["port_map"]
63 load_config = config
64
65class LoadBarrier(basic.SimpleProtocol):
66 """
67 Test barrier under load with loopback
68
69 This test assumes there is a pair of ports on the switch with
70 a loopback cable connected and that spanning tree is disabled.
71 A flow is installed to cause a storm of packet-in messages
72 when a packet is sent to the loopbacked interface. After causing
73 this storm, a barrier request is sent.
74
75 The test succeeds if the barrier response is received. Otherwise
76 the test fails.
77 """
78 def runTest(self):
79 # Set up flow to send from port 1 to port 2 and copy to CPU
80 # Test parameter gives LB port base (assumes consecutive)
81 lb_port = test_param_get(self.config, 'lb_port', default=1)
82 barrier_count = test_param_get(self.config, 'barrier_count',
83 default=10)
84
85 # Set controller to filter packet ins
86 self.controller.filter_packet_in = True
87 self.controller.pkt_in_filter_limit = 10
88
89 pkt = simple_tcp_packet()
Ed Swierk99a74de2012-08-22 06:40:54 -070090 match = packet_to_flow_match(self, pkt)
Dan Talayco942f5302012-04-12 22:32:34 -070091 match.wildcards &= ~ofp.OFPFW_IN_PORT
92 match.in_port = lb_port
93 act = action.action_output()
94 act.port = lb_port + 1
95
96 request = message.flow_mod()
97 request.match = match
98 request.hard_timeout = 2 * barrier_count
99
100 request.buffer_id = 0xffffffff
101 self.assertTrue(request.actions.add(act), "Could not add action")
102
103 act = action.action_output()
104 act.port = ofp.OFPP_CONTROLLER
105 self.assertTrue(request.actions.add(act), "Could not add action")
106
107 rv = self.controller.message_send(request)
108 self.assertTrue(rv != -1, "Error installing flow mod")
109 self.assertEqual(do_barrier(self.controller), 0, "Barrier failed")
110
111 # Create packet out and send to port lb_port + 1
112 msg = message.packet_out()
113 msg.data = str(pkt)
114 act = action.action_output()
115 act.port = lb_port + 1
116 self.assertTrue(msg.actions.add(act), 'Could not add action to msg')
117 load_logger.info("Sleeping before starting storm")
118 time.sleep(1) # Root causing issue with fast disconnects
119 load_logger.info("Sending packet out to %d" % (lb_port + 1))
120 rv = self.controller.message_send(msg)
121 self.assertTrue(rv == 0, "Error sending out message")
122
123 for idx in range(0, barrier_count):
124 self.assertEqual(do_barrier(self.controller), 0, "Barrier failed")
125 # To do: Add some interesting functionality here
126 load_logger.info("Barrier %d completed" % idx)
127
128 # Clear the flow table when done
129 load_logger.debug("Deleting all flows from switch")
130 rc = delete_all_flows(self.controller, load_logger)
131 self.assertEqual(rc, 0, "Failed to delete all flows")
132
133# Do not run by default; still mysterious disconnects often
134test_prio["LoadBarrier"] = -1