00001 /* -*- Mode:C++; c-basic-offset:8; tab-width:8; indent-tabs-mode:t -*- */ 00002 /* 00003 * Copyright (c) 1999 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 MASH Research 00017 * Group at the University of California Berkeley. 00018 * 4. Neither the name of the University nor of the Research Group may be 00019 * used 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 * @(#) $Header: /nfs/jade/vint/CVSROOT/ns-2/satellite/satlink.h,v 1.7 2005/09/21 20:52:47 haldar Exp $ 00035 * 00036 * Contributed by Tom Henderson, UCB Daedalus Research Group, June 1999 00037 */ 00038 00039 #ifndef ns_satlink_h 00040 #define ns_satlink_h 00041 00042 #include "node.h" 00043 #include "channel.h" 00044 #include "phy.h" 00045 #include "queue.h" 00046 #include "net-interface.h" 00047 #include "timer-handler.h" 00048 00049 #define LINK_HDRSIZE 16 00050 00051 // Link types 00052 #define LINK_GENERIC 1 00053 #define LINK_GSL_GEO 2 00054 #define LINK_GSL_POLAR 3 00055 #define LINK_GSL_REPEATER 4 00056 #define LINK_GSL 5 00057 #define LINK_ISL_INTRAPLANE 6 00058 #define LINK_ISL_INTERPLANE 7 00059 #define LINK_ISL_CROSSSEAM 8 00060 00061 class SatLinkHead; 00062 class SatTrace; 00063 class SatNode; 00064 00065 class SatLL : public LL { 00066 public: 00067 SatLL() : LL(), arpcache_(-1), arpcachedst_(-1) {} 00068 virtual void sendDown(Packet* p); 00069 virtual void sendUp(Packet* p); 00070 virtual void recv(Packet* p, Handler* h); 00071 Channel* channel(); // Helper function used for ``ARP'' 00072 SatNode* satnode() {return satnode_; } 00073 protected: 00074 int command(int argc, const char*const* argv); 00075 int getRoute(Packet *p); 00076 SatNode* satnode_; 00077 // Optimization-- cache the last value of Mac address 00078 int arpcache_; 00079 int arpcachedst_; 00080 }; 00081 00083 00084 class SatMac; 00085 class MacSendTimer : public TimerHandler { 00086 public: 00087 MacSendTimer(SatMac *a) : TimerHandler() {a_ = a; } 00088 protected: 00089 virtual void expire(Event *e); 00090 SatMac *a_; 00091 }; 00092 00093 class MacRecvTimer : public TimerHandler { 00094 public: 00095 MacRecvTimer(SatMac *a) : TimerHandler() {a_ = a; } 00096 protected: 00097 virtual void expire(Event *e); 00098 SatMac *a_; 00099 }; 00100 00101 class MacHandlerRcv : public Handler { 00102 public: 00103 MacHandlerRcv(SatMac* m) : mac_(m) {} 00104 void handle(Event* e); 00105 protected: 00106 SatMac* mac_; 00107 }; 00108 00109 class SatMac : public Mac { 00110 public: 00111 SatMac(); 00112 void sendDown(Packet* p); 00113 void sendUp(Packet *p); 00114 virtual void send_timer() {} 00115 virtual void recv_timer() {} 00116 00117 protected: 00118 int command(int argc, const char*const* argv); 00119 MacSendTimer send_timer_; 00120 MacRecvTimer recv_timer_; 00121 SatTrace* drop_trace_; // Trace object for dropped packets in Mac 00122 int trace_drops_; // OTcl-settable flag for whether we trace drops 00123 SatTrace* coll_trace_; // Trace object for collisions in Mac 00124 int trace_collisions_; // OTcl-settable flag for whether we trace coll. 00125 }; 00126 00127 00128 class UnslottedAlohaMac : public SatMac { 00129 public: 00130 UnslottedAlohaMac(); 00131 void sendDown(Packet* p); 00132 void sendUp(Packet *p); 00133 void send_timer(); 00134 void recv_timer(); 00135 void end_of_contention(Packet* p); 00136 00137 protected: 00138 virtual void backoff(double delay=0); 00139 Packet* snd_pkt_; // stores packet currently being sent 00140 Packet* rcv_pkt_; // stores packet currently being recieved 00141 MacState tx_state_; // transmit state (SEND or COLL or IDLE) 00142 MacState rx_state_; // receive state (RECV or IDLE) 00143 int rtx_; // # of retransmissions so far 00144 int rtx_limit_; // Set in OTcl-- retransmission limit 00145 double mean_backoff_; // Set in OTcl-- mean backoff time 00146 double send_timeout_; // Set in OTcl-- time out after this interval 00147 double end_of_contention_; // Saves time that contention will be over 00148 }; 00149 00151 00152 class SatPhy : public Phy { 00153 public: 00154 SatPhy() {} 00155 void sendDown(Packet *p); 00156 int sendUp(Packet *p); 00157 protected: 00158 int command(int argc, const char*const* argv); 00159 }; 00160 00161 class RepeaterPhy : public Phy { 00162 public: 00163 RepeaterPhy() {} 00164 void recv(Packet* p, Handler*); 00165 void sendDown(Packet *p); 00166 int sendUp(Packet *) { return 0; } 00167 protected: 00168 }; 00169 00171 00172 /* 00173 * Class SatChannel 00174 */ 00175 class SatChannel : public Channel{ 00176 friend class SatRouteObject; 00177 public: 00178 SatChannel(void); 00179 int getId() { return index_; } 00180 void add_interface(Phy*); 00181 void remove_interface(Phy*); 00182 int find_peer_mac_addr(int); 00183 00184 protected: 00185 double get_pdelay(Node* tnode, Node* rnode); 00186 private: 00187 00188 }; 00189 00191 00192 class SatNode; 00193 class ErrorModel; 00194 /* 00195 * For now, this is the API used in the satellite networking code (hopefully 00196 * a more general one will follow). 00197 */ 00198 class SatLinkHead : public LinkHead { 00199 public: 00200 SatLinkHead(); 00201 // This builds on the API provided by LinkHead 00202 // (Note: the following pointers are not part of a generic API and may 00203 // be changed in the future 00204 SatPhy* phy_tx() { return phy_tx_; } 00205 SatPhy* phy_rx() { return phy_rx_; } 00206 SatMac* mac() { return mac_; } 00207 SatLL* satll() { return satll_; } 00208 Queue* queue() { return queue_; } 00209 ErrorModel* errmodel() { return errmodel_; } 00210 int linkup_; 00211 SatNode* node() { return ((SatNode*) node_); } 00212 00213 protected: 00214 virtual int command(int argc, const char*const* argv); 00215 SatPhy* phy_tx_; 00216 SatPhy* phy_rx_; 00217 SatMac* mac_; 00218 SatLL* satll_; 00219 Queue* queue_; 00220 ErrorModel* errmodel_; 00221 00222 }; 00223 00224 #endif
1.4.6