Permalink
Browse files

update

  • Loading branch information...
afourmy committed Jun 8, 2016
1 parent 1e99b3b commit 96e0dfe9f4e5567df96657850ebc31cb4e95c5f0
Showing with 1,424 additions and 663 deletions.
  1. +0 −411 AS.py
  2. +1 −0 AUTHOR
  3. +674 −0 LICENSE
  4. +190 −0 NetDim/AS.py
  5. +170 −0 NetDim/AS_management.py
  6. 0 { → NetDim}/__init__.py
  7. BIN NetDim/__pycache__/AS.cpython-34.pyc
  8. BIN NetDim/__pycache__/AS_management.cpython-34.pyc
  9. BIN NetDim/__pycache__/advanced_graph_options.cpython-34.pyc
  10. BIN NetDim/__pycache__/area.cpython-34.pyc
  11. BIN NetDim/__pycache__/drawing_options_window.cpython-34.pyc
  12. BIN NetDim/__pycache__/frame.cpython-34.pyc
  13. BIN NetDim/__pycache__/gui.cpython-34.pyc
  14. BIN NetDim/__pycache__/menus.cpython-34.pyc
  15. BIN NetDim/__pycache__/miscellaneous.cpython-34.pyc
  16. BIN NetDim/__pycache__/network.cpython-34.pyc
  17. BIN NetDim/__pycache__/object_management_window.cpython-34.pyc
  18. BIN NetDim/__pycache__/objects.cpython-34.pyc
  19. BIN NetDim/__pycache__/scenario.cpython-34.pyc
  20. +10 −2 { → NetDim}/advanced_graph_options.py
  21. +54 −0 NetDim/area.py
  22. +10 −2 { → NetDim}/drawing_options_window.py
  23. +20 −22 { → NetDim}/frame.py
  24. +38 −45 { → NetDim}/gui.py
  25. +5 −0 { → NetDim}/main.py
  26. +12 −10 { → NetDim}/menus.py
  27. +14 −10 { → NetDim}/miscellaneous.py
  28. +147 −98 { → NetDim}/network.py
  29. +24 −16 { → NetDim}/object_management_window.py
  30. +16 −6 { → NetDim}/objects.py
  31. +28 −24 { → NetDim}/scenario.py
  32. +10 −8 { → NetDim}/test.py
  33. BIN Tests/test_SP.xls
  34. +1 −1 Tests/test_export.csv
  35. +0 −8 Tests/test_export.txt
  36. BIN Tests/test_export.xls
  37. BIN Workspace/isis2.xls
  38. BIN Workspace/spider.xls
  39. BIN __pycache__/AS.cpython-34.pyc
  40. BIN __pycache__/AS_management.cpython-34.pyc
  41. BIN __pycache__/advanced_graph_options.cpython-34.pyc
  42. BIN __pycache__/area.cpython-34.pyc
  43. BIN __pycache__/drawing_options_window.cpython-34.pyc
  44. BIN __pycache__/frame.cpython-34.pyc
  45. BIN __pycache__/gui.cpython-34.pyc
  46. BIN __pycache__/menus.cpython-34.pyc
  47. BIN __pycache__/miscellaneous.cpython-34.pyc
  48. BIN __pycache__/network.cpython-34.pyc
  49. BIN __pycache__/object_management_window.cpython-34.pyc
  50. BIN __pycache__/objects.cpython-34.pyc
  51. BIN __pycache__/scenario.cpython-34.pyc
View
411 AS.py

This file was deleted.

Oops, something went wrong.
View
1 AUTHOR
@@ -0,0 +1 @@
Antoine Fourmy
View
674 LICENSE

Large diffs are not rendered by default.

Oops, something went wrong.
View
@@ -0,0 +1,190 @@
# NetDim
# Copyright (C) 2016 Antoine Fourmy (antoine.fourmy@gmail.com)
# Released under the GNU General Public License GPLv3
import tkinter as tk
from tkinter import ttk
from miscellaneous import CustomTopLevel
from collections import defaultdict
import area
import AS_management
class AutonomousSystem(object):
class_type = "AS"
def __init__(self, scenario, type, name, trunks=set(), nodes=set(), edges=set(), imp=False):
self.name = name
self.type = type
# pAS as in "pool AS": same as pool network
self.pAS = {"trunk": trunks, "node": nodes, "edge": edges}
# areas is a dict associating a name to an area
self.areas = {}
# routes is a dict of dict such that routes[eA][eB] returns the route
# object going from edge A (source) to edge B (destination).
self.routes = defaultdict(dict)
for obj in nodes | trunks:
obj.AS[self] = set()
# management window of the AS
self.management = AS_management.ASManagement(scenario, self, imp)
# imp tells us if the AS is imported or created from scratch.
if not imp:
self.area_factory("Backbone")
# each type of algorithm will have a specific algorithm, that defines
# how to compute a path in the AS
self.AS_type_to_class = {
"RIP": scenario.ntw.RIP_routing,
"ISIS": scenario.ntw.ISIS_routing
}
self.algorithm = self.AS_type_to_class[type]
def __repr__(self):
return self.name
def __eq__(self, other):
return isinstance(other, self.__class__) and self.name == other.name
def __ne__(self, other):
return not self.__eq__(other)
def __hash__(self):
return hash(self.name)
def area_factory(self, name, trunks=set(), nodes=set()):
if name not in self.areas:
self.areas[name] = area.Area(name, self, trunks, nodes)
return self.areas[name]
def add_to_AS(self, area, *objects):
area.add_to_area(*objects)
for obj in objects:
# add objects in the AS corresponding pool
self.pAS[obj.network_type].add(obj)
def remove_from_AS(self, *objects):
for obj in objects:
# we remove the object from its pool in the AS
self.pAS[obj.network_type].discard(obj)
# we pop the AS from the dict of object AS, and retrieve the list
# of area it belongs to in this AS
obj_areas = obj.AS.pop(self, set())
# for each area, we delete the object from the corresponding pool
for area in obj_areas:
area.remove_from_area(obj)
# we also try to remove it from edge if it was a node
self.pAS["edge"].discard(obj)
def add_to_edges(self, node):
self.pAS["edge"].add(node)
def remove_from_edges(self, node):
self.pAS["edge"].discard(node)
class ModifyAS(CustomTopLevel):
def __init__(self, scenario, mode, obj, AS=set()):
super().__init__()
self.geometry("30x90")
# TODO put that in the dict
titles = {
"add": "Add to AS/area",
"remove": "Remove from AS",
"remove area": "Remove from area",
"manage": "Manage AS"
}
self.title(titles[mode])
# always at least one row and one column with a weight > 0
self.grid_columnconfigure(0, weight=1)
self.grid_rowconfigure(0, weight=1)
# TODO make it a dict
if mode == "add":
command = lambda: self.add(scenario, *obj)
values = tuple(map(str, scenario.ntw.pn["AS"].values()))
elif mode == "remove":
values = tuple(map(str, AS))
command = lambda: self.remove_from_AS(scenario, *obj)
elif mode == "remove area":
values = tuple(map(str, AS))
command = lambda: self.remove_from_area(scenario, *obj)
elif mode == "manage":
values = tuple(map(str, AS))
command = lambda: self.manage_AS(scenario)
# List of existing AS
self.AS_list = ttk.Combobox(self, width=9)
self.AS_list["values"] = values
self.AS_list.current(0)
self.AS_list.grid(row=0, column=0, columnspan=2, pady=5, padx=5, sticky="nsew")
self.AS_list.bind('<<ComboboxSelected>>', lambda e: self.update_value(scenario))
if mode in ("add", "remove area"):
self.area_list = ttk.Combobox(self, width=9)
self.update_value(scenario)
self.area_list.current(0)
self.area_list.grid(row=1, column=0, columnspan=2, pady=5, padx=5, sticky="nsew")
# Button to add in an AS
self.button_add_AS = ttk.Button(self, text="OK", command=command)
#row = 2 if mode in ("add", "remove area") else 1
self.button_add_AS.grid(row=2, column=0, columnspan=2, pady=5, padx=5, sticky="nsew")
# when a different AS is selected, the area combobox is updated accordingly
def update_value(self, scenario):
selected_AS = scenario.ntw.AS_factory(name=self.AS_list.get())
self.area_list["values"] = tuple(map(str, selected_AS.areas))
# TODO merge these three functions into one with the mode
# they share the check + destroy
def add(self, scenario, *objects):
selected_AS = scenario.ntw.AS_factory(name=self.AS_list.get())
selected_AS.management.add_to_AS(self.area_list.get(), *objects)
self.destroy()
def remove_from_area(self, scenario, *objects):
selected_AS = scenario.ntw.AS_factory(name=self.AS_list.get())
selected_AS.management.remove_from_area(self.area_list.get(), *objects)
self.destroy()
def remove_from_AS(self, scenario, *objects):
selected_AS = scenario.ntw.AS_factory(name=self.AS_list.get())
selected_AS.management.remove_from_AS(*objects)
self.destroy()
def manage_AS(self, scenario):
selected_AS = scenario.ntw.AS_factory(name=self.AS_list.get())
selected_AS.management.deiconify()
self.destroy()
class ASCreation(CustomTopLevel):
def __init__(self, scenario, so):
super().__init__()
self.geometry("120x100")
self.title("Create AS")
# List of AS type
self.var_AS_type = tk.StringVar()
self.AS_type_list = ttk.Combobox(self, textvariable=self.var_AS_type, width=6)
self.AS_type_list["values"] = ("RIP", "IS-IS", "OSPF", "MPLS", "RSTP")
self.AS_type_list.current(0)
# retrieve and save node data
self.button_create_AS = ttk.Button(self, text="Create AS", command=lambda: self.create_AS(scenario, so))
# Label for the name/type of the AS
self.label_name = tk.Label(self, bg="#A1DBCD", text="Name")
self.label_type = tk.Label(self, bg="#A1DBCD", text="Type")
# Entry box for the name of the AS
self.var_name = tk.StringVar()
self.entry_name = tk.Entry(self, textvariable=self.var_name, width=10)
self.label_name.grid(row=0, column=0, pady=5, padx=5, sticky=tk.W)
self.entry_name.grid(row=0, column=1, sticky=tk.W)
self.label_type.grid(row=1, column=0, pady=5, padx=5, sticky=tk.W)
self.AS_type_list.grid(row=1,column=1, pady=5, padx=5, sticky=tk.W)
self.button_create_AS.grid(row=3,column=0, columnspan=2, pady=5, padx=5)
def create_AS(self, scenario, so):
new_AS = scenario.ntw.AS_factory(name=self.var_name.get(), type=self.var_AS_type.get(), trunks=so["link"], nodes=so["node"])
self.destroy()
View
@@ -0,0 +1,170 @@
# NetDim
# Copyright (C) 2016 Antoine Fourmy (antoine.fourmy@gmail.com)
# Released under the GNU General Public License GPLv3
import tkinter as tk
from tkinter import ttk
from miscellaneous import ObjectListbox, FocusTopLevel
class ASManagement(FocusTopLevel):
def __init__(self, scenario, AS, imp):
super().__init__()
self.scenario = scenario
self.AS = AS
self.geometry("345x440")
self.title("Manage AS")
self.obj_type = ("trunk", "node", "edge")
self.area_listbox = ("area names", "area trunks", "area nodes")
# listbox of all AS objects
self.dict_listbox = {}
for index, type in enumerate(self.obj_type):
tk.Label(self, bg="#A1DBCD", text="".join(("AS ",type,"s"))).grid(row=1, column=2*index)
listbox = ObjectListbox(self, activestyle="none", width=15, height=7)
self.dict_listbox[type] = listbox
yscroll = tk.Scrollbar(self, command=self.dict_listbox[type].yview, orient=tk.VERTICAL)
listbox.configure(yscrollcommand=yscroll.set)
listbox.bind("<<ListboxSelect>>", lambda e, type=type: self.highlight_object(e, type))
listbox.grid(row=2, column=2*index)
yscroll.grid(row=2, column=1+2*index, sticky="ns")
# populate the listbox with all objects from which the AS was created
for obj_type in ("trunk", "node", "edge"):
for obj in AS.pAS[obj_type]:
self.dict_listbox[obj_type].insert(obj)
# listbox for areas
for index, type in enumerate(self.area_listbox):
tk.Label(self, bg="#A1DBCD", text=type.title()).grid(row=5, column=2*index)
listbox = ObjectListbox(self, activestyle="none", width=15, height=7)
self.dict_listbox[type] = listbox
yscroll = tk.Scrollbar(self, command=self.dict_listbox[type].yview, orient=tk.VERTICAL)
listbox.configure(yscrollcommand=yscroll.set)
if type == "area names":
listbox.bind("<<ListboxSelect>>", lambda e: self.display_area(e))
else:
listbox.bind("<<ListboxSelect>>", lambda e, type=type: self.highlight_object(e, type))
listbox.grid(row=6, column=2*index)
yscroll.grid(row=6, column=1+2*index, sticky="ns")
# find edge nodes of the AS
self.button_find_edge_nodes = ttk.Button(self, text="Find edges", command=lambda: self.find_edge_nodes())
self.button_create_route = ttk.Button(self, text="Create route", command=lambda: self.create_routes())
# find domain trunks: the trunks between nodes of the AS
self.button_find_trunks = ttk.Button(self, text="Find trunks", command=lambda: self.find_trunks())
# operation on nodes
self.button_remove_node_from_AS = ttk.Button(self, text="Remove node", command=lambda: self.remove_selected("node"))
self.button_add_to_edges = ttk.Button(self, text="Add to edges", command=lambda: self.add_to_edges())
self.button_remove_from_edges = ttk.Button(self, text="Remove edge", command=lambda: self.remove_from_edges())
# buttons under the trunks column
self.button_create_route.grid(row=3, column=0)
self.button_find_trunks.grid(row=4, column=0)
# button under the nodes column
self.button_remove_node_from_AS.grid(row=3, column=2)
self.button_add_to_edges.grid(row=4, column=2)
self.button_remove_from_edges.grid(row=5)
# button under the edge column
self.button_find_edge_nodes.grid(row=3, column=4)
self.button_remove_from_edges.grid(row=4, column=4)
# button to create an area
self.button_create_area = ttk.Button(self, text="Create area", command=lambda: area.CreateArea(self))
self.button_create_area.grid(row=7, column=0)
# at first, the backbone is the only area: we insert it in the listbox
self.dict_listbox["area names"].insert("Backbone")
# hide the window when closed
self.protocol("WM_DELETE_WINDOW", self.withdraw)
# if the AS is created from an import, close the management window
if imp: self.withdraw()
## Functions used directly from the AS Management window
# function to highlight the selected object on the canvas
def highlight_object(self, event, obj_type):
selected_object = self.dict_listbox[obj_type].selected()
selected_object = self.scenario.ntw.of(name=selected_object, _type=obj_type)
self.scenario.unhighlight_all()
self.scenario.highlight_objects(selected_object)
# remove the object selected in "obj_type" listbox from the AS
def remove_selected(self, obj_type):
# remove and retrieve the selected object in the listbox
selected_obj = self.dict_listbox[obj_type].pop_selected()
# remove it from the AS as well
self.AS.remove_from_AS(self.scenario.ntw.of(name=selected_obj, _type=obj_type))
def add_to_edges(self):
selected_node = self.dict_listbox["node"].selected()
self.dict_listbox["edge"].insert(selected_node)
selected_node = self.scenario.ntw.nf(name=selected_node)
self.AS.add_to_edges(selected_node)
def remove_from_edges(self):
selected = self.scenario.ntw.nf(name=self.dict_listbox["edge"].pop_selected())
self.AS.remove_from_edges(selected)
def add_to_AS(self, area, *objects):
self.AS.add_to_AS(self.AS.areas[area], *objects)
for obj in objects:
self.dict_listbox[obj.network_type].insert(obj)
def find_edge_nodes(self):
self.dict_listbox["edge"].clear()
for edge in self.scenario.ntw.find_edge_nodes(self.AS):
self.dict_listbox["edge"].insert(edge)
def find_trunks(self):
trunks_between_domain_nodes = set()
for node in self.AS.pAS["node"]:
for neighbor, adj_trunk in self.scenario.ntw.graph[node]["trunk"]:
if neighbor in self.AS.pAS["node"]:
trunks_between_domain_nodes.add(adj_trunk)
self.add_to_AS("Backbone", *trunks_between_domain_nodes)
def create_routes(self):
for eA in self.AS.pAS["edge"]:
for eB in self.AS.pAS["edge"]:
if eA != eB and eB not in self.AS.routes[eA]:
name = "->".join((str(eA), str(eB)))
route = self.scenario.ntw.lf(link_type="route", name=name, s=eA, d=eB)
_, route.path = self.AS.algorithm(eA, eB, self.AS)
route.AS = self.AS
self.scenario.create_link(route)
def create_area(self, name):
self.AS.area_factory(name)
self.dict_listbox["area names"].insert(name)
def display_area(self, event):
area = self.dict_listbox["area names"].selected()
area = self.AS.area_factory(area)
self.scenario.unhighlight_all()
self.scenario.highlight_objects(*(area.pa["node"] | area.pa["trunk"]))
self.dict_listbox["area nodes"].clear()
self.dict_listbox["area trunks"].clear()
for node in area.pa["node"]:
self.dict_listbox["area nodes"].insert(node)
for trunk in area.pa["trunk"]:
self.dict_listbox["area trunks"].insert(trunk)
## Functions used to modify AS from the right-click menu
def remove_from_area(self, area, *objects):
self.AS.areas[area].remove_from_area(*objects)
def remove_from_AS(self, *objects):
self.AS.remove_from_AS(*objects)
for obj in objects:
if obj.network_type == "node":
# remove the node from nodes/edges listbox
self.dict_listbox["node"].pop(obj)
self.dict_listbox["edge"].pop(obj)
elif obj.network_type == "trunk":
self.dict_listbox["trunk"].pop(obj)
File renamed without changes.
View
Binary file not shown.
Binary file not shown.
Binary file not shown.
View
Binary file not shown.
Binary file not shown.
View
Binary file not shown.
View
Binary file not shown.
View
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
View
Binary file not shown.
Binary file not shown.
@@ -1,8 +1,12 @@
# NetDim
# Copyright (C) 2016 Antoine Fourmy (antoine.fourmy@gmail.com)
# Released under the GNU General Public License GPLv3
import tkinter as tk
from tkinter import ttk
from miscellaneous import CustomTopLevel
from miscellaneous import FocusTopLevel
class AdvancedGraphOptionsWindow(CustomTopLevel):
class AdvancedGraphOptionsWindow(FocusTopLevel):
def __init__(self, master):
super().__init__()
self.geometry("600x300")
@@ -37,6 +41,10 @@ def __init__(self, master):
self.entry_source.grid(row=3,column=1, pady=5, padx=5, sticky=tk.W)
self.entry_destination.grid(row=4,column=1, pady=5, padx=5, sticky=tk.W)
# hide the window when closed
self.protocol("WM_DELETE_WINDOW", self.withdraw)
self.withdraw()
def highlight_connected_components(self, master):
master.cs.unhighlight_all()
for idx, connex_comp in enumerate(master.cs.ntw.connected_components()):
Oops, something went wrong.

0 comments on commit 96e0dfe

Please sign in to comment.