Skip to content

Commit e4f5cd2

Browse files
authored
Add files via upload
1 parent 9033e67 commit e4f5cd2

File tree

4 files changed

+85
-38
lines changed

4 files changed

+85
-38
lines changed

network_sketcher.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ 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.4.3")
45+
self.root.title("Network Sketcher ver 2.5.0")
4646
self.root.geometry("510x200+100+100")
4747

4848
# Notebook
@@ -98,9 +98,12 @@ def __init__(self):
9898
Help_1_button_1 = tk.Button(Help_1, text="Japanese", font=("", 14), command=lambda: self.click_action_main1_1('self.help_1_button_1'))
9999
Help_1_button_1.grid(row=1, column=2, sticky='W', padx=20, pady=2 , ipadx=5 ,ipady=0)
100100

101-
Help_1_1 = tk.Label(tab_x2, font=("", 10), text="Copyright 2023 Cisco Systems, Inc. and its affiliates \n SPDX-License-Identifier: Apache-2.0", background='#FFFFFF')
101+
Help_1_1 = tk.Label(tab_x2, font=("", 10), text="Author: Yusuke Ogawa - Security Architect, Cisco | CCIE#17583", background='#FFFFFF')
102102
Help_1_1.grid(column=0, row=3)
103103

104+
Help_1_1 = tk.Label(tab_x2, font=("", 10), text="Copyright 2023 Cisco Systems, Inc. and its affiliates \n SPDX-License-Identifier: Apache-2.0", background='#FFFFFF')
105+
Help_1_1.grid(column=0, row=4, pady=2)
106+
104107
# main loop
105108
self.root.mainloop()
106109

@@ -1013,7 +1016,8 @@ def click_action_sub3_1(self, click_value,push_array):
10131016
#print(flow_list_array)
10141017

10151018
#caluculate routing path
1016-
# TBD
1019+
flow_list_array = ns_extensions.flow.add_routing_path_to_flow(self,full_filepath_master,flow_list_array)
1020+
#print(flow_list_array)
10171021

10181022
#add last end mark
10191023
last_number = flow_list_array[-1][0]

network_sketcher_cli.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,7 @@ def get_next_arg(argv_array, target):
341341
return argv_array[index + 1]
342342
except (ValueError, IndexError):
343343
return None
344+
344345
def get_next_next_arg(argv_array, target):
345346
try:
346347
index = argv_array.index(target)

ns_ddx_figure.py

Lines changed: 14 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2827,9 +2827,9 @@ def add_shape(self,shape_type,shape_left, shape_top, shape_width, shape_hight,sh
28272827

28282828
elif shape_type == 'L3_SEGMENT_VPN':
28292829
#fill paramter
2830-
shape_fill.fore_color.rgb = RGBColor(251, 243, 243)
2830+
shape_fill.fore_color.rgb = RGBColor(248, 243, 251)
28312831
# line paramter
2832-
shape_line.color.rgb = RGBColor(192, 0, 0)
2832+
shape_line.color.rgb = RGBColor(112, 48, 160)
28332833
shape_line.width = Pt(0.75)
28342834
self.shape.adjustments[0] = float(0.30045) # curve of ROUNDED_RECTANGLE 0.0~1.0
28352835
# text parameter
@@ -3020,7 +3020,7 @@ def add_line(self,line_type,inche_from_connect_x,inche_from_connect_y,inche_to_c
30203020
"""))
30213021

30223022
if line_type == 'L3_SEGMENT-VPN':
3023-
shape_line.color.rgb = RGBColor(192, 0, 0)
3023+
shape_line.color.rgb = RGBColor(112, 48, 160)
30243024
line_elem = self.shape.line._get_or_add_ln()
30253025
shape_line.width = Pt(0.7)
30263026
line_elem.append(parse_xml("""
@@ -3034,7 +3034,7 @@ def add_line(self,line_type,inche_from_connect_x,inche_from_connect_y,inche_to_c
30343034
if line_type == 'VPN':
30353035
self.shape.shadow.inherit = True
30363036
shape_line.color.brightness = 0.3
3037-
shape_line.color.rgb = RGBColor(255, 0, 0)
3037+
shape_line.color.rgb = RGBColor(112, 48, 160)
30383038
shape_line.width = Pt(4.0)
30393039
line_elem = self.shape.line._get_or_add_ln()
30403040
line_elem.append(parse_xml("""
@@ -3047,18 +3047,18 @@ def add_line(self,line_type,inche_from_connect_x,inche_from_connect_y,inche_to_c
30473047
if line_type == 'VPN_curve':
30483048
self.shape.shadow.inherit = True
30493049
shape_line.color.brightness = 0.3
3050-
shape_line.color.rgb = RGBColor(255, 0, 0)
3050+
shape_line.color.rgb = RGBColor(112, 48, 160)
30513051
shape_line.width = Pt(4.0)
30523052
#shape_line.dash_style = MSO_LINE.SQUARE_DOT
30533053
line_elem = self.shape.line._get_or_add_ln()
30543054
line_elem.append(parse_xml("""
30553055
<a:headEnd type="diamond" xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main"/>
30563056
"""))
30573057

3058-
if line_type == 'FLOW0':
3058+
if line_type == 'FLOW0': #direct arrow
30593059
self.shape.shadow.inherit = True
30603060
shape_line.color.brightness = 0.3
3061-
shape_line.color.rgb = RGBColor(0, 112, 192)
3061+
shape_line.color.rgb = RGBColor(255, 0, 0)
30623062
shape_line.width = Pt(4.0)
30633063
line_elem = self.shape.line._get_or_add_ln()
30643064
line_elem.append(parse_xml("""
@@ -3068,44 +3068,33 @@ def add_line(self,line_type,inche_from_connect_x,inche_from_connect_y,inche_to_c
30683068
<a:tailEnd type="arrow" xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main"/>
30693069
"""))
30703070

3071-
if line_type == 'FLOW1':
3071+
if line_type == 'FLOW1': #start arrow
30723072
self.shape.shadow.inherit = True
30733073
shape_line.color.brightness = 0.3
3074-
shape_line.color.rgb = RGBColor(0, 112, 192)
3074+
shape_line.color.rgb = RGBColor(255, 0, 0)
30753075
shape_line.width = Pt(4.0)
30763076
line_elem = self.shape.line._get_or_add_ln()
30773077
line_elem.append(parse_xml("""
30783078
<a:headEnd type="oval" xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main"/>
30793079
"""))
3080-
'''line_elem.append(parse_xml("""
3081-
<a:tailEnd type="arrow" xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main"/>
3082-
"""))'''
30833080

3084-
if line_type == 'FLOW2':
3081+
if line_type == 'FLOW2': #end arrow
30853082
self.shape.shadow.inherit = True
30863083
shape_line.color.brightness = 0.3
3087-
shape_line.color.rgb = RGBColor(0, 112, 192)
3084+
shape_line.color.rgb = RGBColor(255, 0, 0)
30883085
shape_line.width = Pt(4.0)
30893086
line_elem = self.shape.line._get_or_add_ln()
3090-
'''line_elem.append(parse_xml("""
3091-
<a:headEnd type="oval" xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main"/>
3092-
"""))'''
30933087
line_elem.append(parse_xml("""
30943088
<a:tailEnd type="arrow" xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main"/>
30953089
"""))
30963090

3097-
if line_type == 'FLOW3':
3091+
if line_type == 'FLOW3': #connect arrow
30983092
self.shape.shadow.inherit = True
30993093
shape_line.color.brightness = 0.3
3100-
shape_line.color.rgb = RGBColor(0, 112, 192)
3094+
shape_line.color.rgb = RGBColor(255, 0, 0)
31013095
shape_line.width = Pt(4.0)
31023096
line_elem = self.shape.line._get_or_add_ln()
3103-
'''line_elem.append(parse_xml("""
3104-
<a:headEnd type="oval" xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main"/>
3105-
"""))
3106-
line_elem.append(parse_xml("""
3107-
<a:tailEnd type="arrow" xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main"/>
3108-
"""))'''
3097+
31093098

31103099

31113100
def l2_device_materials(self,action_type,input_device_name,write_left_top_array,wp_list_array):

ns_extensions.py

Lines changed: 63 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,67 @@
1717
'''
1818
from idlelib.debugobj_r import remote_object_tree_item
1919

20-
import ns_def, ns_egt_maker, ns_ddx_figure
20+
import ns_def, ns_egt_maker, ns_ddx_figure, network_sketcher_cli
2121
from collections import Counter
2222
import tkinter as tk ,tkinter.ttk , openpyxl
2323
import ipaddress, sys, os, re, shutil
2424
import numpy as np
25+
import networkx as nx
2526

2627
class flow():
28+
def add_routing_path_to_flow(self,full_filepath_master,flow_list_array):
29+
print('--- Routing path calculation ---')
30+
argv_array = ['show', 'l3_broadcast_domain']
31+
l3_broadcast_array = network_sketcher_cli.ns_cli_run.cli_show(self, full_filepath_master, argv_array)
32+
#print(l3_broadcast_array)
33+
34+
G = nx.Graph()
35+
# Add nodes and edges to the graph
36+
for domain_info in l3_broadcast_array:
37+
broadcast_domain, device_interfaces = domain_info
38+
devices = [dev[0] for dev in device_interfaces]
39+
40+
# Connect all devices in the broadcast domain (full graph)
41+
for i in range(len(devices)):
42+
for j in range(i + 1, len(devices)):
43+
G.add_edge(devices[i], devices[j])
44+
45+
for row in flow_list_array[2:]:
46+
data = row[1]
47+
source = data[1]
48+
target = data[2]
49+
50+
path = flow.get_shortest_path(G, source, target)
51+
#print(path)
52+
if 'is not in G' in path:
53+
continue
54+
55+
if len(path) >= 2:
56+
path = path[1:-1]
57+
path2 = ', '.join([f"'{p}'" for p in path])
58+
if path2 == '':
59+
path2 = ' '
60+
61+
data[7] = path2
62+
63+
#print(flow_list_array)
64+
return (flow_list_array)
65+
66+
def get_shortest_path(G,source, target):
67+
try:
68+
path = nx.shortest_path(G, source=source, target=target)
69+
#print(source,target,path, G)
70+
return path
71+
except nx.NetworkXNoPath:
72+
return f"The Path from {source} to {target} could not be found."
73+
except nx.NodeNotFound as e:
74+
return str(e)
75+
2776
def append_flows_to_diagram(self,variable3_7_y_1,variable3_7_y_2,variable3_7_y_3): #add at ver 2.4.3
2877
print('--- append_flows_to_diagram ---')
29-
print(variable3_7_y_1.get(), variable3_7_y_2.get(), variable3_7_y_3.get())
30-
print(self.pptx_full_filepath)
31-
print(self.full_filepath)
78+
#print(variable3_7_y_1.get(), variable3_7_y_2.get(), variable3_7_y_3.get())
79+
#print(self.pptx_full_filepath)
80+
#print(self.full_filepath)
3281

3382
ws_flow_name = 'Flow_Data'
3483
excel_maseter_file = self.full_filepath
@@ -56,7 +105,7 @@ def append_flows_to_diagram(self,variable3_7_y_1,variable3_7_y_2,variable3_7_y_3
56105
(element[4] == variable3_7_y_3.get() or variable3_7_y_3.get() == 'Any'):
57106
filtered_target_flow.append(element)
58107

59-
print(filtered_target_flow)
108+
#print(filtered_target_flow)
60109

61110
'''read the pptx file and shapes data'''
62111
self.shape_name_grid_array = []
@@ -75,7 +124,7 @@ def append_flows_to_diagram(self,variable3_7_y_1,variable3_7_y_2,variable3_7_y_3
75124
except IndexError:
76125
pass
77126

78-
print(self.shape_name_grid_array)
127+
#print(self.shape_name_grid_array)
79128

80129
''' deside routes and write flows '''
81130
if os.path.isfile(self.pptx_full_filepath) == True:
@@ -117,7 +166,7 @@ def append_flows_to_diagram(self,variable3_7_y_1,variable3_7_y_2,variable3_7_y_3
117166
if source_grid == None or destination_grid == None:
118167
continue
119168

120-
print(source_grid, destination_grid)
169+
#print(source_grid, destination_grid)
121170

122171
line_type = 'FLOW0'
123172
inche_from_connect_x = (source_grid[1] + source_grid[3] * 0.25) / 914400
@@ -127,10 +176,10 @@ def append_flows_to_diagram(self,variable3_7_y_1,variable3_7_y_2,variable3_7_y_3
127176
ns_ddx_figure.extended.add_line(self,line_type,inche_from_connect_x,inche_from_connect_y,inche_to_connect_x,inche_to_connect_y)
128177

129178
elif len(selected_route_path) >= 3:
130-
print(selected_route_path)
179+
#print(selected_route_path)
131180
for i in range(len(selected_route_path) - 1):
132181
pair = [selected_route_path[i], selected_route_path[i + 1]]
133-
print(pair,i,len(selected_route_path) - 2 )
182+
#print(pair,i,len(selected_route_path) - 2 )
134183

135184
# get source grid value
136185
source_grid = next(
@@ -173,6 +222,9 @@ def append_flows_to_diagram(self,variable3_7_y_1,variable3_7_y_2,variable3_7_y_3
173222
modified_filepath = os.path.join(folder, f"Added_flows_{filename}")
174223
self.active_ppt.save(modified_filepath)
175224

225+
#file open
226+
ns_def.messagebox_file_open(modified_filepath)
227+
176228
def get_flow_item_list(self): # add at ver 2.4.3
177229
#print('--- get_flow_item_list ---')
178230
excel_maseter_file = self.inFileTxt_L2_3_1.get()
@@ -260,8 +312,9 @@ def export_flow_file(self,dummy):
260312
for i in range(1, 8):
261313
if tmp_master_flow_array[1][i] == '':
262314
tmp_master_flow_array[1][i] = '<EMPTY>'
315+
print(tmp_master_flow_array[1][7])
263316

264-
flow_list_array.append([current_row_num, ['',str(current_row_num - 2), '>>' + str(tmp_master_flow_array[1][1]), '>>' + str(tmp_master_flow_array[1][2]), '>>' + str(tmp_master_flow_array[1][3]), '>>' + str(tmp_master_flow_array[1][4]), '>>' + str(tmp_master_flow_array[1][5]), '>>' + str(tmp_master_flow_array[1][6]),' ', '<END>']])
317+
flow_list_array.append([current_row_num, ['',str(current_row_num - 2), '>>' + str(tmp_master_flow_array[1][1]), '>>' + str(tmp_master_flow_array[1][2]), '>>' + str(tmp_master_flow_array[1][3]), '>>' + str(tmp_master_flow_array[1][4]), '>>' + str(tmp_master_flow_array[1][5]), '>>' + str(tmp_master_flow_array[1][6]),str(tmp_master_flow_array[1][7]), '<END>']])
265318
current_row_num += 1
266319

267320
if flag_master_has_flow_sheet == True and all_empty == True:

0 commit comments

Comments
 (0)