Home | History | Annotate | Download | only in pktgen
      1 import os, logging
      2 from autotest_lib.client.bin import test, utils
      3 from autotest_lib.client.common_lib import error
      4 
      5 
      6 class pktgen(test.test):
      7     version = 1
      8 
      9     def execute(self, eth='eth0', count=50000, clone_skb=1, \
     10                     dst_ip='192.168.210.210', dst_mac='01:02:03:04:05:07'):
     11         if not os.path.exists('/proc/net/pktgen'):
     12             utils.system('/sbin/modprobe pktgen')
     13         if not os.path.exists('/proc/net/pktgen'):
     14             raise error.TestError('pktgen not loaded')
     15 
     16         logging.info('Adding devices to run')
     17         self.pgdev = '/proc/net/pktgen/kpktgend_0'
     18 
     19         self.pgset('rem_device_all')
     20         self.pgset('add_device ' + eth)
     21         self.pgset('max_before_softirq 10000')
     22 
     23         # Configure the individual devices
     24         logging.info('Configuring devices')
     25 
     26         self.ethdev='/proc/net/pktgen/' + eth
     27         self.pgdev=self.ethdev
     28 
     29         if clone_skb:
     30             self.pgset('clone_skb %d' % (count))
     31         self.pgset('min_pkt_size 60')
     32         self.pgset('max_pkt_size 60')
     33         self.pgset('dst ' + dst_ip)
     34         self.pgset('dst_mac ' + dst_mac)
     35         self.pgset('count %d' % (count))
     36 
     37         # Time to run
     38         self.pgdev='/proc/net/pktgen/pgctrl'
     39         self.pgset('start')
     40 
     41         output = os.path.join(self.resultsdir, eth)
     42         utils.system ('cp %s %s' % (self.ethdev, output))
     43 
     44 
     45     def pgset(self, command):
     46         file = open(self.pgdev, 'w')
     47         file.write(command + '\n');
     48         file.close
     49 
     50         if not utils.grep('Result: OK', self.pgdev):
     51             if not utils.grep('Result: NA', self.pgdev):
     52                 utils.system('cat ' + self.pgdev)
     53