Skip to content

Commit

Permalink
Merge pull request #1284 from IRATI/e2ens
Browse files Browse the repository at this point in the history
E2ens
  • Loading branch information
edugrasa authored May 9, 2019
2 parents a7f5216 + a426030 commit df6c801
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 48 deletions.
130 changes: 90 additions & 40 deletions kernel/cidm.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,85 +29,135 @@
#include "cidm.h"
#include "common.h"

#define BITS_IN_BITMAP ((2 << BITS_PER_BYTE) * sizeof(cep_id_t))
#define MAX_CEP_ID (((2 << BITS_PER_BYTE) * sizeof(cep_id_t)) - 1)

struct cidm {
DECLARE_BITMAP(bitmap, BITS_IN_BITMAP);
struct list_head allocated_cep_ids;
cep_id_t last_allocated;
};

struct alloc_cepid {
struct list_head list;
cep_id_t cep_id;
};

struct cidm * cidm_create(void)
{
struct cidm * instance;
struct cidm * instance;

instance = rkmalloc(sizeof(*instance), GFP_KERNEL);
if (!instance)
return NULL;
instance = rkmalloc(sizeof(*instance), GFP_KERNEL);
if (!instance)
return NULL;

bitmap_zero(instance->bitmap, BITS_IN_BITMAP);
INIT_LIST_HEAD(&(instance->allocated_cep_ids));
instance->last_allocated = 0;

LOG_DBG("Instance initialized successfully (%zd bits)",
BITS_IN_BITMAP);
LOG_INFO("Instance initialized successfully (%zd cep-ids)",
MAX_CEP_ID);

return instance;
return instance;
}

int cidm_destroy(struct cidm * instance)
{
struct alloc_cepid * pos, * next;

if (!instance) {
LOG_ERR("Bogus instance passed, bailing out");
return -1;
}

list_for_each_entry_safe(pos, next, &instance->allocated_cep_ids, list) {
rkfree(pos);
}

rkfree(instance);

return 0;
}

cep_id_t cidm_allocate(struct cidm * instance)
int cidm_allocated(struct cidm * instance, cep_id_t cep_id)
{
cep_id_t id;
struct alloc_cepid * pos, * next;

if (!instance) {
LOG_ERR("Bogus instance passed, bailing out");
return cep_id_bad();
return -1;
}

id = (cep_id_t) bitmap_find_next_zero_area(instance->bitmap,
BITS_IN_BITMAP,
0, 1, 0);
LOG_DBG("The cidm bitmap find returned id %d (bad = %d)",
id, cep_id_bad());

LOG_DBG("Bits in bitmap %zd", BITS_IN_BITMAP);

if (!is_cep_id_ok(id)) {
LOG_WARN("Got an out-of-range cep-id (%d) from "
"the bitmap allocator, the bitmap is full ...", id);
return cep_id_bad();
list_for_each_entry_safe(pos, next, &instance->allocated_cep_ids, list) {
if (pos->cep_id == cep_id) {
return 1;
}
}

bitmap_set(instance->bitmap, id, 1);

LOG_DBG("Bitmap allocation completed successfully (id = %d)", id);

return id;
return 0;
}

int cidm_release(struct cidm * instance,
cep_id_t id)
cep_id_t cidm_allocate(struct cidm * instance)
{
if (!is_cep_id_ok(id)) {
LOG_ERR("Bad cep-id passed, bailing out");
return -1;
}
struct alloc_cepid * new_cep_id;
cep_id_t cep_id;

if (!instance) {
LOG_ERR("Bogus instance passed, bailing out");
return -1;
return port_id_bad();
}

if (instance->last_allocated == MAX_CEP_ID) {
cep_id = 1;
} else {
cep_id = instance->last_allocated + 1;
}

while (cidm_allocated(instance, cep_id)) {
if (cep_id == MAX_CEP_ID) {
cep_id = 1;
} else {
cep_id ++;
}
}

bitmap_clear(instance->bitmap, id, 1);
new_cep_id = rkmalloc(sizeof(*new_cep_id), GFP_ATOMIC);
if (!new_cep_id)
return cep_id_bad();

LOG_DBG("Bitmap release completed successfully");
INIT_LIST_HEAD(&(new_cep_id->list));
new_cep_id->cep_id = cep_id;
list_add(&(new_cep_id->list), &(instance->allocated_cep_ids));

return 0;
instance->last_allocated = cep_id;

LOG_DBG("Cep-id allocation completed successfully (id = %d)", cep_id);

return cep_id;
}

int cidm_release(struct cidm * instance,
cep_id_t id)
{
struct alloc_cepid * pos, * next;

if (!is_port_id_ok(id)) {
LOG_ERR("Bad cep-id passed, bailing out");
return -1;
}
if (!instance) {
LOG_ERR("Bogus instance passed, bailing out");
return -1;
}

list_for_each_entry_safe(pos, next, &instance->allocated_cep_ids, list) {
if (pos->cep_id == id) {
list_del(&pos->list);
rkfree(pos);
LOG_DBG("Cep-id release completed successfully (cep_id: %d)", id);

return 0;
}
}

LOG_ERR("Didn't find cep-id %d, returning error", id);

return 0;
}
2 changes: 2 additions & 0 deletions kernel/efcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -740,6 +740,8 @@ int efcp_connection_destroy(struct efcp_container * container,

LOG_DBG("EFCP connection destroy called");

/* FIXME: should wait 3*delta-t before destroying the connection */

if (!container) {
LOG_ERR("Bogus container passed, bailing out");
return -1;
Expand Down
18 changes: 11 additions & 7 deletions rinad/src/ipcp/flow-allocator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1449,7 +1449,7 @@ void FlowAllocatorInstance::submitDeallocate(const rina::FlowDeallocateRequestEv
TearDownFlowTimerTask * timerTask = new TearDownFlowTimerTask(this,
object_name_,
true);
timer->scheduleTask(timerTask, TearDownFlowTimerTask::DELAY);
timer->scheduleTask(timerTask, 0);
return;
}

Expand Down Expand Up @@ -1502,11 +1502,14 @@ void FlowAllocatorInstance::submitDeallocate(const rina::FlowDeallocateRequestEv
}
}

//3 Wait 2*MPL before tearing down the flow
// 3 Tear down the flow (don't need to wait for 2*MPL at the side that
// requested the flow deallocation). The spec says that the binding between
// app and EFCP needs to be removed right away (that is, the port), and EFCP
// state will be removed automatically after 2 or 3 delta-t.
TearDownFlowTimerTask * timerTask = new TearDownFlowTimerTask(this,
object_name_,
true);
timer->scheduleTask(timerTask, TearDownFlowTimerTask::DELAY);
timer->scheduleTask(timerTask, 0);
}

void FlowAllocatorInstance::deleteFlowRequestMessageReceived()
Expand All @@ -1528,12 +1531,15 @@ void FlowAllocatorInstance::deleteFlowRequestMessageReceived()
state = WAITING_2_MPL_BEFORE_TEARING_DOWN;
lock_.unlock();

//3 Wait 2*MPL before tearing down the flow
//Don't wait for 2*MPL anymore before tearing down the flow.
//The spec says that the binding between app and EFCP needs to
//be removed right away (that is, the port), and EFCP state will
//be removed automatically after 2 or 3 delta-t.
TearDownFlowTimerTask * timerTask = new TearDownFlowTimerTask(this,
object_name_,
true);

timer->scheduleTask(timerTask, TearDownFlowTimerTask::DELAY);
timer->scheduleTask(timerTask, 0);

if (flow_->internal) {
event = new rina::IPCPInternalFlowDeallocatedEvent(flow_->local_port_id);
Expand Down Expand Up @@ -1748,8 +1754,6 @@ void FlowAllocatorInstance::address_changed(unsigned int new_address,
}

//CLASS TEARDOWNFLOW TIMERTASK
const long TearDownFlowTimerTask::DELAY = 5000;

TearDownFlowTimerTask::TearDownFlowTimerTask(
FlowAllocatorInstance * flow_allocator_instance,
const std::string& flow_object_name, bool requestor)
Expand Down
1 change: 0 additions & 1 deletion rinad/src/ipcp/flow-allocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,6 @@ class FlowAllocatorInstance: public IFlowAllocatorInstance {

class TearDownFlowTimerTask: public rina::TimerTask {
public:
static const long DELAY;

TearDownFlowTimerTask(FlowAllocatorInstance * flow_allocator_instance,
const std::string& flow_object_name, bool requestor);
Expand Down

0 comments on commit df6c801

Please sign in to comment.