Java Code Examples for org.jboss.netty.buffer.ChannelBuffer#readLong()
The following examples show how to use
org.jboss.netty.buffer.ChannelBuffer#readLong() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: OFFlowRemoved.java From floodlight_with_topoguard with Apache License 2.0 | 6 votes |
@Override public void readFrom(ChannelBuffer data) { super.readFrom(data); if (this.match == null) this.match = new OFMatch(); this.match.readFrom(data); this.cookie = data.readLong(); this.priority = data.readShort(); int reasonIndex = 0xff & data.readByte(); if (reasonIndex >= OFFlowRemovedReason.values().length) { reasonIndex = OFFlowRemovedReason.values().length - 1; } this.reason = OFFlowRemovedReason.values()[reasonIndex]; data.readByte(); // pad this.durationSeconds = data.readInt(); this.durationNanoseconds = data.readInt(); this.idleTimeout = data.readShort(); data.readByte(); // pad data.readByte(); // pad this.packetCount = data.readLong(); this.byteCount = data.readLong(); }
Example 2
Source File: OFFlowMod.java From floodlight_with_topoguard with Apache License 2.0 | 6 votes |
@Override public void readFrom(ChannelBuffer data) { super.readFrom(data); if (this.match == null) this.match = new OFMatch(); this.match.readFrom(data); this.cookie = data.readLong(); this.command = data.readShort(); this.idleTimeout = data.readShort(); this.hardTimeout = data.readShort(); this.priority = data.readShort(); this.bufferId = data.readInt(); this.outPort = data.readShort(); this.flags = data.readShort(); if (this.actionFactory == null) throw new RuntimeException("OFActionFactory not set"); this.actions = this.actionFactory.parseActions(data, getLengthU() - MINIMUM_LENGTH); }
Example 3
Source File: TimestampClient.java From spliceengine with GNU Affero General Public License v3.0 | 6 votes |
@Override public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception { ChannelBuffer buf = (ChannelBuffer) e.getMessage(); assert (buf != null); ensureReadableBytes(buf, FIXED_MSG_RECEIVED_LENGTH); short clientCallerId = buf.readShort(); ensureReadableBytes(buf, 8); long timestamp = buf.readLong(); assert (timestamp > 0); ensureReadableBytes(buf, 0); SpliceLogUtils.debug(LOG, "Response from server: clientCallerId = %s, timestamp = %s", clientCallerId, timestamp); Callback cb = clientCallbacks.remove(clientCallerId); if (cb == null) { doClientErrorThrow(LOG, "Client callback with id %s not found, so unable to deliver timestamp %s", null, clientCallerId, timestamp); } // This releases the latch the original client thread is waiting for // (to provide the synchronous behavior for that caller) and also // provides the timestamp. cb.complete(timestamp); super.messageReceived(ctx, e); }
Example 4
Source File: OFFlowStatisticsReply.java From floodlight_with_topoguard with Apache License 2.0 | 6 votes |
@Override public void readFrom(ChannelBuffer data) { this.length = data.readShort(); this.tableId = data.readByte(); data.readByte(); // pad if (this.match == null) this.match = new OFMatch(); this.match.readFrom(data); this.durationSeconds = data.readInt(); this.durationNanoseconds = data.readInt(); this.priority = data.readShort(); this.idleTimeout = data.readShort(); this.hardTimeout = data.readShort(); data.readInt(); // pad data.readShort(); // pad this.cookie = data.readLong(); this.packetCount = data.readLong(); this.byteCount = data.readLong(); if (this.actionFactory == null) throw new RuntimeException("OFActionFactory not set"); this.actions = this.actionFactory.parseActions(data, getLength() - MINIMUM_LENGTH); }
Example 5
Source File: BgpPrefixAttrExtRouteTag.java From onos with Apache License 2.0 | 6 votes |
/** * Reads the Extended Tag. * * @param cb ChannelBuffer * @return object of BgpPrefixAttrExtRouteTag * @throws BgpParseException while parsing BgpPrefixAttrExtRouteTag */ public static BgpPrefixAttrExtRouteTag read(ChannelBuffer cb) throws BgpParseException { ArrayList<Long> pfxExtRouteTag = new ArrayList<Long>(); long temp; short lsAttrLength = cb.readShort(); int len = lsAttrLength / ATTR_PREFIX_EXT_LEN; if (cb.readableBytes() < lsAttrLength) { Validation.validateLen(BgpErrorType.UPDATE_MESSAGE_ERROR, BgpErrorType.ATTRIBUTE_LENGTH_ERROR, lsAttrLength); } for (int i = 0; i < len; i++) { temp = cb.readLong(); pfxExtRouteTag.add(new Long(temp)); } return new BgpPrefixAttrExtRouteTag(pfxExtRouteTag); }
Example 6
Source File: OFPortStatisticsReply.java From floodlight_with_topoguard with Apache License 2.0 | 6 votes |
@Override public void readFrom(ChannelBuffer data) { this.portNumber = data.readShort(); data.readShort(); // pad data.readInt(); // pad this.receivePackets = data.readLong(); this.transmitPackets = data.readLong(); this.receiveBytes = data.readLong(); this.transmitBytes = data.readLong(); this.receiveDropped = data.readLong(); this.transmitDropped = data.readLong(); this.receiveErrors = data.readLong(); this.transmitErrors = data.readLong(); this.receiveFrameErrors = data.readLong(); this.receiveOverrunErrors = data.readLong(); this.receiveCRCErrors = data.readLong(); this.collisions = data.readLong(); }
Example 7
Source File: BgpNodeLSNlriVer4.java From onos with Apache License 2.0 | 6 votes |
/** * Reads from channelBuffer and parses Node LS Nlri. * * @param cb ChannelBuffer * @param afi Address Family Identifier * @param safi Subsequent Address Family Identifier * @return object of this class * @throws BgpParseException while parsing node descriptors */ public static BgpNodeLSNlriVer4 read(ChannelBuffer cb, short afi, byte safi) throws BgpParseException { boolean isVpn = false; RouteDistinguisher routeDistinguisher = null; if ((afi == Constants.AFI_VALUE) && (safi == Constants.VPN_SAFI_VALUE)) { routeDistinguisher = new RouteDistinguisher(); routeDistinguisher = RouteDistinguisher.read(cb); isVpn = true; } else { isVpn = false; } byte protocolId = cb.readByte(); long identifier = cb.readLong(); log.debug("Parse local node descriptors"); BgpNodeLSIdentifier localNodeDescriptors = new BgpNodeLSIdentifier(); localNodeDescriptors = BgpNodeLSIdentifier.parseLocalNodeDescriptors(cb, protocolId); return new BgpNodeLSNlriVer4(identifier, protocolId, localNodeDescriptors, isVpn, routeDistinguisher); }
Example 8
Source File: BgpLinkLsNlriVer4.java From onos with Apache License 2.0 | 6 votes |
/** * Reads from channelBuffer and parses Link LS Nlri. * * @param cb ChannelBuffer * @param afi Address Family Identifier * @param safi Subsequent Address Family Identifier * @return object of this class * @throws BgpParseException while parsing Link LS NLRI */ public static BgpLinkLsNlriVer4 read(ChannelBuffer cb, short afi, byte safi) throws BgpParseException { boolean isVpn = false; RouteDistinguisher routeDistinguisher = null; if ((afi == Constants.AFI_VALUE) && (safi == Constants.VPN_SAFI_VALUE)) { routeDistinguisher = new RouteDistinguisher(); routeDistinguisher = RouteDistinguisher.read(cb); isVpn = true; } else { isVpn = false; } byte protocolId = cb.readByte(); long identifier = cb.readLong(); BgpLinkLSIdentifier linkLSIdentifier = new BgpLinkLSIdentifier(); linkLSIdentifier = BgpLinkLSIdentifier.parseLinkIdendifier(cb, protocolId); return new BgpLinkLsNlriVer4(protocolId, identifier, linkLSIdentifier, routeDistinguisher, isVpn); }
Example 9
Source File: BgpPrefixIPv4LSNlriVer4.java From onos with Apache License 2.0 | 6 votes |
/** * Reads from channelBuffer and parses Prefix LS Nlri. * * @param cb ChannelBuffer * @param afi Address family identifier * @param safi Subsequent address family identifier * @return object of BGPPrefixIPv4LSNlriVer4 * @throws BgpParseException while parsing Prefix LS Nlri */ public static BgpPrefixIPv4LSNlriVer4 read(ChannelBuffer cb, short afi, byte safi) throws BgpParseException { boolean isVpn = false; RouteDistinguisher routeDistinguisher = null; if ((afi == Constants.AFI_VALUE) && (safi == Constants.VPN_SAFI_VALUE)) { routeDistinguisher = new RouteDistinguisher(); routeDistinguisher = RouteDistinguisher.read(cb); isVpn = true; } else { isVpn = false; } byte protocolId = cb.readByte(); long identifier = cb.readLong(); BgpPrefixLSIdentifier bgpPrefixLSIdentifier = new BgpPrefixLSIdentifier(); bgpPrefixLSIdentifier = BgpPrefixLSIdentifier.parsePrefixIdendifier(cb, protocolId); return new BgpPrefixIPv4LSNlriVer4(identifier, protocolId, bgpPrefixLSIdentifier, routeDistinguisher, isVpn); }
Example 10
Source File: OFBsnPktinSuppressionSetRequestVendorData.java From floodlight_with_topoguard with Apache License 2.0 | 5 votes |
@Override public void readFrom(ChannelBuffer data, int length) { super.readFrom(data, length); suppressionEnabled = (data.readByte() != 0); data.readByte(); idleTimeout = data.readShort(); hardTimeout = data.readShort(); priority = data.readShort(); cookie = data.readLong(); }
Example 11
Source File: OpGetMore.java From usergrid with Apache License 2.0 | 5 votes |
@Override public void decode( ChannelBuffer buffer ) throws IOException { super.decode( buffer ); buffer.readInt(); fullCollectionName = readCString( buffer ); numberToReturn = buffer.readInt(); cursorID = buffer.readLong(); }
Example 12
Source File: MessageFrame.java From TrendrrNSQClient with MIT License | 5 votes |
@Override public void setData(byte[] bytes) { //parse the bytes super.setData(bytes); ChannelBuffer buf = ChannelBuffers.wrappedBuffer(bytes); this.timestamp = buf.readLong(); this.attempts = buf.readShort(); this.messageId = new byte[16]; buf.readBytes(this.messageId); this.messageBody = buf.readBytes(buf.readableBytes()).array(); }
Example 13
Source File: OspfMessageReader.java From onos with Apache License 2.0 | 5 votes |
/** * Gets the OSPF packet Header. * * @param channelBuffer channel buffer instance. * @return Ospf Header instance. */ private OspfPacketHeader getOspfHeader(ChannelBuffer channelBuffer) { OspfPacketHeader ospfPacketHeader = new OspfPacketHeader(); // Determine OSPF version & Packet Type int version = channelBuffer.readByte(); //byte 1 is ospf version int packetType = channelBuffer.readByte(); //byte 2 is ospf packet type // byte 3 & 4 combine is packet length. int packetLength = channelBuffer.readShort(); byte[] tempByteArray = new byte[OspfUtil.FOUR_BYTES]; channelBuffer.readBytes(tempByteArray, 0, OspfUtil.FOUR_BYTES); Ip4Address routerId = Ip4Address.valueOf(tempByteArray); tempByteArray = new byte[OspfUtil.FOUR_BYTES]; channelBuffer.readBytes(tempByteArray, 0, OspfUtil.FOUR_BYTES); Ip4Address areaId = Ip4Address.valueOf(tempByteArray); int checkSum = channelBuffer.readUnsignedShort(); int auType = channelBuffer.readUnsignedShort(); int authentication = (int) channelBuffer.readLong(); ospfPacketHeader.setOspfVer(version); ospfPacketHeader.setOspftype(packetType); ospfPacketHeader.setOspfPacLength(packetLength); ospfPacketHeader.setRouterId(routerId); ospfPacketHeader.setAreaId(areaId); ospfPacketHeader.setChecksum(checkSum); ospfPacketHeader.setAuthType(auType); ospfPacketHeader.setAuthentication(authentication); return ospfPacketHeader; }
Example 14
Source File: OpReply.java From usergrid with Apache License 2.0 | 5 votes |
@Override public void decode( ChannelBuffer buffer ) throws IOException { super.decode( buffer ); responseFlags = buffer.readInt(); cursorID = buffer.readLong(); startingFrom = buffer.readInt(); numberReturned = buffer.readInt(); while ( buffer.readable() ) { documents.add( BSONUtils.decoder().readObject( new ChannelBufferInputStream( buffer ) ) ); } }
Example 15
Source File: OFAggregateStatisticsReply.java From floodlight_with_topoguard with Apache License 2.0 | 5 votes |
@Override public void readFrom(ChannelBuffer data) { this.packetCount = data.readLong(); this.byteCount = data.readLong(); this.flowCount = data.readInt(); data.readInt(); // pad }
Example 16
Source File: OFQueueStatisticsReply.java From floodlight_with_topoguard with Apache License 2.0 | 5 votes |
@Override public void readFrom(ChannelBuffer data) { this.portNumber = data.readShort(); data.readShort(); // pad this.queueId = data.readInt(); this.transmitBytes = data.readLong(); this.transmitPackets = data.readLong(); this.transmitErrors = data.readLong(); }
Example 17
Source File: PcepLSObjectVer1.java From onos with Apache License 2.0 | 4 votes |
/** * Returns Linked list of PCEP Value Type. * * @param cb of channel buffer * @return Linked list of PCEP Value Type * @throws PcepParseException if mandatory fields are missing */ protected static List<PcepValueType> parseOptionalTlv(ChannelBuffer cb) throws PcepParseException { List<PcepValueType> llOutOptionalTlv; llOutOptionalTlv = new LinkedList<>(); while (MINIMUM_TLV_HEADER_LENGTH <= cb.readableBytes()) { PcepValueType tlv; short hType = cb.readShort(); short hLength = cb.readShort(); long lValue = 0; switch (hType) { case RoutingUniverseTlv.TYPE: lValue = cb.readLong(); tlv = new RoutingUniverseTlv(lValue); break; case LocalNodeDescriptorsTlv.TYPE: tlv = LocalNodeDescriptorsTlv.read(cb, hLength); break; case RemoteNodeDescriptorsTlv.TYPE: tlv = RemoteNodeDescriptorsTlv.read(cb, hLength); break; case LinkDescriptorsTlv.TYPE: tlv = LinkDescriptorsTlv.read(cb, hLength); break; case NodeAttributesTlv.TYPE: tlv = NodeAttributesTlv.read(cb, hLength); break; case LinkAttributesTlv.TYPE: tlv = LinkAttributesTlv.read(cb, hLength); break; default: throw new PcepParseException("Unsupported TLV type :" + hType); } // Check for the padding int pad = hLength % 4; if (0 < pad) { pad = 4 - pad; if (pad <= cb.readableBytes()) { cb.skipBytes(pad); } } llOutOptionalTlv.add(tlv); } if (0 < cb.readableBytes()) { throw new PcepParseException("Optional Tlv parsing error. Extra bytes received."); } return llOutOptionalTlv; }
Example 18
Source File: MemcachedBinaryCommandDecoder.java From fqueue with Apache License 2.0 | 4 votes |
protected Object decode(ChannelHandlerContext channelHandlerContext, Channel channel, ChannelBuffer channelBuffer) throws Exception { // need at least 24 bytes, to get header if (channelBuffer.readableBytes() < 24) return null; // get the header channelBuffer.markReaderIndex(); ChannelBuffer headerBuffer = ChannelBuffers.buffer(ByteOrder.BIG_ENDIAN, 24); channelBuffer.readBytes(headerBuffer); short magic = headerBuffer.readUnsignedByte(); // magic should be 0x80 if (magic != 0x80) { headerBuffer.resetReaderIndex(); throw new MalformedCommandException("binary request payload is invalid, magic byte incorrect"); } short opcode = headerBuffer.readUnsignedByte(); short keyLength = headerBuffer.readShort(); short extraLength = headerBuffer.readUnsignedByte(); short dataType = headerBuffer.readUnsignedByte(); // unused short reserved = headerBuffer.readShort(); // unused int totalBodyLength = headerBuffer.readInt(); int opaque = headerBuffer.readInt(); long cas = headerBuffer.readLong(); // we want the whole of totalBodyLength; otherwise, keep waiting. if (channelBuffer.readableBytes() < totalBodyLength) { channelBuffer.resetReaderIndex(); return null; } // This assumes correct order in the enum. If that ever changes, we will have to scan for 'code' field. BinaryCommand bcmd = BinaryCommand.values()[opcode]; Command cmdType = bcmd.correspondingCommand; CommandMessage cmdMessage = CommandMessage.command(cmdType); cmdMessage.noreply = bcmd.noreply; cmdMessage.cas_key = cas; cmdMessage.opaque = opaque; cmdMessage.addKeyToResponse = bcmd.addKeyToResponse; // get extras. could be empty. ChannelBuffer extrasBuffer = ChannelBuffers.buffer(ByteOrder.BIG_ENDIAN, extraLength); channelBuffer.readBytes(extrasBuffer); // get the key if any if (keyLength != 0) { ChannelBuffer keyBuffer = ChannelBuffers.buffer(ByteOrder.BIG_ENDIAN, keyLength); channelBuffer.readBytes(keyBuffer); ArrayList<String> keys = new ArrayList<String>(); String key = keyBuffer.toString(USASCII); keys.add(key); // TODO this or UTF-8? ISO-8859-1? cmdMessage.keys = keys; if (cmdType == Command.ADD || cmdType == Command.SET || cmdType == Command.REPLACE || cmdType == Command.APPEND || cmdType == Command.PREPEND) { // TODO these are backwards from the spec, but seem to be what spymemcached demands -- which has the mistake?! short expire = (short) (extrasBuffer.capacity() != 0 ? extrasBuffer.readUnsignedShort() : 0); short flags = (short) (extrasBuffer.capacity() != 0 ? extrasBuffer.readUnsignedShort() : 0); // the remainder of the message -- that is, totalLength - (keyLength + extraLength) should be the payload int size = totalBodyLength - keyLength - extraLength; cmdMessage.element = new LocalCacheElement(key, flags, expire != 0 && expire < CacheElement.THIRTY_DAYS ? LocalCacheElement.Now() + expire : expire, 0L); cmdMessage.element.setData(new byte[size]); channelBuffer.readBytes(cmdMessage.element.getData(), 0, size); } else if (cmdType == Command.INCR || cmdType == Command.DECR) { long initialValue = extrasBuffer.readUnsignedInt(); long amount = extrasBuffer.readUnsignedInt(); long expiration = extrasBuffer.readUnsignedInt(); cmdMessage.incrAmount = (int) amount; cmdMessage.incrDefault = (int) initialValue; cmdMessage.incrExpiry = (int) expiration; } } return cmdMessage; }
Example 19
Source File: MemcachedBinaryCommandDecoder.java From fqueue with Apache License 2.0 | 4 votes |
protected Object decode(ChannelHandlerContext channelHandlerContext, Channel channel, ChannelBuffer channelBuffer) throws Exception { // need at least 24 bytes, to get header if (channelBuffer.readableBytes() < 24) return null; // get the header channelBuffer.markReaderIndex(); ChannelBuffer headerBuffer = ChannelBuffers.buffer(ByteOrder.BIG_ENDIAN, 24); channelBuffer.readBytes(headerBuffer); short magic = headerBuffer.readUnsignedByte(); // magic should be 0x80 if (magic != 0x80) { headerBuffer.resetReaderIndex(); throw new MalformedCommandException("binary request payload is invalid, magic byte incorrect"); } short opcode = headerBuffer.readUnsignedByte(); short keyLength = headerBuffer.readShort(); short extraLength = headerBuffer.readUnsignedByte(); short dataType = headerBuffer.readUnsignedByte(); // unused short reserved = headerBuffer.readShort(); // unused int totalBodyLength = headerBuffer.readInt(); int opaque = headerBuffer.readInt(); long cas = headerBuffer.readLong(); // we want the whole of totalBodyLength; otherwise, keep waiting. if (channelBuffer.readableBytes() < totalBodyLength) { channelBuffer.resetReaderIndex(); return null; } // This assumes correct order in the enum. If that ever changes, we will have to scan for 'code' field. BinaryCommand bcmd = BinaryCommand.values()[opcode]; Command cmdType = bcmd.correspondingCommand; CommandMessage cmdMessage = CommandMessage.command(cmdType); cmdMessage.noreply = bcmd.noreply; cmdMessage.cas_key = cas; cmdMessage.opaque = opaque; cmdMessage.addKeyToResponse = bcmd.addKeyToResponse; // get extras. could be empty. ChannelBuffer extrasBuffer = ChannelBuffers.buffer(ByteOrder.BIG_ENDIAN, extraLength); channelBuffer.readBytes(extrasBuffer); // get the key if any if (keyLength != 0) { ChannelBuffer keyBuffer = ChannelBuffers.buffer(ByteOrder.BIG_ENDIAN, keyLength); channelBuffer.readBytes(keyBuffer); ArrayList<String> keys = new ArrayList<String>(); String key = keyBuffer.toString(USASCII); keys.add(key); // TODO this or UTF-8? ISO-8859-1? cmdMessage.keys = keys; if (cmdType == Command.ADD || cmdType == Command.SET || cmdType == Command.REPLACE || cmdType == Command.APPEND || cmdType == Command.PREPEND) { // TODO these are backwards from the spec, but seem to be what spymemcached demands -- which has the mistake?! short expire = (short) (extrasBuffer.capacity() != 0 ? extrasBuffer.readUnsignedShort() : 0); short flags = (short) (extrasBuffer.capacity() != 0 ? extrasBuffer.readUnsignedShort() : 0); // the remainder of the message -- that is, totalLength - (keyLength + extraLength) should be the payload int size = totalBodyLength - keyLength - extraLength; cmdMessage.element = new LocalCacheElement(key, flags, expire != 0 && expire < CacheElement.THIRTY_DAYS ? LocalCacheElement.Now() + expire : expire, 0L); cmdMessage.element.setData(new byte[size]); channelBuffer.readBytes(cmdMessage.element.getData(), 0, size); } else if (cmdType == Command.INCR || cmdType == Command.DECR) { long initialValue = extrasBuffer.readUnsignedInt(); long amount = extrasBuffer.readUnsignedInt(); long expiration = extrasBuffer.readUnsignedInt(); cmdMessage.incrAmount = (int) amount; cmdMessage.incrDefault = (int) initialValue; cmdMessage.incrExpiry = (int) expiration; } } return cmdMessage; }
Example 20
Source File: RouteDistinguisher.java From onos with Apache License 2.0 | 2 votes |
/** * Reads route distinguisher from channelBuffer. * * @param cb channelBuffer * @return object of RouteDistinguisher */ public static RouteDistinguisher read(ChannelBuffer cb) { return new RouteDistinguisher(cb.readLong()); }