accton/accton_util.py
diff --git a/accton/accton_util.py b/accton/accton_util.py
index 26e7c6c..e6b2adc 100755
--- a/accton/accton_util.py
+++ b/accton/accton_util.py
@@ -696,7 +696,7 @@
return request
#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
-def add_nat_flow(ctrl, eth_type, ip_dst, ip_proto, tcp_dst, set_ip_dst, set_tcp_dst, action_group_id):
+def add_dnat_flow(ctrl, eth_type, ip_dst, ip_proto, tcp_dst, set_ip_dst, set_tcp_dst, action_group_id):
match = ofp.match()
match.oxm_list.append(ofp.oxm.eth_type(eth_type))
match.oxm_list.append(ofp.oxm.ipv4_dst(ip_dst))
@@ -719,6 +719,30 @@
logging.info("Inserting DNAT flow eth_type %lx, dip %lx, ip_proto %ld, tcp_dst %ld, SetFeild: Dip %lx, tcp_dst %ld, action_gorup=%lx",eth_type, ip_dst, ip_proto, tcp_dst, set_ip_dst, set_tcp_dst, action_group_id)
ctrl.message_send(request)
return request
+
+#dpctl tcp:192.168.1.1:6633 flow-mod table=29,cmd=add,prio=291 eth_type=0x800,ip_src=10.0.0.1,ip_proto=6,tcp_src=2000 write:set_field=ip_src:100.0.0.1,set_field=tcp_src:5000 goto:30
+def add_snat_flow(ctrl, eth_type, ip_src, ip_proto, tcp_src, set_ip_src, set_tcp_src):
+ match = ofp.match()
+ match.oxm_list.append(ofp.oxm.eth_type(eth_type))
+ match.oxm_list.append(ofp.oxm.ipv4_src(ip_src))
+ match.oxm_list.append(ofp.oxm.ip_proto(ip_proto))
+ match.oxm_list.append(ofp.oxm.tcp_src(tcp_src))
+
+ request = ofp.message.flow_add(
+ table_id=29,
+ cookie=42,
+ match=match,
+ instructions=[
+ ofp.instruction.write_actions(
+ actions=[ofp.action.set_field(ofp.oxm.ipv4_src(set_ip_src)),
+ ofp.action.set_field(ofp.oxm.tcp_src(set_tcp_src))]),
+ ofp.instruction.goto_table(30)
+ ],
+ buffer_id=ofp.OFP_NO_BUFFER,
+ priority=1)
+ logging.info("Inserting DNAT flow eth_type %lx, sip %lx, ip_proto %ld, tcp_src %ld, SetFeild: sip %lx, tcp_src %ld",eth_type, ip_src, ip_proto, tcp_src, set_ip_src, set_tcp_src)
+ ctrl.message_send(request)
+ return request
def get_vtap_lport_config_xml(dp_id, lport, phy_port, vlan, vnid, operation='merge'):
"""
diff --git a/accton/nat.py b/accton/nat.py
index 7696c2a..c9a03ff 100755
--- a/accton/nat.py
+++ b/accton/nat.py
@@ -103,7 +103,7 @@
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])
ecmp=add_l3_ecmp_group(self.controller, id=0x1000001, l3_ucast_groups=[msg1.group_id, msg2.group_id])
add_termination_flow(self.controller, 0, 0x0800, [0x00,0x00,0x00,0x00,0x02,0x00], 200, goto_table=28, send_barrier=False)
- 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)
+ add_dnat_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)
input_pkt = simple_tcp_packet(pktlen=100,
@@ -139,7 +139,84 @@
#self.dataplane.send(input_port, str(input_pkt))
#verify_packet(self, str(output_pkt2), output_port2)
+class snat_ecmp(base_tests.SimpleDataPlane):
+ """
+ [SNAT ECMP]
+ SNAT (outbound) with ECMP
+
+ Inject eth 1/1 DA000000000100, SA000000000101, Tag 100, SIP 10.0.0.1, DIP 200.0.0.01, Sport 2000, Dport 2828 [increase DIP]
+ Output eth 1/3 DA000000000200, SA000000000201, Tag 200, SIP 100.0.0.1, DIP 200.0.0.X, Sport 5000, Dport 2828
+ Output eth 1/5 DA000000000500, SA000000000501, Tag 5, SIP 100.0.0.1, DIP 200.0.0.X, Sport 5000, Dport 2828
+
+ ./dpctl tcp:192.168.1.1:6633 flow-mod table=10,cmd=add,prio=101 in_port=1,vlan_vid=0x1064/0x1fff goto:20
+ ./dpctl tcp:192.168.1.1:6633 flow-mod table=20,cmd=add,prio=201 vlan_vid=100/0xfff,eth_dst=00:00:00:00:01:00,eth_type=0x0800 goto:29
+ ./dpctl tcp:192.168.1.1:6633 group-mod cmd=add,type=ind,group=0xC80003 group=any,port=any,weight=0 output=3
+ ./dpctl tcp:192.168.1.1:6633 group-mod cmd=add,type=ind,group=0x22000002 group=any,port=any,weight=0 set_field=eth_src=00:00:00:00:02:00,set_field=eth_dst=00:00:00:00:02:01,set_field=vlan_vid=200,group=0xC80003
+ ./dpctl tcp:192.168.1.1:6633 group-mod cmd=add,type=ind,group=0x50005 group=any,port=any,weight=0 output=5
+ ./dpctl tcp:192.168.1.1:6633 group-mod cmd=add,type=ind,group=0x22000005 group=any,port=any,weight=0 set_field=eth_src=00:00:00:00:05:00,set_field=eth_dst=00:00:00:00:05:01,set_field=vlan_vid=5,group=0x50005
+
+ ./dpctl tcp:192.168.1.1:6633 group-mod cmd=add,type=sel,group=0x71000001 group=any,port=any,weight=0 group=0x22000002 group=any,port=any,weight=0 group=0x22000005
+ ./dpctl tcp:192.168.1.1:6633 flow-mod table=29,cmd=add,prio=291 eth_type=0x800,ip_src=10.0.0.1,ip_proto=6,tcp_src=2000 write:set_field=ip_src:100.0.0.1,set_field=tcp_src:5000 goto:30
+ ./dpctl tcp:192.168.1.1:6633 flow-mod table=30,cmd=add,prio=301 eth_type=0x0800,ip_dst=200.0.0.1/255.255.255.0 write:group=0x71000001 goto:60
+ """
+ def runTest(self):
+ delete_all_flows(self.controller)
+ delete_all_groups(self.controller)
+
+ test_ports = sorted(config["port_map"].keys())
+
+ input_port = test_ports[0]
+ output_port = test_ports[1]
+ output_port2 = test_ports[2]
+ add_one_vlan_table_flow(self.controller, input_port, vlan_id=100, vrf=0, flag=VLAN_TABLE_FLAG_ONLY_TAG, send_barrier=False)
+ add_termination_flow(self.controller, 0, 0x0800, [0x00,0x00,0x00,0x00,0x01,0x00], 100, goto_table=29, send_barrier=False)
+ add_one_l2_interface_grouop(self.controller, port=output_port, vlan_id=200, is_tagged=True, send_barrier=False)
+ #Bits 27:24 is for realm id, so unicast group id give 0x2000002
+ msg1=add_l3_unicast_group(self.controller, port=output_port, vlanid=200, id=0x2000002, src_mac=[0x00,0x00,0x00,0x00,0x02,0x00], dst_mac=[0x00,0x00,0x00,0x00,0x02,0x01])
+
+ add_one_l2_interface_grouop(self.controller, port=output_port2, vlan_id=5, is_tagged=True, send_barrier=False)
+ #Bits 27:24 is for realm id, so unicast group id give 0x2000002
+ msg2=add_l3_unicast_group(self.controller, port=output_port2, vlanid=5, id=0x2000005, src_mac=[0x00,0x00,0x00,0x00,0x05,0x00], dst_mac=[0x00,0x00,0x00,0x00,0x05,0x01])
+
+ ecmp=add_l3_ecmp_group(self.controller, id=0x1000001, l3_ucast_groups=[msg1.group_id, msg2.group_id])
+ add_snat_flow(self.controller, 0x0800, 0x0a000001, 6, 2000, 0x64000001, 5000)
+ add_unicast_routing_flow(self.controller, 0x0800, 0xc8000001, 0xffffff00, ecmp.group_id, vrf=0, send_barrier=False)
+
+ input_pkt = simple_tcp_packet(pktlen=100,
+ eth_dst="00:00:00:00:01:00",
+ eth_src="00:00:00:00:01:01",
+ dl_vlan_enable = True,
+ vlan_vid = 100,
+ ip_ttl=64,
+ ip_src='10.0.0.1',
+ ip_dst="200.0.0.1",
+ tcp_sport=2000)
+ output_pkt = simple_tcp_packet(pktlen=100,
+ eth_dst="00:00:00:00:02:01",
+ eth_src="00:00:00:00:02:00",
+ dl_vlan_enable = True,
+ vlan_vid = 200,
+ ip_ttl=63,
+ ip_src="100.0.0.1",
+ ip_dst='200.0.0.1',
+ tcp_sport=5000)
+ output_pkt2 = simple_tcp_packet(pktlen=100,
+ eth_dst="00:00:00:00:05:01",
+ eth_src="00:00:00:00:05:00",
+ dl_vlan_enable = True,
+ vlan_vid = 5,
+ ip_ttl=63,
+ ip_src="100.0.0.1",
+ ip_dst='200.0.0.1',
+ tcp_sport=5000)
+
+ self.dataplane.send(input_port, str(input_pkt))
+ verify_packet(self, str(output_pkt), output_port)
+ #self.dataplane.send(input_port, str(input_pkt))
+ #verify_packet(self, str(output_pkt2), output_port2)
+
+"""just for verify it can work after nat ecmp"""
class l3Route(base_tests.SimpleDataPlane):
"""
[L3 unicast route]