17
17
#include " tokenize.h"
18
18
#include " crmorch.h"
19
19
#include " saihelper.h"
20
+ #include " directory.h"
20
21
21
22
#include " taskworker.h"
22
23
#include " pbutils.h"
24
+ #include " dashrouteorch.h"
23
25
24
26
using namespace std ;
25
27
using namespace swss ;
26
28
29
+ extern Directory<Orch*> gDirectory ;
27
30
extern std::unordered_map<std::string, sai_object_id_t > gVnetNameToId ;
28
31
extern sai_dash_vip_api_t * sai_dash_vip_api;
29
32
extern sai_dash_direction_lookup_api_t * sai_dash_direction_lookup_api;
@@ -37,6 +40,21 @@ DashOrch::DashOrch(DBConnector *db, vector<string> &tableName, ZmqServer *zmqSer
37
40
SWSS_LOG_ENTER ();
38
41
}
39
42
43
+ bool DashOrch::getRouteTypeActions (dash::route_type::RoutingType routing_type, dash::route_type::RouteType& route_type)
44
+ {
45
+ SWSS_LOG_ENTER ();
46
+
47
+ auto it = routing_type_entries_.find (routing_type);
48
+ if (it == routing_type_entries_.end ())
49
+ {
50
+ SWSS_LOG_WARN (" Routing type %s not found" , dash::route_type::RoutingType_Name (routing_type).c_str ());
51
+ return false ;
52
+ }
53
+
54
+ route_type = it->second ;
55
+ return true ;
56
+ }
57
+
40
58
bool DashOrch::addApplianceEntry (const string& appliance_id, const dash::appliance::Appliance &entry)
41
59
{
42
60
SWSS_LOG_ENTER ();
@@ -191,34 +209,34 @@ void DashOrch::doTaskApplianceTable(ConsumerBase& consumer)
191
209
}
192
210
}
193
211
194
- bool DashOrch::addRoutingTypeEntry (const string & routing_type, const dash::route_type::RouteType &entry)
212
+ bool DashOrch::addRoutingTypeEntry (const dash::route_type::RoutingType & routing_type, const dash::route_type::RouteType &entry)
195
213
{
196
214
SWSS_LOG_ENTER ();
197
215
198
216
if (routing_type_entries_.find (routing_type) != routing_type_entries_.end ())
199
217
{
200
- SWSS_LOG_WARN (" Routing type entry already exists for %s" , routing_type.c_str ());
218
+ SWSS_LOG_WARN (" Routing type entry already exists for %s" , dash::route_type::RoutingType_Name ( routing_type) .c_str ());
201
219
return true ;
202
220
}
203
221
204
222
routing_type_entries_[routing_type] = entry;
205
- SWSS_LOG_NOTICE (" Routing type entry added %s" , routing_type.c_str ());
223
+ SWSS_LOG_NOTICE (" Routing type entry added %s" , dash::route_type::RoutingType_Name ( routing_type) .c_str ());
206
224
207
225
return true ;
208
226
}
209
227
210
- bool DashOrch::removeRoutingTypeEntry (const string & routing_type)
228
+ bool DashOrch::removeRoutingTypeEntry (const dash::route_type::RoutingType & routing_type)
211
229
{
212
230
SWSS_LOG_ENTER ();
213
231
214
232
if (routing_type_entries_.find (routing_type) == routing_type_entries_.end ())
215
233
{
216
- SWSS_LOG_WARN (" Routing type entry does not exist for %s" , routing_type.c_str ());
234
+ SWSS_LOG_WARN (" Routing type entry does not exist for %s" , dash::route_type::RoutingType_Name ( routing_type) .c_str ());
217
235
return true ;
218
236
}
219
237
220
238
routing_type_entries_.erase (routing_type);
221
- SWSS_LOG_NOTICE (" Routing type entry removed for %s" , routing_type.c_str ());
239
+ SWSS_LOG_NOTICE (" Routing type entry removed for %s" , dash::route_type::RoutingType_Name ( routing_type) .c_str ());
222
240
223
241
return true ;
224
242
}
@@ -231,16 +249,27 @@ void DashOrch::doTaskRoutingTypeTable(ConsumerBase& consumer)
231
249
while (it != consumer.m_toSync .end ())
232
250
{
233
251
KeyOpFieldsValuesTuple t = it->second ;
234
- string routing_type = kfvKey (t);
252
+ string routing_type_str = kfvKey (t);
235
253
string op = kfvOp (t);
254
+ dash::route_type::RoutingType routing_type;
255
+
256
+ std::transform (routing_type_str.begin (), routing_type_str.end (), routing_type_str.begin (), ::toupper);
257
+ routing_type_str = " ROUTING_TYPE_" + routing_type_str;
258
+
259
+ if (!dash::route_type::RoutingType_Parse (routing_type_str, &routing_type))
260
+ {
261
+ SWSS_LOG_WARN (" Invalid routing type %s" , routing_type_str.c_str ());
262
+ it = consumer.m_toSync .erase (it);
263
+ continue ;
264
+ }
236
265
237
266
if (op == SET_COMMAND)
238
267
{
239
268
dash::route_type::RouteType entry;
240
269
241
270
if (!parsePbMessage (kfvFieldsValues (t), entry))
242
271
{
243
- SWSS_LOG_WARN (" Requires protobuff at routing type :%s" , routing_type .c_str ());
272
+ SWSS_LOG_WARN (" Requires protobuff at routing type :%s" , routing_type_str .c_str ());
244
273
it = consumer.m_toSync .erase (it);
245
274
continue ;
246
275
}
@@ -358,6 +387,23 @@ bool DashOrch::addEniObject(const string& eni, EniEntry& entry)
358
387
eni_attr.value .u32 = app_entry.vm_vni ();
359
388
eni_attrs.push_back (eni_attr);
360
389
390
+ if (entry.metadata .has_pl_underlay_sip ())
391
+ {
392
+ eni_attr.id = SAI_ENI_ATTR_PL_UNDERLAY_SIP;
393
+ to_sai (entry.metadata .pl_underlay_sip (), eni_attr.value .ipaddr );
394
+ eni_attrs.push_back (eni_attr);
395
+ }
396
+
397
+ // auto eni_route_it = eni_route_entries_.find(eni);
398
+ // if (eni_route_it != eni_route_entries_.end())
399
+ // {
400
+ // SWSS_LOG_INFO("ENI %s has route group %s", eni.c_str(), eni_route_it->second.group_id().c_str());
401
+ // DashRouteOrch *dash_route_orch = gDirectory.get<DashRouteOrch*>();
402
+ // eni_attr.id = SAI_ENI_ATTR_OUTBOUND_ROUTING_GROUP_ID;
403
+ // eni_attr.value.oid = dash_route_orch->getRouteGroupOid(eni_route_it->second.group_id());
404
+ // eni_attrs.push_back(eni_attr);
405
+ // }
406
+
361
407
sai_status_t status = sai_dash_eni_api->create_eni (&eni_id, gSwitchId ,
362
408
(uint32_t )eni_attrs.size (), eni_attrs.data ());
363
409
if (status != SAI_STATUS_SUCCESS)
@@ -653,6 +699,154 @@ void DashOrch::doTaskQosTable(ConsumerBase& consumer)
653
699
}
654
700
}
655
701
702
+ bool DashOrch::setEniRoute (const std::string& eni, const dash::eni_route::EniRoute& entry)
703
+ {
704
+ SWSS_LOG_ENTER ();
705
+
706
+
707
+ if (eni_entries_.find (eni) == eni_entries_.end ())
708
+ {
709
+ SWSS_LOG_INFO (" ENI %s not yet created, not programming ENI route entry" , eni.c_str ());
710
+ return false ;
711
+ }
712
+
713
+ DashRouteOrch *dash_route_orch = gDirectory .get <DashRouteOrch*>();
714
+ sai_object_id_t route_group_oid = dash_route_orch->getRouteGroupOid (entry.group_id ());
715
+ if (route_group_oid == SAI_NULL_OBJECT_ID)
716
+ {
717
+ SWSS_LOG_INFO (" Route group not yet created, skipping route entry for ENI %s" , entry.group_id ().c_str ());
718
+ return false ;
719
+ }
720
+
721
+ std::string old_group_id;
722
+ if (eni_route_entries_.find (eni) != eni_route_entries_.end ())
723
+ {
724
+ if (eni_route_entries_[eni].group_id () != entry.group_id ())
725
+ {
726
+ old_group_id = eni_route_entries_[eni].group_id ();
727
+ SWSS_LOG_INFO (" Updating route entry from %s to %s for ENI %s" , eni_route_entries_[eni].group_id ().c_str (), entry.group_id ().c_str (), eni.c_str ());
728
+ }
729
+ else
730
+ {
731
+ SWSS_LOG_WARN (" Duplicate ENI route entry already exists for %s" , eni.c_str ());
732
+ return true ;
733
+ }
734
+ }
735
+
736
+ sai_attribute_t eni_attr;
737
+ eni_attr.id = SAI_ENI_ATTR_OUTBOUND_ROUTING_GROUP_ID;
738
+ eni_attr.value .oid = route_group_oid;
739
+
740
+ sai_status_t status = sai_dash_eni_api->set_eni_attribute (eni_entries_[eni].eni_id ,
741
+ &eni_attr);
742
+
743
+ if (status != SAI_STATUS_SUCCESS)
744
+ {
745
+ SWSS_LOG_ERROR (" Failed to set ENI route group for %s" , eni.c_str ());
746
+ task_process_status handle_status = handleSaiSetStatus ((sai_api_t ) SAI_API_DASH_ENI, status);
747
+ if (handle_status != task_success)
748
+ {
749
+ return parseHandleSaiStatusFailure (handle_status);
750
+ }
751
+ }
752
+ eni_route_entries_[eni] = entry;
753
+ dash_route_orch->bindRouteGroup (entry.group_id ());
754
+
755
+ if (!old_group_id.empty ())
756
+ {
757
+ dash_route_orch->unbindRouteGroup (old_group_id);
758
+ }
759
+
760
+ SWSS_LOG_NOTICE (" Updated ENI route group for %s to route group %s" , eni.c_str (), entry.group_id ().c_str ());
761
+ return true ;
762
+ }
763
+
764
+ bool DashOrch::removeEniRoute (const std::string& eni)
765
+ {
766
+ SWSS_LOG_ENTER ();
767
+
768
+ if (eni_route_entries_.find (eni) == eni_route_entries_.end ())
769
+ {
770
+ SWSS_LOG_WARN (" ENI route entry does not exist for %s" , eni.c_str ());
771
+ return true ;
772
+ }
773
+
774
+ if (eni_entries_.find (eni) != eni_entries_.end ())
775
+ {
776
+ sai_attribute_t eni_attr;
777
+ eni_attr.id = SAI_ENI_ATTR_OUTBOUND_ROUTING_GROUP_ID;
778
+ eni_attr.value .oid = SAI_NULL_OBJECT_ID;
779
+
780
+ sai_status_t status = sai_dash_eni_api->set_eni_attribute (eni_entries_[eni].eni_id ,
781
+ &eni_attr);
782
+ if (status != SAI_STATUS_SUCCESS)
783
+ {
784
+ SWSS_LOG_ERROR (" Failed to remove ENI route for %s" , eni.c_str ());
785
+ task_process_status handle_status = handleSaiSetStatus ((sai_api_t ) SAI_API_DASH_ENI, status);
786
+ if (handle_status != task_success)
787
+ {
788
+ return parseHandleSaiStatusFailure (handle_status);
789
+ }
790
+ }
791
+ }
792
+
793
+ DashRouteOrch *dash_route_orch = gDirectory .get <DashRouteOrch*>();
794
+ dash_route_orch->unbindRouteGroup (eni_route_entries_[eni].group_id ());
795
+ eni_route_entries_.erase (eni);
796
+
797
+ SWSS_LOG_NOTICE (" Removed ENI route entry for %s" , eni.c_str ());
798
+
799
+ return true ;
800
+ }
801
+
802
+ void DashOrch::doTaskEniRouteTable (ConsumerBase& consumer)
803
+ {
804
+ auto it = consumer.m_toSync .begin ();
805
+ while (it != consumer.m_toSync .end ())
806
+ {
807
+ KeyOpFieldsValuesTuple t = it->second ;
808
+ string eni = kfvKey (t);
809
+ string op = kfvOp (t);
810
+
811
+ if (op == SET_COMMAND)
812
+ {
813
+ dash::eni_route::EniRoute entry;
814
+
815
+ if (!parsePbMessage (kfvFieldsValues (t), entry))
816
+ {
817
+ SWSS_LOG_WARN (" Requires protobuf at ENI route:%s" , eni.c_str ());
818
+ it = consumer.m_toSync .erase (it);
819
+ continue ;
820
+ }
821
+
822
+ if (setEniRoute (eni, entry))
823
+ {
824
+ it = consumer.m_toSync .erase (it);
825
+ }
826
+ else
827
+ {
828
+ it++;
829
+ }
830
+ }
831
+ else if (op == DEL_COMMAND)
832
+ {
833
+ if (removeEniRoute (eni))
834
+ {
835
+ it = consumer.m_toSync .erase (it);
836
+ }
837
+ else
838
+ {
839
+ it++;
840
+ }
841
+ }
842
+ else
843
+ {
844
+ SWSS_LOG_ERROR (" Unknown operation %s" , op.c_str ());
845
+ it = consumer.m_toSync .erase (it);
846
+ }
847
+ }
848
+ }
849
+
656
850
void DashOrch::doTask (ConsumerBase& consumer)
657
851
{
658
852
SWSS_LOG_ENTER ();
@@ -677,6 +871,10 @@ void DashOrch::doTask(ConsumerBase& consumer)
677
871
{
678
872
doTaskQosTable (consumer);
679
873
}
874
+ else if (tn == APP_DASH_ENI_ROUTE_TABLE_NAME)
875
+ {
876
+ doTaskEniRouteTable (consumer);
877
+ }
680
878
else
681
879
{
682
880
SWSS_LOG_ERROR (" Unknown table: %s" , tn.c_str ());
0 commit comments