*/
package org.opendaylight.openflowplugin.openflow.md.core.sal.convertor;
-import java.math.BigInteger;
-import java.util.ArrayList;
-import java.util.List;
-
-import org.opendaylight.openflowjava.protocol.api.util.BinContent;
import org.opendaylight.openflowplugin.openflow.md.OFConstants;
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.match.MatchConvertorImpl;
import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.match.MatchReactor;
import org.opendaylight.openflowplugin.openflow.md.util.InventoryDataServiceUtil;
+import org.opendaylight.openflowplugin.openflow.md.util.OpenflowPortsUtil;
+import org.opendaylight.openflowplugin.openflow.md.util.OpenflowVersion;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Dscp;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Uri;
import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.CopyTtlInCase;
import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.tp.src.action._case.SetTpSrcAction;
import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.vlan.id.action._case.SetVlanIdAction;
import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.vlan.pcp.action._case.SetVlanPcpAction;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.OutputPortValues;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanId;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.DlAddressAction;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.DlAddressActionBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.EthertypeAction;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.grouping.ActionBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.EtherType;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumberValues;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumberValuesV10;
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.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
else if (action instanceof PushVlanActionCase)
ofAction = SalToOFPushVlanAction(action, actionBuilder);
else if (action instanceof PopVlanActionCase)
- ofAction = SalToOFPopVlan(actionBuilder);
+ ofAction = (version == OFConstants.OFP_VERSION_1_0) ? SalToOFStripVlan(actionBuilder, version)
+ : SalToOFPopVlan(actionBuilder);
else if (action instanceof PushMplsActionCase)
ofAction = SalToOFPushMplsAction(action, actionBuilder);
else if (action instanceof PopMplsActionCase)
Uri uri = outputAction.getOutputNodeConnector();
- if (version >= OFConstants.OFP_VERSION_1_3) {
-
- if (uri.getValue().equals(OutputPortValues.CONTROLLER.toString())) {
- portAction.setPort(new PortNumber(BinContent.intToUnsignedLong(PortNumberValues.CONTROLLER
- .getIntValue())));
- } else if (uri.getValue().equals(OutputPortValues.ALL.toString())) {
- portAction.setPort(new PortNumber(BinContent.intToUnsignedLong(PortNumberValues.ALL.getIntValue())));
- } else if (uri.getValue().equals(OutputPortValues.ANY.toString())) {
- portAction.setPort(new PortNumber(BinContent.intToUnsignedLong(PortNumberValues.ANY.getIntValue())));
-
- } else if (uri.getValue().equals(OutputPortValues.FLOOD.toString())) {
- portAction.setPort(new PortNumber(BinContent.intToUnsignedLong(PortNumberValues.FLOOD.getIntValue())));
-
- } else if (uri.getValue().equals(OutputPortValues.INPORT.toString())) {
- portAction.setPort(new PortNumber(BinContent.intToUnsignedLong(PortNumberValues.INPORT.getIntValue())));
-
- } else if (uri.getValue().equals(OutputPortValues.LOCAL.toString())) {
- portAction.setPort(new PortNumber(BinContent.intToUnsignedLong(PortNumberValues.LOCAL.getIntValue())));
-
- } else if (uri.getValue().equals(OutputPortValues.NORMAL.toString())) {
- portAction.setPort(new PortNumber(BinContent.intToUnsignedLong(PortNumberValues.NORMAL.getIntValue())));
-
- } else if (uri.getValue().equals(OutputPortValues.TABLE.toString())) {
- portAction.setPort(new PortNumber(BinContent.intToUnsignedLong(PortNumberValues.TABLE.getIntValue())));
-
- } else if (uri.getValue().equals(OutputPortValues.NONE.toString())) {
- logger.error("Unknown Port Type for the Version");
- } else if (InventoryDataServiceUtil.portNumberfromNodeConnectorId(outputAction.getOutputNodeConnector()
- .getValue()) < MAXPortOF13) {
- portAction.setPort(new PortNumber(InventoryDataServiceUtil.portNumberfromNodeConnectorId(outputAction
- .getOutputNodeConnector().getValue())));
- } else {
- logger.error("Invalid Port for Output Action");
- }
- } else if (version == OFConstants.OFP_VERSION_1_0) {
-
- if (uri.getValue().equals(OutputPortValues.CONTROLLER.toString())) {
- portAction.setPort(new PortNumber((long) PortNumberValuesV10.CONTROLLER.getIntValue()));
- } else if (uri.getValue().equals(OutputPortValues.ALL.toString())) {
- portAction.setPort(new PortNumber((long) PortNumberValuesV10.ALL.getIntValue()));
- } else if (uri.getValue().equals(OutputPortValues.FLOOD.toString())) {
- portAction.setPort(new PortNumber((long) PortNumberValuesV10.FLOOD.getIntValue()));
- } else if (uri.getValue().equals(OutputPortValues.INPORT.toString())) {
- portAction.setPort(new PortNumber((long) PortNumberValuesV10.INPORT.getIntValue()));
- } else if (uri.getValue().equals(OutputPortValues.LOCAL.toString())) {
- portAction.setPort(new PortNumber((long) PortNumberValuesV10.LOCAL.getIntValue()));
- } else if (uri.getValue().equals(OutputPortValues.NORMAL.toString())) {
- portAction.setPort(new PortNumber((long) PortNumberValuesV10.NORMAL.getIntValue()));
- } else if (uri.getValue().equals(OutputPortValues.TABLE.toString())) {
- portAction.setPort(new PortNumber((long) PortNumberValuesV10.TABLE.getIntValue()));
- } else if (uri.getValue().equals(OutputPortValues.NONE.toString())) {
- portAction.setPort(new PortNumber((long) PortNumberValuesV10.NONE.getIntValue()));
- } else if (uri.getValue().equals(OutputPortValues.ANY.toString())) {
- logger.error("Unknown Port Type for the Version");
- } else if (InventoryDataServiceUtil.portNumberfromNodeConnectorId(outputAction.getOutputNodeConnector()
- .getValue()) < MAXPortOF10) {
- portAction.setPort(new PortNumber(InventoryDataServiceUtil.portNumberfromNodeConnectorId(outputAction
- .getOutputNodeConnector().getValue())));
- } else {
- logger.error("Invalid Port for Output Action");
- }
+ OpenflowVersion ofVersion = OpenflowVersion.get(version);
+ Long portNumber = InventoryDataServiceUtil.portNumberfromNodeConnectorId(ofVersion, uri.getValue());
+ if (portNumber != null && (OpenflowPortsUtil.isPortReserved(ofVersion, portNumber) || portNumber < OpenflowPortsUtil.getMaxPortForVersion(ofVersion)) ) {
+ portAction.setPort(new PortNumber(portNumber));
+ } else {
+ logger.error("Invalid Port specified "+ portNumber + " for Output Action for OF version:"+ ofVersion);
}
- actionBuilder
- .setType(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.Output.class);
+ actionBuilder.setType(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.Output.class);
actionBuilder.addAugmentation(PortAction.class, portAction.build());
return actionBuilder.build();
* Method to convert OF actions associated with bucket to SAL Actions.
*
* @param actionList
+ * @param ofVersion current ofp version
* @return List of converted SAL Actions.
*/
public static List<org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action> toMDSalActions(
- List<Action> actionList) {
+ List<Action> actionList, OpenflowVersion ofVersion) {
List<org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action> bucketActions = new ArrayList<>();
for (Action action : actionList) {
if (action.getType().equals(
- org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.Output.class))
+ org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.Output.class)) {
bucketActions.add(ofToSALOutputAction(action));
- else if (action.getType().equals(
- org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.Group.class))
+
+ } else if (action.getType().equals(
+ org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.Group.class)) {
bucketActions.add(ofToSALGroupAction(action));
- else if (action.getType().equals(
+
+ } else if (action.getType().equals(
org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.CopyTtlOut.class)) {
CopyTtlOutBuilder copyTtlOutaction = new CopyTtlOutBuilder();
bucketActions.add(new CopyTtlOutCaseBuilder().setCopyTtlOut(copyTtlOutaction.build()).build());
+
} else if (action.getType().equals(
org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.CopyTtlIn.class)) {
CopyTtlInBuilder copyTtlInaction = new CopyTtlInBuilder();
bucketActions.add(new CopyTtlInCaseBuilder().setCopyTtlIn(copyTtlInaction.build()).build());
+
} else if (action.getType().equals(
- org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetMplsTtl.class))
+ org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetMplsTtl.class)) {
bucketActions.add(ofToSALSetMplsTtl(action));
- else if (action.getType().equals(
+
+ } else if (action.getType().equals(
org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.DecMplsTtl.class)) {
DecMplsTtlBuilder decMplsTtl = new DecMplsTtlBuilder();
bucketActions.add(new DecMplsTtlCaseBuilder().setDecMplsTtl(decMplsTtl.build()).build());
+
} else if (action.getType().equals(
- org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.PushVlan.class))
+ org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.PushVlan.class)) {
bucketActions.add(ofToSALPushVlanAction(action));
- else if (action.getType().equals(
- org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.PopVlan.class)) {
+
+ } else if (action.getType().equals(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.PopVlan.class)
+ || action.getType().equals(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.StripVlan.class)) {
+ // OF1.0 nodes will emit StripVlan and OF1.3+ will emit StripVlan/PopVlan, convert both to PopVlan for SAL
PopVlanActionBuilder popVlan = new PopVlanActionBuilder();
bucketActions.add(new PopVlanActionCaseBuilder().setPopVlanAction(popVlan.build()).build());
+
} else if (action.getType().equals(
org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.PushMpls.class)) {
- PushMplsActionBuilder pushMpls = new PushMplsActionBuilder();
- bucketActions.add(new PushMplsActionCaseBuilder().setPushMplsAction(pushMpls.build()).build());
+ bucketActions.add(ofToSALPushMplsAction(action));
+
} else if (action.getType().equals(
org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.PopMpls.class)) {
- PopMplsActionBuilder popMpls = new PopMplsActionBuilder();
- bucketActions.add(new PopMplsActionCaseBuilder().setPopMplsAction(popMpls.build()).build());
+ bucketActions.add(ofToSALPopMplsAction(action));
+
} else if (action.getType().equals(
- org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetQueue.class))
+ org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetQueue.class)) {
bucketActions.add(ofToSALSetQueue(action));
- else if (action.getType().equals(
- org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetNwTtl.class))
+ } else if (action.getType().equals(
+ org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetNwTtl.class)) {
bucketActions.add(ofToSALSetNwTtl(action));
- else if (action.getType().equals(
+
+ } else if (action.getType().equals(
org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.DecNwTtl.class)) {
DecNwTtlBuilder decNwTtl = new DecNwTtlBuilder();
bucketActions.add(new DecNwTtlCaseBuilder().setDecNwTtl(decNwTtl.build()).build());
+
} else if (action.getType().equals(
- org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetField.class))
- bucketActions.add(new SetFieldCaseBuilder().setSetField(MatchConvertorImpl.ofToSALSetField(action))
+ org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetField.class)) {
+ bucketActions.add(new SetFieldCaseBuilder().setSetField(MatchConvertorImpl.fromOFSetFieldToSALSetFieldAction(action, ofVersion))
.build());
-
- else if (action.getType().equals(
- org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.PushPbb.class))
+ } else if (action.getType().equals(
+ org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.PushPbb.class)) {
bucketActions.add(ofToSALPushPbbAction(action));
- else if (action.getType().equals(
+
+ } else if (action.getType().equals(
org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.PopPbb.class)) {
PopPbbActionBuilder popPbb = new PopPbbActionBuilder();
bucketActions.add(new PopPbbActionCaseBuilder().setPopPbbAction(popPbb.build()).build());
+
} else if (action.getType().equals(
org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.Experimenter.class)) {
// bucketActions.add(ofToSALExperimenter(action));
PushVlanActionBuilder pushVlanAction = new PushVlanActionBuilder();
EthertypeAction etherType = action.getAugmentation(EthertypeAction.class);
- pushVlanAction.setVlanId(new VlanId(etherType.getEthertype().getValue()));
+ pushVlanAction.setEthernetType(etherType.getEthertype().getValue());
return new PushVlanActionCaseBuilder().setPushVlanAction(pushVlanAction.build()).build();
}
+ /**
+ * Method converts OF PushMpls action to SAL PushMpls action.
+ *
+ * @param action
+ * @return PushMplsAction
+ */
+ public static PushMplsActionCase ofToSALPushMplsAction(Action action) {
+
+ PushMplsActionBuilder pushMplsAction = new PushMplsActionBuilder();
+
+ EthertypeAction etherType = action.getAugmentation(EthertypeAction.class);
+ pushMplsAction.setEthernetType(etherType.getEthertype().getValue());
+
+ return new PushMplsActionCaseBuilder().setPushMplsAction(pushMplsAction.build()).build();
+ }
+
+ /**
+ * Method converts OF PopMpls action to SAL PopMpls action.
+ *
+ * @param action
+ * @return PopMplsActionCase
+ */
+ public static PopMplsActionCase ofToSALPopMplsAction(Action action) {
+
+ PopMplsActionBuilder popMplsAction = new PopMplsActionBuilder();
+
+ EthertypeAction etherType = action.getAugmentation(EthertypeAction.class);
+ popMplsAction.setEthernetType(etherType.getEthertype().getValue());
+
+ return new PopMplsActionCaseBuilder().setPopMplsAction(popMplsAction.build()).build();
+ }
+
/**
* Method converts OF SetQueue action to SAL SetQueue action.
*