blob: 4a6e9709273f548b1e5840c7b126a23329d89ba8 [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 Lane28fa9272013-03-08 16:00:25 -080026 m = ofp.message.vendor()
Ed Swierk47f608d2012-11-12 15:36:32 -080027 m.vendor = 0x005c16c7
28 m.data = struct.pack("!LBBBB", 3, enabled, 0, 0, 0)
Rich Lane5c3151c2013-01-03 17:15:41 -080029 self.controller.message_send(m)
Ed Swierk47f608d2012-11-12 15:36:32 -080030
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 Lane28fa9272013-03-08 16:00:25 -080036 m = ofp.message.vendor()
Ed Swierk47f608d2012-11-12 15:36:32 -080037 m.vendor = 0x005c16c7
38 m.data = struct.pack("!LBBBB", 4, 0, 0, 0, 0)
Rich Lane5c3151c2013-01-03 17:15:41 -080039 self.controller.message_send(m)
Ed Swierk47f608d2012-11-12 15:36:32 -080040 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 Lane28fa9272013-03-08 16:00:25 -080056 m, r = self.controller.transact(ofp.message.features_request(), 2)
Ed Swierk47f608d2012-11-12 15:36:32 -080057 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 Lane28fa9272013-03-08 16:00:25 -080066 m, r = self.controller.transact(ofp.message.features_request(), 2)
Ed Swierk47f608d2012-11-12 15:36:32 -080067 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 Laneb659c762013-03-11 23:08:36 -070075 act1 = ofp.action.bsn_mirror()
Ed Swierk47f608d2012-11-12 15:36:32 -080076 act1.dest_port = mirror_ports[0]
77 act1.copy_stage = 0
Rich Laneb659c762013-03-11 23:08:36 -070078 act2 = ofp.action.bsn_mirror()
Ed Swierk47f608d2012-11-12 15:36:32 -080079 act2.dest_port = mirror_ports[1]
80 act2.copy_stage = 0
Rich Lane9d3cc6b2013-03-08 16:33:08 -080081 act3 = ofp.action.output()
Ed Swierk47f608d2012-11-12 15:36:32 -080082 act3.port = ports[1]
Rich Laneba3f0e22013-03-11 16:43:57 -070083 flow_mod = ofp.message.flow_add()
Ed Swierk47f608d2012-11-12 15:36:32 -080084 flow_mod.match = match
Rich Lanec495d9e2013-03-08 17:43:36 -080085 flow_mod.actions.append(act1)
86 flow_mod.actions.append(act2)
87 flow_mod.actions.append(act3)
Rich Lane32bf9482013-01-03 17:26:30 -080088 delete_all_flows(self.controller)
Rich Lane5c3151c2013-01-03 17:15:41 -080089 self.controller.message_send(flow_mod)
Rich Lane3a261d52013-01-03 17:45:08 -080090 do_barrier(self.controller)
Ed Swierk47f608d2012-11-12 15:36:32 -080091
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)