ONOS-3460 - Link provider that enforces strict configuration

This provider uses the "links" configuration of the network
config and only allows discovery of links that are in
the config.

Refactoring will be done in a subsequent patch set - the DiscoveryContext and
LinkDiscovery classes are duplicates, they need to be refactored so the
LLDP provider and the Network Config provider can share them.

Change-Id: I4de12fc1c4ffa05e3cac7767b8a31f48ba379f6c
diff --git a/cli/src/main/java/org/onosproject/cli/net/LinksListCommand.java b/cli/src/main/java/org/onosproject/cli/net/LinksListCommand.java
index b9403a3..6e73eb9 100644
--- a/cli/src/main/java/org/onosproject/cli/net/LinksListCommand.java
+++ b/cli/src/main/java/org/onosproject/cli/net/LinksListCommand.java
@@ -35,7 +35,7 @@
          description = "Lists all infrastructure links")
 public class LinksListCommand extends AbstractShellCommand {
 
-    private static final String FMT = "src=%s/%s, dst=%s/%s, type=%s, state=%s%s";
+    private static final String FMT = "src=%s/%s, dst=%s/%s, type=%s, state=%s%s, expected=%s";
     private static final String COMPACT = "%s/%s-%s/%s";
 
     @Argument(index = 0, name = "uri", description = "Device ID",
@@ -93,7 +93,8 @@
         return String.format(FMT, link.src().deviceId(), link.src().port(),
                              link.dst().deviceId(), link.dst().port(),
                              link.type(), link.state(),
-                             annotations(link.annotations()));
+                             annotations(link.annotations()),
+                             link.isExpected());
     }
 
     /**
diff --git a/core/api/src/main/java/org/onosproject/net/DefaultLink.java b/core/api/src/main/java/org/onosproject/net/DefaultLink.java
index 5515175..a52df72 100644
--- a/core/api/src/main/java/org/onosproject/net/DefaultLink.java
+++ b/core/api/src/main/java/org/onosproject/net/DefaultLink.java
@@ -119,7 +119,8 @@
             final DefaultLink other = (DefaultLink) obj;
             return Objects.equals(this.src, other.src) &&
                     Objects.equals(this.dst, other.dst) &&
-                    Objects.equals(this.type, other.type);
+                    Objects.equals(this.type, other.type) &&
+                    Objects.equals(this.isExpected, other.isExpected);
         }
         return false;
     }
diff --git a/core/api/src/main/java/org/onosproject/net/link/DefaultLinkDescription.java b/core/api/src/main/java/org/onosproject/net/link/DefaultLinkDescription.java
index 4252695..1c74513 100644
--- a/core/api/src/main/java/org/onosproject/net/link/DefaultLinkDescription.java
+++ b/core/api/src/main/java/org/onosproject/net/link/DefaultLinkDescription.java
@@ -31,6 +31,30 @@
     private final ConnectPoint src;
     private final ConnectPoint dst;
     private final Link.Type type;
+    private final boolean isExpected;
+
+    public static final boolean EXPECTED = true;
+    public static final boolean NOT_EXPECTED = false;
+
+    /**
+     * Creates a link description using the supplied information.
+     *
+     * @param src         link source
+     * @param dst         link destination
+     * @param type        link type
+     * @param isExpected  is the link expected to be part of this configuration
+     * @param annotations optional key/value annotations
+     */
+    public DefaultLinkDescription(ConnectPoint src, ConnectPoint dst,
+                                  Link.Type type,
+                                  boolean isExpected,
+                                  SparseAnnotations... annotations) {
+        super(annotations);
+        this.src = src;
+        this.dst = dst;
+        this.type = type;
+        this.isExpected = isExpected;
+    }
 
     /**
      * Creates a link description using the supplied information.
@@ -41,11 +65,9 @@
      * @param annotations optional key/value annotations
      */
     public DefaultLinkDescription(ConnectPoint src, ConnectPoint dst,
-                                  Link.Type type, SparseAnnotations... annotations) {
-        super(annotations);
-        this.src = src;
-        this.dst = dst;
-        this.type = type;
+                                  Link.Type type,
+                                  SparseAnnotations... annotations) {
+        this(src, dst, type, EXPECTED, annotations);
     }
 
     @Override
@@ -64,18 +86,24 @@
     }
 
     @Override
+    public boolean isExpected() {
+        return isExpected;
+    }
+
+    @Override
     public String toString() {
         return MoreObjects.toStringHelper(this)
                 .add("src", src())
                 .add("dst", dst())
                 .add("type", type())
+                .add("isExpected", isExpected())
                 .add("annotations", annotations())
                 .toString();
     }
 
     @Override
     public int hashCode() {
-        return Objects.hashCode(super.hashCode(), src, dst, type);
+        return Objects.hashCode(super.hashCode(), src, dst, type, isExpected);
     }
 
     @Override
@@ -87,7 +115,8 @@
             DefaultLinkDescription that = (DefaultLinkDescription) object;
             return Objects.equal(this.src, that.src)
                     && Objects.equal(this.dst, that.dst)
-                    && Objects.equal(this.type, that.type);
+                    && Objects.equal(this.type, that.type)
+                    && Objects.equal(this.isExpected, that.isExpected);
         }
         return false;
     }
diff --git a/core/api/src/main/java/org/onosproject/net/link/LinkDescription.java b/core/api/src/main/java/org/onosproject/net/link/LinkDescription.java
index f85718b..60761ad 100644
--- a/core/api/src/main/java/org/onosproject/net/link/LinkDescription.java
+++ b/core/api/src/main/java/org/onosproject/net/link/LinkDescription.java
@@ -45,5 +45,12 @@
      */
     Link.Type type();
 
+    /**
+     * Returns true if the link is expected, false otherwise.
+     *
+     * @return expected flag
+     */
+    boolean isExpected();
+
     // Add further link attributes
 }
diff --git a/core/store/dist/src/main/java/org/onosproject/store/link/impl/CoreConfig.java b/core/store/dist/src/main/java/org/onosproject/store/link/impl/CoreConfig.java
new file mode 100644
index 0000000..dba3106
--- /dev/null
+++ b/core/store/dist/src/main/java/org/onosproject/store/link/impl/CoreConfig.java
@@ -0,0 +1,37 @@
+/*
+ * Copyright 2016 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.store.link.impl;
+
+import org.onosproject.core.ApplicationId;
+import org.onosproject.net.config.Config;
+
+public class CoreConfig extends Config<ApplicationId> {
+
+    private static final String LINK_DISCOVERY_MODE = "linkDiscoveryMode";
+
+    protected static final String DEFAULT_LINK_DISCOVERY_MODE = "PERMISSIVE";
+
+    /**
+     * Returns the link discovery mode.
+     *
+     * @return link discovery mode
+     */
+    public ECLinkStore.LinkDiscoveryMode linkDiscoveryMode() {
+        return ECLinkStore.LinkDiscoveryMode
+                .valueOf(get(LINK_DISCOVERY_MODE, DEFAULT_LINK_DISCOVERY_MODE));
+    }
+}
+
diff --git a/core/store/dist/src/main/java/org/onosproject/store/link/impl/ECLinkStore.java b/core/store/dist/src/main/java/org/onosproject/store/link/impl/ECLinkStore.java
index 8e77ac8..845518e 100644
--- a/core/store/dist/src/main/java/org/onosproject/store/link/impl/ECLinkStore.java
+++ b/core/store/dist/src/main/java/org/onosproject/store/link/impl/ECLinkStore.java
@@ -15,21 +15,6 @@
  */
 package org.onosproject.store.link.impl;
 
-import static com.google.common.base.Preconditions.checkNotNull;
-import static org.onosproject.net.DefaultAnnotations.merge;
-import static org.onosproject.net.DefaultAnnotations.union;
-import static org.onosproject.net.Link.State.ACTIVE;
-import static org.onosproject.net.Link.State.INACTIVE;
-import static org.onosproject.net.Link.Type.DIRECT;
-import static org.onosproject.net.Link.Type.INDIRECT;
-import static org.onosproject.net.LinkKey.linkKey;
-import static org.onosproject.net.link.LinkEvent.Type.LINK_ADDED;
-import static org.onosproject.net.link.LinkEvent.Type.LINK_REMOVED;
-import static org.onosproject.net.link.LinkEvent.Type.LINK_UPDATED;
-import static org.onosproject.store.service.EventuallyConsistentMapEvent.Type.PUT;
-import static org.onosproject.store.service.EventuallyConsistentMapEvent.Type.REMOVE;
-import static org.slf4j.LoggerFactory.getLogger;
-
 import java.util.Collection;
 import java.util.Map;
 import java.util.Objects;
@@ -48,6 +33,8 @@
 import org.onlab.util.SharedExecutors;
 import org.onosproject.cluster.ClusterService;
 import org.onosproject.cluster.NodeId;
+import org.onosproject.core.ApplicationId;
+import org.onosproject.core.CoreService;
 import org.onosproject.mastership.MastershipService;
 import org.onosproject.net.AnnotationKeys;
 import org.onosproject.net.AnnotationsUtil;
@@ -56,8 +43,12 @@
 import org.onosproject.net.DefaultLink;
 import org.onosproject.net.DeviceId;
 import org.onosproject.net.Link;
-import org.onosproject.net.LinkKey;
 import org.onosproject.net.Link.Type;
+import org.onosproject.net.LinkKey;
+import org.onosproject.net.config.ConfigFactory;
+import org.onosproject.net.config.NetworkConfigEvent;
+import org.onosproject.net.config.NetworkConfigListener;
+import org.onosproject.net.config.NetworkConfigRegistry;
 import org.onosproject.net.device.DeviceClockService;
 import org.onosproject.net.link.DefaultLinkDescription;
 import org.onosproject.net.link.LinkDescription;
@@ -82,6 +73,22 @@
 import com.google.common.collect.Maps;
 import com.google.common.util.concurrent.Futures;
 
+import static com.google.common.base.Preconditions.checkNotNull;
+import static org.onosproject.net.DefaultAnnotations.merge;
+import static org.onosproject.net.DefaultAnnotations.union;
+import static org.onosproject.net.Link.State.ACTIVE;
+import static org.onosproject.net.Link.State.INACTIVE;
+import static org.onosproject.net.Link.Type.DIRECT;
+import static org.onosproject.net.Link.Type.INDIRECT;
+import static org.onosproject.net.LinkKey.linkKey;
+import static org.onosproject.net.config.basics.SubjectFactories.APP_SUBJECT_FACTORY;
+import static org.onosproject.net.link.LinkEvent.Type.LINK_ADDED;
+import static org.onosproject.net.link.LinkEvent.Type.LINK_REMOVED;
+import static org.onosproject.net.link.LinkEvent.Type.LINK_UPDATED;
+import static org.onosproject.store.service.EventuallyConsistentMapEvent.Type.PUT;
+import static org.onosproject.store.service.EventuallyConsistentMapEvent.Type.REMOVE;
+import static org.slf4j.LoggerFactory.getLogger;
+
 /**
  * Manages the inventory of links using a {@code EventuallyConsistentMap}.
  */
@@ -91,11 +98,29 @@
     extends AbstractStore<LinkEvent, LinkStoreDelegate>
     implements LinkStore {
 
+    /**
+     * Modes for dealing with newly discovered links.
+     */
+    protected enum LinkDiscoveryMode {
+        /**
+         * Permissive mode - all newly discovered links are valid.
+         */
+        PERMISSIVE,
+
+        /**
+         * Strict mode - all newly discovered links must be defined in
+         * the network config.
+         */
+        STRICT
+    }
+
     private final Logger log = getLogger(getClass());
 
     private final Map<LinkKey, Link> links = Maps.newConcurrentMap();
     private EventuallyConsistentMap<Provided<LinkKey>, LinkDescription> linkDescriptions;
 
+    private ApplicationId appId;
+
     private static final MessageSubject LINK_INJECT_MESSAGE = new MessageSubject("inject-link-request");
 
     @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
@@ -113,9 +138,20 @@
     @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
     protected ClusterService clusterService;
 
+    @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+    protected NetworkConfigRegistry netCfgService;
+
+    @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+    protected CoreService coreService;
+
     private EventuallyConsistentMapListener<Provided<LinkKey>, LinkDescription> linkTracker =
             new InternalLinkTracker();
 
+    // Listener for config changes
+    private final InternalConfigListener cfgListener = new InternalConfigListener();
+
+    protected LinkDiscoveryMode linkDiscoveryMode = LinkDiscoveryMode.STRICT;
+
     protected static final KryoSerializer SERIALIZER = new KryoSerializer() {
         @Override
         protected void setupKryoPool() {
@@ -129,6 +165,12 @@
 
     @Activate
     public void activate() {
+        appId = coreService.registerApplication("org.onosproject.core");
+        netCfgService.registerConfigFactory(factory);
+        netCfgService.addListener(cfgListener);
+
+        cfgListener.reconfigure(netCfgService.getConfig(appId, CoreConfig.class));
+
         KryoNamespace.Builder serializer = KryoNamespace.newBuilder()
                 .register(KryoNamespaces.API)
                 .register(MastershipBasedTimestamp.class)
@@ -162,6 +204,8 @@
         linkDescriptions.destroy();
         links.clear();
         clusterCommunicator.removeSubscriber(LINK_INJECT_MESSAGE);
+        netCfgService.removeListener(cfgListener);
+        netCfgService.unregisterConfigFactory(factory);
 
         log.info("Stopped");
     }
@@ -255,6 +299,7 @@
                         current.src(),
                         current.dst(),
                         current.type() == DIRECT ? DIRECT : updated.type(),
+                        current.isExpected(),
                         union(current.annotations(), updated.annotations()));
         }
         return updated;
@@ -268,6 +313,7 @@
                 eventType.set(LINK_ADDED);
                 return newLink;
             } else if (existingLink.state() != newLink.state() ||
+                       existingLink.isExpected() != newLink.isExpected() ||
                         (existingLink.type() == INDIRECT && newLink.type() == DIRECT) ||
                         !AnnotationsUtil.isEqual(existingLink.annotations(), newLink.annotations())) {
                     eventType.set(LINK_UPDATED);
@@ -316,14 +362,28 @@
                                                           linkDescriptions.get(key).annotations()));
         });
 
-        boolean isDurable = Objects.equals(annotations.get().value(AnnotationKeys.DURABLE), "true");
+        Link.State initialLinkState;
+
+        boolean isExpected;
+        if (linkDiscoveryMode == LinkDiscoveryMode.PERMISSIVE) {
+            initialLinkState = ACTIVE;
+            isExpected =
+                    Objects.equals(annotations.get().value(AnnotationKeys.DURABLE), "true");
+        } else {
+            initialLinkState = base.isExpected() ? ACTIVE : INACTIVE;
+            isExpected = base.isExpected();
+        }
+
+
+
+
         return DefaultLink.builder()
                 .providerId(baseProviderId)
                 .src(src)
                 .dst(dst)
                 .type(type)
-                .state(ACTIVE)
-                .isExpected(isDurable)
+                .state(initialLinkState)
+                .isExpected(isExpected)
                 .annotations(annotations.get())
                 .build();
     }
@@ -350,7 +410,7 @@
             return null;
         }
 
-        if (link.isDurable()) {
+        if (linkDiscoveryMode == LinkDiscoveryMode.PERMISSIVE && link.isExpected()) {
             // FIXME: this will not sync link state!!!
             return link.state() == INACTIVE ? null :
                     updateLink(linkKey(link.src(), link.dst()), link,
@@ -421,4 +481,47 @@
             }
         }
     }
+
+    private class InternalConfigListener implements NetworkConfigListener {
+
+        void reconfigure(CoreConfig coreConfig) {
+            if (coreConfig == null) {
+                linkDiscoveryMode = LinkDiscoveryMode.PERMISSIVE;
+            } else {
+                linkDiscoveryMode = coreConfig.linkDiscoveryMode();
+            }
+            if (linkDiscoveryMode == LinkDiscoveryMode.STRICT) {
+                // Remove any previous links to force them to go through the strict
+                // discovery process
+                linkDescriptions.clear();
+                links.clear();
+            }
+            log.debug("config set link discovery mode to {}",
+                      linkDiscoveryMode.name());
+        }
+
+        @Override
+        public void event(NetworkConfigEvent event) {
+
+            if ((event.type() == NetworkConfigEvent.Type.CONFIG_ADDED ||
+                    event.type() == NetworkConfigEvent.Type.CONFIG_UPDATED) &&
+                    event.configClass().equals(CoreConfig.class)) {
+
+                CoreConfig cfg = netCfgService.getConfig(appId, CoreConfig.class);
+                reconfigure(cfg);
+                log.info("Reconfigured");
+            }
+        }
+    }
+
+    // Configuration properties factory
+    private final ConfigFactory factory =
+            new ConfigFactory<ApplicationId, CoreConfig>(APP_SUBJECT_FACTORY,
+                                                        CoreConfig.class,
+                                                        "core") {
+                @Override
+                public CoreConfig createConfig() {
+                    return new CoreConfig();
+                }
+            };
 }
diff --git a/core/store/dist/src/main/java/org/onosproject/store/link/impl/GossipLinkStore.java b/core/store/dist/src/main/java/org/onosproject/store/link/impl/GossipLinkStore.java
index cf46b15..551e731 100644
--- a/core/store/dist/src/main/java/org/onosproject/store/link/impl/GossipLinkStore.java
+++ b/core/store/dist/src/main/java/org/onosproject/store/link/impl/GossipLinkStore.java
@@ -15,12 +15,20 @@
  */
 package org.onosproject.store.link.impl;
 
-import com.google.common.base.Function;
-import com.google.common.collect.FluentIterable;
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.Multimaps;
-import com.google.common.collect.SetMultimap;
-import com.google.common.collect.Sets;
+import java.io.IOException;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
+
 import org.apache.commons.lang3.RandomUtils;
 import org.apache.felix.scr.annotations.Activate;
 import org.apache.felix.scr.annotations.Deactivate;
@@ -32,7 +40,6 @@
 import org.onosproject.cluster.ControllerNode;
 import org.onosproject.cluster.NodeId;
 import org.onosproject.mastership.MastershipService;
-import org.onosproject.net.AnnotationKeys;
 import org.onosproject.net.AnnotationsUtil;
 import org.onosproject.net.ConnectPoint;
 import org.onosproject.net.DefaultAnnotations;
@@ -60,20 +67,12 @@
 import org.onosproject.store.serializers.custom.DistributedStoreSerializers;
 import org.slf4j.Logger;
 
-import java.io.IOException;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.Objects;
-import java.util.Set;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ConcurrentMap;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-import java.util.concurrent.ScheduledExecutorService;
-import java.util.concurrent.TimeUnit;
+import com.google.common.base.Function;
+import com.google.common.collect.FluentIterable;
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.Multimaps;
+import com.google.common.collect.SetMultimap;
+import com.google.common.collect.Sets;
 
 import static com.google.common.base.Preconditions.checkNotNull;
 import static com.google.common.base.Predicates.notNull;
@@ -433,7 +432,9 @@
                     new DefaultLinkDescription(
                         linkDescription.value().src(),
                         linkDescription.value().dst(),
-                        newType, merged),
+                        newType,
+                        existingLinkDescription.value().isExpected(),
+                        merged),
                     linkDescription.timestamp());
         }
         return descs.put(providerId, newLinkDescription);
@@ -608,14 +609,17 @@
             annotations = merge(annotations, e.getValue().value().annotations());
         }
 
-        boolean isDurable = Objects.equals(annotations.value(AnnotationKeys.DURABLE), "true");
+        //boolean isDurable = Objects.equals(annotations.value(AnnotationKeys.DURABLE), "true");
+
+        // TEMP
+        Link.State initialLinkState = base.value().isExpected() ? ACTIVE : INACTIVE;
         return DefaultLink.builder()
                 .providerId(baseProviderId)
                 .src(src)
                 .dst(dst)
                 .type(type)
-                .state(ACTIVE)
-                .isExpected(isDurable)
+                .state(initialLinkState)
+                .isExpected(base.value().isExpected())
                 .annotations(annotations)
                 .build();
     }
diff --git a/providers/netcfglinks/pom.xml b/providers/netcfglinks/pom.xml
new file mode 100644
index 0000000..3cc0799
--- /dev/null
+++ b/providers/netcfglinks/pom.xml
@@ -0,0 +1,61 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  ~ Copyright 2014 Open Networking Laboratory
+  ~
+  ~ Licensed under the Apache License, Version 2.0 (the "License");
+  ~ you may not use this file except in compliance with the License.
+  ~ You may obtain a copy of the License at
+  ~
+  ~     http://www.apache.org/licenses/LICENSE-2.0
+  ~
+  ~ Unless required by applicable law or agreed to in writing, software
+  ~ distributed under the License is distributed on an "AS IS" BASIS,
+  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  ~ See the License for the specific language governing permissions and
+  ~ limitations under the License.
+  -->
+<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>onos-providers</artifactId>
+        <groupId>org.onosproject</groupId>
+        <version>1.5.0-SNAPSHOT</version>
+    </parent>
+    <modelVersion>4.0.0</modelVersion>
+
+    <artifactId>onos-netcfg-links-provider</artifactId>
+    <packaging>bundle</packaging>
+
+    <description>
+        Links provider that uses network config service to predefine devices and links.
+    </description>
+    <url>http://onosproject.org</url>
+
+    <properties>
+        <onos.app.name>org.onosproject.netcfglinksprovider</onos.app.name>
+        <onos.app.origin>ON.Lab</onos.app.origin>
+    </properties>
+
+    <dependencies>
+
+        <dependency>
+            <groupId>org.onosproject</groupId>
+            <artifactId>onlab-osgi</artifactId>
+        </dependency>
+
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+            <version>4.11</version>
+            <scope>test</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>org.easymock</groupId>
+            <artifactId>easymock</artifactId>
+            <scope>test</scope>
+        </dependency>
+    </dependencies>
+
+</project>
diff --git a/providers/netcfglinks/src/main/java/org/onosproject/provider/netcfglinks/DiscoveryContext.java b/providers/netcfglinks/src/main/java/org/onosproject/provider/netcfglinks/DiscoveryContext.java
new file mode 100644
index 0000000..c9c3433
--- /dev/null
+++ b/providers/netcfglinks/src/main/java/org/onosproject/provider/netcfglinks/DiscoveryContext.java
@@ -0,0 +1,69 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.provider.netcfglinks;
+
+import org.onosproject.mastership.MastershipService;
+import org.onosproject.net.LinkKey;
+import org.onosproject.net.link.LinkProviderService;
+import org.onosproject.net.packet.PacketService;
+
+/**
+ * Shared context for use by link discovery.
+ */
+interface DiscoveryContext {
+
+    /**
+     * Returns the shared mastership service reference.
+     *
+     * @return mastership service
+     */
+    MastershipService mastershipService();
+
+    /**
+     * Returns the shared link provider service reference.
+     *
+     * @return link provider service
+     */
+    LinkProviderService providerService();
+
+    /**
+     * Returns the shared packet service reference.
+     *
+     * @return packet service
+     */
+    PacketService packetService();
+
+    /**
+     * Returns the probe rate in millis.
+     *
+     * @return probe rate
+     */
+    long probeRate();
+
+    /**
+     * Indicates whether to emit BDDP.
+     *
+     * @return true to emit BDDP
+     */
+    boolean useBddp();
+
+    /**
+     * Touches the link identified by the given key to indicate that it's active.
+     *
+     * @param key link key
+     */
+    void touchLink(LinkKey key);
+}
diff --git a/providers/netcfglinks/src/main/java/org/onosproject/provider/netcfglinks/LinkDiscovery.java b/providers/netcfglinks/src/main/java/org/onosproject/provider/netcfglinks/LinkDiscovery.java
new file mode 100644
index 0000000..4997775
--- /dev/null
+++ b/providers/netcfglinks/src/main/java/org/onosproject/provider/netcfglinks/LinkDiscovery.java
@@ -0,0 +1,262 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.provider.netcfglinks;
+
+import java.nio.ByteBuffer;
+import java.util.Set;
+
+import org.jboss.netty.util.Timeout;
+import org.jboss.netty.util.TimerTask;
+import org.onlab.packet.Ethernet;
+import org.onlab.packet.ONOSLLDP;
+import org.onlab.util.Timer;
+import org.onosproject.net.ConnectPoint;
+import org.onosproject.net.Device;
+import org.onosproject.net.DeviceId;
+import org.onosproject.net.Link.Type;
+import org.onosproject.net.LinkKey;
+import org.onosproject.net.Port;
+import org.onosproject.net.PortNumber;
+import org.onosproject.net.link.DefaultLinkDescription;
+import org.onosproject.net.link.LinkDescription;
+import org.onosproject.net.packet.DefaultOutboundPacket;
+import org.onosproject.net.packet.OutboundPacket;
+import org.onosproject.net.packet.PacketContext;
+import org.slf4j.Logger;
+
+import com.google.common.collect.Sets;
+
+import static java.util.concurrent.TimeUnit.MILLISECONDS;
+import static org.onosproject.net.PortNumber.portNumber;
+import static org.onosproject.net.flow.DefaultTrafficTreatment.builder;
+import static org.slf4j.LoggerFactory.getLogger;
+
+/**
+ * Run discovery process from a physical switch. Ports are initially labeled as
+ * slow ports. When an LLDP is successfully received, label the remote port as
+ * fast. Every probeRate milliseconds, loop over all fast ports and send an
+ * LLDP, send an LLDP for a single slow port. Based on FlowVisor topology
+ * discovery implementation.
+ */
+class LinkDiscovery implements TimerTask {
+
+    private final Logger log = getLogger(getClass());
+
+    private static final String SRC_MAC = "DE:AD:BE:EF:BA:11";
+
+    private final Device device;
+    private final DiscoveryContext context;
+
+    private final ONOSLLDP lldpPacket;
+    private final Ethernet ethPacket;
+    private final Ethernet bddpEth;
+
+    private Timeout timeout;
+    private volatile boolean isStopped;
+
+    // Set of ports to be probed
+    private final Set<Long> ports = Sets.newConcurrentHashSet();
+
+    /**
+     * Instantiates discovery manager for the given physical switch. Creates a
+     * generic LLDP packet that will be customized for the port it is sent out on.
+     * Starts the the timer for the discovery process.
+     *
+     * @param device  the physical switch
+     * @param context discovery context
+     */
+    LinkDiscovery(Device device, DiscoveryContext context) {
+        this.device = device;
+        this.context = context;
+
+        lldpPacket = new ONOSLLDP();
+        lldpPacket.setChassisId(device.chassisId());
+        lldpPacket.setDevice(device.id().toString());
+
+        ethPacket = new Ethernet();
+        ethPacket.setEtherType(Ethernet.TYPE_LLDP);
+        ethPacket.setDestinationMACAddress(ONOSLLDP.LLDP_NICIRA);
+        ethPacket.setPayload(this.lldpPacket);
+        ethPacket.setPad(true);
+
+        bddpEth = new Ethernet();
+        bddpEth.setPayload(lldpPacket);
+        bddpEth.setEtherType(Ethernet.TYPE_BSN);
+        bddpEth.setDestinationMACAddress(ONOSLLDP.BDDP_MULTICAST);
+        bddpEth.setPad(true);
+
+        isStopped = true;
+        start();
+        log.debug("Started discovery manager for switch {}", device.id());
+
+    }
+
+    synchronized void stop() {
+        if (!isStopped) {
+            isStopped = true;
+            timeout.cancel();
+        } else {
+            log.warn("LinkDiscovery stopped multiple times?");
+        }
+    }
+
+    synchronized void start() {
+        if (isStopped) {
+            isStopped = false;
+            timeout = Timer.getTimer().newTimeout(this, 0, MILLISECONDS);
+        } else {
+            log.warn("LinkDiscovery started multiple times?");
+        }
+    }
+
+    synchronized boolean isStopped() {
+        return isStopped || timeout.isCancelled();
+    }
+
+    /**
+     * Add physical port to discovery process.
+     * Send out initial LLDP and label it as slow port.
+     *
+     * @param port the port
+     */
+    void addPort(Port port) {
+        boolean newPort = ports.add(port.number().toLong());
+        boolean isMaster = context.mastershipService().isLocalMaster(device.id());
+        if (newPort && isMaster) {
+            log.debug("Sending initial probe to port {}@{}", port.number().toLong(), device.id());
+            sendProbes(port.number().toLong());
+        }
+    }
+
+    /**
+     * removed physical port from discovery process.
+     * @param port the port number
+     */
+    void removePort(PortNumber port) {
+        ports.remove(port.toLong());
+    }
+
+    /**
+     * Handles an incoming LLDP packet. Creates link in topology and adds the
+     * link for staleness tracking.
+     *
+     * @param packetContext packet context
+     * @return true if handled
+     */
+    boolean handleLldp(PacketContext packetContext) {
+        Ethernet eth = packetContext.inPacket().parsed();
+        if (eth == null) {
+            return false;
+        }
+
+        ONOSLLDP onoslldp = ONOSLLDP.parseONOSLLDP(eth);
+        if (onoslldp != null) {
+            PortNumber srcPort = portNumber(onoslldp.getPort());
+            PortNumber dstPort = packetContext.inPacket().receivedFrom().port();
+            DeviceId srcDeviceId = DeviceId.deviceId(onoslldp.getDeviceString());
+            DeviceId dstDeviceId = packetContext.inPacket().receivedFrom().deviceId();
+
+            ConnectPoint src = new ConnectPoint(srcDeviceId, srcPort);
+            ConnectPoint dst = new ConnectPoint(dstDeviceId, dstPort);
+
+            LinkDescription ld = eth.getEtherType() == Ethernet.TYPE_LLDP ?
+                    new DefaultLinkDescription(src, dst, Type.DIRECT, DefaultLinkDescription.EXPECTED) :
+                    new DefaultLinkDescription(src, dst, Type.INDIRECT, DefaultLinkDescription.EXPECTED);
+
+            try {
+                context.providerService().linkDetected(ld);
+                context.touchLink(LinkKey.linkKey(src, dst));
+            } catch (IllegalStateException e) {
+                return true;
+            }
+            return true;
+        }
+        return false;
+    }
+
+
+    /**
+     * Execute this method every t milliseconds. Loops over all ports
+     * labeled as fast and sends out an LLDP. Send out an LLDP on a single slow
+     * port.
+     *
+     * @param t timeout
+     */
+    @Override
+    public void run(Timeout t) {
+        if (isStopped()) {
+            return;
+        }
+
+        if (context.mastershipService().isLocalMaster(device.id())) {
+            log.trace("Sending probes from {}", device.id());
+            ports.forEach(this::sendProbes);
+        }
+
+        if (!isStopped()) {
+            timeout = Timer.getTimer().newTimeout(this, context.probeRate(), MILLISECONDS);
+        }
+    }
+
+    /**
+     * Creates packet_out LLDP for specified output port.
+     *
+     * @param port the port
+     * @return Packet_out message with LLDP data
+     */
+    private OutboundPacket createOutBoundLldp(Long port) {
+        if (port == null) {
+            return null;
+        }
+        lldpPacket.setPortId(port.intValue());
+        ethPacket.setSourceMACAddress(SRC_MAC);
+        return new DefaultOutboundPacket(device.id(),
+                                         builder().setOutput(portNumber(port)).build(),
+                                         ByteBuffer.wrap(ethPacket.serialize()));
+    }
+
+    /**
+     * Creates packet_out BDDP for specified output port.
+     *
+     * @param port the port
+     * @return Packet_out message with LLDP data
+     */
+    private OutboundPacket createOutBoundBddp(Long port) {
+        if (port == null) {
+            return null;
+        }
+        lldpPacket.setPortId(port.intValue());
+        bddpEth.setSourceMACAddress(SRC_MAC);
+        return new DefaultOutboundPacket(device.id(),
+                                         builder().setOutput(portNumber(port)).build(),
+                                         ByteBuffer.wrap(bddpEth.serialize()));
+    }
+
+    private void sendProbes(Long portNumber) {
+        log.trace("Sending probes out to {}@{}", portNumber, device.id());
+        OutboundPacket pkt = createOutBoundLldp(portNumber);
+        context.packetService().emit(pkt);
+        if (context.useBddp()) {
+            OutboundPacket bpkt = createOutBoundBddp(portNumber);
+            context.packetService().emit(bpkt);
+        }
+    }
+
+    boolean containsPort(long portNumber) {
+        return ports.contains(portNumber);
+    }
+
+}
diff --git a/providers/netcfglinks/src/main/java/org/onosproject/provider/netcfglinks/NetworkConfigLinksProvider.java b/providers/netcfglinks/src/main/java/org/onosproject/provider/netcfglinks/NetworkConfigLinksProvider.java
new file mode 100644
index 0000000..edbc25c
--- /dev/null
+++ b/providers/netcfglinks/src/main/java/org/onosproject/provider/netcfglinks/NetworkConfigLinksProvider.java
@@ -0,0 +1,424 @@
+/*
+ * Copyright 2016 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.provider.netcfglinks;
+
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Optional;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+
+import org.apache.felix.scr.annotations.Activate;
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.Deactivate;
+import org.apache.felix.scr.annotations.Property;
+import org.apache.felix.scr.annotations.Reference;
+import org.apache.felix.scr.annotations.ReferenceCardinality;
+import org.onlab.packet.Ethernet;
+import org.onlab.packet.ONOSLLDP;
+import org.onosproject.core.ApplicationId;
+import org.onosproject.core.CoreService;
+import org.onosproject.mastership.MastershipService;
+import org.onosproject.net.ConnectPoint;
+import org.onosproject.net.DefaultAnnotations;
+import org.onosproject.net.Device;
+import org.onosproject.net.DeviceId;
+import org.onosproject.net.Link;
+import org.onosproject.net.LinkKey;
+import org.onosproject.net.Port;
+import org.onosproject.net.PortNumber;
+import org.onosproject.net.config.NetworkConfigEvent;
+import org.onosproject.net.config.NetworkConfigListener;
+import org.onosproject.net.config.NetworkConfigRegistry;
+import org.onosproject.net.config.basics.BasicLinkConfig;
+import org.onosproject.net.device.DeviceEvent;
+import org.onosproject.net.device.DeviceListener;
+import org.onosproject.net.device.DeviceService;
+import org.onosproject.net.flow.DefaultTrafficSelector;
+import org.onosproject.net.flow.TrafficSelector;
+import org.onosproject.net.link.DefaultLinkDescription;
+import org.onosproject.net.link.LinkProvider;
+import org.onosproject.net.link.LinkProviderRegistry;
+import org.onosproject.net.link.LinkProviderService;
+import org.onosproject.net.packet.InboundPacket;
+import org.onosproject.net.packet.PacketContext;
+import org.onosproject.net.packet.PacketPriority;
+import org.onosproject.net.packet.PacketProcessor;
+import org.onosproject.net.packet.PacketService;
+import org.onosproject.net.provider.AbstractProvider;
+import org.onosproject.net.provider.ProviderId;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import static org.onlab.packet.Ethernet.TYPE_BSN;
+import static org.onlab.packet.Ethernet.TYPE_LLDP;
+import static org.onosproject.net.PortNumber.portNumber;
+
+/**
+ * Provider to pre-discover links and devices based on a specified network
+ * config.
+ */
+
+@Component(immediate = true)
+public class NetworkConfigLinksProvider
+        extends AbstractProvider
+        implements LinkProvider {
+
+    @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+    protected LinkProviderRegistry providerRegistry;
+
+    @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+    protected DeviceService deviceService;
+
+    @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+    protected PacketService packetService;
+
+    @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+    protected MastershipService masterService;
+
+    @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+    protected NetworkConfigRegistry netCfgService;
+
+    @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+    protected CoreService coreService;
+
+    private static final String PROP_PROBE_RATE = "probeRate";
+    private static final int DEFAULT_PROBE_RATE = 3000;
+    @Property(name = PROP_PROBE_RATE, intValue = DEFAULT_PROBE_RATE,
+            label = "LLDP and BDDP probe rate specified in millis")
+    private int probeRate = DEFAULT_PROBE_RATE;
+
+    // Device link discovery helpers.
+    protected final Map<DeviceId, LinkDiscovery> discoverers = new ConcurrentHashMap<>();
+
+    private final DiscoveryContext context = new InternalDiscoveryContext();
+
+    private LinkProviderService providerService;
+
+    private static final String PROVIDER_NAME =
+            "org.onosproject.provider.netcfglinks";
+    private final Logger log = LoggerFactory.getLogger(getClass());
+
+    private ApplicationId appId;
+    private final InternalPacketProcessor packetProcessor = new InternalPacketProcessor();
+    private final InternalDeviceListener deviceListener = new InternalDeviceListener();
+    private final InternalConfigListener cfgListener = new InternalConfigListener();
+
+    private Set<LinkKey> configuredLinks = new HashSet<>();
+
+    public NetworkConfigLinksProvider() {
+        super(new ProviderId("lldp", PROVIDER_NAME));
+    }
+
+    private void createLinks() {
+        netCfgService.getSubjects(LinkKey.class)
+                .forEach(linkKey -> configuredLinks.add(linkKey));
+    }
+
+    @Activate
+    protected void activate() {
+        log.info("Activated");
+        appId = coreService.registerApplication(PROVIDER_NAME);
+        packetService.addProcessor(packetProcessor, PacketProcessor.advisor(0));
+        providerService = providerRegistry.register(this);
+        deviceService.addListener(deviceListener);
+        netCfgService.addListener(cfgListener);
+        requestIntercepts();
+        loadDevices();
+        createLinks();
+    }
+
+    @Deactivate
+    protected void deactivate() {
+        withdrawIntercepts();
+        providerRegistry.unregister(this);
+        disable();
+        log.info("Deactivated");
+    }
+
+    /**
+     * Loads available devices and registers their ports to be probed.
+     */
+    private void loadDevices() {
+        deviceService.getAvailableDevices()
+                .forEach(d -> updateDevice(d)
+                        .ifPresent(ld -> updatePorts(ld, d.id())));
+    }
+
+    private Optional<LinkDiscovery> updateDevice(Device device) {
+        if (device == null) {
+            return Optional.empty();
+        }
+
+        LinkDiscovery ld = discoverers.computeIfAbsent(device.id(),
+                                                       did -> new LinkDiscovery(device, context));
+        if (ld.isStopped()) {
+            ld.start();
+        }
+        return Optional.of(ld);
+    }
+
+    /**
+     * Updates ports of the specified device to the specified discovery helper.
+     */
+    private void updatePorts(LinkDiscovery discoverer, DeviceId deviceId) {
+        deviceService.getPorts(deviceId).forEach(p -> updatePort(discoverer, p));
+    }
+
+
+    private void updatePort(LinkDiscovery discoverer, Port port) {
+        if (port == null) {
+            return;
+        }
+        if (port.number().isLogical()) {
+            // silently ignore logical ports
+            return;
+        }
+
+        discoverer.addPort(port);
+    }
+
+    /**
+     * Disables link discovery processing.
+     */
+    private void disable() {
+
+        providerRegistry.unregister(this);
+        discoverers.values().forEach(LinkDiscovery::stop);
+        discoverers.clear();
+
+        providerService = null;
+    }
+
+    /**
+     * Provides processing context for the device link discovery helpers.
+     */
+    private class InternalDiscoveryContext implements DiscoveryContext {
+        @Override
+        public MastershipService mastershipService() {
+            return masterService;
+        }
+
+        @Override
+        public LinkProviderService providerService() {
+            return providerService;
+        }
+
+        @Override
+        public PacketService packetService() {
+            return packetService;
+        }
+
+        @Override
+        public long probeRate() {
+            return probeRate;
+        }
+
+        @Override
+        public boolean useBddp() {
+            return true;
+        }
+
+        @Override
+        public void touchLink(LinkKey key) {
+            //linkTimes.put(key, System.currentTimeMillis());
+        }
+    }
+
+    LinkKey extractLinkKey(PacketContext packetContext) {
+        Ethernet eth = packetContext.inPacket().parsed();
+        if (eth == null) {
+            return null;
+        }
+
+        ONOSLLDP onoslldp = ONOSLLDP.parseONOSLLDP(eth);
+        if (onoslldp != null) {
+            PortNumber srcPort = portNumber(onoslldp.getPort());
+            PortNumber dstPort = packetContext.inPacket().receivedFrom().port();
+            DeviceId srcDeviceId = DeviceId.deviceId(onoslldp.getDeviceString());
+            DeviceId dstDeviceId = packetContext.inPacket().receivedFrom().deviceId();
+
+            ConnectPoint src = new ConnectPoint(srcDeviceId, srcPort);
+            ConnectPoint dst = new ConnectPoint(dstDeviceId, dstPort);
+            return LinkKey.linkKey(src, dst);
+        }
+        return null;
+    }
+
+    /**
+     * Processes incoming packets.
+     */
+    private class InternalPacketProcessor implements PacketProcessor {
+        @Override
+        public void process(PacketContext context) {
+            if (context == null || context.isHandled()) {
+                return;
+            }
+
+            Ethernet eth = context.inPacket().parsed();
+            if (eth == null || (eth.getEtherType() != TYPE_LLDP && eth.getEtherType() != TYPE_BSN)) {
+                return;
+            }
+
+            InboundPacket inPacket = context.inPacket();
+            LinkKey linkKey = extractLinkKey(context);
+            if (linkKey != null) {
+                if (configuredLinks.contains(linkKey)) {
+                    log.debug("Found configured link {}", linkKey);
+                    LinkDiscovery ld = discoverers.get(inPacket.receivedFrom().deviceId());
+                    if (ld == null) {
+                        return;
+                    }
+                    if (ld.handleLldp(context)) {
+                        context.block();
+                    }
+                } else {
+                    log.debug("Found link that was not in the configuration {}", linkKey);
+                    providerService.linkDetected(
+                            new DefaultLinkDescription(linkKey.src(),
+                                                       linkKey.dst(),
+                                                       Link.Type.DIRECT,
+                                                       DefaultLinkDescription.NOT_EXPECTED,
+                                                       DefaultAnnotations.EMPTY));
+                }
+            }
+        }
+    }
+
+    /**
+     * Requests packet intercepts.
+     */
+    private void requestIntercepts() {
+        TrafficSelector.Builder selector = DefaultTrafficSelector.builder();
+        selector.matchEthType(TYPE_LLDP);
+        packetService.requestPackets(selector.build(), PacketPriority.CONTROL,
+                                     appId, Optional.empty());
+
+        selector.matchEthType(TYPE_BSN);
+
+        packetService.requestPackets(selector.build(), PacketPriority.CONTROL,
+                                     appId, Optional.empty());
+
+    }
+
+    /**
+     * Withdraws packet intercepts.
+     */
+    private void withdrawIntercepts() {
+        TrafficSelector.Builder selector = DefaultTrafficSelector.builder();
+        selector.matchEthType(TYPE_LLDP);
+        packetService.cancelPackets(selector.build(), PacketPriority.CONTROL,
+                                    appId, Optional.empty());
+        selector.matchEthType(TYPE_BSN);
+        packetService.cancelPackets(selector.build(), PacketPriority.CONTROL,
+                                    appId, Optional.empty());
+    }
+
+    /**
+     * Processes device events.
+     */
+    private class InternalDeviceListener implements DeviceListener {
+        @Override
+        public void event(DeviceEvent event) {
+            if (event.type() == DeviceEvent.Type.PORT_STATS_UPDATED) {
+                return;
+            }
+            Device device = event.subject();
+            Port port = event.port();
+            if (device == null) {
+                log.error("Device is null.");
+                return;
+            }
+            log.trace("{} {} {}", event.type(), event.subject(), event);
+            final DeviceId deviceId = device.id();
+            switch (event.type()) {
+                case DEVICE_ADDED:
+                case DEVICE_UPDATED:
+                    updateDevice(device).ifPresent(ld -> updatePorts(ld, deviceId));
+                    break;
+                case PORT_ADDED:
+                case PORT_UPDATED:
+                    if (port.isEnabled()) {
+                        updateDevice(device).ifPresent(ld -> updatePort(ld, port));
+                    } else {
+                        log.debug("Port down {}", port);
+                        //removePort(port);
+                        providerService.linksVanished(new ConnectPoint(port.element().id(),
+                                                                       port.number()));
+                    }
+                    break;
+                case PORT_REMOVED:
+                    log.debug("Port removed {}", port);
+                    //removePort(port);
+                    providerService.linksVanished(new ConnectPoint(port.element().id(),
+                                                                   port.number()));
+                    break;
+                case DEVICE_REMOVED:
+                case DEVICE_SUSPENDED:
+                    log.debug("Device removed {}", deviceId);
+                    //removeDevice(deviceId);
+                    providerService.linksVanished(deviceId);
+                    break;
+                case DEVICE_AVAILABILITY_CHANGED:
+                    if (deviceService.isAvailable(deviceId)) {
+                        log.debug("Device up {}", deviceId);
+                        updateDevice(device).ifPresent(ld -> updatePorts(ld, deviceId));
+                    } else {
+                        log.debug("Device down {}", deviceId);
+                        //removeDevice(deviceId);
+                        providerService.linksVanished(deviceId);
+                    }
+                    break;
+                case PORT_STATS_UPDATED:
+                    break;
+                default:
+                    log.debug("Unknown event {}", event);
+            }
+        }
+    }
+
+    private class InternalConfigListener implements NetworkConfigListener {
+
+        private void addLink(LinkKey linkKey) {
+            configuredLinks.add(linkKey);
+        }
+
+        private void removeLink(LinkKey linkKey) {
+            DefaultLinkDescription linkDescription =
+                    new DefaultLinkDescription(linkKey.src(), linkKey.dst(),
+                                               Link.Type.DIRECT);
+            configuredLinks.remove(linkKey);
+            providerService.linkVanished(linkDescription);
+        }
+
+        @Override
+        public void event(NetworkConfigEvent event) {
+
+            if (event.configClass().equals(BasicLinkConfig.class)) {
+                log.info("net config event of type {} for basic link {}",
+                         event.type(), event.subject());
+                LinkKey linkKey = (LinkKey) event.subject();
+                if (event.type() == NetworkConfigEvent.Type.CONFIG_ADDED) {
+                    addLink(linkKey);
+                } else if (event.type() == NetworkConfigEvent.Type.CONFIG_REMOVED) {
+                    removeLink(linkKey);
+                }
+            }
+            log.info("Reconfigured");
+        }
+    }
+
+}
diff --git a/providers/netcfglinks/src/main/java/org/onosproject/provider/netcfglinks/package-info.java b/providers/netcfglinks/src/main/java/org/onosproject/provider/netcfglinks/package-info.java
new file mode 100644
index 0000000..1701b0a
--- /dev/null
+++ b/providers/netcfglinks/src/main/java/org/onosproject/provider/netcfglinks/package-info.java
@@ -0,0 +1,21 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * Provider to pre-discover links and devices based on a specified network
+ * config.
+ */
+package org.onosproject.provider.netcfglinks;
diff --git a/providers/pom.xml b/providers/pom.xml
index f72090b..08364bc 100644
--- a/providers/pom.xml
+++ b/providers/pom.xml
@@ -43,6 +43,7 @@
         <module>bgp</module>
         <module>snmp</module>
         <module>rest</module>
+        <module>netcfglinks</module>
     </modules>
 
     <dependencies>
diff --git a/utils/misc/src/main/java/org/onlab/packet/ONOSLLDP.java b/utils/misc/src/main/java/org/onlab/packet/ONOSLLDP.java
index 78a6ad3..f025521 100644
--- a/utils/misc/src/main/java/org/onlab/packet/ONOSLLDP.java
+++ b/utils/misc/src/main/java/org/onlab/packet/ONOSLLDP.java
@@ -71,7 +71,7 @@
     private final byte[] ttlValue = new byte[] {0, 0x78};
 
     // Only needs to be accessed from LinkProbeFactory.
-    protected ONOSLLDP(byte ... subtype) {
+    public ONOSLLDP(byte ... subtype) {
         super();
         for (byte st : subtype) {
             opttlvs.put(st, new LLDPOrganizationalTLV());
diff --git a/web/gui/src/main/java/org/onosproject/ui/impl/TopologyViewMessageHandlerBase.java b/web/gui/src/main/java/org/onosproject/ui/impl/TopologyViewMessageHandlerBase.java
index e2d9214..49d5155 100644
--- a/web/gui/src/main/java/org/onosproject/ui/impl/TopologyViewMessageHandlerBase.java
+++ b/web/gui/src/main/java/org/onosproject/ui/impl/TopologyViewMessageHandlerBase.java
@@ -278,6 +278,7 @@
         ObjectNode payload = objectNode()
                 .put("id", compactLinkString(link))
                 .put("type", link.type().toString().toLowerCase())
+                .put("expected", link.isExpected())
                 .put("online", link.state() == Link.State.ACTIVE)
                 .put("linkWidth", 1.2)
                 .put("src", link.src().deviceId().toString())
diff --git a/web/gui/src/main/webapp/app/view/topo/topo.css b/web/gui/src/main/webapp/app/view/topo/topo.css
index 69f500f..1270979 100644
--- a/web/gui/src/main/webapp/app/view/topo/topo.css
+++ b/web/gui/src/main/webapp/app/view/topo/topo.css
@@ -526,6 +526,12 @@
     opacity: .5;
     stroke-dasharray: 8 4;
 }
+/* FIXME: Review for not-permitted links */
+#ov-topo svg .link.not-permitted {
+    stroke: rgb(255,0,0);
+    stroke-width: 5.0;
+    stroke-dasharray: 8 4;
+}
 
 #ov-topo svg .link.secondary {
     stroke-width: 3px;
diff --git a/web/gui/src/main/webapp/app/view/topo/topoForce.js b/web/gui/src/main/webapp/app/view/topo/topoForce.js
index 3c68f3e..21137af 100644
--- a/web/gui/src/main/webapp/app/view/topo/topoForce.js
+++ b/web/gui/src/main/webapp/app/view/topo/topoForce.js
@@ -323,7 +323,8 @@
             .domain([1, 12])
             .range([widthRatio, 12 * widthRatio])
             .clamp(true),
-        allLinkTypes = 'direct indirect optical tunnel';
+        allLinkTypes = 'direct indirect optical tunnel',
+        allLinkSubTypes = 'inactive not-permitted';
 
     function restyleLinkElement(ldata, immediate) {
         // this fn's job is to look at raw links and decide what svg classes
@@ -333,6 +334,7 @@
             type = ldata.type(),
             lw = ldata.linkWidth(),
             online = ldata.online(),
+            modeCls = ldata.expected() ? 'inactive' : 'not-permitted',
             delay = immediate ? 0 : 1000;
 
         // FIXME: understand why el is sometimes undefined on addLink events...
@@ -343,7 +345,8 @@
         // a more efficient way to fix it.
         if (el && !el.empty()) {
             el.classed('link', true);
-            el.classed('inactive', !online);
+            el.classed(allLinkSubTypes, false);
+            el.classed(modeCls, !online);
             el.classed(allLinkTypes, false);
             if (type) {
                 el.classed(type, true);
diff --git a/web/gui/src/main/webapp/app/view/topo/topoModel.js b/web/gui/src/main/webapp/app/view/topo/topoModel.js
index 282a066..ed9eeb1 100644
--- a/web/gui/src/main/webapp/app/view/topo/topoModel.js
+++ b/web/gui/src/main/webapp/app/view/topo/topoModel.js
@@ -198,6 +198,11 @@
                     t = lnk.fromTarget;
                 return (s && s.type) || (t && t.type) || defaultLinkType;
             },
+            expected: function () {
+                var s = lnk.fromSource,
+                    t = lnk.fromTarget;
+                return (s && s.expected) && (t && t.expected);
+            },
             online: function () {
                 var s = lnk.fromSource,
                     t = lnk.fromTarget,
diff --git a/web/gui/src/main/webapp/app/view/topo/topoPanel.js b/web/gui/src/main/webapp/app/view/topo/topoPanel.js
index af2c4bc..37faf29 100644
--- a/web/gui/src/main/webapp/app/view/topo/topoPanel.js
+++ b/web/gui/src/main/webapp/app/view/topo/topoPanel.js
@@ -301,8 +301,12 @@
         return linkTypePres[d.type()] || d.type();
     }
 
+    function linkExpected(d) {
+        return d.expected();
+    }
+
     var coreOrder = [
-            'Type', '-',
+            'Type', 'Expected', '-',
             'A_type', 'A_id', 'A_label', 'A_port', '-',
             'B_type', 'B_id', 'B_label', 'B_port', '-'
         ],
@@ -332,6 +336,7 @@
             propOrder: order,
             props: {
                 Type: linkType(data),
+                Expected: linkExpected(data),
 
                 A_type: data.source.class,
                 A_id: data.source.id,