SAL Actions Property is OF1.0 specific 35/2535/3
authorAlessandro Boch <aboch@cisco.com>
Fri, 8 Nov 2013 19:19:49 +0000 (11:19 -0800)
committerAlessandro Boch <aboch@cisco.com>
Mon, 11 Nov 2013 17:10:27 +0000 (09:10 -0800)
- 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 <aboch@cisco.com>
opendaylight/protocol_plugins/openflow/pom.xml
opendaylight/protocol_plugins/openflow/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/internal/FlowConverter.java
opendaylight/protocol_plugins/openflow/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/internal/InventoryServiceShim.java
opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/action/Enqueue.java [new file with mode: 0644]
opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/action/SupportedFlowActions.java [new file with mode: 0644]
opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/core/Actions.java

index c7522c977f81527adf1acc63696d5a0dda49f38f..ca0ff45d61e4977ed677f761d93c73c86262482e 100644 (file)
@@ -70,7 +70,7 @@
     <dependency>
       <groupId>org.opendaylight.controller</groupId>
       <artifactId>sal</artifactId>
     <dependency>
       <groupId>org.opendaylight.controller</groupId>
       <artifactId>sal</artifactId>
-      <version>0.5.1-SNAPSHOT</version>
+      <version>0.6.0-SNAPSHOT</version>
     </dependency>
     <dependency>
       <groupId>org.opendaylight.controller</groupId>
     </dependency>
     <dependency>
       <groupId>org.opendaylight.controller</groupId>
index 2bbe9c12c6719e736f960bd2fba4a1457825060c..8fa4941b88771c94dbf3b578a3f89717339f899e 100644 (file)
@@ -12,7 +12,9 @@ import java.math.BigInteger;
 import java.net.InetAddress;
 import java.net.UnknownHostException;
 import java.util.ArrayList;
 import java.net.InetAddress;
 import java.net.UnknownHostException;
 import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.List;
 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;
 
 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.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;
 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;
     }
 
         return flow;
     }
 
+    private static final Map<Integer, Class<? extends Action>> actionMap = new HashMap<Integer, Class<? extends Action>>() {
+        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<Class<? extends Action>> getFlowActions(int ofActionBitmask) {
+        List<Class<? extends Action>> list = new ArrayList<Class<? extends Action>>();
+
+        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;
+    }
+
 }
 }
index a920adf71d35163094514674fbb5b8a158bf66d7..f4843cf8283f36f2dc4ae957c2e46c42d363e4d6 100644 (file)
@@ -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.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.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;
 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();
             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);
         }
         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 (file)
index 0000000..b3891c8
--- /dev/null
@@ -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 (file)
index 0000000..0a5d9c8
--- /dev/null
@@ -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<Class<? extends Action>> actions;
+
+    private SupportedFlowActions() {
+        super(SupportedFlowActionsPropName);
+        this.actions = new ArrayList<Class<? extends Action>>();
+    }
+
+    public SupportedFlowActions(List<Class<? extends Action>> actions) {
+        super(SupportedFlowActionsPropName);
+        this.actions = new ArrayList<Class<? extends Action>>(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<Class<? extends Action>> getActions() {
+        return new ArrayList<Class<? extends Action>>(this.actions);
+    }
+
+    @XmlElement(name = "value")
+    @Override
+    public String getStringValue() {
+        List<String> nameList = new ArrayList<String>();
+        for (Class<? extends Action> 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();
+    }
+}
index 6cada2c0417788291aa62491513e851645599f08..b3fa45bbc957322d3b0839ac86506d30359def7e 100644 (file)
@@ -20,8 +20,9 @@ import javax.xml.bind.annotation.XmlRootElement;
  * @brief  Class representing actions
  *
  * Describes supported actions
  * @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 {
 @XmlRootElement
 @XmlAccessorType(XmlAccessType.NONE)
 public class Actions extends Property {
@@ -92,15 +93,19 @@ public class Actions extends Property {
 
     @Override
     public boolean equals(Object obj) {
 
     @Override
     public boolean equals(Object obj) {
-        if (this == obj)
+        if (this == obj) {
             return true;
             return true;
-        if (!super.equals(obj))
+        }
+        if (!super.equals(obj)) {
             return false;
             return false;
-        if (getClass() != obj.getClass())
+        }
+        if (getClass() != obj.getClass()) {
             return false;
             return false;
+        }
         Actions other = (Actions) obj;
         Actions other = (Actions) obj;
-        if (actionsValue != other.actionsValue)
+        if (actionsValue != other.actionsValue) {
             return false;
             return false;
+        }
         return true;
     }
 
         return true;
     }