Search in sources :

Example 16 with BitArray

use of org.opendaylight.protocol.util.BitArray in project bgpcep by opendaylight.

the class FSIpv4FragmentHandler method serializeFragment.

@Override
protected final byte serializeFragment(final Fragment fragment) {
    final BitArray bs = new BitArray(Byte.SIZE);
    bs.set(DONT_FRAGMENT, fragment.isDoNot());
    bs.set(FIRST_FRAGMENT, fragment.isFirst());
    bs.set(IS_A_FRAGMENT, fragment.isIsA());
    bs.set(LAST_FRAGMENT, fragment.isLast());
    return bs.toByte();
}
Also used : BitArray(org.opendaylight.protocol.util.BitArray)

Example 17 with BitArray

use of org.opendaylight.protocol.util.BitArray in project bgpcep by opendaylight.

the class FSIpv6FragmentHandler method serializeFragment.

@Override
protected final byte serializeFragment(final Fragment fragment) {
    final BitArray bs = new BitArray(Byte.SIZE);
    bs.set(DONT_FRAGMENT, Boolean.FALSE);
    bs.set(FIRST_FRAGMENT, fragment.isFirst());
    bs.set(IS_A_FRAGMENT, fragment.isIsA());
    bs.set(LAST_FRAGMENT, fragment.isLast());
    return bs.toByte();
}
Also used : BitArray(org.opendaylight.protocol.util.BitArray)

Example 18 with BitArray

use of org.opendaylight.protocol.util.BitArray in project bgpcep by opendaylight.

the class SimpleAttributeRegistry method addAttribute.

private void addAttribute(final ByteBuf buffer, final Map<Integer, RawAttribute> attributes) throws BGPDocumentedException {
    final BitArray flags = BitArray.valueOf(buffer.readByte());
    final int type = buffer.readUnsignedByte();
    final int len = (flags.get(EXTENDED_LENGTH_BIT)) ? buffer.readUnsignedShort() : buffer.readUnsignedByte();
    if (!attributes.containsKey(type)) {
        final AttributeParser parser = this.handlers.getParser(type);
        if (parser == null) {
            processUnrecognized(flags, type, buffer, len);
        } else {
            attributes.put(type, new RawAttribute(parser, buffer.readSlice(len)));
        }
    } else {
        LOG.debug("Ignoring duplicate attribute type {}", type);
    }
}
Also used : AttributeParser(org.opendaylight.protocol.bgp.parser.spi.AttributeParser) BitArray(org.opendaylight.protocol.util.BitArray) PeerSpecificParserConstraint(org.opendaylight.protocol.bgp.parser.spi.PeerSpecificParserConstraint)

Example 19 with BitArray

use of org.opendaylight.protocol.util.BitArray in project bgpcep by opendaylight.

the class AbstractBmpPerPeerMessageParser method parsePerPeerHeader.

protected static PeerHeader parsePerPeerHeader(final ByteBuf bytes) {
    Preconditions.checkArgument(bytes.readableBytes() >= PER_PEER_HEADER_SIZE);
    final PeerHeaderBuilder phBuilder = new PeerHeaderBuilder();
    final PeerType peerType = PeerType.forValue(bytes.readByte());
    phBuilder.setType(peerType);
    final BitArray flags = BitArray.valueOf(bytes, FLAGS_SIZE);
    phBuilder.setAdjRibInType(AdjRibInType.forValue(flags.get(L_FLAG_POS) ? 1 : 0));
    phBuilder.setIpv4(!flags.get(V_FLAG_POS));
    switch(peerType) {
        case L3vpn:
            phBuilder.setPeerDistinguisher(new PeerDistinguisher(RouteDistinguisherUtil.parseRouteDistinguisher(bytes)));
            break;
        case Local:
            phBuilder.setPeerDistinguisher(new PeerDistinguisher(ByteArray.readBytes(bytes, PEER_DISTINGUISHER_SIZE)));
            break;
        case Global:
        default:
            bytes.skipBytes(PEER_DISTINGUISHER_SIZE);
            break;
    }
    if (phBuilder.isIpv4()) {
        bytes.skipBytes(Ipv6Util.IPV6_LENGTH - Ipv4Util.IP4_LENGTH);
        phBuilder.setAddress(new IpAddress(Ipv4Util.addressForByteBuf(bytes)));
    } else {
        phBuilder.setAddress(new IpAddress(Ipv6Util.addressForByteBuf(bytes)));
    }
    phBuilder.setAs(new AsNumber(bytes.readUnsignedInt()));
    phBuilder.setBgpId(Ipv4Util.addressForByteBuf(bytes));
    phBuilder.setTimestampSec(new Timestamp(bytes.readUnsignedInt()));
    phBuilder.setTimestampMicro(new Timestamp(bytes.readUnsignedInt()));
    return phBuilder.build();
}
Also used : PeerType(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev171207.PeerType) IpAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress) BitArray(org.opendaylight.protocol.util.BitArray) PeerHeaderBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev171207.peer.header.PeerHeaderBuilder) PeerDistinguisher(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev171207.Peer.PeerDistinguisher) AsNumber(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber) Timestamp(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Timestamp)

Example 20 with BitArray

use of org.opendaylight.protocol.util.BitArray in project bgpcep by opendaylight.

the class AbstractMessageParser method parseObjects.

private List<Object> parseObjects(final ByteBuf bytes) throws PCEPDeserializerException {
    final List<Object> objs = new ArrayList<>();
    while (bytes.isReadable()) {
        if (bytes.readableBytes() < COMMON_OBJECT_HEADER_LENGTH) {
            throw new PCEPDeserializerException("Too few bytes in passed array. Passed: " + bytes.readableBytes() + " Expected: >= " + COMMON_OBJECT_HEADER_LENGTH + ".");
        }
        final int objClass = bytes.readUnsignedByte();
        final byte flagsByte = bytes.readByte();
        final BitArray flags = BitArray.valueOf(flagsByte);
        final int objType = UnsignedBytes.toInt(ByteArray.copyBitsRange(flagsByte, OT_SF_OFFSET, OT_SF_LENGTH));
        final int objLength = bytes.readUnsignedShort();
        if (bytes.readableBytes() < objLength - COMMON_OBJECT_HEADER_LENGTH) {
            throw new PCEPDeserializerException("Too few bytes in passed array. Passed: " + bytes.readableBytes() + " Expected: >= " + objLength + ".");
        }
        // copy bytes for deeper parsing
        final ByteBuf bytesToPass = bytes.readSlice(objLength - COMMON_OBJECT_HEADER_LENGTH);
        final ObjectHeader header = new ObjectHeaderImpl(flags.get(PROCESSED), flags.get(IGNORED));
        if (VendorInformationUtil.isVendorInformationObject(objClass, objType)) {
            final EnterpriseNumber enterpriseNumber = new EnterpriseNumber(bytesToPass.readUnsignedInt());
            final Optional<? extends Object> obj = this.registry.parseVendorInformationObject(enterpriseNumber, header, bytesToPass);
            if (obj.isPresent()) {
                objs.add(obj.get());
            }
        } else {
            // parseObject is required to return null for P=0 errored objects
            final Object o = this.registry.parseObject(objClass, objType, header, bytesToPass);
            if (o != null) {
                objs.add(o);
            }
        }
    }
    return objs;
}
Also used : ObjectHeader(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.ObjectHeader) ArrayList(java.util.ArrayList) EnterpriseNumber(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.iana.rev130816.EnterpriseNumber) Object(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Object) VendorInformationObject(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.vendor.information.objects.VendorInformationObject) BitArray(org.opendaylight.protocol.util.BitArray) ByteBuf(io.netty.buffer.ByteBuf)

Aggregations

BitArray (org.opendaylight.protocol.util.BitArray)100 ByteBuf (io.netty.buffer.ByteBuf)27 PCEPDeserializerException (org.opendaylight.protocol.pcep.spi.PCEPDeserializerException)8 IpPrefix (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefix)8 RSVPParsingException (org.opendaylight.protocol.rsvp.parser.spi.RSVPParsingException)6 IpPrefixSubobject (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.IpPrefixSubobject)4 IpPrefixCase (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route.subobjects.subobject.type.IpPrefixCase)4 IpAddress (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress)3 Weight (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.segment.routing.ext.rev151014.Weight)3 SubobjectBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.reported.route.object.rro.SubobjectBuilder)3 LabelType (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.label.subobject.LabelType)3 SubobjectContainerBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route.subobjects.list.SubobjectContainerBuilder)3 IpPrefixCaseBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route.subobjects.subobject.type.IpPrefixCaseBuilder)3 IpPrefixBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route.subobjects.subobject.type.ip.prefix._case.IpPrefixBuilder)3 ArrayList (java.util.ArrayList)2 ByteBufWriteUtil.writeFloat32 (org.opendaylight.protocol.util.ByteBufWriteUtil.writeFloat32)2 Stateful1 (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.initiated.rev171025.Stateful1)2 Nai (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.segment.routing.rev171025.sr.subobject.Nai)2 RequestId (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.RequestId)2 Flags (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.monitoring.object.Monitoring.Flags)2