-def get_request(url):
- return requests.request(
- "GET", url.format(RESTCONF_BASE_URL),
- headers=TYPE_APPLICATION_JSON,
- auth=(ODL_LOGIN, ODL_PWD),
- timeout=REQUEST_TIMEOUT)
-
-
-def post_request(url, data):
- if data:
- print(json.dumps(data))
- return requests.request(
- "POST", url.format(RESTCONF_BASE_URL),
- data=json.dumps(data),
- headers=TYPE_APPLICATION_JSON,
- auth=(ODL_LOGIN, ODL_PWD),
- timeout=REQUEST_TIMEOUT)
-
- return requests.request(
- "POST", url.format(RESTCONF_BASE_URL),
- headers=TYPE_APPLICATION_JSON,
- auth=(ODL_LOGIN, ODL_PWD),
- timeout=REQUEST_TIMEOUT)
-
-
-def post_xmlrequest(url, data):
- if data:
- return requests.request(
- "POST", url.format(RESTCONF_BASE_URL),
- data=data,
- headers=TYPE_APPLICATION_XML,
- auth=(ODL_LOGIN, ODL_PWD),
- timeout=REQUEST_TIMEOUT)
- return None
-
-
-def put_request(url, data):
- return requests.request(
- "PUT", url.format(RESTCONF_BASE_URL),
- data=json.dumps(data),
- headers=TYPE_APPLICATION_JSON,
- auth=(ODL_LOGIN, ODL_PWD),
- timeout=REQUEST_TIMEOUT)
-
-
-def put_xmlrequest(url, data):
- return requests.request(
- "PUT", url.format(RESTCONF_BASE_URL),
- data=data,
- headers=TYPE_APPLICATION_XML,
- auth=(ODL_LOGIN, ODL_PWD),
- timeout=REQUEST_TIMEOUT)
-
-
-def put_jsonrequest(url, data):
- return requests.request(
- "PUT", url.format(RESTCONF_BASE_URL),
- data=data,
- headers=TYPE_APPLICATION_JSON,
- auth=(ODL_LOGIN, ODL_PWD),
- timeout=REQUEST_TIMEOUT)
-
-
-def rawput_request(url, data):
- return requests.request(
- "PUT", url.format(RESTCONF_BASE_URL),
- data=data,
- headers=TYPE_APPLICATION_JSON,
- auth=(ODL_LOGIN, ODL_PWD),
- timeout=REQUEST_TIMEOUT)
-
-
-def rawpost_request(url, data):
- return requests.request(
- "POST", url.format(RESTCONF_BASE_URL),
- data=data,
- headers=TYPE_APPLICATION_JSON,
- auth=(ODL_LOGIN, ODL_PWD),
- timeout=REQUEST_TIMEOUT)
-
-
-def delete_request(url):
- return requests.request(
- "DELETE", url.format(RESTCONF_BASE_URL),
- headers=TYPE_APPLICATION_JSON,
- auth=(ODL_LOGIN, ODL_PWD),
- timeout=REQUEST_TIMEOUT)
-
-
-def mount_device(node_id, sim):
- url = URL_CONFIG_NETCONF_TOPO + "node/" + node_id
- body = {"node": [{
- "node-id": node_id,
- "netconf-node-topology:username": NODES_LOGIN,
- "netconf-node-topology:password": NODES_PWD,
- "netconf-node-topology:host": "127.0.0.1",
- "netconf-node-topology:port": SIMS[sim]['port'],
- "netconf-node-topology:tcp-only": "false",
- "netconf-node-topology:pass-through": {}}]}
- response = put_request(url, body)
- if wait_until_log_contains(TPCE_LOG, re.escape("Triggering notification stream NETCONF for node " + node_id), 180):
- print("Node " + node_id + " correctly added to tpce topology", end='... ', flush=True)
- else:
- print("Node " + node_id + " still not added to tpce topology", end='... ', flush=True)
- if response.status_code == requests.codes.ok:
- print("It was probably loaded at start-up", end='... ', flush=True)
- # TODO an else-clause to abort test would probably be nice here
- return response
-
-
-def mount_tapi_device(node_id, sim):
- url = URL_CONFIG_NETCONF_TOPO + "node/" + node_id
- body = {"node": [{
- "node-id": node_id,
- "netconf-node-topology:username": NODES_LOGIN,
- "netconf-node-topology:password": NODES_PWD,
- "netconf-node-topology:host": "127.0.0.1",
- "netconf-node-topology:port": SIMS[sim]['port'],
- "netconf-node-topology:tcp-only": "false",
- "netconf-node-topology:pass-through": {}}]}
- response = put_request(url, body)
- if wait_until_log_contains(TPCE_LOG, re.escape(f"TAPI node for or node {node_id} successfully merged"), 200):
- print("Node " + node_id + " correctly added to tpce topology", end='... ', flush=True)
- else:
- print("Node " + node_id + " still not added to tpce topology", end='... ', flush=True)
- if response.status_code == requests.codes.ok:
- print("It was probably loaded at start-up", end='... ', flush=True)
- # TODO an else-clause to abort test would probably be nice here
- return response
-
-
-def unmount_device(node_id):
- url = URL_CONFIG_NETCONF_TOPO + "node/" + node_id
- response = delete_request(url)
- if wait_until_log_contains(TPCE_LOG, re.escape("onDeviceDisConnected: " + node_id), 180):
- print("Node " + node_id + " correctly deleted from tpce topology", end='... ', flush=True)
- else:
- print("Node " + node_id + " still not deleted from tpce topology", end='... ', flush=True)
- return response
-
-
-def connect_xpdr_to_rdm_request(xpdr_node: str, xpdr_num: str, network_num: str,
- rdm_node: str, srg_num: str, termination_num: str):
- url = "{}/operations/transportpce-networkutils:init-xpdr-rdm-links"
- data = {
- "networkutils:input": {
- "networkutils:links-input": {
- "networkutils:xpdr-node": xpdr_node,
- "networkutils:xpdr-num": xpdr_num,
- "networkutils:network-num": network_num,
- "networkutils:rdm-node": rdm_node,
- "networkutils:srg-num": srg_num,
- "networkutils:termination-point-num": termination_num
- }
- }
- }
- return post_request(url, data)
-
-
-def connect_rdm_to_xpdr_request(xpdr_node: str, xpdr_num: str, network_num: str,
- rdm_node: str, srg_num: str, termination_num: str):
- url = "{}/operations/transportpce-networkutils:init-rdm-xpdr-links"
- data = {
- "networkutils:input": {
- "networkutils:links-input": {
- "networkutils:xpdr-node": xpdr_node,
- "networkutils:xpdr-num": xpdr_num,
- "networkutils:network-num": network_num,
- "networkutils:rdm-node": rdm_node,
- "networkutils:srg-num": srg_num,
- "networkutils:termination-point-num": termination_num
- }
- }
- }
- return post_request(url, data)
-
-
-def connect_xpdr_to_rdm_tapi_request(xpdr_node: str, xpdr_num: str, rdm_node: str, srg_num: str):
- url = "{}/operations/transportpce-tapinetworkutils:init-xpdr-rdm-tapi-link"
- data = {
- "input": {
- "xpdr-node": xpdr_node,
- "network-tp": xpdr_num,
- "rdm-node": rdm_node,
- "add-drop-tp": srg_num
- }
- }
- return post_request(url, data)
-
-
-def check_netconf_node_request(node: str, suffix: str):
- url = URL_CONFIG_NETCONF_TOPO + (
- "node/" + node + "/yang-ext:mount/org-openroadm-device:org-openroadm-device/" + suffix
- )
- return get_request(url)
-
-
-def get_netconf_oper_request(node: str):
- url = "{}/operational/network-topology:network-topology/topology/topology-netconf/node/" + node
- return get_request(url)
-
-
-def get_ordm_topo_request(suffix: str):
- url = URL_CONFIG_ORDM_TOPO + suffix
- return get_request(url)
-
-
-def add_oms_attr_request(link: str, attr):
- url = URL_CONFIG_ORDM_TOPO + (
- "ietf-network-topology:link/" + link + "/org-openroadm-network-topology:OMS-attributes/span"
- )
- return put_request(url, attr)
-
-
-def del_oms_attr_request(link: str):
- url = URL_CONFIG_ORDM_TOPO + (
- "ietf-network-topology:link/" + link + "/org-openroadm-network-topology:OMS-attributes/span"
- )
- return delete_request(url)
-
-
-def get_clli_net_request():
- return get_request(URL_CONFIG_CLLI_NET)
-
-
-def get_ordm_net_request():
- return get_request(URL_CONFIG_ORDM_NET)
-
-
-def get_otn_topo_request():
- return get_request(URL_CONFIG_OTN_TOPO)
-
-
-def del_link_request(link: str):
- url = URL_CONFIG_ORDM_TOPO + ("ietf-network-topology:link/" + link)
- return delete_request(url)
-
-
-def del_node_request(node: str):
- url = URL_CONFIG_CLLI_NET + ("node/" + node)
- return delete_request(url)
-
-
-def portmapping_request(suffix: str):
- url = URL_PORTMAPPING + suffix
- return get_request(url)
-
-
-def get_notifications_process_service_request(attr):
- return post_request(URL_GET_NBINOTIFICATIONS_PROCESS_SERV, attr)
-
-
-def get_notifications_alarm_service_request(attr):
- return post_request(URL_GET_NBINOTIFICATIONS_ALARM_SERV, attr)
-
-
-def get_service_list_request(suffix: str):
- return get_request(URL_OPER_SERV_LIST + suffix)
-
-
-def get_service_path_list_request(suffix: str):
- return get_request(URL_OPER_SERV_PATH_LIST + suffix)
-
-
-def service_create_request(attr):
- return post_request(URL_SERV_CREATE, attr)
-
-
-def service_delete_request(servicename: str,
- requestid="e3028bae-a90f-4ddd-a83f-cf224eba0e58",
- notificationurl="http://localhost:8585/NotificationServer/notify"):
- attr = {"input": {
- "sdnc-request-header": {
- "request-id": requestid,
- "rpc-action": "service-delete",
- "request-system-id": "appname",
- "notification-url": notificationurl},
- "service-delete-req-info": {
- "service-name": servicename,
- "tail-retention": "no"}}}
- return post_request(URL_SERV_DELETE, attr)
-
-
-def service_path_request(operation: str, servicename: str, wavenumber: str, nodes, centerfreq: str,
- slotwidth: int, minfreq: float, maxfreq: float, lowerslotnumber: int,
- higherslotnumber: int, modulation_format="dp-qpsk"):
- attr = {"renderer:input": {
- "renderer:service-name": servicename,
- "renderer:wave-number": wavenumber,
- "renderer:modulation-format": modulation_format,
- "renderer:operation": operation,
- "renderer:nodes": nodes,
- "renderer:center-freq": centerfreq,
- "renderer:nmc-width": slotwidth,
- "renderer:min-freq": minfreq,
- "renderer:max-freq": maxfreq,
- "renderer:lower-spectral-slot-number": lowerslotnumber,
- "renderer:higher-spectral-slot-number": higherslotnumber}}
- return post_request(URL_SERVICE_PATH, attr)
-
-
-def otn_service_path_request(operation: str, servicename: str, servicerate: str, serviceformat: str, nodes,
- eth_attr=None):
- attr = {"service-name": servicename,
- "operation": operation,
- "service-rate": servicerate,
- "service-format": serviceformat,
- "nodes": nodes}
- if eth_attr:
- attr.update(eth_attr)
- return post_request(URL_OTN_SERVICE_PATH, {"renderer:input": attr})
-
-
-def create_ots_oms_request(nodeid: str, lcp: str):
- attr = {"input": {
- "node-id": nodeid,
- "logical-connection-point": lcp}}
- return post_request(URL_CREATE_OTS_OMS, attr)
-
-
-def path_computation_request(requestid: str, servicename: str, serviceaend, servicezend,
- hardconstraints=None, softconstraints=None, metric="hop-count", other_attr=None):
- attr = {"service-name": servicename,
- "resource-reserve": "true",
- "service-handler-header": {"request-id": requestid},
- "service-a-end": serviceaend,
- "service-z-end": servicezend,
- "pce-routing-metric": metric}
- if hardconstraints:
- attr.update({"hard-constraints": hardconstraints})
- if softconstraints:
- attr.update({"soft-constraints": softconstraints})
- if other_attr:
- attr.update(other_attr)
- return post_request(URL_PATH_COMPUTATION_REQUEST, {"input": attr})
-
-
-def tapi_create_connectivity_request(topologyidorname):
- return post_request(URL_TAPI_CREATE_CONNECTIVITY, topologyidorname)
-
-
-def tapi_get_connectivity_request(serviceidorname):
- attr = {
- "input": {
- "service-id-or-name": serviceidorname}}
- return post_request(URL_TAPI_GET_CONNECTIVITY, attr)
-
-
-def tapi_delete_connectivity_request(serviceidorname):
- attr = {
- "input": {
- "service-id-or-name": serviceidorname}}
- return post_request(URL_TAPI_DELETE_CONNECTIVITY, attr)
-
-
-def tapi_get_topology_details_request(topologyidorname):
- attr = {
- "input": {
- "topology-id-or-name": topologyidorname}}
- return post_request(URL_TAPI_TOPOLOGY_DETAILS, attr)
-
-
-def tapi_get_node_details_request(topologyidorname, nodeidorname):
- attr = {
- "input": {
- "topology-id-or-name": topologyidorname,
- "node-id-or-name": nodeidorname}}
- return post_request(URL_TAPI_NODE_DETAILS, attr)
-
-
-def tapi_get_node_edge_point_details_request(topologyidorname, nodeidorname, nepidorname):
- attr = {
- "input": {
- "topology-id-or-name": topologyidorname,
- "node-id-or-name": nodeidorname,
- "ep-id-or-name": nepidorname}}
- return post_request(URL_TAPI_NEP_DETAILS, attr)
-
-
-def tapi_get_sip_details_request():
- return post_request(URL_TAPI_SIP_LIST, "")
-
-
-def tapi_get_service_list_request():
- return post_request(URL_TAPI_SERVICE_LIST, "")
-
-
-def tapi_create_notification_subscription_service_request(attr):
- return post_request(URL_TAPI_NOTIFICATION_SUBS_SERVICE, attr)
-
-
-def tapi_get_notifications_list_request(attr):
- return post_request(URL_TAPI_GET_NOTIFICATION_LIST, attr)
-
-