blob: f22a871bf104b720f9c8e42e137b9a8e0e4da3c4 [file] [log] [blame]
Matteo Scandoloa229eca2017-08-08 13:05:28 -07001
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 Laneea873262013-01-11 08:15:55 -080017'''
18Created on Jan 27, 2011
19
20@author: capveg
21'''
22
23import logging
24
25import ofp
26from oftest import config
27import oftest.oft12.testutils as testutils
28import oftest.base_tests as base_tests
29
30class 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 Lane97b61c12013-05-07 15:32:41 -070058 self.assertEqual(len(flow_stats.entries),1,
Rich Laneea873262013-01-11 08:15:55 -080059 "Expected only one flow_mod")
Rich Lane97b61c12013-05-07 15:32:41 -070060 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 Laneea873262013-01-11 08:15:55 -080067 self.assertEqual(stat.match, fm_new.match)
Rich Laneea873262013-01-11 08:15:55 -080068 self.assertEqual(stat.instructions, fm_new.instructions)
69 # @todo consider adding more tests here
70
71
72if __name__ == "__main__":
73 print "Please run through oft script: ./oft --test_spec=flow_mods"