modified grpc set node service and node service file to use messages for their config, updated start session to leverage these messages to set them when starting a session
This commit is contained in:
parent
b88abd0f74
commit
18c9904d58
5 changed files with 90 additions and 37 deletions
|
@ -159,6 +159,8 @@ class CoreGrpcClient:
|
||||||
emane_model_configs=None,
|
emane_model_configs=None,
|
||||||
wlan_configs=None,
|
wlan_configs=None,
|
||||||
mobility_configs=None,
|
mobility_configs=None,
|
||||||
|
service_configs=None,
|
||||||
|
service_file_configs=None,
|
||||||
):
|
):
|
||||||
"""
|
"""
|
||||||
Start a session.
|
Start a session.
|
||||||
|
@ -169,9 +171,11 @@ class CoreGrpcClient:
|
||||||
:param core_pb2.SessionLocation location: location to set
|
:param core_pb2.SessionLocation location: location to set
|
||||||
:param list[core_pb2.Hook] hooks: session hooks to set
|
:param list[core_pb2.Hook] hooks: session hooks to set
|
||||||
:param dict emane_config: emane configuration to set
|
:param dict emane_config: emane configuration to set
|
||||||
:param list emane_model_configs: emane model configurations to set
|
:param list emane_model_configs: node emane model configurations
|
||||||
:param list wlan_configs: wlan configurations to set
|
:param list wlan_configs: node wlan configurations
|
||||||
:param list mobility_configs: mobility configurations to set
|
:param list mobility_configs: node mobility configurations
|
||||||
|
:param list service_configs: node service configurations
|
||||||
|
:param list service_file_configs: node service file configurations
|
||||||
:return: start session response
|
:return: start session response
|
||||||
:rtype: core_pb2.StartSessionResponse
|
:rtype: core_pb2.StartSessionResponse
|
||||||
"""
|
"""
|
||||||
|
@ -185,6 +189,8 @@ class CoreGrpcClient:
|
||||||
emane_model_configs=emane_model_configs,
|
emane_model_configs=emane_model_configs,
|
||||||
wlan_configs=wlan_configs,
|
wlan_configs=wlan_configs,
|
||||||
mobility_configs=mobility_configs,
|
mobility_configs=mobility_configs,
|
||||||
|
service_configs=service_configs,
|
||||||
|
service_file_configs=service_file_configs,
|
||||||
)
|
)
|
||||||
return self.stub.StartSession(request)
|
return self.stub.StartSession(request)
|
||||||
|
|
||||||
|
@ -768,14 +774,14 @@ class CoreGrpcClient:
|
||||||
:rtype: core_pb2.SetNodeServiceResponse
|
:rtype: core_pb2.SetNodeServiceResponse
|
||||||
:raises grpc.RpcError: when session or node doesn't exist
|
:raises grpc.RpcError: when session or node doesn't exist
|
||||||
"""
|
"""
|
||||||
request = core_pb2.SetNodeServiceRequest(
|
config = core_pb2.ServiceConfig(
|
||||||
session_id=session_id,
|
|
||||||
node_id=node_id,
|
node_id=node_id,
|
||||||
service=service,
|
service=service,
|
||||||
startup=startup,
|
startup=startup,
|
||||||
validate=validate,
|
validate=validate,
|
||||||
shutdown=shutdown,
|
shutdown=shutdown,
|
||||||
)
|
)
|
||||||
|
request = core_pb2.SetNodeServiceRequest(session_id=session_id, config=config)
|
||||||
return self.stub.SetNodeService(request)
|
return self.stub.SetNodeService(request)
|
||||||
|
|
||||||
def set_node_service_file(self, session_id, node_id, service, file_name, data):
|
def set_node_service_file(self, session_id, node_id, service, file_name, data):
|
||||||
|
@ -791,12 +797,11 @@ class CoreGrpcClient:
|
||||||
:rtype: core_pb2.SetNodeServiceFileResponse
|
:rtype: core_pb2.SetNodeServiceFileResponse
|
||||||
:raises grpc.RpcError: when session or node doesn't exist
|
:raises grpc.RpcError: when session or node doesn't exist
|
||||||
"""
|
"""
|
||||||
|
config = core_pb2.ServiceFileConfig(
|
||||||
|
node_id=node_id, service=service, file=file_name, data=data
|
||||||
|
)
|
||||||
request = core_pb2.SetNodeServiceFileRequest(
|
request = core_pb2.SetNodeServiceFileRequest(
|
||||||
session_id=session_id,
|
session_id=session_id, config=config
|
||||||
node_id=node_id,
|
|
||||||
service=service,
|
|
||||||
file=file_name,
|
|
||||||
data=data,
|
|
||||||
)
|
)
|
||||||
return self.stub.SetNodeServiceFile(request)
|
return self.stub.SetNodeServiceFile(request)
|
||||||
|
|
||||||
|
|
|
@ -319,3 +319,18 @@ def session_location(session, location):
|
||||||
session.location.refxyz = (location.x, location.y, location.z)
|
session.location.refxyz = (location.x, location.y, location.z)
|
||||||
session.location.setrefgeo(location.lat, location.lon, location.alt)
|
session.location.setrefgeo(location.lat, location.lon, location.alt)
|
||||||
session.location.refscale = location.scale
|
session.location.refscale = location.scale
|
||||||
|
|
||||||
|
|
||||||
|
def service_configuration(session, config):
|
||||||
|
"""
|
||||||
|
Convenience method for setting a node service configuration.
|
||||||
|
|
||||||
|
:param core.emulator.session.Session session: session for service configuration
|
||||||
|
:param core_pb2.ServiceConfig config: service configuration
|
||||||
|
:return:
|
||||||
|
"""
|
||||||
|
session.services.set_service(config.node_id, config.service)
|
||||||
|
service = session.services.get_service(config.node_id, config.service)
|
||||||
|
service.startup = tuple(config.startup)
|
||||||
|
service.validate = tuple(config.validate)
|
||||||
|
service.shutdown = tuple(config.shutdown)
|
||||||
|
|
|
@ -153,6 +153,16 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
|
||||||
config.node_id, Ns2ScriptedMobility.name, config.config
|
config.node_id, Ns2ScriptedMobility.name, config.config
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# service configs
|
||||||
|
for config in request.service_configs:
|
||||||
|
grpcutils.service_configuration(session, config)
|
||||||
|
|
||||||
|
# service file configs
|
||||||
|
for config in request.service_file_configs:
|
||||||
|
session.services.set_service_file(
|
||||||
|
config.node_id, config.service, config.file, config.data
|
||||||
|
)
|
||||||
|
|
||||||
# create links
|
# create links
|
||||||
grpcutils.create_links(session, request.links)
|
grpcutils.create_links(session, request.links)
|
||||||
|
|
||||||
|
@ -1172,11 +1182,8 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
|
||||||
"""
|
"""
|
||||||
logging.debug("set node service: %s", request)
|
logging.debug("set node service: %s", request)
|
||||||
session = self.get_session(request.session_id, context)
|
session = self.get_session(request.session_id, context)
|
||||||
session.services.set_service(request.node_id, request.service)
|
config = request.config
|
||||||
service = session.services.get_service(request.node_id, request.service)
|
grpcutils.service_configuration(session, config)
|
||||||
service.startup = tuple(request.startup)
|
|
||||||
service.validate = tuple(request.validate)
|
|
||||||
service.shutdown = tuple(request.shutdown)
|
|
||||||
return core_pb2.SetNodeServiceResponse(result=True)
|
return core_pb2.SetNodeServiceResponse(result=True)
|
||||||
|
|
||||||
def SetNodeServiceFile(self, request, context):
|
def SetNodeServiceFile(self, request, context):
|
||||||
|
@ -1191,8 +1198,9 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
|
||||||
"""
|
"""
|
||||||
logging.debug("set node service file: %s", request)
|
logging.debug("set node service file: %s", request)
|
||||||
session = self.get_session(request.session_id, context)
|
session = self.get_session(request.session_id, context)
|
||||||
|
config = request.config
|
||||||
session.services.set_service_file(
|
session.services.set_service_file(
|
||||||
request.node_id, request.service, request.file, request.data
|
config.node_id, config.service, config.file, config.data
|
||||||
)
|
)
|
||||||
return core_pb2.SetNodeServiceFileResponse(result=True)
|
return core_pb2.SetNodeServiceFileResponse(result=True)
|
||||||
|
|
||||||
|
|
|
@ -144,6 +144,8 @@ message StartSessionRequest {
|
||||||
repeated WlanConfig wlan_configs = 7;
|
repeated WlanConfig wlan_configs = 7;
|
||||||
repeated EmaneModelConfig emane_model_configs = 8;
|
repeated EmaneModelConfig emane_model_configs = 8;
|
||||||
repeated MobilityConfig mobility_configs = 9;
|
repeated MobilityConfig mobility_configs = 9;
|
||||||
|
repeated ServiceConfig service_configs = 10;
|
||||||
|
repeated ServiceFileConfig service_file_configs = 11;
|
||||||
}
|
}
|
||||||
|
|
||||||
message StartSessionResponse {
|
message StartSessionResponse {
|
||||||
|
@ -554,11 +556,7 @@ message GetNodeServiceFileResponse {
|
||||||
|
|
||||||
message SetNodeServiceRequest {
|
message SetNodeServiceRequest {
|
||||||
int32 session_id = 1;
|
int32 session_id = 1;
|
||||||
int32 node_id = 2;
|
ServiceConfig config = 2;
|
||||||
string service = 3;
|
|
||||||
repeated string startup = 4;
|
|
||||||
repeated string validate = 5;
|
|
||||||
repeated string shutdown = 6;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
message SetNodeServiceResponse {
|
message SetNodeServiceResponse {
|
||||||
|
@ -567,10 +565,7 @@ message SetNodeServiceResponse {
|
||||||
|
|
||||||
message SetNodeServiceFileRequest {
|
message SetNodeServiceFileRequest {
|
||||||
int32 session_id = 1;
|
int32 session_id = 1;
|
||||||
int32 node_id = 2;
|
ServiceFileConfig config = 2;
|
||||||
string service = 3;
|
|
||||||
string file = 4;
|
|
||||||
string data = 5;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
message SetNodeServiceFileResponse {
|
message SetNodeServiceFileResponse {
|
||||||
|
@ -718,6 +713,21 @@ message EmaneModelConfig {
|
||||||
map<string, string> config = 4;
|
map<string, string> config = 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
message ServiceConfig {
|
||||||
|
int32 node_id = 1;
|
||||||
|
string service = 2;
|
||||||
|
repeated string startup = 3;
|
||||||
|
repeated string validate = 4;
|
||||||
|
repeated string shutdown = 5;
|
||||||
|
}
|
||||||
|
|
||||||
|
message ServiceFileConfig {
|
||||||
|
int32 node_id = 1;
|
||||||
|
string service = 2;
|
||||||
|
string file = 3;
|
||||||
|
string data = 4;
|
||||||
|
}
|
||||||
|
|
||||||
message MessageType {
|
message MessageType {
|
||||||
enum Enum {
|
enum Enum {
|
||||||
NONE = 0;
|
NONE = 0;
|
||||||
|
|
|
@ -27,7 +27,6 @@ class TestGrpc:
|
||||||
# given
|
# given
|
||||||
client = CoreGrpcClient()
|
client = CoreGrpcClient()
|
||||||
session = grpc_server.coreemu.create_session()
|
session = grpc_server.coreemu.create_session()
|
||||||
nodes = []
|
|
||||||
position = core_pb2.Position(x=50, y=100)
|
position = core_pb2.Position(x=50, y=100)
|
||||||
node_one = core_pb2.Node(id=1, position=position, model="PC")
|
node_one = core_pb2.Node(id=1, position=position, model="PC")
|
||||||
position = core_pb2.Position(x=100, y=100)
|
position = core_pb2.Position(x=100, y=100)
|
||||||
|
@ -36,8 +35,7 @@ class TestGrpc:
|
||||||
wlan_node = core_pb2.Node(
|
wlan_node = core_pb2.Node(
|
||||||
id=3, type=NodeTypes.WIRELESS_LAN.value, position=position
|
id=3, type=NodeTypes.WIRELESS_LAN.value, position=position
|
||||||
)
|
)
|
||||||
nodes.extend([node_one, node_two, wlan_node])
|
nodes = [node_one, node_two, wlan_node]
|
||||||
links = []
|
|
||||||
interface_helper = InterfaceHelper(ip4_prefix="10.83.0.0/16")
|
interface_helper = InterfaceHelper(ip4_prefix="10.83.0.0/16")
|
||||||
interface_one = interface_helper.create_interface(node_one.id, 0)
|
interface_one = interface_helper.create_interface(node_one.id, 0)
|
||||||
interface_two = interface_helper.create_interface(node_two.id, 0)
|
interface_two = interface_helper.create_interface(node_two.id, 0)
|
||||||
|
@ -48,12 +46,11 @@ class TestGrpc:
|
||||||
interface_one=interface_one,
|
interface_one=interface_one,
|
||||||
interface_two=interface_two,
|
interface_two=interface_two,
|
||||||
)
|
)
|
||||||
links.append(link)
|
links = [link]
|
||||||
hooks = []
|
|
||||||
hook = core_pb2.Hook(
|
hook = core_pb2.Hook(
|
||||||
state=core_pb2.SessionState.RUNTIME, file="echo.sh", data="echo hello"
|
state=core_pb2.SessionState.RUNTIME, file="echo.sh", data="echo hello"
|
||||||
)
|
)
|
||||||
hooks.append(hook)
|
hooks = [hook]
|
||||||
location_x = 5
|
location_x = 5
|
||||||
location_y = 10
|
location_y = 10
|
||||||
location_z = 15
|
location_z = 15
|
||||||
|
@ -73,7 +70,6 @@ class TestGrpc:
|
||||||
emane_config_key = "platform_id_start"
|
emane_config_key = "platform_id_start"
|
||||||
emane_config_value = "2"
|
emane_config_value = "2"
|
||||||
emane_config = {emane_config_key: emane_config_value}
|
emane_config = {emane_config_key: emane_config_value}
|
||||||
model_configs = []
|
|
||||||
model_node_id = 20
|
model_node_id = 20
|
||||||
model_config_key = "bandwidth"
|
model_config_key = "bandwidth"
|
||||||
model_config_value = "500000"
|
model_config_value = "500000"
|
||||||
|
@ -83,21 +79,30 @@ class TestGrpc:
|
||||||
model=EmaneIeee80211abgModel.name,
|
model=EmaneIeee80211abgModel.name,
|
||||||
config={model_config_key: model_config_value},
|
config={model_config_key: model_config_value},
|
||||||
)
|
)
|
||||||
model_configs.append(model_config)
|
model_configs = [model_config]
|
||||||
wlan_configs = []
|
|
||||||
wlan_config_key = "range"
|
wlan_config_key = "range"
|
||||||
wlan_config_value = "333"
|
wlan_config_value = "333"
|
||||||
wlan_config = core_pb2.WlanConfig(
|
wlan_config = core_pb2.WlanConfig(
|
||||||
node_id=wlan_node.id, config={wlan_config_key: wlan_config_value}
|
node_id=wlan_node.id, config={wlan_config_key: wlan_config_value}
|
||||||
)
|
)
|
||||||
wlan_configs.append(wlan_config)
|
wlan_configs = [wlan_config]
|
||||||
mobility_config_key = "refresh_ms"
|
mobility_config_key = "refresh_ms"
|
||||||
mobility_config_value = "60"
|
mobility_config_value = "60"
|
||||||
mobility_configs = []
|
|
||||||
mobility_config = core_pb2.MobilityConfig(
|
mobility_config = core_pb2.MobilityConfig(
|
||||||
node_id=wlan_node.id, config={mobility_config_key: mobility_config_value}
|
node_id=wlan_node.id, config={mobility_config_key: mobility_config_value}
|
||||||
)
|
)
|
||||||
mobility_configs.append(mobility_config)
|
mobility_configs = [mobility_config]
|
||||||
|
service_config = core_pb2.ServiceConfig(
|
||||||
|
node_id=node_one.id, service="DefaultRoute", validate=["echo hello"]
|
||||||
|
)
|
||||||
|
service_configs = [service_config]
|
||||||
|
service_file_config = core_pb2.ServiceFileConfig(
|
||||||
|
node_id=node_one.id,
|
||||||
|
service="DefaultRoute",
|
||||||
|
file="defaultroute.sh",
|
||||||
|
data="echo hello",
|
||||||
|
)
|
||||||
|
service_file_configs = [service_file_config]
|
||||||
|
|
||||||
# when
|
# when
|
||||||
with patch.object(CoreXmlWriter, "write"):
|
with patch.object(CoreXmlWriter, "write"):
|
||||||
|
@ -112,6 +117,8 @@ class TestGrpc:
|
||||||
model_configs,
|
model_configs,
|
||||||
wlan_configs,
|
wlan_configs,
|
||||||
mobility_configs,
|
mobility_configs,
|
||||||
|
service_configs,
|
||||||
|
service_file_configs,
|
||||||
)
|
)
|
||||||
|
|
||||||
# then
|
# then
|
||||||
|
@ -139,6 +146,14 @@ class TestGrpc:
|
||||||
model_node_id, EmaneIeee80211abgModel.name
|
model_node_id, EmaneIeee80211abgModel.name
|
||||||
)
|
)
|
||||||
assert set_model_config[model_config_key] == model_config_value
|
assert set_model_config[model_config_key] == model_config_value
|
||||||
|
service = session.services.get_service(
|
||||||
|
node_one.id, service_config.service, default_service=True
|
||||||
|
)
|
||||||
|
assert service.validate == tuple(service_config.validate)
|
||||||
|
service_file = session.services.get_service_file(
|
||||||
|
node_one, service_file_config.service, service_file_config.file
|
||||||
|
)
|
||||||
|
assert service_file.data == service_file_config.data
|
||||||
|
|
||||||
@pytest.mark.parametrize("session_id", [None, 6013])
|
@pytest.mark.parametrize("session_id", [None, 6013])
|
||||||
def test_create_session(self, grpc_server, session_id):
|
def test_create_session(self, grpc_server, session_id):
|
||||||
|
|
Loading…
Reference in a new issue