Skip to content

Commit b5b9a56

Browse files
committed
[muxorch] Skip programming SoC IP kernel tunnel route
Signed-off-by: Longxiang Lyu <[email protected]>
1 parent ec507a4 commit b5b9a56

File tree

2 files changed

+56
-25
lines changed

2 files changed

+56
-25
lines changed

orchagent/muxorch.cpp

+33-18
Original file line numberDiff line numberDiff line change
@@ -359,8 +359,8 @@ static bool remove_nh_tunnel(sai_object_id_t nh_id, IpAddress& ipAddr)
359359
return true;
360360
}
361361

362-
MuxCable::MuxCable(string name, IpPrefix& srv_ip4, IpPrefix& srv_ip6, IpAddress peer_ip, std::set<IpAddress> skip_neighbors)
363-
:mux_name_(name), srv_ip4_(srv_ip4), srv_ip6_(srv_ip6), peer_ip4_(peer_ip), skip_neighbors_(skip_neighbors)
362+
MuxCable::MuxCable(string name, IpPrefix& srv_ip4, IpPrefix& srv_ip6, IpAddress peer_ip)
363+
:mux_name_(name), srv_ip4_(srv_ip4), srv_ip6_(srv_ip6), peer_ip4_(peer_ip)
364364
{
365365
mux_orch_ = gDirectory.get<MuxOrch*>();
366366
mux_cb_orch_ = gDirectory.get<MuxCableOrch*>();
@@ -543,11 +543,6 @@ bool MuxCable::nbrHandler(bool enable, bool update_rt)
543543
void MuxCable::updateNeighbor(NextHopKey nh, bool add)
544544
{
545545
sai_object_id_t tnh = mux_orch_->getNextHopTunnelId(MUX_TUNNEL, peer_ip4_);
546-
if (add && skip_neighbors_.find(nh.ip_address) != skip_neighbors_.end())
547-
{
548-
SWSS_LOG_INFO("Skip update neighbor %s on %s", nh.ip_address.to_string().c_str(), nh.alias.c_str());
549-
return;
550-
}
551546
nbr_handler_->update(nh, tnh, add, state_);
552547
if (add)
553548
{
@@ -564,7 +559,6 @@ void MuxNbrHandler::update(NextHopKey nh, sai_object_id_t tunnelId, bool add, Mu
564559
SWSS_LOG_INFO("Neigh %s on %s, add %d, state %d",
565560
nh.ip_address.to_string().c_str(), nh.alias.c_str(), add, state);
566561

567-
MuxCableOrch* mux_cb_orch = gDirectory.get<MuxCableOrch*>();
568562
IpPrefix pfx = nh.ip_address.to_string();
569563

570564
if (add)
@@ -591,7 +585,7 @@ void MuxNbrHandler::update(NextHopKey nh, sai_object_id_t tunnelId, bool add, Mu
591585
case MuxState::MUX_STATE_STANDBY:
592586
neighbors_[nh.ip_address] = tunnelId;
593587
gNeighOrch->disableNeighbor(nh);
594-
mux_cb_orch->addTunnelRoute(nh);
588+
updateTunnelRoute(nh, true);
595589
create_route(pfx, tunnelId);
596590
break;
597591
default:
@@ -606,7 +600,7 @@ void MuxNbrHandler::update(NextHopKey nh, sai_object_id_t tunnelId, bool add, Mu
606600
if (state == MuxState::MUX_STATE_STANDBY)
607601
{
608602
remove_route(pfx);
609-
mux_cb_orch->removeTunnelRoute(nh);
603+
updateTunnelRoute(nh, false);
610604
}
611605
neighbors_.erase(nh.ip_address);
612606
}
@@ -615,7 +609,6 @@ void MuxNbrHandler::update(NextHopKey nh, sai_object_id_t tunnelId, bool add, Mu
615609
bool MuxNbrHandler::enable(bool update_rt)
616610
{
617611
NeighborEntry neigh;
618-
MuxCableOrch* mux_cb_orch = gDirectory.get<MuxCableOrch*>();
619612

620613
auto it = neighbors_.begin();
621614
while (it != neighbors_.end())
@@ -671,7 +664,7 @@ bool MuxNbrHandler::enable(bool update_rt)
671664
{
672665
return false;
673666
}
674-
mux_cb_orch->removeTunnelRoute(nh_key);
667+
updateTunnelRoute(nh_key, false);
675668
}
676669

677670
it++;
@@ -683,7 +676,6 @@ bool MuxNbrHandler::enable(bool update_rt)
683676
bool MuxNbrHandler::disable(sai_object_id_t tnh)
684677
{
685678
NeighborEntry neigh;
686-
MuxCableOrch* mux_cb_orch = gDirectory.get<MuxCableOrch*>();
687679

688680
auto it = neighbors_.begin();
689681
while (it != neighbors_.end())
@@ -729,7 +721,7 @@ bool MuxNbrHandler::disable(sai_object_id_t tnh)
729721
return false;
730722
}
731723

732-
mux_cb_orch->addTunnelRoute(nh_key);
724+
updateTunnelRoute(nh_key, true);
733725

734726
IpPrefix pfx = it->first.to_string();
735727
if (create_route(pfx, it->second) != SAI_STATUS_SUCCESS)
@@ -754,6 +746,27 @@ sai_object_id_t MuxNbrHandler::getNextHopId(const NextHopKey nhKey)
754746
return SAI_NULL_OBJECT_ID;
755747
}
756748

749+
void MuxNbrHandler::updateTunnelRoute(NextHopKey nh, bool add)
750+
{
751+
MuxOrch* mux_orch = gDirectory.get<MuxOrch*>();
752+
MuxCableOrch* mux_cb_orch = gDirectory.get<MuxCableOrch*>();
753+
754+
if (mux_orch->isSkipNeighbor(nh.ip_address))
755+
{
756+
SWSS_LOG_INFO("Skip updating neighbor %s, add %d", nh.ip_address.to_string().c_str(), add);
757+
return;
758+
}
759+
760+
if (add)
761+
{
762+
mux_cb_orch->addTunnelRoute(nh);
763+
}
764+
else
765+
{
766+
mux_cb_orch->removeTunnelRoute(nh);
767+
}
768+
}
769+
757770
std::map<std::string, AclTable> MuxAclHandler::acl_table_;
758771

759772
MuxAclHandler::MuxAclHandler(sai_object_id_t port, string alias)
@@ -971,7 +984,7 @@ bool MuxOrch::isNeighborActive(const IpAddress& nbr, const MacAddress& mac, stri
971984

972985
if (ptr)
973986
{
974-
return (ptr->isActive() || ptr->isSkipNeighbor(nbr));
987+
return ptr->isActive();
975988
}
976989

977990
string port;
@@ -985,15 +998,15 @@ bool MuxOrch::isNeighborActive(const IpAddress& nbr, const MacAddress& mac, stri
985998
if (!port.empty() && isMuxExists(port))
986999
{
9871000
MuxCable* ptr = getMuxCable(port);
988-
return (ptr->isActive() || ptr->isSkipNeighbor(nbr));
1001+
return ptr->isActive();
9891002
}
9901003

9911004
NextHopKey nh_key = NextHopKey(nbr, alias);
9921005
string curr_port = getNexthopMuxName(nh_key);
9931006
if (port.empty() && !curr_port.empty() && isMuxExists(curr_port))
9941007
{
9951008
MuxCable* ptr = getMuxCable(curr_port);
996-
return (ptr->isActive() || ptr->isSkipNeighbor(nbr));
1009+
return ptr->isActive();
9971010
}
9981011

9991012
return true;
@@ -1289,7 +1302,8 @@ bool MuxOrch::handleMuxCfg(const Request& request)
12891302
}
12901303

12911304
mux_cable_tb_[port_name] = std::make_unique<MuxCable>
1292-
(MuxCable(port_name, srv_ip, srv_ip6, mux_peer_switch_, skip_neighbors));
1305+
(MuxCable(port_name, srv_ip, srv_ip6, mux_peer_switch_));
1306+
addSkipNeighbors(skip_neighbors);
12931307

12941308
SWSS_LOG_NOTICE("Mux entry for port '%s' was added", port_name.c_str());
12951309
}
@@ -1301,6 +1315,7 @@ bool MuxOrch::handleMuxCfg(const Request& request)
13011315
return true;
13021316
}
13031317

1318+
removeSkipNeighbors(skip_neighbors);
13041319
mux_cable_tb_.erase(port_name);
13051320

13061321
SWSS_LOG_NOTICE("Mux cable for port '%s' was removed", port_name.c_str());

orchagent/muxorch.h

+23-7
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ class MuxNbrHandler
6767

6868
sai_object_id_t getNextHopId(const NextHopKey);
6969

70+
private:
71+
inline void updateTunnelRoute(NextHopKey, bool = true);
72+
7073
private:
7174
MuxNeighbor neighbors_;
7275
string alias_;
@@ -76,7 +79,7 @@ class MuxNbrHandler
7679
class MuxCable
7780
{
7881
public:
79-
MuxCable(string name, IpPrefix& srv_ip4, IpPrefix& srv_ip6, IpAddress peer_ip, std::set<IpAddress> skip_neighbors);
82+
MuxCable(string name, IpPrefix& srv_ip4, IpPrefix& srv_ip6, IpAddress peer_ip);
8083

8184
bool isActive() const
8285
{
@@ -97,10 +100,6 @@ class MuxCable
97100
{
98101
return nbr_handler_->getNextHopId(nh);
99102
}
100-
bool isSkipNeighbor(const IpAddress& nbr)
101-
{
102-
return (skip_neighbors_.find(nbr) != skip_neighbors_.end());
103-
}
104103

105104
private:
106105
bool stateActive();
@@ -119,8 +118,6 @@ class MuxCable
119118
IpPrefix srv_ip4_, srv_ip6_;
120119
IpAddress peer_ip4_;
121120

122-
std::set<IpAddress> skip_neighbors_;
123-
124121
MuxOrch *mux_orch_;
125122
MuxCableOrch *mux_cb_orch_;
126123
MuxStateOrch *mux_state_orch_;
@@ -180,6 +177,11 @@ class MuxOrch : public Orch2, public Observer, public Subject
180177
return mux_cable_tb_.at(portName).get();
181178
}
182179

180+
bool isSkipNeighbor(const IpAddress& nbr)
181+
{
182+
return (skip_neighbors_.find(nbr) != skip_neighbors_.end());
183+
}
184+
183185
MuxCable* findMuxCableInSubnet(IpAddress);
184186
bool isNeighborActive(const IpAddress&, const MacAddress&, string&);
185187
void update(SubjectType, void *);
@@ -212,6 +214,19 @@ class MuxOrch : public Orch2, public Observer, public Subject
212214
void createStandaloneTunnelRoute(IpAddress neighborIp);
213215
void removeStandaloneTunnelRoute(IpAddress neighborIp);
214216

217+
void addSkipNeighbors(const std::set<IpAddress> &neighbors)
218+
{
219+
skip_neighbors_.insert(neighbors.begin(), neighbors.end());
220+
}
221+
222+
void removeSkipNeighbors(const std::set<IpAddress> &neighbors)
223+
{
224+
for (const IpAddress &neighbor : neighbors)
225+
{
226+
skip_neighbors_.erase(neighbor);
227+
}
228+
}
229+
215230
IpAddress mux_peer_switch_ = 0x0;
216231
sai_object_id_t mux_tunnel_id_ = SAI_NULL_OBJECT_ID;
217232

@@ -227,6 +242,7 @@ class MuxOrch : public Orch2, public Observer, public Subject
227242

228243
MuxCfgRequest request_;
229244
std::set<IpAddress> standalone_tunnel_neighbors_;
245+
std::set<IpAddress> skip_neighbors_;
230246
};
231247

232248
const request_description_t mux_cable_request_description = {

0 commit comments

Comments
 (0)