Search in sources :

Example 51 with BitArray

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

the class SessionAttributeLspRaObjectParser method localSerializeObject.

@Override
public void localSerializeObject(final RsvpTeObject teLspObject, final ByteBuf output) {
    Preconditions.checkArgument(teLspObject instanceof SessionAttributeObjectWithResourcesAffinities, "SessionAttributeObject is mandatory.");
    final SessionAttributeObjectWithResourcesAffinities sessionObject = (SessionAttributeObjectWithResourcesAffinities) teLspObject;
    final ByteBuf sessionName = Unpooled.wrappedBuffer(StandardCharsets.US_ASCII.encode(sessionObject.getSessionName()));
    final int pad = SessionAttributeLspObjectParser.getPadding(sessionName.readableBytes());
    serializeAttributeHeader(BODY_SIZE_C1 + pad + sessionName.readableBytes(), CLASS_NUM, CTYPE, output);
    writeAttributeFilter(sessionObject.getIncludeAny(), output);
    writeAttributeFilter(sessionObject.getExcludeAny(), output);
    writeAttributeFilter(sessionObject.getIncludeAll(), output);
    output.writeByte(sessionObject.getSetupPriority());
    output.writeByte(sessionObject.getHoldPriority());
    final BitArray bs = new BitArray(FLAGS_SIZE);
    bs.set(SessionAttributeLspObjectParser.LOCAL_PROTECTION, sessionObject.isLocalProtectionDesired());
    bs.set(SessionAttributeLspObjectParser.LABEL_RECORDING, sessionObject.isLabelRecordingDesired());
    bs.set(SessionAttributeLspObjectParser.SE_STYLE, sessionObject.isSeStyleDesired());
    bs.toByteBuf(output);
    output.writeByte(sessionName.readableBytes());
    output.writeBytes(Unpooled.wrappedBuffer(StandardCharsets.US_ASCII.encode(sessionObject.getSessionName())));
    output.writeZero(pad);
}
Also used : SessionAttributeObjectWithResourcesAffinities(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.session.attribute.object.session.attribute.object.SessionAttributeObjectWithResourcesAffinities) BitArray(org.opendaylight.protocol.util.BitArray) ByteBuf(io.netty.buffer.ByteBuf)

Example 52 with BitArray

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

the class SessionAttributeLspRaObjectParser method localParseObject.

@Override
protected RsvpTeObject localParseObject(final ByteBuf byteBuf) throws RSVPParsingException {
    final SessionAttributeObjectWithResourcesAffinitiesBuilder builder = new SessionAttributeObjectWithResourcesAffinitiesBuilder();
    builder.setIncludeAny(new AttributeFilter(byteBuf.readUnsignedInt()));
    builder.setExcludeAny(new AttributeFilter(byteBuf.readUnsignedInt()));
    builder.setIncludeAll(new AttributeFilter(byteBuf.readUnsignedInt()));
    builder.setSetupPriority(byteBuf.readUnsignedByte());
    builder.setHoldPriority(byteBuf.readUnsignedByte());
    final BitArray bs = BitArray.valueOf(byteBuf.readByte());
    builder.setLocalProtectionDesired(bs.get(SessionAttributeLspObjectParser.LOCAL_PROTECTION));
    builder.setLabelRecordingDesired(bs.get(SessionAttributeLspObjectParser.LABEL_RECORDING));
    builder.setSeStyleDesired(bs.get(SessionAttributeLspObjectParser.SE_STYLE));
    final short nameLenght = byteBuf.readUnsignedByte();
    final ByteBuf auxBuf = byteBuf.readSlice(nameLenght);
    final String name = new String(ByteArray.readAllBytes(auxBuf), StandardCharsets.US_ASCII);
    builder.setSessionName(name);
    return builder.build();
}
Also used : SessionAttributeObjectWithResourcesAffinitiesBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.session.attribute.object.session.attribute.object.SessionAttributeObjectWithResourcesAffinitiesBuilder) AttributeFilter(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.AttributeFilter) BitArray(org.opendaylight.protocol.util.BitArray) ByteBuf(io.netty.buffer.ByteBuf)

Example 53 with BitArray

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

the class MetricObjectParser method localParseObject.

@Override
protected RsvpTeObject localParseObject(final ByteBuf byteBuf) throws RSVPParsingException {
    final MetricObjectBuilder builder = new MetricObjectBuilder();
    byteBuf.skipBytes(ByteBufWriteUtil.SHORT_BYTES_LENGTH);
    final BitArray flags = BitArray.valueOf(byteBuf.readByte());
    builder.setBound(flags.get(BOUND));
    builder.setComputed(flags.get(COMPUTED));
    builder.setMetricType(byteBuf.readUnsignedByte());
    builder.setValue(new Float32(ByteArray.readBytes(byteBuf, METRIC_VALUE_F_LENGTH)));
    return builder.build();
}
Also used : Float32(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ieee754.rev130819.Float32) ByteBufWriteUtil.writeFloat32(org.opendaylight.protocol.util.ByteBufWriteUtil.writeFloat32) MetricObjectBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.metric.object.MetricObjectBuilder) BitArray(org.opendaylight.protocol.util.BitArray)

Example 54 with BitArray

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

the class MetricObjectParser method localSerializeObject.

@Override
public void localSerializeObject(final RsvpTeObject teLspObject, final ByteBuf output) {
    Preconditions.checkArgument(teLspObject instanceof MetricObject, "BandwidthObject is mandatory.");
    final MetricObject metric = (MetricObject) teLspObject;
    serializeAttributeHeader(BODY_SIZE, CLASS_NUM, CTYPE, output);
    output.writeZero(ByteBufWriteUtil.SHORT_BYTES_LENGTH);
    final BitArray reflect = new BitArray(FLAGS_SIZE);
    reflect.set(BOUND, metric.isBound());
    reflect.set(COMPUTED, metric.isComputed());
    reflect.toByteBuf(output);
    output.writeByte(metric.getMetricType());
    writeFloat32(metric.getValue(), output);
}
Also used : BitArray(org.opendaylight.protocol.util.BitArray) MetricObject(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.metric.object.MetricObject)

Example 55 with BitArray

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

the class AbstractBmpPerPeerMessageParser method serializePerPeerHeader.

protected void serializePerPeerHeader(final PeerHeader peerHeader, final ByteBuf output) {
    Preconditions.checkArgument(peerHeader != null, "Per-peer header cannot be null.");
    final PeerType peerType = peerHeader.getType();
    output.writeByte(peerType.getIntValue());
    final BitArray flags = new BitArray(FLAGS_SIZE);
    flags.set(L_FLAG_POS, peerHeader.getAdjRibInType().getIntValue() != 0);
    flags.set(V_FLAG_POS, !peerHeader.isIpv4());
    flags.toByteBuf(output);
    final PeerDistinguisher peerDistinguisher = peerHeader.getPeerDistinguisher();
    switch(peerType) {
        case L3vpn:
            RouteDistinguisherUtil.serializeRouteDistinquisher(peerDistinguisher.getRouteDistinguisher(), output);
            break;
        case Local:
            output.writeBytes(peerDistinguisher.getBinary());
            break;
        case Global:
        default:
            output.writeZero(PEER_DISTINGUISHER_SIZE);
            break;
    }
    if (peerHeader.isIpv4()) {
        output.writeZero(Ipv6Util.IPV6_LENGTH - Ipv4Util.IP4_LENGTH);
        ByteBufWriteUtil.writeIpv4Address(peerHeader.getAddress().getIpv4Address(), output);
    } else {
        ByteBufWriteUtil.writeIpv6Address(peerHeader.getAddress().getIpv6Address(), output);
    }
    ByteBufWriteUtil.writeUnsignedInt(peerHeader.getAs().getValue(), output);
    ByteBufWriteUtil.writeIpv4Address(peerHeader.getBgpId(), output);
    if (peerHeader.getTimestampSec() != null) {
        ByteBufWriteUtil.writeUnsignedInt(peerHeader.getTimestampSec().getValue(), output);
    } else {
        output.writeZero(ByteBufWriteUtil.INT_BYTES_LENGTH);
    }
    if (peerHeader.getTimestampMicro() != null) {
        ByteBufWriteUtil.writeUnsignedInt(peerHeader.getTimestampMicro().getValue(), output);
    } else {
        output.writeZero(ByteBufWriteUtil.INT_BYTES_LENGTH);
    }
}
Also used : PeerType(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev171207.PeerType) BitArray(org.opendaylight.protocol.util.BitArray) PeerDistinguisher(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev171207.Peer.PeerDistinguisher)

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