icds/Dockerfiles/forContainerNet/bootserver/bootstrap_server.py
Abdel-Kader Chabi-Sika-Boni 45612c1d88 mise a jour
2021-01-02 18:20:06 +01:00

194 lines
6.9 KiB
Python
Executable file
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/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)