INET Framework for OMNeT++/OMNEST
inet::InetPacketPrinter2 Class Reference
Inheritance diagram for inet::InetPacketPrinter2:

Public Member Functions

 InetPacketPrinter2 ()
 
virtual ~InetPacketPrinter2 ()
 
virtual int getScoreFor (cMessage *msg) const override
 
virtual void printMessage (std::ostream &os, cMessage *msg) const override
 

Protected Member Functions

std::string formatARPPacket (ARPPacket *packet) const
 
std::string formatICMPPacket (ICMPMessage *packet) const
 
std::string formatIeee80211Frame (ieee80211::Ieee80211Frame *packet) const
 
std::string formatPingPayload (PingPayload *packet) const
 
std::string formatRIPPacket (RIPPacket *packet) const
 
std::string formatRadioFrame (RadioFrame *packet) const
 
std::string formatTCPPacket (tcp::TCPSegment *tcpSeg) const
 
std::string formatUDPPacket (UDPPacket *udpPacket) const
 

Protected Attributes

bool showEncapsulatedPackets
 
L3Address srcAddr
 
L3Address destAddr
 

Constructor & Destructor Documentation

inet::InetPacketPrinter2::InetPacketPrinter2 ( )
inline
100 { showEncapsulatedPackets = true; }
bool showEncapsulatedPackets
Definition: InetPacketPrinter2.cc:85
virtual inet::InetPacketPrinter2::~InetPacketPrinter2 ( )
inlinevirtual
101 {}

Member Function Documentation

std::string inet::InetPacketPrinter2::formatARPPacket ( ARPPacket packet) const
protected
195 {
196  std::ostringstream os;
197 #ifdef WITH_IPv4
198  switch (packet->getOpcode()) {
199  case ARP_REQUEST:
200  os << "ARP req: " << packet->getDestIPAddress()
201  << "=? (s=" << packet->getSrcIPAddress() << "(" << packet->getSrcMACAddress() << "))";
202  break;
203 
204  case ARP_REPLY:
205  os << "ARP reply: "
206  << packet->getSrcIPAddress() << "=" << packet->getSrcMACAddress()
207  << " (d=" << packet->getDestIPAddress() << "(" << packet->getDestMACAddress() << "))"
208  ;
209  break;
210 
211  case ARP_RARP_REQUEST:
212  os << "RARP req: " << packet->getDestMACAddress()
213  << "=? (s=" << packet->getSrcIPAddress() << "(" << packet->getSrcMACAddress() << "))";
214  break;
215 
216  case ARP_RARP_REPLY:
217  os << "RARP reply: "
218  << packet->getSrcMACAddress() << "=" << packet->getSrcIPAddress()
219  << " (d=" << packet->getDestIPAddress() << "(" << packet->getDestMACAddress() << "))";
220  break;
221 
222  default:
223  os << "ARP op=" << packet->getOpcode() << ": d=" << packet->getDestIPAddress()
224  << "(" << packet->getDestMACAddress()
225  << ") s=" << packet->getSrcIPAddress()
226  << "(" << packet->getSrcMACAddress() << ")";
227  break;
228  }
229 #endif // ifdef WITH_IPv4
230  return os.str();
231 }
Definition: ARPPacket_m.h:62
Definition: ARPPacket_m.h:61
Definition: ARPPacket_m.h:60
Definition: ARPPacket_m.h:63
std::string inet::InetPacketPrinter2::formatICMPPacket ( ICMPMessage packet) const
protected
434 {
435  std::ostringstream os;
436 #ifdef WITH_IPv4
437  switch (packet->getType()) {
438  case ICMP_ECHO_REQUEST:
439  os << "ICMP echo request " << srcAddr << " to " << destAddr;
440  break;
441 
442  case ICMP_ECHO_REPLY:
443  os << "ICMP echo reply " << srcAddr << " to " << destAddr;
444  break;
445 
447  os << "ICMP dest unreachable " << srcAddr << " to " << destAddr << " type=" << packet->getType() << " code=" << packet->getCode()
448  << " origin:" << INFO_SEPAR;
449  InetPacketPrinter2().printMessage(os, packet->getEncapsulatedPacket());
450  showEncapsulatedPackets = false; // stop printing
451  break;
452 
453  default:
454  os << "ICMP " << srcAddr << " to " << destAddr << " type=" << packet->getType() << " code=" << packet->getCode();
455  break;
456  }
457 #endif // ifdef WITH_IPv4
458  return os.str();
459 }
AddressType getType() const
Definition: L3Address.cc:52
Definition: ICMPMessage_m.h:69
Definition: ICMPMessage_m.h:66
InetPacketPrinter2()
Definition: InetPacketPrinter2.cc:100
Definition: ICMPMessage_m.h:74
L3Address destAddr
Definition: InetPacketPrinter2.cc:87
L3Address srcAddr
Definition: InetPacketPrinter2.cc:86
bool showEncapsulatedPackets
Definition: InetPacketPrinter2.cc:85
std::string inet::InetPacketPrinter2::formatIeee80211Frame ( ieee80211::Ieee80211Frame packet) const
protected
234 {
235  using namespace ieee80211;
236 
237  std::ostringstream os;
238 #ifdef WITH_IEEE80211
239  os << "WLAN ";
240  switch (packet->getType()) {
242  os << " assoc req"; //TODO
243  break;
244 
246  os << " assoc resp"; //TODO
247  break;
248 
250  os << " reassoc req"; //TODO
251  break;
252 
254  os << " reassoc resp"; //TODO
255  break;
256 
257  case ST_PROBEREQUEST:
258  os << " probe request"; //TODO
259  break;
260 
261  case ST_PROBERESPONSE:
262  os << " probe response"; //TODO
263  break;
264 
265  case ST_BEACON:
266  os << "beacon"; //TODO
267  break;
268 
269  case ST_ATIM:
270  os << " atim"; //TODO
271  break;
272 
273  case ST_DISASSOCIATION:
274  os << " disassoc"; //TODO
275  break;
276 
277  case ST_AUTHENTICATION:
278  os << " auth"; //TODO
279  break;
280 
281  case ST_DEAUTHENTICATION:
282  os << " deauth"; //TODO
283  break;
284 
285  case ST_ACTION:
286  os << " action"; //TODO
287  break;
288 
289  case ST_NOACKACTION:
290  os << " noackaction"; //TODO
291  break;
292 
293  case ST_PSPOLL:
294  os << " pspoll"; //TODO
295  break;
296 
297  case ST_RTS: {
298  Ieee80211RTSFrame *pk = check_and_cast<Ieee80211RTSFrame *>(packet);
299  os << " rts " << pk->getTransmitterAddress() << " to " << packet->getReceiverAddress();
300  break;
301  }
302 
303  case ST_CTS:
304  os << " cts " << packet->getReceiverAddress();
305  break;
306 
307  case ST_ACK:
308  os << " ack " << packet->getReceiverAddress();
309  break;
310 
311  case ST_BLOCKACK_REQ:
312  os << " reassoc resp"; //TODO
313  break;
314 
315  case ST_BLOCKACK:
316  os << " block ack"; //TODO
317  break;
318 
319  case ST_DATA:
320  case ST_DATA_WITH_QOS:
321  os << " data"; //TODO
322  break;
323 
324  case ST_LBMS_REQUEST:
325  os << " lbms req"; //TODO
326  break;
327 
328  case ST_LBMS_REPORT:
329  os << " lbms report"; //TODO
330  break;
331 
332  default:
333  os << "??? (" << packet->getClassName() << ")";
334  break;
335  }
336 #endif // ifdef WITH_IEEE80211
337  return os.str();
338 }
Definition: Ieee80211Frame_m.h:114
Definition: Ieee80211Frame_m.h:104
Definition: Ieee80211Frame_m.h:99
Definition: Ieee80211Frame_m.h:100
Definition: Ieee80211Frame_m.h:109
Definition: Ieee80211Frame_m.h:106
Definition: Ieee80211Frame_m.h:117
Definition: Ieee80211Frame_m.h:98
Definition: Ieee80211Frame_m.h:113
Definition: Ieee80211Frame_m.h:101
Definition: Ieee80211Frame_m.h:103
Definition: Ieee80211Frame_m.h:110
Definition: Ieee80211Frame_m.h:112
Definition: Ieee80211Frame_m.h:108
Definition: Ieee80211Frame_m.h:115
Definition: Ieee80211Frame_m.h:102
Definition: Ieee80211Frame_m.h:118
Definition: Ieee80211Frame_m.h:111
Definition: Ieee80211Frame_m.h:116
Definition: Ieee80211Frame_m.h:119
Definition: Ieee80211Frame_m.h:97
Definition: Ieee80211Frame_m.h:107
Definition: Ieee80211Frame_m.h:105
std::string inet::InetPacketPrinter2::formatPingPayload ( PingPayload packet) const
protected
406 {
407  std::ostringstream os;
408  os << "PING ";
409 #ifdef WITH_IPv4
410  ICMPMessage *owner = dynamic_cast<ICMPMessage *>(packet->getOwner());
411  if (owner) {
412  switch (owner->getType()) {
413  case ICMP_ECHO_REQUEST:
414  os << "req ";
415  break;
416 
417  case ICMP_ECHO_REPLY:
418  os << "reply ";
419  break;
420 
421  default:
422  break;
423  }
424  }
425 #endif // ifdef WITH_IPv4
426  os << srcAddr << " to " << destAddr
427  << " (" << packet->getByteLength() << " bytes) id=" << packet->getId()
428  << " seq=" << packet->getSeqNo();
429 
430  return os.str();
431 }
Definition: ICMPMessage_m.h:69
std::string str() const
Definition: L3Address.cc:86
Definition: ICMPMessage_m.h:74
L3Address destAddr
Definition: InetPacketPrinter2.cc:87
L3Address srcAddr
Definition: InetPacketPrinter2.cc:86
std::string inet::InetPacketPrinter2::formatRadioFrame ( RadioFrame packet) const
protected
501 {
502  std::ostringstream os;
503 #ifdef WITH_RADIO
504  // Note: Do NOT try to print transmission's properties here! getTransmission() will likely
505  // return an invalid pointer here, because the transmission is no longer kept in the Medium.
506  // const ITransmission *transmission = packet->getTransmission();
507  os << "duration=" << SIMTIME_DBL(packet->getDuration()) * 1000 << "ms";
508 #endif // ifdef WITH_RADIO
509  return os.str();
510 }
std::string inet::InetPacketPrinter2::formatRIPPacket ( RIPPacket packet) const
protected
462 {
463  std::ostringstream os;
464 #ifdef WITH_RIP
465  os << "RIP: ";
466  switch (packet->getCommand()) {
467  case RIP_REQUEST:
468  os << "req ";
469  break;
470 
471  case RIP_RESPONSE:
472  os << "resp ";
473  break;
474 
475  default:
476  os << "unknown ";
477  break;
478  }
479  unsigned int size = packet->getEntryArraySize();
480  for (unsigned int i = 0; i < size; ++i) {
481  RIPEntry& entry = packet->getEntry(i);
482  if (i > 0)
483  os << "; ";
484  if (i > 2) {
485  os << "...(" << size << " entries)";
486  break;
487  }
488  os << entry.address << "/" << entry.prefixLength;
489  if (!entry.nextHop.isUnspecified())
490  os << "->" << entry.nextHop;
491  if (entry.metric == 16)
492  os << " unroutable";
493  else
494  os << " m=" << entry.metric;
495  }
496 #endif // ifdef WITH_RIP
497  return os.str();
498 }
Definition: RIPPacket_m.h:58
Definition: RIPPacket_m.h:57
if(!(yy_init))
Definition: lexer.cc:1644
std::string inet::InetPacketPrinter2::formatTCPPacket ( tcp::TCPSegment tcpSeg) const
protected
341 {
342  std::ostringstream os;
343 #ifdef WITH_TCP_COMMON
344  os << "TCP: " << srcAddr << '.' << tcpSeg->getSrcPort() << " > " << destAddr << '.' << tcpSeg->getDestPort() << ":";
345  // flags
346  bool flags = false;
347  if (tcpSeg->getUrgBit()) {
348  flags = true;
349  os << " U";
350  }
351  if (tcpSeg->getAckBit()) {
352  flags = true;
353  os << " A";
354  }
355  if (tcpSeg->getPshBit()) {
356  flags = true;
357  os << " P";
358  }
359  if (tcpSeg->getRstBit()) {
360  flags = true;
361  os << " R";
362  }
363  if (tcpSeg->getSynBit()) {
364  flags = true;
365  os << " S";
366  }
367  if (tcpSeg->getFinBit()) {
368  flags = true;
369  os << " F";
370  }
371  if (!flags) {
372  os << " .";
373  }
374 
375  // data-seqno
376  if (tcpSeg->getPayloadLength() > 0 || tcpSeg->getSynBit()) {
377  os << " " << tcpSeg->getSequenceNo() << ":" << tcpSeg->getSequenceNo() + tcpSeg->getPayloadLength();
378  os << "(" << tcpSeg->getPayloadLength() << ")";
379  }
380 
381  // ack
382  if (tcpSeg->getAckBit())
383  os << " ack " << tcpSeg->getAckNo();
384 
385  // window
386  os << " win " << tcpSeg->getWindow();
387 
388  // urgent
389  if (tcpSeg->getUrgBit())
390  os << " urg " << tcpSeg->getUrgentPointer();
391 #endif // ifdef WITH_TCP_COMMON
392  return os.str();
393 }
std::string str() const
Definition: L3Address.cc:86
L3Address destAddr
Definition: InetPacketPrinter2.cc:87
L3Address srcAddr
Definition: InetPacketPrinter2.cc:86
std::string inet::InetPacketPrinter2::formatUDPPacket ( UDPPacket udpPacket) const
protected
396 {
397  std::ostringstream os;
398 #ifdef WITH_UDP
399  os << "UDP: " << srcAddr << '.' << udpPacket->getSourcePort() << " > " << destAddr << '.' << udpPacket->getDestinationPort()
400  << ": (" << udpPacket->getByteLength() << ")";
401 #endif // ifdef WITH_UDP
402  return os.str();
403 }
std::string str() const
Definition: L3Address.cc:86
L3Address destAddr
Definition: InetPacketPrinter2.cc:87
L3Address srcAddr
Definition: InetPacketPrinter2.cc:86
int inet::InetPacketPrinter2::getScoreFor ( cMessage *  msg) const
overridevirtual
112 {
113  return msg->isPacket() ? 21 : 0;
114 }
void inet::InetPacketPrinter2::printMessage ( std::ostream &  os,
cMessage *  msg 
) const
overridevirtual

Referenced by formatICMPPacket().

117 {
118  std::string outs;
119 
120  //reset mutable variables
121  srcAddr = destAddr = L3Address();
123 
124  for (cPacket *pk = dynamic_cast<cPacket *>(msg); showEncapsulatedPackets && pk; pk = pk->getEncapsulatedPacket()) {
125  std::ostringstream out;
126  INetworkDatagram *dgram = dynamic_cast<INetworkDatagram *>(pk);
127  if (dgram) {
128  srcAddr = dgram->getSourceAddress();
129  destAddr = dgram->getDestinationAddress();
130 #ifdef WITH_IPv4
131  if (dynamic_cast<IPv4Datagram *>(pk)) {
132  IPv4Datagram *ipv4dgram = static_cast<IPv4Datagram *>(pk);
133  out << "IPv4: " << srcAddr << " > " << destAddr;
134  if (ipv4dgram->getMoreFragments() || ipv4dgram->getFragmentOffset() > 0) {
135  out << " " << (ipv4dgram->getMoreFragments() ? "" : "last ")
136  << "fragment with offset=" << ipv4dgram->getFragmentOffset() << " of ";
137  }
138  }
139  else
140 #endif // ifdef WITH_IPv4
141  out << pk->getClassName() << ": " << srcAddr << " > " << destAddr;
142  }
143 #ifdef WITH_ETHERNET
144  else if (dynamic_cast<EtherFrame *>(pk)) {
145  EtherFrame *eth = static_cast<EtherFrame *>(pk);
146  out << "ETH: " << eth->getSrc() << " > " << eth->getDest() << " (" << eth->getByteLength() << " bytes)";
147  }
148 #endif // ifdef WITH_ETHERNET
149 #ifdef WITH_TCP_COMMON
150  else if (dynamic_cast<tcp::TCPSegment *>(pk)) {
151  out << formatTCPPacket(static_cast<tcp::TCPSegment *>(pk));
152  }
153 #endif // ifdef WITH_TCP_COMMON
154 #ifdef WITH_UDP
155  else if (dynamic_cast<UDPPacket *>(pk)) {
156  out << formatUDPPacket(static_cast<UDPPacket *>(pk));
157  }
158 #endif // ifdef WITH_UDP
159 #ifdef WITH_IPv4
160  else if (dynamic_cast<ICMPMessage *>(pk)) {
161  out << formatICMPPacket(static_cast<ICMPMessage *>(pk));
162  }
163  else if (dynamic_cast<ARPPacket *>(pk)) {
164  out << formatARPPacket(static_cast<ARPPacket *>(pk));
165  }
166 #endif // ifdef WITH_IPv4
167 #ifdef WITH_IEEE80211
168  else if (dynamic_cast<ieee80211::Ieee80211Frame *>(pk)) {
169  out << formatIeee80211Frame(static_cast<ieee80211::Ieee80211Frame *>(pk));
170  }
171 #endif // ifdef WITH_IEEE80211
172  else if (dynamic_cast<PingPayload *>(pk)) {
173  out << formatPingPayload(static_cast<PingPayload *>(pk));
174  }
175 #ifdef WITH_RIP
176  else if (dynamic_cast<RIPPacket *>(pk)) {
177  out << formatRIPPacket(static_cast<RIPPacket *>(pk));
178  }
179 #endif // ifdef WITH_RIP
180 #ifdef WITH_RADIO
181  else if (dynamic_cast<RadioFrame *>(pk)) {
182  out << formatRadioFrame(static_cast<RadioFrame *>(pk));
183  }
184 #endif // ifdef WITH_RADIO
185  else
186  out << pk->getClassName() << ":" << pk->getByteLength() << " bytes";
187  if (outs.length())
188  out << INFO_SEPAR << outs;
189  outs = out.str();
190  }
191  os << outs;
192 }
L3Address destAddr
Definition: InetPacketPrinter2.cc:87
L3Address srcAddr
Definition: InetPacketPrinter2.cc:86
bool showEncapsulatedPackets
Definition: InetPacketPrinter2.cc:85

Member Data Documentation

L3Address inet::InetPacketPrinter2::destAddr
mutableprotected
bool inet::InetPacketPrinter2::showEncapsulatedPackets
mutableprotected
L3Address inet::InetPacketPrinter2::srcAddr
mutableprotected

The documentation for this class was generated from the following file: