def test_local_flood_update(self): br = self.br with mock.patch.object(br, '_send_msg') as sendmsg: br.local_flood_update(network=1234, ports=[1, 2, 3], flood_unicast=True) (dp, ofp, ofpp) = br._get_dp() call = mock.call expected_calls = [ call( ofpp.OFPFlowMod( dp, instructions=[ ofpp.OFPInstructionActions(ofp.OFPIT_APPLY_ACTIONS, [ ofpp.OFPActionOutput(port=1), ofpp.OFPActionOutput(port=2), ofpp.OFPActionOutput(port=3) ]) ], match=ofpp.OFPMatch(metadata=meta.mk_metadata(1234)), priority=1, table_id=13)), call( ofpp.OFPFlowMod(dp, command=ofp.OFPFC_DELETE_STRICT, match=ofpp.OFPMatch( eth_dst=('01:00:00:00:00:00', '01:00:00:00:00:00'), metadata=meta.mk_metadata(1234)), out_group=ofp.OFPG_ANY, out_port=ofp.OFPP_ANY, priority=1, table_id=13)) ] sendmsg.assert_has_calls(expected_calls)
def provision_tenant_physnet(self, network_type, network, segmentation_id, phys_port): """for vlan and flat.""" assert network_type in [p_const.TYPE_VLAN, p_const.TYPE_FLAT] (dp, ofp, ofpp) = self._get_dp() # inbound metadata = meta.mk_metadata(network) instructions = [ofpp.OFPInstructionWriteMetadata(metadata=metadata[0], metadata_mask=metadata[1])] if network_type == p_const.TYPE_VLAN: vlan_vid = segmentation_id | ofp.OFPVID_PRESENT match = ofpp.OFPMatch(in_port=phys_port, vlan_vid=vlan_vid) actions = [ofpp.OFPActionPopVlan()] instructions += [ofpp.OFPInstructionActions(ofp.OFPIT_APPLY_ACTIONS, actions)] else: match = ofpp.OFPMatch(in_port=phys_port) instructions += [ofpp.OFPInstructionGotoTable(table_id=tables.PHYS_IN)] msg = ofpp.OFPFlowMod(dp, priority=1, table_id=tables.CHECK_IN_PORT, match=match, instructions=instructions) self._send_msg(msg) # outbound match = ofpp.OFPMatch(metadata=meta.mk_metadata(network, meta.LOCAL)) if network_type == p_const.TYPE_VLAN: actions = [ofpp.OFPActionPushVlan(), ofpp.OFPActionSetField(vlan_vid=vlan_vid)] else: actions = [] actions += [ofpp.OFPActionOutput(port=phys_port)] if network_type == p_const.TYPE_VLAN: actions += [ofpp.OFPActionPopVlan()] instructions = [ ofpp.OFPInstructionActions(ofp.OFPIT_APPLY_ACTIONS, actions), ofpp.OFPInstructionGotoTable(table_id=tables.PHYS_FLOOD + 1), ] msg = ofpp.OFPFlowMod(dp, priority=1, table_id=tables.PHYS_FLOOD, match=match, instructions=instructions) self._send_msg(msg)
def local_flood_update(self, network, ports, flood_unicast): (dp, ofp, ofpp) = self._get_dp() match_all = ofpp.OFPMatch(metadata=meta.mk_metadata(network)) match_multicast = ofpp.OFPMatch(metadata=meta.mk_metadata(network), eth_dst=('01:00:00:00:00:00', '01:00:00:00:00:00')) if flood_unicast: match_add = match_all match_del = match_multicast else: match_add = match_multicast match_del = match_all actions = [ofpp.OFPActionOutput(port=p) for p in ports] instructions = [ ofpp.OFPInstructionActions(ofp.OFPIT_APPLY_ACTIONS, actions), ] msg = ofpp.OFPFlowMod(dp, table_id=tables.LOCAL_FLOOD, priority=1, match=match_add, instructions=instructions) self._send_msg(msg) self.delete_flows(table_id=tables.LOCAL_FLOOD, strict=True, priority=1, match=match_del)
def provision_tenant_physnet(self, network_type, network, segmentation_id, phys_port): """for vlan and flat.""" assert (network_type in [p_const.TYPE_VLAN, p_const.TYPE_FLAT]) (dp, ofp, ofpp) = self._get_dp() # inbound metadata = meta.mk_metadata(network) instructions = [ ofpp.OFPInstructionWriteMetadata(metadata=metadata[0], metadata_mask=metadata[1]) ] if network_type == p_const.TYPE_VLAN: vlan_vid = segmentation_id | ofp.OFPVID_PRESENT match = ofpp.OFPMatch(in_port=phys_port, vlan_vid=vlan_vid) actions = [ofpp.OFPActionPopVlan()] instructions += [ ofpp.OFPInstructionActions(ofp.OFPIT_APPLY_ACTIONS, actions) ] else: match = ofpp.OFPMatch(in_port=phys_port) instructions += [ofpp.OFPInstructionGotoTable(table_id=tables.PHYS_IN)] msg = ofpp.OFPFlowMod(dp, priority=1, table_id=tables.CHECK_IN_PORT, match=match, instructions=instructions) self._send_msg(msg) # outbound match = ofpp.OFPMatch(metadata=meta.mk_metadata(network, meta.LOCAL)) if network_type == p_const.TYPE_VLAN: actions = [ ofpp.OFPActionPushVlan(), ofpp.OFPActionSetField(vlan_vid=vlan_vid), ] else: actions = [] actions += [ofpp.OFPActionOutput(port=phys_port)] if network_type == p_const.TYPE_VLAN: actions += [ofpp.OFPActionPopVlan()] instructions = [ ofpp.OFPInstructionActions(ofp.OFPIT_APPLY_ACTIONS, actions), ofpp.OFPInstructionGotoTable(table_id=tables.PHYS_FLOOD + 1), ] msg = ofpp.OFPFlowMod(dp, priority=1, table_id=tables.PHYS_FLOOD, match=match, instructions=instructions) self._send_msg(msg)
def test_reclaim_tenant_physnet(self): br = self.br with mock.patch.object(br, '_send_msg') as sendmsg: br.reclaim_tenant_physnet(network_type="vlan", network=150, segmentation_id=151, phys_port=99) (dp, ofp, ofpp) = br._get_dp() call = mock.call expected_calls = [ call( ofpp.OFPFlowMod(dp, command=ofp.OFPFC_DELETE, match=ofpp.OFPMatch(in_port=99, vlan_vid=151 | ofp.OFPVID_PRESENT), out_group=ofp.OFPG_ANY, out_port=ofp.OFPP_ANY, priority=0, table_id=0)), call( ofpp.OFPFlowMod( dp, command=ofp.OFPFC_DELETE, match=ofpp.OFPMatch(metadata=meta.mk_metadata(150)), out_group=ofp.OFPG_ANY, out_port=ofp.OFPP_ANY, priority=0, table_id=12)) ] sendmsg.assert_has_calls(expected_calls)
def test_install_tunnel_output(self): br = self.br with mock.patch.object(br, '_send_msg') as sendmsg: br.install_tunnel_output(table_id=110, network=111, segmentation_id=112, port=113, remote_ips=['192.0.2.8', '192.0.2.9'], goto_next=True) (dp, ofp, ofpp) = br._get_dp() call = mock.call expected_calls = [ call( ofpp.OFPFlowMod( dp, instructions=[ ofpp.OFPInstructionActions(ofp.OFPIT_APPLY_ACTIONS, [ ofpp.OFPActionSetField(tunnel_id=112), ofpp.OFPActionSetField(tun_ipv4_dst='192.0.2.8'), ofpp.OFPActionOutput(port=113), ofpp.OFPActionSetField(tun_ipv4_dst='192.0.2.9'), ofpp.OFPActionOutput(port=113) ]), ofpp.OFPInstructionGotoTable(table_id=111) ], match=ofpp.OFPMatch( metadata=meta.mk_metadata(111, meta.LOCAL)), priority=1, table_id=110)) ] sendmsg.assert_has_calls(expected_calls)
def local_out_add_port(self, network, port, mac): (dp, ofp, ofpp) = self._get_dp() match = ofpp.OFPMatch(metadata=meta.mk_metadata(network), eth_dst=mac) actions = [ofpp.OFPActionOutput(port=port)] instructions = [ofpp.OFPInstructionActions(ofp.OFPIT_APPLY_ACTIONS, actions)] msg = ofpp.OFPFlowMod(dp, table_id=tables.LOCAL_OUT, priority=1, match=match, instructions=instructions) self._send_msg(msg)
def local_flood_update(self, network, ports, flood_unicast): (dp, ofp, ofpp) = self._get_dp() match_all = ofpp.OFPMatch(metadata=meta.mk_metadata(network)) match_multicast = ofpp.OFPMatch( metadata=meta.mk_metadata(network), eth_dst=("01:00:00:00:00:00", "01:00:00:00:00:00") ) if flood_unicast: match_add = match_all match_del = match_multicast else: match_add = match_multicast match_del = match_all actions = [ofpp.OFPActionOutput(port=p) for p in ports] instructions = [ofpp.OFPInstructionActions(ofp.OFPIT_APPLY_ACTIONS, actions)] msg = ofpp.OFPFlowMod(dp, table_id=tables.LOCAL_FLOOD, priority=1, match=match_add, instructions=instructions) self._send_msg(msg) self.delete_flows(table_id=tables.LOCAL_FLOOD, strict=True, priority=1, match=match_del)
def reclaim_tenant_physnet(self, network_type, network, segmentation_id, phys_port): (_dp, ofp, _ofpp) = self._get_dp() vlan_vid = segmentation_id | ofp.OFPVID_PRESENT if network_type == p_const.TYPE_VLAN: self.delete_flows(table_id=tables.CHECK_IN_PORT, in_port=phys_port, vlan_vid=vlan_vid) else: self.delete_flows(table_id=tables.CHECK_IN_PORT, in_port=phys_port) self.delete_flows(table_id=tables.PHYS_FLOOD, metadata=meta.mk_metadata(network))
def check_in_port_add_local_port(self, network, port): (dp, ofp, ofpp) = self._get_dp() match = ofpp.OFPMatch(in_port=port) metadata = meta.mk_metadata(network, meta.LOCAL) instructions = [ ofpp.OFPInstructionWriteMetadata(metadata=metadata[0], metadata_mask=metadata[1]), ofpp.OFPInstructionGotoTable(table_id=tables.LOCAL_IN), ] msg = ofpp.OFPFlowMod(dp, table_id=tables.CHECK_IN_PORT, priority=1, match=match, instructions=instructions) self._send_msg(msg)
def arp_passthrough(self, network, tpa): (dp, ofp, ofpp) = self._get_dp() match = ofpp.OFPMatch( metadata=meta.mk_metadata(network), eth_type=ether.ETH_TYPE_ARP, arp_op=arp.ARP_REQUEST, arp_tpa=tpa ) instructions = [ofpp.OFPInstructionGotoTable(table_id=tables.TUNNEL_OUT)] msg = ofpp.OFPFlowMod( dp, table_id=tables.ARP_PASSTHROUGH, priority=1, idle_timeout=5, match=match, instructions=instructions ) self._send_msg(msg)
def provision_tenant_tunnel(self, network_type, network, segmentation_id): (dp, _ofp, ofpp) = self._get_dp() match = ofpp.OFPMatch(tunnel_id=segmentation_id) metadata = meta.mk_metadata(network) instructions = [ ofpp.OFPInstructionWriteMetadata(metadata=metadata[0], metadata_mask=metadata[1]), ofpp.OFPInstructionGotoTable(table_id=tables.TUNNEL_OUT), ] msg = ofpp.OFPFlowMod( dp, table_id=tables.TUNNEL_IN[network_type], priority=1, match=match, instructions=instructions ) self._send_msg(msg)
def test_local_flood_delete(self): br = self.br with mock.patch.object(br, '_send_msg') as sendmsg: br.local_flood_delete(network=1234) (dp, ofp, ofpp) = br._get_dp() call = mock.call expected_calls = [ call(ofpp.OFPFlowMod(dp, command=ofp.OFPFC_DELETE, match=ofpp.OFPMatch(metadata=meta.mk_metadata(1234)), out_group=ofp.OFPG_ANY, out_port=ofp.OFPP_ANY, priority=0, table_id=13)) ] sendmsg.assert_has_calls(expected_calls)
def test_local_out_delete_port(self): br = self.br with mock.patch.object(br, '_send_msg') as sendmsg: br.local_out_delete_port(network=1234, mac='12:34:56:78:9a:bc') (dp, ofp, ofpp) = br._get_dp() call = mock.call expected_calls = [ call(ofpp.OFPFlowMod(dp, command=ofp.OFPFC_DELETE, match=ofpp.OFPMatch(eth_dst="12:34:56:78:9a:bc", metadata=meta.mk_metadata(1234)), out_group=ofp.OFPG_ANY, out_port=ofp.OFPP_ANY, priority=0, table_id=8)) ] sendmsg.assert_has_calls(expected_calls)
def local_out_add_port(self, network, port, mac): (dp, ofp, ofpp) = self._get_dp() match = ofpp.OFPMatch(metadata=meta.mk_metadata(network), eth_dst=mac) actions = [ofpp.OFPActionOutput(port=port)] instructions = [ ofpp.OFPInstructionActions(ofp.OFPIT_APPLY_ACTIONS, actions), ] msg = ofpp.OFPFlowMod(dp, table_id=tables.LOCAL_OUT, priority=1, match=match, instructions=instructions) self._send_msg(msg)
def install_tunnel_output( self, table_id, network, segmentation_id, port, remote_ips, goto_next, **additional_matches ): (dp, ofp, ofpp) = self._get_dp() match = ofpp.OFPMatch(metadata=meta.mk_metadata(network, meta.LOCAL), **additional_matches) actions = [ofpp.OFPActionSetField(tunnel_id=segmentation_id)] actions += itertools.chain.from_iterable( [[ofpp.OFPActionSetField(tun_ipv4_dst=ip), ofpp.OFPActionOutput(port=port)] for ip in remote_ips] ) instructions = [ofpp.OFPInstructionActions(ofp.OFPIT_APPLY_ACTIONS, actions)] if goto_next: instructions += [ofpp.OFPInstructionGotoTable(table_id=table_id + 1)] msg = ofpp.OFPFlowMod(dp, table_id=table_id, priority=1, match=match, instructions=instructions) self._send_msg(msg)
def provision_tenant_tunnel(self, network_type, network, segmentation_id): (dp, _ofp, ofpp) = self._get_dp() match = ofpp.OFPMatch(tunnel_id=segmentation_id) metadata = meta.mk_metadata(network) instructions = [ ofpp.OFPInstructionWriteMetadata(metadata=metadata[0], metadata_mask=metadata[1]), ofpp.OFPInstructionGotoTable(table_id=tables.TUNNEL_OUT), ] msg = ofpp.OFPFlowMod(dp, table_id=tables.TUNNEL_IN[network_type], priority=1, match=match, instructions=instructions) self._send_msg(msg)
def test_local_out_add_port(self): br = self.br with mock.patch.object(br, '_send_msg') as sendmsg: br.local_out_add_port(network=1234, port=7, mac='12:34:56:78:9a:bc') (dp, ofp, ofpp) = br._get_dp() call = mock.call expected_calls = [ call(ofpp.OFPFlowMod(dp, instructions=[ ofpp.OFPInstructionActions(ofp.OFPIT_APPLY_ACTIONS, [ofpp.OFPActionOutput(port=7)])], match=ofpp.OFPMatch(eth_dst="12:34:56:78:9a:bc", metadata=meta.mk_metadata(1234)), priority=1, table_id=8)) ] sendmsg.assert_has_calls(expected_calls)
def test_local_flood_update(self): br = self.br with mock.patch.object(br, '_send_msg') as sendmsg: br.local_flood_update(network=1234, ports=[1, 2, 3], flood_unicast=True) (dp, ofp, ofpp) = br._get_dp() call = mock.call expected_calls = [ call(ofpp.OFPFlowMod(dp, instructions=[ofpp.OFPInstructionActions( ofp.OFPIT_APPLY_ACTIONS, [ ofpp.OFPActionOutput(port=1), ofpp.OFPActionOutput(port=2), ofpp.OFPActionOutput(port=3)])], match=ofpp.OFPMatch(metadata=meta.mk_metadata(1234)), priority=1, table_id=13)), call(ofpp.OFPFlowMod(dp, command=ofp.OFPFC_DELETE_STRICT, match=ofpp.OFPMatch( eth_dst=('01:00:00:00:00:00', '01:00:00:00:00:00'), metadata=meta.mk_metadata(1234)), out_group=ofp.OFPG_ANY, out_port=ofp.OFPP_ANY, priority=1, table_id=13)) ] sendmsg.assert_has_calls(expected_calls)
def arp_passthrough(self, network, tpa): (dp, ofp, ofpp) = self._get_dp() match = ofpp.OFPMatch(metadata=meta.mk_metadata(network), eth_type=ether.ETH_TYPE_ARP, arp_op=arp.ARP_REQUEST, arp_tpa=tpa) instructions = [ ofpp.OFPInstructionGotoTable(table_id=tables.TUNNEL_OUT) ] msg = ofpp.OFPFlowMod(dp, table_id=tables.ARP_PASSTHROUGH, priority=1, idle_timeout=5, match=match, instructions=instructions) self._send_msg(msg)
def test_arp_passthrough(self): br = self.br with mock.patch.object(br, '_send_msg') as sendmsg: br.arp_passthrough(network=1234, tpa='192.0.2.1') (dp, ofp, ofpp) = br._get_dp() arp = importutils.import_module('ryu.lib.packet.arp') ether = importutils.import_module('ryu.ofproto.ether') call = mock.call expected_calls = [ call(ofpp.OFPFlowMod(dp, idle_timeout=5, instructions=[ofpp.OFPInstructionGotoTable(table_id=7)], match=ofpp.OFPMatch(arp_op=arp.ARP_REQUEST, arp_tpa="192.0.2.1", eth_type=ether.ETH_TYPE_ARP, metadata=meta.mk_metadata(1234)), priority=1, table_id=5)) ] sendmsg.assert_has_calls(expected_calls)
def test_local_flood_delete(self): br = self.br with mock.patch.object(br, '_send_msg') as sendmsg: br.local_flood_delete(network=1234) (dp, ofp, ofpp) = br._get_dp() call = mock.call expected_calls = [ call( ofpp.OFPFlowMod( dp, command=ofp.OFPFC_DELETE, match=ofpp.OFPMatch(metadata=meta.mk_metadata(1234)), out_group=ofp.OFPG_ANY, out_port=ofp.OFPP_ANY, priority=0, table_id=13)) ] sendmsg.assert_has_calls(expected_calls)
def test_delete_tunnel_output(self): br = self.br with mock.patch.object(br, '_send_msg') as sendmsg: br.delete_tunnel_output(table_id=110, network=111) (dp, ofp, ofpp) = br._get_dp() call = mock.call expected_calls = [ call( ofpp.OFPFlowMod( dp, command=ofp.OFPFC_DELETE, match=ofpp.OFPMatch( metadata=meta.mk_metadata(111, meta.LOCAL)), out_group=ofp.OFPG_ANY, out_port=ofp.OFPP_ANY, priority=0, table_id=110)) ] sendmsg.assert_has_calls(expected_calls)
def test_provision_tenant_physnet(self): br = self.br with mock.patch.object(br, '_send_msg') as sendmsg: br.provision_tenant_physnet(network_type="vlan", network=150, segmentation_id=151, phys_port=99) (dp, ofp, ofpp) = br._get_dp() call = mock.call expected_calls = [ call( ofpp.OFPFlowMod( dp, instructions=[ ofpp.OFPInstructionWriteMetadata( metadata=150, metadata_mask=meta.NETWORK_MASK), ofpp.OFPInstructionActions(ofp.OFPIT_APPLY_ACTIONS, [ofpp.OFPActionPopVlan()]), ofpp.OFPInstructionGotoTable(table_id=3) ], match=ofpp.OFPMatch(in_port=99, vlan_vid=151 | ofp.OFPVID_PRESENT), priority=1, table_id=0)), call( ofpp.OFPFlowMod( dp, instructions=[ ofpp.OFPInstructionActions(ofp.OFPIT_APPLY_ACTIONS, [ ofpp.OFPActionPushVlan(), ofpp.OFPActionSetField(vlan_vid=151 | ofp.OFPVID_PRESENT), ofpp.OFPActionOutput(port=99), ofpp.OFPActionPopVlan() ]), ofpp.OFPInstructionGotoTable(table_id=13) ], match=ofpp.OFPMatch( metadata=meta.mk_metadata(150, meta.LOCAL)), priority=1, table_id=12)) ] sendmsg.assert_has_calls(expected_calls)
def test_reclaim_tenant_physnet(self): br = self.br with mock.patch.object(br, '_send_msg') as sendmsg: br.reclaim_tenant_physnet(network_type="vlan", network=150, segmentation_id=151, phys_port=99) (dp, ofp, ofpp) = br._get_dp() call = mock.call expected_calls = [ call(ofpp.OFPFlowMod(dp, command=ofp.OFPFC_DELETE, match=ofpp.OFPMatch(in_port=99, vlan_vid=151 | ofp.OFPVID_PRESENT), out_group=ofp.OFPG_ANY, out_port=ofp.OFPP_ANY, priority=0, table_id=0)), call(ofpp.OFPFlowMod(dp, command=ofp.OFPFC_DELETE, match=ofpp.OFPMatch(metadata=meta.mk_metadata(150)), out_group=ofp.OFPG_ANY, out_port=ofp.OFPP_ANY, priority=0, table_id=12)) ] sendmsg.assert_has_calls(expected_calls)
def test_provision_tenant_physnet(self): br = self.br with mock.patch.object(br, '_send_msg') as sendmsg: br.provision_tenant_physnet(network_type="vlan", network=150, segmentation_id=151, phys_port=99) (dp, ofp, ofpp) = br._get_dp() call = mock.call expected_calls = [ call(ofpp.OFPFlowMod(dp, instructions=[ ofpp.OFPInstructionWriteMetadata(metadata=150, metadata_mask=meta.NETWORK_MASK), ofpp.OFPInstructionActions(ofp.OFPIT_APPLY_ACTIONS, [ ofpp.OFPActionPopVlan()]), ofpp.OFPInstructionGotoTable(table_id=3)], match=ofpp.OFPMatch(in_port=99, vlan_vid=151 | ofp.OFPVID_PRESENT), priority=1, table_id=0)), call( ofpp.OFPFlowMod( dp, instructions=[ ofpp.OFPInstructionActions( ofp.OFPIT_APPLY_ACTIONS, [ ofpp.OFPActionPushVlan(), ofpp.OFPActionSetField( vlan_vid=151 | ofp.OFPVID_PRESENT ), ofpp.OFPActionOutput(port=99), ofpp.OFPActionPopVlan() ] ), ofpp.OFPInstructionGotoTable(table_id=13) ], match=ofpp.OFPMatch( metadata=meta.mk_metadata(150, meta.LOCAL) ), priority=1, table_id=12 ) ) ] sendmsg.assert_has_calls(expected_calls)
def test_local_out_delete_port(self): br = self.br with mock.patch.object(br, '_send_msg') as sendmsg: br.local_out_delete_port(network=1234, mac='12:34:56:78:9a:bc') (dp, ofp, ofpp) = br._get_dp() call = mock.call expected_calls = [ call( ofpp.OFPFlowMod(dp, command=ofp.OFPFC_DELETE, match=ofpp.OFPMatch( eth_dst="12:34:56:78:9a:bc", metadata=meta.mk_metadata(1234)), out_group=ofp.OFPG_ANY, out_port=ofp.OFPP_ANY, priority=0, table_id=8)) ] sendmsg.assert_has_calls(expected_calls)
def test_delete_tunnel_output(self): br = self.br with mock.patch.object(br, '_send_msg') as sendmsg: br.delete_tunnel_output(table_id=110, network=111) (dp, ofp, ofpp) = br._get_dp() call = mock.call expected_calls = [ call( ofpp.OFPFlowMod( dp, command=ofp.OFPFC_DELETE, match=ofpp.OFPMatch( metadata=meta.mk_metadata(111, meta.LOCAL) ), out_group=ofp.OFPG_ANY, out_port=ofp.OFPP_ANY, priority=0, table_id=110 ) ) ] sendmsg.assert_has_calls(expected_calls)
def test_arp_passthrough(self): br = self.br with mock.patch.object(br, '_send_msg') as sendmsg: br.arp_passthrough(network=1234, tpa='192.0.2.1') (dp, ofp, ofpp) = br._get_dp() arp = importutils.import_module('ryu.lib.packet.arp') ether = importutils.import_module('ryu.ofproto.ether') call = mock.call expected_calls = [ call( ofpp.OFPFlowMod( dp, idle_timeout=5, instructions=[ofpp.OFPInstructionGotoTable(table_id=7)], match=ofpp.OFPMatch(arp_op=arp.ARP_REQUEST, arp_tpa="192.0.2.1", eth_type=ether.ETH_TYPE_ARP, metadata=meta.mk_metadata(1234)), priority=1, table_id=5)) ] sendmsg.assert_has_calls(expected_calls)
def test_install_tunnel_output(self): br = self.br with mock.patch.object(br, '_send_msg') as sendmsg: br.install_tunnel_output(table_id=110, network=111, segmentation_id=112, port=113, remote_ips=['192.0.2.8', '192.0.2.9'], goto_next=True) (dp, ofp, ofpp) = br._get_dp() call = mock.call expected_calls = [ call( ofpp.OFPFlowMod( dp, instructions=[ ofpp.OFPInstructionActions( ofp.OFPIT_APPLY_ACTIONS, [ ofpp.OFPActionSetField(tunnel_id=112), ofpp.OFPActionSetField( tun_ipv4_dst='192.0.2.8'), ofpp.OFPActionOutput(port=113), ofpp.OFPActionSetField( tun_ipv4_dst='192.0.2.9'), ofpp.OFPActionOutput(port=113) ] ), ofpp.OFPInstructionGotoTable(table_id=111) ], match=ofpp.OFPMatch( metadata=meta.mk_metadata(111, meta.LOCAL) ), priority=1, table_id=110 ) ) ] sendmsg.assert_has_calls(expected_calls)
def install_tunnel_output(self, table_id, network, segmentation_id, port, remote_ips, goto_next, **additional_matches): (dp, ofp, ofpp) = self._get_dp() match = ofpp.OFPMatch(metadata=meta.mk_metadata(network, meta.LOCAL), **additional_matches) actions = [ofpp.OFPActionSetField(tunnel_id=segmentation_id)] actions += itertools.chain.from_iterable([[ ofpp.OFPActionSetField(tun_ipv4_dst=ip), ofpp.OFPActionOutput(port=port) ] for ip in remote_ips]) instructions = [ ofpp.OFPInstructionActions(ofp.OFPIT_APPLY_ACTIONS, actions), ] if goto_next: instructions += [ ofpp.OFPInstructionGotoTable(table_id=table_id + 1), ] msg = ofpp.OFPFlowMod(dp, table_id=table_id, priority=1, match=match, instructions=instructions) self._send_msg(msg)
def test_local_out_add_port(self): br = self.br with mock.patch.object(br, '_send_msg') as sendmsg: br.local_out_add_port(network=1234, port=7, mac='12:34:56:78:9a:bc') (dp, ofp, ofpp) = br._get_dp() call = mock.call expected_calls = [ call( ofpp.OFPFlowMod(dp, instructions=[ ofpp.OFPInstructionActions( ofp.OFPIT_APPLY_ACTIONS, [ofpp.OFPActionOutput(port=7)]) ], match=ofpp.OFPMatch( eth_dst="12:34:56:78:9a:bc", metadata=meta.mk_metadata(1234)), priority=1, table_id=8)) ] sendmsg.assert_has_calls(expected_calls)
def local_out_delete_port(self, network, mac): self.delete_flows(table_id=tables.LOCAL_OUT, metadata=meta.mk_metadata(network), eth_dst=mac)
def local_flood_delete(self, network): self.delete_flows(table_id=tables.LOCAL_FLOOD, metadata=meta.mk_metadata(network))
def delete_tunnel_output(self, table_id, network, **additional_matches): (dp, _ofp, ofpp) = self._get_dp() self.delete_flows(table_id=table_id, metadata=meta.mk_metadata(network, meta.LOCAL), **additional_matches)