00001 00002 /* 00003 * Copyright (C) 2000 by the University of Southern California 00004 * $Id: mip.h,v 1.8 2005/08/25 18:58:08 johnh Exp $ 00005 * 00006 * This program is free software; you can redistribute it and/or 00007 * modify it under the terms of the GNU General Public License, 00008 * version 2, as published by the Free Software Foundation. 00009 * 00010 * This program is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 * GNU General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU General Public License along 00016 * with this program; if not, write to the Free Software Foundation, Inc., 00017 * 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. 00018 * 00019 * 00020 * The copyright of this module includes the following 00021 * linking-with-specific-other-licenses addition: 00022 * 00023 * In addition, as a special exception, the copyright holders of 00024 * this module give you permission to combine (via static or 00025 * dynamic linking) this module with free software programs or 00026 * libraries that are released under the GNU LGPL and with code 00027 * included in the standard release of ns-2 under the Apache 2.0 00028 * license or under otherwise-compatible licenses with advertising 00029 * requirements (or modified versions of such code, with unchanged 00030 * license). You may copy and distribute such a system following the 00031 * terms of the GNU GPL for this module and the licenses of the 00032 * other code concerned, provided that you include the source code of 00033 * that other code when and as the GNU GPL requires distribution of 00034 * source code. 00035 * 00036 * Note that people who make modified versions of this module 00037 * are not obligated to grant this special exception for their 00038 * modified versions; it is their choice whether to do so. The GNU 00039 * General Public License gives permission to release a modified 00040 * version without this exception; this exception also makes it 00041 * possible to release a modified version which carries forward this 00042 * exception. 00043 * 00044 */ 00045 00046 // Other copyrights might apply to parts of this software and are so 00047 // noted when applicable. 00048 // 00049 // $Header: /cvsroot/nsnam/ns-2/mobile/mip.h,v 1.8 2005/08/25 18:58:08 johnh Exp $ 00050 00051 /* 00052 * Copyright (c) Sun Microsystems, Inc. 1998 All rights reserved. 00053 * 00054 * Redistribution and use in source and binary forms, with or without 00055 * modification, are permitted provided that the following conditions 00056 * are met: 00057 * 00058 * 1. Redistributions of source code must retain the above copyright 00059 * notice, this list of conditions and the following disclaimer. 00060 * 00061 * 2. Redistributions in binary form must reproduce the above copyright 00062 * notice, this list of conditions and the following disclaimer in the 00063 * documentation and/or other materials provided with the distribution. 00064 * 00065 * 3. All advertising materials mentioning features or use of this software 00066 * must display the following acknowledgement: 00067 * This product includes software developed by Sun Microsystems, Inc. 00068 * 00069 * 4. The name of the Sun Microsystems, Inc nor may not be used to endorse or 00070 * promote products derived from this software without specific prior 00071 * written permission. 00072 * 00073 * SUN MICROSYSTEMS MERCHANTABILITY OF THIS SOFTWARE OR THE SUITABILITY OF THIS 00074 * SOFTWARE FOR ANY PARTICULAR PURPOSE. The software is provided "as is" 00075 * without express or implied warranty of any kind. 00076 * 00077 * These notices must be retained in any copies of any part of this software. 00078 */ 00079 00080 /* Ported by Ya Xu to official ns release Jan. 1999 */ 00081 00082 00083 #ifndef ns_mip_h 00084 #define ns_mip_h 00085 00086 #include <assert.h> 00087 #include "agent.h" 00088 #include "classifier-addr.h" 00089 00090 #define MIP_TIMER_SIMPLE 0 00091 #define MIP_TIMER_AGTLIST 1 00092 00093 struct hdr_ipinip { 00094 hdr_ip hdr_; 00095 struct hdr_ipinip *next_; // XXX multiple encapsulation OK 00096 00097 // Header access methods 00098 static int offset_; // required by PacketHeaderManager 00099 inline static int& offset() { return offset_; } 00100 inline static hdr_ipinip* access(const Packet* p) { 00101 return (hdr_ipinip*) p->access(offset_); 00102 } 00103 }; 00104 00105 typedef enum { 00106 MIPT_REG_REQUEST, MIPT_REG_REPLY, MIPT_ADS, MIPT_SOL 00107 } MipRegType; 00108 00109 struct hdr_mip { 00110 int haddr_; 00111 int ha_; 00112 int coa_; 00113 MipRegType type_; 00114 double lifetime_; 00115 int seqno_; 00116 00117 // Header access methods 00118 static int offset_; // required by PacketHeaderManager 00119 inline static int& offset() { return offset_; } 00120 inline static hdr_mip* access(const Packet* p) { 00121 return (hdr_mip*) p->access(offset_); 00122 } 00123 }; 00124 00125 class MIPEncapsulator : public Connector { 00126 public: 00127 MIPEncapsulator(); 00128 void recv(Packet *p, Handler *h); 00129 protected: 00130 ns_addr_t here_; 00131 int mask_; 00132 int shift_; 00133 int defttl_; 00134 }; 00135 00136 class MIPDecapsulator : public AddressClassifier { 00137 public: 00138 MIPDecapsulator(); 00139 void recv(Packet* p, Handler* h); 00140 }; 00141 00142 class SimpleTimer : public TimerHandler { 00143 public: 00144 SimpleTimer(Agent *a) : TimerHandler() { a_ = a; } 00145 protected: 00146 inline void expire(Event *) { a_->timeout(MIP_TIMER_SIMPLE); } 00147 Agent *a_; 00148 }; 00149 00150 class MIPBSAgent : public Agent { 00151 public: 00152 MIPBSAgent(); 00153 virtual void recv(Packet *, Handler *); 00154 void timeout(int); 00155 protected: 00156 int command(int argc, const char*const*argv); 00157 void send_ads(int dst = -1, NsObject *target = NULL); 00158 void sendOutBCastPkt(Packet *p); 00159 double beacon_; /* beacon period */ 00160 NsObject *bcast_target_; /* where to send out ads */ 00161 NsObject *ragent_; /* where to send reg-replies to MH */ 00162 SimpleTimer timer_; 00163 int mask_; 00164 int shift_; 00165 #ifndef notdef 00166 int seqno_; /* current ad seqno */ 00167 #endif 00168 double adlftm_; /* ads lifetime */ 00169 }; 00170 00171 class MIPMHAgent; 00172 00173 class AgtListTimer : public TimerHandler { 00174 public: 00175 AgtListTimer(MIPMHAgent *a) : TimerHandler() { a_ = a; } 00176 protected: 00177 void expire(Event *e); 00178 MIPMHAgent *a_; 00179 }; 00180 00181 typedef struct _agentList { 00182 int node_; 00183 double expire_time_; 00184 double lifetime_; 00185 struct _agentList *next_; 00186 } AgentList; 00187 00188 class MIPMHAgent : public Agent { 00189 public: 00190 MIPMHAgent(); 00191 void recv(Packet *, Handler *); 00192 void timeout(int); 00193 protected: 00194 int command(int argc, const char*const*argv); 00195 void reg(); 00196 void send_sols(); 00197 void sendOutBCastPkt(Packet *p); 00198 int ha_; 00199 int coa_; 00200 double reg_rtx_; 00201 double beacon_; 00202 NsObject *bcast_target_; /* where to send out solicitations */ 00203 AgentList *agts_; 00204 SimpleTimer rtx_timer_; 00205 AgtListTimer agtlist_timer_; 00206 int mask_; 00207 int shift_; 00208 #ifndef notdef 00209 int seqno_; /* current registration seqno */ 00210 #endif 00211 double reglftm_; /* registration lifetime */ 00212 double adlftm_; /* current ads lifetime */ 00213 MobileNode *node_; /* ptr to my mobilenode,if appl. */ 00214 00215 }; 00216 00217 #endif