grpc support for get session options and location

This commit is contained in:
bharnden 2019-02-20 21:19:35 -08:00
parent b573eb641e
commit e819b706bc
4 changed files with 153 additions and 65 deletions

View file

@ -21,6 +21,16 @@ class CoreApiClient(object):
request.id = _id
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
def connect(self):
channel = grpc.insecure_channel(self.address)
@ -42,6 +52,9 @@ def main():
session = client.get_session(session_data.id)
print(session)
print(client.get_session_options(session_data.id))
print(client.get_session_location(session_data.id))
if __name__ == "__main__":
logging.basicConfig()

View file

@ -91,6 +91,48 @@ class CoreApiServer(core_pb2_grpc.CoreApiServicer):
session_data.nodes = session.get_node_count()
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):
session = self.coreemu.sessions.get(request.id)
if not request:
@ -103,35 +145,32 @@ class CoreApiServer(core_pb2_grpc.CoreApiServicer):
if not isinstance(node.objid, int):
continue
node_data = response.nodes.add()
node_data.id = node.objid
node_data.name = node.name
node_data.type = nodeutils.get_node_type(node.__class__).value
node_proto = response.nodes.add()
node_proto.id = node.objid
node_proto.name = node.name
node_proto.type = nodeutils.get_node_type(node.__class__).value
model = getattr(node, "type", None)
if model:
node_data.model = model
if model is not None:
node_proto.model = model
x = node.position.x
if x is not None:
node_data.position.x = x
y = node.position.y
if y is not None:
node_data.position.y = y
z = node.position.z
if z is not None:
node_data.position.z = z
update_proto(
node_proto.position,
x=node.position.x,
y=node.position.y,
z=node.position.z
)
services = getattr(node, "services", [])
if services is None:
services = []
services = [x.name for x in services]
node_data.services.extend(services)
node_proto.services.extend(services)
emane_model = None
if nodeutils.is_node(node, NodeTypes.EMANE):
emane_model = node.model.name
if emane_model:
node_data.emane = emane_model
if emane_model is not None:
node_proto.emane = emane_model
links_data = node.all_link_data(0)
for link_data in links_data:

View file

@ -3,81 +3,117 @@ syntax = "proto3";
package core;
service CoreApi {
rpc GetSessions (SessionsRequest) returns (SessionsResponse) {}
rpc GetSession (SessionRequest) returns (SessionResponse) {}
rpc GetSessions (SessionsRequest) returns (SessionsResponse) {
}
rpc GetSession (SessionRequest) returns (SessionResponse) {
}
rpc GetSessionOptions (SessionOptionsRequest) returns (SessionOptionsResponse) {
}
rpc GetSessionLocation (SessionLocationRequest) returns (SessionLocationResponse) {
}
}
message SessionsRequest {
}
message SessionsResponse {
repeated Session sessions = 1;
repeated Session sessions = 1;
}
message SessionRequest {
int32 id = 1;
int32 id = 1;
}
message SessionResponse {
int32 state = 1;
repeated Node nodes = 2;
repeated Link links = 3;
int32 state = 1;
repeated Node nodes = 2;
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 {
int32 id = 1;
int32 state = 2;
int32 nodes = 3;
int32 id = 1;
int32 state = 2;
int32 nodes = 3;
}
message Node {
int32 id = 1;
string name = 2;
int32 type = 3;
string model = 4;
Position position = 5;
repeated string services = 6;
string emane = 7;
int32 id = 1;
string name = 2;
int32 type = 3;
string model = 4;
Position position = 5;
repeated string services = 6;
string emane = 7;
}
message Link {
int32 node_one = 1;
int32 node_two = 2;
int32 type = 3;
Interface interface_one = 4;
Interface interface_two = 5;
LinkOptions options = 6;
int32 node_one = 1;
int32 node_two = 2;
int32 type = 3;
Interface interface_one = 4;
Interface interface_two = 5;
LinkOptions options = 6;
}
message LinkOptions {
string opaque = 1;
float jitter = 2;
string key = 3;
float mburst = 4;
float mer = 5;
float per = 6;
float bandwidth = 7;
float burst = 8;
float delay = 9;
float dup = 10;
bool unidirectional = 11;
string opaque = 1;
float jitter = 2;
string key = 3;
float mburst = 4;
float mer = 5;
float per = 6;
float bandwidth = 7;
float burst = 8;
float delay = 9;
float dup = 10;
bool unidirectional = 11;
}
message Interface {
int32 id = 1;
string name = 2;
string mac = 3;
string ip4 = 4;
int32 ip4mask = 5;
string ip6 = 6;
int32 ip6mask = 7;
int32 id = 1;
string name = 2;
string mac = 3;
string ip4 = 4;
int32 ip4mask = 5;
string ip6 = 6;
int32 ip6mask = 7;
}
message Position {
int32 x = 1;
int32 y = 2;
int32 z = 3;
float lat = 4;
float lon = 5;
float alt = 6;
float x = 1;
float y = 2;
float z = 3;
float lat = 4;
float lon = 5;
float alt = 6;
}

0
daemon/scripts/core-daemon Normal file → Executable file
View file