void LinkAggregationManager::stateUpdated(const StateDelta& delta) {
  CHECK(sw_->getUpdateEvb()->inRunningEventBaseThread());

  folly::SharedMutexWritePriority::WriteHolder writeGuard(&controllersLock_);

  if (!initialized_) {
    bool inserted;
    for (const auto& port : *(delta.newState()->getPorts())) {
      // TODO(samank): use try_emplace once OSS build uses boost >1.63.0
      std::tie(std::ignore, inserted) = portToController_.insert(std::make_pair(
          port->getID(),
          std::make_shared<LacpController>(
              port->getID(), sw_->getLacpEvb(), this)));
      CHECK(inserted);
    }

    for (const auto& portAndController : portToController_) {
      portAndController.second->startMachines();
    }
    initialized_ = true;
  }

  DeltaFunctions::forEachChanged(
      delta.getAggregatePortsDelta(),
      &LinkAggregationManager::aggregatePortChanged,
      &LinkAggregationManager::aggregatePortAdded,
      &LinkAggregationManager::aggregatePortRemoved,
      this);

  // Downgrade to a reader lock
  folly::SharedMutexWritePriority::ReadHolder readGuard(std::move(writeGuard));

  DeltaFunctions::forEachChanged(
      delta.getPortsDelta(), &LinkAggregationManager::portChanged, this);
}
Example #2
0
void NeighborUpdater::stateUpdated(const StateDelta& delta) {
  CHECK(sw_->getUpdateEVB()->inRunningEventBaseThread());
  for (const auto& entry : delta.getVlansDelta()) {
    sendNeighborUpdates(entry);
    auto oldEntry = entry.getOld();
    auto newEntry = entry.getNew();

    if (!newEntry) {
      vlanDeleted(oldEntry.get());
    } else if (!oldEntry) {
      vlanAdded(delta.newState().get(), newEntry.get());
    } else {
      vlanChanged(oldEntry.get(), newEntry.get());
    }
  }

  const auto& oldState = delta.oldState();
  const auto& newState = delta.newState();
  if (oldState->getArpTimeout() != newState->getArpTimeout() ||
      oldState->getNdpTimeout() != newState->getNdpTimeout() ||
      oldState->getMaxNeighborProbes() != newState->getMaxNeighborProbes() ||
      oldState->getStaleEntryInterval() != newState->getStaleEntryInterval()) {
    std::lock_guard<std::mutex> g(cachesMutex_);
    for (auto& vlanAndCaches : caches_) {
      auto& arpCache = vlanAndCaches.second->arpCache;
      auto& ndpCache = vlanAndCaches.second->ndpCache;
      arpCache->setTimeout(newState->getArpTimeout());
      arpCache->setMaxNeighborProbes(newState->getMaxNeighborProbes());
      arpCache->setStaleEntryInterval(newState->getStaleEntryInterval());
      ndpCache->setTimeout(newState->getNdpTimeout());
      ndpCache->setMaxNeighborProbes(newState->getMaxNeighborProbes());
      ndpCache->setStaleEntryInterval(newState->getStaleEntryInterval());
    }
  }
}
Example #3
0
void NeighborUpdater::stateUpdated(const StateDelta& delta) {
  CHECK(sw_->getUpdateEVB()->inRunningEventBaseThread());
  for (const auto& entry : delta.getVlansDelta()) {
    sendNeighborUpdates(entry);
    auto oldEntry = entry.getOld();
    auto newEntry = entry.getNew();

    if (!newEntry) {
      vlanDeleted(oldEntry.get());
    } else if (!oldEntry) {
      vlanAdded(delta.newState().get(), newEntry.get());
    } else {
      vlanChanged(oldEntry.get(), newEntry.get());
    }
  }
  unresolvedNhopsProber_->stateChanged(delta);
}
Example #4
0
void TunManager::stateUpdated(const StateDelta& delta) {
  // TODO(aeckert): We currently compare the entire interface map instead
  // of using the iterator in this delta because some of the interfaces may get
  // get probed from hardware, before they are in the SwitchState. It would be
  // nicer if we did a little more work at startup to sync the state, perhaps
  // updating the SwitchState with the probed interfaces. This would allow us
  // to reuse the iterator in the delta for more readable code and also not
  // have to worry about waiting to listen to updates until the SwSwitch is in
  // the configured state. t4155406 should also help with that.

  auto state = delta.newState();
  evb_->runInEventBaseThread([this, state]() {
      this->sync(state);
    });
}
Example #5
0
void RouteUpdateLogger::stateUpdated(const StateDelta& delta) {
  for (const auto& rtDelta : delta.getRouteTablesDelta()) {
    DeltaFunctions::forEachChanged(
        rtDelta.getRoutesV4Delta(),
        &handleChangedRoute<folly::IPAddressV4>,
        &handleAddedRoute<folly::IPAddressV4>,
        &handleRemovedRoute<folly::IPAddressV4>,
        prefixTracker_,
        routeLoggerV4_);
    DeltaFunctions::forEachChanged(
        rtDelta.getRoutesV6Delta(),
        &handleChangedRoute<folly::IPAddressV6>,
        &handleAddedRoute<folly::IPAddressV6>,
        &handleRemovedRoute<folly::IPAddressV6>,
        prefixTracker_,
        routeLoggerV6_);
  }
}
Example #6
0
void NexthopToRouteCount::stateChanged(const StateDelta& delta) {
   for (auto const& rtDelta : delta.getRouteTablesDelta()) {
      // Do add/changed first so we don't remove next hops due to decrements
      // in ref count via removed routes, only to add them back again if these
      // next hops show up in added/changed routes
     if (rtDelta.getNew()) {
       RouterID id = rtDelta.getNew()->getID();
       forEachChanged(
           rtDelta.getRoutesV4Delta(),
           &NexthopToRouteCount::processChangedRoute<RouteV4>,
           &NexthopToRouteCount::processAddedRoute<RouteV4>,
           [&](NexthopToRouteCount *, RouterID, const shared_ptr<RouteV4>&) {},
           this,
           id);
       forEachChanged(
           rtDelta.getRoutesV6Delta(),
           &NexthopToRouteCount::processChangedRoute<RouteV6>,
           &NexthopToRouteCount::processAddedRoute<RouteV6>,
           [&](NexthopToRouteCount *, RouterID, const shared_ptr<RouteV6>&) {},
           this,
           id);
    }
    // Process removed routes
    if (rtDelta.getOld()) {
      RouterID id = rtDelta.getOld()->getID();
      forEachRemoved(
          rtDelta.getRoutesV4Delta(),
          &NexthopToRouteCount::processRemovedRoute<RouteV4>,
          this,
          id);
      forEachRemoved(
          rtDelta.getRoutesV6Delta(),
          &NexthopToRouteCount::processRemovedRoute<RouteV6>,
          this,
          id);
    }
  }
}