Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2022-present Open Networking Foundation |
| 3 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | * you may not use this file except in compliance with the License. |
| 5 | * You may obtain a copy of the License at |
| 6 | * |
| 7 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | * |
| 9 | * Unless required by applicable law or agreed to in writing, software |
| 10 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | * See the License for the specific language governing permissions and |
| 13 | * limitations under the License. |
| 14 | */ |
| 15 | |
| 16 | package application |
| 17 | |
| 18 | import ( |
Akash Soni | a824697 | 2023-01-03 10:37:08 +0530 | [diff] [blame] | 19 | "context" |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 20 | "encoding/json" |
| 21 | "errors" |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 22 | "fmt" |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 23 | "net" |
vinokuma | 04dc9f8 | 2023-07-31 15:47:49 +0530 | [diff] [blame] | 24 | "reflect" |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 25 | "strconv" |
| 26 | "sync" |
| 27 | "time" |
| 28 | |
Akash Soni | a824697 | 2023-01-03 10:37:08 +0530 | [diff] [blame] | 29 | //errorCodes "voltha-go-controller/internal/pkg/errorcodes" |
| 30 | |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 31 | "github.com/google/gopacket" |
| 32 | "github.com/google/gopacket/layers" |
| 33 | "go.uber.org/atomic" |
| 34 | |
Akash Soni | a824697 | 2023-01-03 10:37:08 +0530 | [diff] [blame] | 35 | "voltha-go-controller/database" |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 36 | "voltha-go-controller/internal/pkg/controller" |
| 37 | cntlr "voltha-go-controller/internal/pkg/controller" |
Akash Soni | a824697 | 2023-01-03 10:37:08 +0530 | [diff] [blame] | 38 | |
| 39 | errorCodes "voltha-go-controller/internal/pkg/errorcodes" |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 40 | "voltha-go-controller/internal/pkg/of" |
| 41 | "voltha-go-controller/internal/pkg/util" |
Tinoj Joseph | 1d10832 | 2022-07-13 10:07:39 +0530 | [diff] [blame] | 42 | "voltha-go-controller/log" |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 43 | ) |
| 44 | |
| 45 | const ( |
| 46 | // ICMPv6ArpGroupID constant |
| 47 | ICMPv6ArpGroupID uint32 = 1 |
| 48 | |
| 49 | // Radisys vendor id constant |
| 50 | Radisys string = "Radisys" |
Tinoj Joseph | 50d722c | 2022-12-06 22:53:22 +0530 | [diff] [blame] | 51 | |
| 52 | // DPU_MGMT_TRAFFIC serviceType, vnetType constant |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 53 | DpuMgmtTraffic string = "DPU_MGMT_TRAFFIC" |
Tinoj Joseph | 50d722c | 2022-12-06 22:53:22 +0530 | [diff] [blame] | 54 | |
| 55 | // DPU_ANCP_TRAFFIC serviceType, vnetType constant |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 56 | DpuAncpTraffic string = "DPU_ANCP_TRAFFIC" |
Tinoj Joseph | 50d722c | 2022-12-06 22:53:22 +0530 | [diff] [blame] | 57 | |
| 58 | // FTTB_SUBSCRIBER_TRAFFIC serviceType, vnetType constant |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 59 | FttbSubscriberTraffic string = "FTTB_SUBSCRIBER_TRAFFIC" |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 60 | ) |
| 61 | |
| 62 | var ( |
| 63 | //BroadcastMAC - Broadcast MAC Address |
| 64 | BroadcastMAC, _ = net.ParseMAC("ff:ff:ff:ff:ff:ff") |
| 65 | ) |
| 66 | |
| 67 | // NonZeroMacAddress utility to identify if the MAC address is non-zero. |
| 68 | // We use zero MAC address as an unset MAC address |
| 69 | func NonZeroMacAddress(h net.HardwareAddr) bool { |
| 70 | for i := 0; i < 6; i++ { |
| 71 | if h[i] != 0 { |
| 72 | return true |
| 73 | } |
| 74 | } |
| 75 | return false |
| 76 | } |
| 77 | |
| 78 | // VNET package manages the different virtual networks that are part of the |
| 79 | // the network. In the case of VOLT, the networks can be single tagged or |
| 80 | // double tagged networks. In addition, the networks may be used for unicast |
| 81 | // and multicast traffic. The unicast traffic further has two models, the |
| 82 | // 1:1 and N:1 model. In case of a 1:1 model, the outer tag is same for many |
| 83 | // subscribers and the inner tag is unique to each subscriber for the same |
| 84 | // outer tag. The N:1 uses the same inner and outer tags, or for that matter |
| 85 | // a single tag that can also be shared by subscribers. The VNET implementation |
| 86 | // manages all these possibilities and the associated configuration. |
| 87 | |
| 88 | const ( |
| 89 | // PbitMatchNone constant |
| 90 | PbitMatchNone of.PbitType = 8 |
| 91 | // PbitMatchAll constant |
| 92 | PbitMatchAll of.PbitType = 0xFF |
| 93 | ) |
| 94 | |
| 95 | // SVlan - Value of the outer tag if double tagged or the only tag if single |
| 96 | // tagged |
| 97 | // SVlanTpid - SVlan Tag Protocol Identifier |
| 98 | // CVlan - Value of the inner tag. Set to VlanNone if single tagged |
| 99 | // DhcpRelay - Set to true if the DHCP relay is enabled on the virtual network |
| 100 | // MacLearning - Set to true if the flows should include MAC address |
| 101 | // UsDhcpPbit - The pbit used for US DHCP packets |
| 102 | // DsDhcpPbit - The pbit used for DS DHCP packets |
| 103 | |
| 104 | // VnetConfig structure |
| 105 | type VnetConfig struct { |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 106 | CtrlPktPbitRemark map[of.PbitType]of.PbitType |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 107 | Name string |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 108 | VnetType string |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 109 | Encapsulation string |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 110 | DevicesList []string //List of serial number of devices on which this vnet is applied |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 111 | UsDhcpPbit []of.PbitType |
| 112 | DsDhcpPbit []of.PbitType |
| 113 | UsIGMPPbit []of.PbitType |
| 114 | DsIGMPPbit []of.PbitType |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 115 | ONTEtherTypeClassification int |
| 116 | MacLearning MacLearningType |
Tinoj Joseph | 50d722c | 2022-12-06 22:53:22 +0530 | [diff] [blame] | 117 | UsPonCTagPriority of.PbitType |
| 118 | UsPonSTagPriority of.PbitType |
| 119 | DsPonCTagPriority of.PbitType |
| 120 | DsPonSTagPriority of.PbitType |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 121 | SVlan of.VlanType |
| 122 | CVlan of.VlanType |
| 123 | UniVlan of.VlanType |
| 124 | SVlanTpid layers.EthernetType |
| 125 | VlanControl VlanControl |
| 126 | DhcpRelay bool |
| 127 | ArpLearning bool |
| 128 | AllowTransparent bool |
| 129 | PppoeIa bool |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 130 | } |
| 131 | |
| 132 | // VnetOper structure |
| 133 | type VnetOper struct { |
| 134 | PendingDeleteFlow map[string]map[string]bool |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 135 | AssociatedPorts map[string]bool `json:"-"` |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 136 | PendingDeviceToDelete string |
| 137 | VnetLock sync.RWMutex `json:"-"` |
| 138 | VnetPortLock sync.RWMutex `json:"-"` |
| 139 | DeleteInProgress bool |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 140 | } |
| 141 | |
| 142 | // VoltVnet sructure |
| 143 | type VoltVnet struct { |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 144 | Version string |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 145 | VnetConfig |
| 146 | VnetOper |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 147 | } |
| 148 | |
| 149 | const ( |
| 150 | // EncapsulationPPPoEIA constant |
| 151 | EncapsulationPPPoEIA string = "PPPoE-IA" |
| 152 | // EncapsulationPPPoE constant |
| 153 | EncapsulationPPPoE string = "PPPoE" |
| 154 | // EncapsulationIPoE constant |
| 155 | EncapsulationIPoE string = "IPoE" |
| 156 | ) |
| 157 | |
| 158 | // NewVoltVnet is constructor for the VNET structure |
| 159 | func NewVoltVnet(cfg VnetConfig) *VoltVnet { |
| 160 | var vv VoltVnet |
| 161 | vv.VnetConfig = cfg |
| 162 | if vv.PendingDeleteFlow == nil { |
| 163 | vv.PendingDeleteFlow = make(map[string]map[string]bool) |
| 164 | } |
| 165 | vv.DeleteInProgress = false |
| 166 | if cfg.Encapsulation == EncapsulationPPPoEIA { |
| 167 | vv.PppoeIa = true |
| 168 | } |
| 169 | vv.AssociatedPorts = make(map[string]bool) |
| 170 | return &vv |
| 171 | } |
| 172 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 173 | // associatePortToVnet - associate a port to Vnet |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 174 | func (vv *VoltVnet) associatePortToVnet(port string) { |
| 175 | vv.VnetPortLock.Lock() |
| 176 | if vv.AssociatedPorts == nil { |
| 177 | vv.AssociatedPorts = make(map[string]bool) |
| 178 | } |
| 179 | vv.AssociatedPorts[port] = true |
| 180 | vv.VnetPortLock.Unlock() |
| 181 | } |
| 182 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 183 | // disassociatePortFromVnet - disassociate a port from Vnet and return true if the association map is empty |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 184 | func (vv *VoltVnet) disassociatePortFromVnet(cntx context.Context, device string, port string) { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 185 | logger.Infow(ctx, "Disassociate Port from Vnet", log.Fields{"Device": device, "Port": port}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 186 | vv.VnetPortLock.Lock() |
| 187 | delete(vv.AssociatedPorts, port) |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 188 | logger.Debugw(ctx, "Disassociated Port from Vnet", log.Fields{"Device": device, "Port": port, "Vnet": vv.Name, "PendingDeleteFlow": vv.PendingDeleteFlow, "AssociatedPorts": vv.AssociatedPorts, "DeleteFlag": vv.DeleteInProgress}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 189 | vv.VnetPortLock.Unlock() |
| 190 | |
| 191 | if vv.DeleteInProgress { |
| 192 | if !vv.isAssociatedPortsPresent() { |
| 193 | if len(vv.PendingDeleteFlow[device]) == 0 { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 194 | logger.Debugw(ctx, "Deleting Vnet", log.Fields{"Name": vv.Name}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 195 | GetApplication().deleteVnetConfig(vv) |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 196 | _ = db.DelVnet(cntx, vv.Name) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 197 | } else { |
| 198 | logger.Warnw(ctx, "Skipping Del Vnet", log.Fields{"Name": vv.Name, "PendingDeleteFlow": vv.PendingDeleteFlow}) |
| 199 | } |
| 200 | } else { |
| 201 | vv.VnetPortLock.RLock() |
| 202 | logger.Warnw(ctx, "Skipping Del Vnet", log.Fields{"Name": vv.Name, "AssociatedPorts": vv.AssociatedPorts}) |
| 203 | vv.VnetPortLock.RUnlock() |
| 204 | } |
| 205 | } |
| 206 | } |
| 207 | |
| 208 | func (vv *VoltVnet) isAssociatedPortsPresent() bool { |
| 209 | vv.VnetPortLock.RLock() |
| 210 | defer vv.VnetPortLock.RUnlock() |
| 211 | return len(vv.AssociatedPorts) != 0 |
| 212 | } |
| 213 | |
| 214 | // WriteToDb commit the VNET to the database |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 215 | func (vv *VoltVnet) WriteToDb(cntx context.Context) { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 216 | if vv.DeleteInProgress { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 217 | logger.Warnw(ctx, "Skipping Redis Update for Vnet, Vnet delete in progress", log.Fields{"Vnet": vv.Name, "SVlan": vv.SVlan}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 218 | return |
| 219 | } |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 220 | vv.ForceWriteToDb(cntx) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 221 | } |
| 222 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 223 | // ForceWriteToDb force commit a vnet to the DB |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 224 | func (vv *VoltVnet) ForceWriteToDb(cntx context.Context) { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 225 | vv.VnetPortLock.RLock() |
| 226 | defer vv.VnetPortLock.RUnlock() |
| 227 | vv.Version = database.PresentVersionMap[database.VnetPath] |
| 228 | logger.Debugw(ctx, "Updating VNET....", log.Fields{"vnet": vv}) |
| 229 | if b, err := json.Marshal(vv); err == nil { |
Akash Soni | a824697 | 2023-01-03 10:37:08 +0530 | [diff] [blame] | 230 | if err := db.PutVnet(cntx, vv.Name, string(b)); err != nil { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 231 | logger.Warnw(ctx, "Add Vnet to DB failed", log.Fields{"Vnet": vv.Name, "SVlan": vv.SVlan, "Error": err}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 232 | } |
| 233 | } |
| 234 | } |
| 235 | |
| 236 | // VnetKey creates the key using the two VLAN tags |
| 237 | // We append the two VLAN tags to create a single key |
| 238 | func VnetKey(otag of.VlanType, itag of.VlanType, utag of.VlanType) string { |
| 239 | return strconv.Itoa(int(otag)) + "-" + strconv.Itoa(int(itag)) + "-" + strconv.Itoa(int(utag)) |
| 240 | } |
| 241 | |
| 242 | // GetVnet get VNET configuration related functionality associated with VOLT application |
| 243 | func (va *VoltApplication) GetVnet(otag of.VlanType, itag of.VlanType, utag of.VlanType) *VoltVnet { |
| 244 | // When matching VNET, it is expected to match first just the outer |
| 245 | // tag, and then the combination to make sure there is no conflict |
| 246 | // for the new configuration. |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 247 | logger.Debugw(ctx, "Get Vnet configuration", log.Fields{"SVlan": otag, "CVlan": itag, "UniVlan": utag}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 248 | if vnet, ok := va.VnetsByTag.Load(VnetKey(otag, of.VlanNone, utag)); ok { |
| 249 | return vnet.(*VoltVnet) |
| 250 | } |
| 251 | if vnet, ok := va.VnetsByTag.Load(VnetKey(otag, itag, utag)); ok { |
| 252 | return vnet.(*VoltVnet) |
| 253 | } |
| 254 | return nil |
| 255 | } |
| 256 | |
| 257 | // The VNET may also be assigned name for easier references. For now, |
| 258 | // the VNET is mainly identified by the two VLANs. |
| 259 | |
| 260 | // GetVnetByName to get vnet by name |
| 261 | func (va *VoltApplication) GetVnetByName(name string) *VoltVnet { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 262 | logger.Debugw(ctx, "Get Vnet by Name", log.Fields{"Name": name}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 263 | if vnet, ok := va.VnetsByName.Load(name); ok { |
| 264 | return vnet.(*VoltVnet) |
| 265 | } |
| 266 | return nil |
| 267 | } |
| 268 | |
| 269 | // storeVnetConfig to store vnet config |
| 270 | func (va *VoltApplication) storeVnetConfig(cfg VnetConfig, vv *VoltVnet) { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 271 | logger.Debugw(ctx, "Store Vnet config", log.Fields{"Name": cfg.Name}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 272 | var vnetMap *util.ConcurrentMap |
| 273 | |
| 274 | va.VnetsByTag.Store(VnetKey(cfg.SVlan, cfg.CVlan, cfg.UniVlan), vv) |
| 275 | va.VnetsByName.Store(cfg.Name, vv) |
| 276 | |
| 277 | if vnetMapIntf, ok := va.VnetsBySvlan.Get(vv.SVlan); !ok { |
| 278 | vnetMap = util.NewConcurrentMap() |
| 279 | } else { |
| 280 | vnetMap = vnetMapIntf.(*util.ConcurrentMap) |
| 281 | } |
| 282 | vnetMap.Set(vv, true) |
| 283 | va.VnetsBySvlan.Set(vv.SVlan, vnetMap) |
| 284 | } |
| 285 | |
| 286 | // deleteVnetConfig to delete vnet config |
| 287 | func (va *VoltApplication) deleteVnetConfig(vnet *VoltVnet) { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 288 | logger.Debugw(ctx, "Delete Vnet config", log.Fields{"Name": vnet.Name}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 289 | va.VnetsByTag.Delete(VnetKey(vnet.SVlan, vnet.CVlan, vnet.UniVlan)) |
| 290 | va.VnetsByName.Delete(vnet.Name) |
| 291 | |
| 292 | if vnetMapIntf, ok := va.VnetsBySvlan.Get(vnet.SVlan); ok { |
| 293 | vnetMap := vnetMapIntf.(*util.ConcurrentMap) |
| 294 | vnetMap.Remove(vnet) |
| 295 | va.VnetsBySvlan.Set(vnet.SVlan, vnetMap) |
| 296 | } |
| 297 | } |
| 298 | |
| 299 | // AddVnet to add a VNET to the list of VNETs configured. |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 300 | func (va *VoltApplication) AddVnet(cntx context.Context, cfg VnetConfig, oper *VnetOper) error { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 301 | logger.Debugw(ctx, "Add Vnet config", log.Fields{"Name": cfg.Name}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 302 | AppMutex.VnetMutex.Lock() |
| 303 | var vv *VoltVnet |
| 304 | devicesToHandle := []string{} |
| 305 | vv = va.GetVnetByName(cfg.Name) |
| 306 | if vv != nil { |
| 307 | //Could be for another OLT or could be case of backup-restore |
| 308 | for _, serialNum := range cfg.DevicesList { |
| 309 | if isDeviceInList(serialNum, vv.DevicesList) { |
| 310 | //This is backup restore scenario, just update the profile |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 311 | logger.Infow(ctx, "Add Vnet : Profile Name already exists with OLT, update-the-profile", log.Fields{"SerialNum": serialNum}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 312 | continue |
| 313 | } |
| 314 | devicesToHandle = append(devicesToHandle, serialNum) |
| 315 | } |
| 316 | if len(devicesToHandle) == 0 { |
Tinoj Joseph | 1d10832 | 2022-07-13 10:07:39 +0530 | [diff] [blame] | 317 | logger.Debugw(ctx, "Ignoring Duplicate VNET by name ", log.Fields{"Vnet": cfg.Name}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 318 | AppMutex.VnetMutex.Unlock() |
| 319 | return nil |
| 320 | } |
| 321 | } |
| 322 | |
| 323 | if vv == nil { |
| 324 | vv = NewVoltVnet(cfg) |
| 325 | if oper != nil { |
| 326 | vv.PendingDeleteFlow = oper.PendingDeleteFlow |
| 327 | vv.DeleteInProgress = oper.DeleteInProgress |
| 328 | vv.AssociatedPorts = oper.AssociatedPorts |
| 329 | vv.PendingDeviceToDelete = oper.PendingDeviceToDelete |
| 330 | } |
| 331 | devicesToHandle = append(devicesToHandle, cfg.DevicesList...) |
| 332 | } else { |
| 333 | vv.DevicesList = append(vv.DevicesList, devicesToHandle...) |
| 334 | } |
| 335 | |
| 336 | va.storeVnetConfig(cfg, vv) |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 337 | vv.WriteToDb(cntx) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 338 | |
| 339 | logger.Infow(ctx, "Added VNET TO DB", log.Fields{"cfg": cfg, "devicesToHandle": devicesToHandle}) |
| 340 | |
| 341 | //va.PushDevFlowForVlan(vv) |
| 342 | AppMutex.VnetMutex.Unlock() |
| 343 | return nil |
| 344 | } |
| 345 | |
| 346 | // DelVnet to delete a VNET from the list of VNETs configured |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 347 | func (va *VoltApplication) DelVnet(cntx context.Context, name, deviceSerialNum string) error { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 348 | logger.Infow(ctx, "Deleting Vnet", log.Fields{"Vnet": name}) |
| 349 | AppMutex.VnetMutex.Lock() |
| 350 | if vnetIntf, ok := va.VnetsByName.Load(name); ok { |
| 351 | vnet := vnetIntf.(*VoltVnet) |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 352 | // Delete from mvp list |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 353 | vnet.DevicesList = util.RemoveFromSlice(vnet.DevicesList, deviceSerialNum) |
| 354 | |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 355 | va.DeleteDevFlowForVlanFromDevice(cntx, vnet, deviceSerialNum) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 356 | if len(vnet.DevicesList) == 0 { |
| 357 | vnet.DeleteInProgress = true |
| 358 | vnet.PendingDeviceToDelete = deviceSerialNum |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 359 | vnet.ForceWriteToDb(cntx) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 360 | vnet.VnetPortLock.RLock() |
| 361 | if len(vnet.PendingDeleteFlow) == 0 && !vnet.isAssociatedPortsPresent() { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 362 | logger.Debugw(ctx, "Deleting Vnet", log.Fields{"Name": vnet.Name, "AssociatedPorts": vnet.AssociatedPorts, "PendingDelFlows": vnet.PendingDeleteFlow}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 363 | va.deleteVnetConfig(vnet) |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 364 | _ = db.DelVnet(cntx, vnet.Name) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 365 | } else { |
| 366 | logger.Warnw(ctx, "Skipping Del Vnet", log.Fields{"Name": vnet.Name, "AssociatedPorts": vnet.AssociatedPorts, "PendingDelFlows": vnet.PendingDeleteFlow}) |
| 367 | } |
| 368 | vnet.VnetPortLock.RUnlock() |
| 369 | } else { |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 370 | // Update the devicelist in db |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 371 | vnet.WriteToDb(cntx) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 372 | } |
| 373 | } |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 374 | // TODO: if no vnets are present on device remove icmpv6 group from device |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 375 | AppMutex.VnetMutex.Unlock() |
| 376 | return nil |
| 377 | } |
| 378 | |
| 379 | // UpdateVnet to update the VNET with associated service count |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 380 | func (va *VoltApplication) UpdateVnet(cntx context.Context, vv *VoltVnet) error { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 381 | va.storeVnetConfig(vv.VnetConfig, vv) |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 382 | vv.WriteToDb(cntx) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 383 | logger.Infow(ctx, "Updated VNET TO DB", log.Fields{"vv": vv.VnetConfig}) |
| 384 | return nil |
| 385 | } |
| 386 | |
| 387 | // ------------------------------------------------------------ |
| 388 | // Manifestation of a VNET on a port is handled below |
| 389 | // ------------------------------------------------------------ |
| 390 | // |
| 391 | // The VNET on a port handles everything that is done for a VNET |
| 392 | // such as DHCP relay state machine, MAC addresses, IP addresses |
| 393 | // learnt, so on. |
| 394 | |
| 395 | // DhcpStatus type |
| 396 | type DhcpStatus uint8 |
| 397 | |
| 398 | const ( |
| 399 | // DhcpStatusNone constant |
| 400 | DhcpStatusNone DhcpStatus = 0 |
| 401 | // DhcpStatusAcked constant |
| 402 | DhcpStatusAcked DhcpStatus = 1 |
| 403 | // DhcpStatusNacked constant |
| 404 | DhcpStatusNacked DhcpStatus = 2 |
| 405 | // EthTypeNone constant |
| 406 | EthTypeNone int = 0 |
| 407 | // EthTypeIPoE constant |
| 408 | EthTypeIPoE int = 1 |
| 409 | // EthTypePPPoE constant |
| 410 | EthTypePPPoE int = 2 |
| 411 | ) |
| 412 | |
| 413 | // VoltPortVnet structure |
| 414 | type VoltPortVnet struct { |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 415 | PendingDeleteFlow map[string]bool |
| 416 | servicesCount *atomic.Uint64 |
| 417 | services sync.Map |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 418 | Device string |
| 419 | Port string |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 420 | VnetName string |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 421 | VnetType string |
| 422 | MvlanProfileName string |
| 423 | Version string |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 424 | DhcpExpiryTime time.Time |
| 425 | Dhcp6ExpiryTime time.Time |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 426 | Ipv4Addr net.IP |
| 427 | Ipv6Addr net.IP |
| 428 | MacAddr net.HardwareAddr |
| 429 | LearntMacAddr net.HardwareAddr |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 430 | CircuitID []byte //Will not be used |
| 431 | RemoteID []byte //Will not be used |
| 432 | VpvLock sync.Mutex `json:"-"` |
| 433 | PendingFlowLock sync.RWMutex `json:"-"` |
| 434 | SchedID int |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 435 | ONTEtherTypeClassification int |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 436 | MacLearning MacLearningType |
| 437 | PonPort uint32 |
| 438 | McastUsMeterID uint32 |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 439 | McastTechProfileID uint16 |
| 440 | McastPbit of.PbitType |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 441 | SVlanTpid layers.EthernetType |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 442 | DhcpPbit of.PbitType |
Tinoj Joseph | 50d722c | 2022-12-06 22:53:22 +0530 | [diff] [blame] | 443 | UsPonCTagPriority of.PbitType |
| 444 | UsPonSTagPriority of.PbitType |
| 445 | DsPonCTagPriority of.PbitType |
| 446 | DsPonSTagPriority of.PbitType |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 447 | SVlan of.VlanType |
| 448 | CVlan of.VlanType |
| 449 | UniVlan of.VlanType |
| 450 | VlanControl VlanControl |
| 451 | RelayState DhcpRelayState |
| 452 | DhcpStatus DhcpStatus |
| 453 | PPPoeState PppoeIaState |
| 454 | RelayStatev6 Dhcpv6RelayState |
| 455 | DHCPv6DUID [MaxLenDhcpv6DUID]byte |
| 456 | DhcpRelay bool |
| 457 | ArpRelay bool |
| 458 | PppoeIa bool |
| 459 | DeleteInProgress bool |
| 460 | Blocked bool |
| 461 | AllowTransparent bool |
| 462 | IgmpEnabled bool |
| 463 | IgmpFlowsApplied bool |
| 464 | McastService bool |
| 465 | FlowsApplied bool |
Hitesh Chhabra | 9f9a9df | 2023-06-13 17:52:15 +0530 | [diff] [blame] | 466 | IsOption82Enabled bool //Will not be used |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 467 | } |
| 468 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 469 | // VlanControl vlan control type |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 470 | type VlanControl uint8 |
| 471 | |
| 472 | const ( |
| 473 | // None constant |
| 474 | // ONU and OLT will passthrough UNIVLAN as is to BNG |
| 475 | None VlanControl = iota |
| 476 | |
| 477 | // ONUCVlanOLTSVlan constant |
| 478 | // Tagged traffic, ONU will replace UNIVLAN with CVLAN and OLT will add SVLAN |
| 479 | // Untagged traffic, ONU will add CVLAN and OLT will add SVLAN |
| 480 | ONUCVlanOLTSVlan |
| 481 | |
| 482 | // OLTCVlanOLTSVlan constant |
| 483 | // Tagged traffic, ONU will passthrough UNIVLAN as is to OLT and |
| 484 | // OLT will replace UNIVLAN with CVLAN and add SVLAN |
| 485 | OLTCVlanOLTSVlan |
| 486 | |
| 487 | // ONUCVlan constant |
| 488 | // Tagged traffic, ONU will replace UNIVLAN with CVLAN |
| 489 | // Untagged traffic, ONU will add CVLAN |
| 490 | ONUCVlan |
| 491 | |
| 492 | // OLTSVlan constant |
| 493 | // UnTagged traffic, OLT will add the SVLAN |
| 494 | OLTSVlan |
| 495 | ) |
| 496 | |
| 497 | // NewVoltPortVnet is constructor for VoltPortVnet |
| 498 | func NewVoltPortVnet(vnet *VoltVnet) *VoltPortVnet { |
| 499 | var vpv VoltPortVnet |
| 500 | |
| 501 | vpv.VnetName = vnet.Name |
| 502 | vpv.SVlan = vnet.SVlan |
| 503 | vpv.CVlan = vnet.CVlan |
| 504 | vpv.UniVlan = vnet.UniVlan |
| 505 | vpv.SVlanTpid = vnet.SVlanTpid |
| 506 | vpv.DhcpRelay = vnet.DhcpRelay |
| 507 | vpv.DhcpStatus = DhcpStatusNone |
| 508 | vpv.PPPoeState = PppoeIaStateNone |
| 509 | vpv.ArpRelay = vnet.ArpLearning |
| 510 | vpv.PppoeIa = vnet.PppoeIa |
| 511 | vpv.VlanControl = vnet.VlanControl |
| 512 | vpv.ONTEtherTypeClassification = vnet.ONTEtherTypeClassification |
| 513 | vpv.AllowTransparent = vnet.AllowTransparent |
| 514 | vpv.FlowsApplied = false |
| 515 | vpv.IgmpEnabled = false |
| 516 | vpv.MacAddr, _ = net.ParseMAC("00:00:00:00:00:00") |
| 517 | vpv.LearntMacAddr, _ = net.ParseMAC("00:00:00:00:00:00") |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 518 | vpv.servicesCount = atomic.NewUint64(0) |
| 519 | vpv.SchedID = 0 |
| 520 | vpv.PendingDeleteFlow = make(map[string]bool) |
| 521 | vpv.DhcpPbit = vnet.UsDhcpPbit[0] |
Tinoj Joseph | 50d722c | 2022-12-06 22:53:22 +0530 | [diff] [blame] | 522 | vpv.UsPonCTagPriority = vnet.UsPonCTagPriority |
| 523 | vpv.UsPonSTagPriority = vnet.UsPonSTagPriority |
| 524 | vpv.DsPonCTagPriority = vnet.UsPonCTagPriority |
| 525 | vpv.DsPonSTagPriority = vnet.UsPonSTagPriority |
| 526 | |
| 527 | vpv.VnetType = vnet.VnetType |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 528 | return &vpv |
| 529 | } |
| 530 | |
| 531 | func (vpv *VoltPortVnet) setDevice(device string) { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 532 | logger.Debugw(ctx, "Set Device", log.Fields{"Device": device}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 533 | if vpv.Device != device && vpv.Device != "" { |
| 534 | GetApplication().DisassociateVpvsFromDevice(device, vpv) |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 535 | // TEMP: |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 536 | vpv.printAssociatedVPVs(false) |
| 537 | } |
| 538 | |
Tinoj Joseph | ec742f6 | 2022-09-29 19:11:10 +0530 | [diff] [blame] | 539 | logger.Infow(ctx, "Associating VPV and Device", log.Fields{"Device": device, "Port": vpv.Port, "SVlan": vpv.SVlan}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 540 | |
| 541 | vpv.Device = device |
| 542 | GetApplication().AssociateVpvsToDevice(device, vpv) |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 543 | // TEMP: |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 544 | vpv.printAssociatedVPVs(true) |
| 545 | } |
| 546 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 547 | // TODO - Nav - Temp |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 548 | func (vpv *VoltPortVnet) printAssociatedVPVs(add bool) { |
| 549 | logger.Infow(ctx, "Start----Printing all associated VPV", log.Fields{"Device": vpv.Device, "Add": add}) |
| 550 | if vMap := GetApplication().GetAssociatedVpvsForDevice(vpv.Device, vpv.SVlan); vMap != nil { |
| 551 | vMap.Range(func(key, value interface{}) bool { |
| 552 | vpvEntry := key.(*VoltPortVnet) |
| 553 | logger.Infow(ctx, "Associated VPVs", log.Fields{"SVlan": vpvEntry.SVlan, "CVlan": vpvEntry.CVlan, "UniVlan": vpvEntry.UniVlan}) |
| 554 | return true |
| 555 | }) |
| 556 | } |
| 557 | logger.Infow(ctx, "End----Printing all associated VPV", log.Fields{"Device": vpv.Device, "Add": add}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 558 | } |
| 559 | |
| 560 | // GetCircuitID : The interface to be satisfied by the VoltPortVnet to be a DHCP relay |
| 561 | // session is implemented below. The main functions still remain in |
| 562 | // the service.go file. |
| 563 | func (vpv *VoltPortVnet) GetCircuitID() []byte { |
| 564 | return []byte(vpv.CircuitID) |
| 565 | } |
| 566 | |
| 567 | // GetRemoteID to get remote id |
| 568 | func (vpv *VoltPortVnet) GetRemoteID() []byte { |
| 569 | return []byte(vpv.RemoteID) |
| 570 | } |
| 571 | |
| 572 | // GetDhcpState to get dhcp state |
| 573 | func (vpv *VoltPortVnet) GetDhcpState() DhcpRelayState { |
| 574 | return vpv.RelayState |
| 575 | } |
| 576 | |
| 577 | // SetDhcpState to set the dhcp state |
| 578 | func (vpv *VoltPortVnet) SetDhcpState(state DhcpRelayState) { |
| 579 | vpv.RelayState = state |
| 580 | } |
| 581 | |
| 582 | // GetPppoeIaState to get pppoeia state |
| 583 | func (vpv *VoltPortVnet) GetPppoeIaState() PppoeIaState { |
| 584 | return vpv.PPPoeState |
| 585 | } |
| 586 | |
| 587 | // SetPppoeIaState to set pppoeia state |
| 588 | func (vpv *VoltPortVnet) SetPppoeIaState(state PppoeIaState) { |
| 589 | vpv.PPPoeState = state |
| 590 | } |
| 591 | |
| 592 | // GetDhcpv6State to get dhcpv6 state |
| 593 | func (vpv *VoltPortVnet) GetDhcpv6State() Dhcpv6RelayState { |
| 594 | return vpv.RelayStatev6 |
| 595 | } |
| 596 | |
| 597 | // SetDhcpv6State to set dhcpv6 state |
| 598 | func (vpv *VoltPortVnet) SetDhcpv6State(state Dhcpv6RelayState) { |
| 599 | vpv.RelayStatev6 = state |
| 600 | } |
| 601 | |
| 602 | // DhcpResultInd for dhcp result indication |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 603 | func (vpv *VoltPortVnet) DhcpResultInd(cntx context.Context, res *layers.DHCPv4) { |
| 604 | vpv.ProcessDhcpResult(cntx, res) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 605 | } |
| 606 | |
| 607 | // Dhcpv6ResultInd for dhcpv6 result indication |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 608 | func (vpv *VoltPortVnet) Dhcpv6ResultInd(cntx context.Context, ipv6Addr net.IP, leaseTime uint32) { |
| 609 | vpv.ProcessDhcpv6Result(cntx, ipv6Addr, leaseTime) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 610 | } |
| 611 | |
| 612 | // GetNniVlans to get nni vlans |
| 613 | func (vpv *VoltPortVnet) GetNniVlans() (uint16, uint16) { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 614 | logger.Debugw(ctx, "Get Nni Vlans", log.Fields{"vpv.VlanControl": vpv.VlanControl}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 615 | switch vpv.VlanControl { |
| 616 | case ONUCVlanOLTSVlan, |
| 617 | OLTCVlanOLTSVlan: |
| 618 | return uint16(vpv.SVlan), uint16(vpv.CVlan) |
| 619 | case ONUCVlan, |
| 620 | None: |
| 621 | return uint16(vpv.SVlan), uint16(of.VlanNone) |
| 622 | case OLTSVlan: |
| 623 | return uint16(vpv.SVlan), uint16(of.VlanNone) |
| 624 | } |
| 625 | return uint16(of.VlanNone), uint16(of.VlanNone) |
| 626 | } |
| 627 | |
| 628 | // GetService to get service |
| 629 | func (vpv *VoltPortVnet) GetService(name string) (*VoltService, bool) { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 630 | logger.Debugw(ctx, "Get Service", log.Fields{"name": name}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 631 | service, ok := vpv.services.Load(name) |
| 632 | if ok { |
| 633 | return service.(*VoltService), ok |
| 634 | } |
| 635 | return nil, ok |
| 636 | } |
| 637 | |
| 638 | // AddService to add service |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 639 | func (vpv *VoltPortVnet) AddService(cntx context.Context, service *VoltService) { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 640 | logger.Debugw(ctx, "Add Service", log.Fields{"ServiceName": service.Name}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 641 | vpv.services.Store(service.Name, service) |
| 642 | vpv.servicesCount.Inc() |
| 643 | logger.Infow(ctx, "Service added/updated to VPV", log.Fields{"Port": vpv.Port, "SVLAN": vpv.SVlan, "CVLAN": vpv.CVlan, "UNIVlan": vpv.UniVlan, "Service": service.Name, "Count": vpv.servicesCount.Load()}) |
| 644 | } |
| 645 | |
| 646 | // DelService to delete service |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 647 | func (vpv *VoltPortVnet) DelService(cntx context.Context, service *VoltService) { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 648 | logger.Debugw(ctx, "Delete Service", log.Fields{"ServiceName": service.Name}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 649 | vpv.services.Delete(service.Name) |
| 650 | vpv.servicesCount.Dec() |
| 651 | |
| 652 | // If the only Igmp Enabled service is removed, remove the Igmp trap flow along with it |
| 653 | if service.IgmpEnabled { |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 654 | if err := vpv.DelIgmpFlows(cntx); err != nil { |
Akash Soni | a824697 | 2023-01-03 10:37:08 +0530 | [diff] [blame] | 655 | statusCode, statusMessage := errorCodes.GetErrorInfo(err) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 656 | vpv.FlowInstallFailure("VGC processing failure", statusCode, statusMessage) |
| 657 | } |
| 658 | |
| 659 | vpv.IgmpEnabled = false |
| 660 | } |
| 661 | logger.Infow(ctx, "Service deleted from VPV", log.Fields{"Port": vpv.Port, "SVLAN": vpv.SVlan, "CVLAN": vpv.CVlan, "UNIVlan": vpv.UniVlan, "Service": service.Name, "Count": vpv.servicesCount.Load()}) |
| 662 | } |
| 663 | |
| 664 | // ProcessDhcpResult to process dhcp results |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 665 | func (vpv *VoltPortVnet) ProcessDhcpResult(cntx context.Context, res *layers.DHCPv4) { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 666 | logger.Debug(ctx, "Process Dhcp Result") |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 667 | msgType := DhcpMsgType(res) |
| 668 | if msgType == layers.DHCPMsgTypeAck { |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 669 | vpv.ProcessDhcpSuccess(cntx, res) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 670 | } else if msgType == layers.DHCPMsgTypeNak { |
| 671 | vpv.DhcpStatus = DhcpStatusNacked |
| 672 | } |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 673 | vpv.WriteToDb(cntx) |
| 674 | } |
| 675 | |
| 676 | // RangeOnServices to call a function on all services on the vpv |
Sridhar Ravindra | 03aa0bf | 2023-09-12 17:46:40 +0530 | [diff] [blame] | 677 | func (vpv *VoltPortVnet) RangeOnServices(cntx context.Context, callback func(cntx context.Context, key, value interface{}, flag bool) bool, delFlowsInDevice bool) { |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 678 | vpv.services.Range(func(key, value interface{}) bool { |
Sridhar Ravindra | 03aa0bf | 2023-09-12 17:46:40 +0530 | [diff] [blame] | 679 | return callback(cntx, key, value, delFlowsInDevice) |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 680 | }) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 681 | } |
| 682 | |
| 683 | // ProcessDhcpSuccess : Learn the IPv4 address allocated to the services and update the |
| 684 | // the services with the same. This also calls for adding flows |
| 685 | // for the services as the DHCP procedure is completed |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 686 | func (vpv *VoltPortVnet) ProcessDhcpSuccess(cntx context.Context, res *layers.DHCPv4) { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 687 | logger.Info(ctx, "Process Dhcp Success") |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 688 | vpv.DhcpStatus = DhcpStatusAcked |
| 689 | vpv.Ipv4Addr, _ = GetIpv4Addr(res) |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 690 | logger.Debugw(ctx, "Received IPv4 Address and Services Configured", log.Fields{"IP Address": vpv.Ipv4Addr.String(), "Count": vpv.servicesCount.Load()}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 691 | |
Sridhar Ravindra | 03aa0bf | 2023-09-12 17:46:40 +0530 | [diff] [blame] | 692 | vpv.RangeOnServices(cntx, vpv.updateIPv4AndProvisionFlows, false) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 693 | vpv.ProcessDhcpv4Options(res) |
| 694 | } |
| 695 | |
| 696 | // ProcessDhcpv4Options : Currently we process lease time and store the validity of the |
| 697 | // IP address allocated. |
| 698 | func (vpv *VoltPortVnet) ProcessDhcpv4Options(res *layers.DHCPv4) { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 699 | logger.Debug(ctx, "Process Dhcp v4 Options") |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 700 | for _, o := range res.Options { |
| 701 | switch o.Type { |
| 702 | case layers.DHCPOptLeaseTime: |
| 703 | leasetime := GetIPv4LeaseTime(o) |
| 704 | vpv.DhcpExpiryTime = time.Now().Add((time.Duration(leasetime) * time.Second)) |
| 705 | logger.Infow(ctx, "Lease Expiry Set", log.Fields{"Time": vpv.DhcpExpiryTime}) |
| 706 | } |
| 707 | } |
| 708 | } |
| 709 | |
| 710 | // ProcessDhcpv6Result : Read the IPv6 address allocated to the device and store it on the |
| 711 | // VNET. The same IPv6 address is also passed to the services. When a |
| 712 | // service is fetched all the associated information such as MAC address, |
| 713 | // IPv4 address and IPv6 addresses can be provided. |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 714 | func (vpv *VoltPortVnet) ProcessDhcpv6Result(cntx context.Context, ipv6Addr net.IP, leaseTime uint32) { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 715 | logger.Debugw(ctx, "Process Dhcp v6 Result", log.Fields{"ipv6Addr": ipv6Addr, "leaseTime": leaseTime}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 716 | // TODO: Status based hanlding of flows |
| 717 | vpv.Dhcp6ExpiryTime = time.Now().Add((time.Duration(leaseTime) * time.Second)) |
| 718 | vpv.Ipv6Addr = ipv6Addr |
| 719 | |
Sridhar Ravindra | 03aa0bf | 2023-09-12 17:46:40 +0530 | [diff] [blame] | 720 | vpv.RangeOnServices(cntx, vpv.updateIPv6AndProvisionFlows, false) |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 721 | vpv.WriteToDb(cntx) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 722 | } |
| 723 | |
| 724 | // AddSvcUsMeterToDevice to add service upstream meter info to device |
Sridhar Ravindra | 03aa0bf | 2023-09-12 17:46:40 +0530 | [diff] [blame] | 725 | func AddSvcUsMeterToDevice(cntx context.Context, key, value interface{}, flag bool) bool { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 726 | svc := value.(*VoltService) |
Tinoj Joseph | 1d10832 | 2022-07-13 10:07:39 +0530 | [diff] [blame] | 727 | logger.Infow(ctx, "Adding upstream meter profile to device", log.Fields{"ServiceName": svc.Name}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 728 | if device, _ := GetApplication().GetDeviceFromPort(svc.Port); device != nil { |
| 729 | GetApplication().AddMeterToDevice(svc.Port, device.Name, svc.UsMeterID, 0) |
| 730 | return true |
| 731 | } |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 732 | logger.Warnw(ctx, "Dropping US Meter request: Device not found", log.Fields{"Service": svc}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 733 | return false |
| 734 | } |
| 735 | |
| 736 | // PushFlowsForPortVnet - triggers flow construction and push for provided VPV |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 737 | func (vpv *VoltPortVnet) PushFlowsForPortVnet(cntx context.Context, d *VoltDevice) { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 738 | logger.Debugw(ctx, "Push Flows For Port Vnet", log.Fields{"Port": vpv.Port}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 739 | vp := d.GetPort(vpv.Port) |
| 740 | |
| 741 | //Ignore if UNI port is not found or not UP |
| 742 | if vp == nil || vp.State != PortStateUp { |
| 743 | logger.Warnw(ctx, "Ignoring Vlan UP Ind for VPV: Port Not Found/Ready", log.Fields{"Port": vp}) |
| 744 | return |
| 745 | } |
| 746 | |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 747 | //Disable the flag so that flows can be pushed again |
| 748 | // vpv.IgmpFlowsApplied = false |
| 749 | // vpv.DsFlowsApplied = false |
| 750 | // vpv.UsFlowsApplied = false |
| 751 | vpv.VpvLock.Lock() |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 752 | vpv.PortUpInd(cntx, d, vpv.Port) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 753 | vpv.VpvLock.Unlock() |
| 754 | } |
| 755 | |
| 756 | // PortUpInd : When a port transistions to UP state, the indication is passed |
| 757 | // on to this module via the application. We read the VNET configuration |
| 758 | // again here to apply the latest configuration if the configuration |
| 759 | // changed. Thus, a reboot of ONT forces the new configuration to get |
| 760 | // applied. |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 761 | func (vpv *VoltPortVnet) PortUpInd(cntx context.Context, device *VoltDevice, port string) { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 762 | logger.Infow(ctx, "Port UP Ind, pushing flows for the port", log.Fields{"Device": device, "Port": port, "VnetDhcp": vpv.DhcpRelay, "McastService": vpv.McastService}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 763 | if vpv.DeleteInProgress { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 764 | logger.Warnw(ctx, "Ignoring VPV Port UP Ind, VPV deleteion In-Progress", log.Fields{"Device": device, "Port": port, "Vnet": vpv.VnetName}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 765 | return |
| 766 | } |
| 767 | vpv.setDevice(device.Name) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 768 | |
| 769 | nni, _ := GetApplication().GetNniPort(device.Name) |
| 770 | if nni == "" { |
| 771 | logger.Warnw(ctx, "Ignoring Vnet Port UP indication: NNI is unavailable", log.Fields{"Port": vpv.Port, "Device": device.Name}) |
| 772 | return |
| 773 | } |
| 774 | |
Akash Soni | a824697 | 2023-01-03 10:37:08 +0530 | [diff] [blame] | 775 | if nniPort := device.GetPort(nni); nniPort != nil { |
| 776 | //If NNI port is not mached to nb nni port dont send flows |
| 777 | devConfig := GetApplication().GetDeviceConfig(device.SerialNum) |
| 778 | if devConfig != nil { |
Akash Soni | 53da285 | 2023-03-15 00:31:31 +0530 | [diff] [blame] | 779 | if devConfig.UplinkPort != strconv.Itoa(int(nniPort.ID)) { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 780 | logger.Warnw(ctx, "NNI port not configured from NB, not pushing flows", log.Fields{"NB NNI Port": devConfig.UplinkPort, "SB NNI port": nniPort.ID}) |
Akash Soni | a824697 | 2023-01-03 10:37:08 +0530 | [diff] [blame] | 781 | return |
| 782 | } |
| 783 | } |
| 784 | } |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 785 | |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 786 | if vpv.Blocked { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 787 | logger.Warnw(ctx, "VPV Blocked for Processing. Ignoring flow push request", log.Fields{"Port": vpv.Port, "Vnet": vpv.VnetName}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 788 | return |
| 789 | } |
| 790 | |
| 791 | if vpv.DhcpRelay || vpv.ArpRelay || vpv.PppoeIa { |
| 792 | // If MAC Learning is true if no MAC is configured, push DS/US DHCP, US HSIA flows without MAC. |
| 793 | // DS HSIA flows are installed after learning the MAC. |
| 794 | logger.Infow(ctx, "Port Up - Trap Flows", log.Fields{"Device": device.Name, "Port": port}) |
Tinoj Joseph | 50d722c | 2022-12-06 22:53:22 +0530 | [diff] [blame] | 795 | // no HSIA flows for multicast service and DPU_MGMT Service |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 796 | if !vpv.McastService && vpv.VnetType != DpuMgmtTraffic { |
Sridhar Ravindra | 03aa0bf | 2023-09-12 17:46:40 +0530 | [diff] [blame] | 797 | vpv.RangeOnServices(cntx, AddUsHsiaFlows, false) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 798 | } |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 799 | if vpv.VnetType == DpuMgmtTraffic { |
Sridhar Ravindra | 03aa0bf | 2023-09-12 17:46:40 +0530 | [diff] [blame] | 800 | vpv.RangeOnServices(cntx, AddMeterToDevice, false) |
Tinoj Joseph | 50d722c | 2022-12-06 22:53:22 +0530 | [diff] [blame] | 801 | } |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 802 | vpv.AddTrapFlows(cntx) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 803 | if vpv.MacLearning == MacLearningNone || NonZeroMacAddress(vpv.MacAddr) { |
| 804 | logger.Infow(ctx, "Port Up - DS Flows", log.Fields{"Device": device.Name, "Port": port}) |
Tinoj Joseph | 50d722c | 2022-12-06 22:53:22 +0530 | [diff] [blame] | 805 | /*In case of DPU_MGMT_TRAFFIC, need to install both US and DS traffic */ |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 806 | if vpv.VnetType == DpuMgmtTraffic { |
Sridhar Ravindra | 03aa0bf | 2023-09-12 17:46:40 +0530 | [diff] [blame] | 807 | vpv.RangeOnServices(cntx, AddUsHsiaFlows, false) |
Tinoj Joseph | 50d722c | 2022-12-06 22:53:22 +0530 | [diff] [blame] | 808 | } |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 809 | // US & DS DHCP, US HSIA flows are already installed |
| 810 | // install only DS HSIA flow here. |
| 811 | // no HSIA flows for multicast service |
Akash Soni | 53da285 | 2023-03-15 00:31:31 +0530 | [diff] [blame] | 812 | if !vpv.McastService { |
Sridhar Ravindra | 03aa0bf | 2023-09-12 17:46:40 +0530 | [diff] [blame] | 813 | vpv.RangeOnServices(cntx, AddDsHsiaFlows, false) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 814 | } |
| 815 | } |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 816 | } else { |
| 817 | // DHCP relay is not configured. This implies that the service must use |
| 818 | // 1:1 and does not require MAC learning. In a completely uncommon but |
| 819 | // plausible case, the MAC address can be learnt from N:1 without DHCP |
| 820 | // relay by configuring any unknown MAC address to be reported. This |
| 821 | // however is not seen as a real use case. |
| 822 | logger.Infow(ctx, "Port Up - Service Flows", log.Fields{"Device": device.Name, "Port": port}) |
| 823 | if !vpv.McastService { |
Sridhar Ravindra | 03aa0bf | 2023-09-12 17:46:40 +0530 | [diff] [blame] | 824 | vpv.RangeOnServices(cntx, AddUsHsiaFlows, false) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 825 | } |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 826 | vpv.AddTrapFlows(cntx) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 827 | if !vpv.McastService { |
Sridhar Ravindra | 03aa0bf | 2023-09-12 17:46:40 +0530 | [diff] [blame] | 828 | vpv.RangeOnServices(cntx, AddDsHsiaFlows, false) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 829 | } |
| 830 | } |
| 831 | |
| 832 | // Process IGMP proxy - install IGMP trap rules before DHCP trap rules |
| 833 | if vpv.IgmpEnabled { |
| 834 | logger.Infow(ctx, "Port Up - IGMP Flows", log.Fields{"Device": device.Name, "Port": port}) |
Sridhar Ravindra | 03aa0bf | 2023-09-12 17:46:40 +0530 | [diff] [blame] | 835 | vpv.RangeOnServices(cntx, AddSvcUsMeterToDevice, false) |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 836 | if err := vpv.AddIgmpFlows(cntx); err != nil { |
Akash Soni | a824697 | 2023-01-03 10:37:08 +0530 | [diff] [blame] | 837 | statusCode, statusMessage := errorCodes.GetErrorInfo(err) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 838 | vpv.FlowInstallFailure("VGC processing failure", statusCode, statusMessage) |
| 839 | } |
| 840 | |
| 841 | if vpv.McastService { |
Sridhar Ravindra | 03aa0bf | 2023-09-12 17:46:40 +0530 | [diff] [blame] | 842 | vpv.RangeOnServices(cntx, PostAccessConfigSuccessInd, false) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 843 | } |
| 844 | } |
| 845 | |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 846 | vpv.WriteToDb(cntx) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 847 | } |
| 848 | |
| 849 | // PortDownInd : When the port status changes to down, we delete all configured flows |
| 850 | // The same indication is also passed to the services enqueued for them |
| 851 | // to take appropriate actions |
Sridhar Ravindra | 03aa0bf | 2023-09-12 17:46:40 +0530 | [diff] [blame] | 852 | // delFlowsInDevice flag indicates that flows should be deleted only in DB/device and should not be forwarded to core |
| 853 | func (vpv *VoltPortVnet) PortDownInd(cntx context.Context, device string, port string, nbRequest bool, delFlowsInDevice bool) { |
Tinoj Joseph | 4ead4e0 | 2023-01-30 03:12:44 +0530 | [diff] [blame] | 854 | if !nbRequest && !GetApplication().OltFlowServiceConfig.RemoveFlowsOnDisable { |
| 855 | logger.Info(ctx, "VPV Port DOWN Ind, Not deleting flows since RemoveOnDisable is disabled") |
| 856 | return |
| 857 | } |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 858 | logger.Infow(ctx, "VPV Port DOWN Ind, deleting all flows for services", |
| 859 | log.Fields{"service count": vpv.servicesCount.Load()}) |
| 860 | |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 861 | //vpv.RangeOnServices(cntx, DelAllFlows) |
| 862 | vpv.DelTrapFlows(cntx) |
Sridhar Ravindra | 03aa0bf | 2023-09-12 17:46:40 +0530 | [diff] [blame] | 863 | vpv.DelHsiaFlows(cntx, delFlowsInDevice) |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 864 | vpv.WriteToDb(cntx) |
| 865 | vpv.ClearServiceCounters(cntx) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 866 | } |
| 867 | |
| 868 | // SetMacAddr : The MAC address is set when a MAC address is learnt through the |
| 869 | // packets received from the network. Currently, DHCP packets are |
| 870 | // only packets we learn the MAC address from |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 871 | func (vpv *VoltPortVnet) SetMacAddr(cntx context.Context, addr net.HardwareAddr) { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 872 | logger.Infow(ctx, "Set Mac Addr", log.Fields{"MAC addr": addr.String(), "Port": vpv.Port}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 873 | //Store Learnt MAC address and return if MACLearning is not enabled |
| 874 | vpv.LearntMacAddr = addr |
| 875 | if vpv.MacLearning == MacLearningNone || !NonZeroMacAddress(addr) || |
| 876 | (NonZeroMacAddress(vpv.MacAddr) && vpv.MacLearning == Learn) { |
| 877 | return |
| 878 | } |
| 879 | |
| 880 | // Compare the two MAC addresses to see if it is same |
| 881 | // If they are same, we just return. If not, we perform |
| 882 | // actions to address the change in MAC address |
| 883 | //if NonZeroMacAddress(vpv.MacAddr) && !util.MacAddrsMatch(vpv.MacAddr, addr) { |
| 884 | if !util.MacAddrsMatch(vpv.MacAddr, addr) { |
| 885 | expectedPort := GetApplication().GetMacInPortMap(addr) |
| 886 | if expectedPort != "" && expectedPort != vpv.Port { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 887 | logger.Warnw(ctx, "mac-learnt-from-different-port-ignoring-setmacaddr", |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 888 | log.Fields{"ExpectedPort": expectedPort, "ReceivedPort": vpv.Port, "LearntMacAdrr": vpv.MacAddr, "NewMacAdrr": addr.String()}) |
| 889 | return |
| 890 | } |
| 891 | if NonZeroMacAddress(vpv.MacAddr) { |
| 892 | logger.Warnw(ctx, "MAC Address Changed. Remove old flows (if added) and re-add with updated MAC", log.Fields{"UpdatedMAC": addr}) |
| 893 | |
| 894 | // The newly learnt MAC address is different than earlier one. |
| 895 | // The existing MAC based HSIA flows need to be undone as the device |
| 896 | // may have been changed |
| 897 | // Atleast one HSIA flow should be present in adapter to retain the TP and GEM |
| 898 | // hence delete one after the other |
Sridhar Ravindra | 03aa0bf | 2023-09-12 17:46:40 +0530 | [diff] [blame] | 899 | vpv.RangeOnServices(cntx, DelUsHsiaFlows, false) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 900 | vpv.MacAddr = addr |
Sridhar Ravindra | 03aa0bf | 2023-09-12 17:46:40 +0530 | [diff] [blame] | 901 | vpv.RangeOnServices(cntx, vpv.setLearntMAC, false) |
| 902 | vpv.RangeOnServices(cntx, AddUsHsiaFlows, false) |
| 903 | vpv.RangeOnServices(cntx, DelDsHsiaFlows, false) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 904 | GetApplication().DeleteMacInPortMap(vpv.MacAddr) |
| 905 | } else { |
| 906 | vpv.MacAddr = addr |
Sridhar Ravindra | 03aa0bf | 2023-09-12 17:46:40 +0530 | [diff] [blame] | 907 | vpv.RangeOnServices(cntx, vpv.setLearntMAC, false) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 908 | logger.Infow(ctx, "MAC Address learnt from DHCP or ARP", log.Fields{"Learnt MAC": addr.String(), "Port": vpv.Port}) |
| 909 | } |
| 910 | GetApplication().UpdateMacInPortMap(vpv.MacAddr, vpv.Port) |
| 911 | } else { |
| 912 | logger.Infow(ctx, "Leant MAC Address is same", log.Fields{"Learnt MAC": addr.String(), "Port": vpv.Port}) |
| 913 | } |
| 914 | |
| 915 | _, err := GetApplication().GetDeviceFromPort(vpv.Port) |
| 916 | if err != nil { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 917 | logger.Errorw(ctx, "Not pushing Service Flows: Error Getting Device", log.Fields{"Reason": err.Error()}) |
Akash Soni | a824697 | 2023-01-03 10:37:08 +0530 | [diff] [blame] | 918 | statusCode, statusMessage := errorCodes.GetErrorInfo(err) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 919 | vpv.FlowInstallFailure("VGC processing failure", statusCode, statusMessage) |
| 920 | return |
| 921 | } |
| 922 | // Ds Hsia flows has to be pushed |
| 923 | if vpv.FlowsApplied { |
Tinoj Joseph | 50d722c | 2022-12-06 22:53:22 +0530 | [diff] [blame] | 924 | // In case of DPU_MGMT_TRAFFIC install both US and DS Flows |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 925 | if vpv.VnetType == DpuMgmtTraffic { |
Sridhar Ravindra | 03aa0bf | 2023-09-12 17:46:40 +0530 | [diff] [blame] | 926 | vpv.RangeOnServices(cntx, AddUsHsiaFlows, false) |
Tinoj Joseph | 50d722c | 2022-12-06 22:53:22 +0530 | [diff] [blame] | 927 | } |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 928 | // no HSIA flows for multicast service |
| 929 | if !vpv.McastService { |
Sridhar Ravindra | 03aa0bf | 2023-09-12 17:46:40 +0530 | [diff] [blame] | 930 | vpv.RangeOnServices(cntx, AddDsHsiaFlows, false) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 931 | } |
| 932 | } |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 933 | vpv.WriteToDb(cntx) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 934 | } |
| 935 | |
| 936 | // MatchesVlans : If the VNET matches both S and C VLANs, return true. Else, return false |
| 937 | func (vpv *VoltPortVnet) MatchesVlans(svlan of.VlanType, cvlan of.VlanType, univlan of.VlanType) bool { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 938 | logger.Debugw(ctx, "Matches Vlans", log.Fields{"Svlan": svlan, "Cvlan": cvlan, "Univlan": univlan}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 939 | if vpv.SVlan != svlan || vpv.CVlan != cvlan || vpv.UniVlan != univlan { |
| 940 | return false |
| 941 | } |
| 942 | return true |
| 943 | } |
| 944 | |
| 945 | // MatchesCvlan : If the VNET matches CVLAN, return true. Else, return false |
| 946 | func (vpv *VoltPortVnet) MatchesCvlan(cvlan []of.VlanType) bool { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 947 | logger.Debugw(ctx, "Matches Cvlans", log.Fields{"Cvlan": cvlan}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 948 | if len(cvlan) != 1 && !vpv.AllowTransparent { |
| 949 | return false |
| 950 | } |
| 951 | if vpv.CVlan != cvlan[0] { |
| 952 | return false |
| 953 | } |
| 954 | return true |
| 955 | } |
| 956 | |
| 957 | // MatchesPriority : If the VNET matches priority of the incoming packet with any service, return true. Else, return false |
| 958 | func (vpv *VoltPortVnet) MatchesPriority(priority uint8) *VoltService { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 959 | logger.Debugw(ctx, "Matches Priority", log.Fields{"Priority": priority}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 960 | var service *VoltService |
| 961 | pbitFound := false |
| 962 | matchpbitsFunc := func(key, value interface{}) bool { |
| 963 | svc := value.(*VoltService) |
| 964 | for _, pbit := range svc.Pbits { |
Sridhar Ravindra | b8374ae | 2023-04-14 15:49:25 +0530 | [diff] [blame] | 965 | if uint8(pbit) == priority || uint8(pbit) == uint8(of.PbitMatchAll) { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 966 | logger.Infow(ctx, "Pbit match found with service", |
| 967 | log.Fields{"Pbit": priority, "serviceName": svc.Name}) |
| 968 | pbitFound = true |
| 969 | service = svc |
| 970 | return false //Returning false to stop the Range loop |
| 971 | } |
| 972 | } |
| 973 | return true |
| 974 | } |
| 975 | _ = pbitFound |
| 976 | vpv.services.Range(matchpbitsFunc) |
| 977 | return service |
| 978 | } |
| 979 | |
| 980 | // GetRemarkedPriority : If the VNET matches priority of the incoming packet with any service, return true. Else, return false |
| 981 | func (vpv *VoltPortVnet) GetRemarkedPriority(priority uint8) uint8 { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 982 | logger.Debugw(ctx, "Get Remarked Priority", log.Fields{"Priority": priority}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 983 | dsPbit := uint8(0) |
| 984 | matchpbitsFunc := func(key, value interface{}) bool { |
| 985 | svc := value.(*VoltService) |
| 986 | if remarkPbit, ok := svc.DsRemarkPbitsMap[int(priority)]; ok { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 987 | logger.Warnw(ctx, "Pbit match found with service", |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 988 | log.Fields{"Pbit": priority, "serviceName": svc.Name, "remarkPbit": remarkPbit}) |
| 989 | dsPbit = uint8(remarkPbit) |
| 990 | return false //Returning false to stop the Range loop |
| 991 | } |
| 992 | // When no remarking info is available, remark the incoming pbit |
| 993 | // to highest pbit configured for the subscriber (across all subservices associated) |
| 994 | svcPbit := uint8(svc.Pbits[0]) |
| 995 | if svcPbit > dsPbit { |
| 996 | dsPbit = svcPbit |
| 997 | } |
| 998 | return true |
| 999 | } |
| 1000 | vpv.services.Range(matchpbitsFunc) |
| 1001 | logger.Debugw(ctx, "Remarked Pbit Value", log.Fields{"Incoming": priority, "Remarked": dsPbit}) |
| 1002 | return dsPbit |
| 1003 | } |
| 1004 | |
| 1005 | // AddSvc adds a service on the VNET on a port. The addition is |
| 1006 | // triggered when NB requests for service addition |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 1007 | func (vpv *VoltPortVnet) AddSvc(cntx context.Context, svc *VoltService) { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 1008 | logger.Infow(ctx, "Add Service to VPV", log.Fields{"ServiceName": svc.Name}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1009 | //vpv.services = append(vpv.services, svc) |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 1010 | vpv.AddService(cntx, svc) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1011 | logger.Debugw(ctx, "Added Service to VPV", log.Fields{"Num of SVCs": vpv.servicesCount.Load(), "SVC": svc}) |
| 1012 | |
| 1013 | // Learn the circuit-id and remote-id from the service |
| 1014 | // TODO: There must be a better way of doing this. This |
| 1015 | // may be explored |
| 1016 | if svc.IgmpEnabled { |
| 1017 | vpv.IgmpEnabled = true |
| 1018 | } |
| 1019 | // first time service activation MacLearning will have default value as None. |
| 1020 | // to handle reciliency if anythng other then None we should retain it . |
| 1021 | if svc.MacLearning == MacLearningNone { |
| 1022 | if !vpv.DhcpRelay && !vpv.ArpRelay { |
| 1023 | svc.MacLearning = MacLearningNone |
| 1024 | } else if vpv.MacLearning == Learn { |
| 1025 | svc.MacLearning = Learn |
| 1026 | } else if vpv.MacLearning == ReLearn { |
| 1027 | svc.MacLearning = ReLearn |
| 1028 | } |
| 1029 | } |
| 1030 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 1031 | // TODO: Temp Change - Need to address MAC Learning flow issues completely |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1032 | if (svc.MacLearning == Learn || svc.MacLearning == ReLearn) && NonZeroMacAddress(vpv.MacAddr) { |
| 1033 | svc.MacAddr = vpv.MacAddr |
| 1034 | } else if vpv.servicesCount.Load() == 1 { |
| 1035 | vpv.MacAddr = svc.MacAddr |
| 1036 | } |
| 1037 | |
| 1038 | vpv.MacLearning = svc.MacLearning |
| 1039 | vpv.PonPort = svc.PonPort |
| 1040 | logger.Debugw(ctx, "Added MAC to VPV", log.Fields{"MacLearning": vpv.MacLearning, "VPV": vpv}) |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 1041 | // Reconfigure Vlans based on Vlan Control type |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1042 | svc.VlanControl = vpv.VlanControl |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1043 | if svc.McastService { |
| 1044 | vpv.McastService = true |
| 1045 | vpv.McastTechProfileID = svc.TechProfileID |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 1046 | // Assumption: Only one Pbit for mcast service |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1047 | vpv.McastPbit = svc.Pbits[0] |
| 1048 | vpv.McastUsMeterID = svc.UsMeterID |
| 1049 | vpv.SchedID = svc.SchedID |
| 1050 | } |
| 1051 | svc.ONTEtherTypeClassification = vpv.ONTEtherTypeClassification |
| 1052 | svc.AllowTransparent = vpv.AllowTransparent |
| 1053 | svc.SVlanTpid = vpv.SVlanTpid |
| 1054 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 1055 | // Ensure configuring the mvlan profile only once |
| 1056 | // One subscriber cannot have multiple mvlan profiles. Only the first configuration is valid |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1057 | if svc.MvlanProfileName != "" { |
| 1058 | if vpv.MvlanProfileName == "" { |
| 1059 | vpv.MvlanProfileName = svc.MvlanProfileName |
| 1060 | } else { |
| 1061 | logger.Warnw(ctx, "Mvlan Profile already configured for subscriber. Ignoring new Mvlan", log.Fields{"Existing Mvlan": vpv.MvlanProfileName, "New Mvlan": svc.MvlanProfileName}) |
| 1062 | } |
| 1063 | } |
| 1064 | |
Akash Soni | a824697 | 2023-01-03 10:37:08 +0530 | [diff] [blame] | 1065 | voltDevice, err := GetApplication().GetDeviceFromPort(vpv.Port) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1066 | if err != nil { |
| 1067 | logger.Warnw(ctx, "Not pushing Service Flows: Error Getting Device", log.Fields{"Reason": err.Error()}) |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 1068 | // statusCode, statusMessage := errorCodes.GetErrorInfo(err) |
| 1069 | // TODO-COMM: vpv.FlowInstallFailure("VGC processing failure", statusCode, statusMessage) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1070 | return |
| 1071 | } |
Tinoj Joseph | ec742f6 | 2022-09-29 19:11:10 +0530 | [diff] [blame] | 1072 | if !svc.IsActivated { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 1073 | logger.Warnw(ctx, "Not pushing Service Flows: Service Not activated", log.Fields{"ServiceName": svc.Name}) |
Tinoj Joseph | ec742f6 | 2022-09-29 19:11:10 +0530 | [diff] [blame] | 1074 | return |
| 1075 | } |
Akash Soni | a824697 | 2023-01-03 10:37:08 +0530 | [diff] [blame] | 1076 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 1077 | // If NNI port is not mached to nb nni port |
Akash Soni | a824697 | 2023-01-03 10:37:08 +0530 | [diff] [blame] | 1078 | devConfig := GetApplication().GetDeviceConfig(voltDevice.SerialNum) |
| 1079 | |
Akash Soni | 53da285 | 2023-03-15 00:31:31 +0530 | [diff] [blame] | 1080 | if devConfig.UplinkPort != voltDevice.NniPort { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 1081 | logger.Warnw(ctx, "NNI port mismatch", log.Fields{"NB NNI Port": devConfig.UplinkPort, "SB NNI port": voltDevice.NniPort}) |
Akash Soni | a824697 | 2023-01-03 10:37:08 +0530 | [diff] [blame] | 1082 | return |
| 1083 | } |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 1084 | // Push Service Flows if DHCP relay is not configured |
| 1085 | // or already DHCP flows are configured for the VPV |
| 1086 | // to which the serivce is associated |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1087 | if vpv.FlowsApplied { |
| 1088 | if NonZeroMacAddress(vpv.MacAddr) || svc.MacLearning == MacLearningNone { |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 1089 | svc.AddHsiaFlows(cntx) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1090 | } else { |
Akash Soni | a824697 | 2023-01-03 10:37:08 +0530 | [diff] [blame] | 1091 | if err := svc.AddUsHsiaFlows(cntx); err != nil { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1092 | logger.Warnw(ctx, "Add US hsia flow failed", log.Fields{"service": svc.Name, "Error": err}) |
| 1093 | } |
| 1094 | } |
| 1095 | } |
| 1096 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 1097 | // Assumption: Igmp will be enabled only for one service and SubMgr ensure the same |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1098 | // When already the port is UP and provisioned a service without igmp, then trap flows for subsequent |
| 1099 | // service with Igmp Enabled needs to be installed |
| 1100 | if svc.IgmpEnabled && vpv.FlowsApplied { |
| 1101 | logger.Infow(ctx, "Add Service - IGMP Flows", log.Fields{"Device": vpv.Device, "Port": vpv.Port}) |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 1102 | if err := vpv.AddIgmpFlows(cntx); err != nil { |
Akash Soni | a824697 | 2023-01-03 10:37:08 +0530 | [diff] [blame] | 1103 | statusCode, statusMessage := errorCodes.GetErrorInfo(err) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1104 | vpv.FlowInstallFailure("VGC processing failure", statusCode, statusMessage) |
| 1105 | } |
| 1106 | |
| 1107 | if vpv.McastService { |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 1108 | // For McastService, send Service Activated indication once IGMP US flow is pushed |
Sridhar Ravindra | 03aa0bf | 2023-09-12 17:46:40 +0530 | [diff] [blame] | 1109 | vpv.RangeOnServices(cntx, PostAccessConfigSuccessInd, false) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1110 | } |
| 1111 | } |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 1112 | vpv.WriteToDb(cntx) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1113 | } |
| 1114 | |
| 1115 | // setLearntMAC to set learnt mac |
Sridhar Ravindra | 03aa0bf | 2023-09-12 17:46:40 +0530 | [diff] [blame] | 1116 | func (vpv *VoltPortVnet) setLearntMAC(cntx context.Context, key, value interface{}, flag bool) bool { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1117 | svc := value.(*VoltService) |
| 1118 | svc.SetMacAddr(vpv.MacAddr) |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 1119 | svc.WriteToDb(cntx) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1120 | return true |
| 1121 | } |
| 1122 | |
| 1123 | // PostAccessConfigSuccessInd for posting access config success indication |
Sridhar Ravindra | 03aa0bf | 2023-09-12 17:46:40 +0530 | [diff] [blame] | 1124 | func PostAccessConfigSuccessInd(cntx context.Context, key, value interface{}, flag bool) bool { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1125 | return true |
| 1126 | } |
| 1127 | |
| 1128 | // updateIPv4AndProvisionFlows to update ipv4 and provisional flows |
Sridhar Ravindra | 03aa0bf | 2023-09-12 17:46:40 +0530 | [diff] [blame] | 1129 | func (vpv *VoltPortVnet) updateIPv4AndProvisionFlows(cntx context.Context, key, value interface{}, flag bool) bool { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1130 | svc := value.(*VoltService) |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 1131 | logger.Debugw(ctx, "Updating Ipv4 address for service", log.Fields{"ServiceName": svc.Name}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1132 | svc.SetIpv4Addr(vpv.Ipv4Addr) |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 1133 | svc.WriteToDb(cntx) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1134 | |
| 1135 | return true |
| 1136 | } |
| 1137 | |
| 1138 | // updateIPv6AndProvisionFlows to update ipv6 and provisional flow |
Sridhar Ravindra | 03aa0bf | 2023-09-12 17:46:40 +0530 | [diff] [blame] | 1139 | func (vpv *VoltPortVnet) updateIPv6AndProvisionFlows(cntx context.Context, key, value interface{}, flag bool) bool { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1140 | svc := value.(*VoltService) |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 1141 | logger.Debugw(ctx, "Updating Ipv6 address for service", log.Fields{"ServiceName": svc.Name}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1142 | svc.SetIpv6Addr(vpv.Ipv6Addr) |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 1143 | svc.WriteToDb(cntx) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1144 | |
| 1145 | return true |
| 1146 | } |
| 1147 | |
| 1148 | // AddUsHsiaFlows to add upstream hsia flows |
Sridhar Ravindra | 03aa0bf | 2023-09-12 17:46:40 +0530 | [diff] [blame] | 1149 | func AddUsHsiaFlows(cntx context.Context, key, value interface{}, flag bool) bool { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1150 | svc := value.(*VoltService) |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 1151 | logger.Debugw(ctx, "Add US Hsia Flows", log.Fields{"ServiceName": svc.Name}) |
Akash Soni | a824697 | 2023-01-03 10:37:08 +0530 | [diff] [blame] | 1152 | if err := svc.AddUsHsiaFlows(cntx); err != nil { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1153 | logger.Warnw(ctx, "Add US hsia flow failed", log.Fields{"service": svc.Name, "Error": err}) |
| 1154 | } |
| 1155 | return true |
| 1156 | } |
| 1157 | |
| 1158 | // AddDsHsiaFlows to add downstream hsia flows |
Sridhar Ravindra | 03aa0bf | 2023-09-12 17:46:40 +0530 | [diff] [blame] | 1159 | func AddDsHsiaFlows(cntx context.Context, key, value interface{}, flag bool) bool { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1160 | svc := value.(*VoltService) |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 1161 | logger.Debugw(ctx, "Add DS Hsia Flows", log.Fields{"ServiceName": svc.Name}) |
Akash Soni | a824697 | 2023-01-03 10:37:08 +0530 | [diff] [blame] | 1162 | if err := svc.AddDsHsiaFlows(cntx); err != nil { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1163 | logger.Warnw(ctx, "Add DS hsia flow failed", log.Fields{"service": svc.Name, "Error": err}) |
| 1164 | } |
| 1165 | return true |
| 1166 | } |
| 1167 | |
| 1168 | // ClearFlagsInService to clear the flags used in service |
Sridhar Ravindra | 03aa0bf | 2023-09-12 17:46:40 +0530 | [diff] [blame] | 1169 | func ClearFlagsInService(cntx context.Context, key, value interface{}, flag bool) bool { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1170 | svc := value.(*VoltService) |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 1171 | logger.Debugw(ctx, "Received Cleared Flow Flags for service", log.Fields{"name": svc.Name}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1172 | svc.ServiceLock.Lock() |
| 1173 | svc.IgmpFlowsApplied = false |
| 1174 | svc.DsDhcpFlowsApplied = false |
| 1175 | svc.DsHSIAFlowsApplied = false |
| 1176 | svc.Icmpv6FlowsApplied = false |
| 1177 | svc.UsHSIAFlowsApplied = false |
| 1178 | svc.UsDhcpFlowsApplied = false |
| 1179 | svc.PendingFlows = make(map[string]bool) |
| 1180 | svc.AssociatedFlows = make(map[string]bool) |
| 1181 | svc.ServiceLock.Unlock() |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 1182 | svc.WriteToDb(cntx) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1183 | logger.Debugw(ctx, "Cleared Flow Flags for service", log.Fields{"name": svc.Name}) |
| 1184 | return true |
| 1185 | } |
| 1186 | |
| 1187 | // DelDsHsiaFlows to delete hsia flows |
Sridhar Ravindra | 03aa0bf | 2023-09-12 17:46:40 +0530 | [diff] [blame] | 1188 | // delFlowsInDevice flag indicates that flows should be deleted only in DB/device and should not be forwarded to core |
| 1189 | func DelDsHsiaFlows(cntx context.Context, key, value interface{}, delFlowsInDevice bool) bool { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1190 | svc := value.(*VoltService) |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 1191 | logger.Debugw(ctx, "Delete DS Hsia Flows", log.Fields{"ServiceName": svc.Name}) |
Sridhar Ravindra | 03aa0bf | 2023-09-12 17:46:40 +0530 | [diff] [blame] | 1192 | if err := svc.DelDsHsiaFlows(cntx, delFlowsInDevice); err != nil { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1193 | logger.Warnw(ctx, "Delete DS hsia flow failed", log.Fields{"service": svc.Name, "Error": err}) |
| 1194 | } |
| 1195 | return true |
| 1196 | } |
| 1197 | |
| 1198 | // DelUsHsiaFlows to delete upstream hsia flows |
Sridhar Ravindra | 03aa0bf | 2023-09-12 17:46:40 +0530 | [diff] [blame] | 1199 | // delFlowsInDevice flag indicates that flows should be deleted only in DB/device and should not be forwarded to core |
| 1200 | func DelUsHsiaFlows(cntx context.Context, key, value interface{}, delFlowsInDevice bool) bool { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1201 | svc := value.(*VoltService) |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 1202 | logger.Debugw(ctx, "Delete US Hsia Flows", log.Fields{"ServiceName": svc.Name}) |
Sridhar Ravindra | 03aa0bf | 2023-09-12 17:46:40 +0530 | [diff] [blame] | 1203 | if err := svc.DelUsHsiaFlows(cntx, delFlowsInDevice); err != nil { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1204 | logger.Warnw(ctx, "Delete US hsia flow failed", log.Fields{"service": svc.Name, "Error": err}) |
| 1205 | } |
| 1206 | return true |
| 1207 | } |
| 1208 | |
| 1209 | // ClearServiceCounters to clear the service counters |
Sridhar Ravindra | 03aa0bf | 2023-09-12 17:46:40 +0530 | [diff] [blame] | 1210 | func ClearServiceCounters(cntx context.Context, key, value interface{}, flag bool) bool { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1211 | svc := value.(*VoltService) |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 1212 | logger.Debugw(ctx, "Received Clear Service Counters", log.Fields{"ServiceName": svc.Name}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1213 | //Delete the per service counter too |
| 1214 | GetApplication().ServiceCounters.Delete(svc.Name) |
| 1215 | if svc.IgmpEnabled && svc.EnableMulticastKPI { |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 1216 | _ = db.DelAllServiceChannelCounter(cntx, svc.Name) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1217 | } |
| 1218 | return true |
| 1219 | } |
| 1220 | |
Tinoj Joseph | 50d722c | 2022-12-06 22:53:22 +0530 | [diff] [blame] | 1221 | // AddMeterToDevice to add meter config to device, used in FTTB case |
Sridhar Ravindra | 03aa0bf | 2023-09-12 17:46:40 +0530 | [diff] [blame] | 1222 | func AddMeterToDevice(cntx context.Context, key, value interface{}, flag bool) bool { |
Tinoj Joseph | 50d722c | 2022-12-06 22:53:22 +0530 | [diff] [blame] | 1223 | svc := value.(*VoltService) |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 1224 | logger.Debugw(ctx, "Received Add Meter To Device", log.Fields{"ServiceName": svc.Name}) |
Akash Soni | 53da285 | 2023-03-15 00:31:31 +0530 | [diff] [blame] | 1225 | if err := svc.AddMeterToDevice(cntx); err != nil { |
Tinoj Joseph | 50d722c | 2022-12-06 22:53:22 +0530 | [diff] [blame] | 1226 | logger.Warnw(ctx, "Add Meter failed", log.Fields{"service": svc.Name, "Error": err}) |
| 1227 | } |
| 1228 | return true |
| 1229 | } |
| 1230 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 1231 | // AddTrapFlows - Adds US & DS Trap flows |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 1232 | func (vpv *VoltPortVnet) AddTrapFlows(cntx context.Context) { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 1233 | logger.Debugw(ctx, "Received Add US & DS DHCP, IGMP Trap Flows", log.Fields{"FlowsApplied": vpv.FlowsApplied, "VgcRebooted": vgcRebooted}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1234 | if !vpv.FlowsApplied || vgcRebooted { |
| 1235 | if vpv.DhcpRelay { |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 1236 | if err := vpv.AddUsDhcpFlows(cntx); err != nil { |
Akash Soni | a824697 | 2023-01-03 10:37:08 +0530 | [diff] [blame] | 1237 | statusCode, statusMessage := errorCodes.GetErrorInfo(err) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1238 | vpv.FlowInstallFailure("VGC processing failure", statusCode, statusMessage) |
| 1239 | } |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 1240 | if err := vpv.AddDsDhcpFlows(cntx); err != nil { |
Akash Soni | a824697 | 2023-01-03 10:37:08 +0530 | [diff] [blame] | 1241 | statusCode, statusMessage := errorCodes.GetErrorInfo(err) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1242 | vpv.FlowInstallFailure("VGC processing failure", statusCode, statusMessage) |
| 1243 | } |
| 1244 | logger.Infow(ctx, "ICMPv6 MC Group modification will not be triggered to rwcore for ", |
| 1245 | log.Fields{"port": vpv.Port}) |
| 1246 | //vpv.updateICMPv6McGroup(true) |
| 1247 | } else if vpv.ArpRelay { |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 1248 | if err := vpv.AddUsArpFlows(cntx); err != nil { |
Akash Soni | a824697 | 2023-01-03 10:37:08 +0530 | [diff] [blame] | 1249 | statusCode, statusMessage := errorCodes.GetErrorInfo(err) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1250 | vpv.FlowInstallFailure("VGC processing failure", statusCode, statusMessage) |
| 1251 | } |
| 1252 | logger.Info(ctx, "ARP trap rules not added in downstream direction") |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1253 | } else if vpv.PppoeIa { |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 1254 | if err := vpv.AddUsPppoeFlows(cntx); err != nil { |
Akash Soni | a824697 | 2023-01-03 10:37:08 +0530 | [diff] [blame] | 1255 | statusCode, statusMessage := errorCodes.GetErrorInfo(err) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1256 | vpv.FlowInstallFailure("VGC processing failure", statusCode, statusMessage) |
| 1257 | } |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 1258 | if err := vpv.AddDsPppoeFlows(cntx); err != nil { |
Akash Soni | a824697 | 2023-01-03 10:37:08 +0530 | [diff] [blame] | 1259 | statusCode, statusMessage := errorCodes.GetErrorInfo(err) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1260 | vpv.FlowInstallFailure("VGC processing failure", statusCode, statusMessage) |
| 1261 | } |
| 1262 | } |
| 1263 | vpv.FlowsApplied = true |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 1264 | vpv.WriteToDb(cntx) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1265 | } |
| 1266 | } |
| 1267 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 1268 | // DelTrapFlows - Removes all US & DS DHCP, IGMP trap flows. |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 1269 | func (vpv *VoltPortVnet) DelTrapFlows(cntx context.Context) { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 1270 | logger.Debugw(ctx, "Received Delete US & DS DHCP, IGMP Trap Flows", log.Fields{"FlowsApplied": vpv.FlowsApplied, "VgcRebooted": vgcRebooted}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1271 | // Delete HSIA & DHCP flows before deleting IGMP flows |
| 1272 | if vpv.FlowsApplied || vgcRebooted { |
| 1273 | if vpv.DhcpRelay { |
Akash Soni | a824697 | 2023-01-03 10:37:08 +0530 | [diff] [blame] | 1274 | if err := vpv.DelUsDhcpFlows(cntx); err != nil { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1275 | logger.Warnw(ctx, "Delete US hsia flow failed", log.Fields{"port": vpv.Port, "SVlan": vpv.SVlan, "CVlan": vpv.CVlan, |
| 1276 | "UniVlan": vpv.UniVlan, "Error": err}) |
| 1277 | } |
| 1278 | logger.Infow(ctx, "ICMPv6 MC Group modification will not be triggered to rwcore for ", |
| 1279 | log.Fields{"port": vpv.Port}) |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 1280 | if err := vpv.DelDsDhcpFlows(cntx); err != nil { |
Akash Soni | a824697 | 2023-01-03 10:37:08 +0530 | [diff] [blame] | 1281 | statusCode, statusMessage := errorCodes.GetErrorInfo(err) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1282 | vpv.FlowInstallFailure("VGC processing failure", statusCode, statusMessage) |
| 1283 | } |
| 1284 | //vpv.updateICMPv6McGroup(false) |
| 1285 | } else if vpv.ArpRelay { |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 1286 | if err := vpv.DelUsArpFlows(cntx); err != nil { |
Akash Soni | a824697 | 2023-01-03 10:37:08 +0530 | [diff] [blame] | 1287 | statusCode, statusMessage := errorCodes.GetErrorInfo(err) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1288 | vpv.FlowInstallFailure("VGC processing failure", statusCode, statusMessage) |
| 1289 | } |
| 1290 | } else if vpv.PppoeIa { |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 1291 | if err := vpv.DelUsPppoeFlows(cntx); err != nil { |
Akash Soni | a824697 | 2023-01-03 10:37:08 +0530 | [diff] [blame] | 1292 | statusCode, statusMessage := errorCodes.GetErrorInfo(err) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1293 | vpv.FlowInstallFailure("VGC processing failure", statusCode, statusMessage) |
| 1294 | } |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 1295 | if err := vpv.DelDsPppoeFlows(cntx); err != nil { |
Akash Soni | a824697 | 2023-01-03 10:37:08 +0530 | [diff] [blame] | 1296 | statusCode, statusMessage := errorCodes.GetErrorInfo(err) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1297 | vpv.FlowInstallFailure("VGC processing failure", statusCode, statusMessage) |
| 1298 | } |
| 1299 | } |
| 1300 | vpv.FlowsApplied = false |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 1301 | vpv.WriteToDb(cntx) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1302 | } |
Akash Soni | a824697 | 2023-01-03 10:37:08 +0530 | [diff] [blame] | 1303 | if err := vpv.DelIgmpFlows(cntx); err != nil { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1304 | logger.Warnw(ctx, "Delete igmp flow failed", log.Fields{"port": vpv.Port, "SVlan": vpv.SVlan, "CVlan": vpv.CVlan, |
| 1305 | "UniVlan": vpv.UniVlan, "Error": err}) |
| 1306 | } |
| 1307 | } |
| 1308 | |
| 1309 | // DelHsiaFlows deletes the service flows |
Sridhar Ravindra | 03aa0bf | 2023-09-12 17:46:40 +0530 | [diff] [blame] | 1310 | func (vpv *VoltPortVnet) DelHsiaFlows(cntx context.Context, delFlowsInDevice bool) { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 1311 | logger.Infow(ctx, "Received Delete Hsia Flows", log.Fields{"McastService": vpv.McastService}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1312 | // no HSIA flows for multicast service |
| 1313 | if !vpv.McastService { |
Sridhar Ravindra | 03aa0bf | 2023-09-12 17:46:40 +0530 | [diff] [blame] | 1314 | vpv.RangeOnServices(cntx, DelUsHsiaFlows, delFlowsInDevice) |
| 1315 | vpv.RangeOnServices(cntx, DelDsHsiaFlows, delFlowsInDevice) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1316 | } |
| 1317 | } |
| 1318 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 1319 | // ClearServiceCounters - Removes all igmp counters for a service |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 1320 | func (vpv *VoltPortVnet) ClearServiceCounters(cntx context.Context) { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1321 | //send flows deleted indication to submgr |
Sridhar Ravindra | 03aa0bf | 2023-09-12 17:46:40 +0530 | [diff] [blame] | 1322 | vpv.RangeOnServices(cntx, ClearServiceCounters, false) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1323 | } |
| 1324 | |
| 1325 | // AddUsDhcpFlows pushes the DHCP flows to the VOLTHA via the controller |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 1326 | func (vpv *VoltPortVnet) AddUsDhcpFlows(cntx context.Context) error { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1327 | var vd *VoltDevice |
| 1328 | device := vpv.Device |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 1329 | logger.Debugw(ctx, "Received Add US DHCP Flows", log.Fields{"Device": device}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1330 | |
| 1331 | if vd = GetApplication().GetDevice(device); vd != nil { |
| 1332 | if vd.State != controller.DeviceStateUP { |
| 1333 | logger.Errorw(ctx, "Skipping US DHCP Flow Push - Device state DOWN", log.Fields{"Port": vpv.Port, "SVLAN": vpv.SVlan, "CVLAN": vpv.CVlan, "UNIVlan": vpv.UniVlan, "device": device}) |
| 1334 | return nil |
| 1335 | } |
| 1336 | } else { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 1337 | err := errorCodes.ErrDeviceNotFound |
| 1338 | return fmt.Errorf("us dhcp flow push failed - device not found for Port %s, Svlan %d, Cvlan %d, UniVlan %d. Device %s : %w", vpv.Port, vpv.SVlan, vpv.CVlan, vpv.UniVlan, device, err) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1339 | } |
| 1340 | |
| 1341 | flows, err := vpv.BuildUsDhcpFlows() |
| 1342 | if err == nil { |
| 1343 | logger.Debugw(ctx, "Adding US DHCP flows", log.Fields{"Device": device}) |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 1344 | if err1 := vpv.PushFlows(cntx, vd, flows); err1 != nil { |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 1345 | // push ind here ABHI |
Akash Soni | a824697 | 2023-01-03 10:37:08 +0530 | [diff] [blame] | 1346 | statusCode, statusMessage := errorCodes.GetErrorInfo(err1) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1347 | vpv.FlowInstallFailure("VGC processing failure", statusCode, statusMessage) |
| 1348 | } |
| 1349 | } else { |
| 1350 | logger.Errorw(ctx, "US DHCP Flow Add Failed", log.Fields{"Reason": err.Error(), "Device": device}) |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 1351 | // push ind here ABHI |
Akash Soni | a824697 | 2023-01-03 10:37:08 +0530 | [diff] [blame] | 1352 | statusCode, statusMessage := errorCodes.GetErrorInfo(err) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1353 | vpv.FlowInstallFailure("VGC processing failure", statusCode, statusMessage) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1354 | } |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1355 | return nil |
| 1356 | } |
| 1357 | |
| 1358 | // AddDsDhcpFlows function pushes the DHCP flows to the VOLTHA via the controller |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 1359 | func (vpv *VoltPortVnet) AddDsDhcpFlows(cntx context.Context) error { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1360 | var vd *VoltDevice |
| 1361 | device := vpv.Device |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 1362 | logger.Debugw(ctx, "Received Add DS DHCP Flows", log.Fields{"Device": device}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1363 | |
| 1364 | if vd = GetApplication().GetDevice(device); vd != nil { |
| 1365 | if vd.State != controller.DeviceStateUP { |
| 1366 | logger.Errorw(ctx, "Skipping DS DHCP Flow Push - Device state DOWN", log.Fields{"Port": vpv.Port, "SVLAN": vpv.SVlan, "CVLAN": vpv.CVlan, "UNIVlan": vpv.UniVlan, "device": device}) |
| 1367 | return nil |
| 1368 | } |
| 1369 | } else { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 1370 | err := errorCodes.ErrDeviceNotFound |
| 1371 | return fmt.Errorf("ds dhcp flow push failed - device not found for Port %s, Svlan %d, Cvlan %d, UniVlan %d. Device %s : %w", vpv.Port, vpv.SVlan, vpv.CVlan, vpv.UniVlan, device, err) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1372 | } |
Tinoj Joseph | 50d722c | 2022-12-06 22:53:22 +0530 | [diff] [blame] | 1373 | if vd.GlobalDhcpFlowAdded { |
| 1374 | logger.Info(ctx, "Global Dhcp flow already exists") |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1375 | return nil |
| 1376 | } |
| 1377 | |
| 1378 | flows, err := vpv.BuildDsDhcpFlows() |
| 1379 | if err == nil { |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 1380 | if err1 := vpv.PushFlows(cntx, vd, flows); err1 != nil { |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 1381 | // push ind here and procced |
Akash Soni | a824697 | 2023-01-03 10:37:08 +0530 | [diff] [blame] | 1382 | statusCode, statusMessage := errorCodes.GetErrorInfo(err1) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1383 | vpv.FlowInstallFailure("VGC processing failure", statusCode, statusMessage) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1384 | } |
| 1385 | } else { |
| 1386 | logger.Errorw(ctx, "DS DHCP Flow Add Failed", log.Fields{"Reason": err.Error()}) |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 1387 | // send ind here and proceed |
Akash Soni | a824697 | 2023-01-03 10:37:08 +0530 | [diff] [blame] | 1388 | statusCode, statusMessage := errorCodes.GetErrorInfo(err) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1389 | vpv.FlowInstallFailure("VGC processing failure", statusCode, statusMessage) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1390 | } |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1391 | if GetApplication().GetVendorID() != Radisys { |
| 1392 | vd.GlobalDhcpFlowAdded = true |
| 1393 | } |
| 1394 | return nil |
| 1395 | } |
| 1396 | |
| 1397 | // DelDhcpFlows deletes both US & DS DHCP flows applied for this Vnet instantiated on the port |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 1398 | func (vpv *VoltPortVnet) DelDhcpFlows(cntx context.Context) { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 1399 | logger.Info(ctx, "Received Delete DHCP Flows") |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 1400 | if err := vpv.DelUsDhcpFlows(cntx); err != nil { |
Akash Soni | a824697 | 2023-01-03 10:37:08 +0530 | [diff] [blame] | 1401 | statusCode, statusMessage := errorCodes.GetErrorInfo(err) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1402 | vpv.FlowInstallFailure("VGC processing failure", statusCode, statusMessage) |
| 1403 | } |
| 1404 | |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 1405 | if err := vpv.DelDsDhcpFlows(cntx); err != nil { |
Akash Soni | a824697 | 2023-01-03 10:37:08 +0530 | [diff] [blame] | 1406 | statusCode, statusMessage := errorCodes.GetErrorInfo(err) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1407 | vpv.FlowInstallFailure("VGC processing failure", statusCode, statusMessage) |
| 1408 | } |
| 1409 | } |
| 1410 | |
| 1411 | // DelUsDhcpFlows delete the DHCP flows applied for this Vnet instantiated on the port |
| 1412 | // Write the status of the VPV to the DB once the delete is scheduled |
| 1413 | // for dispatch |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 1414 | func (vpv *VoltPortVnet) DelUsDhcpFlows(cntx context.Context) error { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 1415 | logger.Debugw(ctx, "Received Delete US DHCP Flows", log.Fields{"Port": vpv.Port}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1416 | device, err := GetApplication().GetDeviceFromPort(vpv.Port) |
| 1417 | if err != nil { |
| 1418 | return err |
| 1419 | } |
| 1420 | |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 1421 | err = vpv.delDhcp4Flows(cntx, device) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1422 | if err != nil { |
Akash Soni | a824697 | 2023-01-03 10:37:08 +0530 | [diff] [blame] | 1423 | statusCode, statusMessage := errorCodes.GetErrorInfo(err) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1424 | vpv.FlowInstallFailure("VGC processing failure", statusCode, statusMessage) |
| 1425 | } |
Akash Soni | a824697 | 2023-01-03 10:37:08 +0530 | [diff] [blame] | 1426 | |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1427 | return nil |
| 1428 | } |
| 1429 | |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 1430 | func (vpv *VoltPortVnet) delDhcp4Flows(cntx context.Context, device *VoltDevice) error { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 1431 | logger.Debugw(ctx, "Received US Delete DHCP4 Flows", log.Fields{"DeviceName": device.Name}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1432 | flows, err := vpv.BuildUsDhcpFlows() |
| 1433 | if err == nil { |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 1434 | return vpv.RemoveFlows(cntx, device, flows) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1435 | } |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 1436 | return fmt.Errorf("US DHCP Flow Delete Failed : %w", err) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1437 | } |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1438 | |
| 1439 | // DelDsDhcpFlows delete the DHCP flows applied for this Vnet instantiated on the port |
| 1440 | // Write the status of the VPV to the DB once the delete is scheduled |
| 1441 | // for dispatch |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 1442 | func (vpv *VoltPortVnet) DelDsDhcpFlows(cntx context.Context) error { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 1443 | logger.Debugw(ctx, "Received Delete DS DHCP Flows", log.Fields{"Port": vpv.Port}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1444 | device, err := GetApplication().GetDeviceFromPort(vpv.Port) |
| 1445 | if err != nil { |
| 1446 | return err |
| 1447 | } |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 1448 | err = vpv.delDsDhcp4Flows(cntx, device) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1449 | if err != nil { |
Akash Soni | a824697 | 2023-01-03 10:37:08 +0530 | [diff] [blame] | 1450 | statusCode, statusMessage := errorCodes.GetErrorInfo(err) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1451 | vpv.FlowInstallFailure("VGC processing failure", statusCode, statusMessage) |
| 1452 | } |
| 1453 | /* |
Akash Soni | a824697 | 2023-01-03 10:37:08 +0530 | [diff] [blame] | 1454 | err = vpv.delDsDhcp6Flows(device) |
| 1455 | if err != nil { |
| 1456 | statusCode, statusMessage := errorCodes.GetErrorInfo(err) |
| 1457 | vpv.FlowInstallFailure("VGC processing failure", statusCode, statusMessage) |
| 1458 | }*/ |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1459 | return nil |
| 1460 | } |
| 1461 | |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 1462 | func (vpv *VoltPortVnet) delDsDhcp4Flows(cntx context.Context, device *VoltDevice) error { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 1463 | logger.Debugw(ctx, "Received DS Delete DHCP4 Flows", log.Fields{"DeviceName": device.Name}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1464 | flows, err := vpv.BuildDsDhcpFlows() |
| 1465 | if err == nil { |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 1466 | return vpv.RemoveFlows(cntx, device, flows) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1467 | } |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 1468 | return fmt.Errorf("DS DHCP Flow Delete Failed : %w", err) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1469 | } |
| 1470 | |
| 1471 | /* |
| 1472 | func (vpv *VoltPortVnet) delDsDhcp6Flows(device *VoltDevice) error { |
| 1473 | flows, err := vpv.BuildDsDhcp6Flows() |
| 1474 | if err == nil { |
| 1475 | return vpv.RemoveFlows(device, flows) |
| 1476 | } |
| 1477 | logger.Errorw(ctx, "DS DHCP6 Flow Delete Failed", log.Fields{"Reason": err.Error()}) |
| 1478 | return err |
| 1479 | }*/ |
| 1480 | |
| 1481 | // AddUsArpFlows pushes the ARP flows to the VOLTHA via the controller |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 1482 | func (vpv *VoltPortVnet) AddUsArpFlows(cntx context.Context) error { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1483 | var vd *VoltDevice |
| 1484 | device := vpv.Device |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 1485 | logger.Debugw(ctx, "Received Add US Arp Flows", log.Fields{"DeviceName": device}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1486 | if vd = GetApplication().GetDevice(device); vd != nil { |
| 1487 | if vd.State != controller.DeviceStateUP { |
| 1488 | logger.Errorw(ctx, "Skipping US ARP Flow Push - Device state DOWN", log.Fields{"Port": vpv.Port, "SVLAN": vpv.SVlan, "CVLAN": vpv.CVlan, "UNIVlan": vpv.UniVlan, "device": device}) |
| 1489 | return nil |
| 1490 | } |
| 1491 | } else { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 1492 | err := errorCodes.ErrDeviceNotFound |
| 1493 | return fmt.Errorf("US ARP Flow Push Failed- Device not found : Port %s : SVLAN %d : CVLAN %d : UNIVlan %d : device %s : %w", vpv.Port, vpv.SVlan, vpv.CVlan, vpv.UniVlan, device, err) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1494 | } |
| 1495 | |
| 1496 | flows, err := vpv.BuildUsArpFlows() |
| 1497 | if err == nil { |
| 1498 | logger.Debugw(ctx, "Adding US ARP flows", log.Fields{"Device": device}) |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 1499 | if err1 := vpv.PushFlows(cntx, vd, flows); err1 != nil { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 1500 | return fmt.Errorf("Pushing US ARP Flow Failed : %w", err1) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1501 | } |
| 1502 | } else { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 1503 | return fmt.Errorf("US ARP Flow Add Failed : Device %s : %w", device, err) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1504 | } |
| 1505 | return nil |
| 1506 | } |
| 1507 | |
| 1508 | // DelUsArpFlows delete the ARP flows applied for this Vnet instantiated on the port |
| 1509 | // Write the status of the VPV to the DB once the delete is scheduled |
| 1510 | // for dispatch |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 1511 | func (vpv *VoltPortVnet) DelUsArpFlows(cntx context.Context) error { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 1512 | logger.Debugw(ctx, "Delete US ARP Flows", log.Fields{"Port": vpv.Port}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1513 | device, err := GetApplication().GetDeviceFromPort(vpv.Port) |
| 1514 | if err != nil { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 1515 | return fmt.Errorf("US ARP Flow Delete Failed : DeviceName %s : %w", device.Name, err) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1516 | } |
| 1517 | flows, err := vpv.BuildUsArpFlows() |
| 1518 | if err == nil { |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 1519 | return vpv.RemoveFlows(cntx, device, flows) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1520 | } |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 1521 | return fmt.Errorf("US ARP Flow Delete Failed : DeviceName %s : %w", device.Name, err) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1522 | } |
| 1523 | |
| 1524 | // AddUsPppoeFlows pushes the PPPoE flows to the VOLTHA via the controller |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 1525 | func (vpv *VoltPortVnet) AddUsPppoeFlows(cntx context.Context) error { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1526 | logger.Debugw(ctx, "Adding US PPPoE flows", log.Fields{"STAG": vpv.SVlan, "CTAG": vpv.CVlan, "Device": vpv.Device}) |
| 1527 | |
| 1528 | var vd *VoltDevice |
| 1529 | device := vpv.Device |
| 1530 | |
| 1531 | if vd = GetApplication().GetDevice(device); vd != nil { |
| 1532 | if vd.State != controller.DeviceStateUP { |
| 1533 | logger.Errorw(ctx, "Skipping US PPPoE Flow Push - Device state DOWN", log.Fields{"Port": vpv.Port, "SVLAN": vpv.SVlan, "CVLAN": vpv.CVlan, "UNIVlan": vpv.UniVlan, "device": device}) |
| 1534 | return nil |
| 1535 | } |
| 1536 | } else { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 1537 | err := errorCodes.ErrDeviceNotFound |
| 1538 | return fmt.Errorf("US PPPoE Flow Push Failed- Device not found : Port %s : SVLAN %d : CVLAN %d : UNIVlan %d : device %s : %w", vpv.Port, vpv.SVlan, vpv.CVlan, vpv.UniVlan, device, err) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1539 | } |
| 1540 | |
| 1541 | if flows, err := vpv.BuildUsPppoeFlows(); err == nil { |
| 1542 | logger.Debugw(ctx, "Adding US PPPoE flows", log.Fields{"Device": device}) |
| 1543 | |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 1544 | if err1 := vpv.PushFlows(cntx, vd, flows); err1 != nil { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 1545 | return fmt.Errorf("Pushing US PPPoE Flows Failed : %w", err1) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1546 | } |
| 1547 | } else { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 1548 | return fmt.Errorf("US PPPoE Flow Add Failed : Device %s : %w", device, err) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1549 | } |
| 1550 | return nil |
| 1551 | } |
| 1552 | |
| 1553 | // AddDsPppoeFlows to add downstream pppoe flows |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 1554 | func (vpv *VoltPortVnet) AddDsPppoeFlows(cntx context.Context) error { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1555 | logger.Debugw(ctx, "Adding DS PPPoE flows", log.Fields{"STAG": vpv.SVlan, "CTAG": vpv.CVlan, "Device": vpv.Device}) |
| 1556 | var vd *VoltDevice |
| 1557 | device := vpv.Device |
| 1558 | |
| 1559 | if vd = GetApplication().GetDevice(device); vd != nil { |
| 1560 | if vd.State != controller.DeviceStateUP { |
| 1561 | logger.Errorw(ctx, "Skipping DS PPPoE Flow Push - Device state DOWN", log.Fields{"Port": vpv.Port, "SVLAN": vpv.SVlan, "CVLAN": vpv.CVlan, "UNIVlan": vpv.UniVlan, "device": device}) |
| 1562 | return nil |
| 1563 | } |
| 1564 | } else { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 1565 | err := errorCodes.ErrDeviceNotFound |
| 1566 | return fmt.Errorf("DS PPPoE Flow Push Failed- Device not found : Port %s : SVLAN %d : CVLAN %d : UNIVlan %d : device %s : %w", vpv.Port, vpv.SVlan, vpv.CVlan, vpv.UniVlan, device, err) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1567 | } |
| 1568 | |
| 1569 | flows, err := vpv.BuildDsPppoeFlows() |
| 1570 | if err == nil { |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 1571 | if err1 := vpv.PushFlows(cntx, vd, flows); err1 != nil { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 1572 | return fmt.Errorf("Pushing DS PPPoE Flows Failed : %w", err1) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1573 | } |
| 1574 | } else { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 1575 | return fmt.Errorf("DS PPPoE Flow Add Failed : Device %s : %w", device, err) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1576 | } |
| 1577 | return nil |
| 1578 | } |
| 1579 | |
| 1580 | // DelUsPppoeFlows delete the PPPoE flows applied for this Vnet instantiated on the port |
| 1581 | // Write the status of the VPV to the DB once the delete is scheduled |
| 1582 | // for dispatch |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 1583 | func (vpv *VoltPortVnet) DelUsPppoeFlows(cntx context.Context) error { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1584 | logger.Debugw(ctx, "Deleting US PPPoE flows", log.Fields{"STAG": vpv.SVlan, "CTAG": vpv.CVlan, "Device": vpv.Device}) |
| 1585 | device, err := GetApplication().GetDeviceFromPort(vpv.Port) |
| 1586 | if err != nil { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 1587 | return fmt.Errorf("US PPPoE Flow Delete Failed : DeviceName %s : %w", device.Name, err) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1588 | } |
| 1589 | flows, err := vpv.BuildUsPppoeFlows() |
| 1590 | if err == nil { |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 1591 | return vpv.RemoveFlows(cntx, device, flows) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1592 | } |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 1593 | return fmt.Errorf("US PPPoE Flow Delete Failed : DeviceName %s : %w", device.Name, err) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1594 | } |
| 1595 | |
| 1596 | // DelDsPppoeFlows delete the PPPoE flows applied for this Vnet instantiated on the port |
| 1597 | // Write the status of the VPV to the DB once the delete is scheduled |
| 1598 | // for dispatch |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 1599 | func (vpv *VoltPortVnet) DelDsPppoeFlows(cntx context.Context) error { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1600 | logger.Debugw(ctx, "Deleting DS PPPoE flows", log.Fields{"STAG": vpv.SVlan, "CTAG": vpv.CVlan, "Device": vpv.Device}) |
| 1601 | device, err := GetApplication().GetDeviceFromPort(vpv.Port) |
| 1602 | if err != nil { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 1603 | return fmt.Errorf("DS PPPoE Flow Delete Failed : DeviceName %s : %w", device.Name, err) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1604 | } |
| 1605 | flows, err := vpv.BuildDsPppoeFlows() |
| 1606 | if err == nil { |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 1607 | return vpv.RemoveFlows(cntx, device, flows) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1608 | } |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 1609 | return fmt.Errorf("DS PPPoE Flow Delete Failed : DeviceName %s : %w", device.Name, err) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1610 | } |
| 1611 | |
| 1612 | // AddIgmpFlows function pushes the IGMP flows to the VOLTHA via the controller |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 1613 | func (vpv *VoltPortVnet) AddIgmpFlows(cntx context.Context) error { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 1614 | logger.Debugw(ctx, "Received Add Igmp Flows", log.Fields{"IgmpFlowsApplied": vpv.IgmpFlowsApplied, "VgcRebooted": vgcRebooted}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1615 | if !vpv.IgmpFlowsApplied || vgcRebooted { |
| 1616 | if vpv.MvlanProfileName == "" { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 1617 | logger.Warn(ctx, "Mvlan Profile not configured. Ignoring Igmp trap flow") |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1618 | return nil |
| 1619 | } |
| 1620 | device, err := GetApplication().GetDeviceFromPort(vpv.Port) |
| 1621 | if err != nil { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 1622 | return fmt.Errorf("Error getting device from port : Port %s : %w", vpv.Port, err) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1623 | } else if device.State != controller.DeviceStateUP { |
| 1624 | logger.Warnw(ctx, "Device state Down. Ignoring US IGMP Flow Push", log.Fields{"Port": vpv.Port, "SVLAN": vpv.SVlan, "CVLAN": vpv.CVlan, "UNIVlan": vpv.UniVlan}) |
| 1625 | return nil |
| 1626 | } |
| 1627 | flows, err := vpv.BuildIgmpFlows() |
| 1628 | if err == nil { |
| 1629 | for cookie := range flows.SubFlows { |
| 1630 | if vd := GetApplication().GetDevice(device.Name); vd != nil { |
| 1631 | cookie := strconv.FormatUint(cookie, 10) |
| 1632 | fe := &FlowEvent{ |
| 1633 | eType: EventTypeUsIgmpFlowAdded, |
| 1634 | cookie: cookie, |
| 1635 | eventData: vpv, |
| 1636 | } |
| 1637 | vd.RegisterFlowAddEvent(cookie, fe) |
| 1638 | } |
| 1639 | } |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 1640 | if err1 := cntlr.GetController().AddFlows(cntx, vpv.Port, device.Name, flows); err1 != nil { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1641 | return err1 |
| 1642 | } |
| 1643 | } else { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 1644 | return fmt.Errorf("IGMP Flow Add Failed : %w", err) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1645 | } |
| 1646 | vpv.IgmpFlowsApplied = true |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 1647 | vpv.WriteToDb(cntx) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1648 | } |
| 1649 | return nil |
| 1650 | } |
| 1651 | |
| 1652 | // DelIgmpFlows delete the IGMP flows applied for this Vnet instantiated on the port |
| 1653 | // Write the status of the VPV to the DB once the delete is scheduled |
| 1654 | // for dispatch |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 1655 | func (vpv *VoltPortVnet) DelIgmpFlows(cntx context.Context) error { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 1656 | logger.Debugw(ctx, "Received Delete Igmp Flows", log.Fields{"IgmpFlowsApplied": vpv.IgmpFlowsApplied, "VgcRebooted": vgcRebooted}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1657 | if vpv.IgmpFlowsApplied || vgcRebooted { |
| 1658 | device, err := GetApplication().GetDeviceFromPort(vpv.Port) |
| 1659 | if err != nil { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 1660 | return fmt.Errorf("Error getting device from port : Port %s : %w", vpv.Port, err) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1661 | } |
| 1662 | flows, err := vpv.BuildIgmpFlows() |
| 1663 | if err == nil { |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 1664 | if err1 := vpv.RemoveFlows(cntx, device, flows); err1 != nil { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1665 | return err1 |
| 1666 | } |
| 1667 | } else { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 1668 | return fmt.Errorf("IGMP Flow Delete Failed : %w", err) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1669 | } |
| 1670 | vpv.IgmpFlowsApplied = false |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 1671 | vpv.WriteToDb(cntx) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1672 | } |
| 1673 | return nil |
| 1674 | } |
| 1675 | |
| 1676 | // BuildUsDhcpFlows builds the US DHCP relay flows for a subscriber |
| 1677 | // The flows included by this function cover US only as the DS is |
| 1678 | // created either automatically by the VOLTHA or at the device level |
| 1679 | // earlier |
| 1680 | func (vpv *VoltPortVnet) BuildUsDhcpFlows() (*of.VoltFlow, error) { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 1681 | logger.Infow(ctx, "Building US DHCP flow", log.Fields{"Port": vpv.Port}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1682 | flow := &of.VoltFlow{} |
| 1683 | flow.SubFlows = make(map[uint64]*of.VoltSubFlow) |
| 1684 | |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1685 | subFlow := of.NewVoltSubFlow() |
| 1686 | subFlow.SetTableID(0) |
| 1687 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 1688 | if vpv.VnetType == DpuMgmtTraffic { |
Tinoj Joseph | 50d722c | 2022-12-06 22:53:22 +0530 | [diff] [blame] | 1689 | subFlow.SetMatchVlan(vpv.CVlan) |
| 1690 | subFlow.SetMatchPbit(vpv.UsPonCTagPriority) |
| 1691 | subFlow.SetPcp(vpv.UsPonSTagPriority) |
| 1692 | subFlow.SetSetVlan(vpv.SVlan) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1693 | } else { |
| 1694 | subFlow.SetMatchVlan(vpv.UniVlan) |
| 1695 | subFlow.SetSetVlan(vpv.CVlan) |
Tinoj Joseph | 50d722c | 2022-12-06 22:53:22 +0530 | [diff] [blame] | 1696 | subFlow.SetPcp(vpv.DhcpPbit) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1697 | } |
| 1698 | subFlow.SetUdpv4Match() |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1699 | subFlow.DstPort = 67 |
Tinoj Joseph | 50d722c | 2022-12-06 22:53:22 +0530 | [diff] [blame] | 1700 | subFlow.SrcPort = 68 |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1701 | uniport, err := GetApplication().GetPortID(vpv.Port) |
| 1702 | if err != nil { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 1703 | return nil, fmt.Errorf("failed to fetch uni port %s from vpv : %w", vpv.Port, err) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1704 | } |
| 1705 | subFlow.SetInPort(uniport) |
| 1706 | // PortName and PortID to be used for validation of port before flow pushing |
| 1707 | flow.PortID = uniport |
| 1708 | flow.PortName = vpv.Port |
| 1709 | subFlow.SetReportToController() |
| 1710 | |
| 1711 | // Set techprofile, meterid of first service |
| 1712 | vpv.services.Range(func(key, value interface{}) bool { |
Tinoj Joseph | 50d722c | 2022-12-06 22:53:22 +0530 | [diff] [blame] | 1713 | vs := value.(*VoltService) |
| 1714 | var writemetadata uint64 |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 1715 | if vpv.VnetType == DpuMgmtTraffic { |
Sridhar Ravindra | b8374ae | 2023-04-14 15:49:25 +0530 | [diff] [blame] | 1716 | writemetadata = uint64(vs.TechProfileID)<<32 + uint64(vs.UsMeterID) |
Tinoj Joseph | 50d722c | 2022-12-06 22:53:22 +0530 | [diff] [blame] | 1717 | } else { |
| 1718 | writemetadata = uint64(vs.TechProfileID) << 32 |
| 1719 | } |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1720 | subFlow.SetWriteMetadata(writemetadata) |
Tinoj Joseph | 50d722c | 2022-12-06 22:53:22 +0530 | [diff] [blame] | 1721 | subFlow.SetMeterID(vs.UsMeterID) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1722 | return false |
| 1723 | }) |
| 1724 | |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1725 | // metadata := uint64(uniport) |
| 1726 | // subFlow.SetWriteMetadata(metadata) |
| 1727 | allowTransparent := 0 |
| 1728 | if vpv.AllowTransparent { |
| 1729 | allowTransparent = 1 |
| 1730 | } |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 1731 | if vpv.VnetType != DpuMgmtTraffic { |
Tinoj Joseph | 50d722c | 2022-12-06 22:53:22 +0530 | [diff] [blame] | 1732 | metadata := uint64(allowTransparent)<<56 | uint64(vpv.ONTEtherTypeClassification)<<36 | uint64(vpv.VlanControl)<<32 | uint64(vpv.UniVlan)<<16 | uint64(vpv.CVlan) |
| 1733 | subFlow.SetTableMetadata(metadata) |
| 1734 | } |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1735 | //| 12-bit cvlan | 4 bits empty | <32-bits uniport>| 16-bits dhcp mask or flow mask | |
| 1736 | subFlow.Cookie = uint64(vpv.CVlan)<<52 | uint64(uniport)<<16 | of.DhcpArpFlowMask | of.UsFlowMask |
| 1737 | subFlow.Priority = of.DhcpFlowPriority |
| 1738 | |
| 1739 | flow.SubFlows[subFlow.Cookie] = subFlow |
| 1740 | logger.Infow(ctx, "Built US DHCP flow ", log.Fields{"cookie": subFlow.Cookie, "flow": flow}) |
| 1741 | return flow, nil |
| 1742 | } |
| 1743 | |
| 1744 | // BuildDsDhcpFlows to build the downstream dhcp flows |
| 1745 | func (vpv *VoltPortVnet) BuildDsDhcpFlows() (*of.VoltFlow, error) { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1746 | logger.Infow(ctx, "Building DS DHCP flow", log.Fields{"Port": vpv.Port, "ML": vpv.MacLearning, "Mac": vpv.MacAddr}) |
| 1747 | flow := &of.VoltFlow{} |
| 1748 | flow.SubFlows = make(map[uint64]*of.VoltSubFlow) |
| 1749 | subFlow := of.NewVoltSubFlow() |
| 1750 | subFlow.SetTableID(0) |
Tinoj Joseph | 50d722c | 2022-12-06 22:53:22 +0530 | [diff] [blame] | 1751 | // match on vlan only for fttb case |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 1752 | if vpv.VnetType == DpuMgmtTraffic { |
Tinoj Joseph | 50d722c | 2022-12-06 22:53:22 +0530 | [diff] [blame] | 1753 | subFlow.SetMatchVlan(vpv.SVlan) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1754 | } |
| 1755 | subFlow.SetUdpv4Match() |
| 1756 | subFlow.SrcPort = 67 |
| 1757 | subFlow.DstPort = 68 |
| 1758 | uniport, _ := GetApplication().GetPortID(vpv.Port) |
| 1759 | nni, err := GetApplication().GetNniPort(vpv.Device) |
| 1760 | if err != nil { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 1761 | return nil, fmt.Errorf("failed to fetch nni port %s from vpv : %w", nni, err) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1762 | } |
| 1763 | nniport, err := GetApplication().GetPortID(nni) |
| 1764 | if err != nil { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 1765 | return nil, fmt.Errorf("failed to fetch port id %d for nni : %w", nniport, err) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1766 | } |
| 1767 | subFlow.SetInPort(nniport) |
| 1768 | // PortName and PortID to be used for validation of port before flow pushing |
| 1769 | flow.PortID = uniport |
| 1770 | flow.PortName = vpv.Port |
| 1771 | // metadata := uint64(uniport) |
| 1772 | // subFlow.SetWriteMetadata(metadata) |
| 1773 | allowTransparent := 0 |
| 1774 | if vpv.AllowTransparent { |
| 1775 | allowTransparent = 1 |
| 1776 | } |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 1777 | if vpv.VnetType != DpuMgmtTraffic { |
Tinoj Joseph | 50d722c | 2022-12-06 22:53:22 +0530 | [diff] [blame] | 1778 | metadata := uint64(allowTransparent)<<56 | uint64(vpv.ONTEtherTypeClassification)<<36 | uint64(vpv.VlanControl)<<32 | uint64(vpv.UniVlan)<<16 | uint64(vpv.CVlan) |
| 1779 | subFlow.SetTableMetadata(metadata) |
| 1780 | subFlow.Priority = of.DhcpFlowPriority |
| 1781 | } |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1782 | subFlow.SetReportToController() |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 1783 | // | 12-bit cvlan | 4 bits empty | <32-bits uniport>| 16-bits dhcp mask or flow mask | |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1784 | subFlow.Cookie = uint64(vpv.CVlan)<<52 | uint64(uniport)<<16 | of.DhcpArpFlowMask | of.DsFlowMask |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1785 | |
| 1786 | flow.SubFlows[subFlow.Cookie] = subFlow |
| 1787 | logger.Infow(ctx, "Built DS DHCP flow ", log.Fields{"cookie": subFlow.Cookie, "Flow": flow}) |
| 1788 | |
| 1789 | return flow, nil |
| 1790 | } |
| 1791 | |
| 1792 | // BuildUsDhcp6Flows to trap the DHCPv6 packets to be reported to the |
| 1793 | // application. |
| 1794 | func (vpv *VoltPortVnet) BuildUsDhcp6Flows() (*of.VoltFlow, error) { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 1795 | logger.Infow(ctx, "Building US DHCPv6 flow", log.Fields{"Port": vpv.Port}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1796 | flow := &of.VoltFlow{} |
| 1797 | flow.SubFlows = make(map[uint64]*of.VoltSubFlow) |
| 1798 | |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1799 | subFlow := of.NewVoltSubFlow() |
| 1800 | subFlow.SetTableID(0) |
| 1801 | |
| 1802 | subFlow.SetMatchVlan(vpv.UniVlan) |
| 1803 | subFlow.SetSetVlan(vpv.CVlan) |
| 1804 | subFlow.SetUdpv6Match() |
| 1805 | subFlow.SrcPort = 546 |
| 1806 | subFlow.DstPort = 547 |
| 1807 | uniport, err := GetApplication().GetPortID(vpv.Port) |
| 1808 | if err != nil { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 1809 | return nil, fmt.Errorf("failed to fetch uni port %d from vpv : %w", uniport, err) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1810 | } |
| 1811 | // Set techprofile, meterid of first service |
| 1812 | vpv.services.Range(func(key, value interface{}) bool { |
| 1813 | svc := value.(*VoltService) |
| 1814 | writemetadata := uint64(svc.TechProfileID) << 32 |
| 1815 | subFlow.SetWriteMetadata(writemetadata) |
| 1816 | subFlow.SetMeterID(svc.UsMeterID) |
| 1817 | return false |
| 1818 | }) |
| 1819 | subFlow.SetInPort(uniport) |
| 1820 | // PortName and PortID to be used for validation of port before flow pushing |
| 1821 | flow.PortID = uniport |
| 1822 | flow.PortName = vpv.Port |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 1823 | // subFlow.SetMeterId(vpv.UsDhcpMeterId) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1824 | // metadata := uint64(uniport) |
| 1825 | // subFlow.SetWriteMetadata(metadata) |
| 1826 | allowTransparent := 0 |
| 1827 | if vpv.AllowTransparent { |
| 1828 | allowTransparent = 1 |
| 1829 | } |
| 1830 | metadata := uint64(allowTransparent)<<56 | uint64(vpv.ONTEtherTypeClassification)<<36 | uint64(vpv.VlanControl)<<32 | uint64(vpv.UniVlan)<<16 | uint64(vpv.CVlan) |
| 1831 | subFlow.SetTableMetadata(metadata) |
| 1832 | subFlow.SetReportToController() |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 1833 | // | 12-bit cvlan | 4 bits empty | <32-bits uniport>| 16-bits dhcp mask or flow mask | |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1834 | subFlow.Cookie = uint64(vpv.CVlan)<<52 | uint64(uniport)<<16 | of.Dhcpv6FlowMask | of.UsFlowMask |
| 1835 | subFlow.Priority = of.DhcpFlowPriority |
| 1836 | |
| 1837 | flow.SubFlows[subFlow.Cookie] = subFlow |
| 1838 | logger.Infow(ctx, "Built US DHCPv6 flow", log.Fields{"cookie": subFlow.Cookie, "flow": flow}) |
| 1839 | return flow, nil |
| 1840 | } |
| 1841 | |
| 1842 | // BuildDsDhcp6Flows to trap the DHCPv6 packets to be reported to the |
| 1843 | // application. |
| 1844 | func (vpv *VoltPortVnet) BuildDsDhcp6Flows() (*of.VoltFlow, error) { |
| 1845 | logger.Infow(ctx, "Building DS DHCPv6 flow", log.Fields{"Port": vpv.Port, "ML": vpv.MacLearning, "Mac": vpv.MacAddr}) |
| 1846 | |
| 1847 | flow := &of.VoltFlow{} |
| 1848 | flow.SubFlows = make(map[uint64]*of.VoltSubFlow) |
| 1849 | subFlow := of.NewVoltSubFlow() |
| 1850 | subFlow.SetTableID(0) |
| 1851 | |
| 1852 | vpv.setDsMatchVlan(subFlow) |
| 1853 | subFlow.SetUdpv6Match() |
| 1854 | subFlow.SrcPort = 547 |
| 1855 | subFlow.DstPort = 547 |
| 1856 | uniport, _ := GetApplication().GetPortID(vpv.Port) |
| 1857 | nni, err := GetApplication().GetNniPort(vpv.Device) |
| 1858 | if err != nil { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 1859 | logger.Errorw(ctx, "Failed to fetch nni port from vpv", log.Fields{"error": err, "device": vpv.Device}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1860 | return nil, err |
| 1861 | } |
| 1862 | nniport, err := GetApplication().GetPortID(nni) |
| 1863 | if err != nil { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 1864 | logger.Errorw(ctx, "Failed to fetch port ID for nni", log.Fields{"error": err, "nni": nni}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1865 | return nil, err |
| 1866 | } |
| 1867 | subFlow.SetInPort(nniport) |
| 1868 | // PortName and PortID to be used for validation of port before flow pushing |
| 1869 | flow.PortID = uniport |
| 1870 | flow.PortName = vpv.Port |
| 1871 | // metadata := uint64(uniport) |
| 1872 | // subFlow.SetWriteMetadata(metadata) |
| 1873 | allowTransparent := 0 |
| 1874 | if vpv.AllowTransparent { |
| 1875 | allowTransparent = 1 |
| 1876 | } |
| 1877 | metadata := uint64(allowTransparent)<<56 | uint64(vpv.ONTEtherTypeClassification)<<36 | uint64(vpv.VlanControl)<<32 | uint64(vpv.UniVlan)<<16 | uint64(vpv.CVlan) |
| 1878 | subFlow.SetTableMetadata(metadata) |
| 1879 | subFlow.SetReportToController() |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 1880 | // | 12-bit cvlan | 4 bits empty | <32-bits uniport>| 16-bits dhcp mask or flow mask | |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1881 | subFlow.Cookie = uint64(vpv.CVlan)<<52 | uint64(uniport)<<16 | of.Dhcpv6FlowMask | of.DsFlowMask |
| 1882 | subFlow.Priority = of.DhcpFlowPriority |
| 1883 | |
| 1884 | flow.SubFlows[subFlow.Cookie] = subFlow |
| 1885 | logger.Infow(ctx, "Built DS DHCPv6 flow", log.Fields{"cookie": subFlow.Cookie, "flow": flow}) |
| 1886 | return flow, nil |
| 1887 | } |
| 1888 | |
| 1889 | // BuildUsArpFlows builds the US ARP relay flows for a subscriber |
| 1890 | // The flows included by this function cover US only as the DS is |
| 1891 | // created either automatically by the VOLTHA or at the device level |
| 1892 | // earlier |
| 1893 | func (vpv *VoltPortVnet) BuildUsArpFlows() (*of.VoltFlow, error) { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 1894 | logger.Infow(ctx, "Building US ARP flow", log.Fields{"Port": vpv.Port}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1895 | flow := &of.VoltFlow{} |
| 1896 | flow.SubFlows = make(map[uint64]*of.VoltSubFlow) |
| 1897 | |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1898 | subFlow := of.NewVoltSubFlow() |
| 1899 | subFlow.SetTableID(0) |
| 1900 | |
| 1901 | if vpv.MacLearning == MacLearningNone && NonZeroMacAddress(vpv.MacAddr) { |
| 1902 | subFlow.SetMatchSrcMac(vpv.MacAddr) |
| 1903 | } |
| 1904 | |
| 1905 | subFlow.SetMatchDstMac(BroadcastMAC) |
| 1906 | if err := vpv.setUsMatchVlan(subFlow); err != nil { |
| 1907 | return nil, err |
| 1908 | } |
| 1909 | subFlow.SetArpMatch() |
| 1910 | uniport, err := GetApplication().GetPortID(vpv.Port) |
| 1911 | if err != nil { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 1912 | return nil, fmt.Errorf("failed to fetch uni port %d from vpv : %w", uniport, err) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1913 | } |
| 1914 | subFlow.SetInPort(uniport) |
| 1915 | // PortName and PortID to be used for validation of port before flow pushing |
| 1916 | flow.PortID = uniport |
| 1917 | flow.PortName = vpv.Port |
| 1918 | subFlow.SetReportToController() |
| 1919 | allowTransparent := 0 |
| 1920 | if vpv.AllowTransparent { |
| 1921 | allowTransparent = 1 |
| 1922 | } |
| 1923 | metadata := uint64(uniport) |
| 1924 | subFlow.SetWriteMetadata(metadata) |
| 1925 | metadata = uint64(allowTransparent)<<56 | uint64(vpv.ONTEtherTypeClassification)<<36 | uint64(vpv.VlanControl)<<32 | uint64(vpv.UniVlan)<<16 | uint64(vpv.CVlan) |
| 1926 | subFlow.SetTableMetadata(metadata) |
| 1927 | subFlow.Cookie = uint64(vpv.CVlan)<<52 | uint64(uniport)<<32 | of.DhcpArpFlowMask | of.UsFlowMask |
| 1928 | subFlow.Priority = of.ArpFlowPriority |
| 1929 | |
| 1930 | flow.SubFlows[subFlow.Cookie] = subFlow |
| 1931 | logger.Infow(ctx, "Built US ARP flow ", log.Fields{"cookie": subFlow.Cookie, "flow": flow}) |
| 1932 | return flow, nil |
| 1933 | } |
| 1934 | |
| 1935 | // setUsMatchVlan to set upstream match vlan |
| 1936 | func (vpv *VoltPortVnet) setUsMatchVlan(flow *of.VoltSubFlow) error { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 1937 | logger.Debugw(ctx, "Set Us Match Vlan", log.Fields{"Value": vpv.VlanControl}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1938 | switch vpv.VlanControl { |
| 1939 | case None: |
| 1940 | flow.SetMatchVlan(vpv.SVlan) |
| 1941 | case ONUCVlanOLTSVlan: |
| 1942 | flow.SetMatchVlan(vpv.CVlan) |
| 1943 | case OLTCVlanOLTSVlan: |
| 1944 | flow.SetMatchVlan(vpv.UniVlan) |
| 1945 | //flow.SetSetVlan(vpv.CVlan) |
| 1946 | case ONUCVlan: |
| 1947 | flow.SetMatchVlan(vpv.SVlan) |
| 1948 | case OLTSVlan: |
| 1949 | flow.SetMatchVlan(vpv.UniVlan) |
| 1950 | //flow.SetSetVlan(vpv.SVlan) |
| 1951 | default: |
| 1952 | logger.Errorw(ctx, "Invalid Vlan Control Option", log.Fields{"Value": vpv.VlanControl}) |
| 1953 | return errorCodes.ErrInvalidParamInRequest |
| 1954 | } |
| 1955 | return nil |
| 1956 | } |
| 1957 | |
| 1958 | // BuildUsPppoeFlows to build upstream pppoe flows |
| 1959 | func (vpv *VoltPortVnet) BuildUsPppoeFlows() (*of.VoltFlow, error) { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 1960 | logger.Infow(ctx, "Building US PPPoE flow", log.Fields{"Port": vpv.Port}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1961 | flow := &of.VoltFlow{} |
| 1962 | flow.SubFlows = make(map[uint64]*of.VoltSubFlow) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1963 | subFlow := of.NewVoltSubFlow() |
| 1964 | subFlow.SetTableID(0) |
| 1965 | |
| 1966 | if vpv.MacLearning == MacLearningNone && NonZeroMacAddress(vpv.MacAddr) { |
| 1967 | subFlow.SetMatchSrcMac(vpv.MacAddr) |
| 1968 | } |
| 1969 | |
| 1970 | if err := vpv.setUsMatchVlan(subFlow); err != nil { |
| 1971 | return nil, err |
| 1972 | } |
| 1973 | subFlow.SetPppoeDiscoveryMatch() |
| 1974 | uniport, err := GetApplication().GetPortID(vpv.Port) |
| 1975 | if err != nil { |
| 1976 | return nil, err |
| 1977 | } |
| 1978 | subFlow.SetInPort(uniport) |
| 1979 | subFlow.SetReportToController() |
| 1980 | // PortName and PortID to be used for validation of port before flow pushing |
| 1981 | flow.PortID = uniport |
| 1982 | flow.PortName = vpv.Port |
| 1983 | |
| 1984 | allowTransparent := 0 |
| 1985 | if vpv.AllowTransparent { |
| 1986 | allowTransparent = 1 |
| 1987 | } |
| 1988 | metadata := uint64(uniport) |
| 1989 | subFlow.SetWriteMetadata(metadata) |
| 1990 | |
| 1991 | metadata = uint64(allowTransparent)<<56 | uint64(vpv.ONTEtherTypeClassification)<<36 | uint64(vpv.VlanControl)<<32 | uint64(vpv.UniVlan)<<16 | uint64(vpv.CVlan) |
| 1992 | subFlow.SetTableMetadata(metadata) |
| 1993 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 1994 | // | 12-bit cvlan | 4 bits empty | <32-bits uniport>| 16-bits pppoe mask or flow mask | |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 1995 | subFlow.Cookie = uint64(vpv.CVlan)<<52 | uint64(uniport)<<16 | of.PppoeFlowMask | of.UsFlowMask |
| 1996 | subFlow.Priority = of.PppoeFlowPriority |
| 1997 | |
| 1998 | flow.SubFlows[subFlow.Cookie] = subFlow |
| 1999 | logger.Infow(ctx, "Built US PPPoE flow ", log.Fields{"cookie": subFlow.Cookie, "flow": flow}) |
| 2000 | return flow, nil |
| 2001 | } |
| 2002 | |
| 2003 | // BuildDsPppoeFlows to build downstream pppoe flows |
| 2004 | func (vpv *VoltPortVnet) BuildDsPppoeFlows() (*of.VoltFlow, error) { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 2005 | logger.Infow(ctx, "Building DS PPPoE flow", log.Fields{"Port": vpv.Port, "ML": vpv.MacLearning, "Mac": vpv.MacAddr}) |
| 2006 | flow := &of.VoltFlow{} |
| 2007 | flow.SubFlows = make(map[uint64]*of.VoltSubFlow) |
| 2008 | subFlow := of.NewVoltSubFlow() |
| 2009 | subFlow.SetTableID(0) |
| 2010 | |
| 2011 | vpv.setDsMatchVlan(subFlow) |
| 2012 | subFlow.SetPppoeDiscoveryMatch() |
| 2013 | |
| 2014 | if NonZeroMacAddress(vpv.MacAddr) { |
| 2015 | subFlow.SetMatchDstMac(vpv.MacAddr) |
| 2016 | } |
| 2017 | |
| 2018 | uniport, _ := GetApplication().GetPortID(vpv.Port) |
| 2019 | nni, err := GetApplication().GetNniPort(vpv.Device) |
| 2020 | if err != nil { |
| 2021 | return nil, err |
| 2022 | } |
| 2023 | nniport, err := GetApplication().GetPortID(nni) |
| 2024 | if err != nil { |
| 2025 | return nil, err |
| 2026 | } |
| 2027 | subFlow.SetInPort(nniport) |
| 2028 | // PortName and PortID to be used for validation of port before flow pushing |
| 2029 | flow.PortID = uniport |
| 2030 | flow.PortName = vpv.Port |
| 2031 | metadata := uint64(uniport) |
| 2032 | subFlow.SetWriteMetadata(metadata) |
| 2033 | allowTransparent := 0 |
| 2034 | if vpv.AllowTransparent { |
| 2035 | allowTransparent = 1 |
| 2036 | } |
| 2037 | metadata = uint64(allowTransparent)<<56 | uint64(vpv.ONTEtherTypeClassification)<<36 | uint64(vpv.VlanControl)<<32 | uint64(vpv.UniVlan)<<16 | uint64(vpv.CVlan) |
| 2038 | subFlow.SetTableMetadata(metadata) |
| 2039 | subFlow.SetReportToController() |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 2040 | // | 12-bit cvlan | 4 bits empty | <32-bits uniport>| 16-bits dhcp mask or flow mask | |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 2041 | subFlow.Cookie = uint64(vpv.CVlan)<<52 | uint64(uniport)<<16 | of.PppoeFlowMask | of.DsFlowMask |
| 2042 | subFlow.Priority = of.PppoeFlowPriority |
| 2043 | |
| 2044 | flow.SubFlows[subFlow.Cookie] = subFlow |
| 2045 | logger.Infow(ctx, "Built DS DHCP flow ", log.Fields{"cookie": subFlow.Cookie, "Flow": flow}) |
| 2046 | return flow, nil |
| 2047 | } |
| 2048 | |
| 2049 | // setDsMatchVlan to set downstream match vlan |
| 2050 | func (vpv *VoltPortVnet) setDsMatchVlan(flow *of.VoltSubFlow) { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 2051 | logger.Debugw(ctx, "Set Ds Match Vlan", log.Fields{"Vlan": vpv.VlanControl}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 2052 | switch vpv.VlanControl { |
| 2053 | case None: |
| 2054 | flow.SetMatchVlan(vpv.SVlan) |
| 2055 | case ONUCVlanOLTSVlan, |
| 2056 | OLTCVlanOLTSVlan, |
| 2057 | ONUCVlan, |
| 2058 | OLTSVlan: |
| 2059 | flow.SetMatchVlan(vpv.SVlan) |
| 2060 | default: |
| 2061 | logger.Errorw(ctx, "Invalid Vlan Control Option", log.Fields{"Value": vpv.VlanControl}) |
| 2062 | } |
| 2063 | } |
| 2064 | |
| 2065 | // BuildIgmpFlows builds the US IGMP flows for a subscriber. IGMP requires flows only |
| 2066 | // in the US direction. |
| 2067 | func (vpv *VoltPortVnet) BuildIgmpFlows() (*of.VoltFlow, error) { |
| 2068 | logger.Infow(ctx, "Building US IGMP Flow", log.Fields{"Port": vpv.Port}) |
| 2069 | mvp := GetApplication().GetMvlanProfileByName(vpv.MvlanProfileName) |
| 2070 | if mvp == nil { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 2071 | return nil, errors.New("mvlan profile configured not found") |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 2072 | } |
| 2073 | mvlan := mvp.GetUsMatchVlan() |
| 2074 | flow := &of.VoltFlow{} |
| 2075 | flow.SubFlows = make(map[uint64]*of.VoltSubFlow) |
| 2076 | subFlow := of.NewVoltSubFlow() |
| 2077 | subFlow.SetTableID(0) |
| 2078 | |
Akash Soni | a824697 | 2023-01-03 10:37:08 +0530 | [diff] [blame] | 2079 | subFlow.SetMatchVlan(vpv.UniVlan) |
| 2080 | subFlow.SetSetVlan(vpv.CVlan) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 2081 | |
| 2082 | uniport, err := GetApplication().GetPortID(vpv.Port) |
| 2083 | if err != nil { |
| 2084 | return nil, err |
| 2085 | } |
| 2086 | subFlow.SetInPort(uniport) |
| 2087 | // PortName and PortID to be used for validation of port before flow pushing |
| 2088 | flow.PortID = uniport |
| 2089 | flow.PortName = vpv.Port |
| 2090 | |
| 2091 | if vpv.MacLearning == MacLearningNone && NonZeroMacAddress(vpv.MacAddr) { |
| 2092 | subFlow.SetMatchSrcMac(vpv.MacAddr) |
| 2093 | } |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 2094 | logger.Debugw(ctx, "Mvlan", log.Fields{"mvlan": mvlan}) |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 2095 | // metadata := uint64(mvlan) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 2096 | |
| 2097 | if vpv.McastService { |
| 2098 | metadata := uint64(vpv.McastUsMeterID) |
| 2099 | metadata = metadata | uint64(vpv.McastTechProfileID)<<32 |
| 2100 | subFlow.SetMatchPbit(vpv.McastPbit) |
| 2101 | subFlow.SetMeterID(vpv.McastUsMeterID) |
| 2102 | subFlow.SetWriteMetadata(metadata) |
| 2103 | } else { |
| 2104 | // Set techprofile, meterid of first service |
| 2105 | vpv.services.Range(func(key, value interface{}) bool { |
| 2106 | svc := value.(*VoltService) |
| 2107 | writemetadata := uint64(svc.TechProfileID) << 32 |
| 2108 | subFlow.SetWriteMetadata(writemetadata) |
| 2109 | subFlow.SetMeterID(svc.UsMeterID) |
| 2110 | return false |
| 2111 | }) |
| 2112 | } |
| 2113 | |
| 2114 | allowTransparent := 0 |
| 2115 | if vpv.AllowTransparent { |
| 2116 | allowTransparent = 1 |
| 2117 | } |
| 2118 | metadata := uint64(allowTransparent)<<56 | uint64(vpv.SchedID)<<40 | uint64(vpv.ONTEtherTypeClassification)<<36 | uint64(vpv.VlanControl)<<32 | uint64(vpv.UniVlan)<<16 | uint64(vpv.CVlan) |
| 2119 | subFlow.SetTableMetadata(metadata) |
| 2120 | subFlow.SetIgmpMatch() |
| 2121 | subFlow.SetReportToController() |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 2122 | // | 16 bits empty | <32-bits uniport>| 16-bits igmp mask or flow mask | |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 2123 | subFlow.Cookie = uint64(uniport)<<16 | of.IgmpFlowMask | of.UsFlowMask |
| 2124 | subFlow.Priority = of.IgmpFlowPriority |
| 2125 | |
| 2126 | flow.SubFlows[subFlow.Cookie] = subFlow |
| 2127 | logger.Infow(ctx, "Built US IGMP flow ", log.Fields{"cookie": subFlow.Cookie, "flow": flow}) |
| 2128 | return flow, nil |
| 2129 | } |
| 2130 | |
| 2131 | // WriteToDb for writing to database |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 2132 | func (vpv *VoltPortVnet) WriteToDb(cntx context.Context) { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 2133 | if vpv.DeleteInProgress { |
| 2134 | logger.Warnw(ctx, "Skipping Redis Update for VPV, VPV delete in progress", log.Fields{"Vnet": vpv.VnetName, "Port": vpv.Port}) |
| 2135 | return |
| 2136 | } |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 2137 | vpv.ForceWriteToDb(cntx) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 2138 | } |
| 2139 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 2140 | // ForceWriteToDb force commit a VPV to the DB |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 2141 | func (vpv *VoltPortVnet) ForceWriteToDb(cntx context.Context) { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 2142 | vpv.PendingFlowLock.RLock() |
| 2143 | defer vpv.PendingFlowLock.RUnlock() |
| 2144 | vpv.Version = database.PresentVersionMap[database.VpvPath] |
| 2145 | if b, err := json.Marshal(vpv); err == nil { |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 2146 | if err := db.PutVpv(cntx, vpv.Port, uint16(vpv.SVlan), uint16(vpv.CVlan), uint16(vpv.UniVlan), string(b)); err != nil { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 2147 | logger.Warnw(ctx, "VPV write to DB failed", log.Fields{"port": vpv.Port, "SVlan": vpv.SVlan, "CVlan": vpv.CVlan, |
| 2148 | "UniVlan": vpv.UniVlan, "Error": err}) |
| 2149 | } |
| 2150 | } |
| 2151 | } |
| 2152 | |
| 2153 | // DelFromDb for deleting from database |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 2154 | func (vpv *VoltPortVnet) DelFromDb(cntx context.Context) { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 2155 | logger.Debugw(ctx, "Deleting VPV from DB", log.Fields{"Port": vpv.Port, "SVLAN": vpv.SVlan, "CVLAN": vpv.CVlan}) |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 2156 | _ = db.DelVpv(cntx, vpv.Port, uint16(vpv.SVlan), uint16(vpv.CVlan), uint16(vpv.UniVlan)) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 2157 | } |
| 2158 | |
| 2159 | // ClearAllServiceFlags to clear all service flags |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 2160 | func (vpv *VoltPortVnet) ClearAllServiceFlags(cntx context.Context) { |
Sridhar Ravindra | 03aa0bf | 2023-09-12 17:46:40 +0530 | [diff] [blame] | 2161 | vpv.RangeOnServices(cntx, ClearFlagsInService, false) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 2162 | } |
| 2163 | |
| 2164 | // ClearAllVpvFlags to clear all vpv flags |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 2165 | func (vpv *VoltPortVnet) ClearAllVpvFlags(cntx context.Context) { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 2166 | logger.Debugw(ctx, "Clear All Vpv Flags", log.Fields{"Port": vpv.Port, "Device": vpv.Device}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 2167 | vpv.PendingFlowLock.Lock() |
| 2168 | vpv.FlowsApplied = false |
| 2169 | vpv.IgmpFlowsApplied = false |
| 2170 | vpv.PendingDeleteFlow = make(map[string]bool) |
| 2171 | vpv.PendingFlowLock.Unlock() |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 2172 | vpv.WriteToDb(cntx) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 2173 | logger.Debugw(ctx, "Cleared Flow Flags for VPV", |
| 2174 | log.Fields{"device": vpv.Device, "port": vpv.Port, |
| 2175 | "svlan": vpv.SVlan, "cvlan": vpv.CVlan, "univlan": vpv.UniVlan}) |
| 2176 | } |
| 2177 | |
| 2178 | // CreateVpvFromString to create vpv from string |
| 2179 | func (va *VoltApplication) CreateVpvFromString(b []byte, hash string) { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 2180 | logger.Info(ctx, "Create Vpv From String") |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 2181 | var vpv VoltPortVnet |
| 2182 | if err := json.Unmarshal(b, &vpv); err == nil { |
| 2183 | vnetsByPortsSliceIntf, ok := va.VnetsByPort.Load(vpv.Port) |
| 2184 | if !ok { |
| 2185 | va.VnetsByPort.Store(vpv.Port, []*VoltPortVnet{}) |
| 2186 | vnetsByPortsSliceIntf = []*VoltPortVnet{} |
| 2187 | } |
| 2188 | vpv.servicesCount = atomic.NewUint64(0) |
| 2189 | vnetsByPortsSlice := vnetsByPortsSliceIntf.([]*VoltPortVnet) |
| 2190 | vnetsByPortsSlice = append(vnetsByPortsSlice, &vpv) |
| 2191 | va.VnetsByPort.Store(vpv.Port, vnetsByPortsSlice) |
| 2192 | va.UpdateMacInPortMap(vpv.MacAddr, vpv.Port) |
| 2193 | if vnet := va.GetVnetByName(vpv.VnetName); vnet != nil { |
| 2194 | vnet.associatePortToVnet(vpv.Port) |
| 2195 | } |
| 2196 | |
| 2197 | if vpv.DeleteInProgress { |
| 2198 | va.VoltPortVnetsToDelete[&vpv] = true |
| 2199 | logger.Warnw(ctx, "VPV (restored) to be deleted", log.Fields{"Port": vpv.Port, "Vnet": vpv.VnetName}) |
| 2200 | } |
| 2201 | logger.Debugw(ctx, "Added VPV from string", log.Fields{"port": vpv.Port, "svlan": vpv.SVlan, "cvlan": vpv.CVlan, "univlan": vpv.UniVlan}) |
| 2202 | } |
| 2203 | } |
| 2204 | |
| 2205 | // RestoreVpvsFromDb to restore vpvs from database |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 2206 | func (va *VoltApplication) RestoreVpvsFromDb(cntx context.Context) { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 2207 | logger.Info(ctx, "Restore Vpvs From Db") |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 2208 | // VNETS must be learnt first |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 2209 | vpvs, _ := db.GetVpvs(cntx) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 2210 | for hash, vpv := range vpvs { |
| 2211 | b, ok := vpv.Value.([]byte) |
| 2212 | if !ok { |
| 2213 | logger.Warn(ctx, "The value type is not []byte") |
| 2214 | continue |
| 2215 | } |
| 2216 | va.CreateVpvFromString(b, hash) |
| 2217 | } |
| 2218 | } |
| 2219 | |
| 2220 | // GetVnetByPort : VNET related functionality of VOLT Application here on. |
| 2221 | // Get the VNET from a port. The port identity is passed as device and port identities in string. |
| 2222 | // The identity of the VNET is the SVLAN and the CVLAN. Only if the both match the VLAN |
| 2223 | // is assumed to have matched. TODO: 1:1 should be treated differently and needs to be addressed |
| 2224 | func (va *VoltApplication) GetVnetByPort(port string, svlan of.VlanType, cvlan of.VlanType, univlan of.VlanType) *VoltPortVnet { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 2225 | logger.Debugw(ctx, "Get Vnet By Port", log.Fields{"port": port, "svlan": svlan, "cvlan": cvlan, "univlan": univlan}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 2226 | if _, ok := va.VnetsByPort.Load(port); !ok { |
| 2227 | return nil |
| 2228 | } |
| 2229 | vpvs, _ := va.VnetsByPort.Load(port) |
| 2230 | for _, vpv := range vpvs.([]*VoltPortVnet) { |
| 2231 | if vpv.MatchesVlans(svlan, cvlan, univlan) { |
| 2232 | return vpv |
| 2233 | } |
| 2234 | } |
| 2235 | return nil |
| 2236 | } |
| 2237 | |
| 2238 | // AddVnetToPort to add vnet to port |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 2239 | func (va *VoltApplication) AddVnetToPort(cntx context.Context, port string, vvnet *VoltVnet, vs *VoltService) *VoltPortVnet { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 2240 | // The VNET is not on the port and is to be added |
| 2241 | logger.Debugw(ctx, "Adding VNET to Port", log.Fields{"Port": port, "VNET": vvnet.Name}) |
| 2242 | vpv := NewVoltPortVnet(vvnet) |
| 2243 | vpv.MacLearning = vvnet.MacLearning |
| 2244 | vpv.Port = port |
| 2245 | vvnet.associatePortToVnet(port) |
| 2246 | if _, ok := va.VnetsByPort.Load(port); !ok { |
| 2247 | va.VnetsByPort.Store(port, []*VoltPortVnet{}) |
| 2248 | } |
| 2249 | vpvsIntf, _ := va.VnetsByPort.Load(port) |
| 2250 | vpvs := vpvsIntf.([]*VoltPortVnet) |
| 2251 | vpvs = append(vpvs, vpv) |
| 2252 | va.VnetsByPort.Store(port, vpvs) |
| 2253 | va.UpdateMacInPortMap(vpv.MacAddr, vpv.Port) |
| 2254 | |
| 2255 | vpv.VpvLock.Lock() |
| 2256 | defer vpv.VpvLock.Unlock() |
| 2257 | |
| 2258 | // Add the service that is causing the VNET to be added to the port |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 2259 | vpv.AddSvc(cntx, vs) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 2260 | |
Tinoj Joseph | ec742f6 | 2022-09-29 19:11:10 +0530 | [diff] [blame] | 2261 | if !vs.IsActivated { |
| 2262 | logger.Warn(ctx, "Not Checking port state: Service Not activated") |
| 2263 | // Process the PORT UP if the port is already up |
| 2264 | d, err := va.GetDeviceFromPort(port) |
| 2265 | if err == nil { |
| 2266 | vpv.setDevice(d.Name) |
| 2267 | } |
| 2268 | vpv.WriteToDb(cntx) |
| 2269 | return vpv |
| 2270 | } |
| 2271 | |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 2272 | // Process the PORT UP if the port is already up |
| 2273 | d, err := va.GetDeviceFromPort(port) |
| 2274 | if err == nil { |
| 2275 | vpv.setDevice(d.Name) |
| 2276 | p := d.GetPort(port) |
| 2277 | if p != nil { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 2278 | logger.Debugw(ctx, "Checking UNI port state", log.Fields{"State": p.State}) |
Akash Soni | 024eb8e | 2023-04-28 16:25:09 +0530 | [diff] [blame] | 2279 | if d.State == controller.DeviceStateUP && p.State == PortStateUp { |
| 2280 | vpv.PortUpInd(cntx, d, port) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 2281 | } |
| 2282 | } |
| 2283 | } |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 2284 | vpv.WriteToDb(cntx) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 2285 | return vpv |
| 2286 | } |
| 2287 | |
| 2288 | // DelVnetFromPort for deleting vnet from port |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 2289 | func (va *VoltApplication) DelVnetFromPort(cntx context.Context, port string, vpv *VoltPortVnet) { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 2290 | logger.Debugw(ctx, "Delete Vnet From Port", log.Fields{"Port": port, "VNET": vpv.Device}) |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 2291 | // Delete DHCP Session |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 2292 | delDhcpSessions(vpv.LearntMacAddr, vpv.SVlan, vpv.CVlan, vpv.DHCPv6DUID) |
| 2293 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 2294 | // Delete PPPoE session |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 2295 | delPppoeIaSessions(vpv.LearntMacAddr, vpv.SVlan, vpv.CVlan) |
| 2296 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 2297 | // Delete Mac from MacPortMap |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 2298 | va.DeleteMacInPortMap(vpv.MacAddr) |
| 2299 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 2300 | // Delete VPV |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 2301 | vpvsIntf, ok := va.VnetsByPort.Load(port) |
| 2302 | if !ok { |
| 2303 | return |
| 2304 | } |
| 2305 | vpvs := vpvsIntf.([]*VoltPortVnet) |
| 2306 | for i, lvpv := range vpvs { |
vinokuma | 04dc9f8 | 2023-07-31 15:47:49 +0530 | [diff] [blame] | 2307 | if reflect.DeepEqual(lvpv, vpv) { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 2308 | logger.Debugw(ctx, "Deleting VPV from port", log.Fields{"Port": vpv.Port, "SVLAN": vpv.SVlan, "CVLAN": vpv.CVlan, |
| 2309 | "UNIVLAN": vpv.UniVlan}) |
| 2310 | |
| 2311 | vpvs = append(vpvs[0:i], vpvs[i+1:]...) |
| 2312 | |
| 2313 | vpv.DeleteInProgress = true |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 2314 | vpv.ForceWriteToDb(cntx) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 2315 | |
| 2316 | va.VnetsByPort.Store(port, vpvs) |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 2317 | vpv.DelTrapFlows(cntx) |
Sridhar Ravindra | 03aa0bf | 2023-09-12 17:46:40 +0530 | [diff] [blame] | 2318 | vpv.DelHsiaFlows(cntx, false) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 2319 | va.DisassociateVpvsFromDevice(vpv.Device, vpv) |
| 2320 | vpv.PendingFlowLock.RLock() |
| 2321 | if len(vpv.PendingDeleteFlow) == 0 { |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 2322 | vpv.DelFromDb(cntx) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 2323 | } |
| 2324 | if vnet := va.GetVnetByName(vpv.VnetName); vnet != nil { |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 2325 | vnet.disassociatePortFromVnet(cntx, vpv.Device, vpv.Port) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 2326 | } |
| 2327 | vpv.PendingFlowLock.RUnlock() |
| 2328 | return |
| 2329 | } |
| 2330 | } |
| 2331 | } |
| 2332 | |
| 2333 | // RestoreVnetsFromDb to restore vnet from port |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 2334 | func (va *VoltApplication) RestoreVnetsFromDb(cntx context.Context) { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 2335 | logger.Info(ctx, "Restore Vnets From Db") |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 2336 | // VNETS must be learnt first |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 2337 | vnets, _ := db.GetVnets(cntx) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 2338 | for _, net := range vnets { |
| 2339 | b, ok := net.Value.([]byte) |
| 2340 | if !ok { |
| 2341 | logger.Warn(ctx, "The value type is not []byte") |
| 2342 | continue |
| 2343 | } |
| 2344 | var vnet VoltVnet |
| 2345 | err := json.Unmarshal(b, &vnet) |
| 2346 | if err != nil { |
| 2347 | logger.Warn(ctx, "Unmarshal of VNET failed") |
| 2348 | continue |
| 2349 | } |
| 2350 | logger.Debugw(ctx, "Retrieved VNET", log.Fields{"VNET": vnet.VnetConfig}) |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 2351 | if err := va.AddVnet(cntx, vnet.VnetConfig, &vnet.VnetOper); err != nil { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 2352 | logger.Warnw(ctx, "Add Vnet Failed", log.Fields{"Config": vnet.VnetConfig, "Error": err}) |
| 2353 | } |
| 2354 | |
| 2355 | if vnet.DeleteInProgress { |
| 2356 | va.VnetsToDelete[vnet.Name] = true |
| 2357 | logger.Warnw(ctx, "Vnet (restored) to be deleted", log.Fields{"Vnet": vnet.Name}) |
| 2358 | } |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 2359 | } |
| 2360 | } |
| 2361 | |
| 2362 | // GetServiceFromCvlan : Locate a service based on the packet received. The packet contains VLANs that |
| 2363 | // are used as the key to locate the service. If more than one service is on the |
| 2364 | // same port (essentially a UNI of ONU), the services must be separated by different |
| 2365 | // CVLANs |
| 2366 | func (va *VoltApplication) GetServiceFromCvlan(device, port string, vlans []of.VlanType, priority uint8) *VoltService { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 2367 | logger.Debugw(ctx, "Get Service From Cvlan", log.Fields{"Device": device, "Port": port, "VLANs": vlans, "Priority": priority}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 2368 | // Fetch the device first to make sure the device exists |
| 2369 | dIntf, ok := va.DevicesDisc.Load(device) |
| 2370 | if !ok { |
| 2371 | return nil |
| 2372 | } |
| 2373 | d := dIntf.(*VoltDevice) |
| 2374 | |
| 2375 | // If the port is NNI port, the services dont exist on it. The svc then |
| 2376 | // must be obtained from a different context and is not included here |
| 2377 | if port == d.NniPort { |
| 2378 | return nil |
| 2379 | } |
| 2380 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 2381 | // To return the matched service |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 2382 | var service *VoltService |
| 2383 | |
| 2384 | // This is an access port and the port should have all the associated |
| 2385 | // services which can be uniquely identified by the VLANs in the packet |
| 2386 | vnets, ok := va.VnetsByPort.Load(port) |
| 2387 | |
| 2388 | if !ok { |
| 2389 | logger.Debugw(ctx, "No Vnets for port", log.Fields{"Port": port}) |
| 2390 | return nil |
| 2391 | } |
| 2392 | logger.Debugw(ctx, "Matching for VLANs", log.Fields{"VLANs": vlans, "Priority": priority}) |
| 2393 | for _, vnet := range vnets.([]*VoltPortVnet) { |
| 2394 | logger.Infow(ctx, "Vnet", log.Fields{"Vnet": vnet}) |
| 2395 | switch vnet.VlanControl { |
| 2396 | case ONUCVlanOLTSVlan: |
| 2397 | service = vnet.MatchesPriority(priority) |
| 2398 | if vnet.MatchesCvlan(vlans) && service != nil { |
| 2399 | return service |
| 2400 | } |
| 2401 | case ONUCVlan, |
| 2402 | None: |
| 2403 | service = vnet.MatchesPriority(priority) |
| 2404 | // In case of DHCP Flow - cvlan == VlanNone |
| 2405 | // In case of HSIA Flow - cvlan == Svlan |
| 2406 | if len(vlans) == 1 && (vlans[0] == vnet.SVlan || vlans[0] == of.VlanNone) && service != nil { |
| 2407 | return service |
| 2408 | } |
| 2409 | case OLTCVlanOLTSVlan, |
| 2410 | OLTSVlan: |
| 2411 | service = vnet.MatchesPriority(priority) |
| 2412 | if len(vlans) == 1 && vlans[0] == vnet.UniVlan && service != nil { |
| 2413 | return service |
| 2414 | } |
| 2415 | default: |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 2416 | logger.Warnw(ctx, "Invalid Vlan Control Option", log.Fields{"Value": vnet.VlanControl}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 2417 | } |
| 2418 | } |
| 2419 | return nil |
| 2420 | } |
| 2421 | |
| 2422 | // GetVnetFromFields : Locate a service based on the packet received. The packet contains VLANs that |
| 2423 | // are used as the key to locate the service. If more than one service is on the |
| 2424 | // same port (essentially a UNI of ONU), the services must be separated by different |
| 2425 | // CVLANs |
| 2426 | func (va *VoltApplication) GetVnetFromFields(device string, port string, vlans []of.VlanType, priority uint8) (*VoltPortVnet, *VoltService) { |
| 2427 | // Fetch the device first to make sure the device exists |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 2428 | logger.Debugw(ctx, "Get Vnet From Fields", log.Fields{"Device": device, "Port": port, "VLANs": vlans, "Priority": priority}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 2429 | dIntf, ok := va.DevicesDisc.Load(device) |
| 2430 | if !ok { |
| 2431 | return nil, nil |
| 2432 | } |
| 2433 | d := dIntf.(*VoltDevice) |
| 2434 | |
| 2435 | // If the port is NNI port, the services dont exist on it. The svc then |
| 2436 | // must be obtained from a different context and is not included here |
| 2437 | if port == d.NniPort { |
| 2438 | return nil, nil |
| 2439 | } |
| 2440 | |
| 2441 | //To return the matched service |
| 2442 | var service *VoltService |
| 2443 | |
| 2444 | // This is an access port and the port should have all the associated |
| 2445 | // services which can be uniquely identified by the VLANs in the packet |
| 2446 | if vnets, ok := va.VnetsByPort.Load(port); ok { |
| 2447 | logger.Debugw(ctx, "Matching for VLANs", log.Fields{"VLANs": vlans, "Priority": priority}) |
| 2448 | for _, vnet := range vnets.([]*VoltPortVnet) { |
| 2449 | logger.Infow(ctx, "Vnet", log.Fields{"Vnet": vnet}) |
| 2450 | switch vnet.VlanControl { |
| 2451 | case ONUCVlanOLTSVlan: |
| 2452 | service = vnet.MatchesPriority(priority) |
| 2453 | if vnet.MatchesCvlan(vlans) && service != nil { |
| 2454 | return vnet, service |
| 2455 | } |
| 2456 | case ONUCVlan, |
| 2457 | None: |
| 2458 | service = vnet.MatchesPriority(priority) |
| 2459 | if (len(vlans) == 1 || vnet.AllowTransparent) && vlans[0] == vnet.SVlan && service != nil { |
| 2460 | return vnet, service |
| 2461 | } |
| 2462 | case OLTCVlanOLTSVlan, |
| 2463 | OLTSVlan: |
| 2464 | service = vnet.MatchesPriority(priority) |
| 2465 | if (len(vlans) == 1 || vnet.AllowTransparent) && vlans[0] == vnet.UniVlan && service != nil { |
| 2466 | return vnet, service |
| 2467 | } |
| 2468 | default: |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 2469 | logger.Warnw(ctx, "Invalid Vlan Control Option", log.Fields{"Value": vnet.VlanControl}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 2470 | } |
| 2471 | } |
| 2472 | } |
| 2473 | return nil, nil |
| 2474 | } |
| 2475 | |
| 2476 | // GetVnetFromPkt : Locate a service based on the packet received. The packet contains VLANs that |
| 2477 | // are used as the key to locate the service. If more than one service is on the |
| 2478 | // same port (essentially a UNI of ONU), the services must be separated by different |
| 2479 | // CVLANs |
| 2480 | func (va *VoltApplication) GetVnetFromPkt(device string, port string, pkt gopacket.Packet) (*VoltPortVnet, *VoltService) { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 2481 | logger.Debugw(ctx, "Get Vnet From Pkt", log.Fields{"Device": device, "Port": port}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 2482 | vlans := GetVlans(pkt) |
| 2483 | priority := GetPriority(pkt) |
| 2484 | return va.GetVnetFromFields(device, port, vlans, priority) |
| 2485 | } |
| 2486 | |
| 2487 | // PushDevFlowForVlan to push icmpv6 flows for vlan |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 2488 | func (va *VoltApplication) PushDevFlowForVlan(cntx context.Context, vnet *VoltVnet) { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 2489 | logger.Debugw(ctx, "PushDevFlowForVlan", log.Fields{"SVlan": vnet.SVlan, "CVlan": vnet.CVlan}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 2490 | pushflow := func(key interface{}, value interface{}) bool { |
| 2491 | device := value.(*VoltDevice) |
| 2492 | if !isDeviceInList(device.SerialNum, vnet.DevicesList) { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 2493 | logger.Warnw(ctx, "Device not present in vnet device list", log.Fields{"Device": device.SerialNum}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 2494 | return true |
| 2495 | } |
| 2496 | if device.State != controller.DeviceStateUP { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 2497 | logger.Warnw(ctx, "Push Dev Flows Failed - Device state DOWN", log.Fields{"Port": device.NniPort, "Vlan": vnet.SVlan, "device": device}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 2498 | return true |
| 2499 | } |
| 2500 | if applied, ok := device.VlanPortStatus.Load(uint16(vnet.SVlan)); !ok || !applied.(bool) { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 2501 | logger.Warnw(ctx, "Push Dev Flows Failed - Vlan not enabled yet", log.Fields{"Port": device.NniPort, "Vlan": vnet.SVlan}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 2502 | return true |
| 2503 | } |
| 2504 | |
| 2505 | if vnetListIntf, ok := device.ConfiguredVlanForDeviceFlows.Get(VnetKey(vnet.SVlan, vnet.CVlan, 0)); ok { |
| 2506 | vnetList := vnetListIntf.(*util.ConcurrentMap) |
| 2507 | vnetList.Set(vnet.Name, true) |
| 2508 | device.ConfiguredVlanForDeviceFlows.Set(VnetKey(vnet.SVlan, vnet.CVlan, 0), vnetList) |
| 2509 | logger.Infow(ctx, "Flow already pushed for these Vlans. Adding profile to list", log.Fields{"SVlan": vnet.SVlan, "CVlan": vnet.CVlan, "vnetList-len": vnetList.Length()}) |
| 2510 | return true |
| 2511 | } |
| 2512 | logger.Debugw(ctx, "Configuring Dev Flows Group for device ", log.Fields{"Device": device}) |
| 2513 | err := ProcessIcmpv6McGroup(device.Name, false) |
| 2514 | if err != nil { |
| 2515 | logger.Warnw(ctx, "Configuring Dev Flows Group for device failed ", log.Fields{"Device": device.Name, "err": err}) |
| 2516 | return true |
| 2517 | } |
| 2518 | if portID, err := va.GetPortID(device.NniPort); err == nil { |
| 2519 | if state, _ := cntlr.GetController().GetPortState(device.Name, device.NniPort); state != cntlr.PortStateUp { |
| 2520 | logger.Warnw(ctx, "Skipping Dev Flow Configuration - Port Down", log.Fields{"Device": device}) |
| 2521 | return true |
| 2522 | } |
| 2523 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 2524 | // Pushing ICMPv6 Flow |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 2525 | flow := BuildICMPv6Flow(portID, vnet) |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 2526 | err = cntlr.GetController().AddFlows(cntx, device.NniPort, device.Name, flow) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 2527 | if err != nil { |
| 2528 | logger.Warnw(ctx, "Configuring ICMPv6 Flow for device failed ", log.Fields{"Device": device.Name, "err": err}) |
| 2529 | return true |
| 2530 | } |
| 2531 | logger.Infow(ctx, "ICMPv6 Flow Added to Queue", log.Fields{"flow": flow}) |
| 2532 | |
| 2533 | // Pushing ARP Flow |
| 2534 | flow = BuildDSArpFlow(portID, vnet) |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 2535 | err = cntlr.GetController().AddFlows(cntx, device.NniPort, device.Name, flow) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 2536 | if err != nil { |
| 2537 | logger.Warnw(ctx, "Configuring ARP Flow for device failed ", log.Fields{"Device": device.Name, "err": err}) |
| 2538 | return true |
| 2539 | } |
| 2540 | logger.Infow(ctx, "ARP Flow Added to Queue", log.Fields{"flow": flow}) |
| 2541 | |
| 2542 | vnetList := util.NewConcurrentMap() |
| 2543 | vnetList.Set(vnet.Name, true) |
| 2544 | device.ConfiguredVlanForDeviceFlows.Set(VnetKey(vnet.SVlan, vnet.CVlan, 0), vnetList) |
| 2545 | } |
| 2546 | return true |
| 2547 | } |
| 2548 | va.DevicesDisc.Range(pushflow) |
| 2549 | } |
| 2550 | |
| 2551 | // PushDevFlowForDevice to push icmpv6 flows for device |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 2552 | func (va *VoltApplication) PushDevFlowForDevice(cntx context.Context, device *VoltDevice) { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 2553 | logger.Debugw(ctx, "PushDevFlowForDevice", log.Fields{"device": device.Name}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 2554 | err := ProcessIcmpv6McGroup(device.Name, false) |
| 2555 | if err != nil { |
| 2556 | logger.Warnw(ctx, "Configuring ICMPv6 Group for device failed ", log.Fields{"Device": device.Name, "err": err}) |
| 2557 | return |
| 2558 | } |
| 2559 | pushicmpv6 := func(key, value interface{}) bool { |
| 2560 | vnet := value.(*VoltVnet) |
| 2561 | if vnetListIntf, ok := device.ConfiguredVlanForDeviceFlows.Get(VnetKey(vnet.SVlan, vnet.CVlan, 0)); ok { |
| 2562 | vnetList := vnetListIntf.(*util.ConcurrentMap) |
| 2563 | vnetList.Set(vnet.Name, true) |
| 2564 | device.ConfiguredVlanForDeviceFlows.Set(VnetKey(vnet.SVlan, vnet.CVlan, 0), vnetList) |
| 2565 | logger.Infow(ctx, "Flow already pushed for these Vlans. Adding profile to list", log.Fields{"SVlan": vnet.SVlan, "CVlan": vnet.CVlan, "vnetList-len": vnetList.Length()}) |
| 2566 | return true |
| 2567 | } |
| 2568 | nniPortID, err := va.GetPortID(device.NniPort) |
| 2569 | if err != nil { |
| 2570 | logger.Errorw(ctx, "Push ICMPv6 Failed - Failed to get NNI Port Id", log.Fields{"Port": device.NniPort, "Reason": err.Error}) |
| 2571 | } |
| 2572 | if applied, ok := device.VlanPortStatus.Load(uint16(vnet.SVlan)); !ok || !applied.(bool) { |
| 2573 | logger.Warnw(ctx, "Push ICMPv6 Failed - Vlan not enabled yet", log.Fields{"Port": device.NniPort, "Vlan": vnet.SVlan}) |
| 2574 | return true |
| 2575 | } |
| 2576 | flow := BuildICMPv6Flow(nniPortID, vnet) |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 2577 | err = cntlr.GetController().AddFlows(cntx, device.NniPort, device.Name, flow) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 2578 | if err != nil { |
| 2579 | logger.Warnw(ctx, "Configuring ICMPv6 Flow for device failed ", log.Fields{"Device": device.Name, "err": err}) |
| 2580 | return true |
| 2581 | } |
| 2582 | logger.Infow(ctx, "ICMP Flow Added to Queue", log.Fields{"flow": flow}) |
| 2583 | |
| 2584 | flow = BuildDSArpFlow(nniPortID, vnet) |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 2585 | err = cntlr.GetController().AddFlows(cntx, device.NniPort, device.Name, flow) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 2586 | if err != nil { |
| 2587 | logger.Warnw(ctx, "Configuring ARP Flow for device failed ", log.Fields{"Device": device.Name, "err": err}) |
| 2588 | return true |
| 2589 | } |
| 2590 | logger.Infow(ctx, "ARP Flow Added to Queue", log.Fields{"flow": flow}) |
| 2591 | |
| 2592 | vnetList := util.NewConcurrentMap() |
| 2593 | vnetList.Set(vnet.Name, true) |
| 2594 | device.ConfiguredVlanForDeviceFlows.Set(VnetKey(vnet.SVlan, vnet.CVlan, 0), vnetList) |
| 2595 | return true |
| 2596 | } |
| 2597 | va.VnetsByName.Range(pushicmpv6) |
| 2598 | } |
| 2599 | |
| 2600 | // DeleteDevFlowForVlan to delete icmpv6 flow for vlan |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 2601 | func (va *VoltApplication) DeleteDevFlowForVlan(cntx context.Context, vnet *VoltVnet) { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 2602 | logger.Debugw(ctx, "DeleteDevFlowForVlan", log.Fields{"SVlan": vnet.SVlan, "CVlan": vnet.CVlan}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 2603 | delflows := func(key interface{}, value interface{}) bool { |
| 2604 | device := value.(*VoltDevice) |
| 2605 | |
| 2606 | if vnetListIntf, ok := device.ConfiguredVlanForDeviceFlows.Get(VnetKey(vnet.SVlan, vnet.CVlan, 0)); ok { |
| 2607 | vnetList := vnetListIntf.(*util.ConcurrentMap) |
| 2608 | vnetList.Remove(vnet.Name) |
| 2609 | device.ConfiguredVlanForDeviceFlows.Set(VnetKey(vnet.SVlan, vnet.CVlan, 0), vnetList) |
| 2610 | if vnetList.Length() != 0 { |
| 2611 | logger.Warnw(ctx, "Similar VNet associated to diff service. Not removing ICMPv6 flow", log.Fields{"SVlan": vnet.SVlan, "CVlan": vnet.CVlan, "vnetList-len": vnetList.Length()}) |
| 2612 | return true |
| 2613 | } |
| 2614 | } |
| 2615 | if portID, err := va.GetPortID(device.NniPort); err == nil { |
| 2616 | if state, _ := cntlr.GetController().GetPortState(device.Name, device.NniPort); state != cntlr.PortStateUp { |
| 2617 | logger.Warnw(ctx, "Skipping ICMPv6 Flow Deletion - Port Down", log.Fields{"Device": device}) |
| 2618 | return true |
| 2619 | } |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 2620 | // Pushing ICMPv6 Flow |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 2621 | flow := BuildICMPv6Flow(portID, vnet) |
| 2622 | flow.ForceAction = true |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 2623 | err := vnet.RemoveFlows(cntx, device, flow) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 2624 | if err != nil { |
| 2625 | logger.Warnw(ctx, "De-Configuring ICMPv6 Flow for device failed ", log.Fields{"Device": device.Name, "err": err}) |
| 2626 | return true |
| 2627 | } |
| 2628 | logger.Infow(ctx, "ICMPv6 Flow Delete Added to Queue", log.Fields{"flow": flow}) |
| 2629 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 2630 | // Pushing ARP Flow |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 2631 | flow = BuildDSArpFlow(portID, vnet) |
| 2632 | flow.ForceAction = true |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 2633 | err = vnet.RemoveFlows(cntx, device, flow) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 2634 | if err != nil { |
| 2635 | logger.Warnw(ctx, "De-Configuring ARP Flow for device failed ", log.Fields{"Device": device.Name, "err": err}) |
| 2636 | return true |
| 2637 | } |
| 2638 | logger.Infow(ctx, "ARP Flow Delete Added to Queue", log.Fields{"flow": flow}) |
| 2639 | |
| 2640 | device.ConfiguredVlanForDeviceFlows.Remove(VnetKey(vnet.SVlan, vnet.CVlan, 0)) |
| 2641 | } |
| 2642 | return true |
| 2643 | } |
| 2644 | va.DevicesDisc.Range(delflows) |
| 2645 | } |
| 2646 | |
| 2647 | // DeleteDevFlowForDevice to delete icmpv6 flow for device |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 2648 | func (va *VoltApplication) DeleteDevFlowForDevice(cntx context.Context, device *VoltDevice) { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 2649 | logger.Debugw(ctx, "DeleteDevFlowForDevice", log.Fields{"Device": device}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 2650 | delicmpv6 := func(key, value interface{}) bool { |
| 2651 | vnet := value.(*VoltVnet) |
| 2652 | if vnetListIntf, ok := device.ConfiguredVlanForDeviceFlows.Get(VnetKey(vnet.SVlan, vnet.CVlan, 0)); ok { |
| 2653 | vnetList := vnetListIntf.(*util.ConcurrentMap) |
| 2654 | vnetList.Remove(vnet.Name) |
| 2655 | device.ConfiguredVlanForDeviceFlows.Set(VnetKey(vnet.SVlan, vnet.CVlan, 0), vnetList) |
| 2656 | if vnetList.Length() != 0 { |
| 2657 | logger.Warnw(ctx, "Similar VNet associated to diff service. Not removing ICMPv6 flow", log.Fields{"SVlan": vnet.SVlan, "CVlan": vnet.CVlan, "vnetList-len": vnetList.Length()}) |
| 2658 | return true |
| 2659 | } |
| 2660 | } else { |
| 2661 | logger.Warnw(ctx, "ICMPv6 Flow map entry not found for Vnet", log.Fields{"Vnet": vnet.VnetConfig}) |
| 2662 | return true |
| 2663 | } |
| 2664 | nniPortID, err := va.GetPortID(device.NniPort) |
| 2665 | if err != nil { |
| 2666 | logger.Errorw(ctx, "Delete ICMPv6 Failed - Failed to get NNI Port Id", log.Fields{"Port": device.NniPort, "Reason": err.Error}) |
| 2667 | } |
| 2668 | flow := BuildICMPv6Flow(nniPortID, vnet) |
| 2669 | flow.ForceAction = true |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 2670 | err = vnet.RemoveFlows(cntx, device, flow) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 2671 | if err != nil { |
| 2672 | logger.Warnw(ctx, "De-Configuring ICMPv6 Flow for device failed ", log.Fields{"Device": device.Name, "err": err}) |
| 2673 | return true |
| 2674 | } |
| 2675 | |
| 2676 | flow = BuildDSArpFlow(nniPortID, vnet) |
| 2677 | flow.ForceAction = true |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 2678 | err = vnet.RemoveFlows(cntx, device, flow) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 2679 | if err != nil { |
| 2680 | logger.Warnw(ctx, "De-Configuring ARP Flow for device failed ", log.Fields{"Device": device.Name, "err": err}) |
| 2681 | return true |
| 2682 | } |
| 2683 | |
| 2684 | device.ConfiguredVlanForDeviceFlows.Remove(VnetKey(vnet.SVlan, vnet.CVlan, 0)) |
| 2685 | logger.Infow(ctx, "ICMP Flow Delete Added to Queue", log.Fields{"flow": flow}) |
| 2686 | return true |
| 2687 | } |
| 2688 | va.VnetsByName.Range(delicmpv6) |
| 2689 | logger.Debugw(ctx, "De-Configuring ICMPv6 Group for device ", log.Fields{"Device": device.Name}) |
| 2690 | err := ProcessIcmpv6McGroup(device.Name, true) |
| 2691 | if err != nil { |
| 2692 | logger.Warnw(ctx, "De-Configuring ICMPv6 Group on device failed ", log.Fields{"Device": device.Name, "err": err}) |
| 2693 | return |
| 2694 | } |
| 2695 | } |
| 2696 | |
| 2697 | // DeleteDevFlowForVlanFromDevice to delete icmpv6 flow for vlan from device |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 2698 | func (va *VoltApplication) DeleteDevFlowForVlanFromDevice(cntx context.Context, vnet *VoltVnet, deviceSerialNum string) { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 2699 | logger.Debugw(ctx, "DeleteDevFlowForVlanFromDevice", log.Fields{"Device-serialNum": deviceSerialNum, "SVlan": vnet.SVlan, "CVlan": vnet.CVlan}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 2700 | delflows := func(key interface{}, value interface{}) bool { |
| 2701 | device := value.(*VoltDevice) |
| 2702 | if device.SerialNum != deviceSerialNum { |
| 2703 | return true |
| 2704 | } |
| 2705 | if vnetListIntf, ok := device.ConfiguredVlanForDeviceFlows.Get(VnetKey(vnet.SVlan, vnet.CVlan, 0)); ok { |
| 2706 | vnetList := vnetListIntf.(*util.ConcurrentMap) |
| 2707 | vnetList.Remove(vnet.Name) |
| 2708 | device.ConfiguredVlanForDeviceFlows.Set(VnetKey(vnet.SVlan, vnet.CVlan, 0), vnetList) |
| 2709 | if vnetList.Length() != 0 { |
| 2710 | logger.Warnw(ctx, "Similar VNet associated to diff service. Not removing ICMPv6 flow", log.Fields{"SVlan": vnet.SVlan, "CVlan": vnet.CVlan, "vnetList-len": vnetList.Length()}) |
| 2711 | return true |
| 2712 | } |
| 2713 | } else if !vgcRebooted && len(vnet.DevicesList) != 0 { |
| 2714 | // Return only in-case of non-reboot/delete scenario. Else, the flows need to be force removed |
| 2715 | // DeviceList check is there to avoid dangling flow in-case of pod restart during service de-activation. |
| 2716 | // The step will be as follow: |
| 2717 | // 1. Deact Service |
| 2718 | // 2. Pod Reboot |
| 2719 | // 3. Pending Delete Service triggered |
| 2720 | // 4. Del Service Ind followed by DelVnet req from NB |
| 2721 | // 5. If Vlan status response is awaited, the ConfiguredVlanForDeviceFlows cache will not have flow info |
| 2722 | // hence the flow will not be cleared |
| 2723 | logger.Warnw(ctx, "Dev Flow map entry not found for Vnet", log.Fields{"PodReboot": vgcRebooted, "VnetDeleteInProgress": vnet.DeleteInProgress}) |
| 2724 | return true |
| 2725 | } |
| 2726 | if portID, err := va.GetPortID(device.NniPort); err == nil { |
| 2727 | if state, _ := cntlr.GetController().GetPortState(device.Name, device.NniPort); state != cntlr.PortStateUp { |
| 2728 | logger.Warnw(ctx, "Skipping ICMPv6 Flow Deletion - Port Down", log.Fields{"Device": device}) |
| 2729 | return false |
| 2730 | } |
| 2731 | flow := BuildICMPv6Flow(portID, vnet) |
| 2732 | flow.ForceAction = true |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 2733 | if err := vnet.RemoveFlows(cntx, device, flow); err != nil { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 2734 | logger.Warnw(ctx, "Delete Flow Failed", log.Fields{"Device": device, "Flow": flow, "Error": err}) |
| 2735 | } |
| 2736 | logger.Infow(ctx, "ICMP Flow Delete Added to Queue", log.Fields{"flow": flow}) |
| 2737 | |
| 2738 | flow = BuildDSArpFlow(portID, vnet) |
| 2739 | flow.ForceAction = true |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 2740 | if err := vnet.RemoveFlows(cntx, device, flow); err != nil { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 2741 | logger.Warnw(ctx, "Delete Flow Failed", log.Fields{"Device": device, "Flow": flow, "Error": err}) |
| 2742 | } |
| 2743 | logger.Infow(ctx, "ARP Flow Delete Added to Queue", log.Fields{"flow": flow}) |
| 2744 | device.ConfiguredVlanForDeviceFlows.Remove(VnetKey(vnet.SVlan, vnet.CVlan, 0)) |
| 2745 | } |
| 2746 | return false |
| 2747 | } |
| 2748 | va.DevicesDisc.Range(delflows) |
| 2749 | } |
| 2750 | |
| 2751 | // BuildICMPv6Flow to Build DS flow for ICMPv6 |
| 2752 | func BuildICMPv6Flow(inport uint32, vnet *VoltVnet) *of.VoltFlow { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 2753 | logger.Debugw(ctx, "Building ICMPv6 MC Flow", log.Fields{"SVlan": vnet.SVlan, "CVlan": vnet.CVlan}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 2754 | flow := &of.VoltFlow{} |
| 2755 | flow.SubFlows = make(map[uint64]*of.VoltSubFlow) |
| 2756 | subFlow := of.NewVoltSubFlow() |
| 2757 | |
| 2758 | subFlow.SetICMPv6Match() |
| 2759 | subFlow.SetMatchVlan(vnet.SVlan) |
| 2760 | subFlow.SetInPort(inport) |
| 2761 | subFlow.SetPopVlan() |
| 2762 | subFlow.SetOutGroup(ICMPv6ArpGroupID) |
| 2763 | subFlow.Cookie = uint64(vnet.CVlan)<<48 | uint64(vnet.SVlan)<<32 | of.IgmpFlowMask | of.DsFlowMask |
| 2764 | subFlow.Priority = of.McFlowPriority |
| 2765 | var metadata uint64 |
| 2766 | if vnet.VlanControl == None { |
| 2767 | metadata = uint64(ONUCVlan)<<32 | uint64(vnet.CVlan) |
| 2768 | } else { |
| 2769 | metadata = uint64(vnet.VlanControl)<<32 | uint64(vnet.CVlan) |
| 2770 | } |
| 2771 | subFlow.SetTableMetadata(metadata) |
| 2772 | metadata = uint64(vnet.setPbitRemarking()) |
| 2773 | |
| 2774 | logger.Infow(ctx, "ICMPv6 Pbit Remarking", log.Fields{"RemarkPbit": metadata}) |
| 2775 | subFlow.SetWriteMetadata(metadata) |
| 2776 | flow.SubFlows[subFlow.Cookie] = subFlow |
| 2777 | return flow |
| 2778 | } |
| 2779 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 2780 | // BuildDSArpFlow Builds DS flow for ARP |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 2781 | func BuildDSArpFlow(inport uint32, vnet *VoltVnet) *of.VoltFlow { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 2782 | logger.Debugw(ctx, "Building ARP MC Flow", log.Fields{"SVlan": vnet.SVlan, "CVlan": vnet.CVlan}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 2783 | |
| 2784 | flow := &of.VoltFlow{} |
| 2785 | flow.SubFlows = make(map[uint64]*of.VoltSubFlow) |
| 2786 | subFlow := of.NewVoltSubFlow() |
| 2787 | |
| 2788 | BcastMAC, _ := net.ParseMAC("FF:FF:FF:FF:FF:FF") |
| 2789 | subFlow.SetArpMatch() |
| 2790 | subFlow.SetMatchDstMac(BcastMAC) |
| 2791 | subFlow.SetMatchVlan(vnet.SVlan) |
| 2792 | subFlow.SetInPort(inport) |
| 2793 | subFlow.SetPopVlan() |
| 2794 | subFlow.SetOutGroup(ICMPv6ArpGroupID) |
| 2795 | |
| 2796 | subFlow.Cookie = uint64(vnet.CVlan)<<48 | uint64(vnet.SVlan)<<32 | of.DsArpFlowMask | of.DsFlowMask |
| 2797 | subFlow.Priority = of.McFlowPriority |
| 2798 | |
| 2799 | var metadata uint64 |
| 2800 | if vnet.VlanControl == None { |
| 2801 | metadata = uint64(ONUCVlan)<<32 | uint64(vnet.CVlan) |
| 2802 | } else { |
| 2803 | metadata = uint64(vnet.VlanControl)<<32 | uint64(vnet.CVlan) |
| 2804 | } |
| 2805 | subFlow.SetTableMetadata(metadata) |
| 2806 | metadata = uint64(vnet.setPbitRemarking()) |
| 2807 | subFlow.SetWriteMetadata(metadata) |
| 2808 | |
| 2809 | flow.SubFlows[subFlow.Cookie] = subFlow |
| 2810 | logger.Infow(ctx, "ARP Pbit Remarking", log.Fields{"RemarkPbit": metadata}) |
| 2811 | return flow |
| 2812 | } |
| 2813 | |
| 2814 | // setPbitRemarking to set Pbit remarking |
| 2815 | func (vv *VoltVnet) setPbitRemarking() uint32 { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 2816 | // Remarkable |
| 2817 | // Remarked Pbit Pbit |
| 2818 | // |-----------------------------| |------| |
| 2819 | // |7| |6| |5| |4| |3| |2| |1| |0| 76543210 |
| 2820 | // 000 000 000 000 000 000 000 000 00000000 |
| 2821 | |
| 2822 | // Eg: |
| 2823 | // For 6:3 & 7:1 |
| 2824 | // 001 011 000 000 000 000 000 000 11000000 |
| 2825 | |
| 2826 | var remarkable uint8 |
| 2827 | var remarked uint32 |
| 2828 | for refPbit, remarkPbit := range vv.CtrlPktPbitRemark { |
| 2829 | remarkable = remarkable | 1<<refPbit |
| 2830 | remarked = remarked | uint32(remarkPbit)<<(refPbit*3) |
| 2831 | } |
| 2832 | return remarked<<8 | uint32(remarkable) |
| 2833 | } |
| 2834 | |
| 2835 | // ProcessIcmpv6McGroup to add icmpv6 multicast group |
| 2836 | func ProcessIcmpv6McGroup(device string, delete bool) error { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 2837 | logger.Info(ctx, "Creating ICMPv6 MC Group") |
| 2838 | va := GetApplication() |
| 2839 | vd := va.GetDevice(device) |
| 2840 | group := &of.Group{} |
| 2841 | group.GroupID = ICMPv6ArpGroupID |
| 2842 | group.Device = device |
| 2843 | if delete { |
| 2844 | if !vd.icmpv6GroupAdded { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 2845 | logger.Debug(ctx, "ICMPv6 MC Group is already deleted. Ignoring icmpv6 group Delete") |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 2846 | return nil //TODO |
| 2847 | } |
| 2848 | vd.icmpv6GroupAdded = false |
| 2849 | group.Command = of.GroupCommandDel |
| 2850 | group.ForceAction = true |
| 2851 | } else { |
| 2852 | if vd.icmpv6GroupAdded { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 2853 | logger.Debug(ctx, "ICMPv6 MC Group is already added. Ignoring icmpv6 group Add") |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 2854 | return nil //TODO |
| 2855 | } |
| 2856 | vd.icmpv6GroupAdded = true |
| 2857 | group.Command = of.GroupCommandAdd |
| 2858 | receivers := GetApplication().GetIcmpv6Receivers(device) |
| 2859 | group.Buckets = append(group.Buckets, receivers...) |
| 2860 | } |
| 2861 | logger.Infow(ctx, "ICMPv6 MC Group Action", log.Fields{"Device": device, "Delete": delete}) |
| 2862 | port, _ := GetApplication().GetNniPort(device) |
| 2863 | err := cntlr.GetController().GroupUpdate(port, device, group) |
| 2864 | return err |
| 2865 | } |
| 2866 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 2867 | // isVlanMatching - checks is vlans matches with vpv based on vlan control |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 2868 | func (vpv *VoltPortVnet) isVlanMatching(cvlan of.VlanType, svlan of.VlanType) bool { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 2869 | logger.Debugw(ctx, "Is Vlan Matching", log.Fields{"cvlan": cvlan, "svlan": svlan}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 2870 | switch vpv.VlanControl { |
| 2871 | case ONUCVlanOLTSVlan, |
| 2872 | OLTCVlanOLTSVlan: |
| 2873 | if vpv.SVlan == svlan && vpv.CVlan == cvlan { |
| 2874 | return true |
| 2875 | } |
| 2876 | case ONUCVlan, |
| 2877 | OLTSVlan, |
| 2878 | None: |
| 2879 | if vpv.SVlan == svlan { |
| 2880 | return true |
| 2881 | } |
| 2882 | default: |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 2883 | logger.Warnw(ctx, "Invalid Vlan Control Option", log.Fields{"Value": vpv.VlanControl}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 2884 | } |
| 2885 | return false |
| 2886 | } |
| 2887 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 2888 | // PushFlows - Triggers flow addition after registering for flow indication event |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 2889 | func (vpv *VoltPortVnet) PushFlows(cntx context.Context, device *VoltDevice, flow *of.VoltFlow) error { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 2890 | logger.Debugw(ctx, "Push Flows", log.Fields{"DeviceName": device.Name, "Flow port": flow.PortID}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 2891 | for cookie := range flow.SubFlows { |
| 2892 | cookie := strconv.FormatUint(cookie, 10) |
| 2893 | fe := &FlowEvent{ |
| 2894 | eType: EventTypeControlFlowAdded, |
| 2895 | cookie: cookie, |
| 2896 | eventData: vpv, |
| 2897 | } |
| 2898 | device.RegisterFlowAddEvent(cookie, fe) |
| 2899 | } |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 2900 | return cntlr.GetController().AddFlows(cntx, vpv.Port, device.Name, flow) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 2901 | } |
| 2902 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 2903 | // FlowInstallFailure - Process flow failure indication and triggers HSIA failure for all associated services |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 2904 | func (vpv *VoltPortVnet) FlowInstallFailure(cookie string, errorCode uint32, errReason string) { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 2905 | logger.Debugw(ctx, "Flow Install Failure", log.Fields{"Cookie": cookie, "ErrorCode": errorCode, "ErrReason": errReason}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 2906 | sendFlowFailureInd := func(key, value interface{}) bool { |
| 2907 | //svc := value.(*VoltService) |
| 2908 | //TODO-COMM: svc.triggerServiceFailureInd(errorCode, errReason) |
| 2909 | return true |
| 2910 | } |
| 2911 | logger.Errorw(ctx, "Control Flow Add Failure Notification", log.Fields{"uniPort": vpv.Port, "Cookie": cookie, "ErrorCode": errorCode, "ErrorReason": errReason}) |
| 2912 | vpv.services.Range(sendFlowFailureInd) |
| 2913 | } |
| 2914 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 2915 | // RemoveFlows - Triggers flow deletion after registering for flow indication event |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 2916 | func (vpv *VoltPortVnet) RemoveFlows(cntx context.Context, device *VoltDevice, flow *of.VoltFlow) error { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 2917 | logger.Debugw(ctx, "Remove Flows", log.Fields{"DeviceName": device.Name, "Flow port": flow.PortID}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 2918 | vpv.PendingFlowLock.Lock() |
| 2919 | defer vpv.PendingFlowLock.Unlock() |
| 2920 | |
| 2921 | for cookie := range flow.SubFlows { |
| 2922 | cookie := strconv.FormatUint(cookie, 10) |
| 2923 | fe := &FlowEvent{ |
| 2924 | eType: EventTypeControlFlowRemoved, |
| 2925 | device: device.Name, |
| 2926 | cookie: cookie, |
| 2927 | eventData: vpv, |
| 2928 | } |
| 2929 | device.RegisterFlowDelEvent(cookie, fe) |
| 2930 | vpv.PendingDeleteFlow[cookie] = true |
| 2931 | } |
Sridhar Ravindra | 03aa0bf | 2023-09-12 17:46:40 +0530 | [diff] [blame] | 2932 | return cntlr.GetController().DelFlows(cntx, vpv.Port, device.Name, flow, false) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 2933 | } |
| 2934 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 2935 | // CheckAndDeleteVpv - remove VPV from DB is there are no pending flows to be removed |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 2936 | func (vpv *VoltPortVnet) CheckAndDeleteVpv(cntx context.Context) { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 2937 | logger.Debugw(ctx, "Check And Delete Vpv", log.Fields{"VPV Port": vpv.Port, "Device": vpv.Device, "Vnet": vpv.VnetName}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 2938 | vpv.PendingFlowLock.RLock() |
| 2939 | defer vpv.PendingFlowLock.RUnlock() |
| 2940 | if !vpv.DeleteInProgress { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 2941 | logger.Warnw(ctx, "Skipping removing VPV from DB as VPV delete is in progress", log.Fields{"VPV Port": vpv.Port, "Device": vpv.Device, "Vnet": vpv.VnetName}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 2942 | return |
| 2943 | } |
| 2944 | if len(vpv.PendingDeleteFlow) == 0 && !vpv.FlowsApplied { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 2945 | logger.Debugw(ctx, "All Flows removed for VPV. Triggering VPV Deletion from DB", log.Fields{"VPV Port": vpv.Port, "Device": vpv.Device, "Vnet": vpv.VnetName}) |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 2946 | vpv.DelFromDb(cntx) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 2947 | logger.Infow(ctx, "Deleted VPV from DB/Cache successfully", log.Fields{"VPV Port": vpv.Port, "Device": vpv.Device, "Vnet": vpv.VnetName}) |
| 2948 | } |
| 2949 | } |
| 2950 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 2951 | // FlowRemoveSuccess - Process flow success indication |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 2952 | func (vpv *VoltPortVnet) FlowRemoveSuccess(cntx context.Context, cookie string, device string) { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 2953 | vpv.PendingFlowLock.Lock() |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 2954 | logger.Debugw(ctx, "VPV Flow Remove Success Notification", log.Fields{"Port": vpv.Port, "Cookie": cookie, "Device": device}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 2955 | |
| 2956 | delete(vpv.PendingDeleteFlow, cookie) |
| 2957 | vpv.PendingFlowLock.Unlock() |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 2958 | vpv.CheckAndDeleteVpv(cntx) |
| 2959 | vpv.WriteToDb(cntx) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 2960 | } |
| 2961 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 2962 | // FlowRemoveFailure - Process flow failure indication and triggers Del HSIA failure for all associated services |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 2963 | func (vpv *VoltPortVnet) FlowRemoveFailure(cntx context.Context, cookie string, device string, errorCode uint32, errReason string) { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 2964 | vpv.PendingFlowLock.Lock() |
| 2965 | |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 2966 | logger.Debugw(ctx, "VPV Flow Remove Failure Notification", log.Fields{"Port": vpv.Port, "Cookie": cookie, "ErrorCode": errorCode, "ErrorReason": errReason, "Device": device}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 2967 | |
| 2968 | sendFlowFailureInd := func(key, value interface{}) bool { |
| 2969 | svc := value.(*VoltService) |
| 2970 | svc.triggerServiceFailureInd(errorCode, errReason) |
| 2971 | return true |
| 2972 | } |
| 2973 | logger.Errorw(ctx, "Control Flow Del Failure Notification", log.Fields{"uniPort": vpv.Port, "Cookie": cookie, "ErrorCode": errorCode, "ErrorReason": errReason}) |
| 2974 | vpv.services.Range(sendFlowFailureInd) |
| 2975 | |
| 2976 | if vpv.DeleteInProgress { |
| 2977 | delete(vpv.PendingDeleteFlow, cookie) |
| 2978 | vpv.PendingFlowLock.Unlock() |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 2979 | vpv.CheckAndDeleteVpv(cntx) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 2980 | } else { |
| 2981 | vpv.PendingFlowLock.Unlock() |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 2982 | vpv.WriteToDb(cntx) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 2983 | } |
| 2984 | } |
| 2985 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 2986 | // RemoveFlows - Triggers flow deletion after registering for flow indication event |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 2987 | func (vv *VoltVnet) RemoveFlows(cntx context.Context, device *VoltDevice, flow *of.VoltFlow) error { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 2988 | logger.Debugw(ctx, "Remove Flows", log.Fields{"PortName": flow.PortName, "DeviceName": device.Name}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 2989 | vv.VnetLock.Lock() |
| 2990 | defer vv.VnetLock.Unlock() |
| 2991 | |
| 2992 | var flowMap map[string]bool |
| 2993 | var ok bool |
| 2994 | |
| 2995 | for cookie := range flow.SubFlows { |
| 2996 | cookie := strconv.FormatUint(cookie, 10) |
| 2997 | fe := &FlowEvent{ |
| 2998 | eType: EventTypeDeviceFlowRemoved, |
| 2999 | device: device.Name, |
| 3000 | cookie: cookie, |
| 3001 | eventData: vv, |
| 3002 | } |
| 3003 | device.RegisterFlowDelEvent(cookie, fe) |
| 3004 | if flowMap, ok = vv.PendingDeleteFlow[device.Name]; !ok { |
| 3005 | flowMap = make(map[string]bool) |
| 3006 | } |
| 3007 | flowMap[cookie] = true |
| 3008 | vv.PendingDeleteFlow[device.Name] = flowMap |
| 3009 | } |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 3010 | vv.WriteToDb(cntx) |
Sridhar Ravindra | 03aa0bf | 2023-09-12 17:46:40 +0530 | [diff] [blame] | 3011 | return cntlr.GetController().DelFlows(cntx, device.NniPort, device.Name, flow, false) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 3012 | } |
| 3013 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 3014 | // CheckAndDeleteVnet - remove Vnet from DB is there are no pending flows to be removed |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 3015 | func (vv *VoltVnet) CheckAndDeleteVnet(cntx context.Context, device string) { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 3016 | logger.Debugw(ctx, "Check And Delete Vnet", log.Fields{"Device": device, "Vnet": vv.Name}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 3017 | if !vv.DeleteInProgress { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 3018 | logger.Warnw(ctx, "Skipping removing Vnet from DB as Vnet delete is in progress", log.Fields{"Name": vv.Name, "AssociatedPorts": vv.AssociatedPorts, "Device": device}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 3019 | return |
| 3020 | } |
| 3021 | vv.VnetPortLock.RLock() |
| 3022 | if len(vv.PendingDeleteFlow[device]) == 0 && !vv.isAssociatedPortsPresent() { |
| 3023 | logger.Warnw(ctx, "Deleting Vnet : All flows removed", log.Fields{"Name": vv.Name, "AssociatedPorts": vv.AssociatedPorts, "Device": device}) |
| 3024 | GetApplication().deleteVnetConfig(vv) |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 3025 | _ = db.DelVnet(cntx, vv.Name) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 3026 | logger.Infow(ctx, "Deleted Vnet from DB/Cache successfully", log.Fields{"Device": device, "Vnet": vv.Name}) |
| 3027 | } else { |
| 3028 | logger.Warnw(ctx, "Skipping Del Vnet", log.Fields{"Name": vv.Name, "AssociatedPorts": vv.AssociatedPorts, "PendingDelFlows": vv.PendingDeleteFlow[device]}) |
| 3029 | } |
| 3030 | vv.VnetPortLock.RUnlock() |
| 3031 | } |
| 3032 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 3033 | // FlowRemoveSuccess - Process flow success indication |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 3034 | func (vv *VoltVnet) FlowRemoveSuccess(cntx context.Context, cookie string, device string) { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 3035 | vv.VnetLock.Lock() |
| 3036 | defer vv.VnetLock.Unlock() |
| 3037 | |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 3038 | logger.Debugw(ctx, "Vnet Flow Remove Success Notification", log.Fields{"VnetProfile": vv.Name, "Cookie": cookie, "Device": device}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 3039 | |
| 3040 | if _, ok := vv.PendingDeleteFlow[device]; ok { |
| 3041 | delete(vv.PendingDeleteFlow[device], cookie) |
| 3042 | } |
| 3043 | |
| 3044 | //Check and update success for pending disable request |
| 3045 | if d := GetApplication().GetDevice(device); d != nil { |
| 3046 | _, present := d.ConfiguredVlanForDeviceFlows.Get(VnetKey(vv.SVlan, vv.CVlan, 0)) |
| 3047 | if !present && len(vv.PendingDeleteFlow[device]) == 0 { |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 3048 | vv.CheckAndDeleteVnet(cntx, device) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 3049 | } |
| 3050 | } |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 3051 | vv.WriteToDb(cntx) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 3052 | } |
| 3053 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 3054 | // FlowRemoveFailure - Process flow failure indication |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 3055 | func (vv *VoltVnet) FlowRemoveFailure(cntx context.Context, cookie string, device string, errorCode uint32, errReason string) { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 3056 | vv.VnetLock.Lock() |
| 3057 | defer vv.VnetLock.Unlock() |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 3058 | logger.Debugw(ctx, "Vnet Flow Remove Failure Notification", log.Fields{"VnetProfile": vv.Name, "Cookie": cookie, "Device": device, "ErrorCode": errorCode, "ErrorReason": errReason}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 3059 | |
| 3060 | if flowMap, ok := vv.PendingDeleteFlow[device]; ok { |
| 3061 | if _, ok := flowMap[cookie]; ok { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 3062 | logger.Debugw(ctx, "Device Flow Remove Failure Notification", log.Fields{"Vnet": vv.Name, "Cookie": cookie, "ErrorCode": errorCode, "ErrorReason": errReason, "Device": device}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 3063 | |
| 3064 | if vv.DeleteInProgress { |
| 3065 | delete(vv.PendingDeleteFlow[device], cookie) |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 3066 | vv.CheckAndDeleteVnet(cntx, device) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 3067 | } |
| 3068 | return |
| 3069 | } |
| 3070 | } |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 3071 | logger.Debugw(ctx, "Device Flow Remove Failure Notification for Unknown cookie", log.Fields{"Vnet": vv.Name, "Cookie": cookie, "ErrorCode": errorCode, "ErrorReason": errReason}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 3072 | } |
| 3073 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 3074 | // IgmpFlowInstallFailure - Process flow failure indication and triggers HSIA failure for Igmp enabled services |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 3075 | func (vpv *VoltPortVnet) IgmpFlowInstallFailure(cookie string, errorCode uint32, errReason string) { |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 3076 | // Note: Current implementation supports only for single service with Igmp Enabled for a subscriber |
| 3077 | // When multiple Igmp-suported service enabled, comment "return false" |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 3078 | logger.Debugw(ctx, "Igmp Flow Install Failure", log.Fields{"Cookie": cookie, "ErrorCode": errorCode, "ErrorReason": errReason}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 3079 | |
| 3080 | sendFlowFailureInd := func(key, value interface{}) bool { |
| 3081 | svc := value.(*VoltService) |
| 3082 | if svc.IgmpEnabled { |
| 3083 | svc.triggerServiceFailureInd(errorCode, errReason) |
| 3084 | return false |
| 3085 | } |
| 3086 | return true |
| 3087 | } |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 3088 | logger.Debugw(ctx, "US IGMP Flow Failure Notification", log.Fields{"uniPort": vpv.Port, "Cookie": cookie, "ErrorCode": errorCode, "ErrorReason": errReason}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 3089 | vpv.services.Range(sendFlowFailureInd) |
| 3090 | } |
| 3091 | |
| 3092 | // GetMatchingMcastService to get matching multicast service |
| 3093 | func (va *VoltApplication) GetMatchingMcastService(port string, device string, cvlan of.VlanType) *VoltService { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 3094 | logger.Debugw(ctx, "Get Matching Mcast Service", log.Fields{"Port": port, "Device": device, "Cvlan": cvlan}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 3095 | var service *VoltService |
| 3096 | dIntf, ok := va.DevicesDisc.Load(device) |
| 3097 | if !ok { |
| 3098 | return nil |
| 3099 | } |
| 3100 | d := dIntf.(*VoltDevice) |
| 3101 | |
| 3102 | // If the port is NNI port, the services dont exist on it. The svc then |
| 3103 | // must be obtained from a different context and is not included here |
| 3104 | if port == d.NniPort { |
| 3105 | return nil |
| 3106 | } |
| 3107 | |
| 3108 | // This is an access port and the port should have all the associated |
| 3109 | // services which can be uniquely identified by the VLANs in the packet |
| 3110 | vnets, ok := va.VnetsByPort.Load(port) |
| 3111 | |
| 3112 | if !ok { |
| 3113 | logger.Debugw(ctx, "No Vnets for port", log.Fields{"Port": port}) |
| 3114 | return nil |
| 3115 | } |
| 3116 | logger.Debugw(ctx, "Matching for VLANs", log.Fields{"VLANs": cvlan}) |
| 3117 | getMcastService := func(key, value interface{}) bool { |
| 3118 | srv := value.(*VoltService) |
| 3119 | if srv.IgmpEnabled { |
| 3120 | service = srv |
| 3121 | |
| 3122 | //TODO: Current implementation supports only for single service with Igmp Enabled |
| 3123 | //FIX-ME: When multiple service suports Igmp, update of logic required |
| 3124 | return false |
| 3125 | } |
| 3126 | return true |
| 3127 | } |
| 3128 | |
| 3129 | for _, vpv := range vnets.([]*VoltPortVnet) { |
| 3130 | if vpv.CVlan == cvlan { |
| 3131 | vpv.services.Range(getMcastService) |
| 3132 | if service != nil { |
| 3133 | break |
| 3134 | } |
| 3135 | } |
| 3136 | } |
| 3137 | return service |
| 3138 | } |
| 3139 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 3140 | // TriggerAssociatedFlowDelete - Re-trigger delete for pending delete flows |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 3141 | func (vv *VoltVnet) TriggerAssociatedFlowDelete(cntx context.Context, device string) bool { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 3142 | logger.Infow(ctx, "Trigger Associated Flow Delete", log.Fields{"Device": device}) |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 3143 | vv.VnetLock.Lock() |
| 3144 | cookieList := []uint64{} |
| 3145 | flowMap := vv.PendingDeleteFlow[device] |
| 3146 | |
| 3147 | for cookie := range flowMap { |
| 3148 | cookieList = append(cookieList, convertToUInt64(cookie)) |
| 3149 | } |
| 3150 | vv.VnetLock.Unlock() |
| 3151 | |
| 3152 | if len(cookieList) == 0 { |
| 3153 | return false |
| 3154 | } |
| 3155 | |
| 3156 | for _, cookie := range cookieList { |
| 3157 | if vd := GetApplication().GetDevice(device); vd != nil { |
| 3158 | flow := &of.VoltFlow{} |
| 3159 | flow.SubFlows = make(map[uint64]*of.VoltSubFlow) |
| 3160 | subFlow := of.NewVoltSubFlow() |
| 3161 | subFlow.Cookie = cookie |
| 3162 | flow.SubFlows[cookie] = subFlow |
| 3163 | logger.Infow(ctx, "Retriggering Vnet Delete Flow", log.Fields{"Device": device, "Vnet": vv.Name, "Cookie": cookie}) |
Tinoj Joseph | 07cc537 | 2022-07-18 22:53:51 +0530 | [diff] [blame] | 3164 | if err := vv.RemoveFlows(cntx, vd, flow); err != nil { |
Naveen Sampath | 04696f7 | 2022-06-13 15:19:14 +0530 | [diff] [blame] | 3165 | logger.Warnw(ctx, "Vnet Delete Flow Failed", log.Fields{"Device": device, "Vnet": vv.Name, "Cookie": cookie, "Error": err}) |
| 3166 | } |
| 3167 | } |
| 3168 | } |
| 3169 | return true |
| 3170 | } |
Tinoj Joseph | c2ccd6b | 2022-07-19 04:32:15 +0530 | [diff] [blame] | 3171 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 3172 | // JSONMarshal wrapper function for json Marshal VoltVnet |
| 3173 | func (vv *VoltVnet) JSONMarshal() ([]byte, error) { |
Tinoj Joseph | c2ccd6b | 2022-07-19 04:32:15 +0530 | [diff] [blame] | 3174 | return json.Marshal(VoltVnet{ |
| 3175 | VnetConfig: vv.VnetConfig, |
Akash Soni | a824697 | 2023-01-03 10:37:08 +0530 | [diff] [blame] | 3176 | Version: vv.Version, |
Tinoj Joseph | c2ccd6b | 2022-07-19 04:32:15 +0530 | [diff] [blame] | 3177 | VnetOper: VnetOper{ |
| 3178 | PendingDeleteFlow: vv.VnetOper.PendingDeleteFlow, |
| 3179 | DeleteInProgress: vv.VnetOper.DeleteInProgress, |
| 3180 | PendingDeviceToDelete: vv.VnetOper.PendingDeviceToDelete, |
| 3181 | }, |
| 3182 | }) |
| 3183 | } |
| 3184 | |
vinokuma | 926cb3e | 2023-03-29 11:41:06 +0530 | [diff] [blame] | 3185 | // JSONMarshal wrapper function for json Marshal VoltPortVnet |
| 3186 | func (vpv *VoltPortVnet) JSONMarshal() ([]byte, error) { |
Tinoj Joseph | c2ccd6b | 2022-07-19 04:32:15 +0530 | [diff] [blame] | 3187 | return json.Marshal(VoltPortVnet{ |
| 3188 | Device: vpv.Device, |
| 3189 | Port: vpv.Port, |
| 3190 | PonPort: vpv.PonPort, |
| 3191 | VnetName: vpv.VnetName, |
| 3192 | SVlan: vpv.SVlan, |
| 3193 | CVlan: vpv.CVlan, |
| 3194 | UniVlan: vpv.UniVlan, |
| 3195 | SVlanTpid: vpv.SVlanTpid, |
| 3196 | DhcpRelay: vpv.DhcpRelay, |
| 3197 | ArpRelay: vpv.ArpRelay, |
| 3198 | PppoeIa: vpv.PppoeIa, |
| 3199 | MacLearning: vpv.MacLearning, |
| 3200 | DhcpStatus: vpv.DhcpStatus, |
| 3201 | DhcpExpiryTime: vpv.DhcpExpiryTime, |
| 3202 | Dhcp6ExpiryTime: vpv.Dhcp6ExpiryTime, |
| 3203 | FlowsApplied: vpv.FlowsApplied, |
| 3204 | Ipv4Addr: vpv.Ipv4Addr, |
| 3205 | Ipv6Addr: vpv.Ipv6Addr, |
| 3206 | MacAddr: vpv.MacAddr, |
| 3207 | LearntMacAddr: vpv.LearntMacAddr, |
| 3208 | CircuitID: vpv.CircuitID, |
| 3209 | RemoteID: vpv.RemoteID, |
Hitesh Chhabra | 9f9a9df | 2023-06-13 17:52:15 +0530 | [diff] [blame] | 3210 | IsOption82Enabled: vpv.IsOption82Enabled, |
Tinoj Joseph | c2ccd6b | 2022-07-19 04:32:15 +0530 | [diff] [blame] | 3211 | RelayState: vpv.RelayState, |
| 3212 | PPPoeState: vpv.PPPoeState, |
| 3213 | RelayStatev6: vpv.RelayStatev6, |
| 3214 | IgmpEnabled: vpv.IgmpEnabled, |
| 3215 | IgmpFlowsApplied: vpv.IgmpFlowsApplied, |
| 3216 | McastService: vpv.McastService, |
| 3217 | ONTEtherTypeClassification: vpv.ONTEtherTypeClassification, |
| 3218 | VlanControl: vpv.VlanControl, |
| 3219 | MvlanProfileName: vpv.MvlanProfileName, |
| 3220 | Version: vpv.Version, |
| 3221 | McastTechProfileID: vpv.McastTechProfileID, |
| 3222 | McastPbit: vpv.McastPbit, |
| 3223 | McastUsMeterID: vpv.McastUsMeterID, |
| 3224 | AllowTransparent: vpv.AllowTransparent, |
| 3225 | SchedID: vpv.SchedID, |
| 3226 | DHCPv6DUID: vpv.DHCPv6DUID, |
| 3227 | PendingDeleteFlow: vpv.PendingDeleteFlow, |
| 3228 | DeleteInProgress: vpv.DeleteInProgress, |
| 3229 | Blocked: vpv.Blocked, |
| 3230 | DhcpPbit: vpv.DhcpPbit, |
| 3231 | }) |
| 3232 | } |
Tinoj Joseph | ec742f6 | 2022-09-29 19:11:10 +0530 | [diff] [blame] | 3233 | |
| 3234 | func (vpv *VoltPortVnet) IsServiceActivated(cntx context.Context) bool { |
Hitesh Chhabra | 2b2347d | 2023-07-31 17:36:48 +0530 | [diff] [blame] | 3235 | logger.Debugw(ctx, "Is Service Activated", log.Fields{"Name": vpv.Port}) |
Tinoj Joseph | ec742f6 | 2022-09-29 19:11:10 +0530 | [diff] [blame] | 3236 | isActivated := false |
| 3237 | vpv.services.Range(func(key, value interface{}) bool { |
| 3238 | svc := value.(*VoltService) |
| 3239 | if svc.IsActivated { |
| 3240 | logger.Infow(ctx, "Found activated service on the vpv", log.Fields{"Name": svc.Name}) |
| 3241 | isActivated = true |
| 3242 | return false //to exit loop |
| 3243 | } |
| 3244 | return true |
| 3245 | }) |
| 3246 | return isActivated |
| 3247 | } |