import org.opendaylight.openflowplugin.api.openflow.device.handlers.DeviceReplyProcessor;
import org.opendaylight.openflowplugin.api.openflow.device.handlers.MultiMsgCollector;
import org.opendaylight.openflowplugin.api.openflow.lifecycle.ContextChainStateListener;
-import org.opendaylight.openflowplugin.api.openflow.registry.ItemLifeCycleRegistry;
import org.opendaylight.openflowplugin.api.openflow.statistics.ofpspecific.MessageSpy;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader;
*/
void updatePacketInRateLimit(long upperBound);
- /**
- * Getter.
- * @return registry point for item life cycle sources of device
- */
- ItemLifeCycleRegistry getItemLifeCycleSourceRegistry();
-
/**
* Checks if device and controller supports single layer serialization.
* @return true if single layer serialization is supported
+++ /dev/null
-/*
- * Copyright (c) 2015 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.api.openflow.registry;
-
-import org.opendaylight.openflowplugin.api.openflow.rpc.ItemLifeCycleSource;
-import org.opendaylight.yangtools.concepts.Registration;
-
-/**
- * Registration point for any kind of lifecycle sources per device.
- */
-public interface ItemLifeCycleRegistry {
-
- /**
- * register given life cycle source to known sources of device.
- *
- * @param lifeCycleSource life cycle changes provider
- * @return closeable registration
- */
- Registration registerLifeCycleSource(ItemLifeCycleSource lifeCycleSource);
-
- /**
- * close all existing registrations.
- */
- void clear();
-
- /**
- * Registered sources.
- * @return registered sources
- */
- Iterable<ItemLifeCycleSource> getLifeCycleSources();
-}
+++ /dev/null
-/*
- * Copyright (c) 2015 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.api.openflow.rpc;
-
-import javax.annotation.Nullable;
-import org.opendaylight.openflowplugin.api.openflow.rpc.listener.ItemLifecycleListener;
-
-/**
- * provides read-write access to assigned {@link ItemLifecycleListener}.
- */
-public interface ItemLifeCycleKeeper extends ItemLifeCycleSource {
-
- /**
- * lifecycle listener.
- * @return assigned item lifecycle listener
- */
- @Nullable
- ItemLifecycleListener getItemLifecycleListener();
-}
+++ /dev/null
-/*
- * Copyright (c) 2015 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.api.openflow.rpc;
-
-import javax.annotation.Nullable;
-import org.opendaylight.openflowplugin.api.openflow.rpc.listener.ItemLifecycleListener;
-
-/**
- * A source of switch item lifecycle enables for injecting of
- * a {@link org.opendaylight.openflowplugin.api.openflow.rpc.listener.ItemLifecycleListener}
- * in order to act upon item lifecycle changes.
- */
-public interface ItemLifeCycleSource {
-
- /**
- * lifecycle changes.
- * @param itemLifecycleListener acts upon lifecycle changes
- */
- void setItemLifecycleListener(@Nullable ItemLifecycleListener itemLifecycleListener);
-
-
-}
+++ /dev/null
-/*
- * Copyright (c) 2015 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.api.openflow.rpc.listener;
-
-import org.opendaylight.yangtools.yang.binding.DataObject;
-import org.opendaylight.yangtools.yang.binding.Identifiable;
-import org.opendaylight.yangtools.yang.binding.Identifier;
-import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
-
-/**
- * Flow/group/meter lifecycle listener - aimed on rpc result approved by barrier message.
- */
-public interface ItemLifecycleListener {
-
- /**
- * react upon item added event.
- *
- * @param itemPath keyed path in DS
- * @param itemBody item body
- */
-
- <I extends Identifiable<K> & DataObject, K extends Identifier<I>> void onAdded(
- KeyedInstanceIdentifier<I, K> itemPath, I itemBody);
-
- /**
- * react upon item removed event.
- *
- * @param itemPath keyed path in DS
- */
- <I extends Identifiable<K> & DataObject, K extends Identifier<I>> void onRemoved(
- KeyedInstanceIdentifier<I, K> itemPath);
-
- /**
- * react upon item updated event.
- *
- * @param itemPath keyed path in DS
- * @param itemBody item body
- */
-
- <I extends Identifiable<K> & DataObject, K extends Identifier<I>> void onUpdated(
- KeyedInstanceIdentifier<I, K> itemPath, I itemBody);
-}
+++ /dev/null
-/*
- * Copyright (c) 2015 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.impl.common;
-
-import javax.annotation.Nullable;
-import org.opendaylight.openflowplugin.api.openflow.rpc.ItemLifeCycleKeeper;
-import org.opendaylight.openflowplugin.api.openflow.rpc.ItemLifeCycleSource;
-import org.opendaylight.openflowplugin.api.openflow.rpc.listener.ItemLifecycleListener;
-
-/**
- * simple standalone {@link ItemLifeCycleSource} implementation.
- */
-public class ItemLifeCycleSourceImpl implements ItemLifeCycleKeeper {
-
- private ItemLifecycleListener itemLifecycleListener;
-
- @Override
- public void setItemLifecycleListener(@Nullable ItemLifecycleListener itemLifecycleListener) {
-
- this.itemLifecycleListener = itemLifecycleListener;
- }
-
- @Override
- public ItemLifecycleListener getItemLifecycleListener() {
- return itemLifecycleListener;
- }
-}
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.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.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.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;
private final DataBroker dataBroker;
private final Collection<RequestContext<?>> requestContexts = new HashSet<>();
private final MessageSpy messageSpy;
- private final ItemLifeCycleKeeper flowLifeCycleKeeper;
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 TranslatorLibrary translatorLibrary;
- private final ItemLifeCycleRegistry itemLifeCycleSourceRegistry;
private final ConvertorExecutor convertorExecutor;
private final DeviceInitializerProvider deviceInitializerProvider;
private final PacketInRateLimiter packetInLimiter;
this.flowRemovedTranslator = translatorLibrary.lookupTranslator(
new TranslatorKey(deviceInfo.getVersion(), FlowRemoved.class.getName()));
- this.itemLifeCycleSourceRegistry = new ItemLifeCycleRegistryImpl();
- this.flowLifeCycleKeeper = new ItemLifeCycleSourceImpl();
- this.itemLifeCycleSourceRegistry.registerLifeCycleSource(flowLifeCycleKeeper);
this.convertorExecutor = convertorExecutor;
this.skipTableFeatures = skipTableFeatures;
this.useSingleLayerSerialization = useSingleLayerSerialization;
// Trigger off a notification
notificationPublishService.offerNotification(flowRemovedNotification);
}
-
- 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
(int) (HIGH_WATERMARK_FACTOR * upperBound));
}
- @Override
- public ItemLifeCycleRegistry getItemLifeCycleSourceRegistry() {
- return itemLifeCycleSourceRegistry;
- }
-
@Override
public void setExtensionConverterProvider(final ExtensionConverterProvider extensionConverterProvider) {
this.extensionConverterProvider = extensionConverterProvider;
+++ /dev/null
-/*
- * Copyright (c) 2015 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.impl.device;
-
-import java.util.Collections;
-import java.util.Set;
-import java.util.concurrent.ConcurrentHashMap;
-import org.opendaylight.openflowplugin.api.openflow.registry.ItemLifeCycleRegistry;
-import org.opendaylight.openflowplugin.api.openflow.rpc.ItemLifeCycleSource;
-import org.opendaylight.yangtools.concepts.Registration;
-
-/**
- * Default implementation.
- */
-public class ItemLifeCycleRegistryImpl implements ItemLifeCycleRegistry {
-
- private final Set<ItemLifeCycleSource> registry;
-
- public ItemLifeCycleRegistryImpl() {
- registry = Collections.newSetFromMap(new ConcurrentHashMap<ItemLifeCycleSource, Boolean>());
- }
-
-
- @Override
-
- public Registration registerLifeCycleSource(final ItemLifeCycleSource lifeCycleSource) {
- registry.add(lifeCycleSource);
- return () -> registry.remove(lifeCycleSource);
- }
-
- @Override
- public void clear() {
- registry.clear();
- }
-
- @Override
- public Iterable<ItemLifeCycleSource> getLifeCycleSources() {
- return Collections.unmodifiableCollection(registry);
- }
-}
@Override
public ConnectionStatus deviceConnected(final ConnectionContext connectionContext) throws Exception {
-
final DeviceInfo deviceInfo = connectionContext.getDeviceInfo();
final ContextChain contextChain = contextChainMap.get(deviceInfo);
-
final FeaturesReply featuresReply = connectionContext.getFeatures();
final Short auxiliaryId = featuresReply != null ? featuresReply.getAuxiliaryId() : null;
@Override
@SuppressWarnings("checkstyle:IllegalCatch")
public void instantiateServiceInstance() {
-
try {
contexts.forEach(OFPContext::instantiateServiceInstance);
LOG.info("Started clustering services for node {}", deviceInfo);
+++ /dev/null
-/*
- * Copyright (c) 2015 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.impl.rpc.listener;
-
-import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
-import org.opendaylight.openflowplugin.api.openflow.device.TxFacade;
-import org.opendaylight.openflowplugin.api.openflow.rpc.listener.ItemLifecycleListener;
-import org.opendaylight.yangtools.yang.binding.DataObject;
-import org.opendaylight.yangtools.yang.binding.Identifiable;
-import org.opendaylight.yangtools.yang.binding.Identifier;
-import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * General implementation of {@link ItemLifecycleListener} - keeping of DS/operational reflection up-to-date.
- */
-public class ItemLifecycleListenerImpl implements ItemLifecycleListener {
-
- private static final Logger LOG = LoggerFactory.getLogger(ItemLifecycleListenerImpl.class);
- private static final String NOT_ABLE_TO_WRITE_TO_TRANSACTION = "Not able to write to transaction: ";
-
- private final TxFacade txFacade;
-
- public ItemLifecycleListenerImpl(final TxFacade txFacade) {
- this.txFacade = txFacade;
- }
-
- @Override
- @SuppressWarnings("checkstyle:IllegalCatch")
- public <I extends Identifiable<K> & DataObject, K extends Identifier<I>>
- void onAdded(KeyedInstanceIdentifier<I, K> itemPath, I itemBody) {
- try {
- txFacade.writeToTransaction(LogicalDatastoreType.OPERATIONAL, itemPath, itemBody);
- txFacade.submitTransaction();
- } catch (Exception e) {
- LOG.warn(NOT_ABLE_TO_WRITE_TO_TRANSACTION, e);
- }
- }
-
- @Override
- @SuppressWarnings("checkstyle:IllegalCatch")
- public <I extends Identifiable<K> & DataObject, K extends Identifier<I>>
- void onRemoved(KeyedInstanceIdentifier<I, K> itemPath) {
- try {
- txFacade.addDeleteToTxChain(LogicalDatastoreType.OPERATIONAL, itemPath);
- txFacade.submitTransaction();
- } catch (Exception e) {
- LOG.warn(NOT_ABLE_TO_WRITE_TO_TRANSACTION, e);
- }
- }
-
- @Override
- @SuppressWarnings("checkstyle:IllegalCatch")
- public <I extends Identifiable<K> & DataObject, K extends Identifier<I>>
- void onUpdated(KeyedInstanceIdentifier<I, K> itemPath, I itemBody) {
- try {
- txFacade.addDeleteToTxChain(LogicalDatastoreType.OPERATIONAL, itemPath);
- txFacade.writeToTransaction(LogicalDatastoreType.OPERATIONAL, itemPath, itemBody);
- txFacade.submitTransaction();
- } catch (Exception e) {
- LOG.warn(NOT_ABLE_TO_WRITE_TO_TRANSACTION, e);
- }
- }
-}
import java.util.List;
import java.util.Objects;
import java.util.concurrent.Future;
-import javax.annotation.Nullable;
import org.opendaylight.openflowplugin.api.OFConstants;
import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack;
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.rpc.ItemLifeCycleSource;
-import org.opendaylight.openflowplugin.api.openflow.rpc.listener.ItemLifecycleListener;
import org.opendaylight.openflowplugin.impl.registry.flow.FlowDescriptorFactory;
import org.opendaylight.openflowplugin.impl.registry.flow.FlowRegistryKeyFactory;
import org.opendaylight.openflowplugin.impl.services.multilayer.MultiLayerFlowService;
import org.opendaylight.openflowplugin.impl.services.singlelayer.SingleLayerFlowService;
import org.opendaylight.openflowplugin.impl.util.ErrorUtil;
-import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorExecutor;
import org.opendaylight.openflowplugin.impl.util.FlowCreatorUtil;
+import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorExecutor;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId;
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.FlowBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowKey;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowInput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowInputBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-public class SalFlowServiceImpl implements SalFlowService, ItemLifeCycleSource {
+public class SalFlowServiceImpl implements SalFlowService {
private static final Logger LOG = LoggerFactory.getLogger(SalFlowServiceImpl.class);
private final MultiLayerFlowService<UpdateFlowOutput> flowUpdate;
private final MultiLayerFlowService<AddFlowOutput> flowAdd;
private final SingleLayerFlowService<UpdateFlowOutput> flowUpdateMessage;
private final SingleLayerFlowService<RemoveFlowOutput> flowRemoveMessage;
private final DeviceContext deviceContext;
- private ItemLifecycleListener itemLifecycleListener;
public SalFlowServiceImpl(final RequestContextStack requestContextStack,
final DeviceContext deviceContext,
flowRemoveMessage = new SingleLayerFlowService<>(requestContextStack, deviceContext, RemoveFlowOutput.class);
}
- @Override
- public void setItemLifecycleListener(@Nullable ItemLifecycleListener itemLifecycleListener) {
- this.itemLifecycleListener = itemLifecycleListener;
- }
-
@Override
public Future<RpcResult<AddFlowOutput>> addFlow(final AddFlowInput input) {
final FlowRegistryKey flowRegistryKey =
if (LOG.isDebugEnabled()) {
LOG.debug("Flow add with id={} finished without error", flowDescriptor.getFlowId().getValue());
}
-
- if (itemLifecycleListener != null) {
- KeyedInstanceIdentifier<Flow, FlowKey> flowPath = createFlowPath(flowDescriptor,
- deviceContext.getDeviceInfo().getNodeInstanceIdentifier());
- final FlowBuilder flowBuilder = new FlowBuilder(input).setId(flowDescriptor.getFlowId());
- itemLifecycleListener.onAdded(flowPath, flowBuilder.build());
- }
} else {
if (LOG.isDebugEnabled()) {
LOG.debug("Flow add failed for flow={}, errors={}", input,
FlowRegistryKey flowRegistryKey =
FlowRegistryKeyFactory.create(deviceContext.getDeviceInfo().getVersion(), input);
deviceContext.getDeviceFlowRegistry().addMark(flowRegistryKey);
-
- if (itemLifecycleListener != null) {
- final FlowDescriptor flowDescriptor =
- deviceContext.getDeviceFlowRegistry().retrieveDescriptor(flowRegistryKey);
-
- if (flowDescriptor != null) {
- KeyedInstanceIdentifier<Flow, FlowKey> flowPath = createFlowPath(flowDescriptor,
- deviceContext.getDeviceInfo().getNodeInstanceIdentifier());
- itemLifecycleListener.onRemoved(flowPath);
- }
- }
} else {
if (LOG.isDebugEnabled()) {
LOG.debug("Flow remove failed for flow={}, errors={}", input,
deviceFlowRegistry.addMark(origFlowRegistryKey);
deviceFlowRegistry.storeDescriptor(updatedFlowRegistryKey, updatedFlowDescriptor);
}
-
- if (itemLifecycleListener != null) {
- final KeyedInstanceIdentifier<Flow, FlowKey> flowPath =
- createFlowPath(
- updatedFlowDescriptor,
- deviceContext.getDeviceInfo().getNodeInstanceIdentifier());
-
- final Flow flow = new FlowBuilder(updated)
- .setId(updatedFlowDescriptor.getFlowId())
- .build();
-
- if (Objects.nonNull(origFlowDescriptor)) {
- itemLifecycleListener.onUpdated(flowPath, flow);
- } else {
- itemLifecycleListener.onAdded(flowPath, flow);
- }
- }
}
@Override
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
import java.util.concurrent.Future;
-import javax.annotation.Nullable;
import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack;
-import org.opendaylight.openflowplugin.api.openflow.rpc.ItemLifeCycleSource;
-import org.opendaylight.openflowplugin.api.openflow.rpc.listener.ItemLifecycleListener;
import org.opendaylight.openflowplugin.impl.services.multilayer.MultiLayerGroupService;
import org.opendaylight.openflowplugin.impl.services.singlelayer.SingleLayerGroupService;
import org.opendaylight.openflowplugin.impl.util.ErrorUtil;
import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.UpdateGroupOutput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.Group;
import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.GroupId;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.groups.GroupBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.groups.GroupKey;
import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-public class SalGroupServiceImpl implements SalGroupService, ItemLifeCycleSource {
+public class SalGroupServiceImpl implements SalGroupService {
private static final Logger LOG = LoggerFactory.getLogger(SalGroupServiceImpl.class);
private final MultiLayerGroupService<AddGroupInput, AddGroupOutput> addGroup;
private final MultiLayerGroupService<Group, UpdateGroupOutput> updateGroup;
private final SingleLayerGroupService<RemoveGroupOutput> removeGroupMessage;
private final DeviceContext deviceContext;
- private ItemLifecycleListener itemLifecycleListener;
public SalGroupServiceImpl(final RequestContextStack requestContextStack,
final DeviceContext deviceContext,
removeGroupMessage = new SingleLayerGroupService<>(requestContextStack, deviceContext, RemoveGroupOutput.class);
}
- @Override
- public void setItemLifecycleListener(@Nullable ItemLifecycleListener itemLifecycleListener) {
- this.itemLifecycleListener = itemLifecycleListener;
- }
-
@Override
public Future<RpcResult<AddGroupOutput>> addGroup(final AddGroupInput input) {
final ListenableFuture<RpcResult<AddGroupOutput>> resultFuture =
LOG.debug("Group add with id={} finished without error", input.getGroupId().getValue());
}
deviceContext.getDeviceGroupRegistry().store(input.getGroupId());
- addIfNecessaryToDS(input.getGroupId(), input);
} else {
if (LOG.isDebugEnabled()) {
LOG.debug("Group add with id={} failed, errors={}", input.getGroupId().getValue(),
LOG.debug("Group update with original id={} finished without error",
input.getOriginalGroup().getGroupId().getValue());
}
- removeIfNecessaryFromDS(input.getOriginalGroup().getGroupId());
- addIfNecessaryToDS(input.getUpdatedGroup().getGroupId(), input.getUpdatedGroup());
} else {
LOG.warn("Group update with original id={} failed, errors={}",
input.getOriginalGroup().getGroupId(), ErrorUtil.errorsToString(result.getErrors()));
LOG.debug("Group remove with id={} finished without error", input.getGroupId().getValue());
}
removeGroup.getDeviceRegistry().getDeviceGroupRegistry().addMark(input.getGroupId());
- removeIfNecessaryFromDS(input.getGroupId());
} else {
LOG.warn("Group remove with id={} failed, errors={}", input.getGroupId().getValue(),
ErrorUtil.errorsToString(result.getErrors()));
return resultFuture;
}
- private void removeIfNecessaryFromDS(final GroupId groupId) {
- if (itemLifecycleListener != null) {
- KeyedInstanceIdentifier<org.opendaylight.yang.gen.v1.urn
- .opendaylight.group.types.rev131018.groups.Group, GroupKey> groupPath
- = createGroupPath(groupId,
- deviceContext.getDeviceInfo().getNodeInstanceIdentifier());
- itemLifecycleListener.onRemoved(groupPath);
- }
- }
-
- private void addIfNecessaryToDS(final GroupId groupId, final Group data) {
- if (itemLifecycleListener != null) {
- KeyedInstanceIdentifier<org.opendaylight.yang.gen.v1.urn
- .opendaylight.group.types.rev131018.groups.Group, GroupKey> groupPath
- = createGroupPath(groupId,
- deviceContext.getDeviceInfo().getNodeInstanceIdentifier());
- itemLifecycleListener.onAdded(groupPath, new GroupBuilder(data).build());
- }
- }
-
private static KeyedInstanceIdentifier<org.opendaylight.yang.gen.v1.urn
.opendaylight.group.types.rev131018.groups.Group, GroupKey>
createGroupPath(final GroupId groupId, final KeyedInstanceIdentifier<Node, NodeKey> nodePath) {
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
import java.util.concurrent.Future;
-import javax.annotation.Nullable;
import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack;
-import org.opendaylight.openflowplugin.api.openflow.rpc.ItemLifeCycleSource;
-import org.opendaylight.openflowplugin.api.openflow.rpc.listener.ItemLifecycleListener;
import org.opendaylight.openflowplugin.impl.services.multilayer.MultiLayerMeterService;
import org.opendaylight.openflowplugin.impl.services.singlelayer.SingleLayerMeterService;
import org.opendaylight.openflowplugin.impl.util.ErrorUtil;
import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorExecutor;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.meters.MeterBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.meters.MeterKey;
import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-public class SalMeterServiceImpl implements SalMeterService, ItemLifeCycleSource {
+public class SalMeterServiceImpl implements SalMeterService {
private static final Logger LOG = LoggerFactory.getLogger(SalMeterServiceImpl.class);
private final MultiLayerMeterService<AddMeterInput, AddMeterOutput> addMeter;
private final MultiLayerMeterService<Meter, UpdateMeterOutput> updateMeter;
private final SingleLayerMeterService<UpdateMeterOutput> updateMeterMessage;
private final SingleLayerMeterService<RemoveMeterOutput> removeMeterMessage;
- private ItemLifecycleListener itemLifecycleListener;
private final DeviceContext deviceContext;
public SalMeterServiceImpl(final RequestContextStack requestContextStack,
removeMeterMessage = new SingleLayerMeterService<>(requestContextStack, deviceContext, RemoveMeterOutput.class);
}
- @Override
- public void setItemLifecycleListener(@Nullable ItemLifecycleListener itemLifecycleListener) {
- this.itemLifecycleListener = itemLifecycleListener;
- }
-
@Override
public Future<RpcResult<AddMeterOutput>> addMeter(final AddMeterInput input) {
final ListenableFuture<RpcResult<AddMeterOutput>> resultFuture =
LOG.debug("Meter add with id={} finished without error", input.getMeterId());
}
deviceContext.getDeviceMeterRegistry().store(input.getMeterId());
- addIfNecessaryToDS(input.getMeterId(),input);
} else {
if (LOG.isDebugEnabled()) {
LOG.debug("Meter add with id={} failed, errors={}", input.getMeterId(),
LOG.debug("Meter update with id={} finished without error",
input.getOriginalMeter().getMeterId());
}
- if (itemLifecycleListener != null) {
- removeIfNecessaryFromDS(input.getOriginalMeter().getMeterId());
- addIfNecessaryToDS(input.getUpdatedMeter().getMeterId(),input.getUpdatedMeter());
- }
} else {
LOG.warn("Meter update with id={} failed, errors={}", input.getOriginalMeter().getMeterId(),
ErrorUtil.errorsToString(result.getErrors()));
LOG.debug("Meter remove with id={} finished without error", input.getMeterId());
}
removeMeter.getDeviceRegistry().getDeviceMeterRegistry().addMark(input.getMeterId());
- removeIfNecessaryFromDS(input.getMeterId());
} else {
LOG.warn("Meter remove with id={} failed, errors={}", input.getMeterId(),
ErrorUtil.errorsToString(result.getErrors()));
return resultFuture;
}
- private void removeIfNecessaryFromDS(final MeterId meterId) {
- if (itemLifecycleListener != null) {
- KeyedInstanceIdentifier<org.opendaylight.yang.gen.v1.urn
- .opendaylight.flow.inventory.rev130819.meters.Meter, MeterKey> meterPath
- = createMeterPath(meterId, deviceContext.getDeviceInfo().getNodeInstanceIdentifier());
- itemLifecycleListener.onRemoved(meterPath);
- }
- }
-
- private void addIfNecessaryToDS(final MeterId meterId, final Meter data) {
- if (itemLifecycleListener != null) {
- KeyedInstanceIdentifier<org.opendaylight.yang.gen.v1.urn
- .opendaylight.flow.inventory.rev130819.meters.Meter, MeterKey> groupPath
- = createMeterPath(meterId, deviceContext.getDeviceInfo().getNodeInstanceIdentifier());
- itemLifecycleListener.onAdded(groupPath, new MeterBuilder(data).build());
- }
- }
-
private static KeyedInstanceIdentifier<org.opendaylight.yang.gen.v1.urn
.opendaylight.flow.inventory.rev130819.meters.Meter, MeterKey> createMeterPath(
final MeterId meterId,
import org.opendaylight.openflowplugin.api.openflow.device.RequestContext;
import org.opendaylight.openflowplugin.api.openflow.lifecycle.ContextChainMastershipState;
import org.opendaylight.openflowplugin.api.openflow.lifecycle.ContextChainMastershipWatcher;
-import org.opendaylight.openflowplugin.api.openflow.rpc.listener.ItemLifecycleListener;
import org.opendaylight.openflowplugin.api.openflow.statistics.StatisticsContext;
import org.opendaylight.openflowplugin.impl.datastore.MultipartWriterProvider;
import org.opendaylight.openflowplugin.impl.rpc.AbstractRequestContext;
-import org.opendaylight.openflowplugin.impl.rpc.listener.ItemLifecycleListenerImpl;
import org.opendaylight.openflowplugin.impl.services.util.RequestContextUtil;
import org.opendaylight.openflowplugin.impl.statistics.services.dedicated.StatisticsGatheringOnTheFlyService;
import org.opendaylight.openflowplugin.impl.statistics.services.dedicated.StatisticsGatheringService;
private static final Logger LOG = LoggerFactory.getLogger(StatisticsContextImpl.class);
private static final String CONNECTION_CLOSED = "Connection closed.";
- private final ItemLifecycleListener itemLifeCycleListener;
private final Collection<RequestContext<?>> requestContexts = new HashSet<>();
private final DeviceContext deviceContext;
private final DeviceState devState;
this.executorService = executorService;
this.isStatisticsPollingOn = isStatisticsPollingOn;
this.convertorExecutor = convertorExecutor;
- this.itemLifeCycleListener = new ItemLifecycleListenerImpl(deviceContext);
this.deviceInfo = deviceContext.getDeviceInfo();
this.statisticsPollingInterval = statisticsPollingInterval;
this.maximumPollingDelay = maximumPollingDelay;
@Override
public void enableGathering() {
this.schedulingEnabled.set(true);
- deviceContext.getItemLifeCycleSourceRegistry()
- .getLifeCycleSources().forEach(itemLifeCycleSource -> itemLifeCycleSource
- .setItemLifecycleListener(null));
}
@Override
public void disableGathering() {
this.schedulingEnabled.set(false);
- deviceContext.getItemLifeCycleSourceRegistry()
- .getLifeCycleSources().forEach(itemLifeCycleSource -> itemLifeCycleSource
- .setItemLifecycleListener(itemLifeCycleListener));
}
@Override
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.ItemLifeCycleSource;
-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;
final FlowDescriptor flowDescriptor = FlowDescriptorFactory.create((short) 0, new FlowId("ut-ofp:f456"));
deviceContext.getDeviceFlowRegistry().storeDescriptor(flowRegKey, flowDescriptor);
- // plug in lifecycleListener
- final ItemLifecycleListener itemLifecycleListener = Mockito.mock(ItemLifecycleListener.class);
- for (final ItemLifeCycleSource lifeCycleSource : deviceContext.getItemLifeCycleSourceRegistry()
- .getLifeCycleSources()) {
- lifeCycleSource.setItemLifecycleListener(itemLifecycleListener);
- }
-
// prepare empty input message
final FlowRemovedMessageBuilder flowRemovedBld = new FlowRemovedMessageBuilder();
deviceContext.setNotificationPublishService(mockedNotificationPublishService);
deviceContext.processFlowRemovedMessage(flowRemovedBld.build());
-
- Mockito.verify(itemLifecycleListener).onRemoved(flowToBeRemovedPath);
}
@Test
+++ /dev/null
-/**
- * Copyright (c) 2015 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.impl.rpc;
-
-import static org.mockito.Matchers.eq;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.verifyNoMoreInteractions;
-
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.Mock;
-import org.mockito.runners.MockitoJUnitRunner;
-import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
-import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
-import org.opendaylight.openflowplugin.api.openflow.rpc.listener.ItemLifecycleListener;
-import org.opendaylight.openflowplugin.impl.rpc.listener.ItemLifecycleListenerImpl;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
-import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
-
-@RunWith(MockitoJUnitRunner.class)
-public class ItemLifecycleListenerImplTest {
-
- @Mock
- private DeviceContext deviceContext;
-
- @Mock
- private Node node;
-
- private KeyedInstanceIdentifier<Node, NodeKey> nodeInstanceIdentifier;
- private ItemLifecycleListener itemLifecycleListener;
-
-
- @Before
- public void setUp() {
- final NodeId nodeId = new NodeId("openflow:1");
- nodeInstanceIdentifier = InstanceIdentifier.create(Nodes.class).child(Node.class, new NodeKey(nodeId));
- itemLifecycleListener = new ItemLifecycleListenerImpl(deviceContext);
- }
-
- @After
- public void tearDown() {
- verifyNoMoreInteractions(deviceContext);
- }
-
- @Test
- public void testOnAdded() throws Exception {
- itemLifecycleListener.onAdded(nodeInstanceIdentifier, node);
- verify(deviceContext)
- .writeToTransaction(eq(LogicalDatastoreType.OPERATIONAL), eq(nodeInstanceIdentifier), eq(node));
- verify(deviceContext).submitTransaction();
- }
-
- @Test
- public void testOnRemoved() throws Exception {
- itemLifecycleListener.onRemoved(nodeInstanceIdentifier);
- verify(deviceContext).addDeleteToTxChain(eq(LogicalDatastoreType.OPERATIONAL), eq(nodeInstanceIdentifier));
- verify(deviceContext).submitTransaction();
- }
-}
import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
import org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo;
import org.opendaylight.openflowplugin.api.openflow.device.DeviceState;
-import org.opendaylight.openflowplugin.api.openflow.registry.ItemLifeCycleRegistry;
import org.opendaylight.openflowplugin.api.openflow.rpc.RpcContext;
import org.opendaylight.openflowplugin.api.openflow.statistics.ofpspecific.MessageSpy;
import org.opendaylight.openflowplugin.extension.api.core.extension.ExtensionConverterProvider;
@Mock
private ConnectionContext connectionContext;
@Mock
- private ItemLifeCycleRegistry itemLifeCycleRegistry;
- @Mock
private MessageSpy messageSpy;
@Mock
private RpcContext removedContexts;
Mockito.when(deviceInfo.getNodeId()).thenReturn(nodeKey.getId());
Mockito.when(deviceInfo.getNodeInstanceIdentifier()).thenReturn(nodePath);
Mockito.when(connectionContext.getFeatures()).thenReturn(features);
- Mockito.when(deviceContext.getItemLifeCycleSourceRegistry()).thenReturn(itemLifeCycleRegistry);
Mockito.when(deviceContext.getPrimaryConnectionContext()).thenReturn(connectionContext);
Mockito.when(deviceContext.getDeviceState()).thenReturn(deviceState);
Mockito.when(deviceContext.getDeviceInfo()).thenReturn(deviceInfo);
package org.opendaylight.openflowplugin.impl.services.sal;
import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.times;
import static org.mockito.Mockito.when;
import com.google.common.util.concurrent.Futures;
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.rpc.listener.ItemLifecycleListener;
import org.opendaylight.openflowplugin.api.openflow.statistics.ofpspecific.MessageSpy;
import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorManager;
import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorManagerFactory;
@Test
public void testAddFlow() throws Exception {
- addFlow(null, OFConstants.OFP_VERSION_1_0);
- addFlow(null, OFConstants.OFP_VERSION_1_3);
+ addFlow(OFConstants.OFP_VERSION_1_0);
+ addFlow(OFConstants.OFP_VERSION_1_3);
}
@Test
@Test
public void testAddFlowWithItemLifecycle() throws Exception {
- addFlow(mock(ItemLifecycleListener.class), OFConstants.OFP_VERSION_1_0);
- addFlow(mock(ItemLifecycleListener.class), OFConstants.OFP_VERSION_1_3);
+ addFlow(OFConstants.OFP_VERSION_1_0);
+ addFlow(OFConstants.OFP_VERSION_1_3);
}
- private void addFlow(final ItemLifecycleListener itemLifecycleListener, short version) throws ExecutionException,
+ private void addFlow(short version) throws ExecutionException,
InterruptedException {
AddFlowInput mockedAddFlowInput = new AddFlowInputBuilder()
.setMatch(match)
.setTableId((short)1)
.build();
SalFlowServiceImpl salFlowService = mockSalFlowService(version);
- salFlowService.setItemLifecycleListener(itemLifecycleListener);
mockingFlowRegistryLookup();
verifyOutput(salFlowService.addFlow(mockedAddFlowInput));
- if (itemLifecycleListener != null) {
- Mockito.verify(itemLifecycleListener)
- .onAdded(Matchers.<KeyedInstanceIdentifier<Flow, FlowKey>>any(), Matchers.<Flow>any());
- }
}
@Test
public void testRemoveFlow() throws Exception {
- removeFlow(null, OFConstants.OFP_VERSION_1_0);
- removeFlow(null, OFConstants.OFP_VERSION_1_3);
+ removeFlow(OFConstants.OFP_VERSION_1_0);
+ removeFlow(OFConstants.OFP_VERSION_1_3);
}
@Test
public void testRemoveFlowWithItemLifecycle() throws Exception {
- removeFlow(mock(ItemLifecycleListener.class), OFConstants.OFP_VERSION_1_0);
- removeFlow(mock(ItemLifecycleListener.class), OFConstants.OFP_VERSION_1_3);
+ removeFlow(OFConstants.OFP_VERSION_1_0);
+ removeFlow(OFConstants.OFP_VERSION_1_3);
}
- private void removeFlow(final ItemLifecycleListener itemLifecycleListener, short version) throws Exception {
+ private void removeFlow(short version) throws Exception {
RemoveFlowInput mockedRemoveFlowInput = new RemoveFlowInputBuilder()
.setMatch(match)
.setTableId((short)1)
.build();
SalFlowServiceImpl salFlowService = mockSalFlowService(version);
- if (itemLifecycleListener != null) {
- salFlowService.setItemLifecycleListener(itemLifecycleListener);
- mockingFlowRegistryLookup();
-
- }
-
verifyOutput(salFlowService.removeFlow(mockedRemoveFlowInput));
- if (itemLifecycleListener != null) {
- Mockito.verify(itemLifecycleListener).onRemoved(Matchers.<KeyedInstanceIdentifier<Flow, FlowKey>>any());
- }
-
}
@Test
public void testUpdateFlow() throws Exception {
- updateFlow(null, OFConstants.OFP_VERSION_1_0);
- updateFlow(null, OFConstants.OFP_VERSION_1_3);
+ updateFlow(OFConstants.OFP_VERSION_1_0);
+ updateFlow(OFConstants.OFP_VERSION_1_3);
}
@Test
public void testUpdateFlowWithItemLifecycle() throws Exception {
- updateFlow(mock(ItemLifecycleListener.class), OFConstants.OFP_VERSION_1_0);
- updateFlow(mock(ItemLifecycleListener.class), OFConstants.OFP_VERSION_1_3);
+ updateFlow(OFConstants.OFP_VERSION_1_0);
+ updateFlow(OFConstants.OFP_VERSION_1_3);
}
- private void updateFlow(final ItemLifecycleListener itemLifecycleListener, short version) throws Exception {
+ private void updateFlow(short version) throws Exception {
UpdateFlowInput mockedUpdateFlowInput = mock(UpdateFlowInput.class);
UpdateFlowInput mockedUpdateFlowInput1 = mock(UpdateFlowInput.class);
when(mockedUpdateFlowInput1.getOriginalFlow()).thenReturn(mockedOriginalFlow1);
SalFlowServiceImpl salFlowService = mockSalFlowService(version);
- if (itemLifecycleListener != null) {
- salFlowService.setItemLifecycleListener(itemLifecycleListener);
- mockingFlowRegistryLookup();
- }
verifyOutput(salFlowService.updateFlow(mockedUpdateFlowInput));
verifyOutput(salFlowService.updateFlow(mockedUpdateFlowInput1));
-
- if (itemLifecycleListener != null) {
- Mockito.verify(itemLifecycleListener, times(2))
- .onUpdated(Matchers.<KeyedInstanceIdentifier<Flow, FlowKey>>any(), Matchers.<Flow>any());
- }
-
}
private void mockingFlowRegistryLookup() {
package org.opendaylight.openflowplugin.impl.services.sal;
import static org.mockito.Matchers.eq;
-import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import org.junit.Test;
-import org.mockito.Matchers;
import org.mockito.Mock;
import org.opendaylight.openflowplugin.api.openflow.registry.group.DeviceGroupRegistry;
-import org.opendaylight.openflowplugin.api.openflow.rpc.listener.ItemLifecycleListener;
import org.opendaylight.openflowplugin.impl.services.ServiceMocking;
import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorManager;
import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorManagerFactory;
import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.group.update.UpdatedGroup;
import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.group.update.UpdatedGroupBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.GroupId;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.groups.Group;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.groups.GroupKey;
-import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
public class SalGroupServiceImplTest extends ServiceMocking {
@Test
public void testAddGroup() throws Exception {
- addGroup(null);
+ addGroup();
}
@Test
public void testAddGroupWithItemLifecycle() throws Exception {
- addGroup(mock(ItemLifecycleListener.class));
+ addGroup();
}
- private void addGroup(final ItemLifecycleListener itemLifecycleListener) {
+ private void addGroup() {
final GroupId dummyGroupId = new GroupId(DUMMY_GROUP_ID);
AddGroupInput addGroupInput = new AddGroupInputBuilder().setGroupId(dummyGroupId).build();
this.<AddGroupOutput>mockSuccessfulFuture();
- salGroupService.setItemLifecycleListener(itemLifecycleListener);
-
salGroupService.addGroup(addGroupInput);
verify(mockedRequestContextStack).createRequestContext();
verify(mockedDeviceGroupRegistry).store(eq(dummyGroupId));
-
- if (itemLifecycleListener != null) {
- verify(itemLifecycleListener)
- .onAdded(Matchers.<KeyedInstanceIdentifier<Group, GroupKey>>any(),Matchers.<Group>any());
- }
}
@Test
public void testUpdateGroup() throws Exception {
- updateGroup(null);
+ updateGroup();
}
@Test
public void testUpdateGroupWithItemLifecycle() throws Exception {
- updateGroup(mock(ItemLifecycleListener.class));
+ updateGroup();
}
- private void updateGroup(final ItemLifecycleListener itemLifecycleListener) {
+ private void updateGroup() {
final UpdatedGroup updatedGroup = new UpdatedGroupBuilder().setGroupId(new GroupId(DUMMY_GROUP_ID)).build();
final OriginalGroup originalGroup = new OriginalGroupBuilder().setGroupId(new GroupId(DUMMY_GROUP_ID)).build();
final UpdateGroupInput updateGroupInput =
new UpdateGroupInputBuilder().setUpdatedGroup(updatedGroup).setOriginalGroup(originalGroup).build();
this.<UpdateGroupOutput>mockSuccessfulFuture();
-
- salGroupService.setItemLifecycleListener(itemLifecycleListener);
-
salGroupService.updateGroup(updateGroupInput);
verify(mockedRequestContextStack).createRequestContext();
-
- if (itemLifecycleListener != null) {
- verify(itemLifecycleListener)
- .onAdded(Matchers.<KeyedInstanceIdentifier<Group, GroupKey>>any(),Matchers.<Group>any());
- verify(itemLifecycleListener).onRemoved(Matchers.<KeyedInstanceIdentifier<Group, GroupKey>>any());
- }
}
@Test
public void testRemoveGroup() throws Exception {
- removeGroup(null);
+ removeGroup();
}
@Test
public void testRemoveGroupWithItemLifecycle() throws Exception {
- removeGroup(mock(ItemLifecycleListener.class));
+ removeGroup();
}
- private void removeGroup(final ItemLifecycleListener itemLifecycleListener) throws Exception {
+ private void removeGroup() throws Exception {
final GroupId dummyGroupId = new GroupId(DUMMY_GROUP_ID);
RemoveGroupInput removeGroupInput = new RemoveGroupInputBuilder().setGroupId(dummyGroupId).build();
this.<RemoveGroupOutput>mockSuccessfulFuture();
- salGroupService.setItemLifecycleListener(itemLifecycleListener);
-
salGroupService.removeGroup(removeGroupInput);
verify(mockedRequestContextStack).createRequestContext();
verify(mockedDeviceGroupRegistry).addMark(eq(dummyGroupId));
-
- if (itemLifecycleListener != null) {
- verify(itemLifecycleListener).onRemoved(Matchers.<KeyedInstanceIdentifier<Group, GroupKey>>any());
- }
}
}
package org.opendaylight.openflowplugin.impl.services.sal;
import static org.mockito.Matchers.eq;
-import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import org.junit.Test;
-import org.mockito.Matchers;
import org.mockito.Mock;
import org.opendaylight.openflowplugin.api.openflow.registry.meter.DeviceMeterRegistry;
-import org.opendaylight.openflowplugin.api.openflow.rpc.listener.ItemLifecycleListener;
import org.opendaylight.openflowplugin.impl.services.ServiceMocking;
import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorManager;
import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorManagerFactory;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.meters.Meter;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.meters.MeterKey;
import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.AddMeterInput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.AddMeterInputBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.AddMeterOutput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.meter.update.UpdatedMeter;
import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.meter.update.UpdatedMeterBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.MeterId;
-import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
public class SalMeterServiceImplTest extends ServiceMocking {
@Test
public void testAddMeter() throws Exception {
- addMeter(null);
+ addMeter();
}
@Test
public void testAddMeterWithItemLifecycle() throws Exception {
- addMeter(mock(ItemLifecycleListener.class));
+ addMeter();
}
- private void addMeter(final ItemLifecycleListener itemLifecycleListener) {
+ private void addMeter() {
final MeterId dummyMeterId = new MeterId(DUMMY_METER_ID);
AddMeterInput addMeterInput = new AddMeterInputBuilder().setMeterId(dummyMeterId).build();
this.<AddMeterOutput>mockSuccessfulFuture();
- salMeterService.setItemLifecycleListener(itemLifecycleListener);
-
salMeterService.addMeter(addMeterInput);
verify(mockedRequestContextStack).createRequestContext();
verify(mockedDeviceMeterRegistry).store(eq(dummyMeterId));
-
- if (itemLifecycleListener != null) {
- verify(itemLifecycleListener)
- .onAdded(Matchers.<KeyedInstanceIdentifier<Meter, MeterKey>>any(),Matchers.<Meter>any());
- }
}
@Test
public void testUpdateMeter() throws Exception {
- updateMeter(null);
+ updateMeter();
}
@Test
public void testUpdateMeterWithItemLifecycle() throws Exception {
- updateMeter(mock(ItemLifecycleListener.class));
+ updateMeter();
}
- private void updateMeter(final ItemLifecycleListener itemLifecycleListener) throws Exception {
+ private void updateMeter() throws Exception {
final UpdatedMeter dummyUpdatedMeter =
new UpdatedMeterBuilder().setMeterId(new MeterId(DUMMY_METTER_ID)).build();
final OriginalMeter dummyOriginalMeter =
this.<AddMeterOutput>mockSuccessfulFuture();
- salMeterService.setItemLifecycleListener(itemLifecycleListener);
-
salMeterService.updateMeter(updateMeterInput);
verify(mockedRequestContextStack).createRequestContext();
-
- if (itemLifecycleListener != null) {
- verify(itemLifecycleListener)
- .onAdded(Matchers.<KeyedInstanceIdentifier<Meter, MeterKey>>any(),Matchers.<Meter>any());
- verify(itemLifecycleListener).onRemoved(Matchers.<KeyedInstanceIdentifier<Meter, MeterKey>>any());
- }
}
@Test
public void testRemoveMeter() throws Exception {
- removeMeter(null);
+ removeMeter();
}
@Test
public void testRemoveMeterWithItemLifecycle() throws Exception {
- removeMeter(mock(ItemLifecycleListener.class));
+ removeMeter();
}
- private void removeMeter(final ItemLifecycleListener itemLifecycleListener) throws Exception {
+ private void removeMeter() throws Exception {
final MeterId dummyMeterId = new MeterId(DUMMY_METER_ID);
RemoveMeterInput removeMeterInput = new RemoveMeterInputBuilder().setMeterId(dummyMeterId).build();
this.<RemoveMeterOutput>mockSuccessfulFuture();
- salMeterService.setItemLifecycleListener(itemLifecycleListener);
-
salMeterService.removeMeter(removeMeterInput);
verify(mockedRequestContextStack).createRequestContext();
verify(mockedDeviceMeterRegistry).addMark(eq(dummyMeterId));
-
- if (itemLifecycleListener != null) {
- verify(itemLifecycleListener).onRemoved(Matchers.<KeyedInstanceIdentifier<Meter, MeterKey>>any());
- }
}
}