macauley_cheng | b75de69 | 2015-11-09 13:50:32 +0800 | [diff] [blame^] | 1 | """
|
| 2 | Nat Test
|
| 3 |
|
| 4 | Test each flow table can set entry, and packet rx correctly.
|
| 5 | """
|
| 6 |
|
| 7 | import logging
|
| 8 |
|
| 9 | from oftest import config
|
| 10 | import oftest.base_tests as base_tests
|
| 11 | import ofp
|
| 12 | from oftest.testutils import *
|
| 13 | from accton_util import *
|
| 14 |
|
| 15 | class dnat(base_tests.SimpleDataPlane):
|
| 16 | """
|
| 17 | [DNAT]
|
| 18 | DNAT (inbound)
|
| 19 |
|
| 20 | Inject eth 1/3 DA000000000200, SA000000000201, Tag 200, SIP 200.0.0.1, DIP 100.0.0.01, Sport 2828, Dport 5000
|
| 21 | Output eth 1/1 DA000000000101, SA000000000100, Tag 100, SIP 200.0.0.1, DIP 10.0.0.01, Sport 2828, Dport 2000
|
| 22 |
|
| 23 | ./dpctl tcp:192.168.1.1:6633 flow-mod table=10,cmd=add,prio=101 in_port=3,vlan_vid=0x10c8/0x1fff goto:20
|
| 24 | ./dpctl tcp:192.168.1.1:6633 group-mod cmd=add,type=ind,group=0x640001 group=any,port=any,weight=0 output=1
|
| 25 | ./dpctl tcp:192.168.1.1:6633 group-mod cmd=add,type=ind,group=0x23000001 group=any,port=any,weight=0 set_field=eth_src=00:00:00:00:01:00,set_field=eth_dst=00:00:00:00:01:01,set_field=vlan_vid=100,group=0x640001
|
| 26 | ./dpctl tcp:192.168.1.1:6633 flow-mod table=20,cmd=add,prio=201 vlan_vid=200/0xfff,eth_dst=00:00:00:00:02:00,eth_type=0x0800 goto:28
|
| 27 | ./dpctl tcp:192.168.1.1:6633 flow-mod table=28,cmd=add,prio=281 eth_type=0x800,ip_dst=100.0.0.1,ip_proto=6,tcp_dst=5000 write:set_field=ip_dst:10.0.0.1,set_field=tcp_dst:2000,group=0x23000001 goto:60
|
| 28 | """
|
| 29 | def runTest(self):
|
| 30 | delete_all_flows(self.controller)
|
| 31 | delete_all_groups(self.controller)
|
| 32 |
|
| 33 | test_ports = sorted(config["port_map"].keys())
|
| 34 |
|
| 35 | input_port = test_ports[0]
|
| 36 | output_port = test_ports[1]
|
| 37 |
|
| 38 | add_one_vlan_table_flow(self.controller, input_port, vlan_id=200, vrf=0, flag=VLAN_TABLE_FLAG_ONLY_BOTH, send_barrier=False)
|
| 39 | add_termination_flow(self.controller, input_port, 0x0800, [0x00,0x00,0x00,0x00,0x02,0x00], 200, goto_table=28, send_barrier=False)
|
| 40 |
|
| 41 | add_one_l2_interface_grouop(self.controller, port=output_port, vlan_id=100, is_tagged=True, send_barrier=False)
|
| 42 | msg1=add_l3_unicast_group(self.controller, port=output_port, vlanid=100, id=0x3000001, src_mac=[0x00,0x00,0x00,0x00,0x01,0x00], dst_mac=[0x00,0x00,0x00,0x00,0x01,0x01])
|
| 43 | add_nat_flow(self.controller, eth_type=0x0800, ip_dst=0x64000001, ip_proto=6, tcp_dst=5000, set_ip_dst=0x0a000001, set_tcp_dst=2000, action_group_id=msg1.group_id)
|
| 44 |
|
| 45 | input_pkt = simple_tcp_packet(pktlen=100,
|
| 46 | eth_dst="00:00:00:00:02:00",
|
| 47 | eth_src="00:00:00:00:02:01",
|
| 48 | dl_vlan_enable = True,
|
| 49 | vlan_vid = 200,
|
| 50 | ip_ttl=64,
|
| 51 | ip_src="200.0.0.1",
|
| 52 | ip_dst='100.0.0.1',
|
| 53 | tcp_dport=5000)
|
| 54 | output_pkt = simple_tcp_packet(pktlen=100,
|
| 55 | eth_dst="00:00:00:00:01:01",
|
| 56 | eth_src="00:00:00:00:01:00",
|
| 57 | dl_vlan_enable = True,
|
| 58 | vlan_vid = 100,
|
| 59 | ip_ttl=63,
|
| 60 | ip_src="200.0.0.1",
|
| 61 | ip_dst='10.0.0.1',
|
| 62 | tcp_dport=2000)
|
| 63 |
|
| 64 | self.dataplane.send(input_port, str(input_pkt))
|
| 65 | verify_packet(self, str(output_pkt), output_port)
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 | class dnatEcmp(base_tests.SimpleDataPlane):
|
| 70 | """
|
| 71 | [DNAT ECMP]
|
| 72 | DNAT (inbound) with ECMP
|
| 73 |
|
| 74 | Inject eth 1/3 DA000000000200, SA000000000201, Tag 200, SIP 200.0.0.1, DIP 100.0.0.01, Sport 2828, Dport 5000 [increase SIP]
|
| 75 | Output eth 1/1 DA000000000101, SA000000000100, Tag 100, SIP 200.0.0.X, DIP 10.0.0.01, Sport 2828, Dport 2000
|
| 76 | Output eth 1/5 DA000005224466, SA000005223355, Tag 2, SIP 200.0.0.X, DIP 10.0.0.01, Sport 2828, Dport 2000
|
| 77 |
|
| 78 | ./dpctl tcp:192.168.1.1:6633 flow-mod table=10,cmd=add,prio=101 in_port=3,vlan_vid=0x10c8/0x1fff goto:20
|
| 79 | ./dpctl tcp:192.168.1.1:6633 group-mod cmd=add,type=ind,group=0x640001 group=any,port=any,weight=0 output=1
|
| 80 | ./dpctl tcp:192.168.1.1:6633 group-mod cmd=add,type=ind,group=0x23000001 group=any,port=any,weight=0 set_field=eth_src=00:00:00:00:01:00,set_field=eth_dst=00:00:00:00:01:01,set_field=vlan_vid=100,group=0x640001
|
| 81 | ./dpctl tcp:192.168.1.1:6633 group-mod cmd=add,type=ind,group=0x20005 group=any,port=any,weight=0 output=5
|
| 82 | ./dpctl tcp:192.168.1.1:6633 group-mod cmd=add,type=ind,group=0x23000005 group=any,port=any,weight=0 set_field=eth_src=00:00:05:22:33:55,set_field=eth_dst=00:00:05:22:44:66,set_field=vlan_vid=2,group=0x20005
|
| 83 | ./dpctl tcp:192.168.1.1:6633 group-mod cmd=add,type=sel,group=0x71000001 group=any,port=any,weight=0 group=0x23000001 group=any,port=any,weight=0 group=0x23000005
|
| 84 | ./dpctl tcp:192.168.1.1:6633 flow-mod table=20,cmd=add,prio=201 vlan_vid=200/0xfff,eth_dst=00:00:00:00:02:00,eth_type=0x0800 goto:28
|
| 85 |
|
| 86 | ./dpctl tcp:192.168.1.1:6633 flow-mod table=28,cmd=add,prio=281 eth_type=0x800,ip_dst=100.0.0.1,ip_proto=6,tcp_dst=5000 write:set_field=ip_dst:10.0.0.1,set_field=tcp_dst:2000,group=0x71000001 goto:60
|
| 87 | """
|
| 88 | def runTest(self):
|
| 89 | delete_all_flows(self.controller)
|
| 90 | delete_all_groups(self.controller)
|
| 91 |
|
| 92 | test_ports = config["port_map"].keys()
|
| 93 | input_port = test_ports[0]
|
| 94 | output_port = test_ports[1]
|
| 95 | output_port2 = test_ports[2]
|
| 96 |
|
| 97 | add_one_vlan_table_flow(self.controller, input_port, vlan_id=200, vrf=0, flag=VLAN_TABLE_FLAG_ONLY_TAG, send_barrier=False)
|
| 98 | add_one_l2_interface_grouop(self.controller, port=output_port, vlan_id=100, is_tagged=True, send_barrier=False)
|
| 99 | #Bits 27:24 is for realm id, so unicast group id give 0x3000001
|
| 100 | msg1=add_l3_unicast_group(self.controller, port=output_port, vlanid=100, id=0x3000001, src_mac=[0x00,0x00,0x00,0x00,0x01,0x00], dst_mac=[0x00,0x00,0x00,0x00,0x01,0x01])
|
| 101 | add_one_l2_interface_grouop(self.controller, port=output_port2, vlan_id=2, is_tagged=True, send_barrier=False)
|
| 102 | #Bits 27:24 is for realm id, so unicast group id give 0x3000005
|
| 103 | msg2=add_l3_unicast_group(self.controller, port=output_port2, vlanid=2, id=0x3000005, src_mac=[0x00,0x00,0x05,0x22,0x33,0x55], dst_mac=[0x00,0x00,0x05,0x22,0x44,0x66])
|
| 104 | ecmp=add_l3_ecmp_group(self.controller, id=0x1000001, l3_ucast_groups=[msg1.group_id, msg2.group_id])
|
| 105 | add_termination_flow(self.controller, 0, 0x0800, [0x00,0x00,0x00,0x00,0x02,0x00], 200, goto_table=28, send_barrier=False)
|
| 106 | add_nat_flow(self.controller, eth_type=0x0800, ip_dst=0x64000001, ip_proto=6, tcp_dst=5000, set_ip_dst=0x0a000001, set_tcp_dst=2000, action_group_id=ecmp.group_id)
|
| 107 |
|
| 108 |
|
| 109 | input_pkt = simple_tcp_packet(pktlen=100,
|
| 110 | eth_dst="00:00:00:00:02:00",
|
| 111 | eth_src="00:00:00:00:02:01",
|
| 112 | dl_vlan_enable = True,
|
| 113 | vlan_vid = 200,
|
| 114 | ip_ttl=64,
|
| 115 | ip_src="200.0.0.1",
|
| 116 | ip_dst='100.0.0.1',
|
| 117 | tcp_dport=5000)
|
| 118 | output_pkt = simple_tcp_packet(pktlen=100,
|
| 119 | eth_dst="00:00:00:00:01:01",
|
| 120 | eth_src="00:00:00:00:01:00",
|
| 121 | dl_vlan_enable = True,
|
| 122 | vlan_vid = 100,
|
| 123 | ip_ttl=63,
|
| 124 | ip_src="200.0.0.1",
|
| 125 | ip_dst='10.0.0.1',
|
| 126 | tcp_dport=2000)
|
| 127 | output_pkt2 = simple_tcp_packet(pktlen=100,
|
| 128 | eth_dst="00:00:05:22:44:66",
|
| 129 | eth_src="00:00:05:22:33:55",
|
| 130 | dl_vlan_enable = True,
|
| 131 | vlan_vid = 2,
|
| 132 | ip_ttl=63,
|
| 133 | ip_src="200.0.0.1",
|
| 134 | ip_dst='10.0.0.1',
|
| 135 | tcp_dport=2000)
|
| 136 |
|
| 137 | self.dataplane.send(input_port, str(input_pkt))
|
| 138 | verify_packet(self, str(output_pkt2), output_port2)
|
| 139 | #self.dataplane.send(input_port, str(input_pkt))
|
| 140 | #verify_packet(self, str(output_pkt2), output_port2)
|
| 141 |
|
| 142 |
|
| 143 | class l3Route(base_tests.SimpleDataPlane):
|
| 144 | """
|
| 145 | [L3 unicast route]
|
| 146 | Do unicast route and output to specified port
|
| 147 |
|
| 148 | Inject eth 1/3 Tag2, SA000000112233, DA7072cf7cf3a3, SIP 192.168.1.100, DIP 192.168.2.2
|
| 149 | Output eth 1/1 Tag3, SA 000004223355, DA 000004224466
|
| 150 |
|
| 151 | ./dpctl tcp:192.168.1.1:6633 flow-mod table=0,cmd=add,prio=1 in_port=0/0xffff0000 goto:10
|
| 152 | ./dpctl tcp:192.168.1.1:6633 flow-mod table=10,cmd=add,prio=101 in_port=3,vlan_vid=0x1002/0x1fff goto:20
|
| 153 | ./dpctl tcp:192.168.1.1:6633 flow-mod table=20,cmd=add,prio=201 in_port=3,vlan_vid=2/0xfff,eth_dst=70:72:cf:7c:f3:a3,eth_type=0x0800 goto:30
|
| 154 | ./dpctl tcp:192.168.1.1:6633 group-mod cmd=add,type=ind,group=0x30001 group=any,port=any,weight=0 output=1
|
| 155 | ./dpctl tcp:192.168.1.1:6633 group-mod cmd=add,type=ind,group=0x20000003 group=any,port=any,weight=0 set_field=eth_src=00:00:04:22:33:55,set_field=eth_dst=00:00:04:22:44:66,set_field=vlan_vid=3,group=0x30001
|
| 156 | ./dpctl tcp:192.168.1.1:6633 flow-mod table=30,cmd=add,prio=301 eth_type=0x0800,ip_dst=192.168.2.2/255.255.255.0 write:group=0x20000003 goto:60
|
| 157 | """
|
| 158 | def runTest(self):
|
| 159 | delete_all_flows(self.controller)
|
| 160 | delete_all_groups(self.controller)
|
| 161 |
|
| 162 | test_ports = sorted(config["port_map"].keys())
|
| 163 |
|
| 164 | input_port = test_ports[0]
|
| 165 | output_port = test_ports[1]
|
| 166 |
|
| 167 | add_port_table_flow(self.controller, is_overlay=False)
|
| 168 | add_one_vlan_table_flow(self.controller, input_port, vlan_id=2, vrf=0, flag=VLAN_TABLE_FLAG_ONLY_TAG, send_barrier=False)
|
| 169 | add_termination_flow(self.controller, input_port, 0x0800, [0x70, 0x72, 0xcf, 0x7c, 0xf3, 0xa3], 2, send_barrier=False)
|
| 170 | add_one_l2_interface_grouop(self.controller, port=output_port, vlan_id=3, is_tagged=True, send_barrier=False)
|
| 171 | msg=add_l3_unicast_group(self.controller, port=output_port, vlanid=3, id=3, src_mac=[0x00,0x00,0x04,0x22,0x33,0x55], dst_mac=[0x00,0x00,0x04,0x22,0x44,0x66])
|
| 172 | add_unicast_routing_flow(self.controller, 0x0800, 0xc0a80202, 0xffffff00, msg.group_id)
|
| 173 |
|
| 174 | #verify tx/rx packet
|
| 175 | input_pkt = simple_tcp_packet(pktlen=100,
|
| 176 | eth_dst="70:72:cf:7c:f3:a3",
|
| 177 | eth_src="00:00:00:00:02:01",
|
| 178 | dl_vlan_enable = True,
|
| 179 | vlan_vid = 2,
|
| 180 | ip_ttl=64,
|
| 181 | ip_src="200.0.0.1",
|
| 182 | ip_dst='192.168.2.2')
|
| 183 | output_pkt = simple_tcp_packet(pktlen=100,
|
| 184 | eth_dst="00:00:04:22:44:66",
|
| 185 | eth_src="00:00:04:22:33:55",
|
| 186 | dl_vlan_enable = True,
|
| 187 | vlan_vid = 3,
|
| 188 | ip_ttl=63,
|
| 189 | ip_src="200.0.0.1",
|
| 190 | ip_dst='192.168.2.2')
|
| 191 |
|
| 192 | self.dataplane.send(input_port, str(input_pkt))
|
| 193 | verify_packet(self, str(output_pkt), output_port)
|
| 194 |
|
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
|
| 199 |
|
| 200 | |