diff --git a/networkxtest.py b/networkxtest.py index ed859ec5378d38eb89eb1c9db2511df59761d4a7..ba309271c1015181bd49031b1ed829f966585184 100644 --- a/networkxtest.py +++ b/networkxtest.py @@ -22,29 +22,31 @@ hosts = [] newitem = Host() for x in range(1, routersNumber + 1): + newitem = Host() #reconstruct new item to empty item + os.system('echo "$(cat ~/onlab/router' + str(x) + '/router' + str(x) + '_hostname.txt | grep "h" | cut -d\' \' -f2)" >> ~/onlab/router' + str(x) + '/router' + str(x) + '_name.txt') with open('./router' + str(x) + '/router' + str(x) + '_name.txt','r') as file_1: for line in file_1.readlines(): - #print(line) line = line.replace('\n', '') newitem.name = line + os.system('echo "$(cat ~/onlab/router' + str(x) + '/router' + str(x) + '_routes.txt | grep "^L " | cut -d\' \' -f9 | cut -d\'/\' -f1)" >> ~/onlab/router' + str(x) + '/router' + str(x) + '_locales.txt') with open('./router' + str(x) + '/router' + str(x) + '_locales.txt', 'r') as file_2: for line in file_2.readlines(): #print(line) line = line.replace('\n', '') newitem.ips.append(line) + os.system('echo "$(cat ~/onlab/router' + str(x) + '/router' + str(x) + '_routes.txt | grep "^C " | cut -d\' \' -f9 | cut -d\'/\' -f2)" >> ~/onlab/router' + str(x) + '/router' + str(x) + '_masks.txt') with open('./router' + str(x) + '/router' + str(x) + '_masks.txt', 'r') as file_3: for line in file_3.readlines(): - #print(line) line = line.replace('\n', '') newitem.masks.append(line) + os.system('echo "$(cat ~/onlab/router' + str(x) + '/router' + str(x) + '_routes.txt | grep "^C " | cut -d\' \' -f9 | cut -d\'/\' -f1)" >> ~/onlab/router' + str(x) + '/router' + str(x) + '_networks.txt') with open('./router' + str(x) + '/router' + str(x) + '_networks.txt', 'r') as file_4: for line in file_4.readlines(): - #print(line) line = line.replace('\n', '') newitem.networks.append(line) hosts.append(newitem) @@ -75,14 +77,22 @@ for i in range(len(hosts)-1): if crnws == nxnws: G.add_edge(currentelement.name, nextelement.name) -for edge in nx.bfs_edges(G, source="R1"): - print("Edge:", edge) -#path = list(nx.algorithms.bfs_edges(G, source=1)) -#print(path) -#path_edges = list(path, path[1:]) +pathlist= [] + +all_paths = list(nx.all_simple_paths(G, source="R2", target="R5")) +for path in all_paths: + pathelements = [] + for all in path: + pathelements.append(all) + print(all, end=' ') + print("\n") + pathlist.append(pathelements) +for all in pathlist: + for to in all: + print(to, end=" ") -print(G.nodes.data()) +#print(G.nodes.data()) nx.draw_networkx(G) plt.show() diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000000000000000000000000000000000000..79c5fa75d76df1d98e6ba1307c934ae81f17a9ef --- /dev/null +++ b/requirements.txt @@ -0,0 +1 @@ +sudo apt-get install python3-tk