1
#pragma once
2

            
3
#include "envoy/extensions/load_balancing_policies/round_robin/v3/round_robin.pb.h"
4
#include "envoy/extensions/load_balancing_policies/round_robin/v3/round_robin.pb.validate.h"
5
#include "envoy/upstream/load_balancer.h"
6

            
7
#include "source/common/common/logger.h"
8
#include "source/extensions/load_balancing_policies/common/factory_base.h"
9
#include "source/extensions/load_balancing_policies/round_robin/round_robin_lb.h"
10

            
11
namespace Envoy {
12
namespace Extensions {
13
namespace LoadBalancingPolicies {
14
namespace RoundRobin {
15

            
16
using RoundRobinLbProto = envoy::extensions::load_balancing_policies::round_robin::v3::RoundRobin;
17
using ClusterProto = envoy::config::cluster::v3::Cluster;
18

            
19
struct RoundRobinCreator : public Logger::Loggable<Logger::Id::upstream> {
20
  Upstream::LoadBalancerPtr operator()(Upstream::LoadBalancerParams params,
21
                                       OptRef<const Upstream::LoadBalancerConfig> lb_config,
22
                                       const Upstream::ClusterInfo& cluster_info,
23
                                       const Upstream::PrioritySet& priority_set,
24
                                       Runtime::Loader& runtime, Random::RandomGenerator& random,
25
                                       TimeSource& time_source);
26
};
27

            
28
class Factory : public Common::FactoryBase<RoundRobinLbProto, RoundRobinCreator> {
29
public:
30
1305
  Factory() : FactoryBase("envoy.load_balancing_policies.round_robin") {}
31

            
32
  absl::StatusOr<Upstream::LoadBalancerConfigPtr>
33
  loadConfig(Server::Configuration::ServerFactoryContext&,
34
111
             const Protobuf::Message& config) override {
35
111
    ASSERT(dynamic_cast<const RoundRobinLbProto*>(&config) != nullptr);
36
111
    const RoundRobinLbProto& typed_config = dynamic_cast<const RoundRobinLbProto&>(config);
37
111
    return Upstream::LoadBalancerConfigPtr{new Upstream::TypedRoundRobinLbConfig(typed_config)};
38
111
  }
39

            
40
  absl::StatusOr<Upstream::LoadBalancerConfigPtr>
41
12178
  loadLegacy(Server::Configuration::ServerFactoryContext&, const ClusterProto& cluster) override {
42
12178
    return Upstream::LoadBalancerConfigPtr{new Upstream::TypedRoundRobinLbConfig(
43
12178
        cluster.common_lb_config(), cluster.round_robin_lb_config())};
44
12178
  }
45
};
46

            
47
DECLARE_FACTORY(Factory);
48

            
49
} // namespace RoundRobin
50
} // namespace LoadBalancingPolicies
51
} // namespace Extensions
52
} // namespace Envoy