netconf

package
v1.2.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 1, 2021 License: Apache-2.0 Imports: 16 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

DefaultCapabilities sets the default capabilities of the client library

View Source
var ErrBadChunk = errors.New("bad chunk")

ErrBadChunk indicates a chunked framing protocol error occurred

Functions

func SSHConfigPubKeyFile

func SSHConfigPubKeyFile(user string, file string, passphrase string) (*ssh.ClientConfig, error)

SSHConfigPubKeyFile is a convenience function that takes a username, private key and passphrase and returns a new ssh.ClientConfig setup to pass credentials to DialSSH

func SplitChunked

func SplitChunked(endOfMessage func()) bufio.SplitFunc

SplitChunked returns a bufio.SplitFunc suitable for decoding "chunked framing" NETCONF transport streams.

endOfMessage will be called at the end of each NETCONF message, and must not be nil.

It must only be used with bufio.Scanner who have a buffer of at least 16 bytes (rarely is this a concern).

Types

type Callback added in v1.2.0

type Callback func(Event)

Callback is a function that can receive events.

type Dispatcher added in v1.2.0

type Dispatcher struct {
	// contains filtered or unexported fields
}

Dispatcher objects can register callbacks for specific events, then when those events occur, dispatch them its according callback functions.

func (*Dispatcher) Dispatch added in v1.2.0

func (d *Dispatcher) Dispatch(eventID string, eventType EventType, value interface{})

Dispatch an event by triggering its associated callback. FIXME manage errors

func (*Dispatcher) Register added in v1.2.0

func (d *Dispatcher) Register(eventID string, callback Callback)

Register a callback function for the specified eventID.

func (*Dispatcher) Remove added in v1.2.0

func (d *Dispatcher) Remove(eventID string)

Remove a callback function for the specified eventID.

func (*Dispatcher) WaitForMessages added in v1.2.0

func (d *Dispatcher) WaitForMessages()

WaitForMessages waits for all messages in the queue to be processed TODO support timeout

type Event added in v1.2.0

type Event interface {
	EventID() string
	Value() interface{}
	RPCReply() *message.RPCReply
	Notification() *message.Notification
}

Event represents actions that occur during NETCONF exchange. Listeners can register callbacks with event handlers when creating a new RPC.

type EventType added in v1.2.0

type EventType uint16

EventType is an enumeration of the kind of events that can occur.

func (EventType) String added in v1.2.0

func (t EventType) String() string

String returns the name of event types

type ReadWriteCloser

type ReadWriteCloser struct {
	io.Reader
	io.WriteCloser
}

ReadWriteCloser represents a combined IO Reader and WriteCloser

func NewReadWriteCloser

func NewReadWriteCloser(r io.Reader, w io.WriteCloser) *ReadWriteCloser

NewReadWriteCloser creates a new combined IO Reader and WriteCloser from the provided objects

type Session

type Session struct {
	Transport                   Transport
	SessionID                   int
	Capabilities                []string
	IsClosed                    bool
	Listener                    *Dispatcher
	IsNotificationStreamCreated bool
}

Session represents a NETCONF sessions with a remote NETCONF server

func DialSSH

func DialSSH(target string, config *ssh.ClientConfig) (*Session, error)

DialSSH creates a new NETCONF session using an SSH Transport. See TransportSSH.Dial for arguments.

func DialSSHTimeout

func DialSSHTimeout(target string, config *ssh.ClientConfig, timeout time.Duration) (*Session, error)

DialSSHTimeout creates a new NETCONF session using an SSH Transport with timeout. See TransportSSH.Dial for arguments. The timeout value is used for both connection establishment and Read/Write operations.

func NewSession

func NewSession(t Transport) *Session

NewSession creates a new NETCONF session using the provided transport layer.

func (*Session) AsyncRPC added in v1.2.0

func (session *Session) AsyncRPC(operation message.RPCMethod, callback Callback) error

AsyncRPC is used to send an RPC method and receive the response asynchronously.

func (*Session) Close

func (session *Session) Close() error

Close is used to close and end a session

func (*Session) CreateNotificationStream added in v1.2.0

func (session *Session) CreateNotificationStream(
	timeout int32, stopTime string, startTime string, stream string, callback Callback,
) error

CreateNotificationStream is a convenient method to create a notification stream registration. TODO limitation - for now, we can only register one stream per session, because when a notification is received there is no way to attribute it to a specific stream

func (*Session) ReceiveHello added in v1.1.1

func (session *Session) ReceiveHello() (*message.Hello, error)

ReceiveHello is the first message received when connecting to a NETCONF server. It provides the supported capabilities of the server.

func (*Session) SendHello added in v1.1.1

func (session *Session) SendHello(hello *message.Hello) error

SendHello send the initial message through NETCONF to advertise supported capability.

func (*Session) SyncRPC added in v1.2.0

func (session *Session) SyncRPC(operation message.RPCMethod, timeout int32) (*message.RPCReply, error)

SyncRPC is used to execute an RPC method and receive the response synchronously

type Transport

type Transport interface {
	Send([]byte) error
	Receive() ([]byte, error)
	Close() error
	SetVersion(version string)
}

Transport interface defines what characteristics make up a NETCONF transport layer object.

type TransportSSH

type TransportSSH struct {
	// contains filtered or unexported fields
}

TransportSSH maintains the information necessary to communicate with the remote device over SSH

func (*TransportSSH) Chunked

func (t *TransportSSH) Chunked(b []byte) ([]byte, error)

func (*TransportSSH) Close

func (t *TransportSSH) Close() error

Close closes an existing SSH session and socket if they exist.

func (*TransportSSH) Dial

func (t *TransportSSH) Dial(target string, config *ssh.ClientConfig) error

Dial connects and establishes SSH sessions

target can be an IP address (e.g.) 172.16.1.1 which utilizes the default NETCONF over SSH port of 830. Target can also specify a port with the following format <host>:<port (e.g. 172.16.1.1:22)

config takes a ssh.ClientConfig connection. See documentation for go.crypto/ssh for documentation. There is a helper function SSHConfigPassword thar returns a ssh.ClientConfig for simple username/password authentication

func (*TransportSSH) Receive

func (t *TransportSSH) Receive() ([]byte, error)

func (*TransportSSH) Send

func (t *TransportSSH) Send(data []byte) error

Send a well formatted NETCONF rpc message as a slice of bytes adding on the necessary framing messages.

func (*TransportSSH) SetVersion

func (t *TransportSSH) SetVersion(version string)

func (*TransportSSH) WaitForBytes

func (t *TransportSSH) WaitForBytes(b []byte) ([]byte, error)

func (*TransportSSH) WaitForFunc

func (t *TransportSSH) WaitForFunc(f func([]byte) (int, error)) ([]byte, error)

func (*TransportSSH) WaitForRegexp

func (t *TransportSSH) WaitForRegexp(re *regexp.Regexp) ([]byte, [][]byte, error)

func (*TransportSSH) WaitForString

func (t *TransportSSH) WaitForString(s string) (string, error)

func (*TransportSSH) Writeln

func (t *TransportSSH) Writeln(b []byte) (int, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL