removed IdGen class, added simple function to find next valid node id
This commit is contained in:
parent
199c4618f5
commit
6ddf1ac9a4
2 changed files with 14 additions and 16 deletions
|
@ -10,15 +10,6 @@ from core.nodes.interface import CoreInterface
|
||||||
from core.nodes.physical import PhysicalNode
|
from core.nodes.physical import PhysicalNode
|
||||||
|
|
||||||
|
|
||||||
class IdGen:
|
|
||||||
def __init__(self, _id: int = 0) -> None:
|
|
||||||
self.id = _id
|
|
||||||
|
|
||||||
def next(self) -> int:
|
|
||||||
self.id += 1
|
|
||||||
return self.id
|
|
||||||
|
|
||||||
|
|
||||||
def link_config(
|
def link_config(
|
||||||
node: Union[CoreNetworkBase, PhysicalNode],
|
node: Union[CoreNetworkBase, PhysicalNode],
|
||||||
interface: CoreInterface,
|
interface: CoreInterface,
|
||||||
|
|
|
@ -20,7 +20,6 @@ from core.emane.nodes import EmaneNet
|
||||||
from core.emulator.data import ConfigData, EventData, ExceptionData, FileData, LinkData
|
from core.emulator.data import ConfigData, EventData, ExceptionData, FileData, LinkData
|
||||||
from core.emulator.distributed import DistributedController
|
from core.emulator.distributed import DistributedController
|
||||||
from core.emulator.emudata import (
|
from core.emulator.emudata import (
|
||||||
IdGen,
|
|
||||||
InterfaceData,
|
InterfaceData,
|
||||||
LinkOptions,
|
LinkOptions,
|
||||||
NodeOptions,
|
NodeOptions,
|
||||||
|
@ -111,7 +110,6 @@ class Session:
|
||||||
self.link_colors = {}
|
self.link_colors = {}
|
||||||
|
|
||||||
# dict of nodes: all nodes and nets
|
# dict of nodes: all nodes and nets
|
||||||
self.node_id_gen = IdGen()
|
|
||||||
self.nodes = {}
|
self.nodes = {}
|
||||||
self._nodes_lock = threading.Lock()
|
self._nodes_lock = threading.Lock()
|
||||||
|
|
||||||
|
@ -649,6 +647,19 @@ class Session:
|
||||||
if node_two:
|
if node_two:
|
||||||
node_two.lock.release()
|
node_two.lock.release()
|
||||||
|
|
||||||
|
def _next_node_id(self) -> int:
|
||||||
|
"""
|
||||||
|
Find the next valid node id, starting from 1.
|
||||||
|
|
||||||
|
:return: next node id
|
||||||
|
"""
|
||||||
|
_id = 1
|
||||||
|
while True:
|
||||||
|
if _id not in self.nodes:
|
||||||
|
break
|
||||||
|
_id += 1
|
||||||
|
return _id
|
||||||
|
|
||||||
def add_node(
|
def add_node(
|
||||||
self, _class: Type[NT], _id: int = None, options: NodeOptions = None
|
self, _class: Type[NT], _id: int = None, options: NodeOptions = None
|
||||||
) -> NT:
|
) -> NT:
|
||||||
|
@ -669,10 +680,7 @@ class Session:
|
||||||
|
|
||||||
# determine node id
|
# determine node id
|
||||||
if not _id:
|
if not _id:
|
||||||
while True:
|
_id = self._next_node_id()
|
||||||
_id = self.node_id_gen.next()
|
|
||||||
if _id not in self.nodes:
|
|
||||||
break
|
|
||||||
|
|
||||||
# generate name if not provided
|
# generate name if not provided
|
||||||
if not options:
|
if not options:
|
||||||
|
@ -1399,7 +1407,6 @@ class Session:
|
||||||
self.sdt.delete_node(node.id)
|
self.sdt.delete_node(node.id)
|
||||||
funcs.append((node.shutdown, [], {}))
|
funcs.append((node.shutdown, [], {}))
|
||||||
utils.threadpool(funcs)
|
utils.threadpool(funcs)
|
||||||
self.node_id_gen.id = 0
|
|
||||||
|
|
||||||
def write_nodes(self) -> None:
|
def write_nodes(self) -> None:
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Add table
Reference in a new issue