VOL-1190 Filter out unreachable device before reporting to ONOS

calling ListReachableLogicalDevices instead of ListLogicalDevices. The filtering is done in the voltha core

Change-Id: I517f963423b83c49bce1469ebb016af1eb72a4a9
diff --git a/ofagent/connection_mgr.py b/ofagent/connection_mgr.py
index 2496dd5..f90c9f7 100644
--- a/ofagent/connection_mgr.py
+++ b/ofagent/connection_mgr.py
@@ -201,14 +201,17 @@
         log.debug('stop-monitor-vcore-grpc-channel')
 
     @inlineCallbacks
-    def get_list_of_logical_devices_from_voltha(self):
+    def get_list_of_reachable_logical_devices_from_voltha(self):
 
         while self.running:
             log.info('retrieve-logical-device-list')
             try:
-                devices = yield self.grpc_client.list_logical_devices()
+                devices = yield \
+                    self.grpc_client.list_reachable_logical_devices()
+
                 for device in devices:
-                    log.info("logical-device-entry", id=device.id, datapath_id=device.datapath_id)
+                    log.info("reachable-logical-device-entry", id=device.id,
+                             datapath_id=device.datapath_id)
 
                 returnValue(devices)
 
@@ -292,10 +295,11 @@
                 if self.channel is not None and self.grpc_client is not None and \
                                 self.subscription is not None:
                     # get current list from Voltha
-                    devices = yield self.get_list_of_logical_devices_from_voltha()
+                    reachable_devices = yield \
+                        self.get_list_of_reachable_logical_devices_from_voltha()
 
                     # update agent list and mapping tables as needed
-                    self.refresh_agent_connections(devices)
+                    self.refresh_agent_connections(reachable_devices)
                 else:
                     log.info('vcore-communication-unavailable')
 
diff --git a/ofagent/grpc_client.py b/ofagent/grpc_client.py
index 56af949..ab9417b 100644
--- a/ofagent/grpc_client.py
+++ b/ofagent/grpc_client.py
@@ -241,6 +241,13 @@
         returnValue(res.items)
 
     @inlineCallbacks
+    def list_reachable_logical_devices(self):
+        res = yield threads.deferToThread(
+            self.local_stub.ListReachableLogicalDevices, empty_pb2.Empty(),
+            timeout=self.grpc_timeout)
+        returnValue(res.items)
+
+    @inlineCallbacks
     def subscribe(self, subscriber):
         res = yield threads.deferToThread(
             self.local_stub.Subscribe, subscriber, timeout=self.grpc_timeout)
diff --git a/voltha/core/global_handler.py b/voltha/core/global_handler.py
index 098e145..27ccd41 100644
--- a/voltha/core/global_handler.py
+++ b/voltha/core/global_handler.py
@@ -169,6 +169,18 @@
 
     @twisted_async
     @inlineCallbacks
+    def ListReachableLogicalDevices(self, request, context):
+        log.debug('grpc-request', request=request)
+        response = yield self.dispatcher.dispatch(
+                'ListReachableLogicalDevices',
+                Empty(),
+                context,
+                broadcast=True)
+        log.debug('grpc-response', response=response)
+        returnValue(response)
+
+    @twisted_async
+    @inlineCallbacks
     def GetLogicalDevice(self, request, context):
         log.debug('grpc-request', request=request)
 
diff --git a/voltha/core/local_handler.py b/voltha/core/local_handler.py
index 2a2df05..35a2395 100644
--- a/voltha/core/local_handler.py
+++ b/voltha/core/local_handler.py
@@ -33,7 +33,7 @@
     DeviceTypes, DeviceGroups, DeviceGroup, AdminState, OperStatus, ChangeEvent, \
     AlarmFilter, AlarmFilters, SelfTestResponse, OfAgentSubscriber
 from voltha.protos.device_pb2 import PmConfigs, Images, ImageDownload, ImageDownloads
-from voltha.protos.common_pb2 import OperationResp
+from voltha.protos.common_pb2 import OperationResp, ConnectStatus
 from voltha.protos.bbf_fiber_base_pb2 import AllMulticastDistributionSetData, AllMulticastGemportsConfigData
 from voltha.registry import registry
 from voltha.protos.omci_mib_db_pb2 import MibDeviceData
@@ -140,6 +140,21 @@
         return LogicalDevices(items=items)
 
     @twisted_async
+    def ListReachableLogicalDevices(self, request, context):
+        log.debug('grpc-request', request=request)
+        logical_devices = self.root.get('/logical_devices')
+        reachable_logical_devices = []
+
+        for logical_device in logical_devices:
+            device = self.root.get('/devices/{}'.format(
+                logical_device.root_device_id))
+            if device is not None and device.connect_status == \
+                    ConnectStatus.REACHABLE:
+                reachable_logical_devices.append(logical_device)
+
+        return LogicalDevices(items=reachable_logical_devices)
+
+    @twisted_async
     def GetLogicalDevice(self, request, context):
         log.debug('grpc-request', request=request)
 
diff --git a/voltha/protos/voltha.proto b/voltha/protos/voltha.proto
index 4736973..a7cc99d 100644
--- a/voltha/protos/voltha.proto
+++ b/voltha/protos/voltha.proto
@@ -284,6 +284,14 @@
         option (voltha.yang_xml_tag).xml_tag = 'logical_devices';
     }
 
+    // List all reachable logical devices managed by the Voltha cluster
+    rpc ListReachableLogicalDevices(google.protobuf.Empty) returns
+    (LogicalDevices) {
+        option (google.api.http) = {
+            get: "/api/v1/reachable_logical_devices"
+        };
+    }
+
     // Get additional information on a given logical device
     rpc GetLogicalDevice(ID) returns(LogicalDevice) {
         option (google.api.http) = {
@@ -1021,6 +1029,14 @@
         option (voltha.yang_xml_tag).xml_tag = 'logical_devices';
     }
 
+    // List all reachable logical devices managed by this Voltha instance
+    rpc ListReachableLogicalDevices(google.protobuf.Empty) returns
+    (LogicalDevices) {
+        option (google.api.http) = {
+            get: "/api/v1/local/reachable_logical_devices"
+        };
+    }
+
     // Get additional information on given logical device
     rpc GetLogicalDevice(ID) returns(LogicalDevice) {
         option (google.api.http) = {