diff --git a/cmd/gnmi-telemetry/telemetry.go b/cmd/gnmi-telemetry/telemetry.go index 80a784f77da6fb869812222d3a4f4247f5c2a548..a749593fa97ec83cf245d8825b4e9811e9ca0b49 100644 --- a/cmd/gnmi-telemetry/telemetry.go +++ b/cmd/gnmi-telemetry/telemetry.go @@ -3,7 +3,6 @@ package main import ( "code.fbi.h-da.de/cocsn/gosdn/forks/goarista/gnmi" "code.fbi.h-da.de/cocsn/gosdn/nucleus" - schema "code.fbi.h-da.de/cocsn/yang-models/generated/arista" "context" "fmt" "github.com/google/uuid" @@ -23,8 +22,7 @@ func main() { RespChan: make(chan *gpb.SubscribeResponse), } device := nucleus.Device{ - Device: &schema.Device{}, - SBI: sbi, + SBI: sbi, Config: nucleus.DeviceConfig{ Uuid: uuid.New(), Address: "localhost:9339", @@ -33,8 +31,8 @@ func main() { }, Transport: transport, } - pnd := nucleus.NewPND("openconfig", sbi) - if err := pnd.AddDevice(device); err != nil { + pnd := nucleus.NewPND("openconfig", "a simple openconfig PND", sbi) + if err := pnd.AddDevice(&device); err != nil { log.Fatal(err) } diff --git a/nucleus/cli-handling.go b/nucleus/cli-handling.go index d409735d105350364712fc82531873317b9eb8fa..432b9d4eb98932cbebdeaeb3e4f3d052f82358d5 100644 --- a/nucleus/cli-handling.go +++ b/nucleus/cli-handling.go @@ -206,25 +206,35 @@ func (s *server) AddDevice(ctx context.Context, in *pb.AddDeviceRequest) (*pb.Ad if err != nil { return &pb.AddDeviceReply{Message: err.Error()}, err } - pnd := s.core.principalNetworkDomains[uuidPND] + pnd, exists := s.core.principalNetworkDomains[uuidPND] + if exists != true { + return &pb.AddDeviceReply{Message: err.Error()}, err + } sbi := s.core.principalNetworkDomains[uuidPND].GetSBIs()["default"] + transport := &Gnmi{SetNode: sbi.SetNode()} + cfg := &gnmi.Config{ + Addr: in.Device.Address, + Username: in.Device.Username, + Password: in.Device.Password, + } + transport.SetConfig(cfg) + newDevice := Device{ - Uuid: uuid.New(), - Device: sbi.Schema().Root, - SBI: sbi, + SBI: sbi, Config: DeviceConfig{ + Uuid: uuid.New(), Address: in.Device.Address, Username: in.Device.Username, Password: in.Device.Password, }, - Transport: sbi.GetTransport(), + Transport: transport, } devicesMap := pnd.GetDevices() - devicesMap[newDevice.Uuid] = newDevice + devicesMap[newDevice.Config.Uuid] = &newDevice s.core.MarshallPNDs() - return &pb.AddDeviceReply{Message: "Added new Device: " + newDevice.Uuid.String()}, err + return &pb.AddDeviceReply{Message: "Added new Device: " + newDevice.Config.Uuid.String()}, err } func (s *server) HandleDeviceGetRequest(ctx context.Context, in *pb.DeviceGetRequest) (*pb.DeviceGetReply, error) { @@ -237,32 +247,25 @@ func (s *server) HandleDeviceGetRequest(ctx context.Context, in *pb.DeviceGetReq if err != nil { return &pb.DeviceGetReply{Message: err.Error()}, err } + pnd, exists := s.core.principalNetworkDomains[uuidPND] + if exists != true { + err := errors.New("Couldnt find PND: UUID is wrong") + return &pb.DeviceGetReply{Message: err.Error()}, err + } device, exists := s.core.principalNetworkDomains[uuidPND].GetDevices()[uuidDevice] if exists != true { err := errors.New("Couldnt find device: UUID is wrong") return &pb.DeviceGetReply{Message: err.Error()}, err } - cfg := &gnmi.Config{ - Addr: device.Config.Address, - Password: device.Config.Password, - Username: device.Config.Username, - } - ctxGnmi := gnmi.NewContext(context.Background(), cfg) - ctxGnmi = context.WithValue(ctxGnmi, "config", cfg) - paths := []string{in.GetPath()} - req, err := gnmi.NewGetRequest(gnmi.SplitPaths(paths), "") - resp, err := GetWithRequest(ctxGnmi, req) + err = pnd.Request(uuidDevice, in.GetPath()) if err != nil { return &pb.DeviceGetReply{Message: err.Error()}, err } - if err := device.Add(resp); err != nil { - return &pb.DeviceGetReply{Message: err.Error()}, err - } - d, err := json.MarshalIndent(device.Device, "", "\t") + + d, err := json.MarshalIndent(device, "", "\t") if err != nil { return &pb.DeviceGetReply{Message: err.Error()}, err - } return &pb.DeviceGetReply{Message: string(d)}, nil diff --git a/nucleus/controller.go b/nucleus/controller.go index 3de206c574e0aa2c0adf851990d2c271154ae08a..bc10fad0ae2a4c7552af80a6d39ccfb625c43544 100644 --- a/nucleus/controller.go +++ b/nucleus/controller.go @@ -35,12 +35,15 @@ func (c *Core) Initialize(IsRunningChannel chan bool) { } c.AttachDatabase() c.CreateSouthboundInterfaces() - - err = c.UnMarshallPNDs() - if err != nil { - log.Info(err) + for sbi := range c.southboundInterfaces { + log.Info(sbi) } + // err = c.UnMarshallPNDs() + // if err != nil { + // log.Info(err) + // } + c.IsRunning = IsRunningChannel } @@ -78,12 +81,10 @@ func (c *Core) UnMarshallPNDs() error { // CreateSouthboundInterfaces initializes the controller with his SBIs func (c *Core) CreateSouthboundInterfaces() { - if len(c.southboundInterfaces) == 0 { - arista := GetAristaOCInstance() - c.southboundInterfaces[arista.SbiIdentifier()] = arista - openconfig := GetOpenconfigInstance() - c.southboundInterfaces[openconfig.SbiIdentifier()] = openconfig - } + arista := &AristaOC{} + c.southboundInterfaces[arista.SbiIdentifier()] = arista + openconfig := &OpenConfig{} + c.southboundInterfaces[openconfig.SbiIdentifier()] = openconfig } // Shutdown waits for the shutdown signal and gracefully shuts down once it arrived diff --git a/nucleus/json_Helper.go b/nucleus/json_Helper.go index 364fe2eed4dcd7e9cb47b98a3e99bfa62fc42cd8..dc9c13816d5f7066f15b5ce5870f1d35450f9de2 100644 --- a/nucleus/json_Helper.go +++ b/nucleus/json_Helper.go @@ -48,10 +48,10 @@ func getSouthboundInterfaceFromJSONMap(m map[string]interface{}) SouthboundInter switch sbi := m["name"]; sbi { case "arista": - newSBI = GetAristaOCInstance() + newSBI = &AristaOC{} case "openconfig": - newSBI = GetOpenconfigInstance() + newSBI = &OpenConfig{} } return newSBI } diff --git a/nucleus/southbound.go b/nucleus/southbound.go index a95152c32e9acba8c32432a87237f3ec212a7e2a..cb2ac3721bb67e493c96c4de9abe94bfb3960a0a 100644 --- a/nucleus/southbound.go +++ b/nucleus/southbound.go @@ -20,8 +20,6 @@ type SouthboundInterface interface { // Needed for type assertion. SetNode() func(schema *yang.Entry, root interface{}, path *gpb.Path, val interface{}, opts ...ytypes.SetNodeOpt) error Schema() *ytypes.Schema - SetTransport(t Transport) - GetTransport() Transport } type Tapi struct { @@ -31,7 +29,6 @@ type Tapi struct { // The struct holds the YANG schema and a function that // returns an SBI specific SetNode function. type OpenConfig struct { - Name string `json:"name"` // deprecated transport Transport @@ -42,7 +39,7 @@ type OpenConfig struct { // the SBI // deprecated func (oc *OpenConfig) SbiIdentifier() string { - return oc.Name + return "openconfig" } func (oc *OpenConfig) Schema() *ytypes.Schema { @@ -65,16 +62,7 @@ func (oc *OpenConfig) SetNode() func(schema *yang.Entry, root interface{}, path } } -func (oc *OpenConfig) GetTransport() Transport { - return oc.transport -} - -func (oc *OpenConfig) SetTransport(t Transport) { - oc.transport = t -} - type AristaOC struct { - Name string `json:"name"` // deprecated transport Transport @@ -82,7 +70,7 @@ type AristaOC struct { } func (oc *AristaOC) SbiIdentifier() string { - return oc.Name + return "arista" } func (oc *AristaOC) Schema() *ytypes.Schema { @@ -104,11 +92,3 @@ func (oc *AristaOC) SetNode() func(schema *yang.Entry, root interface{}, path *g return nil } } - -func (oc *AristaOC) GetTransport() Transport { - return oc.transport -} - -func (oc *AristaOC) SetTransport(t Transport) { - oc.transport = t -}