Exemplo n.º 1
0
 def create_virtual_networks(self,):
     for i in range(len(self.CMConfig["Vnets"])):
         vnetdetails = self.CMConfig["Vnets"][i]
         vn = ipoplib.VNET
         # Create VNET Request Message
         self.registerCBT("Logger", "info", "Creating Vnet {0}".format(vnetdetails["TapName"]))
         vn["IPOP"]["Request"]["InterfaceName"] = vnetdetails["TapName"]
         vn["IPOP"]["Request"]["Description"] = vnetdetails["Description"]
         vn["IPOP"]["Request"]["LocalVirtIP4"] = vnetdetails["IP4"]
         vn["IPOP"]["Request"]["LocalPrefix4"] = vnetdetails["IP4PrefixLen"]
         if "MTU4" in vnetdetails:
             vn["IPOP"]["Request"]["MTU4"] = vnetdetails["MTU4"]
         vnetdetails["uid"] = fxlib.gen_uid(vnetdetails["IP4"])
         vn["IPOP"]["Request"]["LocalUID"] = vnetdetails["uid"]
         # Currently configured to take the first stun address
         vn["IPOP"]["Request"]["StunAddress"] = self.CMConfig["Stun"][0]
         if "Turn" in self.CMConfig:
             if self.CMConfig["Turn"][0]["Address"] is not None:
                 vn["IPOP"]["Request"]["TurnAddress"] = self.CMConfig["Turn"][0]["Address"]
             if self.CMConfig["Turn"][0]["User"] is not None:
                 vn["IPOP"]["Request"]["TurnUser"] = self.CMConfig["Turn"][0]["User"]
             if self.CMConfig["Turn"][0]["Password"] is not None:
                 vn["IPOP"]["Request"]["TurnPass"] = self.CMConfig["Turn"][0]["Password"]
         if "IPMappingEnabled" in vnetdetails:
             vn["IPOP"]["Request"]["IPMappingEnabled"] = vnetdetails["IPMappingEnabled"]
         vn["IPOP"]["Request"]["L2TunnelEnabled"] = True
         vn["IPOP"]["TransactionId"] = self.trans_counter
         self.trans_counter += 1
         self.send_msg(json.dumps(vn))
Exemplo n.º 2
0
 def create_virtual_networks(self, ):
     for i in range(len(self.CMConfig["Vnets"])):
         vnetdetails = self.CMConfig["Vnets"][i]
         vn = ipoplib.VNET
         # Create VNET Request Message
         self.registerCBT(
             "Logger", "info",
             "Creating Vnet {0}".format(vnetdetails["TapName"]))
         vn["IPOP"]["Request"]["InterfaceName"] = vnetdetails["TapName"]
         vn["IPOP"]["Request"]["Description"] = vnetdetails["Description"]
         vn["IPOP"]["Request"]["LocalVirtIP4"] = vnetdetails["IP4"]
         vn["IPOP"]["Request"]["LocalPrefix4"] = vnetdetails["IP4PrefixLen"]
         if "MTU4" in vnetdetails:
             vn["IPOP"]["Request"]["MTU4"] = vnetdetails["MTU4"]
         vnetdetails["uid"] = fxlib.gen_uid(vnetdetails["IP4"])
         vn["IPOP"]["Request"]["LocalUID"] = vnetdetails["uid"]
         # Currently configured to take the first stun address
         vn["IPOP"]["Request"]["StunAddress"] = self.CMConfig["Stun"][0]
         if "Turn" in self.CMConfig:
             if self.CMConfig["Turn"][0]["Address"] is not None:
                 vn["IPOP"]["Request"]["TurnAddress"] = self.CMConfig[
                     "Turn"][0]["Address"]
             if self.CMConfig["Turn"][0]["User"] is not None:
                 vn["IPOP"]["Request"]["TurnUser"] = self.CMConfig["Turn"][
                     0]["User"]
             if self.CMConfig["Turn"][0]["Password"] is not None:
                 vn["IPOP"]["Request"]["TurnPass"] = self.CMConfig["Turn"][
                     0]["Password"]
         if "IPMappingEnabled" in vnetdetails:
             vn["IPOP"]["Request"]["IPMappingEnabled"] = vnetdetails[
                 "IPMappingEnabled"]
         vn["IPOP"]["Request"]["L2TunnelEnabled"] = True
         vn["IPOP"]["TransactionId"] = self.trans_counter
         self.trans_counter += 1
         self.send_msg(json.dumps(vn))
Exemplo n.º 3
0
    def __init__(self):
        self.parse_config()
        fxlib.CONFIG = self.CONFIG

        # CFxHandleDict is a dict containing the references to
        # CFxHandles of all CMs with key as the module name and
        # value as the CFxHandle reference
        self.CFxHandleDict = {}

        self.vpn_type = self.CONFIG['CFx']['vpn_type']
        self.user = self.CONFIG['CFx']["xmpp_username"]
        self.password = self.CONFIG['CFx']["xmpp_password"]
        self.host = self.CONFIG['CFx']["xmpp_host"]
        self.port = self.CONFIG['CFx']["xmpp_port"]

        if self.vpn_type == 'GroupVPN':
            self.ip4 = self.CONFIG['BaseTopologyManager']["ip4"]
            self.uid = fxlib.gen_uid(self.ip4)  # SHA-1 Hash
        elif self.vpn_type == 'SocialVPN':
            self.ip4 = self.CONFIG['AddressMapper']["ip4"]
            self.uid = self.CONFIG['CFx']['local_uid']
        self.ip6 = fxlib.gen_ip6(self.uid)

        if socket.has_ipv6:
            self.sock = socket.socket(socket.AF_INET6, socket.SOCK_DGRAM)
            self.sock_svr = socket.socket(socket.AF_INET6, socket.SOCK_DGRAM)
            self.sock_svr.bind((self.CONFIG['TincanSender']["localhost6"],
                                self.CONFIG['CFx']["contr_port"]))
        else:
            self.sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
            self.sock_svr = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
            self.sock_svr.bind((self.CONFIG['TincanSender']["localhost"],
                                self.CONFIG['CFx']["contr_port"]))
        self.sock.bind(("", 0))
        self.sock_list = [self.sock, self.sock_svr]
Exemplo n.º 4
0
    def __init__(self):
        self.parse_config()
        fxlib.CONFIG = self.CONFIG

        # CFxHandleDict is a dict containing the references to
        # CFxHandles of all CMs with key as the module name and
        # value as the CFxHandle reference
        self.CFxHandleDict = {}

        self.vpn_type = self.CONFIG['CFx']['vpn_type']
        self.user = self.CONFIG['CFx']["xmpp_username"]
        self.password = self.CONFIG['CFx']["xmpp_password"]
        self.host = self.CONFIG['CFx']["xmpp_host"]
        self.port = self.CONFIG['CFx']["xmpp_port"]
        
        if self.vpn_type == 'GroupVPN':
            self.ip4 = self.CONFIG['BaseTopologyManager']["ip4"]
            self.uid = fxlib.gen_uid(self.ip4)  # SHA-1 Hash
        elif self.vpn_type == 'SocialVPN':
            self.ip4 = self.CONFIG['AddressMapper']["ip4"]
            self.uid = self.CONFIG['CFx']['local_uid']
        self.ip6 = fxlib.gen_ip6(self.uid)

        if socket.has_ipv6:
            self.sock = socket.socket(socket.AF_INET6, socket.SOCK_DGRAM)
            self.sock_svr = socket.socket(socket.AF_INET6, socket.SOCK_DGRAM)
            self.sock_svr.bind((self.CONFIG['TincanSender']["localhost6"],
                                self.CONFIG['CFx']["contr_port"]))
        else:
            self.sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
            self.sock_svr = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
            self.sock_svr.bind((self.CONFIG['TincanSender']["localhost"],
                                self.CONFIG['CFx']["contr_port"]))
        self.sock.bind(("", 0))
        self.sock_list = [self.sock, self.sock_svr]
    def __init__(self, CFxHandle, paramDict):

        super(BaseTopologyManager, self).__init__()
        self.CFxHandle = CFxHandle
        self.CMConfig = paramDict
        self.ipop_state = None
        self.interval_counter = 0
        self.cv_interval = 5
        self.use_visualizer = False

        self.uid = ""
        self.ip4 = ""
        self.local_state = {}

        # peers (linked nodes)
        self.peers = {}

        # links:
        #   self.links["successor"] = { uid: None }
        #   self.links["chord"]     = { uid: {"log_uid": log_uid, "ttl": ttl} }
        #   self.links["on_demand"] = { uid: {"ttl": ttl, "rate": rate} }
        #   self.links["inbound"]   = { uid: None }

        self.links = {
            "successor": {}, "chord": {}, "on_demand": {}, "inbound": {}
        }

        self.log_chords = []

        # discovered nodes
        #   self.discovered_nodes is the list of nodes used by the successors policy
        #   self.discovered_nodes_srv is the list of nodes obtained from peer_state
        #       notifications
        self.discovered_nodes = []
        self.discovered_nodes_srv = []

        # p2p overlay state
        self.p2p_state = "started"

        # address mapping
        self.uid_ip4_table = {}
        self.ip4_uid_table = {}

        # populate uid_ip4_table and ip4_uid_table with all UID and IPv4
        # mappings within the /16 subnet
        parts = self.CMConfig["ip4"].split(".")
        ip_prefix = parts[0] + "." + parts[1] + "."
        for i in range(0, 255):
            for j in range(0, 255):
                ip4 = ip_prefix + str(i) + "." + str(j)
                uid = fxlib.gen_uid(ip4)
                self.uid_ip4_table[uid] = ip4
                self.ip4_uid_table[ip4] = uid

        if 'use_central_visualizer' in self.CMConfig:
            self.use_visualizer = self.CMConfig["use_central_visualizer"]
        if "interval_central_visualizer" in self.CMConfig:
            self.cv_interval = self.CMConfig["interval_central_visualizer"]
Exemplo n.º 6
0
 def __init__(self,CFxHandle,paramDict,ModuleName):
     ControllerModule.__init__(self,CFxHandle,paramDict,ModuleName)
     self.xmpp_peers = defaultdict(int)
     # need to maintain uid<->jid mapping to route xmpp messages.
     self.uid_jid = {}
     self.jid_uid = defaultdict(lambda:['',False])
     self.xmpp_username = self.CMConfig.get("username")
     self.xmpp_passwd = self.CMConfig.get("password")
     self.xmpp_host = self.CMConfig.get("xmpp_host")
     self.uid = ""
     # time of last recvd xmpp advt.
     self.last_sent_advt = 0
     # keeps track of if xmpp advt recvd in interval
     self.xmpp_advt_recvd = True
     # Initial ADVT Delay
     self.INITIAL_ADVT_DELAY =5
     # interval between sending advertisements
     self.advt_delay = self.INITIAL_ADVT_DELAY
     # Maximum delay between advertisements is 10 minutes
     self.MAX_ADVT_DELAY = 600 
     # initialize the base Xmpp client class
     sleekxmpp.ClientXMPP.__init__(self,self.xmpp_username,self.xmpp_passwd,sasl_mech='PLAIN')
     self['feature_mechanisms'].unencrypted_plain = True
     # register a new plugin stanza and handler for it,
     # whenever a matching message will be received on 
     # the xmpp stream , registered handler will be called.
     register_stanza_plugin(Message, Ipop_Msg)
     self.registerHandler(
             Callback('Ipop',
             StanzaPath('message/Ipop'),
             self.MsgListener))
     # Register event handler for session start 
     self.add_event_handler("session_start",self.start)
     # calculate UID, for the meantime
     # address mapping
     self.uid_ip4_table = {}
     self.ip4_uid_table = {}
     # populate uid_ip4_table and ip4_uid_table with all UID and IPv4
     # mappings within the /16 subnet
     parts = self.CMConfig["ip4"].split(".")
     ip_prefix = parts[0] + "." + parts[1] + "."
     for i in range(0, 255):
         for j in range(0, 255):
             ip4 = ip_prefix + str(i) + "." + str(j)
             uid = fxlib.gen_uid(ip4)
             self.uid_ip4_table[uid] = ip4
             self.ip4_uid_table[ip4] = uid
     self.uid = self.ip4_uid_table[self.CMConfig["ip4"]]
     # Start xmpp handling thread
     self.xmpp_handler()
Exemplo n.º 7
0
 def __init__(self,CFxHandle,paramDict,ModuleName):
     ControllerModule.__init__(self,CFxHandle,paramDict,ModuleName)
     self.xmpp_peers = defaultdict(int)
     # need to maintain uid<->jid mapping to route xmpp messages.
     self.uid_jid = {}
     self.xmpp_username = self.CMConfig.get("username")
     self.xmpp_passwd = self.CMConfig.get("password")
     self.xmpp_host = self.CMConfig.get("xmpp_host")
     self.uid = ""
     # initialize the base Xmpp client class
     sleekxmpp.ClientXMPP.__init__(self,self.xmpp_username,self.xmpp_passwd)
     # register a new plugin stanza and handler for it,
     # whenever a matching message will be received on 
     # the xmpp stream , registered handler will be called.
     register_stanza_plugin(Message, Ipop_Msg)
     self.registerHandler(
             Callback('Ipop',
             StanzaPath('message/Ipop'),
             self.MsgListener))
     # Register event handler for session start 
     self.add_event_handler("session_start",self.start)
     # calculate UID, for the meantime
     # address mapping
     self.uid_ip4_table = {}
     self.ip4_uid_table = {}
     # populate uid_ip4_table and ip4_uid_table with all UID and IPv4
     # mappings within the /16 subnet
     parts = self.CMConfig["ip4"].split(".")
     ip_prefix = parts[0] + "." + parts[1] + "."
     for i in range(0, 255):
         for j in range(0, 255):
             ip4 = ip_prefix + str(i) + "." + str(j)
             uid = fxlib.gen_uid(ip4)
             self.uid_ip4_table[uid] = ip4
             self.ip4_uid_table[ip4] = uid
     self.uid = self.ip4_uid_table[self.CMConfig["ip4"]]
     # Start xmpp handling thread
     self.xmpp_handler()
Exemplo n.º 8
0
 def __init__(self, CFxHandle, paramDict, ModuleName):
     ControllerModule.__init__(self, CFxHandle, paramDict, ModuleName)
     self.xmpp_peers = defaultdict(int)
     # need to maintain uid<->jid mapping to route xmpp messages.
     self.uid_jid = {}
     self.xmpp_username = self.CMConfig.get("username")
     self.xmpp_passwd = self.CMConfig.get("password")
     self.xmpp_host = self.CMConfig.get("xmpp_host")
     self.uid = ""
     # initialize the base Xmpp client class
     sleekxmpp.ClientXMPP.__init__(self, self.xmpp_username,
                                   self.xmpp_passwd)
     # register a new plugin stanza and handler for it,
     # whenever a matching message will be received on
     # the xmpp stream , registered handler will be called.
     register_stanza_plugin(Message, Ipop_Msg)
     self.registerHandler(
         Callback('Ipop', StanzaPath('message/Ipop'), self.MsgListener))
     # Register event handler for session start
     self.add_event_handler("session_start", self.start)
     # calculate UID, for the meantime
     # address mapping
     self.uid_ip4_table = {}
     self.ip4_uid_table = {}
     # populate uid_ip4_table and ip4_uid_table with all UID and IPv4
     # mappings within the /16 subnet
     parts = self.CMConfig["ip4"].split(".")
     ip_prefix = parts[0] + "." + parts[1] + "."
     for i in range(0, 255):
         for j in range(0, 255):
             ip4 = ip_prefix + str(i) + "." + str(j)
             uid = fxlib.gen_uid(ip4)
             self.uid_ip4_table[uid] = ip4
             self.ip4_uid_table[ip4] = uid
     self.uid = self.ip4_uid_table[self.CMConfig["ip4"]]
     # Start xmpp handling thread
     self.xmpp_handler()
Exemplo n.º 9
0
    def __init__(self):
        self.CONFIG = {}
        self.parse_config()

        #fxlib.CONFIG = self.CONFIG
        self.transaction_counter = 0
        # CFxHandleDict is a dict containing the references to
        # CFxHandles of all CMs with key as the module name and
        # value as the CFxHandle reference
        self.CFxHandleDict = {}

        self.vpn_type = self.CONFIG['CFx']['Model']

        if self.vpn_type == 'GroupVPN':
            self.vnetdetails = self.CONFIG["Tincan"]["Vnets"]
            for k in range(len(self.vnetdetails)):
                ip4 = self.vnetdetails[k]["IP4"]
                self.vnetdetails[k]["uid"] = fxlib.gen_uid(ip4)
                self.vnetdetails[k]["ip6"] = fxlib.gen_ip6(
                    self.vnetdetails[k]["uid"])
        elif self.vpn_type == 'SocialVPN':
            self.ip4 = self.CONFIG['AddressMapper']["ip4"]
            self.uid = self.CONFIG['CFx']['local_uid']
            self.ip6 = fxlib.gen_ip6(self.uid)

        if socket.has_ipv6:
            self.sock = socket.socket(socket.AF_INET6, socket.SOCK_DGRAM)
            self.sock_svr = socket.socket(socket.AF_INET6, socket.SOCK_DGRAM)
            self.sock_svr.bind(("::1", self.CONFIG['CFx']["contr_port"]))
        else:
            self.sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
            self.sock_svr = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
            self.sock_svr.bind((self.CONFIG['TincanSender']["localhost"],
                                self.CONFIG['CFx']["contr_port"]))
        self.sock.bind(("", 0))
        self.sock_list = [self.sock, self.sock_svr]
    def __init__(self, CFxHandle, paramDict, ModuleName):

        super(BaseTopologyManager, self).__init__(CFxHandle, paramDict, ModuleName)
        self.CFxHandle = CFxHandle
        self.CMConfig = paramDict
        self.ipop_state = None
        self.interval_counter = 0
        self.cv_interval = 5
        self.use_visualizer = False
        # need this to query for peer state since it is no longer maintained 
        # by tincan.
        self.peer_uids = defaultdict(int)

        self.uid = ""
        self.ip4 = ""

        # peers (linked nodes)
        self.peers = {}

        # links:
        #   self.links["successor"] = { uid: None }
        #   self.links["chord"]     = { uid: {"log_uid": log_uid, "ttl": ttl} }
        #   self.links["on_demand"] = { uid: {"ttl": ttl, "rate": rate} }
        self.links = {
            "successor": {}, "chord": {}, "on_demand": {}
        }

        self.log_chords = []

        self.max_num_links = self.CMConfig["num_successors"] + \
                             self.CMConfig["num_chords"] + \
                             self.CMConfig["num_on_demand"] + \
                             self.CMConfig["num_inbound"]

        # discovered nodes
        #   self.discovered_nodes is the list of nodes used by the successors policy
        #   self.discovered_nodes_srv is the list of nodes obtained from peer_state
        #       notifications
        self.discovered_nodes = []
        self.discovered_nodes_srv = []

        # p2p overlay state
        self.p2p_state = "started"

        # address mapping
        self.uid_ip4_table = {}
        self.ip4_uid_table = {}

        # populate uid_ip4_table and ip4_uid_table with all UID and IPv4
        # mappings within the /16 subnet
        parts = self.CFxHandle.queryParam("ip4").split(".")
        ip_prefix = parts[0] + "." + parts[1] + "."
        for i in range(0, 255):
            for j in range(0, 255):
                ip4 = ip_prefix + str(i) + "." + str(j)
                uid = fxlib.gen_uid(ip4)
                self.uid_ip4_table[uid] = ip4
                self.ip4_uid_table[ip4] = uid

        if 'use_central_visualizer' in self.CMConfig:
            self.use_visualizer = self.CMConfig["use_central_visualizer"]
        if "interval_central_visualizer" in self.CMConfig:
            self.cv_interval = self.CMConfig["interval_central_visualizer"]
Exemplo n.º 11
0
    def __init__(self,CFxHandle,paramDict,ModuleName):
        ControllerModule.__init__(self,CFxHandle,paramDict,ModuleName)
        # keeps track of last recvd advertisement and if node is active on XMPP.
        self.xmpp_peers = defaultdict(lambda:[0,False])
        # need to maintain uid<->jid mapping to route xmpp messages.
        self.uid_jid = {}
        # FullJID,Knows my UID,num(Correct advts recvd)
        self.jid_uid = defaultdict(lambda:['',False,1])
        self.xmpp_username = self.CMConfig.get("xmpp_username")
        self.xmpp_passwd = self.CMConfig.get("xmpp_password")
        self.xmpp_host = self.CMConfig.get("xmpp_host")
        self.xmpp_port = self.CMConfig.get("xmpp_port")
        self.vpn_type = self.CFxHandle.queryParam("vpn_type")
        self.uid = ""
        # time of last recvd xmpp advt.
        self.last_sent_advt = 0
        # keeps track of if xmpp advt recvd in interval
        self.xmpp_advt_recvd = True
        # Initial ADVT Delay
        self.INITIAL_ADVT_DELAY =5
        # interval between sending advertisements
        self.advt_delay = self.INITIAL_ADVT_DELAY
        # Maximum delay between advertisements is 10 minutes
        self.MAX_ADVT_DELAY = 600 
        # initialize the base Xmpp client class, handle login/authentication.
        if self.CMConfig.get("xmpp_authentication_method")=="x509" and \
            (self.CMConfig.get("xmpp_username")!= None \
                or self.CMConfig.get("xmpp_password")!= None):
            raise RuntimeError("x509 Authentication Exception. Username or Password present in IPOP configuration file.")

        use_tls = True
        if self.CMConfig.get("xmpp_authentication_method")=="x509":
            sleekxmpp.ClientXMPP.__init__(self,self.xmpp_host,self.xmpp_passwd,sasl_mech='EXTERNAL')
            self.ssl_version = ssl.PROTOCOL_TLSv1
            self.ca_certs = self.CMConfig.get("truststore")
            self.certfile = self.CMConfig.get("certdirectory")+self.CMConfig.get("certfile")
            self.keyfile = self.CMConfig.get("certdirectory")+self.CMConfig.get("keyfile")
        else:
            sleekxmpp.ClientXMPP.__init__(self, self.xmpp_username, self.xmpp_passwd, sasl_mech='PLAIN')
            if self.CMConfig.get("xmpp_accept_untrusted_server")==True:
                self['feature_mechanisms'].unencrypted_plain = True
                use_tls = False
            else:
                self.ca_certs = self.CMConfig.get("truststore")
        # register a new plugin stanza and handler for it,
        # whenever a matching message will be received on 
        # the xmpp stream , registered handler will be called.
        register_stanza_plugin(Message, Ipop_Msg)
        self.registerHandler(
                Callback('Ipop',
                StanzaPath('message/Ipop'),
                self.MsgListener))
        # Register event handler for session start 
        self.add_event_handler("session_start",self.start)
        # calculate UID, for the meantime
        # address mapping
        self.uid_ip4_table = {}
        self.ip4_uid_table = {}
        # populate uid_ip4_table and ip4_uid_table with all UID and IPv4
        # mappings within the /16 subnet
        if (self.vpn_type == "GroupVPN"):
            parts = self.CFxHandle.queryParam("ip4").split(".")
            ip_prefix = parts[0] + "." + parts[1] + "."
            for i in range(0, 255):
                for j in range(0, 255):
                    ip4 = ip_prefix + str(i) + "." + str(j)
                    uid = fxlib.gen_uid(ip4)
                    self.uid_ip4_table[uid] = ip4
                    self.ip4_uid_table[ip4] = uid
            self.uid = self.ip4_uid_table[self.CFxHandle.queryParam("ip4")]
        elif (self.vpn_type == "SocialVPN"):
            self.registerCBT('Watchdog', 'QUERY_IPOP_STATE')
        # Start xmpp handling thread
        self.xmpp_handler()