亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關(guān)于我們
? 蟲蟲下載站

?? antnet.cc.bak

?? 基于 NS2 的 AntNet 源代碼
?? BAK
?? 第 1 頁 / 共 2 頁
字號:
/* * antnet.cc * * 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. * * If you are using this program for any publication, we kindly request that you cite: * "Ant Colony Optimisation Based Routing on NS-2",  * V. Laxmi, Lavina Jain and M. S. Gaur,  * International Conference on Wireless Communication and Sensor Networks (WCSN),  * India, December 2006. *  * 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. * * Author: Lavina Jain * *//////////////////////////////////////////////////// \file antnet.cc/// \brief Implementation file for Agent Antnet////////////////////////////////////////////////#include "antnet.h"#include "address.h" // to fascilitate inlines#include <stdio.h>#include <stdlib.h>#include <math.h> int hdr_ant_pkt::offset_;	///< to access ant packet header  偏移量extern double r;		///< reinforcement factorextern int N;			///< number of neighbors of a nodeextern int NUM_NODES;		///< total number of nodes in the topology////////////////////////////////////////////////////////////////////////////// \brief tcl binding for new packet: Ant///////////////////////////////////////////////////////////////////////////static class AntHeaderClass : public PacketHeaderClass { 	public: 	AntHeaderClass() : PacketHeaderClass("PacketHeader/Ant",sizeof(hdr_ant_pkt)) { 		bind_offset(&hdr_ant_pkt::offset_); 	} } class_rtProtoAnt_hdr;////////////////////////////////////////////////////////////////////////////// \brief tcl binding for new Agent: Antnet///////////////////////////////////////////////////////////////////////////static class AntnetClass : public TclClass {	public:	AntnetClass() : TclClass("Agent/Antnet") {}	TclObject* create(int argc, const char*const* argv) {		assert(argc == 5);		return (new Antnet((nsaddr_t)Address::instance().str2addr(argv[4])));	}} class_rtProtoAntnet; ////////////////////////////////////////////////////////////////////////////// tcl binding for agent parameters/// default values defined in ns-default.tcl/////////////////////////////////////////////////////////////////////////// Antnet::Antnet(nsaddr_t id) : Agent(PT_ANT), ant_timer_(this), dmux_(0) {		bind("num_nodes_", &num_nodes_);	// number of nodes in topology	bind("num_nodes_x_", &num_nodes_x_);	// number of nodes in row (for regular mesh topology)	bind("num_nodes_y_", &num_nodes_y_);	// number of nodes in column (for regular mesh topology)	bind("r_factor_", &r_factor_);		// reinforcement factor    r = r_factor_	bind("timer_ant_", &timer_ant_);	// timer for generation of forward ants		ra_addr_ = id;		// agent address 	ant_seq_num_ = 0;	// initialize sequence number of ant packets to zero}//////////////////////////////////////////////////////////////////// commands that the agent can handle/////////////////////////////////////////////////////////////////int Antnet::command(int argc, const char*const* argv) {	if (argc == 2) {		if(strcasecmp(argv[1], "start") == 0) {	// begin AntNet algorithm			initialize_rtable();	// initialize routing tables			ant_timer_.resched(0.);	// schedule timer to begin ant generation now			return TCL_OK;		}		else if(strcasecmp(argv[1], "stop") == 0) {	// stop AntNet algorithm			ant_timer_.cancel();	// cancel any scheduled timers			return TCL_OK;		}		else if (strcasecmp(argv[1], "print_rtable") == 0) {	// print routing tables to a file			FILE *fp = fopen(file_rtable,"a");	// file name defined in antnet_common.h			fprintf(fp,"\nRouting table at node %d\n",addr());			fclose(fp);			rtable_.print();	// call method to print routing table			return TCL_OK;		} 	}	else if (argc == 3) {		// obtain corresponding dmux to carry packets		if (strcmp(argv[1], "port-dmux") == 0) {			dmux_ = (PortClassifier*)TclObject::lookup(argv[2]);			if (dmux_ == 0) {				fprintf(stderr, "%s: %s lookup of %s failed\n",__FILE__,argv[1],argv[2]);				return TCL_ERROR; 			}			return TCL_OK; 		}		// obtain corresponding tracer		else if (strcmp(argv[1], "log-target") == 0 || strcmp(argv[1], "tracetarget") == 0) {			logtarget_ = (Trace*)TclObject::lookup(argv[2]);			if (logtarget_ == 0)				return TCL_ERROR;			return TCL_OK;		}	}	// add node1 to neighbor list of node2 and vice-versa (we assume duplex link)	else if (argc == 4) {		if(strcmp(argv[1], "add-neighbor") == 0) {			Node *node1 = (Node*)TclObject::lookup(argv[2]);			Node *node2 = (Node*)TclObject::lookup(argv[3]);			add_Neighbor(node1, node2);			return TCL_OK;		}	} 	// Pass the command to the base class	return Agent::command(argc, argv);}//////////////////////////////////////////////////////////////////// Agent recieves ant packets/////////////////////////////////////////////////////////////////void Antnet::recv(Packet *p, Handler *h) {	struct hdr_cmn *ch = HDR_CMN(p);	// common header	struct hdr_ip *ih = HDR_IP(p);		// ip header	struct hdr_ant_pkt *ah = HDR_ANT_PKT(p);// ant header			if((int)ih->saddr() == ra_addr()) {		// If loop, drop the packet		if (ch->num_forwards() > 0) {			drop(p, DROP_RTR_ROUTE_LOOP);		}		// else if reciever is the source		else if (ch->num_forwards() == 0){				}	}	else {		// recieved packet is an Ant packet		if(ch->ptype() == PT_ANT) {			// call method to handle ant packet			recv_ant_pkt(p);		}		// if not Ant packet, drop		else {			drop(p, DROP_RTR_ROUTE_LOOP);		}	}}//////////////////////////////////////////////////////////////////// Method to send a forward ant/// Called when ant timer expires/////////////////////////////////////////////////////////////////void Antnet::send_ant_pkt() {	nsaddr_t next, dest;	Packet* p = allocpkt();			// allocate new packet	struct hdr_cmn* ch = HDR_CMN(p);	// common header	struct hdr_ip* ih = HDR_IP(p);		// ip header	struct hdr_ant_pkt* ah = HDR_ANT_PKT(p);// ant header		ah->pkt_type() = FORWARD_ANT;		// set ant type as FORWARD ant	ah->pkt_src() = addr();			// source address	ah->pkt_len() = ANT_SIZE;		// length of ant header	ah->pkt_seq_num() = ant_seq_num_++;	// sequence number	ah->pkt_start_time() = CURRENT_TIME;	// packet generation time	dest = rtable_.calc_destination(addr());// generate random destination	ah->pkt_dst() = dest;			// set packet destination	ah->pkt_mem_size() = 0;			// initialize size of memory	ah->pkt_memory_[0].node_addr = addr();	// add source node to memory	ah->pkt_memory_[0].trip_time = 0.0;	// add trip time to this node to memory	ah->pkt_mem_size()++;			// increment size of memory			ch->ptype() = PT_ANT;			// set packet type as Ant	ch->direction() = hdr_cmn::DOWN;	// forward ant	ch->size() = IP_HDR_LEN + ah->pkt_len();// packet header size	ch->error() = 0;	ch->addr_type() = NS_AF_INET;	// generate next hop as per AntNet algorithm	next = rtable_.calc_next(addr(), ah->pkt_dst(), addr());	// if next hop same as this node, release packet	if(next == addr()) {		Packet::free(p);		return;	}	ch->next_hop() = next;		// set next hop address in common header		ih->saddr() = addr();		// set source address in ip header	ih->daddr() = next;		// set destination address in ip header	ih->ttl() = 2 * (NUM_NODES);	// set time-to-live	if(DEBUG)		fprintf(stdout,"sending antnet packet from %d to %d next hop %d\n", ah->pkt_src(), ah->pkt_dst(), ih->daddr());		target_->recv(p);	// send forward ant packet}////////////////////////////////////////////////////////////////////// Method to recieve Ant packet at the Agent/// Calls appropriate methods to process forward and backward ants///////////////////////////////////////////////////////////////////void Antnet::recv_ant_pkt(Packet* p) {	struct hdr_ip* ih = HDR_IP(p);		// ip header	struct hdr_cmn* ch = HDR_CMN(p);	// common header	struct hdr_ant_pkt* ah = HDR_ANT_PKT(p);// ant header		assert(ih->sport() == RT_PORT);	assert(ih->dport() == RT_PORT);		if(DEBUG)		printf("In recv_antnet_pkt() %d at node %d %d source %d dest %d\n", ch->direction(), addr(), ih->daddr(), ah->pkt_src(), ah->pkt_dst());		if(ch->direction() == hdr_cmn::DOWN) {	// forward ant		if(addr() == ah->pkt_dst()) {	// destination node			// add this node to memory			memorize(p);			// create backward ant			create_backward_ant_pkt(p);		}		else {		// not destination node			// add this node to memory			memorize(p);			// send forward ant to next hop node as determined by AntNet algorithm			forward_ant_pkt(p);		}	}	else 	if(ch->direction() == hdr_cmn::UP) {	// backward ant		if(addr() == ah->pkt_dst()) {	// destination node, travel complete		    //00000000000000		     //update_traffic(p);			// update routing table			update_table(p);			// release packet			Packet::free(p);			return;		}		else {		// not destination node		     //00000000000000000000		    // update_traffic(p);			// update routing table			update_table(p);			// send backward ant to next hop node as determined by memory			backward_ant_pkt(p);		}	}}////////////////////////////////////////////////////////////////////// Method to build meory of forward ant///////////////////////////////////////////////////////////////////void Antnet::memorize(Packet* p) {	struct hdr_ant_pkt* tmp = HDR_ANT_PKT(p);	// ant header		double time = CURRENT_TIME - tmp->pkt_start_time();	// trip time to this node		// If node revisited, there is a loop, remove loop and corresponding memory	for(int i=0; i<tmp->pkt_mem_size(); i++) {		if(tmp->pkt_memory_[i].node_addr == addr()) {			double t = time - tmp->pkt_memory_[i].trip_time;			tmp->pkt_mem_size() = i+1;			for(int j=0; j <= i; j++) {				tmp->pkt_memory_[j].trip_time += t;			}			return;		}	}		// add current node to memory	tmp->pkt_memory_[tmp->pkt_mem_size()].node_addr = addr();	tmp->pkt_memory_[tmp->pkt_mem_size()].trip_time = time;	tmp->pkt_mem_size() = tmp->pkt_mem_size()+1;	if(DEBUG) {		fprintf(stdout,"adding %d to memory of pkt %d\n", addr(), tmp->pkt_seq_num());	}}//////////////////////////////////////////////////////////////////////////////////////////// Method to send forward ant packet to next hop node as determined by AntNet algorithm////////////////////////////////////////////////////////////////////////////////////////void Antnet::forward_ant_pkt(Packet* p) {	struct hdr_ip* ih = HDR_IP(p);		// ip header	struct hdr_cmn* ch = HDR_CMN(p);	// common header	struct hdr_ant_pkt* ah = HDR_ANT_PKT(p);// ant header	nsaddr_t parent = ih->saddr();	// parent node	// find next hop node as per AntNet algorithm

?? 快捷鍵說明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
麻豆视频观看网址久久| 国产精品的网站| 免费不卡在线视频| 欧美mv日韩mv国产网站| 麻豆国产欧美日韩综合精品二区| 日韩一区二区三区四区| 精品一区二区影视| 国产天堂亚洲国产碰碰| 日本精品一区二区三区高清| 日日欢夜夜爽一区| 国产亚洲欧美色| 在线日韩av片| 国产成人免费在线观看不卡| 国产精品久线观看视频| 欧美综合亚洲图片综合区| 日本不卡视频在线观看| 久久精品视频免费观看| 在线国产亚洲欧美| 久久99久久久久久久久久久| 国产精品久久久久久久久快鸭 | 欧美日韩一区二区三区在线看| 日韩高清一区在线| 国产精品乱码一区二三区小蝌蚪| 色国产精品一区在线观看| 久久精品国产999大香线蕉| 国产精品高潮呻吟| 欧美一二三区精品| 91在线观看高清| 麻豆一区二区99久久久久| 成人免费在线播放视频| 8x8x8国产精品| 菠萝蜜视频在线观看一区| 日韩av中文字幕一区二区| 最好看的中文字幕久久| 精品国产乱码久久久久久夜甘婷婷| 99久免费精品视频在线观看| 奇米色一区二区三区四区| 亚洲女同ⅹxx女同tv| 久久伊99综合婷婷久久伊| 色婷婷久久久亚洲一区二区三区| 激情综合色播激情啊| 亚洲高清不卡在线| 欧美国产日产图区| 精品国产乱码久久久久久影片| 在线视频综合导航| 99久久精品免费看国产| 国产激情视频一区二区在线观看| 亚洲va韩国va欧美va| ...xxx性欧美| 中文字幕欧美区| 精品少妇一区二区三区在线播放 | 中文字幕日韩欧美一区二区三区| 日韩色视频在线观看| 欧美日韩综合在线免费观看| 不卡在线观看av| 国产高清不卡一区| 精品一区二区三区在线观看| 婷婷久久综合九色综合伊人色| 麻豆91免费观看| 日产精品久久久久久久性色| 亚洲一区中文日韩| 一区av在线播放| 亚洲精品老司机| 亚洲人成精品久久久久久| 国产精品卡一卡二| 国产精品国产精品国产专区不蜜| 久久久久久久久久久久久夜| 精品国产一区二区三区久久久蜜月 | 91精品国模一区二区三区| 欧美三级日本三级少妇99| 色婷婷综合久色| 色网站国产精品| 在线中文字幕一区二区| 欧美亚洲另类激情小说| 欧美午夜电影在线播放| 欧美影院一区二区三区| 欧美日韩一区三区| 制服丝袜av成人在线看| 欧美福利一区二区| 日韩欧美亚洲一区二区| 欧美va在线播放| 久久综合九色综合欧美98 | 欧美一区二区视频网站| 91精品国产aⅴ一区二区| 日韩一区二区免费在线观看| 日韩欧美一区电影| xvideos.蜜桃一区二区| 中文欧美字幕免费| 亚洲欧美日韩国产一区二区三区| 一区二区三区精品视频| 视频一区二区三区中文字幕| 久久成人综合网| 丰满亚洲少妇av| 91极品视觉盛宴| 欧美一区二区三区成人| 精品第一国产综合精品aⅴ| 亚洲国产成人私人影院tom| 日韩美女精品在线| 午夜精品123| 国产精品系列在线播放| 色综合天天做天天爱| 欧美日韩aaaaa| 久久综合999| 麻豆精品一区二区三区| 国产成人亚洲精品狼色在线| 97久久超碰精品国产| 欧美日韩国产综合久久 | 成人激情免费网站| 欧美中文字幕一区二区三区| 日韩一区二区精品| 国产精品麻豆一区二区| 日韩精品国产欧美| 国产成人精品免费网站| 欧美三区在线观看| 久久久久久久久久久电影| 一区二区三区久久久| 国产在线国偷精品免费看| 91老师国产黑色丝袜在线| 91精品久久久久久久91蜜桃| 国产精品欧美精品| 日韩va欧美va亚洲va久久| 不卡视频一二三四| 精品国产免费人成电影在线观看四季| 中文字幕日韩一区二区| 看国产成人h片视频| 99精品久久久久久| 久久综合九色综合久久久精品综合| 亚洲激情图片qvod| 丁香天五香天堂综合| 91精品国产91久久久久久最新毛片| 国产精品色眯眯| 黄页视频在线91| 精品视频色一区| 国产精品久久久久一区二区三区 | 在线视频亚洲一区| 国产精品乱码久久久久久| 男女男精品视频网| 欧美在线免费观看亚洲| 综合分类小说区另类春色亚洲小说欧美| 麻豆视频观看网址久久| 欧美日韩国产不卡| 亚洲一区二区视频在线观看| 成人av午夜电影| 国产日韩欧美电影| 韩国三级电影一区二区| 6080午夜不卡| 亚洲h动漫在线| 欧美中文字幕不卡| 亚洲精品欧美二区三区中文字幕| 国产在线视频精品一区| 日韩精品一区二区三区蜜臀| 午夜电影网一区| 欧美日韩精品一区二区三区四区 | 成人白浆超碰人人人人| 欧美精品一区二区三区在线 | 中文字幕亚洲视频| 国产91高潮流白浆在线麻豆| 欧美成人性福生活免费看| 免费观看在线色综合| 日韩区在线观看| 美国av一区二区| 精品处破学生在线二十三| 韩国精品主播一区二区在线观看| 欧美一区二区久久| 日本va欧美va瓶| 欧美变态口味重另类| 国内成人自拍视频| 2014亚洲片线观看视频免费| 激情六月婷婷综合| 久久久美女毛片| 国产馆精品极品| 国产精品色眯眯| 97se亚洲国产综合自在线不卡 | 久久色视频免费观看| 韩国视频一区二区| 国产网站一区二区| www.欧美色图| 一区二区三区四区视频精品免费| 不卡一区二区三区四区| 一区二区视频在线看| 欧亚一区二区三区| 七七婷婷婷婷精品国产| 久久这里只精品最新地址| 国产成人综合网| 亚洲啪啪综合av一区二区三区| 91啦中文在线观看| 手机精品视频在线观看| 精品国精品自拍自在线| 波多野结衣的一区二区三区| 一个色综合网站| 欧美一区二区观看视频| 国产69精品一区二区亚洲孕妇| 欧美国产丝袜视频| 欧美调教femdomvk| 黄页视频在线91| 尤物视频一区二区| 日韩精品中文字幕一区二区三区| 成人三级伦理片| 丝袜美腿成人在线| 亚洲国产成人自拍|