Skip to content

Commit

Permalink
Remove app_db from muxorch
Browse files Browse the repository at this point in the history
Signed-off-by: bingwang <wang.bing@microsoft.com>
  • Loading branch information
bingwang-ms committed Apr 22, 2022
1 parent 11efd68 commit a82a593
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 67 deletions.
69 changes: 19 additions & 50 deletions orchagent/muxorch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1184,14 +1184,12 @@ void MuxOrch::update(SubjectType type, void *cntx)
}
}

MuxOrch::MuxOrch(DBConnector *cfg_db, DBConnector *app_db, const std::vector<std::string> &tables,
MuxOrch::MuxOrch(DBConnector *db, const std::vector<std::string> &tables,
TunnelDecapOrch* decapOrch, NeighOrch* neighOrch, FdbOrch* fdbOrch) :
Orch2(cfg_db, tables, request_),
Orch2(db, tables, request_),
decap_orch_(decapOrch),
neigh_orch_(neighOrch),
fdb_orch_(fdbOrch),
app_decap_tunnel_table_(app_db, APP_TUNNEL_DECAP_TABLE_NAME)

fdb_orch_(fdbOrch)
{
handler_map_.insert(handler_pair(CFG_MUX_CABLE_TABLE_NAME, &MuxOrch::handleMuxCfg));
handler_map_.insert(handler_pair(CFG_PEER_SWITCH_TABLE_NAME, &MuxOrch::handlePeerSwitch));
Expand Down Expand Up @@ -1245,44 +1243,6 @@ bool MuxOrch::handleMuxCfg(const Request& request)
return true;
}

// Retrieve tc_to_queue_map and tc_to_dscp_map from CONFIG_DB, and
// resolve the ids from QosOrch
bool MuxOrch::resolveQosTableIds()
{
std::vector<FieldValueTuple> field_value_tuples;
if (app_decap_tunnel_table_.get(MUX_TUNNEL, field_value_tuples))
{
KeyOpFieldsValuesTuple tuple{"TUNNEL", MUX_TUNNEL, field_value_tuples};
// Read tc_to_queue_map_id
tc_to_queue_map_id_ = gQosOrch->resolveTunnelQosMap(app_decap_tunnel_table_.getTableName(), MUX_TUNNEL, encap_tc_to_queue_field_name, tuple);
if (tc_to_queue_map_id_ == SAI_NULL_OBJECT_ID)
{
SWSS_LOG_NOTICE("QoS map for tunnel %s type %s is not set", MUX_TUNNEL, encap_tc_to_queue_field_name.c_str());
}
else
{
SWSS_LOG_NOTICE("Resolved QoS map for tunnel %s type %s id %" PRId64, MUX_TUNNEL, encap_tc_to_queue_field_name.c_str(), tc_to_queue_map_id_);
}

// Read tc_to_dscp_map_id
tc_to_dscp_map_id_ = gQosOrch->resolveTunnelQosMap(app_decap_tunnel_table_.getTableName(), MUX_TUNNEL, encap_tc_to_dscp_field_name, tuple);
if (tc_to_dscp_map_id_ == SAI_NULL_OBJECT_ID)
{
SWSS_LOG_NOTICE("QoS map for tunnel %s type %s is not set", MUX_TUNNEL, encap_tc_to_dscp_field_name.c_str());
}
else
{
SWSS_LOG_NOTICE("Resolved QoS map for tunnel %s type %s id %" PRId64, MUX_TUNNEL, encap_tc_to_dscp_field_name.c_str(), tc_to_dscp_map_id_);
}
return true;
}
else
{
SWSS_LOG_NOTICE("Entry for table %s not created yet in APP_DB", MUX_TUNNEL);
return false;
}
}

bool MuxOrch::handlePeerSwitch(const Request& request)
{
SWSS_LOG_ENTER();
Expand All @@ -1307,21 +1267,30 @@ bool MuxOrch::handlePeerSwitch(const Request& request)
auto it = dst_ips.getIpAddresses().begin();
const IpAddress& dst_ip = *it;

// Read dscp_mode of MuxTunnel0 from app_db
string dscp_mode_name = "pipe";
if (!app_decap_tunnel_table_.hget(MUX_TUNNEL, "dscp_mode", dscp_mode_name))
// Read dscp_mode of MuxTunnel0 from decap_orch
string dscp_mode_name = decap_orch_->getDscpMode(MUX_TUNNEL);
if (dscp_mode_name == "")
{
SWSS_LOG_NOTICE("dscp_mode not available for %s", MUX_TUNNEL);
SWSS_LOG_INFO("dscp_mode for tunnel %s is not available yet", MUX_TUNNEL);
return false;
}

// Read tc_to_dscp_map_id and tc_to_queue_map_id
if (!resolveQosTableIds())
// Read tc_to_dscp_map_id of MuxTunnel0 from decap_orch
sai_object_id_t tc_to_dscp_map_id = SAI_NULL_OBJECT_ID;
if (!decap_orch_->getQosMapId(MUX_TUNNEL, encap_tc_to_dscp_field_name, tc_to_dscp_map_id))
{
SWSS_LOG_INFO("tc_to_dscp_map_id for tunnel %s is not available yet", MUX_TUNNEL);
return false;
}
// Read tc_to_queue_map_id of MuxTunnel0 from decap_orch
sai_object_id_t tc_to_queue_map_id = SAI_NULL_OBJECT_ID;
if (!decap_orch_->getQosMapId(MUX_TUNNEL, encap_tc_to_queue_field_name, tc_to_queue_map_id))
{
SWSS_LOG_INFO("tc_to_queue_map_id for tunnel %s is not available yet", MUX_TUNNEL);
return false;
}

mux_tunnel_id_ = create_tunnel(&peer_ip, &dst_ip, tc_to_dscp_map_id_, tc_to_queue_map_id_, dscp_mode_name);
mux_tunnel_id_ = create_tunnel(&peer_ip, &dst_ip, tc_to_dscp_map_id, tc_to_queue_map_id, dscp_mode_name);
SWSS_LOG_NOTICE("Mux peer ip '%s' was added, peer name '%s'",
peer_ip.to_string().c_str(), peer_name.c_str());
}
Expand Down
7 changes: 1 addition & 6 deletions orchagent/muxorch.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ class MuxCfgRequest : public Request
class MuxOrch : public Orch2, public Observer, public Subject
{
public:
MuxOrch(DBConnector *cfg_db, DBConnector *app_db, const std::vector<std::string> &tables, TunnelDecapOrch*, NeighOrch*, FdbOrch*);
MuxOrch(DBConnector *db, const std::vector<std::string> &tables, TunnelDecapOrch*, NeighOrch*, FdbOrch*);

using handler_pair = pair<string, bool (MuxOrch::*) (const Request& )>;
using handler_map = map<string, bool (MuxOrch::*) (const Request& )>;
Expand Down Expand Up @@ -196,12 +196,8 @@ class MuxOrch : public Orch2, public Observer, public Subject

bool getMuxPort(const MacAddress&, const string&, string&);

bool resolveQosTableIds();

IpAddress mux_peer_switch_ = 0x0;
sai_object_id_t mux_tunnel_id_ = SAI_NULL_OBJECT_ID;
sai_object_id_t tc_to_queue_map_id_ = SAI_NULL_OBJECT_ID;
sai_object_id_t tc_to_dscp_map_id_ = SAI_NULL_OBJECT_ID;

MuxCableTb mux_cable_tb_;
MuxTunnelNHs mux_tunnel_nh_;
Expand All @@ -214,7 +210,6 @@ class MuxOrch : public Orch2, public Observer, public Subject
FdbOrch *fdb_orch_;

MuxCfgRequest request_;
Table app_decap_tunnel_table_;
};

const request_description_t mux_cable_request_description = {
Expand Down
2 changes: 1 addition & 1 deletion orchagent/orchdaemon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ bool OrchDaemon::init()
CFG_MUX_CABLE_TABLE_NAME,
CFG_PEER_SWITCH_TABLE_NAME
};
MuxOrch *mux_orch = new MuxOrch(m_configDb, m_applDb, mux_tables, tunnel_decap_orch, gNeighOrch, gFdbOrch);
MuxOrch *mux_orch = new MuxOrch(m_configDb, mux_tables, tunnel_decap_orch, gNeighOrch, gFdbOrch);
gDirectory.set(mux_orch);

MuxCableOrch *mux_cb_orch = new MuxCableOrch(m_applDb, m_stateDb, APP_MUX_CABLE_TABLE_NAME);
Expand Down
66 changes: 62 additions & 4 deletions orchagent/tunneldecaporch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ void TunnelDecapOrch::doTask(Consumer& consumer)
string ttl_mode;
sai_object_id_t dscp_to_dc_map_id = SAI_NULL_OBJECT_ID;
sai_object_id_t tc_to_pg_map_id = SAI_NULL_OBJECT_ID;
// The tc_to_dscp_map_id and tc_to_queue_map_id are parsed here for muxorch to retrieve
sai_object_id_t tc_to_dscp_map_id = SAI_NULL_OBJECT_ID;
sai_object_id_t tc_to_queue_map_id = SAI_NULL_OBJECT_ID;

bool valid = true;

Expand Down Expand Up @@ -126,6 +129,7 @@ void TunnelDecapOrch::doTask(Consumer& consumer)
if (exists)
{
setTunnelAttribute(fvField(i), dscp_mode, tunnel_id);
tunnelTable[key].dscp_mode = dscp_mode;
}
}
else if (fvField(i) == "ecn_mode")
Expand Down Expand Up @@ -186,6 +190,24 @@ void TunnelDecapOrch::doTask(Consumer& consumer)
setTunnelAttribute(fvField(i), tc_to_pg_map_id, tunnel_id);
}
}
else if (fvField(i) == encap_tc_to_dscp_field_name)
{
tc_to_dscp_map_id = gQosOrch->resolveTunnelQosMap(table_name, key, encap_tc_to_dscp_field_name, t);
if (exists)
{
// Record only
tunnelTable[key].encap_tc_to_dscp_map_id = tc_to_dscp_map_id;
}
}
else if (fvField(i) == encap_tc_to_queue_field_name)
{
tc_to_queue_map_id = gQosOrch->resolveTunnelQosMap(table_name, key, encap_tc_to_queue_field_name, t);
if (exists)
{
// Record only
tunnelTable[key].encap_tc_to_queue_map_id = tc_to_queue_map_id;
}
}
}

//create new tunnel if it doesn't exists already
Expand All @@ -195,6 +217,9 @@ void TunnelDecapOrch::doTask(Consumer& consumer)
if (addDecapTunnel(key, tunnel_type, ip_addresses, p_src_ip, dscp_mode, ecn_mode, encap_ecn_mode, ttl_mode,
dscp_to_dc_map_id, tc_to_pg_map_id))
{
// Record only
tunnelTable[key].encap_tc_to_dscp_map_id = tc_to_dscp_map_id;
tunnelTable[key].encap_tc_to_queue_map_id = tc_to_queue_map_id;
SWSS_LOG_NOTICE("Tunnel(s) added to ASIC_DB.");
}
else
Expand Down Expand Up @@ -385,7 +410,7 @@ bool TunnelDecapOrch::addDecapTunnel(
}
}

tunnelTable[key] = { tunnel_id, overlayIfId, dst_ip, {} };
tunnelTable[key] = { tunnel_id, overlayIfId, dst_ip, {}, dscp, SAI_NULL_OBJECT_ID, SAI_NULL_OBJECT_ID };

// create a decap tunnel entry for every source_ip - dest_ip pair
if (!addDecapTunnelTermEntries(key, src_ip, dst_ip, tunnel_id, term_type))
Expand Down Expand Up @@ -609,15 +634,14 @@ bool TunnelDecapOrch::setTunnelAttribute(string field, sai_object_id_t value, sa

sai_attribute_t attr;

if (field == "decap_dscp_to_tc_map")
if (field == decap_dscp_to_tc_field_name)
{
// TC remapping.
attr.id = SAI_TUNNEL_ATTR_DECAP_QOS_DSCP_TO_TC_MAP;
attr.value.oid = value;

}

if (field == "decap_tc_to_pg_map")
else if (field == decap_tc_to_pg_field_name)
{
// TC to PG remapping
attr.id = SAI_TUNNEL_ATTR_DECAP_QOS_TC_TO_PRIORITY_GROUP_MAP;
Expand Down Expand Up @@ -939,3 +963,37 @@ IpAddresses TunnelDecapOrch::getDstIpAddresses(std::string tunnelKey)
return tunnelTable[tunnelKey].dst_ip_addrs;
}

std::string TunnelDecapOrch::getDscpMode(const std::string &tunnelKey) const
{
auto iter = tunnelTable.find(tunnelKey);
if (iter == tunnelTable.end())
{
SWSS_LOG_INFO("Tunnel not found %s", tunnelKey.c_str());
return "";
}
return iter->second.dscp_mode;
}

bool TunnelDecapOrch::getQosMapId(const std::string &tunnelKey, const std::string &qos_table_type, sai_object_id_t &oid) const
{
auto iter = tunnelTable.find(tunnelKey);
if (iter == tunnelTable.end())
{
SWSS_LOG_INFO("Tunnel not found %s", tunnelKey.c_str());
return false;
}
if (qos_table_type == encap_tc_to_dscp_field_name)
{
oid = iter->second.encap_tc_to_dscp_map_id;
}
else if (qos_table_type == encap_tc_to_queue_field_name)
{
oid = iter->second.encap_tc_to_queue_map_id;
}
else
{
SWSS_LOG_ERROR("Unsupported qos type %s", qos_table_type.c_str());
return false;
}
return true;
}
14 changes: 9 additions & 5 deletions orchagent/tunneldecaporch.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,13 @@ struct TunnelTermEntry

struct TunnelEntry
{
sai_object_id_t tunnel_id; // tunnel id
sai_object_id_t overlay_intf_id; // overlay interface id
swss::IpAddresses dst_ip_addrs; // destination ip addresses
std::vector<TunnelTermEntry> tunnel_term_info; // tunnel_entry ids related to the tunnel abd ips related to the tunnel (all ips for tunnel entries that refer to this tunnel)
sai_object_id_t tunnel_id; // tunnel id
sai_object_id_t overlay_intf_id; // overlay interface id
swss::IpAddresses dst_ip_addrs; // destination ip addresses
std::vector<TunnelTermEntry> tunnel_term_info; // tunnel_entry ids related to the tunnel abd ips related to the tunnel (all ips for tunnel entries that refer to this tunnel)
std::string dscp_mode; // dscp_mode, will be used in muxorch
sai_object_id_t encap_tc_to_dscp_map_id; // TC_TO_DSCP map id, will be used in muxorch
sai_object_id_t encap_tc_to_queue_map_id; // TC_TO_QUEUE map id, will be used in muxorch
};

struct NexthopTunnel
Expand Down Expand Up @@ -65,7 +68,8 @@ class TunnelDecapOrch : public Orch
sai_object_id_t createNextHopTunnel(std::string tunnelKey, swss::IpAddress& ipAddr);
bool removeNextHopTunnel(std::string tunnelKey, swss::IpAddress& ipAddr);
swss::IpAddresses getDstIpAddresses(std::string tunnelKey);

std::string getDscpMode(const std::string &tunnelKey) const;
bool getQosMapId(const std::string &tunnelKey, const std::string &qos_table_type, sai_object_id_t &oid) const;
private:
TunnelTable tunnelTable;
ExistingIps existingIps;
Expand Down
2 changes: 1 addition & 1 deletion tests/mock_tests/routeorch_ut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ namespace routeorch_test
CFG_MUX_CABLE_TABLE_NAME,
CFG_PEER_SWITCH_TABLE_NAME
};
MuxOrch *mux_orch = new MuxOrch(m_config_db.get(), m_app_db.get(), mux_tables, tunnel_decap_orch, gNeighOrch, gFdbOrch);
MuxOrch *mux_orch = new MuxOrch(m_config_db.get(), mux_tables, tunnel_decap_orch, gNeighOrch, gFdbOrch);
gDirectory.set(mux_orch);

ASSERT_EQ(gFgNhgOrch, nullptr);
Expand Down

0 comments on commit a82a593

Please sign in to comment.