Beispiel #1
0
	def __init__ (self,data):
		self.type = PeerType(ord(data[2]))
		self.flag = PeerFlag(ord(data[3]))
		self.distinguisher = unpack('!L',data[4:8])[0]
		self.asn = unpack('!L',data[28:32])[0]
		self.id = IPv4.unpack(data[32:36])

		if self.flag.ipv4(): self.peer_address = IPv4.unpack(data[24:28])
		if self.flag.ipv6(): self.peer_address = IPv6.unpack(data[12:28])
Beispiel #2
0
    def __init__(self, data):
        self.type = PeerType(ord(data[2]))
        self.flag = PeerFlag(ord(data[3]))
        self.distinguisher = unpack('!L', data[4:8])[0]
        self.asn = unpack('!L', data[28:32])[0]
        self.id = IPv4.unpack(data[32:36])

        if self.flag.ipv4(): self.peer_address = IPv4.unpack(data[24:28])
        if self.flag.ipv6(): self.peer_address = IPv6.unpack(data[12:28])
Beispiel #3
0
    def unpack(cls, data, length):
        sid = IPv6.unpack(data[1:17])
        behavior = unpack("!H", data[18:20])[0]
        subsubtlvs = []

        data = data[21:]
        while data:
            code = data[0]
            length = unpack("!H", data[1:3])[0]
            if code in cls.registered_subsubtlvs:
                subsubtlv = klass = cls.registered_subsubtlvs[code].unpack(
                    data[3:length + 3], length)
            else:
                subsubtlv = GenericSrv6ServiceDataSubSubTlv(
                    code, data[3:length + 3])
            subsubtlvs.append(subsubtlv)
            data = data[length + 3:]

        return cls(sid=sid, behavior=behavior, subsubtlvs=subsubtlvs)
Beispiel #4
0
 def unpack(data):
     ip, bit = unpack('!16sH', data[2:20])
     return TrafficNextHopIPv6IETF(IPv6.ntop(ip), bool(bit & 0x01),
                                   data[:20])
Beispiel #5
0
def prefix_sid_srv6(tokeniser):
    value = tokeniser()
    if value != "(":
        raise Exception("expect '(', but received '%s'" % value)

    service_type = tokeniser()
    if service_type not in ["l3-service", "l2-service"]:
        raise Exception(
            "expect 'l3-service' or 'l2-service', but received '%s'" % value)

    sid = IPv6.unpack(IPv6.pton(tokeniser()))
    behavior = 0xFFFF
    subtlvs = []
    subsubtlvs = []
    value = tokeniser()
    if value != ")":
        base = 10 if not value.startswith("0x") else 16
        behavior = int(value, base)
        value = tokeniser()
        if value == "[":
            values = []
            for i in range(6):
                if i != 0:
                    value = tokeniser()
                    if value != ",":
                        raise Exception("expect ',', but received '%s'" %
                                        value)
                value = tokeniser()
                base = 10 if not value.startswith("0x") else 16
                values.append(int(value, base))

            value = tokeniser()
            if value != "]":
                raise Exception("expect ']', but received '%s'" % value)

            value = tokeniser()

            subsubtlvs.append(
                Srv6SidStructure(
                    loc_block_len=values[0],
                    loc_node_len=values[1],
                    func_len=values[2],
                    arg_len=values[3],
                    tpose_len=values[4],
                    tpose_offset=values[5],
                ))

    subtlvs.append(
        Srv6SidInformation(
            sid=sid,
            behavior=behavior,
            subsubtlvs=subsubtlvs,
        ))

    if value != ")":
        raise Exception("expect ')', but received '%s'" % value)

    if service_type == "l3-service":
        return PrefixSid([Srv6L3Service(subtlvs=subtlvs)])
    elif service_type == "l2-service":
        return PrefixSid([Srv6L2Service(subtlvs=subtlvs)])