import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MeterIdInstructionBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.TableIdInstruction;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.TableIdInstructionBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.ActionsList;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instructions.Instructions;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instructions.InstructionsBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowModCommand;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.TableId;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.OxmMatchType;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.MatchEntries;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowModInput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowModInputBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import com.google.common.base.Objects;
+
/**
* Utility class for converting a MD-SAL Flow into the OF flow mod
*/
/** default match entries - empty */
public static final List<MatchEntries> DEFAULT_MATCH_ENTRIES = new ArrayList<MatchEntries>();
- public static FlowModInput toFlowModInput(Flow flow, short version) {
+ public static FlowModInputBuilder toFlowModInput(Flow flow, short version,BigInteger datapathid) {
FlowModInputBuilder flowMod = new FlowModInputBuilder();
if (flow.getCookie() != null) {
flowMod.setCookie(flow.getCookie());
if (flow instanceof AddFlowInput) {
flowMod.setCommand(FlowModCommand.OFPFCADD);
} else if (flow instanceof RemoveFlowInput) {
- if (flow.isStrict() != null && flow.isStrict()) {
+ if (Objects.firstNonNull(flow.isStrict(), Boolean.FALSE)) {
flowMod.setCommand(FlowModCommand.OFPFCDELETESTRICT);
} else {
flowMod.setCommand(FlowModCommand.OFPFCDELETE);
}
} else if (flow instanceof UpdatedFlow) {
- if (flow.isStrict() != null && flow.isStrict()) {
+ if (Objects.firstNonNull(flow.isStrict(), Boolean.FALSE)) {
flowMod.setCommand(FlowModCommand.OFPFCMODIFYSTRICT);
} else {
flowMod.setCommand(FlowModCommand.OFPFCMODIFY);
// convert and inject flowFlags
- FlowFlagReactor.getInstance().convert(flow.getFlags(), version, flowMod);
+ FlowFlagReactor.getInstance().convert(flow.getFlags(), version, flowMod,datapathid);
// convert and inject match
- MatchReactor.getInstance().convert(flow.getMatch(), version, flowMod);
+ MatchReactor.getInstance().convert(flow.getMatch(), version, flowMod,datapathid);
if (flow.getInstructions() != null) {
- flowMod.setInstructions(toInstructions(flow.getInstructions(), version));
+ flowMod.setInstructions(toInstructions(flow.getInstructions(), version,datapathid));
+ flowMod.setActionsList(getActionsList(flow.getInstructions(), version,datapathid));
}
flowMod.setVersion(version);
- return flowMod.build();
+
+ return flowMod;
}
private static List<Instructions> toInstructions(
org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Instructions instructions,
- short version) {
+ short version,BigInteger datapathid) {
List<Instructions> instructionsList = new ArrayList<>();
for (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.Instruction instruction : instructions
.setType(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.WriteActions.class);
ActionsInstructionBuilder actionsInstructionBuilder = new ActionsInstructionBuilder();
actionsInstructionBuilder.setActionsList(ActionConvertor.getActionList(writeActions.getAction(),
- version));
+ version,datapathid));
instructionBuilder.addAugmentation(ActionsInstruction.class, actionsInstructionBuilder.build());
instructionsList.add(instructionBuilder.build());
}
.setType(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.ApplyActions.class);
ActionsInstructionBuilder actionsInstructionBuilder = new ActionsInstructionBuilder();
actionsInstructionBuilder.setActionsList(ActionConvertor.getActionList(applyActions.getAction(),
- version));
+ version,datapathid));
instructionBuilder.addAugmentation(ActionsInstruction.class, actionsInstructionBuilder.build());
instructionsList.add(instructionBuilder.build());
}
.setType(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.ClearActions.class);
ActionsInstructionBuilder actionsInstructionBuilder = new ActionsInstructionBuilder();
actionsInstructionBuilder.setActionsList(ActionConvertor.getActionList(clearActions.getAction(),
- version));
+ version,datapathid));
instructionBuilder.addAugmentation(ActionsInstruction.class, actionsInstructionBuilder.build());
instructionsList.add(instructionBuilder.build());
}
}
return instructionsList;
}
+
+ private static List<ActionsList> getActionsList(
+ org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Instructions instructions,
+ short version,BigInteger datapathid) {
+
+ for (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.Instruction instruction : instructions
+ .getInstruction()) {
+ org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.Instruction curInstruction = instruction
+ .getInstruction();
+
+ if (curInstruction instanceof ApplyActionsCase) {
+ ApplyActionsCase applyActionscase = (ApplyActionsCase) curInstruction;
+ ApplyActions applyActions = applyActionscase.getApplyActions();
+ return ActionConvertor.getActionList(applyActions.getAction(), version,datapathid);
+ }
+
+ }
+ return null;
+ }
}
\ No newline at end of file