List of usage examples for io.netty.buffer ByteBuf writeZero
public abstract ByteBuf writeZero(int length);
From source file:org.opendaylight.protocol.bgp.parser.spi.pojo.SimpleNlriRegistry.java
License:Open Source License
@Override public void serializeMpReach(final MpReachNlri mpReachNlri, final ByteBuf byteAggregator) { final Class<? extends AddressFamily> afi = mpReachNlri.getAfi(); final Class<? extends SubsequentAddressFamily> safi = mpReachNlri.getSafi(); byteAggregator.writeShort(this.afiReg.numberForClass(afi)); byteAggregator.writeByte(this.safiReg.numberForClass(safi)); final CNextHop cNextHop = mpReachNlri.getCNextHop(); if (cNextHop != null) { final Map.Entry<Class<? extends CNextHop>, BgpTableType> key = new AbstractMap.SimpleEntry( cNextHop.getImplementedInterface(), new BgpTableTypeImpl(afi, safi)); final NextHopParserSerializer nextHopSerializer = this.nextHopSerializers.get(key); final ByteBuf nextHopBuffer = Unpooled.buffer(); if (nextHopSerializer == null) { //TODO Remove once deprecated registerNlriParser is removed LOG.warn("NexHop Parser/Serializer for AFI/SAFI ({},{}) not bound", afi, safi); NextHopUtil.serializeNextHop(cNextHop, nextHopBuffer); } else {/*www . j a v a 2 s . c o m*/ nextHopSerializer.serializeNextHop(cNextHop, nextHopBuffer); } byteAggregator.writeByte(nextHopBuffer.writerIndex()); byteAggregator.writeBytes(nextHopBuffer); } else { byteAggregator.writeZero(NEXT_HOP_LENGHT); } byteAggregator.writeZero(RESERVED); }
From source file:org.opendaylight.protocol.bmp.impl.message.PeerUpHandler.java
License:Open Source License
@Override public void serializeMessageBody(final Notification message, final ByteBuf buffer) { super.serializeMessageBody(message, buffer); Preconditions.checkArgument(message instanceof PeerUpNotification, "An instance of Peer Up notification is required"); final PeerUpNotification peerUp = (PeerUpNotification) message; if (peerUp.getLocalAddress().getIpv4Address() != null) { buffer.writeZero(Ipv6Util.IPV6_LENGTH - Ipv4Util.IP4_LENGTH); ByteBufWriteUtil.writeIpv4Address(peerUp.getLocalAddress().getIpv4Address(), buffer); } else {// www. jav a 2s .c o m ByteBufWriteUtil.writeIpv6Address(peerUp.getLocalAddress().getIpv6Address(), buffer); } ByteBufWriteUtil.writeUnsignedShort(peerUp.getLocalPort().getValue(), buffer); ByteBufWriteUtil.writeUnsignedShort(peerUp.getRemotePort().getValue(), buffer); getBgpMessageRegistry().serializeMessage(new OpenBuilder(peerUp.getSentOpen()).build(), buffer); getBgpMessageRegistry().serializeMessage(new OpenBuilder(peerUp.getReceivedOpen()).build(), buffer); serializeTlvs(peerUp.getInformation(), buffer); }
From source file:org.opendaylight.protocol.bmp.spi.parser.AbstractBmpPerPeerMessageParser.java
License:Open Source License
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 ? false : true); flags.set(V_FLAG_POS, !peerHeader.isIpv4()); flags.toByteBuf(output);//from ww w .java 2s . co m final PeerDistinguisher peerDistinguisher = peerHeader.getPeerDistinguisher(); switch (peerType) { case L3vpn: if (peerDistinguisher.getRouteDistinguisher() != null) { RouteDistinguisherUtil.serializeRouteDistinquisher(peerDistinguisher.getRouteDistinguisher(), output); } else { PeerDistinguisherUtil.serializePeerDistinguisher(peerHeader.getDistinguisher(), 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); } }
From source file:org.opendaylight.protocol.pcep.ietf.stateful07.Stateful07RSVPErrorSpecTlvParser.java
License:Open Source License
private void serializerUserError(final UserError ue, final ByteBuf body) { final byte[] desc = (ue.getDescription() == null) ? new byte[0] : ue.getDescription().getBytes(StandardCharsets.UTF_8); final ByteBuf userErrorBuf = Unpooled.buffer(); Preconditions.checkArgument(ue.getEnterprise() != null, "EnterpriseNumber is mandatory"); writeUnsignedInt(ue.getEnterprise().getValue(), userErrorBuf); writeUnsignedByte(ue.getSubOrg(), userErrorBuf); userErrorBuf.writeByte(desc.length); Preconditions.checkArgument(ue.getValue() != null, "Value is mandatory."); writeUnsignedShort(ue.getValue(), userErrorBuf); userErrorBuf.writeBytes(desc);//from www .j a va 2 s . c o m userErrorBuf.writeZero(TlvUtil.getPadding(desc.length, TlvUtil.PADDED_TO)); formatRSVPObject(USER_ERROR_CLASS_NUM, USER_ERROR_CLASS_TYPE, userErrorBuf, body); }
From source file:org.opendaylight.protocol.pcep.ietf.stateful07.Stateful07SrpObjectParser.java
License:Open Source License
protected void serializeFlags(final Srp srp, final ByteBuf body) { body.writeZero(FLAGS_SIZE / Byte.SIZE); }
From source file:org.opendaylight.protocol.pcep.impl.object.PCEPClassTypeObjectParser.java
License:Open Source License
@Override public void serializeObject(final Object object, final ByteBuf buffer) { Preconditions.checkArgument(object instanceof ClassType, "Wrong instance of PCEPObject. Passed %s. Needed ClassTypeObject.", object.getClass()); final ByteBuf body = Unpooled.buffer(SIZE); body.writeZero(SIZE - 1); final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.ClassType classType = ((ClassType) object) .getClassType();//from w ww . j a va2 s . c o m Preconditions.checkArgument(classType != null, "ClassType is mandatory."); writeUnsignedByte(classType.getValue(), body); ObjectUtil.formatSubobject(TYPE, CLASS, object.isProcessingRule(), object.isIgnore(), body, buffer); }
From source file:org.opendaylight.protocol.pcep.impl.object.PCEPCloseObjectParser.java
License:Open Source License
@Override public void serializeObject(final Object object, final ByteBuf buffer) { Preconditions.checkArgument(object instanceof CClose, "Wrong instance of PCEPObject. Passed %s. Needed CCloseObject.", object.getClass()); final CClose obj = (CClose) object; final ByteBuf body = Unpooled.buffer(); body.writeZero(RESERVED + FLAGS_F_LENGTH); Preconditions.checkArgument(obj.getReason() != null, "Reason is mandatory."); writeUnsignedByte(obj.getReason(), body); serializeTlvs(obj.getTlvs(), body);//from www. jav a 2 s .c o m ObjectUtil.formatSubobject(TYPE, CLASS, object.isProcessingRule(), object.isIgnore(), body, buffer); }
From source file:org.opendaylight.protocol.pcep.impl.object.PCEPErrorObjectParser.java
License:Open Source License
@Override public void serializeObject(final Object object, final ByteBuf buffer) { Preconditions.checkArgument(object instanceof ErrorObject, "Wrong instance of PCEPObject. Passed %s. Needed ErrorObject.", object.getClass()); final ErrorObject errObj = (ErrorObject) object; final ByteBuf body = Unpooled.buffer(); body.writeZero(FLAGS_F_LENGTH + RESERVED); Preconditions.checkArgument(errObj.getType() != null, "Type is mandatory."); writeUnsignedByte(errObj.getType(), body); Preconditions.checkArgument(errObj.getValue() != null, "Value is mandatory."); writeUnsignedByte(errObj.getValue(), body); serializeTlvs(errObj.getTlvs(), body); ObjectUtil.formatSubobject(TYPE, CLASS, object.isProcessingRule(), object.isIgnore(), body, buffer); }
From source file:org.opendaylight.protocol.pcep.impl.object.PCEPExcludeRouteObjectParser.java
License:Open Source License
@Override public void serializeObject(final Object object, final ByteBuf buffer) { Preconditions.checkArgument(object instanceof Xro, "Wrong instance of PCEPObject. Passed %s. Needed XroObject.", object.getClass()); final Xro obj = (Xro) object; final ByteBuf body = Unpooled.buffer(); body.writeZero(FLAGS_OFFSET); writeBoolean(obj.getFlags() != null ? obj.getFlags().isFail() : null, body); serializeSubobject(obj.getSubobject(), body); ObjectUtil.formatSubobject(TYPE, CLASS, object.isProcessingRule(), object.isIgnore(), body, buffer); }
From source file:org.opendaylight.protocol.pcep.impl.object.PCEPLoadBalancingObjectParser.java
License:Open Source License
@Override public void serializeObject(final Object object, final ByteBuf buffer) { Preconditions.checkArgument(object instanceof LoadBalancing, "Wrong instance of PCEPObject. Passed %s. Needed LoadBalancingObject.", object.getClass()); final LoadBalancing specObj = (LoadBalancing) object; final ByteBuf body = Unpooled.buffer(SIZE); body.writeZero(RESERVED + FLAGS_F_LENGTH); writeUnsignedByte(specObj.getMaxLsp(), body); writeFloat32(specObj.getMinBandwidth(), body); ObjectUtil.formatSubobject(TYPE, CLASS, object.isProcessingRule(), object.isIgnore(), body, buffer); }