ConfigurationUtils.cc

Go to the documentation of this file.
00001 /*
00002  * ConfigurationUtils.cpp
00003  *
00004  *  Created on: Feb 8, 2011
00005  *      Author: tillsteinbach
00006  */
00007 
00008 #include "ConfigurationUtils.h"
00009 
00010 #include <System_Specification.hpp>
00011 #include <Network_Configuration.hpp>
00012 #include <Device_Target_Mapping.hpp>
00013 #include <Device_Specification.hpp>
00014 #include <Device_Targets.hpp>
00015 #include <Protocol_Definition.hpp>
00016 #include <IP_Configuration.hpp>
00017 #include <Virtuallink_Map.hpp>
00018 #include <ecore.hpp> // Ecore metamodel
00019 #include <ecorecpp.hpp>
00020 
00021 #include <list>
00022 
00023 ecorecpp::MetaModelRepository_ptr ConfigurationUtils::getPreloadedMMR()
00024 {
00025     ecorecpp::MetaModelRepository_ptr mmr = ecorecpp::MetaModelRepository::_instance();
00026     mmr->load(Network_Configuration::Network_ConfigurationPackage::_instance());
00027     mmr->load(System_Specification::System_SpecificationPackage::_instance());
00028     mmr->load(Device_Target_Mapping::Device_Target_MappingPackage::_instance());
00029     mmr->load(Device_Specification::Device_SpecificationPackage::_instance());
00030     mmr->load(Device_Targets::Device_TargetsPackage::_instance());
00031     mmr->load(Protocol_Definition::Protocol_DefinitionPackage::_instance());
00032     mmr->load(IP_Configuration::IP_ConfigurationPackage::_instance());
00033     mmr->load(Virtuallink_Map::Virtuallink_MapPackage::_instance());
00034     return mmr;
00035 }
00036 
00037 void ConfigurationUtils::resolveCommonAliases(ecorecpp::ModelRepository_ptr mr)
00038 {
00039     mr->addAlias("platform:/plugin/com.tttech.tte.targetdevices/data/TTE_Prot_Layer_100M.device_targets",
00040             "TTE_Prot_Layer_100M.device_targets");
00041     mr->addAlias("platform:/plugin/com.tttech.tte.targetdevices/data/TTE_Dev_Switch_8port_100M_V2.device_targets",
00042             "TTE_Dev_Switch_8port_100M_V2.device_targets");
00043     mr->addAlias("platform:/plugin/com.tttech.tte.models/data/PredefinedIntegrityConfigurations.network_config",
00044             "PredefinedIntegrityConfigurations.network_config");
00045 }
00046 
00047 long ConfigurationUtils::mac2long(std::string string)
00048 {
00049     std::string::size_type pos;
00050     while ((pos = string.find(":")) != std::string::npos)
00051         string.erase(pos, 1);
00052     return strtoul(string.c_str(), NULL, 16);
00053 }
00054 
00055 unsigned long ConfigurationUtils::time2ticks(std::string string, double tick)
00056 {
00057     double factor = 0;
00058     std::string::size_type pos;
00059     if ((pos = string.find("ns")) != std::string::npos)
00060     {
00061         factor = 1000000000;
00062     }
00063     else if ((pos = string.find("us")) != std::string::npos)
00064     {
00065         factor = 1000000;
00066     }
00067     else if ((pos = string.find("ms")) != std::string::npos)
00068     {
00069         factor = 1000;
00070     }
00071     else if ((pos = string.find("s")) != std::string::npos)
00072         factor = 1;
00073 
00074     if (pos != std::string::npos)
00075         string.erase(pos);
00076     return round(::strtod(string.c_str(), 0) / (tick * factor));
00077 }
00078 
00079 double ConfigurationUtils::freq2s(std::string string)
00080 {
00081     double factor = 0;
00082     std::string::size_type pos;
00083     if ((pos = string.find("MHZ")) != std::string::npos || (pos = string.find("MHz")) != std::string::npos || (pos
00084             = string.find("Mhz")) != std::string::npos)
00085     {
00086         factor = 1000000;
00087     }
00088     if (pos != std::string::npos)
00089         string.erase(pos);
00090     return 1 / (::strtod(string.c_str(), 0) * factor);
00091 }
00092 
00093 Device_Specification::DeviceSpecification_ptr ConfigurationUtils::getDeviceSpecification(std::string device_name,
00094         Network_Configuration::NetworkConfig_ptr nc)
00095 {
00096     ecorecpp::mapping::EList<Network_Configuration::DeviceReferringElement>& dreList = nc->getDeviceReferringElement();
00097     for (unsigned int i = 0; i < dreList.size(); i++)
00098     {
00099         Network_Configuration::DeviceReferringElement_ptr dre = dreList.get(i);
00100         if (!dre->getRefDevice()->getName().compare(device_name))
00101         {
00102             return dre->getRefDeviceSpecification();
00103         }
00104     }
00105     return NULL;
00106 }
00107 
00108 int ConfigurationUtils::getPortSerialNumber(System_Specification::Port_ptr port,
00109         Device_Target_Mapping::Mappings_ptr map)
00110 {
00111     ecorecpp::mapping::EList<Device_Target_Mapping::DeviceMapping>& devicemapList =
00112             map->getDeviceMappings()->getDeviceMapping();
00113     for (unsigned int i = 0; i < devicemapList.size(); i++)
00114     {
00115         Device_Target_Mapping::PortMappings_ptr pms = devicemapList.get(i)->getPortMappings();
00116         // Switch Portmappings
00117         if (!pms->eClass()->getName().compare("SwPortMappings"))
00118         {
00119             ecorecpp::mapping::EList<Device_Target_Mapping::SwPortMapping>& portmapList = pms->as<
00120                     Device_Target_Mapping::SwPortMappings> ()->getTargetPortMapping();
00121             //Go through port mappings
00122             for (unsigned int j = 0; j < portmapList.size(); j++)
00123             {
00124                 Device_Target_Mapping::SwPortMapping_ptr pm = portmapList.get(j);
00125                 std::string refname = pm->getRefPort()->getName();
00126                 std::string pname = port->getName();
00127                 //If reference device is our device and PHY is found we have a physical port
00128                 if (!pm->getRefPort()->getName().compare(port->getName()) && !pm->getRefTargetPort()->getName().find(
00129                         "PHY") != -1)
00130                 {
00131                     return pm->getRefTargetPort()->getPortSerialNumber();
00132                 }
00133             }
00134         }
00135         // EndSystem Portmappings
00136         else if (!pms->eClass()->getName().compare("EsPortMappings"))
00137         {
00138             ecorecpp::mapping::EList<Device_Target_Mapping::EsPortMapping>& portmapList = pms->as<
00139                     Device_Target_Mapping::EsPortMappings> ()->getTargetPortMapping();
00140             //Go through port mappings
00141             for (unsigned int j = 0; j < portmapList.size(); j++)
00142             {
00143                 Device_Target_Mapping::EsPortMapping_ptr pm = portmapList.get(j);
00144                 //If reference device is our device and PHY is found we have a physical port
00145                 if (!pm->getRefPort()->getName().compare(port->getName()) && !pm->getRefTargetPort()->getName().find(
00146                         "PHY") != -1)
00147                 {
00148                     return pm->getRefTargetPort()->getPortSerialNumber();
00149                 }
00150             }
00151         }
00152     }
00153     return -1;
00154 }
00155 
00156 string ConfigurationUtils::getPortName(System_Specification::Port_ptr port, Device_Target_Mapping::Mappings_ptr map)
00157 {
00158     ecorecpp::mapping::EList<Device_Target_Mapping::DeviceMapping>& devicemapList =
00159             map->getDeviceMappings()->getDeviceMapping();
00160     for (unsigned int i = 0; i < devicemapList.size(); i++)
00161     {
00162         Device_Target_Mapping::PortMappings_ptr pms = devicemapList.get(i)->getPortMappings();
00163         // Switch Portmappings
00164         if (!pms->eClass()->getName().compare("SwPortMappings"))
00165         {
00166             ecorecpp::mapping::EList<Device_Target_Mapping::SwPortMapping>& portmapList = pms->as<
00167                     Device_Target_Mapping::SwPortMappings> ()->getTargetPortMapping();
00168             //Go through port mappings
00169             for (unsigned int j = 0; j < portmapList.size(); j++)
00170             {
00171                 Device_Target_Mapping::SwPortMapping_ptr pm = portmapList.get(j);
00172                 std::string refname = pm->getRefPort()->getName();
00173                 //If reference device is our device
00174                 if (!pm->getRefPort()->getName().compare(port->getName()))
00175                 {
00176                     return pm->getRefTargetPort()->getName();
00177                 }
00178             }
00179         }
00180         // EndSystem Portmappings
00181         else if (!pms->eClass()->getName().compare("EsPortMappings"))
00182         {
00183             ecorecpp::mapping::EList<Device_Target_Mapping::EsPortMapping>& portmapList = pms->as<
00184                     Device_Target_Mapping::EsPortMappings> ()->getTargetPortMapping();
00185             //Go through port mappings
00186             for (unsigned int j = 0; j < portmapList.size(); j++)
00187             {
00188                 Device_Target_Mapping::EsPortMapping_ptr pm = portmapList.get(j);
00189                 //If reference device is our device and PHY is found we have a physical port
00190                 if (!pm->getRefPort()->getName().compare(port->getName()))
00191                 {
00192                     return pm->getRefTargetPort()->getName();
00193                 }
00194             }
00195         }
00196     }
00197     return NULL;
00198 }
00199 
00200 int ConfigurationUtils::getVLid(System_Specification::VirtualLink_ptr vl, Device_Target_Mapping::Mappings_ptr map)
00201 {
00202     Virtuallink_Map::VirtualLinkMapping_ptr vlming = map->getRefVirtualLinkMappings();
00203     ecorecpp::mapping::EList<Virtuallink_Map::VirtualLinkMap>& vlmList = vlming->getVirtualLinkMap();
00204     for (unsigned int j = 0; j < vlmList.size(); j++)
00205     {
00206         Virtuallink_Map::VirtualLinkMap_ptr vlm = vlmList.get(j);
00207         if (!vlm->getRefVirtualLink()->getVlid().compare(vl->getVlid()))
00208         {
00209             return vlm->getId();
00210         }
00211     }
00212     return -1;
00213 }
00214 
00215 System_Specification::VirtualLink_ptr ConfigurationUtils::getVLfromVLid(int vlid,
00216         Device_Target_Mapping::Mappings_ptr map)
00217 {
00218     Virtuallink_Map::VirtualLinkMapping_ptr vlming = map->getRefVirtualLinkMappings();
00219     ecorecpp::mapping::EList<Virtuallink_Map::VirtualLinkMap>& vlmList = vlming->getVirtualLinkMap();
00220     for (unsigned int j = 0; j < vlmList.size(); j++)
00221     {
00222         Virtuallink_Map::VirtualLinkMap_ptr vlm = vlmList.get(j);
00223         if (vlm->getId() == vlid)
00224         {
00225             return vlm->getRefVirtualLink();
00226         }
00227     }
00228     //NOT FOUND
00229     return 0;
00230 }
00231 
Generated on Wed Dec 7 11:24:06 2011 for TTEthernet Model for INET Framework by  doxygen 1.6.3