3 * Copyright 2018 gRPC authors.
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
19 #ifndef GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_LB_POLICY_XDS_XDS_LOAD_BALANCER_API_H
20 #define GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_LB_POLICY_XDS_XDS_LOAD_BALANCER_API_H
22 #include <grpc/support/port_platform.h>
24 #include <grpc/slice_buffer.h>
26 #include "src/core/ext/filters/client_channel/lb_policy/xds/xds_client_stats.h"
27 #include "src/core/ext/filters/client_channel/server_address.h"
31 struct XdsLocalityInfo {
32 bool operator==(const XdsLocalityInfo& other) const {
33 return *locality_name == *other.locality_name &&
34 serverlist == other.serverlist && lb_weight == other.lb_weight &&
35 priority == other.priority;
38 // This comparator only compares the locality names.
40 bool operator()(const XdsLocalityInfo& lhs,
41 const XdsLocalityInfo& rhs) const {
42 return XdsLocalityName::Less()(lhs.locality_name, rhs.locality_name);
46 RefCountedPtr<XdsLocalityName> locality_name;
47 ServerAddressList serverlist;
52 using XdsLocalityList = InlinedVector<XdsLocalityInfo, 1>;
54 // There are two phases of accessing this class's content:
55 // 1. to initialize in the control plane combiner;
56 // 2. to use in the data plane combiner.
57 // So no additional synchronization is needed.
58 class XdsDropConfig : public RefCounted<XdsDropConfig> {
61 bool operator==(const DropCategory& other) const {
62 return strcmp(name.get(), other.name.get()) == 0 &&
63 parts_per_million == other.parts_per_million;
67 const uint32_t parts_per_million;
70 using DropCategoryList = InlinedVector<DropCategory, 2>;
72 void AddCategory(UniquePtr<char> name, uint32_t parts_per_million) {
73 drop_category_list_.emplace_back(
74 DropCategory{std::move(name), parts_per_million});
77 // The only method invoked from the data plane combiner.
78 bool ShouldDrop(const UniquePtr<char>** category_name) const;
80 const DropCategoryList& drop_category_list() const {
81 return drop_category_list_;
84 bool operator==(const XdsDropConfig& other) const {
85 return drop_category_list_ == other.drop_category_list_;
87 bool operator!=(const XdsDropConfig& other) const {
88 return !(*this == other);
92 DropCategoryList drop_category_list_;
96 XdsLocalityList locality_list;
97 RefCountedPtr<XdsDropConfig> drop_config;
98 bool drop_all = false;
101 // Creates an EDS request querying \a service_name.
102 grpc_slice XdsEdsRequestCreateAndEncode(const char* service_name);
104 // Parses the EDS response and returns the args to update locality map. If there
105 // is any error, the output update is invalid.
106 grpc_error* XdsEdsResponseDecodeAndParse(const grpc_slice& encoded_response,
109 // Creates an LRS request querying \a server_name.
110 grpc_slice XdsLrsRequestCreateAndEncode(const char* server_name);
112 // Creates an LRS request sending client-side load reports. If all the counters
113 // in \a client_stats are zero, returns empty slice.
114 grpc_slice XdsLrsRequestCreateAndEncode(const char* server_name,
115 XdsClientStats* client_stats);
117 // Parses the LRS response and returns the client-side load reporting interval.
118 // If there is any error (e.g., the found server name doesn't match \a
119 // expected_server_name), the output config is invalid.
120 grpc_error* XdsLrsResponseDecodeAndParse(const grpc_slice& encoded_response,
121 grpc_millis* load_reporting_interval,
122 const char* expected_server_name);
124 } // namespace grpc_core
126 #endif /* GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_LB_POLICY_XDS_XDS_LOAD_BALANCER_API_H \