ADTRAN Adapters: Bug fixes for device flows after deprecation of xPON

Change-Id: I77ca3a2c0431293a3ddfb4576860b0554392c486
diff --git a/voltha/adapters/adtran_olt/adtran_olt.py b/voltha/adapters/adtran_olt/adtran_olt.py
index ac8c495..6b765e6 100644
--- a/voltha/adapters/adtran_olt/adtran_olt.py
+++ b/voltha/adapters/adtran_olt/adtran_olt.py
@@ -52,7 +52,7 @@
         self.descriptor = Adapter(
             id=self.name,
             vendor='ADTRAN, Inc.',
-            version='1.32',
+            version='1.33',
             config=AdapterConfig(log_level=LogLevel.INFO)
         )
         log.debug('adtran_olt.__init__', adapter_agent=adapter_agent)
diff --git a/voltha/adapters/adtran_olt/adtran_olt_handler.py b/voltha/adapters/adtran_olt/adtran_olt_handler.py
index acf2802..6ea7d0d 100644
--- a/voltha/adapters/adtran_olt/adtran_olt_handler.py
+++ b/voltha/adapters/adtran_olt/adtran_olt_handler.py
@@ -854,8 +854,7 @@
             priority=200,
             match_fields=[
                 in_port(nni_port),
-                vlan_vid(ofp.OFPVID_PRESENT + self.utility_vlan),
-                # eth_type(FlowEntry.EtherType.EAPOL)       ?? TODO: is this needed
+                vlan_vid(ofp.OFPVID_PRESENT + self.utility_vlan)
             ],
             actions=[output(pon_port)]
         )
diff --git a/voltha/adapters/adtran_olt/flow/evc.py b/voltha/adapters/adtran_olt/flow/evc.py
index ecc0593..2e1914c 100644
--- a/voltha/adapters/adtran_olt/flow/evc.py
+++ b/voltha/adapters/adtran_olt/flow/evc.py
@@ -221,8 +221,10 @@
 
     def add_evc_map(self, evc_map):
         if self._evc_maps is None:
-            self._evc_maps = {}
-        self._evc_maps[evc_map.name] = evc_map
+            self._evc_maps = dict()
+
+        if evc_map.name not in self._evc_maps:
+            self._evc_maps[evc_map.name] = evc_map
 
     def remove_evc_map(self, evc_map):
         if self._evc_maps is not None and evc_map.name in self._evc_maps:
diff --git a/voltha/adapters/adtran_olt/flow/evc_map.py b/voltha/adapters/adtran_olt/flow/evc_map.py
index 33c9360..92da980 100644
--- a/voltha/adapters/adtran_olt/flow/evc_map.py
+++ b/voltha/adapters/adtran_olt/flow/evc_map.py
@@ -202,7 +202,7 @@
         return '</evc-map></evc-maps>'
 
     def get_evcmap_name(self, onu_id, gem_id):
-        return'{}.{}.{}'.format(self.name, onu_id, gem_id)
+        return'{}.{}.{}.{}'.format(self.name, onu_id, self.pon_id, gem_id)
 
     def _common_install_xml(self):
         xml = '<enabled>{}</enabled>'.format('true' if self._enabled else 'false')
@@ -258,10 +258,11 @@
                 xml += '<ce-vlan-id>{}</ce-vlan-id>'.format(Onu.gem_id_to_gvid(gem_id))
 
                 # GEM-IDs are a sorted list (ascending). First gemport handles downstream traffic
-                if first_gem_id and vid is not None:
+                if first_gem_id and (self._c_tag is not None or vid is not None):
                     first_gem_id = False
+                    vlan = vid or self._c_tag
                     xml += '<network-ingress-filter>'
-                    xml += '<men-ctag>{}</men-ctag>'.format(vid)  # Added in August 2017 model
+                    xml += '<men-ctag>{}</men-ctag>'.format(vlan)  # Added in August 2017 model
                     xml += '</network-ingress-filter>'
 
                 if len(acl_list):
@@ -319,6 +320,7 @@
             work_acls = self._new_acls.copy()
             self._new_acls = dict()
 
+            log.debug('install-evc-map-acls', install_acls=len(work_acls))
             for acl in work_acls.itervalues():
                 try:
                     yield acl.install()
@@ -328,6 +330,13 @@
                     self._new_acls.update(work_acls)
                     raise
 
+            # Any user-data flows attached to this map ?
+            c_tag = None
+            for flow_id, flow in self._flows.items():
+                c_tag = flow.inner_vid or flow.vlan_id or c_tag
+
+            self._c_tag = c_tag
+
             # Now EVC-MAP
             if not self._installed or self._needs_update:
                 log.debug('needs-install-or-update', installed=self._installed, update=self._needs_update)
@@ -493,7 +502,7 @@
     def add_flow(self, flow, evc):
         """
         Add a new flow to an existing EVC-MAP. This can be called to add:
-          o an ACL flow to an existing utility/untagged EVC, or
+          o an ACL flow to an existing utility EVC, or
           o an ACL flow to an existing User Data Flow, or
           o a User Data Flow to an existing ACL flow (and this needs the EVC updated
             as well.
@@ -522,6 +531,7 @@
         self._flows[flow.flow_id] = flow
         self._needs_update = True
 
+        # Are there ACLs to add to any existing (or empty) ACLs
         if len(tmp_map._new_acls) > 0:
             self._new_acls.update(tmp_map._new_acls)        # New ACL flow
             log.debug('add-acl-flows', map=str(self), new=tmp_map._new_acls)
@@ -533,6 +543,7 @@
             self._evc.remove_evc_map(self)
             evc.add_evc_map(self)
             self._evc = evc
+
         return self
 
     @inlineCallbacks
@@ -571,7 +582,7 @@
                     # or Untagged EVC from a user data EVC
                     if self._evc and not self._evc.service_evc and\
                         len(self._flows) > 0 and\
-                        all(f.is_acl_flow for f in self._flows.itervalues()):
+                            all(f.is_acl_flow for f in self._flows.itervalues()):
 
                         self._evc.remove_evc_map(self)
                         first_flow = self._flows.itervalues().next()
@@ -615,7 +626,7 @@
         # Note: When actually installed into the OLT, the .onu_id.gem_port is
         #       appended to the name
         return {'ingress-port': items[1],
-                'flow-id': items[2].split('.')[0]} if len(items) == 3 else dict()
+                'flow-id': items[2].split('.')[0]} if len(items) > 2 else dict()
 
     def add_gem_port(self, gem_port, reflow=False):
         # TODO: Refactor
diff --git a/voltha/adapters/adtran_olt/flow/flow_entry.py b/voltha/adapters/adtran_olt/flow/flow_entry.py
index a0d67fe..02b112e 100644
--- a/voltha/adapters/adtran_olt/flow/flow_entry.py
+++ b/voltha/adapters/adtran_olt/flow/flow_entry.py
@@ -52,7 +52,7 @@
         UPSTREAM = 0          # UNI port to NNI Port
         DOWNSTREAM = 1        # NNI port to UNI Port
         CONTROLLER_UNI = 2    # Trap packet on UNI and send to controller
-        NNI_PON = 3           # NNI port to PON Port (all UNIs) - perhaps multicast?
+        NNI_PON = 3           # NNI port to PON Port (all UNIs) - Utility VLAN & multicast
 
         # The following are not yet supported
         CONTROLLER_NNI = 4    # Trap packet on NNI and send to controller
@@ -585,6 +585,11 @@
         if self.vlan_id == FlowEntry.LEGACY_CONTROL_VLAN and self.eth_type is None and self.pcp == 0:
             return False    # Do not install this flow.  Utility VLAN is in charge
 
+        elif self.flow_direction == FlowEntry.FlowDirection.NNI_PON and \
+                self.vlan_id == self.handler.utility_vlan:
+            # Utility VLAN downstream flow/EVC
+            self._is_acl_flow = True
+
         elif self.vlan_id in self._handler.multicast_vlans:
             #  multicast (ethType = IP)                         # TODO: May need to be an NNI_PON flow
             self._is_multicast = True
@@ -800,7 +805,7 @@
                         if len(gem_ids_with_vid) > 0:
                             gem_ids = gem_ids_with_vid[0]
                             ctag = gem_ids_with_vid[1]
-                            gem_id = gem_ids[0]     # TODO: always grab fist in list
+                            gem_id = gem_ids[0]     # TODO: always grab first in list
                             return flow_entry.in_port, ctag, Onu.gem_id_to_gvid(gem_id), \
                                 evc_map.get_evcmap_name(onu_id, gem_id)
         return None, None, None, None
diff --git a/voltha/adapters/adtran_olt/flow/flow_tables.py b/voltha/adapters/adtran_olt/flow/flow_tables.py
index e90e69b..aa90ee3 100644
--- a/voltha/adapters/adtran_olt/flow/flow_tables.py
+++ b/voltha/adapters/adtran_olt/flow/flow_tables.py
@@ -52,7 +52,8 @@
 
     def add(self, flow):
         assert isinstance(flow, FlowEntry)
-        self._flow_table[flow.flow_id] = flow
+        if flow.flow_id not in self._flow_table:
+            self._flow_table[flow.flow_id] = flow
         return flow
 
     def get(self, item):
diff --git a/voltha/adapters/adtran_onu/adtran_onu.py b/voltha/adapters/adtran_onu/adtran_onu.py
index c5288b0..2d6b8a3 100755
--- a/voltha/adapters/adtran_onu/adtran_onu.py
+++ b/voltha/adapters/adtran_onu/adtran_onu.py
@@ -42,7 +42,7 @@
                                                device_handler_class=AdtranOnuHandler,
                                                name='adtran_onu',
                                                vendor='ADTRAN, Inc.',
-                                               version='1.21',
+                                               version='1.22',
                                                device_type='adtran_onu',
                                                vendor_id='ADTN',
                                                accepts_add_remove_flow_updates=False),  # TODO: Support flow-mods
diff --git a/voltha/adapters/adtran_onu/adtran_onu_handler.py b/voltha/adapters/adtran_onu/adtran_onu_handler.py
index 045c559..040a617 100644
--- a/voltha/adapters/adtran_onu/adtran_onu_handler.py
+++ b/voltha/adapters/adtran_onu/adtran_onu_handler.py
@@ -190,11 +190,10 @@
         #self.adapter_agent.unregister_for_inter_adapter_messages()
 
         # Heartbeat
-        self._heartbeat.stop()
+        self._heartbeat.enabled = False
 
         # OMCI Communications
         self._unsubscribe_to_events()
-        self._openomci.enabled = False
 
         # Port shutdown
         for port in self.uni_ports:
@@ -202,6 +201,7 @@
 
         if self._pon is not None:
             self._pon.enabled = False
+        self._openomci.enabled = False
 
     def receive_message(self, msg):
         if self.enabled:
@@ -335,8 +335,8 @@
             if flow_entry.flow_id in self._flows:
                 valid_flows.add(flow_entry.flow_id)
 
-            if flow_entry is None or flow_entry.flow_direction not in {FlowEntry.upstream_flow_types,
-                                                                       FlowEntry.downstream_flow_types}:
+            if flow_entry is None or flow_entry.flow_direction not in \
+                    FlowEntry.upstream_flow_types | FlowEntry.downstream_flow_types:
                 continue
 
             is_upstream = flow_entry.flow_direction in FlowEntry.upstream_flow_types
@@ -467,50 +467,50 @@
 
     def disable(self):
         self.log.info('disabling', device_id=self.device_id)
-        self.enabled = False
-
+        try:
         # Get the latest device reference
-        device = self.adapter_agent.get_device(self.device_id)
 
-        # Disable all ports on that device
-        self.adapter_agent.disable_all_ports(self.device_id)
+            device = self.adapter_agent.get_device(self.device_id)
 
-        # Update the device operational status to UNKNOWN
-        device.oper_status = OperStatus.UNKNOWN
-        device.connect_status = ConnectStatus.UNREACHABLE
-        device.reason = 'Disabled'
-        self.adapter_agent.update_device(device)
+            # Disable all ports on that device
+            self.adapter_agent.disable_all_ports(self.device_id)
 
-        # Remove the uni logical port from the OLT, if still present
-        parent_device = self.adapter_agent.get_device(device.parent_id)
-        assert parent_device
+            # Update the device operational status to UNKNOWN
+            device.oper_status = OperStatus.UNKNOWN
+            device.connect_status = ConnectStatus.UNREACHABLE
+            device.reason = 'Disabled'
+            self.adapter_agent.update_device(device)
 
-        for uni in self.uni_ports:
-            # port_id = 'uni-{}'.format(uni.port_number)
-            port_id = uni.port_id_name()
+            # Remove the uni logical port from the OLT, if still present
+            parent_device = self.adapter_agent.get_device(device.parent_id)
+            assert parent_device
 
-            try:
-                #TODO: there is no logical device if olt disables first
-                logical_device_id = parent_device.parent_id
-                assert logical_device_id
-                port = self.adapter_agent.get_logical_port(logical_device_id,
-                                                           port_id)
-                self.adapter_agent.delete_logical_port(logical_device_id, port)
-            except KeyError:
-                self.log.info('logical-port-not-found', device_id=self.device_id,
-                              portid=port_id)
+            for uni in self.uni_ports:
+                # port_id = 'uni-{}'.format(uni.port_number)
+                port_id = uni.port_id_name()
+                try:
+                    logical_device_id = parent_device.parent_id
+                    assert logical_device_id
+                    port = self.adapter_agent.get_logical_port(logical_device_id,port_id)
+                    self.adapter_agent.delete_logical_port(logical_device_id, port)
+                except KeyError:
+                    self.log.info('logical-port-not-found', device_id=self.device_id,
+                                  portid=port_id)
 
-        # Remove pon port from parent and disable
-        if self._pon is not None:
-            self.adapter_agent.delete_port_reference_from_parent(self.device_id,
-                                                                 self._pon.get_port())
-            self._pon.enabled = False
+            # Remove pon port from parent and disable
+            if self._pon is not None:
+                self.adapter_agent.delete_port_reference_from_parent(self.device_id,
+                                                                     self._pon.get_port())
+                self._pon.enabled = False
 
-        # Unregister for proxied message
-        self.adapter_agent.unregister_for_proxied_messages(device.proxy_address)
+            # Unregister for proxied message
+            self.adapter_agent.unregister_for_proxied_messages(device.proxy_address)
 
-        # TODO:
-        # 1) Remove all flows from the device? or is it done before we are called
+        except Exception as _e:
+            pass    # This is expected if OLT has deleted the ONU device handler
+
+        # And disable OMCI as well
+        self.enabled = False
         self.log.info('disabled', device_id=device.id)
 
     def reenable(self):
@@ -568,15 +568,20 @@
     def delete(self):
         self.log.info('deleting', device_id=self.device_id)
 
-        for uni in self._unis.values():
-            uni.stop()
-            uni.delete()
+        try:
+            for uni in self._unis.values():
+                uni.stop()
+                uni.delete()
 
-        self._pon.stop()
-        self._pon.delete()
+            self._pon.stop()
+            self._pon.delete()
+
+        except Exception as _e:
+            pass    # Expected if the OLT deleted us from the device handler
 
         # OpenOMCI cleanup
-        self._openomci.delete()
+        omci, self._openomci = self._openomci, None
+        omci.delete()
 
     def add_uni_ports(self):
         """ Called after in-sync achieved and not in xPON mode"""
diff --git a/voltha/adapters/adtran_onu/flow/flow_entry.py b/voltha/adapters/adtran_onu/flow/flow_entry.py
index 0c37d1d..2051ce8 100644
--- a/voltha/adapters/adtran_onu/flow/flow_entry.py
+++ b/voltha/adapters/adtran_onu/flow/flow_entry.py
@@ -50,6 +50,9 @@
         (FlowDirection.ANI, FlowDirection.UNI): FlowDirection.DOWNSTREAM
     }
 
+    upstream_flow_types = {FlowDirection.UPSTREAM}
+    downstream_flow_types = {FlowDirection.DOWNSTREAM}
+
     # Well known EtherTypes
     class EtherType(IntEnum):
         EAPOL = 0x888E
diff --git a/voltha/adapters/adtran_onu/omci/adtn_install_flow.py b/voltha/adapters/adtran_onu/omci/adtn_install_flow.py
index 4b920de..04d9d1f 100644
--- a/voltha/adapters/adtran_onu/omci/adtn_install_flow.py
+++ b/voltha/adapters/adtran_onu/omci/adtn_install_flow.py
@@ -14,7 +14,7 @@
 # limitations under the License.
 #
 from twisted.internet import reactor
-from twisted.internet.defer import inlineCallbacks, failure
+from twisted.internet.defer import inlineCallbacks, failure, returnValue
 from voltha.extensions.omci.omci_me import *
 from voltha.extensions.omci.tasks.task import Task
 from voltha.extensions.omci.omci_defs import *
@@ -57,6 +57,7 @@
         self._onu_device = omci_agent.get_device(handler.device_id)
         self._local_deferred = None
         self._flow_entry = flow_entry
+        self._install_by_delete = True
 
         # TODO: Cleanup below that is not needed
         is_upstream = flow_entry.flow_direction in FlowEntry.upstream_flow_types
@@ -71,6 +72,7 @@
         #
         # TODO: Probably need to store many of these in the appropriate object (UNI, PON,...)
         #
+        self._ethernet_uni_entity_id = self._handler.uni_ports[0].entity_id
         self._ieee_mapper_service_profile_entity_id = self._pon.hsi_8021p_mapper_entity_id
         # self._hsi_mac_bridge_port_ani_entity_id = self._pon.hsi_mac_bridge_port_ani_entity_id
 
@@ -128,16 +130,25 @@
         elif status == RC.InstanceExists:
             return False
 
+        elif status == RC.UnknownInstance and operation == 'delete':
+            return True
+
         raise ServiceInstallFailure('{} failed with a status of {}, error_mask: {}, failed_mask: {}, unsupported_mask: {}'
                                     .format(operation, status, error_mask, failed_mask, unsupported_mask))
 
     @inlineCallbacks
     def perform_flow_install(self):
         """
-        Send the commands to configure the flow
+        Send the commands to configure the flow.
+
+        Currently this task uses the pre-installed default TCONT and GEM Port.  This will
+        change when Technology Profiles are supported.
         """
         self.log.info('perform-flow-install', vlan_vid=self._flow_entry.vlan_vid)
 
+        if self._flow_entry.vlan_vid == 0:
+            return
+
         def resources_available():
             # TODO: Rework for non-xpon mode
             return (len(self._handler.uni_ports) > 0 and
@@ -145,33 +156,63 @@
                     len(self._pon.gem_ports))
 
         if self._handler.enabled and resources_available():
+
             omci = self._onu_device.omci_cc
+            brg_id = self._mac_bridge_service_profile_entity_id
+            vlan_vid = self._flow_entry.vlan_vid
+
+            if self._install_by_delete:
+                # Delete any existing flow before adding this new one
+
+                msg = ExtendedVlanTaggingOperationConfigurationDataFrame(brg_id, attributes=None)
+                frame = msg.delete()
+
+                try:
+                    results = yield omci.send(frame)
+                    self.check_status_and_state(results, operation='delete')
+
+                    attributes = dict(
+                        association_type=2,  # Assoc Type, PPTP Ethernet UNI
+                        associated_me_pointer=self._ethernet_uni_entity_id  # Assoc ME, PPTP Entity Id
+                    )
+
+                    frame = ExtendedVlanTaggingOperationConfigurationDataFrame(
+                        self._mac_bridge_service_profile_entity_id,
+                        attributes=attributes
+                    ).create()
+                    results = yield omci.send(frame)
+                    self.check_status_and_state(results, 'flow-recreate-before-set')
+
+                    # TODO: Any of the following needed as well
+
+                    # # Delete bridge ani side vlan filter
+                    # msg = VlanTaggingFilterDataFrame(self._hsi_mac_bridge_port_ani_entity_id)
+                    # frame = msg.delete()
+                    #
+                    # results = yield omci.send(frame)
+                    # self.check_status_and_state(results, 'flow-delete-vlan-tagging-filter-data')
+                    #
+                    # # Re-Create bridge ani side vlan filter
+                    # msg = VlanTaggingFilterDataFrame(
+                    #         self._hsi_mac_bridge_port_ani_entity_id,  # Entity ID
+                    #         vlan_tcis=[vlan_vid],             # VLAN IDs
+                    #         forward_operation=0x10
+                    # )
+                    # frame = msg.create()
+                    #
+                    # results = yield omci.send(frame)
+                    # self.check_status_and_state(results, 'flow-create-vlan-tagging-filter-data')
+
+                except Exception as e:
+                    self.log.exception('flow-delete-before-install-failure', e=e)
+                    self.deferred.errback(failure.Failure(e))
+                    returnValue(None)
+
             try:
-                # TODO: make this a member of the onu gem port or the uni port
-                vlan_vid = self._flow_entry.vlan_vid
-
-                # # Delete bridge ani side vlan filter
-                # msg = VlanTaggingFilterDataFrame(self._hsi_mac_bridge_port_ani_entity_id)
-                # frame = msg.delete()
-                #
-                # results = yield omci.send(frame)
-                # self.check_status_and_state(results, 'flow-delete-vlan-tagging-filter-data')
-                #
-                # # Re-Create bridge ani side vlan filter
-                # msg = VlanTaggingFilterDataFrame(
-                #         self._hsi_mac_bridge_port_ani_entity_id,  # Entity ID
-                #         vlan_tcis=[vlan_vid],             # VLAN IDs
-                #         forward_operation=0x10
-                # )
-                # frame = msg.create()
-                #
-                # results = yield omci.send(frame)
-                # self.check_status_and_state(results, 'flow-create-vlan-tagging-filter-data')
-
+                # Now set the VLAN Tagging Operation up as we want it
                 # Update uni side extended vlan filter
                 # filter for untagged
                 # probably for eapol
-                # TODO: magic 0x1000 / 4096?
                 # TODO: lots of magic
                 # attributes = dict(
                 #         # This table filters and tags upstream frames
@@ -211,29 +252,55 @@
                 # filter for vlan 0
                 # TODO: lots of magic
 
+                ################################################################################
+                # Update Extended VLAN Tagging Operation Config Data
+                #
+                # Specifies the TPIDs in use and that operations in the downstream direction are
+                # inverse to the operations in the upstream direction
+                # TODO: Downstream mode may need to be modified once we work more on the flow rules
+
                 attributes = dict(
-                        # This table filters and tags upstream frames
-                        received_frame_vlan_tagging_operation_table=
-                        VlanTaggingOperation(
-                                filter_outer_priority=15,   # This entry is not a double-tag rule
-                                filter_outer_vid=4096,      # Do not filter on the outer VID value
-                                filter_outer_tpid_de=0,     # Do not filter on the outer TPID field
-
-                                filter_inner_priority=8,    # Filter on inner vlan
-                                filter_inner_vid=0x0,       # Look for vlan 0
-                                filter_inner_tpid_de=0,     # Do not filter on inner TPID field
-                                filter_ether_type=0,        # Do not filter on EtherType
-
-                                treatment_tags_to_remove=1,   # Remove 1 tags
-                                treatment_outer_priority=15,  # Do not add an outer tag
-                                treatment_outer_vid=0,        # n/a
-                                treatment_outer_tpid_de=0,    # n/a
-
-                                treatment_inner_priority=8,    # Add an inner tag and insert this value as the priority
-                                treatment_inner_vid=vlan_vid,  # use this value as the VID in the inner VLAN tag
-                                treatment_inner_tpid_de=4,     # set TPID to 0x8100
-                        )
+                    input_tpid=0x8100,  # input TPID
+                    output_tpid=0x8100,  # output TPID
+                    downstream_mode=0,  # inverse of upstream
                 )
+
+                msg = ExtendedVlanTaggingOperationConfigurationDataFrame(
+                        self._mac_bridge_service_profile_entity_id,  # Bridge Entity ID
+                        attributes=attributes  # See above
+                )
+                frame = msg.set()
+
+                results = yield omci.send(frame)
+                self.check_status_and_state(results, 'set-extended-vlan-tagging-operation-configuration-data')
+
+
+                attributes = dict(
+
+
+                    received_frame_vlan_tagging_operation_table=
+                    VlanTaggingOperation(
+                        filter_outer_priority=15,  # This entry is not a double-tag rule
+                        filter_outer_vid=4096,     # Do not filter on the outer VID value
+                        filter_outer_tpid_de=0,    # Do not filter on the outer TPID field
+
+                        filter_inner_priority=15,  # This is a no-tag rule, ignore all other VLAN tag filter fields
+                        filter_inner_vid=0x1000,   # Do not filter on the inner VID
+                        filter_inner_tpid_de=0,    # Do not filter on inner TPID field
+
+                        filter_ether_type=0,         # Do not filter on EtherType
+                        treatment_tags_to_remove=0,  # Remove 0 tags
+
+                        treatment_outer_priority=15,  # Do not add an outer tag
+                        treatment_outer_vid=0,        # n/a
+                        treatment_outer_tpid_de=0,    # n/a
+
+                        treatment_inner_priority=0,    # Add an inner tag and insert this value as the priority
+                        treatment_inner_vid=vlan_vid,  # use this value as the VID in the inner VLAN tag
+                        treatment_inner_tpid_de=4,     # set TPID
+                    )
+                )
+
                 msg = ExtendedVlanTaggingOperationConfigurationDataFrame(
                         self._mac_bridge_service_profile_entity_id,  # Bridge Entity ID
                         attributes=attributes  # See above
@@ -242,7 +309,7 @@
 
                 results = yield omci.send(frame)
                 self.check_status_and_state(results,
-                                            'flow-set-ext-vlan-tagging-op-config-data-zero-tagged')
+                                            'flow-set-ext-vlan-tagging-op-config-data-untagged')
                 self.deferred.callback('flow-install-success')
 
             except Exception as e:
diff --git a/voltha/adapters/adtran_onu/omci/adtn_mib_download_task.py b/voltha/adapters/adtran_onu/omci/adtn_mib_download_task.py
index 2b2853f..0ef7d92 100644
--- a/voltha/adapters/adtran_onu/omci/adtn_mib_download_task.py
+++ b/voltha/adapters/adtran_onu/omci/adtn_mib_download_task.py
@@ -210,7 +210,8 @@
             #  References:
             #            - Nothing
             attributes = {
-                'spanning_tree_ind': False
+                'spanning_tree_ind': False,
+                'learning_ind': True
             }
             frame = MacBridgeServiceProfileFrame(
                 self._mac_bridge_service_profile_entity_id,
diff --git a/voltha/adapters/adtran_onu/omci/adtn_service_download_task.py b/voltha/adapters/adtran_onu/omci/adtn_service_download_task.py
index 209dcd8..11ce30a 100644
--- a/voltha/adapters/adtran_onu/omci/adtn_service_download_task.py
+++ b/voltha/adapters/adtran_onu/omci/adtn_service_download_task.py
@@ -157,7 +157,7 @@
         and other characteristics are done once resources (gem-ports, tconts, ...)
         have been defined.
         """
-        self.log.info('perform-service-download')
+        self.log.debug('perform-service-download')
         device = self._handler.adapter_agent.get_device(self.device_id)
 
         def resources_available():
@@ -210,7 +210,7 @@
             #            - ONU created TCONT (created on ONU startup)
 
             tcont_idents = self._onu_device.query_mib(Tcont.class_id)
-            self.log.info('tcont-idents', tcont_idents=tcont_idents)
+            self.log.debug('tcont-idents', tcont_idents=tcont_idents)
 
             for tcont in self._pon.tconts.itervalues():
                 if tcont.entity_id is None:
diff --git a/voltha/adapters/adtran_onu/omci/omci.py b/voltha/adapters/adtran_onu/omci/omci.py
index 6690aba..6e0ed82 100644
--- a/voltha/adapters/adtran_onu/omci/omci.py
+++ b/voltha/adapters/adtran_onu/omci/omci.py
@@ -134,7 +134,7 @@
         self._handler = None
 
         if agent is not None:
-            agent(device_id, cleanup=True)
+            agent.remove_device(device_id, cleanup=True)
 
     @property
     def enabled(self):
diff --git a/voltha/adapters/adtran_onu/onu_tcont.py b/voltha/adapters/adtran_onu/onu_tcont.py
index 1f24b76..dee3fcc 100644
--- a/voltha/adapters/adtran_onu/onu_tcont.py
+++ b/voltha/adapters/adtran_onu/onu_tcont.py
@@ -46,7 +46,7 @@
         return OnuTCont(handler, tcont['alloc-id'], td, name=tcont['name'])
 
     @inlineCallbacks
-    def add_to_hardware(self, omci, tcont_entity_id, prev_alloc_id=OnuTCont.free_tcont_alloc_id):
+    def add_to_hardware(self, omci, tcont_entity_id, prev_alloc_id=free_tcont_alloc_id):
         self.log.debug('add-to-hardware', tcont_entity_id=tcont_entity_id)
 
         if self._entity_id == tcont_entity_id: