syntax = "proto3";
package context;

service ContextService {
  rpc GetContextIds (Empty     ) returns (ContextIdList ) {}
  rpc GetContexts   (Empty     ) returns (ContextList   ) {}
  rpc GetContext    (ContextId ) returns (Context       ) {}
  rpc SetContext    (Context   ) returns (ContextId     ) {}
  rpc DeleteContext (ContextId ) returns (Empty         ) {}

  rpc GetTopologyIds(ContextId ) returns (TopologyIdList) {}
  rpc GetTopologies (ContextId ) returns (TopologyList  ) {}
  rpc GetTopology   (TopologyId) returns (Topology      ) {}
  rpc SetTopology   (Topology  ) returns (TopologyId    ) {}
  rpc DeleteTopology(TopologyId) returns (Empty         ) {}

  rpc GetDeviceIds  (Empty     ) returns (DeviceIdList  ) {}
  rpc GetDevices    (Empty     ) returns (DeviceList    ) {}
  rpc GetDevice     (DeviceId  ) returns (Device        ) {}
  rpc SetDevice     (Device    ) returns (DeviceId      ) {}
  rpc RemoveDevice  (DeviceId  ) returns (Empty         ) {}

  rpc GetLinkIds    (Empty     ) returns (LinkIdList    ) {}
  rpc GetLinks      (Empty     ) returns (LinkList      ) {}
  rpc GetLink       (LinkId    ) returns (Link          ) {}
  rpc SetLink       (Link      ) returns (LinkId        ) {}
  rpc DeleteLink    (LinkId    ) returns (Empty         ) {}

  rpc GetServiceIds (ContextId ) returns (ServiceIdList ) {}
  rpc GetServices   (ContextId ) returns (ServiceList   ) {}
  rpc GetService    (ServiceId ) returns (Service       ) {}
  rpc SetService    (Service   ) returns (ServiceId     ) {}
  rpc DeleteService (ServiceId ) returns (Empty         ) {}
}

// ----- Generic -------------------------------------------------------------------------------------------------------
message Empty {}

message Uuid {
  string uuid = 1;
}


// ----- Context -------------------------------------------------------------------------------------------------------
message ContextId {
  Uuid context_uuid = 1;
}

message Context {
  ContextId context_id = 1;
  repeated Topology topology = 2;
  TeraFlowController controller = 3;
}

message ContextIdList {
  repeated ContextId context_ids = 1;
}

message ContextList {
  repeated Context contexts = 1;
}


// ----- Topology ------------------------------------------------------------------------------------------------------
message TopologyId {
  ContextId context_id = 1;
  Uuid topology_uuid = 2;
}

message Topology {
  TopologyId topology_id = 1;
  repeated Device devices = 2;
  repeated Link links = 3;
}

message TopologyIdList {
  repeated TopologyId topology_ids = 1;
}

message TopologyList {
  repeated Topology topologies = 1;
}


// ----- Device --------------------------------------------------------------------------------------------------------
message DeviceId {
  Uuid device_uuid = 1;
}

message Device {
  DeviceId device_id = 1;
  string device_type = 2;
  DeviceConfig device_config = 3;
  DeviceOperationalStatus devive_operational_status = 4;
  repeated DeviceDriver device_drivers = 5;
  repeated EndPoint endpoints = 6;
}

message DeviceConfig {
  repeated ConfigRule config_rules = 1;
}

enum DeviceDriver {
  DRIVER_UNDEFINED = 0; // also used for emulated
  DRIVER_OPENCONFIG = 1;
  DRIVER_TRANSPORT_API = 2;
  DRIVER_P4 = 3;
  DRIVER_IETF_NETWORK_TOPOLOGY = 4;
  DRIVER_ONF_TR_352 = 5;
}

enum DeviceOperationalStatus {
  KEEP_STATUS = 0; // Do not change operational status of device (used in configure)
  DISABLED = -1;
  ENABLED = 1;
}

message DeviceIdList {
  repeated DeviceId device_ids = 1;
}

message DeviceList {
  repeated Device devices = 1;
}


// ----- Link ----------------------------------------------------------------------------------------------------------
message LinkId {
  Uuid link_uuid = 1;
}

message Link {
  LinkId link_id = 1;
  repeated EndPointId endpoints = 2;
}

message LinkIdList {
  repeated LinkId link_ids = 1;
}

message LinkList {
  repeated Link links = 1;
}


// ----- Service -------------------------------------------------------------------------------------------------------
message ServiceId {
  ContextId context_id = 1;
  Uuid service_uuid = 2;
}

message Service {
  ServiceId service_id = 1;
  ServiceType service_type = 2;
  repeated EndPointId endpoints = 3;
  repeated Constraint constraints = 4;
  ServiceState service_state = 5;
  ServiceConfig service_config = 6;
}

enum ServiceType {
  SERVICETYPE_UNKNOWN = 0;
  SERVICETYPE_L3NM = 1;
  SERVICETYPE_L2NM = 2;
  SERVICETYPE_TAPI_CONNECTIVITY_SERVICE = 3;
}

enum ServiceStateEnum {
  SERVICESTATUS_PLANNED = 0;
  SERVICESTATUS_ACTIVE =  1;
  SERVICESTATUS_PENDING_REMOVAL = 2;
}

message ServiceState {
  ServiceStateEnum service_state = 1;
}

message ServiceConfig {
  repeated ConfigRule config_rules = 1;
}

message ServiceIdList {
  repeated ServiceId service_ids = 1;
}

message ServiceList {
  repeated Service services = 1;
}


// ----- Endpoint ------------------------------------------------------------------------------------------------------
message EndPointId {
  TopologyId topology_id = 1;
  DeviceId device_id = 2;
  Uuid endpoint_uuid = 3;
}

message EndPoint {
  EndPointId endpoint_id = 1;
  string port_type = 2;
}


// ----- Configuration -------------------------------------------------------------------------------------------------
enum ConfigAction {
  CONFIGACTION_UNDEFINED = 0;
  CONFIGACTION_SET = 1;
  CONFIGACTION_DELETE = 2;
}

message ConfigRule {
  ConfigAction action = 1;
  string resource_key = 2;
  string resource_value = 3;
}


// ----- Constraint ----------------------------------------------------------------------------------------------------
message Constraint {
  string constraint_type = 1;
  string constraint_value = 2;
}


// ----- Connection ----------------------------------------------------------------------------------------------------
message ConnectionId {
  Uuid connection_uuid = 1;
}

message Connection {
  ConnectionId connection_id = 1;
  ServiceId related_service_id = 2;
  repeated EndPointId path = 3;
}

message ConnectionIdList {
  repeated ConnectionId connection_ids = 1;
}

message ConnectionList {
  repeated Connection connections = 1;
}


// ----- Miscellaneous -------------------------------------------------------------------------------------------------
message TeraFlowController {
  ContextId context_id = 1;
  string ip_address = 2;
  uint32 port = 3;
}

message AuthenticationResult {
  ContextId context_id = 1;
  bool authenticated = 2;
}
