Helper method to get capture and filter it
(self, filter_out_fn=is_ipv6_misc)
| 277 | self._out_assert_counter += 1 |
| 278 | |
| 279 | def _get_capture(self, filter_out_fn=is_ipv6_misc): |
| 280 | """Helper method to get capture and filter it""" |
| 281 | try: |
| 282 | self.wait_for_pg_stop() |
| 283 | # "show packet-generator" CLI is not mp_safe, so VPP parks all |
| 284 | # worker threads at a barrier before executing it. By the time |
| 285 | # the CLI returns "stopped", every packet that was injected by |
| 286 | # the packet-generator has fully traversed the graph (run to |
| 287 | # completion). If any of those packets reached a pg output |
| 288 | # interface, VPP's pg_output node has already called |
| 289 | # pcap_write() which issues a write() syscall — making the |
| 290 | # capture file visible in the kernel VFS immediately (no fsync |
| 291 | # needed; stat() checks the dentry cache, not the block |
| 292 | # device). Therefore a single os.path.isfile() after pg stop |
| 293 | # is sufficient: the file is either here now or no packets |
| 294 | # were captured. |
| 295 | if not os.path.isfile(self.out_path): |
| 296 | self.test.logger.debug( |
| 297 | "Capture file %s not found after pg stop" % self.out_path |
| 298 | ) |
| 299 | return None |
| 300 | self.link_pcap_file(self.out_path, "out", self.out_history_counter) |
| 301 | output = rdpcap(self.out_path) |
| 302 | self.test.logger.debug(f"Capture has {len(output.res)} packets") |
| 303 | except: |
| 304 | self.test.logger.debug( |
| 305 | "Exception in scapy.rdpcap (%s): %s" % (self.out_path, format_exc()) |
| 306 | ) |
| 307 | return None |
| 308 | before = len(output.res) |
| 309 | if filter_out_fn: |
| 310 | output.res = [p for p in output.res if not filter_out_fn(p)] |
| 311 | removed = before - len(output.res) |
| 312 | if removed: |
| 313 | self.test.logger.debug( |
| 314 | "Filtered out %s packets from capture (returning %s)" |
| 315 | % (removed, len(output.res)) |
| 316 | ) |
| 317 | return output |
| 318 | |
| 319 | def get_capture( |
| 320 | self, expected_count=None, remark=None, timeout=None, filter_out_fn=is_ipv6_misc |