Skip to content
Snippets Groups Projects
Commit 75c30dd9 authored by Andrea Sgambelluri's avatar Andrea Sgambelluri
Browse files

Bugs fixed in auto discovery for Transponders , and edit config for Roadms

parent 2a8dccd9
No related branches found
No related tags found
2 merge requests!294Release TeraFlowSDN 4.0,!284Resolve: "(CNIT) Multi-Granular Optical Nodes and Optical Transpoders management"
File added
device 0 → 100644
This diff is collapsed.
......@@ -31,7 +31,8 @@ from device.service.driver_api.AnyTreeTools import TreeNode
from .templates.VPN.common import seperate_port_config
#from .Tools import xml_pretty_print, xml_to_dict, xml_to_file
from .templates.VPN.roadms import (create_media_channel,create_optical_band, disable_media_channel , delete_optical_band)
from .templates.VPN.roadms import (create_media_channel,create_optical_band, disable_media_channel
, delete_optical_band,create_media_channel_v2)
from .templates.VPN.transponder import (edit_optical_channel ,change_optical_channel_status)
from .RetryDecorator import retry
from context.client.ContextClient import ContextClient
......@@ -173,7 +174,7 @@ def edit_config(
str_config_messages = create_optical_band(resources)
else :
#roadm media-channel
str_config_messages=create_media_channel(resources)
str_config_messages=create_media_channel_v2(resources)
#Disabling of the Configuration
else :
# Device type is Transponder
......
......@@ -126,6 +126,57 @@ def create_media_channel (resources):
def create_media_channel_v2 (resources):
optical_band_namespaces="http://flex-scale-project.eu/yang/flex-scale-mg-on"
results=[]
unwanted_keys=['destination_port','source_port','channel_namespace'
,'frequency','operational-mode','target-output-power',
"handled_flow","channel_num"]
config,ports,index=filter_config(resources,unwanted_keys)
doc, tag, text = Doc().tagtext()
with tag('config',xmlns="urn:ietf:params:xml:ns:netconf:base:1.0"):
with tag('wavelength-router', xmlns="http://openconfig.net/yang/wavelength-router"):
with tag('media-channels'):
n = 0
for flow in ports:
src,dest=flow
with tag('channel', operation="create"):
#with tag('channel'):
with tag('index'):text(str(int(index)+n))
with tag('config'):
#with tag('index'):text(index)
for resource in config:
if resource['resource_key'] == "index":
with tag('index'):text(str(int(index)+n))
elif resource['resource_key']== 'optical-band-parent' :
with tag('optical-band-parent',xmlns=optical_band_namespaces):text(resource['value'])
elif resource['resource_key']== 'admin-state' :
with tag('admin-status'):text(resource['value'])
else:
with tag(resource['resource_key']):text(resource['value'])
if src is not None and src != '0':
with tag('source'):
with tag('config'):
with tag('port-name'):text(src)
n+=1
result = indent(
doc.getvalue(),
indentation = ' '*2,
newline = ''
)
results.append(result)
return results
......
......@@ -125,7 +125,7 @@ def extract_media_channels (data_xml:str):
def extract_roadm_ports (xml_data:str):
def extract_roadm_ports_old (xml_data:str):
ports =[]
pattern = r'\bMG_ON_OPTICAL_PORT_WAVEBAND\b'
......@@ -152,8 +152,40 @@ def extract_roadm_ports (xml_data:str):
if (re.search(pattern,value.text)):
name_element= component.find(".//oc:name",namespace)
ports.append(name_element.text)
return ports
return ports
def extract_roadm_ports (xml_data:str):
ports =[]
pattern2=r'\bMG_ON_PORT_TYPE'
pattern = r'\bMG_ON_OPTICAL_PORT_WAVEBAND\b'
xml_bytes = xml_data.encode("utf-8")
root = ET.fromstring(xml_bytes)
namespace = {'oc': 'http://openconfig.net/yang/platform'}
ports = []
components = root.findall('.//oc:component',namespace)
#print(f"component {components}")
for component in components:
properties = component.find(".//oc:properties",namespace)
if (properties is not None):
for property in properties :
value = property.find(".//oc:value",namespace)
name= property.find('.//oc:name',namespace)
if (re.search(pattern2,name.text)):
value = property.find(".//oc:value",namespace)
name_element= component.find(".//oc:name",namespace)
print('value',value.text)
ports.append((name_element.text,value.text))
return ports
......@@ -167,9 +199,10 @@ def roadm_values_extractor (data_xml:str,resource_keys:list,dic:dict):
if len(ports)>0 :
for port in ports :
resource_key = '/endpoints/endpoint[{:s}]'.format(port)
resource_value = {'uuid': port, 'type':'MG_ON_OPTICAL_PORT_WAVEBAND'}
name,type=port
resource_key = '/endpoints/endpoint[{:s}]'.format(name)
resource_value = {'uuid': name, 'type':type}
ports_result.append((resource_key, resource_value))
return [ports_result,optical_bands,media_cahannels]
......
......@@ -8,30 +8,40 @@ import logging
create_media='''
<config xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
<wavelength-router xmlns="http://openconfig.net/yang/wavelength-router">
<media-channels>
<channel>
<index>1</index>
<config>
<index>1</index>
<name>C_BAND</name>
<lower-frequency>192006250</lower-frequency>
<upper-frequency>192056250</upper-frequency>
<optical-band-parent xmlns="http://flex-scale-project.eu/yang/flex-scale-mg-on">1</optical-band-parent>
</config>
<source>
<config>
<port-name>111</port-name>
</config>
</source>
<dest>
<config>
<port-name>2</port-name>
</config>
</dest>
</channel>
</media-channels>
<config xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
<wavelength-router xmlns="http://openconfig.net/yang/wavelength-router">
<media-channels>
<channel operation="create">
<index>2</index>
<config>
<name>C_BAND</name>
<optical-band-parent xmlns="http://flex-scale-project.eu/yang/flex-scale-mg-on">1</optical-band-parent>
<index>2</index>
<lower-frequency>192006250</lower-frequency>
<upper-frequency>192106250</upper-frequency>
</config>
<source>
<config>
<port-name>port-1-in</port-name>
</config>
</source>
</channel>
</media-channels>
</wavelength-router>
</config>
'''
delete_media_channel='''
<config xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
<wavelength-router xmlns="http://openconfig.net/yang/wavelength-router">
<media-channels>
<channel operation="delete">
<index>1</index>
<config>
<index>1</index>
</config>
</channel>
</media-channels>
</wavelength-router>
</config>
'''
......@@ -114,81 +124,46 @@ def extract_channel_xmlns (data_xml:str,is_opticalband:bool):
return namespace
def extract_optical_bands (data_xml:str,namespace:str):
namespaces={"oc":"http://flex-scale-project.eu/yang/flex-scale-mg-on"}
xml_bytes = data_xml.encode("utf-8")
root = ET.fromstring(xml_bytes)
optical_bands= root.find('.//oc:optical-bands',namespaces)
op_bands=[]
if optical_bands is not None :
optical_bands_ele= optical_bands.findall('.//oc:optical-band',namespaces)
for optical_band in optical_bands_ele:
band_ele=optical_band.find('.//oc:name',namespaces)
lower_freq_ele=optical_band.find('.//oc:lower-frequency',namespaces)
upper_freq_ele=optical_band.find('.//oc:upper-frequency',namespaces)
admin_status_ele=optical_band.find('.//oc:admin-status',namespaces)
source_ele=optical_band.find('.//oc:source/oc:config/oc:port-name',namespaces)
dest_ele=optical_band.find('.//oc:dest/oc:config/oc:port-name',namespaces)
channel_index= optical_band.find('.//oc:index',namespaces)
op_band_obj={
'band_name':band_ele.text if band_ele is not None else None,
'lower_frequency':lower_freq_ele.text if lower_freq_ele is not None else None,
'upper_frequency':upper_freq_ele.text if upper_freq_ele is not None else None,
'admin_status':admin_status_ele.text if admin_status_ele is not None else None,
'src_port':source_ele.text if source_ele is not None else None,
'dest_port':dest_ele.text if dest_ele is not None else None,
"channel_index":channel_index.text if channel_index is not None else None
}
op_bands.append(op_band_obj)
return op_bands
def extract_media_channels (data_xml:str,namespace:str):
optical_band_namespaces="http://flex-scale-project.eu/yang/flex-scale-mg-on"
namespaces={"oc":"http://openconfig.net/yang/wavelength-router",'ob_parent':optical_band_namespaces}
xml_bytes = data_xml.encode("utf-8")
root = ET.fromstring(xml_bytes)
media_channels= root.find(f'.//oc:media-channels',namespaces)
op_bands=[]
if media_channels is not None :
media_channels_ele= media_channels.findall('.//oc:channel',namespaces)
def extract_roadm_ports (xml_data:str):
ports =[]
pattern2=r'\bMG_ON_PORT_TYPE'
pattern = r'\bMG_ON_OPTICAL_PORT_WAVEBAND\b'
xml_bytes = xml_data.encode("utf-8")
root = ET.fromstring(xml_bytes)
namespace = {'oc': 'http://openconfig.net/yang/platform'}
ports = []
components = root.findall('.//oc:component',namespace)
#print(f"component {components}")
for component in components:
properties = component.find(".//oc:properties",namespace)
if (properties is not None):
for property in properties :
value = property.find(".//oc:value",namespace)
name= property.find('.//oc:name',namespace)
if (re.search(pattern2,name.text)):
value = property.find(".//oc:value",namespace)
name_element= component.find(".//oc:name",namespace)
print('value',value.text)
ports.append((name_element.text,value.text))
# if (re.search(pattern2,value.text)):
# #print('value',value.text)
# name_element= component.find(".//oc:name",namespace)
# ports.append(name_element.text)
return ports
for optical_band in media_channels_ele:
band_ele=optical_band.find('.//oc:name',namespaces)
lower_freq_ele=optical_band.find('.//oc:lower-frequency',namespaces)
upper_freq_ele=optical_band.find('.//oc:upper-frequency',namespaces)
admin_status_ele=optical_band.find('.//oc:admin-status',namespaces)
source_ele=optical_band.find('.//oc:source/oc:config/oc:port-name',namespaces)
dest_ele=optical_band.find('.//oc:dest/oc:config/oc:port-name',namespaces)
ob_parent=optical_band.find('.//ob_parent:optical-band-parent',namespaces)
channel_index= optical_band.find('.//oc:index',namespaces)
op_band_obj={
'band_name':band_ele.text if band_ele is not None else None,
'lower_frequency':lower_freq_ele.text if lower_freq_ele is not None else None,
'upper_frequency':upper_freq_ele.text if upper_freq_ele is not None else None,
'admin_status':admin_status_ele.text if admin_status_ele is not None else None,
'src_port':source_ele.text if source_ele is not None else None,
'dest_port':dest_ele.text if dest_ele is not None else None,
'optical_band_parent':ob_parent.text if ob_parent is not None else None,
'channel_index':channel_index.text if channel_index is not None else None
}
op_bands.append(op_band_obj)
return op_bands
device = {
'host': '10.0.2.4', # IP address or hostname of the remote machine
'port': 2026, # SSH port (default: 22)
'host': '172.17.254.22', # IP address or hostname of the remote machine
'port': 2022, # SSH port (default: 22)
'username': 'admin', # SSH username
'password': 'admin', # SSH password
'device_params': {'name': 'default'},
......@@ -208,8 +183,9 @@ if __name__ == '__main__':
,hostkey_verify=device['hostkey_verify']
,allow_agent=device['allow_agent']
,look_for_keys=device['look_for_keys']) as m :
#edit_result = m.edit_config (target="running",config=edit_optical_channel)
#edit_result = m.edit_config (target="running",config=delete_media_channel )
result = m.get_config (source="running").data_xml
#ports = extract_roadm_ports(result)
# optical_band_namespaces="http://flex-scale-project.eu/yang/flex-scale-mg-on"
#namespaces={"oc":"http://openconfig.net/yang/wavelength-router"}
#obj=extract_media_channels(result,namespaces)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment