diff --git a/pkg/netlink/common.go b/pkg/netlink/common.go index 3e5f71eb..50985e34 100644 --- a/pkg/netlink/common.go +++ b/pkg/netlink/common.go @@ -5,7 +5,6 @@ import ( "fmt" "log" "net" - "os" "reflect" "sync/atomic" @@ -162,31 +161,20 @@ func netMaskToInt(mask int) (netmaskint [4]uint8) { } // dumpDBs dumps the databse -func dumpDBs() { - file, err := os.OpenFile("netlink_dump", os.O_WRONLY|os.O_CREATE, 0600) - if err != nil { - panic(err) - } - if err := os.Truncate("netlink_dump", 0); err != nil { - log.Printf("netlink: Failed to truncate: %v", err) - } +func dumpDBs() (string, error) { str := dumpRouteDB() - log.Printf("\n") + str += dumpNexthDB() - log.Printf("\n") + str += dumpNeighDB() - log.Printf("\n") + str += dumpFDB() - log.Printf("\n") + str += dumpL2NexthDB() - _, err = file.WriteString(str) - if err != nil { - log.Printf("netlink: %v", err) - } - err = file.Close() - if err != nil { - log.Printf("netlink: error closing file: %v", err) + if str == "" { + return str, fmt.Errorf("no entries in database") } + return str, nil } // checkProto checks the proto type diff --git a/pkg/netlink/fdb.go b/pkg/netlink/fdb.go index f09d19b1..14b9a0d6 100644 --- a/pkg/netlink/fdb.go +++ b/pkg/netlink/fdb.go @@ -202,15 +202,12 @@ func (fdb *FdbEntryStruct) deepEqual(fdbOld *FdbEntryStruct, nc bool) bool { // dumpFDB dump the fdb entries func dumpFDB() string { var s string - log.Printf("netlink: Dump fDB table:\n") s = "fDB table:\n" - for _, n := range latestFDB { + for _, n := range fDB { str := fmt.Sprintf("MacAddr(vlan=%d mac=%s state=%s type=%d l2nh_id=%d) ", n.VlanID, n.Mac, n.State, n.Type, n.Nexthop.ID) - log.Println(str) s += str s += "\n" } - log.Printf("\n\n\n") s += "\n\n" return s } diff --git a/pkg/netlink/l2nexthop.go b/pkg/netlink/l2nexthop.go index eec3a967..cc4419cd 100644 --- a/pkg/netlink/l2nexthop.go +++ b/pkg/netlink/l2nexthop.go @@ -174,21 +174,18 @@ func (l2n *L2NexthopStruct) deepEqual(l2nOld *L2NexthopStruct, nc bool) bool { // dumpL2NexthDB dump the l2 nexthop entries func dumpL2NexthDB() string { var s string - log.Printf("netlink: Dump L2 Nexthop table:\n") s = "L2 Nexthop table:\n" var ip string - for _, n := range latestL2Nexthop { + for _, n := range l2Nexthops { if n.Dst == nil { ip = strNone } else { ip = n.Dst.String() } str := fmt.Sprintf("L2Nexthop(id=%d dev=%s vlan=%d dst=%s type=%d #fDB entries=%d Resolved=%t) ", n.ID, n.Dev, n.VlanID, ip, n.Type, len(n.FdbRefs), n.Resolved) - log.Println(str) s += str s += "\n" } - log.Printf("\n\n\n") s += "\n\n" return s } diff --git a/pkg/netlink/mgmtServer.go b/pkg/netlink/mgmtServer.go new file mode 100644 index 00000000..f1dc8e90 --- /dev/null +++ b/pkg/netlink/mgmtServer.go @@ -0,0 +1,92 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright (c) 2022-2023 Intel Corporation, or its subsidiaries. +// Copyright (C) 2023 Nordix Foundation. + +// Package netlink handles the netlink related functionality +package netlink + +import ( + "context" + "fmt" + "log" + "net" + + "github.com/grpc-ecosystem/go-grpc-middleware/v2/interceptors/logging" + "github.com/opiproject/opi-evpn-bridge/pkg/config" + pm "github.com/opiproject/opi-evpn-bridge/pkg/netlink/proto/gen/go" + "github.com/opiproject/opi-evpn-bridge/pkg/utils" + "go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc" + "go.opentelemetry.io/otel" + "go.opentelemetry.io/otel/trace" + grpc "google.golang.org/grpc" + "google.golang.org/grpc/reflection" +) + +// Server represents the Server object +type Server struct { + pm.UnimplementedManagementServiceServer + Pagination map[string]int + tracer trace.Tracer +} + +// NewServer creates initialized instance of EVPN Mgmt server +func NewServer() *Server { + return &Server{ + Pagination: make(map[string]int), + tracer: otel.Tracer(""), + } +} + +// RunMgmtGrpcServer start the grpc server for all the components +func RunMgmtGrpcServer(grpcPort uint16) { + if config.GlobalConfig.Tracer { + tp := utils.InitTracerProvider("opi-evpn-bridge") + defer func() { + if err := tp.Shutdown(context.Background()); err != nil { + log.Panicf("Tracer Provider Shutdown: %v", err) + } + }() + } + + lis, err := net.Listen("tcp", fmt.Sprintf(":%d", grpcPort)) + if err != nil { + log.Panicf("failed to listen: %v", err) + } + + var serverOptions []grpc.ServerOption + serverOptions = append(serverOptions, + grpc.StatsHandler(otelgrpc.NewServerHandler()), + grpc.UnaryInterceptor( + logging.UnaryServerInterceptor(utils.InterceptorLogger(log.Default()), + logging.WithLogOnEvents( + logging.StartCall, + logging.FinishCall, + logging.PayloadReceived, + logging.PayloadSent, + ), + )), + ) + s := grpc.NewServer(serverOptions...) + + ManagementServer := NewServer() + pm.RegisterManagementServiceServer(s, ManagementServer) + + reflection.Register(s) + + log.Printf("gRPC server listening at %v", lis.Addr()) + if err := s.Serve(lis); err != nil { + log.Panicf("failed to serve: %v", err) + } +} + +// DumpNetlinkDB executes the dumping of netlink database +func (s *Server) DumpNetlinkDB(_ context.Context, in *pm.DumpNetlinkDbRequest) (*pm.DumpNetlinkDbResult, error) { + if in != nil { + dump, err := DumpDatabases() + if err != nil { + return &pm.DumpNetlinkDbResult{}, err + } + return &pm.DumpNetlinkDbResult{Details: dump}, nil + } + return &pm.DumpNetlinkDbResult{}, nil +} diff --git a/pkg/netlink/neighbor.go b/pkg/netlink/neighbor.go index fe5a51ab..41b3539e 100644 --- a/pkg/netlink/neighbor.go +++ b/pkg/netlink/neighbor.go @@ -291,7 +291,6 @@ func (neigh NeighStruct) neighborAnnotate() NeighStruct { // dumpNeighDB dump the neighbor entries func dumpNeighDB() string { var s string - log.Printf("netlink: Dump Neighbor table:\n") s = "Neighbor table:\n" for _, n := range latestNeighbors { var Proto string @@ -301,7 +300,6 @@ func dumpNeighDB() string { Proto = n.Protocol } str := fmt.Sprintf("Neighbor(vrf=%s dst=%s lladdr=%s dev=%s proto=%s state=%s Type : %d) ", n.VrfName, n.Neigh0.IP.String(), n.Neigh0.HardwareAddr.String(), nameIndex[n.Neigh0.LinkIndex], Proto, getStateStr(n.Neigh0.State), n.Type) - log.Println(str) s += str s += "\n" } diff --git a/pkg/netlink/netlink_watcher.go b/pkg/netlink/netlink_watcher.go index 9e980bd4..d7529c09 100644 --- a/pkg/netlink/netlink_watcher.go +++ b/pkg/netlink/netlink_watcher.go @@ -8,6 +8,7 @@ package netlink import ( "context" "log" + sync "sync" "time" @@ -18,6 +19,9 @@ import ( "github.com/opiproject/opi-evpn-bridge/pkg/utils" ) +// Define a global mutex +var mu sync.Mutex + // deleteLatestDB deletes the latest db snap func deleteLatestDB() { latestRoutes = make(map[RouteKey]*RouteStruct) @@ -98,6 +102,14 @@ func annotateDBEntries() { annotateMap(latestL2Nexthop) } +// DumpDatabases reads the latest netlink state +func DumpDatabases() (string, error) { + mu.Lock() + defer mu.Unlock() // Ensure the mutex is unlocked when the function exits + dump, err := dumpDBs() + return dump, err +} + // readLatestNetlinkState reads the latest netlink state func readLatestNetlinkState() { grdVrf, err := infradb.GetVrf("//network.opiproject.org/vrfs/GRD") @@ -116,11 +128,13 @@ func readLatestNetlinkState() { m[i].addFdbEntry() } } - dumpDBs() } // resyncWithKernel fun resyncs with kernal db func resyncWithKernel() { + mu.Lock() + defer mu.Unlock() // Ensure the mutex is unlocked when the function exits + // Build a new DB snapshot from netlink and other sources readLatestNetlinkState() // Annotate the latest DB entries @@ -133,6 +147,7 @@ func resyncWithKernel() { nexthops = latestNexthop fDB = latestFDB l2Nexthops = latestL2Nexthop + deleteLatestDB() } @@ -188,6 +203,8 @@ func getlink() { } } +const grpcPort uint16 = 50152 + // Initialize function intializes config func Initialize() { pollInterval = config.GlobalConfig.Netlink.PollInterval @@ -201,6 +218,8 @@ func Initialize() { log.Printf("netlink: netlink_monitor disabled") return } + + go RunMgmtGrpcServer(grpcPort) for i := 0; i < len(config.GlobalConfig.Interfaces.PhyPorts); i++ { phyPorts[config.GlobalConfig.Interfaces.PhyPorts[i].Rep] = config.GlobalConfig.Interfaces.PhyPorts[i].Vsi } diff --git a/pkg/netlink/nexthop.go b/pkg/netlink/nexthop.go index fd9674a9..76e4ef97 100644 --- a/pkg/netlink/nexthop.go +++ b/pkg/netlink/nexthop.go @@ -167,7 +167,7 @@ func NHAssignID(key NexthopKey) int { // addNexthop adds the nexthop // -//nolint +// nolint func (nexthop *NexthopStruct) addNexthop(r *RouteStruct) *RouteStruct { if len(r.Nexthops) > 0 && !enableEcmp { log.Printf("ECMP disabled: Ignoring additional nexthop of route") @@ -195,7 +195,7 @@ func (nexthop *NexthopStruct) addNexthop(r *RouteStruct) *RouteStruct { // ParseNexthop parses the neighbor // -//nolint +// nolint func (nexthop *NexthopStruct) ParseNexthop(v *infradb.Vrf, rc RouteCmdInfo) { var phyFlag bool phyFlag = false @@ -418,15 +418,12 @@ func (nexthop *NexthopStruct) GetVrfOperStatus() infradb.VrfOperStatus { // dumpNexthDB dump the nexthop entries func dumpNexthDB() string { var s string - log.Printf("netlink: Dump Nexthop table:\n") s = "Nexthop table:\n" - for _, n := range latestNexthop { + for _, n := range nexthops { str := fmt.Sprintf("Nexthop(id=%d vrf=%s dst=%s dev=%s Local=%t weight=%d flags=[%s] #routes=%d Resolved=%t neighbor=%s) ", n.ID, n.Vrf.Name, n.nexthop.Gw.String(), nameIndex[n.nexthop.LinkIndex], n.Local, n.Weight, getFlagString(n.nexthop.Flags), len(n.RouteRefs), n.Resolved, n.Neighbor.printNeigh()) - log.Println(str) s += str s += "\n" } - log.Printf("\n\n\n") s += "\n\n" return s } diff --git a/pkg/netlink/proto/gen/go/mgmt.pb.go b/pkg/netlink/proto/gen/go/mgmt.pb.go new file mode 100644 index 00000000..c712234d --- /dev/null +++ b/pkg/netlink/proto/gen/go/mgmt.pb.go @@ -0,0 +1,287 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.31.0 +// protoc v3.19.4 +// source: mgmt.proto + +package _go + +import ( + 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 DumpNetlinkDbResult_ErrorCode int32 + +const ( + DumpNetlinkDbResult_OK DumpNetlinkDbResult_ErrorCode = 0 + DumpNetlinkDbResult_INTERNAL_ERROR DumpNetlinkDbResult_ErrorCode = 1 +) + +// Enum value maps for DumpNetlinkDbResult_ErrorCode. +var ( + DumpNetlinkDbResult_ErrorCode_name = map[int32]string{ + 0: "OK", + 1: "INTERNAL_ERROR", + } + DumpNetlinkDbResult_ErrorCode_value = map[string]int32{ + "OK": 0, + "INTERNAL_ERROR": 1, + } +) + +func (x DumpNetlinkDbResult_ErrorCode) Enum() *DumpNetlinkDbResult_ErrorCode { + p := new(DumpNetlinkDbResult_ErrorCode) + *p = x + return p +} + +func (x DumpNetlinkDbResult_ErrorCode) String() string { + return protoimpl.X.EnumStringOf(x.Descriptor(), protoreflect.EnumNumber(x)) +} + +func (DumpNetlinkDbResult_ErrorCode) Descriptor() protoreflect.EnumDescriptor { + return file_mgmt_proto_enumTypes[0].Descriptor() +} + +func (DumpNetlinkDbResult_ErrorCode) Type() protoreflect.EnumType { + return &file_mgmt_proto_enumTypes[0] +} + +func (x DumpNetlinkDbResult_ErrorCode) Number() protoreflect.EnumNumber { + return protoreflect.EnumNumber(x) +} + +// Deprecated: Use DumpNetlinkDbResult_ErrorCode.Descriptor instead. +func (DumpNetlinkDbResult_ErrorCode) EnumDescriptor() ([]byte, []int) { + return file_mgmt_proto_rawDescGZIP(), []int{1, 0} +} + +type DumpNetlinkDbRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Details bool `protobuf:"varint,1,opt,name=details,proto3" json:"details,omitempty"` +} + +func (x *DumpNetlinkDbRequest) Reset() { + *x = DumpNetlinkDbRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_mgmt_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *DumpNetlinkDbRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*DumpNetlinkDbRequest) ProtoMessage() {} + +func (x *DumpNetlinkDbRequest) ProtoReflect() protoreflect.Message { + mi := &file_mgmt_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 DumpNetlinkDbRequest.ProtoReflect.Descriptor instead. +func (*DumpNetlinkDbRequest) Descriptor() ([]byte, []int) { + return file_mgmt_proto_rawDescGZIP(), []int{0} +} + +func (x *DumpNetlinkDbRequest) GetDetails() bool { + if x != nil { + return x.Details + } + return false +} + +type DumpNetlinkDbResult struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + ErrorCode DumpNetlinkDbResult_ErrorCode `protobuf:"varint,1,opt,name=error_code,json=errorCode,proto3,enum=opi_evpn_bridge.pkg.netlink.DumpNetlinkDbResult_ErrorCode" json:"error_code,omitempty"` + Details string `protobuf:"bytes,2,opt,name=details,proto3" json:"details,omitempty"` +} + +func (x *DumpNetlinkDbResult) Reset() { + *x = DumpNetlinkDbResult{} + if protoimpl.UnsafeEnabled { + mi := &file_mgmt_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *DumpNetlinkDbResult) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*DumpNetlinkDbResult) ProtoMessage() {} + +func (x *DumpNetlinkDbResult) ProtoReflect() protoreflect.Message { + mi := &file_mgmt_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 DumpNetlinkDbResult.ProtoReflect.Descriptor instead. +func (*DumpNetlinkDbResult) Descriptor() ([]byte, []int) { + return file_mgmt_proto_rawDescGZIP(), []int{1} +} + +func (x *DumpNetlinkDbResult) GetErrorCode() DumpNetlinkDbResult_ErrorCode { + if x != nil { + return x.ErrorCode + } + return DumpNetlinkDbResult_OK +} + +func (x *DumpNetlinkDbResult) GetDetails() string { + if x != nil { + return x.Details + } + return "" +} + +var File_mgmt_proto protoreflect.FileDescriptor + +var file_mgmt_proto_rawDesc = []byte{ + 0x0a, 0x0a, 0x6d, 0x67, 0x6d, 0x74, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x1b, 0x6f, 0x70, + 0x69, 0x5f, 0x65, 0x76, 0x70, 0x6e, 0x5f, 0x62, 0x72, 0x69, 0x64, 0x67, 0x65, 0x2e, 0x70, 0x6b, + 0x67, 0x2e, 0x6e, 0x65, 0x74, 0x6c, 0x69, 0x6e, 0x6b, 0x22, 0x30, 0x0a, 0x14, 0x44, 0x75, 0x6d, + 0x70, 0x4e, 0x65, 0x74, 0x6c, 0x69, 0x6e, 0x6b, 0x44, 0x62, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, + 0x74, 0x12, 0x18, 0x0a, 0x07, 0x64, 0x65, 0x74, 0x61, 0x69, 0x6c, 0x73, 0x18, 0x01, 0x20, 0x01, + 0x28, 0x08, 0x52, 0x07, 0x64, 0x65, 0x74, 0x61, 0x69, 0x6c, 0x73, 0x22, 0xb3, 0x01, 0x0a, 0x13, + 0x44, 0x75, 0x6d, 0x70, 0x4e, 0x65, 0x74, 0x6c, 0x69, 0x6e, 0x6b, 0x44, 0x62, 0x52, 0x65, 0x73, + 0x75, 0x6c, 0x74, 0x12, 0x59, 0x0a, 0x0a, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x5f, 0x63, 0x6f, 0x64, + 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x3a, 0x2e, 0x6f, 0x70, 0x69, 0x5f, 0x65, 0x76, + 0x70, 0x6e, 0x5f, 0x62, 0x72, 0x69, 0x64, 0x67, 0x65, 0x2e, 0x70, 0x6b, 0x67, 0x2e, 0x6e, 0x65, + 0x74, 0x6c, 0x69, 0x6e, 0x6b, 0x2e, 0x44, 0x75, 0x6d, 0x70, 0x4e, 0x65, 0x74, 0x6c, 0x69, 0x6e, + 0x6b, 0x44, 0x62, 0x52, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x2e, 0x45, 0x72, 0x72, 0x6f, 0x72, 0x43, + 0x6f, 0x64, 0x65, 0x52, 0x09, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x43, 0x6f, 0x64, 0x65, 0x12, 0x18, + 0x0a, 0x07, 0x64, 0x65, 0x74, 0x61, 0x69, 0x6c, 0x73, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x07, 0x64, 0x65, 0x74, 0x61, 0x69, 0x6c, 0x73, 0x22, 0x27, 0x0a, 0x09, 0x45, 0x72, 0x72, 0x6f, + 0x72, 0x43, 0x6f, 0x64, 0x65, 0x12, 0x06, 0x0a, 0x02, 0x4f, 0x4b, 0x10, 0x00, 0x12, 0x12, 0x0a, + 0x0e, 0x49, 0x4e, 0x54, 0x45, 0x52, 0x4e, 0x41, 0x4c, 0x5f, 0x45, 0x52, 0x52, 0x4f, 0x52, 0x10, + 0x01, 0x32, 0x8b, 0x01, 0x0a, 0x11, 0x4d, 0x61, 0x6e, 0x61, 0x67, 0x65, 0x6d, 0x65, 0x6e, 0x74, + 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x76, 0x0a, 0x0d, 0x44, 0x75, 0x6d, 0x70, 0x4e, + 0x65, 0x74, 0x6c, 0x69, 0x6e, 0x6b, 0x44, 0x42, 0x12, 0x31, 0x2e, 0x6f, 0x70, 0x69, 0x5f, 0x65, + 0x76, 0x70, 0x6e, 0x5f, 0x62, 0x72, 0x69, 0x64, 0x67, 0x65, 0x2e, 0x70, 0x6b, 0x67, 0x2e, 0x6e, + 0x65, 0x74, 0x6c, 0x69, 0x6e, 0x6b, 0x2e, 0x44, 0x75, 0x6d, 0x70, 0x4e, 0x65, 0x74, 0x6c, 0x69, + 0x6e, 0x6b, 0x44, 0x62, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x30, 0x2e, 0x6f, 0x70, + 0x69, 0x5f, 0x65, 0x76, 0x70, 0x6e, 0x5f, 0x62, 0x72, 0x69, 0x64, 0x67, 0x65, 0x2e, 0x70, 0x6b, + 0x67, 0x2e, 0x6e, 0x65, 0x74, 0x6c, 0x69, 0x6e, 0x6b, 0x2e, 0x44, 0x75, 0x6d, 0x70, 0x4e, 0x65, + 0x74, 0x6c, 0x69, 0x6e, 0x6b, 0x44, 0x62, 0x52, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x22, 0x00, 0x42, + 0x40, 0x5a, 0x3e, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x6f, 0x70, + 0x69, 0x70, 0x72, 0x6f, 0x6a, 0x65, 0x63, 0x74, 0x2f, 0x6f, 0x70, 0x69, 0x2d, 0x65, 0x76, 0x70, + 0x6e, 0x2d, 0x62, 0x72, 0x69, 0x64, 0x67, 0x65, 0x2f, 0x70, 0x6b, 0x67, 0x2f, 0x6e, 0x65, 0x74, + 0x6c, 0x69, 0x6e, 0x6b, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x67, 0x65, 0x6e, 0x2f, 0x67, + 0x6f, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, +} + +var ( + file_mgmt_proto_rawDescOnce sync.Once + file_mgmt_proto_rawDescData = file_mgmt_proto_rawDesc +) + +func file_mgmt_proto_rawDescGZIP() []byte { + file_mgmt_proto_rawDescOnce.Do(func() { + file_mgmt_proto_rawDescData = protoimpl.X.CompressGZIP(file_mgmt_proto_rawDescData) + }) + return file_mgmt_proto_rawDescData +} + +var file_mgmt_proto_enumTypes = make([]protoimpl.EnumInfo, 1) +var file_mgmt_proto_msgTypes = make([]protoimpl.MessageInfo, 2) +var file_mgmt_proto_goTypes = []interface{}{ + (DumpNetlinkDbResult_ErrorCode)(0), // 0: opi_evpn_bridge.pkg.netlink.DumpNetlinkDbResult.ErrorCode + (*DumpNetlinkDbRequest)(nil), // 1: opi_evpn_bridge.pkg.netlink.DumpNetlinkDbRequest + (*DumpNetlinkDbResult)(nil), // 2: opi_evpn_bridge.pkg.netlink.DumpNetlinkDbResult +} +var file_mgmt_proto_depIdxs = []int32{ + 0, // 0: opi_evpn_bridge.pkg.netlink.DumpNetlinkDbResult.error_code:type_name -> opi_evpn_bridge.pkg.netlink.DumpNetlinkDbResult.ErrorCode + 1, // 1: opi_evpn_bridge.pkg.netlink.ManagementService.DumpNetlinkDB:input_type -> opi_evpn_bridge.pkg.netlink.DumpNetlinkDbRequest + 2, // 2: opi_evpn_bridge.pkg.netlink.ManagementService.DumpNetlinkDB:output_type -> opi_evpn_bridge.pkg.netlink.DumpNetlinkDbResult + 2, // [2:3] is the sub-list for method output_type + 1, // [1:2] is the sub-list for method input_type + 1, // [1:1] is the sub-list for extension type_name + 1, // [1:1] is the sub-list for extension extendee + 0, // [0:1] is the sub-list for field type_name +} + +func init() { file_mgmt_proto_init() } +func file_mgmt_proto_init() { + if File_mgmt_proto != nil { + return + } + if !protoimpl.UnsafeEnabled { + file_mgmt_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*DumpNetlinkDbRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_mgmt_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*DumpNetlinkDbResult); 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_mgmt_proto_rawDesc, + NumEnums: 1, + NumMessages: 2, + NumExtensions: 0, + NumServices: 1, + }, + GoTypes: file_mgmt_proto_goTypes, + DependencyIndexes: file_mgmt_proto_depIdxs, + EnumInfos: file_mgmt_proto_enumTypes, + MessageInfos: file_mgmt_proto_msgTypes, + }.Build() + File_mgmt_proto = out.File + file_mgmt_proto_rawDesc = nil + file_mgmt_proto_goTypes = nil + file_mgmt_proto_depIdxs = nil +} diff --git a/pkg/netlink/proto/gen/go/mgmt_grpc.pb.go b/pkg/netlink/proto/gen/go/mgmt_grpc.pb.go new file mode 100644 index 00000000..a5efbfce --- /dev/null +++ b/pkg/netlink/proto/gen/go/mgmt_grpc.pb.go @@ -0,0 +1,111 @@ +// Code generated by protoc-gen-go-grpc. DO NOT EDIT. +// versions: +// - protoc-gen-go-grpc v1.3.0 +// - protoc v3.19.4 +// source: mgmt.proto + +package _go + +import ( + context "context" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" +) + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +// Requires gRPC-Go v1.32.0 or later. +const _ = grpc.SupportPackageIsVersion7 + +const ( + ManagementService_DumpNetlinkDB_FullMethodName = "/opi_evpn_bridge.pkg.netlink.ManagementService/DumpNetlinkDB" +) + +// ManagementServiceClient is the client API for ManagementService service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream. +type ManagementServiceClient interface { + // Control of the IPU Infra Mgr + DumpNetlinkDB(ctx context.Context, in *DumpNetlinkDbRequest, opts ...grpc.CallOption) (*DumpNetlinkDbResult, error) +} + +type managementServiceClient struct { + cc grpc.ClientConnInterface +} + +func NewManagementServiceClient(cc grpc.ClientConnInterface) ManagementServiceClient { + return &managementServiceClient{cc} +} + +func (c *managementServiceClient) DumpNetlinkDB(ctx context.Context, in *DumpNetlinkDbRequest, opts ...grpc.CallOption) (*DumpNetlinkDbResult, error) { + out := new(DumpNetlinkDbResult) + err := c.cc.Invoke(ctx, ManagementService_DumpNetlinkDB_FullMethodName, in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// ManagementServiceServer is the server API for ManagementService service. +// All implementations must embed UnimplementedManagementServiceServer +// for forward compatibility +type ManagementServiceServer interface { + // Control of the IPU Infra Mgr + DumpNetlinkDB(context.Context, *DumpNetlinkDbRequest) (*DumpNetlinkDbResult, error) + mustEmbedUnimplementedManagementServiceServer() +} + +// UnimplementedManagementServiceServer must be embedded to have forward compatible implementations. +type UnimplementedManagementServiceServer struct { +} + +func (UnimplementedManagementServiceServer) DumpNetlinkDB(context.Context, *DumpNetlinkDbRequest) (*DumpNetlinkDbResult, error) { + return nil, status.Errorf(codes.Unimplemented, "method DumpNetlinkDB not implemented") +} +func (UnimplementedManagementServiceServer) mustEmbedUnimplementedManagementServiceServer() {} + +// UnsafeManagementServiceServer may be embedded to opt out of forward compatibility for this service. +// Use of this interface is not recommended, as added methods to ManagementServiceServer will +// result in compilation errors. +type UnsafeManagementServiceServer interface { + mustEmbedUnimplementedManagementServiceServer() +} + +func RegisterManagementServiceServer(s grpc.ServiceRegistrar, srv ManagementServiceServer) { + s.RegisterService(&ManagementService_ServiceDesc, srv) +} + +func _ManagementService_DumpNetlinkDB_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(DumpNetlinkDbRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ManagementServiceServer).DumpNetlinkDB(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: ManagementService_DumpNetlinkDB_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ManagementServiceServer).DumpNetlinkDB(ctx, req.(*DumpNetlinkDbRequest)) + } + return interceptor(ctx, in, info, handler) +} + +// ManagementService_ServiceDesc is the grpc.ServiceDesc for ManagementService service. +// It's only intended for direct use with grpc.RegisterService, +// and not to be introspected or modified (even as a copy) +var ManagementService_ServiceDesc = grpc.ServiceDesc{ + ServiceName: "opi_evpn_bridge.pkg.netlink.ManagementService", + HandlerType: (*ManagementServiceServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "DumpNetlinkDB", + Handler: _ManagementService_DumpNetlinkDB_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "mgmt.proto", +} diff --git a/pkg/netlink/proto/mgmt.proto b/pkg/netlink/proto/mgmt.proto new file mode 100644 index 00000000..a4342dc1 --- /dev/null +++ b/pkg/netlink/proto/mgmt.proto @@ -0,0 +1,23 @@ +syntax = "proto3"; + +package opi_evpn_bridge.pkg.netlink; + +option go_package = "github.com/opiproject/opi-evpn-bridge/pkg/netlink/proto/gen/go"; + +service ManagementService { + // Control of the IPU Infra Mgr + rpc DumpNetlinkDB(DumpNetlinkDbRequest) returns (DumpNetlinkDbResult) {} +} + +message DumpNetlinkDbRequest { + bool details = 1; +} + +message DumpNetlinkDbResult { + enum ErrorCode { + OK = 0; + INTERNAL_ERROR = 1; + } + ErrorCode error_code = 1; + string details = 2; +} diff --git a/pkg/netlink/route.go b/pkg/netlink/route.go index 3c8d0562..5dc025bb 100644 --- a/pkg/netlink/route.go +++ b/pkg/netlink/route.go @@ -588,9 +588,9 @@ func (route *RouteStruct) GetVrfOperStatus() infradb.VrfOperStatus { // dumpRouteDB dump the route database func dumpRouteDB() string { var s string - log.Printf("netlink: Dump Route table:\n") + s = "Route table:\n" - for _, n := range latestRoutes { + for _, n := range routes { var via string if n.Route0.Gw == nil { via = strNone @@ -598,11 +598,9 @@ func dumpRouteDB() string { via = n.Route0.Gw.String() } str := fmt.Sprintf("Route(vrf=%s dst=%s type=%s proto=%s metric=%d via=%s dev=%s nhid= %+v Table= %d)", n.Vrf.Name, n.Route0.Dst.String(), n.NlType, n.getProto(), n.Route0.Priority, via, nameIndex[n.Route0.LinkIndex], n.Nexthops, n.Route0.Table) - log.Println(str) s += str s += "\n" } - log.Printf("\n\n\n") s += "\n\n" return s }