Java Code Examples for org.jboss.netty.buffer.ChannelBuffer#readInt()
The following examples show how to use
org.jboss.netty.buffer.ChannelBuffer#readInt() .
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: BgpPrefixAttrRouteTag.java From onos with Apache License 2.0 | 6 votes |
/** * Reads the Route Tag. * * @param cb ChannelBuffer * @return object of BgpPrefixAttrRouteTag * @throws BgpParseException while parsing BgpPrefixAttrRouteTag */ public static BgpPrefixAttrRouteTag read(ChannelBuffer cb) throws BgpParseException { int tmp; ArrayList<Integer> pfxRouteTag = new ArrayList<Integer>(); short lsAttrLength = cb.readShort(); int len = lsAttrLength / SIZE; if (cb.readableBytes() < lsAttrLength) { Validation.validateLen(BgpErrorType.UPDATE_MESSAGE_ERROR, BgpErrorType.ATTRIBUTE_LENGTH_ERROR, lsAttrLength); } for (int i = 0; i < len; i++) { tmp = cb.readInt(); pfxRouteTag.add(new Integer(tmp)); } return BgpPrefixAttrRouteTag.of(pfxRouteTag); }
Example 2
Source File: OFQueueGetConfigReply.java From floodlight_with_topoguard with Apache License 2.0 | 6 votes |
@Override public void readFrom(ChannelBuffer data) { super.readFrom(data); this.portNumber = data.readShort(); data.readInt(); // pad data.readShort(); // pad int availLength = (this.length - MINIMUM_LENGTH); this.queues.clear(); while (availLength > 0) { OFPacketQueue queue = new OFPacketQueue(); queue.readFrom(data); queues.add(queue); availLength -= queue.getLength(); } }
Example 3
Source File: OFInterfaceVendorData.java From floodlight_with_topoguard with Apache License 2.0 | 6 votes |
/** * Read this message off the wire from the specified ByteBuffer * @param data */ public void readFrom(ChannelBuffer data) { if (this.hardwareAddress == null) this.hardwareAddress = new byte[OFP_ETH_ALEN]; data.readBytes(this.hardwareAddress); data.readBytes(new byte[2]); byte[] name = new byte[16]; data.readBytes(name); // find the first index of 0 int index = 0; for (byte b : name) { if (0 == b) break; ++index; } this.name = new String(Arrays.copyOf(name, index), Charset.forName("ascii")); ipv4Addr = data.readInt(); ipv4AddrMask = data.readInt(); }
Example 4
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 5
Source File: PayloadPacket.java From pinpoint with Apache License 2.0 | 6 votes |
public static ChannelBuffer readPayload(ChannelBuffer buffer) { if (buffer.readableBytes() < 4) { buffer.resetReaderIndex(); return null; } final int payloadLength = buffer.readInt(); if (payloadLength <= 0) { return EMPTY_BUFFER; } if (buffer.readableBytes() < payloadLength) { buffer.resetReaderIndex(); return null; } return buffer.readBytes(payloadLength); }
Example 6
Source File: PcepFecObjectIPv4AdjacencyVer1.java From onos with Apache License 2.0 | 6 votes |
/** * Reads from channel buffer and Returns object of PcepFecObjectIPv4Adjacency. * * @param cb of channel buffer. * @return object of PcepFecObjectIPv4Adjacency * @throws PcepParseException when fails to read from channel buffer */ public static PcepFecObjectIPv4Adjacency read(ChannelBuffer cb) throws PcepParseException { PcepObjectHeader fecObjHeader; int localIPv4Address; int remoteIPv4Address; fecObjHeader = PcepObjectHeader.read(cb); //take only FEC IPv4 Adjacency Object buffer. ChannelBuffer tempCb = cb.readBytes(fecObjHeader.getObjLen() - MINIMUM_COMMON_HEADER_LENGTH); localIPv4Address = tempCb.readInt(); remoteIPv4Address = tempCb.readInt(); return new PcepFecObjectIPv4AdjacencyVer1(fecObjHeader, localIPv4Address, remoteIPv4Address); }
Example 7
Source File: OFNetmaskVendorData.java From floodlight_with_topoguard with Apache License 2.0 | 5 votes |
/** * Read the vendor data from the channel buffer * @param data: the channel buffer from which we are deserializing * @param length: the length to the end of the enclosing message */ public void readFrom(ChannelBuffer data, int length) { super.readFrom(data, length); tableIndex = data.readByte(); pad1 = data.readByte(); pad2 = data.readByte(); pad3 = data.readByte(); netMask = data.readInt(); }
Example 8
Source File: OFTableStatistics.java From floodlight_with_topoguard with Apache License 2.0 | 5 votes |
@Override public void readFrom(ChannelBuffer data) { this.tableId = data.readByte(); data.readByte(); // pad data.readByte(); // pad data.readByte(); // pad this.name = StringByteSerializer.readFrom(data, MAX_TABLE_NAME_LEN); this.wildcards = data.readInt(); this.maximumEntries = data.readInt(); this.activeCount = data.readInt(); this.lookupCount = data.readLong(); this.matchedCount = data.readLong(); }
Example 9
Source File: OpQuery.java From usergrid with Apache License 2.0 | 5 votes |
@Override public void decode( ChannelBuffer buffer ) throws IOException { super.decode( buffer ); flags = buffer.readInt(); fullCollectionName = readCString( buffer ); numberToSkip = buffer.readInt(); numberToReturn = buffer.readInt(); query = BSONUtils.decoder().readObject( new ChannelBufferInputStream( buffer ) ); if ( buffer.readable() ) { returnFieldSelector = BSONUtils.decoder().readObject( new ChannelBufferInputStream( buffer ) ); logger.info( "found fieldSeclector: {}", returnFieldSelector ); } }
Example 10
Source File: SharedRiskLinkGroupSubTlv.java From onos with Apache License 2.0 | 5 votes |
/** * Reads from channel buffer and returns object of SharedRiskLinkGroupTlv. * * @param c input channel buffer * @param hLength length * @return object of SharedRiskLinkGroupTlv */ public static PcepValueType read(ChannelBuffer c, short hLength) { int iLength = hLength / 4; int[] iSharedRiskLinkGroup = new int[iLength]; for (int i = 0; i < iLength; i++) { iSharedRiskLinkGroup[i] = c.readInt(); } return new SharedRiskLinkGroupSubTlv(iSharedRiskLinkGroup, hLength); }
Example 11
Source File: BgpPeerFrameDecoderTest.java From onos with Apache License 2.0 | 5 votes |
/** * Processes BGP open message. * * @param ctx Channel handler context * @param message open message */ private void processBgpOpen(ChannelHandlerContext ctx, ChannelBuffer message) { int minLength = MINIMUM_OPEN_MSG_LENGTH - MINIMUM_COMMON_HEADER_LENGTH; if (message.readableBytes() < minLength) { log.debug("Error: Bad message length"); ctx.getChannel().close(); return; } message.readByte(); // read version message.readShort(); // read AS number message.readShort(); // read Hold timer message.readInt(); // read BGP Identifier // Optional Parameters int optParamLen = message.readUnsignedByte(); if (message.readableBytes() < optParamLen) { log.debug("Error: Bad message length"); ctx.getChannel().close(); return; } message.readBytes(optParamLen); // Open message received receivedOpenMessageLatch.countDown(); }
Example 12
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 13
Source File: PcepRsvpIpv4ErrorSpec.java From onos with Apache License 2.0 | 5 votes |
/** * Reads PCPE RSVP error spec from channel buffer and returns PCEP rsvp IPv4 error spec object. * * @param cb channel buffer * @return PCEP rsvp IPv4 error spec object */ public static PcepRsvpErrorSpec read(ChannelBuffer cb) { PcepRsvpSpecObjHeader objHeader; int ipv4Addr; byte flags; byte errCode; short errValue; objHeader = PcepRsvpSpecObjHeader.read(cb); ipv4Addr = cb.readInt(); flags = cb.readByte(); errCode = cb.readByte(); errValue = cb.readShort(); return new PcepRsvpIpv4ErrorSpec(objHeader, ipv4Addr, flags, errCode, errValue); }
Example 14
Source File: OFPacketQueue.java From floodlight_with_topoguard with Apache License 2.0 | 5 votes |
public void readFrom(ChannelBuffer data) { this.queueId = data.readInt(); this.length = data.readShort(); data.readShort(); // pad int availLength = (this.length - MINIMUM_LENGTH); this.properties.clear(); while (availLength > 0) { OFQueueProp prop = new OFQueueProp(); prop.readFrom(data); properties.add(prop); availLength -= prop.getLength(); } }
Example 15
Source File: PcepLspObjectVer1.java From onos with Apache License 2.0 | 4 votes |
/** * Returns Linked list of optional tlvs. * * @param cb of channel buffer. * @return list of optional tlvs * @throws PcepParseException when unsupported tlv is received */ protected static LinkedList<PcepValueType> parseOptionalTlv(ChannelBuffer cb) throws PcepParseException { LinkedList<PcepValueType> llOutOptionalTlv; llOutOptionalTlv = new LinkedList<>(); while (MINIMUM_COMMON_HEADER_LENGTH <= cb.readableBytes()) { PcepValueType tlv = null; short hType = cb.readShort(); short hLength = cb.readShort(); int iValue = 0; switch (hType) { case StatefulIPv4LspIdentifiersTlv.TYPE: tlv = StatefulIPv4LspIdentifiersTlv.read(cb); break; case StatefulLspErrorCodeTlv.TYPE: iValue = cb.readInt(); tlv = new StatefulLspErrorCodeTlv(iValue); break; case StatefulRsvpErrorSpecTlv.TYPE: tlv = StatefulRsvpErrorSpecTlv.read(cb); break; case SymbolicPathNameTlv.TYPE: tlv = SymbolicPathNameTlv.read(cb, hLength); break; case StatefulLspDbVerTlv.TYPE: tlv = StatefulLspDbVerTlv.read(cb); break; default: // Skip the unknown TLV. cb.skipBytes(hLength); log.info("Received unsupported TLV type :" + hType + " in LSP object."); } // Check for the padding int pad = hLength % 4; if (0 < pad) { pad = 4 - pad; if (pad <= cb.readableBytes()) { cb.skipBytes(pad); } } if (tlv != null) { llOutOptionalTlv.add(tlv); } } if (0 < cb.readableBytes()) { throw new PcepParseException("Optional Tlv parsing error. Extra bytes received."); } return llOutOptionalTlv; }
Example 16
Source File: LocalNodeDescriptorsTlv.java From onos with Apache License 2.0 | 4 votes |
/** * Reads the channel buffer and returns object of AutonomousSystemTlv. * * @param c input channel buffer * @param hLength length of subtlvs. * @return object of AutonomousSystemTlv * @throws PcepParseException if mandatory fields are missing */ public static PcepValueType read(ChannelBuffer c, short hLength) throws PcepParseException { // Node Descriptor Sub-TLVs (variable) List<PcepValueType> llNodeDescriptorSubTLVs = new LinkedList<>(); ChannelBuffer tempCb = c.readBytes(hLength); while (TLV_HEADER_LENGTH <= tempCb.readableBytes()) { PcepValueType tlv; short hType = tempCb.readShort(); int iValue = 0; short length = tempCb.readShort(); switch (hType) { case AutonomousSystemSubTlv.TYPE: iValue = tempCb.readInt(); tlv = new AutonomousSystemSubTlv(iValue); break; case BgpLsIdentifierSubTlv.TYPE: iValue = tempCb.readInt(); tlv = new BgpLsIdentifierSubTlv(iValue); break; case OspfAreaIdSubTlv.TYPE: iValue = tempCb.readInt(); tlv = new OspfAreaIdSubTlv(iValue); break; case IgpRouterIdSubTlv.TYPE: tlv = IgpRouterIdSubTlv.read(tempCb, length); break; default: throw new PcepParseException("Unsupported Sub TLV type :" + hType); } // Check for the padding int pad = length % 4; if (0 < pad) { pad = 4 - pad; if (pad <= tempCb.readableBytes()) { tempCb.skipBytes(pad); } } llNodeDescriptorSubTLVs.add(tlv); } if (0 < tempCb.readableBytes()) { throw new PcepParseException("Sub Tlv parsing error. Extra bytes received."); } return new LocalNodeDescriptorsTlv(llNodeDescriptorSubTLVs); }
Example 17
Source File: OFActionBigSwitchVendor.java From floodlight_with_topoguard with Apache License 2.0 | 4 votes |
@Override public void readFrom(ChannelBuffer data) { super.readFrom(data); this.subtype = data.readInt(); }
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: As4Path.java From onos with Apache License 2.0 | 4 votes |
/** * Reads from the channel buffer and parses As4Path. * * @param cb ChannelBuffer * @return object of As4Path * @throws BgpParseException while parsing As4Path */ public static As4Path read(ChannelBuffer cb) throws BgpParseException { List<Integer> as4pathSet = new ArrayList<>(); List<Integer> as4pathSeq = new ArrayList<>(); ChannelBuffer tempCb = cb.copy(); Validation validation = Validation.parseAttributeHeader(cb); if (cb.readableBytes() < validation.getLength()) { Validation.validateLen(BgpErrorType.UPDATE_MESSAGE_ERROR, BgpErrorType.ATTRIBUTE_LENGTH_ERROR, validation.getLength()); } //if fourth bit is set length is read as short otherwise as byte , len includes type, length and value int len = validation.isShort() ? validation.getLength() + Constants.TYPE_AND_LEN_AS_SHORT : validation .getLength() + Constants.TYPE_AND_LEN_AS_BYTE; ChannelBuffer data = tempCb.readBytes(len); if (validation.getFirstBit() && !validation.getSecondBit() && validation.getThirdBit()) { throw new BgpParseException(BgpErrorType.UPDATE_MESSAGE_ERROR, BgpErrorType.ATTRIBUTE_FLAGS_ERROR, data); } ChannelBuffer tempBuf = cb.readBytes(validation.getLength()); while (tempBuf.readableBytes() > 0) { byte pathSegType = tempBuf.readByte(); //no of ASes byte pathSegLen = tempBuf.readByte(); //length = no of Ases * ASnum size (4 bytes) int length = pathSegLen * ASNUM_SIZE; if (tempBuf.readableBytes() < length) { Validation.validateLen(BgpErrorType.UPDATE_MESSAGE_ERROR, BgpErrorType.ATTRIBUTE_LENGTH_ERROR, length); } ChannelBuffer aspathBuf = tempBuf.readBytes(length); while (aspathBuf.readableBytes() > 0) { int asNum; asNum = aspathBuf.readInt(); switch (pathSegType) { case AsPath.ASPATH_SET_TYPE: as4pathSet.add(asNum); break; case AsPath.ASPATH_SEQ_TYPE: as4pathSeq.add(asNum); break; default: log.debug("Other type Not Supported:" + pathSegType); } } } return new As4Path(as4pathSet, as4pathSeq); }
Example 20
Source File: LinkLocalRemoteIdentifiersTlv.java From onos with Apache License 2.0 | 2 votes |
/** * Reads the channel buffer and returns object of LinkLocalRemoteIdentifiersTlv. * * @param cb channelBuffer * @return object of LinkLocalRemoteIdentifiersTlv */ public static LinkLocalRemoteIdentifiersTlv read(ChannelBuffer cb) { int linkLocalIdentifer = cb.readInt(); int linkRemoteIdentifer = cb.readInt(); return LinkLocalRemoteIdentifiersTlv.of(linkLocalIdentifer, linkRemoteIdentifer); }