Make the netconf notification stream customisable

Change-Id: I0e51861b7f8cb4961a47e88f64a493106e2c7a8a
diff --git a/drivers/polatis/netconf/src/main/java/org/onosproject/drivers/polatis/netconf/PolatisDeviceDescription.java b/drivers/polatis/netconf/src/main/java/org/onosproject/drivers/polatis/netconf/PolatisDeviceDescription.java
index 21519ef..ad77648 100644
--- a/drivers/polatis/netconf/src/main/java/org/onosproject/drivers/polatis/netconf/PolatisDeviceDescription.java
+++ b/drivers/polatis/netconf/src/main/java/org/onosproject/drivers/polatis/netconf/PolatisDeviceDescription.java
@@ -45,9 +45,10 @@
 import static com.google.common.base.Preconditions.checkNotNull;
 import static org.onosproject.net.Device.Type.FIBER_SWITCH;
 
-import static org.onosproject.drivers.polatis.netconf.PolatisNetconfUtility.netconfGet;
 import static org.onosproject.drivers.polatis.netconf.PolatisNetconfUtility.configAt;
 import static org.onosproject.drivers.polatis.netconf.PolatisNetconfUtility.configsAt;
+import static org.onosproject.drivers.polatis.netconf.PolatisNetconfUtility.netconfGet;
+import static org.onosproject.drivers.polatis.netconf.PolatisNetconfUtility.subscribe;
 import static org.onosproject.drivers.polatis.netconf.PolatisNetconfUtility.xmlOpen;
 import static org.onosproject.drivers.polatis.netconf.PolatisNetconfUtility.xmlClose;
 import static org.onosproject.drivers.polatis.netconf.PolatisNetconfUtility.xmlEmpty;
@@ -102,6 +103,7 @@
                     new ChassisId());
         }
         String reply = netconfGet(handler(), getProductInformationFilter());
+        subscribe(handler());
         HierarchicalConfiguration cfg = configAt(reply, KEY_DATA_PRODINF);
         return new DefaultDeviceDescription(dev.id().uri(), FIBER_SWITCH,
                 cfg.getString(KEY_MANUFACTURER), cfg.getString(KEY_HWVERSION),
diff --git a/drivers/polatis/netconf/src/main/java/org/onosproject/drivers/polatis/netconf/PolatisNetconfUtility.java b/drivers/polatis/netconf/src/main/java/org/onosproject/drivers/polatis/netconf/PolatisNetconfUtility.java
index 1516912..ee1fe39 100644
--- a/drivers/polatis/netconf/src/main/java/org/onosproject/drivers/polatis/netconf/PolatisNetconfUtility.java
+++ b/drivers/polatis/netconf/src/main/java/org/onosproject/drivers/polatis/netconf/PolatisNetconfUtility.java
@@ -220,6 +220,23 @@
     }
 
     /**
+     * Subscribes for notifications.
+     *
+     * @param handler parent driver handler
+     * @return true on success, false otherwise
+     */
+    public static boolean subscribe(DriverHandler handler) {
+        NetconfSession session = getNetconfSession(handler);
+        try {
+            session.startSubscription();
+        } catch (NetconfException e) {
+            log.error("Failed to subscribe for notifications.");
+            return false;
+        }
+        return true;
+    }
+
+    /**
      * Returns the NETCONF session of the device.
      *
      * @return session
diff --git a/drivers/polatis/netconf/src/main/resources/polatis-drivers.xml b/drivers/polatis/netconf/src/main/resources/polatis-drivers.xml
index 88a9844..0c36cbc 100644
--- a/drivers/polatis/netconf/src/main/resources/polatis-drivers.xml
+++ b/drivers/polatis/netconf/src/main/resources/polatis-drivers.xml
@@ -28,5 +28,6 @@
         <behaviour api="org.onosproject.incubator.net.faultmanagement.alarm.AlarmConsumer"
                    impl="org.onosproject.drivers.polatis.netconf.PolatisAlarmConsumer"/>
         <property name="uiType">policon</property>
+        <property name="notificationStream">Polatis</property>
     </driver>
 </drivers>
diff --git a/protocols/netconf/ctl/src/main/java/org/onosproject/netconf/ctl/impl/NetconfSessionMinaImpl.java b/protocols/netconf/ctl/src/main/java/org/onosproject/netconf/ctl/impl/NetconfSessionMinaImpl.java
index 596cb1a..261adea 100644
--- a/protocols/netconf/ctl/src/main/java/org/onosproject/netconf/ctl/impl/NetconfSessionMinaImpl.java
+++ b/protocols/netconf/ctl/src/main/java/org/onosproject/netconf/ctl/impl/NetconfSessionMinaImpl.java
@@ -119,6 +119,7 @@
     private static final String NETCONF_10_CAPABILITY = "urn:ietf:params:netconf:base:1.0";
     private static final String NETCONF_11_CAPABILITY = "urn:ietf:params:netconf:base:1.1";
     private static final String NETCONF_CLIENT_CAPABILITY = "netconfClientCapability";
+    private static final String NOTIFICATION_STREAM = "notificationStream";
 
     private static ServiceDirectory directory = new DefaultServiceDirectory();
 
@@ -351,6 +352,16 @@
         subscriptionbuffer.append("<rpc xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n");
         subscriptionbuffer.append("  <create-subscription\n");
         subscriptionbuffer.append("xmlns=\"urn:ietf:params:xml:ns:netconf:notification:1.0\">\n");
+        DriverService driverService = directory.get(DriverService.class);
+        Driver driver = driverService.getDriver(deviceInfo.getDeviceId());
+        if (driver != null) {
+            String stream = driver.getProperty(NOTIFICATION_STREAM);
+            if (stream != null) {
+                subscriptionbuffer.append("    <stream>");
+                subscriptionbuffer.append(stream);
+                subscriptionbuffer.append("</stream>\n");
+            }
+        }
         // FIXME Only subtree filtering supported at the moment.
         if (filterSchema != null) {
             subscriptionbuffer.append("    ");