From 3cb5e3f18a1c6212f1b247ac89dcc2d4a280581e Mon Sep 17 00:00:00 2001
From: Nikolay Stanchev <ns17@it-innovation.soton.ac.uk>
Date: Fri, 15 Feb 2019 10:03:17 +0000
Subject: [PATCH] updates graph API to return traffic_source tag

---
 src/service/clmcservice/graphapi/tests.py | 12 ++++++------
 src/service/clmcservice/graphapi/views.py |  1 +
 2 files changed, 7 insertions(+), 6 deletions(-)

diff --git a/src/service/clmcservice/graphapi/tests.py b/src/service/clmcservice/graphapi/tests.py
index 3d83f41..02e26c3 100644
--- a/src/service/clmcservice/graphapi/tests.py
+++ b/src/service/clmcservice/graphapi/tests.py
@@ -388,7 +388,7 @@ class TestGraphAPI(object):
         assert error_raised, "HTTP Not Found error must be thrown for a non existing endpoint"
 
         # go through the set of input/output (expected) parameters and assert actual results match with expected ones
-        for dc, endpoint, forward_latencies, reverse_latencies, response_time, request_size, response_size, rtt, global_tags in (
+        for startpoint, endpoint, forward_latencies, reverse_latencies, response_time, request_size, response_size, rtt, global_tags in (
             ("DC6", "nginx_1_ep2", [], [], 22.2, 35600, 6420, 22.2, {"flame_location": "DC6", "flame_sfe": "nginx_1_ep2", "flame_server": "DC6", "flame_sfc": "test_sfc", "flame_sfci": "test_sfc_premium", "flame_sfp": "nginx", "flame_sf": "nginx_1"}),
             ("127.0.0.6", "nginx_1_ep2", [0], [0], 22.2, 35600, 6420, 22.2, {"flame_location": "DC6", "flame_sfe": "nginx_1_ep2", "flame_server": "DC6", "flame_sfc": "test_sfc", "flame_sfci": "test_sfc_premium", "flame_sfp": "nginx", "flame_sf": "nginx_1"}),
             ("ue6", "nginx_1_ep2", [0, 0], [0, 0], 22.2, 35600, 6420, 22.2, {"flame_location": "DC6", "flame_sfe": "nginx_1_ep2", "flame_server": "DC6", "flame_sfc": "test_sfc", "flame_sfci": "test_sfc_premium", "flame_sfp": "nginx", "flame_sf": "nginx_1"}),
@@ -401,12 +401,12 @@ class TestGraphAPI(object):
             request = testing.DummyRequest()
             request.matchdict["graph_id"] = request_id
             request.params["endpoint"] = endpoint
-            request.params["startpoint"] = dc
+            request.params["startpoint"] = startpoint
             response = GraphAPI(request).run_rtt_query()
             # approximation is used to avoid long float numbers retrieved from influx, the test case ensures the results are different enough so that approximation of +-1 is good enough for testing
             assert response.pop("round_trip_time") == pytest.approx(rtt, 1), "Incorrect RTT response"
             assert response == {"forward_latencies": forward_latencies, "reverse_latencies": reverse_latencies, "total_forward_latency": sum(forward_latencies), "total_reverse_latency": sum(reverse_latencies),
-                                "bandwidth": 104857600, "response_time": response_time, "global_tags": global_tags,
+                                "bandwidth": 104857600, "response_time": response_time, "local_tags": {"traffic_source": startpoint}, "global_tags": global_tags,
                                 "request_size": request_size, "response_size": response_size}, "Incorrect RTT response"
 
         # send a new request for a new service function chain to create a second subgraph to test
@@ -432,7 +432,7 @@ class TestGraphAPI(object):
         request_id = graph_subresponse["uuid"]
 
         # go through the set of input/output (expected) parameters and assert actual results match with expected ones
-        for dc, endpoint, forward_latencies, reverse_latencies, response_time, request_size, response_size, rtt, global_tags in (
+        for startpoint, endpoint, forward_latencies, reverse_latencies, response_time, request_size, response_size, rtt, global_tags in (
             ("DC5", "apache_1_ep1", [], [], 17.6, 1480, 7860, 17.6, {"flame_location": "DC5", "flame_sfe": "apache_1_ep1", "flame_server": "DC5", "flame_sfc": "test_sfc", "flame_sfci": "test_sfc_non_premium", "flame_sfp": "apache", "flame_sf": "apache_1"}),
             ("127.0.0.5", "apache_1_ep1", [0], [0], 17.6, 1480, 7860, 17.6, {"flame_location": "DC5", "flame_sfe": "apache_1_ep1", "flame_server": "DC5", "flame_sfc": "test_sfc", "flame_sfci": "test_sfc_non_premium", "flame_sfp": "apache", "flame_sf": "apache_1"}),
             ("DC5", "minio_2_ep1", [], [], 7, 2998, 3610, 7, {"flame_location": "DC5", "flame_sfe": "minio_2_ep1", "flame_server": "DC5", "flame_sfc": "test_sfc", "flame_sfci": "test_sfc_non_premium", "flame_sfp": "minio", "flame_sf": "minio_2"}),
@@ -447,14 +447,14 @@ class TestGraphAPI(object):
             request = testing.DummyRequest()
             request.matchdict["graph_id"] = request_id
             request.params["endpoint"] = endpoint
-            request.params["startpoint"] = dc
+            request.params["startpoint"] = startpoint
             response = GraphAPI(request).run_rtt_query()
             # approximation is used to avoid long float numbers retrieved from influx, the test case ensures the results are different enough so that approximation of +-1 is good enough for testing
             assert response.pop("request_size") == pytest.approx(request_size, 1), "Incorrect RTT response"
             assert response.pop("response_size") == pytest.approx(response_size, 1), "Incorrect RTT response"
             assert response.pop("round_trip_time") == pytest.approx(rtt, 1), "Incorrect RTT response"
             assert response == {"forward_latencies": forward_latencies, "reverse_latencies": reverse_latencies, "total_forward_latency": sum(forward_latencies), "total_reverse_latency": sum(reverse_latencies),
-                                "bandwidth": 104857600, "response_time": response_time, "global_tags": global_tags}, "Incorrect RTT response"
+                                "bandwidth": 104857600, "response_time": response_time, "local_tags": {"traffic_source": startpoint}, "global_tags": global_tags}, "Incorrect RTT response"
 
     def test_delete_network_graph(self):
         """
diff --git a/src/service/clmcservice/graphapi/views.py b/src/service/clmcservice/graphapi/views.py
index 8cde075..4abedc4 100644
--- a/src/service/clmcservice/graphapi/views.py
+++ b/src/service/clmcservice/graphapi/views.py
@@ -167,6 +167,7 @@ class GraphAPI(object):
 
         result["global_tags"] = {"flame_sfe": endpoint_node["name"], "flame_server": hosted_by_node["name"], "flame_location": hosted_by_node["name"],
                                  "flame_sfc": reference_node["sfc"], "flame_sfci": reference_node["sfci"], "flame_sfp": sf_package_node["name"], "flame_sf": sf_node["name"]}
+        result["local_tags"] = {"traffic_source": startpoint_node_label}
 
         # calculate the Round-Trip-Time
         total_forward_latency = sum(result["forward_latencies"])
-- 
GitLab