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

📄 aodv_rtable.cc

📁 在NS环境下对aodv路由协议进行仿真
💻 CC
字号:
/*Copyright (c) 1997, 1998 Carnegie Mellon University.  All RightsReserved. Permission to use, copy, modify, and distribute thissoftware and its documentation is hereby granted (including forcommercial or for-profit use), provided that both the copyright notice and this permission notice appear in all copies of the software, derivative works, or modified versions, and any portions thereof, and that both notices appear in supporting documentation, and that credit is given to Carnegie Mellon University in all publications reporting on direct or indirect use of this code or its derivatives.ALL CODE, SOFTWARE, PROTOCOLS, AND ARCHITECTURES DEVELOPED BY THE CMUMONARCH PROJECT ARE EXPERIMENTAL AND ARE KNOWN TO HAVE BUGS, SOME OFWHICH MAY HAVE SERIOUS CONSEQUENCES. CARNEGIE MELLON PROVIDES THISSOFTWARE OR OTHER INTELLECTUAL PROPERTY IN ITS ``AS IS'' CONDITION,AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULARPURPOSE ARE DISCLAIMED. IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITYBE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, ORCONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OFSUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; ORBUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCEOR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE ORINTELLECTUAL PROPERTY, EVEN IF ADVISED OF THE POSSIBILITY OF SUCHDAMAGE.Carnegie Mellon encourages (but does not require) users of thissoftware or intellectual property to return any improvements orextensions that they make, and to grant Carnegie Mellon the rights to redistribute these changes without encumbrance.The AODV code developed by the CMU/MONARCH group was optimized and tuned by Samir Das and Mahesh Marina, University of Cincinnati. The work was partially done in Sun Microsystems.*/#include <aodv/aodv_rtable.h>//#include <cmu/aodv/aodv.h>/*  The Routing Table*/aodv_rt_entry::aodv_rt_entry(){int i; rt_req_timeout = 0.0; rt_req_cnt = 0; rt_dst = 0; rt_seqno = 0; //My modification***********************************************************// /*     rt_last_hop_count was initialized to INFINITY2 instead of 0! This bug broke    the expanding ring search algorithm in aodv.cc!  */ rt_hops = INFINITY2; rt_last_hop_count = 0; //**************************************************************************// rt_nexthop = 0; LIST_INIT(&rt_pclist); rt_expire = 0.0; rt_flags = RTF_DOWN; /* rt_errors = 0; rt_error_time = 0.0; */ for (i=0; i < MAX_HISTORY; i++) {   rt_disc_latency[i] = 0.0; } hist_indx = 0; rt_req_last_ttl = 0; LIST_INIT(&rt_nblist);};aodv_rt_entry::~aodv_rt_entry(){AODV_Neighbor *nb; while((nb = rt_nblist.lh_first)) {   LIST_REMOVE(nb, nb_link);   delete nb; }AODV_Precursor *pc; while((pc = rt_pclist.lh_first)) {   LIST_REMOVE(pc, pc_link);   delete pc; }}voidaodv_rt_entry::nb_insert(nsaddr_t id){AODV_Neighbor *nb = new AODV_Neighbor(id);         assert(nb); nb->nb_expire = 0; LIST_INSERT_HEAD(&rt_nblist, nb, nb_link);}AODV_Neighbor*aodv_rt_entry::nb_lookup(nsaddr_t id){AODV_Neighbor *nb = rt_nblist.lh_first; for(; nb; nb = nb->nb_link.le_next) {   if(nb->nb_addr == id)     break; } return nb;}voidaodv_rt_entry::pc_insert(nsaddr_t id){	if (pc_lookup(id) == NULL) {	AODV_Precursor *pc = new AODV_Precursor(id);         		assert(pc); 		LIST_INSERT_HEAD(&rt_pclist, pc, pc_link);	}}AODV_Precursor*aodv_rt_entry::pc_lookup(nsaddr_t id){AODV_Precursor *pc = rt_pclist.lh_first; for(; pc; pc = pc->pc_link.le_next) {   if(pc->pc_addr == id)   	return pc; } return NULL;}voidaodv_rt_entry::pc_delete(nsaddr_t id) {AODV_Precursor *pc = rt_pclist.lh_first; for(; pc; pc = pc->pc_link.le_next) {   if(pc->pc_addr == id) {     LIST_REMOVE(pc,pc_link);     delete pc;     break;   } }}voidaodv_rt_entry::pc_delete(void) {AODV_Precursor *pc; while((pc = rt_pclist.lh_first)) {   LIST_REMOVE(pc, pc_link);   delete pc; }}	boolaodv_rt_entry::pc_empty(void) {AODV_Precursor *pc; if ((pc = rt_pclist.lh_first)) return false; else return true;}	/*  The Routing Table*/aodv_rt_entry*aodv_rtable::rt_lookup(nsaddr_t id){aodv_rt_entry *rt = rthead.lh_first; for(; rt; rt = rt->rt_link.le_next) {   if(rt->rt_dst == id)     break; } return rt;}voidaodv_rtable::rt_delete(nsaddr_t id){aodv_rt_entry *rt = rt_lookup(id); if(rt) {   LIST_REMOVE(rt, rt_link);   delete rt; }}aodv_rt_entry*aodv_rtable::rt_add(nsaddr_t id){aodv_rt_entry *rt; assert(rt_lookup(id) == 0); rt = new aodv_rt_entry; assert(rt); rt->rt_dst = id; LIST_INSERT_HEAD(&rthead, rt, rt_link); return rt;}

⌨️ 快捷键说明

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