List of usage examples for io.netty.buffer ByteBuf writeLong
public abstract ByteBuf writeLong(long value);
From source file:org.onosproject.lisp.msg.protocols.DefaultLispInfo.java
License:Apache License
public static void serialize(ByteBuf byteBuf, LispInfo message) throws LispWriterException { // specify LISP message type byte msgType = (byte) (LispType.LISP_INFO.getTypeCode() << INFO_REQUEST_SHIFT_BIT); // info reply flag byte infoReply = DISABLE_BIT; if (message.isInfoReply()) { infoReply = (byte) (ENABLE_BIT << INFO_REPLY_INDEX); }//from ww w . ja va 2 s. c o m byteBuf.writeByte(msgType + infoReply); // fill zero into reserved filed byteBuf.writeByte((short) UNUSED_ZERO); byteBuf.writeByte((short) UNUSED_ZERO); byteBuf.writeByte((short) UNUSED_ZERO); // nonce byteBuf.writeLong(message.getNonce()); // keyId byteBuf.writeShort(message.getKeyId()); // authentication data length in octet byteBuf.writeShort(message.getAuthDataLength()); // authentication data byte[] data = message.getAuthData(); byte[] clone; if (data != null) { clone = data.clone(); Arrays.fill(clone, (byte) UNUSED_ZERO); } byteBuf.writeBytes(data); /// TTL byteBuf.writeInt(message.getTtl()); // fill zero into reserved filed byteBuf.writeByte((short) UNUSED_ZERO); // mask length byteBuf.writeByte(message.getMaskLength()); // EID prefix AFI with EID prefix AfiAddressWriter afiAddressWriter = new AfiAddressWriter(); afiAddressWriter.writeTo(byteBuf, message.getPrefix()); }
From source file:org.onosproject.store.cluster.messaging.impl.MessageEncoder.java
License:Apache License
@Override protected void encode(ChannelHandlerContext context, Object rawMessage, ByteBuf out) throws Exception { InternalMessage message = (InternalMessage) rawMessage; out.writeInt(this.preamble); // write time out.writeLong(message.time().logicalTime()); out.writeLong(message.time().logicalCounter()); // write message id out.writeLong(message.id());//w w w. ja v a 2 s . c o m Endpoint sender = message.sender(); IpAddress senderIp = sender.host(); if (senderIp.version() == Version.INET) { out.writeByte(0); } else { out.writeByte(1); } out.writeBytes(senderIp.toOctets()); // write sender port out.writeInt(sender.port()); byte[] messageTypeBytes = message.type().getBytes(Charsets.UTF_8); // write length of message type out.writeInt(messageTypeBytes.length); // write message type bytes out.writeBytes(messageTypeBytes); // write message status value out.writeInt(message.status().id()); byte[] payload = message.payload(); // write payload length out.writeInt(payload.length); // write payload. out.writeBytes(payload); }
From source file:org.opendaylight.netide.openflowjava.protocol.impl.serialization.factories.FlowRemovedMessageFactory.java
License:Open Source License
@Override public void serialize(FlowRemovedMessage message, ByteBuf outBuffer) { ByteBufUtils.writeOFHeader(MESSAGE_TYPE, message, outBuffer, EncodeConstants.EMPTY_LENGTH); outBuffer.writeLong(message.getCookie().longValue()); outBuffer.writeShort(message.getPriority()); outBuffer.writeByte(message.getReason().getIntValue()); outBuffer.writeByte(message.getTableId().getValue().byteValue()); outBuffer.writeInt(message.getDurationSec().intValue()); outBuffer.writeInt(message.getDurationNsec().intValue()); outBuffer.writeShort(message.getIdleTimeout()); outBuffer.writeShort(message.getHardTimeout()); outBuffer.writeLong(message.getPacketCount().longValue()); outBuffer.writeLong(message.getByteCount().longValue()); OFSerializer<Match> matchSerializer = registry .<Match, OFSerializer<Match>>getSerializer(new MessageTypeKey<>(message.getVersion(), Match.class)); matchSerializer.serialize(message.getMatch(), outBuffer); ByteBufUtils.updateOFHeaderLength(outBuffer); }
From source file:org.opendaylight.netide.openflowjava.protocol.impl.serialization.factories.GetFeaturesOutputFactory.java
License:Open Source License
@Override public void serialize(GetFeaturesOutput message, ByteBuf outBuffer) { ByteBufUtils.writeOFHeader(MESSAGE_TYPE, message, outBuffer, EncodeConstants.EMPTY_LENGTH); outBuffer.writeLong(message.getDatapathId().longValue()); outBuffer.writeInt(message.getBuffers().intValue()); outBuffer.writeByte(message.getTables().intValue()); outBuffer.writeByte(message.getAuxiliaryId().intValue()); outBuffer.writeZero(PADDING);/*from w w w . j a va 2 s . c o m*/ writeCapabilities(message.getCapabilities(), outBuffer); outBuffer.writeInt(message.getReserved().intValue()); ByteBufUtils.updateOFHeaderLength(outBuffer); }
From source file:org.opendaylight.netide.openflowjava.protocol.impl.serialization.factories.MultipartReplyMessageFactory.java
License:Open Source License
private void serializeMeterBody(MultipartReplyBody body, ByteBuf outBuffer) { MultipartReplyMeterCase meterCase = (MultipartReplyMeterCase) body; MultipartReplyMeter meter = meterCase.getMultipartReplyMeter(); for (MeterStats meterStats : meter.getMeterStats()) { ByteBuf meterStatsBuff = UnpooledByteBufAllocator.DEFAULT.buffer(); meterStatsBuff.writeInt(meterStats.getMeterId().getValue().intValue()); meterStatsBuff.writeInt(EncodeConstants.EMPTY_LENGTH); meterStatsBuff.writeZero(METER_PADDING); meterStatsBuff.writeInt(meterStats.getFlowCount().intValue()); meterStatsBuff.writeLong(meterStats.getPacketInCount().longValue()); meterStatsBuff.writeLong(meterStats.getByteInCount().longValue()); meterStatsBuff.writeInt(meterStats.getDurationSec().intValue()); meterStatsBuff.writeInt(meterStats.getDurationNsec().intValue()); for (MeterBandStats meterBandStats : meterStats.getMeterBandStats()) { meterStatsBuff.writeLong(meterBandStats.getPacketBandCount().longValue()); meterStatsBuff.writeLong(meterBandStats.getByteBandCount().longValue()); }/* ww w. j a v a2 s. co m*/ meterStatsBuff.setInt(METER_LENGTH_INDEX, meterStatsBuff.readableBytes()); outBuffer.writeBytes(meterStatsBuff); } }
From source file:org.opendaylight.netide.openflowjava.protocol.impl.serialization.factories.MultipartReplyMessageFactory.java
License:Open Source License
private void serializeGroupBody(MultipartReplyBody body, ByteBuf outBuffer) { MultipartReplyGroupCase groupCase = (MultipartReplyGroupCase) body; MultipartReplyGroup group = groupCase.getMultipartReplyGroup(); for (GroupStats groupStats : group.getGroupStats()) { ByteBuf groupStatsBuff = UnpooledByteBufAllocator.DEFAULT.buffer(); groupStatsBuff.writeShort(EncodeConstants.EMPTY_LENGTH); groupStatsBuff.writeZero(GROUP_STATS_PADDING_1); groupStatsBuff.writeInt(groupStats.getGroupId().getValue().intValue()); groupStatsBuff.writeInt(groupStats.getRefCount().intValue()); groupStatsBuff.writeZero(GROUP_STATS_PADDING_2); groupStatsBuff.writeLong(groupStats.getPacketCount().longValue()); groupStatsBuff.writeLong(groupStats.getByteCount().longValue()); groupStatsBuff.writeInt(groupStats.getDurationSec().intValue()); groupStatsBuff.writeInt(groupStats.getDurationNsec().intValue()); for (BucketStats bucketStats : groupStats.getBucketStats()) { groupStatsBuff.writeLong(bucketStats.getPacketCount().longValue()); groupStatsBuff.writeLong(bucketStats.getByteCount().longValue()); }/* w w w .ja v a2s. co m*/ groupStatsBuff.setShort(GROUP_STATS_LENGTH_INDEX, groupStatsBuff.readableBytes()); outBuffer.writeBytes(groupStatsBuff); } }
From source file:org.opendaylight.netide.openflowjava.protocol.impl.serialization.factories.MultipartReplyMessageFactory.java
License:Open Source License
private void serializeQueueBody(MultipartReplyBody body, ByteBuf outBuffer) { MultipartReplyQueueCase queueCase = (MultipartReplyQueueCase) body; MultipartReplyQueue queue = queueCase.getMultipartReplyQueue(); for (QueueStats queueStats : queue.getQueueStats()) { outBuffer.writeInt(queueStats.getPortNo().intValue()); outBuffer.writeInt(queueStats.getQueueId().intValue()); outBuffer.writeLong(queueStats.getTxBytes().longValue()); outBuffer.writeLong(queueStats.getTxPackets().longValue()); outBuffer.writeLong(queueStats.getTxErrors().longValue()); outBuffer.writeInt(queueStats.getDurationSec().intValue()); outBuffer.writeInt(queueStats.getDurationNsec().intValue()); }/*from ww w. j av a 2 s. co m*/ }
From source file:org.opendaylight.netide.openflowjava.protocol.impl.serialization.factories.MultipartReplyMessageFactory.java
License:Open Source License
private void serializePortStatsBody(MultipartReplyBody body, ByteBuf outBuffer) { MultipartReplyPortStatsCase portStatsCase = (MultipartReplyPortStatsCase) body; MultipartReplyPortStats portStats = portStatsCase.getMultipartReplyPortStats(); for (PortStats portStat : portStats.getPortStats()) { outBuffer.writeInt(portStat.getPortNo().intValue()); outBuffer.writeZero(PORT_STATS_PADDING); outBuffer.writeLong(portStat.getRxPackets().longValue()); outBuffer.writeLong(portStat.getTxPackets().longValue()); outBuffer.writeLong(portStat.getRxBytes().longValue()); outBuffer.writeLong(portStat.getTxBytes().longValue()); outBuffer.writeLong(portStat.getRxDropped().longValue()); outBuffer.writeLong(portStat.getTxDropped().longValue()); outBuffer.writeLong(portStat.getRxErrors().longValue()); outBuffer.writeLong(portStat.getTxErrors().longValue()); outBuffer.writeLong(portStat.getRxFrameErr().longValue()); outBuffer.writeLong(portStat.getRxOverErr().longValue()); outBuffer.writeLong(portStat.getRxCrcErr().longValue()); outBuffer.writeLong(portStat.getCollisions().longValue()); outBuffer.writeInt(portStat.getDurationSec().intValue()); outBuffer.writeInt(portStat.getDurationNsec().intValue()); }/* ww w .j a v a 2s.co m*/ }
From source file:org.opendaylight.netide.openflowjava.protocol.impl.serialization.factories.MultipartReplyMessageFactory.java
License:Open Source License
private void serializeTableBody(MultipartReplyBody body, ByteBuf outBuffer) { MultipartReplyTableCase tableCase = (MultipartReplyTableCase) body; MultipartReplyTable table = tableCase.getMultipartReplyTable(); for (TableStats tableStats : table.getTableStats()) { outBuffer.writeByte(tableStats.getTableId()); outBuffer.writeZero(TABLE_PADDING); outBuffer.writeInt(tableStats.getActiveCount().intValue()); outBuffer.writeLong(tableStats.getLookupCount().longValue()); outBuffer.writeLong(tableStats.getMatchedCount().longValue()); }//from ww w .jav a 2 s . c o m }
From source file:org.opendaylight.netide.openflowjava.protocol.impl.serialization.factories.MultipartReplyMessageFactory.java
License:Open Source License
private void serializeAggregateBody(MultipartReplyBody body, ByteBuf outBuffer) { MultipartReplyAggregateCase aggregateCase = (MultipartReplyAggregateCase) body; MultipartReplyAggregate aggregate = aggregateCase.getMultipartReplyAggregate(); outBuffer.writeLong(aggregate.getPacketCount().longValue()); outBuffer.writeLong(aggregate.getByteCount().longValue()); outBuffer.writeInt(aggregate.getFlowCount().intValue()); outBuffer.writeZero(AGGREGATE_PADDING); }