Rich Lane | ea87326 | 2013-01-11 08:15:55 -0800 | [diff] [blame] | 1 | ''' |
| 2 | Created on Jan 27, 2011 |
| 3 | |
| 4 | @author: capveg |
| 5 | ''' |
| 6 | |
| 7 | import logging |
| 8 | |
| 9 | import ofp |
| 10 | from oftest import config |
| 11 | import oftest.oft12.testutils as testutils |
| 12 | import oftest.base_tests as base_tests |
| 13 | |
| 14 | class 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 Lane | 97b61c1 | 2013-05-07 15:32:41 -0700 | [diff] [blame] | 42 | self.assertEqual(len(flow_stats.entries),1, |
Rich Lane | ea87326 | 2013-01-11 08:15:55 -0800 | [diff] [blame] | 43 | "Expected only one flow_mod") |
Rich Lane | 97b61c1 | 2013-05-07 15:32:41 -0700 | [diff] [blame] | 44 | 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 Lane | ea87326 | 2013-01-11 08:15:55 -0800 | [diff] [blame] | 51 | self.assertEqual(stat.match, fm_new.match) |
Rich Lane | ea87326 | 2013-01-11 08:15:55 -0800 | [diff] [blame] | 52 | self.assertEqual(stat.instructions, fm_new.instructions) |
| 53 | # @todo consider adding more tests here |
| 54 | |
| 55 | |
| 56 | if __name__ == "__main__": |
| 57 | print "Please run through oft script: ./oft --test_spec=flow_mods" |