Disable NIC offloading

Change-Id: Ib46448c8b24f4f499b3fe9f4462a2daa361de5a5
diff --git a/trellis/trellislib.py b/trellis/trellislib.py
index 4a3f7a3..d5e2d2b 100644
--- a/trellis/trellislib.py
+++ b/trellis/trellislib.py
@@ -38,6 +38,8 @@
         self.defaultIntf().name = self.vlanIntf
         self.nameToIntf[self.vlanIntf] = self.defaultIntf()
 
+        disable_offload(self, self.vlanIntf)
+
     def terminate(self, **kwargs):
         self.cmd('ip link remove link %s' % self.vlanIntf)
         super(TaggedRoutedHost, self).terminate()
@@ -68,6 +70,8 @@
 
         self.cmd('ip route add default via %s' % self.gateway)
 
+        disable_offload(self, self.innerVlanIntf)
+
     def terminate(self, **kwargs):
         self.cmd('ip link remove link %s' % self.outerVlanIntf)
         self.cmd('ip link remove link %s' % self.innerVlanIntf)
@@ -84,6 +88,8 @@
         self.cmd('ip addr flush dev %s' % self.defaultIntf())
         self.cmd('dhclient -q -4 -nw -pf %s -lf %s %s' % (self.pidFile, self.leaseFile, self.defaultIntf()))
 
+        disable_offload(self, self.defaultIntf())
+
     def terminate(self, **kwargs):
         self.cmd('kill -9 `cat %s`' % self.pidFile)
         self.cmd('rm -rf %s' % self.pidFile)
@@ -101,6 +107,8 @@
         time.sleep(3)
         self.cmd('dhclient -q -6 -nw -pf %s -lf %s %s' % (self.pidFile, self.leaseFile, self.defaultIntf()))
 
+        disable_offload(self, self.defaultIntf())
+
     def terminate(self, **kwargs):
         self.cmd('kill -9 `cat %s`' % self.pidFile)
         self.cmd('rm -rf %s' % self.pidFile)
@@ -124,6 +132,8 @@
         time.sleep(3)
         self.cmd('dhclient -q -6 -nw -pf %s -lf %s %s' % (self.pidFile6, self.leaseFile6, self.defaultIntf()))
 
+        disable_offload(self, self.defaultIntf())
+
     def terminate(self, **kwargs):
         self.cmd('kill -9 `cat %s`' % self.pidFile4)
         self.cmd('rm -rf %s' % self.pidFile4)
@@ -142,6 +152,8 @@
         self.cmd('touch %s' % self.leasesFile)
         self.cmd('%s -q -4 -pf %s -cf %s %s' % (self.binFile, self.pidFile, self.configFile, self.defaultIntf()))
 
+        disable_offload(self, self.defaultIntf())
+
     def terminate(self, **kwargs):
         self.cmd('kill -9 `cat %s`' % self.pidFile)
         self.cmd('rm -rf %s' % self.pidFile)
@@ -160,6 +172,8 @@
         self.cmd('touch %s' % self.leasesFile)
         self.cmd('%s -q -6 -pf %s -cf %s %s' % (self.binFile, self.pidFile, self.configFile, self.defaultIntf()))
 
+        disable_offload(self, self.defaultIntf())
+
     def terminate(self, **kwargs):
         self.cmd('kill -9 `cat %s`' % self.pidFile)
         self.cmd('rm -rf %s' % self.pidFile)
@@ -183,6 +197,8 @@
         self.cmd('route add default gw %s' % self.gateway)
         self.cmd('%s -4 -a -pf %s %s %s' % (self.binFile, self.pidFile, ifacesStr, self.serverIp))
 
+        disable_offload(self, ifacesStr)
+
     def terminate(self, **kwargs):
         self.cmd('kill -9 `cat %s`', self.pidFile)
         self.cmd('rm -rf %s' % self.pidFile)
@@ -203,6 +219,8 @@
         self.cmd('ip link set up %s' % self.vlanIntf)
         self.cmd('dhclient -q -4 -nw -pf %s %s' % (self.pidFile, self.vlanIntf))
 
+        disable_offload(self, self.vlanIntf)
+
     def terminate(self, **kwargs):
         self.cmd('kill -9 `cat %s`' % self.pidFile)
         self.cmd('rm -rf %s' % self.pidFile)
@@ -218,6 +236,8 @@
         super(TaggedDhcpServer, self).config(**kwargs)
         self.cmd('%s -q -4 -pf %s -cf %s %s' % (self.binFile, self.pidFile, self.configFile, self.vlanIntf))
 
+        disable_offload(self, self.vlanIntf)
+
     def terminate(self, **kwargs):
         self.cmd('kill -9 `cat %s`' % self.pidFile)
         self.cmd('rm -rf %s' % self.pidFile)
@@ -245,6 +265,8 @@
         self.cmd('ip link set %s up' % self.bond0)
         self.cmd('dhclient -q -4 -nw -pf %s %s' % (self.pidFile, self.bond0))
 
+        disable_offload(self, self.bond0)
+
     def terminate(self, **kwargs):
         self.cmd('ip link set %s down' % self.bond0)
         self.cmd('ip link delete %s' % self.bond0)
@@ -280,6 +302,8 @@
         self.cmd('dhclient -q -4 -nw -pf %s %s' % (self.pidFile4, self.bond0))
         self.cmd('dhclient -q -6 -nw -pf %s %s' % (self.pidFile6, self.bond0))
 
+        disable_offload(self, self.bond0)
+
     def terminate(self, **kwargs):
         self.cmd('ip link set %s down' % self.bond0)
         self.cmd('ip link delete %s' % self.bond0)
@@ -355,3 +379,9 @@
     with open("zebradbgp2.conf", "w") as config_file_2:
         config_file_2.write(zebra2)
 
+# Disable NIC offloading
+def disable_offload(host, intf):
+    for attr in ["rx", "tx", "sg"]:
+        cmd = "/sbin/ethtool --offload %s %s off" % (intf, attr)
+        host.cmd(cmd)
+