Skip to content

Commit e22d09a

Browse files
committed
[muxorch] Always use direct link for SoC IPs
Signed-off-by: Longxiang Lyu <lolv@microsoft.com>
1 parent a8e238a commit e22d09a

File tree

2 files changed

+54
-12
lines changed

2 files changed

+54
-12
lines changed

orchagent/muxorch.cpp

Lines changed: 49 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -351,14 +351,14 @@ static bool remove_nh_tunnel(sai_object_id_t nh_id, IpAddress& ipAddr)
351351
return true;
352352
}
353353

354-
MuxCable::MuxCable(string name, IpPrefix& srv_ip4, IpPrefix& srv_ip6, IpAddress peer_ip)
355-
:mux_name_(name), srv_ip4_(srv_ip4), srv_ip6_(srv_ip6), peer_ip4_(peer_ip)
354+
MuxCable::MuxCable(string name, IpPrefix& srv_ip4, IpPrefix& srv_ip6, IpAddress peer_ip, std::set<IpAddress> always_active_neighbors)
355+
:mux_name_(name), srv_ip4_(srv_ip4), srv_ip6_(srv_ip6), peer_ip4_(peer_ip), always_active_neighbors_(always_active_neighbors)
356356
{
357357
mux_orch_ = gDirectory.get<MuxOrch*>();
358358
mux_cb_orch_ = gDirectory.get<MuxCableOrch*>();
359359
mux_state_orch_ = gDirectory.get<MuxStateOrch*>();
360360

361-
nbr_handler_ = std::make_unique<MuxNbrHandler> (MuxNbrHandler());
361+
nbr_handler_ = std::make_unique<MuxNbrHandler> (MuxNbrHandler(always_active_neighbors_));
362362

363363
state_machine_handlers_.insert(handler_pair(MUX_STATE_INIT_ACTIVE, &MuxCable::stateInitActive));
364364
state_machine_handlers_.insert(handler_pair(MUX_STATE_STANDBY_ACTIVE, &MuxCable::stateActive));
@@ -534,7 +534,8 @@ bool MuxCable::nbrHandler(bool enable, bool update_rt)
534534
void MuxCable::updateNeighbor(NextHopKey nh, bool add)
535535
{
536536
sai_object_id_t tnh = mux_orch_->getNextHopTunnelId(MUX_TUNNEL, peer_ip4_);
537-
nbr_handler_->update(nh, tnh, add, state_);
537+
MuxState state = (always_active_neighbors_.count(nh.ip_address) != 0) ? MuxState::MUX_STATE_ACTIVE : state_;
538+
nbr_handler_->update(nh, tnh, add, state);
538539
if (add)
539540
{
540541
mux_orch_->addNexthop(nh, mux_name_);
@@ -545,6 +546,10 @@ void MuxCable::updateNeighbor(NextHopKey nh, bool add)
545546
}
546547
}
547548

549+
MuxNbrHandler::MuxNbrHandler(std::set<IpAddress> always_enabled_neighbors) : always_enabled_neighbors_(always_enabled_neighbors)
550+
{
551+
}
552+
548553
void MuxNbrHandler::update(NextHopKey nh, sai_object_id_t tunnelId, bool add, MuxState state)
549554
{
550555
SWSS_LOG_INFO("Neigh %s on %s, add %d, state %d",
@@ -611,7 +616,7 @@ bool MuxNbrHandler::enable(bool update_rt)
611616
neigh = NeighborEntry(it->first, alias_);
612617
if (!gNeighOrch->enableNeighbor(neigh))
613618
{
614-
SWSS_LOG_INFO("Enabling neigh failed for %s", neigh.ip_address.to_string().c_str());
619+
SWSS_LOG_NOTICE("Enabling neigh failed for %s", neigh.ip_address.to_string().c_str());
615620
return false;
616621
}
617622

@@ -650,6 +655,9 @@ bool MuxNbrHandler::enable(bool update_rt)
650655
/* Increment ref count for ECMP NH members */
651656
gNeighOrch->increaseNextHopRefCount(nh_key, nh_added);
652657

658+
if (always_enabled_neighbors_.count(it->first) != 0) {
659+
update_rt = false;
660+
}
653661
IpPrefix pfx = it->first.to_string();
654662
if (update_rt)
655663
{
@@ -671,9 +679,13 @@ bool MuxNbrHandler::disable(sai_object_id_t tnh)
671679
NeighborEntry neigh;
672680
MuxCableOrch* mux_cb_orch = gDirectory.get<MuxCableOrch*>();
673681

674-
auto it = neighbors_.begin();
675-
while (it != neighbors_.end())
682+
for (auto it = neighbors_.begin(); it != neighbors_.end(); ++it)
676683
{
684+
if (always_enabled_neighbors_.count(it->first) != 0) {
685+
SWSS_LOG_NOTICE("Skip disabling neigh %s on %s", it->first.to_string().c_str(), alias_.c_str());
686+
continue;
687+
}
688+
677689
SWSS_LOG_INFO("Disabling neigh %s on %s", it->first.to_string().c_str(), alias_.c_str());
678690

679691
/* Update NH to point to Tunnel nexhtop */
@@ -722,8 +734,6 @@ bool MuxNbrHandler::disable(sai_object_id_t tnh)
722734
{
723735
return false;
724736
}
725-
726-
it++;
727737
}
728738

729739
return true;
@@ -1208,7 +1218,36 @@ bool MuxOrch::handleMuxCfg(const Request& request)
12081218
auto srv_ip = request.getAttrIpPrefix("server_ipv4");
12091219
auto srv_ip6 = request.getAttrIpPrefix("server_ipv6");
12101220

1221+
std::set<IpAddress> always_active_neighbors;
1222+
std::string cable_type = "active-standby";
1223+
12111224
const auto& port_name = request.getKeyString(0);
1225+
1226+
for (const auto &name : request.getAttrFieldNames())
1227+
{
1228+
if (name == "soc_ipv4")
1229+
{
1230+
auto soc_ip = request.getAttrIpPrefix("soc_ipv4");
1231+
SWSS_LOG_NOTICE("%s: %s was added to always active list", port_name.c_str(), soc_ip.getIp().to_string().c_str());
1232+
always_active_neighbors.insert(soc_ip.getIp());
1233+
}
1234+
else if (name == "soc_ipv6")
1235+
{
1236+
auto soc_ip6 = request.getAttrIpPrefix("soc_ipv6");
1237+
SWSS_LOG_NOTICE("%s: %s was added to always active list", port_name.c_str(), soc_ip6.getIp().to_string().c_str());
1238+
always_active_neighbors.insert(soc_ip6.getIp());
1239+
}
1240+
else if (name == "cable_type")
1241+
{
1242+
cable_type = request.getAttrString("cable_type");
1243+
}
1244+
}
1245+
1246+
if (cable_type != "active-active")
1247+
{
1248+
always_active_neighbors.clear();
1249+
}
1250+
12121251
auto op = request.getOperation();
12131252

12141253
if (op == SET_COMMAND)
@@ -1226,7 +1265,7 @@ bool MuxOrch::handleMuxCfg(const Request& request)
12261265
}
12271266

12281267
mux_cable_tb_[port_name] = std::make_unique<MuxCable>
1229-
(MuxCable(port_name, srv_ip, srv_ip6, mux_peer_switch_));
1268+
(MuxCable(port_name, srv_ip, srv_ip6, mux_peer_switch_, always_active_neighbors));
12301269

12311270
SWSS_LOG_NOTICE("Mux entry for port '%s' was added", port_name.c_str());
12321271
}

orchagent/muxorch.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ typedef std::map<IpAddress, sai_object_id_t> MuxNeighbor;
5959
class MuxNbrHandler
6060
{
6161
public:
62-
MuxNbrHandler() = default;
62+
MuxNbrHandler(std::set<IpAddress> always_enabled_neighbors = {});
6363

6464
bool enable(bool update_rt);
6565
bool disable(sai_object_id_t);
@@ -68,6 +68,7 @@ class MuxNbrHandler
6868
sai_object_id_t getNextHopId(const NextHopKey);
6969

7070
private:
71+
std::set<IpAddress> always_enabled_neighbors_;
7172
MuxNeighbor neighbors_;
7273
string alias_;
7374
};
@@ -76,7 +77,7 @@ class MuxNbrHandler
7677
class MuxCable
7778
{
7879
public:
79-
MuxCable(string name, IpPrefix& srv_ip4, IpPrefix& srv_ip6, IpAddress peer_ip);
80+
MuxCable(string name, IpPrefix& srv_ip4, IpPrefix& srv_ip6, IpAddress peer_ip, std::set<IpAddress> always_active_neighbors);
8081

8182
bool isActive() const
8283
{
@@ -115,6 +116,8 @@ class MuxCable
115116
IpPrefix srv_ip4_, srv_ip6_;
116117
IpAddress peer_ip4_;
117118

119+
std::set<IpAddress> always_active_neighbors_;
120+
118121
MuxOrch *mux_orch_;
119122
MuxCableOrch *mux_cb_orch_;
120123
MuxStateOrch *mux_state_orch_;

0 commit comments

Comments
 (0)