Ejemplo n.º 1
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():
Ejemplo n.º 2
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():
Ejemplo n.º 3
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():