Skip to content

Commit 8ab691c

Browse files
authored
Merge pull request #625 from intel-go/develop
New release 0.8.1
2 parents 048b92a + 66385c6 commit 8ab691c

Some content is hidden

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

69 files changed

+1169
-224
lines changed

Dockerfile

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM ubuntu:cosmic
1+
FROM ubuntu:disco
22

33
ARG MAKEFLAGS=-j2
44

@@ -11,7 +11,6 @@ RUN apt-get -q update && apt-get -q -y install \
1111
git \
1212
curl \
1313
wget \
14-
golang-${GO_VERSION} \
1514
libpcap-dev \
1615
libelf-dev \
1716
hugepages \
@@ -21,7 +20,7 @@ RUN apt-get -q update && apt-get -q -y install \
2120
libmnl-dev \
2221
libibverbs-dev
2322

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

2625
RUN mkdir -p ${NFF_GO}
2726
COPY . ${NFF_GO}

Makefile

+1-7
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44

55
PATH_TO_MK = mk
66
SUBDIRS = nff-go-base dpdk test examples
7-
DOC_TARGETS = flow packet
8-
CI_TESTING_TARGETS = packet low common
7+
CI_TESTING_TARGETS = packet internal/low common
98
TESTING_TARGETS = $(CI_TESTING_TARGETS) test/stability
109

1110
all: $(SUBDIRS)
@@ -33,9 +32,4 @@ citesting: $(CI_TESTING_TARGETS)
3332
$(TESTING_TARGETS):
3433
$(MAKE) -C $@ testing
3534

36-
.PHONY: doc
37-
doc: $(DOC_TARGETS)
38-
mkdir doc
39-
$(foreach package,$(DOC_TARGETS),godoc -analysis=type -analysis=pointer -html github.com/intel-go/nff-go/$(package) > doc/$(package).html;)
40-
4135
include $(PATH_TO_MK)/intermediate.mk

README.md

+14-17
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
[![Go Report Card](https://goreportcard.com/badge/github.com/intel-go/yanff)](https://goreportcard.com/report/github.com/intel-go/yanff)
2-
[![GoDoc](https://godoc.org/github.com/intel-go/yanff?status.svg)](https://godoc.org/github.com/intel-go/yanff)
1+
[![Go Report Card](https://goreportcard.com/badge/github.com/intel-go/nff-go)](https://goreportcard.com/report/github.com/intel-go/nff-go)
2+
[![GoDoc](https://godoc.org/github.com/intel-go/nff-go?status.svg)](https://godoc.org/github.com/intel-go/nff-go)
33
[![Dev chat at https://gitter.im/intel-yanff/Lobby](https://img.shields.io/badge/gitter-developer_chat-46bc99.svg)](https://gitter.im/intel-yanff/Lobby?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
44
[![Build Status](https://travis-ci.org/intel-go/nff-go.svg?branch=develop)](https://travis-ci.org/intel-go/nff-go)
55
# Network Function Framework for Go (former YANFF)
@@ -84,9 +84,15 @@ Requirements in the DPDK Getting Started Guide for
8484
Linux](http://dpdk.org/doc/guides/linux_gsg/sys_reqs.html) for more
8585
information.
8686

87-
Since NFF-Go is build with Mellanox cards support out of the box you
87+
By default NFF-Go is build with Mellanox cards support out of the box you
8888
need to install additional dependencies required for MLX network
89-
drivers. On Ubuntu they are called `libmnl-dev` and `libibverbs-dev`.
89+
drivers. On Ubuntu they are called `libmnl-dev` and
90+
`libibverbs-dev`. For more details see MLX drivers respective pages
91+
for [MLX4](https://doc.dpdk.org/guides/nics/mlx4.html) and
92+
[MLX5](https://doc.dpdk.org/guides/nics/mlx5.html). If these
93+
dependencies cannot be satisfied, and Mellanox drivers are not needed,
94+
you can set variable `NFF_GO_NO_MLX_DRIVERS` to some unempty value to
95+
disable MLX drivers compilation.
9096

9197
Additional dependencies are required for pktgen, especially if you are
9298
running RedHat or CentOS Linux distributions. See [this
@@ -133,18 +139,9 @@ when it is run for the first time, but may be quite slow.
133139

134140
## Documentation
135141

136-
Use:
137-
138-
make doc
139-
140-
to generate full documentation. Alternatively, you can do:
141-
142-
godoc -http=:6060
143-
144-
and browse the following URLs:
145-
146-
* http://localhost:6060/pkg/nff-go/flow/
147-
* http://localhost:6060/pkg/nff-go/packet/
142+
Online API documentation is available on [godoc.org
143+
site](https://godoc.org/github.com/intel-go/nff-go). API usage is
144+
explained on our [Wiki pages](https://github.com/intel-go/nff-go/wiki).
148145

149146
## Tests
150147

@@ -187,7 +184,7 @@ deployed images listed in NFF_GO_HOSTS, use the **make cleanall** command.
187184
## Contributing
188185

189186
If you want to contribute to NFF-Go, check our [Contributing
190-
guide](https://github.com/intel-go/yanff/blob/master/CONTRIBUTING.md). We also
187+
guide](https://github.com/intel-go/nff-go/blob/master/CONTRIBUTING.md). We also
191188
recommend checking the bugs with 'help-wanted' or 'easyfix' in our list of open issues; these bugs
192189
can be solved without an extensive knowledge of NFF-Go. We would love to help
193190
you start contributing.

devices/consts.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ var (
7575

7676
var (
7777
pathSysClassNetDeviceDriver stringBuilder = PathSysClassNet + "/%s/device/driver"
78-
pathSysClassNetDevice stringBuilder = PathSysClassNet + "/%s/device"
78+
pathSysClassNetDevice stringBuilder = PathSysClassNet + "/%s"
7979
)
8080

8181
var (
@@ -107,6 +107,7 @@ func init() {
107107

108108
rVmbusDriver = regexp.MustCompile("/sys/bus/vmbus/drivers/(\\S+)/")
109109

110-
IsPciID = regexp.MustCompile("^\\d{4}:\\d{2}:\\d{2}.\\d$")
110+
// domains are numbered from 0 to ffff), bus (0 to ff), slot (0 to 1f) and function (0 to 7)
111+
IsPciID = regexp.MustCompile("^[[:xdigit:]]{4}:[[:xdigit:]]{2}:[0-1][[:xdigit:]].[0-7]$")
111112
IsUUID = regexp.MustCompile("^[[:xdigit:]]{8}-[[[:xdigit:]]{4}-[[:xdigit:]]{4}-[[:xdigit:]]{4}-[[:xdigit:]]{12}$")
112113
}

devices/misc.go

+22-4
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,18 @@ func FindDefaultDpdkDriver(nicName string) string {
3434

3535
// GetDeviceID returns the device ID of given NIC name.
3636
func GetDeviceID(nicName string) (string, error) {
37-
// DEV_ID=$(basename $(readlink /sys/class/net/<nicName>/device))
38-
return readlinkBaseCmd(pathSysClassNetDevice.With(nicName))
37+
// DEV_ID=$(basename $(readlink /sys/class/net/<nicName>))
38+
raw, err := readlinkCmd(pathSysClassNetDevice.With(nicName))
39+
if err != nil {
40+
return "", err
41+
}
42+
// raw should be like /sys/devices/pci0002:00/0000:00:08.0/virtio2/net/ens8
43+
raws := strings.Split(raw, "/")
44+
if len(raws) < 5 {
45+
return "", fmt.Errorf("path not correct")
46+
}
47+
return raws[4], nil
48+
3949
}
4050

4151
// IsModuleLoaded checks if the kernel has already loaded the driver or not.
@@ -69,12 +79,20 @@ func writeToTargetWithData(sysfs string, flag int, mode os.FileMode, data string
6979
return nil
7080
}
7181

72-
func readlinkBaseCmd(path string) (string, error) {
73-
output, err := cmdOutputWithTimeout(defaultTimeoutLimitation, "readlink", path)
82+
func readlinkCmd(path string) (string, error) {
83+
output, err := cmdOutputWithTimeout(defaultTimeoutLimitation, "readlink", "-f", path)
7484
if err != nil {
7585
return "", fmt.Errorf("Cmd Execute readlink failed: %s", err.Error())
7686
}
7787
outputStr := strings.Trim(string(output), "\n")
88+
return outputStr, nil
89+
}
90+
91+
func readlinkBaseCmd(path string) (string, error) {
92+
outputStr, err := readlinkCmd(path)
93+
if err != nil {
94+
return "", fmt.Errorf("Cmd Execute readlink failed: %s", err.Error())
95+
}
7896
result := filepath.Base(outputStr)
7997
return result, nil
8098
}

dpdk/Makefile

+6-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,12 @@ all: pktgen
2323

2424
$(DPDK_DIR)/$(DPDK_INSTALL_DIR):
2525
$(MAKE) -C $(DPDK_DIR) config T=$(RTE_TARGET)
26-
sed -ri 's,(MLX._PMD=)n,\1y,' $(DPDK_DIR)/build/.config
26+
@if [ -z '${NFF_GO_NO_MLX_DRIVERS}' ]; then \
27+
echo BUILDING DPDK WITH MLX DRIVERS; \
28+
sed -ri 's,(MLX._PMD=)n,\1y,' $(DPDK_DIR)/build/.config; \
29+
else \
30+
echo BUILDING DPDK WITHOUT MLX DRIVERS; \
31+
fi
2732
$(MAKE) -C $(DPDK_DIR)
2833
$(MAKE) -C $(DPDK_DIR) install DESTDIR=$(DPDK_INSTALL_DIR)
2934

dpdk/dpdk

Submodule dpdk updated from 8b937ba to 07efd6d

dpdk/pktgen-dpdk

Submodule pktgen-dpdk updated from 4199555 to ae5a88b

examples/.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,5 @@ netlink
1313
devbind
1414
OSforwarding
1515
generate
16+
jumbo
17+
decrementTTL

examples/Dockerfile

+2
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,5 @@ COPY timer .
2121
COPY netlink .
2222
COPY generate .
2323
COPY OSforwarding .
24+
COPY jumbo .
25+
COPY decrementTTL .

examples/Makefile

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ IMAGENAME = nff-go-examples
77
EXECUTABLES = dump clonablePcapDumper kni copy errorHandling timer \
88
createPacket sendFixedPktsNumber gtpu pingReplay \
99
netlink gopacketParserExample devbind generate \
10-
OSforwarding
10+
OSforwarding jumbo decrementTTL
11+
1112
SUBDIRS = tutorial antiddos demo fileReadWrite firewall forwarding ipsec lb
1213

1314
.PHONY: dpi nffPktgen

examples/decrementTTL.go

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// Copyright 2017 Intel Corporation.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
package main
6+
7+
import (
8+
"flag"
9+
10+
"github.com/intel-go/nff-go/flow"
11+
"github.com/intel-go/nff-go/packet"
12+
)
13+
14+
// Main function for constructing packet processing graph.
15+
func main() {
16+
inPort := flag.Uint("inPort", 0, "port for receiver")
17+
outPort := flag.Uint("outPort", 1, "port for sender")
18+
flag.Parse()
19+
20+
flow.SystemInit(nil)
21+
inputFlow, _ := flow.SetReceiver(uint16(*inPort))
22+
flow.SetHandlerDrop(inputFlow, decrementTTL, nil)
23+
flow.SetSender(inputFlow, uint16(*outPort))
24+
flow.SystemStart()
25+
}
26+
27+
func decrementTTL(current *packet.Packet, c flow.UserContext) bool {
28+
current.ParseL3() // must parse before header can be read
29+
header := current.GetIPv4()
30+
if header == nil { // not IPv4
31+
return false
32+
}
33+
34+
header.TimeToLive--
35+
if header.TimeToLive == 0 { // TTL exceeded, drop
36+
return false
37+
} else {
38+
return true
39+
}
40+
}

examples/dpi/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@
55
PATH_TO_MK = ../../mk
66
SUBDIRS = main pattern
77

8-
export GO_COMPILE_FLAGS += -tags hyperscan_v4
8+
export GO_BUILD_TAGS += hyperscan_v4
99

1010
include $(PATH_TO_MK)/intermediate.mk

examples/dpi/main/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ EXECUTABLES = dpi
99
dpi: ../pattern gohs
1010

1111
gohs:
12-
go get $(GO_COMPILE_FLAGS) -v github.com/flier/gohs/hyperscan
12+
go get -tags hyperscan_v4 -v github.com/flier/gohs/hyperscan
1313

1414
COMMON_FILES = handlers.go
1515

examples/dpi/pattern/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ PATH_TO_MK = ../../../mk
66
IMAGENAME = dpi-pattern
77

88
pattern:
9-
go install $(GO_COMPILE_FLAGS)
9+
go install -tags hyperscan_v4

examples/jumbo.go

+100
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
// Copyright 2019 Intel Corporation.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
package main
6+
7+
import (
8+
"flag"
9+
"fmt"
10+
"github.com/intel-go/nff-go/flow"
11+
"github.com/intel-go/nff-go/packet"
12+
"time"
13+
)
14+
15+
// You need to enable memory jumbo for maxPacketSegment more than 2014.
16+
// Explanation: internal packet buffers are 2048 bytes, first packet will have
17+
// ethernet and ipv4 headers = 14 + 2 = 34 bytes.
18+
// Buffer will overflows if maxPacketSegment > 2048 - 34 = 2014 bytes
19+
20+
// Note: usage of 1484 < maxPacketSegment < 2014 without memory jumbo can work
21+
// on some NICs, but is treated as underfined behaviour
22+
// Explanation: in this situation packet will be fit in internal buffers
23+
// however packet will be more than 1518 bytes - Ethernet max non-jumbo frame
24+
const maxPacketSegment = 1484
25+
26+
// You need to enale chained jumbo for requiredPacketLength > maxPacketSegment
27+
// Explanation: if required length is more than segment length packet will consist of
28+
// several chained segments. You should enable chained jumbo to correctly handle them
29+
30+
// Note: usage of maxPacketSegment > 2014 and also requiredPacketLength > maxPacketSegment
31+
// is forbidden. If you decicde to chain packets you shouldn't chain non-standart packets
32+
// Explanation: in this situation you will need to enable both
33+
// memory and chained jumbo and this is forbidden
34+
const requiredPacketLength = 7000
35+
36+
func main() {
37+
chained := flag.Bool("chained", false, "enable chained jumbo")
38+
memory := flag.Bool("memory", false, "enalbe memory jumbo")
39+
flag.Parse()
40+
41+
// Initialize NFF-GO library at 10 available cores
42+
config := flow.Config{
43+
ChainedJumbo: *chained,
44+
MemoryJumbo: *memory,
45+
}
46+
47+
flow.CheckFatal(flow.SystemInit(&config))
48+
49+
generated := flow.SetGenerator(generate, nil)
50+
flow.SetHandler(generated, dump, nil)
51+
flow.SetSender(generated, 0)
52+
53+
received, _ := flow.SetReceiver(0)
54+
flow.SetHandler(received, dump, nil)
55+
flow.SetStopper(received)
56+
flow.SystemStart()
57+
}
58+
59+
func generate(pkt *packet.Packet, context flow.UserContext) {
60+
remain := requiredPacketLength
61+
c := 0
62+
diff, remain := m(maxPacketSegment, remain)
63+
if packet.InitEmptyIPv4Packet(pkt, diff) == false {
64+
fmt.Printf("maxPacketSegment %d is more than 2014 bytes without enabling memory jumbo\n", maxPacketSegment)
65+
time.Sleep(5 * time.Second)
66+
return
67+
}
68+
pkt.Ether.DAddr = [6]uint8{0x00, 0x11, 0x22, 0x33, 0x44, 0x55}
69+
for i := 0; i < maxPacketSegment; i++ {
70+
(*(*[maxPacketSegment]byte)(pkt.Data))[i] = byte(c % 10)
71+
c++
72+
}
73+
for remain != 0 {
74+
diff, remain = m(maxPacketSegment, remain)
75+
pkt = packet.InitNextPacket(diff, pkt)
76+
for i := 0; i < maxPacketSegment; i++ {
77+
(*(*[maxPacketSegment]byte)(pkt.Data))[i] = byte(c % 10)
78+
c++
79+
}
80+
}
81+
time.Sleep(1 * time.Second)
82+
}
83+
84+
func m(max int, remain int) (uint, int) {
85+
if remain > max {
86+
return uint(max), remain - max
87+
} else {
88+
return uint(remain), 0
89+
}
90+
}
91+
92+
func dump(currentPacket *packet.Packet, context flow.UserContext) {
93+
fmt.Println("NEW PACKET")
94+
fmt.Printf("BLOCK\n%x\nEND_BLOCK\n", currentPacket.GetRawPacketBytes())
95+
for currentPacket.Next != nil {
96+
currentPacket = currentPacket.Next
97+
fmt.Printf("BLOCK\n%x\nEND_BLOCK\n", currentPacket.GetRawPacketBytes())
98+
}
99+
fmt.Println("END PACKET")
100+
}

examples/lb/balancer.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func balancer(pkt *packet.Packet, ctx flow.UserContext) bool {
5151
workerMAC, found := LBConfig.TunnelPort.neighCache.LookupMACForIPv4(workerIP)
5252
if !found {
5353
fmt.Println("Not found MAC address for IP", workerIP.String())
54-
LBConfig.TunnelPort.neighCache.SendARPRequestForIPv4(workerIP, 0)
54+
LBConfig.TunnelPort.neighCache.SendARPRequestForIPv4(workerIP, LBConfig.TunnelPort.Subnet.IPv4.Addr, 0)
5555
return false
5656
}
5757

examples/lb/config.go

+7-1
Original file line numberDiff line numberDiff line change
@@ -64,5 +64,11 @@ func InitFlows() {
6464

6565
func (port *IpPort) initPort() {
6666
port.macAddress = flow.GetPortMACAddress(port.Index)
67-
port.neighCache = packet.NewNeighbourTable(port.Index, port.macAddress, port.Subnet.IPv4.Addr, port.Subnet.IPv6.Addr)
67+
port.neighCache = packet.NewNeighbourTable(port.Index, port.macAddress,
68+
func(ipv4 types.IPv4Address) bool {
69+
return ipv4 == port.Subnet.IPv4.Addr
70+
},
71+
func(ipv6 types.IPv6Address) bool {
72+
return ipv6 == port.Subnet.IPv6.Addr
73+
})
6874
}

examples/nffPktgen/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44

55
PATH_TO_MK = ../../mk
66
IMAGENAME = nff-pktgen
7-
SUBDIRS = testing
7+
SUBDIRS = testing gtp-u
88

99
include $(PATH_TO_MK)/intermediate.mk

0 commit comments

Comments
 (0)