MCPcopy Create free account
hub / github.com/FDio/vpp / wait_for_packet

Method wait_for_packet

test/vpp_pg_interface.py:501–561  ·  view source on GitHub ↗

Wait for next packet captured with a timeout :param timeout: How long to wait for the packet :returns: Captured packet if packet arrived within timeout :raises CaptureTimeoutError: if no packet arrives within timeout

(self, timeout, filter_out_fn=is_ipv6_misc)

Source from the content-addressed store, hash-verified

499 return enough_data
500
501 def wait_for_packet(self, timeout, filter_out_fn=is_ipv6_misc):
502 """
503 Wait for next packet captured with a timeout
504
505 :param timeout: How long to wait for the packet
506
507 :returns: Captured packet if packet arrived within timeout
508 :raises CaptureTimeoutError: if no packet arrives within timeout
509 """
510 deadline = time.time() + timeout
511 if self._pcap_reader is None:
512 if not os.path.isfile(self.out_path):
513 remaining = deadline - time.time()
514 if remaining <= 0 or not self._wait_for_file_inotify(
515 self.out_path, remaining
516 ):
517 raise CaptureTimeoutError(
518 "Capture file %s did not appear within timeout" % self.out_path
519 )
520 while time.time() < deadline:
521 try:
522 self._pcap_reader = PcapReader(self.out_path)
523 break
524 except:
525 self.test.logger.debug(
526 "Exception in scapy.PcapReader(%s): %s"
527 % (self.out_path, format_exc())
528 )
529 if not self._pcap_reader:
530 raise CaptureTimeoutError(
531 "Capture file %s did not appear within timeout" % self.out_path
532 )
533
534 poll = False
535 if timeout > 0:
536 self.test.logger.debug("Waiting for packet")
537 else:
538 poll = True
539 self.test.logger.debug("Polling for packet")
540 while time.time() < deadline or poll:
541 if not self.verify_enough_packet_data_in_pcap():
542 self._test.sleep(0) # yield
543 poll = False
544 continue
545 p = self._pcap_reader.recv()
546 if p is not None:
547 if filter_out_fn is not None and filter_out_fn(p):
548 self.test.logger.debug(
549 "Packet received after %ss was filtered out"
550 % (time.time() - (deadline - timeout))
551 )
552 else:
553 self.test.logger.debug(
554 "Packet received after %fs"
555 % (time.time() - (deadline - timeout))
556 )
557 return p
558 self._test.sleep(0) # yield

Callers 15

wait_for_cflow_packetMethod · 0.45
recvMethod · 0.45
resolve_arpMethod · 0.45
resolve_ndpMethod · 0.45
wait_for_bfd_packetFunction · 0.45
test_session_up_by_ipMethod · 0.45
test_echo_looped_backMethod · 0.45
test_echoMethod · 0.45
test_echo_failMethod · 0.45
test_echo_stopMethod · 0.45
test_stale_echoMethod · 0.45

Calls 5

CaptureTimeoutErrorClass · 0.85
recvMethod · 0.80
sleepMethod · 0.45

Tested by 15

wait_for_cflow_packetMethod · 0.36
wait_for_bfd_packetFunction · 0.36
test_session_up_by_ipMethod · 0.36
test_echo_looped_backMethod · 0.36
test_echoMethod · 0.36
test_echo_failMethod · 0.36
test_echo_stopMethod · 0.36
test_stale_echoMethod · 0.36
test_session_up_by_ipMethod · 0.36
test_echo_looped_backMethod · 0.36