Skip to content

Commit

Permalink
Merge pull request #653 from intel-go/develop
Browse files Browse the repository at this point in the history
New release 0.9
  • Loading branch information
gshimansky committed Sep 20, 2019
2 parents 27d1256 + 4d10b8e commit b6e11fb
Show file tree
Hide file tree
Showing 43 changed files with 1,141 additions and 168 deletions.
3 changes: 3 additions & 0 deletions .gitignore
@@ -1,3 +1,6 @@
# emacs
*~
doc
GPATH
GTAGS
GRTAGS
6 changes: 3 additions & 3 deletions .travis.yml
Expand Up @@ -12,9 +12,9 @@ services:

before_script:
- sudo apt-get install -y linux-headers-$(uname -r)
- docker pull ubuntu:cosmic
- docker build --build-arg https_proxy=${https_proxy} -t test-cosmic .
- docker run -it -d --privileged -v /usr/src:/usr/src -v /lib/modules:/lib/modules -v /sys/devices/system/node:/sys/devices/system/node --name test-nff-go test-cosmic /bin/bash
- docker pull ubuntu:disco
- docker build --build-arg https_proxy=${https_proxy} -t test-disco .
- docker run -it -d --privileged -v /usr/src:/usr/src -v /lib/modules:/lib/modules -v /sys/devices/system/node:/sys/devices/system/node --name test-nff-go test-disco /bin/bash

script:
- docker exec -i test-nff-go go mod download
Expand Down
6 changes: 5 additions & 1 deletion Dockerfile
Expand Up @@ -20,7 +20,11 @@ RUN apt-get -q update && apt-get -q -y install \
libmnl-dev \
libibverbs-dev

RUN cd /opt && curl -L -s https://dl.google.com/go/go1.12.5.linux-amd64.tar.gz | tar zx
RUN cd /opt && curl -L -s https://dl.google.com/go/go1.12.9.linux-amd64.tar.gz | tar zx
RUN git clone -b v0.0.4 https://github.com/libbpf/libbpf
RUN make -C libbpf/src all install
RUN echo "/usr/lib64" > /etc/ld.so.conf.d/usrlib64.conf
RUN ldconfig

RUN mkdir -p ${NFF_GO}
COPY . ${NFF_GO}
Expand Down
23 changes: 22 additions & 1 deletion README.md
Expand Up @@ -35,7 +35,7 @@ func main() {
flow.CheckFatal(flow.SystemInit(&config))

// Get filtering rules from access control file.
L3Rules, err := packet.GetL3ACLFromORIG("Firewall.conf")
L3Rules, err := packet.GetL3ACLFromTextTable("Firewall.conf")
flow.CheckFatal(err)

// Receive packets from zero port. Receive queue will be added automatically.
Expand Down Expand Up @@ -118,6 +118,27 @@ Use Go version 1.11.4 or higher. To check the version of Go, do:

go version
### AF_XDP support

AF_XDP support is enabled by default, and it requires you to install
`libbpf` package. At the time of writing Ubuntu doesn't have this
library among its packages, so it is necessary to build `libbpf` from
sources or disable AF_XDP socket support.

To disable it set variable `NFF_GO_NO_BPF_SUPPORT` to some unempty
value. When NFF_GO is built with it, AF_XDP support is disaled and
using it results in errors.

If you want to build `libbpf` from sources you can do it in two
different ways.
* If you are using stock Linux kernel from distribution, [download
`libbpf` from GitHub](https://github.com/libbpf/libbpf), then
execute `cd src; make; sudo make install`. Add /usr/lib64 to your
ldconfig path.
* If you build Linux kernel from sources, you can build `libbpf` from
Linux source tree using commands `cd tools/lib/bpf; make; sudo make
install install_headers`. Add /usr/local/lib64 to your ldconfig path.

## Building NFF-GO

When Go compiler runs for the first time it downloads all dependent
Expand Down
2 changes: 1 addition & 1 deletion common/Makefile
Expand Up @@ -7,7 +7,7 @@ include $(PATH_TO_MK)/include.mk

.PHONY: testing
testing: check-pktgen
go test
go test -tags "${GO_BUILD_TAGS}"

.PHONY: coverage
coverage:
Expand Down
12 changes: 9 additions & 3 deletions devices/misc.go
Expand Up @@ -40,12 +40,18 @@ func GetDeviceID(nicName string) (string, error) {
return "", err
}
// raw should be like /sys/devices/pci0002:00/0000:00:08.0/virtio2/net/ens8
// or /sys/devices/pci0000:00/0000:00:01.0/0000:03:00.2/net/ens4f2
raws := strings.Split(raw, "/")
if len(raws) < 5 {
if len(raws) < 6 {
return "", fmt.Errorf("path not correct")
}
return raws[4], nil

if IsPciID.Match([]byte(raws[5])) {
return raws[5], nil
} else if IsPciID.Match([]byte(raws[4])) {
return raws[4], nil
} else {
return "", fmt.Errorf("can't get device ID from path: %s", raw)
}
}

// IsModuleLoaded checks if the kernel has already loaded the driver or not.
Expand Down
2 changes: 1 addition & 1 deletion dpdk/dpdk
Submodule dpdk updated from 07efd6 to b81660
2 changes: 1 addition & 1 deletion dpdk/pktgen-dpdk
Submodule pktgen-dpdk updated from ae5a88 to 7a4e0b
8 changes: 2 additions & 6 deletions examples/Makefile
Expand Up @@ -8,15 +8,11 @@ EXECUTABLES = dump clonablePcapDumper kni copy errorHandling timer \
createPacket sendFixedPktsNumber gtpu pingReplay \
netlink gopacketParserExample devbind generate \
OSforwarding jumbo decrementTTL
SUBDIRS = tutorial antiddos demo fileReadWrite firewall forwarding ipsec lb nffPktgen

SUBDIRS = tutorial antiddos demo fileReadWrite firewall forwarding ipsec lb

.PHONY: dpi nffPktgen
.PHONY: dpi
dpi:
$(MAKE) -C dpi

nffPktgen:
$(MAKE) -C nffPktgen

include $(PATH_TO_MK)/intermediate.mk
include $(PATH_TO_MK)/leaf.mk
18 changes: 13 additions & 5 deletions examples/OSforwarding.go
Expand Up @@ -10,15 +10,23 @@ import (
)

func main() {
// If you use af-xdp mode you need to configure queues:
// e.g. ethtool -N my_device flow-type tcp4 dst-port 4242 action 16
afXDP := flag.Bool("af-xdp", false, "use af-xdp. need to use ethtool to setup queues")
inport := flag.String("in", "", "device for receiver")
inQueue := flag.Int("in-queue", 16, "queue for receiver")
outport := flag.String("out", "", "device for sender")
flag.Parse()

flow.CheckFatal(flow.SystemInit(nil))

inputFlow, err := flow.SetReceiverOS(*inport)
flow.CheckFatal(err)
flow.CheckFatal(flow.SetSenderOS(inputFlow, *outport))

if *afXDP {
inputFlow, err := flow.SetReceiverXDP(*inport, *inQueue)
flow.CheckFatal(err)
flow.CheckFatal(flow.SetSenderXDP(inputFlow, *outport))
} else {
inputFlow, err := flow.SetReceiverOS(*inport)
flow.CheckFatal(err)
flow.CheckFatal(flow.SetSenderOS(inputFlow, *outport))
}
flow.CheckFatal(flow.SystemStart())
}
6 changes: 3 additions & 3 deletions examples/errorHandling.go
Expand Up @@ -49,11 +49,11 @@ func main() {
}

// Get splitting rules from access control file.
l3Rules, err = packet.GetL3ACLFromORIG("wrong.conf")
fmt.Printf("error from GetL3ACLFromORIG was: %+v\n", err)
l3Rules, err = packet.GetL3ACLFromTextTable("wrong.conf")
fmt.Printf("error from GetL3ACLFromTextTable was: %+v\n", err)
if common.GetNFErrorCode(err) == common.FileErr {
fmt.Printf("changing file name\n")
l3Rules, err = packet.GetL3ACLFromORIG("Forwarding.conf")
l3Rules, err = packet.GetL3ACLFromTextTable("Forwarding.conf")
CheckFatal(err)
}

Expand Down
2 changes: 1 addition & 1 deletion examples/firewall/firewall.go
Expand Up @@ -29,7 +29,7 @@ func main() {
flow.CheckFatal(flow.SystemInit(&config))

// Get filtering rules from access control file.
l3Rules, err = packet.GetL3ACLFromORIG("firewall.conf")
l3Rules, err = packet.GetL3ACLFromTextTable("firewall.conf")
flow.CheckFatal(err)

// Receive packets from zero port. Receive queue will be added automatically.
Expand Down
2 changes: 1 addition & 1 deletion examples/forwarding/forwarding.go
Expand Up @@ -37,7 +37,7 @@ func main() {
flow.CheckFatal(flow.SystemInit(&config))

// Get splitting rules from access control file.
l3Rules, err = packet.GetL3ACLFromORIG("forwarding.conf")
l3Rules, err = packet.GetL3ACLFromTextTable("forwarding.conf")
flow.CheckFatal(err)

// Receive packets from zero port. Receive queue will be added automatically.
Expand Down
11 changes: 11 additions & 0 deletions examples/nffPktgen/gtp-u/Dockerfile
@@ -0,0 +1,11 @@
# Copyright 2019 Intel Corporation.
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.

ARG USER_NAME
FROM ${USER_NAME}/nff-go-base

LABEL RUN docker run -it --privileged -v /sys/bus/pci/drivers:/sys/bus/pci/drivers -v /sys/kernel/mm/hugepages:/sys/kernel/mm/hugepages -v /sys/devices/system/node:/sys/devices/system/node -v /dev:/dev --name NAME -e NAME=NAME -e IMAGE=IMAGE IMAGE

WORKDIR /workdir
COPY trafficgen .
1 change: 1 addition & 0 deletions examples/nffPktgen/gtp-u/trafficgen.go
Expand Up @@ -192,6 +192,7 @@ func initPortFlows(port *IpPort, myIPs generator.AddrRange, addEncapsulation boo
flow.CheckFatal(flow.SetSender(outFlow, uint16(port.Index)))
// Input flow
inFlow, err := flow.SetReceiver(port.Index)
flow.CheckFatal(err)
flow.CheckFatal(flow.SetHandlerDrop(inFlow, receiveHandler, hc))
flow.CheckFatal(flow.SetStopper(inFlow))
}
Expand Down
2 changes: 1 addition & 1 deletion examples/nffPktgen/testing/Dockerfile
Expand Up @@ -9,5 +9,5 @@ LABEL RUN docker run -it --privileged -v /sys/bus/pci/drivers:/sys/bus/pci/drive

WORKDIR /workdir
COPY sendGetBack .
COPY perfTesting .
COPY perfTest .
COPY dump .

0 comments on commit b6e11fb

Please sign in to comment.