• Main Page
  • Classes
  • Files
  • File List

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

00001 
00002 /*
00003  * path.h
00004  * Copyright (C) 2000 by the University of Southern California
00005  * $Id: path.h,v 1.7 2005/08/25 18:58:05 johnh 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 /* -*- c++ -*- 
00052    path.h
00053 
00054    handles source routes
00055    
00056 */
00057 #ifndef _path_h
00058 #define _path_h
00059 
00060 extern "C" {
00061 #include <stdio.h>
00062 #include <assert.h>
00063 }
00064 
00065 #include <packet.h>
00066 #include "hdr_sr.h"
00067 
00068 class Path;                     // forward declaration
00069 
00070 // state used for tracing the performance of the caches
00071 enum Link_Type {LT_NONE = 0, LT_TESTED = 1, LT_UNTESTED = 2};
00072 enum Log_Status {LS_NONE = 0, LS_UNLOGGED = 1, LS_LOGGED = 2};
00073 
00074 // some type conversion between exisiting NS code and old DSR sim
00075 typedef double Time;
00076 enum ID_Type {NONE = NS_AF_NONE, MAC = NS_AF_ILINK, IP = NS_AF_INET };
00077 
00078 struct ID {
00079   friend class Path; 
00080   ID() : type(NONE), t(-1), link_type(LT_NONE), log_stat(LS_NONE) {}
00081   //  ID():addr(0),type(NONE) {}        // remove for speed? -dam 1/23/98
00082   //ID(unsigned long name, ID_Type t):addr(name),type(t), t(-1), link_type(LT_NONE),log_stat(LS_NONE)
00083   //{
00084   //assert(type == NONE || type == MAC || type == IP);
00085   //}
00086   ID(unsigned long name, ID_Type t):addr(name), type(t), t(-1), 
00087     link_type(LT_NONE),log_stat(LS_NONE)
00088         {
00089                 assert(type == NONE || type == MAC || type == IP);
00090         }
00091   inline ID(const struct sr_addr &a): addr(a.addr), 
00092     type((enum ID_Type) a.addr_type), t(-1), link_type(LT_NONE),
00093           log_stat(LS_NONE)
00094         {
00095                 assert(type == NONE || type == MAC || type == IP);
00096         }
00097   inline void fillSRAddr(struct sr_addr& a) {
00098           a.addr_type = (int) type;
00099           a.addr = addr;
00100   }    
00101   inline nsaddr_t getNSAddr_t() const {
00102           assert(type == IP); return addr;
00103   }
00104   inline bool operator == (const ID& id2) const {
00105           return (type == id2.type) && (addr == id2.addr);
00106   }
00107   inline bool operator != (const ID& id2) const {return !operator==(id2);}
00108   inline int size() const {return (type == IP ? 4 : 6);} 
00109   void unparse(FILE* out) const;
00110   char* dump() const;
00111 
00112   unsigned long addr;
00113   ID_Type type;
00114 
00115   Time t;                       // when was this ID added to the route
00116   Link_Type link_type;
00117   Log_Status log_stat;
00118 };
00119 
00120 extern ID invalid_addr;
00121 extern ID IP_broadcast;
00122 
00123 class Path {
00124 friend void compressPath(Path& path);
00125 friend void CopyIntoPath(Path& to, const Path& from, int start, int stop);
00126 public:
00127   Path();
00128   Path(int route_len, const ID *route = NULL);
00129   Path(const Path& old);
00130   Path(const struct sr_addr *addrs, int len);
00131   Path(struct hdr_sr *srh);
00132 
00133   ~Path();
00134 
00135   void fillSR(struct hdr_sr *srh);
00136 
00137   inline ID& next() {assert(cur_index < len); return path[cur_index++];}
00138   inline void resetIterator() {  cur_index = 0;}
00139   inline void reset() {len = 0; cur_index = 0;}
00140 
00141   inline void setIterator(int i) {assert(i>=0 && i<len); cur_index = i;}
00142   inline void setLength(int l) {assert(l>=0 && l<=MAX_SR_LEN); len = l;}
00143   inline ID& operator[] (int n) const {  
00144     assert(n < len && n >= 0);
00145     return path[n];}
00146   void operator=(const Path& rhs);
00147   bool operator==(const Path& rhs);
00148   inline void appendToPath(const ID& id) { 
00149     assert(len < MAX_SR_LEN); 
00150     path[len++] = id;}
00151   void appendPath(Path& p);
00152   bool member(const ID& id) const;
00153   bool member(const ID& net_id, const ID& MAC_id) const;
00154   Path copy() const;
00155   void copyInto(Path& to) const;
00156   Path reverse() const;
00157   void reverseInPlace();
00158   void removeSection(int from, int to);
00159   // the elements at indices from -> to-1 are removed from the path
00160 
00161   inline bool full() const {return (len >= MAX_SR_LEN);}
00162   inline int length() const {return len;}
00163   inline int index() const {return cur_index;}
00164   inline int &index() {return cur_index;}
00165   int size() const; // # of bytes needed to hold path in packet
00166   void unparse(FILE *out) const;
00167   char *dump() const;
00168   inline ID &owner() {return path_owner;}
00169 
00170   void checkpath(void) const;
00171 private:
00172   int len;
00173   int cur_index;
00174   ID* path;
00175   ID path_owner;
00176 };
00177 
00178 void compressPath(Path& path);
00179 // take a path and remove any double backs from it
00180 // eg:  A B C B D --> A B D
00181 
00182 void CopyIntoPath(Path& to, const Path& from, int start, int stop);
00183 // sets to[0->(stop-start)] = from[start->stop]
00184 
00185 #endif // _path_h

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