+if 'USE_SIMS' not in os.environ:
+ SIMS_TO_USE = 'lightynode'
+ SIMS_TYPE = 'lightynode'
+else:
+ SIMS_TO_USE = os.environ['USE_SIMS']
+ print("Forcing to use SIMS " + SIMS_TO_USE)
+ if SIMS_TO_USE != 'None' or 'SIMS_TYPE' not in os.environ:
+ SIMS_TYPE = SIMS_TO_USE
+ else:
+ SIMS_TYPE = os.environ['SIMS_TYPE']
+ print("Forcing to use SIMS type" + SIMS_TYPE)
+
+
+#
+# Basic HTTP operations
+#
+
+
+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 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 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 post_request(url, data):
+ if 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)
+
+#
+# Process management
+#
+
+
+def start_honeynode(log_file: str, sim):
+ executable = os.path.join(os.path.dirname(os.path.realpath(__file__)),
+ '..', '..', 'honeynode', sim[1], 'honeynode-simulator', 'honeycomb-tpce')
+ sample_directory = os.path.join(os.path.dirname(os.path.realpath(__file__)),
+ '..', '..', 'sample_configs', 'openroadm', sim[1])
+ if os.path.isfile(executable):
+ with open(log_file, 'w', encoding='utf-8') as outfile:
+ return subprocess.Popen(
+ [executable, SIMS[sim]['port'], os.path.join(sample_directory, SIMS[sim]['configfile'])],
+ stdout=outfile, stderr=outfile)
+ return None
+
+
+def start_lightynode(log_file: str, sim):
+ executable = os.path.join(os.path.dirname(os.path.realpath(__file__)),
+ '..', '..', 'lightynode', 'lightynode-openroadm-device', 'start-device.sh')
+ sample_directory = os.path.join(os.path.dirname(os.path.realpath(__file__)),
+ '..', '..', 'sample_configs', 'openroadm', sim[1])
+ if os.path.isfile(executable):
+ with open(log_file, 'w', encoding='utf-8') as outfile:
+ return subprocess.Popen(
+ [executable, "-v" + sim[1], "-p" + SIMS[sim]['port'], "-f" + os.path.join(sample_directory,
+ SIMS[sim]['configfile'])],
+ stdout=outfile, stderr=outfile)
+ return None
+