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

📄 cmu-trace.cc

📁 对ns2软件进行UMTS扩展
💻 CC
📖 第 1 页 / 共 3 页
字号:
/* -*-	Mode:C++; c-basic-offset:8; tab-width:8; indent-tabs-mode:t -*- *//* Modified and extended by Pablo Martin and Paula Ballester, * Strathclyde University, Glasgow. * June, 2003.*//* Copyright (c) 2003 Strathclyde University of Glasgow, Scotland. * 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 and binary code must contain * the above copyright notice, this list of conditions and the following * disclaimer. * * 2. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed at Strathclyde University of * Glasgow, Scotland. * * 3. The name of the University may not be used to endorse or promote * products derived from this software without specific prior written * permission. * STRATHCLYDE UNIVERSITY OF GLASGOW, MAKES NO REPRESENTATIONS * CONCERNING EITHER THE MERCHANTABILITY OF THIS SOFTWARE OR THE * SUITABILITY OF THIS SOFTWARE FOR ANY PARTICULAR PURPOSE.  The software * is provided "as is" without express or implied warranty of any kind.*//* * 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.67 2002/09/12 00:22:01 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>// P.M. & P.B. modifications#include "rlc-umts.h"#include "phy-umts.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;        }	  // P.M. & P.B. modifications	  else if(strcmp(tracename, "PHY") == 0) {                tracetype = TR_PHY;        }        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());		}        }}// P.M. & P.B. modificationsvoidCMUTrace::format_phy(Packet *p, const char *why, int offset){	struct hdr_cmn *ch = HDR_CMN(p);	struct hdr_ip *ih = HDR_IP(p);	struct hdr_phy *ph = HDR_PHY_UMTS(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(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	    // phy layer extension	    offset = strlen(pt_->buffer());	    sprintf(pt_->buffer() + offset,		    "-Phs %d -Phd %d -Phc %d -Php %e ",		    ph->sa_,		    ph->da_,		    ch->channel_t(),		    ph->rx_power_);	     return;	}	return;}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,

⌨️ 快捷键说明

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