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

📄 aodv-interface.cc

📁 AODV version of Uppsala University
💻 CC
字号:
/* * Copyright (c) 2008, Karlstad University * Erik Andersson, Emil Ljungdahl * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: *     * Redistributions of source code must retain the above copyright *       notice, this list of conditions and the following disclaimer. *     * 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. *     * Neither the name of the <organization> nor the *       names of its contributors may be used to endorse or promote products *       derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY COPYRIGHT HOLDERS ``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 <copyright holder> 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. * * This software is based on the original NS-Miracle code found at * http://www.dei.unipd.it/wdyn/?IDsezione=3966 */#include <ip.h>#include "aodv-interface.h"#define NEXT_HOP_UNREACHABLE_DEPHT  5#define NEXT_HOP_UNREACHABLE_REASON "NHU"static class AODVInterfaceModuleClass : public TclClass {	public:		AODVInterfaceModuleClass() : TclClass("Module/IP/AODVInterface") {}		TclObject* create(int, const char*const*) {			return (new AODVInterfaceModule);		}} class_aodvinterface_module;AODVInterfaceModule::AODVInterfaceModule(){}AODVInterfaceModule::~AODVInterfaceModule(){}void AODVInterfaceModule::recv(Packet *p){	hdr_ip *iph = HDR_IP(p);	hdr_cmn *ch = HDR_CMN(p);	if(ch->direction() == hdr_cmn::UP)	{		if (iph->daddr() == ipAddr_ )		{	   // I am the final destination	   // Unfortunately current IpRouting implementation is not	   // aware of the IP address of each underlying interface, so	   // it can only see if the destination is equal to the next	   // hop. For this reason, the IP Interface module must	   // explicitly perform the following operation to let	   // IpRouting do the right thing(TM).			ch->next_hop_ = iph->daddr();	   		}		if  ( (ch->next_hop_ == ipAddr_ )					 || (iph->daddr() == IP_BROADCAST ) )		{ // I am either the next hop or the destination,	  // so I'll forward this packet up			sendUp(p);		}		else		{ // I am NOT the next hop	  			drop(p, NOT_FOR_ME_DEPTH, NOT_FOR_ME_REASON);		}	}	else	{ /* direction DOWN */		/* Check if next hop can be reached through this interface */		if ( ! ((ch->next_hop_ & subnet_) == (ipAddr_ & subnet_) || ch->next_hop_ == IP_BROADCAST))		{			drop(p,NEXT_HOP_UNREACHABLE_DEPHT, NEXT_HOP_UNREACHABLE_REASON);		}		else		{ // next hop is reachable, packet will be sent through this interface	 	  		// Set source IP ONLY IF it was not set before 	  		// (0.0.0.0 is not a valid address)			if (iph->saddr() == 0)				iph->saddr() = ipAddr_;	  		// Mark this IP interface as the previous hop			ch-> prev_hop_ = ipAddr_;				sendDown(p);		}	}}int AODVInterfaceModule::command(int argc, const char*const* argv){	Tcl& tcl = Tcl::instance();	if(argc == 2)	{		if(strcasecmp(argv[1],"subnet")==0)		{			tcl.resultf("%d", subnet_);			return TCL_OK;		}	}	else if(argc == 3)	{		if (strcasecmp (argv[1], "subnet") == 0) {			subnet_ = str2sub((char *)argv[2]);			return TCL_OK;		}	}	return IPModule::command(argc, argv);}

⌨️ 快捷键说明

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