Skip to content

Commit

Permalink
Merge "Moving physical interface bandwidth from a single vector of st…
Browse files Browse the repository at this point in the history
…ructs to two maps of u64. Partial-Bug:1586562"
  • Loading branch information
Zuul authored and opencontrail-ci-admin committed Jun 9, 2016
2 parents 0f1e0fd + 70f09a3 commit 016f42f
Show file tree
Hide file tree
Showing 11 changed files with 117 additions and 167 deletions.
1 change: 1 addition & 0 deletions src/vnsw/agent/SConscript
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ if GetOption('with_libvirt'):
##########################################################################
env.Prepend(CPPPATH = '#/vrouter/include')
env.Prepend(CPPPATH = env['TOP_INCLUDE'] + '/thrift')
env.Prepend(CPPPATH = env['TOP'] + '/tools/sandesh/library/common')

# Function to append TOP level directory
def AddTopDir(list):
Expand Down
4 changes: 4 additions & 0 deletions src/vnsw/agent/uve/SConscript
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@ virtual_machine_pkg = env.SandeshGenPy('virtual_machine.sandesh', 'vrouter/sande
virtual_network_pkg = env.SandeshGenPy('virtual_network.sandesh', 'vrouter/sandesh/', False)
cpuinfo_pkg = env.SandeshGenPy('#controller/src/base/sandesh/cpuinfo.sandesh', 'vrouter/vrouter/', False)
process_info_pkg = env.SandeshGenPy('#controller/src/base/sandesh/process_info.sandesh', 'vrouter/vrouter/', False)
ds_results_pkg = env.SandeshGenPy('#tools/sandesh/library/common/derived_stats_results.sandesh', 'vrouter/vrouter/', False)
virtual_machine_port_bmap_pkg = env.SandeshGenPy('port_bmap.sandesh', 'vrouter/sandesh/virtual_machine/', False)
flow_pkg = env.SandeshGenPy('#controller/src/sandesh/common/flow.sandesh', 'vrouter/sandesh/', False)
interface_pkg = env.SandeshGenPy('interface.sandesh', 'vrouter/sandesh/', False)
interface_port_bmap_pkg = env.SandeshGenPy('port_bmap.sandesh', 'vrouter/sandesh/interface/', False)
env.Depends(cpuinfo_pkg, vrouter_pkg)
env.Depends(process_info_pkg, vrouter_pkg)
env.Depends(ds_results_pkg, vrouter_pkg)
env.Depends(virtual_machine_port_bmap_pkg, virtual_machine_pkg)
env.Depends(interface_port_bmap_pkg, interface_pkg)

Expand Down Expand Up @@ -59,6 +61,7 @@ sdist_depends.extend(vrouter_sources_rules)
sdist_depends.extend(vrouter_pkg)
sdist_depends.extend(cpuinfo_pkg)
sdist_depends.extend(process_info_pkg)
sdist_depends.extend(ds_results_pkg)
sdist_depends.extend(virtual_machine_pkg)
sdist_depends.extend(virtual_network_pkg)
sdist_depends.extend(virtual_machine_port_bmap_pkg)
Expand Down Expand Up @@ -86,6 +89,7 @@ SandeshGenFiles += env.SandeshGenCpp('acl.sandesh')
SandeshGenFiles += env.SandeshGenCpp('prouter.sandesh')

SandeshGenSrcs = env.ExtractCpp(SandeshGenFiles)
env.Depends(SandeshGenSrcs,'#/build/lib/libsandesh.a')
SandeshGenObjs = env.Object(SandeshGenSrcs)

StatsSandeshGenFiles = env.SandeshGenCpp('stats_interval.sandesh')
Expand Down
1 change: 1 addition & 0 deletions src/vnsw/agent/uve/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
'vrouter.vrouter',
'vrouter.vrouter.cpuinfo',
'vrouter.vrouter.process_info',
'vrouter.vrouter.derived_stats_results',
'vrouter.loadbalancer',
'vrouter.sandesh',
'vrouter.sandesh.virtual_machine',
Expand Down
3 changes: 1 addition & 2 deletions src/vnsw/agent/uve/stats_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,7 @@ StatsManager::InterfaceStats::InterfaceStats()
: name(""), speed(0), duplexity(0), in_pkts(0), in_bytes(0),
out_pkts(0), out_bytes(0), prev_in_bytes(0),
prev_out_bytes(0), prev_in_pkts(0), prev_out_pkts(0),
prev_5min_in_bytes(0), prev_5min_out_bytes(0),
prev_10min_in_bytes(0), prev_10min_out_bytes(10), stats_time(0) {
prev_5min_in_bytes(0), prev_5min_out_bytes(0), stats_time(0) {
}

void StatsManager::InterfaceStats::UpdateStats
Expand Down
2 changes: 0 additions & 2 deletions src/vnsw/agent/uve/stats_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ class StatsManager {
uint64_t prev_out_pkts; /* Required for sending diff stats */
uint64_t prev_5min_in_bytes;
uint64_t prev_5min_out_bytes;
uint64_t prev_10min_in_bytes;
uint64_t prev_10min_out_bytes;
uint64_t stats_time;
};
struct VrfStats {
Expand Down
153 changes: 48 additions & 105 deletions src/vnsw/agent/uve/test/test_vrouter_uve.cc
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,41 @@ class UveVrouterUveTest : public ::testing::Test {
}
return ret;
}

bool BandwidthMatch(const map<string,uint64_t> &imp,
const map<string,uint64_t> &omp,
uint64_t in,
uint64_t out) {
if (0 == imp.size()) {
if (in == 0) {
return true;
}
return false;
}
if (0 == omp.size()) {
if (out == 0) {
return true;
}
return false;
}

map<string,uint64_t>::const_iterator it;
EXPECT_EQ(1U, imp.size());
it = imp.begin();
EXPECT_EQ(in, it->second);
if (in != it->second) {
return false;
}

EXPECT_EQ(1U, omp.size());
it = omp.begin();
EXPECT_EQ(out, it->second);
if (out != it->second) {
return false;
}
return true;
}

bool BandwidthMatch(const vector<AgentIfBandwidth> &list, uint64_t in,
uint64_t out) {
if (0 == list.size()) {
Expand Down Expand Up @@ -615,7 +650,9 @@ TEST_F(UveVrouterUveTest, BandwidthTest_1) {
VrouterStatsAgent &uve = vr->prev_stats();
vr->set_bandwidth_count(0);
vector<AgentIfBandwidth> empty_list;
uve.set_phy_if_band(empty_list);
map<string,uint64_t> empty_map;
uve.set_phy_band_in_bps(empty_map);
uve.set_phy_band_out_bps(empty_map);

PhysicalInterfaceKey key(agent_->params()->eth_port());
Interface *intf = static_cast<Interface *>
Expand All @@ -640,8 +677,11 @@ TEST_F(UveVrouterUveTest, BandwidthTest_1) {
client->WaitForIdle();
WAIT_FOR(100, 1000, (collector->interface_stats_responses_ >= 1));

EXPECT_EQ(0, uve.get_phy_if_band().size());
EXPECT_TRUE(BandwidthMatch(uve.get_phy_if_band(), 0, 0));
EXPECT_EQ(0, uve.get_phy_band_in_bps().size());
EXPECT_EQ(0, uve.get_phy_band_out_bps().size());
EXPECT_TRUE(BandwidthMatch(uve.get_phy_band_in_bps(),
uve.get_phy_band_out_bps(),
0, 0));

//Update the stats object
stats->speed = 1;
Expand All @@ -664,8 +704,11 @@ TEST_F(UveVrouterUveTest, BandwidthTest_1) {
}

EXPECT_EQ(2, vr->bandwidth_count());
EXPECT_EQ(1U, uve.get_phy_if_band().size());
EXPECT_TRUE(BandwidthMatch(uve.get_phy_if_band(), 139810, 1048576));
EXPECT_EQ(1U, uve.get_phy_band_in_bps().size());
EXPECT_EQ(1U, uve.get_phy_band_out_bps().size());
EXPECT_TRUE(BandwidthMatch(uve.get_phy_band_in_bps(),
uve.get_phy_band_out_bps(),
139810, 1048576));
vr->clear_count();

//cleanup
Expand Down Expand Up @@ -773,106 +816,6 @@ TEST_F(UveVrouterUveTest, BandwidthTest_2) {
stats->prev_5min_out_bytes = 0;
}

TEST_F(UveVrouterUveTest, BandwidthTest_3) {
Agent *agent = agent_;
AgentUveStats *u = static_cast<AgentUveStats *>(agent_->uve());
StatsManager *sm = u->stats_manager();
VrouterUveEntryTest *vr = static_cast<VrouterUveEntryTest *>
(agent_->uve()->vrouter_uve_entry());
vr->clear_count();
VrouterStatsAgent &uve = vr->prev_stats();

PhysicalInterfaceKey key(agent_->params()->eth_port());
Interface *intf = static_cast<Interface *>
(agent_->interface_table()->FindActiveEntry(&key));
EXPECT_TRUE((intf != NULL));

//Fetch interface stats
AgentStatsCollectorTest *collector = static_cast<AgentStatsCollectorTest *>
(agent->stats_collector());
collector->interface_stats_responses_ = 0;
agent->stats_collector()->Run();
client->WaitForIdle();
WAIT_FOR(100, 1000, (collector->interface_stats_responses_ >= 1));

//Fetch the stats object from agent_stats_collector
StatsManager::InterfaceStats* stats = sm->GetInterfaceStats(intf);
EXPECT_TRUE((stats != NULL));

//Reset bandwidth counter which controls when bandwidth is updated
vr->set_bandwidth_count(0);
vector<AgentIfBandwidth> empty_list;
uve.set_phy_if_10min_usage(empty_list);

u->vrouter_stats_collector()->run_counter_ = 0;
util_.EnqueueVRouterStatsCollectorTask(1);
client->WaitForIdle();
WAIT_FOR(10000, 500, (u->vrouter_stats_collector()->run_counter_ >= 1));

//Update the stats object
stats->speed = 1;
stats->in_bytes = 10 * 1024 * 1024;
stats->out_bytes = (10 * 60 * 1024 * 1024)/8; //60 Mbps = 60 MBps/8
stats->prev_in_bytes = 0;
stats->prev_out_bytes = 0;
stats->prev_10min_in_bytes = 0;
stats->prev_10min_out_bytes = 0;

//Run Vrouter stats collector to update bandwidth
vr->set_bandwidth_count(1);
u->vrouter_stats_collector()->run_counter_ = 0;
util_.EnqueueVRouterStatsCollectorTask(18);
client->WaitForIdle();
WAIT_FOR(10000, 500, (u->vrouter_stats_collector()->run_counter_ >= 18));
if (vr->bandwidth_count() == 18) {
u->vrouter_stats_collector()->run_counter_ = 0;
util_.EnqueueVRouterStatsCollectorTask(1);
client->WaitForIdle();
WAIT_FOR(10000, 500, (u->vrouter_stats_collector()->run_counter_ >= 1));
}

//Verify the 10-min bandwidth usage
EXPECT_EQ(19, vr->bandwidth_count());
EXPECT_EQ(0, uve.get_phy_if_10min_usage().size());
EXPECT_TRUE(BandwidthMatch(uve.get_phy_if_10min_usage(), 0, 0));

//Run Vrouter stats collector again
vr->clear_count();
EXPECT_TRUE(stats->in_bytes != stats->prev_10min_in_bytes);
u->vrouter_stats_collector()->run_counter_ = 0;
util_.EnqueueVRouterStatsCollectorTask(1);
client->WaitForIdle();
WAIT_FOR(10000, 500, (u->vrouter_stats_collector()->run_counter_ >= 1));

//Verify the 10-min bandwidth usage
EXPECT_EQ(0, vr->bandwidth_count());
WAIT_FOR(10000, 500, (uve.get_phy_if_10min_usage().size() == 1));
EXPECT_TRUE(BandwidthMatch(uve.get_phy_if_10min_usage(), 139810, 1048576));

//Run Vrouter stats collector
u->vrouter_stats_collector()->run_counter_ = 0;
util_.EnqueueVRouterStatsCollectorTask(19);
client->WaitForIdle();
WAIT_FOR(10000, 500, (u->vrouter_stats_collector()->run_counter_ >= 19));

//Verify the 10-min bandwidth usage
EXPECT_EQ(1U, uve.get_phy_if_10min_usage().size());
EXPECT_TRUE(BandwidthMatch(uve.get_phy_if_10min_usage(), 139810, 1048576));

//Run Vrouter stats collector again
u->vrouter_stats_collector()->run_counter_ = 0;
util_.EnqueueVRouterStatsCollectorTask(1);
client->WaitForIdle();
WAIT_FOR(10000, 500, (u->vrouter_stats_collector()->run_counter_ >= 1));

//Verify the 10-min bandwidth usage
EXPECT_TRUE(BandwidthMatch(uve.get_phy_if_10min_usage(), 0, 0));
vr->clear_count();
stats->speed = stats->in_bytes = stats->out_bytes = stats->prev_in_bytes
= stats->prev_out_bytes = stats->prev_10min_in_bytes =
stats->prev_10min_out_bytes = 0;
}

TEST_F(UveVrouterUveTest, ExceptionPktsChange) {
AgentUveStats *u = static_cast<AgentUveStats *>(agent_->uve());
VrouterUveEntryTest *vr = static_cast<VrouterUveEntryTest *>
Expand Down
7 changes: 5 additions & 2 deletions src/vnsw/agent/uve/test/vrouter_uve_entry_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,11 @@ void VrouterUveEntryTest::DispatchVrouterStatsMsg(const VrouterStatsAgent &uve)
{
vrouter_stats_msg_count_++;
last_sent_vrouter_stats_ = uve;
if (uve.__isset.phy_if_band) {
prev_stats_.set_phy_if_band(uve.get_phy_if_band());
if (uve.__isset.phy_band_in_bps) {
prev_stats_.set_phy_band_in_bps(uve.get_phy_band_in_bps());
}
if (uve.__isset.phy_band_out_bps) {
prev_stats_.set_phy_band_out_bps(uve.get_phy_band_out_bps());
}
}

Expand Down
7 changes: 5 additions & 2 deletions src/vnsw/agent/uve/vrouter.sandesh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
*/
include "base/sandesh/cpuinfo.sandesh"
include "base/sandesh/process_info.sandesh"
include "sandesh/library/common/derived_stats_results.sandesh"

/**
* Sandesh definition for agent's xen server config
Expand Down Expand Up @@ -277,7 +278,6 @@ struct VrouterStatsAgent { // Agent stats
33: optional list<AgentIfStats> phy_if_stats_list;
34: optional AgentIfStats vhost_stats;
36: optional list<AgentIfBandwidth> phy_if_5min_usage;
37: optional list<AgentIfBandwidth> phy_if_10min_usage;
38: optional list<u32> udp_sport_bitmap;
39: optional list<u32> udp_dport_bitmap;
40: optional list<u32> tcp_sport_bitmap;
Expand All @@ -286,7 +286,10 @@ struct VrouterStatsAgent { // Agent stats
43: optional double total_in_bandwidth_utilization;
44: optional double total_out_bandwidth_utilization;
45: optional VrouterFlowRate flow_rate (tags="")
46: optional list<AgentIfBandwidth> phy_if_band (tags="name:.name")
50: optional map<string,u64> phy_band_in_bps (tags="name:.__key")
51: optional map<string,u64> phy_band_out_bps (tags="name:.__key")
52: optional map<string,derived_stats_results.EWMResult> in_bps_ewm (mstats="phy_band_in_bps:DSEWM:0.2")
53: optional map<string,derived_stats_results.EWMResult> out_bps_ewm (mstats="phy_band_out_bps:DSEWM:0.2")
}

/**
Expand Down

0 comments on commit 016f42f

Please sign in to comment.