Bulk-add copyright headers to java files
[controller.git] / opendaylight / protocol_plugins / stub / src / main / java / org / opendaylight / controller / protocol_plugins / stub / internal / ReadService.java
index cf633a4fe6a805bcc76763a5ee346f4f6e6c25c8..0ff60835c8b70d98357c7fa734c237bfef967780 100644 (file)
@@ -1,20 +1,43 @@
+/*
+ * Copyright (c) 2014 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.protocol_plugins.stub.internal;
 
 import java.net.InetAddress;
 import java.net.UnknownHostException;
 import java.util.ArrayList;
-import java.util.Dictionary;
 import java.util.List;
 
-import org.apache.felix.dm.Component;
-//import org.opendaylight.controller.protocol_plugin_stubs.IPluginReadServiceFilter;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
 import org.opendaylight.controller.sal.action.Action;
+import org.opendaylight.controller.sal.action.Controller;
 import org.opendaylight.controller.sal.action.Drop;
+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.Loopback;
+import org.opendaylight.controller.sal.action.Output;
+import org.opendaylight.controller.sal.action.PopVlan;
+import org.opendaylight.controller.sal.action.PushVlan;
+import org.opendaylight.controller.sal.action.SetDlDst;
+import org.opendaylight.controller.sal.action.SetDlSrc;
+import org.opendaylight.controller.sal.action.SetDlType;
+import org.opendaylight.controller.sal.action.SetNwDst;
+import org.opendaylight.controller.sal.action.SetNwSrc;
+import org.opendaylight.controller.sal.action.SetNwTos;
+import org.opendaylight.controller.sal.action.SetTpDst;
+import org.opendaylight.controller.sal.action.SetTpSrc;
+import org.opendaylight.controller.sal.action.SetVlanCfi;
+import org.opendaylight.controller.sal.action.SetVlanId;
+import org.opendaylight.controller.sal.action.SetVlanPcp;
+import org.opendaylight.controller.sal.action.SwPath;
+import org.opendaylight.controller.sal.core.ConstructionException;
 import org.opendaylight.controller.sal.core.Node;
 import org.opendaylight.controller.sal.core.NodeConnector;
+import org.opendaylight.controller.sal.core.NodeTable;
 import org.opendaylight.controller.sal.flowprogrammer.Flow;
 import org.opendaylight.controller.sal.match.Match;
 import org.opendaylight.controller.sal.match.MatchType;
@@ -22,11 +45,13 @@ import org.opendaylight.controller.sal.reader.FlowOnNode;
 import org.opendaylight.controller.sal.reader.IPluginInReadService;
 import org.opendaylight.controller.sal.reader.NodeConnectorStatistics;
 import org.opendaylight.controller.sal.reader.NodeDescription;
-
+import org.opendaylight.controller.sal.reader.NodeTableStatistics;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 /**
  * Stub Implementation for IPluginInReadService used by SAL
- * 
- * 
+ *
+ *
  */
 public class ReadService implements IPluginInReadService {
     private static final Logger logger = LoggerFactory
@@ -35,7 +60,7 @@ public class ReadService implements IPluginInReadService {
     /**
      * Function called by the dependency manager when all the required
      * dependencies are satisfied
-     * 
+     *
      */
     void init() {
     }
@@ -44,7 +69,7 @@ public class ReadService implements IPluginInReadService {
      * Function called by the dependency manager when at least one dependency
      * become unsatisfied or when the component is shutting down because for
      * example bundle is being stopped.
-     * 
+     *
      */
     void destroy() {
     }
@@ -52,7 +77,7 @@ public class ReadService implements IPluginInReadService {
     /**
      * Function called by dependency manager after "init ()" is called and after
      * the services provided by the class are registered in the service registry
-     * 
+     *
      */
     void start() {
     }
@@ -61,7 +86,7 @@ public class ReadService implements IPluginInReadService {
      * Function called by the dependency manager before the services exported by
      * the component are unregistered, this will be followed by a "destroy ()"
      * calls
-     * 
+     *
      */
     void stop() {
     }
@@ -79,30 +104,72 @@ public class ReadService implements IPluginInReadService {
 
     @Override
     public List<FlowOnNode> readAllFlow(Node node, boolean cached) {
-        Flow flow = new Flow();
 
-        Match match = new Match();
+        ArrayList<FlowOnNode> list = new ArrayList<FlowOnNode>();
+        ArrayList<Action> actionList = new ArrayList<Action>();
+        actionList.add(new Drop()); //IT assumes this is first element
+        actionList.add(new Loopback());
+        actionList.add(new Flood());
+        actionList.add(new FloodAll());
+        actionList.add(new Controller());
+        actionList.add(new SwPath());
+        actionList.add(new HwPath());
         try {
-            match.setField(MatchType.NW_DST, InetAddress.getByName("1.1.1.1"));
+            actionList.add(new Output(new NodeConnector("STUB", 0xCAFE, node)));
+        } catch (ConstructionException e) {
+
+        }
+        byte dst[] = { (byte) 1, (byte) 2, (byte) 3, (byte) 4, (byte) 5 };
+        byte src[] = { (byte) 5, (byte) 4, (byte) 3, (byte) 2, (byte) 1 };
+        actionList.add(new SetDlSrc(src));
+        actionList.add(new SetDlDst(dst));
+        actionList.add(new SetDlType(10));
+
+        actionList.add(new SetVlanId(2));
+        actionList.add(new SetVlanPcp(3));
+        actionList.add(new SetVlanCfi(1));
+
+        actionList.add(new PopVlan());
+        actionList.add(new PushVlan(0x8100, 1, 1, 1234));
+
+        try {
+            actionList.add(new SetNwSrc(InetAddress.getByName("2.2.2.2")));
+            actionList.add(new SetNwDst(InetAddress.getByName("1.1.1.1")));
         } catch (UnknownHostException e) {
 
         }
-        flow.setMatch(match);
-        Action action = new Drop();
+        actionList.add(new SetNwTos(0x10));
+        actionList.add(new SetTpSrc(4201));
+        actionList.add(new SetTpDst(8080));
 
-        List<Action> actions = new ArrayList<Action>();
-        actions.add(action);
-        flow.setActions(actions);
+        short priority = 3500; //IT assumes this value
+        for (Action a : actionList) {
+            Flow flow = new Flow();
+            Match match = new Match();
+            try {
+                match.setField(MatchType.NW_DST,
+                        InetAddress.getByName("1.1.1.1"));
+            } catch (UnknownHostException e) {
 
-        FlowOnNode fn1 = new FlowOnNode(flow);
-        fn1.setByteCount(100);
-        fn1.setDurationNanoseconds(400);
-        fn1.setDurationSeconds(40);
-        fn1.setTableId((byte) 0x1);
-        fn1.setPacketCount(200);
+            }
+            flow.setMatch(match);
+            List<Action> actions = new ArrayList<Action>();
+            actions.add(a);
+            flow.setActions(actions);
+            flow.setPriority(priority++);
+            flow.setIdleTimeout((short) 1000);
+            flow.setHardTimeout((short) 2000);
+            flow.setId(12345);
 
-        ArrayList<FlowOnNode> list = new ArrayList<FlowOnNode>();
-        list.add(fn1);
+            FlowOnNode fn1 = new FlowOnNode(flow);
+            fn1.setByteCount(100);
+            fn1.setDurationNanoseconds(400);
+            fn1.setDurationSeconds(40);
+            fn1.setTableId((byte) 0x1);
+            fn1.setPacketCount(200);
+
+            list.add(fn1);
+        }
         return list;
     }
 
@@ -141,9 +208,13 @@ public class ReadService implements IPluginInReadService {
     @Override
     public List<NodeConnectorStatistics> readAllNodeConnector(Node node,
             boolean cached) {
-        NodeConnector nc = NodeConnector.fromStringNoNode("123", node);
         NodeConnectorStatistics stats = new NodeConnectorStatistics();
-        stats.setNodeConnector(nc);
+        try {
+            NodeConnector nc = new NodeConnector("STUB", 0xCAFE, node);
+            stats.setNodeConnector(nc);
+        } catch (ConstructionException e) {
+            // couldn't create nodeconnector.
+        }
         stats.setCollisionCount(4);
         stats.setReceiveByteCount(1000);
         stats.setReceiveCRCErrorCount(1);
@@ -167,4 +238,33 @@ public class ReadService implements IPluginInReadService {
         return 100;
     }
 
+    @Override
+    public NodeTableStatistics readNodeTable(NodeTable table, boolean b) {
+        NodeTableStatistics stats = new NodeTableStatistics();
+        stats.setNodeTable(table);
+        stats.setActiveCount(4);
+        stats.setLookupCount(4);
+        stats.setMatchedCount(4);
+
+        return stats;
+    }
+
+    @Override
+    public List<NodeTableStatistics> readAllNodeTable(Node node, boolean cached) {
+        NodeTableStatistics stats = new NodeTableStatistics();
+        try {
+            NodeTable nt = new NodeTable(NodeTable.NodeTableIDType.OPENFLOW, Byte.valueOf("10"), node);
+            stats.setNodeTable(nt);
+        } catch (ConstructionException e) {
+            // couldn't create nodetable.
+        }
+
+        stats.setActiveCount(4);
+        stats.setLookupCount(4);
+        stats.setMatchedCount(4);
+
+        List<NodeTableStatistics> result = new ArrayList<NodeTableStatistics>();
+        result.add(stats);
+        return result;
+    }
 }