@@ -1031,29 +1031,59 @@ int VxlanMgr::deleteVxlanNetdevice(std::string vxlan_dev_name)
1031
1031
return swss::exec (cmd, res);
1032
1032
}
1033
1033
1034
+ std::vector<std::string> VxlanMgr::parseNetDev (const string& stdout){
1035
+ std::vector<std::string> netdevs;
1036
+ std::regex device_name_pattern (" ^\\ d+:\\ s+([^:]+)" );
1037
+ std::smatch match_result;
1038
+ auto lines = tokenize (stdout, ' \n ' );
1039
+ for (const std::string & line : lines)
1040
+ {
1041
+ SWSS_LOG_DEBUG (" line : %s\n " ,line.c_str ());
1042
+ if (!std::regex_search (line, match_result, device_name_pattern))
1043
+ {
1044
+ continue ;
1045
+ }
1046
+ std::string dev_name = match_result[1 ];
1047
+ netdevs.push_back (dev_name);
1048
+ }
1049
+ return netdevs;
1050
+ }
1051
+
1034
1052
void VxlanMgr::getAllVxlanNetDevices ()
1035
1053
{
1036
1054
std::string stdout;
1037
- const std::string cmd = std::string (" " ) + IP_CMD + " link show type vxlan" ;
1055
+
1056
+ // Get VxLan Netdev Interfaces
1057
+ std::string cmd = std::string (" " ) + IP_CMD + " link show type vxlan" ;
1038
1058
int ret = swss::exec (cmd, stdout);
1039
1059
if (ret != 0 )
1040
1060
{
1041
- SWSS_LOG_ERROR (" Cannot get devices by command : %s" , cmd.c_str ());
1042
- return ;
1061
+ SWSS_LOG_ERROR (" Cannot get vxlan devices by command : %s" , cmd.c_str ());
1062
+ stdout. clear () ;
1043
1063
}
1044
- std::regex device_name_pattern (" ^\\ d+:\\ s+([^:]+)" );
1045
- std::smatch match_result;
1046
- auto lines = tokenize (stdout, ' \n ' );
1047
- for (const std::string & line : lines)
1064
+ std::vector<std::string> netdevs = parseNetDev (stdout);
1065
+ for (auto netdev : netdevs)
1048
1066
{
1049
- SWSS_LOG_INFO (" line : %s\n " ,line.c_str ());
1050
- if (!std::regex_search (line, match_result, device_name_pattern))
1067
+ m_vxlanNetDevices[netdev] = VXLAN;
1068
+ }
1069
+
1070
+ // Get VxLanIf Netdev Interfaces
1071
+ cmd = std::string (" " ) + IP_CMD + " link show type bridge" ;
1072
+ ret = swss::exec (cmd, stdout);
1073
+ if (ret != 0 )
1074
+ {
1075
+ SWSS_LOG_ERROR (" Cannot get vxlanIf devices by command : %s" , cmd.c_str ());
1076
+ stdout.clear ();
1077
+ }
1078
+ netdevs = parseNetDev (stdout);
1079
+ for (auto netdev : netdevs)
1080
+ {
1081
+ if (netdev.find (VXLAN_IF_NAME_PREFIX) == 0 )
1051
1082
{
1052
- continue ;
1083
+ m_vxlanNetDevices[netdev] = VXLAN_IF ;
1053
1084
}
1054
- std::string vxlan_dev_name = match_result[1 ];
1055
- m_vxlanNetDevices[vxlan_dev_name] = vxlan_dev_name;
1056
1085
}
1086
+
1057
1087
return ;
1058
1088
}
1059
1089
@@ -1150,8 +1180,21 @@ void VxlanMgr::clearAllVxlanDevices()
1150
1180
{
1151
1181
for (auto it = m_vxlanNetDevices.begin (); it != m_vxlanNetDevices.end ();)
1152
1182
{
1153
- SWSS_LOG_INFO (" Deleting Stale NetDevice vxlandevname %s\n " , (it->first ).c_str ());
1154
- deleteVxlanNetdevice (it->first );
1183
+ std::string netdev_name = it->first ;
1184
+ std::string netdev_type = it->second ;
1185
+ SWSS_LOG_INFO (" Deleting Stale NetDevice %s, type: %s\n " , netdev_name.c_str (), netdev_type.c_str ());
1186
+ VxlanInfo info;
1187
+ std::string res;
1188
+ if (netdev_type.compare (VXLAN))
1189
+ {
1190
+ info.m_vxlan = netdev_name;
1191
+ cmdDeleteVxlan (info, res);
1192
+ }
1193
+ else if (netdev_type.compare (VXLAN_IF))
1194
+ {
1195
+ info.m_vxlanIf = netdev_name;
1196
+ cmdDeleteVxlanIf (info, res);
1197
+ }
1155
1198
it = m_vxlanNetDevices.erase (it);
1156
1199
}
1157
1200
}
0 commit comments