grpc updates to provide link data within a session query

This commit is contained in:
bharnden 2019-02-19 23:32:04 -08:00
parent 7aed803aae
commit b573eb641e
2 changed files with 95 additions and 3 deletions

View file

@ -13,6 +13,69 @@ from core.misc import nodeutils
_ONE_DAY_IN_SECONDS = 60 * 60 * 24
def convert_value(value):
if value is None:
return value
else:
return str(value)
def update_proto(obj, **kwargs):
for key in kwargs:
value = kwargs[key]
if value is not None:
logging.info("setting proto key(%s) value(%s)", key, value)
setattr(obj, key, value)
def convert_link(session, link_data, link):
if link_data.interface1_id is not None:
node = session.get_object(link_data.node1_id)
interface = node.netif(link_data.interface1_id)
link.interface_one.id = link_data.interface1_id
link.interface_one.name = interface.name
update_proto(
link.interface_one,
mac=convert_value(link_data.interface1_mac),
ip4=convert_value(link_data.interface1_ip4),
ip4mask=link_data.interface1_ip4_mask,
ip6=convert_value(link_data.interface1_ip6),
ip6mask=link_data.interface1_ip6_mask
)
if link_data.interface2_id is not None:
node = session.get_object(link_data.node2_id)
interface = node.netif(link_data.interface2_id)
link.interface_two.id = link_data.interface2_id
link.interface_two.name = interface.name
update_proto(
link.interface_two,
mac=convert_value(link_data.interface2_mac),
ip4=convert_value(link_data.interface2_ip4),
ip4mask=link_data.interface2_ip4_mask,
ip6=convert_value(link_data.interface2_ip6),
ip6mask=link_data.interface2_ip6_mask
)
link.node_one = link_data.node1_id
link.node_two = link_data.node2_id
link.type = link_data.link_type
update_proto(
link.options,
opaque=link_data.opaque,
jitter=link_data.jitter,
key=link_data.key,
mburst=link_data.mburst,
mer=link_data.mer,
per=link_data.per,
bandwidth=link_data.bandwidth,
burst=link_data.burst,
delay=link_data.delay,
dup=link_data.dup,
unidirectional=link_data.unidirectional
)
class CoreApiServer(core_pb2_grpc.CoreApiServicer):
def __init__(self, coreemu):
super(CoreApiServer, self).__init__()
@ -72,9 +135,9 @@ class CoreApiServer(core_pb2_grpc.CoreApiServicer):
links_data = node.all_link_data(0)
for link_data in links_data:
pass
# link = core_utils.convert_link(session, link_data)
# links.append(link)
link = response.links.add()
convert_link(session, link_data, link)
return response

View file

@ -41,7 +41,36 @@ message Node {
}
message Link {
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;
}
message Interface {
int32 id = 1;
string name = 2;
string mac = 3;
string ip4 = 4;
int32 ip4mask = 5;
string ip6 = 6;
int32 ip6mask = 7;
}
message Position {