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: 380 610 62.3 %
Date: 2026-06-08 02:02:55 Functions: 42 70 60.0 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.14