gnmi

package
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2023 License: Apache-2.0 Imports: 11 Imported by: 5

README

Ondatra gNMI API

The Ondatra gNMI API provides test helpers that wrap the API calls to the ygnmi library. Ondatra uses ygnmi (and by extension ygot) to autogenerate gNMI paths and value structs from an input set of YANG modules. Please read the ygnmi README to learn more about how ygnmi translates gNMI paths to Go API calls and how it handles noncompliance errors in telemetry it receives.

Available gNMI Paths

Ondatra provide a combination of OpenConfig and Open Traffic Generator YANG modules as input to the ygnmi auto-generation.

The OpenConfig paths are documented here:

Information on the Open Traffic Generator YANG modules is available here:

If you are using the IxNetwork (aka "ATE") API, see the IxNetwork Telemetry section below to learn which OpenConfig paths are supported by our IxNetwork gNMI implementation.

Best Practice: Avoid time.Sleep

A test often defines a goal state based on telemetry and waits for the device to reach that state. It may be tempting to add a time.Sleep call to insert such a wait into the test, but sleeping is both flaky (the sleep may be too short) and wasteful (the sleep may be unnecessarily long). Tests can more reliably and efficiently wait for a particular telemetry state by using gnmi.Await or gnmi.Watch.

  • Example 1: Wait to an interface to be up

    Use Await to wait until a single interface is up:

    gnmi.Await(t, dut, gnmi.OC().Interface(dp.Name()).OperStatus().State(), time.Minute, oc.Interface_OperStatus_UP)
    
  • Example 2: Wait for at least 100 packets to be sent

    Use Watch to wait until a DUT sends at least 100 packets. Using Await wouldn't be wise here, because the counter may never register exactly 100.

    watch := gnmi.Watch(t, dut, gnmi.OC().Interface(dp.Name()).Counters().OutPkts().State(), time.Minute, func(val *ygnmi.Value[uint64]) bool {
        count, ok := val.Val()
        return ok && count > 100
    })
    if val, ok := watch.Await(t); !ok {
        t.Fatalf("DUT did not reach target state: got %v", val)
    }
    
  • Example 3: Wait for several interfaces to be up

    Use a batch query with Watch to wait for several interfaces to be up in parallel. Using multiple Await calls wouldn't be as efficient, because that would cause the test to wait for each interface in serial.

    batch := gnmi.OCBatch()
    for _, port := range dut.Ports() {
        batch.AddPaths(gnmi.OC().Interface(port.Name()))
    }
    watch := gnmi.Watch(t, dut, batch.State(), time.Minute, func(val *ygnmi.Value[*oc.Root]) bool {
        root, _ := val.Val()
        for _, port := range dut.Ports() {
            if root.GetInterface(port.Name()).GetOperStatus() != oc.Interface_OperStatus_UP {
                return false
            }
        }
        return true
    })
    if val, ok := watch.Await(t); !ok {
        t.Fatalf("DUT did not reach target state: got %v", val)
    }
    

IxNetwork Telemetry

When using Ondatra's IxNetwork (aka "ATE") API, a test can gather statistics and protocol data about the IxNetwork session via gNMI. This section describes the available IxNetwork telemetry and the corresponding OpenConfig paths at which it can be queried. As the IxNetwork telemetry requires a conversion from a REST API to gNMI, you may encounter some necessary limitations in its behavior.

Statistics Views

IxNetwork statistics views are exported to gNMI paths according to the following table:

Ixia Stats gNMI API Path
Port Stats gnmi.OC().Interface($PortName)
Port CPU Stats gnmi.OC().Component($PortName).Cpu()
Flow Stats gnmi.OC().Flow($FlowName)
Ingress Flow Stats gnmi.OC().Flow($FlowName).IngressTrackingAny()
Egress Flow Stats gnmi.OC().Flow($FlowName).EgressTrackingAny()
Routing Data

Learned routing data is exported under an OpenConfig "network instance" with the same name as the interface over which the data was learned. Specifically, routing data is available under gNMI paths that start gnmi.OC().NetworkInstance($InterfaceName), where $InterfaceName is the argument to an ate.AddInterface($InterfaceName) call in the test.

The following routing data is available via gNMI:

  • BGP IPv4 RIB

    gnmi.OC().NetworkInstance($InterfaceName).
    Protocol(oc.PolicyTypes_INSTALL_PROTOCOL_TYPE_BGP, "0").Bgp().Rib().
    AfiSafi(oc.BgpTypes_AFI_SAFI_TYPE_IPV4_UNICAST).Ipv4Unicast().
    Neighbor($DutIp).AdjRibInPre().Route($Prefix, $PathId)
    
  • BGP IPv6 RIB

    gnmi.OC().NetworkInstance($InterfaceName).
    Protocol(oc.PolicyTypes_INSTALL_PROTOCOL_TYPE_BGP, "0").Bgp().Rib().
    AfiSafi(oc.BgpTypes_AFI_SAFI_TYPE_IPV6_UNICAST).Ipv6Unicast().
    Neighbor($DutIp).AdjRibInPre().Route($Prefix, $PathId)
    
  • BGP Attr Sets

    gnmi.OC().NetworkInstance($InterfaceName).
    Protocol(oc.PolicyTypes_INSTALL_PROTOCOL_TYPE_BGP, "0").Bgp().Rib().
    AttrSet($Index)
    
  • BGP Communities

    gnmi.OC().NetworkInstance($InterfaceName).
    Protocol(oc.PolicyTypes_INSTALL_PROTOCOL_TYPE_BGP, "0").Bgp().Rib().
    Community($Index)
    
  • ISIS LSPs

    gnmi.OC().NetworkInstance($InterfaceName).
    Protocol(oc.PolicyTypes_INSTALL_PROTOCOL_TYPE_ISIS, "0").Isis().
    Level($LevelNum).Lsp($LspId)
    
  • RSVP-TE Sessions

    gnmi.OC().NetworkInstance($InterfaceName).Mpls().SignalingProtocols().
    RsvpTe().SessionId($LocalIndex)
    

Documentation

Overview

Package gnmi contains test-friendly gNMI funcs.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Await

func Await[T any](t testing.TB, dev DeviceOrOpts, q ygnmi.SingletonQuery[T], timeout time.Duration, val T) *ygnmi.Value[T]

Await observes values at Query with a STREAM subscription, blocking until a value that is deep equal to the specified val is received or the timeout is reached. To wait for a generic predicate, or to make a non-blocking call, use the Watch method instead.

func BatchDelete

func BatchDelete[T any](sb *SetBatch, q ygnmi.ConfigQuery[T])

BatchDelete stores an delete operation in the SetBatch.

func BatchReplace

func BatchReplace[T any](sb *SetBatch, q ygnmi.ConfigQuery[T], val T)

BatchReplace stores an replace operation in the SetBatch.

func BatchUpdate

func BatchUpdate[T any](sb *SetBatch, q ygnmi.ConfigQuery[T], val T)

BatchUpdate stores an update operation in the SetBatch.

func Delete

func Delete[T any](t testing.TB, dev DeviceOrOpts, q ygnmi.ConfigQuery[T]) *ygnmi.Result

Delete deletes the configuration at the given query path.

func Get

func Get[T any](t testing.TB, dev DeviceOrOpts, q ygnmi.SingletonQuery[T]) T

Get fetches the value of a SingletonQuery with a ONCE subscription, failing the test fatally if no value is present at the path. Use Lookup to also get metadata or tolerate no value present.

func GetAll

func GetAll[T any](t testing.TB, dev DeviceOrOpts, q ygnmi.WildcardQuery[T]) []T

GetAll fetches the value of a WildcardQuery with a ONCE subscription skipping any non-present paths. It fails the test fatally if no value is present at the path Use LookupAll to also get metadata or tolerate no values present.

func GetConfig

func GetConfig[T any](t testing.TB, dev DeviceOrOpts, q ygnmi.ConfigQuery[T]) T

GetConfig fetches the value of a SingletonQuery with a ONCE subscription, failing the test fatally if no value is present at the path. Use Lookup to also get metadata or tolerate no value present. Note: This is a workaround for Go's type inference not working for this use case and may be removed in a subsequent release. Note: This is equivalent to calling Get with a ConfigQuery and providing a fully-qualified type parameter.

func Lookup

func Lookup[T any](t testing.TB, dev DeviceOrOpts, q ygnmi.SingletonQuery[T]) *ygnmi.Value[T]

Lookup fetches the value of a ygnmi.SingletonQuery with a ONCE subscription.

func LookupAll

func LookupAll[T any](t testing.TB, dev DeviceOrOpts, q ygnmi.WildcardQuery[T]) []*ygnmi.Value[T]

LookupAll fetches the values of a ygnmi.WildcardQuery with a ONCE subscription. It returns an empty list if no values are present at the path.

func LookupConfig

func LookupConfig[T any](t testing.TB, dev DeviceOrOpts, q ygnmi.ConfigQuery[T]) *ygnmi.Value[T]

LookupConfig fetches the value of a ygnmi.SingletonQuery with a ONCE subscription. Note: This is a workaround for Go's type inference not working for this use case and may be removed in a subsequent release. Note: This is equivalent to calling Lookup with a ConfigQuery and providing a fully-qualified type parameter.

func OC

func OC() *ocpath.RootPath

OC returns the root OpenConfig gNMI path.

func OCBatch

func OCBatch() *ocpath.Batch

OCBatch returns a new batch collection of OpenConfig gnmi paths.

func OTG

func OTG() *otgpath.RootPath

OTG returns the root Open Traffic Generator gNMI path.

func OTGBatch

func OTGBatch() *otgpath.Batch

OTGBatch returns a new batch collection of Open Traffic Generator gnmi paths.

func Replace

func Replace[T any](t testing.TB, dev DeviceOrOpts, q ygnmi.ConfigQuery[T], val T) *ygnmi.Result

Replace replaces the configuration at the given query path with the val.

func Update

func Update[T any](t testing.TB, dev DeviceOrOpts, q ygnmi.ConfigQuery[T], val T) *ygnmi.Result

Update updates the configuration at the given query path with the val.

Types

type Collector

type Collector[T any] struct {
	// contains filtered or unexported fields
}

Collector represents an ongoing collection of telemetry values.

func Collect

func Collect[T any](t testing.TB, dev DeviceOrOpts, q ygnmi.SingletonQuery[T], timeout time.Duration) *Collector[T]

Collect starts an asynchronous collection of the values at the query with a STREAM subscription. Calling Await on the return Collection waits until the timeout is reached and returns the collected values.

func CollectAll

func CollectAll[T any](t testing.TB, dev DeviceOrOpts, q ygnmi.WildcardQuery[T], timeout time.Duration) *Collector[T]

CollectAll starts an asynchronous collection of the values at the query with a STREAM subscription. Calling Await on the return Collection waits until the timeout is reached and returns the collected values.

func (*Collector[T]) Await

func (c *Collector[T]) Await(t testing.TB) []*ygnmi.Value[T]

Await waits for the collection to finish and returns all received values. When Await returns the watcher is closed, and Await may not be called again. Note: the func blocks until the timeout is reached.

type DeviceOrOpts

type DeviceOrOpts interface {
	GNMIOpts() *Opts
}

DeviceOrOpts is an interface that is ondatra.Device or a gnmi.Opts

type Opts

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

Opts contains customs options for a gNMI request.

func NewOpts

func NewOpts(id string, useGetForConfig bool, initClient func(context.Context) (gpb.GNMIClient, error)) *Opts

NewOpts creates a set of GNMI options. DO NOT USE: call dut.GNMIOpts() or ate.OTG().GNMIOpts() instead.

func (*Opts) GNMIOpts

func (o *Opts) GNMIOpts() *Opts

GNMIOpts implements the DeviceOrOpts interface.

func (*Opts) WithClient

func (o *Opts) WithClient(client gpb.GNMIClient) *Opts

WithClient sets a custom gNMI client to the client, overriding any set by previous calls.

func (*Opts) WithMetadata

func (o *Opts) WithMetadata(md metadata.MD) *Opts

WithMetadata adds metadata to the outgoing context, overriding any set by previous calls.

func (*Opts) WithYGNMIOpts

func (o *Opts) WithYGNMIOpts(opts ...ygnmi.Option) *Opts

WithYGNMIOpts adds the ygnmi Options to the client, overriding any set by previous calls.

type SetBatch

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

SetBatch allows multiple Set operations (Replace, Update, Delete) to be applied as part of a single Set transaction. Use BatchUpdate, BatchReplace, BatchDelete to add operations, and then call the Set method to send the SetRequest.

func (*SetBatch) Set

func (sb *SetBatch) Set(t testing.TB, dev DeviceOrOpts) *ygnmi.Result

Set performs the gnmi.Set request with all queued operations.

type Watcher

type Watcher[T any] struct {
	// contains filtered or unexported fields
}

Watcher represents an ongoing watch of telemetry values.

func Watch

func Watch[T any](t testing.TB, dev DeviceOrOpts, q ygnmi.SingletonQuery[T], timeout time.Duration, pred func(*ygnmi.Value[T]) bool) *Watcher[T]

Watch starts an asynchronous STREAM subscription, evaluating each observed value with the specified predicate. The subscription completes when either the predicate is true or the timeout is reached. Calling Await on the returned Watcher waits for the subscription to complete. It returns the last observed value and a boolean that indicates whether that value satisfies the predicate.

func WatchAll

func WatchAll[T any](t testing.TB, dev DeviceOrOpts, q ygnmi.WildcardQuery[T], timeout time.Duration, pred func(*ygnmi.Value[T]) bool) *Watcher[T]

WatchAll starts an asynchronous STREAM subscription, evaluating each observed value with the specified predicate. The subscription completes when either the predicate is true or the timeout is reached. Calling Await on the returned Watcher waits for the subscription to complete. It returns the last observed value and a boolean that indicates whether that value satisfies the predicate.

func (*Watcher[T]) Await

func (w *Watcher[T]) Await(t testing.TB) (*ygnmi.Value[T], bool)

Await waits for the watch to finish and returns the last received value and a boolean indicating whether the predicate evaluated to true. When Await returns the watcher is closed, and Await may not be called again.

func (*Watcher[T]) Cancel

func (w *Watcher[T]) Cancel()

Cancel stops the watch immediately.

Directories

Path Synopsis
The migrator command contains a runnable version of the analyzer.
The migrator command contains a runnable version of the analyzer.
gnmifix
Package gnmifix fixes deprecated Ondatra Telemetry code.
Package gnmifix fixes deprecated Ondatra Telemetry code.
oc
Package oc is a generated package which contains definitions of structs which represent a YANG schema.
Package oc is a generated package which contains definitions of structs which represent a YANG schema.
acl
Package acl is a generated package which contains definitions of structs which generate gNMI paths for a YANG schema.
Package acl is a generated package which contains definitions of structs which generate gNMI paths for a YANG schema.
ateflow
Package ateflow is a generated package which contains definitions of structs which generate gNMI paths for a YANG schema.
Package ateflow is a generated package which contains definitions of structs which generate gNMI paths for a YANG schema.
definedsets
Package definedsets is a generated package which contains definitions of structs which generate gNMI paths for a YANG schema.
Package definedsets is a generated package which contains definitions of structs which generate gNMI paths for a YANG schema.
gnmicollectormetadata
Package gnmicollectormetadata is a generated package which contains definitions of structs which generate gNMI paths for a YANG schema.
Package gnmicollectormetadata is a generated package which contains definitions of structs which generate gNMI paths for a YANG schema.
interfaces
Package interfaces is a generated package which contains definitions of structs which generate gNMI paths for a YANG schema.
Package interfaces is a generated package which contains definitions of structs which generate gNMI paths for a YANG schema.
keychain
Package keychain is a generated package which contains definitions of structs which generate gNMI paths for a YANG schema.
Package keychain is a generated package which contains definitions of structs which generate gNMI paths for a YANG schema.
lacp
Package lacp is a generated package which contains definitions of structs which generate gNMI paths for a YANG schema.
Package lacp is a generated package which contains definitions of structs which generate gNMI paths for a YANG schema.
lldp
Package lldp is a generated package which contains definitions of structs which generate gNMI paths for a YANG schema.
Package lldp is a generated package which contains definitions of structs which generate gNMI paths for a YANG schema.
networkinstance
Package networkinstance is a generated package which contains definitions of structs which generate gNMI paths for a YANG schema.
Package networkinstance is a generated package which contains definitions of structs which generate gNMI paths for a YANG schema.
ocpath
Package ocpath is a generated package which contains definitions of structs which generate gNMI paths for a YANG schema.
Package ocpath is a generated package which contains definitions of structs which generate gNMI paths for a YANG schema.
platform
Package platform is a generated package which contains definitions of structs which generate gNMI paths for a YANG schema.
Package platform is a generated package which contains definitions of structs which generate gNMI paths for a YANG schema.
qos
Package qos is a generated package which contains definitions of structs which generate gNMI paths for a YANG schema.
Package qos is a generated package which contains definitions of structs which generate gNMI paths for a YANG schema.
routingpolicy
Package routingpolicy is a generated package which contains definitions of structs which generate gNMI paths for a YANG schema.
Package routingpolicy is a generated package which contains definitions of structs which generate gNMI paths for a YANG schema.
sampling
Package sampling is a generated package which contains definitions of structs which generate gNMI paths for a YANG schema.
Package sampling is a generated package which contains definitions of structs which generate gNMI paths for a YANG schema.
system
Package system is a generated package which contains definitions of structs which generate gNMI paths for a YANG schema.
Package system is a generated package which contains definitions of structs which generate gNMI paths for a YANG schema.
terminaldevice
Package terminaldevice is a generated package which contains definitions of structs which generate gNMI paths for a YANG schema.
Package terminaldevice is a generated package which contains definitions of structs which generate gNMI paths for a YANG schema.
otg
Package otg is a generated package which contains definitions of structs which represent a YANG schema.
Package otg is a generated package which contains definitions of structs which represent a YANG schema.
bgp
Package bgp is a generated package which contains definitions of structs which generate gNMI paths for a YANG schema.
Package bgp is a generated package which contains definitions of structs which generate gNMI paths for a YANG schema.
discovery
Package discovery is a generated package which contains definitions of structs which generate gNMI paths for a YANG schema.
Package discovery is a generated package which contains definitions of structs which generate gNMI paths for a YANG schema.
flow
Package flow is a generated package which contains definitions of structs which generate gNMI paths for a YANG schema.
Package flow is a generated package which contains definitions of structs which generate gNMI paths for a YANG schema.
isis
Package isis is a generated package which contains definitions of structs which generate gNMI paths for a YANG schema.
Package isis is a generated package which contains definitions of structs which generate gNMI paths for a YANG schema.
lacp
Package lacp is a generated package which contains definitions of structs which generate gNMI paths for a YANG schema.
Package lacp is a generated package which contains definitions of structs which generate gNMI paths for a YANG schema.
lag
Package lag is a generated package which contains definitions of structs which generate gNMI paths for a YANG schema.
Package lag is a generated package which contains definitions of structs which generate gNMI paths for a YANG schema.
lldp
Package lldp is a generated package which contains definitions of structs which generate gNMI paths for a YANG schema.
Package lldp is a generated package which contains definitions of structs which generate gNMI paths for a YANG schema.
otgpath
Package otgpath is a generated package which contains definitions of structs which generate gNMI paths for a YANG schema.
Package otgpath is a generated package which contains definitions of structs which generate gNMI paths for a YANG schema.
port
Package port is a generated package which contains definitions of structs which generate gNMI paths for a YANG schema.
Package port is a generated package which contains definitions of structs which generate gNMI paths for a YANG schema.
rsvp
Package rsvp is a generated package which contains definitions of structs which generate gNMI paths for a YANG schema.
Package rsvp is a generated package which contains definitions of structs which generate gNMI paths for a YANG schema.

Jump to

Keyboard shortcuts

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