BufferManager.cc
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #include "BufferManager.h"
00017
00018 #include <buffer/Buffer.h>
00019 #include <TTEInput.h>
00020 #include <TTEOutput.h>
00021 #include "TTEApplicationBase.h"
00022
00023 #include <configuration/ConfigurationUtils.h>
00024
00025
00026 #define X_POS_GUIBUFFER 330
00027 #define Y_POS_GUIBUFFER 30
00028
00029 namespace TTEthernetModel {
00030
00031 Define_Module( BufferManager);
00032
00033 int BufferManager::numInitStages() const
00034 {
00035 return 2;
00036 }
00037
00038 void BufferManager::initialize(int stage)
00039 {
00040 if (stage == 1)
00041 {
00042 unsigned int xPosition = 0;
00043 unsigned int yPosition = 0;
00044
00045 ConfigurationUtils::getPreloadedMMR();
00046 ecorecpp::ModelRepository *mr = ecorecpp::ModelRepository::_instance();
00047 ConfigurationUtils::resolveCommonAliases(mr);
00048 ::ecore::EObject *eobj = mr->getByFilename(getParentModule()->par("network_configuration"));
00049 assert(eobj);
00050 NetworkConfig *nc = ::ecore::instanceOf<NetworkConfig>(eobj);
00051 assert(nc);
00052 DeviceSpecification *dc = ConfigurationUtils::getDeviceSpecification(getParentModule()->par("device_name"), nc);
00053 EList<VirtualLinkSchedule>& vlSchedulesList = dc->getVlSchedules()->getVlSchedule();
00054 for (unsigned int i = 0; i < vlSchedulesList.size(); i++)
00055 {
00056 VirtualLinkSchedule_ptr vls = vlSchedulesList.get(i);
00057 EList<CTIncoming>& incomingList = vls->getIncoming();
00058 for (unsigned int j = 0; j < incomingList.size(); j++)
00059 {
00060 CTIncoming_ptr incoming = incomingList.get(j);
00061 cModuleType *moduleType;
00062 cModule* newCTCModule;
00063 if (incoming->eClass()->getName() == "TTIncoming")
00064 {
00065 Device_Specification::TTIncoming *ttincoming = incoming->as<Device_Specification::TTIncoming> ();
00066 moduleType = cModuleType::get("ttethernet.ctc.TTIncoming");
00067 std::string ctcName = vls->getRefVirtualLink()->getVlid().c_str();
00068 ctcName.append("_CTC");
00069 newCTCModule = moduleType->create(ctcName.c_str(), getParentModule());
00070
00071 newCTCModule->par("receive_window_start") = ConfigurationUtils::time2ticks(
00072 ttincoming->getReceiveWindowStart(),
00073 getParentModule()->getSubmodule("tteScheduler")->par("tick").doubleValue());
00074 newCTCModule->par("receive_window_end") = ConfigurationUtils::time2ticks(
00075 ttincoming->getReceiveWindowEnd(),
00076 getParentModule()->getSubmodule("tteScheduler")->par("tick").doubleValue());
00077 newCTCModule->par("permanence_pit") = ConfigurationUtils::time2ticks(
00078 ttincoming->getPermanencePit(),
00079 getParentModule()->getSubmodule("tteScheduler")->par("tick").doubleValue());
00080 }
00081 else if (incoming->eClass()->getName() == "RCIncoming")
00082 {
00083 Device_Specification::RCIncoming *rcincoming = incoming->as<Device_Specification::RCIncoming> ();
00084 moduleType = cModuleType::get("ttethernet.ctc.RCIncoming");
00085 std::string ctcName = vls->getRefVirtualLink()->getVlid().c_str();
00086 ctcName.append("_CTC");
00087 newCTCModule = moduleType->create(ctcName.c_str(), getParentModule());
00088
00089 newCTCModule->par("bag") = ConfigurationUtils::time2ticks(rcincoming->getRefBagAccount()->getBag(),
00090 getParentModule()->getSubmodule("tteScheduler")->par("tick").doubleValue());
00091 newCTCModule->par("jitter") = ConfigurationUtils::time2ticks(
00092 rcincoming->getRefBagAccount()->getJitter(),
00093 getParentModule()->getSubmodule("tteScheduler")->par("tick").doubleValue());
00094 }
00095 else
00096 {
00097 continue;
00098 }
00099 newCTCModule->finalizeParameters();
00100 newCTCModule->buildInside();
00101 newCTCModule->callInitialize();
00102 newCTCModule->getDisplayString().setTagArg("p", 0, X_POS_GUIBUFFER+200*xPosition);
00103 newCTCModule->getDisplayString().setTagArg("p", 1, Y_POS_GUIBUFFER+60*yPosition);
00104
00105 cModule* newModule;
00106
00107 EList<Outgoing>& outgoingList = incoming->getOutgoing();
00108 for (unsigned int k = 0; k < outgoingList.size(); k++)
00109 {
00110 Outgoing_ptr outgoing = outgoingList.get(k);
00111 if (outgoing->eClass()->getName() == "TTOutgoing")
00112 {
00113 TTOutgoing_ptr ttoutgoing = outgoing->as<TTOutgoing> ();
00114
00115 if (incoming->getBufferDepth() > 0)
00116 {
00117 moduleType = cModuleType::get("ttethernet.buffer.TTQueueBuffer");
00118 }
00119 else
00120 {
00121 moduleType = cModuleType::get("ttethernet.buffer.TTDoubleBuffer");
00122 }
00123
00124 newModule = moduleType->create(vls->getRefVirtualLink()->getVlid().c_str(), getParentModule());
00125
00126 newModule->par("sendWindowStart") = ConfigurationUtils::time2ticks(
00127 ttoutgoing->getSendWindowStart(),
00128 getParentModule()->getSubmodule("tteScheduler")->par("tick").doubleValue());
00129 newModule->par("sendWindowEnd") = ConfigurationUtils::time2ticks(
00130 ttoutgoing->getSendWindowEnd(),
00131 getParentModule()->getSubmodule("tteScheduler")->par("tick").doubleValue());
00132
00133 }
00134 else if (outgoing->eClass()->getName() == "RCOutgoing")
00135 {
00136 RCOutgoing_ptr rcoutgoing = outgoing->as<RCOutgoing> ();
00137
00138 if (incoming->getBufferDepth() > 0)
00139 {
00140 moduleType = cModuleType::get("ttethernet.buffer.RCQueueBuffer");
00141 }
00142 else
00143 {
00144 moduleType = cModuleType::get("ttethernet.buffer.RCDoubleBuffer");
00145 }
00146
00147 newModule = moduleType->create(vls->getRefVirtualLink()->getVlid().c_str(), getParentModule());
00148
00149 newModule->par("max_dispatch_delay") = ConfigurationUtils::time2ticks(
00150 rcoutgoing->getMaxDispatchDelay(),
00151 getParentModule()->getSubmodule("tteScheduler")->par("tick").doubleValue());
00152 newModule->par("bag") = ConfigurationUtils::time2ticks(
00153 rcoutgoing->getRefBagAccount()->getBag(),
00154 getParentModule()->getSubmodule("tteScheduler")->par("tick").doubleValue());
00155 newModule->par("jitter") = ConfigurationUtils::time2ticks(
00156 rcoutgoing->getRefBagAccount()->getJitter(),
00157 getParentModule()->getSubmodule("tteScheduler")->par("tick").doubleValue());
00158
00159 }
00160 else
00161 {
00162 continue;
00163 }
00164
00165 newModule->par("ct_id") = ConfigurationUtils::getVLid(vls->getRefVirtualLink(), nc->getRefMappings());
00166 if (dc->eClass()->getName() == "Switch")
00167 {
00168 Switch *sw = dc->as<Switch> ();
00169 if (sw->getConfig())
00170 {
00171 newModule->par("ct_marker") = ConfigurationUtils::mac2long(sw->getConfig()->getCtMarker());
00172 newModule->par("ct_mask") = ConfigurationUtils::mac2long(sw->getConfig()->getCtMask());
00173 }
00174 }
00175 else if (dc->eClass()->getName() == "EndSystem")
00176 {
00177 EndSystem *es = dc->as<EndSystem> ();
00178 if (es->getConfig())
00179 {
00180 newModule->par("ct_marker") = ConfigurationUtils::mac2long(es->getConfig()->getCtMarker());
00181 newModule->par("ct_mask") = ConfigurationUtils::mac2long(es->getConfig()->getCtMask());
00182 }
00183 }
00184
00185
00186
00187 EList<Port>& incomingportList = incoming->getRefInPort();
00188 for (unsigned int l = 0; l < incomingportList.size(); l++)
00189 {
00190 Port_ptr incomingport = incomingportList.get(l);
00191 string portName = ConfigurationUtils::getPortName(incomingport, nc->getRefMappings());
00192 int ctID = ConfigurationUtils::getVLid(vls->getRefVirtualLink(), nc->getRefMappings());
00193 if (portName.find("PHY") != string::npos)
00194 {
00195 Port_ptr incomingport = incomingportList.get(l);
00196 int iport = ConfigurationUtils::getPortSerialNumber(incomingport, nc->getRefMappings());
00197 if (iport >= 0)
00198 ((TTEInput*) getParentModule()->getSubmodule("phy", iport)->getSubmodule("tteInput"))->addIncoming(
00199 ctID, (Incoming*) newCTCModule);
00200 }
00201 else if (portName == "SYNC")
00202 {
00203
00204 }
00205 else if (portName == "HOST")
00206 {
00207
00208
00209 ((TTEApplicationBase*) getParentModule()->getSubmodule("tteApp"))->addBuffer(
00210 ctID, (Buffer*) newModule);
00211 }
00212 else
00213 {
00214
00215 }
00216 }
00217
00218
00219 EList<Port>& outgoingportList = outgoing->getRefOutPort();
00220 for (unsigned int m = 0; m < outgoingportList.size(); m++)
00221 {
00222 Port_ptr outgoingport = outgoingportList.get(m);
00223 string portName = ConfigurationUtils::getPortName(outgoingport, nc->getRefMappings());
00224 int ctID = ConfigurationUtils::getVLid(vls->getRefVirtualLink(), nc->getRefMappings());
00225 int oport = ConfigurationUtils::getPortSerialNumber(outgoingport, nc->getRefMappings());
00226 cModule *destModule;
00227
00228 if (portName.find("PHY") != string::npos)
00229 {
00230 destModule = getParentModule()->getSubmodule("phy", oport);
00231 if (outgoing->eClass()->getName() == "TTOutgoing")
00232 {
00233 TTBuffer *ttbuffer = dynamic_cast<TTBuffer*> (newModule);
00234 ttbuffer->addDestinationGate(destModule->gate("TTin"));
00235 if (((TTEOutput *) destModule->getSubmodule("tteOutput")))
00236 {
00237 ((TTEOutput *) destModule->getSubmodule("tteOutput"))->registerTTBuffer(ttbuffer);
00238 }
00239 }
00240 else if (outgoing->eClass()->getName() == "RCOutgoing")
00241 {
00242 ((TTEthernetModel::Buffer*) newModule)->addDestinationGate(destModule->gate("RCin"));
00243 }
00244 }
00245 else if (portName == "SYNC")
00246 {
00247 destModule = getParentModule()->getSubmodule("sync", oport);
00248 }
00249 else if (portName == "HOST")
00250 {
00251 destModule = getParentModule()->getSubmodule("tteApp", oport);
00252 ((TTEApplicationBase*) destModule)->addBuffer(ctID, (Buffer*) newModule);
00253 }
00254 else
00255 {
00256 ev << portName << ":" << oport << endl << endl;
00257 continue;
00258 }
00259
00260 }
00261
00262
00263 newCTCModule->gate("out")->connectTo(newModule->gate("in"));
00264
00265 newModule->finalizeParameters();
00266 newModule->buildInside();
00267 newModule->callInitialize();
00268 newModule->getDisplayString().setTagArg("p", 0, X_POS_GUIBUFFER+100+200*xPosition);
00269 newModule->getDisplayString().setTagArg("p", 1, Y_POS_GUIBUFFER+15+60*yPosition);
00270
00271 yPosition++;
00272 if(yPosition>=4){
00273 xPosition++;
00274 yPosition=0;
00275 }
00276 }
00277
00278 }
00279 }
00280
00281 scheduleAt(simTime(), new cMessage("Delete Module"));
00282 }
00283 }
00284
00285 void BufferManager::handleMessage(cMessage *msg)
00286 {
00287
00288 delete msg;
00289 deleteModule();
00290 }
00291
00292 }