From e73b68875318df1fa2942177078ef8655a5550d5 Mon Sep 17 00:00:00 2001 From: denis-tingaikin Date: Tue, 10 May 2022 23:48:29 +0300 Subject: [PATCH] add dns service for vl3 networks Signed-off-by: denis-tingaikin --- pkg/api/dns/dns.pb.go | 427 ++++++++++++++++++++++++++++++++++++++++++ pkg/api/dns/dns.proto | 41 ++++ pkg/api/dns/gen.go | 24 +++ 3 files changed, 492 insertions(+) create mode 100644 pkg/api/dns/dns.pb.go create mode 100644 pkg/api/dns/dns.proto create mode 100644 pkg/api/dns/gen.go diff --git a/pkg/api/dns/dns.pb.go b/pkg/api/dns/dns.pb.go new file mode 100644 index 0000000..b04bd8e --- /dev/null +++ b/pkg/api/dns/dns.pb.go @@ -0,0 +1,427 @@ +// Copyright (c) 2022 Cisco and/or its affiliates. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at: +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// This contains the core Network Service Mesh API definitions for external +// consumption via gRPC protobufs. + +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.26.0 +// protoc v3.17.3 +// source: dns.proto + +package dns + +import ( + context "context" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + reflect "reflect" + sync "sync" +) + +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) + +type Type int32 + +const ( + Type_UNDEFINED Type = 0 + Type_ASSIGN Type = 1 + Type_UNASSIGN Type = 2 +) + +// Enum value maps for Type. +var ( + Type_name = map[int32]string{ + 0: "UNDEFINED", + 1: "ASSIGN", + 2: "UNASSIGN", + } + Type_value = map[string]int32{ + "UNDEFINED": 0, + "ASSIGN": 1, + "UNASSIGN": 2, + } +) + +func (x Type) Enum() *Type { + p := new(Type) + *p = x + return p +} + +func (x Type) String() string { + return protoimpl.X.EnumStringOf(x.Descriptor(), protoreflect.EnumNumber(x)) +} + +func (Type) Descriptor() protoreflect.EnumDescriptor { + return file_dns_proto_enumTypes[0].Descriptor() +} + +func (Type) Type() protoreflect.EnumType { + return &file_dns_proto_enumTypes[0] +} + +func (x Type) Number() protoreflect.EnumNumber { + return protoreflect.EnumNumber(x) +} + +// Deprecated: Use Type.Descriptor instead. +func (Type) EnumDescriptor() ([]byte, []int) { + return file_dns_proto_rawDescGZIP(), []int{0} +} + +type DNSRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Type Type `protobuf:"varint,1,opt,name=type,proto3,enum=dns.Type" json:"type,omitempty"` + Labels map[string]string `protobuf:"bytes,2,rep,name=labels,proto3" json:"labels,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"` + Ip string `protobuf:"bytes,3,opt,name=ip,proto3" json:"ip,omitempty"` +} + +func (x *DNSRequest) Reset() { + *x = DNSRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_dns_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *DNSRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*DNSRequest) ProtoMessage() {} + +func (x *DNSRequest) ProtoReflect() protoreflect.Message { + mi := &file_dns_proto_msgTypes[0] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use DNSRequest.ProtoReflect.Descriptor instead. +func (*DNSRequest) Descriptor() ([]byte, []int) { + return file_dns_proto_rawDescGZIP(), []int{0} +} + +func (x *DNSRequest) GetType() Type { + if x != nil { + return x.Type + } + return Type_UNDEFINED +} + +func (x *DNSRequest) GetLabels() map[string]string { + if x != nil { + return x.Labels + } + return nil +} + +func (x *DNSRequest) GetIp() string { + if x != nil { + return x.Ip + } + return "" +} + +type DNSResponse struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` +} + +func (x *DNSResponse) Reset() { + *x = DNSResponse{} + if protoimpl.UnsafeEnabled { + mi := &file_dns_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *DNSResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*DNSResponse) ProtoMessage() {} + +func (x *DNSResponse) ProtoReflect() protoreflect.Message { + mi := &file_dns_proto_msgTypes[1] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use DNSResponse.ProtoReflect.Descriptor instead. +func (*DNSResponse) Descriptor() ([]byte, []int) { + return file_dns_proto_rawDescGZIP(), []int{1} +} + +func (x *DNSResponse) GetName() string { + if x != nil { + return x.Name + } + return "" +} + +var File_dns_proto protoreflect.FileDescriptor + +var file_dns_proto_rawDesc = []byte{ + 0x0a, 0x09, 0x64, 0x6e, 0x73, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x03, 0x64, 0x6e, 0x73, + 0x22, 0xab, 0x01, 0x0a, 0x0a, 0x44, 0x4e, 0x53, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, + 0x1d, 0x0a, 0x04, 0x74, 0x79, 0x70, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x09, 0x2e, + 0x64, 0x6e, 0x73, 0x2e, 0x54, 0x79, 0x70, 0x65, 0x52, 0x04, 0x74, 0x79, 0x70, 0x65, 0x12, 0x33, + 0x0a, 0x06, 0x6c, 0x61, 0x62, 0x65, 0x6c, 0x73, 0x18, 0x02, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x1b, + 0x2e, 0x64, 0x6e, 0x73, 0x2e, 0x44, 0x4e, 0x53, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x2e, + 0x4c, 0x61, 0x62, 0x65, 0x6c, 0x73, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x52, 0x06, 0x6c, 0x61, 0x62, + 0x65, 0x6c, 0x73, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x70, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x02, 0x69, 0x70, 0x1a, 0x39, 0x0a, 0x0b, 0x4c, 0x61, 0x62, 0x65, 0x6c, 0x73, 0x45, 0x6e, 0x74, + 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, + 0x01, 0x28, 0x09, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x22, 0x21, + 0x0a, 0x0b, 0x44, 0x4e, 0x53, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x12, 0x0a, + 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, + 0x65, 0x2a, 0x2f, 0x0a, 0x04, 0x54, 0x79, 0x70, 0x65, 0x12, 0x0d, 0x0a, 0x09, 0x55, 0x4e, 0x44, + 0x45, 0x46, 0x49, 0x4e, 0x45, 0x44, 0x10, 0x00, 0x12, 0x0a, 0x0a, 0x06, 0x41, 0x53, 0x53, 0x49, + 0x47, 0x4e, 0x10, 0x01, 0x12, 0x0c, 0x0a, 0x08, 0x55, 0x4e, 0x41, 0x53, 0x53, 0x49, 0x47, 0x4e, + 0x10, 0x02, 0x32, 0x3b, 0x0a, 0x03, 0x44, 0x4e, 0x53, 0x12, 0x34, 0x0a, 0x0b, 0x4d, 0x61, 0x6e, + 0x61, 0x67, 0x65, 0x4e, 0x61, 0x6d, 0x65, 0x73, 0x12, 0x0f, 0x2e, 0x64, 0x6e, 0x73, 0x2e, 0x44, + 0x4e, 0x53, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x10, 0x2e, 0x64, 0x6e, 0x73, 0x2e, + 0x44, 0x4e, 0x53, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x28, 0x01, 0x30, 0x01, 0x42, + 0x2f, 0x5a, 0x2d, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x6e, 0x65, + 0x74, 0x77, 0x6f, 0x72, 0x6b, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x6d, 0x65, 0x73, 0x68, + 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x70, 0x6b, 0x67, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x64, 0x6e, 0x73, + 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, +} + +var ( + file_dns_proto_rawDescOnce sync.Once + file_dns_proto_rawDescData = file_dns_proto_rawDesc +) + +func file_dns_proto_rawDescGZIP() []byte { + file_dns_proto_rawDescOnce.Do(func() { + file_dns_proto_rawDescData = protoimpl.X.CompressGZIP(file_dns_proto_rawDescData) + }) + return file_dns_proto_rawDescData +} + +var file_dns_proto_enumTypes = make([]protoimpl.EnumInfo, 1) +var file_dns_proto_msgTypes = make([]protoimpl.MessageInfo, 3) +var file_dns_proto_goTypes = []interface{}{ + (Type)(0), // 0: dns.Type + (*DNSRequest)(nil), // 1: dns.DNSRequest + (*DNSResponse)(nil), // 2: dns.DNSResponse + nil, // 3: dns.DNSRequest.LabelsEntry +} +var file_dns_proto_depIdxs = []int32{ + 0, // 0: dns.DNSRequest.type:type_name -> dns.Type + 3, // 1: dns.DNSRequest.labels:type_name -> dns.DNSRequest.LabelsEntry + 1, // 2: dns.DNS.ManageNames:input_type -> dns.DNSRequest + 2, // 3: dns.DNS.ManageNames:output_type -> dns.DNSResponse + 3, // [3:4] is the sub-list for method output_type + 2, // [2:3] is the sub-list for method input_type + 2, // [2:2] is the sub-list for extension type_name + 2, // [2:2] is the sub-list for extension extendee + 0, // [0:2] is the sub-list for field type_name +} + +func init() { file_dns_proto_init() } +func file_dns_proto_init() { + if File_dns_proto != nil { + return + } + if !protoimpl.UnsafeEnabled { + file_dns_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*DNSRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_dns_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*DNSResponse); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + } + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: file_dns_proto_rawDesc, + NumEnums: 1, + NumMessages: 3, + NumExtensions: 0, + NumServices: 1, + }, + GoTypes: file_dns_proto_goTypes, + DependencyIndexes: file_dns_proto_depIdxs, + EnumInfos: file_dns_proto_enumTypes, + MessageInfos: file_dns_proto_msgTypes, + }.Build() + File_dns_proto = out.File + file_dns_proto_rawDesc = nil + file_dns_proto_goTypes = nil + file_dns_proto_depIdxs = nil +} + +// Reference imports to suppress errors if they are not otherwise used. +var _ context.Context +var _ grpc.ClientConnInterface + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +const _ = grpc.SupportPackageIsVersion6 + +// DNSClient is the client API for DNS service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. +type DNSClient interface { + ManageNames(ctx context.Context, opts ...grpc.CallOption) (DNS_ManageNamesClient, error) +} + +type dNSClient struct { + cc grpc.ClientConnInterface +} + +func NewDNSClient(cc grpc.ClientConnInterface) DNSClient { + return &dNSClient{cc} +} + +func (c *dNSClient) ManageNames(ctx context.Context, opts ...grpc.CallOption) (DNS_ManageNamesClient, error) { + stream, err := c.cc.NewStream(ctx, &_DNS_serviceDesc.Streams[0], "/dns.DNS/ManageNames", opts...) + if err != nil { + return nil, err + } + x := &dNSManageNamesClient{stream} + return x, nil +} + +type DNS_ManageNamesClient interface { + Send(*DNSRequest) error + Recv() (*DNSResponse, error) + grpc.ClientStream +} + +type dNSManageNamesClient struct { + grpc.ClientStream +} + +func (x *dNSManageNamesClient) Send(m *DNSRequest) error { + return x.ClientStream.SendMsg(m) +} + +func (x *dNSManageNamesClient) Recv() (*DNSResponse, error) { + m := new(DNSResponse) + if err := x.ClientStream.RecvMsg(m); err != nil { + return nil, err + } + return m, nil +} + +// DNSServer is the server API for DNS service. +type DNSServer interface { + ManageNames(DNS_ManageNamesServer) error +} + +// UnimplementedDNSServer can be embedded to have forward compatible implementations. +type UnimplementedDNSServer struct { +} + +func (*UnimplementedDNSServer) ManageNames(DNS_ManageNamesServer) error { + return status.Errorf(codes.Unimplemented, "method ManageNames not implemented") +} + +func RegisterDNSServer(s *grpc.Server, srv DNSServer) { + s.RegisterService(&_DNS_serviceDesc, srv) +} + +func _DNS_ManageNames_Handler(srv interface{}, stream grpc.ServerStream) error { + return srv.(DNSServer).ManageNames(&dNSManageNamesServer{stream}) +} + +type DNS_ManageNamesServer interface { + Send(*DNSResponse) error + Recv() (*DNSRequest, error) + grpc.ServerStream +} + +type dNSManageNamesServer struct { + grpc.ServerStream +} + +func (x *dNSManageNamesServer) Send(m *DNSResponse) error { + return x.ServerStream.SendMsg(m) +} + +func (x *dNSManageNamesServer) Recv() (*DNSRequest, error) { + m := new(DNSRequest) + if err := x.ServerStream.RecvMsg(m); err != nil { + return nil, err + } + return m, nil +} + +var _DNS_serviceDesc = grpc.ServiceDesc{ + ServiceName: "dns.DNS", + HandlerType: (*DNSServer)(nil), + Methods: []grpc.MethodDesc{}, + Streams: []grpc.StreamDesc{ + { + StreamName: "ManageNames", + Handler: _DNS_ManageNames_Handler, + ServerStreams: true, + ClientStreams: true, + }, + }, + Metadata: "dns.proto", +} diff --git a/pkg/api/dns/dns.proto b/pkg/api/dns/dns.proto new file mode 100644 index 0000000..0550e2b --- /dev/null +++ b/pkg/api/dns/dns.proto @@ -0,0 +1,41 @@ +// Copyright (c) 2022 Cisco and/or its affiliates. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at: +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// This contains the core Network Service Mesh API definitions for external +// consumption via gRPC protobufs. + +syntax = "proto3"; + +package dns; +option go_package = "github.com/networkservicemesh/api/pkg/api/dns"; + +enum Type { + UNDEFINED = 0; + ASSIGN = 1; + UNASSIGN = 2; +} + +message DNSRequest { + Type type = 1; + map labels = 2; + string ip = 3; +} + +message DNSResponse { + string name = 1; +} + +service DNS { + rpc ManageNames (stream DNSRequest) returns (stream DNSResponse); +} \ No newline at end of file diff --git a/pkg/api/dns/gen.go b/pkg/api/dns/gen.go new file mode 100644 index 0000000..7dcaea3 --- /dev/null +++ b/pkg/api/dns/gen.go @@ -0,0 +1,24 @@ +// Copyright (c) 2022 Cisco and/or its affiliates. +// +// SPDX-License-Identifier: Apache-2.0 +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at: +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Package dns provides the Network Service Mesh API: IpamService{Server,Client}.{ManageNames} +package dns + +// Run with protoc and proto-gen-go matching the versions found in .github/workflows/ci.yaml +// Please also note that you need a 'batteries included' version of protoc such as the one installed +// with brew rather than the 'single binary' install to insure you get the correct *.proto files for imports +//go:generate go install github.com/golang/protobuf/protoc-gen-go@v1.5.2 +//go:generate bash -c "protoc -I . dns.proto --go_out=plugins=grpc,paths=source_relative:. --proto_path=$GOPATH/src/ --proto_path=$GOPATH/pkg/mod/ --proto_path=$( go list -f '{{ .Dir }}' -m github.com/golang/protobuf )"