@@ -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+
2935const 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+
130191void 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);
0 commit comments