Commits (2)
...@@ -226,8 +226,11 @@ def edit_config( ...@@ -226,8 +226,11 @@ def edit_config(
chk_length(str_resource_name, resource, min_length=2, max_length=2) chk_length(str_resource_name, resource, min_length=2, max_length=2)
resource_key,resource_value = resource resource_key,resource_value = resource
chk_string(str_resource_name + '.key', resource_key, allow_empty=False) chk_string(str_resource_name + '.key', resource_key, allow_empty=False)
str_config_messages = compose_config( # get template for configuration str_config_messages = compose_config( # get template for configuration
resource_key, resource_value, delete=delete, vendor=netconf_handler.vendor, message_renderer=netconf_handler.message_renderer) resource_key, resource_value, delete=delete, vendor=netconf_handler.vendor, message_renderer='pyangbind')
# str_config_messages = compose_config( # get template for configuration
# resource_key, resource_value, delete=delete, vendor=netconf_handler.vendor, message_renderer=netconf_handler.message_renderer)
for str_config_message in str_config_messages: # configuration of the received templates for str_config_message in str_config_messages: # configuration of the received templates
if str_config_message is None: raise UnsupportedResourceKeyException(resource_key) if str_config_message is None: raise UnsupportedResourceKeyException(resource_key)
logger.debug('[{:s}] str_config_message[{:d}] = {:s}'.format( logger.debug('[{:s}] str_config_message[{:d}] = {:s}'.format(
......
...@@ -61,7 +61,8 @@ def generate_templates(resource_key: str, resource_value: str, delete: bool,vend ...@@ -61,7 +61,8 @@ def generate_templates(resource_key: str, resource_value: str, delete: bool,vend
elif "inter_instance_policies" in resource_key: elif "inter_instance_policies" in resource_key:
result_templates.append(associate_RP_to_NI(data)) result_templates.append(associate_RP_to_NI(data))
elif "protocols" in resource_key: elif "protocols" in resource_key:
if vendor == "ADVA": result_templates.append(add_protocol_NI(data, vendor, delete)) result_templates.append(add_protocol_NI(data, vendor, delete))
# if vendor == "ADVA": result_templates.append(add_protocol_NI(data, vendor, delete))
elif "table_connections" in resource_key: elif "table_connections" in resource_key:
result_templates.append(create_table_conns(data, delete)) result_templates.append(create_table_conns(data, delete))
elif "interface" in resource_key: elif "interface" in resource_key:
......
...@@ -116,6 +116,9 @@ def add_protocol_NI(parameters,vendor, DEL): ...@@ -116,6 +116,9 @@ def add_protocol_NI(parameters,vendor, DEL):
else: else:
with tag('network-instance'): with tag('network-instance'):
with tag('name'):text(parameters['name']) with tag('name'):text(parameters['name'])
with tag('config'):
with tag('name'): text(parameters['name'])
with tag('type', 'xmlns:oc-ni-types="http://openconfig.net/yang/network-instance-types"'): text('oc-ni-types:DEFAULT_INSTANCE')
with tag('protocols'): with tag('protocols'):
with tag('protocol'): with tag('protocol'):
with tag('identifier', 'xmlns:oc-pol-types="http://openconfig.net/yang/policy-types"'):text('oc-pol-types:',parameters['identifier']) with tag('identifier', 'xmlns:oc-pol-types="http://openconfig.net/yang/policy-types"'):text('oc-pol-types:',parameters['identifier'])
...@@ -123,14 +126,41 @@ def add_protocol_NI(parameters,vendor, DEL): ...@@ -123,14 +126,41 @@ def add_protocol_NI(parameters,vendor, DEL):
with tag('config'): with tag('config'):
with tag('identifier', 'xmlns:oc-pol-types="http://openconfig.net/yang/policy-types"'):text('oc-pol-types:',parameters['identifier']) with tag('identifier', 'xmlns:oc-pol-types="http://openconfig.net/yang/policy-types"'):text('oc-pol-types:',parameters['identifier'])
with tag('name') :text(parameters['protocol_name']) with tag('name') :text(parameters['protocol_name'])
with tag('enabled'): text('true')
if "BGP" in parameters['identifier']: if "BGP" in parameters['identifier']:
with tag('bgp'): with tag('bgp'):
with tag('global'): with tag('global'):
with tag('afi-safis'):
with tag('afi-safi'):
with tag('afi-safi-name', 'xmlns:oc-bgp-types="http://openconfig.net/yang/bgp-types"'): text('oc-bgp-types:IPV4_UNICAST')
with tag('config'):
with tag('afi-safi-name', 'xmlns:oc-bgp-types="http://openconfig.net/yang/bgp-types"'): text('oc-bgp-types:IPV4_UNICAST')
with tag('enabled'): text('true')
with tag('config'): with tag('config'):
with tag('as') :text(parameters['as']) with tag('as') :text(parameters['as'])
if "router-id" in parameters: with tag('peer-groups'):
with tag('router-id'):text(parameters['router-id']) with tag('peer-group'):
if vendor == "ADVA": with tag('peer-group-name'): text('IBGP')
with tag('config'):
with tag('peer-group-name'): text('IBGP')
with tag('peer-as'): text(parameters['protocol_name'])
with tag('afi-safis'):
with tag('afi-safi'):
with tag('afi-safi-name', 'xmlns:oc-bgp-types="http://openconfig.net/yang/bgp-types"'): text('oc-bgp-types:IPV4_UNICAST')
with tag('config'):
with tag('afi-safi-name', 'xmlns:oc-bgp-types="http://openconfig.net/yang/bgp-types"'): text('oc-bgp-types:IPV4_UNICAST')
with tag('enabled'): text('true')
if 'neighbors' in parameters:
with tag('neighbors'):
for neighbor in parameters['neighbors']:
with tag('neighbor'):
with tag('neighbor-address'): text(neighbor['ip_address'])
with tag('config'):
with tag('neighbor-address'): text(neighbor['ip_address'])
with tag('peer-group'): text('IBGP')
# if vendor == "ADVA":
if True:
with tag('tables'): with tag('tables'):
with tag('table'): with tag('table'):
with tag('protocol', 'xmlns:oc-pol-types="http://openconfig.net/yang/policy-types"'):text('oc-pol-types:',parameters['identifier']) with tag('protocol', 'xmlns:oc-pol-types="http://openconfig.net/yang/policy-types"'):text('oc-pol-types:',parameters['identifier'])
......
...@@ -13,7 +13,9 @@ ...@@ -13,7 +13,9 @@
# limitations under the License. # limitations under the License.
import copy, deepmerge, json, logging import copy, deepmerge, json, logging
from typing import Dict
from common.Constants import DEFAULT_CONTEXT_NAME from common.Constants import DEFAULT_CONTEXT_NAME
from werkzeug.exceptions import UnsupportedMediaType
from context.client.ContextClient import ContextClient from context.client.ContextClient import ContextClient
from flask_restful import Resource, request from flask_restful import Resource, request
from service.client.ServiceClient import ServiceClient from service.client.ServiceClient import ServiceClient
...@@ -37,15 +39,20 @@ class BwInfo(_Resource): ...@@ -37,15 +39,20 @@ class BwInfo(_Resource):
return bw_allocations return bw_allocations
def post(self): def post(self):
bwinfo = request.get_json() if not request.is_json:
service = bwInfo_2_service(self.client, bwinfo) raise UnsupportedMediaType('JSON payload is required')
request_data: Dict = request.get_json()
service = bwInfo_2_service(self.client, request_data)
stripped_service = copy.deepcopy(service) stripped_service = copy.deepcopy(service)
stripped_service.ClearField('service_endpoint_ids') stripped_service.ClearField('service_endpoint_ids')
stripped_service.ClearField('service_constraints') stripped_service.ClearField('service_constraints')
stripped_service.ClearField('service_config') stripped_service.ClearField('service_config')
response = format_grpc_to_json(self.service_client.CreateService(stripped_service)) try:
response = format_grpc_to_json(self.service_client.UpdateService(service)) response = format_grpc_to_json(self.service_client.CreateService(stripped_service))
response = format_grpc_to_json(self.service_client.UpdateService(service))
except Exception as e: # pylint: disable=broad-except
return e
return response return response
......
...@@ -19,20 +19,30 @@ import time ...@@ -19,20 +19,30 @@ import time
from decimal import ROUND_HALF_EVEN, Decimal from decimal import ROUND_HALF_EVEN, Decimal
from flask.json import jsonify from flask.json import jsonify
from common.proto.context_pb2 import ( from common.proto.context_pb2 import (
ContextId, Empty, EndPointId, ServiceId, ServiceTypeEnum, Service, Constraint, Constraint_SLA_Capacity, ContextId, Empty, EndPointId, ServiceId, ServiceTypeEnum, Service, ServiceStatusEnum, Constraint, Constraint_SLA_Capacity,
ConfigRule, ConfigRule_Custom, ConfigActionEnum) ConfigRule, ConfigRule_Custom, ConfigActionEnum)
from common.tools.grpc.Tools import grpc_message_to_json from common.tools.grpc.Tools import grpc_message_to_json
from common.tools.grpc.ConfigRules import update_config_rule_custom
from common.tools.object_factory.Context import json_context_id from common.tools.object_factory.Context import json_context_id
from common.tools.object_factory.Service import json_service_id from common.tools.object_factory.Service import json_service_id
LOGGER = logging.getLogger(__name__) LOGGER = logging.getLogger(__name__)
ENDPOINT_SETTINGS_KEY = '/device[{:s}]/endpoint[{:s}]/vlan[{:d}]/settings'
RE_CONFIG_RULE_IF_SUBIF = re.compile(r'^\/interface\[([^\]]+)\]\/subinterface\[([^\]]+)\]$') RE_CONFIG_RULE_IF_SUBIF = re.compile(r'^\/interface\[([^\]]+)\]\/subinterface\[([^\]]+)\]$')
RE_CONFIG_RULE_ADDRESS_IP = re.compile(r'\\\"address_ip\\\": \\\"((?:[0-9]{1,3}\.){3}[0-9]{1,3})\\\"') MEC_CONSIDERED_FIELDS = ['requestType', 'sessionFilter', 'fixedAllocation', 'allocationDirection']
ALLOCATION_DIRECTION_DESCRIPTIONS = {
'00' : 'Downlink (towards the UE)',
'01' : 'Uplink (towards the application/session)',
'10' : 'Symmetrical'}
VLAN_TAG = 0
PREFIX_LENGTH = 24
BGP_AS = 65000
policy_AZ = 'srv_{:d}_a'.format(VLAN_TAG)
policy_ZA = 'srv_{:d}_b'.format(VLAN_TAG)
def service_2_bwInfo(service: Service) -> dict: def service_2_bwInfo(service: Service) -> dict:
response = {} response = {}
# allocationDirection = '??' # String: 00 = Downlink (towards the UE); 01 = Uplink (towards the application/session); 10 = Symmetrical
response['appInsId'] = service.service_id.service_uuid.uuid # String: Application instance identifier response['appInsId'] = service.service_id.service_uuid.uuid # String: Application instance identifier
for constraint in service.service_constraints: for constraint in service.service_constraints:
if constraint.WhichOneof('constraint') == 'sla_capacity': if constraint.WhichOneof('constraint') == 'sla_capacity':
...@@ -58,50 +68,109 @@ def service_2_bwInfo(service: Service) -> dict: ...@@ -58,50 +68,109 @@ def service_2_bwInfo(service: Service) -> dict:
return response return response
def bwInfo_2_service(client, bwInfo: dict) -> Service: 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
service = Service() service = Service()
for key in ['allocationDirection', 'fixedBWPriority', 'requestType', 'timeStamp', 'sessionFilter']:
if key not in bwInfo: service_config_rules = service.service_config.config_rules
continue
config_rule = ConfigRule() route_distinguisher = '{:5d}:{:03d}'.format(BGP_AS, VLAN_TAG)
config_rule.action = ConfigActionEnum.CONFIGACTION_SET settings_cr_key = '/settings'
config_rule_custom = ConfigRule_Custom() settings_cr_value = {'bgp_as':(BGP_AS, True), 'route_distinguisher': (route_distinguisher, True)}
config_rule_custom.resource_key = key update_config_rule_custom(service_config_rules, settings_cr_key, settings_cr_value)
if key != 'sessionFilter':
config_rule_custom.resource_value = str(bwInfo[key]) request_cr_key = '/request'
else: request_cr_value = {k:bw_info[k] for k in MEC_CONSIDERED_FIELDS}
config_rule_custom.resource_value = json.dumps(bwInfo[key])
config_rule.custom.CopyFrom(config_rule_custom) config_rule = ConfigRule()
service.service_config.config_rules.append(config_rule) config_rule.action = ConfigActionEnum.CONFIGACTION_SET
config_rule_custom = ConfigRule_Custom()
if 'sessionFilter' in bwInfo: config_rule_custom.resource_key = request_cr_key
a_ip = bwInfo['sessionFilter'][0]['sourceIp'] config_rule_custom.resource_value = json.dumps(request_cr_value)
z_ip = bwInfo['sessionFilter'][0]['dstAddress'] config_rule.custom.CopyFrom(config_rule_custom)
service_config_rules.append(config_rule)
if 'sessionFilter' in bw_info:
a_ip = bw_info['sessionFilter']['sourceIp']
z_ip = bw_info['sessionFilter']['dstAddress']
devices = client.ListDevices(Empty()).devices devices = client.ListDevices(Empty()).devices
router_id_counter = 1
for device in devices: for device in devices:
device_endpoint_uuids = {ep.name:ep.endpoint_id.endpoint_uuid for ep in device.device_endpoints}
device_endpoint_uuids = {ep.name:ep.endpoint_id.endpoint_uuid.uuid for ep in device.device_endpoints}
for cr in device.device_config.config_rules: for cr in device.device_config.config_rules:
if cr.WhichOneof('config_rule') == 'custom': if cr.WhichOneof('config_rule') != 'custom':
match_subif = RE_CONFIG_RULE_IF_SUBIF.match(cr.custom.resource_key) continue
match_ip = RE_CONFIG_RULE_ADDRESS_IP.match(cr.custom.resource_value) match_subif = RE_CONFIG_RULE_IF_SUBIF.match(cr.custom.resource_key)
if match_subif and match_ip and match_ip.groups(0)[0] in [a_ip, z_ip]: if not match_subif:
# `PORT-` added as prefix continue
port_name = 'PORT-' + match_subif.groups(0)[0] address_ip = json.loads(cr.custom.resource_value).get('address_ip')
ep_id = EndPointId() if address_ip not in [a_ip, z_ip]:
ep_id.endpoint_uuid.uuid = device_endpoint_uuids[port_name] continue
ep_id.device_id.device_uuid.uuid = device.device_id.device_uuid.uuid port_name = 'PORT-' + match_subif.groups(0)[0] # `PORT-` added as prefix
service.service_endpoint_ids.append(ep_id) ep_id = EndPointId()
ep_id.endpoint_uuid.uuid = device_endpoint_uuids[port_name]
ep_id.device_id.device_uuid.uuid = device.device_id.device_uuid.uuid
service.service_endpoint_ids.append(ep_id)
# add interface config rules
endpoint_settings_key = ENDPOINT_SETTINGS_KEY.format(device.name, port_name, VLAN_TAG)
if address_ip == a_ip:
field_updates = {
'address_ip': (address_ip, True),
# 'router_id': ('.'.join([str(router_id_counter)]*4), True),
'router_id': ('200.1.1.1', True),
'neighbor_address_ip': ('192.168.150.2', True),
'route_distinguisher': (route_distinguisher, True),
'sub_interface_index': (0, True),
'vlan_id' : (VLAN_TAG, True),
# 'bgp_as': (BGP_AS+router_id_counter, True),
'bgp_as': (BGP_AS, True),
'ip_address': (address_ip, True),
'prefix_length': (PREFIX_LENGTH, True),
'policy_AZ' : (policy_AZ, True),
'policy_ZA' : (policy_ZA, True),
'address_prefix' : (PREFIX_LENGTH, True),
}
elif address_ip == z_ip:
field_updates = {
'address_ip': (address_ip, True),
# 'router_id': ('.'.join([str(router_id_counter)]*4), True),
'router_id': ('200.1.1.2', True),
'neighbor_address_ip': ('192.168.150.1', True),
'route_distinguisher': (route_distinguisher, True),
'sub_interface_index': (0, True),
'vlan_id' : (VLAN_TAG, True),
# 'bgp_as': (BGP_AS+router_id_counter, True),
'bgp_as': (BGP_AS, True),
'ip_address': (address_ip, True),
'prefix_length': (PREFIX_LENGTH, True),
'policy_AZ' : (policy_ZA, True),
'policy_ZA' : (policy_AZ, True),
'address_prefix' : (PREFIX_LENGTH, True),
}
router_id_counter += 1
LOGGER.debug(f'BEFORE UPDATE -> device.device_config.config_rules: {service_config_rules}')
update_config_rule_custom(service_config_rules, endpoint_settings_key, field_updates)
LOGGER.debug(f'AFTER UPDATE -> device.device_config.config_rules: {service_config_rules}')
service.service_status.service_status = ServiceStatusEnum.SERVICESTATUS_PLANNED
service.service_type = ServiceTypeEnum.SERVICETYPE_L3NM service.service_type = ServiceTypeEnum.SERVICETYPE_L3NM
if 'appInsId' in bwInfo: if 'appInsId' in bw_info:
service.service_id.service_uuid.uuid = bwInfo['appInsId'] service.service_id.service_uuid.uuid = bw_info['appInsId']
service.service_id.context_id.context_uuid.uuid = 'admin' service.service_id.context_id.context_uuid.uuid = 'admin'
service.name = bwInfo['appInsId'] service.name = bw_info['appInsId']
if 'fixedAllocation' in bwInfo: if 'fixedAllocation' in bw_info:
capacity = Constraint_SLA_Capacity() capacity = Constraint_SLA_Capacity()
capacity.capacity_gbps = float(bwInfo['fixedAllocation']) / 1.e9 capacity.capacity_gbps = float(bw_info['fixedAllocation']) / 1.e9
constraint = Constraint() constraint = Constraint()
constraint.sla_capacity.CopyFrom(capacity) constraint.sla_capacity.CopyFrom(capacity)
service.service_constraints.append(constraint) service.service_constraints.append(constraint)
......
...@@ -24,6 +24,7 @@ SETTINGS_RULE_NAME = '/settings' ...@@ -24,6 +24,7 @@ SETTINGS_RULE_NAME = '/settings'
DEVICE_SETTINGS = re.compile(r'\/device\[([^\]]+)\]\/settings') DEVICE_SETTINGS = re.compile(r'\/device\[([^\]]+)\]\/settings')
ENDPOINT_SETTINGS = re.compile(r'\/device\[([^\]]+)\]\/endpoint\[([^\]]+)\]\/settings') ENDPOINT_SETTINGS = re.compile(r'\/device\[([^\]]+)\]\/endpoint\[([^\]]+)\]\/settings')
RE_ENDPOINT_VLAN_SETTINGS = re.compile(r'\/device\[([^\]]+)\]\/endpoint\[([^\]]+)\]\/vlan\[([^\]]+)\]\/settings')
L2NM_SETTINGS_FIELD_DEFAULTS = { L2NM_SETTINGS_FIELD_DEFAULTS = {
'encapsulation_type': 'dot1q', 'encapsulation_type': 'dot1q',
...@@ -150,6 +151,23 @@ def compose_device_config_rules( ...@@ -150,6 +151,23 @@ def compose_device_config_rules(
device_endpoint_keys = set(itertools.product(device_keys, endpoint_keys)) device_endpoint_keys = set(itertools.product(device_keys, endpoint_keys))
if len(device_endpoint_keys.intersection(endpoints_traversed)) == 0: continue if len(device_endpoint_keys.intersection(endpoints_traversed)) == 0: continue
subservice_config_rules.append(config_rule) subservice_config_rules.append(config_rule)
match = RE_ENDPOINT_VLAN_SETTINGS.match(config_rule.custom.resource_key)
if match is not None:
device_uuid_or_name = match.group(1)
device_name_or_uuid = device_name_mapping[device_uuid_or_name]
device_keys = {device_uuid_or_name, device_name_or_uuid}
endpoint_uuid_or_name = match.group(2)
endpoint_name_or_uuid_1 = endpoint_name_mapping[(device_uuid_or_name, endpoint_uuid_or_name)]
endpoint_name_or_uuid_2 = endpoint_name_mapping[(device_name_or_uuid, endpoint_uuid_or_name)]
endpoint_keys = {endpoint_uuid_or_name, endpoint_name_or_uuid_1, endpoint_name_or_uuid_2}
device_endpoint_keys = set(itertools.product(device_keys, endpoint_keys))
if len(device_endpoint_keys.intersection(endpoints_traversed)) == 0: continue
# ! check later: vlan removed from config_rule
config_rule.custom.resource_key = re.sub('\/vlan\[[^\]]+\]', '', config_rule.custom.resource_key)
subservice_config_rules.append(config_rule)
else: else:
continue continue
......
...@@ -37,6 +37,7 @@ def setup_config_rules( ...@@ -37,6 +37,7 @@ def setup_config_rules(
vlan_id = json_endpoint_settings.get('vlan_id', 1 ) # 400 vlan_id = json_endpoint_settings.get('vlan_id', 1 ) # 400
address_ip = json_endpoint_settings.get('address_ip', '0.0.0.0') # '2.2.2.1' address_ip = json_endpoint_settings.get('address_ip', '0.0.0.0') # '2.2.2.1'
address_prefix = json_endpoint_settings.get('address_prefix', 24 ) # 30 address_prefix = json_endpoint_settings.get('address_prefix', 24 ) # 30
neighbor_address_ip = json_endpoint_settings.get('neighbor_address_ip', '0.0.0.0') # '2.2.2.1'
policy_import = json_endpoint_settings.get('policy_AZ', '2' ) # 2 policy_import = json_endpoint_settings.get('policy_AZ', '2' ) # 2
policy_export = json_endpoint_settings.get('policy_ZA', '7' ) # 30 policy_export = json_endpoint_settings.get('policy_ZA', '7' ) # 30
...@@ -46,18 +47,21 @@ def setup_config_rules( ...@@ -46,18 +47,21 @@ def setup_config_rules(
network_subinterface_desc = json_endpoint_settings.get('subif_description','') network_subinterface_desc = json_endpoint_settings.get('subif_description','')
#service_short_uuid = service_uuid.split('-')[-1] #service_short_uuid = service_uuid.split('-')[-1]
#network_instance_name = '{:s}-NetInst'.format(service_short_uuid) #network_instance_name = '{:s}-NetInst'.format(service_short_uuid)
network_instance_name = json_endpoint_settings.get('ni_name', service_uuid.split('-')[-1]) #ELAN-AC:1 # network_instance_name = json_endpoint_settings.get('ni_name', service_uuid.split('-')[-1]) #ELAN-AC:1
network_instance_name = 'default'
if_subif_name = '{:s}.{:d}'.format(endpoint_name, vlan_id) '''
# if_subif_name = '{:s}.{:d}'.format(endpoint_name, vlan_id)
if_subif_name = '{:s}'.format(endpoint_name[5:])
json_config_rules = [ json_config_rules = [
# Configure Interface (not used) # # Configure Interface (not used)
#json_config_rule_set( # json_config_rule_set(
# '/interface[{:s}]'.format(endpoint_name), { # '/interface[{:s}]'.format(endpoint_name), {
# 'name': endpoint_name, # 'name': endpoint_name,
# 'description': network_interface_desc, # 'description': network_interface_desc,
# 'mtu': mtu, # 'mtu': mtu,
#}), # }),
#Create network instance #Create network instance
json_config_rule_set( json_config_rule_set(
...@@ -74,8 +78,10 @@ def setup_config_rules( ...@@ -74,8 +78,10 @@ def setup_config_rules(
json_config_rule_set( json_config_rule_set(
'/network_instance[{:s}]/protocols[BGP]'.format(network_instance_name), { '/network_instance[{:s}]/protocols[BGP]'.format(network_instance_name), {
'name': network_instance_name, 'name': network_instance_name,
'protocol_name': 'BGP', # 'protocol_name': 'BGP',
'protocol_name': bgp_as,
'identifier': 'BGP', 'identifier': 'BGP',
# 'identifier': bgp_as,
'as': bgp_as, 'as': bgp_as,
'router_id': router_id, 'router_id': router_id,
}), }),
...@@ -101,7 +107,8 @@ def setup_config_rules( ...@@ -101,7 +107,8 @@ def setup_config_rules(
json_config_rule_set( json_config_rule_set(
'/interface[{:s}]/subinterface[{:d}]'.format(if_subif_name, sub_interface_index), { '/interface[{:s}]/subinterface[{:d}]'.format(if_subif_name, sub_interface_index), {
'name' : if_subif_name, 'name' : if_subif_name,
'type' :'l3ipvlan', # 'type' :'l3ipvlan',
'type' :'ethernetCsmacd',
'mtu' : mtu, 'mtu' : mtu,
'index' : sub_interface_index, 'index' : sub_interface_index,
'description' : network_subinterface_desc, 'description' : network_subinterface_desc,
...@@ -183,6 +190,40 @@ def setup_config_rules( ...@@ -183,6 +190,40 @@ def setup_config_rules(
}), }),
] ]
'''
if_subif_name = '{:s}'.format(endpoint_name[5:])
json_config_rules = [
#Add DIRECTLY CONNECTED protocol to network instance
json_config_rule_set(
'/network_instance[{:s}]/protocols[DIRECTLY_CONNECTED]'.format(network_instance_name), {
'name': network_instance_name,
'identifier': 'DIRECTLY_CONNECTED',
'protocol_name': 'DIRECTLY_CONNECTED',
}),
# Add BGP neighbors
json_config_rule_set(
'/network_instance[{:s}]/protocols[BGP]'.format(network_instance_name), {
'name': network_instance_name,
'protocol_name': bgp_as,
'identifier': 'BGP',
'as': bgp_as,
'router_id': router_id,
'neighbors': [{'ip_address': neighbor_address_ip, 'remote_as': bgp_as}]
}),
json_config_rule_set(
'/network_instance[{:s}]/table_connections[DIRECTLY_CONNECTED][BGP][IPV4]'.format(network_instance_name), {
'name' : network_instance_name,
'src_protocol' : 'DIRECTLY_CONNECTED',
'dst_protocol' : 'BGP',
'address_family' : 'IPV4',
'default_import_policy': 'ACCEPT_ROUTE',
}),
]
for res_key, res_value in endpoint_acls: for res_key, res_value in endpoint_acls:
json_config_rules.append( json_config_rules.append(
{'action': 1, 'acl': res_value} {'action': 1, 'acl': res_value}
...@@ -201,7 +242,8 @@ def teardown_config_rules( ...@@ -201,7 +242,8 @@ def teardown_config_rules(
json_endpoint_settings : Dict = endpoint_settings.value json_endpoint_settings : Dict = endpoint_settings.value
service_short_uuid = service_uuid.split('-')[-1] service_short_uuid = service_uuid.split('-')[-1]
network_instance_name = '{:s}-NetInst'.format(service_short_uuid) # network_instance_name = '{:s}-NetInst'.format(service_short_uuid)
network_instance_name = json_endpoint_settings.get('ni_name', service_short_uuid) #ELAN-AC:1
#network_interface_desc = '{:s}-NetIf'.format(service_uuid) #network_interface_desc = '{:s}-NetIf'.format(service_uuid)
#network_subinterface_desc = '{:s}-NetSubIf'.format(service_uuid) #network_subinterface_desc = '{:s}-NetSubIf'.format(service_uuid)
...@@ -262,10 +304,10 @@ def teardown_config_rules( ...@@ -262,10 +304,10 @@ def teardown_config_rules(
#Delete interface; automatically deletes: #Delete interface; automatically deletes:
# - /interface[]/subinterface[] # - /interface[]/subinterface[]
json_config_rule_delete('/interface[{:s}]/subinterface[0]'.format(if_subif_name), # json_config_rule_delete('/interface[{:s}]/subinterface[0]'.format(if_subif_name),
{ # {
'name': if_subif_name, # 'name': if_subif_name,
}), # }),
#Delete network instance; automatically deletes: #Delete network instance; automatically deletes:
# - /network_instance[]/interface[] # - /network_instance[]/interface[]
......