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 Oct 25, 2021
1 parent 125c820 commit 73f1dff
Show file tree
Hide file tree
Showing 15 changed files with 216 additions and 1 deletion.
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 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
bmv2 copp acl 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
../img/p4lang.img
1024
2
Expand Down
64 changes: 64 additions & 0 deletions misc/p4lang/forwarder.py
Original file line number Diff line number Diff line change
Expand Up @@ -2198,6 +2198,50 @@ def writeCpuMplsRules(delete, p4info_helper, ingress_sw, dst_label):
ingress_sw.DeleteTableEntry(table_entry2, False)


def writeNshFwdRules(delete, p4info_helper, ingress_sw, sp, si, prt, src, dst, tsp, tsi):
table_entry = p4info_helper.buildTableEntry(
table_name="ig_ctl.ig_ctl_nsh.tbl_nsh",
match_fields={
"hdr.nsh.sp": (sp),
"hdr.nsh.si": (si)
},
action_name="ig_ctl.ig_ctl_nsh.act_forward",
action_params={
"port": prt,
"src": src,
"dst": dst,
"sp": tsp,
"si": tsi
}
)
if delete == 1:
ingress_sw.WriteTableEntry(table_entry, False)
elif delete == 2:
ingress_sw.ModifyTableEntry(table_entry, False)
else:
ingress_sw.DeleteTableEntry(table_entry, False)


def writeNshLocRules(delete, p4info_helper, ingress_sw, sp, si, vrf):
table_entry = p4info_helper.buildTableEntry(
table_name="ig_ctl.ig_ctl_nsh.tbl_nsh",
match_fields={
"hdr.nsh.sp": (sp),
"hdr.nsh.si": (si)
},
action_name="ig_ctl.ig_ctl_nsh.act_route",
action_params={
"vrf": vrf
}
)
if delete == 1:
ingress_sw.WriteTableEntry(table_entry, False)
elif delete == 2:
ingress_sw.ModifyTableEntry(table_entry, False)
else:
ingress_sw.DeleteTableEntry(table_entry, False)


def writeMySrv4rules(delete, p4info_helper, ingress_sw, glob, dst_addr, vrf):
table_entry = p4info_helper.buildTableEntry(
table_name="ig_ctl.ig_ctl_ipv6.tbl_ipv6_fib_host",
Expand Down Expand Up @@ -2963,6 +3007,26 @@ def main(p4info_file_path, bmv2_file_path, p4runtime_address, freerouter_address
writeMyMplsRules(3,p4info_helper,sw1,int(splt[1]),int(splt[2]))
continue

if splt[0] == "nshfwd_add":
writeNshFwdRules(1,p4info_helper,sw1,int(splt[1]),int(splt[2]),int(splt[3]),splt[4],splt[5],int(splt[6]),int(splt[7]))
continue
if splt[0] == "nshfwd_mod":
writeNshFwdRules(2,p4info_helper,sw1,int(splt[1]),int(splt[2]),int(splt[3]),splt[4],splt[5],int(splt[6]),int(splt[7]))
continue
if splt[0] == "nshfwd_del":
writeNshFwdRules(3,p4info_helper,sw1,int(splt[1]),int(splt[2]),int(splt[3]),splt[4],splt[5],int(splt[6]),int(splt[7]))
continue

if splt[0] == "nshloc_add":
writeNshLocRules(1,p4info_helper,sw1,int(splt[1]),int(splt[2]),int(splt[3]))
continue
if splt[0] == "nshloc_mod":
writeNshLocRules(2,p4info_helper,sw1,int(splt[1]),int(splt[2]),int(splt[3]))
continue
if splt[0] == "nshloc_del":
writeNshLocRules(3,p4info_helper,sw1,int(splt[1]),int(splt[2]),int(splt[3]))
continue

if splt[0] == "neigh4_add":
writeNexthopRules(1,p4info_helper,sw1,int(splt[1]),splt[3],splt[5],int(splt[6]))
writeNeighborRules4(1,p4info_helper,sw1,splt[2],int(splt[1]),int(splt[4]))
Expand Down
1 change: 1 addition & 0 deletions misc/p4lang/include/cst_ethertype.p4
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const bit<16> ETHERTYPE_IPV4 = 0x0800;
const bit<16> ETHERTYPE_ARP = 0x0806;
const bit<16> ETHERTYPE_VLAN = 0x8100;
const bit<16> ETHERTYPE_IPV6 = 0x86dd;
const bit<16> ETHERTYPE_NSH = 0x894f;
const bit<16> ETHERTYPE_MPLS_UCAST = 0x8847;
const bit<16> ETHERTYPE_MPLS_MCAST = 0x8848;
const bit<16> ETHERTYPE_LACP = 0x8809;
Expand Down
1 change: 1 addition & 0 deletions misc/p4lang/include/cst_table_size.p4
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

#define NEXTHOP_TABLE_SIZE 2048
#define PPPOE_TABLE_SIZE 2048
#define NSH_TABLE_SIZE 2048
#define IPV4_TUNNEL_TABLE_SIZE 2048
#define IPV6_TUNNEL_TABLE_SIZE 2048

Expand Down
1 change: 1 addition & 0 deletions misc/p4lang/include/hdr_ig_headers.p4
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ struct headers {
l2tp_t l2tp2;
pppbr_t pppbr;
ethernet_t eth4;
nsh_t nsh;
mpls_t mpls0;
mpls_t mpls1;
bier_t bier;
Expand Down
34 changes: 34 additions & 0 deletions misc/p4lang/include/hdr_nsh.p4
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@

/*
* 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 _NSH_P4_
#define _NSH_P4_

header nsh_t {
bit<2> version;
bit<1> oam;
bit<1> res1;
bit<6> ttl;
bit<6> length;
bit<4> res2;
bit<4> md_type;
bit<8> next_proto;
bit<24> sp;
bit<8> si;
}

#endif // _NSH_P4_
2 changes: 2 additions & 0 deletions misc/p4lang/include/ig_ctl.p4
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ control ig_ctl(inout headers hdr,

IngressControlARP() ig_ctl_arp;
IngressControlPPPOE() ig_ctl_pppoe;
IngressControlNSH() ig_ctl_nsh;
IngressControlMPLS() ig_ctl_mpls;
IngressControlBridge() ig_ctl_bridge;
IngressControlIPv4() ig_ctl_ipv4;
Expand Down Expand Up @@ -77,6 +78,7 @@ control ig_ctl(inout headers hdr,
ig_ctl_vrf.apply(hdr,ig_md,ig_intr_md);
ig_ctl_arp.apply(hdr,ig_md,ig_intr_md);
ig_ctl_llc.apply(hdr,ig_md,ig_intr_md);
ig_ctl_nsh.apply(hdr,ig_md,ig_intr_md);
ig_ctl_mpls.apply(hdr,ig_md,ig_intr_md);
if (ig_md.need_clone == 1) {
if (hdr.vlan.isValid()) hdr.vlan.setInvalid();
Expand Down
2 changes: 2 additions & 0 deletions misc/p4lang/include/ig_ctl_bridge.p4
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,10 @@ hdr.ethernet.src_mac_addr:
action act_set_bridge_vpls(NextHopId_t port, label_t lab_tun, label_t lab_svc) {
ig_md.bridge_trg = MAX_PORT;
ig_md.vrf = 0;
ig_md.nsh_valid = 0;
ig_md.mpls0_valid = 0;
ig_md.mpls1_valid = 0;
ig_md.nsh_remove = 0;
ig_md.mpls0_remove = 0;
ig_md.mpls1_remove = 0;
ig_md.arp_valid = 0;
Expand Down
2 changes: 2 additions & 0 deletions misc/p4lang/include/ig_ctl_mpls.p4
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@ control IngressControlMPLS(inout headers hdr,
action act_mpls_cpulabel() {
ig_md.nexthop_id = CPU_PORT;
ig_md.mpls_op_type = 0;
ig_md.nsh_remove = 0;
ig_md.mpls0_remove = 0;
ig_md.mpls1_remove = 0;
ig_md.nsh_valid = 0;
ig_md.mpls0_valid = 0;
ig_md.mpls1_valid = 0;
ig_md.ipv4_valid = 0;
Expand Down
75 changes: 75 additions & 0 deletions misc/p4lang/include/ig_ctl_nsh.p4
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@

/*
* 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 _IG_CTL_NSH_P4_
#define _IG_CTL_NSH_P4_

control IngressControlNSH(inout headers hdr,
inout ingress_metadata_t ig_md,
inout standard_metadata_t ig_intr_md) {

direct_counter(CounterType.packets_and_bytes) stats;

action act_route(switch_vrf_t vrf) {
ig_md.vrf = vrf;
ig_md.nsh_remove = 1;
if (hdr.nsh.next_proto == 1) ig_md.ethertype = ETHERTYPE_IPV4;
if (hdr.nsh.next_proto == 2) ig_md.ethertype = ETHERTYPE_IPV6;
if (hdr.nsh.next_proto == 5) ig_md.ethertype = ETHERTYPE_MPLS_UCAST;
}

action act_forward(SubIntId_t port, mac_addr_t src, mac_addr_t dst, bit<24> sp, bit<8> si) {
hdr.vlan.setInvalid();
ig_md.nsh_remove = 0;
ig_md.target_id = port;
ig_md.mpls0_remove = 0;
ig_md.mpls1_remove = 0;
ig_md.mpls_op_type = 0;
ig_md.ipv4_valid = 0;
ig_md.ipv6_valid = 0;
hdr.ethernet.dst_mac_addr = dst;
hdr.ethernet.src_mac_addr = src;
hdr.nsh.sp = sp;
hdr.nsh.si = si;
}

table tbl_nsh {
key = {
hdr.nsh.sp:
exact;
hdr.nsh.si:
exact;
}
actions = {
act_forward;
act_route;
@defaultonly NoAction;
}
size = NSH_TABLE_SIZE;
default_action = NoAction();
counters = stats;
}

apply {
if (ig_md.nsh_valid==1) {
tbl_nsh.apply();
}
}
}

#endif // _IG_CTL_IPv4_P4_

8 changes: 8 additions & 0 deletions misc/p4lang/include/ig_ctl_outport.p4
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ ig_md.nexthop_id:
hdr.eth3.setInvalid();
}

if (ig_md.nsh_remove == 1) {
hdr.nsh.setInvalid();
}

if (ig_md.mpls1_remove == 1) {
hdr.mpls1.setInvalid();
}
Expand All @@ -95,6 +99,10 @@ ig_md.nexthop_id:

tbl_nexthop.apply();

if (hdr.nsh.isValid()) {
if (hdr.nsh.ttl < 2) act_set_drop();
hdr.nsh.ttl = hdr.nsh.ttl -1;
}
if (hdr.mpls0.isValid()) {
if (hdr.mpls0.ttl < 2) act_set_drop();
hdr.mpls0.ttl = hdr.mpls0.ttl -1;
Expand Down
2 changes: 2 additions & 0 deletions misc/p4lang/include/ig_ctl_vrf.p4
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@ control IngressControlVRF(inout headers hdr,

action act_set_mpls_xconn_encap(NextHopId_t target, label_t tunlab, label_t svclab) {
ig_md.vrf = 0;
ig_md.nsh_valid = 0;
ig_md.mpls0_valid = 0;
ig_md.mpls1_valid = 0;
ig_md.nsh_remove = 0;
ig_md.mpls0_remove = 0;
ig_md.mpls1_remove = 0;
ig_md.arp_valid = 0;
Expand Down
19 changes: 19 additions & 0 deletions misc/p4lang/include/ig_prs_main.p4
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ ETHERTYPE_PPPOE_CTRL :
prs_pppoeCtrl;
ETHERTYPE_PPPOE_DATA :
prs_pppoeData;
ETHERTYPE_NSH :
prs_nsh;
ETHERTYPE_MPLS_UCAST :
prs_mpls0;
ETHERTYPE_IPV4:
Expand Down Expand Up @@ -94,6 +96,8 @@ ETHERTYPE_PPPOE_CTRL :
prs_pppoeCtrl;
ETHERTYPE_PPPOE_DATA :
prs_pppoeData;
ETHERTYPE_NSH :
prs_nsh;
ETHERTYPE_MPLS_UCAST :
prs_mpls0;
ETHERTYPE_IPV4:
Expand Down Expand Up @@ -151,6 +155,21 @@ PPPTYPE_ROUTEDMAC:
transition accept;
}

state prs_nsh {
ig_md.nsh_valid = 1;
pkt.extract(hdr.nsh);
transition select(hdr.nsh.next_proto) {
8w1:
prs_ipv4;
8w2:
prs_ipv6;
8w5:
prs_mpls0;
default:
accept;
}
}

state prs_mpls0 {
pkt.extract(hdr.mpls0);
ig_md.mpls0_valid = 1;
Expand Down
2 changes: 2 additions & 0 deletions misc/p4lang/include/mtd_ig_metadata.p4
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,12 @@ struct ingress_metadata_t {
bit<3> mpls_op_type;
bit<3> srv_op_type;
bit<16> vlan_size;
bit<1> nsh_remove;
bit<1> mpls0_remove;
bit<1> mpls1_remove;
bit<1> pppoe_ctrl_valid;
bit<1> pppoe_data_valid;
bit<1> nsh_valid;
bit<1> mpls0_valid;
bit<1> mpls1_valid;
bit<1> llc_valid;
Expand Down
2 changes: 2 additions & 0 deletions misc/p4lang/router.p4
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "include/hdr_arp.p4"
#include "include/hdr_llc.p4"
#include "include/hdr_vlan.p4"
#include "include/hdr_nsh.p4"
#include "include/hdr_pppoe.p4"
#include "include/hdr_pppbr.p4"
#include "include/hdr_mpls.p4"
Expand Down Expand Up @@ -62,6 +63,7 @@
#include "include/ig_ctl_arp.p4"
#include "include/ig_ctl_llc.p4"
#include "include/ig_ctl_bridge.p4"
#include "include/ig_ctl_nsh.p4"
#include "include/ig_ctl_pppoe.p4"
#include "include/ig_ctl_tunnel.p4"
#include "include/ig_ctl_mpls.p4"
Expand Down

0 comments on commit 73f1dff

Please sign in to comment.