def test_tcpdump_pcap(self): """Check tcpdump creates pcap output""" self.ping_all_when_learned() from_host = self.net.hosts[0] to_host = self.net.hosts[1] tcpdump_filter = ('icmp') pcap_file = os.path.join(self.tmpdir, 'out.pcap') tcpdump_helper = TcpdumpHelper( to_host, tcpdump_filter, [lambda: from_host.cmd('ping -c3 %s' % to_host.IP())], pcap_out=pcap_file, packets=None) tcpdump_helper.execute() self._terminate_with_zero(tcpdump_helper) result = from_host.cmd('tcpdump -en -r %s' % pcap_file) self.assertEqual(result.count('ICMP echo reply'), 3, 'three icmp echo replies')
def test_tcpdump_execute(self): """Check tcpdump filter monitors ping using execute""" self.ping_all_when_learned() from_host = self.net.hosts[0] to_host = self.net.hosts[1] tcpdump_filter = ('icmp') tcpdump_helper = TcpdumpHelper(to_host, tcpdump_filter, [ lambda: from_host.cmd('ping -c1 %s' % to_host.IP())]) tcpdump_txt = tcpdump_helper.execute() self.assertTrue(re.search( '%s: ICMP echo request' % to_host.IP(), tcpdump_txt)) self._terminate_with_zero(tcpdump_helper)