def ubus_call_raw(payload, ipaddr="192.168.1.1"): curl_cmd = "curl -d '%s' http://%s/ubus" % (json.dumps(payload), ipaddr) lan.sendline(curl_cmd) lan.expect("\r\n") lan.expect(prompt) return json.loads(lan.before)
def runTest(self): #for d in [wan, lan]: #d.sendline('apt-get update && apt-get -o Dpkg::Options::="--force-confnew" -y install socat pv') #d.expect(prompt) maxtime = 5 board.get_nf_conntrack_conn_count() for i in range(10000): sz, rate, ip, port = self.startSingleFlow(maxtime=maxtime) print("started UDP to %s:%s sz = %s, rate = %sk" % (ip, port, sz, rate)) time = sz / (rate * 1024) print("time should be ~%s" % time) self.check_and_clean_ips() lan.sendline('fg') lan.expect(prompt, timeout=5) board.get_pp_dev().sendline( 'cat /proc/net/nf_conntrack | grep dst=%s.*dport=%s' % (ip, port)) board.get_pp_dev().expect(prompt) board.get_nf_conntrack_conn_count() self.recover()
def recover(self): board.touch() lan.sendcontrol('c') lan.expect(prompt) board.touch() print("Copying files from lan to dir = %s" % self.config.output_dir) lan.sendline('readlink -f $HOME/%s/' % self.dir) lan.expect_exact('$HOME/%s/' % self.dir) board.touch() lan.expect(prompt) board.touch() fname = lan.before.replace('\n', '').replace('\r', '') board.touch() rm_r(os.path.join(self.config.output_dir, self.dir)) scp_from(fname, lan.ipaddr, lan.username, lan.password, lan.port, self.config.output_dir) # let board settle down board.expect(pexpect.TIMEOUT, timeout=30) board.touch() board.parse_stats(dict_to_log=self.logged) board.touch() self.result_message = 'JMeter: DONE, name = %s cpu usage = %s' % ( self.shortname, self.logged['mpstat'])
def runTest(self): install_lighttpd(wan) wan.sendline('/etc/init.d/lighttpd start') wan.expect(prompt) # Wan device: Create small file in web dir fname = 'small.txt' cmd = '\nhead -c 10000 /dev/urandom > /var/www/%s' % fname wan.sendline(cmd) wan.expect(prompt) # Lan Device: download small file a lot # TODO: this is actually a 404 for lighthttpd config issues? url = 'http://%s/%s' % (wan.gw, fname) # Start CPU monitor board.collect_stats(stats=['mpstat']) # Lan Device: download small file a lot lan.sendline('\nab -dn %s -c %s %s' % (self.num_conn, self.concurrency, url)) lan.expect('Benchmarking') timeout = 0.05 * self.num_conn if 0 != lan.expect([ r'Requests per second:\s+(\d+)', 'apr_socket_recv: Connection reset by peer' ], timeout=timeout): raise Exception("ab failed to run") self.reqs_per_sec = int(lan.match.group(1)) lan.expect(prompt) self.recover()
def runTest(self): lan.sendline('\nping6 -c 20 4aaa::1') lan.expect('PING ') lan.expect(' ([0-9]+) (packets )?received') n = int(lan.match.group(1)) lan.expect(prompt) assert n > 0
def runTest(self): start_port = random.randint(1, 11000) lan.sendline('\nnmap --min-rate 100 -sU -p %s-%s 192.168.0.1' % (start_port, start_port + 200)) lan.expect('Starting Nmap', timeout=5) lan.expect('Nmap scan report', timeout=30) lan.expect(prompt)
def cleanup_ip(self, ip): wan.sendline('ip addr del %s/32 dev %s' % (ip, wan.iface_dut)) wan.expect_exact('ip addr del %s/32 dev %s' % (ip, wan.iface_dut)) wan.expect(prompt) wan.sendline('pkill -9 -f socat.*bind=%s' % ip) wan.expect(prompt) lan.sendline('pkill -9 -f socat.*%s:%s' % (self.socat_send, ip)) lan.expect(prompt)
def runTest(self): if not lan: msg = 'No LAN Device defined, skipping ping test from LAN.' lib.common.test_msg(msg) self.skipTest(msg) lan.sendline('\nping -c2 8.8.8.8') lan.expect('2 (packets )?received', timeout=10) lan.expect(prompt)
def runTest(self): # Make Lan-device ping Wan-Device lan.sendline('\nping6 -c 20 5aaa::6') lan.expect('PING ') lan.expect(' ([0-9]+) (packets )?received') n = int(lan.match.group(1)) lan.expect(prompt) assert n > 0
def runTest(self): from boardfarm.lib.installers import install_snmp, install_snmpd from boardfarm.lib.common import snmp_mib_get wrong_mibs = ['PsysDescr', 'sys123ObjectID', 'sysServiceS'] linux_mibs = ['sysDescr',\ 'sysObjectID',\ 'sysServices',\ 'sysName',\ 'sysServices',\ 'sysUpTime'] test_mibs = [linux_mibs[0], wrong_mibs[0],\ linux_mibs[1], wrong_mibs[1],\ linux_mibs[2], wrong_mibs[2]] unit_test = SnmpMibsUnitTest(mibs_location=os.path.abspath( os.path.join(os.path.dirname(os.path.realpath(__file__)), os.pardir, 'resources', 'mibs')), files=['SNMPv2-MIB'], mibs=test_mibs, err_mibs=wrong_mibs) assert (unit_test.unitTest()) install_snmpd(wan) lan.sendline('echo "nameserver 8.8.8.8" >> /etc/resolv.conf') lan.expect(lan.prompt) install_snmp(lan) wan_iface_ip = wan.get_interface_ipaddr(wan.iface_dut) for mib in linux_mibs: try: result = snmp_mib_get(lan, unit_test.snmp_obj, str(wan_iface_ip), mib, '0', community='public') print('snmpget({})@{}={}'.format(mib, wan_iface_ip, result)) print("Trying with snmp_v2 as well") value = SnmpHelper.snmp_v2(lan, str(wan_iface_ip), mib, community='public') print("Snmpget via snmpv2 on %s: %s" % (mib, value)) except Exception as e: print('Failed on snmpget {} '.format(mib)) print(e) raise e print("Test passed")
def runTest(self): ip = "192.168.1.1" url = 'http://%s/' % ip lan.sendline('\ncurl -v %s' % url) lan.expect('<html') lan.expect('<body') lan.expect('</body>') lan.expect('</html>') lan.expect(prompt)
def recover(self): lan.sendcontrol('c') lan.expect(lan.prompt) lan.sendline('rm -rf Fedora*') lan.expect(lan.prompt) board.sendcontrol('c') board.expect(board.prompt) board.sendline('fg') board.sendcontrol('c') board.expect(board.prompt)
def runTest(self): if not lan: msg = 'No LAN Device defined, skipping ping test from LAN.' lib.common.test_msg(msg) self.skipTest(msg) router_ip = board.get_interface_ipaddr(board.lan_iface) lan.sendline('\nping -i 0.2 -c 5 %s' % router_ip) lan.expect('PING ') lan.expect('5 (packets )?received', timeout=15) lan.expect(prompt)
def runTest(self): for sz in ["74", "128", "256", "512", "1024", "1280", "1518"]: print("running %s UDP test" % sz) lan.sendline( 'netperf -H 192.168.0.1 -t UDP_STREAM -l 60 -- -m %s' % sz) lan.expect_exact( 'netperf -H 192.168.0.1 -t UDP_STREAM -l 60 -- -m %s' % sz) lan.expect('UDP UNIDIRECTIONAL') lan.expect(prompt, timeout=90) board.sendline() board.expect(prompt)
def runTest(self): ip = "192.168.1.1" board.sendline('\nhead -c 1000000 /dev/urandom > /www/deleteme.txt') board.expect('head ', timeout=5) board.expect(prompt) lan.sendline('\ncurl -m 25 http://%s/deleteme.txt > /dev/null' % ip) lan.expect('Total', timeout=5) lan.expect('100 ', timeout=10) lan.expect(prompt, timeout=10) board.sendline('\nrm -f /www/deleteme.txt') board.expect('deleteme.txt') board.expect(prompt)
def runTest(self): if not lan: msg = 'No LAN Device defined, skipping ping test from LAN.' lib.common.test_msg(msg) self.skipTest(msg) if not wan: msg = 'No WAN Device defined, skipping ping WAN test.' lib.common.test_msg(msg) self.skipTest(msg) lan.sendline('\nping -i 0.2 -c 5 %s' % wan.gw) lan.expect('PING ') lan.expect('5 (packets )?received', timeout=15) lan.expect(prompt)
def runTest(self): board.sendline( 'rm -f /etc/config/samba; opkg update; opkg install --force-reinstall samba36-server samba36-client kmod-fs-cifs' ) board.expect('Configuring samba36-server') board.expect(prompt) board.sendline( 'mkdir -p /tmp/samba; chmod a+rwx /tmp/samba; rm -rf /tmp/samba/*') board.expect(prompt) board.sendline( 'uci set samba.@samba[0].homes=0; uci delete samba.@sambashare[0]; uci add samba sambashare; uci set samba.@sambashare[0]=sambashare; uci set samba.@sambashare[0].name="boardfarm-test"; uci set samba.@sambashare[0].path="/tmp/samba"; uci set samba.@sambashare[0].read_only="no"; uci set samba.@sambashare[0].guest_ok="yes"; uci commit samba' ) board.expect(prompt) board.sendline('/etc/init.d/samba restart') board.sendline('smbclient -N -L 127.0.0.1') board.expect('boardfarm-test') board.expect(prompt) lan.sendline('smbclient -N -L %s' % board.get_interface_ipaddr(board.lan_iface)) lan.expect('boardfarm-test') lan.expect(prompt) lan.sendline( 'mkdir -p /mnt/samba; mount -o guest //%s/boardfarm-test /mnt/samba' % board.get_interface_ipaddr(board.lan_iface)) lan.expect(prompt) lan.sendline('echo boardafarm-testing-string > /mnt/samba/test') lan.expect(prompt) lan.sendline('umount /mnt/samba') lan.expect(prompt) board.sendline('cat /tmp/samba/test') board.expect('boardafarm-testing-string') board.expect(prompt)
def runTest(self): lan.sendline('nmap -sS -A -v -p 1-10000 %s' % board.get_interface_ipaddr(board.lan_iface)) lan.expect('Starting Nmap') for i in range(12): if 0 == lan.expect(['Nmap scan report', pexpect.TIMEOUT], timeout=100): break board.touch() lan.expect(prompt, timeout=60) open_ports = re.findall("(\d+)/tcp\s+open", lan.before) msg = "Found %s open TCP ports on LAN interface: %s." % \ (len(open_ports), ", ".join(open_ports)) self.result_message = msg
def runTest(self): # WAN Device: create large file in web directory fname = "/var/www/20mb.txt" wan.sendline('\n[ -e "%s" ] || head -c 20971520 /dev/urandom > %s' % (fname, fname)) wan.expect('/var') wan.expect(prompt) # LAN Device: download the file lan.sendline( '\ncurl -m 57 -g -6 http://[5aaa::6]/20mb.txt > /dev/null') lan.expect('Total', timeout=5) i = lan.expect(["couldn't connect", '20.0M 100 20.0M'], timeout=60) if i == 0: assert False lan.expect(prompt)
def runTest(self): wan_ip = wan.get_interface_ipaddr(wan.iface_dut) wan.sendline('iperf -s -l 1M -w 1M') wan.expect('Server listening on ') board.collect_stats(stats=['mpstat']) time = 10 cmd = "iperf -R -c %s -P %s -t 10 -N -w 1M -l 1M | grep SUM" # prime the pipes... lan.sendline(cmd % (wan_ip, 4)) lan.expect(prompt) prev_con = 0 prev_failed = 0 for con_conn in range(32, 513, 16): try: tstart = datetime.now() lan.sendline(cmd % (wan_ip, con_conn)) failed_cons = 0 while (datetime.now() - tstart).seconds < (time * 2): timeout = (time * 2) - (datetime.now() - tstart).seconds if 0 == lan.expect( ['write failed: Connection reset by peer'] + prompt, timeout=timeout): failed_cons += 1 else: break print_bold("For iperf with %s connections, %s failed...." % (con_conn, failed_cons)) lan.expect('.*') wan.expect('.*') board.touch() prev_conn = con_conn prev_failed = failed_cons if con_conn == 512: self.result_message = "iPerf Concurrent passed 512 connections (failed conns = %s)" % failed_cons except: self.result_message = "iPerf Concurrent Connections failed entirely at %s (failed conns = %s)" % ( prev_conn, prev_failed) break print(self.result_message) self.recover()
def runTest(self): board.sendline('uci set network.lan.ifname="%s %s"' % (board.wan_iface, board.lan_gmac_iface)) board.expect(prompt) board.sendline('uci set firewall.@defaults[0]=defaults') board.expect(prompt) board.sendline('uci set firewall.@defaults[0].input=ACCEPT') board.expect(prompt) board.sendline('uci set firewall.@defaults[0].output=ACCEPT') board.expect(prompt) board.sendline('uci set firewall.@defaults[0].syn_flood=1') board.expect(prompt) board.sendline('uci set firewall.@defaults[0].forward=ACCEPT') board.expect(prompt) board.sendline('uci set firewall.@zone[0]=zone') board.expect(prompt) board.sendline('uci set firewall.@zone[0].name=lan') board.expect(prompt) board.sendline('uci set firewall.@zone[0].network=lan') board.expect(prompt) board.sendline('uci set firewall.@zone[0].input=ACCEPT') board.expect(prompt) board.sendline('uci set firewall.@zone[0].output=ACCEPT') board.expect(prompt) board.sendline('uci set firewall.@zone[0].forward=ACCEPT') board.expect(prompt) board.sendline('uci set firewall.@zone[1]=zone') board.expect(prompt) board.sendline('uci set firewall.@zone[1].name=wan') board.expect(prompt) board.sendline('uci set firewall.@zone[1].network=wan') board.expect(prompt) board.sendline('uci set firewall.@zone[1].output=ACCEPT') board.expect(prompt) board.sendline('uci set firewall.@zone[1].mtu_fix=1') board.expect(prompt) board.sendline('uci set firewall.@zone[1].input=ACCEPT') board.expect(prompt) board.sendline('uci set firewall.@zone[1].forward=ACCEPT') board.expect(prompt) board.sendline('uci commit') board.expect(prompt) board.network_restart() board.firewall_restart() lan.sendline('ifconfig %s 192.168.0.2' % lan.iface_dut) lan.expect(prompt)
def check_and_clean_ips(self): if 'TCP' in self.socat_send: c = 'TCP' else: c = 'UDP' lan.sendline( "echo SYNC; ps aux | grep socat | sed -e 's/.*%s/%s/g' | tr '\n' ' '" % (c, c)) lan.expect_exact("SYNC\r\n") lan.expect(prompt) seen_ips = re.findall('%s:([^:]*):' % self.socat_send, lan.before) if len(self.all_ips) > 0: ips_to_cleanup = set(zip(*self.all_ips)[0]) - set(seen_ips) for done_ip in ips_to_cleanup: self.cleanup_ip(done_ip) self.all_ips = [e for e in self.all_ips if e[0] != done_ip]
def recover(self): lan.sendcontrol('c') lan.expect(prompt) lan.sendline('pkill -9 -f hping3') lan.expect_exact('pkill -9 -f hping3') lan.expect(prompt) wan.sendcontrol('c') wan.expect(prompt) wan.sendline('pkill -9 -f nc ') wan.expect_exact('pkill -9 -f nc') wan.expect(prompt) board.parse_stats(dict_to_log=self.logged) args = (self.conn_rate, self.max_conns, self.logged['mpstat']) self.result_message = "hping3 udp firewall test, conn_rate = %s, max_conns = %s, cpu usage = %.2f" % args
def start_browser(self): try: x, y = self.config.get_display_backend_size() # try to start vnc server self.display = Display( backend=self.config.default_display_backend, rfbport=self.config.default_display_backend_port, visible=0, size=(x, y)) self.display.start() if "BFT_DEBUG" in os.environ: print("Connect to VNC display running on localhost:" + self.config.default_display_backend_port) raw_input("Press any key after connecting to display....") except: # fallback xvfb self.display = Display(visible=0, size=(1366, 768)) self.display.start() try: if lan.http_proxy is not None: proxy = lan.http_proxy elif lan.ipaddr is not None: ip = lan.ipaddr lan.sendline('cat /proc/net/vlan/config') lan.expect('%s.*\|\s([0-9]+).*\|' % lan.iface_dut) port = 8000 + int(lan.match.group(1)) lan.expect(prompt) proxy = "%s:%s" % (ip, port) else: # no proxy, use message below assert False except Exception as e: print(e) raise Exception( "No reasonable http proxy found, please add one to the board config" ) board.enable_mgmt_gui(board, wan) print("Using proxy %s" % proxy) driver = lib.common.get_webproxy_driver(proxy, self.config) return driver
def startSingleFlow(self, mintime=1, maxtime=60): while True: random_ip = fake_generator.ipv4() random_port = randint(1024, 65535) if not ipaddress.ip_address(random_ip.decode()).is_private: if (ipaddress.ip_address(random_ip.decode()), random_port) not in self.all_ips: break else: print("Skipping ip addr: %s" % random_ip) print("Connecting to %s:%s" % (random_ip, random_port)) self.all_ips.append((random_ip, random_port)) # start listners wan.sendline('ip addr add %s/32 dev %s' % (random_ip, wan.iface_dut)) wan.expect(prompt) random_rate = randint(1, 1024) random_size = randint(int(1 * random_rate * mintime), int(1024 * random_rate * maxtime)) args = (self.socat_recv, random_port, random_ip, self.payload, random_rate) wan.sendline( "nohup socat %s:%s,bind=%s system:'(echo -n %s; head /dev/zero) | pv -L %sk' &" % args) print( "nohup socat %s:%s,bind=%s system:'(echo -n %s; head /dev/zero) | pv -L %sk' &" % args) wan.expect(prompt) args = (self.payload, random_size, random_rate, self.socat_send, random_ip, random_port) lan.sendline( "nohup socat system:'(echo -n %s; head -c %s /dev/zero) | pv -L %sk' %s:%s:%s &" % args) print( "nohup socat system:'(echo -n %s; head -c %s /dev/zero) | pv -L %sk' %s:%s:%s &" % args) lan.expect(prompt) self.all_conns.append( (random_size, random_rate, random_ip, random_port)) return (random_size, random_rate, random_ip, random_port)
def runTest(self): #for d in [wan, lan]: #d.sendline('apt-get update && apt-get -o Dpkg::Options::="--force-confnew" -y install socat pv') #d.expect(prompt) sz, rate, ip, port = self.startSingleFlow() print("started UDP to %s:%s sz = %s, rate = %sk" % (ip, port, sz, rate)) time = sz / (rate * 1024) print("time should be ~%s" % time) self.check_and_clean_ips() lan.sendline('fg') lan.expect(prompt, timeout=time + 10) # TODO: make this a function that's more robust board.get_pp_dev().sendline( 'cat /proc/net/nf_conntrack | grep dst=%s.*dport=%s' % (ip, port)) board.get_pp_dev().expect(prompt) self.recover()
def runTest(self): install_hping3(lan) wan_ip = wan.get_interface_ipaddr(wan.iface_dut) wan.sendline('nc -lvu %s 565' % wan_ip) wan.expect_exact('nc -lvu %s 565' % wan_ip) board.collect_stats(stats=['mpstat']) # dest ip and port are fixed, random src port, fixed src ip, 100 us between lan.sendline('hping3 -2 -c %s -d 120 -S -w 64 -p 445 -i %s %s' % (self.conns, self.conn_rate, wan_ip)) lan.expect('HPING') self.max_conns = 0 for not_used in range(10): self.max_conns = max(self.max_conns, board.get_nf_conntrack_conn_count()) board.get_proc_vmstat() lan.expect(pexpect.TIMEOUT, timeout=3) board.expect(pexpect.TIMEOUT, timeout=3) board.touch() self.recover()
def runTest(self): board.sendcontrol('c') board.expect(board.prompt) board.sendline('logread -f &') board.expect(board.prompt) lan.sendline('rm -rf Fedora*') lan.expect(lan.prompt) # TODO: apt-get install bittornado for i in range(10): lan.sendline( "btdownloadheadless 'https://torrent.fedoraproject.org/torrents/Fedora-Games-Live-x86_64-28_Beta.torrent'" ) lan.expect('saving:') done = False while not done: lan.expect(pexpect.TIMEOUT, timeout=1) # flush buffer if 0 == lan.expect( ['time left: Download Succeeded!', pexpect.TIMEOUT], timeout=10): print("Finished, restarting....") done = True board.expect(pexpect.TIMEOUT, timeout=5) board.sendline() # keepalive lan.sendcontrol('c') lan.sendcontrol('c') lan.sendcontrol('c') lan.expect(lan.prompt) lan.sendline('rm -rf Fedora*') lan.expect(lan.prompt)
def runTest(self): random.seed(99) for d in [wan, lan]: d.sendline( 'apt-get update && apt-get -o Dpkg::Options::="--force-confnew" -y install socat pv' ) d.expect(prompt) max_time = 0 single_max = 45 board.collect_stats(stats=['mpstat']) # TODO: query interfaces but this is OK for now for i in range(self.conns): board.get_nf_conntrack_conn_count() board.touch() print("Starting connection %s" % i) sz, rate, ip, port = self.startSingleFlow(maxtime=single_max) print("started flow to %s:%s sz = %s, rate = %sk" % (ip, port, sz, rate)) max_time = max(max_time, sz / (rate * 1024)) self.check_and_clean_ips() print("waiting max time of %ss" % max_time) start = time.time() while time.time() - start < max_time + 5: lan.sendline('wait') lan.expect_exact('wait') lan.expect([pexpect.TIMEOUT] + prompt, timeout=5) lan.sendcontrol('c') lan.expect(prompt) self.check_and_clean_ips() board.get_nf_conntrack_conn_count() board.touch() self.recover()
def runTest(self): board.sendline('\nuci delete network.lan.ip6addr') board.expect('uci ') board.expect(prompt) board.sendline('uci delete network.wan.ip6addr') board.expect(prompt) board.sendline('ip -6 addr delete 5aaa::1/64 dev eth0') board.expect(prompt) board.sendline('uci commit network') board.expect(prompt) board.network_restart() # Lan-side Device lan.sendline('\nip -6 addr del 4aaa::6/64 dev eth1') lan.expect('ip -6') lan.expect(prompt) lan.sendline('ip -6 route del default') lan.expect(prompt) # Wan-side Device wan.sendline('\nip -6 addr del 5aaa::6/64 dev eth1') wan.expect('ip -6') wan.expect(prompt) wan.sendline('ip -6 route del default') wan.expect(prompt) time.sleep(10)