encapsulated grpc enums within messages to help provide better namespace separation due to python/c code generation
This commit is contained in:
parent
ec672d209f
commit
2ed2b4a879
4 changed files with 102 additions and 86 deletions
|
@ -422,7 +422,7 @@ class CoreGrpcClient(object):
|
||||||
:raises grpc.RpcError: when session or one of the nodes don't exist
|
:raises grpc.RpcError: when session or one of the nodes don't exist
|
||||||
"""
|
"""
|
||||||
link = core_pb2.Link(
|
link = core_pb2.Link(
|
||||||
node_one_id=node_one_id, node_two_id=node_two_id, type=core_pb2.LINK_WIRED,
|
node_one_id=node_one_id, node_two_id=node_two_id, type=core_pb2.LinkType.WIRED,
|
||||||
interface_one=interface_one, interface_two=interface_two, options=options)
|
interface_one=interface_one, interface_two=interface_two, options=options)
|
||||||
request = core_pb2.AddLinkRequest(session_id=session_id, link=link)
|
request = core_pb2.AddLinkRequest(session_id=session_id, link=link)
|
||||||
return self.stub.AddLink(request)
|
return self.stub.AddLink(request)
|
||||||
|
|
|
@ -676,11 +676,11 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
|
||||||
session = self.get_session(request.session_id, context)
|
session = self.get_session(request.session_id, context)
|
||||||
node = self.get_node(session, request.node_id, context)
|
node = self.get_node(session, request.node_id, context)
|
||||||
result = True
|
result = True
|
||||||
if request.action == core_pb2.MOBILITY_START:
|
if request.action == core_pb2.MobilityAction.START:
|
||||||
node.mobility.start()
|
node.mobility.start()
|
||||||
elif request.action == core_pb2.MOBILITY_PAUSE:
|
elif request.action == core_pb2.MobilityAction.PAUSE:
|
||||||
node.mobility.pause()
|
node.mobility.pause()
|
||||||
elif request.action == core_pb2.MOBILITY_STOP:
|
elif request.action == core_pb2.MobilityAction.STOP:
|
||||||
node.mobility.stop(move_initial=True)
|
node.mobility.stop(move_initial=True)
|
||||||
else:
|
else:
|
||||||
result = False
|
result = False
|
||||||
|
@ -774,15 +774,15 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
|
||||||
context.abort(grpc.StatusCode.NOT_FOUND, "service not found")
|
context.abort(grpc.StatusCode.NOT_FOUND, "service not found")
|
||||||
|
|
||||||
status = -1
|
status = -1
|
||||||
if request.action == core_pb2.SERVICE_START:
|
if request.action == core_pb2.ServiceAction.START:
|
||||||
status = session.services.startup_service(node, service, wait=True)
|
status = session.services.startup_service(node, service, wait=True)
|
||||||
elif request.action == core_pb2.SERVICE_STOP:
|
elif request.action == core_pb2.ServiceAction.STOP:
|
||||||
status = session.services.stop_service(node, service)
|
status = session.services.stop_service(node, service)
|
||||||
elif request.action == core_pb2.SERVICE_RESTART:
|
elif request.action == core_pb2.ServiceAction.RESTART:
|
||||||
status = session.services.stop_service(node, service)
|
status = session.services.stop_service(node, service)
|
||||||
if not status:
|
if not status:
|
||||||
status = session.services.startup_service(node, service, wait=True)
|
status = session.services.startup_service(node, service, wait=True)
|
||||||
elif request.action == core_pb2.SERVICE_VALIDATE:
|
elif request.action == core_pb2.ServiceAction.VALIDATE:
|
||||||
status = session.services.validate_service(node, service)
|
status = session.services.validate_service(node, service)
|
||||||
|
|
||||||
result = False
|
result = False
|
||||||
|
|
|
@ -128,7 +128,7 @@ message CreateSessionRequest {
|
||||||
|
|
||||||
message CreateSessionResponse {
|
message CreateSessionResponse {
|
||||||
int32 session_id = 1;
|
int32 session_id = 1;
|
||||||
SessionState state = 2;
|
SessionState.Enum state = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
message DeleteSessionRequest {
|
message DeleteSessionRequest {
|
||||||
|
@ -192,7 +192,7 @@ message SetSessionLocationResponse {
|
||||||
|
|
||||||
message SetSessionStateRequest {
|
message SetSessionStateRequest {
|
||||||
int32 session_id = 1;
|
int32 session_id = 1;
|
||||||
SessionState state = 2;
|
SessionState.Enum state = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
message SetSessionStateResponse {
|
message SetSessionStateResponse {
|
||||||
|
@ -212,7 +212,7 @@ message LinkEventsRequest {
|
||||||
}
|
}
|
||||||
|
|
||||||
message LinkEvent {
|
message LinkEvent {
|
||||||
MessageType message_type = 1;
|
MessageType.Enum message_type = 1;
|
||||||
Link link = 2;
|
Link link = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -234,7 +234,7 @@ message ConfigEventsRequest {
|
||||||
}
|
}
|
||||||
|
|
||||||
message ConfigEvent {
|
message ConfigEvent {
|
||||||
MessageType message_type = 1;
|
MessageType.Enum message_type = 1;
|
||||||
int32 node_id = 2;
|
int32 node_id = 2;
|
||||||
string object = 3;
|
string object = 3;
|
||||||
int32 type = 4;
|
int32 type = 4;
|
||||||
|
@ -257,7 +257,7 @@ message ExceptionEventsRequest {
|
||||||
message ExceptionEvent {
|
message ExceptionEvent {
|
||||||
int32 node_id = 1;
|
int32 node_id = 1;
|
||||||
int32 session_id = 2;
|
int32 session_id = 2;
|
||||||
ExceptionLevel level = 3;
|
ExceptionLevel.Enum level = 3;
|
||||||
string source = 4;
|
string source = 4;
|
||||||
string date = 5;
|
string date = 5;
|
||||||
string text = 6;
|
string text = 6;
|
||||||
|
@ -269,7 +269,7 @@ message FileEventsRequest {
|
||||||
}
|
}
|
||||||
|
|
||||||
message FileEvent {
|
message FileEvent {
|
||||||
MessageType message_type = 1;
|
MessageType.Enum message_type = 1;
|
||||||
int32 node_id = 2;
|
int32 node_id = 2;
|
||||||
string name = 3;
|
string name = 3;
|
||||||
string mode = 4;
|
string mode = 4;
|
||||||
|
@ -412,7 +412,7 @@ message SetMobilityConfigResponse {
|
||||||
message MobilityActionRequest {
|
message MobilityActionRequest {
|
||||||
int32 session_id = 1;
|
int32 session_id = 1;
|
||||||
int32 node_id = 2;
|
int32 node_id = 2;
|
||||||
MobilityAction action = 3;
|
MobilityAction.Enum action = 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
message MobilityActionResponse {
|
message MobilityActionResponse {
|
||||||
|
@ -494,7 +494,7 @@ message ServiceActionRequest {
|
||||||
int32 session_id = 1;
|
int32 session_id = 1;
|
||||||
int32 node_id = 2;
|
int32 node_id = 2;
|
||||||
string service = 3;
|
string service = 3;
|
||||||
ServiceAction action = 4;
|
ServiceAction.Enum action = 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
message ServiceActionResponse {
|
message ServiceActionResponse {
|
||||||
|
@ -598,78 +598,94 @@ message OpenXmlResponse {
|
||||||
}
|
}
|
||||||
|
|
||||||
// data structures for messages below
|
// data structures for messages below
|
||||||
enum MessageType {
|
message MessageType {
|
||||||
MESSAGE_NONE = 0;
|
enum Enum {
|
||||||
MESSAGE_ADD = 1;
|
NONE = 0;
|
||||||
MESSAGE_DELETE = 2;
|
ADD = 1;
|
||||||
MESSAGE_CRI = 4;
|
DELETE = 2;
|
||||||
MESSAGE_LOCAL = 8;
|
CRI = 4;
|
||||||
MESSAGE_STRING = 16;
|
LOCAL = 8;
|
||||||
MESSAGE_TEXT = 32;
|
STRING = 16;
|
||||||
MESSAGE_TTY = 64;
|
TEXT = 32;
|
||||||
|
TTY = 64;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
enum LinkType {
|
message LinkType {
|
||||||
LINK_WIRELESS = 0;
|
enum Enum {
|
||||||
LINK_WIRED = 1;
|
WIRELESS = 0;
|
||||||
|
WIRED = 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
enum SessionState {
|
message SessionState {
|
||||||
STATE_NONE = 0;
|
enum Enum {
|
||||||
STATE_DEFINITION = 1;
|
NONE = 0;
|
||||||
STATE_CONFIGURATION = 2;
|
DEFINITION = 1;
|
||||||
STATE_INSTANTIATION = 3;
|
CONFIGURATION = 2;
|
||||||
STATE_RUNTIME = 4;
|
INSTANTIATION = 3;
|
||||||
STATE_DATACOLLECT = 5;
|
RUNTIME = 4;
|
||||||
STATE_SHUTDOWN = 6;
|
DATACOLLECT = 5;
|
||||||
|
SHUTDOWN = 6;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
enum NodeType {
|
message NodeType {
|
||||||
NODE_DEFAULT = 0;
|
enum Enum {
|
||||||
NODE_PHYSICAL = 1;
|
DEFAULT = 0;
|
||||||
NODE_TBD = 3;
|
PHYSICAL = 1;
|
||||||
NODE_SWITCH = 4;
|
TBD = 3;
|
||||||
NODE_HUB = 5;
|
SWITCH = 4;
|
||||||
NODE_WIRELESS_LAN = 6;
|
HUB = 5;
|
||||||
NODE_RJ45 = 7;
|
WIRELESS_LAN = 6;
|
||||||
NODE_TUNNEL = 8;
|
RJ45 = 7;
|
||||||
NODE_KTUNNEL = 9;
|
TUNNEL = 8;
|
||||||
NODE_EMANE = 10;
|
KTUNNEL = 9;
|
||||||
NODE_TAP_BRIDGE = 11;
|
EMANE = 10;
|
||||||
NODE_PEER_TO_PEER = 12;
|
TAP_BRIDGE = 11;
|
||||||
NODE_CONTROL_NET = 13;
|
PEER_TO_PEER = 12;
|
||||||
NODE_EMANE_NET = 14;
|
CONTROL_NET = 13;
|
||||||
|
EMANE_NET = 14;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
enum ServiceValidationMode {
|
message ServiceValidationMode {
|
||||||
VALIDATION_BLOCKING = 0;
|
enum Enum {
|
||||||
VALIDATION_NON_BLOCKING = 1;
|
BLOCKING = 0;
|
||||||
VALIDATION_TIMER = 2;
|
NON_BLOCKING = 1;
|
||||||
|
TIMER = 2;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
enum ServiceAction {
|
message ServiceAction {
|
||||||
SERVICE_START = 0;
|
enum Enum {
|
||||||
SERVICE_STOP = 1;
|
START = 0;
|
||||||
SERVICE_RESTART = 2;
|
STOP = 1;
|
||||||
SERVICE_VALIDATE = 3;
|
RESTART = 2;
|
||||||
|
VALIDATE = 3;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
enum MobilityAction {
|
message MobilityAction {
|
||||||
MOBILITY_START = 0;
|
enum Enum {
|
||||||
MOBILITY_PAUSE = 1;
|
START = 0;
|
||||||
MOBILITY_STOP = 2;
|
PAUSE = 1;
|
||||||
|
STOP = 2;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
enum ExceptionLevel {
|
message ExceptionLevel {
|
||||||
EXCEPTION_DEFAULT = 0;
|
enum Enum {
|
||||||
EXCEPTION_FATAL = 1;
|
DEFAULT = 0;
|
||||||
EXCEPTION_ERROR = 2;
|
FATAL = 1;
|
||||||
EXCEPTION_WARNING = 3;
|
ERROR = 2;
|
||||||
EXCEPTION_NOTICE = 4;
|
WARNING = 3;
|
||||||
|
NOTICE = 4;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
message Hook {
|
message Hook {
|
||||||
SessionState state = 1;
|
SessionState.Enum state = 1;
|
||||||
string file = 2;
|
string file = 2;
|
||||||
bytes data = 3;
|
bytes data = 3;
|
||||||
}
|
}
|
||||||
|
@ -691,7 +707,7 @@ message NodeServiceData {
|
||||||
repeated string configs = 4;
|
repeated string configs = 4;
|
||||||
repeated string startup = 5;
|
repeated string startup = 5;
|
||||||
repeated string validate = 6;
|
repeated string validate = 6;
|
||||||
ServiceValidationMode validation_mode = 7;
|
ServiceValidationMode.Enum validation_mode = 7;
|
||||||
int32 validation_timer = 8;
|
int32 validation_timer = 8;
|
||||||
repeated string shutdown = 9;
|
repeated string shutdown = 9;
|
||||||
string meta = 10;
|
string meta = 10;
|
||||||
|
@ -712,21 +728,21 @@ message ConfigOption {
|
||||||
|
|
||||||
message Session {
|
message Session {
|
||||||
int32 id = 1;
|
int32 id = 1;
|
||||||
SessionState state = 2;
|
SessionState.Enum state = 2;
|
||||||
repeated Node nodes = 3;
|
repeated Node nodes = 3;
|
||||||
repeated Link links = 4;
|
repeated Link links = 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
message SessionSummary {
|
message SessionSummary {
|
||||||
int32 id = 1;
|
int32 id = 1;
|
||||||
SessionState state = 2;
|
SessionState.Enum state = 2;
|
||||||
int32 nodes = 3;
|
int32 nodes = 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
message Node {
|
message Node {
|
||||||
int32 id = 1;
|
int32 id = 1;
|
||||||
string name = 2;
|
string name = 2;
|
||||||
NodeType type = 3;
|
NodeType.Enum type = 3;
|
||||||
string model = 4;
|
string model = 4;
|
||||||
Position position = 5;
|
Position position = 5;
|
||||||
repeated string services = 6;
|
repeated string services = 6;
|
||||||
|
@ -738,7 +754,7 @@ message Node {
|
||||||
message Link {
|
message Link {
|
||||||
int32 node_one_id = 1;
|
int32 node_one_id = 1;
|
||||||
int32 node_two_id = 2;
|
int32 node_two_id = 2;
|
||||||
LinkType type = 3;
|
LinkType.Enum type = 3;
|
||||||
Interface interface_one = 4;
|
Interface interface_one = 4;
|
||||||
Interface interface_two = 5;
|
Interface interface_two = 5;
|
||||||
LinkOptions options = 6;
|
LinkOptions options = 6;
|
||||||
|
|
|
@ -65,7 +65,7 @@ class TestGrpc:
|
||||||
response = client.get_session(session.id)
|
response = client.get_session(session.id)
|
||||||
|
|
||||||
# then
|
# then
|
||||||
assert response.session.state == core_pb2.STATE_DEFINITION
|
assert response.session.state == core_pb2.SessionState.DEFINITION
|
||||||
assert len(response.session.nodes) == 1
|
assert len(response.session.nodes) == 1
|
||||||
assert len(response.session.links) == 0
|
assert len(response.session.links) == 0
|
||||||
|
|
||||||
|
@ -164,11 +164,11 @@ class TestGrpc:
|
||||||
|
|
||||||
# then
|
# then
|
||||||
with client.context_connect():
|
with client.context_connect():
|
||||||
response = client.set_session_state(session.id, core_pb2.STATE_DEFINITION)
|
response = client.set_session_state(session.id, core_pb2.SessionState.DEFINITION)
|
||||||
|
|
||||||
# then
|
# then
|
||||||
assert response.result is True
|
assert response.result is True
|
||||||
assert session.state == core_pb2.STATE_DEFINITION
|
assert session.state == core_pb2.SessionState.DEFINITION
|
||||||
|
|
||||||
def test_add_node(self, grpc_server):
|
def test_add_node(self, grpc_server):
|
||||||
# given
|
# given
|
||||||
|
@ -254,7 +254,7 @@ class TestGrpc:
|
||||||
# then
|
# then
|
||||||
assert len(response.hooks) == 1
|
assert len(response.hooks) == 1
|
||||||
hook = response.hooks[0]
|
hook = response.hooks[0]
|
||||||
assert hook.state == EventTypes.RUNTIME_STATE.value
|
assert hook.state == core_pb2.SessionState.RUNTIME
|
||||||
assert hook.file == file_name
|
assert hook.file == file_name
|
||||||
assert hook.data == file_data
|
assert hook.data == file_data
|
||||||
|
|
||||||
|
@ -267,7 +267,7 @@ class TestGrpc:
|
||||||
file_name = "test"
|
file_name = "test"
|
||||||
file_data = "echo hello"
|
file_data = "echo hello"
|
||||||
with client.context_connect():
|
with client.context_connect():
|
||||||
response = client.add_hook(session.id, core_pb2.STATE_RUNTIME, file_name, file_data)
|
response = client.add_hook(session.id, core_pb2.SessionState.RUNTIME, file_name, file_data)
|
||||||
|
|
||||||
# then
|
# then
|
||||||
assert response.result is True
|
assert response.result is True
|
||||||
|
@ -591,7 +591,7 @@ class TestGrpc:
|
||||||
|
|
||||||
# then
|
# then
|
||||||
with client.context_connect():
|
with client.context_connect():
|
||||||
response = client.mobility_action(session.id, wlan.objid, core_pb2.MOBILITY_STOP)
|
response = client.mobility_action(session.id, wlan.objid, core_pb2.MobilityAction.STOP)
|
||||||
|
|
||||||
# then
|
# then
|
||||||
assert response.result is True
|
assert response.result is True
|
||||||
|
@ -666,16 +666,16 @@ class TestGrpc:
|
||||||
session = grpc_server.coreemu.create_session()
|
session = grpc_server.coreemu.create_session()
|
||||||
node = session.add_node()
|
node = session.add_node()
|
||||||
service_name = "IPForward"
|
service_name = "IPForward"
|
||||||
validate = ("echo hello",)
|
validate = ["echo hello"]
|
||||||
|
|
||||||
# then
|
# then
|
||||||
with client.context_connect():
|
with client.context_connect():
|
||||||
response = client.set_node_service(session.id, node.objid, service_name, (), validate, ())
|
response = client.set_node_service(session.id, node.objid, service_name, [], validate, [])
|
||||||
|
|
||||||
# then
|
# then
|
||||||
assert response.result is True
|
assert response.result is True
|
||||||
service = session.services.get_service(node.objid, service_name, default_service=True)
|
service = session.services.get_service(node.objid, service_name, default_service=True)
|
||||||
assert service.validate == validate
|
assert service.validate == tuple(validate)
|
||||||
|
|
||||||
def test_set_node_service_file(self, grpc_server):
|
def test_set_node_service_file(self, grpc_server):
|
||||||
# given
|
# given
|
||||||
|
@ -704,7 +704,7 @@ class TestGrpc:
|
||||||
|
|
||||||
# then
|
# then
|
||||||
with client.context_connect():
|
with client.context_connect():
|
||||||
response = client.service_action(session.id, node.objid, service_name, core_pb2.SERVICE_STOP)
|
response = client.service_action(session.id, node.objid, service_name, core_pb2.ServiceAction.STOP)
|
||||||
|
|
||||||
# then
|
# then
|
||||||
assert response.result is True
|
assert response.result is True
|
||||||
|
|
Loading…
Reference in a new issue