• Main Page
  • Classes
  • Files
  • File List

/Users/yzchen/ns/ns-allinone-2.33/ns-2.33/dsr/flowstruct.h

00001 
00002 /*
00003  * flowstruct.h
00004  * Copyright (C) 2000 by the University of Southern California
00005  * $Id: flowstruct.h,v 1.3 2006/02/21 15:20:18 mahrenho Exp $
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License,
00009  * version 2, as published by the Free Software Foundation.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License along
00017  * with this program; if not, write to the Free Software Foundation, Inc.,
00018  * 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
00019  *
00020  *
00021  * The copyright of this module includes the following
00022  * linking-with-specific-other-licenses addition:
00023  *
00024  * In addition, as a special exception, the copyright holders of
00025  * this module give you permission to combine (via static or
00026  * dynamic linking) this module with free software programs or
00027  * libraries that are released under the GNU LGPL and with code
00028  * included in the standard release of ns-2 under the Apache 2.0
00029  * license or under otherwise-compatible licenses with advertising
00030  * requirements (or modified versions of such code, with unchanged
00031  * license).  You may copy and distribute such a system following the
00032  * terms of the GNU GPL for this module and the licenses of the
00033  * other code concerned, provided that you include the source code of
00034  * that other code when and as the GNU GPL requires distribution of
00035  * source code.
00036  *
00037  * Note that people who make modified versions of this module
00038  * are not obligated to grant this special exception for their
00039  * modified versions; it is their choice whether to do so.  The GNU
00040  * General Public License gives permission to release a modified
00041  * version without this exception; this exception also makes it
00042  * possible to release a modified version which carries forward this
00043  * exception.
00044  *
00045  */
00046 
00047 // Other copyrights might apply to parts of this software and are so
00048 // noted when applicable.
00049 //
00050 // Ported from CMU/Monarch's code, appropriate copyright applies.  
00051 
00052 #ifndef __flow_table_h__
00053 #define __flow_table_h__
00054 
00055 extern "C" {
00056 #include <stdio.h>
00057 #include <stdarg.h>
00058 }
00059 
00060 #include "path.h"
00061 #include "srpacket.h"
00062 #include "hdr_sr.h"
00063 //#include "net-if.h"
00064 #include <phy.h>
00065 #include "scheduler.h" // for timeout
00066 
00067 // end_to_end count - 1, actually, so a misnomer...
00068 #define END_TO_END_COUNT        2
00069 #define FLOW_TABLE_SIZE         3000
00070 #define ARS_TABLE_SIZE          5
00071 
00072 struct ARSTabEnt {
00073   int uid;
00074   u_int16_t fid;
00075   int hopsEarly; /* 0 overloads as invalid */
00076 };
00077 
00078 class ARSTable {
00079  public:
00080   ARSTable(int size_ = ARS_TABLE_SIZE);
00081   ~ARSTable();
00082 
00083   void insert(int uid, u_int16_t fid, int hopsEarly);
00084   int  findAndClear(int uid, u_int16_t fid);
00085  private:
00086   ARSTabEnt *table;
00087   int victim;
00088   int size;
00089 };
00090 
00091 struct DRTabEnt { /* Default Route Table Entry */
00092   nsaddr_t src;
00093   nsaddr_t dst;
00094   u_int16_t fid;
00095 };
00096 
00097 class DRTable {
00098   public:
00099     DRTable(int size_=FLOW_TABLE_SIZE);
00100     ~DRTable();
00101     bool find(nsaddr_t src, nsaddr_t dst, u_int16_t &flow);
00102     void insert(nsaddr_t src, nsaddr_t dst, u_int16_t flow);
00103     void flush(nsaddr_t src, nsaddr_t dst);
00104   private:
00105     int       size;
00106     int       maxSize;
00107     DRTabEnt *table;
00108 
00109     void grow();
00110 };
00111 
00112 struct TableEntry {
00113     // The following three are a key
00114     nsaddr_t   sourceIP ;       // Source IP Addresss
00115     nsaddr_t   destinationIP ;  // Destination IP Addresss
00116     u_int16_t   flowId ;        // 16bit flow id
00117 
00118     // Ugly hack for supporting the "established end-to-end" concept
00119     int         count ;         // starts from 0 and when it reaches 
00120                                 // END_TO_END_COUNT it means that the 
00121                                 // flow has been established end to end.
00122 
00123     nsaddr_t    nextHop;        // According to the draft, this is a MUST.
00124                                 // Obviously, said info is also in sourceRoute,
00125                                 // but keeping it separate makes my life easier,
00126                                 // and does so for free. -- ych 5/5/01
00127 
00128     Time        lastAdvRt;      // Last time this route was "advertised"
00129                                 // advertisements are essentially source routed
00130                                 // packets.
00131 
00132     Time        timeout ;       // MUST : Timeout of this flowtable entry
00133     int         hopCount ;      // MUST : Hop count
00134     int         expectedTTL ;   // MUST : Expected TTL
00135     bool        allowDefault ;  // MUST : If true then this flow
00136                                 // can be used as default if the 
00137                                 // source is this node and the 
00138                                 // flow ID is odd.
00139                                 // Default is 'false' 
00140 
00141     Path        sourceRoute ;   // SHOULD : The complete source route.
00142                                 // Nodes not keeping complete source 
00143                                 // route information cannot
00144                                 // participate in Automatic Route
00145                                 // Shortening
00146 };
00147 
00148 class FlowTable
00149 {
00150   public :
00151 
00152     FlowTable(int size_=FLOW_TABLE_SIZE);
00153     ~FlowTable();
00154 
00155     // Returns a pointer to the entry corresponding to
00156     // the index that has been passed.
00157     TableEntry &operator[](int index);
00158 
00159     // Returns the index number for that entry or -1 
00160     // if it is not found
00161     int find(nsaddr_t source, 
00162              nsaddr_t destination, 
00163              u_int16_t flow);
00164 
00165     // If there is an entry corresponding to the arguments of this
00166     // function then the index corresponding to that entry is
00167     // returned; returns -1 on error
00168     int find(nsaddr_t source, 
00169              nsaddr_t destination, 
00170              const Path& route);
00171 
00172     // Returns index number if successfully created, 
00173     // else returns -1 ( if entry already exists )
00174     // or if memory problem.
00175     int createEntry(nsaddr_t source, 
00176                     nsaddr_t destination, 
00177                     u_int16_t flow);
00178 
00179     // If there is a default flow id corresponding to the source and
00180     // destination addresses passed in the argument then return the index
00181     bool defaultFlow(nsaddr_t source, nsaddr_t destination, u_int16_t &flow);
00182 
00183     // Generates the next flow id keeping in mind that default flow
00184     // ids are odd and non-default ones are even.
00185     u_int16_t generateNextFlowId(nsaddr_t destination, 
00186                                  bool allowDefault) ;
00187 
00188     // Purge all the flows which uses the link from 'from' to 'to'
00189     void noticeDeadLink(const ID& from, const ID& to) ;
00190 
00191     // promise not to hold indexes into flow table across cleanup()s.
00192     void cleanup();
00193 
00194     // set our net address, for noticeDeadLink()
00195     void setNetAddr(nsaddr_t net_id);
00196 
00197   private :
00198 
00199     TableEntry *table ; // Actual flow state table
00200     int         size ;          // Number of entries in the table
00201     int         maxSize ;       // Maximum possible size
00202 
00203     u_int16_t   counter;        // next flowid to give out
00204     nsaddr_t    net_addr;       // for noticeDeadLink()
00205     DRTable     DRTab;
00206 
00207     void grow();
00208 };
00209 
00210 #endif  // __flow_table_h__
00211 

Generated on Tue Aug 10 2010 16:16:07 for ns-2.33 by  doxygen 1.7.1