Added dumpMsgCount osgi command 76/4276/3
authorMichal Rehak <mirehak@cisco.com>
Wed, 15 Jan 2014 17:54:36 +0000 (18:54 +0100)
committerGerrit Code Review <gerrit@opendaylight.org>
Thu, 16 Jan 2014 15:53:23 +0000 (15:53 +0000)
+ fixed BigInteger constructors to prevent readig byte[] input as negative number
+ added some copyrights

Change-Id: Ie65ae84845ebbfbf77f6164e1521121471e38ab6
Signed-off-by: Michal Rehak <mirehak@cisco.com>
openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/Activator.java
openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/MDController.java
openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/SwitchConnectionHandlerImpl.java
openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/cmd/MessageCountCommandProvider.java [new file with mode: 0644]
openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/OpenflowPluginProvider.java
openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/OFToMDSalFlowConvertor.java
openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/match/MatchConvertorImpl.java
openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/translator/FlowRemovedTranslator.java
openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/queue/MessageCountDumper.java [new file with mode: 0644]
openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/queue/MessageObservatory.java [new file with mode: 0644]
openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/queue/MessageSpyCounterImpl.java

index 7310dc0547b297987d4c964bcb7be897e47f1433..24e7630e3defa852c70c05de5bf66df17184bd3e 100644 (file)
@@ -91,6 +91,7 @@ public class Activator extends ComponentActivatorAbstractBase {
      *         Object
      */
     public Object[] getGlobalImplementations() {
+        //TODO:: is MDController still needed here?
         Object[] res = { MDController.class, pluginProvider };
         return res;
     }
index 4e0d35f496ccbb347efee0371ba16aad5ef44205..8988a1d4f3010a2adf971459b894e240bcb07302 100644 (file)
@@ -20,7 +20,6 @@ import java.util.concurrent.TimeUnit;
 import java.util.concurrent.TimeoutException;
 
 import org.opendaylight.openflowjava.protocol.api.connection.ConnectionConfiguration;
-import org.opendaylight.openflowjava.protocol.api.connection.SwitchConnectionHandler;
 import org.opendaylight.openflowjava.protocol.spi.connection.SwitchConnectionProvider;
 import org.opendaylight.openflowplugin.openflow.md.core.session.OFSessionUtil;
 import org.opendaylight.openflowplugin.openflow.md.core.translator.ErrorTranslator;
@@ -34,16 +33,17 @@ import org.opendaylight.openflowplugin.openflow.md.core.translator.MultipartRepl
 import org.opendaylight.openflowplugin.openflow.md.core.translator.PacketInTranslator;
 import org.opendaylight.openflowplugin.openflow.md.core.translator.PortStatusMessageToNodeConnectorUpdatedTranslator;
 import org.opendaylight.openflowplugin.openflow.md.lldp.LLDPSpeakerPopListener;
+import org.opendaylight.openflowplugin.openflow.md.queue.MessageSpy;
 import org.opendaylight.openflowplugin.openflow.md.queue.PopListener;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorUpdated;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.SwitchFlowRemoved;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.NodeErrorNotification;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.SwitchFlowRemoved;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.AggregateFlowStatisticsUpdate;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.FlowsStatisticsUpdate;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.FlowTableStatisticsUpdate;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GroupDescStatsUpdated;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GroupFeaturesUpdated;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GroupStatisticsUpdated;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorUpdated;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeUpdated;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.MeterConfigStatsUpdated;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.MeterFeaturesUpdated;
@@ -79,6 +79,7 @@ public class MDController implements IMDController {
 
     private ConcurrentMap<TranslatorKey, Collection<IMDMessageTranslator<OfHeader, List<DataObject>>>> messageTranslators;
     private Map<Class<? extends DataObject>, Collection<PopListener<DataObject>>> popListeners;
+    private MessageSpy<OfHeader, DataObject> messageSpyCounter; 
 
     final private int OF10 = 1;
     final private int OF13 = 4;
@@ -186,8 +187,12 @@ public class MDController implements IMDController {
         LOG.debug("starting ..");
         LOG.debug("switchConnectionProvider: " + switchConnectionProvider);
         // setup handler
-        SwitchConnectionHandler switchConnectionHandler = new SwitchConnectionHandlerImpl();
+        SwitchConnectionHandlerImpl switchConnectionHandler = new SwitchConnectionHandlerImpl();
+        switchConnectionHandler.setMessageSpy(messageSpyCounter);
+        switchConnectionHandler.init();
+        
         switchConnectionProvider.setSwitchConnectionHandler(switchConnectionHandler);
+
         // configure and startup library servers
         switchConnectionProvider.configure(getConnectionConfiguration());
         Future<List<Boolean>> srvStarted = switchConnectionProvider.startup();
@@ -278,5 +283,12 @@ public class MDController implements IMDController {
          }
     }
 
+    /**
+     * @param messageSpyCounter the messageSpyCounter to set
+     */
+    public void setMessageSpyCounter(
+            MessageSpy<OfHeader, DataObject> messageSpyCounter) {
+        this.messageSpyCounter = messageSpyCounter;
+    }
 
 }
index f571e0094b3a05a0ec8f6b69bbdfde86386529a3..e205b29d391c1f94c28621f6c9d27c62070569d1 100644 (file)
@@ -16,14 +16,12 @@ import org.opendaylight.openflowjava.protocol.api.connection.ConnectionAdapter;
 import org.opendaylight.openflowjava.protocol.api.connection.SwitchConnectionHandler;
 import org.opendaylight.openflowplugin.openflow.md.core.session.OFSessionUtil;
 import org.opendaylight.openflowplugin.openflow.md.queue.MessageSpy;
-import org.opendaylight.openflowplugin.openflow.md.queue.MessageSpyCounterImpl;
 import org.opendaylight.openflowplugin.openflow.md.queue.QueueKeeperLightImpl;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader;
 import org.opendaylight.yangtools.yang.binding.DataObject;
 
 /**
- * @author mirehak
- *
+ * basic interconnecting piece between plugin and library 
  */
 public class SwitchConnectionHandlerImpl implements SwitchConnectionHandler {
     
@@ -38,19 +36,26 @@ public class SwitchConnectionHandlerImpl implements SwitchConnectionHandler {
      *
      */
     public SwitchConnectionHandlerImpl() {
-        messageSpy = new MessageSpyCounterImpl();
         queueKeeper = new QueueKeeperLightImpl();
-        queueKeeper.setTranslatorMapping(OFSessionUtil.getTranslatorMap());
-        queueKeeper.setPopListenersMapping(OFSessionUtil.getPopListenerMapping());
-        queueKeeper.setMessageSpy(messageSpy);
         
-        queueKeeper.init();
-
         errorHandler = new ErrorHandlerQueueImpl();
+        //TODO: implement shutdown invocation upon service stop event
         new Thread(errorHandler).start();
         
         //TODO: implement shutdown invocation upon service stop event
         spyPool = new ScheduledThreadPoolExecutor(1);
+    }
+
+    /**
+     * wire all up
+     */
+    public void init() {
+        queueKeeper.setTranslatorMapping(OFSessionUtil.getTranslatorMap());
+        queueKeeper.setPopListenersMapping(OFSessionUtil.getPopListenerMapping());
+        queueKeeper.setMessageSpy(messageSpy);
+        
+        queueKeeper.init();
+        
         spyPool.scheduleAtFixedRate(messageSpy, spyRate, spyRate, TimeUnit.SECONDS);
     }
 
@@ -66,5 +71,12 @@ public class SwitchConnectionHandlerImpl implements SwitchConnectionHandler {
                 connectionAdapter, queueKeeper);
         conductor.setErrorHandler(errorHandler);
     }
+    
+    /**
+     * @param messageSpy the messageSpy to set
+     */
+    public void setMessageSpy(MessageSpy<OfHeader, DataObject> messageSpy) {
+        this.messageSpy = messageSpy;
+    }
 
 }
diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/cmd/MessageCountCommandProvider.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/cmd/MessageCountCommandProvider.java
new file mode 100644 (file)
index 0000000..6f57f90
--- /dev/null
@@ -0,0 +1,64 @@
+/**
+ * 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.openflowplugin.openflow.md.core.cmd;
+
+import org.eclipse.osgi.framework.console.CommandInterpreter;
+import org.eclipse.osgi.framework.console.CommandProvider;
+import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext;
+import org.opendaylight.openflowplugin.openflow.md.queue.MessageCountDumper;
+import org.osgi.framework.BundleContext;
+
+/**
+ * 
+ */
+public class MessageCountCommandProvider implements CommandProvider {
+    
+    private boolean sessionInitiated;
+    private BundleContext ctx;
+    private MessageCountDumper provider;
+    
+    /**
+     * @param ctx
+     * @param provider
+     */
+    public MessageCountCommandProvider(BundleContext ctx, MessageCountDumper provider) {
+        this.ctx = ctx;
+        this.provider = provider;
+    }
+
+    @Override
+    public String getHelp() {
+        String helpString = "----------------- dumpMsgCount--------------\n"
+                + " dumps message counters \n";
+        return helpString;
+    }
+    
+    /**
+     * @param session
+     */
+    public void onSessionInitiated(ProviderContext session) {
+        ctx.registerService(CommandProvider.class.getName(), this, null);
+        this.sessionInitiated = true;
+    }
+    
+    /**
+     * @param ci
+     */
+    public void _dumpMsgCount(CommandInterpreter ci) {
+        if(sessionInitiated) {
+            ci.println("dumping msg counts");
+            for (String countItem : provider.dumpMessageCounts()) {
+                ci.println(countItem);
+            }
+        } else {
+            ci.println("Session not initiated, try again in a few seconds");
+        }
+    }
+
+}
index 291af04874e9aa1b52d8ae8ea9282a9e5a5da4d2..2737326a3b8af2fd1159b71c96f1f2d1487573d2 100644 (file)
@@ -16,6 +16,11 @@ import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderCo
 import org.opendaylight.controller.sal.binding.api.BindingAwareProvider;
 import org.opendaylight.openflowjava.protocol.spi.connection.SwitchConnectionProvider;
 import org.opendaylight.openflowplugin.openflow.md.core.MDController;
+import org.opendaylight.openflowplugin.openflow.md.core.cmd.MessageCountCommandProvider;
+import org.opendaylight.openflowplugin.openflow.md.queue.MessageObservatory;
+import org.opendaylight.openflowplugin.openflow.md.queue.MessageSpyCounterImpl;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader;
+import org.opendaylight.yangtools.yang.binding.DataObject;
 import org.opendaylight.yangtools.yang.binding.RpcService;
 import org.osgi.framework.BundleContext;
 
@@ -31,7 +36,11 @@ public class OpenflowPluginProvider implements BindingAwareProvider {
     private SwitchConnectionProvider switchConnectionProvider;
 
     private MDController mdController;
+    
+    private MessageCountCommandProvider messageCountCommandProvider;
 
+    private MessageObservatory<OfHeader, DataObject> messageCountProvider;
+    
     public void unsetSwitchConnectionProvider() {
         switchConnectionProvider = null;
     }
@@ -52,13 +61,18 @@ public class OpenflowPluginProvider implements BindingAwareProvider {
 
     SalRegistrationManager registrationManager = new SalRegistrationManager();
 
+
     @Override
     public void onSessionInitiated(ProviderContext session) {
+        messageCountProvider = new MessageSpyCounterImpl();
         registrationManager.onSessionInitiated(session);
         mdController = new MDController();
         mdController.setSwitchConnectionProvider(switchConnectionProvider);
+        mdController.setMessageSpyCounter(messageCountProvider);
         mdController.init();
         mdController.start();
+        messageCountCommandProvider = new MessageCountCommandProvider(context, messageCountProvider);
+        messageCountCommandProvider.onSessionInitiated(session);
     }
 
     @Override
@@ -83,11 +97,11 @@ public class OpenflowPluginProvider implements BindingAwareProvider {
     public void setBroker(BindingAwareBroker broker) {
         this.broker = broker;
         registerProvider();
-    };
+    }
 
     public void unsetBroker(BindingAwareBroker broker) {
         this.broker = null;
-    };
+    }
 
     private boolean hasAllDependencies(){
         if(this.broker != null && this.switchConnectionProvider != null) {
index 23c02f49739c6fc2a45c42a76800a4f575c5275c..a75bf448602927d8812307cc053faae781830489 100644 (file)
@@ -127,8 +127,8 @@ public class OFToMDSalFlowConvertor {
                 
                 WriteMetadataCaseBuilder writeMetadataCaseBuilder = new WriteMetadataCaseBuilder();
                 WriteMetadataBuilder writeMetadataBuilder = new WriteMetadataBuilder();
-                writeMetadataBuilder.setMetadata(new BigInteger(metadataInstruction.getMetadata()));
-                writeMetadataBuilder.setMetadataMask(new BigInteger(metadataInstruction.getMetadataMask()));
+                writeMetadataBuilder.setMetadata(new BigInteger(1, metadataInstruction.getMetadata()));
+                writeMetadataBuilder.setMetadataMask(new BigInteger(1, metadataInstruction.getMetadataMask()));
                 writeMetadataCaseBuilder.setWriteMetadata(writeMetadataBuilder.build());
                 
                 InstructionBuilder instBuilder = new InstructionBuilder();
index 38bae864fc763076aa7a0effb1c6646477aa6937..e6d9b0ad67d8e5e2534a922cca681a56685515b6 100644 (file)
@@ -530,7 +530,7 @@ public class MatchConvertorImpl implements MatchConvertor<List<MatchEntries>> {
                 MetadataBuilder metadataBuilder = new MetadataBuilder();
                 MetadataMatchEntry metadataMatchEntry = ofMatch.getAugmentation(MetadataMatchEntry.class);
                 if(metadataMatchEntry != null){
-                    metadataBuilder.setMetadata(new BigInteger(metadataMatchEntry.getMetadata()));
+                    metadataBuilder.setMetadata(new BigInteger(1, metadataMatchEntry.getMetadata()));
                     MaskMatchEntry maskMatchEntry = ofMatch.getAugmentation(MaskMatchEntry.class);
                     if(maskMatchEntry != null){
                         metadataBuilder.setMetadataMask(maskMatchEntry.getMask());
@@ -824,7 +824,7 @@ public class MatchConvertorImpl implements MatchConvertor<List<MatchEntries>> {
                 TunnelBuilder tunnelBuilder = new TunnelBuilder();
                 MetadataMatchEntry metadataMatchEntry = ofMatch.getAugmentation(MetadataMatchEntry.class);
                 if(metadataMatchEntry != null){
-                    tunnelBuilder.setTunnelId(new BigInteger(metadataMatchEntry.getMetadata()));
+                    tunnelBuilder.setTunnelId(new BigInteger(1, metadataMatchEntry.getMetadata()));
                     MaskMatchEntry maskMatchEntry = ofMatch.getAugmentation(MaskMatchEntry.class);
                     if(maskMatchEntry != null){
                         tunnelBuilder.setTunnelMask(maskMatchEntry.getMask());
index 8912585da37feea4bf797fbfed34c54290cd2fec..3665cc7962c0eb729bf435912720f56fb0616264 100644 (file)
@@ -203,7 +203,7 @@ public class FlowRemovedTranslator implements IMDMessageTranslator<OfHeader, Lis
                         .longValue()));
             } else if (field.equals(Metadata.class)) {
                 MetadataBuilder metadata = new MetadataBuilder();
-                metadata.setMetadata(new BigInteger(entry.getAugmentation(MetadataMatchEntry.class).getMetadata()));
+                metadata.setMetadata(new BigInteger(1, entry.getAugmentation(MetadataMatchEntry.class).getMetadata()));
                 if (entry.isHasMask()) {
                     metadata.setMetadataMask(entry.getAugmentation(MaskMatchEntry.class).getMask());
                 }
@@ -417,7 +417,7 @@ public class FlowRemovedTranslator implements IMDMessageTranslator<OfHeader, Lis
                 }
             } else if (field.equals(TunnelId.class)) {
                 TunnelBuilder tunnel = new TunnelBuilder();
-                tunnel.setTunnelId(new BigInteger(entry.getAugmentation(MetadataMatchEntry.class).getMetadata()));
+                tunnel.setTunnelId(new BigInteger(1, entry.getAugmentation(MetadataMatchEntry.class).getMetadata()));
                 if (entry.isHasMask()) {
                     tunnel.setTunnelMask(entry.getAugmentation(MaskMatchEntry.class).getMask());
                 }
diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/queue/MessageCountDumper.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/queue/MessageCountDumper.java
new file mode 100644 (file)
index 0000000..ff59698
--- /dev/null
@@ -0,0 +1,23 @@
+/**
+ * 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.openflowplugin.openflow.md.queue;
+
+import java.util.List;
+
+/**
+ * simple message counters dumper
+ */
+public interface MessageCountDumper {
+
+    /**
+     * @return list of counter items
+     */
+    List<String> dumpMessageCounts();
+
+}
diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/queue/MessageObservatory.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/queue/MessageObservatory.java
new file mode 100644 (file)
index 0000000..254dedc
--- /dev/null
@@ -0,0 +1,20 @@
+/**
+ * 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.openflowplugin.openflow.md.queue;
+
+/**
+ * @param <MSG_IN> 
+ * @param <MSG_OUT> 
+ * 
+ */
+public interface MessageObservatory<MSG_IN, MSG_OUT> extends MessageSpy<MSG_IN, MSG_OUT>, MessageCountDumper {
+
+    // just unifying iface
+    
+}
index fe32b8c554715149a655046e9f50727b8d78d41b..c1f82948d8e715a8bab472ab770578a105e2bb8f 100644 (file)
@@ -8,6 +8,7 @@
 
 package org.opendaylight.openflowplugin.openflow.md.queue;
 
+import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
@@ -23,7 +24,7 @@ import org.slf4j.LoggerFactory;
 /**
  * message counter (by type)
  */
-public class MessageSpyCounterImpl implements MessageSpy<OfHeader, DataObject> {
+public class MessageSpyCounterImpl implements MessageObservatory<OfHeader, DataObject> {
     
     private static final Logger LOG = LoggerFactory
             .getLogger(MessageSpyCounterImpl.class);
@@ -54,11 +55,21 @@ public class MessageSpyCounterImpl implements MessageSpy<OfHeader, DataObject> {
     public void run() {
         // log current counters and cleans it
         if (LOG.isDebugEnabled()) {
-            for (Entry<Class<? extends DataContainer>, AtomicLong[]> statEntry : inputStats.entrySet()) {
-                long amountPerInterval = statEntry.getValue()[0].getAndSet(0);
-                long cumulativeAmount = statEntry.getValue()[1].addAndGet(amountPerInterval);
-                LOG.debug("MSG[{}] -> +{} | {}", statEntry.getKey().getSimpleName(), amountPerInterval, cumulativeAmount);
+            for (String counterItem : dumpMessageCounts()) {
+                LOG.debug(counterItem);
             }
         }
     }
+
+    @Override
+    public List<String> dumpMessageCounts() {
+        List<String> dump = new ArrayList<>();
+        for (Entry<Class<? extends DataContainer>, AtomicLong[]> statEntry : inputStats.entrySet()) {
+            long amountPerInterval = statEntry.getValue()[0].getAndSet(0);
+            long cumulativeAmount = statEntry.getValue()[1].addAndGet(amountPerInterval);
+            dump.add(String.format("MSG[%s] -> +%d | %d", 
+                    statEntry.getKey().getSimpleName(), amountPerInterval, cumulativeAmount));
+        }
+        return dump;
+    }
 }