📄 mobilenode.cc~
字号:
/*-*- Mode:C++; c-basic-offset:8; tab-width:8; indent-tabs-mode:t -*- * * Copyright (c) 1997 Regents of the University of California. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed by the Computer Systems * Engineering Group at Lawrence Berkeley Laboratory. * 4. Neither the name of the University nor of the Laboratory may be used * to endorse or promote products derived from this software without * specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * $Header: /nfs/jade/vint/CVSROOT/ns-2/common/mobilenode.cc,v 1.29 2002/05/06 17:10:40 difa Exp $ * * Code in this file will be changed in the near future. From now on it * should be treated as for backward compatibility only, although it is in * active use by many other code in ns. - Aug 29, 2000 *//* * CMU-Monarch project's Mobility extensions ported by Padma Haldar, * 11/98. */#include <math.h>#include <stdlib.h>#include "connector.h"#include "delay.h"#include "packet.h"#include "random.h"#include "trace.h"#include "address.h"#include "arp.h"#include "topography.h"#include "ll.h"#include "mac.h"#include "propagation.h"#include "mobilenode.h"#include "phy.h"#include "wired-phy.h"#include "god.h"//@@ FaZ #include "paraq-timers.h"//@ FaZ// XXX Must supply the first parameter in the macro otherwise msvc// is unhappy. static LIST_HEAD(_dummy_MobileNodeList, MobileNode) nodehead = { 0 };static class MobileNodeClass : public TclClass {public: MobileNodeClass() : TclClass("Node/MobileNode") {} TclObject* create(int, const char*const*) { return (new MobileNode); }} class_mobilenode;/* * PositionHandler() * * Updates the position of a mobile node every N seconds, where N is * based upon the speed of the mobile and the resolution of the topography. * */voidPositionHandler::handle(Event*){ Scheduler& s = Scheduler::instance();#if 0 fprintf(stderr, "*** POSITION HANDLER for node %d (time: %f) ***\n", node->address(), s.clock());#endif /* * Update current location */ node->update_position(); /* * Choose a new random speed and direction */#ifdef DEBUG fprintf(stderr, "%d - %s: calling random_destination()\n", node->address_, __PRETTY_FUNCTION__);#endif node->random_destination(); s.schedule(&node->pos_handle_, &node->pos_intr_, node->position_update_interval_);}/* ====================================================================== Mobile Node ====================================================================== */MobileNode::MobileNode(void) : pos_handle_(this){ X_ = Y_ = Z_ = speed_ = 0.0; dX_ = dY_ = dZ_ = 0.0; destX_ = destY_ = 0.0; random_motion_ = 0; base_stn_ = -1; T_ = 0; log_target_ = 0; next_ = 0; radius_ = 0; position_update_interval_ = POSITION_UPDATE_INTERVAL; position_update_time_ = 0.0; LIST_INSERT_HEAD(&nodehead, this, link_); // node list LIST_INIT(&ifhead_); // interface list bind("X_", &X_); bind("Y_", &Y_); bind("Z_", &Z_); bind("speed_", &speed_);}intMobileNode::command(int argc, const char*const* argv){ Tcl& tcl = Tcl::instance(); if(argc == 2) { if(strcmp(argv[1], "start") == 0) { start(); return TCL_OK; } else if(strcmp(argv[1], "log-movement") == 0) {#ifdef DEBUG fprintf(stderr, "%d - %s: calling update_position()\n", address_, __PRETTY_FUNCTION__);#endif update_position(); log_movement(); return TCL_OK; } else if(strcmp(argv[1], "log-energy") == 0) { log_energy(1); return TCL_OK; } else if(strcmp(argv[1], "powersaving") == 0) { energy_model()->powersavingflag() = 1; energy_model()->start_powersaving(); return TCL_OK;/*//@@ FaZ 8/7/04 } else if(strcmp(argv[1], "paraqwlan") == 0) { energy_model()->paraqflag() = 1; energy_model()->start_paraq(); return TCL_OK; }//@ FaZ 8/7/04*/ else if(strcmp(argv[1], "adaptivefidelity") == 0) { energy_model()->adaptivefidelity() = 1; energy_model()->powersavingflag() = 1; energy_model()->start_powersaving(); return TCL_OK; } else if (strcmp(argv[1], "energy") == 0) { Tcl& tcl = Tcl::instance(); tcl.resultf("%f", energy_model()->energy()); return TCL_OK; } else if (strcmp(argv[1], "adjustenergy") == 0) { // assume every 10 sec schedule and 1.15 W // idle energy consumption. needs to be // parameterized. idle_energy_patch(10, 1.15); energy_model()->total_sndtime() = 0; energy_model()->total_rcvtime() = 0; energy_model()->total_sleeptime() = 0; return TCL_OK; } else if (strcmp(argv[1], "on") == 0) { energy_model()->node_on() = true; tcl.evalf("%s set netif_(0)", name_); char *str = tcl.result(); tcl.evalf("%s NodeOn", str); God::instance()->ComputeRoute(); return TCL_OK; } else if (strcmp(argv[1], "off") == 0) { energy_model()->node_on() = false; tcl.evalf("%s set netif_(0)", name_); char *str = tcl.result(); tcl.evalf("%s NodeOff", str); tcl.evalf("%s set ragent_", name_); str = tcl.result(); tcl.evalf("%s reset-state", str); God::instance()->ComputeRoute(); return TCL_OK; } else if (strcmp(argv[1], "shutdown") == 0) { // set node state //Phy *p; energy_model()->node_on() = false; //p = ifhead().lh_first; //if (p) ((WirelessPhy *)p)->node_off(); return TCL_OK; } else if (strcmp(argv[1], "startup") == 0) { energy_model()->node_on() = true; return TCL_OK; } } else if(argc == 3) { if(strcmp(argv[1], "addif") == 0) { WiredPhy* phyp = (WiredPhy*)TclObject::lookup(argv[2]); if(phyp == 0) return TCL_ERROR; phyp->insertnode(&ifhead_); phyp->setnode(this); return TCL_OK; } else if (strcmp(argv[1], "setsleeptime") == 0) { energy_model()->afe()->set_sleeptime(atof(argv[2])); energy_model()->afe()->set_sleepseed(atof(argv[2])); return TCL_OK; } else if (strcmp(argv[1], "setenergy") == 0) { energy_model()->setenergy(atof(argv[2])); return TCL_OK; } else if (strcmp(argv[1], "settalive") == 0) { energy_model()->max_inroute_time() = atof(argv[2]); return TCL_OK; } else if (strcmp(argv[1], "maxttl") == 0) { energy_model()->maxttl() = atoi(argv[2]); return TCL_OK; } else if(strcmp(argv[1], "radius") == 0) { radius_ = strtod(argv[2],NULL); return TCL_OK; } else if(strcmp(argv[1], "random-motion") == 0) { random_motion_ = atoi(argv[2]); return TCL_OK; } else if(strcmp(argv[1], "addif") == 0) { WirelessPhy *n = (WirelessPhy*) TclObject::lookup(argv[2]); if(n == 0) return TCL_ERROR; n->insertnode(&ifhead_); n->setnode(this); return TCL_OK; } else if(strcmp(argv[1], "topography") == 0) { T_ = (Topography*) TclObject::lookup(argv[2]); if (T_ == 0) return TCL_ERROR; return TCL_OK; } else if(strcmp(argv[1], "log-target") == 0) { log_target_ = (Trace*) TclObject::lookup(argv[2]); if (log_target_ == 0) return TCL_ERROR; return TCL_OK; } else if (strcmp(argv[1],"base-station") == 0) { base_stn_ = atoi(argv[2]); if(base_stn_ == -1) return TCL_ERROR; return TCL_OK; } } else if (argc == 4) { if (strcmp(argv[1], "idleenergy") == 0) { idle_energy_patch(atof(argv[2]),atof(argv[3])); return TCL_OK; } } else if (argc == 5) { if (strcmp(argv[1], "setdest") == 0) { /* <mobilenode> setdest <X> <Y> <speed> */#ifdef DEBUG fprintf(stderr, "%d - %s: calling set_destination()\n", address_, __FUNCTION__);#endif if (set_destination(atof(argv[2]), atof(argv[3]), atof(argv[4])) < 0) return TCL_ERROR; return TCL_OK; } } return Node::command(argc, argv);}/* ======================================================================
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -