Main Page | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Compound Members | File Members

satnode.cc

Go to the documentation of this file.
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  * Contributed by Tom Henderson, UCB Daedalus Research Group, June 1999
00035  */
00036 
00037 #ifndef lint
00038 static const char rcsid[] =
00039     "@(#) $Header: /nfs/jade/vint/CVSROOT/ns-2/satellite/satnode.cc,v 1.8 2001/11/06 06:21:47 tomh Exp $";
00040 #endif
00041 
00042 #include "satnode.h"
00043 #include "satlink.h"
00044 #include "sattrace.h"
00045 #include "sathandoff.h"
00046 #include "satposition.h"
00047 
00048 static class SatNodeClass : public TclClass {
00049 public:
00050         SatNodeClass() : TclClass("Node/SatNode") {}
00051         TclObject* create(int , const char*const* ) {
00052                 return (new SatNode);
00053         }
00054 } class_satnode;
00055 
00056 #define MAXSATNODELIST 64 // Assume 64 nodes to start-- dynamically increases
00057 int* SatNode::satnodelist_ = NULL;
00058 int SatNode::maxsatnodelist_ = 0;
00059 int SatNode::dist_routing_ = 0;
00060 
00061 SatNode::SatNode() : ragent_(0), trace_(0), hm_(0)  
00062 {
00063         bind_bool("dist_routing_", &dist_routing_);
00064 }
00065 
00066 int SatNode::command(int argc, const char*const* argv) {     
00067         Tcl& tcl = Tcl::instance();
00068         if (argc == 2) {
00069                 if (strcmp(argv[1], "set_downlink") == 0) {
00070                         if (downlink_ != NULL) {
00071                                 tcl.result(downlink_->name());
00072                                 return (TCL_OK);
00073                         }
00074                 } else if (strcmp(argv[1], "set_uplink") == 0) {
00075                         if (downlink_ != NULL) {
00076                                 tcl.result(uplink_->name());
00077                                 return (TCL_OK);
00078                         }
00079                 } else if (strcmp(argv[1], "start_handoff") == 0) {
00080                         if (hm_)
00081                                 hm_->start();
00082                         else {
00083                                 printf("Error: starting non-existent ");
00084                                 printf("handoff mgr\n");
00085                                 exit(1);
00086                         }
00087                         return (TCL_OK);
00088                 } else if (strcmp(argv[1], "dump_sats") == 0) {
00089                         dumpSats();
00090                         return (TCL_OK);
00091                 }
00092         }
00093         if (argc == 3) {
00094                 if (strcmp(argv[1], "set_uplink") == 0) {
00095                         uplink_ = (SatChannel *) TclObject::lookup(argv[2]);
00096                         if (uplink_ == 0) {
00097                                 tcl.resultf("no such object %s", argv[2]);
00098                                 return (TCL_ERROR);
00099                         }
00100                         return (TCL_OK);
00101                 } else if (strcmp(argv[1], "set_downlink") == 0) {
00102                         downlink_ = (SatChannel *) TclObject::lookup(argv[2]);
00103                         if (downlink_ == 0) {
00104                                 tcl.resultf("no such object %s", argv[2]);
00105                                 return (TCL_ERROR);
00106                         }
00107                         return (TCL_OK);
00108                 } else if (strcmp(argv[1], "set_trace") == 0) {
00109                         trace_ = (SatTrace *) TclObject::lookup(argv[2]);
00110                         if (trace_ == 0) {
00111                                 tcl.resultf("no such object %s", argv[2]);
00112                                 return (TCL_ERROR);
00113                         }
00114                         return (TCL_OK);
00115                 } else if (strcmp(argv[1], "set_ragent") == 0) {
00116                         ragent_ = (SatRouteAgent *) TclObject::lookup(argv[2]);
00117                         if (ragent_ == 0) {
00118                                 tcl.resultf("no such object %s", argv[2]);
00119                                 return (TCL_ERROR);
00120                         }
00121                         return (TCL_OK);
00122                 } else if(strcmp(argv[1], "addif") == 0) {
00123                         SatPhy* n = (SatPhy*) TclObject::lookup(argv[2]);
00124                         if(n == 0)
00125                                 return TCL_ERROR; 
00126                         n->insertnode(&ifhead_);
00127                         n->setnode(this);
00128                         return TCL_OK;
00129                 } else if (strcmp(argv[1], "set_position") == 0) {
00130                         pos_ = (SatPosition*) TclObject::lookup(argv[2]);
00131                         if (pos_ == 0) {
00132                                 tcl.resultf("no such object %s", argv[2]);
00133                                 return (TCL_ERROR);
00134                         }
00135                         return (TCL_OK);
00136                 } else if (strcmp(argv[1], "set_handoff_mgr") == 0) {
00137                         hm_ = (LinkHandoffMgr*) TclObject::lookup(argv[2]);
00138                         if (hm_ == 0) {
00139                                 tcl.resultf("no such object %s", argv[2]);
00140                                 return (TCL_ERROR);
00141                         }
00142                         return (TCL_OK);
00143                 } else if (strcmp(argv[1], "set_address") == 0) {
00144                         addNode(atoi(argv[2]));
00145                         return (TCL_OK);
00146                 }
00147         }
00148         return (Node::command(argc, argv));
00149 }
00150 
00151 int SatNode::addNode(int nodenum)
00152 {
00153         if (maxsatnodelist_ == 0) {
00154                 satnodelist_ = new int[MAXSATNODELIST];
00155                 memset(satnodelist_, 0, MAXSATNODELIST * sizeof(satnodelist_));
00156                 maxsatnodelist_ = MAXSATNODELIST;
00157         }
00158         assert(nodenum < 2*maxsatnodelist_);
00159         if (nodenum >= maxsatnodelist_) {
00160                 // Double size of array
00161                 int i;
00162                 int* temp = new int[2 * maxsatnodelist_];
00163                 memset(temp, 0, 2 * maxsatnodelist_ * sizeof(temp));
00164                 for (i = 0; i < maxsatnodelist_; i++) {
00165                         temp[i] = satnodelist_[i];
00166                 }
00167                 delete [] satnodelist_;
00168                 satnodelist_ = temp;
00169                 maxsatnodelist_ *= 2;
00170         }
00171         satnodelist_[nodenum] = 1;
00172         return 0;
00173 }
00174 
00175 int SatNode::IsASatNode(int nodenum)
00176 {
00177         if (nodenum > maxsatnodelist_) {
00178                 printf("Error: IsASatNode() nodenum %d greater than maxsatnodelist_ %d\n", nodenum, maxsatnodelist_);
00179                 exit(1);
00180         }
00181         return satnodelist_[nodenum];
00182 }
00183 
00184 // debugging method for dumping out all of the satellite and ISL locations
00185 // on demand from OTcl.
00186 void SatNode::dumpSats()
00187 {
00188         SatNode *snodep, *peer_snodep;
00189         SatPosition *sposp, *peer_sposp;
00190         PolarSatPosition *polar_sposp;
00191         SatLinkHead *slhp;
00192         int linktype;
00193 
00194         printf("\nDumping satellites at time %.2f\n\n", NOW);
00195         for (snodep= (SatNode*) Node::nodehead_.lh_first; snodep; 
00196                 snodep = (SatNode*) snodep->nextnode()) {
00197                 if (!SatNode::IsASatNode(snodep->address()))
00198                         continue;
00199                 sposp = snodep->position();
00200                 printf("%d\t%.2f\t%.2f", snodep->address(), 
00201                     RAD_TO_DEG(SatGeometry::get_latitude(sposp->coord())), 
00202                     RAD_TO_DEG(SatGeometry::get_longitude(sposp->coord())));
00203                 // If SatNode is polar, append plane information
00204                 if (sposp->type()==POSITION_SAT_POLAR) {
00205                         polar_sposp = (PolarSatPosition*) snodep->position();
00206                         printf ("\t%d", polar_sposp->plane());
00207                 } else if (sposp->type()==POSITION_SAT_GEO) {
00208                         printf ("\tGEO");
00209                 } else if (sposp->type()==POSITION_SAT_TERM) {
00210                         printf ("\tTERM");
00211                 }
00212                 printf("\n");
00213         }
00214         printf("\n");
00215         // Dump satellite links
00216         // There is a static list of address classifiers //QQQ
00217         printf("Links:\n");
00218         for (snodep = (SatNode*) Node::nodehead_.lh_first; snodep; 
00219                 snodep = (SatNode*) snodep->nextnode()) {
00220                 if (!SatNode::IsASatNode(snodep->address()))
00221                         continue;
00222                 // XXX Not all links necessarily satlinks
00223                 for (slhp = (SatLinkHead*) snodep->linklisthead_.lh_first; 
00224                     slhp; slhp = (SatLinkHead*) slhp->nextlinkhead() ) {
00225                         linktype = slhp->type();
00226                         if (linktype == LINK_GENERIC)
00227                                 continue;
00228                         if (!slhp->linkup_)
00229                                 continue;
00230                         // Link is up.
00231                         // Print out source and dest coordinates.
00232                         sposp = snodep->position();
00233                         peer_snodep = hm_->get_peer(slhp);
00234                         if (peer_snodep == 0)
00235                                 continue; // this link interface is not attached
00236                         // need something in here for txs.
00237                         peer_sposp = peer_snodep->position();
00238                         printf("%.2f\t%.2f\t%.2f\t%.2f\t%d\n", 
00239                          RAD_TO_DEG(SatGeometry::get_latitude(sposp->coord())),
00240                          RAD_TO_DEG(SatGeometry::get_longitude(sposp->coord())),
00241                          RAD_TO_DEG(SatGeometry::get_latitude(peer_sposp->coord())), 
00242                          RAD_TO_DEG(SatGeometry::get_longitude(peer_sposp->coord())),
00243                          linktype);
00244                 }
00245         }
00246         printf("\nDumped satellites at time %.2f\n\n", NOW);
00247 }

Generated on Tue Apr 20 12:14:31 2004 for NS2.26SourcesOriginal by doxygen 1.3.3