1
#pragma once
2

            
3
#include <memory>
4

            
5
#include "envoy/common/pure.h"
6
#include "envoy/common/time.h"
7
#include "envoy/config/route/v3/route.pb.h"
8
#include "envoy/rds/route_config_update_receiver.h"
9
#include "envoy/service/discovery/v3/discovery.pb.h"
10

            
11
#include "source/common/protobuf/protobuf.h"
12

            
13
#include "absl/types/optional.h"
14

            
15
namespace Envoy {
16
namespace Router {
17

            
18
/**
19
 * A primitive that keeps track of updates to a RouteConfiguration.
20
 */
21
class RouteConfigUpdateReceiver : public Rds::RouteConfigUpdateReceiver {
22
public:
23
  /**
24
   * Same purpose as Rds::RouteConfigUpdateReceiver::protobufConfiguration()
25
   * but the return is downcasted to proper type.
26
   * @return current RouteConfiguration downcasted from Protobuf::Message&
27
   */
28
  virtual const envoy::config::route::v3::RouteConfiguration&
29
  protobufConfigurationCast() const PURE;
30

            
31
  using VirtualHostRefVector =
32
      std::vector<std::reference_wrapper<const envoy::config::route::v3::VirtualHost>>;
33

            
34
  /**
35
   * Called on updates via VHDS.
36
   * @param added_vhosts supplies VirtualHosts that have been added.
37
   * @param added_resource_ids set of resources IDs (names + aliases) added.
38
   * @param removed_resources supplies names of VirtualHosts that have been removed.
39
   * @param version_info supplies RouteConfiguration version.
40
   * @return bool whether RouteConfiguration has been updated.
41
   */
42
  virtual bool onVhdsUpdate(const VirtualHostRefVector& added_vhosts,
43
                            std::set<std::string>&& added_resource_ids,
44
                            const Protobuf::RepeatedPtrField<std::string>& removed_resources,
45
                            const std::string& version_info) PURE;
46

            
47
  /**
48
   * @return bool return whether VHDS configuration has been changed in the last RDS update.
49
   */
50
  // TODO(dmitri-d): Consider splitting RouteConfigUpdateReceiver into a RouteConfig state and a
51
  // last update state. The latter could be passed to callbacks as a parameter, which would make the
52
  // intent and the lifecycle of the "last update state" less muddled.
53
  virtual bool vhdsConfigurationChanged() const PURE;
54

            
55
  /**
56
   * @return the union of all resource names and aliases (if any) received with the last VHDS
57
   * update.
58
   */
59
  virtual const std::set<std::string>& resourceIdsInLastVhdsUpdate() PURE;
60
};
61

            
62
using RouteConfigUpdatePtr = std::unique_ptr<RouteConfigUpdateReceiver>;
63
} // namespace Router
64
} // namespace Envoy