From 1bfe01d6a10fd61d5fecca91f3ced02589893f5c Mon Sep 17 00:00:00 2001
From: Malte Bauch <malte.bauch@stud.h-da.de>
Date: Tue, 19 Jan 2021 21:16:33 +0100
Subject: [PATCH] updated southbound and nucleus/controller

- southbound to work with gob
- controller load/save pnd functions
---
 nucleus/cli-handling.go    | 11 +++++++----
 nucleus/controller.go      |  3 ++-
 nucleus/southbound.go      |  4 ++--
 nucleus/southbound_test.go |  6 +++---
 4 files changed, 14 insertions(+), 10 deletions(-)

diff --git a/nucleus/cli-handling.go b/nucleus/cli-handling.go
index 56efaff9f..e18c610d5 100644
--- a/nucleus/cli-handling.go
+++ b/nucleus/cli-handling.go
@@ -156,8 +156,11 @@ func (s *server) TAPIGetLink(ctx context.Context, in *pb.TAPIRequest) (*pb.TAPIR
 func (s *server) CreatePND(ctx context.Context, in *pb.PNDRequest) (*pb.PNDReply, error) {
 	log.Info("Received: ", in.GetName())
 	path := viper.GetString("pnd.path")
-	//TODO: change sbi
-	s.core.principalNetworkDomains[uuid.New()] = NewPND(in.GetName(), in.GetDescription(), s.core.southboundInterfaces["test"])
-	s.core.savePNDs(path)
-	return &pb.PNDReply{Message: "Created new PND: " + in.GetName()}, nil
+	sbi := &OpenConfig{}
+	id := uuid.New()
+	s.core.principalNetworkDomains[id] = NewPND(in.GetName(), in.GetDescription(), sbi)
+	if err := s.core.savePNDs(path); err != nil {
+		log.Info(err)
+	}
+	return &pb.PNDReply{Message: "Created new PND: " + id.String()}, nil
 }
diff --git a/nucleus/controller.go b/nucleus/controller.go
index 24dac3324..7563da754 100644
--- a/nucleus/controller.go
+++ b/nucleus/controller.go
@@ -35,6 +35,7 @@ func (c *Core) Initialize(IsRunningChannel chan bool) {
 	}
 	path := viper.GetString("pnd.path")
 	gob.Register(&pndImplementation{})
+	gob.Register(&OpenConfig{})
 	c.AttachDatabase()
 
 	if err := c.loadPNDs(path); err != nil {
@@ -50,7 +51,7 @@ func (c *Core) AttachDatabase() {
 }
 
 // TODO: the load and save functions for pnds are just temporary and should be
-//       moved to the database
+// moved to the database
 
 // SavePNDs imports the PNDs from last session
 func (c *Core) savePNDs(path string) error {
diff --git a/nucleus/southbound.go b/nucleus/southbound.go
index a3aa5af68..743c24326 100644
--- a/nucleus/southbound.go
+++ b/nucleus/southbound.go
@@ -10,7 +10,7 @@ type Tapi struct {
 }
 
 type OpenConfig struct {
-	transport Transport
+	Transport Transport
 }
 
 func (oc *OpenConfig) SbiIdentifier() string {
@@ -18,7 +18,7 @@ func (oc *OpenConfig) SbiIdentifier() string {
 }
 
 func (oc *OpenConfig) OpenconfigInterfaces(device Device) {
-	resp, err := oc.transport.Get(nil, nil...)
+	resp, err := oc.Transport.Get(nil, nil...)
 	if err != nil {
 
 	}
diff --git a/nucleus/southbound_test.go b/nucleus/southbound_test.go
index 447696fa7..04b7456fb 100644
--- a/nucleus/southbound_test.go
+++ b/nucleus/southbound_test.go
@@ -16,7 +16,7 @@ func TestOpenConfig_SbiIdentifier(t *testing.T) {
 	for _, tt := range tests {
 		t.Run(tt.name, func(t *testing.T) {
 			oc := &OpenConfig{
-				transport: tt.fields.transport,
+				Transport: tt.fields.transport,
 			}
 			if got := oc.SbiIdentifier(); got != tt.want {
 				t.Errorf("SbiIdentifier() = %v, want %v", got, tt.want)
@@ -42,9 +42,9 @@ func TestOpenConfig_OpenconfigInterfaces(t *testing.T) {
 	for _, tt := range tests {
 		t.Run(tt.name, func(t *testing.T) {
 			oc := &OpenConfig{
-				transport: tt.fields.transport,
+				Transport: tt.fields.transport,
 			}
 			oc.OpenconfigInterfaces(tt.args.device)
 		})
 	}
-}
\ No newline at end of file
+}
-- 
GitLab