| 127 | } |
| 128 | |
| 129 | void |
| 130 | NextHopStrategyFactory::createStrategy(const std::string &name, const NHPolicyType policy_type, ts::Yaml::Map &node) |
| 131 | { |
| 132 | std::shared_ptr<NextHopSelectionStrategy> strat; |
| 133 | std::shared_ptr<NextHopRoundRobin> strat_rr; |
| 134 | std::shared_ptr<NextHopConsistentHash> strat_chash; |
| 135 | |
| 136 | strat = strategyInstance(name.c_str()); |
| 137 | if (strat != nullptr) { |
| 138 | NH_Note("A strategy named '%s' has already been loaded and another will not be created.", name.data()); |
| 139 | node.bad(); |
| 140 | return; |
| 141 | } |
| 142 | |
| 143 | try { |
| 144 | switch (policy_type) { |
| 145 | case NH_FIRST_LIVE: |
| 146 | case NH_RR_STRICT: |
| 147 | case NH_RR_IP: |
| 148 | case NH_RR_LATCHED: |
| 149 | strat_rr = std::make_shared<NextHopRoundRobin>(name, policy_type, node); |
| 150 | _strategies.emplace(std::make_pair(std::string(name), strat_rr)); |
| 151 | break; |
| 152 | case NH_CONSISTENT_HASH: |
| 153 | strat_chash = std::make_shared<NextHopConsistentHash>(name, policy_type, node); |
| 154 | _strategies.emplace(std::make_pair(std::string(name), strat_chash)); |
| 155 | break; |
| 156 | default: // handles P_UNDEFINED, no strategy is added |
| 157 | break; |
| 158 | }; |
| 159 | } catch (std::exception &ex) { |
| 160 | strat.reset(); |
| 161 | } |
| 162 | } |
| 163 | |
| 164 | std::shared_ptr<NextHopSelectionStrategy> |
| 165 | NextHopStrategyFactory::strategyInstance(const char *name) |