Skip to content

Commit

Permalink
adds guid, route group id and few small fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
mgheorghe committed Jun 6, 2024
1 parent e2b5bc8 commit aca811d
Show file tree
Hide file tree
Showing 10 changed files with 91 additions and 18 deletions.
7 changes: 7 additions & 0 deletions dpugen/confutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@
# https://pythonspeed.com/articles/json-memory-streaming/


import uuid
import hashlib

def create_uuid_from_string(val: str):
hex_string = hashlib.md5(val.encode("UTF-8")).hexdigest()
return uuid.UUID(hex=hex_string)

def dumps_json(data, indent=2, depth=1):
assert depth > 0
space = ' ' * indent
Expand Down
13 changes: 6 additions & 7 deletions dpugen/dash.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def create_eni_config(dpu_conf, dpu_params, eni_id):
eni_id = dpu_id * ENI_COUNT + eni_index
eni_params['ENI_COUNT'] = 1
eni_params['ENI_START'] = dpu_params['ENI_START'] + eni_index * conf.params_dict['ENI_STEP']
eni_params['LOOPBACK'] = str(ipaddress.ip_address(conf.params_dict['LOOPBACK']) + (eni_id % DPUS) * int(ipaddress.ip_address(conf.params_dict['IP_STEP1'])))
eni_params['LOOPBACK'] = dpu_params['LOOPBACK']
eni_params['PAL'] = str(ipaddress.ip_address(dpu_params['PAL']) + eni_index * int(ipaddress.ip_address(conf.params_dict['IP_STEP1'])))
eni_params['PAR'] = str(ipaddress.ip_address(dpu_params['PAR']) + eni_index * int(ipaddress.ip_address(conf.params_dict['IP_STEP1'])))
eni_params['GATEWAY'] = str(ipaddress.ip_address(dpu_params['GATEWAY']) + eni_index * int(ipaddress.ip_address(conf.params_dict['IP_STEP1'])))
Expand All @@ -118,12 +118,11 @@ def create_eni_config(dpu_conf, dpu_params, eni_id):

eni_params['TOTAL_OUTBOUND_ROUTES'] = dpu_params['TOTAL_OUTBOUND_ROUTES'] // ENI_COUNT

threads.append(multiprocessing.Process(target=create_eni_config, args=(eni_conf, eni_params, 'dpu%d.eni%03d' % ((eni_id % DPUS), eni_id))))
threads.append(multiprocessing.Process(target=create_eni_config, args=(eni_conf, eni_params, 'dpu%d.eni%03d' % (dpu_id, eni_id))))

for p in threads:
p.start()

for p in threads:
p.join()
for p in threads:
p.start()
for p in threads:
p.join()

print('done', file=sys.stderr)
3 changes: 3 additions & 0 deletions dpugen/dashgen/acl_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

from dpugen.confbase import ConfBase
from dpugen.confutils import common_main
from dpugen.confutils import create_uuid_from_string


class AclGroups(ConfBase):
Expand All @@ -27,6 +28,7 @@ def items(self):
yield {
'DASH_ACL_GROUP_TABLE:%d' % table_id: {
'ip_version': 'ipv4',
'guid': create_uuid_from_string('DASH_ACL_GROUP_TABLE:%d' % table_id)
},
'OP': 'SET'
}
Expand All @@ -38,6 +40,7 @@ def items(self):
yield {
'DASH_ACL_GROUP_TABLE:%d' % table_id: {
'ip_version': 'ipv4',
'guid': create_uuid_from_string('DASH_ACL_GROUP_TABLE:%d' % table_id)
},
'OP': 'SET'
}
Expand Down
12 changes: 12 additions & 0 deletions dpugen/dashgen/dash_eni_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,22 @@ def items(self):
'OP': 'SET'
}

self.num_yields += 1
yield {
'DASH_QOS_TABLE:qos-%d' % eni: {
'qos_id': 'qos-%d' % eni,
"bw": 0,
"cps": 0,
"flows": 0
},
'OP': 'SET'
}

self.num_yields += 1
yield {
'DASH_ENI_TABLE:eni-%d' % eni: {
'eni_id': 'eni-%d' % eni,
"qos": 'qos-%d' % eni,
'mac_address': local_mac,
'underlay_ip': vm_underlay_dip,
'admin_state': 'enabled',
Expand Down
2 changes: 2 additions & 0 deletions dpugen/dashgen/dash_vnet_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from dpugen.confbase import ConfBase
from dpugen.confutils import common_main
from dpugen.confutils import create_uuid_from_string


class Vnets(ConfBase):
Expand All @@ -23,6 +24,7 @@ def items(self):
yield {
'DASH_VNET_TABLE:vnet-%d' % r_vni_id: {
'vni': r_vni_id,
'guid': create_uuid_from_string('DASH_VNET_TABLE:vnet-%d' % r_vni_id)
},
'OP': 'SET'
}
Expand Down
8 changes: 4 additions & 4 deletions dpugen/dflt_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
'DC_STEP': '0.0.1.0', # '0.0.1.0'

'LOOPBACK': '221.0.0.1', # '221.0.0.1'
'PAL': '221.1.0.1', # '221.1.0.1'
'PAR': '221.2.0.1', # '221.2.0.1'
'PAL': '221.1.0.0', # '221.1.0.0'
'PAR': '221.2.0.0', # '221.2.0.0'
'GATEWAY': '222.0.0.1', # '222.0.0.1'

'DPUS': 8, # 1
'DPUS': 8, # 8

'ENI_START': 1, # 1
'ENI_COUNT': 256, # 32
'ENI_COUNT': 256, # 256
'ENI_STEP': 1, # 1
'ENI_L2R_STEP': 1000, # 1000

Expand Down
2 changes: 2 additions & 0 deletions dpugen/sai.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import dpugen.saigen.outbound_ca_to_pa
import dpugen.saigen.outbound_routing
import dpugen.saigen.pa_validation
import dpugen.saigen.routing_group
import dpugen.saigen.vips
import dpugen.saigen.vnets

Expand Down Expand Up @@ -41,6 +42,7 @@ def generate(self):
dpugen.saigen.vnets.Vnets(self.params_dict),
dpugen.saigen.acl_group.AclGroups(self.params_dict),
dpugen.saigen.acl_rule.AclRules(self.params_dict),
dpugen.saigen.routing_group.RoutingGroup(self.params_dict),
dpugen.saigen.enis.Enis(self.params_dict),
dpugen.saigen.address_maps.Mappings(self.params_dict),
dpugen.saigen.inbound_routing.InboundRouting(self.params_dict),
Expand Down
10 changes: 7 additions & 3 deletions dpugen/saigen/enis.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,15 @@ def items(self):
'op': 'create',
'type': 'SAI_OBJECT_TYPE_ENI',
'attributes': [
'SAI_ENI_ATTR_CPS', '10000',
'SAI_ENI_ATTR_PPS', '100000',
'SAI_ENI_ATTR_FLOWS', '100000',
'SAI_ENI_ATTR_CPS', '0',
'SAI_ENI_ATTR_PPS', '0',
'SAI_ENI_ATTR_FLOWS', '0',
'SAI_ENI_ATTR_ADMIN_STATE', 'True',
"SAI_ENI_ATTR_HA_SCOPE_ID", "0",
'SAI_ENI_ATTR_VM_UNDERLAY_DIP', vm_underlay_dip,
'SAI_ENI_ATTR_VM_VNI', f'{eni}',
'SAI_ENI_ATTR_VNET_ID', f'$vnet_#eni{eni}',
'SAI_ENI_ATTR_ROUTING_GROUP_ID', f'$routinggid_#{eni}',
'SAI_ENI_ATTR_INBOUND_V4_STAGE1_DASH_ACL_GROUP_ID', '0',
'SAI_ENI_ATTR_INBOUND_V4_STAGE2_DASH_ACL_GROUP_ID', '0',
'SAI_ENI_ATTR_INBOUND_V4_STAGE3_DASH_ACL_GROUP_ID', '0',
Expand All @@ -59,6 +61,8 @@ def items(self):
'SAI_ENI_ATTR_OUTBOUND_V6_STAGE3_DASH_ACL_GROUP_ID', '0',
'SAI_ENI_ATTR_OUTBOUND_V6_STAGE4_DASH_ACL_GROUP_ID', '0',
'SAI_ENI_ATTR_OUTBOUND_V6_STAGE5_DASH_ACL_GROUP_ID', '0',
"SAI_ENI_ATTR_V4_METER_POLICY_ID", "0",
"SAI_ENI_ATTR_V6_METER_POLICY_ID", "0",
]
}
for nsg_index in range(p.ACL_NSG_COUNT * 2):
Expand Down
8 changes: 4 additions & 4 deletions dpugen/saigen/outbound_routing.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def items(self):
'type': 'SAI_OBJECT_TYPE_OUTBOUND_ROUTING_ENTRY',
'key': {
'switch_id': '$SWITCH_ID',
'eni_id': f'$eni_#{eni}',
'routing_group_id': f'$routinggid_#{eni}',
'destination': f'{ip}/{route["mask"]}'
},
'attributes': [
Expand All @@ -141,7 +141,7 @@ def items(self):
'type': 'SAI_OBJECT_TYPE_OUTBOUND_ROUTING_ENTRY',
'key': {
'switch_id': '$SWITCH_ID',
'eni_id': f'$eni_#{eni}',
'routing_group_id': f'$routinggid_#{eni}',
'destination': f'{ip}/{route["mask"]}'
},
'attributes': [
Expand All @@ -163,7 +163,7 @@ def items(self):
'type': 'SAI_OBJECT_TYPE_OUTBOUND_ROUTING_ENTRY',
'key': {
'switch_id': '$SWITCH_ID',
'eni_id': f'$eni_#{eni}',
'routing_group_id': f'$routinggid_#{eni}',
'destination': f'{remote_ip_prefix}/10'
},
'attributes': [
Expand All @@ -179,7 +179,7 @@ def items(self):
'type': 'SAI_OBJECT_TYPE_OUTBOUND_ROUTING_ENTRY',
'key': {
'switch_id': '$SWITCH_ID',
'eni_id': f'$eni_#{eni}',
'routing_group_id': f'$routinggid_#{eni}',
'destination': f'{remote_ip_prefix}/10'
},
'attributes': [
Expand Down
44 changes: 44 additions & 0 deletions dpugen/saigen/routing_group.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/usr/bin/python3
"""SAI generator for ENI"""

import os
import sys

from dpugen.confbase import (
ConfBase,
maca,
socket_inet_ntoa,
struct_pack
)
from dpugen.confutils import common_main


class RoutingGroup(ConfBase):

def __init__(self, params={}):
super().__init__(params)
self.num_yields = 0

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

routing_group_data = {
'name': f'routinggid_#{eni}',
'op': 'create',
'type': 'SAI_OBJECT_TYPE_ROUTING_GROUP',
'attributes': [
'SAI_ROUTING_GROUP_ATTR_ADMIN_STATE', 'True',
]
}

self.num_yields += 1
yield routing_group_data


if __name__ == '__main__':
conf = RoutingGroup()
common_main(conf)

0 comments on commit aca811d

Please sign in to comment.