updated proto enums to be prefixed with a contextual name, since they all derive from the module directly

This commit is contained in:
bharnden 2019-03-25 17:16:54 -07:00
parent 7299abd64d
commit fdc0362ba5
4 changed files with 48 additions and 147 deletions

View file

@ -136,15 +136,21 @@ class CoreGrpcClient(object):
def add_link(self, session, node_one, node_two, interface_one=None, interface_two=None, link_options=None):
interface_one_proto = None
if interface_one is not None:
mac = interface_one.mac
if mac is not None:
mac = str(mac)
interface_one_proto = core_pb2.Interface(
id=interface_one.id, name=interface_one.name, mac=str(interface_one.mac),
id=interface_one.id, name=interface_one.name, mac=mac,
ip4=interface_one.ip4, ip4mask=interface_one.ip4_mask,
ip6=interface_one.ip6, ip6mask=interface_one.ip6_mask)
interface_two_proto = None
if interface_two is not None:
mac = interface_two.mac
if mac is not None:
mac = str(mac)
interface_two_proto = core_pb2.Interface(
id=interface_two.id, name=interface_two.name, mac=str(interface_two.mac),
id=interface_two.id, name=interface_two.name, mac=mac,
ip4=interface_two.ip4, ip4mask=interface_two.ip4_mask,
ip6=interface_two.ip6, ip6mask=interface_two.ip6_mask)

View file

@ -4,20 +4,17 @@ import os
import tempfile
import time
from Queue import Queue, Empty
from itertools import repeat
import grpc
from concurrent import futures
from core.conf import ConfigShim
from core.data import ConfigData, FileData
from core.emulator.emudata import NodeOptions, InterfaceData, LinkOptions
from core.enumerations import NodeTypes, EventTypes, LinkTypes, MessageFlags, ConfigFlags, ConfigDataTypes
from core.enumerations import NodeTypes, EventTypes, LinkTypes
from core.grpc import core_pb2
from core.grpc import core_pb2_grpc
from core.misc import nodeutils
from core.mobility import BasicRangeModel, Ns2ScriptedMobility
from core.service import ServiceManager, ServiceShim
from core.service import ServiceManager
_ONE_DAY_IN_SECONDS = 60 * 60 * 24
@ -99,108 +96,6 @@ def convert_link(session, link_data):
)
def send_objects(session):
time.sleep(1)
# find all nodes and links
nodes_data = []
links_data = []
with session._objects_lock:
for obj in session.objects.itervalues():
node_data = obj.data(message_type=MessageFlags.ADD.value)
if node_data:
nodes_data.append(node_data)
node_links = obj.all_link_data(flags=MessageFlags.ADD.value)
for link_data in node_links:
links_data.append(link_data)
# send all nodes first, so that they will exist for any links
for node_data in nodes_data:
session.broadcast_node(node_data)
for link_data in links_data:
session.broadcast_link(link_data)
# send mobility model info
for node_id in session.mobility.nodes():
for model_name, config in session.mobility.get_all_configs(node_id).iteritems():
model_class = session.mobility.models[model_name]
logging.debug("mobility config: node(%s) class(%s) values(%s)", node_id, model_class, config)
config_data = ConfigShim.config_data(0, node_id, ConfigFlags.UPDATE.value, model_class, config)
session.broadcast_config(config_data)
# send emane model info
for node_id in session.emane.nodes():
for model_name, config in session.emane.get_all_configs(node_id).iteritems():
model_class = session.emane.models[model_name]
logging.debug("emane config: node(%s) class(%s) values(%s)", node_id, model_class, config)
config_data = ConfigShim.config_data(0, node_id, ConfigFlags.UPDATE.value, model_class, config)
session.broadcast_config(config_data)
# service customizations
service_configs = session.services.all_configs()
for node_id, service in service_configs:
opaque = "service:%s" % service.name
data_types = tuple(repeat(ConfigDataTypes.STRING.value, len(ServiceShim.keys)))
node = session.get_object(node_id)
values = ServiceShim.tovaluelist(node, service)
config_data = ConfigData(
message_type=0,
node=node_id,
object=session.services.name,
type=ConfigFlags.UPDATE.value,
data_types=data_types,
data_values=values,
session=str(session.session_id),
opaque=opaque
)
session.broadcast_config(config_data)
for file_name, config_data in session.services.all_files(service):
file_data = FileData(
message_type=MessageFlags.ADD.value,
node=node_id,
name=str(file_name),
type=opaque,
data=str(config_data)
)
session.broadcast_file(file_data)
# TODO: send location info
# send hook scripts
for state in sorted(session._hooks.keys()):
for file_name, config_data in session._hooks[state]:
file_data = FileData(
message_type=MessageFlags.ADD.value,
name=str(file_name),
type="hook:%s" % state,
data=str(config_data)
)
session.broadcast_file(file_data)
# send session configuration
session_config = session.options.get_configs()
config_data = ConfigShim.config_data(0, None, ConfigFlags.UPDATE.value, session.options, session_config)
session.broadcast_config(config_data)
# send session metadata
configs = session.metadata.get_configs()
if configs:
data_values = "|".join(["%s=%s" % item for item in configs.iteritems()])
data_types = tuple(ConfigDataTypes.STRING.value for _ in session.metadata.get_configs())
config_data = ConfigData(
message_type=0,
object=session.metadata.name,
type=ConfigFlags.NONE.value,
data_types=data_types,
data_values=data_values
)
session.broadcast_config(config_data)
logging.debug("informed GUI about %d nodes and %d links", len(nodes_data), len(links_data))
class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
def __init__(self, coreemu):
super(CoreGrpcServer, self).__init__()

View file

@ -602,47 +602,47 @@ message OpenXmlResponse {
// data structures for messages below
enum MessageType {
NOTHING = 0;
ADD = 1;
DELETE = 2;
CRI = 4;
LOCAL = 8;
STRING = 16;
TEXT = 32;
TTY = 64;
MESSAGE_NONE = 0;
MESSAGE_ADD = 1;
MESSAGE_DELETE = 2;
MESSAGE_CRI = 4;
MESSAGE_LOCAL = 8;
MESSAGE_STRING = 16;
MESSAGE_TEXT = 32;
MESSAGE_TTY = 64;
}
enum SessionState {
NONE = 0;
DEFINITION = 1;
CONFIGURATION = 2;
INSTANTIATION = 3;
RUNTIME = 4;
DATACOLLECT = 5;
SHUTDOWN = 6;
STATE_NONE = 0;
STATE_DEFINITION = 1;
STATE_CONFIGURATION = 2;
STATE_INSTANTIATION = 3;
STATE_RUNTIME = 4;
STATE_DATACOLLECT = 5;
STATE_SHUTDOWN = 6;
}
enum NodeType {
DEFAULT = 0;
PHYSICAL = 1;
TBD = 3;
SWITCH = 4;
HUB = 5;
WIRELESS_LAN = 6;
RJ45 = 7;
TUNNEL = 8;
KTUNNEL = 9;
EMANE = 10;
TAP_BRIDGE = 11;
PEER_TO_PEER = 12;
CONTROL_NET = 13;
EMANE_NET = 14;
NODE_DEFAULT = 0;
NODE_PHYSICAL = 1;
NODE_TBD = 3;
NODE_SWITCH = 4;
NODE_HUB = 5;
NODE_WIRELESS_LAN = 6;
NODE_RJ45 = 7;
NODE_TUNNEL = 8;
NODE_KTUNNEL = 9;
NODE_EMANE = 10;
NODE_TAP_BRIDGE = 11;
NODE_PEER_TO_PEER = 12;
NODE_CONTROL_NET = 13;
NODE_EMANE_NET = 14;
}
enum ServiceValidationMode {
BLOCKING = 0;
NON_BLOCKING = 1;
TIMER = 2;
VALIDATION_BLOCKING = 0;
VALIDATION_NON_BLOCKING = 1;
VALIDATION_TIMER = 2;
}
enum ServiceAction {
@ -660,10 +660,10 @@ enum MobilityAction {
enum ExceptionLevel {
EXCEPTION_DEFAULT = 0;
FATAL = 1;
ERROR = 2;
WARNING = 3;
NOTICE = 4;
EXCEPTION_FATAL = 1;
EXCEPTION_ERROR = 2;
EXCEPTION_WARNING = 3;
EXCEPTION_NOTICE = 4;
}
message Hook {

View file

@ -72,7 +72,7 @@ class TestGrpc:
response = client.get_session(session.session_id)
# then
assert response.session.state == core_pb2.DEFINITION
assert response.session.state == core_pb2.STATE_DEFINITION
assert len(response.session.nodes) == 1
assert len(response.session.links) == 0
@ -277,7 +277,7 @@ class TestGrpc:
# then
with client.context_connect():
response = client.save_xml(session.session_id, str(tmp))
client.save_xml(session.session_id, str(tmp))
# then
assert tmp.exists()