use of org.opendaylight.openflowjava.protocol.api.keys.MessageCodeKey in project openflowplugin by opendaylight.
the class CodeKeyMakerFactoryTest method testExperimenterMatchEntriesKeyMaker.
/**
* Tests {@link CodeKeyMakerFactory#createMatchEntriesKeyMaker(short)}.
*/
@Test
public void testExperimenterMatchEntriesKeyMaker() {
CodeKeyMaker keyMaker = CodeKeyMakerFactory.createMatchEntriesKeyMaker(EncodeConstants.OF13_VERSION_ID);
Assert.assertNotNull("Null key maker", keyMaker);
ByteBuf buffer = BufferHelper.buildBuffer("FF FF 00 04 00 00 00 01");
// skip XID
buffer.skipBytes(4);
MessageCodeKey codeKey = keyMaker.make(buffer);
Assert.assertNotNull("Null key", codeKey);
MatchEntryDeserializerKey comparationKey = new MatchEntryDeserializerKey(EncodeConstants.OF13_VERSION_ID, 65535, 0);
comparationKey.setExperimenterId(1L);
Assert.assertEquals("Wrong key", comparationKey, codeKey);
Assert.assertEquals("Buffer index modified", 8, buffer.readableBytes());
}
use of org.opendaylight.openflowjava.protocol.api.keys.MessageCodeKey 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.openflowjava.protocol.api.keys.MessageCodeKey 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.openflowjava.protocol.api.keys.MessageCodeKey in project openflowplugin by opendaylight.
the class FlowRemovedMessageFactory method deserialize.
@Override
// FB doesn't recognize Objects.requireNonNull
@SuppressFBWarnings("UWF_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR")
public FlowRemovedMessage deserialize(ByteBuf rawMessage) {
Objects.requireNonNull(registry);
FlowRemovedMessageBuilder builder = new FlowRemovedMessageBuilder();
builder.setVersion((short) EncodeConstants.OF13_VERSION_ID);
builder.setXid(rawMessage.readUnsignedInt());
byte[] cookie = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
rawMessage.readBytes(cookie);
builder.setCookie(new BigInteger(1, cookie));
builder.setPriority(rawMessage.readUnsignedShort());
builder.setReason(FlowRemovedReason.forValue(rawMessage.readUnsignedByte()));
builder.setTableId(new TableId((long) rawMessage.readUnsignedByte()));
builder.setDurationSec(rawMessage.readUnsignedInt());
builder.setDurationNsec(rawMessage.readUnsignedInt());
builder.setIdleTimeout(rawMessage.readUnsignedShort());
builder.setHardTimeout(rawMessage.readUnsignedShort());
byte[] packetCount = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
rawMessage.readBytes(packetCount);
builder.setPacketCount(new BigInteger(1, packetCount));
byte[] byteCount = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
rawMessage.readBytes(byteCount);
builder.setByteCount(new BigInteger(1, byteCount));
OFDeserializer<Match> matchDeserializer = registry.getDeserializer(new MessageCodeKey(EncodeConstants.OF13_VERSION_ID, EncodeConstants.EMPTY_VALUE, Match.class));
builder.setMatch(matchDeserializer.deserialize(rawMessage));
return builder.build();
}
use of org.opendaylight.openflowjava.protocol.api.keys.MessageCodeKey in project openflowplugin by opendaylight.
the class DeserializerRegistryImpl method init.
/**
* Decoder table provisioning.
*/
@Override
public void init() {
registry = new HashMap<>();
// register message deserializers
MessageDeserializerInitializer.registerMessageDeserializers(this);
// register additional message deserializers
AdditionalMessageDeserializerInitializer.registerMessageDeserializers(this);
// register common structure deserializers
registerDeserializer(new MessageCodeKey(EncodeConstants.OF10_VERSION_ID, EncodeConstants.EMPTY_VALUE, MatchV10.class), new OF10MatchDeserializer());
registerDeserializer(new MessageCodeKey(EncodeConstants.OF13_VERSION_ID, EncodeConstants.EMPTY_VALUE, Match.class), new MatchDeserializer());
// register match entry deserializers
MatchEntryDeserializerInitializer.registerMatchEntryDeserializers(this);
// register action deserializers
ActionDeserializerInitializer.registerDeserializers(this);
// register instruction deserializers
InstructionDeserializerInitializer.registerDeserializers(this);
}
Aggregations