X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=openflowplugin-impl%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fopenflowplugin%2Fimpl%2Fdevice%2FDeviceContextImpl.java;h=63f97c73afcd8f04e90a77758e2048e324f9f121;hb=d8cc382a8dbdcb7c89b68457b3ae0b6d576ee28f;hp=0fb1b1d929bec9ba5a4aba7e27d03e9f322ab631;hpb=be60232071d79bcb2f237d95f65f62bb5c83d0ce;p=openflowplugin.git diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/device/DeviceContextImpl.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/device/DeviceContextImpl.java index 0fb1b1d929..63f97c73af 100644 --- a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/device/DeviceContextImpl.java +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/device/DeviceContextImpl.java @@ -8,43 +8,39 @@ package org.opendaylight.openflowplugin.impl.device; import com.google.common.annotations.VisibleForTesting; -import com.google.common.base.Function; import com.google.common.base.Preconditions; import com.google.common.base.Verify; -import com.google.common.util.concurrent.AsyncFunction; import com.google.common.util.concurrent.FutureCallback; -import com.google.common.util.concurrent.FutureFallback; import com.google.common.util.concurrent.Futures; import com.google.common.util.concurrent.ListenableFuture; -import io.netty.util.HashedWheelTimer; import io.netty.util.Timeout; import java.math.BigInteger; -import java.util.Collection; import java.util.HashMap; -import java.util.HashSet; import java.util.List; import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; -import javax.annotation.CheckForNull; +import java.util.concurrent.ExecutionException; import javax.annotation.Nonnull; import org.opendaylight.controller.md.sal.binding.api.DataBroker; import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService; -import org.opendaylight.controller.md.sal.binding.api.NotificationService; import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction; import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; +import org.opendaylight.controller.md.sal.common.api.data.TransactionChainClosedException; +import org.opendaylight.mdsal.singleton.common.api.ServiceGroupIdentifier; import org.opendaylight.openflowjava.protocol.api.connection.ConnectionAdapter; import org.opendaylight.openflowjava.protocol.api.connection.OutboundQueue; import org.opendaylight.openflowjava.protocol.api.keys.MessageTypeKey; import org.opendaylight.openflowplugin.api.openflow.connection.ConnectionContext; import org.opendaylight.openflowplugin.api.openflow.connection.OutboundQueueProvider; import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext; +import org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo; +import org.opendaylight.openflowplugin.api.openflow.device.DeviceManager; import org.opendaylight.openflowplugin.api.openflow.device.DeviceState; import org.opendaylight.openflowplugin.api.openflow.device.MessageTranslator; import org.opendaylight.openflowplugin.api.openflow.device.RequestContext; import org.opendaylight.openflowplugin.api.openflow.device.TranslatorLibrary; import org.opendaylight.openflowplugin.api.openflow.device.Xid; -import org.opendaylight.openflowplugin.api.openflow.device.handlers.DeviceTerminationPhaseHandler; import org.opendaylight.openflowplugin.api.openflow.device.handlers.MultiMsgCollector; +import org.opendaylight.openflowplugin.api.openflow.lifecycle.LifecycleConductor; import org.opendaylight.openflowplugin.api.openflow.md.core.SwitchConnectionDistinguisher; import org.opendaylight.openflowplugin.api.openflow.md.core.TranslatorKey; import org.opendaylight.openflowplugin.api.openflow.registry.ItemLifeCycleRegistry; @@ -54,16 +50,13 @@ import org.opendaylight.openflowplugin.api.openflow.registry.flow.FlowRegistryKe import org.opendaylight.openflowplugin.api.openflow.registry.group.DeviceGroupRegistry; import org.opendaylight.openflowplugin.api.openflow.registry.meter.DeviceMeterRegistry; import org.opendaylight.openflowplugin.api.openflow.rpc.ItemLifeCycleKeeper; -import org.opendaylight.openflowplugin.api.openflow.rpc.RpcContext; import org.opendaylight.openflowplugin.api.openflow.rpc.listener.ItemLifecycleListener; -import org.opendaylight.openflowplugin.api.openflow.statistics.StatisticsContext; import org.opendaylight.openflowplugin.api.openflow.statistics.ofpspecific.MessageSpy; import org.opendaylight.openflowplugin.extension.api.ConvertorMessageFromOFJava; import org.opendaylight.openflowplugin.extension.api.ExtensionConverterProviderKeeper; import org.opendaylight.openflowplugin.extension.api.core.extension.ExtensionConverterProvider; import org.opendaylight.openflowplugin.extension.api.exception.ConversionException; import org.opendaylight.openflowplugin.extension.api.path.MessagePath; -import org.opendaylight.openflowplugin.impl.LifecycleConductor; import org.opendaylight.openflowplugin.impl.common.ItemLifeCycleSourceImpl; import org.opendaylight.openflowplugin.impl.common.NodeStaticReplyTranslatorUtil; import org.opendaylight.openflowplugin.impl.device.listener.MultiMsgCollectorImpl; @@ -72,7 +65,7 @@ import org.opendaylight.openflowplugin.impl.registry.flow.FlowRegistryKeyFactory import org.opendaylight.openflowplugin.impl.registry.group.DeviceGroupRegistryImpl; import org.opendaylight.openflowplugin.impl.registry.meter.DeviceMeterRegistryImpl; import org.opendaylight.openflowplugin.impl.util.DeviceInitializationUtils; -import org.opendaylight.openflowplugin.impl.util.MdSalRegistrationUtils; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorExecutor; import org.opendaylight.openflowplugin.openflow.md.core.session.SwitchConnectionCookieOFImpl; import org.opendaylight.yang.gen.v1.urn.opendaylight.experimenter.message.service.rev151020.ExperimenterMessageFromDevBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode; @@ -81,8 +74,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.ta import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowKey; import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId; -import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorRef; -import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId; import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef; import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnector; import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnectorBuilder; @@ -103,7 +94,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.experimenter import org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.PacketReceived; import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.FlowCapableNodeConnectorStatisticsData; import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.FlowCapableNodeConnectorStatisticsDataBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.role.service.rev150727.OfpRole; import org.opendaylight.yangtools.yang.binding.DataObject; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier; @@ -113,7 +103,7 @@ import org.slf4j.LoggerFactory; /** * */ -public class DeviceContextImpl implements DeviceContext, ExtensionConverterProviderKeeper { +public class DeviceContextImpl implements DeviceContext, ExtensionConverterProviderKeeper{ private static final Logger LOG = LoggerFactory.getLogger(DeviceContextImpl.class); @@ -127,91 +117,81 @@ public class DeviceContextImpl implements DeviceContext, ExtensionConverterProvi private final ConnectionContext primaryConnectionContext; private final DeviceState deviceState; private final DataBroker dataBroker; - private final HashedWheelTimer hashedWheelTimer; private final Map auxiliaryConnectionContexts; private final TransactionChainManager transactionChainManager; private final DeviceFlowRegistry deviceFlowRegistry; private final DeviceGroupRegistry deviceGroupRegistry; private final DeviceMeterRegistry deviceMeterRegistry; - private final Collection closeHandlers = new HashSet<>(); private final PacketInRateLimiter packetInLimiter; private final MessageSpy messageSpy; private final ItemLifeCycleKeeper flowLifeCycleKeeper; private NotificationPublishService notificationPublishService; - private NotificationService notificationService; private final OutboundQueue outboundQueueProvider; private Timeout barrierTaskTimeout; private final MessageTranslator portStatusTranslator; private final MessageTranslator packetInTranslator; private final MessageTranslator flowRemovedTranslator; private final TranslatorLibrary translatorLibrary; - private final Map nodeConnectorCache; private final ItemLifeCycleRegistry itemLifeCycleSourceRegistry; - private RpcContext rpcContext; private ExtensionConverterProvider extensionConverterProvider; - - private final boolean switchFeaturesMandatory; - private StatisticsContext statisticsContext; - - private final NodeId nodeId; - - private volatile DEVICE_CONTEXT_STATE deviceCtxState; - - - @VisibleForTesting - DeviceContextImpl(@Nonnull final ConnectionContext primaryConnectionContext, - @Nonnull final DeviceState deviceState, - @Nonnull final DataBroker dataBroker, - @Nonnull final HashedWheelTimer hashedWheelTimer, - @Nonnull final MessageSpy _messageSpy, - @Nonnull final OutboundQueueProvider outboundQueueProvider, - @Nonnull final TranslatorLibrary translatorLibrary, - final boolean switchFeaturesMandatory) { - this.switchFeaturesMandatory = switchFeaturesMandatory; + private final DeviceManager deviceManager; + + private boolean switchFeaturesMandatory; + private final DeviceInfo deviceInfo; + private final ConvertorExecutor convertorExecutor; + private volatile CONTEXT_STATE state; + + public DeviceContextImpl( + @Nonnull final ConnectionContext primaryConnectionContext, + @Nonnull final DataBroker dataBroker, + @Nonnull final LifecycleConductor conductor, + @Nonnull final OutboundQueueProvider outboundQueueProvider, + @Nonnull final TranslatorLibrary translatorLibrary, + @Nonnull final DeviceManager manager, + final ConvertorExecutor convertorExecutor) { this.primaryConnectionContext = Preconditions.checkNotNull(primaryConnectionContext); - this.deviceState = Preconditions.checkNotNull(deviceState); + this.deviceInfo = primaryConnectionContext.getDeviceInfo(); + this.deviceState = new DeviceStateImpl(); this.dataBroker = Preconditions.checkNotNull(dataBroker); - this.hashedWheelTimer = Preconditions.checkNotNull(hashedWheelTimer); + Preconditions.checkNotNull(conductor); this.outboundQueueProvider = Preconditions.checkNotNull(outboundQueueProvider); - this.transactionChainManager = new TransactionChainManager(dataBroker, deviceState); + this.transactionChainManager = new TransactionChainManager(dataBroker, deviceInfo , conductor); auxiliaryConnectionContexts = new HashMap<>(); - deviceFlowRegistry = new DeviceFlowRegistryImpl(); + deviceFlowRegistry = new DeviceFlowRegistryImpl(dataBroker, deviceInfo.getNodeInstanceIdentifier()); deviceGroupRegistry = new DeviceGroupRegistryImpl(); deviceMeterRegistry = new DeviceMeterRegistryImpl(); - messageSpy = _messageSpy; + messageSpy = conductor.getMessageIntelligenceAgency(); + this.deviceManager = Preconditions.checkNotNull(manager); packetInLimiter = new PacketInRateLimiter(primaryConnectionContext.getConnectionAdapter(), /*initial*/ 1000, /*initial*/2000, messageSpy, REJECTED_DRAIN_FACTOR); this.translatorLibrary = translatorLibrary; portStatusTranslator = translatorLibrary.lookupTranslator( - new TranslatorKey(deviceState.getVersion(), PortGrouping.class.getName())); + new TranslatorKey(deviceInfo.getVersion(), PortGrouping.class.getName())); packetInTranslator = translatorLibrary.lookupTranslator( - new TranslatorKey(deviceState.getVersion(), PacketIn.class.getName())); + new TranslatorKey(deviceInfo.getVersion(), PacketIn.class.getName())); flowRemovedTranslator = translatorLibrary.lookupTranslator( - new TranslatorKey(deviceState.getVersion(), FlowRemoved.class.getName())); - - - nodeConnectorCache = new ConcurrentHashMap<>(); + new TranslatorKey(deviceInfo.getVersion(), FlowRemoved.class.getName())); itemLifeCycleSourceRegistry = new ItemLifeCycleRegistryImpl(); flowLifeCycleKeeper = new ItemLifeCycleSourceImpl(); itemLifeCycleSourceRegistry.registerLifeCycleSource(flowLifeCycleKeeper); - deviceCtxState = DEVICE_CONTEXT_STATE.INITIALIZATION; - - nodeId = primaryConnectionContext.getNodeId(); + this.state = CONTEXT_STATE.INITIALIZATION; + this.convertorExecutor = convertorExecutor; } /** * This method is called from {@link DeviceManagerImpl} only. So we could say "posthandshake process finish" * and we are able to set a scheduler for an automatic transaction submitting by time (0,5sec). */ - void initialSubmitTransaction() { + @Override + public void initialSubmitTransaction() { transactionChainManager.initialSubmitWriteTransaction(); } @Override - public Long reservedXidForDeviceMessage() { + public Long reserveXidForDeviceMessage() { return outboundQueueProvider.reserveEntry(); } @@ -228,11 +208,9 @@ public class DeviceContextImpl implements DeviceContext, ExtensionConverterProvi @Override public void removeAuxiliaryConnectionContext(final ConnectionContext connectionContext) { final SwitchConnectionDistinguisher connectionDistinguisher = createConnectionDistinguisher(connectionContext); - if (null != connectionDistinguisher) { - LOG.debug("auxiliary connection dropped: {}, nodeId:{}", connectionContext.getConnectionAdapter() - .getRemoteAddress(), nodeId); - auxiliaryConnectionContexts.remove(connectionDistinguisher); - } + LOG.debug("auxiliary connection dropped: {}, nodeId:{}", connectionContext.getConnectionAdapter() + .getRemoteAddress(), getDeviceInfo().getNodeId()); + auxiliaryConnectionContexts.remove(connectionDistinguisher); } @Override @@ -246,103 +224,21 @@ public class DeviceContextImpl implements DeviceContext, ExtensionConverterProvi } @Override - public ListenableFuture onClusterRoleChange(final OfpRole oldRole, @CheckForNull final OfpRole role) { - LOG.trace("onClusterRoleChange {} for node:", role, nodeId); - Preconditions.checkArgument(role != null); - if (role.equals(oldRole)) { - LOG.debug("Demanded role change for device {} is not changed. OldRole: {}, NewRole {}", nodeId, oldRole, role); - return Futures.immediateFuture(null); - } - if (OfpRole.BECOMEMASTER.equals(role)) { - return onDeviceTakeClusterLeadership(); - } else if (OfpRole.BECOMESLAVE.equals(role)) { - return onDeviceLostClusterLeadership(); - } else { - LOG.warn("Unknown OFCluster Role {} for Node {}", role, nodeId); - if (null != rpcContext) { - MdSalRegistrationUtils.unregisterServices(rpcContext); - } - return transactionChainManager.deactivateTransactionManager(); - } - } - - @Override - public ListenableFuture onDeviceLostClusterLeadership() { - LOG.trace("onDeviceLostClusterLeadership for node: {}", nodeId); - if (null != rpcContext) { - MdSalRegistrationUtils.registerSlaveServices(rpcContext, OfpRole.BECOMESLAVE); - } - return transactionChainManager.deactivateTransactionManager(); - } - - @Override - public ListenableFuture onDeviceTakeClusterLeadership() { - LOG.trace("onDeviceTakeClusterLeadership for node: {}", nodeId); - /* validation */ - if (statisticsContext == null) { - final String errMsg = String.format("DeviceCtx %s is up but we are missing StatisticsContext", nodeId); - LOG.warn(errMsg); - return Futures.immediateFailedFuture(new IllegalStateException(errMsg)); - } - if (rpcContext == null) { - final String errMsg = String.format("DeviceCtx %s is up but we are missing RpcContext", nodeId); - LOG.warn(errMsg); - return Futures.immediateFailedFuture(new IllegalStateException(errMsg)); - } - /* Routed RPC registration */ - MdSalRegistrationUtils.registerMasterServices(getRpcContext(), DeviceContextImpl.this, OfpRole.BECOMEMASTER); - getRpcContext().registerStatCompatibilityServices(); - - /* Prepare init info collecting */ - getDeviceState().setDeviceSynchronized(false); - transactionChainManager.activateTransactionManager(); - /* Init Collecting NodeInfo */ - final ListenableFuture initCollectingDeviceInfo = DeviceInitializationUtils.initializeNodeInformation( - DeviceContextImpl.this, switchFeaturesMandatory); - /* Init Collecting StatInfo */ - final ListenableFuture statPollFuture = Futures.transform(initCollectingDeviceInfo, - new AsyncFunction() { - - @Override - public ListenableFuture apply(final Void input) throws Exception { - getStatisticsContext().statListForCollectingInitialization(); - return getStatisticsContext().gatherDynamicData(); - } - }); - - return Futures.transform(statPollFuture, new Function() { - - @Override - public Void apply(final Boolean input) { - if (ConnectionContext.CONNECTION_STATE.RIP.equals(getPrimaryConnectionContext().getConnectionState())) { - final String errMsg = String.format("We lost connection for Device %s, context has to be closed.", - getDeviceState().getNodeId()); - LOG.warn(errMsg); - throw new IllegalStateException(errMsg); - } - if (!input.booleanValue()) { - final String errMsg = String.format("Get Initial Device %s information fails", - getDeviceState().getNodeId()); - LOG.warn(errMsg); - throw new IllegalStateException(errMsg); - } - LOG.debug("Get Initial Device {} information is successful", nodeId); - getDeviceState().setDeviceSynchronized(true); - initialSubmitTransaction(); - getDeviceState().setStatisticsPollingEnabledProp(true); - return null; - } - }); + public void writeToTransaction(final LogicalDatastoreType store, + final InstanceIdentifier path, + final T data){ + transactionChainManager.writeToTransaction(store, path, data, false); } @Override - public void writeToTransaction(final LogicalDatastoreType store, - final InstanceIdentifier path, final T data) throws Exception { - transactionChainManager.writeToTransaction(store, path, data); + public void writeToTransactionWithParentsSlow(final LogicalDatastoreType store, + final InstanceIdentifier path, + final T data){ + transactionChainManager.writeToTransaction(store, path, data, true); } @Override - public void addDeleteToTxChain(final LogicalDatastoreType store, final InstanceIdentifier path) throws Exception { + public void addDeleteToTxChain(final LogicalDatastoreType store, final InstanceIdentifier path) throws TransactionChainClosedException { transactionChainManager.addDeleteOperationTotTxChain(store, path); } @@ -394,11 +290,19 @@ public class DeviceContextImpl implements DeviceContext, ExtensionConverterProvi @Override public void processFlowRemovedMessage(final FlowRemoved flowRemoved) { + //1. translate to general flow (table, priority, match, cookie) + final org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.FlowRemoved flowRemovedNotification = + flowRemovedTranslator.translate(flowRemoved, deviceInfo, null); + + if(!deviceManager.getIsNotificationFlowRemovedOff()) { + // Trigger off a notification + notificationPublishService.offerNotification(flowRemovedNotification); + } else if(LOG.isDebugEnabled()) { + LOG.debug("For nodeId={} isNotificationFlowRemovedOff={}", getDeviceInfo().getNodeId(), deviceManager.getIsNotificationFlowRemovedOff()); + } + final ItemLifecycleListener itemLifecycleListener = flowLifeCycleKeeper.getItemLifecycleListener(); if (itemLifecycleListener != null) { - //1. translate to general flow (table, priority, match, cookie) - final org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.FlowRemoved flowRemovedNotification = - flowRemovedTranslator.translate(flowRemoved, this, null); //2. create registry key final FlowRegistryKey flowRegKey = FlowRegistryKeyFactory.create(flowRemovedNotification); //3. lookup flowId @@ -406,7 +310,7 @@ public class DeviceContextImpl implements DeviceContext, ExtensionConverterProvi //4. if flowId present: if (flowDescriptor != null) { // a) construct flow path - final KeyedInstanceIdentifier flowPath = getDeviceState().getNodeInstanceIdentifier() + final KeyedInstanceIdentifier flowPath = getDeviceInfo().getNodeInstanceIdentifier() .augmentation(FlowCapableNode.class) .child(Table.class, flowDescriptor.getTableKey()) .child(Flow.class, new FlowKey(flowDescriptor.getFlowId())); @@ -414,7 +318,7 @@ public class DeviceContextImpl implements DeviceContext, ExtensionConverterProvi itemLifecycleListener.onRemoved(flowPath); } else { LOG.debug("flow id not found: nodeId={} tableId={}, priority={}", - getDeviceState().getNodeId(), flowRegKey.getTableId(), flowRemovedNotification.getPriority()); + getDeviceInfo().getNodeId(), flowRegKey.getTableId(), flowRemovedNotification.getPriority()); } } } @@ -422,7 +326,7 @@ public class DeviceContextImpl implements DeviceContext, ExtensionConverterProvi @Override public void processPortStatusMessage(final PortStatusMessage portStatus) { messageSpy.spyMessage(portStatus.getImplementedInterface(), MessageSpy.STATISTIC_GROUP.FROM_SWITCH_PUBLISHED_SUCCESS); - final FlowCapableNodeConnector flowCapableNodeConnector = portStatusTranslator.translate(portStatus, this, null); + final FlowCapableNodeConnector flowCapableNodeConnector = portStatusTranslator.translate(portStatus, getDeviceInfo(), null); final KeyedInstanceIdentifier iiToNodeConnector = provideIIToNodeConnector(portStatus.getPortNo(), portStatus.getVersion()); try { @@ -436,14 +340,14 @@ public class DeviceContextImpl implements DeviceContext, ExtensionConverterProvi addDeleteToTxChain(LogicalDatastoreType.OPERATIONAL, iiToNodeConnector); } submitTransaction(); - } catch (Exception e) { - LOG.warn("Error processing port status message: {}", e.getMessage()); + } catch (final Exception e) { + LOG.warn("Error processing port status message: ", e); } } private KeyedInstanceIdentifier provideIIToNodeConnector(final long portNo, final short version) { - final InstanceIdentifier iiToNodes = deviceState.getNodeInstanceIdentifier(); - final BigInteger dataPathId = deviceState.getFeatures().getDatapathId(); + final InstanceIdentifier iiToNodes = getDeviceInfo().getNodeInstanceIdentifier(); + final BigInteger dataPathId = getDeviceInfo().getDatapathId(); final NodeConnectorId nodeConnectorId = NodeStaticReplyTranslatorUtil.nodeConnectorId(dataPathId.toString(), portNo, version); return iiToNodes.child(NodeConnector.class, new NodeConnectorKey(nodeConnectorId)); } @@ -452,7 +356,7 @@ public class DeviceContextImpl implements DeviceContext, ExtensionConverterProvi public void processPacketInMessage(final PacketInMessage packetInMessage) { messageSpy.spyMessage(packetInMessage.getImplementedInterface(), MessageSpy.STATISTIC_GROUP.FROM_SWITCH); final ConnectionAdapter connectionAdapter = getPrimaryConnectionContext().getConnectionAdapter(); - final PacketReceived packetReceived = packetInTranslator.translate(packetInMessage, this, null); + final PacketReceived packetReceived = packetInTranslator.translate(packetInMessage, getDeviceInfo(), null); if (packetReceived == null) { LOG.debug("Received a null packet from switch {}", connectionAdapter.getRemoteAddress()); @@ -500,13 +404,13 @@ public class DeviceContextImpl implements DeviceContext, ExtensionConverterProvi // lookup converter final ExperimenterDataOfChoice vendorData = notification.getExperimenterDataOfChoice(); final MessageTypeKey key = new MessageTypeKey<>( - deviceState.getVersion(), + getDeviceInfo().getVersion(), (Class) vendorData.getImplementedInterface()); final ConvertorMessageFromOFJava messageConverter = extensionConverterProvider.getMessageConverter(key); if (messageConverter == null) { LOG.warn("custom converter for {}[OF:{}] not found", notification.getExperimenterDataOfChoice().getImplementedInterface(), - deviceState.getVersion()); + getDeviceInfo().getVersion()); return; } // build notification @@ -514,12 +418,12 @@ public class DeviceContextImpl implements DeviceContext, ExtensionConverterProvi try { messageOfChoice = messageConverter.convert(vendorData, MessagePath.MESSAGE_NOTIFICATION); final ExperimenterMessageFromDevBuilder experimenterMessageFromDevBld = new ExperimenterMessageFromDevBuilder() - .setNode(new NodeRef(deviceState.getNodeInstanceIdentifier())) + .setNode(new NodeRef(getDeviceInfo().getNodeInstanceIdentifier())) .setExperimenterMessageOfChoice(messageOfChoice); // publish notificationPublishService.offerNotification(experimenterMessageFromDevBld.build()); } catch (final ConversionException e) { - LOG.warn("Conversion of experimenter notification failed", e); + LOG.error("Conversion of experimenter notification failed", e); } } @@ -528,16 +432,11 @@ public class DeviceContextImpl implements DeviceContext, ExtensionConverterProvi return translatorLibrary; } - @Override - public HashedWheelTimer getTimer() { - return hashedWheelTimer; - } - @Override public synchronized void close() { LOG.debug("closing deviceContext: {}, nodeId:{}", getPrimaryConnectionContext().getConnectionAdapter().getRemoteAddress(), - getDeviceState().getNodeId()); + getDeviceInfo().getNodeId()); // NOOP throw new UnsupportedOperationException("Autocloseble.close will be removed soon"); } @@ -552,11 +451,6 @@ public class DeviceContextImpl implements DeviceContext, ExtensionConverterProvi return barrierTaskTimeout; } - @Override - public void setNotificationService(final NotificationService notificationService) { - this.notificationService = notificationService; - } - @Override public void setNotificationPublishService(final NotificationPublishService notificationPublishService) { this.notificationPublishService = notificationPublishService; @@ -569,8 +463,8 @@ public class DeviceContextImpl implements DeviceContext, ExtensionConverterProvi @Override public void onPublished() { - Verify.verify(DEVICE_CONTEXT_STATE.INITIALIZATION.equals(deviceCtxState)); - deviceCtxState = DEVICE_CONTEXT_STATE.WORKING; + Verify.verify(CONTEXT_STATE.INITIALIZATION.equals(getState())); + setState(CONTEXT_STATE.WORKING); primaryConnectionContext.getConnectionAdapter().setPacketInFiltering(false); for (final ConnectionContext switchAuxConnectionContext : auxiliaryConnectionContexts.values()) { switchAuxConnectionContext.getConnectionAdapter().setPacketInFiltering(false); @@ -582,18 +476,6 @@ public class DeviceContextImpl implements DeviceContext, ExtensionConverterProvi return new MultiMsgCollectorImpl(this, requestContext); } - @Override - public NodeConnectorRef lookupNodeConnectorRef(final Long portNumber) { - return nodeConnectorCache.get(portNumber); - } - - @Override - public void storeNodeConnectorRef(final Long portNumber, final NodeConnectorRef nodeConnectorRef) { - nodeConnectorCache.put( - Preconditions.checkNotNull(portNumber), - Preconditions.checkNotNull(nodeConnectorRef)); - } - @Override public void updatePacketInRateLimit(final long upperBound) { packetInLimiter.changeWaterMarks((int) (LOW_WATERMARK_FACTOR * upperBound), (int) (HIGH_WATERMARK_FACTOR * upperBound)); @@ -604,16 +486,6 @@ public class DeviceContextImpl implements DeviceContext, ExtensionConverterProvi return itemLifeCycleSourceRegistry; } - @Override - public void setRpcContext(final RpcContext rpcContext) { - this.rpcContext = rpcContext; - } - - @Override - public RpcContext getRpcContext() { - return rpcContext; - } - @Override public void setExtensionConverterProvider(final ExtensionConverterProvider extensionConverterProvider) { this.extensionConverterProvider = extensionConverterProvider; @@ -624,28 +496,17 @@ public class DeviceContextImpl implements DeviceContext, ExtensionConverterProvi return extensionConverterProvider; } - @Override - public void setStatisticsContext(final StatisticsContext statisticsContext) { - this.statisticsContext = statisticsContext; - } - - @Override - public StatisticsContext getStatisticsContext() { - return statisticsContext; - } - @Override public synchronized void shutdownConnection() { - LOG.debug("Shutdown method for node {}", nodeId); - deviceState.setValid(false); - if (DEVICE_CONTEXT_STATE.TERMINATION.equals(deviceCtxState)) { - LOG.debug("DeviceCtx for Node {} is in termination process.", nodeId); + LOG.debug("Shutdown method for node {}", getDeviceInfo().getNodeId()); + if (CONTEXT_STATE.TERMINATION.equals(getState())) { + LOG.debug("DeviceCtx for Node {} is in termination process.", getDeviceInfo().getNodeId()); return; } - deviceCtxState = DEVICE_CONTEXT_STATE.TERMINATION; + setState(CONTEXT_STATE.TERMINATION); if (ConnectionContext.CONNECTION_STATE.RIP.equals(getPrimaryConnectionContext().getConnectionState())) { - LOG.debug("ConnectionCtx for Node {} is in RIP state.", deviceState.getNodeId()); + LOG.debug("ConnectionCtx for Node {} is in RIP state.", getDeviceInfo().getNodeId()); return; } /* Terminate Auxiliary Connection */ @@ -662,13 +523,50 @@ public class DeviceContextImpl implements DeviceContext, ExtensionConverterProvi } @Override - public DEVICE_CONTEXT_STATE getDeviceContextState() { - return deviceCtxState; + public ListenableFuture shuttingDownDataStoreTransactions() { + return transactionChainManager.shuttingDown(); + } + + @VisibleForTesting + TransactionChainManager getTransactionChainManager() { + return this.transactionChainManager; } @Override - public ListenableFuture shuttingDownDataStoreTransactions() { - deviceState.setValid(false); - return transactionChainManager.shuttingDown(); + public void setSwitchFeaturesMandatory(boolean switchFeaturesMandatory) { + this.switchFeaturesMandatory = switchFeaturesMandatory; + } + + @Override + public CONTEXT_STATE getState() { + return this.state; + } + + @Override + public void setState(CONTEXT_STATE state) { + this.state = state; + } + + @Override + public void startupClusterServices() throws ExecutionException, InterruptedException { + LOG.debug("Initializing transaction chain manager for node {}", getDeviceInfo().getNodeId()); + this.transactionChainManager.activateTransactionManager(); + LOG.debug("Waiting to get node {} information", getDeviceInfo().getNodeId()); + DeviceInitializationUtils.initializeNodeInformation(this, switchFeaturesMandatory, this.convertorExecutor).get(); + } + + @Override + public ListenableFuture stopClusterServices() { + return this.transactionChainManager.deactivateTransactionManager(); + } + + @Override + public ServiceGroupIdentifier getServiceIdentifier() { + return this.deviceInfo.getServiceIdentifier(); + } + + @Override + public DeviceInfo getDeviceInfo() { + return this.deviceInfo; } }