OpenSDN source code
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
interface_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 "interface_kstate.h"
7 #include <iomanip>
8 #include <sstream>
9 #include "vr_interface.h"
10 
11 using namespace std;
12 
13 InterfaceKState::InterfaceKState(KInterfaceResp *obj, const std::string &ctx,
14  vr_interface_req &req, int id) :
15  KState(ctx, obj) {
16  if (id >= 0) {
17  req.set_h_op(sandesh_op::GET);
18  req.set_vifr_idx(id);
19  } else {
20  InitDumpRequest(req);
21  req.set_vifr_marker(-1);
22  }
23 }
24 
25 void InterfaceKState::InitDumpRequest(vr_interface_req &req) const {
26  req.set_h_op(sandesh_op::DUMP);
27  req.set_vifr_idx(0);
28 }
29 
31  KInterfaceResp *resp = static_cast<KInterfaceResp *>(response_object_);
32  if (resp) {
33  if (MoreData()) {
34  /* There are more interfaces in Kernel. We need to query them from
35  * Kernel and send it to Sandesh.
36  */
37  SendResponse();
39  } else {
40  resp->set_context(response_context_);
41  resp->Response();
42  more_context_ = boost::any();
43  }
44  }
45 }
46 
48  vr_interface_req req;
49  InitDumpRequest(req);
50  int32_t idx = boost::any_cast<int32_t>(more_context_);
51  req.set_vifr_marker(idx);
52  EncodeAndSend(req);
53 }
54 
56 
57  KInterfaceResp *resp = static_cast<KInterfaceResp *>(response_object_);
58  resp->set_context(response_context_);
59  resp->set_more(true);
60  resp->Response();
61 
62  response_object_ = new KInterfaceResp();
63 }
64 
65 const string InterfaceKState::TypeToString(int if_type) const {
66  unsigned short type = if_type;
67  switch(type) {
68  case VIF_TYPE_HOST:
69  return "HOST";
70  case VIF_TYPE_AGENT:
71  return "AGENT";
72  case VIF_TYPE_PHYSICAL:
73  return "PHYSICAL";
74  case VIF_TYPE_VIRTUAL:
75  return "VIRTUAL";
76  default:
77  return "INVALID";
78  }
79 }
80 
81 const string InterfaceKState::FlagsToString(int flags) const {
82  string str("");;
83  if (flags == 0) {
84  return "NIL";
85  }
86  if (flags & VIF_FLAG_POLICY_ENABLED) {
87  str += "POLICY ";
88  }
89  if (flags & VIF_FLAG_MIRROR_RX) {
90  str += "MIRR_RX ";
91  }
92  if (flags & VIF_FLAG_MIRROR_TX) {
93  str += "MIRR_TX ";
94  }
95  return str;
96 }
std::string response_context_
Definition: kstate.h:63
void InitDumpRequest(vr_interface_req &req) const
InterfaceKState(KInterfaceResp *obj, const std::string &resp_ctx, vr_interface_req &encoder, int id)
Definition: kstate.h:24
boost::any more_context_
Definition: kstate.h:66
Sandesh * response_object_
Definition: kstate.h:64
uint8_t type
Definition: load_balance.h:109
const std::string TypeToString(int type) const
virtual void Handler()
const std::string FlagsToString(int flags) const
bool MoreData() const
Definition: kstate.cc:29
void EncodeAndSend(Sandesh &encoder)
Definition: kstate.cc:63
virtual void SendNextRequest()
virtual void SendResponse()