blob: 9a768c22293a25662acf3f9fe67ffd9140cb1825 [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 Lane51c924b2014-03-28 16:25:55 -070017# Distributed under the OpenFlow Software License (see LICENSE)
18# Copyright (c) 2014 Big Switch Networks, Inc.
19"""
20Flow-mod test cases
21"""
22
23import logging
24
25import oftest
26from oftest import config
27import oftest.base_tests as base_tests
28import ofp
29from loxi.pp import pp
30
31from oftest.testutils import *
32from oftest.parse import parse_ipv6
33
34class Overwrite(base_tests.SimpleDataPlane):
35 """
36 Verify that overwriting a flow changes most fields but preserves stats
37 """
38 def runTest(self):
39 in_port, out_port1, out_port2 = openflow_ports(3)
40
41 delete_all_flows(self.controller)
42
43 table_id = test_param_get("table", 0)
44 match = ofp.match([
45 ofp.oxm.in_port(in_port),
46 ])
47 priority = 1000
48
49 logging.info("Inserting flow")
50 request = ofp.message.flow_add(
51 table_id=table_id,
52 match=match,
53 instructions=[
54 ofp.instruction.apply_actions([ofp.action.output(out_port1)]),
55 ],
56 buffer_id=ofp.OFP_NO_BUFFER,
57 priority=priority,
58 flags=ofp.OFPFF_SEND_FLOW_REM,
59 cookie=0x1234,
60 hard_timeout=1000,
61 idle_timeout=2000)
62 self.controller.message_send(request)
63 do_barrier(self.controller)
64
65 # Send a packet through so that we can check stats were preserved
66 self.dataplane.send(in_port, str(simple_tcp_packet(pktlen=100)))
67 verify_flow_stats(self, ofp.match(), table_id=table_id, pkts=1)
68
69 # Send a flow-add with the same table_id, match, and priority, causing
70 # an overwrite
71 logging.info("Overwriting flow")
72 request = ofp.message.flow_add(
73 table_id=table_id,
74 match=match,
75 instructions=[
76 ofp.instruction.apply_actions([ofp.action.output(out_port2)]),
77 ],
78 buffer_id=ofp.OFP_NO_BUFFER,
79 priority=priority,
80 flags=0,
81 cookie=0xabcd,
82 hard_timeout=3000,
83 idle_timeout=4000)
84 self.controller.message_send(request)
85 do_barrier(self.controller)
86
87 # Should not get a flow-removed message
88 msg, _ = self.controller.poll(exp_msg=ofp.message.flow_removed,
89 timeout=oftest.ofutils.default_negative_timeout)
90 self.assertEquals(msg, None)
91
92 # Check that the fields in the flow stats entry match the second flow-add
93 stats = get_flow_stats(self, ofp.match())
94 self.assertEquals(len(stats), 1)
95 entry = stats[0]
96 logging.debug(entry.show())
97 self.assertEquals(entry.instructions, request.instructions)
98 self.assertEquals(entry.flags, request.flags)
99 self.assertEquals(entry.cookie, request.cookie)
100 self.assertEquals(entry.hard_timeout, request.hard_timeout)
101 self.assertEquals(entry.idle_timeout, request.idle_timeout)
102
103 # Flow stats should have been preserved
104 verify_flow_stats(self, ofp.match(), table_id=table_id, pkts=1)