VOL-1453 changed adapter agent references to core_proxy

Change-Id: Ie3ae798e859d11b317b2c6629906089038e528e3
diff --git a/python/adapters/brcm_openomci_onu/brcm_openomci_onu.py b/python/adapters/brcm_openomci_onu/brcm_openomci_onu.py
index 51f3f5a..ff70e50 100644
--- a/python/adapters/brcm_openomci_onu/brcm_openomci_onu.py
+++ b/python/adapters/brcm_openomci_onu/brcm_openomci_onu.py
@@ -21,6 +21,8 @@
 """
 
 from twisted.internet import reactor, task
+from twisted.internet.defer import inlineCallbacks
+
 from zope.interface import implementer
 
 from pyvoltha.adapters.interface import IAdapterInterface
@@ -210,12 +212,13 @@
     def send_proxied_message(self, proxy_address, msg):
         log.debug('send-proxied-message', proxy_address=proxy_address, msg=msg)
 
+    @inlineCallbacks
     def receive_proxied_message(self, proxy_address, msg):
         log.debug('receive-proxied-message', proxy_address=proxy_address,
                  device_id=proxy_address.device_id, msg=hexify(msg))
         # Device_id from the proxy_address is the olt device id. We need to
         # get the onu device id using the port number in the proxy_address
-        device = self.adapter_agent. \
+        device = self.core_proxy. \
             get_child_device_with_proxy_address(proxy_address)
         if device:
             handler = self.devices_handlers[device.id]
@@ -225,13 +228,14 @@
         log.info('packet-out', logical_device_id=logical_device_id,
                  egress_port_no=egress_port_no, msg_len=len(msg))
 
+    @inlineCallbacks
     def receive_inter_adapter_message(self, msg):
         log.debug('receive_inter_adapter_message', msg=msg)
         proxy_address = msg['proxy_address']
         assert proxy_address is not None
         # Device_id from the proxy_address is the olt device id. We need to
         # get the onu device id using the port number in the proxy_address
-        device = self.adapter_agent. \
+        device = self.core_proxy. \
             get_child_device_with_proxy_address(proxy_address)
         if device:
             handler = self.devices_handlers[device.id]
diff --git a/python/adapters/brcm_openomci_onu/brcm_openomci_onu_handler.py b/python/adapters/brcm_openomci_onu/brcm_openomci_onu_handler.py
index ce74795..cd7fc62 100644
--- a/python/adapters/brcm_openomci_onu/brcm_openomci_onu_handler.py
+++ b/python/adapters/brcm_openomci_onu/brcm_openomci_onu_handler.py
@@ -210,7 +210,6 @@
         self.proxy_address = device.proxy_address
         self.parent_id = device.parent_id
         self._pon_port_number = device.parent_port_no
-
         if self.enabled is not True:
             self.log.info('activating-new-onu')
             # populate what we know.  rest comes later after mib sync
@@ -259,6 +258,7 @@
             self.log.info('onu-already-activated')
 
     # Called once when the adapter needs to re-create device.  usually on vcore restart
+    @inlineCallbacks
     def reconcile(self, device):
         self.log.debug('function-entry', device=device)
 
@@ -266,10 +266,6 @@
         assert device.parent_id
         assert device.proxy_address.device_id
 
-        # register for proxied messages right away
-        self.proxy_address = device.proxy_address
-        self.adapter_agent.register_for_proxied_messages(device.proxy_address)
-
         if self.enabled is not True:
             self.log.info('reconciling-broadcom-onu-device')
 
@@ -278,7 +274,7 @@
             # need to restart state machines on vcore restart.  there is no indication to do it for us.
             self._onu_omci_device.start()
             device.reason = "restarting-openomci"
-            self.adapter_agent.update_device(device)
+            yield self.core_proxy.update_device(device)
 
             # TODO: this is probably a bit heavy handed
             # Force a reboot for now.  We need indications to reflow to reassign tconts and gems given vcore went away
@@ -311,19 +307,6 @@
         if self._pon is not None:
             self._pon.enabled = True
 
-    # TODO: move to UniPort
-    def update_logical_port(self, logical_device_id, port_id, state):
-        try:
-            self.log.info('updating-logical-port', logical_port_id=port_id,
-                          logical_device_id=logical_device_id, state=state)
-            logical_port = self.adapter_agent.get_logical_port(logical_device_id,
-                                                               port_id)
-            logical_port.ofp_port.state = state
-            self.adapter_agent.update_logical_port(logical_device_id,
-                                                   logical_port)
-        except Exception as e:
-            self.log.exception("exception-updating-port", e=e)
-
     def delete(self, device):
         self.log.info('delete-onu', device=device)
         if self.parent_adapter:
@@ -424,22 +407,24 @@
                 tp = ast.literal_eval(tp)
                 self.log.debug("tp-instance", tp=tp)
                 self._do_tech_profile_configuration(uni_id, tp)
-
+                
+                @inlineCallbacks
                 def success(_results):
                     self.log.info("tech-profile-config-done-successfully")
-                    device = self.adapter_agent.get_device(self.device_id)
+                    device = yield self.core_proxy.get_device(self.device_id)
                     device.reason = 'tech-profile-config-download-success'
-                    self.adapter_agent.update_device(device)
+                    yield self.core_proxy.update_device(device)
                     if tp_path in self._tp_service_specific_task[uni_id]:
                         del self._tp_service_specific_task[uni_id][tp_path]
                     self._tech_profile_download_done[uni_id][tp_path] = True
 
+                @inlineCallbacks
                 def failure(_reason):
                     self.log.warn('tech-profile-config-failure-retrying',
                                    _reason=_reason)
-                    device = self.adapter_agent.get_device(self.device_id)
+                    device = yield self.core_proxy.get_device(self.device_id)
                     device.reason = 'tech-profile-config-download-failure-retrying'
-                    self.adapter_agent.update_device(device)
+                    yield self.core_proxy.update_device(device)
                     if tp_path in self._tp_service_specific_task[uni_id]:
                         del self._tp_service_specific_task[uni_id][tp_path]
                     self._deferred = reactor.callLater(_STARTUP_RETRY_WAIT, self.load_and_configure_tech_profile,
@@ -720,15 +705,16 @@
             onu_device.reason = "stopping-openomci"
             onu_device.connect_status = ConnectStatus.UNREACHABLE
             onu_device.oper_status = OperStatus.DISCOVERED
-            self.adapter_agent.update_device(onu_device)
+            yield self.core_proxy.update_device(onu_device)
         else:
             self.log.debug('not-changing-openomci-statemachine')
 
     # Not currently called by olt or anything else
+    @inlineCallbacks
     def remove_interface(self, data):
         self.log.debug('function-entry', data=data)
 
-        onu_device = self.adapter_agent.get_device(self.device_id)
+        onu_device = yield self.core_proxy.get_device(self.device_id)
 
         self.log.debug('stopping-openomci-statemachine')
         reactor.callLater(0, self._onu_omci_device.stop)
@@ -741,22 +727,24 @@
 
         self.disable_ports(onu_device)
         onu_device.reason = "stopping-openomci"
-        self.adapter_agent.update_device(onu_device)
+        yield self.core_proxy.update_device(onu_device)
 
         # TODO: im sure there is more to do here
 
     # Not currently called.  Would be called presumably from the olt handler
+    @inlineCallbacks
     def remove_gemport(self, data):
         self.log.debug('remove-gemport', data=data)
-        device = self.adapter_agent.get_device(self.device_id)
+        device = yield self.core_proxy.get_device(self.device_id)
         if device.connect_status != ConnectStatus.REACHABLE:
             self.log.error('device-unreachable')
             return
 
     # Not currently called.  Would be called presumably from the olt handler
+    @inlineCallbacks
     def remove_tcont(self, tcont_data, traffic_descriptor_data):
         self.log.debug('remove-tcont', tcont_data=tcont_data, traffic_descriptor_data=traffic_descriptor_data)
-        device = self.adapter_agent.get_device(self.device_id)
+        device = yield self.core_proxy.get_device(self.device_id)
         if device.connect_status != ConnectStatus.REACHABLE:
             self.log.error('device-unreachable')
             return
@@ -769,6 +757,7 @@
 
         # TODO: create objects and populate for later omci calls
 
+    @inlineCallbacks
     def disable(self, device):
         self.log.debug('function-entry', device=device)
         try:
@@ -788,7 +777,7 @@
                 self.disable_ports(device)
                 device.oper_status = OperStatus.UNKNOWN
                 device.reason = "omci-admin-lock"
-                self.adapter_agent.update_device(device)
+                yield self.core_proxy.update_device(device)
 
             # lock all the unis
             task = BrcmUniLockTask(self.omci_agent, self.device_id, lock=True)
@@ -797,6 +786,7 @@
         except Exception as e:
             log.exception('exception-in-onu-disable', exception=e)
 
+    @inlineCallbacks
     def reenable(self, device):
         self.log.debug('function-entry', device=device)
         try:
@@ -805,26 +795,28 @@
             self.log.debug('restarting-openomci-statemachine')
             self._subscribe_to_events()
             device.reason = "restarting-openomci"
-            self.adapter_agent.update_device(device)
+            yield self.core_proxy.update_device(device)
             reactor.callLater(1, self._onu_omci_device.start)
             self._heartbeat.enabled = True
         except Exception as e:
             log.exception('exception-in-onu-reenable', exception=e)
 
+    @inlineCallbacks
     def reboot(self):
         self.log.info('reboot-device')
-        device = self.adapter_agent.get_device(self.device_id)
+        device = yield self.core_proxy.get_device(self.device_id)
         if device.connect_status != ConnectStatus.REACHABLE:
             self.log.error("device-unreachable")
             return
 
+        @inlineCallbacks
         def success(_results):
             self.log.info('reboot-success', _results=_results)
             self.disable_ports(device)
             device.connect_status = ConnectStatus.UNREACHABLE
             device.oper_status = OperStatus.DISCOVERED
             device.reason = "rebooting"
-            self.adapter_agent.update_device(device)
+            yield self.core_proxy.update_device(device)
 
         def failure(_reason):
             self.log.info('reboot-failure', _reason=_reason)
@@ -832,38 +824,40 @@
         self._deferred = self._onu_omci_device.reboot()
         self._deferred.addCallbacks(success, failure)
 
+    @inlineCallbacks
     def disable_ports(self, onu_device):
         self.log.info('disable-ports', device_id=self.device_id,
                       onu_device=onu_device)
 
         # Disable all ports on that device
-        self.adapter_agent.disable_all_ports(self.device_id)
+        yield self.core_proxy.disable_all_ports(self.device_id)
 
-        parent_device = self.adapter_agent.get_device(onu_device.parent_id)
+        parent_device = yield self.core_proxy.get_device(onu_device.parent_id)
         assert parent_device
         logical_device_id = parent_device.parent_id
         assert logical_device_id
-        ports = self.adapter_agent.get_ports(onu_device.id, Port.ETHERNET_UNI)
-        for port in ports:
-            port_id = 'uni-{}'.format(port.port_no)
-            # TODO: move to UniPort
-            self.update_logical_port(logical_device_id, port_id, OFPPS_LINK_DOWN)
+        ports = yield self.core_proxy.get_ports(onu_device.id, Port.ETHERNET_UNI)
+        #TODO this should all be handled by the core
+        #for port in ports:
+        #    port_id = 'uni-{}'.format(port.port_no)
+        #    self.update_logical_port(logical_device_id, port_id, OFPPS_LINK_DOWN)
 
+    @inlineCallbacks
     def enable_ports(self, onu_device):
         self.log.info('enable-ports', device_id=self.device_id, onu_device=onu_device)
 
         # Disable all ports on that device
-        self.adapter_agent.enable_all_ports(self.device_id)
+        self.core_proxy.enable_all_ports(self.device_id)
 
-        parent_device = self.adapter_agent.get_device(onu_device.parent_id)
+        parent_device = yield self.core_proxy.get_device(onu_device.parent_id)
         assert parent_device
         logical_device_id = parent_device.parent_id
         assert logical_device_id
-        ports = self.adapter_agent.get_ports(onu_device.id, Port.ETHERNET_UNI)
-        for port in ports:
-            port_id = 'uni-{}'.format(port.port_no)
-            # TODO: move to UniPort
-            self.update_logical_port(logical_device_id, port_id, OFPPS_LIVE)
+        ports = yield self.core_proxy.get_ports(onu_device.id, Port.ETHERNET_UNI)
+        #TODO this should be handled by the core
+        #for port in ports:
+        #    port_id = 'uni-{}'.format(port.port_no)
+        #    self.update_logical_port(logical_device_id, port_id, OFPPS_LIVE)
 
     # Called just before openomci state machine is started.  These listen for events from selected state machines,
     # most importantly, mib in sync.  Which ultimately leads to downloading the mib
diff --git a/python/adapters/brcm_openomci_onu/heartbeat.py b/python/adapters/brcm_openomci_onu/heartbeat.py
index 209876f..13f1d62 100644
--- a/python/adapters/brcm_openomci_onu/heartbeat.py
+++ b/python/adapters/brcm_openomci_onu/heartbeat.py
@@ -73,7 +73,7 @@
 
     @property
     def check_value(self):
-        # device = self._handler.adapter_agent.get_device(self._device_id)
+        # device = self._handler.core_proxy.get_device(self._device_id)
         # return device.serial_number
         return 'ADTN'
 
@@ -142,7 +142,7 @@
         """
         Check the number of heartbeat failures against the limit and emit an alarm if needed
         """
-        device = self._handler.adapter_agent.get_device(self._device_id)
+        device = self._handler.core_proxy.get_device(self._device_id)
 
         try:
             from pyvoltha.adapters.extensions.alarms.heartbeat_alarm import HeartbeatAlarm
@@ -153,7 +153,7 @@
                     device.connect_status = ConnectStatus.UNREACHABLE
                     device.oper_status = OperStatus.FAILED
                     device.reason = self.heartbeat_last_reason
-                    self._handler.adapter_agent.update_device(device)
+                    self._handler.core_proxy.update_device(device)
                     HeartbeatAlarm(self._handler.alarms, 'onu', self._heartbeat_miss).raise_alarm()
                     self._alarm_active = True
                     self.on_heartbeat_alarm(True)
@@ -163,7 +163,7 @@
                     device.connect_status = ConnectStatus.REACHABLE
                     device.oper_status = OperStatus.ACTIVE
                     device.reason = ''
-                    self._handler.adapter_agent.update_device(device)
+                    self._handler.core_proxy.update_device(device)
                     HeartbeatAlarm(self._handler.alarms, 'onu').clear_alarm()
 
                     self._alarm_active = False