@@ -26,6 +26,12 @@ const map<string, sai_switch_attr_t> switch_attribute_map =
26
26
{" vxlan_router_mac" , SAI_SWITCH_ATTR_VXLAN_DEFAULT_ROUTER_MAC}
27
27
};
28
28
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
+
29
35
const map<string, sai_packet_action_t > packet_action_map =
30
36
{
31
37
{" drop" , SAI_PACKET_ACTION_DROP},
@@ -127,6 +133,61 @@ void SwitchOrch::doCfgSensorsTableTask(Consumer &consumer)
127
133
}
128
134
}
129
135
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
+
130
191
void SwitchOrch::doAppSwitchTableTask (Consumer &consumer)
131
192
{
132
193
SWSS_LOG_ENTER ();
@@ -136,19 +197,31 @@ void SwitchOrch::doAppSwitchTableTask(Consumer &consumer)
136
197
{
137
198
auto t = it->second ;
138
199
auto op = kfvOp (t);
200
+ bool retry = false ;
139
201
140
202
if (op == SET_COMMAND)
141
203
{
142
- bool retry = false ;
143
-
144
204
for (auto i : kfvFieldsValues (t))
145
205
{
146
206
auto attribute = fvField (i);
147
207
148
208
if (switch_attribute_map.find (attribute) == switch_attribute_map.end ())
149
209
{
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 ;
152
225
}
153
226
154
227
auto value = fvValue (i);
0 commit comments