Newer
Older
"code.fbi.h-da.de/cocsn/gosdn/database"
"code.fbi.h-da.de/cocsn/gosdn/log"
"code.fbi.h-da.de/cocsn/gosdn/nucleus/interfaces"
"code.fbi.h-da.de/cocsn/gosdn/sbi/restconf/util"
"crypto/tls"
"github.com/go-openapi/runtime"
httptransport "github.com/go-openapi/runtime/client"
"github.com/go-openapi/strfmt"
//MCPClient handles requests to a Ciena MCP RESTCONF endpoint
type MCPClient struct {
transport *httptransport.Runtime
client *apiclient.ServiceTopologyTAPI
// GetConfig returns a ClientConfig struct containing
// the current configuration stat of the Ciena SBI client
func (c MCPClient) GetConfig() interfaces.ClientConfig {
return *c.config
//NewMCPClient creates a Ciena flavores TAPI client
func NewMCPClient(endpoint, username, password string, database *database.Database, config *interfaces.ClientConfig) *MCPClient {
transport.Transport.(*http.Transport).TLSClientConfig = &tls.Config{InsecureSkipVerify: true}
// create the API client, with the transport
basicAuth := httptransport.BasicAuth(username, password)
// authenticate client
transport.DefaultAuthentication = basicAuth
buffer := new(bytes.Buffer)
transport.Consumers[runtime.JSONMime] = util.YANGConsumer{Data: buffer}
database: database,
buffer: buffer,
// 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
_, err := c.client.TapiConnectivityCore.GetTapiCoreContextConnection(nil)
if err != nil { return err}
dest := &tapi.TapiCommon_Context_ConnectivityContext_Connection{}
if err := tapi.Unmarshal(c.buffer.Bytes(), dest); err != nil { return err }
c.database.StoreConnections(c.buffer.String())
log.Debug(c.buffer.Next(25))
// 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
func (c *MCPClient) GetLinks() error {
defer c.buffer.Reset()
_, err := c.client.TapiTopologyCore.GetTapiCoreContextTopologyMcpBaseTopologyLink(nil)
if err != nil { return err}
dest := &tapi.TapiCommon_Context_TopologyContext_Topology_Link{}
if err := tapi.Unmarshal(c.buffer.Bytes(), dest); err != nil { return err }
log.Debug(c.buffer.Next(25))
return err
}
// 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
_, err := c.client.TapiTopologyCore.GetTapiCoreContextTopologyMcpBaseTopologyNode(nil)
if err != nil { return err}
dest := &tapi.TapiCommon_Context_TopologyContext_Topology_Node{}
if err := tapi.Unmarshal(c.buffer.Bytes(), dest); err != nil { return err }
c.database.StoreNodes(c.buffer.String())
log.Debug(c.buffer.Next(25))
// 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
_, err := c.client.TapiTopologyCore.GetTapiCoreContextTopologyMcpBaseTopologyNodeEdgePoint(nil)
if err != nil { return err}
dest := &tapi.TapiCommon_Context_TopologyContext_Topology_Link_NodeEdgePoint{}
if err := tapi.Unmarshal(c.buffer.Bytes(), dest); err != nil { return err }
c.database.StoreNodeEdgePoints(c.buffer.String())
log.Debug(c.buffer.Next(25))