daemon: renamed NodeData.node_type to type, removed NodeData/NodeOptions fields that were not being used for clarity

This commit is contained in:
Blake Harnden 2020-06-17 22:43:13 -07:00
parent a64047e221
commit b92ff0586a
7 changed files with 70 additions and 92 deletions

View file

@ -34,7 +34,6 @@ def add_node_data(node_proto: core_pb2.Node) -> Tuple[NodeTypes, int, NodeOption
name=node_proto.name,
model=node_proto.model,
icon=node_proto.icon,
opaque=node_proto.opaque,
image=node_proto.image,
services=node_proto.services,
config_services=node_proto.config_services,

View file

@ -722,7 +722,6 @@ class CoreHandler(socketserver.BaseRequestHandler):
options.icon = message.get_tlv(NodeTlvs.ICON.value)
options.canvas = message.get_tlv(NodeTlvs.CANVAS.value)
options.opaque = message.get_tlv(NodeTlvs.OPAQUE.value)
options.server = message.get_tlv(NodeTlvs.EMULATION_SERVER.value)
services = message.get_tlv(NodeTlvs.SERVICES.value)

View file

@ -18,9 +18,6 @@ def convert_node(node_data):
:param core.emulator.data.NodeData node_data: node data to convert
:return: packed node message
"""
session = None
if node_data.session is not None:
session = str(node_data.session)
services = None
if node_data.services is not None:
services = "|".join([x for x in node_data.services])
@ -28,25 +25,18 @@ def convert_node(node_data):
coreapi.CoreNodeTlv,
[
(NodeTlvs.NUMBER, node_data.id),
(NodeTlvs.TYPE, node_data.node_type.value),
(NodeTlvs.TYPE, node_data.type.value),
(NodeTlvs.NAME, node_data.name),
(NodeTlvs.IP_ADDRESS, node_data.ip_address),
(NodeTlvs.MAC_ADDRESS, node_data.mac_address),
(NodeTlvs.IP6_ADDRESS, node_data.ip6_address),
(NodeTlvs.MODEL, node_data.model),
(NodeTlvs.EMULATION_ID, node_data.emulation_id),
(NodeTlvs.EMULATION_SERVER, node_data.server),
(NodeTlvs.SESSION, session),
(NodeTlvs.X_POSITION, int(node_data.x_position)),
(NodeTlvs.Y_POSITION, int(node_data.y_position)),
(NodeTlvs.CANVAS, node_data.canvas),
(NodeTlvs.NETWORK_ID, node_data.network_id),
(NodeTlvs.SERVICES, services),
(NodeTlvs.LATITUDE, str(node_data.latitude)),
(NodeTlvs.LONGITUDE, str(node_data.longitude)),
(NodeTlvs.ALTITUDE, str(node_data.altitude)),
(NodeTlvs.ICON, node_data.icon),
(NodeTlvs.OPAQUE, node_data.opaque),
],
)
return coreapi.CoreNodeMessage.pack(node_data.message_type.value, tlv_data)

View file

@ -73,28 +73,71 @@ class FileData:
@dataclass
class NodeData:
message_type: MessageFlags = None
id: int = None
node_type: NodeTypes = None
class NodeOptions:
"""
Options for creating and updating nodes within core.
"""
name: str = None
ip_address: str = None
mac_address: str = None
ip6_address: str = None
model: str = None
emulation_id: int = None
model: Optional[str] = "PC"
canvas: int = None
icon: str = None
services: List[str] = field(default_factory=list)
config_services: List[str] = field(default_factory=list)
x: float = None
y: float = None
lat: float = None
lon: float = None
alt: float = None
server: str = None
session: int = None
image: str = None
emane: str = None
def set_position(self, x: float, y: float) -> None:
"""
Convenience method for setting position.
:param x: x position
:param y: y position
:return: nothing
"""
self.x = x
self.y = y
def set_location(self, lat: float, lon: float, alt: float) -> None:
"""
Convenience method for setting location.
:param lat: latitude
:param lon: longitude
:param alt: altitude
:return: nothing
"""
self.lat = lat
self.lon = lon
self.alt = alt
@dataclass
class NodeData:
"""
Used to represent nodes being broadcasted.
"""
message_type: MessageFlags = None
type: NodeTypes = None
id: int = None
name: str = None
model: str = None
server: str = None
icon: str = None
canvas: int = None
services: List[str] = None
x_position: float = None
y_position: float = None
canvas: int = None
network_id: int = None
services: List[str] = None
latitude: float = None
longitude: float = None
altitude: float = None
icon: str = None
opaque: str = None
source: str = None
@ -158,10 +201,10 @@ class LinkData:
label: str = None
node1_id: int = None
node2_id: int = None
network_id: int = None
iface1: InterfaceData = None
iface2: InterfaceData = None
options: LinkOptions = LinkOptions()
network_id: int = None
color: str = None
@ -259,51 +302,3 @@ class IpPrefixes:
iface_data = self.gen_iface(node.id, name, mac)
iface_data.id = node.next_iface_id()
return iface_data
@dataclass
class NodeOptions:
"""
Options for creating and updating nodes within core.
"""
name: str = None
model: Optional[str] = "PC"
canvas: int = None
icon: str = None
opaque: str = None
services: List[str] = field(default_factory=list)
config_services: List[str] = field(default_factory=list)
x: float = None
y: float = None
lat: float = None
lon: float = None
alt: float = None
emulation_id: int = None
server: str = None
image: str = None
emane: str = None
def set_position(self, x: float, y: float) -> None:
"""
Convenience method for setting position.
:param x: x position
:param y: y position
:return: nothing
"""
self.x = x
self.y = y
def set_location(self, lat: float, lon: float, alt: float) -> None:
"""
Convenience method for setting location.
:param lat: latitude
:param lon: longitude
:param alt: altitude
:return: nothing
"""
self.lat = lat
self.lon = lon
self.alt = alt

View file

@ -523,7 +523,6 @@ class Session:
# set node attributes
node.icon = options.icon
node.canvas = options.canvas
node.opaque = options.opaque
# set node position and broadcast it
self.set_node_position(node, options)

View file

@ -195,29 +195,26 @@ class NodeBase(abc.ABC):
"""
if self.apitype is None:
return None
x, y, _ = self.getposition()
model = self.type
server = None
if self.server is not None:
server = self.server.name
services = [service.name for service in self.services]
services = [x.name for x in self.services]
return NodeData(
message_type=message_type,
type=self.apitype,
id=self.id,
node_type=self.apitype,
name=self.name,
emulation_id=self.id,
model=model,
server=server,
canvas=self.canvas,
icon=self.icon,
opaque=self.opaque,
x_position=x,
y_position=y,
latitude=self.position.lat,
longitude=self.position.lon,
altitude=self.position.alt,
model=model,
server=server,
services=services,
source=source,
)

View file

@ -692,13 +692,12 @@ message Node {
repeated string services = 6;
string emane = 7;
string icon = 8;
string opaque = 9;
string image = 10;
string server = 11;
repeated string config_services = 12;
Geo geo = 13;
string dir = 14;
string channel = 15;
string image = 9;
string server = 10;
repeated string config_services = 11;
Geo geo = 12;
string dir = 13;
string channel = 14;
}
message Link {