Skip to content
This repository has been archived by the owner on Apr 29, 2024. It is now read-only.

Removed duplicate code. #21

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 1 addition & 40 deletions p4c_bm/plugin/sai/inc/sai_templ.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,46 +20,7 @@ limitations under the License.
#include <p4_sim/saitypes.h>

//:: p4_pd_prefix = "p4_pd_" + p4_prefix + "_"

//:: def get_type(byte_width):
//:: if byte_width == 1:
//:: return "uint8_t"
//:: elif byte_width == 2:
//:: return "uint16_t"
//:: elif byte_width <= 4:
//:: return "uint32_t"
//:: else:
//:: return "uint8_t *"
//:: #endif
//:: #enddef
//::
//:: # match_fields is list of tuples (name, type)
//:: def gen_match_params(match_fields, field_info):
//:: params = []
//:: for field, type in match_fields:
//:: if type == "valid":
//:: params += [(field + "_valid", 1)]
//:: continue
//:: #endif
//:: f_info = field_info[field]
//:: bytes_needed = (f_info["bit_width"] + 7 ) / 8
//:: params += [(field, bytes_needed)]
//:: if type == "lpm": params += [(field + "_prefix_length", 2)]
//:: if type == "ternary": params += [(field + "_mask", bytes_needed)]
//:: #endfor
//:: return params
//:: #enddef
//::
//:: def gen_action_params(names, byte_widths, _get_type = get_type):
//:: params = []
//:: for name, width in zip(names, byte_widths):
//:: name = "action_" + name
//:: params += [(name, width)]
//:: #endfor
//:: return params
//:: #enddef
//::
//::
//:: from common import *

//:: for table, t_info in table_info.items():

Expand Down
40 changes: 1 addition & 39 deletions p4c_bm/plugin/sai/src/p4_sai_rpc_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,45 +76,7 @@ class sai_p4_saiHandler : virtual public sai_p4_saiIf {
return 0;
}

//:: def get_type(byte_width):
//:: if byte_width == 1:
//:: return "uint8_t"
//:: elif byte_width == 2:
//:: return "uint16_t"
//:: elif byte_width <= 4:
//:: return "uint32_t"
//:: else:
//:: return "const std::string&"
//:: #endif
//:: #enddef
//::
//:: # match_fields is list of tuples (name, type)
//:: def gen_match_params(match_fields, field_info):
//:: params = []
//:: for field, type in match_fields:
//:: if type == "valid":
//:: params += [(field + "_valid", 1)]
//:: continue
//:: #endif
//:: f_info = field_info[field]
//:: bytes_needed = (f_info["bit_width"] + 7 ) / 8
//:: params += [(field, bytes_needed)]
//:: if type == "lpm": params += [(field + "_prefix_length", 2)]
//:: if type == "ternary": params += [(field + "_mask", bytes_needed)]
//:: #endfor
//:: return params
//:: #enddef
//::
//:: def gen_action_params(names, byte_widths, _get_type = get_type):
//:: params = []
//:: for name, width in zip(names, byte_widths):
//:: name = "action_" + name
//:: params += [(name, width)]
//:: #endfor
//:: return params
//:: #enddef
//::
//::
//:: from common import *

//:: for table, t_info in table_info.items():

Expand Down
39 changes: 1 addition & 38 deletions p4c_bm/plugin/sai/src/sai_templ.c
Original file line number Diff line number Diff line change
Expand Up @@ -136,44 +136,7 @@ typedef enum {
} p4_table_opcode_t;


//:: def get_type(byte_width):
//:: if byte_width == 1:
//:: return "uint8_t"
//:: elif byte_width == 2:
//:: return "uint16_t"
//:: elif byte_width <= 4:
//:: return "uint32_t"
//:: else:
//:: return "uint8_t *"
//:: #endif
//:: #enddef
//::
//:: # match_fields is list of tuples (name, type)
//:: def gen_match_params(match_fields, field_info):
//:: params = []
//:: for field, type in match_fields:
//:: if type == "valid":
//:: params += [(field + "_valid", 1)]
//:: continue
//:: #endif
//:: f_info = field_info[field]
//:: bytes_needed = (f_info["bit_width"] + 7 ) / 8
//:: params += [(field, bytes_needed)]
//:: if type == "lpm": params += [(field + "_prefix_length", 2)]
//:: if type == "ternary": params += [(field + "_mask", bytes_needed)]
//:: #endfor
//:: return params
//:: #enddef
//::
//:: def gen_action_params_name(names, byte_widths, _get_type = get_type):
//:: params = []
//:: for name, width in zip(names, byte_widths):
//:: params += [("action_" + name, width, name)]
//:: #endfor
//:: return params
//:: #enddef
//::
//::
//:: from common import *

//:: for table, t_info in table_info.items():
/*
Expand Down
44 changes: 1 addition & 43 deletions p4c_bm/plugin/sai/thrift/p4_sai_rpc.thrift
Original file line number Diff line number Diff line change
Expand Up @@ -53,49 +53,7 @@ struct sai_attribute_list {
3: list<sai_attribute> attr_list;
}

//:: def get_type(byte_width):
//:: if byte_width == 1:
//:: return "byte"
//:: elif byte_width == 2:
//:: return "i16"
//:: elif byte_width <= 4:
//:: return "i32"
//:: elif byte_width == 6:
//:: return "MacAddr_t"
//:: elif byte_width == 16:
//:: return "IPv6_t"
//:: else:
//:: return "string"
//:: #endif
//:: #enddef
//::
//:: # match_fields is list of tuples (name, type)
//:: def gen_match_params(match_fields, field_info):
//:: params = []
//:: for field, type in match_fields:
//:: if type == "valid":
//:: params += [(field + "_valid", 1)]
//:: continue
//:: #endif
//:: f_info = field_info[field]
//:: bytes_needed = (f_info["bit_width"] + 7 ) / 8
//:: params += [(field, bytes_needed)]
//:: if type == "lpm": params += [(field + "_prefix_length", 2)]
//:: if type == "ternary": params += [(field + "_mask", bytes_needed)]
//:: #endfor
//:: return params
//:: #enddef
//::
//:: def gen_action_params(names, byte_widths, _get_type = get_type):
//:: params = []
//:: for name, width in zip(names, byte_widths):
//:: name = "action_" + name
//:: params += [(name, width)]
//:: #endfor
//:: return params
//:: #enddef
//::
//::
//:: from common import *

# Match structs

Expand Down
41 changes: 1 addition & 40 deletions p4c_bm/templates/inc/pd.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,46 +22,7 @@ limitations under the License.
#include <p4_sim/pd_static.h>

//:: p4_pd_prefix = "p4_pd_" + p4_prefix + "_"

//:: def get_type(byte_width):
//:: if byte_width == 1:
//:: return "uint8_t"
//:: elif byte_width == 2:
//:: return "uint16_t"
//:: elif byte_width <= 4:
//:: return "uint32_t"
//:: else:
//:: return "uint8_t *"
//:: #endif
//:: #enddef
//::
//:: # match_fields is list of tuples (name, type)
//:: def gen_match_params(match_fields, field_info):
//:: params = []
//:: for field, type in match_fields:
//:: if type == "valid":
//:: params += [(field + "_valid", 1)]
//:: continue
//:: #endif
//:: f_info = field_info[field]
//:: bytes_needed = (f_info["bit_width"] + 7 ) / 8
//:: params += [(field, bytes_needed)]
//:: if type == "lpm": params += [(field + "_prefix_length", 2)]
//:: if type == "ternary": params += [(field + "_mask", bytes_needed)]
//:: #endfor
//:: return params
//:: #enddef
//::
//:: def gen_action_params(names, byte_widths, _get_type = get_type):
//:: params = []
//:: for name, width in zip(names, byte_widths):
//:: name = "action_" + name
//:: params += [(name, width)]
//:: #endfor
//:: return params
//:: #enddef
//::
//::
//:: from common import *

/* MATCH STRUCTS */

Expand Down
38 changes: 1 addition & 37 deletions p4c_bm/templates/src/p4_pd_rpc_server.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -33,43 +33,7 @@ public:
//:: #endfor
}

//:: def get_type(byte_width):
//:: if byte_width == 1:
//:: return "const int8_t"
//:: elif byte_width == 2:
//:: return "const int16_t"
//:: elif byte_width <= 4:
//:: return "const int32_t"
//:: else:
//:: return "const std::string&"
//:: #endif
//:: #enddef
//::
//:: # match_fields is list of tuples (name, type)
//:: def gen_match_params(match_fields, field_info):
//:: params = []
//:: for field, type in match_fields:
//:: if type == "valid":
//:: params += [(field + "_valid", 1)]
//:: continue
//:: #endif
//:: f_info = field_info[field]
//:: bytes_needed = (f_info["bit_width"] + 7 ) / 8
//:: params += [(field, bytes_needed)]
//:: if type == "lpm": params += [(field + "_prefix_length", 2)]
//:: if type == "ternary": params += [(field + "_mask", bytes_needed)]
//:: #endfor
//:: return params
//:: #enddef
//::
//:: def gen_action_params(names, byte_widths, _get_type = get_type):
//:: params = []
//:: for name, width in zip(names, byte_widths):
//:: name = "action_" + name
//:: params += [(name, width)]
//:: #endfor
//:: return params
//:: #enddef
//:: from common import *
//::
//:: def gen_pd_args(params):
//:: # Need to coerce strings to appropriate type
Expand Down
41 changes: 1 addition & 40 deletions p4c_bm/templates/src/pd.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,6 @@ limitations under the License.

//:: p4_pd_prefix = "p4_pd_" + p4_prefix + "_"
//::
//:: def get_type(byte_width):
//:: if byte_width == 1:
//:: return "uint8_t"
//:: elif byte_width == 2:
//:: return "uint16_t"
//:: elif byte_width <= 4:
//:: return "uint32_t"
//:: else:
//:: return "uint8_t *"
//:: #endif
//:: #enddef
//::
//:: def get_num_match_bits(match_fields, field_info):
//:: num_bits = 0
//:: for field, type in match_fields:
Expand All @@ -59,34 +47,7 @@ limitations under the License.
//:: return num_bits
//:: #enddef
//::
//::
//:: # match_fields is list of tuples (name, type)
//:: def gen_match_params(match_fields, field_info):
//:: params = []
//:: for field, type in match_fields:
//:: if type == "valid":
//:: params += [(field + "_valid", 1)]
//:: continue
//:: #endif
//:: f_info = field_info[field]
//:: bytes_needed = (f_info["bit_width"] + 7 ) / 8
//:: params += [(field, bytes_needed)]
//:: if type == "lpm": params += [(field + "_prefix_length", 2)]
//:: if type == "ternary": params += [(field + "_mask", bytes_needed)]
//:: #endfor
//:: return params
//:: #enddef
//::
//:: def gen_action_params(names, byte_widths):
//:: params = []
//:: for name, width in zip(names, byte_widths):
//:: name = "action_" + name
//:: params += [(name, width)]
//:: #endfor
//:: return params
//:: #enddef
//::
//::
//:: from common import *

//:: for table, t_info in table_info.items():
//:: if not t_info["match_fields"]: continue
Expand Down