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, nov'98 -Padma.*/ 00035 00036 /* dsdv.h -*- c++ -*- 00037 $Id: dsdv.h,v 1.6 1999/08/20 18:03:16 haoboy Exp $ 00038 00039 */ 00040 00041 #ifndef cmu_dsdv_h_ 00042 #define cmu_dsdv_h_ 00043 00044 #include "config.h" 00045 #include "agent.h" 00046 #include "ip.h" 00047 #include "delay.h" 00048 #include "scheduler.h" 00049 #include "queue.h" 00050 #include "trace.h" 00051 #include "arp.h" 00052 #include "ll.h" 00053 #include "mac.h" 00054 #include "priqueue.h" 00055 00056 #include "rtable.h" 00057 00058 #if defined(WIN32) && !defined(snprintf) 00059 #define snprintf _snprintf 00060 #endif /* WIN32 && !snprintf */ 00061 00062 typedef double Time; 00063 00064 #define MAX_QUEUE_LENGTH 5 00065 #define ROUTER_PORT 0xff 00066 00067 class DSDV_Helper; 00068 class DSDVTriggerHandler; 00069 00070 class DSDV_Agent : public Agent { 00071 friend class DSDV_Helper; 00072 friend class DSDVTriggerHandler; 00073 public: 00074 DSDV_Agent(); 00075 virtual int command(int argc, const char * const * argv); 00076 void lost_link(Packet *p); 00077 00078 protected: 00079 void helper_callback(Event *e); 00080 Packet* rtable(int); 00081 virtual void recv(Packet *, Handler *); 00082 void trace(char* fmt, ...); 00083 void tracepkt(Packet *, double, int, const char *); 00084 void needTriggeredUpdate(rtable_ent *prte, Time t); 00085 // if no triggered update already pending for route prte, make one so 00086 void cancelTriggersBefore(Time t); 00087 // Cancel any triggered events scheduled to take place *before* time 00088 // t (exclusive) 00089 Packet * makeUpdate(int& periodic); 00090 // return a packet advertising the state in the routing table 00091 // makes a full ``periodic'' update if requested, or a ``triggered'' 00092 // partial update if there are only a few changes and full update otherwise 00093 // returns with periodic = 1 if full update returned, or = 0 if partial 00094 // update returned 00095 void updateRoute(rtable_ent *old_rte, rtable_ent *new_rte); 00096 void processUpdate (Packet * p); 00097 void forwardPacket (Packet * p); 00098 void startUp(); 00099 int diff_subnet(int dst); 00100 void sendOutBCastPkt(Packet *p); 00101 00102 00103 // update old_rte in routing table to to new_rte 00104 Trace *tracetarget; // Trace Target 00105 DSDV_Helper *helper_; // DSDV Helper, handles callbacks 00106 DSDVTriggerHandler *trigger_handler; 00107 RoutingTable *table_; // Routing Table 00108 PriQueue *ll_queue; // link level output queue 00109 int seqno_; // Sequence number to advertise with... 00110 int myaddr_; // My address... 00111 00112 // Extensions for mixed type simulations using wired and wireless 00113 // nodes 00114 char *subnet_; // My subnet 00115 MobileNode *node_; // My node 00116 // for debugging 00117 char *address; 00118 NsObject *port_dmux_; // my port dmux 00119 00120 Event *periodic_callback_; // notify for periodic update 00121 00122 // Randomness/MAC/logging parameters 00123 int be_random_; 00124 int use_mac_; 00125 int verbose_; 00126 int trace_wst_; 00127 00128 // last time a periodic update was sent... 00129 double lasttup_; // time of last triggered update 00130 double next_tup; // time of next triggered update 00131 // Event *trigupd_scheduled; // event marking a scheduled triggered update 00132 00133 // DSDV constants: 00134 double alpha_; // 0.875 00135 double wst0_; // 6 (secs) 00136 double perup_; // 15 (secs) period between updates 00137 int min_update_periods_; // 3 we must hear an update from a neighbor 00138 // every min_update_periods or we declare 00139 // them unreachable 00140 00141 void output_rte(const char *prefix, rtable_ent *prte, DSDV_Agent *a); 00142 00143 }; 00144 00145 class DSDV_Helper : public Handler { 00146 public: 00147 DSDV_Helper(DSDV_Agent *a_) { a = a_; } 00148 virtual void handle(Event *e) { a->helper_callback(e); } 00149 00150 private: 00151 DSDV_Agent *a; 00152 }; 00153 00154 #endif