Exemplo n.º 1
0
def independent_routing(cp_num):
    cpNets = []
    ispTopo = Topology('isp_network', ISP_TOPO_DIR)
    for i in range(cp_num):
        cpNets.append(CpNetwork('Abilene', CP_TOPO_DIR))

    trafficMatrix = {}
    for i in range(cp_num):
        trafficMatrix[i] = cpNets[i].egress_max_throughput(10000, ispTopo)

    ispNet = IspNetwork('isp_network', ISP_TOPO_DIR)
    ispNet.linkcaps = set_link_caps(ispNet.topo)
    pptc, throughput = ispNet.calc_path_maxminfair(trafficMatrix)

    ingress_bw_dict = {}
    for i in range(cp_num):
        ingress_bw_dict[i] = {}
    for tc, paths in pptc.iteritems():
        for path in paths:
            nodes = path.getNodes()
            ingress = nodes[0]
            if ingress in ingress_bw_dict[tc.network_id]:
                ingress_bw_dict[tc.network_id][ingress] += path.bw
            else:
                ingress_bw_dict[tc.network_id][ingress] = path.bw

    for id, bw_dict in ingress_bw_dict.iteritems():
        print 'network id:{}'.format(id)
        for ingress, bw in bw_dict.iteritems():
            print '{}:{}'.format(ingress, bw)

    with open(INDEPENDENT_LOG_DIR, 'a') as f:
        f.write(str(throughput))
        f.write('\n')
        '''f.write('independent routing\n')
Exemplo n.º 2
0
def shortest_gfi(cp_num):
    cpNetworks = []
    ispTopo = Topology('isp_network', './data/topologies/simple.graphml')
    for i in range(cp_num):
        cpNetworks.append(
            CpNetwork('Abilene', './data/topologies/Abilene.graphml'))

    trafficMatrix = {}
    for i in range(cp_num):
        trafficMatrix[i] = cpNetworks[i].egress_volume_shortest([0, 1],
                                                                ispTopo)

    ispNet = IspNetwork('isp_network', './data/topologies/simple.graphml')
    pptc, throughput = ispNet.calc_path_maxminfair(trafficMatrix)

    pptc_dict = {}
    for i in range(cp_num):
        pptc_dict[i] = {}
    for tc, paths in pptc.iteritems():
        pptc_dict[tc.network_id][copy.deepcopy(tc)] = copy.deepcopy(paths)

    pptc_iso_dict = {}
    for i in range(cp_num):
        ispNet_local = IspNetwork('isp_network',
                                  './data/topologies/simple.graphml')
        tm = {}
        pptc_iso_dict[i] = {}
        tm.update({i: trafficMatrix[i]})
        pptc, throughput = ispNet_local.calc_path_shortest(tm)
        for tc, paths in pptc.iteritems():
            print tc
            print paths
            pptc_iso_dict[i][copy.deepcopy(tc)] = copy.deepcopy(paths)

    gfi = calc_gfi(pptc_dict, pptc_iso_dict, cp_num, ispNet)

    ingress_bw_dict = {}
    for i in range(cp_num):
        ingress_bw_dict[i] = {}
    for tc, paths in pptc.iteritems():
        for path in paths:
            nodes = path.getNodes()
            ingress = nodes[0]
            if ingress in ingress_bw_dict[tc.network_id]:
                ingress_bw_dict[tc.network_id][ingress] += path.bw
            else:
                ingress_bw_dict[tc.network_id][ingress] = path.bw

    for id, bw_dict in ingress_bw_dict.iteritems():
        print "network id:{}".format(id)
        for ingress, bw in bw_dict.iteritems():
            print '{}:{}'.format(ingress, bw)

    #log to file
    with open(SHORTEST_LOG_DIR, 'a') as f:
        f.write(str(gfi))
        f.write('\n')
        '''f.write('default routing \n')
Exemplo n.º 3
0
def negotiate_routing(cp_num):
    cpNets = []
    ispTopo = Topology('isp_network', ISP_TOPO_DIR)
    for i in range(cp_num):
        cpNets.append(CpNetwork('Abilene', CP_TOPO_DIR))

    trafficMatrix = {}
    for i in range(cp_num):
        trafficMatrix[i] = cpNets[i].egress_all(10000, ispTopo)

    ispNet = IspNetwork('isp_network', ISP_TOPO_DIR)
    ispNet.linkcaps = set_link_caps(ispNet.topo)
    egress_bw_dict, throughput = ispNet.calc_path_singleinput(
        10000, trafficMatrix, cp_num)
    link_utils = ispNet.get_link_util()
    for link, util in link_utils.iteritems():
        print 'link {} util {}'.format(link, util)
    '''with open(NEGO_LOG_DIR, 'a') as f:
        f.write('first isp throughput:{}\n'.format(throughput))
        for id, bw_dict in egress_bw_dict.iteritems():
            f.write('cp network:{}\n'.format(id))
            for egress, bw in bw_dict.iteritems():
                f.write('egress:{} bw:{}\n'.format(egress, bw))'''

    trafficMatrix = {}
    for id, bw_dict in egress_bw_dict.iteritems():
        trafficMatrix[id] = cpNets[id].egress_ratio(10000, ispTopo, bw_dict)

    pptc, throughput = ispNet.calc_path_maxminfair(trafficMatrix)

    ingress_bw_dict = {}
    for i in range(cp_num):
        ingress_bw_dict[i] = {}
    for tc, paths in pptc.iteritems():
        for path in paths:
            nodes = path.getNodes()
            ingress = nodes[0]
            if ingress in ingress_bw_dict[tc.network_id]:
                ingress_bw_dict[tc.network_id][ingress] += path.bw
            else:
                ingress_bw_dict[tc.network_id][ingress] = path.bw

    for id, bw_dict in ingress_bw_dict.iteritems():
        print 'network id:{}'.format(id)
        for ingress, bw in bw_dict.iteritems():
            print '{}:{}'.format(ingress, bw)

    with open(NEGO_LOG_DIR, 'a') as f:
        f.write(str(throughput))
        f.write('\n')
        '''for id, bw_dict in ingress_bw_dict.iteritems():
Exemplo n.º 4
0
def default_test(cp_num, isp_num):
    cpNetworks = []
    for i in range(cp_num):
        cpNetworks.append(CpNetwork('Abilene', CP_TOPO_DIR))

    trafficMatrix = {}
    ispNetworks = []
    union_ISP = networkx.DiGraph()
    dst_topos = []
    for i in range(isp_num):
        net = IspNetwork('isp_network', ISP_TOPO_DIR)
        mapping = dict(zip(net.topo._graph.nodes(), [x + i * 11 for x in networkx.nodes_iter(net.topo._graph)]))
        net.topo._graph = networkx.relabel_nodes(net.topo._graph, mapping)
        ispNetworks.append(net)
        dst_topos.append(net.topo._graph)
        #union_ISP = networkx.union(union_ISP, net.topo._graph)

    for i in range(cp_num):
        trafficMatrix[i] = cpNetworks[i].egress_volume_shortest([0, 1, 2], dst_topos)
        
            
    with open(DEFAULT_LOG_DIR, 'a') as f:
        for i in range(isp_num):
            ispNetworks[i].linkcaps = set_link_caps(ispNetworks[i].topo)
            pptc, throughput = ispNetworks[i].calc_path_shortest(trafficMatrix, i)
            #isp_pptc.append(pptc)

            cp_bw_total = {}
            for tc, paths in pptc.iteritems():
                cp_id = tc.network_id
                for path in paths:
                    if cp_id in cp_bw_total:
                        cp_bw_total[cp_id] += path.bw
                    else:
                        cp_bw_total[cp_id] = path.bw
                        
            for cp_id in cp_bw_total.keys():
                f.write('cp {} isp {} get bw {}'.format(cp_id, i, cp_bw_total[cp_id]))
                f.write('\n')
Exemplo n.º 5
0
def default_routing(cp_num):
    cpNetworks = []
    ispTopo = Topology('isp_network', ISP_TOPO_DIR)
    for i in range(cp_num):
        cpNetworks.append(CpNetwork('Abilene', CP_TOPO_DIR))

    trafficMatrix = {}
    for i in range(cp_num):
        trafficMatrix[i] = cpNetworks[i].egress_volume_shortest([0, 1],
                                                                ispTopo)

    ispNet = IspNetwork('isp_network', ISP_TOPO_DIR)
    ispNet.linkcaps = set_link_caps(ispNet.topo)
    pptc, throughput = ispNet.calc_path_shortest(trafficMatrix)

    ingress_bw_dict = {}
    for i in range(cp_num):
        ingress_bw_dict[i] = {}
    for tc, paths in pptc.iteritems():
        for path in paths:
            nodes = path.getNodes()
            ingress = nodes[0]
            if ingress in ingress_bw_dict[tc.network_id]:
                ingress_bw_dict[tc.network_id][ingress] += path.bw
            else:
                ingress_bw_dict[tc.network_id][ingress] = path.bw

    for id, bw_dict in ingress_bw_dict.iteritems():
        print "network id:{}".format(id)
        for ingress, bw in bw_dict.iteritems():
            print '{}:{}'.format(ingress, bw)

    #log to file
    with open(DEFAULT_LOG_DIR, 'a') as f:
        f.write(str(throughput))
        f.write('\n')
        '''f.write('default routing \n')
Exemplo n.º 6
0
def optimal_routing(cp_num):
    cpNets = []
    node_num = 0
    union_graph = networkx.DiGraph()
    for i in range(cp_num):
        net = CpNetwork('Abilene', CP_TOPO_DIR)
        mapping = dict(
            zip(net.topo._graph.nodes(),
                [x + i * 11 for x in networkx.nodes_iter(net.topo._graph)]))
        net.topo._graph = networkx.relabel_nodes(net.topo._graph, mapping)
        node_num += networkx.number_of_nodes(net.topo._graph)
        cpNets.append(net)
        union_graph = networkx.union(union_graph, net.topo._graph)

    ispNet = IspNetwork('isp_network', ISP_TOPO_DIR)
    mapping = dict(
        zip(ispNet.topo._graph.nodes(),
            [x + node_num for x in networkx.nodes_iter(ispNet.topo._graph)]))
    ispNet.topo._graph = networkx.relabel_nodes(ispNet.topo._graph, mapping)

    trafficMatrix = {}
    for i in range(cp_num):
        trafficMatrix[i] = cpNets[i].egress_default(
            networkx.nodes_iter(cpNets[i].topo._graph), ispNet.topo)

    ispNet.topo._graph = networkx.union(ispNet.topo._graph, union_graph)
    ispNet.linkcaps = set_link_caps(ispNet.topo)
    for i in range(cp_num):
        node_1 = i * 11
        node_2 = i * 11 + 1
        node_3 = cp_num * 11
        node_4 = cp_num * 11 + 1
        ispNet.topo._graph.add_edge(node_1, node_3)
        ispNet.topo._graph.add_edge(node_2, node_4)
        ispNet.linkcaps[(node_1, node_3)] = 10000000
        ispNet.linkcaps[(node_2, node_4)] = 10000000

    node = cp_num * 11
    ispNet.linkcaps[(node, node + 1)] = 10
    ispNet.linkcaps[(node + 1, node)] = 10
    ispNet.linkcaps[(node, node + 2)] = 10
    ispNet.linkcaps[(node + 2, node)] = 10

    print ispNet.topo._graph.edges()
    pptc, throughput = ispNet.calc_path_maxminfair(trafficMatrix)

    ingress_bw_dict = {}
    for i in range(cp_num):
        ingress_bw_dict[i] = {}
    for tc, paths in pptc.iteritems():
        for path in paths:
            nodes = path.getNodes()
            ingress = nodes[0]
            if ingress in ingress_bw_dict[tc.network_id]:
                ingress_bw_dict[tc.network_id][ingress] += path.bw
            else:
                ingress_bw_dict[tc.network_id][ingress] = path.bw

    for id, bw_dict in ingress_bw_dict.iteritems():
        print 'network id:{}'.format(id)
        for ingress, bw in bw_dict.iteritems():
            print '{}:{}'.format(ingress, bw)

    with open(OPTIMAL_LOG_DIR, 'a') as f:
        f.write(str(throughput))
        f.write('\n')
        '''f.write('independent routing\n')
Exemplo n.º 7
0
def negotiate_gfi(cp_num):
    cpNets = []
    ispTopo = Topology('isp_network', './data/topologies/simple.graphml')
    for i in range(cp_num):
        cpNets.append(CpNetwork('Abilene',
                                './data/topologies/Abilene.graphml'))

    trafficMatrix = {}
    for i in range(cp_num):
        trafficMatrix[i] = cpNets[i].egress_all(10000, ispTopo)

    ispNet = IspNetwork('isp_network', './data/topologies/simple.graphml')
    egress_bw_dict, throughput = ispNet.calc_path_singleinput(
        10000, trafficMatrix, cp_num)
    '''with open(NEGO_LOG_DIR, 'a') as f:
        f.write('first isp throughput:{}\n'.format(throughput))
        for id, bw_dict in egress_bw_dict.iteritems():
            f.write('cp network:{}\n'.format(id))
            for egress, bw in bw_dict.iteritems():
                f.write('egress:{} bw:{}\n'.format(egress, bw))
'''

    trafficMatrix = {}
    for id, bw_dict in egress_bw_dict.iteritems():
        trafficMatrix[id] = cpNets[id].egress_ratio(10000, ispTopo, bw_dict)

    pptc, throughput = ispNet.calc_path_maxminfair(trafficMatrix)

    pptc_dict = {}
    for i in range(cp_num):
        pptc_dict[i] = {}
    for tc, paths in pptc.iteritems():
        pptc_dict[tc.network_id][copy.deepcopy(tc)] = copy.deepcopy(paths)

    pptc_iso_dict = {}
    for i in range(cp_num):
        ispNet_local = IspNetwork('isp_network',
                                  './data/topologies/simple.graphml')
        tm = {}
        pptc_iso_dict[i] = {}
        tm.update({i: trafficMatrix[i]})
        pptc, throughput = ispNet_local.calc_path_shortest(tm)
        for tc, paths in pptc.iteritems():
            pptc_iso_dict[i][copy.deepcopy(tc)] = copy.deepcopy(paths)

    gfi = calc_gfi(pptc_dict, pptc_iso_dict, cp_num, ispNet)

    ingress_bw_dict = {}
    for i in range(cp_num):
        ingress_bw_dict[i] = {}
    for tc, paths in pptc.iteritems():
        for path in paths:
            nodes = path.getNodes()
            ingress = nodes[0]
            if ingress in ingress_bw_dict[tc.network_id]:
                ingress_bw_dict[tc.network_id][ingress] += path.bw
            else:
                ingress_bw_dict[tc.network_id][ingress] = path.bw

    for id, bw_dict in ingress_bw_dict.iteritems():
        print 'network id:{}'.format(id)
        for ingress, bw in bw_dict.iteritems():
            print '{}:{}'.format(ingress, bw)

    with open(NEGO_LOG_DIR, 'a') as f:
        f.write(str(gfi))
        f.write('\n')
        '''for id, bw_dict in ingress_bw_dict.iteritems():
Exemplo n.º 8
0
def negotiate_routing(cp_num):
    cpNets = []
    ispTopo = Topology('isp_network', './data/topologies/simple.graphml')
    node_num = 0
    for i in range(cp_num):
        net = CpNetwork('Abilene', './data/topologies/Abilene.graphml')
        print net.topo._graph.nodes()
        mapping = dict(
            zip(net.topo._graph.nodes(),
                [x + i * 11 for x in networkx.nodes_iter(net.topo._graph)]))
        net.topo._graph = networkx.relabel_nodes(net.topo._graph, mapping)
        print net.topo._graph.nodes()
        node_num += networkx.number_of_nodes(net.topo._graph)
    '''trafficMatrix = {}
    for i in range(cp_num):
        trafficMatrix[i] = cpNets[i].egress_all(10000, ispTopo)'''

    ispNet = IspNetwork('isp_network', './data/topologies/simple.graphml')
    mapping = dict(
        zip(ispNet.topo._graph.nodes(),
            [x + node_num for x in networkx.nodes_iter(ispNet.topo._graph)]))
    ispNet.topo._graph = networkx.relabel_nodes(ispNet.topo._graph, mapping)
    print ispNet.topo._graph.nodes()
    return
    egress_bw_dict, throughput = ispNet.calc_path_singleinput(
        10000, trafficMatrix, cp_num)

    print 'singleinput'
    for id, bw_dict in egress_bw_dict.iteritems():
        print 'network:{}'.format(id)
        for egress, bw in bw_dict.iteritems():
            print 'egress:{} bw:{}'.format(egress, bw)
    '''with open(NEGO_LOG_DIR, 'a') as f:
        f.write('first isp throughput:{}\n'.format(throughput))
        for id, bw_dict in egress_bw_dict.iteritems():
            f.write('cp network:{}\n'.format(id))
            for egress, bw in bw_dict.iteritems():
                f.write('egress:{} bw:{}\n'.format(egress, bw))
'''

    trafficMatrix = {}
    for id, bw_dict in egress_bw_dict.iteritems():
        trafficMatrix[id] = cpNets[id].egress_ratio(10000, ispTopo, bw_dict)

    pptc, throughput = ispNet.calc_path_maxminfair(trafficMatrix)

    ingress_bw_dict = {}
    for i in range(cp_num):
        ingress_bw_dict[i] = {}
    for tc, paths in pptc.iteritems():
        for path in paths:
            nodes = path.getNodes()
            ingress = nodes[0]
            if ingress in ingress_bw_dict[tc.network_id]:
                ingress_bw_dict[tc.network_id][ingress] += path.bw
            else:
                ingress_bw_dict[tc.network_id][ingress] = path.bw

    for id, bw_dict in ingress_bw_dict.iteritems():
        print 'network id:{}'.format(id)
        for ingress, bw in bw_dict.iteritems():
            print '{}:{}'.format(ingress, bw)

    with open(NEGO_LOG_DIR, 'a') as f:
        f.write(str(throughput))
        f.write('\n')
        '''for id, bw_dict in ingress_bw_dict.iteritems():