import os
import time
+import socket
from traceback import format_exc
from scapy.utils import wrpcap, rdpcap, PcapReader
from vpp_interface import VppInterface
ICMPv6NDOptSrcLLAddr, ICMPv6NDOptDstLLAddr, ICMPv6ND_RA, RouterAlert, \
IPv6ExtHdrHopByHop
from util import ppp, ppc
-
+from scapy.utils6 import in6_getnsma, in6_getnsmac, in6_ismaddr
+from scapy.utils import inet_pton, inet_ntop
def is_ipv6_misc(p):
""" Is packet one of uninteresting IPv6 broadcasts? """
if p.haslayer(ICMPv6ND_RA):
- return True
+ if in6_ismaddr(p[IPv6].dst):
+ return True
if p.haslayer(IPv6ExtHdrHopByHop):
for o in p[IPv6ExtHdrHopByHop].options:
if isinstance(o, RouterAlert):
self._input_cli = "packet-generator new pcap %s source pg%u name %s" % (
self.in_path, self.pg_index, self.cap_name)
- def enable_capture(self):
- """ Enable capture on this packet-generator interface"""
+ def rotate_out_file(self):
try:
if os.path.isfile(self.out_path):
os.rename(self.out_path,
self._out_file))
except:
pass
+
+ def enable_capture(self):
+ """ Enable capture on this packet-generator interface"""
+ self.rotate_out_file()
# FIXME this should be an API, but no such exists atm
self.test.vapi.cli(self.capture_cli)
self._pcap_reader = None
before = len(output.res)
if filter_out_fn:
output.res = [p for p in output.res if not filter_out_fn(p)]
- removed = len(output.res) - before
+ removed = before - len(output.res)
if removed:
self.test.logger.debug(
"Filtered out %s packets from capture (returning %s)" %
expected_count = \
self.test.get_packet_count_for_if_idx(self.sw_if_index)
based_on = "based on stored packet_infos"
+ if expected_count == 0:
+ raise Exception(
+ "Internal error, expected packet count for %s is 0!" % name)
self.test.logger.debug("Expecting to capture %s(%s) packets on %s" % (
expected_count, based_on, name))
- if expected_count == 0:
- raise Exception(
- "Internal error, expected packet count for %s is 0!" % name)
while remaining_time > 0:
before = time.time()
capture = self._get_capture(remaining_time, filter_out_fn)
if len(capture.res) == expected_count:
# bingo, got the packets we expected
return capture
+ elif expected_count == 0:
+ return None
remaining_time -= elapsed_time
if capture:
raise Exception("Captured packets mismatch, captured %s packets, "
if len(capture.res) == 0:
# junk filtered out, we're good
return
- self.test.logger.error(
- ppc("Unexpected packets captured:", capture))
+ self.test.logger.error(
+ ppc("Unexpected packets captured:", capture))
except:
pass
if remark:
self.test.logger.debug("Waiting for capture file %s to appear, "
"timeout is %ss" % (self.out_path, timeout))
else:
- self.test.logger.debug(
- "Capture file %s already exists" %
- self.out_path)
+ self.test.logger.debug("Capture file %s already exists" %
+ self.out_path)
return True
while time.time() < limit:
if os.path.isfile(self.out_path):
def create_ndp_req(self):
"""Create NDP - NS applicable for this interface"""
- return (Ether(dst="ff:ff:ff:ff:ff:ff", src=self.remote_mac) /
- IPv6(src=self.remote_ip6, dst=self.local_ip6) /
+ nsma = in6_getnsma(inet_pton(socket.AF_INET6, self.local_ip6))
+ d = inet_ntop(socket.AF_INET6, nsma)
+
+ return (Ether(dst=in6_getnsmac(nsma)) /
+ IPv6(dst=d, src=self.remote_ip6) /
ICMPv6ND_NS(tgt=self.local_ip6) /
ICMPv6NDOptSrcLLAddr(lladdr=self.remote_mac))
self.test.logger.info("No ARP received on port %s" %
pg_interface.name)
return
+ self.rotate_out_file()
arp_reply = captured_packet.copy() # keep original for exception
# Make Dot1AD packet content recognizable to scapy
if arp_reply.type == 0x88a8:
self._local_mac = opt.lladdr
self.test.logger.debug(self.test.vapi.cli("show trace"))
# we now have the MAC we've been after
+ self.rotate_out_file()
return
except:
self.test.logger.info(
now = time.time()
self.test.logger.debug(self.test.vapi.cli("show trace"))
+ self.rotate_out_file()
raise Exception("Timeout while waiting for NDP response")