diff --git a/ovs/vswitch.go b/ovs/vswitch.go index d06b302..30a6ec3 100644 --- a/ovs/vswitch.go +++ b/ovs/vswitch.go @@ -228,6 +228,17 @@ func (v *VSwitchSetService) Interface(ifi string, options InterfaceOptions) erro return err } +// VxlanInterface sets vxlan configuration +func (v *VSwitchSetService) VxlanInterface(ifi string, options InterfaceOptions) error { + // Prepend command line arguments before expanding options slice + // and appending it + args := []string{"--may-exist", "add-port", options.Bridge, ifi, "--", "set", "interface", ifi} + args = append(args, options.slice()...) + + _, err := v.v.exec(args...) + return err +} + // An InterfaceOptions struct enables configuration of an Interface. type InterfaceOptions struct { // Type specifies the Open vSwitch interface type. @@ -270,6 +281,20 @@ 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 + + // LocalIP can be populated when the interface is a tunnel interface type + // for example "stt" or "vxlan". It specifies the LocalIP IP address with which to + // form tunnels when traffic is sent to this port. + LocalIP string + + // Bridge to be connected if vxlan + Bridge string + + //Src Port + SrcPort string + + //Dst Port + DstPort string } // slice creates a string slice containing any non-zero option values from the @@ -307,5 +332,17 @@ func (i InterfaceOptions) slice() []string { s = append(s, fmt.Sprintf("options:key=%s", i.Key)) } + if i.LocalIP != "" { + s = append(s, fmt.Sprintf("options:local_ip=%s", i.LocalIP)) + } + + if i.SrcPort != "" { + s = append(s, fmt.Sprintf("options:src_port=%s", i.SrcPort)) + } + + if i.DstPort != "" { + s = append(s, fmt.Sprintf("options:dst_port=%s", i.DstPort)) + } + return s } diff --git a/ovs/vswitch_test.go b/ovs/vswitch_test.go index 8dfa9c8..60eec63 100644 --- a/ovs/vswitch_test.go +++ b/ovs/vswitch_test.go @@ -845,6 +845,21 @@ func TestInterfaceOptions_slice(t *testing.T) { "options:key=flow", }, }, + { + desc: "vxlan tunnel", + i: InterfaceOptions{ + Type: InterfaceTypeSTT, + RemoteIP: "flow", + LocalIP: "flow", + Key: "flow", + }, + out: []string{ + "type=vxlan", + "options:remote_ip=flow", + "options:local_ip=flow", + "options:key=flow", + }, + }, { desc: "all options", i: InterfaceOptions{