From 30415cd41ef2ae62841417b4a6a9113129cd718d Mon Sep 17 00:00:00 2001 From: Ze Gan Date: Wed, 31 May 2023 11:44:19 +0800 Subject: [PATCH] [proto]: Initial proto files (#1) Initial version for protobuf files and its conversion. Based on: https://github.com/sonic-net/DASH/blob/f0517f92b70d05a3b3d55268bec1795c4434f684/documentation/general/dash-sonic-hld.md Signed-off-by: Ze Gan --- .gitignore | 2 ++ Readme.md | 22 +++++++++++++++ proto/acl_group.proto | 14 +++++++++ proto/acl_in.proto | 18 ++++++++++++ proto/acl_out.proto | 18 ++++++++++++ proto/acl_rule.proto | 46 ++++++++++++++++++++++++++++++ proto/appliance.proto | 17 +++++++++++ proto/eni.proto | 40 ++++++++++++++++++++++++++ proto/meter.proto | 18 ++++++++++++ proto/meter_policy.proto | 14 +++++++++ proto/meter_rule.proto | 18 ++++++++++++ proto/prefix_tag.proto | 16 +++++++++++ proto/qos.proto | 17 +++++++++++ proto/route.proto | 49 ++++++++++++++++++++++++++++++++ proto/route_rule.proto | 35 +++++++++++++++++++++++ proto/route_type.proto | 53 +++++++++++++++++++++++++++++++++++ proto/routing_appliance.proto | 18 ++++++++++++ proto/types.proto | 37 ++++++++++++++++++++++++ proto/vnet.proto | 18 ++++++++++++ proto/vnet_mapping.proto | 40 ++++++++++++++++++++++++++ 20 files changed, 510 insertions(+) create mode 100644 .gitignore create mode 100644 proto/acl_group.proto create mode 100644 proto/acl_in.proto create mode 100644 proto/acl_out.proto create mode 100644 proto/acl_rule.proto create mode 100644 proto/appliance.proto create mode 100644 proto/eni.proto create mode 100644 proto/meter.proto create mode 100644 proto/meter_policy.proto create mode 100644 proto/meter_rule.proto create mode 100644 proto/prefix_tag.proto create mode 100644 proto/qos.proto create mode 100644 proto/route.proto create mode 100644 proto/route_rule.proto create mode 100644 proto/route_type.proto create mode 100644 proto/routing_appliance.proto create mode 100644 proto/types.proto create mode 100644 proto/vnet.proto create mode 100644 proto/vnet_mapping.proto diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b4ee4fd --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +proto/* +!proto/*.proto diff --git a/Readme.md b/Readme.md index f9f886b..3ae91ae 100644 --- a/Readme.md +++ b/Readme.md @@ -1,3 +1,25 @@ # sonic-dash-api This repository hosts the DASH API definition for the SONiC project. The schema of DASH APP DB is at [DASH APP DB](https://github.com/sonic-net/DASH/blob/main/documentation/general/dash-sonic-hld.md#32-dash-app-db) and all entries of DASH APP DB will be encoded as protobuf. + +## Protobuf Convention + +1. File name use underscore case, E.G. `acl_rule.proto` +2. All file except common utility should include and only include one message of entry and one message of its key. +3. Message name of entry use camel case. E.G. `AclRule`. +4. Message name of entry key use the entry name with a fixed postfix `Key`. E.G. `AclRuleKey`. +5. If the value of entry is a list, the item use the entry name with a fixed postfix `Item`. E.G. `RouteTypeItem`. +6. Member variable use underscore case. E.G. `src_addr`. +7. For enumerations type, the enum name use camel case, E.G. `IpVersion` +8. The field of enum use full capital with underscore case, and the enum name use as the prefix for each field. E.G. +`IP_VERSION_IPV4` + +## Redis DB + +1. Table name will be full capital with underscore. And the prefix `DASH` and postfix `Table` will be added to entry name. E.G. `DASH_VNET_MAPPING_TABLE` +2. The key message is sequentially joint as the Redis key with colon separator. E.G. `AclRuleKey{group_id=group1, rule_num=3}`, the key of Redis entry will be `DASH_ACL_RULE_TABLE:group1:3` +3. The value is the entry message with the bytes array of protobuf + +## GNMI + +TODO diff --git a/proto/acl_group.proto b/proto/acl_group.proto new file mode 100644 index 0000000..1a05b10 --- /dev/null +++ b/proto/acl_group.proto @@ -0,0 +1,14 @@ +syntax = "proto3"; + +package dash.acl_group; + +import "types.proto"; + +message AclGroup { + types.IpVersion ip_version = 1; + types.Guid guid = 2; +} + +message AclGroupKey { + string group_id = 1; +} diff --git a/proto/acl_in.proto b/proto/acl_in.proto new file mode 100644 index 0000000..abac5c6 --- /dev/null +++ b/proto/acl_in.proto @@ -0,0 +1,18 @@ +syntax = "proto3"; + +package dash.acl_in; + +message AclIn { + // Optional + // IPv4 ACL group ID + string v4_acl_group_id = 1; + // Optional + // IPv6 ACL group ID + string v6_acl_group_id = 2; +} + +message AclInKey { + string eni = 1; + // ACL stage can be {1, 2, 3, 4, 5} + uint32 stage = 2; +} diff --git a/proto/acl_out.proto b/proto/acl_out.proto new file mode 100644 index 0000000..351b41f --- /dev/null +++ b/proto/acl_out.proto @@ -0,0 +1,18 @@ +syntax = "proto3"; + +package dash.acl_out; + +message AclOut { + // Optional + // IPv4 ACL group ID + string v4_acl_group_id = 1; + // Optional + // IPv6 ACL group ID + string v6_acl_group_id = 2; +} + +message AclOutKey { + string eni = 1; + // ACL stage can be {1, 2, 3, 4, 5} + uint32 stage = 2; +} diff --git a/proto/acl_rule.proto b/proto/acl_rule.proto new file mode 100644 index 0000000..99538c2 --- /dev/null +++ b/proto/acl_rule.proto @@ -0,0 +1,46 @@ +syntax = "proto3"; + +package dash.acl_rule; + +import "types.proto"; + +enum Action { + ACTION_DENY = 0; + ACTION_PERMIT = 1; +} + +message AclRule { + // priority of the rule, lower the value, higher the priority + uint32 priority = 1; + // allow/deny + acl_rule.Action action = 2; + // true/false ; if true, stop processing further rules + bool terminating = 3; + // Optional + // Protocol list. E.g. 6-tcp, 17-udp; if not provided, match on all protocols + repeated uint32 protocol = 4; + // Optional + // list of source tag name, if not provided, match on ANY tag or NO tag. + repeated string src_tag = 9; + // Optional + // list of destination tag name, if not provided, match on ANY tag or NO tag. + repeated string dst_tag = 10; + // Optional + // list of source ip prefixes, if not provided, match on all source IPs. + repeated types.IpPrefix src_addr = 5; + // Optional + // list of destination ip prefixes, if not provided, match on all destination IPs. + repeated types.IpPrefix dst_addr = 6; + // Optional + // list of range of source ports, if not provided, match on all source ports. + repeated types.ValueOrRange src_port = 7; + // Optional + // list of range of destination ports, if not provided, match on all destination ports. + repeated types.ValueOrRange dst_port = 8; +} + +message AclRuleKey { + string group_id = 1; + // unique rule num within the group. + uint32 rule_num = 2; +} diff --git a/proto/appliance.proto b/proto/appliance.proto new file mode 100644 index 0000000..f3749dd --- /dev/null +++ b/proto/appliance.proto @@ -0,0 +1,17 @@ +syntax = "proto3"; + +package dash.appliance; + +import "types.proto"; + +message Appliance { + // source ip address, to be used in encap + types.IpAddress sip = 1; + // VM VNI that is used for setting direction. Also used for inbound encap to VM + uint32 vm_vni = 2; +} + +message ApplianceKey { + // Attributes specific for the appliance + string appliance_id = 1; +} diff --git a/proto/eni.proto b/proto/eni.proto new file mode 100644 index 0000000..f23db7e --- /dev/null +++ b/proto/eni.proto @@ -0,0 +1,40 @@ +syntax = "proto3"; + +package dash.eni; + +import "types.proto"; + +enum State{ + STATE_DISABLED = 0; + STATE_ENABLED = 1; +} + +message Eni { + string eni_id = 1; + bytes mac_address = 2; + // Associated Qos profile + string qos = 3; + // PA address for Inbound encapsulation to VM + types.IpAddress underlay_ip = 4; + // Enabled after all configurations are applied + eni.State admin_state = 5; + // Vnet that ENI belongs to + string vnet = 6; + // Optional + // Private Link encoding for IPv6 SIP transpositions + optional types.IpPrefix pl_sip_encoding = 7; + // Optional + // Underlay SIP (ST GW VIP) to be used for all private link transformation for this ENI + optional types.IpAddress pl_underlay_sip = 8; + // Optional + // IPv4 meter policy ID + optional string v4_meter_policy_id = 9; + // Optional + // IPv6 meter policy ID + optional string v6_meter_policy_id = 10; +} + +message EniKey { + // ENI MAC as key + string eni = 1; +} diff --git a/proto/meter.proto b/proto/meter.proto new file mode 100644 index 0000000..4b08073 --- /dev/null +++ b/proto/meter.proto @@ -0,0 +1,18 @@ +syntax = "proto3"; + +package dash.meter_rule; + +message Meter { + // Optional + optional string metadata = 1; + // Number of transmitted bytes (read-only) + bytes tx_counter = 2; + // Number of received bytes (read-only) + bytes rx_counter = 3; +} + +message MeterKey { + string eni = 1; + // metering class id table per (ENI) + uint64 metering_class_id = 2; +} diff --git a/proto/meter_policy.proto b/proto/meter_policy.proto new file mode 100644 index 0000000..9c3ceab --- /dev/null +++ b/proto/meter_policy.proto @@ -0,0 +1,14 @@ +syntax = "proto3"; + +package dash.meter_policy; + +import "types.proto"; + +message MeterPolicy { + // IP version (IPv4/IPv6) + types.IpVersion ip_version = 1; +} + +message MeterPolicyKey { + string meter_policy_id = 1; +} diff --git a/proto/meter_rule.proto b/proto/meter_rule.proto new file mode 100644 index 0000000..534b571 --- /dev/null +++ b/proto/meter_rule.proto @@ -0,0 +1,18 @@ +syntax = "proto3"; + +package dash.meter_rule; + +import "types.proto"; + +message MeterRule { + // priority of the rule: lower the value, higher the priority + uint32 priority = 1; + // ip prefix for matching + types.IpPrefix ip_prefix = 2; + uint64 metering_class = 3; +} + +message MeterRuleKey { + string meter_policy_id = 1; + uint32 rule_num = 2; +} diff --git a/proto/prefix_tag.proto b/proto/prefix_tag.proto new file mode 100644 index 0000000..5d59c58 --- /dev/null +++ b/proto/prefix_tag.proto @@ -0,0 +1,16 @@ +syntax = "proto3"; + +package dash.tag; + +import "types.proto"; + +message PrefixTag { + types.IpVersion ip_version = 1; + // valid to have empty list of prefixes. + // If the prefix is empty, no packet will be assigned to this TAG. + repeated types.IpPrefix prefix_list = 2; +} + +message PrefixTagKey { + string tag_name = 1; +} diff --git a/proto/qos.proto b/proto/qos.proto new file mode 100644 index 0000000..e787f65 --- /dev/null +++ b/proto/qos.proto @@ -0,0 +1,17 @@ +syntax = "proto3"; + +package dash.qos; + +message Qos { + string qos_id = 1; + // bandwidth in kbps + uint32 bw = 2; + // Number of connection per second + uint32 cps = 3; + // Number of flows + uint32 flows = 4; +} + +message QosKey { + string qos_name = 1; +} diff --git a/proto/route.proto b/proto/route.proto new file mode 100644 index 0000000..f90de90 --- /dev/null +++ b/proto/route.proto @@ -0,0 +1,49 @@ +syntax = "proto3"; + +package dash.route_lpm; + +import "types.proto"; +import "route_type.proto"; + +message VnetDirect { + // destination vnet name if action_type is {vnet, vnet_direct}, a vnet other than eni's vnet means vnet peering + string vnet = 1; + // overly_ip to lookup if routing_type is {vnet_direct}, use dst ip from packet if not specified + optional types.IpAddress overlay_ip = 2; +} + +message ServiceTunnel { + // overlay ipv6 src ip if routing_type is {servicetunnel} + types.IpAddress overlay_sip = 1; + // overlay ipv6 dst ip if routing_type is {servicetunnel} + types.IpAddress overlay_dip = 2; + // underlay ipv4 src ip if routing_type is {servicetunnel}, this is the ST GW VIP (for ST traffic) or custom VIP + types.IpAddress underlay_sip = 3; + // underlay ipv4 dst ip to override if routing_type is {servicetunnel}, use dst ip from packet if not specified + types.IpAddress underlay_dip = 4; +} + +message Route { + route_type.RoutingType action_type = 1; + oneof Action { + // destination vnet name if action_type is vnet,, a vnet other than eni's vnet means vnet peering + string vnet = 2; + // destination vnet name if action_type is vnet_direct,, a vnet other than eni's vnet means vnet peering + string vnet_direct = 3; + // appliance id if action_type is {appliance} + string appliance = 4; + // service tunnel if action_type is {service_tunnel} + route_lpm.ServiceTunnel service_tunnel = 5; + } + // Metering policy lookup enable (optional), default = false + optional bool metering_policy_en = 6; + // Metering class-id, used if metering policy lookup is not enabled + optional uint64 metering_class = 7; +} + +// ENI route table with CA prefix for packet Outbound +message RouteKey { + string eni = 1; + // IP prefix string with prefix length. E.G. 10.1.0.0/16 + string prefix = 2; +} diff --git a/proto/route_rule.proto b/proto/route_rule.proto new file mode 100644 index 0000000..2ee4caa --- /dev/null +++ b/proto/route_rule.proto @@ -0,0 +1,35 @@ +syntax = "proto3"; + +package dash.route_rule; + +import "route_type.proto"; + +message RouteRule { + // reference to routing type, action can be decap or drop + route_type.RoutingType action_type = 1; + // priority of the rule, lower the value, higher the priority + uint32 priority = 2; + // Optional + // protocol value of incoming packet to match; 0 (any) + optional uint32 protocol = 3; + // Optional + // mapped VNET for the key vni/pa + optional string vnet = 4; + // Optional + // perform PA validation in the mapping table belonging to vnet_name. Default is set to true + optional bool pa_validation = 5; + // Optional + // Metering class-id + optional uint64 metering_class = 6; + // Optional + // optional region_id which the vni/prefix belongs to as a string for any vendor optimizations + optional string region = 7; +} + +// ENI Inbound route table with VNI and optional SRC PA prefix +message RouteRuleKey { + string eni = 1; + uint32 vni = 2; + // IP prefix string with prefix length. E.G. 10.1.0.0/16 + string prefix = 3; +}; diff --git a/proto/route_type.proto b/proto/route_type.proto new file mode 100644 index 0000000..84f8835 --- /dev/null +++ b/proto/route_type.proto @@ -0,0 +1,53 @@ +syntax = "proto3"; + +package dash.route_type; + +enum ActionType { + ACTION_TYPE_MAPROUTING = 0; + ACTION_TYPE_DIRECT = 1; + ACTION_TYPE_STATICENCAP = 2; + ACTION_TYPE_APPLIANCE = 3; + ACTION_TYPE_4_to_6 = 4; + ACTION_TYPE_MAPDECAP = 5; + ACTION_TYPE_DECAP = 6; + ACTION_TYPE_DROP = 7; +} + +enum EncapType { + ENCAP_TYPE_VXLAN = 0; + ENCAP_TYPE_NVGRE = 1; +} + +enum RoutingType { + ROUTING_TYPE_DIRECT = 0; + ROUTING_TYPE_VNET = 1; + ROUTING_TYPE_VNET_DIRECT = 2; + ROUTING_TYPE_VNET_ENCAP = 3; + ROUTING_TYPE_APPLIANCE = 4; + ROUTING_TYPE_PRIVATELINK = 5; + ROUTING_TYPE_PRIVATELINKNSG = 6; + ROUTING_TYPE_SERVICETUNNEL = 7; + ROUTING_TYPE_DROP = 8; +} + +message RouteTypeItem { + string action_name = 1; + route_type.ActionType action_type = 2; + // Optional + // encap type depends on the action_type - {vxlan, nvgre} + optional route_type.EncapType encap_type = 3; + // Optional + // vni value associated with the corresponding action. Applicable if encap_type is specified. + optional uint32 vni = 4; +} + +message RouteType { + repeated RouteTypeItem items = 1; +} + +message RouteTypeKey { + // Available value has been enumerated at enum RoutingType. + // Use string as the key for better readability. + // Actions can be a list of action_types + string routing_type = 1; +} diff --git a/proto/routing_appliance.proto b/proto/routing_appliance.proto new file mode 100644 index 0000000..611a08a --- /dev/null +++ b/proto/routing_appliance.proto @@ -0,0 +1,18 @@ +syntax = "proto3"; + +package dash.routing_appliance; + +import "types.proto"; +import "route_type.proto"; + +message RoutingAppliance { + types.Guid appliance_guid = 1; + repeated types.IpAddress addresses = 2; + route_type.EncapType encap_type = 3; + uint32 vni = 4; +} + +message RoutingApplianceKey { + // Used for PL NSG + string appliance_id = 1; +} diff --git a/proto/types.proto b/proto/types.proto new file mode 100644 index 0000000..230e390 --- /dev/null +++ b/proto/types.proto @@ -0,0 +1,37 @@ +syntax = "proto3"; + +package dash.types; + +message IpAddress { + oneof ip { + fixed32 ipv4 = 1; // Network byte order (big-endian) + bytes ipv6 = 2; // Network byte order (big-endian) + } +} + +message IpPrefix { + IpAddress ip = 1; + IpAddress mask = 2; +} + +message Range { + uint32 min = 1; + uint32 max = 2; +} + +message ValueOrRange { +oneof value_or_range { + uint32 value = 1; + Range range = 2; +} +} + +enum IpVersion { + IP_VERSION_IPV4 = 0; + IP_VERSION_IPV6 = 1; +} + +message Guid { + // 128 bits (16 bytes) + bytes value = 1; +} diff --git a/proto/vnet.proto b/proto/vnet.proto new file mode 100644 index 0000000..c75b948 --- /dev/null +++ b/proto/vnet.proto @@ -0,0 +1,18 @@ +syntax = "proto3"; + +package dash.vnet; + +import "types.proto"; + +message Vnet { + uint32 vni = 1; + types.Guid guid = 2; + // Optional + repeated types.IpPrefix address_space = 3; + // Optional + repeated string peer_list = 4; +} + +message VnetKey { + string vnet_name = 1; +} diff --git a/proto/vnet_mapping.proto b/proto/vnet_mapping.proto new file mode 100644 index 0000000..8071616 --- /dev/null +++ b/proto/vnet_mapping.proto @@ -0,0 +1,40 @@ +syntax = "proto3"; + +package dash.vnet_mapping; + +import "types.proto"; +import "route_type.proto"; + +message VnetMapping { + // reference to routing type + route_type.RoutingType action_type = 1; + // PA address for the CA + types.IpAddress underlay_ip = 2; + // Optional + // Inner dst mac + optional bytes mac_address = 3; + // Optional + // metering class-id + optional uint64 metering_class = 4; + // Optional + // override the metering class-id coming from the route table + optional bool override_meter = 5; + // Optional + // if true, use the destination VNET VNI for encap. If false or not specified, use source VNET's VNI + optional bool use_dst_vni = 6; + // Optional + optional bool use_pl_sip_eni = 7; + // Optional + // overlay src ip if routing_type is {privatelink} + optional types.IpAddress overlay_sip = 8; + // Optional + // overlay dst ip if routing_type is {privatelink} + optional types.IpAddress overlay_dip = 9; +} + +// CA-PA mapping table for Vnet +message VnetMappingKey { + string vnet = 1; + // IP address string. E.G. 10.2.0.6 + string ip_address = 2; +}