Tinoj Joseph | cf161be | 2022-07-07 19:47:47 +0530 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2022-present Open Networking Foundation |
| 3 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | * you may not use this file except in compliance with the License. |
| 5 | * You may obtain a copy of the License at |
| 6 | * |
| 7 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | * |
| 9 | * Unless required by applicable law or agreed to in writing, software |
| 10 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | * See the License for the specific language governing permissions and |
| 13 | * limitations under the License. |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 14 | */ |
Tinoj Joseph | cf161be | 2022-07-07 19:47:47 +0530 | [diff] [blame] | 15 | |
| 16 | package application |
| 17 | |
| 18 | import ( |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 19 | "context" |
Tinoj Joseph | cf161be | 2022-07-07 19:47:47 +0530 | [diff] [blame] | 20 | "encoding/json" |
| 21 | "errors" |
| 22 | "net" |
| 23 | "strconv" |
| 24 | "strings" |
| 25 | "sync" |
| 26 | |
Tinoj Joseph | cf161be | 2022-07-07 19:47:47 +0530 | [diff] [blame] | 27 | "voltha-go-controller/database" |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 28 | cntlr "voltha-go-controller/internal/pkg/controller" |
Tinoj Joseph | cf161be | 2022-07-07 19:47:47 +0530 | [diff] [blame] | 29 | "voltha-go-controller/internal/pkg/of" |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 30 | common "voltha-go-controller/internal/pkg/types" |
Tinoj Joseph | cf161be | 2022-07-07 19:47:47 +0530 | [diff] [blame] | 31 | "voltha-go-controller/internal/pkg/util" |
| 32 | "voltha-go-controller/log" |
| 33 | ) |
| 34 | |
| 35 | // ------------------------------------------------------------ |
| 36 | // MVLAN related implemnetation |
| 37 | // |
| 38 | // Each MVLAN is configured with groups of multicast IPs. The idea of |
| 39 | // groups is to be able to group some multicast channels into an individual |
| 40 | // PON group and have a unique multicast GEM port for that set. However, in |
| 41 | // the current implementation, the concept of grouping is not fully utilized. |
| 42 | |
| 43 | // MvlanGroup structure |
| 44 | // A set of MC IPs form a group |
| 45 | |
| 46 | // MCGroupProxy identifies source specific multicast(SSM) config. |
| 47 | type MCGroupProxy struct { |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 48 | // Mode represents source list include/exclude |
| 49 | Mode common.MulticastSrcListMode |
| 50 | // SourceList represents list of multicast server IP addresses. |
| 51 | SourceList []net.IP |
Tinoj Joseph | cf161be | 2022-07-07 19:47:47 +0530 | [diff] [blame] | 52 | } |
| 53 | |
| 54 | // MvlanGroup identifies MC group info |
| 55 | type MvlanGroup struct { |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 56 | Name string |
| 57 | McIPs []string |
| 58 | Wildcard bool |
| 59 | IsStatic bool |
Tinoj Joseph | cf161be | 2022-07-07 19:47:47 +0530 | [diff] [blame] | 60 | } |
| 61 | |
| 62 | // OperInProgress type |
| 63 | type OperInProgress uint8 |
| 64 | |
| 65 | const ( |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 66 | // UpdateInProgress constant |
| 67 | UpdateInProgress OperInProgress = 2 |
| 68 | // NoOp constant |
| 69 | NoOp OperInProgress = 1 |
| 70 | // Nil constant |
| 71 | Nil OperInProgress = 0 |
Tinoj Joseph | cf161be | 2022-07-07 19:47:47 +0530 | [diff] [blame] | 72 | ) |
| 73 | |
| 74 | // MvlanProfile : A set of groups of MC IPs for a MVLAN profile. It is assumed that |
| 75 | // the MVLAN IP is not repeated within multiples groups and across |
| 76 | // MVLAN profiles. The first match is used up on search to lcoate the |
| 77 | // MVLAN profile for an MC IP |
| 78 | type MvlanProfile struct { |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 79 | Groups map[string]*MvlanGroup |
| 80 | Proxy map[string]*MCGroupProxy |
| 81 | oldGroups map[string]*MvlanGroup |
| 82 | oldProxy map[string]*MCGroupProxy |
| 83 | IgmpServVersion map[string]*uint8 |
| 84 | PendingDeleteFlow map[string]map[string]bool |
| 85 | DevicesList map[string]OperInProgress //device serial number //here |
| 86 | Version string |
| 87 | Name string |
| 88 | mvpLock sync.RWMutex |
| 89 | mvpFlowLock sync.RWMutex |
| 90 | MaxActiveChannels uint32 |
| 91 | Mvlan of.VlanType |
| 92 | PonVlan of.VlanType |
| 93 | IsPonVlanPresent bool |
| 94 | IsChannelBasedGroup bool |
| 95 | DeleteInProgress bool |
Tinoj Joseph | cf161be | 2022-07-07 19:47:47 +0530 | [diff] [blame] | 96 | } |
| 97 | |
| 98 | // NewMvlanProfile is constructor for MVLAN profile. |
| 99 | func NewMvlanProfile(name string, mvlan of.VlanType, ponVlan of.VlanType, isChannelBasedGroup bool, OLTSerialNums []string, actChannelPerPon uint32) *MvlanProfile { |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 100 | var mvp MvlanProfile |
| 101 | mvp.Name = name |
| 102 | mvp.Mvlan = mvlan |
| 103 | mvp.PonVlan = ponVlan |
| 104 | mvp.mvpLock = sync.RWMutex{} |
| 105 | mvp.Groups = make(map[string]*MvlanGroup) |
| 106 | mvp.Proxy = make(map[string]*MCGroupProxy) |
| 107 | mvp.DevicesList = make(map[string]OperInProgress) |
| 108 | mvp.PendingDeleteFlow = make(map[string]map[string]bool) |
| 109 | mvp.IsChannelBasedGroup = isChannelBasedGroup |
| 110 | mvp.MaxActiveChannels = actChannelPerPon |
| 111 | mvp.DeleteInProgress = false |
| 112 | mvp.IgmpServVersion = make(map[string]*uint8) |
Tinoj Joseph | cf161be | 2022-07-07 19:47:47 +0530 | [diff] [blame] | 113 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 114 | if (ponVlan != of.VlanNone) && (ponVlan != 0) { |
| 115 | mvp.IsPonVlanPresent = true |
| 116 | } |
| 117 | return &mvp |
Tinoj Joseph | cf161be | 2022-07-07 19:47:47 +0530 | [diff] [blame] | 118 | } |
| 119 | |
| 120 | // AddMvlanProxy for addition of groups to an MVLAN profile |
| 121 | func (mvp *MvlanProfile) AddMvlanProxy(name string, proxyInfo common.MulticastGroupProxy) { |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 122 | proxy := &MCGroupProxy{} |
| 123 | proxy.Mode = proxyInfo.Mode |
| 124 | proxy.SourceList = util.GetExpIPList(proxyInfo.SourceList) |
Tinoj Joseph | cf161be | 2022-07-07 19:47:47 +0530 | [diff] [blame] | 125 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 126 | if _, ok := mvp.Proxy[name]; !ok { |
| 127 | logger.Debugw(ctx, "Added MVLAN Proxy", log.Fields{"Name": name, "Proxy": proxy}) |
| 128 | } else { |
| 129 | logger.Debugw(ctx, "Updated MVLAN Proxy", log.Fields{"Name": name, "Proxy": proxy}) |
| 130 | } |
| 131 | if proxyInfo.IsStatic == common.IsStaticYes { |
| 132 | mvp.Groups[name].IsStatic = true |
| 133 | } |
| 134 | mvp.Proxy[name] = proxy |
Tinoj Joseph | cf161be | 2022-07-07 19:47:47 +0530 | [diff] [blame] | 135 | } |
| 136 | |
| 137 | // AddMvlanGroup for addition of groups to an MVLAN profile |
| 138 | func (mvp *MvlanProfile) AddMvlanGroup(name string, ips []string) { |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 139 | mvg := &MvlanGroup{} |
| 140 | mvg.Name = name |
| 141 | mvg.Wildcard = len(ips) == 0 |
| 142 | mvg.McIPs = ips |
| 143 | mvg.IsStatic = false |
| 144 | if _, ok := mvp.Groups[name]; !ok { |
| 145 | logger.Debugw(ctx, "Added MVLAN Group", log.Fields{"VLAN": mvp.Mvlan, "Name": name, "mvg": mvg, "IPs": mvg.McIPs}) |
| 146 | } else { |
| 147 | logger.Debugw(ctx, "Updated MVLAN Group", log.Fields{"VLAN": mvp.Mvlan, "Name": name}) |
| 148 | } |
| 149 | mvp.Groups[name] = mvg |
Tinoj Joseph | cf161be | 2022-07-07 19:47:47 +0530 | [diff] [blame] | 150 | } |
| 151 | |
| 152 | // GetUsMatchVlan provides mvlan for US Match parameter |
| 153 | func (mvp *MvlanProfile) GetUsMatchVlan() of.VlanType { |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 154 | if mvp.IsPonVlanPresent { |
| 155 | return mvp.PonVlan |
| 156 | } |
| 157 | return mvp.Mvlan |
Tinoj Joseph | cf161be | 2022-07-07 19:47:47 +0530 | [diff] [blame] | 158 | } |
| 159 | |
| 160 | // WriteToDb is utility to write Mvlan Profile Info to database |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 161 | func (mvp *MvlanProfile) WriteToDb(cntx context.Context) error { |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 162 | if mvp.DeleteInProgress { |
| 163 | logger.Warnw(ctx, "Skipping Redis Update for MvlanProfile, MvlanProfile delete in progress", log.Fields{"Mvlan": mvp.Mvlan}) |
| 164 | return nil |
| 165 | } |
Tinoj Joseph | cf161be | 2022-07-07 19:47:47 +0530 | [diff] [blame] | 166 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 167 | mvp.Version = database.PresentVersionMap[database.MvlanPath] |
| 168 | b, err := json.Marshal(mvp) |
| 169 | if err != nil { |
| 170 | return err |
| 171 | } |
| 172 | if err1 := db.PutMvlan(cntx, uint16(mvp.Mvlan), string(b)); err1 != nil { |
| 173 | return err1 |
| 174 | } |
| 175 | return nil |
Tinoj Joseph | cf161be | 2022-07-07 19:47:47 +0530 | [diff] [blame] | 176 | } |
| 177 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 178 | // isChannelStatic - Returns true if the given channel is part of static group in the Mvlan Profile |
Tinoj Joseph | cf161be | 2022-07-07 19:47:47 +0530 | [diff] [blame] | 179 | func (mvp *MvlanProfile) isChannelStatic(channel net.IP) bool { |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 180 | for _, mvg := range mvp.Groups { |
| 181 | if mvg.IsStatic { |
| 182 | if isChannelStatic := doesIPMatch(channel, mvg.McIPs); isChannelStatic { |
| 183 | return true |
| 184 | } |
| 185 | } |
| 186 | } |
| 187 | return false |
Tinoj Joseph | cf161be | 2022-07-07 19:47:47 +0530 | [diff] [blame] | 188 | } |
| 189 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 190 | // containsStaticChannels - Returns if any static channels is part of the Mvlan Profile |
Tinoj Joseph | cf161be | 2022-07-07 19:47:47 +0530 | [diff] [blame] | 191 | func (mvp *MvlanProfile) containsStaticChannels() bool { |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 192 | for _, mvg := range mvp.Groups { |
| 193 | if mvg.IsStatic && len(mvg.McIPs) != 0 { |
| 194 | return true |
| 195 | } |
| 196 | } |
| 197 | return false |
Tinoj Joseph | cf161be | 2022-07-07 19:47:47 +0530 | [diff] [blame] | 198 | } |
| 199 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 200 | // getAllStaticChannels - Returns all static channels in the Mvlan Profile |
Tinoj Joseph | cf161be | 2022-07-07 19:47:47 +0530 | [diff] [blame] | 201 | func (mvp *MvlanProfile) getAllStaticChannels() ([]net.IP, bool) { |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 202 | channelList := []net.IP{} |
| 203 | containsStatic := false |
| 204 | for _, mvg := range mvp.Groups { |
| 205 | if mvg.IsStatic { |
| 206 | staticChannels, _ := mvg.getAllChannels() |
| 207 | channelList = append(channelList, staticChannels...) |
| 208 | } |
| 209 | } |
| 210 | if len(channelList) > 0 { |
| 211 | containsStatic = true |
| 212 | } |
| 213 | return channelList, containsStatic |
Tinoj Joseph | cf161be | 2022-07-07 19:47:47 +0530 | [diff] [blame] | 214 | } |
| 215 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 216 | // getAllOldGroupStaticChannels - Returns all static channels in the Mvlan Profile |
Tinoj Joseph | cf161be | 2022-07-07 19:47:47 +0530 | [diff] [blame] | 217 | func (mvp *MvlanProfile) getAllOldGroupStaticChannels() ([]net.IP, bool) { |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 218 | channelList := []net.IP{} |
| 219 | containsStatic := false |
| 220 | for _, mvg := range mvp.oldGroups { |
| 221 | if mvg.IsStatic { |
| 222 | staticChannels, _ := mvg.getAllChannels() |
| 223 | channelList = append(channelList, staticChannels...) |
| 224 | } |
| 225 | } |
| 226 | if len(channelList) > 0 { |
| 227 | containsStatic = true |
| 228 | } |
| 229 | return channelList, containsStatic |
Tinoj Joseph | cf161be | 2022-07-07 19:47:47 +0530 | [diff] [blame] | 230 | } |
| 231 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 232 | // getAllChannels - Returns all channels in the Mvlan Profile |
Tinoj Joseph | cf161be | 2022-07-07 19:47:47 +0530 | [diff] [blame] | 233 | func (mvg *MvlanGroup) getAllChannels() ([]net.IP, bool) { |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 234 | channelList := []net.IP{} |
Tinoj Joseph | cf161be | 2022-07-07 19:47:47 +0530 | [diff] [blame] | 235 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 236 | if mvg == nil || len(mvg.McIPs) == 0 { |
| 237 | return []net.IP{}, false |
| 238 | } |
Tinoj Joseph | cf161be | 2022-07-07 19:47:47 +0530 | [diff] [blame] | 239 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 240 | grpChannelOrRange := mvg.McIPs |
| 241 | for _, channelOrRange := range grpChannelOrRange { |
| 242 | if strings.Contains(channelOrRange, "-") { |
| 243 | var splits = strings.Split(channelOrRange, "-") |
| 244 | ipStart := util.IP2LongConv(net.ParseIP(splits[0])) |
| 245 | ipEnd := util.IP2LongConv(net.ParseIP(splits[1])) |
Tinoj Joseph | cf161be | 2022-07-07 19:47:47 +0530 | [diff] [blame] | 246 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 247 | for i := ipStart; i <= ipEnd; i++ { |
| 248 | channelList = append(channelList, util.Long2ipConv(i)) |
| 249 | } |
| 250 | } else { |
| 251 | channelList = append(channelList, net.ParseIP(channelOrRange)) |
| 252 | } |
| 253 | } |
| 254 | return channelList, true |
Tinoj Joseph | cf161be | 2022-07-07 19:47:47 +0530 | [diff] [blame] | 255 | } |
| 256 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 257 | // SetUpdateStatus - Sets profile update status for devices |
Tinoj Joseph | cf161be | 2022-07-07 19:47:47 +0530 | [diff] [blame] | 258 | func (mvp *MvlanProfile) SetUpdateStatus(serialNum string, status OperInProgress) { |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 259 | if serialNum != "" { |
| 260 | mvp.DevicesList[serialNum] = status |
| 261 | return |
| 262 | } |
Tinoj Joseph | cf161be | 2022-07-07 19:47:47 +0530 | [diff] [blame] | 263 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 264 | for srNo := range mvp.DevicesList { |
| 265 | mvp.DevicesList[srNo] = status |
| 266 | } |
Tinoj Joseph | cf161be | 2022-07-07 19:47:47 +0530 | [diff] [blame] | 267 | } |
| 268 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 269 | // isUpdateInProgress - checking is update is in progress for the mvlan profile |
Tinoj Joseph | cf161be | 2022-07-07 19:47:47 +0530 | [diff] [blame] | 270 | func (mvp *MvlanProfile) isUpdateInProgress() bool { |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 271 | for srNo := range mvp.DevicesList { |
| 272 | if mvp.DevicesList[srNo] == UpdateInProgress { |
| 273 | return true |
| 274 | } |
| 275 | } |
| 276 | return false |
Tinoj Joseph | cf161be | 2022-07-07 19:47:47 +0530 | [diff] [blame] | 277 | } |
| 278 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 279 | // IsUpdateInProgressForDevice - Checks is Mvlan Profile update is is progress for the given device |
Tinoj Joseph | cf161be | 2022-07-07 19:47:47 +0530 | [diff] [blame] | 280 | func (mvp *MvlanProfile) IsUpdateInProgressForDevice(device string) bool { |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 281 | if vd := GetApplication().GetDevice(device); vd != nil { |
| 282 | if mvp.DevicesList[vd.SerialNum] == UpdateInProgress { |
| 283 | return true |
| 284 | } |
| 285 | } |
| 286 | return false |
Tinoj Joseph | cf161be | 2022-07-07 19:47:47 +0530 | [diff] [blame] | 287 | } |
| 288 | |
| 289 | // DelFromDb to delere mvlan from database |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 290 | func (mvp *MvlanProfile) DelFromDb(cntx context.Context) { |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 291 | _ = db.DelMvlan(cntx, uint16(mvp.Mvlan)) |
Tinoj Joseph | cf161be | 2022-07-07 19:47:47 +0530 | [diff] [blame] | 292 | } |
| 293 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 294 | // DelFlows - Triggers flow deletion after registering for flow indication event |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 295 | func (mvp *MvlanProfile) DelFlows(cntx context.Context, device *VoltDevice, flow *of.VoltFlow) error { |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 296 | mvp.mvpFlowLock.Lock() |
| 297 | defer mvp.mvpFlowLock.Unlock() |
Tinoj Joseph | cf161be | 2022-07-07 19:47:47 +0530 | [diff] [blame] | 298 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 299 | var flowMap map[string]bool |
| 300 | var ok bool |
Tinoj Joseph | cf161be | 2022-07-07 19:47:47 +0530 | [diff] [blame] | 301 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 302 | for cookie := range flow.SubFlows { |
| 303 | cookie := strconv.FormatUint(cookie, 10) |
| 304 | fe := &FlowEvent{ |
| 305 | eType: EventTypeMcastFlowRemoved, |
| 306 | device: device.Name, |
| 307 | cookie: cookie, |
| 308 | eventData: mvp, |
| 309 | } |
| 310 | device.RegisterFlowDelEvent(cookie, fe) |
Tinoj Joseph | cf161be | 2022-07-07 19:47:47 +0530 | [diff] [blame] | 311 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 312 | if flowMap, ok = mvp.PendingDeleteFlow[device.Name]; !ok { |
| 313 | flowMap = make(map[string]bool) |
| 314 | } |
| 315 | flowMap[cookie] = true |
| 316 | mvp.PendingDeleteFlow[device.Name] = flowMap |
| 317 | } |
| 318 | if err := mvp.WriteToDb(cntx); err != nil { |
| 319 | logger.Errorw(ctx, "Mvlan profile write to DB failed", log.Fields{"ProfileName": mvp.Name}) |
| 320 | } |
Sridhar Ravindra | b76eb16 | 2025-07-02 01:25:10 +0530 | [diff] [blame^] | 321 | nniPort, err := GetApplication().GetNniPort(device.Name) |
| 322 | if err != nil { |
| 323 | logger.Errorw(ctx, "Error getting NNI port", log.Fields{"Error": err}) |
| 324 | } |
| 325 | return cntlr.GetController().DelFlows(cntx, nniPort, device.Name, flow, false) |
Tinoj Joseph | cf161be | 2022-07-07 19:47:47 +0530 | [diff] [blame] | 326 | } |
| 327 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 328 | // FlowRemoveSuccess - Process flow success indication |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 329 | func (mvp *MvlanProfile) FlowRemoveSuccess(cntx context.Context, cookie string, device string) { |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 330 | mvp.mvpFlowLock.Lock() |
| 331 | defer mvp.mvpFlowLock.Unlock() |
Tinoj Joseph | cf161be | 2022-07-07 19:47:47 +0530 | [diff] [blame] | 332 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 333 | logger.Infow(ctx, "Mvlan Flow Remove Success Notification", log.Fields{"MvlanProfile": mvp.Name, "Cookie": cookie, "Device": device}) |
Tinoj Joseph | cf161be | 2022-07-07 19:47:47 +0530 | [diff] [blame] | 334 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 335 | if _, ok := mvp.PendingDeleteFlow[device]; ok { |
| 336 | delete(mvp.PendingDeleteFlow[device], cookie) |
| 337 | } |
Tinoj Joseph | cf161be | 2022-07-07 19:47:47 +0530 | [diff] [blame] | 338 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 339 | if err := mvp.WriteToDb(cntx); err != nil { |
| 340 | logger.Errorw(ctx, "Mvlan profile write to DB failed", log.Fields{"ProfileName": mvp.Name}) |
| 341 | } |
Tinoj Joseph | cf161be | 2022-07-07 19:47:47 +0530 | [diff] [blame] | 342 | } |
| 343 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 344 | // FlowRemoveFailure - Process flow failure indication |
Tinoj Joseph | cf161be | 2022-07-07 19:47:47 +0530 | [diff] [blame] | 345 | func (mvp *MvlanProfile) FlowRemoveFailure(cookie string, device string, errorCode uint32, errReason string) { |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 346 | mvp.mvpFlowLock.Lock() |
| 347 | defer mvp.mvpFlowLock.Unlock() |
Tinoj Joseph | cf161be | 2022-07-07 19:47:47 +0530 | [diff] [blame] | 348 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 349 | if flowMap, ok := mvp.PendingDeleteFlow[device]; ok { |
| 350 | if _, ok := flowMap[cookie]; ok { |
| 351 | logger.Errorw(ctx, "Mvlan Flow Remove Failure Notification", log.Fields{"MvlanProfile": mvp.Name, "Cookie": cookie, "ErrorCode": errorCode, "ErrorReason": errReason, "Device": device}) |
| 352 | return |
| 353 | } |
| 354 | } |
| 355 | logger.Errorw(ctx, "Mvlan Flow Del Failure Notification for Unknown cookie", log.Fields{"MvlanProfile": mvp.Name, "Cookie": cookie, "ErrorCode": errorCode, "ErrorReason": errReason}) |
Tinoj Joseph | cf161be | 2022-07-07 19:47:47 +0530 | [diff] [blame] | 356 | } |
| 357 | |
| 358 | // IsStaticGroup to check if group is static |
| 359 | func (mvp *MvlanProfile) IsStaticGroup(groupName string) bool { |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 360 | return mvp.Groups[groupName].IsStatic |
Tinoj Joseph | cf161be | 2022-07-07 19:47:47 +0530 | [diff] [blame] | 361 | } |
| 362 | |
| 363 | // generateGroupKey to generate group key |
| 364 | func (mvp *MvlanProfile) generateGroupKey(name string, ipAddr string) string { |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 365 | if mvp.IsChannelBasedGroup { |
| 366 | return mvp.Mvlan.String() + "_" + ipAddr |
| 367 | } |
| 368 | return mvp.Mvlan.String() + "_" + name |
Tinoj Joseph | cf161be | 2022-07-07 19:47:47 +0530 | [diff] [blame] | 369 | } |
| 370 | |
| 371 | // GetStaticGroupName to get static igmp group |
| 372 | func (mvp *MvlanProfile) GetStaticGroupName(gip net.IP) string { |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 373 | for _, mvg := range mvp.Groups { |
| 374 | if mvg.IsStatic { |
| 375 | if doesIPMatch(gip, mvg.McIPs) { |
| 376 | return mvg.Name |
| 377 | } |
| 378 | } |
| 379 | } |
| 380 | return "" |
Tinoj Joseph | cf161be | 2022-07-07 19:47:47 +0530 | [diff] [blame] | 381 | } |
| 382 | |
| 383 | // GetStaticIgmpGroup to get static igmp group |
| 384 | func (mvp *MvlanProfile) GetStaticIgmpGroup(gip net.IP) *IgmpGroup { |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 385 | staticGroupName := mvp.GetStaticGroupName(gip) |
| 386 | grpKey := mvp.generateGroupKey(staticGroupName, gip.String()) |
| 387 | logger.Debugw(ctx, "Get Static IGMP Group", log.Fields{"Group": grpKey}) |
| 388 | ig, ok := GetApplication().IgmpGroups.Load(grpKey) |
| 389 | if ok { |
| 390 | logger.Debugw(ctx, "Get Static IGMP Group Success", log.Fields{"Group": grpKey}) |
| 391 | return ig.(*IgmpGroup) |
| 392 | } |
| 393 | return nil |
Tinoj Joseph | cf161be | 2022-07-07 19:47:47 +0530 | [diff] [blame] | 394 | } |
| 395 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 396 | // pushIgmpMcastFlows - Adds all IGMP related flows (generic DS flow & static group flows) |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 397 | func (mvp *MvlanProfile) pushIgmpMcastFlows(cntx context.Context, OLTSerialNum string) { |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 398 | mvp.mvpLock.RLock() |
| 399 | defer mvp.mvpLock.RUnlock() |
Tinoj Joseph | cf161be | 2022-07-07 19:47:47 +0530 | [diff] [blame] | 400 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 401 | if mvp.DevicesList[OLTSerialNum] == Nil { |
| 402 | logger.Infow(ctx, "Mvlan Profile not configure for device", log.Fields{"Device": OLTSerialNum, "Mvlan": mvp.Mvlan}) |
| 403 | return |
| 404 | } |
Tinoj Joseph | cf161be | 2022-07-07 19:47:47 +0530 | [diff] [blame] | 405 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 406 | d, _ := GetApplication().GetDeviceBySerialNo(OLTSerialNum) |
| 407 | if d == nil { |
| 408 | logger.Warnw(ctx, "Skipping Igmp & Mcast Flow processing: Device Not Found", log.Fields{"Device_SrNo": OLTSerialNum, "Mvlan": mvp.Mvlan}) |
| 409 | return |
| 410 | } |
Sridhar Ravindra | b76eb16 | 2025-07-02 01:25:10 +0530 | [diff] [blame^] | 411 | nniPort, err := GetApplication().GetNniPort(d.Name) |
| 412 | if err != nil { |
| 413 | logger.Errorw(ctx, "Error getting NNI port", log.Fields{"Error": err}) |
| 414 | } |
| 415 | p := d.GetPort(nniPort) |
Tinoj Joseph | cf161be | 2022-07-07 19:47:47 +0530 | [diff] [blame] | 416 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 417 | if p != nil && p.State == PortStateUp { |
| 418 | logger.Infow(ctx, "NNI Port Status is: UP & Vlan Enabled", log.Fields{"Device": d, "port": p}) |
Tinoj Joseph | cf161be | 2022-07-07 19:47:47 +0530 | [diff] [blame] | 419 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 420 | //Push Igmp DS Control Flows |
| 421 | err := mvp.ApplyIgmpDSFlowForMvp(cntx, d.Name) |
| 422 | if err != nil { |
| 423 | logger.Errorw(ctx, "DS IGMP Flow Add Failed for device", |
| 424 | log.Fields{"Reason": err.Error(), "device": d.Name}) |
| 425 | } |
Tinoj Joseph | cf161be | 2022-07-07 19:47:47 +0530 | [diff] [blame] | 426 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 427 | //Trigger Join for static channels |
| 428 | if channelList, containsStatic := mvp.getAllStaticChannels(); containsStatic { |
| 429 | mvp.ProcessStaticGroup(cntx, d.Name, channelList, true) |
| 430 | } else { |
| 431 | logger.Infow(ctx, "No Static Channels Present", log.Fields{"mvp": mvp.Name, "Mvlan": mvp.Mvlan}) |
| 432 | } |
| 433 | } |
Tinoj Joseph | cf161be | 2022-07-07 19:47:47 +0530 | [diff] [blame] | 434 | } |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 435 | |
| 436 | // removeIgmpMcastFlows - Removes all IGMP related flows (generic DS flow & static group flows) |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 437 | func (mvp *MvlanProfile) removeIgmpMcastFlows(cntx context.Context, oltSerialNum string) { |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 438 | mvp.mvpLock.RLock() |
| 439 | defer mvp.mvpLock.RUnlock() |
Tinoj Joseph | cf161be | 2022-07-07 19:47:47 +0530 | [diff] [blame] | 440 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 441 | if d, _ := GetApplication().GetDeviceBySerialNo(oltSerialNum); d != nil { |
Sridhar Ravindra | b76eb16 | 2025-07-02 01:25:10 +0530 | [diff] [blame^] | 442 | nniPort, err := GetApplication().GetNniPort(d.Name) |
| 443 | if err != nil { |
| 444 | logger.Errorw(ctx, "Error getting NNI port", log.Fields{"Error": err}) |
| 445 | } |
| 446 | p := d.GetPort(nniPort) |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 447 | if p != nil { |
| 448 | logger.Infow(ctx, "NNI Port Status is: UP", log.Fields{"Device": d, "port": p}) |
Tinoj Joseph | cf161be | 2022-07-07 19:47:47 +0530 | [diff] [blame] | 449 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 450 | // ***Do not change the order*** |
| 451 | // When Vlan is disabled, the process end is determined by the DS Igmp flag in device |
Tinoj Joseph | cf161be | 2022-07-07 19:47:47 +0530 | [diff] [blame] | 452 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 453 | //Trigger Leave for static channels |
| 454 | if channelList, containsStatic := mvp.getAllStaticChannels(); containsStatic { |
| 455 | mvp.ProcessStaticGroup(cntx, d.Name, channelList, false) |
| 456 | } else { |
| 457 | logger.Infow(ctx, "No Static Channels Present", log.Fields{"mvp": mvp.Name, "Mvlan": mvp.Mvlan}) |
| 458 | } |
Tinoj Joseph | cf161be | 2022-07-07 19:47:47 +0530 | [diff] [blame] | 459 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 460 | //Remove all dynamic members for the Mvlan Profile |
| 461 | GetApplication().IgmpGroups.Range(func(key, value interface{}) bool { |
| 462 | ig := value.(*IgmpGroup) |
| 463 | if ig.Mvlan == mvp.Mvlan { |
| 464 | igd := ig.Devices[d.Name] |
| 465 | ig.DelIgmpGroupDevice(cntx, igd) |
| 466 | if ig.NumDevicesActive() == 0 { |
| 467 | GetApplication().DelIgmpGroup(cntx, ig) |
| 468 | } |
| 469 | } |
| 470 | return true |
| 471 | }) |
Tinoj Joseph | cf161be | 2022-07-07 19:47:47 +0530 | [diff] [blame] | 472 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 473 | //Remove DS Igmp trap flow |
| 474 | err := mvp.RemoveIgmpDSFlowForMvp(cntx, d.Name) |
| 475 | if err != nil { |
| 476 | logger.Errorw(ctx, "DS IGMP Flow Del Failed", log.Fields{"Reason": err.Error(), "device": d.Name}) |
| 477 | } |
| 478 | } |
| 479 | } |
Tinoj Joseph | cf161be | 2022-07-07 19:47:47 +0530 | [diff] [blame] | 480 | } |
| 481 | |
| 482 | // ApplyIgmpDSFlowForMvp to apply Igmp DS flow for mvlan. |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 483 | func (mvp *MvlanProfile) ApplyIgmpDSFlowForMvp(cntx context.Context, device string) error { |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 484 | va := GetApplication() |
| 485 | dIntf, ok := va.DevicesDisc.Load(device) |
| 486 | if !ok { |
| 487 | return errors.New("Device Doesn't Exist") |
| 488 | } |
| 489 | d := dIntf.(*VoltDevice) |
| 490 | mvlan := mvp.Mvlan |
Tinoj Joseph | cf161be | 2022-07-07 19:47:47 +0530 | [diff] [blame] | 491 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 492 | flowAlreadyApplied, ok := d.IgmpDsFlowAppliedForMvlan[uint16(mvlan)] |
| 493 | if !ok || !flowAlreadyApplied { |
| 494 | flows, err := mvp.BuildIgmpDSFlows(device) |
| 495 | if err == nil { |
Sridhar Ravindra | b76eb16 | 2025-07-02 01:25:10 +0530 | [diff] [blame^] | 496 | nniPort, err1 := va.GetNniPort(device) |
| 497 | if err1 != nil { |
| 498 | logger.Errorw(ctx, "Error getting NNI port", log.Fields{"Error": err1}) |
| 499 | } |
| 500 | err = cntlr.GetController().AddFlows(cntx, nniPort, device, flows) |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 501 | if err != nil { |
| 502 | logger.Warnw(ctx, "Configuring IGMP Flow for device failed ", log.Fields{"Device": device, "err": err}) |
| 503 | return err |
| 504 | } |
| 505 | d.IgmpDsFlowAppliedForMvlan[uint16(mvlan)] = true |
| 506 | logger.Infow(ctx, "Updating voltDevice that IGMP DS flow as \"added\" for ", |
| 507 | log.Fields{"device": d.SerialNum, "mvlan": mvlan}) |
| 508 | } else { |
| 509 | logger.Errorw(ctx, "DS IGMP Flow Add Failed", log.Fields{"Reason": err.Error(), "Mvlan": mvlan}) |
| 510 | } |
| 511 | } |
Tinoj Joseph | cf161be | 2022-07-07 19:47:47 +0530 | [diff] [blame] | 512 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 513 | return nil |
Tinoj Joseph | cf161be | 2022-07-07 19:47:47 +0530 | [diff] [blame] | 514 | } |
| 515 | |
| 516 | // RemoveIgmpDSFlowForMvp to remove Igmp DS flow for mvlan. |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 517 | func (mvp *MvlanProfile) RemoveIgmpDSFlowForMvp(cntx context.Context, device string) error { |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 518 | va := GetApplication() |
| 519 | mvlan := mvp.Mvlan |
Tinoj Joseph | cf161be | 2022-07-07 19:47:47 +0530 | [diff] [blame] | 520 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 521 | dIntf, ok := va.DevicesDisc.Load(device) |
| 522 | if !ok { |
| 523 | return errors.New("Device Doesn't Exist") |
| 524 | } |
| 525 | d := dIntf.(*VoltDevice) |
| 526 | /* No need of strict check during DS IGMP deletion |
| 527 | flowAlreadyApplied, ok := d.IgmpDsFlowAppliedForMvlan[uint16(mvlan)] |
| 528 | if ok && flowAlreadyApplied |
| 529 | */ |
| 530 | flows, err := mvp.BuildIgmpDSFlows(device) |
| 531 | if err == nil { |
| 532 | flows.ForceAction = true |
Tinoj Joseph | cf161be | 2022-07-07 19:47:47 +0530 | [diff] [blame] | 533 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 534 | err = mvp.DelFlows(cntx, d, flows) |
| 535 | if err != nil { |
| 536 | logger.Warnw(ctx, "De-Configuring IGMP Flow for device failed ", log.Fields{"Device": device, "err": err}) |
| 537 | return err |
| 538 | } |
| 539 | d.IgmpDsFlowAppliedForMvlan[uint16(mvlan)] = false |
| 540 | logger.Infow(ctx, "Updating voltDevice that IGMP DS flow as \"removed\" for ", |
| 541 | log.Fields{"device": d.SerialNum, "mvlan": mvlan}) |
| 542 | } else { |
| 543 | logger.Errorw(ctx, "DS IGMP Flow Del Failed", log.Fields{"Reason": err.Error()}) |
| 544 | } |
Tinoj Joseph | cf161be | 2022-07-07 19:47:47 +0530 | [diff] [blame] | 545 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 546 | return nil |
Tinoj Joseph | cf161be | 2022-07-07 19:47:47 +0530 | [diff] [blame] | 547 | } |
| 548 | |
| 549 | // BuildIgmpDSFlows to build Igmp DS flows for NNI port |
| 550 | func (mvp *MvlanProfile) BuildIgmpDSFlows(device string) (*of.VoltFlow, error) { |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 551 | dIntf, ok := GetApplication().DevicesDisc.Load(device) |
| 552 | if !ok { |
| 553 | return nil, errors.New("Device Doesn't Exist") |
| 554 | } |
| 555 | d := dIntf.(*VoltDevice) |
Tinoj Joseph | cf161be | 2022-07-07 19:47:47 +0530 | [diff] [blame] | 556 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 557 | logger.Infow(ctx, "Building DS IGMP Flow for NNI port", log.Fields{"vs": d.NniPort, "Mvlan": mvp.Mvlan}) |
| 558 | flow := &of.VoltFlow{} |
| 559 | flow.SubFlows = make(map[uint64]*of.VoltSubFlow) |
| 560 | subFlow := of.NewVoltSubFlow() |
| 561 | subFlow.SetTableID(0) |
| 562 | subFlow.SetMatchVlan(mvp.Mvlan) |
Tinoj Joseph | cf161be | 2022-07-07 19:47:47 +0530 | [diff] [blame] | 563 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 564 | nniPort, err := GetApplication().GetNniPort(device) |
| 565 | if err != nil { |
| 566 | return nil, err |
| 567 | } |
| 568 | nniPortID, err1 := GetApplication().GetPortID(nniPort) |
| 569 | if err1 != nil { |
| 570 | return nil, errors.New("Unknown NNI outport") |
| 571 | } |
| 572 | subFlow.SetInPort(nniPortID) |
| 573 | subFlow.SetIgmpMatch() |
| 574 | subFlow.SetReportToController() |
| 575 | subFlow.Cookie = uint64(nniPortID)<<32 | uint64(mvp.Mvlan) |
| 576 | subFlow.Priority = of.IgmpFlowPriority |
Tinoj Joseph | cf161be | 2022-07-07 19:47:47 +0530 | [diff] [blame] | 577 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 578 | flow.SubFlows[subFlow.Cookie] = subFlow |
| 579 | logger.Infow(ctx, "Built DS IGMP flow", log.Fields{"cookie": subFlow.Cookie, "subflow": subFlow}) |
| 580 | return flow, nil |
Tinoj Joseph | cf161be | 2022-07-07 19:47:47 +0530 | [diff] [blame] | 581 | } |
| 582 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 583 | // updateStaticGroups - Generates static joins & leaves for newly added and removed static channels respectively |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 584 | func (mvp *MvlanProfile) updateStaticGroups(cntx context.Context, deviceID string, added []net.IP, removed []net.IP) { |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 585 | // Update static group configs for all associated devices |
| 586 | updateGroups := func(key interface{}, value interface{}) bool { |
| 587 | d := value.(*VoltDevice) |
Tinoj Joseph | cf161be | 2022-07-07 19:47:47 +0530 | [diff] [blame] | 588 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 589 | if mvp.DevicesList[d.SerialNum] == Nil { |
| 590 | logger.Infow(ctx, "Mvlan Profile not configure for device", log.Fields{"Device": d, "Profile Device List": mvp.DevicesList}) |
| 591 | return true |
| 592 | } |
| 593 | // TODO if mvp.IsChannelBasedGroup { |
| 594 | mvp.ProcessStaticGroup(cntx, d.Name, added, true) |
| 595 | mvp.ProcessStaticGroup(cntx, d.Name, removed, false) |
| 596 | //} |
| 597 | return true |
| 598 | } |
Tinoj Joseph | cf161be | 2022-07-07 19:47:47 +0530 | [diff] [blame] | 599 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 600 | if deviceID != "" { |
| 601 | vd := GetApplication().GetDevice(deviceID) |
| 602 | updateGroups(deviceID, vd) |
| 603 | } else { |
| 604 | GetApplication().DevicesDisc.Range(updateGroups) |
| 605 | } |
Tinoj Joseph | cf161be | 2022-07-07 19:47:47 +0530 | [diff] [blame] | 606 | } |
| 607 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 608 | // updateDynamicGroups - Generates joins with updated sources for existing channels |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 609 | func (mvp *MvlanProfile) updateDynamicGroups(cntx context.Context, deviceID string, added []net.IP, removed []net.IP) { |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 610 | //mvlan := mvp.Mvlan |
| 611 | va := GetApplication() |
Tinoj Joseph | cf161be | 2022-07-07 19:47:47 +0530 | [diff] [blame] | 612 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 613 | updateGroups := func(key interface{}, value interface{}) bool { |
| 614 | d := value.(*VoltDevice) |
Tinoj Joseph | cf161be | 2022-07-07 19:47:47 +0530 | [diff] [blame] | 615 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 616 | if mvp.DevicesList[d.SerialNum] == Nil { |
| 617 | logger.Infow(ctx, "Mvlan Profile not configure for device", log.Fields{"Device": d, "Profile Device List": mvp.DevicesList}) |
| 618 | return true |
| 619 | } |
| 620 | for _, groupAddr := range added { |
| 621 | _, gName := va.GetMvlanProfileForMcIP(mvp.Name, groupAddr) |
| 622 | grpKey := mvp.generateGroupKey(gName, groupAddr.String()) |
| 623 | logger.Debugw(ctx, "IGMP Group", log.Fields{"Group": grpKey, "groupAddr": groupAddr}) |
| 624 | if igIntf, ok := va.IgmpGroups.Load(grpKey); ok { |
| 625 | ig := igIntf.(*IgmpGroup) |
| 626 | if igd, ok := ig.getIgmpGroupDevice(cntx, d.Name); ok { |
| 627 | if igcIntf, ok := igd.GroupChannels.Load(groupAddr.String()); ok { |
| 628 | igc := igcIntf.(*IgmpGroupChannel) |
| 629 | incl := false |
| 630 | var ip []net.IP |
| 631 | var groupModified = false |
| 632 | if _, ok := mvp.Proxy[igc.GroupName]; ok { |
| 633 | if mvp.Proxy[igc.GroupName].Mode == common.Include { |
| 634 | incl = true |
| 635 | } |
| 636 | ip = mvp.Proxy[igc.GroupName].SourceList |
| 637 | } |
| 638 | for port, igp := range igc.NewReceivers { |
| 639 | // Process the include/exclude list which may end up modifying the group |
| 640 | if change, _ := igc.ProcessSources(cntx, port, ip, incl); change { |
| 641 | groupModified = true |
| 642 | } |
| 643 | igc.ProcessMode(port, incl) |
Tinoj Joseph | cf161be | 2022-07-07 19:47:47 +0530 | [diff] [blame] | 644 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 645 | if err := igp.WriteToDb(cntx, igc.Mvlan, igc.GroupAddr, igc.Device); err != nil { |
| 646 | logger.Errorw(ctx, "Igmp group port Write to DB failed", log.Fields{"mvlan": igc.Mvlan, "GroupAddr": igc.GroupAddr}) |
| 647 | } |
| 648 | } |
| 649 | // If the group is modified as this is the first receiver or due to include/exclude list modification |
| 650 | // send a report to the upstream multicast servers |
| 651 | if groupModified { |
| 652 | logger.Debug(ctx, "Group Modified and IGMP report sent to the upstream server") |
| 653 | igc.SendReport(false) |
| 654 | } |
| 655 | if err := igc.WriteToDb(cntx); err != nil { |
| 656 | logger.Errorw(ctx, "Igmp group channel Write to DB failed", log.Fields{"mvlan": igc.Mvlan, "GroupAddr": igc.GroupAddr}) |
| 657 | } |
| 658 | } |
| 659 | } |
| 660 | } |
| 661 | } |
Tinoj Joseph | cf161be | 2022-07-07 19:47:47 +0530 | [diff] [blame] | 662 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 663 | return true |
| 664 | } |
Tinoj Joseph | cf161be | 2022-07-07 19:47:47 +0530 | [diff] [blame] | 665 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 666 | if deviceID != "" { |
| 667 | vd := GetApplication().GetDevice(deviceID) |
| 668 | updateGroups(deviceID, vd) |
| 669 | } else { |
| 670 | GetApplication().DevicesDisc.Range(updateGroups) |
| 671 | } |
Tinoj Joseph | cf161be | 2022-07-07 19:47:47 +0530 | [diff] [blame] | 672 | } |
| 673 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 674 | // GroupsUpdated - Handles removing of Igmp Groups, flows & group table entries for |
| 675 | // channels removed as part of update |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 676 | func (mvp *MvlanProfile) GroupsUpdated(cntx context.Context, deviceID string) { |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 677 | deleteChannelIfRemoved := func(key interface{}, value interface{}) bool { |
| 678 | ig := value.(*IgmpGroup) |
Tinoj Joseph | cf161be | 2022-07-07 19:47:47 +0530 | [diff] [blame] | 679 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 680 | if ig.Mvlan != mvp.Mvlan { |
| 681 | return true |
| 682 | } |
| 683 | grpName := ig.GroupName |
| 684 | logger.Infow(ctx, "###Update Cycle", log.Fields{"IG": ig.GroupName, "Addr": ig.GroupAddr}) |
| 685 | // Check if group exists and remove the entire group object otherwise |
| 686 | if currentChannels := mvp.Groups[grpName]; currentChannels != nil { |
| 687 | if mvp.IsChannelBasedGroup { |
| 688 | channelPresent := doesIPMatch(ig.GroupAddr, currentChannels.McIPs) |
| 689 | if channelPresent || mvp.isChannelStatic(ig.GroupAddr) { |
| 690 | return true |
| 691 | } |
| 692 | } else { |
| 693 | allExistingChannels := ig.GetAllIgmpChannelForDevice(deviceID) |
| 694 | for channel := range allExistingChannels { |
| 695 | channelIP := net.ParseIP(channel) |
| 696 | channelPresent := mvp.IsChannelPresent(channelIP, currentChannels.McIPs, mvp.IsStaticGroup(ig.GroupName)) |
| 697 | if channelPresent { |
| 698 | staticChannel := mvp.isChannelStatic(channelIP) |
| 699 | logger.Infow(ctx, "###Channel Comparison", log.Fields{"staticChannel": staticChannel, "Group": mvp.IsStaticGroup(ig.GroupName), "Channel": channel}) |
| 700 | // Logic: |
| 701 | // If channel is Static & existing Group is also static - No migration required |
| 702 | // If channel is not Static & existing Group is also not static - No migration required |
Tinoj Joseph | cf161be | 2022-07-07 19:47:47 +0530 | [diff] [blame] | 703 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 704 | // If channel is Static and existing Group is not static - Migrate (from dynamic to static) |
| 705 | // (Channel already part of dynamic, added to static) |
Tinoj Joseph | cf161be | 2022-07-07 19:47:47 +0530 | [diff] [blame] | 706 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 707 | // If channel is not Static but existing Group is static - Migrate (from static to dynamic) |
| 708 | // (Channel removed from satic but part of dynamic) |
| 709 | if (staticChannel != mvp.IsStaticGroup(ig.GroupName)) || (ig.IsGroupStatic != mvp.IsStaticGroup(ig.GroupName)) { // Equivalent of XOR |
| 710 | ig.HandleGroupMigration(cntx, deviceID, channelIP) |
| 711 | } else { |
| 712 | if (ig.IsGroupStatic) && mvp.IsStaticGroup(ig.GroupName) { |
| 713 | if ig.GroupName != mvp.GetStaticGroupName(channelIP) { |
| 714 | ig.HandleGroupMigration(cntx, deviceID, channelIP) |
| 715 | } |
| 716 | } |
| 717 | continue |
| 718 | } |
| 719 | } else { |
| 720 | logger.Debugw(ctx, "Channel Removed", log.Fields{"Channel": channel, "Group": grpName}) |
| 721 | ig.DelIgmpChannel(cntx, deviceID, net.ParseIP(channel)) |
| 722 | if ig.NumDevicesActive() == 0 { |
| 723 | GetApplication().DelIgmpGroup(cntx, ig) |
| 724 | } |
| 725 | } |
| 726 | } |
| 727 | ig.IsGroupStatic = mvp.IsStaticGroup(ig.GroupName) |
| 728 | if err := ig.WriteToDb(cntx); err != nil { |
| 729 | logger.Errorw(ctx, "Igmp group Write to DB failed", log.Fields{"groupName": ig.GroupName}) |
| 730 | } |
| 731 | return true |
| 732 | } |
| 733 | } |
| 734 | logger.Debugw(ctx, "Group Removed", log.Fields{"Channel": ig.GroupAddr, "Group": grpName, "ChannelBasedGroup": ig.IsChannelBasedGroup}) |
| 735 | ig.DelIgmpGroup(cntx) |
| 736 | logger.Debugw(ctx, "Removed Igmp Group", log.Fields{"Channel": ig.GroupAddr, "Group": grpName}) |
| 737 | return true |
| 738 | } |
| 739 | GetApplication().IgmpGroups.Range(deleteChannelIfRemoved) |
Tinoj Joseph | cf161be | 2022-07-07 19:47:47 +0530 | [diff] [blame] | 740 | } |
| 741 | |
| 742 | // IsChannelPresent to check if channel is present |
| 743 | func (mvp *MvlanProfile) IsChannelPresent(channelIP net.IP, groupChannelList []string, IsStaticGroup bool) bool { |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 744 | // Only in case of static group, migration need to be supported. |
| 745 | // Dynamic to dynamic group migration not supported currently |
| 746 | if doesIPMatch(channelIP, groupChannelList) || mvp.isChannelStatic(channelIP) { |
| 747 | return true |
| 748 | } else if IsStaticGroup { |
| 749 | return (mvp.GetMvlanGroup(channelIP) != "") |
| 750 | } |
Tinoj Joseph | cf161be | 2022-07-07 19:47:47 +0530 | [diff] [blame] | 751 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 752 | return false |
Tinoj Joseph | cf161be | 2022-07-07 19:47:47 +0530 | [diff] [blame] | 753 | } |
| 754 | |
Tinoj Joseph | cf161be | 2022-07-07 19:47:47 +0530 | [diff] [blame] | 755 | // GetMvlanGroup to get mvlan group |
| 756 | func (mvp *MvlanProfile) GetMvlanGroup(ip net.IP) string { |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 757 | // Check for Static Group First |
| 758 | if mvp.containsStaticChannels() { |
| 759 | grpName := mvp.GetStaticGroupName(ip) |
| 760 | if grpName != "" { |
| 761 | return grpName |
| 762 | } |
| 763 | } |
Tinoj Joseph | cf161be | 2022-07-07 19:47:47 +0530 | [diff] [blame] | 764 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 765 | for _, mvg := range mvp.Groups { |
| 766 | if mvg.Wildcard { |
| 767 | return mvg.Name |
| 768 | } |
| 769 | if doesIPMatch(ip, mvg.McIPs) { |
| 770 | return mvg.Name |
| 771 | } |
| 772 | } |
| 773 | return "" |
Tinoj Joseph | cf161be | 2022-07-07 19:47:47 +0530 | [diff] [blame] | 774 | } |
| 775 | |
| 776 | // ProcessStaticGroup - Process Static Join/Leave Req for static channels |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 777 | func (mvp *MvlanProfile) ProcessStaticGroup(cntx context.Context, device string, groupAddresses []net.IP, isJoin bool) { |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 778 | logger.Debugw(ctx, "Received Static Group Request", log.Fields{"Device": device, "Join": isJoin, "Group Address List": groupAddresses}) |
Tinoj Joseph | cf161be | 2022-07-07 19:47:47 +0530 | [diff] [blame] | 779 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 780 | mvlan := mvp.Mvlan |
| 781 | va := GetApplication() |
Tinoj Joseph | cf161be | 2022-07-07 19:47:47 +0530 | [diff] [blame] | 782 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 783 | // TODO - Handle bulk add of groupAddr |
| 784 | for _, groupAddr := range groupAddresses { |
| 785 | ig := mvp.GetStaticIgmpGroup(groupAddr) |
| 786 | if isJoin { |
| 787 | vd := va.GetDevice(device) |
| 788 | igmpProf, _, _ := getIgmpProxyCfgAndIP(mvlan, vd.SerialNum) |
| 789 | ver := igmpProf.IgmpVerToServer |
Tinoj Joseph | cf161be | 2022-07-07 19:47:47 +0530 | [diff] [blame] | 790 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 791 | if ig == nil { |
| 792 | // First time group Creation: Create the IGMP group and then add the receiver to the group |
| 793 | logger.Infow(ctx, "Static IGMP Add received for new group", log.Fields{"Addr": groupAddr, "Port": StaticPort}) |
| 794 | if ig = GetApplication().AddIgmpGroup(cntx, mvp.Name, groupAddr, device); ig != nil { |
| 795 | ig.IgmpGroupLock.Lock() |
| 796 | ig.AddReceiver(cntx, device, StaticPort, groupAddr, nil, getVersion(ver), |
| 797 | 0, 0, 0xFF) |
| 798 | ig.IgmpGroupLock.Unlock() |
| 799 | } else { |
| 800 | logger.Warnw(ctx, "Static IGMP Group Creation Failed", log.Fields{"Addr": groupAddr}) |
| 801 | } |
| 802 | } else { |
| 803 | // Converting existing dynamic group to static group |
| 804 | if !mvp.IsStaticGroup(ig.GroupName) { |
| 805 | ig.updateGroupName(cntx, ig.GroupName) |
| 806 | } |
| 807 | // Update case: If the IGMP group is already created. just add the receiver |
| 808 | logger.Infow(ctx, "Static IGMP Add received for existing group", log.Fields{"Addr": groupAddr, "Port": StaticPort}) |
| 809 | ig.IgmpGroupLock.Lock() |
| 810 | ig.AddReceiver(cntx, device, StaticPort, groupAddr, nil, getVersion(ver), |
| 811 | 0, 0, 0xFF) |
| 812 | ig.IgmpGroupLock.Unlock() |
| 813 | } |
| 814 | } else if ig != nil { |
| 815 | logger.Infow(ctx, "Static IGMP Del received for existing group", log.Fields{"Addr": groupAddr, "Port": StaticPort}) |
Tinoj Joseph | cf161be | 2022-07-07 19:47:47 +0530 | [diff] [blame] | 816 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 817 | if ig.IsChannelBasedGroup { |
| 818 | grpName := mvp.GetMvlanGroup(ig.GroupAddr) |
| 819 | if grpName != "" { |
| 820 | ig.IgmpGroupLock.Lock() |
| 821 | ig.DelReceiver(cntx, device, StaticPort, groupAddr, nil, 0xFF) |
| 822 | ig.IgmpGroupLock.Unlock() |
| 823 | ig.updateGroupName(cntx, grpName) |
| 824 | } else { |
| 825 | ig.DelIgmpGroup(cntx) |
| 826 | } |
| 827 | } else { |
| 828 | ig.IgmpGroupLock.Lock() |
| 829 | ig.DelReceiver(cntx, device, StaticPort, groupAddr, nil, 0xFF) |
| 830 | ig.IgmpGroupLock.Unlock() |
| 831 | } |
| 832 | if ig.NumDevicesActive() == 0 { |
| 833 | GetApplication().DelIgmpGroup(cntx, ig) |
| 834 | } |
| 835 | } else { |
| 836 | logger.Warnw(ctx, "Static IGMP Del received for unknown group", log.Fields{"Addr": groupAddr}) |
| 837 | } |
| 838 | } |
Tinoj Joseph | cf161be | 2022-07-07 19:47:47 +0530 | [diff] [blame] | 839 | } |
| 840 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 841 | // getStaticChannelDiff - return the static channel newly added and removed from existing static group |
Tinoj Joseph | cf161be | 2022-07-07 19:47:47 +0530 | [diff] [blame] | 842 | func (mvp *MvlanProfile) getStaticChannelDiff() (newlyAdded []net.IP, removed []net.IP, common []net.IP) { |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 843 | var commonChannels []net.IP |
| 844 | newChannelList, _ := mvp.getAllStaticChannels() |
| 845 | existingChannelList, _ := mvp.getAllOldGroupStaticChannels() |
| 846 | if len(existingChannelList) == 0 { |
| 847 | return newChannelList, []net.IP{}, []net.IP{} |
| 848 | } |
| 849 | for _, newChannel := range append([]net.IP{}, newChannelList...) { |
| 850 | for _, existChannel := range append([]net.IP{}, existingChannelList...) { |
| 851 | // Remove common channels between existing and new list |
| 852 | // The remaining in the below slices give the results |
| 853 | // Remaining in newChannelList: Newly added |
| 854 | // Remaining in existingChannelList: Removed channels |
| 855 | if existChannel.Equal(newChannel) { |
| 856 | existingChannelList = removeIPFromList(existingChannelList, existChannel) |
| 857 | newChannelList = removeIPFromList(newChannelList, newChannel) |
| 858 | commonChannels = append(commonChannels, newChannel) |
| 859 | logger.Infow(ctx, "#############Channel: "+existChannel.String()+" New: "+newChannel.String(), log.Fields{"Added": newChannelList, "Removed": existingChannelList}) |
| 860 | break |
| 861 | } |
| 862 | } |
| 863 | } |
| 864 | return newChannelList, existingChannelList, commonChannels |
Tinoj Joseph | cf161be | 2022-07-07 19:47:47 +0530 | [diff] [blame] | 865 | } |
| 866 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 867 | // getGroupChannelDiff - return the channel newly added and removed from existing group |
Tinoj Joseph | cf161be | 2022-07-07 19:47:47 +0530 | [diff] [blame] | 868 | func (mvp *MvlanProfile) getGroupChannelDiff(newGroup *MvlanGroup, oldGroup *MvlanGroup) (newlyAdded []net.IP, removed []net.IP, common []net.IP) { |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 869 | var commonChannels []net.IP |
| 870 | newChannelList, _ := newGroup.getAllChannels() |
| 871 | existingChannelList, _ := oldGroup.getAllChannels() |
| 872 | if len(existingChannelList) == 0 { |
| 873 | return newChannelList, []net.IP{}, []net.IP{} |
| 874 | } |
| 875 | for _, newChannel := range append([]net.IP{}, newChannelList...) { |
| 876 | for _, existChannel := range append([]net.IP{}, existingChannelList...) { |
| 877 | // Remove common channels between existing and new list |
| 878 | // The remaining in the below slices give the results |
| 879 | // Remaining in newChannelList: Newly added |
| 880 | // Remaining in existingChannelList: Removed channels |
| 881 | if existChannel.Equal(newChannel) { |
| 882 | existingChannelList = removeIPFromList(existingChannelList, existChannel) |
| 883 | newChannelList = removeIPFromList(newChannelList, newChannel) |
| 884 | commonChannels = append(commonChannels, newChannel) |
| 885 | logger.Infow(ctx, "#############Channel: "+existChannel.String()+" New: "+newChannel.String(), log.Fields{"Added": newChannelList, "Removed": existingChannelList}) |
| 886 | break |
| 887 | } |
| 888 | } |
| 889 | } |
| 890 | return newChannelList, existingChannelList, commonChannels |
Tinoj Joseph | cf161be | 2022-07-07 19:47:47 +0530 | [diff] [blame] | 891 | } |
| 892 | |
| 893 | // UpdateProfile - Updates the group & member info w.r.t the mvlan profile for the given device |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 894 | func (mvp *MvlanProfile) UpdateProfile(cntx context.Context, deviceID string) { |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 895 | logger.Infow(ctx, "Update Mvlan Profile task triggered", log.Fields{"Mvlan": mvp.Mvlan}) |
| 896 | var removedStaticChannels []net.IP |
| 897 | addedStaticChannels := []net.IP{} |
| 898 | /* Taking mvpLock to protect the mvp groups and proxy */ |
| 899 | mvp.mvpLock.RLock() |
| 900 | defer mvp.mvpLock.RUnlock() |
Tinoj Joseph | cf161be | 2022-07-07 19:47:47 +0530 | [diff] [blame] | 901 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 902 | serialNo := "" |
| 903 | if deviceID != "" { |
| 904 | if vd := GetApplication().GetDevice(deviceID); vd != nil { |
| 905 | serialNo = vd.SerialNum |
| 906 | if mvp.DevicesList[serialNo] != UpdateInProgress { |
| 907 | logger.Warnw(ctx, "Exiting Update Task since device not present in MvlanProfile", log.Fields{"Device": deviceID, "SerialNum": vd.SerialNum, "MvlanProfile": mvp}) |
| 908 | return |
| 909 | } |
| 910 | } else { |
| 911 | logger.Errorw(ctx, "Volt Device not found. Stopping Update Mvlan Profile processing for device", log.Fields{"SerialNo": deviceID, "MvlanProfile": mvp}) |
| 912 | return |
| 913 | } |
| 914 | } |
Tinoj Joseph | cf161be | 2022-07-07 19:47:47 +0530 | [diff] [blame] | 915 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 916 | // Update the groups based on static channels added & removed |
| 917 | if mvp.containsStaticChannels() { |
| 918 | addedStaticChannels, removedStaticChannels, _ = mvp.getStaticChannelDiff() |
| 919 | logger.Debugw(ctx, "Update Task - Static Group Changes", log.Fields{"Added": addedStaticChannels, "Removed": removedStaticChannels}) |
Tinoj Joseph | cf161be | 2022-07-07 19:47:47 +0530 | [diff] [blame] | 920 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 921 | if len(addedStaticChannels) > 0 || len(removedStaticChannels) > 0 { |
| 922 | mvp.updateStaticGroups(cntx, deviceID, []net.IP{}, removedStaticChannels) |
| 923 | } |
| 924 | } |
| 925 | mvp.GroupsUpdated(cntx, deviceID) |
| 926 | if len(addedStaticChannels) > 0 { |
| 927 | mvp.updateStaticGroups(cntx, deviceID, addedStaticChannels, []net.IP{}) |
| 928 | } |
Tinoj Joseph | cf161be | 2022-07-07 19:47:47 +0530 | [diff] [blame] | 929 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 930 | /* Need to handle if SSM params are modified for groups */ |
| 931 | for key := range mvp.Groups { |
| 932 | _, _, commonChannels := mvp.getGroupChannelDiff(mvp.Groups[key], mvp.oldGroups[key]) |
| 933 | if mvp.checkStaticGrpSSMProxyDiff(mvp.oldProxy[key], mvp.Proxy[key]) { |
| 934 | if mvp.Groups[key].IsStatic { |
| 935 | /* Static group proxy modified, need to trigger membership report with new mode/src-list for existing channels */ |
| 936 | mvp.updateStaticGroups(cntx, deviceID, commonChannels, []net.IP{}) |
| 937 | } else { |
| 938 | /* Dynamic group proxy modified, need to trigger membership report with new mode/src-list for existing channels */ |
| 939 | mvp.updateDynamicGroups(cntx, deviceID, commonChannels, []net.IP{}) |
| 940 | } |
| 941 | } |
| 942 | } |
Tinoj Joseph | cf161be | 2022-07-07 19:47:47 +0530 | [diff] [blame] | 943 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 944 | mvp.SetUpdateStatus(serialNo, NoOp) |
Tinoj Joseph | cf161be | 2022-07-07 19:47:47 +0530 | [diff] [blame] | 945 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 946 | if deviceID == "" || !mvp.isUpdateInProgress() { |
| 947 | mvp.oldGroups = nil |
| 948 | } |
| 949 | if err := mvp.WriteToDb(cntx); err != nil { |
| 950 | logger.Errorw(ctx, "Mvlan profile write to DB failed", log.Fields{"ProfileName": mvp.Name}) |
| 951 | } |
| 952 | logger.Debugw(ctx, "Updated MVLAN Profile", log.Fields{"VLAN": mvp.Mvlan, "Name": mvp.Name, "Grp IPs": mvp.Groups}) |
Tinoj Joseph | cf161be | 2022-07-07 19:47:47 +0530 | [diff] [blame] | 953 | } |
| 954 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 955 | // checkStaticGrpSSMProxyDiff- return true if the proxy of oldGroup is modified in newGroup |
Tinoj Joseph | cf161be | 2022-07-07 19:47:47 +0530 | [diff] [blame] | 956 | func (mvp *MvlanProfile) checkStaticGrpSSMProxyDiff(oldProxy *MCGroupProxy, newProxy *MCGroupProxy) bool { |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 957 | if oldProxy == nil && newProxy == nil { |
| 958 | return false |
| 959 | } |
| 960 | if (oldProxy == nil && newProxy != nil) || |
| 961 | (oldProxy != nil && newProxy == nil) { |
| 962 | return true |
| 963 | } |
Tinoj Joseph | cf161be | 2022-07-07 19:47:47 +0530 | [diff] [blame] | 964 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 965 | if oldProxy.Mode != newProxy.Mode { |
| 966 | return true |
| 967 | } |
Tinoj Joseph | cf161be | 2022-07-07 19:47:47 +0530 | [diff] [blame] | 968 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 969 | oldSrcLst := oldProxy.SourceList |
| 970 | newSrcLst := newProxy.SourceList |
| 971 | oLen := len(oldSrcLst) |
| 972 | nLen := len(newSrcLst) |
| 973 | if oLen != nLen { |
| 974 | return true |
| 975 | } |
Tinoj Joseph | cf161be | 2022-07-07 19:47:47 +0530 | [diff] [blame] | 976 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 977 | visited := make([]bool, nLen) |
Tinoj Joseph | cf161be | 2022-07-07 19:47:47 +0530 | [diff] [blame] | 978 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 979 | /* check if any new IPs added in the src list, return true if present */ |
| 980 | for i := 0; i < nLen; i++ { |
| 981 | found := false |
| 982 | element := newSrcLst[i] |
| 983 | for j := 0; j < oLen; j++ { |
| 984 | if visited[j] { |
| 985 | continue |
| 986 | } |
| 987 | if element.Equal(oldSrcLst[j]) { |
| 988 | visited[j] = true |
| 989 | found = true |
| 990 | break |
| 991 | } |
| 992 | } |
| 993 | if !found { |
| 994 | return true |
| 995 | } |
| 996 | } |
Tinoj Joseph | cf161be | 2022-07-07 19:47:47 +0530 | [diff] [blame] | 997 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 998 | visited = make([]bool, nLen) |
| 999 | /* check if any IPs removed from existing src list, return true if removed */ |
| 1000 | for i := 0; i < oLen; i++ { |
| 1001 | found := false |
| 1002 | element := oldSrcLst[i] |
| 1003 | for j := 0; j < nLen; j++ { |
| 1004 | if visited[j] { |
| 1005 | continue |
| 1006 | } |
| 1007 | if element.Equal(newSrcLst[j]) { |
| 1008 | visited[j] = true |
| 1009 | found = true |
| 1010 | break |
| 1011 | } |
| 1012 | } |
| 1013 | if !found { |
| 1014 | return true |
| 1015 | } |
| 1016 | } |
| 1017 | return false |
Tinoj Joseph | cf161be | 2022-07-07 19:47:47 +0530 | [diff] [blame] | 1018 | } |
| 1019 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 1020 | // UpdateActiveChannelSubscriberAlarm - Updates the Active Channel Subscriber Alarm |
Tinoj Joseph | cf161be | 2022-07-07 19:47:47 +0530 | [diff] [blame] | 1021 | func (mvp *MvlanProfile) UpdateActiveChannelSubscriberAlarm() { |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 1022 | va := GetApplication() |
| 1023 | logger.Debugw(ctx, "Update of Active Channel Subscriber Alarm", log.Fields{"Mvlan": mvp.Mvlan}) |
| 1024 | for srNo := range mvp.DevicesList { |
| 1025 | d, _ := va.GetDeviceBySerialNo(srNo) |
| 1026 | if d == nil { |
| 1027 | logger.Warnw(ctx, "Device info not found", log.Fields{"Device_SrNo": srNo, "Mvlan": mvp.Mvlan}) |
| 1028 | return |
| 1029 | } |
| 1030 | d.Ports.Range(func(key, value interface{}) bool { |
| 1031 | //port := key.(string) |
| 1032 | vp := value.(*VoltPort) |
| 1033 | if vp.Type != VoltPortTypeAccess { |
| 1034 | return true |
| 1035 | } |
| 1036 | if mvp.MaxActiveChannels > vp.ActiveChannels && vp.ChannelPerSubAlarmRaised { |
| 1037 | serviceName := GetMcastServiceForSubAlarm(vp, mvp) |
| 1038 | logger.Debugw(ctx, "Clearing-SendActiveChannelPerSubscriberAlarm-due-to-update", log.Fields{"ActiveChannels": vp.ActiveChannels, "ServiceName": serviceName}) |
| 1039 | vp.ChannelPerSubAlarmRaised = false |
| 1040 | } else if mvp.MaxActiveChannels < vp.ActiveChannels && !vp.ChannelPerSubAlarmRaised { |
| 1041 | /* When the max active channel count is reduced via update, we raise an alarm. |
Sridhar Ravindra | b76eb16 | 2025-07-02 01:25:10 +0530 | [diff] [blame^] | 1042 | But the previous excess channels still exist until a leave or expiry */ |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 1043 | serviceName := GetMcastServiceForSubAlarm(vp, mvp) |
| 1044 | logger.Debugw(ctx, "Raising-SendActiveChannelPerSubscriberAlarm-due-to-update", log.Fields{"ActiveChannels": vp.ActiveChannels, "ServiceName": serviceName}) |
| 1045 | vp.ChannelPerSubAlarmRaised = true |
| 1046 | } |
| 1047 | return true |
| 1048 | }) |
| 1049 | } |
Tinoj Joseph | cf161be | 2022-07-07 19:47:47 +0530 | [diff] [blame] | 1050 | } |
| 1051 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 1052 | // TriggerAssociatedFlowDelete - Re-trigger delete for pending delete flows |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 1053 | func (mvp *MvlanProfile) TriggerAssociatedFlowDelete(cntx context.Context, device string) bool { |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 1054 | mvp.mvpFlowLock.Lock() |
Tinoj Joseph | cf161be | 2022-07-07 19:47:47 +0530 | [diff] [blame] | 1055 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 1056 | cookieList := []uint64{} |
| 1057 | flowMap := mvp.PendingDeleteFlow[device] |
Tinoj Joseph | cf161be | 2022-07-07 19:47:47 +0530 | [diff] [blame] | 1058 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 1059 | for cookie := range flowMap { |
| 1060 | cookieList = append(cookieList, convertToUInt64(cookie)) |
| 1061 | } |
| 1062 | mvp.mvpFlowLock.Unlock() |
Tinoj Joseph | cf161be | 2022-07-07 19:47:47 +0530 | [diff] [blame] | 1063 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 1064 | if len(cookieList) == 0 { |
| 1065 | return false |
| 1066 | } |
Tinoj Joseph | cf161be | 2022-07-07 19:47:47 +0530 | [diff] [blame] | 1067 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 1068 | for _, cookie := range cookieList { |
| 1069 | if vd := GetApplication().GetDevice(device); vd != nil { |
| 1070 | flow := &of.VoltFlow{} |
| 1071 | flow.SubFlows = make(map[uint64]*of.VoltSubFlow) |
| 1072 | subFlow := of.NewVoltSubFlow() |
| 1073 | subFlow.Cookie = cookie |
| 1074 | flow.SubFlows[cookie] = subFlow |
| 1075 | logger.Infow(ctx, "Retriggering Vnet Delete Flow", log.Fields{"Device": device, "Mvlan": mvp.Mvlan.String(), "Cookie": cookie}) |
| 1076 | err := mvp.DelFlows(cntx, vd, flow) |
| 1077 | if err != nil { |
| 1078 | logger.Warnw(ctx, "De-Configuring IGMP Flow for device failed ", log.Fields{"Device": device, "err": err}) |
| 1079 | } |
| 1080 | } |
| 1081 | } |
| 1082 | return true |
Tinoj Joseph | cf161be | 2022-07-07 19:47:47 +0530 | [diff] [blame] | 1083 | } |
| 1084 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 1085 | // JSONMarshal wrapper function for json Marshal MvlanProfile |
| 1086 | func (mvp *MvlanProfile) JSONMarshal() ([]byte, error) { |
| 1087 | return json.Marshal(MvlanProfile{ |
| 1088 | Name: mvp.Name, |
| 1089 | Mvlan: mvp.Mvlan, |
| 1090 | PonVlan: mvp.PonVlan, |
| 1091 | Groups: mvp.Groups, |
| 1092 | Proxy: mvp.Proxy, |
| 1093 | Version: mvp.Version, |
| 1094 | IsPonVlanPresent: mvp.IsPonVlanPresent, |
| 1095 | IsChannelBasedGroup: mvp.IsChannelBasedGroup, |
| 1096 | DevicesList: mvp.DevicesList, |
| 1097 | MaxActiveChannels: mvp.MaxActiveChannels, |
| 1098 | PendingDeleteFlow: mvp.PendingDeleteFlow, |
| 1099 | DeleteInProgress: mvp.DeleteInProgress, |
| 1100 | IgmpServVersion: mvp.IgmpServVersion, |
| 1101 | }) |
Tinoj Joseph | cf161be | 2022-07-07 19:47:47 +0530 | [diff] [blame] | 1102 | } |
| 1103 | |
| 1104 | // removeIPFromList to remove ip from the list |
| 1105 | func removeIPFromList(s []net.IP, value net.IP) []net.IP { |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 1106 | i := 0 |
| 1107 | for i = 0; i < len(s); i++ { |
| 1108 | if s[i].Equal(value) { |
| 1109 | break |
| 1110 | } |
| 1111 | } |
| 1112 | if i != len(s) { |
| 1113 | //It means value is found in the slice |
| 1114 | return append(s[0:i], s[i+1:]...) |
| 1115 | } |
| 1116 | return s |
Tinoj Joseph | cf161be | 2022-07-07 19:47:47 +0530 | [diff] [blame] | 1117 | } |
| 1118 | |
| 1119 | // doesIPMatch to check if ip match with any ip from the list |
| 1120 | func doesIPMatch(ip net.IP, ipsOrRange []string) bool { |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 1121 | for _, ipOrRange := range ipsOrRange { |
| 1122 | if strings.Contains(ipOrRange, "-") { |
| 1123 | var splits = strings.Split(ipOrRange, "-") |
| 1124 | ipStart := util.IP2LongConv(net.ParseIP(splits[0])) |
| 1125 | ipEnd := util.IP2LongConv(net.ParseIP(splits[1])) |
| 1126 | if ipEnd < ipStart { |
| 1127 | return false |
| 1128 | } |
| 1129 | ipInt := util.IP2LongConv(ip) |
| 1130 | if ipInt >= ipStart && ipInt <= ipEnd { |
| 1131 | return true |
| 1132 | } |
| 1133 | } else if ip.Equal(net.ParseIP(ipOrRange)) { |
| 1134 | return true |
| 1135 | } |
| 1136 | } |
| 1137 | return false |
Tinoj Joseph | cf161be | 2022-07-07 19:47:47 +0530 | [diff] [blame] | 1138 | } |
| 1139 | |
| 1140 | // IgmpProfile structure |
| 1141 | type IgmpProfile struct { |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 1142 | ProfileID string |
| 1143 | IgmpVerToServer string |
| 1144 | Version string |
| 1145 | IgmpSourceIP net.IP |
| 1146 | UnsolicitedTimeOut uint32 //In seconds |
| 1147 | MaxResp uint32 |
| 1148 | KeepAliveInterval uint32 |
| 1149 | KeepAliveCount uint32 |
| 1150 | LastQueryInterval uint32 |
| 1151 | LastQueryCount uint32 |
| 1152 | IgmpCos uint8 |
| 1153 | FastLeave bool |
| 1154 | PeriodicQuery bool |
| 1155 | WithRAUpLink bool |
| 1156 | WithRADownLink bool |
Tinoj Joseph | cf161be | 2022-07-07 19:47:47 +0530 | [diff] [blame] | 1157 | } |
| 1158 | |
| 1159 | func newIgmpProfile(igmpProfileConfig *common.IGMPConfig) *IgmpProfile { |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 1160 | var igmpProfile IgmpProfile |
| 1161 | igmpProfile.ProfileID = igmpProfileConfig.ProfileID |
| 1162 | igmpProfile.UnsolicitedTimeOut = uint32(igmpProfileConfig.UnsolicitedTimeOut) |
| 1163 | igmpProfile.MaxResp = uint32(igmpProfileConfig.MaxResp) |
Tinoj Joseph | cf161be | 2022-07-07 19:47:47 +0530 | [diff] [blame] | 1164 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 1165 | keepAliveInterval := uint32(igmpProfileConfig.KeepAliveInterval) |
Tinoj Joseph | cf161be | 2022-07-07 19:47:47 +0530 | [diff] [blame] | 1166 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 1167 | //KeepAliveInterval should have a min of 10 seconds |
| 1168 | if keepAliveInterval < MinKeepAliveInterval { |
| 1169 | keepAliveInterval = MinKeepAliveInterval |
| 1170 | logger.Infow(ctx, "Auto adjust keepAliveInterval - Value < 10", log.Fields{"Received": igmpProfileConfig.KeepAliveInterval, "Configured": keepAliveInterval}) |
| 1171 | } |
| 1172 | igmpProfile.KeepAliveInterval = keepAliveInterval |
Tinoj Joseph | cf161be | 2022-07-07 19:47:47 +0530 | [diff] [blame] | 1173 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 1174 | igmpProfile.KeepAliveCount = uint32(igmpProfileConfig.KeepAliveCount) |
| 1175 | igmpProfile.LastQueryInterval = uint32(igmpProfileConfig.LastQueryInterval) |
| 1176 | igmpProfile.LastQueryCount = uint32(igmpProfileConfig.LastQueryCount) |
| 1177 | igmpProfile.FastLeave = *igmpProfileConfig.FastLeave |
| 1178 | igmpProfile.PeriodicQuery = *igmpProfileConfig.PeriodicQuery |
| 1179 | igmpProfile.IgmpCos = uint8(igmpProfileConfig.IgmpCos) |
| 1180 | igmpProfile.WithRAUpLink = *igmpProfileConfig.WithRAUpLink |
| 1181 | igmpProfile.WithRADownLink = *igmpProfileConfig.WithRADownLink |
Tinoj Joseph | cf161be | 2022-07-07 19:47:47 +0530 | [diff] [blame] | 1182 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 1183 | if igmpProfileConfig.IgmpVerToServer == "2" || igmpProfileConfig.IgmpVerToServer == "v2" { |
| 1184 | igmpProfile.IgmpVerToServer = "2" |
| 1185 | } else { |
| 1186 | igmpProfile.IgmpVerToServer = "3" |
| 1187 | } |
| 1188 | igmpProfile.IgmpSourceIP = net.ParseIP(igmpProfileConfig.IgmpSourceIP) |
Tinoj Joseph | cf161be | 2022-07-07 19:47:47 +0530 | [diff] [blame] | 1189 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 1190 | return &igmpProfile |
Tinoj Joseph | cf161be | 2022-07-07 19:47:47 +0530 | [diff] [blame] | 1191 | } |
| 1192 | |
| 1193 | // newDefaultIgmpProfile Igmp profiles with default values |
| 1194 | func newDefaultIgmpProfile() *IgmpProfile { |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 1195 | return &IgmpProfile{ |
| 1196 | ProfileID: DefaultIgmpProfID, |
| 1197 | UnsolicitedTimeOut: 60, |
| 1198 | MaxResp: 10, // seconds |
| 1199 | KeepAliveInterval: 60, // seconds |
| 1200 | KeepAliveCount: 3, // TODO - May not be needed |
| 1201 | LastQueryInterval: 0, // TODO - May not be needed |
| 1202 | LastQueryCount: 0, // TODO - May not be needed |
| 1203 | FastLeave: true, |
| 1204 | PeriodicQuery: false, // TODO - May not be needed |
| 1205 | IgmpCos: 7, //p-bit value included in the IGMP packet |
| 1206 | WithRAUpLink: false, // TODO - May not be needed |
| 1207 | WithRADownLink: false, // TODO - May not be needed |
| 1208 | IgmpVerToServer: "3", |
| 1209 | IgmpSourceIP: net.ParseIP("172.27.0.1"), // This will be replaced by configuration |
| 1210 | } |
Tinoj Joseph | cf161be | 2022-07-07 19:47:47 +0530 | [diff] [blame] | 1211 | } |
| 1212 | |
| 1213 | // WriteToDb is utility to write Igmp Config Info to database |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 1214 | func (igmpProfile *IgmpProfile) WriteToDb(cntx context.Context) error { |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 1215 | igmpProfile.Version = database.PresentVersionMap[database.IgmpProfPath] |
| 1216 | b, err := json.Marshal(igmpProfile) |
| 1217 | if err != nil { |
| 1218 | return err |
| 1219 | } |
| 1220 | if err1 := db.PutIgmpProfile(cntx, igmpProfile.ProfileID, string(b)); err1 != nil { |
| 1221 | return err1 |
| 1222 | } |
| 1223 | return nil |
Tinoj Joseph | cf161be | 2022-07-07 19:47:47 +0530 | [diff] [blame] | 1224 | } |