Commit 5f64f0ea authored by Shayan Hajipour's avatar Shayan Hajipour
Browse files

service_2_bwInfo function bug resolved: change in config rules applied in the function

parent f6afa0c7
Loading
Loading
Loading
Loading
+13 −8
Original line number Diff line number Diff line
@@ -31,7 +31,7 @@ LOGGER = logging.getLogger(__name__)
ENDPOINT_SETTINGS_KEY = '/device[{:s}]/endpoint[{:s}]/vlan[{:d}]/settings'
DEVICE_SETTINGS_KEY = '/device[{:s}]/settings'
RE_CONFIG_RULE_IF_SUBIF = re.compile(r'^\/interface\[([^\]]+)\]\/subinterface\[([^\]]+)\]$')
MEC_CONSIDERED_FIELDS = ['requestType', 'sessionFilter', 'fixedAllocation', 'allocationDirection']
MEC_CONSIDERED_FIELDS = ['requestType', 'sessionFilter', 'fixedAllocation', 'allocationDirection', 'fixedBWPriority']
ALLOCATION_DIRECTION_DESCRIPTIONS = {
    '00' : 'Downlink (towards the UE)',
    '01' : 'Uplink (towards the application/session)',
@@ -59,12 +59,19 @@ def service_2_bwInfo(service: Service) -> dict:
            break

    for config_rule in service.service_config.config_rules:
        resource_value_json = json.loads(config_rule.custom.resource_value)
        if config_rule.custom.resource_key != '/request':
            continue
        for key in ['allocationDirection', 'fixedBWPriority', 'requestType', 'sourceIp', 'sourcePort', 'dstPort', 'protocol', 'sessionFilter']:
            if config_rule.custom.resource_key == key:
                if key != 'sessionFilter':
                    response[key] = config_rule.custom.resource_value
            if key not in resource_value_json: 
                continue

            if key == 'sessionFilter':
                response[key] = [resource_value_json[key]]
            elif key == 'requestType':
                response[key] = str(resource_value_json[key])
            else:
                    response[key] = json.loads(config_rule.custom.resource_value)
                response[key] = resource_value_json[key]

    unixtime = time.time()
    response['timeStamp'] = { # Time stamp to indicate when the corresponding information elements are sent
@@ -76,8 +83,6 @@ def service_2_bwInfo(service: Service) -> dict:

def bwInfo_2_service(client, bw_info: dict) -> Service:
    # add description to allocationDirection code
    if ad_code := bw_info.get('allocationDirection'):
        bw_info['allocationDirection'] = {'code': ad_code, 'description': ALLOCATION_DIRECTION_DESCRIPTIONS[ad_code]}
    if 'sessionFilter' in bw_info:
        bw_info['sessionFilter'] = bw_info['sessionFilter'][0] # Discard other items in sessionFilter field