From 1556d03d7115ec4de7bb60b6b8ea592ca7687622 Mon Sep 17 00:00:00 2001 From: Michal Rehak Date: Mon, 8 Sep 2014 19:45:58 +0200 Subject: [PATCH] BUG-1421: VLAN tag - added original match to vlan-injected match - fixed offset of action order - added original vlan-* actions before injecting special actions - fixed vlan-id-present ignorance Change-Id: I7475fcaa3d1e04a03511cf9c0c33cda6d1c9185a Signed-off-by: Michal Rehak --- .../md/core/sal/convertor/FlowConvertor.java | 81 +++++++++---------- 1 file changed, 40 insertions(+), 41 deletions(-) diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/FlowConvertor.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/FlowConvertor.java index 3adeb37a99..e2c6ddae20 100644 --- a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/FlowConvertor.java +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/FlowConvertor.java @@ -11,6 +11,7 @@ package org.opendaylight.openflowplugin.openflow.md.core.sal.convertor; import com.google.common.base.Objects; import com.google.common.base.Optional; import com.google.common.collect.Ordering; + import org.opendaylight.openflowplugin.api.OFConstants; import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.OrderComparator; import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.flowflag.FlowFlagReactor; @@ -48,6 +49,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instru import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.write.actions._case.WriteActions; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.write.metadata._case.WriteMetadata; import org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanId; +import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.VlanMatch; import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.VlanMatchBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.vlan.match.fields.VlanIdBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ActionsInstruction; @@ -356,16 +358,17 @@ public class FlowConvertor { private static List handleSetVlanIdForOF13(Flow srcFlow, short version, BigInteger datapathId) { List list = new ArrayList<>(); - boolean hasVlanMatch = (srcFlow.getMatch() != null && srcFlow.getMatch().getVlanMatch() != null); + VlanMatch srcVlanMatch = srcFlow.getMatch().getVlanMatch(); + boolean hasVlanMatch = (srcFlow.getMatch() != null && srcVlanMatch != null); if (hasVlanMatch) { //create flow with setfield and match // match on vlan tag or vlanid with no mask - VlanMatchBuilder vlanMatchBuilder = new VlanMatchBuilder(); + VlanMatchBuilder vlanMatchBuilder = new VlanMatchBuilder(srcVlanMatch); VlanIdBuilder vlanIdBuilder = new VlanIdBuilder(); - vlanIdBuilder.setVlanIdPresent(true); - vlanIdBuilder.setVlanId(srcFlow.getMatch().getVlanMatch().getVlanId().getVlanId()); + vlanIdBuilder.setVlanIdPresent(srcVlanMatch.getVlanId().isVlanIdPresent()); + vlanIdBuilder.setVlanId(srcVlanMatch.getVlanId().getVlanId()); vlanMatchBuilder.setVlanId(vlanIdBuilder.build()); - Match match = new MatchBuilder().setVlanMatch(vlanMatchBuilder.build()).build(); + Match match = new MatchBuilder(srcFlow.getMatch()).setVlanMatch(vlanMatchBuilder.build()).build(); Optional optional = injectMatchToFlow(srcFlow, match); if (optional.isPresent()) { @@ -380,7 +383,7 @@ public class FlowConvertor { vlanIdBuilder.setVlanIdPresent(false); vlanIdBuilder.setVlanId(new VlanId(0)); vlanMatchBuilder.setVlanId(vlanIdBuilder.build()); - Match match1 = new MatchBuilder().setVlanMatch(vlanMatchBuilder.build()).build(); + Match match1 = new MatchBuilder(srcFlow.getMatch()).setVlanMatch(vlanMatchBuilder.build()).build(); Optional optional1 = injectMatchAndAction(srcFlow, match1); if (optional1.isPresent()) { @@ -394,7 +397,7 @@ public class FlowConvertor { vlanIdBuilder2.setVlanIdPresent(true); vlanIdBuilder2.setVlanId(new VlanId(0)); vlanMatchBuilder2.setVlanId(vlanIdBuilder2.build()); - Match match2 = new MatchBuilder().setVlanMatch(vlanMatchBuilder2.build()).build(); + Match match2 = new MatchBuilder(srcFlow.getMatch()).setVlanMatch(vlanMatchBuilder2.build()).build(); Optional optional2 = injectMatchToFlow(srcFlow, match2); if (optional2.isPresent()) { list.add(toFlowModInput(optional2.get(), version, datapathId)); @@ -445,21 +448,27 @@ public class FlowConvertor { List targetInstructionList = new ArrayList<>(srcInstructionList.size()); List targetActionList = new ArrayList<>(); + org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.InstructionBuilder instructionBuilder = + new org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.InstructionBuilder(); + for (int i=0; i < srcInstructionList.size(); i++) { - org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.Instruction srcInstruction = srcInstructionList.get(i); - org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.Instruction curSrcInstruction = srcInstruction.getInstruction(); - + org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.Instruction srcInstruction = + srcInstructionList.get(i); + org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.Instruction curSrcInstruction = + srcInstruction.getInstruction(); + if (curSrcInstruction instanceof ApplyActionsCase) { ApplyActionsCase applyActionscase = (ApplyActionsCase) curSrcInstruction; ApplyActions applyActions = applyActionscase.getApplyActions(); List srcActionList = applyActions.getAction(); - boolean orderIncrement = false; + int offset = 0; for (int j=0; j < srcActionList.size(); j++) { // check if its a set-vlan-action. If yes, then add the injected-action - if(srcActionList.get(j).getAction() instanceof SetVlanIdActionCase) { - SetVlanIdActionCase setVlanIdActionCase = (SetVlanIdActionCase) srcActionList.get(j).getAction(); + org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action actionItem = srcActionList.get(j); + if(actionItem.getAction() instanceof SetVlanIdActionCase) { + SetVlanIdActionCase setVlanIdActionCase = (SetVlanIdActionCase) actionItem.getAction(); PushVlanActionCaseBuilder pushVlanActionCaseBuilder = new PushVlanActionCaseBuilder(); PushVlanActionBuilder pushVlanActionBuilder = new PushVlanActionBuilder(); @@ -475,49 +484,39 @@ public class FlowConvertor { org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionBuilder actionBuilder = new ActionBuilder(); actionBuilder.setAction(injectedAction) - .setKey(srcActionList.get(j).getKey()) - .setOrder(srcActionList.get(j).getOrder()); + .setKey(actionItem.getKey()) + .setOrder(actionItem.getOrder() + offset); targetActionList.add(actionBuilder.build()); - - orderIncrement = true; + offset ++; } - if (orderIncrement) { + if (offset > 0) { // we need to increment the order for all the actions added after injection org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionBuilder actionBuilder = - new org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionBuilder(srcActionList.get(j)); - actionBuilder.setOrder(srcActionList.get(j).getOrder() + 1); - targetActionList.add(actionBuilder.build()); - } else { - targetActionList.add(srcActionList.get(j)); + new org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionBuilder(actionItem); + actionBuilder.setOrder(actionItem.getOrder() + offset); + actionItem = actionBuilder.build(); } + + targetActionList.add(actionItem); } ApplyActionsCaseBuilder applyActionsCaseBuilder = new ApplyActionsCaseBuilder(); ApplyActionsBuilder applyActionsBuilder = new ApplyActionsBuilder(); applyActionsBuilder.setAction(targetActionList); applyActionsCaseBuilder.setApplyActions(applyActionsBuilder.build()); - - org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.InstructionBuilder builder = - new org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.InstructionBuilder(); - - targetInstructionList.add( - builder.setKey(srcInstruction.getKey()) - .setOrder(srcInstruction.getOrder()) - .setInstruction(applyActionsCaseBuilder.build()) - .build()); - - + + instructionBuilder.setInstruction(applyActionsCaseBuilder.build()); } else { - org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.InstructionBuilder builder = - new org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.InstructionBuilder(); - targetInstructionList.add( - builder.setKey(srcInstruction.getKey()) - .setOrder(srcInstruction.getOrder()) - .setInstruction(curSrcInstruction) - .build()); + instructionBuilder.setInstruction(curSrcInstruction); } + + instructionBuilder + .setKey(srcInstruction.getKey()) + .setOrder(srcInstruction.getOrder()); + targetInstructionList.add(instructionBuilder.build()); + } return targetInstructionList; -- 2.36.6