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 | 28fa927 | 2013-03-08 16:00:25 -0800 | [diff] [blame] | 26 | m = ofp.message.vendor() |
Ed Swierk | 47f608d | 2012-11-12 15:36:32 -0800 | [diff] [blame] | 27 | m.vendor = 0x005c16c7 |
| 28 | m.data = struct.pack("!LBBBB", 3, enabled, 0, 0, 0) |
Rich Lane | 5c3151c | 2013-01-03 17:15:41 -0800 | [diff] [blame] | 29 | self.controller.message_send(m) |
Ed Swierk | 47f608d | 2012-11-12 15:36:32 -0800 | [diff] [blame] | 30 | |
| 31 | def bsn_get_mirroring(self): |
| 32 | """ |
| 33 | Use the BSN_GET_MIRRORING_REQUEST vendor command to get the |
| 34 | enabled/disabled state of mirror action support |
| 35 | """ |
Rich Lane | 28fa927 | 2013-03-08 16:00:25 -0800 | [diff] [blame] | 36 | m = ofp.message.vendor() |
Ed Swierk | 47f608d | 2012-11-12 15:36:32 -0800 | [diff] [blame] | 37 | m.vendor = 0x005c16c7 |
| 38 | m.data = struct.pack("!LBBBB", 4, 0, 0, 0, 0) |
Rich Lane | 5c3151c | 2013-01-03 17:15:41 -0800 | [diff] [blame] | 39 | self.controller.message_send(m) |
Ed Swierk | 47f608d | 2012-11-12 15:36:32 -0800 | [diff] [blame] | 40 | m, r = self.controller.poll(ofp.OFPT_VENDOR, 2) |
| 41 | self.assertEqual(m.vendor, 0x005c16c7, "Wrong vendor ID") |
| 42 | x = struct.unpack("!LBBBB", m.data) |
| 43 | self.assertEqual(x[0], 5, "Wrong subtype") |
| 44 | return x[1] |
| 45 | |
| 46 | def runTest(self): |
| 47 | mirror_ports = test_param_get("mirror_ports") |
| 48 | ports = [p for p in config["port_map"].keys() if p not in mirror_ports] |
| 49 | pkt = simple_tcp_packet() |
| 50 | match = packet_to_flow_match(self, pkt) |
| 51 | match.in_port = ports[0] |
| 52 | match.wildcards &= ~ofp.OFPFW_IN_PORT |
| 53 | |
| 54 | logging.info("Checking that mirror ports are not reported") |
| 55 | self.assertEqual(bool(self.bsn_get_mirroring()), False) |
Rich Lane | 28fa927 | 2013-03-08 16:00:25 -0800 | [diff] [blame] | 56 | m, r = self.controller.transact(ofp.message.features_request(), 2) |
Ed Swierk | 47f608d | 2012-11-12 15:36:32 -0800 | [diff] [blame] | 57 | p = dict([(pt.port_no, pt) for pt in m.ports]) |
| 58 | self.assertFalse(mirror_ports[0] in p or mirror_ports[1] in p, |
| 59 | "Mirror port in features reply") |
| 60 | |
| 61 | logging.info("Enabling mirror port reporting") |
| 62 | self.bsn_set_mirroring(True) |
| 63 | |
| 64 | logging.info("Checking that mirror ports are reported") |
| 65 | self.assertEqual(bool(self.bsn_get_mirroring()), True) |
Rich Lane | 28fa927 | 2013-03-08 16:00:25 -0800 | [diff] [blame] | 66 | m, r = self.controller.transact(ofp.message.features_request(), 2) |
Ed Swierk | 47f608d | 2012-11-12 15:36:32 -0800 | [diff] [blame] | 67 | p = dict([(pt.port_no, pt) for pt in m.ports]) |
| 68 | self.assertTrue(mirror_ports[0] in p and mirror_ports[1] in p, |
| 69 | "Mirror port not in features reply") |
| 70 | self.assertTrue(p[mirror_ports[0]].config & (1 << 31), |
| 71 | "Mirror port config flag not set in features reply") |
| 72 | self.assertTrue(p[mirror_ports[1]].config & (1 << 31), |
| 73 | "Mirror port config flag not set in features reply") |
| 74 | |
Rich Lane | b659c76 | 2013-03-11 23:08:36 -0700 | [diff] [blame] | 75 | act1 = ofp.action.bsn_mirror() |
Ed Swierk | 47f608d | 2012-11-12 15:36:32 -0800 | [diff] [blame] | 76 | act1.dest_port = mirror_ports[0] |
| 77 | act1.copy_stage = 0 |
Rich Lane | b659c76 | 2013-03-11 23:08:36 -0700 | [diff] [blame] | 78 | act2 = ofp.action.bsn_mirror() |
Ed Swierk | 47f608d | 2012-11-12 15:36:32 -0800 | [diff] [blame] | 79 | act2.dest_port = mirror_ports[1] |
| 80 | act2.copy_stage = 0 |
Rich Lane | 9d3cc6b | 2013-03-08 16:33:08 -0800 | [diff] [blame] | 81 | act3 = ofp.action.output() |
Ed Swierk | 47f608d | 2012-11-12 15:36:32 -0800 | [diff] [blame] | 82 | act3.port = ports[1] |
Rich Lane | ba3f0e2 | 2013-03-11 16:43:57 -0700 | [diff] [blame] | 83 | flow_mod = ofp.message.flow_add() |
Ed Swierk | 47f608d | 2012-11-12 15:36:32 -0800 | [diff] [blame] | 84 | flow_mod.match = match |
Rich Lane | c495d9e | 2013-03-08 17:43:36 -0800 | [diff] [blame] | 85 | flow_mod.actions.append(act1) |
| 86 | flow_mod.actions.append(act2) |
| 87 | flow_mod.actions.append(act3) |
Rich Lane | 32bf948 | 2013-01-03 17:26:30 -0800 | [diff] [blame] | 88 | delete_all_flows(self.controller) |
Rich Lane | 5c3151c | 2013-01-03 17:15:41 -0800 | [diff] [blame] | 89 | self.controller.message_send(flow_mod) |
Rich Lane | 3a261d5 | 2013-01-03 17:45:08 -0800 | [diff] [blame] | 90 | do_barrier(self.controller) |
Ed Swierk | 47f608d | 2012-11-12 15:36:32 -0800 | [diff] [blame] | 91 | |
| 92 | logging.info("Sending packet to port %s" % ports[0]) |
| 93 | self.dataplane.send(ports[0], str(pkt)) |
| 94 | logging.info("Checking that packet was received from output port %s, " |
| 95 | "mirror ports %s and %s" % ( |
| 96 | ports[1], mirror_ports[0], mirror_ports[1])) |
| 97 | receive_pkt_check(self.dataplane, pkt, |
| 98 | [ports[1], mirror_ports[0], mirror_ports[1]], [], |
| 99 | self) |