/
sandesh_ksync.cc
157 lines (137 loc) · 5.54 KB
/
sandesh_ksync.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
/*
* Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
*/
#include <boost/asio.hpp>
#include <db/db_entry.h>
#include <db/db_table.h>
#include <db/db_table_partition.h>
#include <vrouter/ksync/sandesh_ksync.h>
#include <vrouter/ksync/flowtable_ksync.h>
#include <vrouter/ksync/interface_ksync.h>
#include <pkt/flow_table.h>
#include <oper/mirror_table.h>
#include <vrouter/ksync/ksync_init.h>
void vr_interface_req::Process(SandeshContext *context) {
AgentSandeshContext *ioc = static_cast<AgentSandeshContext *>(context);
ioc->IfMsgHandler(this);
}
void vr_drop_stats_req::Process(SandeshContext *context) {
AgentSandeshContext *ioc = static_cast<AgentSandeshContext *>(context);
ioc->DropStatsMsgHandler(this);
}
void vr_vrf_stats_req::Process(SandeshContext *context) {
AgentSandeshContext *ioc = static_cast<AgentSandeshContext *>(context);
ioc->VrfStatsMsgHandler(this);
}
void vrouter_ops::Process(SandeshContext *context) {
AgentSandeshContext *ioc = static_cast<AgentSandeshContext *>(context);
ioc->VrouterOpsMsgHandler(this);
}
int KSyncSandeshContext::VrResponseMsgHandler(vr_response *r) {
response_code_ = r->get_resp_code();
if (-response_code_ == EEXIST) {
return 0;
}
if (response_code_ < 0) {
LOG(ERROR, "VrResponseMsg Error: " << strerror(-response_code_));
return -response_code_;
}
return 0;
}
void KSyncSandeshContext::FlowMsgHandler(vr_flow_req *r) {
assert(r->get_fr_op() == flow_op::FLOW_TABLE_GET ||
r->get_fr_op() == flow_op::FLOW_SET);
if (r->get_fr_op() == flow_op::FLOW_TABLE_GET) {
flow_ksync_->major_devid_ = r->get_fr_ftable_dev();
flow_ksync_->flow_table_size_ = r->get_fr_ftable_size();
flow_ksync_->flow_table_path_ = r->get_fr_file_path();
LOG(DEBUG, "Flow table size : " << r->get_fr_ftable_size());
} else if (r->get_fr_op() == flow_op::FLOW_SET) {
const KSyncIoContext *ioc = ksync_io_ctx();
// TODO : IPv6
FlowKey key(r->get_fr_flow_nh_id(),
Ip4Address(ntohl(r->get_fr_flow_sip())),
Ip4Address(ntohl(r->get_fr_flow_dip())),
r->get_fr_flow_proto(),
ntohs(r->get_fr_flow_sport()),
ntohs(r->get_fr_flow_dport()));
FlowEntry *entry = flow_ksync_->ksync()->agent()->pkt()->flow_table()->
Find(key);
in_addr src;
in_addr dst;
src.s_addr = r->get_fr_flow_sip();
dst.s_addr = r->get_fr_flow_dip();
string src_str = inet_ntoa(src);
string dst_str = inet_ntoa(dst);
if (GetErrno() == EBADF) {
string op;
if (r->get_fr_flags() != 0) {
op = "Add/Update";
} else {
op = "Delete";
}
LOG(ERROR, "Error Flow entry op = " << op
<< " nh = " << (int) key.nh
<< " src = " << src_str << ":" << key.src_port
<< " dst = " << dst_str << ":" << key.dst_port
<< " proto = " << (int)key.protocol
<< " flow_handle = " << (int) r->get_fr_index());
if (entry && (int)entry->flow_handle() == r->get_fr_index()) {
entry->MakeShortFlow(FlowEntry::SHORT_FAILED_VROUTER_INSTALL);
}
return;
}
if (GetErrno() == ENOSPC) {
if (entry) {
entry->MakeShortFlow(FlowEntry::SHORT_FAILED_VROUTER_INSTALL);
}
return;
}
if (entry) {
if (ioc->event() == KSyncEntry::DEL_ACK) {
// Skip delete operation.
return;
}
if (entry->flow_handle() != FlowEntry::kInvalidFlowHandle) {
if ((int)entry->flow_handle() != r->get_fr_index()) {
LOG(DEBUG, "Flow index changed from <" <<
entry->flow_handle() << "> to <" <<
r->get_fr_index() << ">");
}
}
bool update_rev_flow = false;
if ((int)entry->flow_handle() != r->get_fr_index()) {
update_rev_flow = true;
}
flow_ksync_->ksync()->agent()->pkt()->flow_table()->
AddIndexFlowInfo(entry, r->get_fr_index());
FlowEntry *rev_flow = entry->reverse_flow_entry();
//Tie forward flow and reverse flow
if (rev_flow && update_rev_flow) {
rev_flow->UpdateKSync(
flow_ksync_->ksync()->agent()->pkt()->flow_table(),
true);
}
}
} else {
assert(!("Invalid Flow operation"));
}
return;
}
void KSyncSandeshContext::IfMsgHandler(vr_interface_req *r) {
flow_ksync_->ksync()->interface_scanner()->KernelInterfaceData(r);
context_marker_ = r->get_vifr_idx();
}
void KSyncSandeshContext::VrouterOpsMsgHandler(vrouter_ops *r) {
Agent *agent = flow_ksync_->ksync()->agent();
agent->set_vrouter_max_labels(r->get_vo_mpls_labels());
agent->set_vrouter_max_nexthops(r->get_vo_nexthops());
agent->set_vrouter_max_bridge_entries(r->get_vo_bridge_entries());
agent->set_vrouter_max_oflow_bridge_entries(
r->get_vo_oflow_bridge_entries());
agent->set_vrouter_max_interfaces(r->get_vo_interfaces());
agent->set_vrouter_max_mirror_entries(r->get_vo_mirror_entries());
agent->set_vrouter_max_vrfs(r->get_vo_vrfs());
agent->set_vrouter_build_info(r->get_vo_build_info());
return;
}