[ONOS-7876] Initial STC implementation for ODTN
Change-Id: I51a22348cc73c576c5d10551e84ca8ac2f2a2040
diff --git a/tools/test/scenarios/bin/execute-tapi-context-get-call.py b/tools/test/scenarios/bin/execute-tapi-context-get-call.py
new file mode 100755
index 0000000..95cff90
--- /dev/null
+++ b/tools/test/scenarios/bin/execute-tapi-context-get-call.py
@@ -0,0 +1,43 @@
+#! /usr/bin/env python
+
+import requests
+import sys
+import tapiHelper
+
+from requests.auth import HTTPBasicAuth
+
+if len(sys.argv) < 3:
+ print "usage: execute-tapi-context-get-call onos-node state"
+ sys.exit(1)
+
+node = sys.argv[1]
+state = sys.argv[2] #if empty tapi context must be empty, if full it needs to contain all devices and ports
+
+if state != "empty" and len(sys.argv) == 3:
+ print "usage: execute-tapi-context-get-call onos-node full devices links ports"
+ sys.exit(1)
+
+request = 'http://' + node + ':8181/onos/restconf/data/tapi-common:context'
+tapiContext = tapiHelper.get_context(request)
+
+if state == "empty":
+ uuid = tapiContext['tapi-common:context']['tapi-topology:topology-context']['topology'][0]['uuid']
+ if uuid == "":
+ print "empty uuid"
+ sys.exit(1)
+ print "@stc tapi topology uuid=" + uuid
+ sys.exit(0)
+
+if state == "full":
+ devices = sys.argv[3]
+ links = sys.argv[4]
+ ports = sys.argv[5]
+ #TODO parse reply for number of devices, links and ports
+ print "Parsing for given topology not yet implemented"
+ sys.exit(0)
+
+sys.exit(1)
+
+
+
+
diff --git a/tools/test/scenarios/bin/execute-tapi-post-call.py b/tools/test/scenarios/bin/execute-tapi-post-call.py
new file mode 100755
index 0000000..031e276
--- /dev/null
+++ b/tools/test/scenarios/bin/execute-tapi-post-call.py
@@ -0,0 +1,46 @@
+#! /usr/bin/env python
+
+import requests
+import sys
+import tapiHelper
+
+from requests.auth import HTTPBasicAuth
+
+if len(sys.argv) < 4:
+ print "usage: execute-tapi-post-call onos-node context empty uuid. Uuid is optional and defaults to empty"
+ sys.exit(1)
+
+node = sys.argv[1]
+context = sys.argv[2]
+empty = sys.argv[3]
+
+if len(sys.argv) == 4:
+ uuid = ""
+else:
+ uuid = sys.argv[4]
+
+if "get-connectivity-service-list" in context:
+ connectivity_request = 'http://' + node + ':8181/onos/restconf/operations/' + context
+ tapi_connection = tapiHelper.get_connection(connectivity_request, uuid)
+ tapi_connection_json = tapi_connection.json()
+ print tapi_connection_json
+ if not tapi_connection_json["tapi-connectivity:output"] and empty != "empty":
+ print "No connection was established"
+ sys.exit(1)
+ #TODO verify empty connection if uuid is empty
+ #TODO verify correct connection if uuid is not empty
+ sys.exit(0)
+
+if "create-connectivity-service" in context:
+ context_request = 'http://' + node + ':8181/onos/restconf/data/tapi-common:context'
+ connectivity_request = 'http://' + node + ':8181/onos/restconf/operations/' + context
+ tapi_connection = tapiHelper.create_connection(context_request, connectivity_request)
+ print context
+ print tapi_connection.json()
+ sys.exit(0)
+
+sys.exit(1)
+
+
+
+
diff --git a/tools/test/scenarios/bin/tapiHelper.py b/tools/test/scenarios/bin/tapiHelper.py
new file mode 100755
index 0000000..74714d0
--- /dev/null
+++ b/tools/test/scenarios/bin/tapiHelper.py
@@ -0,0 +1,115 @@
+#!/usr/bin/python3
+
+import requests
+import json
+import itertools
+
+#
+# Creates connectivity json
+#
+def tapi_input(sip_uuids):
+ create_input = {
+ "tapi-connectivity:input": {
+ "end-point" : [
+ {
+ "local-id": sip_uuids[0],
+ "service-interface-point": {
+ "service-interface-point-uuid" : sip_uuids[0]
+ }
+ }
+ ,
+ {
+ "local-id": sip_uuids[1],
+ "service-interface-point": {
+ "service-interface-point-uuid" : sip_uuids[1]
+ }
+ }
+ ]
+ }
+ }
+ return create_input
+
+#
+# Obtains TAPI context through restconf
+#
+def get_context(url_context):
+ resp = requests.get(url_context, auth=('onos', 'rocks'))
+ if resp.status_code != 200:
+ raise Exception('GET {}'.format(resp.status_code))
+ return resp.json()
+
+#
+# Requests a connectivity service
+#
+def request_connection(url_connectivity, context):
+ # All Context SIPs
+ sips = context["tapi-common:context"]["service-interface-point"]
+
+ # Sorted Photonic Media SIPs. filter is an iterable
+ esips = list(filter(is_dsr_media, sorted(sips, key=lambda sip: sip["name"][0]["value"])))
+ endpoints = [esips[0], esips[-1]]
+ sip_uuids = []
+ for sip in endpoints:
+ sip_uuids.append(sip["uuid"])
+ for uuid in sip_uuids:
+ print(uuid)
+
+ create_input_json = json.dumps(tapi_input(sip_uuids))
+ print (create_input_json)
+ headers = {'Content-type': 'application/json'}
+ resp = requests.post(url_connectivity, data=create_input_json, headers=headers, auth=('onos', 'rocks'))
+ if resp.status_code != 200:
+ raise Exception('POST {}'.format(resp.status_code))
+ return resp
+
+#
+# Filter method used to keep only SIPs that are photonic_media
+#
+def is_photonic_media(sip):
+ return sip["layer-protocol-name"]=="PHOTONIC_MEDIA"
+
+#
+# Filter method used to keep only SIPs that are DSR
+#
+def is_dsr_media(sip):
+ return sip["layer-protocol-name"]=="DSR"
+
+#
+# Processes the topology to verify the correctness
+#
+def process_topology():
+ # TODO use method to parse topology
+ # Getting the Topology
+ # topology = context["tapi-common:context"]["tapi-topology:topology-context"]["topology"][0]
+ # nodes = topology["node"];
+ # links = topology["link"];
+ noop
+
+#
+# Creates a connection first getting the context, parsing for SIPS and then issuing the request.
+#
+def create_connection(url_context, url_connectivity):
+ context = get_context(url_context)
+ return request_connection(url_connectivity, context)
+
+#
+# Obtains existing connectivity services
+#
+def get_connection(url_connectivity, uuid):
+ if(uuid == ""):
+ json = '{}'
+ else:
+ #TODO use uuid to retrieve given topo
+ print "Not Yet implemented"
+ json = '{}'
+ headers = {'Content-type': 'application/json'}
+ resp = requests.post(url_connectivity, data=json, headers=headers, auth=('onos', 'rocks'))
+ if resp.status_code != 200:
+ raise Exception('POST {}'.format(resp.status_code))
+ return resp
+
+
+
+
+
+