Merge branch 'develop' into coretk-create-node
This commit is contained in:
commit
b097028a4a
10 changed files with 152 additions and 114 deletions
|
@ -194,7 +194,7 @@ class CoreGrpcClient(object):
|
|||
|
||||
def get_session_options(self, session_id):
|
||||
"""
|
||||
Retrieve session options.
|
||||
Retrieve session options as a dict with id mapping.
|
||||
|
||||
:param int session_id: id of session
|
||||
:return: response with a list of configuration groups
|
||||
|
@ -204,6 +204,18 @@ class CoreGrpcClient(object):
|
|||
request = core_pb2.GetSessionOptionsRequest(session_id=session_id)
|
||||
return self.stub.GetSessionOptions(request)
|
||||
|
||||
def get_session_options_group(self, session_id):
|
||||
"""
|
||||
Retrieve session options in a group list.
|
||||
|
||||
:param int session_id: id of session
|
||||
:return: response with a list of configuration groups
|
||||
:rtype: core_pb2.GetSessionOptionsGroupResponse
|
||||
:raises grpc.RpcError: when session doesn't exist
|
||||
"""
|
||||
request = core_pb2.GetSessionOptionsGroupRequest(session_id=session_id)
|
||||
return self.stub.GetSessionOptionsGroup(request)
|
||||
|
||||
def set_session_options(self, session_id, config):
|
||||
"""
|
||||
Set options for a session.
|
||||
|
@ -868,17 +880,18 @@ class CoreGrpcClient(object):
|
|||
with open(file_path, "w") as xml_file:
|
||||
xml_file.write(response.data)
|
||||
|
||||
def open_xml(self, file_path):
|
||||
def open_xml(self, file_path, start=False):
|
||||
"""
|
||||
Load a local scenario XML file to open as a new session.
|
||||
|
||||
:param str file_path: path of scenario XML file
|
||||
:param bool start: True to start session, False otherwise
|
||||
:return: response with opened session id
|
||||
:rtype: core_pb2.OpenXmlResponse
|
||||
"""
|
||||
with open(file_path, "r") as xml_file:
|
||||
data = xml_file.read()
|
||||
request = core_pb2.OpenXmlRequest(data=data)
|
||||
request = core_pb2.OpenXmlRequest(data=data, start=start, file=file_path)
|
||||
return self.stub.OpenXml(request)
|
||||
|
||||
def emane_link(self, session_id, nem_one, nem_two, linked):
|
||||
|
|
|
@ -46,38 +46,33 @@ def convert_value(value):
|
|||
return value
|
||||
|
||||
|
||||
def get_config_groups(config, configurable_options):
|
||||
def get_config_options(config, configurable_options):
|
||||
"""
|
||||
Retrieve configuration groups in a form that is used by the grpc server
|
||||
Retrieve configuration options in a form that is used by the grpc server.
|
||||
|
||||
:param core.config.Configuration config: configuration
|
||||
:param dict config: configuration
|
||||
:param core.config.ConfigurableOptions configurable_options: configurable options
|
||||
:return: list of configuration groups
|
||||
:rtype: [core.api.grpc.core_pb2.ConfigGroup]
|
||||
:return: mapping of configuration ids to configuration options
|
||||
:rtype: dict[str,core.api.grpc.core_pb2.ConfigOption]
|
||||
"""
|
||||
groups = []
|
||||
config_options = []
|
||||
|
||||
results = {}
|
||||
for configuration in configurable_options.configurations():
|
||||
value = config[configuration.id]
|
||||
config_option = core_pb2.ConfigOption()
|
||||
config_option.label = configuration.label
|
||||
config_option.name = configuration.id
|
||||
config_option.value = value
|
||||
config_option.type = configuration.type.value
|
||||
config_option.select.extend(configuration.options)
|
||||
config_options.append(config_option)
|
||||
|
||||
config_option = core_pb2.ConfigOption(
|
||||
label=configuration.label,
|
||||
name=configuration.id,
|
||||
value=value,
|
||||
type=configuration.type.value,
|
||||
select=configuration.options,
|
||||
)
|
||||
results[configuration.id] = config_option
|
||||
for config_group in configurable_options.config_groups():
|
||||
start = config_group.start - 1
|
||||
stop = config_group.stop
|
||||
options = config_options[start:stop]
|
||||
config_group_proto = core_pb2.ConfigGroup(
|
||||
name=config_group.name, options=options
|
||||
)
|
||||
groups.append(config_group_proto)
|
||||
|
||||
return groups
|
||||
options = list(results.values())[start:stop]
|
||||
for option in options:
|
||||
option.group = config_group.name
|
||||
return results
|
||||
|
||||
|
||||
def get_links(session, node):
|
||||
|
@ -310,7 +305,10 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
|
|||
for session_id in self.coreemu.sessions:
|
||||
session = self.coreemu.sessions[session_id]
|
||||
session_summary = core_pb2.SessionSummary(
|
||||
id=session_id, state=session.state, nodes=session.get_node_count()
|
||||
id=session_id,
|
||||
state=session.state,
|
||||
nodes=session.get_node_count(),
|
||||
file=session.file_name,
|
||||
)
|
||||
sessions.append(session_summary)
|
||||
return core_pb2.GetSessionsResponse(sessions=sessions)
|
||||
|
@ -390,20 +388,21 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
|
|||
|
||||
def GetSessionOptions(self, request, context):
|
||||
"""
|
||||
Retrieve session options
|
||||
Retrieve session options.
|
||||
|
||||
:param core.api.grpc.core_pb2.GetSessionOptions request: get-session-options request
|
||||
:param core.api.grpc.core_pb2.GetSessionOptions request:
|
||||
get-session-options request
|
||||
:param grpc.ServicerContext context: context object
|
||||
:return: get-session-options response about all session's options
|
||||
:rtype: core.api.grpc.core_pb2.GetSessionOptions
|
||||
"""
|
||||
logging.debug("get session options: %s", request)
|
||||
session = self.get_session(request.session_id, context)
|
||||
config = session.options.get_configs()
|
||||
defaults = session.options.default_values()
|
||||
defaults.update(config)
|
||||
groups = get_config_groups(defaults, session.options)
|
||||
return core_pb2.GetSessionOptionsResponse(groups=groups)
|
||||
current_config = session.options.get_configs()
|
||||
default_config = session.options.default_values()
|
||||
default_config.update(current_config)
|
||||
config = get_config_options(default_config, session.options)
|
||||
return core_pb2.GetSessionOptionsResponse(config=config)
|
||||
|
||||
def SetSessionOptions(self, request, context):
|
||||
"""
|
||||
|
@ -1115,7 +1114,8 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
|
|||
"""
|
||||
Retrieve all mobility configurations from a session
|
||||
|
||||
:param core.api.grpc.core_pb2.GetMobilityConfigsRequest request: get-mobility-configurations request
|
||||
: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
|
||||
|
@ -1130,33 +1130,36 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
|
|||
for model_name in model_config:
|
||||
if model_name != Ns2ScriptedMobility.name:
|
||||
continue
|
||||
config = session.mobility.get_model_config(node_id, model_name)
|
||||
groups = get_config_groups(config, Ns2ScriptedMobility)
|
||||
response.configs[node_id].groups.extend(groups)
|
||||
current_config = session.mobility.get_model_config(node_id, model_name)
|
||||
config = get_config_options(current_config, Ns2ScriptedMobility)
|
||||
mapped_config = core_pb2.MappedConfig(config=config)
|
||||
response.configs[node_id].CopyFrom(mapped_config)
|
||||
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 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(
|
||||
current_config = session.mobility.get_model_config(
|
||||
request.node_id, Ns2ScriptedMobility.name
|
||||
)
|
||||
groups = get_config_groups(config, Ns2ScriptedMobility)
|
||||
return core_pb2.GetMobilityConfigResponse(groups=groups)
|
||||
config = get_config_options(current_config, Ns2ScriptedMobility)
|
||||
return core_pb2.GetMobilityConfigResponse(config=config)
|
||||
|
||||
def SetMobilityConfig(self, request, context):
|
||||
"""
|
||||
Set mobility configuration of a node
|
||||
|
||||
:param core.api.grpc.core_pb2.SetMobilityConfigRequest request: set-mobility-configuration request
|
||||
: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
|
||||
|
@ -1172,7 +1175,8 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
|
|||
"""
|
||||
Take mobility action whether to start, pause, stop or none of those
|
||||
|
||||
:param core.api.grpc.core_pb2.MobilityActionRequest request: mobility-action request
|
||||
: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
|
||||
|
@ -1212,7 +1216,8 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
|
|||
"""
|
||||
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 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
|
||||
|
@ -1231,7 +1236,8 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
|
|||
def SetServiceDefaults(self, request, context):
|
||||
"""
|
||||
Set new default services to the session after whipping out the old ones
|
||||
:param core.api.grpc.core_pb2.SetServiceDefaults request: set-service-defaults request
|
||||
:param core.api.grpc.core_pb2.SetServiceDefaults request: set-service-defaults
|
||||
request
|
||||
:param grpc.ServicerContext context: context object
|
||||
:return: set-service-defaults response
|
||||
:rtype: core.api.grpc.core_pb2 SetServiceDefaultsResponse
|
||||
|
@ -1249,7 +1255,8 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
|
|||
"""
|
||||
Retrieve a requested service from a node
|
||||
|
||||
:param core.api.grpc.core_pb2.GetNodeServiceRequest request: get-node-service request
|
||||
: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
|
||||
|
@ -1277,7 +1284,8 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
|
|||
"""
|
||||
Retrieve a requested service file from a node
|
||||
|
||||
:param core.api.grpc.core_pb2.GetNodeServiceFileRequest request: get-node-service request
|
||||
: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
|
||||
|
@ -1301,8 +1309,8 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
|
|||
"""
|
||||
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 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
|
||||
|
@ -1320,7 +1328,8 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
|
|||
"""
|
||||
Store the customized service file in the service config
|
||||
|
||||
:param core.api.grpc.core_pb2.SetNodeServiceFileRequest request: set-node-service-file request
|
||||
: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
|
||||
|
@ -1382,11 +1391,11 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
|
|||
"""
|
||||
logging.debug("get wlan config: %s", request)
|
||||
session = self.get_session(request.session_id, context)
|
||||
config = session.mobility.get_model_config(
|
||||
current_config = session.mobility.get_model_config(
|
||||
request.node_id, BasicRangeModel.name
|
||||
)
|
||||
groups = get_config_groups(config, BasicRangeModel)
|
||||
return core_pb2.GetWlanConfigResponse(groups=groups)
|
||||
config = get_config_options(current_config, BasicRangeModel)
|
||||
return core_pb2.GetWlanConfigResponse(config=config)
|
||||
|
||||
def SetWlanConfig(self, request, context):
|
||||
"""
|
||||
|
@ -1418,9 +1427,9 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
|
|||
"""
|
||||
logging.debug("get emane config: %s", request)
|
||||
session = self.get_session(request.session_id, context)
|
||||
config = session.emane.get_configs()
|
||||
groups = get_config_groups(config, session.emane.emane_config)
|
||||
return core_pb2.GetEmaneConfigResponse(groups=groups)
|
||||
current_config = session.emane.get_configs()
|
||||
config = get_config_options(current_config, session.emane.emane_config)
|
||||
return core_pb2.GetEmaneConfigResponse(config=config)
|
||||
|
||||
def SetEmaneConfig(self, request, context):
|
||||
"""
|
||||
|
@ -1459,7 +1468,8 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
|
|||
"""
|
||||
Retrieve EMANE model configuration of a node
|
||||
|
||||
:param core.api.grpc.core_pb2.GetEmaneModelConfigRequest request: get-EMANE-model-configuration request
|
||||
:param core.api.grpc.core_pb2.GetEmaneModelConfigRequest request:
|
||||
get-EMANE-model-configuration request
|
||||
:param grpc.ServicerContext context: context object
|
||||
:return: get-EMANE-model-configuration response
|
||||
:rtype: core.api.grpc.core_pb2.GetEmaneModelConfigResponse
|
||||
|
@ -1468,15 +1478,16 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
|
|||
session = self.get_session(request.session_id, context)
|
||||
model = session.emane.models[request.model]
|
||||
_id = get_emane_model_id(request.node_id, request.interface)
|
||||
config = session.emane.get_model_config(_id, request.model)
|
||||
groups = get_config_groups(config, model)
|
||||
return core_pb2.GetEmaneModelConfigResponse(groups=groups)
|
||||
current_config = session.emane.get_model_config(_id, request.model)
|
||||
config = get_config_options(current_config, model)
|
||||
return core_pb2.GetEmaneModelConfigResponse(config=config)
|
||||
|
||||
def SetEmaneModelConfig(self, request, context):
|
||||
"""
|
||||
Set EMANE model configuration of a node
|
||||
|
||||
:param core.api.grpc.core_pb2.SetEmaneModelConfigRequest request: set-EMANE-model-configuration request
|
||||
:param core.api.grpc.core_pb2.SetEmaneModelConfigRequest request:
|
||||
set-EMANE-model-configuration request
|
||||
:param grpc.ServicerContext context: context object
|
||||
:return: set-EMANE-model-configuration response
|
||||
:rtype: core.api.grpc.core_pb2.SetEmaneModelConfigResponse
|
||||
|
@ -1491,9 +1502,11 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
|
|||
"""
|
||||
Retrieve all EMANE model configurations of a session
|
||||
|
||||
:param core.api.grpc.core_pb2.GetEmaneModelConfigsRequest request: get-EMANE-model-configurations request
|
||||
:param core.api.grpc.core_pb2.GetEmaneModelConfigsRequest request:
|
||||
get-EMANE-model-configurations request
|
||||
:param grpc.ServicerContext context: context object
|
||||
:return: get-EMANE-model-configurations response that has all the EMANE configurations
|
||||
:return: get-EMANE-model-configurations response that has all the EMANE
|
||||
configurations
|
||||
:rtype: core.api.grpc.core_pb2.GetEmaneModelConfigsResponse
|
||||
"""
|
||||
logging.debug("get emane model configs: %s", request)
|
||||
|
@ -1506,11 +1519,12 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
|
|||
|
||||
for model_name in model_config:
|
||||
model = session.emane.models[model_name]
|
||||
config = session.emane.get_model_config(node_id, model_name)
|
||||
config_groups = get_config_groups(config, model)
|
||||
node_configurations = response.configs[node_id]
|
||||
node_configurations.model = model_name
|
||||
node_configurations.groups.extend(config_groups)
|
||||
current_config = session.emane.get_model_config(node_id, model_name)
|
||||
config = get_config_options(current_config, model)
|
||||
model_config = core_pb2.GetEmaneModelConfigsResponse.ModelConfig(
|
||||
model=model_name, config=config
|
||||
)
|
||||
response.configs[node_id].CopyFrom(model_config)
|
||||
return response
|
||||
|
||||
def SaveXml(self, request, context):
|
||||
|
@ -1544,19 +1558,22 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
|
|||
"""
|
||||
logging.debug("open xml: %s", request)
|
||||
session = self.coreemu.create_session()
|
||||
session.set_state(EventTypes.CONFIGURATION_STATE)
|
||||
|
||||
_, temp_path = tempfile.mkstemp()
|
||||
with open(temp_path, "w") as xml_file:
|
||||
xml_file.write(request.data)
|
||||
temp = tempfile.NamedTemporaryFile(delete=False)
|
||||
temp.write(request.data.encode("utf-8"))
|
||||
temp.close()
|
||||
|
||||
try:
|
||||
session.open_xml(temp_path, start=True)
|
||||
session.open_xml(temp.name, request.start)
|
||||
session.name = os.path.basename(request.file)
|
||||
session.file_name = request.file
|
||||
return core_pb2.OpenXmlResponse(session_id=session.id, result=True)
|
||||
except IOError:
|
||||
logging.exception("error opening session file")
|
||||
self.coreemu.delete_session(session.id)
|
||||
context.abort(grpc.StatusCode.INVALID_ARGUMENT, "invalid xml file")
|
||||
finally:
|
||||
os.unlink(temp.name)
|
||||
|
||||
def GetInterfaces(self, request, context):
|
||||
"""
|
||||
|
|
|
@ -944,7 +944,7 @@ class CoreHandler(socketserver.BaseRequestHandler):
|
|||
if os.path.splitext(file_name)[1].lower() == ".xml":
|
||||
session = self.coreemu.create_session(master=False)
|
||||
try:
|
||||
session.open_xml(file_name, start=True)
|
||||
session.open_xml(file_name)
|
||||
except Exception:
|
||||
self.coreemu.delete_session(session.id)
|
||||
raise
|
||||
|
|
|
@ -18,6 +18,7 @@ from core.nodes.ipaddress import IpAddress
|
|||
from core.nodes.network import CoreNetwork, CtrlNet
|
||||
|
||||
LOCK = threading.Lock()
|
||||
CMD_HIDE = True
|
||||
|
||||
|
||||
class DistributedServer(object):
|
||||
|
@ -54,18 +55,18 @@ class DistributedServer(object):
|
|||
replace_env = env is not None
|
||||
if not wait:
|
||||
cmd += " &"
|
||||
logging.info(
|
||||
logging.debug(
|
||||
"remote cmd server(%s) cwd(%s) wait(%s): %s", self.host, cwd, wait, cmd
|
||||
)
|
||||
try:
|
||||
if cwd is None:
|
||||
result = self.conn.run(
|
||||
cmd, hide=False, env=env, replace_env=replace_env
|
||||
cmd, hide=CMD_HIDE, env=env, replace_env=replace_env
|
||||
)
|
||||
else:
|
||||
with self.conn.cd(cwd):
|
||||
result = self.conn.run(
|
||||
cmd, hide=False, env=env, replace_env=replace_env
|
||||
cmd, hide=CMD_HIDE, env=env, replace_env=replace_env
|
||||
)
|
||||
return result.stdout.strip()
|
||||
except UnexpectedExit as e:
|
||||
|
|
|
@ -634,19 +634,23 @@ class Session(object):
|
|||
if node_two:
|
||||
node_two.lock.release()
|
||||
|
||||
def add_node(self, _type=NodeTypes.DEFAULT, _id=None, node_options=None):
|
||||
def add_node(self, _type=NodeTypes.DEFAULT, _id=None, node_options=None, _cls=None):
|
||||
"""
|
||||
Add a node to the session, based on the provided node data.
|
||||
|
||||
:param core.emulator.enumerations.NodeTypes _type: type of node to create
|
||||
:param int _id: id for node, defaults to None for generated id
|
||||
:param core.emulator.emudata.NodeOptions node_options: data to create node with
|
||||
:param class _cls: optional custom class to use for a created node
|
||||
:return: created node
|
||||
:raises core.CoreError: when an invalid node type is given
|
||||
"""
|
||||
|
||||
# validate node type, get class, or throw error
|
||||
node_class = self.get_node_class(_type)
|
||||
if _cls is None:
|
||||
node_class = self.get_node_class(_type)
|
||||
else:
|
||||
node_class = _cls
|
||||
|
||||
# set node start based on current session state, override and check when rj45
|
||||
start = self.state > EventTypes.DEFINITION_STATE.value
|
||||
|
@ -705,13 +709,8 @@ class Session(object):
|
|||
# set node position and broadcast it
|
||||
self.set_node_position(node, node_options)
|
||||
|
||||
# add services to default and physical nodes only
|
||||
if _type in [
|
||||
NodeTypes.DEFAULT,
|
||||
NodeTypes.PHYSICAL,
|
||||
NodeTypes.DOCKER,
|
||||
NodeTypes.LXC,
|
||||
]:
|
||||
# add services to needed nodes
|
||||
if isinstance(node, (CoreNode, PhysicalNode, DockerNode, LxcNode)):
|
||||
node.type = node_options.model
|
||||
logging.debug("set node type: %s", node.type)
|
||||
self.services.add_services(node, node.type, node_options.services)
|
||||
|
@ -820,19 +819,24 @@ class Session(object):
|
|||
:param bool start: instantiate session if true, false otherwise
|
||||
:return: nothing
|
||||
"""
|
||||
logging.info("opening xml: %s", file_name)
|
||||
|
||||
# clear out existing session
|
||||
self.clear()
|
||||
|
||||
if start:
|
||||
self.set_state(EventTypes.CONFIGURATION_STATE)
|
||||
state = EventTypes.CONFIGURATION_STATE
|
||||
else:
|
||||
state = EventTypes.DEFINITION_STATE
|
||||
self.set_state(state)
|
||||
self.name = os.path.basename(file_name)
|
||||
self.file_name = file_name
|
||||
|
||||
# write out xml file
|
||||
CoreXmlReader(self).read(file_name)
|
||||
|
||||
# start session if needed
|
||||
if start:
|
||||
self.name = os.path.basename(file_name)
|
||||
self.file_name = file_name
|
||||
self.instantiate()
|
||||
|
||||
def save_xml(self, file_name):
|
||||
|
|
|
@ -284,7 +284,7 @@ class CoreNetwork(CoreNetworkBase):
|
|||
:rtype: str
|
||||
:raises CoreCommandError: when a non-zero exit status occurs
|
||||
"""
|
||||
logging.info("network node(%s) cmd", self.name)
|
||||
logging.debug("network node(%s) cmd", self.name)
|
||||
output = utils.cmd(args, env, cwd, wait, shell)
|
||||
self.session.distributed.execute(lambda x: x.remote_cmd(args, env, cwd, wait))
|
||||
return output
|
||||
|
|
|
@ -206,7 +206,7 @@ def cmd(args, env=None, cwd=None, wait=True, shell=False):
|
|||
:raises CoreCommandError: when there is a non-zero exit status or the file to
|
||||
execute is not found
|
||||
"""
|
||||
logging.info("command cwd(%s) wait(%s): %s", cwd, wait, args)
|
||||
logging.debug("command cwd(%s) wait(%s): %s", cwd, wait, args)
|
||||
if shell is False:
|
||||
args = shlex.split(args)
|
||||
try:
|
||||
|
|
|
@ -304,10 +304,8 @@ class CoreXmlWriter(object):
|
|||
default_options = self.session.options.default_values()
|
||||
for _id in default_options:
|
||||
default_value = default_options[_id]
|
||||
# TODO: should we just save the current config regardless, since it may change?
|
||||
value = options_config[_id]
|
||||
if value != default_value:
|
||||
add_configuration(option_elements, _id, value)
|
||||
value = options_config.get(_id, default_value)
|
||||
add_configuration(option_elements, _id, value)
|
||||
|
||||
if option_elements.getchildren():
|
||||
self.scenario.append(option_elements)
|
||||
|
|
|
@ -163,7 +163,7 @@ message GetSessionOptionsRequest {
|
|||
}
|
||||
|
||||
message GetSessionOptionsResponse {
|
||||
repeated ConfigGroup groups = 1;
|
||||
map<string, ConfigOption> config = 2;
|
||||
}
|
||||
|
||||
message SetSessionOptionsRequest {
|
||||
|
@ -428,10 +428,7 @@ message GetMobilityConfigsRequest {
|
|||
}
|
||||
|
||||
message GetMobilityConfigsResponse {
|
||||
message MobilityConfig {
|
||||
repeated ConfigGroup groups = 1;
|
||||
}
|
||||
map<int32, MobilityConfig> configs = 1;
|
||||
map<int32, MappedConfig> configs = 1;
|
||||
}
|
||||
|
||||
message GetMobilityConfigRequest {
|
||||
|
@ -440,7 +437,7 @@ message GetMobilityConfigRequest {
|
|||
}
|
||||
|
||||
message GetMobilityConfigResponse {
|
||||
repeated ConfigGroup groups = 1;
|
||||
map<string, ConfigOption> config = 1;
|
||||
}
|
||||
|
||||
message SetMobilityConfigRequest {
|
||||
|
@ -551,7 +548,7 @@ message GetWlanConfigRequest {
|
|||
}
|
||||
|
||||
message GetWlanConfigResponse {
|
||||
repeated ConfigGroup groups = 1;
|
||||
map<string, ConfigOption> config = 1;
|
||||
}
|
||||
|
||||
message SetWlanConfigRequest {
|
||||
|
@ -569,7 +566,7 @@ message GetEmaneConfigRequest {
|
|||
}
|
||||
|
||||
message GetEmaneConfigResponse {
|
||||
repeated ConfigGroup groups = 1;
|
||||
map<string, ConfigOption> config = 1;
|
||||
}
|
||||
|
||||
message SetEmaneConfigRequest {
|
||||
|
@ -597,7 +594,7 @@ message GetEmaneModelConfigRequest {
|
|||
}
|
||||
|
||||
message GetEmaneModelConfigResponse {
|
||||
repeated ConfigGroup groups = 1;
|
||||
map<string, ConfigOption> config = 1;
|
||||
}
|
||||
|
||||
message SetEmaneModelConfigRequest {
|
||||
|
@ -619,7 +616,7 @@ message GetEmaneModelConfigsRequest {
|
|||
message GetEmaneModelConfigsResponse {
|
||||
message ModelConfig {
|
||||
string model = 1;
|
||||
repeated ConfigGroup groups = 2;
|
||||
map<string, ConfigOption> config = 2;
|
||||
}
|
||||
map<int32, ModelConfig> configs = 1;
|
||||
}
|
||||
|
@ -634,6 +631,8 @@ message SaveXmlResponse {
|
|||
|
||||
message OpenXmlRequest {
|
||||
string data = 1;
|
||||
bool start = 2;
|
||||
string file = 3;
|
||||
}
|
||||
|
||||
message OpenXmlResponse {
|
||||
|
@ -777,9 +776,8 @@ message NodeServiceData {
|
|||
string meta = 10;
|
||||
}
|
||||
|
||||
message ConfigGroup {
|
||||
string name = 1;
|
||||
repeated ConfigOption options = 2;
|
||||
message MappedConfig {
|
||||
map<string, ConfigOption> config = 1;
|
||||
}
|
||||
|
||||
message ConfigOption {
|
||||
|
@ -788,6 +786,7 @@ message ConfigOption {
|
|||
string value = 3;
|
||||
int32 type = 4;
|
||||
repeated string select = 5;
|
||||
string group = 6;
|
||||
}
|
||||
|
||||
message Session {
|
||||
|
@ -801,6 +800,7 @@ message SessionSummary {
|
|||
int32 id = 1;
|
||||
SessionState.Enum state = 2;
|
||||
int32 nodes = 3;
|
||||
string file = 4;
|
||||
}
|
||||
|
||||
message Node {
|
||||
|
|
|
@ -100,7 +100,7 @@ class TestGrpc:
|
|||
response = client.get_session_options(session.id)
|
||||
|
||||
# then
|
||||
assert len(response.groups) > 0
|
||||
assert len(response.config) > 0
|
||||
|
||||
def test_get_session_location(self, grpc_server):
|
||||
# given
|
||||
|
@ -457,7 +457,7 @@ class TestGrpc:
|
|||
response = client.get_wlan_config(session.id, wlan.id)
|
||||
|
||||
# then
|
||||
assert len(response.groups) > 0
|
||||
assert len(response.config) > 0
|
||||
|
||||
def test_set_wlan_config(self, grpc_server):
|
||||
# given
|
||||
|
@ -501,7 +501,7 @@ class TestGrpc:
|
|||
response = client.get_emane_config(session.id)
|
||||
|
||||
# then
|
||||
assert len(response.groups) > 0
|
||||
assert len(response.config) > 0
|
||||
|
||||
def test_set_emane_config(self, grpc_server):
|
||||
# given
|
||||
|
@ -540,6 +540,9 @@ class TestGrpc:
|
|||
# then
|
||||
assert len(response.configs) == 1
|
||||
assert emane_network.id in response.configs
|
||||
model_config = response.configs[emane_network.id]
|
||||
assert model_config.model == EmaneIeee80211abgModel.name
|
||||
assert len(model_config.config) > 0
|
||||
|
||||
def test_set_emane_model_config(self, grpc_server):
|
||||
# given
|
||||
|
@ -582,7 +585,7 @@ class TestGrpc:
|
|||
)
|
||||
|
||||
# then
|
||||
assert len(response.groups) > 0
|
||||
assert len(response.config) > 0
|
||||
|
||||
def test_get_emane_models(self, grpc_server):
|
||||
# given
|
||||
|
@ -610,6 +613,8 @@ class TestGrpc:
|
|||
# then
|
||||
assert len(response.configs) > 0
|
||||
assert wlan.id in response.configs
|
||||
mapped_config = response.configs[wlan.id]
|
||||
assert len(mapped_config.config) > 0
|
||||
|
||||
def test_get_mobility_config(self, grpc_server):
|
||||
# given
|
||||
|
@ -623,7 +628,7 @@ class TestGrpc:
|
|||
response = client.get_mobility_config(session.id, wlan.id)
|
||||
|
||||
# then
|
||||
assert len(response.groups) > 0
|
||||
assert len(response.config) > 0
|
||||
|
||||
def test_set_mobility_config(self, grpc_server):
|
||||
# given
|
||||
|
|
Loading…
Reference in a new issue