Merge branch 'enhancement/distributed-flask' of https://github.com/coreemu/core into enhancement/distributed-flask

This commit is contained in:
Blake Harnden 2019-10-17 12:13:45 -07:00
commit fb28741393
5 changed files with 75 additions and 2 deletions

View file

@ -2,7 +2,7 @@
# Process this file with autoconf to produce a configure script.
# this defines the CORE version number, must be static for AC_INIT
AC_INIT(core, 5.5.1)
AC_INIT(core, 5.5.2)
# autoconf and automake initialization
AC_CONFIG_SRCDIR([netns/version.h.in])

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 CoreCommandError, CoreError
from core.location.mobility import BasicRangeModel, Ns2ScriptedMobility
from core.nodes.base import CoreNetworkBase
@ -1560,3 +1560,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

@ -2028,6 +2028,7 @@ class CoreUdpHandler(CoreHandler):
}
self.master = False
self.session = None
self.coreemu = server.mainserver.coreemu
socketserver.BaseRequestHandler.__init__(self, request, client_address, server)
def setup(self):

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 {