From 86d9a337165f13c37d07c3fbbf7f4f2a3b803076 Mon Sep 17 00:00:00 2001 From: bettleChen <2207153529@qq.com> Date: Mon, 24 Jul 2023 15:10:11 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/dataSources.xml | 12 ++++++ NetworkAnalog/NetworkAnalog.py | 65 +++++++++++++++++++-------------- NetworkAnalog/SimObjs.py | 49 ++++++++++++++++--------- NetworkAnalog/network.db | Bin 40960 -> 40960 bytes NetworkAnalog/x1/SimObjs.py | 63 -------------------------------- NetworkAnalog/x2_test.py | 33 +++++++++++++++++ datas/network.db | Bin 0 -> 40960 bytes 7 files changed, 115 insertions(+), 107 deletions(-) delete mode 100644 NetworkAnalog/x1/SimObjs.py create mode 100644 NetworkAnalog/x2_test.py create mode 100644 datas/network.db diff --git a/.idea/dataSources.xml b/.idea/dataSources.xml index e33e3e5..ba6eba2 100644 --- a/.idea/dataSources.xml +++ b/.idea/dataSources.xml @@ -8,5 +8,17 @@ jdbc:sqlite:$PROJECT_DIR$/../网络仿真/NetworkAnalog/network.db $ProjectFileDir$ + + sqlite.xerial + true + org.sqlite.JDBC + jdbc:sqlite:D:\头哥\NetworkAnalog\datas\network.db + $ProjectFileDir$ + + + file://$APPLICATION_CONFIG_DIR$/jdbc-drivers/Xerial SQLiteJDBC/3.40.1/org/xerial/sqlite-jdbc/3.40.1.0/sqlite-jdbc-3.40.1.0.jar + + + \ No newline at end of file diff --git a/NetworkAnalog/NetworkAnalog.py b/NetworkAnalog/NetworkAnalog.py index 33674dc..7622f79 100644 --- a/NetworkAnalog/NetworkAnalog.py +++ b/NetworkAnalog/NetworkAnalog.py @@ -467,6 +467,15 @@ class NetWorkAnalog(Canvas): conn_obj.ConfigCorrect = key[1] self.tag_bind_event() + def show_obj(self, AllSimObj, conns): + self.AllSimObjs = AllSimObj + self.conns = conns + for key, sim_obj in self.AllSimObjs.items(): + print(key) + sim_obj.create_img() + for conn in self.conns: + conn.draw_line() + def delete_obj(self): # todo: 删除对象 """ @@ -919,32 +928,7 @@ class NetWorkAnalog(Canvas): self.AllSimObjs.clear() self.conns.clear() - def create_widget(self): - # todo: 创建页面 - """ - 创建整体页面布局 - :return: - """ - self.create_rectangle(0, 0, self.width * 0.8, self.height * 0.85, outline="#7f6000", width=3) # 矩形框,左上角坐标,右下角坐标 - round_rectangle(self, self.width * 0.82, 30, self.width * 0.98, self.height * 0.85 / 2 - 30, outline="#ffff00", width=3, fill="#f4b88e") # 矩形框,左上角坐标,右下角坐标 - self.create_text(self.width * 0.82 + 120, 30 + 15, text="网络配置信息", anchor="n", font=('微软雅黑', 18, 'bold')) - round_rectangle(self, self.width * 0.82, self.height * 0.85 / 2, self.width * 0.98, self.height * 0.85 - 30, outline="#ffff00", width=2, fill="#f4b88e") # 矩形框,左上角坐标,右下角坐标 - self.create_text(self.width * 0.82 + 120, self.height * 0.85 / 2 + 15, text="路由/交换表信息", anchor="n", font=('微软雅黑', 18, 'bold')) - # 显示左边的固定图片 - img_height, text_height, split_width = self.height - 120, self.height - 60, 120 - self.create_text(split_width, text_height, text="路由器", anchor="nw", font=('微软雅黑', 18, 'bold')) # 显示文字 - router = self.create_image(split_width, img_height, image=self.router_img, anchor="nw") - self.create_text(split_width * 2, text_height, text="交换机", anchor="nw", font=('微软雅黑', 18, 'bold')) # 显示文字 - switch = self.create_image(split_width * 2, img_height, image=self.switch_img, anchor="nw") - self.create_text(split_width * 3, text_height, text="集线器", anchor="nw", font=('微软雅黑', 18, 'bold')) # 显示文字 - hub = self.create_image(split_width * 3, img_height, image=self.hub_img, anchor="nw") - self.create_text(split_width * 4, text_height, text="主机", anchor="nw", font=('微软雅黑', 18, 'bold')) # 显示文字 - host = self.create_image(split_width * 4, img_height, image=self.host_img, anchor="nw") - self.bind_event(router, "路由器") - self.bind_event(switch, "交换机") - self.bind_event(hub, "集线器") - self.bind_event(host, "主机") - + def create_config_button(self): # 创建一个菜单栏,这里我们可以把他理解成一个容器,在窗口的上方 menubar = tk.Menu(root) # 定义一个空菜单单元 @@ -975,7 +959,32 @@ class NetWorkAnalog(Canvas): menubar.add_command(label='清除屏幕', command=self.clear_canvas) root.config(menu=menubar) - self.reload_data() + + def create_widget(self): + # todo: 创建页面 + """ + 创建整体页面布局 + :return: + """ + self.create_rectangle(0, 0, self.width * 0.8, self.height * 0.85, outline="#7f6000", width=3) # 矩形框,左上角坐标,右下角坐标 + round_rectangle(self, self.width * 0.82, 30, self.width * 0.98, self.height * 0.85 / 2 - 30, outline="#ffff00", width=3, fill="#f4b88e") # 矩形框,左上角坐标,右下角坐标 + self.create_text(self.width * 0.82 + 120, 30 + 15, text="网络配置信息", anchor="n", font=('微软雅黑', 18, 'bold')) + round_rectangle(self, self.width * 0.82, self.height * 0.85 / 2, self.width * 0.98, self.height * 0.85 - 30, outline="#ffff00", width=2, fill="#f4b88e") # 矩形框,左上角坐标,右下角坐标 + self.create_text(self.width * 0.82 + 120, self.height * 0.85 / 2 + 15, text="路由/交换表信息", anchor="n", font=('微软雅黑', 18, 'bold')) + # 显示左边的固定图片 + img_height, text_height, split_width = self.height - 120, self.height - 60, 120 + self.create_text(split_width, text_height, text="路由器", anchor="nw", font=('微软雅黑', 18, 'bold')) # 显示文字 + router = self.create_image(split_width, img_height, image=self.router_img, anchor="nw") + self.create_text(split_width * 2, text_height, text="交换机", anchor="nw", font=('微软雅黑', 18, 'bold')) # 显示文字 + switch = self.create_image(split_width * 2, img_height, image=self.switch_img, anchor="nw") + self.create_text(split_width * 3, text_height, text="集线器", anchor="nw", font=('微软雅黑', 18, 'bold')) # 显示文字 + hub = self.create_image(split_width * 3, img_height, image=self.hub_img, anchor="nw") + self.create_text(split_width * 4, text_height, text="主机", anchor="nw", font=('微软雅黑', 18, 'bold')) # 显示文字 + host = self.create_image(split_width * 4, img_height, image=self.host_img, anchor="nw") + self.bind_event(router, "路由器") + self.bind_event(switch, "交换机") + self.bind_event(hub, "集线器") + self.bind_event(host, "主机") if __name__ == '__main__': @@ -991,5 +1000,7 @@ if __name__ == '__main__': (screen_height - root_attr['height']) / 2 - 30) canvas = NetWorkAnalog(root, width=root_attr['width'], heigh=root_attr['height'], bg="white") canvas.place(x=0, y=0, anchor='nw') + canvas.create_config_button() + canvas.reload_data() root.geometry(size) root.mainloop() diff --git a/NetworkAnalog/SimObjs.py b/NetworkAnalog/SimObjs.py index 6c27b31..82e5c41 100644 --- a/NetworkAnalog/SimObjs.py +++ b/NetworkAnalog/SimObjs.py @@ -26,6 +26,22 @@ class SimBase(): self.ObjX = x self.ObjY = y self.canvas = canvas + self.host_img = ImageTk.PhotoImage( + Image.open(sys.path[0] + "/../datas/images/主机.png").resize((60, 60))) + self.host_img_tm = ImageTk.PhotoImage( + Image.open(sys.path[0] + "/../datas/images/主机_tm.png").resize((60, 60))) + self.router_img = ImageTk.PhotoImage( + Image.open(sys.path[0] + "/../datas/images/路由器.png").resize((60, 60))) + self.router_img_tm = ImageTk.PhotoImage( + Image.open(sys.path[0] + "/../datas/images/路由器_tm.png").resize((60, 60))) + self.switch_img = ImageTk.PhotoImage( + Image.open(sys.path[0] + "/../datas/images/交换机.png").resize((60, 60))) + self.switch_img_tm = ImageTk.PhotoImage( + Image.open(sys.path[0] + "/../datas/images/交换机_tm.png").resize((60, 60))) + self.hub_img = ImageTk.PhotoImage( + Image.open(sys.path[0] + "/../datas/images/集线器.png").resize((60, 60))) + self.hub_img_tm = ImageTk.PhotoImage( + Image.open(sys.path[0] + "/../datas/images/集线器_tm.png").resize((60, 60))) self.img = None self.img_tm = None self.interface = [{}, {}, {}, {}] @@ -94,6 +110,18 @@ class SimBase(): 创建图片 :return: """ + if self.ObjType == 1: + self.img = self.host_img + self.img_tm = self.host_img_tm + elif self.ObjType == 2: + self.img = self.router_img + self.img_tm = self.router_img_tm + elif self.ObjType == 3: + self.img = self.switch_img + self.img_tm = self.switch_img_tm + else: + self.img = self.hub_img + self.img_tm = self.hub_img_tm self.canvas.delete("L") id = self.canvas.create_image(self.ObjX - 30, self.ObjY - 30, image=self.img if self.ConfigCorrect == 1 else self.img_tm, anchor="nw", @@ -455,10 +483,7 @@ class SimHost(SimBase): self.interface = [{}] self.connections = [None] self.set_default_config() - self.img = ImageTk.PhotoImage( - Image.open(sys.path[0] + "/../datas/images/主机.png").resize((60, 60))) - self.img_tm = ImageTk.PhotoImage( - Image.open(sys.path[0] + "/../datas/images/主机_tm.png").resize((60, 60))) + def create_packet(self, ip, mac, message): """ @@ -519,10 +544,6 @@ class SimRouter(SimBase): self.ObjLabel = label if label is not None else self.set_default_name() self.router_table = {} self.set_default_router_table() - self.img = ImageTk.PhotoImage( - Image.open(sys.path[0] + "/../datas/images/路由器.png").resize((60, 60))) - self.img_tm = ImageTk.PhotoImage( - Image.open(sys.path[0] + "/../datas/images/路由器_tm.png").resize((60, 60))) def set_default_router_table(self): """ @@ -565,7 +586,9 @@ class SimRouter(SimBase): if conn == packet.up_jump: continue ifs = self.connections.index(conn) + 1 - for network in self.router_table[ifs]: + if self.router_table.get(ifs) is None: + continue + for network in self.router_table.get(ifs): if self.check_destination_ip(packet.destination_ip, network): flag = True next_hop_ifs = ifs @@ -628,10 +651,6 @@ class SimSwitch(SimBase): self.ObjLabel = label if label is not None else self.set_default_name() self.mac_table = {} self.set_default_mac_table() - self.img = ImageTk.PhotoImage( - Image.open(sys.path[0] + "/../datas/images/交换机.png").resize((60, 60))) - self.img_tm = ImageTk.PhotoImage( - Image.open(sys.path[0] + "/../datas/images/交换机_tm.png").resize((60, 60))) def set_default_mac_table(self): """ @@ -721,10 +740,6 @@ class SimHub(SimBase): super().__init__(canvas, x, y, self.ObjID, config, label) self.ObjType = 4 self.ObjLabel = label if label is not None else self.set_default_name() - self.img = ImageTk.PhotoImage( - Image.open(sys.path[0] + "/../datas/images/集线器.png").resize((60, 60))) - self.img_tm = ImageTk.PhotoImage( - Image.open(sys.path[0] + "/../datas/images/集线器_tm.png").resize((60, 60))) def transmit(self, packet: SimPacket): """ diff --git a/NetworkAnalog/network.db b/NetworkAnalog/network.db index e8b53b7f25923766a407e232f8402901b53e1df1..68a2411d102000ae8f785aa44f710d2824ef4299 100644 GIT binary patch literal 40960 zcmeHQd2AfldEa|?c4u~UM5ZNK;!>0>G4fFJj=6j!q9{rfMUfIECb3+HoYR&qiMAxW zR$w=+Z6vP$Nr5DeWAq3d7cH8mNqVG7Tfiw&AVpKuJrMT*0;KsPiHkaJf!2Q%MbYog zwL|NAT&JmFyp@)_Z|8mA`@Y}%-Z{tbw z%h}J%z22U7ueUt!J#ggUa_>?1f`7kzVUMAY^?Gyjr+RaXv$MCQ8BSe(C|vHHIe%#n z9AyW32d55AEY7aZHS2oe*}f(mYr0nE58YVb-8aZGxpF=_bKm63g$tp7>H2w(FB~~G zv2b_q=+xc4J*mrMz4q9?ZewV2Te)=Rd=Nf%@!_*D+fxwI0emoli9Q1-3$3%7P+ zte+gtvG!NapJ&I}XZ=d7+0Pl)?EBK0pn#EK6yWZ~cu(@V6=z=USEfGpOumt4aqieN z_N@WI++qR!3d=iFRVOrDZH?B#rN83Pm9?yZy^X*Ih*);)qps^5`;@< zqKntB#pR3PedogSP}h01#_(ND<>dU_$x{mxN9IoTmW#&qD>V-MrRc%s-l6%0sUwHy z(&$Ld9_uYk9hzF0nwy+DS!^}^@R^^3W-vPiO>1)EEx1Z0RrUu_y18 znnT0G<);tF5T0}W1k3zObv2Or@BeowLJ@04Ft_Tb4c}9bwwgnuqvem27``}W;SaR? z!q>`b2n$Ct5aXYU4ey4rSZJg-%zMMQJ@XI`;LEEj24S0Z4Offp<=CBvRxT7;0>RhJ z?FPYxe);&??iAZh0mQh@vo!0!uF_~SfUj&d?8q{7y8Rqn?M7)$m3G!ftIgNcuc~h2 z8Fgd#FPfj|KGoe^8&#gKoo(Eq?3Dk${-XS>d}sZ~omV^0bnd7xwqLKe+F|?Gq&I7S zB>kpzZ<9#1)>m5(HeP*)jMc&nfq+2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a( z{XCipD8-$lu36k!+F>O$A*B|d-DROV>Zq#Ftqz-9*A*eH^0V8168FPqwTz4#BaMUT zwB^e|Q02QO!wP|m@HM_`@g~m-H!7pVFtW9pm~mdVE8>7*ncs+YUU> zHz&%4n(0@_yLj2)*uTFFt{D)h2wb z*`vQQ1Cx1CRCwZerh|8k&aoj!X<@11-|t7Kj%d&Wt{f}za#Y;2hwsG+3Nn2SwhDo>m=~XJGpYtszuqu{s zSJ*HeWBXm&&Wf9wWPB&ssrR zNsc6JzNADFc2SB&5|$+ik+i;$kyxKlQu+VdsZ*0|B{v9s1a;Wbx-^@eGry$%1&e`B AYXATM diff --git a/NetworkAnalog/x1/SimObjs.py b/NetworkAnalog/x1/SimObjs.py deleted file mode 100644 index 8a5cbc2..0000000 --- a/NetworkAnalog/x1/SimObjs.py +++ /dev/null @@ -1,63 +0,0 @@ -class AllSimConnect(): - # todo: 连接类 - def __init__(self, nodex, nodex_ifs, nodey, nodey_ifs, config=None): - """ - 连接对象 - :param nodex: 节点 - :param nodex_ifs: 节点接口 - :param nodey: 节点 - :param nodey_ifs: 节点接口 - """ - self.ConfigCorrect = 0 if config is None else config - self.NobjS = nodex - self.NobjE = nodey - self.IfsS = nodex_ifs - self.IfsE = nodey_ifs - -class SimHost(): - """ - 主机类 - """ - def __init__(self, x=0, y=0, id=None, config=None, label=None): - self.ObjID = id - self.ObjType = 1 - self.ObjLabel = label - self.interface = [] - self.connections = [] - -class SimRouter(): - """ - 路由类 - """ - def __init__(self, x=0, y=0, id=None, config=None, label=None, *args): - self.ObjID = id - self.ObjType = 2 - self.ObjLabel = label - self.router_table = {} - -class SimSwitch(): - """ - 交换机类 - """ - def __init__(self, x=0, y=0, id=None, config=None, label=None, *args): - self.ObjID = id - self.ObjType = 3 - self.ObjLabel = label - self.mac_table = {} - -class SimHub(): - """ - 集线器类 - """ - def __init__(self, x=0, y=0, id=None, config=None, label=None, *args): - self.ObjID = str() if id is None else id - self.ObjType = 4 - self.ObjLabel = label - -if __name__ == '__main__': - AllSimObj = [] - host1 = SimHost() - AllSimObj.append(host1) - router = SimRouter() - AllSimObj.append(router) - connect = AllSimConnect(host1, 1, router, 1) diff --git a/NetworkAnalog/x2_test.py b/NetworkAnalog/x2_test.py new file mode 100644 index 0000000..978c0c5 --- /dev/null +++ b/NetworkAnalog/x2_test.py @@ -0,0 +1,33 @@ +from NetworkAnalog import NetWorkAnalog +from SimObjs import * + + + +if __name__ == '__main__': + AllSimObj = {} + root = Window() + root.title('网络拓扑图') + root_attr = { + "width": root.winfo_screenwidth() * 0.83, + "height": root.winfo_screenheight() * 0.85, + } + size = '%dx%d+%d+%d' % (root_attr['width'], root_attr['height'], (root.winfo_screenwidth() - root_attr['width']) / 2, + (root.winfo_screenheight() - root_attr['height']) / 2 - 30) + canvas = NetWorkAnalog(root, width=root_attr['width'], heigh=root_attr['height'], bg="white") + canvas.place(x=0, y=0, anchor='nw') + root.geometry(size) + host1 = SimHost(canvas, 406, 268) + AllSimObj[host1.ObjID] = host1 + host2 = SimHost(canvas, 323, 285) + AllSimObj[host2.ObjID] = host2 + router = SimRouter(canvas, 216, 263) + AllSimObj[router.ObjID] = router + host1_router_connect = AllSimConnect(canvas, host1, 1, router, 1) + host2_router_connect = AllSimConnect(canvas, host2, 1, router, 2) + host1.connections[0] = host1_router_connect + router.connections[0] = host1_router_connect + host2.connections[0] = host2_router_connect + router.connections[1] = host2_router_connect + conns = [host1_router_connect, host2_router_connect] + canvas.show_obj(AllSimObj, conns) + root.mainloop() \ No newline at end of file diff --git a/datas/network.db b/datas/network.db new file mode 100644 index 0000000000000000000000000000000000000000..f4128ed3fdcbc11053f1dd1707bbdb364070d009 GIT binary patch literal 40960 zcmeHQd2AfldEa|?c4u~UM5ZNK;!>0>G4fFJj=6j!q9{rfMUfIECb3+HoYR&qiMAxW zR$#-eZ6vP$ae=h1WAq3d7cH8mNqVG75Wp!?AVpKuJy7=m0;KsPiHkaJf!2Q%MbYog zwL|NAT&JmFyp@)_Z|8mA`@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