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

📄 cmu-trace.cc

📁 ns2--网络仿真软件扩展!·
💻 CC
📖 第 1 页 / 共 2 页
字号:
/* -*-	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/cmu-trace.cc,v 1.59 2000/09/01 03:04:05 haoboy Exp $ *//* modified Thomas Schwabe (ICSI) Sep. 2000 */#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;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 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(wrk_ + 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(wrk_);	    sprintf(wrk_ + 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(wrk_ + 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		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(wrk_);	if (thisnode) {		if (thisnode->energy_model()) {			sprintf(wrk_ + 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 (newtrace_) {	    sprintf(wrk_ + 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 {		// TS		/*		sprintf(wrk_ + offset, "------- [%d:%d %d:%d %d %d] ",		src, ih->sport(),		dst, ih->dport(),		ih->ttl_, (ch->next_hop_ < 0) ? 0 : ch->next_hop_);		*/		sprintf(wrk_ + offset, "------- %d [%s.%d %s.%d %d %d] ",			ih->flowid(),                   // flow id			Address::instance().print_nodeaddr(src), ih->sport(),			Address::instance().print_nodeaddr(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 (newtrace_) {	    sprintf(wrk_ + 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(wrk_ + 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 (newtrace_) {	    sprintf(wrk_ + 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,		srh->down_links()[srh->num_route_errors() - 1].from_addr,		srh->down_links()[srh->num_route_errors() - 1].to_addr);	   return;	}	sprintf(wrk_ + offset, 		"%d [%d %d] [%d %d %d %d->%d] [%d %d %d %d->%d]",		srh->num_addrs(),		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,		srh->down_links()[srh->num_route_errors() - 1].from_addr,		srh->down_links()[srh->num_route_errors() - 1].to_addr);}voidCMUTrace::format_msg(Packet *, int){}voidCMUTrace::format_tcp(Packet *p, int offset){	struct hdr_cmn *ch = HDR_CMN(p);	struct hdr_tcp *th = HDR_TCP(p);		if( newtrace_ ) {	    sprintf(wrk_ + offset,		"-Pn tcp -Ps %d -Pa %d -Pf %d -Po %d ",		th->seqno_,		th->ackno_,		ch->num_forwards(),		ch->opt_num_forwards());	} else {	    sprintf(wrk_ + offset,		"[%d %d] %d %d",		th->seqno_,		th->ackno_,		ch->num_forwards(),		ch->opt_num_forwards());	}}voidCMUTrace::format_rtp(Packet *p, int offset){	struct hdr_cmn *ch = HDR_CMN(p);	struct hdr_rtp *rh = HDR_RTP(p);	struct hdr_ip *ih = HDR_IP(p);        Node* thisnode = Node::get_node_by_address(src_);	//hacking, needs to change later,         int dst = Address::instance().get_nodeaddr(ih->daddr());		if (dst == src_){		// I just received a cbr data packet		if (thisnode->energy_model() && 		    thisnode->energy_model()->powersavingflag()) {			thisnode->energy_model()->set_node_state(EnergyModel::INROUTE);		}        }	if (newtrace_) {		sprintf(wrk_ + offset,			"-Pn cbr -Pi %d -Pf %d -Po %d ",			rh->seqno_,			ch->num_forwards(),			ch->opt_num_forwards());	} else {		sprintf(wrk_ + offset,			"[%d] %d %d",			rh->seqno_,			ch->num_forwards(),			ch->opt_num_forwards());	}}voidCMUTrace::format_imep(Packet *p, int offset){        struct hdr_imep *im = HDR_IMEP(p);#define U_INT16_T(x)    *((u_int16_t*) &(x))	if (newtrace_) {	    sprintf(wrk_ + offset,                "-P imep -Pa %c -Ph %c -Po %c -Pl 0x%04x ] ",                (im->imep_block_flags & BLOCK_FLAG_ACK) ? 'A' : '-',                (im->imep_block_flags & BLOCK_FLAG_HELLO) ? 'H' : '-',                (im->imep_block_flags & BLOCK_FLAG_OBJECT) ? 'O' : '-',                U_INT16_T(im->imep_length));	} else {            sprintf(wrk_ + offset,                "[%c %c %c 0x%04x] ",                (im->imep_block_flags & BLOCK_FLAG_ACK) ? 'A' : '-',                (im->imep_block_flags & BLOCK_FLAG_HELLO) ? 'H' : '-',                (im->imep_block_flags & BLOCK_FLAG_OBJECT) ? 'O' : '-',                U_INT16_T(im->imep_length));	}#undef U_INT16_T}voidCMUTrace::format_tora(Packet *p, int offset){        struct hdr_tora *th = HDR_TORA(p);        struct hdr_tora_qry *qh = HDR_TORA_QRY(p);        struct hdr_tora_upd *uh = HDR_TORA_UPD(p);        struct hdr_tora_clr *ch = HDR_TORA_CLR(p);        switch(th->th_type) {        case TORATYPE_QRY:		if (newtrace_) {		    sprintf(wrk_ + offset,

⌨️ 快捷键说明

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