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 and the Daedalus 00018 * research group at UC Berkeley. 00019 * 4. Neither the name of the University nor of the Laboratory may be used 00020 * to endorse or promote products derived from this software without 00021 * specific prior written permission. 00022 * 00023 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 00024 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00025 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00026 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 00027 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00028 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 00029 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 00030 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00031 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 00032 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 00033 * SUCH DAMAGE. 00034 * 00035 * Contributed by Giao Nguyen, http://daedalus.cs.berkeley.edu/~gnguyen 00036 * 00037 * @(#) $Header: /cvsroot/nsnam/ns-2/mac/channel.h,v 1.27 2003/12/23 17:36:35 haldar Exp $ (UCB) 00038 */ 00039 00040 #ifndef ns_channel_h 00041 #define ns_channel_h 00042 00043 #include <string.h> 00044 #include "object.h" 00045 #include "packet.h" 00046 #include "phy.h" 00047 #include "node.h" 00048 00049 class Trace; 00050 class Node; 00051 /*================================================================= 00052 Channel: a shared medium that supports contention and collision 00053 This class is used to represent the physical media to which 00054 network interfaces are attached. As such, the sendUp() 00055 function simply schedules packet reception at the interfaces. 00056 The recv() function should never be called. 00057 =================================================================*/ 00058 00059 class Channel : public TclObject { 00060 public: 00061 Channel(void); 00062 virtual int command(int argc, const char*const* argv); 00063 virtual void recv(Packet* p, Handler*); 00064 struct if_head ifhead_; 00065 TclObject* gridkeeper_; 00066 double maxdelay() { return delay_; }; 00067 int index() {return index_;} 00068 00069 private: 00070 virtual void sendUp(Packet* p, Phy *txif); 00071 void dump(void); 00072 //virtual void contention(Packet*, Handler*); 00073 //int jam(double txtime); 00074 //virtual int collision() { return numtx_ > 1; } 00075 //virtual double txstop() { return txstop_; } 00076 //Packet* pkt() { return pkt_; } 00077 00078 protected: 00079 virtual double get_pdelay(Node* tnode, Node* rnode); 00080 int index_; // multichannel support 00081 double delay_; // channel delay, for collision interval 00082 //double txstop_; // end of the last transmission 00083 //double cwstop_; // end of the contention window 00084 //int numtx_; // number of transmissions during contention 00085 //Packet* pkt_; // packet current transmitted on the channel 00086 Trace* trace_; // to trace the packet transmitting packets 00087 }; 00088 00089 00090 /*class DuplexChannel : public Channel { 00091 public: 00092 DuplexChannel() : Channel() {} 00093 int send(Packet* p, double txtime); 00094 void contention(Packet*, Handler*); // content for the channel 00095 inline double txstop() { return 0; } 00096 };*/ 00097 00098 00099 /*==================================================================== 00100 WirelessChannel 00101 00102 This class is used to represent the physical media used by mobilenodes 00103 ====================================================================*/ 00104 00105 class WirelessChannel : public Channel{ 00106 friend class Topography; 00107 public: 00108 WirelessChannel(void); 00109 virtual int command(int argc, const char*const* argv); 00110 inline double gethighestAntennaZ() { return highestAntennaZ_; } 00111 00112 private: 00113 void sendUp(Packet* p, Phy *txif); 00114 double get_pdelay(Node* tnode, Node* rnode); 00115 00116 /* For list-keeper, channel keeps list of mobilenodes 00117 listening on to it */ 00118 int numNodes_; 00119 MobileNode *xListHead_; 00120 bool sorted_; 00121 void addNodeToList(MobileNode *mn); 00122 void removeNodeFromList(MobileNode *mn); 00123 void sortLists(void); 00124 void updateNodesList(class MobileNode *mn, double oldX); 00125 MobileNode **getAffectedNodes(MobileNode *mn, double radius, int *numAffectedNodes); 00126 00127 protected: 00128 static double distCST_; 00129 static double highestAntennaZ_; 00130 void calcHighestAntennaZ(Phy *tifp); 00131 }; 00132 00133 #endif //_channel_h_ 00134 00135 00136