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