OverSim
TraceChurn.cc
Go to the documentation of this file.
1 //
2 // Copyright (C) 2006 Institut fuer Telematik, Universitaet Karlsruhe (TH)
3 //
4 // This program is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU General Public License
6 // as published by the Free Software Foundation; either version 2
7 // of the License, or (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 //
18 
24 #include <PeerInfo.h>
25 #include <GlobalNodeListAccess.h>
26 #include <UnderlayConfigurator.h>
27 #include "TraceChurn.h"
28 
30 
31 using namespace std;
32 
34 {
35  Enter_Method_Silent();
36 
37  // get uppermost tier
38  // Quick hack. Works fine unless numTiers is > 9 (which should never happen)
39  maxTier = new char[6];
40  strcpy(maxTier, "tier0");
41  maxTier[4] += par("numTiers").longValue();
42 
43  // FIXME: There should be a tracefile command to decide when init phase has finished
44  underlayConfigurator->initFinished();
45 }
46 
47 void TraceChurn::handleMessage(cMessage* msg)
48 {
49  delete msg;
50  return;
51 }
52 
53 void TraceChurn::createNode(int nodeId)
54 {
55  Enter_Method_Silent();
56 
57  TransportAddress* ta = underlayConfigurator->createNode(type);
58  PeerInfo* peer = GlobalNodeListAccess().get()->getPeerInfo(*ta);
59  cGate* inGate = simulation.getModule(peer->getModuleID())->getSubmodule(maxTier)->gate("trace_in");
60  if (!inGate) {
61  throw cRuntimeError("Application has no trace_in gate. Most probably "
62  "that means it is not able to handle trace data.");
63  }
64  nodeMapEntry* e = new nodeMapEntry(ta, inGate);
65  nodeMap[nodeId] = e;
66 }
67 
68 void TraceChurn::deleteNode(int nodeId)
69 {
70  Enter_Method_Silent();
71 
72  nodeMapEntry* e;
73  UNORDERED_MAP<int, nodeMapEntry*>::iterator it = nodeMap.find(nodeId);
74 
75  if (it == nodeMap.end()) {
76  throw cRuntimeError("Trying to delete non-existing node");
77  }
78 
79  e = it->second;
80  underlayConfigurator->preKillNode(NodeType(), e->first);
81  nodeMap.erase(it);
82  delete e->first;
83  delete e;
84 }
85 
87  UNORDERED_MAP<int, nodeMapEntry*>::iterator it = nodeMap.find(nodeId);
88 
89  if (it == nodeMap.end()) {
90  throw cRuntimeError("Trying to get TransportAddress of nonexisting node");
91  }
92 
93  return it->second->first;
94 }
95 
96 cGate* TraceChurn::getAppGateById(int nodeId) {
97  UNORDERED_MAP<int, nodeMapEntry*>::iterator it = nodeMap.find(nodeId);
98 
99  if (it == nodeMap.end()) {
100  throw cRuntimeError("Trying to get appGate of nonexisting node");
101  }
102 
103  return it->second->second;
104 }
105 
107 {
108  char buf[80];
109  sprintf(buf, "trace churn");
110  getDisplayString().setTagArg("t", 0, buf);
111 }