IPv6ErrorHandling.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 // Copyright (C) 2005 Wei Yang, Ng
00005 //
00006 // This program is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public License
00008 // as published by the Free Software Foundation; either version 2
00009 // of the License, or (at your option) any later version.
00010 //
00011 // This program is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 // GNU Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public License
00017 // along with this program; if not, see <http://www.gnu.org/licenses/>.
00018 //
00019 
00020 
00021 //  Cleanup and rewrite: Andras Varga, 2004
00022 //  Implementation of IPv6 version: Wei Yang, Ng, 2005
00023 
00024 #include <omnetpp.h>
00025 #include "IPv6ErrorHandling.h"
00026 #include "IPv6ControlInfo.h"
00027 #include "IPv6Datagram.h"
00028 
00029 Define_Module(IPv6ErrorHandling);
00030 
00031 void IPv6ErrorHandling::initialize()
00032 {
00033 }
00034 
00035 void IPv6ErrorHandling::handleMessage(cMessage *msg)
00036 {
00037     ICMPv6Message *icmpv6Msg = check_and_cast<ICMPv6Message *>(msg);
00038     IPv6Datagram *d = check_and_cast<IPv6Datagram *>(icmpv6Msg->getEncapsulatedMsg());
00039     int type = (int)icmpv6Msg->getType();
00040     int code;
00041     EV << " Type: " << type;
00042     if (dynamic_cast<ICMPv6DestUnreachableMsg *>(icmpv6Msg))
00043     {
00044         ICMPv6DestUnreachableMsg *msg2 = (ICMPv6DestUnreachableMsg *)icmpv6Msg;
00045         code = msg2->getCode();
00046         EV << " Code: " << code;
00047     }
00048     else if (dynamic_cast<ICMPv6PacketTooBigMsg *>(icmpv6Msg))
00049     {
00050         ICMPv6PacketTooBigMsg *msg2 = (ICMPv6PacketTooBigMsg *)icmpv6Msg;
00051         code = 0;
00052     }
00053     else if (dynamic_cast<ICMPv6TimeExceededMsg *>(icmpv6Msg))
00054     {
00055         ICMPv6TimeExceededMsg *msg2 = (ICMPv6TimeExceededMsg *)icmpv6Msg;
00056         code = msg2->getCode();
00057         EV << " Code: " << code;
00058     }
00059     else if (dynamic_cast<ICMPv6ParamProblemMsg *>(icmpv6Msg))
00060     {
00061         ICMPv6ParamProblemMsg *msg2 = (ICMPv6ParamProblemMsg *)icmpv6Msg;
00062         code = msg2->getCode();
00063         EV << " Code: " << code;
00064     }
00065 
00066     EV << " Byte length: " << d->getByteLength()
00067        << " Src: " << d->getSrcAddress()
00068        << " Dest: " << d->getDestAddress()
00069        << " Time: " << simTime()
00070        << "\n";
00071 
00072     if (type == 1)
00073         displayType1Msg(code);
00074     else if (type == 2)
00075         displayType2Msg();
00076     else if (type == 3)
00077         displayType3Msg(code);
00078     else if (type == 4)
00079         displayType4Msg(code);
00080     else
00081         EV << "Unknown Error Type!" << endl;
00082     delete icmpv6Msg;
00083 }
00084 
00085 void IPv6ErrorHandling::displayType1Msg(int code)
00086 {
00087     EV << "Destination Unreachable: ";
00088     if (code == 0)
00089         EV << "no route to destination\n";
00090     else if (code == 1)
00091         EV << "communication with destination administratively prohibited\n";
00092     else if (code == 3)
00093         EV << "address unreachable\n";
00094     else if (code == 4)
00095         EV << "port unreachable\n";
00096     else
00097         EV << "Unknown Error Code!\n";
00098 }
00099 
00100 void IPv6ErrorHandling::displayType2Msg()
00101 {
00102     EV << "Packet Too Big" << endl;
00103     //Code is always 0 and ignored by the receiver.
00104 }
00105 
00106 void IPv6ErrorHandling::displayType3Msg(int code)
00107 {
00108     EV << "Time Exceeded Message: ";
00109     if (code == 0)
00110         EV << "hop limit exceeded in transit\n";
00111     else if (code == 1)
00112         EV << "fragment reassembly time exceeded\n";
00113     else
00114         EV << "Unknown Error Code!\n";
00115 }
00116 
00117 void IPv6ErrorHandling::displayType4Msg(int code)
00118 {
00119     EV << "Parameter Problem Message: ";
00120     if (code == 0)
00121         EV << "erroneous header field encountered\n";
00122     else if (code == 1)
00123         EV << "unrecognized Next Header type encountered\n";
00124     else if (code == 2)
00125         EV << "unrecognized IPv6 option encountered\n";
00126     else
00127         EV << "Unknown Error Code!\n";
00128 }