Skip to content

Commit

Permalink
Merge "* Add queue is field in qos-queue config"
Browse files Browse the repository at this point in the history
  • Loading branch information
Zuul authored and opencontrail-ci-admin committed Sep 2, 2016
2 parents 4622d4a + eb56698 commit 04206d8
Show file tree
Hide file tree
Showing 17 changed files with 186 additions and 25 deletions.
4 changes: 4 additions & 0 deletions src/schema/vnc_cfg.xsd
Expand Up @@ -1098,6 +1098,10 @@ targetNamespace="http://www.contrailsystems.com/2012/VNC-CONFIG/0">
<!--#IFMAP-SEMANTICS-IDL
Property('max-bandwidth', 'qos-queue', 'required', 'CRUD',
'Maximum bandwidth for this queue.') -->
<xsd:element name="qos-queue-identifier" type="xsd:integer"/>
<!--#IFMAP-SEMANTICS-IDL
Property('qos-queue-identifier', 'qos-queue', 'required', 'CRUD',
'Unique id for this queue.') -->

<xsd:element name="qos-config" type="ifmap:IdentityType"/>
<xsd:element name="project-qos-config"/>
Expand Down
2 changes: 1 addition & 1 deletion src/vnsw/agent/cmn/agent.h
Expand Up @@ -292,7 +292,7 @@ class Agent {
static const uint32_t kFlowKSyncTokens = 25;
static const uint32_t kFlowDelTokens = 16;
static const uint32_t kFlowUpdateTokens = 16;

static const uint8_t kInvalidQueueId = 255;
enum ForwardingMode {
NONE,
L2_L3,
Expand Down
51 changes: 50 additions & 1 deletion src/vnsw/agent/init/agent_param.cc
Expand Up @@ -677,6 +677,53 @@ void AgentParam::ParseServices() {
GetValueFromTree<uint32_t>(services_queue_limit_, "SERVICES.queue_limit");
}

void AgentParam::ParseQueue() {
GetValueFromTree<uint16_t>(default_nic_queue_, "QUEUE.default_nic_queue");

if (!tree_.get_child_optional("QUEUE")) {
return;
}

BOOST_FOREACH(ptree::value_type &v, tree_.get_child("QUEUE")) {
std::string nic_queue = v.first;
std::string input = v.second.get_value<string>();
std::vector<std::string> tokens;
std::string sep = "[],";
boost::split(tokens, input, boost::is_any_of(sep),
boost::token_compress_on);

uint16_t queue;
if (sscanf(nic_queue.c_str(), "NIC-QUEUE-%hu", &queue) != 1) {
continue;
}

for (std::vector<string>::const_iterator it = tokens.begin();
it != tokens.end(); it++) {

if (*it == Agent::NullString()) {
continue;
}

string range = *it;
std::vector<uint16_t> range_value;
if (stringToIntegerList(range, "-", range_value)) {
if (range_value.size() == 1) {
qos_queue_map_[range_value[0]] = queue;
continue;
}

if (range_value[0] > range_value[1]) {
continue;
}

for (uint16_t i = range_value[0]; i <= range_value[1]; i++) {
qos_queue_map_[i] = queue;
}
}
}
}
}

void AgentParam::ParseCollectorDSArguments
(const boost::program_options::variables_map &var_map) {
GetOptValue< vector<string> >(var_map, collector_server_list_,
Expand Down Expand Up @@ -990,6 +1037,7 @@ void AgentParam::InitFromConfig() {
ParseNexthopServer();
ParsePlatform();
ParseServices();
ParseQueue();
cout << "Config file <" << config_file_ << "> parsing completed.\n";
return;
}
Expand Down Expand Up @@ -1427,7 +1475,8 @@ AgentParam::AgentParam(bool enable_flow_options,
tbb_thread_count_(Agent::kMaxTbbThreads),
tbb_exec_delay_(0),
tbb_schedule_delay_(0),
tbb_keepawake_timeout_(Agent::kDefaultTbbKeepawakeTimeout) {
tbb_keepawake_timeout_(Agent::kDefaultTbbKeepawakeTimeout),
default_nic_queue_(Agent::kInvalidQueueId) {
// Set common command line arguments supported
boost::program_options::options_description generic("Generic options");
generic.add_options()
Expand Down
15 changes: 15 additions & 0 deletions src/vnsw/agent/init/agent_param.h
Expand Up @@ -289,6 +289,18 @@ class AgentParam {
void set_pkt0_tx_buffer_count(uint32_t val) { pkt0_tx_buffer_count_ = val; }
bool measure_queue_delay() const { return measure_queue_delay_; }
void set_measure_queue_delay(bool val) { measure_queue_delay_ = val; }
uint16_t get_nic_queue(uint16_t queue) {
std::map<uint16_t, uint16_t>::iterator it = qos_queue_map_.find(queue);
if (it != qos_queue_map_.end()) {
return it->second;
}
return default_nic_queue_;
}

void add_nic_queue(uint16_t queue, uint16_t nic_queue) {
qos_queue_map_[queue] = nic_queue;
}

protected:
void set_hypervisor_mode(HypervisorMode m) { hypervisor_mode_ = m; }
virtual void InitFromSystem();
Expand Down Expand Up @@ -367,6 +379,7 @@ class AgentParam {
void ParseNexthopServer();
void ParsePlatform();
void ParseServices();
void ParseQueue();
void set_agent_mode(const std::string &mode);
void set_gateway_mode(const std::string &mode);

Expand Down Expand Up @@ -519,6 +532,8 @@ class AgentParam {
uint32_t tbb_exec_delay_;
uint32_t tbb_schedule_delay_;
uint32_t tbb_keepawake_timeout_;
std::map<uint16_t, uint16_t> qos_queue_map_;
uint16_t default_nic_queue_;
DISALLOW_COPY_AND_ASSIGN(AgentParam);
};

Expand Down
6 changes: 5 additions & 1 deletion src/vnsw/agent/init/test/cfg.ini
Expand Up @@ -150,4 +150,8 @@ ip_blocks=1.1.1.1/24
# Routes to be exported in routing_instance. Each route is represented as
# ip/prefix. Multiple routes are represented by separating each with a space
# routes= 10.10.10.1/24 11.11.11.1/24

[QUEUE]
NIC-QUEUE-1=[1, 3, 5]
NIC-QUEUE-2=[6-10]
NIC-QUEUE-3=[110-109]
default_nic_queue = 8
4 changes: 4 additions & 0 deletions src/vnsw/agent/init/test/test_agent_init.cc
Expand Up @@ -86,6 +86,10 @@ TEST_F(FlowTest, Agent_Conf_file_1) {
EXPECT_TRUE(param.flow_trace_enable());
EXPECT_EQ(param.pkt0_tx_buffer_count(), 2000);
EXPECT_EQ(param.pkt0_tx_buffer_count(), 2000);
EXPECT_EQ(param.get_nic_queue(1), 1);
EXPECT_EQ(param.get_nic_queue(3), 1);
EXPECT_EQ(param.get_nic_queue(8), 2);
EXPECT_EQ(param.get_nic_queue(105), 8);
}

TEST_F(FlowTest, Agent_Conf_file_2) {
Expand Down
1 change: 1 addition & 0 deletions src/vnsw/agent/oper/agent.sandesh
Expand Up @@ -2113,6 +2113,7 @@ response sandesh AgentQosConfigSandeshResp {
request sandesh AddQosQueue {
1: u32 uuid;
2: string name;
3: u16 id;
}

request sandesh DeleteQosQueue {
Expand Down
6 changes: 6 additions & 0 deletions src/vnsw/agent/oper/forwarding_class.cc
Expand Up @@ -96,6 +96,12 @@ bool ForwardingClass::Change(const DBRequest *req) {
ret = true;
}

if (qos_queue_ref_.get()) {
if (nic_queue_id_ != qos_queue_ref_->nic_queue_id()) {
nic_queue_id_ = qos_queue_ref_->nic_queue_id();
ret = true;
}
}
return ret;
}

Expand Down
5 changes: 5 additions & 0 deletions src/vnsw/agent/oper/forwarding_class.h
Expand Up @@ -82,6 +82,10 @@ class ForwardingClass :
return name_;
}

uint16_t nic_queue_id() const {
return nic_queue_id_;
}

private:
boost::uuids::uuid uuid_;
uint32_t id_;
Expand All @@ -90,6 +94,7 @@ class ForwardingClass :
uint32_t mpls_exp_;
QosQueueConstRef qos_queue_ref_;
std::string name_;
uint16_t nic_queue_id_;
DISALLOW_COPY_AND_ASSIGN(ForwardingClass);
};

Expand Down
9 changes: 7 additions & 2 deletions src/vnsw/agent/oper/ifmap_dependency_manager.cc
Expand Up @@ -716,13 +716,18 @@ void IFMapDependencyManager::InitializeDependencyRules(Agent *agent) {
RegisterConfigHandler(this, "service-health-check",
agent ? agent->health_check_table() : NULL);

AddDependencyPath("qos-config",
MakePath("global-qos-config",
AddDependencyPath("qos-config",
MakePath("global-qos-config-qos-config",
"qos-config", true));
RegisterConfigHandler(this, "qos-config",
agent ? agent->qos_config_table() : NULL);

RegisterConfigHandler(this, "qos-queue",
agent ? agent->qos_queue_table() : NULL);

AddDependencyPath("forwarding-class",
MakePath("forwarding-class-qos-queue",
"qos-queue", true));
RegisterConfigHandler(this, "forwarding-class",
agent ? agent->forwarding_class_table() : NULL);
}
Expand Down
32 changes: 23 additions & 9 deletions src/vnsw/agent/oper/qos_queue.cc
Expand Up @@ -9,15 +9,13 @@
#include <oper_db.h>
#include <oper/config_manager.h>
#include <qos_queue.h>
#include <init/agent_param.h>

QosQueue::QosQueue(const boost::uuids::uuid &uuid):
uuid_(uuid), id_(QosQueueTable::kInvalidIndex) {
}

QosQueue::~QosQueue() {
if (id_ != QosQueueTable::kInvalidIndex) {
static_cast<QosQueueTable *>(get_table())->ReleaseIndex(this);
}
}

DBEntryBase::KeyPtr QosQueue::GetDBRequestKey() const {
Expand Down Expand Up @@ -49,13 +47,30 @@ bool QosQueue::IsLess(const DBEntry &rhs) const {
return (uuid_ < qos_q.uuid_);
}

void QosQueue::PostAdd() {
AgentDBTable *table = static_cast<AgentDBTable *>(get_table());
nic_queue_id_ = table->agent()->params()->get_nic_queue(id_);
}

bool QosQueue::Change(const DBRequest *req) {
const AgentDBTable *table = static_cast<const AgentDBTable *>(get_table());
const QosQueueData *data = static_cast<const QosQueueData *>(req->data.get());
bool ret = false;

if (name_ != data->name_) {
name_ = data->name_;
ret = true;
}
return false;

if (id_ != data->id_) {
id_ = data->id_;
if (table) {
nic_queue_id_ = table->agent()->params()->get_nic_queue(id_);
}
ret = true;
}

return ret;
}

void QosQueue::Delete(const DBRequest *req) {
Expand Down Expand Up @@ -142,17 +157,16 @@ bool QosQueueTable::ProcessConfig(IFMapNode *node, DBRequest &req,
return false;
}

autogen::QosQueue *cfg = static_cast <autogen::QosQueue *> (node->GetObject());
req.oper = DBRequest::DB_ENTRY_ADD_CHANGE;
req.key.reset(new QosQueueKey(u));
req.data.reset(new QosQueueData(agent(), node, node->name()));
req.data.reset(new QosQueueData(agent(), node, node->name(),
cfg->identifier()));
Enqueue(&req);
return false;
}

void QosQueueTable::ReleaseIndex(QosQueue *qos_q) {
if (qos_q->id() != kInvalidIndex) {
index_table_.Remove(qos_q->id());
}
}

AgentSandeshPtr
Expand Down Expand Up @@ -181,7 +195,7 @@ void AddQosQueue::HandleRequest() const {
boost::uuids::uuid u1 = StringToUuid(std::string(str));
req.oper = DBRequest::DB_ENTRY_ADD_CHANGE;
req.key.reset(new QosQueueKey(u1));
req.data.reset(new QosQueueData(NULL, NULL, get_name()));
req.data.reset(new QosQueueData(NULL, NULL, get_name(), get_id()));
table->Enqueue(&req);
resp->Response();
}
Expand Down
15 changes: 12 additions & 3 deletions src/vnsw/agent/oper/qos_queue.h
Expand Up @@ -28,9 +28,11 @@ struct QosQueueKey : public AgentOperDBKey {

struct QosQueueData : public AgentOperDBData {

QosQueueData(const Agent *agent, IFMapNode *node, const std::string &name):
AgentOperDBData(agent, node), name_(name) {}
QosQueueData(const Agent *agent, IFMapNode *node, const std::string &name,
uint16_t id):
AgentOperDBData(agent, node), name_(name), id_(id) {}
std::string name_;
uint16_t id_;
};

class QosQueue :
Expand All @@ -47,6 +49,7 @@ class QosQueue :
virtual bool Change(const DBRequest *req);
virtual void Delete(const DBRequest *req);
virtual void SetKey(const DBRequestKey *key);
virtual void PostAdd();

virtual bool DeleteOnZeroRefCount() const {
return false;
Expand All @@ -67,10 +70,16 @@ class QosQueue :
const std::string& name() const {
return name_;
}

uint16_t nic_queue_id() const {
return nic_queue_id_;
}

private:
boost::uuids::uuid uuid_;
uint32_t id_;
uint16_t id_;
std::string name_;
uint16_t nic_queue_id_;
DISALLOW_COPY_AND_ASSIGN(QosQueue);
};

Expand Down
26 changes: 26 additions & 0 deletions src/vnsw/agent/oper/test/test_forwarding_class.cc
Expand Up @@ -111,6 +111,32 @@ TEST_F(FwdClassTest, Test3) {
EXPECT_TRUE(agent->forwarding_class_table()->Size() == 0);
}

TEST_F(FwdClassTest, Test4) {
TestForwardingClassData data[] = {
{1, 1, 1, 1, 1},
};

Agent::GetInstance()->params()->add_nic_queue(10, 100);

AddGlobalConfig(data, 1);
client->WaitForIdle();
EXPECT_TRUE(agent->forwarding_class_table()->Size() == 1);
VerifyForwardingClass(agent, data, 1);

ForwardingClassKey key(MakeUuid(data[0].id_));
ForwardingClass *fc = static_cast<ForwardingClass *>(
agent->forwarding_class_table()->FindActiveEntry(&key));
EXPECT_TRUE(fc->nic_queue_id() == Agent::kInvalidQueueId);

AddQosQueue("qosqueue1", 1, 10);
client->WaitForIdle();

EXPECT_TRUE(fc->nic_queue_id() == 100);

DelGlobalConfig(data, 1);
client->WaitForIdle();
EXPECT_TRUE(agent->forwarding_class_table()->Size() == 0);
}
int main(int argc, char **argv) {
GETUSERARGS();

Expand Down
1 change: 1 addition & 0 deletions src/vnsw/agent/test/test_cmn_util.h
Expand Up @@ -588,4 +588,5 @@ void VerifyForwardingClass(Agent *agent, struct TestForwardingClassData *data,
uint32_t count);
void VerifyQosConfig(Agent *agent, struct TestQosConfigData *data);
void AddQosConfig(struct TestQosConfigData &data);
void AddQosQueue(const char *name, uint32_t id, uint32_t qos_queue_id);
#endif // vnsw_agent_test_cmn_util_h
14 changes: 14 additions & 0 deletions src/vnsw/agent/test/test_util.cc
Expand Up @@ -4299,6 +4299,20 @@ void VerifyQosConfig(Agent *agent, struct TestQosConfigData *data) {
data->default_forwarding_class_);
}

void AddQosQueue(const char *name, uint32_t id, uint32_t qos_queue_id) {

std::stringstream str;
str << "<qos-queue-identifier>" << qos_queue_id << "</qos-queue-identifier>";

char buf[10000];
int len = 0;
memset(buf, 0, 10000);
AddXmlHdr(buf, len);
AddNodeString(buf, len, "qos-queue", name, id, str.str().c_str());
AddXmlTail(buf, len);
ApplyXmlString(buf);
}

void AddGlobalConfig(struct TestForwardingClassData *data,
uint32_t count) {
std::stringstream str;
Expand Down

0 comments on commit 04206d8

Please sign in to comment.