• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // Copyright 2020 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_CORE_EXT_FILTERS_CLIENT_CHANNEL_LB_POLICY_ADDRESS_FILTERING_H
18 #define GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_LB_POLICY_ADDRESS_FILTERING_H
19 
20 #include <grpc/support/port_platform.h>
21 
22 #include <map>
23 #include <string>
24 #include <vector>
25 
26 #include "src/core/ext/filters/client_channel/server_address.h"
27 
28 // The resolver returns a flat list of addresses.  When a hierarchy of
29 // LB policies is in use, each leaf of the hierarchy will need a
30 // different subset of those addresses.  This library provides a
31 // mechanism for determining which address is passed to which leaf
32 // policy.
33 //
34 // Each address will have an associated path that indicates which child
35 // it should be sent to at each level of the hierarchy to wind up at the
36 // right leaf policy.  Each LB policy will look at the first element of
37 // the path of each address to determine which child to send the address
38 // to.  It will then remove that first element when passing the address
39 // down to its child.
40 //
41 // For example, consider the following LB policy hierarchy:
42 //
43 // - priority
44 //   - child0 (weighted_target)
45 //     - localityA (round_robin)
46 //     - localityB (round_robin)
47 //   - child1 (weighted_target)
48 //     - localityC (round_robin)
49 //     - localityD (round_robin)
50 //
51 // Now consider the following addresses:
52 // - 10.0.0.1:80 path=["child0", "localityA"]
53 // - 10.0.0.2:80 path=["child0", "localityB"]
54 // - 10.0.0.3:80 path=["child1", "localityC"]
55 // - 10.0.0.4:80 path=["child1", "localityD"]
56 //
57 // The priority policy will split this up into two lists, one for each
58 // of its children:
59 // - child0:
60 //   - 10.0.0.1:80 path=["localityA"]
61 //   - 10.0.0.2:80 path=["localityB"]
62 // - child1:
63 //   - 10.0.0.3:80 path=["localityC"]
64 //   - 10.0.0.4:80 path=["localityD"]
65 //
66 // The weighted_target policy for child0 will split its list up into two
67 // lists, one for each of its children:
68 // - localityA:
69 //   - 10.0.0.1:80 path=[]
70 // - localityB:
71 //   - 10.0.0.2:80 path=[]
72 //
73 // Similarly, the weighted_target policy for child1 will split its list
74 // up into two lists, one for each of its children:
75 // - localityC:
76 //   - 10.0.0.3:80 path=[]
77 // - localityD:
78 //   - 10.0.0.4:80 path=[]
79 
80 namespace grpc_core {
81 
82 // The attribute key to be used for hierarchical paths in ServerAddress.
83 extern const char* kHierarchicalPathAttributeKey;
84 
85 // Constructs an address attribute containing the hierarchical path
86 // to be associated with the address.
87 std::unique_ptr<ServerAddress::AttributeInterface>
88 MakeHierarchicalPathAttribute(std::vector<std::string> path);
89 
90 // A map from the next path element to the addresses that fall under
91 // that path element.
92 using HierarchicalAddressMap = std::map<std::string, ServerAddressList>;
93 
94 // Splits up the addresses into a separate list for each child.
95 HierarchicalAddressMap MakeHierarchicalAddressMap(
96     const ServerAddressList& addresses);
97 
98 }  // namespace grpc_core
99 
100 #endif /* GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_LB_POLICY_ADDRESS_FILTERING_H \
101         */
102