Skip to content

Commit

Permalink
configure Vxlan veth interface mtu based on configured minimum host i…
Browse files Browse the repository at this point in the history
…nterface mtu
  • Loading branch information
g1rana authored and unclejack committed Jun 4, 2018
1 parent 4aec51c commit 53da09d
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 7 deletions.
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" {
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

0 comments on commit 53da09d

Please sign in to comment.