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 | |
Ed Swierk | 47f608d | 2012-11-12 15:36:32 -0800 | [diff] [blame] | 17 | """ |
| 18 | """ |
| 19 | import struct |
| 20 | |
| 21 | import logging |
| 22 | |
| 23 | from oftest import config |
| 24 | import oftest.controller as controller |
Rich Lane | d7b0ffa | 2013-03-08 15:53:42 -0800 | [diff] [blame] | 25 | import ofp |
Ed Swierk | 47f608d | 2012-11-12 15:36:32 -0800 | [diff] [blame] | 26 | import oftest.base_tests as base_tests |
| 27 | |
| 28 | from oftest.testutils import * |
| 29 | |
Rich Lane | 0a4f637 | 2013-01-02 14:40:22 -0800 | [diff] [blame] | 30 | @nonstandard |
Ed Swierk | 47f608d | 2012-11-12 15:36:32 -0800 | [diff] [blame] | 31 | class BSNMirrorAction(base_tests.SimpleDataPlane): |
| 32 | """ |
| 33 | Exercise BSN vendor extension for copying packets to a mirror destination |
| 34 | port |
| 35 | """ |
| 36 | |
Ed Swierk | 47f608d | 2012-11-12 15:36:32 -0800 | [diff] [blame] | 37 | def bsn_set_mirroring(self, enabled): |
| 38 | """ |
| 39 | Use the BSN_SET_MIRRORING vendor command to enable/disable |
| 40 | mirror action support |
| 41 | """ |
Rich Lane | 4b60145 | 2013-03-11 23:37:06 -0700 | [diff] [blame] | 42 | m = ofp.message.bsn_set_mirroring(report_mirror_ports=enabled) |
Rich Lane | 5c3151c | 2013-01-03 17:15:41 -0800 | [diff] [blame] | 43 | self.controller.message_send(m) |
Ed Swierk | 47f608d | 2012-11-12 15:36:32 -0800 | [diff] [blame] | 44 | |
| 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 Lane | 4b60145 | 2013-03-11 23:37:06 -0700 | [diff] [blame] | 50 | 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 Swierk | 47f608d | 2012-11-12 15:36:32 -0800 | [diff] [blame] | 54 | |
| 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 Lane | 28fa927 | 2013-03-08 16:00:25 -0800 | [diff] [blame] | 65 | m, r = self.controller.transact(ofp.message.features_request(), 2) |
Ed Swierk | 47f608d | 2012-11-12 15:36:32 -0800 | [diff] [blame] | 66 | 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 Lane | 28fa927 | 2013-03-08 16:00:25 -0800 | [diff] [blame] | 75 | m, r = self.controller.transact(ofp.message.features_request(), 2) |
Ed Swierk | 47f608d | 2012-11-12 15:36:32 -0800 | [diff] [blame] | 76 | 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 Lane | b659c76 | 2013-03-11 23:08:36 -0700 | [diff] [blame] | 84 | act1 = ofp.action.bsn_mirror() |
Ed Swierk | 47f608d | 2012-11-12 15:36:32 -0800 | [diff] [blame] | 85 | act1.dest_port = mirror_ports[0] |
| 86 | act1.copy_stage = 0 |
Rich Lane | b659c76 | 2013-03-11 23:08:36 -0700 | [diff] [blame] | 87 | act2 = ofp.action.bsn_mirror() |
Ed Swierk | 47f608d | 2012-11-12 15:36:32 -0800 | [diff] [blame] | 88 | act2.dest_port = mirror_ports[1] |
| 89 | act2.copy_stage = 0 |
Rich Lane | 9d3cc6b | 2013-03-08 16:33:08 -0800 | [diff] [blame] | 90 | act3 = ofp.action.output() |
Ed Swierk | 47f608d | 2012-11-12 15:36:32 -0800 | [diff] [blame] | 91 | act3.port = ports[1] |
Rich Lane | ba3f0e2 | 2013-03-11 16:43:57 -0700 | [diff] [blame] | 92 | flow_mod = ofp.message.flow_add() |
Ed Swierk | 47f608d | 2012-11-12 15:36:32 -0800 | [diff] [blame] | 93 | flow_mod.match = match |
Rich Lane | c495d9e | 2013-03-08 17:43:36 -0800 | [diff] [blame] | 94 | flow_mod.actions.append(act1) |
| 95 | flow_mod.actions.append(act2) |
| 96 | flow_mod.actions.append(act3) |
Rich Lane | 32bf948 | 2013-01-03 17:26:30 -0800 | [diff] [blame] | 97 | delete_all_flows(self.controller) |
Rich Lane | 5c3151c | 2013-01-03 17:15:41 -0800 | [diff] [blame] | 98 | self.controller.message_send(flow_mod) |
Rich Lane | 3a261d5 | 2013-01-03 17:45:08 -0800 | [diff] [blame] | 99 | do_barrier(self.controller) |
Ed Swierk | 47f608d | 2012-11-12 15:36:32 -0800 | [diff] [blame] | 100 | |
| 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 Lane | e4b384d | 2013-09-13 14:33:40 -0700 | [diff] [blame] | 106 | verify_packets(self, pkt, [ports[1], mirror_ports[0], mirror_ports[1]]) |