From ae447013e712e8114888a912732bbfb482275d0c Mon Sep 17 00:00:00 2001 From: Junchao-Mellanox <57339448+Junchao-Mellanox@users.noreply.github.com> Date: Thu, 8 Jul 2021 02:29:44 +0800 Subject: [PATCH] [orchagent] Put port configuration to APPL_DB according to autoneg mode (#1769) *Before puting port related configuration to APPL_DB, check autoneg mode first. If autoneg mode is enabled, "speed" and "interface_type" will not be put into APPL_DB; if autoneg mode is disabled, "adv_speeds" and "adv_interface_types" will not be put into APPL_DB; else all configuration will be put to APPL_DB for backward compatible. --- orchagent/portsorch.cpp | 11 ++++----- portsyncd/portsyncd.cpp | 53 ++++++++++++++++++++++++++++++++++++++++- 2 files changed, 56 insertions(+), 8 deletions(-) diff --git a/orchagent/portsorch.cpp b/orchagent/portsorch.cpp index fab6a7ed5999..87da4e6f73ad 100755 --- a/orchagent/portsorch.cpp +++ b/orchagent/portsorch.cpp @@ -2625,26 +2625,23 @@ void PortsOrch::doPortTask(Consumer &consumer) { an_str = fvValue(i); } - /* Set advertised speeds */ - if (fvField(i) == "adv_speeds") + else if (fvField(i) == "adv_speeds") { adv_speeds_str = fvValue(i); } - /* Set interface type */ - if (fvField(i) == "interface_type") + else if (fvField(i) == "interface_type") { interface_type_str = fvValue(i); } - /* Set advertised interface type */ - if (fvField(i) == "adv_interface_types") + else if (fvField(i) == "adv_interface_types") { adv_interface_types_str = fvValue(i); } /* Set port serdes Pre-emphasis */ - if (fvField(i) == "preemphasis") + else if (fvField(i) == "preemphasis") { getPortSerdesVal(fvValue(i), attr_val); serdes_attr.insert(serdes_attr_pair(SAI_PORT_SERDES_ATTR_PREEMPHASIS, attr_val)); diff --git a/portsyncd/portsyncd.cpp b/portsyncd/portsyncd.cpp index 151ac16657d0..c66fe7db5268 100644 --- a/portsyncd/portsyncd.cpp +++ b/portsyncd/portsyncd.cpp @@ -235,6 +235,10 @@ bool handlePortConfigFromConfigDB(ProducerStateTable &p, DBConnector &cfgDb, boo void handlePortConfig(ProducerStateTable &p, map &port_cfg_map) { + string autoneg; + vector attrs; + vector autoneg_attrs; + vector force_attrs; auto it = port_cfg_map.begin(); while (it != port_cfg_map.end()) @@ -250,7 +254,54 @@ void handlePortConfig(ProducerStateTable &p, map /* No support for port delete yet */ if (op == SET_COMMAND) { - p.set(key, values); + + for (auto i : values) + { + auto field = fvField(i); + if (field == "adv_speeds") + { + autoneg_attrs.push_back(i); + } + else if (field == "adv_interface_types") + { + autoneg_attrs.push_back(i); + } + else if (field == "speed") + { + force_attrs.push_back(i); + } + else if (field == "interface_type") + { + force_attrs.push_back(i); + } + else if (field == "autoneg") + { + autoneg = fvValue(i); + attrs.push_back(i); + } + else + { + attrs.push_back(i); + } + } + if (autoneg == "on") // autoneg is on, only put adv_speeds and adv_interface_types to APPL_DB + { + attrs.insert(attrs.end(), autoneg_attrs.begin(), autoneg_attrs.end()); + } + else if (autoneg == "off") // autoneg is off, only put speed and interface_type to APPL_DB + { + attrs.insert(attrs.end(), force_attrs.begin(), force_attrs.end()); + } + else // autoneg is not configured, put all attributes to APPL_DB + { + attrs.insert(attrs.end(), autoneg_attrs.begin(), autoneg_attrs.end()); + attrs.insert(attrs.end(), force_attrs.begin(), force_attrs.end()); + } + p.set(key, attrs); + attrs.clear(); + autoneg_attrs.clear(); + force_attrs.clear(); + autoneg.clear(); } it = port_cfg_map.erase(it);