Skip to content

Commit

Permalink
Merge pull request Juniper#178 from Juniper/bugs
Browse files Browse the repository at this point in the history
Send Cpu and Memory info via new interface for statsOracle
  • Loading branch information
haripk committed Jan 16, 2014
2 parents 11e7a55 + d47f5b8 commit 2e2c5df
Show file tree
Hide file tree
Showing 8 changed files with 171 additions and 29 deletions.
3 changes: 3 additions & 0 deletions src/vnsw/agent/uve/test/SConscript
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ if sys.platform != 'darwin':
test_vn_uve = env.Program(target = 'test_vn_uve', source = ['test_vn_uve.cc'])
env.Alias('src/vnsw/agent/uve/test:test_vn_uve', test_vn_uve)

test_vrouter_uve = env.Program(target = 'test_vrouter_uve', source = ['test_vrouter_uve.cc'])
env.Alias('src/vnsw/agent/uve/test:test_vrouter_uve', test_vrouter_uve)

test_port_bitmap = env.Program(target = 'test_port_bitmap', source = ['test_port_bitmap.cc'])
env.Alias('src/vnsw/agent/uve/test:test_port_bitmap', test_port_bitmap)

Expand Down
3 changes: 2 additions & 1 deletion src/vnsw/agent/uve/test/test_port_bitmap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ class UvePortBitmapTest : public ::testing::Test {
{"vnet22", 5, "2.2.2.2", "00:00:00:00:02:01", 1, 5},
};

uve = VrouterUveEntryTest::GetInstance();
uve = static_cast<VrouterUveEntryTest *>
(Agent::GetInstance()->uve()->vrouter_uve_entry());
CreateVmportEnv(input, 5);
client->WaitForIdle();
//Don't expect bitmaps to be reset on start of each test
Expand Down
93 changes: 93 additions & 0 deletions src/vnsw/agent/uve/test/test_vrouter_uve.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/*
* Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
*/

#include <cfg/cfg_init.h>
#include <cfg/cfg_interface.h>
#include <oper/operdb_init.h>
#include <controller/controller_init.h>
#include <pkt/pkt_init.h>
#include <services/services_init.h>
#include <ksync/ksync_init.h>
#include <cmn/agent_cmn.h>
#include <base/task.h>
#include <io/event_manager.h>
#include <base/util.h>
#include <ifmap_agent_parser.h>
#include <ifmap_agent_table.h>
#include <oper/vn.h>
#include <oper/vm.h>
#include <oper/interface_common.h>
#include <oper/interface.h>
#include <oper/interface.h>
#include <oper/mirror_table.h>
#include <uve/agent_uve.h>

#include "testing/gunit.h"
#include "test_cmn_util.h"
#include "vr_types.h"
#include <uve/vrouter_stats_collector.h>
#include <uve/vrouter_uve_entry_test.h>

using namespace std;

void RouterIdDepInit() {
}

class VRouterStatsCollectorTask : public Task {
public:
VRouterStatsCollectorTask(int count) :
Task((TaskScheduler::GetInstance()->GetTaskId("Agent::Uve")), 0),
count_(count) {
}
virtual bool Run() {
for (int i = 0; i < count_; i++)
Agent::GetInstance()->uve()->vrouter_stats_collector()->Run();
return true;
}
private:
int count_;
};

class UveVrouterUveTest : public ::testing::Test {
public:
void EnqueueVRouterStatsCollectorTask(int count) {
TaskScheduler *scheduler = TaskScheduler::GetInstance();
VRouterStatsCollectorTask *task = new VRouterStatsCollectorTask(count);
scheduler->Enqueue(task);
}
};


TEST_F(UveVrouterUveTest, ComputeCpuState_1) {

VrouterUveEntryTest *vr = static_cast<VrouterUveEntryTest *>
(Agent::GetInstance()->uve()->vrouter_uve_entry());
vr->clear_count();
EnqueueVRouterStatsCollectorTask(1);
client->WaitForIdle();
EXPECT_EQ(0U, vr->compute_state_send_count());

EnqueueVRouterStatsCollectorTask(5);
client->WaitForIdle();
EXPECT_EQ(1U, vr->compute_state_send_count());

EnqueueVRouterStatsCollectorTask(1);
client->WaitForIdle();
EXPECT_EQ(1U, vr->compute_state_send_count());

EnqueueVRouterStatsCollectorTask(5);
client->WaitForIdle();
EXPECT_EQ(2U, vr->compute_state_send_count());
}

int main(int argc, char **argv) {
GETUSERARGS();
client = TestInit(init_file, ksync_init);

usleep(10000);
int ret = RUN_ALL_TESTS();
Agent::GetInstance()->GetEventManager()->Shutdown();
AsioStop();
return ret;
}
17 changes: 17 additions & 0 deletions src/vnsw/agent/uve/vrouter.sandesh
Original file line number Diff line number Diff line change
Expand Up @@ -204,3 +204,20 @@ uve sandesh VrouterStats {
1: VrouterStatsAgent data;
}

struct VrouterCpuInfo {
1: u32 mem_virt
2: double cpu_share
3: u32 used_sys_mem
4: double one_min_cpuload
}

struct ComputeCpuState {
1: string name (key="ObjectVRouter")
2: optional bool deleted
3: optional list<VrouterCpuInfo> cpu_info (tags="")
}

uve sandesh ComputeCpuStateTrace {
1: ComputeCpuState data
}

48 changes: 30 additions & 18 deletions src/vnsw/agent/uve/vrouter_uve_entry.cc
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ void VrouterUveEntry::DispatchVrouterStatsMsg(const VrouterStatsAgent &uve)
VrouterStats::Send(uve);
}

void VrouterUveEntry::DispatchComputeCpuStateMsg(const ComputeCpuState &ccs) {
ComputeCpuStateTrace::Send(ccs);
}

void VrouterUveEntry::VmWalkDone(DBTableBase *base, StringVectorPtr list) {
VrouterAgent vrouter_agent;
vrouter_agent.set_name(agent_->GetHostName());
Expand Down Expand Up @@ -270,6 +274,21 @@ void VrouterUveEntry::InterfaceNotify(DBTablePartBase *partition,
return;
}

void VrouterUveEntry::BuildAndSendComputeCpuStateMsg(const CpuLoadInfo &info) {
ComputeCpuState astate;
VrouterCpuInfo ainfo;
vector<VrouterCpuInfo> aciv;

astate.set_name(agent_->GetHostName());
ainfo.set_cpu_share(info.get_cpu_share());
ainfo.set_mem_virt(info.get_meminfo().get_virt());
ainfo.set_used_sys_mem(info.get_sys_mem_info().get_used());
ainfo.set_one_min_cpuload(info.get_cpuload().get_one_min_avg());
aciv.push_back(ainfo);
astate.set_cpu_info(aciv);
DispatchComputeCpuStateMsg(astate);
}

bool VrouterUveEntry::SendVrouterMsg() {
static bool first = true;
bool change = false;
Expand Down Expand Up @@ -369,28 +388,21 @@ bool VrouterUveEntry::SendVrouterMsg() {
CpuLoadData::FillCpuInfo(cpu_load_info, true);
if (prev_stats_.get_cpu_info() != cpu_load_info || cpu_first) {
stats.set_cpu_info(cpu_load_info);
if ((prev_stats_.get_cpu_info().get_cpu_share() !=
cpu_load_info.get_cpu_share()) || cpu_first) {
stats.set_cpu_share(cpu_load_info.get_cpu_share());
}
if ((prev_stats_.get_cpu_info().get_meminfo().get_virt() !=
cpu_load_info.get_meminfo().get_virt()) || cpu_first) {
stats.set_virt_mem(cpu_load_info.get_meminfo().get_virt());
}
if ((prev_stats_.get_cpu_info().get_sys_mem_info().get_used() !=
cpu_load_info.get_sys_mem_info().get_used()) || cpu_first) {
stats.set_used_sys_mem(cpu_load_info.get_sys_mem_info().
get_used());
}
if ((prev_stats_.get_cpu_info().get_cpuload().get_one_min_avg() !=
cpu_load_info.get_cpuload().get_one_min_avg()) || cpu_first) {
stats.set_one_min_avg_cpuload(
cpu_load_info.get_cpuload().get_one_min_avg());
}
prev_stats_.set_cpu_info(cpu_load_info);
change = true;
cpu_first = false;
}
//Cpu and mem stats needs to be sent always regardless of whether stats
//have changed since last send
stats.set_cpu_share(cpu_load_info.get_cpu_share());
stats.set_virt_mem(cpu_load_info.get_meminfo().get_virt());
stats.set_used_sys_mem(cpu_load_info.get_sys_mem_info().get_used());
stats.set_one_min_avg_cpuload(
cpu_load_info.get_cpuload().get_one_min_avg());

//Stats oracle interface for cpu and mem stats. Needs to be sent
//always regardless of whether the stats have changed since last send
BuildAndSendComputeCpuStateMsg(cpu_load_info);
cpu_stats_count = 0;
}
vector<AgentIfStats> phy_if_list;
Expand Down
5 changes: 4 additions & 1 deletion src/vnsw/agent/uve/vrouter_uve_entry.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,12 @@ class VrouterUveEntry {
void InterfaceWalkDone(DBTableBase *base, StringVectorPtr if_l,
StringVectorPtr err_if_l,
StringVectorPtr nova_if_l);

private:
virtual void DispatchVrouterMsg(const VrouterAgent &uve) const;
virtual void DispatchVrouterStatsMsg(const VrouterStatsAgent &uve) const;
//DispatchComputeCpuStateMsg is not made const function because in derived
//class it needs to be non-const
virtual void DispatchComputeCpuStateMsg(const ComputeCpuState &ccs);
void InterfaceNotify(DBTablePartBase *partition, DBEntryBase *e);
void VmNotify(DBTablePartBase *partition, DBEntryBase *e);
void VnNotify(DBTablePartBase *partition, DBEntryBase *e);
Expand All @@ -80,6 +82,7 @@ class VrouterUveEntry {
bool BuildPhysicalInterfaceList(std::vector<AgentIfStats> &list) const;
void BuildXmppStatsList(std::vector<AgentXmppStats> &list) const;
void SendVrouterUve();
void BuildAndSendComputeCpuStateMsg(const CpuLoadInfo &info);

Agent *agent_;
PhysicalInterfaceSet phy_intf_set_;
Expand Down
18 changes: 14 additions & 4 deletions src/vnsw/agent/uve/vrouter_uve_entry_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,19 @@

#include <uve/vrouter_uve_entry_test.h>

VrouterUveEntryTest *VrouterUveEntryTest::singleton_;

VrouterUveEntryTest::VrouterUveEntryTest(Agent *agent)
: VrouterUveEntry(agent) {
singleton_ = this;
: VrouterUveEntry(agent), compute_state_send_count_(0) {
}

VrouterUveEntryTest::~VrouterUveEntryTest() {
}

void VrouterUveEntryTest::clear_count() {
compute_state_send_count_ = 0;
}

void VrouterUveEntryTest::DispatchComputeCpuStateMsg
(const ComputeCpuState &ccs) {
compute_state_send_count_++;
}

13 changes: 8 additions & 5 deletions src/vnsw/agent/uve/vrouter_uve_entry_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,15 @@
class VrouterUveEntryTest : public VrouterUveEntry {
public:
VrouterUveEntryTest(Agent *agent);
virtual ~VrouterUveEntryTest() {}
void DispatchVrouterMsg(const VrouterAgent &uve) {}
void DispatchVrouterStatsMsg(const VrouterStatsAgent &uve) {}
static VrouterUveEntryTest* GetInstance() { return singleton_; }
virtual ~VrouterUveEntryTest();
uint32_t compute_state_send_count() const
{ return compute_state_send_count_; }
void clear_count();
void DispatchVrouterMsg(const VrouterAgent &uve) const {}
void DispatchVrouterStatsMsg(const VrouterStatsAgent &uve) const {}
void DispatchComputeCpuStateMsg(const ComputeCpuState &ccs);
private:
static VrouterUveEntryTest* singleton_;
uint32_t compute_state_send_count_;
DISALLOW_COPY_AND_ASSIGN(VrouterUveEntryTest);
};

Expand Down

0 comments on commit 2e2c5df

Please sign in to comment.