def generate_rip_graph(draw_flag, size): """ :param draw_flag: boolean indicating whether the graph should be drawn or not :param size: Integer indicating the size of the graph to be generated :return n_graph: the generated graph """ n_graph = graph_gen.generate_graph(size) # Add a distance matrix, a best weights vector and a queue to all the nodes n = n_graph.number_of_nodes() for i in range(0, n): new_distance_matrix = np.empty((n, n)) new_distance_matrix.fill(sys.maxint) new_distance_matrix[i].fill(-1) # Fill with -1 me as destination new_distance_matrix[:, i] = -1 # Fill with -1 me as path new_best_weights_vector = np.empty(n) new_best_weights_vector.fill(sys.maxint) new_default_next_hop_vector = np.empty(n) new_default_next_hop_vector.fill(None) n_graph.node[i]['distance_matrix'] = new_distance_matrix n_graph.node[i]['default_next_hop'] = new_default_next_hop_vector # Control messages content n_graph.node[i]['best_weights_vector'] = new_best_weights_vector n_graph.node[i]['buffer_queue'] = Queue.Queue(maxsize=n) n_graph.nodes(data=True) if draw_flag: graph_gen.draw_graph(n_graph) return n_graph
rip_broadcast(net_graph) rip_update_distance_matrix(net_graph) return net_graph if __name__ == '__main__': # network_graph = generate_rip_graph(False, 4) # # rip_first_iteration(network_graph) # # while not convergence: # rip_broadcast(network_graph) # rip_update_distance_matrix(network_graph) network_graph = rip_simple(100) # Comparing with bellman-ford for testing for n, nattr in network_graph.nodes(data=True): # For each node n and attribute nattr print "Our RIP:" print "(%d,%s)" % (n, nattr['best_weights_vector']) print "(%d,%s)" % (n, nattr['default_next_hop']) pred, dist = nx.bellman_ford(network_graph, n) print "Bellman_ford:" print sorted(dist.items()) print sorted(pred.items()) break graph_gen.draw_graph(network_graph)