#!/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 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/") def configurations_giver(my_ip): configs = {"local_ip":"127.0.0.1", "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==GWI2_IP: configs["local_port"] = 8181 configs["local_name"] = "gwi2" 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) if __name__=='__main__': app.run(debug=False, host='0.0.0.0', port=5555)