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