Example usage for io.netty.buffer ByteBuf writeZero

List of usage examples for io.netty.buffer ByteBuf writeZero

Introduction

In this page you can find the example usage for io.netty.buffer ByteBuf writeZero.

Prototype

public abstract ByteBuf writeZero(int length);

Source Link

Document

Fills this buffer with NUL (0x00) starting at the current writerIndex and increases the writerIndex by the specified length .

Usage

From source file:org.opendaylight.protocol.rsvp.parser.impl.subobject.rro.RROUnnumberedInterfaceSubobjectParser.java

License:Open Source License

@Override
public void serializeSubobject(final SubobjectContainer subobject, final ByteBuf buffer) {
    Preconditions.checkArgument(subobject.getSubobjectType() instanceof UnnumberedCase,
            "Unknown subobject instance. Passed %s. Needed UnnumberedCase.",
            subobject.getSubobjectType().getClass());
    final UnnumberedSubobject specObj = ((UnnumberedCase) subobject.getSubobjectType()).getUnnumbered();
    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);
    flags.toByteBuf(body);/* www  .  ja  v a  2s  .  c  om*/
    body.writeZero(RESERVED);
    Preconditions.checkArgument(specObj.getRouterId() != null, "RouterId is mandatory.");
    writeUnsignedInt(specObj.getRouterId(), body);
    Preconditions.checkArgument(specObj.getInterfaceId() != null, "InterfaceId is mandatory.");
    writeUnsignedInt(specObj.getInterfaceId(), body);
    RROSubobjectUtil.formatSubobject(TYPE, body, buffer);
}

From source file:org.opendaylight.protocol.rsvp.parser.impl.subobject.xro.XROUnnumberedInterfaceSubobjectParser.java

License:Open Source License

@Override
public void serializeSubobject(final SubobjectContainer subobject, final ByteBuf buffer) {
    Preconditions.checkArgument(subobject.getSubobjectType() instanceof UnnumberedCase,
            "Unknown subobject instance. Passed %s. Needed UnnumberedCase.",
            subobject.getSubobjectType().getClass());
    final ByteBuf body = Unpooled.buffer(CONTENT_LENGTH);
    body.writeZero(RESERVED);
    writeUnsignedByte(subobject.getAttribute() != null ? (short) subobject.getAttribute().getIntValue() : null,
            body);/*w w  w .j a  va 2 s  .c  o m*/
    serializeUnnumeredInterface(((UnnumberedCase) subobject.getSubobjectType()).getUnnumbered(), body);
    XROSubobjectUtil.formatSubobject(TYPE, subobject.isMandatory(), body, buffer);
}

From source file:org.opendaylight.protocol.rsvp.parser.impl.te.AdminStatusObjectParser.java

License:Open Source License

@Override
protected void localSerializeObject(final RsvpTeObject teLspObject, final ByteBuf output) {
    Preconditions.checkArgument(teLspObject instanceof AdminStatusObject, "AssociationObject is mandatory.");
    final AdminStatusObject addObject = (AdminStatusObject) teLspObject;
    serializeAttributeHeader(BODY_SIZE, CLASS_NUM, CTYPE, output);
    final BitArray reflect = new BitArray(FLAGS_SIZE);
    reflect.set(REFLECT, addObject.isReflect());
    reflect.toByteBuf(output);/*  w w w  .j a va2  s . com*/
    output.writeZero(ByteBufWriteUtil.SHORT_BYTES_LENGTH);
    final BitArray flags = new BitArray(FLAGS_SIZE);
    flags.set(TESTING, addObject.isTesting());
    flags.set(DOWN, addObject.isAdministrativelyDown());
    flags.set(DELETION, addObject.isDeletionInProgress());
    flags.toByteBuf(output);
}

From source file:org.opendaylight.protocol.rsvp.parser.impl.te.FlowSpecObjectParser.java

License:Open Source License

@Override
public void localSerializeObject(final RsvpTeObject teLspObject, final ByteBuf output) {
    Preconditions.checkArgument(teLspObject instanceof FlowSpecObject, "SenderTspecObject is mandatory.");
    final FlowSpecObject flowObj = (FlowSpecObject) teLspObject;
    final int sHeader = flowObj.getServiceHeader().getIntValue();
    if (sHeader == 2) {
        serializeAttributeHeader(BODY_SIZE_REQUESTING, CLASS_NUM, CTYPE, output);
        output.writeZero(ByteBufWriteUtil.SHORT_BYTES_LENGTH);
        output.writeShort(REQUESTING_OVERALL_LENGTH);
    } else {/*  ww w.j  a  v  a2  s. c  om*/
        serializeAttributeHeader(BODY_SIZE_CONTROLLED, CLASS_NUM, CTYPE, output);
        output.writeZero(ByteBufWriteUtil.SHORT_BYTES_LENGTH);
        output.writeShort(CONTROLLER_OVERALL_LENGHT);
    }
    output.writeByte(sHeader);
    output.writeZero(ByteBufWriteUtil.ONE_BYTE_LENGTH);
    if (sHeader == 2) {
        output.writeShort(SERVICE_LENGHT);
    } else {
        output.writeShort(CONTROLLED_LENGHT);
    }

    output.writeByte(TOKEN_BUCKET_TSPEC);
    output.writeZero(ByteBufWriteUtil.ONE_BYTE_LENGTH);
    output.writeShort(PARAMETER_127_LENGTH);
    final TspecObject tSpec = flowObj.getTspecObject();
    writeFloat32(tSpec.getTokenBucketRate(), output);
    writeFloat32(tSpec.getTokenBucketSize(), output);
    writeFloat32(tSpec.getPeakDataRate(), output);
    writeUnsignedInt(tSpec.getMinimumPolicedUnit(), output);
    writeUnsignedInt(tSpec.getMaximumPacketSize(), output);

    if (sHeader != 2) {
        return;
    }
    output.writeByte(GUARANTEED_SERVICE_RSPEC);
    output.writeZero(ByteBufWriteUtil.ONE_BYTE_LENGTH);
    output.writeShort(PARAMETER_130_LENGTH);
    writeFloat32(flowObj.getRate(), output);
    writeUnsignedInt(flowObj.getSlackTerm(), output);
}

From source file:org.opendaylight.protocol.rsvp.parser.impl.te.InformationalFastRerouteObjectParser.java

License:Open Source License

@Override
public void localSerializeObject(final RsvpTeObject teLspObject, final ByteBuf byteAggregator) {
    Preconditions.checkArgument(teLspObject instanceof LegacyFastRerouteObject,
            "FastRerouteObject is mandatory.");
    final LegacyFastRerouteObject fastRerouteObject = (LegacyFastRerouteObject) teLspObject;
    serializeAttributeHeader(BODY_SIZE_C7, CLASS_NUM, CTYPE, byteAggregator);

    byteAggregator.writeByte(fastRerouteObject.getSetupPriority());
    byteAggregator.writeByte(fastRerouteObject.getHoldPriority());
    byteAggregator.writeByte(fastRerouteObject.getHopLimit());
    byteAggregator.writeZero(ByteBufWriteUtil.ONE_BYTE_LENGTH);
    byteAggregator.writeBytes(Unpooled.wrappedBuffer(fastRerouteObject.getBandwidth().getValue()));
    writeAttributeFilter(fastRerouteObject.getIncludeAny(), byteAggregator);
    writeAttributeFilter(fastRerouteObject.getExcludeAny(), byteAggregator);
}

From source file:org.opendaylight.protocol.rsvp.parser.impl.te.MetricObjectParser.java

License:Open Source License

@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);/*from   w w  w  .ja  va2  s .  c o  m*/
    output.writeByte(metric.getMetricType());
    writeFloat32(metric.getValue(), output);
}

From source file:org.opendaylight.protocol.rsvp.parser.impl.te.ProtectionCommonParser.java

License:Open Source License

protected static void serializeBodyType1(final ProtectionSubobject protObj, final ByteBuf output) {
    final BitArray flagBitArray = new BitArray(FLAGS_SIZE);
    flagBitArray.set(SECONDARY, protObj.isSecondary());
    flagBitArray.toByteBuf(output);/*from ww  w  .ja  v a2  s .co m*/
    output.writeZero(ByteBufWriteUtil.SHORT_BYTES_LENGTH);
    output.writeByte(protObj.getLinkFlags().getIntValue());
}

From source file:org.opendaylight.protocol.rsvp.parser.impl.te.ProtectionCommonParser.java

License:Open Source License

protected static void serializeBodyType2(final ProtectionSubobject protObj, final ByteBuf output) {
    final BitArray flagBitArray = new BitArray(FLAGS_SIZE);
    flagBitArray.set(SECONDARY, protObj.isSecondary());
    flagBitArray.set(PROTECTING, protObj.isProtecting());
    flagBitArray.set(NOTIFICATION, protObj.isNotification());
    flagBitArray.set(OPERATIONAL, protObj.isOperational());
    flagBitArray.toByteBuf(output);/* w w  w .ja  v  a  2s .co  m*/
    output.writeByte(protObj.getLspFlag().getIntValue());
    output.writeZero(BYTE_SIZE);
    output.writeByte(protObj.getLinkFlags().getIntValue());
    final BitArray flagInPlaceBitArray = new BitArray(FLAGS_SIZE);
    flagInPlaceBitArray.set(IN_PLACE, protObj.isInPlace());
    flagInPlaceBitArray.set(REQUIRED, protObj.isRequired());
    flagInPlaceBitArray.toByteBuf(output);
    output.writeByte(protObj.getSegFlag().getIntValue());
    output.writeZero(ByteBufWriteUtil.SHORT_BYTES_LENGTH);
}

From source file:org.opendaylight.protocol.rsvp.parser.impl.te.ProtectionCommonParser.java

License:Open Source License

protected final void serializeBody(final Short cType, final ProtectionSubobject protObj, final ByteBuf output) {
    output.writeZero(BYTE_SIZE);
    writeUnsignedByte(cType, output);// w ww  . ja v  a2  s  . com
    switch (cType) {
    case PROTECTION_SUBOBJECT_TYPE_1:
        serializeBodyType1(protObj, output);
        break;
    case PROTECTION_SUBOBJECT_TYPE_2:
        serializeBodyType2(protObj, output);
        break;
    default:
        LOG.warn("Secondary Record Route Protection Subobject cType {} not supported", cType);
        break;
    }
}

From source file:org.opendaylight.protocol.rsvp.parser.impl.te.SenderTspecObjectParser.java

License:Open Source License

@Override
public void localSerializeObject(final RsvpTeObject teLspObject, final ByteBuf output) {
    Preconditions.checkArgument(teLspObject instanceof TspecObject, "SenderTspecObject is mandatory.");
    final TspecObject tspecObj = (TspecObject) teLspObject;
    serializeAttributeHeader(BODY_SIZE, CLASS_NUM, CTYPE, output);
    output.writeZero(ByteBufWriteUtil.SHORT_BYTES_LENGTH);
    output.writeShort(OVERALL_LENGTH);// w  ww.jav a  2s.  c  om
    output.writeByte(ByteBufWriteUtil.ONE_BYTE_LENGTH);
    output.writeZero(ByteBufWriteUtil.ONE_BYTE_LENGTH);
    output.writeShort(SERVICE_LENGHT);
    output.writeByte(TOKEN_BUCKET_TSPEC);
    output.writeZero(ByteBufWriteUtil.ONE_BYTE_LENGTH);
    output.writeShort(PARAMETER_127_LENGTH);
    writeFloat32(tspecObj.getTokenBucketRate(), output);
    writeFloat32(tspecObj.getTokenBucketSize(), output);
    writeFloat32(tspecObj.getPeakDataRate(), output);
    writeUnsignedInt(tspecObj.getMinimumPolicedUnit(), output);
    writeUnsignedInt(tspecObj.getMaximumPacketSize(), output);
}