Skip to content

Commit

Permalink
automatic commit at releng box
Browse files Browse the repository at this point in the history
  • Loading branch information
mc36 committed Mar 4, 2022
1 parent 8884273 commit 355d2cf
Show file tree
Hide file tree
Showing 9 changed files with 270 additions and 3 deletions.
2 changes: 1 addition & 1 deletion cfg/p4lang1.ini
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
bmv2 copp acl racl inspect nat vlan bundle bridge pppoe hairpin gre l2tp route mpls vpls evpn eompls srv6 gretap pppoetap l2tptap vxlan ipip pckoudp pbr qos flwspc mroute duplab bier nsh sgt
bmv2 copp acl racl inspect nat vlan bundle bridge pppoe hairpin gre l2tp route mpls vpls evpn eompls srv6 gretap pppoetap l2tptap vxlan ipip pckoudp pbr qos flwspc mroute duplab bier nsh sgt amt gtp
../img/p4lang.img
1024
2
Expand Down
103 changes: 102 additions & 1 deletion misc/p4lang/forwarder.py
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,99 @@ def writeAmt6rules(delete, p4info_helper, ingress_sw, nexthop, port, phport, sip



def writeGtp4rules(delete, p4info_helper, ingress_sw, nexthop, port, phport, sip, dip, dmac, vrf, smac, sprt, dprt, teid):
table_entry1 = p4info_helper.buildTableEntry(
table_name="ig_ctl.ig_ctl_tunnel.tbl_tunnel4",
match_fields={
"ig_md.vrf": vrf,
"hdr.ipv4.protocol": 17,
"hdr.ipv4.src_addr": dip,
"hdr.ipv4.dst_addr": sip,
"ig_md.layer4_srcprt": dprt,
"ig_md.layer4_dstprt": sprt,
},
action_name="ig_ctl.ig_ctl_tunnel.act_tunnel_gtp",
action_params={
"port": port
})
table_entry2 = p4info_helper.buildTableEntry(
table_name="eg_ctl.eg_ctl_nexthop.tbl_nexthop",
match_fields={
"eg_md.nexthop_id": nexthop,
},
action_name="eg_ctl.eg_ctl_nexthop.act_ipv4_gtp4",
action_params={
"dst_mac_addr": dmac,
"src_mac_addr": smac,
"egress_port": phport,
"acl_port": port,
"src_ip_addr": sip,
"dst_ip_addr": dip,
"src_port": sprt,
"dst_port": dprt,
"teid": teid,
})
if delete == 1:
ingress_sw.WriteTableEntry(table_entry1, False)
elif delete == 2:
ingress_sw.ModifyTableEntry(table_entry1, False)
else:
ingress_sw.DeleteTableEntry(table_entry1, False)
if delete == 1:
ingress_sw.WriteTableEntry(table_entry2, False)
elif delete == 2:
ingress_sw.ModifyTableEntry(table_entry2, False)
else:
ingress_sw.DeleteTableEntry(table_entry2, False)


def writeGtp6rules(delete, p4info_helper, ingress_sw, nexthop, port, phport, sip, dip, dmac, vrf, smac, sprt, dprt, teid):
table_entry1 = p4info_helper.buildTableEntry(
table_name="ig_ctl.ig_ctl_tunnel.tbl_tunnel6",
match_fields={
"ig_md.vrf": vrf,
"hdr.ipv6.next_hdr": 17,
"hdr.ipv6.src_addr": dip,
"hdr.ipv6.dst_addr": sip,
"ig_md.layer4_srcprt": dprt,
"ig_md.layer4_dstprt": sprt,
},
action_name="ig_ctl.ig_ctl_tunnel.act_tunnel_gtp",
action_params={
"port": port
})
table_entry2 = p4info_helper.buildTableEntry(
table_name="eg_ctl.eg_ctl_nexthop.tbl_nexthop",
match_fields={
"eg_md.nexthop_id": nexthop,
},
action_name="eg_ctl.eg_ctl_nexthop.act_ipv4_gtp6",
action_params={
"dst_mac_addr": dmac,
"src_mac_addr": smac,
"egress_port": phport,
"acl_port": port,
"src_ip_addr": sip,
"dst_ip_addr": dip,
"src_port": sprt,
"dst_port": dprt,
"teid": teid,
})
if delete == 1:
ingress_sw.WriteTableEntry(table_entry1, False)
elif delete == 2:
ingress_sw.ModifyTableEntry(table_entry1, False)
else:
ingress_sw.DeleteTableEntry(table_entry1, False)
if delete == 1:
ingress_sw.WriteTableEntry(table_entry2, False)
elif delete == 2:
ingress_sw.ModifyTableEntry(table_entry2, False)
else:
ingress_sw.DeleteTableEntry(table_entry2, False)



def writeVxlan4rules(delete, p4info_helper, ingress_sw, bridge, addr, sip, dip, nexthop, instance, vrf, port):
table_entry1 = p4info_helper.buildTableEntry(
table_name="ig_ctl.ig_ctl_bridge.tbl_bridge_learn",
Expand Down Expand Up @@ -2857,7 +2950,7 @@ def main(p4info_file_path, bmv2_file_path, p4runtime_address, freerouter_address
sck.connect((freerouter_address, int(freerouter_port)))
fil = sck.makefile('w')
fil.write("platform bmv2\r\n");
fil.write("capabilities copp acl racl inspect nat vlan bundle bridge pppoe hairpin gre l2tp route mpls vpls evpn eompls gretap pppoetap l2tptap vxlan ipip macsec ipsec pckoudp openvpn wireguard srv6 pbr qos flwspc mroute duplab bier amt nsh sgt amt\r\n");
fil.write("capabilities copp acl racl inspect nat vlan bundle bridge pppoe hairpin gre l2tp route mpls vpls evpn eompls gretap pppoetap l2tptap vxlan ipip macsec ipsec pckoudp openvpn wireguard srv6 pbr qos flwspc mroute duplab bier nsh sgt amt gtp\r\n");
for x in range(0, 10):
data = "portname %i bmv2-port%i\r\n" % (x,x)
fil.write(data)
Expand Down Expand Up @@ -3124,6 +3217,14 @@ def main(p4info_file_path, bmv2_file_path, p4runtime_address, freerouter_address
writeAmt6rules(mode,p4info_helper,sw1,int(splt[1]),int(splt[2]),int(splt[3]),splt[4],splt[5],splt[6],int(splt[7]),splt[8],int(splt[9]),int(splt[10]))
continue

if cmds[0] == "gtp4":
writeGtp4rules(mode,p4info_helper,sw1,int(splt[1]),int(splt[2]),int(splt[3]),splt[4],splt[5],splt[6],int(splt[7]),splt[8],int(splt[9]),int(splt[10]),int(splt[11]))
continue

if cmds[0] == "gtp6":
writeGtp6rules(mode,p4info_helper,sw1,int(splt[1]),int(splt[2]),int(splt[3]),splt[4],splt[5],splt[6],int(splt[7]),splt[8],int(splt[9]),int(splt[10]),int(splt[11]))
continue

if cmds[0] == "bridgevxlan4":
writeVxlan4rules(mode,p4info_helper,sw1,int(splt[1]),splt[2],splt[3],splt[4],int(splt[5]),int(splt[6]),int(splt[7]),int(splt[8]));
continue
Expand Down
95 changes: 95 additions & 0 deletions misc/p4lang/include/eg_ctl_nexthop.p4
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,99 @@ control EgressControlNexthop(inout headers hdr,



action act_ipv4_gtp4(mac_addr_t dst_mac_addr, mac_addr_t src_mac_addr, SubIntId_t egress_port, SubIntId_t acl_port, ipv4_addr_t dst_ip_addr, ipv4_addr_t src_ip_addr, bit<16> src_port, bit<16> dst_port, bit<32> teid) {
/*
* the packet header src_mac is now set to the previous header dst_mac
*/
hdr.ethernet.src_mac_addr = src_mac_addr;

/*
* the new packet header dst_mac is now the dst_mac
* set by the control plane entry
*/
hdr.ethernet.dst_mac_addr = dst_mac_addr;

/*
* the egress_spec port is set now the egress_port
* set by the control plane entry
*/
eg_md.target_id = egress_port;
eg_md.aclport_id = acl_port;

hdr.gtp2.setValid();
hdr.gtp2.flag = 0x30;
hdr.gtp2.type = 0xff;
hdr.gtp2.length = (bit<16>)eg_intr_md.packet_length - eg_md.vlan_size - 14;
hdr.gtp2.teid = teid;

hdr.udp2.setValid();
hdr.udp2.src_port = src_port;
hdr.udp2.dst_port = dst_port;
hdr.udp2.length = (bit<16>)eg_intr_md.packet_length - eg_md.vlan_size - 14 + 16;
hdr.udp2.checksum = 0;

hdr.ipv4d.setValid();
hdr.ipv4d.version = 4;
hdr.ipv4d.ihl = 5;
hdr.ipv4d.diffserv = 0;
hdr.ipv4d.total_len = (bit<16>)eg_intr_md.packet_length - eg_md.vlan_size - 14 + 36;
hdr.ipv4d.identification = 0;
hdr.ipv4d.flags = 0;
hdr.ipv4d.frag_offset = 0;
hdr.ipv4d.ttl = 255;
hdr.ipv4d.protocol = IP_PROTOCOL_UDP;
hdr.ipv4d.hdr_checksum = 0;
hdr.ipv4d.src_addr = src_ip_addr;
hdr.ipv4d.dst_addr = dst_ip_addr;
eg_md.ethertype = ETHERTYPE_IPV4;
}


action act_ipv4_gtp6(mac_addr_t dst_mac_addr, mac_addr_t src_mac_addr, SubIntId_t egress_port, SubIntId_t acl_port, ipv6_addr_t dst_ip_addr, ipv6_addr_t src_ip_addr, bit<16> src_port, bit<16> dst_port, bit<32> teid) {
/*
* the packet header src_mac is now set to the previous header dst_mac
*/
hdr.ethernet.src_mac_addr = src_mac_addr;

/*
* the new packet header dst_mac is now the dst_mac
* set by the control plane entry
*/
hdr.ethernet.dst_mac_addr = dst_mac_addr;

/*
* the egress_spec port is set now the egress_port
* set by the control plane entry
*/
eg_md.target_id = egress_port;
eg_md.aclport_id = acl_port;

hdr.gtp2.setValid();
hdr.gtp2.flag = 0x30;
hdr.gtp2.type = 0xff;
hdr.gtp2.length = (bit<16>)eg_intr_md.packet_length - eg_md.vlan_size - 14;
hdr.gtp2.teid = teid;

hdr.udp2.setValid();
hdr.udp2.src_port = src_port;
hdr.udp2.dst_port = dst_port;
hdr.udp2.length = (bit<16>)eg_intr_md.packet_length - eg_md.vlan_size - 14 + 16;
hdr.udp2.checksum = 0;

hdr.ipv6d.setValid();
hdr.ipv6d.version = 6;
hdr.ipv6d.traffic_class = 0;
hdr.ipv6d.flow_label = 0;
hdr.ipv6d.payload_len = (bit<16>)eg_intr_md.packet_length - eg_md.vlan_size - 14 + 16;
hdr.ipv6d.next_hdr = IP_PROTOCOL_UDP;
hdr.ipv6d.hop_limit = 255;
hdr.ipv6d.src_addr = src_ip_addr;
hdr.ipv6d.dst_addr = dst_ip_addr;
eg_md.ethertype = ETHERTYPE_IPV6;
}




action act_ipv4_fib_discard() {
mark_to_drop(eg_intr_md);
Expand All @@ -439,6 +532,8 @@ eg_md.nexthop_id:
act_ipv4_l2tp6;
act_ipv4_amt4;
act_ipv4_amt6;
act_ipv4_gtp4;
act_ipv4_gtp6;
act_ipv4_fib_discard;
}
size = NEXTHOP_TABLE_SIZE;
Expand Down
29 changes: 29 additions & 0 deletions misc/p4lang/include/hdr_gtp.p4
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright 2019-present GT RARE project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed On an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#ifndef _GTP_P4_
#define _GTP_P4_

header gtp_t {
bit<8> flag;
bit<8> type;
bit<16> length;
bit<32> teid;
}

#endif // _GTP_P4_


2 changes: 2 additions & 0 deletions misc/p4lang/include/hdr_ig_headers.p4
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ struct headers {
vxlan_t vxlan2;
l2tp_t l2tp2;
amt_t amt2;
gtp_t gtp2;
pppbr_t pppbr;
ethernet_t eth4;
polka_t polka;
Expand All @@ -54,6 +55,7 @@ struct headers {
udp_t udp;
l2tp_t l2tp;
amt_t amt;
gtp_t gtp;
vxlan_t vxlan;
tcp_t tcp;
pppbr_t l2tpbr;
Expand Down
12 changes: 12 additions & 0 deletions misc/p4lang/include/ig_ctl_tunnel.p4
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,15 @@ control IngressControlTunnel(inout headers hdr,
}


action act_tunnel_gtp(SubIntId_t port) {
if (ig_md.gtp_type == 4) hdr.ethernet.ethertype = ETHERTYPE_IPV4;
if (ig_md.gtp_type == 6) hdr.ethernet.ethertype = ETHERTYPE_IPV6;
ig_intr_md.egress_spec = (PortId_t)port;
ig_md.need_recir = 1;
ig_md.source_id = port;
}



table tbl_tunnel4 {
key = {
Expand All @@ -108,6 +117,7 @@ ig_md.layer4_dstprt:
act_tunnel_vxlan;
act_tunnel_pckoudp;
act_tunnel_amt;
act_tunnel_gtp;
@defaultonly NoAction;
}
size = IPV4_TUNNEL_TABLE_SIZE;
Expand Down Expand Up @@ -138,6 +148,7 @@ ig_md.layer4_dstprt:
act_tunnel_vxlan;
act_tunnel_pckoudp;
act_tunnel_amt;
act_tunnel_gtp;
@defaultonly NoAction;
}
size = IPV6_TUNNEL_TABLE_SIZE;
Expand All @@ -161,6 +172,7 @@ ig_md.layer4_dstprt:
hdr.vxlan.setInvalid();
hdr.l2tp.setInvalid();
hdr.amt.setInvalid();
hdr.gtp.setInvalid();
hdr.udp.setInvalid();
hdr.gre.setInvalid();
hdr.ipv4.setInvalid();
Expand Down
28 changes: 27 additions & 1 deletion misc/p4lang/include/ig_prs_main.p4
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,10 @@ ETHERTYPE_ROUTEDMAC:
prs_amt;
(0 &&& 0, 2268):
prs_amt;
(2152, 0 &&& 0):
prs_gtp;
(0 &&& 0, 2152):
prs_gtp;
(4789, 0 &&& 0):
prs_vxlan;
(0 &&& 0, 4789):
Expand Down Expand Up @@ -407,7 +411,6 @@ PPPTYPE_ROUTEDMAC:

state prs_amt {
pkt.extract(hdr.amt);
hdr.amt.reserved = 0;
transition select((pkt.lookahead<bit<4>>())[3:0]) {
4w0x4:
prs_amt4;
Expand All @@ -429,6 +432,29 @@ PPPTYPE_ROUTEDMAC:
}


state prs_gtp {
pkt.extract(hdr.gtp);
transition select((pkt.lookahead<bit<4>>())[3:0]) {
4w0x4:
prs_gtp4;
4w0x6:
prs_gtp6;
default:
accept;
}
}

state prs_gtp4 {
ig_md.gtp_type = 4;
transition accept;
}

state prs_gtp6 {
ig_md.gtp_type = 6;
transition accept;
}


state prs_l2tpbr {
pkt.extract(hdr.l2tpbr);
transition prs_eth5;
Expand Down
1 change: 1 addition & 0 deletions misc/p4lang/include/mtd_ig_metadata.p4
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ struct ingress_metadata_t {
bit<3> mpls_op_type;
bit<3> srv_op_type;
bit<3> amt_type;
bit<3> gtp_type;
bit<16> vlan_size;
bit<1> sgt_remove;
bit<1> polka_remove;
Expand Down
1 change: 1 addition & 0 deletions misc/p4lang/router.p4
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
#include "include/hdr_l2tp.p4"
#include "include/hdr_vxlan.p4"
#include "include/hdr_amt.p4"
#include "include/hdr_gtp.p4"

/*----------------------------------------------------------------------------*
* I N G R E S S P R O C E S S I N G *
Expand Down

0 comments on commit 355d2cf

Please sign in to comment.