Ed Swierk | 47f608d | 2012-11-12 15:36:32 -0800 | [diff] [blame] | 1 | """ |
| 2 | """ |
| 3 | import struct |
| 4 | |
| 5 | import logging |
| 6 | |
| 7 | from oftest import config |
| 8 | import oftest.controller as controller |
Rich Lane | d7b0ffa | 2013-03-08 15:53:42 -0800 | [diff] [blame] | 9 | import ofp |
Ed Swierk | 47f608d | 2012-11-12 15:36:32 -0800 | [diff] [blame] | 10 | import oftest.base_tests as base_tests |
| 11 | |
| 12 | from oftest.testutils import * |
| 13 | |
Rich Lane | 0a4f637 | 2013-01-02 14:40:22 -0800 | [diff] [blame] | 14 | @nonstandard |
Ed Swierk | 47f608d | 2012-11-12 15:36:32 -0800 | [diff] [blame] | 15 | class BSNMirrorAction(base_tests.SimpleDataPlane): |
| 16 | """ |
| 17 | Exercise BSN vendor extension for copying packets to a mirror destination |
| 18 | port |
| 19 | """ |
| 20 | |
Ed Swierk | 47f608d | 2012-11-12 15:36:32 -0800 | [diff] [blame] | 21 | def bsn_set_mirroring(self, enabled): |
| 22 | """ |
| 23 | Use the BSN_SET_MIRRORING vendor command to enable/disable |
| 24 | mirror action support |
| 25 | """ |
Rich Lane | 4b60145 | 2013-03-11 23:37:06 -0700 | [diff] [blame] | 26 | m = ofp.message.bsn_set_mirroring(report_mirror_ports=enabled) |
Rich Lane | 5c3151c | 2013-01-03 17:15:41 -0800 | [diff] [blame] | 27 | self.controller.message_send(m) |
Ed Swierk | 47f608d | 2012-11-12 15:36:32 -0800 | [diff] [blame] | 28 | |
| 29 | def bsn_get_mirroring(self): |
| 30 | """ |
| 31 | Use the BSN_GET_MIRRORING_REQUEST vendor command to get the |
| 32 | enabled/disabled state of mirror action support |
| 33 | """ |
Rich Lane | 4b60145 | 2013-03-11 23:37:06 -0700 | [diff] [blame] | 34 | request = ofp.message.bsn_get_mirroring_request() |
| 35 | reply, _ = self.controller.transact(request) |
| 36 | self.assertTrue(isinstance(reply, ofp.message.bsn_get_mirroring_reply), "Unexpected reply type") |
| 37 | return reply.report_mirror_ports |
Ed Swierk | 47f608d | 2012-11-12 15:36:32 -0800 | [diff] [blame] | 38 | |
| 39 | def runTest(self): |
| 40 | mirror_ports = test_param_get("mirror_ports") |
| 41 | ports = [p for p in config["port_map"].keys() if p not in mirror_ports] |
| 42 | pkt = simple_tcp_packet() |
| 43 | match = packet_to_flow_match(self, pkt) |
| 44 | match.in_port = ports[0] |
| 45 | match.wildcards &= ~ofp.OFPFW_IN_PORT |
| 46 | |
| 47 | logging.info("Checking that mirror ports are not reported") |
| 48 | self.assertEqual(bool(self.bsn_get_mirroring()), False) |
Rich Lane | 28fa927 | 2013-03-08 16:00:25 -0800 | [diff] [blame] | 49 | m, r = self.controller.transact(ofp.message.features_request(), 2) |
Ed Swierk | 47f608d | 2012-11-12 15:36:32 -0800 | [diff] [blame] | 50 | p = dict([(pt.port_no, pt) for pt in m.ports]) |
| 51 | self.assertFalse(mirror_ports[0] in p or mirror_ports[1] in p, |
| 52 | "Mirror port in features reply") |
| 53 | |
| 54 | logging.info("Enabling mirror port reporting") |
| 55 | self.bsn_set_mirroring(True) |
| 56 | |
| 57 | logging.info("Checking that mirror ports are reported") |
| 58 | self.assertEqual(bool(self.bsn_get_mirroring()), True) |
Rich Lane | 28fa927 | 2013-03-08 16:00:25 -0800 | [diff] [blame] | 59 | m, r = self.controller.transact(ofp.message.features_request(), 2) |
Ed Swierk | 47f608d | 2012-11-12 15:36:32 -0800 | [diff] [blame] | 60 | p = dict([(pt.port_no, pt) for pt in m.ports]) |
| 61 | self.assertTrue(mirror_ports[0] in p and mirror_ports[1] in p, |
| 62 | "Mirror port not in features reply") |
| 63 | self.assertTrue(p[mirror_ports[0]].config & (1 << 31), |
| 64 | "Mirror port config flag not set in features reply") |
| 65 | self.assertTrue(p[mirror_ports[1]].config & (1 << 31), |
| 66 | "Mirror port config flag not set in features reply") |
| 67 | |
Rich Lane | b659c76 | 2013-03-11 23:08:36 -0700 | [diff] [blame] | 68 | act1 = ofp.action.bsn_mirror() |
Ed Swierk | 47f608d | 2012-11-12 15:36:32 -0800 | [diff] [blame] | 69 | act1.dest_port = mirror_ports[0] |
| 70 | act1.copy_stage = 0 |
Rich Lane | b659c76 | 2013-03-11 23:08:36 -0700 | [diff] [blame] | 71 | act2 = ofp.action.bsn_mirror() |
Ed Swierk | 47f608d | 2012-11-12 15:36:32 -0800 | [diff] [blame] | 72 | act2.dest_port = mirror_ports[1] |
| 73 | act2.copy_stage = 0 |
Rich Lane | 9d3cc6b | 2013-03-08 16:33:08 -0800 | [diff] [blame] | 74 | act3 = ofp.action.output() |
Ed Swierk | 47f608d | 2012-11-12 15:36:32 -0800 | [diff] [blame] | 75 | act3.port = ports[1] |
Rich Lane | ba3f0e2 | 2013-03-11 16:43:57 -0700 | [diff] [blame] | 76 | flow_mod = ofp.message.flow_add() |
Ed Swierk | 47f608d | 2012-11-12 15:36:32 -0800 | [diff] [blame] | 77 | flow_mod.match = match |
Rich Lane | c495d9e | 2013-03-08 17:43:36 -0800 | [diff] [blame] | 78 | flow_mod.actions.append(act1) |
| 79 | flow_mod.actions.append(act2) |
| 80 | flow_mod.actions.append(act3) |
Rich Lane | 32bf948 | 2013-01-03 17:26:30 -0800 | [diff] [blame] | 81 | delete_all_flows(self.controller) |
Rich Lane | 5c3151c | 2013-01-03 17:15:41 -0800 | [diff] [blame] | 82 | self.controller.message_send(flow_mod) |
Rich Lane | 3a261d5 | 2013-01-03 17:45:08 -0800 | [diff] [blame] | 83 | do_barrier(self.controller) |
Ed Swierk | 47f608d | 2012-11-12 15:36:32 -0800 | [diff] [blame] | 84 | |
| 85 | logging.info("Sending packet to port %s" % ports[0]) |
| 86 | self.dataplane.send(ports[0], str(pkt)) |
| 87 | logging.info("Checking that packet was received from output port %s, " |
| 88 | "mirror ports %s and %s" % ( |
| 89 | ports[1], mirror_ports[0], mirror_ports[1])) |
Rich Lane | e4b384d | 2013-09-13 14:33:40 -0700 | [diff] [blame] | 90 | verify_packets(self, pkt, [ports[1], mirror_ports[0], mirror_ports[1]]) |