OpenSDN source code
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
sandesh_ksync.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
3  */
4 
5 #include <boost/asio.hpp>
6 #include <db/db_entry.h>
7 #include <db/db_table.h>
9 #include <base/address_util.h>
13 #include <pkt/flow_mgmt.h>
14 #include <pkt/flow_table.h>
15 #include <oper/mirror_table.h>
17 #include <pkt/flow_proto.h>
18 #include <pkt/flow_token.h>
19 
20 void vr_interface_req::Process(SandeshContext *context) {
21  AgentSandeshContext *ioc = static_cast<AgentSandeshContext *>(context);
22  ioc->IfMsgHandler(this);
23 }
24 
25 void vr_pkt_drop_log_req::Process(SandeshContext *context)
26 {}
27 
28 void vr_info_req::Process(SandeshContext *context)
29 {}
30 
31 void vr_drop_stats_req::Process(SandeshContext *context) {
32  AgentSandeshContext *ioc = static_cast<AgentSandeshContext *>(context);
33  ioc->DropStatsMsgHandler(this);
34 }
35 
36 void vr_vrf_stats_req::Process(SandeshContext *context) {
37  AgentSandeshContext *ioc = static_cast<AgentSandeshContext *>(context);
38  ioc->VrfStatsMsgHandler(this);
39 }
40 
41 void vr_hugepage_config::Process(SandeshContext *context) {
42  AgentSandeshContext *ioc = static_cast<AgentSandeshContext *>(context);
43  ioc->VrouterHugePageHandler(this);
44 }
45 
46 void vrouter_ops::Process(SandeshContext *context) {
47  AgentSandeshContext *ioc = static_cast<AgentSandeshContext *>(context);
48  ioc->VrouterOpsMsgHandler(this);
49 }
50 
51 void vr_mem_stats_req::Process(SandeshContext *context) {
52 }
53 
55  response_code_ = r->get_resp_code();
56 
57  if (response_code_ < 0) {
58  return -response_code_;
59  }
60 
61  return 0;
62 }
63 
64 void KSyncSandeshContext::BridgeTableInfoHandler(vr_bridge_table_data *r) {
65  assert(r->get_btable_op() == sandesh_op::GET);
66  ksync_->ksync_bridge_memory()->set_major_devid(r->get_btable_dev());
67  ksync_->ksync_bridge_memory()->set_table_size(r->get_btable_size());
68  if (r->get_btable_file_path() != Agent::NullString()) {
70  set_table_path(r->get_btable_file_path());
71  }
72  LOG(DEBUG, "Flow table size : " << r->get_btable_size());
73  return;
74 }
75 
76 void KSyncSandeshContext::FlowTableInfoHandler(vr_flow_table_data *r) {
77  assert(r->get_ftable_op() == flow_op::FLOW_TABLE_GET);
78  ksync_->ksync_flow_memory()->set_major_devid(r->get_ftable_dev());
79  ksync_->ksync_flow_memory()->set_table_size(r->get_ftable_size());
80  if (r->get_ftable_file_path() != Agent::NullString()) {
81  ksync_->ksync_flow_memory()->set_table_path(r->get_ftable_file_path());
82  }
83  LOG(DEBUG, "Flow table size : " << r->get_ftable_size());
84 }
85 
86 static void LogFlowError(vr_flow_response *r, int err) {
87  string op;
88  if (r->get_fresp_flags() != 0) {
89  op = "Add/Update";
90  } else {
91  op = "Delete";
92  }
93 
94  LOG(ERROR, "Error Flow entry op = " << op
95  << " flow_handle = " << (int) r->get_fresp_index()
96  << " gen-id = " << (int) r->get_fresp_gen_id());
97 }
98 
99 // Handle vr_flow response from VRouter
100 // We combine responses from both vr_flow and vr_response messages and
101 // generate single event. Copy the results in vr_flow in KSync entry.
102 // On receiving vr_response message, event will be generated for both messages
103 void KSyncSandeshContext::FlowResponseHandler(vr_flow_response *r) {
104  assert(r->get_fresp_op() == flow_op::FLOW_SET);
105 
106  const KSyncIoContext *ioc = ksync_io_ctx();
107  FlowTableKSyncEntry *ksync_entry =
108  dynamic_cast<FlowTableKSyncEntry *>(ioc->GetKSyncEntry());
109  assert(ksync_entry != NULL);
110  ksync_entry->ReleaseToken();
111  // Handling a new KSync response. Reset the response-info fields, they will
112  // be filled below as necessary
113  ksync_entry->ResetKSyncResponseInfo();
114 
115  assert(r->get_fresp_op() == flow_op::FLOW_SET);
116  int err = GetErrno();
117  if (err == EBADF) {
118  LogFlowError(r, err);
119  }
120 
121  // Skip delete operation.
122  if (ioc->event() == KSyncEntry::DEL_ACK) {
123  return;
124  }
125 
126  ksync_entry->SetKSyncResponseInfo(err, r->get_fresp_index(),
127  r->get_fresp_gen_id(),
128  r->get_fresp_bytes(),
129  r->get_fresp_packets(),
130  r->get_fresp_stats_oflow());
131  return;
132 }
133 
135  assert(0);
136 }
137 
138 void KSyncSandeshContext::IfMsgHandler(vr_interface_req *r) {
139  context_marker_ = r->get_vifr_idx();
140 }
141 
142 void KSyncSandeshContext::VrouterHugePageHandler(vr_hugepage_config *r) {
143  std::string message;
144 
145  switch(r->get_vhp_resp()) {
146  case VR_HPAGE_CFG_RESP_HPAGE_SUCCESS:
147  message = "Huge pages set successfully";
148  break;
149  case VR_HPAGE_CFG_RESP_MEM_FAILURE:
150  message = "ERROR !! Failed to set huge pages and vrouter couldnt allocate memory !!";
151  break;
152  case VR_HPAGE_CFG_RESP_INVALID_ARG_MEM_INITED:
153  message = "Invalid huge pages argument, vrouter using allocated memory (not huge pages)";
154  break;
155  case VR_HPAGE_CFG_RESP_HPAGE_FAILURE_MEM_INITED:
156  message = "Failed to set huge pages, vrouter using allocated memory (not huge pages)";
157  break;
158  case VR_HPAGE_CFG_RESP_MEM_ALREADY_INITED:
159  message = "Vrouter using already allocated memory";
160  break;
161  case VR_HPAGE_CFG_RESP_HPAGE_PARTIAL_SUCCESS:
162  message = "Not all huge pages are successfully set, vrouter using allocated memory (not huge pages)";
163  break;
164  default:
165  message = "Failed to set huge pages, invalid vrouter response";
166  break;
167  }
168 
169  LOG(INFO, message);
170 }
171 
173  Agent *agent = ksync_->agent();
174  agent->set_vrouter_max_labels(r->get_vo_mpls_labels());
175  agent->set_vrouter_max_nexthops(r->get_vo_nexthops());
176  agent->set_vrouter_max_bridge_entries(r->get_vo_bridge_entries());
178  r->get_vo_oflow_bridge_entries());
179  agent->set_vrouter_max_interfaces(r->get_vo_interfaces());
180  agent->set_vrouter_max_mirror_entries(r->get_vo_mirror_entries());
181  agent->set_vrouter_max_vrfs(r->get_vo_vrfs());
182  agent->set_vrouter_max_flow_entries(r->get_vo_flow_entries());
183  agent->set_vrouter_max_oflow_entries(r->get_vo_oflow_entries());
184  agent->set_vrouter_build_info(r->get_vo_build_info());
185  agent->set_vrouter_priority_tagging(r->get_vo_priority_tagging());
186  return;
187 }
void set_vrouter_priority_tagging(bool tagging)
Definition: agent.h:1323
virtual void FlowMsgHandler(vr_flow_req *r)
void set_table_path(const std::string &path)
Definition: ksync_memory.h:52
Agent * agent() const
Definition: ksync_init.h:39
virtual void DropStatsMsgHandler(vr_drop_stats_req *req)=0
void set_table_size(int count)
Definition: ksync_memory.h:51
void set_vrouter_max_vrfs(uint32_t max_vrf)
Definition: agent.h:1276
void SetKSyncResponseInfo(int ksync_error, uint32_t flow_handle, uint8_t gen_id, uint64_t evict_flow_bytes, uint64_t evict_flow_packets, int32_t evict_flow_oflow)
void set_vrouter_max_oflow_entries(uint32_t value)
Definition: agent.h:1313
void set_vrouter_max_flow_entries(uint32_t value)
Definition: agent.h:1306
void set_vrouter_max_bridge_entries(uint32_t bridge_entries)
Definition: agent.h:1291
int GetErrno() const
Definition: ksync_sock.h:80
virtual void VrouterOpsMsgHandler(vrouter_ops *req)=0
Definition: agent.h:358
void set_vrouter_max_labels(uint32_t max_labels)
Definition: agent.h:1255
void set_vrouter_max_nexthops(uint32_t max_nexthop)
Definition: agent.h:1262
static const std::string & NullString()
Definition: agent.h:437
virtual void VrouterOpsMsgHandler(vrouter_ops *r)
static void LogFlowError(vr_flow_response *r, int err)
virtual void VrouterHugePageHandler(vr_hugepage_config *r)
const KSyncIoContext * ksync_io_ctx() const
Definition: ksync_sock.h:82
virtual void FlowResponseHandler(vr_flow_response *r)
KSyncBridgeMemory * ksync_bridge_memory() const
Definition: ksync_init.h:82
virtual void IfMsgHandler(vr_interface_req *req)=0
void set_vrouter_build_info(std::string version)
Definition: agent.h:1316
void set_vrouter_max_interfaces(uint32_t max_interfaces)
Definition: agent.h:1269
#define LOG(_Level, _Msg)
Definition: logging.h:33
virtual void BridgeTableInfoHandler(vr_bridge_table_data *r)
virtual void IfMsgHandler(vr_interface_req *req)
KSyncFlowMemory * ksync_flow_memory() const
Definition: ksync_init.h:58
virtual void VrfStatsMsgHandler(vr_vrf_stats_req *req)=0
void set_vrouter_max_oflow_bridge_entries(uint32_t oflow_bridge_entries)
Definition: agent.h:1298
void set_major_devid(int id)
Definition: ksync_memory.h:50
void set_vrouter_max_mirror_entries(uint32_t max_mirror_entries)
Definition: agent.h:1283
virtual int VrResponseMsgHandler(vr_response *r)
virtual void FlowTableInfoHandler(vr_flow_table_data *r)
virtual void VrouterHugePageHandler(vr_hugepage_config *req)
Definition: ksync_sock.h:74