|
INET Framework for OMNeT++/OMNEST
|
00001 // 00002 // Copyright (C) 2011 Martin Danko 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 #include "DscpTtlCorrector.h" 00020 #include "IPDatagram.h" 00021 00022 00023 Define_Module(DscpTtlCorrector); 00024 00025 /* 00026 * initialize(): 00027 * Metoda pre inicializaciu modulu. 00028 */ 00029 00030 void DscpTtlCorrector::initialize() 00031 { 00032 // ziska ukazovatel na modul traffic generatoru 00033 tg = TrafGenAccess().get(); 00034 } 00035 /* 00036 * initialize(): 00037 * Spracuje spravu, ktora pride cez vstupnu branu modulu. 00038 * Rozbali paket a nastavi DSCP a TTL podla definicie toku 00039 * @param msg - prichadzajuca sprava 00040 */ 00041 00042 void DscpTtlCorrector::handleMessage(cMessage *msg) 00043 { 00044 // zistenie indexu vstupnej brany a nazvu 00045 cGate* gate = msg->getArrivalGate(); 00046 std::string name = gate->getBaseName(); 00047 int index = gate->getIndex(); 00048 00049 if (name == "toNetworkLayerIn") 00050 { // paket prichadzajuci z generatora -> musi byt upraveny 00051 cMessage *copy = msg->dup(); 00052 00053 cPacket *test = (cPacket*)(copy); 00054 std::string type = test->getClassName(); 00055 if (type == "IPDatagram") 00056 { // zmena s tyka len IP paketov 00057 IPDatagram *ipData = dynamic_cast<IPDatagram*> (copy); 00058 IPAddress srcAdd = ipData->getSrcAddress(); 00059 IPAddress destAdd = ipData->getDestAddress(); 00060 00061 unsigned char tos = 0; 00062 short ttl = 32; 00063 TCPSegment *tcppacket; 00064 UDPPacket *udppacket; 00065 int srcPort; 00066 int destPort; 00067 00068 switch (ipData->getTransportProtocol()) 00069 { // rozbalenie IP paketu a zistenie DSCP a TTL podla definicie toku 00070 case IP_PROT_UDP: 00071 udppacket = dynamic_cast<UDPPacket *> (ipData->decapsulate()); 00072 srcPort = udppacket->getSourcePort(); 00073 destPort = udppacket->getDestinationPort(); 00074 tos = tg->getDscpByFlowInfo(srcAdd, destAdd, IP_PROT_UDP, srcPort, destPort); 00075 ttl = tg->getTtlByFlowInfo(srcAdd, destAdd, IP_PROT_UDP, srcPort, destPort); 00076 tg->updateSentStats(udppacket->decapsulate()); 00077 delete udppacket; 00078 break; 00079 case IP_PROT_TCP: 00080 tcppacket = dynamic_cast<TCPSegment *> (ipData->decapsulate()); 00081 srcPort = tcppacket->getSrcPort(); 00082 destPort = tcppacket->getDestPort(); 00083 tos = tg->getDscpByFlowInfo(srcAdd, destAdd, IP_PROT_TCP, srcPort, destPort); 00084 ttl = tg->getTtlByFlowInfo(srcAdd, destAdd, IP_PROT_TCP, srcPort, destPort); 00085 cPacket *cpkt; 00086 uint32 endSeqNo; 00087 while ((cpkt=tcppacket->removeFirstPayloadMessage(endSeqNo))!=NULL) 00088 { 00089 tg->updateSentStats(cpkt); 00090 } 00091 delete tcppacket; 00092 break; 00093 default: 00094 break; 00095 } 00096 // zmena pozadovanych hodnot 00097 ipData = dynamic_cast<IPDatagram*> (msg); 00098 ipData->setTimeToLive(ttl); 00099 ipData->setDiffServCodePoint(tos); 00100 } 00101 // vysle zmeneny paket na vystupnu vranu 00102 this->send(msg, "ifOut", index); 00103 delete copy; 00104 } 00105 else 00106 { // paket prichadzajuci zo siete -> posiela sa bez zmeny 00107 this->send(msg, "toNetworkLayerOut", index); 00108 } 00109 } 00110 00111