def recover(self): wan.sendcontrol('c') wan.expect(prompt) wan.sendline('killall -9 socat pv') wan.expect_exact('killall -9 socat pv') wan.expect(prompt) for d in [wan, lan]: d.sendcontrol('c') d.expect(prompt) d.sendline('pgrep -f d1:ad2:id20') d.expect_exact('pgrep -f d1:ad2:id20') d.expect(prompt) d.sendline('pkill -9 -f d1:ad2:id20') d.expect_exact('pkill -9 -f d1:ad2:id20') d.expect(prompt) d.sendline('killall -9 socat') d.expect_exact('killall -9 socat') d.expect(prompt) for ip, port in self.all_ips: self.cleanup_ip(ip) # this needs to be here because we need to make sure mpstat is cleaned up board.parse_stats(dict_to_log=self.logged) print("mpstat cpu usage = %s" % self.logged['mpstat']) self.result_message = "BitTorrent test with %s connections, cpu usage = %s" % ( self.conns, self.logged['mpstat'])
def cleanup_ip(self, ip): wan.sendline('ip addr del %s/32 dev eth1' % ip) wan.expect_exact('ip addr del %s/32 dev eth1' % ip) wan.expect(prompt) wan.sendline('pkill -9 -f socat.*bind=%s' % ip) wan.expect(prompt) lan.sendline('pkill -9 -f socat.*UDP4-SENDTO:%s' % ip) 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 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 recover(self): wan.sendcontrol('c') wan.expect(prompt) wan.sendline('killall -9 socat pv') wan.expect_exact('killall -9 socat pv') wan.expect(prompt) for d in [wan, lan]: d.sendcontrol('c') d.expect(prompt) d.sendline('pgrep -f d1:ad2:id20') d.expect_exact('pgrep -f d1:ad2:id20') d.expect(prompt) d.sendline('pkill -9 -f d1:ad2:id20') d.expect_exact('pkill -9 -f d1:ad2:id20') d.expect(prompt) d.sendline('killall -9 socat') d.expect_exact('killall -9 socat') d.expect(prompt) for ip, port in self.all_ips: self.cleanup_ip(ip)
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): if not wan: msg = 'No WAN Device defined, skipping test_create_session.' lib.common.test_msg(msg) self.skipTest(msg) wan_ip = wan.get_interface_ipaddr("eth0") import devices # this should fail, as "DebianBoxNonExistent" is not (yet) a device try: kwargs ={ 'name':"wan_test_calls_fail", 'ipaddr':wan_ip, 'port':22, 'color': 'magenta' } self.session = devices.get_device("DebianBoxNonExistent", **kwargs) except: pass else: assert self.session is None,"Test Failed on wrong class name" print("Failed to create session on wrong class name (expected) PASS") # this must fail, as "169.254.12.18" is not a valid ip try: kwargs ={ 'name':"wan_test_ip_fail", 'ipaddr':"169.254.12.18", 'port':22, 'color': 'cyan' } self.session = devices.get_device("DebianBox", **kwargs) except: pass else: assert self.session is None,"Test Failed on wrong IP" print("Failed to create session on wrong IP (expected) PASS") # this must fail, as 50 is not a valid port try: kwargs ={ 'name':"wan_test_port_fail", 'ipaddr':wan_ip, 'port':50, 'color': 'red' } self.session = devices.get_device("DebianBox", **kwargs) except: pass else: assert self.session is None,"Test Failed on wrong port" print("Failed to create session on wrong port (expected) PASS") # this must fail, close but no cigar try: kwargs ={ 'name':"wan_test_type_fail", 'ipaddr':wan_ip, 'port':50, 'color': 'red' } self.session = devices.get_device("debina", **kwargs) except: pass else: assert self.session is None,"Test Failed on misspelled class name" print("Failed to create session on misspelled class name (expected) PASS") # this should pass try: kwargs ={ 'name':"correct_wan_parms", 'ipaddr':wan_ip, 'port':'22', 'color': 'yellow' } self.session = devices.get_device("debian", **kwargs) except: assert 0, "Failed to create session, Test FAILED!" else: assert self.session is not None,"Test Failed on correct paramters!!" print("Session created successfully") # is the session really logged onto the wan? wan.sendline() wan.expect(wan.prompt) wan.sendline("ip a") wan.expect_exact("ip a") wan.expect(wan.prompt) w = wan.before self.session.sendline() self.session.expect(self.session.prompt) self.session.sendline("ip a") self.session.expect_exact("ip a") self.session.expect(self.session.prompt) s = self.session.before assert w == s, "Interfaces differ!!! Test Failed" self.session.sendline("exit") print("Test passed")