Skip to content
Snippets Groups Projects
Commit 90e8b93d authored by Manuel Kieweg's avatar Manuel Kieweg
Browse files

Refactoring in progress

parent 9a365ba1
Branches
Tags
4 merge requests!90Develop,!88Use SPF Viper for configuration,!85Draft: Resolve "Overhaul Architecture",!53V.0.1.0 Codename Threadbare
package nucleus package nucleus
import ( import (
"code.fbi.h-da.de/cocsn/gosdn/nucleus/interfaces"
"github.com/google/uuid" "github.com/google/uuid"
) )
// PrincipalNetworkDomain provides an
// interface for PND implementations
type PrincipalNetworkDomain interface {
Destroy() error
AddSbi() error
RemoveSbi() error
AddDevice(Device) error
RemoveDevice(uuid uuid.UUID) error
}
type pndImplementation struct { type pndImplementation struct {
name string name string
sbiContainer map[string]*nucleus.SouthboundInterface sbi map[string]SouthboundInterface
devices map[uuid.UUID]Device devices map[uuid.UUID]Device
} }
//NewPND creates a Principle Network Domain //NewPND creates a Principle Network Domain
func NewPND(name string, sbi *nucleus.SouthboundInterface) nucleus.PrincipalNetworkDomain { func NewPND(name string, sbi SouthboundInterface) PrincipalNetworkDomain {
sbic := make(map[string]*nucleus.SouthboundInterface) sbic := make(map[string]SouthboundInterface)
sbic["default"] = sbi sbic["default"] = sbi
devices := make(map[uuid.UUID]Device)
return &pndImplementation{ return &pndImplementation{
name: name, name: name,
sbiContainer: sbic, sbi: sbic,
devices: devices,
} }
} }
...@@ -35,11 +46,11 @@ func (pnd *pndImplementation) RemoveSbi() error { ...@@ -35,11 +46,11 @@ func (pnd *pndImplementation) RemoveSbi() error {
} }
func (pnd *pndImplementation) AddDevice(device Device) error { func (pnd *pndImplementation) AddDevice(device Device) error {
return addDevice(device) return pnd.addDevice(device)
} }
func (pnd *pndImplementation) RemoveDevice(uuid uuid.UUID) error { func (pnd *pndImplementation) RemoveDevice(uuid uuid.UUID) error {
return removeDevice(uuid) return pnd.removeDevice(uuid)
} }
// Actual implementation, bind to struct if // Actual implementation, bind to struct if
...@@ -56,10 +67,12 @@ func removeSbi() error { ...@@ -56,10 +67,12 @@ func removeSbi() error {
return nil return nil
} }
func addDevice(device Device) error { func (pnd *pndImplementation) addDevice(device Device) error {
pnd.devices[device.Config.Uuid] = device
return nil return nil
} }
func removeDevice(uuid uuid.UUID) error { func (pnd *pndImplementation) removeDevice(uuid uuid.UUID) error {
delete(pnd.devices, uuid)
return nil return nil
} }
package nucleus
import "context"
type Restconf struct {
}
func (rc *Restconf) SetConfig(interface{}) error {
return nil
}
func (rc *Restconf) GetConfig() interface{} {
return nil
}
func (rc *Restconf) Subscribe(ctx context.Context, params ...string) error {
return nil
}
package sbi
import "code.fbi.h-da.de/cocsn/gosdn/nucleus/interfaces"
type OpenConfig struct {
name string
clientContainer []Client
}
//NewSouthboundInterface creates a Southbound Interface
func NewSouthboundInterface(name string, clients ...nucleus.Client) nucleus.SouthboundInterface {
return &OpenConfig{
name: name,
clientContainer: clients,
}
}
// Interface satisfaction
func (sbi *OpenConfig) AddClient() error {
return addClient()
}
func (sbi *OpenConfig) RemoveClient() error {
return removeClient()
}
func (sbi *OpenConfig) CollectHeartbeats() error {
return collectHeartbeats()
}
func (sbi *OpenConfig) ListClients() map[int]nucleus.Client {
return listClients()
}
// Actual implementation, bind to struct if
// neccessary
func addClient() error {
return nil
}
func removeClient() error {
return nil
}
func collectHeartbeats() error {
return nil
}
func listClients() map[int]nucleus.Client {
return nil
}
package nucleus
// SouthboundInterface provides an
// interface for SBI implementations
type SouthboundInterface interface {
GetSBIString() string
}
type Tapi struct {
}
func (t *Tapi) Get(interface{}) (interface{}, error) {
return nil, nil
}
func (t *Tapi) Set(interface{}) error {
return nil
}
func (t *Tapi) Subscribe(interface{}) (interface{}, error) {
return nil, nil
}
type OpenConfig struct {
}
func (oc *OpenConfig) GetSBIString() string {
return "openconfig"
}
func (oc *OpenConfig) Get(interface{}) (interface{}, error) {
return nil, nil
}
func (oc *OpenConfig) Set(interface{}) error {
return nil
}
func (oc *OpenConfig) Subscribe(interface{}) (interface{}, error) {
return nil, nil
}
package util package nucleus
import ( import (
"bytes" "bytes"
"context"
"io" "io"
) )
// Transport provides an interface for
// Transport implementations like RESTCONF
// or gnmi
type Transport interface {
Get(ctx context.Context, params ...string) (interface{}, error)
Set(ctx context.Context, params ...string) (interface{}, error)
Subscribe(ctx context.Context, params ...string) error
}
// YANGConsumer is a auxillary type to redirect the response // YANGConsumer is a auxillary type to redirect the response
// of an RESTCONF call to a ygot YANG unmarshaler // of an RESTCONF call to a ygot YANG unmarshaler
type YANGConsumer struct { type YANGConsumer struct {
......
package transport
package transport
...@@ -4,7 +4,7 @@ import ( ...@@ -4,7 +4,7 @@ import (
"bytes" "bytes"
"code.fbi.h-da.de/cocsn/gosdn/database" "code.fbi.h-da.de/cocsn/gosdn/database"
"code.fbi.h-da.de/cocsn/gosdn/nucleus/interfaces" "code.fbi.h-da.de/cocsn/gosdn/nucleus/interfaces"
"code.fbi.h-da.de/cocsn/gosdn/sbi/restconf/util" t "code.fbi.h-da.de/cocsn/gosdn/nucleus/transport"
apiclient "code.fbi.h-da.de/cocsn/swagger/apis/mcp/client" apiclient "code.fbi.h-da.de/cocsn/swagger/apis/mcp/client"
"code.fbi.h-da.de/cocsn/yang-modules/generated/tapi" "code.fbi.h-da.de/cocsn/yang-modules/generated/tapi"
"crypto/tls" "crypto/tls"
...@@ -19,8 +19,8 @@ import ( ...@@ -19,8 +19,8 @@ import (
"strings" "strings"
) )
//MCPClient handles requests to a Ciena MCP RESTCONF endpoint //Mcp handles requests to a Ciena MCP RESTCONF endpoint
type MCPClient struct { type Mcp struct {
transport *httptransport.Runtime transport *httptransport.Runtime
client *apiclient.ServiceTopologyTAPI client *apiclient.ServiceTopologyTAPI
database *database.Database database *database.Database
...@@ -30,38 +30,38 @@ type MCPClient struct { ...@@ -30,38 +30,38 @@ type MCPClient struct {
} }
// GetConfig returns a ClientConfig struct containing // GetConfig returns a ClientConfig struct containing
// the current configuration stat of the Ciena SBI client // the current configuration stat of the Ciena SBI ciena
func (c MCPClient) GetConfig() nucleus.ClientConfig { func (c Mcp) GetConfig() nucleus.ClientConfig {
return *c.config return *c.config
} }
// ListPorts is a stub to satisfy the interface // ListPorts is a stub to satisfy the interface
// TODO: Implement // TODO: Implement
func (c MCPClient) ListPorts() map[int]nucleus.Port { func (c Mcp) ListPorts() interface{} {
return nil return nil
} }
// PushReceiver is a stub to satisfy the interface // PushReceiver is a stub to satisfy the interface
// TODO: Implement // TODO: Implement
func (c MCPClient) PushReceiver() error { func (c Mcp) PushReceiver() error {
return nil return nil
} }
//NewMCPClient creates a Ciena flavores TAPI client //NewMCPClient creates a Ciena flavores TAPI ciena
func NewMCPClient(endpoint, username, password string, database *database.Database, config *nucleus.ClientConfig) *MCPClient { func NewMCPClient(endpoint, username, password string, database *database.Database, config *nucleus.ClientConfig) *Mcp {
// create the transport // create the transport
transport := httptransport.New(endpoint, "/", nil) transport := httptransport.New(endpoint, "/", nil)
transport.Transport.(*http.Transport).TLSClientConfig = &tls.Config{InsecureSkipVerify: true} transport.Transport.(*http.Transport).TLSClientConfig = &tls.Config{InsecureSkipVerify: true}
// create the API client, with the transport // create the API ciena, with the transport
basicAuth := httptransport.BasicAuth(username, password) basicAuth := httptransport.BasicAuth(username, password)
// authenticate client // authenticate ciena
transport.DefaultAuthentication = basicAuth transport.DefaultAuthentication = basicAuth
client := apiclient.New(transport, strfmt.Default) client := apiclient.New(transport, strfmt.Default)
buffer := new(bytes.Buffer) buffer := new(bytes.Buffer)
transport.Consumers[runtime.JSONMime] = util.YANGConsumer{Data: buffer} transport.Consumers[runtime.JSONMime] = t.YANGConsumer{Data: buffer}
return &MCPClient{ return &Mcp{
transport: transport, transport: transport,
client: client, client: client,
database: database, database: database,
...@@ -72,8 +72,8 @@ func NewMCPClient(endpoint, username, password string, database *database.Databa ...@@ -72,8 +72,8 @@ func NewMCPClient(endpoint, username, password string, database *database.Databa
} }
// GetConnections implements the TAPI Connectivity GetConnections call with a grain of // GetConnections implements the TAPI Connectivity GetConnections call with a grain of
// Ciena salt. The response is written to the client's buffer and passed to the database // Ciena salt. The response is written to the ciena's buffer and passed to the database
func (c *MCPClient) GetConnections() error { func (c *Mcp) GetConnections() error {
defer c.buffer.Reset() defer c.buffer.Reset()
_, err := c.client.TapiConnectivityCore.GetTapiCoreContextConnection(nil) _, err := c.client.TapiConnectivityCore.GetTapiCoreContextConnection(nil)
if err != nil { if err != nil {
...@@ -99,8 +99,8 @@ func (c *MCPClient) GetConnections() error { ...@@ -99,8 +99,8 @@ func (c *MCPClient) GetConnections() error {
} }
// GetLinks implements the TAPI Topology GetLinks call with a grain of // GetLinks implements the TAPI Topology GetLinks call with a grain of
// Ciena salt. The response is written to the client's buffer and passed to the database // Ciena salt. The response is written to the ciena's buffer and passed to the database
func (c *MCPClient) GetLinks() error { func (c *Mcp) GetLinks() error {
defer c.buffer.Reset() defer c.buffer.Reset()
_, err := c.client.TapiTopologyCore.GetTapiCoreContextTopologyMcpBaseTopologyLink(nil) _, err := c.client.TapiTopologyCore.GetTapiCoreContextTopologyMcpBaseTopologyLink(nil)
if err != nil { if err != nil {
...@@ -126,8 +126,8 @@ func (c *MCPClient) GetLinks() error { ...@@ -126,8 +126,8 @@ func (c *MCPClient) GetLinks() error {
} }
// GetNodes implements the TAPI Topology GetNodes call with a grain of // GetNodes implements the TAPI Topology GetNodes call with a grain of
// Ciena salt. The response is written to the client's buffer and passed to the database // Ciena salt. The response is written to the ciena's buffer and passed to the database
func (c *MCPClient) GetNodes() error { func (c *Mcp) GetNodes() error {
defer c.buffer.Reset() defer c.buffer.Reset()
_, err := c.client.TapiTopologyCore.GetTapiCoreContextTopologyMcpBaseTopologyNode(nil) _, err := c.client.TapiTopologyCore.GetTapiCoreContextTopologyMcpBaseTopologyNode(nil)
if err != nil { if err != nil {
...@@ -153,8 +153,8 @@ func (c *MCPClient) GetNodes() error { ...@@ -153,8 +153,8 @@ func (c *MCPClient) GetNodes() error {
} }
// GetNodeEdgePoints implements the TAPI Topology GetNodeEdgePoints call with a grain of // GetNodeEdgePoints implements the TAPI Topology GetNodeEdgePoints call with a grain of
// Ciena salt. The response is written to the client's buffer and passed to the database // Ciena salt. The response is written to the ciena's buffer and passed to the database
func (c *MCPClient) GetNodeEdgePoints() error { func (c *Mcp) GetNodeEdgePoints() error {
defer c.buffer.Reset() defer c.buffer.Reset()
_, err := c.client.TapiTopologyCore.GetTapiCoreContextTopologyMcpBaseTopologyNodeEdgePoint(nil) _, err := c.client.TapiTopologyCore.GetTapiCoreContextTopologyMcpBaseTopologyNodeEdgePoint(nil)
if err != nil { if err != nil {
......
package sbi package plugins
import ( import (
"fmt" "fmt"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment