Skip to content

Commit 97383d3

Browse files
Merge branch 'pr2' into add-p4orch
2 parents 07831eb + 988c7ff commit 97383d3

File tree

4 files changed

+204
-74
lines changed

4 files changed

+204
-74
lines changed

orchagent/orch.cpp

+12-3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include "orch.h"
99

1010
#include "subscriberstatetable.h"
11+
#include "converter.h"
1112
#include "portsorch.h"
1213
#include "tokenize.h"
1314
#include "logger.h"
@@ -44,7 +45,7 @@ Orch::Orch(DBConnector *db, const vector<table_name_with_pri_t> &tableNames_with
4445
}
4546
}
4647

47-
Orch::Orch(const vector<TableConnector>& tables)
48+
Orch::Orch(const vect
4849
{
4950
for (auto it : tables)
5051
{
@@ -878,7 +879,15 @@ void Orch2::doTask(Consumer &consumer)
878879
while (it != consumer.m_toSync.end())
879880
{
880881
bool erase_from_queue = true;
882+
bool sync_mode = false;
881883
ReturnCode rc;
884+
for (const auto &kv : kfvFieldsValues(it->second))
885+
{
886+
if (to_upper(fvField(kv)) == "SYNC_MODE" && to_upper(fvValue(kv)) == "TRUE")
887+
{
888+
sync_mode = true;
889+
}
890+
}
882891
try
883892
{
884893
request_.parse(it->second);
@@ -929,13 +938,13 @@ void Orch2::doTask(Consumer &consumer)
929938
SWSS_LOG_ERROR("%s", rc.message().c_str());
930939
}
931940
request_.clear();
932-
if (!rc.ok())
941+
if (!rc.ok() && sync_mode)
933942
{
934943
m_publisher.publish(consumer.getTableName(), kfvKey(it->second),
935944
kfvFieldsValues(it->second), rc);
936945
}
937946

938-
if (erase_from_queue)
947+
if (erase_from_queue || sync_mode)
939948
{
940949
it = consumer.m_toSync.erase(it);
941950
}

orchagent/vrforch.cpp

+128-40
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ bool VRFOrch::addOperation(const Request& request)
2828
SWSS_LOG_ENTER();
2929
uint32_t vni = 0;
3030
bool error = true;
31+
bool sync_mode = false;
32+
bool sync_mode_config = false;
3133

3234
sai_attribute_t attr;
3335
vector<sai_attribute_t> attrs;
@@ -75,6 +77,12 @@ bool VRFOrch::addOperation(const Request& request)
7577
SWSS_LOG_INFO("MGMT VRF field: %s ignored", name.c_str());
7678
continue;
7779
}
80+
else if (name == "sync_mode")
81+
{
82+
sync_mode_config = true;
83+
sync_mode = request.getAttrBool("sync_mode");
84+
continue;
85+
}
7886
else
7987
{
8088
SWSS_LOG_ERROR("Logic error: Unknown attribute: %s", name.c_str());
@@ -95,27 +103,46 @@ bool VRFOrch::addOperation(const Request& request)
95103
attrs.data());
96104
if (status != SAI_STATUS_SUCCESS)
97105
{
98-
ReturnCode rc = ReturnCode(status)
99-
<< "Failed to create virtual router name: "
100-
<< vrf_name << ", rv: " << sai_serialize_status(status);
101-
SWSS_LOG_ERROR("%s", rc.message().c_str());
102-
m_publisher.publish(request.getTableName(), request.getFullKey(),
103-
request.getFullAttrFields(), rc);
104-
handleSaiCreateStatus(SAI_API_VIRTUAL_ROUTER, status);
105-
// Remove from orchagent queue when there is SAI error
106-
return true;
106+
SWSS_LOG_ERROR("Failed to create virtual router name: %s, rv: %d", vrf_name.c_str(), status);
107+
task_process_status handle_status = handleSaiCreateStatus(SAI_API_VIRTUAL_ROUTER, status);
108+
if (sync_mode)
109+
{
110+
ReturnCode rc = ReturnCode(status)
111+
<< "Failed to create virtual router name: "
112+
<< vrf_name << ", rv: " << sai_serialize_status(status);
113+
m_publisher.publish(request.getTableName(), request.getFullKey(),
114+
request.getFullAttrFields(), rc);
115+
return true;
116+
}
117+
else if (handle_status != task_success)
118+
{
119+
return parseHandleSaiStatusFailure(handle_status);
120+
}
107121
}
108122

109123
vrf_table_[vrf_name].vrf_id = router_id;
110124
vrf_table_[vrf_name].ref_count = 0;
125+
vrf_table_[vrf_name].sync_mode = sync_mode;
111126
vrf_id_table_[router_id] = vrf_name;
112127
if (vni != 0)
113128
{
114129
SWSS_LOG_INFO("VRF '%s' vni %d add", vrf_name.c_str(), vni);
115130
error = updateVrfVNIMap(vrf_name, vni);
116131
if (error == false)
117132
{
118-
return false;
133+
if (sync_mode)
134+
{
135+
ReturnCode rc = ReturnCode(StatusCode::SWSS_RC_INVALID_PARAM)
136+
<< "Failed to update VRF vni map.";
137+
SWSS_LOG_ERROR("%s", rc.message().c_str());
138+
m_publisher.publish(request.getTableName(), request.getFullKey(),
139+
request.getFullAttrFields(), rc);
140+
return true;
141+
}
142+
else
143+
{
144+
return false;
145+
}
119146
}
120147
}
121148
m_stateVrfObjectTable.hset(vrf_name, "state", "ok");
@@ -125,37 +152,65 @@ bool VRFOrch::addOperation(const Request& request)
125152
{
126153
// Update an existing vrf
127154

155+
if (sync_mode_config)
156+
{
157+
vrf_table_[vrf_name].sync_mode = sync_mode;
158+
}
159+
128160
sai_object_id_t router_id = it->second.vrf_id;
129161

130162
for (const auto& attr: attrs)
131163
{
132164
sai_status_t status = sai_virtual_router_api->set_virtual_router_attribute(router_id, &attr);
133165
if (status != SAI_STATUS_SUCCESS)
134166
{
135-
ReturnCode rc = ReturnCode(status)
136-
<< "Failed to update virtual router attribute. vrf name: "
137-
<< vrf_name << ", rv: " << sai_serialize_status(status);
138-
SWSS_LOG_ERROR("%s", rc.message().c_str());
139-
m_publisher.publish(request.getTableName(), request.getFullKey(),
140-
request.getFullAttrFields(), rc);
141-
handleSaiSetStatus(SAI_API_VIRTUAL_ROUTER, status);
142-
// Remove from orchagent queue when there is SAI error
143-
return true;
167+
SWSS_LOG_ERROR("Failed to update virtual router attribute. vrf name: %s, rv: %d", vrf_name.c_str(), status);
168+
task_process_status handle_status = handleSaiSetStatus(SAI_API_VIRTUAL_ROUTER, status);
169+
if (sync_mode)
170+
{
171+
ReturnCode rc = ReturnCode(status)
172+
<< "Failed to update virtual router attribute. vrf name: "
173+
<< vrf_name << ", rv: " << sai_serialize_status(status);
174+
m_publisher.publish(request.getTableName(), request.getFullKey(),
175+
request.getFullAttrFields(), rc);
176+
return true;
177+
}
178+
else if (handle_status != task_success)
179+
{
180+
return parseHandleSaiStatusFailure(handle_status);
181+
}
182+
144183
}
145184
}
146185

147186
SWSS_LOG_INFO("VRF '%s' vni %d modify", vrf_name.c_str(), vni);
148187
error = updateVrfVNIMap(vrf_name, vni);
149188
if (error == false)
150189
{
151-
return false;
190+
if (sync_mode)
191+
{
192+
ReturnCode rc = ReturnCode(StatusCode::SWSS_RC_INVALID_PARAM)
193+
<< "Failed to update VRF vni map.";
194+
SWSS_LOG_ERROR("%s", rc.message().c_str());
195+
m_publisher.publish(request.getTableName(), request.getFullKey(),
196+
request.getFullAttrFields(), rc);
197+
return true;
198+
}
199+
else
200+
{
201+
return false;
202+
}
152203
}
153204

154205
SWSS_LOG_NOTICE("VRF '%s' was updated", vrf_name.c_str());
155206
}
207+
208+
if (sync_mode)
209+
 {
210+
 m_publisher.publish(request.getTableName(), request.getFullKey(),
211+
 request.getFullAttrFields(), ReturnCode());
212+
 }
156213

157-
m_publisher.publish(request.getTableName(), request.getFullKey(),
158-
request.getFullAttrFields(), ReturnCode());
159214
return true;
160215
}
161216

@@ -167,45 +222,78 @@ bool VRFOrch::delOperation(const Request& request)
167222
const std::string& vrf_name = request.getKeyString(0);
168223
if (vrf_table_.find(vrf_name) == std::end(vrf_table_))
169224
{
170-
ReturnCode rc = ReturnCode(StatusCode::SWSS_RC_NOT_FOUND)
171-
<< "VRF '" << vrf_name << "' doesn't exist";
172-
SWSS_LOG_ERROR("%s", rc.message().c_str());
173-
m_publisher.publish(request.getTableName(), request.getFullKey(),
174-
request.getFullAttrFields(), rc);
225+
SWSS_LOG_ERROR("VRF '%s' doesn't exist", vrf_name.c_str());
175226
return true;
176227
}
177228

229+
bool sync_mode = vrf_table_[vrf_name].sync_mode;
178230
if (vrf_table_[vrf_name].ref_count)
179-
return false;
231+
{
232+
if (sync_mode)
233+
 {
234+
 ReturnCode rc = ReturnCode(StatusCode::SWSS_RC_INVALID_PARAM)
235+
 << "Failed to delete VRF " << vrf_name
236+
 << ": reference count is not zero.";
237+
SWSS_LOG_ERROR("%s", rc.message().c_str());
238+
 m_publisher.publish(request.getTableName(), request.getFullKey(),
239+
 request.getFullAttrFields(), rc);
240+
return true;
241+
 }
242+
else
243+
 {
244+
return false;
245+
 }
246+
 }
180247

181248
sai_object_id_t router_id = vrf_table_[vrf_name].vrf_id;
182249
sai_status_t status = sai_virtual_router_api->remove_virtual_router(router_id);
183250
if (status != SAI_STATUS_SUCCESS)
184251
{
185-
ReturnCode rc = ReturnCode(status)
186-
<< "Failed to remove virtual router name: "
187-
<< vrf_name << ", rv:" << sai_serialize_status(status);
188-
SWSS_LOG_ERROR("%s", rc.message().c_str());
189-
m_publisher.publish(request.getTableName(), request.getFullKey(),
190-
request.getFullAttrFields(), rc);
191-
handleSaiRemoveStatus(SAI_API_VIRTUAL_ROUTER, status);
192-
// Remove from orchagent queue when there is SAI error
193-
return true;
252+
SWSS_LOG_ERROR("Failed to remove virtual router name: %s, rv:%d", vrf_name.c_str(), status);
253+
task_process_status handle_status = handleSaiRemoveStatus(SAI_API_VIRTUAL_ROUTER, status);
254+
if (sync_mode)
255+
{
256+
ReturnCode rc = ReturnCode(status)
257+
<< "Failed to remove virtual router name: "
258+
<< vrf_name << ", rv:" << sai_serialize_status(status);
259+
m_publisher.publish(request.getTableName(), request.getFullKey(),
260+
request.getFullAttrFields(), rc);
261+
return true;
262+
}
263+
else if (handle_status != task_success)
264+
{
265+
return parseHandleSaiStatusFailure(handle_status);
266+
}
194267
}
195268

196269
vrf_table_.erase(vrf_name);
197270
vrf_id_table_.erase(router_id);
198271
error = delVrfVNIMap(vrf_name, 0);
199272
if (error == false)
200273
{
201-
return false;
274+
if (sync_mode)
275+
 {
276+
 ReturnCode rc = ReturnCode(StatusCode::SWSS_RC_INVALID_PARAM)
277+
 << "Failed to delete VRF vni map.";
278+
SWSS_LOG_ERROR("%s", rc.message().c_str());
279+
 m_publisher.publish(request.getTableName(), request.getFullKey(),
280+
 request.getFullAttrFields(), rc);
281+
return true;
282+
 }
283+
else
284+
 {
285+
return false;
286+
 }
202287
}
203288
m_stateVrfObjectTable.del(vrf_name);
204289

205290
SWSS_LOG_NOTICE("VRF '%s' was removed", vrf_name.c_str());
206291

207-
m_publisher.publish(request.getTableName(), request.getFullKey(),
208-
request.getFullAttrFields(), ReturnCode());
292+
if (sync_mode)
293+
 {
294+
 m_publisher.publish(request.getTableName(), request.getFullKey(),
295+
 request.getFullAttrFields(), ReturnCode());
296+
 }
209297
return true;
210298
}
211299

orchagent/vrforch.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ struct VrfEntry
99
{
1010
sai_object_id_t vrf_id;
1111
int ref_count;
12+
bool sync_mode;
1213
};
1314

1415
struct VNIEntry
@@ -34,7 +35,8 @@ const request_description_t request_description = {
3435
{ "fallback", REQ_T_BOOL },
3536
{ "vni", REQ_T_UINT },
3637
{ "mgmtVrfEnabled", REQ_T_BOOL },
37-
{ "in_band_mgmt_enabled", REQ_T_BOOL }
38+
{ "in_band_mgmt_enabled", REQ_T_BOOL },
39+
{ "sync_mode", REQ_T_BOOL }
3840
},
3941
{ } // no mandatory attributes
4042
};

0 commit comments

Comments
 (0)