Skip to content

Commit

Permalink
Merge "Send teardown time in FlowLog messages." into R3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Zuul authored and opencontrail-ci-admin committed May 11, 2016
2 parents bc565ca + 95e51e8 commit de3a5cf
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 8 deletions.
1 change: 1 addition & 0 deletions src/sandesh/common/flow.sandesh
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ struct FlowLogData {
12: optional string vm;
16: optional string reverse_uuid;
17: optional i64 setup_time;
18: optional i64 teardown_time;

23: optional i64 bytes;
24: optional i64 packets;
Expand Down
7 changes: 4 additions & 3 deletions src/vnsw/agent/oper/global_vrouter.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ class GlobalVrouter {
public:
static const std::string kMetadataService;
static const Ip4Address kLoopBackIp;
static const uint32_t kDefaultFlowExportRate = 100;
static const int32_t kDefaultFlowExportRate = 100;
static const int32_t kDisableSampling = -1;

struct LinkLocalServiceKey {
Ip4Address linklocal_service_ip;
Expand Down Expand Up @@ -96,7 +97,7 @@ class GlobalVrouter {
const LinkLocalServicesMap &linklocal_services_map() const {
return linklocal_services_map_;
}
uint32_t flow_export_rate() const { return flow_export_rate_; }
int32_t flow_export_rate() const { return flow_export_rate_; }

void GlobalVrouterConfig(DBTablePartBase *partition, DBEntryBase *dbe);
bool FindLinkLocalService(const std::string &service_name,
Expand Down Expand Up @@ -143,7 +144,7 @@ class GlobalVrouter {
boost::scoped_ptr<FabricDnsResolver> fabric_dns_resolver_;
boost::scoped_ptr<AgentRouteResync> agent_route_resync_walker_;
Agent::ForwardingMode forwarding_mode_;
uint32_t flow_export_rate_;
int32_t flow_export_rate_;
FlowAgingTimeoutMap flow_aging_timeout_map_;
EcmpLoadBalance ecmp_load_balance_;
};
Expand Down
2 changes: 1 addition & 1 deletion src/vnsw/agent/test-xml/test_xml_oper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -885,7 +885,7 @@ bool AgentUtXmlGlobalVrouterValidate::Validate() {
return false;

if (flow_export_rate_ != -1) {
uint32_t rate = (uint32_t)(flow_export_rate_);
int32_t rate = flow_export_rate_;
if (vr->flow_export_rate() != rate)
return false;
}
Expand Down
16 changes: 16 additions & 0 deletions src/vnsw/agent/uve/test/test_stats_mock.cc
Original file line number Diff line number Diff line change
Expand Up @@ -995,10 +995,18 @@ TEST_F(StatsTestMock, Underlay_3) {
//invoked, the dispatch of flow log message happens
KSyncSockTypeMap::IncrFlowStats(fe->flow_handle(), 1, 30);

//Verify that flows DON'T have exported_alteast_once_ flag set
EXPECT_FALSE(info->exported_atleast_once());
EXPECT_FALSE(rinfo->exported_atleast_once());

//Invoke FlowStatsCollector to update the stats
util_.EnqueueFlowStatsCollectorTask();
client->WaitForIdle(10);

//Verify that exported flows have exported_alteast_once_ flag set
EXPECT_TRUE(info->exported_atleast_once());
EXPECT_TRUE(rinfo->exported_atleast_once());

//Verify underlay source port for forward flow
EXPECT_EQ(fe->tunnel_type().GetType(), TunnelType::MPLS_GRE);
EXPECT_EQ(info->underlay_source_port(), 1234);
Expand All @@ -1015,11 +1023,19 @@ TEST_F(StatsTestMock, Underlay_3) {
FlowLogData flow_log = f->last_sent_flow_log();
EXPECT_EQ(flow_log.get_underlay_source_port(), 0);

//Verify that teardown_time is not set
EXPECT_FALSE((flow_log.__isset.teardown_time));

//cleanup
DeleteFlow(flow, 1);
client->WaitForIdle();
EXPECT_EQ(0U, flow_proto_->FlowCount());

//Verify that FlowLog sent for deleted flow has teadown time set.
flow_log = f->last_sent_flow_log();
EXPECT_TRUE((flow_log.__isset.teardown_time));
EXPECT_TRUE((flow_log.get_teardown_time() != 0));

//Remove remote VM routes
util_.DeleteRemoteRoute("vrf5", remote_vm4_ip, peer_);
client->WaitForIdle();
Expand Down
6 changes: 3 additions & 3 deletions src/vnsw/agent/vrouter/flow_stats/flow_export_info.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,23 @@ FlowExportInfo::FlowExportInfo() :
setup_time_(0), teardown_time_(0), last_modified_time_(0),
bytes_(0), packets_(0), prev_diff_bytes_(0), prev_diff_packets_(0),
underlay_source_port_(0), changed_(false),
tcp_flags_(0), delete_enqueue_time_(0) {
tcp_flags_(0), delete_enqueue_time_(0), exported_atleast_once_(false) {
}

FlowExportInfo::FlowExportInfo(const FlowEntryPtr &fe) :
flow_(fe), egress_uuid_(boost::uuids::nil_uuid()),
setup_time_(0), teardown_time_(0), last_modified_time_(0),
bytes_(0), packets_(0), prev_diff_bytes_(0), prev_diff_packets_(0),
underlay_source_port_(0), changed_(true),
tcp_flags_(0), delete_enqueue_time_(0) {
tcp_flags_(0), delete_enqueue_time_(0), exported_atleast_once_(false) {
}

FlowExportInfo::FlowExportInfo(const FlowEntryPtr &fe, uint64_t setup_time) :
flow_(fe), egress_uuid_(boost::uuids::nil_uuid()),
setup_time_(setup_time), teardown_time_(0), last_modified_time_(setup_time),
bytes_(0), packets_(0), prev_diff_bytes_(0), prev_diff_packets_(0),
underlay_source_port_(0), changed_(true),
tcp_flags_(0), delete_enqueue_time_(0) {
tcp_flags_(0), delete_enqueue_time_(0), exported_atleast_once_(false) {
}

FlowEntry* FlowExportInfo::reverse_flow() const {
Expand Down
5 changes: 5 additions & 0 deletions src/vnsw/agent/vrouter/flow_stats/flow_export_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ class FlowExportInfo {
changed_ = value;
}

bool exported_atleast_once() const { return exported_atleast_once_; }
void set_exported_atleast_once(bool value) {
exported_atleast_once_ = value;
}
bool IsActionLog() const;
void SetActionLog();
uint16_t tcp_flags() const { return tcp_flags_; }
Expand Down Expand Up @@ -71,6 +75,7 @@ class FlowExportInfo {
bool changed_;
uint16_t tcp_flags_;
uint64_t delete_enqueue_time_;
bool exported_atleast_once_;
};

#endif // __AGENT_FLOW_EXPORT_INFO_H__
13 changes: 12 additions & 1 deletion src/vnsw/agent/vrouter/flow_stats/flow_stats_collector.cc
Original file line number Diff line number Diff line change
Expand Up @@ -664,7 +664,7 @@ void FlowStatsCollector::ExportFlow(FlowExportInfo *info,
FlowEntry *flow = info->flow();
FlowEntry *rflow = info->reverse_flow();

uint32_t cfg_rate = agent_uve_->agent()->oper_db()->global_vrouter()->
int32_t cfg_rate = agent_uve_->agent()->oper_db()->global_vrouter()->
flow_export_rate();
/* We should always try to export flows with Action as LOG regardless of
* configured flow-export-rate */
Expand All @@ -682,9 +682,14 @@ void FlowStatsCollector::ExportFlow(FlowExportInfo *info,
* a. if Log is not configured as action for flow
* b. actual flow-export-rate is >= 80% of configured flow-export-rate
* c. diff_bytes is lesser than the threshold
* d. Flow-sampling is not disabled
* e. Flow-sample does not have teardown time or the sample for the flow is
* not exported earlier.
*/
bool subject_flows_to_algorithm = false;
if (!info->IsActionLog() && (diff_bytes < threshold()) &&
(cfg_rate != GlobalVrouter::kDisableSampling) &&
(!info->teardown_time() || !info->exported_atleast_once()) &&
flow_stats_manager_->flow_export_rate() >= ((double)cfg_rate) * 0.8) {
subject_flows_to_algorithm = true;
}
Expand Down Expand Up @@ -713,6 +718,9 @@ void FlowStatsCollector::ExportFlow(FlowExportInfo *info,
info->set_prev_diff_bytes(0);
info->set_prev_diff_packets(0);

/* Mark the flow as exported */
info->set_exported_atleast_once(true);

FlowLogData &s_flow = msg_list_[GetFlowMsgIdx()];

s_flow.set_flowuuid(to_string(flow->uuid()));
Expand Down Expand Up @@ -751,6 +759,9 @@ void FlowStatsCollector::ExportFlow(FlowExportInfo *info,
GetFlowSandeshActionParams(flow->data().match_p.action_info, action_str);
s_flow.set_action(action_str);
s_flow.set_setup_time(info->setup_time());
if (info->teardown_time()) {
s_flow.set_teardown_time(info->teardown_time());
}
SetUnderlayInfo(info, s_flow);
info->set_changed(false);

Expand Down

0 comments on commit de3a5cf

Please sign in to comment.