예제 #1
0
        else:
            return True

    # An example of a filter function
    @staticmethod
    def filter_non_ipv4(buf):
        eth_typ = struct.unpack_from(">H", buf, 12)[0]
        if eth_typ != ETH_PROTO_IPV4:
            return False
        return True


if __name__ == "__main__":
    import timeit

    log.conf_logger("DEBUG")
    logger.info("* Run tests.")
    buf = bytearray(4096)  # CPU cache slot size
    sock = PacketSocket(buf, "lo")
    sock.bind()
    buf_shallow = sock.get_buf()
    assert id(buf_shallow) == id(buf)
    buf_copy = sock.get_buf(deep_copy=True)
    assert id(buf_copy) != id(buf)

    sock._buf[:10] = b"a" * 10

    def dummpy_filter(buf):
        if buf[:10] != b"a" * 10:
            return False
        return True
예제 #2
0
        logger = logging.getLogger(__name__)
        
        a = time.time()
        term = self.Terminated
        nb = 0
        while not term.value:
            nb += 1
            # logger.info("nb : %i" % nb)

        logger.info("nb : %i - time : %d" % (nb, time.time() - a))
        # print "-%i-" % nb
        # print "time : ", time.time() - a


if __name__ == "__main__":
    log.conf_logger()
    logger = logging.getLogger(__name__)

    # m = ModP()

    # logger.info("start")

    # m.start()
    # time.sleep(5)

    # m.stop()
    # m.join()

    # logger.info("stop")

import rawsock_helpers as rsh
from common import (
    BUFFER_SIZE,
    CODER_LOG_LEVEL,
    FIELD,
    INIT_REDUNDANCY,
    IO_SLEEP,
    META_DATA_LEN,
    MTU,
    SYMBOL_SIZE,
    SYMBOLS,
    UDP_PORT_DATA,
    UDP_PORT_OAM,
)

log.conf_logger(CODER_LOG_LEVEL)
logger = log.logger


def run_recoder(ifce, action, dst_mac):

    buf = bytearray(BUFFER_SIZE)
    udp_cnt = 0

    if dst_mac:
        logger.info(
            "The destination MAC address of all frames are changed to %s" %
            dst_mac)

    try:
        logger.info("Create the raw packet socket.")