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

Local IP support in vxlan #113

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions ovs/vswitch.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
}
15 changes: 15 additions & 0 deletions ovs/vswitch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down