Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
gjain-7 committed Apr 24, 2023
0 parents commit eb71417
Show file tree
Hide file tree
Showing 19 changed files with 1,629 additions and 0 deletions.
163 changes: 163 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
.pybuilder/
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# poetry
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
#poetry.lock

# pdm
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
#pdm.lock
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
# in version control.
# https://pdm.fming.dev/#use-with-ide
.pdm.toml

# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# pytype static type analyzer
.pytype/

# Cython debug symbols
cython_debug/

# PyCharm
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/

# VS Code
.vscode
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
A Ryu based SDN (Software defined Networking) controller to implement switch circuiting using SPF (Shortest Path First) algorithm.

## Todo
- [ ] implement and test `add_rules` and `get_rules` methods.
- [ ] update the cost function along the path possibly in the add rules
- [ ] make the adj list using `EventHostAdd` and `EventSwiwtchAdd` events
122 changes: 122 additions & 0 deletions client.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
# http://10.250.11.109:8080/hosts
import requests
from ast import literal_eval
import json
from utils import cost

# from utils import cost
main_url = "http://10.250.11.109:8080"

# host1:host2: host1->S1->S2->host2
def display_paths(host, data):
for key, value in data.items():
if key == host:
continue
if key[0] == "h":
print(f"{host}-{key} :", end="")
for i in range(len(value) - 1):
print(f"{value[i]}->", end="")
print(f"{value[-1]}")
print()


def pretify(data):
nodes_done = {}
# node1-node2 : cost
for k, v in data.items():
if nodes_done.get(k[0] + k[1], 0) == 1:
continue
print(k[0] + "-" + k[1] + " : " + str(cost(v[0], v[1])))
nodes_done[k[0] + k[1]] = 1
nodes_done[k[1] + k[0]] = 1


def add_connection(main_url):
url = main_url + "/add"
print("1 MAC Based\n2 IP Based\n")
n = input("Enter your choice: ")
data = {"id_spec": "mac" if n == "1" else "ip", "src": "", "dst": "", "bw": 0}
while 1:
print("Enter host1 host2 bandwidth")
inp_str = input()
inp_list = inp_str.split()
if len(inp_list) < 3:
print("Invalid Input...\nTry Again!\n")
continue
host1 = inp_list[0]
host2 = inp_list[1]
try:
bw = float(inp_list[2])
except ValueError:
print("Invalid Input... Bandwidth must be a number\nTry Again!\n")
continue
data["id_spec"] = "gn"
data["src"] = host1
data["dst"] = host2
data["bw"] = bw
try:
response = requests.post(url, json=data)
except:
print("Connection Refused... Try Again Later!\n")
exit(0)

print(response.text)
res = response.json()
if len(res) == 0:
print("No possible path found\n")
else:
print(res)
print()


def get_links(main_url):
url = main_url + "/links"
try:
response = requests.get(url)
res = response.json()
data = {literal_eval(k): v for k, v in json.loads(res).items()}
except requests.exceptions.ConnectionError:
print("Connection Refused... Try Again Later!\n")
exit(0)
pretify(data)


# minimum cost from a particular host to all other hosts
def getMinPath(main_url):
while 1:
host = input("Enter host name: ")
url = f"{main_url}/paths/{host}"
try:
response = requests.get(url)

# res=response.json()
except requests.exceptions.ConnectionError:
print("Connection Refused... Try Again Later!\n")
exit(0)
res = response.json()
display_paths(host, res)


def get_rules(main_url):
switch_num = int(input("Enter switch number: "))
url = f"{main_url}/flows/{switch_num}"
try:
response = requests.get(url)

# res=response.json()
except requests.exceptions.ConnectionError:
print("Connection Refused... Try Again Later!\n")
exit(0)


# getMinPath(main_url)

add_connection(main_url)


# links=get_links(main_url)
# print(links)

# get_links(main_url)

# get_rules(main_url)
Loading

0 comments on commit eb71417

Please sign in to comment.