INET Framework for OMNeT++/OMNEST
AnsaIP.cc
Go to the documentation of this file.
00001 //
00002 // Copyright (C) 2004 Andras Varga
00003 //
00004 // This program is free software; you can redistribute it and/or
00005 // modify it under the terms of the GNU General Public License
00006 // as published by the Free Software Foundation; either version 2
00007 // of the License, or (at your option) any later version.
00008 //
00009 // This program is distributed in the hope that it will be useful,
00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 // GNU General Public License for more details.
00013 //
00014 // You should have received a copy of the GNU General Public License
00015 // along with this program; if not, write to the Free Software
00016 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00017 //
00018 
00019 
00020 #include <omnetpp.h>
00021 #include <stdlib.h>
00022 #include <string.h>
00023 
00024 #include "AnsaIP.h"
00025 #include "IPDatagram.h"
00026 #include "IPControlInfo.h"
00027 #include "ICMPMessage_m.h"
00028 #include "IPv4InterfaceData.h"
00029 #include "ARPPacket_m.h"
00030 
00031 Define_Module(AnsaIP);
00032 
00033 void AnsaIP::initialize()
00034 {
00035         INET_API IP::initialize();
00036 }
00037 
00038 void AnsaIP::handlePacketFromNetwork(IPDatagram *datagram)
00039 {
00040     //
00041     // "Prerouting"
00042     //
00043 
00044     // check for header biterror
00045     if (datagram->hasBitError())
00046     {
00047         // probability of bit error in header = size of header / size of total message
00048         // (ignore bit error if in payload)
00049         double relativeHeaderLength = datagram->getHeaderLength() / (double)datagram->getByteLength();
00050         if (dblrand() <= relativeHeaderLength)
00051         {
00052             EV << "bit error found, sending ICMP_PARAMETER_PROBLEM\n";
00053             icmpAccess.get()->sendErrorMessage(datagram, ICMP_PARAMETER_PROBLEM, 0);
00054             return;
00055         }
00056     }
00057 
00058     // remove control info
00059     //if (datagram->getTransportProtocol()!=IP_PROT_DSR && datagram->getTransportProtocol()!=IP_PROT_MANET)
00060     //{
00061     //    delete datagram->removeControlInfo();
00062     //}
00063     if (datagram->getMoreFragments()) delete datagram->removeControlInfo(); // delete all control message except the last
00064 
00065     // hop counter decrement; FIXME but not if it will be locally delivered
00066     datagram->setTimeToLive(datagram->getTimeToLive()-1);
00067 
00068     // FIXME send IGMP packet to IGMP module 
00069     if (datagram->getTransportProtocol() == IP_PROT_IGMP)
00070     {
00071         cPacket *packet = decapsulateIP(datagram);
00072         send(packet, "transportOut", mapping.getOutputGateForProtocol(IP_PROT_IGMP));
00073         return;
00074     }
00075 
00076     // send PIM packet to PIM module
00077     if (datagram->getTransportProtocol() == IP_PROT_PIM)
00078         {
00079                 cPacket *packet = decapsulateIP(datagram);
00080                 send(packet, "transportOut", mapping.getOutputGateForProtocol(IP_PROT_PIM));
00081         return;
00082         }
00083         
00084     // route packet
00085     if (!datagram->getDestAddress().isMulticast())
00086         routePacket(datagram, NULL, false);
00087     else
00088         routeMulticastPacket(datagram, NULL, getSourceInterfaceFrom(datagram));
00089 }
00090