changes to grpc get emane model configs to return the interface value and actual node id, instead of coded value that would need to be parsed

This commit is contained in:
Blake Harnden 2019-12-13 14:03:41 -08:00
parent 9b16f272b8
commit 9ada94107e
4 changed files with 27 additions and 11 deletions

View file

@ -228,13 +228,11 @@ class CoreClient:
# get emane model config
response = self.client.get_emane_model_configs(self.session_id)
for _id in response.configs:
config = response.configs[_id]
for node_id in response.configs:
config = response.configs[node_id]
interface = None
node_id = _id
if _id >= 1000:
interface = _id % 1000
node_id = int(_id / 1000)
if config.interface != -1:
interface = config.interface
self.set_emane_model_config(
node_id, config.model, config.config, interface
)

View file

@ -221,6 +221,22 @@ def get_emane_model_id(node_id, interface_id):
return node_id
def parse_emane_model_id(_id):
"""
Parses EMANE model id to get true node id and interface id.
:param _id: id to parse
:return: node id and interface id
:rtype: tuple
"""
interface = -1
node_id = _id
if _id >= 1000:
interface = _id % 1000
node_id = int(_id / 1000)
return node_id, interface
def convert_link(session, link_data):
"""
Convert link_data into core protobuf Link

View file

@ -1395,17 +1395,18 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
logging.debug("get emane model configs: %s", request)
session = self.get_session(request.session_id, context)
response = core_pb2.GetEmaneModelConfigsResponse()
for node_id in session.emane.node_configurations:
model_config = session.emane.node_configurations[node_id]
if node_id == -1:
for _id in session.emane.node_configurations:
if _id == -1:
continue
model_config = session.emane.node_configurations[_id]
for model_name in model_config:
model = session.emane.models[model_name]
current_config = session.emane.get_model_config(node_id, model_name)
current_config = session.emane.get_model_config(_id, model_name)
config = get_config_options(current_config, model)
node_id, interface = grpcutils.parse_emane_model_id(_id)
model_config = core_pb2.GetEmaneModelConfigsResponse.ModelConfig(
model=model_name, config=config
model=model_name, config=config, interface=interface
)
response.configs[node_id].CopyFrom(model_config)
return response

View file

@ -666,6 +666,7 @@ message GetEmaneModelConfigsResponse {
message ModelConfig {
string model = 1;
map<string, ConfigOption> config = 2;
int32 interface = 3;
}
map<int32, ModelConfig> configs = 1;
}