1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210
| void
CMUTrace::format_mac_common(Packet *p, const char *why, int offset)
{
hdr_sr *srh = hdr_sr::access(p);
struct hdr_cmn *ch = HDR_CMN(p);
struct hdr_ip *ih = HDR_IP(p);
struct hdr_mac802_11 *mh;
struct hdr_smac *sh;
char mactype[SMALL_LEN];
//add by me
int typ;
double ptran;
strcpy(mactype, Simulator::instance().macType());
if (strcmp (mactype, "Mac/SMAC") == 0)
sh = HDR_SMAC(p);
else
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 ",
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
offset = strlen(pt_->buffer());
if (strcmp (mactype, "Mac/SMAC") == 0) {
format_smac(p, offset);
} else {
format_mac(p, offset);
}
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());
if (strcmp(mactype, "Mac/SMAC") == 0) {
format_smac(p, offset);
} else {
format_mac(p, offset);
}
return;
}
//add by me
typ = srh->addrs()[0].addr_type; // j'ai bien un affichage pour ce paramètre
ptran = srh->addrs()[0].Pt_;
#ifdef LOG_POSITION
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 ",
#else
"%c %f %d %f %.9f _%d_ %3s %4s %d %s %d",
//"%c %f %f/e-9 %f %.9f _%d_ %3s %4s %d %s %d",
#endif
op,
//add by me
ptran,
typ,
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_type == MAC_Type_Control) ? (
(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":
//<zheng: add for 802.15.4>
(mh->dh_fc.fc_subtype == MAC_Subtype_Beacon) ? "BCN" : //Beacon
(mh->dh_fc.fc_subtype == MAC_Subtype_Command_AssoReq) ? "CM1" : //CMD: Association request
(mh->dh_fc.fc_subtype == MAC_Subtype_Command_AssoRsp) ? "CM2" : //CMD: Association response
(mh->dh_fc.fc_subtype == MAC_Subtype_Command_DAssNtf) ? "CM3" : //CMD: Disassociation notification
(mh->dh_fc.fc_subtype == MAC_Subtype_Command_DataReq) ? "CM4" : //CMD: Data request
(mh->dh_fc.fc_subtype == MAC_Subtype_Command_PIDCNtf) ? "CM5" : //CMD: PAN ID conflict notification
(mh->dh_fc.fc_subtype == MAC_Subtype_Command_OrphNtf) ? "CM6" : //CMD: Orphan notification
(mh->dh_fc.fc_subtype == MAC_Subtype_Command_BconReq) ? "CM7" : //CMD: Beacon request
(mh->dh_fc.fc_subtype == MAC_Subtype_Command_CoorRea) ? "CM8" : //CMD: Coordinator realignment
(mh->dh_fc.fc_subtype == MAC_Subtype_Command_GTSReq) ? "CM9" : //CMD: GTS request
"UNKN") :
(mh->dh_fc.fc_type == MAC_Type_Management) ? (
(mh->dh_fc.fc_subtype == MAC_Subtype_80211_Beacon) ? "BCN" :
(mh->dh_fc.fc_subtype == MAC_Subtype_AssocReq) ? "ACRQ" :
(mh->dh_fc.fc_subtype == MAC_Subtype_AssocRep) ? "ACRP" :
(mh->dh_fc.fc_subtype == MAC_Subtype_Auth) ? "AUTH" :
(mh->dh_fc.fc_subtype == MAC_Subtype_ProbeReq) ? "PRRQ" :
(mh->dh_fc.fc_subtype == MAC_Subtype_ProbeRep) ? "PRRP" :
"UNKN") :
"UNKN") :
(ch->ptype() == PT_SMAC) ? (
(sh->type == RTS_PKT) ? "RTS" :
(sh->type == CTS_PKT) ? "CTS" :
(sh->type == ACK_PKT) ? "ACK" :
(sh->type == SYNC_PKT) ? "SYNC" :
"UNKN") :
packet_info.name(ch->ptype())),
ch->size());
offset = strlen(pt_->buffer());
if(tracetype == TR_PHY) {
format_phy(p, offset);
offset = strlen(pt_->buffer());
return;
}
if (strncmp (mactype, "Mac/SMAC", 8) == 0) {
format_smac(p, offset);
} else {
format_mac(p, offset);
}
offset = strlen(pt_->buffer());
if (thisnode) {
if (thisnode->energy_model()) {
// log detailed energy consumption
// total energy and breakdown in idle, sleep, transmit and receive modes
sprintf(pt_->buffer() + offset,
"[energie %f ei %.3f es %.3f et %.3f er %.3f] ",
thisnode->energy_model()->energy(),
thisnode->energy_model()->ei(),
thisnode->energy_model()->es(),
thisnode->energy_model()->et(),
thisnode->energy_model()->er());
}
}
} |
Partager