Ejemplo n.º 1
0
 inline bool
 operator==(RoutingTableEntry& rhs)
 {
   return ((*this).getDestination() == rhs.getDestination()
           &&
          (*this).getNexthopList() == rhs.getNexthopList());
 }
Ejemplo n.º 2
0
RoutingTableEntryList RoutingTable::getPossibleNextHops(const Packet* packet) {
    if (isDeliverable(packet->getDestination())) {
        AddressPtr source = packet->getSource();
        AddressPtr sender = packet->getSender();

        RoutingTableEntryList* availableHops = table[packet->getDestination()];
        RoutingTableEntryList returnedList = RoutingTableEntryList(*availableHops);

        // remove all entries that would route the packet back over the source or sender of the packet (would create a loop)
        RoutingTableEntryList::iterator iterator = returnedList.begin();
        while (iterator != returnedList.end()) {
            RoutingTableEntry* entry = *iterator;
            AddressPtr possibleNextHop = entry->getAddress();
            if (possibleNextHop->equals(source) || possibleNextHop->equals(sender) ) {
                iterator = returnedList.erase(iterator);
            }
            else {
                iterator++;
            }
        }

        return returnedList;
    }
    else {
        // return empty list
        return RoutingTableEntryList();
    }
}
Ejemplo n.º 3
0
// function related to manipulation of routing table
void
RoutingTable::addNextHop(const ndn::Name& destRouter, NextHop& nh)
{
  _LOG_DEBUG("Adding " << nh << " for destination: " << destRouter);

  RoutingTableEntry* rteChk = findRoutingTableEntry(destRouter);
  if (rteChk == 0) {
    RoutingTableEntry rte(destRouter);
    rte.getNexthopList().addNextHop(nh);
    m_rTable.push_back(rte);
  }
  else {
    rteChk->getNexthopList().addNextHop(nh);
  }
}
Ejemplo n.º 4
0
void
NamePrefixTable::addEntry(const ndn::Name& name, RoutingTableEntry& rte)
{
  NptEntryList::iterator it = std::find_if(m_table.begin(),
                                           m_table.end(),
                                           bind(&npteCompare, _1, name));
  if (it == m_table.end()) {
    _LOG_TRACE("Adding origin: " << rte.getDestination() << " to new name prefix: " << name);

    NamePrefixTableEntry entry(name);

    entry.addRoutingTableEntry(rte);

    entry.generateNhlfromRteList();
    entry.getNexthopList().sort();

    m_table.push_back(entry);

    if (rte.getNexthopList().getSize() > 0) {
      _LOG_TRACE("Updating FIB with next hops for " << entry);
      m_nlsr.getFib().update(name, entry.getNexthopList());
    }
  }
  else {
    _LOG_TRACE("Adding origin: " << rte.getDestination() << " to existing prefix: " << *it);

    it->addRoutingTableEntry(rte);

    it->generateNhlfromRteList();
    it->getNexthopList().sort();

    if (it->getNexthopList().getSize() > 0) {
      _LOG_TRACE("Updating FIB with next hops for " << *it);
      m_nlsr.getFib().update(name, it->getNexthopList());
    }
    else {
      // The routing table may recalculate and add a routing table entry with no next hops to
      // replace an existing routing table entry. In this case, the name prefix is no longer
      // reachable through a next hop and should be removed from the FIB. But, the prefix
      // should remain in the Name Prefix Table as a future routing table calculation may
      // add next hops.
      _LOG_TRACE(*it << " has no next hops; removing from FIB");
      m_nlsr.getFib().remove(name);
    }
  }
}
Ejemplo n.º 5
0
void RoutingTable::applyEvaporation(Time* currentTime) {
    long timeDifference = currentTime->getDifferenceInMilliSeconds(lastAccessTime);
    delete currentTime;

    if (evaporationPolicy->isEvaporationNecessary(timeDifference)) {
        lastAccessTime->setToCurrentTime();

        RoutingTableMap::iterator i = table.begin();
        while (i!=table.end()) {
            std::pair<AddressPtr const, RoutingTableEntryList*> entryPair = *i;
            AddressPtr destination = entryPair.first;
            RoutingTableEntryList* nextHopsForDestination = entryPair.second;

            // apply evaporation to all next hops for that destination
            RoutingTableEntryList::iterator j = nextHopsForDestination->begin();
            while (j != nextHopsForDestination->end()) {
                RoutingTableEntry* entry = *j;
                float newPheromoneValue = evaporationPolicy->evaporate(entry->getPheromoneValue(), timeDifference);
                if (newPheromoneValue > 0) {
                    entry->setPheromoneValue(newPheromoneValue);
                    j++;
                }
                else {
                    delete entry;
                    j = nextHopsForDestination->erase(j); // this does not invalidate the iterator, because j is set to the valid return value of erase (will point to end() if empty)
                }
            }

            if (nextHopsForDestination->empty()) {
                delete nextHopsForDestination;
                i = table.erase(i); // this does not invalidate the iterator, because i is set to the valid return value of erase (will point to end() if empty)
            }
            else {
                i++;
            }
        }
    }
}
Ejemplo n.º 6
0
void RoutingTable::removeEntry(AddressPtr destination, AddressPtr nextHop, NetworkInterface* interface) {
    if (table.find(destination) != table.end()) {
        RoutingTableEntryList* entryList = table[destination];
        RoutingTableEntryList::iterator iterator = entryList->begin();

        if (iterator != entryList->end()) {
            while (iterator != entryList->end()) {
                RoutingTableEntry* entry = *iterator;
                if (entry->getAddress()->equals(nextHop) && entry->getNetworkInterface()->equals(interface)) {
                    entryList->erase(iterator);
                    delete entry;
                    break;
                }
                iterator++;
            }

            if (entryList->empty()) {
                // this was the last entry so we can delete the whole list
                table.erase(destination);
                delete entryList;
            }
        }
    }
}
Ejemplo n.º 7
0
void
NamePrefixTable::removeEntry(const ndn::Name& name, RoutingTableEntry& rte)
{
  NptEntryList::iterator it = std::find_if(m_table.begin(),
                                           m_table.end(),
                                           bind(&npteCompare, _1, name));
  if (it != m_table.end()) {
    _LOG_TRACE("Removing origin: " << rte.getDestination() << " from prefix: " << *it);

    it->removeRoutingTableEntry(rte);

    // If the prefix is a router prefix and it does not have any other routing table entries,
    // the Adjacency/Coordinate LSA associated with that origin router has been removed from
    // the LSDB and so the router prefix should be removed from the Name Prefix Table.
    //
    // If the prefix is an advertised name prefix:
    //   If another router advertises this name prefix, the RteList should have another entry
    //   for that router; the next hops should be recalculated and installed in the FIB.
    //
    //   If no other router advertises this name prefix, the RteList should be empty and the
    //   prefix can be removed from the Name Prefix Table. Once a new Name LSA advertises this
    //   prefix, a new entry for the prefix will be created.
    //
    if (it->getRteListSize() == 0) {
      _LOG_TRACE(*it << " has no routing table entries; removing from table and FIB");
      m_table.erase(it);
      m_nlsr.getFib().remove(name);
    }
    else {
      _LOG_TRACE(*it << " has other routing table entries; updating FIB with next hops");
      it->generateNhlfromRteList();
      it->getNexthopList().sort();

      m_nlsr.getFib().update(name, it->getNexthopList());
    }
  }
}
Ejemplo n.º 8
0
static bool
routingTableEntryCompare(RoutingTableEntry& rte, ndn::Name& destRouter)
{
  return rte.getDestination() == destRouter;
}