added hook creation and set location to grpc.StartSession
This commit is contained in:
parent
4e03dc6888
commit
de936ea315
5 changed files with 119 additions and 29 deletions
|
@ -148,17 +148,23 @@ class CoreGrpcClient:
|
|||
self.stub = None
|
||||
self.channel = None
|
||||
|
||||
def start_session(self, session_id, nodes, links):
|
||||
def start_session(self, session_id, nodes, links, location=None, hooks=None):
|
||||
"""
|
||||
Start a session.
|
||||
|
||||
:param int session_id: id of session
|
||||
:param list nodes: list of nodes to create
|
||||
:param list links: list of links to create
|
||||
:param core_pb2.SessionLocation location: location to set
|
||||
:param list[core_pb2.Hook] hooks: session hooks to set
|
||||
:return:
|
||||
"""
|
||||
request = core_pb2.StartSessionRequest(
|
||||
session_id=session_id, nodes=nodes, links=links
|
||||
session_id=session_id,
|
||||
nodes=nodes,
|
||||
links=links,
|
||||
location=location,
|
||||
hooks=hooks,
|
||||
)
|
||||
return self.stub.StartSession(request)
|
||||
|
||||
|
@ -282,9 +288,11 @@ class CoreGrpcClient:
|
|||
:rtype: core_pb2.SetSessionLocationResponse
|
||||
:raises grpc.RpcError: when session doesn't exist
|
||||
"""
|
||||
position = core_pb2.SessionPosition(x=x, y=y, z=z, lat=lat, lon=lon, alt=alt)
|
||||
location = core_pb2.SessionLocation(
|
||||
x=x, y=y, z=z, lat=lat, lon=lon, alt=alt, scale=scale
|
||||
)
|
||||
request = core_pb2.SetSessionLocationRequest(
|
||||
session_id=session_id, position=position, scale=scale
|
||||
session_id=session_id, location=location
|
||||
)
|
||||
return self.stub.SetSessionLocation(request)
|
||||
|
||||
|
|
|
@ -306,3 +306,16 @@ def get_net_stats():
|
|||
stats[line[0]] = {"rx": float(line[1]), "tx": float(line[9])}
|
||||
|
||||
return stats
|
||||
|
||||
|
||||
def session_location(session, location):
|
||||
"""
|
||||
Set session location based on location proto.
|
||||
|
||||
:param core.emulator.session.Session session: session for location
|
||||
:param core_pb2.SessionLocation location: location to set
|
||||
:return: nothing
|
||||
"""
|
||||
session.location.refxyz = (location.x, location.y, location.z)
|
||||
session.location.setrefgeo(location.lat, location.lon, location.alt)
|
||||
session.location.refscale = location.scale
|
||||
|
|
|
@ -122,9 +122,21 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
|
|||
if not os.path.exists(session.session_dir):
|
||||
os.mkdir(session.session_dir)
|
||||
|
||||
# location
|
||||
if request.HasField("location"):
|
||||
grpcutils.session_location(session, request.location)
|
||||
|
||||
# add all hooks
|
||||
for hook in request.hooks:
|
||||
session.add_hook(hook.state, hook.file, None, hook.data)
|
||||
|
||||
# create nodes
|
||||
grpcutils.create_nodes(session, request.nodes)
|
||||
|
||||
# emane configs
|
||||
# wlan configs
|
||||
# mobility configs
|
||||
|
||||
# create links
|
||||
grpcutils.create_links(session, request.links)
|
||||
|
||||
|
@ -217,10 +229,11 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
|
|||
session = self.get_session(request.session_id, context)
|
||||
x, y, z = session.location.refxyz
|
||||
lat, lon, alt = session.location.refgeo
|
||||
position = core_pb2.SessionPosition(x=x, y=y, z=z, lat=lat, lon=lon, alt=alt)
|
||||
return core_pb2.GetSessionLocationResponse(
|
||||
position=position, scale=session.location.refscale
|
||||
scale = session.location.refscale
|
||||
location = core_pb2.SessionLocation(
|
||||
x=x, y=y, z=z, lat=lat, lon=lon, alt=alt, scale=scale
|
||||
)
|
||||
return core_pb2.GetSessionLocationResponse(location=location)
|
||||
|
||||
def SetSessionLocation(self, request, context):
|
||||
"""
|
||||
|
@ -233,15 +246,7 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
|
|||
"""
|
||||
logging.debug("set session location: %s", request)
|
||||
session = self.get_session(request.session_id, context)
|
||||
session.location.refxyz = (
|
||||
request.position.x,
|
||||
request.position.y,
|
||||
request.position.z,
|
||||
)
|
||||
session.location.setrefgeo(
|
||||
request.position.lat, request.position.lon, request.position.alt
|
||||
)
|
||||
session.location.refscale = request.scale
|
||||
grpcutils.session_location(session, request.location)
|
||||
return core_pb2.SetSessionLocationResponse(result=True)
|
||||
|
||||
def SetSessionState(self, request, context):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue