Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +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. |
| 14 | */ |
| 15 | |
| 16 | package application |
| 17 | |
| 18 | import ( |
| 19 | "context" |
| 20 | "encoding/hex" |
| 21 | "encoding/json" |
| 22 | "errors" |
| 23 | "fmt" |
| 24 | "net" |
| 25 | "strconv" |
| 26 | "strings" |
| 27 | "sync" |
| 28 | "time" |
| 29 | |
| 30 | "github.com/google/gopacket" |
| 31 | "github.com/google/gopacket/layers" |
| 32 | |
Akash Soni | a824697 | 2023-01-03 10:37:08 +0530 | [diff] [blame] | 33 | "voltha-go-controller/database" |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 34 | "voltha-go-controller/internal/pkg/controller" |
| 35 | cntlr "voltha-go-controller/internal/pkg/controller" |
Akash Soni | a824697 | 2023-01-03 10:37:08 +0530 | [diff] [blame] | 36 | errorCodes "voltha-go-controller/internal/pkg/errorcodes" |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 37 | "voltha-go-controller/internal/pkg/intf" |
| 38 | "voltha-go-controller/internal/pkg/of" |
| 39 | "voltha-go-controller/internal/pkg/tasks" |
| 40 | "voltha-go-controller/internal/pkg/util" |
Tinoj Joseph | 1d10832 | 2022-07-13 10:07:39 +0530 | [diff] [blame] | 41 | "voltha-go-controller/log" |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 42 | ) |
| 43 | |
| 44 | var logger log.CLogger |
| 45 | var ctx = context.TODO() |
| 46 | |
| 47 | func init() { |
| 48 | // Setup this package so that it's log level can be modified at run time |
| 49 | var err error |
Tinoj Joseph | 1d10832 | 2022-07-13 10:07:39 +0530 | [diff] [blame] | 50 | logger, err = log.AddPackageWithDefaultParam() |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 51 | if err != nil { |
| 52 | panic(err) |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | const ( |
| 57 | // TODO - Need to identify a right place for this |
| 58 | |
| 59 | // PriorityNone constant. |
| 60 | PriorityNone uint8 = 8 |
| 61 | // AnyVlan constant. |
| 62 | AnyVlan uint16 = 0xFFFF |
| 63 | ) |
| 64 | |
| 65 | // List of Mac Learning Type |
| 66 | const ( |
Tinoj Joseph | 1d10832 | 2022-07-13 10:07:39 +0530 | [diff] [blame] | 67 | MacLearningNone MacLearningType = iota |
| 68 | Learn |
| 69 | ReLearn |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 70 | ) |
| 71 | |
| 72 | // MacLearningType represents Mac Learning Type |
| 73 | type MacLearningType int |
| 74 | |
| 75 | var ( |
| 76 | tickCount uint16 |
| 77 | vgcRebooted bool |
| 78 | isUpgradeComplete bool |
| 79 | ) |
| 80 | |
| 81 | var db database.DBIntf |
| 82 | |
| 83 | // PacketHandlers : packet handler for different protocols |
| 84 | var PacketHandlers map[string]CallBack |
| 85 | |
| 86 | // CallBack : registered call back function for different protocol packets |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 87 | type CallBack func(cntx context.Context, device string, port string, pkt gopacket.Packet) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 88 | |
| 89 | const ( |
| 90 | // ARP packet |
| 91 | ARP string = "ARP" |
| 92 | // DHCPv4 packet |
| 93 | DHCPv4 string = "DHCPv4" |
| 94 | // DHCPv6 packet |
| 95 | DHCPv6 string = "DHCPv6" |
| 96 | // IGMP packet |
| 97 | IGMP string = "IGMP" |
| 98 | // PPPOE packet |
| 99 | PPPOE string = "PPPOE" |
| 100 | // US packet side |
| 101 | US string = "US" |
| 102 | // DS packet side |
| 103 | DS string = "DS" |
| 104 | // NNI port name |
| 105 | NNI string = "nni" |
| 106 | ) |
| 107 | |
| 108 | // RegisterPacketHandler : API to register callback function for every protocol |
| 109 | func RegisterPacketHandler(protocol string, callback CallBack) { |
| 110 | if PacketHandlers == nil { |
| 111 | PacketHandlers = make(map[string]CallBack) |
| 112 | } |
| 113 | PacketHandlers[protocol] = callback |
| 114 | } |
| 115 | |
| 116 | // --------------------------------------------------------------------- |
| 117 | // VOLT Ports |
| 118 | // --------------------------------------------------------------------- |
| 119 | // VOLT Ports are ports associated with VOLT devices. Each port is classified into |
| 120 | // Access/NNI. Each port is identified by Name (Identity known to the NB) and |
| 121 | // Id (Identity used on the SB). Both identities are presented when a port is |
| 122 | // discovered in the SB. |
| 123 | |
| 124 | // VoltPortType type for Port Type |
| 125 | type VoltPortType uint8 |
| 126 | |
| 127 | const ( |
| 128 | // VoltPortTypeAccess constant. |
| 129 | VoltPortTypeAccess VoltPortType = 0 |
| 130 | // VoltPortTypeNni constant. |
| 131 | VoltPortTypeNni VoltPortType = 1 |
| 132 | ) |
| 133 | |
| 134 | // PortState type for Port State. |
| 135 | type PortState uint8 |
| 136 | |
| 137 | const ( |
| 138 | // PortStateDown constant. |
| 139 | PortStateDown PortState = 0 |
| 140 | // PortStateUp constant. |
| 141 | PortStateUp PortState = 1 |
| 142 | ) |
| 143 | |
| 144 | // VoltPort structure that is used to store the ports. The name is the |
| 145 | // the main identity used by the application. The SB and NB both present name |
| 146 | // as the identity. The SB is abstracted by VPAgent and the VPAgent transacts |
| 147 | // using name as identity |
| 148 | type VoltPort struct { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 149 | Name string |
| 150 | Device string |
| 151 | PonPort uint32 |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 152 | ActiveChannels uint32 |
| 153 | ID uint32 |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 154 | Type VoltPortType |
| 155 | State PortState |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 156 | ChannelPerSubAlarmRaised bool |
| 157 | } |
| 158 | |
| 159 | // NewVoltPort : Constructor for the port. |
| 160 | func NewVoltPort(device string, name string, id uint32) *VoltPort { |
| 161 | var vp VoltPort |
| 162 | vp.Device = device |
| 163 | vp.Name = name |
| 164 | vp.ID = id |
| 165 | if util.IsNniPort(id) { |
| 166 | vp.Type = VoltPortTypeNni |
| 167 | } else { |
| 168 | vp.PonPort = GetPonPortIDFromUNIPort(id) |
| 169 | } |
| 170 | vp.State = PortStateDown |
| 171 | vp.ChannelPerSubAlarmRaised = false |
| 172 | return &vp |
| 173 | } |
| 174 | |
| 175 | // SetPortID : The ID is used when constructing flows as the flows require ID. |
| 176 | func (vp *VoltPort) SetPortID(id uint32) { |
| 177 | vp.ID = id |
| 178 | if util.IsNniPort(id) { |
| 179 | vp.Type = VoltPortTypeNni |
| 180 | } |
| 181 | } |
| 182 | |
| 183 | // --------------------------------------------------------------------- |
| 184 | // VOLT Device |
| 185 | // --------------------------------------------------------------------- |
| 186 | // |
| 187 | // VoltDevice is an OLT which contains ports of type access and NNI. Each OLT |
| 188 | // can only have one NNI port in the current release. The NNI port always uses |
| 189 | // identity 65536 and all the access ports use identities less than 65535. The |
| 190 | // identification of NNI is done by comparing the port identity with 65535 |
| 191 | |
| 192 | // VoltDevice fields : |
| 193 | // Name: This is the name presented by the device/VOLTHA. This doesn't |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 194 | // have any relation to the physical device |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 195 | // SerialNum: This is the serial number of the device and can be used to |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 196 | // correlate the devices |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 197 | // NniPort: The identity of the NNI port |
| 198 | // Ports: List of all ports added to the device |
| 199 | type VoltDevice struct { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 200 | FlowAddEventMap *util.ConcurrentMap //map[string]*FlowEvent |
| 201 | FlowDelEventMap *util.ConcurrentMap //map[string]*FlowEvent |
| 202 | MigratingServices *util.ConcurrentMap //<vnetID,<RequestID, MigrateServicesRequest>> |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 203 | VpvsBySvlan *util.ConcurrentMap // map[svlan]map[vnet_port]*VoltPortVnet |
| 204 | ConfiguredVlanForDeviceFlows *util.ConcurrentMap //map[string]map[string]bool |
| 205 | IgmpDsFlowAppliedForMvlan map[uint16]bool |
| 206 | State controller.DeviceState |
| 207 | SouthBoundID string |
| 208 | NniPort string |
| 209 | Name string |
| 210 | SerialNum string |
| 211 | Ports sync.Map |
| 212 | VlanPortStatus sync.Map |
| 213 | ActiveChannelsPerPon sync.Map // [PonPortID]*PonPortCfg |
| 214 | PonPortList sync.Map // [PonPortID]map[string]string |
| 215 | ActiveChannelCountLock sync.Mutex // This lock is used to update ActiveIGMPChannels |
Tinoj Joseph | 50d722c | 2022-12-06 22:53:22 +0530 | [diff] [blame] | 216 | NniDhcpTrapVid of.VlanType |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 217 | GlobalDhcpFlowAdded bool |
| 218 | icmpv6GroupAdded bool |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 219 | } |
| 220 | |
| 221 | // NewVoltDevice : Constructor for the device |
| 222 | func NewVoltDevice(name string, slno, southBoundID string) *VoltDevice { |
| 223 | var d VoltDevice |
| 224 | d.Name = name |
| 225 | d.SouthBoundID = southBoundID |
| 226 | d.State = controller.DeviceStateDOWN |
| 227 | d.NniPort = "" |
| 228 | d.SouthBoundID = southBoundID |
| 229 | d.SerialNum = slno |
| 230 | d.icmpv6GroupAdded = false |
| 231 | d.IgmpDsFlowAppliedForMvlan = make(map[uint16]bool) |
| 232 | d.ConfiguredVlanForDeviceFlows = util.NewConcurrentMap() |
| 233 | d.MigratingServices = util.NewConcurrentMap() |
| 234 | d.VpvsBySvlan = util.NewConcurrentMap() |
| 235 | d.FlowAddEventMap = util.NewConcurrentMap() |
| 236 | d.FlowDelEventMap = util.NewConcurrentMap() |
| 237 | d.GlobalDhcpFlowAdded = false |
Tinoj Joseph | 50d722c | 2022-12-06 22:53:22 +0530 | [diff] [blame] | 238 | if config, ok := GetApplication().DevicesConfig.Load(slno); ok { |
| 239 | //Update nni dhcp vid |
Akash Soni | 53da285 | 2023-03-15 00:31:31 +0530 | [diff] [blame] | 240 | deviceConfig := config.(*DeviceConfig) |
Tinoj Joseph | 50d722c | 2022-12-06 22:53:22 +0530 | [diff] [blame] | 241 | d.NniDhcpTrapVid = of.VlanType(deviceConfig.NniDhcpTrapVid) |
| 242 | } |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 243 | return &d |
| 244 | } |
| 245 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 246 | // GetAssociatedVpvsForDevice - return the associated VPVs for given device & svlan |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 247 | func (va *VoltApplication) GetAssociatedVpvsForDevice(device string, svlan of.VlanType) *util.ConcurrentMap { |
| 248 | if d := va.GetDevice(device); d != nil { |
| 249 | return d.GetAssociatedVpvs(svlan) |
| 250 | } |
| 251 | return nil |
| 252 | } |
| 253 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 254 | // AssociateVpvsToDevice - updates the associated VPVs for given device & svlan |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 255 | func (va *VoltApplication) AssociateVpvsToDevice(device string, vpv *VoltPortVnet) { |
| 256 | if d := va.GetDevice(device); d != nil { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 257 | vpvMap := d.GetAssociatedVpvs(vpv.SVlan) |
| 258 | vpvMap.Set(vpv, true) |
| 259 | d.VpvsBySvlan.Set(vpv.SVlan, vpvMap) |
| 260 | logger.Infow(ctx, "VPVMap: SET", log.Fields{"Map": vpvMap.Length()}) |
| 261 | return |
| 262 | } |
| 263 | logger.Errorw(ctx, "Set VPVMap failed: Device Not Found", log.Fields{"Svlan": vpv.SVlan, "Device": device}) |
| 264 | } |
| 265 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 266 | // DisassociateVpvsFromDevice - disassociated VPVs from given device & svlan |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 267 | func (va *VoltApplication) DisassociateVpvsFromDevice(device string, vpv *VoltPortVnet) { |
| 268 | if d := va.GetDevice(device); d != nil { |
| 269 | vpvMap := d.GetAssociatedVpvs(vpv.SVlan) |
| 270 | vpvMap.Remove(vpv) |
| 271 | d.VpvsBySvlan.Set(vpv.SVlan, vpvMap) |
| 272 | logger.Infow(ctx, "VPVMap: Remove", log.Fields{"Map": vpvMap.Length()}) |
| 273 | return |
| 274 | } |
| 275 | logger.Errorw(ctx, "Remove VPVMap failed: Device Not Found", log.Fields{"Svlan": vpv.SVlan, "Device": device}) |
| 276 | } |
| 277 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 278 | // GetAssociatedVpvs - returns the associated VPVs for the given Svlan |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 279 | func (d *VoltDevice) GetAssociatedVpvs(svlan of.VlanType) *util.ConcurrentMap { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 280 | var vpvMap *util.ConcurrentMap |
| 281 | var mapIntf interface{} |
| 282 | var ok bool |
| 283 | |
| 284 | if mapIntf, ok = d.VpvsBySvlan.Get(svlan); ok { |
| 285 | vpvMap = mapIntf.(*util.ConcurrentMap) |
| 286 | } else { |
| 287 | vpvMap = util.NewConcurrentMap() |
| 288 | } |
| 289 | logger.Infow(ctx, "VPVMap: GET", log.Fields{"Map": vpvMap.Length()}) |
| 290 | return vpvMap |
| 291 | } |
| 292 | |
| 293 | // AddPort add port to the device. |
| 294 | func (d *VoltDevice) AddPort(port string, id uint32) *VoltPort { |
| 295 | addPonPortFromUniPort := func(vPort *VoltPort) { |
| 296 | if vPort.Type == VoltPortTypeAccess { |
| 297 | ponPortID := GetPonPortIDFromUNIPort(vPort.ID) |
| 298 | |
| 299 | if ponPortUniList, ok := d.PonPortList.Load(ponPortID); !ok { |
| 300 | uniList := make(map[string]uint32) |
| 301 | uniList[port] = vPort.ID |
| 302 | d.PonPortList.Store(ponPortID, uniList) |
| 303 | } else { |
| 304 | ponPortUniList.(map[string]uint32)[port] = vPort.ID |
| 305 | d.PonPortList.Store(ponPortID, ponPortUniList) |
| 306 | } |
| 307 | } |
| 308 | } |
| 309 | va := GetApplication() |
| 310 | if pIntf, ok := d.Ports.Load(port); ok { |
| 311 | voltPort := pIntf.(*VoltPort) |
| 312 | addPonPortFromUniPort(voltPort) |
| 313 | va.AggActiveChannelsCountPerSub(d.Name, port, voltPort) |
| 314 | d.Ports.Store(port, voltPort) |
| 315 | return voltPort |
| 316 | } |
| 317 | p := NewVoltPort(d.Name, port, id) |
| 318 | va.AggActiveChannelsCountPerSub(d.Name, port, p) |
| 319 | d.Ports.Store(port, p) |
| 320 | if util.IsNniPort(id) { |
| 321 | d.NniPort = port |
| 322 | } |
| 323 | addPonPortFromUniPort(p) |
| 324 | return p |
| 325 | } |
| 326 | |
| 327 | // GetPort to get port information from the device. |
| 328 | func (d *VoltDevice) GetPort(port string) *VoltPort { |
| 329 | if pIntf, ok := d.Ports.Load(port); ok { |
| 330 | return pIntf.(*VoltPort) |
| 331 | } |
| 332 | return nil |
| 333 | } |
| 334 | |
Tinoj Joseph | 4ead4e0 | 2023-01-30 03:12:44 +0530 | [diff] [blame] | 335 | // GetPortByPortID to get port information from the device. |
| 336 | func (d *VoltDevice) GetPortNameFromPortID(portID uint32) string { |
| 337 | portName := "" |
| 338 | d.Ports.Range(func(key, value interface{}) bool { |
| 339 | vp := value.(*VoltPort) |
| 340 | if vp.ID == portID { |
| 341 | portName = vp.Name |
| 342 | } |
| 343 | return true |
| 344 | }) |
| 345 | return portName |
| 346 | } |
| 347 | |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 348 | // DelPort to delete port from the device |
| 349 | func (d *VoltDevice) DelPort(port string) { |
| 350 | if _, ok := d.Ports.Load(port); ok { |
| 351 | d.Ports.Delete(port) |
| 352 | } else { |
| 353 | logger.Warnw(ctx, "Port doesn't exist", log.Fields{"Device": d.Name, "Port": port}) |
| 354 | } |
| 355 | } |
| 356 | |
| 357 | // pushFlowsForUnis to send port-up-indication for uni ports. |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 358 | func (d *VoltDevice) pushFlowsForUnis(cntx context.Context) { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 359 | logger.Info(ctx, "NNI Discovered, Sending Port UP Ind for UNIs") |
| 360 | d.Ports.Range(func(key, value interface{}) bool { |
| 361 | port := key.(string) |
| 362 | vp := value.(*VoltPort) |
| 363 | |
Akash Soni | a824697 | 2023-01-03 10:37:08 +0530 | [diff] [blame] | 364 | logger.Infow(ctx, "NNI Discovered. Sending Port UP Ind for UNI", log.Fields{"Port": port}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 365 | //Ignore if UNI port is not UP |
| 366 | if vp.State != PortStateUp { |
| 367 | return true |
| 368 | } |
| 369 | |
| 370 | //Obtain all VPVs associated with the port |
| 371 | vnets, ok := GetApplication().VnetsByPort.Load(port) |
| 372 | if !ok { |
| 373 | return true |
| 374 | } |
| 375 | |
| 376 | for _, vpv := range vnets.([]*VoltPortVnet) { |
| 377 | vpv.VpvLock.Lock() |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 378 | vpv.PortUpInd(cntx, d, port) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 379 | vpv.VpvLock.Unlock() |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 380 | } |
| 381 | return true |
| 382 | }) |
| 383 | } |
| 384 | |
| 385 | // ---------------------------------------------------------- |
| 386 | // VOLT Application - hosts all other objects |
| 387 | // ---------------------------------------------------------- |
| 388 | // |
| 389 | // The VOLT application is a singleton implementation where |
| 390 | // there is just one instance in the system and is the gateway |
| 391 | // to all other components within the controller |
| 392 | // The declaration of the singleton object |
| 393 | var vapplication *VoltApplication |
| 394 | |
| 395 | // VoltApplication fields : |
| 396 | // ServiceByName - Stores the services by the name as key |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 397 | // A record of NB configuration. |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 398 | // VnetsByPort - Stores the VNETs by the ports configured |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 399 | // from NB. A record of NB configuration. |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 400 | // VnetsByTag - Stores the VNETs by the VLANS configured |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 401 | // from NB. A record of NB configuration. |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 402 | // VnetsByName - Stores the VNETs by the name configured |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 403 | // from NB. A record of NB configuration. |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 404 | // DevicesDisc - Stores the devices discovered from SB. |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 405 | // Should be updated only by events from SB |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 406 | // PortsDisc - Stores the ports discovered from SB. |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 407 | // Should be updated only by events from SB |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 408 | type VoltApplication struct { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 409 | MeterMgr |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 410 | DataMigrationInfo DataMigration |
| 411 | VnetsBySvlan *util.ConcurrentMap |
| 412 | IgmpGroupIds []*IgmpGroup |
| 413 | VoltPortVnetsToDelete map[*VoltPortVnet]bool |
Akash Soni | a824697 | 2023-01-03 10:37:08 +0530 | [diff] [blame] | 414 | IgmpPendingPool map[string]map[*IgmpGroup]bool //[grpkey, map[groupObj]bool] //mvlan_grpName/IP |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 415 | macPortMap map[string]string |
Akash Soni | a824697 | 2023-01-03 10:37:08 +0530 | [diff] [blame] | 416 | VnetsToDelete map[string]bool |
| 417 | ServicesToDelete map[string]bool |
Akash Soni | a824697 | 2023-01-03 10:37:08 +0530 | [diff] [blame] | 418 | PortAlarmProfileCache map[string]map[string]int // [portAlarmID][ThresholdLevelString]ThresholdLevel |
| 419 | vendorID string |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 420 | ServiceByName sync.Map // [serName]*VoltService |
| 421 | VnetsByPort sync.Map // [portName][]*VoltPortVnet |
| 422 | VnetsByTag sync.Map // [svlan-cvlan-uvlan]*VoltVnet |
| 423 | VnetsByName sync.Map // [vnetName]*VoltVnet |
| 424 | DevicesDisc sync.Map |
| 425 | PortsDisc sync.Map |
| 426 | IgmpGroups sync.Map // [grpKey]*IgmpGroup |
| 427 | MvlanProfilesByTag sync.Map |
| 428 | MvlanProfilesByName sync.Map |
| 429 | Icmpv6Receivers sync.Map |
| 430 | DeviceCounters sync.Map //[logicalDeviceId]*DeviceCounters |
| 431 | ServiceCounters sync.Map //[serviceName]*ServiceCounters |
| 432 | NbDevice sync.Map // [OLTSouthBoundID]*NbDevice |
| 433 | OltIgmpInfoBySerial sync.Map |
| 434 | McastConfigMap sync.Map //[OltSerialNo_MvlanProfileID]*McastConfig |
Akash Soni | a824697 | 2023-01-03 10:37:08 +0530 | [diff] [blame] | 435 | DevicesConfig sync.Map //[serialNumber]*DeviceConfig |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 436 | IgmpProfilesByName sync.Map |
| 437 | IgmpTasks tasks.Tasks |
| 438 | IndicationsTasks tasks.Tasks |
| 439 | MulticastAlarmTasks tasks.Tasks |
| 440 | IgmpKPIsTasks tasks.Tasks |
| 441 | pppoeTasks tasks.Tasks |
| 442 | OltFlowServiceConfig OltFlowService |
| 443 | PendingPoolLock sync.RWMutex |
| 444 | // MacAddress-Port MAP to avoid swap of mac across ports. |
| 445 | macPortLock sync.RWMutex |
| 446 | portLock sync.Mutex |
Akash Soni | a824697 | 2023-01-03 10:37:08 +0530 | [diff] [blame] | 447 | } |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 448 | |
Akash Soni | a824697 | 2023-01-03 10:37:08 +0530 | [diff] [blame] | 449 | type DeviceConfig struct { |
| 450 | SerialNumber string `json:"id"` |
| 451 | HardwareIdentifier string `json:"hardwareIdentifier"` |
Akash Soni | 87a1907 | 2023-02-28 00:46:59 +0530 | [diff] [blame] | 452 | IPAddress string `json:"ipAddress"` |
Akash Soni | 53da285 | 2023-03-15 00:31:31 +0530 | [diff] [blame] | 453 | UplinkPort string `json:"uplinkPort"` |
Akash Soni | a824697 | 2023-01-03 10:37:08 +0530 | [diff] [blame] | 454 | NasID string `json:"nasId"` |
| 455 | NniDhcpTrapVid int `json:"nniDhcpTrapVid"` |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 456 | } |
| 457 | |
| 458 | // PonPortCfg contains NB port config and activeIGMPChannels count |
| 459 | type PonPortCfg struct { |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 460 | PortAlarmProfileID string |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 461 | PortID uint32 |
| 462 | MaxActiveChannels uint32 |
| 463 | ActiveIGMPChannels uint32 |
| 464 | EnableMulticastKPI bool |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 465 | } |
| 466 | |
| 467 | // NbDevice OLT Device info |
| 468 | type NbDevice struct { |
| 469 | SouthBoundID string |
| 470 | PonPorts sync.Map // [PortID]*PonPortCfg |
| 471 | } |
| 472 | |
| 473 | // RestoreNbDeviceFromDb restores the NB Device in case of VGC pod restart. |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 474 | func (va *VoltApplication) RestoreNbDeviceFromDb(cntx context.Context, deviceID string) *NbDevice { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 475 | nbDevice := NewNbDevice() |
| 476 | nbDevice.SouthBoundID = deviceID |
| 477 | |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 478 | nbPorts, _ := db.GetAllNbPorts(cntx, deviceID) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 479 | |
| 480 | for key, p := range nbPorts { |
| 481 | b, ok := p.Value.([]byte) |
| 482 | if !ok { |
| 483 | logger.Warn(ctx, "The value type is not []byte") |
| 484 | continue |
| 485 | } |
| 486 | var port PonPortCfg |
| 487 | err := json.Unmarshal(b, &port) |
| 488 | if err != nil { |
| 489 | logger.Warn(ctx, "Unmarshal of PonPortCfg failed") |
| 490 | continue |
| 491 | } |
| 492 | logger.Debugw(ctx, "Port recovered", log.Fields{"port": port}) |
| 493 | ponPortID, _ := strconv.Atoi(key) |
| 494 | nbDevice.PonPorts.Store(uint32(ponPortID), &port) |
| 495 | } |
| 496 | va.NbDevice.Store(deviceID, nbDevice) |
| 497 | return nbDevice |
| 498 | } |
| 499 | |
| 500 | // NewNbDevice Constructor for NbDevice |
| 501 | func NewNbDevice() *NbDevice { |
| 502 | var nbDevice NbDevice |
| 503 | return &nbDevice |
| 504 | } |
| 505 | |
| 506 | // WriteToDb writes nb device port config to kv store |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 507 | func (nbd *NbDevice) WriteToDb(cntx context.Context, portID uint32, ponPort *PonPortCfg) { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 508 | b, err := json.Marshal(ponPort) |
| 509 | if err != nil { |
| 510 | logger.Errorw(ctx, "PonPortConfig-marshal-failed", log.Fields{"err": err}) |
| 511 | return |
| 512 | } |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 513 | db.PutNbDevicePort(cntx, nbd.SouthBoundID, portID, string(b)) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 514 | } |
| 515 | |
| 516 | // AddPortToNbDevice Adds pon port to NB Device and DB |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 517 | func (nbd *NbDevice) AddPortToNbDevice(cntx context.Context, portID, allowedChannels uint32, |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 518 | enableMulticastKPI bool, portAlarmProfileID string) *PonPortCfg { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 519 | ponPort := &PonPortCfg{ |
| 520 | PortID: portID, |
| 521 | MaxActiveChannels: allowedChannels, |
| 522 | EnableMulticastKPI: enableMulticastKPI, |
| 523 | PortAlarmProfileID: portAlarmProfileID, |
| 524 | } |
| 525 | nbd.PonPorts.Store(portID, ponPort) |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 526 | nbd.WriteToDb(cntx, portID, ponPort) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 527 | return ponPort |
| 528 | } |
| 529 | |
Akash Soni | a824697 | 2023-01-03 10:37:08 +0530 | [diff] [blame] | 530 | // RestoreDeviceConfigFromDb to restore vnet from port |
| 531 | func (va *VoltApplication) RestoreDeviceConfigFromDb(cntx context.Context) { |
| 532 | // VNETS must be learnt first |
| 533 | dConfig, _ := db.GetDeviceConfig(cntx) |
| 534 | for _, device := range dConfig { |
| 535 | b, ok := device.Value.([]byte) |
| 536 | if !ok { |
| 537 | logger.Warn(ctx, "The value type is not []byte") |
| 538 | continue |
| 539 | } |
| 540 | devConfig := DeviceConfig{} |
| 541 | err := json.Unmarshal(b, &devConfig) |
| 542 | if err != nil { |
| 543 | logger.Warn(ctx, "Unmarshal of device configuration failed") |
| 544 | continue |
| 545 | } |
| 546 | logger.Debugw(ctx, "Retrieved device config", log.Fields{"Device Config": devConfig}) |
| 547 | if err := va.AddDeviceConfig(cntx, devConfig.SerialNumber, devConfig.HardwareIdentifier, devConfig.NasID, devConfig.IPAddress, devConfig.UplinkPort, devConfig.NniDhcpTrapVid); err != nil { |
| 548 | logger.Warnw(ctx, "Add device config failed", log.Fields{"DeviceConfig": devConfig, "Error": err}) |
| 549 | } |
Akash Soni | a824697 | 2023-01-03 10:37:08 +0530 | [diff] [blame] | 550 | } |
| 551 | } |
| 552 | |
| 553 | // WriteDeviceConfigToDb writes sb device config to kv store |
| 554 | func (dc *DeviceConfig) WriteDeviceConfigToDb(cntx context.Context, serialNum string, deviceConfig *DeviceConfig) error { |
| 555 | b, err := json.Marshal(deviceConfig) |
| 556 | if err != nil { |
| 557 | logger.Errorw(ctx, "deviceConfig-marshal-failed", log.Fields{"err": err}) |
| 558 | return err |
| 559 | } |
| 560 | dberr := db.PutDeviceConfig(cntx, serialNum, string(b)) |
| 561 | if dberr != nil { |
| 562 | logger.Errorw(ctx, "update device config failed", log.Fields{"err": err}) |
| 563 | return dberr |
| 564 | } |
| 565 | return nil |
| 566 | } |
| 567 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 568 | func (va *VoltApplication) AddDeviceConfig(cntx context.Context, serialNum, hardwareIdentifier, nasID, ipAddress, uplinkPort string, nniDhcpTrapID int) error { |
Akash Soni | a824697 | 2023-01-03 10:37:08 +0530 | [diff] [blame] | 569 | var dc *DeviceConfig |
| 570 | |
Akash Soni | 87a1907 | 2023-02-28 00:46:59 +0530 | [diff] [blame] | 571 | deviceConfig := &DeviceConfig{ |
| 572 | SerialNumber: serialNum, |
| 573 | HardwareIdentifier: hardwareIdentifier, |
| 574 | NasID: nasID, |
| 575 | UplinkPort: uplinkPort, |
| 576 | IPAddress: ipAddress, |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 577 | NniDhcpTrapVid: nniDhcpTrapID, |
Akash Soni | a824697 | 2023-01-03 10:37:08 +0530 | [diff] [blame] | 578 | } |
Akash Soni | 87a1907 | 2023-02-28 00:46:59 +0530 | [diff] [blame] | 579 | va.DevicesConfig.Store(serialNum, deviceConfig) |
| 580 | err := dc.WriteDeviceConfigToDb(cntx, serialNum, deviceConfig) |
| 581 | if err != nil { |
| 582 | logger.Errorw(ctx, "DB update for device config failed", log.Fields{"err": err}) |
| 583 | return err |
| 584 | } |
| 585 | |
| 586 | // If device is already discovered update the VoltDevice structure |
| 587 | device, id := va.GetDeviceBySerialNo(serialNum) |
| 588 | if device != nil { |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 589 | device.NniDhcpTrapVid = of.VlanType(nniDhcpTrapID) |
Akash Soni | 87a1907 | 2023-02-28 00:46:59 +0530 | [diff] [blame] | 590 | va.DevicesDisc.Store(id, device) |
| 591 | } |
| 592 | |
Akash Soni | a824697 | 2023-01-03 10:37:08 +0530 | [diff] [blame] | 593 | return nil |
| 594 | } |
| 595 | |
| 596 | // GetDeviceConfig to get a device config. |
| 597 | func (va *VoltApplication) GetDeviceConfig(serNum string) *DeviceConfig { |
| 598 | if d, ok := va.DevicesConfig.Load(serNum); ok { |
| 599 | return d.(*DeviceConfig) |
| 600 | } |
| 601 | return nil |
| 602 | } |
| 603 | |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 604 | // UpdatePortToNbDevice Adds pon port to NB Device and DB |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 605 | func (nbd *NbDevice) UpdatePortToNbDevice(cntx context.Context, portID, allowedChannels uint32, enableMulticastKPI bool, portAlarmProfileID string) *PonPortCfg { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 606 | p, exists := nbd.PonPorts.Load(portID) |
| 607 | if !exists { |
| 608 | logger.Errorw(ctx, "PON port not exists in nb-device", log.Fields{"portID": portID}) |
| 609 | return nil |
| 610 | } |
| 611 | port := p.(*PonPortCfg) |
| 612 | if allowedChannels != 0 { |
| 613 | port.MaxActiveChannels = allowedChannels |
| 614 | port.EnableMulticastKPI = enableMulticastKPI |
| 615 | port.PortAlarmProfileID = portAlarmProfileID |
| 616 | } |
| 617 | |
| 618 | nbd.PonPorts.Store(portID, port) |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 619 | nbd.WriteToDb(cntx, portID, port) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 620 | return port |
| 621 | } |
| 622 | |
| 623 | // DeletePortFromNbDevice Deletes pon port from NB Device and DB |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 624 | func (nbd *NbDevice) DeletePortFromNbDevice(cntx context.Context, portID uint32) { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 625 | if _, ok := nbd.PonPorts.Load(portID); ok { |
| 626 | nbd.PonPorts.Delete(portID) |
| 627 | } |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 628 | db.DelNbDevicePort(cntx, nbd.SouthBoundID, portID) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 629 | } |
| 630 | |
| 631 | // GetApplication : Interface to access the singleton object |
| 632 | func GetApplication() *VoltApplication { |
| 633 | if vapplication == nil { |
| 634 | vapplication = newVoltApplication() |
| 635 | } |
| 636 | return vapplication |
| 637 | } |
| 638 | |
| 639 | // newVoltApplication : Constructor for the singleton object. Hence this is not |
| 640 | // an exported function |
| 641 | func newVoltApplication() *VoltApplication { |
| 642 | var va VoltApplication |
| 643 | va.IgmpTasks.Initialize(context.TODO()) |
| 644 | va.MulticastAlarmTasks.Initialize(context.TODO()) |
| 645 | va.IgmpKPIsTasks.Initialize(context.TODO()) |
| 646 | va.pppoeTasks.Initialize(context.TODO()) |
| 647 | va.storeIgmpProfileMap(DefaultIgmpProfID, newDefaultIgmpProfile()) |
| 648 | va.MeterMgr.Init() |
| 649 | va.AddIgmpGroups(5000) |
| 650 | va.macPortMap = make(map[string]string) |
| 651 | va.IgmpPendingPool = make(map[string]map[*IgmpGroup]bool) |
| 652 | va.VnetsBySvlan = util.NewConcurrentMap() |
| 653 | va.VnetsToDelete = make(map[string]bool) |
| 654 | va.ServicesToDelete = make(map[string]bool) |
| 655 | va.VoltPortVnetsToDelete = make(map[*VoltPortVnet]bool) |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 656 | go va.Start(context.Background(), TimerCfg{tick: 100 * time.Millisecond}, tickTimer) |
| 657 | go va.Start(context.Background(), TimerCfg{tick: time.Duration(GroupExpiryTime) * time.Minute}, pendingPoolTimer) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 658 | InitEventFuncMapper() |
| 659 | db = database.GetDatabase() |
| 660 | return &va |
| 661 | } |
| 662 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 663 | // GetFlowEventRegister - returs the register based on flow mod type |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 664 | func (d *VoltDevice) GetFlowEventRegister(flowModType of.Command) (*util.ConcurrentMap, error) { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 665 | switch flowModType { |
| 666 | case of.CommandDel: |
| 667 | return d.FlowDelEventMap, nil |
| 668 | case of.CommandAdd: |
| 669 | return d.FlowAddEventMap, nil |
| 670 | default: |
| 671 | logger.Error(ctx, "Unknown Flow Mod received") |
| 672 | } |
| 673 | return util.NewConcurrentMap(), errors.New("Unknown Flow Mod") |
| 674 | } |
| 675 | |
| 676 | // RegisterFlowAddEvent to register a flow event. |
| 677 | func (d *VoltDevice) RegisterFlowAddEvent(cookie string, event *FlowEvent) { |
| 678 | logger.Debugw(ctx, "Registered Flow Add Event", log.Fields{"Cookie": cookie, "Event": event}) |
| 679 | d.FlowAddEventMap.MapLock.Lock() |
| 680 | defer d.FlowAddEventMap.MapLock.Unlock() |
| 681 | d.FlowAddEventMap.Set(cookie, event) |
| 682 | } |
| 683 | |
| 684 | // RegisterFlowDelEvent to register a flow event. |
| 685 | func (d *VoltDevice) RegisterFlowDelEvent(cookie string, event *FlowEvent) { |
| 686 | logger.Debugw(ctx, "Registered Flow Del Event", log.Fields{"Cookie": cookie, "Event": event}) |
| 687 | d.FlowDelEventMap.MapLock.Lock() |
| 688 | defer d.FlowDelEventMap.MapLock.Unlock() |
| 689 | d.FlowDelEventMap.Set(cookie, event) |
| 690 | } |
| 691 | |
| 692 | // UnRegisterFlowEvent to unregister a flow event. |
| 693 | func (d *VoltDevice) UnRegisterFlowEvent(cookie string, flowModType of.Command) { |
| 694 | logger.Debugw(ctx, "UnRegistered Flow Add Event", log.Fields{"Cookie": cookie, "Type": flowModType}) |
| 695 | flowEventMap, err := d.GetFlowEventRegister(flowModType) |
| 696 | if err != nil { |
| 697 | logger.Debugw(ctx, "Flow event map does not exists", log.Fields{"flowMod": flowModType, "Error": err}) |
| 698 | return |
| 699 | } |
| 700 | flowEventMap.MapLock.Lock() |
| 701 | defer flowEventMap.MapLock.Unlock() |
| 702 | flowEventMap.Remove(cookie) |
| 703 | } |
| 704 | |
| 705 | // AddIgmpGroups to add Igmp groups. |
| 706 | func (va *VoltApplication) AddIgmpGroups(numOfGroups uint32) { |
| 707 | //TODO: Temp change to resolve group id issue in pOLT |
| 708 | //for i := 1; uint32(i) <= numOfGroups; i++ { |
| 709 | for i := 2; uint32(i) <= (numOfGroups + 1); i++ { |
| 710 | ig := IgmpGroup{} |
| 711 | ig.GroupID = uint32(i) |
| 712 | va.IgmpGroupIds = append(va.IgmpGroupIds, &ig) |
| 713 | } |
| 714 | } |
| 715 | |
| 716 | // GetAvailIgmpGroupID to get id of available igmp group. |
| 717 | func (va *VoltApplication) GetAvailIgmpGroupID() *IgmpGroup { |
| 718 | var ig *IgmpGroup |
| 719 | if len(va.IgmpGroupIds) > 0 { |
| 720 | ig, va.IgmpGroupIds = va.IgmpGroupIds[0], va.IgmpGroupIds[1:] |
| 721 | return ig |
| 722 | } |
| 723 | return nil |
| 724 | } |
| 725 | |
| 726 | // GetIgmpGroupID to get id of igmp group. |
| 727 | func (va *VoltApplication) GetIgmpGroupID(gid uint32) (*IgmpGroup, error) { |
| 728 | for id, ig := range va.IgmpGroupIds { |
| 729 | if ig.GroupID == gid { |
| 730 | va.IgmpGroupIds = append(va.IgmpGroupIds[0:id], va.IgmpGroupIds[id+1:]...) |
| 731 | return ig, nil |
| 732 | } |
| 733 | } |
| 734 | return nil, errors.New("Group Id Missing") |
| 735 | } |
| 736 | |
| 737 | // PutIgmpGroupID to add id of igmp group. |
| 738 | func (va *VoltApplication) PutIgmpGroupID(ig *IgmpGroup) { |
| 739 | va.IgmpGroupIds = append([]*IgmpGroup{ig}, va.IgmpGroupIds[0:]...) |
| 740 | } |
| 741 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 742 | // RestoreUpgradeStatus - gets upgrade/migration status from DB and updates local flags |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 743 | func (va *VoltApplication) RestoreUpgradeStatus(cntx context.Context) { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 744 | Migrate := new(DataMigration) |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 745 | if err := GetMigrationInfo(cntx, Migrate); err == nil { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 746 | if Migrate.Status == MigrationInProgress { |
| 747 | isUpgradeComplete = false |
| 748 | return |
| 749 | } |
| 750 | } |
| 751 | isUpgradeComplete = true |
| 752 | |
| 753 | logger.Infow(ctx, "Upgrade Status Restored", log.Fields{"Upgrade Completed": isUpgradeComplete}) |
| 754 | } |
| 755 | |
| 756 | // ReadAllFromDb : If we are restarted, learn from the database the current execution |
| 757 | // stage |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 758 | func (va *VoltApplication) ReadAllFromDb(cntx context.Context) { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 759 | logger.Info(ctx, "Reading the meters from DB") |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 760 | va.RestoreMetersFromDb(cntx) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 761 | logger.Info(ctx, "Reading the VNETs from DB") |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 762 | va.RestoreVnetsFromDb(cntx) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 763 | logger.Info(ctx, "Reading the VPVs from DB") |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 764 | va.RestoreVpvsFromDb(cntx) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 765 | logger.Info(ctx, "Reading the Services from DB") |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 766 | va.RestoreSvcsFromDb(cntx) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 767 | logger.Info(ctx, "Reading the MVLANs from DB") |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 768 | va.RestoreMvlansFromDb(cntx) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 769 | logger.Info(ctx, "Reading the IGMP profiles from DB") |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 770 | va.RestoreIGMPProfilesFromDb(cntx) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 771 | logger.Info(ctx, "Reading the Mcast configs from DB") |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 772 | va.RestoreMcastConfigsFromDb(cntx) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 773 | logger.Info(ctx, "Reading the IGMP groups for DB") |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 774 | va.RestoreIgmpGroupsFromDb(cntx) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 775 | logger.Info(ctx, "Reading Upgrade status from DB") |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 776 | va.RestoreUpgradeStatus(cntx) |
Tinoj Joseph | 4ead4e0 | 2023-01-30 03:12:44 +0530 | [diff] [blame] | 777 | logger.Info(ctx, "Reading OltFlowService from DB") |
| 778 | va.RestoreOltFlowService(cntx) |
Akash Soni | a824697 | 2023-01-03 10:37:08 +0530 | [diff] [blame] | 779 | logger.Info(ctx, "Reading device config from DB") |
| 780 | va.RestoreDeviceConfigFromDb(cntx) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 781 | logger.Info(ctx, "Reconciled from DB") |
| 782 | } |
| 783 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 784 | // InitStaticConfig to initialize static config. |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 785 | func (va *VoltApplication) InitStaticConfig() { |
| 786 | va.InitIgmpSrcMac() |
| 787 | } |
| 788 | |
| 789 | // SetVendorID to set vendor id |
| 790 | func (va *VoltApplication) SetVendorID(vendorID string) { |
| 791 | va.vendorID = vendorID |
| 792 | } |
| 793 | |
| 794 | // GetVendorID to get vendor id |
| 795 | func (va *VoltApplication) GetVendorID() string { |
| 796 | return va.vendorID |
| 797 | } |
| 798 | |
| 799 | // SetRebootFlag to set reboot flag |
| 800 | func (va *VoltApplication) SetRebootFlag(flag bool) { |
| 801 | vgcRebooted = flag |
| 802 | } |
| 803 | |
| 804 | // GetUpgradeFlag to get reboot status |
| 805 | func (va *VoltApplication) GetUpgradeFlag() bool { |
| 806 | return isUpgradeComplete |
| 807 | } |
| 808 | |
| 809 | // SetUpgradeFlag to set reboot status |
| 810 | func (va *VoltApplication) SetUpgradeFlag(flag bool) { |
| 811 | isUpgradeComplete = flag |
| 812 | } |
| 813 | |
| 814 | // ------------------------------------------------------------ |
| 815 | // Device related functions |
| 816 | |
| 817 | // AddDevice : Add a device and typically the device stores the NNI port on the device |
| 818 | // The NNI port is used when the packets are emitted towards the network. |
| 819 | // The outport is selected as the NNI port of the device. Today, we support |
| 820 | // a single NNI port per OLT. This is true whether the network uses any |
| 821 | // protection mechanism (LAG, ERPS, etc.). The aggregate of the such protection |
| 822 | // is represented by a single NNI port |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 823 | func (va *VoltApplication) AddDevice(cntx context.Context, device string, slno, southBoundID string) { |
Akash Soni | 53da285 | 2023-03-15 00:31:31 +0530 | [diff] [blame] | 824 | logger.Warnw(ctx, "Received Device Ind: Add", log.Fields{"Device": device, "SrNo": slno, "southBoundID": southBoundID}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 825 | if _, ok := va.DevicesDisc.Load(device); ok { |
| 826 | logger.Warnw(ctx, "Device Exists", log.Fields{"Device": device}) |
| 827 | } |
| 828 | d := NewVoltDevice(device, slno, southBoundID) |
| 829 | |
| 830 | addPort := func(key, value interface{}) bool { |
| 831 | portID := key.(uint32) |
| 832 | port := value.(*PonPortCfg) |
| 833 | va.AggActiveChannelsCountForPonPort(device, portID, port) |
| 834 | d.ActiveChannelsPerPon.Store(portID, port) |
| 835 | return true |
| 836 | } |
| 837 | if nbDevice, exists := va.NbDevice.Load(southBoundID); exists { |
| 838 | // Pon Ports added before OLT activate. |
| 839 | nbDevice.(*NbDevice).PonPorts.Range(addPort) |
| 840 | } else { |
| 841 | // Check if NbPort exists in DB. VGC restart case. |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 842 | nbd := va.RestoreNbDeviceFromDb(cntx, southBoundID) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 843 | nbd.PonPorts.Range(addPort) |
| 844 | } |
| 845 | va.DevicesDisc.Store(device, d) |
| 846 | } |
| 847 | |
| 848 | // GetDevice to get a device. |
| 849 | func (va *VoltApplication) GetDevice(device string) *VoltDevice { |
| 850 | if d, ok := va.DevicesDisc.Load(device); ok { |
| 851 | return d.(*VoltDevice) |
| 852 | } |
| 853 | return nil |
| 854 | } |
| 855 | |
| 856 | // DelDevice to delete a device. |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 857 | func (va *VoltApplication) DelDevice(cntx context.Context, device string) { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 858 | logger.Warnw(ctx, "Received Device Ind: Delete", log.Fields{"Device": device}) |
| 859 | if vdIntf, ok := va.DevicesDisc.Load(device); ok { |
| 860 | vd := vdIntf.(*VoltDevice) |
| 861 | va.DevicesDisc.Delete(device) |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 862 | _ = db.DelAllRoutesForDevice(cntx, device) |
| 863 | va.HandleFlowClearFlag(cntx, device, vd.SerialNum, vd.SouthBoundID) |
| 864 | _ = db.DelAllGroup(cntx, device) |
| 865 | _ = db.DelAllMeter(cntx, device) |
| 866 | _ = db.DelAllPorts(cntx, device) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 867 | logger.Debugw(ctx, "Device deleted", log.Fields{"Device": device}) |
| 868 | } else { |
| 869 | logger.Warnw(ctx, "Device Doesn't Exist", log.Fields{"Device": device}) |
| 870 | } |
| 871 | } |
| 872 | |
| 873 | // GetDeviceBySerialNo to get a device by serial number. |
| 874 | // TODO - Transform this into a MAP instead |
Tinoj Joseph | 50d722c | 2022-12-06 22:53:22 +0530 | [diff] [blame] | 875 | func (va *VoltApplication) GetDeviceBySerialNo(slno string) (*VoltDevice, string) { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 876 | var device *VoltDevice |
Tinoj Joseph | 50d722c | 2022-12-06 22:53:22 +0530 | [diff] [blame] | 877 | var deviceID string |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 878 | getserial := func(key interface{}, value interface{}) bool { |
| 879 | device = value.(*VoltDevice) |
Tinoj Joseph | 50d722c | 2022-12-06 22:53:22 +0530 | [diff] [blame] | 880 | deviceID = key.(string) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 881 | return device.SerialNum != slno |
| 882 | } |
| 883 | va.DevicesDisc.Range(getserial) |
Tinoj Joseph | 50d722c | 2022-12-06 22:53:22 +0530 | [diff] [blame] | 884 | return device, deviceID |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 885 | } |
| 886 | |
| 887 | // PortAddInd : This is a PORT add indication coming from the VPAgent, which is essentially |
| 888 | // a request coming from VOLTHA. The device and identity of the port is provided |
| 889 | // in this request. Add them to the application for further use |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 890 | func (va *VoltApplication) PortAddInd(cntx context.Context, device string, id uint32, portName string) { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 891 | logger.Infow(ctx, "Received Port Ind: Add", log.Fields{"Device": device, "Port": portName}) |
| 892 | va.portLock.Lock() |
| 893 | if d := va.GetDevice(device); d != nil { |
| 894 | p := d.AddPort(portName, id) |
| 895 | va.PortsDisc.Store(portName, p) |
| 896 | va.portLock.Unlock() |
| 897 | nni, _ := va.GetNniPort(device) |
| 898 | if nni == portName { |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 899 | d.pushFlowsForUnis(cntx) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 900 | } |
| 901 | } else { |
| 902 | va.portLock.Unlock() |
| 903 | logger.Warnw(ctx, "Device Not Found - Dropping Port Ind: Add", log.Fields{"Device": device, "Port": portName}) |
| 904 | } |
| 905 | } |
| 906 | |
| 907 | // PortDelInd : Only the NNI ports are recorded in the device for now. When port delete |
| 908 | // arrives, only the NNI ports need adjustments. |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 909 | func (va *VoltApplication) PortDelInd(cntx context.Context, device string, port string) { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 910 | logger.Infow(ctx, "Received Port Ind: Delete", log.Fields{"Device": device, "Port": port}) |
| 911 | if d := va.GetDevice(device); d != nil { |
| 912 | p := d.GetPort(port) |
| 913 | if p != nil && p.State == PortStateUp { |
| 914 | logger.Infow(ctx, "Port state is UP. Trigerring Port Down Ind before deleting", log.Fields{"Port": p}) |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 915 | va.PortDownInd(cntx, device, port) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 916 | } |
Tinoj Joseph | 4ead4e0 | 2023-01-30 03:12:44 +0530 | [diff] [blame] | 917 | // if RemoveFlowsOnDisable is flase, then flows will be existing till port delete. Remove the flows now |
| 918 | if !va.OltFlowServiceConfig.RemoveFlowsOnDisable { |
Akash Soni | a824697 | 2023-01-03 10:37:08 +0530 | [diff] [blame] | 919 | vpvs, ok := va.VnetsByPort.Load(port) |
| 920 | if !ok || nil == vpvs || len(vpvs.([]*VoltPortVnet)) == 0 { |
Tinoj Joseph | 4ead4e0 | 2023-01-30 03:12:44 +0530 | [diff] [blame] | 921 | logger.Infow(ctx, "No VNETs on port", log.Fields{"Device": device, "Port": port}) |
| 922 | } else { |
| 923 | for _, vpv := range vpvs.([]*VoltPortVnet) { |
| 924 | vpv.VpvLock.Lock() |
| 925 | vpv.PortDownInd(cntx, device, port, true) |
| 926 | vpv.VpvLock.Unlock() |
| 927 | } |
| 928 | } |
| 929 | } |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 930 | va.portLock.Lock() |
| 931 | defer va.portLock.Unlock() |
| 932 | d.DelPort(port) |
| 933 | if _, ok := va.PortsDisc.Load(port); ok { |
| 934 | va.PortsDisc.Delete(port) |
| 935 | } |
| 936 | } else { |
| 937 | logger.Warnw(ctx, "Device Not Found - Dropping Port Ind: Delete", log.Fields{"Device": device, "Port": port}) |
| 938 | } |
| 939 | } |
| 940 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 941 | // PortUpdateInd Updates port Id incase of ONU movement |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 942 | func (va *VoltApplication) PortUpdateInd(device string, portName string, id uint32) { |
| 943 | logger.Infow(ctx, "Received Port Ind: Update", log.Fields{"Device": device, "Port": portName}) |
| 944 | va.portLock.Lock() |
| 945 | defer va.portLock.Unlock() |
| 946 | if d := va.GetDevice(device); d != nil { |
| 947 | vp := d.GetPort(portName) |
| 948 | vp.ID = id |
| 949 | } else { |
| 950 | logger.Warnw(ctx, "Device Not Found", log.Fields{"Device": device, "Port": portName}) |
| 951 | } |
| 952 | } |
| 953 | |
| 954 | // AddNbPonPort Add pon port to nbDevice |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 955 | func (va *VoltApplication) AddNbPonPort(cntx context.Context, oltSbID string, portID, maxAllowedChannels uint32, |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 956 | enableMulticastKPI bool, portAlarmProfileID string) error { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 957 | var nbd *NbDevice |
| 958 | nbDevice, ok := va.NbDevice.Load(oltSbID) |
| 959 | |
| 960 | if !ok { |
| 961 | nbd = NewNbDevice() |
| 962 | nbd.SouthBoundID = oltSbID |
| 963 | } else { |
| 964 | nbd = nbDevice.(*NbDevice) |
| 965 | } |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 966 | port := nbd.AddPortToNbDevice(cntx, portID, maxAllowedChannels, enableMulticastKPI, portAlarmProfileID) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 967 | |
| 968 | // Add this port to voltDevice |
| 969 | addPort := func(key, value interface{}) bool { |
| 970 | voltDevice := value.(*VoltDevice) |
| 971 | if oltSbID == voltDevice.SouthBoundID { |
| 972 | if _, exists := voltDevice.ActiveChannelsPerPon.Load(portID); !exists { |
| 973 | voltDevice.ActiveChannelsPerPon.Store(portID, port) |
| 974 | } |
| 975 | return false |
| 976 | } |
| 977 | return true |
| 978 | } |
| 979 | va.DevicesDisc.Range(addPort) |
| 980 | va.NbDevice.Store(oltSbID, nbd) |
| 981 | |
| 982 | return nil |
| 983 | } |
| 984 | |
| 985 | // UpdateNbPonPort update pon port to nbDevice |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 986 | func (va *VoltApplication) UpdateNbPonPort(cntx context.Context, oltSbID string, portID, maxAllowedChannels uint32, enableMulticastKPI bool, portAlarmProfileID string) error { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 987 | var nbd *NbDevice |
| 988 | nbDevice, ok := va.NbDevice.Load(oltSbID) |
| 989 | |
| 990 | if !ok { |
| 991 | logger.Errorw(ctx, "Device-doesn't-exists", log.Fields{"deviceID": oltSbID}) |
| 992 | return fmt.Errorf("Device-doesn't-exists-%v", oltSbID) |
| 993 | } |
| 994 | nbd = nbDevice.(*NbDevice) |
| 995 | |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 996 | port := nbd.UpdatePortToNbDevice(cntx, portID, maxAllowedChannels, enableMulticastKPI, portAlarmProfileID) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 997 | if port == nil { |
| 998 | return fmt.Errorf("Port-doesn't-exists-%v", portID) |
| 999 | } |
| 1000 | va.NbDevice.Store(oltSbID, nbd) |
| 1001 | |
| 1002 | // Add this port to voltDevice |
| 1003 | updPort := func(key, value interface{}) bool { |
| 1004 | voltDevice := value.(*VoltDevice) |
| 1005 | if oltSbID == voltDevice.SouthBoundID { |
| 1006 | voltDevice.ActiveChannelCountLock.Lock() |
| 1007 | if p, exists := voltDevice.ActiveChannelsPerPon.Load(portID); exists { |
| 1008 | oldPort := p.(*PonPortCfg) |
| 1009 | if port.MaxActiveChannels != 0 { |
| 1010 | oldPort.MaxActiveChannels = port.MaxActiveChannels |
| 1011 | oldPort.EnableMulticastKPI = port.EnableMulticastKPI |
| 1012 | voltDevice.ActiveChannelsPerPon.Store(portID, oldPort) |
| 1013 | } |
| 1014 | } |
| 1015 | voltDevice.ActiveChannelCountLock.Unlock() |
| 1016 | return false |
| 1017 | } |
| 1018 | return true |
| 1019 | } |
| 1020 | va.DevicesDisc.Range(updPort) |
| 1021 | |
| 1022 | return nil |
| 1023 | } |
| 1024 | |
| 1025 | // DeleteNbPonPort Delete pon port to nbDevice |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 1026 | func (va *VoltApplication) DeleteNbPonPort(cntx context.Context, oltSbID string, portID uint32) error { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1027 | nbDevice, ok := va.NbDevice.Load(oltSbID) |
| 1028 | if ok { |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 1029 | nbDevice.(*NbDevice).DeletePortFromNbDevice(cntx, portID) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1030 | va.NbDevice.Store(oltSbID, nbDevice.(*NbDevice)) |
| 1031 | } else { |
| 1032 | logger.Warnw(ctx, "Delete pon received for unknown device", log.Fields{"oltSbID": oltSbID}) |
| 1033 | return nil |
| 1034 | } |
| 1035 | // Delete this port from voltDevice |
| 1036 | delPort := func(key, value interface{}) bool { |
| 1037 | voltDevice := value.(*VoltDevice) |
| 1038 | if oltSbID == voltDevice.SouthBoundID { |
| 1039 | if _, exists := voltDevice.ActiveChannelsPerPon.Load(portID); exists { |
| 1040 | voltDevice.ActiveChannelsPerPon.Delete(portID) |
| 1041 | } |
| 1042 | return false |
| 1043 | } |
| 1044 | return true |
| 1045 | } |
| 1046 | va.DevicesDisc.Range(delPort) |
| 1047 | return nil |
| 1048 | } |
| 1049 | |
| 1050 | // GetNniPort : Get the NNI port for a device. Called from different other applications |
| 1051 | // as a port to match or destination for a packet out. The VOLT application |
| 1052 | // is written with the assumption that there is a single NNI port. The OLT |
| 1053 | // device is responsible for translating the combination of VLAN and the |
| 1054 | // NNI port ID to identify possibly a single physical port or a logical |
| 1055 | // port which is a result of protection methods applied. |
| 1056 | func (va *VoltApplication) GetNniPort(device string) (string, error) { |
| 1057 | va.portLock.Lock() |
| 1058 | defer va.portLock.Unlock() |
| 1059 | d, ok := va.DevicesDisc.Load(device) |
| 1060 | if !ok { |
| 1061 | return "", errors.New("Device Doesn't Exist") |
| 1062 | } |
| 1063 | return d.(*VoltDevice).NniPort, nil |
| 1064 | } |
| 1065 | |
| 1066 | // NniDownInd process for Nni down indication. |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 1067 | func (va *VoltApplication) NniDownInd(cntx context.Context, deviceID string, devSrNo string) { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1068 | logger.Debugw(ctx, "NNI Down Ind", log.Fields{"device": devSrNo}) |
| 1069 | |
| 1070 | handleIgmpDsFlows := func(key interface{}, value interface{}) bool { |
| 1071 | mvProfile := value.(*MvlanProfile) |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 1072 | mvProfile.removeIgmpMcastFlows(cntx, devSrNo) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1073 | return true |
| 1074 | } |
| 1075 | va.MvlanProfilesByName.Range(handleIgmpDsFlows) |
| 1076 | |
| 1077 | //Clear Static Group |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 1078 | va.ReceiverDownInd(cntx, deviceID, StaticPort) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1079 | } |
| 1080 | |
| 1081 | // DeviceUpInd changes device state to up. |
| 1082 | func (va *VoltApplication) DeviceUpInd(device string) { |
| 1083 | logger.Warnw(ctx, "Received Device Ind: UP", log.Fields{"Device": device}) |
| 1084 | if d := va.GetDevice(device); d != nil { |
| 1085 | d.State = controller.DeviceStateUP |
| 1086 | } else { |
| 1087 | logger.Errorw(ctx, "Ignoring Device indication: UP. Device Missing", log.Fields{"Device": device}) |
| 1088 | } |
| 1089 | } |
| 1090 | |
| 1091 | // DeviceDownInd changes device state to down. |
| 1092 | func (va *VoltApplication) DeviceDownInd(device string) { |
| 1093 | logger.Warnw(ctx, "Received Device Ind: DOWN", log.Fields{"Device": device}) |
| 1094 | if d := va.GetDevice(device); d != nil { |
| 1095 | d.State = controller.DeviceStateDOWN |
| 1096 | } else { |
| 1097 | logger.Errorw(ctx, "Ignoring Device indication: DOWN. Device Missing", log.Fields{"Device": device}) |
| 1098 | } |
| 1099 | } |
| 1100 | |
| 1101 | // DeviceRebootInd process for handling flow clear flag for device reboot |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 1102 | func (va *VoltApplication) DeviceRebootInd(cntx context.Context, device string, serialNum string, southBoundID string) { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1103 | logger.Warnw(ctx, "Received Device Ind: Reboot", log.Fields{"Device": device, "SerialNumber": serialNum}) |
| 1104 | |
| 1105 | if d := va.GetDevice(device); d != nil { |
| 1106 | if d.State == controller.DeviceStateREBOOTED { |
| 1107 | logger.Warnw(ctx, "Ignoring Device Ind: Reboot, Device already in Reboot state", log.Fields{"Device": device, "SerialNumber": serialNum, "State": d.State}) |
| 1108 | return |
| 1109 | } |
| 1110 | d.State = controller.DeviceStateREBOOTED |
| 1111 | } |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 1112 | va.HandleFlowClearFlag(cntx, device, serialNum, southBoundID) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1113 | } |
| 1114 | |
| 1115 | // DeviceDisableInd handles device deactivation process |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 1116 | func (va *VoltApplication) DeviceDisableInd(cntx context.Context, device string) { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1117 | logger.Warnw(ctx, "Received Device Ind: Disable", log.Fields{"Device": device}) |
| 1118 | |
| 1119 | d := va.GetDevice(device) |
| 1120 | if d == nil { |
| 1121 | logger.Errorw(ctx, "Ignoring Device indication: DISABLED. Device Missing", log.Fields{"Device": device}) |
| 1122 | return |
| 1123 | } |
| 1124 | |
| 1125 | d.State = controller.DeviceStateDISABLED |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 1126 | va.HandleFlowClearFlag(cntx, device, d.SerialNum, d.SouthBoundID) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1127 | } |
| 1128 | |
| 1129 | // ProcessIgmpDSFlowForMvlan for processing Igmp DS flow for device |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 1130 | func (va *VoltApplication) ProcessIgmpDSFlowForMvlan(cntx context.Context, d *VoltDevice, mvp *MvlanProfile, addFlow bool) { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1131 | logger.Debugw(ctx, "Process IGMP DS Flows for MVlan", log.Fields{"device": d.Name, "Mvlan": mvp.Mvlan, "addFlow": addFlow}) |
| 1132 | portState := false |
| 1133 | p := d.GetPort(d.NniPort) |
| 1134 | if p != nil && p.State == PortStateUp { |
| 1135 | portState = true |
| 1136 | } |
| 1137 | |
| 1138 | if addFlow { |
| 1139 | if portState { |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 1140 | mvp.pushIgmpMcastFlows(cntx, d.SerialNum) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1141 | } |
| 1142 | } else { |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 1143 | mvp.removeIgmpMcastFlows(cntx, d.SerialNum) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1144 | } |
| 1145 | } |
| 1146 | |
| 1147 | // ProcessIgmpDSFlowForDevice for processing Igmp DS flow for device |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 1148 | func (va *VoltApplication) ProcessIgmpDSFlowForDevice(cntx context.Context, d *VoltDevice, addFlow bool) { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1149 | logger.Debugw(ctx, "Process IGMP DS Flows for device", log.Fields{"device": d.Name, "addFlow": addFlow}) |
| 1150 | |
| 1151 | handleIgmpDsFlows := func(key interface{}, value interface{}) bool { |
| 1152 | mvProfile := value.(*MvlanProfile) |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 1153 | va.ProcessIgmpDSFlowForMvlan(cntx, d, mvProfile, addFlow) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1154 | return true |
| 1155 | } |
| 1156 | va.MvlanProfilesByName.Range(handleIgmpDsFlows) |
| 1157 | } |
| 1158 | |
| 1159 | // GetDeviceFromPort : This is suitable only for access ports as their naming convention |
| 1160 | // makes them unique across all the OLTs. This must be called with |
| 1161 | // port name that is an access port. Currently called from VNETs, attached |
| 1162 | // only to access ports, and the services which are also attached only |
| 1163 | // to access ports |
| 1164 | func (va *VoltApplication) GetDeviceFromPort(port string) (*VoltDevice, error) { |
| 1165 | va.portLock.Lock() |
| 1166 | defer va.portLock.Unlock() |
| 1167 | var err error |
| 1168 | err = nil |
| 1169 | p, ok := va.PortsDisc.Load(port) |
| 1170 | if !ok { |
| 1171 | return nil, errorCodes.ErrPortNotFound |
| 1172 | } |
| 1173 | d := va.GetDevice(p.(*VoltPort).Device) |
| 1174 | if d == nil { |
| 1175 | err = errorCodes.ErrDeviceNotFound |
| 1176 | } |
| 1177 | return d, err |
| 1178 | } |
| 1179 | |
| 1180 | // GetPortID : This too applies only to access ports. The ports can be indexed |
| 1181 | // purely by their names without the device forming part of the key |
| 1182 | func (va *VoltApplication) GetPortID(port string) (uint32, error) { |
| 1183 | va.portLock.Lock() |
| 1184 | defer va.portLock.Unlock() |
| 1185 | p, ok := va.PortsDisc.Load(port) |
| 1186 | if !ok { |
| 1187 | return 0, errorCodes.ErrPortNotFound |
| 1188 | } |
| 1189 | return p.(*VoltPort).ID, nil |
| 1190 | } |
| 1191 | |
| 1192 | // GetPortName : This too applies only to access ports. The ports can be indexed |
| 1193 | // purely by their names without the device forming part of the key |
| 1194 | func (va *VoltApplication) GetPortName(port uint32) (string, error) { |
| 1195 | va.portLock.Lock() |
| 1196 | defer va.portLock.Unlock() |
| 1197 | var portName string |
| 1198 | va.PortsDisc.Range(func(key interface{}, value interface{}) bool { |
| 1199 | portInfo := value.(*VoltPort) |
| 1200 | if portInfo.ID == port { |
| 1201 | portName = portInfo.Name |
| 1202 | return false |
| 1203 | } |
| 1204 | return true |
| 1205 | }) |
| 1206 | return portName, nil |
| 1207 | } |
| 1208 | |
| 1209 | // GetPonFromUniPort to get Pon info from UniPort |
| 1210 | func (va *VoltApplication) GetPonFromUniPort(port string) (string, error) { |
| 1211 | uniPortID, err := va.GetPortID(port) |
| 1212 | if err == nil { |
| 1213 | ponPortID := (uniPortID & 0x0FF00000) >> 20 //pon(8) + onu(8) + uni(12) |
| 1214 | return strconv.FormatUint(uint64(ponPortID), 10), nil |
| 1215 | } |
| 1216 | return "", err |
| 1217 | } |
| 1218 | |
| 1219 | // GetPortState : This too applies only to access ports. The ports can be indexed |
| 1220 | // purely by their names without the device forming part of the key |
| 1221 | func (va *VoltApplication) GetPortState(port string) (PortState, error) { |
| 1222 | va.portLock.Lock() |
| 1223 | defer va.portLock.Unlock() |
| 1224 | p, ok := va.PortsDisc.Load(port) |
| 1225 | if !ok { |
| 1226 | return 0, errors.New("Port not configured") |
| 1227 | } |
| 1228 | return p.(*VoltPort).State, nil |
| 1229 | } |
| 1230 | |
| 1231 | // GetIcmpv6Receivers to get Icmp v6 receivers |
| 1232 | func (va *VoltApplication) GetIcmpv6Receivers(device string) []uint32 { |
| 1233 | var receiverList []uint32 |
| 1234 | receivers, _ := va.Icmpv6Receivers.Load(device) |
| 1235 | if receivers != nil { |
| 1236 | receiverList = receivers.([]uint32) |
| 1237 | } |
| 1238 | return receiverList |
| 1239 | } |
| 1240 | |
| 1241 | // AddIcmpv6Receivers to add Icmp v6 receivers |
| 1242 | func (va *VoltApplication) AddIcmpv6Receivers(device string, portID uint32) []uint32 { |
| 1243 | var receiverList []uint32 |
| 1244 | receivers, _ := va.Icmpv6Receivers.Load(device) |
| 1245 | if receivers != nil { |
| 1246 | receiverList = receivers.([]uint32) |
| 1247 | } |
| 1248 | receiverList = append(receiverList, portID) |
| 1249 | va.Icmpv6Receivers.Store(device, receiverList) |
| 1250 | logger.Debugw(ctx, "Receivers after addition", log.Fields{"Receivers": receiverList}) |
| 1251 | return receiverList |
| 1252 | } |
| 1253 | |
| 1254 | // DelIcmpv6Receivers to delete Icmp v6 receievers |
| 1255 | func (va *VoltApplication) DelIcmpv6Receivers(device string, portID uint32) []uint32 { |
| 1256 | var receiverList []uint32 |
| 1257 | receivers, _ := va.Icmpv6Receivers.Load(device) |
| 1258 | if receivers != nil { |
| 1259 | receiverList = receivers.([]uint32) |
| 1260 | } |
| 1261 | for i, port := range receiverList { |
| 1262 | if port == portID { |
| 1263 | receiverList = append(receiverList[0:i], receiverList[i+1:]...) |
| 1264 | va.Icmpv6Receivers.Store(device, receiverList) |
| 1265 | break |
| 1266 | } |
| 1267 | } |
| 1268 | logger.Debugw(ctx, "Receivers After deletion", log.Fields{"Receivers": receiverList}) |
| 1269 | return receiverList |
| 1270 | } |
| 1271 | |
| 1272 | // ProcessDevFlowForDevice - Process DS ICMPv6 & ARP flow for provided device and vnet profile |
| 1273 | // device - Device Obj |
| 1274 | // vnet - vnet profile name |
| 1275 | // enabled - vlan enabled/disabled - based on the status, the flow shall be added/removed |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 1276 | func (va *VoltApplication) ProcessDevFlowForDevice(cntx context.Context, device *VoltDevice, vnet *VoltVnet, enabled bool) { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1277 | _, applied := device.ConfiguredVlanForDeviceFlows.Get(VnetKey(vnet.SVlan, vnet.CVlan, 0)) |
| 1278 | if enabled { |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 1279 | va.PushDevFlowForVlan(cntx, vnet) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1280 | } else if !enabled && applied { |
| 1281 | //va.DeleteDevFlowForVlan(vnet) |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 1282 | va.DeleteDevFlowForVlanFromDevice(cntx, vnet, device.SerialNum) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1283 | } |
| 1284 | } |
| 1285 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 1286 | // NniVlanIndToIgmp - Trigger receiver up indication to all ports with igmp enabled |
| 1287 | // and has the provided mvlan |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1288 | func (va *VoltApplication) NniVlanIndToIgmp(device *VoltDevice, mvp *MvlanProfile) { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1289 | logger.Infow(ctx, "Sending Igmp Receiver UP indication for all Services", log.Fields{"Vlan": mvp.Mvlan}) |
| 1290 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 1291 | // Trigger nni indication for receiver only for first time |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1292 | if device.IgmpDsFlowAppliedForMvlan[uint16(mvp.Mvlan)] { |
| 1293 | return |
| 1294 | } |
| 1295 | device.Ports.Range(func(key, value interface{}) bool { |
| 1296 | port := key.(string) |
| 1297 | |
| 1298 | if state, _ := va.GetPortState(port); state == PortStateUp { |
| 1299 | vpvs, _ := va.VnetsByPort.Load(port) |
| 1300 | if vpvs == nil { |
| 1301 | return true |
| 1302 | } |
| 1303 | for _, vpv := range vpvs.([]*VoltPortVnet) { |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 1304 | // Send indication only for subscribers with the received mvlan profile |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1305 | if vpv.IgmpEnabled && vpv.MvlanProfileName == mvp.Name { |
| 1306 | vpv.services.Range(ReceiverUpInd) |
| 1307 | } |
| 1308 | } |
| 1309 | } |
| 1310 | return true |
| 1311 | }) |
| 1312 | } |
| 1313 | |
| 1314 | // PortUpInd : |
| 1315 | // ----------------------------------------------------------------------- |
| 1316 | // Port status change handling |
| 1317 | // ---------------------------------------------------------------------- |
| 1318 | // Port UP indication is passed to all services associated with the port |
| 1319 | // so that the services can configure flows applicable when the port goes |
| 1320 | // up from down state |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 1321 | func (va *VoltApplication) PortUpInd(cntx context.Context, device string, port string) { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1322 | d := va.GetDevice(device) |
| 1323 | |
| 1324 | if d == nil { |
| 1325 | logger.Warnw(ctx, "Device Not Found - Dropping Port Ind: UP", log.Fields{"Device": device, "Port": port}) |
| 1326 | return |
| 1327 | } |
| 1328 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 1329 | // Fixme: If Port Update Comes in large numbers, this will result in slow update per device |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1330 | va.portLock.Lock() |
| 1331 | // Do not defer the port mutex unlock here |
| 1332 | // Some of the following func calls needs the port lock, so defering the lock here |
| 1333 | // may lead to dead-lock |
| 1334 | p := d.GetPort(port) |
| 1335 | |
| 1336 | if p == nil { |
| 1337 | logger.Infow(ctx, "Ignoring Port Ind: UP, Port doesnt exist", log.Fields{"Device": device, "PortName": port, "PortId": p}) |
| 1338 | va.portLock.Unlock() |
| 1339 | return |
| 1340 | } |
| 1341 | p.State = PortStateUp |
| 1342 | va.portLock.Unlock() |
| 1343 | |
| 1344 | logger.Infow(ctx, "Received SouthBound Port Ind: UP", log.Fields{"Device": device, "PortName": port, "PortId": p.ID}) |
| 1345 | if p.Type == VoltPortTypeNni { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1346 | logger.Warnw(ctx, "Received NNI Port Ind: UP", log.Fields{"Device": device, "PortName": port, "PortId": p.ID}) |
| 1347 | //va.PushDevFlowForDevice(d) |
| 1348 | //Build Igmp TrapFlowRule |
| 1349 | //va.ProcessIgmpDSFlowForDevice(d, true) |
| 1350 | } |
| 1351 | vpvs, ok := va.VnetsByPort.Load(port) |
| 1352 | if !ok || nil == vpvs || len(vpvs.([]*VoltPortVnet)) == 0 { |
| 1353 | logger.Infow(ctx, "No VNETs on port", log.Fields{"Device": device, "Port": port}) |
| 1354 | //msgbus.ProcessPortInd(msgbus.PortUp, d.SerialNum, p.Name, false, getServiceList(port)) |
| 1355 | return |
| 1356 | } |
| 1357 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 1358 | // If NNI port is not UP, do not push Flows |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1359 | if d.NniPort == "" { |
| 1360 | logger.Warnw(ctx, "NNI port not UP. Not sending Port UP Ind for VPVs", log.Fields{"NNI": d.NniPort}) |
| 1361 | return |
| 1362 | } |
| 1363 | |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1364 | for _, vpv := range vpvs.([]*VoltPortVnet) { |
| 1365 | vpv.VpvLock.Lock() |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 1366 | // If no service is activated drop the portUpInd |
Tinoj Joseph | ec742f6 | 2022-09-29 19:11:10 +0530 | [diff] [blame] | 1367 | if vpv.IsServiceActivated(cntx) { |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 1368 | // Do not trigger indication for the vpv which is already removed from vpv list as |
Tinoj Joseph | ec742f6 | 2022-09-29 19:11:10 +0530 | [diff] [blame] | 1369 | // part of service delete (during the lock wait duration) |
| 1370 | // In that case, the services associated wil be zero |
| 1371 | if vpv.servicesCount.Load() != 0 { |
| 1372 | vpv.PortUpInd(cntx, d, port) |
| 1373 | } |
| 1374 | } else { |
| 1375 | // Service not activated, still attach device to service |
| 1376 | vpv.setDevice(d.Name) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1377 | } |
| 1378 | vpv.VpvLock.Unlock() |
| 1379 | } |
| 1380 | // At the end of processing inform the other entities that |
| 1381 | // are interested in the events |
| 1382 | } |
| 1383 | |
| 1384 | /* |
| 1385 | func getServiceList(port string) map[string]bool { |
| 1386 | serviceList := make(map[string]bool) |
| 1387 | |
| 1388 | getServiceNames := func(key interface{}, value interface{}) bool { |
| 1389 | serviceList[key.(string)] = value.(*VoltService).DsHSIAFlowsApplied |
| 1390 | return true |
| 1391 | } |
| 1392 | |
| 1393 | if vpvs, _ := GetApplication().VnetsByPort.Load(port); vpvs != nil { |
| 1394 | vpvList := vpvs.([]*VoltPortVnet) |
| 1395 | for _, vpv := range vpvList { |
| 1396 | vpv.services.Range(getServiceNames) |
| 1397 | } |
| 1398 | } |
| 1399 | return serviceList |
| 1400 | |
| 1401 | }*/ |
| 1402 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 1403 | // ReceiverUpInd - Send receiver up indication for service with Igmp enabled |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1404 | func ReceiverUpInd(key, value interface{}) bool { |
| 1405 | svc := value.(*VoltService) |
| 1406 | var vlan of.VlanType |
| 1407 | |
| 1408 | if !svc.IPAssigned() { |
| 1409 | logger.Infow(ctx, "IP Not assigned, skipping general query", log.Fields{"Service": svc}) |
| 1410 | return false |
| 1411 | } |
| 1412 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 1413 | // Send port up indication to igmp only for service with igmp enabled |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1414 | if svc.IgmpEnabled { |
| 1415 | if svc.VlanControl == ONUCVlan || svc.VlanControl == ONUCVlanOLTSVlan { |
| 1416 | vlan = svc.CVlan |
| 1417 | } else { |
| 1418 | vlan = svc.UniVlan |
| 1419 | } |
| 1420 | if device, _ := GetApplication().GetDeviceFromPort(svc.Port); device != nil { |
| 1421 | GetApplication().ReceiverUpInd(device.Name, svc.Port, svc.MvlanProfileName, vlan, svc.Pbits) |
| 1422 | } |
| 1423 | return false |
| 1424 | } |
| 1425 | return true |
| 1426 | } |
| 1427 | |
| 1428 | // PortDownInd : Port down indication is passed on to the services so that the services |
| 1429 | // can make changes at this transition. |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 1430 | func (va *VoltApplication) PortDownInd(cntx context.Context, device string, port string) { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1431 | logger.Infow(ctx, "Received SouthBound Port Ind: DOWN", log.Fields{"Device": device, "Port": port}) |
| 1432 | d := va.GetDevice(device) |
| 1433 | |
| 1434 | if d == nil { |
| 1435 | logger.Warnw(ctx, "Device Not Found - Dropping Port Ind: DOWN", log.Fields{"Device": device, "Port": port}) |
| 1436 | return |
| 1437 | } |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 1438 | // Fixme: If Port Update Comes in large numbers, this will result in slow update per device |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1439 | va.portLock.Lock() |
| 1440 | // Do not defer the port mutex unlock here |
| 1441 | // Some of the following func calls needs the port lock, so defering the lock here |
| 1442 | // may lead to dead-lock |
| 1443 | p := d.GetPort(port) |
| 1444 | if p == nil { |
| 1445 | logger.Infow(ctx, "Ignoring Port Ind: Down, Port doesnt exist", log.Fields{"Device": device, "PortName": port, "PortId": p}) |
| 1446 | va.portLock.Unlock() |
| 1447 | return |
| 1448 | } |
| 1449 | p.State = PortStateDown |
| 1450 | va.portLock.Unlock() |
| 1451 | |
| 1452 | if d.State == controller.DeviceStateREBOOTED { |
| 1453 | logger.Infow(ctx, "Ignoring Port Ind: Down, Device has been Rebooted", log.Fields{"Device": device, "PortName": port, "PortId": p}) |
| 1454 | return |
| 1455 | } |
| 1456 | |
| 1457 | if p.Type == VoltPortTypeNni { |
| 1458 | logger.Warnw(ctx, "Received NNI Port Ind: DOWN", log.Fields{"Device": device, "Port": port}) |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 1459 | va.DeleteDevFlowForDevice(cntx, d) |
| 1460 | va.NniDownInd(cntx, device, d.SerialNum) |
| 1461 | va.RemovePendingGroups(cntx, device, true) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1462 | } |
| 1463 | vpvs, ok := va.VnetsByPort.Load(port) |
| 1464 | if !ok || nil == vpvs || len(vpvs.([]*VoltPortVnet)) == 0 { |
| 1465 | logger.Infow(ctx, "No VNETs on port", log.Fields{"Device": device, "Port": port}) |
| 1466 | //msgbus.ProcessPortInd(msgbus.PortDown, d.SerialNum, p.Name, false, getServiceList(port)) |
| 1467 | return |
| 1468 | } |
Akash Soni | a824697 | 2023-01-03 10:37:08 +0530 | [diff] [blame] | 1469 | |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1470 | for _, vpv := range vpvs.([]*VoltPortVnet) { |
| 1471 | vpv.VpvLock.Lock() |
Tinoj Joseph | 4ead4e0 | 2023-01-30 03:12:44 +0530 | [diff] [blame] | 1472 | vpv.PortDownInd(cntx, device, port, false) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1473 | if vpv.IgmpEnabled { |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 1474 | va.ReceiverDownInd(cntx, device, port) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1475 | } |
| 1476 | vpv.VpvLock.Unlock() |
| 1477 | } |
| 1478 | } |
| 1479 | |
| 1480 | // PacketInInd : |
| 1481 | // ----------------------------------------------------------------------- |
| 1482 | // PacketIn Processing |
| 1483 | // Packet In Indication processing. It arrives with the identities of |
| 1484 | // the device and port on which the packet is received. At first, the |
| 1485 | // packet is decoded and the right processor is called. Currently, we |
| 1486 | // plan to support only DHCP and IGMP. In future, we can add more |
| 1487 | // capabilities as needed |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 1488 | func (va *VoltApplication) PacketInInd(cntx context.Context, device string, port string, pkt []byte) { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1489 | // Decode the incoming packet |
| 1490 | packetSide := US |
| 1491 | if strings.Contains(port, NNI) { |
| 1492 | packetSide = DS |
| 1493 | } |
| 1494 | |
| 1495 | logger.Debugw(ctx, "Received a Packet-In Indication", log.Fields{"Device": device, "Port": port}) |
| 1496 | |
| 1497 | gopkt := gopacket.NewPacket(pkt, layers.LayerTypeEthernet, gopacket.Default) |
| 1498 | |
| 1499 | var dot1qFound = false |
| 1500 | for _, l := range gopkt.Layers() { |
| 1501 | if l.LayerType() == layers.LayerTypeDot1Q { |
| 1502 | dot1qFound = true |
| 1503 | break |
| 1504 | } |
| 1505 | } |
| 1506 | |
| 1507 | if !dot1qFound { |
| 1508 | logger.Debugw(ctx, "Ignoring Received Packet-In Indication without Dot1Q Header", |
| 1509 | log.Fields{"Device": device, "Port": port}) |
| 1510 | return |
| 1511 | } |
| 1512 | |
| 1513 | logger.Debugw(ctx, "Received Southbound Packet In", log.Fields{"Pkt": hex.EncodeToString(gopkt.Data())}) |
| 1514 | |
| 1515 | // Classify the packet into packet types that we support |
| 1516 | // The supported types are DHCP and IGMP. The DHCP packet is |
| 1517 | // identified by matching the L4 protocol to UDP. The IGMP packet |
| 1518 | // is identified by matching L3 protocol to IGMP |
| 1519 | arpl := gopkt.Layer(layers.LayerTypeARP) |
| 1520 | if arpl != nil { |
| 1521 | if callBack, ok := PacketHandlers[ARP]; ok { |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 1522 | callBack(cntx, device, port, gopkt) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1523 | } else { |
| 1524 | logger.Debugw(ctx, "ARP handler is not registered, dropping the packet", log.Fields{"Pkt": hex.EncodeToString(gopkt.Data())}) |
| 1525 | } |
| 1526 | return |
| 1527 | } |
| 1528 | ipv4l := gopkt.Layer(layers.LayerTypeIPv4) |
| 1529 | if ipv4l != nil { |
| 1530 | ip := ipv4l.(*layers.IPv4) |
| 1531 | |
| 1532 | if ip.Protocol == layers.IPProtocolUDP { |
| 1533 | logger.Debugw(ctx, "Received Southbound UDP ipv4 packet in", log.Fields{"StreamSide": packetSide}) |
| 1534 | dhcpl := gopkt.Layer(layers.LayerTypeDHCPv4) |
| 1535 | if dhcpl != nil { |
| 1536 | if callBack, ok := PacketHandlers[DHCPv4]; ok { |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 1537 | callBack(cntx, device, port, gopkt) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1538 | } else { |
| 1539 | logger.Debugw(ctx, "DHCPv4 handler is not registered, dropping the packet", log.Fields{"Pkt": hex.EncodeToString(gopkt.Data())}) |
| 1540 | } |
| 1541 | } |
| 1542 | } else if ip.Protocol == layers.IPProtocolIGMP { |
| 1543 | logger.Debugw(ctx, "Received Southbound IGMP packet in", log.Fields{"StreamSide": packetSide}) |
| 1544 | if callBack, ok := PacketHandlers[IGMP]; ok { |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 1545 | callBack(cntx, device, port, gopkt) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1546 | } else { |
| 1547 | logger.Debugw(ctx, "IGMP handler is not registered, dropping the packet", log.Fields{"Pkt": hex.EncodeToString(gopkt.Data())}) |
| 1548 | } |
| 1549 | } |
| 1550 | return |
| 1551 | } |
| 1552 | ipv6l := gopkt.Layer(layers.LayerTypeIPv6) |
| 1553 | if ipv6l != nil { |
| 1554 | ip := ipv6l.(*layers.IPv6) |
| 1555 | if ip.NextHeader == layers.IPProtocolUDP { |
| 1556 | logger.Debug(ctx, "Received Southbound UDP ipv6 packet in") |
| 1557 | dhcpl := gopkt.Layer(layers.LayerTypeDHCPv6) |
| 1558 | if dhcpl != nil { |
| 1559 | if callBack, ok := PacketHandlers[DHCPv6]; ok { |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 1560 | callBack(cntx, device, port, gopkt) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1561 | } else { |
| 1562 | logger.Debugw(ctx, "DHCPv6 handler is not registered, dropping the packet", log.Fields{"Pkt": hex.EncodeToString(gopkt.Data())}) |
| 1563 | } |
| 1564 | } |
| 1565 | } |
| 1566 | return |
| 1567 | } |
| 1568 | |
| 1569 | pppoel := gopkt.Layer(layers.LayerTypePPPoE) |
| 1570 | if pppoel != nil { |
| 1571 | logger.Debugw(ctx, "Received Southbound PPPoE packet in", log.Fields{"StreamSide": packetSide}) |
| 1572 | if callBack, ok := PacketHandlers[PPPOE]; ok { |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 1573 | callBack(cntx, device, port, gopkt) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1574 | } else { |
| 1575 | logger.Debugw(ctx, "PPPoE handler is not registered, dropping the packet", log.Fields{"Pkt": hex.EncodeToString(gopkt.Data())}) |
| 1576 | } |
| 1577 | } |
| 1578 | } |
| 1579 | |
| 1580 | // GetVlans : This utility gets the VLANs from the packet. The VLANs are |
| 1581 | // used to identify the right service that must process the incoming |
| 1582 | // packet |
| 1583 | func GetVlans(pkt gopacket.Packet) []of.VlanType { |
| 1584 | var vlans []of.VlanType |
| 1585 | for _, l := range pkt.Layers() { |
| 1586 | if l.LayerType() == layers.LayerTypeDot1Q { |
| 1587 | q, ok := l.(*layers.Dot1Q) |
| 1588 | if ok { |
| 1589 | vlans = append(vlans, of.VlanType(q.VLANIdentifier)) |
| 1590 | } |
| 1591 | } |
| 1592 | } |
| 1593 | return vlans |
| 1594 | } |
| 1595 | |
| 1596 | // GetPriority to get priority |
| 1597 | func GetPriority(pkt gopacket.Packet) uint8 { |
| 1598 | for _, l := range pkt.Layers() { |
| 1599 | if l.LayerType() == layers.LayerTypeDot1Q { |
| 1600 | q, ok := l.(*layers.Dot1Q) |
| 1601 | if ok { |
| 1602 | return q.Priority |
| 1603 | } |
| 1604 | } |
| 1605 | } |
| 1606 | return PriorityNone |
| 1607 | } |
| 1608 | |
| 1609 | // HandleFlowClearFlag to handle flow clear flag during reboot |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 1610 | func (va *VoltApplication) HandleFlowClearFlag(cntx context.Context, deviceID string, serialNum, southBoundID string) { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1611 | logger.Warnw(ctx, "Clear All flags for Device", log.Fields{"Device": deviceID, "SerialNum": serialNum, "SBID": southBoundID}) |
| 1612 | dev, ok := va.DevicesDisc.Load(deviceID) |
| 1613 | if ok && dev != nil { |
| 1614 | logger.Infow(ctx, "Clear Flags for device", log.Fields{"voltDevice": dev.(*VoltDevice).Name}) |
| 1615 | dev.(*VoltDevice).icmpv6GroupAdded = false |
| 1616 | logger.Infow(ctx, "Clearing DS Icmpv6 Map", |
| 1617 | log.Fields{"voltDevice": dev.(*VoltDevice).Name}) |
| 1618 | dev.(*VoltDevice).ConfiguredVlanForDeviceFlows = util.NewConcurrentMap() |
| 1619 | logger.Infow(ctx, "Clearing DS IGMP Map", |
| 1620 | log.Fields{"voltDevice": dev.(*VoltDevice).Name}) |
| 1621 | for k := range dev.(*VoltDevice).IgmpDsFlowAppliedForMvlan { |
| 1622 | delete(dev.(*VoltDevice).IgmpDsFlowAppliedForMvlan, k) |
| 1623 | } |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 1624 | // Delete group 1 - ICMPv6/ARP group |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1625 | if err := ProcessIcmpv6McGroup(deviceID, true); err != nil { |
| 1626 | logger.Errorw(ctx, "ProcessIcmpv6McGroup failed", log.Fields{"Device": deviceID, "Error": err}) |
| 1627 | } |
| 1628 | } else { |
| 1629 | logger.Warnw(ctx, "VoltDevice not found for device ", log.Fields{"deviceID": deviceID}) |
| 1630 | } |
| 1631 | |
| 1632 | getVpvs := func(key interface{}, value interface{}) bool { |
| 1633 | vpvs := value.([]*VoltPortVnet) |
| 1634 | for _, vpv := range vpvs { |
| 1635 | if vpv.Device == deviceID { |
| 1636 | logger.Infow(ctx, "Clear Flags for vpv", |
| 1637 | log.Fields{"device": vpv.Device, "port": vpv.Port, |
| 1638 | "svlan": vpv.SVlan, "cvlan": vpv.CVlan, "univlan": vpv.UniVlan}) |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 1639 | vpv.ClearAllServiceFlags(cntx) |
| 1640 | vpv.ClearAllVpvFlags(cntx) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1641 | |
| 1642 | if vpv.IgmpEnabled { |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 1643 | va.ReceiverDownInd(cntx, vpv.Device, vpv.Port) |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 1644 | // Also clear service igmp stats |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 1645 | vpv.ClearServiceCounters(cntx) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1646 | } |
| 1647 | } |
| 1648 | } |
| 1649 | return true |
| 1650 | } |
| 1651 | va.VnetsByPort.Range(getVpvs) |
| 1652 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 1653 | // Clear Static Group |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 1654 | va.ReceiverDownInd(cntx, deviceID, StaticPort) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1655 | |
| 1656 | logger.Warnw(ctx, "All flags cleared for device", log.Fields{"Device": deviceID}) |
| 1657 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 1658 | // Reset pending group pool |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 1659 | va.RemovePendingGroups(cntx, deviceID, true) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1660 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 1661 | // Process all Migrate Service Request - force udpate all profiles since resources are already cleaned up |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1662 | if dev != nil { |
| 1663 | triggerForceUpdate := func(key, value interface{}) bool { |
| 1664 | msrList := value.(*util.ConcurrentMap) |
| 1665 | forceUpdateServices := func(key, value interface{}) bool { |
| 1666 | msr := value.(*MigrateServicesRequest) |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 1667 | forceUpdateAllServices(cntx, msr) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1668 | return true |
| 1669 | } |
| 1670 | msrList.Range(forceUpdateServices) |
| 1671 | return true |
| 1672 | } |
| 1673 | dev.(*VoltDevice).MigratingServices.Range(triggerForceUpdate) |
| 1674 | } else { |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 1675 | va.FetchAndProcessAllMigrateServicesReq(cntx, deviceID, forceUpdateAllServices) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1676 | } |
| 1677 | } |
| 1678 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 1679 | // GetPonPortIDFromUNIPort to get pon port id from uni port |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1680 | func GetPonPortIDFromUNIPort(uniPortID uint32) uint32 { |
| 1681 | ponPortID := (uniPortID & 0x0FF00000) >> 20 |
| 1682 | return ponPortID |
| 1683 | } |
| 1684 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 1685 | // ProcessFlowModResultIndication - Processes Flow mod operation indications from controller |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 1686 | func (va *VoltApplication) ProcessFlowModResultIndication(cntx context.Context, flowStatus intf.FlowStatus) { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1687 | d := va.GetDevice(flowStatus.Device) |
| 1688 | if d == nil { |
| 1689 | logger.Errorw(ctx, "Dropping Flow Mod Indication. Device not found", log.Fields{"Cookie": flowStatus.Cookie, "Device": flowStatus.Device}) |
| 1690 | return |
| 1691 | } |
| 1692 | |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 1693 | cookieExists := ExecuteFlowEvent(cntx, d, flowStatus.Cookie, flowStatus) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1694 | |
| 1695 | if flowStatus.Flow != nil { |
| 1696 | flowAdd := (flowStatus.FlowModType == of.CommandAdd) |
| 1697 | if !cookieExists && !isFlowStatusSuccess(flowStatus.Status, flowAdd) { |
| 1698 | pushFlowFailureNotif(flowStatus) |
| 1699 | } |
| 1700 | } |
| 1701 | } |
| 1702 | |
| 1703 | func pushFlowFailureNotif(flowStatus intf.FlowStatus) { |
| 1704 | subFlow := flowStatus.Flow |
| 1705 | cookie := subFlow.Cookie |
| 1706 | uniPort := cookie >> 16 & 0xFFFFFFFF |
| 1707 | logger.Errorw(ctx, "Flow Failure Notification", log.Fields{"uniPort": uniPort, "Cookie": cookie}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1708 | } |
| 1709 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 1710 | // UpdateMvlanProfilesForDevice to update mvlan profile for device |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 1711 | func (va *VoltApplication) UpdateMvlanProfilesForDevice(cntx context.Context, device string) { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1712 | checkAndAddMvlanUpdateTask := func(key, value interface{}) bool { |
| 1713 | mvp := value.(*MvlanProfile) |
| 1714 | if mvp.IsUpdateInProgressForDevice(device) { |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 1715 | mvp.UpdateProfile(cntx, device) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1716 | } |
| 1717 | return true |
| 1718 | } |
| 1719 | va.MvlanProfilesByName.Range(checkAndAddMvlanUpdateTask) |
| 1720 | } |
| 1721 | |
| 1722 | // TaskInfo structure that is used to store the task Info. |
| 1723 | type TaskInfo struct { |
| 1724 | ID string |
| 1725 | Name string |
| 1726 | Timestamp string |
| 1727 | } |
| 1728 | |
| 1729 | // GetTaskList to get task list information. |
| 1730 | func (va *VoltApplication) GetTaskList(device string) map[int]*TaskInfo { |
| 1731 | taskList := cntlr.GetController().GetTaskList(device) |
| 1732 | taskMap := make(map[int]*TaskInfo) |
| 1733 | for i, task := range taskList { |
| 1734 | taskID := strconv.Itoa(int(task.TaskID())) |
| 1735 | name := task.Name() |
| 1736 | timestamp := task.Timestamp() |
| 1737 | taskInfo := &TaskInfo{ID: taskID, Name: name, Timestamp: timestamp} |
| 1738 | taskMap[i] = taskInfo |
| 1739 | } |
| 1740 | return taskMap |
| 1741 | } |
| 1742 | |
| 1743 | // UpdateDeviceSerialNumberList to update the device serial number list after device serial number is updated for vnet and mvlan |
| 1744 | func (va *VoltApplication) UpdateDeviceSerialNumberList(oldOltSlNo string, newOltSlNo string) { |
Tinoj Joseph | 50d722c | 2022-12-06 22:53:22 +0530 | [diff] [blame] | 1745 | voltDevice, _ := va.GetDeviceBySerialNo(oldOltSlNo) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1746 | |
| 1747 | if voltDevice != nil { |
| 1748 | // Device is present with old serial number ID |
| 1749 | logger.Errorw(ctx, "OLT Migration cannot be completed as there are dangling devices", log.Fields{"Serial Number": oldOltSlNo}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1750 | } else { |
| 1751 | logger.Infow(ctx, "No device present with old serial number", log.Fields{"Serial Number": oldOltSlNo}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1752 | // Add Serial Number to Blocked Devices List. |
| 1753 | cntlr.GetController().AddBlockedDevices(oldOltSlNo) |
| 1754 | cntlr.GetController().AddBlockedDevices(newOltSlNo) |
| 1755 | |
| 1756 | updateSlNoForVnet := func(key, value interface{}) bool { |
| 1757 | vnet := value.(*VoltVnet) |
| 1758 | for i, deviceSlNo := range vnet.VnetConfig.DevicesList { |
| 1759 | if deviceSlNo == oldOltSlNo { |
| 1760 | vnet.VnetConfig.DevicesList[i] = newOltSlNo |
| 1761 | logger.Infow(ctx, "device serial number updated for vnet profile", log.Fields{"Updated Serial Number": deviceSlNo, "Previous Serial Number": oldOltSlNo}) |
| 1762 | break |
| 1763 | } |
| 1764 | } |
| 1765 | return true |
| 1766 | } |
| 1767 | |
| 1768 | updateSlNoforMvlan := func(key interface{}, value interface{}) bool { |
| 1769 | mvProfile := value.(*MvlanProfile) |
| 1770 | for deviceSlNo := range mvProfile.DevicesList { |
| 1771 | if deviceSlNo == oldOltSlNo { |
| 1772 | mvProfile.DevicesList[newOltSlNo] = mvProfile.DevicesList[oldOltSlNo] |
| 1773 | delete(mvProfile.DevicesList, oldOltSlNo) |
| 1774 | logger.Infow(ctx, "device serial number updated for mvlan profile", log.Fields{"Updated Serial Number": deviceSlNo, "Previous Serial Number": oldOltSlNo}) |
| 1775 | break |
| 1776 | } |
| 1777 | } |
| 1778 | return true |
| 1779 | } |
| 1780 | |
| 1781 | va.VnetsByName.Range(updateSlNoForVnet) |
| 1782 | va.MvlanProfilesByName.Range(updateSlNoforMvlan) |
| 1783 | |
| 1784 | // Clear the serial number from Blocked Devices List |
| 1785 | cntlr.GetController().DelBlockedDevices(oldOltSlNo) |
| 1786 | cntlr.GetController().DelBlockedDevices(newOltSlNo) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1787 | } |
| 1788 | } |
| 1789 | |
| 1790 | // GetVpvsForDsPkt to get vpv for downstream packets |
| 1791 | func (va *VoltApplication) GetVpvsForDsPkt(cvlan of.VlanType, svlan of.VlanType, clientMAC net.HardwareAddr, |
| 1792 | pbit uint8) ([]*VoltPortVnet, error) { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1793 | var matchVPVs []*VoltPortVnet |
| 1794 | findVpv := func(key, value interface{}) bool { |
| 1795 | vpvs := value.([]*VoltPortVnet) |
| 1796 | for _, vpv := range vpvs { |
| 1797 | if vpv.isVlanMatching(cvlan, svlan) && vpv.MatchesPriority(pbit) != nil { |
| 1798 | var subMac net.HardwareAddr |
| 1799 | if NonZeroMacAddress(vpv.MacAddr) { |
| 1800 | subMac = vpv.MacAddr |
| 1801 | } else if vpv.LearntMacAddr != nil && NonZeroMacAddress(vpv.LearntMacAddr) { |
| 1802 | subMac = vpv.LearntMacAddr |
| 1803 | } else { |
| 1804 | matchVPVs = append(matchVPVs, vpv) |
| 1805 | continue |
| 1806 | } |
| 1807 | if util.MacAddrsMatch(subMac, clientMAC) { |
| 1808 | matchVPVs = append([]*VoltPortVnet{}, vpv) |
| 1809 | logger.Infow(ctx, "Matching VPV found", log.Fields{"Port": vpv.Port, "SVLAN": vpv.SVlan, "CVLAN": vpv.CVlan, "UNIVlan": vpv.UniVlan, "MAC": clientMAC}) |
| 1810 | return false |
| 1811 | } |
| 1812 | } |
| 1813 | } |
| 1814 | return true |
| 1815 | } |
| 1816 | va.VnetsByPort.Range(findVpv) |
| 1817 | |
| 1818 | if len(matchVPVs) != 1 { |
| 1819 | logger.Infow(ctx, "No matching VPV found or multiple vpvs found", log.Fields{"Match VPVs": matchVPVs, "MAC": clientMAC}) |
| 1820 | return nil, errors.New("No matching VPV found or multiple vpvs found") |
| 1821 | } |
| 1822 | return matchVPVs, nil |
| 1823 | } |
| 1824 | |
| 1825 | // GetMacInPortMap to get PORT value based on MAC key |
| 1826 | func (va *VoltApplication) GetMacInPortMap(macAddr net.HardwareAddr) string { |
| 1827 | if NonZeroMacAddress(macAddr) { |
| 1828 | va.macPortLock.Lock() |
| 1829 | defer va.macPortLock.Unlock() |
| 1830 | if port, ok := va.macPortMap[macAddr.String()]; ok { |
| 1831 | logger.Debugw(ctx, "found-entry-macportmap", log.Fields{"MacAddr": macAddr.String(), "Port": port}) |
| 1832 | return port |
| 1833 | } |
| 1834 | } |
| 1835 | logger.Infow(ctx, "entry-not-found-macportmap", log.Fields{"MacAddr": macAddr.String()}) |
| 1836 | return "" |
| 1837 | } |
| 1838 | |
| 1839 | // UpdateMacInPortMap to update MAC PORT (key value) information in MacPortMap |
| 1840 | func (va *VoltApplication) UpdateMacInPortMap(macAddr net.HardwareAddr, port string) { |
| 1841 | if NonZeroMacAddress(macAddr) { |
| 1842 | va.macPortLock.Lock() |
| 1843 | va.macPortMap[macAddr.String()] = port |
| 1844 | va.macPortLock.Unlock() |
| 1845 | logger.Debugw(ctx, "updated-macportmap", log.Fields{"MacAddr": macAddr.String(), "Port": port}) |
| 1846 | } |
| 1847 | } |
| 1848 | |
| 1849 | // DeleteMacInPortMap to remove MAC key from MacPortMap |
| 1850 | func (va *VoltApplication) DeleteMacInPortMap(macAddr net.HardwareAddr) { |
| 1851 | if NonZeroMacAddress(macAddr) { |
| 1852 | port := va.GetMacInPortMap(macAddr) |
| 1853 | va.macPortLock.Lock() |
| 1854 | delete(va.macPortMap, macAddr.String()) |
| 1855 | va.macPortLock.Unlock() |
| 1856 | logger.Debugw(ctx, "deleted-from-macportmap", log.Fields{"MacAddr": macAddr.String(), "Port": port}) |
| 1857 | } |
| 1858 | } |
| 1859 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 1860 | // AddGroupToPendingPool - adds the IgmpGroup with active group table entry to global pending pool |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1861 | func (va *VoltApplication) AddGroupToPendingPool(ig *IgmpGroup) { |
| 1862 | var grpMap map[*IgmpGroup]bool |
| 1863 | var ok bool |
| 1864 | |
| 1865 | va.PendingPoolLock.Lock() |
| 1866 | defer va.PendingPoolLock.Unlock() |
| 1867 | |
| 1868 | logger.Infow(ctx, "Adding IgmpGroup to Global Pending Pool", log.Fields{"GroupID": ig.GroupID, "GroupName": ig.GroupName, "GroupAddr": ig.GroupAddr, "PendingDevices": len(ig.Devices)}) |
| 1869 | // Do Not Reset any current profile info since group table entry tied to mvlan profile |
| 1870 | // The PonVlan is part of set field in group installed |
| 1871 | // Hence, Group created is always tied to the same mvlan profile until deleted |
| 1872 | |
| 1873 | for device := range ig.Devices { |
| 1874 | key := getPendingPoolKey(ig.Mvlan, device) |
| 1875 | |
| 1876 | if grpMap, ok = va.IgmpPendingPool[key]; !ok { |
| 1877 | grpMap = make(map[*IgmpGroup]bool) |
| 1878 | } |
| 1879 | grpMap[ig] = true |
| 1880 | |
| 1881 | //Add grpObj reference to all associated devices |
| 1882 | va.IgmpPendingPool[key] = grpMap |
| 1883 | } |
| 1884 | } |
| 1885 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 1886 | // RemoveGroupFromPendingPool - removes the group from global pending group pool |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1887 | func (va *VoltApplication) RemoveGroupFromPendingPool(device string, ig *IgmpGroup) bool { |
| 1888 | GetApplication().PendingPoolLock.Lock() |
| 1889 | defer GetApplication().PendingPoolLock.Unlock() |
| 1890 | |
| 1891 | logger.Infow(ctx, "Removing IgmpGroup from Global Pending Pool", log.Fields{"Device": device, "GroupID": ig.GroupID, "GroupName": ig.GroupName, "GroupAddr": ig.GroupAddr, "PendingDevices": len(ig.Devices)}) |
| 1892 | |
| 1893 | key := getPendingPoolKey(ig.Mvlan, device) |
| 1894 | if _, ok := va.IgmpPendingPool[key]; ok { |
| 1895 | delete(va.IgmpPendingPool[key], ig) |
| 1896 | return true |
| 1897 | } |
| 1898 | return false |
| 1899 | } |
| 1900 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 1901 | // RemoveGroupsFromPendingPool - removes the group from global pending group pool |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 1902 | func (va *VoltApplication) RemoveGroupsFromPendingPool(cntx context.Context, device string, mvlan of.VlanType) { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1903 | GetApplication().PendingPoolLock.Lock() |
| 1904 | defer GetApplication().PendingPoolLock.Unlock() |
| 1905 | |
| 1906 | logger.Infow(ctx, "Removing IgmpGroups from Global Pending Pool for given Deivce & Mvlan", log.Fields{"Device": device, "Mvlan": mvlan.String()}) |
| 1907 | |
| 1908 | key := getPendingPoolKey(mvlan, device) |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 1909 | va.RemoveGroupListFromPendingPool(cntx, key) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1910 | } |
| 1911 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 1912 | // RemoveGroupListFromPendingPool - removes the groups for provided key |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1913 | // 1. Deletes the group from device |
| 1914 | // 2. Delete the IgmpGroup obj and release the group ID to pool |
| 1915 | // Note: Make sure to obtain PendingPoolLock lock before calling this func |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 1916 | func (va *VoltApplication) RemoveGroupListFromPendingPool(cntx context.Context, key string) { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1917 | if grpMap, ok := va.IgmpPendingPool[key]; ok { |
| 1918 | delete(va.IgmpPendingPool, key) |
| 1919 | for ig := range grpMap { |
| 1920 | for device := range ig.Devices { |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 1921 | ig.DeleteIgmpGroupDevice(cntx, device) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1922 | } |
| 1923 | } |
| 1924 | } |
| 1925 | } |
| 1926 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 1927 | // RemoveGroupDevicesFromPendingPool - removes the group from global pending group pool |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1928 | func (va *VoltApplication) RemoveGroupDevicesFromPendingPool(ig *IgmpGroup) { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1929 | logger.Infow(ctx, "Removing IgmpGroup for all devices from Global Pending Pool", log.Fields{"GroupID": ig.GroupID, "GroupName": ig.GroupName, "GroupAddr": ig.GroupAddr, "PendingDevices": len(ig.Devices)}) |
| 1930 | for device := range ig.PendingGroupForDevice { |
| 1931 | va.RemoveGroupFromPendingPool(device, ig) |
| 1932 | } |
| 1933 | } |
| 1934 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 1935 | // GetGroupFromPendingPool - Returns IgmpGroup obj from global pending pool |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1936 | func (va *VoltApplication) GetGroupFromPendingPool(mvlan of.VlanType, device string) *IgmpGroup { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1937 | var ig *IgmpGroup |
| 1938 | |
| 1939 | va.PendingPoolLock.Lock() |
| 1940 | defer va.PendingPoolLock.Unlock() |
| 1941 | |
| 1942 | key := getPendingPoolKey(mvlan, device) |
| 1943 | logger.Infow(ctx, "Getting IgmpGroup from Global Pending Pool", log.Fields{"Device": device, "Mvlan": mvlan.String(), "Key": key}) |
| 1944 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 1945 | // Gets all IgmpGrp Obj for the device |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1946 | grpMap, ok := va.IgmpPendingPool[key] |
| 1947 | if !ok || len(grpMap) == 0 { |
| 1948 | logger.Infow(ctx, "Matching IgmpGroup not found in Global Pending Pool", log.Fields{"Device": device, "Mvlan": mvlan.String()}) |
| 1949 | return nil |
| 1950 | } |
| 1951 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 1952 | // Gets a random obj from available grps |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1953 | for ig = range grpMap { |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 1954 | // Remove grp obj reference from all devices associated in pending pool |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1955 | for dev := range ig.Devices { |
| 1956 | key := getPendingPoolKey(mvlan, dev) |
| 1957 | delete(va.IgmpPendingPool[key], ig) |
| 1958 | } |
| 1959 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 1960 | // Safety check to avoid re-allocating group already in use |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1961 | if ig.NumDevicesActive() == 0 { |
| 1962 | return ig |
| 1963 | } |
| 1964 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 1965 | // Iteration will continue only if IG is not allocated |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1966 | } |
| 1967 | return nil |
| 1968 | } |
| 1969 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 1970 | // RemovePendingGroups - removes all pending groups for provided reference from global pending pool |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1971 | // reference - mvlan/device ID |
| 1972 | // isRefDevice - true - Device as reference |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 1973 | // false - Mvlan as reference |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 1974 | func (va *VoltApplication) RemovePendingGroups(cntx context.Context, reference string, isRefDevice bool) { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1975 | va.PendingPoolLock.Lock() |
| 1976 | defer va.PendingPoolLock.Unlock() |
| 1977 | |
| 1978 | logger.Infow(ctx, "Removing IgmpGroups from Global Pending Pool", log.Fields{"Reference": reference, "isRefDevice": isRefDevice}) |
| 1979 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 1980 | // Pending Pool key: "<mvlan>_<DeviceID>"" |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1981 | paramPosition := 0 |
| 1982 | if isRefDevice { |
| 1983 | paramPosition = 1 |
| 1984 | } |
| 1985 | |
| 1986 | // 1.Remove the Entry from pending pool |
| 1987 | // 2.Deletes the group from device |
| 1988 | // 3.Delete the IgmpGroup obj and release the group ID to pool |
| 1989 | for key := range va.IgmpPendingPool { |
| 1990 | keyParams := strings.Split(key, "_") |
| 1991 | if keyParams[paramPosition] == reference { |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 1992 | va.RemoveGroupListFromPendingPool(cntx, key) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1993 | } |
| 1994 | } |
| 1995 | } |
| 1996 | |
| 1997 | func getPendingPoolKey(mvlan of.VlanType, device string) string { |
| 1998 | return mvlan.String() + "_" + device |
| 1999 | } |
| 2000 | |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 2001 | func (va *VoltApplication) removeExpiredGroups(cntx context.Context) { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 2002 | logger.Debug(ctx, "Check for expired Igmp Groups") |
| 2003 | removeExpiredGroups := func(key interface{}, value interface{}) bool { |
| 2004 | ig := value.(*IgmpGroup) |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 2005 | ig.removeExpiredGroupFromDevice(cntx) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 2006 | return true |
| 2007 | } |
| 2008 | va.IgmpGroups.Range(removeExpiredGroups) |
| 2009 | } |
| 2010 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 2011 | // TriggerPendingProfileDeleteReq - trigger pending profile delete request |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 2012 | func (va *VoltApplication) TriggerPendingProfileDeleteReq(cntx context.Context, device string) { |
| 2013 | va.TriggerPendingServiceDeleteReq(cntx, device) |
| 2014 | va.TriggerPendingVpvDeleteReq(cntx, device) |
| 2015 | va.TriggerPendingVnetDeleteReq(cntx, device) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 2016 | logger.Warnw(ctx, "All Pending Profile Delete triggered for device", log.Fields{"Device": device}) |
| 2017 | } |
| 2018 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 2019 | // TriggerPendingServiceDeleteReq - trigger pending service delete request |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 2020 | func (va *VoltApplication) TriggerPendingServiceDeleteReq(cntx context.Context, device string) { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 2021 | logger.Warnw(ctx, "Pending Services to be deleted", log.Fields{"Count": len(va.ServicesToDelete)}) |
| 2022 | for serviceName := range va.ServicesToDelete { |
| 2023 | logger.Debugw(ctx, "Trigger Service Delete", log.Fields{"Service": serviceName}) |
| 2024 | if vs := va.GetService(serviceName); vs != nil { |
| 2025 | if vs.Device == device { |
| 2026 | logger.Warnw(ctx, "Triggering Pending Service delete", log.Fields{"Service": vs.Name}) |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 2027 | vs.DelHsiaFlows(cntx) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 2028 | if vs.ForceDelete { |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 2029 | vs.DelFromDb(cntx) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 2030 | } |
| 2031 | } |
| 2032 | } else { |
| 2033 | logger.Errorw(ctx, "Pending Service Not found", log.Fields{"Service": serviceName}) |
| 2034 | } |
| 2035 | } |
| 2036 | } |
| 2037 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 2038 | // TriggerPendingVpvDeleteReq - trigger pending VPV delete request |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 2039 | func (va *VoltApplication) TriggerPendingVpvDeleteReq(cntx context.Context, device string) { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 2040 | logger.Warnw(ctx, "Pending VPVs to be deleted", log.Fields{"Count": len(va.VoltPortVnetsToDelete)}) |
| 2041 | for vpv := range va.VoltPortVnetsToDelete { |
| 2042 | if vpv.Device == device { |
| 2043 | logger.Warnw(ctx, "Triggering Pending VPv flow delete", log.Fields{"Port": vpv.Port, "Device": vpv.Device, "Vnet": vpv.VnetName}) |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 2044 | va.DelVnetFromPort(cntx, vpv.Port, vpv) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 2045 | } |
| 2046 | } |
| 2047 | } |
| 2048 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 2049 | // TriggerPendingVnetDeleteReq - trigger pending vnet delete request |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 2050 | func (va *VoltApplication) TriggerPendingVnetDeleteReq(cntx context.Context, device string) { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 2051 | logger.Warnw(ctx, "Pending Vnets to be deleted", log.Fields{"Count": len(va.VnetsToDelete)}) |
| 2052 | for vnetName := range va.VnetsToDelete { |
| 2053 | if vnetIntf, _ := va.VnetsByName.Load(vnetName); vnetIntf != nil { |
| 2054 | vnet := vnetIntf.(*VoltVnet) |
| 2055 | logger.Warnw(ctx, "Triggering Pending Vnet flows delete", log.Fields{"Vnet": vnet.Name}) |
Tinoj Joseph | 50d722c | 2022-12-06 22:53:22 +0530 | [diff] [blame] | 2056 | if d, _ := va.GetDeviceBySerialNo(vnet.PendingDeviceToDelete); d != nil && d.SerialNum == vnet.PendingDeviceToDelete { |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 2057 | va.DeleteDevFlowForVlanFromDevice(cntx, vnet, vnet.PendingDeviceToDelete) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 2058 | va.deleteVnetConfig(vnet) |
| 2059 | } else { |
Tinoj Joseph | 1d10832 | 2022-07-13 10:07:39 +0530 | [diff] [blame] | 2060 | logger.Warnw(ctx, "Vnet Delete Failed : Device Not Found", log.Fields{"Vnet": vnet.Name, "Device": vnet.PendingDeviceToDelete}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 2061 | } |
| 2062 | } |
| 2063 | } |
| 2064 | } |
Tinoj Joseph | 4ead4e0 | 2023-01-30 03:12:44 +0530 | [diff] [blame] | 2065 | |
| 2066 | type OltFlowService struct { |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 2067 | DefaultTechProfileID int `json:"defaultTechProfileId"` |
Akash Soni | a824697 | 2023-01-03 10:37:08 +0530 | [diff] [blame] | 2068 | EnableDhcpOnNni bool `json:"enableDhcpOnNni"` |
Akash Soni | a824697 | 2023-01-03 10:37:08 +0530 | [diff] [blame] | 2069 | EnableIgmpOnNni bool `json:"enableIgmpOnNni"` |
| 2070 | EnableEapol bool `json:"enableEapol"` |
| 2071 | EnableDhcpV6 bool `json:"enableDhcpV6"` |
| 2072 | EnableDhcpV4 bool `json:"enableDhcpV4"` |
| 2073 | RemoveFlowsOnDisable bool `json:"removeFlowsOnDisable"` |
Tinoj Joseph | 4ead4e0 | 2023-01-30 03:12:44 +0530 | [diff] [blame] | 2074 | } |
| 2075 | |
| 2076 | func (va *VoltApplication) UpdateOltFlowService(cntx context.Context, oltFlowService OltFlowService) { |
| 2077 | logger.Infow(ctx, "UpdateOltFlowService", log.Fields{"oldValue": va.OltFlowServiceConfig, "newValue": oltFlowService}) |
| 2078 | va.OltFlowServiceConfig = oltFlowService |
| 2079 | b, err := json.Marshal(va.OltFlowServiceConfig) |
| 2080 | if err != nil { |
| 2081 | logger.Warnw(ctx, "Failed to Marshal OltFlowServiceConfig", log.Fields{"OltFlowServiceConfig": va.OltFlowServiceConfig}) |
| 2082 | return |
| 2083 | } |
| 2084 | _ = db.PutOltFlowService(cntx, string(b)) |
| 2085 | } |
Akash Soni | a824697 | 2023-01-03 10:37:08 +0530 | [diff] [blame] | 2086 | |
Tinoj Joseph | 4ead4e0 | 2023-01-30 03:12:44 +0530 | [diff] [blame] | 2087 | // RestoreOltFlowService to read from the DB and restore olt flow service config |
| 2088 | func (va *VoltApplication) RestoreOltFlowService(cntx context.Context) { |
| 2089 | oltflowService, err := db.GetOltFlowService(cntx) |
| 2090 | if err != nil { |
| 2091 | logger.Warnw(ctx, "Failed to Get OltFlowServiceConfig from DB", log.Fields{"Error": err}) |
| 2092 | return |
| 2093 | } |
| 2094 | err = json.Unmarshal([]byte(oltflowService), &va.OltFlowServiceConfig) |
| 2095 | if err != nil { |
| 2096 | logger.Warn(ctx, "Unmarshal of oltflowService failed") |
| 2097 | return |
| 2098 | } |
| 2099 | logger.Infow(ctx, "updated OltFlowServiceConfig from DB", log.Fields{"OltFlowServiceConfig": va.OltFlowServiceConfig}) |
| 2100 | } |
Tinoj Joseph | 50d722c | 2022-12-06 22:53:22 +0530 | [diff] [blame] | 2101 | |
Akash Soni | 87a1907 | 2023-02-28 00:46:59 +0530 | [diff] [blame] | 2102 | func (va *VoltApplication) UpdateDeviceConfig(cntx context.Context, deviceConfig *DeviceConfig) { |
| 2103 | var dc *DeviceConfig |
| 2104 | va.DevicesConfig.Store(deviceConfig.SerialNumber, deviceConfig) |
| 2105 | err := dc.WriteDeviceConfigToDb(cntx, deviceConfig.SerialNumber, deviceConfig) |
| 2106 | if err != nil { |
| 2107 | logger.Errorw(ctx, "DB update for device config failed", log.Fields{"err": err}) |
Tinoj Joseph | 50d722c | 2022-12-06 22:53:22 +0530 | [diff] [blame] | 2108 | } |
Akash Soni | 87a1907 | 2023-02-28 00:46:59 +0530 | [diff] [blame] | 2109 | logger.Infow(ctx, "Added OLT configurations", log.Fields{"DeviceInfo": deviceConfig}) |
Tinoj Joseph | 50d722c | 2022-12-06 22:53:22 +0530 | [diff] [blame] | 2110 | // If device is already discovered update the VoltDevice structure |
Akash Soni | 87a1907 | 2023-02-28 00:46:59 +0530 | [diff] [blame] | 2111 | device, id := va.GetDeviceBySerialNo(deviceConfig.SerialNumber) |
Tinoj Joseph | 50d722c | 2022-12-06 22:53:22 +0530 | [diff] [blame] | 2112 | if device != nil { |
Akash Soni | 87a1907 | 2023-02-28 00:46:59 +0530 | [diff] [blame] | 2113 | device.NniDhcpTrapVid = of.VlanType(deviceConfig.NniDhcpTrapVid) |
Tinoj Joseph | 50d722c | 2022-12-06 22:53:22 +0530 | [diff] [blame] | 2114 | va.DevicesDisc.Store(id, device) |
| 2115 | } |
| 2116 | } |