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

📄 cmu-trace.cc

📁 MAODV代码和安装程序 hen nan找啊
💻 CC
📖 第 1 页 / 共 3 页
字号:
/* -*-	Mode:C++; c-basic-offset:8; tab-width:8; indent-tabs-mode:t -*- *//* * Copyright (c) 1997 Regents of the University of California. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright *    notice, this list of conditions and the following disclaimer. * 2. 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. * 3. All advertising materials mentioning features or use of this software *    must display the following acknowledgement: *	This product includes software developed by the Computer Systems *	Engineering Group at Lawrence Berkeley Laboratory. * 4. Neither the name of the University nor of the Laboratory may be used *    to endorse or promote products derived from this software without *    specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``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 THE REGENTS OR CONTRIBUTORS 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. * * Ported from CMU/Monarch's code, appropriate copyright applies. * nov'98 -Padma. * * $Header: /nfs/jade/vint/CVSROOT/ns-2/trace/cmu-trace.cc,v 1.72 2003/02/22 03:53:35 buchheim Exp $ */#include <packet.h>#include <ip.h>#include <tcp.h>#include <rtp.h>#include <arp.h>#include <dsr/hdr_sr.h>	// DSR#include <mac.h>#include <mac-802_11.h>#include <address.h>#include <tora/tora_packet.h> //TORA#include <imep/imep_spec.h>         // IMEP#include <aodv/aodv_packet.h> //AODV#include <cmu-trace.h>#include <mobilenode.h>#include "diffusion/diff_header.h" // DIFFUSION -- Chalermek//#define LOG_POSITION//extern char* pt_names[];static class CMUTraceClass : public TclClass {public:	CMUTraceClass() : TclClass("CMUTrace") { }	TclObject* create(int, const char*const* argv) {		return (new CMUTrace(argv[4], *argv[5]));	}} cmutrace_class;double CMUTrace::bradius = 0.0;double CMUTrace::radius_scaling_factor_ = 0.0;double CMUTrace::duration_scaling_factor_ = 0.0;CMUTrace::CMUTrace(const char *s, char t) : Trace(t){	bzero(tracename, sizeof(tracename));	strncpy(tracename, s, MAX_ID_LEN);        if(strcmp(tracename, "RTR") == 0) {                tracetype = TR_ROUTER;        }	else if(strcmp(tracename, "TRP") == 0) {                tracetype = TR_ROUTER;        }        else if(strcmp(tracename, "MAC") == 0) {                tracetype = TR_MAC;        }        else if(strcmp(tracename, "IFQ") == 0) {                tracetype = TR_IFQ;        }        else if(strcmp(tracename, "AGT") == 0) {                tracetype = TR_AGENT;        }        else {                fprintf(stderr, "CMU Trace Initialized with invalid type\n");                exit(1);        }	assert(type_ == DROP || type_ == SEND || type_ == RECV);	newtrace_ = 0;	for (int i=0 ; i < MAX_NODE ; i++) 		nodeColor[i] = 3 ;        node_ = 0;}voidCMUTrace::format_mac(Packet *p, const char *why, int offset){	struct hdr_cmn *ch = HDR_CMN(p);	struct hdr_ip *ih = HDR_IP(p);	struct hdr_mac802_11 *mh = HDR_MAC802_11(p);	double x = 0.0, y = 0.0, z = 0.0;       	char op = (char) type_;	Node* thisnode = Node::get_node_by_address(src_);	double energy = -1;	if (thisnode) {	    if (thisnode->energy_model()) {		    energy = thisnode->energy_model()->energy();	    }	}	// hack the IP address to convert pkt format to hostid format	// for now until port ids are removed from IP address. -Padma.	int src = Address::instance().get_nodeaddr(ih->saddr());	if(tracetype == TR_ROUTER && type_ == SEND) {		if(src_ != src)			op = FWRD;	}	// use tagged format if appropriate	if (pt_->tagged()) {		int next_hop = -1 ;		Node* nextnode = Node::get_node_by_address(ch->next_hop_);        	if (nextnode) next_hop = nextnode->nodeid(); 		node_->getLoc(&x, &y, &z);		if (op == DROP) op = 'd';		if (op == SEND) op = '+';		if (op == FWRD) op = 'h';		sprintf(pt_->buffer() + offset,			"%c "TIME_FORMAT" -s %d -d %d -p %s -k %3s -i %d "			"-N:loc {%.2f %.2f %.2f} -N:en %f "			"-M:dur %x -M:s %x -M:d %x -M:t %x ",			op,				// event type			Scheduler::instance().clock(),	// time			src_,				// this node			next_hop,			// next hop			packet_info.name(ch->ptype()),	// packet type			tracename,			// trace level			ch->uid(),			// event id			x, y, z,			// location			energy,				// energy			mh->dh_duration,		// MAC: duration			ETHER_ADDR(mh->dh_da),		// MAC: source			ETHER_ADDR(mh->dh_sa),		// MAC: destination			GET_ETHER_TYPE(mh->dh_body)	// MAC: type			);		return;	}	// Use new ns trace format to replace the old cmu trace format)	if (newtrace_) {	    	    node_->getLoc(&x, &y, &z);	    // consistence	    if ( op == DROP ) { op = 'd';}	        // basic trace infomation + basic exenstion	    sprintf(pt_->buffer() + offset,		   "%c -t %.9f -Hs %d -Hd %d -Ni %d -Nx %.2f -Ny %.2f -Nz %.2f -Ne %f -Nl %3s -Nw %s ",		    op,                       // event type		    Scheduler::instance().clock(),  // time		    src_,                           // this node                    ch->next_hop_,                  // next hop		    src_,                           // this node		    x,                              // x coordinate		    y,                              // y coordinate		    z,                              // z coordinate		    energy,                         // energy, -1 = not existing		    tracename,                      // trace level                    why);                            // reason	    // mac layer extension	    offset = strlen(pt_->buffer());	    sprintf(pt_->buffer() + offset, 		    "-Ma %x -Md %x -Ms %x -Mt %x ",		    mh->dh_duration,		    ETHER_ADDR(mh->dh_da),		    ETHER_ADDR(mh->dh_sa),		    GET_ETHER_TYPE(mh->dh_body));		    	     return;	}#ifdef LOG_POSITION        double x = 0.0, y = 0.0, z = 0.0;        node_->getLoc(&x, &y, &z);#endif	sprintf(pt_->buffer() + offset,#ifdef LOG_POSITION		"%c %.9f %d (%6.2f %6.2f) %3s %4s %d %s %d [%x %x %x %x] ",#else		"%c %.9f _%d_ %3s %4s %d %s %d [%x %x %x %x] ",#endif		op,		Scheduler::instance().clock(),                src_,                           // this node#ifdef LOG_POSITION                x,                y,#endif		tracename,		why,		                ch->uid(),                      // identifier for this event				((ch->ptype() == PT_MAC) ? (		  (mh->dh_fc.fc_subtype == MAC_Subtype_RTS) ? "RTS"  :		  (mh->dh_fc.fc_subtype == MAC_Subtype_CTS) ? "CTS"  :		  (mh->dh_fc.fc_subtype == MAC_Subtype_ACK) ? "ACK"  :		  "UNKN"		  ) : packet_info.name(ch->ptype())),				ch->size(),		//*((u_int16_t*) &mh->dh_fc),		mh->dh_duration,		ETHER_ADDR(mh->dh_da),		ETHER_ADDR(mh->dh_sa),		GET_ETHER_TYPE(mh->dh_body));	offset = strlen(pt_->buffer());	if (thisnode) {		if (thisnode->energy_model()) {			sprintf(pt_->buffer() + offset,				"[energy %f] ",				thisnode->energy_model()->energy());		}        }}voidCMUTrace::format_ip(Packet *p, int offset){        struct hdr_cmn *ch = HDR_CMN(p);	struct hdr_ip *ih = HDR_IP(p);		// hack the IP address to convert pkt format to hostid format	// for now until port ids are removed from IP address. -Padma.	int src = Address::instance().get_nodeaddr(ih->saddr());	int dst = Address::instance().get_nodeaddr(ih->daddr());	if (pt_->tagged()) {		sprintf(pt_->buffer() + offset,			"-IP:s %d -IP:sp %d -IP:d %d -IP:dp %d -p %s -e %d "			"-c %d -i %d -IP:ttl %d ",			src,                           // packet src			ih->sport(),                   // src port			dst,                           // packet dest			ih->dport(),                   // dst port			packet_info.name(ch->ptype()), // packet type			ch->size(),                    // packet size			ih->flowid(),                  // flow id			ch->uid(),                     // unique id			ih->ttl_                       // ttl			);	} else if (newtrace_) {	    sprintf(pt_->buffer() + offset,		    "-Is %d.%d -Id %d.%d -It %s -Il %d -If %d -Ii %d -Iv %d ",		    src,                           // packet src		    ih->sport(),                   // src port		    dst,                           // packet dest		    ih->dport(),                   // dst port		    packet_info.name(ch->ptype()),  // packet type		    ch->size(),                     // packet size		    ih->flowid(),                   // flow id		    ch->uid(),                      // unique id		    ih->ttl_);                      // ttl	} else {            sprintf(pt_->buffer() + offset, "------- [%d:%d %d:%d %d %d] ",                src, ih->sport(),                dst, ih->dport(),                ih->ttl_, (ch->next_hop_ < 0) ? 0 : ch->next_hop_);	}}voidCMUTrace::format_arp(Packet *p, int offset){	struct hdr_arp *ah = HDR_ARP(p);	if (pt_->tagged()) {	    sprintf(pt_->buffer() + offset,		    "-arp:op %s -arp:ms %d -arp:s %d -arp:md %d -arp:d %d ",		    ah->arp_op == ARPOP_REQUEST ?  "REQUEST" : "REPLY",		    ah->arp_sha,		    ah->arp_spa,		    ah->arp_tha,		    ah->arp_tpa);	} else if (newtrace_) {	    sprintf(pt_->buffer() + offset,		    "-P arp -Po %s -Pms %d -Ps %d -Pmd %d -Pd %d ",		    ah->arp_op == ARPOP_REQUEST ?  "REQUEST" : "REPLY",		    ah->arp_sha,		    ah->arp_spa,		    ah->arp_tha,		    ah->arp_tpa);	} else {	    sprintf(pt_->buffer() + offset,		"------- [%s %d/%d %d/%d]",		ah->arp_op == ARPOP_REQUEST ?  "REQUEST" : "REPLY",		ah->arp_sha,		ah->arp_spa,		ah->arp_tha,		ah->arp_tpa);	}}voidCMUTrace::format_dsr(Packet *p, int offset){	hdr_sr *srh = hdr_sr::access(p);	if (pt_->tagged()) {	    sprintf(pt_->buffer() + offset,		    "-dsr:h %d -dsr:q %d -dsr:s %d -dsr:p %d -dsr:n %d "		    "-dsr:l %d -dsr:e {%d %d} -dsr:w %d -dsr:m %d -dsr:c %d "		    "-dsr:b {%d %d} ",		    srh->num_addrs(),		    srh->route_request(),		    srh->rtreq_seq(),		    srh->route_reply(),		    srh->rtreq_seq(),		    srh->route_reply_len(),		    srh->reply_addrs()[0].addr,		    srh->reply_addrs()[srh->route_reply_len()-1].addr,		    srh->route_error(),		    srh->num_route_errors(),		    srh->down_links()[srh->num_route_errors() - 1].tell_addr,		    srh->down_links()[srh->num_route_errors() - 1].from_addr,		    srh->down_links()[srh->num_route_errors() - 1].to_addr);	    return;	} else if (newtrace_) {	    sprintf(pt_->buffer() + offset, 		"-P dsr -Ph %d -Pq %d -Ps %d -Pp %d -Pn %d -Pl %d -Pe %d->%d -Pw %d -Pm %d -Pc %d -Pb %d->%d ",		    srh->num_addrs(),                   // how many nodes travered		srh->route_request(),		srh->rtreq_seq(),		srh->route_reply(),		srh->rtreq_seq(),		srh->route_reply_len(),		// the dest of the src route		srh->reply_addrs()[0].addr,		srh->reply_addrs()[srh->route_reply_len()-1].addr,		srh->route_error(),		srh->num_route_errors(),		srh->down_links()[srh->num_route_errors() - 1].tell_addr,

⌨️ 快捷键说明

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