def __init__(self, CONFIG_, logger, observerable, run_event): #super(IpopController, self).__init__("controller") #self.observable = observer.Observable() #self.observable.register(self) global CONFIG CONFIG = CONFIG_ self.run_event = run_event self.observable = observerable il.UdpServer.__init__(self, CONFIG["xmpp_username"], CONFIG["xmpp_password"], CONFIG["xmpp_host"], CONFIG["ip4"], logger) self.idle_peers = {} self.user = CONFIG["xmpp_username"] # XMPP username self.password = CONFIG["xmpp_password"] # XMPP Password self.host = CONFIG["xmpp_host"] # XMPP host self.ip4 = CONFIG["ip4"] self.uid = il.gen_uid(self.ip4) # SHA-1 hash self.vpn_type = CONFIG["controller_type"] self.ctrl_conn_init() global logging print dir(logger) logging = logger print dir(logging) logging.error("what") self.uid_ip_table = {} parts = CONFIG["ip4"].split(".") ip_prefix = parts[0] + "." + parts[1] + "." # Populating the uid_ip_table with all the IPv4 addresses # and the corresponding UIDs in the /16 subnet for i in range(0, 255): for j in range(0, 255): ip = ip_prefix + str(i) + "." + str(j) uid = il.gen_uid(ip) self.uid_ip_table[uid] = ip # Ignore the network interfaces in the list if "network_ignore_list" in CONFIG: logging.debug("network ignore list") il.make_call(self.sock, m="set_network_ignore_list",\ network_ignore_list=CONFIG["network_ignore_list"])
def initialize(self,): # Make Tincan API calls to initialize the controller # Set logging level ipoplib.do_set_logging(self.sock, self.CONFIG["CFx"]["tincan_logging"]) if(self.vpn_type == "GroupVPN"): ipoplib.do_set_translation(self.sock, 0) ipoplib.do_set_switchmode(self.sock, self.CONFIG["TincanSender"] ["switchmode"]) elif(self.vpn_type == "SocialVPN"): ipoplib.do_set_translation(self.sock, 1) # Callback endpoint to receive notifications ipoplib.do_set_cb_endpoint(self.sock, self.sock.getsockname()) # Configure the local node if not self.CONFIG["CFx"]["router_mode"]: ipoplib.do_set_local_ip(self.sock, self.uid, self.ip4, self.ip6, self.CONFIG["CFx"]["ip4_mask"], self.CONFIG["CFx"]["ip6_mask"], self.CONFIG["CFx"]["subnet_mask"], self.CONFIG["TincanSender"]["switchmode"]) else: ipoplib.do_set_local_ip(self.sock, self.uid, self.CONFIG["CFx"]["router_ip"], self.ip6, self.CONFIG["CFx"]["router_ip4_mask"], self.CONFIG["CFx"]["router_ip6_mask"], self.CONFIG["CFx"]["subnet_mask"], self.CONFIG["TincanSender"]["switchmode"]) # Register to the XMPP server ipoplib.do_register_service(self.sock, self.user, self.password, self.host) ipoplib.do_set_trimpolicy(self.sock, self.CONFIG["CFx"]["trim_enabled"]) # Retrieve the state of the local node ipoplib.do_get_state(self.sock) # Ignore the network interfaces in the list if "network_ignore_list" in self.CONFIG["CFx"]: ipoplib.make_call(self.sock, m="set_network_ignore_list", network_ignore_list=CONFIG["CFx"] ["network_ignore_list"]) print "CFx initialized. Loading Controller Modules\n" self.loaded_modules = ['CFx'] # List of modules already loaded # Check for circular dependencies in config.json dependency_graph = {} for key in self.json_data: if(key != 'CFx'): try: dependency_graph[key] = self.json_data[key]['dependencies'] except: pass if(self.detect_cyclic_dependency(dependency_graph)): print "Circular dependency detected in config.json. Exiting" sys.exit() # Iterate through the modules mentioned in config.json # and load them. for key in self.json_data: if (key not in self.loaded_modules): self.load_module(key) # Start all the worker and timer threads for handle in self.CFxHandleDict: self.CFxHandleDict[handle].CMThread.start() if(self.CFxHandleDict[handle].timer_thread): self.CFxHandleDict[handle].timer_thread.start()