ConfigurationManager.cc

Go to the documentation of this file.
00001 //
00002 // This program is free software: you can redistribute it and/or modify
00003 // it under the terms of the GNU Lesser General Public License as published by
00004 // the Free Software Foundation, either version 3 of the License, or
00005 // (at your option) any later version.
00006 // 
00007 // This program is distributed in the hope that it will be useful,
00008 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00009 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00010 // GNU Lesser General Public License for more details.
00011 // 
00012 // You should have received a copy of the GNU Lesser General Public License
00013 // along with this program.  If not, see http://www.gnu.org/licenses/.
00014 // 
00015 
00016 #include "ConfigurationManager.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( ConfigurationManager);
00032 
00033 int ConfigurationManager::numInitStages() const
00034 {
00035     return 2;
00036 }
00037 
00038 void ConfigurationManager::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 
00054         long ct_marker = 0;
00055         long ct_mask = 0;
00056         //Vonfigure Inputs
00057         if (dc->eClass()->getName() == "Switch")
00058         {
00059             Switch *sw = dc->as<Switch> ();
00060             if (sw->getConfig())
00061             {
00062                 ct_marker = ConfigurationUtils::mac2long(sw->getConfig()->getCtMarker());
00063                 ct_mask = ConfigurationUtils::mac2long(sw->getConfig()->getCtMask());
00064             }
00065         }
00066         else if (dc->eClass()->getName() == "EndSystem")
00067         {
00068             EndSystem *es = dc->as<EndSystem> ();
00069             if (es->getConfig())
00070             {
00071                 ct_marker = ConfigurationUtils::mac2long(es->getConfig()->getCtMarker());
00072                 ct_mask = ConfigurationUtils::mac2long(es->getConfig()->getCtMask());
00073             }
00074         }
00075         for(int i=0;getParentModule()->getSubmodule("phy",i);i++){
00076             cModule* input = getParentModule()->getSubmodule("phy",i)->getSubmodule("tteInput");
00077             input->par("ct_marker").setLongValue(ct_marker);
00078             input->par("ct_mask").setLongValue(ct_mask);
00079         }
00080 
00081         //Switch clockspeed
00082         if (dc->eClass()->getName() == "Switch")
00083         {
00084             TargetDevice_ptr td = dc->as<Switch> ()->getRefDeviceMapping()->getRefTargetDevice();
00085             if (td->eClass()->getName() == ("TTTechIpTargetDevice"))
00086             {
00087                 TTTechIpTargetDevice_ptr iptd = td->as<TTTechIpTargetDevice> ();
00088 
00089                 cModule* scheduler = getParentModule()->getSubmodule("tteScheduler");
00090 
00091                 scheduler->par("tick").setDoubleValue(ConfigurationUtils::freq2s(iptd->getClockSpeed()));
00092                 scheduler->par("current_tick").setDoubleValue(scheduler->par("tick").doubleValue());
00093                 //TODO Infomessage of parameter change
00094             }
00095         }
00096 
00097 
00098         EList<VirtualLinkSchedule>& vlSchedulesList = dc->getVlSchedules()->getVlSchedule();
00099         for (unsigned int i = 0; i < vlSchedulesList.size(); i++)
00100         {
00101             VirtualLinkSchedule_ptr vls = vlSchedulesList.get(i);
00102             EList<CTIncoming>& incomingList = vls->getIncoming();
00103             for (unsigned int j = 0; j < incomingList.size(); j++)
00104             {
00105                 CTIncoming_ptr incoming = incomingList.get(j);
00106                 cModuleType *moduleType;
00107                 cModule* newCTCModule;
00108                 if (incoming->eClass()->getName() == "TTIncoming")
00109                 {
00110                     Device_Specification::TTIncoming *ttincoming = incoming->as<Device_Specification::TTIncoming> ();
00111                     moduleType = cModuleType::get("ttethernet.ctc.TTIncoming");
00112                     std::string ctcName = vls->getRefVirtualLink()->getVlid().c_str();
00113                     ctcName.append("_CTC");
00114                     newCTCModule = moduleType->create(ctcName.c_str(), getParentModule());
00115                     //parameters
00116                     newCTCModule->par("receive_window_start") = ConfigurationUtils::time2ticks(
00117                             ttincoming->getReceiveWindowStart(),
00118                             getParentModule()->getSubmodule("tteScheduler")->par("tick").doubleValue());
00119                     newCTCModule->par("receive_window_end") = ConfigurationUtils::time2ticks(
00120                             ttincoming->getReceiveWindowEnd(),
00121                             getParentModule()->getSubmodule("tteScheduler")->par("tick").doubleValue());
00122                     newCTCModule->par("permanence_pit") = ConfigurationUtils::time2ticks(
00123                             ttincoming->getPermanencePit(),
00124                             getParentModule()->getSubmodule("tteScheduler")->par("tick").doubleValue());
00125                 }
00126                 else if (incoming->eClass()->getName() == "RCIncoming")
00127                 {
00128                     Device_Specification::RCIncoming *rcincoming = incoming->as<Device_Specification::RCIncoming> ();
00129                     moduleType = cModuleType::get("ttethernet.ctc.RCIncoming");
00130                     std::string ctcName = vls->getRefVirtualLink()->getVlid().c_str();
00131                     ctcName.append("_CTC");
00132                     newCTCModule = moduleType->create(ctcName.c_str(), getParentModule());
00133                     //parameters
00134                     newCTCModule->par("bag") = ConfigurationUtils::time2ticks(rcincoming->getRefBagAccount()->getBag(),
00135                             getParentModule()->getSubmodule("tteScheduler")->par("tick").doubleValue());
00136                     newCTCModule->par("jitter") = ConfigurationUtils::time2ticks(
00137                             rcincoming->getRefBagAccount()->getJitter(),
00138                             getParentModule()->getSubmodule("tteScheduler")->par("tick").doubleValue());
00139                 }
00140                 else
00141                 {
00142                     continue;
00143                 }
00144                 newCTCModule->finalizeParameters();
00145                 newCTCModule->buildInside();
00146                 newCTCModule->callInitialize();
00147                 newCTCModule->getDisplayString().setTagArg("p", 0, X_POS_GUIBUFFER+200*xPosition);
00148                 newCTCModule->getDisplayString().setTagArg("p", 1, Y_POS_GUIBUFFER+60*yPosition);
00149 
00150                 cModule* newModule;
00151                 //Create Outgoing Buffers
00152                 EList<Outgoing>& outgoingList = incoming->getOutgoing();
00153                 for (unsigned int k = 0; k < outgoingList.size(); k++)
00154                 {
00155                     Outgoing_ptr outgoing = outgoingList.get(k);
00156                     if (outgoing->eClass()->getName() == "TTOutgoing")
00157                     {
00158                         TTOutgoing_ptr ttoutgoing = outgoing->as<TTOutgoing> ();
00159                         //TODO: This may be wrong! What is the difference between incoming and outgoing buffer depth
00160                         if (incoming->getBufferDepth() > 0)
00161                         {
00162                             moduleType = cModuleType::get("ttethernet.buffer.TTQueueBuffer");
00163                         }
00164                         else
00165                         {
00166                             moduleType = cModuleType::get("ttethernet.buffer.TTDoubleBuffer");
00167                         }
00168 
00169                         newModule = moduleType->create(vls->getRefVirtualLink()->getVlid().c_str(), getParentModule());
00170                         //parameters
00171                         newModule->par("sendWindowStart") = ConfigurationUtils::time2ticks(
00172                                 ttoutgoing->getSendWindowStart(),
00173                                 getParentModule()->getSubmodule("tteScheduler")->par("tick").doubleValue());
00174                         newModule->par("sendWindowEnd") = ConfigurationUtils::time2ticks(
00175                                 ttoutgoing->getSendWindowEnd(),
00176                                 getParentModule()->getSubmodule("tteScheduler")->par("tick").doubleValue());
00177 
00178                     }
00179                     else if (outgoing->eClass()->getName() == "RCOutgoing")
00180                     {
00181                         RCOutgoing_ptr rcoutgoing = outgoing->as<RCOutgoing> ();
00182                         //TODO: This may be wrong! What is the difference between incoming and outgoing buffer depth
00183                         if (incoming->getBufferDepth() > 0)
00184                         {
00185                             moduleType = cModuleType::get("ttethernet.buffer.RCQueueBuffer");
00186                         }
00187                         else
00188                         {
00189                             moduleType = cModuleType::get("ttethernet.buffer.RCDoubleBuffer");
00190                         }
00191 
00192                         newModule = moduleType->create(vls->getRefVirtualLink()->getVlid().c_str(), getParentModule());
00193                         //parameters
00194                         newModule->par("max_dispatch_delay") = ConfigurationUtils::time2ticks(
00195                                 rcoutgoing->getMaxDispatchDelay(),
00196                                 getParentModule()->getSubmodule("tteScheduler")->par("tick").doubleValue());
00197                         newModule->par("bag") = ConfigurationUtils::time2ticks(
00198                                 rcoutgoing->getRefBagAccount()->getBag(),
00199                                 getParentModule()->getSubmodule("tteScheduler")->par("tick").doubleValue());
00200                         newModule->par("jitter") = ConfigurationUtils::time2ticks(
00201                                 rcoutgoing->getRefBagAccount()->getJitter(),
00202                                 getParentModule()->getSubmodule("tteScheduler")->par("tick").doubleValue());
00203 
00204                     }
00205                     else
00206                     {
00207                         continue;
00208                     }
00209                     //Set CT ID, marker and mask
00210                     newModule->par("ct_id") = ConfigurationUtils::getVLid(vls->getRefVirtualLink(), nc->getRefMappings());
00211                     if (dc->eClass()->getName() == "Switch")
00212                         {
00213                             Switch *sw = dc->as<Switch> ();
00214                             if (sw->getConfig())
00215                             {
00216                                 newModule->par("ct_marker") = ConfigurationUtils::mac2long(sw->getConfig()->getCtMarker());
00217                                 newModule->par("ct_mask") = ConfigurationUtils::mac2long(sw->getConfig()->getCtMask());
00218                             }
00219                         }
00220                         else if (dc->eClass()->getName() == "EndSystem")
00221                         {
00222                             EndSystem *es = dc->as<EndSystem> ();
00223                             if (es->getConfig())
00224                             {
00225                                 newModule->par("ct_marker") = ConfigurationUtils::mac2long(es->getConfig()->getCtMarker());
00226                                 newModule->par("ct_mask") = ConfigurationUtils::mac2long(es->getConfig()->getCtMask());
00227                             }
00228                         }
00229 
00230                     //Register Incoming at Ports
00231                     //destination Ports
00232                     EList<Port>& incomingportList = incoming->getRefInPort();
00233                     for (unsigned int l = 0; l < incomingportList.size(); l++)
00234                     {
00235                         Port_ptr incomingport = incomingportList.get(l);
00236                         string portName = ConfigurationUtils::getPortName(incomingport, nc->getRefMappings());
00237                         int ctID = ConfigurationUtils::getVLid(vls->getRefVirtualLink(), nc->getRefMappings());
00238                         if (portName.find("PHY") != string::npos)
00239                         {
00240                             Port_ptr incomingport = incomingportList.get(l);
00241                             int iport = ConfigurationUtils::getPortSerialNumber(incomingport, nc->getRefMappings());
00242                             if (iport >= 0)
00243                                 ((TTEInput*) getParentModule()->getSubmodule("phy", iport)->getSubmodule("tteInput"))->addIncoming(
00244                                         ctID, (Incoming*) newCTCModule);
00245                         }
00246                         else if (portName == "SYNC")
00247                         {
00248 
00249                         }
00250                         else if (portName == "HOST")
00251                         {
00252 //                            ((TTEApplicationBase*) getParentModule()->getSubmodule("tteApp"))->addIncoming(
00253 //                                        ctID, (Incoming*) newCTCModule);
00254                             ((TTEApplicationBase*) getParentModule()->getSubmodule("tteApp"))->addBuffer(
00255                                           ctID, (Buffer*) newModule);
00256                         }
00257                         else
00258                         {
00259 
00260                         }
00261                     }
00262 
00263                     //destination Ports
00264                     EList<Port>& outgoingportList = outgoing->getRefOutPort();
00265                     for (unsigned int m = 0; m < outgoingportList.size(); m++)
00266                     {
00267                         Port_ptr outgoingport = outgoingportList.get(m);
00268                         string portName = ConfigurationUtils::getPortName(outgoingport, nc->getRefMappings());
00269                         int ctID = ConfigurationUtils::getVLid(vls->getRefVirtualLink(), nc->getRefMappings());
00270                         int oport = ConfigurationUtils::getPortSerialNumber(outgoingport, nc->getRefMappings());
00271                         cModule *destModule;
00272                         //TODO fix parsing of porttype attribute and use it
00273                         if (portName.find("PHY") != string::npos)
00274                         {
00275                             destModule = getParentModule()->getSubmodule("phy", oport);
00276                             if (outgoing->eClass()->getName() == "TTOutgoing")
00277                             {
00278                                 TTBuffer *ttbuffer = dynamic_cast<TTBuffer*> (newModule);
00279                                 ttbuffer->addDestinationGate(destModule->gate("TTin"));
00280                                 if (((TTEOutput *) destModule->getSubmodule("tteOutput")))
00281                                 {
00282                                     ((TTEOutput *) destModule->getSubmodule("tteOutput"))->registerTTBuffer(ttbuffer);
00283                                 }
00284                             }
00285                             else if (outgoing->eClass()->getName() == "RCOutgoing")
00286                             {
00287                                 ((TTEthernetModel::Buffer*) newModule)->addDestinationGate(destModule->gate("RCin"));
00288                             }
00289                         }
00290                         else if (portName == "SYNC")
00291                         {
00292                             destModule = getParentModule()->getSubmodule("sync", oport);
00293                         }
00294                         else if (portName == "HOST")
00295                         {
00296                             destModule = getParentModule()->getSubmodule("tteApp", oport);
00297                             ((TTEApplicationBase*) destModule)->addBuffer(ctID, (Buffer*) newModule);
00298                         }
00299                         else
00300                         {
00301                             ev << portName << ":" << oport << endl << endl;
00302                             continue;
00303                         }
00304 
00305                     }
00306 
00307                     //generate connections
00308                     newCTCModule->gate("out")->connectTo(newModule->gate("in"));
00309 
00310                     newModule->finalizeParameters();
00311                     newModule->buildInside();
00312                     newModule->callInitialize();
00313                     newModule->getDisplayString().setTagArg("p", 0, X_POS_GUIBUFFER+100+200*xPosition);
00314                     newModule->getDisplayString().setTagArg("p", 1, Y_POS_GUIBUFFER+15+60*yPosition);
00315 
00316                     yPosition++;
00317                     if(yPosition>=4){
00318                         xPosition++;
00319                         yPosition=0;
00320                     }
00321                 }
00322 
00323             }
00324         }
00325         //Generate start message to delete module
00326         scheduleAt(simTime(), new cMessage("Delete Module"));
00327     }
00328 }
00329 
00330 void ConfigurationManager::handleMessage(cMessage *msg)
00331 {
00332     //delete module on first message, it is not needed anymore;
00333     delete msg;
00334     deleteModule();
00335 }
00336 
00337 } //namespace
Generated on Wed Dec 7 11:24:06 2011 for TTEthernet Model for INET Framework by  doxygen 1.6.3