OPNFLWPLUG-1007 : Future (eventually) failed: addFlow -and- transmitPacket 68/73868/10
authorgobinath <gobinath@ericsson.com>
Tue, 10 Jul 2018 07:43:04 +0000 (13:13 +0530)
committergobinath <gobinath@ericsson.com>
Sun, 29 Jul 2018 17:43:33 +0000 (23:13 +0530)
Change-Id: Iffe2fc437925bfe041614e3887975f8d6bc91131
Signed-off-by: gobinath <gobinath@ericsson.com>
18 files changed:
applications/device-ownership-service/pom.xml [new file with mode: 0644]
applications/device-ownership-service/src/main/java/org/opendaylight/openflowplugin/applications/deviceownershipservice/DeviceOwnershipService.java [new file with mode: 0644]
applications/device-ownership-service/src/main/java/org/opendaylight/openflowplugin/applications/deviceownershipservice/impl/DeviceOwnershipServiceImpl.java [moved from applications/lldp-speaker/src/main/java/org/opendaylight/openflowplugin/applications/lldpspeaker/DeviceOwnershipStatusService.java with 83% similarity]
applications/device-ownership-service/src/main/resources/org/opendaylight/blueprint/device-ownership-state-service.xml [new file with mode: 0644]
applications/lldp-speaker/pom.xml
applications/lldp-speaker/src/main/java/org/opendaylight/openflowplugin/applications/lldpspeaker/LLDPSpeaker.java
applications/lldp-speaker/src/main/resources/org/opendaylight/blueprint/lldp-speaker.xml
applications/lldp-speaker/src/test/java/org/opendaylight/openflowplugin/applications/lldpspeaker/LLDPSpeakerTest.java
applications/of-switch-config-pusher/pom.xml
applications/of-switch-config-pusher/src/main/java/org/opendaylight/openflowplugin/openflow/ofswitch/config/DefaultConfigPusher.java
applications/of-switch-config-pusher/src/main/resources/org/opendaylight/blueprint/of-switch-config-pusher.xml
applications/of-switch-config-pusher/src/test/java/org/opendaylight/openflowplugin/openflow/ofswitch/config/DefaultConfigPusherTest.java
applications/pom.xml
applications/table-miss-enforcer/pom.xml
applications/table-miss-enforcer/src/main/java/org/opendaylight/openflowplugin/applications/tablemissenforcer/LLDPPacketPuntEnforcer.java
applications/table-miss-enforcer/src/main/resources/org/opendaylight/blueprint/table-miss-enforcer.xml
applications/table-miss-enforcer/src/test/java/org/opendaylight/openflowplugin/applications/tablemissenforcer/LLDPDataTreeChangeListenerTest.java
artifacts/pom.xml

diff --git a/applications/device-ownership-service/pom.xml b/applications/device-ownership-service/pom.xml
new file mode 100644 (file)
index 0000000..3382c9c
--- /dev/null
@@ -0,0 +1,22 @@
+<?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
diff --git a/applications/device-ownership-service/src/main/java/org/opendaylight/openflowplugin/applications/deviceownershipservice/DeviceOwnershipService.java b/applications/device-ownership-service/src/main/java/org/opendaylight/openflowplugin/applications/deviceownershipservice/DeviceOwnershipService.java
new file mode 100644 (file)
index 0000000..fa62d99
--- /dev/null
@@ -0,0 +1,18 @@
+/*
+ * 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
@@ -5,12 +5,10 @@
  * 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;
@@ -18,26 +16,37 @@ import org.opendaylight.mdsal.eos.binding.api.EntityOwnershipChange;
 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();
@@ -49,16 +58,6 @@ public class DeviceOwnershipStatusService implements EntityOwnershipListener {
         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) {
@@ -72,6 +71,7 @@ public class DeviceOwnershipStatusService implements EntityOwnershipListener {
             } 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);
             }
         }
@@ -80,9 +80,8 @@ public class DeviceOwnershipStatusService implements EntityOwnershipListener {
     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();
diff --git a/applications/device-ownership-service/src/main/resources/org/opendaylight/blueprint/device-ownership-state-service.xml b/applications/device-ownership-service/src/main/resources/org/opendaylight/blueprint/device-ownership-state-service.xml
new file mode 100644 (file)
index 0000000..45bd17f
--- /dev/null
@@ -0,0 +1,18 @@
+<?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>
index 6f27c584ee757e98797428d8e038cb281f654bcf..30250cd122927cf797e12d76ee2dcbe73e8cf36c 100644 (file)
             <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>
index d27b137d3d40e5a2cb8cc644d0a08b2e2eccbf90..7d8fc78fa31e8fe06e6ce1a6ff0bf756eb4c51c6 100644 (file)
@@ -11,7 +11,6 @@ package org.opendaylight.openflowplugin.applications.lldpspeaker;
 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;
@@ -22,7 +21,7 @@ import java.util.concurrent.ThreadFactory;
 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;
@@ -55,7 +54,7 @@ public class LLDPSpeaker implements NodeConnectorEventsObserver, Runnable, AutoC
             .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;
@@ -64,18 +63,18 @@ public class LLDPSpeaker implements NodeConnectorEventsObserver, Runnable, AutoC
     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;
@@ -127,18 +126,16 @@ public class LLDPSpeaker implements NodeConnectorEventsObserver, Runnable, AutoC
     @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());
                 }
             });
@@ -158,10 +155,14 @@ public class LLDPSpeaker implements NodeConnectorEventsObserver, Runnable, AutoC
                     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();
 
@@ -205,7 +206,7 @@ public class LLDPSpeaker implements NodeConnectorEventsObserver, Runnable, AutoC
         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();
             }
         });
index 4290e3dcd00166ab7c6feae4ae3f14729c4f66f0..783d4b8943f21eb7964bbd78ce0eb1dc97ee69ea 100644 (file)
@@ -4,7 +4,7 @@
            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">
@@ -24,7 +24,7 @@
     <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"
index a3ebd12ec5574b6ad5d9f2c300505644f593940e..8adf0f54a7699df754f9b039817fe4c9c56e2253 100644 (file)
@@ -17,7 +17,6 @@ import static org.mockito.Mockito.verify;
 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;
@@ -27,8 +26,7 @@ import org.junit.Test;
 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;
@@ -65,7 +63,7 @@ public class LLDPSpeakerTest {
     @Mock
     private ScheduledFuture scheduledSpeakerTask;
     @Mock
-    private EntityOwnershipService entityOwnershipService;
+    private DeviceOwnershipService deviceOwnershipService;
 
     private LLDPSpeaker lldpSpeaker;
 
@@ -79,8 +77,8 @@ public class LLDPSpeakerTest {
         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());
@@ -116,8 +114,7 @@ public class LLDPSpeakerTest {
         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();
index cc740887ae434dcdc1a29233450ce6b636185624..8e3b39ac058200a345af37c79788c3da6f8b4917 100644 (file)
             <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>
index 72af57e34e0eb25f3d6137b7d09bd6129403d06e..08331f135a5452b89df23f8290c69202eb9e0783 100644 (file)
@@ -8,22 +8,25 @@
 
 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;
@@ -34,17 +37,21 @@ import org.opendaylight.yangtools.yang.common.RpcResult;
 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")
@@ -75,14 +82,20 @@ public class DefaultConfigPusher implements AutoCloseable, DataTreeChangeListene
     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);
+                }
             }
         }
     }
index 93a7f599853bea9a3118bd2a6bfd055329c963d8..f303c62da2ea3e37ba47bb7c62fe9b3cd660056f 100644 (file)
@@ -4,6 +4,7 @@
            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"/>
 
@@ -11,5 +12,6 @@
           init-method="start" destroy-method="close">
     <argument ref="nodeConfigService"/>
     <argument ref="dataBroker"/>
+    <argument ref="deviceOwnershipService"/>
   </bean>
 </blueprint>
\ No newline at end of file
index d2ed20f1ae343741a7f3e3d3cf7a71d6a202a1a9..8b746ed3539c1920e38c1a5f765e4e9616f33c89 100644 (file)
@@ -10,6 +10,7 @@ package org.opendaylight.openflowplugin.openflow.ofswitch.config;
 
 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;
@@ -29,6 +30,7 @@ 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.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;
@@ -52,18 +54,22 @@ public class DefaultConfigPusherTest {
     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
index 576b3697a371b10bdee12235a12d53769a0fbbef..c91c41430c2c6a2d90563fde80646cd92b207622 100644 (file)
@@ -45,6 +45,7 @@
         <module>bulk-o-matic</module>
         <module>reconciliation-framework</module>
         <module>southbound-cli</module>
+        <module>device-ownership-service</module>
     </modules>
 
 </project>
index 3949a5951f11e44495915deade6d0a53fdf4a1ce..a9353b78145e91646f01ca5eabc64fba3b763621 100644 (file)
           <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>
index ffa6baf02a8b1a411a3d8b1468ca7b74105ee3e6..74e264a104926c36a064ad1285212373c6925e05 100644 (file)
@@ -8,6 +8,7 @@
 
 package org.opendaylight.openflowplugin.applications.tablemissenforcer;
 
+import com.google.common.base.Preconditions;
 import java.math.BigInteger;
 import java.util.ArrayList;
 import java.util.Collection;
@@ -22,6 +23,7 @@ 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.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Uri;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.OutputActionCaseBuilder;
@@ -50,6 +52,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instru
 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;
@@ -65,11 +68,15 @@ public class LLDPPacketPuntEnforcer implements AutoCloseable, ClusteredDataTreeC
     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")
@@ -98,11 +105,20 @@ public class LLDPPacketPuntEnforcer implements AutoCloseable, ClusteredDataTreeC
     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);
+                }
+
             }
         }
     }
index bbba85a5aab7e0f1acfc044cb25c801044a24f64..a2d736894f4aef689e38cd512341115876605d6f 100644 (file)
@@ -4,6 +4,7 @@
            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"/>
 
@@ -11,5 +12,6 @@
           init-method="start" destroy-method="close">
     <argument ref="flowService"/>
     <argument ref="dataBroker"/>
+    <argument ref="deviceOwnershipService"/>
   </bean>
 </blueprint>
\ No newline at end of file
index 58f64130073767a2c5e6a29ff50bdbbf7d678d19..aba225f8af169fbd2035aec5d5d4847fef7f40f9 100644 (file)
@@ -12,6 +12,7 @@ import static org.junit.Assert.assertEquals;
 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;
@@ -30,6 +31,7 @@ import org.opendaylight.controller.md.sal.binding.api.DataObjectModification.Mod
 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;
@@ -58,18 +60,22 @@ public class LLDPDataTreeChangeListenerTest {
     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
index 047a8c2de2700a35a29d6ab87b4a4f44e4cf5021..d7df08490eb9e3b28bce6c53b9d03547784d362c 100644 (file)
                 <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>