|
INET Framework for OMNeT++/OMNEST
|
Dumps every packet using the IPacketWriter and PacketDump classes.
More...
#include <PcapRecorder.h>
Dumps every packet using the IPacketWriter and PacketDump classes.
◆ SignalList
◆ PcapRecorder()
| inet::PcapRecorder::PcapRecorder |
( |
| ) |
|
◆ ~PcapRecorder()
| inet::PcapRecorder::~PcapRecorder |
( |
| ) |
|
|
virtual |
◆ finish()
| void inet::PcapRecorder::finish |
( |
| ) |
|
|
overrideprotectedvirtual |
◆ handleMessage()
| void inet::PcapRecorder::handleMessage |
( |
cMessage * |
msg | ) |
|
|
overrideprotectedvirtual |
133 throw cRuntimeError(
"This module does not handle messages");
◆ initialize()
| void inet::PcapRecorder::initialize |
( |
| ) |
|
|
overrideprotectedvirtual |
51 cStringTokenizer signalTokenizer(par(
"sendingSignalNames"));
53 while (signalTokenizer.hasMoreTokens())
58 cStringTokenizer signalTokenizer(par(
"receivingSignalNames"));
60 while (signalTokenizer.hasMoreTokens())
65 cStringTokenizer protocolTokenizer(par(
"dumpProtocols"));
67 while (protocolTokenizer.hasMoreTokens())
72 cStringTokenizer protocolTokenizer(par(
"helpers"));
74 while (protocolTokenizer.hasMoreTokens())
75 helpers.push_back(check_and_cast<IHelper *>(
createOne(protocolTokenizer.nextToken())));
78 const char *moduleNames = par(
"moduleNamePatterns");
79 cStringTokenizer moduleTokenizer(moduleNames);
81 while (moduleTokenizer.hasMoreTokens()) {
83 std::string mname(moduleTokenizer.nextToken());
84 bool isAllIndex = (mname.length() > 3) && mname.rfind(
"[*]") == mname.length() - 3;
87 mname.replace(mname.length() - 3, 3,
"");
89 if (mname[0] ==
'.') {
91 getParentModule()->subscribe(elem.first,
this);
95 for (cModule::SubmoduleIterator i(getParentModule()); !i.end(); i++) {
97 if (0 == strcmp(isAllIndex ? submod->getName() : submod->getFullName(), mname.c_str())) {
101 if (!submod->isSubscribed(elem.first,
this)) {
102 submod->subscribe(elem.first,
this);
103 EV_INFO <<
"Subscribing to " << submod->getFullPath() <<
":" << getSignalName(elem.first) <<
EV_ENDL;
110 if (!found && !isAllIndex)
111 EV_INFO <<
"The module " << mname << (isAllIndex ?
"[*]" :
"") <<
" not found" <<
EV_ENDL;
114 const char *file = par(
"pcapFile");
115 const char *fileFormat = par(
"fileFormat");
116 if (!strcmp(fileFormat,
"pcap"))
118 else if (!strcmp(fileFormat,
"pcapng"))
121 throw cRuntimeError(
"Unknown fileFormat parameter");
◆ matchesLinkType()
| bool inet::PcapRecorder::matchesLinkType |
( |
PcapLinkType |
pcapLinkType, |
|
|
const Protocol * |
protocol |
|
) |
| const |
|
protectedvirtual |
◆ protocolToLinkType()
◆ receiveSignal()
| void inet::PcapRecorder::receiveSignal |
( |
cComponent * |
source, |
|
|
simsignal_t |
signalID, |
|
|
cObject * |
obj, |
|
|
cObject * |
details |
|
) |
| |
|
overrideprotectedvirtual |
164 Enter_Method(
"%s", cComponent::getSignalName(signalID));
167 cPacket *packet =
dynamic_cast<cPacket *
>(obj);
◆ recordPacket()
| void inet::PcapRecorder::recordPacket |
( |
const cPacket * |
msg, |
|
|
Direction |
direction, |
|
|
cComponent * |
source |
|
) |
| |
|
protectedvirtual |
179 if (
auto packet =
dynamic_cast<const Packet *
>(cpacket)) {
186 if (
auto directionTag = packet->findTag<DirectionTag>())
187 direction = directionTag->getDirection();
191 auto srcModule = check_and_cast<cModule *>(source);
193 if (networkInterface ==
nullptr) {
197 ifaceId = ifaceTag->getInterfaceId();
200 if (
auto ifaceTag = packet->findTag<InterfaceInd>())
201 ifaceId = ifaceTag->getInterfaceId();
204 auto ift = check_and_cast_nullable<InterfaceTable *>(
getContainingNode(srcModule)->getSubmodule(
"interfaceTable"));
205 networkInterface = ift->getInterfaceById(ifaceId);
210 auto protocol = packetProtocolTag->getProtocol();
214 throw cRuntimeError(
"Cannot determine the PCAP link type from protocol '%s'",
protocol->getName());
226 delete convertedPacket;
229 throw cRuntimeError(
"The protocol '%s' doesn't match PCAP link type %d",
protocol->getName(), pcapLinkType);
Referenced by receiveSignal().
◆ refreshDisplay()
| void inet::PcapRecorder::refreshDisplay |
( |
| ) |
const |
|
overrideprotectedvirtual |
◆ resolveDirective()
| const char * inet::PcapRecorder::resolveDirective |
( |
char |
directive | ) |
const |
|
overridevirtual |
◆ tryConvertToLinkType()
294 for (IHelper *helper :
helpers) {
295 if (
auto newPacket = helper->tryConvertToLinkType(packet, pcapLinkType,
protocol))
Referenced by recordPacket().
◆ updateDisplayString()
| void inet::PcapRecorder::updateDisplayString |
( |
| ) |
const |
|
protectedvirtual |
156 if (getEnvir()->isGUI()) {
158 getDisplayString().setTagArg(
"t", 0, text);
Referenced by refreshDisplay().
◆ dumpBadFrames
| bool inet::PcapRecorder::dumpBadFrames = false |
|
protected |
◆ dumpProtocols
| std::vector<const Protocol *> inet::PcapRecorder::dumpProtocols |
|
protected |
◆ helpers
| std::vector<IHelper *> inet::PcapRecorder::helpers |
|
protected |
◆ numRecorded
| int inet::PcapRecorder::numRecorded = 0 |
|
protected |
◆ packetFilter
◆ packetPrinter
◆ packetRecordedSignal
| simsignal_t inet::PcapRecorder::packetRecordedSignal = registerSignal("packetRecorded") |
|
staticprotected |
◆ pcapWriter
◆ recordPcap
| bool inet::PcapRecorder::recordPcap = false |
|
protected |
◆ signalList
◆ snaplen
| unsigned int inet::PcapRecorder::snaplen = 0 |
|
protected |
◆ verbose
| bool inet::PcapRecorder::verbose = false |
|
protected |
The documentation for this class was generated from the following files:
@ DIRECTION_INBOUND
Definition: DirectionTag_m.h:57
virtual Packet * tryConvertToLinkType(const Packet *packet, PcapLinkType pcapLinkType, const Protocol *protocol) const
Definition: PcapRecorder.cc:292
@ DIRECTION_OUTBOUND
Definition: DirectionTag_m.h:58
virtual void updateDisplayString() const
Definition: PcapRecorder.cc:154
@ LINKTYPE_ETHERNET_MPACKET
mPackets, as specified by IEEE 802.3br Figure 99-4, starting with the preamble and always ending with...
Definition: IPcapWriter.h:200
removed DscpReq Ipv4ControlInfo Ipv6ControlInfo up L3AddressInd DispatchProtocolReq L4PortInd Ipv4ControlInfo Ipv6ControlInfo down protocol
Definition: IUdp-gates.txt:25
NetworkInterface * findContainingNicModule(const cModule *from)
Find the nic module (inside the networkNode) containing the given module.
Definition: NetworkInterface.cc:679
void setExpression(const char *expression)
Definition: common/packet/PacketFilter.cc:39
virtual void writePacket(simtime_t time, const Packet *packet, Direction direction, NetworkInterface *ie, PcapLinkType linkType)=0
static const Protocol ipv4
Definition: Protocol.h:93
static const Protocol * getProtocol(int id)
Definition: Protocol.cc:50
static const Protocol ipv6
Definition: Protocol.h:94
@ LINKTYPE_IEEE802_11
IEEE 802.11 wireless LAN.
Definition: IPcapWriter.h:50
IPcapWriter * pcapWriter
Definition: PcapRecorder.h:43
cModule * getContainingNode(const cModule *from)
Find the node containing the given module.
Definition: ModuleAccess.cc:40
removed InterfaceReq
Definition: IUdp-gates.txt:11
virtual bool isOpen() const =0
@ LINKTYPE_IEEE802_15_4_NOFCS
IEEE 802.15.4 wireless Personal Area Network, without the FCS at the end of the frame.
Definition: IPcapWriter.h:142
@ LINKTYPE_INVALID
Definition: IPcapWriter.h:18
@ LINKTYPE_RAW
Raw IP.
Definition: IPcapWriter.h:46
bool recordPcap
Definition: PcapRecorder.h:49
cObject * createOne(const char *className, const char *defaultNamespace)
Like cObjectFactory::createOne(), except it starts searching for the class in the given namespace.
Definition: INETUtils.cc:147
@ LINKTYPE_IPV6
Raw IPv6; the packet begins with an IPv6 header.
Definition: IPcapWriter.h:140
removed DscpReq Ipv4ControlInfo Ipv6ControlInfo up L3AddressInd DispatchProtocolReq L4PortInd Ipv4ControlInfo Ipv6ControlInfo down PacketProtocolTag
Definition: IUdp-gates.txt:25
bool dumpBadFrames
Definition: PcapRecorder.h:45
static const Protocol ppp
Definition: Protocol.h:104
static const Protocol ieee802154
Definition: Protocol.h:83
bool matches(const cPacket *packet) const
Definition: common/packet/PacketFilter.cc:92
std::vector< const Protocol * > dumpProtocols
Definition: PcapRecorder.h:41
PacketFilter packetFilter
Definition: PcapRecorder.h:46
#define EV_FIELD(...)
Definition: INETDefs.h:112
@ LINKTYPE_PPP_WITH_DIR
PPP, as per RFC 1661 and RFC 1662, preceded with a one-byte pseudo-header with a zero value meaning "...
Definition: IPcapWriter.h:118
bool verbose
Definition: PcapRecorder.h:48
bool contains(const std::vector< T > &v, const Tk &a)
Definition: stlutils.h:65
virtual void open(const char *filename, unsigned int snaplen)=0
SignalList signalList
Definition: PcapRecorder.h:42
Direction
Enum generated from inet/common/DirectionTag.msg:13 by opp_msgtool.
Definition: DirectionTag_m.h:55
static const Protocol ethernetMac
Definition: Protocol.h:65
virtual std::string printPacketToString(Packet *packet, const char *format=nullptr) const
Definition: PacketPrinter.cc:223
PacketPrinter packetPrinter
Definition: PcapRecorder.h:51
int numRecorded
Definition: PcapRecorder.h:47
virtual bool matchesLinkType(PcapLinkType pcapLinkType, const Protocol *protocol) const
Definition: PcapRecorder.cc:241
std::vector< IHelper * > helpers
Definition: PcapRecorder.h:50
value< int64_t, units::b > b
Definition: Units.h:1241
@ DIRECTION_UNDEFINED
Definition: DirectionTag_m.h:56
virtual void setFlush(bool flush)=0
static const Protocol ethernetPhy
Definition: Protocol.h:66
#define Enter_Method(...)
Definition: SelfDoc.h:71
virtual PcapLinkType protocolToLinkType(const Protocol *protocol) const
Definition: PcapRecorder.cc:268
static const Protocol ieee80211Mac
Definition: Protocol.h:79
@ LINKTYPE_IPV4
Raw IPv4; the packet begins with an IPv4 header.
Definition: IPcapWriter.h:138
virtual void recordPacket(const cPacket *msg, Direction direction, cComponent *source)
Definition: PcapRecorder.cc:177
@ LINKTYPE_ETHERNET
IEEE 802.3 Ethernet.
Definition: IPcapWriter.h:22
#define EV_ENDL
Definition: INETDefs.h:114
static simsignal_t packetRecordedSignal
Definition: PcapRecorder.h:53
unsigned int snaplen
Definition: PcapRecorder.h:44
@ LINKTYPE_IEEE802_15_4
IEEE 802.15.4 wireless Personal Area Network.
Definition: IPcapWriter.h:106