Skip to content

Commit

Permalink
submission
Browse files Browse the repository at this point in the history
Co-authored-by: Vihaan Thora <[email protected]>
  • Loading branch information
gjain-7 and vihaanthora committed May 6, 2023
1 parent 76b3e8c commit 5280abf
Show file tree
Hide file tree
Showing 15 changed files with 99 additions and 58 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ This is an example of how to list things you need to use the software and how to
```sh
pip install -r requirements.txt
```
_Note : Make sure to keep the `eventlet` (pip package) version @0.30.2 (alreay there in requiements)_
_Note : Make sure to keep the `eventlet` (pip package) version @0.30.2 (already there in requirements)_
2. Enter the your topology in the `topology.txt`.

Format for the topology:
Expand Down
59 changes: 31 additions & 28 deletions client.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import json
from utils import cost

main_url = "http://10.250.3.163:8080"
# main_url = "http://127.0.0.1:8080"
main_url = "http://127.0.0.1:8080"


# host1:host2 :host1->S1->S2->host2
def display_paths(paths):
Expand All @@ -15,7 +15,7 @@ def display_paths(paths):
print(f"{value[0]}-{key} :", end="")
print("->".join(value))
print()


# in_port,dl_src,dl_dst actions=output
def display_rules(rules):
Expand All @@ -33,7 +33,7 @@ def display_rules(rules):
# <node1-node2> : <cost>
def display_links(links):
print("\n***************************************\n")
print("Netwrok Links and Cost\n")
print("Network Links and Cost\n")
nodes_done = {}
for k, v in links.items():
if nodes_done.get(k[0] + k[1], 0) == 1:
Expand Down Expand Up @@ -102,6 +102,7 @@ def get_links():
print(e)
exit(0)


# Minimum cost from a particular host to all other hosts
def getMinPath():
host = input("Enter host name: ")
Expand All @@ -113,7 +114,8 @@ def getMinPath():
exit(0)
res = response.json()
display_paths(res)



# Get rules for a particular switch
def get_rules():
switch_num = int(input("Enter switch number: "))
Expand All @@ -126,42 +128,43 @@ def get_rules():
exit(0)



def main():
get_links()


while True:
t=input("\n1 Get rules for a switch\n2 Get minimum path\n3 Add Connections\n4 Exit\nEnter your choice: ")
if t=='1':
t = input(
"\n1 Get rules for a switch\n2 Get minimum path\n3 Add Connections\n4 Exit\nEnter your choice: "
)
if t == "1":
get_rules()
elif t=='2':
elif t == "2":
while 1:
getMinPath()
while 1:
choice = input("Do you want to continue(y/n): ")
if choice not in ['y','n','Y','N']: print("Invalid Choice!")
else: break
if choice.lower() == 'n':
if choice not in ["y", "n", "Y", "N"]:
print("Invalid Choice!")
else:
break
if choice.lower() == "n":
break
elif t=='3':
print("\n1 MAC Based\n2 IP Based\n3 Name Based")
n = input("\nEnter your choice: ")
elif t == "3":
print("\n1 MAC Based\n2 IP Based\n3 Name Based")
n = input("\nEnter your choice: ")
while 1:
add_connection(n)
while 1:
add_connection(n)
while 1:
choice = input("Do you want to continue(y/n): ")
if choice not in ['y','n','Y','N']: print("Invalid Choice!")
else: break
if choice.lower() == 'n':
choice = input("Do you want to continue(y/n): ")
if choice not in ["y", "n", "Y", "N"]:
print("Invalid Choice!")
else:
break
elif t=='4':

if choice.lower() == "n":
break
elif t == "4":
exit(0)
else:
print("Invalid Choice\n")



if __name__=='__main__':
main()
if __name__ == "__main__":
main()
2 changes: 1 addition & 1 deletion controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def add_rule(self, datapath, in_port, src_mac, dst_mac, out_port):
match=match,
instructions=instructions,
out_port=out_port,
priority=ofproto.OFP_DEFAULT_PRIORITY,
priority=5,
idle_timeout=0,
hard_timeout=0,
buffer_id=ofproto.OFP_NO_BUFFER,
Expand Down
2 changes: 1 addition & 1 deletion rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,4 @@ def list_flows(self, req, **kwargs):
self.controller.lock.wait()
return Response(
json_body=self.controller.flows, content_type="application/json"
)
)
File renamed without changes.
7 changes: 7 additions & 0 deletions sample_topology/sample_topo_2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
h1 s1 10 2
s1 s2 5 1
s1 s4 10 4
s2 s3 10 4
s3 s4 5 1
s3 h2 10 2
s2 s4 10 2
22 changes: 22 additions & 0 deletions sample_topology/sample_topo_3.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
s1 s2 50 1
s2 s3 50 2
s3 s4 50 3
s4 s5 50 2
s5 s1 50 5
s6 s7 50 4
s7 s8 50 3
s8 s9 50 2
s9 s10 50 1
s10 s6 50 3
s2 s7 50 5
s4 s9 50 2
h1 s1 50 1
h2 s2 50 1
h3 s3 50 1
h4 s4 50 1
h5 s5 50 1
h6 s6 50 1
h7 s7 50 1
h8 s8 50 1
h9 s9 50 1
h10 s10 50 1
12 changes: 12 additions & 0 deletions sample_topology/sample_topo_4.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
s1 s2 10 1
s2 s5 10 1
s5 s4 10 1
s3 s4 10 1
s1 s3 10 1
s2 s4 10 1
s2 s3 10 1
s1 h1 10 1
s2 h2 10 1
s3 h3 10 1
s4 h4 10 1
s5 h5 10 1
Binary file added screenshots/client_add-connection.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added screenshots/link-cost.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added screenshots/mininet-network.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added screenshots/mininet_switch-flows.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added screenshots/single_source_shortest_paths.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
29 changes: 22 additions & 7 deletions topology.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,22 @@
h1 s1 10 2
s1 s2 5 1
s1 s4 10 4
s2 s3 10 4
s3 s4 5 1
s3 h2 10 2
s2 s4 10 2
s1 s2 50 1
s2 s3 50 2
s3 s4 50 3
s4 s5 50 2
s5 s1 50 5
s6 s7 50 4
s7 s8 50 3
s8 s9 50 2
s9 s10 50 1
s10 s6 50 3
s2 s7 50 5
s4 s9 50 2
h1 s1 50 1
h2 s2 50 1
h3 s3 50 1
h4 s4 50 1
h5 s5 50 1
h6 s6 50 1
h7 s7 50 1
h8 s8 50 1
h9 s9 50 1
h10 s10 50 1
22 changes: 2 additions & 20 deletions utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import heapq
from typing import *


def cost(bandwidth, delay):
return delay + 1 / (1 + bandwidth)

Expand Down Expand Up @@ -40,25 +41,6 @@ def dijkstra(src, bw_query, adj, links):
return distances, paths


def get_output(dst_path, links):
rules = {(dst_path[0], dst_path[-1]): []}
ports = []
for i in range(len(dst_path) - 1):
s1, s2 = dst_path[i], dst_path[i + 1]
ports.append(links[(s1, s2)][0])
ports.append(links[(s1, s2)][1])
ports = ports[1:-1]
cnt = 0
for i in range(len(dst_path) - 2):
s = dst_path[i + 1]
port1 = ports[cnt]
port2 = ports[cnt + 1]
cnt += 2
rules[(dst_path[0], dst_path[-1])].append((s, port1, port2))
print(ports)
return rules


def load_data(file, duplicate_entries=True):
"Stores the link data (bw, delay)"
with open(file, "r") as f:
Expand All @@ -68,7 +50,7 @@ def load_data(file, duplicate_entries=True):
for row in lines:
node1, node2 = row[0], row[1]
data[(node1, node2)] = [int(row[2]), int(row[3])]
if(duplicate_entries):
if duplicate_entries:
data[(node2, node1)] = [int(row[2]), int(row[3])]

return data

0 comments on commit 5280abf

Please sign in to comment.