示例#1
0
void
AdjLsa::removeNptEntries(Nlsr& pnlsr)
{
  if (getOrigRouter() != pnlsr.getConfParameter().getRouterPrefix()) {
    pnlsr.getNamePrefixTable().removeEntry(getOrigRouter(), getOrigRouter());
  }
}
示例#2
0
void
AdjLsa::addNptEntries(Nlsr& pnlsr)
{
  // Only add NPT entries if this is an adj LSA from another router.
  if (getOrigRouter() != pnlsr.getConfParameter().getRouterPrefix()) {
    // Pass the originating router as both the name to register and
    // where it came from.
    pnlsr.getNamePrefixTable().addEntry(getOrigRouter(), getOrigRouter());
  }
}
示例#3
0
void
RoutingTable::scheduleRoutingTableCalculation(Nlsr& pnlsr)
{
  if (pnlsr.getIsRouteCalculationScheduled() != true) {
    ndn::time::milliseconds delay = util::jitter::getTimeWithJitter(m_routingCalcInterval);

    _LOG_DEBUG("Scheduling routing table calculation in " << delay);

    m_scheduler.scheduleEvent(delay, ndn::bind(&RoutingTable::calculate, this, std::ref(pnlsr)));
    pnlsr.setIsRouteCalculationScheduled(true);
  }
}
示例#4
0
void
RoutingTable::scheduleRoutingTableCalculation(Nlsr& pnlsr)
{
  if (pnlsr.getIsRouteCalculationScheduled() != true) {
    _LOG_DEBUG("Scheduling routing table calculation in " << m_routingCalcInterval);

    m_scheduler.scheduleEvent(m_routingCalcInterval,
                              ndn::bind(&RoutingTable::calculate, this, ndn::ref(pnlsr)));

    pnlsr.setIsRouteCalculationScheduled(true);
  }
}
示例#5
0
void
RoutingTable::calculateHypDryRoutingTable(Nlsr& nlsr)
{
  Map map;
  map.createFromAdjLsdb(nlsr);
  map.writeLog();

  size_t nRouters = map.getMapSize();

  HyperbolicRoutingCalculator calculator(nRouters, true,
                                         nlsr.getConfParameter().getRouterPrefix());

  calculator.calculatePaths(map, ndn::ref(*this),
                            nlsr.getLsdb(), nlsr.getAdjacencyList());
}
示例#6
0
文件: map.cpp 项目: vslehman/NLSR
void
Map::createFromCoordinateLsdb(Nlsr& nlsr)
{
  for (CoordinateLsa lsa : nlsr.getLsdb().getCoordinateLsdb()) {
    addEntry(lsa.getOrigRouter());
  }
}
void
LinkStateRoutingTableCalculator::addAllLsNextHopsToRoutingTable(Nlsr& pnlsr, RoutingTable& rt,
                                                                Map& pMap, uint32_t sourceRouter)
{
  _LOG_DEBUG("LinkStateRoutingTableCalculator::addAllNextHopsToRoutingTable Called");

  int nextHopRouter = 0;

  for (size_t i = 0; i < m_nRouters ; i++) {
    if (i != sourceRouter) {

      nextHopRouter = getLsNextHop(i, sourceRouter);

      if (nextHopRouter != NO_NEXT_HOP) {

        double routeCost = m_distance[i];
        ndn::Name nextHopRouterName = pMap.getRouterNameByMappingNo(nextHopRouter);
        std::string nextHopFace =
          pnlsr.getAdjacencyList().getAdjacent(nextHopRouterName).getConnectingFaceUri();
        // Add next hop to routing table
        NextHop nh(nextHopFace, routeCost);
        rt.addNextHop(pMap.getRouterNameByMappingNo(i), nh);
      }
    }
  }
}
void
RoutingTableCalculator::makeAdjMatrix(Nlsr& pnlsr, Map pMap)
{
  std::list<AdjLsa> adjLsdb = pnlsr.getLsdb().getAdjLsdb();
  for (std::list<AdjLsa>::iterator it = adjLsdb.begin(); it != adjLsdb.end() ; it++) {

    int32_t row = pMap.getMappingNoByRouterName((*it).getOrigRouter());

    std::list<Adjacent> adl = (*it).getAdl().getAdjList();
    for (std::list<Adjacent>::iterator itAdl = adl.begin(); itAdl != adl.end() ; itAdl++) {

      int32_t col = pMap.getMappingNoByRouterName((*itAdl).getName());
      double cost = (*itAdl).getLinkCost();

      if ((row >= 0 && row < static_cast<int32_t>(m_nRouters)) &&
          (col >= 0 && col < static_cast<int32_t>(m_nRouters)))
      {
        adjMatrix[row][col] = cost;
      }
    }
  }

  // Links that do not have the same cost for both directions should have their
  // costs corrected:
  //
  //   If the cost of one side of the link is 0, both sides of the link should have their cost
  //   corrected to 0.
  //
  //   Otherwise, both sides of the link should use the larger of the two costs.
  //
  for (size_t row = 0; row < m_nRouters; ++row) {
    for (size_t col = 0; col < m_nRouters; ++col) {
      double toCost = adjMatrix[row][col];
      double fromCost = adjMatrix[col][row];

      if (fromCost != toCost) {
        double correctedCost = 0.0;

        if (toCost != 0 && fromCost != 0) {
          // If both sides of the link are up, use the larger cost
          correctedCost = std::max(toCost, fromCost);
        }

        _LOG_WARN("Cost between [" << row << "][" << col << "] and [" << col << "][" << row <<
                  "] are not the same (" << toCost << " != " << fromCost << "). " <<
                  "Correcting to cost: " << correctedCost);

        adjMatrix[row][col] = correctedCost;
        adjMatrix[col][row] = correctedCost;
      }
    }
  }
}
void
LinkStateRoutingTableCalculator::calculatePath(Map& pMap,
                                               RoutingTable& rt, Nlsr& pnlsr)
{
  _LOG_DEBUG("LinkStateRoutingTableCalculator::calculatePath Called");
  allocateAdjMatrix();
  initMatrix();
  makeAdjMatrix(pnlsr, pMap);
  writeAdjMatrixLog();
  int sourceRouter = pMap.getMappingNoByRouterName(pnlsr.getConfParameter().getRouterPrefix());
  allocateParent();
  allocateDistance();
  if (pnlsr.getConfParameter().getMaxFacesPerPrefix() == 1) {
    // Single Path
    doDijkstraPathCalculation(sourceRouter);
    // update routing table
    addAllLsNextHopsToRoutingTable(pnlsr, rt, pMap, sourceRouter);
  }
  else {
    // Multi Path
    setNoLink(getNumOfLinkfromAdjMatrix(sourceRouter));
    allocateLinks();
    allocateLinkCosts();
    getLinksFromAdjMatrix(links, linkCosts, sourceRouter);
    for (int i = 0 ; i < vNoLink; i++) {
      adjustAdMatrix(sourceRouter, links[i], linkCosts[i]);
      writeAdjMatrixLog();
      doDijkstraPathCalculation(sourceRouter);
      //update routing table
      addAllLsNextHopsToRoutingTable(pnlsr, rt, pMap, sourceRouter);
    }
    freeLinks();
    freeLinksCosts();
  }
  freeParent();
  freeDistance();
  freeAdjMatrix();
}
示例#10
0
文件: map.cpp 项目: vslehman/NLSR
void
Map::createFromAdjLsdb(Nlsr& pnlsr)
{
  std::list<AdjLsa> adjLsdb = pnlsr.getLsdb().getAdjLsdb();
  for (std::list<AdjLsa>::iterator it = adjLsdb.begin();
       it != adjLsdb.end() ; it++) {
    addEntry((*it).getOrigRouter());
    std::list<Adjacent> adl = (*it).getAdl().getAdjList();
    for (std::list<Adjacent>::iterator itAdl = adl.begin();
         itAdl != adl.end() ; itAdl++) {
      addEntry((*itAdl).getName());
    }
  }
}
示例#11
0
void
SyncLogicHandler::processRoutingUpdateFromSync(const ndn::Name& routerName,
                                               uint64_t seqNo,  Nlsr& pnlsr)
{
  ndn::Name rName = routerName;
  if (routerName != pnlsr.getConfParameter().getRouterPrefix()) {
    SequencingManager sm(seqNo);
    sm.writeLog();
    _LOG_DEBUG(routerName);
    try {
      if (pnlsr.getLsdb().isNameLsaNew(rName.append("name"), sm.getNameLsaSeq())) {
        _LOG_DEBUG("Updated Name LSA. Need to fetch it");
        ndn::Name interestName(pnlsr.getConfParameter().getLsaPrefix());
        interestName.append(routerName);
        interestName.append("name");
        interestName.appendNumber(sm.getNameLsaSeq());
        pnlsr.getLsdb().expressInterest(interestName,
                                        pnlsr.getConfParameter().getInterestResendTime(),
                                        0);
      }
      if (pnlsr.getLsdb().isAdjLsaNew(rName.append("adjacency"), sm.getAdjLsaSeq())) {
        _LOG_DEBUG("Updated Adj LSA. Need to fetch it");
        ndn::Name interestName(pnlsr.getConfParameter().getLsaPrefix());
        interestName.append(routerName);
        interestName.append("adjacency");
        interestName.appendNumber(sm.getAdjLsaSeq());
        pnlsr.getLsdb().expressInterest(interestName,
                                        pnlsr.getConfParameter().getInterestResendTime(),
                                        0);
      }
      if (pnlsr.getLsdb().isCoordinateLsaNew(rName.append("coordinate"),
                                             sm.getCorLsaSeq())) {
        _LOG_DEBUG("Updated Cor LSA. Need to fetch it");
        ndn::Name interestName(pnlsr.getConfParameter().getLsaPrefix());
        interestName.append(routerName);
        interestName.append("coordinate");
        interestName.appendNumber(sm.getCorLsaSeq());
        pnlsr.getLsdb().expressInterest(interestName,
                                        pnlsr.getConfParameter().getInterestResendTime(),
                                        0);
      }
    }
    catch (std::exception& e) {
      std::cerr << e.what() << std::endl;
      return;
    }
  }
}
示例#12
0
void
RoutingTable::calculate(Nlsr& pnlsr)
{
  pnlsr.getLsdb().writeCorLsdbLog();
  pnlsr.getLsdb().writeNameLsdbLog();
  pnlsr.getLsdb().writeAdjLsdbLog();
  pnlsr.getNamePrefixTable().writeLog();
  if (pnlsr.getIsRoutingTableCalculating() == false) {
    //setting routing table calculation
    pnlsr.setIsRoutingTableCalculating(true);

    bool isHrEnabled = pnlsr.getConfParameter().getHyperbolicState() == HYPERBOLIC_STATE_ON;

    if ((!isHrEnabled && pnlsr.getLsdb().doesLsaExist(pnlsr.getConfParameter().getRouterPrefix().toUri() + "/" + "adjacency", std::string("adjacency"))) ||
        (isHrEnabled && pnlsr.getLsdb().doesLsaExist(pnlsr.getConfParameter().getRouterPrefix().toUri() + "/" + "coordinate", std::string("coordinate"))))
    {
      if (pnlsr.getIsBuildAdjLsaSheduled() != 1) {
        _LOG_TRACE("Clearing old routing table");
        clearRoutingTable();
        // for dry run options
        clearDryRoutingTable();

        _LOG_DEBUG("Calculating routing table");

        // calculate Link State routing
        if ((pnlsr.getConfParameter().getHyperbolicState() == HYPERBOLIC_STATE_OFF)
            || (pnlsr.getConfParameter().getHyperbolicState() == HYPERBOLIC_STATE_DRY_RUN)) {
          calculateLsRoutingTable(pnlsr);
        }
        //calculate hyperbolic routing
        if (pnlsr.getConfParameter().getHyperbolicState() == HYPERBOLIC_STATE_ON) {
          calculateHypRoutingTable(pnlsr);
        }
        //calculate dry hyperbolic routing
        if (pnlsr.getConfParameter().getHyperbolicState() == HYPERBOLIC_STATE_DRY_RUN) {
          calculateHypDryRoutingTable(pnlsr);
        }
        //need to update NPT here
        _LOG_DEBUG("Calling Update NPT With new Route");
        pnlsr.getNamePrefixTable().updateWithNewRoute();
        writeLog(pnlsr.getConfParameter().getHyperbolicState());
        pnlsr.getNamePrefixTable().writeLog();
        pnlsr.getFib().writeLog();
      }
      else {
        _LOG_DEBUG("Adjacency building is scheduled, so"
                   " routing table can not be calculated :(");
      }
    }
    else {
      _LOG_DEBUG("No Adj LSA of router itself,"
                 " so Routing table can not be calculated :(");
      clearRoutingTable();
      clearDryRoutingTable(); // for dry run options
      // need to update NPT here
      _LOG_DEBUG("Calling Update NPT With new Route");
      pnlsr.getNamePrefixTable().updateWithNewRoute();
      writeLog(pnlsr.getConfParameter().getHyperbolicState());
      pnlsr.getNamePrefixTable().writeLog();
      pnlsr.getFib().writeLog();
      //debugging purpose end
    }
    pnlsr.setIsRouteCalculationScheduled(false); //clear scheduled flag
    pnlsr.setIsRoutingTableCalculating(false); //unsetting routing table calculation
  }
  else {
    scheduleRoutingTableCalculation(pnlsr);
  }
}