added emane model configs and mobility configs to grpc.StartSession
This commit is contained in:
parent
adbab066c9
commit
c0516255f2
4 changed files with 104 additions and 21 deletions
|
@ -156,7 +156,9 @@ class CoreGrpcClient:
|
|||
location=None,
|
||||
hooks=None,
|
||||
emane_config=None,
|
||||
emane_model_configs=None,
|
||||
wlan_configs=None,
|
||||
mobility_configs=None,
|
||||
):
|
||||
"""
|
||||
Start a session.
|
||||
|
@ -167,8 +169,11 @@ class CoreGrpcClient:
|
|||
:param core_pb2.SessionLocation location: location to set
|
||||
:param list[core_pb2.Hook] hooks: session hooks to set
|
||||
:param dict emane_config: emane configuration to set
|
||||
:param list emane_model_configs: emane model configurations to set
|
||||
:param list wlan_configs: wlan configurations to set
|
||||
:return:
|
||||
:param list mobility_configs: mobility configurations to set
|
||||
:return: start session response
|
||||
:rtype: core_pb2.StartSessionResponse
|
||||
"""
|
||||
request = core_pb2.StartSessionRequest(
|
||||
session_id=session_id,
|
||||
|
@ -177,7 +182,9 @@ class CoreGrpcClient:
|
|||
location=location,
|
||||
hooks=hooks,
|
||||
emane_config=emane_config,
|
||||
emane_model_configs=emane_model_configs,
|
||||
wlan_configs=wlan_configs,
|
||||
mobility_configs=mobility_configs,
|
||||
)
|
||||
return self.stub.StartSession(request)
|
||||
|
||||
|
@ -621,8 +628,9 @@ class CoreGrpcClient:
|
|||
:rtype: core_pb2.SetMobilityConfigResponse
|
||||
:raises grpc.RpcError: when session or node doesn't exist
|
||||
"""
|
||||
mobility_config = core_pb2.MobilityConfig(node_id=node_id, config=config)
|
||||
request = core_pb2.SetMobilityConfigRequest(
|
||||
session_id=session_id, node_id=node_id, config=config
|
||||
session_id=session_id, mobility_config=mobility_config
|
||||
)
|
||||
return self.stub.SetMobilityConfig(request)
|
||||
|
||||
|
@ -881,12 +889,11 @@ class CoreGrpcClient:
|
|||
:rtype: core_pb2.SetEmaneModelConfigResponse
|
||||
:raises grpc.RpcError: when session doesn't exist
|
||||
"""
|
||||
model_config = core_pb2.EmaneModelConfig(
|
||||
node_id=node_id, model=model, config=config, interface_id=interface_id
|
||||
)
|
||||
request = core_pb2.SetEmaneModelConfigRequest(
|
||||
session_id=session_id,
|
||||
node_id=node_id,
|
||||
model=model,
|
||||
config=config,
|
||||
interface_id=interface_id,
|
||||
session_id=session_id, emane_model_config=model_config
|
||||
)
|
||||
return self.stub.SetEmaneModelConfig(request)
|
||||
|
||||
|
|
|
@ -81,7 +81,8 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
|
|||
|
||||
:param int session_id: session id
|
||||
:param grpc.ServicerContext context:
|
||||
:return: session object that satisfies. If session not found then raise an exception.
|
||||
: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)
|
||||
|
@ -136,14 +137,21 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
|
|||
# emane configs
|
||||
config = session.emane.get_configs()
|
||||
config.update(request.emane_config)
|
||||
for config in request.emane_model_configs:
|
||||
_id = get_emane_model_id(config.node_id, config.interface_id)
|
||||
session.emane.set_model_config(_id, config.model, config.config)
|
||||
|
||||
# wlan configs
|
||||
for wlan_config in request.wlan_configs:
|
||||
for config in request.wlan_configs:
|
||||
session.mobility.set_model_config(
|
||||
wlan_config.node_id, BasicRangeModel.name, wlan_config.config
|
||||
config.node_id, BasicRangeModel.name, config.config
|
||||
)
|
||||
|
||||
# mobility configs
|
||||
for config in request.mobility_configs:
|
||||
session.mobility.set_model_config(
|
||||
config.node_id, Ns2ScriptedMobility.name, config.config
|
||||
)
|
||||
|
||||
# create links
|
||||
grpcutils.create_links(session, request.links)
|
||||
|
@ -984,8 +992,9 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
|
|||
"""
|
||||
logging.debug("set mobility config: %s", request)
|
||||
session = self.get_session(request.session_id, context)
|
||||
mobility_config = request.mobility_config
|
||||
session.mobility.set_model_config(
|
||||
request.node_id, Ns2ScriptedMobility.name, request.config
|
||||
mobility_config.node_id, Ns2ScriptedMobility.name, mobility_config.config
|
||||
)
|
||||
return core_pb2.SetMobilityConfigResponse(result=True)
|
||||
|
||||
|
@ -1313,8 +1322,9 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
|
|||
"""
|
||||
logging.debug("set emane model config: %s", request)
|
||||
session = self.get_session(request.session_id, context)
|
||||
_id = get_emane_model_id(request.node_id, request.interface_id)
|
||||
session.emane.set_model_config(_id, request.model, request.config)
|
||||
model_config = request.emane_model_config
|
||||
_id = get_emane_model_id(model_config.node_id, model_config.interface_id)
|
||||
session.emane.set_model_config(_id, model_config.model, model_config.config)
|
||||
return core_pb2.SetEmaneModelConfigResponse(result=True)
|
||||
|
||||
def GetEmaneModelConfigs(self, request, context):
|
||||
|
|
|
@ -138,6 +138,8 @@ message StartSessionRequest {
|
|||
SessionLocation location = 5;
|
||||
map<string, string> emane_config = 6;
|
||||
repeated WlanConfig wlan_configs = 7;
|
||||
repeated EmaneModelConfig emane_model_configs = 8;
|
||||
repeated MobilityConfig mobility_configs = 9;
|
||||
}
|
||||
|
||||
message StartSessionResponse {
|
||||
|
@ -466,8 +468,7 @@ message GetMobilityConfigResponse {
|
|||
|
||||
message SetMobilityConfigRequest {
|
||||
int32 session_id = 1;
|
||||
int32 node_id = 2;
|
||||
map<string, string> config = 3;
|
||||
MobilityConfig mobility_config = 2;
|
||||
}
|
||||
|
||||
message SetMobilityConfigResponse {
|
||||
|
@ -622,10 +623,7 @@ message GetEmaneModelConfigResponse {
|
|||
|
||||
message SetEmaneModelConfigRequest {
|
||||
int32 session_id = 1;
|
||||
int32 node_id = 2;
|
||||
int32 interface_id = 3;
|
||||
string model = 4;
|
||||
map<string, string> config = 5;
|
||||
EmaneModelConfig emane_model_config = 2;
|
||||
}
|
||||
|
||||
message SetEmaneModelConfigResponse {
|
||||
|
@ -687,6 +685,18 @@ message WlanConfig {
|
|||
map<string, string> config = 2;
|
||||
}
|
||||
|
||||
message MobilityConfig {
|
||||
int32 node_id = 1;
|
||||
map<string, string> config = 2;
|
||||
}
|
||||
|
||||
message EmaneModelConfig {
|
||||
int32 node_id = 1;
|
||||
int32 interface_id = 2;
|
||||
string model = 3;
|
||||
map<string, string> config = 4;
|
||||
}
|
||||
|
||||
message MessageType {
|
||||
enum Enum {
|
||||
NONE = 0;
|
||||
|
|
|
@ -32,7 +32,11 @@ class TestGrpc:
|
|||
node_one = core_pb2.Node(id=1, position=position, model="PC")
|
||||
position = core_pb2.Position(x=100, y=100)
|
||||
node_two = core_pb2.Node(id=2, position=position, model="PC")
|
||||
nodes.extend([node_one, node_two])
|
||||
position = core_pb2.Position(x=200, y=200)
|
||||
wlan_node = core_pb2.Node(
|
||||
id=3, type=NodeTypes.WIRELESS_LAN.value, position=position
|
||||
)
|
||||
nodes.extend([node_one, node_two, wlan_node])
|
||||
links = []
|
||||
interface_helper = InterfaceHelper(ip4_prefix="10.83.0.0/16")
|
||||
interface_one = interface_helper.create_interface(node_one.id, 0)
|
||||
|
@ -66,15 +70,54 @@ class TestGrpc:
|
|||
alt=location_alt,
|
||||
scale=location_scale,
|
||||
)
|
||||
emane_config_key = "platform_id_start"
|
||||
emane_config_value = "2"
|
||||
emane_config = {emane_config_key: emane_config_value}
|
||||
model_configs = []
|
||||
model_node_id = 20
|
||||
model_config_key = "bandwidth"
|
||||
model_config_value = "500000"
|
||||
model_config = core_pb2.EmaneModelConfig(
|
||||
node_id=model_node_id,
|
||||
interface_id=-1,
|
||||
model=EmaneIeee80211abgModel.name,
|
||||
config={model_config_key: model_config_value},
|
||||
)
|
||||
model_configs.append(model_config)
|
||||
wlan_configs = []
|
||||
wlan_config_key = "range"
|
||||
wlan_config_value = "333"
|
||||
wlan_config = core_pb2.WlanConfig(
|
||||
node_id=wlan_node.id, config={wlan_config_key: wlan_config_value}
|
||||
)
|
||||
wlan_configs.append(wlan_config)
|
||||
mobility_config_key = "refresh_ms"
|
||||
mobility_config_value = "60"
|
||||
mobility_configs = []
|
||||
mobility_config = core_pb2.MobilityConfig(
|
||||
node_id=wlan_node.id, config={mobility_config_key: mobility_config_value}
|
||||
)
|
||||
mobility_configs.append(mobility_config)
|
||||
|
||||
# when
|
||||
with patch.object(CoreXmlWriter, "write"):
|
||||
with client.context_connect():
|
||||
client.start_session(session.id, nodes, links, location, hooks)
|
||||
client.start_session(
|
||||
session.id,
|
||||
nodes,
|
||||
links,
|
||||
location,
|
||||
hooks,
|
||||
emane_config,
|
||||
model_configs,
|
||||
wlan_configs,
|
||||
mobility_configs,
|
||||
)
|
||||
|
||||
# then
|
||||
assert node_one.id in session.nodes
|
||||
assert node_two.id in session.nodes
|
||||
assert wlan_node.id in session.nodes
|
||||
assert session.nodes[node_one.id].netif(0) is not None
|
||||
assert session.nodes[node_two.id].netif(0) is not None
|
||||
hook_file, hook_data = session._hooks[core_pb2.SessionState.RUNTIME][0]
|
||||
|
@ -83,6 +126,19 @@ class TestGrpc:
|
|||
assert session.location.refxyz == (location_x, location_y, location_z)
|
||||
assert session.location.refgeo == (location_lat, location_lon, location_alt)
|
||||
assert session.location.refscale == location_scale
|
||||
assert session.emane.get_config(emane_config_key) == emane_config_value
|
||||
set_wlan_config = session.mobility.get_model_config(
|
||||
wlan_node.id, BasicRangeModel.name
|
||||
)
|
||||
assert set_wlan_config[wlan_config_key] == wlan_config_value
|
||||
set_mobility_config = session.mobility.get_model_config(
|
||||
wlan_node.id, Ns2ScriptedMobility.name
|
||||
)
|
||||
assert set_mobility_config[mobility_config_key] == mobility_config_value
|
||||
set_model_config = session.emane.get_model_config(
|
||||
model_node_id, EmaneIeee80211abgModel.name
|
||||
)
|
||||
assert set_model_config[model_config_key] == model_config_value
|
||||
|
||||
@pytest.mark.parametrize("session_id", [None, 6013])
|
||||
def test_create_session(self, grpc_server, session_id):
|
||||
|
|
Loading…
Reference in a new issue