utils

package
v1.0.6 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2017 License: Apache-2.0 Imports: 26 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 (
	BDName       = "bridge-domain-name"
	IfName       = "interface-name"
	BVI          = "bvi"
	SHZ          = "split-horizon-group"
	IPAddress    = "ip-address"
	PhysAddress  = "physical-address"
	StaticConfig = "static-config"
	IsDrop       = "is-drop"
	IsDelete     = "is-delete"
)

Bridge domain 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 DeleteFibDataFromDb

func DeleteFibDataFromDb(db keyval.ProtoBroker, key string)

DeleteFibDataFromDb removes FIB entry from the ETCD

func ExitWithError

func ExitWithError(code int, err error)

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

func GetBridgeDomainKeyAndValue

func GetBridgeDomainKeyAndValue(endpoints []string, label string, bdName string) (bool, string, *l2.BridgeDomains_BridgeDomain, keyval.ProtoBroker)

GetBridgeDomainKeyAndValue returns true if a bridge domain with the specified name was found together with the BD key, data and data broker

func GetDbForAllAgents

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

GetDbForAllAgents opens a connection to Etcd specified in the command line or the "ETCDV3_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 "ETCDV3_ENDPOINTS" environment variable

func GetFibEntry

func GetFibEntry(endpoints []string, label string, bdLabel string, fibMac string) (bool, string, *l2.FibTableEntries_FibTableEntry)

GetFibEntry returns the FIB entry if exists

func GetInterfaceKeyAndValue

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

GetInterfaceKeyAndValue returns true if an interface with the specified name was found together with the interface key, 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 a 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 WriteBridgeDomainToDb

func WriteBridgeDomainToDb(db keyval.ProtoBroker, key string, bd *l2.BridgeDomains_BridgeDomain)

WriteBridgeDomainToDb writes bridge domain to the ETCD

func WriteFibDataToDb

func WriteFibDataToDb(db keyval.ProtoBroker, key string, fib *l2.FibTableEntries_FibTableEntry)

WriteFibDataToDb writes FIB entry to the ETCD

func WriteInterfaceToDb

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

WriteInterfaceToDb validates and writes interface to the ETCD

Types

type BdConfigWithMD

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

BdConfigWithMD contains a Bridge Domain config data record and its Etcd metadata

type BdStateWithMD

type BdStateWithMD struct {
	Metadata          VppMetaData
	BridgeDomainState *l2.BridgeDomainState_BridgeDomain
}

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.BridgeDomainErrors_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 first reads data from Etcd, 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 text format. If 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.FibTableEntries_FibTableEntry
}

FibTableWithMD contains a FIB table data record and its Etcd metadata

type IfConfigWithMD

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

IfConfigWithMD contains a data record for interface configuration and its Etcd metadata

type IfStateWithMD

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

IfStateWithMD contains a data record for interface State and its Etcd metadata

type InterfaceErrorWithMD

type InterfaceErrorWithMD struct {
	VppMetaData
	InterfaceErrorList []*interfaces.InterfaceErrors_Interface
}

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 after Pop the element at the top of the prefix stack is not the the Last element on a list, it's replaced by 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.StaticRoutes_Route
}

StaticRoutesWithMD contains a static route data record and its Etcd metadata

type TableVppDataContext

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

TableVppDataContext is 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 data is printed. A typical usage would be:

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

func (*TreeWriter) FlushTree

func (p *TreeWriter) FlushTree()

FlushTree takes the content of the finalize buffer 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 just 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.XConnectPairs_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