blob: bfdc88f491a0dbed818bf3e32f34db01f21696e6 [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
Flavio Castro6efe1862015-11-18 16:28:06 -050016class L2Unicast(base_tests.SimpleDataPlane):
17 def runTest(self):
18 delete_all_flows(self.controller)
19 delete_all_groups(self.controller)
20
21 if len(config["port_map"]) <2:
22 logging.info("Port count less than 2, can't run this case")
23 return
24
25 vlan_id=1
26 mac=[0x00, 0x00, 0x00, 0x22, 0x22, 0x00]
27 for port in config["port_map"].keys():
28 #add l2 interface group
29 add_one_l2_interface_grouop(self.controller, port, vlan_id=vlan_id, is_tagged=True, send_barrier=False)
30 #add vlan flow table
31 add_one_vlan_table_flow(self.controller, port, vlan_id, flag=VLAN_TABLE_FLAG_ONLY_BOTH)
32 #add Bridgin table exact match
33 group_id = encode_l2_interface_group_id(vlan_id, port)
34 mac[5]=port
35 add_bridge_flow(self.controller, mac, vlan_id, group_id, True)
36
37 do_barrier(self.controller)
38
39 for outport in config["port_map"].keys():
40 mac[5]=outport
41 dst_mac=':'.join(['%02X' % x for x in mac])
42 for inport in config["port_map"].keys():
43 if inport is not outport:
44 mac[5]=inport
45 src_mac = ':'.join(['%02X' % x for x in mac])
46 parsed_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True, vlan_vid=1, eth_dst=dst_mac,
47 eth_src=src_mac, ip_src="192.168.1.1", ip_dst='192.168.1.2')
48 pkt=str(parsed_pkt)
49 self.dataplane.send(inport, pkt)
50 verify_packet(self, pkt, outport)
51 verify_no_other_packets(self)
52
53
Flavio Castro05d20bc2015-11-16 15:06:14 -050054class L3UcastRoute(base_tests.SimpleDataPlane):
55 """
56 Port1(vlan1, 0x00, 0x00, 0x00, 0x22, 0x22, 0x01, 192.168.1.1) ,
57 Port2(vlan2, 0x00, 0x00, 0x00, 0x22, 0x22, 0x02, 19.168.2.1)
58 """
59 def runTest(self):
60 delete_all_flows(self.controller)
61 delete_all_groups(self.controller)
62
63 if len(config["port_map"]) <2:
64 logging.info("Port count less than 2, can't run this case")
65 return
66
67 vlan_id=1
68 intf_src_mac=[0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc]
69 dst_mac=[0x00, 0x00, 0x00, 0x22, 0x22, 0x00]
70 dip=0xc0a80001
71 for port in config["port_map"].keys():
72 #add l2 interface group
73 add_one_l2_interface_grouop(self.controller, port, vlan_id=vlan_id, is_tagged=True, send_barrier=False)
74 dst_mac[5]=vlan_id
75 l3_msg=add_l3_unicast_group(self.controller, port, vlanid=vlan_id, id=vlan_id, src_mac=intf_src_mac, dst_mac=dst_mac)
76 #add vlan flow table
77 add_one_vlan_table_flow(self.controller, port, vlan_id, flag=VLAN_TABLE_FLAG_ONLY_BOTH)
78 #add termination flow
79 add_termination_flow(self.controller, port, 0x0800, intf_src_mac, vlan_id)
80 #add unicast routing flow
81 dst_ip = dip + (vlan_id<<8)
Flavio Castro6efe1862015-11-18 16:28:06 -050082 add_unicast_routing_flow(self.controller, 0x0800, dst_ip, 0, l3_msg.group_id)
83
84 #add entries in the Bridging table to avoid packet-in from mac learning
85 group_id = encode_l2_interface_group_id(vlan_id, port)
86 add_bridge_flow(self.controller, dst_mac, vlan_id, group_id, True)
87
Flavio Castro05d20bc2015-11-16 15:06:14 -050088 vlan_id += 1
89
90 do_barrier(self.controller)
91
92 port1=config["port_map"].keys()[0]
93 port2=config["port_map"].keys()[1]
94 #port 1 to port 2
95 switch_mac = ':'.join(['%02X' % x for x in intf_src_mac])
96 dst_mac[5]=1
97 port1_mac=':'.join(['%02X' % x for x in dst_mac])
98
99 parsed_pkt = simple_tcp_packet(pktlen=100,
100 dl_vlan_enable=True,
101 vlan_vid=1,
102 eth_dst=switch_mac,
103 eth_src=port1_mac,
104 ip_ttl=64,
105 ip_src="192.168.1.1",
106 ip_dst='192.168.2.1')
107 pkt=str(parsed_pkt)
108 self.dataplane.send(port1, pkt)
109 #build expect packet
110 dst_mac[5]=2
111 port2_mac=':'.join(['%02X' % x for x in dst_mac])
112 exp_pkt = simple_tcp_packet(pktlen=100,
113 dl_vlan_enable=True,
114 vlan_vid=2,
115 eth_dst=port2_mac,
116 eth_src=switch_mac,
117 ip_ttl=63,
118 ip_src="192.168.1.1",
119 ip_dst='192.168.2.1')
120 pkt=str(exp_pkt)
121 verify_packet(self, pkt, port2)
122 verify_no_other_packets(self)
123
124 #port 2 to port 1
125 switch_mac = ':'.join(['%02X' % x for x in intf_src_mac])
126 dst_mac[5]=2
127 port2_mac=':'.join(['%02X' % x for x in dst_mac])
128
129 parsed_pkt = simple_tcp_packet(pktlen=100,
130 dl_vlan_enable=True,
131 vlan_vid=2,
132 eth_dst=switch_mac,
133 eth_src=port2_mac,
134 ip_ttl=64,
135 ip_src="192.168.2.1",
136 ip_dst='192.168.1.1')
137 pkt=str(parsed_pkt)
138 self.dataplane.send(port2, pkt)
139 #build expect packet
140 dst_mac[5]=1
141 port1_mac=':'.join(['%02X' % x for x in dst_mac])
142 exp_pkt = simple_tcp_packet(pktlen=100,
143 dl_vlan_enable=True,
144 vlan_vid=1,
145 eth_dst=port1_mac,
146 eth_src=switch_mac,
147 ip_ttl=63,
148 ip_src="192.168.2.1",
149 ip_dst='192.168.1.1')
150 pkt=str(exp_pkt)
151 verify_packet(self, pkt, port1)
152 verify_no_other_packets(self)
153