00001 // 00002 // Copyright (C) 2008 Institut fuer Telematik, Universitaet Karlsruhe (TH) 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 00024 #include <TransportAddress.h> 00025 #include <UnderlayConfigurator.h> 00026 00027 #include "NoChurn.h" 00028 00029 Define_Module(NoChurn); 00030 00031 void NoChurn::initializeChurn() 00032 { 00033 Enter_Method_Silent(); 00034 00035 initialMean = par("initPhaseCreationInterval"); 00036 initialDeviation = initialMean / 3; 00037 targetOverlayTerminalNum = par("targetOverlayTerminalNum"); 00038 00039 initAddMoreTerminals = true; 00040 00041 mobilityTimer = new cMessage("mobilityTimer"); 00042 scheduleAt(simTime(), mobilityTimer); 00043 } 00044 00045 void NoChurn::handleMessage(cMessage* msg) 00046 { 00047 if (!msg->isSelfMessage()) { 00048 throw cRuntimeError("NoChurn::handleMessage(): " 00049 "Unknown message received!"); 00050 delete msg; 00051 return; 00052 } 00053 00054 if (msg == mobilityTimer) { 00055 if (terminalCount < targetOverlayTerminalNum) { 00056 TransportAddress* ta = underlayConfigurator->createNode(type); 00057 delete ta; // Address not needed in this churn model 00058 } 00059 00060 if (terminalCount >= targetOverlayTerminalNum) { 00061 initAddMoreTerminals = false; 00062 underlayConfigurator->initFinished(); 00063 } else { 00064 scheduleAt(simTime() 00065 + truncnormal(initialMean, initialDeviation), msg); 00066 } 00067 } 00068 } 00069 00070 void NoChurn::updateDisplayString() 00071 { 00072 char buf[80]; 00073 sprintf(buf, "No churn"); 00074 getDisplayString().setTagArg("t", 0, buf); 00075 } 00076 00077 NoChurn::~NoChurn() { 00078 // destroy self timer messages 00079 cancelAndDelete(mobilityTimer); 00080 } 00081