Ejemplo n.º 1
0
    def egress_max_throughput(self, fake_node_id, dst_topo):
        #generate traffic matrix
        trafficMatrix = {}
        dst_topo_node_num = networkx.number_of_nodes(dst_topo._graph)
        for node in self.topo._graph.nodes():
            trafficMatrix[(
                node,
                fake_node_id)] = CITY_TRAFFIC_VOLUME * (dst_topo_node_num - 2)

        #generate fake topology
        self.fake_topo = copy.deepcopy(self.topo)
        self.fake_topo._graph.add_node(fake_node_id)
        #self.fake_topo._graph.add_edge(fake_node_id, 0)
        self.fake_topo._graph.add_edge(0, fake_node_id)
        #self.fake_topo._graph.add_edge(fake_node_id, 1)
        self.fake_topo._graph.add_edge(1, fake_node_id)

        #generate traffic classes
        ie_path_map = generatePath(trafficMatrix.keys(),
                                   self.fake_topo,
                                   nullPredicate,
                                   'shortest',
                                   maxPaths=3)
        trafficClasses = generateTrafficClasses(0, trafficMatrix.keys(),
                                                trafficMatrix, {'a': 1},
                                                {'a': 100})
        norm_list = get_norm_weight(trafficClasses)

        #optimization
        pptc = initOptimization(ie_path_map, self.fake_topo, trafficClasses)
        throughput = maxmin_fair_allocate(trafficClasses, self.linkcaps, pptc,
                                          norm_list, False)

        print 'cp net max throughput:{}'.format(throughput)
        egress_bw_dict = {}
        for tc, paths in pptc.iteritems():
            for path in paths:
                nodes = path.getNodes()
                real_egress = nodes[-2]
                if real_egress in egress_bw_dict:
                    egress_bw_dict[real_egress] += path.bw
                else:
                    egress_bw_dict[real_egress] = path.bw

        for egress, bw in egress_bw_dict.iteritems():
            print 'egress:{} bw:{}'.format(egress, bw)

        result = {}
        dst_topo_node_num = networkx.number_of_nodes(dst_topo._graph)
        for node in dst_topo.nodes():
            if node == 0 or node == 1:
                continue
            for egress, bw in egress_bw_dict.iteritems():
                result[(egress, node)] = bw / (dst_topo_node_num - 2)

        return result
Ejemplo n.º 2
0
def TE():
    # ==============
    # Let's generate some example data;
    # ==============
    topo = Topology('Abilene', 'data/topologies/simple-flex.graphml')
    # Let's load an existing gravity traffic matrix. It's just a dict mapping ingress-egress tuples to flow volume (a float).
    trafficMatrix_1 = TrafficMatrix.load('data/tm/tc-3.tm')
    trafficMatrix_2 = TrafficMatrix.load('data/tm/tc-4.tm')


    # compute traffic classes. We will only have one class that encompasses all the traffic;
    # assume that each flow consumes 2000 units of bandwidth
    ie_path_map_1 = generatePath(trafficMatrix_1.keys(), topo, nullPredicate, "shortest", 5)
    ie_path_map_2 = generatePath(trafficMatrix_2.keys(), topo, nullPredicate, "shortest", 5)
    ie_path_map = dict(ie_path_map_1.items() + ie_path_map_2.items())
    #f = pptc_set.copy()    
    
    trafficClasses_1 = generateTrafficClasses(trafficMatrix_1.keys(), trafficMatrix_1, {'vn1':1}, {'vn1': 100})
    trafficClasses_2 = generateTrafficClasses(trafficMatrix_2.keys(), trafficMatrix_2, {'vn2':1}, {'vn2': 100}, index_base=len(trafficClasses_1))
    for tc in trafficClasses_2:
        print tc
    trafficClasses = trafficClasses_1 + trafficClasses_2
    for tc in trafficClasses:
        print tc
        print "ID:",tc.ID,";name:",tc.name,"src:",tc.src,";dst:",tc.dst,";flows:",tc.volFlows,";byte:",tc.volBytes


    # since our topology is "fake", provision our links and generate link capacities in our network
    linkcaps = setLinkCaps(topo)

    # these will be our link constraints: do not load links more than 50%
    linkConstrCaps = {(u, v): 1.0 for u, v in topo.links()}

    # ==============
    # Optimization
    # ==============
    pptc = initOptimization(ie_path_map, topo, trafficClasses)
    maxmin_fair_allocate(trafficClasses, linkcaps, pptc, False)
Ejemplo n.º 3
0
    def egress_volume_shortest(self, egress_nodes, dst_topos):
        g = self.topo.getGraph()
        egress_nodes_num = len(egress_nodes)

        node_path_dict = {}
        for node in g.nodes():
            for egress in egress_nodes:
                node_path_dict[(node, egress)] = networkx.shortest_path(
                    g, node, egress)

        dst_node_num = 11
        trafficMatrix = {}
        for k in node_path_dict.keys():
            trafficMatrix[k] = CITY_TRAFFIC_VOLUME * 10
            print 'k {} value {}'.format(k, trafficMatrix[k])

        trafficClasses = generateTrafficClasses(0, node_path_dict.keys(),
                                                trafficMatrix, {'a': 1},
                                                {'a': 100})
        pptc = {}
        for tc in trafficClasses:
            pptc[copy.deepcopy(tc)] = [Path(node_path_dict[tc.src, tc.dst])]
        norm_list = get_norm_weight(trafficClasses)
        throughput = maxmin_fair_allocate(trafficClasses, self.linkcaps, pptc,
                                          norm_list, False)

        print 'cp net shortest throughput:{}'.format(throughput)
        egress_bw_dict = {}
        for tc, paths in pptc.iteritems():
            for path in paths:
                nodes = path.getNodes()
                egress = nodes[-1]
                if egress in egress_bw_dict:
                    egress_bw_dict[egress] += path.bw
                else:
                    egress_bw_dict[egress] = path.bw

        for egress, bw in egress_bw_dict.iteritems():
            print 'egress:{} bw:{}'.format(egress, bw)

        dst_topo_node_num = networkx.number_of_nodes(dst_topos[0])
        result = {}
        for egress, dst_topo in zip(egress_bw_dict.keys(), dst_topos):
            for node in dst_topo:
                if node == 0 or node == 11 or node == 22:
                    continue
                bw = egress_bw_dict[egress]
                result[(egress, node)] = bw / 10

        return result
Ejemplo n.º 4
0
    def set_traffic(self, trafficMatrix, topo, isp_id, path_num=3):
        self.trafficMatrix = {}

        isp_nodes = self.topo._graph.nodes()
        print 'ispnodes {}'.format(isp_nodes)
        for cp_id, tm in trafficMatrix.iteritems():
            self.trafficMatrix[cp_id] = {}
            for k, v in tm.iteritems():
                (ingress, dst) = k

                if ingress == isp_id:
                    k1 = (11 * isp_id, dst)
                    self.trafficMatrix[cp_id][k1] = v

        for cp_id, tm in self.trafficMatrix.iteritems():
            print "cp {}".format(cp_id)
            for k in tm.keys():
                print 'k {}'.format(k)

        self.trafficClasses = []
        self.ie_path_map = {}
        base_index = 0

        for key in trafficMatrix.keys():
            self.ie_path_map[key] = generatePath(
                self.trafficMatrix[key].keys(),
                topo,
                nullPredicate,
                "shortest",
                maxPaths=path_num)
            tcs = generateTrafficClasses(key,
                                         self.trafficMatrix[key].keys(),
                                         self.trafficMatrix[key], {'a': 1},
                                         {'a': 100},
                                         index_base=base_index)
            base_index += len(tcs)
            self.trafficClasses.extend(tcs)

        print 'test trafficclass'
        for tc in self.trafficClasses:
            print tc
        #self.linkcaps = provisionLinks(self.topo, self.trafficClasses, 1)
        self.norm_list = get_norm_weight(self.trafficClasses)
Ejemplo n.º 5
0
    def egress_volume_shortest(self, egress_nodes, dst_topo):
        g = self.topo.getGraph()
        node_path_dict = {}
        for node in g.nodes():
            egress_path_dict = {}
            for egress in egress_nodes:
                egress_path_dict[egress] = networkx.shortest_path(g, node, egress)
            min_val = min(egress_path_dict.itervalues())
            closest_egress = [k for k, v in egress_path_dict.iteritems() if v == min_val]
            node_path_dict[(node, closest_egress[0])] = egress_path_dict[closest_egress[0]]
        dst_node_num = networkx.number_of_nodes(dst_topo._graph)
        trafficMatrix = dict(zip(node_path_dict.keys(), [CITY_TRAFFIC_VOLUME * (dst_node_num - 2)] * len(node_path_dict.keys())))
        trafficClasses = generateTrafficClasses(0, node_path_dict.keys(), trafficMatrix, {'a':1}, {'a':100})
        pptc = {}
        for tc in trafficClasses:
            pptc[copy.deepcopy(tc)] = [Path(node_path_dict[tc.src, tc.dst])]
        norm_list = get_norm_weight(trafficClasses)
        throughput = maxmin_fair_allocate(trafficClasses, self.linkcaps, pptc, norm_list, False)

        print 'cp net shortest throughput:{}'.format(throughput)
        egress_bw_dict = {}
        for tc, paths in pptc.iteritems():
            for path in paths:
                nodes = path.getNodes()
                egress = nodes[-1]
                if egress in egress_bw_dict:
                    egress_bw_dict[egress] += path.bw
                else:
                    egress_bw_dict[egress] = path.bw

        for egress, bw in egress_bw_dict.iteritems():
            print 'egress:{} bw:{}'.format(egress, bw)

        dst_topo_node_num = networkx.number_of_nodes(dst_topo._graph)
        result = {}
        for node in dst_topo.nodes():
	    if node == 0 or node == 1:
		continue
            for egress, bw in egress_bw_dict.iteritems():
                result[(egress, node)] = bw / (dst_topo_node_num - 2)
        return result
Ejemplo n.º 6
0
 def set_traffic(self, trafficMatrix):
     self.trafficMatrix = trafficMatrix
     self.trafficClasses = []
     self.ie_path_map = {}
     base_index = 0
     print self.topo._graph.edges()
     for key in trafficMatrix.keys():
         self.ie_path_map[key] = generatePath(
             self.trafficMatrix[key].keys(), self.topo, nullPredicate,
             "shortest", 5)
         tcs = generateTrafficClasses(key,
                                      self.trafficMatrix[key].keys(),
                                      self.trafficMatrix[key], {'a': 1},
                                      {'a': 100},
                                      index_base=base_index)
         base_index += len(tcs)
         self.trafficClasses.extend(tcs)
     #for tc in self.trafficClasses:
     #print tc
     #self.linkcaps = provisionLinks(self.topo, self.trafficClasses, 1)
     self.linkcaps = self.setLinkCaps()
     self.norm_list = self.getNormWeight()
Ejemplo n.º 7
0
 def set_traffic(self, trafficMatrix, topo, path_num=3):
     self.trafficMatrix = trafficMatrix
     self.trafficClasses = []
     self.ie_path_map = {}
     base_index = 0
     for key in trafficMatrix.keys():
         self.ie_path_map[key] = generatePath(
             self.trafficMatrix[key].keys(),
             topo,
             nullPredicate,
             "shortest",
             maxPaths=path_num)
         tcs = generateTrafficClasses(key,
                                      self.trafficMatrix[key].keys(),
                                      self.trafficMatrix[key], {'a': 1},
                                      {'a': 100},
                                      index_base=base_index)
         base_index += len(tcs)
         self.trafficClasses.extend(tcs)
     #for tc in self.trafficClasses:
     #print tc
     #self.linkcaps = provisionLinks(self.topo, self.trafficClasses, 1)
     self.norm_list = get_norm_weight(self.trafficClasses)
Ejemplo n.º 8
0
def TE():
    # ==============
    # Let's generate some example data;
    # ==============
    topo = Topology('Abilene', './data/topologies/Abilene.graphml')
    # Let's load an existing gravity traffic matrix. It's just a dict mapping ingress-egress tuples to flow volume (a float).
    trafficMatrix_1 = TrafficMatrix.load('./data/tm/Abilene.tm')
    #trafficMatrix_2 = TrafficMatrix.load('data/tm/tc-4.tm')
    trafficMatrix_2 = {}
    print trafficMatrix_1.keys()
    for key, value in trafficMatrix_1.iteritems():
        trafficMatrix_2.update({key: 7 * value})

    #print trafficMatrix_2

    # compute traffic classes. We will only have one class that encompasses all the traffic;
    # assume that each flow consumes 2000 units of bandwidth
    ie_path_map_1 = generatePath(trafficMatrix_1.keys(), topo, nullPredicate,
                                 "shortest", 5)
    ie_path_map_2 = generatePath(trafficMatrix_2.keys(), topo, nullPredicate,
                                 "shortest", 5)
    ie_path_map = dict(ie_path_map_1.items() + ie_path_map_2.items())
    #f = pptc_set.copy()

    trafficClasses_1 = generateTrafficClasses(trafficMatrix_1.keys(),
                                              trafficMatrix_1, {'vn1': 1},
                                              {'vn1': 100})
    trafficClasses_2 = generateTrafficClasses(trafficMatrix_2.keys(),
                                              trafficMatrix_2, {'vn2': 1},
                                              {'vn2': 100},
                                              index_base=len(trafficClasses_1))
    trafficClasses = trafficClasses_1 + trafficClasses_2

    v1_sum = sum(tc.demand for tc in trafficClasses_1)
    v2_sum = sum(tc.demand for tc in trafficClasses_2)
    demand_sum = sum(tc.demand for tc in trafficClasses)
    norm_list = {}
    for tc in trafficClasses:
        norm_list[tc] = tc.demand / demand_sum
    max_val = max(norm_list.values())
    for tc in trafficClasses:
        norm_list[tc] = norm_list[tc] / max_val

    # since our topology is "fake", provision our links and generate link capacities in our network
    linkcaps = setLinkCaps(topo)

    # these will be our link constraints: do not load links more than 50%
    linkConstrCaps = {(u, v): 1.0 for u, v in topo.links()}

    # ==============
    # Optimization
    # ==============
    pptc = initOptimization(ie_path_map, topo, trafficClasses)
    maxmin_fair_allocate(trafficClasses, linkcaps, pptc, norm_list, False)

    print "calculating fairness index..."

    pptc_1 = initOptimization(ie_path_map_1, topo, trafficClasses_1)
    maxmin_fair_allocate(trafficClasses_1, linkcaps, pptc_1, norm_list)

    pptc_2 = initOptimization(ie_path_map_2, topo, trafficClasses_2)
    maxmin_fair_allocate(trafficClasses_2, linkcaps, pptc_2, norm_list)

    s_1 = 0.0
    s_2 = 0.0
    s1_num = 0
    s2_num = 0
    for tc in pptc:
        if tc in trafficClasses_1:
            for tc1 in pptc_1:
                if tc.src == tc1.src and tc.dst == tc1.dst:
                    print 'tc:{} tc1:{}'.format(tc.allocate_bw,
                                                tc1.allocate_bw)
                    if tc1.allocate_bw == 0:
                        tc1.allocate_bw = 0.1
                    s_1 += tc.allocate_bw / tc1.allocate_bw
                    s1_num += 1
                    break
        elif tc in trafficClasses_2:
            for tc2 in pptc_2:
                if tc.src == tc2.src and tc.dst == tc2.dst:
                    if tc2.allocate_bw == 0:
                        tc2.allocate_bw = 0.1
                    s_2 += tc.allocate_bw / tc2.allocate_bw
                    s2_num += 1
                    break
    s_1 = s_1 / s1_num
    s_2 = s_2 / s2_num
    print 's1:{} s2:{}'.format(s_1, s_2)

    g1 = copy.deepcopy(pptc_1)
    g2 = copy.deepcopy(pptc_2)

    for tc1 in pptc_1:
        if tc1.calc_flag == 1:
            continue
        for path1 in pptc_1[tc1]:
            for tc2 in pptc_2:
                if tc2.calc_flag == 1:
                    continue
                for path2 in pptc_2[tc2]:
                    links1 = path1.getLinks()
                    links2 = path2.getLinks()
                    if set(links1).intersection(links2):
                        g1[copy.deepcopy(tc2)] = copy.deepcopy(pptc_2[tc2])
                        g2[copy.deepcopy(tc1)] = copy.deepcopy(pptc_1[tc1])
                        flag = 1
                        tc2.calc_flag = 1
                        tc1.calc_flag = 1

    maxmin_fair_allocate(g1.keys(), linkcaps, g1, norm_list)
    maxmin_fair_allocate(g2.keys(), linkcaps, g2, norm_list)

    u_1 = 0.0
    u_2 = 0.0
    u1_num = 0
    u2_num = 0

    for tc1 in g1:
        for tc in pptc:
            if tc.src == tc1.src and tc.dst == tc1.dst:
                print 'tc:{} tc1:{}'.format(tc.allocate_bw, tc1.allocate_bw)
                u_1 += min({tc.allocate_bw / tc1.allocate_bw, 1})
                u1_num += 1
                break
    for tc2 in g2:
        for tc in pptc:
            if tc.src == tc2.src and tc.dst == tc2.dst:
                u_2 += min({tc.allocate_bw / tc2.allocate_bw, 1})
                u2_num += 1
                break

    u_1 = u_1 / u1_num
    u_2 = u_2 / u2_num
    print 'u1:{} u2:{}'.format(u_1, u_2)

    netstat_1 = s_1 / u_1
    netstat_2 = s_2 / u_2

    u = (netstat_1 * v1_sum + netstat_2 * v2_sum) / (v1_sum + v2_sum)
    print u
    gfi = math.sqrt(
        (pow(netstat_1 - u, 2) * v1_sum + pow(netstat_2 - u, 2) * v2_sum) /
        (v1_sum + v2_sum))
    print gfi