VOL-1187 Disable performance metrics collection if unable to create performance management ME.  Also update supported ME in brcm adapter.

Change-Id: I122bac51e30fb779d59da560573009d2c7f75b3d
diff --git a/voltha/adapters/brcm_openomci_onu/omci/brcm_capabilities_task.py b/voltha/adapters/brcm_openomci_onu/omci/brcm_capabilities_task.py
index 1c6524a..6bf5b93 100644
--- a/voltha/adapters/brcm_openomci_onu/omci/brcm_capabilities_task.py
+++ b/voltha/adapters/brcm_openomci_onu/omci/brcm_capabilities_task.py
@@ -65,13 +65,11 @@
 
         # TODO: figure out why broadcom wont answer for ME 287 to get this.  otherwise manually fill in
         me_1287800f1 = [
-            2, 5, 6, 7, 11, 24, 45, 46, 47, 48, 49, 50, 51, 52, 79, 84, 89, 130,
-            131, 133, 134, 135, 136, 137, 148, 157, 158, 159, 171, 256, 257, 262,
-            263, 264, 266, 268, 272, 273, 274, 277, 278, 279, 280, 281, 297, 298,
-            299, 300, 301, 302, 303, 304, 305, 306, 307, 308, 309, 310, 311, 312,
-            329, 330, 332, 334, 336, 340, 341, 342, 343, 348, 425, 426, 65300,
-            65400, 65401, 65402, 65403, 65404, 65406, 65407, 65408, 65409, 65410,
-            65411, 65412, 65413, 65414, 65420, 65421, 65422, 65423, 65424
+            2, 5, 6, 7, 11, 24, 45, 46, 47, 48, 49, 50, 51, 52, 78, 79, 84, 89, 130,
+            131, 133, 134, 135, 136, 137, 148, 157, 158, 159, 162, 163, 164, 171, 240,
+            241, 242, 256, 257, 262, 263, 264, 266, 268, 272, 273, 274, 276, 277, 278,
+            279, 280, 281, 287, 296, 297, 298, 307, 308, 309, 310, 311, 312, 321, 322,
+            329, 330, 332, 334, 336, 340, 341, 342, 343, 347, 348, 425, 426
         ]
         return frozenset(list(me_1287800f1))
 
diff --git a/voltha/extensions/omci/state_machines/performance_intervals.py b/voltha/extensions/omci/state_machines/performance_intervals.py
index 1f58dc8..e9c70c5 100644
--- a/voltha/extensions/omci/state_machines/performance_intervals.py
+++ b/voltha/extensions/omci/state_machines/performance_intervals.py
@@ -84,6 +84,7 @@
     DEFAULT_TICK_DELAY = 15          # Seconds between checks for collection tick
     DEFAULT_INTERVAL_SKEW = 10 * 60  # Seconds to skew past interval boundary
     DEFAULT_COLLECT_ATTEMPTS = 3     # Maximum number of collection fetch attempts
+    DEFAULT_CREATE_ATTEMPTS = 5      # Maximum number of attempts to create a PM Managed Entities
 
     def __init__(self, agent, device_id, tasks,
                  advertise_events=False,
@@ -93,7 +94,8 @@
                  timeout_delay=DEFAULT_RETRY,
                  tick_delay=DEFAULT_TICK_DELAY,
                  interval_skew=DEFAULT_INTERVAL_SKEW,
-                 collect_attempts=DEFAULT_COLLECT_ATTEMPTS):
+                 collect_attempts=DEFAULT_COLLECT_ATTEMPTS,
+                 create_attempts=DEFAULT_CREATE_ATTEMPTS):
         """
         Class initialization
 
@@ -109,6 +111,7 @@
         :param interval_skew: (int/float) Seconds to randomly skew the next interval
                               collection to spread out requests for PM intervals
         :param collect_attempts: (int) Max requests for a single PM interval before fail
+        :param create_attempts: (int) Max attempts to create PM Managed entities before stopping state machine
         """
         self.log = structlog.get_logger(device_id=device_id)
 
@@ -120,6 +123,7 @@
         self._tick_delay = tick_delay
         self._interval_skew = interval_skew
         self._collect_attempts = collect_attempts
+        self._create_attempts = create_attempts
 
         self._sync_time_task = tasks['sync-time']
         self._get_interval_task = tasks['collect-data']
@@ -150,6 +154,7 @@
         self._delete_me_deferred = None
         self._next_interval = None
         self._enet_entity_id = IndexPool(1024, 1)
+        self._add_pm_me_retry = 0
 
         # (Class ID, Instance ID) -> Collect attempts remaining
         self._pm_me_collect_retries = dict()
@@ -505,10 +510,15 @@
         def failure(reason):
             self.log.info('create-me-failure', reason=reason)
             self._current_task = None
-            for pm, me in mes.items():
-                self._add_pm_me[pm] = me
-
-            self._deferred = reactor.callLater(self._timeout_delay, self.failure)
+            if self._add_pm_me_retry <= self._create_attempts:
+              for pm, me in mes.items():
+                  self._add_pm_me[pm] = me
+              self._add_pm_me_retry += 1
+              self._deferred = reactor.callLater(self._timeout_delay, self.failure)
+            else:
+              # we cant seem to create any collection me, no point in doing anything
+              self.log.warn('unable-to-create-pm-me-disabling-collection', reason=reason)
+              self._deferred = reactor.callLater(self._timeout_delay, self.stop)
 
         self._current_task = self._create_pm_task(self._agent, self._device_id, mes)
         self._task_deferred = self._device.task_runner.queue_task(self._current_task)