OpenSDN source code
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
route_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 "route_kstate.h"
7 #include <base/address.h>
8 #include "vr_defs.h"
9 
10 using namespace std;
11 
12 RouteKState::RouteKState(KRouteResp *obj, const std::string &resp_ctx,
13  vr_route_req &req, int id, int family_id, sandesh_op::type op_code, int prefix_size) :
14  KState(resp_ctx, obj), family_id_(family_id), op_code_(op_code), prefix_(prefix_size, 0) {
15  InitEncoder(req, id, op_code_);
16 }
17 
18 void RouteKState::InitEncoder(vr_route_req &req, int id, sandesh_op::type op_code_) const {
19  req.set_rtr_family(family_id_);
20  req.set_rtr_vrf_id(id);
21  req.set_rtr_rid(0);
22  if(op_code_ == sandesh_op::DUMP)
23  req.set_rtr_prefix_len(0);
24  req.set_h_op(op_code_);
25 }
26 
28  KRouteResp *resp = static_cast<KRouteResp *>(response_object_);
29  if (resp) {
30  if (MoreData()) {
31  /* There are more routes in Kernel. We need to query them from
32  * Kernel and send it to Sandesh.
33  */
34  SendResponse();
36  } else {
37  resp->set_context(response_context_);
38  resp->Response();
39  if (!more_context_.empty()) {
40  RouteContext *rctx =
41  boost::any_cast<RouteContext *>(more_context_);
42  if (rctx) {
43  delete rctx;
44  more_context_ = boost::any();
45  }
46  }
47  }
48  }
49 }
50 
52  vr_route_req req;
53  RouteContext *rctx = boost::any_cast<RouteContext *>(more_context_);
54 
55  InitEncoder(req, rctx->vrf_id, op_code_);
56  if (family_id_ == AF_BRIDGE) {
57  req.set_rtr_mac(rctx->marker);
58  } else {
59  // rtr_prefix needs to be initialized
60  req.set_rtr_prefix(prefix_);
61  req.set_rtr_marker(rctx->marker);
62  req.set_rtr_marker_plen(rctx->marker_plen);
63  }
64  EncodeAndSend(req);
65 }
66 
68 
69  KRouteResp *resp = static_cast<KRouteResp *>(response_object_);
70  resp->set_context(response_context_);
71  resp->set_more(true);
72  resp->Response();
73 
74  response_object_ = new KRouteResp();
75 }
76 
77 const string RouteKState::FamilyToString(int nh_family) const {
78  unsigned family = nh_family;
79  switch(family) {
80  case AF_INET:
81  return "AF_INET";
82  case AF_INET6:
83  return "AF_INET6";
84  case AF_BRIDGE:
85  return "AF_BRIDGE";
86  default:
87  return "INVALID";
88  }
89 }
90 
91 const string RouteKState::LabelFlagsToString(int flags) const {
92  if (flags == 0) {
93  return "--NONE--";
94  }
95 
96  string str = "";
97  if (flags & VR_RT_LABEL_VALID_FLAG) {
98  str += "MPLS ";
99  }
100 
101  if (flags & VR_RT_ARP_PROXY_FLAG) {
102  str += "PROXY-ARP";
103  }
104  return str;
105 }
std::string response_context_
Definition: kstate.h:63
virtual void SendNextRequest()
Definition: route_kstate.cc:51
RouteKState(KRouteResp *obj, const std::string &resp_ctx, vr_route_req &encoder, int id, int family_id, sandesh_op::type op_code, int prefix_size)
Definition: route_kstate.cc:12
Definition: kstate.h:24
boost::any more_context_
Definition: kstate.h:66
uint32_t vrf_id
Definition: route_kstate.h:25
virtual void Handler()
Definition: route_kstate.cc:27
sandesh_op::type op_code_
Definition: route_kstate.h:13
const std::string LabelFlagsToString(int flags) const
Definition: route_kstate.cc:91
Sandesh * response_object_
Definition: kstate.h:64
uint8_t type
Definition: load_balance.h:109
std::vector< int8_t > marker
Definition: route_kstate.h:26
virtual void SendResponse()
Definition: route_kstate.cc:67
const std::string FamilyToString(int family) const
Definition: route_kstate.cc:77
bool MoreData() const
Definition: kstate.cc:29
void EncodeAndSend(Sandesh &encoder)
Definition: kstate.cc:63
std::vector< int8_t > prefix_
Definition: route_kstate.h:15
void InitEncoder(vr_route_req &req, int id, sandesh_op::type op_code) const
Definition: route_kstate.cc:18