|
INET Framework for OMNeT++/OMNEST
|
#include <PacketPrinter.h>
|
| virtual int | getScoreFor (cMessage *msg) const override |
| |
| virtual std::set< std::string > | getSupportedTags () const override |
| |
| virtual std::set< std::string > | getDefaultEnabledTags () const override |
| |
| virtual std::vector< std::string > | getColumnNames (const Options *options) const override |
| |
| virtual void | printMessage (std::ostream &stream, cMessage *message) const |
| |
| virtual void | printMessage (std::ostream &stream, cMessage *message, const Options *options) const override |
| |
| virtual void | printPacket (std::ostream &stream, Packet *packet, const char *format=nullptr) const |
| |
| virtual void | printPacket (std::ostream &stream, Packet *packet, const Options *options, const char *format=nullptr) const |
| |
| virtual std::string | printPacketToString (Packet *packet, const char *format=nullptr) const |
| |
| virtual std::string | printPacketToString (Packet *packet, const Options *options, const char *format=nullptr) const |
| |
|
| virtual bool | isEnabledOption (const Options *options, const char *name) const |
| |
| virtual bool | isEnabledInfo (const Options *options, const Protocol *protocol) const |
| |
| virtual const ProtocolPrinter & | getProtocolPrinter (const Protocol *protocol) const |
| |
| virtual void | printContext (std::ostream &stream, const Options *options, Context &context) const |
| |
| virtual void | printPacket (Packet *packet, const Options *options, Context &context) const |
| |
| virtual void | printPacketInsideOut (const Ptr< const PacketDissector::ProtocolDataUnit > &protocolDataUnit, const Options *options, Context &context) const |
| |
| virtual void | printPacketLeftToRight (const Ptr< const PacketDissector::ProtocolDataUnit > &protocolDataUnit, const Options *options, Context &context) const |
| |
| virtual void | printSourceColumn (const std::string source, const Protocol *protocol, const Options *options, Context &context) const |
| |
| virtual void | printDestinationColumn (const std::string destination, const Protocol *protocol, const Options *options, Context &context) const |
| |
| virtual void | printProtocolColumn (const Protocol *protocol, const Options *options, Context &context) const |
| |
| virtual void | printLengthColumn (const Ptr< const PacketDissector::ProtocolDataUnit > &protocolDataUnit, const Options *options, Context &context) const |
| |
◆ getColumnNames()
| std::vector< std::string > inet::PacketPrinter::getColumnNames |
( |
const Options * |
options | ) |
const |
|
overridevirtual |
101 std::vector<std::string> columnNames;
103 columnNames.push_back(
"Source");
105 columnNames.push_back(
"Destination");
107 columnNames.push_back(
"Protocol");
109 columnNames.push_back(
"Type");
111 columnNames.push_back(
"Length");
113 columnNames.push_back(
"Info");
◆ getDefaultEnabledTags()
| std::set< std::string > inet::PacketPrinter::getDefaultEnabledTags |
( |
| ) |
const |
|
overridevirtual |
94 return {
"Print inside out",
95 "Show 'Source' column",
"Show 'Destination' column",
"Show 'Protocol' column",
"Show 'Type' column",
"Show 'Length' column",
"Show 'Info' column",
96 "Show auto source fields",
"Show auto destination fields",
"Show auto info" };
Referenced by printMessage(), and printPacket().
◆ getProtocolPrinter()
◆ getScoreFor()
| int inet::PacketPrinter::getScoreFor |
( |
cMessage * |
msg | ) |
const |
|
overridevirtual |
51 return msg->isPacket() ? 100 : 0;
◆ getSupportedTags()
| std::set< std::string > inet::PacketPrinter::getSupportedTags |
( |
| ) |
const |
|
overridevirtual |
85 return {
"Print inside out",
"Print left to right",
86 "Show 'Source' column",
"Show 'Destination' column",
"Show 'Protocol' column",
"Show 'Type' column",
"Show 'Length' column",
"Show 'Info' column",
87 "Show all PDU source fields",
"Show all PDU destination fields",
"Show all PDU protocols",
"Show all PDU lengths",
88 "Show physical layer info",
"Show link layer info",
"Show network layer info",
"Show transport layer info",
"Show all info",
"Show innermost info",
89 "Show auto source fields",
"Show auto destination fields",
"Show auto info" };
◆ isEnabledInfo()
| bool inet::PacketPrinter::isEnabledInfo |
( |
const Options * |
options, |
|
|
const Protocol * |
protocol |
|
) |
| const |
|
protectedvirtual |
◆ isEnabledOption()
| bool inet::PacketPrinter::isEnabledOption |
( |
const Options * |
options, |
|
|
const char * |
name |
|
) |
| const |
|
protectedvirtual |
◆ printContext()
| void inet::PacketPrinter::printContext |
( |
std::ostream & |
stream, |
|
|
const Options * |
options, |
|
|
Context & |
context |
|
) |
| const |
|
protectedvirtual |
119 if (!context.isCorrect)
120 stream <<
"\x1b[103m";
121 stream <<
"\x1b[30m";
123 stream << context.sourceColumn.str() <<
"\t";
125 stream << context.destinationColumn.str() <<
"\t";
127 stream <<
"\x1b[34m" << context.protocolColumn.str() <<
"\x1b[30m\t";
129 stream <<
"\x1b[34m" << context.typeColumn.str() <<
"\x1b[30m\t";
131 stream << context.lengthColumn.str() <<
"\t";
133 stream << context.infoColumn.str();
Referenced by printMessage(), and printPacket().
◆ printDestinationColumn()
| void inet::PacketPrinter::printDestinationColumn |
( |
const std::string |
destination, |
|
|
const Protocol * |
protocol, |
|
|
const Options * |
options, |
|
|
Context & |
context |
|
) |
| const |
|
protectedvirtual |
324 if (destination.length() != 0) {
325 bool concatenate =
isEnabledOption(options,
"Show all PDU destination fields") ||
328 context.destinationColumn.str(
"");
329 else if (context.destinationColumn.str().length() != 0)
330 context.destinationColumn <<
":";
331 context.destinationColumn << destination;
Referenced by printPacketInsideOut(), and printPacketLeftToRight().
◆ printLengthColumn()
348 auto lengthColumnLength = context.lengthColumn.str().length();
349 if (lengthColumnLength == 0 ||
isEnabledOption(options,
"Show all PDU lengths")) {
350 if (lengthColumnLength != 0)
351 context.lengthColumn <<
", ";
352 context.lengthColumn << protocolDataUnit->getChunkLength();
Referenced by printPacketInsideOut(), and printPacketLeftToRight().
◆ printMessage() [1/2]
| void inet::PacketPrinter::printMessage |
( |
std::ostream & |
stream, |
|
|
cMessage * |
message |
|
) |
| const |
|
virtual |
◆ printMessage() [2/2]
| void inet::PacketPrinter::printMessage |
( |
std::ostream & |
stream, |
|
|
cMessage * |
message, |
|
|
const Options * |
options |
|
) |
| const |
|
overridevirtual |
147 for (
auto cpacket =
dynamic_cast<cPacket *
>(message); cpacket !=
nullptr; cpacket = cpacket->getEncapsulatedPacket()) {
149 #ifdef INET_WITH_PHYSICALLAYERWIRELESSCOMMON
150 else if (
auto signal =
dynamic_cast<physicallayer::Signal *
>(cpacket))
151 printSignal(signal, options, context);
152 #endif // INET_WITH_PHYSICALLAYERWIRELESSCOMMON
153 else if (
auto packet =
dynamic_cast<Packet *
>(cpacket))
156 context.infoColumn << cpacket->str();
◆ printPacket() [1/3]
| void inet::PacketPrinter::printPacket |
( |
Packet * |
packet, |
|
|
const Options * |
options, |
|
|
Context & |
context |
|
) |
| const |
|
protectedvirtual |
205 PacketDissector::PduTreeBuilder pduTreeBuilder;
208 packetDissector.dissectPacket(packet);
210 catch (cRuntimeError&
e) {
212 context.infoColumn <<
e.what() <<
": ";
214 const auto& protocolDataUnit = pduTreeBuilder.getTopLevelPdu();
215 if (protocolDataUnit !=
nullptr) {
216 if (pduTreeBuilder.isSimplyEncapsulatedPacket() &&
isEnabledOption(options,
"Print inside out"))
Referenced by printMessage(), printPacket(), and printPacketToString().
◆ printPacket() [2/3]
| void inet::PacketPrinter::printPacket |
( |
std::ostream & |
stream, |
|
|
Packet * |
packet, |
|
|
const char * |
format = nullptr |
|
) |
| const |
|
virtual |
◆ printPacket() [3/3]
| void inet::PacketPrinter::printPacket |
( |
std::ostream & |
stream, |
|
|
Packet * |
packet, |
|
|
const Options * |
options, |
|
|
const char * |
format = nullptr |
|
) |
| const |
|
virtual |
193 if (format ==
nullptr)
196 DirectiveResolver directiveResolver(context,
numPacket++);
197 StringFormat stringFormat;
198 stringFormat.parseFormat(format);
199 stream << stringFormat.formatString(&directiveResolver);
◆ printPacketInsideOut()
239 auto protocol = protocolDataUnit->getProtocol();
240 context.isCorrect &= protocolDataUnit->isCorrect();
242 for (
const auto& chunk : protocolDataUnit->getChunks()) {
243 if (
auto childLevel = dynamicPtrCast<const PacketDissector::ProtocolDataUnit>(chunk))
247 ProtocolPrinter::Context protocolContext;
248 protocolPrinter.print(chunk,
protocol, options, protocolContext);
249 if (protocolDataUnit->getLevel() > context.infoLevel) {
250 context.infoLevel = protocolDataUnit->getLevel();
256 bool showInnermostInfo =
isEnabledOption(options,
"Show innermost info");
258 if (showInnermostInfo && !(showAutoInfo &&
protocol ==
nullptr)) {
259 context.typeColumn.str(
"");
260 context.infoColumn.str(
"");
262 if (protocolContext.typeColumn.str().length() != 0) {
263 if (context.typeColumn.str().length() != 0)
264 protocolContext.typeColumn <<
" | ";
265 context.typeColumn.str(protocolContext.typeColumn.str() + context.typeColumn.str());
267 if (protocolContext.infoColumn.str().length() != 0) {
268 if (context.infoColumn.str().length() != 0)
269 protocolContext.infoColumn <<
" | ";
270 context.infoColumn.str(protocolContext.infoColumn.str() + context.infoColumn.str());
Referenced by printPacket().
◆ printPacketLeftToRight()
280 auto protocol = protocolDataUnit->getProtocol();
281 context.isCorrect &= protocolDataUnit->isCorrect();
283 for (
const auto& chunk : protocolDataUnit->getChunks()) {
284 if (
auto childLevel = dynamicPtrCast<const PacketDissector::ProtocolDataUnit>(chunk))
288 ProtocolPrinter::Context protocolContext;
289 protocolPrinter.print(chunk,
protocol, options, protocolContext);
290 if (protocolDataUnit->getLevel() > context.infoLevel) {
291 context.infoLevel = protocolDataUnit->getLevel();
298 if (context.typeColumn.str().length() != 0)
299 context.typeColumn <<
" | ";
300 context.typeColumn << protocolContext.typeColumn.str();
301 if (context.infoColumn.str().length() != 0)
302 context.infoColumn <<
" | ";
303 context.infoColumn << protocolContext.infoColumn.str();
Referenced by printPacket().
◆ printPacketToString() [1/2]
| std::string inet::PacketPrinter::printPacketToString |
( |
Packet * |
packet, |
|
|
const char * |
format = nullptr |
|
) |
| const |
|
virtual |
◆ printPacketToString() [2/2]
| std::string inet::PacketPrinter::printPacketToString |
( |
Packet * |
packet, |
|
|
const Options * |
options, |
|
|
const char * |
format = nullptr |
|
) |
| const |
|
virtual |
232 std::stringstream stream;
◆ printProtocolColumn()
| void inet::PacketPrinter::printProtocolColumn |
( |
const Protocol * |
protocol, |
|
|
const Options * |
options, |
|
|
Context & |
context |
|
) |
| const |
|
protectedvirtual |
◆ printSourceColumn()
| void inet::PacketPrinter::printSourceColumn |
( |
const std::string |
source, |
|
|
const Protocol * |
protocol, |
|
|
const Options * |
options, |
|
|
Context & |
context |
|
) |
| const |
|
protectedvirtual |
311 if (source.length() != 0) {
312 bool concatenate =
isEnabledOption(options,
"Show all PDU source fields") ||
315 context.sourceColumn.str(
"");
316 else if (context.sourceColumn.str().length() != 0)
317 context.sourceColumn <<
":";
318 context.sourceColumn << source;
Referenced by printPacketInsideOut(), and printPacketLeftToRight().
◆ numPacket
| int inet::PacketPrinter::numPacket = 0 |
|
mutableprotected |
The documentation for this class was generated from the following files:
virtual const ProtocolPrinter & getProtocolPrinter(const Protocol *protocol) const
Definition: PacketPrinter.cc:75
removed DscpReq Ipv4ControlInfo Ipv6ControlInfo up L3AddressInd DispatchProtocolReq L4PortInd Ipv4ControlInfo Ipv6ControlInfo down protocol
Definition: IUdp-gates.txt:25
virtual bool isEnabledOption(const Options *options, const char *name) const
Definition: PacketPrinter.cc:54
const value< double, units::C > e(1.602176487e-19)
virtual void printPacketLeftToRight(const Ptr< const PacketDissector::ProtocolDataUnit > &protocolDataUnit, const Options *options, Context &context) const
Definition: PacketPrinter.cc:278
@ LinkLayer
Definition: Protocol.h:23
int numPacket
Definition: PacketPrinter.h:48
virtual void printPacketInsideOut(const Ptr< const PacketDissector::ProtocolDataUnit > &protocolDataUnit, const Options *options, Context &context) const
Definition: PacketPrinter.cc:237
virtual void printProtocolColumn(const Protocol *protocol, const Options *options, Context &context) const
Definition: PacketPrinter.cc:335
bool contains(const std::vector< T > &v, const Tk &a)
Definition: stlutils.h:65
virtual bool isEnabledInfo(const Options *options, const Protocol *protocol) const
Definition: PacketPrinter.cc:59
virtual std::set< std::string > getDefaultEnabledTags() const override
Definition: PacketPrinter.cc:92
@ TransportLayer
Definition: Protocol.h:23
static ProtocolPrinterRegistry globalRegistry
Definition: ProtocolPrinterRegistry.h:21
@ PhysicalLayer
Definition: Protocol.h:23
@ NetworkLayer
Definition: Protocol.h:23
const ProtocolPrinter * findProtocolPrinter(const Protocol *protocol) const
Definition: ProtocolPrinterRegistry.cc:25
virtual void printPacket(Packet *packet, const Options *options, Context &context) const
Definition: PacketPrinter.cc:203
virtual void printContext(std::ostream &stream, const Options *options, Context &context) const
Definition: PacketPrinter.cc:117
virtual void printDestinationColumn(const std::string destination, const Protocol *protocol, const Options *options, Context &context) const
Definition: PacketPrinter.cc:322
static ProtocolDissectorRegistry globalRegistry
Definition: ProtocolDissectorRegistry.h:21
virtual void printSourceColumn(const std::string source, const Protocol *protocol, const Options *options, Context &context) const
Definition: PacketPrinter.cc:309
virtual void printMessage(std::ostream &stream, cMessage *message) const
Definition: PacketPrinter.cc:137
virtual void printLengthColumn(const Ptr< const PacketDissector::ProtocolDataUnit > &protocolDataUnit, const Options *options, Context &context) const
Definition: PacketPrinter.cc:346