def connect_cloud_agent(manager, method="geo"):
    cloud_agents = get_cloud_agents(manager)
    client_info = ipinfo()
    if not client_info['hostname']:
        client_info['hostname'] = socket.gethostname()
    elif "No" in client_info['hostname']:
        client_info['hostname'] = socket.gethostname()

    if method == "geo":
        connected_cloud_agent, connected_cloud_agent_ip = geo_connect(client_info, cloud_agents)
    elif method == "net":
        connected_cloud_agent, connected_cloud_agent_ip = net_connect(cloud_agents)
    else:
        print "Unknown method to connect to a cloud agent!"
        return None
    ## Post the info the the centralized manager
    client_info['locator'] = connected_cloud_agent

    num_tries = 0
    while (not notify_manager(manager, method, client_info)) and (num_tries < 3):
        num_tries += 1

    if num_tries == 3:
        print "Try to notify the manager 3 times but all failed."

    return {'name' : connected_cloud_agent, 'ip' : connected_cloud_agent_ip}
def get_node_details(node_ip_file, outputFolder):
    nodes = json.load(open(node_ip_file))
    for user in nodes.keys():
        user_ip = nodes[user]
        user_info = ipinfo(user_ip)
        ## print user_info
        writeJson(outputFolder, user, user_info)
def get_first_mile_groups(inputFolder, silent_mode=True, outputFolder=os.getcwd() + "/data/", outputFileName="firstmile_group"):
    ## Get user QoE files
    qoe_files = glob.glob(inputFolder + "*")

    users = {}
    srv_info = {}

    ## Process each user QoE file
    for user_qoe_file in qoe_files:
        user_file_name = ntpath.basename(user_qoe_file)
        user_name = user_file_name.split('_')[0]
        ## print user_file_name
        srvs = get_all_servers(user_qoe_file)

        for srv in srvs:
            if srv not in users.keys():
                users[srv] = []

            if user_name not in users[srv]:
                users[srv].append(user_name)

        if silent_mode:
            continue

        if srv not in srv_info.keys():
            cur_srv_info = ipinfo(srv)
            srv_info[srv] = cur_srv_info

    if not silent_mode:
        writeJson(outputFolder, outputFileName, users)

    return users
Esempio n. 4
0
def connect_cloud_agent(manager, method="geo"):
    cloud_agents = get_cloud_agents(manager)
    client_info = ipinfo()
    if not client_info['hostname']:
        client_info['hostname'] = socket.gethostname()
    elif "No" in client_info['hostname']:
        client_info['hostname'] = socket.gethostname()

    if method == "geo":
        connected_cloud_agent, connected_cloud_agent_ip = geo_connect(
            client_info, cloud_agents)
    elif method == "net":
        connected_cloud_agent, connected_cloud_agent_ip = net_connect(
            cloud_agents)
    else:
        print "Unknown method to connect to a cloud agent!"
        return None
    ## Post the info the the centralized manager
    client_info['locator'] = connected_cloud_agent

    num_tries = 0
    while (not notify_manager(manager, method,
                              client_info)) and (num_tries < 3):
        num_tries += 1

    if num_tries == 3:
        print "Try to notify the manager 3 times but all failed."

    return {'name': connected_cloud_agent, 'ip': connected_cloud_agent_ip}
def get_ext_ip():
    ext_ip_info = ipinfo()
    ext_ip = ext_ip_info['ip']
    node_info = get_node_info(ext_ip, "client")
    hostname = socket.gethostname()
    if node_info['name'] == node_info['ip']:
        node_info['name'] = hostname
    return ext_ip, node_info
def get_ext_ip():
    node_info = get_node_info()
    ext_ip = node_info['ip']
    if not node_info:
        ext_ip = get_ext_ip_from_websites()
        node_info = ipinfo()
    hostname = socket.gethostname()
    if node_info['name'] == node_info['ip']:
        node_info['name'] = hostname
    return ext_ip, node_info
def get_ext_ip():
    node_info = get_node_info()
    ext_ip = node_info['ip']
    if not node_info:
        ext_ip = get_ext_ip_from_websites()
        node_info = ipinfo()
    hostname = socket.gethostname()
    if node_info['name'] == node_info['ip']:
        node_info['name'] = hostname
    return ext_ip, node_info
def get_hop_by_user(hop_file):
    ### Get client name and attache to the closest cache agent
    client_name = getMyName()
    # client_name = '75-130-96-12.static.oxfr.ma.charter.com'
    hop_data_folder = os.getcwd() + '/hopData/'
    hops_on_user = json.load(open(hop_file))
    if client_name in hops_on_user.keys():
        hops = hops_on_user[client_name]
        for hop in hops.keys():
            hop_info = ipinfo(hop)
            save_ipinfo(hop_data_folder, hop_info)
            print hop_info
def read_user_info(user_name):
    default_user_path = "./clientsInfo/nodes/"
    fileName = default_user_path + user_name + ".json"
    if os.path.exists(fileName):
        user_info = json.load(open(fileName))
    else:
        user_ip = host2ip(user_name)
        if is_ip(user_ip):
            user_info = ipinfo(user_ip)
            writeJson(default_user_path, user_name, user_info)
        else:
            user_info = {}
    return user_info
Esempio n. 10
0
def read_hop_info(hopinfo_path, hop_ip):
    default_hop_path = hopinfo_path + hop_ip + ".json"
    if os.path.exists(default_hop_path):
        try:
            hop_info = json.load(open(default_hop_path))
        except:
            os.remove(default_hop_path)
            if is_ip(hop_ip):
                hop_info = ipinfo(hop_ip)
                save_ipinfo(hopinfo_path, hop_info)
            else:
                hop_info = {}
    else:
        if not is_ip(hop_ip):
            hop_ip = host2ip(hop_ip)

        if is_ip(hop_ip):
            hop_info = ipinfo(hop_ip)
            save_ipinfo(hopinfo_path, hop_info)
        else:
            hop_info = {}
    return hop_info
def getMyName():
	hostname = socket.gethostname()

	if '.' not in hostname:
		ext_ip = get_ext_ip()
		myInfo = ipinfo(ext_ip)
		if "hostname" in myInfo.keys():
			if '.' in myInfo["hostname"]:
				hostname = myInfo["hostname"]
		if ext_ip == "221.199.217.144":
			hostname = "planetlab1.research.nicta.com.au"

		if '.' not in hostname:
			hostname = ext_ip
	return hostname
Esempio n. 12
0
def getMyName():
    hostname = socket.gethostname()

    if '.' not in hostname:
        ext_ip = get_ext_ip()
        myInfo = ipinfo(ext_ip)
        if "hostname" in myInfo.keys():
            if '.' in myInfo["hostname"]:
                hostname = myInfo["hostname"]
        if ext_ip == "221.199.217.144":
            hostname = "planetlab1.research.nicta.com.au"

        if '.' not in hostname:
            hostname = ext_ip
    return hostname
def get_hop_by_host(cdn_host):
    hop_data_folder = os.getcwd() + '/hopData/'

    hops = traceroute(cdn_host)
    print hops

    hop_ids = sorted(hops.keys(), key=int)
    for hop_id in hop_ids:
        cur_hop_ip = hops[hop_id]['IP']
        if cur_hop_ip is '*':
            continue

        if not is_reserved(cur_hop_ip):
            hop_info = ipinfo(cur_hop_ip)
            save_ipinfo(hop_data_folder, hop_info)
            print hop_info
def getMyName():
	hostname = socket.gethostname()
	not_found_names = {
		"221.199.217.144" : "planetlab1.research.nicta.com.au",
		"221.199.217.145" : "planetlab2.research.nicta.com.au"
	}

	if '.' not in hostname:
		ext_ip = get_ext_ip()
		myInfo = ipinfo(ext_ip)
		if "hostname" in myInfo.keys():
			if '.' in myInfo["hostname"]:
				hostname = myInfo["hostname"]
		elif ext_ip in not_found_names.keys():
			hostname = not_found_names[ext_ip]

		if '.' not in hostname:
			hostname = ext_ip
	return hostname
Esempio n. 15
0
def getMyName():
    hostname = socket.gethostname()
    not_found_names = {
        "221.199.217.144": "planetlab1.research.nicta.com.au",
        "221.199.217.145": "planetlab2.research.nicta.com.au"
    }

    if '.' not in hostname:
        ext_ip = get_ext_ip()
        myInfo = ipinfo(ext_ip)
        if "hostname" in myInfo.keys():
            if '.' in myInfo["hostname"]:
                hostname = myInfo["hostname"]
        elif ext_ip in not_found_names.keys():
            hostname = not_found_names[ext_ip]

        if '.' not in hostname:
            hostname = ext_ip
    return hostname
def read_hop_info(hopinfo_path, hop_ip):
    default_hop_path = hopinfo_path + hop_ip + ".json"
    if os.path.exists(default_hop_path):
        try:
            node_info = json.load(open(default_hop_path))
            return node_info
        except:
            os.remove(default_hop_path)

    if not is_ip(hop_ip):
        hop_ip = host2ip(hop_ip)

    if is_ip(hop_ip):
        hop_info = ipinfo(hop_ip)
        node_info = {}
        node_info['ip'] = hop_ip
        node_info['name'] = hop_info['hostname']
        if not hop_info['city']:
            node_info['city'] = ""
        else:
            try:
                node_info['city'] = str(hop_info['city'])
            except:
                node_info['city'] = hop_info['city'].encode('utf-8')
        node_info['region'] = str(hop_info['region'])
        node_info['country'] = str(hop_info['country'])
        node_info['AS'] = hop_info['AS']
        try:
            node_info['ISP'] = str(hop_info['ISP'])
        except:
            node_info['ISP'] = hop_info['ISP'].encode('utf-8')
        node_info['latitude'] = hop_info['latitude']
        node_info['longitude'] = hop_info['longitude']
    else:
        node_info = {}

    return node_info
Esempio n. 17
0
def read_hop_info(hopinfo_path, hop_ip):
    default_hop_path = hopinfo_path + hop_ip + ".json"
    if os.path.exists(default_hop_path):
        try:
            node_info = json.load(open(default_hop_path))
            return node_info
        except:
            os.remove(default_hop_path)

    if not is_ip(hop_ip):
        hop_ip = host2ip(hop_ip)

    if is_ip(hop_ip):
        hop_info = ipinfo(hop_ip)
        node_info = {}
        node_info['ip'] = hop_ip
        node_info['name'] = hop_info['hostname']
        if not hop_info['city']:
            node_info['city'] = ""
        else:
            try:
                node_info['city'] = str(hop_info['city'])
            except:
                node_info['city'] = hop_info['city'].encode('utf-8')
        node_info['region'] = str(hop_info['region'])
        node_info['country'] = str(hop_info['country'])
        node_info['AS'] = hop_info['AS']
        try:
            node_info['ISP'] = str(hop_info['ISP'])
        except:
            node_info['ISP'] = hop_info['ISP'].encode('utf-8')
        node_info['latitude'] = hop_info['latitude']
        node_info['longitude'] = hop_info['longitude']
    else:
        node_info = {}

    return node_info