• Main Page
  • Classes
  • Files
  • File List

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

00001 
00002 /*
00003  * dsragent.h
00004  * Copyright (C) 2000 by the University of Southern California
00005  * $Id: dsragent.h,v 1.10 2005/08/25 18:58:04 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 // Other copyrights might apply to parts of this software and are so noted when applicable.
00047 //
00048 // Ported from CMU/Monarch's code, appropriate copyright applies.  
00049 /* -*- c++ -*-
00050    dsragent.h
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          /* process a packet only once via the 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;                       // insertion time
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   // tap out all data packets received at this host and promiscously snoop
00121   // them for interesting tidbits
00122 
00123   void Terminate(void);
00124         // called at the end of the simulation to purge all packets
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   // will eventually need to handle multiple infs, but this is okay for
00139   // now 1/28/98 -dam
00140   ID net_id, MAC_id;            // our IP addr and MAC addr
00141   NsObject *ll;                 // our link layer output 
00142   CMUPriQueue *ifq;             // output interface queue
00143   Mac *mac_;
00144 
00145   // extensions for wired cum wireless sim mode
00146   MobileNode *node_;
00147   int diff_subnet(ID dest, ID myid);
00148   
00149   // extensions for mobileIP
00150   NsObject *port_dmux_;    // my port dmux
00151   
00152 #ifdef DSR_FILTER_TAP
00153 #define TAP_CACHE_SIZE  1024
00154 #define TAP_BITMASK     (TAP_CACHE_SIZE - 1)
00155   /*
00156    *  A cache of recently seen packets on the TAP so that I
00157    *  don't process them over and over again.
00158    */
00159   int tap_uid_cache[TAP_CACHE_SIZE];
00160 #endif
00161 
00162   /******** internal state ********/
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;        // number for our next route_request
00168   int num_heldoff_rt_replies;
00169   RtRepHoldoff rtrep_holdoff[RTREP_HOLDOFF_SIZE]; // not used 1/27/98
00170   GratReplyHoldDown grat_hold[RTREP_HOLDOFF_SIZE];
00171   int grat_hold_victim;
00172 
00173   /* for flow state ych 5/2/01 */
00174   FlowTable flow_table;
00175   ARSTable  ars_table;
00176 
00177   bool route_error_held; // are we holding a rt err to propagate?
00178   ID err_from, err_to;   // data from the last route err sent to us 
00179   Time route_error_data_time; // time err data was filled in
00180 
00181   /****** internal helper functions ******/
00182 
00183   /* all handle<blah> functions either free or hand off the 
00184      p.pkt handed to them */
00185   void handlePktWithoutSR(SRPacket& p, bool retry);
00186   /* obtain a source route to p's destination and send it off */
00187   void handlePacketReceipt(SRPacket& p);
00188   void handleForwarding(SRPacket& p);
00189   void handleRouteRequest(SRPacket &p);
00190   /* process a route request that isn't targeted at us */
00191 
00192   /* flow state handle functions ych */
00193   void handleFlowForwarding(SRPacket &p);
00194   void handleFlowForwarding(SRPacket &p, int flowidx);
00195   void handleDefaultForwarding(SRPacket &p);
00196 
00197   bool ignoreRouteRequestp(SRPacket& p);
00198   // assumes p is a route_request: answers true if it should be ignored.
00199   // does not update the request table (you have to do that yourself if
00200   // you want this packet ignored in the future)
00201   void sendOutPacketWithRoute(SRPacket& p, bool fresh, Time delay = 0.0);
00202   // take packet and send it out packet must a have a route in it
00203   // fresh determines whether route is reset first
00204   // time at which packet is sent is scheduled delay secs in the future
00205   // pkt.p is freed or handed off
00206   void sendOutRtReq(SRPacket &p, int max_prop = MAX_SR_LEN);
00207   // turn p into a route request and launch it, max_prop of request is
00208   // set as specified
00209   // p.pkt is freed or handed off
00210   void getRouteForPacket(SRPacket &p, bool retry);
00211   /* try to obtain a route for packet
00212      pkt is freed or handed off as needed, unless in_buffer == true
00213      in which case they are not touched */
00214   void acceptRouteReply(SRPacket &p);
00215   /* - enter the packet's source route into our cache
00216      - see if any packets are waiting to be sent out with this source route
00217      - doesn't free the p.pkt */
00218   void returnSrcRouteToRequestor(SRPacket &p);
00219   // take the route in p, add us to the end of it and return the
00220   // route to the sender of p
00221   // doesn't free p.pkt
00222   bool replyFromRouteCache(SRPacket &p); 
00223   /* - see if can reply to this route request from our cache
00224      if so, do it and return true, otherwise, return false 
00225      - frees or hands off p.pkt i ff returns true */
00226   void processUnknownFlowError(SRPacket &p, bool asDefault);
00227   void processFlowARS(const Packet *packet);
00228   // same idea as below, but for unknown flow error
00229   void processBrokenRouteError(SRPacket& p);
00230   // take the error packet and proccess our part of it.
00231   // if needed, send the remainder of the errors to the next person
00232   // doesn't free p.pkt
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   /* mark our route cache reflect the failure of the link between
00241      srh[cur_addr] and srh[next_addr], and then create a route err
00242      message to send to the orginator of the pkt (srh[0]) 
00243      p.pkt freed or handed off */
00244   
00245   void undeliverablePkt(Packet *p, int mine);
00246   /* when we've got a packet we can't deliver, what to do with it? 
00247      frees or hands off p if mine = 1, doesn't hurt it otherwise */
00248 
00249   void dropSendBuff(SRPacket &p);
00250   // log p as being dropped by the sendbuffer in DSR agent
00251   
00252   void stickPacketInSendBuffer(SRPacket& p);
00253   
00254   void sendBufferCheck();
00255   // see if any packets in send buffer need route requests sent out
00256   // for them, or need to be expired
00257 
00258   void sendRouteShortening(SRPacket &p, int heard_at, int xmit_at);
00259   // p was overheard at heard_at in it's SR, but we aren't supposed to
00260   // get it till xmit_at, so all the nodes between heard_at and xmit_at
00261   // can be elided.  Send originator of p a gratuitous route reply to 
00262   // tell them this.
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   // schedule a time to send new_p if we haven't heard a better
00275   // answer in the mean time.  Do not modify new_p after calling this
00276   void snoopForRouteReplies(Time t, Packet *p);
00277   
00278 friend void RouteReplyHoldoffCallback(Node *node, Time time, EventData *data);
00279 #endif //0
00280 
00281   /* the following variables are used to send end-of-sim notices to all objects */
00282 public:
00283         LIST_ENTRY(DSRAgent) link;
00284         static DSRAgent_List agthead;
00285 };
00286 
00287 #endif // _DSRAgent_h

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