LCOV - code coverage report
Current view: top level - builds/DaniloBorquez/flex-net-sim/src - network.cpp (source / functions) Hit Total Coverage
Test: commit SHA1 Lines: 335 357 93.8 %
Date: 2025-08-25 21:30:02 Functions: 44 44 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : #include "network.hpp"
       2             : #include "unique_ptr.hpp"
       3             : 
       4             : #include <algorithm>
       5             : #include <fstream>
       6             : #include <iostream>
       7             : #include <memory>
       8             : #include <set>
       9             : #include <unordered_map>
      10             : 
      11          53 : Network::Network(void) : networkType(1)  {
      12          53 :   this->linkCounter = 0;
      13          53 :   this->nodeCounter = 0;
      14             : 
      15          53 :   this->nodes = std::vector<std::unique_ptr<Node>>();
      16          53 :   this->links = std::vector<std::shared_ptr<Link>>();
      17          53 :   this->linksIn = std::vector<std::shared_ptr<Link>>();
      18          53 :   this->linksOut = std::vector<std::shared_ptr<Link>>();
      19          53 :   this->nodesIn = std::vector<int>();
      20          53 :   this->nodesOut = std::vector<int>();
      21             : 
      22          53 :   this->nodesIn.push_back(0);
      23          53 :   this->nodesOut.push_back(0);
      24          53 : }
      25             : 
      26          26 : Network::Network(std::string filename, int networkType) : networkType(networkType) {
      27          26 :   this->linkCounter = 0;
      28          26 :   this->nodeCounter = 0;
      29             : 
      30          26 :   this->nodes = std::vector<std::unique_ptr<Node>>();
      31          26 :   this->links = std::vector<std::shared_ptr<Link>>();
      32          26 :   this->linksIn = std::vector<std::shared_ptr<Link>>();
      33          26 :   this->linksOut = std::vector<std::shared_ptr<Link>>();
      34          26 :   this->nodesIn = std::vector<int>();
      35          26 :   this->nodesOut = std::vector<int>();
      36             : 
      37          26 :   this->nodesIn.push_back(0);
      38          26 :   this->nodesOut.push_back(0);
      39             : 
      40             :   // open JSON file
      41          52 :   std::ifstream file(filename);
      42          26 :   if (!file.is_open()) {
      43           0 :     throw std::runtime_error("Could not open file: " + filename);
      44             :   }
      45          52 :   nlohmann::json network;
      46          26 :   file >> network;
      47             : 
      48             :   // number of nodes
      49          26 :   int numberOfNodes = network["nodes"].size();
      50             : 
      51             :   // number of links
      52          26 :   int numberOfLinks = network["links"].size();
      53             : 
      54             :   // adding nodes to the network
      55         381 :   for (int i = 0; i < numberOfNodes; i++) {
      56             :     int id;
      57         355 :     id = network["nodes"][i]["id"];
      58         710 :     std::unique_ptr<Node> node = create_unique<Node>(id);
      59         355 :     this->addNode(std::move(node));
      60             :   }
      61             : 
      62          26 :   switch (networkType) {
      63          23 :     case EON:
      64          23 :       readEONLinks(network, numberOfNodes, numberOfLinks);
      65          23 :       break;
      66           1 :     case SDM:
      67           1 :       readSDMLinks(network, numberOfNodes, numberOfLinks);
      68           1 :       break;
      69           2 :     case MB:
      70           2 :       readMBLinks(network, numberOfNodes, numberOfLinks);
      71           2 :       break;
      72           0 :     default:
      73           0 :       readEONLinks(network, numberOfNodes, numberOfLinks);
      74             :   }
      75          26 : }
      76             : 
      77          23 : void Network::readEONLinks(const nlohmann::json& network, int numberOfNodes, int numberOfLinks) {
      78             :   // adding links to the network
      79         989 :   for (int i = 0; i < numberOfLinks; i++) {
      80             :     int id;
      81         966 :     id = network["links"][i]["id"];
      82             :     float length;
      83         966 :     length = network["links"][i]["length"];
      84             :     float slots;
      85         966 :     slots = network["links"][i]["slots"];
      86             : 
      87        1932 :     std::shared_ptr<Link> link = std::make_shared<Link>(id, length, slots);
      88         966 :     this->addLink(link);
      89             : 
      90             :     // connecting nodes
      91             :     int src, dst;
      92         966 :     src = network["links"][i]["src"];
      93         966 :     id = network["links"][i]["id"];
      94         966 :     dst = network["links"][i]["dst"];
      95         966 :     this->connect(src, id, dst);
      96             :   }
      97          23 : }
      98             : 
      99           1 : void Network::readSDMLinks(const nlohmann::json& network, int numberOfNodes, int numberOfLinks) {
     100             :   // adding links to the network
     101          21 :   for (int i = 0; i < numberOfLinks; i++) {
     102             :     int id;
     103          20 :     id = network["links"][i]["id"];
     104             :     float length;
     105          20 :     length = network["links"][i]["length"];
     106             :     int number_of_cores;
     107          20 :     number_of_cores = network["links"][i]["number_of_cores"];
     108             :     int number_of_modes;
     109          20 :     number_of_modes = network["links"][i]["number_of_modes"];
     110          40 :     std::shared_ptr<Link> link = std::make_shared<Link>(id, length, 1, number_of_cores, number_of_modes);
     111             :     float slots;
     112          80 :     for (int j = 0; j < number_of_cores; j++) {
     113         180 :       for (int k = 0; k < number_of_modes; k++) {
     114         120 :         slots = network["links"][i]["slots"][j][k];
     115         120 :         link->setSlots(slots, j, k);
     116             :       }      
     117             :     }
     118          20 :     this->addLink(link);
     119             : 
     120             :     // connecting nodes
     121             :     int src, dst;
     122          20 :     src = network["links"][i]["src"];
     123          20 :     id = network["links"][i]["id"];
     124          20 :     dst = network["links"][i]["dst"];
     125          20 :     this->connect(src, id, dst);
     126             :   }
     127           1 : }
     128             : 
     129           2 : void Network::readMBLinks(const nlohmann::json& network, int numberOfNodes, int numberOfLinks) {
     130             :   // adding links to the network
     131          86 :   for (int i = 0; i < numberOfLinks; i++) {
     132             :     int id;
     133          84 :     id = network["links"][i]["id"];
     134             :     float length;
     135          84 :     length = network["links"][i]["length"];
     136         168 :     std::map<char, int> bandsAndSlots;
     137          84 :     float slots=0;
     138          84 :     int numberOfBands=0;
     139         168 :     auto bandSlots = network["links"][i]["slots"];
     140         420 :     for (auto it = bandSlots.begin(); it != bandSlots.end(); ++it) {
     141         672 :       std::string charValue = it.key();
     142         336 :       char band = charValue[0];
     143         336 :       float SlotsBand=it.value();
     144         336 :       slots+=SlotsBand;
     145         336 :       bandsAndSlots[band]=SlotsBand;
     146         336 :       numberOfBands++;
     147             :     }
     148             :     
     149         168 :     std::shared_ptr<Link> link = std::make_shared<Link>(id, length, slots, bandsAndSlots);
     150          84 :     this->addLink(link);
     151             : 
     152             :     // connecting nodes
     153             :     int src, dst;
     154          84 :     src = network["links"][i]["src"];
     155          84 :     id = network["links"][i]["id"];
     156          84 :     dst = network["links"][i]["dst"];
     157          84 :     this->connect(src, id, dst);
     158             :   }
     159           2 : }
     160             : 
     161           2 : Network::Network(const Network &net, int networkType)
     162           2 :     : networkType(networkType) {
     163           2 :   this->linkCounter = net.linkCounter;
     164           2 :   this->nodeCounter = net.nodeCounter;
     165           2 :   this->nodes = std::vector<std::unique_ptr<Node>>(net.nodes.size());
     166           4 :   for (unsigned int i = 0; i < this->nodes.size(); i++) {
     167             :     // TODO: deep copy of nodes
     168           2 :     this->nodes[i] = create_unique<Node>(*net.nodes[i]);
     169             :   }
     170           2 :   this->links = std::vector<std::shared_ptr<Link>>(net.links.size());
     171           4 :   for (unsigned int i = 0; i < this->links.size(); i++) {
     172             :     // this->links[i] = new Link(*net.links[i]);
     173           2 :     this->links[i] = net.links[i];
     174             :   }
     175             :   // TODO: change loop order
     176           2 :   this->linksIn = std::vector<std::shared_ptr<Link>>(net.linksIn.size());
     177           4 :   for (unsigned int i = 0; i < this->links.size(); i++) {
     178             :     // Copy only the pointer on the linksIn vector
     179           2 :     for (unsigned int j = 0; j < net.linksIn.size(); j++) {
     180           0 :       if (this->links[i]->getId() == net.linksIn[j]->getId()) {
     181           0 :         this->linksIn[j] = this->links[i];
     182           0 :         break;
     183             :       }
     184             :     }
     185             :   }
     186             : 
     187           2 :   this->linksOut = std::vector<std::shared_ptr<Link>>(net.linksOut.size());
     188           4 :   for (unsigned int i = 0; i < this->links.size(); i++) {
     189             :     // Copy only the pointer on the linksOut vector
     190           2 :     for (unsigned int j = 0; j < net.linksOut.size(); j++) {
     191           0 :       if (this->links[i]->getId() == net.linksOut[j]->getId()) {
     192           0 :         this->linksOut[j] = this->links[i];
     193           0 :         break;
     194             :       }
     195             :     }
     196             :   }
     197           2 :   this->nodesIn = net.nodesIn;
     198           2 :   this->nodesOut = net.nodesOut;
     199           2 : }
     200             : 
     201             : // May be useless
     202          20 : std::unique_ptr<Node> &Network::getNode(int nodePos) {
     203          20 :   if (nodePos < 0 || nodePos >= static_cast<int>(this->nodes.size()))
     204           6 :     throw std::runtime_error("Cannot get Node from a position out of bounds.");
     205             : 
     206          14 :   return this->nodes.at(nodePos);
     207             : }
     208             : // Returns the Node at a "nodePos" index inside Nodes vector.
     209             : 
     210             : // May be useless
     211       25015 : std::shared_ptr<Link> Network::getLink(int linkPos) {
     212       25015 :   if (linkPos < 0 || linkPos >= static_cast<int>(this->links.size()))
     213           4 :     throw std::runtime_error("Cannot get Link from a position out of bounds.");
     214             : 
     215       25011 :   return this->links.at(linkPos);
     216             : }
     217             : // Returns the Link pointer at a "linkPos" index inside Links vector.
     218             : 
     219          44 : int Network::getNetworkType() { return this->networkType; }
     220             : // Returns the int that represents the network type of the object
     221             : 
     222           7 : void Network::setNetworkType(int networkType) { this->networkType = networkType; }
     223             : // Returns the int that represents the network type of the object
     224             : 
     225         373 : void Network::addNode(std::unique_ptr<Node> node) {
     226         373 :   if (node->getId() != this->nodeCounter) {
     227             :     throw std::runtime_error(
     228           2 :         "Cannot add a Node to this network with Id mismatching node counter.");
     229             :   }
     230         371 :   this->nodeCounter++;
     231         371 :   this->nodes.push_back(std::move(node));
     232         371 :   this->nodesIn.push_back(0);
     233         371 :   this->nodesOut.push_back(0);
     234         371 : }
     235             : // Add a Node to Nodes vector, increases nodesIn/Out size.
     236             : 
     237        1112 : void Network::addLink(std::shared_ptr<Link> link) {
     238        1112 :   if (link->getId() != Network::linkCounter) {
     239             :     throw std::runtime_error(
     240           2 :         "Cannot add a Link to this network with Id mismatching link counter.");
     241             :   }
     242        1110 :   this->linkCounter++;
     243        1110 :   this->links.push_back(link);
     244        1110 : }
     245             : // Add a Link to Links vector.
     246             : 
     247        1082 : void Network::connect(int src, int linkPos,
     248             :                       int dst)  // Using Ids and Link from Nodes/Links vectors
     249             : {
     250        1082 :   if (src < 0 || src >= this->nodeCounter) {
     251             :     throw std::runtime_error(
     252           4 :         "Cannot connect src " + std::to_string(src) +
     253           4 :         " because its ID is not in the network. Number of nodes in network: " +
     254           6 :         std::to_string(this->nodeCounter));
     255             :   }
     256        1080 :   if (dst < 0 || dst >= this->nodeCounter) {
     257             :     throw std::runtime_error(
     258           4 :         "Cannot connect dst " + std::to_string(dst) +
     259           4 :         " because its ID is not in the network. Number of nodes in network: " +
     260           6 :         std::to_string(this->nodeCounter));
     261             :   }
     262        1078 :   if (linkPos < 0 || linkPos >= this->linkCounter) {
     263             :     throw std::runtime_error(
     264           4 :         "Cannot use link " + std::to_string(linkPos) +
     265           4 :         " because its ID is not in the network. Number of links in network: " +
     266           6 :         std::to_string(this->linkCounter));
     267             :   }
     268        3228 :   this->linksOut.insert(this->linksOut.begin() + this->nodesOut.at(src),
     269        3228 :                         this->links.at(linkPos));
     270        2152 :   std::for_each(this->nodesOut.begin() + src + 1, this->nodesOut.end(),
     271       11225 :                 [](int &n) { n += 1; });
     272             : 
     273        3228 :   this->linksIn.insert(this->linksIn.begin() + this->nodesIn.at(dst),
     274        3228 :                        this->links.at(linkPos));
     275        2152 :   std::for_each(this->nodesIn.begin() + dst + 1, this->nodesIn.end(),
     276       11219 :                 [](int &n) { n += 1; });
     277        1076 :   this->links.at(linkPos)->src = src;
     278        1076 :   this->links.at(linkPos)->dst = dst;
     279        1076 : }
     280             : // Connects two Nodes through one Link (order is important: src != dst):
     281             : //
     282             : //       (Source Node) ---Link---> (Destination Node)
     283             : 
     284       25359 : int Network::isConnected(int src, int dst) {
     285       53288 :   for (int i = this->nodesOut[src]; i < this->nodesOut[src + 1]; i++) {
     286      166127 :     for (int j = nodesIn[dst]; j < nodesIn[dst + 1]; j++) {
     287      138198 :       if (linksOut[i]->getId() == linksIn[j]->getId()) {
     288       25051 :         return linksOut[i]->getId();
     289             :       }
     290             :     }
     291             :   }
     292         308 :   return -1;
     293             : }
     294             : 
     295     2507591 : void Network::useSlot(int linkPos, int slotPos) {
     296     2507591 :   if (linkPos < 0 || linkPos >= static_cast<int>(this->links.size()))
     297           2 :     throw std::runtime_error("Link position out of bounds.");
     298             : 
     299     2507589 :   this->links[linkPos]->setSlot(slotPos, true);
     300     2507589 : }
     301             : 
     302           4 : void Network::useSlot(int linkPos, char band, int slotPos) {
     303           4 :   if (linkPos < 0 || linkPos >= static_cast<int>(this->links.size()))
     304           0 :     throw std::runtime_error("Link position out of bounds.");
     305             : 
     306           4 :   this->links[linkPos]->setSlot(slotPos, band, true);
     307           4 : }
     308             : 
     309          12 : void Network::useSlot(int linkPos, int core, int mode, int slotPos) {
     310          12 :   if (linkPos < 0 || linkPos >= static_cast<int>(this->links.size()))
     311           2 :     throw std::runtime_error("Link position out of bounds.");
     312             : 
     313          10 :   this->links[linkPos]->setSlot(core, mode, slotPos, true);
     314          10 : }
     315             : 
     316          14 : void Network::useSlot(int linkPos, int slotFrom, int slotTo) {
     317          14 :   this->validateSlotFromTo(linkPos, slotFrom, slotTo);
     318             : 
     319          90 :   for (int i = slotFrom; i < slotTo; i++)
     320          80 :     this->links[linkPos]->setSlot(i, true);
     321          10 : }
     322             : 
     323          16 : void Network::useSlot(int linkPos, char band ,int slotFrom, int slotTo) {
     324          16 :   this->validateSlotFromTo(linkPos, band, slotFrom, slotTo);
     325             : 
     326          60 :   for (int i = slotFrom; i < slotTo; i++)
     327          52 :     this->links[linkPos]->setSlot(i,band, true);
     328           8 : }
     329             : 
     330          14 : void Network::useSlot(int linkPos, int core, int mode, int slotFrom, int slotTo) {
     331          14 :   this->validateSlotFromTo(linkPos, core, mode, slotFrom, slotTo);
     332             : 
     333          90 :   for (int i = slotFrom; i < slotTo; i++)
     334          80 :     this->links[linkPos]->setSlot(core, mode, i, true);
     335          10 : }
     336             : 
     337     2507222 : void Network::unuseSlot(int linkPos, int slotPos) {
     338     2507222 :   if (linkPos < 0 || linkPos >= static_cast<int>(this->links.size()))
     339           4 :     throw std::runtime_error("Link position out of bounds.");
     340             : 
     341     2507218 :   this->links[linkPos]->setSlot(slotPos, false);
     342     2507216 : }
     343             : 
     344           6 : void Network::unuseSlot(int linkPos, char band, int slotPos) {
     345           6 :   if (linkPos < 0 || linkPos >= static_cast<int>(this->links.size()))
     346           4 :     throw std::runtime_error("Link position out of bounds.");
     347             :   
     348           2 :   bool notInRange=true;
     349           6 :   for (char c : this->links[linkPos]->getBands()) {
     350           4 :       if (c == band){
     351           2 :         notInRange=false;
     352             :       }
     353             :   }
     354           2 :   if(notInRange){
     355           0 :     throw std::runtime_error("Band does not exist!");
     356             :   }
     357             : 
     358           2 :   this->links[linkPos]->setSlot(slotPos, band,false);
     359           0 : }
     360             : 
     361           8 : void Network::unuseSlot(int linkPos, int core, int mode, int slotPos) {
     362           8 :   if (linkPos < 0 || linkPos >= static_cast<int>(this->links.size()))
     363           4 :     throw std::runtime_error("Link position out of bounds.");
     364             : 
     365           4 :   this->links[linkPos]->setSlot(core, mode, slotPos, false);
     366           2 : }
     367             : 
     368          12 : void Network::unuseSlot(int linkPos, int slotFrom, int slotTo) {
     369          12 :   this->validateSlotFromTo(linkPos, slotFrom, slotTo);
     370             : 
     371          20 :   for (int i = slotFrom; i < slotTo; i++)
     372          18 :     this->links[linkPos]->setSlot(i, false);
     373           2 : }
     374             : 
     375          10 : void Network::unuseSlot(int linkPos, char band, int slotFrom, int slotTo) {
     376          10 :   this->validateSlotFromTo(linkPos, band, slotFrom, slotTo);
     377             : 
     378           0 :   for (int i = slotFrom; i < slotTo; i++)
     379           0 :     this->links[linkPos]->setSlot(i, band, false);
     380           0 : } 
     381             : 
     382          12 : void Network::unuseSlot(int linkPos, int core, int mode, int slotFrom, int slotTo) {
     383          12 :   this->validateSlotFromTo(linkPos, core, mode, slotFrom, slotTo);
     384             : 
     385          20 :   for (int i = slotFrom; i < slotTo; i++)
     386          18 :     this->links[linkPos]->setSlot(core, mode, i, false);
     387           2 : }
     388             : 
     389          20 : int Network::getNumberOfLinks() { return this->linkCounter; }
     390             : 
     391         110 : int Network::getNumberOfNodes() { return this->nodeCounter; }
     392             : 
     393          10 : bool Network::isSlotUsed(int linkPos, int slotPos) {
     394          10 :   if (linkPos < 0 || linkPos >= static_cast<int>(this->links.size()))
     395           4 :     throw std::runtime_error("Link position out of bounds.");
     396             : 
     397          10 :   if (slotPos < 0 ||
     398           4 :       slotPos >= static_cast<int>(this->links[linkPos]->getSlots()))
     399           2 :     throw std::runtime_error("slot position out of bounds.");
     400           4 :   return this->links[linkPos]->getSlot(slotPos);
     401             : }
     402             : 
     403          10 : bool Network::isSlotUsed(int linkPos, int core, int mode, int slotPos) {
     404          10 :   if (linkPos < 0 || linkPos >= static_cast<int>(this->links.size()))
     405           4 :     throw std::runtime_error("Link position out of bounds.");
     406             : 
     407          10 :   if (slotPos < 0 ||
     408           4 :       slotPos >= static_cast<int>(this->links[linkPos]->getSlots(core, mode)))
     409           2 :     throw std::runtime_error("slot position out of bounds.");
     410           4 :   return this->links[linkPos]->getSlot(core, mode, slotPos);
     411             : }
     412             : 
     413           4 : bool Network::isSlotUsed(int linkPos, char band, int slotPos) {
     414           4 :   if (linkPos < 0 || linkPos >= static_cast<int>(this->links.size()))
     415           0 :     throw std::runtime_error("Link position out of bounds.");
     416             : 
     417           8 :   if (slotPos < 0 ||
     418           4 :       slotPos >= static_cast<int>(this->links[linkPos]->getSlots()))
     419           0 :     throw std::runtime_error("slot position out of bounds.");
     420           4 :   for (char c : this->links[linkPos]->getBands()) {
     421           4 :     if (c == band){
     422           8 :       return this->links[linkPos]->getSlot(slotPos,band);
     423             :     }
     424             :   }
     425           0 :   throw std::runtime_error("Cannot get slot in position on a non-existent band");
     426             : }
     427             : 
     428          14 : bool Network::isSlotUsed(int linkPos, int slotFrom, int slotTo) {
     429          14 :   this->validateSlotFromTo(linkPos, slotFrom, slotTo);
     430             : 
     431             :   // Loop through all the Slots in range
     432          14 :   for (int i = slotFrom; i < slotTo; i++) {
     433             :     // If it finds a single used slot...
     434          12 :     if (this->links[linkPos]->getSlot(i)) {
     435             :       //...then the entire slot range is considered "used".
     436           2 :       return true;
     437             :     }
     438             :   }
     439             :   // Otherwise, the entire slot range is free to allocate.
     440           2 :   return false;
     441             : }
     442             : 
     443          16 : bool Network::isSlotUsed(int linkPos, int core, int mode, int slotFrom, int slotTo) {
     444          16 :   this->validateSlotFromTo(linkPos, core, mode, slotFrom, slotTo);
     445             : 
     446             :   // Loop through all the Slots in range
     447          14 :   for (int i = slotFrom; i < slotTo; i++) {
     448             :     // If it finds a single used slot...
     449          12 :     if (this->links[linkPos]->getSlot(core, mode, i)) {
     450             :       //...then the entire slot range is considered "used".
     451           2 :       return true;
     452             :     }
     453             :   }
     454             :   // Otherwise, the entire slot range is free to allocate.
     455           2 :   return false;
     456             : }
     457             : 
     458           4 : bool Network::isSlotUsed(int linkPos, char band, int slotFrom, int slotTo) {
     459           4 :   this->validateSlotFromTo(linkPos, band, slotFrom, slotTo);
     460             : 
     461             :   // Loop through all the Slots in range
     462          14 :   for (int i = slotFrom; i < slotTo; i++) {
     463             :     // If it finds a single used slot...
     464          12 :     if (this->links[linkPos]->getSlot(i,band)) {
     465             :       //...then the entire slot range is considered "used".
     466           2 :       return true;
     467             :     }
     468             :   }
     469             :   // Otherwise, the entire slot range is free to allocate.
     470           2 :   return false;
     471             : }
     472             : 
     473           6 : float Network::averageNeighborhood() {
     474           6 :   if (this->getNumberOfNodes() == 0)
     475           2 :     throw std::runtime_error("The network must be have at least one node.");
     476           4 :   float result = 0;
     477           4 :   result = this->getNumberOfLinks() / this->getNumberOfNodes();
     478           4 :   return result;
     479             : }
     480             : 
     481           4 : float Network::normalAverageNeighborhood() {
     482           4 :   if (this->getNumberOfNodes() == 0)
     483           2 :     throw std::runtime_error("The network must be have at least one node.");
     484           2 :   float result = 0;
     485           4 :   result = (float)this->getNumberOfLinks() /
     486           2 :            (this->getNumberOfNodes() * (this->getNumberOfNodes() - 1));
     487           2 :   return result;
     488             : }
     489             : 
     490           4 : float Network::nodalVariance() {
     491           4 :   if (this->getNumberOfNodes() == 0)
     492           2 :     throw std::runtime_error("The network must be have at least one node.");
     493           2 :   float result = 0;
     494           2 :   float average = this->averageNeighborhood();
     495          30 :   for (int i = 0; i < this->getNumberOfNodes(); i++) {
     496          28 :     result += pow((this->nodesOut[i + 1] - this->nodesOut[i]) - average, 2);
     497             :   }
     498           2 :   result /= this->getNumberOfNodes();
     499           2 :   return result;
     500             : }
     501             : 
     502          40 : void Network::validateSlotFromTo(int linkPos, int slotFrom, int slotTo) {
     503          40 :   if (linkPos < 0 || linkPos >= static_cast<int>(this->links.size()))
     504          10 :     throw std::runtime_error("Link position out of bounds.");
     505          60 :   if (slotFrom < 0 ||
     506          30 :       slotFrom >= static_cast<int>(this->links[linkPos]->getSlots()))
     507           4 :     throw std::runtime_error("slot position out of bounds.");
     508          52 :   if (slotTo < 0 ||
     509          26 :       slotTo >= static_cast<int>(this->links[linkPos]->getSlots()))
     510           0 :     throw std::runtime_error("slot position out of bounds.");
     511          26 :   if (slotFrom > slotTo)
     512             :     throw std::runtime_error(
     513           6 :         "Initial slot position must be lower than the final slot position.");
     514             : 
     515          20 :   if (slotFrom == slotTo)
     516           4 :     throw std::runtime_error("Slot from and slot To cannot be equals.");
     517          16 : }
     518             : 
     519          30 : void Network::validateSlotFromTo(int linkPos, char band , int slotFrom, int slotTo) {
     520          30 :   if (linkPos < 0 || linkPos >= static_cast<int>(this->links.size()))
     521           8 :     throw std::runtime_error("Link position out of bounds.");
     522          44 :   if (slotFrom < 0 ||
     523          22 :       slotFrom >= static_cast<int>(this->links[linkPos]->getSlots(band)))
     524           2 :     throw std::runtime_error("slot position out of bounds.");
     525          40 :   if (slotTo < 0 ||
     526          20 :       slotTo >= static_cast<int>(this->links[linkPos]->getSlots(band)))
     527           0 :     throw std::runtime_error("slot position out of bounds.");
     528          20 :   if (slotFrom > slotTo)
     529             :     throw std::runtime_error(
     530           6 :         "Initial slot position must be lower than the final slot position.");
     531          14 :   if (slotFrom == slotTo)
     532           2 :     throw std::runtime_error("Slot from and slot To cannot be equals.");
     533             :   
     534          12 :   bool notInRange=true;
     535          36 :   for (char c : this->links[linkPos]->getBands()) {
     536          24 :       if (c == band){
     537          12 :         notInRange=false;
     538             :       }
     539             :   }
     540          12 :   if(notInRange){
     541           0 :     throw std::runtime_error("Band does not exist!");
     542             :   }
     543          12 : }
     544             : 
     545          42 : void Network::validateSlotFromTo(int linkPos, int core, int mode, int slotFrom, int slotTo) {
     546          42 :   if (linkPos < 0 || linkPos >= static_cast<int>(this->links.size()))
     547          12 :     throw std::runtime_error("Link position out of bounds.");
     548          60 :   if (slotFrom < 0 ||
     549          30 :       slotFrom >= static_cast<int>(this->links[linkPos]->getSlots(core, mode)))
     550           4 :     throw std::runtime_error("slot position out of bounds.");
     551          52 :   if (slotTo < 0 ||
     552          26 :       slotTo >= static_cast<int>(this->links[linkPos]->getSlots(core, mode)))
     553           0 :     throw std::runtime_error("slot position out of bounds.");
     554          26 :   if (slotFrom > slotTo)
     555             :     throw std::runtime_error(
     556           6 :         "Initial slot position must be lower than the final slot position.");
     557             : 
     558          20 :   if (slotFrom == slotTo)
     559           4 :     throw std::runtime_error("Slot from and slot To cannot be equals.");
     560          31 : }

Generated by: LCOV version 1.13