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