flow

package
v0.6.2 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2018 License: BSD-3-Clause Imports: 9 Imported by: 9

Documentation

Overview

Package flow is the main package of NFF-GO library and should be always imported by user application.

Package flow is the main package of NFF-GO library and should be always imported by user application.

Index

Constants

View Source
const RSSCloneMax = 39
View Source
const RSSCloneMin = 5

TODO "5" and "39" constants derived empirically. Need to investigate more elegant thresholds.

Variables

This section is empty.

Functions

func CheckFatal

func CheckFatal(err error)

CheckFatal is a default error handling function, which prints error message and makes os.Exit in case of non nil error. Any other error handler can be used instead.

func CheckHWCapability

func CheckHWCapability(capa HWCapability, ports []uint16) bool

CheckHWCapability return true if hardware offloading capability present in all ports. Otherwise it returns false.

func DealARPICMP

func DealARPICMP(IN *Flow) error

DealARPICMP is predefined function which will generate replies to ARP and ICMP requests and automatically extract corresponding packets from input flow. If used after merge, function answers packets received on all input ports.

func FillSliceFromMask

func FillSliceFromMask(input []uintptr, mask *[burstSize]bool, output []uintptr) uint8

func GetPortMACAddress

func GetPortMACAddress(port uint16) [common.EtherAddrLen]uint8

GetPortMACAddress returns default MAC address of an Ethernet port.

func SetHandler

func SetHandler(IN *Flow, handleFunction HandleFunction, context UserContext) error

SetHandler adds handle function to flow graph. Gets flow, user defined handle function and context. Each packet from input flow will be handle inside user defined function and sent further in the same flow.

func SetHandlerDrop

func SetHandlerDrop(IN *Flow, separateFunction SeparateFunction, context UserContext) error

SetHandlerDrop adds vector handle function to flow graph. Gets flow, user defined handle function and context. User defined function can return boolean value. If user function returns false after handling a packet it is dropped automatically.

func SetIPForPort

func SetIPForPort(port uint16, ip uint32) error

SetIPForPort sets IP for specified port if it was created. Not thread safe. Return error if requested port isn't exist or wasn't previously requested.

func SetSender

func SetSender(IN *Flow, portId uint16) error

SetSender adds send function to flow graph. Gets flow which will be closed and its packets will be send and port number for which packets will be sent. Send queue will be added to port automatically.

func SetSenderFile

func SetSenderFile(IN *Flow, filename string) error

SetSenderFile adds write function to flow graph. Gets flow which packets will be written to file and target file name.

func SetSenderKNI

func SetSenderKNI(IN *Flow, kni *Kni) error

SetSenderKNI adds function sending to KNI to flow graph. Gets flow which will be closed and its packets will be send to given KNI device. Send queue will be added to port automatically.

func SetStopper

func SetStopper(IN *Flow) error

SetStopper adds stop function to flow graph. Gets flow which will be closed and all packets from each will be dropped.

func SetUseHWCapability

func SetUseHWCapability(capa HWCapability, use bool)

SetUseHWCapability enables or disables using a hardware offloading capability.

func SetVectorHandler

func SetVectorHandler(IN *Flow, vectorHandleFunction VectorHandleFunction, context UserContext) error

SetVectorHandler adds vector handle function to flow graph. Gets flow, user defined vector handle function and context. Each packet from input flow will be handle inside user defined function and sent further in the same flow.

func SetVectorHandlerDrop

func SetVectorHandlerDrop(IN *Flow, vectorSeparateFunction VectorSeparateFunction, context UserContext) error

SetVectorHandlerDrop adds vector handle function to flow graph. Gets flow, user defined vector handle function and context. User defined function can return boolean value. If user function returns false after handling a packet it is dropped automatically.

func SystemInit

func SystemInit(args *Config) error

SystemInit is initialization of system. This function should be always called before graph construction.

func SystemInitPortsAndMemory

func SystemInitPortsAndMemory() error

SystemInitPortsAndMemory performs all initialization necessary to create and send new packets before scheduler may be started.

func SystemReset

func SystemReset()

SystemReset stops whole framework plus cleanup DPDK TODO DPDK cleanup is now incomplete at DPDK side It is n't able to re-init after it and also is under deprecated pragma. Need to fix after DPDK changes.

func SystemStart

func SystemStart() error

SystemStart starts system - begin packet receiving and packet sending. This functions should be always called after flow graph construction. Function can panic during execution.

func SystemStartScheduler

func SystemStartScheduler() error

SystemStartScheduler starts scheduler packet processing. Function does not return.

func SystemStop

func SystemStop()

SystemStop stops the system. All Flow functions plus resource releasing Doesn't cleanup DPDK

Types

type Config

type Config struct {
	// Specifies cores which will be available for scheduler to place
	// flow functions and their clones.
	CPUList string
	// If true, scheduler is disabled entirely. Default value is false.
	DisableScheduler bool
	// If true, scheduler does not stop any previously cloned flow
	// function threads. Default value is false.
	PersistentClones bool
	// If true, Stop routine gets a dedicated CPU core instead of
	// running together with scheduler. Default value is false.
	StopOnDedicatedCore bool
	// Calculate IPv4, UDP and TCP checksums in hardware. This flag
	// slows down general TX processing, so it should be enabled if
	// applications intends to modify packets often, and therefore
	// needs to recalculate their checksums. If application doesn't
	// modify many packets, it may chose to calculate checksums in SW
	// and leave this flag off. Default value is false.
	HWTXChecksum bool
	// Specifies number of mbufs in mempool per port. Default value is
	// 8191.
	MbufNumber uint
	// Specifies number of mbufs in per-CPU core cache in
	// mempool. Default value is 250.
	MbufCacheSize uint
	// Number of burstSize groups in all rings. This should be power
	// of 2. Default value is 256.
	RingSize uint
	// Time between scheduler actions in miliseconds. Default value is
	// 1500.
	ScaleTime uint
	// Time in miliseconds for scheduler to check changing of flow
	// function behaviour. Default value is 10000.
	CheckTime uint
	// Time in miliseconds for scheduler to display statistics.
	// Default value is 1000.
	DebugTime uint
	// Specifies logging type. Default value is common.No |
	// common.Initialization | common.Debug.
	LogType common.LogType
	// Command line arguments to pass to DPDK initialization.
	DPDKArgs []string
	// Is user going to use KNI
	NeedKNI bool
	// Maximum simultaneous receives that should handle all
	// input at your network card
	MaxRecv int
	// Limits parallel instances. 1 for one instance, 1000 for RSS count determine instances
	MaxInIndex int32
	// Scheduler should clone functions even if ti can lead to reordering.
	// This option should be switch off for all high level reassembling like TCP or HTTP
	RestrictedCloning bool
}

Config is a struct with all parameters, which user can pass to NFF-GO library

type Flow

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

Flow is an abstraction for connecting flow functions with each other. Flow shouldn't be understood in any way beyond this.

func SetCopier

func SetCopier(IN *Flow) (OUT *Flow, err error)

SetCopier adds copy function to flow graph. Gets flow which will be copied.

func SetFastGenerator

func SetFastGenerator(f GenerateFunction, targetSpeed uint64, context UserContext) (OUT *Flow, err error)

SetFastGenerator adds clonable generate function to flow graph. Gets user-defined generate function, target speed of generation user wants to achieve and context. Returns new open flow with generated packets. Function tries to achieve target speed by cloning.

func SetGenerator

func SetGenerator(f GenerateFunction, context UserContext) (OUT *Flow)

SetGenerator adds non-clonable generate flow function to flow graph. Gets user-defined generate function and context. Returns new open flow with generated packets. Single packet non-clonable flow function will be added. It can be used for waiting of input user packets.

func SetMerger

func SetMerger(InArray ...*Flow) (OUT *Flow, err error)

SetMerger adds merge function to flow graph. Gets any number of flows. Returns new opened flow. All input flows will be closed. All packets from all these flows will be sent to new flow. This function isn't use any cores. It changes output flows of other functions at initialization stage.

func SetPartitioner

func SetPartitioner(IN *Flow, N uint64, M uint64) (OUT *Flow, err error)

SetPartitioner adds partition function to flow graph. Gets input flow and N and M constants. Returns new opened flow. Each loop N packets will be remained in input flow, next M packets will be sent to new flow. It is advised not to use this function less then (75, 75) for performance reasons. We make partition function unclonable. The most complex task is (1,1). It means that if you would like to simply divide a flow it is recommended to use (75,75) instead of (1,1) for performance reasons.

func SetReceiver

func SetReceiver(portId uint16) (OUT *Flow, err error)

SetReceiver adds receive function to flow graph. Gets port number from which packets will be received. Receive queue will be added to port automatically. Returns new opened flow with received packets

func SetReceiverFile

func SetReceiverFile(filename string, repcount int32) (OUT *Flow)

SetReceiverFile adds read function to flow graph. Gets name of pcap formatted file and number of reads. If repcount = -1, file is read infinitely in circle. Returns new opened flow with read packets.

func SetReceiverKNI

func SetReceiverKNI(kni *Kni) (OUT *Flow)

SetReceiverKNI adds function receive from KNI to flow graph. Gets KNI device from which packets will be received. Receive queue will be added to port automatically. Returns new opened flow with received packets

func SetSeparator

func SetSeparator(IN *Flow, separateFunction SeparateFunction, context UserContext) (OUT *Flow, err error)

SetSeparator adds separate function to flow graph. Gets flow, user defined separate function and context. Returns new opened flow. Each packet from input flow will be remain inside input packet if user defined function returns "true" and is sent to new flow otherwise.

func SetSplitter

func SetSplitter(IN *Flow, splitFunction SplitFunction, flowNumber uint, context UserContext) (OutArray [](*Flow), err error)

SetSplitter adds split function to flow graph. Gets flow, user defined split function, flowNumber of new flows and context. Returns array of new opened flows with corresponding length. Each packet from input flow will be sent to one of new flows based on user defined function output for this packet.

func SetVectorFastGenerator

func SetVectorFastGenerator(f VectorGenerateFunction, targetSpeed uint64, context UserContext) (OUT *Flow, err error)

SetVectorFastGenerator adds clonable vector generate function to flow graph. Gets user-defined vector generate function, target speed of generation user wants to achieve and context. Returns new open flow with generated packets. Function tries to achieve target speed by cloning.

func SetVectorSeparator

func SetVectorSeparator(IN *Flow, vectorSeparateFunction VectorSeparateFunction, context UserContext) (OUT *Flow, err error)

SetVectorSeparator adds vector separate function to flow graph. Gets flow, user defined vector separate function and context. Returns new opened flow. Each packet from input flow will be remain inside input packet if user defined function returns "true" and is sent to new flow otherwise.

func SetVectorSplitter

func SetVectorSplitter(IN *Flow, vectorSplitFunction VectorSplitFunction, flowNumber uint, context UserContext) (OutArray [](*Flow), err error)

SetVectorSplitter adds vector split function to flow graph. Gets flow, user defined vector split function, flowNumber of new flows and context. Returns array of new opened flows with corresponding length. Each packet from input flow will be sent to one of new flows based on user defined function output for this packet.

type Func

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

type GenerateFunction

type GenerateFunction func(*packet.Packet, UserContext)

GenerateFunction is a function type for user defined function which generates packets. Function receives preallocated packet where user should add its size and content.

type HWCapability

type HWCapability int
const (
	HWTXChecksumCapability HWCapability = iota
)

type HandleFunction

type HandleFunction func(*packet.Packet, UserContext)

HandleFunction is a function type for user defined function which handles packets. Function receives a packet from flow. User should parse it and make necessary changes. It is prohibit to free packet in this function.

type Kni

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

Kni is a high level struct of KNI device. The device itself is stored in C memory in low.c and is defined by its port which is equal to port in this structure

func CreateKniDevice

func CreateKniDevice(portId uint16, name string) (*Kni, error)

CreateKniDevice creates KNI device for using in receive or send functions. Gets unique port, and unique name of future KNI device.

type SeparateFunction

type SeparateFunction func(*packet.Packet, UserContext) bool

SeparateFunction is a function type for user defined function which separates packets based on some rule for two flows. Functions receives a packet from flow. User should parse it and decide whether this packet should remains in this flow - return true, or should be sent to new added flow - return false.

type SplitFunction

type SplitFunction func(*packet.Packet, UserContext) uint

SplitFunction is a function type for user defined function which splits packets based in some rule for multiple flows. Function receives a packet from flow. User should parse it and decide in which output flows this packet should be sent. Return number of flow shouldn't exceed target number which was put to SetSplitter function. Also it is assumed that "0" output flow is used for dropping packets - "Stop" function should be set after "Split" function in it.

type Timer

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

func AddTimer

func AddTimer(d time.Duration, handler func(UserContext)) *Timer

AddTimer adds a timer which may call handler function every d milliseconds It is required to add at least one variant of this timer for working TODO d should be approximate as schedTime because handler will be call from scheduler Return created timer

func (*Timer) AddVariant

func (timer *Timer) AddVariant(context UserContext) *bool

AddVariant adds a variant for an existing timer. Variant is a context parameter which will be passed to handler callback from AddTimer function Function return a pointer to variable which should be set to "true" everytime to prevent timer from ping. Timer variant automatically drops after timer invocation

func (*Timer) Stop

func (timer *Timer) Stop()

Stop removes timer with all its variants

type UserContext

type UserContext interface {
	Copy() interface{}
	Delete()
}

UserContext is used inside flow packet and is going for user via it

type VectorGenerateFunction

type VectorGenerateFunction func([]*packet.Packet, UserContext)

VectorGenerateFunction is a function type like GenerateFunction for vector generating

type VectorHandleFunction

type VectorHandleFunction func([]*packet.Packet, *[burstSize]bool, UserContext)

VectorHandleFunction is a function type like HandleFunction for vector handling

type VectorSeparateFunction

type VectorSeparateFunction func([]*packet.Packet, *[burstSize]bool, *[burstSize]bool, UserContext)

VectorSeparateFunction is a function type like SeparateFunction for vector separation

type VectorSplitFunction

type VectorSplitFunction func([]*packet.Packet, *[burstSize]bool, *[burstSize]uint8, UserContext)

VectorSplitFunction is a function type like SplitFunction for vector splitting

Jump to

Keyboard shortcuts

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