Skip to content
This repository was archived by the owner on Sep 3, 2020. It is now read-only.

Commit 5e342e2

Browse files
author
Eric Gourlaouen
committed
Added new packet forwarder
1 parent 51a6258 commit 5e342e2

Some content is hidden

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

59 files changed

+5530
-42
lines changed

.github/ISSUE_TEMPLATE.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
This is a **{bug report/feature request/question/...}** for **{the packet forwarder}**.
2+
3+
- Explain what you want to do
4+
- Explain either:
5+
* which build you used, or
6+
* if you build the packet forwarder yourself, which steps you took to build it
7+
- Explain what steps you took to run it
8+
- Explain what went wrong or what is missing
9+
10+
## Environment
11+
12+
- `<packet-forwarder> version` returns: `Commit={...}`
13+
- My gateway:
14+
- Manufacturer: `{...}`
15+
- Type of concentrator: `{...}`
16+
- Type of interface with the concentrator: `{...}`
17+
- Is connected to: `{The TTN community network|My private TTN network}`

.gitignore

Lines changed: 8 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,8 @@
1-
# Compiled Object files, Static and Dynamic libs (Shared Objects)
2-
*.o
3-
*.a
4-
*.so
5-
6-
# Folders
7-
_obj
8-
_test
9-
10-
# Architecture specific extensions/prefixes
11-
*.[568vq]
12-
[568vq].out
13-
14-
*.cgo1.go
15-
*.cgo2.c
16-
_cgo_defun.c
17-
_cgo_gotypes.go
18-
_cgo_export.*
19-
20-
_testmain.go
21-
22-
*.exe
23-
*.test
24-
*.prof
25-
26-
/release
27-
/vendor/*/
28-
/.cover
29-
30-
# Generated databases
31-
*.db
32-
33-
# Generate coverage profile
34-
coverage.out
1+
*/cover.html
2+
*/cover.out
3+
lora_gateway*/
4+
release/
5+
vendor/*/
6+
7+
# macOS
8+
.DS_Store

.gitlab-ci.yml

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
stages:
2+
- build
3+
- sign
4+
- package
5+
6+
cache:
7+
key: "$CI_PROJECT_PATH"
8+
paths:
9+
- .govendor
10+
- go
11+
12+
before_script:
13+
# Creating release path
14+
- mkdir release
15+
# Go build environment variables
16+
- export GOROOT=$PWD/go
17+
- export GOPATH=$PWD/gopath
18+
- export PATH=$PATH:$GOROOT/bin:$GOPATH/bin
19+
# Creating govendor cache folder
20+
- mkdir -p $PWD/.govendor
21+
- rm -rf $GOPATH
22+
- mkdir -p $GOPATH/.cache && ln -s $PWD/.govendor $GOPATH/.cache/govendor
23+
# Downloading go if not installed yet
24+
- apt-get update -y && apt-get install make git tar -y
25+
- "([[ ! $(go version) =~ \"go1\\.8\" ]] && apt-get install wget -y && wget https://storage.googleapis.com/golang/go1.8.1.linux-amd64.tar.gz && tar -C $PWD -xvzf go1.8.1.linux-amd64.tar.gz) || echo \"Expected Go toolset available in cache\""
26+
# Copying the packet-forwarder in the gopath
27+
- mkdir -p $GOPATH/src/github.com/TheThingsNetwork
28+
- ln -s $PWD $GOPATH/src/github.com/TheThingsNetwork/packet_forwarder
29+
# Build environment variables
30+
- export CI_BUILD_DATE=$(date -u +%Y-%m-%dT%H:%M:%SZ)
31+
- echo "date $CI_BUILD_DATE" >> release/info
32+
- echo "commit $CI_BUILD_DATE" >> release/info
33+
# Downloading dependencies
34+
- pushd $GOPATH/src/github.com/TheThingsNetwork/packet_forwarder
35+
- make dev-deps
36+
- make deps
37+
- popd
38+
39+
multitech-conduit-pktfwd:
40+
stage: build
41+
image: registry.gitlab.com/thethingsindustries/packet-forwarder/multitech-toolchain
42+
script:
43+
# Remove the toolchain's CFLAGS
44+
- "sed 's/.*CFLAGS.*//g' /opt/mlinux/3.2.0/environment-setup-arm926ejste-mlinux-linux-gnueabi -i.bak"
45+
# Enable mLinux toolchain
46+
- sdk_enable_file=$(ls /opt/mlinux/*/*setup*)
47+
- source $sdk_enable_file
48+
# Go to packet forwarder file
49+
- pushd $GOPATH/src/github.com/TheThingsNetwork/packet_forwarder
50+
- GOOS=linux GOARM=5 GOARCH=arm make build
51+
- pushd release
52+
- binary_file=$(ls packet*)
53+
- ./../scripts/multitech/create-multitech-package.sh $binary_file
54+
- popd
55+
- popd
56+
artifacts:
57+
paths:
58+
- release/
59+
60+
kerlink-iot-station-pktfwd:
61+
stage: build
62+
image: registry.gitlab.com/thethingsindustries/packet-forwarder/klk-toolchain
63+
script:
64+
- pushd $GOPATH/src/github.com/TheThingsNetwork/packet_forwarder
65+
- ./scripts/kerlink/build-kerlink.sh /opt
66+
- cp scripts/kerlink/create-kerlink-package.sh release
67+
- popd
68+
artifacts:
69+
paths:
70+
- release/
71+
72+
sign:
73+
before_script: []
74+
only:
75+
- develop@thethingsnetwork/packet_forwarder
76+
- master@thethingsnetwork/packet_forwarder
77+
stage: sign
78+
image: golang:latest
79+
script:
80+
- pushd release
81+
- shasum -a 256 $(ls) > checksums
82+
- gpg --no-tty --batch --import /gpg/signing.ci.gpg-key
83+
- gpg --no-tty --batch --no-use-agent --passphrase $GPG_PASSPHRASE --detach-sign checksums
84+
- popd
85+
artifacts:
86+
paths:
87+
- release/checksums
88+
- release/checksums.sig
89+
90+
azure-binaries:
91+
before_script: []
92+
only:
93+
- develop@thethingsnetwork/packet_forwarder
94+
- master@thethingsnetwork/packet_forwarder
95+
stage: package
96+
image: registry.gitlab.com/thethingsindustries/upload
97+
script:
98+
- cd release
99+
- export STORAGE_CONTAINER=release STORAGE_KEY=$AZURE_STORAGE_KEY ZIP=true TGZ=true PREFIX=$CI_BUILD_REF_NAME/
100+
- upload *

.make/dummyhal/main.make

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
hal.build:
2+
3+
hal.deps:
4+
5+
hal.clean:
6+
7+
hal.clean-deps:

.make/general.make

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Set shell
2+
SHELL = bash
3+
4+
## count the input
5+
count = wc -w

.make/git.make

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
.PHONY: hooks
2+
3+
GIT_COMMIT = `git rev-parse HEAD 2>/dev/null`
4+
GIT_BRANCH = `git rev-parse --abbrev-ref HEAD 2>/dev/null`
5+
GIT_TAG = $(shell git describe --abbrev=0 --tags)
6+
BUILD_DATE = `date -u +%Y-%m-%dT%H:%M%SZ`
7+
8+
# Get all files that are currently staged, except for deleted files
9+
STAGED_FILES = git diff --staged --name-only --diff-filter=d
10+
11+
12+
# Install git hooks
13+
hooks:
14+
@$(log) installing hooks
15+
@touch .git/hooks/pre-commit
16+
@chmod u+x .git/hooks/pre-commit
17+
@echo "make quality-staged" >> .git/hooks/pre-commit

.make/go/build.make

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# Infer GOOS and GOARCH
2+
GOOS ?= $(or $(word 1,$(subst -, ,${TARGET_PLATFORM})), $(shell echo "`go env GOOS`"))
3+
GOARCH ?= $(or $(word 2,$(subst -, ,${TARGET_PLATFORM})), $(shell echo "`go env GOARCH`"))
4+
5+
ifeq ($(GOOS),darwin)
6+
CGO_LDFLAGS := -lmpsse
7+
else
8+
ifeq ($(CFG_SPI),ftdi)
9+
CGO_LDFLAGS := -lrt -lmpsse
10+
else
11+
CGO_LDFLAGS := -lrt
12+
endif
13+
ifneq ($(SDKTARGETSYSROOT),)
14+
CGO_CFLAGS := -I$(SDKTARGETSYSROOT)/usr/include/libftdi1 -I$(SDKTARGETSYSROOT)/usr/include
15+
endif
16+
endif
17+
18+
19+
# build
20+
go.build: $(RELEASE_DIR)/$(NAME)-$(GOOS)-$(GOARCH)-$(PLATFORM)
21+
22+
# default main file
23+
MAIN ?= ./main.go
24+
25+
# Time margin in milliseconds
26+
ifeq ($(PLATFORM),multitech)
27+
SENDING_TIME_MARGIN = 100
28+
else ifeq ($(PLATFORM),kerlink)
29+
SENDING_TIME_MARGIN = 60
30+
endif
31+
32+
LD_FLAGS = -ldflags "-w -X main.version=${PKTFWD_VERSION} -X main.gitCommit=${GIT_COMMIT} -X main.buildDate=${BUILD_DATE} -X github.com/TheThingsNetwork/packet_forwarder/pktfwd.platform=${PLATFORM} -X github.com/TheThingsNetwork/packet_forwarder/cmd.downlinksMargin=${SENDING_TIME_MARGIN}"
33+
34+
# Build the executable
35+
$(RELEASE_DIR)/$(NAME)-%: $(shell $(GO_FILES)) vendor/vendor.json
36+
@$(log) "building" [$(GO_ENV) CC="$(CC)" GOOS=$(GOOS) GOARCH=$(GOARCH) GOARM=$(GOARM) CGO_CFLAGS=$(CGO_CFLAGS) CGO_LDFLAGS=$(CGO_LDFLAGS) $(GO_ENV) $(GO) build -tags '$(HAL_CHOICE)' $(GO_FLAGS) $(LD_FLAGS) $(MAIN) ...]
37+
@$(GO_ENV) CC="$(CC)" GOOS=$(GOOS) GOARCH=$(GOARCH) GOARM=$(GOARM) CGO_CFLAGS="$(CGO_CFLAGS)" CGO_LDFLAGS="$(CGO_LDFLAGS)" $(GO) build -tags '$(HAL_CHOICE)' -o "$(RELEASE_DIR)/$(NAME)-$(GOOS)-$(GOARCH)-$(PLATFORM)-$(CFG_SPI)" -v $(GO_FLAGS) $(LD_FLAGS) $(MAIN)
38+
39+
# Build the executable in dev mode (much faster)
40+
go.dev: GO_FLAGS =
41+
go.dev: GO_ENV =
42+
go.dev: BUILD_TYPE = dev
43+
go.dev: $(RELEASE_DIR)/$(NAME)-$(GOOS)-$(GOARCH)-$(PLATFORM)
44+
45+
## link the executable to a simple name
46+
$(RELEASE_DIR)/$(NAME): $(RELEASE_DIR)/$(NAME)-$(GOOS)-$(GOARCH)-$(PLATFORM)
47+
@$(log) "linking binary" [ln -sfr $(RELEASE_DIR)/$(NAME)-$(GOOS)-$(GOARCH)-$(PLATFORM) $(RELEASE_DIR)/$(NAME)]
48+
@ln -sfr $(RELEASE_DIR)/$(NAME)-$(GOOS)-$(GOARCH)-$(PLATFORM) $(RELEASE_DIR)/$(NAME)
49+
50+
go.link: $(RELEASE_DIR)/$(NAME)
51+
52+
go.link-dev: GO_FLAGS =
53+
go.link-dev: GO_ENV =
54+
go.link-dev: BUILD_TYPE = dev
55+
go.link-dev: go.link
56+
57+
## initialize govendor
58+
vendor/vendor.json:
59+
@$(log) initializing govendor
60+
@govendor init
61+
62+
# vim: ft=make

.make/go/main.make

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
# Programs
2+
GO = go
3+
GOLINT = golint
4+
5+
# License keys
6+
# To add a license key to the binary, specify the variable name using
7+
# LICENSE_KEY_VAR, and add a LICENSE_KEY_FILE variable to the build.
8+
LICENSE_KEY_VAR ?= "main.licenseKey"
9+
LICENSE_KEY_STR ?= $(shell cat "$(LICENSE_KEY_FILE)" 2>/dev/null | head -n -1 | tail -n +2 | tr -d '\n')
10+
11+
# Flags
12+
## go
13+
GO_FLAGS = -a
14+
ifeq ($(HAL_CHOICE),dummy)
15+
GO_ENV = CGO_ENABLED=0
16+
else
17+
GO_ENV = CGO_ENABLED=1
18+
endif
19+
20+
## golint
21+
GOLINT_FLAGS = -set_exit_status
22+
23+
## test
24+
GO_TEST_FLAGS = -cover
25+
26+
## coverage
27+
GO_COVER_FILE = coverage.out
28+
GO_COVER_DIR = .coverage
29+
30+
# Filters
31+
32+
## select only go files
33+
only_go = grep '.go$$'
34+
35+
## select/remove vendored files
36+
no_vendor = grep -v 'vendor'
37+
only_vendor = grep 'vendor'
38+
39+
## select/remove mock files
40+
no_mock = grep -v '_mock.go'
41+
only_mock = grep '_mock.go'
42+
43+
## select/remove protobuf generated files
44+
no_pb = grep -Ev '.pb.go$$|.pb.gw.go$$'
45+
only_pb = grep -E '.pb.go$$|.pb.gw.go$$'
46+
47+
## select/remove test files
48+
no_test = grep -v '_test.go$$'
49+
only_test = grep '_test.go$$'
50+
51+
## filter files to packages
52+
to_packages = sed 's:/[^/]*$$::' | sort | uniq
53+
54+
## make packages local (prefix with ./)
55+
to_local = sed 's:^:\./:'
56+
57+
58+
# Selectors
59+
60+
## find all go files
61+
GO_FILES = find . -name '*.go' | grep -v '.git'
62+
63+
## local go packages
64+
GO_PACKAGES = $(GO_FILES) | $(no_vendor) | $(to_packages)
65+
66+
## external go packages (in vendor)
67+
EXTERNAL_PACKAGES = $(GO_FILES) | $(only_vendor) | $(to_packages)
68+
69+
## staged local packages
70+
STAGED_PACKAGES = $(STAGED_FILES) | $(only_go) | $(no_vendor) | $(to_packages) | $(to_local)
71+
72+
## packages for testing
73+
TEST_PACKAGES = $(GO_FILES) | $(no_vendor) | $(only_test) | $(to_packages)
74+
75+
# Rules
76+
77+
## get tools required for development
78+
go.dev-deps:
79+
@$(log) "fetching go tools"
80+
@command -v govendor > /dev/null || ($(log) Installing govendor && $(GO) get -v -u github.com/kardianos/govendor)
81+
@command -v golint > /dev/null || ($(log) Installing golint && $(GO) get -v -u github.com/golang/lint/golint)
82+
83+
## install dependencies
84+
go.deps:
85+
@$(log) "fetching go dependencies"
86+
@govendor sync -v
87+
88+
## install packages for faster rebuilds
89+
go.install:
90+
@$(log) "installing go packages"
91+
@$(EXTERNAL_PACKAGES) | xargs $(GO) install -v
92+
93+
## clean build files
94+
go.clean:
95+
@$(log) "cleaning release dir" [rm -rf $(RELEASE_DIR)]
96+
@rm -rf $(RELEASE_DIR)
97+
98+
## clean dependencies
99+
go.clean-deps:
100+
@$(log) "cleaning go dependencies" [rm -rf vendor/*/]
101+
@rm -rf vendor/*/
102+
103+
## run tests
104+
go.test:
105+
@$(log) testing `$(TEST_PACKAGES) | $(count)` go packages
106+
@$(GO) test $(GO_TEST_FLAGS) `$(TEST_PACKAGES)`
107+
108+
## clean cover files
109+
go.cover.clean:
110+
rm -rf $(GO_COVER_DIR) $(GO_COVER_FILE)
111+
112+
## package coverage
113+
$(GO_COVER_DIR)/%.out: GO_TEST_FLAGS=-cover -coverprofile="$(GO_COVER_FILE)"
114+
$(GO_COVER_DIR)/%.out: %
115+
@$(log) testing "$<"
116+
@mkdir -p `dirname "$(GO_COVER_DIR)/$<"`
117+
@$(GO) test -cover -coverprofile="$@" "./$<"
118+
119+
## project coverage
120+
$(GO_COVER_FILE): go.cover.clean $(patsubst ./%,./$(GO_COVER_DIR)/%.out,$(shell $(TEST_PACKAGES)))
121+
@echo "mode: set" > $(GO_COVER_FILE)
122+
@cat $(patsubst ./%,./$(GO_COVER_DIR)/%.out,$(shell $(TEST_PACKAGES))) | grep -vE "mode: set" | sort >> $(GO_COVER_FILE)
123+
124+
# vim: ft=make

0 commit comments

Comments
 (0)