73 lines
2.7 KiB
Python
Executable file
73 lines
2.7 KiB
Python
Executable file
#!/usr/bin/python
|
||
'''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
|
||
|
||
app = Flask(__name__)
|
||
|
||
SVR_IP = '192.168.0.1' #name = srv
|
||
|
||
GWI1_IP = '10.0.1.1' #name = gwi1
|
||
GWI2_IP = '10.0.1.2' #name = gwi2
|
||
|
||
GWF1_IP = '10.0.0.1' #name = gwf1
|
||
DEV1_GWF1_IP = '192.168.1.1' #name = dev1gwf1
|
||
DEV2_GWF1_IP = '192.168.1.2' #name = dev2gwf1
|
||
DEV3_GWF1_IP = '192.168.1.3' #name = dev3gwf1
|
||
|
||
GWF2_IP = '10.0.0.2' #name = gwf2
|
||
DEV1_GWF2_IP = '192.168.2.1' #name = dev1gwf2
|
||
DEV2_GWF2_IP = '192.168.2.2' #name = dev2gwf2
|
||
DEV3_GWF2_IP = '192.168.2.3' #name = dev3gwf2
|
||
|
||
GWF3_IP = '10.0.0.3' #name = gwf3
|
||
DEV1_GWF3_IP = '192.168.3.1' #name = dev1gwf3
|
||
DEV2_GWF3_IP = '192.168.3.2' #name = dev2gwf3
|
||
DEV3_GWF3_IP = '192.168.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):
|
||
configs = ""
|
||
if my_ip==SVR_IP:
|
||
configs = SERVER%('srv')
|
||
elif my_ip==GWI1_IP:
|
||
configs = GATEWAY_I%('gwi1',SVR_IP,'srv')
|
||
elif my_ip==GWI2_IP:
|
||
configs = GATEWAY_I%('gwi2',SVR_IP,'srv')
|
||
elif my_ip==GWF1_IP:
|
||
configs = GATEWAY_F%('gwf1',GWI1_IP,'gwi1')
|
||
elif my_ip==GWF2_IP:
|
||
configs = GATEWAY_F%('gwf2',GWI1_IP,'gwi1')
|
||
elif my_ip==GWF3_IP:
|
||
configs = GATEWAY_F%('gwf3',GWI1_IP,'gwi1')
|
||
elif my_ip==DEV1_GWF1_IP:
|
||
configs = DEV%('dev1gwf1',GWF1_IP,'gwf1')
|
||
elif my_ip==DEV2_GWF1_IP:
|
||
configs = DEV%('dev2gwf1',GWF1_IP,'gwf1')
|
||
elif my_ip==DEV3_GWF1_IP:
|
||
configs = DEV%('dev3gwf1',GWF1_IP,'gwf1')
|
||
elif my_ip==DEV1_GWF2_IP:
|
||
configs = DEV%('dev1gwf2',GWF2_IP,'gwf2')
|
||
elif my_ip==DEV2_GWF2_IP:
|
||
configs = DEV%('dev2gwf2',GWF2_IP,'gwf2')
|
||
elif my_ip==DEV3_GWF2_IP:
|
||
configs = DEV%('dev3gwf2',GWF2_IP,'gwf2')
|
||
elif my_ip==DEV1_GWF3_IP:
|
||
configs = DEV%('dev1gwf3',GWF3_IP,'gwf3')
|
||
elif my_ip==DEV2_GWF3_IP:
|
||
configs = DEV%('dev2gwf3',GWF3_IP,'gwf3')
|
||
elif my_ip==DEV3_GWF3_IP:
|
||
configs = DEV%('dev3gwf3',GWF3_IP,'gwf3')
|
||
return configs
|
||
|
||
if __name__=='__main__':
|
||
app.run(debug=False, host='0.0.0.0', port=5555)
|
||
|