// Use generate_pb_grpc.sh to regenerate protobuf and gRPC service definitions.
// Paths and package names here, together with the directory this file resides in, are critical
// for gRPC to work in multiple languages.

syntax = "proto3";

package faucetconfserver;
option go_package = "faucetconfserver/";

// NOTE: currently some of these API calls allow specifying an optional config_file.
// This will be removed in future so the client does not need/have knowledge of the underlying YAML store.
service FaucetConfServer {
  rpc GetConfigFile(GetConfigFileRequest) returns (GetConfigFileReply) {}
  rpc SetConfigFile(SetConfigFileRequest) returns (SetConfigFileReply) {}
  rpc DelConfigFromFile(DelConfigFromFileRequest) returns (DelConfigFromFileReply) {}
  rpc AddPortMirror(AddPortMirrorRequest) returns (AddPortMirrorReply) {}
  rpc RemovePortMirror(RemovePortMirrorRequest) returns (RemovePortMirrorReply) {}
  rpc ClearPortMirror(ClearPortMirrorRequest) returns (ClearPortMirrorReply) {}
  rpc AddPortAcl(AddPortAclRequest) returns (AddPortAclReply) {}
  rpc RemovePortAcl(RemovePortAclRequest) returns (RemovePortAclReply) {}    
  rpc SetPortAcl(SetPortAclRequest) returns (SetPortAclReply) {}
  rpc SetDpInterfaces(SetDpInterfacesRequest) returns (SetDpInterfacesReply) {}
  rpc GetDpInfo(GetDpInfoRequest) returns (GetDpInfoReply) {}
  rpc DelDpInterfaces(DelDpInterfacesRequest) returns (DelDpInterfacesReply) {}
  rpc DelDps(DelDpsRequest) returns (DelDpsReply) {}
  rpc SetRemoteMirrorPort(SetRemoteMirrorPortRequest) returns (SetRemoteMirrorPortReply) {}
  rpc GetDpNames(GetDpNamesRequest) returns (GetDpNamesReply) {}
  rpc GetDpIDs(GetDpIDsRequest) returns (GetDpIDsReply) {}
  rpc GetAclNames(GetAclNamesRequest) returns (GetAclNamesReply) {}
  rpc SetDps(SetDpsRequest) returns (SetDpsReply) {}
  rpc MakeCoprocessorPort(MakeCoprocessorPortRequest) returns (MakeCoprocessorPortReply) {}
  rpc SetVlanOutAcl(SetVlanOutAclRequest) returns (SetVlanOutAclReply) {}
}

// Retrieve YAML config.
message GetConfigFileRequest {
  // Optional: retrieve YAML from this file.
  string config_filename = 1;
}

message GetConfigFileReply {
  string config_yaml = 1;
}

// Set current YAML config, optionally merging or overwriting.
message SetConfigFileRequest {
  string config_filename = 1;
  string config_yaml = 2;
  // If true, then merge new YAML dict in with current.
  bool merge = 3;
  // If set, execute YAML delete per DelConfigFromFileRequest, below.
  string del_config_yaml_keys = 4;
}

message SetConfigFileReply {
}

// Delete a YAML config tree/list item.
message DelConfigFromFileRequest {
  // Optional: delete YAML from this file.
  string config_filename = 1;
  // '[key1, key2', 99]' will delete {key1: {key2: 99}}
  // '[key1, key2']' will delete {key1: {key2}}
  string config_yaml_keys = 2;
}

message DelConfigFromFileReply {
}

// Set a port to mirror to another DP
message SetRemoteMirrorPortRequest {
  string dp_name = 1;
  uint32 port_no = 2;
  uint32 tunnel_vid = 3;
  string remote_dp_name = 4;
  uint32 remote_port_no = 5;
}

message SetRemoteMirrorPortReply {
}

// Add mirroring to a port.
message AddPortMirrorRequest {
  string dp_name = 1;
  uint32 port_no = 2;
  uint32 mirror_port_no = 3;
}

message AddPortMirrorReply {
}

// Configure a port as a coprocessor port.
message MakeCoprocessorPortRequest {
  string dp_name = 1;
  uint32 port_no = 2;
  string description = 3;
  string strategy = 4;
}

message MakeCoprocessorPortReply {  
}

// Remove mirroring from a port.
message RemovePortMirrorRequest {
  string dp_name = 1;
  uint32 port_no = 2;
  uint32 mirror_port_no = 3;
}

message RemovePortMirrorReply {
}

message ClearPortMirrorRequest {
  string dp_name = 1;
  uint32 mirror_port_no = 2;
}

message ClearPortMirrorReply {
}

// Overwrite VLAN output ACL
message SetVlanOutAclRequest {
  string vlan_name = 1;
  string acl_out = 2;
}

message SetVlanOutAclReply {
}

// Overwrite ACL list on a port.
message SetPortAclRequest {
  string dp_name = 1;
  uint32 port_no = 2;
  string acls = 3;
}

message SetPortAclReply {
}

message AddPortAclRequest {
  string dp_name = 1;
  uint32 port_no = 2;
  string acl = 3;
}

message AddPortAclReply {
}

// Remove named ACL from port, or all if no ACL name.
message RemovePortAclRequest {
  string dp_name = 1;
  uint32 port_no = 2;
  string acl = 3;
}

message RemovePortAclReply {
}

message SetInterface {
  uint32 port_no = 1;
  string config_yaml = 2;
}

message SetDpInterfaces {
  string dp_name = 1;
  repeated SetInterface interface_config = 2;
}

// Set/replace config for any number of DPs/interfaces.
message SetDpInterfacesRequest {
  repeated SetDpInterfaces interfaces_config = 1;
}

message SetDpInterfacesReply {
}

// Request DP info.
message GetDpInfoRequest {
  // Optional: if specified, only info about this DP will be returned, otherwise all DPs.
  string dp_name = 1;
  // Optional: look up DPs in only this YAML file.
  string config_filename = 2;
}

message InterfaceInfo {
  uint32 port_no = 1;
  string name = 2;
  string description = 3;
}

message DpInfo {
  string name = 1;
  uint64 dp_id = 2;
  string description = 3;
  repeated InterfaceInfo interfaces = 4;
}

message GetDpInfoReply {
  repeated DpInfo dps = 1;
}

message DelDpInterfacesRequest {
  repeated DpInfo interfaces_config = 1;
  bool delete_empty_dp = 2;
}

message DelDpInterfacesReply {
}

message DelDpsRequest {
  repeated DpInfo interfaces_config = 1;
}

message DelDpsReply {
}

message GetDpNamesRequest {
}

message GetDpNamesReply {
  repeated string dp_name = 1;
}

message GetDpIDsRequest {
}

message GetDpIDsReply {
  repeated uint64 dp_id = 1;
}

message GetAclNamesRequest {
  repeated string acl_name = 1;
}

message GetAclNamesReply {
  repeated string acl_name = 1;
}

message SetDp {
  string dp_name = 1;
  string config_yaml = 2;
}

message SetDpsRequest {
  repeated SetDp dp_config = 1;
}

message SetDpsReply {
}
