From 698a7d71c1baeebe9bc1b6c58708fa4d0f085b57 Mon Sep 17 00:00:00 2001 From: Michal Rehak Date: Wed, 15 Jan 2014 18:54:36 +0100 Subject: [PATCH] Added dumpMsgCount osgi command + fixed BigInteger constructors to prevent readig byte[] input as negative number + added some copyrights Change-Id: Ie65ae84845ebbfbf77f6164e1521121471e38ab6 Signed-off-by: Michal Rehak --- .../openflowplugin/openflow/md/Activator.java | 1 + .../openflow/md/core/MDController.java | 20 ++++-- .../md/core/SwitchConnectionHandlerImpl.java | 30 ++++++--- .../core/cmd/MessageCountCommandProvider.java | 64 +++++++++++++++++++ .../md/core/sal/OpenflowPluginProvider.java | 18 +++++- .../sal/convertor/OFToMDSalFlowConvertor.java | 4 +- .../convertor/match/MatchConvertorImpl.java | 4 +- .../translator/FlowRemovedTranslator.java | 4 +- .../openflow/md/queue/MessageCountDumper.java | 23 +++++++ .../openflow/md/queue/MessageObservatory.java | 20 ++++++ .../md/queue/MessageSpyCounterImpl.java | 21 ++++-- 11 files changed, 183 insertions(+), 26 deletions(-) create mode 100644 openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/cmd/MessageCountCommandProvider.java create mode 100644 openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/queue/MessageCountDumper.java create mode 100644 openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/queue/MessageObservatory.java diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/Activator.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/Activator.java index 7310dc0547..24e7630e3d 100644 --- a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/Activator.java +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/Activator.java @@ -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; } diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/MDController.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/MDController.java index 4e0d35f496..8988a1d4f3 100644 --- a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/MDController.java +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/MDController.java @@ -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>>> messageTranslators; private Map, Collection>> popListeners; + private MessageSpy 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> srvStarted = switchConnectionProvider.startup(); @@ -278,5 +283,12 @@ public class MDController implements IMDController { } } + /** + * @param messageSpyCounter the messageSpyCounter to set + */ + public void setMessageSpyCounter( + MessageSpy messageSpyCounter) { + this.messageSpyCounter = messageSpyCounter; + } } diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/SwitchConnectionHandlerImpl.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/SwitchConnectionHandlerImpl.java index f571e0094b..e205b29d39 100644 --- a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/SwitchConnectionHandlerImpl.java +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/SwitchConnectionHandlerImpl.java @@ -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 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 index 0000000000..6f57f90267 --- /dev/null +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/cmd/MessageCountCommandProvider.java @@ -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"); + } + } + +} diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/OpenflowPluginProvider.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/OpenflowPluginProvider.java index 291af04874..2737326a3b 100644 --- a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/OpenflowPluginProvider.java +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/OpenflowPluginProvider.java @@ -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 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) { diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/OFToMDSalFlowConvertor.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/OFToMDSalFlowConvertor.java index 23c02f4973..a75bf44860 100644 --- a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/OFToMDSalFlowConvertor.java +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/OFToMDSalFlowConvertor.java @@ -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(); diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/match/MatchConvertorImpl.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/match/MatchConvertorImpl.java index 38bae864fc..e6d9b0ad67 100644 --- a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/match/MatchConvertorImpl.java +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/match/MatchConvertorImpl.java @@ -530,7 +530,7 @@ public class MatchConvertorImpl implements MatchConvertor> { 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> { 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()); diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/translator/FlowRemovedTranslator.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/translator/FlowRemovedTranslator.java index 8912585da3..3665cc7962 100644 --- a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/translator/FlowRemovedTranslator.java +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/translator/FlowRemovedTranslator.java @@ -203,7 +203,7 @@ public class FlowRemovedTranslator implements IMDMessageTranslator 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 index 0000000000..254dedce80 --- /dev/null +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/queue/MessageObservatory.java @@ -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 + * @param + * + */ +public interface MessageObservatory extends MessageSpy, MessageCountDumper { + + // just unifying iface + +} diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/queue/MessageSpyCounterImpl.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/queue/MessageSpyCounterImpl.java index fe32b8c554..c1f82948d8 100644 --- a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/queue/MessageSpyCounterImpl.java +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/queue/MessageSpyCounterImpl.java @@ -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 { +public class MessageSpyCounterImpl implements MessageObservatory { private static final Logger LOG = LoggerFactory .getLogger(MessageSpyCounterImpl.class); @@ -54,11 +55,21 @@ public class MessageSpyCounterImpl implements MessageSpy { public void run() { // log current counters and cleans it if (LOG.isDebugEnabled()) { - for (Entry, 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 dumpMessageCounts() { + List dump = new ArrayList<>(); + for (Entry, 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; + } } -- 2.36.6