VOL-1077 added NNI port and management port distinction

Change-Id: Ie24e05aa927661bb9a227d04e565018ce5523cd6
diff --git a/voltha/adapters/ponsim_olt/ponsim_olt.py b/voltha/adapters/ponsim_olt/ponsim_olt.py
index 64357df..b84209c 100644
--- a/voltha/adapters/ponsim_olt/ponsim_olt.py
+++ b/voltha/adapters/ponsim_olt/ponsim_olt.py
@@ -21,6 +21,7 @@
 from uuid import uuid4
 
 import arrow
+import voltha.core.flow_decomposer as fd
 import grpc
 import json
 import structlog
@@ -36,6 +37,7 @@
 from voltha.adapters.iadapter import OltAdapter
 from voltha.core.logical_device_agent import mac_str_to_tuple
 from voltha.protos import third_party
+from voltha.protos import openflow_13_pb2 as ofp
 from voltha.protos import ponsim_pb2
 from voltha.protos.common_pb2 import OperStatus, ConnectStatus, AdminState
 from voltha.protos.device_pb2 import Port, Device, PmConfig, PmConfigs
@@ -638,9 +640,34 @@
                       frame_len=len(frame))
         self._rcv_frame(frame)
 
+    # VOLTHA's flow decomposition removes the information about which flows
+    # are trap flows where traffic should be forwarded to the controller.
+    # We'll go through the flows and change the output port of flows that we
+    # know to be trap flows to the OF CONTROLLER port.
     def update_flow_table(self, flows):
         stub = ponsim_pb2.PonSimStub(self.get_channel())
         self.log.info('pushing-olt-flow-table')
+        for flow in flows:
+            classifier_info = {}
+            for field in fd.get_ofb_fields(flow):
+                if field.type == fd.ETH_TYPE:
+                    classifier_info['eth_type'] = field.eth_type
+                    self.log.debug('field-type-eth-type',
+                                eth_type=classifier_info['eth_type'])
+                elif field.type == fd.IP_PROTO:
+                    classifier_info['ip_proto'] = field.ip_proto
+                    self.log.debug('field-type-ip-proto',
+                                ip_proto=classifier_info['ip_proto'])
+            if ('ip_proto' in classifier_info and (
+                classifier_info['ip_proto'] == 17 or
+                classifier_info['ip_proto'] == 2)) or (
+                      'eth_type' in classifier_info and
+                      classifier_info['eth_type'] == 0x888e):
+                for action in fd.get_actions(flow):
+                    if action.type == ofp.OFPAT_OUTPUT:
+                        action.output.port = ofp.OFPP_CONTROLLER
+            self.log.info('out_port', out_port=fd.get_out_port(flow))
+
         stub.UpdateFlowTable(FlowTable(
             port=0,
             flows=flows