Skip to content

Commit 1a494c8

Browse files
committed
Support bridge STP configuration option
1 parent 6183488 commit 1a494c8

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

ovs/vswitch.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"encoding/json"
1919
"fmt"
2020
"net"
21+
"strconv"
2122
"strings"
2223
)
2324

@@ -204,8 +205,12 @@ type BridgeOptions struct {
204205
// Protocols specifies the OpenFlow protocols the bridge should use.
205206
Protocols []string
206207

207-
//HWAddr specifies the MAC address to be assigned to the bridge.
208+
// HWAddr specifies the MAC address to be assigned to the bridge.
208209
HWAddr string
210+
211+
// STP defines if the spanning tree protocol is to be enabled on the bridge. A
212+
// nil value here will not change the STP config of the bridge.
213+
STP *bool
209214
}
210215

211216
// slice creates a string slice containing any non-zero option values from the
@@ -221,6 +226,10 @@ func (o BridgeOptions) slice() []string {
221226
s = append(s, fmt.Sprintf("other-config:hwaddr=%s", hw.String()))
222227
}
223228

229+
if o.STP != nil {
230+
s = append(s, fmt.Sprintf("stp_enable=%s", strconv.FormatBool(*o.STP)))
231+
}
232+
224233
return s
225234
}
226235

ovs/vswitch_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"errors"
2020
"fmt"
2121
"reflect"
22+
"strconv"
2223
"strings"
2324
"testing"
2425
)
@@ -472,6 +473,7 @@ func TestClientVSwitchSetBridgeOptionsOK(t *testing.T) {
472473
ProtocolOpenFlow15,
473474
}
474475
hwaddr := "55:84:a3:2f:d3:20"
476+
stp := true
475477

476478
c := testClient([]OptionFunc{Timeout(1)}, func(cmd string, args ...string) ([]byte, error) {
477479
if want, got := "ovs-vsctl", cmd; want != got {
@@ -486,6 +488,7 @@ func TestClientVSwitchSetBridgeOptionsOK(t *testing.T) {
486488
bridge,
487489
fmt.Sprintf("protocols=%s", strings.Join(protocols, ",")),
488490
fmt.Sprintf("other-config:hwaddr=%s", hwaddr),
491+
fmt.Sprintf("stp_enable=%s", strconv.FormatBool(stp)),
489492
}
490493
if want, got := wantArgs, args; !reflect.DeepEqual(want, got) {
491494
t.Fatalf("incorrect arguments\n- want: %v\n- got: %v",
@@ -498,6 +501,7 @@ func TestClientVSwitchSetBridgeOptionsOK(t *testing.T) {
498501
err := c.VSwitch.Set.Bridge(bridge, BridgeOptions{
499502
Protocols: protocols,
500503
HWAddr: hwaddr,
504+
STP: &stp,
501505
})
502506
if err != nil {
503507
t.Fatalf("unexpected error for Client.VSwitch.Set.Bridge: %v", err)

0 commit comments

Comments
 (0)