from scapy.layers.inet6 import IPv6, ICMPv6ND_NS, ICMPv6ND_NA,\
ICMPv6NDOptSrcLLAddr, ICMPv6NDOptDstLLAddr, ICMPv6ND_RA, RouterAlert, \
IPv6ExtHdrHopByHop
-from util import ppp, ppc
+from util import ppp, ppc, UnexpectedPacketError
from scapy.utils6 import in6_getnsma, in6_getnsmac, in6_ismaddr
remaining_time -= elapsed_time
if capture:
self.generate_debug_aid("count-mismatch")
+ if len(capture) > 0 and 0 == expected_count:
+ rem = f"\n{remark}" if remark else ""
+ raise UnexpectedPacketError(
+ capture[0],
+ f"\n({len(capture)} packets captured in total){rem}")
raise Exception("Captured packets mismatch, captured %s packets, "
"expected %s packets on %s" %
(len(capture.res), expected_count, name))
else:
raise Exception("No packets captured on %s" % name)
- def assert_nothing_captured(self, remark=None, filter_out_fn=is_ipv6_misc):
+ def assert_nothing_captured(self, timeout=1, remark=None,
+ filter_out_fn=is_ipv6_misc):
""" Assert that nothing unfiltered was captured on interface
:param remark: remark printed into debug logs
if os.path.isfile(self.out_path):
try:
capture = self.get_capture(
- 0, remark=remark, filter_out_fn=filter_out_fn)
+ 0, timeout=timeout, remark=remark,
+ filter_out_fn=filter_out_fn)
if not capture or len(capture.res) == 0:
# junk filtered out, we're good
return
pass
self.generate_debug_aid("empty-assert")
if remark:
- raise AssertionError(
- "Non-empty capture file present for interface %s (%s)" %
- (self.name, remark))
+ raise UnexpectedPacketError(
+ capture[0],
+ f" ({len(capture)} packets captured in total) ({remark})")
else:
- raise AssertionError("Capture file present for interface %s" %
- self.name)
+ raise UnexpectedPacketError(
+ capture[0], f" ({len(capture)} packets captured in total)")
def wait_for_pg_stop(self):
# wait till packet-generator is stopped