This commit is contained in:
Abdel-Kader Chabi-Sika-Boni 2021-01-03 19:00:14 +01:00
rodzic 46310ef22e
commit 2e5c05fff2
21 zmienionych plików z 1497 dodań i 0 usunięć

34
Dockerfiles/API.txt Normal file
Wyświetl plik

@ -0,0 +1,34 @@
SERVER
GET /devices
GET /device/:dev
POST /device/:dev/data
GET /device/:dev/data
POST /devices/register
GET /gateways
GET /gateways/:gw
POST /gateways/register
GET /ping
GET /health
GATEWAY (Intermediary & Final)
POST /gateways/register
POST /devices/register
POST /device/:dev/data
GET /gateways
GET /gateway/:gw
GET /ping
GET /health
DEVICE
---
Data Format
{ Name : LOCAL_ENDPOINT.NAME,
Data : dataItem++, //an integer incrementing everytime data is sent
Time : Date.now(), //the date (+hour) the data has been sent
}
Register Format
{ Name : LOCAL_ENDPOINT.NAME, //the name of the entity which want to register itself
PoC : 'http://' + LOCAL_ENDPOINT.IP + ':' + LOCAL_ENDPOINT.PORT, //the address from which the registering entity can be joined
}

Wyświetl plik

@ -0,0 +1,45 @@
Test Architecture
**********************
* CONTAINER *
* IP = x.x.x.x *
* *
* ++++++++++++++++++ *
* + SERVER (srv) + *
* + IP = 127.0.0.1 + *
* + PORT = 8080 + *
* ++++++++++++++++++ *
**********************
||
**********************
* CONTAINER *
* IP = x.x.x.x *
* *
* ++++++++++++++++++ *
* + GATWEWAY (gwi) + *
* + IP = 127.0.0.1 + *
* + PORT = 8181 + *
* ++++++++++++++++++ *
**********************
||
**********************
* CONTAINER *
* IP = x.x.x.x *
* *
* ++++++++++++++++++ *
* + GATEWAY (gwf1) + *
* + IP = 127.0.0.1 + *
* + PORT = 8282 + *
* ++++++++++++++++++ *
**********************
||
**********************
* CONTAINER *
* IP = x.x.x.x *
* *
* ++++++++++++++++++ *
* + DEVICE (dev1) + *
* + IP = 127.0.0.1 + *
* + PORT = 9001 + *
* ++++++++++++++++++ *
**********************

Wyświetl plik

@ -0,0 +1,23 @@
#!/bin/bash
# This script intend to delete existing images (if exists) and recreate them all
# This script must be launch in root mode
# This script must be launched from the 'forContainerNet' folder
# This script must be launched by being sure there isn't any running container using the images below (exit from topology if not yet done)
docker rmi config:topo
docker rmi server:topo
docker rmi gateway:topo
docker rmi device:topo
cd bootserver
docker build -t config:topo .
cd ../server
docker build -t server:topo .
cd ../gateway
docker build -t gateway:topo .
cd ../device
docker build -t device:topo .

Wyświetl plik

@ -0,0 +1,22 @@
# Choosing the image to use
FROM node:buster
# Installing required libraries
RUN apt-get update && \
apt-get install -y net-tools iputils-ping python-pip && \
pip install flask && \
pip install requests && \
mkdir mydir && \
cd mydir
COPY bootstrap_server.py /mydir
SHELL ["/bin/bash", "-c"]
RUN echo "nohup python /mydir/bootstrap_server.py &" > start.sh && \
echo "/bin/bash" >> start.sh && \
chmod 777 start.sh
# Mandatory entrypoint in containernet
ENTRYPOINT ./start.sh

Wyświetl plik

@ -0,0 +1,52 @@
#!/usr/bin/python
#coding: utf-8
import os
import subprocess
import requests
from time import sleep
BOOTSTRAP_SERVER_ADDRESS = '10.10.10.10:5555'
def retrieve_config():
my_json_config = {"verdict":"oops"}
my_ip = str(subprocess.check_output("echo $MY_IP", shell=True)).rstrip()
print("MY_IP : %s"%(my_ip))
while my_json_config["verdict"] != "yes":
try:
resp = requests.get("http://%s/getmyconfig/%s"%(BOOTSTRAP_SERVER_ADDRESS, my_ip), timeout=2)
except:
print("Unable to join the bootstrap server")
try:
my_json_config = resp.json()
print("Extracted configs [succ] : %s"%(my_json_config))
except:
print("Unable to extract configs from bootstrap server's answer")
print("Extracted configs [fail] : %s"%(my_json_config))
print("request url : ==>%s<=="%("http://%s/getmyconfig/%s"%(BOOTSTRAP_SERVER_ADDRESS, my_ip)))
if "verdict" in my_json_config and my_json_config["verdict"] == "yes":
my_config = config_json_to_string(my_json_config)
subprocess.check_output("node /mydir/*.js %s"%(my_config), shell=True)
else:
my_json_config = {"verdict":"oops"}
sleep(3)
def config_json_to_string(json_config):
config = ""
if "local_ip" in json_config:
config += "--local_ip "+json_config["local_ip"]+" "
if "local_port" in json_config:
config += "--local_port "+str(json_config["local_port"])+" "
if "local_name" in json_config:
config += "--local_name "+json_config["local_name"]+" "
if "remote_ip" in json_config:
config += "--remote_ip "+json_config["remote_ip"]+" "
if "remote_port" in json_config:
config += "--remote_port "+str(json_config["remote_port"])+" "
if "remote_name" in json_config:
config += "--remote_name "+json_config["remote_name"]+" "
if "send_period" in json_config:
config += "--send_period "+str(json_config["send_period"])+" "
return config.strip()
retrieve_config()

Wyświetl plik

@ -0,0 +1,194 @@
#!/usr/bin/python
#coding: utf-8
'''In our topology, we assume the container running this script has ip address 10.10.10.10
(useful information according to our topology: useless otherwise)
'''
from flask import Flask, jsonify
app = Flask(__name__)
SVR_IP = '10.0.0.1' #name = srv
GWI1_IP = '10.2.2.1' #name = gwi1
GWI2_IP = '10.2.2.2' #name = gwi2 (dc)
GWF1_IP = '10.0.1.100' #name = gwf1
DEV1_GWF1_IP = '10.0.1.1' #name = dev1gwf1
DEV2_GWF1_IP = '10.0.1.2' #name = dev2gwf1
DEV3_GWF1_IP = '10.0.1.3' #name = dev3gwf1
GWF2_IP = '10.0.2.100' #name = gwf2
DEV1_GWF2_IP = '10.0.2.1' #name = dev1gwf2
DEV2_GWF2_IP = '10.0.2.2' #name = dev2gwf2
DEV3_GWF2_IP = '10.0.2.3' #name = dev3gwf2
GWF3_IP = '10.0.3.100' #name = gwf3
DEV1_GWF3_IP = '10.0.3.1' #name = dev1gwf3
DEV2_GWF3_IP = '10.0.3.2' #name = dev2gwf3
DEV3_GWF3_IP = '10.0.3.3' #name = dev3gwf3
'''
Formats of configs:
SERVER = "--local_ip 127.0.0.1 --local_port 8080 --local_name %s"
GATEWAY_I = "--local_ip 127.0.0.1 --local_port 8181 --local_name %s --remote_ip %s --remote_port 8080 --remote_name %s"
GATEWAY_F = "--local_ip 127.0.0.1 --local_port 8282 --local_name %s --remote_ip %s --remote_port 8181 --remote_name %s"
DEV = "--local_ip 127.0.0.1 --local_port 9001 --local_name %s --remote_ip %s --remote_port 8282 --remote_name %s --send_period 3000"
'''
SVR_READY = False
GWI1_READY = False
GWI2_READY = False
GWF1_READY = False
GWF2_READY = False
GWF3_READY = False
@app.route("/getmyconfig/<string:my_ip>")
def configurations_giver(my_ip="127.0.0.1"):
global SVR_READY
global GWI1_READY
global GWI2_READY
global GWF1_READY
global GWF2_READY
global GWF3_READY
configs = {"local_ip":my_ip, "verdict":"oops"}
if my_ip==SVR_IP:
configs["local_port"] = 8080
configs["local_name"] = "srv"
configs["verdict"] = "yes"
SVR_READY = True
elif my_ip==GWI1_IP:
if SVR_READY:
configs["local_port"] = 8181
configs["local_name"] = "gwi1"
configs["remote_ip"] = SVR_IP
configs["remote_port"] = 8080
configs["remote_name"] = "srv"
configs["verdict"] = "yes"
GWI1_READY = True
elif my_ip==GWF1_IP:
if GWI1_READY:
configs["local_port"] = 8282
configs["local_name"] = "gwf1"
configs["remote_ip"] = GWI1_IP
configs["remote_port"] = 8181
configs["remote_name"] = "gwi1"
configs["verdict"] = "yes"
GWF1_READY = True
elif my_ip==GWF2_IP:
if GWI1_READY:
configs["local_port"] = 8282
configs["local_name"] = "gwf2"
configs["remote_ip"] = GWI1_IP
configs["remote_port"] = 8181
configs["remote_name"] = "gwi1"
configs["verdict"] = "yes"
GWF2_READY = True
elif my_ip==GWF3_IP:
if GWI1_READY:
configs["local_port"] = 8282
configs["local_name"] = "gwf3"
configs["remote_ip"] = GWI1_IP
configs["remote_port"] = 8181
configs["remote_name"] = "gwi1"
configs["verdict"] = "yes"
GWF3_READY = True
elif my_ip==DEV1_GWF1_IP:
if GWF1_READY:
configs["local_port"] = 9001
configs["local_name"] = "dev1gwf1"
configs["remote_ip"] = GWF1_IP
configs["remote_port"] = 8282
configs["remote_name"] = "gwf1"
configs["send_period"] = 3000
configs["verdict"] = "yes"
elif my_ip==DEV2_GWF1_IP:
if GWF1_READY:
configs["local_port"] = 9001
configs["local_name"] = "dev2gwf1"
configs["remote_ip"] = GWF1_IP
configs["remote_port"] = 8282
configs["remote_name"] = "gwf1"
configs["send_period"] = 3000
configs["verdict"] = "yes"
elif my_ip==DEV3_GWF1_IP:
if GWF1_READY:
configs["local_port"] = 9001
configs["local_name"] = "dev3gwf1"
configs["remote_ip"] = GWF1_IP
configs["remote_port"] = 8282
configs["remote_name"] = "gwf1"
configs["send_period"] = 3000
configs["verdict"] = "yes"
elif my_ip==DEV1_GWF2_IP:
if GWF2_READY:
configs["local_port"] = 9001
configs["local_name"] = "dev1gwf2"
configs["remote_ip"] = GWF2_IP
configs["remote_port"] = 8282
configs["remote_name"] = "gwf2"
configs["send_period"] = 3000
configs["verdict"] = "yes"
elif my_ip==DEV2_GWF2_IP:
if GWF2_READY:
configs["local_port"] = 9001
configs["local_name"] = "dev2gwf2"
configs["remote_ip"] = GWF2_IP
configs["remote_port"] = 8282
configs["remote_name"] = "gwf2"
configs["send_period"] = 3000
configs["verdict"] = "yes"
elif my_ip==DEV3_GWF2_IP:
if GWF2_READY:
configs["local_port"] = 9001
configs["local_name"] = "dev3gwf2"
configs["remote_ip"] = GWF2_IP
configs["remote_port"] = 8282
configs["remote_name"] = "gwf2"
configs["send_period"] = 3000
configs["verdict"] = "yes"
elif my_ip==DEV1_GWF3_IP:
if GWF3_READY:
configs["local_port"] = 9001
configs["local_name"] = "dev1gwf3"
configs["remote_ip"] = GWF3_IP
configs["remote_port"] = 8282
configs["remote_name"] = "gwf3"
configs["send_period"] = 3000
configs["verdict"] = "yes"
elif my_ip==DEV2_GWF3_IP:
if GWF3_READY:
configs["local_port"] = 9001
configs["local_name"] = "dev2gwf3"
configs["remote_ip"] = GWF3_IP
configs["remote_port"] = 8282
configs["remote_name"] = "gwf3"
configs["send_period"] = 3000
configs["verdict"] = "yes"
elif my_ip==DEV3_GWF3_IP:
if GWF3_READY:
configs["local_port"] = 9001
configs["local_name"] = "dev3gwf3"
configs["remote_ip"] = GWF3_IP
configs["remote_port"] = 8282
configs["remote_name"] = "gwf3"
configs["send_period"] = 3000
configs["verdict"] = "yes"
return jsonify(configs)
@app.route("/getmyconfig/")
def configurations_giver_to_dc():
global GWI2_READY
configs = {"local_ip":GWI2_IP, "verdict":"oops"}
if SVR_READY:
configs["local_port"] = 8181
configs["local_name"] = "gwi2"
configs["remote_ip"] = SVR_IP
configs["remote_port"] = 8080
configs["remote_name"] = "srv"
configs["verdict"] = "yes"
GWI2_READY = True
return jsonify(configs)
if __name__=='__main__':
app.run(debug=False, host='0.0.0.0', port=5555)

Wyświetl plik

@ -0,0 +1,28 @@
# Choosing the image to use
FROM node:buster
# Installing required libraries
RUN apt-get update && \
apt-get install -y net-tools iputils-ping python-pip && \
pip install flask && \
pip install requests && \
mkdir mydir && \
cd mydir && \
npm install express && \
npm install yargs && \
npm install systeminformation && \
npm install request
COPY device.js /mydir
COPY bootstrap_client.py /mydir
SHELL ["/bin/bash", "-c"]
RUN echo "nohup python /mydir/bootstrap_client.py &" > start.sh && \
echo "/bin/bash" >> start.sh && \
chmod 777 start.sh
# Mandatory entrypoint in containernet
ENTRYPOINT ./start.sh

Wyświetl plik

@ -0,0 +1,52 @@
#!/usr/bin/python
#coding: utf-8
import os
import subprocess
import requests
from time import sleep
BOOTSTRAP_SERVER_ADDRESS = '10.10.10.10:5555'
def retrieve_config():
my_json_config = {"verdict":"oops"}
my_ip = str(subprocess.check_output("echo $MY_IP", shell=True)).rstrip()
print("MY_IP : %s"%(my_ip))
while my_json_config["verdict"] != "yes":
try:
resp = requests.get("http://%s/getmyconfig/%s"%(BOOTSTRAP_SERVER_ADDRESS, my_ip), timeout=2)
except:
print("Unable to join the bootstrap server")
try:
my_json_config = resp.json()
print("Extracted configs [succ] : %s"%(my_json_config))
except:
print("Unable to extract configs from bootstrap server's answer")
print("Extracted configs [fail] : %s"%(my_json_config))
print("request url : ==>%s<=="%("http://%s/getmyconfig/%s"%(BOOTSTRAP_SERVER_ADDRESS, my_ip)))
if "verdict" in my_json_config and my_json_config["verdict"] == "yes":
my_config = config_json_to_string(my_json_config)
subprocess.check_output("node /mydir/*.js %s"%(my_config), shell=True)
else:
my_json_config = {"verdict":"oops"}
sleep(3)
def config_json_to_string(json_config):
config = ""
if "local_ip" in json_config:
config += "--local_ip "+json_config["local_ip"]+" "
if "local_port" in json_config:
config += "--local_port "+str(json_config["local_port"])+" "
if "local_name" in json_config:
config += "--local_name "+json_config["local_name"]+" "
if "remote_ip" in json_config:
config += "--remote_ip "+json_config["remote_ip"]+" "
if "remote_port" in json_config:
config += "--remote_port "+str(json_config["remote_port"])+" "
if "remote_name" in json_config:
config += "--remote_name "+json_config["remote_name"]+" "
if "send_period" in json_config:
config += "--send_period "+str(json_config["send_period"])+" "
return config.strip()
retrieve_config()

Wyświetl plik

@ -0,0 +1,53 @@
var express = require('express')
var app = express()
var request = require('request');
var argv = require('yargs').argv;
// --local_ip
// --local_port
// --local_name
// --remote_ip
// --remote_port
// --remote_name
// --send_period
var LOCAL_ENDPOINT = {IP : argv.local_ip, PORT : argv.local_port, NAME : argv.local_name};
var REMOTE_ENDPOINT = {IP : argv.remote_ip, PORT : argv.remote_port, NAME : argv.remote_name};
var DATA_PERIOD = argv.send_period;
function doPOST(uri, body, onResponse) {
request({method: 'POST', uri: uri, json : body}, onResponse);
}
function register() {
doPOST(
'http://' + REMOTE_ENDPOINT.IP + ':' + REMOTE_ENDPOINT.PORT + '/devices/register',
{
Name : LOCAL_ENDPOINT.NAME,
PoC : 'http://' + LOCAL_ENDPOINT.IP + ':' + LOCAL_ENDPOINT.PORT,
},
function(error, response, respBody) {
console.log(respBody);
}
);
}
var dataItem = 0;
function sendData() {
doPOST(
'http://' + REMOTE_ENDPOINT.IP + ':' + REMOTE_ENDPOINT.PORT + '/device/'+ LOCAL_ENDPOINT.NAME + '/data',
{
Name : LOCAL_ENDPOINT.NAME,
Data : dataItem++,
Time : Date.now(),
},
function(error, response, respBody) {
console.log(respBody);
}
);
}
register();
setInterval(sendData, DATA_PERIOD);

Wyświetl plik

@ -0,0 +1,28 @@
# Choosing the image to use
FROM node:buster
# Installing required libraries
RUN apt-get update && \
apt-get install -y net-tools iputils-ping python-pip && \
pip install flask && \
pip install requests && \
mkdir mydir && \
cd mydir && \
npm install express && \
npm install yargs && \
npm install systeminformation && \
npm install request
COPY gateway.js /mydir
COPY bootstrap_client.py /mydir
SHELL ["/bin/bash", "-c"]
RUN echo "nohup python /mydir/bootstrap_client.py &" > start.sh && \
echo "/bin/bash" >> start.sh && \
chmod 777 start.sh
# Mandatory entrypoint in containernet
ENTRYPOINT ./start.sh

Wyświetl plik

@ -0,0 +1,52 @@
#!/usr/bin/python
#coding: utf-8
import os
import subprocess
import requests
from time import sleep
BOOTSTRAP_SERVER_ADDRESS = '10.10.10.10:5555'
def retrieve_config():
my_json_config = {"verdict":"oops"}
my_ip = str(subprocess.check_output("echo $MY_IP", shell=True)).rstrip()
print("MY_IP : %s"%(my_ip))
while my_json_config["verdict"] != "yes":
try:
resp = requests.get("http://%s/getmyconfig/%s"%(BOOTSTRAP_SERVER_ADDRESS, my_ip), timeout=2)
except:
print("Unable to join the bootstrap server")
try:
my_json_config = resp.json()
print("Extracted configs [succ] : %s"%(my_json_config))
except:
print("Unable to extract configs from bootstrap server's answer")
print("Extracted configs [fail] : %s"%(my_json_config))
print("request url : ==>%s<=="%("http://%s/getmyconfig/%s"%(BOOTSTRAP_SERVER_ADDRESS, my_ip)))
if "verdict" in my_json_config and my_json_config["verdict"] == "yes":
my_config = config_json_to_string(my_json_config)
subprocess.check_output("node /mydir/*.js %s"%(my_config), shell=True)
else:
my_json_config = {"verdict":"oops"}
sleep(3)
def config_json_to_string(json_config):
config = ""
if "local_ip" in json_config:
config += "--local_ip "+json_config["local_ip"]+" "
if "local_port" in json_config:
config += "--local_port "+str(json_config["local_port"])+" "
if "local_name" in json_config:
config += "--local_name "+json_config["local_name"]+" "
if "remote_ip" in json_config:
config += "--remote_ip "+json_config["remote_ip"]+" "
if "remote_port" in json_config:
config += "--remote_port "+str(json_config["remote_port"])+" "
if "remote_name" in json_config:
config += "--remote_name "+json_config["remote_name"]+" "
if "send_period" in json_config:
config += "--send_period "+str(json_config["send_period"])+" "
return config.strip()
retrieve_config()

Wyświetl plik

@ -0,0 +1,127 @@
var express = require('express')
var app = express()
app.use(express.json()) // for parsing application/json
var request = require('request');
const si = require('systeminformation');
var argv = require('yargs').argv;
// --local_ip
// --local_port
// --local_name
// --remote_ip
// --remote_port
// --remote_name
var LOCAL_ENDPOINT = {IP : argv.local_ip, PORT : argv.local_port, NAME : argv.local_name};
var REMOTE_ENDPOINT = {IP : argv.remote_ip, PORT : argv.remote_port, NAME : argv.remote_name};
const E_OK = 200;
const E_CREATED = 201;
const E_FORBIDDEN = 403;
const E_NOT_FOUND = 404;
const E_ALREADY_EXIST = 500;
var db = {
gateways : new Map()
};
function addNewGateway(gw) {
var res = -1;
if (!db.gateways.get(gw.Name)) {
db.gateways.set(gw.Name, gw);
res = 0;
}
return res;
}
function removeGateway(gw) {
if (db.gateways.get(gw.Name))
db.gateways.delete(gw.Name);
}
function doPOST(uri, body, onResponse) {
request({method: 'POST', uri: uri, json : body}, onResponse);
}
function register() {
doPOST(
'http://' + REMOTE_ENDPOINT.IP + ':' + REMOTE_ENDPOINT.PORT + '/gateways/register',
{
Name : LOCAL_ENDPOINT.NAME,
PoC : 'http://' + LOCAL_ENDPOINT.IP + ':' + LOCAL_ENDPOINT.PORT,
},
function(error, response, respBody) {
console.log(respBody);
}
);
}
app.post('/gateways/register', function(req, res) {
console.log(req.body);
var result = addNewGateway(req.body);
if (result === 0)
res.sendStatus(E_CREATED);
else
res.sendStatus(E_ALREADY_EXIST);
});
app.post('/devices/register', function(req, res) {
console.log(req.body);
doPOST(
'http://' + REMOTE_ENDPOINT.IP + ':' +REMOTE_ENDPOINT.PORT + '/devices/register',
req.body,
function(error, response, respBody) {
console.log(respBody);
res.sendStatus(E_OK);
}
)
});
app.post('/device/:dev/data', function(req, res) {
console.log(req.body);
var dev = req.params.dev;
doPOST(
'http://' + REMOTE_ENDPOINT.IP + ':' +REMOTE_ENDPOINT.PORT + '/device/' + dev + '/data',
req.body,
function(error, response, respBody) {
console.log(respBody);
res.sendStatus(E_OK);
}
)
});
app.get('/gateways', function(req, res) {
console.log(req.body);
let resObj = [];
db.gateways.forEach((v,k) => {
resObj.push(v);
});
res.send(resObj);
});
app.get('/gateway/:gw', function(req, res) {
console.log(req.body);
var gw = req.params.gw;
var gateway = db.gateways.get(gw);
if (gateway)
res.status(E_OK).send(JSON.stringify(gateway));
else
res.sendStatus(E_NOT_FOUND);
});
app.get('/ping', function(req, res) {
console.log(req.body);
res.status(E_OK).send({pong: Date.now()});
});
app.get('/health', function(req, res) {
console.log(req.body);
si.currentLoad((d) => {
console.log(d);
res.status(E_OK).send(JSON.stringify(d));
})
});
register();
app.listen(LOCAL_ENDPOINT.PORT , function () {
console.log(LOCAL_ENDPOINT.NAME + ' listening on : ' + LOCAL_ENDPOINT.PORT );
});

Wyświetl plik

@ -0,0 +1,28 @@
# Choosing the image to use
FROM node:buster
# Installing required libraries
RUN apt-get update && \
apt-get install -y net-tools iputils-ping python-pip && \
pip install flask && \
pip install requests && \
mkdir mydir && \
cd mydir && \
npm install express && \
npm install yargs && \
npm install systeminformation && \
npm install request
COPY server.js /mydir
COPY bootstrap_client.py /mydir
SHELL ["/bin/bash", "-c"]
RUN echo "nohup python /mydir/bootstrap_client.py &" > start.sh && \
echo "/bin/bash" >> start.sh && \
chmod 777 start.sh
# Mandatory entrypoint in containernet
ENTRYPOINT ./start.sh

Wyświetl plik

@ -0,0 +1,52 @@
#!/usr/bin/python
#coding: utf-8
import os
import subprocess
import requests
from time import sleep
BOOTSTRAP_SERVER_ADDRESS = '10.10.10.10:5555'
def retrieve_config():
my_json_config = {"verdict":"oops"}
my_ip = str(subprocess.check_output("echo $MY_IP", shell=True)).rstrip()
print("MY_IP : %s"%(my_ip))
while my_json_config["verdict"] != "yes":
try:
resp = requests.get("http://%s/getmyconfig/%s"%(BOOTSTRAP_SERVER_ADDRESS, my_ip), timeout=2)
except:
print("Unable to join the bootstrap server")
try:
my_json_config = resp.json()
print("Extracted configs [succ] : %s"%(my_json_config))
except:
print("Unable to extract configs from bootstrap server's answer")
print("Extracted configs [fail] : %s"%(my_json_config))
print("request url : ==>%s<=="%("http://%s/getmyconfig/%s"%(BOOTSTRAP_SERVER_ADDRESS, my_ip)))
if "verdict" in my_json_config and my_json_config["verdict"] == "yes":
my_config = config_json_to_string(my_json_config)
subprocess.check_output("node /mydir/*.js %s"%(my_config), shell=True)
else:
my_json_config = {"verdict":"oops"}
sleep(3)
def config_json_to_string(json_config):
config = ""
if "local_ip" in json_config:
config += "--local_ip "+json_config["local_ip"]+" "
if "local_port" in json_config:
config += "--local_port "+str(json_config["local_port"])+" "
if "local_name" in json_config:
config += "--local_name "+json_config["local_name"]+" "
if "remote_ip" in json_config:
config += "--remote_ip "+json_config["remote_ip"]+" "
if "remote_port" in json_config:
config += "--remote_port "+str(json_config["remote_port"])+" "
if "remote_name" in json_config:
config += "--remote_name "+json_config["remote_name"]+" "
if "send_period" in json_config:
config += "--send_period "+str(json_config["send_period"])+" "
return config.strip()
retrieve_config()

Wyświetl plik

@ -0,0 +1,167 @@
var express = require('express')
var app = express()
app.use(express.json())
var argv = require('yargs').argv;
// --local_ip
// --local_port
// --local_name
const si = require('systeminformation');
var LOCAL_ENDPOINT = {IP : argv.local_ip, PORT : argv.local_port, NAME : argv.local_name};
const E_OK = 200;
const E_CREATED = 201;
const E_FORBIDDEN = 403;
const E_NOT_FOUND = 404;
const E_ALREADY_EXIST = 500;
var db = {
devices : new Map(),
data : new Map(),
gateways : new Map()
};
function addNewDevice(dev) {
var result = -1;
if (!db.devices.get(dev.Name)) {
db.devices.set(dev.Name, dev);
if (db.devices.get(dev.Name))
db.data.delete(dev.Name);
db.data.set(dev.Name, []);
result = 0;
}
return result;
}
function addNewGateway(gw) {
var result = -1;
if (!db.gateways.get(gw.Name)) {
db.gateways.set(gw.Name, gw);
result = 0;
}
return result;
}
function removeDevice(dev) {
if (db.devices.get(dev.Name)) {
db.devices.delete(dev.Name);
if (db.devices.get(dev.Name))
db.data.delete(dev.Name);
}
}
function removeGateway(gw) {
if (db.gateways.get(gw.Name))
db.gateways.delete(gw.Name);
}
function addDeviceData(dev, data) {
var result = -1;
var device = db.devices.get(dev);
if (device) {
db.data.get(dev).push(data);
result = 0;
}
return result;
}
app.get('/devices', function(req, res) {
console.log(req.body);
let resObj = [];
db.devices.forEach((v,k) => {
resObj.push(v);
});
res.status(E_OK).send(resObj);
});
app.get('/device/:dev', function(req, res) {
console.log(req.body);
var dev = req.params.dev;
var device = db.devices.get(dev);
if (device)
res.status(E_OK).send(JSON.stringify(device));
else
res.sendStatus(E_NOT_FOUND);
});
app.post('/device/:dev/data', function(req, res) {
console.log(req.body);
var dev = req.params.dev;
var result = addDeviceData(dev, req.body);
if (result === 0)
res.sendStatus(E_CREATED);
else
res.sendStatus(E_NOT_FOUND);
});
app.get('/device/:dev/data', function(req, res) {
console.log(req.body);
var dev = req.params.dev;
var device = db.devices.get(dev);
if (device){
var data = db.data.get(dev);
if (data) {
let resObj = [];
data.forEach((v,k) => {
resObj.push(v);
});
res.status(E_OK).send(JSON.stringify(resObj));
}
else
res.sendStatus(E_NOT_FOUND);
}
else
res.sendStatus(E_NOT_FOUND);
});
app.post('/devices/register', function(req, res) {
console.log(req.body);
var result = addNewDevice(req.body);
if ( result === 0)
res.sendStatus(E_CREATED);
else
res.sendStatus(E_ALREADY_EXIST);
});
app.get('/gateways', function(req, res) {
console.log(req.body);
let resObj = [];
db.gateways.forEach((v,k) => {
resObj.push(v);
});
res.send(resObj);
});
app.get('/gateway/:gw', function(req, res) {
console.log(req.body);
var gw = req.params.gw;
var gateway = db.gateways.get(gw);
if (gateway)
res.status(E_OK).send(JSON.stringify(gateway));
else
res.sendStatus(E_NOT_FOUND);
});
app.post('/gateways/register', function(req, res) {
console.log(req.body);
var result = addNewGateway(req.body);
if ( result === 0)
res.sendStatus(E_CREATED);
else
res.sendStatus(E_ALREADY_EXIST);
});
app.get('/ping', function(req, res) {
console.log(req.body);
res.status(E_OK).send({pong: Date.now()});
});
app.get('/health', function(req, res) {
console.log(req.body);
si.currentLoad((d) => {
console.log(d);
res.status(E_OK).send(JSON.stringify(d));
})
});
app.listen(LOCAL_ENDPOINT.PORT , function () {
console.log(LOCAL_ENDPOINT.NAME + ' listening on : ' + LOCAL_ENDPOINT.PORT );
});

Plik binarny nie jest wyświetlany.

2
jsfiles/README.md Normal file
Wyświetl plik

@ -0,0 +1,2 @@
# icds

53
jsfiles/device.js Normal file
Wyświetl plik

@ -0,0 +1,53 @@
var express = require('express')
var app = express()
var request = require('request');
var argv = require('yargs').argv;
// --local_ip
// --local_port
// --local_name
// --remote_ip
// --remote_port
// --remote_name
// --send_period
var LOCAL_ENDPOINT = {IP : argv.local_ip, PORT : argv.local_port, NAME : argv.local_name};
var REMOTE_ENDPOINT = {IP : argv.remote_ip, PORT : argv.remote_port, NAME : argv.remote_name};
var DATA_PERIOD = argv.send_period;
function doPOST(uri, body, onResponse) {
request({method: 'POST', uri: uri, json : body}, onResponse);
}
function register() {
doPOST(
'http://' + REMOTE_ENDPOINT.IP + ':' + REMOTE_ENDPOINT.PORT + '/devices/register',
{
Name : LOCAL_ENDPOINT.NAME,
PoC : 'http://' + LOCAL_ENDPOINT.IP + ':' + LOCAL_ENDPOINT.PORT,
},
function(error, response, respBody) {
console.log(respBody);
}
);
}
var dataItem = 0;
function sendData() {
doPOST(
'http://' + REMOTE_ENDPOINT.IP + ':' + REMOTE_ENDPOINT.PORT + '/device/'+ LOCAL_ENDPOINT.NAME + '/data',
{
Name : LOCAL_ENDPOINT.NAME,
Data : dataItem++,
Time : Date.now(),
},
function(error, response, respBody) {
console.log(respBody);
}
);
}
register();
setInterval(sendData, DATA_PERIOD);

127
jsfiles/gateway.js Normal file
Wyświetl plik

@ -0,0 +1,127 @@
var express = require('express')
var app = express()
app.use(express.json()) // for parsing application/json
var request = require('request');
const si = require('systeminformation');
var argv = require('yargs').argv;
// --local_ip
// --local_port
// --local_name
// --remote_ip
// --remote_port
// --remote_name
var LOCAL_ENDPOINT = {IP : argv.local_ip, PORT : argv.local_port, NAME : argv.local_name};
var REMOTE_ENDPOINT = {IP : argv.remote_ip, PORT : argv.remote_port, NAME : argv.remote_name};
const E_OK = 200;
const E_CREATED = 201;
const E_FORBIDDEN = 403;
const E_NOT_FOUND = 404;
const E_ALREADY_EXIST = 500;
var db = {
gateways : new Map()
};
function addNewGateway(gw) {
var res = -1;
if (!db.gateways.get(gw.Name)) {
db.gateways.set(gw.Name, gw);
res = 0;
}
return res;
}
function removeGateway(gw) {
if (db.gateways.get(gw.Name))
db.gateways.delete(gw.Name);
}
function doPOST(uri, body, onResponse) {
request({method: 'POST', uri: uri, json : body}, onResponse);
}
function register() {
doPOST(
'http://' + REMOTE_ENDPOINT.IP + ':' + REMOTE_ENDPOINT.PORT + '/gateways/register',
{
Name : LOCAL_ENDPOINT.NAME,
PoC : 'http://' + LOCAL_ENDPOINT.IP + ':' + LOCAL_ENDPOINT.PORT,
},
function(error, response, respBody) {
console.log(respBody);
}
);
}
app.post('/gateways/register', function(req, res) {
console.log(req.body);
var result = addNewGateway(req.body);
if (result === 0)
res.sendStatus(E_CREATED);
else
res.sendStatus(E_ALREADY_EXIST);
});
app.post('/devices/register', function(req, res) {
console.log(req.body);
doPOST(
'http://' + REMOTE_ENDPOINT.IP + ':' +REMOTE_ENDPOINT.PORT + '/devices/register',
req.body,
function(error, response, respBody) {
console.log(respBody);
res.sendStatus(E_OK);
}
)
});
app.post('/device/:dev/data', function(req, res) {
console.log(req.body);
var dev = req.params.dev;
doPOST(
'http://' + REMOTE_ENDPOINT.IP + ':' +REMOTE_ENDPOINT.PORT + '/device/' + dev + '/data',
req.body,
function(error, response, respBody) {
console.log(respBody);
res.sendStatus(E_OK);
}
)
});
app.get('/gateways', function(req, res) {
console.log(req.body);
let resObj = [];
db.gateways.forEach((v,k) => {
resObj.push(v);
});
res.send(resObj);
});
app.get('/gateway/:gw', function(req, res) {
console.log(req.body);
var gw = req.params.gw;
var gateway = db.gateways.get(gw);
if (gateway)
res.status(E_OK).send(JSON.stringify(gateway));
else
res.sendStatus(E_NOT_FOUND);
});
app.get('/ping', function(req, res) {
console.log(req.body);
res.status(E_OK).send({pong: Date.now()});
});
app.get('/health', function(req, res) {
console.log(req.body);
si.currentLoad((d) => {
console.log(d);
res.status(E_OK).send(JSON.stringify(d));
})
});
register();
app.listen(LOCAL_ENDPOINT.PORT , function () {
console.log(LOCAL_ENDPOINT.NAME + ' listening on : ' + LOCAL_ENDPOINT.PORT );
});

167
jsfiles/server.js Normal file
Wyświetl plik

@ -0,0 +1,167 @@
var express = require('express')
var app = express()
app.use(express.json())
var argv = require('yargs').argv;
// --local_ip
// --local_port
// --local_name
const si = require('systeminformation');
var LOCAL_ENDPOINT = {IP : argv.local_ip, PORT : argv.local_port, NAME : argv.local_name};
const E_OK = 200;
const E_CREATED = 201;
const E_FORBIDDEN = 403;
const E_NOT_FOUND = 404;
const E_ALREADY_EXIST = 500;
var db = {
devices : new Map(),
data : new Map(),
gateways : new Map()
};
function addNewDevice(dev) {
var result = -1;
if (!db.devices.get(dev.Name)) {
db.devices.set(dev.Name, dev);
if (db.devices.get(dev.Name))
db.data.delete(dev.Name);
db.data.set(dev.Name, []);
result = 0;
}
return result;
}
function addNewGateway(gw) {
var result = -1;
if (!db.gateways.get(gw.Name)) {
db.gateways.set(gw.Name, gw);
result = 0;
}
return result;
}
function removeDevice(dev) {
if (db.devices.get(dev.Name)) {
db.devices.delete(dev.Name);
if (db.devices.get(dev.Name))
db.data.delete(dev.Name);
}
}
function removeGateway(gw) {
if (db.gateways.get(gw.Name))
db.gateways.delete(gw.Name);
}
function addDeviceData(dev, data) {
var result = -1;
var device = db.devices.get(dev);
if (device) {
db.data.get(dev).push(data);
result = 0;
}
return result;
}
app.get('/devices', function(req, res) {
console.log(req.body);
let resObj = [];
db.devices.forEach((v,k) => {
resObj.push(v);
});
res.status(E_OK).send(resObj);
});
app.get('/device/:dev', function(req, res) {
console.log(req.body);
var dev = req.params.dev;
var device = db.devices.get(dev);
if (device)
res.status(E_OK).send(JSON.stringify(device));
else
res.sendStatus(E_NOT_FOUND);
});
app.post('/device/:dev/data', function(req, res) {
console.log(req.body);
var dev = req.params.dev;
var result = addDeviceData(dev, req.body);
if (result === 0)
res.sendStatus(E_CREATED);
else
res.sendStatus(E_NOT_FOUND);
});
app.get('/device/:dev/data', function(req, res) {
console.log(req.body);
var dev = req.params.dev;
var device = db.devices.get(dev);
if (device){
var data = db.data.get(dev);
if (data) {
let resObj = [];
data.forEach((v,k) => {
resObj.push(v);
});
res.status(E_OK).send(JSON.stringify(resObj));
}
else
res.sendStatus(E_NOT_FOUND);
}
else
res.sendStatus(E_NOT_FOUND);
});
app.post('/devices/register', function(req, res) {
console.log(req.body);
var result = addNewDevice(req.body);
if ( result === 0)
res.sendStatus(E_CREATED);
else
res.sendStatus(E_ALREADY_EXIST);
});
app.get('/gateways', function(req, res) {
console.log(req.body);
let resObj = [];
db.gateways.forEach((v,k) => {
resObj.push(v);
});
res.send(resObj);
});
app.get('/gateway/:gw', function(req, res) {
console.log(req.body);
var gw = req.params.gw;
var gateway = db.gateways.get(gw);
if (gateway)
res.status(E_OK).send(JSON.stringify(gateway));
else
res.sendStatus(E_NOT_FOUND);
});
app.post('/gateways/register', function(req, res) {
console.log(req.body);
var result = addNewGateway(req.body);
if ( result === 0)
res.sendStatus(E_CREATED);
else
res.sendStatus(E_ALREADY_EXIST);
});
app.get('/ping', function(req, res) {
console.log(req.body);
res.status(E_OK).send({pong: Date.now()});
});
app.get('/health', function(req, res) {
console.log(req.body);
si.currentLoad((d) => {
console.log(d);
res.status(E_OK).send(JSON.stringify(d));
})
});
app.listen(LOCAL_ENDPOINT.PORT , function () {
console.log(LOCAL_ENDPOINT.NAME + ' listening on : ' + LOCAL_ENDPOINT.PORT );
});

191
topologie/topology.py Plik wykonywalny
Wyświetl plik

@ -0,0 +1,191 @@
#!/usr/bin/python
# Copyright (c) 2020 INSA Toulouse
# ALL RIGHTS RESERVED.
#
# This topology has been built by inspiring on the 'default_single_dc_topology.py' example of son-emu
#
# Authors
# Abdel Kader CHABI SIKA BONI (Master2 ILoRD at INSA Toulouse, chabisik@etud.insa-toulouse.fr)
# Arnaud PRIEU (5SDBD at INSA Toulouse, prieu@etud.insa-toulouse.fr)
# Year: 2020-2021
import logging
from mininet.log import setLogLevel, info
from emuvim.dcemulator.net import DCNetwork
from emuvim.api.rest.rest_api_endpoint import RestApiEndpoint
from emuvim.api.openstack.openstack_api_endpoint import OpenstackApiEndpoint
logging.basicConfig(level=logging.INFO)
setLogLevel('info') # set Mininet loglevel
logging.getLogger('werkzeug').setLevel(logging.DEBUG)
logging.getLogger('api.openstack.base').setLevel(logging.DEBUG)
logging.getLogger('api.openstack.compute').setLevel(logging.DEBUG)
logging.getLogger('api.openstack.keystone').setLevel(logging.DEBUG)
logging.getLogger('api.openstack.nova').setLevel(logging.DEBUG)
logging.getLogger('api.openstack.neutron').setLevel(logging.DEBUG)
logging.getLogger('api.openstack.heat').setLevel(logging.DEBUG)
logging.getLogger('api.openstack.heat.parser').setLevel(logging.DEBUG)
logging.getLogger('api.openstack.glance').setLevel(logging.DEBUG)
logging.getLogger('api.openstack.helper').setLevel(logging.DEBUG)
#####################################################################################################
# OUR TOPOLOGY'S DETAILS #
# (if changed, bootstrap server script must be changed too and the new config:topo image builded) #
#####################################################################################################
BOOTSTRAP_SERVER = '10.10.10.10' #name = btrap; port = 5555
SVR_IP = '10.0.0.1' #name = srv
GWI1_IP = '10.2.2.1' #name = gwi1
GWI2_IP = '10.2.2.2' #name = gwi2
GWF1_IP = '10.0.1.100' #name = gwf1
DEV1_GWF1_IP = '10.0.1.1' #name = dev1gwf1
DEV2_GWF1_IP = '10.0.1.2' #name = dev2gwf1
DEV3_GWF1_IP = '10.0.1.3' #name = dev3gwf1
GWF2_IP = '10.0.2.100' #name = gwf2
DEV1_GWF2_IP = '10.0.2.1' #name = dev1gwf2
DEV2_GWF2_IP = '10.0.2.2' #name = dev2gwf2
DEV3_GWF2_IP = '10.0.2.3' #name = dev3gwf2
GWF3_IP = '10.0.3.100' #name = gwf3
DEV1_GWF3_IP = '10.0.3.1' #name = dev1gwf3
DEV2_GWF3_IP = '10.0.3.2' #name = dev2gwf3
DEV3_GWF3_IP = '10.0.3.3' #name = dev3gwf3
'''
TOPOLOGY OVERVIEW
Necessary docker images: config:topo ; server:topo ; gateway:topo ; device:topo
++++++++ ++++++++
+ dev1 +--- + gwf1 +
++++++++ | ++++++++
| | ______________++++++++
| | | + dev2 +
++++++++ | ++++++++ ++++++++ ++++++++
+ gwi1 + |_______+ s5 +----------------------------+ dev3 +
++++++++ ++++++++ ++++++++ ++++++++
| | _____________________________________________+ gwf2 +
| | | ++++++++
+++++++ +++++++ +++++++ +++++++ ++++++++ ++++++++
+ srv +--------+ s1 +---------+ s2 +---------+ s3 +------+ s6 +--------------------+ dev1 +
+++++++ +++++++ +++++++ +++++++ ++++++++ ++++++++
| | | | | ++++++++
| | | | |_____________+ dev2 +
| | | | ++++++++
| | ++++++ | ++++++++
| | + s4 +---- |_____+ dev3 +
| | ++++++ | ++++++++
| +++++++++ | |
| + btrap + | |____++++++++ ++++++++
| +++++++++ ______| + s7 +--------+ dev1 +
| | ++++++++ ++++++++
| | ______________| | |
| ________| | | |
| | | | |___________++++++++
| | | | + dev2 +
| ++++++ | | ++++++++
|____________________________+ DC + ++++++++ ++++++++
++++++ + dev3 + + gwf3 +
++++++++ ++++++++
'''
#####################################################################################################
def create_topology():
net = DCNetwork(monitor=False, enable_learning=True)
dc1 = net.addDatacenter("dc1")
# add OpenStack-like APIs to the emulated DC
api1 = OpenstackApiEndpoint("0.0.0.0", 6001)
api1.connect_datacenter(dc1)
api1.start()
api1.connect_dc_network(net)
# add the command line interface endpoint to the emulated DC (REST API)
rapi1 = RestApiEndpoint("0.0.0.0", 5001)
rapi1.connectDCNetwork(net)
rapi1.connectDatacenter(dc1)
rapi1.start()
info('*** Adding bootstrap server\n')
btrap = net.addDocker('btrap', ip=BOOTSTRAP_SERVER, dimage="config:topo")
info('*** Adding topology server\n')
srv = net.addDocker('srv', ip=SVR_IP, dimage="server:topo", environment={'MY_IP':SVR_IP})
info('*** Adding topology intermediary gateway\n')
gwi1 = net.addDocker('gwi1', ip=GWI1_IP, dimage="gateway:topo", environment={'MY_IP':GWI1_IP})
info('*** Adding topology final gateways\n')
gwf1 = net.addDocker('gwf1', ip=GWF1_IP, dimage="gateway:topo", environment={'MY_IP':GWF1_IP})
gwf2 = net.addDocker('gwf2', ip=GWF2_IP, dimage="gateway:topo", environment={'MY_IP':GWF2_IP})
gwf3 = net.addDocker('gwf3', ip=GWF3_IP, dimage="gateway:topo", environment={'MY_IP':GWF3_IP})
info('*** Adding 1st final gateway devices\n')
dev1gwf1 = net.addDocker('dev1gwf1', ip=DEV1_GWF1_IP, dimage="device:topo", environment={'MY_IP':DEV1_GWF1_IP})
dev2gwf1 = net.addDocker('dev2gwf1', ip=DEV2_GWF1_IP, dimage="device:topo", environment={'MY_IP':DEV2_GWF1_IP})
dev3gwf1 = net.addDocker('dev3gwf1', ip=DEV3_GWF1_IP, dimage="device:topo", environment={'MY_IP':DEV3_GWF1_IP})
info('*** Adding 2nd final gateway devices\n')
dev1gwf2 = net.addDocker('dev1gwf2', ip=DEV1_GWF2_IP, dimage="device:topo", environment={'MY_IP':DEV1_GWF2_IP})
dev2gwf2 = net.addDocker('dev2gwf2', ip=DEV2_GWF2_IP, dimage="device:topo", environment={'MY_IP':DEV2_GWF2_IP})
dev3gwf2 = net.addDocker('dev3gwf2', ip=DEV3_GWF2_IP, dimage="device:topo", environment={'MY_IP':DEV3_GWF2_IP})
info('*** Adding 3rd final gateway devices\n')
dev1gwf3 = net.addDocker('dev1gwf3', ip=DEV1_GWF3_IP, dimage="device:topo", environment={'MY_IP':DEV1_GWF3_IP})
dev2gwf3 = net.addDocker('dev2gwf3', ip=DEV2_GWF3_IP, dimage="device:topo", environment={'MY_IP':DEV2_GWF3_IP})
dev3gwf3 = net.addDocker('dev3gwf3', ip=DEV3_GWF3_IP, dimage="device:topo", environment={'MY_IP':DEV3_GWF3_IP})
info('*** Adding switches\n')
s1 = net.addSwitch('s1')
s2 = net.addSwitch('s2')
s3 = net.addSwitch('s3')
s4 = net.addSwitch('s4')
s5 = net.addSwitch('s5')
s6 = net.addSwitch('s6')
s7 = net.addSwitch('s7')
info('*** Creating links\n')
net.addLink(btrap, s2)
net.addLink(s1, s2)
net.addLink(s1, srv)
net.addLink(gwi1, s2)
net.addLink(s2, s3)
net.addLink(s3, s4)
net.addLink(dc1, s4)
net.addLink(dc1, srv) #
########ZONE1###########
net.addLink(s3, s5)
net.addLink(gwf1, s5)
net.addLink(dev1gwf1, s5)
net.addLink(dev2gwf1, s5)
net.addLink(dev3gwf1, s5)
########ZONE2###########
net.addLink(s3, s6)
net.addLink(gwf2, s6)
net.addLink(dev1gwf2, s6)
net.addLink(dev2gwf2, s6)
net.addLink(dev3gwf2, s6)
########ZONE3###########
net.addLink(s4, s7)
net.addLink(gwf3, s7)
net.addLink(dev1gwf3, s7)
net.addLink(dev2gwf3, s7)
net.addLink(dev3gwf3, s7)
info('*** Starting network\n')
net.start()
net.CLI()
# when the user types exit in the CLI, we stop the emulator
net.stop()
def main():
create_topology()
if __name__ == '__main__':
main()