Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

interface and related functions renaming #472

Merged
merged 13 commits into from
Jun 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 37 additions & 37 deletions daemon/core/api/grpc/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@
WlanLinkRequest,
WlanLinkResponse,
)
from core.emulator.emudata import IpPrefixes
from core.emulator.data import IpPrefixes


class InterfaceHelper:
Expand All @@ -110,27 +110,27 @@ def __init__(self, ip4_prefix: str = None, ip6_prefix: str = None) -> None:
"""
self.prefixes: IpPrefixes = IpPrefixes(ip4_prefix, ip6_prefix)

def create_interface(
self, node_id: int, interface_id: int, name: str = None, mac: str = None
def create_iface(
self, node_id: int, iface_id: int, name: str = None, mac: str = None
) -> core_pb2.Interface:
"""
Create an interface protobuf object.

:param node_id: node id to create interface for
:param interface_id: interface id
:param iface_id: interface id
:param name: name of interface
:param mac: mac address for interface
:return: interface protobuf
"""
interface_data = self.prefixes.gen_interface(node_id, name, mac)
iface_data = self.prefixes.gen_iface(node_id, name, mac)
return core_pb2.Interface(
id=interface_id,
name=interface_data.name,
ip4=interface_data.ip4,
ip4mask=interface_data.ip4_mask,
ip6=interface_data.ip6,
ip6mask=interface_data.ip6_mask,
mac=interface_data.mac,
id=iface_id,
name=iface_data.name,
ip4=iface_data.ip4,
ip4_mask=iface_data.ip4_mask,
ip6=iface_data.ip6,
ip6_mask=iface_data.ip6_mask,
mac=iface_data.mac,
)


Expand Down Expand Up @@ -611,8 +611,8 @@ def add_link(
session_id: int,
node1_id: int,
node2_id: int,
interface1: core_pb2.Interface = None,
interface2: core_pb2.Interface = None,
iface1: core_pb2.Interface = None,
iface2: core_pb2.Interface = None,
options: core_pb2.LinkOptions = None,
) -> core_pb2.AddLinkResponse:
"""
Expand All @@ -621,8 +621,8 @@ def add_link(
:param session_id: session id
:param node1_id: node one id
:param node2_id: node two id
:param interface1: node one interface data
:param interface2: node two interface data
:param iface1: node one interface data
:param iface2: node two interface data
:param options: options for link (jitter, bandwidth, etc)
:return: response with result of success or failure
:raises grpc.RpcError: when session or one of the nodes don't exist
Expand All @@ -631,8 +631,8 @@ def add_link(
node1_id=node1_id,
node2_id=node2_id,
type=core_pb2.LinkType.WIRED,
interface1=interface1,
interface2=interface2,
iface1=iface1,
iface2=iface2,
options=options,
)
request = core_pb2.AddLinkRequest(session_id=session_id, link=link)
Expand All @@ -644,8 +644,8 @@ def edit_link(
node1_id: int,
node2_id: int,
options: core_pb2.LinkOptions,
interface1_id: int = None,
interface2_id: int = None,
iface1_id: int = None,
iface2_id: int = None,
) -> core_pb2.EditLinkResponse:
"""
Edit a link between nodes.
Expand All @@ -654,8 +654,8 @@ def edit_link(
:param node1_id: node one id
:param node2_id: node two id
:param options: options for link (jitter, bandwidth, etc)
:param interface1_id: node one interface id
:param interface2_id: node two interface id
:param iface1_id: node one interface id
:param iface2_id: node two interface id
:return: response with result of success or failure
:raises grpc.RpcError: when session or one of the nodes don't exist
"""
Expand All @@ -664,8 +664,8 @@ def edit_link(
node1_id=node1_id,
node2_id=node2_id,
options=options,
interface1_id=interface1_id,
interface2_id=interface2_id,
iface1_id=iface1_id,
iface2_id=iface2_id,
)
return self.stub.EditLink(request)

Expand All @@ -674,26 +674,26 @@ def delete_link(
session_id: int,
node1_id: int,
node2_id: int,
interface1_id: int = None,
interface2_id: int = None,
iface1_id: int = None,
iface2_id: int = None,
) -> core_pb2.DeleteLinkResponse:
"""
Delete a link between nodes.

:param session_id: session id
:param node1_id: node one id
:param node2_id: node two id
:param interface1_id: node one interface id
:param interface2_id: node two interface id
:param iface1_id: node one interface id
:param iface2_id: node two interface id
:return: response with result of success or failure
:raises grpc.RpcError: when session doesn't exist
"""
request = core_pb2.DeleteLinkRequest(
session_id=session_id,
node1_id=node1_id,
node2_id=node2_id,
interface1_id=interface1_id,
interface2_id=interface2_id,
iface1_id=iface1_id,
iface2_id=iface2_id,
)
return self.stub.DeleteLink(request)

Expand Down Expand Up @@ -1028,20 +1028,20 @@ def get_emane_models(self, session_id: int) -> GetEmaneModelsResponse:
return self.stub.GetEmaneModels(request)

def get_emane_model_config(
self, session_id: int, node_id: int, model: str, interface_id: int = -1
self, session_id: int, node_id: int, model: str, iface_id: int = -1
) -> GetEmaneModelConfigResponse:
"""
Get emane model configuration for a node or a node's interface.

:param session_id: session id
:param node_id: node id
:param model: emane model name
:param interface_id: node interface id
:param iface_id: node interface id
:return: response with a list of configuration groups
:raises grpc.RpcError: when session doesn't exist
"""
request = GetEmaneModelConfigRequest(
session_id=session_id, node_id=node_id, model=model, interface=interface_id
session_id=session_id, node_id=node_id, model=model, iface_id=iface_id
)
return self.stub.GetEmaneModelConfig(request)

Expand All @@ -1051,7 +1051,7 @@ def set_emane_model_config(
node_id: int,
model: str,
config: Dict[str, str] = None,
interface_id: int = -1,
iface_id: int = -1,
) -> SetEmaneModelConfigResponse:
"""
Set emane model configuration for a node or a node's interface.
Expand All @@ -1060,12 +1060,12 @@ def set_emane_model_config(
:param node_id: node id
:param model: emane model name
:param config: emane model configuration
:param interface_id: node interface id
:param iface_id: node interface id
:return: response with result of success or failure
:raises grpc.RpcError: when session doesn't exist
"""
model_config = EmaneModelConfig(
node_id=node_id, model=model, config=config, interface_id=interface_id
node_id=node_id, model=model, config=config, iface_id=iface_id
)
request = SetEmaneModelConfigRequest(
session_id=session_id, emane_model_config=model_config
Expand Down Expand Up @@ -1128,7 +1128,7 @@ def emane_link(
)
return self.stub.EmaneLink(request)

def get_interfaces(self) -> core_pb2.GetInterfacesResponse:
def get_ifaces(self) -> core_pb2.GetInterfacesResponse:
"""
Retrieves a list of interfaces available on the host machine that are not
a part of a CORE session.
Expand Down
24 changes: 14 additions & 10 deletions daemon/core/api/grpc/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,28 @@
from core.emulator.session import Session


def handle_node_event(event: NodeData) -> core_pb2.NodeEvent:
def handle_node_event(node_data: NodeData) -> core_pb2.NodeEvent:
"""
Handle node event when there is a node event

:param event: node data
:param node_data: node data
:return: node event that contains node id, name, model, position, and services
"""
position = core_pb2.Position(x=event.x_position, y=event.y_position)
geo = core_pb2.Geo(lat=event.latitude, lon=event.longitude, alt=event.altitude)
node = node_data.node
x, y, _ = node.position.get()
position = core_pb2.Position(x=x, y=y)
lon, lat, alt = node.position.get_geo()
geo = core_pb2.Geo(lon=lon, lat=lat, alt=alt)
services = [x.name for x in node.services]
node_proto = core_pb2.Node(
id=event.id,
name=event.name,
model=event.model,
id=node.id,
name=node.name,
model=node.type,
position=position,
geo=geo,
services=event.services,
services=services,
)
return core_pb2.NodeEvent(node=node_proto, source=event.source)
return core_pb2.NodeEvent(node=node_proto, source=node_data.source)


def handle_link_event(event: LinkData) -> core_pb2.LinkEvent:
Expand Down Expand Up @@ -82,7 +86,7 @@ def handle_config_event(event: ConfigData) -> core_pb2.ConfigEvent:
data_values=event.data_values,
possible_values=event.possible_values,
groups=event.groups,
interface=event.interface_number,
iface_id=event.iface_id,
network_id=event.network_id,
opaque=event.opaque,
data_types=event.data_types,
Expand Down
Loading