This commit cleans up the python directory to ensure the adapters
and the cli runs properly.

Change-Id: Ic68a3ecd1f16a5af44296e3c020c808b185f4c18
diff --git a/python/adapters/kafka/adapter_proxy.py b/python/adapters/kafka/adapter_proxy.py
index fad1093..769de80 100644
--- a/python/adapters/kafka/adapter_proxy.py
+++ b/python/adapters/kafka/adapter_proxy.py
@@ -21,9 +21,9 @@
 import structlog
 from uuid import uuid4
 from twisted.internet.defer import inlineCallbacks, returnValue
-from adapters.kafka.container_proxy import ContainerProxy
-from adapters.protos import third_party
-from adapters.protos.core_adapter_pb2 import InterAdapterHeader, \
+from container_proxy import ContainerProxy
+from python.protos import third_party
+from python.protos.core_adapter_pb2 import InterAdapterHeader, \
     InterAdapterMessage
 import time
 
diff --git a/python/adapters/kafka/adapter_request_facade.py b/python/adapters/kafka/adapter_request_facade.py
index 67f7869..cbae56d 100644
--- a/python/adapters/kafka/adapter_request_facade.py
+++ b/python/adapters/kafka/adapter_request_facade.py
@@ -22,11 +22,11 @@
 from twisted.internet.defer import inlineCallbacks
 from zope.interface import implementer
 
-from adapters.interface import IAdapterInterface
-from adapters.protos.core_adapter_pb2 import IntType, InterAdapterMessage
-from adapters.protos.device_pb2 import Device
-from adapters.protos.openflow_13_pb2 import FlowChanges, FlowGroups, Flows, \
-    FlowGroupChanges
+from python.adapters.interface import IAdapterInterface
+from python.protos.core_adapter_pb2 import IntType, InterAdapterMessage, StrType, Error, ErrorCode
+from python.protos.device_pb2 import Device
+from python.protos.openflow_13_pb2 import FlowChanges, FlowGroups, Flows, \
+    FlowGroupChanges, ofp_packet_out
 
 
 class MacAddressError(BaseException):
@@ -68,7 +68,8 @@
             device.Unpack(d)
             return True, self.adapter.adopt_device(d)
         else:
-            return False, d
+            return False, Error(code=ErrorCode.INVALID_PARAMETERS,
+                                reason="device-invalid")
 
     def get_ofp_device_info(self, device):
         d = Device()
@@ -76,17 +77,22 @@
             device.Unpack(d)
             return True, self.adapter.get_ofp_device_info(d)
         else:
-            return False, d
+            return False, Error(code=ErrorCode.INVALID_PARAMETERS,
+                                reason="device-invalid")
 
     def get_ofp_port_info(self, device, port_no):
         d = Device()
         if device:
             device.Unpack(d)
         else:
-            return (False, d)
-
+            return False, Error(code=ErrorCode.INVALID_PARAMETERS,
+                                reason="device-invalid")
         p = IntType()
-        port_no.Unpack(p)
+        if port_no:
+            port_no.Unpack(p)
+        else:
+            return False, Error(code=ErrorCode.INVALID_PARAMETERS,
+                                reason="port-no-invalid")
 
         return True, self.adapter.get_ofp_port_info(d, p.val)
 
@@ -102,7 +108,8 @@
             device.Unpack(d)
             return True, self.adapter.disable_device(d)
         else:
-            return False, d
+            return False, Error(code=ErrorCode.INVALID_PARAMETERS,
+                                reason="device-invalid")
 
     def reenable_device(self, device):
         d = Device()
@@ -110,7 +117,8 @@
             device.Unpack(d)
             return True, self.adapter.reenable_device(d)
         else:
-            return False, d
+            return False, Error(code=ErrorCode.INVALID_PARAMETERS,
+                                reason="device-invalid")
 
     def reboot_device(self, device):
         d = Device()
@@ -118,7 +126,8 @@
             device.Unpack(d)
             return (True, self.adapter.reboot_device(d))
         else:
-            return (False, d)
+            return False, Error(code=ErrorCode.INVALID_PARAMETERS,
+                                reason="device-invalid")
 
     def download_image(self, device, request):
         return self.adapter.download_image(device, request)
@@ -144,7 +153,8 @@
             device.Unpack(d)
             return (True, self.adapter.delete_device(d))
         else:
-            return (False, d)
+            return False, Error(code=ErrorCode.INVALID_PARAMETERS,
+                                reason="device-invalid")
 
     def get_device_details(self, device):
         return self.adapter.get_device_details(device)
@@ -154,8 +164,8 @@
         if device:
             device.Unpack(d)
         else:
-            return (False, d)
-
+            return False, Error(code=ErrorCode.INVALID_PARAMETERS,
+                                reason="device-invalid")
         f = Flows()
         if flows:
             flows.Unpack(f)
@@ -171,8 +181,8 @@
         if device:
             device.Unpack(d)
         else:
-            return (False, d)
-
+            return False, Error(code=ErrorCode.INVALID_PARAMETERS,
+                                reason="device-invalid")
         f = FlowChanges()
         if flow_changes:
             flow_changes.Unpack(f)
@@ -194,6 +204,33 @@
         if msg:
             msg.Unpack(m)
         else:
-            return (False, m)
+            return False, Error(code=ErrorCode.INVALID_PARAMETERS,
+                                reason="msg-invalid")
 
         return (True, self.adapter.process_inter_adapter_message(m))
+
+
+    def receive_packet_out(self, deviceId, outPort, packet):
+        d_id = StrType()
+        if deviceId:
+            deviceId.Unpack(d_id)
+        else:
+            return False, Error(code=ErrorCode.INVALID_PARAMETERS,
+                                reason="deviceid-invalid")
+
+        op = IntType
+        if outPort:
+            outPort.Unpack(op)
+        else:
+            return False, Error(code=ErrorCode.INVALID_PARAMETERS,
+                                reason="outport-invalid")
+
+        p = ofp_packet_out()
+        if packet:
+            packet.Unpack(p)
+        else:
+            return False, Error(code=ErrorCode.INVALID_PARAMETERS,
+                                reason="packet-invalid")
+
+        return (True, self.adapter.receive_packet_out(d_id, op, p))
+
diff --git a/python/adapters/kafka/container_proxy.py b/python/adapters/kafka/container_proxy.py
index 79918cd..8c4e828 100644
--- a/python/adapters/kafka/container_proxy.py
+++ b/python/adapters/kafka/container_proxy.py
@@ -23,9 +23,9 @@
 from twisted.python import failure
 from zope.interface import implementer
 
-from adapters.common.utils.deferred_utils import DeferredWithTimeout, \
+from python.common.utils.deferred_utils import DeferredWithTimeout, \
     TimeOutError
-from adapters.common.utils.registry import IComponent
+from python.common.utils.registry import IComponent
 
 log = structlog.get_logger()
 
diff --git a/python/adapters/kafka/core_proxy.py b/python/adapters/kafka/core_proxy.py
index cc3f081..4bab30d 100644
--- a/python/adapters/kafka/core_proxy.py
+++ b/python/adapters/kafka/core_proxy.py
@@ -21,11 +21,11 @@
 from google.protobuf.message import Message
 from twisted.internet.defer import inlineCallbacks, returnValue
 
-from adapters.kafka.container_proxy import ContainerProxy
-from adapters.protos.common_pb2 import ID, ConnectStatus, OperStatus
-from adapters.protos.core_adapter_pb2 import StrType, BoolType, IntType
-from adapters.protos.device_pb2 import Device, Ports
-from adapters.protos.voltha_pb2 import CoreInstance
+from container_proxy import ContainerProxy
+from python.protos.common_pb2 import ID, ConnectStatus, OperStatus
+from python.protos.core_adapter_pb2 import StrType, BoolType, IntType, Packet
+from python.protos.device_pb2 import Device, Ports
+from python.protos.voltha_pb2 import CoreInstance
 
 log = structlog.get_logger()
 
@@ -243,7 +243,8 @@
         b = BoolType()
         b.val = init
         res = yield self.invoke(rpc="DevicePMConfigUpdate",
-                                device_pm_config=device_pm_config, init=b)
+                                device_pm_config=device_pm_config,
+                                init=b)
         returnValue(res)
 
     @ContainerProxy.wrap_request(None)
@@ -252,7 +253,8 @@
         log.debug("port_created")
         proto_id = ID()
         proto_id.id = device_id
-        res = yield self.invoke(rpc="PortCreated", device_id=proto_id,
+        res = yield self.invoke(rpc="PortCreated",
+                                device_id=proto_id,
                                 port=port)
         returnValue(res)
 
@@ -274,5 +276,16 @@
     def image_download_deleted(img_dnld):
         raise NotImplementedError()
 
-    def packet_in(device_id, egress_port_no, packet):
-        raise NotImplementedError()
+    def send_packet_in(self, device_id, port, packet):
+        log.debug("send_packet_in")
+        proto_id = ID()
+        proto_id.id = device_id
+        p = IntType()
+        p.val = port
+        pac = Packet()
+        pac.payload = packet
+        res = yield self.invoke(rpc="PacketIn",
+                                device_id=proto_id,
+                                port=p,
+                                packet=pac)
+        returnValue(res)
diff --git a/python/adapters/kafka/event_bus_publisher.py b/python/adapters/kafka/event_bus_publisher.py
index 011fdea..89b3385 100644
--- a/python/adapters/kafka/event_bus_publisher.py
+++ b/python/adapters/kafka/event_bus_publisher.py
@@ -25,7 +25,7 @@
 from google.protobuf.message import Message
 from simplejson import dumps
 
-from adapters.common.event_bus import EventBusClient
+from python.common.event_bus import EventBusClient
 
 log = structlog.get_logger()
 
diff --git a/python/adapters/kafka/kafka_inter_container_library.py b/python/adapters/kafka/kafka_inter_container_library.py
index 3f6f5eb..1d2b05c 100644
--- a/python/adapters/kafka/kafka_inter_container_library.py
+++ b/python/adapters/kafka/kafka_inter_container_library.py
@@ -25,10 +25,10 @@
     DeferredQueue, gatherResults
 from zope.interface import implementer
 
-from adapters.common.utils import asleep
-from adapters.common.utils.registry import IComponent
-from adapters.kafka.kafka_proxy import KafkaProxy, get_kafka_proxy
-from adapters.protos.core_adapter_pb2 import MessageType, Argument, \
+from python.common.utils import asleep
+from python.common.utils.registry import IComponent
+from kafka_proxy import KafkaProxy, get_kafka_proxy
+from python.protos.core_adapter_pb2 import MessageType, Argument, \
     InterContainerRequestBody, InterContainerMessage, Header, \
     InterContainerResponseBody
 
diff --git a/python/adapters/kafka/kafka_proxy.py b/python/adapters/kafka/kafka_proxy.py
index c11caa7..6dcb10f 100644
--- a/python/adapters/kafka/kafka_proxy.py
+++ b/python/adapters/kafka/kafka_proxy.py
@@ -23,9 +23,9 @@
 from twisted.internet.defer import inlineCallbacks, returnValue
 from zope.interface import implementer
 
-from adapters.common.utils.consulhelpers import get_endpoint_from_consul
-from adapters.common.utils.registry import IComponent
-from adapters.kafka.event_bus_publisher import EventBusPublisher
+from python.common.utils.consulhelpers import get_endpoint_from_consul
+from python.common.utils.registry import IComponent
+from event_bus_publisher import EventBusPublisher
 
 log = get_logger()