|
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 00020 #include <omnetpp.h> 00021 #include "App_custum.h" 00022 00023 00024 Register_Class(custom); 00025 00026 /* 00027 * loadConfig(): 00028 * Funkcia nacita konfiguraciu aplikacie zo XML suboru 00029 * @param appConfig - XML blok s konfiguraciu generovanej aplikacie 00030 * @return - Vrati true bola konfiguracia spravne nacitana 00031 */ 00032 bool custom::loadConfig(const cXMLElement& appConfig) 00033 { 00034 00035 cXMLElement* element; 00036 00037 element = appConfig.getFirstChildWithTag("packets_per_second"); 00038 if(element != NULL) 00039 pps = atof(element->getNodeValue()); 00040 00041 element = appConfig.getFirstChildWithTag("packet_size"); 00042 if(element != NULL) 00043 size = atoi(element->getNodeValue()); 00044 00045 element = appConfig.getFirstChildWithTag("time_distribution"); 00046 if(element != NULL) 00047 tDistr = element->getNodeValue(); 00048 00049 element = appConfig.getFirstChildWithTag("size_distribution"); 00050 if(element != NULL) 00051 sDistr = element->getNodeValue(); 00052 00053 if(pps == 0.0 || size == 0) 00054 return false; // chyba nacitania 00055 00056 return true; 00057 } 00058 00059 /* 00060 * getDefaultPort(): 00061 * Funkcia vracia hodnotu implicitneho portu aplikacie 00062 * @return - Vrati implicitny port 00063 */ 00064 int custom::getDefaultPort() 00065 { 00066 return 1024; 00067 } 00068 00069 /* 00070 * getNextPacketTime(): 00071 * Funkcia vrati velkost hlaviciek nad ramec transportneho protokolu 00072 * V tejto aplikacii nie je ziadna encapsulacia navyse 00073 * @return - Vrati nulu 00074 */ 00075 int custom::anotherEncapsulationOverhead() 00076 { 00077 return 0; 00078 } 00079 00080 /* 00081 * getNextPacketTime(): 00082 * Funkcia na zaklade definovaneho rozlozenia uci cas za aky 00083 * sa bude generovat dalsi paket 00084 * @return - Vrati cas genetovania dalsieho paketu 00085 */ 00086 double custom::getNextPacketTime() 00087 { 00088 if(tDistr == "normal") 00089 { 00090 return normal(1.0/pps, 1.0/(pps*10)); 00091 } 00092 else if (tDistr == "exponential") 00093 { 00094 return exponential(1.0/pps); 00095 } 00096 else 00097 { 00098 return 1.0/pps; 00099 } 00100 } 00101 00102 /* 00103 * getPacketSize(): 00104 * Funkcia podla definovaneho rozlozenia vrati velkost vygenerovaneho paketu 00105 * @return - Vrati velkost vygenerovaneho paketu 00106 */ 00107 int custom::getPacketSize() 00108 { 00109 if(tDistr == "normal") 00110 { 00111 return (int) normal(size, size/10); 00112 } 00113 else if (tDistr == "exponential") 00114 { 00115 return (int) exponential(size); 00116 } 00117 else 00118 { 00119 return size; 00120 } 00121 } 00122