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