From 43767bb962ade9659c8aa7eb0e02d412a7a54db2 Mon Sep 17 00:00:00 2001 From: Alessandro Boch Date: Fri, 8 Nov 2013 11:19:49 -0800 Subject: [PATCH] SAL Actions Property is OF1.0 specific - Replaced with a new Property SupportedFlowActions which carries the list of SAL actions the network node supports. The Inventory Service in the protocol plugin is responsible to populate the SupportedFlowAction object with the correspondent SAL Flow actions. - Static conversion OF->SAL actions Map and utility hosted by FlowConverter - Deprecated Actions Property class - With this change an application or functional module will be able to retrieve from switch manager the list of flow actions the network node supports, without need to know which SDN protocol/version the the node is running Change-Id: Ic2b3c5a854fbcaae6e51fc63745dc05ee5bcbf40 Signed-off-by: Alessandro Boch --- .../protocol_plugins/openflow/pom.xml | 2 +- .../openflow/internal/FlowConverter.java | 49 +++++++++ .../internal/InventoryServiceShim.java | 4 +- .../controller/sal/action/Enqueue.java | 38 +++++++ .../sal/action/SupportedFlowActions.java | 99 +++++++++++++++++++ .../controller/sal/core/Actions.java | 15 ++- 6 files changed, 199 insertions(+), 8 deletions(-) create mode 100644 opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/action/Enqueue.java create mode 100644 opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/action/SupportedFlowActions.java diff --git a/opendaylight/protocol_plugins/openflow/pom.xml b/opendaylight/protocol_plugins/openflow/pom.xml index c7522c977f..ca0ff45d61 100644 --- a/opendaylight/protocol_plugins/openflow/pom.xml +++ b/opendaylight/protocol_plugins/openflow/pom.xml @@ -70,7 +70,7 @@ org.opendaylight.controller sal - 0.5.1-SNAPSHOT + 0.6.0-SNAPSHOT org.opendaylight.controller diff --git a/opendaylight/protocol_plugins/openflow/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/internal/FlowConverter.java b/opendaylight/protocol_plugins/openflow/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/internal/FlowConverter.java index 2bbe9c12c6..8fa4941b88 100644 --- a/opendaylight/protocol_plugins/openflow/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/internal/FlowConverter.java +++ b/opendaylight/protocol_plugins/openflow/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/internal/FlowConverter.java @@ -12,7 +12,9 @@ import java.math.BigInteger; import java.net.InetAddress; import java.net.UnknownHostException; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; import org.opendaylight.controller.protocol_plugin.openflow.vendorextension.v6extension.V6FlowMod; import org.opendaylight.controller.protocol_plugin.openflow.vendorextension.v6extension.V6Match; @@ -20,6 +22,7 @@ import org.opendaylight.controller.sal.action.Action; import org.opendaylight.controller.sal.action.ActionType; import org.opendaylight.controller.sal.action.Controller; import org.opendaylight.controller.sal.action.Drop; +import org.opendaylight.controller.sal.action.Enqueue; import org.opendaylight.controller.sal.action.Flood; import org.opendaylight.controller.sal.action.FloodAll; import org.opendaylight.controller.sal.action.HwPath; @@ -747,4 +750,50 @@ public class FlowConverter { return flow; } + private static final Map> actionMap = new HashMap>() { + private static final long serialVersionUID = 1L; + { + put(1 << 0, Output.class); + put(1 << 1, SetVlanId.class); + put(1 << 2, SetVlanPcp.class); + put(1 << 3, PopVlan.class); + put(1 << 4, SetDlSrc.class); + put(1 << 5, SetDlDst.class); + put(1 << 6, SetNwSrc.class); + put(1 << 7, SetNwDst.class); + put(1 << 8, SetNwTos.class); + put(1 << 9, SetTpSrc.class); + put(1 << 10, SetTpDst.class); + put(1 << 11, Enqueue.class); + } + }; + + /** + * Returns the supported flow actions for the netwrok node given the bitmask + * representing the actions the Openflow 1.0 switch supports + * + * @param ofActionBitmask + * OF 1.0 action bitmask + * @return The correspondent list of SAL Action classes + */ + public static List> getFlowActions(int ofActionBitmask) { + List> list = new ArrayList>(); + + for (int i = 0; i < Integer.SIZE; i++) { + int index = 1 << i; + if ((index & ofActionBitmask) > 0) { + if (actionMap.containsKey(index)) { + list.add(actionMap.get(index)); + } + } + } + // Add implicit SAL actions + list.add(Controller.class); + list.add(SwPath.class); + list.add(HwPath.class); + list.add(Drop.class); + + return list; + } + } diff --git a/opendaylight/protocol_plugins/openflow/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/internal/InventoryServiceShim.java b/opendaylight/protocol_plugins/openflow/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/internal/InventoryServiceShim.java index a920adf71d..f4843cf828 100644 --- a/opendaylight/protocol_plugins/openflow/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/internal/InventoryServiceShim.java +++ b/opendaylight/protocol_plugins/openflow/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/internal/InventoryServiceShim.java @@ -26,9 +26,9 @@ import org.opendaylight.controller.protocol_plugin.openflow.core.IController; import org.opendaylight.controller.protocol_plugin.openflow.core.IMessageListener; import org.opendaylight.controller.protocol_plugin.openflow.core.ISwitch; import org.opendaylight.controller.protocol_plugin.openflow.core.ISwitchStateListener; +import org.opendaylight.controller.sal.action.SupportedFlowActions; import org.opendaylight.controller.sal.connection.ConnectionLocality; import org.opendaylight.controller.sal.connection.IPluginOutConnectionService; -import org.opendaylight.controller.sal.core.Actions; import org.opendaylight.controller.sal.core.Buffers; import org.opendaylight.controller.sal.core.Capabilities; import org.opendaylight.controller.sal.core.ContainerFlow; @@ -503,7 +503,7 @@ public class InventoryServiceShim implements IContainerListener, props.add(c); } int act = sw.getActions(); - Actions a = new Actions(act); + SupportedFlowActions a = new SupportedFlowActions(FlowConverter.getFlowActions(act)); if (a != null) { props.add(a); } diff --git a/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/action/Enqueue.java b/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/action/Enqueue.java new file mode 100644 index 0000000000..b3891c8337 --- /dev/null +++ b/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/action/Enqueue.java @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.controller.sal.action; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; + +import org.opendaylight.controller.sal.core.NodeConnector; + +@XmlRootElement +@XmlAccessorType(XmlAccessType.NONE) +public class Enqueue extends Action { + private static final long serialVersionUID = 1L; + @XmlElement + private NodeConnector port; + + /* Dummy constructor for JAXB */ + @SuppressWarnings("unused") + private Enqueue() { + } + + public Enqueue(NodeConnector port) { + type = ActionType.ENQUEUE; + this.port = port; + } + + public NodeConnector getPort() { + return port; + } +} diff --git a/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/action/SupportedFlowActions.java b/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/action/SupportedFlowActions.java new file mode 100644 index 0000000000..0a5d9c82cb --- /dev/null +++ b/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/action/SupportedFlowActions.java @@ -0,0 +1,99 @@ +/* + * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.controller.sal.action; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlElement; + +import org.opendaylight.controller.sal.core.Property; + +/** + * @file SupportedFlowActions.java + * + * @brief Class representing the supported flow actions + * + * Describes the supported flow actions + */ + +@XmlAccessorType(XmlAccessType.NONE) +public class SupportedFlowActions extends Property { + private static final long serialVersionUID = 1L; + public static final String SupportedFlowActionsPropName = "supportedFlowActions"; + private List> actions; + + private SupportedFlowActions() { + super(SupportedFlowActionsPropName); + this.actions = new ArrayList>(); + } + + public SupportedFlowActions(List> actions) { + super(SupportedFlowActionsPropName); + this.actions = new ArrayList>(actions); + } + + @Override + public int hashCode() { + final int prime = 31; + int result = super.hashCode(); + result = prime * result + ((actions == null) ? 0 : actions.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (!super.equals(obj)) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + SupportedFlowActions other = (SupportedFlowActions) obj; + if (actions == null) { + if (other.actions != null) { + return false; + } + } else if (!actions.equals(other.actions)) { + return false; + } + return true; + } + + public List> getActions() { + return new ArrayList>(this.actions); + } + + @XmlElement(name = "value") + @Override + public String getStringValue() { + List nameList = new ArrayList(); + for (Class clazz : actions) { + nameList.add(clazz.getSimpleName()); + } + Collections.sort(nameList); + return nameList.toString(); + } + + @Override + public Property clone() { + return new SupportedFlowActions(this.actions); + } + + @Override + public String toString() { + return this.getStringValue(); + } +} diff --git a/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/core/Actions.java b/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/core/Actions.java index 6cada2c041..b3fa45bbc9 100644 --- a/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/core/Actions.java +++ b/opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/core/Actions.java @@ -20,8 +20,9 @@ import javax.xml.bind.annotation.XmlRootElement; * @brief Class representing actions * * Describes supported actions + * @Deprecated This class is OF 1.0 specific. Use SupportedFlowActions instead. */ - +@Deprecated @XmlRootElement @XmlAccessorType(XmlAccessType.NONE) public class Actions extends Property { @@ -92,15 +93,19 @@ public class Actions extends Property { @Override public boolean equals(Object obj) { - if (this == obj) + if (this == obj) { return true; - if (!super.equals(obj)) + } + if (!super.equals(obj)) { return false; - if (getClass() != obj.getClass()) + } + if (getClass() != obj.getClass()) { return false; + } Actions other = (Actions) obj; - if (actionsValue != other.actionsValue) + if (actionsValue != other.actionsValue) { return false; + } return true; } -- 2.36.6