added grpc api for creating emane link/unlink messages, which will be sent to the gui for being added/removed

This commit is contained in:
bharnden 2019-10-12 08:56:39 -07:00
parent eb248291a5
commit 4e4fcddd00
3 changed files with 73 additions and 1 deletions

View file

@ -864,6 +864,21 @@ class CoreGrpcClient(object):
request = core_pb2.OpenXmlRequest(data=data)
return self.stub.OpenXml(request)
def emane_link(self, session_id, nem_one, nem_two, linked):
"""
Helps broadcast wireless link/unlink between EMANE nodes.
:param int session_id: session id
:param int nem_one:
:param int nem_two:
:param bool linked: True to link, False to unlink
:return: core_pb2.EmaneLinkResponse
"""
request = core_pb2.EmaneLinkRequest(
session_id=session_id, nem_one=nem_one, nem_two=nem_two, linked=linked
)
return self.stub.EmaneLink(request)
def connect(self):
"""
Open connection to server, must be closed manually.

View file

@ -21,7 +21,7 @@ from core.emulator.data import (
NodeData,
)
from core.emulator.emudata import InterfaceData, LinkOptions, NodeOptions
from core.emulator.enumerations import EventTypes, LinkTypes, NodeTypes
from core.emulator.enumerations import EventTypes, LinkTypes, MessageFlags, NodeTypes
from core.errors import CoreError
from core.location.mobility import BasicRangeModel, Ns2ScriptedMobility
from core.nodes.base import CoreNetworkBase
@ -1557,3 +1557,47 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
continue
interfaces.append(interface)
return core_pb2.GetInterfacesResponse(interfaces=interfaces)
def EmaneLink(self, request, context):
"""
Helps broadcast wireless link/unlink between EMANE nodes.
:param core.api.grpc.core_pb2.EmaneLinkRequest request: get-interfaces request
:param grpc.ServicerContext context: context object
:return: emane link response with success status
:rtype: core.api.grpc.core_pb2.EmaneLinkResponse
"""
logging.debug("emane link: %s", request)
session = self.get_session(request.session_id, context)
nem_one = request.nem_one
emane_one, netif = session.emane.nemlookup(nem_one)
if not emane_one or not netif:
context.abort(
grpc.StatusCode.NOT_FOUND, "nem one {} not found".format(nem_one)
)
node_one = netif.node
nem_two = request.nem_two
emane_two, netif = session.emane.nemlookup(nem_two)
if not emane_two or not netif:
context.abort(
grpc.StatusCode.NOT_FOUND, "nem two {} not found".format(nem_two)
)
node_two = netif.node
if emane_one.id == emane_two.id:
if request.linked:
flag = MessageFlags.ADD.value
else:
flag = MessageFlags.DELETE.value
link = LinkData(
message_type=flag,
link_type=LinkTypes.WIRELESS.value,
node1_id=node_one.id,
node2_id=node_two.id,
network_id=emane_one.id,
)
session.broadcast_link(link)
return core_pb2.EmaneLinkResponse(result=True)
else:
return core_pb2.EmaneLinkResponse(result=False)

View file

@ -119,6 +119,8 @@ service CoreApi {
// utilities
rpc GetInterfaces (GetInterfacesRequest) returns (GetInterfacesResponse) {
}
rpc EmaneLink (EmaneLinkRequest) returns (EmaneLinkResponse) {
}
}
// rpc request/response messages
@ -633,6 +635,17 @@ message GetInterfacesResponse {
repeated string interfaces = 1;
}
message EmaneLinkRequest {
int32 session_id = 1;
int32 nem_one = 2;
int32 nem_two = 3;
bool linked = 4;
}
message EmaneLinkResponse {
bool result = 1;
}
// data structures for messages below
message MessageType {
enum Enum {