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

supoprt interface options for vxlan, such as df, local_ip and dst_port. #106

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
2 changes: 1 addition & 1 deletion .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
export PATH=$PATH:$GOPATH/bin
mkdir $GOPATH/src $GOPATH/pkg $GOPATH/bin
go install honnef.co/go/tools/cmd/staticcheck@latest
NEW=$GOPATH/src/github.com/digitalocean/go-openvswitch
NEW=$GOPATH/src/github.com/danieldin95/go-openvswitch
mkdir -p $NEW
cp -r ./* $NEW
cd $NEW
Expand Down
6 changes: 3 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ The `go-openvswitch` project makes use of the [GitHub Flow](https://guides.githu
for contributions.

If you'd like to contribute to the project, please
[open an issue](https://github.com/digitalocean/go-openvswitch/issues/new) or find an
[existing issue](https://github.com/digitalocean/go-openvswitch/issues) that you'd like
[open an issue](https://github.com/danieldin95/go-openvswitch/issues/new) or find an
[existing issue](https://github.com/danieldin95/go-openvswitch/issues) that you'd like
to take on. This ensures that efforts are not duplicated, and that a new feature
aligns with the focus of the rest of the repository.

Expand All @@ -21,7 +21,7 @@ code meets the following criteria:

In addition, if this is your first time contributing to the `go-openvswitch` project,
add your name and email address to the
[AUTHORS](https://github.com/digitalocean/go-openvswitch/blob/master/AUTHORS) file
[AUTHORS](https://github.com/danieldin95/go-openvswitch/blob/master/AUTHORS) file
under the "Contributors" section using the format:
`First Last <[email protected]>`.

Expand Down
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
go-openvswitch [![Build Status](https://travis-ci.org/digitalocean/go-openvswitch.svg?branch=master)](https://travis-ci.org/digitalocean/go-openvswitch) [![GoDoc](https://godoc.org/github.com/digitalocean/go-openvswitch?status.svg)](https://godoc.org/github.com/digitalocean/go-openvswitch) [![Go Report Card](https://goreportcard.com/badge/github.com/digitalocean/go-openvswitch)](https://goreportcard.com/report/github.com/digitalocean/go-openvswitch)
go-openvswitch
[![Build Status](https://travis-ci.org/danieldin95/go-openvswitch.svg?branch=master)](https://travis-ci.org/danieldin95/go-openvswitch)
[![GoDoc](https://godoc.org/github.com/danieldin95/go-openvswitch?status.svg)](https://godoc.org/github.com/danieldin95/go-openvswitch)
[![Go Report Card](https://goreportcard.com/badge/github.com/danieldin95/go-openvswitch)](https://goreportcard.com/report/github.com/danieldin95/go-openvswitch)
==============

Go packages which enable interacting with Open vSwitch and related tools. Apache 2.0 Licensed.
Expand All @@ -7,4 +10,4 @@ Go packages which enable interacting with Open vSwitch and related tools. Apache
- `ovsdb`: Package ovsdb implements an OVSDB client, as described in RFC 7047.
- `ovsnl`: Package ovsnl enables interaction with the Linux Open vSwitch generic netlink interface.

See each package's README for additional information.
See each package's README for additional information.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module github.com/digitalocean/go-openvswitch
module github.com/danieldin95/go-openvswitch

go 1.16

Expand Down
4 changes: 2 additions & 2 deletions ovs/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -502,8 +502,8 @@ type resubmitPortAction struct {

// MarshalText implements Action.
func (a *resubmitPortAction) MarshalText() ([]byte, error) {
// Largest valid port ID is 0xfffffeff per openflow spec.
if a.port < 0 || a.port > 0xfffffeff {
// Largest valid port ID is 0xfffeff per openflow spec.
if a.port < 0 || a.port > 0xfffeff {
return nil, errResubmitPortInvalid
}

Expand Down
8 changes: 4 additions & 4 deletions ovs/action_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -401,12 +401,12 @@ func TestActionResubmitPort(t *testing.T) {
action: "resubmit:1",
},
{
desc: "max port (0xfffffeff)",
port: 0xfffffeff,
action: "resubmit:4294967039",
desc: "max port (0xfffeff)",
port: 0xfffeff,
action: "resubmit:16776959",
},
{
desc: "max port+1 (0xfffffeff)",
desc: "max port+1 (0xfffeff)",
port: 0xffffff00,
err: errResubmitPortInvalid,
},
Expand Down
2 changes: 1 addition & 1 deletion ovs/datapath.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ type CLI interface {
// supported by the ovs-dpctl command
type DataPathService struct {
// We define here a CLI interface making easier to mock ovs-dpctl command
// as in github.com/digitalocean/go-openvswitch/ovs/datapath_test.go
// as in github.com/danieldin95/go-openvswitch/ovs/datapath_test.go
CLI
}

Expand Down
4 changes: 4 additions & 0 deletions ovs/datapath_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,10 @@ func TestGetCTLimitsWithBinary(t *testing.T) {
for _, tt := range tests {
t.Run(tt.desc, func(t *testing.T) {
results, err := tt.dp.GetCTLimits(tt.dpName, tt.zones)
if err != nil {
t.Errorf(err.Error())
return
}
switch tt.testCase {
case validTest:
if tt.want.defaultLimit["default"] != results.defaultLimit["default"] {
Expand Down
2 changes: 1 addition & 1 deletion ovs/matchparser.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func parseMatch(key string, value string) (Match, error) {
case tpSRC, tpDST:
return parsePort(key, value, math.MaxUint16)
case conjID:
return parseIntMatch(key, value, math.MaxUint32)
return parseIntMatch(key, value, math.MaxInt32)
case arpSPA:
return ARPSourceProtocolAddress(value), nil
case arpTPA:
Expand Down
32 changes: 32 additions & 0 deletions ovs/vswitch.go
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,9 @@ type InterfaceOptions struct {
// Type specifies the Open vSwitch interface type.
Type InterfaceType

// Indicate whether enable bfd.
BfdEnable bool

// Peer specifies an interface to peer with when creating a patch interface.
Peer string

Expand Down Expand Up @@ -274,6 +277,19 @@ type InterfaceOptions struct {
// tunneled traffic leaving this interface. Optionally it could be set to
// "flow" which expects the flow to set tunnel ID.
Key string

// Specifies the usage of the Don't Fragment flag (DF) bit in outgoing packets
// with IPv4 headers. The value inherit causes the bit to be copied from
// the original IP header. The values unset and set cause the bit to be always unset
// or always set, respectively. By default, the bit is not set.
DfDefault string

// Specifies the source IP address to use in outgoing packets.
LocalIP string

// Specifies the UDP destination port to communicate to the remote
// VXLAN tunnel endpoint.
DstPort uint32
}

// slice creates a string slice containing any non-zero option values from the
Expand All @@ -285,6 +301,10 @@ func (i InterfaceOptions) slice() []string {
s = append(s, fmt.Sprintf("type=%s", i.Type))
}

if i.BfdEnable {
s = append(s, "bfd:enable=true")
}

if i.Peer != "" {
s = append(s, fmt.Sprintf("options:peer=%s", i.Peer))
}
Expand Down Expand Up @@ -315,5 +335,17 @@ func (i InterfaceOptions) slice() []string {
s = append(s, fmt.Sprintf("options:key=%s", i.Key))
}

if i.DfDefault != "" {
s = append(s, fmt.Sprintf("options:df_default=%s", i.DfDefault))
}

if i.LocalIP != "" {
s = append(s, fmt.Sprintf("options:local_ip=%s", i.LocalIP))
}

if i.DstPort > 0 {
s = append(s, fmt.Sprintf("options:dst_port=%d", i.DstPort))
}

return s
}
36 changes: 36 additions & 0 deletions ovs/vswitch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -857,6 +857,42 @@ func TestInterfaceOptions_slice(t *testing.T) {
"options:key=flow",
},
},
{
desc: "flow based VxLAN tunnel",
i: InterfaceOptions{
Type: InterfaceTypeVXLAN,
RemoteIP: "192.168.11.12",
Key: "flow",
DfDefault: "false",
LocalIP: "192.168.11.10",
DstPort: 8472,
},
out: []string{
"type=vxlan",
"options:remote_ip=192.168.11.12",
"options:key=flow",
"options:df_default=false",
"options:local_ip=192.168.11.10",
"options:dst_port=8472",
},
},
{
desc: "VxLAN tunnel with BFD enable",
i: InterfaceOptions{
Type: InterfaceTypeVXLAN,
BfdEnable: true,
RemoteIP: "192.168.11.12",
LocalIP: "192.168.11.10",
DstPort: 8472,
},
out: []string{
"type=vxlan",
"bfd:enable=true",
"options:remote_ip=192.168.11.12",
"options:local_ip=192.168.11.10",
"options:dst_port=8472",
},
},
{
desc: "all options",
i: InterfaceOptions{
Expand Down
2 changes: 1 addition & 1 deletion ovsdb/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
"sync/atomic"
"time"

"github.com/digitalocean/go-openvswitch/ovsdb/internal/jsonrpc"
"github.com/danieldin95/go-openvswitch/ovsdb/internal/jsonrpc"
)

// A Client is an OVSDB client. Clients can be customized by using OptionFuncs
Expand Down
2 changes: 1 addition & 1 deletion ovsdb/client_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"testing"
"time"

"github.com/digitalocean/go-openvswitch/ovsdb"
"github.com/danieldin95/go-openvswitch/ovsdb"
"github.com/google/go-cmp/cmp"
)

Expand Down
4 changes: 2 additions & 2 deletions ovsdb/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ import (
"testing"
"time"

"github.com/digitalocean/go-openvswitch/ovsdb"
"github.com/digitalocean/go-openvswitch/ovsdb/internal/jsonrpc"
"github.com/danieldin95/go-openvswitch/ovsdb"
"github.com/danieldin95/go-openvswitch/ovsdb/internal/jsonrpc"
"github.com/google/go-cmp/cmp"
)

Expand Down
2 changes: 1 addition & 1 deletion ovsdb/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"log"
"time"

"github.com/digitalocean/go-openvswitch/ovsdb"
"github.com/danieldin95/go-openvswitch/ovsdb"
)

// This example demonstrates basic usage of a Client. The Client connects to
Expand Down
2 changes: 1 addition & 1 deletion ovsdb/internal/jsonrpc/conn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"io"
"testing"

"github.com/digitalocean/go-openvswitch/ovsdb/internal/jsonrpc"
"github.com/danieldin95/go-openvswitch/ovsdb/internal/jsonrpc"
"github.com/google/go-cmp/cmp"
)

Expand Down
2 changes: 1 addition & 1 deletion ovsdb/rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func (c *Client) ListDatabases(ctx context.Context) ([]string, error) {
// Echo verifies that the OVSDB connection is alive, and can be used to keep
// the connection alive.
func (c *Client) Echo(ctx context.Context) error {
req := [1]string{"github.com/digitalocean/go-openvswitch/ovsdb"}
req := [1]string{"github.com/danieldin95/go-openvswitch/ovsdb"}

var res [1]string
if err := c.rpc(ctx, "echo", &res, req); err != nil {
Expand Down
6 changes: 3 additions & 3 deletions ovsdb/rpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ import (
"context"
"testing"

"github.com/digitalocean/go-openvswitch/ovsdb"
"github.com/digitalocean/go-openvswitch/ovsdb/internal/jsonrpc"
"github.com/danieldin95/go-openvswitch/ovsdb"
"github.com/danieldin95/go-openvswitch/ovsdb/internal/jsonrpc"
"github.com/google/go-cmp/cmp"
)

Expand Down Expand Up @@ -70,7 +70,7 @@ func TestClientEchoError(t *testing.T) {
}

func TestClientEchoOK(t *testing.T) {
const echo = "github.com/digitalocean/go-openvswitch/ovsdb"
const echo = "github.com/danieldin95/go-openvswitch/ovsdb"

c, _, done := testClient(t, func(req jsonrpc.Request) jsonrpc.Response {
if diff := cmp.Diff("echo", req.Method); diff != "" {
Expand Down
2 changes: 1 addition & 1 deletion ovsnl/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"strings"
"unsafe"

"github.com/digitalocean/go-openvswitch/ovsnl/internal/ovsh"
"github.com/danieldin95/go-openvswitch/ovsnl/internal/ovsh"
"github.com/mdlayher/genetlink"
)

Expand Down
2 changes: 1 addition & 1 deletion ovsnl/client_linux_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"os"
"testing"

"github.com/digitalocean/go-openvswitch/ovsnl"
"github.com/danieldin95/go-openvswitch/ovsnl"
"github.com/google/go-cmp/cmp"
)

Expand Down
2 changes: 1 addition & 1 deletion ovsnl/client_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"os"
"testing"

"github.com/digitalocean/go-openvswitch/ovsnl/internal/ovsh"
"github.com/danieldin95/go-openvswitch/ovsnl/internal/ovsh"
"github.com/mdlayher/genetlink"
"github.com/mdlayher/genetlink/genltest"
"github.com/mdlayher/netlink"
Expand Down
2 changes: 1 addition & 1 deletion ovsnl/datapath.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
"fmt"
"unsafe"

"github.com/digitalocean/go-openvswitch/ovsnl/internal/ovsh"
"github.com/danieldin95/go-openvswitch/ovsnl/internal/ovsh"
"github.com/mdlayher/genetlink"
"github.com/mdlayher/netlink"
"github.com/mdlayher/netlink/nlenc"
Expand Down
2 changes: 1 addition & 1 deletion ovsnl/datapath_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"testing"
"unsafe"

"github.com/digitalocean/go-openvswitch/ovsnl/internal/ovsh"
"github.com/danieldin95/go-openvswitch/ovsnl/internal/ovsh"
"github.com/google/go-cmp/cmp"
"github.com/mdlayher/genetlink"
"github.com/mdlayher/genetlink/genltest"
Expand Down