blob: 7f40534ce715853a336fc010186b8b4c93f7ed60 [file] [log] [blame]
Ed Swierk47f608d2012-11-12 15:36:32 -08001"""
2"""
3import struct
4
5import logging
6
7from oftest import config
8import oftest.controller as controller
Rich Laned7b0ffa2013-03-08 15:53:42 -08009import ofp
Ed Swierk47f608d2012-11-12 15:36:32 -080010import oftest.base_tests as base_tests
11
12from oftest.testutils import *
13
Rich Lane0a4f6372013-01-02 14:40:22 -080014@nonstandard
Ed Swierk47f608d2012-11-12 15:36:32 -080015class BSNMirrorAction(base_tests.SimpleDataPlane):
16 """
17 Exercise BSN vendor extension for copying packets to a mirror destination
18 port
19 """
20
Ed Swierk47f608d2012-11-12 15:36:32 -080021 def bsn_set_mirroring(self, enabled):
22 """
23 Use the BSN_SET_MIRRORING vendor command to enable/disable
24 mirror action support
25 """
Rich Lane4b601452013-03-11 23:37:06 -070026 m = ofp.message.bsn_set_mirroring(report_mirror_ports=enabled)
Rich Lane5c3151c2013-01-03 17:15:41 -080027 self.controller.message_send(m)
Ed Swierk47f608d2012-11-12 15:36:32 -080028
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 Lane4b601452013-03-11 23:37:06 -070034 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 Swierk47f608d2012-11-12 15:36:32 -080038
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 Lane28fa9272013-03-08 16:00:25 -080049 m, r = self.controller.transact(ofp.message.features_request(), 2)
Ed Swierk47f608d2012-11-12 15:36:32 -080050 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 Lane28fa9272013-03-08 16:00:25 -080059 m, r = self.controller.transact(ofp.message.features_request(), 2)
Ed Swierk47f608d2012-11-12 15:36:32 -080060 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 Laneb659c762013-03-11 23:08:36 -070068 act1 = ofp.action.bsn_mirror()
Ed Swierk47f608d2012-11-12 15:36:32 -080069 act1.dest_port = mirror_ports[0]
70 act1.copy_stage = 0
Rich Laneb659c762013-03-11 23:08:36 -070071 act2 = ofp.action.bsn_mirror()
Ed Swierk47f608d2012-11-12 15:36:32 -080072 act2.dest_port = mirror_ports[1]
73 act2.copy_stage = 0
Rich Lane9d3cc6b2013-03-08 16:33:08 -080074 act3 = ofp.action.output()
Ed Swierk47f608d2012-11-12 15:36:32 -080075 act3.port = ports[1]
Rich Laneba3f0e22013-03-11 16:43:57 -070076 flow_mod = ofp.message.flow_add()
Ed Swierk47f608d2012-11-12 15:36:32 -080077 flow_mod.match = match
Rich Lanec495d9e2013-03-08 17:43:36 -080078 flow_mod.actions.append(act1)
79 flow_mod.actions.append(act2)
80 flow_mod.actions.append(act3)
Rich Lane32bf9482013-01-03 17:26:30 -080081 delete_all_flows(self.controller)
Rich Lane5c3151c2013-01-03 17:15:41 -080082 self.controller.message_send(flow_mod)
Rich Lane3a261d52013-01-03 17:45:08 -080083 do_barrier(self.controller)
Ed Swierk47f608d2012-11-12 15:36:32 -080084
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 Lanee4b384d2013-09-13 14:33:40 -070090 verify_packets(self, pkt, [ports[1], mirror_ports[0], mirror_ports[1]])