Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Migrate service to V2 #52

Merged
merged 17 commits into from
Jan 18, 2022
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,6 @@ venv
internal/llrp/testdata/**/*.json
internal/llrp/testdata/**/*.bytes
!internal/llrp/testdata/roAccessReports/*-00?*

#do not track vscode
.vscode/*
74 changes: 64 additions & 10 deletions Attribution.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ https://github.com/cenkalti/backoff/blob/master/LICENSE
edsrzf/mmap-go (BSD-3) https://github.com/edsrzf/mmap-go
https://github.com/edsrzf/mmap-go/blob/master/LICENSE

edgexfoundry/go-mod-core-contracts (Apache 2.0) https://github.com/edgexfoundry/go-mod-core-contracts
https://github.com/edgexfoundry/go-mod-core-contracts/blob/master/LICENSE
edgexfoundry/go-mod-core-contracts/v2 (Apache 2.0) https://github.com/edgexfoundry/go-mod-core-contracts/v2
https://github.com/edgexfoundry/go-mod-core-contracts/v2/blob/master/LICENSE

edgexfoundry/go-mod-registry (Apache 2.0) https://github.com/edgexfoundry/go-mod-registry
edgexfoundry/go-mod-registry/v2 (Apache 2.0) https://github.com/edgexfoundry/go-mod-registry/v2
https://github.com/edgexfoundry/go-mod-registry/blob/master/LICENSE

edgexfoundry/device-sdk-go (Apache 2.0) https://github.com/edgexfoundry/device-sdk-go
https://github.com/edgexfoundry/device-sdk-go/blob/master/LICENSE
edgexfoundry/device-sdk-go/v2 (Apache 2.0) https://github.com/edgexfoundry/device-sdk-go/v2
https://github.com/edgexfoundry/device-sdk-go/v2/blob/master/LICENSE

gorilla/mux 1.6.2 (BSD-3) https://github.com/gorilla/mux
https://github.com/gorilla/mux/blob/master/LICENSE
Expand Down Expand Up @@ -123,14 +123,14 @@ https://github.com/OneOfOne/xxhash/blob/master/LICENCE
hashicorp/consul/api (Mozilla Public License 2.0) https://github.com/hashicorp/consul/api
https://github.com/hashicorp/consul/blob/master/LICENSE

edgexfoundry/go-mod-bootstrap (Apache 2.0) https://github.com/edgexfoundry/go-mod-bootstrap
https://github.com/edgexfoundry/go-mod-bootstrap/blob/master/LICENSE
edgexfoundry/go-mod-bootstrap/v2 (Apache 2.0) https://github.com/edgexfoundry/go-mod-bootstrap/v2
https://github.com/edgexfoundry/go-mod-bootstrap/v2/blob/master/LICENSE

edgexfoundry/go-mod-secrets (Apache 2.0) https://github.com/edgexfoundry/go-mod-secrets
edgexfoundry/go-mod-secret/v2 (Apache 2.0) https://github.com/edgexfoundry/go-mod-secrets/v2
https://github.com/edgexfoundry/go-mod-secrets/blob/master/LICENSE

edgexfoundry/go-mod-configuration (Apache 2.0) https://github.com/edgexfoundry/go-mod-configuration
https://github.com/edgexfoundry/go-mod-configuration/blob/master/LICENSE
edgexfoundry/go-mod-configuration/v2 (Apache 2.0) https://github.com/edgexfoundry/go-mod-configuration/v2
https://github.com/edgexfoundry/go-mod-configuration/v2/blob/master/LICENSE

fxamacker/cbor (MIT) https://github.com/fxamacker/cbor/v2
https://github.com/fxamacker/cbor/blob/master/LICENSE
Expand All @@ -155,3 +155,57 @@ https://github.com/go-playground/validator/blob/master/LICENSE

leodido/go-urn (MIT) https://github.com/leodido/go-urn
https://github.com/leodido/go-urn/blob/master/LICENSE

hashicorp/go-multierror (Mozilla Public License 2.0) https://github.com/hashicorp/go-multierror
https://github.com/hashicorp/go-multierror/blob/master/LICENSE

davecgh/go-spew (ISC) https://github.com/davecgh/go-spew
https://github.com/davecgh/go-spew/blob/master/LICENSE

eclipse/paho.mqtt.golang (Eclipse Distribution License) https://github.com/eclipse/paho.mqtt.golang
https://github.com/eclipse/paho.mqtt.golang/blob/master/LICENSE

edgexfoundry/go-mod-messaging/v2 (Apache 2.0) https://github.com/edgexfoundry/go-mod-messaging/v2
https://github.com/edgexfoundry/go-mod-messaging/blob/master/LICENSE

github.com/fatih/color (MIT) https://github.com/fatih/color
https://github.com/fatih/color/blob/master/LICENSE.md

go-redis/redis (BSD-2) https://github.com/go-redis/redis/v7
https://github.com/go-redis/redis/blob/master/LICENSE

gorilla/websocket (BSD-2) https://github.com/gorilla/websocket
https://github.com/gorilla/websocket/blob/master/LICENSE

hashicorp/errwrap (Mozilla Public License 2.0) https://github.com/hashicorp/errwrap
https://github.com/hashicorp/errwrap/blob/master/LICENSE

github.com/hashicorp/go-hclog (MIT) https://github.com/hashicorp/go-hclog
https://github.com/hashicorp/go-hclog/blob/master/LICENSE

github.com/mattn/go-colorable (MIT) https://github.com/mattn/go-colorable
https://github.com/mattn/go-colorable/blob/master/LICENSE

github.com/mattn/go-isatty (MIT) https://github.com/mattn/go-isatty
https://github.com/mattn/go-isatty/blob/master/LICENSE

pebbe/zmq4 (BSD-2) https://github.com/pebbe/zmq4
https://github.com/pebbe/zmq4/blob/master/LICENSE.txt

pmezard/go-difflib (Unspecified) https://github.com/pmezard/go-difflib
https://github.com/pmezard/go-difflib/blob/master/LICENSE

stretchr/testify (MIT) https://github.com/stretchr/testify
https://github.com/stretchr/testify/blob/master/LICENSE

golang.org/x/crypto (Unspecified) https://github.com/golang/crypto
https://github.com/golang/crypto/blob/master/LICENSE

golang.org/x/net (Unspecified) https://github.com/golang/net
https://github.com/golang/net/blob/master/LICENSE

golang.org/x/text (Unspecified) https://github.com/golang/text
https://github.com/golang/text/blob/master/LICENSE

gopkg.in/yaml.v3 (MIT) https://github.com/go-yaml/yaml/
https://github.com/go-yaml/yaml/blob/v3/LICENSE
7 changes: 5 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ ARG BASE=golang:1.16-alpine3.14
FROM ${BASE} AS builder

ARG MAKE='make build'
ARG ALPINE_PKG_BASE="make git"
ARG ALPINE_PKG_BASE="make git gcc libc-dev zeromq-dev"
ARG ALPINE_PKG_EXTRA=""

RUN sed -e 's/dl-cdn[.]alpinelinux.org/nl.alpinelinux.org/g' -i~ /etc/apk/repositories
Expand All @@ -37,11 +37,14 @@ FROM alpine:3.14
LABEL license='SPDX-License-Identifier: Apache-2.0' \
copyright='Copyright (c) 2021: Intel'

RUN sed -e 's/dl-cdn[.]alpinelinux.org/nl.alpinelinux.org/g' -i~ /etc/apk/repositories
RUN apk add --update --no-cache zeromq dumb-init
lenny-goodell marked this conversation as resolved.
Show resolved Hide resolved

COPY --from=builder /go/src/github.com/edgexfoundry/device-rfid-llrp-go/LICENSE /
marcpfuller marked this conversation as resolved.
Show resolved Hide resolved
COPY --from=builder /go/src/github.com/edgexfoundry/device-rfid-llrp-go/Attribution.txt /
COPY --from=builder /go/src/github.com/edgexfoundry/device-rfid-llrp-go/cmd /

EXPOSE 49989
EXPOSE 59989

ENTRYPOINT ["/device-rfid-llrp-go"]
marcpfuller marked this conversation as resolved.
Show resolved Hide resolved
CMD ["-cp=consul.http://edgex-core-consul:8500", "--confdir=/res", "--registry"]
11 changes: 4 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.PHONY: build test clean prepare update docker

GO = CGO_ENABLED=0 GO111MODULE=on go
GO=CGO_ENABLED=1 GO111MODULE=on go

MICROSERVICES=cmd/device-rfid-llrp-go
marcpfuller marked this conversation as resolved.
Show resolved Hide resolved
marcpfuller marked this conversation as resolved.
Show resolved Hide resolved

Expand All @@ -14,11 +14,11 @@ VERSION=$(shell cat ./VERSION 2>/dev/null || echo 0.0.0)
GIT_SHA=$(shell git rev-parse HEAD)
GOFLAGS=-ldflags "-X github.com/edgexfoundry/device-rfid-llrp-go.Version=$(VERSION)"
marcpfuller marked this conversation as resolved.
Show resolved Hide resolved

build: $(MICROSERVICES)

tidy:
go mod tidy

build: $(MICROSERVICES)

cmd/device-rfid-llrp-go:
marcpfuller marked this conversation as resolved.
Show resolved Hide resolved
$(GO) build $(GOFLAGS) -o $@ ./cmd

Expand All @@ -32,9 +32,6 @@ test:
clean:
rm -f $(MICROSERVICES)

update:
$(GO) mod download

docker: $(DOCKERS)
marcpfuller marked this conversation as resolved.
Show resolved Hide resolved

docker_device_rfid_llrp_go:
marcpfuller marked this conversation as resolved.
Show resolved Hide resolved
Expand All @@ -47,4 +44,4 @@ docker_device_rfid_llrp_go:
.

vendor:
$(GO) mod vendor
go mod vendor
70 changes: 37 additions & 33 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,24 @@ make build
```bash
make docker
```
**Run EdgeX Hanoi**
- [Docker](https://github.com/edgexfoundry/edgex-compose/tree/hanoi)
**Run EdgeX Jakarta**

- [Docker](https://github.com/edgexfoundry/edgex-compose/tree/jakarta)
- [Snap](https://snapcraft.io/edgexfoundry)

**Run device-rfid-llrp**
- [Run via Snap](#snap-development-and-testing)

- Docker
- Add `device-rfid-llrp` to your `docker-compose.yml` file
- Use [compose-builder](https://github.com/edgexfoundry/edgex-compose/tree/jakarta/compose-builder)
- For non secure mode `make gen ds-llrp no-secty`
- For secure mode `make gen ds-llrp`
- `docker-compose -p edgex up -d`

- Native

```shell
cd cmd && ./device-rfid-llrp-go -cp=consul.http://localhost:8500
cd cmd && EDGEX_SECURITY_SECRET_STORE=false ./device-rfid-llrp-go -cp -r
```

**Configure subnet information**
Expand All @@ -56,53 +63,47 @@ make docker
>_**Note 2:** The system will trigger a discovery 10 seconds after any change is made to the subnet
> or discover port config, so this step is often not required_
```bash
curl -X POST http://localhost:49989/api/v1/discovery
curl -X POST http://localhost:59989/api/v2/discovery
```

At this point the `device-rfid-llrp` service should have discovered your LLRP devices on the network and
registered them with EdgeX.
At this point the `device-rfid-llrp` service should have discovered your LLRP devices on the network and registered them with EdgeX.

For more detailed info, see [Device Discovery](#Device-Discovery) and
[EdgeX Device Naming](#EdgeX-Device-Naming).
For more detailed info, see [Device Discovery](#Device-Discovery) and [EdgeX Device Naming](#EdgeX-Device-Naming).

## Device Discovery
>_**Note:** Device discovery is currently only compatible with IPv4 networks.
If using an IPv6-only network, you will need to [manually add your devices to EdgeX](#manually-adding-a-device)._

This service has the functionality to probe the local network
in an effort to discover devices that support LLRP.
This service has the functionality to probe the local network in an effort to discover devices that support LLRP.

This discovery also happens at a regular interval and can be configured via
[EdgeX Consul][consul_discovery]
This discovery also happens at a regular interval and can be configured via [EdgeX Consul][consul_discovery]
for existing installations, and [configuration.toml][config_toml] for default values.

The discovery configuration can be modified via the `[Driver]` section of the [configuration.toml][config_toml] file.
The additional discovery configuration can be modified via the `[AppCustom]` section of the [configuration.toml][config_toml] file.

>_**Note:** Please read the [Notes on configuration.toml](#Notes-on-configurationtoml) for things to be
aware of when modifying this file._

[consul_discovery]: http://localhost:8500/ui/dc1/kv/edgex/devices/1.0/edgex-device-rfid-llrp/Device/Discovery/
```toml
[Driver]
# NOTE: Items in the Driver section MUST be in quotes, even for numbers due to EdgeX limitation

```toml
[AppCustom]
# List of IPv4 subnets to perform LLRP discovery process on, in CIDR format (X.X.X.X/Y)
# separated by commas ex: "192.168.1.0/24,10.0.0.0/24"
DiscoverySubnets = ""

# Maximum simultaneous network probes
ProbeAsyncLimit = "5000"
ProbeAsyncLimit = 4000

# Maximum amount of seconds to wait for each IP probe before timing out.
# This will also be the minimum time the discovery process can take.
ProbeTimeoutSeconds = "2"
ProbeTimeoutSeconds = 2

# Port to scan for LLRP devices on
ScanPort = "5084"

# Maximum amount of seconds the discovery process is allowed to run before it will be cancelled.
# It is especially important to have this configured in the case of larger subnets such as /16 and /8
MaxDiscoverDurationSeconds = "300"
MaxDiscoverDurationSeconds = 300
```

The `DiscoverySubnets` config option defaults to blank, and needs to be provided before a discovery can occur.
Expand All @@ -119,8 +120,8 @@ field in Consul for you.

Discovery can be manually triggered via REST:
```bash
# POST http://<hostname>:<device-rfid-llrp-go port>/api/v1/discovery
curl -X POST http://localhost:49989/api/v1/discovery
# POST http://<hostname>:<device-rfid-llrp-go port>/api/v2/discovery
curl -X POST http://localhost:59989/api/v2/discovery
```

Every IP address in each of the subnets provided in `DiscoverySubnets` are probed at the specified `ScanPort` (default `5084`).
Expand Down Expand Up @@ -179,7 +180,7 @@ aware of when modifying this file._
```
[[DeviceList]]
Name = "Speedway"
Profile = "Device.LLRP.Profile"
Profile = "Device-LLRP-Profile"
Description = "LLRP RFID Reader"
Labels = ["LLRP", "RFID"]
[DeviceList.Protocols]
Expand All @@ -188,11 +189,12 @@ aware of when modifying this file._
port = "5084"
```

[add_device]: https://app.swaggerhub.com/apis-docs/EdgeXFoundry1/core-metadata/1.2.0#/default/post_v1_device
[add_device]: https://app.swaggerhub.com/apis-docs/EdgeXFoundry1/core-metadata/2.1.0#/default/post_device
[config_toml]: cmd/res/configuration.toml
[provision_watcher]: cmd/res/provision_watchers
[impinj_watcher]: cmd/res/provision_watchers/impinj.provision.watcher.json
[generic_watcher]: cmd/res/provision_watchers/llrp.provision.watcher.json
[consul_discovery]: http://localhost:8500/ui/dc1/kv/edgex/devices/2.0/device-rfid-llrp/Device/Discovery/

## Device Profiles, Custom LLRP Messages, and Service Limitations
For some use cases, you may want or need to supply your own `deviceProfile`,
Expand Down Expand Up @@ -245,7 +247,7 @@ The following `LLRP` operations are _not_ supported at this time:
There's really no reasonable general-purpose way to support it
except through code, so if you need it, consider forking this repo
and adding the interaction by using our [LLRP Library][llrp_library].

A `ProvisionWatcher` is used during the device discovery process to match discovered readers.
It also determines the device profile to be used when adding the new device. The two pre-defined
watchers are a [generic one][generic_watcher], and one for [Impinj][impinj_watcher]. Any new provision watchers
Expand Down Expand Up @@ -287,6 +289,7 @@ and how it satisfies the read request:
- `AccessSpec` sends `GET_ACCESSSPECS` (Message Type 44)
and returns `GET_ACCESSSPECS_RESPONSE` (Message Type 44).


You can configure `deviceCommands` in your device profile
to read more than one resource at a time,
in which case the device service attempts each of the commands requests in the order
Expand Down Expand Up @@ -324,8 +327,8 @@ as a base64-encoded byte array, which it uses as the `payload` of the `CustomMes
You can see an example [device profile][custom_profile]
that defines a `deviceResource` to enable Impinj's custom extensions.

[basic_profile]: cmd/res/llrp.device.profile.yaml
[custom_profile]: cmd/res/llrp.impinj.profile.yaml
[basic_profile]: cmd/res/profiles/llrp.device.profile.yaml
[custom_profile]: cmd/res/profiles/llrp.impinj.profile.yaml
[llrp_library]: internal/llrp/hacking_with_llrp.md
[llrp_diagram]: internal/llrp/LLRPMsgStructure.pdf

Expand Down Expand Up @@ -374,7 +377,7 @@ so don't rely on them for much more than happy-path testing.
to the first reader that EdgeX knows about,
waits a bit, disables/deletes it from the reader,
then displays any collected tags.

They assume everything is running and expect you have a these on your path:
`jq`, `curl`, `sed`, `xargs`, `base64`, and `od`.
By default, they all try to connect to `localhost` on the typical EdgeX ports.
Expand Down Expand Up @@ -428,6 +431,7 @@ The full options it will respond to:
but [is only needed in special circumstances](#updating-recorded-test-data)
and should not be used unless you understand the consequences.


Note that if you're using the Goland IDE,
you can put these options in a test config's `program arguments`,
though the `short` and `verbose` options need the `test.` prefix.
Expand Down Expand Up @@ -570,7 +574,7 @@ and verify there are no errors in the logs: `sudo snap logs edgex-device-llrp`.
Consul UI can also be used to verify if the service has started without any errors `http://localhost:8500`

Follow [First Run](#first-run) section to auto-configure subnet & trigger device discovery.
As part of testing, registered devices can be checked via EdgeX Core-Metadata API - `http://localhost:48081/api/v1/device`
As part of testing, registered devices can be checked via EdgeX Core-Metadata API - `http://localhost:59881/api/v2/device/service/name/device-rfid-llrp`

#### Here are other helpful commands:
- List installed Snap packages: `snap list`
Expand All @@ -584,11 +588,11 @@ As part of testing, registered devices can be checked via EdgeX Core-Metadata AP
- Modifying the `configuration.toml` file will require you to rebuild the docker image
and re-deploy using the new image
- Any modifications made to the `configuration.toml` file will be ignored if this is not
the first time you have deployed the service and EdgeX Consul is enabled.
the first time you have deployed the service and EdgeX Consul is enabled.
- Consul will always overwrite any modifications to the toml.
- To get around this behavior, you may delete the whole configuration group for this
service within [EdgeX Consul][consul_devices].

![](images/delete_consul.png)

[consul_devices]: http://localhost:8500/ui/dc1/kv/edgex/devices/1.0/
[consul_devices]: http://localhost:8500/ui/dc1/kv/edgex/devices/2.0/
2 changes: 1 addition & 1 deletion bin/auto-configure.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ err() {
}

CONSUL_URL=${CONSUL_URL:-http://localhost:8500}
url="${CONSUL_URL}/v1/kv/edgex/devices/1.0/edgex-device-rfid-llrp/Driver/DiscoverySubnets"
url="${CONSUL_URL}/v1/kv/edgex/devices/2.0/device-rfid-llrp/AppCustom/DiscoverySubnets"

### Dependencies Check
# Note: trailing ${red} is to colorize red all potential error output from the following commands
Expand Down
2 changes: 1 addition & 1 deletion cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ package main
import (
"github.com/edgexfoundry/device-rfid-llrp-go"
"github.com/edgexfoundry/device-rfid-llrp-go/internal/driver"
"github.com/edgexfoundry/device-sdk-go/pkg/startup"
"github.com/edgexfoundry/device-sdk-go/v2/pkg/startup"
)

func main() {
Expand Down
Loading