use of org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.Table in project openflowplugin by opendaylight.
the class OF10StatsReplyMessageFactoryTest method testFlowBodySerialize.
@Test
public void testFlowBodySerialize() throws Exception {
MultipartReplyMessageBuilder builder;
builder = new MultipartReplyMessageBuilder();
BufferHelper.setupHeader(builder, EncodeConstants.OF10_VERSION_ID);
builder.setFlags(new MultipartRequestFlags(true));
builder.setType(MultipartType.forValue(1));
MultipartReplyFlowCaseBuilder flowCase = new MultipartReplyFlowCaseBuilder();
MultipartReplyFlowBuilder flow = new MultipartReplyFlowBuilder();
flow.setFlowStats(createFlowStats());
flowCase.setMultipartReplyFlow(flow.build());
builder.setMultipartReplyBody(flowCase.build());
MultipartReplyMessage message = builder.build();
ByteBuf serializedBuffer = UnpooledByteBufAllocator.DEFAULT.buffer();
factory.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());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.Table in project openflowplugin by opendaylight.
the class OF10StatsRequestAggregateTest method test.
/**
* Tests {@link OF10StatsRequestInputFactory} for correct serialization.
*/
@Test
public void test() throws Exception {
MultipartRequestInputBuilder builder = new MultipartRequestInputBuilder();
BufferHelper.setupHeader(builder, EncodeConstants.OF10_VERSION_ID);
builder.setType(MultipartType.OFPMPAGGREGATE);
builder.setFlags(new MultipartRequestFlags(false));
final MultipartRequestAggregateCaseBuilder caseBuilder = new MultipartRequestAggregateCaseBuilder();
final MultipartRequestAggregateBuilder aggBuilder = new MultipartRequestAggregateBuilder();
MatchV10Builder matchBuilder = new MatchV10Builder();
matchBuilder.setWildcards(new FlowWildcardsV10(true, true, true, true, true, true, true, true, true, true));
matchBuilder.setNwSrcMask((short) 8);
matchBuilder.setNwDstMask((short) 16);
matchBuilder.setInPort(51);
matchBuilder.setDlSrc(new MacAddress("00:01:02:03:04:05"));
matchBuilder.setDlDst(new MacAddress("05:04:03:02:01:00"));
matchBuilder.setDlVlan(52);
matchBuilder.setDlVlanPcp((short) 53);
matchBuilder.setDlType(54);
matchBuilder.setNwTos((short) 55);
matchBuilder.setNwProto((short) 56);
matchBuilder.setNwSrc(new Ipv4Address("10.0.0.1"));
matchBuilder.setNwDst(new Ipv4Address("10.0.0.2"));
matchBuilder.setTpSrc(57);
matchBuilder.setTpDst(58);
aggBuilder.setMatchV10(matchBuilder.build());
aggBuilder.setTableId((short) 5);
aggBuilder.setOutPort(42L);
caseBuilder.setMultipartRequestAggregate(aggBuilder.build());
builder.setMultipartRequestBody(caseBuilder.build());
MultipartRequestInput message = builder.build();
ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
statsFactory.serialize(message, out);
BufferHelper.checkHeaderV10(out, (byte) 16, 56);
Assert.assertEquals("Wrong type", 2, out.readUnsignedShort());
Assert.assertEquals("Wrong flags", 0, out.readUnsignedShort());
// skip match check
out.skipBytes(40);
Assert.assertEquals("Wrong table-id", 5, out.readUnsignedByte());
out.skipBytes(1);
Assert.assertEquals("Wrong out port", 42, out.readUnsignedShort());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.Table in project openflowplugin by opendaylight.
the class MultipartReplyTableFeaturesTest method testMultipartReplyTableFeatures.
/**
* Testing {@link MultipartReplyMessageFactory} for correct translation into POJO.
*/
@Test
public void testMultipartReplyTableFeatures() {
ByteBuf bb = BufferHelper.buildBuffer(//
"00 0C 00 00 00 00 00 00 " + // first table feature
"00 40 01 00 00 00 00 00 " + // length, tableId, padding
"4F 70 65 6E 64 61 79 6C 69 67 68 74 00 00 00 00 00 00 00 " + //
"00 00 00 00 00 00 00 00 00 00 00 00 00 " + // name
"00 00 00 00 00 00 00 01 " + // metadata match
"00 00 00 00 00 00 00 02 " + // metadata write
"00 00 00 00 " + // config
"00 00 00 2A " + // second table feature
"00 40 02 00 00 00 00 00 " + // length, tableId, padding
"4F 70 65 6E 64 61 79 6C 69 67 68 74 00 00 00 00 00 00 00" + // name
" 00 00 00 00 00 00 00 00 00 00 00 00 00 " + // metadata match
"00 00 00 00 00 00 00 03 " + // metadata write
"00 00 00 00 00 00 00 04 " + // config
"00 00 00 03 " + // max entries
"00 00 00 2B");
MultipartReplyMessage builtByFactory = BufferHelper.deserialize(factory, bb);
BufferHelper.checkHeaderV13(builtByFactory);
Assert.assertEquals("Wrong type", 12, builtByFactory.getType().getIntValue());
Assert.assertEquals("Wrong flag", false, builtByFactory.getFlags().isOFPMPFREQMORE());
MultipartReplyTableFeaturesCase messageCase = (MultipartReplyTableFeaturesCase) builtByFactory.getMultipartReplyBody();
MultipartReplyTableFeatures message = messageCase.getMultipartReplyTableFeatures();
Assert.assertEquals("Wrong table features size", 2, message.getTableFeatures().size());
TableFeatures feature = message.getTableFeatures().get(0);
Assert.assertEquals("Wrong table id", 1, feature.getTableId().intValue());
Assert.assertEquals("Wrong name", "Opendaylight", feature.getName());
Assert.assertArrayEquals("Wrong metadata match", new byte[] { 0, 0, 0, 0, 0, 0, 0, 1 }, feature.getMetadataMatch());
Assert.assertArrayEquals("Wrong metadata write", new byte[] { 0, 0, 0, 0, 0, 0, 0, 2 }, feature.getMetadataWrite());
Assert.assertEquals("Wrong config", false, feature.getConfig().isOFPTCDEPRECATEDMASK());
Assert.assertEquals("Wrong max entries", 42, feature.getMaxEntries().intValue());
feature = message.getTableFeatures().get(1);
Assert.assertEquals("Wrong table id", 2, feature.getTableId().intValue());
Assert.assertEquals("Wrong name", "Opendaylight", feature.getName());
Assert.assertArrayEquals("Wrong metadata match", new byte[] { 0, 0, 0, 0, 0, 0, 0, 3 }, feature.getMetadataMatch());
Assert.assertArrayEquals("Wrong metadata write", new byte[] { 0, 0, 0, 0, 0, 0, 0, 4 }, feature.getMetadataWrite());
Assert.assertEquals("Wrong config", true, feature.getConfig().isOFPTCDEPRECATEDMASK());
Assert.assertEquals("Wrong max entries", 43, feature.getMaxEntries().intValue());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.Table in project openflowplugin by opendaylight.
the class MultipartReplyTableFeaturesTest method testEmptyMultipartReplyTableFeatures.
/**
* Testing {@link MultipartReplyMessageFactory} for correct translation into POJO.
*/
@Test
public void testEmptyMultipartReplyTableFeatures() {
ByteBuf bb = BufferHelper.buildBuffer("00 0C 00 00 00 00 00 00");
MultipartReplyMessage builtByFactory = BufferHelper.deserialize(factory, bb);
BufferHelper.checkHeaderV13(builtByFactory);
Assert.assertEquals("Wrong type", 12, builtByFactory.getType().getIntValue());
Assert.assertEquals("Wrong flag", false, builtByFactory.getFlags().isOFPMPFREQMORE());
MultipartReplyTableFeaturesCase messageCase = (MultipartReplyTableFeaturesCase) builtByFactory.getMultipartReplyBody();
MultipartReplyTableFeatures message = messageCase.getMultipartReplyTableFeatures();
Assert.assertEquals("Wrong table features size", 0, message.getTableFeatures().size());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.Table in project openflowplugin by opendaylight.
the class OF10StatsReplyMessageFactoryTest method testTable.
/**
* Testing OF10StatsReplyMessageFactory (Table) for correct deserialization.
*/
@Test
public void testTable() {
ByteBuf bb = BufferHelper.buildBuffer("00 03 00 01 " + "08 00 00 00 4A 41 4D 45 53 20 42 4F 4E 44 00 00 00 00 00 00 00 00 00 " + "00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 " + "00 00 00 30 00 00 00 10 FF 01 01 01 01 01 01 01 FF 01 01 01 01 01 01 00");
MultipartReplyMessage builtByFactory = BufferHelper.deserialize(statsFactory, bb);
BufferHelper.checkHeaderV10(builtByFactory);
Assert.assertEquals("Wrong type", 0x03, builtByFactory.getType().getIntValue());
Assert.assertEquals("Wrong flag", true, builtByFactory.getFlags().isOFPMPFREQMORE());
MultipartReplyTableCase messageCase = (MultipartReplyTableCase) builtByFactory.getMultipartReplyBody();
MultipartReplyTable message = messageCase.getMultipartReplyTable();
Assert.assertEquals("Wrong tableId", 8, message.getTableStats().get(0).getTableId().intValue());
Assert.assertEquals("Wrong name", "JAMES BOND", message.getTableStats().get(0).getName());
Assert.assertEquals("Wrong wildcards", new FlowWildcardsV10(false, false, false, false, false, false, false, false, false, false), message.getTableStats().get(0).getWildcards());
Assert.assertEquals("Wrong src-mask", 32, message.getTableStats().get(0).getNwSrcMask().intValue());
Assert.assertEquals("Wrong dst-mask", 32, message.getTableStats().get(0).getNwDstMask().intValue());
Assert.assertEquals("Wrong max-entries", 48, message.getTableStats().get(0).getMaxEntries().longValue());
Assert.assertEquals("Wrong activeCount", 16, message.getTableStats().get(0).getActiveCount().longValue());
Assert.assertEquals("Wrong lookupCount", new BigInteger(1, new byte[] { (byte) 0xFF, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 }), message.getTableStats().get(0).getLookupCount());
Assert.assertEquals("Wrong matchedCount", new BigInteger(1, new byte[] { (byte) 0xFF, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00 }), message.getTableStats().get(0).getMatchedCount());
Assert.assertTrue("Unread data", bb.readableBytes() == 0);
}
Aggregations