⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dsragent.cc

📁 NS2的dsr-ocean仿真代码,对学习研究NS2的人非常有研究价值
💻 CC
📖 第 1 页 / 共 5 页
字号:
/* * dsragent.cc * Copyright (C) 2000 by the University of Southern California * $Id: dsragent.cc,v 1.36 2005/08/28 23:23:03 tomh Exp $ * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License, * version 2, as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. * * * The copyright of this module includes the following * linking-with-specific-other-licenses addition: * * In addition, as a special exception, the copyright holders of * this module give you permission to combine (via static or * dynamic linking) this module with free software programs or * libraries that are released under the GNU LGPL and with code * included in the standard release of ns-2 under the Apache 2.0 * license or under otherwise-compatible licenses with advertising * requirements (or modified versions of such code, with unchanged * license).  You may copy and distribute such a system following the * terms of the GNU GPL for this module and the licenses of the * other code concerned, provided that you include the source code of * that other code when and as the GNU GPL requires distribution of * source code. * * Note that people who make modified versions of this module * are not obligated to grant this special exception for their * modified versions; it is their choice whether to do so.  The GNU * General Public License gives permission to release a modified * version without this exception; this exception also makes it * possible to release a modified version which carries forward this * exception. * *///// Other copyrights might apply to parts of this software and are so// noted when applicable.///*    dsragent.cc   requires a radio model such that sendPacket returns true   iff the packet is recieved by the destination node.      Ported from CMU/Monarch's code, appropriate copyright applies.  */extern "C" {#include <assert.h>#include <math.h>#include <stdio.h>#include <signal.h>#include <float.h>}#include <object.h>#include <agent.h>#include <trace.h>#include <packet.h>#include <scheduler.h>#include <random.h>#include <mac.h>#include <ll.h>#include <cmu-trace.h>#include "path.h"#include "srpacket.h"#include "routecache.h"#include "requesttable.h"#include "dsragent.h"#include <iostream>/*==============================================================  Declarations and global defintions------------------------------------------------------------*/// #define NEW_IFQ_LOGIC// #define NEW_REQUEST_LOGIC#define NEW_SALVAGE_LOGIC#ifdef NEW_SALVAGE_LOGIC/* *  Maximum number of times that a packet may be salvaged. */static int dsr_salvage_max_attempts = 15;/* *  Maximum number of Route Requests that can be sent for a salvaged *  packets that was originated at another node. */static int dsr_salvage_max_requests = 1;/* *  May an intermediate node send a propagating Route Request for *  a salvaged packet that was originated elsewhere. */static bool dsr_salvage_allow_propagating = 0;#endif/* couple of flowstate constants... */static const bool dsragent_enable_flowstate = false; //static const bool dsragent_prefer_default_flow = true;static const bool dsragent_prefer_shorter_over_default = true;static const bool dsragent_always_reestablish = true;static const int min_adv_interval = 5;static const int default_flow_timeout = 60;//#define DSRFLOW_VERBOSEstatic const int verbose = 0;static const int verbose_srr = 0;static const int verbose_ssalv = 1;DSRAgent_List DSRAgent::agthead = { 0 };Time arp_timeout = 30.0e-3;	// (sec) arp request timeoutTime rt_rq_period = 0.5;	// (sec) length of one backoff periodTime rt_rq_max_period = 10.0;	// (sec) maximum time between rt reqsTime send_timeout = SEND_TIMEOUT; // (sec) how long a packet can live in sendbuf#if 0/* used in route reply holdoffs, which are currently disabled -dam 5/98 */Time rt_rep_holdoff_period = 3.0e-3; // secs (about 2*process_time)// to determine how long to sit on our rt reply we pick a number// U(O.0,rt_rep_holdoff_period) + (our route length-1)*rt_rep_holdoff#endif //0Time grat_hold_down_time = 1.0;	// (sec) min time between grat replies for				// same routeTime max_err_hold = 1.0;        // (sec) // maximum time between when we recv a route error told to us, and when we// transmit a propagating route request that can carry that data.  used to// keep us from propagating stale route error data/*************** selectors ******************/bool dsragent_snoop_forwarded_errors = true;// give errors we forward to our cache?bool dsragent_snoop_source_routes = false; //// should we snoop on any source routes we see?bool dsragent_reply_only_to_first_rtreq = false;// should we only respond to the first route request we receive from a host?bool dsragent_propagate_last_error = true;// should we take the data from the last route error msg sent to us// and propagate it around on the next propagating route request we do?// this is aka grat route error propagationbool dsragent_send_grat_replies = false; //// should we send gratuitous replies to effect route shortening?bool dsragent_salvage_with_cache = false; //// should we consult our cache for a route if we get a xmitfailure// and salvage the packet using the route if possiblebool dsragent_use_tap = true;// should we listen to a promiscuous tap?bool dsragent_reply_from_cache_on_propagating = false; //// should we consult the route cache before propagating rt req's and// answer if possible?bool dsragent_ring_zero_search = false; //// should we send a non-propagating route request as the first action// in each route discovery action?// NOTE: to completely turn off replying from cache, you should// set both dsragent_ring_zero_search and // dsragent_reply_from_cache_on_propagating to falsebool dsragent_dont_salvage_bad_replies = true;// if we have an xmit failure on a packet, and the packet contains a // route reply, should we scan the reply to see if contains the dead link?// if it does, we won't salvage the packet unless there's something aside// from a reply in it (in which case we salvage, but cut out the rt reply)bool dsragent_require_bi_routes = true;// do we need to have bidirectional source routes? // [XXX this flag doesn't control all the behaviors and code that assume// bidirectional links -dam 5/14/98]#if 0bool lsnode_holdoff_rt_reply = true;// if we have a cached route to reply to route_request with, should we// hold off and not send it for a while?bool lsnode_require_use = true;// do we require ourselves to hear a route requestor use a route// before we withold our route, or is merely hearing another (better)// route reply enough?#endif/*Our strategy is as follows: - it's only worth discovering bidirectional routes, since all data paths will have to have to be bidirectional for 802.11 ACKs to work - reply to all route requests for us that we recv (not just the first one) but reply to them by reversing the route and unicasting.  don't do a route request (since that will end up returning the requestor lots of routes that are potentially unidirectional). By reversing the discovered  route for the route reply, only routes that are bidirectional will make it back the original requestor - once a packet goes into the sendbuffer, it can't be piggybacked on a  route request.  the code assumes that the only thing that removes packets from the send buff is the StickPktIn routine, or the route reply arrives routine*//*===========================================================================  SendBuf management and helpers---------------------------------------------------------------------------*/voidSendBufferTimer::expire(Event *) {   a_->sendBufferCheck();   resched(BUFFER_CHECK + BUFFER_CHECK * Random::uniform(1.0));}// ******************************* //void FaultyTimer::expire(Event* e) {  int current_time = (int)Scheduler::instance().clock();  FaultyTimePeriod faultyPeriod = faultyTimeQueue.front();  // if its faulty  if(agent->getFaultyStatus()) {    // check if the current time is the same as the end_time    // of the faulty period    if(current_time == faultyPeriod.getEndTime()) {      // if it is, then set the node back to normal behaviour      agent->setFaultyStatus(false);      // and remove this faulty period from the queue      faultyTimeQueue.pop();    }  }  // if its not faulty  else {    // check if the current time is the same as the start_time    // of the faulty period    if(current_time == faultyPeriod.getStartTime()) {      // if it is, then set the node to faulty behaviour      agent->setFaultyStatus(true);    }  }    // only reset the timer if its queue is not empty  if(!faultyTimeQueue.empty()) {    resched(1);  }else {    delete this;  }}// ******************************* //voidDSRAgent::dropSendBuff(SRPacket &p)  // log p as being dropped by the sendbuffer in DSR agent{  trace("Ssb %.5f _%s_ dropped %s -> %s", Scheduler::instance().clock(), 	net_id.dump(), p.src.dump(), p.dest.dump());  drop(p.pkt, DROP_RTR_QTIMEOUT);  p.pkt = 0;  p.route.reset();}voidDSRAgent::stickPacketInSendBuffer(SRPacket& p){  Time min = DBL_MAX;  int min_index = 0;  int c;  if (verbose)    trace("Sdebug %.5f _%s_ stuck into send buff %s -> %s",	  Scheduler::instance().clock(), 	  net_id.dump(), p.src.dump(), p.dest.dump());  for (c = 0 ; c < SEND_BUF_SIZE ; c ++)    if (send_buf[c].p.pkt == NULL)      {	send_buf[c].t = Scheduler::instance().clock();	send_buf[c].p = p;	return;      }    else if (send_buf[c].t < min)      {	min = send_buf[c].t;	min_index = c;      }    // kill somebody  dropSendBuff(send_buf[min_index].p);  send_buf[min_index].t = Scheduler::instance().clock();  send_buf[min_index].p = p;}voidDSRAgent::sendBufferCheck()  // see if any packets in send buffer need route requests sent out  // for them, or need to be expired{ // this is called about once a second.  run everybody through the  // get route for pkt routine to see if it's time to do another   // route request or what not  int c;  for (c  = 0 ; c <SEND_BUF_SIZE ; c++) {	  if (send_buf[c].p.pkt == NULL)		  continue;	  if (Scheduler::instance().clock() - send_buf[c].t > send_timeout) {		  dropSendBuff(send_buf[c].p);		  send_buf[c].p.pkt = 0;		  continue;	  }#ifdef DEBUG	  trace("Sdebug %.5f _%s_ checking for route for dst %s",		Scheduler::instance().clock(), net_id.dump(), 		send_buf[c].p.dest.dump());#endif	  handlePktWithoutSR(send_buf[c].p, true);#ifdef DEBUG	  if (send_buf[c].p.pkt == NULL) 		  trace("Sdebug %.5f _%s_ sendbuf pkt to %s liberated by handlePktWOSR",			Scheduler::instance().clock(), net_id.dump(), 			send_buf[c].p.dest.dump());#endif  }}/*==============================================================  Route Request backoff------------------------------------------------------------*/static boolBackOffTest(Entry *e, Time time)// look at the entry and decide if we can send another route// request or not.  update entry as well{  Time next = ((Time) (0x1 << (e->rt_reqs_outstanding * 2))) * rt_rq_period;  if (next > rt_rq_max_period)	  next = rt_rq_max_period;  if (next + e->last_rt_req > time)	  return false;  // don't let rt_reqs_outstanding overflow next on the LogicalShiftsLeft's  if (e->rt_reqs_outstanding < 15)	  e->rt_reqs_outstanding++;  e->last_rt_req = time;  return true;}/*===========================================================================  DSRAgent OTcl linkage---------------------------------------------------------------------------*/static class DSRAgentClass : public TclClass {public:  DSRAgentClass() : TclClass("Agent/DSRAgent") {}  TclObject* create(int, const char*const*) {    return (new DSRAgent);  }} class_DSRAgent;/*===========================================================================  DSRAgent methods---------------------------------------------------------------------------*/DSRAgent::DSRAgent(): Agent(PT_DSR), request_table(128), route_cache(NULL),send_buf_timer(this), flow_table(), ars_table(){  int c;  route_request_num = 1;  route_cache = makeRouteCache();  for (c = 0 ; c < RTREP_HOLDOFF_SIZE ; c++)	  rtrep_holdoff[c].requested_dest = invalid_addr;  num_heldoff_rt_replies = 0;  target_ = 0;  logtarget = 0;  grat_hold_victim = 0;  for (c = 0; c < RTREP_HOLDOFF_SIZE ; c++) {    grat_hold[c].t = 0;    grat_hold[c].p.reset();  }  //bind("off_SR_", &off_sr_);  //bind("off_ll_", &off_ll_);  //bind("off_mac_", &off_mac_);  //bind("off_ip_", &off_ip_);  ll = 0;  ifq = 0;  mac_ = 0;  LIST_INSERT_HEAD(&agthead, this, link);#ifdef DSR_FILTER_TAP  bzero(tap_uid_cache, sizeof(tap_uid_cache));#endif  route_error_held = false;}DSRAgent::~DSRAgent(){  fprintf(stderr,"DFU: Don't do this! I haven't figured out ~DSRAgent\n");  exit(-1);}voidDSRAgent::Terminate(){	int c;	for (c  = 0 ; c < SEND_BUF_SIZE ; c++) {		if (send_buf[c].p.pkt) {			drop(send_buf[c].p.pkt, DROP_END_OF_SIMULATION);			send_buf[c].p.pkt = 0;		}	}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -