Skip to content

Commit

Permalink
Normalize Sirius P4 pipeline tables
Browse files Browse the repository at this point in the history
  • Loading branch information
mukeshmv committed May 31, 2022
1 parent e420737 commit 4035541
Show file tree
Hide file tree
Showing 7 changed files with 152 additions and 174 deletions.
32 changes: 19 additions & 13 deletions SAI/sai_api_gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
PIPELINES_TAG = 'pipelines'
NAME_TAG = 'name'
INGRESS_PIPE = 'ingress'
EGRESS_PIPE = 'egress'
TABLES_TAG = 'tables'
KEY_TAG = 'key'

Expand All @@ -23,14 +24,18 @@ def get_ingress_pipeline(json_program):

return None

def get_egress_pipeline(json_program):
for pipe in json_program[PIPELINES_TAG]:
if pipe[NAME_TAG] == EGRESS_PIPE:
return pipe

def get_tables(ingress_pipeline):
tables = []
for table in ingress_pipeline[TABLES_TAG]:
return None


def get_tables(tables, pipeline):
for table in pipeline[TABLES_TAG]:
if len(table[KEY_TAG]) > 0:
tables.append(table)

return tables


def get_sai_key_type(key_size, key_header, key_field):
Expand Down Expand Up @@ -135,7 +140,9 @@ def get_sai_action_data(program, action_name):

def generate_sai_api(program, ignore_tables):
sai_api = dict()
tables = get_tables(get_ingress_pipeline(program))
tables = []
get_tables(tables, get_ingress_pipeline(program))
get_tables(tables, get_egress_pipeline(program))
sai_tables = []
for table in tables:
sai_table_data = dict()
Expand Down Expand Up @@ -271,10 +278,6 @@ def write_sai_files(sai_api):
exit(1)


if os.path.exists('./SAI'):
print('Directory ./SAI already exists. Please remove in order to proceed')
exit(1)

# Get SAI dictionary from P4 dictionary
print("Generating SAI API...")
with open(args.filepath) as json_program_file:
Expand All @@ -283,9 +286,12 @@ def write_sai_files(sai_api):
sai_api = generate_sai_api(json_program, args.ignore_tables.split(','))
sai_api['app_name'] = args.apiname

# Clone a clean SAI repo
print("Cloning SAI repository...")
Repo.clone_from(args.sai_git_url, './SAI', branch=args.sai_git_branch)
if os.path.exists('./SAI'):
print('Directory ./SAI already exists.')
else:
# Clone a clean SAI repo
print("Cloning SAI repository...")
Repo.clone_from(args.sai_git_url, './SAI', branch=args.sai_git_branch)

# Write SAI dictionary into SAI API headers
write_sai_files(sai_api)
Expand Down
4 changes: 2 additions & 2 deletions sirius-pipeline/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ DOCKER_RUN := docker run \
--rm \
bmv2-$(USER)

bmv2/sirius_pipeline.bmv2/sirius_pipeline.json:
bmv2/sirius_pipeline.bmv2/sirius_pipeline.json: bmv2/*.p4
$(DOCKER_RUN) p4c -b bmv2 bmv2/sirius_pipeline.p4 -o bmv2/sirius_pipeline.bmv2

clean:
rm -rf bmv2/sirius_pipeline.bmv2

run-switch:
$(DOCKER_RUN) simple_switch --log-console --interface 0@veth0 --interface 1@veth2 /bmv2/sirius_pipeline.bmv2/sirius_pipeline.json
$(DOCKER_RUN) sudo LD_LIBRARY_PATH=/usr/local/lib simple_switch --log-console --interface 0@veth0 --interface 1@veth2 /bmv2/sirius_pipeline.bmv2/sirius_pipeline.json

docker:
docker build \
Expand Down
14 changes: 7 additions & 7 deletions sirius-pipeline/bmv2/sirius_acl.p4
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ match_kind {
direct_counter(CounterType.packets_and_bytes) ## table_name ##_counter; \
table table_name { \
key = { \
meta.eni : exact @name("meta.eni:eni"); \
hdr.ipv4.dst_addr : list @name("hdr.ipv4.dst_addr:dip"); \
hdr.ipv4.src_addr : list @name("hdr.ipv4.src_addr:sip"); \
hdr.ipv4.protocol : list @name("hdr.ipv4.src_addr:protocol"); \
hdr.tcp.src_port : range_list @name("hdr.tcp.src_port:sport"); \
hdr.tcp.dst_port : range_list @name("hdr.tcp.dst_port:dport"); \
meta. ## table_name ##_acl_group_id : exact @name("meta.acl_group_id:acl_group_id"); \
hdr.ipv4.dst_addr : optional @name("hdr.ipv4.dst_addr:dip"); \
hdr.ipv4.src_addr : optional @name("hdr.ipv4.src_addr:sip"); \
hdr.ipv4.protocol : optional @name("hdr.ipv4.src_addr:protocol"); \
hdr.tcp.src_port : optional @name("hdr.tcp.src_port:sport"); \
hdr.tcp.dst_port : optional @name("hdr.tcp.dst_port:dport"); \
} \
actions = { \
permit; \
Expand All @@ -40,7 +40,7 @@ match_kind {
deny: {return;} \
}

/*
/*
* This control results in a new set of tables every time
* it is applied, i. e. inbound ACL tables are different
* from outbound, and API will be generated for each of them
Expand Down
82 changes: 0 additions & 82 deletions sirius-pipeline/bmv2/sirius_inbound.p4

This file was deleted.

8 changes: 8 additions & 0 deletions sirius-pipeline/bmv2/sirius_metadata.p4
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@ struct metadata_t {
encap_data_t encap_data;
EthernetAddress eni_addr;
bit<16> eni;
bit<16> stage1_acl_group_id;
bit<16> stage2_acl_group_id;
bit<16> stage3_acl_group_id;
bit<16> acl_group_id;
bit<16> route_table_id;
bit<16> tunnel_id;
bit<16> vnet;
bit<24> lookup_vni;
bit<16> vm_id;
bit<8> appliance_id;
bit<1> is_dst_ip_v6;
Expand Down
51 changes: 2 additions & 49 deletions sirius-pipeline/bmv2/sirius_outbound.p4
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,11 @@
#define _SIRIUS_OUTBOUND_P4_

#include "sirius_headers.p4"
#include "sirius_acl.p4"
#include "sirius_conntrack.p4"

control outbound(inout headers_t hdr,
inout metadata_t meta,
inout standard_metadata_t standard_metadata)
{
action set_vni(bit<24> vni) {
meta.encap_data.vni = vni;
}

table eni_to_vni {
key = {
meta.eni : exact @name("meta.eni:eni");
}

actions = {
set_vni;
}
}

action route_vnet(bit<24> dest_vnet_vni) {
meta.encap_data.dest_vnet_vni = dest_vnet_vni;
}
Expand All @@ -43,7 +27,7 @@ control outbound(inout headers_t hdr,
counters = routing_counter;
}

action set_tunnel_mapping(IPv4Address underlay_dip,
action set_tunnel_mapping(bit<16> tunnel_id,
EthernetAddress overlay_dmac,
bit<1> use_dst_vni) {
/*
Expand All @@ -54,7 +38,7 @@ control outbound(inout headers_t hdr,
*/
meta.encap_data.vni = meta.encap_data.vni * (bit<24>)(~use_dst_vni) + meta.encap_data.dest_vnet_vni * (bit<24>)use_dst_vni;
meta.encap_data.overlay_dmac = overlay_dmac;
meta.encap_data.underlay_dip = underlay_dip;
meta.tunnel_id = tunnel_id;
}

direct_counter(CounterType.packets_and_bytes) ca_to_pa_counter;
Expand All @@ -75,40 +59,9 @@ control outbound(inout headers_t hdr,
}

apply {
eni_to_vni.apply();

#ifdef STATEFUL_P4
ConntrackOut.apply(0);
#endif /* STATEFUL_P4 */

#ifdef PNA_CONNTRACK
ConntrackOut.apply(hdr, meta);
#endif // PNA_CONNTRACK

/* ACL */
if (!meta.conntrack_data.allow_out) {
acl.apply(hdr, meta, standard_metadata);
}

#ifdef STATEFUL_P4
ConntrackIn.apply(1);
#endif /* STATEFUL_P4 */

#ifdef PNA_CONNTRACK
ConntrackIn.apply(hdr, meta);
#endif // PNA_CONNTRACK

switch (routing.apply().action_run) {
route_vnet: {
ca_to_pa.apply();

vxlan_encap(hdr,
meta.encap_data.underlay_dmac,
meta.encap_data.underlay_smac,
meta.encap_data.underlay_dip,
meta.encap_data.underlay_sip,
meta.encap_data.overlay_dmac,
meta.encap_data.vni);
}
}
}
Expand Down
Loading

0 comments on commit 4035541

Please sign in to comment.