Skip to content

Commit

Permalink
Merge pull request #8 from atlanticwave-sdx/7-create-a-swagger-server…
Browse files Browse the repository at this point in the history
…-with-standard-topology-and-connection-endpoints

XS⚠️ ◾ 7 create a swagger server with standard topology and connection endpoints
  • Loading branch information
lmarinve authored Apr 17, 2024
2 parents 89d4511 + 261db9a commit a29e889
Show file tree
Hide file tree
Showing 8 changed files with 363 additions and 488 deletions.
18 changes: 14 additions & 4 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,20 @@ SDX_TOPOLOGY_VALIDATOR='http://192.168.0.14:8000/validator/v1/validate'
SDX_OXPOS='kytos,kytos,kytos,kytos'
SDX_OXPO_NAMES='Test-OXP,Ampath-OXP,SAX-OXP,Tenet-OXPO'
SDX_OXPO_URLS='test.net,ampath.net,sax.net,tenet.ac.za'
SDX_LC_DOMAINS='urn:sdx:topology:test.net,urn:sdx:topology:ampath.net,urn:sdx:topology:sax.net,urn:sdx:topology:tenet.ac.za'
SDX_LC_URLS='http://0.0.0.0:8080/SDX-LC/1.0.0/topology,http://192.168.0.15:8080/SDX-LC/1.0.0/topology,http://192.168.0.16:8080/SDX-LC/1.0.0/topology,http://192.168.0.17:8080/SDX-LC/1.0.0/topology'
KYTOS_PROVISION='http://0.0.0.0:8181/SDX-LC/1.0.0/provision'
KYTOS_TOPOLOGY='http://0.0.0.0:8181/api/kytos/topology/v3/'
KYTOS_SDX_TOPOLOGY='http://0.0.0.0:8181/api/kytos/sdx_topology/v1/topology'
KYTOS_SDX_VERSION_CONTROL='http://0.0.0.0:8181/api/kytos/sdx_topology/v1/version/control'
FLASK_APP='swagger_server/__main__:main'
DEFAULT_TOPOLOGY='/topology'
DEFAULT_CONNECTION='/connection'
DEFAULT_URL='http://192.168.0.2:8181'
TOPOLOGY_PATH='/api/kytos/sdx_topology/v1/version/control'
CONNECTION_PATH='/api/kytos/topology/v3'
TOPOLOGY_1='/topology/1'
TOPOLOGY_2='/topology/2'
TOPOLOGY_3='/topology/3'
CONNECTION_1='/connection/1'
CONNECTION_2='/connection/2'
CONNECTION_3='/connection/3'
URL_1='http://192.168.0.2:8181'
URL_2='http://192.168.0.3:8181'
URL_3='http://192.168.0.4:8181'
21 changes: 3 additions & 18 deletions amlight/kytos-sdx-topology/app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ def setup(self):
self.shelve_loaded = False # pylint: disable=W0201
self.version_control = False # pylint: disable=W0201
OXPO_ID = int(os.environ.get("OXPO_ID"))
sdx_lc_urls_str = os.environ.get("SDXLC_URLS")
self.sdxlc_url = sdx_lc_urls_str.split(",")[OXPO_ID]
oxpo_names_str = os.environ.get("OXPO_NAMES")
self.oxpo_name = oxpo_names_str.split(",")[OXPO_ID]
oxpo_urls_str = os.environ.get("OXPO_URLS")
Expand Down Expand Up @@ -82,20 +80,6 @@ def get_kytos_topology():
result = kytos_topology["topology"]
return result

def post_sdx_lc(self, event_type=None):
""" return the status from post sdx topology to sdx lc"""
sdxlc_url = self.sdxlc_url
post_topology = requests.post(
sdxlc_url,
timeout=60,
json=self.sdx_topology)
if post_topology.status_code == 200:
if event_type is not None:
return {"result": self.sdx_topology,
"status_code": post_topology.status_code}
return {"result": post_topology.json(),
"status_code": post_topology.status_code}

def validate_sdx_topology(self):
""" return 200 if validated topology following the SDX data model"""
try:
Expand Down Expand Up @@ -171,8 +155,9 @@ def post_sdx_topology(self, event_type=None, event_timestamp=None):
if evaluate_topology["status_code"] == 200:
self.kytos2sdx = topology_updated.get("kytos2sdx", {})
self.sdx2kytos = topology_updated.get("sdx2kytos", {})
result = self.post_sdx_lc(event_type)
return result

return {"result": self.sdx_topology,
"status_code": evaluate_topology["status_code"]}
with shelve.open("events_shelve") as log_events:
shelve_events = log_events['events']
shelve_events.append(
Expand Down
27 changes: 16 additions & 11 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,8 @@ services:
OXPO_URLS: ${SDX_OXPO_URLS}
#
SDXTOPOLOGY_VALIDATOR: ${SDX_TOPOLOGY_VALIDATOR}
SDXLC_URLS: ${SDX_LC_URLS}
KYTOS_PROVISION: ${KYTOS_PROVISION}
KYTOS_TOPOLOGY: ${KYTOS_TOPOLOGY}
KYTOSSDX_TOPOLOGY: ${KYTOS_SDX_TOPOLOGY}
KYTOSSDX_VERSION_CONTROL: ${KYTOS_SDX_VERSION_CONTROL}
depends_on:
- mongo-ready
entrypoint: ["/scripts/amlight.sh"]
Expand Down Expand Up @@ -73,11 +70,8 @@ services:
OXPO_URLS: ${SDX_OXPO_URLS}
#
SDXTOPOLOGY_VALIDATOR: ${SDX_TOPOLOGY_VALIDATOR}
SDXLC_URLS: ${SDX_LC_URLS}
KYTOS_PROVISION: ${KYTOS_PROVISION}
KYTOS_TOPOLOGY: ${KYTOS_TOPOLOGY}
KYTOSSDX_TOPOLOGY: ${KYTOS_SDX_TOPOLOGY}
KYTOSSDX_VERSION_CONTROL: ${KYTOS_SDX_VERSION_CONTROL}
depends_on:
- mongo-ready
entrypoint: ["/scripts/sax.sh"]
Expand Down Expand Up @@ -113,11 +107,8 @@ services:
OXPO_URLS: ${SDX_OXPO_URLS}
#
SDXTOPOLOGY_VALIDATOR: ${SDX_TOPOLOGY_VALIDATOR}
SDXLC_URLS: ${SDX_LC_URLS}
KYTOS_PROVISION: ${KYTOS_PROVISION}
KYTOS_TOPOLOGY: ${KYTOS_TOPOLOGY}
KYTOSSDX_TOPOLOGY: ${KYTOS_SDX_TOPOLOGY}
KYTOSSDX_VERSION_CONTROL: ${KYTOS_SDX_VERSION_CONTROL}
depends_on:
- mongo-ready
entrypoint: ["/scripts/tenet.sh"]
Expand Down Expand Up @@ -300,9 +291,23 @@ services:
ports:
- 80:8080
volumes:
- ./os-base/nginx-base:/validator
- ./os-base/nginx-base:/oxpoapi
environment:
SWAGGER_JSON: /validator/validator.json
SWAGGER_JSON: /oxpoapi/oxpoapi.json
DEFAULT_TOPOLOGY: ${DEFAULT_TOPOLOGY}
DEFAULT_CONNECTION: ${DEFAULT_CONNECTION}
DEFAULT_URL: ${DEFAULT_URL}
TOPOLOGY_PATH: ${TOPOLOGY_PATH}
CONNECTION_PATH: ${CONNECTION_PATH}
TOPOLOGY_1: ${TOPOLOGY_1}
TOPOLOGY_2: ${TOPOLOGY_2}
TOPOLOGY_3: ${TOPOLOGY_3}
CONNECTION_1: ${CONNECTION_1}
CONNECTION_2: ${CONNECTION_2}
CONNECTION_3: ${CONNECTION_3}
URL_1: ${URL_1}
URL_2: ${URL_2}
URL_3: ${URL_3}

validator:
container_name: validator
Expand Down
40 changes: 40 additions & 0 deletions enable_all.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/bin/bash

AMLIGHT=http://0.0.0.0:8181
SAX=http://0.0.0.0:8282
TENET=http://0.0.0.0:8383

# Enable all switches
for sw in $(curl -s $AMLIGHT/api/kytos/topology/v3/switches | jq -r '.switches[].id'); do curl -H 'Content-type: application/json' -X POST $AMLIGHT/api/kytos/topology/v3/switches/$sw/enable; curl -H 'Content-type: application/json' -X POST $AMLIGHT/api/kytos/topology/v3/interfaces/switch/$sw/enable; done
for sw in $(curl -s $SAX/api/kytos/topology/v3/switches | jq -r '.switches[].id'); do curl -H 'Content-type: application/json' -X POST $SAX/api/kytos/topology/v3/switches/$sw/enable; curl -H 'Content-type: application/json' -X POST $SAX/api/kytos/topology/v3/interfaces/switch/$sw/enable; done
for sw in $(curl -s $TENET/api/kytos/topology/v3/switches | jq -r '.switches[].id'); do curl -H 'Content-type: application/json' -X POST $TENET/api/kytos/topology/v3/switches/$sw/enable; curl -H 'Content-type: application/json' -X POST $TENET/api/kytos/topology/v3/interfaces/switch/$sw/enable; done

# give a few seconds for link discovery (LLDP)
sleep 10

# enable all links
for l in $(curl -s $AMLIGHT/api/kytos/topology/v3/links | jq -r '.links[].id'); do curl -H 'Content-type: application/json' -X POST $AMLIGHT/api/kytos/topology/v3/links/$l/enable; done
for l in $(curl -s $SAX/api/kytos/topology/v3/links | jq -r '.links[].id'); do curl -H 'Content-type: application/json' -X POST $SAX/api/kytos/topology/v3/links/$l/enable; done
for l in $(curl -s $TENET/api/kytos/topology/v3/links | jq -r '.links[].id'); do curl -H 'Content-type: application/json' -X POST $TENET/api/kytos/topology/v3/links/$l/enable; done

# Amlight network operator role
curl -H 'Content-type: application/json' -X POST $AMLIGHT/api/kytos/topology/v3/switches/aa:00:00:00:00:00:00:01/metadata -d '{"lat": "25.77", "lng": "-80.19", "address": "Miami", "iso3166_2_lvl4": "US-FL"}'
curl -H 'Content-type: application/json' -X POST $AMLIGHT/api/kytos/topology/v3/switches/aa:00:00:00:00:00:00:02/metadata -d '{"lat": "26.38", "lng": "-80.11", "address": "BocaRaton", "iso3166_2_lvl4": "US-FL"}'
curl -H 'Content-type: application/json' -X POST $AMLIGHT/api/kytos/topology/v3/switches/aa:00:00:00:00:00:00:03/metadata -d '{"lat": "30.27", "lng": "-81.68", "address": "Jacksonville", "iso3166_2_lvl4": "US-FL"}'
curl -H 'Content-type: application/json' -X POST $AMLIGHT/api/kytos/topology/v3/interfaces/aa:00:00:00:00:00:00:01:40/metadata -d '{"sdx_nni": "sax.net:Sax01:40"}'
curl -H 'Content-type: application/json' -X POST $AMLIGHT/api/kytos/topology/v3/interfaces/aa:00:00:00:00:00:00:02:40/metadata -d '{"sdx_nni": "sax.net:Sax02:40"}'

# SAX network operator role
curl -H 'Content-type: application/json' -X POST $SAX/api/kytos/topology/v3/switches/dd:00:00:00:00:00:00:04/metadata -d '{"lat": "-3", "lng": "-40", "address": "Fortaleza", "iso3166_2_lvl4": "BR-CE"}'
curl -H 'Content-type: application/json' -X POST $SAX/api/kytos/topology/v3/switches/dd:00:00:00:00:00:00:05/metadata -d '{"lat": "-3", "lng": "-20", "address": "Fortaleza", "iso3166_2_lvl4": "BR-CE"}'
curl -H 'Content-type: application/json' -X POST $SAX/api/kytos/topology/v3/interfaces/dd:00:00:00:00:00:00:04:40/metadata -d '{"sdx_nni": "ampath.net:Ampath1:40"}'
curl -H 'Content-type: application/json' -X POST $SAX/api/kytos/topology/v3/interfaces/dd:00:00:00:00:00:00:04:41/metadata -d '{"sdx_nni": "tenet.ac.za:Tenet01:41"}'
curl -H 'Content-type: application/json' -X POST $SAX/api/kytos/topology/v3/interfaces/dd:00:00:00:00:00:00:05:40/metadata -d '{"sdx_nni": "ampath.net:Ampath2:40"}'
curl -H 'Content-type: application/json' -X POST $SAX/api/kytos/topology/v3/interfaces/dd:00:00:00:00:00:00:05:41/metadata -d '{"sdx_nni": "tenet.ac.za:Tenet02:41"}'

# TENET operator
curl -H 'Content-type: application/json' -X POST $TENET/api/kytos/topology/v3/switches/cc:00:00:00:00:00:00:06/metadata -d '{"lat": "-33", "lng": "18", "address": "CapeTown", "iso3166_2_lvl4": "ZA-WC"}'
curl -H 'Content-type: application/json' -X POST $TENET/api/kytos/topology/v3/switches/cc:00:00:00:00:00:00:07/metadata -d '{"lat": "-26", "lng": "28", "address": "Johanesburgo", "iso3166_2_lvl4": "ZA-GP"}'
curl -H 'Content-type: application/json' -X POST $TENET/api/kytos/topology/v3/switches/cc:00:00:00:00:00:00:08/metadata -d '{"lat": "-33", "lng": "27", "address": "EastLondon", "iso3166_2_lvl4": "ZA-EC"}'
curl -H 'Content-type: application/json' -X POST $TENET/api/kytos/topology/v3/interfaces/cc:00:00:00:00:00:00:06:41/metadata -d '{"sdx_nni": "sax.net:Sax01:41"}'
curl -H 'Content-type: application/json' -X POST $TENET/api/kytos/topology/v3/interfaces/cc:00:00:00:00:00:00:07:41/metadata -d '{"sdx_nni": "sax.net:Sax02:41"}'
2 changes: 2 additions & 0 deletions os-base/nginx-base/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,5 @@ ENV LANG=C.UTF-8
# set environment variables
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1

COPY ./os-base/nginx-base/default.conf.template /etc/nginx/templates/default.conf.template
76 changes: 76 additions & 0 deletions os-base/nginx-base/default.conf.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
types {
text/plain yaml;
text/plain yml;
}

gzip on;
gzip_static on;
gzip_disable "msie6";

gzip_vary on;
gzip_types text/plain text/css application/javascript;

map $request_method $access_control_max_age {
OPTIONS 1728000; # 20 days
}
server_tokens off; # Hide Nginx version

server {
listen $PORT;
server_name localhost;
index index.html index.htm;

location $BASE_URL {
absolute_redirect off;
alias /usr/share/nginx/html/;
expires 1d;

location ~ swagger-initializer.js {
expires -1;
include templates/cors.conf;
}

location ~* \.(?:json|yml|yaml)$ {
#SWAGGER_ROOT
expires -1;

include templates/cors.conf;
}

include templates/cors.conf;
include templates/embedding.conf;
}

location $DEFAULT_TOPOLOGY {
proxy_pass $DEFAULT_URL$TOPOLOGY_PATH;
}

location $TOPOLOGY_1 {
proxy_pass $URL_1$TOPOLOGY_PATH;
}

location $TOPOLOGY_2 {
proxy_pass $URL_2$TOPOLOGY_PATH;
}

location $TOPOLOGY_3 {
proxy_pass $URL_3$TOPOLOGY_PATH;
}

location $DEFAULT_CONNECTION {
proxy_pass $DEFAULT_URL$CONNECTION_PATH;
}

location $CONNECTION_1 {
proxy_pass $URL_1$CONNECTION_PATH;
}

location $CONNECTION_2 {
proxy_pass $URL_2$CONNECTION_PATH;
}

location $CONNECTION_3 {
proxy_pass $URL_3$CONNECTION_PATH;
}

}
112 changes: 112 additions & 0 deletions os-base/nginx-base/oxpoapi.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
{
"openapi": "3.0.0",
"info": {
"title": "Oxpo Api Wrapper",
"description": "The wrapper abstracts the complexities of direct API calls and offers a consistent method to interact with different OXPO services",
"version": "1.0.0",
"contact": {
"email": "[email protected]"
}
},
"servers": [
{
"url": "http://67.17.206.221"
}
],
"tags": [
{
"name": "topology",
"description": "Everything about your domain topology",
"externalDocs": {
"description": "Find out more",
"url": "https://www.atlanticwave-sdx.net"
}
},
{
"name": "node",
"description": "everything about a node in your domain"
},
{
"name": "link",
"description": "everything about a link in your domain"
},
{
"name": "user",
"description": "Operations about user",
"externalDocs": {
"description": "Find out more about our store",
"url": "https://www.atlanticwave-sdx.net"
}
}
],
"paths": {
"/topology": {
"get": {
"tags": [
"topology"
],
"summary": "Get SDX Topology",
"description": "Get SDX topology",
"responses": {
"200": {
"description": "Successful response",
"content": {
"application/json": {}
}
}
}
}
},
"/topology/1": {
"get": {
"tags": [
"topology"
],
"summary": "Get Ampath SDX Topology",
"description": "Get Ampath SDX topology",
"responses": {
"200": {
"description": "Successful response",
"content": {
"application/json": {}
}
}
}
}
},
"/topology/2": {
"get": {
"tags": [
"topology"
],
"summary": "Get SAX SDX Topology",
"description": "Get SAX SDX topology",
"responses": {
"200": {
"description": "Successful response",
"content": {
"application/json": {}
}
}
}
}
},
"/topology/3": {
"get": {
"tags": [
"topology"
],
"summary": "Get Tenet SDX Topology",
"description": "Get Tenet SDX topology",
"responses": {
"200": {
"description": "Successful response",
"content": {
"application/json": {}
}
}
}
}
}
}
}
Loading

0 comments on commit a29e889

Please sign in to comment.