use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.output.action._case.OutputAction in project openflowplugin by opendaylight.
the class OutputActionSerializer method serialize.
@Override
public void serialize(OutputActionCase action, ByteBuf outBuffer) {
super.serialize(action, outBuffer);
final OutputAction outputAction = action.getOutputAction();
Long value = InventoryDataServiceUtil.portNumberfromNodeConnectorId(OpenflowVersion.OF13, outputAction.getOutputNodeConnector().getValue());
if (value == null) {
throw new IllegalArgumentException("Not a valid port number: " + outputAction.getOutputNodeConnector().getValue());
}
outBuffer.writeInt(value.intValue());
outBuffer.writeShort(MoreObjects.firstNonNull(outputAction.getMaxLength(), 0));
outBuffer.writeZero(ActionConstants.OUTPUT_PADDING);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.output.action._case.OutputAction in project openflowplugin by opendaylight.
the class OutputActionDeserializerTest method testDeserialize.
@Test
public void testDeserialize() throws Exception {
final ByteBuf in = UnpooledByteBufAllocator.DEFAULT.buffer();
final int portNum = 10;
final short maxLength = 24;
writeHeader(in);
in.writeInt(portNum);
in.writeShort(maxLength);
in.writeZero(ActionConstants.OUTPUT_PADDING);
final Action action = deserializeAction(in);
assertTrue(OutputActionCase.class.isInstance(action));
final OutputAction outputAction = OutputActionCase.class.cast(action).getOutputAction();
assertEquals(portNum, InventoryDataServiceUtil.portNumberfromNodeConnectorId(OpenflowVersion.OF13, outputAction.getOutputNodeConnector().getValue()).intValue());
assertEquals(maxLength, outputAction.getMaxLength().shortValue());
assertEquals(0, in.readableBytes());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.output.action._case.OutputAction in project openflowplugin by opendaylight.
the class SalToOfOutputActionCase method process.
@Nonnull
@Override
public Optional<Action> process(@Nonnull final OutputActionCase source, final ActionConvertorData data, ConvertorExecutor convertorExecutor) {
final OutputAction outputAction = source.getOutputAction();
final OutputActionBuilder outputBuilder = new OutputActionBuilder();
if (outputAction.getMaxLength() != null) {
outputBuilder.setMaxLength(outputAction.getMaxLength());
} else {
outputBuilder.setMaxLength(0);
}
final OpenflowVersion version = OpenflowVersion.get(data.getVersion());
final String nodeConnectorId = outputAction.getOutputNodeConnector().getValue();
final Long portNumber = InventoryDataServiceUtil.portNumberfromNodeConnectorId(version, nodeConnectorId);
if (OpenflowPortsUtil.checkPortValidity(version, portNumber)) {
outputBuilder.setPort(new PortNumber(portNumber));
} else {
LOG.error("Invalid Port specified {} for Output Action for OF version: {}", portNumber, version);
}
return Optional.of(new ActionBuilder().setActionChoice(new OutputActionCaseBuilder().setOutputAction(outputBuilder.build()).build()).build());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.output.action._case.OutputAction in project openflowplugin by opendaylight.
the class OfToSalOutputActionCase method process.
@Override
public Optional<Action> process(@Nonnull final OutputActionCase source, final ActionResponseConvertorData data, ConvertorExecutor convertorExecutor) {
final OpenflowVersion ofVersion = OpenflowVersion.get(data.getVersion());
OutputActionBuilder outputAction = new OutputActionBuilder();
OutputAction outputActionFromOF = source.getOutputAction();
if (outputActionFromOF.getPort() != null) {
PortNumberUni protocolAgnosticPort = OpenflowPortsUtil.getProtocolAgnosticPort(ofVersion, outputActionFromOF.getPort().getValue());
String portNumberAsString = OpenflowPortsUtil.portNumberToString(protocolAgnosticPort);
outputAction.setOutputNodeConnector(new Uri(portNumberAsString));
} else {
LOG.error("Provided action is not OF Output action, no associated port found!");
}
Integer maxLength = outputActionFromOF.getMaxLength();
if (maxLength != null) {
outputAction.setMaxLength(maxLength);
} else {
LOG.error("Provided action is not OF Output action, no associated length found!");
}
OutputActionCaseBuilder outputActionCaseBuilder = new OutputActionCaseBuilder();
outputActionCaseBuilder.setOutputAction(outputAction.build());
return Optional.of(outputActionCaseBuilder.build());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.output.action._case.OutputAction in project openflowplugin by opendaylight.
the class ActionConvertorV10Test method testToMDSalActions.
/**
* Test {@link ActionResponseConvertor#convert(List, ActionResponseConvertorData)}}.
*/
@Test
public void testToMDSalActions() {
OutputActionCaseBuilder caseBuilder = new OutputActionCaseBuilder();
OutputActionBuilder outputBuilder = new OutputActionBuilder();
outputBuilder.setPort(new org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber(14L));
outputBuilder.setMaxLength(555);
caseBuilder.setOutputAction(outputBuilder.build());
org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder actionBuilder = new org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder();
actionBuilder.setActionChoice(caseBuilder.build());
List<org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action> actions = new ArrayList<>();
actions.add(actionBuilder.build());
ActionResponseConvertorData data = new ActionResponseConvertorData(OFConstants.OFP_VERSION_1_0);
data.setActionPath(ActionPath.FLOWS_STATISTICS_UPDATE_APPLY_ACTIONS);
Optional<List<org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action>> mdSalActionsOptional = convertorManager.convert(actions, data);
List<org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action> mdSalActions = mdSalActionsOptional.orElse(Collections.emptyList());
Assert.assertEquals("Wrong number of output actions", 1, mdSalActions.size());
org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action action = mdSalActions.get(0);
Assert.assertEquals("Wrong action type", "org.opendaylight.yang.gen.v1.urn.opendaylight.action.types" + ".rev131112.action.action.OutputActionCase", action.getImplementedInterface().getName());
OutputActionCase outputAction = (OutputActionCase) action;
Assert.assertEquals("Wrong output port", "14", outputAction.getOutputAction().getOutputNodeConnector().getValue());
Assert.assertEquals("Wrong max length", 555, outputAction.getOutputAction().getMaxLength().intValue());
}
Aggregations