[ 3195 ] Remove duplicate method add_port

Update to the device operations as follows:
1) Add a few test scenarios to test the device state transitions
2) Check whether there is a callback before removing it from the queue
3) Fix a port reference issue when disabling an ONU
4) Update the CLI to handle exceptions from the grpc server

Change-Id: Ic7f41e80279f41d9a4575da5dd49de11294a22d5
diff --git a/voltha/adapters/ponsim_olt/ponsim_olt.py b/voltha/adapters/ponsim_olt/ponsim_olt.py
index 3fed5c4..aecac9f 100644
--- a/voltha/adapters/ponsim_olt/ponsim_olt.py
+++ b/voltha/adapters/ponsim_olt/ponsim_olt.py
@@ -185,6 +185,7 @@
         self.io_port = None
         self.logical_device_id = None
         self.nni_port = None
+        self.ofp_port_no = None
         self.interface = registry('main').get_args().interface
 
     def __del__(self):
@@ -257,6 +258,7 @@
         )
         ld_initialized = self.adapter_agent.create_logical_device(ld)
         cap = OFPPF_1GB_FD | OFPPF_FIBER
+        self.ofp_port_no = info.nni_port
         self.adapter_agent.add_logical_port(ld_initialized.id, LogicalPort(
             id='nni',
             ofp_port=ofp_port(
@@ -401,12 +403,12 @@
         # Disable all child devices first
         self.adapter_agent.disable_all_child_devices(self.device_id)
 
-        # # Remove all child devices
-        # self.adapter_agent.remove_all_child_devices(self.device_id)
-
         # Remove the peer references from this device
         self.adapter_agent.delete_all_peer_references(self.device_id)
 
+        # Set all ports to disabled
+        self.adapter_agent.disable_all_ports(self.device_id)
+
         # close the frameio port
         registry('frameio').close_port(self.io_port)
 
@@ -427,6 +429,9 @@
         device.connect_status = ConnectStatus.REACHABLE
         self.adapter_agent.update_device(device)
 
+        # Set all ports to enabled
+        self.adapter_agent.enable_all_ports(self.device_id)
+
         ld = LogicalDevice(
             # not setting id and datapth_id will let the adapter agent pick id
             desc=ofp_desc(
@@ -453,11 +458,9 @@
         self.adapter_agent.add_logical_port(ld_initialized.id, LogicalPort(
             id='nni',
             ofp_port=ofp_port(
-                # port_no=info.nni_port,
-                # hw_addr=mac_str_to_tuple('00:00:00:00:00:%02x' % info.nni_port),
-                port_no=self.nni_port.port_no,
+                port_no=self.ofp_port_no,
                 hw_addr=mac_str_to_tuple(
-                    '00:00:00:00:00:%02x' % self.nni_port.port_no),
+                    '00:00:00:00:00:%02x' % self.ofp_port_no),
                 name='nni',
                 config=0,
                 state=OFPPS_LIVE,
@@ -481,7 +484,6 @@
         # Reenable all child devices
         self.adapter_agent.reenable_all_child_devices(device.id)
 
-
         # finally, open the frameio port to receive in-band packet_in messages
         self.log.info('registering-frameio')
         self.io_port = registry('frameio').open_port(