blob: 054f3742a9c85bb6442e65117ccd24c88d7da09f [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
Ed Swierk47f608d2012-11-12 15:36:32 -080017"""
18"""
19import struct
20
21import logging
22
23from oftest import config
24import oftest.controller as controller
Rich Laned7b0ffa2013-03-08 15:53:42 -080025import ofp
Ed Swierk47f608d2012-11-12 15:36:32 -080026import oftest.base_tests as base_tests
27
28from oftest.testutils import *
29
Rich Lane0a4f6372013-01-02 14:40:22 -080030@nonstandard
Ed Swierk47f608d2012-11-12 15:36:32 -080031class BSNMirrorAction(base_tests.SimpleDataPlane):
32 """
33 Exercise BSN vendor extension for copying packets to a mirror destination
34 port
35 """
36
Ed Swierk47f608d2012-11-12 15:36:32 -080037 def bsn_set_mirroring(self, enabled):
38 """
39 Use the BSN_SET_MIRRORING vendor command to enable/disable
40 mirror action support
41 """
Rich Lane4b601452013-03-11 23:37:06 -070042 m = ofp.message.bsn_set_mirroring(report_mirror_ports=enabled)
Rich Lane5c3151c2013-01-03 17:15:41 -080043 self.controller.message_send(m)
Ed Swierk47f608d2012-11-12 15:36:32 -080044
45 def bsn_get_mirroring(self):
46 """
47 Use the BSN_GET_MIRRORING_REQUEST vendor command to get the
48 enabled/disabled state of mirror action support
49 """
Rich Lane4b601452013-03-11 23:37:06 -070050 request = ofp.message.bsn_get_mirroring_request()
51 reply, _ = self.controller.transact(request)
52 self.assertTrue(isinstance(reply, ofp.message.bsn_get_mirroring_reply), "Unexpected reply type")
53 return reply.report_mirror_ports
Ed Swierk47f608d2012-11-12 15:36:32 -080054
55 def runTest(self):
56 mirror_ports = test_param_get("mirror_ports")
57 ports = [p for p in config["port_map"].keys() if p not in mirror_ports]
58 pkt = simple_tcp_packet()
59 match = packet_to_flow_match(self, pkt)
60 match.in_port = ports[0]
61 match.wildcards &= ~ofp.OFPFW_IN_PORT
62
63 logging.info("Checking that mirror ports are not reported")
64 self.assertEqual(bool(self.bsn_get_mirroring()), False)
Rich Lane28fa9272013-03-08 16:00:25 -080065 m, r = self.controller.transact(ofp.message.features_request(), 2)
Ed Swierk47f608d2012-11-12 15:36:32 -080066 p = dict([(pt.port_no, pt) for pt in m.ports])
67 self.assertFalse(mirror_ports[0] in p or mirror_ports[1] in p,
68 "Mirror port in features reply")
69
70 logging.info("Enabling mirror port reporting")
71 self.bsn_set_mirroring(True)
72
73 logging.info("Checking that mirror ports are reported")
74 self.assertEqual(bool(self.bsn_get_mirroring()), True)
Rich Lane28fa9272013-03-08 16:00:25 -080075 m, r = self.controller.transact(ofp.message.features_request(), 2)
Ed Swierk47f608d2012-11-12 15:36:32 -080076 p = dict([(pt.port_no, pt) for pt in m.ports])
77 self.assertTrue(mirror_ports[0] in p and mirror_ports[1] in p,
78 "Mirror port not in features reply")
79 self.assertTrue(p[mirror_ports[0]].config & (1 << 31),
80 "Mirror port config flag not set in features reply")
81 self.assertTrue(p[mirror_ports[1]].config & (1 << 31),
82 "Mirror port config flag not set in features reply")
83
Rich Laneb659c762013-03-11 23:08:36 -070084 act1 = ofp.action.bsn_mirror()
Ed Swierk47f608d2012-11-12 15:36:32 -080085 act1.dest_port = mirror_ports[0]
86 act1.copy_stage = 0
Rich Laneb659c762013-03-11 23:08:36 -070087 act2 = ofp.action.bsn_mirror()
Ed Swierk47f608d2012-11-12 15:36:32 -080088 act2.dest_port = mirror_ports[1]
89 act2.copy_stage = 0
Rich Lane9d3cc6b2013-03-08 16:33:08 -080090 act3 = ofp.action.output()
Ed Swierk47f608d2012-11-12 15:36:32 -080091 act3.port = ports[1]
Rich Laneba3f0e22013-03-11 16:43:57 -070092 flow_mod = ofp.message.flow_add()
Ed Swierk47f608d2012-11-12 15:36:32 -080093 flow_mod.match = match
Rich Lanec495d9e2013-03-08 17:43:36 -080094 flow_mod.actions.append(act1)
95 flow_mod.actions.append(act2)
96 flow_mod.actions.append(act3)
Rich Lane32bf9482013-01-03 17:26:30 -080097 delete_all_flows(self.controller)
Rich Lane5c3151c2013-01-03 17:15:41 -080098 self.controller.message_send(flow_mod)
Rich Lane3a261d52013-01-03 17:45:08 -080099 do_barrier(self.controller)
Ed Swierk47f608d2012-11-12 15:36:32 -0800100
101 logging.info("Sending packet to port %s" % ports[0])
102 self.dataplane.send(ports[0], str(pkt))
103 logging.info("Checking that packet was received from output port %s, "
104 "mirror ports %s and %s" % (
105 ports[1], mirror_ports[0], mirror_ports[1]))
Rich Lanee4b384d2013-09-13 14:33:40 -0700106 verify_packets(self, pkt, [ports[1], mirror_ports[0], mirror_ports[1]])