Matteo Scandolo | a229eca | 2017-08-08 13:05:28 -0700 | [diff] [blame] | 1 | |
| 2 | # Copyright 2017-present Open Networking Foundation |
| 3 | # |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | # you may not use this file except in compliance with the License. |
| 6 | # You may obtain a copy of the License at |
| 7 | # |
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | # |
| 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | # See the License for the specific language governing permissions and |
| 14 | # limitations under the License. |
| 15 | |
| 16 | |
Rich Lane | ea87326 | 2013-01-11 08:15:55 -0800 | [diff] [blame] | 17 | ''' |
| 18 | Created on Jan 27, 2011 |
| 19 | |
| 20 | @author: capveg |
| 21 | ''' |
| 22 | |
| 23 | import logging |
| 24 | |
| 25 | import ofp |
| 26 | from oftest import config |
| 27 | import oftest.oft12.testutils as testutils |
| 28 | import oftest.base_tests as base_tests |
| 29 | |
| 30 | class FlowMod_ModifyStrict(base_tests.SimpleProtocol): |
| 31 | """ Simple FlowMod Modify test |
| 32 | delete all flows in the table |
| 33 | insert an exact match flow_mod sending to port[1] |
| 34 | then swap the output action from port[1] to port[2] |
| 35 | then get flow_stats |
| 36 | assert that the new actions are in place |
| 37 | """ |
| 38 | def runTest(self): |
| 39 | ing_port = config["port_map"].keys()[0] |
| 40 | out_port1 = config["port_map"].keys()[1] |
| 41 | out_port2 = config["port_map"].keys()[2] |
| 42 | pkt = testutils.simple_tcp_packet() |
| 43 | testutils.delete_all_flows(self.controller, logging) |
| 44 | fm_orig = testutils.flow_msg_create(self, pkt, |
| 45 | ing_port=ing_port, |
| 46 | egr_port=out_port1) |
| 47 | fm_new = testutils.flow_msg_create(self, pkt, |
| 48 | ing_port=ing_port, |
| 49 | egr_port=out_port2) |
| 50 | fm_new.command = ofp.OFPFC_MODIFY_STRICT |
| 51 | rv = self.controller.message_send(fm_orig) |
| 52 | self.assertEqual(rv, 0, "Failed to insert 1st flow_mod") |
| 53 | testutils.do_barrier(self.controller) |
| 54 | rv = self.controller.message_send(fm_new) |
| 55 | testutils.do_barrier(self.controller) |
| 56 | self.assertEqual(rv, 0, "Failed to insert 2nd flow_mod") |
| 57 | flow_stats = testutils.flow_stats_get(self) |
Rich Lane | 97b61c1 | 2013-05-07 15:32:41 -0700 | [diff] [blame] | 58 | self.assertEqual(len(flow_stats.entries),1, |
Rich Lane | ea87326 | 2013-01-11 08:15:55 -0800 | [diff] [blame] | 59 | "Expected only one flow_mod") |
Rich Lane | 97b61c1 | 2013-05-07 15:32:41 -0700 | [diff] [blame] | 60 | stat = flow_stats.entries[0] |
| 61 | |
| 62 | def canonicalize_match(match): |
| 63 | match.oxm_list.sort(key=lambda x: x.type_len) |
| 64 | |
| 65 | canonicalize_match(stat.match) |
| 66 | canonicalize_match(fm_new.match) |
Rich Lane | ea87326 | 2013-01-11 08:15:55 -0800 | [diff] [blame] | 67 | self.assertEqual(stat.match, fm_new.match) |
Rich Lane | ea87326 | 2013-01-11 08:15:55 -0800 | [diff] [blame] | 68 | self.assertEqual(stat.instructions, fm_new.instructions) |
| 69 | # @todo consider adding more tests here |
| 70 | |
| 71 | |
| 72 | if __name__ == "__main__": |
| 73 | print "Please run through oft script: ./oft --test_spec=flow_mods" |