3 from abc import abstractmethod, ABCMeta
4 from cStringIO import StringIO
7 def ppp(headline, packet):
8 """ Return string containing the output of scapy packet.show() call. """
10 old_stdout = sys.stdout
14 sys.stdout = old_stdout
18 def ppc(headline, capture, limit=10):
19 """ Return string containing ppp() printout for a capture.
21 :param headline: printed as first line of output
22 :param capture: packets to print
23 :param limit: limit the print to # of packets
28 if limit < len(capture):
29 tail = "\nPrint limit reached, %s out of %s packets printed" % (
32 body = "".join([ppp("Packet #%s:" % count, p)
33 for count, p in zip(range(0, limit), capture)])
34 return "%s\n%s%s" % (headline, body, tail)
37 class NumericConstant(object):
38 __metaclass__ = ABCMeta
43 def __init__(self, value):
53 if self._value in self.desc_dict:
54 return self.desc_dict[self._value]
59 """ Generic test host "connected" to VPPs interface. """
74 return socket.inet_pton(socket.AF_INET, self._ip4)
81 def __init__(self, mac=None, ip4=None, ip6=None):