sysrib

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2023 License: Apache-2.0 Imports: 36 Imported by: 0

Documentation

Overview

Package sysrib implements a system-level RIB that is populated initially using an OpenConfig configuration.

Index

Constants

View Source
const (
	// SockAddr is the unix domain socket address for the Sysrib API.
	SockAddr = "/tmp/sysrib.api"

	// ZAPIAddr is the connection address for ZAPI, which is in the form
	// of "type:address", where type can either be a unix or tcp socket.
	ZAPIAddr = "unix:/var/run/zserv.api"
)
View Source
const (
	AdminDistanceConnected = 0
	AdminDistanceStatic    = 1
	AdminDistanceBGP       = 20
)

AdminDistance is the admin-distance of a routing protocol. See https://docs.frrouting.org/en/latest/zebra.html#administrative-distance

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

Client is a ZAPI client.

func (*Client) HandleRequest

func (c *Client) HandleRequest(conn net.Conn, vrfID uint32)

HandleRequest handles an incoming ZAPI client connection.

func (*Client) RedistributeResolvedRoutes

func (c *Client) RedistributeResolvedRoutes(conn net.Conn)

RedistributeResolvedRoutes sends RedistributeRouteAdd messages to the client connection for all currently-resolved routes.

type Dataplane

type Dataplane struct {
	Client *ygnmi.Client
}

Dataplane is a wrapper around dpb.HALClient to enable testing before resolved route translation.

TODO(wenbli): This is a temporary workaround due to the instability of the API. Once the dataplane API is stable, then we'll want to test at the API layer instead.

func (*Dataplane) ProgramRoute

func (d *Dataplane) ProgramRoute(r *ResolvedRoute) error

programRoute programs the route in the dataplane, returning an error on failure.

type GUEHeaders

type GUEHeaders struct {
	GUEPolicy
	// contains filtered or unexported fields
}

GUEHeaders represents the IP and UDP headers that are to encapsulate the packet.

type GUEPolicy

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

GUEPolicy represents the static values in the IP and UDP headers that are to encapsulate the packet.

srcPort is a hash. dstIP is the nexthop of the BGP route.

type Interface

type Interface struct {
	Name         string `json:"name"`
	Index        int32  `json:"index"`
	Subinterface uint32 `json:"subinterface"`
}

Interface describes an interface of a device.

type NIRIB

type NIRIB struct {
	// IPV4 is the IPv4 RIB
	IPV4 *generics_tree.TreeV4[*Route]
	// IPV6 is the IPv6 RIB
	IPV6 *generics_tree.TreeV6[*Route]
}

NIRIB is the RIB for a single network instance.

type ResolvedNexthop

type ResolvedNexthop struct {
	afthelper.NextHopSummary

	Port       Interface
	GUEHeaders GUEHeaders
}

ResolvedNexthop contains the information required to forward an IP packet.

This type must be hashable, and uniquely identifies nexthops.

func (ResolvedNexthop) HasGUE

func (nh ResolvedNexthop) HasGUE() bool

HasGUE returns a bool indicating whether the resolved nexthop contains GUE information.

type ResolvedRoute

type ResolvedRoute struct {
	RouteKey

	// NOTE: The order of the nexthops should not matter when being programmed into the forwarding plane. As such, the forwarding plane should sort these nexthops before assigning the hash output for ECMP.
	Nexthops map[ResolvedNexthop]bool
}

ResolvedRoute represents a route that is ready to be programmed into the forwarding plane.

type Route

type Route struct {
	// Prefix is a prefix that was being stored.
	Prefix string `json:"prefix"`
	// Connected indicates that the route is directly connected.
	Connected *Interface `json:"connected"`
	// NextHops is the set of IP nexthops that the route uses if
	// it is not a connected route.
	NextHops  []*afthelper.NextHopSummary `json:"nexthops"`
	RoutePref RoutePreference
}

Route is used to store a route in the radix tree.

func NewRouteViaIF

func NewRouteViaIF(pfx string, intf *Interface) *Route

NewRoute returns a new route for the specified prefix. Note - today this doesn't actually result in a viable forwarding entry unless its a connected route :-)

func (*Route) String

func (r *Route) String() string

type RouteKey

type RouteKey struct {
	Prefix string
	NIName string
}

RouteKey is the unique identifier of an IP route.

type RoutePreference

type RoutePreference struct {
	// AdminDistance is the admin distance of the protocol that added this
	// route.
	// See https://docs.frrouting.org/en/latest/zebra.html#administrative-distance
	AdminDistance uint8 `json:"admin-distance"`
	// Metric is the metric of the route. It is comparable only within
	// routes of the same protocol, and therefore the same admin distance.
	Metric uint32 `json:"metric"`
}

type Server

type Server struct {
	pb.UnimplementedSysribServer // For forward-compatibility
	// contains filtered or unexported fields
}

Server is the implementation of the Sysrib API.

API: - SetRoute - addInterfacePrefix - setInterface

func New

func New(cfg *oc.Root) (*Server, error)

New instantiates server to handle client queries.

If dp is nil, then a connection attempt is made.

func (*Server) PrintProgrammedRoutes added in v0.2.0

func (s *Server) PrintProgrammedRoutes()

PrintProgrammedRoutes prints the programmed routes.

func (*Server) ProgrammedRoutes added in v0.3.0

func (s *Server) ProgrammedRoutes() map[RouteKey]*ResolvedRoute

ProgrammedRoutes returns the shallow copy of the programmed routes of the RIB manager.

func (*Server) ResolveAndProgramDiff

func (s *Server) ResolveAndProgramDiff() error

ResolveAndProgramDiff walks through each prefix in the RIB, resolving it and programs the forwarding plane.

TODO(wenbli): handle route deletion.

func (*Server) ResolvedRoutes

func (s *Server) ResolvedRoutes() map[RouteKey]*Route

ResolvedRoutes returns the shallow copy of the resolved routes of the RIB manager.

func (*Server) SetRoute

func (s *Server) SetRoute(_ context.Context, req *pb.SetRouteRequest) (*pb.SetRouteResponse, error)

SetRoute implements ROUTE_ADD and ROUTE_DELETE

func (*Server) Start

func (s *Server) Start(gClient gpb.GNMIClient, target, zapiURL string) error

Start starts the sysrib gRPC service at a unix domain socket. This should be started prior to routing services to allow them to connect to sysrib during their initialization.

- If zapiURL is not specified, then the ZAPI server will not be started.

func (*Server) Stop

func (s *Server) Stop()

Stop stops the sysrib server.

type SysRIB

type SysRIB struct {

	// NI is the list of network instances (aka VRFs)
	NI map[string]*NIRIB

	// GUEPolicies are the configured BGP-triggered GUE policies.
	// Every update to this should trigger a re-computation of the resolved
	// routes.
	// TODO(wenbli): Support v6 GUE policies. When adding support, make
	// sure to error out when an IPv6-mapped IPv4 prefix is provided.
	GUEPoliciesV4 *generics_tree.TreeV4[GUEPolicy]
	GUEPoliciesV6 *generics_tree.TreeV6[GUEPolicy]
	// contains filtered or unexported fields
}

SysRIB is a RIB data structure that can be used to resolve routing entries to their egress interfaces. Currently it supports only IPV4 entries.

func NewSysRIB

func NewSysRIB(initialCfg *oc.Root) (*SysRIB, error)

NewSysRIB returns a SysRIB from an input parsed OpenConfig configuration.

- initialCfg, if specified, will be used to populate connected routes into the RIB manager. Note this is intended to be used for standalone device testing.

func NewSysRIBFromJSON

func NewSysRIBFromJSON(jsonCfg []byte) (*SysRIB, error)

NewSysRIBFromJSON returns a new SysRIB from an RFC7951 marshalled JSON OpenConfig configuration.

func (*SysRIB) AddRoute

func (sr *SysRIB) AddRoute(ni string, r *Route) (bool, error)

AddRoute adds a route, r, to the network instance, ni, in the sysRIB. It returns true if the route was added, and false if not. If the route already exists, it returns (false, nil)

func (*SysRIB) DeleteGUEPolicy

func (sr *SysRIB) DeleteGUEPolicy(prefix string) (bool, error)

DeleteGUEPolicy sets a GUE Policy in the RIB. It returns true if a policy was deleted, and false if not.

func (*SysRIB) EgressInterface

func (sr *SysRIB) EgressInterface(inputNI string, ip *net.IPNet) ([]*Interface, error)

EgressInterface looks up the IP destination address ip in the routes for network instance named inputNI. It returns a slice of the interfaces that the packet would be forwarded via.

TODO(robjs): support determining the NI based solely on the input interface. TODO(robjs): support a better description of a packet using the formats that ONDATRA uses.

TODO(robjs): support WCMP

func (*SysRIB) PrintRIB added in v0.2.0

func (s *SysRIB) PrintRIB()

PrintRIB prints the IPv4 and IPv6 RIBs.

func (*SysRIB) SetGUEPolicy

func (sr *SysRIB) SetGUEPolicy(prefix string, policy GUEPolicy) error

SetGUEPolicy sets a GUE Policy in the RIB.

type ZServer

type ZServer struct {

	// ClientMutex protects the ZAPI client map.
	ClientMutex sync.RWMutex
	// ClientMap stores all connected ZAPI clients.
	ClientMap map[net.Conn]*Client
	// contains filtered or unexported fields
}

ZServer is a ZAPI server.

func StartZServer

func StartZServer(address string, vrfID uint32, sysrib *Server) (*ZServer, error)

StartZServer starts a ZAPI server on the given connection type and path,

e.g. - "unix", "/var/run/zapi.serv"

It also resquires the sysrib server in order to send and receive redistributed routes.

TODO: vrfID is not well-integrated with the sysrib.

func (*ZServer) ClientRegister

func (s *ZServer) ClientRegister(conn net.Conn) *Client

ClientRegister creates a new ZAPI client connection.

func (*ZServer) ClientUnregister

func (s *ZServer) ClientUnregister(conn net.Conn)

ClientUnregister deletes a ZAPI client connection.

func (*ZServer) Stop

func (s *ZServer) Stop()

Stop stops the ZAPI server.

Jump to

Keyboard shortcuts

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