use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyFlowCaseBuilder in project openflowplugin by opendaylight.
the class MultipartReplyTranslatorUtilTest method translateFlow.
@Test
public void translateFlow() {
final MultipartReply multipartReply = buildReply(MultipartType.OFPMPFLOW, new MultipartReplyFlowCaseBuilder().setMultipartReplyFlow(new MultipartReplyFlowBuilder().build()).build());
dummyAssertReply(multipartReply);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyFlowCaseBuilder 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.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyFlowCaseBuilder in project openflowplugin by opendaylight.
the class MultipartReplyMessageFactory method setFlow.
private MultipartReplyFlowCase setFlow(final ByteBuf input) {
MultipartReplyFlowCaseBuilder caseBuilder = new MultipartReplyFlowCaseBuilder();
MultipartReplyFlowBuilder flowBuilder = new MultipartReplyFlowBuilder();
List<FlowStats> flowStatsList = new ArrayList<>();
while (input.readableBytes() > 0) {
FlowStatsBuilder flowStatsBuilder = new FlowStatsBuilder();
int flowRecordLength = input.readUnsignedShort();
ByteBuf subInput = input.readSlice(flowRecordLength - EncodeConstants.SIZE_OF_SHORT_IN_BYTES);
flowStatsBuilder.setTableId(subInput.readUnsignedByte());
subInput.skipBytes(PADDING_IN_FLOW_STATS_HEADER_01);
flowStatsBuilder.setDurationSec(subInput.readUnsignedInt());
flowStatsBuilder.setDurationNsec(subInput.readUnsignedInt());
flowStatsBuilder.setPriority(subInput.readUnsignedShort());
flowStatsBuilder.setIdleTimeout(subInput.readUnsignedShort());
flowStatsBuilder.setHardTimeout(subInput.readUnsignedShort());
flowStatsBuilder.setFlags(createFlowModFlagsFromBitmap(subInput.readUnsignedShort()));
subInput.skipBytes(PADDING_IN_FLOW_STATS_HEADER_02);
byte[] cookie = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
subInput.readBytes(cookie);
flowStatsBuilder.setCookie(new BigInteger(1, cookie));
byte[] packetCount = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
subInput.readBytes(packetCount);
flowStatsBuilder.setPacketCount(new BigInteger(1, packetCount));
byte[] byteCount = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
subInput.readBytes(byteCount);
flowStatsBuilder.setByteCount(new BigInteger(1, byteCount));
OFDeserializer<Match> matchDeserializer = registry.getDeserializer(new MessageCodeKey(EncodeConstants.OF13_VERSION_ID, EncodeConstants.EMPTY_VALUE, Match.class));
flowStatsBuilder.setMatch(matchDeserializer.deserialize(subInput));
CodeKeyMaker keyMaker = CodeKeyMakerFactory.createInstructionsKeyMaker(EncodeConstants.OF13_VERSION_ID);
List<Instruction> instructions = ListDeserializer.deserializeList(EncodeConstants.OF13_VERSION_ID, subInput.readableBytes(), subInput, keyMaker, registry);
flowStatsBuilder.setInstruction(instructions);
flowStatsList.add(flowStatsBuilder.build());
}
flowBuilder.setFlowStats(flowStatsList);
caseBuilder.setMultipartReplyFlow(flowBuilder.build());
return caseBuilder.build();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyFlowCaseBuilder in project openflowplugin by opendaylight.
the class OF10StatsReplyMessageFactory method setFlow.
private MultipartReplyFlowCase setFlow(ByteBuf input) {
MultipartReplyFlowCaseBuilder caseBuilder = new MultipartReplyFlowCaseBuilder();
MultipartReplyFlowBuilder flowBuilder = new MultipartReplyFlowBuilder();
List<FlowStats> flowStatsList = new ArrayList<>();
while (input.readableBytes() > 0) {
FlowStatsBuilder flowStatsBuilder = new FlowStatsBuilder();
final int length = input.readUnsignedShort();
flowStatsBuilder.setTableId(input.readUnsignedByte());
input.skipBytes(PADDING_IN_FLOW_STATS_HEADER);
OFDeserializer<MatchV10> matchDeserializer = registry.getDeserializer(new MessageCodeKey(EncodeConstants.OF10_VERSION_ID, EncodeConstants.EMPTY_VALUE, MatchV10.class));
flowStatsBuilder.setMatchV10(matchDeserializer.deserialize(input));
flowStatsBuilder.setDurationSec(input.readUnsignedInt());
flowStatsBuilder.setDurationNsec(input.readUnsignedInt());
flowStatsBuilder.setPriority(input.readUnsignedShort());
flowStatsBuilder.setIdleTimeout(input.readUnsignedShort());
flowStatsBuilder.setHardTimeout(input.readUnsignedShort());
input.skipBytes(PADDING_IN_FLOW_STATS_HEADER_02);
byte[] cookie = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
input.readBytes(cookie);
flowStatsBuilder.setCookie(new BigInteger(1, cookie));
byte[] packetCount = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
input.readBytes(packetCount);
flowStatsBuilder.setPacketCount(new BigInteger(1, packetCount));
byte[] byteCount = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
input.readBytes(byteCount);
flowStatsBuilder.setByteCount(new BigInteger(1, byteCount));
CodeKeyMaker keyMaker = CodeKeyMakerFactory.createActionsKeyMaker(EncodeConstants.OF10_VERSION_ID);
List<Action> actions = ListDeserializer.deserializeList(EncodeConstants.OF10_VERSION_ID, length - LENGTH_OF_FLOW_STATS, input, keyMaker, registry);
flowStatsBuilder.setAction(actions);
flowStatsList.add(flowStatsBuilder.build());
}
flowBuilder.setFlowStats(flowStatsList);
caseBuilder.setMultipartReplyFlow(flowBuilder.build());
return caseBuilder.build();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyFlowCaseBuilder in project openflowplugin by opendaylight.
the class MultipartReplyMessageFactoryTest method testFlowSerialize.
@Test
public void testFlowSerialize() throws Exception {
MultipartReplyMessageBuilder builder = new MultipartReplyMessageBuilder();
BufferHelper.setupHeader(builder, EncodeConstants.OF13_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.checkHeaderV13(serializedBuffer, MESSAGE_TYPE, 192);
Assert.assertEquals("Wrong type", MultipartType.OFPMPFLOW.getIntValue(), serializedBuffer.readShort());
Assert.assertEquals("Wrong flags", message.getFlags(), createMultipartRequestFlags(serializedBuffer.readShort()));
serializedBuffer.skipBytes(PADDING);
testFlowBody(message.getMultipartReplyBody(), serializedBuffer);
}
Aggregations