Add support for configuring OLT access device data with uplink/vlan information.
This is required when running on target OLT switches where we have to configure
the uplink/vlan information with the device ids for ONOS to program IGMP flows correctly.
Add methods for getting devices and flows from ONOS rest interface.
Change relevant OnosCtrl methods to class methods that are applicable for global onos configurations.
diff --git a/src/test/dhcp/dhcpTest.py b/src/test/dhcp/dhcpTest.py
index 370861f..debb2c3 100644
--- a/src/test/dhcp/dhcpTest.py
+++ b/src/test/dhcp/dhcpTest.py
@@ -39,7 +39,7 @@
         self.onos_ctrl.deactivate()
 
     def onos_load_config(self, config):
-        status, code = self.onos_ctrl.config(config)
+        status, code = OnosCtrl.config(config)
         if status is False:
             log.info('JSON request returned status %d' %code)
             assert_equal(status, True)
diff --git a/src/test/igmp/igmpTest.py b/src/test/igmp/igmpTest.py
index 7b3227b..9a6bf09 100644
--- a/src/test/igmp/igmpTest.py
+++ b/src/test/igmp/igmpTest.py
@@ -71,7 +71,7 @@
         self.onos_ctrl.deactivate()
 
     def onos_load_config(self, config):
-        status, code = self.onos_ctrl.config(config)
+        status, code = OnosCtrl.config(config)
         if status is False:
             log.info('JSON request returned status %d' %code)
             assert_equal(status, True)
diff --git a/src/test/setup/olt_config.json b/src/test/setup/olt_config.json
index 83e2b06..8aab363 100644
--- a/src/test/setup/olt_config.json
+++ b/src/test/setup/olt_config.json
@@ -1,2 +1,2 @@
-{ "olt" : false , "ports" : { "tx" : "veth2", "rx" : "veth0" } }
+{ "olt" : false , "ports" : { "tx" : "veth2", "rx" : "veth0" }, "uplink" : 2, "vlan" : 0 }
   
diff --git a/src/test/subscriber/subscriberTest.py b/src/test/subscriber/subscriberTest.py
index fca9335..ac01950 100644
--- a/src/test/subscriber/subscriberTest.py
+++ b/src/test/subscriber/subscriberTest.py
@@ -142,7 +142,7 @@
 class subscriber_exchange(unittest.TestCase):
 
       apps = [ 'org.onosproject.aaa', 'org.onosproject.dhcp' ]
-
+      olt_apps = [ 'org.onosproject.igmp', 'org.onosproject.cordmcast' ]
       dhcp_server_config = {
         "ip": "10.1.11.50",
         "mac": "ca:fe:ca:fe:ca:fe",
@@ -167,11 +167,11 @@
                 self.port_map = g_subscriber_port_map
           else:
                 log.info('Using OLT Port configuration for test setup')
-          for app in self.apps:
-              onos_ctrl = OnosCtrl(app)
-              status, _ = onos_ctrl.activate()
-              assert_equal(status, True)
-              time.sleep(2)
+                log.info('Configuring CORD OLT access device information')
+                OnosCtrl.cord_olt_config(self.olt.olt_device_data())
+                self.activate_apps(self.olt_apps)
+
+          self.activate_apps(self.apps)
 
       def teardown(self):
           '''Deactivate the dhcp app'''
@@ -179,6 +179,13 @@
               onos_ctrl = OnosCtrl(app)
               onos_ctrl.deactivate()
 
+      def activate_apps(self, apps):
+            for app in self.olt_apps:
+                  onos_ctrl = OnosCtrl(app)
+                  status, _ = onos_ctrl.activate()
+                  assert_equal(status, True)
+                  time.sleep(2)
+
       def onos_aaa_load(self):
             if self.aaa_loaded:
                   return
@@ -199,8 +206,7 @@
           self.onos_load_config('org.onosproject.dhcp', dhcp_dict)
 
       def onos_load_config(self, app, config):
-          onos_ctrl = OnosCtrl(app)
-          status, code = onos_ctrl.config(config)
+          status, code = OnosCtrl.config(config)
           if status is False:
              log.info('JSON config request for app %s returned status %d' %(app, code))
              assert_equal(status, True)
diff --git a/src/test/tls/tlsAuthTest.py b/src/test/tls/tlsAuthTest.py
index 5a30c49..309b1e4 100644
--- a/src/test/tls/tlsAuthTest.py
+++ b/src/test/tls/tlsAuthTest.py
@@ -23,7 +23,7 @@
             self.onos_load_config(aaa_dict)
 
       def onos_load_config(self, config):
-            status, code = self.onos_ctrl.config(config)
+            status, code = OnosCtrl.config(config)
             if status is False:
                   log.info('Configure request for AAA returned status %d' %code)
                   assert_equal(status, True)
diff --git a/src/test/utils/Channels.py b/src/test/utils/Channels.py
index 19e84d7..e0b11c8 100644
--- a/src/test/utils/Channels.py
+++ b/src/test/utils/Channels.py
@@ -65,7 +65,7 @@
             time.sleep(self.delay)
 
     def onos_load_config(self, config):
-        status, code = self.onos_ctrl.config(config)
+        status, code = OnosCtrl.config(config)
         if status is False:
             log.info('JSON config request returned status %d' %code)
         time.sleep(2)
diff --git a/src/test/utils/OltConfig.py b/src/test/utils/OltConfig.py
index 8fad75b..24c5410 100644
--- a/src/test/utils/OltConfig.py
+++ b/src/test/utils/OltConfig.py
@@ -30,3 +30,11 @@
             return port_map
         else:
             return None
+
+    def olt_device_data(self):
+        if self.on_olt():
+            accessDeviceDict = {}
+            accessDeviceDict['uplink'] = str(self.olt_conf['uplink'])
+            accessDeviceDict['vlan'] = str(self.olt_conf['vlan'])
+            return accessDeviceDict
+        return None
diff --git a/src/test/utils/OnosCtrl.py b/src/test/utils/OnosCtrl.py
index 043438f..bad2016 100644
--- a/src/test/utils/OnosCtrl.py
+++ b/src/test/utils/OnosCtrl.py
@@ -3,21 +3,24 @@
 import os,sys,time
 
 class OnosCtrl:
-    
+
+    auth = ('karaf', 'karaf')
+    controller = os.getenv('ONOS_CONTROLLER_IP') or 'localhost'
+    cfg_url = 'http://%s:8181/onos/v1/network/configuration/' %(controller)
+
     def __init__(self, app, controller = None):
         self.app = app
-        if controller is None:
-            self.controller = os.getenv('ONOS_CONTROLLER_IP') or 'localhost'
-        else:
+        if controller is not None:
             self.controller = controller
         self.app_url = 'http://%s:8181/onos/v1/applications/%s' %(self.controller, self.app)
         self.cfg_url = 'http://%s:8181/onos/v1/network/configuration/' %(self.controller)
         self.auth = ('karaf', 'karaf')
 
-    def config(self, config):
+    @classmethod
+    def config(cls, config):
         if config:
             json_data = json.dumps(config)
-            resp = requests.post(self.cfg_url, auth = self.auth, data = json_data)
+            resp = requests.post(cls.cfg_url, auth = cls.auth, data = json_data)
             return resp.ok, resp.status_code
         return False, 400
 
@@ -29,4 +32,39 @@
         resp = requests.delete(self.app_url + '/active', auth = self.auth)
         return resp.ok, resp.status_code
 
+    @classmethod
+    def get_devices(cls):
+        url = 'http://%s:8181/onos/v1/devices' %(cls.controller)
+        result = requests.get(url, auth = cls.auth)
+        if result.ok:
+            devices = result.json()['devices']
+            return filter(lambda d: d['available'], devices)
 
+        return None
+
+    @classmethod
+    def get_flows(cls, device_id):
+        url = 'http://%s:8181/onos/v1/flows/' %(cls.controller) + device_id
+        result = requests.get(url, auth = cls.auth)
+        if result.ok:
+            return result.json()['flows']
+        return None
+
+    @classmethod
+    def cord_olt_config(cls, olt_device_data = None):
+        '''Configures OLT data for existing devices/switches'''
+        if olt_device_data is None:
+            return
+        did_dict = {}
+        config = { 'devices' : did_dict }
+        devices = cls.get_devices()
+        if not devices:
+            return
+        device_ids = map(lambda d: d['id'], devices)
+        for did in device_ids:
+            access_device_dict = {}
+            access_device_dict['accessDevice'] = olt_device_data
+            did_dict[did] = access_device_dict
+
+        ##configure the device list with access information
+        return cls.config(config)