• Main Page
  • Classes
  • Files
  • File List

/Users/yzchen/ns/ns-allinone-2.33/ns-2.33/tora/tora.h

00001 /* -*-  Mode:C++; c-basic-offset:8; tab-width:8; indent-tabs-mode:t -*- */
00002 /*
00003  * Copyright (c) 1997 Regents of the University of California.
00004  * All rights reserved.
00005  *
00006  * Redistribution and use in source and binary forms, with or without
00007  * modification, are permitted provided that the following conditions
00008  * are met:
00009  * 1. Redistributions of source code must retain the above copyright
00010  *    notice, this list of conditions and the following disclaimer.
00011  * 2. Redistributions in binary form must reproduce the above copyright
00012  *    notice, this list of conditions and the following disclaimer in the
00013  *    documentation and/or other materials provided with the distribution.
00014  * 3. All advertising materials mentioning features or use of this software
00015  *    must display the following acknowledgement:
00016  *      This product includes software developed by the Computer Systems
00017  *      Engineering Group at Lawrence Berkeley Laboratory.
00018  * 4. Neither the name of the University nor of the Laboratory may be used
00019  *    to endorse or promote products derived from this software without
00020  *    specific prior written permission.
00021  *
00022  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
00023  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00024  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00025  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
00026  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00027  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
00028  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00029  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00030  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
00031  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00032  * SUCH DAMAGE.
00033  *
00034  * Ported from CMU/Monarch's code 
00035  *
00036  * $Header: /cvsroot/nsnam/ns-2/tora/tora.h,v 1.5 2000/09/01 03:04:12 haoboy Exp $
00037  */
00038 
00039 #ifndef __tora_h__
00040 #define __tora_h__
00041 
00042 #include <packet.h>
00043 #include <ip.h>
00044 #include <cmu-trace.h>
00045 #include <priqueue.h>
00046 #include <rtqueue.h>
00047 #include "lib/bsd-list.h"
00048 
00049 #include <rtproto/rtproto.h>
00050 #include <imep/imep.h>
00051 #include <tora/tora_packet.h>
00052 #include <tora/tora_neighbor.h>
00053 #include <tora/tora_dest.h>
00054 
00055 LIST_HEAD(td_head, TORADest);
00056 
00057 //#define LOGGING
00058 
00059 typedef double Time;
00060 
00061 /*
00062  *  Causes TORA to discard any packets that have "looped".
00063  */
00064 #define TORA_DISALLOW_ROUTE_LOOP
00065 
00066 #define MinQueryRate            0.200   // seconds
00067 // used to rate limit queries
00068 
00069 class TORANeighbor;
00070 class TORADest;
00071 class Height;
00072 
00073 class toraAgent : public rtAgent {
00074         friend class TORANeighbor;
00075         friend class TORADest;
00076 public:
00077         toraAgent(nsaddr_t id);
00078         void recv(Packet* p, Handler*);
00079         int             command(int argc, const char*const* argv);
00080 
00081         // ============================================================
00082         // Routing API (see cmu/rtproto/rtproto.h)
00083 
00084         void rtNotifyLinkUP(nsaddr_t index);
00085         void rtNotifyLinkDN(nsaddr_t index);
00086         void rtNotifyLinkStatus(nsaddr_t index, u_int32_t status);
00087         void rtRoutePacket(Packet *p);
00088 
00089         // ============================================================
00090 
00091 private:
00092 
00093         nsaddr_t        index;  // added for line 78 of tora.cc, needed for
00094                                 // further verification
00095 
00096         TORADest*       dst_find(nsaddr_t id);
00097         TORADest*       dst_add(nsaddr_t id);
00098         void            dst_dump(void);
00099 
00100         void            rt_resolve(Packet *p);
00101         void            forward(Packet *p, nsaddr_t nexthop, Time delay = 0.0);
00102 
00103         void            purge_queue(void);
00104         void            enque(TORADest *td, Packet *p);
00105         Packet*         deque(TORADest *td);
00106 
00107         /*
00108          * Incoming Packets
00109          */
00110         void            recvTORA(Packet* p);
00111         void            recvQRY(Packet *p);
00112         void            recvUPD(Packet *p);
00113         void            recvCLR(Packet *p);
00114 
00115         /*
00116          *  Outgoing Packets
00117          */
00118         void            sendQRY(nsaddr_t id);
00119         void            sendUPD(nsaddr_t id);
00120         void            sendCLR(nsaddr_t id, double tau, nsaddr_t oid);
00121         void            tora_output(Packet *p);
00122 
00123 
00124         // ============================================================
00125         // ============================================================
00126 
00127         inline int initialized() {
00128                  return logtarget && ifqueue && imepagent;
00129         }
00130 
00131         td_head         dstlist;        // Active destinations
00132 
00133         imepAgent       *imepagent;
00134         // a handle to the IMEP layer
00135 
00136         /*
00137          * A mechanism for logging the contents of the routing
00138          * table.
00139          */
00140         Trace           *logtarget;
00141         void trace(char* fmt, ...);
00142         virtual void reset();
00143 
00144         /*
00145          *  A "drop-front" queue used by the routing layer to buffer
00146          *  packets to which it does not have a route.
00147          */
00148         rtqueue        rqueue;
00149 
00150         /*
00151          * A pointer to the network interface queue that sits
00152          * between the "classifier" and the "link layer".
00153          */
00154         PriQueue        *ifqueue;
00155 
00156         /*
00157          * Logging Routines
00158          */
00159         void            log_route_loop(nsaddr_t prev, nsaddr_t next);
00160 
00161         void            log_link_layer_feedback(Packet *p);
00162         void            log_link_layer_recycle(Packet *p);
00163         void            log_lnk_del(nsaddr_t dst);
00164         void            log_lnk_kept(nsaddr_t dst);
00165 
00166         void            log_nb_del(nsaddr_t dst, nsaddr_t id);
00167         void            log_recv_qry(Packet *p);
00168         void            log_recv_upd(Packet *p);
00169         void            log_recv_clr(Packet *p);
00170         void            log_route_table(void);
00171 
00172         void            log_dst_state_change(TORADest *td);
00173 
00174         void            logNextHopChange(TORADest *td);
00175         void            logNbDeletedLastDN(TORADest *td);
00176         void            logToraDest(TORADest *td);
00177         void            logToraNeighbor(TORANeighbor *tn);
00178 };
00179 
00180 #endif /* __tora_h__ */
00181 

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