grpc added get emane models, model config, and model configs

This commit is contained in:
bharnden 2019-03-15 21:38:29 -07:00
parent 5753c91906
commit 641427671c
3 changed files with 115 additions and 2 deletions

View file

@ -244,6 +244,25 @@ class CoreApiClient(object):
request.session = session
return self.stub.GetEmaneConfig(request)
def get_emane_models(self, session):
request = core_pb2.GetEmaneModelsRequest()
request.session = session
return self.stub.GetEmaneModels(request)
def get_emane_model_config(self, session, _id, model, interface_id=None):
request = core_pb2.GetEmaneModelConfigRequest()
request.session = session
if interface_id is not None:
_id = _id * 1000 + interface_id
request.id = _id
request.model = model
return self.stub.GetEmaneModelConfig(request)
def get_emane_model_configs(self, session):
request = core_pb2.GetEmaneModelConfigsRequest()
request.session = session
return self.stub.GetEmaneModelConfigs(request)
def save_xml(self, session, file_path):
request = core_pb2.SaveXmlRequest()
request.session = session
@ -285,10 +304,12 @@ def main():
print("default services: %s" % client.get_service_defaults(session_data.id))
print("emane models: {}".format(client.get_emane_models(session_data.id)))
response = client.get_sessions()
print("core client received: %s" % response)
print("emane config: %s" % client.get_emane_config(session_data.id))
print("emane config: {}".format(client.get_emane_config(session_data.id)))
# set session location
response = client.set_session_location(
@ -325,6 +346,8 @@ def main():
node_options.y = 5
print("edit node: %s" % client.edit_node(session_data.id, node_id, node_options))
print("get node: %s" % client.get_node(session_data.id, node_id))
print("emane model config: {}".format(
client.get_emane_model_config(session_data.id, node_id, "emane_tdma")))
print("node service: %s" % client.get_node_service(session_data.id, node_id, "zebra"))

View file

@ -170,7 +170,9 @@ class CoreApiServer(core_pb2_grpc.CoreApiServicer):
session.location.setrefgeo(request.position.lat, request.position.lon, request.position.alt)
session.location.refscale = request.scale
return core_pb2.SetSessionLocationResponse()
response = core_pb2.SetSessionLocationResponse()
response.result = True
return response
def SetSessionState(self, request, context):
response = core_pb2.SetSessionStateResponse()
@ -572,6 +574,57 @@ class CoreApiServer(core_pb2_grpc.CoreApiServicer):
response.groups.extend(groups)
return response
def GetEmaneModels(self, request, context):
session = self.coreemu.sessions.get(request.session)
if not session:
raise Exception("no session found")
models = []
for model in session.emane.models.keys():
if len(model.split("_")) != 2:
continue
models.append(model)
response = core_pb2.GetEmaneModelsResponse()
response.models.extend(models)
return response
def GetEmaneModelConfig(self, request, context):
session = self.coreemu.sessions.get(request.session)
if not session:
raise Exception("no session found")
node = session.get_object(request.id)
if not node:
raise Exception("no node found")
model = session.emane.models[request.model]
config = session.emane.get_model_config(node.objid, request.model)
groups = get_config_groups(config, model)
response = core_pb2.GetEmaneModelConfigResponse()
response.groups.extend(groups)
return response
def GetEmaneModelConfigs(self, request, context):
session = self.coreemu.sessions.get(request.session)
if not session:
raise Exception("no session found")
response = core_pb2.GetEmaneModelConfigsResponse()
for node_id, model_config in session.emane.node_configurations.iteritems():
if node_id == -1:
continue
for model_name in model_config.iterkeys():
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.setdefault(node_id, {})
node_configurations = response.configs[node_id]
node_configurations.model = model_name
node_configurations.groups.extend(config_groups)
# node_configurations[model_name] = config_groups
return response
def SaveXml(self, request, context):
session = self.coreemu.sessions.get(request.session)
if not session:

View file

@ -45,6 +45,12 @@ service CoreApi {
}
rpc GetEmaneConfig (GetEmaneConfigRequest) returns (GetEmaneConfigResponse) {
}
rpc GetEmaneModels (GetEmaneModelsRequest) returns (GetEmaneModelsResponse) {
}
rpc GetEmaneModelConfig (GetEmaneModelConfigRequest) returns (GetEmaneModelConfigResponse) {
}
rpc GetEmaneModelConfigs (GetEmaneModelConfigsRequest) returns (GetEmaneModelConfigsResponse) {
}
rpc SaveXml (SaveXmlRequest) returns (SaveXmlResponse) {
}
rpc OpenXml (OpenXmlRequest) returns (OpenXmlResponse) {
@ -110,6 +116,7 @@ message SetSessionLocationRequest {
}
message SetSessionLocationResponse {
bool result = 1;
}
message SetSessionStateRequest {
@ -253,6 +260,36 @@ message GetEmaneConfigResponse {
repeated ConfigGroup groups = 1;
}
message GetEmaneModelsRequest {
int32 session = 1;
}
message GetEmaneModelsResponse {
repeated string models = 1;
}
message GetEmaneModelConfigRequest {
int32 session = 1;
int32 id = 2;
string model = 3;
}
message GetEmaneModelConfigResponse {
repeated ConfigGroup groups = 1;
}
message GetEmaneModelConfigsRequest {
int32 session = 1;
}
message GetEmaneModelConfigsResponse {
message ModelConfig {
string model = 1;
repeated ConfigGroup groups = 2;
}
map<int32, ModelConfig> configs = 1;
}
message SaveXmlRequest {
int32 session = 1;
}