00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
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;
00069
00070
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
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
00082
00083
00084
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;
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
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;
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
00180
00181
00182 void CopyIntoPath(Path& to, const Path& from, int start, int stop);
00183
00184
00185 #endif // _path_h