@Override
    public void write(ByteBuf bb, OFFlowStatsEntryVer10 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));

      message.tableId.writeByte(bb);
      // pad: 1 bytes
      bb.writeZero(1);
      message.match.writeTo(bb);
      bb.writeInt(U32.t(message.durationSec));
      bb.writeInt(U32.t(message.durationNsec));
      bb.writeShort(U16.t(message.priority));
      bb.writeShort(U16.t(message.idleTimeout));
      bb.writeShort(U16.t(message.hardTimeout));
      // pad: 6 bytes
      bb.writeZero(6);
      bb.writeLong(message.cookie.getValue());
      bb.writeLong(message.packetCount.getValue());
      bb.writeLong(message.byteCount.getValue());
      ChannelUtils.writeList(bb, message.actions);

      // update length field
      int length = bb.writerIndex() - startIndex;
      bb.setShort(lengthIndex, length);
    }
 @Override
 public void serializeExtendedCommunity(
     final ExtendedCommunities exCommunities, final ByteBuf buffer) {
   final ExtendedCommunity ex = exCommunities.getExtendedCommunity();
   if (ex instanceof TrafficRateExtendedCommunityCase) {
     final TrafficRateExtendedCommunity trafficRate =
         ((TrafficRateExtendedCommunityCase) ex).getTrafficRateExtendedCommunity();
     ByteBufWriteUtil.writeShort(trafficRate.getInformativeAs().getValue().shortValue(), buffer);
     buffer.writeBytes(trafficRate.getLocalAdministrator().getValue());
   } else if (ex instanceof TrafficActionExtendedCommunityCase) {
     final TrafficActionExtendedCommunity trafficAction =
         ((TrafficActionExtendedCommunityCase) ex).getTrafficActionExtendedCommunity();
     buffer.writeZero(RESERVED);
     final BitArray flags = new BitArray(FLAGS_SIZE);
     flags.set(SAMPLE_BIT, trafficAction.isSample());
     flags.set(TERMINAL_BIT, trafficAction.isTerminalAction());
     flags.toByteBuf(buffer);
   } else if (ex instanceof RedirectExtendedCommunityCase) {
     final RedirectExtendedCommunity redirect =
         ((RedirectExtendedCommunityCase) ex).getRedirectExtendedCommunity();
     ByteBufWriteUtil.writeUnsignedShort(
         redirect.getGlobalAdministrator().getValue().intValue(), buffer);
     buffer.writeBytes(redirect.getLocalAdministrator());
   } else if (ex instanceof TrafficMarkingExtendedCommunityCase) {
     final TrafficMarkingExtendedCommunity trafficMarking =
         ((TrafficMarkingExtendedCommunityCase) ex).getTrafficMarkingExtendedCommunity();
     buffer.writeZero(RESERVED);
     ByteBufWriteUtil.writeUnsignedByte(
         trafficMarking.getGlobalAdministrator().getValue().shortValue(), buffer);
   } else {
     super.serializeExtendedCommunity(exCommunities, buffer);
   }
 }
Example #3
0
 /**
  * Writes 16-bit short <code>value</code> if not null, otherwise writes zeros to the <code>output
  * </code> ByteBuf. ByteBuf's writerIndex is increased by 2.
  *
  * @param value Short value to be written to the output.
  * @param output ByteBuf, where value or zeros are written.
  */
 public static void writeShort(final Short value, final ByteBuf output) {
   if (value != null) {
     output.writeShort(value);
   } else {
     output.writeZero(SHORT_BYTES_LENGTH);
   }
 }
Example #4
0
 /**
  * Writes IPv6 prefix if not null, otherwise writes zeros to the <code>output</code> ByteBuf.
  * ByteBuf's writerIndex is increased by 17.
  *
  * @param ipv6Prefix IPv6 prefix to be written to the output. Prefix is written in the last byte.
  * @param output ByteBuf, where ipv6Prefix or zeros are written.
  */
 public static void writeIpv6Prefix(final Ipv6Prefix ipv6Prefix, final ByteBuf output) {
   if (ipv6Prefix != null) {
     output.writeBytes(Ipv6Util.bytesForPrefix(ipv6Prefix));
   } else {
     output.writeZero(IPV6_PREFIX_BYTE_LENGTH);
   }
 }
Example #5
0
 /**
  * Writes unsigned 64-bit integer <code>value</code> if not null, otherwise writes zeros to the
  * <code>output</code> ByteBuf. ByteBuf's writerIndex is increased by 8.
  *
  * @param value BigInteger value to be written to the output.
  * @param output ByteBuf, where value or zeros are written.
  */
 public static void writeUnsignedLong(final BigInteger value, final ByteBuf output) {
   if (value != null) {
     output.writeLong(value.longValue());
   } else {
     output.writeZero(LONG_BYTES_LENGTH);
   }
 }
Example #6
0
 /**
  * Writes IPv6 address if not null, otherwise writes zeros to the <code>output</code> ByteBuf.
  * ByteBuf's writerIndex is increased by 16.
  *
  * @param ipv6Address IPv6 address to be written to the output.
  * @param output ByteBuf, where ipv6Address or zeros are written.
  */
 public static void writeIpv6Address(final Ipv6Address ipv6Address, final ByteBuf output) {
   if (ipv6Address != null) {
     output.writeBytes(Ipv6Util.bytesForAddress(ipv6Address));
   } else {
     output.writeZero(Ipv6Util.IPV6_LENGTH);
   }
 }
Example #7
0
 /**
  * Writes unsigned 32-bit integer <code>value</code> if not null, otherwise writes zeros to the
  * <code>output</code> ByteBuf. ByteBuf's writerIndex is increased by 4.
  *
  * @param value Long value to be written to the output.
  * @param output ByteBuf, where value or zeros are written.
  */
 public static void writeUnsignedInt(final Long value, final ByteBuf output) {
   if (value != null) {
     output.writeInt(value.intValue());
   } else {
     output.writeZero(INT_BYTES_LENGTH);
   }
 }
Example #8
0
 /**
  * Writes unsigned 16-bit short integer <code>value</code> if not null, otherwise writes zeros to
  * the <code>output</code> ByteBuf. ByteBuf's writerIndex is increased by 2.
  *
  * @param value Integer value to be written to the output.
  * @param output ByteBuf, where value or zeros are written.
  */
 public static void writeUnsignedShort(final Integer value, final ByteBuf output) {
   if (value != null) {
     output.writeShort(value.shortValue());
   } else {
     output.writeZero(SHORT_BYTES_LENGTH);
   }
 }
Example #9
0
 /**
  * Writes unsigned byte <code>value</code> if not null, otherwise writes zero to the <code>output
  * </code> ByteBuf. ByteBuf's writerIndex is increased by 1.
  *
  * @param value Short value to be write to the output.
  * @param output ByteBuf, where value or zeros are written.
  */
 public static void writeUnsignedByte(final Short value, final ByteBuf output) {
   if (value != null) {
     output.writeByte(value);
   } else {
     output.writeZero(ONE_BYTE_LENGTH);
   }
 }
Example #10
0
 /**
  * Writes Float32 <code>value</code> if not null, otherwise writes zeros to the <code>output
  * </code> ByteBuf. ByteBuf's writerIndex is increased by 4.
  *
  * @param value Float32 value to be written to the output.
  * @param output ByteBuf, where value or zeros are written.
  */
 public static void writeFloat32(final Float32 value, final ByteBuf output) {
   if (value != null) {
     output.writeBytes(value.getValue());
   } else {
     output.writeZero(FLOAT32_BYTES_LENGTH);
   }
 }
Example #11
0
 /**
  * Writes 64-bit long <code>value</code> if not null, otherwise writes zeros to the <code>output
  * </code> ByteBuf. ByteBuf's writerIndex is increased by 8.
  *
  * @param value Long value to be written to the output.
  * @param output ByteBuf, where value or zeros are written.
  */
 public static void writeLong(final Long value, final ByteBuf output) {
   if (value != null) {
     output.writeLong(value);
   } else {
     output.writeZero(LONG_BYTES_LENGTH);
   }
 }
 @Override
 public void serialize(Action action, ByteBuf outBuffer) {
   super.serialize(action, outBuffer);
   outBuffer.writeByte(
       ((SetMplsTtlCase) action.getActionChoice()).getSetMplsTtlAction().getMplsTtl());
   outBuffer.writeZero(ActionConstants.SET_MPLS_TTL_PADDING);
 }
Example #13
0
 /**
  * Writes boolean <code>value</code> if not null, otherwise writes zero to the <code>output</code>
  * ByteBuf. ByteBuf's writerIndex is increased by 1.
  *
  * @param value Boolean value to be written to the output.
  * @param output ByteBuf, where value or zero is written.
  */
 public static void writeBoolean(final Boolean value, final ByteBuf output) {
   if (value != null) {
     output.writeBoolean(value);
   } else {
     output.writeZero(ONE_BYTE_LENGTH);
   }
 }
Example #14
0
 /**
  * Writes 32-bit integer <code>value</code> if not null, otherwise writes zeros to the <code>
  * output</code> ByteBuf. ByteBuf's writerIndex is increased by 4.
  *
  * @param value Integer value to be written to the output.
  * @param output ByteBuf, where value or zeros are written.
  */
 public static void writeInt(final Integer value, final ByteBuf output) {
   if (value != null) {
     output.writeInt(value);
   } else {
     output.writeZero(INT_BYTES_LENGTH);
   }
 }
 @Override
 public void serialize(Action input, ByteBuf outBuffer) {
   ActionSetNshc1 action = ((ActionSetNshc1) input.getActionChoice());
   serializeHeader(LENGTH, NXAST_SET_NSC_SUBTYPE, outBuffer);
   outBuffer.writeZero(padding);
   outBuffer.writeInt(action.getNxActionSetNshc1().getNshc().intValue());
 }
Example #16
0
 /**
  * Writes 24-bit integer <code>value</code> if not null, otherwise writes zeros to the <code>
  * output</code> ByteBuf. ByteBuf's writerIndex is increased by 3.
  *
  * @param value Medium value to be written to the output.
  * @param output ByteBuf, where value or zeros are written.
  */
 public static void writeMedium(final Integer value, final ByteBuf output) {
   if (value != null) {
     output.writeMedium(value);
   } else {
     output.writeZero(MEDIUM_BYTES_LENGTH);
   }
 }
 @Override
 public void write(ByteBuf bb, OFPortDescVer12 message) {
   message.portNo.write4Bytes(bb);
   // pad: 4 bytes
   bb.writeZero(4);
   message.hwAddr.write6Bytes(bb);
   // pad: 2 bytes
   bb.writeZero(2);
   ChannelUtils.writeFixedLengthString(bb, message.name, 16);
   OFPortConfigSerializerVer12.writeTo(bb, message.config);
   OFPortStateSerializerVer12.writeTo(bb, message.state);
   OFPortFeaturesSerializerVer12.writeTo(bb, message.curr);
   OFPortFeaturesSerializerVer12.writeTo(bb, message.advertised);
   OFPortFeaturesSerializerVer12.writeTo(bb, message.supported);
   OFPortFeaturesSerializerVer12.writeTo(bb, message.peer);
   bb.writeInt(U32.t(message.currSpeed));
   bb.writeInt(U32.t(message.maxSpeed));
 }
 @Override
 public void write(ByteBuf bb, OFPortStatsRequestVer13 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 = 4
   bb.writeShort((short) 0x4);
   OFStatsRequestFlagsSerializerVer13.writeTo(bb, message.flags);
   // pad: 4 bytes
   bb.writeZero(4);
   message.portNo.write4Bytes(bb);
   // pad: 4 bytes
   bb.writeZero(4);
 }
 @Override
 public void write(ByteBuf bb, OFActionCopyTtlInVer11 message) {
   // fixed value property type = 12
   bb.writeShort((short) 0xc);
   // fixed value property length = 8
   bb.writeShort((short) 0x8);
   // pad: 4 bytes
   bb.writeZero(4);
 }
 @Override
 public void marshallMessage(ByteBuf cb) {
   cb.writeInt(slaveServerId);
   MysqlAPIUtils.putLengthCodedString(cb, reportHost, true /* codeNullasZero */);
   MysqlAPIUtils.putLengthCodedString(cb, reportUser, true /* codeNullasZero */);
   MysqlAPIUtils.putLengthCodedString(cb, reportPassword, true /* codeNullasZero */);
   cb.writeShort(reportPort);
   cb.writeZero(8);
 }
Example #21
0
 /**
  * Writes BitSet's bits if not null, otherwise writes zeros to the <code>output</code> ByteBuf.
  * ByteBuf's writerIndex is increased by specified length.
  *
  * @param bitSet BitSet values to be written to the output, starting from left most bit.
  * @param outputLength Number of bytes to be written, must be greater than 0.
  * @param output ByteBuf, where bitSet or zeros are written.
  */
 public static void writeBitSet(
     final BitSet bitSet, final int outputLength, final ByteBuf output) {
   Preconditions.checkArgument(outputLength > 0);
   if (bitSet != null) {
     output.writeBytes(ByteArray.bitSetToBytes(bitSet, outputLength));
   } else {
     output.writeZero(outputLength);
   }
 }
 @Override
 public void write(ByteBuf bb, OFActionSetDlSrcVer10 message) {
   // fixed value property type = 4
   bb.writeShort((short) 0x4);
   // fixed value property length = 16
   bb.writeShort((short) 0x10);
   message.dlAddr.write6Bytes(bb);
   // pad: 6 bytes
   bb.writeZero(6);
 }
Example #23
0
 public static void writeFixedLengthString(ByteBuf bb, String string, int length) {
   int l = string.length();
   if (l > length) {
     throw new IllegalArgumentException(
         "Error writing string: length=" + l + " > max Length=" + length);
   }
   bb.writeBytes(string.getBytes(Charsets.US_ASCII));
   if (l < length) {
     bb.writeZero(length - l);
   }
 }
  @Override
  public void serialize(FlowRemovedMessage message, ByteBuf outBuffer) {
    ByteBufUtils.writeOFHeader(MESSAGE_TYPE, message, outBuffer, EncodeConstants.EMPTY_LENGTH);

    OFSerializer<MatchV10> matchSerializer =
        registry.getSerializer(new MessageTypeKey<>(message.getVersion(), MatchV10.class));

    matchSerializer.serialize(message.getMatchV10(), outBuffer);

    outBuffer.writeLong(message.getCookie().longValue());
    outBuffer.writeShort(message.getPriority());
    outBuffer.writeByte(message.getReason().getIntValue());
    outBuffer.writeZero(PADDING);
    outBuffer.writeInt(message.getDurationSec().intValue());
    outBuffer.writeInt(message.getDurationNsec().intValue());
    outBuffer.writeShort(message.getIdleTimeout());
    outBuffer.writeZero(PADDING);
    outBuffer.writeZero(PADDING);
    outBuffer.writeLong(message.getPacketCount().longValue());
    outBuffer.writeLong(message.getByteCount().longValue());
    ByteBufUtils.updateOFHeaderLength(outBuffer);
  }
 @Override
 public void write(ByteBuf bb, OFMeterFeaturesStatsReplyVer14 message) {
   // fixed value property version = 5
   bb.writeByte((byte) 0x5);
   // fixed value property type = 19
   bb.writeByte((byte) 0x13);
   // fixed value property length = 32
   bb.writeShort((short) 0x20);
   bb.writeInt(U32.t(message.xid));
   // fixed value property statsType = 11
   bb.writeShort((short) 0xb);
   OFStatsReplyFlagsSerializerVer14.writeTo(bb, message.flags);
   // pad: 4 bytes
   bb.writeZero(4);
   message.features.writeTo(bb);
 }
 @Override
 public void write(ByteBuf bb, OFBsnSetMirroringVer14 message) {
   // fixed value property version = 5
   bb.writeByte((byte) 0x5);
   // fixed value property type = 4
   bb.writeByte((byte) 0x4);
   // fixed value property length = 20
   bb.writeShort((short) 0x14);
   bb.writeInt(U32.t(message.xid));
   // fixed value property experimenter = 0x5c16c7L
   bb.writeInt(0x5c16c7);
   // fixed value property subtype = 0x3L
   bb.writeInt(0x3);
   bb.writeByte(U8.t(message.reportMirrorPorts));
   // pad: 3 bytes
   bb.writeZero(3);
 }
 @Override
 public void write(ByteBuf bb, OFBsnSetPktinSuppressionRequestVer12 message) {
   // fixed value property version = 3
   bb.writeByte((byte) 0x3);
   // fixed value property type = 4
   bb.writeByte((byte) 0x4);
   // fixed value property length = 32
   bb.writeShort((short) 0x20);
   bb.writeInt(U32.t(message.xid));
   // fixed value property experimenter = 0x5c16c7L
   bb.writeInt(0x5c16c7);
   // fixed value property subtype = 0xbL
   bb.writeInt(0xb);
   bb.writeByte(message.enabled ? 1 : 0);
   // pad: 1 bytes
   bb.writeZero(1);
   bb.writeShort(U16.t(message.idleTimeout));
   bb.writeShort(U16.t(message.hardTimeout));
   bb.writeShort(U16.t(message.priority));
   bb.writeLong(message.cookie.getValue());
 }
    @Override
    public void write(ByteBuf bb, OFMeterStatsReplyVer14 message) {
      int startIndex = bb.writerIndex();
      // fixed value property version = 5
      bb.writeByte((byte) 0x5);
      // 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 = 9
      bb.writeShort((short) 0x9);
      OFStatsReplyFlagsSerializerVer14.writeTo(bb, message.flags);
      // pad: 4 bytes
      bb.writeZero(4);
      ChannelUtils.writeList(bb, message.entries);

      // update length field
      int length = bb.writerIndex() - startIndex;
      bb.setShort(lengthIndex, length);
    }
 @Override
 public ByteBuf writeZero(int var1) {
   return a.writeZero(var1);
 }
Example #30
0
 @Override
 public ByteBuf writeZero(int length) {
   return buf.writeZero(length);
 }