Example usage for io.netty.buffer ByteBuf readLong

List of usage examples for io.netty.buffer ByteBuf readLong

Introduction

In this page you can find the example usage for io.netty.buffer ByteBuf readLong.

Prototype

public abstract long readLong();

Source Link

Document

Gets a 64-bit integer at the current readerIndex and increases the readerIndex by 8 in this buffer.

Usage

From source file:org.opendaylight.netide.openflowjava.protocol.impl.serialization.factories.OF10StatsReplyMessageFactoryTest.java

License:Open Source License

@Test
public void testFlowBodySerialize() {
    builder.setType(MultipartType.forValue(1));
    MultipartReplyFlowCaseBuilder flowCase = new MultipartReplyFlowCaseBuilder();
    MultipartReplyFlowBuilder flow = new MultipartReplyFlowBuilder();
    flow.setFlowStats(createFlowStats());
    flowCase.setMultipartReplyFlow(flow.build());
    builder.setMultipartReplyBody(flowCase.build());
    message = builder.build();//from   ww  w  . j  a v a  2s  .c o  m
    OF10StatsReplyMessageFactory serializer = new OF10StatsReplyMessageFactory();
    SerializerRegistry registry = new NetIdeSerializerRegistryImpl();
    registry.init();
    serializer.injectSerializerRegistry(registry);
    ByteBuf serializedBuffer = UnpooledByteBufAllocator.DEFAULT.buffer();
    serializer.serialize(message, serializedBuffer);
    BufferHelper.checkHeaderV10(serializedBuffer, MESSAGE_TYPE, 108);
    Assert.assertEquals("Wrong type", MultipartType.OFPMPFLOW.getIntValue(), serializedBuffer.readShort());
    Assert.assertEquals("Wrong flags", message.getFlags(),
            createMultipartRequestFlags(serializedBuffer.readShort()));
    FlowStats flowStats = flow.getFlowStats().get(0);
    Assert.assertEquals("Wrong length", 96, serializedBuffer.readShort());
    Assert.assertEquals("Wrong Table ID", flowStats.getTableId().intValue(),
            serializedBuffer.readUnsignedByte());
    serializedBuffer.skipBytes(1);
    Assert.assertEquals("Wrong wildcards", 3678463, serializedBuffer.readUnsignedInt());
    Assert.assertEquals("Wrong inPort", 58, serializedBuffer.readUnsignedShort());
    byte[] dlSrc = new byte[6];
    serializedBuffer.readBytes(dlSrc);
    Assert.assertEquals("Wrong dlSrc", "01:01:01:01:01:01", ByteBufUtils.macAddressToString(dlSrc));
    byte[] dlDst = new byte[6];
    serializedBuffer.readBytes(dlDst);
    Assert.assertEquals("Wrong dlDst", "FF:FF:FF:FF:FF:FF", ByteBufUtils.macAddressToString(dlDst));
    Assert.assertEquals("Wrong dlVlan", 18, serializedBuffer.readUnsignedShort());
    Assert.assertEquals("Wrong dlVlanPcp", 5, serializedBuffer.readUnsignedByte());
    serializedBuffer.skipBytes(1);
    Assert.assertEquals("Wrong dlType", 42, serializedBuffer.readUnsignedShort());
    Assert.assertEquals("Wrong nwTos", 4, serializedBuffer.readUnsignedByte());
    Assert.assertEquals("Wrong nwProto", 7, serializedBuffer.readUnsignedByte());
    serializedBuffer.skipBytes(2);
    Assert.assertEquals("Wrong nwSrc", 134744072, serializedBuffer.readUnsignedInt());
    Assert.assertEquals("Wrong nwDst", 269488144, serializedBuffer.readUnsignedInt());
    Assert.assertEquals("Wrong tpSrc", 6653, serializedBuffer.readUnsignedShort());
    Assert.assertEquals("Wrong tpDst", 6633, serializedBuffer.readUnsignedShort());
    Assert.assertEquals("Wrong duration sec", flowStats.getDurationSec().intValue(),
            serializedBuffer.readInt());
    Assert.assertEquals("Wrong duration nsec", flowStats.getDurationNsec().intValue(),
            serializedBuffer.readInt());
    Assert.assertEquals("Wrong priority", flowStats.getPriority().intValue(), serializedBuffer.readShort());
    Assert.assertEquals("Wrong idle timeout", flowStats.getIdleTimeout().intValue(),
            serializedBuffer.readShort());
    Assert.assertEquals("Wrong hard timeout", flowStats.getHardTimeout().intValue(),
            serializedBuffer.readShort());
    serializedBuffer.skipBytes(6);
    Assert.assertEquals("Wrong cookie", flowStats.getCookie().longValue(), serializedBuffer.readLong());
    Assert.assertEquals("Wrong Packet count", flowStats.getPacketCount().longValue(),
            serializedBuffer.readLong());
    Assert.assertEquals("Wrong Byte count", flowStats.getByteCount().longValue(), serializedBuffer.readLong());
    Assert.assertEquals("Wrong action type", 0, serializedBuffer.readUnsignedShort());
    Assert.assertEquals("Wrong action length", 8, serializedBuffer.readUnsignedShort());
    Assert.assertEquals("Wrong port", 42, serializedBuffer.readUnsignedShort());
    Assert.assertEquals("Wrong maxlength", 50, serializedBuffer.readUnsignedShort());
}

From source file:org.opendaylight.netide.openflowjava.protocol.impl.serialization.factories.OF10StatsReplyMessageFactoryTest.java

License:Open Source License

@Test
public void testAggregateBodySerialize() {
    builder.setType(MultipartType.forValue(2));
    MultipartReplyAggregateCaseBuilder aggregateCase = new MultipartReplyAggregateCaseBuilder();
    MultipartReplyAggregateBuilder aggregate = new MultipartReplyAggregateBuilder();
    aggregate.setPacketCount(BigInteger.valueOf(1234L));
    aggregate.setByteCount(BigInteger.valueOf(1234L));
    aggregate.setFlowCount(1L);//from  w w  w .ja va2s  .  c o m
    aggregateCase.setMultipartReplyAggregate(aggregate.build());
    builder.setMultipartReplyBody(aggregateCase.build());
    message = builder.build();
    OF10StatsReplyMessageFactory serializer = new OF10StatsReplyMessageFactory();
    SerializerRegistry registry = new NetIdeSerializerRegistryImpl();
    registry.init();
    serializer.injectSerializerRegistry(registry);
    ByteBuf serializedBuffer = UnpooledByteBufAllocator.DEFAULT.buffer();
    serializer.serialize(message, serializedBuffer);
    BufferHelper.checkHeaderV10(serializedBuffer, MESSAGE_TYPE, 36);
    Assert.assertEquals("Wrong type", MultipartType.OFPMPAGGREGATE.getIntValue(), serializedBuffer.readShort());
    Assert.assertEquals("Wrong flags", message.getFlags(),
            createMultipartRequestFlags(serializedBuffer.readShort()));
    Assert.assertEquals("Wrong Packet count", 1234L, serializedBuffer.readLong());
    Assert.assertEquals("Wrong Byte count", 1234L, serializedBuffer.readLong());
    Assert.assertEquals("Wrong flow count", 1L, serializedBuffer.readInt());
    serializedBuffer.skipBytes(4);
}

From source file:org.opendaylight.netide.openflowjava.protocol.impl.serialization.factories.OF10StatsReplyMessageFactoryTest.java

License:Open Source License

@Test
public void testTableBodySerialize() {
    builder.setType(MultipartType.forValue(3));
    MultipartReplyTableCaseBuilder tableCase = new MultipartReplyTableCaseBuilder();
    MultipartReplyTableBuilder table = new MultipartReplyTableBuilder();
    table.setTableStats(createTableStats());
    tableCase.setMultipartReplyTable(table.build());
    builder.setMultipartReplyBody(tableCase.build());
    message = builder.build();/*from www  .j  av a2  s.com*/
    OF10StatsReplyMessageFactory serializer = new OF10StatsReplyMessageFactory();
    SerializerRegistry registry = new NetIdeSerializerRegistryImpl();
    registry.init();
    serializer.injectSerializerRegistry(registry);
    ByteBuf serializedBuffer = UnpooledByteBufAllocator.DEFAULT.buffer();
    serializer.serialize(message, serializedBuffer);
    BufferHelper.checkHeaderV10(serializedBuffer, MESSAGE_TYPE, 60);
    Assert.assertEquals("Wrong type", MultipartType.OFPMPTABLE.getIntValue(), serializedBuffer.readShort());
    Assert.assertEquals("Wrong flags", message.getFlags(),
            createMultipartRequestFlags(serializedBuffer.readShort()));
    Assert.assertEquals("Wrong table id", 1, serializedBuffer.readUnsignedByte());
    serializedBuffer.skipBytes(3);
    Assert.assertEquals("Wrong name", "Table name",
            ByteBufUtils.decodeNullTerminatedString(serializedBuffer, 16));
    Assert.assertEquals("Wrong wildcards", 3145983, serializedBuffer.readUnsignedInt());
    Assert.assertEquals("Wrong max entries", 1L, serializedBuffer.readUnsignedInt());
    Assert.assertEquals("Wrong active count", 1L, serializedBuffer.readUnsignedInt());
    Assert.assertEquals("Wrong lookup count", 1234L, serializedBuffer.readLong());
    Assert.assertEquals("Wrong matched count", 1234L, serializedBuffer.readLong());
}

From source file:org.opendaylight.netide.openflowjava.protocol.impl.serialization.factories.OF10StatsReplyMessageFactoryTest.java

License:Open Source License

@Test
public void testPortStatsBodySerialize() {
    builder.setType(MultipartType.forValue(4));
    MultipartReplyPortStatsCaseBuilder portStatsCase = new MultipartReplyPortStatsCaseBuilder();
    MultipartReplyPortStatsBuilder portStats = new MultipartReplyPortStatsBuilder();
    portStats.setPortStats(createPortStats());
    portStatsCase.setMultipartReplyPortStats(portStats.build());
    builder.setMultipartReplyBody(portStatsCase.build());
    message = builder.build();/*www.j av  a 2s  .  com*/
    OF10StatsReplyMessageFactory serializer = new OF10StatsReplyMessageFactory();
    SerializerRegistry registry = new NetIdeSerializerRegistryImpl();
    registry.init();
    serializer.injectSerializerRegistry(registry);
    ByteBuf serializedBuffer = UnpooledByteBufAllocator.DEFAULT.buffer();
    serializer.serialize(message, serializedBuffer);
    BufferHelper.checkHeaderV10(serializedBuffer, MESSAGE_TYPE, 118);
    Assert.assertEquals("Wrong type", MultipartType.OFPMPPORTSTATS.getIntValue(), serializedBuffer.readShort());
    Assert.assertEquals("Wrong flags", message.getFlags(),
            createMultipartRequestFlags(serializedBuffer.readShort()));
    MultipartReplyPortStatsCase body = (MultipartReplyPortStatsCase) message.getMultipartReplyBody();
    MultipartReplyPortStats messageOutput = body.getMultipartReplyPortStats();
    PortStats portStatsOutput = messageOutput.getPortStats().get(0);
    Assert.assertEquals("Wrong port no", portStatsOutput.getPortNo().intValue(), serializedBuffer.readInt());
    serializedBuffer.skipBytes(6);
    Assert.assertEquals("Wrong rx packets", portStatsOutput.getRxPackets().longValue(),
            serializedBuffer.readLong());
    Assert.assertEquals("Wrong tx packets", portStatsOutput.getTxPackets().longValue(),
            serializedBuffer.readLong());
    Assert.assertEquals("Wrong rx bytes", portStatsOutput.getRxBytes().longValue(),
            serializedBuffer.readLong());
    Assert.assertEquals("Wrong tx bytes", portStatsOutput.getTxBytes().longValue(),
            serializedBuffer.readLong());
    Assert.assertEquals("Wrong rx dropped", portStatsOutput.getRxDropped().longValue(),
            serializedBuffer.readLong());
    Assert.assertEquals("Wrong tx dropped", portStatsOutput.getTxDropped().longValue(),
            serializedBuffer.readLong());
    Assert.assertEquals("Wrong rx errors", portStatsOutput.getRxErrors().longValue(),
            serializedBuffer.readLong());
    Assert.assertEquals("Wrong tx errors", portStatsOutput.getTxErrors().longValue(),
            serializedBuffer.readLong());
    Assert.assertEquals("Wrong rx frame err", portStatsOutput.getRxFrameErr().longValue(),
            serializedBuffer.readLong());
    Assert.assertEquals("Wrong rx over err", portStatsOutput.getRxOverErr().longValue(),
            serializedBuffer.readLong());
    Assert.assertEquals("Wrong rx crc err", portStatsOutput.getRxCrcErr().longValue(),
            serializedBuffer.readLong());
    Assert.assertEquals("Wrong collisions", portStatsOutput.getCollisions().longValue(),
            serializedBuffer.readLong());
}

From source file:org.opendaylight.netide.openflowjava.protocol.impl.serialization.factories.OF10StatsReplyMessageFactoryTest.java

License:Open Source License

@Test
public void testQueueBodySerialize() {
    builder.setType(MultipartType.forValue(5));
    MultipartReplyQueueCaseBuilder queueCase = new MultipartReplyQueueCaseBuilder();
    MultipartReplyQueueBuilder queue = new MultipartReplyQueueBuilder();
    queue.setQueueStats(createQueueStats());
    queueCase.setMultipartReplyQueue(queue.build());
    builder.setMultipartReplyBody(queueCase.build());
    message = builder.build();//from ww  w .ja v  a  2 s  .  c om
    OF10StatsReplyMessageFactory serializer = new OF10StatsReplyMessageFactory();
    SerializerRegistry registry = new NetIdeSerializerRegistryImpl();
    registry.init();
    serializer.injectSerializerRegistry(registry);
    ByteBuf serializedBuffer = UnpooledByteBufAllocator.DEFAULT.buffer();
    serializer.serialize(message, serializedBuffer);
    BufferHelper.checkHeaderV10(serializedBuffer, MESSAGE_TYPE, 44);
    Assert.assertEquals("Wrong type", MultipartType.OFPMPQUEUE.getIntValue(), serializedBuffer.readShort());
    Assert.assertEquals("Wrong flags", message.getFlags(),
            createMultipartRequestFlags(serializedBuffer.readShort()));
    MultipartReplyQueueCase body = (MultipartReplyQueueCase) message.getMultipartReplyBody();
    MultipartReplyQueue messageOutput = body.getMultipartReplyQueue();
    QueueStats queueStats = messageOutput.getQueueStats().get(0);
    Assert.assertEquals("Wrong length", 32, serializedBuffer.readUnsignedShort());
    serializedBuffer.skipBytes(2);
    Assert.assertEquals("Wrong queue id", queueStats.getQueueId().intValue(),
            serializedBuffer.readUnsignedInt());
    Assert.assertEquals("Wrong tx bytes", queueStats.getTxBytes().longValue(), serializedBuffer.readLong());
    Assert.assertEquals("Wrong tx packets", queueStats.getTxPackets().longValue(), serializedBuffer.readLong());
    Assert.assertEquals("Wrong tx errors", queueStats.getTxErrors().longValue(), serializedBuffer.readLong());
}

From source file:org.opendaylight.openflowjava.nx.codec.action.LearnCodecUtil.java

License:Open Source License

static void deserializeLearnHeader(final ByteBuf message, NxActionLearnBuilder nxActionLearnBuilder) {
    nxActionLearnBuilder.setIdleTimeout(message.readUnsignedShort());
    nxActionLearnBuilder.setHardTimeout(message.readUnsignedShort());
    nxActionLearnBuilder.setPriority(message.readUnsignedShort());
    nxActionLearnBuilder.setCookie(BigInteger.valueOf(message.readLong()));
    nxActionLearnBuilder.setFlags(message.readUnsignedShort());
    nxActionLearnBuilder.setTableId(message.readUnsignedByte());
    message.skipBytes(1);/*from  w w w .  ja  v  a  2 s  .  co m*/
    nxActionLearnBuilder.setFinIdleTimeout(message.readUnsignedShort());
    nxActionLearnBuilder.setFinHardTimeout(message.readUnsignedShort());
}

From source file:org.opendaylight.openflowjava.nx.codec.action.RegLoadCodec.java

License:Open Source License

@Override
public Action deserialize(final ByteBuf message) {
    ActionBuilder actionBuilder = deserializeHeader(message);
    NxActionRegLoadBuilder nxActionRegLoadBuilder = new NxActionRegLoadBuilder();
    ActionRegLoadBuilder actionRegLoadBuilder = new ActionRegLoadBuilder();
    nxActionRegLoadBuilder.setOfsNbits(message.readUnsignedShort());
    nxActionRegLoadBuilder.setDst(message.readUnsignedInt());
    nxActionRegLoadBuilder.setValue(BigInteger.valueOf(message.readLong()));
    actionRegLoadBuilder.setNxActionRegLoad(nxActionRegLoadBuilder.build());
    actionBuilder.setActionChoice(actionRegLoadBuilder.build());
    return actionBuilder.build();
}

From source file:org.opendaylight.openflowjava.nx.codec.match.MplsLabelCodec.java

License:Open Source License

@Override
public MatchEntry deserialize(ByteBuf message) {
    MatchEntryBuilder matchEntryBuilder = deserializeHeader(message);
    OfMplsLabelCaseValueBuilder caseBuilder = new OfMplsLabelCaseValueBuilder();
    MplsLabelValuesBuilder valuesBuilder = new MplsLabelValuesBuilder();
    valuesBuilder.setMplsLabel(message.readLong()).build();
    caseBuilder.setMplsLabelValues(valuesBuilder.build());
    matchEntryBuilder.setMatchEntryValue(caseBuilder.build());
    return matchEntryBuilder.build();
}

From source file:org.opendaylight.openflowjava.nx.codec.match.TunIdCodec.java

License:Open Source License

@Override
public MatchEntry deserialize(ByteBuf message) {
    MatchEntryBuilder matchEntriesBuilder = deserializeHeader(message);
    TunIdCaseValueBuilder caseBuilder = new TunIdCaseValueBuilder();
    TunIdValuesBuilder tunIdBuilder = new TunIdValuesBuilder();
    tunIdBuilder.setValue(BigInteger.valueOf(message.readLong()));
    caseBuilder.setTunIdValues(tunIdBuilder.build());
    matchEntriesBuilder.setMatchEntryValue(caseBuilder.build());
    return matchEntriesBuilder.build();
}

From source file:org.opendaylight.openflowjava.protocol.impl.serialization.factories.FlowRemovedMessageFactoryTest.java

License:Open Source License

@Test
public void testSerialize() throws Exception {
    FlowRemovedMessageBuilder builder = new FlowRemovedMessageBuilder();
    BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID);
    builder.setCookie(BigInteger.valueOf(1234L));
    builder.setPriority(1234);/*from   w  w w .  j  a  v a2s .  c om*/
    builder.setReason(FlowRemovedReason.forValue(2));
    builder.setTableId(new TableId(65L));
    builder.setDurationSec(1234L);
    builder.setDurationNsec(1234L);
    builder.setIdleTimeout(1234);
    builder.setHardTimeout(1234);
    builder.setPacketCount(BigInteger.valueOf(1234L));
    builder.setByteCount(BigInteger.valueOf(1234L));
    MatchBuilder matchBuilder = new MatchBuilder();
    matchBuilder.setType(OxmMatchType.class);
    List<MatchEntry> entries = new ArrayList<>();
    MatchEntryBuilder entriesBuilder = new MatchEntryBuilder();
    entriesBuilder.setOxmClass(OpenflowBasicClass.class);
    entriesBuilder.setOxmMatchField(InPhyPort.class);
    entriesBuilder.setHasMask(false);
    InPhyPortCaseBuilder inPhyPortCaseBuilder = new InPhyPortCaseBuilder();
    InPhyPortBuilder inPhyPortBuilder = new InPhyPortBuilder();
    inPhyPortBuilder.setPortNumber(new PortNumber(42L));
    inPhyPortCaseBuilder.setInPhyPort(inPhyPortBuilder.build());
    entriesBuilder.setMatchEntryValue(inPhyPortCaseBuilder.build());
    entries.add(entriesBuilder.build());
    entriesBuilder.setOxmClass(OpenflowBasicClass.class);
    entriesBuilder.setOxmMatchField(IpEcn.class);
    entriesBuilder.setHasMask(false);
    IpEcnCaseBuilder ipEcnCaseBuilder = new IpEcnCaseBuilder();
    IpEcnBuilder ipEcnBuilder = new IpEcnBuilder();
    ipEcnBuilder.setEcn((short) 4);
    ipEcnCaseBuilder.setIpEcn(ipEcnBuilder.build());
    entriesBuilder.setMatchEntryValue(ipEcnCaseBuilder.build());
    entries.add(entriesBuilder.build());
    matchBuilder.setMatchEntry(entries);
    builder.setMatch(matchBuilder.build());
    FlowRemovedMessage message = builder.build();
    ByteBuf serializedBuffer = UnpooledByteBufAllocator.DEFAULT.buffer();
    factory.serialize(message, serializedBuffer);

    BufferHelper.checkHeaderV13(serializedBuffer, MESSAGE_TYPE, 72);
    Assert.assertEquals("Wrong cookie", message.getCookie().longValue(), serializedBuffer.readLong());
    Assert.assertEquals("Wrong priority", message.getPriority().intValue(), serializedBuffer.readShort());
    Assert.assertEquals("Wrong reason", message.getReason().getIntValue(), serializedBuffer.readByte());
    Assert.assertEquals("Wrong Table ID", message.getTableId().getValue().intValue(),
            serializedBuffer.readUnsignedByte());
    Assert.assertEquals("Wrong duration sec", message.getDurationSec().intValue(), serializedBuffer.readInt());
    Assert.assertEquals("Wrong duration nsec", message.getDurationNsec().intValue(),
            serializedBuffer.readInt());
    Assert.assertEquals("Wrong Idle timeout", message.getIdleTimeout().intValue(),
            serializedBuffer.readShort());
    Assert.assertEquals("Wrong Hard timeout", message.getIdleTimeout().intValue(),
            serializedBuffer.readShort());
    Assert.assertEquals("Wrong Packet count", message.getPacketCount().longValue(),
            serializedBuffer.readLong());
    Assert.assertEquals("Wrong Byte count", message.getByteCount().longValue(), serializedBuffer.readLong());
    Assert.assertEquals("Wrong match type", 1, serializedBuffer.readUnsignedShort());
    serializedBuffer.skipBytes(EncodeConstants.SIZE_OF_SHORT_IN_BYTES);
    Assert.assertEquals("Wrong oxm class", 0x8000, serializedBuffer.readUnsignedShort());
    short fieldAndMask = serializedBuffer.readUnsignedByte();
    Assert.assertEquals("Wrong oxm hasMask", 0, fieldAndMask & 1);
    Assert.assertEquals("Wrong oxm field", 1, fieldAndMask >> 1);
    serializedBuffer.skipBytes(EncodeConstants.SIZE_OF_BYTE_IN_BYTES);
    Assert.assertEquals("Wrong oxm value", 42, serializedBuffer.readUnsignedInt());
    Assert.assertEquals("Wrong oxm class", 0x8000, serializedBuffer.readUnsignedShort());
    fieldAndMask = serializedBuffer.readUnsignedByte();
    Assert.assertEquals("Wrong oxm hasMask", 0, fieldAndMask & 1);
    Assert.assertEquals("Wrong oxm field", 9, fieldAndMask >> 1);
    serializedBuffer.skipBytes(EncodeConstants.SIZE_OF_BYTE_IN_BYTES);
    Assert.assertEquals("Wrong oxm value", 4, serializedBuffer.readUnsignedByte());
    serializedBuffer.skipBytes(7);
}