refactored LinkOptions to be used within LinkData, instead of duplicating data, removed session from LinkOptions and LinkData
This commit is contained in:
parent
eeca33e722
commit
a29a7a5582
10 changed files with 120 additions and 113 deletions
|
@ -224,9 +224,7 @@ class NodeBase(abc.ABC):
|
|||
|
||||
def all_link_data(self, flags: MessageFlags = MessageFlags.NONE) -> List[LinkData]:
|
||||
"""
|
||||
Build CORE Link data for this object. There is no default
|
||||
method for PyCoreObjs as PyCoreNodes do not implement this but
|
||||
PyCoreNets do.
|
||||
Build link data for this node.
|
||||
|
||||
:param flags: message flags
|
||||
:return: list of link data
|
||||
|
@ -1108,35 +1106,27 @@ class CoreNetworkBase(NodeBase):
|
|||
iface2.ip6 = ip
|
||||
iface2.ip6_mask = mask
|
||||
|
||||
options_data = iface.get_link_options(unidirectional)
|
||||
link_data = LinkData(
|
||||
message_type=flags,
|
||||
node1_id=self.id,
|
||||
node2_id=linked_node.id,
|
||||
link_type=self.linktype,
|
||||
unidirectional=unidirectional,
|
||||
iface2=iface2,
|
||||
delay=iface.getparam("delay"),
|
||||
bandwidth=iface.getparam("bw"),
|
||||
dup=iface.getparam("duplicate"),
|
||||
jitter=iface.getparam("jitter"),
|
||||
loss=iface.getparam("loss"),
|
||||
options=options_data,
|
||||
)
|
||||
all_links.append(link_data)
|
||||
|
||||
if not uni:
|
||||
continue
|
||||
iface.swapparams("_params_up")
|
||||
options_data = iface.get_link_options(unidirectional)
|
||||
link_data = LinkData(
|
||||
message_type=MessageFlags.NONE,
|
||||
node1_id=linked_node.id,
|
||||
node2_id=self.id,
|
||||
link_type=self.linktype,
|
||||
unidirectional=1,
|
||||
delay=iface.getparam("delay"),
|
||||
bandwidth=iface.getparam("bw"),
|
||||
dup=iface.getparam("duplicate"),
|
||||
jitter=iface.getparam("jitter"),
|
||||
loss=iface.getparam("loss"),
|
||||
options=options_data,
|
||||
)
|
||||
iface.swapparams("_params_up")
|
||||
all_links.append(link_data)
|
||||
|
|
|
@ -7,6 +7,7 @@ import time
|
|||
from typing import TYPE_CHECKING, Callable, Dict, List, Optional, Tuple
|
||||
|
||||
from core import utils
|
||||
from core.emulator.data import LinkOptions
|
||||
from core.emulator.enumerations import MessageFlags, TransportType
|
||||
from core.errors import CoreCommandError
|
||||
from core.nodes.netclient import LinuxNetClient, get_net_client
|
||||
|
@ -169,6 +170,34 @@ class CoreInterface:
|
|||
"""
|
||||
return self._params.get(key)
|
||||
|
||||
def get_link_options(self, unidirectional: int) -> LinkOptions:
|
||||
"""
|
||||
Get currently set params as link options.
|
||||
|
||||
:param unidirectional: unidirectional setting
|
||||
:return: link options
|
||||
"""
|
||||
delay = self.getparam("delay")
|
||||
if delay is not None:
|
||||
delay = int(delay)
|
||||
bandwidth = self.getparam("bw")
|
||||
if bandwidth is not None:
|
||||
bandwidth = int(bandwidth)
|
||||
dup = self.getparam("duplicate")
|
||||
if dup is not None:
|
||||
dup = int(dup)
|
||||
jitter = self.getparam("jitter")
|
||||
if jitter is not None:
|
||||
jitter = int(jitter)
|
||||
return LinkOptions(
|
||||
delay=delay,
|
||||
bandwidth=bandwidth,
|
||||
dup=dup,
|
||||
jitter=jitter,
|
||||
loss=self.getparam("loss"),
|
||||
unidirectional=unidirectional,
|
||||
)
|
||||
|
||||
def getparams(self) -> List[Tuple[str, float]]:
|
||||
"""
|
||||
Return (key, value) pairs for parameters.
|
||||
|
|
|
@ -884,11 +884,12 @@ class PtpNet(CoreNetwork):
|
|||
:return: list of link data
|
||||
"""
|
||||
all_links = []
|
||||
|
||||
if len(self.ifaces) != 2:
|
||||
return all_links
|
||||
|
||||
iface1, iface2 = self.get_ifaces()
|
||||
ifaces = self.get_ifaces()
|
||||
iface1 = ifaces[0]
|
||||
iface2 = ifaces[1]
|
||||
unidirectional = 0
|
||||
if iface1.getparams() != iface2.getparams():
|
||||
unidirectional = 1
|
||||
|
@ -919,19 +920,15 @@ class PtpNet(CoreNetwork):
|
|||
iface2.ip6 = ip
|
||||
iface2.ip6_mask = mask
|
||||
|
||||
options_data = iface1.get_link_options(unidirectional)
|
||||
link_data = LinkData(
|
||||
message_type=flags,
|
||||
node1_id=iface1.node.id,
|
||||
node2_id=iface2.node.id,
|
||||
link_type=self.linktype,
|
||||
unidirectional=unidirectional,
|
||||
delay=iface1.getparam("delay"),
|
||||
bandwidth=iface1.getparam("bw"),
|
||||
loss=iface1.getparam("loss"),
|
||||
dup=iface1.getparam("duplicate"),
|
||||
jitter=iface1.getparam("jitter"),
|
||||
iface1=iface1_data,
|
||||
iface2=iface2_data,
|
||||
options=options_data,
|
||||
)
|
||||
all_links.append(link_data)
|
||||
|
||||
|
@ -940,19 +937,15 @@ class PtpNet(CoreNetwork):
|
|||
if unidirectional:
|
||||
iface1_data = InterfaceData(id=iface2.node.get_iface_id(iface2))
|
||||
iface2_data = InterfaceData(id=iface1.node.get_iface_id(iface1))
|
||||
options_data = iface2.get_link_options(unidirectional)
|
||||
link_data = LinkData(
|
||||
message_type=MessageFlags.NONE,
|
||||
link_type=self.linktype,
|
||||
node1_id=iface2.node.id,
|
||||
node2_id=iface1.node.id,
|
||||
delay=iface2.getparam("delay"),
|
||||
bandwidth=iface2.getparam("bw"),
|
||||
loss=iface2.getparam("loss"),
|
||||
dup=iface2.getparam("duplicate"),
|
||||
jitter=iface2.getparam("jitter"),
|
||||
unidirectional=1,
|
||||
iface1=iface1_data,
|
||||
iface2=iface2_data,
|
||||
options=options_data,
|
||||
)
|
||||
all_links.append(link_data)
|
||||
return all_links
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue