l3

package
v0.0.0-...-c2e30b8 Latest Latest
Warning

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

Go to latest
Published: Jan 26, 2021 License: NIST-PD-fallback Imports: 10 Imported by: 9

Documentation

Overview

Package l3 defines a network layer face abstraction.

The Transport interface defines a lower layer communication channel. It knows NDN-TLV structure, but not NDN packet types. It should be implemented for different communication technologies. NDNgo library offers Transport implementations for Unix, UDP, TCP, and AF_PACKET sockets.

The Face type is the service exposed to the network layer. It allows sending and receiving packets on a Transport.

Index

Constants

View Source
const (
	DefaultTransportRxQueueSize = 64
	DefaultTransportTxQueueSize = 64
)

TransportQueueConfig defaults.

View Source
const MaxFwFaces = 1 << 23

MaxFwFaces is the maximum number of active FwFaces in a Forwarder.

Variables

View Source
var (
	ErrMaxFwFaces = errors.New("too many FwFaces")
)

Error conditions.

Functions

func DeleteDefaultForwarder

func DeleteDefaultForwarder()

DeleteDefaultForwarder deletes the default Forwarder. This is non-thread-safe and should only be used in test cases.

func NewTransportBase

func NewTransportBase(qcfg TransportQueueConfig) (b *TransportBase, p *TransportBasePriv)

NewTransportBase creates helpers for implementing Transport.

Types

type Face

type Face interface {
	// Transport returns the underlying transport.
	Transport() Transport

	// Rx returns a channel to receive incoming packets.
	// This function always returns the same channel.
	// This channel is closed when the face is closed.
	Rx() <-chan *ndn.Packet

	// Tx returns a channel to send outgoing packets.
	// This function always returns the same channel.
	// Closing this channel causes the face to close.
	Tx() chan<- ndn.L3Packet

	State() TransportState
	OnStateChange(cb func(st TransportState)) io.Closer
}

Face represents a communicate channel to send and receive NDN network layer packets.

func NewFace

func NewFace(tr Transport) (Face, error)

NewFace creates a Face. tr.Rx() and tr.Tx() should not be used after this operation.

type Forwarder

type Forwarder interface {
	// AddTransport constructs a Face and invokes AddFace.
	AddTransport(tr Transport) (FwFace, error)

	// AddFace adds a Face to the forwarder.
	// face.Rx() and face.Tx() should not be used after this operation.
	AddFace(face Face) (FwFace, error)

	// AddReadvertiseDestination adds a destination for prefix announcement.
	//
	// Limitations of current implementation:
	//  - Existing announcements are not advertised on dest.
	//    Thus, it is recommended to add all readvertise destinations before announcing a prefix.
	//  - There is no error handling.
	AddReadvertiseDestination(dest ReadvertiseDestination)

	// RemoveReadvertiseDestination removes a destination for prefix announcement.
	//
	// Limitations of current implementation:
	//  - Announcements are not withdrawn before removing dest.
	//  - There is no error handling.
	RemoveReadvertiseDestination(dest ReadvertiseDestination)
}

Forwarder is a logical forwarding plane. Its main purpose is to demultiplex incoming packets among faces, where a 'face' is defined as a duplex stream of packets.

This is a simplified forwarder with several limitations.

  • There is no loop prevention: no Nonce list and no decrementing HopLimit. If multiple uplinks have "/" route, Interests will be forwarded among them and might cause persistent loops. Thus, it is not recommended to connect to multiple uplinks.
  • There is no pending Interest table. Instead, downstream 'face' ID is inserted as part of the PIT token. Since the NDN-DPDK forwarder expects 8-octet PIT tokens, this takes away some space. Thus, consumers are allowed to use a PIT token up to 4 octets; Interests with longer PIT tokens may be dropped.

func GetDefaultForwarder

func GetDefaultForwarder() Forwarder

GetDefaultForwarder returns the default Forwarder.

func NewForwarder

func NewForwarder() Forwarder

NewForwarder creates a Forwarder.

type FwFace

type FwFace interface {
	io.Closer
	Transport() Transport
	State() TransportState
	OnStateChange(cb func(st TransportState)) io.Closer

	AddRoute(name ndn.Name)
	RemoveRoute(name ndn.Name)

	AddAnnouncement(name ndn.Name)
	RemoveAnnouncement(name ndn.Name)
}

FwFace represents a face added to the forwarder.

func AddUplink(tr Transport) (f FwFace, e error)

AddUplink adds a transport to the default Forwarder and sets the route "/" on the face.

type ReadvertiseDestination

type ReadvertiseDestination interface {
	Advertise(name ndn.Name) error

	Withdraw(name ndn.Name) error
}

ReadvertiseDestination represents a destination of name advertisement.

Generally, a name advertised to a destination would cause Interests matching the name to come to the forwarder. This is also known as name registration.

type Transport

type Transport interface {
	// Rx returns a channel to receive incoming TLV elements.
	// This function always returns the same channel.
	// This channel is closed when the transport is closed.
	Rx() <-chan []byte

	// Tx returns a channel to send outgoing TLV elements.
	// This function always returns the same channel.
	// Closing this channel causes the transport to close.
	Tx() chan<- []byte

	// State returns current state.
	State() TransportState

	// OnStateChange registers a callback to be invoked when State() changes.
	// Returns an io.Closer to cancel the callback registration.
	OnStateChange(cb func(st TransportState)) io.Closer
}

Transport represents a communicate channel to send and receive TLV packets.

type TransportBase

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

TransportBase is an optional helper for implementing Transport.

func (*TransportBase) OnStateChange

func (b *TransportBase) OnStateChange(cb func(st TransportState)) io.Closer

OnStateChange implements Transport.

func (*TransportBase) Rx

func (b *TransportBase) Rx() <-chan []byte

Rx implements Transport.

func (*TransportBase) State

func (b *TransportBase) State() TransportState

State implements Transport.

func (*TransportBase) Tx

func (b *TransportBase) Tx() chan<- []byte

Tx implements Transport.

type TransportBasePriv

type TransportBasePriv struct {
	Rx chan<- []byte
	Tx <-chan []byte
	// contains filtered or unexported fields
}

TransportBasePriv is an optional helper for implementing Transport.

func (*TransportBasePriv) SetState

func (p *TransportBasePriv) SetState(st TransportState)

SetState changes transport state.

type TransportQueueConfig

type TransportQueueConfig struct {
	// RxQueueSize is the Go channel buffer size of RX channel.
	// The default is DefaultTransportRxQueueSize.
	RxQueueSize int `json:"rxQueueSize,omitempty"`

	// TxQueueSize is the Go channel buffer size of TX channel.
	// The default is DefaultTransportTxQueueSize.
	TxQueueSize int `json:"txQueueSize,omitempty"`
}

TransportQueueConfig contains Transport queue configuration.

func (*TransportQueueConfig) ApplyTransportQueueConfigDefaults

func (cfg *TransportQueueConfig) ApplyTransportQueueConfigDefaults()

ApplyTransportQueueConfigDefaults sets empty values to defaults.

type TransportState

type TransportState int

TransportState indicates up/down state of a transport.

const (
	// TransportUp indicates the transport is operational.
	TransportUp TransportState = iota

	// TransportDown indicates the transport is nonoperational.
	TransportDown

	// TransportClosed indicates the transport has been closed.
	// It cannot be restarted.
	TransportClosed
)

Jump to

Keyboard shortcuts

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