blob: 1f286d229e5f62c0a16f4807efd64196230127e5 [file] [log] [blame]
"""
Flow Test
Test each flow table can set entry, and packet rx correctly.
"""
import logging
from oftest import config
import oftest.base_tests as base_tests
import ofp
from oftest.testutils import *
from accton_util import *
class L2McastFlow(base_tests.SimpleDataPlane):
"""
Test output function for an exact-match flow
Add some multicast flows
Then, for all ports, verifies that sending a matching packet
to a multicast match results in an output to all ports.
"""
def runTest(self):
ports = sorted(config["port_map"].keys())
delete_all_flows(self.controller)
delete_all_groups(self.controller)
# table 10: vlan
# send to table 20
add_vlan_table_flow(self.controller, config["port_map"].keys(), 1)
# group table
# set up untag groups for each port
add_l2_interface_grouop(self.controller, config["port_map"].keys(), 1, False, False)
# set up multicast group
add_l2_mcast_group(self.controller, config["port_map"].keys(), 1, 1)
test_macs = [[0x01, 0x00, 0x5e, 0x0f, 0xff, 0xff]]
for test_mac in test_macs:
group_id = encode_l2_mcast_group_id(1, 1)
add_bridge_flow(self.controller, test_mac, 1, group_id, True)
for test_mac in test_macs:
mactest = ':'.join(['%02X' % x for x in test_mac])
for in_port in ports:
# change dest based on port number
parsed_pkt = simple_tcp_packet(eth_dst=mactest)
pkt = str(parsed_pkt)
logging.info("OutputExact test, from port %d to mac %s", in_port, mactest)
self.dataplane.send(in_port, pkt)
for ofport in ports:
if ofport == in_port: #tx port won't rx packet, unless L3 mcast routing
continue
verify_packet(self, pkt, ofport)
verify_no_other_packets(self)
class L2UnicastFlow(base_tests.SimpleDataPlane):
"""
Test output function for an exact-match flow
For each port A, adds a flow directing matching packets to that port.
Then, for all other ports B != A, verifies that sending a matching packet
to B results in an output to A.
"""
def runTest(self):
ports = sorted(config["port_map"].keys())
delete_all_flows(self.controller)
delete_all_groups(self.controller)
# table 10: vlan
# send to table 20
#add_vlan_table_flow(self.controller, config["port_map"].keys(),1)
# group table
# set up tag groups for each port
add_l2_interface_group(self.controller, config["port_map"].keys(), 1, True, 1)
for port in ports:
add_one_vlan_table_flow(self.controller, port, 1)
group_id = encode_l2_interface_group_id(1, port)
add_bridge_flow(self.controller, [0x00, 0x12, 0x34, 0x56, 0x78, port], 1, group_id, True)
do_barrier(self.controller)
for out_port in ports:
# change dest based on port number
mac_dst= '00:12:34:56:78:%02X' % out_port
for in_port in ports:
if in_port == out_port:
continue
# change source based on port number to avoid packet-ins from learning
mac_src= '00:12:34:56:79:%02X' % in_port
parsed_pkt = simple_tcp_packet(dl_vlan_enable=True, vlan_vid=1, eth_dst=mac_dst, eth_src=mac_src)
pkt = str(parsed_pkt)
logging.info("OutputExact test, ports %d to %d", in_port, out_port)
self.dataplane.send(in_port, pkt)
for ofport in ports:
if ofport in [out_port]:
verify_packet(self, pkt, ofport)
else:
verify_no_packet(self, pkt, ofport)
verify_no_other_packets(self)
class L2Flood(base_tests.SimpleDataPlane):
"""
Test L2 unknown unicast flooding and broadcast flood
"""
def runTest(self):
ports = sorted(config["port_map"].keys())
delete_all_flows(self.controller)
delete_all_groups(self.controller)
# table 10: vlan
# send to table 20
add_vlan_table_flow(self.controller, ports, 1)
# group table
# set up untag groups for each port
add_l2_interface_grouop(self.controller, ports, 1, False, 1)
input_port = ports.pop()
flood_ports= ports
#no fllod group create, veriy all drop
parsed_pkt = simple_tcp_packet(eth_dst='00:12:34:56:78:9a')
pkt = str(parsed_pkt)
self.dataplane.send(input_port, pkt)
verify_no_other_packets(self)
parsed_pkt = simple_tcp_packet(eth_dst='FF:FF:FF:FF:FF:FF')
pkt = str(parsed_pkt)
self.dataplane.send(input_port, pkt)
verify_no_other_packets(self)
#add flood groupo
msg=add_l2_flood_group(self.controller, flood_ports, 1, 1)
add_bridge_flow(self.controller, None, 1, msg.group_id, True)
#verify flood
parsed_pkt = simple_tcp_packet(eth_dst='00:12:34:56:78:9a')
pkt = str(parsed_pkt)
self.dataplane.send(input_port, pkt)
for ofport in flood_ports:
verify_packet(self, pkt, ofport)
verify_no_other_packets(self)
for ofport in flood_ports:
self.dataplane.send(ofport, pkt)
#self won't rx packet
verify_no_packet(self, pkt, ofport)
#others will rx packet
tmp_ports=[]
for tmp in flood_ports:
if tmp != ofport:
tmp_ports.append(tmp)
verify_packets(self, pkt, tmp_ports)
verify_no_other_packets(self)
parsed_pkt = simple_tcp_packet(eth_dst='FF:FF:FF:FF:FF:FF')
pkt = str(parsed_pkt)
self.dataplane.send(input_port, pkt)
for ofport in flood_ports:
verify_packet(self, pkt, ofport)
class PacketInMiss(base_tests.SimpleDataPlane):
"""
Test packet in function for a table-miss flow
Send a packet to each dataplane port and verify that a packet
in message is received from the controller for each
NOTE: Verify This case the oft option shall not use --switch-ip
"""
def runTest(self):
delete_all_flows(self.controller)
delete_all_groups(self.controller)
parsed_pkt = simple_tcp_packet(pktlen=100)
parsed_vlan_pkt = simple_tcp_packet(pktlen=104,
vlan_vid=0x1001, dl_vlan_enable=True)
pkt = str(parsed_pkt)
vlan_pkt = str(parsed_vlan_pkt)
# table 10: vlan
# send to table 20
add_vlan_table_flow(self.controller, config["port_map"].keys(), 1)
# group table
# set up untag groups for each port
add_l2_interface_grouop(self.controller, config["port_map"].keys(), 1, False, 1)
# create match
match = ofp.match()
match.oxm_list.append(ofp.oxm.vlan_vid(0x1001))
request = ofp.message.flow_add(
table_id=60,
cookie=42,
match=match,
instructions=[
ofp.instruction.apply_actions(
actions=[
ofp.action.output(
port=ofp.OFPP_CONTROLLER,
max_len=ofp.OFPCML_NO_BUFFER)]),
],
buffer_id=ofp.OFP_NO_BUFFER,
priority=1)
logging.info("Inserting packet in flow to controller")
self.controller.message_send(request)
do_barrier(self.controller)
for of_port in config["port_map"].keys():
logging.info("PacketInMiss test, port %d", of_port)
self.dataplane.send(of_port, pkt)
#AOS current packet in will not have vlan tag
if config["cicada_poject"]:
verify_packet_in(self, vlan_pkt, of_port, ofp.OFPR_ACTION)
else:
verify_packet_in(self, pkt, of_port, ofp.OFPR_ACTION)
verify_no_other_packets(self)
class PacketOut(base_tests.SimpleDataPlane):
"""
Verify action Flood, ALL, in port
"""
def runTest(self):
if config["cicada_poject"]:
pass
delete_all_flows(self.controller)
delete_all_groups(self.controller)
parsed_pkt = simple_tcp_packet(pktlen=100)
parsed_vlan_pkt = simple_tcp_packet(pktlen=104,
vlan_vid=0x1002, dl_vlan_enable=True)
pkt = str(parsed_pkt)
vlan_pkt = str(parsed_vlan_pkt)
#packet out flood, untag packet
self.controller.message_send(ofp.message.packet_out(in_port=ofp.OFPP_CONTROLLER,
buffer_id=ofp.OFP_NO_BUFFER,
actions=[ofp.action.output(
port=ofp.OFPP_FLOOD)],
data=pkt))
for of_port in config["port_map"].keys():
verify_packet(self, pkt, of_port)
verify_no_other_packets(self)
#packet out flood, tag packet, because it can't identify vlan has which port
#so we do as all action.
self.controller.message_send(ofp.message.packet_out(in_port=ofp.OFPP_CONTROLLER,
buffer_id=ofp.OFP_NO_BUFFER,
actions=[ofp.action.output(
port=ofp.OFPP_FLOOD)],
data=vlan_pkt))
for of_port in config["port_map"].keys():
verify_packet(self, vlan_pkt, of_port)
verify_no_other_packets(self)
#packet out all
self.controller.message_send(ofp.message.packet_out(in_port=ofp.OFPP_CONTROLLER,
buffer_id=ofp.OFP_NO_BUFFER,
actions=[ofp.action.output(
port=ofp.OFPP_FLOOD)],
data=pkt))
for of_port in config["port_map"].keys():
verify_packet(self, pkt, of_port)
verify_no_other_packets(self)
#packet out to in port
in_port = config["port_map"].keys()[0]
self.controller.message_send(ofp.message.packet_out(in_port=in_port,
buffer_id=ofp.OFP_NO_BUFFER,
actions=[ofp.action.output(
port=in_port)],
data=pkt))
verify_packet(self, pkt, in_port)
verify_no_other_packets(self)
class L3UcastRoute(base_tests.SimpleDataPlane):
"""
Port1(vlan1, 0x00, 0x00, 0x00, 0x22, 0x22, 0x01, 192.168.1.1) ,
Port2(vlan2, 0x00, 0x00, 0x00, 0x22, 0x22, 0x02, 19.168.2.1)
"""
def runTest(self):
delete_all_flows(self.controller)
delete_all_groups(self.controller)
if len(config["port_map"]) <2:
logging.info("Port count less than 2, can't run this case")
return
vlan_id=1
intf_src_mac=[0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc]
dst_mac=[0x00, 0x00, 0x00, 0x22, 0x22, 0x00]
dip=0xc0a80001
for port in config["port_map"].keys():
#add l2 interface group
add_one_l2_interface_group(self.controller, port, vlan_id=vlan_id, is_tagged=False, send_barrier=False)
dst_mac[5]=vlan_id
l3_msg=add_l3_unicast_group(self.controller, port, vlanid=vlan_id, id=vlan_id, src_mac=intf_src_mac, dst_mac=dst_mac)
#add vlan flow table
add_one_vlan_table_flow(self.controller, port, vlan_id, flag=VLAN_TABLE_FLAG_ONLY_BOTH)
#add termination flow
add_termination_flow(self.controller, port, 0x0800, intf_src_mac, vlan_id)
#add unicast routing flow
dst_ip = dip + (vlan_id<<8)
add_unicast_routing_flow(self.controller, 0x0800, dst_ip, 0, l3_msg.group_id)
vlan_id += 1
do_barrier(self.controller)
port1=config["port_map"].keys()[0]
port2=config["port_map"].keys()[1]
#port 1 to port 2
switch_mac = ':'.join(['%02X' % x for x in intf_src_mac])
dst_mac[5]=1
port1_mac=':'.join(['%02X' % x for x in dst_mac])
parsed_pkt = simple_tcp_packet(pktlen=100,
eth_dst=switch_mac,
eth_src=port1_mac,
ip_ttl=64,
ip_src="192.168.1.1",
ip_dst='192.168.2.1')
pkt=str(parsed_pkt)
self.dataplane.send(port1, pkt)
#build expect packet
dst_mac[5]=2
port2_mac=':'.join(['%02X' % x for x in dst_mac])
exp_pkt = simple_tcp_packet(pktlen=100,
eth_dst=port2_mac,
eth_src=switch_mac,
ip_ttl=63,
ip_src="192.168.1.1",
ip_dst='192.168.2.1')
pkt=str(exp_pkt)
verify_packet(self, pkt, port2)
verify_no_other_packets(self)
#port 2 to port 1
switch_mac = ':'.join(['%02X' % x for x in intf_src_mac])
dst_mac[5]=2
port2_mac=':'.join(['%02X' % x for x in dst_mac])
parsed_pkt = simple_tcp_packet(pktlen=100,
eth_dst=switch_mac,
eth_src=port2_mac,
ip_ttl=64,
ip_src="192.168.2.1",
ip_dst='192.168.1.1')
pkt=str(parsed_pkt)
self.dataplane.send(port2, pkt)
#build expect packet
dst_mac[5]=1
port1_mac=':'.join(['%02X' % x for x in dst_mac])
exp_pkt = simple_tcp_packet(pktlen=100,
eth_dst=port1_mac,
eth_src=switch_mac,
ip_ttl=63,
ip_src="192.168.2.1",
ip_dst='192.168.1.1')
pkt=str(exp_pkt)
verify_packet(self, pkt, port1)
verify_no_other_packets(self)
class L3UcastRouteOnSamVLANSamPort(base_tests.SimpleDataPlane):
"""
Port1(vlan1, 0x00, 0x00, 0x00, 0x22, 0x22, 0x01, 192.168.1.1) ,
Port1(vlan1, 0x00, 0x00, 0x00, 0x22, 0x22, 0x02, 19.168.2.1)
"""
def runTest(self):
delete_all_flows(self.controller)
delete_all_groups(self.controller)
port = config["port_map"].keys()[0]
vlan_id=1
intf_src_mac=[0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc]
port_mac1=[0x00, 0x00, 0x00, 0x22, 0x22, 0x01]
port_mac2=[0x00, 0x00, 0x00, 0x22, 0x22, 0x02]
port_ip1=0xc0a80101
port_ip1_str=convertIP4toStr(port_ip1)
port_ip2=0xc0a80201
port_ip2_str=convertIP4toStr(port_ip2)
#add l2 interface group
add_one_l2_interface_group(self.controller, port, vlan_id=vlan_id, is_tagged=False, send_barrier=False)
#add vlan flow table
add_one_vlan_table_flow(self.controller, port, vlan_id, flag=VLAN_TABLE_FLAG_ONLY_BOTH)
#add termination flow
add_termination_flow(self.controller, port, 0x0800, intf_src_mac, vlan_id)
"""192.168.1.1->192.168.2.1"""
l3_msg=add_l3_unicast_group(self.controller, port, vlanid=vlan_id, id=1, src_mac=intf_src_mac, dst_mac=port_mac2)
add_unicast_routing_flow(self.controller, 0x0800, port_ip2, 0, l3_msg.group_id)
"""192.168.1.1->192.168.2.1"""
l3_msg=add_l3_unicast_group(self.controller, port, vlanid=vlan_id, id=2, src_mac=intf_src_mac, dst_mac=port_mac1)
add_unicast_routing_flow(self.controller, 0x0800, port_ip1, 0, l3_msg.group_id)
do_barrier(self.controller)
"""send packet to verify"""
"""192.168.1.1->192.168.2.1"""
switch_mac_str = convertMACtoStr(intf_src_mac)
port_mac1_str = convertMACtoStr(port_mac1)
port_mac2_str = convertMACtoStr(port_mac2)
ttl=64
#send packet
parsed_pkt = simple_tcp_packet(pktlen=100,
eth_dst=switch_mac_str,
eth_src=port_mac1_str,
ip_ttl=ttl,
ip_src=port_ip1_str,
ip_dst=port_ip2_str)
pkt=str(parsed_pkt)
self.dataplane.send(port, pkt)
#build expect packet
exp_pkt = simple_tcp_packet(pktlen=100,
eth_dst=port_mac2_str,
eth_src=switch_mac_str,
ip_ttl=(ttl-1),
ip_src=port_ip1_str,
ip_dst=port_ip2_str)
pkt=str(exp_pkt)
verify_packet(self, pkt, port)
verify_no_other_packets(self)
"""192.168.2.1->192.168.1.1"""
parsed_pkt = simple_tcp_packet(pktlen=100,
eth_dst=switch_mac_str,
eth_src=port_mac2_str,
ip_ttl=ttl,
ip_src=port_ip2_str,
ip_dst=port_ip1_str)
pkt=str(parsed_pkt)
self.dataplane.send(port, pkt)
#build expect packet
exp_pkt = simple_tcp_packet(pktlen=100,
eth_dst=port_mac1_str,
eth_src=switch_mac_str,
ip_ttl=(ttl-1),
ip_src=port_ip2_str,
ip_dst=port_ip1_str)
pkt=str(exp_pkt)
verify_packet(self, pkt, port)
verify_no_other_packets(self)
class L3UcastRouteOnDiffVLANSamPort(base_tests.SimpleDataPlane):
"""
Port1(vlan1, 0x00, 0x00, 0x00, 0x22, 0x22, 0x01, 192.168.1.1) ,
Port1(vlan2, 0x00, 0x00, 0x00, 0x22, 0x22, 0x02, 19.168.2.1)
"""
def runTest(self):
delete_all_flows(self.controller)
delete_all_groups(self.controller)
port = config["port_map"].keys()[0]
port_vlan_id1=1
port_vlan_id2=2
intf_src_mac=[0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc]
port_mac1=[0x00, 0x00, 0x00, 0x22, 0x22, 0x01]
port_mac2=[0x00, 0x00, 0x00, 0x22, 0x22, 0x02]
port_ip1=0xc0a80101
port_ip1_str=convertIP4toStr(port_ip1)
port_ip2=0xc0a80201
port_ip2_str=convertIP4toStr(port_ip2)
#add l2 interface group
add_one_l2_interface_group(self.controller, port, vlan_id=port_vlan_id1, is_tagged=True, send_barrier=False)
add_one_l2_interface_group(self.controller, port, vlan_id=port_vlan_id2, is_tagged=True, send_barrier=False)
#add vlan flow table
add_one_vlan_table_flow(self.controller, port, port_vlan_id1, flag=VLAN_TABLE_FLAG_ONLY_BOTH)
add_one_vlan_table_flow(self.controller, port, port_vlan_id2, flag=VLAN_TABLE_FLAG_ONLY_BOTH)
#add termination flow
add_termination_flow(self.controller, port, 0x0800, intf_src_mac, port_vlan_id1)
add_termination_flow(self.controller, port, 0x0800, intf_src_mac, port_vlan_id2)
"""192.168.1.1->192.168.2.1"""
l3_msg=add_l3_unicast_group(self.controller, port, vlanid=port_vlan_id2, id=1, src_mac=intf_src_mac, dst_mac=port_mac2)
add_unicast_routing_flow(self.controller, 0x0800, port_ip2, 0, l3_msg.group_id)
"""192.168.1.1->192.168.2.1"""
l3_msg=add_l3_unicast_group(self.controller, port, vlanid=port_vlan_id1, id=2, src_mac=intf_src_mac, dst_mac=port_mac1)
add_unicast_routing_flow(self.controller, 0x0800, port_ip1, 0, l3_msg.group_id)
do_barrier(self.controller)
"""send packet to verify"""
"""192.168.1.1->192.168.2.1"""
switch_mac_str =convertMACtoStr(intf_src_mac)
port_mac1_str= convertMACtoStr(port_mac1)
port_mac2_str= convertMACtoStr(port_mac2)
ttl=64
#send packet
parsed_pkt = simple_tcp_packet(pktlen=100,
eth_dst=switch_mac_str,
eth_src=port_mac1_str,
dl_vlan_enable=True,
vlan_vid=port_vlan_id1,
ip_ttl=ttl,
ip_src=port_ip1_str,
ip_dst=port_ip2_str)
pkt=str(parsed_pkt)
self.dataplane.send(port, pkt)
#build expect packet
exp_pkt = simple_tcp_packet(pktlen=100,
eth_dst=port_mac2_str,
eth_src=switch_mac_str,
dl_vlan_enable=True,
vlan_vid=port_vlan_id2,
ip_ttl=(ttl-1),
ip_src=port_ip1_str,
ip_dst=port_ip2_str)
pkt=str(exp_pkt)
verify_packet(self, pkt, port)
verify_no_other_packets(self)
"""192.168.2.1->192.168.1.1"""
switch_mac = convertMACtoStr(intf_src_mac)
port_mac2_str=convertMACtoStr(port_mac2)
parsed_pkt = simple_tcp_packet(pktlen=100,
eth_dst=switch_mac_str,
eth_src=port_mac2_str,
dl_vlan_enable=True,
vlan_vid=port_vlan_id2,
ip_ttl=ttl,
ip_src=port_ip2_str,
ip_dst=port_ip1_str)
pkt=str(parsed_pkt)
self.dataplane.send(port, pkt)
#build expect packet
exp_pkt = simple_tcp_packet(pktlen=100,
eth_dst=port_mac1_str,
eth_src=switch_mac_str,
dl_vlan_enable=True,
vlan_vid=port_vlan_id1,
ip_ttl=(ttl-1),
ip_src=port_ip2_str,
ip_dst=port_ip1_str)
pkt=str(exp_pkt)
verify_packet(self, pkt, port)
verify_no_other_packets(self)
class L3UcastVrfRouteOnSamVLANSamPort(base_tests.SimpleDataPlane):
"""
Port1(vlan1, VRF1, 0x00, 0x00, 0x00, 0x22, 0x22, 0x01, 192.168.1.1) ,
Port1(vlan1, VRF1, 0x00, 0x00, 0x00, 0x22, 0x22, 0x02, 19.168.2.1)
Port1(vlan2, VRF2, 0x00, 0x00, 0x00, 0x22, 0x22, 0x01, 192.168.1.1) ,
Port1(vlan2, VRF2, 0x00, 0x00, 0x00, 0x22, 0x22, 0x02, 19.168.2.1)
"""
def runTest(self):
delete_all_flows(self.controller)
delete_all_groups(self.controller)
port = config["port_map"].keys()[0]
vrf1=1
vrf2=2
vrf1_vlan_id=1
vrf2_vlan_id=2
intf_src_mac=[0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc]
port_mac1=[0x00, 0x00, 0x00, 0x22, 0x22, 0x01]
port_mac2=[0x00, 0x00, 0x00, 0x22, 0x22, 0x02]
port_ip1=0xc0a80101
port_ip1_str=convertIP4toStr(port_ip1)
port_ip2=0xc0a80201
port_ip2_str=convertIP4toStr(port_ip2)
#add l2 interface group
add_one_l2_interface_group(self.controller, port, vlan_id=vrf1_vlan_id, is_tagged=True, send_barrier=False)
add_one_l2_interface_group(self.controller, port, vlan_id=vrf2_vlan_id, is_tagged=True, send_barrier=False)
#add vlan flow table
add_one_vlan_table_flow(self.controller, port, vrf1_vlan_id, vrf=vrf1, flag=VLAN_TABLE_FLAG_ONLY_TAG)
add_one_vlan_table_flow(self.controller, port, vrf2_vlan_id, vrf=vrf2, flag=VLAN_TABLE_FLAG_ONLY_TAG)
#add termination flow
add_termination_flow(self.controller, 0, 0x0800, intf_src_mac, vrf1_vlan_id)
add_termination_flow(self.controller, 0, 0x0800, intf_src_mac, vrf2_vlan_id)
"""192.168.1.1->192.168.2.1"""
l3_msg=add_l3_unicast_group(self.controller, port, vlanid=vrf1_vlan_id, id=1, src_mac=intf_src_mac, dst_mac=port_mac2)
add_unicast_routing_flow(self.controller, 0x0800, port_ip2, 0, l3_msg.group_id, vrf1)
l3_msg=add_l3_unicast_group(self.controller, port, vlanid=vrf2_vlan_id, id=2, src_mac=intf_src_mac, dst_mac=port_mac2)
add_unicast_routing_flow(self.controller, 0x0800, port_ip2, 0, l3_msg.group_id, vrf2)
"""192.168.1.1->192.168.2.1"""
l3_msg=add_l3_unicast_group(self.controller, port, vlanid=vrf1_vlan_id, id=3, src_mac=intf_src_mac, dst_mac=port_mac1)
add_unicast_routing_flow(self.controller, 0x0800, port_ip1, 0, l3_msg.group_id, vrf1)
l3_msg=add_l3_unicast_group(self.controller, port, vlanid=vrf2_vlan_id, id=4, src_mac=intf_src_mac, dst_mac=port_mac1)
add_unicast_routing_flow(self.controller, 0x0800, port_ip1, 0, l3_msg.group_id, vrf2)
do_barrier(self.controller)
"""send packet to verify on VRF vrf1"""
"""192.168.1.1->192.168.2.1"""
switch_mac_str = convertMACtoStr(intf_src_mac)
port_mac1_str = convertMACtoStr(port_mac1)
port_mac2_str = convertMACtoStr(port_mac2)
ttl=64
#send packet
parsed_pkt = simple_tcp_packet(pktlen=100,
eth_dst=switch_mac_str,
eth_src=port_mac1_str,
dl_vlan_enable=True,
vlan_vid=vrf1_vlan_id,
ip_ttl=ttl,
ip_src=port_ip1_str,
ip_dst=port_ip2_str)
pkt=str(parsed_pkt)
self.dataplane.send(port, pkt)
#build expect packet
exp_pkt = simple_tcp_packet(pktlen=100,
eth_dst=port_mac2_str,
eth_src=switch_mac_str,
dl_vlan_enable=True,
vlan_vid=vrf1_vlan_id,
ip_ttl=(ttl-1),
ip_src=port_ip1_str,
ip_dst=port_ip2_str)
pkt=str(exp_pkt)
verify_packet(self, pkt, port)
verify_no_other_packets(self)
"""192.168.2.1->192.168.1.1"""
parsed_pkt = simple_tcp_packet(pktlen=100,
eth_dst=switch_mac_str,
eth_src=port_mac2_str,
dl_vlan_enable=True,
vlan_vid=vrf1_vlan_id,
ip_ttl=ttl,
ip_src=port_ip2_str,
ip_dst=port_ip1_str)
pkt=str(parsed_pkt)
self.dataplane.send(port, pkt)
#build expect packet
exp_pkt = simple_tcp_packet(pktlen=100,
eth_dst=port_mac1_str,
eth_src=switch_mac_str,
dl_vlan_enable=True,
vlan_vid=vrf1_vlan_id,
ip_ttl=(ttl-1),
ip_src=port_ip2_str,
ip_dst=port_ip1_str)
pkt=str(exp_pkt)
verify_packet(self, pkt, port)
verify_no_other_packets(self)
"""send packet to verify on VRF vrf2"""
"""192.168.1.1->192.168.2.1"""
switch_mac_str = convertMACtoStr(intf_src_mac)
port_mac1_str = convertMACtoStr(port_mac1)
port_mac2_str = convertMACtoStr(port_mac2)
ttl=64
#send packet
parsed_pkt = simple_tcp_packet(pktlen=100,
eth_dst=switch_mac_str,
eth_src=port_mac1_str,
dl_vlan_enable=True,
vlan_vid=vrf2_vlan_id,
ip_ttl=ttl,
ip_src=port_ip1_str,
ip_dst=port_ip2_str)
pkt=str(parsed_pkt)
self.dataplane.send(port, pkt)
#build expect packet
exp_pkt = simple_tcp_packet(pktlen=100,
eth_dst=port_mac2_str,
eth_src=switch_mac_str,
dl_vlan_enable=True,
vlan_vid=vrf2_vlan_id,
ip_ttl=(ttl-1),
ip_src=port_ip1_str,
ip_dst=port_ip2_str)
pkt=str(exp_pkt)
verify_packet(self, pkt, port)
verify_no_other_packets(self)
"""192.168.2.1->192.168.1.1"""
parsed_pkt = simple_tcp_packet(pktlen=100,
eth_dst=switch_mac_str,
eth_src=port_mac2_str,
dl_vlan_enable=True,
vlan_vid=vrf2_vlan_id,
ip_ttl=ttl,
ip_src=port_ip2_str,
ip_dst=port_ip1_str)
pkt=str(parsed_pkt)
self.dataplane.send(port, pkt)
#build expect packet
exp_pkt = simple_tcp_packet(pktlen=100,
eth_dst=port_mac1_str,
eth_src=switch_mac_str,
dl_vlan_enable=True,
vlan_vid=vrf2_vlan_id,
ip_ttl=(ttl-1),
ip_src=port_ip2_str,
ip_dst=port_ip1_str)
pkt=str(exp_pkt)
verify_packet(self, pkt, port)
verify_no_other_packets(self)
class L3UcastECMP(base_tests.SimpleDataPlane):
"""
Port1(vlan1, 0x00, 0x00, 0x00, 0x22, 0x22, 0x01, 192.168.1.1) ,
Port2(vlan2, 0x00, 0x00, 0x00, 0x22, 0x22, 0x02, 19.168.2.1)
"""
def runTest(self):
delete_all_flows(self.controller)
delete_all_groups(self.controller)
if len(config["port_map"]) <2:
logging.info("Port count less than 2, can't run this case")
return
vlan_id=1
intf_src_mac=[0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc]
dst_mac=[0x00, 0x00, 0x00, 0x22, 0x22, 0x00]
dip=0xc0a80001
for port in config["port_map"].keys():
#add l2 interface group
add_one_l2_interface_group(self.controller, port, vlan_id=vlan_id, is_tagged=False, send_barrier=False)
dst_mac[5]=vlan_id
l3_msg=add_l3_unicast_group(self.controller, port, vlanid=vlan_id, id=vlan_id, src_mac=intf_src_mac, dst_mac=dst_mac)
ecmp_msg=add_l3_ecmp_group(self.controller, vlan_id, [l3_msg.group_id])
#add vlan flow table
add_one_vlan_table_flow(self.controller, port, vlan_id, flag=VLAN_TABLE_FLAG_ONLY_BOTH)
#add termination flow
add_termination_flow(self.controller, port, 0x0800, intf_src_mac, vlan_id)
#add unicast routing flow
dst_ip = dip + (vlan_id<<8)
#ECMP shall have prefix not 32
add_unicast_routing_flow(self.controller, 0x0800, dst_ip, 0xffffff00, ecmp_msg.group_id)
vlan_id += 1
do_barrier(self.controller)
port1=config["port_map"].keys()[0]
port2=config["port_map"].keys()[1]
#port 1 to port 2
switch_mac = ':'.join(['%02X' % x for x in intf_src_mac])
dst_mac[5]=1
port1_mac=':'.join(['%02X' % x for x in dst_mac])
parsed_pkt = simple_tcp_packet(pktlen=100,
eth_dst=switch_mac,
eth_src=port1_mac,
ip_ttl=64,
ip_src="192.168.1.1",
ip_dst='192.168.2.1')
pkt=str(parsed_pkt)
self.dataplane.send(port1, pkt)
#build expect packet
dst_mac[5]=2
port2_mac=':'.join(['%02X' % x for x in dst_mac])
exp_pkt = simple_tcp_packet(pktlen=100,
eth_dst=port2_mac,
eth_src=switch_mac,
ip_ttl=63,
ip_src="192.168.1.1",
ip_dst='192.168.2.1')
pkt=str(exp_pkt)
verify_packet(self, pkt, port2)
verify_no_other_packets(self)
#port 2 to port 1
switch_mac = ':'.join(['%02X' % x for x in intf_src_mac])
dst_mac[5]=2
port2_mac=':'.join(['%02X' % x for x in dst_mac])
parsed_pkt = simple_tcp_packet(pktlen=100,
eth_dst=switch_mac,
eth_src=port2_mac,
ip_ttl=64,
ip_src="192.168.2.1",
ip_dst='192.168.1.1')
pkt=str(parsed_pkt)
self.dataplane.send(port2, pkt)
#build expect packet
dst_mac[5]=1
port1_mac=':'.join(['%02X' % x for x in dst_mac])
exp_pkt = simple_tcp_packet(pktlen=100,
eth_dst=port1_mac,
eth_src=switch_mac,
ip_ttl=63,
ip_src="192.168.2.1",
ip_dst='192.168.1.1')
pkt=str(exp_pkt)
verify_packet(self, pkt, port1)
verify_no_other_packets(self)
class L3UcastECMP2(base_tests.SimpleDataPlane):
"""
Port1(vlan1, 0x00, 0x00, 0x00, 0x22, 0x22, 0x01, 192.168.1.1) ,
Port2(vlan2, 0x00, 0x00, 0x00, 0x22, 0x22, 0x02, 19.168.2.1)
Portn(vlann, 0x00, 0x00, 0x00, 0x22, 0x22, 0x0n, 19.168.n.1)
"""
def runTest(self):
delete_all_flows(self.controller)
delete_all_groups(self.controller)
if len(config["port_map"]) <3:
logging.info("Port count less than 3, can't run this case")
return
vlan_id=1
intf_src_mac=[0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc]
same_dst_mac=[0x00, 0x00, 0x00, 0x22, 0x22, 0x22]
l3_ucast_gips=[]
tx_port = config["port_map"].keys()[0]
for port in config["port_map"].keys():
#add l2 interface group
add_one_l2_interface_group(self.controller, port, vlan_id=vlan_id, is_tagged=False, send_barrier=False)
if tx_port != port:
l3_msg=add_l3_unicast_group(self.controller, port, vlanid=vlan_id, id=vlan_id, src_mac=intf_src_mac, dst_mac=same_dst_mac)
l3_ucast_gips.append(l3_msg.group_id)
#add vlan flow table
add_one_vlan_table_flow(self.controller, port, vlan_id, flag=VLAN_TABLE_FLAG_ONLY_BOTH)
#add termination flow
add_termination_flow(self.controller, port, 0x0800, intf_src_mac, vlan_id)
vlan_id += 1
tx_dip=0x0a0a0a0a
tx_sip=0x0b0a0a0a
ecmp_msg=add_l3_ecmp_group(self.controller, vlan_id, l3_ucast_gips)
#ECMP shall have prefix not 32
add_unicast_routing_flow(self.controller, 0x0800, tx_dip, 0xffffff00, ecmp_msg.group_id)
do_barrier(self.controller)
switch_mac = ':'.join(['%02X' % x for x in intf_src_mac])
packet_src_mac="00:00:33:44:55:66"
#from unknown src ip to unknown dst ip, to verify ecmp
parsed_pkt = simple_tcp_packet(pktlen=100,
eth_dst=switch_mac,
eth_src=packet_src_mac,
ip_ttl=64,
ip_src=convertIP4toStr(tx_sip),
ip_dst=convertIP4toStr(tx_dip))
self.dataplane.send(tx_port, str(parsed_pkt))
#build expect packet
dst_mac=':'.join(['%02X' % x for x in same_dst_mac])
exp_pkt = simple_tcp_packet(pktlen=100,
eth_dst=dst_mac,
eth_src=switch_mac,
ip_ttl=63,
ip_src=convertIP4toStr(tx_sip),
ip_dst=convertIP4toStr(tx_dip))
verify_packet(self, exp_pkt, config["port_map"].keys()[2])
verify_no_other_packets(self)
tx_sip=tx_sip+0x01000000
#from unknown scr ip to unknown dst ip, to verify ecmp
parsed_pkt = simple_tcp_packet(pktlen=100,
eth_dst=switch_mac,
eth_src=packet_src_mac,
ip_ttl=64,
ip_src=convertIP4toStr(tx_sip),
ip_dst=convertIP4toStr(tx_dip))
self.dataplane.send(tx_port, str(parsed_pkt))
#build expect packet
dst_mac=':'.join(['%02X' % x for x in same_dst_mac])
exp_pkt = simple_tcp_packet(pktlen=100,
eth_dst=dst_mac,
eth_src=switch_mac,
ip_ttl=63,
ip_src=convertIP4toStr(tx_sip),
ip_dst=convertIP4toStr(tx_dip))
verify_packet(self, exp_pkt, config["port_map"].keys()[1])
verify_no_other_packets(self)
class L3McastRoute1(base_tests.SimpleDataPlane):
"""
Mcast routing, From VLAN 1 to VLAN 2
"""
def runTest(self):
"""
port1 (vlan 1)-> port 2 (vlan 2)
"""
delete_all_flows(self.controller)
delete_all_groups(self.controller)
if len(config["port_map"]) <3:
logging.info("Port count less than 2, can't run this case")
return
vlan_id =1
port2_out_vlan=2
port3_out_vlan=3
in_vlan=1 #macast group vid shall use input vlan diffe from l3 interface use output vlan
intf_src_mac=[0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc]
intf_src_mac_str=':'.join(['%02X' % x for x in intf_src_mac])
dst_mac=[0x01, 0x00, 0x5e, 0x01, 0x01, 0x01]
dst_mac_str=':'.join(['%02X' % x for x in dst_mac])
port1_mac=[0x00, 0x11, 0x11, 0x11, 0x11, 0x11]
port1_mac_str=':'.join(['%02X' % x for x in port1_mac])
src_ip=0xc0a80101
src_ip_str="192.168.1.1"
dst_ip=0xe0010101
dst_ip_str="224.1.1.1"
port1=config["port_map"].keys()[0]
port2=config["port_map"].keys()[1]
port3=config["port_map"].keys()[2]
#add l2 interface group
for port in config["port_map"].keys():
add_one_l2_interface_group(self.controller, port, vlan_id=vlan_id, is_tagged=False, send_barrier=False)
#add vlan flow table
add_one_vlan_table_flow(self.controller, port, vlan_id, flag=VLAN_TABLE_FLAG_ONLY_BOTH)
vlan_id +=1
#add termination flow
add_termination_flow(self.controller, port1, 0x0800, [0x01, 0x00, 0x5e, 0x00, 0x00, 0x00], vlan_id)
#add l3 interface group
port2_ucast_msg=add_l3_interface_group(self.controller, port2, port2_out_vlan, 2, intf_src_mac)
port3_ucast_msg=add_l3_interface_group(self.controller, port3, port3_out_vlan, 3, intf_src_mac)
mcat_group_msg=add_l3_mcast_group(self.controller, in_vlan, 2, [port2_ucast_msg.group_id, port3_ucast_msg.group_id])
add_mcast4_routing_flow(self.controller, in_vlan, src_ip, 0, dst_ip, mcat_group_msg.group_id)
parsed_pkt = simple_udp_packet(pktlen=100,
eth_dst=dst_mac_str,
eth_src=port1_mac_str,
ip_ttl=64,
ip_src=src_ip_str,
ip_dst=dst_ip_str)
pkt=str(parsed_pkt)
self.dataplane.send(port1, pkt)
parsed_pkt = simple_udp_packet(pktlen=100,
eth_dst=dst_mac_str,
eth_src=intf_src_mac_str,
ip_ttl=63,
ip_src=src_ip_str,
ip_dst=dst_ip_str)
pkt=str(parsed_pkt)
verify_packet(self, pkt, port2)
verify_packet(self, pkt, port3)
verify_no_other_packets(self)
class L3McastRoute2(base_tests.SimpleDataPlane):
"""
Mcast routing, but on same vlan (l2mcast)
"""
def runTest(self):
"""
port1 (vlan 1)-> port 2 (vlan 1)
"""
delete_all_flows(self.controller)
delete_all_groups(self.controller)
if len(config["port_map"]) <2:
logging.info("Port count less than 2, can't run this case")
return
vlan_id =1
intf_src_mac=[0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc]
intf_src_mac_str=':'.join(['%02X' % x for x in intf_src_mac])
dst_mac=[0x01, 0x00, 0x5e, 0x01, 0x01, 0x01]
dst_mac_str=':'.join(['%02X' % x for x in dst_mac])
port1_mac=[0x00, 0x11, 0x11, 0x11, 0x11, 0x11]
port1_mac_str=':'.join(['%02X' % x for x in port1_mac])
src_ip=0xc0a80101
src_ip_str="192.168.1.1"
dst_ip=0xe0010101
dst_ip_str="224.1.1.1"
port1=config["port_map"].keys()[0]
port2=config["port_map"].keys()[1]
#add l2 interface group
l2_intf_group_list=[]
for port in config["port_map"].keys():
if port != port1 and port !=port2:
continue
l2_intf_gid, msg=add_one_l2_interface_group(self.controller, port, vlan_id=vlan_id, is_tagged=False, send_barrier=False)
l2_intf_group_list.append(l2_intf_gid)
#add vlan flow table
add_one_vlan_table_flow(self.controller, port, vlan_id, flag=VLAN_TABLE_FLAG_ONLY_BOTH)
#add termination flow
add_termination_flow(self.controller, port1, 0x0800, [0x01, 0x00, 0x5e, 0x00, 0x00, 0x00], vlan_id)
#add l3 interface group
mcat_group_msg=add_l3_mcast_group(self.controller, vlan_id, 2, l2_intf_group_list)
add_mcast4_routing_flow(self.controller, vlan_id, src_ip, 0, dst_ip, mcat_group_msg.group_id)
parsed_pkt = simple_udp_packet(pktlen=100,
eth_dst=dst_mac_str,
eth_src=port1_mac_str,
ip_ttl=64,
ip_src=src_ip_str,
ip_dst=dst_ip_str)
pkt=str(parsed_pkt)
self.dataplane.send(port1, pkt)
verify_packet(self, pkt, port2)
verify_no_other_packets(self)