Skip to content
Snippets Groups Projects
Commit 9ce5f012 authored by Nikolay Stanchev's avatar Nikolay Stanchev
Browse files

Updates the network topology builder

parent cfe4e4ca
No related branches found
No related tags found
No related merge requests found
......@@ -250,7 +250,7 @@ class GraphAPI(object):
# map the dpid to the switch IP address, the IP address is in the format '/172.168.23.54:1234'
switches[switch["switchDPID"]] = switch["inetAddress"][1:].split(":")[0]
# retrieve all links - if SDN controller is unavailable on the given IP address return 503 Service Unavailable
# retrieve all external links (gathered through BDDP) - if SDN controller is unavailable on the given IP address return 503 Service Unavailable
try:
url = "http://{0}:8080{1}".format(sdn_controller_ip, "/wm/topology/external-links/json")
response = get(url)
......@@ -266,7 +266,28 @@ class GraphAPI(object):
raise HTTPNotImplemented("The SDN controller failed to return a successful response when querying for the network topology.")
try:
links = response.json()
external_links = response.json()
except ValueError: # response not in JSON
msg = "The SDN controller returned a response which couldn't be converted to JSON."
log.error("Unexpected error: {0}".format(msg))
raise HTTPNotImplemented("The SDN controller failed to return a valid JSON response when querying for the network topology.")
# retrieve all local links (gathered through LLDP) - if SDN controller is unavailable on the given IP address return 503 Service Unavailable
try:
url = "http://{0}:8080{1}".format(sdn_controller_ip, "/wm/topology/links/json")
response = get(url)
except exceptions.ConnectionError:
msg = "The SDN controller is not available on IP {0} and port 8080.".format(sdn_controller_ip)
log.error("Unexpected error: {0}".format(msg))
raise HTTPServiceUnavailable("The SDN controller couldn't be reached when trying to build the network topology.")
if response.status_code != 200:
msg = "The SDN controller returned a response with status code different than 200."
log.error("Unexpected error: {0}".format(msg))
raise HTTPNotImplemented("The SDN controller failed to return a successful response when querying for the network topology.")
try:
local_links = response.json()
except ValueError: # response not in JSON
msg = "The SDN controller returned a response which couldn't be converted to JSON."
log.error("Unexpected error: {0}".format(msg))
......@@ -283,7 +304,10 @@ class GraphAPI(object):
clusters = {}
# build the network graph and retrieve the number of switch nodes and cluster nodes that were created
switch_count, clusters_count = build_network_graph(graph, switches, links, clusters)
tmp_switch_count, tmp_clusters_count = build_network_graph(graph, switches, external_links, clusters)
switch_count, clusters_count = build_network_graph(graph, switches, local_links, clusters)
switch_count += tmp_switch_count
clusters_count += tmp_clusters_count
return {"new_switches_count": switch_count, "new_clusters_count": clusters_count}
......
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