Skip to content

Commit

Permalink
Merge "Send Physical Interface bandwidth as bps."
Browse files Browse the repository at this point in the history
  • Loading branch information
Zuul authored and opencontrail-ci-admin committed Mar 9, 2016
2 parents 63ecabb + 84efe28 commit 23851a7
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 43 deletions.
13 changes: 7 additions & 6 deletions src/vnsw/agent/uve/test/test_vrouter_uve.cc
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,8 @@ class UveVrouterUveTest : public ::testing::Test {
}
return ret;
}
bool BandwidthMatch(const vector<AgentIfBandwidth> &list, int in, int out) {
bool BandwidthMatch(const vector<AgentIfBandwidth> &list, uint64_t in,
uint64_t out) {
if (0 == list.size()) {
if ((in == 0) && (out == 0)) {
return true;
Expand Down Expand Up @@ -664,7 +665,7 @@ 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(), 13, 100));
EXPECT_TRUE(BandwidthMatch(uve.get_phy_if_band(), 139810, 1048576));
vr->clear_count();

//cleanup
Expand Down Expand Up @@ -745,7 +746,7 @@ TEST_F(UveVrouterUveTest, BandwidthTest_2) {

//Verify the 5-min bandwidth usage
EXPECT_EQ(1U, uve.get_phy_if_5min_usage().size());
EXPECT_TRUE(BandwidthMatch(uve.get_phy_if_5min_usage(), 2, 100));
EXPECT_TRUE(BandwidthMatch(uve.get_phy_if_5min_usage(), 27962, 1048576));

//Run Vrouter stats collector
u->vrouter_stats_collector()->run_counter_ = 0;
Expand All @@ -754,7 +755,7 @@ TEST_F(UveVrouterUveTest, BandwidthTest_2) {
WAIT_FOR(10000, 500, (u->vrouter_stats_collector()->run_counter_ >= 9));

//Verify the 5-min bandwidth usage has not changed
EXPECT_TRUE(BandwidthMatch(uve.get_phy_if_5min_usage(), 2, 100));
EXPECT_TRUE(BandwidthMatch(uve.get_phy_if_5min_usage(), 27962, 1048576));

//Run Vrouter stats collector again
u->vrouter_stats_collector()->run_counter_ = 0;
Expand Down Expand Up @@ -846,7 +847,7 @@ TEST_F(UveVrouterUveTest, BandwidthTest_3) {
//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(), 13, 100));
EXPECT_TRUE(BandwidthMatch(uve.get_phy_if_10min_usage(), 139810, 1048576));

//Run Vrouter stats collector
u->vrouter_stats_collector()->run_counter_ = 0;
Expand All @@ -856,7 +857,7 @@ TEST_F(UveVrouterUveTest, BandwidthTest_3) {

//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(), 13, 100));
EXPECT_TRUE(BandwidthMatch(uve.get_phy_if_10min_usage(), 139810, 1048576));

//Run Vrouter stats collector again
u->vrouter_stats_collector()->run_counter_ = 0;
Expand Down
3 changes: 3 additions & 0 deletions src/vnsw/agent/uve/test/vrouter_uve_entry_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ 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());
}
}

void VrouterUveEntryTest::WaitForWalkCompletion() {
Expand Down
8 changes: 4 additions & 4 deletions src/vnsw/agent/uve/vrouter.sandesh
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,8 @@ struct AgentIfStats {
*/
struct AgentIfBandwidth {
1: string name (aggtype="listkey")
2: u16 in_bandwidth_usage;
3: u16 out_bandwidth_usage;
2: u64 in_bandwidth_usage;
3: u64 out_bandwidth_usage;
}

/**
Expand Down Expand Up @@ -280,8 +280,8 @@ struct VrouterStatsAgent { // Agent stats
40: optional list<u32> tcp_sport_bitmap;
41: optional list<u32> tcp_dport_bitmap;
42: optional AgentDropStats drop_stats;
43: optional byte total_in_bandwidth_utilization;
44: optional byte total_out_bandwidth_utilization;
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")
}
Expand Down
80 changes: 52 additions & 28 deletions src/vnsw/agent/uve/vrouter_uve_entry.cc
Original file line number Diff line number Diff line change
Expand Up @@ -133,32 +133,26 @@ bool VrouterUveEntry::SendVrouterMsg() {
// 1 minute bandwidth
if (bandwidth_count_ && ((bandwidth_count_ % bandwidth_mod_1min) == 0)) {
vector<AgentIfBandwidth> phy_if_blist;
BuildPhysicalInterfaceBandwidth(phy_if_blist, 1);
double in_util = 0, out_util = 0;
BuildPhysicalInterfaceBandwidth(phy_if_blist, 1, &in_util, &out_util);
/* One minute bandwidth has 'tags' annotation and has to be sent
* always regardless of change in bandwidth or not */
stats.set_phy_if_band(phy_if_blist);
change = true;
if (prev_stats_.get_phy_if_band() != phy_if_blist) {
prev_stats_.set_phy_if_band(phy_if_blist);

vector<AgentIfBandwidth>::iterator it = phy_if_blist.begin();
int num_intfs = 0, in_band = 0, out_band = 0;
while(it != phy_if_blist.end()) {
AgentIfBandwidth band = *it;
in_band += band.get_in_bandwidth_usage();
out_band += band.get_out_bandwidth_usage();
num_intfs++;
++it;
}
stats.set_total_in_bandwidth_utilization((in_band/num_intfs));
stats.set_total_out_bandwidth_utilization((out_band/num_intfs));
if (in_util != prev_stats_.get_total_in_bandwidth_utilization()) {
stats.set_total_in_bandwidth_utilization(in_util);
prev_stats_.set_total_in_bandwidth_utilization(in_util);
}
if (out_util != prev_stats_.get_total_out_bandwidth_utilization()) {
stats.set_total_out_bandwidth_utilization(out_util);
prev_stats_.set_total_out_bandwidth_utilization(out_util);
}
}

// 5 minute bandwidth
if (bandwidth_count_ && ((bandwidth_count_ % bandwidth_mod_5min) == 0)) {
vector<AgentIfBandwidth> phy_if_blist;
BuildPhysicalInterfaceBandwidth(phy_if_blist, 5);
BuildPhysicalInterfaceBandwidth(phy_if_blist, 5, NULL, NULL);
if (prev_stats_.get_phy_if_5min_usage() != phy_if_blist) {
stats.set_phy_if_5min_usage(phy_if_blist);
prev_stats_.set_phy_if_5min_usage(phy_if_blist);
Expand All @@ -169,7 +163,7 @@ bool VrouterUveEntry::SendVrouterMsg() {
// 10 minute bandwidth
if (bandwidth_count_ && ((bandwidth_count_ % bandwidth_mod_10min) == 0)) {
vector<AgentIfBandwidth> phy_if_blist;
BuildPhysicalInterfaceBandwidth(phy_if_blist, 10);
BuildPhysicalInterfaceBandwidth(phy_if_blist, 10, NULL, NULL);
if (prev_stats_.get_phy_if_10min_usage() != phy_if_blist) {
stats.set_phy_if_10min_usage(phy_if_blist);
prev_stats_.set_phy_if_10min_usage(phy_if_blist);
Expand Down Expand Up @@ -260,22 +254,30 @@ bool VrouterUveEntry::SendVrouterMsg() {
return true;
}

uint8_t VrouterUveEntry::CalculateBandwitdh(uint64_t bytes, int speed_mbps,
int diff_seconds) const {
uint64_t VrouterUveEntry::CalculateBandwitdh(uint64_t bytes, int speed_mbps,
int diff_seconds,
double *utilization_bps) const {
*utilization_bps = 0;
if (bytes == 0 || speed_mbps == 0) {
return 0;
}
uint64_t bits = bytes * 8;
if (diff_seconds == 0) {
return 0;
}
uint64_t speed_bps = speed_mbps * 1024 * 1024;
/* Compute bandwidth in bps */
uint64_t bps = bits/diff_seconds;
return (bps * 100)/speed_bps;

/* Compute network utilization in percentage */
uint64_t speed_bps = speed_mbps * 1024 * 1024;
double bps_double = bits/diff_seconds;
*utilization_bps = (bps_double * 100)/speed_bps;
return bps;
}

uint8_t VrouterUveEntry::GetBandwidthUsage
(StatsManager::InterfaceStats *s, bool dir_in, int mins) const {
uint64_t VrouterUveEntry::GetBandwidthUsage(StatsManager::InterfaceStats *s,
bool dir_in, int mins,
double *util) const {

uint64_t bytes;
if (dir_in) {
Expand Down Expand Up @@ -309,7 +311,7 @@ uint8_t VrouterUveEntry::GetBandwidthUsage
break;
}
}
return CalculateBandwitdh(bytes, s->speed, (mins * 60));
return CalculateBandwitdh(bytes, s->speed, (mins * 60), util);
}

bool VrouterUveEntry::BuildPhysicalInterfaceList(vector<AgentIfStats> &list)
Expand Down Expand Up @@ -340,9 +342,18 @@ bool VrouterUveEntry::BuildPhysicalInterfaceList(vector<AgentIfStats> &list)
}

bool VrouterUveEntry::BuildPhysicalInterfaceBandwidth
(vector<AgentIfBandwidth> &phy_if_list, uint8_t mins) const {
uint8_t in_band, out_band;
(vector<AgentIfBandwidth> &phy_if_list, uint8_t mins, double *in_avg_util,
double *out_avg_util) const {
uint64_t in_band, out_band;
double in_util, out_util;
bool changed = false;
int num_intfs = 0;
if (in_avg_util != NULL) {
*in_avg_util = 0;
}
if (out_avg_util != NULL) {
*out_avg_util = 0;
}

PhysicalInterfaceSet::const_iterator it = phy_intf_set_.begin();
while (it != phy_intf_set_.end()) {
Expand All @@ -355,13 +366,26 @@ bool VrouterUveEntry::BuildPhysicalInterfaceBandwidth
}
AgentIfBandwidth phy_stat_entry;
phy_stat_entry.set_name(intf->name());
in_band = GetBandwidthUsage(s, true, mins);
out_band = GetBandwidthUsage(s, false, mins);
in_band = GetBandwidthUsage(s, true, mins, &in_util);
out_band = GetBandwidthUsage(s, false, mins, &out_util);
phy_stat_entry.set_in_bandwidth_usage(in_band);
phy_stat_entry.set_out_bandwidth_usage(out_band);
phy_if_list.push_back(phy_stat_entry);
changed = true;
if (in_avg_util != NULL) {
*in_avg_util += in_util;
}
if (out_avg_util != NULL) {
*out_avg_util += out_util;
}
++it;
num_intfs++;
}
if ((in_avg_util != NULL) && num_intfs) {
*in_avg_util /= num_intfs;
}
if ((out_avg_util != NULL) && num_intfs) {
*out_avg_util /= num_intfs;
}
return changed;
}
Expand Down
11 changes: 6 additions & 5 deletions src/vnsw/agent/uve/vrouter_uve_entry.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,13 @@ class VrouterUveEntry : public VrouterUveEntryBase {
void InitPrevStats() const;
void FetchDropStats(AgentDropStats &ds) const;
bool SetVrouterPortBitmap(VrouterStatsAgent &vr_stats);
uint8_t CalculateBandwitdh(uint64_t bytes, int speed_mbps,
int diff_seconds) const;
uint8_t GetBandwidthUsage(StatsManager::InterfaceStats *s,
bool dir_in, int mins) const;
uint64_t CalculateBandwitdh(uint64_t bytes, int speed_mbps,
int diff_seconds, double *utilization_bps) const;
uint64_t GetBandwidthUsage(StatsManager::InterfaceStats *s,
bool dir_in, int mins, double *util) const;
bool BuildPhysicalInterfaceBandwidth(std::vector<AgentIfBandwidth> &list,
uint8_t mins) const;
uint8_t mins, double *in_util,
double *out_util) const;
bool BuildPhysicalInterfaceList(std::vector<AgentIfStats> &list) const;
std::string GetMacAddress(const MacAddress &mac) const;
void BuildXmppStatsList(std::vector<AgentXmppStats> &list) const;
Expand Down

0 comments on commit 23851a7

Please sign in to comment.