fixes for omci exchange in pmcs_onu

Change-Id: I078dd6a694dbedddddd28e6324cc9b8d83d33bb3
diff --git a/common/event_bus.py b/common/event_bus.py
index fa8423a..d572e62 100644
--- a/common/event_bus.py
+++ b/common/event_bus.py
@@ -111,7 +111,7 @@
                 try:
                     candidate.callback(topic, msg)
                 except Exception, e:
-                    log.warning('callback-failed', e=e, topic=topic)
+                    log.warning('callback-failed', e=repr(e), topic=topic)
 
 
 default_bus = EventBus()
diff --git a/voltha/adapters/microsemi_olt/APIProxy.py b/voltha/adapters/microsemi_olt/APIProxy.py
index 5ac07bc..ff9f466 100644
--- a/voltha/adapters/microsemi_olt/APIProxy.py
+++ b/voltha/adapters/microsemi_olt/APIProxy.py
@@ -26,11 +26,10 @@
 
 log = structlog.get_logger()
 
-class Proxy(BaseOltAutomaton):
+class APIProxy(BaseOltAutomaton):
 
     proxy_address = None
     msg = None
-    opcode = None
 
     def parse_args(self, debug=0, store=0, **kwargs):
         self.adaptor_agent = kwargs.pop('adapter_agent')
@@ -73,10 +72,9 @@
     """
 
     @ATMT.condition(send_msg)
-    def send_msg(self):
-        pkt = PAS5211MsgSendFrame(frame=self.msg, port_id=self.proxy_address.onu_id)
-        opcode = packet.opcode & 0xFFFF
-        self.send(self.px(pkt))
+    def send_api_msg(self):
+        self.opcode = self.msg.opcode & 0xFF
+        self.send(self.px(self.msg))
         raise self.wait_response()
 
     # Transitions from wait_event
@@ -85,14 +83,11 @@
         raise self.error("No OMCI event for {}".format(self.proxy_address))
 
     @ATMT.receive_condition(wait_response)
-    def wait_response(self, pkt):
+    def wait_for_response(self, pkt):
         if PAS5211EventFrameReceived in pkt:
             rcv_opcode = pkt.opcode & 0xFF
-            if rcv_opcode==opcode:
+            if rcv_opcode == self.opcode:
                 # FIXME we may need to verify the transaction id
                 #  to make sure we have the right packet
                 self.adaptor_agent.recieve_proxied_message(self.proxy_address,pkt)
                 raise self.end()
-                
-            else:
-                raise self.error("Received opcode "+pkt.opcode+" does not match")
\ No newline at end of file
diff --git a/voltha/adapters/microsemi_olt/ActivationWatcher.py b/voltha/adapters/microsemi_olt/ActivationWatcher.py
index c59c19c..70dd42f 100644
--- a/voltha/adapters/microsemi_olt/ActivationWatcher.py
+++ b/voltha/adapters/microsemi_olt/ActivationWatcher.py
@@ -35,9 +35,6 @@
 from voltha.extensions.omci.omci_entities import CircuitPack
 from voltha.extensions.omci.omci_frame import OmciFrame
 from voltha.extensions.omci.omci_messages import OmciGet, OmciGetResponse
-from voltha.protos.common_pb2 import AdminState
-from voltha.protos.common_pb2 import OperStatus
-from voltha.protos.device_pb2 import Port
 
 log = structlog.get_logger()
 _verbose = False
diff --git a/voltha/adapters/microsemi_olt/DeviceManager.py b/voltha/adapters/microsemi_olt/DeviceManager.py
index a9795d4..3a33275 100644
--- a/voltha/adapters/microsemi_olt/DeviceManager.py
+++ b/voltha/adapters/microsemi_olt/DeviceManager.py
@@ -15,8 +15,10 @@
 #
 from uuid import uuid4
 import structlog
-from voltha.protos.common_pb2 import ConnectStatus, OperStatus
-from voltha.protos.device_pb2 import Device
+
+from voltha.adapters.microsemi_olt.PAS5211 import CHANNELS
+from voltha.protos.common_pb2 import ConnectStatus, OperStatus, AdminState
+from voltha.protos.device_pb2 import Device, Port
 from voltha.protos.logical_device_pb2 import LogicalDevice, LogicalPort
 from voltha.protos.openflow_13_pb2 import ofp_desc, ofp_switch_features, OFPC_FLOW_STATS, OFPC_TABLE_STATS, \
     OFPC_PORT_STATS, OFPC_GROUP_STATS, ofp_port, OFPPS_LIVE, OFPPF_10GB_FD, OFPPF_FIBER
@@ -53,6 +55,15 @@
         self.device.oper_status = ConnectStatus.REACHABLE
         self.adapter_agent.update_device(self.device)
 
+        for i in CHANNELS:
+            self.adapter_agent.add_port(self.device.id, Port(
+                port_no=i,
+                label='PON port',
+                type=Port.PON_OLT,
+                admin_state=AdminState.ENABLED,
+                oper_status=OperStatus.ACTIVE
+            ))
+
     def create_logical_device(self):
         log.info('create-logical-device')
         # then shortly after we create the logical device with one port
diff --git a/voltha/adapters/microsemi_olt/OMCIProxy.py b/voltha/adapters/microsemi_olt/OMCIProxy.py
index be81fd4..58efaf6 100644
--- a/voltha/adapters/microsemi_olt/OMCIProxy.py
+++ b/voltha/adapters/microsemi_olt/OMCIProxy.py
@@ -23,11 +23,13 @@
 from voltha.adapters.microsemi_olt.BaseOltAutomaton import BaseOltAutomaton
 from voltha.adapters.microsemi_olt.PAS5211 import PAS5211MsgSendFrame, PAS5211MsgSendFrameResponse, \
     PAS5211EventFrameReceived
+from voltha.adapters.microsemi_olt.PAS5211_constants import PON_ENABLE, PON_TRUE
+from voltha.adapters.microsemi_olt.PAS5211_constants import PON_PORT_PON
 
 log = structlog.get_logger()
 
-class OMCIProxy(BaseOltAutomaton):
 
+class OMCIProxy(BaseOltAutomaton):
 
     proxy_address = None
     msg = None
@@ -78,8 +80,12 @@
 
     @ATMT.condition(got_omci_msg)
     def send_omci_msg(self):
-        pkt = PAS5211MsgSendFrame(frame=self.msg, port_id=self.proxy_address.onu_id)
-        self.send(self.px(pkt))
+        log.debug('send-omci-msg')
+        send_frame = PAS5211MsgSendFrame(port_type=PON_PORT_PON, port_id=self.proxy_address.onu_id,
+                                         management_frame=PON_TRUE, frame=self.msg)
+        to_send = self.px(send_frame)
+        to_send.show()
+        self.send(to_send)
         raise self.wait_send_response()
 
     # Transitions from wait_send_response
@@ -104,4 +110,4 @@
             #  to make sure we have the right packet
             self.adaptor_agent.recieve_proxied_message(self.proxy_address,
                                                        pkt['PAS5211EventFrameReceived'])
-            raise self.end()
\ No newline at end of file
+            raise self.end()
diff --git a/voltha/adapters/microsemi_olt/microsemi_olt.py b/voltha/adapters/microsemi_olt/microsemi_olt.py
index 098140c..b98e340 100644
--- a/voltha/adapters/microsemi_olt/microsemi_olt.py
+++ b/voltha/adapters/microsemi_olt/microsemi_olt.py
@@ -17,19 +17,18 @@
 """
 Microsemi/Celestica Ruby vOLTHA adapter.
 """
-from common.frameio.frameio import BpfProgramFilter, FrameIOManager
-from scapy.layers.l2 import Dot3
 import structlog
 from twisted.internet import reactor
 
-
-
 from voltha.adapters.interface import IAdapterInterface
+from voltha.adapters.microsemi_olt.APIProxy import APIProxy
 from voltha.adapters.microsemi_olt.ActivationWatcher import ActivationWatcher
 from voltha.adapters.microsemi_olt.DeviceManager import DeviceManager
 from voltha.adapters.microsemi_olt.OMCIProxy import OMCIProxy
 from voltha.adapters.microsemi_olt.OltStateMachine import OltStateMachine
 from voltha.adapters.microsemi_olt.PAS5211_comm import PAS5211Communication
+from voltha.extensions.omci.omci_frame import OmciFrame
+from voltha.extensions.omci.omci_messages import OmciMessage
 from voltha.protos import third_party
 from voltha.protos.adapter_pb2 import Adapter, AdapterConfig
 from voltha.protos.common_pb2 import LogLevel
@@ -104,7 +103,7 @@
         reactor.callLater(0, self._init_olt, olt, activation)
 
         log.info('adopted-device', device=device)
-        self.olts[target] = (olt, activation)
+        self.olts[target] = (olt, activation, comm)
 
     def abandon_device(self, device):
         self._abandon(device.mac_address)
@@ -132,19 +131,29 @@
                   flows=flows, groups=groups)
 
     def send_proxied_message(self, proxy_address, msg):
-        if msg.opcode == "0x302a":
-            log.info('send-omci-proxied-message', proxy_address=proxy_address, msg=msg)
+        device = self.adaptor_agent.get_device(proxy_address.device_id)
+        _, _, comm = self.olts[device.mac_address]
+        if isinstance(msg, OmciFrame):
+            log.info('send-omci-proxied-message', proxy_address=proxy_address, device=device)
             # TODO make this more efficient
             omci_proxy = OMCIProxy(proxy_address=proxy_address,
-                                   msg=msg)
-            omci_proxy.run()
-            del omci_proxy
+                                   msg=msg,
+                                   adapter_agent=self.adaptor_agent,
+                                   target=device.mac_address,
+                                   comm=comm,
+                                   iface=self.interface)
+            omci_proxy.runbg()
+
 
         else:
-            log.info('send-proxied-message', proxy_address=proxy_address, msg=msg)
-            api_proxy = APIProxy(device.proxy_address,msg)
-            api_proxy.run()
-            del api_proxy 
+            log.info('send-proxied-message', proxy_address=proxy_address)
+            api_proxy = APIProxy(proxy_address=proxy_address,
+                                 msg=msg,
+                                 adapter_agent=self.adaptor_agent,
+                                 target=device.mac_address,
+                                 comm=comm,
+                                 iface=self.interface)
+            api_proxy.runbg()
 
     def receive_proxied_message(self, proxy_address, msg):
         raise NotImplementedError()
@@ -164,7 +173,7 @@
         activation_watch.runbg()
 
     def _abandon(self, target):
-        olt, activation = self.olts[target]
+        olt, activation, _ = self.olts[target]
         olt.stop()
         activation.stop()
         del self.olts[target]
diff --git a/voltha/adapters/pmcs_onu/pmcs_onu.py b/voltha/adapters/pmcs_onu/pmcs_onu.py
index c9812e0..e049552 100644
--- a/voltha/adapters/pmcs_onu/pmcs_onu.py
+++ b/voltha/adapters/pmcs_onu/pmcs_onu.py
@@ -25,6 +25,9 @@
 
 from voltha.adapters.interface import IAdapterInterface
 from voltha.adapters.microsemi_olt.DeviceManager import mac_str_to_tuple
+from voltha.adapters.microsemi_olt.PAS5211 import PAS5211GetOnuAllocs, PAS5211GetOnuAllocsResponse, PAS5211GetSnInfo, \
+    PAS5211GetSnInfoResponse, PAS5211GetOnusRange, PAS5211GetOnusRangeResponse
+from voltha.extensions.omci.omci_frame import OmciFrame
 from voltha.protos import third_party
 from voltha.protos.adapter_pb2 import Adapter
 from voltha.protos.adapter_pb2 import AdapterConfig
@@ -34,17 +37,18 @@
 from voltha.protos.logical_device_pb2 import LogicalPort
 from voltha.protos.openflow_13_pb2 import OFPPF_1GB_FD, OFPPF_FIBER, ofp_port, OFPPS_LIVE
 
-from voltha.extensions.omci.omci_entities import CircuitPack
-from voltha.extensions.omci.omci_frame import OmciFrame
-<<<<<<< HEAD
-from voltha.extensions.omci.omci_messages import OmciGet, OmciGetResponse
-=======
-from voltha.extensions.omci.omci_messages import OmciGet, OmciGetResponse, OmciCreate
->>>>>>> pmcs message sequence completed
+from voltha.extensions.omci.omci_messages import OmciGet, OmciGetResponse, OmciCreate, OmciMibResetResponse, OmciSet, \
+    OmciSetResponse, OmciCreateResponse, OmciMibReset
 
 _ = third_party
 log = structlog.get_logger()
 
+def sequence_generator(init):
+    num = init
+    while True:
+        yield num
+        num += 1
+
 @implementer(IAdapterInterface)
 class PmcsOnu(object):
 
@@ -68,6 +72,7 @@
             config=AdapterConfig(log_level=LogLevel.INFO)
         )
         self.incoming_messages = DeferredQueue()
+        self.trangen = sequence_generator(1)
 
     def start(self):
         log.debug('starting')
@@ -130,7 +135,7 @@
 
     def receive_proxied_message(self, proxy_address, msg):
         log.info('receive-proxied-message', proxy_address=proxy_address,
-                 device_id=proxy_address.device_id, msg=msg)
+                 device_id=proxy_address.device_id)
         self.incoming_messages.put(msg)
 
     def receive_packet_out(self, logical_device_id, egress_port_no, msg):
@@ -142,24 +147,24 @@
         # first we verify that we got parent reference and proxy info
         assert device.parent_id
         assert device.proxy_address.device_id
-        assert device.proxy_address.channel_id
+        assert device.proxy_address.channel_id == 0
 
         device.model = 'GPON ONU'
         device.hardware_version = 'tbd'
-        device.firware_version = 'tbd'
+        device.firmware_version = 'tbd'
         device.software_version = 'tbd'
 
         device.connect_status = ConnectStatus.REACHABLE
 
         self.adapter_agent.update_device(device)
 
-        uni_port = Port(port_no=self.port_id,
+        uni_port = Port(port_no=1000, # FIXME It becomes the alloc_id
                     label="{} ONU".format('PMCS'),
                     type=Port.ETHERNET_UNI,
                     admin_state=AdminState.ENABLED,
                     oper_status=OperStatus.ACTIVE
                     )
-        self.device.add_port(uni_port)
+        self.adapter_agent.add_port(device.id, uni_port)
 
         pon_port = Port(
             port_no=1,
@@ -186,13 +191,13 @@
         # and name for the virtual ports, as this is guaranteed to be unique
         # in the context of the OLT port, so it is also unique in the context
         # of the logical device
-        port_no = device.proxy_address.channel_id
+        port_no = device.proxy_address.channel_id # FIXME this may need to be fixed
         cap = OFPPF_1GB_FD | OFPPF_FIBER
         self.adapter_agent.add_logical_port(logical_device_id, LogicalPort(
             id=str(port_no),
             ofp_port=ofp_port(
                 port_no=port_no,
-                hw_addr=mac_str_to_tuple(device.mac_address),
+                hw_addr=mac_str_to_tuple(device.serial_number)[2:8],
                 name='uni-{}'.format(port_no),
                 config=0,
                 state=OFPPS_LIVE,
@@ -206,19 +211,20 @@
             device_port_no=uni_port.port_no
         ))
 
-        self._initialize_onu(device)
+        yield self._initialize_onu(device)
 
         # and finally update to "ACTIVE"
         device = self.adapter_agent.get_device(device.id)
         device.oper_status = OperStatus.ACTIVE
         self.adapter_agent.update_device(device)
 
-
+    @inlineCallbacks
     def _initialize_onu(self, device):
+        device = self.adapter_agent.get_device(device.id)
+        self.adapter_agent.register_for_proxied_messages(device.proxy_address)
+        log.debug("INIT", device=device)
         # DO things to the ONU
-
-
-        # |###[ OmciFrame ]### 
+        # |###[ OmciFrame ]###
         #     |  transaction_id= 1
         #     |  message_type= 79
         #     |  omci      = 10
@@ -229,11 +235,20 @@
         #     |  omci_trailer= 40
 
         # OmciMibReset
-        msg = OmciMibReset(entity_class = 2, entity_id = 0)
-        response = yield self.adapter_agent.send_proxied_message(device.proxy_address, msg)
 
-        if not OmciMibResetResponse in response:
-            pass
+        msg = OmciMibReset(entity_class = 2, entity_id = 0)
+        frame = OmciFrame(transaction_id=self.trangen.next(),
+                          message_type=OmciMibReset.message_id,
+                          omci_message=msg)
+
+
+        self.adapter_agent.send_proxied_message(device.proxy_address, frame)
+
+        response = yield self.incoming_messages.get()
+
+        if OmciMibResetResponse not in response:
+            log.error("Failed to perform a MIB reset for {}".format(device.proxy_address))
+            return
 
         # ###[ PAS5211Dot3 ]### 
         #   dst       = 00:0c:d5:00:01:00
@@ -259,10 +274,13 @@
 
         
         msg = PAS5211GetOnuAllocs()
-        response = yield self.adapter_agent.send_proxied_message(device.proxy_address, msg)
+        self.adapter_agent.send_proxied_message(device.proxy_address, msg)
 
-        if not PAS5211GetOnuAllocsResponse in response:
-            pass
+        response = yield self.incoming_messages.get()
+
+        if PAS5211GetOnuAllocsResponse not in response:
+            log.error("Failed to get alloc ids for {}".format(device.proxy_address))
+            return
 
         #  ###[ PAS5211Dot3 ]### 
         #   dst       = 00:0c:d5:00:01:00
@@ -287,10 +305,13 @@
 
 
         msg = PAS5211GetSnInfo(serial_number=device.serial_number)
-        response = yield self.adapter_agent.send_proxied_message(device.proxy_address, msg)   
+        self.adapter_agent.send_proxied_message(device.proxy_address, msg)
 
-        if not PAS5211GetSnInfoResponse in response:
-            pass
+        response = yield self.incoming_messages.get()
+
+        if PAS5211GetSnInfoResponse not in response:
+            log.error("Failed to get serial number info for {}".format(device.proxy_address))
+            return
 
         # ###[ PAS5211Dot3 ]### 
         #   dst       = 00:0c:d5:00:01:00
@@ -314,10 +335,13 @@
         #               load      = '\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
         
         msg = PAS5211GetOnusRange()
-        response = yield self.adapter_agent.send_proxied_message(device.proxy_address, msg)  
+        self.adapter_agent.send_proxied_message(device.proxy_address, msg)
 
-        if not PAS5211GetOnusRangeResponse in response:
-            pass       
+        response = yield self.incoming_messages.get()
+
+        if PAS5211GetOnusRangeResponse not in response:
+            log.error("Failed to get ONU Range for {}".format(device.proxy_address))
+            return
        
         #  |  ###[ OmciFrame ]###
         # | transaction_id = 2
@@ -337,13 +361,17 @@
                       data=dict(
                         alloc_id = 1000
                     ))
-        response = yield self.adapter_agent.send_proxied_message(device.proxy_address, msg)
+        frame = OmciFrame(transaction_id=self.trangen.next(),
+                          message_type=OmciSet.message_id,
+                          omci_message=msg)
+        self.adapter_agent.send_proxied_message(device.proxy_address, frame)
 
-        if not OmciSetResponse in response:
-            pass
+        response = yield self.incoming_messages.get()
 
+        if OmciSetResponse not in response:
+            log.error("Failed to set alloc id for {}".format(device.proxy_address))
+            return
 
-        #   ###[ PAS5211MsgSendFrame ]###
         # length = 44
         # port_type = 0
         # port_id = 0
@@ -369,13 +397,19 @@
         msg = OmciCreate(entity_class=45, entity_id=1,
                          data=dict(
                              max_age = 5120, hello_time = 512, priority = 32768,
-                             port_bridging_ind = 0, spanning_tree_ind= 0, unknown_mac_address_discard= 0, mac_learning_depth=128
-                             learning_ind= 0, forward_delay= 3840
+                             port_bridging_ind = 0, spanning_tree_ind= 0, unknown_mac_address_discard= 0, mac_learning_depth=128,
+                             learning_ind=0, forward_delay=3840
                          ))
-        response = yield self.adapter_agent.send_proxied_message(device.proxy_address, msg)
+        frame = OmciFrame(transaction_id=self.trangen.next(),
+                          message_type=OmciCreate.message_id,
+                          omci_message=msg)
+        self.adapter_agent.send_proxied_message(device.proxy_address, frame)
 
-        if not OmciCreateResponse in response:
-            pass
+        response = yield self.incoming_messages.get()
+
+        if OmciCreateResponse not in response:
+            log.error("Failed to set parameter on {}".format(device.proxy_address))
+            return
 
 
         # |###[ OmciFrame ]### 
@@ -397,10 +431,18 @@
                                 port_path_cost = 100, port_spanning_tree_in = 0,
                                 lan_fcs_ind = 0, bridge_id_pointer = 1
                          ))
-        response = yield self.adapter_agent.send_proxied_message(device.proxy_address, msg)
+
+        frame = OmciFrame(transaction_id=self.trangen.next(),
+                          message_type=OmciCreate.message_id,
+                          omci_message=msg)
+
+        self.adapter_agent.send_proxied_message(device.proxy_address, frame)
+
+        response = yield self.incoming_messages.get()
         
-        if not OmciCreateResponse in response:
-            pass
+        if OmciCreateResponse not in response:
+            log.error("Failed to set info for {}".format(device.proxy_address))
+            return
 
         # |###[ OmciFrame ]### 
         # |  transaction_id= 5
@@ -417,10 +459,18 @@
                          data=dict(
                                 association_type= 2, associated_me_pointer= 257
                          ))
-        response = yield self.adapter_agent.send_proxied_message(device.proxy_address, msg)
 
-        if not OmciCreateResponse in response:
-            pass
+        frame = OmciFrame(transaction_id=self.trangen.next(),
+                          message_type=OmciCreate.message_id,
+                          omci_message=msg)
+
+        self.adapter_agent.send_proxied_message(device.proxy_address, frame)
+
+        response = yield self.incoming_messages.get()
+
+        if OmciCreateResponse not in response:
+            log.error("Failed to set association info for {}".format(device.proxy_address))
+            return
 
         # |###[ OmciFrame ]### 
         # |  transaction_id= 6
@@ -437,13 +487,20 @@
         msg = OmciSet(entity_class = 171, entity_id = 0, attributes_mask = 47616,
                       data=dict(
                         association_type = 2, input_tpid = 33024, associated_me_pointer= 257,
-                    downstream_mode= 0, output_tpid= 33024
+                        downstream_mode= 0, output_tpid= 33024
                     ))
 
-        response = yield self.adapter_agent.send_proxied_message(device.proxy_address, msg)
+        frame = OmciFrame(transaction_id=self.trangen.next(),
+                          message_type=OmciSet.message_id,
+                          omci_message=msg)
 
-        if not OmciSetResponse in response:
-            pass
+        self.adapter_agent.send_proxied_message(device.proxy_address, frame)
+
+        response = yield self.incoming_messages.get()
+
+        if OmciSetResponse not in response:
+            log.error("Failed to set association tpid info for {}".format(device.proxy_address))
+            return
 
         # |###[ OmciFrame ]### 
         # |  transaction_id= 7
@@ -453,7 +510,11 @@
         # |   |###[ OmciCreate ]### 
         # |   |  entity_class= 130
         # |   |  entity_id = 1
-        # |   |  data      = {'tp_pointer': 65535, 'unmarked_frame_option': 1, 'interwork_tp_pointer_for_p_bit_priority_6': 65535, 'interwork_tp_pointer_for_p_bit_priority_7': 65535, 'interwork_tp_pointer_for_p_bit_priority_4': 65535, 'interwork_tp_pointer_for_p_bit_priority_5': 65535, 'interwork_tp_pointer_for_p_bit_priority_2': 65535, 'interwork_tp_pointer_for_p_bit_priority_3': 65535, 'interwork_tp_pointer_for_p_bit_priority_0': 65535, 'interwork_tp_pointer_for_p_bit_priority_1': 65535, 'tp_type': 0, 'default_p_bit_marking': 0}
+        # |   |  data      = {'tp_pointer': 65535, 'unmarked_frame_option': 1, 'interwork_tp_pointer_for_p_bit_priority_6': 65535,
+        #          'interwork_tp_pointer_for_p_bit_priority_7': 65535, 'interwork_tp_pointer_for_p_bit_priority_4': 65535,
+        #           'interwork_tp_pointer_for_p_bit_priority_5': 65535, 'interwork_tp_pointer_for_p_bit_priority_2': 65535,
+        #           'interwork_tp_pointer_for_p_bit_priority_3': 65535, 'interwork_tp_pointer_for_p_bit_priority_0': 65535,
+        #           'interwork_tp_pointer_for_p_bit_priority_1': 65535, 'tp_type': 0, 'default_p_bit_marking': 0}
         # |  omci_trailer= 40
 
         msg = OmciCreate(entity_class=130, entity_id=1,
@@ -461,13 +522,21 @@
                                 tp_pointer= 65535, unmarked_frame_option= 1, interwork_tp_pointer_for_p_bit_priority_6= 65535, 
                                 interwork_tp_pointer_for_p_bit_priority_7= 65535, interwork_tp_pointer_for_p_bit_priority_4= 65535, 
                                 interwork_tp_pointer_for_p_bit_priority_5= 65535, interwork_tp_pointer_for_p_bit_priority_2= 65535, 
-                                interwork_tp_pointer_for_p_bit_priority_3= 65535, interwork_tp_pointer_for_p_bit_priority_0: 65535, 
-                                interwork_tp_pointer_for_p_bit_priority_1= 65535, tp_type= 0, default_p_bit_marking= 0}
+                                interwork_tp_pointer_for_p_bit_priority_3= 65535, interwork_tp_pointer_for_p_bit_priority_0= 65535,
+                                interwork_tp_pointer_for_p_bit_priority_1= 65535, tp_type= 0, default_p_bit_marking= 0
                          ))
-        response = yield self.adapter_agent.send_proxied_message(device.proxy_address, msg)
 
-        if not OmciCreateResponse in response:
-            pass
+        frame = OmciFrame(transaction_id=self.trangen.next(),
+                          message_type=OmciCreate.message_id,
+                          omci_message=msg)
+
+        self.adapter_agent.send_proxied_message(device.proxy_address, frame)
+
+        response = yield self.incoming_messages.get()
+
+        if OmciCreateResponse not in response:
+            log.error("Failed to set interwork info for {}".format(device.proxy_address))
+            return
 
         # |###[ OmciFrame ]### 
         # |  transaction_id= 8
@@ -485,10 +554,18 @@
                                 tp_pointer= 1, encapsulation_methods= 1, port_num= 1, port_priority= 3, tp_type= 5, 
                                 port_path_cost= 32, port_spanning_tree_in= 1, lan_fcs_ind= 0, bridge_id_pointer= 1
                          ))
-        response = yield self.adapter_agent.send_proxied_message(self, device.proxy_address, msg)
 
-        if not OmciCreateResponse in response:
-            pass
+        frame = OmciFrame(transaction_id=self.trangen.next(),
+                          message_type=OmciCreate.message_id,
+                          omci_message=msg)
+
+        self.adapter_agent.send_proxied_message(self, device.proxy_address, frame)
+
+        response = yield self.incoming_messages.get()
+
+        if OmciCreateResponse not in response:
+            log.error("Failed to set encap info for {}".format(device.proxy_address))
+            return
 
         # |###[ OmciFrame ]### 
         # |  transaction_id= 9
@@ -507,10 +584,18 @@
                                 traffic_descriptor_profile_pointer= 0, traffic_management_pointer_upstream= 4, 
                                 port_id= 1000
                          ))
-        response = yield self.adapter_agent.send_proxied_message(device.proxy_address, msg)
 
-        if not OmciCreateResponse in response:
-            pass
+        frame = OmciFrame(transaction_id=self.trangen.next(),
+                          message_type=OmciCreate.message_id,
+                          omci_message=msg)
+
+        self.adapter_agent.send_proxied_message(device.proxy_address, frame)
+
+        response = yield self.incoming_messages.get()
+
+        if OmciCreateResponse not in response:
+            log.error("Failed to priority queue for {}".format(device.proxy_address))
+            return
 
         # |###[ OmciFrame ]### 
         # |  transaction_id= 10
@@ -529,9 +614,15 @@
                                 service_profile_pointer= 1, interworking_option= 5, 
                                 interworking_tp_pointer= 0
                          ))
-        response = yield self.adapter_agent.send_proxied_message(device.proxy_address, msg)
 
-        if not OmciCreateResponse in response:
-            pass
+        frame = OmciFrame(transaction_id=self.trangen.next(),
+                          message_type=OmciCreate.message_id,
+                          omci_message=msg)
 
-        pass
\ No newline at end of file
+        self.adapter_agent.send_proxied_message(device.proxy_address, frame)
+
+        response = yield self.incoming_messages.get()
+
+        if OmciCreateResponse not in response:
+            log.error("Failed to set gem info for {}".format(device.proxy_address))
+            return
\ No newline at end of file
diff --git a/voltha/protos/device.proto b/voltha/protos/device.proto
index 5a32f28..39ec13e 100644
--- a/voltha/protos/device.proto
+++ b/voltha/protos/device.proto
@@ -131,7 +131,7 @@
         string device_id = 1;  // Which device to use as proxy to this device
         uint32 channel_id = 2;  // Sub-address within proxy
         uint32 onu_id = 3; // onu identifier; optional
-        uint32 onu_sesssion_id = 4; // session identifier for the ONU; optional
+        uint32 onu_session_id = 4; // session identifier for the ONU; optional
     };
 
     oneof address {