--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <parent>
+ <artifactId>applications</artifactId>
+ <groupId>org.opendaylight.openflowplugin</groupId>
+ <version>0.7.0-SNAPSHOT</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+
+ <groupId>org.opendaylight.openflowplugin.applications</groupId>
+ <artifactId>device-ownership-service</artifactId>
+ <packaging>bundle</packaging>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.opendaylight.mdsal</groupId>
+ <artifactId>mdsal-eos-binding-api</artifactId>
+ </dependency>
+ </dependencies>
+</project>
\ No newline at end of file
--- /dev/null
+/*
+ * Copyright (c) 2018 Ericsson India Global Services Pvt Ltd. 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.applications.deviceownershipservice;
+
+public interface DeviceOwnershipService {
+ /**
+ * Method is used to check if the node is the entity owner of the switch.
+ * @return true if the node is the owner of the switch ,
+ * false if either the switch is owned by some other node or if the cluster is in Jeopardy
+ */
+ boolean isEntityOwned(String nodeId);
+}
\ No newline at end of file
* 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.applications.lldpspeaker;
+package org.opendaylight.openflowplugin.applications.deviceownershipservice.impl;
import com.google.common.base.Optional;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
-import java.util.ArrayList;
-import java.util.List;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.regex.Pattern;
import org.opendaylight.mdsal.eos.binding.api.EntityOwnershipListener;
import org.opendaylight.mdsal.eos.binding.api.EntityOwnershipService;
import org.opendaylight.mdsal.eos.common.api.EntityOwnershipState;
+import org.opendaylight.openflowplugin.applications.deviceownershipservice.DeviceOwnershipService;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.core.general.entity.rev150930.Entity;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-public class DeviceOwnershipStatusService implements EntityOwnershipListener {
- private static final Logger LOG = LoggerFactory.getLogger(DeviceOwnershipStatusService.class);
+public class DeviceOwnershipServiceImpl implements DeviceOwnershipService, EntityOwnershipListener {
+ private static final Logger LOG = LoggerFactory.getLogger(DeviceOwnershipService.class);
private static final String SERVICE_ENTITY_TYPE = "org.opendaylight.mdsal.ServiceEntityType";
private static final Pattern NODE_ID_PATTERN = Pattern.compile("^openflow:\\d+");
private final EntityOwnershipService eos;
private final ConcurrentMap<String, EntityOwnershipState> ownershipStateCache = new ConcurrentHashMap<>();
- public DeviceOwnershipStatusService(final EntityOwnershipService entityOwnershipService) {
+ public DeviceOwnershipServiceImpl(final EntityOwnershipService entityOwnershipService) {
this.eos = entityOwnershipService;
+ }
+
+ public void start() {
registerEntityOwnershipListener();
+ LOG.info("DeviceOwnershipService started");
}
+ public void close() {
+ LOG.info("DeviceOwnershipService closed");
+ }
+
+ @Override
public boolean isEntityOwned(final String nodeId) {
EntityOwnershipState state = ownershipStateCache.get(nodeId);
if (state == null) {
+ LOG.debug("The ownership state for node {} is not cached. Retrieving from the EOS Datastore");
java.util.Optional<EntityOwnershipState> status = getCurrentOwnershipStatus(nodeId);
if (status.isPresent()) {
state = status.get();
return state != null && state.equals(EntityOwnershipState.IS_OWNER);
}
- public List<String> getOwnedNodes() {
- List<String> nodes = new ArrayList<>();
- ownershipStateCache.forEach((node, change) -> {
- if (isEntityOwned(node)) {
- nodes.add(node);
- }
- });
- return nodes;
- }
-
@Override
@SuppressFBWarnings("BC_UNCONFIRMED_CAST_OF_RETURN_VALUE")
public void ownershipChanged(final EntityOwnershipChange ownershipChange) {
} else if (!ownershipChange.getState().isOwner() && ownershipChange.getState().hasOwner()) {
ownershipStateCache.put(entityName, EntityOwnershipState.OWNED_BY_OTHER);
} else if (ownershipChange.getState().isOwner()) {
+ LOG.trace("Entity for node : {} is registered", entityName);
ownershipStateCache.put(entityName, EntityOwnershipState.IS_OWNER);
}
}
private java.util.Optional<EntityOwnershipState> getCurrentOwnershipStatus(final String nodeId) {
org.opendaylight.mdsal.eos.binding.api.Entity entity = createNodeEntity(nodeId);
Optional<EntityOwnershipState> ownershipStatus = eos.getOwnershipState(entity);
-
if (ownershipStatus.isPresent()) {
- LOG.debug("Fetched ownership status for node {} is {}", nodeId, ownershipStatus.get());
+ LOG.trace("Fetched ownership status for node {} is {}", nodeId, ownershipStatus.get());
return java.util.Optional.of(ownershipStatus.get());
}
return java.util.Optional.empty();
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
+ xmlns:odl="http://opendaylight.org/xmlns/blueprint/v1.0.0"
+ odl:use-default-for-reference-types="true">
+
+ <reference id="entityOwnershipService" interface="org.opendaylight.mdsal.eos.binding.api.EntityOwnershipService"/>
+
+ <bean id="deviceOwnershipService" class="org.opendaylight.openflowplugin.applications.deviceownershipservice.impl.DeviceOwnershipServiceImpl"
+ init-method="start"
+ destroy-method="close">
+ <argument ref="entityOwnershipService"/>
+ </bean>
+
+ <service ref="deviceOwnershipService"
+ interface="org.opendaylight.openflowplugin.applications.deviceownershipservice.DeviceOwnershipService"
+ odl:type="default"/>
+
+</blueprint>
<groupId>org.opendaylight.openflowplugin.applications</groupId>
<artifactId>topology-lldp-discovery</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.opendaylight.openflowplugin.applications</groupId>
+ <artifactId>device-ownership-service</artifactId>
+ <version>${project.version}</version>
+ </dependency>
<dependency>
<groupId>org.opendaylight.infrautils</groupId>
<artifactId>infrautils-util</artifactId>
import com.google.common.base.Preconditions;
import com.google.common.util.concurrent.ThreadFactoryBuilder;
import java.security.NoSuchAlgorithmException;
-import java.util.Arrays;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import org.opendaylight.infrautils.utils.concurrent.JdkFutures;
-import org.opendaylight.mdsal.eos.binding.api.EntityOwnershipService;
+import org.opendaylight.openflowplugin.applications.deviceownershipservice.DeviceOwnershipService;
import org.opendaylight.openflowplugin.libraries.liblldp.PacketException;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNodeConnector;
.setNameFormat("lldp-speaker-%d").setDaemon(true).build();
private final PacketProcessingService packetProcessingService;
private final ScheduledExecutorService scheduledExecutorService;
- private final DeviceOwnershipStatusService deviceOwnershipStatusService;
+ private final DeviceOwnershipService deviceOwnershipService;
private final Map<InstanceIdentifier<NodeConnector>, TransmitPacketInput> nodeConnectorMap =
new ConcurrentHashMap<>();
private final MacAddress addressDestionation;
private volatile OperStatus operationalStatus = OperStatus.RUN;
public LLDPSpeaker(final PacketProcessingService packetProcessingService, final MacAddress addressDestionation,
- final EntityOwnershipService entityOwnershipService) {
+ final DeviceOwnershipService deviceOwnershipService) {
this(packetProcessingService, Executors.newSingleThreadScheduledExecutor(THREAD_FACTORY), addressDestionation,
- entityOwnershipService);
+ deviceOwnershipService);
}
public LLDPSpeaker(final PacketProcessingService packetProcessingService,
final ScheduledExecutorService scheduledExecutorService,
final MacAddress addressDestionation,
- final EntityOwnershipService entityOwnershipService) {
+ final DeviceOwnershipService deviceOwnershipStatusService) {
this.addressDestionation = addressDestionation;
this.scheduledExecutorService = scheduledExecutorService;
- this.deviceOwnershipStatusService = new DeviceOwnershipStatusService(entityOwnershipService);
+ this.deviceOwnershipService = deviceOwnershipStatusService;
scheduledSpeakerTask = this.scheduledExecutorService
.scheduleAtFixedRate(this, LLDP_FLOOD_PERIOD,LLDP_FLOOD_PERIOD, TimeUnit.SECONDS);
this.packetProcessingService = packetProcessingService;
@Override
public void run() {
if (OperStatus.RUN.equals(operationalStatus)) {
- LOG.debug("Sending LLDP frames to nodes {}", Arrays.toString(deviceOwnershipStatusService
- .getOwnedNodes().toArray()));
LOG.debug("Sending LLDP frames to total {} ports", getOwnedPorts());
nodeConnectorMap.keySet().forEach(ncIID -> {
NodeConnectorId nodeConnectorId = InstanceIdentifier.keyOf(ncIID).getId();
NodeId nodeId = ncIID.firstKeyOf(Node.class, NodeKey.class).getId();
- if (deviceOwnershipStatusService.isEntityOwned(nodeId.getValue())) {
+ if (deviceOwnershipService.isEntityOwned(nodeId.getValue())) {
LOG.debug("Node is owned by this controller, sending LLDP packet through port {}",
nodeConnectorId.getValue());
packetProcessingService.transmitPacket(nodeConnectorMap.get(ncIID));
} else {
- LOG.trace("Node {} is not owned by this controller, so skip sending LLDP packet on port {}",
+ LOG.debug("Node {} is not owned by this controller, so skip sending LLDP packet on port {}",
nodeId.getValue(), nodeConnectorId.getValue());
}
});
nodeConnectorId.getValue());
return;
}
-
// Prepare to build LLDP payload
InstanceIdentifier<Node> nodeInstanceId = nodeConnectorInstanceId.firstIdentifierOf(Node.class);
NodeId nodeId = InstanceIdentifier.keyOf(nodeInstanceId).getId();
+ if (!deviceOwnershipService.isEntityOwned(nodeId.getValue())) {
+ LOG.debug("Node {} is not owned by this controller, so skip sending LLDP packet on port {}",
+ nodeId.getValue(), nodeConnectorId.getValue());
+ return;
+ }
MacAddress srcMacAddress = flowConnector.getHardwareAddress();
Long outputPortNo = flowConnector.getPortNumber().getUint32();
AtomicInteger ownedPorts = new AtomicInteger();
nodeConnectorMap.keySet().forEach(ncIID -> {
NodeId nodeId = ncIID.firstKeyOf(Node.class, NodeKey.class).getId();
- if (deviceOwnershipStatusService.isEntityOwned(nodeId.getValue())) {
+ if (deviceOwnershipService.isEntityOwned(nodeId.getValue())) {
ownedPorts.incrementAndGet();
}
});
odl:use-default-for-reference-types="true">
<reference id="dataBroker" interface="org.opendaylight.controller.md.sal.binding.api.DataBroker"/>
- <reference id="entityOwnershipService" interface="org.opendaylight.mdsal.eos.binding.api.EntityOwnershipService"/>
+ <reference id="deviceOwnershipService" interface="org.opendaylight.openflowplugin.applications.deviceownershipservice.DeviceOwnershipService"/>
<odl:clustered-app-config id="lldpSpeakerConfig"
binding-class="org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflow.applications.lldp.speaker.config.rev160512.LldpSpeakerConfig">
<argument>
<bean factory-ref="lldpSpeakerConfig" factory-method="getAddressDestination"/>
</argument>
- <argument ref="entityOwnershipService"/>
+ <argument ref="deviceOwnershipService"/>
</bean>
<bean id="nodeConnectorEventTranslator" class="org.opendaylight.openflowplugin.applications.lldpspeaker.NodeConnectorInventoryEventTranslator"
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when;
-import com.google.common.base.Optional;
import java.security.NoSuchAlgorithmException;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
-import org.opendaylight.mdsal.eos.binding.api.EntityOwnershipService;
-import org.opendaylight.mdsal.eos.common.api.EntityOwnershipState;
+import org.opendaylight.openflowplugin.applications.deviceownershipservice.DeviceOwnershipService;
import org.opendaylight.openflowplugin.libraries.liblldp.PacketException;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNodeConnector;
@Mock
private ScheduledFuture scheduledSpeakerTask;
@Mock
- private EntityOwnershipService entityOwnershipService;
+ private DeviceOwnershipService deviceOwnershipService;
private LLDPSpeaker lldpSpeaker;
when(scheduledExecutorService.scheduleAtFixedRate(any(Runnable.class), anyLong(), anyLong(),
any(TimeUnit.class))).thenReturn(scheduledSpeakerTask);
lldpSpeaker = new LLDPSpeaker(packetProcessingService,
- scheduledExecutorService, null, entityOwnershipService);
- when(entityOwnershipService.getOwnershipState(any())).thenReturn(Optional.of(EntityOwnershipState.IS_OWNER));
+ scheduledExecutorService, null, deviceOwnershipService);
+ when(deviceOwnershipService.isEntityOwned(any())).thenReturn(true);
lldpSpeaker.setOperationalStatus(OperStatus.RUN);
doReturn(RpcResultBuilder.success().buildFuture()).when(packetProcessingService).transmitPacket(any());
lldpSpeaker.nodeConnectorAdded(ID, FLOW_CAPABLE_NODE_CONNECTOR);
- when(entityOwnershipService.getOwnershipState(any()))
- .thenReturn(Optional.of(EntityOwnershipState.OWNED_BY_OTHER));
+ when(deviceOwnershipService.isEntityOwned(any())).thenReturn(false);
// Execute one iteration of periodic task - LLDP packet should be
// not transmit second packet because it doesn't own the device.
lldpSpeaker.run();
<groupId>org.opendaylight.openflowplugin</groupId>
<artifactId>openflowplugin-common</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.opendaylight.openflowplugin.applications</groupId>
+ <artifactId>device-ownership-service</artifactId>
+ <version>${project.version}</version>
+ </dependency>
<dependency>
<groupId>org.opendaylight.infrautils</groupId>
<artifactId>infrautils-util</artifactId>
package org.opendaylight.openflowplugin.openflow.ofswitch.config;
+import com.google.common.base.Preconditions;
import java.util.Collection;
import java.util.concurrent.Future;
import javax.annotation.Nonnull;
+import org.opendaylight.controller.md.sal.binding.api.ClusteredDataTreeChangeListener;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
import org.opendaylight.controller.md.sal.binding.api.DataObjectModification.ModificationType;
-import org.opendaylight.controller.md.sal.binding.api.DataTreeChangeListener;
import org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier;
import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
import org.opendaylight.infrautils.utils.concurrent.JdkFutures;
import org.opendaylight.openflowplugin.api.OFConstants;
+import org.opendaylight.openflowplugin.applications.deviceownershipservice.DeviceOwnershipService;
import org.opendaylight.openflowplugin.common.wait.SimpleTaskRetryLooper;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef;
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.yang.gen.v1.urn.opendaylight.module.config.rev141015.NodeConfigService;
import org.opendaylight.yang.gen.v1.urn.opendaylight.module.config.rev141015.SetConfigInputBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.module.config.rev141015.SetConfigOutput;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-public class DefaultConfigPusher implements AutoCloseable, DataTreeChangeListener<FlowCapableNode> {
+public class DefaultConfigPusher implements AutoCloseable, ClusteredDataTreeChangeListener<FlowCapableNode> {
private static final Logger LOG = LoggerFactory.getLogger(DefaultConfigPusher.class);
private static final long STARTUP_LOOP_TICK = 500L;
private static final int STARTUP_LOOP_MAX_RETRIES = 8;
private final NodeConfigService nodeConfigService;
private final DataBroker dataBroker;
+ private final DeviceOwnershipService deviceOwnershipService;
private ListenerRegistration<?> listenerRegistration;
- public DefaultConfigPusher(NodeConfigService nodeConfigService, DataBroker dataBroker) {
+ public DefaultConfigPusher(NodeConfigService nodeConfigService, DataBroker dataBroker,
+ DeviceOwnershipService deviceOwnershipService) {
this.nodeConfigService = nodeConfigService;
this.dataBroker = dataBroker;
+ this.deviceOwnershipService = Preconditions.checkNotNull(deviceOwnershipService,
+ "DeviceOwnershipService can not be null");
}
@SuppressWarnings("checkstyle:IllegalCatch")
public void onDataTreeChanged(@Nonnull final Collection<DataTreeModification<FlowCapableNode>> modifications) {
for (DataTreeModification<FlowCapableNode> modification : modifications) {
if (modification.getRootNode().getModificationType() == ModificationType.WRITE) {
- SetConfigInputBuilder setConfigInputBuilder = new SetConfigInputBuilder();
- setConfigInputBuilder.setFlag(SwitchConfigFlag.FRAGNORMAL.toString());
- setConfigInputBuilder.setMissSearchLength(OFConstants.OFPCML_NO_BUFFER);
- setConfigInputBuilder.setNode(new NodeRef(modification.getRootPath()
- .getRootIdentifier().firstIdentifierOf(Node.class)));
- final Future<RpcResult<SetConfigOutput>> resultFuture =
- nodeConfigService.setConfig(setConfigInputBuilder.build());
- JdkFutures.addErrorLogging(resultFuture, LOG, "addFlow");
+ String nodeId = modification.getRootPath().getRootIdentifier()
+ .firstKeyOf(Node.class, NodeKey.class).getId().getValue();
+ if (deviceOwnershipService.isEntityOwned(nodeId)) {
+ SetConfigInputBuilder setConfigInputBuilder = new SetConfigInputBuilder();
+ setConfigInputBuilder.setFlag(SwitchConfigFlag.FRAGNORMAL.toString());
+ setConfigInputBuilder.setMissSearchLength(OFConstants.OFPCML_NO_BUFFER);
+ setConfigInputBuilder.setNode(new NodeRef(modification.getRootPath()
+ .getRootIdentifier().firstIdentifierOf(Node.class)));
+ final Future<RpcResult<SetConfigOutput>> resultFuture =
+ nodeConfigService.setConfig(setConfigInputBuilder.build());
+ JdkFutures.addErrorLogging(resultFuture, LOG, "addFlow");
+ } else {
+ LOG.debug("Node {} is not owned by this controller, so skip setting config", nodeId);
+ }
}
}
}
odl:use-default-for-reference-types="true">
<reference id="dataBroker" interface="org.opendaylight.controller.md.sal.binding.api.DataBroker"/>
+ <reference id="deviceOwnershipService" interface="org.opendaylight.openflowplugin.applications.deviceownershipservice.DeviceOwnershipService"/>
<odl:rpc-service id="nodeConfigService" interface="org.opendaylight.yang.gen.v1.urn.opendaylight.module.config.rev141015.NodeConfigService"/>
init-method="start" destroy-method="close">
<argument ref="nodeConfigService"/>
<argument ref="dataBroker"/>
+ <argument ref="deviceOwnershipService"/>
</bean>
</blueprint>
\ No newline at end of file
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.when;
import java.util.Collections;
import org.junit.After;
import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
import org.opendaylight.openflowplugin.api.OFConstants;
+import org.opendaylight.openflowplugin.applications.deviceownershipservice.DeviceOwnershipService;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
private NodeConfigService nodeConfigService;
@Mock
private DataTreeModification<FlowCapableNode> dataTreeModification;
+ @Mock
+ private DeviceOwnershipService deviceOwnershipService;
@Captor
private ArgumentCaptor<SetConfigInput> setConfigInputCaptor;
@Before
public void setUp() throws Exception {
doReturn(RpcResultBuilder.success().buildFuture()).when(nodeConfigService).setConfig(any());
- defaultConfigPusher = new DefaultConfigPusher(nodeConfigService, Mockito.mock(DataBroker.class));
+ defaultConfigPusher = new DefaultConfigPusher(nodeConfigService, Mockito.mock(DataBroker.class),
+ deviceOwnershipService);
final DataTreeIdentifier<FlowCapableNode> identifier =
new DataTreeIdentifier(LogicalDatastoreType.OPERATIONAL, NODE_IID);
Mockito.when(dataTreeModification.getRootPath()).thenReturn(identifier);
Mockito.when(dataTreeModification.getRootNode()).thenReturn(Mockito.mock(DataObjectModification.class));
Mockito.when(dataTreeModification.getRootNode().getModificationType()).thenReturn(ModificationType.WRITE);
+ when(deviceOwnershipService.isEntityOwned(any())).thenReturn(true);
}
@Test
<module>bulk-o-matic</module>
<module>reconciliation-framework</module>
<module>southbound-cli</module>
+ <module>device-ownership-service</module>
</modules>
</project>
<artifactId>infrautils-util</artifactId>
<version>${infrautils.version}</version>
</dependency>
+ <dependency>
+ <groupId>org.opendaylight.openflowplugin.applications</groupId>
+ <artifactId>device-ownership-service</artifactId>
+ <version>${project.version}</version>
+ </dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
package org.opendaylight.openflowplugin.applications.tablemissenforcer;
+import com.google.common.base.Preconditions;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Collection;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
import org.opendaylight.infrautils.utils.concurrent.JdkFutures;
import org.opendaylight.openflowplugin.api.OFConstants;
+import org.opendaylight.openflowplugin.applications.deviceownershipservice.DeviceOwnershipService;
import org.opendaylight.openflowplugin.common.wait.SimpleTaskRetryLooper;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Uri;
import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.OutputActionCaseBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef;
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.concepts.ListenerRegistration;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
import org.opendaylight.yangtools.yang.common.RpcResult;
private static final String DEFAULT_FLOW_ID = "42";
private final SalFlowService flowService;
private final DataBroker dataBroker;
+ private final DeviceOwnershipService deviceOwnershipService;
private ListenerRegistration<?> listenerRegistration;
- public LLDPPacketPuntEnforcer(SalFlowService flowService, DataBroker dataBroker) {
+ public LLDPPacketPuntEnforcer(SalFlowService flowService, DataBroker dataBroker,
+ DeviceOwnershipService deviceOwnershipService) {
this.flowService = flowService;
this.dataBroker = dataBroker;
+ this.deviceOwnershipService = Preconditions.checkNotNull(deviceOwnershipService,
+ "DeviceOwnershipService can not be null");
}
@SuppressWarnings("IllegalCatch")
public void onDataTreeChanged(@Nonnull final Collection<DataTreeModification<FlowCapableNode>> modifications) {
for (DataTreeModification<FlowCapableNode> modification : modifications) {
if (modification.getRootNode().getModificationType() == ModificationType.WRITE) {
- AddFlowInputBuilder addFlowInput = new AddFlowInputBuilder(createFlow());
- addFlowInput.setNode(
- new NodeRef(modification.getRootPath().getRootIdentifier().firstIdentifierOf(Node.class)));
- final Future<RpcResult<AddFlowOutput>> resultFuture = this.flowService.addFlow(addFlowInput.build());
- JdkFutures.addErrorLogging(resultFuture, LOG, "addFlow");
+ String nodeId = modification.getRootPath().getRootIdentifier()
+ .firstKeyOf(Node.class, NodeKey.class).getId().getValue();
+ if (deviceOwnershipService.isEntityOwned(nodeId)) {
+ AddFlowInputBuilder addFlowInput = new AddFlowInputBuilder(createFlow());
+ addFlowInput.setNode(new NodeRef(modification.getRootPath()
+ .getRootIdentifier().firstIdentifierOf(Node.class)));
+ final Future<RpcResult<AddFlowOutput>> resultFuture = this.flowService
+ .addFlow(addFlowInput.build());
+ JdkFutures.addErrorLogging(resultFuture, LOG, "addFlow");
+ } else {
+ LOG.debug("Node {} is not owned by this controller, so skip adding LLDP table miss flow",
+ nodeId);
+ }
+
}
}
}
odl:use-default-for-reference-types="true">
<reference id="dataBroker" interface="org.opendaylight.controller.md.sal.binding.api.DataBroker"/>
+ <reference id="deviceOwnershipService" interface="org.opendaylight.openflowplugin.applications.deviceownershipservice.DeviceOwnershipService"/>
<odl:rpc-service id="flowService" interface="org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.SalFlowService"/>
init-method="start" destroy-method="close">
<argument ref="flowService"/>
<argument ref="dataBroker"/>
+ <argument ref="deviceOwnershipService"/>
</bean>
</blueprint>
\ No newline at end of file
import static org.junit.Assert.assertNotNull;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.when;
import java.util.Collections;
import org.junit.After;
import org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier;
import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.openflowplugin.applications.deviceownershipservice.DeviceOwnershipService;
import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.OutputActionCase;
import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
private SalFlowService flowService;
@Mock
private DataTreeModification<FlowCapableNode> dataTreeModification;
+ @Mock
+ private DeviceOwnershipService deviceOwnershipService;
@Captor
private ArgumentCaptor<AddFlowInput> addFlowInputCaptor;
@Before
public void setUp() {
doReturn(RpcResultBuilder.success().buildFuture()).when(flowService).addFlow(any());
- lldpPacketPuntEnforcer = new LLDPPacketPuntEnforcer(flowService, Mockito.mock(DataBroker.class));
+ lldpPacketPuntEnforcer = new LLDPPacketPuntEnforcer(flowService, Mockito.mock(DataBroker.class),
+ deviceOwnershipService);
final DataTreeIdentifier<FlowCapableNode> identifier = new DataTreeIdentifier(LogicalDatastoreType.OPERATIONAL,
NODE_IID);
Mockito.when(dataTreeModification.getRootPath()).thenReturn(identifier);
Mockito.when(dataTreeModification.getRootNode()).thenReturn(Mockito.mock(DataObjectModification.class));
Mockito.when(dataTreeModification.getRootNode().getModificationType()).thenReturn(ModificationType.WRITE);
+ when(deviceOwnershipService.isEntityOwned(any())).thenReturn(true);
}
@Test
<artifactId>notification-supplier</artifactId>
<version>${project.version}</version>
</dependency>
+ <dependency>
+ <groupId>${project.groupId}.applications</groupId>
+ <artifactId>device-ownership-status-service</artifactId>
+ <version>${project.version}</version>
+ </dependency>
<!-- config files -->
<dependency>
<groupId>${project.groupId}</groupId>