# Path: pyisis/lib/util.py
# def as_string (cobj):
# def cast_as (bufptr, ctype):
# def copy_as (s, ctype):
# def copy_cobj (s, ctype):
# def memcpy (dst, src):
#     def _chr3 (val):
#     def buffer3 (val, off=None, sz=None):
#     def tlvrdb (val):
#     def buffer3 (val, off=None, l=None):
#     def stringify3 (b):
# def debug_exception ():
#     def __init__ (self):
#     def elapsed (self):
#     def __str__ (self):
#     def __init__ (self, lifetime):
#     def reset (self, lifetime):
#     def expire_at (self):
#     def timeleft (self):
#     def __init__ (self):
#     def __enter__ (self):
#     def __exit__ (self, *args):
#     def held (self):
#     def acquire (self, blocking=True):
#     def release (self):
# def debug_after (count=1):
#     def __enter__ (self):
#     def __exit__ (self, *args):
# class CPUTimer (object):
# class Lifetime (object):
# class QueryLock (object):
# class NoLock (object):


from pyisis.lib.util import chr3, tlvrdb
import logbook
import struct
import sys
    pass


def receiveLSPBufferSize ():
    """ISO10589:2002"""
    return 1492


def originatingLxLSPBufferSize (unused_lindex):
    """ISO10589:2002"""
    return receiveLSPBufferSize()


def get_pdu_class (pkt):
    etype = struct.unpack("!H", pkt[12:14])[0]
    if etype > 1500 and etype != 0x8870:
        return None
    if pkt[14:16] != "\xfe\xfe" or (pkt[16] != "\x00" and pkt[16] != "\x03"):
        return None
    pkt = pkt[17:]
    if tlvrdb(pkt[CLNS_HDR_IDRP]) != CLNS_IDRP_ISIS:
        return None
    if ((tlvrdb(pkt[CLNS_HDR_VERSION]) != CLNS_VERSION or
         tlvrdb(pkt[CLNS_HDR_VERSION2]) != CLNS_VERSION2 or
         tlvrdb(pkt[CLNS_HDR_SYSID_LEN]) not in (0, 6))):

        # XXX this represents malformed packet at this point.
        # and exception may be better here.
        return None


# Path: pyisis/lib/util.py
# def as_string (cobj):
# def cast_as (bufptr, ctype):
# def copy_as (s, ctype):
# def copy_cobj (s, ctype):
# def memcpy (dst, src):
#     def _chr3 (val):
#     def buffer3 (val, off=None, sz=None):
#     def tlvrdb (val):
#     def buffer3 (val, off=None, l=None):
#     def stringify3 (b):
# def debug_exception ():
#     def __init__ (self):
#     def elapsed (self):
#     def __str__ (self):
#     def __init__ (self, lifetime):
#     def reset (self, lifetime):
#     def expire_at (self):
#     def timeleft (self):
#     def __init__ (self):
#     def __enter__ (self):
#     def __exit__ (self, *args):
#     def held (self):
#     def acquire (self, blocking=True):
#     def release (self):
# def debug_after (count=1):
#     def __enter__ (self):
#     def __exit__ (self, *args):
# class CPUTimer (object):
# class Lifetime (object):
# class QueryLock (object):
# class NoLock (object):


# Path: pyisis/clns.py
from pyisis.lib.util import chr3, tlvrdb
import logbook
import struct
import sys

    pass


def receiveLSPBufferSize ():
    """ISO10589:2002"""
    return 1492


def originatingLxLSPBufferSize (unused_lindex):
    """ISO10589:2002"""
    return receiveLSPBufferSize()


def get_pdu_class (pkt):
    etype = struct.unpack("!H", pkt[12:14])[0]
    if etype > 1500 and etype != 0x8870:
        return None
    if pkt[14:16] != "\xfe\xfe" or (pkt[16] != "\x00" and pkt[16] != "\x03"):
        return None
    pkt = pkt[17:]
    if tlvrdb(pkt[CLNS_HDR_IDRP]) != CLNS_IDRP_ISIS:
        return None
    if ((tlvrdb(pkt[CLNS_HDR_VERSION]) != CLNS_VERSION or
         tlvrdb(pkt[CLNS_HDR_VERSION2]) != CLNS_VERSION2 or
         tlvrdb(pkt[CLNS_HDR_SYSID_LEN]) not in (0, 6))):

        # XXX this represents malformed packet at this point.
        # and exception may be better here.
        return None


    pdutype = tlvrdb(pkt[CLNS_HDR_PDUTYPE]) & 0x1f