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

Public Member Functions

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

Protected Member Functions

void printTCPPacket (std::ostream &os, L3Address srcAddr, L3Address destAddr, tcp::TCPSegment *tcpSeg) const
 
void printUDPPacket (std::ostream &os, L3Address srcAddr, L3Address destAddr, UDPPacket *udpPacket) const
 
void printICMPPacket (std::ostream &os, L3Address srcAddr, L3Address destAddr, ICMPMessage *packet) const
 

Constructor & Destructor Documentation

inet::InetPacketPrinter::InetPacketPrinter ( )
inline
56 {}
virtual inet::InetPacketPrinter::~InetPacketPrinter ( )
inlinevirtual
57 {}

Member Function Documentation

int inet::InetPacketPrinter::getScoreFor ( cMessage *  msg) const
overridevirtual
65 {
66  return msg->isPacket() ? 20 : 0;
67 }
void inet::InetPacketPrinter::printICMPPacket ( std::ostream &  os,
L3Address  srcAddr,
L3Address  destAddr,
ICMPMessage packet 
) const
protected
175 {
176 #ifdef WITH_IPv4
177  switch (packet->getType()) {
178  case ICMP_ECHO_REQUEST: {
179  PingPayload *payload = check_and_cast<PingPayload *>(packet->getEncapsulatedPacket());
180  os << "ping " << srcAddr << " to " << destAddr
181  << " (" << packet->getByteLength() << " bytes) id=" << payload->getId() << " seq=" << payload->getSeqNo();
182  break;
183  }
184 
185  case ICMP_ECHO_REPLY: {
186  PingPayload *payload = check_and_cast<PingPayload *>(packet->getEncapsulatedPacket());
187  os << "pong " << srcAddr << " to " << destAddr
188  << " (" << packet->getByteLength() << " bytes) id=" << payload->getId() << " seq=" << payload->getSeqNo();
189  break;
190  }
191 
193  os << "ICMP dest unreachable " << srcAddr << " to " << destAddr << " type=" << packet->getType() << " code=" << packet->getCode()
194  << " origin: ";
195  printMessage(os, packet->getEncapsulatedPacket());
196  break;
197 
198  default:
199  os << "ICMP " << srcAddr << " to " << destAddr << " type=" << packet->getType() << " code=" << packet->getCode();
200  break;
201  }
202 #else // ifdef WITH_IPv4
203  os << " ICMP: " << srcAddr << " > " << destAddr;
204 #endif // ifdef WITH_IPv4
205 }
Definition: ICMPMessage_m.h:69
Definition: ICMPMessage_m.h:66
virtual void printMessage(std::ostream &os, cMessage *msg) const override
Definition: InetPacketPrinter.cc:69
Definition: ICMPMessage_m.h:74
void inet::InetPacketPrinter::printMessage ( std::ostream &  os,
cMessage *  msg 
) const
overridevirtual
70 {
71  L3Address srcAddr, destAddr;
72 
73  for (cPacket *pk = dynamic_cast<cPacket *>(msg); pk; pk = pk->getEncapsulatedPacket()) {
74  INetworkDatagram *dgram = dynamic_cast<INetworkDatagram *>(pk);
75  if (dgram) {
76  srcAddr = dgram->getSourceAddress();
77  destAddr = dgram->getDestinationAddress();
78 #ifdef WITH_IPv4
79  if (dynamic_cast<IPv4Datagram *>(pk)) {
80  IPv4Datagram *ipv4dgram = static_cast<IPv4Datagram *>(pk);
81  if (ipv4dgram->getMoreFragments() || ipv4dgram->getFragmentOffset() > 0)
82  os << (ipv4dgram->getMoreFragments() ? "" : "last ")
83  << "fragment with offset=" << ipv4dgram->getFragmentOffset() << " of ";
84  }
85 #endif // ifdef WITH_IPv4
86  }
87 #ifdef WITH_TCP_COMMON
88  else if (dynamic_cast<tcp::TCPSegment *>(pk)) {
89  printTCPPacket(os, srcAddr, destAddr, static_cast<tcp::TCPSegment *>(pk));
90  return;
91  }
92 #endif // ifdef WITH_TCP_COMMON
93 #ifdef WITH_UDP
94  else if (dynamic_cast<UDPPacket *>(pk)) {
95  printUDPPacket(os, srcAddr, destAddr, static_cast<UDPPacket *>(pk));
96  return;
97  }
98 #endif // ifdef WITH_UDP
99 #ifdef WITH_IPv4
100  else if (dynamic_cast<ICMPMessage *>(pk)) {
101  printICMPPacket(os, srcAddr, destAddr, static_cast<ICMPMessage *>(pk));
102  return;
103  }
104 #endif // ifdef WITH_IPv4
105  }
106  os << "(" << msg->getClassName() << ")" << " id=" << msg->getId() << " kind=" << msg->getKind();
107 }
void printICMPPacket(std::ostream &os, L3Address srcAddr, L3Address destAddr, ICMPMessage *packet) const
Definition: InetPacketPrinter.cc:174
void printTCPPacket(std::ostream &os, L3Address srcAddr, L3Address destAddr, tcp::TCPSegment *tcpSeg) const
Definition: InetPacketPrinter.cc:109
void printUDPPacket(std::ostream &os, L3Address srcAddr, L3Address destAddr, UDPPacket *udpPacket) const
Definition: InetPacketPrinter.cc:164
void inet::InetPacketPrinter::printTCPPacket ( std::ostream &  os,
L3Address  srcAddr,
L3Address  destAddr,
tcp::TCPSegment tcpSeg 
) const
protected
110 {
111 #ifdef WITH_TCP_COMMON
112  os << " TCP: " << srcAddr << '.' << tcpSeg->getSrcPort() << " > " << destAddr << '.' << tcpSeg->getDestPort() << ": ";
113  // flags
114  bool flags = false;
115  if (tcpSeg->getUrgBit()) {
116  flags = true;
117  os << "U ";
118  }
119  if (tcpSeg->getAckBit()) {
120  flags = true;
121  os << "A ";
122  }
123  if (tcpSeg->getPshBit()) {
124  flags = true;
125  os << "P ";
126  }
127  if (tcpSeg->getRstBit()) {
128  flags = true;
129  os << "R ";
130  }
131  if (tcpSeg->getSynBit()) {
132  flags = true;
133  os << "S ";
134  }
135  if (tcpSeg->getFinBit()) {
136  flags = true;
137  os << "F ";
138  }
139  if (!flags) {
140  os << ". ";
141  }
142 
143  // data-seqno
144  if (tcpSeg->getPayloadLength() > 0 || tcpSeg->getSynBit()) {
145  os << tcpSeg->getSequenceNo() << ":" << tcpSeg->getSequenceNo() + tcpSeg->getPayloadLength();
146  os << "(" << tcpSeg->getPayloadLength() << ") ";
147  }
148 
149  // ack
150  if (tcpSeg->getAckBit())
151  os << "ack " << tcpSeg->getAckNo() << " ";
152 
153  // window
154  os << "win " << tcpSeg->getWindow() << " ";
155 
156  // urgent
157  if (tcpSeg->getUrgBit())
158  os << "urg " << tcpSeg->getUrgentPointer() << " ";
159 #else // ifdef WITH_TCP_COMMON
160  os << " TCP: " << srcAddr << ".? > " << destAddr << ".?";
161 #endif // ifdef WITH_TCP_COMMON
162 }
void inet::InetPacketPrinter::printUDPPacket ( std::ostream &  os,
L3Address  srcAddr,
L3Address  destAddr,
UDPPacket udpPacket 
) const
protected
165 {
166 #ifdef WITH_UDP
167  os << " UDP: " << srcAddr << '.' << udpPacket->getSourcePort() << " > " << destAddr << '.' << udpPacket->getDestinationPort()
168  << ": (" << udpPacket->getByteLength() << ")";
169 #else // ifdef WITH_UDP
170  os << " UDP: " << srcAddr << ".? > " << destAddr << ".?";
171 #endif // ifdef WITH_UDP
172 }

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