def addTo_RM_FlowTable(self, finished_taskList, releaseTime,
                           debug_which_cpu):
        debug_ftl = [x.get_id() for x in finished_taskList]
        Debug.PPrint(
            "%f" % self.env.now + "," + self.label + "," +
            'addTo_RM_FlowTable::, : Enter - fin_tsk_lst=' + str(debug_ftl) +
            ", which_cpu=" + str(debug_which_cpu),
            DebugCat.DEBUG_CAT_MAPPERINFO)

        num_flows_added = []
        for each_task in finished_taskList:

            task_mapped_nodeid = self.RM_instance.task_mapping_table[
                each_task.get_id()]['node_id']
            child_tasks_ids = each_task.get_children()  #ids
            child_tasks_ixs = each_task.get_children_frames()  #ixs
            child_tasks_id_ix_rel = self._get_tid_tix_dict(
                child_tasks_ids, child_tasks_ixs)

            # find unique flows
            # e.g. if task has two children both mapped on same node, then we only have 1 flow
            dst_node_list = []
            temp_destinations_dict = {}
            for each_child_id in child_tasks_ids:
                child_task_nodeid = self.RM_instance.task_mapping_table[
                    each_child_id]['node_id']

                if (child_task_nodeid not in temp_destinations_dict):
                    temp_destinations_dict[child_task_nodeid] = [each_child_id]
                else:
                    temp_destinations_dict[child_task_nodeid].append(
                        each_child_id)

                if (child_task_nodeid not in dst_node_list):
                    dst_node_list.append(child_task_nodeid)

                    #                    ## DEBUG ##
                    #                    if(each_task.get_id() == 721):
                    #                        print "each_child_id = " + str(each_child_id)
                    #                        print "child_task_nodeid = " + str(child_task_nodeid)
                    #                        pprint.pprint(temp_destinations_dict)
                    #                        print "dst_node_list = " + str(dst_node_list)
                    #                    ###########

                    # new flow
                    if (child_task_nodeid != task_mapped_nodeid):
                        nextid = self.RM_instance.flow_table.nextid
                        route = self.RM_instance.interconnect.getRouteXY(
                            task_mapped_nodeid, child_task_nodeid)
                        priority = each_task.get_priority() + (
                            self.RM_instance.flow_priority_offset +
                            100) + nextid
                        basicLatency = self.RM_instance.interconnect.getRouteCostXY(
                            task_mapped_nodeid, child_task_nodeid,
                            each_task.get_completedTaskSize())
                        payload = each_task.get_completedTaskSize()
                        endTime_wrt_BL = releaseTime + basicLatency

                        newflow = NoCFlow(
                            nextid,
                            each_task,
                            each_task.get_id(),
                            temp_destinations_dict[child_task_nodeid],
                            self._get_tixs_from_tids(
                                temp_destinations_dict[child_task_nodeid],
                                child_tasks_id_ix_rel),
                            task_mapped_nodeid,
                            child_task_nodeid,
                            route,
                            priority,
                            None,
                            basicLatency,
                            payload,
                            endTime_wrt_BL,
                            type=FlowType.FLOWTYPE_DATA)

                        #                         ## DEBUG ##
                        #                        if(each_task.get_id() == 721):
                        #                            print newflow
                        #                        ###########

                        # add to the flow table
                        self.RM_instance.flow_table.addFlow(
                            newflow, releaseTime, basicLatency)
                        num_flows_added.append(newflow.get_id())

        # update the table
        if (len(num_flows_added) > 0):
            self.RM_instance.flow_table.updateTable(
                fire=True)  # one update for many additions
    def addTo_RM_FlowTable_HEVC_FrameLevel(self, finished_taskList,
                                           releaseTime, debug_which_cpu):
        debug_ftl = [x.get_id() for x in finished_taskList]
        Debug.PPrint(
            "%f" % self.env.now + "," + self.label + "," +
            'addTo_RM_FlowTable::, : Enter - fin_tsk_lst=' + str(debug_ftl) +
            ", which_cpu=" + str(debug_which_cpu),
            DebugCat.DEBUG_CAT_MAPPERINFO)

        TEMP_BYTE_OFFSET = 32

        num_flows_added = []
        for each_task in finished_taskList:

            task_mapped_nodeid = self.RM_instance.task_mapping_table[
                each_task.get_id()]['node_id']
            child_tasks_info = each_task.get_expected_data_to_children(
            )  # children and the data payload size

            # if we are sending two flows to the same node, corresponding to two child tasks,
            # then we have to make sure the payload is different (i.e. TEMP_BYTE_OFFSET), else there will be event firing isues
            temp_node_id_payload_dict = {}
            for each_child_id, each_child_payload in child_tasks_info.iteritems(
            ):
                child_task_nodeid = self.RM_instance.task_mapping_table[
                    each_child_id]['node_id']

                flow_payload = each_child_payload

                if child_task_nodeid in temp_node_id_payload_dict:  # redundancy
                    if (each_child_payload == temp_node_id_payload_dict[
                            child_task_nodeid]):  # same payload
                        temp_node_id_payload_dict[
                            child_task_nodeid] += TEMP_BYTE_OFFSET
                        flow_payload += TEMP_BYTE_OFFSET
                else:
                    temp_node_id_payload_dict[
                        child_task_nodeid] = each_child_payload

                # new flow
                if (child_task_nodeid != task_mapped_nodeid):
                    nextid = self.RM_instance.flow_table.nextid
                    route = self.RM_instance.interconnect.getRouteXY(
                        task_mapped_nodeid, child_task_nodeid)
                    priority = each_task.get_priority() + (
                        self.RM_instance.flow_priority_offset + 100) + nextid
                    payload = flow_payload
                    basicLatency = self.RM_instance.interconnect.getRouteCostXY(
                        task_mapped_nodeid, child_task_nodeid, payload)
                    payload_metadata = {
                        'child_id': each_child_id,
                        'each_child_payload': each_child_payload,
                    }
                    endTime_wrt_BL = releaseTime + basicLatency

                    newflow = NoCFlow(
                        nextid,
                        each_task,
                        each_task.get_id(),
                        [each_child_id],
                        None,  #self._get_tixs_from_tids(temp_destinations_dict[child_task_nodeid], child_tasks_id_ix_rel),
                        task_mapped_nodeid,
                        child_task_nodeid,
                        route,
                        priority,
                        None,
                        basicLatency,
                        payload,
                        endTime_wrt_BL,
                        type=FlowType.FLOWTYPE_DATA_HEVC,
                        payload_metadata=payload_metadata)

                    # add to the flow table
                    self.RM_instance.flow_table.addFlow(
                        newflow, releaseTime, basicLatency)
                    num_flows_added.append(newflow.get_id())

        # update the table
        if (len(num_flows_added) > 0):
            self.RM_instance.flow_table.updateTable(
                fire=True)  # one update for many additions