package org.opendaylight.openflowplugin.impl.device;
import com.google.common.annotations.VisibleForTesting;
-import com.google.common.base.Function;
-import com.google.common.base.Optional;
-import com.google.common.base.Verify;
import com.google.common.util.concurrent.FutureCallback;
import com.google.common.util.concurrent.Futures;
-import com.google.common.util.concurrent.JdkFutureAdapters;
import com.google.common.util.concurrent.ListenableFuture;
+import com.google.common.util.concurrent.MoreExecutors;
import io.netty.util.HashedWheelTimer;
-import io.netty.util.Timeout;
-import io.netty.util.TimerTask;
-import java.math.BigInteger;
import java.util.Collection;
-import java.util.HashMap;
+import java.util.Collections;
+import java.util.HashSet;
import java.util.List;
-import java.util.Map;
import java.util.Objects;
+import java.util.Optional;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
+import java.util.concurrent.atomic.AtomicBoolean;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
import org.opendaylight.mdsal.singleton.common.api.ServiceGroupIdentifier;
import org.opendaylight.openflowjava.protocol.api.connection.ConnectionAdapter;
-import org.opendaylight.openflowjava.protocol.api.connection.OutboundQueueHandlerRegistration;
import org.opendaylight.openflowjava.protocol.api.keys.MessageTypeKey;
-import org.opendaylight.openflowplugin.api.ConnectionException;
import org.opendaylight.openflowplugin.api.OFConstants;
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.ClusterInitializationPhaseHandler;
import org.opendaylight.openflowplugin.api.openflow.device.handlers.MultiMsgCollector;
import org.opendaylight.openflowplugin.api.openflow.lifecycle.ContextChainMastershipState;
-import org.opendaylight.openflowplugin.api.openflow.lifecycle.LifecycleService;
-import org.opendaylight.openflowplugin.api.openflow.lifecycle.MastershipChangeListener;
-import org.opendaylight.openflowplugin.api.openflow.md.core.SwitchConnectionDistinguisher;
+import org.opendaylight.openflowplugin.api.openflow.lifecycle.ContextChainMastershipWatcher;
+import org.opendaylight.openflowplugin.api.openflow.lifecycle.ContextChainState;
import org.opendaylight.openflowplugin.api.openflow.md.core.TranslatorKey;
import org.opendaylight.openflowplugin.api.openflow.md.util.OpenflowVersion;
-import org.opendaylight.openflowplugin.api.openflow.registry.ItemLifeCycleRegistry;
import org.opendaylight.openflowplugin.api.openflow.registry.flow.DeviceFlowRegistry;
-import org.opendaylight.openflowplugin.api.openflow.registry.flow.FlowDescriptor;
-import org.opendaylight.openflowplugin.api.openflow.registry.flow.FlowRegistryKey;
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.listener.ItemLifecycleListener;
import org.opendaylight.openflowplugin.api.openflow.statistics.ofpspecific.MessageSpy;
+import org.opendaylight.openflowplugin.common.txchain.TransactionChainManager;
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.common.ItemLifeCycleSourceImpl;
import org.opendaylight.openflowplugin.impl.datastore.MultipartWriterProvider;
import org.opendaylight.openflowplugin.impl.datastore.MultipartWriterProviderFactory;
import org.opendaylight.openflowplugin.impl.device.initialization.AbstractDeviceInitializer;
import org.opendaylight.openflowplugin.impl.device.initialization.DeviceInitializerProvider;
import org.opendaylight.openflowplugin.impl.device.listener.MultiMsgCollectorImpl;
-import org.opendaylight.openflowplugin.impl.device.listener.OpenflowProtocolListenerFullImpl;
import org.opendaylight.openflowplugin.impl.registry.flow.DeviceFlowRegistryImpl;
-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.rpc.AbstractRequestContext;
+import org.opendaylight.openflowplugin.impl.services.util.RequestContextUtil;
+import org.opendaylight.openflowplugin.impl.util.MatchUtil;
import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorExecutor;
-import org.opendaylight.openflowplugin.openflow.md.core.session.SwitchConnectionCookieOFImpl;
import org.opendaylight.openflowplugin.openflow.md.util.InventoryDataServiceUtil;
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;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNodeConnector;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.Table;
-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.NodeConnectorRef;
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;
import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnectorKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.Match;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortReason;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.Error;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ExperimenterMessage;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowRemoved;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketIn;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketInMessage;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortGrouping;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortStatus;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortStatusMessage;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.experimenter.core.ExperimenterDataOfChoice;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.experimenter.types.rev151020.experimenter.core.message.ExperimenterMessageOfChoice;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.PacketIn;
import org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.PacketReceived;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.PacketReceivedBuilder;
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.yang.gen.v1.urn.opendaylight.role.service.rev150727.SalRoleService;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.role.service.rev150727.SetRoleInput;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.role.service.rev150727.SetRoleInputBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.role.service.rev150727.SetRoleOutput;
+import org.opendaylight.yangtools.yang.binding.DataContainer;
import org.opendaylight.yangtools.yang.binding.DataObject;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
-import org.opendaylight.yangtools.yang.common.RpcResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
// TODO: high water mark factor should be parametrized
private static final float HIGH_WATERMARK_FACTOR = 0.95f;
- // Timeout in seconds after what we will give up on propagating role
- private static final int SET_ROLE_TIMEOUT = 10;
+ // Timeout in milliseconds after what we will give up on initializing device
+ private static final int DEVICE_INIT_TIMEOUT = 9000;
+
+ // Timeout in milliseconds after what we will give up on closing transaction chain
+ private static final int TX_CHAIN_CLOSE_TIMEOUT = 10000;
private static final int LOW_WATERMARK = 1000;
private static final int HIGH_WATERMARK = 2000;
- private final MultipartWriterProvider writerProvider;
-
- private boolean initialized;
- private SalRoleService salRoleService = null;
+ private final MultipartWriterProvider writerProvider;
private final HashedWheelTimer hashedWheelTimer;
- private volatile ConnectionContext primaryConnectionContext;
private final DeviceState deviceState;
private final DataBroker dataBroker;
- private final Map<SwitchConnectionDistinguisher, ConnectionContext> auxiliaryConnectionContexts;
- private TransactionChainManager transactionChainManager;
- private DeviceFlowRegistry deviceFlowRegistry;
- private DeviceGroupRegistry deviceGroupRegistry;
- private DeviceMeterRegistry deviceMeterRegistry;
- private PacketInRateLimiter packetInLimiter;
+ private final Collection<RequestContext<?>> requestContexts = new HashSet<>();
private final MessageSpy messageSpy;
- private final ItemLifeCycleKeeper flowLifeCycleKeeper;
- private NotificationPublishService notificationPublishService;
- private Timeout barrierTaskTimeout;
private final MessageTranslator<PortGrouping, FlowCapableNodeConnector> portStatusTranslator;
private final MessageTranslator<PacketInMessage, PacketReceived> packetInTranslator;
- private final MessageTranslator<FlowRemoved, org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.FlowRemoved> flowRemovedTranslator;
+ private final MessageTranslator<FlowRemoved, org.opendaylight.yang.gen.v1.urn.opendaylight
+ .flow.service.rev130819.FlowRemoved> flowRemovedTranslator;
private final TranslatorLibrary translatorLibrary;
- private final ItemLifeCycleRegistry itemLifeCycleSourceRegistry;
- private ExtensionConverterProvider extensionConverterProvider;
- private boolean skipTableFeatures;
- private boolean switchFeaturesMandatory;
- private DeviceInfo deviceInfo;
private final ConvertorExecutor convertorExecutor;
- private volatile CONTEXT_STATE state;
- private ClusterInitializationPhaseHandler clusterInitializationPhaseHandler;
- private final DeviceManager myManager;
private final DeviceInitializerProvider deviceInitializerProvider;
+ private final PacketInRateLimiter packetInLimiter;
+ private final DeviceInfo deviceInfo;
+ private final ConnectionContext primaryConnectionContext;
+ private final boolean skipTableFeatures;
+ private final boolean switchFeaturesMandatory;
+ private final boolean isFlowRemovedNotificationOn;
private final boolean useSingleLayerSerialization;
- private OutboundQueueProvider outboundQueueProvider;
- private boolean isInitialTransactionSubmitted;
-
- DeviceContextImpl(
- @Nonnull final ConnectionContext primaryConnectionContext,
- @Nonnull final DataBroker dataBroker,
- @Nonnull final MessageSpy messageSpy,
- @Nonnull final TranslatorLibrary translatorLibrary,
- @Nonnull final DeviceManager contextManager,
- final ConvertorExecutor convertorExecutor,
- final boolean skipTableFeatures,
- final HashedWheelTimer hashedWheelTimer,
- final boolean useSingleLayerSerialization,
- final DeviceInitializerProvider deviceInitializerProvider) {
+ private final AtomicBoolean initialized = new AtomicBoolean(false);
+ private final AtomicBoolean hasState = new AtomicBoolean(false);
+ private final AtomicBoolean isInitialTransactionSubmitted = new AtomicBoolean(false);
+ private NotificationPublishService notificationPublishService;
+ private TransactionChainManager transactionChainManager;
+ private DeviceFlowRegistry deviceFlowRegistry;
+ private DeviceGroupRegistry deviceGroupRegistry;
+ private DeviceMeterRegistry deviceMeterRegistry;
+ private ExtensionConverterProvider extensionConverterProvider;
+ private ContextChainMastershipWatcher contextChainMastershipWatcher;
+
+ DeviceContextImpl(@Nonnull final ConnectionContext primaryConnectionContext,
+ @Nonnull final DataBroker dataBroker,
+ @Nonnull final MessageSpy messageSpy,
+ @Nonnull final TranslatorLibrary translatorLibrary,
+ final ConvertorExecutor convertorExecutor,
+ final boolean skipTableFeatures,
+ final HashedWheelTimer hashedWheelTimer,
+ final boolean useSingleLayerSerialization,
+ final DeviceInitializerProvider deviceInitializerProvider,
+ final boolean isFlowRemovedNotificationOn,
+ final boolean switchFeaturesMandatory) {
this.primaryConnectionContext = primaryConnectionContext;
- this.outboundQueueProvider = (OutboundQueueProvider) primaryConnectionContext.getOutboundQueueProvider();
this.deviceInfo = primaryConnectionContext.getDeviceInfo();
this.hashedWheelTimer = hashedWheelTimer;
this.deviceInitializerProvider = deviceInitializerProvider;
- this.myManager = contextManager;
+ this.isFlowRemovedNotificationOn = isFlowRemovedNotificationOn;
+ this.switchFeaturesMandatory = switchFeaturesMandatory;
this.deviceState = new DeviceStateImpl();
this.dataBroker = dataBroker;
- this.auxiliaryConnectionContexts = new HashMap<>();
this.messageSpy = messageSpy;
this.packetInLimiter = new PacketInRateLimiter(primaryConnectionContext.getConnectionAdapter(),
this.portStatusTranslator = translatorLibrary.lookupTranslator(
new TranslatorKey(deviceInfo.getVersion(), PortGrouping.class.getName()));
this.packetInTranslator = translatorLibrary.lookupTranslator(
- new TranslatorKey(deviceInfo.getVersion(), PacketIn.class.getName()));
+ new TranslatorKey(deviceInfo.getVersion(), org.opendaylight.yang.gen.v1.urn.opendaylight.openflow
+ .protocol.rev130731
+ .PacketIn.class.getName()));
this.flowRemovedTranslator = translatorLibrary.lookupTranslator(
new TranslatorKey(deviceInfo.getVersion(), FlowRemoved.class.getName()));
- this.itemLifeCycleSourceRegistry = new ItemLifeCycleRegistryImpl();
- this.flowLifeCycleKeeper = new ItemLifeCycleSourceImpl();
- this.itemLifeCycleSourceRegistry.registerLifeCycleSource(flowLifeCycleKeeper);
- this.state = CONTEXT_STATE.INITIALIZATION;
this.convertorExecutor = convertorExecutor;
this.skipTableFeatures = skipTableFeatures;
this.useSingleLayerSerialization = useSingleLayerSerialization;
- this.initialized = false;
writerProvider = MultipartWriterProviderFactory.createDefaultProvider(this);
}
@Override
public boolean initialSubmitTransaction() {
- if (initialized) {
- isInitialTransactionSubmitted = true;
- return transactionChainManager.initialSubmitWriteTransaction();
+ if (!initialized.get()) {
+ return false;
}
- return false;
- }
-
- @Override
- public void addAuxiliaryConnectionContext(final ConnectionContext connectionContext) {
- final SwitchConnectionDistinguisher connectionDistinguisher = createConnectionDistinguisher(connectionContext);
- auxiliaryConnectionContexts.put(connectionDistinguisher, connectionContext);
- }
-
- private static SwitchConnectionDistinguisher createConnectionDistinguisher(final ConnectionContext connectionContext) {
- return new SwitchConnectionCookieOFImpl(connectionContext.getFeatures().getAuxiliaryId());
- }
-
- @Override
- public void removeAuxiliaryConnectionContext(final ConnectionContext connectionContext) {
- final SwitchConnectionDistinguisher connectionDistinguisher = createConnectionDistinguisher(connectionContext);
- LOG.debug("auxiliary connection dropped: {}, nodeId:{}", connectionContext.getConnectionAdapter()
- .getRemoteAddress(), getDeviceInfo().getLOGValue());
- auxiliaryConnectionContexts.remove(connectionDistinguisher);
+ final boolean initialSubmit = transactionChainManager.initialSubmitWriteTransaction();
+ isInitialTransactionSubmitted.set(initialSubmit);
+ return initialSubmit;
}
@Override
return dataBroker.newReadOnlyTransaction();
}
+ @Override
+ public boolean isTransactionsEnabled() {
+ return isInitialTransactionSubmitted.get();
+ }
+
@Override
public <T extends DataObject> void writeToTransaction(final LogicalDatastoreType store,
final InstanceIdentifier<T> path,
- final T data){
- if (initialized) {
+ final T data) {
+ if (initialized.get()) {
transactionChainManager.writeToTransaction(store, path, data, false);
}
}
@Override
public <T extends DataObject> void writeToTransactionWithParentsSlow(final LogicalDatastoreType store,
final InstanceIdentifier<T> path,
- final T data){
- if (initialized) {
+ final T data) {
+ if (initialized.get()) {
transactionChainManager.writeToTransaction(store, path, data, true);
}
}
@Override
- public <T extends DataObject> void addDeleteToTxChain(final LogicalDatastoreType store, final InstanceIdentifier<T> path) {
- if (initialized) {
- transactionChainManager.addDeleteOperationTotTxChain(store, path);
+ public <T extends DataObject> void addDeleteToTxChain(final LogicalDatastoreType store,
+ final InstanceIdentifier<T> path) {
+ if (initialized.get()) {
+ transactionChainManager.addDeleteOperationToTxChain(store, path);
}
}
@Override
public boolean submitTransaction() {
- return initialized && transactionChainManager.submitWriteTransaction();
+ return initialized.get() && transactionChainManager.submitTransaction();
}
@Override
return primaryConnectionContext;
}
- @Override
- public ConnectionContext getAuxiliaryConnectionContexts(final BigInteger cookie) {
- return auxiliaryConnectionContexts.get(new SwitchConnectionCookieOFImpl(cookie.longValue()));
- }
-
@Override
public DeviceFlowRegistry getDeviceFlowRegistry() {
return deviceFlowRegistry;
public void processReply(final OfHeader ofHeader) {
messageSpy.spyMessage(
ofHeader.getImplementedInterface(),
- (ofHeader instanceof Error)
- ? MessageSpy.STATISTIC_GROUP.FROM_SWITCH_PUBLISHED_FAILURE
- : MessageSpy.STATISTIC_GROUP.FROM_SWITCH_PUBLISHED_SUCCESS);
+ ofHeader instanceof Error
+ ? MessageSpy.StatisticsGroup.FROM_SWITCH_PUBLISHED_FAILURE
+ : MessageSpy.StatisticsGroup.FROM_SWITCH_PUBLISHED_SUCCESS);
}
@Override
public void processReply(final Xid xid, final List<? extends OfHeader> ofHeaderList) {
ofHeaderList.forEach(header -> messageSpy.spyMessage(
header.getImplementedInterface(),
- (header instanceof Error)
- ? MessageSpy.STATISTIC_GROUP.FROM_SWITCH_PUBLISHED_FAILURE
- : MessageSpy.STATISTIC_GROUP.FROM_SWITCH_PUBLISHED_SUCCESS));
+ header instanceof Error
+ ? MessageSpy.StatisticsGroup.FROM_SWITCH_PUBLISHED_FAILURE
+ : MessageSpy.StatisticsGroup.FROM_SWITCH_PUBLISHED_SUCCESS));
}
@Override
final org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.FlowRemoved flowRemovedNotification =
flowRemovedTranslator.translate(flowRemoved, deviceInfo, null);
- if(!myManager.isFlowRemovedNotificationOn()) {
+ if (isFlowRemovedNotificationOn) {
// Trigger off a notification
notificationPublishService.offerNotification(flowRemovedNotification);
- } else if(LOG.isDebugEnabled()) {
- LOG.debug("For nodeId={} isNotificationFlowRemovedOn={}", getDeviceInfo().getLOGValue(), myManager.isFlowRemovedNotificationOn());
- }
-
- final ItemLifecycleListener itemLifecycleListener = flowLifeCycleKeeper.getItemLifecycleListener();
- if (itemLifecycleListener != null) {
- //2. create registry key
- final FlowRegistryKey flowRegKey = FlowRegistryKeyFactory.create(getDeviceInfo().getVersion(), flowRemovedNotification);
- //3. lookup flowId
- final FlowDescriptor flowDescriptor = deviceFlowRegistry.retrieveDescriptor(flowRegKey);
- //4. if flowId present:
- if (flowDescriptor != null) {
- // a) construct flow path
- final KeyedInstanceIdentifier<Flow, FlowKey> flowPath = getDeviceInfo().getNodeInstanceIdentifier()
- .augmentation(FlowCapableNode.class)
- .child(Table.class, flowDescriptor.getTableKey())
- .child(Flow.class, new FlowKey(flowDescriptor.getFlowId()));
- // b) notify listener
- itemLifecycleListener.onRemoved(flowPath);
- } else {
- LOG.debug("flow id not found: nodeId={} tableId={}, priority={}",
- getDeviceInfo().getNodeId(), flowRegKey.getTableId(), flowRemovedNotification.getPriority());
- }
}
}
@Override
+ @SuppressWarnings("checkstyle:IllegalCatch")
public void processPortStatusMessage(final PortStatusMessage portStatus) {
- messageSpy.spyMessage(portStatus.getImplementedInterface(), MessageSpy.STATISTIC_GROUP.FROM_SWITCH_PUBLISHED_SUCCESS);
+ messageSpy.spyMessage(portStatus.getImplementedInterface(), MessageSpy.StatisticsGroup
+ .FROM_SWITCH_PUBLISHED_SUCCESS);
- if (isInitialTransactionSubmitted) {
+ if (initialized.get()) {
try {
writePortStatusMessage(portStatus);
submitTransaction();
} catch (final Exception e) {
LOG.warn("Error processing port status message for port {} on device {}",
- portStatus.getPortNo(), getDeviceInfo().getLOGValue(), e);
+ portStatus.getPortNo(), getDeviceInfo(), e);
}
+ } else if (!hasState.get()) {
+ primaryConnectionContext.handlePortStatusMessage(portStatus);
}
}
portStatusMessage.getPortNo(),
OpenflowVersion.get(deviceInfo.getVersion()))));
- if (PortReason.OFPPRADD.equals(portStatusMessage.getReason()) || PortReason.OFPPRMODIFY.equals(portStatusMessage.getReason())) {
+ if (PortReason.OFPPRADD.equals(portStatusMessage.getReason())
+ || PortReason.OFPPRMODIFY.equals(portStatusMessage.getReason())) {
// because of ADD status node connector has to be created
writeToTransaction(LogicalDatastoreType.OPERATIONAL, iiToNodeConnector, new NodeConnectorBuilder()
.setKey(iiToNodeConnector.getKey())
- .addAugmentation(FlowCapableNodeConnectorStatisticsData.class, new FlowCapableNodeConnectorStatisticsDataBuilder().build())
+ .addAugmentation(FlowCapableNodeConnectorStatisticsData.class, new
+ FlowCapableNodeConnectorStatisticsDataBuilder().build())
.addAugmentation(FlowCapableNodeConnector.class, flowCapableNodeConnector)
.build());
} else if (PortReason.OFPPRDELETE.equals(portStatusMessage.getReason())) {
@Override
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, getDeviceInfo(), null);
+ handlePacketInMessage(packetReceived, packetInMessage.getImplementedInterface(), packetReceived.getMatch());
+ }
- if (packetReceived == null) {
+ private void handlePacketInMessage(final PacketIn packetIn,
+ final Class<?> implementedInterface,
+ final Match match) {
+ messageSpy.spyMessage(implementedInterface, MessageSpy.StatisticsGroup.FROM_SWITCH);
+ final ConnectionAdapter connectionAdapter = getPrimaryConnectionContext().getConnectionAdapter();
+
+ if (packetIn == null) {
LOG.debug("Received a null packet from switch {}", connectionAdapter.getRemoteAddress());
- messageSpy.spyMessage(packetInMessage.getImplementedInterface(), MessageSpy.STATISTIC_GROUP.FROM_SWITCH_TRANSLATE_SRC_FAILURE);
+ messageSpy.spyMessage(implementedInterface, MessageSpy.StatisticsGroup.FROM_SWITCH_TRANSLATE_SRC_FAILURE);
return;
- } else {
- messageSpy.spyMessage(packetReceived.getImplementedInterface(), MessageSpy.STATISTIC_GROUP.FROM_SWITCH_TRANSLATE_OUT_SUCCESS);
}
+ final OpenflowVersion openflowVersion = OpenflowVersion.get(deviceInfo.getVersion());
+
+ // Try to get ingress from match
+ final NodeConnectorRef nodeConnectorRef = Objects.nonNull(packetIn.getIngress())
+ ? packetIn.getIngress() : Optional.ofNullable(match)
+ .map(Match::getInPort)
+ .map(nodeConnectorId -> InventoryDataServiceUtil
+ .portNumberfromNodeConnectorId(
+ openflowVersion,
+ nodeConnectorId))
+ .map(portNumber -> InventoryDataServiceUtil
+ .nodeConnectorRefFromDatapathIdPortno(
+ deviceInfo.getDatapathId(),
+ portNumber,
+ openflowVersion))
+ .orElse(null);
+
+ messageSpy.spyMessage(implementedInterface, MessageSpy.StatisticsGroup.FROM_SWITCH_TRANSLATE_OUT_SUCCESS);
+
if (!packetInLimiter.acquirePermit()) {
LOG.debug("Packet limited");
// TODO: save packet into emergency slot if possible
- messageSpy.spyMessage(packetReceived.getImplementedInterface(), MessageSpy.STATISTIC_GROUP.FROM_SWITCH_PACKET_IN_LIMIT_REACHED_AND_DROPPED);
+ messageSpy.spyMessage(implementedInterface, MessageSpy.StatisticsGroup
+ .FROM_SWITCH_PACKET_IN_LIMIT_REACHED_AND_DROPPED);
return;
}
- final ListenableFuture<?> offerNotification = notificationPublishService.offerNotification(packetReceived);
+ final ListenableFuture<?> offerNotification = notificationPublishService
+ .offerNotification(new PacketReceivedBuilder(packetIn)
+ .setIngress(nodeConnectorRef)
+ .setMatch(MatchUtil.transformMatch(match,
+ org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.packet.received
+ .Match.class))
+ .build());
+
if (NotificationPublishService.REJECTED.equals(offerNotification)) {
LOG.debug("notification offer rejected");
- messageSpy.spyMessage(packetReceived.getImplementedInterface(), MessageSpy.STATISTIC_GROUP.FROM_SWITCH_NOTIFICATION_REJECTED);
+ messageSpy.spyMessage(implementedInterface, MessageSpy.StatisticsGroup.FROM_SWITCH_NOTIFICATION_REJECTED);
packetInLimiter.drainLowWaterMark();
packetInLimiter.releasePermit();
return;
Futures.addCallback(offerNotification, new FutureCallback<Object>() {
@Override
public void onSuccess(final Object result) {
- messageSpy.spyMessage(packetReceived.getImplementedInterface(), MessageSpy.STATISTIC_GROUP.FROM_SWITCH_PUBLISHED_SUCCESS);
+ messageSpy.spyMessage(implementedInterface, MessageSpy.StatisticsGroup.FROM_SWITCH_PUBLISHED_SUCCESS);
packetInLimiter.releasePermit();
}
@Override
- public void onFailure(final Throwable t) {
- messageSpy.spyMessage(packetReceived.getImplementedInterface(), MessageSpy.STATISTIC_GROUP.FROM_SWITCH_NOTIFICATION_REJECTED);
- LOG.debug("notification offer failed: {}", t.getMessage());
- LOG.trace("notification offer failed..", t);
+ public void onFailure(final Throwable throwable) {
+ messageSpy.spyMessage(implementedInterface, MessageSpy.StatisticsGroup
+ .FROM_SWITCH_NOTIFICATION_REJECTED);
+ LOG.debug("notification offer failed: {}", throwable.getMessage());
+ LOG.trace("notification offer failed..", throwable);
packetInLimiter.releasePermit();
}
- });
+ }, MoreExecutors.directExecutor());
}
@Override
final MessageTypeKey<? extends ExperimenterDataOfChoice> key = new MessageTypeKey<>(
getDeviceInfo().getVersion(),
(Class<? extends ExperimenterDataOfChoice>) vendorData.getImplementedInterface());
- final ConvertorMessageFromOFJava<ExperimenterDataOfChoice, MessagePath> messageConverter = extensionConverterProvider.getMessageConverter(key);
+ final ConvertorMessageFromOFJava<ExperimenterDataOfChoice, MessagePath> messageConverter =
+ extensionConverterProvider.getMessageConverter(key);
if (messageConverter == null) {
LOG.warn("custom converter for {}[OF:{}] not found",
notification.getExperimenterDataOfChoice().getImplementedInterface(),
final ExperimenterMessageOfChoice messageOfChoice;
try {
messageOfChoice = messageConverter.convert(vendorData, MessagePath.MESSAGE_NOTIFICATION);
- final ExperimenterMessageFromDevBuilder experimenterMessageFromDevBld = new ExperimenterMessageFromDevBuilder()
+ final ExperimenterMessageFromDevBuilder experimenterMessageFromDevBld = new
+ ExperimenterMessageFromDevBuilder()
.setNode(new NodeRef(getDeviceInfo().getNodeInstanceIdentifier()))
.setExperimenterMessageOfChoice(messageOfChoice);
// publish
}
@Override
- public TranslatorLibrary oook() {
- return translatorLibrary;
- }
+ public boolean processAlienMessage(final OfHeader message) {
+ final Class<? extends DataContainer> implementedInterface = message.getImplementedInterface();
- @Override
- public void setCurrentBarrierTimeout(final Timeout timeout) {
- barrierTaskTimeout = timeout;
+ if (Objects.nonNull(implementedInterface) && org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service
+ .rev130709.PacketInMessage.class.equals(implementedInterface)) {
+ final org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709
+ .PacketInMessage packetInMessage = org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service
+ .rev130709.PacketInMessage.class.cast(message);
+
+ handlePacketInMessage(packetInMessage, implementedInterface, packetInMessage.getMatch());
+ return true;
+ }
+
+ return false;
}
@Override
- public Timeout getBarrierTaskTimeout() {
- return barrierTaskTimeout;
+ public TranslatorLibrary oook() {
+ return translatorLibrary;
}
@Override
@Override
public void onPublished() {
- Verify.verify(CONTEXT_STATE.INITIALIZATION.equals(getState()));
- this.state = CONTEXT_STATE.WORKING;
primaryConnectionContext.getConnectionAdapter().setPacketInFiltering(false);
}
@Override
- public <T extends OfHeader> MultiMsgCollector<T> getMultiMsgCollector(final RequestContext<List<T>> requestContext) {
+ public <T extends OfHeader> MultiMsgCollector<T> getMultiMsgCollector(final RequestContext<List<T>>
+ requestContext) {
return new MultiMsgCollectorImpl<>(this, requestContext);
}
@Override
public void updatePacketInRateLimit(final long upperBound) {
- packetInLimiter.changeWaterMarks((int) (LOW_WATERMARK_FACTOR * upperBound), (int) (HIGH_WATERMARK_FACTOR * upperBound));
- }
-
- @Override
- public ItemLifeCycleRegistry getItemLifeCycleSourceRegistry() {
- return itemLifeCycleSourceRegistry;
+ packetInLimiter.changeWaterMarks((int) (LOW_WATERMARK_FACTOR * upperBound),
+ (int) (HIGH_WATERMARK_FACTOR * upperBound));
}
@Override
return extensionConverterProvider;
}
- @Override
- public synchronized void shutdownConnection() {
- if (LOG.isDebugEnabled()) {
- LOG.debug("Shutdown method for node {}", getDeviceInfo().getLOGValue());
- }
- if (CONTEXT_STATE.TERMINATION.equals(getState())) {
- LOG.debug("DeviceCtx for Node {} is in termination process.", getDeviceInfo().getLOGValue());
- return;
- }
-
- if (ConnectionContext.CONNECTION_STATE.RIP.equals(getPrimaryConnectionContext().getConnectionState())) {
- LOG.debug("ConnectionCtx for Node {} is in RIP state.", getDeviceInfo().getLOGValue());
- return;
- }
-
- // Terminate Auxiliary Connection
- for (final ConnectionContext connectionContext : auxiliaryConnectionContexts.values()) {
- LOG.debug("Closing auxiliary connection {}", connectionContext.getNodeId());
- connectionContext.closeConnection(false);
- }
-
- // Terminate Primary Connection
- getPrimaryConnectionContext().closeConnection(true);
-
- // Close all datastore registries
- if (initialized) {
- deviceGroupRegistry.close();
- deviceFlowRegistry.close();
- deviceMeterRegistry.close();
- }
+ @VisibleForTesting
+ TransactionChainManager getTransactionChainManager() {
+ return this.transactionChainManager;
}
@Override
- public ListenableFuture<Void> shuttingDownDataStoreTransactions() {
- return initialized
- ? this.transactionChainManager.shuttingDown()
+ public ListenableFuture<Void> closeServiceInstance() {
+ final ListenableFuture<Void> listenableFuture = initialized.get()
+ ? transactionChainManager.deactivateTransactionManager()
: Futures.immediateFuture(null);
- }
- @VisibleForTesting
- TransactionChainManager getTransactionChainManager() {
- return this.transactionChainManager;
+ hashedWheelTimer.newTimeout((timerTask) -> {
+ if (!listenableFuture.isDone() && !listenableFuture.isCancelled()) {
+ listenableFuture.cancel(true);
+ }
+ }, TX_CHAIN_CLOSE_TIMEOUT, TimeUnit.MILLISECONDS);
+
+ return listenableFuture;
}
@Override
- public void setSwitchFeaturesMandatory(boolean switchFeaturesMandatory) {
- this.switchFeaturesMandatory = switchFeaturesMandatory;
+ public DeviceInfo getDeviceInfo() {
+ return this.deviceInfo;
}
@Override
- public synchronized void replaceConnection(final ConnectionContext connectionContext) {
-
- primaryConnectionContext = null;
- deviceInfo = null;
- packetInLimiter = null;
-
- primaryConnectionContext = connectionContext;
- deviceInfo = primaryConnectionContext.getDeviceInfo();
-
- packetInLimiter = new PacketInRateLimiter(primaryConnectionContext.getConnectionAdapter(),
- /*initial*/ LOW_WATERMARK, /*initial*/HIGH_WATERMARK, messageSpy, REJECTED_DRAIN_FACTOR);
-
- primaryConnectionContext.setOutboundQueueProvider(outboundQueueProvider);
-
- final OutboundQueueHandlerRegistration<OutboundQueueProvider> outboundQueueHandlerRegistration =
- primaryConnectionContext.getConnectionAdapter().registerOutboundQueueHandler(
- outboundQueueProvider,
- myManager.getBarrierCountLimit(),
- myManager.getBarrierIntervalNanos());
-
- primaryConnectionContext.setOutboundQueueHandleRegistration(outboundQueueHandlerRegistration);
-
- final OpenflowProtocolListenerFullImpl messageListener = new OpenflowProtocolListenerFullImpl(
- primaryConnectionContext.getConnectionAdapter(), this);
-
- primaryConnectionContext.getConnectionAdapter().setMessageListener(messageListener);
-
- LOG.info("ConnectionEvent: Connection on device:{}, NodeId:{} switched.",
- primaryConnectionContext.getConnectionAdapter().getRemoteAddress(),
- primaryConnectionContext.getDeviceInfo().getNodeId());
-
+ public void registerMastershipWatcher(@Nonnull final ContextChainMastershipWatcher newWatcher) {
+ this.contextChainMastershipWatcher = newWatcher;
}
+ @Nonnull
@Override
- public CONTEXT_STATE getState() {
- return this.state;
+ public ServiceGroupIdentifier getIdentifier() {
+ return deviceInfo.getServiceIdentifier();
}
@Override
- public ListenableFuture<Void> stopClusterServices(boolean connectionInterrupted) {
- final ListenableFuture<Void> deactivateTxManagerFuture = initialized
- ? transactionChainManager.deactivateTransactionManager()
- : Futures.immediateFuture(null);
+ public void close() {
+ // Close all datastore registries and transactions
+ if (initialized.getAndSet(false)) {
+ deviceGroupRegistry.close();
+ deviceFlowRegistry.close();
+ deviceMeterRegistry.close();
- if (!connectionInterrupted) {
- final ListenableFuture<Void> makeSlaveFuture
- = Futures.transform(makeDeviceSlave(), new Function<RpcResult<SetRoleOutput>, Void>() {
- @Nullable
- @Override
- public Void apply(@Nullable RpcResult<SetRoleOutput> setRoleOutputRpcResult) {
- return null;
- }
- });
+ final ListenableFuture<Void> txChainShuttingDown = transactionChainManager.shuttingDown();
- Futures.addCallback(makeSlaveFuture, new FutureCallback<Void>() {
+ Futures.addCallback(txChainShuttingDown, new FutureCallback<Void>() {
@Override
- public void onSuccess(@Nullable Void aVoid) {
- if (LOG.isDebugEnabled()) {
- LOG.debug("Role SLAVE was successfully propagated on device, node {}", deviceInfo.getLOGValue());
- }
+ public void onSuccess(@Nullable final Void result) {
+ transactionChainManager.close();
+ transactionChainManager = null;
}
@Override
public void onFailure(final Throwable throwable) {
- LOG.warn("Was not able to set role SLAVE to device on node {} ", deviceInfo.getLOGValue());
- LOG.trace("Error occurred on device role setting, probably connection loss: ", throwable);
+ transactionChainManager.close();
+ transactionChainManager = null;
}
- });
+ }, MoreExecutors.directExecutor());
}
- return deactivateTxManagerFuture;
- }
-
- @Override
- public ServiceGroupIdentifier getServiceIdentifier() {
- return this.deviceInfo.getServiceIdentifier();
- }
- @Override
- public DeviceInfo getDeviceInfo() {
- return this.deviceInfo;
- }
-
- @Override
- public void close() {
- //NOOP
- }
-
- @Override
- public void putLifecycleServiceIntoTxChainManager(final LifecycleService lifecycleService){
- if (initialized) {
- this.transactionChainManager.setLifecycleService(lifecycleService);
- }
+ requestContexts.forEach(requestContext -> RequestContextUtil
+ .closeRequestContextWithRpcError(requestContext, "Connection closed."));
+ requestContexts.clear();
}
@Override
return useSingleLayerSerialization && getDeviceInfo().getVersion() >= OFConstants.OFP_VERSION_1_3;
}
+ // TODO: exception handling should be fixed by using custom checked exception, never RuntimeExceptions
@Override
- public boolean isSkipTableFeatures() {
- return this.skipTableFeatures;
- }
-
- @Override
- public void setSalRoleService(@Nonnull SalRoleService salRoleService) {
- this.salRoleService = salRoleService;
- }
-
- @Override
- public void setLifecycleInitializationPhaseHandler(final ClusterInitializationPhaseHandler handler) {
- this.clusterInitializationPhaseHandler = handler;
- }
-
- @Override
- public boolean onContextInstantiateService(final MastershipChangeListener mastershipChangeListener) {
-
- LOG.info("Starting device context cluster services for node {}", deviceInfo.getLOGValue());
+ @SuppressWarnings({"checkstyle:IllegalCatch"})
+ public void instantiateServiceInstance() {
lazyTransactionManagerInitialization();
- this.transactionChainManager.activateTransactionManager();
try {
- final java.util.Optional<AbstractDeviceInitializer> initializer = deviceInitializerProvider
- .lookup(deviceInfo.getVersion());
+ final List<PortStatusMessage> portStatusMessages = primaryConnectionContext
+ .retrieveAndClearPortStatusMessages();
+
+ portStatusMessages.forEach(this::writePortStatusMessage);
+ submitTransaction();
+ } catch (final Exception ex) {
+ throw new RuntimeException(String.format("Error processing port status messages from device %s: %s",
+ deviceInfo.toString(), ex.toString()), ex);
+ }
- if (initializer.isPresent()) {
- initializer.get().initialize(this, switchFeaturesMandatory, writerProvider, convertorExecutor);
- } else {
- throw new ExecutionException(new ConnectionException("Unsupported version " + deviceInfo.getVersion()));
+ final Optional<AbstractDeviceInitializer> initializer = deviceInitializerProvider
+ .lookup(deviceInfo.getVersion());
+
+ if (initializer.isPresent()) {
+ final Future<Void> initialize = initializer
+ .get()
+ .initialize(this, switchFeaturesMandatory, skipTableFeatures, writerProvider, convertorExecutor);
+
+ try {
+ initialize.get(DEVICE_INIT_TIMEOUT, TimeUnit.MILLISECONDS);
+ } catch (TimeoutException ex) {
+ initialize.cancel(true);
+ throw new RuntimeException(String.format("Failed to initialize device %s in %ss: %s",
+ deviceInfo.toString(), String.valueOf(DEVICE_INIT_TIMEOUT / 1000), ex.toString()), ex);
+ } catch (ExecutionException | InterruptedException ex) {
+ throw new RuntimeException(
+ String.format("Device %s cannot be initialized: %s", deviceInfo.toString(), ex.toString()), ex);
}
- } catch (ExecutionException | InterruptedException e) {
- LOG.warn("Device {} cannot be initialized: ", deviceInfo.getLOGValue(), e);
- return false;
+ } else {
+ throw new RuntimeException(String.format("Unsupported version %s for device %s",
+ deviceInfo.getVersion(),
+ deviceInfo.toString()));
}
- Futures.addCallback(sendRoleChangeToDevice(OfpRole.BECOMEMASTER),
- new RpcResultFutureCallback(mastershipChangeListener));
-
- final ListenableFuture<List<Optional<FlowCapableNode>>> deviceFlowRegistryFill = getDeviceFlowRegistry().fill();
+ final ListenableFuture<List<com.google.common.base.Optional<FlowCapableNode>>> deviceFlowRegistryFill =
+ getDeviceFlowRegistry().fill();
Futures.addCallback(deviceFlowRegistryFill,
- new DeviceFlowRegistryCallback(deviceFlowRegistryFill, mastershipChangeListener));
-
- return this.clusterInitializationPhaseHandler.onContextInstantiateService(mastershipChangeListener);
+ new DeviceFlowRegistryCallback(deviceFlowRegistryFill, contextChainMastershipWatcher),
+ MoreExecutors.directExecutor());
}
@VisibleForTesting
void lazyTransactionManagerInitialization() {
- if (!this.initialized) {
+ if (!this.initialized.get()) {
if (LOG.isDebugEnabled()) {
- LOG.debug("Transaction chain manager for node {} created", deviceInfo.getLOGValue());
+ LOG.debug("Transaction chain manager for node {} created", deviceInfo);
}
- this.transactionChainManager = new TransactionChainManager(dataBroker, deviceInfo);
- this.deviceFlowRegistry = new DeviceFlowRegistryImpl(deviceInfo.getVersion(), dataBroker, deviceInfo.getNodeInstanceIdentifier());
+ this.transactionChainManager = new TransactionChainManager(dataBroker, deviceInfo.getNodeId().getValue());
+ this.deviceFlowRegistry = new DeviceFlowRegistryImpl(deviceInfo.getVersion(), dataBroker,
+ deviceInfo.getNodeInstanceIdentifier());
this.deviceGroupRegistry = new DeviceGroupRegistryImpl();
this.deviceMeterRegistry = new DeviceMeterRegistryImpl();
- this.initialized = true;
}
+
+ transactionChainManager.activateTransactionManager();
+ initialized.set(true);
}
@Nullable
@Override
public <T> RequestContext<T> createRequestContext() {
- return new AbstractRequestContext<T>(deviceInfo.reserveXidForDeviceMessage()) {
+ final Long xid = deviceInfo.reserveXidForDeviceMessage();
+
+ final AbstractRequestContext<T> abstractRequestContext = new AbstractRequestContext<T>(xid) {
@Override
public void close() {
+ requestContexts.remove(this);
}
};
- }
-
- private ListenableFuture<RpcResult<SetRoleOutput>> sendRoleChangeToDevice(final OfpRole newRole) {
- if (LOG.isDebugEnabled()) {
- LOG.debug("Sending new role {} to device {}", newRole, deviceInfo.getNodeId());
- }
-
- final Future<RpcResult<SetRoleOutput>> setRoleOutputFuture;
-
- if (deviceInfo.getVersion() >= OFConstants.OFP_VERSION_1_3) {
- final SetRoleInput setRoleInput = (new SetRoleInputBuilder()).setControllerRole(newRole)
- .setNode(new NodeRef(deviceInfo.getNodeInstanceIdentifier())).build();
-
- setRoleOutputFuture = this.salRoleService.setRole(setRoleInput);
-
- final TimerTask timerTask = timeout -> {
- if (!setRoleOutputFuture.isDone()) {
- LOG.warn("New role {} was not propagated to device {} during {} sec", newRole, deviceInfo.getLOGValue(), SET_ROLE_TIMEOUT);
- setRoleOutputFuture.cancel(true);
- }
- };
-
- hashedWheelTimer.newTimeout(timerTask, SET_ROLE_TIMEOUT, TimeUnit.SECONDS);
- } else {
- LOG.info("Device: {} with version: {} does not support role", deviceInfo.getLOGValue(), deviceInfo.getVersion());
- return Futures.immediateFuture(null);
- }
-
- return JdkFutureAdapters.listenInPoolThread(setRoleOutputFuture);
+ requestContexts.add(abstractRequestContext);
+ return abstractRequestContext;
}
@Override
- public ListenableFuture<RpcResult<SetRoleOutput>> makeDeviceSlave() {
- return sendRoleChangeToDevice(OfpRole.BECOMESLAVE);
- }
-
- private class RpcResultFutureCallback implements FutureCallback<RpcResult<SetRoleOutput>> {
-
- private final MastershipChangeListener mastershipChangeListener;
-
- RpcResultFutureCallback(final MastershipChangeListener mastershipChangeListener) {
- this.mastershipChangeListener = mastershipChangeListener;
- }
-
- @Override
- public void onSuccess(@Nullable RpcResult<SetRoleOutput> setRoleOutputRpcResult) {
- this.mastershipChangeListener.onMasterRoleAcquired(
- deviceInfo,
- ContextChainMastershipState.MASTER_ON_DEVICE
- );
- if (LOG.isDebugEnabled()) {
- LOG.debug("Role MASTER was successfully set on device, node {}", deviceInfo.getLOGValue());
- }
- }
-
- @Override
- public void onFailure(final Throwable throwable) {
- mastershipChangeListener.onNotAbleToStartMastership(
- deviceInfo,
- "Was not able to set MASTER role on device");
- }
+ public void onStateAcquired(final ContextChainState state) {
+ hasState.set(true);
}
- private class DeviceFlowRegistryCallback implements FutureCallback<List<Optional<FlowCapableNode>>> {
- private final ListenableFuture<List<Optional<FlowCapableNode>>> deviceFlowRegistryFill;
- private final MastershipChangeListener mastershipChangeListener;
+ private class DeviceFlowRegistryCallback implements FutureCallback<List<com.google.common.base
+ .Optional<FlowCapableNode>>> {
+ private final ListenableFuture<List<com.google.common.base.Optional<FlowCapableNode>>> deviceFlowRegistryFill;
+ private final ContextChainMastershipWatcher contextChainMastershipWatcher;
DeviceFlowRegistryCallback(
- ListenableFuture<List<Optional<FlowCapableNode>>> deviceFlowRegistryFill,
- MastershipChangeListener mastershipChangeListener) {
+ ListenableFuture<List<com.google.common.base.Optional<FlowCapableNode>>> deviceFlowRegistryFill,
+ ContextChainMastershipWatcher contextChainMastershipWatcher) {
this.deviceFlowRegistryFill = deviceFlowRegistryFill;
- this.mastershipChangeListener = mastershipChangeListener;
+ this.contextChainMastershipWatcher = contextChainMastershipWatcher;
}
@Override
- public void onSuccess(@Nullable List<Optional<FlowCapableNode>> result) {
+ public void onSuccess(@Nullable List<com.google.common.base.Optional<FlowCapableNode>> result) {
if (LOG.isDebugEnabled()) {
// Count all flows we read from datastore for debugging purposes.
// This number do not always represent how many flows were actually added
// to DeviceFlowRegistry, because of possible duplicates.
- long flowCount = Optional.fromNullable(result).asSet().stream()
+ long flowCount = Optional.ofNullable(result)
+ .map(Collections::singleton)
+ .orElse(Collections.emptySet())
+ .stream()
.flatMap(Collection::stream)
.filter(Objects::nonNull)
.flatMap(flowCapableNodeOptional -> flowCapableNodeOptional.asSet().stream())
.filter(Objects::nonNull)
.count();
- LOG.debug("Finished filling flow registry with {} flows for node: {}", flowCount, deviceInfo.getLOGValue());
+ LOG.debug("Finished filling flow registry with {} flows for node: {}", flowCount, deviceInfo);
}
- this.mastershipChangeListener.onMasterRoleAcquired(deviceInfo, ContextChainMastershipState.INITIAL_FLOW_REGISTRY_FILL);
+ this.contextChainMastershipWatcher.onMasterRoleAcquired(deviceInfo, ContextChainMastershipState
+ .INITIAL_FLOW_REGISTRY_FILL);
}
@Override
- public void onFailure(Throwable t) {
+ public void onFailure(Throwable throwable) {
if (deviceFlowRegistryFill.isCancelled()) {
if (LOG.isDebugEnabled()) {
- LOG.debug("Cancelled filling flow registry with flows for node: {}", deviceInfo.getLOGValue());
+ LOG.debug("Cancelled filling flow registry with flows for node: {}", deviceInfo);
}
} else {
- LOG.warn("Failed filling flow registry with flows for node: {} with exception: {}", deviceInfo.getLOGValue(), t);
+ LOG.warn("Failed filling flow registry with flows for node: {} with exception: {}", deviceInfo,
+ throwable);
}
- mastershipChangeListener.onNotAbleToStartMastership(
+ contextChainMastershipWatcher.onNotAbleToStartMastership(
deviceInfo,
- "Was not able to fill flow registry on device");
+ "Was not able to fill flow registry on device",
+ false);
}
}