Process on how to add trust table in NS2.
I am assuming AODV protocol. In rtable.cc add below code
trust_entry::trust_entry()
{
//Initialize as per your need.
}
trust_entry::~trust_entry()
{
//Deconstruct as per your need.
}
trust_entry* trust_store::trust_lookup( nsaddr_t node_id)
{
trust_entry *rp = trusthead.lh_first;
for (; rp; rp = rp->trust_link.le_next) {
if (rp->node_id == node_id)
break;
}
return rp;
}
void trust_store::trust_delete( nsaddr_t node_id)
{
trust_entry *rp = trust_lookup(node_id);
if (rp)
{
LIST_REMOVE(rp, trust_link);
delete rp;
}
}
trust_entry*
trust_store::trust_insert( nsaddr_t node_id, nsaddr_t prev_node,nsaddr_t next_node,int32_t trust_value)
{
trust_entry *rp;
//assert(tr_lookup(dst_seq_no) == 0);
rp = new trust_entry;
assert(rp);
rp->node_id = node_id;
rp->prev_node = prev_node;
rp->next_node = next_node;
rp->trust_value = trust_value;
LIST_INSERT_HEAD(&trusthead, rp, trust_link);
return rp;
}
trust_entry* trust_store::trust_update( nsaddr_t node_id,nsaddr_t prev_node,nsaddr_t next_node, int32_t trust_value)
{ trust_delete(node_id);
trust_insert(node_id,prev_ node,next_node,trust_value);
}
In rtable.h add below codetrust_entry::trust_entry()
{
//Initialize as per your need.
}
trust_entry::~trust_entry()
{
//Deconstruct as per your need.
}
trust_entry* trust_store::trust_lookup(
{
trust_entry *rp = trusthead.lh_first;
for (; rp; rp = rp->trust_link.le_next) {
if (rp->node_id == node_id)
break;
}
return rp;
}
void trust_store::trust_delete(
{
trust_entry *rp = trust_lookup(node_id);
if (rp)
{
LIST_REMOVE(rp, trust_link);
delete rp;
}
}
trust_entry*
trust_store::trust_insert(
{
trust_entry *rp;
//assert(tr_lookup(dst_seq_no) == 0);
rp = new trust_entry;
assert(rp);
rp->node_id = node_id;
rp->prev_node = prev_node;
rp->next_node = next_node;
rp->trust_value = trust_value;
LIST_INSERT_HEAD(&trusthead, rp, trust_link);
return rp;
}
trust_entry* trust_store::trust_update(
{ trust_delete(node_id);
trust_insert(node_id,prev_
}
class trust_entry
{
friend class AODV;
friend class trust_store;
public:
trust_entry();
~trust_entry();
nsaddr_t node_id;
nsaddr_t prev_node;
nsaddr_t next_node;
int32_t trust_value;
protected:
LIST_ENTRY(trust_entry) trust_link;
};
class trust_store
{
public:
trust_store()
{
LIST_INIT(&trusthead);
}
trust_entry* head()
{
return trusthead.lh_first;
}
trust_entry* trust_insert(nsaddr_t node_id,nsaddr_t prev_node,nsaddr_t next_node,int32_t trust_value);
trust_entry* trust_lookup(nsaddr_t node_id);
void trust_delete(nsaddr_t node_id);
trust_entry* trust_update(nsaddr_t node_id,nsaddr_t prev_node,nsaddr_t next_node, int32_t trust_value);
private:
LIST_HEAD(trust_head, trust_entry) trusthead;
};
trust_store tstore;
No comments:
Post a Comment