LCOV - code coverage report
Current view: top level - vnsw/agent/oper - path_preference.cc (source / functions) Hit Total Coverage
Test: OpenSDN C/C++ coverage (all TARGET_SET jobs) Lines: 0 610 0.0 %
Date: 2026-11-23 02:04:52 Functions: 0 70 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :  * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
       3             :  * Copyright Contributors to the OpenSDN project
       4             :  */
       5             : #include <boost/statechart/custom_reaction.hpp>
       6             : #include <boost/statechart/event.hpp>
       7             : #include <boost/statechart/simple_state.hpp>
       8             : #include <boost/statechart/state.hpp>
       9             : #include <boost/statechart/state_machine.hpp>
      10             : #include <cmn/agent_cmn.h>
      11             : #include <route/route.h>
      12             : #include <oper/route_common.h>
      13             : #include <oper/vrf.h>
      14             : #include <oper/mirror_table.h>
      15             : #include <oper/path_preference.h>
      16             : #include <mac_learning/mac_learning_init.h>
      17             : 
      18             : namespace sc = boost::statechart;
      19             : namespace mpl = boost::mpl;
      20             : 
      21             : SandeshTraceBufferPtr PathPreferenceTraceBuf(
      22             :         SandeshTraceBufferCreate("PathPreference", 5000));
      23             : struct EvStart : sc::event<EvStart> {
      24           0 :     EvStart() {
      25           0 :     }
      26             : 
      27             :     static const char *Name() {
      28             :         return "Start";
      29             :     }
      30             : };
      31             : 
      32             : struct EvTrafficSeen : sc::event<EvTrafficSeen> {
      33           0 :     EvTrafficSeen() {
      34           0 :     }
      35             :     static const char *Name() {
      36             :         return "TrafficSeen";
      37             :     }
      38             : };
      39             : 
      40             : struct EvWaitForTraffic : sc::event<EvWaitForTraffic> {
      41           0 :     EvWaitForTraffic() {
      42           0 :     }
      43             :     static const char *Name() {
      44             :         return "WaitForTraffic";
      45             :     }
      46             : };
      47             : 
      48             : struct EvSeqChange : sc::event<EvSeqChange> {
      49           0 :     EvSeqChange(uint32_t sequence) : sequence_(sequence) {
      50           0 :     }
      51             :     static const char *Name() {
      52             :         return "SeqChange";
      53             :     }
      54             :     uint32_t sequence_;
      55             : };
      56             : 
      57             : //Path transition to ECMP
      58             : struct EvActiveActiveMode : sc::event<EvActiveActiveMode> {
      59           0 :     EvActiveActiveMode() {
      60           0 :     }
      61             :     static const char *Name() {
      62             :         return "EcmpRoute";
      63             :     }
      64             : };
      65             : 
      66             : struct EvControlNodeInSync : sc::event<EvControlNodeInSync> {
      67           0 :     EvControlNodeInSync() {
      68           0 :     }
      69             :     static const char *Name() {
      70             :         return "Control node route in sync";
      71             :     }
      72             : };
      73             : 
      74             : struct Init : public sc::state<Init, PathPreferenceSM> {
      75             :     typedef mpl::list<
      76             :         sc::custom_reaction<EvStart>
      77             :     > reactions;
      78             : 
      79           0 :     Init(my_context ctx) : my_base(ctx) {
      80           0 :         PathPreferenceSM *state_machine = &context<PathPreferenceSM>();
      81           0 :         state_machine->Log("INIT");
      82           0 :     }
      83             : 
      84           0 :     sc::result react(const EvStart &event) {
      85           0 :         return transit<WaitForTraffic>();
      86             :     }
      87             : };
      88             : 
      89             : struct WaitForTraffic : sc::state<WaitForTraffic, PathPreferenceSM> {
      90             :     typedef mpl::list<
      91             :         sc::custom_reaction<EvTrafficSeen>,
      92             :         sc::custom_reaction<EvSeqChange>,
      93             :         sc::custom_reaction<EvWaitForTraffic>,
      94             :         sc::custom_reaction<EvActiveActiveMode>,
      95             :         sc::custom_reaction<EvControlNodeInSync>
      96             :     > reactions;
      97             : 
      98           0 :     WaitForTraffic(my_context ctx) : my_base(ctx) {
      99           0 :         PathPreferenceSM *state_machine = &context<PathPreferenceSM>();
     100           0 :         if (state_machine->wait_for_traffic() == false) {
     101           0 :             state_machine->set_wait_for_traffic(true);
     102           0 :             state_machine->set_preference(PathPreference::LOW);
     103           0 :             state_machine->EnqueuePathChange();
     104           0 :             state_machine->UpdateDependentRoute();
     105           0 :             state_machine->Log("Wait For Traffic");
     106             :         }
     107           0 :     }
     108             : 
     109           0 :     sc::result react(const EvTrafficSeen &event) {
     110           0 :         return transit<TrafficSeen>();
     111             :     }
     112             : 
     113           0 :     sc::result react(const EvSeqChange &event) {
     114           0 :         PathPreferenceSM *state_machine = &context<PathPreferenceSM>();
     115           0 :         state_machine->set_max_sequence(event.sequence_);
     116           0 :         state_machine->Log("WaitForTraffic EvSeqChange");
     117           0 :         return discard_event();
     118             :     }
     119             : 
     120           0 :     sc::result react(const EvWaitForTraffic &event) {
     121           0 :         return discard_event();
     122             :     }
     123             : 
     124           0 :     sc::result react(const EvActiveActiveMode &event) {
     125           0 :         return transit<ActiveActiveState>();
     126             :     }
     127             : 
     128           0 :     sc::result react(const EvControlNodeInSync &event) {
     129           0 :         return discard_event();
     130             :     }
     131             : };
     132             : 
     133             : struct TrafficSeen : sc::state<TrafficSeen, PathPreferenceSM> {
     134             :     typedef mpl::list<
     135             :         sc::custom_reaction<EvTrafficSeen>,
     136             :         sc::custom_reaction<EvSeqChange>,
     137             :         sc::custom_reaction<EvWaitForTraffic>,
     138             :         sc::custom_reaction<EvActiveActiveMode>,
     139             :         sc::custom_reaction<EvControlNodeInSync>
     140             :     > reactions;
     141             : 
     142           0 :     TrafficSeen(my_context ctx) : my_base(ctx) {
     143           0 :         PathPreferenceSM *state_machine = &context<PathPreferenceSM>();
     144             :         //Enqueue a route change
     145           0 :         if (state_machine->wait_for_traffic() == true) {
     146           0 :            state_machine->UpdateFlapTime();
     147           0 :            uint32_t seq = state_machine->max_sequence();
     148           0 :            state_machine->set_wait_for_traffic(false);
     149           0 :            seq++;
     150           0 :            state_machine->set_max_sequence(seq);
     151           0 :            if (state_machine->is_dependent_rt() == false) {
     152           0 :                state_machine->set_sequence(seq);
     153             :            }
     154           0 :            state_machine->set_preference(PathPreference::HIGH);
     155           0 :            state_machine->EnqueuePathChange();
     156           0 :            state_machine->UpdateDependentRoute();
     157           0 :            state_machine->Log("Traffic seen");
     158             :         }
     159           0 :     }
     160             : 
     161           0 :     sc::result react(const EvTrafficSeen &event) {
     162           0 :         return discard_event();
     163             :     }
     164             : 
     165           0 :     sc::result react(const EvWaitForTraffic &event) {
     166           0 :         return transit<WaitForTraffic>();
     167             :     }
     168             : 
     169           0 :     sc::result react(const EvSeqChange &event) {
     170           0 :         PathPreferenceSM *state_machine = &context<PathPreferenceSM>();
     171           0 :         if (event.sequence_ > state_machine->sequence()) {
     172           0 :             state_machine->set_max_sequence(event.sequence_);
     173           0 :             state_machine->Log("TrafficSeen EvSeqChange");
     174           0 :             if (state_machine->IsPathFlapping()) {
     175             :                 //If path is continuosly flapping
     176             :                 //delay wihtdrawing of route
     177           0 :                 if (state_machine->RetryTimerRunning() == false) {
     178           0 :                     state_machine->IncreaseRetryTimeout();
     179           0 :                     state_machine->StartRetryTimer();
     180           0 :                     state_machine->Log("Back off and retry update");
     181             :                 }
     182           0 :                 return discard_event();
     183             :             }
     184             :         }
     185           0 :         return transit<WaitForTraffic>();
     186             :     }
     187             : 
     188           0 :     sc::result react(const EvActiveActiveMode &event) {
     189           0 :         return transit<ActiveActiveState>();
     190             :     }
     191             : 
     192           0 :     sc::result react(const EvControlNodeInSync &event) {
     193           0 :         PathPreferenceSM *state_machine = &context<PathPreferenceSM>();
     194           0 :         state_machine->Log("in sync with control-node");
     195           0 :         return discard_event();
     196             :     }
     197             : };
     198             : 
     199             : struct ActiveActiveState : sc::state<ActiveActiveState, PathPreferenceSM> {
     200             :     typedef mpl::list<
     201             :         sc::custom_reaction<EvTrafficSeen>,
     202             :         sc::custom_reaction<EvSeqChange>,
     203             :         sc::custom_reaction<EvWaitForTraffic>,
     204             :         sc::custom_reaction<EvActiveActiveMode>,
     205             :         sc::custom_reaction<EvControlNodeInSync>
     206             :     > reactions;
     207             : 
     208           0 :     ActiveActiveState(my_context ctx) : my_base(ctx) {
     209           0 :         PathPreferenceSM *state_machine = &context<PathPreferenceSM>();
     210             :         //Enqueue a route change
     211           0 :         if (state_machine->preference() == PathPreference::LOW ||
     212           0 :             state_machine->wait_for_traffic() == true) {
     213           0 :            state_machine->set_wait_for_traffic(false);
     214           0 :            uint32_t seq = 0;
     215           0 :            state_machine->set_max_sequence(seq);
     216           0 :            state_machine->set_sequence(seq);
     217           0 :            state_machine->set_preference(PathPreference::HIGH);
     218           0 :            state_machine->EnqueuePathChange();
     219           0 :            state_machine->UpdateDependentRoute();
     220           0 :            state_machine->Log("Ecmp path");
     221             :         }
     222           0 :     }
     223             : 
     224           0 :     sc::result react(const EvTrafficSeen &event) {
     225           0 :         return discard_event();
     226             :     }
     227             : 
     228           0 :     sc::result react(const EvWaitForTraffic &event) {
     229           0 :         return transit<WaitForTraffic>();
     230             :     }
     231             : 
     232           0 :     sc::result react(const EvSeqChange &event) {
     233           0 :         PathPreferenceSM *state_machine = &context<PathPreferenceSM>();
     234           0 :         state_machine->set_max_sequence(event.sequence_);
     235           0 :         state_machine->Log("ActiveActiveState EvSeqChange");
     236           0 :         return transit<WaitForTraffic>();
     237             :     }
     238             : 
     239           0 :     sc::result react(const EvActiveActiveMode &event) {
     240           0 :         return discard_event();
     241             :     }
     242             : 
     243           0 :     sc::result react(const EvControlNodeInSync &event) {
     244           0 :         return discard_event();
     245             :     }
     246             : };
     247             : 
     248           0 : PathPreferenceSM::PathPreferenceSM(Agent *agent, const Peer *peer,
     249             :     AgentRoute *rt, bool is_dependent_route,
     250           0 :     const PathPreference &pref): agent_(agent), peer_(peer),
     251           0 :     rt_(rt), path_preference_(0, PathPreference::LOW, false, false),
     252           0 :     max_sequence_(0), timer_(NULL), timeout_(kMinInterval),
     253           0 :     flap_count_(0), is_dependent_rt_(is_dependent_route),
     254           0 :     dependent_rt_(this) {
     255           0 :     path_preference_ = pref;
     256           0 :     initiate();
     257           0 :     process_event(EvStart());
     258           0 :     backoff_timer_fired_time_ = UTCTimestampUsec();
     259           0 : }
     260             : 
     261           0 : PathPreferenceSM::~PathPreferenceSM() {
     262           0 :     if (timer_ != NULL) {
     263           0 :         timer_->Cancel();
     264           0 :         TimerManager::DeleteTimer(timer_);
     265             :     }
     266             : 
     267           0 :     PathDependencyList::iterator iter = dependent_routes_.begin();
     268           0 :     for (;iter != dependent_routes_.end(); iter++) {
     269           0 :         PathPreferenceSM *path_sm = iter.operator->();
     270           0 :         path_sm->process_event(EvWaitForTraffic());
     271             :     }
     272             : 
     273           0 :     timer_ = NULL;
     274           0 : }
     275             : 
     276           0 : bool PathPreferenceSM::Retry() {
     277           0 :     flap_count_ = 0;
     278           0 :     backoff_timer_fired_time_ = UTCTimestampUsec();
     279           0 :     process_event(EvWaitForTraffic());
     280           0 :     return false;
     281             : }
     282             : 
     283           0 : void PathPreferenceSM::StartRetryTimer() {
     284           0 :     if (timer_ == NULL) {
     285           0 :         timer_ = TimerManager::CreateTimer(
     286           0 :                 *(agent_->event_manager())->io_service(),
     287             :                 "Stale cleanup timer",
     288             :                 TaskScheduler::GetInstance()->GetTaskId("db::DBTable"),
     289             :                 0, false);
     290             :     }
     291           0 :     timer_->Start(timeout_,
     292             :                   boost::bind(&PathPreferenceSM::Retry, this));
     293           0 : }
     294             : 
     295           0 : void PathPreferenceSM::CancelRetryTimer() {
     296           0 :     if (timer_ == NULL) {
     297           0 :         return;
     298             :     }
     299           0 :     timer_->Cancel();
     300             : }
     301             : 
     302           0 : bool PathPreferenceSM::RetryTimerRunning() {
     303           0 :     if (timer_ == NULL) {
     304           0 :         return false;
     305             :     }
     306           0 :     return timer_->running();
     307             : }
     308             : 
     309           0 : void PathPreferenceSM::IncreaseRetryTimeout() {
     310           0 :     timeout_ = timeout_ * 2;
     311           0 :     if (timeout_ > kMaxInterval) {
     312           0 :         timeout_ = kMaxInterval;
     313             :     }
     314           0 : }
     315             : 
     316           0 : bool PathPreferenceSM::IsFlap() const {
     317           0 :     uint64_t time_sec = (UTCTimestampUsec() -
     318           0 :                          last_stable_high_priority_change_at_)/1000;
     319           0 :     if (time_sec > kMinInterval) {
     320           0 :         return false;
     321             :     }
     322           0 :     return true;
     323             : }
     324             : 
     325           0 : void PathPreferenceSM::DecreaseRetryTimeout() {
     326             :     uint64_t time_sec =
     327           0 :         (UTCTimestampUsec() - backoff_timer_fired_time_)/1000;
     328           0 :     if (time_sec > kMinInterval) {
     329           0 :         timeout_ = kMinInterval;
     330             :     }
     331           0 : }
     332             : 
     333           0 : void PathPreferenceSM::UpdateFlapTime() {
     334           0 :     if (IsFlap()) {
     335           0 :         flap_count_++;
     336             :     } else {
     337           0 :         DecreaseRetryTimeout();
     338           0 :         last_stable_high_priority_change_at_ = UTCTimestampUsec();
     339           0 :         flap_count_ = 0;
     340             :     }
     341           0 : }
     342             : 
     343           0 : bool PathPreferenceSM::IsPathFlapping() const {
     344           0 :     if (flap_count_ >= kMaxFlapCount && IsFlap()) {
     345           0 :         return true;
     346             :     }
     347           0 :     return false;
     348             : }
     349             : 
     350           0 : void PathPreferenceSM::UpdateDependentRoute() {
     351           0 :     if (is_dependent_rt_ == true) {
     352           0 :         return;
     353             :     }
     354             : 
     355           0 :     PathDependencyList::iterator iter = dependent_routes_.begin();
     356           0 :     for (;iter != dependent_routes_.end(); iter++) {
     357           0 :         PathPreferenceSM *path_sm = iter.operator->();
     358           0 :         if (path_preference_.preference() == PathPreference::HIGH) {
     359           0 :             path_sm->process_event(EvTrafficSeen());
     360             :         } else {
     361           0 :             path_sm->process_event(EvWaitForTraffic());
     362             :         }
     363             :     }
     364             : }
     365             : 
     366           0 : void PathPreferenceSM::Process() {
     367           0 :      uint32_t max_sequence = 0;
     368           0 :      const AgentPath *best_path = NULL;
     369           0 :      bool maciplearning_prefix = false;
     370           0 :      const AgentPath *local_path =  rt_->FindPath(peer_);
     371             :      //Dont act on notification of derived routes
     372           0 :      if (is_dependent_rt_) {
     373           0 :          path_preference_.set_ecmp(local_path->path_preference().ecmp());
     374           0 :          if (dependent_rt_.get()) {
     375           0 :              if (dependent_rt_->path_preference_.preference() ==
     376             :                      PathPreference::HIGH) {
     377           0 :                  process_event(EvTrafficSeen());
     378             :              } else {
     379           0 :                  process_event(EvWaitForTraffic());
     380             :              }
     381             :          }
     382           0 :          return;
     383             :      }
     384             : 
     385           0 :      if (local_path->path_preference().ecmp() == true) {
     386           0 :          path_preference_.set_ecmp(true);
     387             :          //If a path is ecmp, just set the priority to HIGH
     388           0 :          process_event(EvActiveActiveMode());
     389           0 :          return;
     390             :      }
     391             : 
     392           0 :      if (ecmp() == true) {
     393           0 :          path_preference_.set_ecmp(local_path->path_preference().ecmp());
     394             :          //Route transition from ECMP to non ECMP,
     395             :          //move to wait for traffic state
     396           0 :          process_event(EvWaitForTraffic());
     397           0 :          return;
     398             :      }
     399             : 
     400             :      //Check if BGP path is present
     401           0 :      for (Route::PathList::iterator it = rt_->GetPathList().begin();
     402           0 :           it != rt_->GetPathList().end(); ++it) {
     403             :          const AgentPath *path =
     404           0 :              static_cast<const AgentPath *>(it.operator->());
     405           0 :          if (path == local_path) {
     406           0 :              if (path->path_preference().sequence() < sequence()) {
     407           0 :                  EnqueuePathChange();
     408             :              }
     409           0 :              continue;
     410             :          }
     411             :          //Get best preference and sequence no from all BGP peer
     412           0 :          if (max_sequence < path->sequence()) {
     413           0 :              max_sequence = path->sequence();
     414           0 :              best_path = path;
     415             :          }
     416             :      }
     417             : 
     418           0 :      if (!best_path) {
     419           0 :          return;
     420             :      }
     421             : 
     422             :      //Skip seq number change for macip learning prefix inet rt path in waitfortraffic state to exclude stale paths
     423           0 :      if ( rt_->vrf() && rt_->vrf()->vn() && rt_->vrf()->vn()->mac_ip_learning_enable()) {
     424           0 :          MacIpLearningEntry *entry = NULL;
     425             :          const InetUnicastRouteEntry *inet_rt =
     426           0 :          dynamic_cast<const InetUnicastRouteEntry *>(rt_);
     427           0 :          if ( inet_rt != NULL) {
     428           0 :             MacIpLearningKey macip_entry_key(rt_->vrf()->vrf_id(), inet_rt->prefix_address());
     429           0 :             entry = agent_->mac_learning_proto()->
     430           0 :                 GetMacIpLearningTable()->Find(macip_entry_key);
     431             :          }
     432           0 :          if (entry != NULL && wait_for_traffic() ==true) {
     433           0 :              maciplearning_prefix = true;
     434           0 :              if (max_sequence > sequence()) {
     435           0 :                  Log("WaitForTraffic EvSeqChange skipped ");
     436             :              }
     437             :          }
     438             :      }
     439           0 :      if ((max_sequence > sequence()) && (maciplearning_prefix == false)) {
     440           0 :          process_event(EvSeqChange(max_sequence));
     441           0 :      } else if (sequence() == max_sequence &&
     442           0 :              best_path->ComputeNextHop(agent_) ==
     443           0 :              local_path->ComputeNextHop(agent_)) {
     444             :          //Control node chosen path and local path are same
     445           0 :          process_event(EvControlNodeInSync());
     446           0 :      } else if (sequence() == max_sequence &&
     447           0 :              best_path->ComputeNextHop(agent_) !=
     448           0 :              local_path->ComputeNextHop(agent_)) {
     449           0 :          process_event(EvWaitForTraffic());
     450             :      }
     451             : 
     452           0 :      UpdateDependentRoute();
     453             : }
     454             : 
     455           0 : void PathPreferenceSM::Log(std::string state) {
     456           0 :     std::string dependent_ip_str = "";
     457           0 :     if (is_dependent_rt()) {
     458           0 :         dependent_ip_str = dependent_ip().to_string();
     459             :     }
     460             : 
     461           0 :     PATH_PREFERENCE_TRACE(rt_->vrf()->GetName(), rt_->GetAddressString(),
     462             :                           preference(), sequence(), state, timeout(),
     463             :                           dependent_ip_str, flap_count_, max_sequence_);
     464           0 : }
     465             : 
     466           0 : void PathPreferenceSM::EnqueuePathChange() {
     467           0 :     DBRequest req(DBRequest::DB_ENTRY_ADD_CHANGE);
     468           0 :     req.key = rt_->GetDBRequestKey();
     469           0 :     AgentRouteKey *key = static_cast<AgentRouteKey *>(req.key.get());
     470           0 :     key->sub_op_ = AgentKey::RESYNC;
     471           0 :     key->set_peer(peer_);
     472           0 :     req.data.reset(new PathPreferenceData(path_preference_));
     473             : 
     474           0 :     if (rt_->vrf() == NULL) {
     475           0 :         return;
     476             :     }
     477             : 
     478           0 :     AgentRouteTable *table = NULL;
     479           0 :     if (rt_->GetTableType() == Agent::EVPN) {
     480           0 :         table = agent_->fabric_evpn_table();
     481           0 :     } else if (rt_->GetTableType() == Agent::INET4_UNICAST) {
     482           0 :         table = agent_->fabric_inet4_unicast_table();
     483           0 :     } else if (rt_->GetTableType() == Agent::INET4_MPLS) {
     484           0 :         table = agent_->fabric_inet4_mpls_table();
     485           0 :     } else if (rt_->GetTableType() == Agent::INET6_UNICAST) {
     486           0 :         table = agent_->fabric_inet4_unicast_table();
     487             :     }
     488             : 
     489           0 :     if (table) {
     490           0 :         table->Enqueue(&req);
     491             :     }
     492           0 : }
     493             : 
     494           0 : PathPreferenceIntfState::RouteAddrList::RouteAddrList() :
     495           0 :     family_(Address::INET), ip_(), plen_(0), vrf_name_(), seen_(false) {
     496           0 : }
     497             : 
     498           0 : PathPreferenceIntfState::RouteAddrList::RouteAddrList
     499             :     (const Address::Family &family, const IpAddress &ip, uint32_t plen,
     500           0 :      const std::string &vrf) :
     501           0 :     family_(family), ip_(ip), plen_(plen), vrf_name_(vrf), seen_(false) {
     502           0 : }
     503             : 
     504           0 : bool PathPreferenceIntfState::RouteAddrList::operator<(
     505             :         const RouteAddrList &rhs) const {
     506           0 :     if (family_ != rhs.family_) {
     507           0 :         return family_ < rhs.family_;
     508             :     }
     509             : 
     510           0 :     if (ip_ != rhs.ip_) {
     511           0 :         return ip_ < rhs.ip_;
     512             :     }
     513             : 
     514           0 :     if (plen_ != rhs.plen_) {
     515           0 :         return plen_ < rhs.plen_;
     516             :     }
     517             : 
     518           0 :     return vrf_name_ < rhs.vrf_name_;
     519             : }
     520             : 
     521           0 : bool PathPreferenceIntfState::RouteAddrList::operator==(
     522             :         const RouteAddrList &rhs) const {
     523           0 :     if ((family_ == rhs.family_) && (ip_ == rhs.ip_) &&
     524           0 :         (plen_ == rhs.plen_) && (vrf_name_ == rhs.vrf_name_)) {
     525           0 :         return true;
     526             :     }
     527           0 :     return false;
     528             : }
     529             : 
     530           0 : PathPreferenceIntfState::PathPreferenceIntfState(const VmInterface *intf):
     531           0 :     intf_(intf) {
     532           0 : }
     533             : 
     534           0 : PathPreferenceState::PathPreferenceState(Agent *agent,
     535           0 :     AgentRoute *rt): agent_(agent), rt_(rt) {
     536           0 : }
     537             : 
     538           0 : PathPreferenceState::~PathPreferenceState() {
     539             :     PeerPathPreferenceMap::iterator path_preference_it =
     540           0 :         path_preference_peer_map_.begin();
     541           0 :     while (path_preference_it != path_preference_peer_map_.end()) {
     542           0 :         PeerPathPreferenceMap::iterator prev_it = path_preference_it++;
     543           0 :         PathPreferenceSM *path_preference_sm = prev_it->second;
     544           0 :         delete path_preference_sm;
     545           0 :         path_preference_peer_map_.erase(prev_it);
     546             :     }
     547             : 
     548             :     PathPreferenceModule *path_module =
     549           0 :         agent_->oper_db()->route_preference_module();
     550           0 :     path_module->DeleteUnresolvedPath(this);
     551           0 : }
     552             : 
     553             : //Given a VRF table the table listener id for given route
     554             : bool
     555           0 : PathPreferenceState::GetRouteListenerId(const VrfEntry* vrf,
     556             :                                         const Agent::RouteTableType &table_type,
     557             :                                         DBTableBase::ListenerId &rt_id) const {
     558           0 :     if (vrf == NULL) {
     559           0 :         return false;
     560             :     }
     561             : 
     562             :     DBTableBase::ListenerId vrf_id =
     563           0 :         agent_->oper_db()->route_preference_module()->vrf_id();
     564             :     const PathPreferenceVrfState *vrf_state =
     565             :         static_cast<const PathPreferenceVrfState *>(
     566           0 :                 vrf->GetState(agent_->vrf_table(), vrf_id));
     567           0 :     if (!vrf_state) {
     568           0 :         return false;
     569             :     }
     570             : 
     571           0 :     rt_id = DBTableBase::kInvalidId;
     572           0 :     if (table_type == Agent::EVPN) {
     573           0 :         rt_id = vrf_state->evpn_rt_id_;
     574           0 :     } else if (table_type == Agent::INET4_UNICAST) {
     575           0 :         rt_id = vrf_state->uc_rt_id_;
     576           0 :     } else if (table_type == Agent::INET4_MPLS) {
     577           0 :         rt_id = vrf_state->mpls_rt_id_;
     578           0 :     } else if (table_type == Agent::INET6_UNICAST) {
     579           0 :         rt_id = vrf_state->uc6_rt_id_;
     580             :     } else {
     581           0 :         return false;
     582             :     }
     583             : 
     584           0 :     return true;
     585             : }
     586             : 
     587             : PathPreferenceSM*
     588           0 : PathPreferenceState::GetDependentPath(const AgentPath *path) const {
     589             : 
     590           0 :     if (path->path_preference().IsDependentRt() == false) {
     591           0 :         return NULL;
     592             :     }
     593           0 :     uint32_t plen = 32;
     594           0 :     if (path->path_preference().dependent_ip().is_v6()) {
     595           0 :         plen = 128;
     596             :     }
     597             : 
     598           0 :     InetUnicastRouteKey key(path->peer(), path->path_preference().vrf(),
     599           0 :                             path->path_preference().dependent_ip(), plen);
     600             :     const VrfEntry *vrf =
     601           0 :         agent_->vrf_table()->FindVrfFromName(path->path_preference().vrf());
     602           0 :     if (!vrf) {
     603           0 :         return NULL;
     604             :     }
     605             : 
     606           0 :     AgentRouteTable *table = NULL;
     607           0 :     Agent::RouteTableType table_type = Agent::INET4_UNICAST;
     608           0 :     if (path->path_preference().dependent_ip().is_v4()) {
     609             :         table = static_cast<AgentRouteTable *>(
     610           0 :                                  vrf->GetInet4UnicastRouteTable());
     611           0 :     } else if (path->path_preference().dependent_ip().is_v6()) {
     612             :         table = static_cast<AgentRouteTable *>(
     613           0 :                                  vrf->GetInet6UnicastRouteTable());
     614           0 :         table_type = Agent::INET6_UNICAST;
     615             :     }
     616           0 :     AgentRoute *rt = static_cast<AgentRoute *>(table->Find(&key));
     617           0 :     if (rt == NULL) {
     618           0 :         return NULL;
     619             :     }
     620             : 
     621           0 :     DBTableBase::ListenerId rt_id = DBTableBase::kInvalidId;
     622           0 :     GetRouteListenerId(vrf, table_type, rt_id);
     623             : 
     624             :     PathPreferenceState *state = static_cast<PathPreferenceState *>(
     625           0 :             rt->GetState(table, rt_id));
     626           0 :     if (state == NULL) {
     627           0 :         return NULL;
     628             :     }
     629           0 :     return state->GetSM(path->peer());
     630           0 : }
     631             : 
     632           0 : void PathPreferenceState::Process(bool &should_resolve) {
     633             :     PathPreferenceModule *path_module =
     634           0 :         agent_->oper_db()->route_preference_module();
     635             :     //Set all the path as not seen, eventually when path is seen
     636             :     //flag would be set appropriatly
     637             :      PeerPathPreferenceMap::iterator path_preference_it =
     638           0 :          path_preference_peer_map_.begin();
     639           0 :      while (path_preference_it != path_preference_peer_map_.end()) {
     640           0 :          PathPreferenceSM *path_preference_sm = path_preference_it->second;
     641           0 :          path_preference_sm->set_seen(false);
     642           0 :          path_preference_it++;
     643             :      }
     644             : 
     645           0 :      for (Route::PathList::iterator it = rt_->GetPathList().begin();
     646           0 :           it != rt_->GetPathList().end(); ++it) {
     647             :          const AgentPath *path =
     648           0 :              static_cast<const AgentPath *>(it.operator->());
     649           0 :          if (path->peer() == NULL) {
     650           0 :              continue;
     651             :          }
     652           0 :          if (path->peer()->GetType() != Peer::LOCAL_VM_PORT_PEER) {
     653           0 :              continue;
     654             :          }
     655             : 
     656           0 :          bool new_path_added = false;
     657             :          PathPreferenceSM *path_preference_sm;
     658           0 :          if (path_preference_peer_map_.find(path->peer()) ==
     659           0 :                  path_preference_peer_map_.end()) {
     660             :              //Add new path
     661           0 :              path_preference_sm =
     662           0 :                  new PathPreferenceSM(agent_, path->peer(), rt_,
     663           0 :                                       false, path->path_preference());
     664           0 :              path_preference_peer_map_.insert(
     665           0 :                 std::pair<const Peer *, PathPreferenceSM *>
     666           0 :                 (path->peer(), path_preference_sm));
     667           0 :              new_path_added = true;
     668             :          } else {
     669           0 :              path_preference_sm =
     670           0 :                  path_preference_peer_map_.find(path->peer())->second;
     671             :          }
     672           0 :          bool dependent_rt = path->path_preference().IsDependentRt();
     673           0 :          if (dependent_rt) {
     674           0 :              PathPreferenceSM *sm = GetDependentPath(path);
     675           0 :              if (sm == NULL) {
     676             :                  //Path is unresolved,
     677             :                  //add it to unresolved list
     678           0 :                  path_module->AddUnresolvedPath(this);
     679             :              } else {
     680           0 :                  path_module->DeleteUnresolvedPath(this);
     681             :              }
     682           0 :              path_preference_sm->set_dependent_rt(sm);
     683             :          } else {
     684           0 :              path_preference_sm->set_dependent_rt(NULL);
     685             :          }
     686           0 :          path_preference_sm->set_is_dependent_rt(dependent_rt);
     687           0 :          path_preference_sm->set_dependent_ip(
     688           0 :                  path->path_preference().dependent_ip());
     689             : 
     690           0 :          path_preference_sm->set_seen(true);
     691           0 :          path_preference_sm->Process();
     692             : 
     693           0 :          if (dependent_rt == false && new_path_added) {
     694           0 :              should_resolve = true;
     695             :          }
     696             :      }
     697             : 
     698             :      //Delete all path not seen, in latest path list
     699           0 :      path_preference_it = path_preference_peer_map_.begin();
     700           0 :      while (path_preference_it != path_preference_peer_map_.end()) {
     701           0 :          PeerPathPreferenceMap::iterator prev_it = path_preference_it++;
     702           0 :          PathPreferenceSM *path_preference_sm = prev_it->second;
     703           0 :          if (path_preference_sm->seen() == false) {
     704           0 :              delete path_preference_sm;
     705           0 :              path_preference_peer_map_.erase(prev_it);
     706             :          }
     707             :      }
     708           0 : }
     709             : 
     710           0 : PathPreferenceSM* PathPreferenceState::GetSM(const Peer *peer) {
     711           0 :     if (path_preference_peer_map_.find(peer) ==
     712           0 :             path_preference_peer_map_.end()) {
     713           0 :         return NULL;
     714             :     }
     715           0 :     return path_preference_peer_map_.find(peer)->second;
     716             : }
     717             : 
     718           0 : PathPreferenceRouteListener::PathPreferenceRouteListener(Agent *agent,
     719           0 :     AgentRouteTable *table): agent_(agent), rt_table_(table),
     720           0 :     id_(DBTableBase::kInvalidId), table_delete_ref_(this, table->deleter()),
     721           0 :     deleted_(false) {
     722             :     managed_delete_walk_ref_ = table->
     723           0 :         AllocWalker(boost::bind(&PathPreferenceRouteListener::DeleteState,
     724             :                                   this, _1, _2),
     725             :                     boost::bind(&PathPreferenceRouteListener::Walkdone, this,
     726           0 :                                 _1, _2, this));
     727           0 : }
     728             : 
     729           0 : void PathPreferenceRouteListener::Init() {
     730           0 :     id_ = rt_table_->Register(boost::bind(&PathPreferenceRouteListener::Notify,
     731             :                                           this,
     732             :                                           _1, _2));
     733           0 : }
     734             : 
     735           0 : void PathPreferenceRouteListener::Delete() {
     736           0 :     set_deleted();
     737             :     //Managed delete walk need to be done only once.
     738           0 :     if (managed_delete_walk_ref_.get()) {
     739           0 :         rt_table_->WalkAgain(managed_delete_walk_ref_);
     740             :     }
     741           0 : }
     742             : 
     743           0 : void PathPreferenceRouteListener::ManagedDelete() {
     744           0 :     Delete();
     745           0 : }
     746             : 
     747           0 : void PathPreferenceRouteListener::Walkdone(DBTable::DBTableWalkRef walk_ref,
     748             :                                        DBTableBase *partition,
     749             :                                        PathPreferenceRouteListener *state) {
     750           0 :     rt_table_->Unregister(id_);
     751           0 :     table_delete_ref_.Reset(NULL);
     752           0 :     if (walk_ref.get() != NULL)
     753           0 :         (static_cast<DBTable *>(partition))->ReleaseWalker(walk_ref);
     754           0 :     managed_delete_walk_ref_ = NULL;
     755           0 :     delete state;
     756           0 : }
     757             : 
     758           0 : bool PathPreferenceRouteListener::DeleteState(DBTablePartBase *partition,
     759             :                                               DBEntryBase *e) {
     760             :     PathPreferenceState *state =
     761           0 :         static_cast<PathPreferenceState *>(e->GetState(rt_table_, id_));
     762           0 :     if (state) {
     763           0 :         e->ClearState(rt_table_, id_);
     764           0 :         delete state;
     765             :     }
     766           0 :     return true;
     767             : }
     768             : 
     769           0 : void PathPreferenceRouteListener::Notify(DBTablePartBase *partition,
     770             :                                          DBEntryBase *e) {
     771             :     PathPreferenceState *state =
     772           0 :         static_cast<PathPreferenceState *>(e->GetState(rt_table_, id_));
     773           0 :     if (e->IsDeleted()) {
     774           0 :         if (state) {
     775           0 :             e->ClearState(rt_table_, id_);
     776           0 :             delete state;
     777             :         }
     778           0 :         return;
     779             :     }
     780             : 
     781           0 :     if (deleted_) return;
     782             : 
     783           0 :     AgentRoute *rt = static_cast<AgentRoute *>(e);
     784           0 :     for (Route::PathList::iterator it = rt->GetPathList().begin();
     785           0 :           it != rt->GetPathList().end(); ++it) {
     786             :         const AgentPath *path =
     787           0 :              static_cast<const AgentPath *>(it.operator->());
     788           0 :         if (path->peer() == NULL) {
     789           0 :             continue;
     790             :         }
     791           0 :         if (path->peer()->GetType() != Peer::LOCAL_VM_PORT_PEER) {
     792           0 :             continue;
     793             :         }
     794           0 :         if (path->path_preference().static_preference() == true) {
     795           0 :             return;
     796             :         }
     797             :     }
     798             : 
     799           0 :     if (!state) {
     800           0 :         state = new PathPreferenceState(agent_, rt);
     801             :     }
     802           0 :     bool should_resolve = false;
     803           0 :     state->Process(should_resolve);
     804           0 :     e->SetState(rt_table_, id_, state);
     805             : 
     806           0 :     if (should_resolve) {
     807             :         PathPreferenceModule *path_module =
     808           0 :                     agent_->oper_db()->route_preference_module();
     809           0 :         path_module->Resolve();
     810             :     }
     811             : }
     812             : 
     813           0 : PathPreferenceModule::PathPreferenceModule(Agent *agent):
     814           0 :     agent_(agent), vrf_id_(DBTableBase::kInvalidId),
     815           0 :     work_queue_(TaskScheduler::GetInstance()->GetTaskId("db::DBTable"), 0,
     816           0 :                 boost::bind(&PathPreferenceModule::DequeueEvent, this, _1)) {
     817           0 :     work_queue_.set_name("Path Preference");
     818           0 : }
     819             : 
     820           0 : bool PathPreferenceModule::DequeueEvent(PathPreferenceEventContainer event) {
     821             :     const Interface *intf =
     822           0 :         agent_->interface_table()->FindInterface(event.interface_index_);
     823           0 :     if (intf == NULL || (intf->type() != Interface::VM_INTERFACE)) {
     824           0 :         return true;
     825             :     }
     826             : 
     827           0 :     const VmInterface *vm_intf = static_cast<const VmInterface *>(intf);
     828             : 
     829             :     const VrfEntry *vrf =
     830           0 :         agent_->vrf_table()->FindVrfFromId(event.vrf_index_);
     831           0 :     if (vrf == NULL) {
     832           0 :         return true;
     833             :     }
     834             : 
     835             :     const PathPreferenceVrfState *state =
     836             :         static_cast<const PathPreferenceVrfState *>(
     837           0 :         vrf->GetState(agent_->vrf_table(), vrf_id_));
     838             : 
     839           0 :     if (!state) {
     840           0 :         return true;
     841             :     }
     842             : 
     843           0 :     PathPreferenceState *path_preference = NULL;
     844           0 :     PathPreferenceSM *path_preference_sm = NULL;
     845           0 :     const PathPreferenceState *cpath_preference = NULL;
     846             : 
     847             :     EvpnRouteKey evpn_key(NULL, vrf->GetName(),
     848           0 :                  event.mac_, event.ip_,
     849           0 :                  EvpnAgentRouteTable::ComputeHostIpPlen(event.ip_),
     850           0 :                  event.vxlan_id_);
     851             :     const EvpnRouteEntry *evpn_rt =
     852             :               static_cast<const EvpnRouteEntry *>(
     853           0 :               vrf->GetEvpnRouteTable()->FindActiveEntry(&evpn_key));
     854             : 
     855           0 :     if (evpn_rt) {
     856             :         cpath_preference = static_cast<const PathPreferenceState *>(
     857           0 :                                evpn_rt->GetState(vrf->GetEvpnRouteTable(),
     858           0 :                                state->evpn_rt_id_));
     859           0 :         if (cpath_preference) {
     860           0 :             path_preference = const_cast<PathPreferenceState *>(cpath_preference);
     861           0 :             path_preference_sm = path_preference->GetSM(vm_intf->peer());
     862           0 :             if (path_preference_sm) {
     863           0 :                 EvTrafficSeen ev;
     864           0 :                 path_preference_sm->process_event(ev);
     865           0 :             }
     866             :         }
     867             :     }
     868             : 
     869           0 :     EvpnRouteKey evpn_null_ip_key(NULL, vrf->GetName(), event.mac_,
     870           0 :                                   Ip4Address(0), 32, event.vxlan_id_);
     871             :     evpn_rt = static_cast<const EvpnRouteEntry *>(
     872           0 :               vrf->GetEvpnRouteTable()->FindActiveEntry(&evpn_null_ip_key));
     873           0 :     if (evpn_rt) {
     874             :         cpath_preference = static_cast<const PathPreferenceState *>(
     875           0 :                                evpn_rt->GetState(vrf->GetEvpnRouteTable(),
     876           0 :                                state->evpn_rt_id_));
     877           0 :         if (cpath_preference) {
     878           0 :             path_preference = const_cast<PathPreferenceState *>(cpath_preference);
     879           0 :             path_preference_sm = path_preference->GetSM(vm_intf->peer());
     880           0 :             if (path_preference_sm) {
     881           0 :                 EvTrafficSeen ev;
     882           0 :                 path_preference_sm->process_event(ev);
     883           0 :             }
     884             :         }
     885             :     }
     886             : 
     887           0 :     InetUnicastRouteKey rt_key(NULL, vrf->GetName(), event.ip_, event.plen_);
     888           0 :     const InetUnicastRouteEntry *rt = NULL;
     889           0 :     if (event.ip_.is_v4()) {
     890             :         rt = static_cast<const InetUnicastRouteEntry *>(
     891           0 :             vrf->GetInet4UnicastRouteTable()->FindActiveEntry(&rt_key));
     892           0 :     } else if(event.ip_.is_v6()) {
     893             :         rt = static_cast<const InetUnicastRouteEntry *>(
     894           0 :             vrf->GetInet6UnicastRouteTable()->FindActiveEntry(&rt_key));
     895             :     }
     896           0 :     if (!rt) {
     897           0 :         return true;
     898             :     }
     899             : 
     900           0 :     if (event.ip_.is_v4()) {
     901             :         cpath_preference = static_cast<const PathPreferenceState *>(
     902           0 :             rt->GetState(vrf->GetInet4UnicastRouteTable(), state->uc_rt_id_));
     903           0 :     } else if(event.ip_.is_v6()) {
     904             :         cpath_preference = static_cast<const PathPreferenceState *>(
     905           0 :             rt->GetState(vrf->GetInet6UnicastRouteTable(), state->uc6_rt_id_));
     906             :     }
     907           0 :     if (!cpath_preference) {
     908           0 :         return true;
     909             :     }
     910             : 
     911           0 :     path_preference = const_cast<PathPreferenceState *>(cpath_preference);
     912           0 :     path_preference_sm = path_preference->GetSM(vm_intf->peer());
     913           0 :     if (path_preference_sm) {
     914           0 :         EvTrafficSeen ev;
     915           0 :         path_preference_sm->process_event(ev);
     916           0 :     }
     917           0 :     return true;
     918           0 : }
     919             : 
     920           0 : void PathPreferenceModule::EnqueueTrafficSeen(IpAddress ip, uint32_t plen,
     921             :                                               uint32_t interface_index,
     922             :                                               uint32_t vrf_index,
     923             :                                               const MacAddress &mac) {
     924             :     const Interface *intf =
     925           0 :         agent_->interface_table()->FindInterface(interface_index);
     926           0 :     if (intf == NULL || (intf->type() != Interface::VM_INTERFACE)) {
     927           0 :         return;
     928             :     }
     929             : 
     930           0 :     const VmInterface *vm_intf = static_cast<const VmInterface *>(intf);
     931             : 
     932             : 
     933             :     //If the local preference is set by config, we dont identify Active
     934             :     //node dynamically
     935           0 :     if (vm_intf->local_preference() != 0) {
     936           0 :         return;
     937             :     }
     938             : 
     939           0 :     const VrfEntry *vrf = agent_->vrf_table()->FindVrfFromId(vrf_index);
     940           0 :     if (vrf == NULL) {
     941           0 :         return;
     942             :     }
     943             : 
     944           0 :     if (vrf == vm_intf->forwarding_vrf()) {
     945           0 :         vrf = vm_intf->vrf();
     946             :     }
     947             : 
     948           0 :     InetUnicastRouteEntry *rt = vrf->GetUcRoute(ip);
     949             :     EvpnRouteKey key(vm_intf->peer(), vrf->GetName(), mac, ip,
     950             :                      EvpnAgentRouteTable::ComputeHostIpPlen(ip),
     951           0 :                      vm_intf->ethernet_tag());
     952             :     EvpnRouteEntry *evpn_rt = static_cast<EvpnRouteEntry *>(
     953           0 :         vrf->GetEvpnRouteTable()->FindActiveEntry(&key));
     954           0 :     if (!rt && !evpn_rt) {
     955           0 :         return;
     956             :     }
     957             : 
     958           0 :     const AgentPath *path = NULL;
     959           0 :     const AgentPath *evpn_path = NULL;
     960             : 
     961           0 :     if (rt) {
     962           0 :         path = rt->FindPath(vm_intf->peer());
     963             :     }
     964           0 :     if (evpn_rt) {
     965           0 :         evpn_path = evpn_rt->FindPath(vm_intf->peer());
     966             :     }
     967             : 
     968           0 :     if (!path && !evpn_path) {
     969           0 :         return;
     970             :     }
     971             : 
     972           0 :     PathPreferenceEventContainer event;
     973           0 :     if (rt) {
     974           0 :         event.ip_ = rt->prefix_address();
     975           0 :         event.plen_ = rt->prefix_length();
     976             :     } else {
     977             :         // (0 IP + Mac) event required for EVPN
     978           0 :         event.ip_ = IpAddress();
     979           0 :         event.plen_ = 32;
     980             :     }
     981           0 :     event.interface_index_ = interface_index;
     982           0 :     event.vrf_index_ = vrf_index;
     983           0 :     event.mac_ = mac;
     984           0 :     event.vxlan_id_ = vm_intf->ethernet_tag();
     985           0 :     work_queue_.Enqueue(event);
     986             : 
     987           0 :     if (vm_intf->forwarding_vrf() != vm_intf->vrf() &&
     988           0 :         vm_intf->forwarding_vrf()->vrf_id() == vrf_index) {
     989           0 :         event.vrf_index_ = vm_intf->vrf()->vrf_id();
     990           0 :         work_queue_.Enqueue(event);
     991             :     }
     992           0 : }
     993             : 
     994           0 : void PathPreferenceModule::VrfNotify(DBTablePartBase *partition,
     995             :                                      DBEntryBase *e) {
     996           0 :    const VrfEntry *vrf = static_cast<const VrfEntry *>(e);
     997             :    PathPreferenceVrfState *vrf_state =
     998           0 :        static_cast<PathPreferenceVrfState *>(e->GetState(partition->parent(),
     999             :                                                           vrf_id_));
    1000             : 
    1001           0 :    if (vrf->IsDeleted()) {
    1002           0 :        if (vrf_state) {
    1003           0 :            e->ClearState(partition->parent(), vrf_id_);
    1004           0 :            delete vrf_state;
    1005             :        }
    1006           0 :        return;
    1007             :    }
    1008             : 
    1009           0 :    if (vrf_state) {
    1010           0 :        return;
    1011             :    }
    1012             : 
    1013             :    PathPreferenceRouteListener *uc_rt_listener =
    1014             :        new PathPreferenceRouteListener(agent_,
    1015           0 :                                        vrf->GetInet4UnicastRouteTable());
    1016           0 :    uc_rt_listener->Init();
    1017             : 
    1018             :    PathPreferenceRouteListener *evpn_rt_listener =
    1019             :        new PathPreferenceRouteListener(agent_,
    1020           0 :                                        vrf->GetEvpnRouteTable());
    1021           0 :    evpn_rt_listener->Init();
    1022             : 
    1023             :    PathPreferenceRouteListener *uc6_rt_listener =
    1024             :        new PathPreferenceRouteListener(agent_,
    1025           0 :                                        vrf->GetInet6UnicastRouteTable());
    1026           0 :    uc6_rt_listener->Init();
    1027             :    PathPreferenceRouteListener *mpls_rt_listener =
    1028             :        new PathPreferenceRouteListener(agent_,
    1029           0 :                                        vrf->GetInet4MplsUnicastRouteTable());
    1030           0 :    mpls_rt_listener->Init();
    1031             : 
    1032           0 :    vrf_state = new PathPreferenceVrfState(uc_rt_listener->id(),
    1033           0 :                                           evpn_rt_listener->id(),
    1034           0 :                                           uc6_rt_listener->id(),
    1035           0 :                                           mpls_rt_listener->id());
    1036             : 
    1037           0 :    e->SetState(partition->parent(), vrf_id_, vrf_state);
    1038           0 :    return;
    1039             : }
    1040             : 
    1041           0 : void PathPreferenceModule::AddUnresolvedPath(PathPreferenceState *sm) {
    1042           0 :     unresolved_paths_.insert(sm);
    1043           0 : }
    1044             : 
    1045           0 : void PathPreferenceModule::DeleteUnresolvedPath(PathPreferenceState *sm) {
    1046           0 :     std::set<PathPreferenceState *>::iterator it = unresolved_paths_.find(sm);
    1047           0 :     if (it != unresolved_paths_.end()) {
    1048           0 :         unresolved_paths_.erase(it);
    1049             :     }
    1050           0 : }
    1051             : 
    1052           0 : void PathPreferenceModule::Resolve() {
    1053           0 :     std::set<PathPreferenceState *> tmp = unresolved_paths_;
    1054           0 :     unresolved_paths_.clear();
    1055             : 
    1056           0 :     bool resolve_path = false;
    1057             :     //Process all the elements
    1058           0 :     std::set<PathPreferenceState *>::iterator it = tmp.begin();
    1059           0 :     for(; it != tmp.end(); it++) {
    1060           0 :         (*it)->Process(resolve_path);
    1061             :     }
    1062           0 : }
    1063             : 
    1064           0 : void PathPreferenceModule::Init() {
    1065           0 :     vrf_id_ = agent_->vrf_table()->Register(
    1066             :                   boost::bind(&PathPreferenceModule::VrfNotify, this, _1, _2));
    1067           0 : }
    1068             : 
    1069           0 : void PathPreferenceModule::Shutdown() {
    1070           0 :     agent_->vrf_table()->Unregister(vrf_id_);
    1071           0 : }

Generated by: LCOV version 1.14