further updates to python docs and docs files

This commit is contained in:
Huy Pham 2019-09-13 11:07:04 -07:00
parent 2bfcc9ef24
commit 1843b5f709
6 changed files with 459 additions and 81 deletions

View file

@ -35,12 +35,27 @@ _INTERFACE_REGEX = re.compile(r"\d+")
def convert_value(value):
"""
Convert value into string.
:param value: value
:return: string conversion of the value
:rtype: str
"""
if value is not None:
value = str(value)
return value
# TODO add comments
def get_config_groups(config, configurable_options):
"""
???
:param core.config.Configuration config: configuration
:param core.config.ConfigurableOptions configurable_options: configurable options
:return:
"""
groups = []
config_options = []
@ -66,11 +81,13 @@ def get_config_groups(config, configurable_options):
return groups
# TODO add comments
def get_links(session, node):
"""
Get
:param session:
:param node:
:param core.emulator.Session session: node's section
:param core.nodes.base.CoreNode node: node to get links from
:return:
"""
links = []
@ -81,6 +98,14 @@ def get_links(session, node):
def get_emane_model_id(node_id, interface_id):
"""
Get EMANE model id
:param int node_id: node id
:param int interface_id: interface id
:return: EMANE model id
:rtype: int
"""
if interface_id >= 0:
return node_id * 1000 + interface_id
else:
@ -88,6 +113,14 @@ def get_emane_model_id(node_id, interface_id):
def convert_link(session, link_data):
"""
Convert link_data into core protobuf Link
:param core.emulator.session.Session session:
:param core.emulator.data.LinkData link_data:
:return: core protobuf Link
:rtype: core.api.grpc.core_pb2.Link
"""
interface_one = None
if link_data.interface1_id is not None:
node = session.get_node(link_data.node1_id)
@ -146,6 +179,7 @@ def convert_link(session, link_data):
)
# TODO add comments
def get_net_stats():
with open("/proc/net/dev", "r") as f:
data = f.readlines()[2:]
@ -162,7 +196,14 @@ def get_net_stats():
return stats
# TODO add comment
class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
"""
Create CoreGrpcServer instance
:param core.emulator.coreemu.CoreEmu coreemu: coreemu object
"""
def __init__(self, coreemu):
super(CoreGrpcServer, self).__init__()
self.coreemu = coreemu
@ -194,6 +235,14 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
self.server.stop(None)
def get_session(self, session_id, context):
"""
Retrieve session given the session id
:param int session_id: session id
:param grpc.ServicerContext context:
:return: session object that satisfies. If session not found then raise an exception.
:rtype: core.emulator.session.Session
"""
session = self.coreemu.sessions.get(session_id)
if not session:
context.abort(
@ -202,6 +251,15 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
return session
def get_node(self, session, node_id, context):
"""
Retrieve node given session and node id
:param core.emulator.session.Session session: session that contains the node
:param int node_id: node id
:param grpc.ServicerContext context:
:return: node object that satisfies. If node not found then raise an exception.
:rtype: core.nodes.base.CoreNode
"""
try:
return session.get_node(node_id)
except KeyError:
@ -210,6 +268,14 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
)
def CreateSession(self, request, context):
"""
Create a session
:param core.api.grpc.core_pb2.CreateSessionRequest request: create-session request
:param grpc.ServicerContext context:
:return: a create-session response
:rtype: core.api.grpc.core_pb2.CreateSessionResponse
"""
logging.debug("create session: %s", request)
session = self.coreemu.create_session(request.session_id)
session.set_state(EventTypes.DEFINITION_STATE)
@ -220,11 +286,27 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
)
def DeleteSession(self, request, context):
"""
Delete the session
:param core.api.grpc.core_pb2.DeleteSessionRequest request: delete-session request
:param grpc.ServicerContext context: context object
:return: a delete-session response
:rtype: core.api.grpc.core_pb2.DeleteSessionResponse
"""
logging.debug("delete session: %s", request)
result = self.coreemu.delete_session(request.session_id)
return core_pb2.DeleteSessionResponse(result=result)
def GetSessions(self, request, context):
"""
Delete the session
:param core.api.grpc.core_pb2.GetSessionRequest request: get-session request
:param grpc.ServicerContext context: context object
:return: a delete-session response
:rtype: core.api.grpc.core_pb2.DeleteSessionResponse
"""
logging.debug("get sessions: %s", request)
sessions = []
for session_id in self.coreemu.sessions:
@ -236,6 +318,14 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
return core_pb2.GetSessionsResponse(sessions=sessions)
def GetSessionLocation(self, request, context):
"""
Retrieve a requested session location
:param core.api.grpc.core_pb2.GetSessionLocationRequest request: get-session-location request
:param grpc.ServicerContext context: context object
:return: a get-session-location response
:rtype: core.api.grpc.core_pb2.GetSessionLocationResponse
"""
logging.debug("get session location: %s", request)
session = self.get_session(request.session_id, context)
x, y, z = session.location.refxyz
@ -246,6 +336,14 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
)
def SetSessionLocation(self, request, context):
"""
Set session location
:param core.api.grpc.core_pb2.SetSessionLocationRequest request: set-session-location request
:param grpc.ServicerContext context: context object
:return: a set-session-location-response
:rtype: core.api.grpc.core_pb2.SetSessionLocationResponse
"""
logging.debug("set session location: %s", request)
session = self.get_session(request.session_id, context)
session.location.refxyz = (
@ -260,6 +358,14 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
return core_pb2.SetSessionLocationResponse(result=True)
def SetSessionState(self, request, context):
"""
Set session state
:param core.api.grpc.core_pb2.SetSessionStateRequest request: set-session-state request
:param grpc.ServicerContext context:context object
:return: set-session-state response
:rtype: core.api.grpc.core_pb2.SetSessionStateResponse
"""
logging.debug("set session state: %s", request)
session = self.get_session(request.session_id, context)
@ -284,6 +390,7 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
return core_pb2.SetSessionStateResponse(result=result)
# TODO add comments
def GetSessionOptions(self, request, context):
logging.debug("get session options: %s", request)
session = self.get_session(request.session_id, context)
@ -293,6 +400,7 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
groups = get_config_groups(defaults, session.options)
return core_pb2.GetSessionOptionsResponse(groups=groups)
# TODO add comments
def SetSessionOptions(self, request, context):
logging.debug("set session options: %s", request)
session = self.get_session(request.session_id, context)
@ -301,6 +409,14 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
return core_pb2.SetSessionOptionsResponse(result=True)
def GetSession(self, request, context):
"""
Retrieve requested session
:param core.api.grpc.core_pb2.GetSessionRequest request: get-session request
:param grpc.ServicerContext context: context object
:return: get-session response
:rtype: core.api.grpc.core_bp2.GetSessionResponse
"""
logging.debug("get session: %s", request)
session = self.get_session(request.session_id, context)
@ -345,6 +461,7 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
session_proto = core_pb2.Session(state=session.state, nodes=nodes, links=links)
return core_pb2.GetSessionResponse(session=session_proto)
# TODO add comments
def Events(self, request, context):
session = self.get_session(request.session_id, context)
queue = Queue()
@ -389,7 +506,15 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
session.event_handlers.remove(queue.put)
self._cancel_stream(context)
# TODO add comment
def _handle_node_event(self, event):
"""
Handle node event when there is a node event
:param event: an event in the event queue
:return: node event that contains node id, name, model, position, and services
:rtype: core.api.grpc.core_pb2.Node Event
"""
position = core_pb2.Position(x=event.x_position, y=event.y_position)
services = event.services or ""
services = services.split("|")
@ -402,7 +527,15 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
)
return core_pb2.NodeEvent(node=node_proto)
# TODO add comments
def _handle_link_event(self, event):
"""
Handle link event when there is a link event
:param event: an event from the event queue
:return: link event that has message type and link information
:rtype: core.api.grpc.core_pb2.LinkEvent
"""
interface_one = None
if event.interface1_id is not None:
interface_one = core_pb2.Interface(
@ -450,7 +583,15 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
)
return core_pb2.LinkEvent(message_type=event.message_type, link=link)
# TODO add comments
def _handle_session_event(self, event):
"""
Handle session event when there is a session event
:param event:
:return: session event
:rtype: core.api.grpc.core_pb2.SessionEvent
"""
event_time = event.time
if event_time is not None:
event_time = float(event_time)
@ -463,7 +604,15 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
session_id=event.session,
)
# TODO add comments
def _handle_config_event(self, event):
"""
Handle configuration event when there is configuration event
:param event:
:return: configuration event
:rtype: core.api.grpc.core_pb2.ConfigEvent
"""
session_id = None
if event.session is not None:
session_id = int(event.session)
@ -484,7 +633,12 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
data_types=event.data_types,
)
# TODO add comments
def _handle_exception_event(self, event):
"""
:param event:
:return:
"""
return core_pb2.ExceptionEvent(
node_id=event.node,
session_id=int(event.session),
@ -495,6 +649,7 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
opaque=event.opaque,
)
# TODO add comments
def _handle_file_event(self, event):
return core_pb2.FileEvent(
message_type=event.message_type,
@ -509,6 +664,7 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
compressed_data=event.compressed_data,
)
# TODO add comments
def Throughputs(self, request, context):
delay = 3
last_check = None
@ -561,6 +717,14 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
time.sleep(delay)
def AddNode(self, request, context):
"""
Add node to requested session
:param core.api.grpc.core_pb2.AddNodeRequest request: add-node request
:param grpc.ServicerContext context: context object
:return: add-node response
:rtype: core.api.grpc.core_pb2.AddNodeResponse
"""
logging.debug("add node: %s", request)
session = self.get_session(request.session_id, context)
@ -590,6 +754,14 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
return core_pb2.AddNodeResponse(node_id=node.id)
def GetNode(self, request, context):
"""
Retrieve node
:param core.api.grpc.core_pb2.GetNodeRequest request: get-node request
:param grpc.ServicerContext context: context object
:return: get-node response
:rtype: core.api.grpc.core_pb2.GetNodeResponse
"""
logging.debug("get node: %s", request)
session = self.get_session(request.session_id, context)
node = self.get_node(session, request.node_id, context)
@ -634,6 +806,14 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
return core_pb2.GetNodeResponse(node=node_proto, interfaces=interfaces)
def EditNode(self, request, context):
"""
Edit node
:param core.api.grpc.core_bp2.EditNodeRequest request: edit-node request
:param grpc.ServicerContext context: context object
:return: edit-node response
:rtype: core.api.grpc.core_pb2.EditNodeResponse
"""
logging.debug("edit node: %s", request)
session = self.get_session(request.session_id, context)
node_id = request.node_id
@ -653,12 +833,26 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
return core_pb2.EditNodeResponse(result=result)
def DeleteNode(self, request, context):
"""
Delete node
:param core.api.grpc.core_pb2.DeleteNodeRequest request: delete-node request
:param grpc.ServicerContext context: context object
:return: core.api.grpc.core_pb2.DeleteNodeResponse
"""
logging.debug("delete node: %s", request)
session = self.get_session(request.session_id, context)
result = session.delete_node(request.node_id)
return core_pb2.DeleteNodeResponse(result=result)
def NodeCommand(self, request, context):
"""
Run command on a node
:param core.api.grpc.core_pb2.NodeCommandRequest request: node-command request
:param grpc.ServicerContext context: context object
:return: core.api.grpc.core_pb2.NodeCommandResponse
"""
logging.debug("sending node command: %s", request)
session = self.get_session(request.session_id, context)
node = self.get_node(session, request.node_id, context)
@ -666,6 +860,14 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
return core_pb2.NodeCommandResponse(output=output)
def GetNodeTerminal(self, request, context):
"""
Retrieve terminal command string of a node
:param core.api.grpc.core_pb2.GetNodeTerminalRequest request: get-node-terminal request
:param grpc.ServicerContext context: context object
:return: get-node-terminal response
:rtype: core.api.grpc.core_bp2.GetNodeTerminalResponse
"""
logging.debug("getting node terminal: %s", request)
session = self.get_session(request.session_id, context)
node = self.get_node(session, request.node_id, context)
@ -673,6 +875,14 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
return core_pb2.GetNodeTerminalResponse(terminal=terminal)
def GetNodeLinks(self, request, context):
"""
Retrieve all links form a requested node
:param core.api.grpc.core_pb2.GetNodeLinksRequest request: get-node-links request
:param grpc.ServicerContext context: context object
:return: get-node-links response
:rtype: core.api.grpc.core_pb2.GetNodeLinksResponse
"""
logging.debug("get node links: %s", request)
session = self.get_session(request.session_id, context)
node = self.get_node(session, request.node_id, context)
@ -680,6 +890,14 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
return core_pb2.GetNodeLinksResponse(links=links)
def AddLink(self, request, context):
"""
Add link to a session
:param core.api.grpc.core_pb2.AddLinkRequest request: add-link request
:param grpc.ServicerContext context: context object
:return: add-link response
:rtype: core.api.grpc.AddLinkResponse
"""
logging.debug("add link: %s", request)
session = self.get_session(request.session_id, context)
@ -761,6 +979,14 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
return core_pb2.AddLinkResponse(result=True)
def EditLink(self, request, context):
"""
Edit a link
:param core.api.grpc.core_pb2.EditLinkRequest request: edit-link request
:param grpc.ServicerContext context: context object
:return: edit-link response
:rtype: core.api.grpc.core_pb2.EditLinkResponse
"""
logging.debug("edit link: %s", request)
session = self.get_session(request.session_id, context)
node_one_id = request.node_one_id
@ -786,6 +1012,14 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
return core_pb2.EditLinkResponse(result=True)
def DeleteLink(self, request, context):
"""
Delete a link
:param core.api.grpc.core_pb2.DeleteLinkRequest request: delete-link request
:param grpc.ServicerContext context: context object
:return: delete-link response
:rtype: core.api.grpc.core_pb2.DeleteLinkResponse
"""
logging.debug("delete link: %s", request)
session = self.get_session(request.session_id, context)
node_one_id = request.node_one_id
@ -809,6 +1043,14 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
return core_pb2.GetHooksResponse(hooks=hooks)
def AddHook(self, request, context):
"""
Add hook to a session
:param core.api.grpc.core_pb2.AddHookRequest request: add-hook request
:param grpc.ServicerContext context: context object
:return: add-hook response
:rtype: core.api.grpc.core_pb2.AddHookResponse
"""
logging.debug("add hook: %s", request)
session = self.get_session(request.session_id, context)
hook = request.hook
@ -816,6 +1058,14 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
return core_pb2.AddHookResponse(result=True)
def GetMobilityConfigs(self, request, context):
"""
Retrieve all mobility configurations from a session
:param core.api.grpc.core_pb2.GetMobilityConfigsRequest request: get-mobility-configurations request
:param grpc.ServicerContext context: context object
:return: get-mobility-configurations response that has a list of configurations
:rtype: core.api.grpc.core_pb2.GetMobilityConfigsResponse
"""
logging.debug("get mobility configs: %s", request)
session = self.get_session(request.session_id, context)
response = core_pb2.GetMobilityConfigsResponse()
@ -832,6 +1082,14 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
return response
def GetMobilityConfig(self, request, context):
"""
Retrieve mobility configuration of a node
:param core.api.grpc.core_pb2.GetMobilityConfigRequest request: get-mobility-configuration request
:param grpc.ServicerContext context: context object
:return: get-mobility-configuration response
:rtype: core.api.grpc.core_pb2.GetMobilityConfigResponse
"""
logging.debug("get mobility config: %s", request)
session = self.get_session(request.session_id, context)
config = session.mobility.get_model_config(
@ -841,6 +1099,14 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
return core_pb2.GetMobilityConfigResponse(groups=groups)
def SetMobilityConfig(self, request, context):
"""
Set mobility configuration of a node
:param core.api.grpc.core_pb2.SetMobilityConfigRequest request: set-mobility-configuration request
:param grpc.ServicerContext context: context object
:return: set-mobility-configuration response
"rtype" core.api.grpc.SetMobilityConfigResponse
"""
logging.debug("set mobility config: %s", request)
session = self.get_session(request.session_id, context)
session.mobility.set_model_config(
@ -849,6 +1115,14 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
return core_pb2.SetMobilityConfigResponse(result=True)
def MobilityAction(self, request, context):
"""
Take mobility action whether to start, pause, stop or none of those
:param core.api.grpc.core_pb2.MobilityActionRequest request: mobility-action request
:param grpc.ServicerContext context: context object
:return: mobility-action response
:rtype: core.api.grpc.core_pb2.MobilityActionResponse
"""
logging.debug("mobility action: %s", request)
session = self.get_session(request.session_id, context)
node = self.get_node(session, request.node_id, context)
@ -864,6 +1138,14 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
return core_pb2.MobilityActionResponse(result=result)
def GetServices(self, request, context):
"""
Retrieve all the services that are running
:param core.api.grpc.core_pb2.GetServicesRequest request: get-service request
:param grpc.ServicerContext context: context object
:return: get-services response
:rtype: core.api.grpc.core_pb2.GetServicesResponse
"""
logging.debug("get services: %s", request)
services = []
for name in ServiceManager.services:
@ -873,6 +1155,14 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
return core_pb2.GetServicesResponse(services=services)
def GetServiceDefaults(self, request, context):
"""
Retrieve all the default services of all node types in a session
:param core.api.grpc.core_pb2.GetServiceDefaultsRequest request: get-default-service request
:param grpc.ServicerContext context: context object
:return: get-service-defaults response about all the available default services
:rtype: core.api.grpc.core_pb2.GetServiceDefaultsResponse
"""
logging.debug("get service defaults: %s", request)
session = self.get_session(request.session_id, context)
all_service_defaults = []
@ -884,6 +1174,7 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
all_service_defaults.append(service_defaults)
return core_pb2.GetServiceDefaultsResponse(defaults=all_service_defaults)
# TODO add comments
def SetServiceDefaults(self, request, context):
logging.debug("set service defaults: %s", request)
session = self.get_session(request.session_id, context)
@ -895,6 +1186,14 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
return core_pb2.SetServiceDefaultsResponse(result=True)
def GetNodeService(self, request, context):
"""
Retrieve a requested service from a node
:param core.api.grpc.core_pb2.GetNodeServiceRequest request: get-node-service request
:param grpc.ServicerContext context: context object
:return: get-node-service response about the requested service
:rtype: core.api.grpc.core_pb2.GetNodeServiceResponse
"""
logging.debug("get node service: %s", request)
session = self.get_session(request.session_id, context)
service = session.services.get_service(
@ -915,6 +1214,14 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
return core_pb2.GetNodeServiceResponse(service=service_proto)
def GetNodeServiceFile(self, request, context):
"""
Retrieve a requested service file from a node
:param core.api.grpc.core_pb2.GetNodeServiceFileRequest request: get-node-service request
:param grpc.ServicerContext context: context object
:return: get-node-service response about the requested service
:rtype: core.api.grpc.core_pb2.GetNodeServiceFileResponse
"""
logging.debug("get node service file: %s", request)
session = self.get_session(request.session_id, context)
node = self.get_node(session, request.node_id, context)
@ -931,6 +1238,15 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
return core_pb2.GetNodeServiceFileResponse(data=file_data.data)
def SetNodeService(self, request, context):
"""
Set a node service for a node
:param core.api.grpc.core_pb2.SetNodeServiceRequest request: set-node-service request
that has info to set a node service
:param grpc.ServicerContext context: context object
:return: set-node-service response
:rtype: core.api.grpc.core_pb2.SetNodeServiceResponse
"""
logging.debug("set node service: %s", request)
session = self.get_session(request.session_id, context)
session.services.set_service(request.node_id, request.service)
@ -941,6 +1257,14 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
return core_pb2.SetNodeServiceResponse(result=True)
def SetNodeServiceFile(self, request, context):
"""
Store the customized service file in the service config
:param core.api.grpc.core_pb2.SetNodeServiceFileRequest request: set-node-service-file request
:param grpc.ServicerContext context: context object
:return: set-node-service-file response
:rtype: core.api.grpc.core_pb2.SetNodeServiceFileResponse
"""
logging.debug("set node service file: %s", request)
session = self.get_session(request.session_id, context)
session.services.set_service_file(
@ -949,6 +1273,14 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
return core_pb2.SetNodeServiceFileResponse(result=True)
def ServiceAction(self, request, context):
"""
Take action whether to start, stop, restart, validate the service or none of the above
:param core.api.grpc.core_pb2.ServiceActionRequest request: service-action request
:param grpcServicerContext context: context object
:return: service-action response about status of action
:rtype: core.api.grpc.core_pb2.ServiceActionResponse
"""
logging.debug("service action: %s", request)
session = self.get_session(request.session_id, context)
node = self.get_node(session, request.node_id, context)
@ -980,6 +1312,14 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
return core_pb2.ServiceActionResponse(result=result)
def GetWlanConfig(self, request, context):
"""
Retrieve wireless-lan configuration of a node
:param core.api.grpc.core_pb2.GetWlanConfigRequest request: get-wlan-configuration request
:param context: core.api.grpc.core_pb2.GetWlanConfigResponse
:return: get-wlan-configuration response about the wlan configuration of a node
:rtype: core.api.grpc.core_pb2.GetWlanConfigResponse
"""
logging.debug("get wlan config: %s", request)
session = self.get_session(request.session_id, context)
config = session.mobility.get_model_config(
@ -989,6 +1329,14 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
return core_pb2.GetWlanConfigResponse(groups=groups)
def SetWlanConfig(self, request, context):
"""
Set configuration data for a model
:param core.api.grpc.core_pb2.SetWlanConfigRequest request: set-wlan-configuration request
:param grpc.ServicerContext context: context object
:return: set-wlan-configuration response
:rtype: core.api.grpc.core_pb2.SetWlanConfigResponse
"""
logging.debug("set wlan config: %s", request)
session = self.get_session(request.session_id, context)
session.mobility.set_model_config(
@ -1000,6 +1348,14 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
return core_pb2.SetWlanConfigResponse(result=True)
def GetEmaneConfig(self, request, context):
"""
Retrieve EMANE configuration of a session
:param core.api.grpc.core_pb2.GetEmanConfigRequest request: get-EMANE-configuration request
:param grpc.ServicerContext context: context object
:return: get-EMANE-configuration response
:rtype: core.api.grpc.core_pb2.GetEmaneConfigResponse
"""
logging.debug("get emane config: %s", request)
session = self.get_session(request.session_id, context)
config = session.emane.get_configs()
@ -1007,13 +1363,29 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
return core_pb2.GetEmaneConfigResponse(groups=groups)
def SetEmaneConfig(self, request, context):
"""
Set EMANE configuration of a session
:param core.api.grpc.core_pb2.SetEmaneConfigRequest request: set-EMANE-configuration request
:param grpc.ServicerContext context: context object
:return: set-EMANE-configuration response
:rtype: core.api.grpc.core_pb2.SetEmaneConfigResponse
"""
logging.debug("set emane config: %s", request)
session = self.get_session(request.session_id, context)
config = session.emane.get_configs()
config.update(request.config)
return core_pb2.SetEmaneConfigResponse(result=True)
# TODO add comment
def GetEmaneModels(self, request, context):
"""
Retrieve all the EMANE models in the session
:param request:
:param context:
:return:
"""
logging.debug("get emane models: %s", request)
session = self.get_session(request.session_id, context)
models = []
@ -1058,6 +1430,14 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
return response
def SaveXml(self, request, context):
"""
Export the session nto the EmulationScript XML format
:param core.api.grpc.core_pb2.SaveXmlRequest request: save xml request
:param grpc SrvicerContext context: context object
:return: save-xml response
:rtype: core.api.grpc.core_pb2.SaveXmlResponse
"""
logging.debug("save xml: %s", request)
session = self.get_session(request.session_id, context)
@ -1070,6 +1450,14 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
return core_pb2.SaveXmlResponse(data=data)
def OpenXml(self, request, context):
"""
Import a session from the EmulationScript XML format
:param core.api.grpc.OpenXmlRequest request: open-xml request
:param grpc.ServicerContext context: context object
:return: Open-XML response or raise an exception if invalid XML file
:rtype: core.api.grpc.core_pb2.OpenXMLResponse
"""
logging.debug("open xml: %s", request)
session = self.coreemu.create_session()
session.set_state(EventTypes.CONFIGURATION_STATE)
@ -1086,6 +1474,7 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
self.coreemu.delete_session(session.id)
context.abort(grpc.StatusCode.INVALID_ARGUMENT, "invalid xml file")
# TODO add comment
def GetInterfaces(self, request, context):
interfaces = []
for interface in os.listdir("/sys/class/net"):

View file

@ -351,7 +351,7 @@ class ModelManager(ConfigurableManager):
def get_model_config(self, node_id, model_name):
"""
Set configuration data for a model.
Retrieve configuration data for a model.
:param int node_id: node id to set model configuration for
:param str model_name: model to set configuration for

View file

@ -210,7 +210,7 @@ class NodeBase(object):
:param flags: message flags
:return: list of link data
:rtype: core.data.LinkData
:rtype: [core.data.LinkData]
"""
return []
@ -1109,6 +1109,11 @@ class CoreNetworkBase(NodeBase):
"""
Build link data objects for this network. Each link object describes a link
between this network and a node.
:param int flags: message type
:return: list of link data
:rtype: [core.data.LinkData]
"""
all_links = []

View file

@ -7,11 +7,13 @@
The top question about the performance of CORE is often *how many nodes can it handle?* The answer depends on several factors:
* Hardware - the number and speed of processors in the computer, the available processor cache, RAM memory, and front-side bus speed may greatly affect overall performance.
* Operating system version - distribution of Linux and the specific kernel versions used will affect overall performance.
* Active processes - all nodes share the same CPU resources, so if one or more nodes is performing a CPU-intensive task, overall performance will suffer.
* Network traffic - the more packets that are sent around the virtual network increases the amount of CPU usage.
* GUI usage - widgets that run periodically, mobility scenarios, and other GUI interactions generally consume CPU cycles that may be needed for emulation.
|||
|---|---|
| Hardware | the number and speed of processors in the computer, the available processor cache, RAM memory, and front-side bus speed may greatly affect overall performance. |
| Operating system version | distribution of Linux and the specific kernel versions used will affect overall performance. |
| Active processes | all nodes share the same CPU resources, so if one or more nodes is performing a CPU-intensive task, overall performance will suffer. |
| Network traffic | the more packets that are sent around the virtual network increases the amount of CPU usage. |
| GUI usage | widgets that run periodically, mobility scenarios, and other GUI interactions generally consume CPU cycles that may be needed for emulation. |
On a typical single-CPU Xeon 3.0GHz server machine with 2GB RAM running Linux, we have found it reasonable to run 30-75 nodes running OSPFv2 and OSPFv3 routing. On this hardware CORE can instantiate 100 or more nodes, but at that point it becomes critical as to what each of the nodes is doing.

View file

@ -24,17 +24,13 @@ shutdown commands, and meta-data associated with a node.
Here are the default node types and their services:
* *router* - zebra, OSFPv2, OSPFv3, and IPForward services for IGP
link-state routing.
* *host* - DefaultRoute and SSH services, representing an SSH server having a
default route when connected directly to a router.
* *PC* - DefaultRoute service for having a default route when connected
directly to a router.
* *mdr* - zebra, OSPFv3MDR, and IPForward services for
wireless-optimized MANET Designated Router routing.
* *prouter* - a physical router, having the same default services as the
*router* node type; for incorporating Linux testbed machines into an
emulation.
|||
|---|---|
| *router* | zebra, OSFPv2, OSPFv3, and IPForward services for IGP link-state routing. |
| *host* | DefaultRoute and SSH services, representing an SSH server having a default route when connected directly to a router. |
| *PC* | DefaultRoute service for having a default route when connected directly to a router. |
| *mdr* | zebra, OSPFv3MDR, and IPForward services for wireless-optimized MANET Designated Router routing. |
| *prouter* | a physical router, having the same default services as the *router* node type; for incorporating Linux testbed machines into an emulation. |
Configuration files can be automatically generated by each service. For
example, CORE automatically generates routing protocol configuration for the

View file

@ -72,24 +72,34 @@ When CORE is in Edit mode (the default), the vertical Editing Toolbar exists on
* ![alt text](../gui/icons/tiny/select.gif) *Selection Tool* - default tool for selecting, moving, configuring nodes
* ![alt text](../gui/icons/tiny/start.gif) *Start button* - starts Execute mode, instantiates the emulation
* ![alt text](../gui/icons/tiny/link.gif) *Link* - the Link Tool allows network links to be drawn between two nodes by clicking and dragging the mouse
* ![alt text](../gui/icons/tiny/router.gif) *Network-layer virtual nodes*
* ![alt text](../gui/icons/tiny/router.gif) *Router* - runs Quagga OSPFv2 and OSPFv3 routing to forward packets
* ![alt text](../gui/icons/tiny/host.gif) *Host* - emulated server machine having a default route, runs SSH server
* ![alt text](../gui/icons/tiny/pc.gif) *PC* - basic emulated machine having a default route, runs no processes by default
* ![alt text](../gui/icons/tiny/mdr.gif) *MDR* - runs Quagga OSPFv3 MDR routing for MANET-optimized routing
* ![alt text](../gui/icons/tiny/router_green.gif) *PRouter* - physical router represents a real testbed machine
* ![alt text](../gui/icons/tiny/document-properties.gif) *Edit* - edit node types button invokes the CORE Node Types dialog. New types of nodes may be created having different icons and names. The default services that are started with each node type can be changed here.
* ![alt text](../gui/icons/tiny/hub.gif) *Link-layer nodes*
* ![alt text](../gui/icons/tiny/hub.gif) *Hub* - the Ethernet hub forwards incoming packets to every connected node
* ![alt text](../gui/icons/tiny/lanswitch.gif) *Switch* - the Ethernet switch intelligently forwards incoming packets to attached hosts using an Ethernet address hash table
* ![alt text](../gui/icons/tiny/wlan.gif) *Wireless LAN* - when routers are connected to this WLAN node, they join a wireless network and an antenna is drawn instead of a connecting line; the WLAN node typically controls connectivity between attached wireless nodes based on the distance between them
* ![alt text](../gui/icons/tiny/rj45.gif) *RJ45* - with the RJ45 Physical Interface Tool, emulated nodes can be linked to real physical interfaces; using this tool, real networks and devices can be physically connected to the live-running emulation
* ![alt text](../gui/icons/tiny/tunnel.gif) *Tunnel* - the Tunnel Tool allows connecting together more than one CORE emulation using GRE tunnels
* ![alt text](../gui/icons/tiny/router.gif) *Network-layer virtual nodes consist of the following:*
|||
|---|---|
| ![alt text](../gui/icons/tiny/router.gif) *Router* | runs Quagga OSPFv2 and OSPFv3 routing to forward packets. |
| ![alt text](../gui/icons/tiny/host.gif) *Host* | emulated server machine having a default route, runs SSH server. |
| ![alt text](../gui/icons/tiny/pc.gif) *PC* | basic emulated machine having a default route, runs no processes by default. |
| ![alt text](../gui/icons/tiny/mdr.gif) *MDR* | runs Quagga OSPFv3 MDR routing for MANET-optimized routing. |
| ![alt text](../gui/icons/tiny/router_green.gif) *PRouter* | physical router represents a real testbed machine. |
| ![alt text](../gui/icons/tiny/document-properties.gif) *Edit* | edit node types button invokes the CORE Node Types dialog. New types of nodes may be created having different icons and names. The default services that are started with each node type can be changed here. |
* ![alt text](../gui/icons/tiny/hub.gif) *Link-layer nodes consist of the following:*
|||
|---|---|
| ![alt text](../gui/icons/tiny/hub.gif) *Hub* | the Ethernet hub forwards incoming packets to every connected node. |
| ![alt text](../gui/icons/tiny/lanswitch.gif) *Switch* | the Ethernet switch intelligently forwards incoming packets to attached hosts using an Ethernet address hash table. |
| ![alt text](../gui/icons/tiny/wlan.gif) *Wireless LAN* | when routers are connected to this WLAN node, they join a wireless network and an antenna is drawn instead of a connecting line; the WLAN node typically controls connectivity between attached wireless nodes based on the distance between them. |
| ![alt text](../gui/icons/tiny/rj45.gif) *RJ45* | with the RJ45 Physical Interface Tool, emulated nodes can be linked to real physical interfaces; using this tool, real networks and devices can be physically connected to the live-running emulation. |
| ![alt text](../gui/icons/tiny/tunnel.gif) *Tunnel* | the Tunnel Tool allows connecting together more than one CORE emulation using GRE tunnels. |
* *Annotation Tools*
* ![alt text](../gui/icons/tiny/marker.gif) *Marker* - for drawing marks on the canvas
* ![alt text](../gui/icons/tiny/oval.gif) *Oval* - for drawing circles on the canvas that appear in the background
* ![alt text](../gui/icons/tiny/rectangle.gif) *Rectangle* - for drawing rectangles on the canvas that appear in the background
* ![alt text](../gui/icons/tiny/text.gif) *Text* - for placing text captions on the canvas
|||
|---|---|
| ![alt text](../gui/icons/tiny/marker.gif) *Marker* - for drawing marks on the canvas. |
| ![alt text](../gui/icons/tiny/oval.gif) *Oval* - for drawing circles on the canvas that appear in the background. |
| ![alt text](../gui/icons/tiny/rectangle.gif) *Rectangle* - for drawing rectangles on the canvas that appear in the background. |
| ![alt text](../gui/icons/tiny/text.gif) *Text* - for placing text captions on the canvas. |
### Execution Toolbar
@ -259,50 +269,26 @@ The Session Menu has entries for starting, stopping, and managing sessions,
in addition to global options such as node types, comments, hooks, servers,
and options.
* *Start* or *Stop* - this starts or stops the emulation, performing the same
function as the green Start or red Stop button.
* *Change sessions...* - invokes the CORE Sessions dialog box containing a list
of active CORE sessions in the daemon. Basic session information such as
name, node count, start time, and a thumbnail are displayed. This dialog
allows connecting to different sessions, shutting them down, or starting
a new session.
* *Node types...* - invokes the CORE Node Types dialog, performing the same
function as the Edit button on the Network-Layer Nodes toolbar.
* *Comments...* - invokes the CORE Session Comments window where optional
text comments may be specified. These comments are saved at the top of the
configuration file, and can be useful for describing the topology or how
to use the network.
* *Hooks...* - invokes the CORE Session Hooks window where scripts may be
configured for a particular session state. The top of the window has a list
of configured hooks, and buttons on the bottom left allow adding, editing,
and removing hook scripts. The new or edit button will open a hook script
editing window. A hook script is a shell script invoked on the host (not
within a virtual node).
* *definition* - used by the GUI to tell the backend to clear any state.
* *configuration* - when the user presses the *Start* button, node, link, and
other configuration data is sent to the backend. This state is also
reached when the user customizes a service.
* *instantiation* - after configuration data has been sent, just before the nodes are created.
* *runtime* - all nodes and networks have been
built and are running. (This is the same state at which
the previously-named *global experiment script* was run.)
* *datacollect* - the user has pressed the
*Stop* button, but before services have been stopped and nodes have been
shut down. This is a good time to collect log files and other data from the
nodes.
* *shutdown* - all nodes and networks have been shut down and destroyed.
* *Reset node positions* - if you have moved nodes around
using the mouse or by using a mobility module, choosing this item will reset
all nodes to their original position on the canvas. The node locations are
remembered when you first press the Start button.
* *Emulation servers...* - invokes the CORE emulation
servers dialog for configuring.
* *Change Sessions...* - invokes the Sessions dialog for switching between different
running sessions. This dialog is presented during startup when one or
more sessions are already running.
* *Options...* - presents per-session options, such as the IPv4 prefix to be
used, if any, for a control network the ability to preserve
the session directory; and an on/off switch for SDT3D support.
|||
|---|---|
| *Start* or *Stop* | this starts or stops the emulation, performing the same function as the green Start or red Stop button. |
| *Change sessions...* | invokes the CORE Sessions dialog box containing a list of active CORE sessions in the daemon. Basic session information such as name, node count, start time, and a thumbnail are displayed. This dialog allows connecting to different sessions, shutting them down, or starting a new session. |
| *Node types...* | invokes the CORE Node Types dialog, performing the same function as the Edit button on the Network-Layer Nodes toolbar. |
| *Comments...* | invokes the CORE Session Comments window where optional text comments may be specified. These comments are saved at the top of the configuration file, and can be useful for describing the topology or how to use the network. |
| *Hooks...* | invokes the CORE Session Hooks window where scripts may be configured for a particular session state. The session states are defined in the table right below. The top of the window has a list of configured hooks, and buttons on the bottom left allow adding, editing, and removing hook scripts. The new or edit button will open a hook script editing window. A hook script is a shell script invoked on the host (not within a virtual node). |
| *Reset node positions* | if you have moved nodes around using the mouse or by using a mobility module, choosing this item will reset all nodes to their original position on the canvas. The node locations are remembered when you first press the Start button. |
| *Emulation servers...* | invokes the CORE emulation servers dialog for configuring. |
| *Change Sessions...* | invokes the Sessions dialog for switching between different running sessions. This dialog is presented during startup when one or more sessions are already running. |
| *Options...* | presents per-session options, such as the IPv4 prefix to be used, if any, for a control network the ability to preserve the session directory; and an on/off switch for SDT3D support. |
| |Session states|
|---|---|
| *definition* | used by the GUI to tell the backend to clear any state. |
| *configuration* | when the user presses the *Start* button, node, link, and other configuration data is sent to the backend. This state is also reached when the user customizes a service. |
| *instantiation* | after configuration data has been sent, just before the nodes are created. |
| *runtime* | all nodes and networks have been built and are running. (This is the same state at which the previously-named *global experiment script* was run.)
| *datacollect* | the user has pressed the *Stop* button, but before services have been stopped and nodes have been shut down. This is a good time to collect log files and other data from the nodes. |
| *shutdown* | all nodes and networks have been shut down and destroyed. |
### Help Menu