def ctrl_conn_init(self):
        il.do_set_logging(self.sock, CONFIG["tincan_logging"])

        # Callback endpoint to receive notifications
        il.do_set_cb_endpoint(self.sock, self.sock.getsockname()) 

        il.do_set_local_ip(self.sock, self.uid, self.ip4, il.gen_ip6(self.uid),
                           CONFIG["ip4_mask"], CONFIG["ip6_mask"], 
                           CONFIG["subnet_mask"], CONFIG["switchmode"],
                           CONFIG["mtu"], CONFIG["internal_mtu"])

        # Register to the XMPP server
        il.do_register_service(self.sock, self.user, self.password, self.host) 
        il.do_set_switchmode(self.sock, CONFIG["switchmode"])
        il.do_set_trimpolicy(self.sock, CONFIG["trim_enabled"])
        il.do_get_state(self.sock) # Information about the local node
示例#2
0
    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()