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