auto add DPNs
diff --git a/apps/fpcagent/BUCK b/apps/fpcagent/BUCK
index 5ab31d7..ac20966 100644
--- a/apps/fpcagent/BUCK
+++ b/apps/fpcagent/BUCK
@@ -13,6 +13,7 @@
     '//apps/restconf/api:onos-apps-restconf-api',
     '//models/fpcagent:onos-models-fpcagent',
     '//models/common:onos-models-common',
+    '//lib:javax.ws.rs-api',
     ':jetty-servlet-custom',
     ':jetty-server-custom',
     ':jetty-io-custom',
diff --git a/apps/fpcagent/src/main/java/org/onosproject/fpcagent/FpcManager.java b/apps/fpcagent/src/main/java/org/onosproject/fpcagent/FpcManager.java
index f576930..ac82649 100644
--- a/apps/fpcagent/src/main/java/org/onosproject/fpcagent/FpcManager.java
+++ b/apps/fpcagent/src/main/java/org/onosproject/fpcagent/FpcManager.java
@@ -31,8 +31,8 @@
 import org.onosproject.core.IdGenerator;
 import org.onosproject.fpcagent.protocols.DpnNgicCommunicator;
 import org.onosproject.fpcagent.protocols.DpnP4Communicator;
-import org.onosproject.fpcagent.providers.ZmqDpnDeviceListener;
-import org.onosproject.fpcagent.providers.ZmqDpnProviderService;
+import org.onosproject.fpcagent.providers.NgicDpnDeviceListener;
+import org.onosproject.fpcagent.providers.NgicDpnProviderService;
 import org.onosproject.fpcagent.util.ConfigHelper;
 import org.onosproject.fpcagent.util.eventstream.JettyServer;
 import org.onosproject.fpcagent.util.eventstream.NbEventWorkerManager;
@@ -96,7 +96,7 @@
     private CoreService coreService;
 
     @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
-    private ZmqDpnProviderService zmqDpnProviderService;
+    private NgicDpnProviderService ngicDpnProviderService;
 
     @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
     private RestconfService restconfService;
@@ -108,7 +108,7 @@
     private IdGenerator notificationIds;
     private FpcConfig fpcConfig;
     private boolean started = false;
-    private HashSet<ZmqDpnDeviceListener> listeners = Sets.newHashSet();
+    private HashSet<NgicDpnDeviceListener> listeners = Sets.newHashSet();
 
     /* Config */
     private ConfigFactory<ApplicationId, FpcConfig> fpcConfigConfigFactory =
@@ -131,7 +131,7 @@
 
         JettyServer.createInstance().open();
         ParseStream.createInstance().open();
-        NbEventWorkerManager.createInstance(20, restconfService).open();
+        NbEventWorkerManager.createInstance(20).open();
         DpnNgicCommunicator.createInstance();
         DpnP4Communicator.createInstance(applicationId, flowRuleService);
 
@@ -168,7 +168,7 @@
                             helper.dpnSubscriberUri(),
                             helper.nodeId(),
                             helper.networkId(),
-                            zmqDpnProviderService.getListener(),
+                            ngicDpnProviderService.getListener(),
                             notificationIds
                     );
 
@@ -184,12 +184,12 @@
     }
 
     @Override
-    public void addListener(ZmqDpnDeviceListener listener) {
+    public void addListener(NgicDpnDeviceListener listener) {
         listeners.add(listener);
     }
 
     @Override
-    public void removeListener(ZmqDpnDeviceListener listener) {
+    public void removeListener(NgicDpnDeviceListener listener) {
         listeners.remove(listener);
     }
 
diff --git a/apps/fpcagent/src/main/java/org/onosproject/fpcagent/FpcRpcManager.java b/apps/fpcagent/src/main/java/org/onosproject/fpcagent/FpcRpcManager.java
index f8b80fd..a8afa83 100644
--- a/apps/fpcagent/src/main/java/org/onosproject/fpcagent/FpcRpcManager.java
+++ b/apps/fpcagent/src/main/java/org/onosproject/fpcagent/FpcRpcManager.java
@@ -41,6 +41,7 @@
 import org.onosproject.net.device.DeviceListener;
 import org.onosproject.net.device.DeviceService;
 import org.onosproject.net.device.DeviceStore;
+import org.onosproject.restconf.api.RestconfService;
 import org.onosproject.yang.gen.v1.fpc.rev20150105.fpc.DefaultConnectionInfo;
 import org.onosproject.yang.gen.v1.fpc.rev20150105.fpc.P4DpnControlProtocol;
 import org.onosproject.yang.gen.v1.fpc.rev20150105.fpc.ZmqDpnControlProtocol;
@@ -154,6 +155,9 @@
     @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
     private DeviceService deviceService;
 
+    @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+    private RestconfService restconfService;
+
     private InternalDeviceListener listener = new InternalDeviceListener();
 
     // FIXME configurable
@@ -181,6 +185,7 @@
         FpcUtil.modelConverter = modelConverter;
         FpcUtil.dynamicConfigService = dynamicConfigService;
         FpcUtil.deviceStore = deviceStore;
+        FpcUtil.restconfService = restconfService;
         getResourceId();
 
         // Create the Default Tenant and added to the Tenants structure.
@@ -1064,7 +1069,7 @@
 
         @Override
         public void event(DeviceEvent event) {
-            if (event.subject().manufacturer().equals("fpc")) {
+            if (event.subject().id().toString().contains("fpc")) {
                 TENANT_INFO.forEach(
                         (tenantId, clients) -> {
                             String nodeNetwork = event.subject().annotations().value("node/network");
@@ -1085,16 +1090,17 @@
                                             availability.dpnName(dpn.dpnName());
 
                                             switch (event.type()) {
-                                                case DEVICE_UPDATED:
                                                 case DEVICE_ADDED: {
                                                     availability.dpnStatus(DpnStatusEnum.AVAILABLE);
                                                     break;
                                                 }
-                                                case DEVICE_AVAILABILITY_CHANGED:
                                                 case DEVICE_REMOVED: {
                                                     availability.dpnStatus(DpnStatusEnum.UNAVAILABLE);
                                                     break;
                                                 }
+                                                case DEVICE_UPDATED:
+                                                case DEVICE_AVAILABILITY_CHANGED:
+                                                    break;
                                                 default:
                                                     throw new RuntimeException("Unknown Device case.");
                                             }
@@ -1108,6 +1114,24 @@
                             }
                         });
             }
+            if (event.subject().id().toString().contains("bmv2") ||
+                    event.subject().id().toString().contains("tofino")) {
+                switch (event.type()) {
+                    case DEVICE_ADDED: {
+                        addDpn(event.subject().id().toString().split(":")[2]);
+                        break;
+                    }
+                    case DEVICE_REMOVED: {
+                        deleteDpn(event.subject().id().toString().split(":")[2]);
+                        break;
+                    }
+                    case DEVICE_UPDATED:
+                    case DEVICE_AVAILABILITY_CHANGED:
+                        break;
+                    default:
+                        throw new RuntimeException("Unknown Device case.");
+                }
+            }
 //            else if (event.subject().manufacturer().equals("cp")) {
 //                String clientId = event.subject().annotations().value("client-id");
 //                if (CLIENT_INFO.keySet().contains(ClientIdentifier.fromString(clientId))) {
diff --git a/apps/fpcagent/src/main/java/org/onosproject/fpcagent/FpcService.java b/apps/fpcagent/src/main/java/org/onosproject/fpcagent/FpcService.java
index 7bb120d..d7b7c9d 100644
--- a/apps/fpcagent/src/main/java/org/onosproject/fpcagent/FpcService.java
+++ b/apps/fpcagent/src/main/java/org/onosproject/fpcagent/FpcService.java
@@ -16,16 +16,16 @@
 
 package org.onosproject.fpcagent;
 
-import org.onosproject.fpcagent.providers.ZmqDpnDeviceListener;
+import org.onosproject.fpcagent.providers.NgicDpnDeviceListener;
 import org.onosproject.fpcagent.util.ConfigHelper;
 
 import java.util.Optional;
 
 public interface FpcService {
 
-    void addListener(ZmqDpnDeviceListener listener);
+    void addListener(NgicDpnDeviceListener listener);
 
-    void removeListener(ZmqDpnDeviceListener listener);
+    void removeListener(NgicDpnDeviceListener listener);
 
     Optional<ConfigHelper> getConfig();
 }
diff --git a/apps/fpcagent/src/main/java/org/onosproject/fpcagent/providers/ZmqDpnDeviceListener.java b/apps/fpcagent/src/main/java/org/onosproject/fpcagent/providers/NgicDpnDeviceListener.java
similarity index 94%
rename from apps/fpcagent/src/main/java/org/onosproject/fpcagent/providers/ZmqDpnDeviceListener.java
rename to apps/fpcagent/src/main/java/org/onosproject/fpcagent/providers/NgicDpnDeviceListener.java
index c13bf06..37607fc 100644
--- a/apps/fpcagent/src/main/java/org/onosproject/fpcagent/providers/ZmqDpnDeviceListener.java
+++ b/apps/fpcagent/src/main/java/org/onosproject/fpcagent/providers/NgicDpnDeviceListener.java
@@ -16,7 +16,7 @@
 
 package org.onosproject.fpcagent.providers;
 
-public interface ZmqDpnDeviceListener {
+public interface NgicDpnDeviceListener {
     void deviceAdded(String id, byte topic);
 
     void deviceRemoved(String id);
diff --git a/apps/fpcagent/src/main/java/org/onosproject/fpcagent/providers/ZmqDpnProvider.java b/apps/fpcagent/src/main/java/org/onosproject/fpcagent/providers/NgicDpnProvider.java
similarity index 85%
rename from apps/fpcagent/src/main/java/org/onosproject/fpcagent/providers/ZmqDpnProvider.java
rename to apps/fpcagent/src/main/java/org/onosproject/fpcagent/providers/NgicDpnProvider.java
index c7f2706..13175ab 100644
--- a/apps/fpcagent/src/main/java/org/onosproject/fpcagent/providers/ZmqDpnProvider.java
+++ b/apps/fpcagent/src/main/java/org/onosproject/fpcagent/providers/NgicDpnProvider.java
@@ -38,6 +38,8 @@
 import org.onosproject.net.provider.ProviderId;
 import org.slf4j.Logger;
 
+import static org.onosproject.fpcagent.util.FpcUtil.addDpn;
+import static org.onosproject.fpcagent.util.FpcUtil.deleteDpn;
 import static org.onosproject.net.DeviceId.deviceId;
 import static org.slf4j.LoggerFactory.getLogger;
 
@@ -46,17 +48,19 @@
  */
 @Component(immediate = true)
 @Service
-public class ZmqDpnProvider extends AbstractProvider implements ZmqDpnProviderService {
+public class NgicDpnProvider
+        extends AbstractProvider
+        implements NgicDpnProviderService {
 
-    private static final Logger log = getLogger(ZmqDpnProvider.class);
-    private final InternalDeviceListenerZmq listener = new InternalDeviceListenerZmq();
+    private static final Logger log = getLogger(NgicDpnProvider.class);
+    private final InternalDeviceListenerNgic listener = new InternalDeviceListenerNgic();
 
     @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
     protected DeviceProviderRegistry providerRegistry;
 
     private DeviceProviderService providerService;
 
-    public ZmqDpnProvider() {
+    public NgicDpnProvider() {
         super(new ProviderId("fpc", "org.onosproject.providers.dpn"));
     }
 
@@ -73,7 +77,7 @@
         log.info("FPC Device Provider Stopped");
     }
 
-    public InternalDeviceListenerZmq getListener() {
+    public InternalDeviceListenerNgic getListener() {
         return listener;
     }
 
@@ -97,7 +101,7 @@
 
     }
 
-    public class InternalDeviceListenerZmq implements ZmqDpnDeviceListener {
+    public class InternalDeviceListenerNgic implements NgicDpnDeviceListener {
 
         @Override
         public void deviceAdded(String id, byte topic) {
@@ -117,11 +121,13 @@
                     description = new DefaultDeviceDescription(descriptionBase, annotations);
 
             providerService.deviceConnected(deviceId, description);
+            addDpn(id.split("/")[0].split("node")[1]);
         }
 
         @Override
         public void deviceRemoved(String id) {
             providerService.deviceDisconnected(deviceId("fpc:" + id));
+            deleteDpn(id.split("/")[0].split("node")[1]);
         }
     }
 }
diff --git a/apps/fpcagent/src/main/java/org/onosproject/fpcagent/providers/ZmqDpnProviderService.java b/apps/fpcagent/src/main/java/org/onosproject/fpcagent/providers/NgicDpnProviderService.java
similarity index 87%
rename from apps/fpcagent/src/main/java/org/onosproject/fpcagent/providers/ZmqDpnProviderService.java
rename to apps/fpcagent/src/main/java/org/onosproject/fpcagent/providers/NgicDpnProviderService.java
index cc78c6c..b621afa 100644
--- a/apps/fpcagent/src/main/java/org/onosproject/fpcagent/providers/ZmqDpnProviderService.java
+++ b/apps/fpcagent/src/main/java/org/onosproject/fpcagent/providers/NgicDpnProviderService.java
@@ -18,8 +18,8 @@
 
 import org.onosproject.net.device.DeviceProvider;
 
-public interface ZmqDpnProviderService extends DeviceProvider {
+public interface NgicDpnProviderService extends DeviceProvider {
 
-    ZmqDpnDeviceListener getListener();
+    NgicDpnDeviceListener getListener();
 
 }
diff --git a/apps/fpcagent/src/main/java/org/onosproject/fpcagent/util/FpcUtil.java b/apps/fpcagent/src/main/java/org/onosproject/fpcagent/util/FpcUtil.java
index 3180aa7..bccc8e8 100644
--- a/apps/fpcagent/src/main/java/org/onosproject/fpcagent/util/FpcUtil.java
+++ b/apps/fpcagent/src/main/java/org/onosproject/fpcagent/util/FpcUtil.java
@@ -26,6 +26,7 @@
 import org.onosproject.fpcagent.util.eventstream.ConfigureService;
 import org.onosproject.net.Device;
 import org.onosproject.net.device.DeviceStore;
+import org.onosproject.restconf.api.RestconfService;
 import org.onosproject.restconf.utils.RestconfUtils;
 import org.onosproject.yang.gen.v1.fpc.rev20150105.fpc.registerclient.DefaultRegisterClientInput;
 import org.onosproject.yang.gen.v1.ietfdmmfpcagent.rev20160803.ietfdmmfpcagent.ClientIdentifier;
@@ -56,6 +57,7 @@
 import org.slf4j.LoggerFactory;
 
 import java.math.BigInteger;
+import java.net.URI;
 import java.util.AbstractMap;
 import java.util.HashSet;
 import java.util.List;
@@ -77,6 +79,7 @@
     public static DynamicConfigService dynamicConfigService;
     public static ModelConverter modelConverter;
     public static DeviceStore deviceStore;
+    public static RestconfService restconfService;
     // Resource IDs
     public static ResourceId configureDpn;
     public static ResourceId configure;
@@ -375,4 +378,47 @@
             log.error(ExceptionUtils.getFullStackTrace(e));
         }
     }
+
+    public static void addDpn(String dpnId) {
+        String dpnAdd = "" +
+                "    {\n" +
+                "        \"dpns\": [\n" +
+                "            {\n" +
+                "                \"dpn-id\": \"{$dpnId}\",\n" +
+                "                \"dpn-name\": \"site{$dpnId}-anchor{$dpnId}\",\n" +
+                "                \"dpn-groups\": [\n" +
+                "                    \"foo\"\n" +
+                "                ],\n" +
+                "                \"node-id\": \"node{$dpnId}\",\n" +
+                "                \"network-id\": \"network{$dpnId}\",\n" +
+                "                \"control-protocol\": \"zmq-dpn-control-protocol\",\n" +
+                "                \"abstract\": false\n" +
+                "            }\n" +
+                "        ]\n" +
+                "    }";
+
+        try {
+            ObjectMapper mapper = new ObjectMapper();
+            ObjectNode node = (ObjectNode) mapper.readTree(dpnAdd.replace("{$dpnId}", dpnId));
+
+            restconfService.runPostOperationOnDataResource(
+                    new URI("/onos/restconf/data/ietf-dmm-fpcagent:tenants/tenant=default/fpc-topology"),
+                    node
+            );
+        } catch (Exception e) {
+            log.error(ExceptionUtils.getFullStackTrace(e));
+        }
+
+    }
+
+    public static void deleteDpn(String dpnId) {
+        String dpnDelete = "/onos/restconf/data/ietf-dmm-fpcagent:tenants/tenant=default/fpc-topology/dpns={$dpnId}";
+
+        try {
+            restconfService.runDeleteOperationOnDataResource(new URI(dpnDelete.replace("{$dpnId}", dpnId)));
+        } catch (Exception e) {
+            log.error(ExceptionUtils.getFullStackTrace(e));
+        }
+
+    }
 }
diff --git a/apps/fpcagent/src/main/java/org/onosproject/fpcagent/util/eventstream/NbEventWorkerManager.java b/apps/fpcagent/src/main/java/org/onosproject/fpcagent/util/eventstream/NbEventWorkerManager.java
index 2fbc782..d1762f4 100644
--- a/apps/fpcagent/src/main/java/org/onosproject/fpcagent/util/eventstream/NbEventWorkerManager.java
+++ b/apps/fpcagent/src/main/java/org/onosproject/fpcagent/util/eventstream/NbEventWorkerManager.java
@@ -22,7 +22,6 @@
 import org.json.JSONException;
 import org.json.JSONObject;
 import org.onosproject.restconf.api.RestconfRpcOutput;
-import org.onosproject.restconf.api.RestconfService;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -33,10 +32,11 @@
 import java.util.concurrent.BlockingQueue;
 import java.util.concurrent.CompletableFuture;
 import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
 import java.util.concurrent.LinkedBlockingQueue;
 
+import static org.onosproject.fpcagent.util.FpcUtil.restconfService;
+
 /**
  * Implements a Worker to process event-data pairs sent by the FPC Client.
  */
@@ -49,21 +49,19 @@
     private final BlockingQueue<Entry<String, Entry<String, String>>> blockingQueue;
     private final int poolSize;
     private boolean run;
-    private final RestconfService restconfService;
 
     static {
         CLIENT_ID_TO_URI = new ConcurrentHashMap<>();
     }
 
-    protected NbEventWorkerManager(int poolSize, RestconfService restconfService) {
+    protected NbEventWorkerManager(int poolSize) {
         this.poolSize = poolSize;
-        this.restconfService = restconfService;
         this.blockingQueue = new LinkedBlockingQueue<>();
     }
 
-    public static NbEventWorkerManager createInstance(int poolSize, RestconfService restconfService) {
+    public static NbEventWorkerManager createInstance(int poolSize) {
         if (_instance == null) {
-            _instance = new NbEventWorkerManager(poolSize, restconfService);
+            _instance = new NbEventWorkerManager(poolSize);
         }
         return _instance;
     }
@@ -81,8 +79,7 @@
     }
 
     public void open() {
-        ExecutorService executorService = Executors.newFixedThreadPool(this.poolSize);
-        executorService.submit(() -> {
+        Executors.newFixedThreadPool(this.poolSize).submit(() -> {
             this.run = true;
             Entry<String, Entry<String, String>> contents = null;
             while (run) {
diff --git a/apps/fpcagent/src/main/java/org/onosproject/fpcagent/workers/ZmqSbSubscriberManager.java b/apps/fpcagent/src/main/java/org/onosproject/fpcagent/workers/ZmqSbSubscriberManager.java
index 71ab3ed..4e3d67e 100644
--- a/apps/fpcagent/src/main/java/org/onosproject/fpcagent/workers/ZmqSbSubscriberManager.java
+++ b/apps/fpcagent/src/main/java/org/onosproject/fpcagent/workers/ZmqSbSubscriberManager.java
@@ -18,7 +18,7 @@
 
 import org.apache.commons.lang.exception.ExceptionUtils;
 import org.onosproject.core.IdGenerator;
-import org.onosproject.fpcagent.providers.ZmqDpnDeviceListener;
+import org.onosproject.fpcagent.providers.NgicDpnDeviceListener;
 import org.onosproject.fpcagent.util.CacheManager;
 import org.onosproject.fpcagent.util.FpcUtil;
 import org.onosproject.yang.gen.v1.ietfdmmfpcagent.rev20160803.ietfdmmfpcagent.ClientIdentifier;
@@ -70,22 +70,22 @@
     private Future<?> broadcastTopicWorker;
     private Future<?> generalWorker;
 
-    private ZmqDpnDeviceListener zmqDpnDeviceListener;
+    private NgicDpnDeviceListener ngicDpnDeviceListener;
 
     protected ZmqSbSubscriberManager(String address, String nodeId, String networkId,
-                                     ZmqDpnDeviceListener zmqDpnDeviceListener, IdGenerator notificationIds) {
+                                     NgicDpnDeviceListener ngicDpnDeviceListener, IdGenerator notificationIds) {
         this.address = address;
         this.run = true;
         this.nodeId = nodeId;
         this.networkId = networkId;
         this.conflictingTopic = false;
         this.controllerSourceId = (long) ThreadLocalRandom.current().nextInt(0, 65535);
-        this.zmqDpnDeviceListener = zmqDpnDeviceListener;
+        this.ngicDpnDeviceListener = ngicDpnDeviceListener;
         this.notificationIds = notificationIds;
     }
 
     public static ZmqSbSubscriberManager createInstance(String address, String nodeId, String networkId,
-                                                        ZmqDpnDeviceListener providerService,
+                                                        NgicDpnDeviceListener providerService,
                                                         IdGenerator notificationIds) {
         if (_instance == null) {
             _instance = new ZmqSbSubscriberManager(address, nodeId, networkId, providerService, notificationIds);
@@ -234,10 +234,10 @@
                         fromIntToLong(buf, 4), deviceId);
                 if (status.equals(DpnStatusIndication.HELLO)) {
                     log.info("Hello {} on topic {}", deviceId, buf[2]);
-                    zmqDpnDeviceListener.deviceAdded(deviceId, buf[2]);
+                    ngicDpnDeviceListener.deviceAdded(deviceId, buf[2]);
                 } else if (status.equals(DpnStatusIndication.GOODBYE)) {
                     log.info("Bye {}", deviceId);
-                    zmqDpnDeviceListener.deviceRemoved(deviceId);
+                    ngicDpnDeviceListener.deviceRemoved(deviceId);
                 }
                 return new AbstractMap.SimpleEntry<>(status, deviceId);
             } else if (type.equals(S11MsgType.DPN_RESPONSE)) {