Skip to content

Commit c91a7f2

Browse files
authored
[switchorch] Implement VXLAN src port range feature (#1959)
* Implement VXLAN src port range feature configuring Signed-off-by: Andriy Yurkiv <[email protected]>
1 parent b20f0f4 commit c91a7f2

File tree

3 files changed

+88
-9
lines changed

3 files changed

+88
-9
lines changed

orchagent/switchorch.cpp

Lines changed: 77 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ const map<string, sai_switch_attr_t> switch_attribute_map =
2626
{"vxlan_router_mac", SAI_SWITCH_ATTR_VXLAN_DEFAULT_ROUTER_MAC}
2727
};
2828

29+
const map<string, sai_switch_tunnel_attr_t> switch_tunnel_attribute_map =
30+
{
31+
{"vxlan_sport", SAI_SWITCH_TUNNEL_ATTR_VXLAN_UDP_SPORT},
32+
{"vxlan_mask", SAI_SWITCH_TUNNEL_ATTR_VXLAN_UDP_SPORT_MASK}
33+
};
34+
2935
const map<string, sai_packet_action_t> packet_action_map =
3036
{
3137
{"drop", SAI_PACKET_ACTION_DROP},
@@ -127,6 +133,61 @@ void SwitchOrch::doCfgSensorsTableTask(Consumer &consumer)
127133
}
128134
}
129135

136+
137+
sai_status_t SwitchOrch::setSwitchTunnelVxlanParams(swss::FieldValueTuple &val)
138+
{
139+
auto attribute = fvField(val);
140+
auto value = fvValue(val);
141+
sai_attribute_t attr;
142+
sai_status_t status;
143+
144+
if (!m_vxlanSportUserModeEnabled)
145+
{
146+
// Enable Vxlan src port range feature
147+
vector<sai_attribute_t> attrs;
148+
attr.id = SAI_SWITCH_TUNNEL_ATTR_TUNNEL_TYPE;
149+
attr.value.s32 = SAI_TUNNEL_TYPE_VXLAN;
150+
attrs.push_back(attr);
151+
attr.id = SAI_SWITCH_TUNNEL_ATTR_TUNNEL_VXLAN_UDP_SPORT_MODE;
152+
attr.value.s32 = SAI_TUNNEL_VXLAN_UDP_SPORT_MODE_USER_DEFINED;
153+
attrs.push_back(attr);
154+
155+
status = sai_switch_api->create_switch_tunnel(&m_switchTunnelId, gSwitchId, static_cast<uint32_t>(attrs.size()), attrs.data());
156+
157+
if (status != SAI_STATUS_SUCCESS)
158+
{
159+
SWSS_LOG_ERROR("Failed to create switch_tunnel object, rv:%d", status);
160+
return status;
161+
}
162+
163+
m_vxlanSportUserModeEnabled = true;
164+
}
165+
166+
attr.id = switch_tunnel_attribute_map.at(attribute);
167+
switch (attr.id)
168+
{
169+
case SAI_SWITCH_TUNNEL_ATTR_VXLAN_UDP_SPORT:
170+
attr.value.u16 = to_uint<uint16_t>(value);
171+
break;
172+
case SAI_SWITCH_TUNNEL_ATTR_VXLAN_UDP_SPORT_MASK:
173+
attr.value.u8 = to_uint<uint8_t>(value);
174+
break;
175+
default:
176+
SWSS_LOG_ERROR("Invalid switch tunnel attribute id %d", attr.id);
177+
return SAI_STATUS_SUCCESS;
178+
}
179+
180+
status = sai_switch_api->set_switch_tunnel_attribute(m_switchTunnelId, &attr);
181+
if (status != SAI_STATUS_SUCCESS)
182+
{
183+
SWSS_LOG_ERROR("Failed to set tunnnel switch attribute %s to %s, rv:%d", attribute.c_str(), value.c_str(), status);
184+
return status;
185+
}
186+
187+
SWSS_LOG_NOTICE("Set switch attribute %s to %s", attribute.c_str(), value.c_str());
188+
return SAI_STATUS_SUCCESS;
189+
}
190+
130191
void SwitchOrch::doAppSwitchTableTask(Consumer &consumer)
131192
{
132193
SWSS_LOG_ENTER();
@@ -136,19 +197,31 @@ void SwitchOrch::doAppSwitchTableTask(Consumer &consumer)
136197
{
137198
auto t = it->second;
138199
auto op = kfvOp(t);
200+
bool retry = false;
139201

140202
if (op == SET_COMMAND)
141203
{
142-
bool retry = false;
143-
144204
for (auto i : kfvFieldsValues(t))
145205
{
146206
auto attribute = fvField(i);
147207

148208
if (switch_attribute_map.find(attribute) == switch_attribute_map.end())
149209
{
150-
SWSS_LOG_ERROR("Unsupported switch attribute %s", attribute.c_str());
151-
break;
210+
// Check additionally 'switch_tunnel_attribute_map' for Switch Tunnel
211+
if (switch_tunnel_attribute_map.find(attribute) == switch_tunnel_attribute_map.end())
212+
{
213+
SWSS_LOG_ERROR("Unsupported switch attribute %s", attribute.c_str());
214+
break;
215+
}
216+
217+
auto status = setSwitchTunnelVxlanParams(i);
218+
if ((status != SAI_STATUS_SUCCESS) && (handleSaiSetStatus(SAI_API_SWITCH, status) == task_need_retry))
219+
{
220+
retry = true;
221+
break;
222+
}
223+
224+
continue;
152225
}
153226

154227
auto value = fvValue(i);

orchagent/switchorch.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,13 @@ class SwitchOrch : public Orch
3535
void doAppSwitchTableTask(Consumer &consumer);
3636
void initSensorsTable();
3737
void querySwitchTpidCapability();
38+
sai_status_t setSwitchTunnelVxlanParams(swss::FieldValueTuple &val);
3839

3940
swss::NotificationConsumer* m_restartCheckNotificationConsumer;
4041
void doTask(swss::NotificationConsumer& consumer);
4142
swss::DBConnector *m_db;
4243
swss::Table m_switchTable;
44+
sai_object_id_t m_switchTunnelId;
4345

4446
// ASIC temperature sensors
4547
std::shared_ptr<swss::DBConnector> m_stateDb = nullptr;
@@ -52,6 +54,7 @@ class SwitchOrch : public Orch
5254
bool m_numTempSensorsInitialized = false;
5355
bool m_sensorsMaxTempSupported = true;
5456
bool m_sensorsAvgTempSupported = true;
57+
bool m_vxlanSportUserModeEnabled = false;
5558

5659
// Information contained in the request from
5760
// external program for orchagent pre-shutdown state check

tests/test_switch.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,16 @@ def check_object(db, table, key, expected_attributes):
4040
(value, name, expected_attributes[name])
4141

4242

43-
def vxlan_switch_test(dvs, oid, port, mac):
43+
def vxlan_switch_test(dvs, oid, port, mac, mask, sport):
4444
app_db = swsscommon.DBConnector(swsscommon.APPL_DB, dvs.redis_sock, 0)
4545
create_entry_pst(
4646
app_db,
4747
"SWITCH_TABLE", ':', "switch",
4848
[
4949
("vxlan_port", port),
50-
("vxlan_router_mac", mac)
50+
("vxlan_router_mac", mac),
51+
("vxlan_mask", mask),
52+
("vxlan_sport", sport),
5153
],
5254
)
5355
time.sleep(2)
@@ -57,6 +59,8 @@ def vxlan_switch_test(dvs, oid, port, mac):
5759
{
5860
'SAI_SWITCH_ATTR_VXLAN_DEFAULT_PORT': port,
5961
'SAI_SWITCH_ATTR_VXLAN_DEFAULT_ROUTER_MAC': mac,
62+
'SAI_SWITCH_TUNNEL_ATTR_VXLAN_UDP_SPORT_MASK': mask,
63+
'SAI_SWITCH_TUNNEL_ATTR_VXLAN_UDP_SPORT': sport,
6064
}
6165
)
6266

@@ -67,10 +71,9 @@ class TestSwitch(object):
6771
'''
6872
def test_switch_attribute(self, dvs, testlog):
6973
switch_oid = get_exist_entry(dvs, "ASIC_STATE:SAI_OBJECT_TYPE_SWITCH")
74+
vxlan_switch_test(dvs, switch_oid, "12345", "00:01:02:03:04:05", "20", "54321")
7075

71-
vxlan_switch_test(dvs, switch_oid, "12345", "00:01:02:03:04:05")
72-
73-
vxlan_switch_test(dvs, switch_oid, "56789", "00:0A:0B:0C:0D:0E")
76+
vxlan_switch_test(dvs, switch_oid, "56789", "00:0A:0B:0C:0D:0E", "15", "56789")
7477

7578

7679
# Add Dummy always-pass test at end as workaroud

0 commit comments

Comments
 (0)