X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=test%2Futil.py;h=e21fdb810260d285940ff6e32ca7b765de4a9ae8;hb=5993a34a12cb41f83ced26893b977b4eb2947708;hp=c86d602d79250762b5006bc0cff3480042d70999;hpb=2f1563129ad8d34d365f5ef8620ff76ff7b08e70;p=vpp.git diff --git a/test/util.py b/test/util.py index c86d602d792..e21fdb81026 100644 --- a/test/util.py +++ b/test/util.py @@ -2,9 +2,9 @@ import abc import ipaddress +import logging import socket from socket import AF_INET6 -import six import sys import os.path @@ -20,6 +20,10 @@ from scapy.utils6 import in6_mactoifaceid from io import BytesIO from vpp_papi import mac_pton +# Set up an empty logger for the testcase that can be overridden as necessary +null_logger = logging.getLogger('VppTestCase.util') +null_logger.addHandler(logging.NullHandler()) + def ppp(headline, packet): """ Return string containing the output of scapy packet.show() call. """ @@ -108,7 +112,7 @@ def check_core_path(logger, core_path): " current core pattern is: %s" % corefmt) -class NumericConstant(object): +class NumericConstant: desc_dict = {} @@ -127,7 +131,7 @@ class NumericConstant(object): return "" -class Host(object): +class Host: """ Generic test host "connected" to VPPs interface. """ @property @@ -199,19 +203,6 @@ class Host(object): self._ip6_ll = ip6_ll -class ForeignAddressFactory(object): - count = 0 - prefix_len = 24 - net_template = '10.10.10.{}' - net = net_template.format(0) + '/' + str(prefix_len) - - def get_ip4(self): - if self.count > 255: - raise Exception("Network host address exhaustion") - self.count += 1 - return self.net_template.format(self.count) - - class L4_Conn(): """ L4 'connection' tied to two VPP interfaces """ @@ -272,20 +263,7 @@ class L4_CONN_SIDE: L4_CONN_SIDE_ONE = 1 -class LoggerWrapper(object): - def __init__(self, logger=None): - self._logger = logger - - def debug(self, *args, **kwargs): - if self._logger: - self._logger.debug(*args, **kwargs) - - def error(self, *args, **kwargs): - if self._logger: - self._logger.error(*args, **kwargs) - - -def fragment_rfc791(packet, fragsize, _logger=None): +def fragment_rfc791(packet, fragsize, logger=null_logger): """ Fragment an IPv4 packet per RFC 791 :param packet: packet to fragment @@ -293,7 +271,6 @@ def fragment_rfc791(packet, fragsize, _logger=None): :note: IP options are not supported :returns: list of fragments """ - logger = LoggerWrapper(_logger) logger.debug(ppp("Fragmenting packet:", packet)) packet = packet.__class__(scapy.compat.raw(packet)) # recalc. all values if len(packet[IP].options) > 0: @@ -325,13 +302,13 @@ def fragment_rfc791(packet, fragsize, _logger=None): p[IP].frag = fo + nfb del p[IP].chksum - more_fragments = fragment_rfc791(p, fragsize, _logger) + more_fragments = fragment_rfc791(p, fragsize, logger) pkts.extend(more_fragments) return pkts -def fragment_rfc8200(packet, identification, fragsize, _logger=None): +def fragment_rfc8200(packet, identification, fragsize, logger=null_logger): """ Fragment an IPv6 packet per RFC 8200 :param packet: packet to fragment @@ -339,7 +316,6 @@ def fragment_rfc8200(packet, identification, fragsize, _logger=None): :note: IP options are not supported :returns: list of fragments """ - logger = LoggerWrapper(_logger) packet = packet.__class__(scapy.compat.raw(packet)) # recalc. all values if len(packet) <= fragsize: return [packet]