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
- func CheckFatal(err error)
- func CheckHWCapability(capa HWCapability, ports []uint16) []bool
- func DealARPICMP(IN *Flow) error
- func FillSliceFromMask(input []uintptr, mask *[vBurstSize]bool, output []uintptr) uint8
- func GetNameByPort(port uint16) (string, error)
- func GetPortByName(name string) (uint16, error)
- func GetPortMACAddress(port uint16) [types.EtherAddrLen]uint8
- func SetHandler(IN *Flow, handleFunction HandleFunction, context UserContext) error
- func SetHandlerDrop(IN *Flow, separateFunction SeparateFunction, context UserContext) error
- func SetIPForPort(port uint16, ip types.IPv4Address) error
- func SetSender(IN *Flow, portId uint16) error
- func SetSenderFile(IN *Flow, filename string) error
- func SetSenderKNI(IN *Flow, kni *Kni) error
- func SetSenderOS(IN *Flow, device string) error
- func SetSenderXDP(IN *Flow, device string) error
- func SetStopper(IN *Flow) error
- func SetUseHWCapability(capa HWCapability, use bool)
- func SetVectorHandler(IN *Flow, vectorHandleFunction VectorHandleFunction, context UserContext) error
- func SetVectorHandlerDrop(IN *Flow, vectorSeparateFunction VectorSeparateFunction, context UserContext) error
- func SystemInit(args *Config) error
- func SystemInitPortsAndMemory() error
- func SystemReset()
- func SystemStart() error
- func SystemStartScheduler() error
- func SystemStop() error
- type Config
- type Flow
- func SetCopier(IN *Flow) (OUT *Flow, err error)
- func SetFastGenerator(f GenerateFunction, targetSpeed uint64, context UserContext) (OUT *Flow, tc chan uint64, err error)
- func SetGenerator(f GenerateFunction, context UserContext) (OUT *Flow)
- func SetMerger(InArray ...*Flow) (OUT *Flow, err error)
- func SetPartitioner(IN *Flow, N uint64, M uint64) (OUT *Flow, err error)
- func SetReceiver(portId uint16) (OUT *Flow, err error)
- func SetReceiverFile(filename string, repcount int32) (OUT *Flow)
- func SetReceiverKNI(kni *Kni) (OUT *Flow)
- func SetReceiverOS(device string) (*Flow, error)
- func SetReceiverXDP(device string, queue int) (*Flow, error)
- func SetSenderReceiverKNI(IN *Flow, kni *Kni, linuxCore bool) (OUT *Flow, err error)
- func SetSeparator(IN *Flow, separateFunction SeparateFunction, context UserContext) (OUT *Flow, err error)
- func SetSplitter(IN *Flow, splitFunction SplitFunction, flowNumber uint, context UserContext) (OutArray [](*Flow), err error)
- func SetVectorFastGenerator(f VectorGenerateFunction, targetSpeed uint64, context UserContext) (OUT *Flow, tc chan uint64, err error)
- func SetVectorSeparator(IN *Flow, vectorSeparateFunction VectorSeparateFunction, context UserContext) (OUT *Flow, err error)
- func SetVectorSplitter(IN *Flow, vectorSplitFunction VectorSplitFunction, flowNumber uint, ...) (OutArray [](*Flow), err error)
- type Func
- type GenerateFunction
- type HWCapability
- type HandleFunction
- type KNIParameters
- type Kni
- type SeparateFunction
- type SplitFunction
- type Timer
- type UserContext
- type VectorGenerateFunction
- type VectorHandleFunction
- type VectorSeparateFunction
- type VectorSplitFunction
Constants ¶
const RSSCloneMax = 39
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 returns array of booleans for every requested port. An element of this array is set to true if hardware offloading capability is supported on corresponding port, otherwise it is set to false.
func DealARPICMP ¶
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 GetNameByPort ¶ added in v0.7.3
GetNameByPort gets the device name from port id. The device name is specified as below:
- PCIe address (Domain:Bus:Device.Function), for example- 0000:02:00.0 - SoC device name, for example- fsl-gmac0 - vdev dpdk name, for example- net_[pcap0|null0|tun0|tap0]
func GetPortByName ¶ added in v0.7.3
GetPortByName gets the port id from device name. The device name should be specified as below:
- PCIe address (Domain:Bus:Device.Function), for example- 0000:2:00.0 - SoC device name, for example- fsl-gmac0 - vdev dpdk name, for example- net_[pcap0|null0|tap0]
func GetPortMACAddress ¶
func GetPortMACAddress(port uint16) [types.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 types.IPv4Address) 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 ¶
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 ¶
SetSenderFile adds write function to flow graph. Gets flow which packets will be written to file and target file name.
func SetSenderKNI ¶
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 SetSenderOS ¶ added in v0.8.0
SetSenderOS adds function send from flow graph to Linux interface. Gets name of device, will return error if can't initialize socket. Creates RAW socket, sends packets, closes input flow.
func SetSenderXDP ¶ added in v0.9.0
SetSenderXDP adds function send from flow graph to Linux AF_XDP interface. Gets name of device, will return error if can't initialize socket. Creates RAW socket, sends packets, closes input flow.
func SetStopper ¶
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 ¶
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() error
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 it can lead to reordering. // This option should be switched off for all high level reassembling like TCP or HTTP RestrictedCloning bool // If application uses EncapsulateHead or DecapsulateHead functions L2 pointers // should be reinit every receving or generating a packet. This can be removed if // EncapsulateHead and DecapsulateHead are not in use NoPacketHeadChange bool // HTTP server address to use for serving statistics and // telemetry. Server provides different types of statistics which // can be controlled by statistics flags. File format is // JSON. Registered roots return statistics for all framework // graph nodes or accept an optional argument /ID where ID is port // number for send and receive nodes. // // Following are possible statistics requests: // // /rxtxstats for protocol statistics gathered on all send and // receive or /rxtxstats/name for individual send/receiver node. // // /telemetry for all nodes names and their counters which include // received, send, processed, lost and dropped packets. Using // /telemetry/name returns information about individual node. // // If no string is specified, no HTTP server is spawned. StatsHTTPAddress *net.TCPAddr // Enables possibility of IP reassembly via chaining packets ChainedReassembly bool // Enables possibility of handling jumbo frames via chaining packets ChainedJumbo bool // Enables possibility of handling jumbo frames via making huge packets // Will require big amount of memory MemoryJumbo bool // Enables hardware assisted timestamps in packet mbufs. These // timestamps can be accessed with GetPacketTimestamp function. HWRXPacketsTimestamp bool // Disable setting custom handler for SIGINT in // SystemStartScheduler. When handler is enabled // SystemStartScheduler waits for SIGINT notification and calls // SystemStop after it. It is enabled by default. NoSetSIGINTHandler bool // Number of CPU cores to be occupied by Send routines. It is // necessary to set TXQueuesNumberPerPort to a reasonably big // number which can be divided by SendCPUCoresPerPort. SendCPUCoresPerPort int // Number of transmit queues to use on network card. By default it // is minimum of NIC supported TX queues number and 2. If this // value is specified and NIC doesn't support this number of TX // queues, initialization fails. TXQueuesNumberPerPort int // Controls scheduler interval in milliseconds. Default value is // 500. Lower values allow faster reaction to changing traffic but // increase scheduling overhead. SchedulerInterval uint }
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 SetFastGenerator ¶
func SetFastGenerator(f GenerateFunction, targetSpeed uint64, context UserContext) (OUT *Flow, tc chan uint64, 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 and channel that can be used for dynamically changing target speed 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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 SetReceiverOS ¶ added in v0.8.0
SetReceiverOS adds function receive from Linux interface to flow graph. Gets name of device, will return error if can't initialize socket. Creates RAW socket, returns new opened flow with received packets.
func SetReceiverXDP ¶ added in v0.9.0
SetReceiverXDP adds function receive from Linux AF_XDP to flow graph. Gets name of device and queue number, will return error if can't initialize socket. Creates AF_XDP socket, returns new opened flow with received packets.
func SetSenderReceiverKNI ¶ added in v0.7.3
SetSenderReceiverKNI adds function send/receive from KNI. Gets KNI device from which packets will be received and flow to send. Returns new opened flow with received packets If linuxCore parameter is true function will use core that was assigned to KNI device in Linux. So all send/receive/device can use one core
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, tc chan uint64, 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 and channel that can be used for dynamically changing target speed 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 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 HWRXPacketsTimestamp )
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 KNIParameters ¶ added in v0.7.3
type KNIParameters struct {
// contains filtered or unexported fields
}
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
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
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, *[vBurstSize]bool, UserContext)
VectorHandleFunction is a function type like HandleFunction for vector handling
type VectorSeparateFunction ¶
type VectorSeparateFunction func([]*packet.Packet, *[vBurstSize]bool, *[vBurstSize]bool, UserContext)
VectorSeparateFunction is a function type like SeparateFunction for vector separation
type VectorSplitFunction ¶
type VectorSplitFunction func([]*packet.Packet, *[vBurstSize]bool, *[vBurstSize]uint8, UserContext)
VectorSplitFunction is a function type like SplitFunction for vector splitting