1 //
2 // Copyright 2018 gRPC authors.
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 //     http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16 
17 #ifndef GRPC_SRC_CORE_EXT_FILTERS_CLIENT_CHANNEL_LB_POLICY_XDS_XDS_ATTRIBUTES_H
18 #define GRPC_SRC_CORE_EXT_FILTERS_CLIENT_CHANNEL_LB_POLICY_XDS_XDS_ATTRIBUTES_H
19 
20 #include <grpc/support/port_platform.h>
21 
22 #include <stdint.h>
23 
24 #include <memory>
25 #include <string>
26 #include <utility>
27 
28 #include "src/core/ext/xds/xds_client_stats.h"
29 #include "src/core/lib/gprpp/ref_counted_ptr.h"
30 #include "src/core/lib/resolver/server_address.h"
31 
32 namespace grpc_core {
33 
34 extern const char* kXdsLocalityNameAttributeKey;
35 
36 class XdsLocalityAttribute : public ServerAddress::AttributeInterface {
37  public:
XdsLocalityAttribute(RefCountedPtr<XdsLocalityName> locality_name,uint32_t weight)38   XdsLocalityAttribute(RefCountedPtr<XdsLocalityName> locality_name,
39                        uint32_t weight)
40       : locality_name_(std::move(locality_name)), weight_(weight) {}
41 
locality_name()42   RefCountedPtr<XdsLocalityName> locality_name() const {
43     return locality_name_;
44   }
45 
weight()46   uint32_t weight() const { return weight_; }
47 
Copy()48   std::unique_ptr<AttributeInterface> Copy() const override {
49     return std::make_unique<XdsLocalityAttribute>(locality_name_->Ref(),
50                                                   weight_);
51   }
52 
53   int Cmp(const AttributeInterface* other) const override;
54 
55   std::string ToString() const override;
56 
57  private:
58   RefCountedPtr<XdsLocalityName> locality_name_;
59   uint32_t weight_;
60 };
61 
62 }  // namespace grpc_core
63 
64 #endif  // GRPC_SRC_CORE_EXT_FILTERS_CLIENT_CHANNEL_LB_POLICY_XDS_XDS_ATTRIBUTES_H
65