Skip to content

Commit 2328ffc

Browse files
authored
Merge pull request #53 from cisco-open/Ver2.5.1
Ver2.5.1
2 parents 4099be9 + 7940e41 commit 2328ffc

File tree

4 files changed

+232
-13
lines changed

4 files changed

+232
-13
lines changed

network_sketcher.py

Lines changed: 47 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
import tkinter as tk ,tkinter.ttk as ttk,tkinter.filedialog, tkinter.messagebox
2020
from tkinterdnd2 import *
2121
import sys, os, subprocess ,webbrowser ,openpyxl
22-
import ns_def,network_sketcher_dev,ns_sync_between_layers,ns_attribute_table_sync_master
22+
import ns_def,network_sketcher_dev,ns_sync_between_layers,ns_attribute_table_sync_master, network_sketcher_cli
2323
import ns_extensions
2424
import ns_vpn_diagram_create
2525

@@ -42,8 +42,10 @@ def __init__(self):
4242
self.click_value_3rd = ''
4343
self.click_value_VPN = ''
4444
self.root = TkinterDnD.Tk()
45-
self.root.title("Network Sketcher ver 2.5.0")
45+
self.root.title("Network Sketcher ver 2.5.1")
4646
self.root.geometry("510x200+100+100")
47+
icon = tk.PhotoImage(file='ns_logo.png')
48+
self.root.iconphoto(True, icon)
4749

4850
# Notebook
4951
nb = ttk.Notebook()
@@ -90,7 +92,7 @@ def __init__(self):
9092
#Help_1_label_1.grid(row=0, column=0, sticky='W', padx=5, pady=2)
9193

9294
Help_1 = tk.LabelFrame(tab_x2, text=" Online User Guide ", font=("", 14), height=1, background="#FFFFFF")
93-
Help_1.grid(row=1, column=0, columnspan=3, sticky='W', padx=5, pady=5, ipadx=10, ipady=5)
95+
Help_1.grid(row=0, column=0, sticky='W', padx=5, pady=5, ipadx=10, ipady=5)
9496

9597
Help_1_button_2 = tk.Button(Help_1, text="English", font=("", 14), command=lambda: self.click_action_main1_1('self.help_1_button_2'))
9698
Help_1_button_2.grid(row=1, column=1, sticky='W', padx=20, pady=2 , ipadx=15,ipady=0)
@@ -713,20 +715,51 @@ def sub_master_extention_2(self): # Report Button
713715
self.sub3_5.title('Report')
714716
self.root.update_idletasks()
715717
#print(self.root.winfo_width(),self.root.winfo_height(),self.root.winfo_x(),self.root.winfo_y() ) # width, height , x , y
716-
geo = str(self.root.winfo_width() - 230) + 'x' + str(self.root.winfo_height() - 60) + '+' + str(self.root.winfo_x() + self.root.winfo_width() +150) + '+' + str(self.root.winfo_y() + 50 )
718+
geo = str(self.root.winfo_width() - 260) + 'x' + str(self.root.winfo_height() + 60) + '+' + str(self.root.winfo_x() + self.root.winfo_width() +150) + '+' + str(self.root.winfo_y() + 50 )
717719
self.sub3_5.geometry(geo)
718720

719721
self.sub3_5_0 = tk.Label(self.sub3_5, text=local_filename, font=("", 12), background="#FFFFFF")
720-
self.sub3_5_0 .grid(row=0, column=0, columnspan=7, sticky='W', padx=5, pady=5, ipadx=30, ipady=15)
722+
self.sub3_5_0 .grid(row=0, column=0, columnspan=7, sticky='W', padx=5, pady=5, ipadx=30, ipady=5)
721723

722-
# IP Address report
723-
self.sub3_5_1 = tk.LabelFrame(self.sub3_5, text='Export', font=("", 14), height=1, background="#C2E2EC")
724+
# Report frame
725+
self.sub3_5_1 = tk.LabelFrame(self.sub3_5, text='Report', font=("", 14), height=1, background="#C2E2EC")
724726
self.sub3_5_1.grid(row=1, column=0, columnspan=5, sticky='W', padx=5, pady=0, ipadx=3, ipady=0)
725727

726-
# Export to the IP Address table
727-
self.sub3_5_button_1 = tk.Button(self.sub3_5_1, text=" IP Address table ", font=("", 12), command=lambda: self.click_action_sub('self.sub3_5_button_1','dummy'))
728+
# Report to the IP Address table
729+
self.sub3_5_2 = tk.LabelFrame(self.sub3_5_1, text='IP Address', font=("", 14), height=1, background="#E8F4F8")
730+
self.sub3_5_2.grid(row=1, column=0, columnspan=5, sticky='W', padx=5, pady=0, ipadx=3, ipady=0)
731+
732+
self.sub3_5_button_1 = tk.Button(self.sub3_5_2, text=" IP Address table ", font=("", 12), command=lambda: self.click_action_sub('self.sub3_5_button_1','dummy'))
728733
self.sub3_5_button_1.grid(row=6, column=0, sticky='W', padx=20, pady=5)
729734

735+
# Report to the IP Address table , add at ver 2.5.1
736+
self.sub3_5_4 = tk.LabelFrame(self.sub3_5_1, text='Flow', font=("", 14), height=1, background="#E8F4F8")
737+
self.sub3_5_4.grid(row=2, column=0, columnspan=5, sticky='W', padx=5, pady=4, ipadx=3, ipady=0)
738+
739+
argv_array = ['show', 'l3_interface']
740+
full_filepath_master = self.inFileTxt_L2_3_1.get()
741+
self.show_l3_interface = network_sketcher_cli.ns_cli_run.cli_show(self, full_filepath_master, argv_array)
742+
743+
unique_devices = set()
744+
for item in self.show_l3_interface:
745+
device_name = item[0]
746+
unique_devices.add(device_name)
747+
748+
show_device_list = sorted(unique_devices, reverse=False)
749+
750+
optionFLOW_1_1 = show_device_list
751+
global variableFLOW_1_1
752+
variableFLOW_1_1 = tk.StringVar()
753+
self.comboFLOW_1_1 = ttk.Combobox(self.sub3_5_4, values=optionFLOW_1_1, textvariable=variableFLOW_1_1, font=("", 12), state='readonly',width=10)
754+
self.comboFLOW_1_1.set(str(optionFLOW_1_1[0]))
755+
self.comboFLOW_1_1.option_add("*TCombobox*Listbox.Font", ("", 12))
756+
self.comboFLOW_1_1.grid(row=0, column=0, sticky='N', padx=10, pady=10, ipady=0, ipadx=35)
757+
self.comboFLOW_1_1.bind("<<ComboboxSelected>>", self.on_combobox_select)
758+
759+
self.sub3_5_button_6 = tk.Button(self.sub3_5_4, text=" Device Flow table ", font=("", 12), command=lambda: self.click_action_sub('self.sub3_5_button_6','dummy'))
760+
self.sub3_5_button_6.grid(row=1, column=0, sticky='W', padx=10, ipadx=10, pady=1)
761+
762+
730763
def sub_master_extention_3(self): # Append flow Button
731764
local_filename = self.filename
732765
local_fullpath = self.full_filepath
@@ -818,6 +851,11 @@ def drop_sub3_7(self, event):
818851
self.sub3_7_label_4.grid(row=2, column=1, columnspan=3, sticky='W', padx=5, pady=20)
819852

820853
def click_action_sub(self, click_value, target_area_name):
854+
if click_value == 'self.sub3_5_button_6': # select device flow table
855+
#print ('--- device flow table ---',variableFLOW_1_1.get())
856+
ns_extensions.flow_report.create_device_flow_table(self, self.inFileTxt_L2_3_1.get(), variableFLOW_1_1.get())
857+
ns_def.messagebox_file_open(str(self.outFileTxt_11_3.get()))
858+
821859
if click_value == 'self.sub3_7_button_3': # select Submit
822860
ns_extensions.flow.append_flows_to_diagram(self,variable3_7_y_1,variable3_7_y_2,variable3_7_y_3)
823861

ns_egt_maker.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,9 @@ def create_excel_gui_tree(input_excel_name,output_excel_name,NEW_OR_ADD,egt_make
296296
output_tree_excel = openpyxl.load_workbook(output_excel_name)
297297
number_of_sheets += 1
298298

299+
elif NEW_OR_ADD == 'ADD_OPTION1': # add at ver 2.5.1 for add device table sheets
300+
output_tree_excel = openpyxl.load_workbook(output_excel_name)
301+
299302
elif NEW_OR_ADD == 'PARA':
300303
number_of_add_modify_rows = -1
301304
output_tree_excel = openpyxl.load_workbook(output_excel_name)

ns_extensions.py

Lines changed: 182 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,185 @@
2424
import numpy as np
2525
import networkx as nx
2626

27-
class flow():
27+
class flow_report():
28+
def create_device_flow_table(self,full_filepath_master,device_name):
29+
print('--- create_device_flow_table ---',full_filepath_master,device_name)
30+
## check Flow_Data sheet exists in Master file
31+
input_excel_master = openpyxl.load_workbook(full_filepath_master)
32+
ws_list_master = input_excel_master.sheetnames
33+
input_excel_master.close()
34+
35+
ws_flow_name = 'Flow_Data'
36+
if ws_flow_name in ws_list_master:
37+
master_flow_array = ns_def.convert_excel_to_array(ws_flow_name, full_filepath_master, 3)
38+
master_flow_array = master_flow_array[:-1]
39+
#print(master_flow_array)
40+
target_flow_array = []
41+
for tmp_master_flow_array in master_flow_array:
42+
tmp_routing_path = ''
43+
if tmp_master_flow_array[1][6] != '':
44+
tmp_routing_path = tmp_master_flow_array[1][6]
45+
elif tmp_master_flow_array[1][6] == '' and tmp_master_flow_array[1][6] != ' ':
46+
tmp_routing_path = tmp_master_flow_array[1][7]
47+
48+
if tmp_master_flow_array[1][1] == device_name or tmp_master_flow_array[1][2] == device_name or device_name in tmp_routing_path:
49+
target_flow_array.append([tmp_master_flow_array[1][0],tmp_master_flow_array[1][1],tmp_master_flow_array[1][2],tmp_master_flow_array[1][3],tmp_master_flow_array[1][4],tmp_master_flow_array[1][5],tmp_routing_path])
50+
#print(target_flow_array)
51+
52+
53+
'''
54+
export flow report
55+
'''
56+
excel_maseter_file = full_filepath_master
57+
iDir = os.path.abspath(os.path.dirname(excel_maseter_file))
58+
59+
basename_without_ext = os.path.splitext(os.path.basename(excel_maseter_file))[0]
60+
self.outFileTxt_11_3.delete(0, tkinter.END)
61+
self.outFileTxt_11_3.insert(tk.END, iDir + ns_def.return_os_slash() + '[FLOW_REPORT]' + basename_without_ext.replace('[MASTER]', '') + '.xlsx')
62+
63+
## check file open
64+
ns_def.check_file_open(self.outFileTxt_11_3.get())
65+
66+
# flag exist flow file
67+
flag_flow_table_exist = False
68+
if os.path.isfile(self.outFileTxt_11_3.get()) == True:
69+
#os.remove(self.outFileTxt_11_3.get())
70+
flag_flow_table_exist = True
71+
72+
self.excel_flow_file = self.outFileTxt_11_3.get()
73+
74+
## check Flow_Data sheet exists in Master file
75+
input_excel_master = openpyxl.load_workbook(excel_maseter_file)
76+
ws_list_master = input_excel_master.sheetnames
77+
input_excel_master.close()
78+
79+
'''
80+
MAKE Flows Table List
81+
'''
82+
master_device_table_tuple = {}
83+
flow_list_array = []
84+
egt_maker_width_array = ['5','25', '25','25', '25','15', '20', '25', '40'] # for Network Sketcher Ver 2.0
85+
flow_list_array.append([1, ['<RANGE>', '1','1', '1', '1', '1', '1', '1', '1', '1', '<END>']])
86+
flow_list_array.append([2, ['<HEADER>', 'No','Source Device Name', 'Destination Device Name','Source IP Address', 'Destination IP Address','TCP/UDP/ICMP','Service name(Port)', 'Max. bandwidth(Mbps)', 'Routing path settings', '<END>']])
87+
current_row_num = 3
88+
89+
'''add flow table list'''
90+
#print(self.show_l3_interface)
91+
# Initialize a dictionary to hold devices and their IP addresses
92+
device_ips = {}
93+
94+
# Iterate through the list of interfaces
95+
for tmp_show_l3_interface in self.show_l3_interface:
96+
tmp_device_name = tmp_show_l3_interface[0]
97+
tmp_ip_address = tmp_show_l3_interface[3]
98+
99+
# Add the IP address to the corresponding device in the dictionary
100+
if tmp_device_name not in device_ips:
101+
device_ips[tmp_device_name] = []
102+
device_ips[tmp_device_name].append(tmp_ip_address)
103+
104+
for tmp_target_flow_array in target_flow_array:
105+
tmp_target_flow_array = list(map(str, tmp_target_flow_array))
106+
tmp_target_flow_array.insert(0, '')
107+
tmp_target_flow_array.append('<END>')
108+
source_ip_array = device_ips[tmp_target_flow_array[2]]
109+
destination_ip_array = device_ips[tmp_target_flow_array[3]]
110+
str_source_ip = ', '.join(map(str, source_ip_array ))
111+
str_destination_ip = ', '.join(map(str, destination_ip_array))
112+
tmp_target_flow_array.insert(4, str_source_ip)
113+
tmp_target_flow_array.insert(5, str_destination_ip)
114+
flow_list_array.append([current_row_num,tmp_target_flow_array])
115+
current_row_num += 1
116+
117+
#add last <EMD>
118+
flow_list_array.append([current_row_num, ['<END>']])
119+
#print(flow_list_array)
120+
121+
#print(flow_list_array)
122+
### Convert to tuple
123+
master_device_table_tuple = ns_def.convert_array_to_tuple(flow_list_array)
124+
125+
'''
126+
Create temp input data file
127+
'''
128+
# List of characters not allowed in Excel worksheet names
129+
forbidden_chars = [':', '\\', '/', '?', '*', '[', ']']
130+
# Remove forbidden characters using a list comprehension
131+
cleaned_device_name = ''.join(char for char in device_name if char not in forbidden_chars)
132+
133+
134+
### Create the flow table excel file or add sheet
135+
self.worksheet_name = cleaned_device_name
136+
if flag_flow_table_exist == False:
137+
wb = openpyxl.Workbook()
138+
sheet = wb.active
139+
sheet.title = self.worksheet_name
140+
wb.save(self.excel_flow_file)
141+
else:
142+
wb = openpyxl.load_workbook(self.excel_flow_file)
143+
if self.worksheet_name in wb.sheetnames:
144+
# Remove the existing worksheet
145+
sheet_to_remove = wb[self.worksheet_name]
146+
wb.remove(sheet_to_remove)
147+
148+
wb.create_sheet(title=self.worksheet_name)
149+
wb.save(self.excel_flow_file)
150+
151+
'''
152+
Create [FLOW_REPORT] file
153+
'''
154+
tmp_master_data_array = []
155+
tmp_master_data_array.append([1, [self.worksheet_name]])
156+
#print(tmp_master_data_array)
157+
158+
template_master_data_tuple = {}
159+
template_master_data_tuple = ns_def.convert_array_to_tuple(tmp_master_data_array)
160+
161+
#print('Create --- template_master_data_tuple---')
162+
#print(template_master_data_tuple)
163+
offset_row = 0
164+
offset_column = 0
165+
write_to_section = '_template_'
166+
ns_def.write_excel_meta(template_master_data_tuple, self.excel_flow_file, self.worksheet_name, write_to_section, offset_row, offset_column)
167+
168+
###
169+
input_excel_name = self.excel_flow_file
170+
output_excel_name = self.outFileTxt_11_3.get()
171+
if flag_flow_table_exist == False:
172+
NEW_OR_ADD = 'NEW'
173+
else:
174+
NEW_OR_ADD = 'ADD_OPTION1'
175+
ns_egt_maker.create_excel_gui_tree(input_excel_name,output_excel_name,NEW_OR_ADD, egt_maker_width_array)
176+
177+
'''
178+
Add FLOW_List table from meta
179+
'''
180+
# Write normal tuple to excel
181+
tmp_ws_name = '_tmp_'
182+
master_excel_meta = master_device_table_tuple
183+
ppt_meta_file = output_excel_name
184+
excel_file_path = ppt_meta_file
185+
worksheet_name = tmp_ws_name
186+
section_write_to = '<<N/A>>'
187+
offset_row = 0
188+
offset_column = 0
189+
ns_def.create_excel_sheet(ppt_meta_file, tmp_ws_name)
190+
ns_def.write_excel_meta(master_excel_meta, excel_file_path, worksheet_name, section_write_to, offset_row, offset_column)
191+
192+
#print(output_excel_name)
193+
self.input_tree_excel = openpyxl.load_workbook(output_excel_name)
194+
worksheet_name = cleaned_device_name
195+
start_row = 1
196+
start_column = 0
197+
custom_table_name = ppt_meta_file
198+
self.input_tree_excel = ns_egt_maker.insert_custom_excel_table(self.input_tree_excel, worksheet_name, start_row, start_column, custom_table_name)
199+
self.input_tree_excel.save(output_excel_name)
200+
201+
# Remove _tmp_ sheet from excel master self.worksheet_name
202+
ns_def.remove_excel_sheet(ppt_meta_file, tmp_ws_name)
203+
204+
205+
class flow():
28206
def add_routing_path_to_flow(self,full_filepath_master,flow_list_array):
29207
print('--- Routing path calculation ---')
30208
argv_array = ['show', 'l3_broadcast_domain']
@@ -434,13 +612,13 @@ def export_ip_report(self,dummy):
434612
# SET IP Address report file patch
435613
basename_without_ext = os.path.splitext(os.path.basename(excel_maseter_file))[0]
436614
self.outFileTxt_11_3.delete(0, tkinter.END)
437-
self.outFileTxt_11_3.insert(tk.END, iDir + ns_def.return_os_slash() + '[IP_TABLE]' + basename_without_ext.replace('[MASTER]', '') + '.xlsx')
438-
self.excel_file_path = iDir + ns_def.return_os_slash() + '_template_[IP_TABLE]' + basename_without_ext.replace('[MASTER]', '') + '.xlsx'
615+
self.outFileTxt_11_3.insert(tk.END, iDir + ns_def.return_os_slash() + '[IP_REPORT]' + basename_without_ext.replace('[MASTER]', '') + '.xlsx') #change IP_TABLE to IP_REPORT at ver 2.5.1
616+
self.excel_file_path = iDir + ns_def.return_os_slash() + '_template_[IP_REPORT]' + basename_without_ext.replace('[MASTER]', '') + '.xlsx' #change IP_TABLE to IP_REPORT at ver 2.5.1
439617

440618
## check file open
441619
ns_def.check_file_open(self.outFileTxt_11_3.get())
442620

443-
# remove exist device file
621+
# remove exist ip table file
444622
if os.path.isfile(self.outFileTxt_11_3.get()) == True:
445623
os.remove(self.outFileTxt_11_3.get())
446624

ns_logo.png

51.4 KB
Loading

0 commit comments

Comments
 (0)