fix merge conflict
This commit is contained in:
commit
e2fba18ba5
12 changed files with 75 additions and 48 deletions
|
@ -1556,9 +1556,10 @@ class Session:
|
|||
funcs = []
|
||||
for node_id in self.nodes:
|
||||
node = self.nodes[node_id]
|
||||
if isinstance(node, CoreNodeBase):
|
||||
args = (node,)
|
||||
funcs.append((self.services.stop_services, args, {}))
|
||||
if not isinstance(node, CoreNodeBase) or not node.up:
|
||||
continue
|
||||
args = (node,)
|
||||
funcs.append((self.services.stop_services, args, {}))
|
||||
utils.threadpool(funcs)
|
||||
|
||||
# shutdown emane
|
||||
|
|
|
@ -110,6 +110,8 @@ class CoreClient:
|
|||
self.xml_dir = None
|
||||
self.xml_file = None
|
||||
|
||||
self.modified_service_nodes = set()
|
||||
|
||||
def reset(self):
|
||||
# helpers
|
||||
self.interfaces_manager.reset()
|
||||
|
@ -124,6 +126,7 @@ class CoreClient:
|
|||
self.emane_config = None
|
||||
self.service_configs.clear()
|
||||
self.file_configs.clear()
|
||||
self.modified_service_nodes.clear()
|
||||
for mobility_player in self.mobility_players.values():
|
||||
mobility_player.handle_close()
|
||||
self.mobility_players.clear()
|
||||
|
@ -806,6 +809,9 @@ class CoreClient:
|
|||
logging.error("unknown node: %s", node_id)
|
||||
continue
|
||||
del self.canvas_nodes[node_id]
|
||||
|
||||
self.modified_service_nodes.discard(node_id)
|
||||
|
||||
if node_id in self.mobility_configs:
|
||||
del self.mobility_configs[node_id]
|
||||
if node_id in self.wlan_configs:
|
||||
|
@ -1046,3 +1052,6 @@ class CoreClient:
|
|||
config = self.emane_model_configs.get(_from)
|
||||
if config:
|
||||
self.emane_model_configs[_to] = config
|
||||
|
||||
def service_been_modified(self, node_id: int) -> bool:
|
||||
return node_id in self.modified_service_nodes
|
||||
|
|
|
@ -36,8 +36,14 @@ class NodeServiceDialog(Dialog):
|
|||
services = canvas_node.core_node.services
|
||||
model = canvas_node.core_node.model
|
||||
if len(services) == 0:
|
||||
if not NodeUtils.is_custom(canvas_node.core_node.model):
|
||||
# not custom node type and node's services haven't been modified before
|
||||
if not NodeUtils.is_custom(
|
||||
canvas_node.core_node.model
|
||||
) and not self.app.core.service_been_modified(self.node_id):
|
||||
services = set(self.app.core.default_services[model])
|
||||
# services of default type nodes were modified to be empty
|
||||
elif canvas_node.core_node.id in self.app.core.modified_service_nodes:
|
||||
services = set()
|
||||
else:
|
||||
services = set(
|
||||
NodeUtils.get_custom_node_services(self.app.guiconfig, model)
|
||||
|
@ -141,12 +147,14 @@ class NodeServiceDialog(Dialog):
|
|||
)
|
||||
|
||||
def click_save(self):
|
||||
# if node is custom type or current services are not the default services then set core node services and add node to modified services node set
|
||||
if (
|
||||
self.canvas_node.core_node.model not in self.app.core.default_services
|
||||
or self.current_services
|
||||
!= self.app.core.default_services[self.canvas_node.core_node.model]
|
||||
):
|
||||
self.canvas_node.core_node.services[:] = self.current_services
|
||||
self.app.core.modified_service_nodes.add(self.canvas_node.core_node.id)
|
||||
else:
|
||||
if len(self.canvas_node.core_node.services) > 0:
|
||||
self.canvas_node.core_node.services[:] = []
|
||||
|
|
|
@ -854,6 +854,11 @@ class CanvasGraph(tk.Canvas):
|
|||
node = CanvasNode(
|
||||
self.master, scaled_x, scaled_y, copy, self.nodes[canvas_nid].image
|
||||
)
|
||||
|
||||
# add new node to modified_service_nodes set if that set contains the to_copy node
|
||||
if self.app.core.service_been_modified(core_node.id):
|
||||
self.app.core.modified_service_nodes.add(copy.id)
|
||||
|
||||
copy_map[canvas_nid] = node.id
|
||||
self.core.canvas_nodes[copy.id] = node
|
||||
self.nodes[node.id] = node
|
||||
|
|
|
@ -89,12 +89,15 @@ class MenuAction:
|
|||
title="Open",
|
||||
filetypes=(("XML Files", "*.xml"), ("All Files", "*")),
|
||||
)
|
||||
if file_path:
|
||||
self.app.core.xml_file = file_path
|
||||
self.app.core.xml_dir = str(os.path.dirname(file_path))
|
||||
self.open_xml_task(file_path)
|
||||
|
||||
def open_xml_task(self, filename):
|
||||
if filename:
|
||||
self.app.core.xml_file = filename
|
||||
self.app.core.xml_dir = str(os.path.dirname(filename))
|
||||
self.prompt_save_running_session()
|
||||
self.app.statusbar.progress_bar.start(5)
|
||||
task = BackgroundTask(self.app, self.app.core.open_xml, args=(file_path,))
|
||||
task = BackgroundTask(self.app, self.app.core.open_xml, args=(filename,))
|
||||
task.start()
|
||||
|
||||
def gui_preferences(self):
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
import logging
|
||||
import os
|
||||
import tkinter as tk
|
||||
from functools import partial
|
||||
from typing import TYPE_CHECKING
|
||||
|
@ -55,6 +57,10 @@ class Menubar(tk.Menu):
|
|||
menu.add_command(label="Save", accelerator="Ctrl+S", command=self.save)
|
||||
menu.add_command(label="Reload", underline=0, state=tk.DISABLED)
|
||||
self.app.bind_all("<Control-s>", self.save)
|
||||
|
||||
# some hard code values for testing
|
||||
recent = tk.Menu(menu)
|
||||
menu.add_cascade(label="Recent files", menu=recent)
|
||||
menu.add_separator()
|
||||
menu.add_command(label="Export Python script...", state=tk.DISABLED)
|
||||
menu.add_command(label="Execute XML or Python script...", state=tk.DISABLED)
|
||||
|
@ -409,6 +415,13 @@ class Menubar(tk.Menu):
|
|||
menu.add_command(label="About", command=self.menuaction.show_about)
|
||||
self.add_cascade(label="Help", menu=menu)
|
||||
|
||||
def open_recent_files(self, filename: str):
|
||||
if os.path.isfile(filename):
|
||||
logging.debug("Open recent file %s", filename)
|
||||
self.menuaction.open_xml_task(filename)
|
||||
else:
|
||||
logging.warning("File does not exist %s", filename)
|
||||
|
||||
def save(self, event=None):
|
||||
xml_file = self.app.core.xml_file
|
||||
if xml_file:
|
||||
|
|
|
@ -284,6 +284,7 @@ class CoreNodeBase(NodeBase):
|
|||
self.config_services = {}
|
||||
self.nodedir = None
|
||||
self.tmpnodedir = False
|
||||
self.up = False
|
||||
|
||||
def add_config_service(self, service_class: "ConfigServiceType") -> None:
|
||||
"""
|
||||
|
@ -503,7 +504,6 @@ class CoreNode(CoreNodeBase):
|
|||
)
|
||||
self.client = None
|
||||
self.pid = None
|
||||
self.up = False
|
||||
self.lock = threading.RLock()
|
||||
self._mounts = []
|
||||
self.bootsh = bootsh
|
||||
|
|
|
@ -289,7 +289,6 @@ class Rj45Node(CoreNodeBase, CoreInterface):
|
|||
"""
|
||||
CoreNodeBase.__init__(self, session, _id, name, start, server)
|
||||
CoreInterface.__init__(self, session, self, name, mtu, server)
|
||||
self.up = False
|
||||
self.lock = threading.RLock()
|
||||
self.ifindex = None
|
||||
# the following are PyCoreNetIf attributes
|
||||
|
|
|
@ -923,20 +923,14 @@ class CoreXmlReader:
|
|||
|
||||
if link_options.unidirectional == 1 and node_set in node_sets:
|
||||
logging.info(
|
||||
"updating link node_one(%s) node_two(%s): %s",
|
||||
node_one,
|
||||
node_two,
|
||||
link_options,
|
||||
"updating link node_one(%s) node_two(%s)", node_one, node_two
|
||||
)
|
||||
self.session.update_link(
|
||||
node_one, node_two, interface_one.id, interface_two.id, link_options
|
||||
)
|
||||
else:
|
||||
logging.info(
|
||||
"adding link node_one(%s) node_two(%s): %s",
|
||||
node_one,
|
||||
node_two,
|
||||
link_options,
|
||||
"adding link node_one(%s) node_two(%s)", node_one, node_two
|
||||
)
|
||||
self.session.add_link(
|
||||
node_one, node_two, interface_one, interface_two, link_options
|
||||
|
|
|
@ -15,18 +15,18 @@ def parse(name):
|
|||
help="number of nodes to create in this example",
|
||||
)
|
||||
parser.add_argument(
|
||||
"-t",
|
||||
"--time",
|
||||
"-c",
|
||||
"--count",
|
||||
type=int,
|
||||
default=DEFAULT_TIME,
|
||||
help="example iperf run time in seconds",
|
||||
help="number of time to ping node",
|
||||
)
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
if args.nodes < 2:
|
||||
parser.error(f"invalid min number of nodes: {args.nodes}")
|
||||
if args.time < 1:
|
||||
parser.error(f"invalid test time: {args.time}")
|
||||
if args.count < 1:
|
||||
parser.error(f"invalid ping count({args.count}), count must be greater than 0")
|
||||
|
||||
return args
|
|
@ -1,7 +1,7 @@
|
|||
import datetime
|
||||
import logging
|
||||
import parser
|
||||
import time
|
||||
|
||||
import params
|
||||
from core.emulator.coreemu import CoreEmu
|
||||
from core.emulator.emudata import IpPrefixes
|
||||
from core.emulator.enumerations import EventTypes, NodeTypes
|
||||
|
@ -33,14 +33,10 @@ def example(args):
|
|||
# get nodes to run example
|
||||
first_node = session.get_node(2)
|
||||
last_node = session.get_node(args.nodes + 1)
|
||||
|
||||
logging.info("starting iperf server on node: %s", first_node.name)
|
||||
first_node.cmd("iperf -s -D")
|
||||
first_node_address = prefixes.ip4_address(first_node)
|
||||
logging.info("node %s connecting to %s", last_node.name, first_node_address)
|
||||
output = last_node.cmd(f"iperf -t {args.time} -c {first_node_address}")
|
||||
logging.info("node %s pinging %s", last_node.name, first_node_address)
|
||||
output = last_node.cmd(f"ping -c {args.count} {first_node_address}")
|
||||
logging.info(output)
|
||||
first_node.cmd("killall -9 iperf")
|
||||
|
||||
# shutdown session
|
||||
coreemu.shutdown()
|
||||
|
@ -48,11 +44,13 @@ def example(args):
|
|||
|
||||
def main():
|
||||
logging.basicConfig(level=logging.INFO)
|
||||
args = parser.parse("switch")
|
||||
start = datetime.datetime.now()
|
||||
logging.info("running switch example: nodes(%s) time(%s)", args.nodes, args.time)
|
||||
args = params.parse("switch")
|
||||
start = time.perf_counter()
|
||||
logging.info(
|
||||
"running switch example: nodes(%s) ping count(%s)", args.nodes, args.count
|
||||
)
|
||||
example(args)
|
||||
logging.info("elapsed time: %s", datetime.datetime.now() - start)
|
||||
logging.info("elapsed time: %s", time.perf_counter() - start)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import datetime
|
||||
import logging
|
||||
import parser
|
||||
import time
|
||||
|
||||
import params
|
||||
from core.emulator.coreemu import CoreEmu
|
||||
from core.emulator.emudata import IpPrefixes, NodeOptions
|
||||
from core.emulator.enumerations import EventTypes, NodeTypes
|
||||
|
@ -37,14 +37,10 @@ def example(args):
|
|||
# get nodes for example run
|
||||
first_node = session.get_node(2)
|
||||
last_node = session.get_node(args.nodes + 1)
|
||||
|
||||
logging.info("starting iperf server on node: %s", first_node.name)
|
||||
first_node.cmd("iperf -s -D")
|
||||
address = prefixes.ip4_address(first_node)
|
||||
logging.info("node %s connecting to %s", last_node.name, address)
|
||||
output = last_node.cmd(f"iperf -t {args.time} -c {address}")
|
||||
logging.info("node %s pinging %s", last_node.name, address)
|
||||
output = last_node.cmd(f"ping -c {args.count} {address}")
|
||||
logging.info(output)
|
||||
first_node.cmd("killall -9 iperf")
|
||||
|
||||
# shutdown session
|
||||
coreemu.shutdown()
|
||||
|
@ -52,12 +48,13 @@ def example(args):
|
|||
|
||||
def main():
|
||||
logging.basicConfig(level=logging.INFO)
|
||||
args = parser.parse("wlan")
|
||||
|
||||
start = datetime.datetime.now()
|
||||
logging.info("running wlan example: nodes(%s) time(%s)", args.nodes, args.time)
|
||||
args = params.parse("wlan")
|
||||
start = time.perf_counter()
|
||||
logging.info(
|
||||
"running wlan example: nodes(%s) ping count(%s)", args.nodes, args.count
|
||||
)
|
||||
example(args)
|
||||
logging.info("elapsed time: %s", datetime.datetime.now() - start)
|
||||
logging.info("elapsed time: %s", time.perf_counter() - start)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
|
Loading…
Add table
Reference in a new issue