Skip to content

Commit

Permalink
Merge "Update flow setup rate stats on flow add/delete events."
Browse files Browse the repository at this point in the history
  • Loading branch information
Zuul authored and opencontrail-ci-admin committed Nov 25, 2015
2 parents 30bc06f + 2f31b40 commit c027dff
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 9 deletions.
25 changes: 25 additions & 0 deletions src/vnsw/agent/cmn/agent_stats.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,31 @@ class AgentStats {
uint64_t min_flow_deletes_per_second() const {
return min_flow_deletes_per_second_;
}

void set_prev_flow_add_time(uint64_t time) {
prev_flow_add_time_ = time;
}
void set_prev_flow_delete_time(uint64_t time) {
prev_flow_delete_time_ = time;
}
void set_prev_flow_created(uint64_t value) {
prev_flow_created_ = value;
}
void set_prev_flow_aged(uint64_t value) {
prev_flow_aged_ = value;
}
void set_max_flow_adds_per_second(uint64_t value) {
max_flow_adds_per_second_ = value;;
}
void set_min_flow_adds_per_second(uint64_t value) {
min_flow_adds_per_second_ = value;;
}
void set_max_flow_deletes_per_second(uint64_t value) {
max_flow_deletes_per_second_ = value;;
}
void set_min_flow_deletes_per_second(uint64_t value) {
min_flow_deletes_per_second_ = value;
}
void UpdateFlowAddMinMaxStats(uint64_t time);
void UpdateFlowDelMinMaxStats(uint64_t time);
void ResetFlowAddMinMaxStats(uint64_t time);
Expand Down
16 changes: 10 additions & 6 deletions src/vnsw/agent/pkt/flow_table.cc
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,12 @@ void FlowTable::Copy(FlowEntry *lhs, const FlowEntry *rhs) {
lhs->Copy(rhs);
}

FlowEntry *FlowTable::Locate(FlowEntry *flow) {
FlowEntry *FlowTable::Locate(FlowEntry *flow, uint64_t time) {
std::pair<FlowEntryMap::iterator, bool> ret;
ret = flow_entry_map_.insert(FlowEntryMapPair(flow->key(), flow));
if (ret.second == true) {
agent_->stats()->incr_flow_created();
agent_->stats()->UpdateFlowAddMinMaxStats(time);
ret.first->second->set_on_tree();
return flow;
}
Expand All @@ -129,8 +130,9 @@ FlowEntry *FlowTable::Locate(FlowEntry *flow) {
}

void FlowTable::Add(FlowEntry *flow, FlowEntry *rflow) {
FlowEntry *new_flow = Locate(flow);
FlowEntry *new_rflow = (rflow != NULL) ? Locate(rflow) : NULL;
uint64_t time = UTCTimestampUsec();
FlowEntry *new_flow = Locate(flow, time);
FlowEntry *new_rflow = (rflow != NULL) ? Locate(rflow, time) : NULL;
Add(flow, new_flow, rflow, new_rflow, false);
}

Expand Down Expand Up @@ -221,7 +223,7 @@ void FlowTable::Add(FlowEntry *flow_req, FlowEntry *flow,
AddInternal(flow_req, flow, rflow_req, rflow, update);
}

void FlowTable::DeleteInternal(FlowEntryMap::iterator &it) {
void FlowTable::DeleteInternal(FlowEntryMap::iterator &it, uint64_t time) {
FlowEntry *fe = it->second;
if (fe->deleted()) {
/* Already deleted return from here. */
Expand Down Expand Up @@ -252,6 +254,7 @@ void FlowTable::DeleteInternal(FlowEntryMap::iterator &it) {
}

agent_->stats()->incr_flow_aged();
agent_->stats()->UpdateFlowDelMinMaxStats(time);
}

bool FlowTable::Delete(const FlowKey &key, bool del_reverse_flow) {
Expand All @@ -269,16 +272,17 @@ bool FlowTable::Delete(const FlowKey &key, bool del_reverse_flow) {
reverse_flow = fe->reverse_flow_entry();
}

uint64_t time = UTCTimestampUsec();
/* Delete the forward flow */
DeleteInternal(it);
DeleteInternal(it, time);

if (!reverse_flow) {
return true;
}

it = flow_entry_map_.find(reverse_flow->key());
if (it != flow_entry_map_.end()) {
DeleteInternal(it);
DeleteInternal(it, time);
return true;
}
return false;
Expand Down
4 changes: 2 additions & 2 deletions src/vnsw/agent/pkt/flow_table.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ class FlowTable {
FlowTableKSyncObject *ksync_object() const { return ksync_object_; }

// Table managment routines
FlowEntry *Locate(FlowEntry *flow);
FlowEntry *Locate(FlowEntry *flow, uint64_t t);
FlowEntry *Find(const FlowKey &key);
void Add(FlowEntry *flow, FlowEntry *rflow);
void Update(FlowEntry *flow, FlowEntry *rflow);
Expand Down Expand Up @@ -206,7 +206,7 @@ class FlowTable {
friend void intrusive_ptr_release(FlowEntry *fe);
private:

void DeleteInternal(FlowEntryMap::iterator &it);
void DeleteInternal(FlowEntryMap::iterator &it, uint64_t t);
void ResyncAFlow(FlowEntry *fe);
void DeleteFlowInfo(FlowEntry *fe);
void DeleteVmFlowInfo(FlowEntry *fe);
Expand Down
15 changes: 15 additions & 0 deletions src/vnsw/agent/uve/test/test_vrouter_uve.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1132,6 +1132,12 @@ TEST_F(UveVrouterUveTest, FlowSetupRate) {
vr->clear_count();
vr->set_prev_flow_created(agent_->stats()->flow_created());
vr->set_prev_flow_aged(agent_->stats()->flow_aged());
agent_->stats()->set_prev_flow_created(agent_->stats()->flow_created());
agent_->stats()->set_prev_flow_aged(agent_->stats()->flow_aged());
agent_->stats()->set_max_flow_adds_per_second(AgentStats::kInvalidFlowCount);
agent_->stats()->set_min_flow_adds_per_second(AgentStats::kInvalidFlowCount);
agent_->stats()->set_max_flow_deletes_per_second(AgentStats::kInvalidFlowCount);
agent_->stats()->set_min_flow_deletes_per_second(AgentStats::kInvalidFlowCount);

FlowSetUp();
TestFlow flow[] = {
Expand All @@ -1156,6 +1162,7 @@ TEST_F(UveVrouterUveTest, FlowSetupRate) {
//Update prev_time to current_time - 1 sec
uint64_t t = UTCTimestampUsec() - 1000000;
vr->set_prev_flow_setup_rate_export_time(t);
agent_->stats()->set_prev_flow_add_time(t);

//Create Flows
EXPECT_EQ(0, flow_proto_->FlowCount());
Expand All @@ -1168,11 +1175,14 @@ TEST_F(UveVrouterUveTest, FlowSetupRate) {
//Verify flow add rate
const VrouterStatsAgent stats = vr->last_sent_stats();
EXPECT_EQ(4U, stats.get_flow_rate().get_added_flows());
EXPECT_EQ(1U, stats.get_flow_rate().get_max_flow_adds_per_second());
EXPECT_EQ(1U, stats.get_flow_rate().get_min_flow_adds_per_second());
EXPECT_EQ(0U, stats.get_flow_rate().get_deleted_flows());

//Update prev_time to current_time - 1 sec
t = UTCTimestampUsec() - 1000000;
vr->set_prev_flow_setup_rate_export_time(t);
agent_->stats()->set_prev_flow_add_time(t);

//Create two more flows
TestFlow flow2[] = {
Expand All @@ -1195,11 +1205,14 @@ TEST_F(UveVrouterUveTest, FlowSetupRate) {
//Verify flow add rate
const VrouterStatsAgent stats2 = vr->last_sent_stats();
EXPECT_EQ(2U, stats2.get_flow_rate().get_added_flows());
EXPECT_EQ(4U, stats2.get_flow_rate().get_max_flow_adds_per_second());
EXPECT_EQ(4U, stats2.get_flow_rate().get_min_flow_adds_per_second());
EXPECT_EQ(0U, stats2.get_flow_rate().get_deleted_flows());

//Update prev_time to current_time - 1 sec
t = UTCTimestampUsec() - 1000000;
vr->set_prev_flow_setup_rate_export_time(t);
agent_->stats()->set_prev_flow_delete_time(t);

//Delete flows and verify delete rate
DeleteFlow(flow2, 1);
Expand All @@ -1212,6 +1225,8 @@ TEST_F(UveVrouterUveTest, FlowSetupRate) {
const VrouterStatsAgent stats3 = vr->last_sent_stats();
EXPECT_EQ(0U, stats3.get_flow_rate().get_added_flows());
EXPECT_EQ(2U, stats3.get_flow_rate().get_deleted_flows());
EXPECT_EQ(1U, stats3.get_flow_rate().get_max_flow_deletes_per_second());
EXPECT_EQ(1U, stats3.get_flow_rate().get_min_flow_deletes_per_second());

FlowTearDown();
vr->clear_count();
Expand Down
2 changes: 1 addition & 1 deletion src/vnsw/agent/uve/vrouter_uve_entry.cc
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ bool VrouterUveEntry::SendVrouterMsg() {
VrouterFlowRate flow_rate;
flow_rate.set_added_flows(created_flows);
flow_rate.set_max_flow_adds_per_second(max_add_rate);
flow_rate.set_max_flow_adds_per_second(min_add_rate);
flow_rate.set_min_flow_adds_per_second(min_add_rate);
flow_rate.set_deleted_flows(aged_flows);
flow_rate.set_max_flow_deletes_per_second(max_del_rate);
flow_rate.set_min_flow_deletes_per_second(min_del_rate);
Expand Down

0 comments on commit c027dff

Please sign in to comment.