Browse Source

mise a jour

Abdel-Kader Chabi-Sika-Boni 3 years ago
parent
commit
2e5c05fff2

+ 34
- 0
Dockerfiles/API.txt View File

@@ -0,0 +1,34 @@
1
+SERVER
2
+GET /devices
3
+GET /device/:dev
4
+POST /device/:dev/data
5
+GET /device/:dev/data
6
+POST /devices/register
7
+GET /gateways
8
+GET /gateways/:gw
9
+POST /gateways/register
10
+GET /ping
11
+GET /health
12
+
13
+GATEWAY (Intermediary & Final)
14
+POST /gateways/register
15
+POST /devices/register
16
+POST /device/:dev/data
17
+GET /gateways
18
+GET /gateway/:gw
19
+GET /ping
20
+GET /health
21
+
22
+DEVICE
23
+---
24
+
25
+Data Format
26
+{ Name : LOCAL_ENDPOINT.NAME,
27
+  Data : dataItem++, //an integer incrementing everytime data is sent
28
+  Time : Date.now(), //the date (+hour) the data has been sent
29
+}
30
+
31
+Register Format
32
+{ Name : LOCAL_ENDPOINT.NAME, //the name of the entity which want to register itself
33
+  PoC : 'http://' + LOCAL_ENDPOINT.IP + ':' + LOCAL_ENDPOINT.PORT, //the address from which the registering entity can be joined
34
+}

+ 45
- 0
Dockerfiles/explanations.txt View File

@@ -0,0 +1,45 @@
1
+Test Architecture
2
+
3
+**********************
4
+* CONTAINER          *
5
+* IP = x.x.x.x       *
6
+*                    *
7
+* ++++++++++++++++++ *
8
+* + SERVER (srv)   + *
9
+* + IP = 127.0.0.1 + *
10
+* + PORT = 8080    + *
11
+* ++++++++++++++++++ *
12
+**********************
13
+          ||
14
+**********************
15
+* CONTAINER          *
16
+* IP = x.x.x.x       *
17
+*                    *
18
+* ++++++++++++++++++ *
19
+* + GATWEWAY (gwi) + *
20
+* + IP = 127.0.0.1 + *
21
+* + PORT = 8181    + *
22
+* ++++++++++++++++++ *
23
+**********************
24
+          ||
25
+**********************
26
+* CONTAINER          *
27
+* IP = x.x.x.x       *
28
+*                    *
29
+* ++++++++++++++++++ *
30
+* + GATEWAY (gwf1) + *
31
+* + IP = 127.0.0.1 + *
32
+* + PORT = 8282    + *
33
+* ++++++++++++++++++ *
34
+**********************
35
+          ||
36
+**********************
37
+* CONTAINER          *
38
+* IP = x.x.x.x       *
39
+*                    *
40
+* ++++++++++++++++++ *
41
+* + DEVICE (dev1)  + *
42
+* + IP = 127.0.0.1 + *
43
+* + PORT = 9001    + *
44
+* ++++++++++++++++++ *
45
+**********************

+ 23
- 0
Dockerfiles/forContainerNet/automatic_images_creation.sh View File

@@ -0,0 +1,23 @@
1
+#!/bin/bash
2
+
3
+# This script intend to delete existing images (if exists) and recreate them all
4
+# This script must be launch in root mode
5
+# This script must be launched from the 'forContainerNet' folder
6
+# 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)
7
+
8
+docker rmi config:topo
9
+docker rmi server:topo
10
+docker rmi gateway:topo
11
+docker rmi device:topo
12
+
13
+cd bootserver
14
+docker build -t config:topo .
15
+
16
+cd ../server
17
+docker build -t server:topo .
18
+
19
+cd ../gateway
20
+docker build -t gateway:topo .
21
+
22
+cd ../device
23
+docker build -t  device:topo .

+ 22
- 0
Dockerfiles/forContainerNet/bootserver/Dockerfile View File

@@ -0,0 +1,22 @@
1
+# Choosing the image to use
2
+FROM node:buster
3
+
4
+# Installing required libraries
5
+RUN apt-get update && \
6
+    apt-get install -y net-tools iputils-ping python-pip && \
7
+    pip install flask && \
8
+    pip install requests && \
9
+    mkdir mydir && \
10
+    cd mydir
11
+
12
+COPY bootstrap_server.py /mydir
13
+
14
+SHELL ["/bin/bash", "-c"]
15
+
16
+RUN echo "nohup python /mydir/bootstrap_server.py &" > start.sh && \
17
+    echo "/bin/bash" >> start.sh && \
18
+    chmod 777 start.sh
19
+
20
+# Mandatory entrypoint in containernet
21
+ENTRYPOINT ./start.sh
22
+

+ 52
- 0
Dockerfiles/forContainerNet/bootserver/bootstrap_client.py View File

@@ -0,0 +1,52 @@
1
+#!/usr/bin/python
2
+#coding: utf-8
3
+import os
4
+import subprocess
5
+import requests
6
+from time import sleep
7
+
8
+
9
+BOOTSTRAP_SERVER_ADDRESS = '10.10.10.10:5555'
10
+
11
+def retrieve_config():
12
+    my_json_config = {"verdict":"oops"}
13
+    my_ip = str(subprocess.check_output("echo $MY_IP", shell=True)).rstrip()
14
+    print("MY_IP : %s"%(my_ip))
15
+    while my_json_config["verdict"] != "yes":
16
+        try:
17
+            resp = requests.get("http://%s/getmyconfig/%s"%(BOOTSTRAP_SERVER_ADDRESS, my_ip), timeout=2)
18
+        except:
19
+            print("Unable to join the bootstrap server")
20
+        try:
21
+            my_json_config = resp.json()
22
+            print("Extracted configs [succ] : %s"%(my_json_config))
23
+        except:
24
+            print("Unable to extract configs from bootstrap server's answer")
25
+            print("Extracted configs [fail] : %s"%(my_json_config))
26
+        print("request url : ==>%s<=="%("http://%s/getmyconfig/%s"%(BOOTSTRAP_SERVER_ADDRESS, my_ip)))
27
+        if "verdict" in my_json_config and my_json_config["verdict"] == "yes":
28
+            my_config = config_json_to_string(my_json_config)
29
+            subprocess.check_output("node /mydir/*.js %s"%(my_config), shell=True)
30
+        else:
31
+            my_json_config = {"verdict":"oops"}
32
+        sleep(3)
33
+
34
+def config_json_to_string(json_config):
35
+    config = ""
36
+    if "local_ip" in json_config:
37
+        config += "--local_ip "+json_config["local_ip"]+" "
38
+    if "local_port" in json_config:
39
+        config += "--local_port "+str(json_config["local_port"])+" "
40
+    if "local_name" in json_config:
41
+        config += "--local_name "+json_config["local_name"]+" "
42
+    if "remote_ip" in json_config:
43
+        config += "--remote_ip "+json_config["remote_ip"]+" "
44
+    if "remote_port" in json_config:
45
+        config += "--remote_port "+str(json_config["remote_port"])+" "
46
+    if "remote_name" in json_config:
47
+        config += "--remote_name "+json_config["remote_name"]+" "
48
+    if "send_period" in json_config:
49
+        config += "--send_period "+str(json_config["send_period"])+" "
50
+    return config.strip()
51
+
52
+retrieve_config()

+ 194
- 0
Dockerfiles/forContainerNet/bootserver/bootstrap_server.py View File

@@ -0,0 +1,194 @@
1
+#!/usr/bin/python
2
+#coding: utf-8
3
+'''In our topology, we assume the container running this script has ip address 10.10.10.10
4
+   (useful information according to our topology: useless otherwise)
5
+'''
6
+from flask import Flask, jsonify
7
+
8
+app = Flask(__name__)
9
+
10
+SVR_IP = '10.0.0.1' #name = srv
11
+
12
+GWI1_IP = '10.2.2.1' #name = gwi1
13
+GWI2_IP = '10.2.2.2' #name = gwi2 (dc)
14
+
15
+GWF1_IP = '10.0.1.100' #name = gwf1
16
+DEV1_GWF1_IP = '10.0.1.1' #name = dev1gwf1
17
+DEV2_GWF1_IP = '10.0.1.2' #name = dev2gwf1
18
+DEV3_GWF1_IP = '10.0.1.3' #name = dev3gwf1
19
+
20
+GWF2_IP = '10.0.2.100' #name = gwf2
21
+DEV1_GWF2_IP = '10.0.2.1' #name = dev1gwf2
22
+DEV2_GWF2_IP = '10.0.2.2' #name = dev2gwf2
23
+DEV3_GWF2_IP = '10.0.2.3' #name = dev3gwf2
24
+
25
+GWF3_IP = '10.0.3.100' #name = gwf3
26
+DEV1_GWF3_IP = '10.0.3.1' #name = dev1gwf3
27
+DEV2_GWF3_IP = '10.0.3.2' #name = dev2gwf3
28
+DEV3_GWF3_IP = '10.0.3.3' #name = dev3gwf3
29
+
30
+'''
31
+Formats of configs:
32
+SERVER =    "--local_ip 127.0.0.1 --local_port 8080 --local_name %s"
33
+GATEWAY_I = "--local_ip 127.0.0.1 --local_port 8181 --local_name %s --remote_ip %s --remote_port 8080 --remote_name %s"
34
+GATEWAY_F = "--local_ip 127.0.0.1​ --local_port 8282 --local_name %s --remote_ip %s --remote_port 8181 --remote_name %s"
35
+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"
36
+'''
37
+
38
+SVR_READY   = False
39
+GWI1_READY  = False
40
+GWI2_READY  = False
41
+GWF1_READY  = False
42
+GWF2_READY  = False
43
+GWF3_READY  = False
44
+
45
+@app.route("/getmyconfig/<string:my_ip>")
46
+def configurations_giver(my_ip="127.0.0.1"):
47
+    global SVR_READY
48
+    global GWI1_READY
49
+    global GWI2_READY
50
+    global GWF1_READY
51
+    global GWF2_READY
52
+    global GWF3_READY
53
+    configs = {"local_ip":my_ip, "verdict":"oops"}
54
+    if my_ip==SVR_IP:
55
+        configs["local_port"] = 8080
56
+        configs["local_name"] = "srv"
57
+        configs["verdict"]    = "yes"
58
+        SVR_READY = True
59
+    elif my_ip==GWI1_IP:
60
+        if SVR_READY:
61
+            configs["local_port"]  = 8181
62
+            configs["local_name"]  = "gwi1"
63
+            configs["remote_ip"]   = SVR_IP
64
+            configs["remote_port"] = 8080
65
+            configs["remote_name"] = "srv"
66
+            configs["verdict"]     = "yes"
67
+            GWI1_READY = True
68
+    elif my_ip==GWF1_IP:
69
+        if GWI1_READY:
70
+            configs["local_port"]  = 8282
71
+            configs["local_name"]  = "gwf1"
72
+            configs["remote_ip"]   = GWI1_IP
73
+            configs["remote_port"] = 8181
74
+            configs["remote_name"] = "gwi1"
75
+            configs["verdict"]     = "yes"
76
+            GWF1_READY = True
77
+    elif my_ip==GWF2_IP:
78
+        if GWI1_READY:
79
+            configs["local_port"]  = 8282
80
+            configs["local_name"]  = "gwf2"
81
+            configs["remote_ip"]   = GWI1_IP
82
+            configs["remote_port"] = 8181
83
+            configs["remote_name"] = "gwi1"
84
+            configs["verdict"]     = "yes"
85
+            GWF2_READY = True
86
+    elif my_ip==GWF3_IP:
87
+        if GWI1_READY:
88
+            configs["local_port"]  = 8282
89
+            configs["local_name"]  = "gwf3"
90
+            configs["remote_ip"]   = GWI1_IP
91
+            configs["remote_port"] = 8181
92
+            configs["remote_name"] = "gwi1"
93
+            configs["verdict"]     = "yes"
94
+            GWF3_READY = True
95
+    elif my_ip==DEV1_GWF1_IP:
96
+        if GWF1_READY:
97
+            configs["local_port"]  = 9001
98
+            configs["local_name"]  = "dev1gwf1"
99
+            configs["remote_ip"]   = GWF1_IP
100
+            configs["remote_port"] = 8282
101
+            configs["remote_name"] = "gwf1"
102
+            configs["send_period"] = 3000
103
+            configs["verdict"]     = "yes"
104
+    elif my_ip==DEV2_GWF1_IP:
105
+        if GWF1_READY:
106
+            configs["local_port"]  = 9001
107
+            configs["local_name"]  = "dev2gwf1"
108
+            configs["remote_ip"]   = GWF1_IP
109
+            configs["remote_port"] = 8282
110
+            configs["remote_name"] = "gwf1"
111
+            configs["send_period"] = 3000
112
+            configs["verdict"]     = "yes"
113
+    elif my_ip==DEV3_GWF1_IP:
114
+        if GWF1_READY:
115
+            configs["local_port"]  = 9001
116
+            configs["local_name"]  = "dev3gwf1"
117
+            configs["remote_ip"]   = GWF1_IP
118
+            configs["remote_port"] = 8282
119
+            configs["remote_name"] = "gwf1"
120
+            configs["send_period"] = 3000
121
+            configs["verdict"]     = "yes"
122
+    elif my_ip==DEV1_GWF2_IP:
123
+        if GWF2_READY:
124
+            configs["local_port"]  = 9001
125
+            configs["local_name"]  = "dev1gwf2"
126
+            configs["remote_ip"]   = GWF2_IP
127
+            configs["remote_port"] = 8282
128
+            configs["remote_name"] = "gwf2"
129
+            configs["send_period"] = 3000
130
+            configs["verdict"]     = "yes"
131
+    elif my_ip==DEV2_GWF2_IP:
132
+        if GWF2_READY:
133
+            configs["local_port"]  = 9001
134
+            configs["local_name"]  = "dev2gwf2"
135
+            configs["remote_ip"]   = GWF2_IP
136
+            configs["remote_port"] = 8282
137
+            configs["remote_name"] = "gwf2"
138
+            configs["send_period"] = 3000
139
+            configs["verdict"]     = "yes"
140
+    elif my_ip==DEV3_GWF2_IP:
141
+        if GWF2_READY:
142
+            configs["local_port"]  = 9001
143
+            configs["local_name"]  = "dev3gwf2"
144
+            configs["remote_ip"]   = GWF2_IP
145
+            configs["remote_port"] = 8282
146
+            configs["remote_name"] = "gwf2"
147
+            configs["send_period"] = 3000
148
+            configs["verdict"]     = "yes"
149
+    elif my_ip==DEV1_GWF3_IP:
150
+        if GWF3_READY:
151
+            configs["local_port"]  = 9001
152
+            configs["local_name"]  = "dev1gwf3"
153
+            configs["remote_ip"]   = GWF3_IP
154
+            configs["remote_port"] = 8282
155
+            configs["remote_name"] = "gwf3"
156
+            configs["send_period"] = 3000
157
+            configs["verdict"]     = "yes"
158
+    elif my_ip==DEV2_GWF3_IP:
159
+        if GWF3_READY:
160
+            configs["local_port"]  = 9001
161
+            configs["local_name"]  = "dev2gwf3"
162
+            configs["remote_ip"]   = GWF3_IP
163
+            configs["remote_port"] = 8282
164
+            configs["remote_name"] = "gwf3"
165
+            configs["send_period"] = 3000
166
+            configs["verdict"]     = "yes"
167
+    elif my_ip==DEV3_GWF3_IP:
168
+        if GWF3_READY:
169
+            configs["local_port"]  = 9001
170
+            configs["local_name"]  = "dev3gwf3"
171
+            configs["remote_ip"]   = GWF3_IP
172
+            configs["remote_port"] = 8282
173
+            configs["remote_name"] = "gwf3"
174
+            configs["send_period"] = 3000
175
+            configs["verdict"]     = "yes"
176
+    return jsonify(configs)
177
+
178
+@app.route("/getmyconfig/")
179
+def configurations_giver_to_dc():
180
+    global GWI2_READY
181
+    configs = {"local_ip":GWI2_IP, "verdict":"oops"}
182
+    if SVR_READY:
183
+        configs["local_port"]  = 8181
184
+        configs["local_name"]  = "gwi2"
185
+        configs["remote_ip"]   = SVR_IP
186
+        configs["remote_port"] = 8080
187
+        configs["remote_name"] = "srv"
188
+        configs["verdict"] = "yes"
189
+        GWI2_READY = True
190
+    return jsonify(configs)
191
+
192
+if __name__=='__main__':
193
+    app.run(debug=False, host='0.0.0.0', port=5555)
194
+

+ 28
- 0
Dockerfiles/forContainerNet/device/Dockerfile View File

@@ -0,0 +1,28 @@
1
+# Choosing the image to use
2
+FROM node:buster
3
+
4
+# Installing required libraries
5
+RUN apt-get update && \
6
+    apt-get install -y net-tools iputils-ping python-pip && \
7
+    pip install flask && \
8
+    pip install requests && \
9
+    mkdir mydir && \
10
+    cd mydir && \
11
+    npm install express && \
12
+    npm install yargs && \
13
+    npm install systeminformation && \
14
+    npm install request
15
+
16
+COPY device.js /mydir
17
+
18
+COPY bootstrap_client.py /mydir
19
+
20
+SHELL ["/bin/bash", "-c"]
21
+
22
+RUN echo "nohup python /mydir/bootstrap_client.py &" > start.sh && \
23
+    echo "/bin/bash" >> start.sh && \
24
+    chmod 777 start.sh
25
+
26
+# Mandatory entrypoint in containernet
27
+ENTRYPOINT ./start.sh
28
+

+ 52
- 0
Dockerfiles/forContainerNet/device/bootstrap_client.py View File

@@ -0,0 +1,52 @@
1
+#!/usr/bin/python
2
+#coding: utf-8
3
+import os
4
+import subprocess
5
+import requests
6
+from time import sleep
7
+
8
+
9
+BOOTSTRAP_SERVER_ADDRESS = '10.10.10.10:5555'
10
+
11
+def retrieve_config():
12
+    my_json_config = {"verdict":"oops"}
13
+    my_ip = str(subprocess.check_output("echo $MY_IP", shell=True)).rstrip()
14
+    print("MY_IP : %s"%(my_ip))
15
+    while my_json_config["verdict"] != "yes":
16
+        try:
17
+            resp = requests.get("http://%s/getmyconfig/%s"%(BOOTSTRAP_SERVER_ADDRESS, my_ip), timeout=2)
18
+        except:
19
+            print("Unable to join the bootstrap server")
20
+        try:
21
+            my_json_config = resp.json()
22
+            print("Extracted configs [succ] : %s"%(my_json_config))
23
+        except:
24
+            print("Unable to extract configs from bootstrap server's answer")
25
+            print("Extracted configs [fail] : %s"%(my_json_config))
26
+        print("request url : ==>%s<=="%("http://%s/getmyconfig/%s"%(BOOTSTRAP_SERVER_ADDRESS, my_ip)))
27
+        if "verdict" in my_json_config and my_json_config["verdict"] == "yes":
28
+            my_config = config_json_to_string(my_json_config)
29
+            subprocess.check_output("node /mydir/*.js %s"%(my_config), shell=True)
30
+        else:
31
+            my_json_config = {"verdict":"oops"}
32
+        sleep(3)
33
+
34
+def config_json_to_string(json_config):
35
+    config = ""
36
+    if "local_ip" in json_config:
37
+        config += "--local_ip "+json_config["local_ip"]+" "
38
+    if "local_port" in json_config:
39
+        config += "--local_port "+str(json_config["local_port"])+" "
40
+    if "local_name" in json_config:
41
+        config += "--local_name "+json_config["local_name"]+" "
42
+    if "remote_ip" in json_config:
43
+        config += "--remote_ip "+json_config["remote_ip"]+" "
44
+    if "remote_port" in json_config:
45
+        config += "--remote_port "+str(json_config["remote_port"])+" "
46
+    if "remote_name" in json_config:
47
+        config += "--remote_name "+json_config["remote_name"]+" "
48
+    if "send_period" in json_config:
49
+        config += "--send_period "+str(json_config["send_period"])+" "
50
+    return config.strip()
51
+
52
+retrieve_config()

+ 53
- 0
Dockerfiles/forContainerNet/device/device.js View File

@@ -0,0 +1,53 @@
1
+var express = require('express')
2
+var app = express()
3
+var request = require('request');
4
+
5
+var argv = require('yargs').argv;
6
+// --local_ip
7
+// --local_port
8
+// --local_name
9
+// --remote_ip
10
+// --remote_port
11
+// --remote_name
12
+// --send_period 
13
+
14
+var LOCAL_ENDPOINT = {IP : argv.local_ip, PORT : argv.local_port, NAME : argv.local_name};
15
+var REMOTE_ENDPOINT = {IP : argv.remote_ip, PORT : argv.remote_port, NAME : argv.remote_name};
16
+
17
+var DATA_PERIOD = argv.send_period;
18
+
19
+function doPOST(uri, body, onResponse) {
20
+    request({method: 'POST', uri: uri, json : body}, onResponse); 
21
+}
22
+
23
+function register() {
24
+    doPOST(
25
+        'http://' + REMOTE_ENDPOINT.IP + ':' + REMOTE_ENDPOINT.PORT + '/devices/register', 
26
+        {
27
+            Name : LOCAL_ENDPOINT.NAME, 
28
+            PoC : 'http://' + LOCAL_ENDPOINT.IP + ':' + LOCAL_ENDPOINT.PORT, 
29
+        },
30
+        function(error, response, respBody) {
31
+            console.log(respBody);
32
+        }
33
+    );
34
+}
35
+
36
+var dataItem = 0;
37
+function sendData() {
38
+    doPOST(
39
+        'http://' + REMOTE_ENDPOINT.IP + ':' + REMOTE_ENDPOINT.PORT + '/device/'+ LOCAL_ENDPOINT.NAME + '/data', 
40
+        {
41
+            Name : LOCAL_ENDPOINT.NAME, 
42
+            Data : dataItem++,
43
+            Time : Date.now(),
44
+        },
45
+        function(error, response, respBody) {
46
+            console.log(respBody);
47
+        }
48
+    );
49
+}
50
+
51
+register();
52
+
53
+setInterval(sendData, DATA_PERIOD);

+ 28
- 0
Dockerfiles/forContainerNet/gateway/Dockerfile View File

@@ -0,0 +1,28 @@
1
+# Choosing the image to use
2
+FROM node:buster
3
+
4
+# Installing required libraries
5
+RUN apt-get update && \
6
+    apt-get install -y net-tools iputils-ping python-pip && \
7
+    pip install flask && \
8
+    pip install requests && \
9
+    mkdir mydir && \
10
+    cd mydir && \
11
+    npm install express && \
12
+    npm install yargs && \
13
+    npm install systeminformation && \
14
+    npm install request
15
+
16
+COPY gateway.js /mydir
17
+
18
+COPY bootstrap_client.py /mydir
19
+
20
+SHELL ["/bin/bash", "-c"]
21
+
22
+RUN echo "nohup python /mydir/bootstrap_client.py &" > start.sh && \
23
+    echo "/bin/bash" >> start.sh && \
24
+    chmod 777 start.sh
25
+
26
+# Mandatory entrypoint in containernet
27
+ENTRYPOINT ./start.sh
28
+

+ 52
- 0
Dockerfiles/forContainerNet/gateway/bootstrap_client.py View File

@@ -0,0 +1,52 @@
1
+#!/usr/bin/python
2
+#coding: utf-8
3
+import os
4
+import subprocess
5
+import requests
6
+from time import sleep
7
+
8
+
9
+BOOTSTRAP_SERVER_ADDRESS = '10.10.10.10:5555'
10
+
11
+def retrieve_config():
12
+    my_json_config = {"verdict":"oops"}
13
+    my_ip = str(subprocess.check_output("echo $MY_IP", shell=True)).rstrip()
14
+    print("MY_IP : %s"%(my_ip))
15
+    while my_json_config["verdict"] != "yes":
16
+        try:
17
+            resp = requests.get("http://%s/getmyconfig/%s"%(BOOTSTRAP_SERVER_ADDRESS, my_ip), timeout=2)
18
+        except:
19
+            print("Unable to join the bootstrap server")
20
+        try:
21
+            my_json_config = resp.json()
22
+            print("Extracted configs [succ] : %s"%(my_json_config))
23
+        except:
24
+            print("Unable to extract configs from bootstrap server's answer")
25
+            print("Extracted configs [fail] : %s"%(my_json_config))
26
+        print("request url : ==>%s<=="%("http://%s/getmyconfig/%s"%(BOOTSTRAP_SERVER_ADDRESS, my_ip)))
27
+        if "verdict" in my_json_config and my_json_config["verdict"] == "yes":
28
+            my_config = config_json_to_string(my_json_config)
29
+            subprocess.check_output("node /mydir/*.js %s"%(my_config), shell=True)
30
+        else:
31
+            my_json_config = {"verdict":"oops"}
32
+        sleep(3)
33
+
34
+def config_json_to_string(json_config):
35
+    config = ""
36
+    if "local_ip" in json_config:
37
+        config += "--local_ip "+json_config["local_ip"]+" "
38
+    if "local_port" in json_config:
39
+        config += "--local_port "+str(json_config["local_port"])+" "
40
+    if "local_name" in json_config:
41
+        config += "--local_name "+json_config["local_name"]+" "
42
+    if "remote_ip" in json_config:
43
+        config += "--remote_ip "+json_config["remote_ip"]+" "
44
+    if "remote_port" in json_config:
45
+        config += "--remote_port "+str(json_config["remote_port"])+" "
46
+    if "remote_name" in json_config:
47
+        config += "--remote_name "+json_config["remote_name"]+" "
48
+    if "send_period" in json_config:
49
+        config += "--send_period "+str(json_config["send_period"])+" "
50
+    return config.strip()
51
+
52
+retrieve_config()

+ 127
- 0
Dockerfiles/forContainerNet/gateway/gateway.js View File

@@ -0,0 +1,127 @@
1
+var express = require('express')
2
+var app = express()
3
+app.use(express.json()) // for parsing application/json
4
+
5
+var request = require('request');
6
+const si = require('systeminformation');
7
+var argv = require('yargs').argv;
8
+// --local_ip
9
+// --local_port
10
+// --local_name
11
+// --remote_ip
12
+// --remote_port
13
+// --remote_name
14
+
15
+var LOCAL_ENDPOINT = {IP : argv.local_ip, PORT : argv.local_port, NAME : argv.local_name};
16
+var REMOTE_ENDPOINT = {IP : argv.remote_ip, PORT : argv.remote_port, NAME : argv.remote_name};
17
+
18
+const E_OK              = 200;
19
+const E_CREATED         = 201;
20
+const E_FORBIDDEN       = 403;
21
+const E_NOT_FOUND       = 404;
22
+const E_ALREADY_EXIST   = 500;
23
+
24
+
25
+var db = {
26
+        gateways : new Map()
27
+    };
28
+
29
+function addNewGateway(gw) {
30
+    var res = -1;
31
+    if (!db.gateways.get(gw.Name)) {
32
+        db.gateways.set(gw.Name, gw);
33
+        res = 0;
34
+    }
35
+    return res;
36
+}
37
+
38
+function removeGateway(gw) {
39
+    if (db.gateways.get(gw.Name))
40
+        db.gateways.delete(gw.Name);
41
+}
42
+    
43
+
44
+function doPOST(uri, body, onResponse) {
45
+    request({method: 'POST', uri: uri, json : body}, onResponse); 
46
+}
47
+
48
+function register() {
49
+    doPOST(
50
+        'http://' + REMOTE_ENDPOINT.IP + ':' + REMOTE_ENDPOINT.PORT + '/gateways/register', 
51
+        {
52
+            Name : LOCAL_ENDPOINT.NAME, 
53
+            PoC : 'http://' + LOCAL_ENDPOINT.IP + ':' + LOCAL_ENDPOINT.PORT, 
54
+        },
55
+        function(error, response, respBody) {
56
+            console.log(respBody);
57
+        }
58
+    );
59
+}
60
+
61
+
62
+app.post('/gateways/register', function(req, res) {
63
+    console.log(req.body);
64
+    var result = addNewGateway(req.body);
65
+    if (result === 0)
66
+        res.sendStatus(E_CREATED);  
67
+    else
68
+        res.sendStatus(E_ALREADY_EXIST);  
69
+ });
70
+app.post('/devices/register', function(req, res) {
71
+    console.log(req.body);
72
+    doPOST(
73
+        'http://' + REMOTE_ENDPOINT.IP + ':' +REMOTE_ENDPOINT.PORT + '/devices/register',
74
+        req.body,
75
+        function(error, response, respBody) {
76
+            console.log(respBody);
77
+            res.sendStatus(E_OK); 
78
+        }
79
+    )
80
+ });
81
+ app.post('/device/:dev/data', function(req, res) {
82
+    console.log(req.body);
83
+    var dev = req.params.dev;
84
+    doPOST(
85
+        'http://' + REMOTE_ENDPOINT.IP + ':' +REMOTE_ENDPOINT.PORT + '/device/' + dev + '/data',
86
+        req.body,
87
+        function(error, response, respBody) {
88
+            console.log(respBody);
89
+            res.sendStatus(E_OK); 
90
+        }
91
+    )
92
+});
93
+app.get('/gateways', function(req, res) {
94
+    console.log(req.body);
95
+    let resObj = [];
96
+    db.gateways.forEach((v,k) => {
97
+        resObj.push(v);
98
+    });
99
+    res.send(resObj);
100
+});
101
+app.get('/gateway/:gw', function(req, res) {
102
+    console.log(req.body);
103
+    var gw = req.params.gw;
104
+    var gateway = db.gateways.get(gw);
105
+    if (gateway)
106
+        res.status(E_OK).send(JSON.stringify(gateway));
107
+    else
108
+        res.sendStatus(E_NOT_FOUND);
109
+});
110
+
111
+app.get('/ping', function(req, res) {
112
+    console.log(req.body);
113
+    res.status(E_OK).send({pong: Date.now()});
114
+});
115
+app.get('/health', function(req, res) {
116
+    console.log(req.body);
117
+    si.currentLoad((d) => {
118
+        console.log(d);
119
+        res.status(E_OK).send(JSON.stringify(d));
120
+    })
121
+});
122
+
123
+
124
+register();
125
+app.listen(LOCAL_ENDPOINT.PORT , function () {
126
+    console.log(LOCAL_ENDPOINT.NAME + ' listening on : ' + LOCAL_ENDPOINT.PORT );
127
+});

+ 28
- 0
Dockerfiles/forContainerNet/server/Dockerfile View File

@@ -0,0 +1,28 @@
1
+# Choosing the image to use
2
+FROM node:buster
3
+
4
+# Installing required libraries
5
+RUN apt-get update && \
6
+    apt-get install -y net-tools iputils-ping python-pip && \
7
+    pip install flask && \
8
+    pip install requests && \
9
+    mkdir mydir && \
10
+    cd mydir && \
11
+    npm install express && \
12
+    npm install yargs && \
13
+    npm install systeminformation && \
14
+    npm install request
15
+
16
+COPY server.js /mydir
17
+
18
+COPY bootstrap_client.py /mydir
19
+
20
+SHELL ["/bin/bash", "-c"]
21
+
22
+RUN echo "nohup python /mydir/bootstrap_client.py &" > start.sh && \
23
+    echo "/bin/bash" >> start.sh && \
24
+    chmod 777 start.sh
25
+
26
+# Mandatory entrypoint in containernet
27
+ENTRYPOINT ./start.sh
28
+

+ 52
- 0
Dockerfiles/forContainerNet/server/bootstrap_client.py View File

@@ -0,0 +1,52 @@
1
+#!/usr/bin/python
2
+#coding: utf-8
3
+import os
4
+import subprocess
5
+import requests
6
+from time import sleep
7
+
8
+
9
+BOOTSTRAP_SERVER_ADDRESS = '10.10.10.10:5555'
10
+
11
+def retrieve_config():
12
+    my_json_config = {"verdict":"oops"}
13
+    my_ip = str(subprocess.check_output("echo $MY_IP", shell=True)).rstrip()
14
+    print("MY_IP : %s"%(my_ip))
15
+    while my_json_config["verdict"] != "yes":
16
+        try:
17
+            resp = requests.get("http://%s/getmyconfig/%s"%(BOOTSTRAP_SERVER_ADDRESS, my_ip), timeout=2)
18
+        except:
19
+            print("Unable to join the bootstrap server")
20
+        try:
21
+            my_json_config = resp.json()
22
+            print("Extracted configs [succ] : %s"%(my_json_config))
23
+        except:
24
+            print("Unable to extract configs from bootstrap server's answer")
25
+            print("Extracted configs [fail] : %s"%(my_json_config))
26
+        print("request url : ==>%s<=="%("http://%s/getmyconfig/%s"%(BOOTSTRAP_SERVER_ADDRESS, my_ip)))
27
+        if "verdict" in my_json_config and my_json_config["verdict"] == "yes":
28
+            my_config = config_json_to_string(my_json_config)
29
+            subprocess.check_output("node /mydir/*.js %s"%(my_config), shell=True)
30
+        else:
31
+            my_json_config = {"verdict":"oops"}
32
+        sleep(3)
33
+
34
+def config_json_to_string(json_config):
35
+    config = ""
36
+    if "local_ip" in json_config:
37
+        config += "--local_ip "+json_config["local_ip"]+" "
38
+    if "local_port" in json_config:
39
+        config += "--local_port "+str(json_config["local_port"])+" "
40
+    if "local_name" in json_config:
41
+        config += "--local_name "+json_config["local_name"]+" "
42
+    if "remote_ip" in json_config:
43
+        config += "--remote_ip "+json_config["remote_ip"]+" "
44
+    if "remote_port" in json_config:
45
+        config += "--remote_port "+str(json_config["remote_port"])+" "
46
+    if "remote_name" in json_config:
47
+        config += "--remote_name "+json_config["remote_name"]+" "
48
+    if "send_period" in json_config:
49
+        config += "--send_period "+str(json_config["send_period"])+" "
50
+    return config.strip()
51
+
52
+retrieve_config()

+ 167
- 0
Dockerfiles/forContainerNet/server/server.js View File

@@ -0,0 +1,167 @@
1
+var express = require('express')
2
+var app = express()
3
+app.use(express.json()) 
4
+
5
+var argv = require('yargs').argv;
6
+// --local_ip
7
+// --local_port
8
+// --local_name
9
+const si = require('systeminformation');
10
+
11
+var LOCAL_ENDPOINT = {IP : argv.local_ip, PORT : argv.local_port, NAME : argv.local_name};
12
+
13
+const E_OK              = 200;
14
+const E_CREATED         = 201;
15
+const E_FORBIDDEN       = 403;
16
+const E_NOT_FOUND       = 404;
17
+const E_ALREADY_EXIST   = 500;
18
+
19
+
20
+var db = {
21
+        devices : new Map(),
22
+        data : new Map(),
23
+        gateways : new Map()
24
+    };
25
+
26
+function addNewDevice(dev) {
27
+    var result = -1;
28
+    if (!db.devices.get(dev.Name)) {
29
+        db.devices.set(dev.Name, dev);
30
+
31
+        if (db.devices.get(dev.Name))
32
+            db.data.delete(dev.Name);
33
+        db.data.set(dev.Name, []);
34
+
35
+        result = 0;
36
+    }
37
+    return result;
38
+}
39
+
40
+function addNewGateway(gw) {
41
+    var result = -1;
42
+    if (!db.gateways.get(gw.Name)) {
43
+        db.gateways.set(gw.Name, gw);
44
+        result = 0;
45
+    }
46
+    return result;
47
+}
48
+
49
+function removeDevice(dev) {
50
+    if (db.devices.get(dev.Name)) {
51
+        db.devices.delete(dev.Name);
52
+        if (db.devices.get(dev.Name))
53
+            db.data.delete(dev.Name);
54
+    }
55
+}
56
+
57
+function removeGateway(gw) {
58
+    if (db.gateways.get(gw.Name))
59
+        db.gateways.delete(gw.Name);
60
+}
61
+
62
+function addDeviceData(dev, data) {
63
+    var result = -1;
64
+    var device = db.devices.get(dev);
65
+    if (device) {
66
+        db.data.get(dev).push(data);
67
+        result = 0;
68
+    }
69
+    return result;
70
+}
71
+
72
+
73
+
74
+app.get('/devices', function(req, res) {
75
+    console.log(req.body);
76
+    let resObj = [];
77
+    db.devices.forEach((v,k) => {
78
+        resObj.push(v);
79
+    });
80
+    res.status(E_OK).send(resObj);
81
+});
82
+app.get('/device/:dev', function(req, res) {
83
+    console.log(req.body);
84
+    var dev = req.params.dev;
85
+    var device = db.devices.get(dev);
86
+    if (device)
87
+        res.status(E_OK).send(JSON.stringify(device));
88
+    else
89
+        res.sendStatus(E_NOT_FOUND);
90
+});
91
+app.post('/device/:dev/data', function(req, res) {
92
+    console.log(req.body);
93
+    var dev = req.params.dev;
94
+    var result = addDeviceData(dev, req.body);
95
+    if (result === 0)
96
+        res.sendStatus(E_CREATED);
97
+    else
98
+        res.sendStatus(E_NOT_FOUND);
99
+});
100
+app.get('/device/:dev/data', function(req, res) {
101
+    console.log(req.body);
102
+    var dev = req.params.dev;
103
+    var device = db.devices.get(dev);
104
+    if (device){
105
+        var data = db.data.get(dev);
106
+        if (data) {
107
+            let resObj = [];
108
+            data.forEach((v,k) => {
109
+                resObj.push(v);
110
+            });
111
+            res.status(E_OK).send(JSON.stringify(resObj));
112
+        }
113
+        else
114
+            res.sendStatus(E_NOT_FOUND);
115
+    }
116
+    else
117
+        res.sendStatus(E_NOT_FOUND);
118
+});
119
+app.post('/devices/register', function(req, res) {
120
+    console.log(req.body);
121
+    var result = addNewDevice(req.body);
122
+    if ( result === 0)
123
+        res.sendStatus(E_CREATED);  
124
+    else
125
+        res.sendStatus(E_ALREADY_EXIST);  
126
+});
127
+app.get('/gateways', function(req, res) {
128
+    console.log(req.body);
129
+    let resObj = [];
130
+    db.gateways.forEach((v,k) => {
131
+        resObj.push(v);
132
+    });
133
+    res.send(resObj);
134
+});
135
+app.get('/gateway/:gw', function(req, res) {
136
+    console.log(req.body);
137
+    var gw = req.params.gw;
138
+    var gateway = db.gateways.get(gw);
139
+    if (gateway)
140
+        res.status(E_OK).send(JSON.stringify(gateway));
141
+    else
142
+        res.sendStatus(E_NOT_FOUND);
143
+});
144
+app.post('/gateways/register', function(req, res) {
145
+    console.log(req.body);
146
+    var result = addNewGateway(req.body);
147
+    if ( result === 0)
148
+        res.sendStatus(E_CREATED);  
149
+    else
150
+        res.sendStatus(E_ALREADY_EXIST);  
151
+});
152
+
153
+app.get('/ping', function(req, res) {
154
+    console.log(req.body);
155
+    res.status(E_OK).send({pong: Date.now()});
156
+});
157
+app.get('/health', function(req, res) {
158
+    console.log(req.body);
159
+    si.currentLoad((d) => {
160
+        console.log(d);
161
+        res.status(E_OK).send(JSON.stringify(d));
162
+    })
163
+});
164
+
165
+app.listen(LOCAL_ENDPOINT.PORT , function () {
166
+    console.log(LOCAL_ENDPOINT.NAME + ' listening on : ' + LOCAL_ENDPOINT.PORT );
167
+});

BIN
enonce/2020-2021-_UE-PETAR--SUJETS-ETUDE.pdf View File


+ 2
- 0
jsfiles/README.md View File

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

+ 53
- 0
jsfiles/device.js View File

@@ -0,0 +1,53 @@
1
+var express = require('express')
2
+var app = express()
3
+var request = require('request');
4
+
5
+var argv = require('yargs').argv;
6
+// --local_ip
7
+// --local_port
8
+// --local_name
9
+// --remote_ip
10
+// --remote_port
11
+// --remote_name
12
+// --send_period 
13
+
14
+var LOCAL_ENDPOINT = {IP : argv.local_ip, PORT : argv.local_port, NAME : argv.local_name};
15
+var REMOTE_ENDPOINT = {IP : argv.remote_ip, PORT : argv.remote_port, NAME : argv.remote_name};
16
+
17
+var DATA_PERIOD = argv.send_period;
18
+
19
+function doPOST(uri, body, onResponse) {
20
+    request({method: 'POST', uri: uri, json : body}, onResponse); 
21
+}
22
+
23
+function register() {
24
+    doPOST(
25
+        'http://' + REMOTE_ENDPOINT.IP + ':' + REMOTE_ENDPOINT.PORT + '/devices/register', 
26
+        {
27
+            Name : LOCAL_ENDPOINT.NAME, 
28
+            PoC : 'http://' + LOCAL_ENDPOINT.IP + ':' + LOCAL_ENDPOINT.PORT, 
29
+        },
30
+        function(error, response, respBody) {
31
+            console.log(respBody);
32
+        }
33
+    );
34
+}
35
+
36
+var dataItem = 0;
37
+function sendData() {
38
+    doPOST(
39
+        'http://' + REMOTE_ENDPOINT.IP + ':' + REMOTE_ENDPOINT.PORT + '/device/'+ LOCAL_ENDPOINT.NAME + '/data', 
40
+        {
41
+            Name : LOCAL_ENDPOINT.NAME, 
42
+            Data : dataItem++,
43
+            Time : Date.now(),
44
+        },
45
+        function(error, response, respBody) {
46
+            console.log(respBody);
47
+        }
48
+    );
49
+}
50
+
51
+register();
52
+
53
+setInterval(sendData, DATA_PERIOD);

+ 127
- 0
jsfiles/gateway.js View File

@@ -0,0 +1,127 @@
1
+var express = require('express')
2
+var app = express()
3
+app.use(express.json()) // for parsing application/json
4
+
5
+var request = require('request');
6
+const si = require('systeminformation');
7
+var argv = require('yargs').argv;
8
+// --local_ip
9
+// --local_port
10
+// --local_name
11
+// --remote_ip
12
+// --remote_port
13
+// --remote_name
14
+
15
+var LOCAL_ENDPOINT = {IP : argv.local_ip, PORT : argv.local_port, NAME : argv.local_name};
16
+var REMOTE_ENDPOINT = {IP : argv.remote_ip, PORT : argv.remote_port, NAME : argv.remote_name};
17
+
18
+const E_OK              = 200;
19
+const E_CREATED         = 201;
20
+const E_FORBIDDEN       = 403;
21
+const E_NOT_FOUND       = 404;
22
+const E_ALREADY_EXIST   = 500;
23
+
24
+
25
+var db = {
26
+        gateways : new Map()
27
+    };
28
+
29
+function addNewGateway(gw) {
30
+    var res = -1;
31
+    if (!db.gateways.get(gw.Name)) {
32
+        db.gateways.set(gw.Name, gw);
33
+        res = 0;
34
+    }
35
+    return res;
36
+}
37
+
38
+function removeGateway(gw) {
39
+    if (db.gateways.get(gw.Name))
40
+        db.gateways.delete(gw.Name);
41
+}
42
+    
43
+
44
+function doPOST(uri, body, onResponse) {
45
+    request({method: 'POST', uri: uri, json : body}, onResponse); 
46
+}
47
+
48
+function register() {
49
+    doPOST(
50
+        'http://' + REMOTE_ENDPOINT.IP + ':' + REMOTE_ENDPOINT.PORT + '/gateways/register', 
51
+        {
52
+            Name : LOCAL_ENDPOINT.NAME, 
53
+            PoC : 'http://' + LOCAL_ENDPOINT.IP + ':' + LOCAL_ENDPOINT.PORT, 
54
+        },
55
+        function(error, response, respBody) {
56
+            console.log(respBody);
57
+        }
58
+    );
59
+}
60
+
61
+
62
+app.post('/gateways/register', function(req, res) {
63
+    console.log(req.body);
64
+    var result = addNewGateway(req.body);
65
+    if (result === 0)
66
+        res.sendStatus(E_CREATED);  
67
+    else
68
+        res.sendStatus(E_ALREADY_EXIST);  
69
+ });
70
+app.post('/devices/register', function(req, res) {
71
+    console.log(req.body);
72
+    doPOST(
73
+        'http://' + REMOTE_ENDPOINT.IP + ':' +REMOTE_ENDPOINT.PORT + '/devices/register',
74
+        req.body,
75
+        function(error, response, respBody) {
76
+            console.log(respBody);
77
+            res.sendStatus(E_OK); 
78
+        }
79
+    )
80
+ });
81
+ app.post('/device/:dev/data', function(req, res) {
82
+    console.log(req.body);
83
+    var dev = req.params.dev;
84
+    doPOST(
85
+        'http://' + REMOTE_ENDPOINT.IP + ':' +REMOTE_ENDPOINT.PORT + '/device/' + dev + '/data',
86
+        req.body,
87
+        function(error, response, respBody) {
88
+            console.log(respBody);
89
+            res.sendStatus(E_OK); 
90
+        }
91
+    )
92
+});
93
+app.get('/gateways', function(req, res) {
94
+    console.log(req.body);
95
+    let resObj = [];
96
+    db.gateways.forEach((v,k) => {
97
+        resObj.push(v);
98
+    });
99
+    res.send(resObj);
100
+});
101
+app.get('/gateway/:gw', function(req, res) {
102
+    console.log(req.body);
103
+    var gw = req.params.gw;
104
+    var gateway = db.gateways.get(gw);
105
+    if (gateway)
106
+        res.status(E_OK).send(JSON.stringify(gateway));
107
+    else
108
+        res.sendStatus(E_NOT_FOUND);
109
+});
110
+
111
+app.get('/ping', function(req, res) {
112
+    console.log(req.body);
113
+    res.status(E_OK).send({pong: Date.now()});
114
+});
115
+app.get('/health', function(req, res) {
116
+    console.log(req.body);
117
+    si.currentLoad((d) => {
118
+        console.log(d);
119
+        res.status(E_OK).send(JSON.stringify(d));
120
+    })
121
+});
122
+
123
+
124
+register();
125
+app.listen(LOCAL_ENDPOINT.PORT , function () {
126
+    console.log(LOCAL_ENDPOINT.NAME + ' listening on : ' + LOCAL_ENDPOINT.PORT );
127
+});

+ 167
- 0
jsfiles/server.js View File

@@ -0,0 +1,167 @@
1
+var express = require('express')
2
+var app = express()
3
+app.use(express.json()) 
4
+
5
+var argv = require('yargs').argv;
6
+// --local_ip
7
+// --local_port
8
+// --local_name
9
+const si = require('systeminformation');
10
+
11
+var LOCAL_ENDPOINT = {IP : argv.local_ip, PORT : argv.local_port, NAME : argv.local_name};
12
+
13
+const E_OK              = 200;
14
+const E_CREATED         = 201;
15
+const E_FORBIDDEN       = 403;
16
+const E_NOT_FOUND       = 404;
17
+const E_ALREADY_EXIST   = 500;
18
+
19
+
20
+var db = {
21
+        devices : new Map(),
22
+        data : new Map(),
23
+        gateways : new Map()
24
+    };
25
+
26
+function addNewDevice(dev) {
27
+    var result = -1;
28
+    if (!db.devices.get(dev.Name)) {
29
+        db.devices.set(dev.Name, dev);
30
+
31
+        if (db.devices.get(dev.Name))
32
+            db.data.delete(dev.Name);
33
+        db.data.set(dev.Name, []);
34
+
35
+        result = 0;
36
+    }
37
+    return result;
38
+}
39
+
40
+function addNewGateway(gw) {
41
+    var result = -1;
42
+    if (!db.gateways.get(gw.Name)) {
43
+        db.gateways.set(gw.Name, gw);
44
+        result = 0;
45
+    }
46
+    return result;
47
+}
48
+
49
+function removeDevice(dev) {
50
+    if (db.devices.get(dev.Name)) {
51
+        db.devices.delete(dev.Name);
52
+        if (db.devices.get(dev.Name))
53
+            db.data.delete(dev.Name);
54
+    }
55
+}
56
+
57
+function removeGateway(gw) {
58
+    if (db.gateways.get(gw.Name))
59
+        db.gateways.delete(gw.Name);
60
+}
61
+
62
+function addDeviceData(dev, data) {
63
+    var result = -1;
64
+    var device = db.devices.get(dev);
65
+    if (device) {
66
+        db.data.get(dev).push(data);
67
+        result = 0;
68
+    }
69
+    return result;
70
+}
71
+
72
+
73
+
74
+app.get('/devices', function(req, res) {
75
+    console.log(req.body);
76
+    let resObj = [];
77
+    db.devices.forEach((v,k) => {
78
+        resObj.push(v);
79
+    });
80
+    res.status(E_OK).send(resObj);
81
+});
82
+app.get('/device/:dev', function(req, res) {
83
+    console.log(req.body);
84
+    var dev = req.params.dev;
85
+    var device = db.devices.get(dev);
86
+    if (device)
87
+        res.status(E_OK).send(JSON.stringify(device));
88
+    else
89
+        res.sendStatus(E_NOT_FOUND);
90
+});
91
+app.post('/device/:dev/data', function(req, res) {
92
+    console.log(req.body);
93
+    var dev = req.params.dev;
94
+    var result = addDeviceData(dev, req.body);
95
+    if (result === 0)
96
+        res.sendStatus(E_CREATED);
97
+    else
98
+        res.sendStatus(E_NOT_FOUND);
99
+});
100
+app.get('/device/:dev/data', function(req, res) {
101
+    console.log(req.body);
102
+    var dev = req.params.dev;
103
+    var device = db.devices.get(dev);
104
+    if (device){
105
+        var data = db.data.get(dev);
106
+        if (data) {
107
+            let resObj = [];
108
+            data.forEach((v,k) => {
109
+                resObj.push(v);
110
+            });
111
+            res.status(E_OK).send(JSON.stringify(resObj));
112
+        }
113
+        else
114
+            res.sendStatus(E_NOT_FOUND);
115
+    }
116
+    else
117
+        res.sendStatus(E_NOT_FOUND);
118
+});
119
+app.post('/devices/register', function(req, res) {
120
+    console.log(req.body);
121
+    var result = addNewDevice(req.body);
122
+    if ( result === 0)
123
+        res.sendStatus(E_CREATED);  
124
+    else
125
+        res.sendStatus(E_ALREADY_EXIST);  
126
+});
127
+app.get('/gateways', function(req, res) {
128
+    console.log(req.body);
129
+    let resObj = [];
130
+    db.gateways.forEach((v,k) => {
131
+        resObj.push(v);
132
+    });
133
+    res.send(resObj);
134
+});
135
+app.get('/gateway/:gw', function(req, res) {
136
+    console.log(req.body);
137
+    var gw = req.params.gw;
138
+    var gateway = db.gateways.get(gw);
139
+    if (gateway)
140
+        res.status(E_OK).send(JSON.stringify(gateway));
141
+    else
142
+        res.sendStatus(E_NOT_FOUND);
143
+});
144
+app.post('/gateways/register', function(req, res) {
145
+    console.log(req.body);
146
+    var result = addNewGateway(req.body);
147
+    if ( result === 0)
148
+        res.sendStatus(E_CREATED);  
149
+    else
150
+        res.sendStatus(E_ALREADY_EXIST);  
151
+});
152
+
153
+app.get('/ping', function(req, res) {
154
+    console.log(req.body);
155
+    res.status(E_OK).send({pong: Date.now()});
156
+});
157
+app.get('/health', function(req, res) {
158
+    console.log(req.body);
159
+    si.currentLoad((d) => {
160
+        console.log(d);
161
+        res.status(E_OK).send(JSON.stringify(d));
162
+    })
163
+});
164
+
165
+app.listen(LOCAL_ENDPOINT.PORT , function () {
166
+    console.log(LOCAL_ENDPOINT.NAME + ' listening on : ' + LOCAL_ENDPOINT.PORT );
167
+});

+ 191
- 0
topologie/topology.py View File

@@ -0,0 +1,191 @@
1
+#!/usr/bin/python
2
+# Copyright (c) 2020 INSA Toulouse
3
+# ALL RIGHTS RESERVED.
4
+#
5
+# This topology has been built by inspiring on the 'default_single_dc_topology.py' example of son-emu
6
+# 
7
+# Authors
8
+# Abdel Kader CHABI SIKA BONI (Master2 ILoRD at INSA Toulouse, chabisik@etud.insa-toulouse.fr)
9
+# Arnaud PRIEU                (5SDBD at INSA Toulouse, prieu@etud.insa-toulouse.fr)
10
+# Year: 2020-2021
11
+
12
+
13
+import logging
14
+from mininet.log import setLogLevel, info
15
+from emuvim.dcemulator.net import DCNetwork
16
+from emuvim.api.rest.rest_api_endpoint import RestApiEndpoint
17
+from emuvim.api.openstack.openstack_api_endpoint import OpenstackApiEndpoint
18
+
19
+logging.basicConfig(level=logging.INFO)
20
+setLogLevel('info')  # set Mininet loglevel
21
+logging.getLogger('werkzeug').setLevel(logging.DEBUG)
22
+logging.getLogger('api.openstack.base').setLevel(logging.DEBUG)
23
+logging.getLogger('api.openstack.compute').setLevel(logging.DEBUG)
24
+logging.getLogger('api.openstack.keystone').setLevel(logging.DEBUG)
25
+logging.getLogger('api.openstack.nova').setLevel(logging.DEBUG)
26
+logging.getLogger('api.openstack.neutron').setLevel(logging.DEBUG)
27
+logging.getLogger('api.openstack.heat').setLevel(logging.DEBUG)
28
+logging.getLogger('api.openstack.heat.parser').setLevel(logging.DEBUG)
29
+logging.getLogger('api.openstack.glance').setLevel(logging.DEBUG)
30
+logging.getLogger('api.openstack.helper').setLevel(logging.DEBUG)
31
+
32
+#####################################################################################################
33
+#                                OUR TOPOLOGY'S DETAILS                                             #
34
+#  (if changed, bootstrap server script must be changed too and the new config:topo image builded)  #
35
+#####################################################################################################
36
+BOOTSTRAP_SERVER = '10.10.10.10' #name = btrap; port = 5555
37
+
38
+SVR_IP = '10.0.0.1' #name = srv
39
+
40
+GWI1_IP = '10.2.2.1' #name = gwi1
41
+GWI2_IP = '10.2.2.2' #name = gwi2
42
+
43
+GWF1_IP = '10.0.1.100' #name = gwf1
44
+DEV1_GWF1_IP = '10.0.1.1' #name = dev1gwf1
45
+DEV2_GWF1_IP = '10.0.1.2' #name = dev2gwf1
46
+DEV3_GWF1_IP = '10.0.1.3' #name = dev3gwf1
47
+
48
+GWF2_IP = '10.0.2.100' #name = gwf2
49
+DEV1_GWF2_IP = '10.0.2.1' #name = dev1gwf2
50
+DEV2_GWF2_IP = '10.0.2.2' #name = dev2gwf2
51
+DEV3_GWF2_IP = '10.0.2.3' #name = dev3gwf2
52
+
53
+GWF3_IP = '10.0.3.100' #name = gwf3
54
+DEV1_GWF3_IP = '10.0.3.1' #name = dev1gwf3
55
+DEV2_GWF3_IP = '10.0.3.2' #name = dev2gwf3
56
+DEV3_GWF3_IP = '10.0.3.3' #name = dev3gwf3
57
+
58
+'''
59
+TOPOLOGY OVERVIEW
60
+Necessary docker images: config:topo ; server:topo ; gateway:topo ; device:topo
61
+
62
+
63
+                                  ++++++++         ++++++++
64
+                                  + dev1 +---      + gwf1 +
65
+                                  ++++++++  |      ++++++++
66
+                                            |          |  ______________++++++++
67
+                                            |          |  |             + dev2 +
68
+                                ++++++++    |       ++++++++            ++++++++        ++++++++
69
+                                + gwi1 +    |_______+  s5  +----------------------------+ dev3 +
70
+                                ++++++++            ++++++++                            ++++++++              ++++++++
71
+                                   |                 |           _____________________________________________+ gwf2 +
72
+                                   |                 |           |                                            ++++++++
73
+ +++++++        +++++++         +++++++         +++++++      ++++++++                    ++++++++
74
+ + srv +--------+ s1  +---------+ s2  +---------+ s3  +------+  s6  +--------------------+ dev1 +
75
+ +++++++        +++++++         +++++++         +++++++      ++++++++                    ++++++++
76
+    |                             |                |            | |             ++++++++
77
+    |                             |                |            | |_____________+ dev2 +
78
+    |                             |                |            |               ++++++++
79
+    |                             |             ++++++          |     ++++++++
80
+    |                             |             + s4 +----      |_____+ dev3 +
81
+    |                             |             ++++++   |            ++++++++
82
+    |                         +++++++++           |      |
83
+    |                         + btrap +           |      |____++++++++        ++++++++
84
+    |                         +++++++++     ______|           +  s7  +--------+ dev1 +
85
+    |                                       |                 ++++++++        ++++++++
86
+    |                                       |    ______________| | |
87
+    |                               ________|    |               | |
88
+    |                               |            |               | |___________++++++++
89
+    |                               |            |               |             + dev2 +
90
+    |                            ++++++          |               |             ++++++++
91
+    |____________________________+ DC +      ++++++++         ++++++++
92
+                                 ++++++      + dev3 +         + gwf3 +
93
+                                             ++++++++         ++++++++
94
+'''
95
+#####################################################################################################
96
+
97
+
98
+def create_topology():
99
+    net = DCNetwork(monitor=False, enable_learning=True)
100
+
101
+    dc1 = net.addDatacenter("dc1")
102
+    # add OpenStack-like APIs to the emulated DC
103
+    api1 = OpenstackApiEndpoint("0.0.0.0", 6001)
104
+    api1.connect_datacenter(dc1)
105
+    api1.start()
106
+    api1.connect_dc_network(net)
107
+    # add the command line interface endpoint to the emulated DC (REST API)
108
+    rapi1 = RestApiEndpoint("0.0.0.0", 5001)
109
+    rapi1.connectDCNetwork(net)
110
+    rapi1.connectDatacenter(dc1)
111
+    rapi1.start()
112
+
113
+    info('*** Adding bootstrap server\n')
114
+    btrap = net.addDocker('btrap', ip=BOOTSTRAP_SERVER, dimage="config:topo")
115
+
116
+    info('*** Adding topology server\n')
117
+    srv = net.addDocker('srv', ip=SVR_IP, dimage="server:topo", environment={'MY_IP':SVR_IP})
118
+
119
+    info('*** Adding topology intermediary gateway\n')
120
+    gwi1 = net.addDocker('gwi1', ip=GWI1_IP, dimage="gateway:topo", environment={'MY_IP':GWI1_IP})
121
+
122
+    info('*** Adding topology final gateways\n')
123
+    gwf1 = net.addDocker('gwf1', ip=GWF1_IP, dimage="gateway:topo", environment={'MY_IP':GWF1_IP})
124
+    gwf2 = net.addDocker('gwf2', ip=GWF2_IP, dimage="gateway:topo", environment={'MY_IP':GWF2_IP})
125
+    gwf3 = net.addDocker('gwf3', ip=GWF3_IP, dimage="gateway:topo", environment={'MY_IP':GWF3_IP})
126
+
127
+    info('*** Adding 1st final gateway devices\n')
128
+    dev1gwf1 = net.addDocker('dev1gwf1', ip=DEV1_GWF1_IP, dimage="device:topo", environment={'MY_IP':DEV1_GWF1_IP})
129
+    dev2gwf1 = net.addDocker('dev2gwf1', ip=DEV2_GWF1_IP, dimage="device:topo", environment={'MY_IP':DEV2_GWF1_IP})
130
+    dev3gwf1 = net.addDocker('dev3gwf1', ip=DEV3_GWF1_IP, dimage="device:topo", environment={'MY_IP':DEV3_GWF1_IP})
131
+
132
+    info('*** Adding 2nd final gateway devices\n')
133
+    dev1gwf2 = net.addDocker('dev1gwf2', ip=DEV1_GWF2_IP, dimage="device:topo", environment={'MY_IP':DEV1_GWF2_IP})
134
+    dev2gwf2 = net.addDocker('dev2gwf2', ip=DEV2_GWF2_IP, dimage="device:topo", environment={'MY_IP':DEV2_GWF2_IP})
135
+    dev3gwf2 = net.addDocker('dev3gwf2', ip=DEV3_GWF2_IP, dimage="device:topo", environment={'MY_IP':DEV3_GWF2_IP})
136
+
137
+    info('*** Adding 3rd final gateway devices\n')
138
+    dev1gwf3 = net.addDocker('dev1gwf3', ip=DEV1_GWF3_IP, dimage="device:topo", environment={'MY_IP':DEV1_GWF3_IP})
139
+    dev2gwf3 = net.addDocker('dev2gwf3', ip=DEV2_GWF3_IP, dimage="device:topo", environment={'MY_IP':DEV2_GWF3_IP})
140
+    dev3gwf3 = net.addDocker('dev3gwf3', ip=DEV3_GWF3_IP, dimage="device:topo", environment={'MY_IP':DEV3_GWF3_IP})
141
+
142
+    info('*** Adding switches\n')
143
+    s1 = net.addSwitch('s1')
144
+    s2 = net.addSwitch('s2')
145
+    s3 = net.addSwitch('s3')
146
+    s4 = net.addSwitch('s4')
147
+    s5 = net.addSwitch('s5')
148
+    s6 = net.addSwitch('s6')
149
+    s7 = net.addSwitch('s7')
150
+
151
+    info('*** Creating links\n')
152
+    net.addLink(btrap, s2)
153
+    net.addLink(s1, s2)
154
+    net.addLink(s1, srv)
155
+    net.addLink(gwi1, s2)
156
+    net.addLink(s2, s3)
157
+    net.addLink(s3, s4)
158
+    net.addLink(dc1, s4)
159
+    net.addLink(dc1, srv) #
160
+    ########ZONE1###########
161
+    net.addLink(s3, s5)
162
+    net.addLink(gwf1, s5)
163
+    net.addLink(dev1gwf1, s5)
164
+    net.addLink(dev2gwf1, s5)
165
+    net.addLink(dev3gwf1, s5)
166
+    ########ZONE2###########
167
+    net.addLink(s3, s6)
168
+    net.addLink(gwf2, s6)
169
+    net.addLink(dev1gwf2, s6)
170
+    net.addLink(dev2gwf2, s6)
171
+    net.addLink(dev3gwf2, s6)
172
+    ########ZONE3###########
173
+    net.addLink(s4, s7)
174
+    net.addLink(gwf3, s7)
175
+    net.addLink(dev1gwf3, s7)
176
+    net.addLink(dev2gwf3, s7)
177
+    net.addLink(dev3gwf3, s7)
178
+
179
+    info('*** Starting network\n')
180
+    net.start()
181
+    net.CLI()
182
+    # when the user types exit in the CLI, we stop the emulator
183
+    net.stop()
184
+
185
+
186
+def main():
187
+    create_topology()
188
+
189
+
190
+if __name__ == '__main__':
191
+    main()

Loading…
Cancel
Save