blob: ff5f6efbb49b944e11fa9a087338056c0939c2e4 [file] [log] [blame]
Flavio Castro05d20bc2015-11-16 15:06:14 -05001"""
2Flow Test
3Test each flow table can set entry, and packet rx correctly.
41) L3UcastRoute
52) QinQ
6"""
7
8import logging
9
10from oftest import config
11import oftest.base_tests as base_tests
12import ofp
13from oftest.testutils import *
14from accton_util import *
15
16class L3UcastRoute(base_tests.SimpleDataPlane):
17 """
18 Port1(vlan1, 0x00, 0x00, 0x00, 0x22, 0x22, 0x01, 192.168.1.1) ,
19 Port2(vlan2, 0x00, 0x00, 0x00, 0x22, 0x22, 0x02, 19.168.2.1)
20 """
21 def runTest(self):
22 delete_all_flows(self.controller)
23 delete_all_groups(self.controller)
24
25 if len(config["port_map"]) <2:
26 logging.info("Port count less than 2, can't run this case")
27 return
28
29 vlan_id=1
30 intf_src_mac=[0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc]
31 dst_mac=[0x00, 0x00, 0x00, 0x22, 0x22, 0x00]
32 dip=0xc0a80001
33 for port in config["port_map"].keys():
34 #add l2 interface group
35 add_one_l2_interface_grouop(self.controller, port, vlan_id=vlan_id, is_tagged=True, send_barrier=False)
36 dst_mac[5]=vlan_id
37 l3_msg=add_l3_unicast_group(self.controller, port, vlanid=vlan_id, id=vlan_id, src_mac=intf_src_mac, dst_mac=dst_mac)
38 #add vlan flow table
39 add_one_vlan_table_flow(self.controller, port, vlan_id, flag=VLAN_TABLE_FLAG_ONLY_BOTH)
40 #add termination flow
41 add_termination_flow(self.controller, port, 0x0800, intf_src_mac, vlan_id)
42 #add unicast routing flow
43 dst_ip = dip + (vlan_id<<8)
44 add_unicast_routing_flow(self.controller, 0x0800, dst_ip, 0, l3_msg.group_id)
45 vlan_id += 1
46
47 do_barrier(self.controller)
48
49 port1=config["port_map"].keys()[0]
50 port2=config["port_map"].keys()[1]
51 #port 1 to port 2
52 switch_mac = ':'.join(['%02X' % x for x in intf_src_mac])
53 dst_mac[5]=1
54 port1_mac=':'.join(['%02X' % x for x in dst_mac])
55
56 parsed_pkt = simple_tcp_packet(pktlen=100,
57 dl_vlan_enable=True,
58 vlan_vid=1,
59 eth_dst=switch_mac,
60 eth_src=port1_mac,
61 ip_ttl=64,
62 ip_src="192.168.1.1",
63 ip_dst='192.168.2.1')
64 pkt=str(parsed_pkt)
65 self.dataplane.send(port1, pkt)
66 #build expect packet
67 dst_mac[5]=2
68 port2_mac=':'.join(['%02X' % x for x in dst_mac])
69 exp_pkt = simple_tcp_packet(pktlen=100,
70 dl_vlan_enable=True,
71 vlan_vid=2,
72 eth_dst=port2_mac,
73 eth_src=switch_mac,
74 ip_ttl=63,
75 ip_src="192.168.1.1",
76 ip_dst='192.168.2.1')
77 pkt=str(exp_pkt)
78 verify_packet(self, pkt, port2)
79 verify_no_other_packets(self)
80
81 #port 2 to port 1
82 switch_mac = ':'.join(['%02X' % x for x in intf_src_mac])
83 dst_mac[5]=2
84 port2_mac=':'.join(['%02X' % x for x in dst_mac])
85
86 parsed_pkt = simple_tcp_packet(pktlen=100,
87 dl_vlan_enable=True,
88 vlan_vid=2,
89 eth_dst=switch_mac,
90 eth_src=port2_mac,
91 ip_ttl=64,
92 ip_src="192.168.2.1",
93 ip_dst='192.168.1.1')
94 pkt=str(parsed_pkt)
95 self.dataplane.send(port2, pkt)
96 #build expect packet
97 dst_mac[5]=1
98 port1_mac=':'.join(['%02X' % x for x in dst_mac])
99 exp_pkt = simple_tcp_packet(pktlen=100,
100 dl_vlan_enable=True,
101 vlan_vid=1,
102 eth_dst=port1_mac,
103 eth_src=switch_mac,
104 ip_ttl=63,
105 ip_src="192.168.2.1",
106 ip_dst='192.168.1.1')
107 pkt=str(exp_pkt)
108 verify_packet(self, pkt, port1)
109 verify_no_other_packets(self)
110