OpenSDN source code
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
vrf_stats_kstate.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
3  */
4 
5 #include "kstate.h"
6 #include "vrf_stats_kstate.h"
7 #include <iomanip>
8 #include <sstream>
9 #include "vr_defs.h"
10 
11 using namespace std;
12 
13 VrfStatsKState::VrfStatsKState(KVrfStatsResp *obj, const std::string &resp_ctx,
14  vr_vrf_stats_req &req, int id) :
15  KState(resp_ctx, obj) {
16  if (id >= 0) {
17  req.set_h_op(sandesh_op::GET);
18  req.set_vsr_vrf(id);
19  req.set_vsr_family(AF_INET);
20  } else {
21  InitDumpRequest(req);
22  req.set_vsr_marker(-1);
23  }
24 }
25 
26 void VrfStatsKState::InitDumpRequest(vr_vrf_stats_req &req) const {
27  req.set_h_op(sandesh_op::DUMP);
28  req.set_vsr_rid(0);
29  req.set_vsr_family(AF_INET);
30 }
31 
33  KVrfStatsResp *resp = static_cast<KVrfStatsResp *>(response_object_);
34  if (resp) {
35  if (MoreData()) {
36  /* There are more interfaces in Kernel. We need to query them from
37  * Kernel and send it to Sandesh.
38  */
39  SendResponse();
41  } else {
42  resp->set_context(response_context_);
43  resp->Response();
44  more_context_ = boost::any();
45  }
46  }
47 }
48 
50  vr_vrf_stats_req req;
51  InitDumpRequest(req);
52  int32_t idx = boost::any_cast<int32_t>(more_context_);
53  req.set_vsr_marker(idx);
54  EncodeAndSend(req);
55 }
56 
58 
59  KVrfStatsResp *resp = static_cast<KVrfStatsResp *>(response_object_);
60  resp->set_context(response_context_);
61  resp->set_more(true);
62  resp->Response();
63 
64  response_object_ = new KVrfStatsResp();
65 }
66 
67 const string VrfStatsKState::FamilyToString(int vrf_family) const {
68  unsigned family = vrf_family;
69  switch(family) {
70  case AF_INET:
71  return "AF_INET";
72  default:
73  return "INVALID";
74  }
75 }
virtual void SendNextRequest()
std::string response_context_
Definition: kstate.h:63
virtual void SendResponse()
Definition: kstate.h:24
boost::any more_context_
Definition: kstate.h:66
const std::string FamilyToString(int family) const
void InitDumpRequest(vr_vrf_stats_req &req) const
Sandesh * response_object_
Definition: kstate.h:64
VrfStatsKState(KVrfStatsResp *obj, const std::string &resp_ctx, vr_vrf_stats_req &encoder, int id)
bool MoreData() const
Definition: kstate.cc:29
void EncodeAndSend(Sandesh &encoder)
Definition: kstate.cc:63
virtual void Handler()