use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.ofj.nx.action.learn.grouping.nx.action.learn.FlowMods in project openflowplugin by opendaylight.
the class LearnCodecUtil method serializeFlowMods.
static void serializeFlowMods(final ByteBuf outBuffer, ActionLearn action) {
if (action.getNxActionLearn().getFlowMods() != null) {
for (FlowMods flowMod : action.getNxActionLearn().getFlowMods()) {
if (flowMod.getFlowModSpec() instanceof FlowModAddMatchFromFieldCase) {
FlowModAddMatchFromField flowModSpecFromField = ((FlowModAddMatchFromFieldCase) flowMod.getFlowModSpec()).getFlowModAddMatchFromField();
toFlowModSpecHeader(flowModSpecFromField, outBuffer);
outBuffer.writeInt(flowModSpecFromField.getSrcField().intValue());
outBuffer.writeShort(flowModSpecFromField.getSrcOfs().shortValue());
outBuffer.writeInt(flowModSpecFromField.getDstField().intValue());
outBuffer.writeShort(flowModSpecFromField.getDstOfs().shortValue());
} else if (flowMod.getFlowModSpec() instanceof FlowModAddMatchFromValueCase) {
FlowModAddMatchFromValue flowModSpec = ((FlowModAddMatchFromValueCase) flowMod.getFlowModSpec()).getFlowModAddMatchFromValue();
toFlowModSpecHeader(flowModSpec, outBuffer);
outBuffer.writeShort(flowModSpec.getValue().shortValue());
outBuffer.writeInt(flowModSpec.getSrcField().intValue());
outBuffer.writeShort(flowModSpec.getSrcOfs().shortValue());
} else if (flowMod.getFlowModSpec() instanceof FlowModCopyFieldIntoFieldCase) {
FlowModCopyFieldIntoField flowModSpec = ((FlowModCopyFieldIntoFieldCase) flowMod.getFlowModSpec()).getFlowModCopyFieldIntoField();
toFlowModSpecHeader(flowModSpec, outBuffer);
outBuffer.writeInt(flowModSpec.getSrcField().intValue());
outBuffer.writeShort(flowModSpec.getSrcOfs().shortValue());
outBuffer.writeInt(flowModSpec.getDstField().intValue());
outBuffer.writeShort(flowModSpec.getDstOfs().shortValue());
} else if (flowMod.getFlowModSpec() instanceof FlowModCopyValueIntoFieldCase) {
FlowModCopyValueIntoField flowModSpec = ((FlowModCopyValueIntoFieldCase) flowMod.getFlowModSpec()).getFlowModCopyValueIntoField();
toFlowModSpecHeader(flowModSpec, outBuffer);
outBuffer.writeShort(flowModSpec.getValue().shortValue());
outBuffer.writeInt(flowModSpec.getDstField().intValue());
outBuffer.writeShort(flowModSpec.getDstOfs().shortValue());
} else if (flowMod.getFlowModSpec() instanceof FlowModOutputToPortCase) {
FlowModOutputToPort flowModSpec = ((FlowModOutputToPortCase) flowMod.getFlowModSpec()).getFlowModOutputToPort();
toFlowModSpecHeader(flowModSpec, outBuffer);
outBuffer.writeInt(flowModSpec.getSrcField().intValue());
outBuffer.writeShort(flowModSpec.getSrcOfs().shortValue());
}
}
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.ofj.nx.action.learn.grouping.nx.action.learn.FlowMods in project openflowplugin by opendaylight.
the class LearnCodecUtil method buildFlowModSpecs.
static synchronized void buildFlowModSpecs(NxActionLearnBuilder nxActionLearnBuilder, ByteBuf message, short messageLength) {
LearnCodecUtil.length = messageLength;
List<FlowMods> flowModeList = new ArrayList<>();
while (LearnCodecUtil.length > 0) {
FlowMods flowMod = readFlowMod(message);
if (flowMod != null) {
flowModeList.add(flowMod);
} else {
LOG.trace("skipping padding bytes");
}
}
if (LearnCodecUtil.length != 0) {
LOG.error("Learn Codec read " + Math.abs(messageLength) + " bytes more than needed from stream. Packet might be corrupted");
}
nxActionLearnBuilder.setFlowMods(flowModeList);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.ofj.nx.action.learn.grouping.nx.action.learn.FlowMods in project openflowplugin by opendaylight.
the class LearnCodecTest method createFlowMods.
private List<FlowMods> createFlowMods() {
final List<FlowMods> flowMods = new ArrayList<>();
// length = 14
final FlowModsBuilder flowMod = new FlowModsBuilder();
FlowModAddMatchFromFieldBuilder spec = new FlowModAddMatchFromFieldBuilder();
spec.setFlowModNumBits(48);
spec.setSrcField((long) 9);
spec.setSrcOfs(10);
spec.setDstField((long) 11);
spec.setDstOfs(12);
FlowModAddMatchFromFieldCaseBuilder caseBuilder = new FlowModAddMatchFromFieldCaseBuilder();
caseBuilder.setFlowModAddMatchFromField(spec.build());
flowMod.setFlowModSpec(caseBuilder.build());
flowMods.add(flowMod.build());
// length = 14
final FlowModsBuilder flowMod2 = new FlowModsBuilder();
FlowModCopyFieldIntoFieldBuilder spec2 = new FlowModCopyFieldIntoFieldBuilder();
spec2.setFlowModNumBits(48);
spec2.setSrcField((long) 9);
spec2.setSrcOfs(10);
spec2.setDstField((long) 11);
spec2.setDstOfs(12);
FlowModCopyFieldIntoFieldCaseBuilder caseBuilder2 = new FlowModCopyFieldIntoFieldCaseBuilder();
caseBuilder2.setFlowModCopyFieldIntoField(spec2.build());
flowMod2.setFlowModSpec(caseBuilder2.build());
flowMods.add(flowMod2.build());
// length = 10
final FlowModsBuilder flowMod3 = new FlowModsBuilder();
FlowModCopyValueIntoFieldBuilder spec3 = new FlowModCopyValueIntoFieldBuilder();
spec3.setFlowModNumBits(48);
spec3.setValue(9);
spec3.setDstField((long) 10);
spec3.setDstOfs(11);
FlowModCopyValueIntoFieldCaseBuilder caseBuilder3 = new FlowModCopyValueIntoFieldCaseBuilder();
caseBuilder3.setFlowModCopyValueIntoField(spec3.build());
flowMod3.setFlowModSpec(caseBuilder3.build());
flowMods.add(flowMod3.build());
// length = 10
final FlowModsBuilder flowMod4 = new FlowModsBuilder();
FlowModAddMatchFromValueBuilder spec4 = new FlowModAddMatchFromValueBuilder();
spec4.setFlowModNumBits(48);
spec4.setValue(9);
spec4.setSrcField((long) 10);
spec4.setSrcOfs(11);
FlowModAddMatchFromValueCaseBuilder caseBuilder4 = new FlowModAddMatchFromValueCaseBuilder();
caseBuilder4.setFlowModAddMatchFromValue(spec4.build());
flowMod4.setFlowModSpec(caseBuilder4.build());
flowMods.add(flowMod4.build());
// length = 8
final FlowModsBuilder flowMod5 = new FlowModsBuilder();
FlowModOutputToPortBuilder spec5 = new FlowModOutputToPortBuilder();
spec5.setFlowModNumBits(48);
spec5.setSrcField((long) 9);
spec5.setSrcOfs(10);
FlowModOutputToPortCaseBuilder caseBuilder5 = new FlowModOutputToPortCaseBuilder();
caseBuilder5.setFlowModOutputToPort(spec5.build());
flowMod5.setFlowModSpec(caseBuilder5.build());
flowMods.add(flowMod5.build());
return flowMods;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.ofj.nx.action.learn.grouping.nx.action.learn.FlowMods in project openflowplugin by opendaylight.
the class LearnCodecUtil method readFlowToPort.
private static FlowMods readFlowToPort(ByteBuf message, short numBits) {
FlowModOutputToPortBuilder builder = new FlowModOutputToPortBuilder();
builder.setSrcField((long) message.readInt());
builder.setSrcOfs((int) message.readShort());
builder.setFlowModNumBits((int) numBits);
length -= TO_PORT_LENGTH - EncodeConstants.SIZE_OF_SHORT_IN_BYTES;
FlowModsBuilder flowModsBuilder = new FlowModsBuilder();
FlowModOutputToPortCaseBuilder caseBuilder = new FlowModOutputToPortCaseBuilder();
caseBuilder.setFlowModOutputToPort(builder.build());
flowModsBuilder.setFlowModSpec(caseBuilder.build());
return flowModsBuilder.build();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.ofj.nx.action.learn.grouping.nx.action.learn.FlowMods in project openflowplugin by opendaylight.
the class LearnCodecUtil method readFlowModAddMatchFromField.
private static FlowMods readFlowModAddMatchFromField(ByteBuf message, short numBits) {
FlowModAddMatchFromFieldBuilder builder = new FlowModAddMatchFromFieldBuilder();
builder.setSrcField((long) message.readInt());
builder.setSrcOfs((int) message.readShort());
builder.setDstField((long) message.readInt());
builder.setDstOfs((int) message.readShort());
builder.setFlowModNumBits((int) numBits);
length -= FROM_FIELD_LENGTH - EncodeConstants.SIZE_OF_SHORT_IN_BYTES;
FlowModsBuilder flowModsBuilder = new FlowModsBuilder();
FlowModAddMatchFromFieldCaseBuilder caseBuilder = new FlowModAddMatchFromFieldCaseBuilder();
caseBuilder.setFlowModAddMatchFromField(builder.build());
flowModsBuilder.setFlowModSpec(caseBuilder.build());
return flowModsBuilder.build();
}
Aggregations