blob: 27ebb9e3ba8b395d6969183009e8ed4b3ab61edc [file] [log] [blame]
Rich Laneea873262013-01-11 08:15:55 -08001'''
2Created on Jan 27, 2011
3
4@author: capveg
5'''
6
7import logging
8
9import ofp
10from oftest import config
11import oftest.oft12.testutils as testutils
12import oftest.base_tests as base_tests
13
14class FlowMod_ModifyStrict(base_tests.SimpleProtocol):
15 """ Simple FlowMod Modify test
16 delete all flows in the table
17 insert an exact match flow_mod sending to port[1]
18 then swap the output action from port[1] to port[2]
19 then get flow_stats
20 assert that the new actions are in place
21 """
22 def runTest(self):
23 ing_port = config["port_map"].keys()[0]
24 out_port1 = config["port_map"].keys()[1]
25 out_port2 = config["port_map"].keys()[2]
26 pkt = testutils.simple_tcp_packet()
27 testutils.delete_all_flows(self.controller, logging)
28 fm_orig = testutils.flow_msg_create(self, pkt,
29 ing_port=ing_port,
30 egr_port=out_port1)
31 fm_new = testutils.flow_msg_create(self, pkt,
32 ing_port=ing_port,
33 egr_port=out_port2)
34 fm_new.command = ofp.OFPFC_MODIFY_STRICT
35 rv = self.controller.message_send(fm_orig)
36 self.assertEqual(rv, 0, "Failed to insert 1st flow_mod")
37 testutils.do_barrier(self.controller)
38 rv = self.controller.message_send(fm_new)
39 testutils.do_barrier(self.controller)
40 self.assertEqual(rv, 0, "Failed to insert 2nd flow_mod")
41 flow_stats = testutils.flow_stats_get(self)
Rich Lane97b61c12013-05-07 15:32:41 -070042 self.assertEqual(len(flow_stats.entries),1,
Rich Laneea873262013-01-11 08:15:55 -080043 "Expected only one flow_mod")
Rich Lane97b61c12013-05-07 15:32:41 -070044 stat = flow_stats.entries[0]
45
46 def canonicalize_match(match):
47 match.oxm_list.sort(key=lambda x: x.type_len)
48
49 canonicalize_match(stat.match)
50 canonicalize_match(fm_new.match)
Rich Laneea873262013-01-11 08:15:55 -080051 self.assertEqual(stat.match, fm_new.match)
Rich Laneea873262013-01-11 08:15:55 -080052 self.assertEqual(stat.instructions, fm_new.instructions)
53 # @todo consider adding more tests here
54
55
56if __name__ == "__main__":
57 print "Please run through oft script: ./oft --test_spec=flow_mods"