//---------------------------------------------------------------------------------------------------------------------
pmip_entry_t *pmip_cache_add(pmip_entry_t * bce)
{
    int ret = 1;
    int mutex_return_code;
    assert(bce);
    bce->unreach = 0;
    mutex_return_code = pthread_rwlock_wrlock(&pmip_lock);
    last_BID++;
    bce->BID=last_BID;

    if (mutex_return_code != 0) {
        dbg("pthread_rwlock_wrlock(&pmip_lock) %s\n", strerror(mutex_return_code));
    }
    if ((ret = __pmipcache_insert(bce)) != 0) {
        pthread_rwlock_unlock(&pmip_lock);
        dbg("WARNING: PMIP ENTRY NOT INSERTED..\n");
        return NULL;
    }
    dbg("Making Entry\n");
    dbg("PMIP cache entry for: %x:%x:%x:%x:%x:%x:%x:%x with type %d is added\n", NIP6ADDR(&bce->mn_hw_address), bce->type);
    bce->n_rets_counter = conf.MaxMessageRetransmissions;
    dbg("Retransmissions counter intialized: %d\n", bce->n_rets_counter);
    if (bce->type == BCE_PMIP) {
        pmip_cache_start(bce);
    }
    mutex_return_code = pthread_rwlock_unlock(&pmip_lock);
    if (mutex_return_code != 0) {
        dbg("pthread_rwlock_unlock(&pmip_lock) %s\n", strerror(mutex_return_code));
    }
    return bce;
}
//---------------------------------------------------------------------------------------------------------------------
pmip_entry_t *pmip_cache_add(pmip_entry_t * bce)
{
	//dbg("inside pmip_cache_add\n");
	int ret = 1;
	assert(bce);
	//dbg("after assertion\n");
	bce->unreach = 0;
	pthread_rwlock_wrlock(&pmip_lock);
	if ((ret = __pmipcache_insert(bce)) != 0) {
		pthread_rwlock_unlock(&pmip_lock);
		dbg("WARNING: PMIP ENTRY NOT INSERTED..\n");
		return NULL;
	}
	//dbg("Making Entry\n");
	//dbg("PMIP cache entry for: %x:%x:%x:%x:%x:%x:%x:%x with type %d is added\n", NIP6ADDR(&bce->mn_hw_address), bce->type);
	bce->n_rets_counter = conf.MaxMessageRetransmissions;
	//dbg("Retransmissions counter intialized: %d\n", bce->n_rets_counter);
	if (bce->type == BCE_PMIP) {
		pmip_cache_start(bce);
	}
	pthread_rwlock_unlock(&pmip_lock);
	return bce;
}