Skip to content

Commit 6183488

Browse files
committed
Support hwaddr config option to set bridge MAC
1 parent e2f1bc6 commit 6183488

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

ovs/vswitch.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ package ovs
1717
import (
1818
"encoding/json"
1919
"fmt"
20+
"net"
2021
"strings"
2122
)
2223

@@ -202,6 +203,9 @@ func (v *VSwitchSetService) Bridge(bridge string, options BridgeOptions) error {
202203
type BridgeOptions struct {
203204
// Protocols specifies the OpenFlow protocols the bridge should use.
204205
Protocols []string
206+
207+
//HWAddr specifies the MAC address to be assigned to the bridge.
208+
HWAddr string
205209
}
206210

207211
// slice creates a string slice containing any non-zero option values from the
@@ -213,6 +217,10 @@ func (o BridgeOptions) slice() []string {
213217
s = append(s, fmt.Sprintf("protocols=%s", strings.Join(o.Protocols, ",")))
214218
}
215219

220+
if hw, err := net.ParseMAC(o.HWAddr); err == nil {
221+
s = append(s, fmt.Sprintf("other-config:hwaddr=%s", hw.String()))
222+
}
223+
216224
return s
217225
}
218226

ovs/vswitch_test.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,7 @@ func TestClientVSwitchGetBridgeProtocolsOK(t *testing.T) {
461461
}
462462
}
463463

464-
func TestClientVSwitchSetBridgeProtocolsOK(t *testing.T) {
464+
func TestClientVSwitchSetBridgeOptionsOK(t *testing.T) {
465465
const bridge = "br0"
466466
protocols := []string{
467467
ProtocolOpenFlow10,
@@ -471,6 +471,7 @@ func TestClientVSwitchSetBridgeProtocolsOK(t *testing.T) {
471471
ProtocolOpenFlow14,
472472
ProtocolOpenFlow15,
473473
}
474+
hwaddr := "55:84:a3:2f:d3:20"
474475

475476
c := testClient([]OptionFunc{Timeout(1)}, func(cmd string, args ...string) ([]byte, error) {
476477
if want, got := "ovs-vsctl", cmd; want != got {
@@ -484,6 +485,7 @@ func TestClientVSwitchSetBridgeProtocolsOK(t *testing.T) {
484485
"bridge",
485486
bridge,
486487
fmt.Sprintf("protocols=%s", strings.Join(protocols, ",")),
488+
fmt.Sprintf("other-config:hwaddr=%s", hwaddr),
487489
}
488490
if want, got := wantArgs, args; !reflect.DeepEqual(want, got) {
489491
t.Fatalf("incorrect arguments\n- want: %v\n- got: %v",
@@ -495,6 +497,7 @@ func TestClientVSwitchSetBridgeProtocolsOK(t *testing.T) {
495497

496498
err := c.VSwitch.Set.Bridge(bridge, BridgeOptions{
497499
Protocols: protocols,
500+
HWAddr: hwaddr,
498501
})
499502
if err != nil {
500503
t.Fatalf("unexpected error for Client.VSwitch.Set.Bridge: %v", err)

0 commit comments

Comments
 (0)