Skip to content

Commit

Permalink
fixes previous commit
Browse files Browse the repository at this point in the history
  • Loading branch information
mgheorghe committed Apr 23, 2024
1 parent d5e86d9 commit 374982a
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 23 deletions.
56 changes: 46 additions & 10 deletions dpugen/sai.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/usr/bin/python3
"""Entry point to generate a DPU Hero test config in SAI format."""

import copy
import ipaddress
import multiprocessing
import sys

import dpugen.saigen.acl_group
Expand All @@ -15,12 +17,14 @@
import dpugen.saigen.vips
import dpugen.saigen.vnets

from .confbase import ConfBase
from .confbase import (
ConfBase,
maca
)
from .confutils import (
common_arg_parser,
common_output,
common_parse_args,
write_list_file_iterator
common_parse_args
)


Expand All @@ -29,8 +33,8 @@ class SaiConfig(ConfBase):
def __init__(self, params={}):
super().__init__(params)


def generate(self):
# Pass top-level params to sub-generators.
self.configs = [
dpugen.saigen.vips.Vips(self.params_dict),
dpugen.saigen.direction_lookup.DirectionLookup(self.params_dict),
Expand All @@ -51,8 +55,12 @@ def items(self):
result.extend(c.items())
return result

def write_to_file(self, fformat, outfile):
write_list_file_iterator(self.items(), fformat, outfile)
def create_asic_config(dpu_conf, dpu_params, dpu_id):
common_parse_args(dpu_conf)
dpu_conf.merge_params(dpu_params)
dpu_conf.generate()
common_output(dpu_conf, dpu_id)



if __name__ == '__main__':
Expand All @@ -62,7 +70,35 @@ def write_to_file(self, fformat, outfile):
args = parser.parse_args()

conf = SaiConfig()
common_parse_args(conf)
conf.generate()
common_output(conf)

threads = []
DPUS = conf.params_dict['DPUS']

ENI_COUNT = conf.params_dict['ENI_COUNT'] // DPUS

for dpu_id in range(DPUS):
print('dpu %d' % dpu_id)

dpu_conf = copy.deepcopy(conf)
dpu_params = {}

dpu_params['ENI_COUNT'] = ENI_COUNT
dpu_params['ENI_START'] = conf.params_dict['ENI_START'] + dpu_id * ENI_COUNT * conf.params_dict['ENI_STEP']
dpu_params['LOOPBACK'] = str(ipaddress.ip_address(conf.params_dict['LOOPBACK']) + dpu_id * int(ipaddress.ip_address(conf.params_dict['IP_STEP1'])))
dpu_params['PAL'] = str(ipaddress.ip_address(conf.params_dict['PAL']) + dpu_id * ENI_COUNT * int(ipaddress.ip_address(conf.params_dict['IP_STEP1'])))
dpu_params['PAR'] = str(ipaddress.ip_address(conf.params_dict['PAR']) + dpu_id * ENI_COUNT * int(ipaddress.ip_address(conf.params_dict['IP_STEP1'])))
dpu_params['GATEWAY'] = str(ipaddress.ip_address(conf.params_dict['GATEWAY']) + dpu_id * ENI_COUNT * int(ipaddress.ip_address(conf.params_dict['IP_STEP1'])))
dpu_params['IP_L_START'] = str(ipaddress.ip_address(conf.params_dict['IP_L_START']) + dpu_id * ENI_COUNT * int(ipaddress.ip_address(conf.params_dict['IP_STEP_ENI'])))
dpu_params['IP_R_START'] = str(ipaddress.ip_address(conf.params_dict['IP_R_START']) + dpu_id * ENI_COUNT * int(ipaddress.ip_address(conf.params_dict['IP_STEP_ENI'])))
dpu_params['MAC_L_START'] = str(maca(int(maca(conf.params_dict['MAC_L_START'])) + dpu_id * ENI_COUNT * int(maca(conf.params_dict['MAC_STEP_ENI']))))
dpu_params['MAC_R_START'] = str(maca(int(maca(conf.params_dict['MAC_R_START'])) + dpu_id * ENI_COUNT * int(maca(conf.params_dict['MAC_STEP_ENI']))))

dpu_params['TOTAL_OUTBOUND_ROUTES'] = conf.params_dict['TOTAL_OUTBOUND_ROUTES'] // DPUS

threads.append(multiprocessing.Process(target=create_asic_config, args=(dpu_conf, dpu_params, 'dpu%d' % dpu_id)))
for p in threads:
p.start()
for p in threads:
p.join()

print('done', file=sys.stderr)
8 changes: 2 additions & 6 deletions dpugen/saigen/address_maps.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,10 @@ def __init__(self, params={}):
def items(self):
print(' Generating %s ...' % os.path.basename(__file__), file=sys.stderr)
p = self.params
ip_int = self.cooked_params

for eni_index, eni in enumerate(range(p.ENI_START, p.ENI_START + p.ENI_COUNT * p.ENI_STEP, p.ENI_STEP)):

eni_mac = str(
maca(
int(maca(p.MAC_L_START)) + eni_index * int(maca(p.ENI_MAC_STEP))
)
).replace('-', ':')
eni_mac = str(maca(ip_int.MAC_L_START + eni_index * ip_int.MAC_STEP_ENI))

self.num_yields += 1
yield {
Expand Down
1 change: 1 addition & 0 deletions dpugen/saigen/inbound_routing.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ def __init__(self, params={}):
def items(self):
print(' Generating %s ...' % os.path.basename(__file__), file=sys.stderr)
p = self.params
ip_int = self.cooked_params

for eni_index, eni in enumerate(range(p.ENI_START, p.ENI_START + p.ENI_COUNT * p.ENI_STEP, p.ENI_STEP)): # Per ENI
remote_ip = socket_inet_ntoa(struct_pack('>L', ip_int.IP_R_START + ip_int.IP_STEP_ENI * eni_index))
Expand Down
14 changes: 7 additions & 7 deletions dpugen/saigen/outbound_routing.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ def items(self):
raise Exception('ACL_MAPPED_PER_NSG <%d> cannot be < 0' % p.ACL_MAPPED_PER_NSG)

added_route_count = 0
for table_index in range(p.ACL_NSG_COUNT * 2): # Per outbound group (5)
IP_R_START_nsg = IP_R_START_eni + ip_int.IP_STEP_NSG * table_index
for nsg_index in range(p.ACL_NSG_COUNT * 2): # Per outbound group (5)
IP_R_START_nsg = IP_R_START_eni + ip_int.IP_STEP_NSG * nsg_index
for acl_index in range(0, p.ACL_RULES_NSG, 2): # Per even rule (1000 / 2)

IP_RANGE_START = IP_R_START_nsg + p.IP_PER_ACL_RULE * acl_index - 1
Expand All @@ -112,14 +112,14 @@ def items(self):
routes = self.make_more_routes(routes, OUTBOUND_ROUTES_PER_ACL * 2)
routes = self.make_more_routes(routes, OUTBOUND_ROUTES_PER_ACL * 2)

for route in routes:
for route_index, route in enumerate(routes):
ip = socket_inet_ntoa(struct_pack('>L', route['ip']))
if acl_index < p.ACL_MAPPED_PER_NSG:

# routes that have a mac mapping
self.num_yields += 1
yield {
'name': f'outbound_routing_#eni{eni}nsg{nsg_index}acl{acl_index}ip{ip_index}p{prefix_index}',
'name': f'outbound_routing_#eni{eni}nsg{nsg_index}acl{acl_index}ri{route_index}',
'op': 'create',
'type': 'SAI_OBJECT_TYPE_OUTBOUND_ROUTING_ENTRY',
'key': {
Expand All @@ -136,7 +136,7 @@ def items(self):
# routes that do not have a mac mapping
self.num_yields += 1
yield {
'name': f'outbound_routing_#eni{eni}nsg{nsg_index}acl{acl_index}ip{ip_index}p{prefix_index}',
'name': f'outbound_routing_#eni{eni}nsg{nsg_index}acl{acl_index}ri{route_index}',
'op': 'create',
'type': 'SAI_OBJECT_TYPE_OUTBOUND_ROUTING_ENTRY',
'key': {
Expand All @@ -158,7 +158,7 @@ def items(self):
if p.MAPPED_ACL_PER_NSG > 0:
self.num_yields += 1
yield {
'name': f'outbound_routing_#eni{eni}',
'name': f'outbound_routing_#eni{eni}mapped',
'op': 'create',
'type': 'SAI_OBJECT_TYPE_OUTBOUND_ROUTING_ENTRY',
'key': {
Expand All @@ -174,7 +174,7 @@ def items(self):
elif p.ACL_MAPPED_PER_NSG == 0:
self.num_yields += 1
yield {
'name': f'outbound_routing_#eni{eni}nsg{nsg_index}acl{acl_index}ip{ip_index}p{prefix_index}',
'name': f'outbound_routing_#eni{eni}routed',
'op': 'create',
'type': 'SAI_OBJECT_TYPE_OUTBOUND_ROUTING_ENTRY',
'key': {
Expand Down

0 comments on commit 374982a

Please sign in to comment.