def test_tcpdump_noblock(self):
     """Check tcpdump uses nonblocking next_line"""
     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 -c10 %s' % to_host.IP())],
         blocking=False, packets=None)
     count = 0
     while tcpdump_helper.next_line():
         count = count + 1
         self.assertTrue(count < 10, 'Too many ping results before noblock')
     self._terminate_with_nonzero(tcpdump_helper)
 def test_tcpdump_noblock(self):
     """Check tcpdump uses nonblocking next_line"""
     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 -c10 %s' % to_host.IP())],
         blocking=False, packets=None)
     count = 0
     while tcpdump_helper.next_line():
         count = count + 1
         self.assertTrue(count < 10, 'Too many ping results before noblock')
     self._terminate_with_nonzero(tcpdump_helper)
    def test_tcpdump_nextline(self):
        """Check tcpdump filter monitors ping using next_line"""
        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 -c5 -i2 %s' % to_host.IP())])

        self.assertTrue(re.search('proto ICMP', tcpdump_helper.next_line()))
        next_line = tcpdump_helper.next_line()
        self.assertTrue(re.search('%s: ICMP echo request' % to_host.IP(), next_line), next_line)
        self.assertTrue(re.search('proto ICMP', tcpdump_helper.next_line()))
        next_line = tcpdump_helper.next_line()
        self.assertTrue(re.search('%s: ICMP echo reply' % from_host.IP(), next_line), next_line)
        self.assertFalse(re.search('ICMP', tcpdump_helper.next_line()))
        while tcpdump_helper.next_line():
            pass
        self._terminate_with_zero(tcpdump_helper)
    def test_tcpdump_nextline(self):
        """Check tcpdump filter monitors ping using next_line"""
        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 -c5 -i2 %s' % to_host.IP())])

        self.assertTrue(re.search('proto ICMP', tcpdump_helper.next_line()))
        next_line = tcpdump_helper.next_line()
        self.assertTrue(re.search('%s: ICMP echo request' % to_host.IP(), next_line), next_line)
        self.assertTrue(re.search('proto ICMP', tcpdump_helper.next_line()))
        next_line = tcpdump_helper.next_line()
        self.assertTrue(re.search('%s: ICMP echo reply' % from_host.IP(), next_line), next_line)
        self.assertFalse(re.search('ICMP', tcpdump_helper.next_line()))
        while tcpdump_helper.next_line():
            pass
        self._terminate_with_zero(tcpdump_helper)