Merge branch 'coretk' of https://github.com/coreemu/core into coretk
This commit is contained in:
commit
6a08bff7de
18 changed files with 166 additions and 76 deletions
|
@ -416,7 +416,7 @@ class CoreClient:
|
||||||
else:
|
else:
|
||||||
emane_config = None
|
emane_config = None
|
||||||
|
|
||||||
start = time.time()
|
start = time.perf_counter()
|
||||||
response = self.client.start_session(
|
response = self.client.start_session(
|
||||||
self.session_id,
|
self.session_id,
|
||||||
nodes,
|
nodes,
|
||||||
|
@ -430,7 +430,7 @@ class CoreClient:
|
||||||
service_configs,
|
service_configs,
|
||||||
file_configs,
|
file_configs,
|
||||||
)
|
)
|
||||||
process_time = time.time() - start
|
process_time = time.perf_counter() - start
|
||||||
logging.debug("start session(%s), result: %s", self.session_id, response.result)
|
logging.debug("start session(%s), result: %s", self.session_id, response.result)
|
||||||
self.app.statusbar.start_session_callback(process_time)
|
self.app.statusbar.start_session_callback(process_time)
|
||||||
|
|
||||||
|
@ -444,9 +444,9 @@ class CoreClient:
|
||||||
def stop_session(self, session_id=None):
|
def stop_session(self, session_id=None):
|
||||||
if not session_id:
|
if not session_id:
|
||||||
session_id = self.session_id
|
session_id = self.session_id
|
||||||
start = time.time()
|
start = time.perf_counter()
|
||||||
response = self.client.stop_session(session_id)
|
response = self.client.stop_session(session_id)
|
||||||
process_time = time.time() - start
|
process_time = time.perf_counter() - start
|
||||||
self.app.statusbar.stop_session_callback(process_time)
|
self.app.statusbar.stop_session_callback(process_time)
|
||||||
logging.debug("stopped session(%s), result: %s", session_id, response.result)
|
logging.debug("stopped session(%s), result: %s", session_id, response.result)
|
||||||
|
|
||||||
|
|
44
coretk/coretk/dialogs/about.py
Normal file
44
coretk/coretk/dialogs/about.py
Normal file
|
@ -0,0 +1,44 @@
|
||||||
|
import tkinter as tk
|
||||||
|
|
||||||
|
from coretk.dialogs.dialog import Dialog
|
||||||
|
from coretk.widgets import CodeText
|
||||||
|
|
||||||
|
LICENSE = """\
|
||||||
|
Copyright (c) 2005-2020, the Boeing Company.
|
||||||
|
|
||||||
|
Redistribution and use in source and binary forms, with or without
|
||||||
|
modification, are permitted provided that the following conditions are met:
|
||||||
|
|
||||||
|
1. Redistributions of source code must retain the above copyright notice,
|
||||||
|
this list of conditions and the following disclaimer.
|
||||||
|
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||||
|
this list of conditions and the following disclaimer in the documentation
|
||||||
|
and/or other materials provided with the distribution.
|
||||||
|
|
||||||
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||||
|
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||||
|
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||||
|
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||||
|
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||||
|
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||||
|
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||||
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
|
||||||
|
THE POSSIBILITY OF SUCH DAMAGE.\
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
class AboutDialog(Dialog):
|
||||||
|
def __init__(self, master, app):
|
||||||
|
super().__init__(master, app, "About CORE", modal=True)
|
||||||
|
self.draw()
|
||||||
|
|
||||||
|
def draw(self):
|
||||||
|
self.top.columnconfigure(0, weight=1)
|
||||||
|
self.top.rowconfigure(0, weight=1)
|
||||||
|
|
||||||
|
text = CodeText(self.top)
|
||||||
|
text.insert("1.0", LICENSE)
|
||||||
|
text.config(state=tk.DISABLED)
|
||||||
|
text.grid(sticky="nsew")
|
|
@ -3,6 +3,7 @@ from tkinter import ttk
|
||||||
|
|
||||||
from core.api.grpc import core_pb2
|
from core.api.grpc import core_pb2
|
||||||
from coretk.dialogs.dialog import Dialog
|
from coretk.dialogs.dialog import Dialog
|
||||||
|
from coretk.widgets import CodeText
|
||||||
|
|
||||||
|
|
||||||
class HookDialog(Dialog):
|
class HookDialog(Dialog):
|
||||||
|
@ -43,7 +44,7 @@ class HookDialog(Dialog):
|
||||||
frame.columnconfigure(0, weight=1)
|
frame.columnconfigure(0, weight=1)
|
||||||
frame.rowconfigure(0, weight=1)
|
frame.rowconfigure(0, weight=1)
|
||||||
frame.grid(row=1, sticky="nsew", pady=2)
|
frame.grid(row=1, sticky="nsew", pady=2)
|
||||||
self.data = tk.Text(frame)
|
self.data = CodeText(frame)
|
||||||
self.data.insert(
|
self.data.insert(
|
||||||
1.0,
|
1.0,
|
||||||
(
|
(
|
||||||
|
|
|
@ -2,12 +2,11 @@
|
||||||
import logging
|
import logging
|
||||||
import tkinter as tk
|
import tkinter as tk
|
||||||
from tkinter import ttk
|
from tkinter import ttk
|
||||||
from tkinter.scrolledtext import ScrolledText
|
|
||||||
|
|
||||||
from core.api.grpc import core_pb2
|
from core.api.grpc import core_pb2
|
||||||
from coretk.dialogs.dialog import Dialog
|
from coretk.dialogs.dialog import Dialog
|
||||||
from coretk.images import ImageEnum, Images
|
from coretk.images import ImageEnum, Images
|
||||||
from coretk.widgets import ListboxScroll
|
from coretk.widgets import CodeText, ListboxScroll
|
||||||
|
|
||||||
|
|
||||||
class ServiceConfiguration(Dialog):
|
class ServiceConfiguration(Dialog):
|
||||||
|
@ -182,7 +181,7 @@ class ServiceConfiguration(Dialog):
|
||||||
button.grid(row=0, column=2)
|
button.grid(row=0, column=2)
|
||||||
frame.grid(row=3, column=0, sticky="nsew")
|
frame.grid(row=3, column=0, sticky="nsew")
|
||||||
|
|
||||||
self.service_file_data = ScrolledText(tab1)
|
self.service_file_data = CodeText(tab1)
|
||||||
self.service_file_data.grid(row=4, column=0, sticky="nsew")
|
self.service_file_data.grid(row=4, column=0, sticky="nsew")
|
||||||
if len(self.filenames) > 0:
|
if len(self.filenames) > 0:
|
||||||
self.filename_combobox.current(0)
|
self.filename_combobox.current(0)
|
||||||
|
|
|
@ -4,7 +4,6 @@ import tkinter as tk
|
||||||
from PIL import Image, ImageTk
|
from PIL import Image, ImageTk
|
||||||
|
|
||||||
from core.api.grpc import core_pb2
|
from core.api.grpc import core_pb2
|
||||||
from core.api.grpc.core_pb2 import NodeType
|
|
||||||
from coretk.dialogs.shapemod import ShapeDialog
|
from coretk.dialogs.shapemod import ShapeDialog
|
||||||
from coretk.graph.edges import CanvasEdge, CanvasWirelessEdge
|
from coretk.graph.edges import CanvasEdge, CanvasWirelessEdge
|
||||||
from coretk.graph.enums import GraphMode, ScaleOption
|
from coretk.graph.enums import GraphMode, ScaleOption
|
||||||
|
@ -64,40 +63,6 @@ class CanvasGraph(tk.Canvas):
|
||||||
self.show_grid = tk.BooleanVar(value=True)
|
self.show_grid = tk.BooleanVar(value=True)
|
||||||
self.adjust_to_dim = tk.BooleanVar(value=False)
|
self.adjust_to_dim = tk.BooleanVar(value=False)
|
||||||
|
|
||||||
def create_node_context(self, canvas_node):
|
|
||||||
node = canvas_node.core_node
|
|
||||||
context = tk.Menu(self.master)
|
|
||||||
context.add_command(label="Configure", command=canvas_node.show_config)
|
|
||||||
if node.type == NodeType.WIRELESS_LAN:
|
|
||||||
context.add_command(
|
|
||||||
label="WLAN Config", command=canvas_node.show_wlan_config
|
|
||||||
)
|
|
||||||
if self.master.core.is_runtime():
|
|
||||||
if canvas_node.core_node.id in self.master.core.mobility_players:
|
|
||||||
context.add_command(
|
|
||||||
label="Mobility Player",
|
|
||||||
command=canvas_node.show_mobility_player,
|
|
||||||
)
|
|
||||||
else:
|
|
||||||
context.add_command(
|
|
||||||
label="Mobility Config", command=canvas_node.show_mobility_config
|
|
||||||
)
|
|
||||||
if node.type == NodeType.EMANE:
|
|
||||||
context.add_command(
|
|
||||||
label="EMANE Config", command=canvas_node.show_emane_config
|
|
||||||
)
|
|
||||||
context.add_command(label="Select adjacent", state=tk.DISABLED)
|
|
||||||
context.add_command(label="Create link to", state=tk.DISABLED)
|
|
||||||
context.add_command(label="Assign to", state=tk.DISABLED)
|
|
||||||
context.add_command(label="Move to", state=tk.DISABLED)
|
|
||||||
context.add_command(label="Cut", state=tk.DISABLED)
|
|
||||||
context.add_command(label="Copy", state=tk.DISABLED)
|
|
||||||
context.add_command(label="Paste", state=tk.DISABLED)
|
|
||||||
context.add_command(label="Delete", state=tk.DISABLED)
|
|
||||||
context.add_command(label="Hide", state=tk.DISABLED)
|
|
||||||
context.add_command(label="Services", state=tk.DISABLED)
|
|
||||||
return context
|
|
||||||
|
|
||||||
def reset_and_redraw(self, session):
|
def reset_and_redraw(self, session):
|
||||||
"""
|
"""
|
||||||
Reset the private variables CanvasGraph object, redraw nodes given the new grpc
|
Reset the private variables CanvasGraph object, redraw nodes given the new grpc
|
||||||
|
@ -517,7 +482,7 @@ class CanvasGraph(tk.Canvas):
|
||||||
canvas_node = self.nodes.get(selected)
|
canvas_node = self.nodes.get(selected)
|
||||||
if canvas_node:
|
if canvas_node:
|
||||||
logging.debug(f"node context: {selected}")
|
logging.debug(f"node context: {selected}")
|
||||||
self.context = self.create_node_context(canvas_node)
|
self.context = canvas_node.create_context()
|
||||||
self.context.post(event.x_root, event.y_root)
|
self.context.post(event.x_root, event.y_root)
|
||||||
else:
|
else:
|
||||||
self.context.unpost()
|
self.context.unpost()
|
||||||
|
|
|
@ -2,6 +2,7 @@ import logging
|
||||||
import tkinter as tk
|
import tkinter as tk
|
||||||
from tkinter import font
|
from tkinter import font
|
||||||
|
|
||||||
|
from core.api.grpc.core_pb2 import NodeType
|
||||||
from coretk.dialogs.emaneconfig import EmaneConfigDialog
|
from coretk.dialogs.emaneconfig import EmaneConfigDialog
|
||||||
from coretk.dialogs.mobilityconfig import MobilityConfigDialog
|
from coretk.dialogs.mobilityconfig import MobilityConfigDialog
|
||||||
from coretk.dialogs.nodeconfig import NodeConfigDialog
|
from coretk.dialogs.nodeconfig import NodeConfigDialog
|
||||||
|
@ -36,6 +37,15 @@ class CanvasNode:
|
||||||
fill="#0000CD",
|
fill="#0000CD",
|
||||||
)
|
)
|
||||||
self.tooltip = CanvasTooltip(self.canvas)
|
self.tooltip = CanvasTooltip(self.canvas)
|
||||||
|
self.edges = set()
|
||||||
|
self.interfaces = []
|
||||||
|
self.wireless_edges = set()
|
||||||
|
self.moving = None
|
||||||
|
self.antennae = []
|
||||||
|
self.setup_bindings()
|
||||||
|
|
||||||
|
def setup_bindings(self):
|
||||||
|
# self.canvas.bind("<Button-3>", self.click_context)
|
||||||
self.canvas.tag_bind(self.id, "<ButtonPress-1>", self.click_press)
|
self.canvas.tag_bind(self.id, "<ButtonPress-1>", self.click_press)
|
||||||
self.canvas.tag_bind(self.id, "<ButtonRelease-1>", self.click_release)
|
self.canvas.tag_bind(self.id, "<ButtonRelease-1>", self.click_release)
|
||||||
self.canvas.tag_bind(self.id, "<B1-Motion>", self.motion)
|
self.canvas.tag_bind(self.id, "<B1-Motion>", self.motion)
|
||||||
|
@ -43,11 +53,6 @@ class CanvasNode:
|
||||||
self.canvas.tag_bind(self.id, "<Control-1>", self.select_multiple)
|
self.canvas.tag_bind(self.id, "<Control-1>", self.select_multiple)
|
||||||
self.canvas.tag_bind(self.id, "<Enter>", self.on_enter)
|
self.canvas.tag_bind(self.id, "<Enter>", self.on_enter)
|
||||||
self.canvas.tag_bind(self.id, "<Leave>", self.on_leave)
|
self.canvas.tag_bind(self.id, "<Leave>", self.on_leave)
|
||||||
self.edges = set()
|
|
||||||
self.interfaces = []
|
|
||||||
self.wireless_edges = set()
|
|
||||||
self.moving = None
|
|
||||||
self.antennae = []
|
|
||||||
|
|
||||||
def delete(self):
|
def delete(self):
|
||||||
self.canvas.delete(self.id)
|
self.canvas.delete(self.id)
|
||||||
|
@ -186,6 +191,53 @@ class CanvasNode:
|
||||||
shape = self.canvas.shapes[object_id]
|
shape = self.canvas.shapes[object_id]
|
||||||
shape.motion(None, x - my_x, y - my_y)
|
shape.motion(None, x - my_x, y - my_y)
|
||||||
|
|
||||||
|
def create_context(self):
|
||||||
|
is_wlan = self.core_node.type == NodeType.WIRELESS_LAN
|
||||||
|
is_emane = self.core_node.type == NodeType.EMANE
|
||||||
|
context = tk.Menu(self.canvas)
|
||||||
|
if self.app.core.is_runtime():
|
||||||
|
context.add_command(label="Configure", command=self.show_config)
|
||||||
|
if NodeUtils.is_container_node(self.core_node.type):
|
||||||
|
context.add_command(label="Services", state=tk.DISABLED)
|
||||||
|
if is_wlan and self.core_node.id in self.app.core.mobility_players:
|
||||||
|
context.add_command(
|
||||||
|
label="Mobility Player", command=self.show_mobility_player
|
||||||
|
)
|
||||||
|
context.add_command(label="Select Adjacent", state=tk.DISABLED)
|
||||||
|
context.add_command(label="Hide", state=tk.DISABLED)
|
||||||
|
if NodeUtils.is_container_node(self.core_node.type):
|
||||||
|
context.add_command(label="Shell Window", state=tk.DISABLED)
|
||||||
|
context.add_command(label="Tcpdump", state=tk.DISABLED)
|
||||||
|
context.add_command(label="Tshark", state=tk.DISABLED)
|
||||||
|
context.add_command(label="Wireshark", state=tk.DISABLED)
|
||||||
|
context.add_command(label="View Log", state=tk.DISABLED)
|
||||||
|
else:
|
||||||
|
context.add_command(label="Configure", command=self.show_config)
|
||||||
|
if NodeUtils.is_container_node(self.core_node.type):
|
||||||
|
context.add_command(label="Services", state=tk.DISABLED)
|
||||||
|
if is_emane:
|
||||||
|
context.add_command(
|
||||||
|
label="EMANE Config", command=self.show_emane_config
|
||||||
|
)
|
||||||
|
if is_wlan:
|
||||||
|
context.add_command(label="WLAN Config", command=self.show_wlan_config)
|
||||||
|
context.add_command(
|
||||||
|
label="Mobility Config", command=self.show_mobility_config
|
||||||
|
)
|
||||||
|
if NodeUtils.is_wireless_node(self.core_node.type):
|
||||||
|
context.add_command(label="Link To All MDRs", state=tk.DISABLED)
|
||||||
|
context.add_command(label="Select Members", state=tk.DISABLED)
|
||||||
|
context.add_command(label="Select Adjacent", state=tk.DISABLED)
|
||||||
|
context.add_command(label="Create Link To", state=tk.DISABLED)
|
||||||
|
context.add_command(label="Assign To", state=tk.DISABLED)
|
||||||
|
context.add_command(label="Move To", state=tk.DISABLED)
|
||||||
|
context.add_command(label="Cut", state=tk.DISABLED)
|
||||||
|
context.add_command(label="Copy", state=tk.DISABLED)
|
||||||
|
context.add_command(label="Paste", state=tk.DISABLED)
|
||||||
|
context.add_command(label="Delete", state=tk.DISABLED)
|
||||||
|
context.add_command(label="Hide", state=tk.DISABLED)
|
||||||
|
return context
|
||||||
|
|
||||||
def select_multiple(self, event):
|
def select_multiple(self, event):
|
||||||
self.canvas.select_object(self.id, choose_multiple=True)
|
self.canvas.select_object(self.id, choose_multiple=True)
|
||||||
|
|
||||||
|
|
|
@ -12,6 +12,7 @@ import grpc
|
||||||
|
|
||||||
from core.api.grpc import core_pb2
|
from core.api.grpc import core_pb2
|
||||||
from coretk.appconfig import XML_PATH
|
from coretk.appconfig import XML_PATH
|
||||||
|
from coretk.dialogs.about import AboutDialog
|
||||||
from coretk.dialogs.canvasbackground import CanvasBackgroundDialog
|
from coretk.dialogs.canvasbackground import CanvasBackgroundDialog
|
||||||
from coretk.dialogs.canvassizeandscale import SizeAndScaleDialog
|
from coretk.dialogs.canvassizeandscale import SizeAndScaleDialog
|
||||||
from coretk.dialogs.hooks import HooksDialog
|
from coretk.dialogs.hooks import HooksDialog
|
||||||
|
@ -33,10 +34,10 @@ class MenuAction:
|
||||||
|
|
||||||
def cleanup_old_session(self, quitapp=False):
|
def cleanup_old_session(self, quitapp=False):
|
||||||
logging.info("cleaning up old session")
|
logging.info("cleaning up old session")
|
||||||
start = time.time()
|
start = time.perf_counter()
|
||||||
self.app.core.stop_session()
|
self.app.core.stop_session()
|
||||||
self.app.core.delete_session()
|
self.app.core.delete_session()
|
||||||
process_time = time.time() - start
|
process_time = time.perf_counter() - start
|
||||||
self.app.statusbar.stop_session_callback(process_time)
|
self.app.statusbar.stop_session_callback(process_time)
|
||||||
if quitapp:
|
if quitapp:
|
||||||
self.app.quit()
|
self.app.quit()
|
||||||
|
@ -151,3 +152,7 @@ class MenuAction:
|
||||||
def edit_observer_widgets(self):
|
def edit_observer_widgets(self):
|
||||||
dialog = ObserverDialog(self.app, self.app)
|
dialog = ObserverDialog(self.app, self.app)
|
||||||
dialog.show()
|
dialog.show()
|
||||||
|
|
||||||
|
def show_about(self):
|
||||||
|
dialog = AboutDialog(self.app, self.app)
|
||||||
|
dialog.show()
|
||||||
|
|
|
@ -462,5 +462,5 @@ class Menubar(tk.Menu):
|
||||||
label="Core Documentation (www)",
|
label="Core Documentation (www)",
|
||||||
command=self.menuaction.help_core_documentation,
|
command=self.menuaction.help_core_documentation,
|
||||||
)
|
)
|
||||||
menu.add_command(label="About", state=tk.DISABLED)
|
menu.add_command(label="About", command=self.menuaction.show_about)
|
||||||
self.add_cascade(label="Help", menu=menu)
|
self.add_cascade(label="Help", menu=menu)
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
import logging
|
import logging
|
||||||
import tkinter as tk
|
import tkinter as tk
|
||||||
from functools import partial
|
from functools import partial
|
||||||
from tkinter import ttk
|
from tkinter import font, ttk
|
||||||
|
from tkinter.scrolledtext import ScrolledText
|
||||||
|
|
||||||
from core.api.grpc import core_pb2
|
from core.api.grpc import core_pb2
|
||||||
|
|
||||||
|
@ -155,3 +156,26 @@ class CheckboxList(FrameScroll):
|
||||||
func = partial(self.clicked, name, var)
|
func = partial(self.clicked, name, var)
|
||||||
checkbox = ttk.Checkbutton(self.frame, text=name, variable=var, command=func)
|
checkbox = ttk.Checkbutton(self.frame, text=name, variable=var, command=func)
|
||||||
checkbox.grid(sticky="w")
|
checkbox.grid(sticky="w")
|
||||||
|
|
||||||
|
|
||||||
|
class CodeFont(font.Font):
|
||||||
|
def __init__(self):
|
||||||
|
super().__init__(font="TkFixedFont", color="green")
|
||||||
|
|
||||||
|
|
||||||
|
class CodeText(ScrolledText):
|
||||||
|
def __init__(self, master, **kwargs):
|
||||||
|
super().__init__(
|
||||||
|
master,
|
||||||
|
bd=0,
|
||||||
|
bg="black",
|
||||||
|
cursor="xterm lime lime",
|
||||||
|
fg="lime",
|
||||||
|
font=CodeFont(),
|
||||||
|
highlightbackground="black",
|
||||||
|
insertbackground="lime",
|
||||||
|
selectbackground="lime",
|
||||||
|
selectforeground="black",
|
||||||
|
relief=tk.FLAT,
|
||||||
|
**kwargs
|
||||||
|
)
|
||||||
|
|
|
@ -660,7 +660,7 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
|
||||||
last_check = None
|
last_check = None
|
||||||
last_stats = None
|
last_stats = None
|
||||||
while self._is_running(context):
|
while self._is_running(context):
|
||||||
now = time.time()
|
now = time.monotonic()
|
||||||
stats = get_net_stats()
|
stats = get_net_stats()
|
||||||
|
|
||||||
# calculate average
|
# calculate average
|
||||||
|
|
|
@ -1710,7 +1710,7 @@ class CoreHandler(socketserver.BaseRequestHandler):
|
||||||
event_type=event_type,
|
event_type=event_type,
|
||||||
name=name,
|
name=name,
|
||||||
data=fail_data + ";" + unknown_data,
|
data=fail_data + ";" + unknown_data,
|
||||||
time=str(time.time()),
|
time=str(time.monotonic()),
|
||||||
)
|
)
|
||||||
|
|
||||||
self.session.broadcast_event(event_data)
|
self.session.broadcast_event(event_data)
|
||||||
|
|
|
@ -103,7 +103,7 @@ class Session:
|
||||||
|
|
||||||
# TODO: should the default state be definition?
|
# TODO: should the default state be definition?
|
||||||
self.state = EventTypes.NONE.value
|
self.state = EventTypes.NONE.value
|
||||||
self._state_time = time.time()
|
self._state_time = time.monotonic()
|
||||||
self._state_file = os.path.join(self.session_dir, "state")
|
self._state_file = os.path.join(self.session_dir, "state")
|
||||||
|
|
||||||
# hooks handlers
|
# hooks handlers
|
||||||
|
@ -1030,7 +1030,7 @@ class Session:
|
||||||
return
|
return
|
||||||
|
|
||||||
self.state = state_value
|
self.state = state_value
|
||||||
self._state_time = time.time()
|
self._state_time = time.monotonic()
|
||||||
logging.info("changing session(%s) to state %s", self.id, state_name)
|
logging.info("changing session(%s) to state %s", self.id, state_name)
|
||||||
|
|
||||||
self.write_state(state_value)
|
self.write_state(state_value)
|
||||||
|
@ -1038,7 +1038,7 @@ class Session:
|
||||||
self.run_state_hooks(state_value)
|
self.run_state_hooks(state_value)
|
||||||
|
|
||||||
if send_event:
|
if send_event:
|
||||||
event_data = EventData(event_type=state_value, time=str(time.time()))
|
event_data = EventData(event_type=state_value, time=str(time.monotonic()))
|
||||||
self.broadcast_event(event_data)
|
self.broadcast_event(event_data)
|
||||||
|
|
||||||
def write_state(self, state):
|
def write_state(self, state):
|
||||||
|
@ -1821,7 +1821,7 @@ class Session:
|
||||||
if not in runtime.
|
if not in runtime.
|
||||||
"""
|
"""
|
||||||
if self.state == EventTypes.RUNTIME_STATE.value:
|
if self.state == EventTypes.RUNTIME_STATE.value:
|
||||||
return time.time() - self._state_time
|
return time.monotonic() - self._state_time
|
||||||
else:
|
else:
|
||||||
return 0.0
|
return 0.0
|
||||||
|
|
||||||
|
|
|
@ -145,7 +145,7 @@ class EventLoop:
|
||||||
with self.lock:
|
with self.lock:
|
||||||
if not self.running or not self.queue:
|
if not self.running or not self.queue:
|
||||||
break
|
break
|
||||||
now = time.time()
|
now = time.monotonic()
|
||||||
if self.queue[0].time > now:
|
if self.queue[0].time > now:
|
||||||
schedule = True
|
schedule = True
|
||||||
break
|
break
|
||||||
|
@ -170,7 +170,7 @@ class EventLoop:
|
||||||
raise ValueError("scheduling event while not running")
|
raise ValueError("scheduling event while not running")
|
||||||
if not self.queue:
|
if not self.queue:
|
||||||
return
|
return
|
||||||
delay = self.queue[0].time - time.time()
|
delay = self.queue[0].time - time.monotonic()
|
||||||
if self.timer:
|
if self.timer:
|
||||||
raise ValueError("timer was already set")
|
raise ValueError("timer was already set")
|
||||||
self.timer = Timer(delay, self.__run_events)
|
self.timer = Timer(delay, self.__run_events)
|
||||||
|
@ -187,7 +187,7 @@ class EventLoop:
|
||||||
if self.running:
|
if self.running:
|
||||||
return
|
return
|
||||||
self.running = True
|
self.running = True
|
||||||
self.start = time.time()
|
self.start = time.monotonic()
|
||||||
for event in self.queue:
|
for event in self.queue:
|
||||||
event.time += self.start
|
event.time += self.start
|
||||||
self.__schedule_event()
|
self.__schedule_event()
|
||||||
|
@ -225,7 +225,7 @@ class EventLoop:
|
||||||
self.eventnum += 1
|
self.eventnum += 1
|
||||||
evtime = float(delaysec)
|
evtime = float(delaysec)
|
||||||
if self.running:
|
if self.running:
|
||||||
evtime += time.time()
|
evtime += time.monotonic()
|
||||||
event = Event(eventnum, evtime, func, *args, **kwds)
|
event = Event(eventnum, evtime, func, *args, **kwds)
|
||||||
|
|
||||||
if self.queue:
|
if self.queue:
|
||||||
|
|
|
@ -174,7 +174,7 @@ class MobilityManager(ModelManager):
|
||||||
event_type=event_type,
|
event_type=event_type,
|
||||||
name=f"mobility:{model.name}",
|
name=f"mobility:{model.name}",
|
||||||
data=data,
|
data=data,
|
||||||
time=str(time.time()),
|
time=str(time.monotonic()),
|
||||||
)
|
)
|
||||||
|
|
||||||
self.session.broadcast_event(event_data)
|
self.session.broadcast_event(event_data)
|
||||||
|
@ -612,7 +612,7 @@ class WayPointMobility(WirelessModel):
|
||||||
if self.state != self.STATE_RUNNING:
|
if self.state != self.STATE_RUNNING:
|
||||||
return
|
return
|
||||||
t = self.lasttime
|
t = self.lasttime
|
||||||
self.lasttime = time.time()
|
self.lasttime = time.monotonic()
|
||||||
now = self.lasttime - self.timezero
|
now = self.lasttime - self.timezero
|
||||||
dt = self.lasttime - t
|
dt = self.lasttime - t
|
||||||
|
|
||||||
|
@ -664,7 +664,7 @@ class WayPointMobility(WirelessModel):
|
||||||
:return: nothing
|
:return: nothing
|
||||||
"""
|
"""
|
||||||
logging.info("running mobility scenario")
|
logging.info("running mobility scenario")
|
||||||
self.timezero = time.time()
|
self.timezero = time.monotonic()
|
||||||
self.lasttime = self.timezero - (0.001 * self.refresh_ms)
|
self.lasttime = self.timezero - (0.001 * self.refresh_ms)
|
||||||
self.movenodesinitial()
|
self.movenodesinitial()
|
||||||
self.runround()
|
self.runround()
|
||||||
|
@ -844,7 +844,7 @@ class WayPointMobility(WirelessModel):
|
||||||
self.lasttime = 0
|
self.lasttime = 0
|
||||||
self.run()
|
self.run()
|
||||||
elif laststate == self.STATE_PAUSED:
|
elif laststate == self.STATE_PAUSED:
|
||||||
now = time.time()
|
now = time.monotonic()
|
||||||
self.timezero += now - self.lasttime
|
self.timezero += now - self.lasttime
|
||||||
self.lasttime = now - (0.001 * self.refresh_ms)
|
self.lasttime = now - (0.001 * self.refresh_ms)
|
||||||
self.runround()
|
self.runround()
|
||||||
|
@ -871,7 +871,7 @@ class WayPointMobility(WirelessModel):
|
||||||
:return: nothing
|
:return: nothing
|
||||||
"""
|
"""
|
||||||
self.state = self.STATE_PAUSED
|
self.state = self.STATE_PAUSED
|
||||||
self.lasttime = time.time()
|
self.lasttime = time.monotonic()
|
||||||
|
|
||||||
|
|
||||||
class Ns2ScriptedMobility(WayPointMobility):
|
class Ns2ScriptedMobility(WayPointMobility):
|
||||||
|
|
|
@ -57,7 +57,7 @@ class EbtablesQueue:
|
||||||
:return: nothing
|
:return: nothing
|
||||||
"""
|
"""
|
||||||
with self.updatelock:
|
with self.updatelock:
|
||||||
self.last_update_time[wlan] = time.time()
|
self.last_update_time[wlan] = time.monotonic()
|
||||||
|
|
||||||
if self.doupdateloop:
|
if self.doupdateloop:
|
||||||
return
|
return
|
||||||
|
@ -108,9 +108,9 @@ class EbtablesQueue:
|
||||||
:rtype: float
|
:rtype: float
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
elapsed = time.time() - self.last_update_time[wlan]
|
elapsed = time.monotonic() - self.last_update_time[wlan]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
self.last_update_time[wlan] = time.time()
|
self.last_update_time[wlan] = time.monotonic()
|
||||||
elapsed = 0.0
|
elapsed = 0.0
|
||||||
|
|
||||||
return elapsed
|
return elapsed
|
||||||
|
@ -122,7 +122,7 @@ class EbtablesQueue:
|
||||||
:param wlan: wlan entity
|
:param wlan: wlan entity
|
||||||
:return: nothing
|
:return: nothing
|
||||||
"""
|
"""
|
||||||
self.last_update_time[wlan] = time.time()
|
self.last_update_time[wlan] = time.monotonic()
|
||||||
self.updates.remove(wlan)
|
self.updates.remove(wlan)
|
||||||
|
|
||||||
def updateloop(self):
|
def updateloop(self):
|
||||||
|
|
|
@ -538,13 +538,13 @@ class CoreServices:
|
||||||
time.sleep(service.validation_timer)
|
time.sleep(service.validation_timer)
|
||||||
# non-blocking, attempt to validate periodically, up to validation_timer time
|
# non-blocking, attempt to validate periodically, up to validation_timer time
|
||||||
elif service.validation_mode == ServiceMode.NON_BLOCKING:
|
elif service.validation_mode == ServiceMode.NON_BLOCKING:
|
||||||
start = time.time()
|
start = time.monotonic()
|
||||||
while True:
|
while True:
|
||||||
status = self.validate_service(node, service)
|
status = self.validate_service(node, service)
|
||||||
if not status:
|
if not status:
|
||||||
break
|
break
|
||||||
|
|
||||||
if time.time() - start > service.validation_timer:
|
if time.monotonic() - start > service.validation_timer:
|
||||||
break
|
break
|
||||||
|
|
||||||
time.sleep(service.validation_period)
|
time.sleep(service.validation_period)
|
||||||
|
|
|
@ -1042,7 +1042,7 @@ class TestGrpc:
|
||||||
client.events(session.id, handle_event)
|
client.events(session.id, handle_event)
|
||||||
time.sleep(0.1)
|
time.sleep(0.1)
|
||||||
event = EventData(
|
event = EventData(
|
||||||
event_type=EventTypes.RUNTIME_STATE.value, time=str(time.time())
|
event_type=EventTypes.RUNTIME_STATE.value, time=str(time.monotonic())
|
||||||
)
|
)
|
||||||
session.broadcast_event(event)
|
session.broadcast_event(event)
|
||||||
|
|
||||||
|
|
|
@ -523,7 +523,7 @@ class TestGui:
|
||||||
MessageFlags.ADD.value,
|
MessageFlags.ADD.value,
|
||||||
[
|
[
|
||||||
(EventTlvs.TYPE, EventTypes.SCHEDULED.value),
|
(EventTlvs.TYPE, EventTypes.SCHEDULED.value),
|
||||||
(EventTlvs.TIME, str(time.time() + 100)),
|
(EventTlvs.TIME, str(time.monotonic() + 100)),
|
||||||
(EventTlvs.NODE, node.id),
|
(EventTlvs.NODE, node.id),
|
||||||
(EventTlvs.NAME, "event"),
|
(EventTlvs.NAME, "event"),
|
||||||
(EventTlvs.DATA, "data"),
|
(EventTlvs.DATA, "data"),
|
||||||
|
|
Loading…
Add table
Reference in a new issue