OpenSDN source code
diag_proto.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
3  * Copyright Contributors to the OpenSDN project
4  */
5 
6 #ifndef vnsw_agent_diag_proto_hpp
7 #define vnsw_agent_diag_proto_hpp
8 
9 #include <mutex>
10 
11 #include <pkt/pkt_handler.h>
12 #include <pkt/proto.h>
13 #include <pkt/proto_handler.h>
14 #include <oper/health_check.h>
15 
17 class SegmentHealthCheckPktStatsResp;
18 
19 class DiagProto : public Proto {
20 public:
21  // map from interface id to segment health check service packet object
22  typedef std::map<uint32_t, SegmentHealthCheckPkt *> SessionMap;
23  typedef std::pair<uint32_t, SegmentHealthCheckPkt *> SessionPair;
24 
30  };
31 
32  struct DiagStats {
33  uint64_t requests_sent;
35  uint64_t replies_sent;
36  uint64_t replies_received;
37  DiagStats() { Reset(); }
38  void Reset() {
40  replies_received = 0;
41  }
42  };
43  typedef std::map<uint32_t, DiagStats> DiagStatsMap;
44  typedef std::pair<uint32_t, DiagStats> DiagStatsPair;
45 
46  DiagProto(Agent *agent, boost::asio::io_context &io);
47  virtual ~DiagProto() {}
48 
49  ProtoHandler *AllocProtoHandler(boost::shared_ptr<PktInfo> info,
50  boost::asio::io_context &io);
54  void IncrementDiagStats(uint32_t itf_id, DiagStatsType type);
55  const DiagStatsMap &stats() const { return stats_; }
56  void FillSandeshHealthCheckResponse(SegmentHealthCheckPktStatsResp *resp);
57 
58 private:
60  /* lock for stats_ field for access between
61  * health-check (which sends first health check packet),
62  * timer-task (which sends periodic health check packets),
63  * Diag task (which receives health-check requests/replies and sends
64  * health-check replies)
65  * Introspect (which reads stats for filling introspect response)
66  */
67  std::mutex stats_mutex_;
70 };
71 
72 #endif
Definition: agent.h:361
DiagProto(Agent *agent, boost::asio::io_context &io)
Definition: diag_proto.cc:17
std::pair< uint32_t, DiagStats > DiagStatsPair
Definition: diag_proto.h:44
std::pair< uint32_t, SegmentHealthCheckPkt * > SessionPair
Definition: diag_proto.h:23
std::map< uint32_t, SegmentHealthCheckPkt * > SessionMap
Definition: diag_proto.h:22
DISALLOW_COPY_AND_ASSIGN(DiagProto)
std::map< uint32_t, DiagStats > DiagStatsMap
Definition: diag_proto.h:43
bool SegmentHealthCheckProcess(HealthCheckTable::HealthCheckServiceAction action, HealthCheckInstanceService *service)
Definition: diag_proto.cc:30
const DiagStatsMap & stats() const
Definition: diag_proto.h:55
@ REPLIES_SENT
Definition: diag_proto.h:28
@ REQUESTS_SENT
Definition: diag_proto.h:26
@ REQUESTS_RECEIVED
Definition: diag_proto.h:27
@ REPLIES_RECEIVED
Definition: diag_proto.h:29
SessionMap session_map_
Definition: diag_proto.h:59
void FillSandeshHealthCheckResponse(SegmentHealthCheckPktStatsResp *resp)
Definition: diag_proto.cc:119
DiagStatsMap stats_
Definition: diag_proto.h:68
virtual ~DiagProto()
Definition: diag_proto.h:47
std::mutex stats_mutex_
Definition: diag_proto.h:67
ProtoHandler * AllocProtoHandler(boost::shared_ptr< PktInfo > info, boost::asio::io_context &io)
Definition: diag_proto.cc:25
void IncrementDiagStats(uint32_t itf_id, DiagStatsType type)
Definition: diag_proto.cc:94
uint8_t type
Definition: load_balance.h:2
Definition: io_utils.cc:12
uint64_t replies_received
Definition: diag_proto.h:36
uint64_t requests_sent
Definition: diag_proto.h:33
uint64_t requests_received
Definition: diag_proto.h:34
uint64_t replies_sent
Definition: diag_proto.h:35