HA cache sync for switch manager
[controller.git] / opendaylight / sal / implementation / src / main / java / org / opendaylight / controller / sal / implementation / internal / ReadService.java
index 81bfa5b63fb48b7a8fa18b05ea5b2a4340cad344..edc91173890970b12680fa27628fe378a9ba1490 100644 (file)
@@ -25,6 +25,7 @@ import org.opendaylight.controller.sal.action.Output;
 import org.opendaylight.controller.sal.action.PopVlan;
 import org.opendaylight.controller.sal.core.ConstructionException;
 import org.opendaylight.controller.sal.core.Node;
+import org.opendaylight.controller.sal.core.NodeTable;
 import org.opendaylight.controller.sal.core.NodeConnector;
 import org.opendaylight.controller.sal.core.Node.NodeIDType;
 import org.opendaylight.controller.sal.flowprogrammer.Flow;
@@ -35,10 +36,13 @@ import org.opendaylight.controller.sal.reader.IPluginInReadService;
 import org.opendaylight.controller.sal.reader.IReadService;
 import org.opendaylight.controller.sal.reader.NodeConnectorStatistics;
 import org.opendaylight.controller.sal.reader.NodeDescription;
+import org.opendaylight.controller.sal.reader.NodeTableStatistics;
 import org.opendaylight.controller.sal.utils.EtherTypes;
+import org.opendaylight.controller.sal.utils.GlobalConstants;
 import org.opendaylight.controller.sal.utils.IPProtocols;
 import org.opendaylight.controller.sal.utils.NodeConnectorCreator;
 import org.opendaylight.controller.sal.utils.NodeCreator;
+import org.opendaylight.controller.sal.utils.NodeTableCreator;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.FrameworkUtil;
 import org.slf4j.Logger;
@@ -109,11 +113,11 @@ public class ReadService implements IReadService, CommandProvider {
         String type = null;
         for (Object e : props.entrySet()) {
             Map.Entry entry = (Map.Entry) e;
-            logger.trace("Prop key:(" + entry.getKey() + ") value:("
-                    + entry.getValue() + ")");
+            logger.trace("Prop key:({}) value:({})", entry.getKey(),
+                    entry.getValue());
         }
 
-        Object value = props.get("protocolPluginType");
+        Object value = props.get(GlobalConstants.PROTOCOLPLUGINTYPE.toString());
         if (value instanceof String) {
             type = (String) value;
         }
@@ -122,7 +126,7 @@ public class ReadService implements IReadService, CommandProvider {
                     + "protocolPluginType provided");
         } else {
             this.pluginReader.put(type, s);
-            logger.debug("Stored the pluginReader for type:" + type);
+            logger.debug("Stored the pluginReader for type: {}", type);
         }
     }
 
@@ -136,11 +140,11 @@ public class ReadService implements IReadService, CommandProvider {
         logger.debug("Received unsetpluginReader request");
         for (Object e : props.entrySet()) {
             Map.Entry entry = (Map.Entry) e;
-            logger.trace("Prop key:(" + entry.getKey() + ") value:("
-                    + entry.getValue() + ")");
+            logger.trace("Prop key:({}) value:({})", entry.getKey(),
+                    entry.getValue());
         }
 
-        Object value = props.get("protocoloPluginType");
+        Object value = props.get(GlobalConstants.PROTOCOLPLUGINTYPE.toString());
         if (value instanceof String) {
             type = (String) value;
         }
@@ -149,7 +153,7 @@ public class ReadService implements IReadService, CommandProvider {
                     + "protocolPluginType provided");
         } else if (this.pluginReader.get(type).equals(s)) {
             this.pluginReader.remove(type);
-            logger.debug("Removed the pluginReader for type:" + type);
+            logger.debug("Removed the pluginReader for type: {}", type);
         }
     }
 
@@ -158,10 +162,10 @@ public class ReadService implements IReadService, CommandProvider {
         if (pluginReader != null) {
             if (this.pluginReader.get(node.getType()) != null) {
                 return this.pluginReader.get(node.getType())
-                    .readFlow(node, flow, true);
+                        .readFlow(node, flow, true);
             }
         }
-        logger.warn("Plugin unuvailable");
+        logger.warn("Plugin unavailable");
         return null;
     }
 
@@ -170,10 +174,10 @@ public class ReadService implements IReadService, CommandProvider {
         if (pluginReader != null) {
             if (this.pluginReader.get(node.getType()) != null) {
                 return this.pluginReader.get(node.getType())
-                    .readFlow(node, flow, false);
+                        .readFlow(node, flow, false);
             }
         }
-        logger.warn("Plugin unuvailable");
+        logger.warn("Plugin unavailable");
         return null;
     }
 
@@ -182,10 +186,10 @@ public class ReadService implements IReadService, CommandProvider {
         if (pluginReader != null) {
             if (this.pluginReader.get(node.getType()) != null) {
                 return this.pluginReader.get(node.getType())
-                    .readAllFlow(node, true);
+                        .readAllFlow(node, true);
             }
         }
-        logger.warn("Plugin unuvailable");
+        logger.warn("Plugin unavailable");
         return null;
     }
 
@@ -194,10 +198,10 @@ public class ReadService implements IReadService, CommandProvider {
         if (pluginReader != null) {
             if (this.pluginReader.get(node.getType()) != null) {
                 return this.pluginReader.get(node.getType())
-                    .readAllFlow(node, false);
+                        .readAllFlow(node, false);
             }
         }
-        logger.warn("Plugin unuvailable");
+        logger.warn("Plugin unavailable");
         return null;
     }
 
@@ -206,10 +210,10 @@ public class ReadService implements IReadService, CommandProvider {
         if (pluginReader != null) {
             if (this.pluginReader.get(node.getType()) != null) {
                 return this.pluginReader.get(node.getType())
-                    .readDescription(node, true);
+                        .readDescription(node, true);
             }
         }
-        logger.warn("Plugin unuvailable");
+        logger.warn("Plugin unavailable");
         return null;
     }
 
@@ -218,10 +222,10 @@ public class ReadService implements IReadService, CommandProvider {
         if (pluginReader != null) {
             if (this.pluginReader.get(node.getType()) != null) {
                 return this.pluginReader.get(node.getType())
-                    .readDescription(node, false);
+                        .readDescription(node, false);
             }
         }
-        logger.warn("Plugin unuvailable");
+        logger.warn("Plugin unavailable");
         return null;
     }
 
@@ -231,10 +235,10 @@ public class ReadService implements IReadService, CommandProvider {
         if (pluginReader != null && node != null) {
             if (this.pluginReader.get(node.getType()) != null) {
                 return this.pluginReader.get(node.getType())
-                    .readNodeConnector(connector, true);
+                        .readNodeConnector(connector, true);
             }
         }
-        logger.warn("Plugin unuvailable");
+        logger.warn("Plugin unavailable");
         return null;
     }
 
@@ -245,10 +249,10 @@ public class ReadService implements IReadService, CommandProvider {
         if (pluginReader != null && node != null) {
             if (this.pluginReader.get(node.getType()) != null) {
                 return this.pluginReader.get(node.getType())
-                    .readNodeConnector(connector, false);
+                        .readNodeConnector(connector, false);
             }
         }
-        logger.warn("Plugin unuvailable");
+        logger.warn("Plugin unavailable");
         return null;
     }
 
@@ -257,10 +261,49 @@ public class ReadService implements IReadService, CommandProvider {
         if (pluginReader != null) {
             if (this.pluginReader.get(node.getType()) != null) {
                 return this.pluginReader.get(node.getType())
-                    .readAllNodeConnector(node, true);
+                        .readAllNodeConnector(node, true);
             }
         }
-        logger.warn("Plugin unuvailable");
+        logger.warn("Plugin unavailable");
+        return null;
+    }
+
+    @Override
+    public List<NodeTableStatistics> readNodeTable(Node node) {
+        if (pluginReader != null) {
+            if (this.pluginReader.get(node.getType()) != null) {
+                return this.pluginReader.get(node.getType())
+                        .readAllNodeTable(node, true);
+            }
+        }
+        logger.warn("Plugin unavailable");
+        return null;
+    }
+
+
+    @Override
+    public NodeTableStatistics nonCachedReadNodeTable(NodeTable table) {
+        Node node = table.getNode();
+        if (pluginReader != null && node != null) {
+            if (this.pluginReader.get(node.getType()) != null) {
+                return this.pluginReader.get(node.getType())
+                        .readNodeTable(table, false);
+            }
+        }
+        logger.warn("Plugin unavailable");
+        return null;
+    }
+
+    @Override
+    public NodeTableStatistics readNodeTable(NodeTable table) {
+        Node node = table.getNode();
+        if (pluginReader != null && node != null) {
+            if (this.pluginReader.get(node.getType()) != null) {
+                return this.pluginReader.get(node.getType())
+                        .readNodeTable(table, true);
+            }
+        }
+        logger.warn("Plugin unavailable");
         return null;
     }
 
@@ -269,10 +312,10 @@ public class ReadService implements IReadService, CommandProvider {
         if (pluginReader != null) {
             if (this.pluginReader.get(node.getType()) != null) {
                 return this.pluginReader.get(node.getType())
-                    .readAllNodeConnector(node, false);
+                        .readAllNodeConnector(node, false);
             }
         }
-        logger.warn("Plugin unuvailable");
+        logger.warn("Plugin unavailable");
         return null;
     }
 
@@ -282,10 +325,10 @@ public class ReadService implements IReadService, CommandProvider {
         if (pluginReader != null && node != null) {
             if (this.pluginReader.get(node.getType()) != null) {
                 return this.pluginReader.get(node.getType())
-                    .getTransmitRate(connector);
+                        .getTransmitRate(connector);
             }
         }
-        logger.warn("Plugin unuvailable");
+        logger.warn("Plugin unavailable");
         return 0;
     }
 
@@ -303,15 +346,15 @@ public class ReadService implements IReadService, CommandProvider {
         StringBuffer help = new StringBuffer();
         help.append("---SAL Reader testing commands---\n");
         help
-                .append("\t readflows <sid> <cached>  - Read all the (cached) flows from the openflow switch <sid>\n");
+        .append("\t readflows <sid> <cached>  - Read all the (cached) flows from the openflow switch <sid>\n");
         help
-                .append("\t readflow  <sid> <cached>  - Read the (cached) sample flow from the openflow switch <sid>\n");
+        .append("\t readflow  <sid> <cached>  - Read the (cached) sample flow from the openflow switch <sid>\n");
         help
-                .append("\t readdesc  <sid> <cached>  - Read the (cached) description from openflow switch <sid>\n");
+        .append("\t readdesc  <sid> <cached>  - Read the (cached) description from openflow switch <sid>\n");
         help
-                .append("\t           cached=true/false. If false or not specified, the protocol plugin cached info\n");
+        .append("\t           cached=true/false. If false or not specified, the protocol plugin cached info\n");
         help
-                .append("\t           is returned. If true, the info is directly retrieved from the switch\n");
+        .append("\t           is returned. If true, the info is directly retrieved from the switch\n");
         return help.toString();
     }
 
@@ -328,9 +371,9 @@ public class ReadService implements IReadService, CommandProvider {
         try {
             node = new Node(NodeIDType.OPENFLOW, Long.valueOf(nodeId));
         } catch (NumberFormatException e) {
-            e.printStackTrace();
+            logger.error("",e);
         } catch (ConstructionException e) {
-            e.printStackTrace();
+            logger.error("",e);
         }
         List<FlowOnNode> list = (cached) ? this.readAllFlows(node) : this
                 .nonCachedReadAllFlows(node);
@@ -355,9 +398,9 @@ public class ReadService implements IReadService, CommandProvider {
         try {
             node = new Node(NodeIDType.OPENFLOW, Long.valueOf(nodeId));
         } catch (NumberFormatException e) {
-            e.printStackTrace();
+            logger.error("",e);
         } catch (ConstructionException e) {
-            e.printStackTrace();
+            logger.error("",e);
         }
         Flow flow = getSampleFlow(node);
         FlowOnNode flowOnNode = (cached) ? this.readFlow(node, flow) : this
@@ -382,18 +425,18 @@ public class ReadService implements IReadService, CommandProvider {
         try {
             node = new Node(NodeIDType.OPENFLOW, Long.valueOf(nodeId));
         } catch (NumberFormatException e) {
-            e.printStackTrace();
+            logger.error("",e);
         } catch (ConstructionException e) {
-            e.printStackTrace();
+            logger.error("",e);
         }
         List<NodeConnectorStatistics> list = (cached) ? this
                 .readNodeConnectors(node) : this
                 .nonCachedReadNodeConnectors(node);
-        if (list != null) {
-            ci.println(list.toString());
-        } else {
-            ci.println("null");
-        }
+                if (list != null) {
+                    ci.println(list.toString());
+                } else {
+                    ci.println("null");
+                }
     }
 
     public void _readport(CommandInterpreter ci) {
@@ -417,11 +460,39 @@ public class ReadService implements IReadService, CommandProvider {
         NodeConnectorStatistics stats = (cached) ? this
                 .readNodeConnector(nodeConnector) : this
                 .nonCachedReadNodeConnector(nodeConnector);
-        if (stats != null) {
-            ci.println(stats.toString());
-        } else {
-            ci.println("null");
+                if (stats != null) {
+                    ci.println(stats.toString());
+                } else {
+                    ci.println("null");
+                }
+    }
+
+    public void _readtable(CommandInterpreter ci) {
+        String nodeId = ci.nextArgument();
+        String tableId = ci.nextArgument();
+        String cacheReq = ci.nextArgument();
+        boolean cached;
+        if (nodeId == null) {
+            ci.print("Node id not specified");
+            return;
+        }
+        if (tableId == null) {
+            ci.print("Table id not specified");
+            return;
         }
+        cached = (cacheReq == null) ? true : cacheReq.equals("true");
+        NodeTable nodeTable = null;
+        Node node = NodeCreator.createOFNode(Long.parseLong(nodeId));
+        nodeTable = NodeTableCreator.createNodeTable(Byte
+                .valueOf(tableId), node);
+        NodeTableStatistics stats = (cached) ? this
+                .readNodeTable(nodeTable) : this
+                .nonCachedReadNodeTable(nodeTable);
+                if (stats != null) {
+                    ci.println(stats.toString());
+                } else {
+                    ci.println("null");
+                }
     }
 
     public void _readdescr(CommandInterpreter ci) {
@@ -438,9 +509,9 @@ public class ReadService implements IReadService, CommandProvider {
         try {
             node = new Node(NodeIDType.OPENFLOW, Long.valueOf(nodeId));
         } catch (NumberFormatException e) {
-            e.printStackTrace();
+            logger.error("",e);
         } catch (ConstructionException e) {
-            e.printStackTrace();
+            logger.error("",e);
         }
         NodeDescription desc = (cached) ? this.readDescription(node) : this
                 .nonCachedReadDescription(node);