Merge pull request #293 from coreemu/sidebar

Sidebar
This commit is contained in:
bharnden 2019-09-27 16:03:23 -07:00 committed by GitHub
commit 7562b8a445
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
29 changed files with 1261 additions and 651 deletions

BIN
coretk/coretk/OVS.gif Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 744 B

View file

@ -1,7 +1,8 @@
import logging
import tkinter as tk
import coretk.menuaction as action
from coretk.coremenubar import CoreMenubar
from coretk.coretoolbar import CoreToolbar
from coretk.graph import CanvasGraph
from coretk.images import Images
@ -16,7 +17,6 @@ class Application(tk.Frame):
self.create_widgets()
def load_images(self):
Images.load("switch", "switch.png")
Images.load("core", "core-icon.png")
def setup_app(self):
@ -26,668 +26,26 @@ class Application(tk.Frame):
self.master.tk.call("wm", "iconphoto", self.master._w, image)
self.pack(fill=tk.BOTH, expand=True)
def create_file_menu(self):
"""
Create file menu
:return: nothing
"""
file_menu = tk.Menu(self.menubar)
file_menu.add_command(
label="New", command=action.file_new, accelerator="Ctrl+N", underline=0
)
file_menu.add_command(
label="Open...", command=action.file_open, accelerator="Ctrl+O", underline=0
)
file_menu.add_command(label="Reload", command=action.file_reload, underline=0)
file_menu.add_command(
label="Save", command=action.file_save, accelerator="Ctrl+S", underline=0
)
file_menu.add_command(label="Save As XML...", command=action.file_save_as_xml)
file_menu.add_command(label="Save As imn...", command=action.file_save_as_imn)
file_menu.add_separator()
file_menu.add_command(
label="Export Python script...", command=action.file_export_python_script
)
file_menu.add_command(
label="Execute XML or Python script...",
command=action.file_execute_xml_or_python_script,
)
file_menu.add_command(
label="Execute Python script with options...",
command=action.file_execute_python_script_with_options,
)
file_menu.add_separator()
file_menu.add_command(
label="Open current file in editor...",
command=action.file_open_current_file_in_editor,
)
file_menu.add_command(label="Print...", command=action.file_print, underline=0)
file_menu.add_command(
label="Save screenshot...", command=action.file_save_screenshot
)
file_menu.add_separator()
file_menu.add_command(
label="/home/ncs/.core/configs/sample1.imn",
command=action.file_example_link,
)
file_menu.add_separator()
file_menu.add_command(label="Quit", command=self.master.quit, underline=0)
self.menubar.add_cascade(label="File", menu=file_menu, underline=0)
def create_edit_menu(self):
"""
Create edit menu
:return: nothing
"""
edit_menu = tk.Menu(self.menubar)
edit_menu.add_command(
label="Undo", command=action.edit_undo, accelerator="Ctrl+Z", underline=0
)
edit_menu.add_command(
label="Redo", command=action.edit_redo, accelerator="Ctrl+Y", underline=0
)
edit_menu.add_separator()
edit_menu.add_command(
label="Cut", command=action.edit_cut, accelerator="Ctrl+X", underline=0
)
edit_menu.add_command(
label="Copy", command=action.edit_copy, accelerator="Ctrl+C", underline=0
)
edit_menu.add_command(
label="Paste", command=action.edit_paste, accelerator="Ctrl+V", underline=0
)
edit_menu.add_separator()
edit_menu.add_command(
label="Select all", command=action.edit_select_all, accelerator="Ctrl+A"
)
edit_menu.add_command(
label="Select Adjacent",
command=action.edit_select_adjacent,
accelerator="Ctrl+J",
)
edit_menu.add_separator()
edit_menu.add_command(
label="Find...", command=action.edit_find, accelerator="Ctrl+F", underline=0
)
edit_menu.add_command(label="Clear marker", command=action.edit_clear_marker)
edit_menu.add_command(label="Preferences...", command=action.edit_preferences)
self.menubar.add_cascade(label="Edit", menu=edit_menu, underline=0)
def create_canvas_menu(self):
"""
Create canvas menu
:return: nothing
"""
canvas_menu = tk.Menu(self.menubar)
canvas_menu.add_command(label="New", command=action.canvas_new)
canvas_menu.add_command(label="Manage...", command=action.canvas_manage)
canvas_menu.add_command(label="Delete", command=action.canvas_delete)
canvas_menu.add_separator()
canvas_menu.add_command(label="Size/scale...", command=action.canvas_size_scale)
canvas_menu.add_command(label="Wallpaper...", command=action.canvas_wallpaper)
canvas_menu.add_separator()
canvas_menu.add_command(
label="Previous", command=action.canvas_previous, accelerator="PgUp"
)
canvas_menu.add_command(
label="Next", command=action.canvas_next, accelerator="PgDown"
)
canvas_menu.add_command(
label="First", command=action.canvas_first, accelerator="Home"
)
canvas_menu.add_command(
label="Last", command=action.canvas_last, accelerator="End"
)
self.menubar.add_cascade(label="Canvas", menu=canvas_menu, underline=0)
def create_show_menu(self, view_menu):
"""
Create the menu items in View/Show
:param tkinter.Menu view_menu: the view menu
:return: nothing
"""
show_menu = tk.Menu(view_menu)
show_menu.add_command(label="All", command=action.sub_menu_items)
show_menu.add_command(label="None", command=action.sub_menu_items)
show_menu.add_separator()
show_menu.add_command(label="Interface Names", command=action.sub_menu_items)
show_menu.add_command(label="IPv4 Addresses", command=action.sub_menu_items)
show_menu.add_command(label="IPv6 Addresses", command=action.sub_menu_items)
show_menu.add_command(label="Node Labels", command=action.sub_menu_items)
show_menu.add_command(label="Annotations", command=action.sub_menu_items)
show_menu.add_command(label="Grid", command=action.sub_menu_items)
show_menu.add_command(label="API Messages", command=action.sub_menu_items)
view_menu.add_cascade(label="Show", menu=show_menu)
def create_view_menu(self):
"""
Create view menu
:return: nothing
"""
view_menu = tk.Menu(self.menubar)
self.create_show_menu(view_menu)
view_menu.add_command(
label="Show hidden nodes", command=action.view_show_hidden_nodes
)
view_menu.add_command(label="Locked", command=action.view_locked)
view_menu.add_command(label="3D GUI...", command=action.view_3d_gui)
view_menu.add_separator()
view_menu.add_command(
label="Zoom in", command=action.view_zoom_in, accelerator="+"
)
view_menu.add_command(
label="Zoom out", command=action.view_zoom_out, accelerator="-"
)
self.menubar.add_cascade(label="View", menu=view_menu, underline=0)
def create_experimental_menu(self, tools_menu):
"""
Create experimental menu item and the sub menu items inside
:param tkinter.Menu tools_menu: tools menu
:return: nothing
"""
experimental_menu = tk.Menu(tools_menu)
experimental_menu.add_command(
label="Plugins...", command=action.sub_menu_items, underline=0
)
experimental_menu.add_command(
label="ns2immunes converter...", command=action.sub_menu_items, underline=0
)
experimental_menu.add_command(
label="Topology partitioning...", command=action.sub_menu_items
)
tools_menu.add_cascade(
label="Experimental", menu=experimental_menu, underline=0
)
def create_random_menu(self, topology_generator_menu):
"""
Create random menu item and the sub menu items inside
:param tkinter.Menu topology_generator_menu: topology generator menu
:return: nothing
"""
random_menu = tk.Menu(topology_generator_menu)
# list of number of random nodes to create
nums = [1, 5, 10, 15, 20, 30, 40, 50, 75, 100]
for i in nums:
the_label = "R(" + str(i) + ")"
random_menu.add_command(label=the_label, command=action.sub_menu_items)
topology_generator_menu.add_cascade(
label="Random", menu=random_menu, underline=0
)
def create_grid_menu(self, topology_generator_menu):
"""
Create grid menu item and the sub menu items inside
:param tkinter.Menu topology_generator_menu: topology_generator_menu
:return: nothing
"""
grid_menu = tk.Menu(topology_generator_menu)
# list of number of nodes to create
nums = [1, 5, 10, 15, 20, 25, 30, 35, 40, 50, 60, 70, 80, 90, 100]
for i in nums:
the_label = "G(" + str(i) + ")"
grid_menu.add_command(label=the_label, command=action.sub_menu_items)
topology_generator_menu.add_cascade(label="Grid", menu=grid_menu, underline=0)
def create_connected_grid_menu(self, topology_generator_menu):
"""
Create connected grid menu items and the sub menu items inside
:param tkinter.Menu topology_generator_menu: topology generator menu
:return: nothing
"""
grid_menu = tk.Menu(topology_generator_menu)
for i in range(1, 11, 1):
i_n_menu = tk.Menu(grid_menu)
for j in range(1, 11, 1):
i_j_label = str(i) + " X " + str(j)
i_n_menu.add_command(label=i_j_label, command=action.sub_menu_items)
i_n_label = str(i) + " X N"
grid_menu.add_cascade(label=i_n_label, menu=i_n_menu)
topology_generator_menu.add_cascade(
label="Connected Grid", menu=grid_menu, underline=0
)
def create_chain_menu(self, topology_generator_menu):
"""
Create chain menu item and the sub menu items inside
:param tkinter.Menu topology_generator_menu: topology generator menu
:return: nothing
"""
chain_menu = tk.Menu(topology_generator_menu)
# number of nodes to create
nums = list(range(2, 25, 1)) + [32, 64, 128]
for i in nums:
the_label = "P(" + str(i) + ")"
chain_menu.add_command(label=the_label, command=action.sub_menu_items)
topology_generator_menu.add_cascade(label="Chain", menu=chain_menu, underline=0)
def create_star_menu(self, topology_generator_menu):
"""
Create star menu item and the sub menu items inside
:param tkinter.Menu topology_generator_menu: topology generator menu
:return: nothing
"""
star_menu = tk.Menu(topology_generator_menu)
for i in range(3, 26, 1):
the_label = "C(" + str(i) + ")"
star_menu.add_command(label=the_label, command=action.sub_menu_items)
topology_generator_menu.add_cascade(label="Star", menu=star_menu, underline=0)
def create_cycle_menu(self, topology_generator_menu):
"""
Create cycle menu item and the sub items inside
:param tkinter.Menu topology_generator_menu: topology generator menu
:return: nothing
"""
cycle_menu = tk.Menu(topology_generator_menu)
for i in range(3, 25, 1):
the_label = "C(" + str(i) + ")"
cycle_menu.add_command(label=the_label, command=action.sub_menu_items)
topology_generator_menu.add_cascade(label="Cycle", menu=cycle_menu, underline=0)
def create_wheel_menu(self, topology_generator_menu):
"""
Create wheel menu item and the sub menu items inside
:param tkinter.Menu topology_generator_menu: topology generator menu
:return: nothing
"""
wheel_menu = tk.Menu(topology_generator_menu)
for i in range(4, 26, 1):
the_label = "W(" + str(i) + ")"
wheel_menu.add_command(label=the_label, command=action.sub_menu_items)
topology_generator_menu.add_cascade(label="Wheel", menu=wheel_menu, underline=0)
def create_cube_menu(self, topology_generator_menu):
"""
Create cube menu item and the sub menu items inside
:param tkinter.Menu topology_generator_menu: topology generator menu
:return: nothing
"""
cube_menu = tk.Menu(topology_generator_menu)
for i in range(2, 7, 1):
the_label = "Q(" + str(i) + ")"
cube_menu.add_command(label=the_label, command=action.sub_menu_items)
topology_generator_menu.add_cascade(label="Cube", menu=cube_menu, underline=0)
def create_clique_menu(self, topology_generator_menu):
"""
Create clique menu item and the sub menu items inside
:param tkinter.Menu topology_generator_menu: topology generator menu
:return: nothing
"""
clique_menu = tk.Menu(topology_generator_menu)
for i in range(3, 25, 1):
the_label = "K(" + str(i) + ")"
clique_menu.add_command(label=the_label, command=action.sub_menu_items)
topology_generator_menu.add_cascade(
label="Clique", menu=clique_menu, underline=0
)
def create_bipartite_menu(self, topology_generator_menu):
"""
Create bipartite menu item and the sub menu items inside
:param tkinter.Menu topology_generator_menu: topology_generator_menu
:return: nothing
"""
bipartite_menu = tk.Menu(topology_generator_menu)
temp = 24
for i in range(1, 13, 1):
i_n_menu = tk.Menu(bipartite_menu)
for j in range(i, temp, 1):
i_j_label = "K(" + str(i) + " X " + str(j) + ")"
i_n_menu.add_command(label=i_j_label, command=action.sub_menu_items)
i_n_label = "K(" + str(i) + " X N)"
bipartite_menu.add_cascade(label=i_n_label, menu=i_n_menu)
temp = temp - 1
topology_generator_menu.add_cascade(
label="Bipartite", menu=bipartite_menu, underline=0
)
def create_topology_generator_menu(self, tools_menu):
"""
Create topology menu item and its sub menu items
:param tkinter.Menu tools_menu: tools menu
:return: nothing
"""
topology_generator_menu = tk.Menu(tools_menu)
self.create_random_menu(topology_generator_menu)
self.create_grid_menu(topology_generator_menu)
self.create_connected_grid_menu(topology_generator_menu)
self.create_chain_menu(topology_generator_menu)
self.create_star_menu(topology_generator_menu)
self.create_cycle_menu(topology_generator_menu)
self.create_wheel_menu(topology_generator_menu)
self.create_cube_menu(topology_generator_menu)
self.create_clique_menu(topology_generator_menu)
self.create_bipartite_menu(topology_generator_menu)
tools_menu.add_cascade(
label="Topology generator", menu=topology_generator_menu, underline=0
)
def create_tools_menu(self):
"""
Create tools menu
:return: nothing
"""
tools_menu = tk.Menu(self.menubar)
tools_menu.add_command(
label="Auto rearrange all",
command=action.tools_auto_rearrange_all,
underline=0,
)
tools_menu.add_command(
label="Auto rearrange selected",
command=action.tools_auto_rearrange_selected,
underline=0,
)
tools_menu.add_separator()
tools_menu.add_command(
label="Align to grid", command=action.tools_align_to_grid, underline=0
)
tools_menu.add_separator()
tools_menu.add_command(label="Traffic...", command=action.tools_traffic)
tools_menu.add_command(
label="IP addresses...", command=action.tools_ip_addresses, underline=0
)
tools_menu.add_command(
label="MAC addresses...", command=action.tools_mac_addresses, underline=0
)
tools_menu.add_command(
label="Build hosts file...",
command=action.tools_build_hosts_file,
underline=0,
)
tools_menu.add_command(
label="Renumber nodes...", command=action.tools_renumber_nodes, underline=0
)
self.create_experimental_menu(tools_menu)
self.create_topology_generator_menu(tools_menu)
tools_menu.add_command(label="Debugger...", command=action.tools_debugger)
self.menubar.add_cascade(label="Tools", menu=tools_menu, underline=0)
def create_observer_widgets_menu(self, widget_menu):
"""
Create observer widget menu item and create the sub menu items inside
:param tkinter.Menu widget_menu: widget_menu
:return: nothing
"""
observer_widget_menu = tk.Menu(widget_menu)
observer_widget_menu.add_command(label="None", command=action.sub_menu_items)
observer_widget_menu.add_command(
label="processes", command=action.sub_menu_items
)
observer_widget_menu.add_command(
label="ifconfig", command=action.sub_menu_items
)
observer_widget_menu.add_command(
label="IPv4 routes", command=action.sub_menu_items
)
observer_widget_menu.add_command(
label="IPv6 routes", command=action.sub_menu_items
)
observer_widget_menu.add_command(
label="OSPFv2 neighbors", command=action.sub_menu_items
)
observer_widget_menu.add_command(
label="OSPFv3 neighbors", command=action.sub_menu_items
)
observer_widget_menu.add_command(
label="Listening sockets", command=action.sub_menu_items
)
observer_widget_menu.add_command(
label="IPv4 MFC entries", command=action.sub_menu_items
)
observer_widget_menu.add_command(
label="IPv6 MFC entries", command=action.sub_menu_items
)
observer_widget_menu.add_command(
label="firewall rules", command=action.sub_menu_items
)
observer_widget_menu.add_command(
label="IPsec policies", command=action.sub_menu_items
)
observer_widget_menu.add_command(
label="docker logs", command=action.sub_menu_items
)
observer_widget_menu.add_command(
label="OSPFv3 MDR level", command=action.sub_menu_items
)
observer_widget_menu.add_command(
label="PIM neighbors", command=action.sub_menu_items
)
observer_widget_menu.add_command(label="Edit...", command=action.sub_menu_items)
widget_menu.add_cascade(label="Observer Widgets", menu=observer_widget_menu)
def create_adjacency_menu(self, widget_menu):
"""
Create adjacency menu item and the sub menu items inside
:param tkinter.Menu widget_menu: widget menu
:return: nothing
"""
adjacency_menu = tk.Menu(widget_menu)
adjacency_menu.add_command(label="OSPFv2", command=action.sub_menu_items)
adjacency_menu.add_command(label="OSPFv3", command=action.sub_menu_items)
adjacency_menu.add_command(label="OSLR", command=action.sub_menu_items)
adjacency_menu.add_command(label="OSLRv2", command=action.sub_menu_items)
widget_menu.add_cascade(label="Adjacency", menu=adjacency_menu)
def create_widgets_menu(self):
"""
Create widget menu
:return: nothing
"""
widget_menu = tk.Menu(self.menubar)
self.create_observer_widgets_menu(widget_menu)
self.create_adjacency_menu(widget_menu)
widget_menu.add_command(label="Throughput", command=action.widgets_throughput)
widget_menu.add_separator()
widget_menu.add_command(
label="Configure Adjacency...", command=action.widgets_configure_adjacency
)
widget_menu.add_command(
label="Configure Throughput...", command=action.widgets_configure_throughput
)
self.menubar.add_cascade(label="Widgets", menu=widget_menu, underline=0)
def create_session_menu(self):
"""
Create session menu
:return: nothing
"""
session_menu = tk.Menu(self.menubar)
session_menu.add_command(
label="Start", command=action.session_start, underline=0
)
session_menu.add_command(
label="Change sessions...",
command=action.session_change_sessions,
underline=0,
)
session_menu.add_separator()
session_menu.add_command(
label="Node types...", command=action.session_node_types, underline=0
)
session_menu.add_command(
label="Comments...", command=action.session_comments, underline=0
)
session_menu.add_command(
label="Hooks...", command=action.session_hooks, underline=0
)
session_menu.add_command(
label="Reset node positions",
command=action.session_reset_node_positions,
underline=0,
)
session_menu.add_command(
label="Emulation servers...",
command=action.session_emulation_servers,
underline=0,
)
session_menu.add_command(
label="Options...", command=action.session_options, underline=0
)
self.menubar.add_cascade(label="Session", menu=session_menu, underline=0)
def create_help_menu(self):
"""
Create help menu
:return: nothing
"""
help_menu = tk.Menu(self.menubar)
help_menu.add_command(
label="Core Github (www)", command=action.help_core_github
)
help_menu.add_command(
label="Core Documentation (www)", command=action.help_core_documentation
)
help_menu.add_command(label="About", command=action.help_about)
self.menubar.add_cascade(label="Help", menu=help_menu)
def bind_menubar_shortcut(self):
"""
Bind hot keys to matching command
:return: nothing
"""
self.bind_all("<Control-n>", action.file_new_shortcut)
self.bind_all("<Control-o>", action.file_open_shortcut)
self.bind_all("<Control-s>", action.file_save_shortcut)
self.bind_all("<Control-z>", action.edit_undo_shortcut)
self.bind_all("<Control-y>", action.edit_redo_shortcut)
self.bind_all("<Control-x>", action.edit_cut_shortcut)
self.bind_all("<Control-c>", action.edit_copy_shortcut)
self.bind_all("<Control-v>", action.edit_paste_shortcut)
self.bind_all("<Control-a>", action.edit_select_all_shortcut)
self.bind_all("<Control-j>", action.edit_select_adjacent_shortcut)
self.bind_all("<Control-f>", action.edit_find_shortcut)
self.bind_all("<Prior>", action.canvas_previous_shortcut)
self.bind_all("<Next>", action.canvas_next_shortcut)
self.bind_all("<Home>", action.canvas_first_shortcut)
self.bind_all("<End>", action.canvas_last_shortcut)
self.bind_all("<Control-Shift-plus>", action.view_zoom_in_shortcut)
self.bind_all("<Control-minus>", action.view_zoom_out_shortcut)
def create_menu(self):
self.master.option_add("*tearOff", tk.FALSE)
self.menubar = tk.Menu(self.master)
self.create_file_menu()
self.create_edit_menu()
self.create_canvas_menu()
self.create_view_menu()
self.create_tools_menu()
self.create_widgets_menu()
self.create_session_menu()
self.create_help_menu()
core_menu = CoreMenubar(self, self.master, self.menubar)
core_menu.create_core_menubar()
self.master.config(menu=self.menubar)
self.bind_menubar_shortcut()
def create_widgets(self):
image = Images.get("switch")
edit_frame = tk.Frame(self)
edit_frame.pack(side=tk.LEFT, fill=tk.Y, ipadx=2, ipady=2)
radio_value = tk.IntVar()
b = tk.Radiobutton(
edit_frame, indicatoron=False, variable=radio_value, value=1, image=image
)
b.pack(side=tk.TOP, pady=1)
b = tk.Radiobutton(
edit_frame, indicatoron=False, variable=radio_value, value=2, image=image
)
b.pack(side=tk.TOP, pady=1)
b = tk.Radiobutton(
edit_frame, indicatoron=False, variable=radio_value, value=3, image=image
)
b.pack(side=tk.TOP, pady=1)
b = tk.Radiobutton(
edit_frame, indicatoron=False, variable=radio_value, value=4, image=image
)
b.pack(side=tk.TOP, pady=1)
b = tk.Radiobutton(
edit_frame, indicatoron=False, variable=radio_value, value=5, image=image
)
b.pack(side=tk.TOP, pady=1)
core_editbar = CoreToolbar(self.master, edit_frame, self.menubar)
core_editbar.create_toolbar()
self.canvas = CanvasGraph(
self, background="#cccccc", scrollregion=(0, 0, 1000, 1000)
)
self.canvas.pack(fill=tk.BOTH, expand=True)
# self.canvas.create_line(0, 0, 10, 10)
scroll_x = tk.Scrollbar(
self.canvas, orient=tk.HORIZONTAL, command=self.canvas.xview
)

View file

@ -0,0 +1,654 @@
import tkinter as tk
import coretk.menuaction as action
class CoreMenubar(object):
"""
Core menubar
"""
def __init__(self, application, master, menubar):
"""
Create a CoreMenubar instance
:param master:
:param tkinter.Menu menubar: menubar object
:param coretk.app.Application application: application object
"""
self.menubar = menubar
self.master = master
self.application = application
def create_file_menu(self):
"""
Create file menu
:return: nothing
"""
file_menu = tk.Menu(self.menubar)
file_menu.add_command(
label="New", command=action.file_new, accelerator="Ctrl+N", underline=0
)
file_menu.add_command(
label="Open...", command=action.file_open, accelerator="Ctrl+O", underline=0
)
file_menu.add_command(label="Reload", command=action.file_reload, underline=0)
file_menu.add_command(
label="Save", command=action.file_save, accelerator="Ctrl+S", underline=0
)
file_menu.add_command(label="Save As XML...", command=action.file_save_as_xml)
file_menu.add_command(label="Save As imn...", command=action.file_save_as_imn)
file_menu.add_separator()
file_menu.add_command(
label="Export Python script...", command=action.file_export_python_script
)
file_menu.add_command(
label="Execute XML or Python script...",
command=action.file_execute_xml_or_python_script,
)
file_menu.add_command(
label="Execute Python script with options...",
command=action.file_execute_python_script_with_options,
)
file_menu.add_separator()
file_menu.add_command(
label="Open current file in editor...",
command=action.file_open_current_file_in_editor,
)
file_menu.add_command(label="Print...", command=action.file_print, underline=0)
file_menu.add_command(
label="Save screenshot...", command=action.file_save_screenshot
)
file_menu.add_separator()
file_menu.add_command(
label="/home/ncs/.core/configs/sample1.imn",
command=action.file_example_link,
)
file_menu.add_separator()
file_menu.add_command(label="Quit", command=self.master.quit, underline=0)
self.menubar.add_cascade(label="File", menu=file_menu, underline=0)
def create_edit_menu(self):
"""
Create edit menu
:return: nothing
"""
edit_menu = tk.Menu(self.menubar)
edit_menu.add_command(
label="Undo", command=action.edit_undo, accelerator="Ctrl+Z", underline=0
)
edit_menu.add_command(
label="Redo", command=action.edit_redo, accelerator="Ctrl+Y", underline=0
)
edit_menu.add_separator()
edit_menu.add_command(
label="Cut", command=action.edit_cut, accelerator="Ctrl+X", underline=0
)
edit_menu.add_command(
label="Copy", command=action.edit_copy, accelerator="Ctrl+C", underline=0
)
edit_menu.add_command(
label="Paste", command=action.edit_paste, accelerator="Ctrl+V", underline=0
)
edit_menu.add_separator()
edit_menu.add_command(
label="Select all", command=action.edit_select_all, accelerator="Ctrl+A"
)
edit_menu.add_command(
label="Select Adjacent",
command=action.edit_select_adjacent,
accelerator="Ctrl+J",
)
edit_menu.add_separator()
edit_menu.add_command(
label="Find...", command=action.edit_find, accelerator="Ctrl+F", underline=0
)
edit_menu.add_command(label="Clear marker", command=action.edit_clear_marker)
edit_menu.add_command(label="Preferences...", command=action.edit_preferences)
self.menubar.add_cascade(label="Edit", menu=edit_menu, underline=0)
def create_canvas_menu(self):
"""
Create canvas menu
:return: nothing
"""
canvas_menu = tk.Menu(self.menubar)
canvas_menu.add_command(label="New", command=action.canvas_new)
canvas_menu.add_command(label="Manage...", command=action.canvas_manage)
canvas_menu.add_command(label="Delete", command=action.canvas_delete)
canvas_menu.add_separator()
canvas_menu.add_command(label="Size/scale...", command=action.canvas_size_scale)
canvas_menu.add_command(label="Wallpaper...", command=action.canvas_wallpaper)
canvas_menu.add_separator()
canvas_menu.add_command(
label="Previous", command=action.canvas_previous, accelerator="PgUp"
)
canvas_menu.add_command(
label="Next", command=action.canvas_next, accelerator="PgDown"
)
canvas_menu.add_command(
label="First", command=action.canvas_first, accelerator="Home"
)
canvas_menu.add_command(
label="Last", command=action.canvas_last, accelerator="End"
)
self.menubar.add_cascade(label="Canvas", menu=canvas_menu, underline=0)
def create_show_menu(self, view_menu):
"""
Create the menu items in View/Show
:param tkinter.Menu view_menu: the view menu
:return: nothing
"""
show_menu = tk.Menu(view_menu)
show_menu.add_command(label="All", command=action.sub_menu_items)
show_menu.add_command(label="None", command=action.sub_menu_items)
show_menu.add_separator()
show_menu.add_command(label="Interface Names", command=action.sub_menu_items)
show_menu.add_command(label="IPv4 Addresses", command=action.sub_menu_items)
show_menu.add_command(label="IPv6 Addresses", command=action.sub_menu_items)
show_menu.add_command(label="Node Labels", command=action.sub_menu_items)
show_menu.add_command(label="Annotations", command=action.sub_menu_items)
show_menu.add_command(label="Grid", command=action.sub_menu_items)
show_menu.add_command(label="API Messages", command=action.sub_menu_items)
view_menu.add_cascade(label="Show", menu=show_menu)
def create_view_menu(self):
"""
Create view menu
:return: nothing
"""
view_menu = tk.Menu(self.menubar)
self.create_show_menu(view_menu)
view_menu.add_command(
label="Show hidden nodes", command=action.view_show_hidden_nodes
)
view_menu.add_command(label="Locked", command=action.view_locked)
view_menu.add_command(label="3D GUI...", command=action.view_3d_gui)
view_menu.add_separator()
view_menu.add_command(
label="Zoom in", command=action.view_zoom_in, accelerator="+"
)
view_menu.add_command(
label="Zoom out", command=action.view_zoom_out, accelerator="-"
)
self.menubar.add_cascade(label="View", menu=view_menu, underline=0)
def create_experimental_menu(self, tools_menu):
"""
Create experimental menu item and the sub menu items inside
:param tkinter.Menu tools_menu: tools menu
:return: nothing
"""
experimental_menu = tk.Menu(tools_menu)
experimental_menu.add_command(
label="Plugins...", command=action.sub_menu_items, underline=0
)
experimental_menu.add_command(
label="ns2immunes converter...", command=action.sub_menu_items, underline=0
)
experimental_menu.add_command(
label="Topology partitioning...", command=action.sub_menu_items
)
tools_menu.add_cascade(
label="Experimental", menu=experimental_menu, underline=0
)
def create_random_menu(self, topology_generator_menu):
"""
Create random menu item and the sub menu items inside
:param tkinter.Menu topology_generator_menu: topology generator menu
:return: nothing
"""
random_menu = tk.Menu(topology_generator_menu)
# list of number of random nodes to create
nums = [1, 5, 10, 15, 20, 30, 40, 50, 75, 100]
for i in nums:
the_label = "R(" + str(i) + ")"
random_menu.add_command(label=the_label, command=action.sub_menu_items)
topology_generator_menu.add_cascade(
label="Random", menu=random_menu, underline=0
)
def create_grid_menu(self, topology_generator_menu):
"""
Create grid menu item and the sub menu items inside
:param tkinter.Menu topology_generator_menu: topology_generator_menu
:return: nothing
"""
grid_menu = tk.Menu(topology_generator_menu)
# list of number of nodes to create
nums = [1, 5, 10, 15, 20, 25, 30, 35, 40, 50, 60, 70, 80, 90, 100]
for i in nums:
the_label = "G(" + str(i) + ")"
grid_menu.add_command(label=the_label, command=action.sub_menu_items)
topology_generator_menu.add_cascade(label="Grid", menu=grid_menu, underline=0)
def create_connected_grid_menu(self, topology_generator_menu):
"""
Create connected grid menu items and the sub menu items inside
:param tkinter.Menu topology_generator_menu: topology generator menu
:return: nothing
"""
grid_menu = tk.Menu(topology_generator_menu)
for i in range(1, 11, 1):
i_n_menu = tk.Menu(grid_menu)
for j in range(1, 11, 1):
i_j_label = str(i) + " X " + str(j)
i_n_menu.add_command(label=i_j_label, command=action.sub_menu_items)
i_n_label = str(i) + " X N"
grid_menu.add_cascade(label=i_n_label, menu=i_n_menu)
topology_generator_menu.add_cascade(
label="Connected Grid", menu=grid_menu, underline=0
)
def create_chain_menu(self, topology_generator_menu):
"""
Create chain menu item and the sub menu items inside
:param tkinter.Menu topology_generator_menu: topology generator menu
:return: nothing
"""
chain_menu = tk.Menu(topology_generator_menu)
# number of nodes to create
nums = list(range(2, 25, 1)) + [32, 64, 128]
for i in nums:
the_label = "P(" + str(i) + ")"
chain_menu.add_command(label=the_label, command=action.sub_menu_items)
topology_generator_menu.add_cascade(label="Chain", menu=chain_menu, underline=0)
def create_star_menu(self, topology_generator_menu):
"""
Create star menu item and the sub menu items inside
:param tkinter.Menu topology_generator_menu: topology generator menu
:return: nothing
"""
star_menu = tk.Menu(topology_generator_menu)
for i in range(3, 26, 1):
the_label = "C(" + str(i) + ")"
star_menu.add_command(label=the_label, command=action.sub_menu_items)
topology_generator_menu.add_cascade(label="Star", menu=star_menu, underline=0)
def create_cycle_menu(self, topology_generator_menu):
"""
Create cycle menu item and the sub items inside
:param tkinter.Menu topology_generator_menu: topology generator menu
:return: nothing
"""
cycle_menu = tk.Menu(topology_generator_menu)
for i in range(3, 25, 1):
the_label = "C(" + str(i) + ")"
cycle_menu.add_command(label=the_label, command=action.sub_menu_items)
topology_generator_menu.add_cascade(label="Cycle", menu=cycle_menu, underline=0)
def create_wheel_menu(self, topology_generator_menu):
"""
Create wheel menu item and the sub menu items inside
:param tkinter.Menu topology_generator_menu: topology generator menu
:return: nothing
"""
wheel_menu = tk.Menu(topology_generator_menu)
for i in range(4, 26, 1):
the_label = "W(" + str(i) + ")"
wheel_menu.add_command(label=the_label, command=action.sub_menu_items)
topology_generator_menu.add_cascade(label="Wheel", menu=wheel_menu, underline=0)
def create_cube_menu(self, topology_generator_menu):
"""
Create cube menu item and the sub menu items inside
:param tkinter.Menu topology_generator_menu: topology generator menu
:return: nothing
"""
cube_menu = tk.Menu(topology_generator_menu)
for i in range(2, 7, 1):
the_label = "Q(" + str(i) + ")"
cube_menu.add_command(label=the_label, command=action.sub_menu_items)
topology_generator_menu.add_cascade(label="Cube", menu=cube_menu, underline=0)
def create_clique_menu(self, topology_generator_menu):
"""
Create clique menu item and the sub menu items inside
:param tkinter.Menu topology_generator_menu: topology generator menu
:return: nothing
"""
clique_menu = tk.Menu(topology_generator_menu)
for i in range(3, 25, 1):
the_label = "K(" + str(i) + ")"
clique_menu.add_command(label=the_label, command=action.sub_menu_items)
topology_generator_menu.add_cascade(
label="Clique", menu=clique_menu, underline=0
)
def create_bipartite_menu(self, topology_generator_menu):
"""
Create bipartite menu item and the sub menu items inside
:param tkinter.Menu topology_generator_menu: topology_generator_menu
:return: nothing
"""
bipartite_menu = tk.Menu(topology_generator_menu)
temp = 24
for i in range(1, 13, 1):
i_n_menu = tk.Menu(bipartite_menu)
for j in range(i, temp, 1):
i_j_label = "K(" + str(i) + " X " + str(j) + ")"
i_n_menu.add_command(label=i_j_label, command=action.sub_menu_items)
i_n_label = "K(" + str(i) + " X N)"
bipartite_menu.add_cascade(label=i_n_label, menu=i_n_menu)
temp = temp - 1
topology_generator_menu.add_cascade(
label="Bipartite", menu=bipartite_menu, underline=0
)
def create_topology_generator_menu(self, tools_menu):
"""
Create topology menu item and its sub menu items
:param tkinter.Menu tools_menu: tools menu
:return: nothing
"""
topology_generator_menu = tk.Menu(tools_menu)
self.create_random_menu(topology_generator_menu)
self.create_grid_menu(topology_generator_menu)
self.create_connected_grid_menu(topology_generator_menu)
self.create_chain_menu(topology_generator_menu)
self.create_star_menu(topology_generator_menu)
self.create_cycle_menu(topology_generator_menu)
self.create_wheel_menu(topology_generator_menu)
self.create_cube_menu(topology_generator_menu)
self.create_clique_menu(topology_generator_menu)
self.create_bipartite_menu(topology_generator_menu)
tools_menu.add_cascade(
label="Topology generator", menu=topology_generator_menu, underline=0
)
def create_tools_menu(self):
"""
Create tools menu
:return: nothing
"""
tools_menu = tk.Menu(self.menubar)
tools_menu.add_command(
label="Auto rearrange all",
command=action.tools_auto_rearrange_all,
underline=0,
)
tools_menu.add_command(
label="Auto rearrange selected",
command=action.tools_auto_rearrange_selected,
underline=0,
)
tools_menu.add_separator()
tools_menu.add_command(
label="Align to grid", command=action.tools_align_to_grid, underline=0
)
tools_menu.add_separator()
tools_menu.add_command(label="Traffic...", command=action.tools_traffic)
tools_menu.add_command(
label="IP addresses...", command=action.tools_ip_addresses, underline=0
)
tools_menu.add_command(
label="MAC addresses...", command=action.tools_mac_addresses, underline=0
)
tools_menu.add_command(
label="Build hosts file...",
command=action.tools_build_hosts_file,
underline=0,
)
tools_menu.add_command(
label="Renumber nodes...", command=action.tools_renumber_nodes, underline=0
)
self.create_experimental_menu(tools_menu)
self.create_topology_generator_menu(tools_menu)
tools_menu.add_command(label="Debugger...", command=action.tools_debugger)
self.menubar.add_cascade(label="Tools", menu=tools_menu, underline=0)
def create_observer_widgets_menu(self, widget_menu):
"""
Create observer widget menu item and create the sub menu items inside
:param tkinter.Menu widget_menu: widget_menu
:return: nothing
"""
observer_widget_menu = tk.Menu(widget_menu)
observer_widget_menu.add_command(label="None", command=action.sub_menu_items)
observer_widget_menu.add_command(
label="processes", command=action.sub_menu_items
)
observer_widget_menu.add_command(
label="ifconfig", command=action.sub_menu_items
)
observer_widget_menu.add_command(
label="IPv4 routes", command=action.sub_menu_items
)
observer_widget_menu.add_command(
label="IPv6 routes", command=action.sub_menu_items
)
observer_widget_menu.add_command(
label="OSPFv2 neighbors", command=action.sub_menu_items
)
observer_widget_menu.add_command(
label="OSPFv3 neighbors", command=action.sub_menu_items
)
observer_widget_menu.add_command(
label="Listening sockets", command=action.sub_menu_items
)
observer_widget_menu.add_command(
label="IPv4 MFC entries", command=action.sub_menu_items
)
observer_widget_menu.add_command(
label="IPv6 MFC entries", command=action.sub_menu_items
)
observer_widget_menu.add_command(
label="firewall rules", command=action.sub_menu_items
)
observer_widget_menu.add_command(
label="IPsec policies", command=action.sub_menu_items
)
observer_widget_menu.add_command(
label="docker logs", command=action.sub_menu_items
)
observer_widget_menu.add_command(
label="OSPFv3 MDR level", command=action.sub_menu_items
)
observer_widget_menu.add_command(
label="PIM neighbors", command=action.sub_menu_items
)
observer_widget_menu.add_command(label="Edit...", command=action.sub_menu_items)
widget_menu.add_cascade(label="Observer Widgets", menu=observer_widget_menu)
def create_adjacency_menu(self, widget_menu):
"""
Create adjacency menu item and the sub menu items inside
:param tkinter.Menu widget_menu: widget menu
:return: nothing
"""
adjacency_menu = tk.Menu(widget_menu)
adjacency_menu.add_command(label="OSPFv2", command=action.sub_menu_items)
adjacency_menu.add_command(label="OSPFv3", command=action.sub_menu_items)
adjacency_menu.add_command(label="OSLR", command=action.sub_menu_items)
adjacency_menu.add_command(label="OSLRv2", command=action.sub_menu_items)
widget_menu.add_cascade(label="Adjacency", menu=adjacency_menu)
def create_widgets_menu(self):
"""
Create widget menu
:return: nothing
"""
widget_menu = tk.Menu(self.menubar)
self.create_observer_widgets_menu(widget_menu)
self.create_adjacency_menu(widget_menu)
widget_menu.add_command(label="Throughput", command=action.widgets_throughput)
widget_menu.add_separator()
widget_menu.add_command(
label="Configure Adjacency...", command=action.widgets_configure_adjacency
)
widget_menu.add_command(
label="Configure Throughput...", command=action.widgets_configure_throughput
)
self.menubar.add_cascade(label="Widgets", menu=widget_menu, underline=0)
def create_session_menu(self):
"""
Create session menu
:return: nothing
"""
session_menu = tk.Menu(self.menubar)
session_menu.add_command(
label="Start", command=action.session_start, underline=0
)
session_menu.add_command(
label="Change sessions...",
command=action.session_change_sessions,
underline=0,
)
session_menu.add_separator()
session_menu.add_command(
label="Node types...", command=action.session_node_types, underline=0
)
session_menu.add_command(
label="Comments...", command=action.session_comments, underline=0
)
session_menu.add_command(
label="Hooks...", command=action.session_hooks, underline=0
)
session_menu.add_command(
label="Reset node positions",
command=action.session_reset_node_positions,
underline=0,
)
session_menu.add_command(
label="Emulation servers...",
command=action.session_emulation_servers,
underline=0,
)
session_menu.add_command(
label="Options...", command=action.session_options, underline=0
)
self.menubar.add_cascade(label="Session", menu=session_menu, underline=0)
def create_help_menu(self):
"""
Create help menu
:return: nothing
"""
help_menu = tk.Menu(self.menubar)
help_menu.add_command(
label="Core Github (www)", command=action.help_core_github
)
help_menu.add_command(
label="Core Documentation (www)", command=action.help_core_documentation
)
help_menu.add_command(label="About", command=action.help_about)
self.menubar.add_cascade(label="Help", menu=help_menu)
def bind_menubar_shortcut(self):
"""
Bind hot keys to matching command
:return: nothing
"""
self.application.bind_all("<Control-n>", action.file_new_shortcut)
self.application.bind_all("<Control-o>", action.file_open_shortcut)
self.application.bind_all("<Control-s>", action.file_save_shortcut)
self.application.bind_all("<Control-z>", action.edit_undo_shortcut)
self.application.bind_all("<Control-y>", action.edit_redo_shortcut)
self.application.bind_all("<Control-x>", action.edit_cut_shortcut)
self.application.bind_all("<Control-c>", action.edit_copy_shortcut)
self.application.bind_all("<Control-v>", action.edit_paste_shortcut)
self.application.bind_all("<Control-a>", action.edit_select_all_shortcut)
self.application.bind_all("<Control-j>", action.edit_select_adjacent_shortcut)
self.application.bind_all("<Control-f>", action.edit_find_shortcut)
self.application.bind_all("<Prior>", action.canvas_previous_shortcut)
self.application.bind_all("<Next>", action.canvas_next_shortcut)
self.application.bind_all("<Home>", action.canvas_first_shortcut)
self.application.bind_all("<End>", action.canvas_last_shortcut)
self.application.bind_all("<Control-Shift-plus>", action.view_zoom_in_shortcut)
self.application.bind_all("<Control-minus>", action.view_zoom_out_shortcut)
def create_core_menubar(self):
"""
Create core menubar and bind the hot keys to their matching command
:return: nothing
"""
self.create_file_menu()
self.create_edit_menu()
self.create_canvas_menu()
self.create_view_menu()
self.create_tools_menu()
self.create_widgets_menu()
self.create_session_menu()
self.create_help_menu()
self.bind_menubar_shortcut()

View file

@ -0,0 +1,543 @@
import logging
import tkinter as tk
from coretk.images import Images
from coretk.tooltip import CreateToolTip
class CoreToolbar(object):
"""
Core toolbar class
"""
def __init__(self, master, edit_frame, menubar):
"""
Create a CoreToolbar instance
:param tkinter.Frame edit_frame: edit frame
"""
self.master = master
self.edit_frame = edit_frame
self.menubar = menubar
self.radio_value = tk.IntVar()
self.exec_radio_value = tk.IntVar()
# button dimension
self.width = 32
self.height = 32
# Used for drawing the horizontally displayed menu items for network-layer nodes and link-layer node
self.selection_tool_button = None
# Reference to the option menus
self.link_layer_option_menu = None
self.marker_option_menu = None
self.network_layer_option_menu = None
def load_toolbar_images(self):
"""
Load the images that appear in core toolbar
:return: nothing
"""
Images.load("core", "core-icon.png")
Images.load("start", "start.gif")
Images.load("switch", "lanswitch.gif")
Images.load("marker", "marker.gif")
Images.load("router", "router.gif")
Images.load("select", "select.gif")
Images.load("link", "link.gif")
Images.load("hub", "hub.gif")
Images.load("wlan", "wlan.gif")
Images.load("rj45", "rj45.gif")
Images.load("tunnel", "tunnel.gif")
Images.load("oval", "oval.gif")
Images.load("rectangle", "rectangle.gif")
Images.load("text", "text.gif")
Images.load("host", "host.gif")
Images.load("pc", "pc.gif")
Images.load("mdr", "mdr.gif")
Images.load("prouter", "router_green.gif")
Images.load("ovs", "OVS.gif")
Images.load("editnode", "document-properties.gif")
Images.load("run", "run.gif")
Images.load("plot", "plot.gif")
Images.load("twonode", "twonode.gif")
Images.load("stop", "stop.gif")
Images.load("observe", "observe.gif")
def destroy_previous_frame(self):
"""
Destroy any extra frame from previous before drawing a new one
:return: nothing
"""
if (
self.network_layer_option_menu
and self.network_layer_option_menu.winfo_exists()
):
self.network_layer_option_menu.destroy()
if self.link_layer_option_menu and self.link_layer_option_menu.winfo_exists():
self.link_layer_option_menu.destroy()
if self.marker_option_menu and self.marker_option_menu.winfo_exists():
self.marker_option_menu.destroy()
def destroy_children_widgets(self, parent):
"""
Destroy all children of a parent widget
:param tkinter.Frame parent: parent frame
:return: nothing
"""
for i in parent.winfo_children():
if i.winfo_name() != "!frame":
i.destroy()
def create_button(self, img, func, frame, main_button):
"""
Create button and put it on the frame
:param PIL.Image img: button image
:param func: the command that is executed when button is clicked
:param tkinter.Frame frame: frame that contains the button
:param tkinter.Radiobutton main_button: main button
:return: nothing
"""
button = tk.Button(frame, width=self.width, height=self.height, image=img)
button.pack(side=tk.LEFT, pady=1)
button.bind("<Button-1>", lambda mb: func(main_button))
def create_radio_button(self, frame, image, func, variable, value, tooltip_msg):
button = tk.Radiobutton(
frame,
indicatoron=False,
width=self.width,
height=self.height,
image=image,
value=value,
variable=variable,
command=func,
)
button.pack(side=tk.TOP, pady=1)
CreateToolTip(button, tooltip_msg)
def create_regular_button(self, frame, image, func):
button = tk.Button(
frame, width=self.width, height=self.height, image=image, command=func
)
button.pack(side=tk.TOP, pady=1)
def draw_button_menu_frame(self, edit_frame, option_frame, main_button):
"""
Draw option menu frame right next to the main button
:param tkinter.Frame edit_frame: parent frame of the main button
:param tkinter.Frame option_frame: option frame to draw
:param tkinter.Radiobutton main_button: the main button
:return: nothing
"""
first_button = edit_frame.winfo_children()[0]
_x = main_button.winfo_rootx() - first_button.winfo_rootx() + 40
_y = main_button.winfo_rooty() - first_button.winfo_rooty() - 1
option_frame.place(x=_x, y=_y)
def bind_widgets_before_frame_hide(self, frame):
"""
Bind the widgets to a left click, when any of the widgets is clicked, the menu option frame is destroyed before
any further action is performed
:param tkinter.Frame frame: the frame to be destroyed
:return: nothing
"""
self.menubar.bind("<Button-1>", lambda e: frame.destroy())
self.master.bind("<Button-1>", lambda e: frame.destroy())
def unbind_widgets_after_frame_hide(self):
"""
Unbind the widgets to make sure everything works normally again after the menu option frame is destroyed
:return: nothing
"""
self.master.unbind("<Button-1>")
self.menubar.unbind("Button-1>")
def click_selection_tool(self):
logging.debug("Click SELECTION TOOL")
def click_start_stop_session_tool(self):
logging.debug("Click START STOP SESSION button")
self.destroy_children_widgets(self.edit_frame)
self.create_runtime_toolbar()
def click_link_tool(self):
logging.debug("Click LINK button")
def pick_router(self, main_button):
self.network_layer_option_menu.destroy()
main_button.configure(image=Images.get("router"))
logging.debug("Pick router option")
def pick_host(self, main_button):
self.network_layer_option_menu.destroy()
main_button.configure(image=Images.get("host"))
logging.debug("Pick host option")
def pick_pc(self, main_button):
self.network_layer_option_menu.destroy()
main_button.configure(image=Images.get("pc"))
logging.debug("Pick PC option")
def pick_mdr(self, main_button):
self.network_layer_option_menu.destroy()
main_button.configure(image=Images.get("mdr"))
logging.debug("Pick MDR option")
def pick_prouter(self, main_button):
self.network_layer_option_menu.destroy()
main_button.configure(image=Images.get("prouter"))
logging.debug("Pick prouter option")
def pick_ovs(self, main_button):
self.network_layer_option_menu.destroy()
main_button.configure(image=Images.get("ovs"))
logging.debug("Pick OVS option")
def pick_editnode(self, main_button):
self.network_layer_option_menu.destroy()
main_button.configure(image=Images.get("editnode"))
logging.debug("Pick editnode option")
def draw_network_layer_options(self, network_layer_button):
"""
Draw the options for network-layer button
:param tkinter.Radiobutton network_layer_button: network-layer button
:return: nothing
"""
# create a frame and add buttons to it
self.destroy_previous_frame()
option_frame = tk.Frame(self.master, padx=1, pady=1)
img_list = [
Images.get("router"),
Images.get("host"),
Images.get("pc"),
Images.get("mdr"),
Images.get("prouter"),
Images.get("ovs"),
Images.get("editnode"),
]
func_list = [
self.pick_router,
self.pick_host,
self.pick_pc,
self.pick_mdr,
self.pick_prouter,
self.pick_ovs,
self.pick_editnode,
]
for i in range(len(img_list)):
self.create_button(
img_list[i], func_list[i], option_frame, network_layer_button
)
# place frame at a calculated position as well as keep a reference of that frame
self.draw_button_menu_frame(self.edit_frame, option_frame, network_layer_button)
self.network_layer_option_menu = option_frame
# destroy the frame before any further actions on other widgets
self.bind_widgets_before_frame_hide(option_frame)
option_frame.wait_window(option_frame)
self.unbind_widgets_after_frame_hide()
def create_network_layer_button(self):
"""
Create network layer button
:return: nothing
"""
router_image = Images.get("router")
network_layer_button = tk.Radiobutton(
self.edit_frame,
indicatoron=False,
variable=self.radio_value,
value=3,
width=self.width,
height=self.height,
image=router_image,
command=lambda: self.draw_network_layer_options(network_layer_button),
)
network_layer_button.pack(side=tk.TOP, pady=1)
CreateToolTip(network_layer_button, "Network-layer virtual nodes")
def pick_hub(self, main_button):
self.link_layer_option_menu.destroy()
main_button.configure(image=Images.get("hub"))
logging.debug("Pick link-layer node HUB")
def pick_switch(self, main_button):
self.link_layer_option_menu.destroy()
main_button.configure(image=Images.get("switch"))
logging.debug("Pick link-layer node SWITCH")
def pick_wlan(self, main_button):
self.link_layer_option_menu.destroy()
main_button.configure(image=Images.get("wlan"))
logging.debug("Pick link-layer node WLAN")
def pick_rj45(self, main_button):
self.link_layer_option_menu.destroy()
main_button.configure(image=Images.get("rj45"))
logging.debug("Pick link-layer node RJ45")
def pick_tunnel(self, main_button):
self.link_layer_option_menu.destroy()
main_button.configure(image=Images.get("tunnel"))
logging.debug("Pick link-layer node TUNNEL")
def draw_link_layer_options(self, link_layer_button):
"""
Draw the options for link-layer button
:param tkinter.RadioButton link_layer_button: link-layer button
:return: nothing
"""
# create a frame and add buttons to it
self.destroy_previous_frame()
option_frame = tk.Frame(self.master, padx=1, pady=1)
img_list = [
Images.get("hub"),
Images.get("switch"),
Images.get("wlan"),
Images.get("rj45"),
Images.get("tunnel"),
]
func_list = [
self.pick_hub,
self.pick_switch,
self.pick_wlan,
self.pick_rj45,
self.pick_tunnel,
]
for i in range(len(img_list)):
self.create_button(
img_list[i], func_list[i], option_frame, link_layer_button
)
# place frame at a calculated position as well as keep a reference of the frame
self.draw_button_menu_frame(self.edit_frame, option_frame, link_layer_button)
self.link_layer_option_menu = option_frame
# destroy the frame before any further actions on other widgets
self.bind_widgets_before_frame_hide(option_frame)
option_frame.wait_window(option_frame)
self.unbind_widgets_after_frame_hide()
def create_link_layer_button(self):
"""
Create link-layer node button and the options that represent different link-layer node types
:return: nothing
"""
hub_image = Images.get("hub")
link_layer_button = tk.Radiobutton(
self.edit_frame,
indicatoron=False,
variable=self.radio_value,
value=4,
width=self.width,
height=self.height,
image=hub_image,
command=lambda: self.draw_link_layer_options(link_layer_button),
)
link_layer_button.pack(side=tk.TOP, pady=1)
CreateToolTip(link_layer_button, "link-layer nodes")
def pick_marker(self, main_button):
self.marker_option_menu.destroy()
main_button.configure(image=Images.get("marker"))
logging.debug("Pick MARKER")
return "break"
def pick_oval(self, main_button):
self.marker_option_menu.destroy()
main_button.configure(image=Images.get("oval"))
logging.debug("Pick OVAL")
def pick_rectangle(self, main_button):
self.marker_option_menu.destroy()
main_button.configure(image=Images.get("rectangle"))
logging.debug("Pick RECTANGLE")
def pick_text(self, main_button):
self.marker_option_menu.destroy()
main_button.configure(image=Images.get("text"))
logging.debug("Pick TEXT")
def draw_marker_options(self, main_button):
"""
Draw the options for marker button
:param tkinter.Radiobutton main_button: the main button
:return: nothing
"""
# create a frame and add buttons to it
self.destroy_previous_frame()
option_frame = tk.Frame(self.master, padx=1, pady=1)
img_list = [
Images.get("marker"),
Images.get("oval"),
Images.get("rectangle"),
Images.get("text"),
]
func_list = [
self.pick_marker,
self.pick_oval,
self.pick_rectangle,
self.pick_text,
]
for i in range(len(img_list)):
self.create_button(img_list[i], func_list[i], option_frame, main_button)
# place the frame at a calculated position as well as keep a reference of that frame
self.draw_button_menu_frame(self.edit_frame, option_frame, main_button)
self.marker_option_menu = option_frame
# destroy the frame before any further actions on other widgets
self.bind_widgets_before_frame_hide(option_frame)
option_frame.wait_window(option_frame)
self.unbind_widgets_after_frame_hide()
def create_marker_button(self):
"""
Create marker button and options that represent different marker types
:return: nothing
"""
marker_image = Images.get("marker")
marker_main_button = tk.Radiobutton(
self.edit_frame,
indicatoron=False,
variable=self.radio_value,
value=5,
width=self.width,
height=self.height,
image=marker_image,
command=lambda: self.draw_marker_options(marker_main_button),
)
marker_main_button.pack(side=tk.TOP, pady=1)
CreateToolTip(marker_main_button, "background annotation tools")
def create_toolbar(self):
self.load_toolbar_images()
self.create_regular_button(
self.edit_frame, Images.get("start"), self.click_start_stop_session_tool
)
self.create_radio_button(
self.edit_frame,
Images.get("select"),
self.click_selection_tool,
self.radio_value,
1,
"selection tool",
)
self.create_radio_button(
self.edit_frame,
Images.get("link"),
self.click_link_tool,
self.radio_value,
2,
"link tool",
)
self.create_network_layer_button()
self.create_link_layer_button()
self.create_marker_button()
def create_observe_button(self):
menu_button = tk.Menubutton(
self.edit_frame,
image=Images.get("observe"),
width=self.width,
height=self.height,
direction=tk.RIGHT,
relief=tk.RAISED,
)
menu_button.menu = tk.Menu(menu_button, tearoff=0)
menu_button["menu"] = menu_button.menu
menu_button.pack(side=tk.TOP, pady=1)
menu_button.menu.add_command(label="None")
menu_button.menu.add_command(label="processes")
menu_button.menu.add_command(label="ifconfig")
menu_button.menu.add_command(label="IPv4 routes")
menu_button.menu.add_command(label="IPv6 routes")
menu_button.menu.add_command(label="OSPFv2 neighbors")
menu_button.menu.add_command(label="OSPFv3 neighbors")
menu_button.menu.add_command(label="Listening sockets")
menu_button.menu.add_command(label="IPv4 MFC entries")
menu_button.menu.add_command(label="IPv6 MFC entries")
menu_button.menu.add_command(label="firewall rules")
menu_button.menu.add_command(label="IPSec policies")
menu_button.menu.add_command(label="docker logs")
menu_button.menu.add_command(label="OSPFv3 MDR level")
menu_button.menu.add_command(label="PIM neighbors")
menu_button.menu.add_command(label="Edit...")
def click_stop_button(self):
logging.debug("Click on STOP button ")
self.destroy_children_widgets(self.edit_frame)
self.create_toolbar()
def click_run_button(self):
logging.debug("Click on RUN button")
def click_plot_button(self):
logging.debug("Click on plot button")
def click_marker_button(self):
logging.debug("Click on marker button")
def click_two_node_button(self):
logging.debug("Click TWONODE button")
def create_runtime_toolbar(self):
self.create_regular_button(
self.edit_frame, Images.get("stop"), self.click_stop_button
)
self.create_radio_button(
self.edit_frame,
Images.get("select"),
self.click_selection_tool,
self.exec_radio_value,
1,
"selection tool",
)
self.create_observe_button()
self.create_radio_button(
self.edit_frame,
Images.get("plot"),
self.click_plot_button,
self.exec_radio_value,
2,
"plot",
)
self.create_radio_button(
self.edit_frame,
Images.get("marker"),
self.click_marker_button,
self.exec_radio_value,
3,
"marker",
)
self.create_radio_button(
self.edit_frame,
Images.get("twonode"),
self.click_two_node_button,
self.exec_radio_value,
4,
"run command from one node to another",
)
self.create_regular_button(
self.edit_frame, Images.get("run"), self.click_run_button
)

Binary file not shown.

After

Width:  |  Height:  |  Size: 635 B

BIN
coretk/coretk/host.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

BIN
coretk/coretk/hub.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 719 B

BIN
coretk/coretk/lanswitch.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 744 B

BIN
coretk/coretk/link.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 86 B

BIN
coretk/coretk/marker.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 375 B

BIN
coretk/coretk/mdr.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

BIN
coretk/coretk/observe.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

BIN
coretk/coretk/oval.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 174 B

BIN
coretk/coretk/pc.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

BIN
coretk/coretk/plot.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 265 B

BIN
coretk/coretk/rectangle.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 160 B

BIN
coretk/coretk/rj45.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 755 B

BIN
coretk/coretk/router.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 753 B

BIN
coretk/coretk/run.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 324 B

BIN
coretk/coretk/select.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 925 B

BIN
coretk/coretk/start.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

BIN
coretk/coretk/stop.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

BIN
coretk/coretk/text.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 127 B

View file

@ -0,0 +1,17 @@
"""
Python file that store button actions
"""
import logging
def click_selection_tool():
logging.debug("Click SELECTION TOOL")
def click_start_stop_session_tool():
logging.debug("Click START STOP SELECTION TOOL")
def click_link_tool():
logging.debug("Click LINK TOOL")

38
coretk/coretk/tooltip.py Normal file
View file

@ -0,0 +1,38 @@
import tkinter as tk
class CreateToolTip(object):
"""
Create tool tip for a given widget
"""
def __init__(self, widget, text="widget info"):
self.widget = widget
self.text = text
self.widget.bind("<Enter>", self.enter)
self.widget.bind("<Leave>", self.close)
self.tw = None
def enter(self, event=None):
x = 0
y = 0
x, y, cx, cy = self.widget.bbox("insert")
x += self.widget.winfo_rootx()
y += self.widget.winfo_rooty() + 32
self.tw = tk.Toplevel(self.widget)
self.tw.wm_overrideredirect(True)
self.tw.wm_geometry("+%d+%d" % (x, y))
label = tk.Label(
self.tw,
text=self.text,
justify=tk.LEFT,
background="#ffffe6",
relief="solid",
borderwidth=1,
)
label.pack(ipadx=1)
def close(self, event=None):
if self.tw:
self.tw.destroy()

BIN
coretk/coretk/tunnel.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 799 B

BIN
coretk/coretk/twonode.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 220 B

BIN
coretk/coretk/wlan.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 146 B