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

📄 cmu-trace.cc

📁 ns2--网络仿真软件扩展!·
💻 CC
📖 第 1 页 / 共 2 页
字号:
			"-P tora -Pt 0x%x -Pd %d -Pc QUERY ",                        qh->tq_type, qh->tq_dst);			                } else {                    sprintf(wrk_ + offset, "[0x%x %d] (QUERY)",                        qh->tq_type, qh->tq_dst);		}                break;        case TORATYPE_UPD:		if (newtrace_) {		    sprintf(wrk_ + offset,                        "-P tora -Pt 0x%x -Pd %d (%f %d %d %d %d) -Pc UPDATE ",                        uh->tu_type,                        uh->tu_dst,                        uh->tu_tau,                        uh->tu_oid,                        uh->tu_r,                        uh->tu_delta,                        uh->tu_id);		} else {                    sprintf(wrk_ + offset,                        "-Pt 0x%x -Pd %d -Pa %f -Po %d -Pr %d -Pe %d -Pi %d -Pc UPDATE ",                        uh->tu_type,                        uh->tu_dst,                        uh->tu_tau,                        uh->tu_oid,                        uh->tu_r,                        uh->tu_delta,                        uh->tu_id);		}                break;        case TORATYPE_CLR:		if (newtrace_) {		    sprintf(wrk_ + offset, 			"-P tora -Pt 0x%x -Pd %d -Pa %f -Po %d -Pc CLEAR ",                        ch->tc_type,                        ch->tc_dst,                        ch->tc_tau,                        ch->tc_oid);		} else {                    sprintf(wrk_ + offset, "[0x%x %d %f %d] (CLEAR)",                        ch->tc_type,                        ch->tc_dst,                        ch->tc_tau,                        ch->tc_oid);		}                break;        }}voidCMUTrace::format_aodv(Packet *p, int offset){        struct hdr_aodv *ah = HDR_AODV(p);        struct hdr_aodv_request *rq = HDR_AODV_REQUEST(p);        struct hdr_aodv_reply *rp = HDR_AODV_REPLY(p);        switch(ah->ah_type) {        case AODVTYPE_RREQ:		if (newtrace_) {		    sprintf(wrk_ + offset,			"-P aodv -Pt 0x%x -Ph %d -Pb %d -Pd %d -Pds %d -Ps %d -Pss %d -Pc REQUEST ",			rq->rq_type,                        rq->rq_hop_count,                        rq->rq_bcast_id,                        rq->rq_dst,                        rq->rq_dst_seqno,                        rq->rq_src,                        rq->rq_src_seqno);		} else {		    sprintf(wrk_ + offset,			"[0x%x %d %d [%d %d] [%d %d]] (REQUEST)",			rq->rq_type,                        rq->rq_hop_count,                        rq->rq_bcast_id,                        rq->rq_dst,                        rq->rq_dst_seqno,                        rq->rq_src,                        rq->rq_src_seqno);		}                break;        case AODVTYPE_RREP:        case AODVTYPE_UREP:        case AODVTYPE_HELLO:		if (newtrace_) {		    sprintf(wrk_ + offset,			"-P aodv -Pt 0x%x -Ph %d -Pd %d -Pds %d -Pl %d -Pc %s ",			rp->rp_type,                        rp->rp_hop_count,                        rp->rp_dst,                        rp->rp_dst_seqno,                        rp->rp_lifetime,                        rp->rp_type == AODVTYPE_RREP ? "REPLY" :                        (rp->rp_type == AODVTYPE_UREP ? "UNSOLICITED REPLY" :                         "HELLO"));	        } else {		    sprintf(wrk_ + offset,			"[0x%x %d [%d %d] %d] (%s)",			rp->rp_type,                        rp->rp_hop_count,                        rp->rp_dst,                        rp->rp_dst_seqno,                        rp->rp_lifetime,                        rp->rp_type == AODVTYPE_RREP ? "REPLY" :                        (rp->rp_type == AODVTYPE_UREP ? "UNSOLICITED REPLY" :                         "HELLO"));		}                break;        default:#ifdef WIN32                fprintf(stderr,		        "CMUTrace::format_aodv: invalid AODV packet type\n");#else		fprintf(stderr,		        "%s: invalid AODV packet type\n", __FUNCTION__);#endif                abort();        }}voidCMUTrace::nam_format(Packet *p, int offset){	Node* srcnode = 0 ;	Node* dstnode = 0 ;	Node* nextnode = 0 ;        struct hdr_cmn *ch = HDR_CMN(p);	struct hdr_ip *ih = HDR_IP(p);	char op = (char) type_;	char colors[32];	int next_hop = -1 ;        int dst = Address::instance().get_nodeaddr(ih->daddr());	nextnode = Node::get_node_by_address(ch->next_hop_);        if (nextnode) next_hop = nextnode->nodeid(); 	srcnode = Node::get_node_by_address(src_);	dstnode = Node::get_node_by_address(ch->next_hop_);	double distance = 0;        if ((srcnode) && (dstnode)) {	   MobileNode* tmnode = (MobileNode*)srcnode;	   MobileNode* rmnode = (MobileNode*)dstnode;	   distance = tmnode->propdelay(rmnode) * 300000000 ;	}	double energy = -1;	double initenergy = -1;	//default value for changing node color with respect to energy depletion	double l1 = 0.5; 	double l2 = 0.2;		if (srcnode) {	    if (srcnode->energy_model()) {		    energy = srcnode->energy_model()->energy();		    initenergy = srcnode->energy_model()->initialenergy();		    l1 = srcnode->energy_model()->level1();		    l2 = srcnode->energy_model()->level2();	    }	}        int energyLevel = 0 ;        double energyLeft = (double)(energy/initenergy) ;        if ((energyLeft <= 1 ) && (energyLeft >= l1 )) energyLevel = 3;	        if ((energyLeft >= l2 ) && (energyLeft < l1 )) energyLevel = 2;	        if ((energyLeft > 0 ) && (energyLeft < l2 )) energyLevel = 1;		if (energyLevel == 0) 		strcpy(colors,"-c black -o red");        else if (energyLevel == 1) 		strcpy(colors,"-c red -o yellow");        else if (energyLevel == 2) 		strcpy(colors,"-c yellow -o green");        else if (energyLevel == 3) 		strcpy(colors,"-c green -o black");	// A simple hack for scadds demo (fernandez's visit) -- Chalermek	int pkt_color = 0;	if (ch->ptype()==PT_DIFF) {		hdr_diff *dfh= HDR_DIFF(p);		if (dfh->mess_type != DATA) {			pkt_color = 1;		}	}	// convert to nam format 	if (op == 's') op = 'h' ;	if (op == 'D') op = 'd' ;	if (op == 'h') {	   sprintf(nwrk_ ,		"+ -t %.9f -s %d -d %d -p %s -e %d -c 2 -a %d -i %d -k %3s ",		Scheduler::instance().clock(),		src_,                           // this node		next_hop,		packet_info.name(ch->ptype()),		ch->size(),		pkt_color,   		ch->uid(),		tracename);	   offset = strlen(nwrk_);	   namdump();	   sprintf(nwrk_ ,		"- -t %.9f -s %d -d %d -p %s -e %d -c 2 -a %d -i %d -k %3s",		Scheduler::instance().clock(),		src_,                           // this node		next_hop,		packet_info.name(ch->ptype()),		ch->size(),		pkt_color,		ch->uid(),		tracename);	   offset = strlen(nwrk_);           namdump();	}        // if nodes are too far from each other	// nam won't dump SEND event 'cuz it's	// gonna be dropped later anyway	// this value 250 is pre-calculated by using 	// two-ray ground refelction model with fixed	// transmission power 3.652e-10//	if ((type_ == SEND)  && (distance > 250 )) return ;	if(tracetype == TR_ROUTER && type_ == RECV && dst != -1 ) return ;	if(type_ == RECV && dst == -1 )dst = src_ ; //broadcasting event        if (energy != -1) { //energy model being turned on	   if (nodeColor[src_] != energyLevel ) { //only dump it when node  	       sprintf(nwrk_ ,                    //color change	          "n -t %.9f -s %d -S COLOR %s",	           Scheduler::instance().clock(),	           src_,                           // this node	           colors);               offset = strlen(nwrk_);               namdump();	       nodeColor[src_] = energyLevel ;	    }           }	sprintf(nwrk_ ,		"%c -t %.9f -s %d -d %d -p %s -e %d -c 2 -a %d -i %d -k %3s",		op,		Scheduler::instance().clock(),		src_,                           // this node		next_hop,		packet_info.name(ch->ptype()),		ch->size(),		pkt_color,		ch->uid(),		tracename);	offset = strlen(nwrk_);	namdump();}void CMUTrace::format(Packet* p, const char *why){	hdr_cmn *ch = HDR_CMN(p);	int offset = 0;	/*	 * Log the MAC Header	 */	format_mac(p, why, offset);	if (namChan_) 		nam_format(p, offset);	offset = strlen(wrk_);	switch(ch->ptype()) {	case PT_MAC:		break;	case PT_ARP:		format_arp(p, offset);		break;	default:		format_ip(p, offset);		offset = strlen(wrk_);		switch(ch->ptype()) {		case PT_AODV:			format_aodv(p, offset);			break;		case PT_TORA:                        format_tora(p, offset);                        break;                case PT_IMEP:                        format_imep(p, offset);                        break;		case PT_DSR:			format_dsr(p, offset);			break;		case PT_MESSAGE:		case PT_UDP:			format_msg(p, offset);			break;		case PT_TCP:		case PT_ACK:			format_tcp(p, offset);			break;		case PT_CBR:			format_rtp(p, offset);			break;	        case PT_DIFF:			break;		// TS		case PT_EXP:			format_rtp(p, offset);			break;				default:			fprintf(stderr, "%s - invalid packet type (%s).\n",				__PRETTY_FUNCTION__, packet_info.name(ch->ptype()));			exit(1);		}	}}intCMUTrace::command(int argc, const char*const* argv){	        if(argc == 3) {                if(strcmp(argv[1], "node") == 0) {                        node_ = (MobileNode*) TclObject::lookup(argv[2]);                        if(node_ == 0)                                return TCL_ERROR;                        return TCL_OK;                }		if (strcmp(argv[1], "newtrace") == 0) {			newtrace_ = atoi(argv[2]);		        return TCL_OK;		}        }	return Trace::command(argc, argv);}/*ARGSUSED*/voidCMUTrace::recv(Packet *p, Handler *h){	if (!node_energy()) {		Packet::free(p);		return;	}        assert(initialized());        /*         * Agent Trace "stamp" the packet with the optimal route on         * sending.         */        if (tracetype == TR_AGENT && type_ == SEND) {                God::instance()->stampPacket(p);        }#if 0        /*         * When the originator of a packet drops the packet, it may or may         * not have been stamped by GOD.  Stamp it before logging the         * information.         */        if(src_ == src && type_ == DROP) {                God::instance()->stampPacket(p);        }#endif	format(p, "---");	dump();	//namdump();	if(target_ == 0)		Packet::free(p);	else		send(p, h);}voidCMUTrace::recv(Packet *p, const char* why){        assert(initialized() && type_ == DROP);	if (!node_energy()) {		Packet::free(p);		return;	}#if 0        /*         * When the originator of a packet drops the packet, it may or may         * not have been stamped by GOD.  Stamp it before logging the         * information.         */        if(src_ == ih->saddr()) {                God::instance()->stampPacket(p);        }#endif	format(p, why);	dump();	//namdump();	Packet::free(p);}int CMUTrace::node_energy(){	Node* thisnode = Node::get_node_by_address(src_);	double energy = 1;	if (thisnode) {		if (thisnode->energy_model()) {			energy = thisnode->energy_model()->energy();		}	} 	if (energy > 0) return 1;	return 0;}

⌨️ 快捷键说明

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