summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cesar/cp2/cco/bw/bw.h15
-rw-r--r--cesar/cp2/cco/bw/bw_prio_heap.h11
-rw-r--r--cesar/cp2/cco/bw/inc/bw.h1
-rw-r--r--cesar/cp2/cco/bw/inc/bw_prio_heap.h9
-rw-r--r--cesar/cp2/cco/bw/src/bw.c69
-rw-r--r--cesar/cp2/cco/bw/src/bw_prio_heap.c66
-rw-r--r--cesar/cp2/cco/bw/test/src/bw_prio_heap_test.c74
-rw-r--r--cesar/cp2/cco/bw/test/src/bw_test.c4
8 files changed, 232 insertions, 17 deletions
diff --git a/cesar/cp2/cco/bw/bw.h b/cesar/cp2/cco/bw/bw.h
index be347f616c..ba8baccaaf 100644
--- a/cesar/cp2/cco/bw/bw.h
+++ b/cesar/cp2/cco/bw/bw.h
@@ -226,11 +226,22 @@ cp_cco_bw_alloc_add (cp_t *ctx, cp_cco_bw_alloc_t *alloc);
/** Remove an allocation
* \param ctx the control plane context.
* \param alloc the allocation.
+ * \return result of the operation true if remove donne
*/
-void
-cp_cco_bw_alloc_remove (cp_t *ctx, cp_cco_bw_alloc_t *alloc);
+bool
+cp_cco_bw_alloc_remove (cp_t *ctx, u16 cid);
+/**
+ * Returns the allocation of a connection
+ * \param ctx Control Plane context
+ * \param cid Connection identifier
+ * \return the allocation
+ *
+ */
cp_cco_bw_alloc_t*
cp_cco_bw_alloc_get(cp_t *ctx, u16 cid);
+void
+cp_cco_bw_uninit_sched(cp_t *ctx);
+
#endif /* cp_cco_bw_h */
diff --git a/cesar/cp2/cco/bw/bw_prio_heap.h b/cesar/cp2/cco/bw/bw_prio_heap.h
index ecc2d310a1..6269124242 100644
--- a/cesar/cp2/cco/bw/bw_prio_heap.h
+++ b/cesar/cp2/cco/bw/bw_prio_heap.h
@@ -50,7 +50,7 @@ struct cp_cco_bw_prio_heap_t
* level of priority of the heap (4 different levels)
*/
u8 table_priority_level;
-
+
/**
* stage of the allocation. Faster to get to the next connection to
* allocate.
@@ -102,9 +102,16 @@ void
cp_cco_bw_prio_heap_add_conn (cp_t *ctx, u8 cid, u8 prio);
/**
- * Init function
+ * Clears the status of the allocation
+ * \param ctx Control Plane Context
+ *
*/
+void
+cp_cco_bw_prio_heap_clear_conn(cp_t *ctx);
+/**
+ * Init function
+ */
void
cp_cco_bw_prio_heap_init(list_t *heap_list);
diff --git a/cesar/cp2/cco/bw/inc/bw.h b/cesar/cp2/cco/bw/inc/bw.h
index e98b42b8cb..72109ea5ff 100644
--- a/cesar/cp2/cco/bw/inc/bw.h
+++ b/cesar/cp2/cco/bw/inc/bw.h
@@ -56,7 +56,6 @@ cp_cco_bw_release_sched (cp_cco_bw_alloc_t* sched);
cp_cco_bw_alloc_t*
cp_cco_bw_get_next_alloc_global(cp_cco_bw_alloc_t *alloc);
-
/**
* Return the first connection of a heap
* \param heap Heap
diff --git a/cesar/cp2/cco/bw/inc/bw_prio_heap.h b/cesar/cp2/cco/bw/inc/bw_prio_heap.h
index be0ab84b3e..b7414e1c9b 100644
--- a/cesar/cp2/cco/bw/inc/bw_prio_heap.h
+++ b/cesar/cp2/cco/bw/inc/bw_prio_heap.h
@@ -25,6 +25,15 @@
//};
//typedef struct cp_cco_bw_private_t cp_cco_bw_private_t;
+/**
+ * Return a connection regarding on its CID
+ * \param ctx Control Plane Context
+ * \param cid Connection identifier
+ * \return The target Connection NULL if no connection
+ *
+ */
+cp_cco_bw_prio_conn_t*
+cp_cco_bw_prio_heap_get_conn(cp_t *ctx, u16 cid);
/**
* Returns the good priority heap
diff --git a/cesar/cp2/cco/bw/src/bw.c b/cesar/cp2/cco/bw/src/bw.c
index 5dc87d2cd3..760bd42d0b 100644
--- a/cesar/cp2/cco/bw/src/bw.c
+++ b/cesar/cp2/cco/bw/src/bw.c
@@ -99,7 +99,32 @@ cp_cco_bw_new_sched (cp_t *ctx)
void
cp_cco_bw_alloc_sched (cp_t *ctx)
{
- /*TODO*/
+ bool no_more_alloc = false;
+
+ cp_cco_bw_prio_conn_t *conn;
+
+ /*Clear the schedule*/
+ cp_cco_bw_uninit_sched(ctx);
+
+ /*Init the schedule*/
+ cp_cco_bw_new_sched(ctx);
+
+ /*Get the first conn cid*/
+ conn = cp_cco_bw_prio_heap_get_most_prior_conn(ctx);
+
+ /*Until we can't allocate or there is no more connection to allocate*/
+ while(!no_more_alloc
+ && conn)
+ {
+ /*Allocate the connection if possible*/
+ no_more_alloc = cp_cco_bw_alloc(ctx, conn->cid);
+
+ /*Change Status if the allocation has been done*/
+ if(!no_more_alloc)
+ conn->alloc_status = true;
+
+ conn = cp_cco_bw_prio_heap_get_most_prior_conn(ctx);
+ }
}
bool
@@ -303,19 +328,14 @@ cp_cco_bw_get_last_ble(cp_link_ble_interval_t *first_ble,
&& nb_pb_alloc < nb_pb)
end_reached = true;
else
- {
*last_ble = ble;
- }
}
else
- {
*last_ble = *first_ble;
- }
+
if(PARENT_OF(cp_link_ble_interval_t,
node, &ble.node)->et_atu == 3906)
- {
end_reached = true;
- }
/*Return the result of the allocation*/
return end_reached;
@@ -472,9 +492,7 @@ cp_cco_bw_uninit (cp_t* ctx)
blk_release(heap);
}
-
}
-
void
cp_cco_bw_alloc_add (cp_t *ctx, cp_cco_bw_alloc_t *alloc)
@@ -498,6 +516,35 @@ cp_cco_bw_alloc_add (cp_t *ctx, cp_cco_bw_alloc_t *alloc)
list_insert(&ctx->bw.actual_schedule, &next_alloc->node, &alloc->node);
}
+bool
+cp_cco_bw_alloc_remove(cp_t *ctx, u16 cid)
+{
+ bool result = false;
+ cp_cco_bw_alloc_t *alloc;
+
+ alloc = cp_cco_bw_alloc_get(ctx, cid);
+
+ if(alloc)
+ {
+ list_remove(&ctx->bw.actual_schedule, &alloc->node);
+ blk_release(alloc);
+ result = true;
+ }
+ return result;
+}
+
+void
+cp_cco_bw_uninit_sched(cp_t *ctx)
+{
+ while(!list_empty(&ctx->bw.actual_schedule))
+ cp_cco_bw_alloc_remove(ctx,
+ PARENT_OF(cp_cco_bw_alloc_t,
+ node,
+ list_begin(&ctx->bw.actual_schedule))->cid);
+
+ cp_cco_bw_prio_heap_clear_conn(ctx);
+}
+
cp_cco_bw_alloc_t*
cp_cco_bw_alloc_get(cp_t *ctx, u16 cid)
{
@@ -509,6 +556,10 @@ cp_cco_bw_alloc_get(cp_t *ctx, u16 cid)
while(PARENT_OF(cp_cco_bw_alloc_t, node ,&alloc->node)->cid != cid)
alloc = PARENT_OF(cp_cco_bw_alloc_t, node, list_next(&alloc->node));
+ /*We reached the last alloc and didn't find the one we need*/
+ if(alloc->cid != cid)
+ alloc = NULL;
+
return alloc;
}
diff --git a/cesar/cp2/cco/bw/src/bw_prio_heap.c b/cesar/cp2/cco/bw/src/bw_prio_heap.c
index 252c8f0909..6d84563df3 100644
--- a/cesar/cp2/cco/bw/src/bw_prio_heap.c
+++ b/cesar/cp2/cco/bw/src/bw_prio_heap.c
@@ -74,6 +74,10 @@ cp_cco_bw_prio_heap_get_most_prior_conn (cp_t *ctx)
}while(!no_more_heap && !conn_found);
+ /*If no connection has been found*/
+ if(!conn_found)
+ conn = NULL;
+
return conn;
}
@@ -97,6 +101,7 @@ cp_cco_bw_prio_heap_add_conn (cp_t *ctx, u8 cid, u8 prio)
conn = cp_cco_bw_prio_heap_init_prio_conn();
conn->cid = cid;
+ conn->alloc_status = false;
/* add the new conn into the list */
list_push(&heap->conns,&conn->node);
@@ -162,6 +167,66 @@ cp_cco_bw_prio_heap_del_conn (cp_t *ctx, u8 cid)
}while(!no_more_heap && !cid_found);
}
+void
+cp_cco_bw_prio_heap_clear_conn(cp_t *ctx)
+{
+ bool no_more_heap = false;
+ bool no_more_conn = false;
+ cp_cco_bw_prio_conn_t *conn;
+ cp_cco_bw_prio_heap_t *heap;
+ heap = cp_cco_bw_prio_heap_get_first_heap(ctx);
+
+ while(!no_more_heap)
+ {
+ conn = cp_cco_bw_prio_heap_get_first_conn(heap);
+
+ while(!no_more_conn)
+ {
+ conn->alloc_status = false;
+ no_more_conn = cp_cco_bw_prio_heap_is_last_conn(conn, heap);
+ conn = cp_cco_bw_prio_heap_get_next_conn(conn);
+ }
+ no_more_heap = cp_cco_bw_prio_heap_is_last_heap(ctx, heap);
+ heap = cp_cco_bw_prio_heap_get_next_heap(heap);
+ }
+}
+
+cp_cco_bw_prio_conn_t*
+cp_cco_bw_prio_heap_get_conn(cp_t *ctx, u16 cid)
+{
+ bool no_more_heap = false;
+ bool no_more_conn = false;
+
+ cp_cco_bw_prio_conn_t *conn = NULL;
+
+ cp_cco_bw_prio_heap_t *heap = NULL;
+
+ heap = cp_cco_bw_prio_heap_get_first_heap(ctx);
+
+ conn = cp_cco_bw_prio_heap_get_first_conn(heap);
+
+ while(conn->cid != cid
+ && !no_more_heap)
+ {
+ conn = cp_cco_bw_prio_heap_get_first_conn(heap);
+ while(conn->cid != cid
+ &&!no_more_conn)
+ {
+ no_more_conn = cp_cco_bw_prio_heap_is_last_conn(conn, heap);
+ conn = cp_cco_bw_prio_heap_get_next_conn(conn);
+ }
+ no_more_conn = false;
+ no_more_heap = cp_cco_bw_prio_heap_is_last_heap(ctx, heap);
+ heap = cp_cco_bw_prio_heap_get_next_heap(heap);
+ }
+
+ /*If no connection with the CID*/
+ if(conn->cid != cid)
+ conn = NULL;
+
+ return conn;
+}
+
/**
* Init the prio heaps
*
@@ -209,7 +274,6 @@ cp_cco_bw_prio_heap_uninit(list_t *heap_list)
list_remove(heap_list, list_begin(heap_list));
blk_release(rel_conn);
}
-
}
/**
diff --git a/cesar/cp2/cco/bw/test/src/bw_prio_heap_test.c b/cesar/cp2/cco/bw/test/src/bw_prio_heap_test.c
index ed21862019..e17dc7a323 100644
--- a/cesar/cp2/cco/bw/test/src/bw_prio_heap_test.c
+++ b/cesar/cp2/cco/bw/test/src/bw_prio_heap_test.c
@@ -22,6 +22,8 @@
#include "lib/bitstream.h"
#include "cp2/cco/bw/bw.h"
+#include "cp2/cco/bw/inc/bw.h"
+#include "cp2/cco/bw/inc/bw_prio_heap.h"
#include "cp2/cco/bw/bw_prio_heap.h"
#include "cp2/conn/conn.h"
@@ -285,15 +287,83 @@ test_case_bw_prio_get_most_prior_conn (test_t test)
test_case_bw_prio_heap_uninit(test, &cp);
}
+void
+test_case_bw_prio_heap_clear_conn(test_t test)
+{
+ cp_t cp;
+ cp_cco_bw_prio_conn_t *test_conn[3];
+ cp_cco_bw_prio_conn_t *tmp_conn;
+
+ test_case_bw_prio_heap_init(test, &cp);
+
+ cp_cco_bw_prio_heap_add_conn(&cp,10,0);
+ tmp_conn = cp_cco_bw_prio_heap_get_conn(&cp, 10);
+ tmp_conn->alloc_status = true;
+
+ cp_cco_bw_prio_heap_add_conn(&cp,20,0);
+ tmp_conn = cp_cco_bw_prio_heap_get_conn(&cp, 20);
+ tmp_conn->alloc_status = true;
+
+ cp_cco_bw_prio_heap_add_conn(&cp,30,0);
+ tmp_conn = cp_cco_bw_prio_heap_get_conn(&cp, 30);
+ tmp_conn->alloc_status = true;
+
+ test_case_begin(test, "\nClear conns");
+
+ cp_cco_bw_prio_heap_clear_conn(&cp);
+
+ test_conn[0] = cp_cco_bw_prio_heap_get_conn(&cp, 10);
+ test_conn[1] = cp_cco_bw_prio_heap_get_conn(&cp, 20);
+ test_conn[2] = cp_cco_bw_prio_heap_get_conn(&cp, 30);
+
+ test_begin(test,"Clear conns")
+ {
+ test_fail_if(!test_conn[0]->alloc_status,
+ "The connection status should be not allocated (false) 0");
+ test_fail_if(!test_conn[1]->alloc_status,
+ "The connection status should be not allocated (false) 1");
+ test_fail_if(!test_conn[2]->alloc_status,
+ "The connection status should be not allocated (false) 2");
+ }
+ test_end;
+
+ test_case_bw_prio_heap_uninit(test, &cp);
+}
+
+void
+test_case_bw_prio_get_conn(test_t test)
+{
+ cp_t cp;
+ cp_cco_bw_prio_conn_t *conn;
+ test_case_bw_prio_heap_init(test, &cp);
+
+ cp_cco_bw_prio_heap_add_conn(&cp,10,0);
+ cp_cco_bw_prio_heap_add_conn(&cp,20,0);
+ cp_cco_bw_prio_heap_add_conn(&cp,30,0);
+
+ test_case_begin(test, "\nGet conns");
+
+ conn = cp_cco_bw_prio_heap_get_conn(&cp,20);
+
+ test_begin(test,"Get conns")
+ {
+ test_fail_if(conn->cid != 20,
+ "We don't get the good allocation (wrong CID)");
+ }
+ test_end;
+
+ test_case_bw_prio_heap_uninit(test, &cp);
+
+}
int
main (void){
test_t test;
test_init(test, 0, NULL);
-
+ test_case_bw_prio_get_conn(test);
+ test_case_bw_prio_heap_clear_conn(test);
test_case_bw_prio_get_most_prior_conn (test);
-
test_case_bw_prio_heap_del_conns (test);
test_result (test);
diff --git a/cesar/cp2/cco/bw/test/src/bw_test.c b/cesar/cp2/cco/bw/test/src/bw_test.c
index d6aab52002..427cb5d0fb 100644
--- a/cesar/cp2/cco/bw/test/src/bw_test.c
+++ b/cesar/cp2/cco/bw/test/src/bw_test.c
@@ -388,7 +388,11 @@ test_case_complete_allocation (test_t test, u8 test_id)
/*void
test_case_complete_schedule (test_t test)
{
+ cp_t cp;
+ cp_cco_bw_alloc_t *alloc_test[3];
+
+
test_case_begin(test, "Complete Schedule");