icds/Dockerfiles/forContainerNet/bootserver/bootstrap_server.py
2021-01-02 01:17:09 +01:00

159 行
5.7 KiB
Python
可执行文件

此文件含有不可见的 Unicode 字符

此文件含有人类无法区分的不可见的 Unicode 字符,但可以由计算机进行不同的处理。 如果您是想特意这样的,可以安全地忽略该警告。 使用 Escape 按钮显示他们。

#!/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"
'''
@app.route("/getmyconfig/<string:my_ip>")
def configurations_giver(my_ip="127.0.0.1"):
configs = {"local_ip":my_ip, "verdict":"oops"}
if my_ip==SVR_IP:
configs["local_port"] = 8080
configs["local_name"] = "srv"
configs["verdict"] = "yes"
elif my_ip==GWI1_IP:
configs["local_port"] = 8181
configs["local_name"] = "gwi1"
configs["remote_ip"] = SVR_IP
configs["remote_port"] = 8080
configs["remote_name"] = "srv"
configs["verdict"] = "yes"
elif my_ip==GWF1_IP:
configs["local_port"] = 8282
configs["local_name"] = "gwf1"
configs["remote_ip"] = GWI1_IP
configs["remote_port"] = 8181
configs["remote_name"] = "gwi1"
configs["verdict"] = "yes"
elif my_ip==GWF2_IP:
configs["local_port"] = 8282
configs["local_name"] = "gwf2"
configs["remote_ip"] = GWI1_IP
configs["remote_port"] = 8181
configs["remote_name"] = "gwi1"
configs["verdict"] = "yes"
elif my_ip==GWF3_IP:
configs["local_port"] = 8282
configs["local_name"] = "gwf3"
configs["remote_ip"] = GWI1_IP
configs["remote_port"] = 8181
configs["remote_name"] = "gwi1"
configs["verdict"] = "yes"
elif my_ip==DEV1_GWF1_IP:
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:
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:
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:
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:
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:
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:
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:
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:
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():
configs = {"local_ip":GWI2_IP, "verdict":"yes"}
configs["local_port"] = 8181
configs["local_name"] = "gwi2"
configs["remote_ip"] = SVR_IP
configs["remote_port"] = 8080
configs["remote_name"] = "srv"
return jsonify(configs)
if __name__=='__main__':
app.run(debug=False, host='0.0.0.0', port=5555)