Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include <omnetpp.h>
00023 #include "ErrorHandling.h"
00024 #include "IPControlInfo.h"
00025 #include "IPDatagram.h"
00026 #include "ICMPMessage.h"
00027
00028
00029 Define_Module(ErrorHandling);
00030
00031 void ErrorHandling::initialize()
00032 {
00033 numReceived = 0;
00034 WATCH(numReceived);
00035 }
00036
00037 void ErrorHandling::handleMessage(cMessage *msg)
00038 {
00039 numReceived++;
00040
00041 ICMPMessage *icmpMsg = check_and_cast<ICMPMessage *>(msg);
00042
00043 IPDatagram *d = check_and_cast<IPDatagram *>(icmpMsg->getEncapsulatedMsg());
00044
00045 EV << "Error Handler: ICMP message received:\n";
00046 EV << " Type: " << (int)icmpMsg->getType()
00047 << " Code: " << (int)icmpMsg->getCode()
00048 << " Bytelength: " << d->getByteLength()
00049 << " Src: " << d->getSrcAddress()
00050 << " Dest: " << d->getDestAddress()
00051 << " Time: " << simTime()
00052 << "\n";
00053
00054 delete icmpMsg;
00055
00056 if (ev.isGUI())
00057 {
00058 char buf[80];
00059 sprintf(buf, "errors: %ld", numReceived);
00060 getDisplayString().setTagArg("t",0,buf);
00061 }
00062 }
00063