Example #1
0
 def test_diamond(self):
     '''Simple diamond graph w/two equal paths.'''
     g = nx.Graph()
     g.add_path(['A', 'B', 'Z', 'C', 'A'])
     set_unit_weights(g)
     paths = vertex_disjoint_shortest_pair(g, 'A', 'Z')
     exp_paths = [['A', 'B', 'Z'], ['A', 'C', 'Z']]
     compare_path_lists(self, paths, exp_paths)
Example #2
0
 def test_diamond(self):
     '''Simple diamond graph w/two equal paths.'''
     g = nx.Graph()
     g.add_path(['A', 'B', 'Z', 'C', 'A'])
     set_unit_weights(g)
     paths = vertex_disjoint_shortest_pair(g, 'A', 'Z')
     exp_paths = [['A', 'B', 'Z'], ['A', 'C', 'Z']]
     compare_path_lists(self, paths, exp_paths)
Example #3
0
    def test_example_3_13_a_mod_2(self):
        '''Example 3.13a on pg 65, mod 2 on pg 78.

        This example has two equally good path choices (ABIFZ / AGDHZ and
        ABCDEFZ / AGDHZ), so only check sum of paths.
        '''
        g = graph_fig_3_13_a_mod_2
        vd_paths = vertex_disjoint_shortest_pair(g, 'A', 'Z')
        vd_paths_len = sum([pathlen(g, vd_paths[i]) for i in [0, 1]])
        exp_paths = [[i for i in 'ABIFZ'], [i for i in 'AGDHZ']]
        exp_paths_len = sum([pathlen(g, exp_paths[i]) for i in [0, 1]])
        compare_path_lists(self, vd_paths, exp_paths, g, 14)
        self.assertEqual(vd_paths_len, exp_paths_len)
Example #4
0
    def test_example_3_13_a_mod_2(self):
        '''Example 3.13a on pg 65, mod 2 on pg 78.

        This example has two equally good path choices (ABIFZ / AGDHZ and
        ABCDEFZ / AGDHZ), so only check sum of paths.
        '''
        g = graph_fig_3_13_a_mod_2
        vd_paths = vertex_disjoint_shortest_pair(g, 'A', 'Z')
        vd_paths_len = sum([pathlen(g, vd_paths[i]) for i in [0, 1]])
        exp_paths = [[i for i in 'ABIFZ'], [i for i in 'AGDHZ']]
        exp_paths_len = sum([pathlen(g, exp_paths[i]) for i in [0, 1]])
        compare_path_lists(self, vd_paths, exp_paths, g, 14)
        self.assertEqual(vd_paths_len, exp_paths_len)
Example #5
0
def do_metrics(options, topo, g, mylist):
    temp=[]
    FlowSpace_domain = [] #FlowSpace Rules Table for domain wide slicing
    FlowSpace_switch = [] #FlowSpace Rules Table for switch wide slicing
    FlowSpace_port = [] #FlowSpace Rules Table for port wide
    query = []
    dst = [] #stores connection points as  multiple destinations
    paths_temp = [ ]	#stores disjoint paths from src to connection points
    print "computing metricss for topo: %s" % topo
    options = parse_args()
    if options.weights_from_file:
	filename_weights = get_filename_weights(options)
	read_weights_from_file(g,filename_weights)
    #graph_util.construct_array(g,mylist) #testing elements-please ignore
    #lookup_process.init_lookup(mylist)
    #lookup_process.read_query(query)
    #lookup_process.lookup_table(mylist,query)
    filename = get_filename(topo, options)
    filename_domain, filename_switch, filename_port = get_tablefilename(topo,options)
    data = {}  # Data to be computed --> acceptance ratio, flowspace rules and number of flowspace rules
    bandwidth = options.bandwidth
    if bandwidth:
	data['Weights used'] = 'Bandwidth'
    else:
	data['Weighs used'] = 'Propagation delay'
    apsp = nx.all_pairs_dijkstra_path_length(g) # weight computation according to dijkstra algorithm
    apsp_paths = nx.all_pairs_dijkstra_path(g) # all pair of dijkstra paths
    if options.disjoint_paths:
	dst=[]
	paths_temp = []
	connection_points = []
	connection_points = options.connection_points #for future implementation of multi-domain environments
	if g.__contains__(options.src):
		src = options.src
	else:		
		src = options.dst
	graph_util.parse_points(g,dst,connection_points)
	#print dst
	counter=0
        '''Disjoint paths computation'''
        for i in range(len(dst)):
		#print apsp[src][dst]
		temp1,temp2  = paths.vertex_disjoint_shortest_pair(g, src, dst[i])
		if temp1!=None and temp2!=None:
			length1 = get_length(apsp,temp1)
			paths_temp.append((temp1,length1,dst[i]))
			length2 = get_length(apsp,temp2)
			paths_temp.append((temp2,length2,dst[i]))
			counter = counter+2
		elif temp1!=None and temp2==None:
			length = get_length(apsp,temp1)
			paths_temp.append((temp1,length,dst[i]))
			counter=counter+1
	if counter == 0 or counter==1:
		print "Could not find two or more paths to check if they are disjoint"
		print "The execution will know be stopped"
		raise SystemExit
	#print apsp[src][dst]
	paths_temp = sorted(paths_temp, key=itemgetter(1))
	path1,path2 = get_disjoint(g,paths_temp)
	if path1 == None or path2 == None:
		print("Could not establish a set of disjoint paths between the requsted source and destination nodes")
		print "The execution will now be stopped"
                raise SystemExit
	
	print path1,path2
	path_temp1 , cost1, dst1 = path1
	path_temp2 , cost2, dst2 = path2
	apsp[src][dst1] = cost1
	apsp_paths[src][dst1] = path_temp1
	apsp[src][dst2]=cost2
	apsp_paths[src][dst2]=path_temp2

    '''Precomputations for metrics computation'''
    
    if options.reuse:
	star_path_counter = options.star_paths
	iters = options.simple_paths
	disjoints = options.disjoint
	dis_counter = 0
	unbound_ratio = options.unbound
	dst=[]
	dis_paths = []
	paths_temp = []
	connection_points = []
        connection_points = options.connection_points
	graph_util.parse_points(g,dst,connection_points)
	for node in g.nodes():
		if dis_counter >= disjoints:
			break
		src = node
		counter = 0
		for i in range(len(dst)):
                	#print apsp[src][dst]
                	temp1,temp2  = paths.vertex_disjoint_shortest_pair(g, src, dst[i])
                	if temp1!=None and temp2!=None:
                        	length1 = get_length(apsp,temp1)
				if length1 == -1:
					break
                        	paths_temp.append((temp1,length1,dst[i]))
                        	length2 = get_length(apsp,temp2)
				if length2== -1:
					break
                        	paths_temp.append((temp2,length2,dst[i]))
                        	counter = counter+2
                	elif temp1!=None and temp2==None:
                        	length = get_length(apsp,temp1)
				if length == -1:
					break
                        	paths_temp.append((temp1,length,dst[i]))
                        	counter=counter+1
		if counter == 0 or counter==1:
			continue
		paths_temp = sorted(paths_temp, key=itemgetter(1))
        	path1,path2 = get_disjoint(g,paths_temp)
		if path1!=None and path2!=None:
			dis_counter = dis_counter +2
			dis_paths.append(path1[0])
			dis_paths.append(path2[0])

	if dis_counter == disjoints:
		print("-------Found %d disjoint paths" % dis_counter)
	else:
		print("-------Found %d disjoint paths out of %d that was requested" % (dis_counter,disjoints))
    	evaluation.compute_metrics(FlowSpace_domain,FlowSpace_switch,FlowSpace_port,g,data,iters,dis_counter,dis_paths,star_path_counter,unbound_ratio) #this function actually computes acceptance ratio and generate non-overlapping flowspace rules

        '''creation of file containing flowspace rules in /tables folder. One file is cretated for each slicing method'''
        
	dirname = os.path.dirname(filename_domain)
        if not os.path.exists(dirname):
     	   os.mkdir(dirname)
        write_json_file(filename_domain+"Flowspace table" , FlowSpace_domain)
	dirname = os.path.dirname(filename_switch)
        if not os.path.exists(dirname):
    	    os.mkdir(dirname)
        write_json_file(filename_switch+"Flowspace table", FlowSpace_switch)
	dirname = os.path.dirname(filename_port)
    	if not os.path.exists(dirname):
        	os.mkdir(dirname)
       	write_json_file(filename_port + "Flowspace table", FlowSpace_port)

    '''creation of file containing acceptance ratio results and number of flowspace rules for each slicing method in /acceptance_ratio folder'''

    if options.use_prior:
        data = read_json_file(filename)
    else:
    	if options.write:
        	dirname = os.path.dirname(filename)
        	if not os.path.exists(dirname):
            		os.mkdir(dirname)
    			write_json_file(filename + 'acceptance_ratio', data)
       
    return data, filename
Example #6
0
 def test_example_3_13_a_mod_1(self):
     '''Example 3.13a on pg 65, mod 1 on pg 78.'''
     g = graph_fig_3_13_a_mod_1
     vd_paths = vertex_disjoint_shortest_pair(g, 'A', 'Z')
     exp_paths = [[i for i in 'ABCDEFZ'], [i for i in 'AGHZ']]
     compare_path_lists(self, vd_paths, exp_paths, g, 14)
Example #7
0
 def test_example_3_13_a(self):
     '''Example 3.13a on pg 65.'''
     g = graph_fig_3_13_a
     vd_paths = vertex_disjoint_shortest_pair(g, 'A', 'Z')
     exp_paths = [[i for i in 'AGCDEFZ'], [i for i in 'ABIZ']]
     compare_path_lists(self, vd_paths, exp_paths)
Example #8
0
 def test_example_3_14(self):
     '''Example 3.14 on pg 76.'''
     g = graph_fig_3_14
     vd_paths = vertex_disjoint_shortest_pair(g, 'A', 'Z')
     exp_paths = [[i for i in 'ABCFZ'], [i for i in 'AEDZ']]
     compare_path_lists(self, vd_paths, exp_paths, g, 14)
Example #9
0
def do_metrics(options, topo, g, mylist):
    temp = []
    FlowSpace_domain = []  #FlowSpace Rules Table for domain wide slicing
    FlowSpace_switch = []  #FlowSpace Rules Table for switch wide slicing
    FlowSpace_port = []  #FlowSpace Rules Table for port wide
    query = []
    dst = []  #stores connection points as  multiple destinations
    paths_temp = []  #stores disjoint paths from src to connection points
    print "computing metricss for topo: %s" % topo
    options = parse_args()
    if options.weights_from_file:
        filename_weights = get_filename_weights(options)
        read_weights_from_file(g, filename_weights)
    #graph_util.construct_array(g,mylist) #testing elements-please ignore
    #lookup_process.init_lookup(mylist)
    #lookup_process.read_query(query)
    #lookup_process.lookup_table(mylist,query)
    filename = get_filename(topo, options)
    filename_domain, filename_switch, filename_port = get_tablefilename(
        topo, options)
    data = {
    }  # Data to be computed --> acceptance ratio, flowspace rules and number of flowspace rules
    bandwidth = options.bandwidth
    if bandwidth:
        data['Weights used'] = 'Bandwidth'
    else:
        data['Weighs used'] = 'Propagation delay'
    apsp = nx.all_pairs_dijkstra_path_length(
        g)  # weight computation according to dijkstra algorithm
    apsp_paths = nx.all_pairs_dijkstra_path(g)  # all pair of dijkstra paths
    if options.disjoint_paths:
        dst = []
        paths_temp = []
        connection_points = []
        connection_points = options.connection_points  #for future implementation of multi-domain environments
        if g.__contains__(options.src):
            src = options.src
        else:
            src = options.dst
        graph_util.parse_points(g, dst, connection_points)
        #print dst
        counter = 0
        '''Disjoint paths computation'''
        for i in range(len(dst)):
            #print apsp[src][dst]
            temp1, temp2 = paths.vertex_disjoint_shortest_pair(g, src, dst[i])
            if temp1 != None and temp2 != None:
                length1 = get_length(apsp, temp1)
                paths_temp.append((temp1, length1, dst[i]))
                length2 = get_length(apsp, temp2)
                paths_temp.append((temp2, length2, dst[i]))
                counter = counter + 2
            elif temp1 != None and temp2 == None:
                length = get_length(apsp, temp1)
                paths_temp.append((temp1, length, dst[i]))
                counter = counter + 1
        if counter == 0 or counter == 1:
            print "Could not find two or more paths to check if they are disjoint"
            print "The execution will know be stopped"
            raise SystemExit
        #print apsp[src][dst]
        paths_temp = sorted(paths_temp, key=itemgetter(1))
        path1, path2 = get_disjoint(g, paths_temp)
        if path1 == None or path2 == None:
            print(
                "Could not establish a set of disjoint paths between the requsted source and destination nodes"
            )
            print "The execution will now be stopped"
            raise SystemExit

        print path1, path2
        path_temp1, cost1, dst1 = path1
        path_temp2, cost2, dst2 = path2
        apsp[src][dst1] = cost1
        apsp_paths[src][dst1] = path_temp1
        apsp[src][dst2] = cost2
        apsp_paths[src][dst2] = path_temp2
    '''Precomputations for metrics computation'''

    if options.reuse:
        star_path_counter = options.star_paths
        iters = options.simple_paths
        disjoints = options.disjoint
        dis_counter = 0
        unbound_ratio = options.unbound
        dst = []
        dis_paths = []
        paths_temp = []
        connection_points = []
        connection_points = options.connection_points
        graph_util.parse_points(g, dst, connection_points)
        for node in g.nodes():
            if dis_counter >= disjoints:
                break
            src = node
            counter = 0
            for i in range(len(dst)):
                #print apsp[src][dst]
                temp1, temp2 = paths.vertex_disjoint_shortest_pair(
                    g, src, dst[i])
                if temp1 != None and temp2 != None:
                    length1 = get_length(apsp, temp1)
                    if length1 == -1:
                        break
                    paths_temp.append((temp1, length1, dst[i]))
                    length2 = get_length(apsp, temp2)
                    if length2 == -1:
                        break
                    paths_temp.append((temp2, length2, dst[i]))
                    counter = counter + 2
                elif temp1 != None and temp2 == None:
                    length = get_length(apsp, temp1)
                    if length == -1:
                        break
                    paths_temp.append((temp1, length, dst[i]))
                    counter = counter + 1
            if counter == 0 or counter == 1:
                continue
            paths_temp = sorted(paths_temp, key=itemgetter(1))
            path1, path2 = get_disjoint(g, paths_temp)
            if path1 != None and path2 != None:
                dis_counter = dis_counter + 2
                dis_paths.append(path1[0])
                dis_paths.append(path2[0])

        if dis_counter == disjoints:
            print("-------Found %d disjoint paths" % dis_counter)
        else:
            print(
                "-------Found %d disjoint paths out of %d that was requested" %
                (dis_counter, disjoints))
        evaluation.compute_metrics(
            FlowSpace_domain, FlowSpace_switch, FlowSpace_port, g, data, iters,
            dis_counter, dis_paths, star_path_counter, unbound_ratio
        )  #this function actually computes acceptance ratio and generate non-overlapping flowspace rules
        '''creation of file containing flowspace rules in /tables folder. One file is cretated for each slicing method'''

        dirname = os.path.dirname(filename_domain)
        if not os.path.exists(dirname):
            os.mkdir(dirname)
        write_json_file(filename_domain + "Flowspace table", FlowSpace_domain)
        dirname = os.path.dirname(filename_switch)
        if not os.path.exists(dirname):
            os.mkdir(dirname)
        write_json_file(filename_switch + "Flowspace table", FlowSpace_switch)
        dirname = os.path.dirname(filename_port)
        if not os.path.exists(dirname):
            os.mkdir(dirname)
        write_json_file(filename_port + "Flowspace table", FlowSpace_port)
    '''creation of file containing acceptance ratio results and number of flowspace rules for each slicing method in /acceptance_ratio folder'''

    if options.use_prior:
        data = read_json_file(filename)
    else:
        if options.write:
            dirname = os.path.dirname(filename)
            if not os.path.exists(dirname):
                os.mkdir(dirname)
                write_json_file(filename + 'acceptance_ratio', data)

    return data, filename
Example #10
0
 def test_example_3_13_a_mod_1(self):
     '''Example 3.13a on pg 65, mod 1 on pg 78.'''
     g = graph_fig_3_13_a_mod_1
     vd_paths = vertex_disjoint_shortest_pair(g, 'A', 'Z')
     exp_paths = [[i for i in 'ABCDEFZ'], [i for i in 'AGHZ']]
     compare_path_lists(self, vd_paths, exp_paths, g, 14)
Example #11
0
 def test_example_3_13_a(self):
     '''Example 3.13a on pg 65.'''
     g = graph_fig_3_13_a
     vd_paths = vertex_disjoint_shortest_pair(g, 'A', 'Z')
     exp_paths = [[i for i in 'AGCDEFZ'], [i for i in 'ABIZ']]
     compare_path_lists(self, vd_paths, exp_paths)
Example #12
0
 def test_example_3_14(self):
     '''Example 3.14 on pg 76.'''
     g = graph_fig_3_14
     vd_paths = vertex_disjoint_shortest_pair(g, 'A', 'Z')
     exp_paths = [[i for i in 'ABCFZ'], [i for i in 'AEDZ']]
     compare_path_lists(self, vd_paths, exp_paths, g, 14)