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

configure Vxlan veth interface mtu based on configured minimum host … #1135

Merged
merged 1 commit into from
May 29, 2018
Merged
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
24 changes: 17 additions & 7 deletions drivers/ovsd/ovsSwitch.go
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,13 @@ const (

// OvsSwitch represents on OVS bridge instance
type OvsSwitch struct {
bridgeName string
netType string
uplinkDb cmap.ConcurrentMap
ovsdbDriver *OvsdbDriver
ofnetAgent *ofnet.OfnetAgent
hostPvtNW int
bridgeName string
netType string
uplinkDb cmap.ConcurrentMap
ovsdbDriver *OvsdbDriver
ofnetAgent *ofnet.OfnetAgent
hostPvtNW int
vxlanEncapMtu int
}

// getPvtIP returns a private IP for the port
Expand Down Expand Up @@ -100,6 +101,10 @@ func NewOvsSwitch(bridgeName, netType, localIP, fwdMode string,
sw.netType = netType
sw.uplinkDb = cmap.New()
sw.hostPvtNW = hostPvtNW
sw.vxlanEncapMtu, err = netutils.GetHostLowestLinkMtu()
if err != nil {
log.Fatalf("Failed to get Host Node MTU. Err: %v", err)
}

// Create OVS db driver
sw.ovsdbDriver, err = NewOvsdbDriver(bridgeName, "secure", vxlanUDPPort)
Expand Down Expand Up @@ -359,7 +364,12 @@ func (sw *OvsSwitch) CreatePort(intfName string, cfgEp *mastercfg.CfgEndpointSta

// Set the link mtu to 1450 to allow for 50 bytes vxlan encap
// (inner eth header(14) + outer IP(20) outer UDP(8) + vxlan header(8))
err = setLinkMtu(intfName, vxlanEndpointMtu)
if sw.netType == "vxlan" {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a constant you can use here instead of a string literal?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no constant available ; same string literal has been used other part of code

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see this section of code:
sw.ovsdbDriver.ovsSwitch = sw

    if netType == "vxlan" {
            ofnetPort = vxlanOfnetPort
            ctrlrPort = vxlanCtrlerPort
            switch fwdMode {
            case "bridge":
                    datapath = "vxlan"
            case "routing":
                    datapath = "vrouter"
            default:

correctMtu := sw.vxlanEncapMtu - 50 //Include Vxlan header size
err = setLinkMtu(intfName, correctMtu)
} else {
err = setLinkMtu(intfName, sw.vxlanEncapMtu)
}
if err != nil {
log.Errorf("Error setting link %s mtu. Err: %v", intfName, err)
return err
Expand Down
24 changes: 24 additions & 0 deletions utils/netutils/netutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -755,6 +755,30 @@ func GetLocalAddrList() ([]string, error) {
return addrList, err
}

//GetHostLowestLinkMtu return lowest mtu for host interface(excluding ovs
//interface
func GetHostLowestLinkMtu() (int, error) {

lowestMTU := 9000 //Jumbo frame MTU
intfList, err := net.Interfaces()
if err != nil {
return 0, err
}
// Loop thru each interface and add its ip addr to list
for _, intf := range intfList {
if strings.HasPrefix(intf.Name, "docker") || strings.HasPrefix(intf.Name, "veth") ||
strings.HasPrefix(intf.Name, "vport") || strings.HasPrefix(intf.Name, "lo") {
continue
}

lowestMTU = int(math.Min(float64(lowestMTU), float64(intf.MTU)))
}
if lowestMTU == 0 {
return 0, errors.New("Failed to find minimum MTU")
}
return lowestMTU, nil
}

// IsAddrLocal check if an address is local
func IsAddrLocal(findAddr string) bool {
// get the local addr list
Expand Down