fixed tlv api changing wlan config during runtime, fixed for grpc as well and added grpc test

This commit is contained in:
Blake Harnden 2019-06-11 13:11:36 -07:00
parent 5b1c9a6e68
commit 38c58d9603
4 changed files with 26 additions and 5 deletions

View file

@ -854,7 +854,10 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
def SetWlanConfig(self, request, context):
logging.debug("set wlan config: %s", request)
session = self.get_session(request.session_id, context)
session.mobility.set_model_config(request.node_id, BasicRangeModel.name, request.config)
node = self.get_node(session, request.node_id, context)
session.mobility.set_model_config(node.id, BasicRangeModel.name, request.config)
if session.state == EventTypes.RUNTIME_STATE.value:
node.updatemodel(request.config)
return core_pb2.SetWlanConfigResponse(result=True)
def GetEmaneConfig(self, request, context):

View file

@ -40,6 +40,7 @@ from core.emulator.enumerations import NodeTlvs
from core.emulator.enumerations import NodeTypes
from core.emulator.enumerations import RegisterTlvs
from core.emulator.enumerations import SessionTlvs
from core.location.mobility import BasicRangeModel
from core.nodes import nodeutils
from core.services.coreservices import ServiceManager
from core.services.coreservices import ServiceShim
@ -1268,6 +1269,12 @@ class CoreHandler(socketserver.BaseRequestHandler):
parsed_config = ConfigShim.str_to_dict(values_str)
self.session.mobility.set_model_config(node_id, object_name, parsed_config)
if self.session.state == EventTypes.RUNTIME_STATE.value and object_name == BasicRangeModel.name:
try:
node = self.session.get_node(node_id)
node.updatemodel(parsed_config)
except KeyError:
logging.error("skipping mobility configuration for unknown node: %s", node_id)
return replies

View file

@ -1039,14 +1039,14 @@ class WlanNode(CoreNetwork):
if not self.model:
raise ValueError("no model set to update for node(%s)", self.id)
logging.info("node(%s) updating model(%s): %s", self.id, self.model.name, config)
self.model.set_configs(config, node_id=self.id)
self.model.update_config(config)
if self.model.position_callback:
for netif in self.netifs():
netif.poshook = self.model.position_callback
if netif.node is not None:
x, y, z = netif.node.position.get()
netif.poshook(netif, x, y, z)
self.model.updateconfig()
self.model.setlinkparams()
def all_link_data(self, flags):
"""

View file

@ -458,18 +458,29 @@ class TestGrpc:
# given
client = CoreGrpcClient()
session = grpc_server.coreemu.create_session()
session.set_state(EventTypes.CONFIGURATION_STATE)
wlan = session.add_node(_type=NodeTypes.WIRELESS_LAN)
wlan.setmodel(BasicRangeModel, BasicRangeModel.default_values())
session.instantiate()
range_key = "range"
range_value = "300"
range_value = "50"
# then
with client.context_connect():
response = client.set_wlan_config(session.id, wlan.id, {range_key: range_value})
response = client.set_wlan_config(session.id, wlan.id, {
range_key: range_value,
"delay": "0",
"loss": "0",
"bandwidth": "50000",
"error": "0",
"jitter": "0"
})
# then
assert response.result is True
config = session.mobility.get_model_config(wlan.id, BasicRangeModel.name)
assert config[range_key] == range_value
assert wlan.model.range == int(range_value)
def test_get_emane_config(self, grpc_server):
# given