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 #ifndef _DSRAgent_h
00055 #define _DSRAgent_h
00056
00057 class DSRAgent;
00058
00059 #include <stdarg.h>
00060
00061 #include <object.h>
00062 #include <agent.h>
00063 #include <trace.h>
00064 #include <packet.h>
00065 #include <dsr-priqueue.h>
00066 #include <mac.h>
00067 #include <mobilenode.h>
00068
00069 #include "path.h"
00070 #include "srpacket.h"
00071 #include "routecache.h"
00072 #include "requesttable.h"
00073 #include "flowstruct.h"
00074
00075 #define BUFFER_CHECK 0.03 // seconds between buffer checks
00076 #define RREQ_JITTER 0.010 // seconds to jitter broadcast route requests
00077 #define SEND_TIMEOUT 30.0 // # seconds a packet can live in sendbuf
00078 #define SEND_BUF_SIZE 64
00079 #define RTREP_HOLDOFF_SIZE 10
00080
00081 #define GRAT_ROUTE_ERROR 0 // tell_addr indicating a grat route err
00082
00083 #define DSR_FILTER_TAP
00084
00085 class ArpCallbackClass;
00086 struct RtRepHoldoff {
00087 ID requestor;
00088 ID requested_dest;
00089 int best_length;
00090 int our_length;
00091 };
00092
00093 struct SendBufEntry {
00094 Time t;
00095 SRPacket p;
00096 };
00097
00098 struct GratReplyHoldDown {
00099 Time t;
00100 Path p;
00101 };
00102
00103 class SendBufferTimer : public TimerHandler {
00104 public:
00105 SendBufferTimer(DSRAgent *a) : TimerHandler() { a_ = a;}
00106 void expire(Event *e);
00107 protected:
00108 DSRAgent *a_;
00109 };
00110
00111 LIST_HEAD(DSRAgent_List, DSRAgent);
00112
00113 class DSRAgent : public Tap, public Agent {
00114 public:
00115
00116 virtual int command(int argc, const char*const* argv);
00117 virtual void recv(Packet*, Handler* callback = 0);
00118
00119 void tap(const Packet *p);
00120
00121
00122
00123 void Terminate(void);
00124
00125 void sendOutBCastPkt(Packet *p);
00126
00127 DSRAgent();
00128 ~DSRAgent();
00129
00130 private:
00131
00132 Trace *logtarget;
00133 int off_mac_;
00134 int off_ll_;
00135 int off_ip_;
00136 int off_sr_;
00137
00138
00139
00140 ID net_id, MAC_id;
00141 NsObject *ll;
00142 CMUPriQueue *ifq;
00143 Mac *mac_;
00144
00145
00146 MobileNode *node_;
00147 int diff_subnet(ID dest, ID myid);
00148
00149
00150 NsObject *port_dmux_;
00151
00152 #ifdef DSR_FILTER_TAP
00153 #define TAP_CACHE_SIZE 1024
00154 #define TAP_BITMASK (TAP_CACHE_SIZE - 1)
00155
00156
00157
00158
00159 int tap_uid_cache[TAP_CACHE_SIZE];
00160 #endif
00161
00162
00163 RequestTable request_table;
00164 RouteCache *route_cache;
00165 SendBufEntry send_buf[SEND_BUF_SIZE];
00166 SendBufferTimer send_buf_timer;
00167 int route_request_num;
00168 int num_heldoff_rt_replies;
00169 RtRepHoldoff rtrep_holdoff[RTREP_HOLDOFF_SIZE];
00170 GratReplyHoldDown grat_hold[RTREP_HOLDOFF_SIZE];
00171 int grat_hold_victim;
00172
00173
00174 FlowTable flow_table;
00175 ARSTable ars_table;
00176
00177 bool route_error_held;
00178 ID err_from, err_to;
00179 Time route_error_data_time;
00180
00181
00182
00183
00184
00185 void handlePktWithoutSR(SRPacket& p, bool retry);
00186
00187 void handlePacketReceipt(SRPacket& p);
00188 void handleForwarding(SRPacket& p);
00189 void handleRouteRequest(SRPacket &p);
00190
00191
00192
00193 void handleFlowForwarding(SRPacket &p);
00194 void handleFlowForwarding(SRPacket &p, int flowidx);
00195 void handleDefaultForwarding(SRPacket &p);
00196
00197 bool ignoreRouteRequestp(SRPacket& p);
00198
00199
00200
00201 void sendOutPacketWithRoute(SRPacket& p, bool fresh, Time delay = 0.0);
00202
00203
00204
00205
00206 void sendOutRtReq(SRPacket &p, int max_prop = MAX_SR_LEN);
00207
00208
00209
00210 void getRouteForPacket(SRPacket &p, bool retry);
00211
00212
00213
00214 void acceptRouteReply(SRPacket &p);
00215
00216
00217
00218 void returnSrcRouteToRequestor(SRPacket &p);
00219
00220
00221
00222 bool replyFromRouteCache(SRPacket &p);
00223
00224
00225
00226 void processUnknownFlowError(SRPacket &p, bool asDefault);
00227 void processFlowARS(const Packet *packet);
00228
00229 void processBrokenRouteError(SRPacket& p);
00230
00231
00232
00233
00234 void sendUnknownFlow(SRPacket &p, bool asDefault, u_int16_t flowid = 0);
00235
00236 void xmitFailed(Packet *pkt, const char* reason = "DROP_RTR_MAC_CALLBACK");
00237
00238 void xmitFlowFailed(Packet *pkt, const char* reason = "DROP_RTR_MAC_CALLBACK");
00239
00240
00241
00242
00243
00244
00245 void undeliverablePkt(Packet *p, int mine);
00246
00247
00248
00249 void dropSendBuff(SRPacket &p);
00250
00251
00252 void stickPacketInSendBuffer(SRPacket& p);
00253
00254 void sendBufferCheck();
00255
00256
00257
00258 void sendRouteShortening(SRPacket &p, int heard_at, int xmit_at);
00259
00260
00261
00262
00263
00264 void testinit();
00265 void trace(char* fmt, ...);
00266
00267 friend void XmitFailureCallback(Packet *pkt, void *data);
00268 friend void XmitFlowFailureCallback(Packet *pkt, void *data);
00269 friend int FilterFailure(Packet *p, void *data);
00270 friend class SendBufferTimer;
00271
00272 #if 0
00273 void scheduleRouteReply(Time t, Packet *new_p);
00274
00275
00276 void snoopForRouteReplies(Time t, Packet *p);
00277
00278 friend void RouteReplyHoldoffCallback(Node *node, Time time, EventData *data);
00279 #endif //0
00280
00281
00282 public:
00283 LIST_ENTRY(DSRAgent) link;
00284 static DSRAgent_List agthead;
00285 };
00286
00287 #endif // _DSRAgent_h