improved sdt deletion of links by using the id properly
This commit is contained in:
parent
1252f72220
commit
71196004c8
2 changed files with 25 additions and 21 deletions
|
@ -430,7 +430,7 @@ class Session:
|
||||||
if node_two:
|
if node_two:
|
||||||
node_two.lock.release()
|
node_two.lock.release()
|
||||||
|
|
||||||
self.sdt.add_link(node_one_id, node_two_id, is_wireless=False)
|
self.sdt.add_link(node_one_id, node_two_id)
|
||||||
return node_one_interface, node_two_interface
|
return node_one_interface, node_two_interface
|
||||||
|
|
||||||
def delete_link(
|
def delete_link(
|
||||||
|
|
|
@ -5,7 +5,7 @@ sdt.py: Scripted Display Tool (SDT3D) helper
|
||||||
import logging
|
import logging
|
||||||
import socket
|
import socket
|
||||||
import threading
|
import threading
|
||||||
from typing import TYPE_CHECKING, Optional, Tuple
|
from typing import TYPE_CHECKING, Optional
|
||||||
from urllib.parse import urlparse
|
from urllib.parse import urlparse
|
||||||
|
|
||||||
from core import constants
|
from core import constants
|
||||||
|
@ -21,12 +21,11 @@ if TYPE_CHECKING:
|
||||||
from core.emulator.session import Session
|
from core.emulator.session import Session
|
||||||
|
|
||||||
|
|
||||||
def link_data_params(link_data: LinkData) -> Tuple[int, int, bool, int]:
|
def get_link_id(node_one: int, node_two: int, network_id: int) -> str:
|
||||||
node_one = link_data.node1_id
|
link_id = f"{node_one}-{node_two}"
|
||||||
node_two = link_data.node2_id
|
if network_id is not None:
|
||||||
is_wireless = link_data.link_type == LinkTypes.WIRELESS
|
link_id = f"{link_id}-{network_id}"
|
||||||
network_id = link_data.network_id
|
return link_id
|
||||||
return node_one, node_two, is_wireless, network_id
|
|
||||||
|
|
||||||
|
|
||||||
CORE_LAYER = "CORE"
|
CORE_LAYER = "CORE"
|
||||||
|
@ -226,8 +225,7 @@ class Sdt:
|
||||||
is_wireless = isinstance(net, (WlanNode, EmaneNet))
|
is_wireless = isinstance(net, (WlanNode, EmaneNet))
|
||||||
if is_wireless and link_data.node1_id == net.id:
|
if is_wireless and link_data.node1_id == net.id:
|
||||||
continue
|
continue
|
||||||
params = link_data_params(link_data)
|
self.handle_link_update(link_data)
|
||||||
self.add_link(*params)
|
|
||||||
|
|
||||||
def get_node_position(self, node: NodeBase) -> Optional[str]:
|
def get_node_position(self, node: NodeBase) -> Optional[str]:
|
||||||
"""
|
"""
|
||||||
|
@ -348,15 +346,19 @@ class Sdt:
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def add_link(
|
def add_link(
|
||||||
self, node_one: int, node_two: int, is_wireless: bool, network_id: int = None
|
self,
|
||||||
|
node_one: int,
|
||||||
|
node_two: int,
|
||||||
|
network_id: int = None,
|
||||||
|
is_wireless: bool = False,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""
|
"""
|
||||||
Handle adding a link in SDT.
|
Handle adding a link in SDT.
|
||||||
|
|
||||||
:param node_one: node one id
|
:param node_one: node one id
|
||||||
:param node_two: node two id
|
:param node_two: node two id
|
||||||
|
:param network_id: network link is associated with, None otherwise
|
||||||
:param is_wireless: True if link is wireless, False otherwise
|
:param is_wireless: True if link is wireless, False otherwise
|
||||||
:param network_id: network link is associated with
|
|
||||||
:return: nothing
|
:return: nothing
|
||||||
"""
|
"""
|
||||||
logging.debug("sdt add link: %s, %s, %s", node_one, node_two, is_wireless)
|
logging.debug("sdt add link: %s, %s, %s", node_one, node_two, is_wireless)
|
||||||
|
@ -368,9 +370,7 @@ class Sdt:
|
||||||
attr = "green,2"
|
attr = "green,2"
|
||||||
else:
|
else:
|
||||||
attr = "red,2"
|
attr = "red,2"
|
||||||
link_id = f"{node_one}-{node_two}"
|
link_id = get_link_id(node_one, node_two, network_id)
|
||||||
if network_id is not None:
|
|
||||||
link_id = f"{link_id}-{network_id}"
|
|
||||||
layer = LINK_LAYER
|
layer = LINK_LAYER
|
||||||
if network_id:
|
if network_id:
|
||||||
node = self.session.nodes[network_id]
|
node = self.session.nodes[network_id]
|
||||||
|
@ -378,12 +378,13 @@ class Sdt:
|
||||||
layer = f"{layer}::{network_name}"
|
layer = f"{layer}::{network_name}"
|
||||||
self.cmd(f"link {node_one},{node_two},{link_id} linkLayer {layer} line {attr}")
|
self.cmd(f"link {node_one},{node_two},{link_id} linkLayer {layer} line {attr}")
|
||||||
|
|
||||||
def delete_link(self, node_one: int, node_two: int) -> None:
|
def delete_link(self, node_one: int, node_two: int, network_id: int = None) -> None:
|
||||||
"""
|
"""
|
||||||
Handle deleting a node in SDT.
|
Handle deleting a node in SDT.
|
||||||
|
|
||||||
:param node_one: node one id
|
:param node_one: node one id
|
||||||
:param node_two: node two id
|
:param node_two: node two id
|
||||||
|
:param network_id: network link is associated with, None otherwise
|
||||||
:return: nothing
|
:return: nothing
|
||||||
"""
|
"""
|
||||||
logging.debug("sdt delete link: %s, %s", node_one, node_two)
|
logging.debug("sdt delete link: %s, %s", node_one, node_two)
|
||||||
|
@ -391,7 +392,8 @@ class Sdt:
|
||||||
return
|
return
|
||||||
if self.wireless_net_check(node_one) or self.wireless_net_check(node_two):
|
if self.wireless_net_check(node_one) or self.wireless_net_check(node_two):
|
||||||
return
|
return
|
||||||
self.cmd(f"delete link,{node_one},{node_two}")
|
link_id = get_link_id(node_one, node_two, network_id)
|
||||||
|
self.cmd(f"delete link,{node_one},{node_two},{link_id}")
|
||||||
|
|
||||||
def handle_link_update(self, link_data: LinkData) -> None:
|
def handle_link_update(self, link_data: LinkData) -> None:
|
||||||
"""
|
"""
|
||||||
|
@ -400,9 +402,11 @@ class Sdt:
|
||||||
:param link_data: link data to handle
|
:param link_data: link data to handle
|
||||||
:return: nothing
|
:return: nothing
|
||||||
"""
|
"""
|
||||||
|
node_one = link_data.node1_id
|
||||||
|
node_two = link_data.node2_id
|
||||||
|
network_id = link_data.network_id
|
||||||
|
is_wireless = link_data.link_type == LinkTypes.WIRELESS
|
||||||
if link_data.message_type == MessageFlags.ADD:
|
if link_data.message_type == MessageFlags.ADD:
|
||||||
params = link_data_params(link_data)
|
self.add_link(node_one, node_two, network_id, is_wireless)
|
||||||
self.add_link(*params)
|
|
||||||
elif link_data.message_type == MessageFlags.DELETE:
|
elif link_data.message_type == MessageFlags.DELETE:
|
||||||
params = link_data_params(link_data)
|
self.delete_link(node_one, node_two, network_id)
|
||||||
self.delete_link(*params[:2])
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue