• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 //
3 // Copyright 2016 gRPC authors.
4 //
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
8 //
9 //     http://www.apache.org/licenses/LICENSE-2.0
10 //
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.
16 //
17 //
18 
19 #ifndef GRPC_SRC_CORE_LOAD_BALANCING_GRPCLB_LOAD_BALANCER_API_H
20 #define GRPC_SRC_CORE_LOAD_BALANCING_GRPCLB_LOAD_BALANCER_API_H
21 #include <grpc/slice.h>
22 #include <grpc/support/port_platform.h>
23 #include <stdint.h>
24 
25 #include <vector>
26 
27 #include "absl/strings/string_view.h"
28 #include "src/core/load_balancing/grpclb/grpclb_client_stats.h"
29 #include "src/core/util/time.h"
30 #include "upb/mem/arena.h"
31 
32 #define GRPC_GRPCLB_SERVICE_NAME_MAX_LENGTH 128
33 #define GRPC_GRPCLB_SERVER_IP_ADDRESS_MAX_SIZE 16
34 #define GRPC_GRPCLB_SERVER_LOAD_BALANCE_TOKEN_MAX_SIZE 50
35 
36 namespace grpc_core {
37 
38 // Contains server information. When the drop field is not true, use the other
39 // fields.
40 struct GrpcLbServer {
41   int32_t ip_size;
42   char ip_addr[GRPC_GRPCLB_SERVER_IP_ADDRESS_MAX_SIZE];
43   int32_t port;
44   char load_balance_token[GRPC_GRPCLB_SERVER_LOAD_BALANCE_TOKEN_MAX_SIZE];
45   bool drop;
46 
47   bool operator==(const GrpcLbServer& other) const;
48 };
49 
50 struct GrpcLbResponse {
51   enum { INITIAL, SERVERLIST, FALLBACK } type;
52   Duration client_stats_report_interval;
53   std::vector<GrpcLbServer> serverlist;
54 };
55 
56 // Creates a serialized grpclb request.
57 grpc_slice GrpcLbRequestCreate(absl::string_view lb_service_name,
58                                upb_Arena* arena);
59 
60 // Creates a serialized grpclb load report request.
61 grpc_slice GrpcLbLoadReportRequestCreate(
62     int64_t num_calls_started, int64_t num_calls_finished,
63     int64_t num_calls_finished_with_client_failed_to_send,
64     int64_t num_calls_finished_known_received,
65     const GrpcLbClientStats::DroppedCallCounts* drop_token_counts,
66     upb_Arena* arena);
67 
68 // Deserialize a grpclb response.
69 bool GrpcLbResponseParse(const grpc_slice& serialized_response,
70                          upb_Arena* arena, GrpcLbResponse* result);
71 
72 }  // namespace grpc_core
73 
74 #endif  // GRPC_SRC_CORE_LOAD_BALANCING_GRPCLB_LOAD_BALANCER_API_H
75