00001 /* -*- Mode:C++; c-basic-offset:8; tab-width:8; indent-tabs-mode:t -*- 00002 * 00003 * Copyright (c) 1997-2000 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 * $Header: /cvsroot/nsnam/ns-2/common/node.h,v 1.33 2002/05/30 17:44:03 haldar Exp $ 00035 */ 00036 00037 /* 00038 * XXX GUIDELINE TO ADDING FUNCTIONALITY TO THE BASE NODE 00039 * 00040 * One should not add something specific to one particular routing module 00041 * into the base node, which is shared by all modules in ns. Otherwise you 00042 * bloat other people's simulations. 00043 */ 00044 00045 /* 00046 * CMU-Monarch project's Mobility extensions ported by Padma Haldar, 00047 * 10/98. 00048 */ 00049 00050 #ifndef __ns_node_h__ 00051 #define __ns_node_h__ 00052 00053 #include "connector.h" 00054 #include "object.h" 00055 #include "lib/bsd-list.h" 00056 00057 #include "phy.h" 00058 #include "net-interface.h" 00059 #include "energy-model.h" 00060 #include "location.h" 00061 #include "rtmodule.h" 00062 00063 class NixNode; 00064 class LinkHead; 00065 00066 LIST_HEAD(linklist_head, LinkHead); // declare list head structure 00067 /* 00068 * The interface between a network stack and the higher layers. 00069 * This is analogous to the OTcl Link class's "head_" object. 00070 * XXX This object should provide a uniform API across multiple link objects; 00071 * right now it is a placeholder. See satlink.h for now. It is declared in 00072 * node.h for now since all nodes have a linked list of LinkHeads. 00073 */ 00074 00075 #include "parentnode.h" 00076 00077 class Node; 00078 class NetworkInterface; 00079 class RoutingModule; 00080 class LinkHead : public Connector { 00081 public: 00082 LinkHead(); 00083 00084 // API goes here 00085 Node* node() { return node_; } 00086 int type() { return type_; } 00087 int32_t label(); 00088 // Future API items could go here 00089 00090 // list of all networkinterfaces on a node 00091 inline void insertlink(struct linklist_head *head) { 00092 LIST_INSERT_HEAD(head, this, link_entry_); 00093 } 00094 LinkHead* nextlinkhead(void) const { return link_entry_.le_next; } 00095 00096 protected: 00097 virtual int command(int argc, const char*const* argv); 00098 NetworkInterface* net_if_; // Each link has a Network Interface 00099 Node* node_; // Pointer to node object 00100 int type_; // Type of link 00101 // Each node has a linked list of link heads 00102 LIST_ENTRY(LinkHead) link_entry_; 00103 00104 }; 00105 00106 LIST_HEAD(node_head, Node); // declare list head structure 00107 00108 //declare the neighbor list structure 00109 //added for pushback, but should be useful otherwise also. 00110 //there was something here which was moved to energy model. 00111 //since that work is in flux, i am not meddling with it. 00112 struct neighbor_list_node { 00113 int nodeid; 00114 neighbor_list_node* next; 00115 }; 00116 00117 // Size of the buffer for dumping nam traces. 00118 const int NODE_NAMLOG_BUFSZ = 256; 00119 00120 //routing module node used for creating rtg module list 00121 struct rtm_node { 00122 RoutingModule* rtm; 00123 rtm_node* next; 00124 }; 00125 00126 class Node : public ParentNode { 00127 public: 00128 Node(void); 00129 ~Node(); 00130 00131 inline int address() { return address_;} 00132 inline int nodeid() { return nodeid_;} 00133 inline bool exist_namchan() const { return (namChan_ != 0); } 00134 00135 virtual int command(int argc, const char*const* argv); 00136 virtual void namlog(const char *fmt, ...); 00137 00138 NsObject* intf_to_target(int32_t); 00139 00140 static struct node_head nodehead_; // static head of list of nodes 00141 inline void insert(struct node_head* head) { 00142 LIST_INSERT_HEAD(head, this, entry); 00143 } 00144 inline Node* nextnode() { return entry.le_next; } 00145 00146 // The remaining objects handle a (static) linked list of nodes 00147 // Used by Tom's satallite code and the wireless code 00148 inline const struct if_head& ifhead() const { return ifhead_; } 00149 inline const struct linklist_head& linklisthead() const { 00150 return linklisthead_; 00151 } 00152 00153 //neighbor list maintenance 00154 neighbor_list_node* neighbor_list_; 00155 void addNeighbor(Node *node); 00156 00157 static Node* get_node_by_address(nsaddr_t); 00158 00159 //routines for supporting routing 00160 void route_notify (RoutingModule *rtm); 00161 void unreg_route_notify(RoutingModule *rtm); 00162 void add_route (char *dst, NsObject *target); 00163 void delete_route (char *dst, NsObject *nullagent); 00164 void set_table_size(int nn); 00165 void set_table_size(int level, int csize); 00166 00167 protected: 00168 LIST_ENTRY(Node) entry; // declare list entry structure 00169 int address_; 00170 int nodeid_; // for nam use 00171 00172 // Nam tracing facility 00173 Tcl_Channel namChan_; 00174 // Single thread ns, so we can use one global storage for all 00175 // node objects 00176 static char nwrk_[NODE_NAMLOG_BUFSZ]; 00177 void namdump(); 00178 00179 struct if_head ifhead_; // list of phys for this node 00180 struct linklist_head linklisthead_; // list of link heads on node 00181 00182 // pointer to head of rtmodule chain 00183 RoutingModule* rtnotif_; 00184 00185 #ifdef HAVE_STL 00186 NixNode* nixnode_; // used for nix routing (on-demand source routing for simulator performance) 00187 #endif /* STL */ 00188 00189 public: 00190 // XXX Energy related stuff. Should be moved later to a wireless 00191 // routing plugin module instead of sitting here. 00192 inline EnergyModel* energy_model() { return energy_model_; } 00193 inline Location* location() { return location_; } 00194 protected: 00195 EnergyModel* energy_model_; 00196 // XXX Currently this is a placeholder only. It is supposed to 00197 // hold the position-related stuff in MobileNode. Yet another 00198 // 'Under Construction' sign :( 00199 Location* location_; 00200 }; 00201 00202 #endif /* __ns_node_h__ */