Пример #1
0
  public void writeTo(ChannelBuffer data) {
    data.writeShort(fieldId);
    data.writeShort(offset);
    data.writeShort(length);
    data.writeShort(0);

    if (value == null) {
      data.writeZero(OFGlobal.OFP_MAX_FIELD_LENGTH_IN_BYTE);
    } else {
      if (value.length > OFGlobal.OFP_MAX_FIELD_LENGTH_IN_BYTE) {
        data.writeBytes(
            value,
            OFGlobal.OFP_MAX_FIELD_LENGTH_IN_BYTE - value.length,
            OFGlobal.OFP_MAX_FIELD_LENGTH_IN_BYTE);
      } else {
        data.writeBytes(value);
        data.writeZero(OFGlobal.OFP_MAX_FIELD_LENGTH_IN_BYTE - value.length);
      }
    }

    if (mask == null) {
      data.writeZero(OFGlobal.OFP_MAX_FIELD_LENGTH_IN_BYTE);
    } else {
      if (mask.length > OFGlobal.OFP_MAX_FIELD_LENGTH_IN_BYTE) {
        data.writeBytes(
            mask,
            OFGlobal.OFP_MAX_FIELD_LENGTH_IN_BYTE - mask.length,
            OFGlobal.OFP_MAX_FIELD_LENGTH_IN_BYTE);
      } else {
        data.writeBytes(mask);
        data.writeZero(OFGlobal.OFP_MAX_FIELD_LENGTH_IN_BYTE - mask.length);
      }
    }
  }
    @Override
    public void write(ChannelBuffer bb, OFBsnGentableBucketStatsReplyVer13 message) {
      int startIndex = bb.writerIndex();
      // fixed value property version = 4
      bb.writeByte((byte) 0x4);
      // fixed value property type = 19
      bb.writeByte((byte) 0x13);
      // length is length of variable message, will be updated at the end
      int lengthIndex = bb.writerIndex();
      bb.writeShort(U16.t(0));

      bb.writeInt(U32.t(message.xid));
      // fixed value property statsType = 65535
      bb.writeShort((short) 0xffff);
      OFStatsReplyFlagsSerializerVer13.writeTo(bb, message.flags);
      // pad: 4 bytes
      bb.writeZero(4);
      // fixed value property experimenter = 0x5c16c7L
      bb.writeInt(0x5c16c7);
      // fixed value property subtype = 0x5L
      bb.writeInt(0x5);
      ChannelUtils.writeList(bb, message.entries);

      // update length field
      int length = bb.writerIndex() - startIndex;
      bb.setShort(lengthIndex, length);
    }
 @Override
 public void write(ChannelBuffer bb, OFGroupFeaturesStatsReplyVer12 message) {
   // fixed value property version = 3
   bb.writeByte((byte) 0x3);
   // fixed value property type = 19
   bb.writeByte((byte) 0x13);
   // fixed value property length = 56
   bb.writeShort((short) 0x38);
   bb.writeInt(U32.t(message.xid));
   // fixed value property statsType = 8
   bb.writeShort((short) 0x8);
   OFStatsReplyFlagsSerializerVer12.writeTo(bb, message.flags);
   // pad: 4 bytes
   bb.writeZero(4);
   bb.writeInt(U32.t(message.types));
   bb.writeInt(U32.t(message.capabilities));
   bb.writeInt(U32.t(message.maxGroupsAll));
   bb.writeInt(U32.t(message.maxGroupsSelect));
   bb.writeInt(U32.t(message.maxGroupsIndirect));
   bb.writeInt(U32.t(message.maxGroupsFf));
   bb.writeInt(U32.t(message.actionsAll));
   bb.writeInt(U32.t(message.actionsSelect));
   bb.writeInt(U32.t(message.actionsIndirect));
   bb.writeInt(U32.t(message.actionsFf));
 }
    @Override
    public void write(ChannelBuffer bb, OFBsnPduTxRequestVer10 message) {
      int startIndex = bb.writerIndex();
      // fixed value property version = 1
      bb.writeByte((byte) 0x1);
      // fixed value property type = 4
      bb.writeByte((byte) 0x4);
      // length is length of variable message, will be updated at the end
      int lengthIndex = bb.writerIndex();
      bb.writeShort(U16.t(0));

      bb.writeInt(U32.t(message.xid));
      // fixed value property experimenter = 0x5c16c7L
      bb.writeInt(0x5c16c7);
      // fixed value property subtype = 0x1fL
      bb.writeInt(0x1f);
      bb.writeInt(U32.t(message.txIntervalMs));
      message.portNo.write2Bytes(bb);
      bb.writeByte(U8.t(message.slotNum));
      // pad: 3 bytes
      bb.writeZero(3);
      bb.writeBytes(message.data);

      // update length field
      int length = bb.writerIndex() - startIndex;
      bb.setShort(lengthIndex, length);
    }
Пример #5
0
  @Override
  public void writeTo(ChannelBuffer data) {
    super.writeTo(data);
    data.writeByte(command);
    data.writeByte(groupType);
    data.writeByte(actionNum);
    data.writeByte(0);
    data.writeInt(groupId);

    data.writeInt(counterId);
    data.writeZero(4);

    if (actionList == null) {
      data.writeZero(OFGlobal.OFP_MAX_ACTION_NUMBER_PER_GROUP * OFAction.MAXIMAL_LENGTH);
    } else {
      OFAction action;

      if (actionNum > actionList.size()) {
        throw new RuntimeException(
            "actionNum " + actionNum + " > actionList.size()" + actionList.size());
      }

      int i;
      for (i = 0; i < actionNum && i < OFGlobal.OFP_MAX_ACTION_NUMBER_PER_GROUP; i++) {
        action = actionList.get(i);
        if (action == null) {
          data.writeZero(OFAction.MAXIMAL_LENGTH);
        } else {
          action.writeTo(data);
          if (action.getLength() < OFAction.MAXIMAL_LENGTH) {
            data.writeZero(OFAction.MAXIMAL_LENGTH - action.getLength());
          }
        }
      }
      if (i < OFGlobal.OFP_MAX_ACTION_NUMBER_PER_GROUP) {
        data.writeZero((OFGlobal.OFP_MAX_ACTION_NUMBER_PER_GROUP - i) * OFAction.MAXIMAL_LENGTH);
      }
    }
  }
    @Override
    public void write(ChannelBuffer bb, OFBsnVlanCounterStatsEntryVer13 message) {
      int startIndex = bb.writerIndex();
      // length is length of variable message, will be updated at the end
      int lengthIndex = bb.writerIndex();
      bb.writeShort(U16.t(0));

      bb.writeShort(U16.t(message.vlanVid));
      // pad: 4 bytes
      bb.writeZero(4);
      ChannelUtils.writeList(bb, message.values);

      // update length field
      int length = bb.writerIndex() - startIndex;
      bb.setShort(lengthIndex, length);
    }
    @Override
    public void write(ChannelBuffer bb, OFActionSetFieldVer12 message) {
      int startIndex = bb.writerIndex();
      // fixed value property type = 25
      bb.writeShort((short) 0x19);
      // length is length of variable message, will be updated at the end
      int lengthIndex = bb.writerIndex();
      bb.writeShort(U16.t(0));

      message.field.writeTo(bb);

      // update length field
      int length = bb.writerIndex() - startIndex;
      int alignedLength = ((length + 7) / 8 * 8);
      bb.setShort(lengthIndex, alignedLength);
      // align message to 8 bytes
      bb.writeZero(alignedLength - length);
    }
 @Override
 public void write(ChannelBuffer bb, OFBsnGentableDescStatsRequestVer13 message) {
   // fixed value property version = 4
   bb.writeByte((byte) 0x4);
   // fixed value property type = 18
   bb.writeByte((byte) 0x12);
   // fixed value property length = 24
   bb.writeShort((short) 0x18);
   bb.writeInt(U32.t(message.xid));
   // fixed value property statsType = 65535
   bb.writeShort((short) 0xffff);
   OFStatsRequestFlagsSerializerVer13.writeTo(bb, message.flags);
   // pad: 4 bytes
   bb.writeZero(4);
   // fixed value property experimenter = 0x5c16c7L
   bb.writeInt(0x5c16c7);
   // fixed value property subtype = 0x4L
   bb.writeInt(0x4);
 }
Пример #9
0
    /* (non-Javadoc)
     * @see java.util.TimerTask#run()
     */
    @Override
    public void run() {

      // assemble the buffer
      ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
      buffer.writeZero(StackdPacket.HEADER_SIZE);
      for (MinerSession session : getSessions()) {
        String name = session.getName();
        buffer.writeInt(session.getId());
        buffer.writeInt(name.length());
        for (int i = 0; i < name.length(); i++) {
          buffer.writeChar(name.charAt(i));
        }
      }

      // wrap it in a packet and send it
      StackdPacket packet =
          new StackdPacket(MinerPacketConstants.TYPE_S2C_PLAYER_NAMES_UPDATE, buffer, false);
      broadcast(packet);
    }
 @Override
 public void write(ChannelBuffer bb, OFBsnImageDescStatsReplyVer14 message) {
   // fixed value property version = 5
   bb.writeByte((byte) 0x5);
   // fixed value property type = 19
   bb.writeByte((byte) 0x13);
   // fixed value property length = 536
   bb.writeShort((short) 0x218);
   bb.writeInt(U32.t(message.xid));
   // fixed value property statsType = 65535
   bb.writeShort((short) 0xffff);
   OFStatsReplyFlagsSerializerVer14.writeTo(bb, message.flags);
   // pad: 4 bytes
   bb.writeZero(4);
   // fixed value property experimenter = 0x5c16c7L
   bb.writeInt(0x5c16c7);
   // fixed value property subtype = 0xeL
   bb.writeInt(0xe);
   ChannelUtils.writeFixedLengthString(bb, message.imageChecksum, 256);
   ChannelUtils.writeFixedLengthString(bb, message.startupConfigChecksum, 256);
 }
  private void sendReply(Channel channel, long deviceId, byte packetNumber) {
    ChannelBuffer reply = ChannelBuffers.directBuffer(ByteOrder.LITTLE_ENDIAN, 28);
    reply.writeByte('M');
    reply.writeByte('C');
    reply.writeByte('G');
    reply.writeByte('P');
    reply.writeByte(MSG_SERVER_ACKNOWLEDGE);
    reply.writeInt((int) deviceId);
    reply.writeByte(commandCount++);
    reply.writeInt(0); // authentication code
    reply.writeByte(0);
    reply.writeByte(packetNumber);
    reply.writeZero(11);

    byte checksum = 0;
    for (int i = 4; i < 27; i++) {
      checksum += reply.getByte(i);
    }
    reply.writeByte(checksum);

    if (channel != null) {
      channel.write(reply);
    }
  }
 public void writeTo(ChannelBuffer data) {
   super.writeTo(data);
   data.writeShort(fieldPosition);
   data.writeZero(2);
   data.writeInt(fieldLength);
 }
 @Override
 public void writeTo(ChannelBuffer data) {
   super.writeTo(data);
   data.writeZero(6);
 }