*/
package org.opendaylight.openflowplugin.openflow.md.core.sal.convertor;
-import java.math.BigInteger;
-import java.util.ArrayList;
-import java.util.List;
-
+import com.google.common.collect.Ordering;
import org.opendaylight.openflowplugin.extension.api.ConverterExtensionKey;
import org.opendaylight.openflowplugin.extension.api.ConvertorActionToOFJava;
import org.opendaylight.openflowplugin.extension.api.ConvertorToOFJava;
import org.opendaylight.openflowplugin.extension.api.TypeVersionKey;
import org.opendaylight.openflowplugin.extension.api.path.ActionPath;
-import org.opendaylight.openflowplugin.openflow.md.OFConstants;
+import org.opendaylight.openflowplugin.api.OFConstants;
import org.opendaylight.openflowplugin.openflow.md.core.extension.ActionExtensionHelper;
import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.ActionSetNwDstReactor;
import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.ActionSetNwSrcReactor;
+import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.OrderComparator;
import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.match.MatchConvertorImpl;
import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.match.MatchReactor;
import org.opendaylight.openflowplugin.openflow.md.core.session.OFSessionUtil;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.OxmFieldsActionBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PortAction;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PortActionBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PortMatchEntry;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PortMatchEntryBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.QueueIdAction;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.QueueIdActionBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.VlanPcpAction;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.EthDst;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.EthSrc;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.OpenflowBasicClass;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.TcpDst;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.TcpSrc;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.VlanVid;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntries;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntriesBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import java.math.BigInteger;
+import java.util.ArrayList;
+import java.util.List;
+
/**
* @author usha@ericsson Action List:This class takes data from SAL layer and
* converts into OF Data
*/
public static List<Action> getActions(
List<org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action> actions,
- short version, BigInteger datapathid)
-
- {
+ short version, BigInteger datapathid) {
List<Action> actionsList = new ArrayList<>();
Action ofAction;
+ actions = Ordering.from(OrderComparator.<org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action>toInstance())
+ .sortedCopy(actions);
+
for (int actionItem = 0; actionItem < actions.size(); actionItem++) {
ofAction = null;
ActionBuilder actionBuilder = new ActionBuilder();
else if (action instanceof DecMplsTtlCase)
ofAction = SalToOFDecMplsTtl(actionBuilder);
else if (action instanceof PushVlanActionCase)
- ofAction = SalToOFPushVlanAction(action, actionBuilder);
+ ofAction = SalToOFPushVlanAction(action, actionBuilder, version);
else if (action instanceof PopVlanActionCase)
- ofAction = (version == OFConstants.OFP_VERSION_1_0) ? SalToOFStripVlan(actionBuilder, version)
+ ofAction = (version == OFConstants.OFP_VERSION_1_0) ?
+ SalToOFStripVlan(actionBuilder, version)
: SalToOFPopVlan(actionBuilder);
else if (action instanceof PushMplsActionCase)
ofAction = SalToOFPushMplsAction(action, actionBuilder);
ofAction = SalToOFPopPBB(actionBuilder);
// 1.0 Actions
- else if (action instanceof SetVlanIdActionCase)
+ else if (action instanceof SetVlanIdActionCase) {
+ /*if (version == OFConstants.OFP_VERSION_1_0) {
+
+ } else {
+ List<Action> setVlanIdActionsList = convertToOF13(action, actionBuilder);
+ actionsList.addAll(setVlanIdActionsList);
+ }*/
ofAction = SalToOFSetVlanId(action, actionBuilder, version);
+ }
else if (action instanceof SetVlanPcpActionCase)
ofAction = SalToOFSetVlanpcp(action, actionBuilder, version);
else if (action instanceof StripVlanActionCase)
ActionBuilder actionBuilder, short version, BigInteger datapathid) {
SetFieldCase setFieldCase = (SetFieldCase) action;
- org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.Match match = setFieldCase
- .getSetField();
+ org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.Match match =
+ setFieldCase.getSetField();
+
+ if (version == OFConstants.OFP_VERSION_1_0) {
+ // pushvlan +setField can be called to configure 1.0 switches via MDSAL app
+ if (match.getVlanMatch() != null) {
+ VlanVidActionBuilder vlanidActionBuilder = new VlanVidActionBuilder();
+ vlanidActionBuilder.setVlanVid(match.getVlanMatch().getVlanId().getVlanId().getValue());
+ actionBuilder.setType(
+ org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetVlanVid.class);
+ actionBuilder.addAugmentation(VlanVidAction.class, vlanidActionBuilder.build());
+ return actionBuilder.build();
+ } else {
+ return emtpyAction(actionBuilder);
+ }
- OxmFieldsActionBuilder oxmFieldsActionBuilder = new OxmFieldsActionBuilder();
- MatchReactor.getInstance().convert(match, version, oxmFieldsActionBuilder, datapathid);
+ } else {
+ OxmFieldsActionBuilder oxmFieldsActionBuilder = new OxmFieldsActionBuilder();
+ MatchReactor.getInstance().convert(match, version, oxmFieldsActionBuilder, datapathid);
- actionBuilder
- .setType(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetField.class);
+ actionBuilder.setType(
+ org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetField.class);
+
+ actionBuilder.addAugmentation(OxmFieldsAction.class, oxmFieldsActionBuilder.build());
+ return actionBuilder.build();
+ }
- actionBuilder.addAugmentation(OxmFieldsAction.class, oxmFieldsActionBuilder.build());
- return actionBuilder.build();
}
private static Action SalToOFDecNwTtl(ActionBuilder actionBuilder) {
private static Action SalToOFPushVlanAction(
org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action action,
- ActionBuilder actionBuilder) {
+ ActionBuilder actionBuilder, short version) {
+ if (version == OFConstants.OFP_VERSION_1_0) {
+ // if client configure openflow 1.0 switch as a openflow 1.3 switch using openflow 1.3 instructions
+ // then we can ignore PUSH_VLAN as set-vlan-id will push a vlan header if not present
+ return emtpyAction(actionBuilder);
+ }
+
PushVlanActionCase pushVlanActionCase = (PushVlanActionCase) action;
PushVlanAction pushVlanAction = pushVlanActionCase.getPushVlanAction();
actionBuilder.setType(PushVlan.class);
return emtpyAction(actionBuilder);
}
+ // set-vlan-id (1.0 feature) can be called on 1.3 switches as well using ADSAL apis
private static Action SalToOFSetVlanId(
org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action action,
ActionBuilder actionBuilder, short version) {
.setType(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetVlanVid.class);
actionBuilder.addAugmentation(VlanVidAction.class, vlanidActionBuilder.build());
return actionBuilder.build();
+
} else if (version >= OFConstants.OFP_VERSION_1_3) {
OxmFieldsActionBuilder oxmFieldsActionBuilder = new OxmFieldsActionBuilder();
actionBuilder
logger.error("Unknown Action Type for the Version", version);
return null;
}
-
}
private static Action SalToOFSetDlDst(
logger.error("Unknown Action Type for the Version", version);
return null;
}
-
}
protected static Action SalToOFSetNwSrc(
.setType(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetTpSrc.class);
actionBuilder.addAugmentation(PortAction.class, settpsrc.build());
return actionBuilder.build();
+ } else if (version == OFConstants.OFP_VERSION_1_3) {
+ SetTpSrcActionCase settpsrccase = (SetTpSrcActionCase) action;
+ SetTpSrcAction settpsrcaction = settpsrccase.getSetTpSrcAction();
+
+ MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
+ matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
+ matchEntriesBuilder.setHasMask(false);
+ matchEntriesBuilder.setOxmMatchField(TcpSrc.class);
+ PortMatchEntryBuilder portMatchEntryBuilder = new PortMatchEntryBuilder();
+ portMatchEntryBuilder.setPort(new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.PortNumber(settpsrcaction.getPort().getValue().intValue()));
+ matchEntriesBuilder.addAugmentation(PortMatchEntry.class, portMatchEntryBuilder.build());
+
+ actionBuilder
+ .setType(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetField.class);
+
+ OxmFieldsActionBuilder oxmFieldsActionBuilder = new OxmFieldsActionBuilder();
+ List<MatchEntries> matchEntries = new ArrayList<MatchEntries>();
+ matchEntries.add(matchEntriesBuilder.build());
+ oxmFieldsActionBuilder.setMatchEntries(matchEntries);
+
+ actionBuilder.addAugmentation(OxmFieldsAction.class, oxmFieldsActionBuilder.build());
+ return actionBuilder.build();
}
logger.error("Unknown Action Type for the Version", version);
return null;
.setType(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetTpDst.class);
actionBuilder.addAugmentation(PortAction.class, settpdst.build());
return actionBuilder.build();
+ } else if (version == OFConstants.OFP_VERSION_1_3) {
+ SetTpDstActionCase settpdstcase = (SetTpDstActionCase) action;
+ SetTpDstAction settpdstaction = settpdstcase.getSetTpDstAction();
+
+ MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
+ matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
+ matchEntriesBuilder.setHasMask(false);
+ matchEntriesBuilder.setOxmMatchField(TcpDst.class);
+ PortMatchEntryBuilder portMatchEntryBuilder = new PortMatchEntryBuilder();
+ portMatchEntryBuilder.setPort(new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.PortNumber(settpdstaction.getPort().getValue().intValue()));
+ matchEntriesBuilder.addAugmentation(PortMatchEntry.class, portMatchEntryBuilder.build());
+
+ actionBuilder
+ .setType(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetField.class);
+
+ OxmFieldsActionBuilder oxmFieldsActionBuilder = new OxmFieldsActionBuilder();
+ List<MatchEntries> matchEntries = new ArrayList<MatchEntries>();
+ matchEntries.add(matchEntriesBuilder.build());
+ oxmFieldsActionBuilder.setMatchEntries(matchEntries);
+
+ actionBuilder.addAugmentation(OxmFieldsAction.class, oxmFieldsActionBuilder.build());
+ return actionBuilder.build();
}
logger.error("Unknown Action Type for the Version", version);
return null;