From 234104bb1d0a8a4d023bf92000fd66f0ecd04f62 Mon Sep 17 00:00:00 2001 From: Sudhindra Aithal Date: Fri, 5 Mar 2021 16:36:16 -0800 Subject: [PATCH 1/3] Local IP support in vxlan --- ovs/vswitch.go | 22 ++++++++++++++++++++++ ovs/vswitch_test.go | 15 +++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/ovs/vswitch.go b/ovs/vswitch.go index d06b302..b887670 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,14 @@ 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 } // slice creates a string slice containing any non-zero option values from the @@ -307,5 +326,8 @@ 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.Key)) + } 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{ From 73bcee2c25a04ed5c8e060b628c8e1598da3c7ef Mon Sep 17 00:00:00 2001 From: Sudhindra Aithal Date: Tue, 9 Mar 2021 14:22:39 -0800 Subject: [PATCH 2/3] Fix LOCAL IP setting --- ovs/vswitch.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ovs/vswitch.go b/ovs/vswitch.go index b887670..776aacc 100644 --- a/ovs/vswitch.go +++ b/ovs/vswitch.go @@ -327,7 +327,7 @@ func (i InterfaceOptions) slice() []string { } if i.LocalIP != "" { - s = append(s, fmt.Sprintf("options:local_ip=%s", i.Key)) + s = append(s, fmt.Sprintf("options:local_ip=%s", i.LocalIP)) } return s } From e2842369e2ef25b0a8f04d6e7edd0682fb2604d7 Mon Sep 17 00:00:00 2001 From: Sudhindra Aithal Date: Tue, 11 Oct 2022 06:27:43 -0700 Subject: [PATCH 3/3] Add support for src and dst port --- ovs/vswitch.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/ovs/vswitch.go b/ovs/vswitch.go index 776aacc..30a6ec3 100644 --- a/ovs/vswitch.go +++ b/ovs/vswitch.go @@ -289,6 +289,12 @@ type InterfaceOptions struct { // 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 @@ -329,5 +335,14 @@ func (i InterfaceOptions) slice() []string { 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 }