utils

package
v2.0.2+incompatible Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2019 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Overview

Package utils provides utility functions used in agentctl commands.

Index

Constants

View Source
const (
	ExitSuccess = iota
	ExitError
	ExitBadConnection
	ExitInvalidInput
	ExitBadFeature
	ExitInterrupted
	ExitIO
	ExitBadArgs = 128
)

Common exit flags

View Source
const (
	HostIfName       = "host-if-name"
	MemifMaster      = "master"
	MemifMode        = "mode"
	MemifID          = "id"
	MemifSktFileName = "sock-filename"
	MemifSecret      = "secret"
	MemifRingSize    = "ring-size"
	MemifBufferSize  = "buffer-size"
	MemifRxQueues    = "rx-queues"
	MemifTxQueues    = "tx-queues"
	VxLanSrcAddr     = "src-addr"
	VxLanDstAddr     = "dst-addr"
	VxLanVni         = "vni"
)

Interface flag names

View Source
const (
	// IfConfig labels used by json formatter
	IfConfig = "INTERFACE CONFIG"
	// IfState labels used by json formatter
	IfState = "INTERFACE STATE"
	// BdConfig labels used by json formatter
	BdConfig = "BRIDGE DOMAINS CONFIG"
	// BdState labels used by json formatter
	BdState = "BRIDGE DOMAINS State"
	// L2FibConfig labels used by json formatter
	L2FibConfig = "L2 FIB TABLE"
	// L3FibConfig labels used by json formatter
	L3FibConfig = "L3 FIB TABLE"
)
View Source
const (
	InPkt     string = "IN-PKT"
	InBytes   string = "IN-BYTES"
	InErrPkt  string = "IN-ERR-PKT"
	InMissPkt string = "IN-MISS-PKT"
	InNoBuf   string = "IN-NO-BUFF"
	OutPkt    string = "OUT-PKT"
	OutBytes  string = "OUT-BYTES"
	OutErrPkt string = "OUT-ERR-PKT"
	Drop      string = "DROP"
	Punt      string = "PUNT"
	Ipv4Pkt   string = "IPV4-PKT"
	Ipv6Pkt   string = "IPV6-PKT"

	NoData  string = "Nothing to show, add some data or change the filter"
	NoSpace string = "There is not enough space to show the whole table. Use --short"
)

Used as a header/info message

Variables

This section is empty.

Functions

func DeleteDataFromDb

func DeleteDataFromDb(db keyval.ProtoBroker, key string,
	labelFilter []string, typeFilter []string) (bool, error)

DeleteDataFromDb deletes the specified Key from the database if the Key matches both the labelFilter and the dataFilter.

The function returns an error if the etcd client encountered an error. The function returns true if the specified item has been found and successfully deleted.

func ExitWithError

func ExitWithError(code int, err error)

ExitWithError is used by all commands to print out an error and exit.

func GetDbForAllAgents

func GetDbForAllAgents(endpoints []string) (keyval.ProtoBroker, error)

GetDbForAllAgents opens a connection to etcd, specified in the command line or the "ETCD_ENDPOINTS" environment variable.

func GetDbForOneAgent

func GetDbForOneAgent(endpoints []string, agentLabel string) (keyval.ProtoBroker, error)

GetDbForOneAgent opens a connection to etcd, specified in the command line or the "ETCD_ENDPOINTS" environment variable.

func GetInterfaceKeyAndValue

func GetInterfaceKeyAndValue(endpoints []string, label string, ifName string) (bool, string, *interfaces.Interface, keyval.ProtoBroker)

GetInterfaceKeyAndValue returns true if an interface with the specified name was found together with the interface key, and data, and data broker.

func IsFlagPresent

func IsFlagPresent(flag string) bool

IsFlagPresent verifies flag presence in the OS args.

func ParseKey

func ParseKey(key string) (label string, dataType string, name string, plugStatCfgRev string)

ParseKey parses the etcd Key for the microservice label and the data type encoded in the Key. The function returns the microservice label, the data type and the list of parameters, that contains path segments that follow the data path segment in the Key URL. The parameter list is empty if data path is the Last segment in the Key.

URI Examples: * /vnf-agent/{agent-label}/vpp/config/v1/interface/{interface-name} * /vnf-agent/{agent-label}/vpp/status/v1/interface/{interface-name} * /vnf-agent/{agent-label}/check/status/v1/agent

Explanation of the URI examples: * allAgntsPref label plugin stats ver dataType * ps[0] ps[1] ps[2]ps[3] ps[4]

Example for dataType ... "check/status/v1/"

func UpdateIpv4Address

func UpdateIpv4Address(old []string, updates []string) []string

UpdateIpv4Address updates interface's IPv4 address.

func UpdateIpv6Address

func UpdateIpv6Address(old []string, updates []string) []string

UpdateIpv6Address updates interface's IPv6 address.

func ValidateIpv4Addr

func ValidateIpv4Addr(ipv4Addr string) bool

ValidateIpv4Addr validates string representation of IPv4 address.

func ValidateIpv6Addr

func ValidateIpv6Addr(ipv6Addr string) bool

ValidateIpv6Addr validates string representation of IPv6 address.

func ValidatePhyAddr

func ValidatePhyAddr(pAddr string)

ValidatePhyAddr validates string representation of MAC address.

func WriteInterfaceToDb

func WriteInterfaceToDb(db keyval.ProtoBroker, key string, ifc *interfaces.Interface)

WriteInterfaceToDb validates and writes interface to the etcd.

Types

type BdConfigWithMD

type BdConfigWithMD struct {
	Metadata     VppMetaData
	BridgeDomain *l2.BridgeDomain
}

BdConfigWithMD contains a Bridge Domain config data record and its etcd metadata.

type BdStateWithMD

type BdStateWithMD struct {
	Metadata VppMetaData
}

BdStateWithMD contains a Bridge Domain state data record and its etcd metadata.

type BdWithMD

type BdWithMD struct {
	Config *BdConfigWithMD
	State  *BdStateWithMD
}

BdWithMD contains a Bridge Domain data record and its etcd metadata.

type BridgeDomainErrorWithMD

type BridgeDomainErrorWithMD struct {
	VppMetaData
	BdErrorList []*l2.BridgeDomain
}

BridgeDomainErrorWithMD contains a data record for bridge domain errors and its etcd metadata.

type EtcdDump

type EtcdDump map[string]*VppData

EtcdDump is a map of VppData records. It constitutes a temporary storage for data retrieved from etcd. "Temporary" means during the execution of an agentctl command. Every command reads data from etcd first, then processes it, and finally either outputs the processed data to the user or updates one or more data records in etcd.

func NewEtcdDump

func NewEtcdDump() EtcdDump

NewEtcdDump returns a new instance of the temporary storage that will hold data retrieved from etcd.

func (EtcdDump) CreateEmptyRecord

func (ed EtcdDump) CreateEmptyRecord(key string)

CreateEmptyRecord creates an empty placeholder record in the EtcdDump temporary storage.

func (EtcdDump) PrintDataAsJSON

func (ed EtcdDump) PrintDataAsJSON(filter []string) (*bytes.Buffer, error)

PrintDataAsJSON prints etcd data in JSON format.

func (EtcdDump) PrintDataAsTable

func (ed EtcdDump) PrintDataAsTable(table *goterm.Table, filter []string, short bool, active bool) (*goterm.Table, error)

PrintDataAsTable receives the complete etcd data, applies all filters, flags and other restrictions, then prints table filled with interface statistics.

func (EtcdDump) PrintDataAsText

func (ed EtcdDump) PrintDataAsText(showEtcd bool, printAsTree bool) (*bytes.Buffer, error)

PrintDataAsText prints data from an EtcdDump repo in the text format. If the tree option is chosen, output is printed with tree lines.

func (EtcdDump) ReadDataFromDb

func (ed EtcdDump) ReadDataFromDb(db keyval.ProtoBroker, key string,
	labelFilter []string, typeFilter []string) (found bool, err error)

ReadDataFromDb reads a data record from etcd, parses it according to the expected record type and stores it in the EtcdDump temporary storage. A record is identified by a Key.

The function returns an error if the etcd client encountered an error. The function returns true if the specified item has been found.

type FibTableWithMD

type FibTableWithMD struct {
	VppMetaData
	FibTable []*l2.FIBEntry
}

FibTableWithMD contains an FIB table data record and its etcd metadata.

type IfConfigWithMD

type IfConfigWithMD struct {
	Metadata  VppMetaData
	Interface *interfaces.Interface
}

IfConfigWithMD contains a data record for interface configuration and its etcd metadata.

type IfStateWithMD

type IfStateWithMD struct {
	Metadata       VppMetaData
	InterfaceState *interfaces.InterfaceState
}

IfStateWithMD contains a data record for interface state and its etcd metadata.

type InterfaceErrorWithMD

type InterfaceErrorWithMD struct {
	VppMetaData
}

InterfaceErrorWithMD contains a data record for interface errors and its etcd metadata.

type InterfaceWithMD

type InterfaceWithMD struct {
	Config *IfConfigWithMD
	State  *IfStateWithMD
}

InterfaceWithMD contains a data record for interface and its etcd metadata.

type PfxStack

type PfxStack struct {
	Entries    []PfxStackEntry
	Spaces     int
	FirstDash  string
	MiddleDash string
	LastDash   string
}

PfxStack is helper struct while creating tree output.

func (*PfxStack) GetPreamble

func (stack *PfxStack) GetPreamble(icon string) string

GetPreamble creates the string for a prefix stack entry. The prefix itself is then created by joining all prefix Entries.

func (*PfxStack) GetPrefix

func (stack *PfxStack) GetPrefix() string

GetPrefix returns prefix as a sum of preambles.

func (*PfxStack) Pop

func (stack *PfxStack) Pop()

Pop increases the current prefix stack level (i.e. it make the prefix stack shorter). If the element at the top of the prefix stack is not the the Last element on a list after Pop, it's replaced with the list element (FirstDash) icon.

func (*PfxStack) Push

func (stack *PfxStack) Push()

Push increases the current prefix stack level (i.e. it makes the prefix stack longer). If the list at the current level continues (i.e. the list element is not the Last element), the current prefix element is replaced with a vertical bar (MiddleDash) icon. If the current element is the Last element of a list, the current prefix element is replaced with a space (i.e. the vertical line in the tree will not continue).

func (*PfxStack) SetLast

func (stack *PfxStack) SetLast()

SetLast sets the top element of the prefix stack to display the Last element of a list.

type PfxStackEntry

type PfxStackEntry struct {
	Preamble string
	Last     bool
}

PfxStackEntry represents entry in prefix stack entry list.

type PrintLine

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

PrintLine represents one line in the tree output.

type StaticRoutesWithMD

type StaticRoutesWithMD struct {
	VppMetaData
	Routes []*l3.Route
}

StaticRoutesWithMD contains a static route data record and its etcd metadata.

type TableVppDataContext

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

TableVppDataContext is the data context for one vpp (where number of interfaces == rows) with mandatory info: agent label (vpp name), list of interfaces used in table (without filtered items) and interfaceMap with statistics data.

type TreeWriter

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

TreeWriter is an implementation of the TreePrinter interface.

func NewTreeWriter

func NewTreeWriter(spaces int, first string, middle string, last string) *TreeWriter

NewTreeWriter returns a reference to a newly created TreeWriter instance. Parameters passed into this function determine the visual appearance of the tree in which the data is printed. A typical usage would be:

p := NewTreeWriter(1, "├─", "│ ", "└─")

func (*TreeWriter) FlushTree

func (p *TreeWriter) FlushTree()

FlushTree takes the content of the finalized buffer, and formats it into a tree, and prints it out to stdout.

func (*TreeWriter) Write

func (p *TreeWriter) Write(b []byte) (n int, err error)

Write is an override of io.Write - it only collects the data to be written in a holding buffer for later printing in the FlushTable() function.

type VppData

type VppData struct {
	Interfaces         map[string]InterfaceWithMD
	InterfaceErrors    map[string]InterfaceErrorWithMD
	BridgeDomains      map[string]BdWithMD
	BridgeDomainErrors map[string]BridgeDomainErrorWithMD
	FibTableEntries    FibTableWithMD
	XConnectPairs      map[string]XconnectWithMD
	StaticRoutes       StaticRoutesWithMD
	Status             map[string]VppStatusWithMD
	ShowEtcd           bool
}

VppData defines a structure to hold all etcd data records (of all types) for one VPP.

type VppMetaData

type VppMetaData struct {
	Rev int64
	Key string
}

VppMetaData defines the etcd metadata.

type VppStatusWithMD

type VppStatusWithMD struct {
	VppMetaData
	status.AgentStatus
}

VppStatusWithMD contains a VPP Status data record and its etcd metadata.

type XconnectWithMD

type XconnectWithMD struct {
	VppMetaData
	*l2.XConnectPair
}

XconnectWithMD contains an l2 cross-Connect data record and its etcd metadata.

Jump to

Keyboard shortcuts

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