OpenSDN source code
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
mirror_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 "mirror_kstate.h"
7 #include "vr_mirror.h"
8 
9 using namespace std;
10 
11 MirrorKState::MirrorKState(KMirrorResp *obj, const std::string &resp_ctx,
12  vr_mirror_req &req, int id): KState(resp_ctx, obj) {
13 
14  req.set_mirr_index(id);
15  if (id >= 0) {
16  req.set_h_op(sandesh_op::GET);
17  } else {
18  req.set_h_op(sandesh_op::DUMP);
19  req.set_mirr_marker(-1);
20  }
21 }
22 
24  vr_mirror_req req;
25 
26  req.set_mirr_index(0);
27  req.set_h_op(sandesh_op::DUMP);
28  int32_t idx = boost::any_cast<int32_t>(more_context_);
29  req.set_mirr_marker(idx);
30  EncodeAndSend(req);
31 }
32 
34  KMirrorResp *resp = static_cast<KMirrorResp *>(response_object_);
35  if (resp) {
36  if (MoreData()) {
37  /* There are more nexthops in Kernel. We need to query them from
38  * Kernel and send it to Sandesh.
39  */
40  SendResponse();
42  } else {
43  resp->set_context(response_context_);
44  resp->Response();
45  more_context_ = boost::any();
46  }
47  }
48 }
49 
51 
52  KMirrorResp *resp = static_cast<KMirrorResp *>(response_object_);
53  resp->set_context(response_context_);
54  resp->set_more(true);
55  resp->Response();
56 
57  response_object_ = new KMirrorResp();
58 }
59 
60 const string MirrorKState::FlagsToString(int flags) const {
61  if (flags == 0) {
62  return "NIL";
63  }
64  if (flags & VR_MIRROR_FLAG_MARKED_DELETE) {
65  return "MARKED_DELETE";
66  }
67  return "INVALID";
68 }
std::string response_context_
Definition: kstate.h:63
virtual void SendResponse()
Definition: kstate.h:24
boost::any more_context_
Definition: kstate.h:66
MirrorKState(KMirrorResp *obj, const std::string &resp_ctx, vr_mirror_req &req, int id)
Sandesh * response_object_
Definition: kstate.h:64
virtual void SendNextRequest()
const std::string FlagsToString(int flags) const
bool MoreData() const
Definition: kstate.cc:29
void EncodeAndSend(Sandesh &encoder)
Definition: kstate.cc:63
virtual void Handler()