Joey Armstrong | aca03cf | 2024-04-23 09:29:52 -0400 | [diff] [blame] | 1 | /* ----------------------------------------------------------------------- |
| 2 | * Copyright 2022-2024 Open Networking Foundation Contributors |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | * ----------------------------------------------------------------------- |
| 16 | * SPDX-FileCopyrightText: 2022-2024 Open Networking Foundation Contributors |
| 17 | * SPDX-License-Identifier: Apache-2.0 |
| 18 | * ----------------------------------------------------------------------- |
Tinoj Joseph | d5b4f2f | 2022-11-11 19:25:24 +0530 | [diff] [blame] | 19 | */ |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 20 | |
| 21 | package application |
| 22 | |
| 23 | import ( |
| 24 | "bytes" |
Tinoj Joseph | d5b4f2f | 2022-11-11 19:25:24 +0530 | [diff] [blame] | 25 | "context" |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 26 | "encoding/json" |
| 27 | "errors" |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 28 | "fmt" |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 29 | "net" |
| 30 | "reflect" |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 31 | "sort" |
| 32 | "strconv" |
| 33 | "strings" |
| 34 | "sync" |
Tinoj Joseph | d5b4f2f | 2022-11-11 19:25:24 +0530 | [diff] [blame] | 35 | infraerrorCodes "voltha-go-controller/internal/pkg/errorcodes" |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 36 | |
| 37 | "github.com/google/gopacket/layers" |
| 38 | |
Tinoj Joseph | d5b4f2f | 2022-11-11 19:25:24 +0530 | [diff] [blame] | 39 | "voltha-go-controller/database" |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 40 | "voltha-go-controller/internal/pkg/controller" |
| 41 | cntlr "voltha-go-controller/internal/pkg/controller" |
Tinoj Joseph | d5b4f2f | 2022-11-11 19:25:24 +0530 | [diff] [blame] | 42 | errorCodes "voltha-go-controller/internal/pkg/errorcodes" |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 43 | "voltha-go-controller/internal/pkg/of" |
| 44 | "voltha-go-controller/internal/pkg/util" |
Tinoj Joseph | 1d10832 | 2022-07-13 10:07:39 +0530 | [diff] [blame] | 45 | "voltha-go-controller/log" |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 46 | ) |
| 47 | |
| 48 | const ( |
| 49 | // DSLAttrEnabled constant |
| 50 | DSLAttrEnabled string = "ENABLED" |
Tinoj Joseph | ec742f6 | 2022-09-29 19:11:10 +0530 | [diff] [blame] | 51 | // DeviceAny constant |
| 52 | DeviceAny string = "DEVICE-ANY" |
Akash Soni | 634d9bf | 2023-07-10 12:11:10 +0530 | [diff] [blame] | 53 | |
| 54 | ALL_FLOWS_PROVISIONED string = "ALL_FLOWS_PROVISIONED" |
| 55 | |
| 56 | NO_FLOWS_PROVISIONED string = "NO_FLOWS_PROVISIONED" |
| 57 | |
| 58 | FLOWS_PROVISIONED_PARTIALLY string = "FLOWS_PROVISIONED_PARTIALLY" |
| 59 | |
| 60 | SUBSCRIBER_DISABLED_IN_CONTROLLER string = "DISABLED_IN_CONTROLLER" |
| 61 | |
| 62 | SUBSCRIBER_NOT_IN_CONTROLLER string = "NOT_IN_CONTROLLER" |
| 63 | |
| 64 | ONT_FLOWS_PROVISION_STATE_UNUSED string = "ONT_FLOWS_PROVISION_STATE_UNUSED" |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 65 | ) |
| 66 | |
| 67 | // VoltServiceCfg structure |
| 68 | // Name - Uniquely identifies a service across the entire application |
| 69 | // UniVlan - The VLAN of the packets entering the UNI of ONU |
| 70 | // CVlan - The VLAN to transalate to/from on the PON link |
| 71 | // SVlan - The outer VLAN to be used on the NNI of OLT. |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 72 | // - In general, 4096 is used as NO VLAN for all the above |
| 73 | // SVlanTpid - SVlan Tag Protocol Identifier |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 74 | // Pbits - Each bit of uint8 represents one p-bit. MSB is pbit 7 |
| 75 | // DhcpRelay - Whether it is turned on/off |
| 76 | // CircuitId - The circuit id to be used with DHCP relay. Unused otherwise |
| 77 | // RemoveId - Same as above |
| 78 | // Port - The access port for the service. Each service has a single access |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 79 | // port. The converse is not always true |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 80 | // MacLearning - If MAC learning is turned on, the MAC address learned from the |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 81 | // the service activation is used in programming flows |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 82 | // MacAddress - The MAC hardware address learnt on the UNI interface |
| 83 | // MacAddresses - Not yet implemented. To be used to learn more MAC addresses |
| 84 | type VoltServiceCfg struct { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 85 | Pbits []of.PbitType |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 86 | Name string |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 87 | CircuitID string |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 88 | Port string |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 89 | UsMeterProfile string |
| 90 | DsMeterProfile string |
| 91 | AggDsMeterProfile string |
| 92 | VnetID string |
| 93 | MvlanProfileName string |
| 94 | RemoteIDType string |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 95 | DataRateAttr string |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 96 | ServiceType string |
| 97 | DsRemarkPbitsMap map[int]int // Ex: Remark case {0:0,1:0} and No-remark case {1:1} |
| 98 | RemoteID []byte |
| 99 | MacAddr net.HardwareAddr |
| 100 | ONTEtherTypeClassification int |
| 101 | SchedID int |
| 102 | Trigger ServiceTrigger |
| 103 | MacLearning MacLearningType |
| 104 | PonPort uint32 |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 105 | MinDataRateUs uint32 |
| 106 | MinDataRateDs uint32 |
| 107 | MaxDataRateUs uint32 |
| 108 | MaxDataRateDs uint32 |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 109 | TechProfileID uint16 |
| 110 | SVlanTpid layers.EthernetType |
| 111 | UniVlan of.VlanType |
| 112 | CVlan of.VlanType |
| 113 | SVlan of.VlanType |
| 114 | UsPonCTagPriority of.PbitType |
| 115 | UsPonSTagPriority of.PbitType |
| 116 | DsPonSTagPriority of.PbitType |
| 117 | DsPonCTagPriority of.PbitType |
| 118 | VlanControl VlanControl |
Hitesh Chhabra | 9f9a9df | 2023-06-13 17:52:15 +0530 | [diff] [blame] | 119 | IsOption82Enabled bool |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 120 | IgmpEnabled bool |
| 121 | McastService bool |
| 122 | AllowTransparent bool |
| 123 | EnableMulticastKPI bool |
Tinoj Joseph | ec742f6 | 2022-09-29 19:11:10 +0530 | [diff] [blame] | 124 | IsActivated bool |
Sridhar Ravindra | 3ec1423 | 2024-01-01 19:11:48 +0530 | [diff] [blame] | 125 | FlowPushCount map[string]uint32 // Tracks the number of flow install/delete failure attempts per cookie in order to throttle flow auditing |
| 126 | ServiceDeactivateReason SvcDeactivateReason // Mentions why the service was deactivated |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 127 | } |
| 128 | |
| 129 | // VoltServiceOper structure |
| 130 | type VoltServiceOper struct { |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 131 | Metadata interface{} |
| 132 | PendingFlows map[string]bool |
| 133 | AssociatedFlows map[string]bool |
| 134 | BwAvailInfo string |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 135 | //MacLearning bool |
| 136 | //MacAddr net.HardwareAddr |
Hitesh Chhabra | 64be244 | 2023-06-21 17:06:34 +0530 | [diff] [blame] | 137 | Device string |
| 138 | Ipv4Addr net.IP |
| 139 | Ipv6Addr net.IP |
| 140 | ServiceLock sync.RWMutex `json:"-"` |
| 141 | UsMeterID uint32 |
| 142 | DsMeterID uint32 |
| 143 | AggDsMeterID uint32 |
| 144 | UpdateInProgress bool |
| 145 | DeleteInProgress bool |
| 146 | DeactivateInProgress bool |
| 147 | ForceDelete bool |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 148 | // Multiservice-Fix |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 149 | UsHSIAFlowsApplied bool |
| 150 | DsHSIAFlowsApplied bool |
| 151 | UsDhcpFlowsApplied bool |
| 152 | DsDhcpFlowsApplied bool |
| 153 | IgmpFlowsApplied bool |
| 154 | Icmpv6FlowsApplied bool |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 155 | } |
| 156 | |
| 157 | // VoltService structure |
| 158 | type VoltService struct { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 159 | VoltServiceOper |
| 160 | Version string |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 161 | VoltServiceCfg |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 162 | } |
| 163 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 164 | // ServiceTrigger - Service activation trigger |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 165 | type ServiceTrigger int |
| 166 | |
| 167 | const ( |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 168 | // NBActivate - Service added due to NB Action |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 169 | NBActivate ServiceTrigger = 0 |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 170 | // ServiceVlanUpdate - Service added due to Svlan Update |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 171 | ServiceVlanUpdate ServiceTrigger = 1 |
| 172 | ) |
| 173 | |
Sridhar Ravindra | 3ec1423 | 2024-01-01 19:11:48 +0530 | [diff] [blame] | 174 | // SvcDeactivateReason - Reason for service deactivation |
| 175 | type SvcDeactivateReason uint8 |
| 176 | |
| 177 | const ( |
| 178 | // Service deactivated reason - none |
| 179 | SvcDeacRsn_None SvcDeactivateReason = 0 |
| 180 | // Service deactivate reason - NB |
| 181 | SvcDeacRsn_NB SvcDeactivateReason = 1 |
| 182 | // Service deactivate reason - Controller |
| 183 | SvcDeacRsn_Controller SvcDeactivateReason = 2 |
| 184 | ) |
| 185 | |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 186 | // AppMutexes structure |
| 187 | type AppMutexes struct { |
| 188 | ServiceDataMutex sync.Mutex `json:"-"` |
| 189 | VnetMutex sync.Mutex `json:"-"` |
| 190 | } |
| 191 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 192 | // MigrateServiceMetadata - migrate services request metadata |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 193 | type MigrateServiceMetadata struct { |
| 194 | NewVnetID string |
| 195 | RequestID string |
| 196 | } |
| 197 | |
| 198 | // AppMutex variable |
| 199 | var AppMutex AppMutexes |
| 200 | |
| 201 | // NewVoltService for constructor for volt service |
| 202 | func NewVoltService(cfg *VoltServiceCfg) *VoltService { |
| 203 | var vs VoltService |
| 204 | vs.VoltServiceCfg = *cfg |
| 205 | vs.UsHSIAFlowsApplied = false |
| 206 | vs.DsHSIAFlowsApplied = false |
| 207 | vs.DeleteInProgress = false |
Hitesh Chhabra | 64be244 | 2023-06-21 17:06:34 +0530 | [diff] [blame] | 208 | vs.DeactivateInProgress = false |
Sridhar Ravindra | 3ec1423 | 2024-01-01 19:11:48 +0530 | [diff] [blame] | 209 | vs.ServiceDeactivateReason = SvcDeacRsn_None |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 210 | //vs.MacAddr, _ = net.ParseMAC("00:00:00:00:00:00") |
Sridhar Ravindra | 3ec1423 | 2024-01-01 19:11:48 +0530 | [diff] [blame] | 211 | |
Hitesh Chhabra | 9f9a9df | 2023-06-13 17:52:15 +0530 | [diff] [blame] | 212 | vs.IsOption82Enabled = cfg.IsOption82Enabled |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 213 | vs.MacAddr = cfg.MacAddr |
| 214 | vs.Ipv4Addr = net.ParseIP("0.0.0.0") |
| 215 | vs.Ipv6Addr = net.ParseIP("::") |
| 216 | vs.PendingFlows = make(map[string]bool) |
| 217 | vs.AssociatedFlows = make(map[string]bool) |
Sridhar Ravindra | 3ec1423 | 2024-01-01 19:11:48 +0530 | [diff] [blame] | 218 | vs.FlowPushCount = make(map[string]uint32) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 219 | return &vs |
| 220 | } |
| 221 | |
| 222 | // WriteToDb commit a service to the DB if service delete is not in-progress |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 223 | func (vs *VoltService) WriteToDb(cntx context.Context) { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 224 | vs.ServiceLock.RLock() |
| 225 | defer vs.ServiceLock.RUnlock() |
| 226 | |
| 227 | if vs.DeleteInProgress { |
| 228 | logger.Warnw(ctx, "Skipping Redis Update for Service, Service delete in progress", log.Fields{"Service": vs.Name}) |
| 229 | return |
| 230 | } |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 231 | vs.ForceWriteToDb(cntx) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 232 | } |
| 233 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 234 | // ForceWriteToDb force commit a service to the DB |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 235 | func (vs *VoltService) ForceWriteToDb(cntx context.Context) { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 236 | b, err := json.Marshal(vs) |
| 237 | |
| 238 | if err != nil { |
| 239 | logger.Errorw(ctx, "Json Marshal Failed for Service", log.Fields{"Service": vs.Name}) |
| 240 | return |
| 241 | } |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 242 | if err1 := db.PutService(cntx, vs.Name, string(b)); err1 != nil { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 243 | logger.Errorw(ctx, "DB write oper failed for Service", log.Fields{"Service": vs.Name}) |
| 244 | } |
| 245 | } |
| 246 | |
| 247 | // isDataRateAttrPresent to check if data attribute is present |
| 248 | func (vs *VoltService) isDataRateAttrPresent() bool { |
| 249 | return vs.DataRateAttr == DSLAttrEnabled |
| 250 | } |
| 251 | |
| 252 | // DelFromDb delete a service from DB |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 253 | func (vs *VoltService) DelFromDb(cntx context.Context) { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 254 | logger.Debugw(ctx, "Deleting Service from DB", log.Fields{"Name": vs.Name}) |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 255 | // TODO - Need to understand and delete the second call |
| 256 | // Calling twice has worked though don't know why |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 257 | _ = db.DelService(cntx, vs.Name) |
| 258 | _ = db.DelService(cntx, vs.Name) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 259 | } |
| 260 | |
| 261 | // MatchesVlans find the service that matches the VLANs. In this case it is |
| 262 | // purely based on CVLAN. The CVLAN can sufficiently be used to |
| 263 | // match a service |
| 264 | func (vs *VoltService) MatchesVlans(vlans []of.VlanType) bool { |
| 265 | if len(vlans) != 1 { |
| 266 | return false |
| 267 | } |
| 268 | |
| 269 | if vlans[0] == vs.CVlan { |
| 270 | return true |
| 271 | } |
| 272 | return false |
| 273 | } |
| 274 | |
| 275 | // MatchesPbits allows matching a service to a pbit. This is used |
| 276 | // to search for a service matching the pbits, typically to identify |
| 277 | // attributes for other flows such as DHCP, IGMP, etc. |
| 278 | func (vs *VoltService) MatchesPbits(pbits []of.PbitType) bool { |
| 279 | for _, pbit := range pbits { |
| 280 | for _, pb := range vs.Pbits { |
| 281 | if pb == pbit { |
| 282 | return true |
| 283 | } |
| 284 | } |
| 285 | } |
| 286 | return false |
| 287 | } |
| 288 | |
| 289 | // IsPbitExist allows matching a service to a pbit. This is used |
| 290 | // to search for a service matching the pbit |
| 291 | func (vs *VoltService) IsPbitExist(pbit of.PbitType) bool { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 292 | logger.Debugw(ctx, "Request for IsPbitExist", log.Fields{"pbit": pbit}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 293 | for _, pb := range vs.Pbits { |
| 294 | if pb == pbit { |
| 295 | return true |
| 296 | } |
| 297 | } |
| 298 | return false |
| 299 | } |
| 300 | |
| 301 | // AddHsiaFlows - Adds US & DS HSIA Flows for the service |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 302 | func (vs *VoltService) AddHsiaFlows(cntx context.Context) { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 303 | logger.Debugw(ctx, "Add US & DS HSIA Flows for the service", log.Fields{"ServiceName": vs.Name}) |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 304 | if err := vs.AddUsHsiaFlows(cntx); err != nil { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 305 | statusCode, statusMessage := infraerrorCodes.GetErrorInfo(err) |
| 306 | vs.triggerServiceFailureInd(statusCode, statusMessage) |
| 307 | } |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 308 | if err := vs.AddDsHsiaFlows(cntx); err != nil { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 309 | statusCode, statusMessage := infraerrorCodes.GetErrorInfo(err) |
| 310 | vs.triggerServiceFailureInd(statusCode, statusMessage) |
| 311 | } |
| 312 | } |
| 313 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 314 | // DelHsiaFlows - Deletes US & DS HSIA Flows for the service |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 315 | func (vs *VoltService) DelHsiaFlows(cntx context.Context) { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 316 | logger.Debugw(ctx, "Delete US & DS HSIA Flows for the service", log.Fields{"ServiceName": vs.Name}) |
Sridhar Ravindra | 03aa0bf | 2023-09-12 17:46:40 +0530 | [diff] [blame] | 317 | if err := vs.DelUsHsiaFlows(cntx, false); err != nil { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 318 | statusCode, statusMessage := infraerrorCodes.GetErrorInfo(err) |
| 319 | vs.triggerServiceFailureInd(statusCode, statusMessage) |
| 320 | } |
| 321 | |
Sridhar Ravindra | 03aa0bf | 2023-09-12 17:46:40 +0530 | [diff] [blame] | 322 | if err := vs.DelDsHsiaFlows(cntx, false); err != nil { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 323 | statusCode, statusMessage := infraerrorCodes.GetErrorInfo(err) |
| 324 | vs.triggerServiceFailureInd(statusCode, statusMessage) |
| 325 | } |
| 326 | } |
| 327 | |
Tinoj Joseph | 50d722c | 2022-12-06 22:53:22 +0530 | [diff] [blame] | 328 | func (vs *VoltService) AddMeterToDevice(cntx context.Context) error { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 329 | logger.Debugw(ctx, "Add Meter To Device for the service", log.Fields{"ServiceName": vs.Name}) |
Tinoj Joseph | 50d722c | 2022-12-06 22:53:22 +0530 | [diff] [blame] | 330 | if vs.DeleteInProgress || vs.UpdateInProgress { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 331 | logger.Warnw(ctx, "Ignoring Meter Push, Service deleteion In-Progress", log.Fields{"Device": vs.Device, "Service": vs.Name}) |
Tinoj Joseph | 50d722c | 2022-12-06 22:53:22 +0530 | [diff] [blame] | 332 | } |
| 333 | va := GetApplication() |
| 334 | logger.Infow(ctx, "Configuring Meters for FTTB", log.Fields{"ServiceName": vs.Name}) |
| 335 | device, err := va.GetDeviceFromPort(vs.Port) |
| 336 | if err != nil { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 337 | return fmt.Errorf("Error during Getting Device from Port %s for service %s : %w", vs.Port, vs.Name, err) |
Tinoj Joseph | 50d722c | 2022-12-06 22:53:22 +0530 | [diff] [blame] | 338 | } else if device.State != controller.DeviceStateUP { |
| 339 | logger.Warnw(ctx, "Device state Down. Ignoring Meter Push", log.Fields{"Service": vs.Name, "Port": vs.Port}) |
| 340 | return nil |
| 341 | } |
| 342 | va.AddMeterToDevice(vs.Port, device.Name, vs.UsMeterID, 0) |
| 343 | va.AddMeterToDevice(vs.Port, device.Name, vs.DsMeterID, vs.AggDsMeterID) |
| 344 | return nil |
| 345 | } |
| 346 | |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 347 | // AddUsHsiaFlows - Add US HSIA Flows for the service |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 348 | func (vs *VoltService) AddUsHsiaFlows(cntx context.Context) error { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 349 | logger.Infow(ctx, "Configuring US HSIA Service Flows", log.Fields{"Device": vs.Device, "ServiceName": vs.Name}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 350 | if vs.DeleteInProgress || vs.UpdateInProgress { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 351 | logger.Warnw(ctx, "Ignoring US HSIA Flow Push, Service deleteion In-Progress", log.Fields{"Device": vs.Device, "Service": vs.Name}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 352 | return nil |
| 353 | } |
| 354 | |
| 355 | va := GetApplication() |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 356 | if !vs.UsHSIAFlowsApplied || vgcRebooted { |
| 357 | device, err := va.GetDeviceFromPort(vs.Port) |
| 358 | if err != nil { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 359 | return fmt.Errorf("Error Getting Device for Service %s and Port %s : %w", vs.Name, vs.Port, err) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 360 | } else if device.State != controller.DeviceStateUP { |
| 361 | logger.Warnw(ctx, "Device state Down. Ignoring US HSIA Flow Push", log.Fields{"Service": vs.Name, "Port": vs.Port}) |
| 362 | return nil |
| 363 | } |
| 364 | |
| 365 | vs.Device = device.Name |
Tinoj Joseph | 50d722c | 2022-12-06 22:53:22 +0530 | [diff] [blame] | 366 | /* In case of DPU_MGMT_TRAFFIC the meters will be configured before US flow creation*/ |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 367 | if vs.ServiceType != DpuMgmtTraffic { |
Tinoj Joseph | 50d722c | 2022-12-06 22:53:22 +0530 | [diff] [blame] | 368 | va.AddMeterToDevice(vs.Port, device.Name, vs.UsMeterID, 0) |
| 369 | va.AddMeterToDevice(vs.Port, device.Name, vs.DsMeterID, vs.AggDsMeterID) |
| 370 | } |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 371 | pBits := vs.Pbits |
| 372 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 373 | // If no pbits configured for service, hence add PbitNone for flows |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 374 | if len(vs.Pbits) == 0 { |
| 375 | pBits = append(pBits, PbitMatchNone) |
| 376 | } |
| 377 | for _, pbits := range pBits { |
| 378 | usflows, err := vs.BuildUsHsiaFlows(pbits) |
| 379 | if err != nil { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 380 | logger.Errorw(ctx, "Error Building HSIA US flows", log.Fields{"Device": vs.Device, "Service": vs.Name, "Reason": err.Error()}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 381 | statusCode, statusMessage := infraerrorCodes.GetErrorInfo(err) |
| 382 | vs.triggerServiceFailureInd(statusCode, statusMessage) |
| 383 | continue |
| 384 | } |
| 385 | usflows.MigrateCookie = vgcRebooted |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 386 | if err := vs.AddFlows(cntx, device, usflows); err != nil { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 387 | logger.Errorw(ctx, "Error adding HSIA US flows", log.Fields{"Device": vs.Device, "Service": vs.Name, "Reason": err.Error()}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 388 | statusCode, statusMessage := infraerrorCodes.GetErrorInfo(err) |
| 389 | vs.triggerServiceFailureInd(statusCode, statusMessage) |
| 390 | } |
| 391 | } |
| 392 | vs.UsHSIAFlowsApplied = true |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 393 | logger.Debugw(ctx, "Pushed US HSIA Service Flows", log.Fields{"Device": vs.Device, "ServiceName": vs.Name}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 394 | } |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 395 | vs.WriteToDb(cntx) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 396 | return nil |
| 397 | } |
| 398 | |
| 399 | // AddDsHsiaFlows - Add DS HSIA Flows for the service |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 400 | func (vs *VoltService) AddDsHsiaFlows(cntx context.Context) error { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 401 | logger.Infow(ctx, "Configuring DS HSIA Service Flows", log.Fields{"Device": vs.Device, "ServiceName": vs.Name}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 402 | if vs.DeleteInProgress { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 403 | logger.Warnw(ctx, "Ignoring DS HSIA Flow Push, Service deleteion In-Progress", log.Fields{"Device": vs.Device, "Service": vs.Name}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 404 | return nil |
| 405 | } |
| 406 | |
| 407 | va := GetApplication() |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 408 | if !vs.DsHSIAFlowsApplied || vgcRebooted { |
| 409 | device, err := va.GetDeviceFromPort(vs.Port) |
| 410 | if err != nil { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 411 | return fmt.Errorf("Error Getting Device for Service %s and Port %s : %w", vs.Name, vs.Port, err) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 412 | } else if device.State != controller.DeviceStateUP { |
| 413 | logger.Warnw(ctx, "Device state Down. Ignoring DS HSIA Flow Push", log.Fields{"Service": vs.Name, "Port": vs.Port}) |
| 414 | return nil |
| 415 | } |
| 416 | |
| 417 | va.AddMeterToDevice(vs.Port, device.Name, vs.DsMeterID, vs.AggDsMeterID) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 418 | |
| 419 | //If no pbits configured for service, hence add PbitNone for flows |
| 420 | if len(vs.DsRemarkPbitsMap) == 0 { |
| 421 | dsflows, err := vs.BuildDsHsiaFlows(of.PbitType(of.PbitMatchNone)) |
| 422 | if err != nil { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 423 | return fmt.Errorf("Error Building HSIA DS flows for Service %s and Port %s : %w", vs.Name, vs.Port, err) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 424 | } |
| 425 | dsflows.MigrateCookie = vgcRebooted |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 426 | if err = vs.AddFlows(cntx, device, dsflows); err != nil { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 427 | logger.Errorw(ctx, "Failed to add HSIA DS flows", log.Fields{"Device": vs.Device, "Service": vs.Name, "Reason": err}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 428 | statusCode, statusMessage := infraerrorCodes.GetErrorInfo(err) |
| 429 | vs.triggerServiceFailureInd(statusCode, statusMessage) |
| 430 | } |
| 431 | } else { |
| 432 | // if all 8 p-bits are to be remarked to one-pbit, configure all-to-one remarking flow |
| 433 | if _, ok := vs.DsRemarkPbitsMap[int(of.PbitMatchAll)]; ok { |
| 434 | dsflows, err := vs.BuildDsHsiaFlows(of.PbitType(of.PbitMatchAll)) |
| 435 | if err != nil { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 436 | return fmt.Errorf("Error Building HSIA DS flows for Service %s and Port %s : %w", vs.Name, vs.Port, err) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 437 | } |
| 438 | logger.Debug(ctx, "Add-one-match-all-pbit-flow") |
| 439 | dsflows.MigrateCookie = vgcRebooted |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 440 | if err := vs.AddFlows(cntx, device, dsflows); err != nil { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 441 | logger.Errorw(ctx, "Failed to add HSIA DS flows", log.Fields{"Device": vs.Device, "Service": vs.Name, "Reason": err}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 442 | statusCode, statusMessage := infraerrorCodes.GetErrorInfo(err) |
| 443 | vs.triggerServiceFailureInd(statusCode, statusMessage) |
| 444 | } |
| 445 | } else { |
| 446 | for matchPbit := range vs.DsRemarkPbitsMap { |
| 447 | dsflows, err := vs.BuildDsHsiaFlows(of.PbitType(matchPbit)) |
| 448 | if err != nil { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 449 | logger.Errorw(ctx, "Error Building HSIA DS flows", log.Fields{"Device": vs.Device, "Service": vs.Name, "Reason": err.Error()}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 450 | statusCode, statusMessage := infraerrorCodes.GetErrorInfo(err) |
| 451 | vs.triggerServiceFailureInd(statusCode, statusMessage) |
| 452 | continue |
| 453 | } |
| 454 | dsflows.MigrateCookie = vgcRebooted |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 455 | if err := vs.AddFlows(cntx, device, dsflows); err != nil { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 456 | logger.Errorw(ctx, "Failed to Add HSIA DS flows", log.Fields{"Device": vs.Device, "Service": vs.Name, "Reason": err}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 457 | statusCode, statusMessage := infraerrorCodes.GetErrorInfo(err) |
| 458 | vs.triggerServiceFailureInd(statusCode, statusMessage) |
| 459 | } |
| 460 | } |
| 461 | } |
| 462 | } |
| 463 | vs.DsHSIAFlowsApplied = true |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 464 | logger.Debugw(ctx, "Pushed DS HSIA Service Flows", log.Fields{"Device": vs.Device, "ServiceName": vs.Name}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 465 | } |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 466 | vs.WriteToDb(cntx) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 467 | return nil |
| 468 | } |
| 469 | |
| 470 | // DelUsHsiaFlows - Deletes US HSIA Flows for the service |
Sridhar Ravindra | 03aa0bf | 2023-09-12 17:46:40 +0530 | [diff] [blame] | 471 | func (vs *VoltService) DelUsHsiaFlows(cntx context.Context, delFlowsInDevice bool) error { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 472 | logger.Infow(ctx, "Removing US HSIA Services", log.Fields{"Device": vs.Device, "ServiceName": vs.Name}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 473 | if vs.UsHSIAFlowsApplied || vgcRebooted { |
| 474 | device, err := GetApplication().GetDeviceFromPort(vs.Port) |
| 475 | if err != nil { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 476 | return fmt.Errorf("Error Getting Device for Service %s and Port %s : %w", vs.Name, vs.Port, err) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 477 | } |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 478 | pBits := vs.Pbits |
| 479 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 480 | // If no pbits configured for service, hence add PbitNone for flows |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 481 | if len(vs.Pbits) == 0 { |
| 482 | pBits = append(pBits, PbitMatchNone) |
| 483 | } |
| 484 | for _, pbits := range pBits { |
| 485 | usflows, err := vs.BuildUsHsiaFlows(pbits) |
| 486 | if err != nil { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 487 | logger.Errorw(ctx, "Error Building HSIA US flows", log.Fields{"Device": vs.Device, "ServiceName": vs.Name, "Reason": err.Error()}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 488 | statusCode, statusMessage := infraerrorCodes.GetErrorInfo(err) |
| 489 | vs.triggerServiceFailureInd(statusCode, statusMessage) |
| 490 | continue |
| 491 | } |
| 492 | usflows.MigrateCookie = vgcRebooted |
Sridhar Ravindra | 03aa0bf | 2023-09-12 17:46:40 +0530 | [diff] [blame] | 493 | if err = vs.DelFlows(cntx, device, usflows, delFlowsInDevice); err != nil { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 494 | logger.Errorw(ctx, "Error Deleting HSIA US flows", log.Fields{"Device": vs.Device, "ServiceName": vs.Name, "Reason": err.Error()}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 495 | statusCode, statusMessage := infraerrorCodes.GetErrorInfo(err) |
| 496 | vs.triggerServiceFailureInd(statusCode, statusMessage) |
| 497 | } |
| 498 | } |
| 499 | vs.UsHSIAFlowsApplied = false |
| 500 | } |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 501 | vs.WriteToDb(cntx) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 502 | return nil |
| 503 | } |
| 504 | |
| 505 | // DelDsHsiaFlows - Deletes DS HSIA Flows for the service |
Sridhar Ravindra | 03aa0bf | 2023-09-12 17:46:40 +0530 | [diff] [blame] | 506 | func (vs *VoltService) DelDsHsiaFlows(cntx context.Context, delFlowsInDevice bool) error { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 507 | logger.Infow(ctx, "Removing DS HSIA Services", log.Fields{"Device": vs.Device, "ServiceName": vs.Name}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 508 | if vs.DsHSIAFlowsApplied || vgcRebooted { |
| 509 | device, err := GetApplication().GetDeviceFromPort(vs.Port) |
| 510 | if err != nil { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 511 | return fmt.Errorf("Error Getting Device for Service %s and Port %s : %w", vs.Name, vs.Port, err) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 512 | } |
| 513 | |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 514 | var matchPbit int |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 515 | // If no pbits configured for service, hence add PbitNone for flows |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 516 | if len(vs.DsRemarkPbitsMap) == 0 { |
| 517 | dsflows, err := vs.BuildDsHsiaFlows(of.PbitType(PbitMatchNone)) |
| 518 | if err != nil { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 519 | return fmt.Errorf("Error Building HSIA DS flows for Service %s and Port %s : %w", vs.Name, vs.Port, err) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 520 | } |
| 521 | dsflows.MigrateCookie = vgcRebooted |
Sridhar Ravindra | 03aa0bf | 2023-09-12 17:46:40 +0530 | [diff] [blame] | 522 | if err = vs.DelFlows(cntx, device, dsflows, delFlowsInDevice); err != nil { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 523 | logger.Errorw(ctx, "Error Deleting HSIA DS flows", log.Fields{"Device": vs.Device, "ServiceName": vs.Name, "Reason": err.Error()}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 524 | statusCode, statusMessage := infraerrorCodes.GetErrorInfo(err) |
| 525 | vs.triggerServiceFailureInd(statusCode, statusMessage) |
| 526 | } |
| 527 | } else if _, ok := vs.DsRemarkPbitsMap[int(PbitMatchAll)]; ok { |
| 528 | dsflows, err := vs.BuildDsHsiaFlows(of.PbitType(int(PbitMatchAll))) |
| 529 | if err != nil { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 530 | return fmt.Errorf("Error Building HSIA DS flows for Service %s and Port %s : %w", vs.Name, vs.Port, err) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 531 | } |
| 532 | dsflows.MigrateCookie = vgcRebooted |
Sridhar Ravindra | 03aa0bf | 2023-09-12 17:46:40 +0530 | [diff] [blame] | 533 | if err = vs.DelFlows(cntx, device, dsflows, delFlowsInDevice); err != nil { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 534 | logger.Errorw(ctx, "Error Deleting HSIA DS flows", log.Fields{"Device": vs.Device, "ServiceName": vs.Name, "Reason": err.Error()}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 535 | statusCode, statusMessage := infraerrorCodes.GetErrorInfo(err) |
| 536 | vs.triggerServiceFailureInd(statusCode, statusMessage) |
| 537 | } |
| 538 | } else { |
| 539 | for matchPbit = range vs.DsRemarkPbitsMap { |
| 540 | dsflows, err := vs.BuildDsHsiaFlows(of.PbitType(matchPbit)) |
| 541 | if err != nil { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 542 | logger.Errorw(ctx, "Error Building HSIA DS flows", log.Fields{"Device": vs.Device, "ServiceName": vs.Name, "Reason": err.Error()}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 543 | statusCode, statusMessage := infraerrorCodes.GetErrorInfo(err) |
| 544 | vs.triggerServiceFailureInd(statusCode, statusMessage) |
| 545 | continue |
| 546 | } |
| 547 | dsflows.MigrateCookie = vgcRebooted |
Sridhar Ravindra | 03aa0bf | 2023-09-12 17:46:40 +0530 | [diff] [blame] | 548 | if err = vs.DelFlows(cntx, device, dsflows, delFlowsInDevice); err != nil { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 549 | logger.Errorw(ctx, "Error Deleting HSIA DS flows", log.Fields{"Device": vs.Device, "ServiceName": vs.Name, "Reason": err.Error()}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 550 | statusCode, statusMessage := infraerrorCodes.GetErrorInfo(err) |
| 551 | vs.triggerServiceFailureInd(statusCode, statusMessage) |
| 552 | } |
| 553 | } |
| 554 | } |
| 555 | vs.DsHSIAFlowsApplied = false |
| 556 | } |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 557 | logger.Infow(ctx, "Deleted HSIA DS flows from DB successfully", log.Fields{"Device": vs.Device, "ServiceName": vs.Name}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 558 | // Post HSIA configuration success indication on message bus |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 559 | vs.WriteToDb(cntx) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 560 | return nil |
| 561 | } |
| 562 | |
| 563 | // BuildDsHsiaFlows build the DS HSIA flows |
| 564 | // Called for add/delete HSIA flows |
| 565 | func (vs *VoltService) BuildDsHsiaFlows(pbits of.PbitType) (*of.VoltFlow, error) { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 566 | logger.Debugw(ctx, "Building DS HSIA Service Flows", log.Fields{"Device": vs.Device, "ServiceName": vs.Name}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 567 | flow := &of.VoltFlow{} |
| 568 | flow.SubFlows = make(map[uint64]*of.VoltSubFlow) |
| 569 | |
| 570 | // Get the out and in ports for the flows |
| 571 | device, err := GetApplication().GetDeviceFromPort(vs.Port) |
| 572 | if err != nil { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 573 | return nil, fmt.Errorf("Error Getting Device for Service %s and Port %s : %w", vs.Name, vs.Port, err) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 574 | } |
| 575 | inport, _ := GetApplication().GetPortID(device.NniPort) |
| 576 | outport, _ := GetApplication().GetPortID(vs.Port) |
| 577 | // PortName and PortID to be used for validation of port before flow pushing |
| 578 | flow.PortID = outport |
| 579 | flow.PortName = vs.Port |
| 580 | allowTransparent := 0 |
| 581 | if vs.AllowTransparent { |
| 582 | allowTransparent = 1 |
| 583 | } |
| 584 | |
| 585 | // initialized actnPbit to 0 for cookie genration backward compatibility. |
| 586 | var actnPbit of.PbitType |
| 587 | remarkPbit, remarkExists := vs.DsRemarkPbitsMap[int(pbits)] |
| 588 | |
| 589 | generateDSCookie := func(vlan of.VlanType, valToShift uint64) uint64 { |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 590 | // | 12-bit cvlan/UniVlan | 4 bits action pbit | <32-bits uniport>| 16-bits HSIA mask OR flow mask OR pbit | |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 591 | cookie := uint64(vlan)<<52 + uint64(actnPbit)<<48 + uint64(outport)<<16 | of.HsiaFlowMask |
| 592 | cookie = cookie | of.DsFlowMask |
| 593 | cookie = cookie + (valToShift << 4) + uint64(pbits) |
| 594 | return cookie |
| 595 | } |
| 596 | |
| 597 | l2ProtoValue, err := GetMetadataForL2Protocol(vs.SVlanTpid) |
| 598 | if err != nil { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 599 | return nil, fmt.Errorf("DS HSIA flow push failed: Invalid SvlanTpid for Service %s and SvlanTpid %s : %w", vs.SVlanTpid, vs.Port, err) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 600 | } |
| 601 | |
| 602 | // Add Table-0 flow that deals with the outer VLAN in pOLT |
| 603 | { |
| 604 | subflow1 := of.NewVoltSubFlow() |
| 605 | subflow1.SetTableID(0) |
| 606 | subflow1.SetGoToTable(1) |
| 607 | subflow1.SetInPort(inport) |
| 608 | |
| 609 | if pbits != PbitMatchNone { |
| 610 | subflow1.SetMatchPbit(pbits) |
| 611 | } |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 612 | if remarkExists && (of.PbitType(remarkPbit) != pbits) { |
| 613 | subflow1.SetPcp(of.PbitType(remarkPbit)) |
| 614 | // match & action pbits are different, set remark-pbit action |
| 615 | actnPbit = of.PbitType(remarkPbit) |
| 616 | // mask remark p-bit to 4bits |
| 617 | actnPbit = actnPbit & 0x0F |
| 618 | } |
| 619 | |
| 620 | if err := vs.setDSMatchActionVlanT0(subflow1); err != nil { |
| 621 | return nil, err |
| 622 | } |
Tinoj Joseph | 1d10832 | 2022-07-13 10:07:39 +0530 | [diff] [blame] | 623 | logger.Infow(ctx, "HSIA DS flows MAC Learning & MAC", log.Fields{"ML": vs.MacLearning, "Mac": vs.MacAddr}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 624 | if NonZeroMacAddress(vs.MacAddr) { |
| 625 | subflow1.SetMatchDstMac(vs.MacAddr) |
| 626 | } |
| 627 | subflow1.Priority = of.HsiaFlowPriority |
| 628 | subflow1.SetMeterID(vs.DsMeterID) |
| 629 | |
| 630 | /* WriteMetaData 8 Byte(uint64) usage: |
| 631 | | Byte8 | Byte7 | Byte6 | Byte5 | Byte4 | Byte3 | Byte2 | Byte1 | |
| 632 | | reserved | reserved | TpID | TpID | uinID | uniID | uniID | uniID | */ |
| 633 | metadata := uint64(vs.CVlan)<<48 + uint64(vs.TechProfileID)<<32 + uint64(outport) |
Sridhar Ravindra | b8374ae | 2023-04-14 15:49:25 +0530 | [diff] [blame] | 634 | if vs.ServiceType == FttbSubscriberTraffic { |
| 635 | metadata = uint64(of.VlanAny)<<48 + uint64(vs.TechProfileID)<<32 + uint64(outport) |
| 636 | } |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 637 | subflow1.SetWriteMetadata(metadata) |
| 638 | |
| 639 | /* TableMetaData 8 Byte(uint64) Voltha usage: (Considering MSB bit as 63rd bit and LSB bit as 0th bit) |
| 640 | | Byte8 | Byte7 | Byte6 | Byte5 | Byte4 | Byte3 | Byte2 | Byte1 | |
| 641 | | 0000 | 00 | 0 | 0 | 00000000 | 00000000 | 0000 0000 | 00000000 | 00000000 | 00000000 | 00000000| |
| 642 | | reserved | svlanTpID | Buff us | AT | schedID | schedID | onteth vlanCtrl | unitag | unitag | ctag | ctag | */ |
| 643 | |
| 644 | //TODO-COMM: |
| 645 | /* TableMetaData 8 Byte(uint64) Community usage: (Considering MSB bit as 63rd bit and LSB bit as 0th bit) |
| 646 | | Byte8 | Byte7 | Byte6 | Byte5 | Byte4 | Byte3 | Byte2 | Byte1 | |
| 647 | | 0000 | 00 | 0 | 0 | 00000000 | 00000000 | 0000 0000 | 00000000 | 00000000 | 00000000 | 00000000| |
| 648 | | reserved | svlanTpID | Buff us | AT | schedID | schedID | onteth vlanCtrl | ctag | ctag | ctag | ctag | */ |
| 649 | |
Sridhar Ravindra | b8374ae | 2023-04-14 15:49:25 +0530 | [diff] [blame] | 650 | if vs.ServiceType != FttbSubscriberTraffic { |
| 651 | metadata = uint64(l2ProtoValue)<<58 | uint64(allowTransparent)<<56 | uint64(vs.SchedID)<<40 | uint64(vs.ONTEtherTypeClassification)<<36 | uint64(vs.VlanControl)<<32 | uint64(vs.CVlan) |
| 652 | subflow1.SetTableMetadata(metadata) |
| 653 | } |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 654 | // TODO - We are using cookie as key and must come up with better cookie |
| 655 | // allocation algorithm |
| 656 | /** |
| 657 | * Cokies may clash when - |
| 658 | * on same uni-port we have two sub-service |
| 659 | * 1. U=10, C=100, S=310, p-bit=4 - VLAN_Control = OLT_CVLAN_OLT_SVLAN |
| 660 | * 2. U=10, C=10, S=320, p-bit=4 - VLAN_control = ONU_CVLAN_ONU_SVLAN |
| 661 | * However, this p-bit re-use will not be allowed by sub-mgr. |
| 662 | */ |
| 663 | if vs.VlanControl == OLTCVlanOLTSVlan { |
| 664 | /** |
| 665 | * The new cookie generation is only for OLT_CVLAN_OLT_SVLAN case (TEF residential case) within a UNI. |
| 666 | * After vgc upgrade, if we have to deactivate an already existing TEF residential service, then we have to |
| 667 | * use old cookie. |
| 668 | */ |
| 669 | subflow1.Cookie = generateDSCookie(vs.UniVlan, 0) |
| 670 | if vgcRebooted { |
| 671 | subflow1.OldCookie = generateDSCookie(vs.CVlan, 0) |
| 672 | } |
| 673 | } else { |
| 674 | // In case of Olt_Svlan , CVLAN=UNIVLAN so cookie can be constructed with CVLAN as well |
| 675 | subflow1.Cookie = generateDSCookie(vs.CVlan, 0) |
| 676 | } |
| 677 | |
| 678 | flow.SubFlows[subflow1.Cookie] = subflow1 |
| 679 | logger.Infow(ctx, "Building downstream HSIA flow for T0", log.Fields{"cookie": subflow1.Cookie, |
| 680 | "subflow": subflow1}) |
| 681 | } |
| 682 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 683 | // Add Table-1 flow that deals with inner VLAN at the ONU |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 684 | { |
| 685 | subflow2 := of.NewVoltSubFlow() |
| 686 | subflow2.SetTableID(1) |
| 687 | subflow2.SetInPort(inport) |
| 688 | if NonZeroMacAddress(vs.MacAddr) { |
| 689 | subflow2.SetMatchDstMac(vs.MacAddr) |
| 690 | } |
| 691 | |
| 692 | if err := vs.setDSMatchActionVlanT1(subflow2); err != nil { |
| 693 | return nil, err |
| 694 | } |
| 695 | if pbits != PbitMatchNone { |
| 696 | subflow2.SetMatchPbit(pbits) |
| 697 | } |
| 698 | |
| 699 | if remarkExists && (of.PbitType(remarkPbit) != pbits) { |
| 700 | subflow2.SetPcp(of.PbitType(remarkPbit)) |
| 701 | } |
| 702 | |
| 703 | subflow2.SetOutPort(outport) |
| 704 | subflow2.SetMeterID(vs.DsMeterID) |
| 705 | |
| 706 | // refer Table-0 flow generation for byte information |
| 707 | metadata := uint64(vs.CVlan)<<48 + uint64(vs.TechProfileID)<<32 + uint64(outport) |
Sridhar Ravindra | b8374ae | 2023-04-14 15:49:25 +0530 | [diff] [blame] | 708 | if vs.ServiceType == FttbSubscriberTraffic { |
| 709 | metadata = uint64(of.VlanAny)<<48 + uint64(vs.TechProfileID)<<32 + uint64(outport) |
| 710 | } |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 711 | subflow2.SetWriteMetadata(metadata) |
| 712 | |
| 713 | // Table-1 and inport is NNI: It is a DS flow for ONU, add uniport in metadata to make it unique |
| 714 | if util.IsNniPort(inport) { |
| 715 | metadata = uint64(outport) |
| 716 | } else { |
| 717 | // refer Table-0 flow generation for byte information |
| 718 | metadata = uint64(l2ProtoValue)<<58 | uint64(allowTransparent)<<56 | uint64(vs.SchedID)<<40 | uint64(vs.ONTEtherTypeClassification)<<36 | uint64(vs.VlanControl)<<32 | uint64(vs.CVlan) |
| 719 | } |
| 720 | subflow2.SetTableMetadata(metadata) |
| 721 | // Setting of Cookie - TODO - Improve the allocation algorithm |
| 722 | if vs.VlanControl == OLTCVlanOLTSVlan { |
| 723 | /** |
| 724 | * The new cookie generation is only for OLT_CVLAN_OLT_SVLAN case (TEF residential case) within a UNI. |
| 725 | * After vgc upgrade, if we have to deactivate an already existing TEF residential service, then we have to |
| 726 | * use old cookie. |
| 727 | */ |
| 728 | subflow2.Cookie = generateDSCookie(vs.UniVlan, 1) |
| 729 | if vgcRebooted { |
| 730 | subflow2.OldCookie = generateDSCookie(vs.CVlan, 1) |
| 731 | } |
| 732 | } else { |
| 733 | // In case of Olt_Svlan , CVLAN=UNIVLAN so cookie can be constructed with CVLAN as well |
| 734 | subflow2.Cookie = generateDSCookie(vs.CVlan, 1) |
| 735 | } |
| 736 | |
| 737 | subflow2.Priority = of.HsiaFlowPriority |
| 738 | flow.SubFlows[subflow2.Cookie] = subflow2 |
| 739 | logger.Infow(ctx, "Building downstream HSIA flow for T1", log.Fields{"cookie": subflow2.Cookie, |
| 740 | "subflow": subflow2}) |
| 741 | } |
| 742 | |
| 743 | return flow, nil |
| 744 | } |
| 745 | |
| 746 | // BuildUsHsiaFlows build the US HSIA flows |
| 747 | // Called for add/delete HSIA flows |
| 748 | func (vs *VoltService) BuildUsHsiaFlows(pbits of.PbitType) (*of.VoltFlow, error) { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 749 | logger.Debugw(ctx, "Building US HSIA Service Flows", log.Fields{"Device": vs.Device, "ServiceName": vs.Name}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 750 | flow := &of.VoltFlow{} |
| 751 | flow.SubFlows = make(map[uint64]*of.VoltSubFlow) |
| 752 | |
| 753 | // Get the out and in ports for the flows |
| 754 | device, err := GetApplication().GetDeviceFromPort(vs.Port) |
| 755 | if err != nil { |
| 756 | return nil, errorCodes.ErrDeviceNotFound |
| 757 | } |
| 758 | outport, _ := GetApplication().GetPortID(device.NniPort) |
| 759 | inport, _ := GetApplication().GetPortID(vs.Port) |
| 760 | // PortName and PortID to be used for validation of port before flow pushing |
| 761 | flow.PortID = inport |
| 762 | flow.PortName = vs.Port |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 763 | |
| 764 | // Add Table-0 flow that deals with the inner VLAN in ONU |
| 765 | { |
| 766 | subflow1 := of.NewVoltSubFlow() |
| 767 | subflow1.SetTableID(0) |
| 768 | subflow1.SetGoToTable(1) |
| 769 | subflow1.SetInPort(inport) |
| 770 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 771 | if vs.ServiceType == DpuMgmtTraffic { |
Tinoj Joseph | 50d722c | 2022-12-06 22:53:22 +0530 | [diff] [blame] | 772 | subflow1.SetMatchPbit(vs.UsPonCTagPriority) |
| 773 | subflow1.SetPcp(vs.UsPonSTagPriority) |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 774 | } else if vs.ServiceType == DpuAncpTraffic { |
Tinoj Joseph | 50d722c | 2022-12-06 22:53:22 +0530 | [diff] [blame] | 775 | subflow1.SetPcp(vs.UsPonSTagPriority) |
| 776 | } |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 777 | if err := vs.setUSMatchActionVlanT0(subflow1); err != nil { |
| 778 | return nil, err |
| 779 | } |
| 780 | subflow1.SetMeterID(vs.UsMeterID) |
| 781 | |
Tinoj Joseph | 50d722c | 2022-12-06 22:53:22 +0530 | [diff] [blame] | 782 | /* WriteMetaData 8 Byte(uint64) usage: |
| 783 | | Byte8 | Byte7 | Byte6 | Byte5 | Byte4 | Byte3 | Byte2 | Byte1 | |
| 784 | | reserved | reserved | TpID | TpID | uinID | uniID | uniID | uniID | */ |
| 785 | //metadata := uint64(vs.CVlan)<<48 + uint64(vs.TechProfileID)<<32 + uint64(outport) |
| 786 | metadata := uint64(vs.TechProfileID)<<32 + uint64(outport) |
Sridhar Ravindra | b8374ae | 2023-04-14 15:49:25 +0530 | [diff] [blame] | 787 | if vs.ServiceType == FttbSubscriberTraffic { |
| 788 | metadata = uint64(of.VlanAny)<<48 + uint64(vs.TechProfileID)<<32 + uint64(outport) |
| 789 | } |
Tinoj Joseph | 50d722c | 2022-12-06 22:53:22 +0530 | [diff] [blame] | 790 | subflow1.SetWriteMetadata(metadata) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 791 | |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 792 | if vs.VlanControl == OLTCVlanOLTSVlan { |
| 793 | /** |
| 794 | * The new cookie generation is only for OLT_CVLAN_OLT_SVLAN case (TEF residential case) within a UNI. |
| 795 | * After vgc upgrade, if we have to deactivate an already existing TEF residential service, then we have to |
| 796 | * use old cookie. |
| 797 | */ |
| 798 | subflow1.Cookie = vs.generateUSCookie(vs.UniVlan, 0, inport, pbits) |
| 799 | if vgcRebooted { |
| 800 | subflow1.OldCookie = vs.generateUSCookie(vs.CVlan, 0, inport, pbits) |
| 801 | } |
| 802 | } else { |
| 803 | // In case of Olt_Svlan , CVLAN=UNIVLAN so cookie can be constructed with CVLAN as well |
| 804 | subflow1.Cookie = vs.generateUSCookie(vs.CVlan, 0, inport, pbits) |
| 805 | } |
| 806 | subflow1.Priority = of.HsiaFlowPriority |
| 807 | flow.SubFlows[subflow1.Cookie] = subflow1 |
| 808 | logger.Infow(ctx, "Building upstream HSIA flow for T0", log.Fields{"cookie": subflow1.Cookie, "subflow": subflow1}) |
| 809 | } |
| 810 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 811 | // Add Table-1 flow that deals with the outer vlan in pOLT |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 812 | { |
| 813 | subflow2 := of.NewVoltSubFlow() |
| 814 | subflow2.SetTableID(1) |
| 815 | subflow2.SetInPort(inport) |
| 816 | |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 817 | if err := vs.setUSMatchActionVlanT1(subflow2); err != nil { |
| 818 | return nil, err |
| 819 | } |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 820 | if vs.ServiceType == DpuMgmtTraffic { |
Tinoj Joseph | 50d722c | 2022-12-06 22:53:22 +0530 | [diff] [blame] | 821 | subflow2.SetMatchSrcMac(vs.MacAddr) |
| 822 | } |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 823 | subflow2.SetInPort(inport) |
| 824 | subflow2.SetOutPort(outport) |
| 825 | subflow2.SetMeterID(vs.UsMeterID) |
| 826 | |
Tinoj Joseph | 50d722c | 2022-12-06 22:53:22 +0530 | [diff] [blame] | 827 | // refer Table-0 flow generation for byte information |
| 828 | metadata := uint64(vs.TechProfileID)<<32 + uint64(outport) |
Sridhar Ravindra | b8374ae | 2023-04-14 15:49:25 +0530 | [diff] [blame] | 829 | if vs.ServiceType == FttbSubscriberTraffic { |
| 830 | metadata = uint64(of.VlanAny)<<48 + uint64(vs.TechProfileID)<<32 + uint64(outport) |
| 831 | } |
Tinoj Joseph | 50d722c | 2022-12-06 22:53:22 +0530 | [diff] [blame] | 832 | subflow2.SetWriteMetadata(metadata) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 833 | |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 834 | if vs.VlanControl == OLTCVlanOLTSVlan { |
| 835 | /** |
| 836 | * The new cookie generation is only for OLT_CVLAN_OLT_SVLAN case (TEF residential case) within a UNI. |
| 837 | * After vgc upgrade, if we have to deactivate an already existing TEF residential service, then we have to |
| 838 | * use old cookie. |
| 839 | */ |
| 840 | subflow2.Cookie = vs.generateUSCookie(vs.UniVlan, 1, inport, pbits) |
| 841 | if vgcRebooted { |
| 842 | subflow2.OldCookie = vs.generateUSCookie(vs.CVlan, 1, inport, pbits) |
| 843 | } |
| 844 | } else { |
| 845 | // In case of Olt_Svlan , CVLAN=UNIVLAN so cookie can be constructed with CVLAN as well |
| 846 | subflow2.Cookie = vs.generateUSCookie(vs.CVlan, 1, inport, pbits) |
| 847 | } |
| 848 | subflow2.Priority = of.HsiaFlowPriority |
| 849 | |
| 850 | flow.SubFlows[subflow2.Cookie] = subflow2 |
| 851 | logger.Infow(ctx, "Building upstream HSIA flow for T1", log.Fields{"cookie": subflow2.Cookie, "subflow": subflow2}) |
| 852 | } |
| 853 | |
| 854 | return flow, nil |
| 855 | } |
| 856 | |
| 857 | func (vs *VoltService) generateUSCookie(vlan of.VlanType, valToShift uint64, inport uint32, pbits of.PbitType) uint64 { |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 858 | // | 12-bit cvlan/UniVlan | 4 bits empty | <32-bits uniport>| 16-bits HSIA mask OR flow mask OR pbit | |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 859 | logger.Debugw(ctx, "Generate US Cookie", log.Fields{"Vlan": vlan, "ValToShift": vlan, "Inport": inport, "Pbits": pbits}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 860 | cookie := uint64(vlan)<<52 + uint64(inport)<<16 | of.HsiaFlowMask |
| 861 | cookie = cookie | of.UsFlowMask |
| 862 | cookie = cookie + (valToShift << 4) + uint64(pbits) |
| 863 | return cookie |
| 864 | } |
| 865 | |
| 866 | // setUSMatchActionVlanT1 - Sets the Match & Action w.r.t Vlans for US Table-1 |
| 867 | // based on different Vlan Controls |
| 868 | func (vs *VoltService) setUSMatchActionVlanT1(flow *of.VoltSubFlow) error { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 869 | logger.Debugw(ctx, "Set US Match Action Vlan T1", log.Fields{"Value": vs.VlanControl}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 870 | switch vs.VlanControl { |
| 871 | case None: |
| 872 | flow.SetMatchVlan(vs.SVlan) |
| 873 | case ONUCVlanOLTSVlan: |
| 874 | flow.SetMatchVlan(vs.CVlan) |
| 875 | flow.SetPushVlan(vs.SVlan, vs.SVlanTpid) |
| 876 | case OLTCVlanOLTSVlan: |
| 877 | flow.SetMatchVlan(vs.UniVlan) |
| 878 | flow.SetSetVlan(vs.CVlan) |
| 879 | flow.SetPushVlan(vs.SVlan, vs.SVlanTpid) |
| 880 | case ONUCVlan: |
| 881 | flow.SetMatchVlan(vs.SVlan) |
| 882 | case OLTSVlan: |
| 883 | if vs.UniVlan != of.VlanAny && vs.UniVlan != of.VlanNone { |
| 884 | flow.SetMatchVlan(vs.UniVlan) |
| 885 | flow.SetSetVlan(vs.SVlan) |
| 886 | } else if vs.UniVlan != of.VlanNone { |
| 887 | flow.SetMatchVlan(vs.UniVlan) |
| 888 | flow.SetPushVlan(vs.SVlan, layers.EthernetTypeDot1Q) |
| 889 | } else { |
| 890 | flow.SetPushVlan(vs.SVlan, layers.EthernetTypeDot1Q) |
| 891 | } |
| 892 | default: |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 893 | err := errorCodes.ErrInvalidParamInRequest |
| 894 | return fmt.Errorf("Invalid Vlan Control Option %d : %w", vs.VlanControl, err) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 895 | } |
| 896 | return nil |
| 897 | } |
| 898 | |
| 899 | // setDSMatchActionVlanT0 - Sets the Match & Action w.r.t Vlans for DS Table-0 |
| 900 | // based on different Vlan Controls |
| 901 | func (vs *VoltService) setDSMatchActionVlanT0(flow *of.VoltSubFlow) error { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 902 | logger.Debugw(ctx, "Set DS Match Action Vlan T0", log.Fields{"Value": vs.VlanControl}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 903 | switch vs.VlanControl { |
| 904 | case None: |
| 905 | flow.SetMatchVlan(vs.SVlan) |
| 906 | case ONUCVlanOLTSVlan: |
| 907 | flow.SetMatchVlan(vs.SVlan) |
| 908 | flow.SetPopVlan() |
| 909 | case OLTCVlanOLTSVlan: |
| 910 | flow.SetMatchVlan(vs.SVlan) |
| 911 | flow.SetPopVlan() |
| 912 | flow.SetSetVlan(vs.UniVlan) |
| 913 | case ONUCVlan: |
| 914 | flow.SetMatchVlan(vs.SVlan) |
| 915 | case OLTSVlan: |
| 916 | flow.SetMatchVlan(vs.SVlan) |
| 917 | if vs.UniVlan != of.VlanNone && vs.UniVlan != of.VlanAny { |
| 918 | flow.SetSetVlan(vs.UniVlan) |
| 919 | } else { |
| 920 | flow.SetPopVlan() |
| 921 | } |
| 922 | default: |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 923 | err := errorCodes.ErrInvalidParamInRequest |
| 924 | return fmt.Errorf("Invalid Vlan Control Option %d : %w", vs.VlanControl, err) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 925 | } |
| 926 | return nil |
| 927 | } |
| 928 | |
| 929 | // setUSMatchActionVlanT0 - Sets the Match & Action w.r.t Vlans for US Table-0 |
| 930 | // based on different Vlan Controls |
| 931 | func (vs *VoltService) setUSMatchActionVlanT0(flow *of.VoltSubFlow) error { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 932 | logger.Debugw(ctx, "Set US Match Action Vlan T0", log.Fields{"Value": vs.VlanControl}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 933 | switch vs.VlanControl { |
| 934 | case None: |
| 935 | flow.SetMatchVlan(vs.SVlan) |
| 936 | case ONUCVlanOLTSVlan: |
| 937 | if vs.UniVlan != of.VlanNone { |
| 938 | flow.SetMatchVlan(vs.UniVlan) |
| 939 | flow.SetSetVlan(vs.CVlan) |
| 940 | } else { |
| 941 | flow.SetPushVlan(vs.CVlan, layers.EthernetTypeDot1Q) |
| 942 | } |
| 943 | case OLTCVlanOLTSVlan: |
| 944 | flow.SetMatchVlan(vs.UniVlan) |
| 945 | case ONUCVlan: |
| 946 | if vs.UniVlan != of.VlanNone { |
| 947 | flow.SetMatchVlan(vs.UniVlan) |
| 948 | flow.SetSetVlan(vs.SVlan) |
| 949 | } else { |
| 950 | flow.SetPushVlan(vs.SVlan, layers.EthernetTypeDot1Q) |
| 951 | } |
| 952 | case OLTSVlan: |
| 953 | flow.SetMatchVlan(vs.UniVlan) |
| 954 | default: |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 955 | err := errorCodes.ErrInvalidParamInRequest |
| 956 | return fmt.Errorf("Invalid Vlan Control Option %d : %w", vs.VlanControl, err) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 957 | } |
| 958 | return nil |
| 959 | } |
| 960 | |
| 961 | // setDSMatchActionVlanT1 - Sets the Match & Action w.r.t Vlans for DS Table-1 |
| 962 | // based on different Vlan Controls |
| 963 | func (vs *VoltService) setDSMatchActionVlanT1(flow *of.VoltSubFlow) error { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 964 | logger.Debugw(ctx, "Set DS Match Action Vlan T1", log.Fields{"Value": vs.VlanControl}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 965 | switch vs.VlanControl { |
| 966 | case None: |
| 967 | flow.SetMatchVlan(vs.SVlan) |
| 968 | case ONUCVlanOLTSVlan: |
| 969 | flow.SetMatchVlan(vs.CVlan) |
| 970 | if vs.UniVlan != of.VlanNone { |
| 971 | flow.SetSetVlan(vs.UniVlan) |
| 972 | } else { |
| 973 | flow.SetPopVlan() |
| 974 | } |
| 975 | case OLTCVlanOLTSVlan: |
| 976 | flow.SetMatchVlan(vs.UniVlan) |
| 977 | case ONUCVlan: |
| 978 | flow.SetMatchVlan(vs.SVlan) |
| 979 | if vs.UniVlan != of.VlanNone { |
| 980 | flow.SetSetVlan(vs.UniVlan) |
| 981 | } else { |
| 982 | flow.SetPopVlan() |
| 983 | } |
| 984 | case OLTSVlan: |
| 985 | flow.SetMatchVlan(vs.UniVlan) |
| 986 | default: |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 987 | err := errorCodes.ErrInvalidParamInRequest |
| 988 | return fmt.Errorf("Invalid Vlan Control Option %d : %w", vs.VlanControl, err) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 989 | } |
| 990 | return nil |
| 991 | } |
| 992 | |
| 993 | // SvcUpInd for service up indication |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 994 | func (vs *VoltService) SvcUpInd(cntx context.Context) { |
| 995 | vs.AddHsiaFlows(cntx) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 996 | } |
| 997 | |
| 998 | // SvcDownInd for service down indication |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 999 | func (vs *VoltService) SvcDownInd(cntx context.Context) { |
| 1000 | vs.DelHsiaFlows(cntx) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1001 | } |
| 1002 | |
| 1003 | // SetIpv4Addr to set ipv4 address |
| 1004 | func (vs *VoltService) SetIpv4Addr(addr net.IP) { |
| 1005 | vs.Ipv4Addr = addr |
| 1006 | } |
| 1007 | |
| 1008 | // SetIpv6Addr to set ipv6 address |
| 1009 | func (vs *VoltService) SetIpv6Addr(addr net.IP) { |
| 1010 | vs.Ipv6Addr = addr |
| 1011 | } |
| 1012 | |
| 1013 | // SetMacAddr to set mac address |
| 1014 | func (vs *VoltService) SetMacAddr(addr net.HardwareAddr) { |
| 1015 | vs.MacAddr = addr |
| 1016 | } |
| 1017 | |
| 1018 | // ---------------------------------------------- |
| 1019 | // VOLT Application - Related to services |
| 1020 | // --------------------------------------------- |
| 1021 | // --------------------------------------------------------------- |
| 1022 | // Service CRUD functions. These are exposed to the overall binary |
| 1023 | // to be invoked from the point where the CRUD operations are received |
| 1024 | // from the external entities |
| 1025 | |
| 1026 | // AddService : A service in the context of VOLT is a subscriber or service of a |
| 1027 | // subscriber which is uniquely identified by a combination of MAC |
| 1028 | // address, VLAN tags, 802.1p bits. However, in the context of the |
| 1029 | // current implementation, a service is an entity that is identified by a |
| 1030 | // unique L2 (MAC address + VLANs) or unique L3 (VLANs + IP address) |
| 1031 | // FUNC: Add Service |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 1032 | func (va *VoltApplication) AddService(cntx context.Context, cfg VoltServiceCfg, oper *VoltServiceOper) error { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 1033 | logger.Infow(ctx, "Service to be configured", log.Fields{"Cfg": cfg}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1034 | var mmUs, mmDs *VoltMeter |
| 1035 | var err error |
| 1036 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 1037 | // Take the Device lock only in case of NB add request. |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1038 | // Allow internal adds since internal add happen only under |
| 1039 | // 1. Restore Service from DB |
| 1040 | // 2. Service Migration |
| 1041 | if oper == nil { |
| 1042 | if svc := va.GetService(cfg.Name); svc != nil { |
| 1043 | logger.Warnw(ctx, "Service Already Exists. Ignoring Add Service Request", log.Fields{"Name": cfg.Name}) |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 1044 | return errors.New("service already exists") |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1045 | } |
| 1046 | } |
| 1047 | |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1048 | // Service doesn't exist. So create it and add to the port |
| 1049 | vs := NewVoltService(&cfg) |
| 1050 | if oper != nil { |
| 1051 | vs.UsHSIAFlowsApplied = oper.UsHSIAFlowsApplied |
| 1052 | vs.DsHSIAFlowsApplied = oper.DsHSIAFlowsApplied |
| 1053 | vs.Ipv4Addr = oper.Ipv4Addr |
| 1054 | vs.Ipv6Addr = oper.Ipv6Addr |
| 1055 | vs.MacLearning = cfg.MacLearning |
| 1056 | vs.PendingFlows = oper.PendingFlows |
| 1057 | vs.AssociatedFlows = oper.AssociatedFlows |
| 1058 | vs.DeleteInProgress = oper.DeleteInProgress |
Hitesh Chhabra | 64be244 | 2023-06-21 17:06:34 +0530 | [diff] [blame] | 1059 | vs.DeactivateInProgress = oper.DeactivateInProgress |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1060 | vs.BwAvailInfo = oper.BwAvailInfo |
| 1061 | vs.Device = oper.Device |
Sridhar Ravindra | 45589a7 | 2024-01-04 17:57:35 +0530 | [diff] [blame] | 1062 | // FlowPushCount is newly introduced map and it can be nil when VGC is upgraded. Hence adding a nil check to handle backward compatibility |
| 1063 | if cfg.FlowPushCount != nil { |
| 1064 | vs.FlowPushCount = cfg.FlowPushCount |
| 1065 | } |
Sridhar Ravindra | 3ec1423 | 2024-01-01 19:11:48 +0530 | [diff] [blame] | 1066 | vs.ServiceDeactivateReason = cfg.ServiceDeactivateReason |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1067 | } else { |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 1068 | // Sorting Pbit from highest |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1069 | sort.Slice(vs.Pbits, func(i, j int) bool { |
| 1070 | return vs.Pbits[i] > vs.Pbits[j] |
| 1071 | }) |
| 1072 | logger.Infow(ctx, "Sorted Pbits", log.Fields{"Pbits": vs.Pbits}) |
| 1073 | } |
| 1074 | logger.Infow(ctx, "VolthService...", log.Fields{"vs": vs.Name}) |
| 1075 | |
| 1076 | // The bandwidth and shaper profile combined into meter |
| 1077 | if mmDs, err = va.GetMeter(cfg.DsMeterProfile); err == nil { |
| 1078 | vs.DsMeterID = mmDs.ID |
| 1079 | } else { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 1080 | return errors.New("downStream meter profile not found") |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1081 | } |
| 1082 | |
| 1083 | // The aggregated downstream meter profile |
| 1084 | // if mmAg, err = va.GetMeter(cfg.AggDsMeterProfile); err == nil { |
| 1085 | // vs.AggDsMeterID = mmAg.ID |
| 1086 | // } else { |
| 1087 | // return errors.New("Aggregated meter profile not found") |
| 1088 | // } |
| 1089 | |
| 1090 | // if cfg.AggDsMeterProfile == cfg.UsMeterProfile { |
| 1091 | // vs.UsMeterID = mmAg.ID |
| 1092 | // } else { |
| 1093 | // The bandwidth and shaper profile combined into meter |
| 1094 | if mmUs, err = va.GetMeter(cfg.UsMeterProfile); err == nil { |
| 1095 | vs.UsMeterID = mmUs.ID |
| 1096 | } else { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 1097 | return errors.New("upstream meter profile not found") |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1098 | } |
| 1099 | //} |
| 1100 | |
| 1101 | AppMutex.ServiceDataMutex.Lock() |
| 1102 | defer AppMutex.ServiceDataMutex.Unlock() |
| 1103 | |
| 1104 | // Add the service to the VNET |
| 1105 | vnet := va.GetVnet(cfg.SVlan, cfg.CVlan, cfg.UniVlan) |
| 1106 | if vnet != nil { |
| 1107 | if vpv := va.GetVnetByPort(vs.Port, cfg.SVlan, cfg.CVlan, cfg.UniVlan); vpv != nil { |
| 1108 | vpv.VpvLock.Lock() |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 1109 | vpv.AddSvc(cntx, vs) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1110 | vpv.VpvLock.Unlock() |
| 1111 | } else { |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 1112 | va.AddVnetToPort(cntx, vs.Port, vnet, vs) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1113 | } |
| 1114 | } else { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 1115 | logger.Warnw(ctx, "VNET-does-not-exist-for-service", log.Fields{"ServiceName": cfg.Name}) |
| 1116 | return errors.New("vnet doesn't exist") |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1117 | } |
| 1118 | |
Tinoj Joseph | 50d722c | 2022-12-06 22:53:22 +0530 | [diff] [blame] | 1119 | // If the device is already discovered, update the device name in service |
| 1120 | d, err := va.GetDeviceFromPort(vs.Port) |
| 1121 | if err == nil { |
| 1122 | vs.Device = d.Name |
| 1123 | } |
| 1124 | |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1125 | vs.Version = database.PresentVersionMap[database.ServicePath] |
| 1126 | // Add the service to the volt application |
| 1127 | va.ServiceByName.Store(vs.Name, vs) |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 1128 | vs.WriteToDb(cntx) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1129 | |
| 1130 | if nil == oper { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1131 | if !vs.UsHSIAFlowsApplied { |
| 1132 | vs.triggerServiceInProgressInd() |
| 1133 | } |
| 1134 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 1135 | // Update meter profiles service count if service is being added from northbound |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1136 | mmDs.AssociatedServices++ |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 1137 | va.UpdateMeterProf(cntx, *mmDs) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1138 | if mmUs != nil { |
| 1139 | mmUs.AssociatedServices++ |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 1140 | va.UpdateMeterProf(cntx, *mmUs) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1141 | } |
| 1142 | //mmAg.AssociatedServices++ |
| 1143 | //va.UpdateMeterProf(*mmAg) |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 1144 | logger.Debugw(ctx, "northbound-service-add-successful", log.Fields{"ServiceName": vs.Name}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1145 | } |
| 1146 | |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 1147 | logger.Debugw(ctx, "Added Service to DB", log.Fields{"Name": vs.Name, "Port": (vs.Port), "ML": vs.MacLearning}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1148 | return nil |
| 1149 | } |
| 1150 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 1151 | // DelServiceWithPrefix - Deletes service with the provided prefix. |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1152 | // Added for DT/TT usecase with sadis replica interface |
Hitesh Chhabra | 7d249a0 | 2023-07-04 21:33:49 +0530 | [diff] [blame] | 1153 | func (va *VoltApplication) DelServiceWithPrefix(cntx context.Context, prefix string) error { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 1154 | logger.Infow(ctx, "Delete Service With provided Prefix", log.Fields{"Prefix": prefix}) |
Hitesh Chhabra | 7d249a0 | 2023-07-04 21:33:49 +0530 | [diff] [blame] | 1155 | var isServiceExist bool |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1156 | va.ServiceByName.Range(func(key, value interface{}) bool { |
| 1157 | srvName := key.(string) |
| 1158 | vs := value.(*VoltService) |
| 1159 | if strings.Contains(srvName, prefix) { |
Hitesh Chhabra | 7d249a0 | 2023-07-04 21:33:49 +0530 | [diff] [blame] | 1160 | isServiceExist = true |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 1161 | va.DelService(cntx, srvName, true, nil, false) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1162 | |
| 1163 | vnetName := strconv.FormatUint(uint64(vs.SVlan), 10) + "-" |
| 1164 | vnetName = vnetName + strconv.FormatUint(uint64(vs.CVlan), 10) + "-" |
| 1165 | vnetName = vnetName + strconv.FormatUint(uint64(vs.UniVlan), 10) |
| 1166 | |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 1167 | if err := va.DelVnet(cntx, vnetName, ""); err != nil { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1168 | logger.Warnw(ctx, "Delete Vnet Failed", log.Fields{"Name": vnetName, "Error": err}) |
| 1169 | } |
| 1170 | } |
| 1171 | return true |
| 1172 | }) |
Hitesh Chhabra | 7d249a0 | 2023-07-04 21:33:49 +0530 | [diff] [blame] | 1173 | |
| 1174 | if !isServiceExist { |
| 1175 | return errorCodes.ErrServiceNotFound |
| 1176 | } |
| 1177 | return nil |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1178 | } |
| 1179 | |
| 1180 | // DelService delete a service form the application |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 1181 | func (va *VoltApplication) DelService(cntx context.Context, name string, forceDelete bool, newSvc *VoltServiceCfg, serviceMigration bool) { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1182 | AppMutex.ServiceDataMutex.Lock() |
| 1183 | defer AppMutex.ServiceDataMutex.Unlock() |
| 1184 | |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 1185 | logger.Infow(ctx, "Delete Service Request", log.Fields{"Service": name, "ForceDelete": forceDelete, "serviceMigration": serviceMigration}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1186 | var noFlowsPresent bool |
| 1187 | |
| 1188 | vsIntf, ok := va.ServiceByName.Load(name) |
| 1189 | if !ok { |
| 1190 | logger.Warnw(ctx, "Service doesn't exist", log.Fields{"ServiceName": name}) |
| 1191 | return |
| 1192 | } |
| 1193 | vs := vsIntf.(*VoltService) |
| 1194 | vpv := va.GetVnetByPort(vs.Port, vs.SVlan, vs.CVlan, vs.UniVlan) |
| 1195 | if vpv == nil { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 1196 | logger.Warnw(ctx, "Vpv Not found for Service", log.Fields{"vs": vs.Name}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1197 | return |
| 1198 | } |
| 1199 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 1200 | // Set this to avoid race-condition during flow result processing |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1201 | vs.DeleteInProgress = true |
| 1202 | vs.ForceDelete = forceDelete |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 1203 | vs.ForceWriteToDb(cntx) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1204 | |
| 1205 | if len(vs.AssociatedFlows) == 0 { |
| 1206 | noFlowsPresent = true |
| 1207 | } |
| 1208 | vpv.VpvLock.Lock() |
| 1209 | defer vpv.VpvLock.Unlock() |
| 1210 | |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 1211 | vs.DelHsiaFlows(cntx) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1212 | |
| 1213 | if vpv.IgmpEnabled { |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 1214 | va.ReceiverDownInd(cntx, vpv.Device, vpv.Port) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1215 | } |
| 1216 | logger.Infow(ctx, "Delete Service from VPV", log.Fields{"VPV_Port": vpv.Port, "VPV_SVlan": vpv.SVlan, "VPV_CVlan": vpv.CVlan, "VPV_UniVlan": vpv.UniVlan, "ServiceName": name}) |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 1217 | vpv.DelService(cntx, vs) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1218 | if vpv.servicesCount.Load() == 0 { |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 1219 | va.DelVnetFromPort(cntx, vs.Port, vpv) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1220 | } |
| 1221 | |
| 1222 | // Delete the service immediately in case of Force Delete |
| 1223 | // This will be enabled when profile reconciliation happens after restore |
| 1224 | // of backedup data |
| 1225 | if vs.ForceDelete { |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 1226 | vs.DelFromDb(cntx) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1227 | GetApplication().ServiceByName.Delete(vs.Name) |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 1228 | logger.Debugw(ctx, "Deleted service from DB/Cache successfully", log.Fields{"serviceName": vs.Name}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1229 | } |
| 1230 | |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1231 | if nil != newSvc { |
| 1232 | logger.Infow(ctx, "Old Service meter profiles", log.Fields{"AGG": vs.AggDsMeterProfile, "DS": vs.DsMeterProfile, "US": vs.UsMeterProfile}) |
| 1233 | logger.Infow(ctx, "New Service meter profiles", log.Fields{"AGG": newSvc.AggDsMeterProfile, "DS": newSvc.DsMeterProfile, "US": newSvc.UsMeterProfile}) |
| 1234 | } |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1235 | |
Sridhar Ravindra | 2d2ef4e | 2023-02-08 16:43:38 +0530 | [diff] [blame] | 1236 | logger.Infow(ctx, "About to mark meter for deletion\n", log.Fields{"serviceName": vs.Name}) |
| 1237 | |
| 1238 | if aggMeter, ok := va.MeterMgr.GetMeterByID(vs.AggDsMeterID); ok { |
| 1239 | if nil == newSvc || (nil != newSvc && aggMeter.Name != newSvc.AggDsMeterProfile) { |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 1240 | if aggMeter.AssociatedServices > 0 { |
| 1241 | aggMeter.AssociatedServices-- |
| 1242 | logger.Infow(ctx, "Agg Meter associated services updated\n", log.Fields{"MeterID": aggMeter}) |
| 1243 | va.UpdateMeterProf(cntx, *aggMeter) |
| 1244 | } |
Sridhar Ravindra | 2d2ef4e | 2023-02-08 16:43:38 +0530 | [diff] [blame] | 1245 | } |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1246 | } |
| 1247 | if dsMeter, ok := va.MeterMgr.GetMeterByID(vs.DsMeterID); ok { |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 1248 | if nil == newSvc || (nil != newSvc && dsMeter.Name != newSvc.DsMeterProfile) { |
| 1249 | if dsMeter.AssociatedServices > 0 { |
| 1250 | dsMeter.AssociatedServices-- |
| 1251 | logger.Infow(ctx, "DS Meter associated services updated\n", log.Fields{"MeterID": dsMeter}) |
| 1252 | va.UpdateMeterProf(cntx, *dsMeter) |
| 1253 | } |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1254 | } |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1255 | } |
| 1256 | if vs.AggDsMeterID != vs.UsMeterID { |
| 1257 | if usMeter, ok := va.MeterMgr.GetMeterByID(vs.UsMeterID); ok { |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 1258 | if nil == newSvc || (nil != newSvc && usMeter.Name != newSvc.UsMeterProfile) { |
| 1259 | if usMeter.AssociatedServices > 0 { |
| 1260 | usMeter.AssociatedServices-- |
| 1261 | logger.Infow(ctx, "US Meter associated services updated\n", log.Fields{"MeterID": usMeter}) |
| 1262 | va.UpdateMeterProf(cntx, *usMeter) |
| 1263 | } |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1264 | } |
| 1265 | } |
| 1266 | } |
| 1267 | |
| 1268 | if noFlowsPresent || vs.ForceDelete { |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 1269 | vs.CheckAndDeleteService(cntx) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1270 | } |
| 1271 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 1272 | // Delete the per service counter too |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1273 | va.ServiceCounters.Delete(name) |
| 1274 | if vs.IgmpEnabled && vs.EnableMulticastKPI { |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 1275 | _ = db.DelAllServiceChannelCounter(cntx, name) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1276 | } |
| 1277 | } |
| 1278 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 1279 | // AddFlows - Adds the flow to the service |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1280 | // Triggers flow addition after registering for flow indication event |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 1281 | func (vs *VoltService) AddFlows(cntx context.Context, device *VoltDevice, flow *of.VoltFlow) error { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1282 | // Using locks instead of concurrent map for PendingFlows to avoid |
| 1283 | // race condition during flow response indication processing |
| 1284 | vs.ServiceLock.Lock() |
| 1285 | defer vs.ServiceLock.Unlock() |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 1286 | logger.Debugw(ctx, "Adds the flow to the service", log.Fields{"Port": vs.Port, "Device": device.Name}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1287 | |
| 1288 | for cookie := range flow.SubFlows { |
| 1289 | cookie := strconv.FormatUint(cookie, 10) |
| 1290 | fe := &FlowEvent{ |
| 1291 | eType: EventTypeServiceFlowAdded, |
| 1292 | device: device.Name, |
| 1293 | cookie: cookie, |
| 1294 | eventData: vs, |
| 1295 | } |
| 1296 | device.RegisterFlowAddEvent(cookie, fe) |
| 1297 | vs.PendingFlows[cookie] = true |
| 1298 | } |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 1299 | return cntlr.GetController().AddFlows(cntx, vs.Port, device.Name, flow) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1300 | } |
| 1301 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 1302 | // FlowInstallSuccess - Called when corresponding service flow installation is success |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1303 | // If no more pending flows, HSIA indication wil be triggered |
Sridhar Ravindra | 3ec1423 | 2024-01-01 19:11:48 +0530 | [diff] [blame] | 1304 | func (vs *VoltService) FlowInstallSuccess(cntx context.Context, cookie string, bwAvailInfo of.BwAvailDetails, flowEventMap *util.ConcurrentMap) { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 1305 | logger.Debugw(ctx, "Flow Add Success Notification", log.Fields{"Cookie": cookie, "bwAvailInfo": bwAvailInfo, "Service": vs.Name}) |
Sridhar Ravindra | 3ec1423 | 2024-01-01 19:11:48 +0530 | [diff] [blame] | 1306 | flowEventMap.MapLock.Lock() |
| 1307 | flowEventMap.Remove(cookie) |
| 1308 | flowEventMap.MapLock.Unlock() |
| 1309 | |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1310 | if vs.DeleteInProgress { |
| 1311 | logger.Warnw(ctx, "Skipping Flow Add Success Notification. Service deletion in-progress", log.Fields{"Cookie": cookie, "Service": vs.Name}) |
| 1312 | return |
| 1313 | } |
| 1314 | vs.ServiceLock.Lock() |
| 1315 | |
| 1316 | if _, ok := vs.PendingFlows[cookie]; !ok { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 1317 | logger.Warnw(ctx, "Flow Add Success for unknown Cookie", log.Fields{"Service": vs.Name, "Cookie": cookie}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1318 | vs.ServiceLock.Unlock() |
| 1319 | return |
| 1320 | } |
| 1321 | |
| 1322 | delete(vs.PendingFlows, cookie) |
| 1323 | vs.AssociatedFlows[cookie] = true |
Sridhar Ravindra | 3ec1423 | 2024-01-01 19:11:48 +0530 | [diff] [blame] | 1324 | vs.FlowPushCount[cookie] = 0 |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1325 | vs.ServiceLock.Unlock() |
| 1326 | var prevBwAvail, presentBwAvail string |
| 1327 | if bwAvailInfo.PrevBw != "" && bwAvailInfo.PresentBw != "" { |
| 1328 | prevBwAvail = bwAvailInfo.PrevBw |
| 1329 | presentBwAvail = bwAvailInfo.PresentBw |
| 1330 | vs.BwAvailInfo = prevBwAvail + "," + presentBwAvail |
Tinoj Joseph | 1d10832 | 2022-07-13 10:07:39 +0530 | [diff] [blame] | 1331 | logger.Debugw(ctx, "Bandwidth-value-formed", log.Fields{"BwAvailInfo": vs.BwAvailInfo}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1332 | } |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 1333 | vs.WriteToDb(cntx) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1334 | |
| 1335 | if len(vs.PendingFlows) == 0 && vs.DsHSIAFlowsApplied { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1336 | device, err := GetApplication().GetDeviceFromPort(vs.Port) |
| 1337 | if err != nil { |
| 1338 | logger.Errorw(ctx, "Error Getting Device. Dropping HSIA Success indication to NB", log.Fields{"Reason": err.Error(), "Service": vs.Name, "Port": vs.Port}) |
| 1339 | return |
| 1340 | } else if device.State != controller.DeviceStateUP { |
| 1341 | logger.Warnw(ctx, "Device state Down. Dropping HSIA Success indication to NB", log.Fields{"Service": vs.Name, "Port": vs.Port}) |
| 1342 | return |
| 1343 | } |
| 1344 | |
| 1345 | if vs.Trigger == ServiceVlanUpdate { |
| 1346 | vs.Trigger = NBActivate |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 1347 | defer vs.WriteToDb(cntx) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1348 | } |
| 1349 | logger.Infow(ctx, "All Flows installed for Service", log.Fields{"Service": vs.Name}) |
| 1350 | return |
| 1351 | } |
| 1352 | logger.Infow(ctx, "Processed Service Flow Add Success Indication", log.Fields{"Cookie": cookie, "Service": vs.Name, "DsFlowsApplied": vs.DsHSIAFlowsApplied}) |
| 1353 | } |
| 1354 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 1355 | // FlowInstallFailure - Called when corresponding service flow installation is failed |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1356 | // Trigger service failure indication to NB |
Sridhar Ravindra | 3ec1423 | 2024-01-01 19:11:48 +0530 | [diff] [blame] | 1357 | func (vs *VoltService) FlowInstallFailure(cntx context.Context, cookie string, errorCode uint32, errReason string, flowEventMap *util.ConcurrentMap) { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 1358 | logger.Debugw(ctx, "Service flow installation failure", log.Fields{"Service": vs.Name, "Cookie": cookie, "errorCode": errorCode, "errReason": errReason}) |
Sridhar Ravindra | 3ec1423 | 2024-01-01 19:11:48 +0530 | [diff] [blame] | 1359 | |
| 1360 | isServiceDeactivated := vs.CheckAndDeactivateService(cntx, cookie) |
| 1361 | if isServiceDeactivated { |
| 1362 | flowEventMap.MapLock.Lock() |
| 1363 | for ck := range vs.PendingFlows { |
| 1364 | flowEventMap.Remove(ck) |
| 1365 | } |
| 1366 | flowEventMap.MapLock.Unlock() |
| 1367 | } |
| 1368 | |
| 1369 | vs.ServiceLock.RLock() |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1370 | if _, ok := vs.PendingFlows[cookie]; !ok { |
| 1371 | logger.Errorw(ctx, "Flow Add Failure for unknown Cookie", log.Fields{"Service": vs.Name, "Cookie": cookie}) |
| 1372 | vs.ServiceLock.RUnlock() |
| 1373 | return |
| 1374 | } |
| 1375 | vs.ServiceLock.RUnlock() |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 1376 | logger.Debugw(ctx, "HSIA Flow Add Failure Notification", log.Fields{"uniPort": vs.Port, "Cookie": cookie, "Service": vs.Name, "ErrorCode": errorCode, "ErrorReason": errReason}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1377 | vs.triggerServiceFailureInd(errorCode, errReason) |
| 1378 | } |
| 1379 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 1380 | // DelFlows - Deletes the flow from the service |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1381 | // Triggers flow deletion after registering for flow indication event |
Sridhar Ravindra | 03aa0bf | 2023-09-12 17:46:40 +0530 | [diff] [blame] | 1382 | func (vs *VoltService) DelFlows(cntx context.Context, device *VoltDevice, flow *of.VoltFlow, delFlowsInDevice bool) error { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 1383 | logger.Debugw(ctx, "Delete the flow from the service", log.Fields{"Port": vs.Port, "Device": device.Name}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1384 | if !vs.ForceDelete { |
| 1385 | // Using locks instead of concurrent map for AssociatedFlows to avoid |
| 1386 | // race condition during flow response indication processing |
| 1387 | vs.ServiceLock.Lock() |
| 1388 | defer vs.ServiceLock.Unlock() |
| 1389 | |
| 1390 | for cookie := range flow.SubFlows { |
| 1391 | cookie := strconv.FormatUint(cookie, 10) |
| 1392 | fe := &FlowEvent{ |
| 1393 | eType: EventTypeServiceFlowRemoved, |
| 1394 | cookie: cookie, |
| 1395 | eventData: vs, |
| 1396 | } |
| 1397 | device.RegisterFlowDelEvent(cookie, fe) |
| 1398 | } |
| 1399 | } |
Sridhar Ravindra | 03aa0bf | 2023-09-12 17:46:40 +0530 | [diff] [blame] | 1400 | return cntlr.GetController().DelFlows(cntx, vs.Port, device.Name, flow, delFlowsInDevice) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1401 | } |
| 1402 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 1403 | // CheckAndDeleteService - remove service from DB is there are no pending flows to be removed |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 1404 | func (vs *VoltService) CheckAndDeleteService(cntx context.Context) { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 1405 | logger.Debugw(ctx, "Delete service from DB/Cache", log.Fields{"serviceName": vs.Name}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1406 | if vs.DeleteInProgress && len(vs.AssociatedFlows) == 0 && !vs.DsHSIAFlowsApplied { |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 1407 | vs.DelFromDb(cntx) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1408 | GetApplication().ServiceByName.Delete(vs.Name) |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 1409 | logger.Debugw(ctx, "Deleted service from DB/Cache successfully", log.Fields{"serviceName": vs.Name}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1410 | } |
| 1411 | } |
| 1412 | |
Sridhar Ravindra | 3ec1423 | 2024-01-01 19:11:48 +0530 | [diff] [blame] | 1413 | // CheckAndDeactivateService - deactivate service and remove flows from DB, if the max flows retry attempt has reached |
| 1414 | func (vs *VoltService) CheckAndDeactivateService(cntx context.Context, cookie string) bool { |
| 1415 | vs.ServiceLock.Lock() |
| 1416 | logger.Debugw(ctx, "Check and Deactivate service if flow install threshold is reached and remove flows from DB/Device", log.Fields{"serviceName": vs.Name, "FlowPushCount": vs.FlowPushCount[cookie]}) |
| 1417 | vs.FlowPushCount[cookie]++ |
| 1418 | if vs.FlowPushCount[cookie] == controller.GetController().GetMaxFlowRetryAttempt() { |
| 1419 | if vs.IsActivated { |
| 1420 | vs.ServiceLock.Unlock() |
| 1421 | device, err := GetApplication().GetDeviceFromPort(vs.Port) |
| 1422 | if err != nil { |
| 1423 | // Even if the port/device does not exists at this point in time, the deactivate request is succss. |
| 1424 | // So no error is returned |
| 1425 | logger.Warnw(ctx, "Error Getting Device", log.Fields{"Reason": err.Error(), "Port": vs.Port}) |
| 1426 | return false |
| 1427 | } |
| 1428 | vs.SetSvcDeactivationFlags(SvcDeacRsn_Controller) |
| 1429 | GetApplication().ServiceByName.Store(vs.Name, vs) |
| 1430 | p := device.GetPort(vs.Port) |
| 1431 | if p != nil && (p.State == PortStateUp) { |
| 1432 | if vpv := GetApplication().GetVnetByPort(vs.Port, vs.SVlan, vs.CVlan, vs.UniVlan); vpv != nil { |
| 1433 | // Port down call internally deletes all the flows |
| 1434 | vpv.PortDownInd(cntx, vs.Device, vs.Port, true, true) |
| 1435 | } else { |
| 1436 | logger.Warnw(ctx, "VPV does not exists!!!", log.Fields{"Device": vs.Device, "port": vs.Port, "SvcName": vs.Name}) |
| 1437 | } |
| 1438 | } |
| 1439 | vs.DeactivateInProgress = false |
| 1440 | GetApplication().ServiceByName.Store(vs.Name, vs) |
| 1441 | vs.WriteToDb(cntx) |
| 1442 | logger.Infow(ctx, "Service deactivated after max flow install attempts", log.Fields{"SvcName": vs.Name, "Cookie": cookie}) |
| 1443 | return true |
| 1444 | } |
| 1445 | } |
| 1446 | vs.ServiceLock.Unlock() |
| 1447 | return false |
| 1448 | } |
| 1449 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 1450 | // FlowRemoveSuccess - Called when corresponding service flow removal is success |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1451 | // If no more associated flows, DelHSIA indication wil be triggered |
Sridhar Ravindra | 3ec1423 | 2024-01-01 19:11:48 +0530 | [diff] [blame] | 1452 | func (vs *VoltService) FlowRemoveSuccess(cntx context.Context, cookie string, flowEventMap *util.ConcurrentMap) { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1453 | // if vs.DeleteInProgress { |
| 1454 | // logger.Warnw(ctx, "Skipping Flow Remove Success Notification. Service deletion in-progress", log.Fields{"Cookie": cookie, "Service": vs.Name}) |
| 1455 | // return |
| 1456 | // } |
Sridhar Ravindra | 3ec1423 | 2024-01-01 19:11:48 +0530 | [diff] [blame] | 1457 | flowEventMap.MapLock.Lock() |
| 1458 | flowEventMap.Remove(cookie) |
| 1459 | flowEventMap.MapLock.Unlock() |
| 1460 | |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1461 | vs.ServiceLock.Lock() |
| 1462 | logger.Infow(ctx, "Processing Service Flow Remove Success Indication", log.Fields{"Cookie": cookie, "Service": vs.Name, "Associated Flows": vs.AssociatedFlows, "DsFlowsApplied": vs.DsHSIAFlowsApplied}) |
| 1463 | |
| 1464 | if _, ok := vs.AssociatedFlows[cookie]; ok { |
| 1465 | delete(vs.AssociatedFlows, cookie) |
| 1466 | } else if _, ok := vs.PendingFlows[cookie]; ok { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 1467 | logger.Debugw(ctx, "Service Flow Remove: Cookie Present in Pending Flow list. No Action", log.Fields{"Service": vs.Name, "Cookie": cookie, "AssociatedFlows": vs.AssociatedFlows, "PendingFlows": vs.PendingFlows}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1468 | } else { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 1469 | logger.Debugw(ctx, "Service Flow Remove Success for unknown Cookie", log.Fields{"Service": vs.Name, "Cookie": cookie, "AssociatedFlows": vs.AssociatedFlows, "PendingFlows": vs.PendingFlows}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1470 | } |
| 1471 | |
Sridhar Ravindra | 3ec1423 | 2024-01-01 19:11:48 +0530 | [diff] [blame] | 1472 | vs.FlowPushCount[cookie] = 0 |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1473 | vs.ServiceLock.Unlock() |
| 1474 | |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 1475 | vs.WriteToDb(cntx) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1476 | |
| 1477 | if len(vs.AssociatedFlows) == 0 && !vs.DsHSIAFlowsApplied { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1478 | device := GetApplication().GetDevice(vs.Device) |
| 1479 | if device == nil { |
| 1480 | logger.Errorw(ctx, "Error Getting Device. Dropping DEL_HSIA Success indication to NB", log.Fields{"Service": vs.Name, "Port": vs.Port}) |
| 1481 | return |
| 1482 | } else if device.State != controller.DeviceStateUP { |
| 1483 | logger.Warnw(ctx, "Device state Down. Dropping DEL_HSIA Success indication to NB", log.Fields{"Service": vs.Name, "Port": vs.Port}) |
| 1484 | return |
| 1485 | } |
| 1486 | |
| 1487 | if vs.UpdateInProgress { |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 1488 | vs.updateVnetProfile(cntx, vs.Device) |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 1489 | // Not sending DEL_HSIA Indication since it wil be generated internally by SubMgr |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1490 | return |
| 1491 | } |
| 1492 | logger.Infow(ctx, "All Flows removed for Service. Triggering Service De-activation Success indication to NB", log.Fields{"Service": vs.Name, "DeleteFlag": vs.DeleteInProgress}) |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 1493 | vs.CheckAndDeleteService(cntx) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1494 | |
| 1495 | return |
| 1496 | } |
| 1497 | logger.Infow(ctx, "Processed Service Flow Remove Success Indication", log.Fields{"Cookie": cookie, "Service": vs.Name, "Associated Flows": vs.AssociatedFlows, "DsFlowsApplied": vs.DsHSIAFlowsApplied}) |
| 1498 | } |
| 1499 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 1500 | // FlowRemoveFailure - Called when corresponding service flow installation is failed |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1501 | // Trigger service failure indication to NB |
Sridhar Ravindra | 3ec1423 | 2024-01-01 19:11:48 +0530 | [diff] [blame] | 1502 | func (vs *VoltService) FlowRemoveFailure(cntx context.Context, cookie string, errorCode uint32, errReason string, flowEventMap *util.ConcurrentMap) { |
| 1503 | vs.ServiceLock.Lock() |
| 1504 | logger.Debugw(ctx, "Processing Service Flow Remove Failure Indication", log.Fields{"Cookie": cookie, "Service": vs.Name, "Associated Flows": vs.AssociatedFlows, "DsFlowsApplied": vs.DsHSIAFlowsApplied, "FlowPushCount": vs.FlowPushCount[cookie]}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1505 | |
Sridhar Ravindra | 3ec1423 | 2024-01-01 19:11:48 +0530 | [diff] [blame] | 1506 | vs.FlowPushCount[cookie]++ |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1507 | if _, ok := vs.AssociatedFlows[cookie]; !ok { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 1508 | logger.Warnw(ctx, "Flow Failure for unknown Cookie", log.Fields{"Service": vs.Name, "Cookie": cookie}) |
Sridhar Ravindra | 3ec1423 | 2024-01-01 19:11:48 +0530 | [diff] [blame] | 1509 | vs.ServiceLock.Unlock() |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1510 | return |
| 1511 | } |
| 1512 | if vs.DeleteInProgress { |
| 1513 | delete(vs.AssociatedFlows, cookie) |
| 1514 | } |
Sridhar Ravindra | 3ec1423 | 2024-01-01 19:11:48 +0530 | [diff] [blame] | 1515 | vs.ServiceLock.Unlock() |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 1516 | logger.Debugw(ctx, "Service Flow Remove Failure Notification", log.Fields{"uniPort": vs.Port, "Cookie": cookie, "Service": vs.Name, "ErrorCode": errorCode, "ErrorReason": errReason}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1517 | |
| 1518 | vs.triggerServiceFailureInd(errorCode, errReason) |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 1519 | vs.CheckAndDeleteService(cntx) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1520 | } |
| 1521 | |
| 1522 | func (vs *VoltService) triggerServiceFailureInd(errorCode uint32, errReason string) { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 1523 | logger.Debugw(ctx, "Trigger Service Failure Ind", log.Fields{"Service": vs.Name, "Port": vs.Port}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1524 | device, err := GetApplication().GetDeviceFromPort(vs.Port) |
| 1525 | if err != nil { |
| 1526 | logger.Errorw(ctx, "Error Getting Device. Dropping DEL_HSIA Failure indication to NB", log.Fields{"Reason": err.Error(), "Service": vs.Name, "Port": vs.Port}) |
| 1527 | return |
| 1528 | } else if device.State != controller.DeviceStateUP { |
| 1529 | logger.Warnw(ctx, "Device state Down. Dropping DEL_HSIA Failure indication to NB", log.Fields{"Service": vs.Name, "Port": vs.Port}) |
| 1530 | return |
| 1531 | } |
| 1532 | } |
| 1533 | |
| 1534 | // RestoreSvcsFromDb read from the DB and restore all the services |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 1535 | func (va *VoltApplication) RestoreSvcsFromDb(cntx context.Context) { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1536 | // VNETS must be learnt first |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 1537 | logger.Debug(ctx, "Restore Svcs From Db") |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 1538 | vss, _ := db.GetServices(cntx) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1539 | for _, vs := range vss { |
| 1540 | b, ok := vs.Value.([]byte) |
| 1541 | if !ok { |
| 1542 | logger.Warn(ctx, "The value type is not []byte") |
| 1543 | continue |
| 1544 | } |
| 1545 | var vvs VoltService |
| 1546 | err := json.Unmarshal(b, &vvs) |
| 1547 | if err != nil { |
| 1548 | logger.Warn(ctx, "Unmarshal of VNET failed") |
| 1549 | continue |
| 1550 | } |
| 1551 | logger.Debugw(ctx, "Retrieved Service", log.Fields{"Service": vvs.VoltServiceCfg}) |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 1552 | if err := va.AddService(cntx, vvs.VoltServiceCfg, &vvs.VoltServiceOper); err != nil { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1553 | logger.Warnw(ctx, "Add New Service Failed", log.Fields{"Service": vvs.Name, "Error": err}) |
| 1554 | } |
| 1555 | |
Hitesh Chhabra | 64be244 | 2023-06-21 17:06:34 +0530 | [diff] [blame] | 1556 | if vvs.VoltServiceOper.DeactivateInProgress { |
| 1557 | va.ServicesToDeactivate[vvs.VoltServiceCfg.Name] = true |
| 1558 | logger.Warnw(ctx, "Service (restored) to be deactivated", log.Fields{"Service": vvs.Name}) |
| 1559 | } |
| 1560 | |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1561 | if vvs.VoltServiceOper.DeleteInProgress { |
| 1562 | va.ServicesToDelete[vvs.VoltServiceCfg.Name] = true |
| 1563 | logger.Warnw(ctx, "Service (restored) to be deleted", log.Fields{"Service": vvs.Name}) |
| 1564 | } |
| 1565 | } |
| 1566 | } |
| 1567 | |
| 1568 | // GetService to get service |
| 1569 | func (va *VoltApplication) GetService(name string) *VoltService { |
| 1570 | if vs, ok := va.ServiceByName.Load(name); ok { |
| 1571 | return vs.(*VoltService) |
| 1572 | } |
| 1573 | return nil |
| 1574 | } |
| 1575 | |
| 1576 | // GetCircuitID to get circuit id |
| 1577 | func (vs *VoltService) GetCircuitID() []byte { |
| 1578 | return []byte(vs.CircuitID) |
| 1579 | } |
| 1580 | |
| 1581 | // GetRemoteID to get remote id |
| 1582 | func (vs *VoltService) GetRemoteID() []byte { |
| 1583 | return []byte(vs.RemoteID) |
| 1584 | } |
| 1585 | |
| 1586 | // IPAssigned to check if ip is assigned |
| 1587 | func (vs *VoltService) IPAssigned() bool { |
| 1588 | if vs.Ipv4Addr != nil && !vs.Ipv4Addr.Equal(net.ParseIP("0.0.0.0")) { |
| 1589 | return true |
| 1590 | } else if vs.Ipv6Addr != nil && !vs.Ipv6Addr.Equal(net.ParseIP("0:0:0:0:0:0:0:0")) { |
| 1591 | return true |
| 1592 | } |
| 1593 | return false |
| 1594 | } |
| 1595 | |
| 1596 | // GetServiceNameFromCookie to get service name from cookie |
| 1597 | func (va *VoltApplication) GetServiceNameFromCookie(cookie uint64, portName string, pbit uint8, device string, tableMetadata uint64) *VoltService { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 1598 | logger.Debugw(ctx, "Get Service Name From Cookie", log.Fields{"Cookie": cookie, "PortName": portName, "Pbit": pbit, "Device": device, "TableMetadata": tableMetadata}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1599 | var vlan uint64 |
| 1600 | vlanControl := (tableMetadata >> 32) & 0xF |
| 1601 | |
| 1602 | if vlanControl == uint64(OLTCVlanOLTSVlan) { |
| 1603 | // Fetching UniVlan for vlanControl OLTCVLANOLTSVLAN |
| 1604 | vlan = (tableMetadata >> 16) & 0xFFFF |
| 1605 | } else { |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 1606 | // Fetching CVlan for other vlanControl |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1607 | vlan = cookie >> 52 |
| 1608 | } |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 1609 | logger.Debugw(ctx, "Configured Params", log.Fields{"VlanControl": vlanControl, "vlan": vlan}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1610 | var vlans []of.VlanType |
| 1611 | vlans = append(vlans, of.VlanType(vlan)) |
| 1612 | service := GetApplication().GetServiceFromCvlan(device, portName, vlans, uint8(pbit)) |
| 1613 | if nil != service { |
Tinoj Joseph | 1d10832 | 2022-07-13 10:07:39 +0530 | [diff] [blame] | 1614 | logger.Infow(ctx, "Service Found for", log.Fields{"serviceName": service.Name, "portName": portName, "ctag": vlan}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1615 | } else { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 1616 | logger.Warnw(ctx, "No Service for", log.Fields{"portName": portName, "ctag": vlan, "Pbit": pbit, "device": device, "VlanControl": vlanControl}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1617 | } |
| 1618 | return service |
| 1619 | } |
| 1620 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 1621 | // MigrateServicesReqStatus - update vnet request status |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1622 | type MigrateServicesReqStatus string |
| 1623 | |
| 1624 | const ( |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 1625 | // MigrateSrvsReqInit constant |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1626 | MigrateSrvsReqInit MigrateServicesReqStatus = "Init" |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 1627 | // MigrateSrvsReqDeactTriggered constant |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1628 | MigrateSrvsReqDeactTriggered MigrateServicesReqStatus = "Profiles Deactivated" |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 1629 | // MigrateSrvsReqCompleted constant |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1630 | MigrateSrvsReqCompleted MigrateServicesReqStatus = "Update Complete" |
| 1631 | ) |
| 1632 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 1633 | // MigrateServicesRequest - update vnet request params |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1634 | type MigrateServicesRequest struct { |
| 1635 | ID string |
| 1636 | OldVnetID string |
| 1637 | NewVnetID string |
| 1638 | ServicesList map[string]bool |
| 1639 | DeviceID string |
| 1640 | Status MigrateServicesReqStatus |
| 1641 | MigrateServicesLock sync.RWMutex |
| 1642 | } |
| 1643 | |
| 1644 | func newMigrateServicesRequest(id string, oldVnetID string, newVnetID string, serviceMap map[string]bool, deviceID string) *MigrateServicesRequest { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1645 | var msr MigrateServicesRequest |
| 1646 | msr.OldVnetID = oldVnetID |
| 1647 | msr.NewVnetID = newVnetID |
| 1648 | msr.ID = id |
| 1649 | msr.ServicesList = serviceMap |
| 1650 | msr.DeviceID = deviceID |
| 1651 | msr.Status = MigrateSrvsReqInit |
| 1652 | return &msr |
| 1653 | } |
| 1654 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 1655 | // GetMsrKey - generates migrate service request key |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1656 | func (msr *MigrateServicesRequest) GetMsrKey() string { |
| 1657 | return msr.OldVnetID + "-" + msr.ID |
| 1658 | } |
| 1659 | |
| 1660 | // //isRequestComplete - return if all request has been processed and completed |
| 1661 | // // RequestProcessed indicates that all the profile de-activation has been triggered |
| 1662 | // // And the associated profiles indicates the profiles awaiting results |
| 1663 | // func (msr *MigrateServicesRequest) isRequestComplete() bool { |
| 1664 | // //return edr.RequestProcessed && (len(edr.AssociatedProfiles) == 0) |
| 1665 | // return (len(edr.AssociatedProfiles) == 0) |
| 1666 | // } |
| 1667 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 1668 | // WriteToDB - writes the udpate vnet request details ot DB |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 1669 | func (msr *MigrateServicesRequest) WriteToDB(cntx context.Context) { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1670 | logger.Debugw(ctx, "Adding Migrate Service Request to DB", log.Fields{"OldVnet": msr.OldVnetID, "NewVnet": msr.NewVnetID, "Device": msr.DeviceID, "RequestID": msr.ID, "ServiceCount": len(msr.ServicesList)}) |
| 1671 | if b, err := json.Marshal(msr); err == nil { |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 1672 | if err = db.PutMigrateServicesReq(cntx, msr.DeviceID, msr.GetMsrKey(), string(b)); err != nil { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1673 | logger.Warnw(ctx, "PutMigrateServicesReq Failed", log.Fields{"OldVnet": msr.OldVnetID, "NewVnet": msr.NewVnetID, |
Tinoj Joseph | d5b4f2f | 2022-11-11 19:25:24 +0530 | [diff] [blame] | 1674 | "Device": msr.DeviceID, "Error": err}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1675 | } |
| 1676 | } |
| 1677 | } |
| 1678 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 1679 | // MigrateServices - updated vnet profile for services |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 1680 | func (va *VoltApplication) MigrateServices(cntx context.Context, serialNum string, reqID string, oldVnetID, newVnetID string, serviceList []string) error { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 1681 | logger.Debugw(ctx, "Migrate Serviec Request Received", log.Fields{"SerialNum": serialNum, "RequestID": reqID, "OldVnet": oldVnetID, "NewVnet": newVnetID, "ServiceList": serviceList}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1682 | if _, ok := va.VnetsByName.Load(oldVnetID); !ok { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 1683 | return errors.New("old vnet id not found") |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1684 | } |
| 1685 | if _, ok := va.VnetsByName.Load(newVnetID); !ok { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 1686 | return errors.New("new vnet id not found") |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1687 | } |
| 1688 | |
Tinoj Joseph | 50d722c | 2022-12-06 22:53:22 +0530 | [diff] [blame] | 1689 | d, _ := va.GetDeviceBySerialNo(serialNum) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1690 | if d == nil { |
| 1691 | logger.Errorw(ctx, "Error Getting Device", log.Fields{"SerialNum": serialNum}) |
| 1692 | return errorCodes.ErrDeviceNotFound |
| 1693 | } |
| 1694 | |
| 1695 | serviceMap := make(map[string]bool) |
| 1696 | |
| 1697 | for _, service := range serviceList { |
| 1698 | serviceMap[service] = false |
| 1699 | } |
| 1700 | msr := newMigrateServicesRequest(reqID, oldVnetID, newVnetID, serviceMap, d.Name) |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 1701 | msr.WriteToDB(cntx) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1702 | |
| 1703 | d.AddMigratingServices(msr) |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 1704 | go msr.ProcessMigrateServicesProfRequest(cntx) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1705 | return nil |
| 1706 | } |
| 1707 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 1708 | // ProcessMigrateServicesProfRequest - collects all associated profiles |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 1709 | func (msr *MigrateServicesRequest) ProcessMigrateServicesProfRequest(cntx context.Context) { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 1710 | logger.Debug(ctx, "Process Migrate Services Prof Request") |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1711 | va := GetApplication() |
| 1712 | for srv, processed := range msr.ServicesList { |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 1713 | // Indicates new service is already created and only deletion of old one is pending |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1714 | if processed { |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 1715 | va.DelService(cntx, srv, true, nil, true) |
| 1716 | msr.serviceMigrated(cntx, srv) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1717 | continue |
| 1718 | } |
| 1719 | |
| 1720 | logger.Infow(ctx, "Migrate Service Triggering", log.Fields{"Service": srv}) |
| 1721 | if vsIntf, ok := va.ServiceByName.Load(srv); ok { |
| 1722 | vs := vsIntf.(*VoltService) |
| 1723 | vpv := va.GetVnetByPort(vs.Port, vs.SVlan, vs.CVlan, vs.UniVlan) |
| 1724 | if vpv == nil { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 1725 | logger.Warnw(ctx, "Vpv Not found for Service", log.Fields{"vs": vs.Name, "port": vs.Port, "Vnet": vs.VnetID}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1726 | continue |
| 1727 | } |
| 1728 | logger.Infow(ctx, "Migrating Service", log.Fields{"Service": vs.Name, "UsFlowApplied": vs.UsHSIAFlowsApplied}) |
| 1729 | vpv.Blocked = true |
| 1730 | |
| 1731 | // setDeactTrigger := func(key, value interface{}) bool { |
| 1732 | // vs := value.(*VoltService) |
| 1733 | vs.ServiceLock.Lock() |
| 1734 | vs.UpdateInProgress = true |
| 1735 | metadata := &MigrateServiceMetadata{ |
| 1736 | NewVnetID: msr.NewVnetID, |
| 1737 | RequestID: msr.ID, |
| 1738 | } |
| 1739 | vs.Metadata = metadata |
| 1740 | vs.ServiceLock.Unlock() |
| 1741 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 1742 | // vpv flows will be removed when last service is removed from it and |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1743 | // new vpv flows will be installed when new service is added |
| 1744 | if vs.UsHSIAFlowsApplied { |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 1745 | vpv.DelTrapFlows(cntx) |
| 1746 | vs.DelHsiaFlows(cntx) |
Tinoj Joseph | 1d10832 | 2022-07-13 10:07:39 +0530 | [diff] [blame] | 1747 | logger.Infow(ctx, "Remove Service Flows Triggered", log.Fields{"Service": srv, "US": vs.UsHSIAFlowsApplied, "DS": vs.DsHSIAFlowsApplied}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1748 | } else { |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 1749 | vs.updateVnetProfile(cntx, msr.DeviceID) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1750 | } |
| 1751 | } else { |
| 1752 | logger.Warnw(ctx, "Migrate Service Failed: Service Not Found", log.Fields{"Service": srv, "Vnet": msr.OldVnetID}) |
| 1753 | } |
| 1754 | } |
| 1755 | } |
| 1756 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 1757 | // AddMigratingServices - store msr info to device obj |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1758 | func (d *VoltDevice) AddMigratingServices(msr *MigrateServicesRequest) { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 1759 | logger.Infow(ctx, "Add Migrating Services", log.Fields{"Vnet": msr.OldVnetID}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1760 | var msrMap *util.ConcurrentMap |
| 1761 | if msrMapIntf, ok := d.MigratingServices.Get(msr.OldVnetID); !ok { |
| 1762 | msrMap = util.NewConcurrentMap() |
| 1763 | } else { |
| 1764 | msrMap = msrMapIntf.(*util.ConcurrentMap) |
| 1765 | } |
| 1766 | |
| 1767 | msrMap.Set(msr.ID, msr) |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 1768 | logger.Debugw(ctx, "1: MsrListLen", log.Fields{"Len": msrMap.Length(), "Vnet": msr.OldVnetID}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1769 | |
| 1770 | d.MigratingServices.Set(msr.OldVnetID, msrMap) |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 1771 | logger.Debugw(ctx, "1: DeviceMsr", log.Fields{"Device": d.Name, "Vnet": msr.OldVnetID, "Len": d.MigratingServices.Length()}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1772 | } |
| 1773 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 1774 | // getMigrateServicesRequest - fetches msr info from device |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1775 | func (va *VoltApplication) getMigrateServicesRequest(deviceID string, oldVnetID string, requestID string) *MigrateServicesRequest { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 1776 | logger.Debugw(ctx, "Get Migrate Services Request", log.Fields{"DeviceID": deviceID, "OldVnetID": oldVnetID, "RequestID": requestID}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1777 | if vd := va.GetDevice(deviceID); vd != nil { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 1778 | logger.Debugw(ctx, "2: DeviceMsr", log.Fields{"Device": deviceID, "Vnet": oldVnetID, "Len": vd.MigratingServices.Length()}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1779 | if msrListIntf, ok := vd.MigratingServices.Get(oldVnetID); ok { |
| 1780 | msrList := msrListIntf.(*util.ConcurrentMap) |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 1781 | logger.Debugw(ctx, "2: MsrListLen", log.Fields{"Len": msrList.Length(), "Vnet": oldVnetID}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1782 | if msrObj, ok := msrList.Get(requestID); ok { |
| 1783 | return msrObj.(*MigrateServicesRequest) |
| 1784 | } |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1785 | } |
| 1786 | } |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 1787 | logger.Warnw(ctx, "Device Not Found", log.Fields{"DeviceID": deviceID}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1788 | return nil |
| 1789 | } |
| 1790 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 1791 | // updateMigrateServicesRequest - Updates the device with updated msr |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1792 | func (va *VoltApplication) updateMigrateServicesRequest(deviceID string, oldVnetID string, requestID string, msr *MigrateServicesRequest) { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 1793 | logger.Debugw(ctx, "Update Migrate Services Request", log.Fields{"DeviceID": deviceID, "OldVnetID": oldVnetID, "RequestID": requestID}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1794 | if vd := va.GetDevice(deviceID); vd != nil { |
| 1795 | if msrList, ok := vd.MigratingServices.Get(oldVnetID); ok { |
| 1796 | if _, ok := msrList.(*util.ConcurrentMap).Get(requestID); ok { |
| 1797 | msrList.(*util.ConcurrentMap).Set(requestID, msr) |
| 1798 | } |
| 1799 | } |
| 1800 | } |
| 1801 | } |
| 1802 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 1803 | // updateVnetProfile - Called on flow process completion |
| 1804 | // Removes old service and creates new VPV & service with updated vnet profile |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 1805 | func (vs *VoltService) updateVnetProfile(cntx context.Context, deviceID string) { |
Tinoj Joseph | 1d10832 | 2022-07-13 10:07:39 +0530 | [diff] [blame] | 1806 | logger.Infow(ctx, "Update Vnet Profile Triggering", log.Fields{"Service": vs.Name, "US": vs.UsHSIAFlowsApplied, "DS": vs.DsHSIAFlowsApplied}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1807 | |
| 1808 | nvs := VoltService{} |
| 1809 | nvs.VoltServiceCfg = vs.VoltServiceCfg |
| 1810 | nvs.Device = vs.Device |
| 1811 | nvs.Ipv4Addr = vs.Ipv4Addr |
| 1812 | nvs.Ipv6Addr = vs.Ipv6Addr |
| 1813 | nvs.UsMeterID = vs.UsMeterID |
| 1814 | nvs.DsMeterID = vs.DsMeterID |
| 1815 | nvs.AggDsMeterID = vs.AggDsMeterID |
| 1816 | nvs.UsHSIAFlowsApplied = vs.UsHSIAFlowsApplied |
| 1817 | nvs.DsHSIAFlowsApplied = vs.DsHSIAFlowsApplied |
| 1818 | nvs.UsDhcpFlowsApplied = vs.UsDhcpFlowsApplied |
| 1819 | nvs.DsDhcpFlowsApplied = vs.DsDhcpFlowsApplied |
| 1820 | nvs.IgmpFlowsApplied = vs.IgmpFlowsApplied |
| 1821 | nvs.Icmpv6FlowsApplied = vs.Icmpv6FlowsApplied |
| 1822 | nvs.PendingFlows = vs.PendingFlows |
| 1823 | nvs.AssociatedFlows = vs.AssociatedFlows |
| 1824 | nvs.DeleteInProgress = vs.DeleteInProgress |
Hitesh Chhabra | 64be244 | 2023-06-21 17:06:34 +0530 | [diff] [blame] | 1825 | nvs.DeactivateInProgress = vs.DeactivateInProgress |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1826 | nvs.ForceDelete = vs.ForceDelete |
| 1827 | nvs.BwAvailInfo = vs.BwAvailInfo |
| 1828 | nvs.UpdateInProgress = vs.UpdateInProgress |
| 1829 | |
| 1830 | if nvs.DeleteInProgress { |
| 1831 | logger.Warnw(ctx, "Skipping Service Migration. Service Delete in Progress", log.Fields{"Device": deviceID, "Service": vs.Name, "Vnet": vs.VnetID}) |
| 1832 | return |
| 1833 | } |
| 1834 | |
| 1835 | metadata := vs.Metadata.(*MigrateServiceMetadata) |
| 1836 | oldVnetID := vs.VnetID |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1837 | oldSrvName := vs.Name |
| 1838 | |
| 1839 | if metadata == nil || metadata.NewVnetID == "" { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 1840 | logger.Warnw(ctx, "Migrate Service Metadata not found. Dropping vnet profile update request", log.Fields{"Service": vs.Name, "Vnet": vs.VnetID}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1841 | return |
| 1842 | } |
| 1843 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 1844 | nvs.VnetID = metadata.NewVnetID |
| 1845 | id := metadata.RequestID |
| 1846 | |
| 1847 | // First add the new service and then only delete the old service |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1848 | // Since if post del service in case of pod crash or reboot, the service data will be lost |
| 1849 | va := GetApplication() |
| 1850 | msr := va.getMigrateServicesRequest(deviceID, oldVnetID, id) |
| 1851 | vnets := strings.Split(metadata.NewVnetID, "-") |
| 1852 | svlan, _ := strconv.Atoi(vnets[0]) |
| 1853 | nvs.SVlan = of.VlanType(svlan) |
| 1854 | nvs.UpdateInProgress = false |
| 1855 | nvs.Metadata = nil |
| 1856 | nvs.Trigger = ServiceVlanUpdate |
| 1857 | |
| 1858 | svcName := vs.Port + "-" + strconv.FormatUint(uint64(nvs.SVlan), 10) + "-" |
| 1859 | svcName = svcName + strconv.FormatUint(uint64(vs.CVlan), 10) + "-" |
| 1860 | nvs.Name = svcName + strconv.FormatUint(uint64(vs.TechProfileID), 10) |
| 1861 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 1862 | // TODO:Nav Pass a copy, not the pointer |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 1863 | logger.Debugw(ctx, "Add New Service Triggering", log.Fields{"Service": nvs.Name, "US": nvs.UsHSIAFlowsApplied, "DS": nvs.DsHSIAFlowsApplied, "DelFlag": nvs.DeleteInProgress}) |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 1864 | if err := va.AddService(cntx, nvs.VoltServiceCfg, &nvs.VoltServiceOper); err != nil { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1865 | logger.Warnw(ctx, "Add New Service Failed", log.Fields{"Service": nvs.Name, "Error": err}) |
| 1866 | } |
| 1867 | logger.Infow(ctx, "Add New Service Triggered", log.Fields{"Service": nvs.Name, "US": nvs.UsHSIAFlowsApplied, "DS": nvs.DsHSIAFlowsApplied, "DelFlag": nvs.DeleteInProgress}) |
| 1868 | |
| 1869 | msr.ServicesList[oldSrvName] = true |
| 1870 | va.updateMigrateServicesRequest(deviceID, oldVnetID, id, msr) |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 1871 | msr.WriteToDB(cntx) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1872 | |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 1873 | logger.Debugw(ctx, "Del Old Service Triggering", log.Fields{"Service": oldSrvName, "US": vs.UsHSIAFlowsApplied, "DS": vs.DsHSIAFlowsApplied, "DelFlag": vs.DeleteInProgress}) |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 1874 | va.DelService(cntx, oldSrvName, true, nil, true) |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 1875 | logger.Debugw(ctx, "Del Old Service Triggered", log.Fields{"Service": oldSrvName, "US": vs.UsHSIAFlowsApplied, "DS": vs.DsHSIAFlowsApplied, "DelFlag": vs.DeleteInProgress}) |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 1876 | msr.serviceMigrated(cntx, oldSrvName) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1877 | } |
| 1878 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 1879 | // serviceMigrated - called on successful service updation |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1880 | // Removes the service entry from servicelist and deletes the request on process completion |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 1881 | func (msr *MigrateServicesRequest) serviceMigrated(cntx context.Context, serviceName string) { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 1882 | logger.Infow(ctx, "Service Migrated", log.Fields{"ServiceName": serviceName}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1883 | msr.MigrateServicesLock.Lock() |
| 1884 | defer msr.MigrateServicesLock.Unlock() |
| 1885 | |
| 1886 | delete(msr.ServicesList, serviceName) |
| 1887 | |
| 1888 | if len(msr.ServicesList) == 0 { |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 1889 | _ = db.DelMigrateServicesReq(cntx, msr.DeviceID, msr.GetMsrKey()) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1890 | return |
| 1891 | } |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 1892 | msr.WriteToDB(cntx) |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 1893 | // TODO:Nav - Need for any Response to SubMgr? |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1894 | } |
| 1895 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 1896 | // TriggerPendingMigrateServicesReq - trigger pending service request |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 1897 | func (va *VoltApplication) TriggerPendingMigrateServicesReq(cntx context.Context, device string) { |
| 1898 | va.FetchAndProcessAllMigrateServicesReq(cntx, device, storeAndProcessMigrateSrvRequest) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1899 | } |
| 1900 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 1901 | // FetchAndProcessAllMigrateServicesReq - fetch all pending migrate services req from DB and process based on provided func |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 1902 | func (va *VoltApplication) FetchAndProcessAllMigrateServicesReq(cntx context.Context, device string, msrAction func(context.Context, *MigrateServicesRequest)) { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 1903 | logger.Infow(ctx, "Fetch all pending migrate services req from DB and process based on provided func", log.Fields{"Device": device}) |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 1904 | msrList, _ := db.GetAllMigrateServicesReq(cntx, device) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1905 | for _, msr := range msrList { |
| 1906 | b, ok := msr.Value.([]byte) |
| 1907 | if !ok { |
| 1908 | logger.Warn(ctx, "The value type is not []byte") |
| 1909 | continue |
| 1910 | } |
| 1911 | msr := va.createMigrateServicesFromString(b) |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 1912 | msrAction(cntx, msr) |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 1913 | logger.Debugw(ctx, "Triggering Pending Migrate Services Req", log.Fields{"OldVnet": msr.OldVnetID, "NewVnet": msr.NewVnetID, "Device": device, "PendingProfiles": len(msr.ServicesList)}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1914 | } |
| 1915 | } |
| 1916 | |
| 1917 | // createMigrateServicesFromString to create Service from string |
| 1918 | func (va *VoltApplication) createMigrateServicesFromString(b []byte) *MigrateServicesRequest { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 1919 | logger.Info(ctx, "Create Migrate Services From String") |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1920 | var msr MigrateServicesRequest |
| 1921 | if err := json.Unmarshal(b, &msr); err == nil { |
| 1922 | logger.Debugw(ctx, "Adding Migrate Services Request From Db", log.Fields{"Vlan": msr.OldVnetID}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1923 | } else { |
| 1924 | logger.Warn(ctx, "Unmarshal failed") |
| 1925 | } |
| 1926 | return &msr |
| 1927 | } |
| 1928 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 1929 | // storeAndProcessMigrateSrvRequest - stores the msr info in device obj and triggers req |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 1930 | func storeAndProcessMigrateSrvRequest(cntx context.Context, msr *MigrateServicesRequest) { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 1931 | logger.Infow(ctx, "Store And Process Migrate Srv Request", log.Fields{"MsrID": msr.DeviceID}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1932 | d := GetApplication().GetDevice(msr.DeviceID) |
| 1933 | d.AddMigratingServices(msr) |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 1934 | msr.ProcessMigrateServicesProfRequest(cntx) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1935 | } |
| 1936 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 1937 | // forceUpdateAllServices - force udpate services with new vnet profile |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 1938 | func forceUpdateAllServices(cntx context.Context, msr *MigrateServicesRequest) { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 1939 | logger.Infow(ctx, "Force udpate services with new vnet profile", log.Fields{"MsrID": msr.NewVnetID}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1940 | for srv := range msr.ServicesList { |
| 1941 | if vsIntf, ok := GetApplication().ServiceByName.Load(srv); ok { |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 1942 | vsIntf.(*VoltService).updateVnetProfile(cntx, msr.DeviceID) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1943 | } |
| 1944 | } |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 1945 | _ = db.DelMigrateServicesReq(cntx, msr.DeviceID, msr.GetMsrKey()) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1946 | } |
| 1947 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 1948 | // nolint: gocyclo |
| 1949 | // DeepEqualServicecfg - checks if the given service cfgs are same |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1950 | func (va *VoltApplication) DeepEqualServicecfg(evs *VoltServiceCfg, nvs *VoltServiceCfg) bool { |
| 1951 | if nvs.Name != evs.Name { |
| 1952 | return false |
| 1953 | } |
| 1954 | if nvs.UniVlan != evs.UniVlan { |
| 1955 | return false |
| 1956 | } |
| 1957 | if nvs.CVlan != evs.CVlan { |
| 1958 | return false |
| 1959 | } |
| 1960 | if nvs.SVlan != evs.SVlan { |
| 1961 | return false |
| 1962 | } |
| 1963 | if nvs.SVlanTpid != 0 && nvs.SVlanTpid != evs.SVlanTpid { |
| 1964 | return false |
| 1965 | } |
| 1966 | if !util.IsPbitSliceSame(nvs.Pbits, evs.Pbits) { |
| 1967 | return false |
| 1968 | } |
| 1969 | if !reflect.DeepEqual(nvs.DsRemarkPbitsMap, evs.DsRemarkPbitsMap) { |
| 1970 | return false |
| 1971 | } |
| 1972 | if nvs.TechProfileID != evs.TechProfileID { |
| 1973 | return false |
| 1974 | } |
| 1975 | if nvs.CircuitID != evs.CircuitID { |
| 1976 | return false |
| 1977 | } |
| 1978 | if !bytes.Equal(nvs.RemoteID, evs.RemoteID) { |
| 1979 | return false |
| 1980 | } |
| 1981 | if nvs.Port != evs.Port { |
| 1982 | return false |
| 1983 | } |
| 1984 | if nvs.PonPort != evs.PonPort { |
| 1985 | return false |
| 1986 | } |
| 1987 | if evs.MacLearning == MacLearningNone && !util.MacAddrsMatch(nvs.MacAddr, evs.MacAddr) { |
| 1988 | return false |
| 1989 | } |
Hitesh Chhabra | 9f9a9df | 2023-06-13 17:52:15 +0530 | [diff] [blame] | 1990 | if nvs.IsOption82Enabled != evs.IsOption82Enabled { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1991 | return false |
| 1992 | } |
| 1993 | if nvs.IgmpEnabled != evs.IgmpEnabled { |
| 1994 | return false |
| 1995 | } |
| 1996 | if nvs.McastService != evs.McastService { |
| 1997 | return false |
| 1998 | } |
| 1999 | if nvs.ONTEtherTypeClassification != evs.ONTEtherTypeClassification { |
| 2000 | return false |
| 2001 | } |
| 2002 | if nvs.UsMeterProfile != evs.UsMeterProfile { |
| 2003 | return false |
| 2004 | } |
| 2005 | if nvs.DsMeterProfile != evs.DsMeterProfile { |
| 2006 | return false |
| 2007 | } |
| 2008 | if nvs.AggDsMeterProfile != evs.AggDsMeterProfile { |
| 2009 | return false |
| 2010 | } |
| 2011 | if nvs.VnetID != evs.VnetID { |
| 2012 | return false |
| 2013 | } |
| 2014 | if nvs.MvlanProfileName != evs.MvlanProfileName { |
| 2015 | return false |
| 2016 | } |
| 2017 | if nvs.RemoteIDType != evs.RemoteIDType { |
| 2018 | return false |
| 2019 | } |
| 2020 | if nvs.SchedID != evs.SchedID { |
| 2021 | return false |
| 2022 | } |
| 2023 | if nvs.AllowTransparent != evs.AllowTransparent { |
| 2024 | return false |
| 2025 | } |
| 2026 | if nvs.EnableMulticastKPI != evs.EnableMulticastKPI { |
| 2027 | return false |
| 2028 | } |
| 2029 | if nvs.DataRateAttr != evs.DataRateAttr { |
| 2030 | return false |
| 2031 | } |
| 2032 | if nvs.MinDataRateUs != evs.MinDataRateUs { |
| 2033 | return false |
| 2034 | } |
| 2035 | if nvs.MinDataRateDs != evs.MinDataRateDs { |
| 2036 | return false |
| 2037 | } |
| 2038 | if nvs.MaxDataRateUs != evs.MaxDataRateUs { |
| 2039 | return false |
| 2040 | } |
| 2041 | if nvs.MaxDataRateDs != evs.MaxDataRateDs { |
| 2042 | return false |
| 2043 | } |
| 2044 | |
| 2045 | return true |
| 2046 | } |
| 2047 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 2048 | // TriggerAssociatedFlowDelete - re-trigger service flow delete for pending delete flows |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 2049 | func (vs *VoltService) TriggerAssociatedFlowDelete(cntx context.Context) bool { |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 2050 | // Clear the Flows flag if already set |
| 2051 | // This case happens only in case of some race condition |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 2052 | logger.Infow(ctx, "Trigger Associated Flow Delete", log.Fields{"Device": vs.Device, "Service": vs.Name}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 2053 | if vs.UsHSIAFlowsApplied { |
Sridhar Ravindra | 03aa0bf | 2023-09-12 17:46:40 +0530 | [diff] [blame] | 2054 | if err := vs.DelUsHsiaFlows(cntx, false); err != nil { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 2055 | logger.Warnw(ctx, "DelUsHsiaFlows Failed", log.Fields{"Device": vs.Device, "Service": vs.Name, "Error": err}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 2056 | } |
| 2057 | } |
| 2058 | |
| 2059 | if vs.DsHSIAFlowsApplied { |
Sridhar Ravindra | 03aa0bf | 2023-09-12 17:46:40 +0530 | [diff] [blame] | 2060 | if err := vs.DelDsHsiaFlows(cntx, false); err != nil { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 2061 | logger.Warnw(ctx, "DelDsHsiaFlows Failed", log.Fields{"Device": vs.Device, "Service": vs.Name, "Error": err}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 2062 | } |
| 2063 | } |
| 2064 | |
| 2065 | vs.ServiceLock.Lock() |
| 2066 | cookieList := []uint64{} |
| 2067 | for cookie := range vs.AssociatedFlows { |
| 2068 | cookieList = append(cookieList, convertToUInt64(cookie)) |
| 2069 | } |
| 2070 | vs.ServiceLock.Unlock() |
| 2071 | |
| 2072 | if len(cookieList) == 0 { |
| 2073 | return false |
| 2074 | } |
| 2075 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 2076 | // Trigger Flow Delete |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 2077 | for _, cookie := range cookieList { |
| 2078 | if vd := GetApplication().GetDevice(vs.Device); vd != nil { |
| 2079 | flow := &of.VoltFlow{} |
| 2080 | flow.SubFlows = make(map[uint64]*of.VoltSubFlow) |
| 2081 | subFlow := of.NewVoltSubFlow() |
| 2082 | subFlow.Cookie = cookie |
| 2083 | flow.SubFlows[cookie] = subFlow |
| 2084 | logger.Infow(ctx, "Retriggering Service Delete Flow", log.Fields{"Device": vs.Device, "Service": vs.Name, "Cookie": cookie}) |
Sridhar Ravindra | 03aa0bf | 2023-09-12 17:46:40 +0530 | [diff] [blame] | 2085 | if err := vs.DelFlows(cntx, vd, flow, false); err != nil { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 2086 | logger.Warnw(ctx, "DelFlows Failed", log.Fields{"Device": vs.Device, "Service": vs.Name, "Cookie": cookie, "Error": err}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 2087 | } |
| 2088 | } |
| 2089 | } |
| 2090 | return true |
| 2091 | } |
| 2092 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 2093 | // triggerServiceInProgressInd - Indication is generated when Service is not provisioned after add serviec req from NB |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 2094 | func (vs *VoltService) triggerServiceInProgressInd() { |
| 2095 | } |
Tinoj Joseph | c2ccd6b | 2022-07-19 04:32:15 +0530 | [diff] [blame] | 2096 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 2097 | // JSONMarshal wrapper function for json Marshal VoltService |
| 2098 | func (vs *VoltService) JSONMarshal() ([]byte, error) { |
Tinoj Joseph | c2ccd6b | 2022-07-19 04:32:15 +0530 | [diff] [blame] | 2099 | return json.Marshal(VoltService{ |
| 2100 | VoltServiceCfg: vs.VoltServiceCfg, |
| 2101 | VoltServiceOper: VoltServiceOper{ |
Hitesh Chhabra | 64be244 | 2023-06-21 17:06:34 +0530 | [diff] [blame] | 2102 | Device: vs.VoltServiceOper.Device, |
| 2103 | Ipv4Addr: vs.VoltServiceOper.Ipv4Addr, |
| 2104 | Ipv6Addr: vs.VoltServiceOper.Ipv6Addr, |
| 2105 | UsMeterID: vs.VoltServiceOper.UsMeterID, |
| 2106 | DsMeterID: vs.VoltServiceOper.DsMeterID, |
| 2107 | AggDsMeterID: vs.VoltServiceOper.AggDsMeterID, |
| 2108 | UsHSIAFlowsApplied: vs.VoltServiceOper.UsHSIAFlowsApplied, |
| 2109 | DsHSIAFlowsApplied: vs.VoltServiceOper.DsHSIAFlowsApplied, |
| 2110 | UsDhcpFlowsApplied: vs.VoltServiceOper.UsDhcpFlowsApplied, |
| 2111 | DsDhcpFlowsApplied: vs.VoltServiceOper.DsDhcpFlowsApplied, |
| 2112 | IgmpFlowsApplied: vs.VoltServiceOper.IgmpFlowsApplied, |
| 2113 | Icmpv6FlowsApplied: vs.VoltServiceOper.Icmpv6FlowsApplied, |
| 2114 | PendingFlows: vs.VoltServiceOper.PendingFlows, |
| 2115 | AssociatedFlows: vs.VoltServiceOper.AssociatedFlows, |
| 2116 | DeleteInProgress: vs.VoltServiceOper.DeleteInProgress, |
| 2117 | DeactivateInProgress: vs.VoltServiceOper.DeactivateInProgress, |
| 2118 | ForceDelete: vs.VoltServiceOper.ForceDelete, |
| 2119 | BwAvailInfo: vs.VoltServiceOper.BwAvailInfo, |
| 2120 | UpdateInProgress: vs.VoltServiceOper.UpdateInProgress, |
| 2121 | Metadata: vs.VoltServiceOper.Metadata, |
Tinoj Joseph | c2ccd6b | 2022-07-19 04:32:15 +0530 | [diff] [blame] | 2122 | }, |
| 2123 | }) |
| 2124 | } |
Tinoj Joseph | ec742f6 | 2022-09-29 19:11:10 +0530 | [diff] [blame] | 2125 | |
| 2126 | // GetProgrammedSubscribers to get list of programmed subscribers |
Tinoj Joseph | d5b4f2f | 2022-11-11 19:25:24 +0530 | [diff] [blame] | 2127 | func (va *VoltApplication) GetProgrammedSubscribers(cntx context.Context, deviceID, portNo string) ([]*VoltService, error) { |
Tinoj Joseph | ec742f6 | 2022-09-29 19:11:10 +0530 | [diff] [blame] | 2128 | var svcList []*VoltService |
| 2129 | logger.Infow(ctx, "GetProgrammedSubscribers Request ", log.Fields{"Device": deviceID, "Port": portNo}) |
| 2130 | va.ServiceByName.Range(func(key, value interface{}) bool { |
| 2131 | vs := value.(*VoltService) |
Tinoj Joseph | d5b4f2f | 2022-11-11 19:25:24 +0530 | [diff] [blame] | 2132 | if len(deviceID) > 0 { |
| 2133 | if len(portNo) > 0 { |
Tinoj Joseph | ec742f6 | 2022-09-29 19:11:10 +0530 | [diff] [blame] | 2134 | if deviceID == vs.Device && portNo == vs.Port { |
| 2135 | svcList = append(svcList, vs) |
| 2136 | } |
| 2137 | } else { |
| 2138 | if deviceID == vs.Device { |
| 2139 | svcList = append(svcList, vs) |
| 2140 | } |
| 2141 | } |
| 2142 | } else { |
| 2143 | svcList = append(svcList, vs) |
| 2144 | } |
| 2145 | return true |
| 2146 | }) |
| 2147 | return svcList, nil |
| 2148 | } |
| 2149 | |
Akash Soni | 634d9bf | 2023-07-10 12:11:10 +0530 | [diff] [blame] | 2150 | type FlowProvisionStatus struct { |
| 2151 | FlowProvisionStatus string |
| 2152 | } |
| 2153 | |
| 2154 | // GetFlowProvisionStatus to get status of the subscriber and flow provisioned in controller |
Akash Soni | 3c391e7 | 2023-08-16 12:21:33 +0530 | [diff] [blame] | 2155 | func (va *VoltApplication) GetFlowProvisionStatus(portNo string) FlowProvisionStatus { |
Akash Soni | 634d9bf | 2023-07-10 12:11:10 +0530 | [diff] [blame] | 2156 | logger.Infow(ctx, "GetFlowProvisionStatus Request ", log.Fields{"Port": portNo}) |
| 2157 | flowProvisionStatus := FlowProvisionStatus{} |
Akash Soni | 3c391e7 | 2023-08-16 12:21:33 +0530 | [diff] [blame] | 2158 | flowProvisionStatus.FlowProvisionStatus = SUBSCRIBER_NOT_IN_CONTROLLER |
Akash Soni | 634d9bf | 2023-07-10 12:11:10 +0530 | [diff] [blame] | 2159 | va.ServiceByName.Range(func(key, value interface{}) bool { |
| 2160 | vs := value.(*VoltService) |
| 2161 | logger.Debugw(ctx, "Volt Service ", log.Fields{"VS": vs}) |
Akash Soni | 3c391e7 | 2023-08-16 12:21:33 +0530 | [diff] [blame] | 2162 | if portNo == vs.Port { |
| 2163 | if vs.DsHSIAFlowsApplied && vs.UsHSIAFlowsApplied && vs.LenOfPendingFlows() == 0 { |
| 2164 | flowProvisionStatus.FlowProvisionStatus = ALL_FLOWS_PROVISIONED |
| 2165 | return false |
| 2166 | } else if !vs.IsActivated { |
| 2167 | flowProvisionStatus.FlowProvisionStatus = SUBSCRIBER_DISABLED_IN_CONTROLLER |
| 2168 | return false |
| 2169 | } else if !vs.DsHSIAFlowsApplied && !vs.UsHSIAFlowsApplied { |
| 2170 | flowProvisionStatus.FlowProvisionStatus = NO_FLOWS_PROVISIONED |
| 2171 | return false |
Akash Soni | 230e621 | 2023-10-16 10:46:07 +0530 | [diff] [blame] | 2172 | } else if vs.DsHSIAFlowsApplied && vs.UsHSIAFlowsApplied && vs.LenOfPendingFlows() > 0 { |
Akash Soni | 3c391e7 | 2023-08-16 12:21:33 +0530 | [diff] [blame] | 2173 | flowProvisionStatus.FlowProvisionStatus = FLOWS_PROVISIONED_PARTIALLY |
| 2174 | return false |
Akash Soni | 634d9bf | 2023-07-10 12:11:10 +0530 | [diff] [blame] | 2175 | } |
| 2176 | } |
| 2177 | return true |
| 2178 | }) |
Akash Soni | 634d9bf | 2023-07-10 12:11:10 +0530 | [diff] [blame] | 2179 | return flowProvisionStatus |
| 2180 | } |
| 2181 | |
| 2182 | func (vs *VoltService) LenOfPendingFlows() int { |
| 2183 | vs.ServiceLock.RLock() |
| 2184 | lth := len(vs.PendingFlows) |
| 2185 | vs.ServiceLock.RUnlock() |
| 2186 | return lth |
| 2187 | } |
| 2188 | |
Tinoj Joseph | ec742f6 | 2022-09-29 19:11:10 +0530 | [diff] [blame] | 2189 | // ActivateService to activate pre-provisioned service |
Tinoj Joseph | af37ce8 | 2022-12-28 11:59:43 +0530 | [diff] [blame] | 2190 | func (va *VoltApplication) ActivateService(cntx context.Context, deviceID, portNo string, sVlan, cVlan of.VlanType, tpID uint16) error { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 2191 | logger.Infow(ctx, "Service Activate Request ", log.Fields{"Device": deviceID, "Port": portNo, "Svaln": sVlan, "Cvlan": cVlan, "TpID": tpID}) |
Tinoj Joseph | af37ce8 | 2022-12-28 11:59:43 +0530 | [diff] [blame] | 2192 | device, err := va.GetDeviceFromPort(portNo) |
| 2193 | if err != nil { |
Sridhar Ravindra | f8251e7 | 2023-09-06 17:09:30 +0530 | [diff] [blame] | 2194 | // Lets activate the service even though port was not found. We will push the flows once the port is added by voltha |
| 2195 | logger.Warnw(ctx, "Couldn't get device for port, continuing with service activation", log.Fields{"Reason": err.Error(), "Port": portNo}) |
Tinoj Joseph | af37ce8 | 2022-12-28 11:59:43 +0530 | [diff] [blame] | 2196 | } |
| 2197 | // If device id is not provided check only port number |
Sridhar Ravindra | f8251e7 | 2023-09-06 17:09:30 +0530 | [diff] [blame] | 2198 | if device != nil { |
| 2199 | if deviceID == DeviceAny { |
| 2200 | deviceID = device.Name |
| 2201 | } else if deviceID != device.Name { |
Sridhar Ravindra | 3ec1423 | 2024-01-01 19:11:48 +0530 | [diff] [blame] | 2202 | err := errorCodes.ErrDeviceNotFound |
| 2203 | return fmt.Errorf("wrong device id %s : %w", deviceID, err) |
Sridhar Ravindra | f8251e7 | 2023-09-06 17:09:30 +0530 | [diff] [blame] | 2204 | } |
Tinoj Joseph | af37ce8 | 2022-12-28 11:59:43 +0530 | [diff] [blame] | 2205 | } |
Tinoj Joseph | ec742f6 | 2022-09-29 19:11:10 +0530 | [diff] [blame] | 2206 | va.ServiceByName.Range(func(key, value interface{}) bool { |
| 2207 | vs := value.(*VoltService) |
Tinoj Joseph | ec742f6 | 2022-09-29 19:11:10 +0530 | [diff] [blame] | 2208 | // If svlan if provided, then the tags and tpID of service has to be matching |
Tinoj Joseph | d5b4f2f | 2022-11-11 19:25:24 +0530 | [diff] [blame] | 2209 | if sVlan != of.VlanNone && (sVlan != vs.SVlan || cVlan != vs.CVlan || tpID != vs.TechProfileID) { |
Sridhar Ravindra | 3ec1423 | 2024-01-01 19:11:48 +0530 | [diff] [blame] | 2210 | logger.Warnw(ctx, "Service Activate Request Does not match", log.Fields{"Device": deviceID, "voltService": vs}) |
Tinoj Joseph | ec742f6 | 2022-09-29 19:11:10 +0530 | [diff] [blame] | 2211 | return true |
| 2212 | } |
| 2213 | if portNo == vs.Port && !vs.IsActivated { |
Sridhar Ravindra | f8251e7 | 2023-09-06 17:09:30 +0530 | [diff] [blame] | 2214 | // Mark the service as activated, so that we can push the flows later when the port is added by voltha |
Sridhar Ravindra | 3ec1423 | 2024-01-01 19:11:48 +0530 | [diff] [blame] | 2215 | logger.Debugw(ctx, "Service Activate", log.Fields{"Name": vs.Name}) |
Tinoj Joseph | ec742f6 | 2022-09-29 19:11:10 +0530 | [diff] [blame] | 2216 | vs.IsActivated = true |
| 2217 | va.ServiceByName.Store(vs.Name, vs) |
| 2218 | vs.WriteToDb(cntx) |
Sridhar Ravindra | f8251e7 | 2023-09-06 17:09:30 +0530 | [diff] [blame] | 2219 | |
| 2220 | // Push the flows only if the port is already added and we have a valid device |
| 2221 | if device != nil { |
| 2222 | p := device.GetPort(vs.Port) |
| 2223 | if p == nil { |
| 2224 | logger.Warnw(ctx, "Wrong device or port", log.Fields{"Device": deviceID, "Port": portNo}) |
| 2225 | return true |
| 2226 | } |
| 2227 | // If port is already up send indication to vpv |
| 2228 | if p.State == PortStateUp { |
| 2229 | if vpv := va.GetVnetByPort(vs.Port, vs.SVlan, vs.CVlan, vs.UniVlan); vpv != nil { |
| 2230 | // PortUp call initiates flow addition |
| 2231 | vpv.PortUpInd(cntx, device, portNo) |
| 2232 | } else { |
| 2233 | logger.Warnw(ctx, "VPV does not exists!!!", log.Fields{"Device": deviceID, "port": portNo, "SvcName": vs.Name}) |
| 2234 | } |
Tinoj Joseph | ec742f6 | 2022-09-29 19:11:10 +0530 | [diff] [blame] | 2235 | } |
| 2236 | } |
| 2237 | } |
| 2238 | return true |
| 2239 | }) |
Tinoj Joseph | af37ce8 | 2022-12-28 11:59:43 +0530 | [diff] [blame] | 2240 | return nil |
Tinoj Joseph | ec742f6 | 2022-09-29 19:11:10 +0530 | [diff] [blame] | 2241 | } |
| 2242 | |
Sridhar Ravindra | 3ec1423 | 2024-01-01 19:11:48 +0530 | [diff] [blame] | 2243 | func (vs *VoltService) SetSvcDeactivationFlags(deactivateRsn SvcDeactivateReason) { |
| 2244 | vs.DeactivateInProgress = true |
| 2245 | vs.IsActivated = false |
| 2246 | vs.ServiceDeactivateReason = deactivateRsn |
| 2247 | } |
| 2248 | |
Tinoj Joseph | ec742f6 | 2022-09-29 19:11:10 +0530 | [diff] [blame] | 2249 | // DeactivateService to activate pre-provisioned service |
Tinoj Joseph | af37ce8 | 2022-12-28 11:59:43 +0530 | [diff] [blame] | 2250 | func (va *VoltApplication) DeactivateService(cntx context.Context, deviceID, portNo string, sVlan, cVlan of.VlanType, tpID uint16) error { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 2251 | logger.Infow(ctx, "Service Deactivate Request ", log.Fields{"Device": deviceID, "Port": portNo, "Svaln": sVlan, "Cvlan": cVlan, "TpID": tpID}) |
Hitesh Chhabra | 7d249a0 | 2023-07-04 21:33:49 +0530 | [diff] [blame] | 2252 | |
Tinoj Joseph | ec742f6 | 2022-09-29 19:11:10 +0530 | [diff] [blame] | 2253 | va.ServiceByName.Range(func(key, value interface{}) bool { |
| 2254 | vs := value.(*VoltService) |
| 2255 | // If svlan if provided, then the tags and tpID of service has to be matching |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 2256 | logger.Debugw(ctx, "Service Deactivate Request ", log.Fields{"Device": deviceID, "Port": portNo}) |
Tinoj Joseph | d5b4f2f | 2022-11-11 19:25:24 +0530 | [diff] [blame] | 2257 | if sVlan != of.VlanNone && (sVlan != vs.SVlan || cVlan != vs.CVlan || tpID != vs.TechProfileID) { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 2258 | logger.Warnw(ctx, "condition not matched", log.Fields{"Device": deviceID, "Port": portNo, "sVlan": sVlan, "cVlan": cVlan, "tpID": tpID}) |
Tinoj Joseph | ec742f6 | 2022-09-29 19:11:10 +0530 | [diff] [blame] | 2259 | return true |
| 2260 | } |
Tinoj Joseph | af37ce8 | 2022-12-28 11:59:43 +0530 | [diff] [blame] | 2261 | if portNo == vs.Port && vs.IsActivated { |
Sridhar Ravindra | 3ec1423 | 2024-01-01 19:11:48 +0530 | [diff] [blame] | 2262 | vs.SetSvcDeactivationFlags(SvcDeacRsn_NB) |
Tinoj Joseph | ec742f6 | 2022-09-29 19:11:10 +0530 | [diff] [blame] | 2263 | va.ServiceByName.Store(vs.Name, vs) |
| 2264 | vs.WriteToDb(cntx) |
Tinoj Joseph | 4ead4e0 | 2023-01-30 03:12:44 +0530 | [diff] [blame] | 2265 | device, err := va.GetDeviceFromPort(portNo) |
| 2266 | if err != nil { |
| 2267 | // Even if the port/device does not exists at this point in time, the deactivate request is succss. |
| 2268 | // So no error is returned |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 2269 | logger.Warnw(ctx, "Error Getting Device", log.Fields{"Reason": err.Error(), "Port": portNo}) |
Tinoj Joseph | 4ead4e0 | 2023-01-30 03:12:44 +0530 | [diff] [blame] | 2270 | return true |
| 2271 | } |
Tinoj Joseph | af37ce8 | 2022-12-28 11:59:43 +0530 | [diff] [blame] | 2272 | p := device.GetPort(vs.Port) |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 2273 | if p != nil && (p.State == PortStateUp || !va.OltFlowServiceConfig.RemoveFlowsOnDisable) { |
Tinoj Joseph | ec742f6 | 2022-09-29 19:11:10 +0530 | [diff] [blame] | 2274 | if vpv := va.GetVnetByPort(vs.Port, vs.SVlan, vs.CVlan, vs.UniVlan); vpv != nil { |
| 2275 | // Port down call internally deletes all the flows |
Sridhar Ravindra | 03aa0bf | 2023-09-12 17:46:40 +0530 | [diff] [blame] | 2276 | vpv.PortDownInd(cntx, deviceID, portNo, true, false) |
Tinoj Joseph | ec742f6 | 2022-09-29 19:11:10 +0530 | [diff] [blame] | 2277 | if vpv.IgmpEnabled { |
| 2278 | va.ReceiverDownInd(cntx, deviceID, portNo) |
| 2279 | } |
Hitesh Chhabra | 64be244 | 2023-06-21 17:06:34 +0530 | [diff] [blame] | 2280 | vs.DeactivateInProgress = false |
Tinoj Joseph | ec742f6 | 2022-09-29 19:11:10 +0530 | [diff] [blame] | 2281 | } else { |
| 2282 | logger.Warnw(ctx, "VPV does not exists!!!", log.Fields{"Device": deviceID, "port": portNo, "SvcName": vs.Name}) |
| 2283 | } |
| 2284 | } |
| 2285 | } |
| 2286 | return true |
| 2287 | }) |
Tinoj Joseph | af37ce8 | 2022-12-28 11:59:43 +0530 | [diff] [blame] | 2288 | return nil |
Tinoj Joseph | ec742f6 | 2022-09-29 19:11:10 +0530 | [diff] [blame] | 2289 | } |
Tinoj Joseph | 4ead4e0 | 2023-01-30 03:12:44 +0530 | [diff] [blame] | 2290 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 2291 | // GetServicePbit to get first set bit in the pbit map |
| 2292 | // returns -1 : If configured to match on all pbits |
| 2293 | // returns 8 : If no pbits are configured |
| 2294 | // returns first pbit if specific pbit is configured |
Tinoj Joseph | ec742f6 | 2022-09-29 19:11:10 +0530 | [diff] [blame] | 2295 | func (vs *VoltService) GetServicePbit() int { |
| 2296 | if vs.IsPbitExist(of.PbitMatchAll) { |
| 2297 | return -1 |
| 2298 | } |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 2299 | for pbit := 0; pbit < int(of.PbitMatchNone); pbit++ { |
Tinoj Joseph | ec742f6 | 2022-09-29 19:11:10 +0530 | [diff] [blame] | 2300 | if vs.IsPbitExist(of.PbitType(pbit)) { |
| 2301 | return pbit |
| 2302 | } |
| 2303 | } |
| 2304 | return int(of.PbitMatchNone) |
| 2305 | } |