Skip to content

Commit

Permalink
Rename is_*_v4_or_v6 to *_is_v6. (#472)
Browse files Browse the repository at this point in the history
This makes code more explicit on 0 = v4 and 1 = v6.

This change will not change any generated code. Here is the diff for proof. Only comment update after make.
  • Loading branch information
r12f authored Dec 9, 2023
1 parent 56b8a6a commit c06909c
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 55 deletions.
55 changes: 28 additions & 27 deletions dash-pipeline/SAI/sai_api_gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,9 +293,9 @@ def __init__(self):
self.sai_key_name = ""
self.match_type = ""
self.bitwidth = 0
self.v4_or_v6_id = 0
self.ip_is_v6_field_id = 0

def parse_p4rt(self, p4rt_table_key, v4_or_v6_key_ids):
def parse_p4rt(self, p4rt_table_key, ip_is_v6_key_ids):
'''
This method parses the P4Runtime table key object and populates the SAI API table key object.
Expand Down Expand Up @@ -349,10 +349,10 @@ def parse_p4rt(self, p4rt_table_key, v4_or_v6_key_ids):
else:
raise ValueError(f"match_type={self.match_type} is not supported")

# If v4_or_v6 key is present, save its id.
v4_or_v6_key_name = "is_" + self.sai_key_name + "_v4_or_v6"
if v4_or_v6_key_name in v4_or_v6_key_ids:
self.v4_or_v6_id = v4_or_v6_key_ids[v4_or_v6_key_name]
# If *_is_v6 key is present, save its id.
ip_is_v6_key_name = self.sai_key_name + "_is_v6"
if ip_is_v6_key_name in ip_is_v6_key_ids:
self.ip_is_v6_field_id = ip_is_v6_key_ids[ip_is_v6_key_name]

return

Expand Down Expand Up @@ -390,17 +390,17 @@ def parse_action_params(self, p4rt_table_action, sai_enums):
if PARAMS_TAG not in p4rt_table_action:
return

# Save all *_v4_or_v6 param ids.
v4_or_v6_param_ids = dict()
# Save all *_is_v6 param ids.
ip_is_v6_param_ids = dict()
for p4rt_table_action_param in p4rt_table_action[PARAMS_TAG]:
if 'v4_or_v6' in p4rt_table_action_param[NAME_TAG]:
v4_or_v6_param_name = p4rt_table_action_param[NAME_TAG]
v4_or_v6_param_ids[v4_or_v6_param_name] = p4rt_table_action_param['id']
if '_is_v6' in p4rt_table_action_param[NAME_TAG]:
ip_is_v6_param_name = p4rt_table_action_param[NAME_TAG]
ip_is_v6_param_ids[ip_is_v6_param_name] = p4rt_table_action_param['id']

# Parse all params.
for p in p4rt_table_action[PARAMS_TAG]:
param_name = p[NAME_TAG]
param = SAIAPITableActionParam.from_p4rt(p, sai_enums = sai_enums, v4_or_v6_param_ids = v4_or_v6_param_ids)
param = SAIAPITableActionParam.from_p4rt(p, sai_enums = sai_enums, ip_is_v6_param_ids = ip_is_v6_param_ids)
self.params.append(param)

return
Expand All @@ -412,10 +412,10 @@ def __init__(self):
super().__init__()
self.bitwidth = 0
self.default = None
self.v4_or_v6_id = 0
self.ip_is_v6_field_id = 0
self.paramActions = []

def parse_p4rt(self, p4rt_table_action_param, sai_enums, v4_or_v6_param_ids):
def parse_p4rt(self, p4rt_table_action_param, sai_enums, ip_is_v6_param_ids):
'''
This method parses the P4Runtime table action object and populates the SAI API table action object.
Expand All @@ -439,10 +439,10 @@ def parse_p4rt(self, p4rt_table_action_param, sai_enums, v4_or_v6_param_ids):

self.bitwidth = p4rt_table_action_param[BITWIDTH_TAG]

# If v4_or_v6 key is present, save its id.
v4_or_v6_param_name = "is_" + self.name + "_v4_or_v6"
if v4_or_v6_param_name in v4_or_v6_param_ids:
self.v4_or_v6_id = v4_or_v6_param_ids[v4_or_v6_param_name]
# If *_is_v6 key is present, save its id.
ip_is_v6_param_name = self.name + "_is_v6"
if ip_is_v6_param_name in ip_is_v6_param_ids:
self.ip_is_v6_field_id = ip_is_v6_param_ids[ip_is_v6_param_name]

return

Expand All @@ -467,7 +467,7 @@ def __init__(self):
self.is_object = None

def parse_p4rt(self, p4rt_table, program, all_actions, ignore_tables):
table_control, table_name = p4rt_table[PREAMBLE_TAG][NAME_TAG].split('.', 1)
_, table_name = p4rt_table[PREAMBLE_TAG][NAME_TAG].split('.', 1)

if table_name in ignore_tables:
self.ignored = True
Expand Down Expand Up @@ -530,17 +530,18 @@ def __table_with_counters(self, program):
return 'false'

def __parse_table_keys(self, p4rt_table):
v4_or_v6_key_ids = dict()
ip_is_v6_key_ids = dict()
for p4rt_table_key in p4rt_table[MATCH_FIELDS_TAG]:
if 'v4_or_v6' in p4rt_table_key[NAME_TAG]:
_, v4_or_v6_key_name = p4rt_table_key[NAME_TAG].split(':')
v4_or_v6_key_ids[v4_or_v6_key_name] = p4rt_table_key['id']
if '_is_v6' in p4rt_table_key[NAME_TAG]:
_, ip_is_v6_key_name = p4rt_table_key[NAME_TAG].split(':')
ip_is_v6_key_ids[ip_is_v6_key_name] = p4rt_table_key['id']

for p4rt_table_key in p4rt_table[MATCH_FIELDS_TAG]:
if 'v4_or_v6' in p4rt_table_key[NAME_TAG]:
# Skip all *_is_v6 keys, as they will be linked via table key property.
if '_is_v6' in p4rt_table_key[NAME_TAG]:
continue

table_key = SAIAPITableKey.from_p4rt(p4rt_table_key, v4_or_v6_key_ids)
table_key = SAIAPITableKey.from_p4rt(p4rt_table_key, ip_is_v6_key_ids)
self.keys.append(table_key)

for p4rt_table_key in self.keys:
Expand All @@ -560,8 +561,8 @@ def __merge_action_params_to_table_params(self, action):
we only need to keep one copy of the param in the table, so we don't generate multiple SAI attributes.
'''
for action_param in action.params:
# skip v4/v6 selector, as they are linked via parameter property already.
if 'v4_or_v6' in action_param.name:
# skip v4/v6 selector, as they are linked via parameter property.
if '_is_v6' in action_param.name:
continue

for table_action_param in self.action_params:
Expand Down
30 changes: 15 additions & 15 deletions dash-pipeline/SAI/templates/saiapi.cpp.j2
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,11 @@ static sai_status_t dash_sai_create_{{ table.name }}(
assert(mask && "SAI_{{ table.name | upper }}_ATTR_{{ key.sai_key_name | upper }}_MASK isn't provided");
{{key.field}}SetMask(mask->value, mf_ternary, {{key.bitwidth}});
{% endif %}
{% if key.v4_or_v6_id != 0 %}
{% if key.ip_is_v6_field_id != 0 %}
{
// set v4_or_v6 field
// set ip_is_v6_field_id field
auto mf = matchActionEntry->add_match();
mf->set_field_id({{key.v4_or_v6_id}});
mf->set_field_id({{key.ip_is_v6_field_id}});
auto mf_exact = mf->mutable_exact();
booldataSetVal((attr_list[i].value.ipaddr.addr_family == SAI_IP_ADDR_FAMILY_IPV4) ? 0 : 1, mf_exact, 1);
}
Expand Down Expand Up @@ -187,11 +187,11 @@ static sai_status_t dash_sai_create_{{ table.name }}(
param->set_param_id({{param.id}});
{{param.field}}SetVal(attr_list[i].value, param, {{param.bitwidth}});
//matchedParams++;
{% if param.v4_or_v6_id != 0 %}
{% if param.ip_is_v6_field_id != 0 %}
{
// set v4_or_v6 field
// set ip_is_v6_field_id field
auto param2 = action->add_params();
param2->set_param_id({{param.v4_or_v6_id}});
param2->set_param_id({{param.ip_is_v6_field_id}});
booldataSetVal((attr_list[i].value.ipaddr.addr_family == SAI_IP_ADDR_FAMILY_IPV4) ? 0 : 1, param2, 1);
//matchedParams++;
}
Expand Down Expand Up @@ -364,11 +364,11 @@ static sai_status_t dash_sai_create_{{ table.name }}(
//{{key.field}}SetVal(attr_list[i].value, mf1_list, {{key.bitwidth}});
{% endif %}
}
{% if key.v4_or_v6_id != 0 %}
{% if key.ip_is_v6_field_id != 0 %}
{
// set v4_or_v6 field
// set ip_is_v6_field_id field
auto mf = matchActionEntry->add_match();
mf->set_field_id({{key.v4_or_v6_id}});
mf->set_field_id({{key.ip_is_v6_field_id}});
auto mf_exact = mf->mutable_exact();
booldataSetVal((tableEntry->{{ key.sai_key_name | lower }}.addr_family == SAI_IP_ADDR_FAMILY_IPV4) ? 0 : 1, mf_exact, 1);
}
Expand Down Expand Up @@ -422,11 +422,11 @@ static sai_status_t dash_sai_create_{{ table.name }}(
param->set_param_id({{param.id}});
{{param.field}}SetVal(attr_list[i].value, param, {{param.bitwidth}});
//matchedParams++;
{% if param.v4_or_v6_id != 0 %}
{% if param.ip_is_v6_field_id != 0 %}
{
// set v4_or_v6 field
// set ip_is_v6_field_id field
auto param2 = action->add_params();
param2->set_param_id({{param.v4_or_v6_id}});
param2->set_param_id({{param.ip_is_v6_field_id}});
booldataSetVal((attr_list[i].value.ipaddr.addr_family == SAI_IP_ADDR_FAMILY_IPV4) ? 0 : 1, param2, 1);
//matchedParams++;
}
Expand Down Expand Up @@ -527,11 +527,11 @@ static sai_status_t dash_sai_remove_{{ table.name }}(
//{{key.field}}SetVal(attr_list[i].value, mf1_list, {{key.bitwidth}});
{% endif %}
}
{% if key.v4_or_v6_id != 0 %}
{% if key.ip_is_v6_field_id != 0 %}
{
// set v4_or_v6 field
// set ip_is_v6_field_id field
auto mf = matchActionEntry->add_match();
mf->set_field_id({{key.v4_or_v6_id}});
mf->set_field_id({{key.ip_is_v6_field_id}});
auto mf_exact = mf->mutable_exact();
booldataSetVal((tableEntry->{{ key.sai_key_name | lower }}.addr_family == SAI_IP_ADDR_FAMILY_IPV4) ? 0 : 1, mf_exact, 1);
}
Expand Down
26 changes: 13 additions & 13 deletions dash-pipeline/bmv2/dash_outbound.p4
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ control outbound(inout headers_t hdr,
}

action route_vnet_direct(bit<16> dst_vnet_id,
bit<1> is_overlay_ip_v4_or_v6,
bit<1> overlay_ip_is_v6,
IPv4ORv6Address overlay_ip,
bit<1> meter_policy_en,
bit<16> meter_class) {
meta.dst_vnet_id = dst_vnet_id;
meta.lkup_dst_ip_addr = overlay_ip;
meta.is_lkup_dst_ip_v6 = is_overlay_ip_v4_or_v6;
meta.is_lkup_dst_ip_v6 = overlay_ip_is_v6;
set_route_meter_attrs(meter_policy_en, meter_class);
}

Expand All @@ -42,26 +42,26 @@ control outbound(inout headers_t hdr,
meta.dropped = true;
}

action route_service_tunnel(bit<1> is_overlay_dip_v4_or_v6,
action route_service_tunnel(bit<1> overlay_dip_is_v6,
IPv4ORv6Address overlay_dip,
bit<1> is_overlay_dip_mask_v4_or_v6,
bit<1> overlay_dip_mask_is_v6,
IPv4ORv6Address overlay_dip_mask,
bit<1> is_overlay_sip_v4_or_v6,
bit<1> overlay_sip_is_v6,
IPv4ORv6Address overlay_sip,
bit<1> is_overlay_sip_mask_v4_or_v6,
bit<1> overlay_sip_mask_is_v6,
IPv4ORv6Address overlay_sip_mask,
bit<1> is_underlay_dip_v4_or_v6,
bit<1> underlay_dip_is_v6,
IPv4ORv6Address underlay_dip,
bit<1> is_underlay_sip_v4_or_v6,
bit<1> underlay_sip_is_v6,
IPv4ORv6Address underlay_sip,
dash_encapsulation_t dash_encapsulation,
bit<24> tunnel_key,
bit<1> meter_policy_en,
bit<16> meter_class) {
/* Assume the overlay addresses provided are always IPv6 and the original are IPv4 */
/* assert(is_overlay_dip_v4_or_v6 == 1 && is_overlay_sip_v4_or_v6 == 1);
assert(is_overlay_dip_mask_v4_or_v6 == 1 && is_overlay_sip_mask_v4_or_v6 == 1);
assert(is_underlay_dip_v4_or_v6 != 1 && is_underlay_sip_v4_or_v6 != 1); */
/* assert(overlay_dip_is_v6 == 1 && overlay_sip_is_v6 == 1);
assert(overlay_dip_mask_is_v6 == 1 && overlay_sip_mask_is_v6 == 1);
assert(underlay_dip_is_v6 != 1 && underlay_sip_is_v6 != 1); */
meta.encap_data.original_overlay_dip = hdr.ipv4.src_addr;
meta.encap_data.original_overlay_sip = hdr.ipv4.dst_addr;

Expand Down Expand Up @@ -95,7 +95,7 @@ control outbound(inout headers_t hdr,
table routing {
key = {
meta.eni_id : exact @name("meta.eni_id:eni_id");
meta.is_overlay_ip_v6 : exact @name("meta.is_overlay_ip_v6:is_destination_v4_or_v6");
meta.is_overlay_ip_v6 : exact @name("meta.is_overlay_ip_v6:destination_is_v6");
meta.dst_ip_addr : lpm @name("meta.dst_ip_addr:destination");
}

Expand Down Expand Up @@ -179,7 +179,7 @@ control outbound(inout headers_t hdr,
key = {
/* Flow for express route */
meta.dst_vnet_id: exact @name("meta.dst_vnet_id:dst_vnet_id");
meta.is_lkup_dst_ip_v6 : exact @name("meta.is_lkup_dst_ip_v6:is_dip_v4_or_v6");
meta.is_lkup_dst_ip_v6 : exact @name("meta.is_lkup_dst_ip_v6:dip_is_v6");
meta.lkup_dst_ip_addr : exact @name("meta.lkup_dst_ip_addr:dip");
}

Expand Down

0 comments on commit c06909c

Please sign in to comment.