flexran_agent_task_manager.h 4.95 KB
Newer Older
1 2 3 4 5
/*
 * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The OpenAirInterface Software Alliance licenses this file to You under
6
 * the OAI Public License, Version 1.1  (the "License"); you may not use this file
7 8 9 10 11 12 13 14 15 16 17 18 19 20
 * except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.openairinterface.org/?page_id=698
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *-------------------------------------------------------------------------------
 * For more information about the OpenAirInterface (OAI) Software Alliance:
 *      contact@openairinterface.org
 */ 
21

22 23
/*! \file flexran_agent_task_manager.h
 * \brief Implementation of scheduled tasks manager for the FlexRAN agent
24 25 26 27 28 29 30
 * \author Xenofon Foukas
 * \date January 2016
 * \version 0.1
 * \email: x.foukas@sms.ed.ac.uk
 * @ingroup _mac
 */

31 32
#ifndef FLEXRAN_AGENT_TASK_MANAGER_
#define FLEXRAN_AGENT_TASK_MANAGER_
33 34 35 36

#include <stdint.h>
#include <pthread.h>

37
#include "flexran.pb-c.h"
38

39
#include "flexran_agent_common.h"
40

41 42 43 44 45 46 47 48 49
#ifdef __cplusplus
extern "C" {
#endif

#define DEFAULT_CAPACITY 512
  
/**
 * The structure containing the enb agent task to be executed
 */
50
typedef struct flexran_agent_task_s {
51 52 53 54
  /* The frame in which the task needs to be executed */
  uint16_t frame_num;
  /* The subframe in which the task needs to be executed */
  uint8_t subframe_num;
55 56
  /* The task to be executed in the form of a Protocol__FlexranMessage */
  Protocol__FlexranMessage *task;
57
} flexran_agent_task_t;
58 59 60 61

/**
 * Priority Queue Structure for tasks
 */
62
typedef struct flexran_agent_task_queue_s {
63
  mid_t mod_id;
64 65 66 67 68 69 70 71 72
  /* The amount of allocated memory for agent tasks in the heap*/
  volatile size_t capacity;
  /* The actual size of the tasks heap at a certain time */
  volatile size_t count;
  /* The earliest frame that has a pending task */
  volatile uint16_t first_frame;
  /* The earliest subframe within the frame that has a pending task */
  volatile uint8_t first_subframe;
  /* An array of prioritized tasks stored in a heap */
73
  flexran_agent_task_t **task;
74
  /* A pointer to a comparator function, used to prioritize elements */
75
  int (*cmp)(mid_t mod_id, const flexran_agent_task_t *t1, const flexran_agent_task_t *t2);
76
  pthread_mutex_t *mutex;
77
} flexran_agent_task_queue_t;
78 79 80 81 82 83 84 85 86 87 88 89 90

typedef enum {
  HEAP_OK = 0,
  HEAP_EMPTY,
  HEAP_FAILED,
  HEAP_REALLOCERROR,
  HEAP_NOREALLOC,
  HEAP_FATAL,
} heapstatus_e;
  
/**
 * Allocate memory for a task in the queue
 */
91 92
flexran_agent_task_t *flexran_agent_task_create(Protocol__FlexranMessage *msg,
						uint16_t frame_num, uint8_t subframe_num);
93 94 95 96
  
/**
 * Free memory for a task of the queue
 */
97
void flexran_agent_task_destroy(flexran_agent_task_t *task);
98 99 100 101
  
/**
 * Allocate initial memory for storing the tasks
 */
102 103 104
  flexran_agent_task_queue_t *flexran_agent_task_queue_init(mid_t mod_id, size_t capacity,
							    int (*cmp)(mid_t mod_id, const flexran_agent_task_t *t1, 
								       const flexran_agent_task_t *t2));
105 106 107 108

/**
 * Allocate initial memory for storing the tasks using default parameters
 */
109
flexran_agent_task_queue_t *flexran_agent_task_queue_default_init(mid_t mod_id);  
110 111 112 113
  
/**
 * De-allocate memory for the tasks queue
 */
114
void flexran_agent_task_queue_destroy(flexran_agent_task_queue_t *queue);
115 116 117 118
  
/**
 * Insert task into the queue
 */
119
int flexran_agent_task_queue_put(flexran_agent_task_queue_t *queue, flexran_agent_task_t *task); 
120 121 122 123 124

/**
 * Remove the task with the highest priority from the queue
 * task becomes NULL if there is no task for the current frame and subframe
 */
125
int flexran_agent_task_queue_get_current_task(flexran_agent_task_queue_t *queue, flexran_agent_task_t **task);
126 127 128 129

/**
 * Check if the top priority task is for a specific frame and subframe
 */
130 131
int flexran_agent_task_queue_has_upcoming_task (flexran_agent_task_queue_t *queue,
						const uint16_t frame, const uint8_t subframe);
132 133 134 135

/**
 * Restructure heap after modifications
 */
136
void _flexran_agent_task_queue_heapify(flexran_agent_task_queue_t *queue, size_t idx);
137 138 139 140

/**
 * Reallocate memory once the heap reaches max size
 */
141
int _flexran_agent_task_queue_realloc_heap(flexran_agent_task_queue_t *queue);
142 143 144 145 146 147

/**
 * Compare two agent tasks based on frame and subframe
 * returns 0 if tasks t1, t2 have the same priority
 * return negative value if t1 needs to be executed after t2
 * return positive value if t1 preceeds t2
148
 * Need to give eNB id for the comparisson based on the current frame-subframe
149
 */
150
  int _flexran_agent_task_queue_cmp(mid_t mod_id, const flexran_agent_task_t *t1, const flexran_agent_task_t *t2);
151 152 153 154 155

#ifdef __cplusplus
}
#endif
  
156
#endif  /*FLEXRAN_AGENT_TASK_MANAGER_*/