Main Page | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Compound Members | File Members

FlowTable Class Reference

#include <flowstruct.h>

Collaboration diagram for FlowTable:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 FlowTable (int size_=FLOW_TABLE_SIZE)
 ~FlowTable ()
TableEntryoperator[] (int index)
int find (nsaddr_t source, nsaddr_t destination, u_int16_t flow)
int find (nsaddr_t source, nsaddr_t destination, const Path &route)
int createEntry (nsaddr_t source, nsaddr_t destination, u_int16_t flow)
bool defaultFlow (nsaddr_t source, nsaddr_t destination, u_int16_t &flow)
u_int16_t generateNextFlowId (nsaddr_t destination, bool allowDefault)
void noticeDeadLink (const ID &from, const ID &to)
void cleanup ()
void setNetAddr (nsaddr_t net_id)

Private Member Functions

void grow ()

Private Attributes

TableEntrytable
int size
int maxSize
u_int16_t counter
nsaddr_t net_addr
DRTable DRTab

Constructor & Destructor Documentation

FlowTable::FlowTable int  size_ = FLOW_TABLE_SIZE  ) 
 

Definition at line 30 of file flowstruct.cc.

References counter, maxSize, size, and table.

00030                               : DRTab(size_) {
00031         assert (size_ > 0);
00032         size = 0;
00033         maxSize = size_;
00034         table = new TableEntry[size_];
00035         counter = 0;
00036 }

FlowTable::~FlowTable  ) 
 

Definition at line 38 of file flowstruct.cc.

References table.

00038                       {
00039         delete table;
00040 }


Member Function Documentation

void FlowTable::cleanup  ) 
 

Definition at line 130 of file flowstruct.cc.

References checkDefaultFlow(), Scheduler::clock(), DRTab, Scheduler::instance(), size, table, and TableEntry::timeout.

Referenced by DSRAgent::handleFlowForwarding(), and DSRAgent::sendOutPacketWithRoute().

00130                         {
00131         int front, back;
00132         double now = Scheduler::instance().clock();
00133 
00134         return; // it's messing up path orders...
00135 
00136         // init front to the first expired entry
00137         for (front=0; (front<size) && (table[front].timeout >= now); front++)
00138                 ;
00139 
00140         // init back to the last unexpired entry
00141         for (back = size-1; (front<back) && (table[back].timeout < now); back--)
00142                 checkDefaultFlow(DRTab, table[back]);
00143 
00144         while (front < back) {
00145                 checkDefaultFlow(DRTab, table[front]);
00146                 bcopy(table+back, table+front, sizeof(TableEntry)); // swap
00147                 back--;
00148 
00149                 // next expired entry
00150                 while ((front<back) && (table[front].timeout >= now))
00151                         front++;
00152                 while ((front<back) && (table[back].timeout < now)) {
00153                         checkDefaultFlow(DRTab, table[back]);
00154                         back--;
00155                 }
00156         }
00157 
00158         size = back+1;
00159 }

Here is the call graph for this function:

int FlowTable::createEntry nsaddr_t  source,
nsaddr_t  destination,
u_int16_t  flow
 

Definition at line 88 of file flowstruct.cc.

References DRTab, find(), grow(), DRTable::insert(), maxSize, size, and table.

Referenced by DSRAgent::handleFlowForwarding(), and DSRAgent::sendOutPacketWithRoute().

00089                                            {
00090         if (find(source, destination, flow) != -1)
00091                 return -1;
00092         if (size == maxSize)
00093                 grow();
00094         if (size == maxSize)
00095                 return -1;
00096 
00097         table[size].sourceIP = source;
00098         table[size].destinationIP = destination;
00099         table[size].flowId = flow;
00100 
00101         if (flow & 1)
00102                 DRTab.insert(source, destination, flow);
00103 
00104         return size++;
00105 }

Here is the call graph for this function:

bool FlowTable::defaultFlow nsaddr_t  source,
nsaddr_t  destination,
u_int16_t flow
 

Definition at line 165 of file flowstruct.cc.

References DRTab, and DRTable::find().

Referenced by DSRAgent::handleDefaultForwarding(), DSRAgent::processFlowARS(), DSRAgent::processUnknownFlowError(), DSRAgent::sendOutPacketWithRoute(), and DSRAgent::xmitFlowFailed().

00166                                              {
00167         return DRTab.find(source, destination, flow);
00168 }

Here is the call graph for this function:

int FlowTable::find nsaddr_t  source,
nsaddr_t  destination,
const Path route
 

Definition at line 58 of file flowstruct.cc.

References TableEntry::destinationIP, size, TableEntry::sourceIP, and table.

00058                                                                             {
00059         register int i;
00060         for (i=size-1; i>=0; i--)
00061                 if (table[i].sourceIP == source &&
00062                     table[i].destinationIP == destination &&
00063                     table[i].sourceRoute == route)
00064                         break;
00065 
00066         return i;
00067 }

int FlowTable::find nsaddr_t  source,
nsaddr_t  destination,
u_int16_t  flow
 

Definition at line 47 of file flowstruct.cc.

References TableEntry::destinationIP, size, TableEntry::sourceIP, and table.

Referenced by createEntry(), DSRAgent::handleDefaultForwarding(), DSRAgent::handleFlowForwarding(), DSRAgent::processFlowARS(), DSRAgent::processUnknownFlowError(), DSRAgent::sendOutPacketWithRoute(), and DSRAgent::xmitFlowFailed().

00047                                                                          {
00048         register int i;
00049         for (i=size-1; i>=0; i--)
00050                 if (table[i].sourceIP == source &&
00051                     table[i].destinationIP == destination &&
00052                     table[i].flowId == flow)
00053                         break;
00054 
00055         return i;
00056 }

u_int16_t FlowTable::generateNextFlowId nsaddr_t  destination,
bool  allowDefault
 

Definition at line 80 of file flowstruct.cc.

References counter, and u_int16_t.

Referenced by DSRAgent::sendOutPacketWithRoute().

00080                                                                                {
00081         if ((counter&1)^allowDefault) // make sure parity is correct
00082                 counter++;
00083 
00084         assert((counter & 1) == allowDefault);
00085         return counter++;
00086 }

void FlowTable::grow  )  [private]
 

Definition at line 69 of file flowstruct.cc.

References maxSize, and table.

Referenced by createEntry().

00069                      {
00070         assert(0);
00071         TableEntry *temp;
00072         if (!(temp = new TableEntry[maxSize*2]))
00073                 return;
00074         bcopy(table, temp, sizeof(TableEntry)*maxSize);
00075         delete table;
00076         maxSize *= 2;
00077         table = temp;
00078 }

void FlowTable::noticeDeadLink const ID from,
const ID to
 

Definition at line 107 of file flowstruct.cc.

References Scheduler::clock(), Scheduler::instance(), net_addr, size, TableEntry::sourceIP, table, and TableEntry::timeout.

Referenced by DSRAgent::processBrokenRouteError(), and DSRAgent::xmitFailed().

00107                                                            {
00108         double now = Scheduler::instance().clock();
00109 
00110         for (int i=0; i<size; i++)
00111                 if (table[i].timeout >= now && table[i].sourceIP == net_addr)
00112                         for (int n=0; n < (table[i].sourceRoute.length()-1); n++)
00113                                 if (table[i].sourceRoute[n] == from &&
00114                                     table[i].sourceRoute[n+1] == to) {
00115                                         table[i].timeout = now - 1;
00116                                         // XXX ych rediscover??? 5/2/01
00117                                 }
00118 }

Here is the call graph for this function:

TableEntry & FlowTable::operator[] int  index  ) 
 

Definition at line 42 of file flowstruct.cc.

References size, and table.

00042                                            {
00043         assert(index >= 0 && index < size);
00044         return table[index];
00045 }

void FlowTable::setNetAddr nsaddr_t  net_id  ) 
 

Definition at line 161 of file flowstruct.cc.

References net_addr.

Referenced by DSRAgent::command().

00161                                           {
00162         net_addr = net_id;
00163 }


Member Data Documentation

u_int16_t FlowTable::counter [private]
 

Definition at line 178 of file flowstruct.h.

Referenced by FlowTable(), and generateNextFlowId().

DRTable FlowTable::DRTab [private]
 

Definition at line 180 of file flowstruct.h.

Referenced by cleanup(), createEntry(), and defaultFlow().

int FlowTable::maxSize [private]
 

Definition at line 176 of file flowstruct.h.

Referenced by createEntry(), FlowTable(), and grow().

nsaddr_t FlowTable::net_addr [private]
 

Definition at line 179 of file flowstruct.h.

Referenced by noticeDeadLink(), and setNetAddr().

int FlowTable::size [private]
 

Definition at line 175 of file flowstruct.h.

Referenced by cleanup(), createEntry(), find(), FlowTable(), noticeDeadLink(), and operator[]().

TableEntry* FlowTable::table [private]
 

Definition at line 174 of file flowstruct.h.

Referenced by cleanup(), createEntry(), find(), FlowTable(), grow(), noticeDeadLink(), operator[](), and ~FlowTable().


The documentation for this class was generated from the following files:
Generated on Tue Apr 20 12:47:42 2004 for NS2.26SourcesOriginal by doxygen 1.3.3