TraceChurn.cc

Go to the documentation of this file.
00001 //
00002 // Copyright (C) 2006 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 <PeerInfo.h>
00025 #include <GlobalNodeListAccess.h>
00026 #include <UnderlayConfigurator.h>
00027 #include "TraceChurn.h"
00028 
00029 Define_Module(TraceChurn);
00030 
00031 using namespace std;
00032 
00033 void TraceChurn::initializeChurn()
00034 {
00035     Enter_Method_Silent();
00036 
00037     // get uppermost tier
00038     // Quick hack. Works fine unless numTiers is > 9 (which should never happen)
00039     maxTier = new char[6];
00040     strcpy(maxTier, "tier0");
00041     maxTier[4] += par("numTiers").longValue();
00042 
00043     // FIXME: There should be a tracefile command to decide when init phase has finished
00044     underlayConfigurator->initFinished();
00045 }
00046 
00047 void TraceChurn::handleMessage(cMessage* msg)
00048 {
00049     delete msg;
00050     return;
00051 }
00052 
00053 void TraceChurn::createNode(int nodeId)
00054 {
00055     Enter_Method_Silent();
00056 
00057     TransportAddress* ta = underlayConfigurator->createNode(type);
00058     PeerInfo* peer = GlobalNodeListAccess().get()->getPeerInfo(*ta);
00059     cGate* inGate = simulation.getModule(peer->getModuleID())->getSubmodule(maxTier)->gate("trace_in");
00060     if (!inGate) {
00061         throw cRuntimeError("Application has no trace_in gate. Most probably "
00062                              "that means it is not able to handle trace data.");
00063     }
00064     nodeMapEntry* e = new nodeMapEntry(ta, inGate);
00065     nodeMap[nodeId] = e;
00066 }
00067 
00068 void TraceChurn::deleteNode(int nodeId)
00069 {
00070     Enter_Method_Silent();
00071 
00072     nodeMapEntry* e;
00073     UNORDERED_MAP<int, nodeMapEntry*>::iterator it = nodeMap.find(nodeId);
00074 
00075     if (it == nodeMap.end()) {
00076         throw cRuntimeError("Trying to delete non-existing node");
00077     }
00078 
00079     e = it->second;
00080     underlayConfigurator->preKillNode(NodeType(), e->first);
00081     nodeMap.erase(it);
00082     delete e->first;
00083     delete e;
00084 }
00085 
00086 TransportAddress* TraceChurn::getTransportAddressById(int nodeId) {
00087     UNORDERED_MAP<int, nodeMapEntry*>::iterator it = nodeMap.find(nodeId);
00088 
00089     if (it == nodeMap.end()) {
00090         throw cRuntimeError("Trying to get TransportAddress of nonexisting node");
00091     }
00092 
00093     return it->second->first;
00094 }
00095 
00096 cGate* TraceChurn::getAppGateById(int nodeId) {
00097     UNORDERED_MAP<int, nodeMapEntry*>::iterator it = nodeMap.find(nodeId);
00098 
00099     if (it == nodeMap.end()) {
00100         throw cRuntimeError("Trying to get appGate of nonexisting node");
00101     }
00102 
00103     return it->second->second;
00104 }
00105 
00106 void TraceChurn::updateDisplayString()
00107 {
00108     char buf[80];
00109     sprintf(buf, "trace churn");
00110     getDisplayString().setTagArg("t", 0, buf);
00111 }
Generated on Wed May 26 16:21:15 2010 for OverSim by  doxygen 1.6.3