5 #include <sys/socket.h>
7 #include <linux/netlink.h>
11 #include <sys/types.h>
14 #include <asm/types.h>
15 #include <boost/asio.hpp>
36 #include <vr_genetlink.h>
42 using namespace boost::asio::ip;
59 int encode_len, error;
61 vr_flow_table_data info;
62 info.set_ftable_op(flow_op::FLOW_TABLE_GET);
63 info.set_ftable_size(0);
64 info.set_ftable_dev(0);
65 info.set_ftable_file_path(
"");
66 info.set_ftable_processed(0);
67 info.set_ftable_hold_oflows(0);
68 info.set_ftable_added(0);
69 info.set_ftable_cpus(0);
70 info.set_ftable_created(0);
71 info.set_ftable_oflow_entries(0);
72 encode_len = info.WriteBinary(nl_get_buf_ptr(cl) + attr_len,
73 nl_get_buf_len(cl), &error);
78 return sizeof(vr_flow_entry);
89 if (ventry && ventry->fe_gen_id == gen_id &&
90 ventry->fe_action == VR_FLOW_ACTION_HOLD) {
93 FlowKey key(ventry->fe_key.flow_nh_id, sip, dip,
94 ventry->fe_key.flow_proto,
95 ntohs(ventry->fe_key.flow_sport),
96 ntohs(ventry->fe_key.flow_dport));
120 const vr_flow_entry *vflow_entry =
122 if (vflow_entry && vflow_entry->fe_action == VR_FLOW_ACTION_HOLD) {
123 gen_id = vflow_entry->fe_gen_id;
131 if (kflow->fe_key.flow_family == AF_INET) {
132 *sip =
Ip4Address(ntohl(kflow->fe_key.key_u.ip4_key.ip4_sip));
133 *dip =
Ip4Address(ntohl(kflow->fe_key.key_u.ip4_key.ip4_dip));
135 const unsigned char *k_sip = kflow->fe_key.key_u.ip6_key.ip6_sip;
136 const unsigned char *k_dip = kflow->fe_key.key_u.ip6_key.ip6_dip;
137 Ip6Address::bytes_type sbytes;
138 Ip6Address::bytes_type dbytes;
139 for (
int i = 0; i < 16; i++) {
140 sbytes[i] = k_sip[i];
141 dbytes[i] = k_dip[i];
150 key->
nh = kflow->fe_key.flow4_nh_id;
154 key->
src_port = ntohs(kflow->fe_key.flow4_sport);
155 key->
dst_port = ntohs(kflow->fe_key.flow4_dport);
156 key->
protocol = kflow->fe_key.flow4_proto;
162 uint8_t gen_id)
const {
173 if (kflow->fe_gen_id != gen_id) {
181 (uint32_t idx,
bool ignore_active_status)
const {
186 if (idx >= table_entries_count_) {
191 if (ignore_active_status) {
192 return &flow_table_[idx];
195 if (flow_table_[idx].fe_flags & VR_FLOW_FLAG_ACTIVE) {
196 return &flow_table_[idx];
206 key->
nh = kflow->fe_key.flow4_nh_id;
210 key->
src_port = ntohs(kflow->fe_key.flow4_sport);
211 key->
dst_port = ntohs(kflow->fe_key.flow4_dport);
212 key->
protocol = kflow->fe_key.flow4_proto;
214 if (kflow->fe_action == VR_FLOW_ACTION_NAT) {
217 *is_nat_flow =
false;
223 uint16_t flags)
const {
227 if (flags & VR_FLOW_FLAG_EVICTED) {
236 vr_flow_stats *stat)
const {
241 *stat = kflow->fe_stats;
247 vr_flow_stats *stat,
KFlowData *info)
const {
248 *stat = kflow->fe_stats;
251 info->
flags = kflow->fe_flags;
257 vr_flow_stats *stats,
273 if (kflow->fe_gen_id != gen_id) {
void DecrementHoldFlowCounter()
ServicesModule * services() const
bool GetFlowKey(uint32_t index, FlowKey *key, bool *is_nat_flow)
const vr_flow_entry * GetKFlowStatsAndInfo(const FlowKey &key, uint32_t idx, uint8_t gen_id, vr_flow_stats *stats, KFlowData *info) const
boost::asio::ip::address IpAddress
AgentStats * stats() const
virtual int EncodeReq(nl_client *nl, uint32_t attr_len)
uint32_t table_entries_count_
const vr_flow_entry * flow_table_
virtual void FlowResponseHandler(vr_flow_response *req)
virtual int get_entry_size()
static void FlowMmapFree()
virtual void FlowTableInfoHandler(vr_flow_table_data *r)
static void VrFlowToIp(const vr_flow_entry *kflow, IpAddress *sip, IpAddress *dip)
uint32_t hold_flow_counter_
void KFlow2FlowKey(const vr_flow_entry *entry, FlowKey *key) const
bool IsEqual(const FlowKey &key) const
const vr_flow_entry * GetKFlowStats(const FlowKey &key, uint32_t idx, uint8_t gen_id, vr_flow_stats *stats) const
boost::asio::ip::address_v6 Ip6Address
virtual void SetTableSize()
void IncrementHoldFlowCounter()
void set_flow_table_size(uint32_t count)
void update_hold_flow_count(uint32_t value)
virtual void FlowMsgHandler(vr_flow_req *req)=0
virtual bool IsInactiveEntry(uint32_t idx, uint8_t &gen_id)
IcmpErrorProto * icmp_error_proto() const
KSyncFlowMemory(KSync *ksync, uint32_t minor_id)
boost::asio::ip::address_v4 Ip4Address
FlowProto * get_flow_proto() const
const vr_flow_entry * GetKernelFlowEntry(uint32_t idx, bool ignore_active_status) const
void Register(FlowIndexToKeyFn fn)
const vr_flow_entry * GetValidKFlowEntry(const FlowKey &key, uint32_t idx, uint8_t gen_id) const
bool IsEvictionMarked(const vr_flow_entry *entry, uint16_t flags) const
static const uint32_t kInvalidFlowHandle
void ReadFlowInfo(const vr_flow_entry *k_flow, vr_flow_stats *stats, KFlowData *info) const
static vr_flow_entry * FlowMmapAlloc(int size)
void CreateAuditEntry(const FlowKey &key, uint32_t flow_handle, uint8_t gen_id)
static const int kTestFlowTableSize
uint16_t underlay_src_port
virtual void CreateProtoAuditEntry(uint32_t index, uint8_t gen_id)
void UpdateAgentHoldFlowCounter()