-
Notifications
You must be signed in to change notification settings - Fork 543
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[portsorch]: Bring the physical ports up are only after buffer configuration was applied #515
Merged
pavel-shirshov
merged 4 commits into
sonic-net:master
from
pavel-shirshov:pavelsh/up_after_qos
Jun 8, 2018
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,6 +29,7 @@ BufferOrch::BufferOrch(DBConnector *db, vector<string> &tableNames) : Orch(db, t | |
{ | ||
SWSS_LOG_ENTER(); | ||
initTableHandlers(); | ||
initBufferReadyLists(db); | ||
}; | ||
|
||
void BufferOrch::initTableHandlers() | ||
|
@@ -42,6 +43,59 @@ void BufferOrch::initTableHandlers() | |
m_bufferHandlerMap.insert(buffer_handler_pair(CFG_BUFFER_PORT_EGRESS_PROFILE_LIST_NAME, &BufferOrch::processEgressBufferProfileList)); | ||
} | ||
|
||
void BufferOrch::initBufferReadyLists(DBConnector *db) | ||
{ | ||
SWSS_LOG_ENTER(); | ||
|
||
Table pg_table(db, CFG_BUFFER_PG_TABLE_NAME); | ||
initBufferReadyList(pg_table); | ||
|
||
Table queue_table(db, CFG_BUFFER_QUEUE_TABLE_NAME); | ||
initBufferReadyList(queue_table); | ||
} | ||
|
||
void BufferOrch::initBufferReadyList(Table& table) | ||
{ | ||
SWSS_LOG_ENTER(); | ||
|
||
std::vector<std::string> keys; | ||
table.getKeys(keys); | ||
|
||
for (const auto& key: keys) | ||
{ | ||
m_ready_list[key] = false; | ||
|
||
auto tokens = tokenize(key, config_db_key_delimiter); | ||
if (tokens.size() != 2) | ||
{ | ||
SWSS_LOG_ERROR("Wrong format of a table '%s' key '%s'. Skip it", table.getTableName().c_str(), key.c_str()); | ||
continue; | ||
} | ||
|
||
auto port_names = tokenize(tokens[0], list_item_delimiter); | ||
|
||
for(const auto& port_name: port_names) | ||
{ | ||
m_port_ready_list_ref[port_name].push_back(key); | ||
} | ||
} | ||
} | ||
|
||
bool BufferOrch::isPortReady(const std::string& port_name) const | ||
{ | ||
SWSS_LOG_ENTER(); | ||
|
||
const auto& list_of_keys = m_port_ready_list_ref.at(port_name); | ||
|
||
bool result = true; | ||
for (const auto& key: list_of_keys) | ||
{ | ||
result = result && m_ready_list.at(key); | ||
} | ||
|
||
return result; | ||
} | ||
|
||
task_process_status BufferOrch::processBufferPool(Consumer &consumer) | ||
{ | ||
SWSS_LOG_ENTER(); | ||
|
@@ -315,7 +369,7 @@ task_process_status BufferOrch::processQueue(Consumer &consumer) | |
auto it = consumer.m_toSync.begin(); | ||
KeyOpFieldsValuesTuple tuple = it->second; | ||
sai_object_id_t sai_buffer_profile; | ||
string key = kfvKey(tuple); | ||
const string key = kfvKey(tuple); | ||
string op = kfvOp(tuple); | ||
vector<string> tokens; | ||
sai_uint32_t range_low, range_high; | ||
|
@@ -374,6 +428,16 @@ task_process_status BufferOrch::processQueue(Consumer &consumer) | |
} | ||
} | ||
} | ||
|
||
if (m_ready_list.find(key) != m_ready_list.end()) | ||
{ | ||
m_ready_list[key] = true; | ||
} | ||
else | ||
{ | ||
SWSS_LOG_ERROR("Queue profile '%s' was inserted after BufferOrch init", key.c_str()); | ||
} | ||
|
||
return task_process_status::task_success; | ||
} | ||
|
||
|
@@ -386,7 +450,7 @@ task_process_status BufferOrch::processPriorityGroup(Consumer &consumer) | |
auto it = consumer.m_toSync.begin(); | ||
KeyOpFieldsValuesTuple tuple = it->second; | ||
sai_object_id_t sai_buffer_profile; | ||
string key = kfvKey(tuple); | ||
const string key = kfvKey(tuple); | ||
string op = kfvOp(tuple); | ||
vector<string> tokens; | ||
sai_uint32_t range_low, range_high; | ||
|
@@ -451,6 +515,16 @@ task_process_status BufferOrch::processPriorityGroup(Consumer &consumer) | |
} | ||
} | ||
} | ||
|
||
if (m_ready_list.find(key) != m_ready_list.end()) | ||
{ | ||
m_ready_list[key] = true; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
the same |
||
} | ||
else | ||
{ | ||
SWSS_LOG_ERROR("PG profile '%s' was inserted after BufferOrch init", key.c_str()); | ||
} | ||
|
||
return task_process_status::task_success; | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
from swsscommon import swsscommon | ||
import time | ||
|
||
# The test check that the ports will be up, when the admin state is UP by conf db. | ||
|
||
def test_PortsAreUpAfterBuffers(dvs): | ||
num_ports = 32 | ||
asic_db = swsscommon.DBConnector(swsscommon.ASIC_DB, dvs.redis_sock, 0) | ||
conf_db = swsscommon.DBConnector(swsscommon.CONFIG_DB, dvs.redis_sock, 0) | ||
|
||
conf_port_table = swsscommon.Table(conf_db, "PORT") | ||
asic_port_table = swsscommon.Table(asic_db, "ASIC_STATE:SAI_OBJECT_TYPE_PORT") | ||
|
||
# enable all ports | ||
fvs = swsscommon.FieldValuePairs([("admin_status", "up")]) | ||
for i in range(0, num_ports): | ||
conf_port_table.set("Ethernet%d" % (i*4), fvs) | ||
|
||
time.sleep(5) | ||
|
||
# check that the ports are enabled in ASIC | ||
asic_port_records = asic_port_table.getKeys() | ||
assert len(asic_port_records) == (num_ports + 1), "Number of port records doesn't match number of ports" # +CPU port | ||
num_set = 0 | ||
for k in asic_port_records: | ||
status, fvs = asic_port_table.get(k) | ||
assert status, "Got an error when get a key" | ||
for fv in fvs: | ||
if fv[0] == "SAI_PORT_ATTR_ADMIN_STATE": | ||
assert fv[1] == "true", "The port isn't UP as expected" | ||
num_set += 1 | ||
# make sure that state is set for all "num_ports" ports | ||
assert num_set == num_ports, "Not all ports are up" |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
search the key twice
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you please elaborate on it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
m_ready_list.find()
m_ready_list[]
In reply to: 193597878 [](ancestors = 193597878)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
vs
I think first case is more readable, although it might be slightly slower in case the compiler will not optimize it.
That code is not on he hot path, so I preferred to use better readability here.