+ 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>
* Object
*/
public Object[] getGlobalImplementations() {
+ //TODO:: is MDController still needed here?
Object[] res = { MDController.class, pluginProvider };
return res;
}
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;
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;
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;
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();
}
}
+ /**
+ * @param messageSpyCounter the messageSpyCounter to set
+ */
+ public void setMessageSpyCounter(
+ MessageSpy<OfHeader, DataObject> messageSpyCounter) {
+ this.messageSpyCounter = messageSpyCounter;
+ }
}
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 {
*
*/
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);
}
connectionAdapter, queueKeeper);
conductor.setErrorHandler(errorHandler);
}
+
+ /**
+ * @param messageSpy the messageSpy to set
+ */
+ public void setMessageSpy(MessageSpy<OfHeader, DataObject> messageSpy) {
+ this.messageSpy = messageSpy;
+ }
}
--- /dev/null
+/**
+ * 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");
+ }
+ }
+
+}
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;
private SwitchConnectionProvider switchConnectionProvider;
private MDController mdController;
+
+ private MessageCountCommandProvider messageCountCommandProvider;
+ private MessageObservatory<OfHeader, DataObject> messageCountProvider;
+
public void unsetSwitchConnectionProvider() {
switchConnectionProvider = null;
}
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
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) {
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();
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());
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());
.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());
}
}
} 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());
}
--- /dev/null
+/**
+ * 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();
+
+}
--- /dev/null
+/**
+ * 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
+
+}
package org.opendaylight.openflowplugin.openflow.md.queue;
+import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
/**
* 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);
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;
+ }
}