Search in sources :

Example 76 with BitArray

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

the class PCEPRequestParameterObjectParser method serializeObject.

@Override
public void serializeObject(final Object object, final ByteBuf buffer) {
    Preconditions.checkArgument(object instanceof Rp, "Wrong instance of PCEPObject. Passed %s. Needed RPObject.", object.getClass());
    final ByteBuf body = Unpooled.buffer();
    final Rp rpObj = (Rp) object;
    final BitArray flags = new BitArray(FLAGS_SIZE);
    flags.set(R_FLAG_OFFSET, rpObj.isReoptimization());
    flags.set(B_FLAG_OFFSET, rpObj.isBiDirectional());
    flags.set(O_FLAG_OFFSET, rpObj.isLoose());
    flags.set(M_FLAG_OFFSET, rpObj.isMakeBeforeBreak());
    flags.set(D_FLAG_OFFSET, rpObj.isOrder());
    flags.set(P_FLAG_OFFSET, rpObj.isPathKey());
    flags.set(S_FLAG_OFFSET, rpObj.isSupplyOf());
    flags.set(F_FLAG_OFFSET, rpObj.isFragmentation());
    flags.set(N_FLAG_OFFSET, rpObj.isP2mp());
    flags.set(E_FLAG_OFFSET, rpObj.isEroCompression());
    final byte[] res = flags.array();
    if (rpObj.getPriority() != null) {
        final byte p = UnsignedBytes.checkedCast(rpObj.getPriority());
        res[res.length - 1] = (byte) (res[res.length - 1] | p);
    }
    body.writeBytes(res);
    Preconditions.checkArgument(rpObj.getRequestId() != null, "RequestId is mandatory");
    writeUnsignedInt(rpObj.getRequestId().getValue(), body);
    serializeTlvs(rpObj.getTlvs(), body);
    ObjectUtil.formatSubobject(TYPE, CLASS, object.isProcessingRule(), object.isIgnore(), body, buffer);
}
Also used : BitArray(org.opendaylight.protocol.util.BitArray) ByteBuf(io.netty.buffer.ByteBuf) Rp(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.rp.object.Rp)

Example 77 with BitArray

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

the class PCEPSvecObjectParser method parseObject.

@Override
public Svec parseObject(final ObjectHeader header, final ByteBuf bytes) throws PCEPDeserializerException {
    Preconditions.checkArgument(bytes != null && bytes.isReadable(), "Array of bytes is mandatory. Can't be null or empty.");
    if (bytes.readableBytes() < MIN_SIZE) {
        throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + bytes.readableBytes() + "; Expected: >=" + MIN_SIZE + ".");
    }
    bytes.skipBytes(FLAGS_F_OFFSET);
    final BitArray flags = BitArray.valueOf(bytes, FLAGS_SIZE);
    final List<RequestId> requestIDs = Lists.newArrayList();
    while (bytes.isReadable()) {
        requestIDs.add(new RequestId(bytes.readUnsignedInt()));
    }
    if (requestIDs.isEmpty()) {
        throw new PCEPDeserializerException("Empty Svec Object - no request ids.");
    }
    final SvecBuilder builder = new SvecBuilder();
    builder.setIgnore(header.isIgnore());
    builder.setProcessingRule(header.isProcessingRule());
    builder.setLinkDiverse(flags.get(L_FLAG_OFFSET));
    builder.setNodeDiverse(flags.get(N_FLAG_OFFSET));
    builder.setSrlgDiverse(flags.get(S_FLAG_OFFSET));
    builder.setRequestsIds(requestIDs);
    return builder.build();
}
Also used : RequestId(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.RequestId) SvecBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.svec.object.SvecBuilder) BitArray(org.opendaylight.protocol.util.BitArray) PCEPDeserializerException(org.opendaylight.protocol.pcep.spi.PCEPDeserializerException)

Example 78 with BitArray

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

the class PCEPMetricObjectParser method serializeObject.

@Override
public void serializeObject(final Object object, final ByteBuf buffer) {
    Preconditions.checkArgument(object instanceof Metric, "Wrong instance of PCEPObject. Passed %s. Needed MetricObject.", object.getClass());
    final Metric mObj = (Metric) object;
    final ByteBuf body = Unpooled.buffer(SIZE);
    body.writeZero(RESERVED);
    final BitArray flags = new BitArray(FLAGS_SIZE);
    flags.set(C_FLAG_OFFSET, mObj.isComputed());
    flags.set(B_FLAG_OFFSET, mObj.isBound());
    flags.toByteBuf(body);
    Preconditions.checkArgument(mObj.getMetricType() != null, "MetricType is mandatory.");
    writeUnsignedByte(mObj.getMetricType(), body);
    writeFloat32(mObj.getValue(), body);
    ObjectUtil.formatSubobject(TYPE, CLASS, object.isProcessingRule(), object.isIgnore(), body, buffer);
}
Also used : Metric(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.metric.object.Metric) BitArray(org.opendaylight.protocol.util.BitArray) ByteBuf(io.netty.buffer.ByteBuf)

Example 79 with BitArray

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

the class RROIpv4PrefixSubobjectParser method parseSubobject.

@Override
public Subobject parseSubobject(final ByteBuf buffer) throws PCEPDeserializerException {
    Preconditions.checkArgument(buffer != null && buffer.isReadable(), "Array of bytes is mandatory. Can't be null or empty.");
    if (buffer.readableBytes() != CONTENT4_LENGTH) {
        throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + buffer.readableBytes() + ";");
    }
    final SubobjectBuilder builder = new SubobjectBuilder();
    final int length = buffer.getUnsignedByte(PREFIX4_F_OFFSET);
    final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route.subobjects.subobject.type.ip.prefix._case.IpPrefix prefix = new IpPrefixBuilder().setIpPrefix(new IpPrefix(Ipv4Util.prefixForBytes(ByteArray.readBytes(buffer, Ipv4Util.IP4_LENGTH), length))).build();
    buffer.skipBytes(PREFIX_F_LENGTH);
    final BitArray flags = BitArray.valueOf(buffer, FLAGS_SIZE);
    builder.setProtectionAvailable(flags.get(LPA_F_OFFSET));
    builder.setProtectionInUse(flags.get(LPIU_F_OFFSET));
    builder.setSubobjectType(new IpPrefixCaseBuilder().setIpPrefix(prefix).build());
    return builder.build();
}
Also used : SubobjectBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.reported.route.object.rro.SubobjectBuilder) IpPrefix(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefix) IpPrefixCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route.subobjects.subobject.type.IpPrefixCaseBuilder) BitArray(org.opendaylight.protocol.util.BitArray) IpPrefixBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route.subobjects.subobject.type.ip.prefix._case.IpPrefixBuilder) PCEPDeserializerException(org.opendaylight.protocol.pcep.spi.PCEPDeserializerException)

Example 80 with BitArray

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

the class RROIpv6PrefixSubobjectParser method serializeSubobject.

@Override
public void serializeSubobject(final Subobject subobject, final ByteBuf buffer) {
    Preconditions.checkArgument(subobject.getSubobjectType() instanceof IpPrefixCase, "Unknown subobject instance. Passed %s. Needed IpPrefixCase.", subobject.getSubobjectType().getClass());
    final IpPrefixSubobject specObj = ((IpPrefixCase) subobject.getSubobjectType()).getIpPrefix();
    final IpPrefix prefix = specObj.getIpPrefix();
    final BitArray flags = new BitArray(FLAGS_SIZE);
    flags.set(LPA_F_OFFSET, subobject.isProtectionAvailable());
    flags.set(LPIU_F_OFFSET, subobject.isProtectionInUse());
    final ByteBuf body = Unpooled.buffer(CONTENT_LENGTH);
    Preconditions.checkArgument(prefix.getIpv6Prefix() != null, "Ipv6Prefix is mandatory.");
    writeIpv6Prefix(prefix.getIpv6Prefix(), body);
    flags.toByteBuf(body);
    RROSubobjectUtil.formatSubobject(TYPE, body, buffer);
}
Also used : IpPrefixSubobject(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.IpPrefixSubobject) IpPrefix(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefix) IpPrefixCase(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route.subobjects.subobject.type.IpPrefixCase) 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