diff --git a/networkxtest.py b/networkxtest.py index c5dce59d686b5cfe76e517c946df60d8d6d859d6..ed859ec5378d38eb89eb1c9db2511df59761d4a7 100644 --- a/networkxtest.py +++ b/networkxtest.py @@ -3,26 +3,30 @@ import matplotlib.pyplot as plt import os as os -class Hosts: +class Host: ips = list() masks = list() + networks = list() - def _init__(self, name, ips, masks): - self.name = name + def __init__(self): + self.name = "" self.ips = [] self.masks = [] + self.networks = [] G = nx.Graph() -routersNumber = 3 +routersNumber = 5 hosts = [] +newitem = Host() for x in range(1, routersNumber + 1): - newitem = Hosts() + 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') @@ -37,33 +41,54 @@ for x in range(1, routersNumber + 1): #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) - - for all in hosts: - print(all.name) - for i in all.ips: - print(i) - for i in all.masks: - print(i) +''' +for all in hosts: + print(all.name) + for i in all.ips: + print(i) + for i in all.masks: + print(i) + for i in all.networks: + print(i) + print("") +''' for all in hosts: G.add_node(all.name) G.add_nodes_from([all.name], ips = all.ips) G.add_nodes_from([all.name], masks = all.masks) + G.add_nodes_from([all.name], networks = all.networks) + +for i in range(len(hosts)-1): + for j in range(i+1, len(hosts)): + currentelement = hosts[i] + nextelement = hosts[j] + for crnws in currentelement.networks: + for nxnws in nextelement.networks: + 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:]) + -for all in hosts: - for toall in hosts: - for ina in all.ips: - for inb in toall.ips: - if ina == inb: - G.add_edge(all.name, toall.name) print(G.nodes.data()) nx.draw_networkx(G) plt.show() -#for x in range(1, routersNumber + 1 ): - #os.system('rm ~/onlab/router' + str(x) + '/router' + str(x) + '_locales.txt ~/onlab/router' + str(x) + '/router' + str(x) + '_name.txt ~/onlab/router' + str(x) + '/router' + str(x) + '_masks.txt') +for x in range(1, routersNumber + 1 ): + os.system('rm ~/onlab/router' + str(x) + '/router' + str(x) + '_locales.txt ~/onlab/router' + str(x) + '/router' + str(x) + '_name.txt ~/onlab/router' + str(x) + '/router' + str(x) + '_masks.txt ~/onlab/router' + str(x) + '/router' + str(x) + '_networks.txt') diff --git a/router1/router1_locales.txt b/router1/router1_locales.txt deleted file mode 100644 index 8b137891791fe96927ad78e64b0aad7bded08bdc..0000000000000000000000000000000000000000 --- a/router1/router1_locales.txt +++ /dev/null @@ -1 +0,0 @@ - diff --git a/router1/router1_masks.txt b/router1/router1_masks.txt deleted file mode 100644 index 8b137891791fe96927ad78e64b0aad7bded08bdc..0000000000000000000000000000000000000000 --- a/router1/router1_masks.txt +++ /dev/null @@ -1 +0,0 @@ - diff --git a/router1/router1_name.txt b/router1/router1_name.txt deleted file mode 100644 index 1e1244e1ec5540df6715f7a268d75821ea75b47b..0000000000000000000000000000000000000000 --- a/router1/router1_name.txt +++ /dev/null @@ -1 +0,0 @@ -R1 diff --git a/router1/router1_routes.txt b/router1/router1_routes.txt index 1e2ce4d66170423df3c4aad476b2c01e99a69ff6..70c742579a10814d9db5e0d46da852776783decc 100644 --- a/router1/router1_routes.txt +++ b/router1/router1_routes.txt @@ -1,11 +1,18 @@ Codes: L - local, C - connected, S - static, R - RIP, M - mobile, B - BGP - D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area + D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2 - E1 - OSPF external type 1, E2 - OSPF external type 2 - i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2 - ia - IS-IS inter area, * - candidate default, U - per-user static route - o - ODR, P - periodic downloaded static route, H - NHRP, l - LISP - a - application route - + - replicated route, % - next hop override, p - overrides from PfR + E1 - OSPF external type 1, E2 - OSPF external type 2, E - EGP + i - IS-IS, L1 - IS-IS level-1, L2 - IS-IS level-2, ia - IS-IS inter area + * - candidate default, U - per-user static route, o - ODR + P - periodic downloaded static route -Gateway of last resort is not set \ No newline at end of file +Gateway of last resort is not set + + 192.168.1.0/24 is variably subnetted, 2 subnets, 2 masks +C 192.168.1.0/24 is directly connected, GigabitEthernet0/0/0 +L 192.168.1.1/32 is directly connected, GigabitEthernet0/0/0 +S 192.168.2.0/24 [1/0] via 192.168.1.2 + 192.168.5.0/24 is variably subnetted, 2 subnets, 2 masks +C 192.168.5.0/24 is directly connected, GigabitEthernet0/0/1 +L 192.168.5.1/32 is directly connected, GigabitEthernet0/0/1 + \ No newline at end of file diff --git a/router2/router2_locales.txt b/router2/router2_locales.txt deleted file mode 100644 index 8b137891791fe96927ad78e64b0aad7bded08bdc..0000000000000000000000000000000000000000 --- a/router2/router2_locales.txt +++ /dev/null @@ -1 +0,0 @@ - diff --git a/router2/router2_masks.txt b/router2/router2_masks.txt deleted file mode 100644 index 8b137891791fe96927ad78e64b0aad7bded08bdc..0000000000000000000000000000000000000000 --- a/router2/router2_masks.txt +++ /dev/null @@ -1 +0,0 @@ - diff --git a/router2/router2_name.txt b/router2/router2_name.txt deleted file mode 100644 index 40d37fcc596f394d8d0d83bbce8fa0f86a2d0154..0000000000000000000000000000000000000000 --- a/router2/router2_name.txt +++ /dev/null @@ -1 +0,0 @@ -R2 diff --git a/router2/router2_routes.txt b/router2/router2_routes.txt index 1e2ce4d66170423df3c4aad476b2c01e99a69ff6..2e232b9305d2b629813d5a0be4511c66696f2120 100644 --- a/router2/router2_routes.txt +++ b/router2/router2_routes.txt @@ -1,11 +1,17 @@ Codes: L - local, C - connected, S - static, R - RIP, M - mobile, B - BGP - D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area + D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2 - E1 - OSPF external type 1, E2 - OSPF external type 2 - i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2 - ia - IS-IS inter area, * - candidate default, U - per-user static route - o - ODR, P - periodic downloaded static route, H - NHRP, l - LISP - a - application route - + - replicated route, % - next hop override, p - overrides from PfR + E1 - OSPF external type 1, E2 - OSPF external type 2, E - EGP + i - IS-IS, L1 - IS-IS level-1, L2 - IS-IS level-2, ia - IS-IS inter area + * - candidate default, U - per-user static route, o - ODR + P - periodic downloaded static route -Gateway of last resort is not set \ No newline at end of file +Gateway of last resort is not set + + 192.168.1.0/24 is variably subnetted, 2 subnets, 2 masks +C 192.168.1.0/24 is directly connected, GigabitEthernet0/0/0 +L 192.168.1.2/32 is directly connected, GigabitEthernet0/0/0 + 192.168.2.0/24 is variably subnetted, 2 subnets, 2 masks +C 192.168.2.0/24 is directly connected, GigabitEthernet0/0/1 +L 192.168.2.2/32 is directly connected, GigabitEthernet0/0/1 +S 192.168.3.0/24 [1/0] via 192.168.2.1 \ No newline at end of file diff --git a/router3/router3_locales.txt b/router3/router3_locales.txt deleted file mode 100644 index 8b137891791fe96927ad78e64b0aad7bded08bdc..0000000000000000000000000000000000000000 --- a/router3/router3_locales.txt +++ /dev/null @@ -1 +0,0 @@ - diff --git a/router3/router3_masks.txt b/router3/router3_masks.txt deleted file mode 100644 index 8b137891791fe96927ad78e64b0aad7bded08bdc..0000000000000000000000000000000000000000 --- a/router3/router3_masks.txt +++ /dev/null @@ -1 +0,0 @@ - diff --git a/router3/router3_name.txt b/router3/router3_name.txt deleted file mode 100644 index a773565a53ea6c6b16035baff92cf54fb6238c76..0000000000000000000000000000000000000000 --- a/router3/router3_name.txt +++ /dev/null @@ -1 +0,0 @@ -R3 diff --git a/router3/router3_routes.txt b/router3/router3_routes.txt index 1e2ce4d66170423df3c4aad476b2c01e99a69ff6..e7b73c4292ff75dd2bb4ab9c1e95a359a281ed23 100644 --- a/router3/router3_routes.txt +++ b/router3/router3_routes.txt @@ -1,11 +1,16 @@ Codes: L - local, C - connected, S - static, R - RIP, M - mobile, B - BGP - D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area + D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2 - E1 - OSPF external type 1, E2 - OSPF external type 2 - i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2 - ia - IS-IS inter area, * - candidate default, U - per-user static route - o - ODR, P - periodic downloaded static route, H - NHRP, l - LISP - a - application route - + - replicated route, % - next hop override, p - overrides from PfR + E1 - OSPF external type 1, E2 - OSPF external type 2, E - EGP + i - IS-IS, L1 - IS-IS level-1, L2 - IS-IS level-2, ia - IS-IS inter area + * - candidate default, U - per-user static route, o - ODR + P - periodic downloaded static route -Gateway of last resort is not set \ No newline at end of file +Gateway of last resort is not set + + 192.168.2.0/24 is variably subnetted, 2 subnets, 2 masks +C 192.168.2.0/24 is directly connected, GigabitEthernet0/0/1 +L 192.168.2.1/32 is directly connected, GigabitEthernet0/0/1 + 192.168.3.0/24 is variably subnetted, 2 subnets, 2 masks +C 192.168.3.0/24 is directly connected, Loopback0 +L 192.168.3.1/32 is directly connected, Loopback0 \ No newline at end of file diff --git a/router4/router4_hostname.txt b/router4/router4_hostname.txt new file mode 100644 index 0000000000000000000000000000000000000000..15f938521e9dee092cc9483f3790a4d20cd9d4ce --- /dev/null +++ b/router4/router4_hostname.txt @@ -0,0 +1 @@ +hostname R4 \ No newline at end of file diff --git a/router4/router4_routes.txt b/router4/router4_routes.txt new file mode 100644 index 0000000000000000000000000000000000000000..a49869ba18fdf7a4b590ee09698a7efb018dbf47 --- /dev/null +++ b/router4/router4_routes.txt @@ -0,0 +1,18 @@ +Codes: L - local, C - connected, S - static, R - RIP, M - mobile, B - BGP + D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area + N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2 + E1 - OSPF external type 1, E2 - OSPF external type 2, E - EGP + i - IS-IS, L1 - IS-IS level-1, L2 - IS-IS level-2, ia - IS-IS inter area + * - candidate default, U - per-user static route, o - ODR + P - periodic downloaded static route + +Gateway of last resort is not set + + 192.168.3.0/24 is variably subnetted, 2 subnets, 2 masks +C 192.168.3.0/24 is directly connected, GigabitEthernet0/0/0 +L 192.168.3.2/32 is directly connected, GigabitEthernet0/0/0 + 192.168.5.0/24 is variably subnetted, 2 subnets, 2 masks +C 192.168.5.0/24 is directly connected, GigabitEthernet0/0/1 +L 192.168.5.2/32 is directly connected, GigabitEthernet0/0/1 +C 192.168.6.0/24 is directly connected, GigabitEthernet0/0/1 +L 192.168.6.2/32 is directly connected, GigabitEthernet0/0/1 \ No newline at end of file diff --git a/router5/router5_hostname.txt b/router5/router5_hostname.txt new file mode 100644 index 0000000000000000000000000000000000000000..5f7d3b2559145e297df0f254ef658efd84fa85ee --- /dev/null +++ b/router5/router5_hostname.txt @@ -0,0 +1 @@ +hostname R5 \ No newline at end of file diff --git a/router5/router5_routes.txt b/router5/router5_routes.txt new file mode 100644 index 0000000000000000000000000000000000000000..6e5cf89b77a5afa42eb5ed86ebf780134002d7b4 --- /dev/null +++ b/router5/router5_routes.txt @@ -0,0 +1,15 @@ +Codes: L - local, C - connected, S - static, R - RIP, M - mobile, B - BGP + D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area + N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2 + E1 - OSPF external type 1, E2 - OSPF external type 2, E - EGP + i - IS-IS, L1 - IS-IS level-1, L2 - IS-IS level-2, ia - IS-IS inter area + * - candidate default, U - per-user static route, o - ODR + P - periodic downloaded static route + +Gateway of last resort is not set + + 192.168.4.0/24 is variably subnetted, 2 subnets, 2 masks +C 192.168.4.0/24 is directly connected, GigabitEthernet0/0/1 +L 192.168.4.2/32 is directly connected, GigabitEthernet0/0/1 +C 192.168.6.0/24 is directly connected, GigabitEthernet0/0/1 +L 192.168.6.1/32 is directly connected, GigabitEthernet0/0/1 \ No newline at end of file