grpc support for get session options and location
This commit is contained in:
parent
b573eb641e
commit
e819b706bc
4 changed files with 153 additions and 65 deletions
|
@ -21,6 +21,16 @@ class CoreApiClient(object):
|
||||||
request.id = _id
|
request.id = _id
|
||||||
return self.stub.GetSession(request)
|
return self.stub.GetSession(request)
|
||||||
|
|
||||||
|
def get_session_options(self, _id):
|
||||||
|
request = core_pb2.SessionOptionsRequest()
|
||||||
|
request.id = _id
|
||||||
|
return self.stub.GetSessionOptions(request)
|
||||||
|
|
||||||
|
def get_session_location(self, _id):
|
||||||
|
request = core_pb2.SessionLocationRequest()
|
||||||
|
request.id = _id
|
||||||
|
return self.stub.GetSessionLocation(request)
|
||||||
|
|
||||||
@contextmanager
|
@contextmanager
|
||||||
def connect(self):
|
def connect(self):
|
||||||
channel = grpc.insecure_channel(self.address)
|
channel = grpc.insecure_channel(self.address)
|
||||||
|
@ -42,6 +52,9 @@ def main():
|
||||||
session = client.get_session(session_data.id)
|
session = client.get_session(session_data.id)
|
||||||
print(session)
|
print(session)
|
||||||
|
|
||||||
|
print(client.get_session_options(session_data.id))
|
||||||
|
print(client.get_session_location(session_data.id))
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
logging.basicConfig()
|
logging.basicConfig()
|
||||||
|
|
|
@ -91,6 +91,48 @@ class CoreApiServer(core_pb2_grpc.CoreApiServicer):
|
||||||
session_data.nodes = session.get_node_count()
|
session_data.nodes = session.get_node_count()
|
||||||
return response
|
return response
|
||||||
|
|
||||||
|
def GetSessionLocation(self, request, context):
|
||||||
|
session = self.coreemu.sessions.get(request.id)
|
||||||
|
x, y, z = session.location.refxyz
|
||||||
|
lat, lon, alt = session.location.refgeo
|
||||||
|
response = core_pb2.SessionLocationResponse()
|
||||||
|
update_proto(
|
||||||
|
response.position,
|
||||||
|
x=x,
|
||||||
|
y=y,
|
||||||
|
z=z,
|
||||||
|
lat=lat,
|
||||||
|
lon=lon,
|
||||||
|
alt=alt
|
||||||
|
)
|
||||||
|
update_proto(response, scale=session.location.refscale)
|
||||||
|
return response
|
||||||
|
|
||||||
|
def GetSessionOptions(self, request, context):
|
||||||
|
session = self.coreemu.sessions.get(request.id)
|
||||||
|
config = session.options.get_configs()
|
||||||
|
|
||||||
|
response = core_pb2.SessionOptionsResponse()
|
||||||
|
config_options = []
|
||||||
|
for configuration in session.options.configurations():
|
||||||
|
value = config[configuration.id]
|
||||||
|
config_option = core_pb2.ConfigOption()
|
||||||
|
config_option.label = configuration.label
|
||||||
|
config_option.name = configuration.id
|
||||||
|
config_option.value = value
|
||||||
|
config_option.type = configuration.type.value
|
||||||
|
config_option.select.extend(configuration.options)
|
||||||
|
config_options.append(config_option)
|
||||||
|
|
||||||
|
for config_group in session.options.config_groups():
|
||||||
|
start = config_group.start - 1
|
||||||
|
stop = config_group.stop
|
||||||
|
config_group_proto = response.groups.add()
|
||||||
|
config_group_proto.name = config_group.name
|
||||||
|
config_group_proto.options.extend(config_options[start: stop])
|
||||||
|
|
||||||
|
return response
|
||||||
|
|
||||||
def GetSession(self, request, context):
|
def GetSession(self, request, context):
|
||||||
session = self.coreemu.sessions.get(request.id)
|
session = self.coreemu.sessions.get(request.id)
|
||||||
if not request:
|
if not request:
|
||||||
|
@ -103,35 +145,32 @@ class CoreApiServer(core_pb2_grpc.CoreApiServicer):
|
||||||
if not isinstance(node.objid, int):
|
if not isinstance(node.objid, int):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
node_data = response.nodes.add()
|
node_proto = response.nodes.add()
|
||||||
node_data.id = node.objid
|
node_proto.id = node.objid
|
||||||
node_data.name = node.name
|
node_proto.name = node.name
|
||||||
node_data.type = nodeutils.get_node_type(node.__class__).value
|
node_proto.type = nodeutils.get_node_type(node.__class__).value
|
||||||
model = getattr(node, "type", None)
|
model = getattr(node, "type", None)
|
||||||
if model:
|
if model is not None:
|
||||||
node_data.model = model
|
node_proto.model = model
|
||||||
|
|
||||||
x = node.position.x
|
update_proto(
|
||||||
if x is not None:
|
node_proto.position,
|
||||||
node_data.position.x = x
|
x=node.position.x,
|
||||||
y = node.position.y
|
y=node.position.y,
|
||||||
if y is not None:
|
z=node.position.z
|
||||||
node_data.position.y = y
|
)
|
||||||
z = node.position.z
|
|
||||||
if z is not None:
|
|
||||||
node_data.position.z = z
|
|
||||||
|
|
||||||
services = getattr(node, "services", [])
|
services = getattr(node, "services", [])
|
||||||
if services is None:
|
if services is None:
|
||||||
services = []
|
services = []
|
||||||
services = [x.name for x in services]
|
services = [x.name for x in services]
|
||||||
node_data.services.extend(services)
|
node_proto.services.extend(services)
|
||||||
|
|
||||||
emane_model = None
|
emane_model = None
|
||||||
if nodeutils.is_node(node, NodeTypes.EMANE):
|
if nodeutils.is_node(node, NodeTypes.EMANE):
|
||||||
emane_model = node.model.name
|
emane_model = node.model.name
|
||||||
if emane_model:
|
if emane_model is not None:
|
||||||
node_data.emane = emane_model
|
node_proto.emane = emane_model
|
||||||
|
|
||||||
links_data = node.all_link_data(0)
|
links_data = node.all_link_data(0)
|
||||||
for link_data in links_data:
|
for link_data in links_data:
|
||||||
|
|
|
@ -3,81 +3,117 @@ syntax = "proto3";
|
||||||
package core;
|
package core;
|
||||||
|
|
||||||
service CoreApi {
|
service CoreApi {
|
||||||
rpc GetSessions (SessionsRequest) returns (SessionsResponse) {}
|
rpc GetSessions (SessionsRequest) returns (SessionsResponse) {
|
||||||
rpc GetSession (SessionRequest) returns (SessionResponse) {}
|
}
|
||||||
|
rpc GetSession (SessionRequest) returns (SessionResponse) {
|
||||||
|
}
|
||||||
|
rpc GetSessionOptions (SessionOptionsRequest) returns (SessionOptionsResponse) {
|
||||||
|
}
|
||||||
|
rpc GetSessionLocation (SessionLocationRequest) returns (SessionLocationResponse) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
message SessionsRequest {
|
message SessionsRequest {
|
||||||
}
|
}
|
||||||
|
|
||||||
message SessionsResponse {
|
message SessionsResponse {
|
||||||
repeated Session sessions = 1;
|
repeated Session sessions = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
message SessionRequest {
|
message SessionRequest {
|
||||||
int32 id = 1;
|
int32 id = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
message SessionResponse {
|
message SessionResponse {
|
||||||
int32 state = 1;
|
int32 state = 1;
|
||||||
repeated Node nodes = 2;
|
repeated Node nodes = 2;
|
||||||
repeated Link links = 3;
|
repeated Link links = 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
message SessionOptionsRequest {
|
||||||
|
int32 id = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
message SessionOptionsResponse {
|
||||||
|
repeated ConfigGroup groups = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
message SessionLocationRequest {
|
||||||
|
int32 id = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
message SessionLocationResponse {
|
||||||
|
Position position = 1;
|
||||||
|
float scale = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
message ConfigGroup {
|
||||||
|
string name = 1;
|
||||||
|
repeated ConfigOption options = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
message ConfigOption {
|
||||||
|
string label = 1;
|
||||||
|
string name = 2;
|
||||||
|
string value = 3;
|
||||||
|
int32 type = 4;
|
||||||
|
repeated string select = 5;
|
||||||
}
|
}
|
||||||
|
|
||||||
message Session {
|
message Session {
|
||||||
int32 id = 1;
|
int32 id = 1;
|
||||||
int32 state = 2;
|
int32 state = 2;
|
||||||
int32 nodes = 3;
|
int32 nodes = 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
message Node {
|
message Node {
|
||||||
int32 id = 1;
|
int32 id = 1;
|
||||||
string name = 2;
|
string name = 2;
|
||||||
int32 type = 3;
|
int32 type = 3;
|
||||||
string model = 4;
|
string model = 4;
|
||||||
Position position = 5;
|
Position position = 5;
|
||||||
repeated string services = 6;
|
repeated string services = 6;
|
||||||
string emane = 7;
|
string emane = 7;
|
||||||
}
|
}
|
||||||
|
|
||||||
message Link {
|
message Link {
|
||||||
int32 node_one = 1;
|
int32 node_one = 1;
|
||||||
int32 node_two = 2;
|
int32 node_two = 2;
|
||||||
int32 type = 3;
|
int32 type = 3;
|
||||||
Interface interface_one = 4;
|
Interface interface_one = 4;
|
||||||
Interface interface_two = 5;
|
Interface interface_two = 5;
|
||||||
LinkOptions options = 6;
|
LinkOptions options = 6;
|
||||||
}
|
}
|
||||||
|
|
||||||
message LinkOptions {
|
message LinkOptions {
|
||||||
string opaque = 1;
|
string opaque = 1;
|
||||||
float jitter = 2;
|
float jitter = 2;
|
||||||
string key = 3;
|
string key = 3;
|
||||||
float mburst = 4;
|
float mburst = 4;
|
||||||
float mer = 5;
|
float mer = 5;
|
||||||
float per = 6;
|
float per = 6;
|
||||||
float bandwidth = 7;
|
float bandwidth = 7;
|
||||||
float burst = 8;
|
float burst = 8;
|
||||||
float delay = 9;
|
float delay = 9;
|
||||||
float dup = 10;
|
float dup = 10;
|
||||||
bool unidirectional = 11;
|
bool unidirectional = 11;
|
||||||
}
|
}
|
||||||
|
|
||||||
message Interface {
|
message Interface {
|
||||||
int32 id = 1;
|
int32 id = 1;
|
||||||
string name = 2;
|
string name = 2;
|
||||||
string mac = 3;
|
string mac = 3;
|
||||||
string ip4 = 4;
|
string ip4 = 4;
|
||||||
int32 ip4mask = 5;
|
int32 ip4mask = 5;
|
||||||
string ip6 = 6;
|
string ip6 = 6;
|
||||||
int32 ip6mask = 7;
|
int32 ip6mask = 7;
|
||||||
}
|
}
|
||||||
|
|
||||||
message Position {
|
message Position {
|
||||||
int32 x = 1;
|
float x = 1;
|
||||||
int32 y = 2;
|
float y = 2;
|
||||||
int32 z = 3;
|
float z = 3;
|
||||||
float lat = 4;
|
float lat = 4;
|
||||||
float lon = 5;
|
float lon = 5;
|
||||||
float alt = 6;
|
float alt = 6;
|
||||||
}
|
}
|
||||||
|
|
0
daemon/scripts/core-daemon
Normal file → Executable file
0
daemon/scripts/core-daemon
Normal file → Executable file
Loading…
Reference in a new issue