summaryrefslogtreecommitdiffstats
path: root/test/vpp_pg_interface.py
diff options
context:
space:
mode:
authorKlement Sekera <ksekera@cisco.com>2016-09-29 14:43:44 +0200
committerDave Barach <openvpp@barachs.net>2016-12-07 19:54:12 +0000
commit0e3c0de1ed87f3cdf16e26e05e39ea6eebeafb18 (patch)
treedd5f11c08311a95ce56eb8c33d4e8681940bf877 /test/vpp_pg_interface.py
parentd171d48edc1672564db8bb920586b8ea220df14c (diff)
BFD: basic asynchronous session up/down
This is a work-in-progress basic BFD session handling. Only asynchronous mode is supported at the moment. Setting the session flags doesn't work. Change-Id: Idba27f721b5c35be5a66a6d202a63d23ff7ecf6f Signed-off-by: Klement Sekera <ksekera@cisco.com>
Diffstat (limited to 'test/vpp_pg_interface.py')
-rw-r--r--test/vpp_pg_interface.py40
1 files changed, 38 insertions, 2 deletions
diff --git a/test/vpp_pg_interface.py b/test/vpp_pg_interface.py
index 533c4603a2e..012f5768353 100644
--- a/test/vpp_pg_interface.py
+++ b/test/vpp_pg_interface.py
@@ -1,10 +1,10 @@
import os
import time
-from scapy.utils import wrpcap, rdpcap
+from scapy.utils import wrpcap, rdpcap, PcapReader
from vpp_interface import VppInterface
from scapy.layers.l2 import Ether, ARP
-from scapy.layers.inet6 import IPv6, ICMPv6ND_NS, ICMPv6ND_NA, \
+from scapy.layers.inet6 import IPv6, ICMPv6ND_NS, ICMPv6ND_NA,\
ICMPv6NDOptSrcLLAddr, ICMPv6NDOptDstLLAddr
from util import ppp
@@ -93,6 +93,7 @@ class VppPGInterface(VppInterface):
pass
# FIXME this should be an API, but no such exists atm
self.test.vapi.cli(self.capture_cli)
+ self._pcap_reader = None
def add_stream(self, pkts):
"""
@@ -132,6 +133,41 @@ class VppPGInterface(VppInterface):
return []
return output
+ def wait_for_packet(self, timeout):
+ """
+ Wait for next packet captured with a timeout
+
+ :param timeout: How long to wait for the packet
+
+ :returns: Captured packet if no packet arrived within timeout
+ :raises Exception: if no packet arrives within timeout
+ """
+ limit = time.time() + timeout
+ if self._pcap_reader is None:
+ self.test.logger.debug("Waiting for the capture file to appear")
+ while time.time() < limit:
+ if os.path.isfile(self.out_path):
+ break
+ time.sleep(0) # yield
+ if os.path.isfile(self.out_path):
+ self.test.logger.debug("Capture file appeared after %fs" %
+ (time.time() - (limit - timeout)))
+ self._pcap_reader = PcapReader(self.out_path)
+ else:
+ self.test.logger.debug("Timeout - capture file still nowhere")
+ raise Exception("Packet didn't arrive within timeout")
+
+ self.test.logger.debug("Waiting for packet")
+ while time.time() < limit:
+ p = self._pcap_reader.recv()
+ if p is not None:
+ self.test.logger.debug("Packet received after %fs",
+ (time.time() - (limit - timeout)))
+ return p
+ time.sleep(0) # yield
+ self.test.logger.debug("Timeout - no packets received")
+ raise Exception("Packet didn't arrive within timeout")
+
def create_arp_req(self):
"""Create ARP request applicable for this interface"""
return (Ether(dst="ff:ff:ff:ff:ff:ff", src=self.remote_mac) /