3
3
#include " orch.h"
4
4
#include " sai.h"
5
5
#include " saiextensions.h"
6
+ #include " bfdorch.h"
6
7
#include " dashorch.h"
7
8
#include " crmorch.h"
8
9
#include " saihelper.h"
@@ -58,9 +59,10 @@ static const map<sai_ha_scope_event_t, string> sai_ha_scope_event_type_name =
58
59
{ SAI_HA_SCOPE_EVENT_SPLIT_BRAIN_DETECTED, " split_brain_detected" }
59
60
};
60
61
61
- DashHaOrch::DashHaOrch (DBConnector *db, const vector<string> &tables, DashOrch *dash_orch, DBConnector *app_state_db, ZmqServer *zmqServer) :
62
+ DashHaOrch::DashHaOrch (DBConnector *db, const vector<string> &tables, DashOrch *dash_orch, BfdOrch *bfd_orch, DBConnector *app_state_db, ZmqServer *zmqServer) :
62
63
ZmqOrch(db, tables, zmqServer),
63
- m_dash_orch(dash_orch)
64
+ m_dash_orch(dash_orch),
65
+ m_bfd_orch(bfd_orch)
64
66
{
65
67
SWSS_LOG_ENTER ();
66
68
@@ -524,7 +526,7 @@ bool DashHaOrch::addHaScopeEntry(const std::string &key, const dash::ha_scope::H
524
526
return parseHandleSaiStatusFailure (handle_status);
525
527
}
526
528
}
527
- m_ha_scope_entries[key] = HaScopeEntry {sai_ha_scope_oid, entry, getNowTime ()};
529
+ m_ha_scope_entries[key] = HaScopeEntry {sai_ha_scope_oid, entry, getNowTime (), SAI_DASH_HA_STATE_DEAD, getNowTime () };
528
530
SWSS_LOG_NOTICE (" Created HA Scope object for %s" , key.c_str ());
529
531
530
532
// set HA Scope ID to ENI
@@ -574,6 +576,18 @@ bool DashHaOrch::setHaScopeHaRole(const std::string &key, const dash::ha_scope::
574
576
575
577
sai_object_id_t ha_scope_id = m_ha_scope_entries[key].ha_scope_id ;
576
578
579
+ /*
580
+ Remove bfd passive sessions in planned shutdown (scope == DPU)
581
+ */
582
+ if (entry.ha_role () == dash::types::HA_ROLE_DEAD
583
+ && !m_ha_set_entries.empty ())
584
+ {
585
+ if (has_dpu_scope ())
586
+ {
587
+ m_bfd_orch->removeAllSoftwareBfdSessions ();
588
+ }
589
+ }
590
+
577
591
sai_attribute_t ha_scope_attr;
578
592
ha_scope_attr.id = SAI_HA_SCOPE_ATTR_DASH_HA_ROLE;
579
593
ha_scope_attr.value .u32 = to_sai (entry.ha_role ());
@@ -806,6 +820,68 @@ void DashHaOrch::doTaskHaScopeTable(ConsumerBase &consumer)
806
820
}
807
821
}
808
822
823
+ void DashHaOrch::doTaskBfdSessionTable (ConsumerBase &consumer)
824
+ {
825
+ SWSS_LOG_ENTER ();
826
+
827
+ auto it = consumer.m_toSync .begin ();
828
+ while (it != consumer.m_toSync .end ())
829
+ {
830
+ KeyOpFieldsValuesTuple tuple = it->second ;
831
+ const auto & key = kfvKey (tuple);
832
+ const auto & op = kfvOp (tuple);
833
+
834
+ SWSS_LOG_DEBUG (" Processing BFD Session table" );
835
+
836
+ if (op == SET_COMMAND)
837
+ {
838
+ if (has_eni_scope ())
839
+ {
840
+ m_bfd_orch->createSoftwareBfdSession (key, kfvFieldsValues (tuple));
841
+ }
842
+
843
+ // Per HLD, once the state is moved to Active/Standby/Standalone state, we will create the BFD responder on DPU.
844
+ bool has_dpu_scope_ha_state_activated = false ;
845
+ if (has_dpu_scope ())
846
+ {
847
+ for (const auto & ha_scope_entry : m_ha_scope_entries)
848
+ {
849
+ if (in (ha_scope_entry.second .ha_state , {SAI_DASH_HA_STATE_ACTIVE,
850
+ SAI_DASH_HA_STATE_STANDBY,
851
+ SAI_DASH_HA_STATE_STANDALONE}))
852
+ {
853
+ has_dpu_scope_ha_state_activated = true ;
854
+ break ;
855
+ }
856
+ }
857
+ }
858
+
859
+ if (has_dpu_scope_ha_state_activated)
860
+ {
861
+ m_bfd_orch->createSoftwareBfdSession (key, kfvFieldsValues (tuple));
862
+ }
863
+
864
+ /*
865
+ Caching BFD sessions for planned ha_role up->down->up.
866
+ */
867
+ if ((!has_eni_scope ()))
868
+ {
869
+ SWSS_LOG_INFO (" Caching BFD session %s as there is no non-dead DPU HA Scope" , key.c_str ());
870
+
871
+ m_bfd_session_pending_creation[key] = kfvFieldsValues (tuple);
872
+ }
873
+
874
+ it = consumer.m_toSync .erase (it);
875
+ }
876
+ else if (op == DEL_COMMAND)
877
+ {
878
+ m_bfd_orch->removeSoftwareBfdSession (key);
879
+ it = consumer.m_toSync .erase (it);
880
+ m_bfd_session_pending_creation.erase (key);
881
+ }
882
+ }
883
+ }
884
+
809
885
void DashHaOrch::doTask (ConsumerBase &consumer)
810
886
{
811
887
SWSS_LOG_ENTER ();
@@ -817,7 +893,12 @@ void DashHaOrch::doTask(ConsumerBase &consumer)
817
893
else if (consumer.getTableName () == APP_DASH_HA_SCOPE_TABLE_NAME)
818
894
{
819
895
doTaskHaScopeTable (consumer);
820
- } else
896
+ }
897
+ else if (consumer.getTableName () == APP_BFD_SESSION_TABLE_NAME)
898
+ {
899
+ doTaskBfdSessionTable (consumer);
900
+ }
901
+ else
821
902
{
822
903
SWSS_LOG_ERROR (" Unknown table: %s" , consumer.getTableName ().c_str ());
823
904
}
@@ -929,6 +1010,17 @@ void DashHaOrch::doTask(NotificationConsumer &consumer)
929
1010
}
930
1011
931
1012
fvs.push_back ({" ha_state" , sai_ha_state_name.at (ha_scope_event[i].ha_state )});
1013
+ fvs.push_back ({" ha_state_start_time" , to_string (now_time)});
1014
+
1015
+ m_ha_scope_entries[key].ha_state = ha_scope_event[i].ha_state ;
1016
+ m_ha_scope_entries[key].last_state_start_time = now_time;
1017
+
1018
+ if (has_dpu_scope () && in (ha_scope_event[i].ha_state , {SAI_DASH_HA_STATE_ACTIVE,
1019
+ SAI_DASH_HA_STATE_STANDBY,
1020
+ SAI_DASH_HA_STATE_STANDALONE}))
1021
+ {
1022
+ processCachedBfdSessions ();
1023
+ }
932
1024
break ;
933
1025
default :
934
1026
SWSS_LOG_ERROR (" Unknown HA Scope event type %d for %s" , event_type, key.c_str ());
@@ -1113,4 +1205,42 @@ bool DashHaOrch::convertKfvToHaScopePb(const std::vector<FieldValueTuple> &kfv,
1113
1205
}
1114
1206
}
1115
1207
return true ;
1116
- }
1208
+ }
1209
+
1210
+ bool DashHaOrch::has_dpu_scope ()
1211
+ {
1212
+ for (const auto & ha_set_entry : m_ha_set_entries)
1213
+ {
1214
+ if (ha_set_entry.second .metadata .scope () == dash::types::HA_SCOPE_DPU)
1215
+ {
1216
+ return true ;
1217
+ }
1218
+ }
1219
+ return false ;
1220
+ }
1221
+
1222
+ bool DashHaOrch::has_eni_scope ()
1223
+ {
1224
+ for (const auto & ha_set_entry : m_ha_set_entries)
1225
+ {
1226
+ if (ha_set_entry.second .metadata .scope () == dash::types::HA_SCOPE_ENI)
1227
+ {
1228
+ return true ;
1229
+ }
1230
+ }
1231
+ return false ;
1232
+ }
1233
+
1234
+ void DashHaOrch::processCachedBfdSessions ()
1235
+ {
1236
+ /*
1237
+ Create bfd passive sessions cached when moving out of DEAD role (scope == DPU)
1238
+ */
1239
+ if (has_dpu_scope () && !m_bfd_session_pending_creation.empty ())
1240
+ {
1241
+ for (const auto & bfd_entry : m_bfd_session_pending_creation)
1242
+ {
1243
+ m_bfd_orch->createSoftwareBfdSession (bfd_entry.first , bfd_entry.second );
1244
+ }
1245
+ }
1246
+ }
0 commit comments