예제 #1
0
    def from_bytes(cls, bytes):
        self = cls()

        d = {}

        idx = 0
        for kind in ('withdraw', 'pathattr'):
            plen, = struct.unpack_from('!H', bytes, idx)
            idx += 2
            d[kind] = bytes[idx:idx+plen]
            idx += plen

        self.nlri = nlri.parse(bytes[idx:])
        self.withdraw = nlri.parse(d['withdraw'])

        self.pathattr = OD()

        idx = 0
        bytes = d['pathattr']

        while idx < len(bytes):

            used, pattr = pathattr.decode(bytes, idx)
            idx += used
            self.pathattr[pattr.type] = pattr

        return self
예제 #2
0
파일: pathattr.py 프로젝트: plajjan/pybgp
    def from_bytes(cls, val):
        afi, safi = struct.unpack_from('!HB', val)

        w = nlri.parse(val[3:], afi, safi)

        v = cls(dict(afi=afi, safi=safi, withdraw=w))

        return v
예제 #3
0
    def from_bytes(cls, val):
        afi, safi = struct.unpack_from('!HB', val)

        w = nlri.parse(val[3:], afi, safi)

        v = cls(dict(afi=afi, safi=safi, withdraw=w))

        return v
예제 #4
0
    def from_bytes(cls, val):
        afi, safi, nhlen = struct.unpack_from('!HBB', val)
        fmt = '%dsB' % (nhlen, )
        nh, reserved = struct.unpack_from(fmt, val, 4)

        if afi == 1 and safi == 128:
            # vpnv4
            rdlo, rdhi, nhip = struct.unpack('!II4s', nh)
            nh = socket.inet_ntoa(nhip)

        n = nlri.parse(val[5 + nhlen:], afi, safi)

        v = cls(dict(afi=afi, safi=safi, nh=nh, nlri=n))

        if reserved:
            # probably useless, but pass it through anyway
            v.reserved = reserved

        return v
예제 #5
0
파일: pathattr.py 프로젝트: plajjan/pybgp
    def from_bytes(cls, val):
        afi, safi, nhlen = struct.unpack_from('!HBB', val)
        fmt = '%dsB' % (nhlen,)
        nh, reserved = struct.unpack_from(fmt, val, 4)

        if afi==1 and safi==128:
            # vpnv4
            rdlo, rdhi, nhip = struct.unpack('!II4s', nh)
            nh = socket.inet_ntoa(nhip)

        n = nlri.parse(val[5+nhlen:], afi, safi)

        v = cls(dict(afi=afi, safi=safi, nh=nh, nlri=n))


        if reserved:
            # probably useless, but pass it through anyway
            v.reserved = reserved

        return v