Skip to content

Commit

Permalink
Merge "Update Aging time for TCP flow-stats-collector"
Browse files Browse the repository at this point in the history
  • Loading branch information
Zuul authored and opencontrail-ci-admin committed Mar 7, 2016
2 parents f448583 + 257b512 commit acf4c45
Show file tree
Hide file tree
Showing 6 changed files with 102 additions and 20 deletions.
2 changes: 2 additions & 0 deletions src/vnsw/agent/pkt/pkt.sandesh
Expand Up @@ -372,6 +372,8 @@ traceobject sandesh FlowRouteUpdate {
response sandesh FlowAgeTimeResp {
1: u32 old_age_time;
2: u32 new_age_time;
3: u32 old_tcp_age_time;
4: u32 new_tcp_age_time;
}

/**
Expand Down
29 changes: 20 additions & 9 deletions src/vnsw/agent/pkt/pkt_sandesh_flow.cc
Expand Up @@ -412,20 +412,31 @@ void FlowAgeTimeReq::HandleRequest() const {

FlowStatsCollector *collector =
agent->flow_stats_manager()->default_flow_stats_collector();
FlowStatsCollector *tcp_col =
agent->flow_stats_manager()->tcp_flow_stats_collector();

FlowAgeTimeResp *resp = new FlowAgeTimeResp();
if (collector == NULL) {
goto done;
if (collector) {
resp->set_old_age_time(collector->flow_age_time_intvl_in_secs());

if (age_time && age_time != resp->get_old_age_time()) {
collector->UpdateFlowAgeTimeInSecs(age_time);
resp->set_new_age_time(age_time);
} else {
resp->set_new_age_time(resp->get_old_age_time());
}
}
resp->set_old_age_time(collector->flow_age_time_intvl_in_secs());
if (tcp_col) {
resp->set_old_tcp_age_time(tcp_col->flow_age_time_intvl_in_secs());

if (age_time && age_time != resp->get_old_age_time()) {
collector->UpdateFlowAgeTimeInSecs(age_time);
resp->set_new_age_time(age_time);
} else {
resp->set_new_age_time(resp->get_old_age_time());
if (age_time && age_time != resp->get_old_age_time() &&
!tcp_col->user_configured()) {
tcp_col->UpdateFlowAgeTimeInSecs(age_time);
resp->set_new_tcp_age_time(age_time);
} else {
resp->set_new_tcp_age_time(resp->get_old_tcp_age_time());
}
}
done:
resp->set_context(context());
resp->set_more(false);
resp->Response();
Expand Down
3 changes: 3 additions & 0 deletions src/vnsw/agent/vrouter/flow_stats/flow_stats_collector.h
Expand Up @@ -101,6 +101,8 @@ class FlowStatsCollector : public StatsCollector {
bool deleted() const {
return deleted_;
}
bool user_configured() const { return user_configured_; }
void set_user_configured(bool value) { user_configured_ = value; }
const FlowAgingTableKey& flow_aging_key() const {
return flow_aging_key_;
}
Expand Down Expand Up @@ -194,6 +196,7 @@ class FlowStatsCollector : public StatsCollector {
FlowAgingTableKey flow_aging_key_;
uint32_t instance_id_;
FlowStatsManager *flow_stats_manager_;
bool user_configured_;
DISALLOW_COPY_AND_ASSIGN(FlowStatsCollector);
};
#endif //vnsw_agent_flow_stats_collector_h
19 changes: 11 additions & 8 deletions src/vnsw/agent/vrouter/flow_stats/flow_stats_manager.cc
Expand Up @@ -119,6 +119,7 @@ void FlowStatsManager::AddReqHandler(boost::shared_ptr<FlowStatsCollectorReq>
it->second->set_flow_age_time_intvl(
1000000L * (uint64_t)req->flow_cache_timeout);
it->second->set_deleted(false);
it->second->set_user_configured(req->user_configured);
return;
}

Expand All @@ -137,6 +138,7 @@ void FlowStatsManager::AddReqHandler(boost::shared_ptr<FlowStatsCollectorReq>
if (req->key.port == 0) {
protocol_list_[req->key.proto] = aging_table.get();
}
aging_table->set_user_configured(req->user_configured);
}

void FlowStatsManager::DeleteReqHandler(boost::shared_ptr<FlowStatsCollectorReq>
Expand Down Expand Up @@ -175,12 +177,13 @@ void FlowStatsManager::FreeReqHandler(boost::shared_ptr<FlowStatsCollectorReq>
}

void FlowStatsManager::Add(const FlowAgingTableKey &key,
uint64_t flow_stats_interval,
uint64_t flow_cache_timeout) {
uint64_t flow_stats_interval,
uint64_t flow_cache_timeout, bool user_configured) {
boost::shared_ptr<FlowStatsCollectorReq>
req(new FlowStatsCollectorReq(
FlowStatsCollectorReq::ADD_FLOW_STATS_COLLECTOR,
key, flow_stats_interval, flow_cache_timeout));
key, flow_stats_interval, flow_cache_timeout,
user_configured));
request_queue_.Enqueue(req);
}

Expand All @@ -197,7 +200,7 @@ void FlowStatsManager::Delete(const FlowAgingTableKey &key) {
req.reset(new FlowStatsCollectorReq(
FlowStatsCollectorReq::ADD_FLOW_STATS_COLLECTOR,
key, agent_->params()->flow_stats_interval(),
agent_->params()->flow_cache_timeout()));
agent_->params()->flow_cache_timeout(), false));
} else {
req.reset(new FlowStatsCollectorReq(
FlowStatsCollectorReq::DELETE_FLOW_STATS_COLLECTOR, key));
Expand Down Expand Up @@ -339,7 +342,7 @@ void FlowStatsManager::FlowStatsReqHandler(Agent *agent,
} else {
agent->flow_stats_manager()->Add(
FlowAgingTableKey(protocol, port),
agent->params()->flow_stats_interval(), timeout);
agent->params()->flow_stats_interval(), timeout, true);
}
}

Expand All @@ -348,9 +351,9 @@ void FlowStatsManager::Init(uint64_t flow_stats_interval,
agent_->set_flow_stats_req_handler(&(FlowStatsManager::FlowStatsReqHandler));
Add(FlowAgingTableKey(kCatchAllProto, 0),
flow_stats_interval,
flow_cache_timeout);
flow_cache_timeout, false);
Add(FlowAgingTableKey(IPPROTO_TCP, 0), flow_stats_interval,
flow_cache_timeout);
flow_cache_timeout, false);
timer_->Start(FlowThresoldUpdateTime,
boost::bind(&FlowStatsManager::UpdateFlowThreshold, this));
}
Expand Down Expand Up @@ -391,7 +394,7 @@ void ShowAgingConfig::HandleRequest() const {
void AddAgingConfig::HandleRequest() const {
FlowStatsManager *fam = Agent::GetInstance()->flow_stats_manager();
fam->Add(FlowAgingTableKey(get_protocol(), get_port()),
get_stats_interval(), get_cache_timeout());
get_stats_interval(), get_cache_timeout(), true);
SandeshResponse *resp = new FlowStatsCfgResp();
resp->set_context(context());
resp->Response();
Expand Down
8 changes: 5 additions & 3 deletions src/vnsw/agent/vrouter/flow_stats/flow_stats_manager.h
Expand Up @@ -44,9 +44,10 @@ struct FlowStatsCollectorReq {
};

FlowStatsCollectorReq(Event ev, const FlowAgingTableKey &k,
uint64_t interval, uint64_t timeout) :
uint64_t interval, uint64_t timeout,
bool user_cfgd) :
event(ev), key(k), flow_stats_interval(interval),
flow_cache_timeout(timeout) {}
flow_cache_timeout(timeout), user_configured(user_cfgd) {}

FlowStatsCollectorReq(Event ev, const FlowAgingTableKey &k):
event(ev), key(k) {}
Expand All @@ -55,6 +56,7 @@ struct FlowStatsCollectorReq {
FlowAgingTableKey key;
uint64_t flow_stats_interval;
uint64_t flow_cache_timeout;
bool user_configured;
};

class FlowStatsManager {
Expand Down Expand Up @@ -84,7 +86,7 @@ class FlowStatsManager {
//Add protocol + port based flow aging table
void Add(const FlowAgingTableKey &key,
uint64_t flow_stats_interval,
uint64_t flow_cache_timeout);
uint64_t flow_cache_timeout, bool user_configured);
void Delete(const FlowAgingTableKey &key);
void Free(const FlowAgingTableKey &key);

Expand Down
61 changes: 61 additions & 0 deletions src/vnsw/agent/vrouter/flow_stats/test/test_flow_stats.cc
Expand Up @@ -39,6 +39,25 @@ class FlowStatsTest : public ::testing::Test {
type_specific_response_count_++;
}
}
void FlowAgeTimeSet(uint64_t age_time_secs) {
FlowAgeTimeReq *req = new FlowAgeTimeReq();
req->set_new_age_time(age_time_secs);
Sandesh::set_response_callback(
boost::bind(&FlowStatsTest::FlowAgeTimeResponse, this, _1));
req->HandleRequest();
client->WaitForIdle();
req->Release();
}
void FlowAgeTimeResponse(Sandesh *sandesh) {
response_count_++;
FlowAgeTimeResp *resp =
dynamic_cast<FlowAgeTimeResp *>(sandesh);
if (resp != NULL) {
type_specific_response_count_++;
age_resp_.set_new_age_time(resp->get_new_age_time());
age_resp_.set_new_tcp_age_time(resp->get_new_tcp_age_time());
}
}
void FlowParamsGet() {
FlowStatsCollectionParamsReq *req = new FlowStatsCollectionParamsReq();
Sandesh::set_response_callback(
Expand Down Expand Up @@ -105,6 +124,7 @@ class FlowStatsTest : public ::testing::Test {
uint32_t num_entries_;
Agent *agent_;
FlowProto *flow_proto_;
FlowAgeTimeResp age_resp_;
};

TEST_F(FlowStatsTest, SandeshFlowParams) {
Expand Down Expand Up @@ -195,6 +215,47 @@ TEST_F(FlowStatsTest, FlowTreeSize) {
FlowTeardown();
}

TEST_F(FlowStatsTest, FlowAgeIntrospect_1) {
ClearCount();
FlowAgeTimeSet(100);
client->WaitForIdle();
WAIT_FOR(1000, 1000, (response_count_ == 1));
EXPECT_EQ(1U, type_specific_response_count_);
EXPECT_EQ(100U, age_resp_.get_new_age_time());
EXPECT_EQ(100U, age_resp_.get_new_tcp_age_time());

//cleanup
ClearCount();
uint64_t default_age_time = FlowStatsCollector::FlowAgeTime/(1000 * 1000);
FlowAgeTimeSet(default_age_time);
client->WaitForIdle();
WAIT_FOR(1000, 1000, (response_count_ == 1));
}

TEST_F(FlowStatsTest, FlowAgeIntrospect_2) {
ClearCount();
/* Mark TCP flow-stats-collector as user_configured */
FlowStatsCollector *tcp_col =
agent_->flow_stats_manager()->tcp_flow_stats_collector();
tcp_col->set_user_configured(true);
uint64_t old_age_time = tcp_col->flow_age_time_intvl_in_secs();
FlowAgeTimeSet(100);
client->WaitForIdle();
WAIT_FOR(1000, 1000, (response_count_ == 1));
EXPECT_EQ(1U, type_specific_response_count_);

//Verify that age is updated only for default collector.
EXPECT_EQ(100U, age_resp_.get_new_age_time());
EXPECT_EQ(old_age_time, age_resp_.get_new_tcp_age_time());

//cleanup
ClearCount();
uint64_t default_age_time = FlowStatsCollector::FlowAgeTime/(1000 * 1000);
FlowAgeTimeSet(default_age_time);
client->WaitForIdle();
WAIT_FOR(1000, 1000, (response_count_ == 1));
}

int main(int argc, char *argv[]) {
int ret;
GETUSERARGS();
Expand Down

0 comments on commit acf4c45

Please sign in to comment.