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