Skip to content

Commit 048b92a

Browse files
authored
Merge pull request #571 from intel-go/develop
Release 0.8
2 parents d7badc5 + b2e018e commit 048b92a

File tree

118 files changed

+3750
-1684
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

118 files changed

+3750
-1684
lines changed

Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ RUN apt-get -q update && apt-get -q -y install \
2121
libmnl-dev \
2222
libibverbs-dev
2323

24-
RUN cd /opt && curl -L -s https://dl.google.com/go/go1.11.4.linux-amd64.tar.gz | tar zx
24+
RUN cd /opt && curl -L -s https://dl.google.com/go/go1.11.5.linux-amd64.tar.gz | tar zx
2525

2626
RUN mkdir -p ${NFF_GO}
2727
COPY . ${NFF_GO}

common/common.go

+6-323
Original file line numberDiff line numberDiff line change
@@ -7,332 +7,9 @@
77
package common
88

99
import (
10-
"fmt"
11-
"io"
12-
"log"
13-
"math"
14-
"os"
1510
"strconv"
16-
17-
"github.com/pkg/errors"
18-
)
19-
20-
// Max array length for type conversions
21-
const MaxLength = math.MaxInt32
22-
23-
// Length of addresses.
24-
const (
25-
EtherAddrLen = 6
26-
IPv4AddrLen = 4
27-
IPv6AddrLen = 16
28-
)
29-
30-
// Supported EtherType for L2
31-
const (
32-
IPV4Number = 0x0800
33-
ARPNumber = 0x0806
34-
VLANNumber = 0x8100
35-
MPLSNumber = 0x8847
36-
IPV6Number = 0x86dd
37-
38-
SwapIPV4Number = 0x0008
39-
SwapARPNumber = 0x0608
40-
SwapVLANNumber = 0x0081
41-
SwapMPLSNumber = 0x4788
42-
SwapIPV6Number = 0xdd86
43-
)
44-
45-
// Supported L4 types
46-
const (
47-
ICMPNumber = 0x01
48-
IPNumber = 0x04
49-
TCPNumber = 0x06
50-
UDPNumber = 0x11
51-
ICMPv6Number = 0x3a
52-
NoNextHeader = 0x3b
53-
)
54-
55-
// Supported ICMP Types
56-
const (
57-
ICMPTypeEchoRequest uint8 = 8
58-
ICMPTypeEchoResponse uint8 = 0
59-
ICMPv6TypeEchoRequest uint8 = 128
60-
ICMPv6TypeEchoResponse uint8 = 129
61-
ICMPv6NeighborSolicitation uint8 = 135
62-
ICMPv6NeighborAdvertisement uint8 = 136
63-
)
64-
65-
// These constants keep length of supported headers in bytes.
66-
//
67-
// IPv6Len - minimum length of IPv6 header in bytes. It can be higher and it
68-
// is not determined inside packet. Only default minimum size is used.
69-
//
70-
// IPv4MinLen and TCPMinLen are used only in packet generation functions.
71-
//
72-
// In parsing we take actual length of TCP header from DataOff field and length of
73-
// IPv4 take from Ihl field.
74-
const (
75-
EtherLen = 14
76-
VLANLen = 4
77-
MPLSLen = 4
78-
IPv4MinLen = 20
79-
IPv6Len = 40
80-
ICMPLen = 8
81-
TCPMinLen = 20
82-
UDPLen = 8
83-
ARPLen = 28
84-
GTPMinLen = 8
85-
)
86-
87-
const (
88-
TCPMinDataOffset = 0x50 // minimal tcp data offset
89-
IPv4VersionIhl = 0x45 // IPv4, IHL = 5 (min header len)
90-
IPv6VtcFlow = 0x60 // IPv6 version
91-
)
92-
93-
// LogType - type of logging, used in flow package
94-
type LogType uint8
95-
96-
const (
97-
// No - no output even after fatal errors
98-
No LogType = 1 << iota
99-
// Initialization - output during system initialization
100-
Initialization = 2
101-
// Debug - output during execution one time per time period (scheduler ticks)
102-
Debug = 4
103-
// Verbose - output during execution as soon as something happens. Can influence performance
104-
Verbose = 8
105-
)
106-
107-
// TCPFlags contains set TCP flags.
108-
type TCPFlags uint8
109-
110-
// Constants for valuues of TCP flags.
111-
const (
112-
TCPFlagFin = 0x01
113-
TCPFlagSyn = 0x02
114-
TCPFlagRst = 0x04
115-
TCPFlagPsh = 0x08
116-
TCPFlagAck = 0x10
117-
TCPFlagUrg = 0x20
118-
TCPFlagEce = 0x40
119-
TCPFlagCwr = 0x80
12011
)
12112

122-
// ErrorCode type for codes of errors
123-
type ErrorCode int
124-
125-
// constants with error codes
126-
const (
127-
_ ErrorCode = iota
128-
Fail
129-
ParseCPUListErr
130-
ReqTooManyPorts
131-
BadArgument
132-
UseNilFlowErr
133-
UseClosedFlowErr
134-
OpenedFlowAtTheEnd
135-
PortHasNoQueues
136-
NotAllQueuesUsed
137-
FailToInitPort
138-
ParseRuleJSONErr
139-
FileErr
140-
ParseRuleErr
141-
IncorrectArgInRules
142-
IncorrectRule
143-
AllocMbufErr
144-
PktMbufHeadRoomTooSmall
145-
NotEnoughCores
146-
CreatePortErr
147-
MaxCPUExceedErr
148-
PcapReadFail
149-
PcapWriteFail
150-
InvalidCPURangeErr
151-
SetAffinityErr
152-
MultipleReceivePort
153-
MultipleKNIPort
154-
WrongPort
155-
FailToInitDPDK
156-
FailToCreateKNI
157-
FailToReleaseKNI
158-
)
159-
160-
// NFError is error type returned by nff-go functions
161-
type NFError struct {
162-
Code ErrorCode
163-
Message string
164-
CauseErr error
165-
}
166-
167-
type causer interface {
168-
Cause() error
169-
}
170-
171-
// Error method to implement error interface
172-
func (err NFError) Error() string {
173-
return fmt.Sprintf("%s (%d)", err.Message, err.Code)
174-
}
175-
176-
// GetNFErrorCode returns value of cCode field if err is
177-
// NFError or pointer to it and -1 otherwise.
178-
func GetNFErrorCode(err error) ErrorCode {
179-
if nferr := GetNFError(err); nferr != nil {
180-
return nferr.Code
181-
}
182-
return -1
183-
}
184-
185-
func checkAndGetNFErrPointer(err error) *NFError {
186-
if err != nil {
187-
if nferr, ok := err.(NFError); ok {
188-
return &nferr
189-
} else if nferr, ok := err.(*NFError); ok {
190-
return nferr
191-
}
192-
}
193-
return nil
194-
}
195-
196-
// GetNFError if error is NFerror or pointer to int
197-
// returns pointer to NFError, otherwise returns nil.
198-
func GetNFError(err error) (nferr *NFError) {
199-
nferr = checkAndGetNFErrPointer(err)
200-
if nferr == nil {
201-
if cause, ok := err.(causer); ok {
202-
nferr = checkAndGetNFErrPointer(cause.Cause())
203-
}
204-
}
205-
return nferr
206-
}
207-
208-
// Cause returns the underlying cause of error, if
209-
// possible. If not, returns err itself.
210-
func (err *NFError) Cause() error {
211-
if err == nil {
212-
return nil
213-
}
214-
if err.CauseErr != nil {
215-
if cause, ok := err.CauseErr.(causer); ok {
216-
return cause.Cause()
217-
}
218-
return err.CauseErr
219-
}
220-
return err
221-
}
222-
223-
// Format makes formatted printing of errors,
224-
// the following verbs are supported:
225-
// %s, %v print the error. If the error has a
226-
// Cause it will be printed recursively
227-
// %+v - extended format. Each Frame of the error's
228-
// StackTrace will be printed in detail if possible.
229-
func (err *NFError) Format(s fmt.State, verb rune) {
230-
switch verb {
231-
case 'v':
232-
if s.Flag('+') {
233-
if cause := err.Cause(); cause != err && cause != nil {
234-
fmt.Fprintf(s, "%+v\n", err.Cause())
235-
io.WriteString(s, err.Message)
236-
return
237-
}
238-
}
239-
fallthrough
240-
case 's', 'q':
241-
io.WriteString(s, err.Error())
242-
}
243-
}
244-
245-
// WrapWithNFError returns an error annotating err with a stack trace
246-
// at the point WrapWithNFError is called, and the next our NFError.
247-
// If err is nil, Wrap returns nil.
248-
func WrapWithNFError(err error, message string, code ErrorCode) error {
249-
err = &NFError{
250-
CauseErr: err,
251-
Message: message,
252-
Code: code,
253-
}
254-
return errors.WithStack(err)
255-
}
256-
257-
var currentLogType = No | Initialization | Debug
258-
259-
// LogFatal internal, used in all packages
260-
func LogFatal(logType LogType, v ...interface{}) {
261-
if logType&currentLogType != 0 {
262-
t := fmt.Sprintln(v...)
263-
log.Fatal("ERROR: ", t)
264-
}
265-
os.Exit(1)
266-
}
267-
268-
// LogFatalf is a wrapper at LogFatal which makes formatting before logger.
269-
func LogFatalf(logType LogType, format string, v ...interface{}) {
270-
LogFatal(logType, fmt.Sprintf(format, v...))
271-
}
272-
273-
// LogError internal, used in all packages
274-
func LogError(logType LogType, v ...interface{}) string {
275-
if logType&currentLogType != 0 {
276-
t := fmt.Sprintln(v...)
277-
log.Print("ERROR: ", t)
278-
return t
279-
}
280-
return ""
281-
}
282-
283-
// LogWarning internal, used in all packages
284-
func LogWarning(logType LogType, v ...interface{}) {
285-
if logType&currentLogType != 0 {
286-
t := fmt.Sprintln(v...)
287-
log.Print("WARNING: ", t)
288-
}
289-
}
290-
291-
// LogDebug internal, used in all packages
292-
func LogDebug(logType LogType, v ...interface{}) {
293-
if logType&currentLogType != 0 {
294-
t := fmt.Sprintln(v...)
295-
log.Print("DEBUG: ", t)
296-
}
297-
}
298-
299-
// LogDrop internal, used in all packages
300-
func LogDrop(logType LogType, v ...interface{}) {
301-
if logType&currentLogType != 0 {
302-
t := fmt.Sprintln(v...)
303-
log.Print("DROP: ", t)
304-
}
305-
}
306-
307-
// LogTitle internal, used in all packages
308-
func LogTitle(logType LogType, v ...interface{}) {
309-
if logType&currentLogType != 0 {
310-
log.Print(v...)
311-
}
312-
}
313-
314-
// SetLogType internal, used in flow package
315-
func SetLogType(logType LogType) {
316-
log.SetFlags(0)
317-
currentLogType = logType
318-
}
319-
320-
// GetDPDKLogLevel internal, used in flow package
321-
func GetDPDKLogLevel() string {
322-
switch currentLogType {
323-
case No:
324-
return "0"
325-
case No | Initialization:
326-
return "7"
327-
case No | Initialization | Debug:
328-
return "8"
329-
case No | Initialization | Debug | Verbose:
330-
return "8"
331-
default:
332-
return "8"
333-
}
334-
}
335-
33613
// GetDefaultCPUs returns default core list {0, 1, ..., NumCPU}
33714
func GetDefaultCPUs(cpuNumber int) []int {
33815
cpus := make([]int, cpuNumber, cpuNumber)
@@ -420,3 +97,9 @@ func dropInvalidCPUs(nums []int, maxcpu int) []int {
42097
}
42198
return nums[:i]
42299
}
100+
101+
// RXTXStats describes statistics for sender or receiver flow function
102+
// node.
103+
type RXTXStats struct {
104+
PacketsProcessed, PacketsDropped, BytesProcessed uint64
105+
}

0 commit comments

Comments
 (0)