blob: dadb42fb4490e8e32463a542f95586c070d62852 [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
Dan Talayco942f5302012-04-12 22:32:34 -070039#@var load_config Local copy of global configuration data
40load_config = None
41
42# For test priority
43#@var test_prio Set test priority for local tests
44test_prio = {}
45
46
47def test_set_init(config):
48 """
49 Set up function for packet action test classes
50
51 @param config The configuration dictionary; see oft
52 """
53
54 global load_port_map
Dan Talayco942f5302012-04-12 22:32:34 -070055 global load_config
56
Dan Talayco942f5302012-04-12 22:32:34 -070057 load_port_map = config["port_map"]
58 load_config = config
59
60class LoadBarrier(basic.SimpleProtocol):
61 """
62 Test barrier under load with loopback
63
64 This test assumes there is a pair of ports on the switch with
65 a loopback cable connected and that spanning tree is disabled.
66 A flow is installed to cause a storm of packet-in messages
67 when a packet is sent to the loopbacked interface. After causing
68 this storm, a barrier request is sent.
69
70 The test succeeds if the barrier response is received. Otherwise
71 the test fails.
72 """
73 def runTest(self):
74 # Set up flow to send from port 1 to port 2 and copy to CPU
75 # Test parameter gives LB port base (assumes consecutive)
76 lb_port = test_param_get(self.config, 'lb_port', default=1)
77 barrier_count = test_param_get(self.config, 'barrier_count',
78 default=10)
79
80 # Set controller to filter packet ins
81 self.controller.filter_packet_in = True
82 self.controller.pkt_in_filter_limit = 10
83
84 pkt = simple_tcp_packet()
Ed Swierk99a74de2012-08-22 06:40:54 -070085 match = packet_to_flow_match(self, pkt)
Dan Talayco942f5302012-04-12 22:32:34 -070086 match.wildcards &= ~ofp.OFPFW_IN_PORT
87 match.in_port = lb_port
88 act = action.action_output()
89 act.port = lb_port + 1
90
91 request = message.flow_mod()
92 request.match = match
93 request.hard_timeout = 2 * barrier_count
94
95 request.buffer_id = 0xffffffff
96 self.assertTrue(request.actions.add(act), "Could not add action")
97
98 act = action.action_output()
99 act.port = ofp.OFPP_CONTROLLER
100 self.assertTrue(request.actions.add(act), "Could not add action")
101
102 rv = self.controller.message_send(request)
103 self.assertTrue(rv != -1, "Error installing flow mod")
104 self.assertEqual(do_barrier(self.controller), 0, "Barrier failed")
105
106 # Create packet out and send to port lb_port + 1
107 msg = message.packet_out()
108 msg.data = str(pkt)
109 act = action.action_output()
110 act.port = lb_port + 1
111 self.assertTrue(msg.actions.add(act), 'Could not add action to msg')
Rich Lane9a003812012-10-04 17:17:59 -0700112 logging.info("Sleeping before starting storm")
Dan Talayco942f5302012-04-12 22:32:34 -0700113 time.sleep(1) # Root causing issue with fast disconnects
Rich Lane9a003812012-10-04 17:17:59 -0700114 logging.info("Sending packet out to %d" % (lb_port + 1))
Dan Talayco942f5302012-04-12 22:32:34 -0700115 rv = self.controller.message_send(msg)
116 self.assertTrue(rv == 0, "Error sending out message")
117
118 for idx in range(0, barrier_count):
119 self.assertEqual(do_barrier(self.controller), 0, "Barrier failed")
120 # To do: Add some interesting functionality here
Rich Lane9a003812012-10-04 17:17:59 -0700121 logging.info("Barrier %d completed" % idx)
Dan Talayco942f5302012-04-12 22:32:34 -0700122
123 # Clear the flow table when done
Rich Lane9a003812012-10-04 17:17:59 -0700124 logging.debug("Deleting all flows from switch")
125 rc = delete_all_flows(self.controller)
Dan Talayco942f5302012-04-12 22:32:34 -0700126 self.assertEqual(rc, 0, "Failed to delete all flows")
127
128# Do not run by default; still mysterious disconnects often
129test_prio["LoadBarrier"] = -1