ErrorHandling.cc

Go to the documentation of this file.
00001 //
00002 // Copyright (C) 2000 Institut fuer Telematik, Universitaet Karlsruhe
00003 // Copyright (C) 2004 Andras Varga
00004 //
00005 // This program is free software; you can redistribute it and/or
00006 // modify it under the terms of the GNU Lesser General Public License
00007 // as published by the Free Software Foundation; either version 2
00008 // of the License, or (at your option) any later version.
00009 //
00010 // This program is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 // GNU Lesser General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU Lesser General Public License
00016 // along with this program; if not, see <http://www.gnu.org/licenses/>.
00017 //
00018 
00019 
00020 //  Cleanup and rewrite: Andras Varga, 2004
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     // Note: we must NOT use decapsulate() because payload in ICMP is conceptually truncated
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