private boolean handleRevision1Response(ChannelHandlerContext ctx, int payloadLength)
      throws Exception {
    int code = buffered.readInt();

    int descriptionLength = buffered.readInt();
    byte[] descBytes = new byte[descriptionLength];
    buffered.readBytes(descBytes, 0, descBytes.length);

    String description = new String(descBytes, StandardCharsets.UTF_8);

    logger.debug(
        "Decoded payload with length:[{}], code:[{}], descriptionLength:[{}], description:[{}] on connection [{}]",
        payloadLength,
        code,
        descriptionLength,
        description,
        ctx.getChannel().getLocalAddress());

    if (200 <= code && code <= 299) {
      logger.info(
          "Connected to Found Elasticsearch: [{}]: [{}] on connection [{}]",
          code,
          description,
          ctx.getChannel().getLocalAddress());
      return true;
    } else {
      logger.error(
          "Unable to connect to Found Elasticsearch: [{}]: [{}] on connection [{}]",
          code,
          description,
          ctx.getChannel().getLocalAddress());
      return false;
    }
  }
    @Override
    public OFInstructionIdBsnRequireVlanXlate readFrom(ChannelBuffer bb) throws OFParseError {
      int start = bb.readerIndex();
      // fixed value property type == 65535
      short type = bb.readShort();
      if (type != (short) 0xffff)
        throw new OFParseError(
            "Wrong type: Expected=OFInstructionType.EXPERIMENTER(65535), got=" + type);
      int length = U16.f(bb.readShort());
      if (length != 12) throw new OFParseError("Wrong length: Expected=12(12), got=" + length);
      if (bb.readableBytes() + (bb.readerIndex() - start) < length) {
        // Buffer does not have all data yet
        bb.readerIndex(start);
        return null;
      }
      if (logger.isTraceEnabled()) logger.trace("readFrom - length={}", length);
      // fixed value property experimenter == 0x5c16c7L
      int experimenter = bb.readInt();
      if (experimenter != 0x5c16c7)
        throw new OFParseError(
            "Wrong experimenter: Expected=0x5c16c7L(0x5c16c7L), got=" + experimenter);
      // fixed value property subtype == 0x8L
      int subtype = bb.readInt();
      if (subtype != 0x8)
        throw new OFParseError("Wrong subtype: Expected=0x8L(0x8L), got=" + subtype);

      if (logger.isTraceEnabled())
        logger.trace("readFrom - returning shared instance={}", INSTANCE);
      return INSTANCE;
    }
コード例 #3
0
  @Override
  protected Object decode(
      ChannelHandlerContext ctx, Channel channel, ChannelBuffer buffer, DecodingState state)
      throws Exception {
    switch (state) {
      case COMMAND_LENGTH:
        commandLength = buffer.readInt();
        checkpoint(DecodingState.COMMAND);
      case COMMAND:
        byte[] commandBytes = new byte[commandLength];
        buffer.readBytes(commandBytes, 0, commandLength);
        String commandJson = new String(commandBytes, CharsetUtil.UTF_8);
        command = gson.fromJson(commandJson, EuchreCommand.class);
        checkpoint(DecodingState.PAYLOAD_LENGTH);
      case PAYLOAD_LENGTH:
        payloadLength = buffer.readInt();
        checkpoint(DecodingState.PAYLOAD);
      case PAYLOAD:
        byte[] payloadBytes = new byte[payloadLength];
        buffer.readBytes(payloadBytes, 0, payloadLength);
        payload = new String(payloadBytes, CharsetUtil.UTF_8);
    }

    try {
      return new CommandPayloadDecodedModel(command, payload);
    } finally {
      reset();
    }
  }
コード例 #4
0
 @Override
 public EntityObjectMessage decode(ChannelBuffer buffer) throws IOException {
   int entityId = buffer.readInt();
   byte type = buffer.readByte();
   int x = buffer.readInt();
   int y = buffer.readInt();
   int z = buffer.readInt();
   int throwerId = buffer.readInt();
   if (throwerId > 0) {
     short speedX = buffer.readShort();
     short speedY = buffer.readShort();
     short speedZ = buffer.readShort();
     return new EntityObjectMessage(
         entityId,
         type,
         x,
         y,
         z,
         throwerId,
         speedX,
         speedY,
         speedZ,
         NullRepositionManager.getInstance());
   }
   return new EntityObjectMessage(
       entityId, type, x, y, z, throwerId, NullRepositionManager.getInstance());
 }
コード例 #5
0
 @Override
 public OFActionBsn readFrom(ChannelBuffer bb) throws OFParseError {
   if (bb.readableBytes() < MINIMUM_LENGTH) return null;
   int start = bb.readerIndex();
   // fixed value property type == 65535
   short type = bb.readShort();
   if (type != (short) 0xffff)
     throw new OFParseError(
         "Wrong type: Expected=OFActionType.EXPERIMENTER(65535), got=" + type);
   int length = U16.f(bb.readShort());
   if (length < MINIMUM_LENGTH)
     throw new OFParseError(
         "Wrong length: Expected to be >= " + MINIMUM_LENGTH + ", was: " + length);
   // fixed value property experimenter == 0x5c16c7L
   int experimenter = bb.readInt();
   if (experimenter != 0x5c16c7)
     throw new OFParseError(
         "Wrong experimenter: Expected=0x5c16c7L(0x5c16c7L), got=" + experimenter);
   int subtype = bb.readInt();
   bb.readerIndex(start);
   switch (subtype) {
     case 0x4:
       // discriminator value 0x4L=0x4L for class OFActionBsnChecksumVer10
       return OFActionBsnChecksumVer10.READER.readFrom(bb);
     case 0x1:
       // discriminator value 0x1L=0x1L for class OFActionBsnMirrorVer10
       return OFActionBsnMirrorVer10.READER.readFrom(bb);
     case 0x2:
       // discriminator value 0x2L=0x2L for class OFActionBsnSetTunnelDstVer10
       return OFActionBsnSetTunnelDstVer10.READER.readFrom(bb);
     default:
       throw new OFParseError(
           "Unknown value for discriminator subtype of class OFActionBsnVer10: " + subtype);
   }
 }
コード例 #6
0
ファイル: MessageCodec.java プロジェクト: stsmedia/TomP2P
 /**
  * Decode a message header from a Netty buffer
  *
  * @param buffer The buffer to decode from
  * @param sender The sender of the packet, which has been set in the socket class
  * @return The partial message, only the header fields are filled
  */
 public static Message decodeHeader(
     final ChannelBuffer buffer, final InetSocketAddress recipient, final InetSocketAddress sender)
     throws DecoderException {
   final Message message = new Message();
   message.setVersion(buffer.readInt());
   message.setMessageId(buffer.readInt());
   //
   final int typeCommand = buffer.readUnsignedByte();
   message.setType(Type.values()[typeCommand >>> 4]);
   message.setCommand(Command.values()[typeCommand & 0xf]);
   final Number160 senderID = readID(buffer);
   final int portTCP = buffer.readUnsignedShort();
   final int portUDP = buffer.readUnsignedShort();
   final Number160 recipientID = readID(buffer);
   message.setRecipient(new PeerAddress(recipientID, recipient));
   final int contentType = buffer.readUnsignedShort();
   message.setContentType(
       Content.values()[contentType & 0xf],
       Content.values()[(contentType >>> 4) & 0xf],
       Content.values()[(contentType >>> 8) & 0xf],
       Content.values()[contentType >>> 12]);
   // set the address as we see it, important for port forwarding
   // identification
   final int senderMessageOptions = buffer.readUnsignedByte();
   final int senderOptions = senderMessageOptions >>> 4;
   final PeerAddress peerAddress =
       new PeerAddress(senderID, sender.getAddress(), portTCP, portUDP, senderOptions);
   message.setSender(peerAddress);
   final int options = senderMessageOptions & 0xf;
   message.setOptions(options);
   return message;
 }
コード例 #7
0
  /**
   * Handles a received {@link MBeanServerConnection} invocation
   *
   * @param channel The channel the request was received on
   * @param remoteAddress The remote address of the caller
   * @param buffer THe buffer received
   */
  public static void handleJMXRequest(
      Channel channel, SocketAddress remoteAddress, ChannelBuffer buffer) {
    buffer.resetReaderIndex();
    /* The request write */
    //		cb.writeByte(OpCode.JMX_REQUEST.op());  // 1
    //		cb.writeBytes(domainInfoData);   // domain data
    //		cb.writeInt(reqId);					// 4
    //		cb.writeByte(methodToKey.get(method)); // 1
    //		cb.writeInt(sargs.length);  			// 4
    //		cb.writeBytes(sargs);		           // sargs.length
    Object result = null;
    MBeanServerConnection server = null;
    buffer.skipBytes(1);
    byte domainIndicator = buffer.readByte();
    if (domainIndicator == 0) {
      server = JMXHelper.getHeliosMBeanServer();
    } else {
      byte[] domainBytes = new byte[domainIndicator];
      buffer.readBytes(domainBytes);
      String domain = new String(domainBytes);
      server = JMXHelper.getLocalMBeanServer(true, domain);
      if (server == null) {
        result = new SmallException("Failed to locate MBeanServer for domain [" + domain + "]");
      }
    }
    int reqId = buffer.readInt();
    byte methodId = buffer.readByte();
    if (result == null) {
      int payloadSize = buffer.readInt();
      byte[] payload = new byte[payloadSize];
      buffer.readBytes(payload);
      Object[] params = getInput(payload);
      Method targetMethod = null;
      try {
        targetMethod = keyToMethod.get(methodId);
        if (targetMethod == null) {
          result =
              new SmallException(
                  "Failed to handle MBeanServerConnection invocation because method Op Code ["
                      + methodId
                      + "] was not recognized");
        } else {
          if ("addNotificationListener".equals(targetMethod.getName())
              && !targetMethod.getParameterTypes()[1].equals(ObjectName.class)) {

          } else if ("removeNotificationListener".equals(targetMethod.getName())
              && !targetMethod.getParameterTypes()[1].equals(ObjectName.class)) {

          } else {
            result = targetMethod.invoke(server, params);
          }
        }
      } catch (Throwable t) {
        SimpleLogger.warn("Failed to invoke [", targetMethod, "]", t);
        result = new SmallException(t.toString());
      }
    }
    writeJMXResponse(reqId, methodId, channel, remoteAddress, result);
  }
コード例 #8
0
ファイル: UseBedCodec.java プロジェクト: spacechase0/Vanilla
 @Override
 public UseBedMessage decode(ChannelBuffer buffer) throws IOException {
   int id = buffer.readInt();
   int used = buffer.readUnsignedByte();
   int x = buffer.readInt();
   int y = buffer.readUnsignedByte();
   int z = buffer.readInt();
   return new UseBedMessage(id, used, x, y, z);
 }
コード例 #9
0
 /**
  * Reads the channel buffer and returns object of StatefulIPv4LspIdentidiersTlv.
  *
  * @param c of type channel buffer
  * @return object of StatefulIPv4LspIdentidiersTlv
  */
 public static PcepValueType read(ChannelBuffer c) {
   int ipv4IngressAddress = c.readInt();
   short lspId = c.readShort();
   short tunnelId = c.readShort();
   int extendedTunnelId = c.readInt();
   int ipv4EgressAddress = c.readInt();
   return new StatefulIPv4LspIdentifiersTlv(
       ipv4IngressAddress, lspId, tunnelId, extendedTunnelId, ipv4EgressAddress);
 }
コード例 #10
0
 @Override
 public ExperienceOrbMessage decode(ChannelBuffer buffer) throws IOException {
   int id = buffer.readInt();
   int x = buffer.readInt();
   int y = buffer.readInt();
   int z = buffer.readInt();
   short count = buffer.readShort();
   return new ExperienceOrbMessage(id, x, y, z, count);
 }
コード例 #11
0
    @Override
    public OFGroupFeaturesStatsReply readFrom(ChannelBuffer bb) throws OFParseError {
      int start = bb.readerIndex();
      // fixed value property version == 3
      byte version = bb.readByte();
      if (version != (byte) 0x3)
        throw new OFParseError("Wrong version: Expected=OFVersion.OF_12(3), got=" + version);
      // fixed value property type == 19
      byte type = bb.readByte();
      if (type != (byte) 0x13)
        throw new OFParseError("Wrong type: Expected=OFType.STATS_REPLY(19), got=" + type);
      int length = U16.f(bb.readShort());
      if (length != 56) throw new OFParseError("Wrong length: Expected=56(56), got=" + length);
      if (bb.readableBytes() + (bb.readerIndex() - start) < length) {
        // Buffer does not have all data yet
        bb.readerIndex(start);
        return null;
      }
      if (logger.isTraceEnabled()) logger.trace("readFrom - length={}", length);
      long xid = U32.f(bb.readInt());
      // fixed value property statsType == 8
      short statsType = bb.readShort();
      if (statsType != (short) 0x8)
        throw new OFParseError(
            "Wrong statsType: Expected=OFStatsType.GROUP_FEATURES(8), got=" + statsType);
      Set<OFStatsReplyFlags> flags = OFStatsReplyFlagsSerializerVer12.readFrom(bb);
      // pad: 4 bytes
      bb.skipBytes(4);
      long types = U32.f(bb.readInt());
      long capabilities = U32.f(bb.readInt());
      long maxGroupsAll = U32.f(bb.readInt());
      long maxGroupsSelect = U32.f(bb.readInt());
      long maxGroupsIndirect = U32.f(bb.readInt());
      long maxGroupsFf = U32.f(bb.readInt());
      long actionsAll = U32.f(bb.readInt());
      long actionsSelect = U32.f(bb.readInt());
      long actionsIndirect = U32.f(bb.readInt());
      long actionsFf = U32.f(bb.readInt());

      OFGroupFeaturesStatsReplyVer12 groupFeaturesStatsReplyVer12 =
          new OFGroupFeaturesStatsReplyVer12(
              xid,
              flags,
              types,
              capabilities,
              maxGroupsAll,
              maxGroupsSelect,
              maxGroupsIndirect,
              maxGroupsFf,
              actionsAll,
              actionsSelect,
              actionsIndirect,
              actionsFf);
      if (logger.isTraceEnabled()) logger.trace("readFrom - read={}", groupFeaturesStatsReplyVer12);
      return groupFeaturesStatsReplyVer12;
    }
コード例 #12
0
 @Override
 public EntityTeleportMessage decode(ChannelBuffer buffer) throws IOException {
   int id = buffer.readInt();
   int x = buffer.readInt();
   int y = buffer.readInt();
   int z = buffer.readInt();
   int rotation = buffer.readUnsignedByte();
   int pitch = buffer.readUnsignedByte();
   return new EntityTeleportMessage(id, x, y, z, rotation, pitch);
 }
コード例 #13
0
ファイル: BlockActionCodec.java プロジェクト: NikoMix/Vanilla
 @Override
 public BlockActionMessage decode(ChannelBuffer buffer) throws IOException {
   int x = buffer.readInt();
   int y = buffer.readUnsignedShort();
   int z = buffer.readInt();
   byte firstByte = buffer.readByte();
   byte secondByte = buffer.readByte();
   short blockId = buffer.readShort();
   return new BlockActionMessage(x, y, z, blockId, firstByte, secondByte);
 }
コード例 #14
0
ファイル: MasterClient210.java プロジェクト: Analect/neo4j
 protected static IdAllocation readIdAllocation(ChannelBuffer buffer) {
   int numberOfDefragIds = buffer.readInt();
   long[] defragIds = new long[numberOfDefragIds];
   for (int i = 0; i < numberOfDefragIds; i++) {
     defragIds[i] = buffer.readLong();
   }
   long rangeStart = buffer.readLong();
   int rangeLength = buffer.readInt();
   long highId = buffer.readLong();
   long defragCount = buffer.readLong();
   return new IdAllocation(new IdRange(defragIds, rangeStart, rangeLength), highId, defragCount);
 }
コード例 #15
0
ファイル: PlayerSpawnCodec.java プロジェクト: Sleaker/Vanilla
 @Override
 public PlayerSpawnMessage decode(ChannelBuffer buffer) throws IOException {
   int id = buffer.readInt();
   String name = ChannelBufferUtils.readString(buffer);
   int x = buffer.readInt();
   int y = buffer.readInt();
   int z = buffer.readInt();
   int rotation = buffer.readUnsignedByte();
   int pitch = buffer.readUnsignedByte();
   int item = buffer.readUnsignedShort();
   List<Parameter<?>> parameters = ChannelBufferUtils.readParameters(buffer);
   return new PlayerSpawnMessage(id, name, x, y, z, rotation, pitch, item, parameters);
 }
コード例 #16
0
  @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)));
    }
  }
コード例 #17
0
    @Override
    public OFBsnGentableBucketStatsReply readFrom(ChannelBuffer bb) throws OFParseError {
      int start = bb.readerIndex();
      // fixed value property version == 4
      byte version = bb.readByte();
      if (version != (byte) 0x4)
        throw new OFParseError("Wrong version: Expected=OFVersion.OF_13(4), got=" + version);
      // fixed value property type == 19
      byte type = bb.readByte();
      if (type != (byte) 0x13)
        throw new OFParseError("Wrong type: Expected=OFType.STATS_REPLY(19), got=" + type);
      int length = U16.f(bb.readShort());
      if (length < MINIMUM_LENGTH)
        throw new OFParseError(
            "Wrong length: Expected to be >= " + MINIMUM_LENGTH + ", was: " + length);
      if (bb.readableBytes() + (bb.readerIndex() - start) < length) {
        // Buffer does not have all data yet
        bb.readerIndex(start);
        return null;
      }
      if (logger.isTraceEnabled()) logger.trace("readFrom - length={}", length);
      long xid = U32.f(bb.readInt());
      // fixed value property statsType == 65535
      short statsType = bb.readShort();
      if (statsType != (short) 0xffff)
        throw new OFParseError(
            "Wrong statsType: Expected=OFStatsType.EXPERIMENTER(65535), got=" + statsType);
      Set<OFStatsReplyFlags> flags = OFStatsReplyFlagsSerializerVer13.readFrom(bb);
      // pad: 4 bytes
      bb.skipBytes(4);
      // fixed value property experimenter == 0x5c16c7L
      int experimenter = bb.readInt();
      if (experimenter != 0x5c16c7)
        throw new OFParseError(
            "Wrong experimenter: Expected=0x5c16c7L(0x5c16c7L), got=" + experimenter);
      // fixed value property subtype == 0x5L
      int subtype = bb.readInt();
      if (subtype != 0x5)
        throw new OFParseError("Wrong subtype: Expected=0x5L(0x5L), got=" + subtype);
      List<OFBsnGentableBucketStatsEntry> entries =
          ChannelUtils.readList(
              bb, length - (bb.readerIndex() - start), OFBsnGentableBucketStatsEntryVer13.READER);

      OFBsnGentableBucketStatsReplyVer13 bsnGentableBucketStatsReplyVer13 =
          new OFBsnGentableBucketStatsReplyVer13(xid, flags, entries);
      if (logger.isTraceEnabled())
        logger.trace("readFrom - read={}", bsnGentableBucketStatsReplyVer13);
      return bsnGentableBucketStatsReplyVer13;
    }
コード例 #18
0
ファイル: UpdateSignCodec.java プロジェクト: nallar/Vanilla
 @Override
 public UpdateSignMessage decode(ChannelBuffer buffer) throws IOException {
   int x = buffer.readInt();
   int y = buffer.readShort();
   int z = buffer.readInt();
   String[] message = new String[4];
   for (int i = 0; i < message.length; i++) {
     String line = ChannelBufferUtils.readString(buffer);
     if (line == null) {
       line = "";
     }
     message[i] = line;
   }
   return new UpdateSignMessage(x, y, z, message);
 }
コード例 #19
0
ファイル: AuthenticationDecoder.java プロジェクト: Haridos/v4
 @Override
 protected Object decode(
     ChannelHandlerContext chtx, Channel chan, ChannelBuffer in, AuthenticationStage state)
     throws Exception {
   switch (state) {
     case VALIDATION:
       int bytesLeft = readableBytes(in);
       if (bytesLeft >= 3) {
         int type = in.readUnsignedByte();
         int size = in.readUnsignedShort();
         if (size != readableBytes(in)) {
           throw new Exception("Mismatched login packet size.");
         }
         int version = in.readInt();
         if (version != 614) {
           throw new Exception("Incorrect revision read");
         }
         if (type == 16 || type == 18) {
           checkpoint(AuthenticationStage.DETAILS);
         }
       }
       break;
     case DETAILS:
       in.readUnsignedByte();
       int mode = in.readUnsignedByte();
       in.readUnsignedShort();
       in.readUnsignedShort();
       in.readUnsignedByte();
       in.skipBytes(24);
       readRS2String(in); // macaddress!
       in.readInt();
       int size = in.readUnsignedByte();
       in.skipBytes(size);
       in.skipBytes(6 + (33 * 4) + 8 + 2 + 14);
       if (in.readUnsignedByte() != 10) {
         throw new Exception("Invalid RSA header.");
       }
       in.readLong();
       in.readLong();
       long l = in.readLong();
       String name = longToString(l);
       String password = readRS2String(in);
       int left = readableBytes(in);
       in.skipBytes(left);
       return new LoginRequest(chan, chtx, name, password, mode);
   }
   return null;
 }
コード例 #20
0
ファイル: EventDecoder.java プロジェクト: sgroschupf/cesto
  @Override
  protected Object decode(ChannelHandlerContext ctx, Channel channel, ChannelBuffer buffer)
      throws Exception {
    // wait for prefix
    if (buffer.readableBytes() < 4) {
      return null;
    }

    int length = buffer.getInt(buffer.readerIndex());
    // wait for the complete event
    if (buffer.readableBytes() < length + 4) {
      return null;
    }

    // skip package length header
    buffer.skipBytes(4);
    // decode
    int typeLength = buffer.readInt();
    String type = buffer.toString(buffer.readerIndex(), typeLength, "UTF-8");
    int eventLength = length - typeLength;
    byte[] eventBytes = new byte[eventLength];
    buffer.skipBytes(typeLength);
    buffer.readBytes(eventBytes);
    return new Event(type, eventBytes);
  }
コード例 #21
0
ファイル: STTS.java プロジェクト: k2wanko/NLiveRoid
 @Override
 public void read(ChannelBuffer in) {
   in.readInt(); // UI8 version + UI24 flags
   final int count = in.readInt();
   Log.d("no of time to sample records: {}", "" + count);
   records = new ArrayList<STTSRecord>(count);
   for (int i = 0; i < count; i++) {
     final STTSRecord record = new STTSRecord();
     record.sampleCount = in.readInt();
     record.sampleDuration = in.readInt();
     Log.d(
         "#{} sampleCount: {} sampleDuration: {}",
         "" + new Object[] {i, record.sampleCount, record.sampleDuration});
     records.add(record);
   }
 }
コード例 #22
0
ファイル: LoadChunkCodec.java プロジェクト: hapm/Vanilla
 @Override
 public LoadChunkMessage decode(ChannelBuffer buffer) {
   int x = buffer.readInt();
   int z = buffer.readInt();
   boolean loaded = buffer.readByte() == 1;
   return new LoadChunkMessage(x, z, loaded);
 }
コード例 #23
0
    @Override
    public OFEchoRequest readFrom(ChannelBuffer bb) throws OFParseError {
      int start = bb.readerIndex();
      // fixed value property version == 1
      byte version = bb.readByte();
      if (version != (byte) 0x1)
        throw new OFParseError("Wrong version: Expected=OFVersion.OF_10(1), got=" + version);
      // fixed value property type == 2
      byte type = bb.readByte();
      if (type != (byte) 0x2)
        throw new OFParseError("Wrong type: Expected=OFType.ECHO_REQUEST(2), got=" + type);
      int length = U16.f(bb.readShort());
      if (length < MINIMUM_LENGTH)
        throw new OFParseError(
            "Wrong length: Expected to be >= " + MINIMUM_LENGTH + ", was: " + length);
      if (bb.readableBytes() + (bb.readerIndex() - start) < length) {
        // Buffer does not have all data yet
        bb.readerIndex(start);
        return null;
      }
      if (logger.isTraceEnabled()) logger.trace("readFrom - length={}", length);
      long xid = U32.f(bb.readInt());
      byte[] data = ChannelUtils.readBytes(bb, length - (bb.readerIndex() - start));

      OFEchoRequestVer10 echoRequestVer10 = new OFEchoRequestVer10(xid, data);
      if (logger.isTraceEnabled()) logger.trace("readFrom - read={}", echoRequestVer10);
      return echoRequestVer10;
    }
コード例 #24
0
    @Override
    public OFQueueOpFailedErrorMsg readFrom(ChannelBuffer bb) throws OFParseError {
      int start = bb.readerIndex();
      // fixed value property version == 4
      byte version = bb.readByte();
      if (version != (byte) 0x4)
        throw new OFParseError("Wrong version: Expected=OFVersion.OF_13(4), got=" + version);
      // fixed value property type == 1
      byte type = bb.readByte();
      if (type != (byte) 0x1)
        throw new OFParseError("Wrong type: Expected=OFType.ERROR(1), got=" + type);
      int length = U16.f(bb.readShort());
      if (length < MINIMUM_LENGTH)
        throw new OFParseError(
            "Wrong length: Expected to be >= " + MINIMUM_LENGTH + ", was: " + length);
      if (bb.readableBytes() + (bb.readerIndex() - start) < length) {
        // Buffer does not have all data yet
        bb.readerIndex(start);
        return null;
      }
      if (logger.isTraceEnabled()) logger.trace("readFrom - length={}", length);
      long xid = U32.f(bb.readInt());
      // fixed value property errType == 9
      short errType = bb.readShort();
      if (errType != (short) 0x9)
        throw new OFParseError(
            "Wrong errType: Expected=OFErrorType.QUEUE_OP_FAILED(9), got=" + errType);
      OFQueueOpFailedCode code = OFQueueOpFailedCodeSerializerVer13.readFrom(bb);
      byte[] data = ChannelUtils.readBytes(bb, length - (bb.readerIndex() - start));

      OFQueueOpFailedErrorMsgVer13 queueOpFailedErrorMsgVer13 =
          new OFQueueOpFailedErrorMsgVer13(xid, code, data);
      if (logger.isTraceEnabled()) logger.trace("readFrom - read={}", queueOpFailedErrorMsgVer13);
      return queueOpFailedErrorMsgVer13;
    }
コード例 #25
0
 /**
  * @param headerLength
  * @param middleLength
  * @param endLength
  * @param buf
  * @return the new AuthentPacket from buffer
  * @throws OpenR66ProtocolPacketException
  */
 public static AuthentPacket createFromBuffer(
     int headerLength, int middleLength, int endLength, ChannelBuffer buf)
     throws OpenR66ProtocolPacketException {
   if (headerLength - 1 <= 0) {
     throw new OpenR66ProtocolPacketException("Not enough data");
   }
   if (middleLength <= 0) {
     throw new OpenR66ProtocolPacketException("Not enough data");
   }
   if (endLength < 5) {
     throw new OpenR66ProtocolPacketException("Not enough data");
   }
   final byte[] bheader = new byte[headerLength - 1];
   final byte[] bmiddle = new byte[middleLength];
   if (headerLength - 1 > 0) {
     buf.readBytes(bheader);
   }
   if (middleLength > 0) {
     buf.readBytes(bmiddle);
   }
   // end part
   Integer newId = buf.readInt();
   byte valid = buf.readByte();
   String version =
       R66Versions.V2_4_12.getVersion(); // first base reference where it is unacceptable
   if (endLength > 5) {
     // version
     byte[] bversion = new byte[endLength - 5];
     buf.readBytes(bversion);
     version = new String(bversion);
   }
   final String sheader = new String(bheader);
   return new AuthentPacket(sheader, bmiddle, newId, valid, version);
 }
コード例 #26
0
ファイル: PcepTEObjectVer1.java プロジェクト: chinghanyu/onos
  /**
   * Reads from the channel buffer and returns Object of PcepTEObject.
   *
   * @param cb of type channel buffer
   * @return Object of PcepTEObject
   * @throws PcepParseException if mandatory fields are missing
   */
  public static PcepTEObject read(ChannelBuffer cb) throws PcepParseException {
    log.debug("read");

    PcepObjectHeader teObjHeader;
    byte yProtocolId;
    // 2-flags
    boolean bRFlag;
    boolean bSFlag;
    int iTEId;
    LinkedList<PcepValueType> llOptionalTlv;

    teObjHeader = PcepObjectHeader.read(cb);

    // take only TEObject buffer.
    ChannelBuffer tempCb = cb.readBytes(teObjHeader.getObjLen() - OBJECT_HEADER_LENGTH);

    yProtocolId = tempCb.readByte();
    // ignore first two bytes of Flags
    tempCb.readShort();

    Integer iTemp = (int) tempCb.readByte(); // read 3rd byte Flag
    bSFlag = ((iTemp & FLAG_SET_S_FLAG) == FLAG_SET_S_FLAG) ? true : false;
    bRFlag = ((iTemp & FLAG_SET_R_FLAG) == FLAG_SET_R_FLAG) ? true : false;

    iTEId = tempCb.readInt();

    // parse optional TLV
    llOptionalTlv = parseOptionalTlv(tempCb);

    return new PcepTEObjectVer1(teObjHeader, yProtocolId, bRFlag, bSFlag, iTEId, llOptionalTlv);
  }
コード例 #27
0
 /**
  * Read int from this packet buffer.
  *
  * @return int
  */
 protected final int readD() {
   try {
     return buf.readInt();
   } catch (Exception e) {
     log.error("Missing D for: " + this);
   }
   return 0;
 }
コード例 #28
0
  public static String readExtendedString(ChannelBuffer buffer) {
    byte[] data = new byte[buffer.readInt()];
    for (int i = 0; i < data.length; i++) {
      data[i] = buffer.readByte();
    }

    return new String(data, UTF_8).trim();
  }
コード例 #29
0
  @Override
  public void readFrom(ChannelBuffer data) {
    super.readFrom(data);

    command = data.readByte();
    groupType = data.readByte();
    actionNum = data.readByte();
    data.readByte();
    groupId = data.readInt();

    counterId = data.readInt();
    data.readBytes(4);

    this.actionList =
        this.actionFactory.parseActions(
            data, OFGlobal.OFP_MAX_ACTION_NUMBER_PER_GROUP * OFAction.MAXIMAL_LENGTH);
  }
コード例 #30
0
ファイル: Server.java プロジェクト: Analect/neo4j
  protected RequestContext readContext(ChannelBuffer buffer) {
    long sessionId = buffer.readLong();
    int machineId = buffer.readInt();
    int eventIdentifier = buffer.readInt();
    long neoTx = buffer.readLong();
    int masterId = buffer.readInt();
    long checksum = buffer.readLong();

    RequestContext readRequestContext =
        new RequestContext(sessionId, machineId, eventIdentifier, neoTx, masterId, checksum);
    // Only perform checksum checks on the neo data source. If there's none in the request
    // then don't perform any such check.
    if (neoTx > 0) {
      txVerifier.assertMatch(neoTx, masterId, checksum);
    }
    return readRequestContext;
  }