manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2018-present Open Networking Foundation |
| 3 | |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Scott Baker | dbd960e | 2020-02-28 08:57:51 -0800 | [diff] [blame] | 17 | //Package core provides the utility for olt devices, flows and statistics |
| 18 | package core |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 19 | |
| 20 | import ( |
| 21 | "context" |
Matteo Scandolo | 6056e82 | 2019-11-13 14:05:29 -0800 | [diff] [blame] | 22 | "encoding/hex" |
Girish Gowdra | cefae19 | 2020-03-19 18:14:10 -0700 | [diff] [blame] | 23 | "errors" |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 24 | "fmt" |
Gamze Abaka | 7650be6 | 2021-02-26 10:50:36 +0000 | [diff] [blame] | 25 | "strconv" |
serkant.uluderya | 4aff186 | 2020-09-17 23:35:26 +0300 | [diff] [blame] | 26 | "strings" |
| 27 | "sync" |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 28 | "time" |
serkant.uluderya | 4aff186 | 2020-09-17 23:35:26 +0300 | [diff] [blame] | 29 | |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 30 | "github.com/opencord/voltha-lib-go/v7/pkg/meters" |
Mahir Gunyel | 199570a | 2021-07-04 15:39:36 -0700 | [diff] [blame] | 31 | |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 32 | "github.com/opencord/voltha-lib-go/v7/pkg/flows" |
| 33 | "github.com/opencord/voltha-lib-go/v7/pkg/log" |
Mahir Gunyel | 85f61c1 | 2021-10-06 11:53:45 -0700 | [diff] [blame] | 34 | plt "github.com/opencord/voltha-lib-go/v7/pkg/platform" |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 35 | tp "github.com/opencord/voltha-lib-go/v7/pkg/techprofile" |
Scott Baker | dbd960e | 2020-02-28 08:57:51 -0800 | [diff] [blame] | 36 | rsrcMgr "github.com/opencord/voltha-openolt-adapter/internal/pkg/resourcemanager" |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 37 | "github.com/opencord/voltha-protos/v5/go/common" |
khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 38 | ia "github.com/opencord/voltha-protos/v5/go/inter_adapter" |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 39 | ofp "github.com/opencord/voltha-protos/v5/go/openflow_13" |
| 40 | openoltpb2 "github.com/opencord/voltha-protos/v5/go/openolt" |
| 41 | tp_pb "github.com/opencord/voltha-protos/v5/go/tech_profile" |
| 42 | "github.com/opencord/voltha-protos/v5/go/voltha" |
Chaitrashree G S | 579fe73 | 2019-08-20 20:50:47 -0400 | [diff] [blame] | 43 | |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 44 | "github.com/opencord/voltha-openolt-adapter/internal/pkg/olterrors" |
Daniele Rossi | 22db98e | 2019-07-11 11:50:00 +0000 | [diff] [blame] | 45 | "google.golang.org/grpc/codes" |
| 46 | "google.golang.org/grpc/status" |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 47 | ) |
| 48 | |
| 49 | const ( |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 50 | //IPProtoDhcp flow category |
| 51 | IPProtoDhcp = 17 |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 52 | |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 53 | //IgmpProto proto value |
| 54 | IgmpProto = 2 |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 55 | |
| 56 | //EapEthType eapethtype value |
| 57 | EapEthType = 0x888e |
| 58 | //LldpEthType lldp ethtype value |
| 59 | LldpEthType = 0x88cc |
Esin Karaman | ae41e2b | 2019-12-17 18:13:13 +0000 | [diff] [blame] | 60 | //IPv4EthType IPv4 ethernet type value |
| 61 | IPv4EthType = 0x800 |
Marcos Aurelio Carrero (Furukawa) | 388fb0a | 2021-02-04 18:05:11 -0300 | [diff] [blame] | 62 | //PPPoEDEthType PPPoE discovery ethernet type value |
| 63 | PPPoEDEthType = 0x8863 |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 64 | |
Andrea Campanella | 7acc0b9 | 2020-02-14 09:20:49 +0100 | [diff] [blame] | 65 | //ReservedVlan Transparent Vlan (Masked Vlan, VLAN_ANY in ONOS Flows) |
| 66 | ReservedVlan = 4096 |
Harsh Awasthi | ea45af7 | 2019-08-26 02:39:00 -0400 | [diff] [blame] | 67 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 68 | //DefaultMgmtVlan default vlan value |
| 69 | DefaultMgmtVlan = 4091 |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 70 | |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 71 | // Openolt Flow |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 72 | |
David K. Bainbridge | 82efc49 | 2019-09-04 09:57:11 -0700 | [diff] [blame] | 73 | //Upstream constant |
| 74 | Upstream = "upstream" |
| 75 | //Downstream constant |
| 76 | Downstream = "downstream" |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 77 | //Multicast constant |
| 78 | Multicast = "multicast" |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 79 | //PacketTagType constant |
| 80 | PacketTagType = "pkt_tag_type" |
David K. Bainbridge | 82efc49 | 2019-09-04 09:57:11 -0700 | [diff] [blame] | 81 | //Untagged constant |
| 82 | Untagged = "untagged" |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 83 | //SingleTag constant |
| 84 | SingleTag = "single_tag" |
| 85 | //DoubleTag constant |
| 86 | DoubleTag = "double_tag" |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 87 | |
| 88 | // classifierInfo |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 89 | |
| 90 | //EthType constant |
| 91 | EthType = "eth_type" |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 92 | //EthDst constant |
| 93 | EthDst = "eth_dst" |
Girish Gowdra | ffa52e5 | 2022-02-16 15:48:10 -0800 | [diff] [blame^] | 94 | //EthSrc constant |
| 95 | EthSrc = "eth_src" |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 96 | //TPID constant |
| 97 | TPID = "tpid" |
| 98 | //IPProto constant |
| 99 | IPProto = "ip_proto" |
| 100 | //InPort constant |
| 101 | InPort = "in_port" |
| 102 | //VlanVid constant |
| 103 | VlanVid = "vlan_vid" |
| 104 | //VlanPcp constant |
| 105 | VlanPcp = "vlan_pcp" |
| 106 | |
| 107 | //UDPDst constant |
| 108 | UDPDst = "udp_dst" |
| 109 | //UDPSrc constant |
| 110 | UDPSrc = "udp_src" |
| 111 | //Ipv4Dst constant |
| 112 | Ipv4Dst = "ipv4_dst" |
| 113 | //Ipv4Src constant |
| 114 | Ipv4Src = "ipv4_src" |
David K. Bainbridge | 82efc49 | 2019-09-04 09:57:11 -0700 | [diff] [blame] | 115 | //Metadata constant |
| 116 | Metadata = "metadata" |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 117 | //TunnelID constant |
| 118 | TunnelID = "tunnel_id" |
David K. Bainbridge | 82efc49 | 2019-09-04 09:57:11 -0700 | [diff] [blame] | 119 | //Output constant |
| 120 | Output = "output" |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 121 | //GroupID constant |
| 122 | GroupID = "group_id" |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 123 | // Actions |
| 124 | |
| 125 | //PopVlan constant |
| 126 | PopVlan = "pop_vlan" |
| 127 | //PushVlan constant |
| 128 | PushVlan = "push_vlan" |
| 129 | //TrapToHost constant |
| 130 | TrapToHost = "trap_to_host" |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 131 | //MaxMeterBand constant |
| 132 | MaxMeterBand = 2 |
| 133 | //VlanPCPMask contant |
| 134 | VlanPCPMask = 0xFF |
| 135 | //VlanvIDMask constant |
| 136 | VlanvIDMask = 0xFFF |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 137 | //IntfID constant |
| 138 | IntfID = "intfId" |
| 139 | //OnuID constant |
| 140 | OnuID = "onuId" |
| 141 | //UniID constant |
| 142 | UniID = "uniId" |
| 143 | //PortNo constant |
| 144 | PortNo = "portNo" |
| 145 | //AllocID constant |
| 146 | AllocID = "allocId" |
Gamze Abaka | fcbd6e7 | 2020-12-17 13:25:16 +0000 | [diff] [blame] | 147 | //GemID constant |
| 148 | GemID = "gemId" |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 149 | |
| 150 | //NoneOnuID constant |
| 151 | NoneOnuID = -1 |
| 152 | //NoneUniID constant |
| 153 | NoneUniID = -1 |
Matteo Scandolo | 738c52a | 2020-08-03 11:14:22 -0700 | [diff] [blame] | 154 | |
Girish Gowdra | fb3d610 | 2020-10-16 16:32:36 -0700 | [diff] [blame] | 155 | // Max number of flows that can be queued per ONU |
| 156 | maxConcurrentFlowsPerOnu = 20 |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 157 | |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 158 | bitMapPrefix = "0b" |
| 159 | pbit1 = '1' |
| 160 | ) |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 161 | |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 162 | type schedQueue struct { |
| 163 | direction tp_pb.Direction |
| 164 | intfID uint32 |
| 165 | onuID uint32 |
| 166 | uniID uint32 |
| 167 | tpID uint32 |
| 168 | uniPort uint32 |
Takahiro Suzuki | 2ba0e0b | 2020-06-05 14:23:03 -0700 | [diff] [blame] | 169 | tpInst interface{} |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 170 | meterID uint32 |
khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 171 | flowMetadata *ofp.FlowMetadata |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 172 | } |
| 173 | |
Gamze Abaka | 7650be6 | 2021-02-26 10:50:36 +0000 | [diff] [blame] | 174 | type flowContext struct { |
| 175 | intfID uint32 |
| 176 | onuID uint32 |
| 177 | uniID uint32 |
| 178 | portNo uint32 |
| 179 | classifier map[string]interface{} |
| 180 | action map[string]interface{} |
| 181 | logicalFlow *ofp.OfpFlowStats |
| 182 | allocID uint32 |
| 183 | gemPortID uint32 |
| 184 | tpID uint32 |
| 185 | pbitToGem map[uint32]uint32 |
| 186 | gemToAes map[uint32]bool |
| 187 | } |
| 188 | |
Girish Gowdra | fb3d610 | 2020-10-16 16:32:36 -0700 | [diff] [blame] | 189 | // This control block is created per flow add/remove and pushed on the incomingFlows channel slice |
| 190 | // The flowControlBlock is then picked by the perOnuFlowHandlerRoutine for further processing. |
| 191 | // There is on perOnuFlowHandlerRoutine routine per ONU that constantly monitors for any incoming |
| 192 | // flow and processes it serially |
| 193 | type flowControlBlock struct { |
khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 194 | ctx context.Context // Flow handler context |
| 195 | addFlow bool // if true flow to be added, else removed |
| 196 | flow *ofp.OfpFlowStats // Flow message |
| 197 | flowMetadata *ofp.FlowMetadata // FlowMetadata that contains flow meter information. This can be nil for Flow remove |
| 198 | errChan *chan error // channel to report the Flow handling error |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 199 | } |
| 200 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 201 | //OpenOltFlowMgr creates the Structure of OpenOltFlowMgr obj |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 202 | type OpenOltFlowMgr struct { |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 203 | ponPortIdx uint32 // Pon Port this FlowManager is responsible for |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 204 | techprofile tp.TechProfileIf |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 205 | deviceHandler *DeviceHandler |
| 206 | grpMgr *OpenOltGroupMgr |
| 207 | resourceMgr *rsrcMgr.OpenOltResourceMgr |
| 208 | |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 209 | packetInGemPort map[rsrcMgr.PacketInInfoKey]uint32 //packet in gem port local cache |
| 210 | packetInGemPortLock sync.RWMutex |
| 211 | |
Girish Gowdra | fb3d610 | 2020-10-16 16:32:36 -0700 | [diff] [blame] | 212 | // Slice of channels. Each channel in slice, index by ONU ID, queues flows per ONU. |
| 213 | // A go routine per ONU, waits on the unique channel (indexed by ONU ID) for incoming flows (add/remove) |
Girish Gowdra | 4736e5c | 2021-08-25 15:19:10 -0700 | [diff] [blame] | 214 | incomingFlows []chan flowControlBlock |
| 215 | stopFlowHandlerRoutine []chan bool |
| 216 | flowHandlerRoutineActive []bool |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 217 | } |
| 218 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 219 | //NewFlowManager creates OpenOltFlowMgr object and initializes the parameters |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 220 | func NewFlowManager(ctx context.Context, dh *DeviceHandler, rMgr *rsrcMgr.OpenOltResourceMgr, grpMgr *OpenOltGroupMgr, ponPortIdx uint32) *OpenOltFlowMgr { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 221 | logger.Infow(ctx, "initializing-flow-manager", log.Fields{"device-id": dh.device.Id}) |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 222 | var flowMgr OpenOltFlowMgr |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 223 | var err error |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 224 | |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 225 | flowMgr.deviceHandler = dh |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 226 | flowMgr.ponPortIdx = ponPortIdx |
Girish Gowdra | 9602eb4 | 2020-09-09 15:50:39 -0700 | [diff] [blame] | 227 | flowMgr.grpMgr = grpMgr |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 228 | flowMgr.resourceMgr = rMgr |
yasin sapli | d056627 | 2021-12-21 09:10:30 +0000 | [diff] [blame] | 229 | // dh.totalPonPorts is reserved for NNI trap flows. It doesn't need a tech profile |
| 230 | if ponPortIdx != dh.totalPonPorts { |
| 231 | if err = flowMgr.populateTechProfileForCurrentPonPort(ctx); err != nil { |
| 232 | logger.Errorw(ctx, "error-while-populating-tech-profile-mgr", log.Fields{"err": err}) |
| 233 | return nil |
| 234 | } |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 235 | } |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 236 | flowMgr.packetInGemPort = make(map[rsrcMgr.PacketInInfoKey]uint32) |
Girish Gowdra | fb3d610 | 2020-10-16 16:32:36 -0700 | [diff] [blame] | 237 | |
| 238 | // Create a slice of buffered channels for handling concurrent flows per ONU. |
| 239 | // The additional entry (+1) is to handle the NNI trap flows on a separate channel from individual ONUs channel |
Mahir Gunyel | 85f61c1 | 2021-10-06 11:53:45 -0700 | [diff] [blame] | 240 | flowMgr.incomingFlows = make([]chan flowControlBlock, plt.MaxOnusPerPon+1) |
| 241 | flowMgr.stopFlowHandlerRoutine = make([]chan bool, plt.MaxOnusPerPon+1) |
| 242 | flowMgr.flowHandlerRoutineActive = make([]bool, plt.MaxOnusPerPon+1) |
Girish Gowdra | fb3d610 | 2020-10-16 16:32:36 -0700 | [diff] [blame] | 243 | for i := range flowMgr.incomingFlows { |
| 244 | flowMgr.incomingFlows[i] = make(chan flowControlBlock, maxConcurrentFlowsPerOnu) |
Girish Gowdra | ae56c72 | 2021-11-22 14:31:11 -0800 | [diff] [blame] | 245 | flowMgr.stopFlowHandlerRoutine[i] = make(chan bool) |
Girish Gowdra | fb3d610 | 2020-10-16 16:32:36 -0700 | [diff] [blame] | 246 | // Spin up a go routine to handling incoming flows (add/remove). |
| 247 | // There will be on go routine per ONU. |
| 248 | // This routine will be blocked on the flowMgr.incomingFlows[onu-id] channel for incoming flows. |
Girish Gowdra | 4736e5c | 2021-08-25 15:19:10 -0700 | [diff] [blame] | 249 | flowMgr.flowHandlerRoutineActive[i] = true |
| 250 | go flowMgr.perOnuFlowHandlerRoutine(i, flowMgr.incomingFlows[i], flowMgr.stopFlowHandlerRoutine[i]) |
Girish Gowdra | fb3d610 | 2020-10-16 16:32:36 -0700 | [diff] [blame] | 251 | } |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 252 | |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 253 | //load interface to multicast queue map from kv store |
Girish Gowdra | 9602eb4 | 2020-09-09 15:50:39 -0700 | [diff] [blame] | 254 | flowMgr.grpMgr.LoadInterfaceToMulticastQueueMap(ctx) |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 255 | logger.Info(ctx, "initialization-of-flow-manager-success") |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 256 | return &flowMgr |
| 257 | } |
| 258 | |
Kent Hagerman | e6ff101 | 2020-07-14 15:07:53 -0400 | [diff] [blame] | 259 | func (f *OpenOltFlowMgr) registerFlow(ctx context.Context, flowFromCore *ofp.OfpFlowStats, deviceFlow *openoltpb2.Flow) error { |
yasin sapli | d056627 | 2021-12-21 09:10:30 +0000 | [diff] [blame] | 260 | // In case of nni trap flow |
| 261 | if deviceFlow.AccessIntfId == -1 { |
yasin sapli | bddc2d7 | 2022-02-08 13:10:17 +0000 | [diff] [blame] | 262 | return f.resourceMgr.RegisterFlowIDForGem(ctx, uint32(deviceFlow.AccessIntfId), flowFromCore) |
yasin sapli | d056627 | 2021-12-21 09:10:30 +0000 | [diff] [blame] | 263 | } |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 264 | if !deviceFlow.ReplicateFlow && deviceFlow.GemportId > 0 { |
| 265 | // Flow is not replicated in this case, we need to register the flow for a single gem-port |
yasin sapli | bddc2d7 | 2022-02-08 13:10:17 +0000 | [diff] [blame] | 266 | return f.resourceMgr.RegisterFlowIDForGem(ctx, uint32(deviceFlow.GemportId), flowFromCore) |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 267 | } else if deviceFlow.ReplicateFlow && len(deviceFlow.PbitToGemport) > 0 { |
| 268 | // Flow is replicated in this case. We need to register the flow for all the gem-ports it is replicated to. |
| 269 | for _, gemPort := range deviceFlow.PbitToGemport { |
yasin sapli | bddc2d7 | 2022-02-08 13:10:17 +0000 | [diff] [blame] | 270 | if err := f.resourceMgr.RegisterFlowIDForGem(ctx, gemPort, flowFromCore); err != nil { |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 271 | return err |
| 272 | } |
Matteo Scandolo | 738c52a | 2020-08-03 11:14:22 -0700 | [diff] [blame] | 273 | } |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 274 | } |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 275 | return nil |
| 276 | } |
| 277 | |
Girish Gowdra | 9602eb4 | 2020-09-09 15:50:39 -0700 | [diff] [blame] | 278 | func (f *OpenOltFlowMgr) processAddFlow(ctx context.Context, intfID uint32, onuID uint32, uniID uint32, portNo uint32, |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 279 | classifierInfo map[string]interface{}, actionInfo map[string]interface{}, flow *ofp.OfpFlowStats, TpID uint32, |
khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 280 | UsMeterID uint32, DsMeterID uint32, flowMetadata *ofp.FlowMetadata) error { |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 281 | var allocID uint32 |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 282 | var gemPorts []uint32 |
Takahiro Suzuki | 2ba0e0b | 2020-06-05 14:23:03 -0700 | [diff] [blame] | 283 | var TpInst interface{} |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 284 | |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 285 | logger.Infow(ctx, "dividing-flow", log.Fields{ |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 286 | "device-id": f.deviceHandler.device.Id, |
| 287 | "intf-id": intfID, |
| 288 | "onu-id": onuID, |
| 289 | "uni-id": uniID, |
| 290 | "port-no": portNo, |
Matteo Scandolo | d625b4c | 2020-04-02 16:16:01 -0700 | [diff] [blame] | 291 | "classifier": classifierInfo, |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 292 | "action": actionInfo, |
| 293 | "usmeter-iD": UsMeterID, |
| 294 | "dsmeter-iD": DsMeterID, |
| 295 | "tp-id": TpID}) |
Matt Jeanneret | 7719961 | 2019-07-26 18:08:35 -0400 | [diff] [blame] | 296 | // only create tcont/gemports if there is actually an onu id. otherwise BAL throws an error. Usually this |
| 297 | // is because the flow is an NNI flow and there would be no onu resources associated with it |
| 298 | // TODO: properly deal with NNI flows |
Kent Hagerman | e6ff101 | 2020-07-14 15:07:53 -0400 | [diff] [blame] | 299 | if onuID == 0 { |
Andrea Campanella | bfe0843 | 2020-09-11 17:07:03 +0200 | [diff] [blame] | 300 | cause := "no-onu-id-for-flow" |
| 301 | fields := log.Fields{ |
| 302 | "onu": onuID, |
| 303 | "port-no": portNo, |
| 304 | "classifer": classifierInfo, |
| 305 | "action": actionInfo, |
| 306 | "device-id": f.deviceHandler.device.Id} |
| 307 | logger.Errorw(ctx, cause, fields) |
| 308 | return olterrors.NewErrNotFound(cause, fields, nil) |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 309 | } |
| 310 | |
Matteo Scandolo | d625b4c | 2020-04-02 16:16:01 -0700 | [diff] [blame] | 311 | uni := getUniPortPath(f.deviceHandler.device.Id, intfID, int32(onuID), int32(uniID)) |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 312 | logger.Debugw(ctx, "uni-port-path", log.Fields{ |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 313 | "uni": uni, |
| 314 | "device-id": f.deviceHandler.device.Id}) |
Girish Gowdra | 3d63303 | 2019-12-10 16:37:05 +0530 | [diff] [blame] | 315 | |
Girish Gowdra | fb3d610 | 2020-10-16 16:32:36 -0700 | [diff] [blame] | 316 | logger.Debugw(ctx, "dividing-flow-create-tcont-gem-ports", log.Fields{ |
| 317 | "device-id": f.deviceHandler.device.Id, |
| 318 | "intf-id": intfID, |
| 319 | "onu-id": onuID, |
| 320 | "uni-id": uniID, |
| 321 | "port-no": portNo, |
| 322 | "classifier": classifierInfo, |
| 323 | "action": actionInfo, |
| 324 | "usmeter-id": UsMeterID, |
| 325 | "dsmeter-id": DsMeterID, |
| 326 | "tp-id": TpID}) |
| 327 | allocID, gemPorts, TpInst = f.createTcontGemports(ctx, intfID, onuID, uniID, uni, portNo, TpID, UsMeterID, DsMeterID, flowMetadata) |
| 328 | if allocID == 0 || gemPorts == nil || TpInst == nil { |
| 329 | logger.Error(ctx, "alloc-id-gem-ports-tp-unavailable") |
| 330 | return olterrors.NewErrNotFound( |
| 331 | "alloc-id-gem-ports-tp-unavailable", |
| 332 | nil, nil) |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 333 | } |
Girish Gowdra | fb3d610 | 2020-10-16 16:32:36 -0700 | [diff] [blame] | 334 | args := make(map[string]uint32) |
| 335 | args[IntfID] = intfID |
| 336 | args[OnuID] = onuID |
| 337 | args[UniID] = uniID |
| 338 | args[PortNo] = portNo |
| 339 | args[AllocID] = allocID |
| 340 | |
| 341 | /* Flows can be added specific to gemport if p-bits are received. |
| 342 | * If no pbit mentioned then adding flows for all gemports |
| 343 | */ |
Gamze Abaka | 6d0a64f | 2021-11-18 08:08:33 +0000 | [diff] [blame] | 344 | return f.checkAndAddFlow(ctx, args, classifierInfo, actionInfo, flow, TpInst, gemPorts, TpID, uni) |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 345 | } |
| 346 | |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 347 | // CreateSchedulerQueues creates traffic schedulers on the device with the given scheduler configuration and traffic shaping info |
Girish Gowdra | f3728b1 | 2022-02-02 21:46:51 -0800 | [diff] [blame] | 348 | // nolint: gocyclo |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 349 | func (f *OpenOltFlowMgr) CreateSchedulerQueues(ctx context.Context, sq schedQueue) error { |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 350 | |
Girish Gowdra | f3728b1 | 2022-02-02 21:46:51 -0800 | [diff] [blame] | 351 | logger.Infow(ctx, "CreateSchedulerQueues", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 352 | log.Fields{"dir": sq.direction, |
| 353 | "intf-id": sq.intfID, |
| 354 | "onu-id": sq.onuID, |
| 355 | "uni-id": sq.uniID, |
| 356 | "tp-id": sq.tpID, |
| 357 | "meter-id": sq.meterID, |
| 358 | "tp-inst": sq.tpInst, |
| 359 | "flowmetadata": sq.flowMetadata, |
| 360 | "device-id": f.deviceHandler.device.Id}) |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 361 | |
Girish Gowdra | 6071f38 | 2021-12-14 12:52:04 +0530 | [diff] [blame] | 362 | direction, err := verifyMeterIDAndGetDirection(sq.meterID, sq.direction) |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 363 | if err != nil { |
| 364 | return err |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 365 | } |
| 366 | |
Girish Gowdra | f3728b1 | 2022-02-02 21:46:51 -0800 | [diff] [blame] | 367 | var TrafficShaping *tp_pb.TrafficShapingInfo |
| 368 | if sq.flowMetadata == nil || len(sq.flowMetadata.Meters) != 1 { |
| 369 | return olterrors.NewErrInvalidValue(log.Fields{ |
| 370 | "reason": "invalid-meter-config", |
| 371 | "meter-id": sq.meterID, |
| 372 | "device-id": f.deviceHandler.device.Id}, nil) |
| 373 | } |
| 374 | |
| 375 | if TrafficShaping, err = meters.GetTrafficShapingInfo(ctx, sq.flowMetadata.Meters[0]); err != nil { |
| 376 | return olterrors.NewErrInvalidValue(log.Fields{ |
| 377 | "reason": "invalid-meter-config", |
| 378 | "meter-id": sq.meterID, |
| 379 | "device-id": f.deviceHandler.device.Id}, nil) |
| 380 | } |
| 381 | |
| 382 | var SchedCfg *tp_pb.SchedulerConfig |
| 383 | if sq.direction == tp_pb.Direction_UPSTREAM { |
| 384 | SchedCfg = f.techprofile.GetUsScheduler(sq.tpInst.(*tp_pb.TechProfileInstance)) |
| 385 | } else if sq.direction == tp_pb.Direction_DOWNSTREAM { |
| 386 | SchedCfg = f.techprofile.GetDsScheduler(sq.tpInst.(*tp_pb.TechProfileInstance)) |
| 387 | } |
| 388 | TrafficSched := []*tp_pb.TrafficScheduler{f.techprofile.GetTrafficScheduler(sq.tpInst.(*tp_pb.TechProfileInstance), SchedCfg, TrafficShaping)} |
| 389 | TrafficSched[0].TechProfileId = sq.tpID |
| 390 | |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 391 | /* Lets make a simple assumption that if the meter-id is present on the KV store, |
| 392 | * then the scheduler and queues configuration is applied on the OLT device |
| 393 | * in the given direction. |
| 394 | */ |
yasin sapli | bddc2d7 | 2022-02-08 13:10:17 +0000 | [diff] [blame] | 395 | meterInfo, err := f.resourceMgr.GetMeterInfoForOnu(ctx, direction, sq.onuID, sq.uniID, sq.tpID) |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 396 | if err != nil { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 397 | return olterrors.NewErrNotFound("meter", |
| 398 | log.Fields{"intf-id": sq.intfID, |
| 399 | "onu-id": sq.onuID, |
| 400 | "uni-id": sq.uniID, |
| 401 | "device-id": f.deviceHandler.device.Id}, err) |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 402 | } |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 403 | |
Girish Gowdra | f3728b1 | 2022-02-02 21:46:51 -0800 | [diff] [blame] | 404 | // update reference count and return if the meter was already installed before |
Girish Gowdra | 6071f38 | 2021-12-14 12:52:04 +0530 | [diff] [blame] | 405 | if meterInfo != nil && meterInfo.MeterID == sq.meterID { |
Girish Gowdra | f3728b1 | 2022-02-02 21:46:51 -0800 | [diff] [blame] | 406 | logger.Infow(ctx, "scheduler-already-created-for-direction", |
Girish Gowdra | 6071f38 | 2021-12-14 12:52:04 +0530 | [diff] [blame] | 407 | log.Fields{"device-id": f.deviceHandler.device.Id, "direction": direction, "meter-id": sq.meterID}) |
yasin sapli | bddc2d7 | 2022-02-08 13:10:17 +0000 | [diff] [blame] | 408 | if err = f.resourceMgr.HandleMeterInfoRefCntUpdate(ctx, direction, sq.onuID, sq.uniID, sq.tpID, true); err != nil { |
Girish Gowdra | f3728b1 | 2022-02-02 21:46:51 -0800 | [diff] [blame] | 409 | return err |
| 410 | } |
| 411 | |
| 412 | if allocExists := f.isAllocUsedByAnotherUNI(ctx, sq); allocExists { |
| 413 | // Alloc object was already created as part of flow setup on another uni of the onu for the same service. |
| 414 | // Just create gem ports and traffic queues on the current uni for the given service |
| 415 | logger.Infow(ctx, "alloc in use on another uni, schedulers already created, creating queues only", |
| 416 | log.Fields{"intf-id": sq.intfID, |
| 417 | "onu-id": sq.onuID, |
| 418 | "uni-id": sq.uniID, |
| 419 | "tp-id": sq.tpID, |
| 420 | "device-id": f.deviceHandler.device.Id}) |
| 421 | // The upstream scheduler is already created. We only need to create the queues |
| 422 | // If there are multiple upstream flows on a given uni, then it is possible that |
| 423 | // we call pushTrafficQueues multiple times, but that is OK as BAL returns OK. |
| 424 | // TODO: Find better mechanism to not duplicate request. |
| 425 | if err = f.pushTrafficQueues(ctx, sq, TrafficSched); err != nil { |
| 426 | return olterrors.NewErrAdapter("failure-pushing-traffic-queues-to-device", |
| 427 | log.Fields{"intf-id": sq.intfID, |
| 428 | "direction": sq.direction, |
| 429 | "device-id": f.deviceHandler.device.Id}, err) |
| 430 | } |
| 431 | } else { |
| 432 | logger.Infow(ctx, "alloc not in use on another uni, only meter ref cnt updated", |
| 433 | log.Fields{"intf-id": sq.intfID, |
| 434 | "onu-id": sq.onuID, |
| 435 | "uni-id": sq.uniID, |
| 436 | "tp-id": sq.tpID, |
| 437 | "device-id": f.deviceHandler.device.Id}) |
| 438 | } |
| 439 | return err |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 440 | } |
Girish Kumar | 8f73fe0 | 2019-12-09 13:19:37 +0000 | [diff] [blame] | 441 | |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 442 | logger.Debugw(ctx, "meter-does-not-exist-creating-new", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 443 | log.Fields{ |
| 444 | "meter-id": sq.meterID, |
Girish Gowdra | 6071f38 | 2021-12-14 12:52:04 +0530 | [diff] [blame] | 445 | "direction": direction, |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 446 | "device-id": f.deviceHandler.device.Id}) |
Girish Kumar | 8f73fe0 | 2019-12-09 13:19:37 +0000 | [diff] [blame] | 447 | |
Girish Gowdra | a482f27 | 2021-03-24 23:04:19 -0700 | [diff] [blame] | 448 | found := false |
| 449 | meterInfo = &rsrcMgr.MeterInfo{} |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 450 | if sq.flowMetadata != nil { |
| 451 | for _, meter := range sq.flowMetadata.Meters { |
| 452 | if sq.meterID == meter.MeterId { |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 453 | meterInfo.MeterID = meter.MeterId |
Girish Gowdra | a482f27 | 2021-03-24 23:04:19 -0700 | [diff] [blame] | 454 | meterInfo.RefCnt = 1 // initialize it to 1, since this is the first flow that referenced the meter id. |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 455 | logger.Debugw(ctx, "found-meter-config-from-flowmetadata", |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 456 | log.Fields{"meter": meter, |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 457 | "device-id": f.deviceHandler.device.Id}) |
Girish Gowdra | a482f27 | 2021-03-24 23:04:19 -0700 | [diff] [blame] | 458 | found = true |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 459 | break |
| 460 | } |
| 461 | } |
| 462 | } else { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 463 | logger.Errorw(ctx, "flow-metadata-not-present-in-flow", log.Fields{"device-id": f.deviceHandler.device.Id}) |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 464 | } |
Girish Gowdra | a482f27 | 2021-03-24 23:04:19 -0700 | [diff] [blame] | 465 | if !found { |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 466 | return olterrors.NewErrNotFound("meterbands", log.Fields{ |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 467 | "reason": "Could-not-get-meterbands-from-flowMetadata", |
| 468 | "flow-metadata": sq.flowMetadata, |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 469 | "meter-id": sq.meterID, |
| 470 | "device-id": f.deviceHandler.device.Id}, nil) |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 471 | } |
Gamze Abaka | 0117442 | 2021-03-10 06:55:27 +0000 | [diff] [blame] | 472 | |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 473 | if err := f.pushSchedulerQueuesToDevice(ctx, sq, TrafficSched); err != nil { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 474 | return olterrors.NewErrAdapter("failure-pushing-traffic-scheduler-and-queues-to-device", |
| 475 | log.Fields{"intf-id": sq.intfID, |
| 476 | "direction": sq.direction, |
| 477 | "device-id": f.deviceHandler.device.Id}, err) |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 478 | } |
| 479 | |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 480 | /* After we successfully applied the scheduler configuration on the OLT device, |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 481 | * store the meter id on the KV store, for further reference. |
| 482 | */ |
yasin sapli | bddc2d7 | 2022-02-08 13:10:17 +0000 | [diff] [blame] | 483 | if err := f.resourceMgr.StoreMeterInfoForOnu(ctx, direction, sq.onuID, sq.uniID, sq.tpID, meterInfo); err != nil { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 484 | return olterrors.NewErrAdapter("failed-updating-meter-id", |
| 485 | log.Fields{"onu-id": sq.onuID, |
| 486 | "meter-id": sq.meterID, |
| 487 | "device-id": f.deviceHandler.device.Id}, err) |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 488 | } |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 489 | logger.Infow(ctx, "updated-meter-info-into-kv-store-successfully", |
Girish Gowdra | 6071f38 | 2021-12-14 12:52:04 +0530 | [diff] [blame] | 490 | log.Fields{"direction": direction, |
Girish Gowdra | a482f27 | 2021-03-24 23:04:19 -0700 | [diff] [blame] | 491 | "meter-info": meterInfo, |
| 492 | "device-id": f.deviceHandler.device.Id}) |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 493 | return nil |
| 494 | } |
| 495 | |
Girish Gowdra | f3728b1 | 2022-02-02 21:46:51 -0800 | [diff] [blame] | 496 | func (f *OpenOltFlowMgr) pushTrafficQueues(ctx context.Context, sq schedQueue, TrafficSched []*tp_pb.TrafficScheduler) error { |
| 497 | trafficQueues, err := f.techprofile.GetTrafficQueues(ctx, sq.tpInst.(*tp_pb.TechProfileInstance), sq.direction) |
| 498 | if err != nil { |
| 499 | return olterrors.NewErrAdapter("unable-to-construct-traffic-queue-configuration", |
| 500 | log.Fields{"intf-id": sq.intfID, |
| 501 | "direction": sq.direction, |
| 502 | "device-id": f.deviceHandler.device.Id}, err) |
| 503 | } |
| 504 | logger.Debugw(ctx, "sending-traffic-queues-create-to-device", |
| 505 | log.Fields{"direction": sq.direction, |
| 506 | "traffic-queues": trafficQueues, |
| 507 | "device-id": f.deviceHandler.device.Id}) |
| 508 | queues := &tp_pb.TrafficQueues{IntfId: sq.intfID, OnuId: sq.onuID, |
| 509 | UniId: sq.uniID, PortNo: sq.uniPort, |
| 510 | TrafficQueues: trafficQueues, |
| 511 | TechProfileId: TrafficSched[0].TechProfileId} |
| 512 | if _, err := f.deviceHandler.Client.CreateTrafficQueues(ctx, queues); err != nil { |
| 513 | if len(queues.TrafficQueues) > 1 { |
| 514 | logger.Debug(ctx, "removing-queues-for-1tcont-multi-gem", log.Fields{"intfID": sq.intfID, "onuID": sq.onuID, "dir": sq.direction}) |
| 515 | _, _ = f.deviceHandler.Client.RemoveTrafficQueues(ctx, queues) |
| 516 | } |
| 517 | return olterrors.NewErrAdapter("failed-to-create-traffic-queues-in-device", log.Fields{"traffic-queues": trafficQueues}, err) |
| 518 | } |
| 519 | return err |
| 520 | } |
| 521 | |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 522 | func (f *OpenOltFlowMgr) pushSchedulerQueuesToDevice(ctx context.Context, sq schedQueue, TrafficSched []*tp_pb.TrafficScheduler) error { |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 523 | trafficQueues, err := f.techprofile.GetTrafficQueues(ctx, sq.tpInst.(*tp_pb.TechProfileInstance), sq.direction) |
Girish Kumar | 8f73fe0 | 2019-12-09 13:19:37 +0000 | [diff] [blame] | 524 | |
| 525 | if err != nil { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 526 | return olterrors.NewErrAdapter("unable-to-construct-traffic-queue-configuration", |
| 527 | log.Fields{"intf-id": sq.intfID, |
| 528 | "direction": sq.direction, |
| 529 | "device-id": f.deviceHandler.device.Id}, err) |
Girish Kumar | 8f73fe0 | 2019-12-09 13:19:37 +0000 | [diff] [blame] | 530 | } |
| 531 | |
Gamze Abaka | cb0e677 | 2021-06-10 08:32:12 +0000 | [diff] [blame] | 532 | if allocExists := f.isAllocUsedByAnotherUNI(ctx, sq); !allocExists { |
| 533 | logger.Debugw(ctx, "sending-traffic-scheduler-create-to-device", |
| 534 | log.Fields{ |
| 535 | "direction": sq.direction, |
| 536 | "TrafficScheds": TrafficSched, |
| 537 | "device-id": f.deviceHandler.device.Id, |
| 538 | "intfID": sq.intfID, |
| 539 | "onuID": sq.onuID, |
| 540 | "uniID": sq.uniID}) |
| 541 | if _, err := f.deviceHandler.Client.CreateTrafficSchedulers(ctx, &tp_pb.TrafficSchedulers{ |
| 542 | IntfId: sq.intfID, OnuId: sq.onuID, |
| 543 | UniId: sq.uniID, PortNo: sq.uniPort, |
| 544 | TrafficScheds: TrafficSched}); err != nil { |
| 545 | return olterrors.NewErrAdapter("failed-to-create-traffic-schedulers-in-device", log.Fields{"TrafficScheds": TrafficSched}, err) |
| 546 | } |
| 547 | logger.Infow(ctx, "successfully-created-traffic-schedulers", log.Fields{ |
| 548 | "direction": sq.direction, |
| 549 | "traffic-queues": trafficQueues, |
| 550 | "device-id": f.deviceHandler.device.Id}) |
Girish Kumar | 8f73fe0 | 2019-12-09 13:19:37 +0000 | [diff] [blame] | 551 | } |
| 552 | |
| 553 | // On receiving the CreateTrafficQueues request, the driver should create corresponding |
| 554 | // downstream queues. |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 555 | logger.Debugw(ctx, "sending-traffic-queues-create-to-device", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 556 | log.Fields{"direction": sq.direction, |
| 557 | "traffic-queues": trafficQueues, |
| 558 | "device-id": f.deviceHandler.device.Id}) |
Gamze Abaka | 411ef2f | 2021-11-22 08:38:08 +0000 | [diff] [blame] | 559 | queues := &tp_pb.TrafficQueues{IntfId: sq.intfID, OnuId: sq.onuID, |
| 560 | UniId: sq.uniID, PortNo: sq.uniPort, |
| 561 | TrafficQueues: trafficQueues, |
| 562 | TechProfileId: TrafficSched[0].TechProfileId} |
| 563 | if _, err := f.deviceHandler.Client.CreateTrafficQueues(ctx, queues); err != nil { |
| 564 | if len(queues.TrafficQueues) > 1 { |
| 565 | logger.Debug(ctx, "removing-queues-for-1tcont-multi-gem", log.Fields{"intfID": sq.intfID, "onuID": sq.onuID, "dir": sq.direction}) |
| 566 | _, _ = f.deviceHandler.Client.RemoveTrafficQueues(ctx, queues) |
| 567 | } |
| 568 | f.revertScheduler(ctx, sq, TrafficSched) |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 569 | return olterrors.NewErrAdapter("failed-to-create-traffic-queues-in-device", log.Fields{"traffic-queues": trafficQueues}, err) |
Girish Kumar | 8f73fe0 | 2019-12-09 13:19:37 +0000 | [diff] [blame] | 570 | } |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 571 | logger.Infow(ctx, "successfully-created-traffic-schedulers", log.Fields{ |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 572 | "direction": sq.direction, |
| 573 | "traffic-queues": trafficQueues, |
| 574 | "device-id": f.deviceHandler.device.Id}) |
Girish Kumar | 8f73fe0 | 2019-12-09 13:19:37 +0000 | [diff] [blame] | 575 | |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 576 | if sq.direction == tp_pb.Direction_DOWNSTREAM { |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 577 | multicastTrafficQueues := f.techprofile.GetMulticastTrafficQueues(ctx, sq.tpInst.(*tp_pb.TechProfileInstance)) |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 578 | if len(multicastTrafficQueues) > 0 { |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 579 | if _, present := f.grpMgr.GetInterfaceToMcastQueueMap(sq.intfID); !present { //assumed that there is only one queue per PON for the multicast service |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 580 | //the default queue with multicastQueuePerPonPort.Priority per a pon interface is used for multicast service |
| 581 | //just put it in interfaceToMcastQueueMap to use for building group members |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 582 | logger.Debugw(ctx, "multicast-traffic-queues", log.Fields{"device-id": f.deviceHandler.device.Id}) |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 583 | multicastQueuePerPonPort := multicastTrafficQueues[0] |
Girish Gowdra | 9602eb4 | 2020-09-09 15:50:39 -0700 | [diff] [blame] | 584 | val := &QueueInfoBrief{ |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 585 | gemPortID: multicastQueuePerPonPort.GemportId, |
| 586 | servicePriority: multicastQueuePerPonPort.Priority, |
| 587 | } |
Girish Gowdra | 9602eb4 | 2020-09-09 15:50:39 -0700 | [diff] [blame] | 588 | f.grpMgr.UpdateInterfaceToMcastQueueMap(sq.intfID, val) |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 589 | //also store the queue info in kv store |
yasin sapli | bddc2d7 | 2022-02-08 13:10:17 +0000 | [diff] [blame] | 590 | if err := f.resourceMgr.AddMcastQueueForIntf(ctx, multicastQueuePerPonPort.GemportId, multicastQueuePerPonPort.Priority); err != nil { |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 591 | logger.Errorw(ctx, "failed-to-add-mcast-queue", log.Fields{"err": err}) |
Kent Hagerman | e6ff101 | 2020-07-14 15:07:53 -0400 | [diff] [blame] | 592 | return err |
| 593 | } |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 594 | |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 595 | logger.Infow(ctx, "multicast-queues-successfully-updated", log.Fields{"device-id": f.deviceHandler.device.Id}) |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 596 | } |
| 597 | } |
| 598 | } |
Girish Kumar | 8f73fe0 | 2019-12-09 13:19:37 +0000 | [diff] [blame] | 599 | return nil |
| 600 | } |
| 601 | |
Girish Gowdra | f3728b1 | 2022-02-02 21:46:51 -0800 | [diff] [blame] | 602 | // RemoveQueues removes the traffic queues from the device based on the given schedQueue info |
| 603 | func (f *OpenOltFlowMgr) RemoveQueues(ctx context.Context, sq schedQueue) error { |
| 604 | var err error |
| 605 | logger.Infow(ctx, "removing-queue-in-olt", |
| 606 | log.Fields{ |
| 607 | "direction": sq.direction, |
| 608 | "intf-id": sq.intfID, |
| 609 | "onu-id": sq.onuID, |
| 610 | "uni-id": sq.uniID, |
| 611 | "uni-port": sq.uniPort, |
| 612 | "device-id": f.deviceHandler.device.Id}) |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 613 | |
Girish Gowdra | f3728b1 | 2022-02-02 21:46:51 -0800 | [diff] [blame] | 614 | TrafficQueues, err := f.techprofile.GetTrafficQueues(ctx, sq.tpInst.(*tp_pb.TechProfileInstance), sq.direction) |
| 615 | if err != nil { |
| 616 | return olterrors.NewErrAdapter("unable-to-construct-traffic-queue-configuration", |
| 617 | log.Fields{ |
| 618 | "intf-id": sq.intfID, |
| 619 | "direction": sq.direction, |
| 620 | "device-id": f.deviceHandler.device.Id}, err) |
| 621 | } |
| 622 | |
| 623 | if _, err = f.deviceHandler.Client.RemoveTrafficQueues(ctx, |
| 624 | &tp_pb.TrafficQueues{IntfId: sq.intfID, OnuId: sq.onuID, |
| 625 | UniId: sq.uniID, PortNo: sq.uniPort, |
| 626 | TrafficQueues: TrafficQueues, |
| 627 | TechProfileId: sq.tpID}); err != nil { |
| 628 | return olterrors.NewErrAdapter("unable-to-remove-traffic-queues-from-device", |
| 629 | log.Fields{ |
| 630 | "intf-id": sq.intfID, |
| 631 | "traffic-queues": TrafficQueues, |
| 632 | "device-id": f.deviceHandler.device.Id}, err) |
| 633 | } |
| 634 | logger.Infow(ctx, "removed-traffic-queues-successfully", log.Fields{"device-id": f.deviceHandler.device.Id, "trafficQueues": TrafficQueues}) |
| 635 | |
| 636 | return err |
| 637 | } |
| 638 | |
| 639 | // RemoveScheduler removes the traffic scheduler from the device based on the given schedQueue info |
| 640 | func (f *OpenOltFlowMgr) RemoveScheduler(ctx context.Context, sq schedQueue) error { |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 641 | var Direction string |
| 642 | var SchedCfg *tp_pb.SchedulerConfig |
| 643 | var err error |
Girish Gowdra | f3728b1 | 2022-02-02 21:46:51 -0800 | [diff] [blame] | 644 | logger.Infow(ctx, "removing-scheduler-in-olt", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 645 | log.Fields{ |
| 646 | "direction": sq.direction, |
| 647 | "intf-id": sq.intfID, |
| 648 | "onu-id": sq.onuID, |
| 649 | "uni-id": sq.uniID, |
| 650 | "uni-port": sq.uniPort, |
| 651 | "device-id": f.deviceHandler.device.Id}) |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 652 | if sq.direction == tp_pb.Direction_UPSTREAM { |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 653 | SchedCfg = f.techprofile.GetUsScheduler(sq.tpInst.(*tp_pb.TechProfileInstance)) |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 654 | Direction = "upstream" |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 655 | } else if sq.direction == tp_pb.Direction_DOWNSTREAM { |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 656 | SchedCfg = f.techprofile.GetDsScheduler(sq.tpInst.(*tp_pb.TechProfileInstance)) |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 657 | Direction = "downstream" |
| 658 | } |
| 659 | |
Girish Gowdra | a482f27 | 2021-03-24 23:04:19 -0700 | [diff] [blame] | 660 | TrafficShaping := &tp_pb.TrafficShapingInfo{} // this info is not really useful for the agent during flow removal. Just use default values. |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 661 | |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 662 | TrafficSched := []*tp_pb.TrafficScheduler{f.techprofile.GetTrafficScheduler(sq.tpInst.(*tp_pb.TechProfileInstance), SchedCfg, TrafficShaping)} |
Gamze Abaka | 78a1d2a | 2020-04-27 10:17:27 +0000 | [diff] [blame] | 663 | TrafficSched[0].TechProfileId = sq.tpID |
Girish Kumar | 8f73fe0 | 2019-12-09 13:19:37 +0000 | [diff] [blame] | 664 | |
Girish Gowdra | f3728b1 | 2022-02-02 21:46:51 -0800 | [diff] [blame] | 665 | if _, err = f.deviceHandler.Client.RemoveTrafficSchedulers(ctx, &tp_pb.TrafficSchedulers{ |
| 666 | IntfId: sq.intfID, OnuId: sq.onuID, |
| 667 | UniId: sq.uniID, PortNo: sq.uniPort, |
| 668 | TrafficScheds: TrafficSched}); err != nil { |
| 669 | return olterrors.NewErrAdapter("unable-to-remove-traffic-schedulers-from-device", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 670 | log.Fields{ |
Girish Gowdra | f3728b1 | 2022-02-02 21:46:51 -0800 | [diff] [blame] | 671 | "intf-id": sq.intfID, |
| 672 | "traffic-schedulers": TrafficSched, |
| 673 | "onu-id": sq.onuID, |
| 674 | "uni-id": sq.uniID, |
| 675 | "uni-port": sq.uniPort}, err) |
Girish Kumar | 8f73fe0 | 2019-12-09 13:19:37 +0000 | [diff] [blame] | 676 | } |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 677 | |
Girish Gowdra | f3728b1 | 2022-02-02 21:46:51 -0800 | [diff] [blame] | 678 | logger.Infow(ctx, "removed-traffic-schedulers-successfully", |
| 679 | log.Fields{"device-id": f.deviceHandler.device.Id, |
| 680 | "intf-id": sq.intfID, |
| 681 | "onu-id": sq.onuID, |
| 682 | "uni-id": sq.uniID, |
| 683 | "uni-port": sq.uniPort}) |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 684 | |
Girish Gowdra | f3728b1 | 2022-02-02 21:46:51 -0800 | [diff] [blame] | 685 | if sq.direction == tp_pb.Direction_UPSTREAM { |
| 686 | allocID := sq.tpInst.(*tp_pb.TechProfileInstance).UsScheduler.AllocId |
| 687 | // Delete the TCONT on the ONU. |
| 688 | uni := getUniPortPath(f.deviceHandler.device.Id, sq.intfID, int32(sq.onuID), int32(sq.uniID)) |
yasin sapli | bddc2d7 | 2022-02-08 13:10:17 +0000 | [diff] [blame] | 689 | tpPath := f.getTPpath(ctx, uni, sq.tpID) |
Girish Gowdra | f3728b1 | 2022-02-02 21:46:51 -0800 | [diff] [blame] | 690 | if err := f.sendDeleteTcontToChild(ctx, sq.intfID, sq.onuID, sq.uniID, allocID, tpPath); err != nil { |
| 691 | logger.Errorw(ctx, "error-processing-delete-tcont-towards-onu", |
Gamze Abaka | cb0e677 | 2021-06-10 08:32:12 +0000 | [diff] [blame] | 692 | log.Fields{ |
Girish Gowdra | f3728b1 | 2022-02-02 21:46:51 -0800 | [diff] [blame] | 693 | "intf": sq.intfID, |
| 694 | "onu-id": sq.onuID, |
| 695 | "uni-id": sq.uniID, |
| 696 | "device-id": f.deviceHandler.device.Id, |
| 697 | "alloc-id": allocID}) |
Gamze Abaka | cb0e677 | 2021-06-10 08:32:12 +0000 | [diff] [blame] | 698 | } |
| 699 | } |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 700 | |
| 701 | /* After we successfully remove the scheduler configuration on the OLT device, |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 702 | * delete the meter id on the KV store. |
| 703 | */ |
Girish Gowdra | f3728b1 | 2022-02-02 21:46:51 -0800 | [diff] [blame] | 704 | err = f.removeMeterReference(ctx, Direction, sq) |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 705 | return err |
| 706 | } |
| 707 | |
Girish Gowdra | 197acc1 | 2021-08-16 10:59:45 -0700 | [diff] [blame] | 708 | // We are trying to force remove the schedulers and queues here if one exists for the given key. |
| 709 | // We ignore any errors encountered in the process. The errors most likely are encountered when |
| 710 | // the schedulers and queues are already cleared for the given key. |
| 711 | func (f *OpenOltFlowMgr) forceRemoveSchedulerQueues(ctx context.Context, sq schedQueue) { |
| 712 | |
| 713 | var schedCfg *tp_pb.SchedulerConfig |
| 714 | var err error |
| 715 | logger.Infow(ctx, "removing-schedulers-and-queues-in-olt", |
| 716 | log.Fields{ |
| 717 | "direction": sq.direction, |
| 718 | "intf-id": sq.intfID, |
| 719 | "onu-id": sq.onuID, |
| 720 | "uni-id": sq.uniID, |
| 721 | "uni-port": sq.uniPort, |
| 722 | "tp-id": sq.tpID, |
| 723 | "device-id": f.deviceHandler.device.Id}) |
| 724 | if sq.direction == tp_pb.Direction_UPSTREAM { |
| 725 | schedCfg = f.techprofile.GetUsScheduler(sq.tpInst.(*tp_pb.TechProfileInstance)) |
| 726 | } else if sq.direction == tp_pb.Direction_DOWNSTREAM { |
| 727 | schedCfg = f.techprofile.GetDsScheduler(sq.tpInst.(*tp_pb.TechProfileInstance)) |
| 728 | } |
| 729 | |
| 730 | TrafficShaping := &tp_pb.TrafficShapingInfo{} // this info is not really useful for the agent during flow removal. Just use default values. |
| 731 | TrafficSched := []*tp_pb.TrafficScheduler{f.techprofile.GetTrafficScheduler(sq.tpInst.(*tp_pb.TechProfileInstance), schedCfg, TrafficShaping)} |
| 732 | TrafficSched[0].TechProfileId = sq.tpID |
| 733 | |
| 734 | // Remove traffic queues. Ignore any errors, just log them. |
| 735 | if TrafficQueues, err := f.techprofile.GetTrafficQueues(ctx, sq.tpInst.(*tp_pb.TechProfileInstance), sq.direction); err != nil { |
| 736 | logger.Errorw(ctx, "error retrieving traffic queue", log.Fields{ |
| 737 | "direction": sq.direction, |
| 738 | "intf-id": sq.intfID, |
| 739 | "onu-id": sq.onuID, |
| 740 | "uni-id": sq.uniID, |
| 741 | "uni-port": sq.uniPort, |
| 742 | "tp-id": sq.tpID, |
| 743 | "device-id": f.deviceHandler.device.Id, |
| 744 | "err": err}) |
| 745 | } else { |
| 746 | if _, err = f.deviceHandler.Client.RemoveTrafficQueues(ctx, |
| 747 | &tp_pb.TrafficQueues{IntfId: sq.intfID, OnuId: sq.onuID, |
| 748 | UniId: sq.uniID, PortNo: sq.uniPort, |
| 749 | TrafficQueues: TrafficQueues, |
| 750 | TechProfileId: TrafficSched[0].TechProfileId}); err != nil { |
| 751 | logger.Warnw(ctx, "error removing traffic queue", log.Fields{ |
| 752 | "direction": sq.direction, |
| 753 | "intf-id": sq.intfID, |
| 754 | "onu-id": sq.onuID, |
| 755 | "uni-id": sq.uniID, |
| 756 | "uni-port": sq.uniPort, |
| 757 | "tp-id": sq.tpID, |
| 758 | "device-id": f.deviceHandler.device.Id, |
| 759 | "err": err}) |
| 760 | |
| 761 | } else { |
| 762 | logger.Infow(ctx, "removed-traffic-queues-successfully", log.Fields{"device-id": f.deviceHandler.device.Id, |
| 763 | "direction": sq.direction, |
| 764 | "intf-id": sq.intfID, |
| 765 | "onu-id": sq.onuID, |
| 766 | "uni-id": sq.uniID, |
| 767 | "uni-port": sq.uniPort, |
| 768 | "tp-id": sq.tpID}) |
| 769 | } |
| 770 | } |
| 771 | |
| 772 | // Remove traffic schedulers. Ignore any errors, just log them. |
| 773 | if _, err = f.deviceHandler.Client.RemoveTrafficSchedulers(ctx, &tp_pb.TrafficSchedulers{ |
| 774 | IntfId: sq.intfID, OnuId: sq.onuID, |
| 775 | UniId: sq.uniID, PortNo: sq.uniPort, |
| 776 | TrafficScheds: TrafficSched}); err != nil { |
| 777 | logger.Warnw(ctx, "error removing traffic scheduler", log.Fields{ |
| 778 | "direction": sq.direction, |
| 779 | "intf-id": sq.intfID, |
| 780 | "onu-id": sq.onuID, |
| 781 | "uni-id": sq.uniID, |
| 782 | "uni-port": sq.uniPort, |
| 783 | "tp-id": sq.tpID, |
| 784 | "device-id": f.deviceHandler.device.Id, |
| 785 | "err": err}) |
| 786 | } else { |
| 787 | logger.Infow(ctx, "removed-traffic-schedulers-successfully", log.Fields{"device-id": f.deviceHandler.device.Id, |
| 788 | "direction": sq.direction, |
| 789 | "intf-id": sq.intfID, |
| 790 | "onu-id": sq.onuID, |
| 791 | "uni-id": sq.uniID, |
| 792 | "uni-port": sq.uniPort, |
| 793 | "tp-id": sq.tpID}) |
| 794 | } |
| 795 | } |
| 796 | |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 797 | // This function allocates tconts and GEM ports for an ONU |
khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 798 | func (f *OpenOltFlowMgr) createTcontGemports(ctx context.Context, intfID uint32, onuID uint32, uniID uint32, uni string, uniPort uint32, TpID uint32, UsMeterID uint32, DsMeterID uint32, flowMetadata *ofp.FlowMetadata) (uint32, []uint32, interface{}) { |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 799 | var allocIDs []uint32 |
| 800 | var allgemPortIDs []uint32 |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 801 | var gemPortIDs []uint32 |
Girish Gowdra | 3d63303 | 2019-12-10 16:37:05 +0530 | [diff] [blame] | 802 | tpInstanceExists := false |
Girish Kumar | 8f73fe0 | 2019-12-09 13:19:37 +0000 | [diff] [blame] | 803 | var err error |
yasin sapli | bddc2d7 | 2022-02-08 13:10:17 +0000 | [diff] [blame] | 804 | allocIDs = f.resourceMgr.GetCurrentAllocIDsForOnu(ctx, onuID, uniID) |
| 805 | allgemPortIDs = f.resourceMgr.GetCurrentGEMPortIDsForOnu(ctx, onuID, uniID) |
| 806 | tpPath := f.getTPpath(ctx, uni, TpID) |
Girish Gowdra | 5493426 | 2019-11-13 14:19:55 +0530 | [diff] [blame] | 807 | |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 808 | logger.Debugw(ctx, "creating-new-tcont-and-gem", log.Fields{ |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 809 | "intf-id": intfID, |
| 810 | "onu-id": onuID, |
| 811 | "uni-id": uniID, |
| 812 | "device-id": f.deviceHandler.device.Id, |
| 813 | "tp-id": TpID}) |
Girish Gowdra | 5493426 | 2019-11-13 14:19:55 +0530 | [diff] [blame] | 814 | |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 815 | // Check tech profile instance already exists for derived port name |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 816 | techProfileInstance, _ := f.techprofile.GetTPInstance(ctx, tpPath) |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 817 | if techProfileInstance == nil { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 818 | logger.Infow(ctx, "tp-instance-not-found--creating-new", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 819 | log.Fields{ |
| 820 | "path": tpPath, |
| 821 | "device-id": f.deviceHandler.device.Id}) |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 822 | techProfileInstance, err = f.techprofile.CreateTechProfileInstance(ctx, TpID, uni, intfID) |
Girish Kumar | 8f73fe0 | 2019-12-09 13:19:37 +0000 | [diff] [blame] | 823 | if err != nil { |
Girish Gowdra | 5493426 | 2019-11-13 14:19:55 +0530 | [diff] [blame] | 824 | // This should not happen, something wrong in KV backend transaction |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 825 | logger.Errorw(ctx, "tp-instance-create-failed", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 826 | log.Fields{ |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 827 | "err": err, |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 828 | "tp-id": TpID, |
| 829 | "device-id": f.deviceHandler.device.Id}) |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 830 | return 0, nil, nil |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 831 | } |
yasin sapli | bddc2d7 | 2022-02-08 13:10:17 +0000 | [diff] [blame] | 832 | if err := f.resourceMgr.UpdateTechProfileIDForOnu(ctx, onuID, uniID, TpID); err != nil { |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 833 | logger.Warnw(ctx, "failed-to-update-tech-profile-id", log.Fields{"err": err}) |
Kent Hagerman | e6ff101 | 2020-07-14 15:07:53 -0400 | [diff] [blame] | 834 | } |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 835 | } else { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 836 | logger.Debugw(ctx, "tech-profile-instance-already-exist-for-given port-name", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 837 | log.Fields{ |
| 838 | "uni": uni, |
| 839 | "device-id": f.deviceHandler.device.Id}) |
Girish Gowdra | 3d63303 | 2019-12-10 16:37:05 +0530 | [diff] [blame] | 840 | tpInstanceExists = true |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 841 | } |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 842 | |
Takahiro Suzuki | 2ba0e0b | 2020-06-05 14:23:03 -0700 | [diff] [blame] | 843 | switch tpInst := techProfileInstance.(type) { |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 844 | case *tp_pb.TechProfileInstance: |
Takahiro Suzuki | 2ba0e0b | 2020-06-05 14:23:03 -0700 | [diff] [blame] | 845 | if UsMeterID != 0 { |
| 846 | sq := schedQueue{direction: tp_pb.Direction_UPSTREAM, intfID: intfID, onuID: onuID, uniID: uniID, tpID: TpID, |
| 847 | uniPort: uniPort, tpInst: techProfileInstance, meterID: UsMeterID, flowMetadata: flowMetadata} |
| 848 | if err := f.CreateSchedulerQueues(ctx, sq); err != nil { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 849 | logger.Errorw(ctx, "CreateSchedulerQueues-failed-upstream", |
Takahiro Suzuki | 2ba0e0b | 2020-06-05 14:23:03 -0700 | [diff] [blame] | 850 | log.Fields{ |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 851 | "err": err, |
Matteo Scandolo | 2f6b5bc | 2020-09-17 13:58:10 -0700 | [diff] [blame] | 852 | "onu-id": onuID, |
| 853 | "uni-id": uniID, |
| 854 | "intf-id": intfID, |
Takahiro Suzuki | 2ba0e0b | 2020-06-05 14:23:03 -0700 | [diff] [blame] | 855 | "meter-id": UsMeterID, |
| 856 | "device-id": f.deviceHandler.device.Id}) |
Gamze Abaka | 411ef2f | 2021-11-22 08:38:08 +0000 | [diff] [blame] | 857 | f.revertTechProfileInstance(ctx, sq) |
Takahiro Suzuki | 2ba0e0b | 2020-06-05 14:23:03 -0700 | [diff] [blame] | 858 | return 0, nil, nil |
| 859 | } |
| 860 | } |
| 861 | if DsMeterID != 0 { |
| 862 | sq := schedQueue{direction: tp_pb.Direction_DOWNSTREAM, intfID: intfID, onuID: onuID, uniID: uniID, tpID: TpID, |
| 863 | uniPort: uniPort, tpInst: techProfileInstance, meterID: DsMeterID, flowMetadata: flowMetadata} |
| 864 | if err := f.CreateSchedulerQueues(ctx, sq); err != nil { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 865 | logger.Errorw(ctx, "CreateSchedulerQueues-failed-downstream", |
Takahiro Suzuki | 2ba0e0b | 2020-06-05 14:23:03 -0700 | [diff] [blame] | 866 | log.Fields{ |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 867 | "err": err, |
Matteo Scandolo | 2f6b5bc | 2020-09-17 13:58:10 -0700 | [diff] [blame] | 868 | "onu-id": onuID, |
| 869 | "uni-id": uniID, |
| 870 | "intf-id": intfID, |
Takahiro Suzuki | 2ba0e0b | 2020-06-05 14:23:03 -0700 | [diff] [blame] | 871 | "meter-id": DsMeterID, |
| 872 | "device-id": f.deviceHandler.device.Id}) |
Gamze Abaka | 411ef2f | 2021-11-22 08:38:08 +0000 | [diff] [blame] | 873 | f.revertTechProfileInstance(ctx, sq) |
Takahiro Suzuki | 2ba0e0b | 2020-06-05 14:23:03 -0700 | [diff] [blame] | 874 | return 0, nil, nil |
| 875 | } |
| 876 | } |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 877 | allocID := tpInst.UsScheduler.AllocId |
Takahiro Suzuki | 2ba0e0b | 2020-06-05 14:23:03 -0700 | [diff] [blame] | 878 | for _, gem := range tpInst.UpstreamGemPortAttributeList { |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 879 | gemPortIDs = append(gemPortIDs, gem.GemportId) |
Takahiro Suzuki | 2ba0e0b | 2020-06-05 14:23:03 -0700 | [diff] [blame] | 880 | } |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 881 | allocIDs = appendUnique32bit(allocIDs, allocID) |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 882 | |
Takahiro Suzuki | 2ba0e0b | 2020-06-05 14:23:03 -0700 | [diff] [blame] | 883 | if tpInstanceExists { |
| 884 | return allocID, gemPortIDs, techProfileInstance |
| 885 | } |
| 886 | |
| 887 | for _, gemPortID := range gemPortIDs { |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 888 | allgemPortIDs = appendUnique32bit(allgemPortIDs, gemPortID) |
Takahiro Suzuki | 2ba0e0b | 2020-06-05 14:23:03 -0700 | [diff] [blame] | 889 | } |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 890 | logger.Infow(ctx, "allocated-tcont-and-gem-ports", |
Takahiro Suzuki | 2ba0e0b | 2020-06-05 14:23:03 -0700 | [diff] [blame] | 891 | log.Fields{ |
Matteo Scandolo | 8458537 | 2021-03-18 14:21:22 -0700 | [diff] [blame] | 892 | "intf-id": intfID, |
| 893 | "onu-id": onuID, |
| 894 | "uni-id": uniID, |
Takahiro Suzuki | 2ba0e0b | 2020-06-05 14:23:03 -0700 | [diff] [blame] | 895 | "alloc-ids": allocIDs, |
| 896 | "gemports": allgemPortIDs, |
| 897 | "device-id": f.deviceHandler.device.Id}) |
| 898 | // Send Tconts and GEM ports to KV store |
| 899 | f.storeTcontsGEMPortsIntoKVStore(ctx, intfID, onuID, uniID, allocIDs, allgemPortIDs) |
Girish Gowdra | 3d63303 | 2019-12-10 16:37:05 +0530 | [diff] [blame] | 900 | return allocID, gemPortIDs, techProfileInstance |
khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 901 | case *tp_pb.EponTechProfileInstance: |
Takahiro Suzuki | 2ba0e0b | 2020-06-05 14:23:03 -0700 | [diff] [blame] | 902 | // CreateSchedulerQueues for EPON needs to be implemented here |
| 903 | // when voltha-protos for EPON is completed. |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 904 | allocID := tpInst.AllocId |
Takahiro Suzuki | 2ba0e0b | 2020-06-05 14:23:03 -0700 | [diff] [blame] | 905 | for _, gem := range tpInst.UpstreamQueueAttributeList { |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 906 | gemPortIDs = append(gemPortIDs, gem.GemportId) |
Takahiro Suzuki | 2ba0e0b | 2020-06-05 14:23:03 -0700 | [diff] [blame] | 907 | } |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 908 | allocIDs = appendUnique32bit(allocIDs, allocID) |
Takahiro Suzuki | 2ba0e0b | 2020-06-05 14:23:03 -0700 | [diff] [blame] | 909 | |
| 910 | if tpInstanceExists { |
| 911 | return allocID, gemPortIDs, techProfileInstance |
| 912 | } |
| 913 | |
| 914 | for _, gemPortID := range gemPortIDs { |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 915 | allgemPortIDs = appendUnique32bit(allgemPortIDs, gemPortID) |
Takahiro Suzuki | 2ba0e0b | 2020-06-05 14:23:03 -0700 | [diff] [blame] | 916 | } |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 917 | logger.Infow(ctx, "allocated-tcont-and-gem-ports", |
Takahiro Suzuki | 2ba0e0b | 2020-06-05 14:23:03 -0700 | [diff] [blame] | 918 | log.Fields{ |
| 919 | "alloc-ids": allocIDs, |
| 920 | "gemports": allgemPortIDs, |
| 921 | "device-id": f.deviceHandler.device.Id}) |
| 922 | // Send Tconts and GEM ports to KV store |
| 923 | f.storeTcontsGEMPortsIntoKVStore(ctx, intfID, onuID, uniID, allocIDs, allgemPortIDs) |
| 924 | return allocID, gemPortIDs, techProfileInstance |
| 925 | default: |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 926 | logger.Errorw(ctx, "unknown-tech", |
Takahiro Suzuki | 2ba0e0b | 2020-06-05 14:23:03 -0700 | [diff] [blame] | 927 | log.Fields{ |
| 928 | "tpInst": tpInst}) |
| 929 | return 0, nil, nil |
Girish Gowdra | 3d63303 | 2019-12-10 16:37:05 +0530 | [diff] [blame] | 930 | } |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 931 | } |
| 932 | |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 933 | func (f *OpenOltFlowMgr) storeTcontsGEMPortsIntoKVStore(ctx context.Context, intfID uint32, onuID uint32, uniID uint32, allocID []uint32, gemPortIDs []uint32) { |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 934 | |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 935 | logger.Debugw(ctx, "storing-allocated-tconts-and-gem-ports-into-KV-store", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 936 | log.Fields{ |
| 937 | "intf-id": intfID, |
| 938 | "onu-id": onuID, |
| 939 | "uni-id": uniID, |
| 940 | "alloc-id": allocID, |
| 941 | "gemport-ids": gemPortIDs, |
| 942 | "device-id": f.deviceHandler.device.Id}) |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 943 | /* Update the allocated alloc_id and gem_port_id for the ONU/UNI to KV store */ |
yasin sapli | bddc2d7 | 2022-02-08 13:10:17 +0000 | [diff] [blame] | 944 | if err := f.resourceMgr.UpdateAllocIdsForOnu(ctx, onuID, uniID, allocID); err != nil { |
yasin sapli | 9e4c509 | 2022-02-01 13:52:33 +0000 | [diff] [blame] | 945 | logger.Errorw(ctx, "error-while-uploading-allocid-to-kv-store", log.Fields{"device-id": f.deviceHandler.device.Id, "onuID": onuID, "allocID": allocID}) |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 946 | } |
yasin sapli | bddc2d7 | 2022-02-08 13:10:17 +0000 | [diff] [blame] | 947 | if err := f.resourceMgr.UpdateGEMPortIDsForOnu(ctx, onuID, uniID, gemPortIDs); err != nil { |
yasin sapli | 9e4c509 | 2022-02-01 13:52:33 +0000 | [diff] [blame] | 948 | logger.Errorw(ctx, "error-while-uploading-gemports-to-kv-store", log.Fields{"device-id": f.deviceHandler.device.Id, "onuID": onuID, "gemPort": gemPortIDs}) |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 949 | } |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 950 | |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 951 | logger.Infow(ctx, "stored-tconts-and-gem-into-kv-store-successfully", log.Fields{"device-id": f.deviceHandler.device.Id}) |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 952 | for _, gemPort := range gemPortIDs { |
yasin sapli | bddc2d7 | 2022-02-08 13:10:17 +0000 | [diff] [blame] | 953 | if err := f.resourceMgr.AddGemToOnuGemInfo(ctx, onuID, gemPort); err != nil { |
yasin sapli | 9e4c509 | 2022-02-01 13:52:33 +0000 | [diff] [blame] | 954 | logger.Errorw(ctx, "error-while-uploading-onugeminfos-to-kv-store", log.Fields{"device-id": f.deviceHandler.device.Id, "onuID": onuID, "gemPort": gemPort}) |
| 955 | } |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 956 | } |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 957 | } |
| 958 | |
Girish Gowdra | 4736e5c | 2021-08-25 15:19:10 -0700 | [diff] [blame] | 959 | func (f *OpenOltFlowMgr) populateTechProfileForCurrentPonPort(ctx context.Context) error { |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 960 | for _, techRange := range f.resourceMgr.DevInfo.Ranges { |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 961 | for _, intfID := range techRange.IntfIds { |
Girish Gowdra | 4736e5c | 2021-08-25 15:19:10 -0700 | [diff] [blame] | 962 | if intfID == f.ponPortIdx { // initialize only for the pon port that this flow manager is managing |
| 963 | var err error |
| 964 | f.techprofile, err = tp.NewTechProfile(ctx, f.resourceMgr.PonRsrMgr, f.resourceMgr.PonRsrMgr.Backend, |
| 965 | f.resourceMgr.PonRsrMgr.Address, f.deviceHandler.cm.Backend.PathPrefix) |
| 966 | if err != nil || f.techprofile == nil { |
| 967 | logger.Errorw(ctx, "failed-to-allocate-to-techprofile-for-pon-port", log.Fields{"intfID": intfID, "err": err}) |
| 968 | return fmt.Errorf("failed-to-allocate-tech-profile-for-pon-port--pon-%v-err-%v", intfID, err) |
| 969 | } |
| 970 | logger.Debugw(ctx, "init-tech-profile-done", |
| 971 | log.Fields{ |
| 972 | "intf-id": intfID, |
| 973 | "device-id": f.deviceHandler.device.Id}) |
| 974 | return nil |
Girish Gowdra | 4c3d460 | 2021-07-22 16:33:37 -0700 | [diff] [blame] | 975 | } |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 976 | } |
| 977 | } |
Girish Gowdra | 4736e5c | 2021-08-25 15:19:10 -0700 | [diff] [blame] | 978 | logger.Errorw(ctx, "pon port not found in the the device pon port range", log.Fields{"intfID": f.ponPortIdx}) |
| 979 | return fmt.Errorf("pon-port-idx-not-found-in-the-device-info-pon-port-range-%v", f.ponPortIdx) |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 980 | } |
| 981 | |
Gamze Abaka | 7650be6 | 2021-02-26 10:50:36 +0000 | [diff] [blame] | 982 | func (f *OpenOltFlowMgr) addUpstreamDataPathFlow(ctx context.Context, flowContext *flowContext) error { |
Girish Gowdra | ffa52e5 | 2022-02-16 15:48:10 -0800 | [diff] [blame^] | 983 | flowContext.classifier[PacketTagType] = SingleTag |
| 984 | // extract the cvid/inner-vid from the write metadata |
| 985 | writeMetadata := flows.GetMetadataFromWriteMetadataAction(ctx, flowContext.logicalFlow) |
| 986 | if writeMetadata != 0 { |
| 987 | // Writemetadata field is 8 bytes |
| 988 | // cvid is on the outer most two bytes of the write metadata |
| 989 | cvid := (writeMetadata & 0xffff000000000000) >> 48 |
| 990 | // if the cvid does not match the classifier vlan, then this indicates it is a double tagged packet |
| 991 | if cvid != flowContext.classifier[VlanVid] && cvid != 0 { |
| 992 | flowContext.classifier[PacketTagType] = DoubleTag |
| 993 | } |
| 994 | } |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 995 | logger.Debugw(ctx, "adding-upstream-data-flow", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 996 | log.Fields{ |
Gamze Abaka | 7650be6 | 2021-02-26 10:50:36 +0000 | [diff] [blame] | 997 | "uplinkClassifier": flowContext.classifier, |
| 998 | "uplinkAction": flowContext.action}) |
| 999 | return f.addSymmetricDataPathFlow(ctx, flowContext, Upstream) |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 1000 | } |
| 1001 | |
Gamze Abaka | 7650be6 | 2021-02-26 10:50:36 +0000 | [diff] [blame] | 1002 | func (f *OpenOltFlowMgr) addDownstreamDataPathFlow(ctx context.Context, flowContext *flowContext) error { |
| 1003 | downlinkClassifier := flowContext.classifier |
| 1004 | downlinkAction := flowContext.action |
Girish Gowdra | ffa52e5 | 2022-02-16 15:48:10 -0800 | [diff] [blame^] | 1005 | // default to single tag. If we detect an inner cvid from write-metadata, then we mark the PacketTagType as DoubleTag |
| 1006 | downlinkClassifier[PacketTagType] = SingleTag |
| 1007 | // extract the cvid/inner-vid from the write metadata |
| 1008 | writeMetadata := flows.GetMetadataFromWriteMetadataAction(ctx, flowContext.logicalFlow) |
| 1009 | if writeMetadata != 0 { |
| 1010 | // Writemetadata field is 8 bytes |
| 1011 | // cvid is on the outer most two bytes of the write metadata |
| 1012 | if cvid := (writeMetadata & 0xffff000000000000) >> 48; cvid != 0 { |
| 1013 | downlinkClassifier[PacketTagType] = DoubleTag |
| 1014 | } |
Andrea Campanella | faa4215 | 2021-10-28 11:50:56 +0530 | [diff] [blame] | 1015 | } |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1016 | logger.Debugw(ctx, "adding-downstream-data-flow", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1017 | log.Fields{ |
| 1018 | "downlinkClassifier": downlinkClassifier, |
| 1019 | "downlinkAction": downlinkAction}) |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 1020 | // Ignore Downlink trap flow given by core, cannot do anything with this flow */ |
| 1021 | if vlan, exists := downlinkClassifier[VlanVid]; exists { |
| 1022 | if vlan.(uint32) == (uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 4000) { //private VLAN given by core |
David K. Bainbridge | 82efc49 | 2019-09-04 09:57:11 -0700 | [diff] [blame] | 1023 | if metadata, exists := downlinkClassifier[Metadata]; exists { // inport is filled in metadata by core |
Mahir Gunyel | 85f61c1 | 2021-10-06 11:53:45 -0700 | [diff] [blame] | 1024 | if uint32(metadata.(uint64)) == plt.MkUniPortNum(ctx, flowContext.intfID, flowContext.onuID, flowContext.uniID) { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1025 | logger.Infow(ctx, "ignoring-dl-trap-device-flow-from-core", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1026 | log.Fields{ |
Gamze Abaka | 7650be6 | 2021-02-26 10:50:36 +0000 | [diff] [blame] | 1027 | "flow": flowContext.logicalFlow, |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1028 | "device-id": f.deviceHandler.device.Id, |
Gamze Abaka | 7650be6 | 2021-02-26 10:50:36 +0000 | [diff] [blame] | 1029 | "onu-id": flowContext.onuID, |
| 1030 | "intf-id": flowContext.intfID}) |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1031 | return nil |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 1032 | } |
| 1033 | } |
| 1034 | } |
Manikkaraj k | 884c124 | 2019-04-11 16:26:42 +0530 | [diff] [blame] | 1035 | } |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 1036 | |
Girish Gowdra | ffa52e5 | 2022-02-16 15:48:10 -0800 | [diff] [blame^] | 1037 | // If Pop Vlan action is specified, set the vlan to be popped from the classifier vlan match field. |
| 1038 | // The matched vlan is the one that is getting popped. |
| 1039 | if val, ok := downlinkAction[PopVlan]; ok && val.(bool) { |
| 1040 | // vlan_vid is a uint32. must be type asserted as such or conversion fails |
| 1041 | dlClVid, ok := downlinkClassifier[VlanVid].(uint32) |
| 1042 | if ok { |
| 1043 | downlinkAction[VlanVid] = dlClVid & 0xfff |
| 1044 | } |
Girish Gowdra | 26f344b | 2019-10-23 14:39:13 +0530 | [diff] [blame] | 1045 | } |
| 1046 | |
Gamze Abaka | 7650be6 | 2021-02-26 10:50:36 +0000 | [diff] [blame] | 1047 | return f.addSymmetricDataPathFlow(ctx, flowContext, Downstream) |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 1048 | } |
| 1049 | |
Gamze Abaka | 7650be6 | 2021-02-26 10:50:36 +0000 | [diff] [blame] | 1050 | func (f *OpenOltFlowMgr) addSymmetricDataPathFlow(ctx context.Context, flowContext *flowContext, direction string) error { |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 1051 | |
Gamze Abaka | 7650be6 | 2021-02-26 10:50:36 +0000 | [diff] [blame] | 1052 | intfID := flowContext.intfID |
| 1053 | onuID := flowContext.onuID |
| 1054 | uniID := flowContext.uniID |
| 1055 | classifier := flowContext.classifier |
| 1056 | action := flowContext.action |
| 1057 | allocID := flowContext.allocID |
| 1058 | gemPortID := flowContext.gemPortID |
| 1059 | tpID := flowContext.tpID |
| 1060 | logicalFlow := flowContext.logicalFlow |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1061 | logger.Infow(ctx, "adding-hsia-flow", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1062 | log.Fields{ |
| 1063 | "intf-id": intfID, |
| 1064 | "onu-id": onuID, |
| 1065 | "uni-id": uniID, |
| 1066 | "device-id": f.deviceHandler.device.Id, |
| 1067 | "classifier": classifier, |
| 1068 | "action": action, |
| 1069 | "direction": direction, |
| 1070 | "alloc-id": allocID, |
| 1071 | "gemport-id": gemPortID, |
| 1072 | "logicalflow": *logicalFlow}) |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 1073 | |
yasin sapli | bddc2d7 | 2022-02-08 13:10:17 +0000 | [diff] [blame] | 1074 | present, err := f.resourceMgr.IsFlowOnKvStore(ctx, int32(onuID), logicalFlow.Id) |
yasin sapli | d056627 | 2021-12-21 09:10:30 +0000 | [diff] [blame] | 1075 | if present { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1076 | logger.Infow(ctx, "flow-already-exists", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1077 | log.Fields{ |
| 1078 | "device-id": f.deviceHandler.device.Id, |
| 1079 | "intf-id": intfID, |
| 1080 | "onu-id": onuID}) |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1081 | return nil |
yasin sapli | d056627 | 2021-12-21 09:10:30 +0000 | [diff] [blame] | 1082 | } else if err != nil { |
| 1083 | logger.Errorw(ctx, "aborting-addSymmetricDataPathFlow--flow-may-already-exist", |
| 1084 | log.Fields{"intf-id": intfID, "onu-id": onuID, "flow-id": logicalFlow.Id}) |
| 1085 | return err |
Girish Gowdra | 3d63303 | 2019-12-10 16:37:05 +0530 | [diff] [blame] | 1086 | } |
yasin sapli | d056627 | 2021-12-21 09:10:30 +0000 | [diff] [blame] | 1087 | |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1088 | classifierProto, err := makeOpenOltClassifierField(classifier) |
| 1089 | if err != nil { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1090 | return olterrors.NewErrInvalidValue(log.Fields{"classifier": classifier, "device-id": f.deviceHandler.device.Id}, err).Log() |
Manikkaraj k | 884c124 | 2019-04-11 16:26:42 +0530 | [diff] [blame] | 1091 | } |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1092 | logger.Debugw(ctx, "created-classifier-proto", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1093 | log.Fields{ |
| 1094 | "classifier": *classifierProto, |
| 1095 | "device-id": f.deviceHandler.device.Id}) |
Gamze Abaka | 724d085 | 2020-03-18 12:10:24 +0000 | [diff] [blame] | 1096 | actionProto, err := makeOpenOltActionField(action, classifier) |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1097 | if err != nil { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1098 | return olterrors.NewErrInvalidValue(log.Fields{"action": action, "device-id": f.deviceHandler.device.Id}, err).Log() |
Manikkaraj k | 884c124 | 2019-04-11 16:26:42 +0530 | [diff] [blame] | 1099 | } |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1100 | logger.Debugw(ctx, "created-action-proto", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1101 | log.Fields{ |
| 1102 | "action": *actionProto, |
| 1103 | "device-id": f.deviceHandler.device.Id}) |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1104 | networkIntfID, err := getNniIntfID(ctx, classifier, action) |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 1105 | if err != nil { |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 1106 | return olterrors.NewErrNotFound("nni-interface-id", |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1107 | log.Fields{ |
| 1108 | "classifier": classifier, |
| 1109 | "action": action, |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1110 | "device-id": f.deviceHandler.device.Id, |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1111 | }, err).Log() |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 1112 | } |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 1113 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1114 | flow := openoltpb2.Flow{AccessIntfId: int32(intfID), |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 1115 | OnuId: int32(onuID), |
| 1116 | UniId: int32(uniID), |
| 1117 | FlowId: logicalFlow.Id, |
| 1118 | FlowType: direction, |
| 1119 | AllocId: int32(allocID), |
| 1120 | NetworkIntfId: int32(networkIntfID), |
| 1121 | GemportId: int32(gemPortID), |
| 1122 | Classifier: classifierProto, |
| 1123 | Action: actionProto, |
| 1124 | Priority: int32(logicalFlow.Priority), |
| 1125 | Cookie: logicalFlow.Cookie, |
| 1126 | PortNo: flowContext.portNo, |
| 1127 | TechProfileId: tpID, |
| 1128 | ReplicateFlow: len(flowContext.pbitToGem) > 0, |
| 1129 | PbitToGemport: flowContext.pbitToGem, |
| 1130 | GemportToAes: flowContext.gemToAes, |
Gamze Abaka | 78a1d2a | 2020-04-27 10:17:27 +0000 | [diff] [blame] | 1131 | } |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1132 | if err := f.addFlowToDevice(ctx, logicalFlow, &flow); err != nil { |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 1133 | return olterrors.NewErrFlowOp("add", logicalFlow.Id, nil, err).Log() |
Manikkaraj k | 884c124 | 2019-04-11 16:26:42 +0530 | [diff] [blame] | 1134 | } |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1135 | logger.Infow(ctx, "hsia-flow-added-to-device-successfully", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1136 | log.Fields{"direction": direction, |
| 1137 | "device-id": f.deviceHandler.device.Id, |
| 1138 | "flow": flow, |
| 1139 | "intf-id": intfID, |
| 1140 | "onu-id": onuID}) |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 1141 | |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1142 | return nil |
Manikkaraj k | 884c124 | 2019-04-11 16:26:42 +0530 | [diff] [blame] | 1143 | } |
Esin Karaman | ae41e2b | 2019-12-17 18:13:13 +0000 | [diff] [blame] | 1144 | |
Gamze Abaka | 7650be6 | 2021-02-26 10:50:36 +0000 | [diff] [blame] | 1145 | func (f *OpenOltFlowMgr) addDHCPTrapFlow(ctx context.Context, flowContext *flowContext) error { |
| 1146 | |
| 1147 | intfID := flowContext.intfID |
| 1148 | onuID := flowContext.onuID |
| 1149 | uniID := flowContext.uniID |
| 1150 | logicalFlow := flowContext.logicalFlow |
| 1151 | classifier := flowContext.classifier |
| 1152 | action := flowContext.action |
Manjunath Vanarajulu | adc57d1 | 2019-04-23 11:07:21 +0530 | [diff] [blame] | 1153 | |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1154 | networkIntfID, err := getNniIntfID(ctx, classifier, action) |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 1155 | if err != nil { |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 1156 | return olterrors.NewErrNotFound("nni-interface-id", log.Fields{ |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1157 | "classifier": classifier, |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1158 | "action": action, |
| 1159 | "device-id": f.deviceHandler.device.Id}, |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1160 | err).Log() |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 1161 | } |
Manjunath Vanarajulu | adc57d1 | 2019-04-23 11:07:21 +0530 | [diff] [blame] | 1162 | |
| 1163 | // Clear the action map |
| 1164 | for k := range action { |
| 1165 | delete(action, k) |
| 1166 | } |
| 1167 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1168 | action[TrapToHost] = true |
| 1169 | classifier[UDPSrc] = uint32(68) |
| 1170 | classifier[UDPDst] = uint32(67) |
| 1171 | classifier[PacketTagType] = SingleTag |
Manjunath Vanarajulu | adc57d1 | 2019-04-23 11:07:21 +0530 | [diff] [blame] | 1172 | |
yasin sapli | bddc2d7 | 2022-02-08 13:10:17 +0000 | [diff] [blame] | 1173 | present, err := f.resourceMgr.IsFlowOnKvStore(ctx, int32(onuID), logicalFlow.Id) |
yasin sapli | d056627 | 2021-12-21 09:10:30 +0000 | [diff] [blame] | 1174 | if present { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1175 | logger.Infow(ctx, "flow-exists--not-re-adding", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1176 | log.Fields{ |
| 1177 | "device-id": f.deviceHandler.device.Id, |
| 1178 | "intf-id": intfID, |
| 1179 | "onu-id": onuID}) |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1180 | return nil |
yasin sapli | d056627 | 2021-12-21 09:10:30 +0000 | [diff] [blame] | 1181 | } else if err != nil { |
| 1182 | logger.Errorw(ctx, "aborting-addDHCPTrapFlow--flow-may-already-exist", |
| 1183 | log.Fields{"intf-id": intfID, "onu-id": onuID, "flow-id": logicalFlow.Id}) |
| 1184 | return err |
Girish Gowdra | 3d63303 | 2019-12-10 16:37:05 +0530 | [diff] [blame] | 1185 | } |
Manjunath Vanarajulu | adc57d1 | 2019-04-23 11:07:21 +0530 | [diff] [blame] | 1186 | |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1187 | logger.Debugw(ctx, "creating-ul-dhcp-flow", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1188 | log.Fields{ |
| 1189 | "ul_classifier": classifier, |
| 1190 | "ul_action": action, |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 1191 | "uplinkFlowId": logicalFlow.Id, |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1192 | "intf-id": intfID, |
| 1193 | "onu-id": onuID, |
| 1194 | "device-id": f.deviceHandler.device.Id}) |
Manjunath Vanarajulu | adc57d1 | 2019-04-23 11:07:21 +0530 | [diff] [blame] | 1195 | |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1196 | classifierProto, err := makeOpenOltClassifierField(classifier) |
| 1197 | if err != nil { |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 1198 | return olterrors.NewErrInvalidValue(log.Fields{"classifier": classifier}, err).Log() |
Manjunath Vanarajulu | adc57d1 | 2019-04-23 11:07:21 +0530 | [diff] [blame] | 1199 | } |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1200 | logger.Debugw(ctx, "created-classifier-proto", log.Fields{"classifier": *classifierProto}) |
Gamze Abaka | 724d085 | 2020-03-18 12:10:24 +0000 | [diff] [blame] | 1201 | actionProto, err := makeOpenOltActionField(action, classifier) |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1202 | if err != nil { |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 1203 | return olterrors.NewErrInvalidValue(log.Fields{"action": action}, err).Log() |
Manjunath Vanarajulu | adc57d1 | 2019-04-23 11:07:21 +0530 | [diff] [blame] | 1204 | } |
| 1205 | |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1206 | dhcpFlow := openoltpb2.Flow{AccessIntfId: int32(intfID), |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1207 | OnuId: int32(onuID), |
| 1208 | UniId: int32(uniID), |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 1209 | FlowId: logicalFlow.Id, |
David K. Bainbridge | 82efc49 | 2019-09-04 09:57:11 -0700 | [diff] [blame] | 1210 | FlowType: Upstream, |
Gamze Abaka | 7650be6 | 2021-02-26 10:50:36 +0000 | [diff] [blame] | 1211 | AllocId: int32(flowContext.allocID), |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1212 | NetworkIntfId: int32(networkIntfID), |
Gamze Abaka | 7650be6 | 2021-02-26 10:50:36 +0000 | [diff] [blame] | 1213 | GemportId: int32(flowContext.gemPortID), |
Manjunath Vanarajulu | adc57d1 | 2019-04-23 11:07:21 +0530 | [diff] [blame] | 1214 | Classifier: classifierProto, |
| 1215 | Action: actionProto, |
| 1216 | Priority: int32(logicalFlow.Priority), |
| 1217 | Cookie: logicalFlow.Cookie, |
Gamze Abaka | 7650be6 | 2021-02-26 10:50:36 +0000 | [diff] [blame] | 1218 | PortNo: flowContext.portNo, |
| 1219 | TechProfileId: flowContext.tpID, |
| 1220 | ReplicateFlow: len(flowContext.pbitToGem) > 0, |
| 1221 | PbitToGemport: flowContext.pbitToGem, |
| 1222 | GemportToAes: flowContext.gemToAes, |
Gamze Abaka | 78a1d2a | 2020-04-27 10:17:27 +0000 | [diff] [blame] | 1223 | } |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1224 | if err := f.addFlowToDevice(ctx, logicalFlow, &dhcpFlow); err != nil { |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 1225 | return olterrors.NewErrFlowOp("add", logicalFlow.Id, log.Fields{"dhcp-flow": dhcpFlow}, err).Log() |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1226 | } |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1227 | logger.Infow(ctx, "dhcp-ul-flow-added-to-device-successfully", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1228 | log.Fields{ |
| 1229 | "device-id": f.deviceHandler.device.Id, |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 1230 | "flow-id": logicalFlow.Id, |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1231 | "intf-id": intfID, |
| 1232 | "onu-id": onuID}) |
Manjunath Vanarajulu | adc57d1 | 2019-04-23 11:07:21 +0530 | [diff] [blame] | 1233 | |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1234 | return nil |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 1235 | } |
| 1236 | |
Esin Karaman | ae41e2b | 2019-12-17 18:13:13 +0000 | [diff] [blame] | 1237 | //addIGMPTrapFlow creates IGMP trap-to-host flow |
Gamze Abaka | 7650be6 | 2021-02-26 10:50:36 +0000 | [diff] [blame] | 1238 | func (f *OpenOltFlowMgr) addIGMPTrapFlow(ctx context.Context, flowContext *flowContext) error { |
| 1239 | delete(flowContext.classifier, VlanVid) |
| 1240 | return f.addUpstreamTrapFlow(ctx, flowContext) |
Esin Karaman | ae41e2b | 2019-12-17 18:13:13 +0000 | [diff] [blame] | 1241 | } |
| 1242 | |
| 1243 | //addUpstreamTrapFlow creates a trap-to-host flow |
Gamze Abaka | 7650be6 | 2021-02-26 10:50:36 +0000 | [diff] [blame] | 1244 | func (f *OpenOltFlowMgr) addUpstreamTrapFlow(ctx context.Context, flowContext *flowContext) error { |
| 1245 | |
| 1246 | intfID := flowContext.intfID |
| 1247 | onuID := flowContext.onuID |
| 1248 | uniID := flowContext.uniID |
| 1249 | logicalFlow := flowContext.logicalFlow |
| 1250 | classifier := flowContext.classifier |
| 1251 | action := flowContext.action |
Esin Karaman | ae41e2b | 2019-12-17 18:13:13 +0000 | [diff] [blame] | 1252 | |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1253 | networkIntfID, err := getNniIntfID(ctx, classifier, action) |
Esin Karaman | ae41e2b | 2019-12-17 18:13:13 +0000 | [diff] [blame] | 1254 | if err != nil { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1255 | return olterrors.NewErrNotFound("nni-interface-id", |
| 1256 | log.Fields{ |
| 1257 | "classifier": classifier, |
| 1258 | "action": action, |
| 1259 | "device-id": f.deviceHandler.device.Id}, |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1260 | err).Log() |
Esin Karaman | ae41e2b | 2019-12-17 18:13:13 +0000 | [diff] [blame] | 1261 | } |
| 1262 | |
| 1263 | // Clear the action map |
| 1264 | for k := range action { |
| 1265 | delete(action, k) |
| 1266 | } |
| 1267 | |
| 1268 | action[TrapToHost] = true |
| 1269 | classifier[PacketTagType] = SingleTag |
Esin Karaman | ae41e2b | 2019-12-17 18:13:13 +0000 | [diff] [blame] | 1270 | |
yasin sapli | bddc2d7 | 2022-02-08 13:10:17 +0000 | [diff] [blame] | 1271 | present, err := f.resourceMgr.IsFlowOnKvStore(ctx, int32(onuID), logicalFlow.Id) |
yasin sapli | d056627 | 2021-12-21 09:10:30 +0000 | [diff] [blame] | 1272 | if present { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1273 | logger.Infow(ctx, "flow-exists-not-re-adding", log.Fields{"device-id": f.deviceHandler.device.Id}) |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1274 | return nil |
yasin sapli | d056627 | 2021-12-21 09:10:30 +0000 | [diff] [blame] | 1275 | } else if err != nil { |
| 1276 | logger.Errorw(ctx, "aborting-addUpstreamTrapFlow--flow-may-already-exist", |
| 1277 | log.Fields{"intf-id": intfID, "onu-id": onuID, "flow-id": logicalFlow.Id}) |
| 1278 | return err |
Esin Karaman | ae41e2b | 2019-12-17 18:13:13 +0000 | [diff] [blame] | 1279 | } |
| 1280 | |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1281 | logger.Debugw(ctx, "creating-upstream-trap-flow", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1282 | log.Fields{ |
| 1283 | "ul_classifier": classifier, |
| 1284 | "ul_action": action, |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 1285 | "uplinkFlowId": logicalFlow.Id, |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1286 | "device-id": f.deviceHandler.device.Id, |
| 1287 | "intf-id": intfID, |
| 1288 | "onu-id": onuID}) |
Esin Karaman | ae41e2b | 2019-12-17 18:13:13 +0000 | [diff] [blame] | 1289 | |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1290 | classifierProto, err := makeOpenOltClassifierField(classifier) |
| 1291 | if err != nil { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1292 | return olterrors.NewErrInvalidValue(log.Fields{"classifier": classifier, "device-id": f.deviceHandler.device.Id}, err).Log() |
Esin Karaman | ae41e2b | 2019-12-17 18:13:13 +0000 | [diff] [blame] | 1293 | } |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1294 | logger.Debugw(ctx, "created-classifier-proto", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1295 | log.Fields{ |
| 1296 | "classifier": *classifierProto, |
| 1297 | "device-id": f.deviceHandler.device.Id}) |
Gamze Abaka | 724d085 | 2020-03-18 12:10:24 +0000 | [diff] [blame] | 1298 | actionProto, err := makeOpenOltActionField(action, classifier) |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1299 | if err != nil { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1300 | return olterrors.NewErrInvalidValue(log.Fields{"action": action, "device-id": f.deviceHandler.device.Id}, err).Log() |
Esin Karaman | ae41e2b | 2019-12-17 18:13:13 +0000 | [diff] [blame] | 1301 | } |
| 1302 | |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1303 | flow := openoltpb2.Flow{AccessIntfId: int32(intfID), |
Esin Karaman | ae41e2b | 2019-12-17 18:13:13 +0000 | [diff] [blame] | 1304 | OnuId: int32(onuID), |
| 1305 | UniId: int32(uniID), |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 1306 | FlowId: logicalFlow.Id, |
Esin Karaman | ae41e2b | 2019-12-17 18:13:13 +0000 | [diff] [blame] | 1307 | FlowType: Upstream, |
Gamze Abaka | 7650be6 | 2021-02-26 10:50:36 +0000 | [diff] [blame] | 1308 | AllocId: int32(flowContext.allocID), |
Esin Karaman | ae41e2b | 2019-12-17 18:13:13 +0000 | [diff] [blame] | 1309 | NetworkIntfId: int32(networkIntfID), |
Gamze Abaka | 7650be6 | 2021-02-26 10:50:36 +0000 | [diff] [blame] | 1310 | GemportId: int32(flowContext.gemPortID), |
Esin Karaman | ae41e2b | 2019-12-17 18:13:13 +0000 | [diff] [blame] | 1311 | Classifier: classifierProto, |
| 1312 | Action: actionProto, |
| 1313 | Priority: int32(logicalFlow.Priority), |
| 1314 | Cookie: logicalFlow.Cookie, |
Gamze Abaka | 7650be6 | 2021-02-26 10:50:36 +0000 | [diff] [blame] | 1315 | PortNo: flowContext.portNo, |
| 1316 | TechProfileId: flowContext.tpID, |
| 1317 | ReplicateFlow: len(flowContext.pbitToGem) > 0, |
| 1318 | PbitToGemport: flowContext.pbitToGem, |
| 1319 | GemportToAes: flowContext.gemToAes, |
Gamze Abaka | 78a1d2a | 2020-04-27 10:17:27 +0000 | [diff] [blame] | 1320 | } |
Esin Karaman | ae41e2b | 2019-12-17 18:13:13 +0000 | [diff] [blame] | 1321 | |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1322 | if err := f.addFlowToDevice(ctx, logicalFlow, &flow); err != nil { |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 1323 | return olterrors.NewErrFlowOp("add", logicalFlow.Id, log.Fields{"flow": flow, "device-id": f.deviceHandler.device.Id}, err).Log() |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1324 | } |
Esin Karaman | ae41e2b | 2019-12-17 18:13:13 +0000 | [diff] [blame] | 1325 | |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1326 | return nil |
Esin Karaman | ae41e2b | 2019-12-17 18:13:13 +0000 | [diff] [blame] | 1327 | } |
| 1328 | |
Marcos Aurelio Carrero (Furukawa) | 388fb0a | 2021-02-04 18:05:11 -0300 | [diff] [blame] | 1329 | // Add EthType flow to device with mac, vlanId as classifier for upstream and downstream |
Gamze Abaka | 7650be6 | 2021-02-26 10:50:36 +0000 | [diff] [blame] | 1330 | func (f *OpenOltFlowMgr) addEthTypeBasedFlow(ctx context.Context, flowContext *flowContext, vlanID uint32, ethType uint32) error { |
| 1331 | intfID := flowContext.intfID |
| 1332 | onuID := flowContext.onuID |
| 1333 | uniID := flowContext.uniID |
| 1334 | portNo := flowContext.portNo |
| 1335 | allocID := flowContext.allocID |
| 1336 | gemPortID := flowContext.gemPortID |
| 1337 | logicalFlow := flowContext.logicalFlow |
| 1338 | classifier := flowContext.classifier |
| 1339 | action := flowContext.action |
| 1340 | |
Marcos Aurelio Carrero (Furukawa) | 388fb0a | 2021-02-04 18:05:11 -0300 | [diff] [blame] | 1341 | logger.Infow(ctx, "adding-ethType-flow-to-device", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1342 | log.Fields{ |
| 1343 | "intf-id": intfID, |
| 1344 | "onu-id": onuID, |
| 1345 | "port-no": portNo, |
| 1346 | "alloc-id": allocID, |
| 1347 | "gemport-id": gemPortID, |
| 1348 | "vlan-id": vlanID, |
Marcos Aurelio Carrero (Furukawa) | 388fb0a | 2021-02-04 18:05:11 -0300 | [diff] [blame] | 1349 | "flow": logicalFlow, |
| 1350 | "ethType": ethType}) |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 1351 | |
| 1352 | uplinkClassifier := make(map[string]interface{}) |
| 1353 | uplinkAction := make(map[string]interface{}) |
Girish Gowdra | 3d63303 | 2019-12-10 16:37:05 +0530 | [diff] [blame] | 1354 | |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 1355 | // Fill Classfier |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 1356 | uplinkClassifier[EthType] = ethType |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1357 | uplinkClassifier[PacketTagType] = SingleTag |
| 1358 | uplinkClassifier[VlanVid] = vlanID |
Gamze Abaka | 724d085 | 2020-03-18 12:10:24 +0000 | [diff] [blame] | 1359 | uplinkClassifier[VlanPcp] = classifier[VlanPcp] |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 1360 | // Fill action |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1361 | uplinkAction[TrapToHost] = true |
yasin sapli | bddc2d7 | 2022-02-08 13:10:17 +0000 | [diff] [blame] | 1362 | present, err := f.resourceMgr.IsFlowOnKvStore(ctx, int32(onuID), logicalFlow.Id) |
yasin sapli | d056627 | 2021-12-21 09:10:30 +0000 | [diff] [blame] | 1363 | if present { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1364 | logger.Infow(ctx, "flow-exists-not-re-adding", log.Fields{ |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1365 | "device-id": f.deviceHandler.device.Id, |
| 1366 | "onu-id": onuID, |
Marcos Aurelio Carrero (Furukawa) | 388fb0a | 2021-02-04 18:05:11 -0300 | [diff] [blame] | 1367 | "intf-id": intfID, |
| 1368 | "ethType": ethType}) |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1369 | return nil |
yasin sapli | d056627 | 2021-12-21 09:10:30 +0000 | [diff] [blame] | 1370 | } else if err != nil { |
| 1371 | logger.Errorw(ctx, "aborting-addEthTypeBasedFlow--flow-may-already-exist", |
| 1372 | log.Fields{"intf-id": intfID, "onu-id": onuID, "flow-id": logicalFlow.Id}) |
| 1373 | return err |
Girish Gowdra | 3d63303 | 2019-12-10 16:37:05 +0530 | [diff] [blame] | 1374 | } |
Marcos Aurelio Carrero (Furukawa) | 388fb0a | 2021-02-04 18:05:11 -0300 | [diff] [blame] | 1375 | //Add Uplink EthType Flow |
| 1376 | logger.Debugw(ctx, "creating-ul-ethType-flow", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1377 | log.Fields{ |
| 1378 | "ul_classifier": uplinkClassifier, |
| 1379 | "ul_action": uplinkAction, |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 1380 | "uplinkFlowId": logicalFlow.Id, |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1381 | "device-id": f.deviceHandler.device.Id, |
| 1382 | "intf-id": intfID, |
| 1383 | "onu-id": onuID}) |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 1384 | |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1385 | classifierProto, err := makeOpenOltClassifierField(uplinkClassifier) |
| 1386 | if err != nil { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1387 | return olterrors.NewErrInvalidValue(log.Fields{ |
| 1388 | "classifier": uplinkClassifier, |
| 1389 | "device-id": f.deviceHandler.device.Id}, err).Log() |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 1390 | } |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1391 | logger.Debugw(ctx, "created-classifier-proto", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1392 | log.Fields{ |
| 1393 | "classifier": *classifierProto, |
| 1394 | "device-id": f.deviceHandler.device.Id}) |
Gamze Abaka | 724d085 | 2020-03-18 12:10:24 +0000 | [diff] [blame] | 1395 | actionProto, err := makeOpenOltActionField(uplinkAction, uplinkClassifier) |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1396 | if err != nil { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1397 | return olterrors.NewErrInvalidValue(log.Fields{"action": uplinkAction, "device-id": f.deviceHandler.device.Id}, err).Log() |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 1398 | } |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1399 | logger.Debugw(ctx, "created-action-proto", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1400 | log.Fields{ |
| 1401 | "action": *actionProto, |
| 1402 | "device-id": f.deviceHandler.device.Id}) |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1403 | networkIntfID, err := getNniIntfID(ctx, classifier, action) |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 1404 | if err != nil { |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 1405 | return olterrors.NewErrNotFound("nni-interface-id", log.Fields{ |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1406 | "classifier": classifier, |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1407 | "action": action, |
| 1408 | "device-id": f.deviceHandler.device.Id}, |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1409 | err).Log() |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 1410 | } |
| 1411 | |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1412 | upstreamFlow := openoltpb2.Flow{AccessIntfId: int32(intfID), |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1413 | OnuId: int32(onuID), |
| 1414 | UniId: int32(uniID), |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 1415 | FlowId: logicalFlow.Id, |
David K. Bainbridge | 82efc49 | 2019-09-04 09:57:11 -0700 | [diff] [blame] | 1416 | FlowType: Upstream, |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1417 | AllocId: int32(allocID), |
| 1418 | NetworkIntfId: int32(networkIntfID), |
| 1419 | GemportId: int32(gemPortID), |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 1420 | Classifier: classifierProto, |
| 1421 | Action: actionProto, |
| 1422 | Priority: int32(logicalFlow.Priority), |
| 1423 | Cookie: logicalFlow.Cookie, |
Gamze Abaka | 78a1d2a | 2020-04-27 10:17:27 +0000 | [diff] [blame] | 1424 | PortNo: portNo, |
Gamze Abaka | 7650be6 | 2021-02-26 10:50:36 +0000 | [diff] [blame] | 1425 | TechProfileId: flowContext.tpID, |
| 1426 | ReplicateFlow: len(flowContext.pbitToGem) > 0, |
| 1427 | PbitToGemport: flowContext.pbitToGem, |
| 1428 | GemportToAes: flowContext.gemToAes, |
Gamze Abaka | 78a1d2a | 2020-04-27 10:17:27 +0000 | [diff] [blame] | 1429 | } |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1430 | if err := f.addFlowToDevice(ctx, logicalFlow, &upstreamFlow); err != nil { |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 1431 | return olterrors.NewErrFlowOp("add", logicalFlow.Id, log.Fields{"flow": upstreamFlow}, err).Log() |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1432 | } |
Marcos Aurelio Carrero (Furukawa) | 388fb0a | 2021-02-04 18:05:11 -0300 | [diff] [blame] | 1433 | logger.Infow(ctx, "ethType-ul-flow-added-to-device-successfully", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1434 | log.Fields{ |
| 1435 | "device-id": f.deviceHandler.device.Id, |
| 1436 | "onu-id": onuID, |
| 1437 | "intf-id": intfID, |
Marcos Aurelio Carrero (Furukawa) | 388fb0a | 2021-02-04 18:05:11 -0300 | [diff] [blame] | 1438 | "ethType": ethType, |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1439 | }) |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 1440 | |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1441 | return nil |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 1442 | } |
| 1443 | |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1444 | func makeOpenOltClassifierField(classifierInfo map[string]interface{}) (*openoltpb2.Classifier, error) { |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1445 | var classifier openoltpb2.Classifier |
David K. Bainbridge | 82efc49 | 2019-09-04 09:57:11 -0700 | [diff] [blame] | 1446 | |
| 1447 | classifier.EthType, _ = classifierInfo[EthType].(uint32) |
| 1448 | classifier.IpProto, _ = classifierInfo[IPProto].(uint32) |
| 1449 | if vlanID, ok := classifierInfo[VlanVid].(uint32); ok { |
Andrea Campanella | 7acc0b9 | 2020-02-14 09:20:49 +0100 | [diff] [blame] | 1450 | if vlanID != ReservedVlan { |
| 1451 | vid := vlanID & VlanvIDMask |
Harsh Awasthi | ea45af7 | 2019-08-26 02:39:00 -0400 | [diff] [blame] | 1452 | classifier.OVid = vid |
| 1453 | } |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 1454 | } |
Andrea Campanella | faa4215 | 2021-10-28 11:50:56 +0530 | [diff] [blame] | 1455 | // The classifierInfo[Metadata] carries the vlan that the OLT see when it receives packet from the ONU |
David K. Bainbridge | 82efc49 | 2019-09-04 09:57:11 -0700 | [diff] [blame] | 1456 | if metadata, ok := classifierInfo[Metadata].(uint64); ok { |
| 1457 | vid := uint32(metadata) |
Andrea Campanella | faa4215 | 2021-10-28 11:50:56 +0530 | [diff] [blame] | 1458 | // Set the OVid or IVid classifier based on the whether OLT is using a transparent tag or not |
| 1459 | // If OLT is using transparent tag mechanism, then it classifies whatever tag it sees to/from ONU which |
| 1460 | //is OVid from the perspective of the OLT. When OLT also places or pops the outer tag, then classifierInfo[Metadata] |
| 1461 | // becomes the IVid. |
| 1462 | if classifier.OVid != 0 && classifier.OVid != ReservedVlan { // This is case when classifier.OVid is not set |
| 1463 | if vid != ReservedVlan { |
| 1464 | classifier.IVid = vid |
| 1465 | } |
| 1466 | } else { |
| 1467 | if vid != ReservedVlan { |
| 1468 | classifier.OVid = vid |
| 1469 | } |
Harsh Awasthi | ea45af7 | 2019-08-26 02:39:00 -0400 | [diff] [blame] | 1470 | } |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 1471 | } |
Girish Gowdra | fae935c | 2020-02-17 19:21:44 +0530 | [diff] [blame] | 1472 | // Use VlanPCPMask (0xff) to signify NO PCP. Else use valid PCP (0 to 7) |
David K. Bainbridge | 82efc49 | 2019-09-04 09:57:11 -0700 | [diff] [blame] | 1473 | if vlanPcp, ok := classifierInfo[VlanPcp].(uint32); ok { |
Girish Gowdra | fae935c | 2020-02-17 19:21:44 +0530 | [diff] [blame] | 1474 | classifier.OPbits = vlanPcp |
| 1475 | } else { |
| 1476 | classifier.OPbits = VlanPCPMask |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 1477 | } |
David K. Bainbridge | 82efc49 | 2019-09-04 09:57:11 -0700 | [diff] [blame] | 1478 | classifier.SrcPort, _ = classifierInfo[UDPSrc].(uint32) |
| 1479 | classifier.DstPort, _ = classifierInfo[UDPDst].(uint32) |
| 1480 | classifier.DstIp, _ = classifierInfo[Ipv4Dst].(uint32) |
| 1481 | classifier.SrcIp, _ = classifierInfo[Ipv4Src].(uint32) |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 1482 | classifier.DstMac, _ = classifierInfo[EthDst].([]uint8) |
Girish Gowdra | ffa52e5 | 2022-02-16 15:48:10 -0800 | [diff] [blame^] | 1483 | classifier.SrcMac, _ = classifierInfo[EthSrc].([]uint8) |
David K. Bainbridge | 82efc49 | 2019-09-04 09:57:11 -0700 | [diff] [blame] | 1484 | if pktTagType, ok := classifierInfo[PacketTagType].(string); ok { |
| 1485 | classifier.PktTagType = pktTagType |
| 1486 | |
| 1487 | switch pktTagType { |
| 1488 | case SingleTag: |
| 1489 | case DoubleTag: |
| 1490 | case Untagged: |
| 1491 | default: |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 1492 | return nil, olterrors.NewErrInvalidValue(log.Fields{"packet-tag-type": pktTagType}, nil) |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 1493 | } |
| 1494 | } |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1495 | return &classifier, nil |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 1496 | } |
| 1497 | |
Gamze Abaka | 724d085 | 2020-03-18 12:10:24 +0000 | [diff] [blame] | 1498 | func makeOpenOltActionField(actionInfo map[string]interface{}, classifierInfo map[string]interface{}) (*openoltpb2.Action, error) { |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1499 | var actionCmd openoltpb2.ActionCmd |
| 1500 | var action openoltpb2.Action |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 1501 | action.Cmd = &actionCmd |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1502 | if _, ok := actionInfo[PopVlan]; ok { |
Girish Gowdra | ffa52e5 | 2022-02-16 15:48:10 -0800 | [diff] [blame^] | 1503 | // Pop outer vid |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 1504 | action.Cmd.RemoveOuterTag = true |
Gamze Abaka | 724d085 | 2020-03-18 12:10:24 +0000 | [diff] [blame] | 1505 | if _, ok := actionInfo[VlanPcp]; ok { |
Girish Gowdra | ffa52e5 | 2022-02-16 15:48:10 -0800 | [diff] [blame^] | 1506 | // Remark inner pbit |
Gamze Abaka | 724d085 | 2020-03-18 12:10:24 +0000 | [diff] [blame] | 1507 | action.Cmd.RemarkInnerPbits = true |
| 1508 | action.IPbits = actionInfo[VlanPcp].(uint32) |
| 1509 | if _, ok := actionInfo[VlanVid]; ok { |
Girish Gowdra | ffa52e5 | 2022-02-16 15:48:10 -0800 | [diff] [blame^] | 1510 | // Remark inner vid |
Gamze Abaka | 724d085 | 2020-03-18 12:10:24 +0000 | [diff] [blame] | 1511 | action.Cmd.TranslateInnerTag = true |
| 1512 | action.IVid = actionInfo[VlanVid].(uint32) |
| 1513 | } |
| 1514 | } |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1515 | } else if _, ok := actionInfo[PushVlan]; ok { |
Girish Gowdra | ffa52e5 | 2022-02-16 15:48:10 -0800 | [diff] [blame^] | 1516 | // push outer vid |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1517 | action.OVid = actionInfo[VlanVid].(uint32) |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 1518 | action.Cmd.AddOuterTag = true |
Gamze Abaka | 724d085 | 2020-03-18 12:10:24 +0000 | [diff] [blame] | 1519 | if _, ok := actionInfo[VlanPcp]; ok { |
Girish Gowdra | ffa52e5 | 2022-02-16 15:48:10 -0800 | [diff] [blame^] | 1520 | // translate outer pbit |
Gamze Abaka | 724d085 | 2020-03-18 12:10:24 +0000 | [diff] [blame] | 1521 | action.OPbits = actionInfo[VlanPcp].(uint32) |
| 1522 | action.Cmd.RemarkOuterPbits = true |
| 1523 | if _, ok := classifierInfo[VlanVid]; ok { |
Girish Gowdra | ffa52e5 | 2022-02-16 15:48:10 -0800 | [diff] [blame^] | 1524 | // translate inner vid |
Gamze Abaka | 724d085 | 2020-03-18 12:10:24 +0000 | [diff] [blame] | 1525 | action.IVid = classifierInfo[VlanVid].(uint32) |
| 1526 | action.Cmd.TranslateInnerTag = true |
| 1527 | } |
| 1528 | } |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1529 | } else if _, ok := actionInfo[TrapToHost]; ok { |
| 1530 | action.Cmd.TrapToHost = actionInfo[TrapToHost].(bool) |
Girish Gowdra | ffa52e5 | 2022-02-16 15:48:10 -0800 | [diff] [blame^] | 1531 | } else if _, ok := actionInfo[VlanVid]; ok { |
| 1532 | // Translate outer vid |
| 1533 | action.Cmd.TranslateOuterTag = true |
| 1534 | action.OVid = actionInfo[VlanVid].(uint32) |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 1535 | } |
Andrea Campanella | faa4215 | 2021-10-28 11:50:56 +0530 | [diff] [blame] | 1536 | // When OLT is transparent to vlans no-action is valid. |
| 1537 | /* |
| 1538 | else { |
| 1539 | return nil, olterrors.NewErrInvalidValue(log.Fields{"action-command": actionInfo}, nil) |
| 1540 | } |
| 1541 | */ |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1542 | return &action, nil |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 1543 | } |
| 1544 | |
Matteo Scandolo | d625b4c | 2020-04-02 16:16:01 -0700 | [diff] [blame] | 1545 | // getTPpath return the ETCD path for a given UNI port |
yasin sapli | bddc2d7 | 2022-02-08 13:10:17 +0000 | [diff] [blame] | 1546 | func (f *OpenOltFlowMgr) getTPpath(ctx context.Context, uniPath string, TpID uint32) string { |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 1547 | return f.techprofile.GetTechProfileInstanceKey(ctx, TpID, uniPath) |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 1548 | } |
| 1549 | |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 1550 | // DeleteTechProfileInstances removes the tech profile instances from persistent storage |
Girish Gowdra | 197acc1 | 2021-08-16 10:59:45 -0700 | [diff] [blame] | 1551 | // We also force release scheduler and queues associated with the tp instance. Theoretically there could be |
| 1552 | // an issue if the upstream scheduler (DBA) is shared across multiple UNI and we force release it, given that |
| 1553 | // this function is only meant to clean up TP instances of a given UNI. But in practicality this routine |
| 1554 | // is only meant to be called when the clean up of resource for the whole ONU is taking place. |
| 1555 | // The reason for introducing the force cleanup of scheduler and queues (on the OLT) was introduced here |
| 1556 | // because it was observed that if the ONU device was deleted too soon after the flows were |
| 1557 | // unprovisioned on that ONU, the scheduler and queue removal pertinent to that ONU would remain |
| 1558 | // uncleaned on the OLT. So we force clean up here and ignore any error that OLT returns during the |
| 1559 | // force cleanup (possible if the OLT has already cleared those resources). |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 1560 | func (f *OpenOltFlowMgr) DeleteTechProfileInstances(ctx context.Context, intfID uint32, onuID uint32, uniID uint32) error { |
yasin sapli | bddc2d7 | 2022-02-08 13:10:17 +0000 | [diff] [blame] | 1561 | tpIDList := f.resourceMgr.GetTechProfileIDForOnu(ctx, onuID, uniID) |
Matteo Scandolo | d625b4c | 2020-04-02 16:16:01 -0700 | [diff] [blame] | 1562 | uniPortName := getUniPortPath(f.deviceHandler.device.Id, intfID, int32(onuID), int32(uniID)) |
| 1563 | |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 1564 | for _, tpID := range tpIDList { |
Girish Gowdra | 197acc1 | 2021-08-16 10:59:45 -0700 | [diff] [blame] | 1565 | |
| 1566 | // Force cleanup scheduler/queues -- start |
Mahir Gunyel | 85f61c1 | 2021-10-06 11:53:45 -0700 | [diff] [blame] | 1567 | uniPortNum := plt.MkUniPortNum(ctx, intfID, onuID, uniID) |
Girish Gowdra | 197acc1 | 2021-08-16 10:59:45 -0700 | [diff] [blame] | 1568 | uni := getUniPortPath(f.deviceHandler.device.Id, intfID, int32(onuID), int32(uniID)) |
yasin sapli | bddc2d7 | 2022-02-08 13:10:17 +0000 | [diff] [blame] | 1569 | tpPath := f.getTPpath(ctx, uni, tpID) |
Girish Gowdra | 197acc1 | 2021-08-16 10:59:45 -0700 | [diff] [blame] | 1570 | tpInst, err := f.techprofile.GetTPInstance(ctx, tpPath) |
| 1571 | if err != nil || tpInst == nil { // This should not happen, something wrong in KV backend transaction |
| 1572 | logger.Warnw(ctx, "tech-profile-not-in-kv-store", |
| 1573 | log.Fields{ |
| 1574 | "tp-id": tpID, |
| 1575 | "path": tpPath}) |
| 1576 | } |
| 1577 | switch tpInstance := tpInst.(type) { |
| 1578 | case *tp_pb.TechProfileInstance: |
| 1579 | f.forceRemoveSchedulerQueues(ctx, schedQueue{direction: tp_pb.Direction_UPSTREAM, intfID: intfID, onuID: onuID, uniID: uniID, tpID: tpID, uniPort: uniPortNum, tpInst: tpInstance}) |
| 1580 | f.forceRemoveSchedulerQueues(ctx, schedQueue{direction: tp_pb.Direction_DOWNSTREAM, intfID: intfID, onuID: onuID, uniID: uniID, tpID: tpID, uniPort: uniPortNum, tpInst: tpInstance}) |
| 1581 | } |
| 1582 | // Force cleanup scheduler/queues -- end |
| 1583 | |
| 1584 | // Now remove the tp instance |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 1585 | if err := f.DeleteTechProfileInstance(ctx, intfID, onuID, uniID, uniPortName, tpID); err != nil { |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 1586 | logger.Errorw(ctx, "delete-tech-profile-failed", log.Fields{"err": err, "device-id": f.deviceHandler.device.Id}) |
Girish Gowdra | 5493426 | 2019-11-13 14:19:55 +0530 | [diff] [blame] | 1587 | // return err |
| 1588 | // We should continue to delete tech-profile instances for other TP IDs |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 1589 | } |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 1590 | logger.Debugw(ctx, "tech-profile-instance-deleted", log.Fields{"device-id": f.deviceHandler.device.Id, "uniPortName": uniPortName, "tp-id": tpID}) |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 1591 | } |
| 1592 | return nil |
| 1593 | } |
| 1594 | |
| 1595 | // DeleteTechProfileInstance removes the tech profile instance from persistent storage |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 1596 | func (f *OpenOltFlowMgr) DeleteTechProfileInstance(ctx context.Context, intfID uint32, onuID uint32, uniID uint32, uniPortName string, tpID uint32) error { |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 1597 | if uniPortName == "" { |
Matteo Scandolo | d625b4c | 2020-04-02 16:16:01 -0700 | [diff] [blame] | 1598 | uniPortName = getUniPortPath(f.deviceHandler.device.Id, intfID, int32(onuID), int32(uniID)) |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 1599 | } |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 1600 | if err := f.techprofile.DeleteTechProfileInstance(ctx, tpID, uniPortName); err != nil { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1601 | return olterrors.NewErrAdapter("failed-to-delete-tp-instance-from-kv-store", |
| 1602 | log.Fields{ |
| 1603 | "tp-id": tpID, |
| 1604 | "uni-port-name": uniPortName, |
| 1605 | "device-id": f.deviceHandler.device.Id}, err) |
Devmalya Paul | 495b94a | 2019-08-27 19:42:00 -0400 | [diff] [blame] | 1606 | } |
| 1607 | return nil |
| 1608 | } |
| 1609 | |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1610 | func (f *OpenOltFlowMgr) addFlowToDevice(ctx context.Context, logicalFlow *ofp.OfpFlowStats, deviceFlow *openoltpb2.Flow) error { |
Daniele Rossi | 22db98e | 2019-07-11 11:50:00 +0000 | [diff] [blame] | 1611 | |
| 1612 | var intfID uint32 |
| 1613 | /* For flows which trap out of the NNI, the AccessIntfId is invalid |
| 1614 | (set to -1). In such cases, we need to refer to the NetworkIntfId . |
| 1615 | */ |
| 1616 | if deviceFlow.AccessIntfId != -1 { |
| 1617 | intfID = uint32(deviceFlow.AccessIntfId) |
| 1618 | } else { |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 1619 | // We need to log the valid interface ID. |
| 1620 | // For trap-on-nni flows, the access_intf_id is invalid (-1), so choose the network_intf_id. |
Daniele Rossi | 22db98e | 2019-07-11 11:50:00 +0000 | [diff] [blame] | 1621 | intfID = uint32(deviceFlow.NetworkIntfId) |
| 1622 | } |
| 1623 | |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1624 | logger.Debugw(ctx, "sending-flow-to-device-via-grpc", log.Fields{ |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1625 | "flow": *deviceFlow, |
| 1626 | "device-id": f.deviceHandler.device.Id, |
| 1627 | "intf-id": intfID}) |
Neha Sharma | 8f4e432 | 2020-08-06 10:51:53 +0000 | [diff] [blame] | 1628 | _, err := f.deviceHandler.Client.FlowAdd(log.WithSpanFromContext(context.Background(), ctx), deviceFlow) |
Daniele Rossi | 22db98e | 2019-07-11 11:50:00 +0000 | [diff] [blame] | 1629 | |
| 1630 | st, _ := status.FromError(err) |
| 1631 | if st.Code() == codes.AlreadyExists { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1632 | logger.Debug(ctx, "flow-already-exists", log.Fields{ |
Matteo Scandolo | d625b4c | 2020-04-02 16:16:01 -0700 | [diff] [blame] | 1633 | "err": err, |
| 1634 | "deviceFlow": deviceFlow, |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1635 | "device-id": f.deviceHandler.device.Id, |
| 1636 | "intf-id": intfID}) |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1637 | return nil |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 1638 | } |
Daniele Rossi | 22db98e | 2019-07-11 11:50:00 +0000 | [diff] [blame] | 1639 | |
| 1640 | if err != nil { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1641 | logger.Errorw(ctx, "failed-to-add-flow-to-device", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1642 | log.Fields{"err": err, |
| 1643 | "device-flow": deviceFlow, |
| 1644 | "device-id": f.deviceHandler.device.Id, |
| 1645 | "intf-id": intfID}) |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1646 | return err |
Daniele Rossi | 22db98e | 2019-07-11 11:50:00 +0000 | [diff] [blame] | 1647 | } |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1648 | logger.Infow(ctx, "flow-added-to-device-successfully ", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1649 | log.Fields{ |
| 1650 | "flow": *deviceFlow, |
| 1651 | "device-id": f.deviceHandler.device.Id, |
| 1652 | "intf-id": intfID}) |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 1653 | |
yasin sapli | d056627 | 2021-12-21 09:10:30 +0000 | [diff] [blame] | 1654 | if err := f.registerFlow(ctx, logicalFlow, deviceFlow); err != nil { |
| 1655 | logger.Errorw(ctx, "failed-to-register-flow", log.Fields{"err": err}) |
| 1656 | return err |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 1657 | } |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1658 | return nil |
Manjunath Vanarajulu | 28c3e82 | 2019-05-16 11:14:28 -0400 | [diff] [blame] | 1659 | } |
| 1660 | |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1661 | func (f *OpenOltFlowMgr) removeFlowFromDevice(ctx context.Context, deviceFlow *openoltpb2.Flow, ofFlowID uint64) error { |
| 1662 | logger.Debugw(ctx, "sending-flow-to-device-via-grpc", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1663 | log.Fields{ |
| 1664 | "flow": *deviceFlow, |
| 1665 | "device-id": f.deviceHandler.device.Id}) |
Neha Sharma | 8f4e432 | 2020-08-06 10:51:53 +0000 | [diff] [blame] | 1666 | _, err := f.deviceHandler.Client.FlowRemove(log.WithSpanFromContext(context.Background(), ctx), deviceFlow) |
Manjunath Vanarajulu | 28c3e82 | 2019-05-16 11:14:28 -0400 | [diff] [blame] | 1667 | if err != nil { |
serkant.uluderya | 245caba | 2019-09-24 23:15:29 -0700 | [diff] [blame] | 1668 | if f.deviceHandler.device.ConnectStatus == common.ConnectStatus_UNREACHABLE { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1669 | logger.Warnw(ctx, "can-not-remove-flow-from-device--unreachable", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1670 | log.Fields{ |
| 1671 | "err": err, |
| 1672 | "deviceFlow": deviceFlow, |
| 1673 | "device-id": f.deviceHandler.device.Id}) |
serkant.uluderya | 245caba | 2019-09-24 23:15:29 -0700 | [diff] [blame] | 1674 | //Assume the flow is removed |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1675 | return nil |
serkant.uluderya | 245caba | 2019-09-24 23:15:29 -0700 | [diff] [blame] | 1676 | } |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 1677 | return olterrors.NewErrFlowOp("remove", deviceFlow.FlowId, log.Fields{"deviceFlow": deviceFlow}, err) |
serkant.uluderya | 245caba | 2019-09-24 23:15:29 -0700 | [diff] [blame] | 1678 | |
Manjunath Vanarajulu | 28c3e82 | 2019-05-16 11:14:28 -0400 | [diff] [blame] | 1679 | } |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1680 | logger.Infow(ctx, "flow-removed-from-device-successfully", log.Fields{ |
Matteo Scandolo | 9218624 | 2020-06-12 10:54:18 -0700 | [diff] [blame] | 1681 | "of-flow-id": ofFlowID, |
| 1682 | "flow": *deviceFlow, |
| 1683 | "device-id": f.deviceHandler.device.Id, |
| 1684 | }) |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1685 | return nil |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 1686 | } |
| 1687 | |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1688 | func (f *OpenOltFlowMgr) addLLDPFlow(ctx context.Context, flow *ofp.OfpFlowStats, portNo uint32) error { |
Humera Kouser | 94d7a84 | 2019-08-25 19:04:32 -0400 | [diff] [blame] | 1689 | |
| 1690 | classifierInfo := make(map[string]interface{}) |
| 1691 | actionInfo := make(map[string]interface{}) |
| 1692 | |
| 1693 | classifierInfo[EthType] = uint32(LldpEthType) |
| 1694 | classifierInfo[PacketTagType] = Untagged |
| 1695 | actionInfo[TrapToHost] = true |
| 1696 | |
| 1697 | // LLDP flow is installed to trap LLDP packets on the NNI port. |
| 1698 | // We manage flow_id resource pool on per PON port basis. |
| 1699 | // Since this situation is tricky, as a hack, we pass the NNI port |
| 1700 | // index (network_intf_id) as PON port Index for the flow_id resource |
| 1701 | // pool. Also, there is no ONU Id available for trapping LLDP packets |
| 1702 | // on NNI port, use onu_id as -1 (invalid) |
| 1703 | // ****************** CAVEAT ******************* |
| 1704 | // This logic works if the NNI Port Id falls within the same valid |
| 1705 | // range of PON Port Ids. If this doesn't work for some OLT Vendor |
| 1706 | // we need to have a re-look at this. |
| 1707 | // ********************************************* |
| 1708 | |
| 1709 | var onuID = -1 |
| 1710 | var uniID = -1 |
| 1711 | var gemPortID = -1 |
| 1712 | |
Mahir Gunyel | 85f61c1 | 2021-10-06 11:53:45 -0700 | [diff] [blame] | 1713 | networkInterfaceID, err := plt.IntfIDFromNniPortNum(ctx, portNo) |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1714 | if err != nil { |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 1715 | return olterrors.NewErrInvalidValue(log.Fields{"nni-port-number": portNo}, err).Log() |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1716 | } |
yasin sapli | bddc2d7 | 2022-02-08 13:10:17 +0000 | [diff] [blame] | 1717 | present, err := f.resourceMgr.IsFlowOnKvStore(ctx, int32(onuID), flow.Id) |
yasin sapli | d056627 | 2021-12-21 09:10:30 +0000 | [diff] [blame] | 1718 | if present { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1719 | logger.Infow(ctx, "flow-exists--not-re-adding", log.Fields{"device-id": f.deviceHandler.device.Id}) |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1720 | return nil |
yasin sapli | d056627 | 2021-12-21 09:10:30 +0000 | [diff] [blame] | 1721 | } else if err != nil { |
| 1722 | logger.Errorw(ctx, "aborting-addLLDPFlow--flow-may-already-exist", |
| 1723 | log.Fields{"intf-id": networkInterfaceID, "onu-id": onuID, "flow-id": flow.Id}) |
| 1724 | return err |
Humera Kouser | 94d7a84 | 2019-08-25 19:04:32 -0400 | [diff] [blame] | 1725 | } |
Humera Kouser | 94d7a84 | 2019-08-25 19:04:32 -0400 | [diff] [blame] | 1726 | |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1727 | classifierProto, err := makeOpenOltClassifierField(classifierInfo) |
| 1728 | if err != nil { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1729 | return olterrors.NewErrInvalidValue( |
| 1730 | log.Fields{ |
| 1731 | "classifier": classifierInfo, |
| 1732 | "device-id": f.deviceHandler.device.Id}, err) |
Humera Kouser | 94d7a84 | 2019-08-25 19:04:32 -0400 | [diff] [blame] | 1733 | } |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1734 | logger.Debugw(ctx, "created-classifier-proto", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1735 | log.Fields{ |
| 1736 | "classifier": *classifierProto, |
| 1737 | "device-id": f.deviceHandler.device.Id}) |
Gamze Abaka | 724d085 | 2020-03-18 12:10:24 +0000 | [diff] [blame] | 1738 | actionProto, err := makeOpenOltActionField(actionInfo, classifierInfo) |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1739 | if err != nil { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1740 | return olterrors.NewErrInvalidValue( |
| 1741 | log.Fields{ |
| 1742 | "action": actionInfo, |
| 1743 | "device-id": f.deviceHandler.device.Id}, err) |
Humera Kouser | 94d7a84 | 2019-08-25 19:04:32 -0400 | [diff] [blame] | 1744 | } |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1745 | logger.Debugw(ctx, "created-action-proto", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1746 | log.Fields{ |
| 1747 | "action": *actionProto, |
| 1748 | "device-id": f.deviceHandler.device.Id}) |
Humera Kouser | 94d7a84 | 2019-08-25 19:04:32 -0400 | [diff] [blame] | 1749 | |
| 1750 | downstreamflow := openoltpb2.Flow{AccessIntfId: int32(-1), // AccessIntfId not required |
| 1751 | OnuId: int32(onuID), // OnuId not required |
| 1752 | UniId: int32(uniID), // UniId not used |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 1753 | FlowId: flow.Id, |
Humera Kouser | 94d7a84 | 2019-08-25 19:04:32 -0400 | [diff] [blame] | 1754 | FlowType: Downstream, |
| 1755 | NetworkIntfId: int32(networkInterfaceID), |
| 1756 | GemportId: int32(gemPortID), |
| 1757 | Classifier: classifierProto, |
| 1758 | Action: actionProto, |
| 1759 | Priority: int32(flow.Priority), |
| 1760 | Cookie: flow.Cookie, |
| 1761 | PortNo: portNo} |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1762 | if err := f.addFlowToDevice(ctx, flow, &downstreamflow); err != nil { |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 1763 | return olterrors.NewErrFlowOp("add", flow.Id, |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1764 | log.Fields{ |
| 1765 | "flow": downstreamflow, |
| 1766 | "device-id": f.deviceHandler.device.Id}, err) |
Humera Kouser | 94d7a84 | 2019-08-25 19:04:32 -0400 | [diff] [blame] | 1767 | } |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1768 | logger.Infow(ctx, "lldp-trap-on-nni-flow-added-to-device-successfully", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1769 | log.Fields{ |
| 1770 | "device-id": f.deviceHandler.device.Id, |
| 1771 | "onu-id": onuID, |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 1772 | "flow-id": flow.Id}) |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 1773 | |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1774 | return nil |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 1775 | } |
| 1776 | |
Matteo Scandolo | d625b4c | 2020-04-02 16:16:01 -0700 | [diff] [blame] | 1777 | func getUniPortPath(oltID string, intfID uint32, onuID int32, uniID int32) string { |
| 1778 | return fmt.Sprintf("olt-{%s}/pon-{%d}/onu-{%d}/uni-{%d}", oltID, intfID, onuID, uniID) |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 1779 | } |
| 1780 | |
Mahir Gunyel | 0f89fd2 | 2020-04-11 18:24:42 -0700 | [diff] [blame] | 1781 | //getOnuDevice to fetch onu from cache or core. |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1782 | func (f *OpenOltFlowMgr) getOnuDevice(ctx context.Context, intfID uint32, onuID uint32) (*OnuDevice, error) { |
Mahir Gunyel | 0f89fd2 | 2020-04-11 18:24:42 -0700 | [diff] [blame] | 1783 | onuKey := f.deviceHandler.formOnuKey(intfID, onuID) |
| 1784 | onuDev, ok := f.deviceHandler.onus.Load(onuKey) |
| 1785 | if !ok { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1786 | logger.Debugw(ctx, "couldnt-find-onu-in-cache", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1787 | log.Fields{ |
| 1788 | "intf-id": intfID, |
| 1789 | "onu-id": onuID, |
| 1790 | "device-id": f.deviceHandler.device.Id}) |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1791 | onuDevice, err := f.getChildDevice(ctx, intfID, onuID) |
Mahir Gunyel | 0f89fd2 | 2020-04-11 18:24:42 -0700 | [diff] [blame] | 1792 | if err != nil { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1793 | return nil, olterrors.NewErrNotFound("onu-child-device", |
| 1794 | log.Fields{ |
| 1795 | "onu-id": onuID, |
| 1796 | "intf-id": intfID, |
| 1797 | "device-id": f.deviceHandler.device.Id}, err) |
Mahir Gunyel | 0f89fd2 | 2020-04-11 18:24:42 -0700 | [diff] [blame] | 1798 | } |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 1799 | onuDev = NewOnuDevice(onuDevice.Id, onuDevice.Type, onuDevice.SerialNumber, onuDevice.ProxyAddress.OnuId, onuDevice.ProxyAddress.ChannelId, onuDevice.ProxyAddress.DeviceId, false, onuDevice.AdapterEndpoint) |
Mahir Gunyel | 0f89fd2 | 2020-04-11 18:24:42 -0700 | [diff] [blame] | 1800 | //better to ad the device to cache here. |
| 1801 | f.deviceHandler.StoreOnuDevice(onuDev.(*OnuDevice)) |
| 1802 | } else { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1803 | logger.Debugw(ctx, "found-onu-in-cache", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1804 | log.Fields{ |
| 1805 | "intf-id": intfID, |
| 1806 | "onu-id": onuID, |
| 1807 | "device-id": f.deviceHandler.device.Id}) |
Mahir Gunyel | 0f89fd2 | 2020-04-11 18:24:42 -0700 | [diff] [blame] | 1808 | } |
| 1809 | |
| 1810 | return onuDev.(*OnuDevice), nil |
| 1811 | } |
| 1812 | |
| 1813 | //getChildDevice to fetch onu |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1814 | func (f *OpenOltFlowMgr) getChildDevice(ctx context.Context, intfID uint32, onuID uint32) (*voltha.Device, error) { |
| 1815 | logger.Infow(ctx, "GetChildDevice", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1816 | log.Fields{ |
| 1817 | "pon-port": intfID, |
| 1818 | "onu-id": onuID, |
| 1819 | "device-id": f.deviceHandler.device.Id}) |
Mahir Gunyel | 85f61c1 | 2021-10-06 11:53:45 -0700 | [diff] [blame] | 1820 | parentPortNo := plt.IntfIDToPortNo(intfID, voltha.Port_PON_OLT) |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1821 | onuDevice, err := f.deviceHandler.GetChildDevice(ctx, parentPortNo, onuID) |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 1822 | if err != nil { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1823 | return nil, olterrors.NewErrNotFound("onu", |
| 1824 | log.Fields{ |
| 1825 | "interface-id": parentPortNo, |
| 1826 | "onu-id": onuID, |
| 1827 | "device-id": f.deviceHandler.device.Id}, |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 1828 | err) |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 1829 | } |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1830 | logger.Infow(ctx, "successfully-received-child-device-from-core", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1831 | log.Fields{ |
| 1832 | "device-id": f.deviceHandler.device.Id, |
| 1833 | "child_device_id": onuDevice.Id, |
| 1834 | "child_device_sn": onuDevice.SerialNumber}) |
Manikkaraj k | 884c124 | 2019-04-11 16:26:42 +0530 | [diff] [blame] | 1835 | return onuDevice, nil |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 1836 | } |
| 1837 | |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1838 | func (f *OpenOltFlowMgr) sendDeleteGemPortToChild(ctx context.Context, intfID uint32, onuID uint32, uniID uint32, gemPortID uint32, tpPath string) error { |
| 1839 | onuDev, err := f.getOnuDevice(ctx, intfID, onuID) |
Girish Gowdra | 6b13058 | 2019-11-20 16:45:20 +0530 | [diff] [blame] | 1840 | if err != nil { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1841 | logger.Debugw(ctx, "couldnt-find-onu-child-device", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1842 | log.Fields{ |
| 1843 | "intf-id": intfID, |
| 1844 | "onu-id": onuID, |
| 1845 | "uni-id": uniID, |
| 1846 | "device-id": f.deviceHandler.device.Id}) |
Mahir Gunyel | 0f89fd2 | 2020-04-11 18:24:42 -0700 | [diff] [blame] | 1847 | return err |
Girish Gowdra | 6b13058 | 2019-11-20 16:45:20 +0530 | [diff] [blame] | 1848 | } |
| 1849 | |
khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 1850 | delGemPortMsg := &ia.DeleteGemPortMessage{ |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 1851 | DeviceId: onuDev.deviceID, |
| 1852 | UniId: uniID, |
| 1853 | TpInstancePath: tpPath, |
| 1854 | GemPortId: gemPortID, |
| 1855 | } |
| 1856 | logger.Debugw(ctx, "sending-gem-port-delete-to-openonu-adapter", log.Fields{"msg": *delGemPortMsg, "child-device-id": onuDev.deviceID}) |
| 1857 | |
| 1858 | if err := f.deviceHandler.sendDeleteGemPortToChildAdapter(ctx, onuDev.adapterEndpoint, delGemPortMsg); err != nil { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1859 | return olterrors.NewErrCommunication("send-delete-gem-port-to-onu-adapter", |
| 1860 | log.Fields{ |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 1861 | "from-adapter": f.deviceHandler.openOLT.config.AdapterEndpoint, |
| 1862 | "to-adapter": onuDev.adapterEndpoint, |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1863 | "onu-id": onuDev.deviceID, |
| 1864 | "proxyDeviceID": onuDev.proxyDeviceID, |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 1865 | "device-id": f.deviceHandler.device.Id}, err) |
Girish Gowdra | 6b13058 | 2019-11-20 16:45:20 +0530 | [diff] [blame] | 1866 | } |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 1867 | |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1868 | logger.Infow(ctx, "success-sending-del-gem-port-to-onu-adapter", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1869 | log.Fields{ |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 1870 | "msg": delGemPortMsg, |
| 1871 | "from-adapter": f.deviceHandler.device.Type, |
| 1872 | "to-adapter": onuDev.deviceType, |
| 1873 | "device-id": f.deviceHandler.device.Id, |
| 1874 | "child-device-id": onuDev.deviceID}) |
Girish Gowdra | 6b13058 | 2019-11-20 16:45:20 +0530 | [diff] [blame] | 1875 | return nil |
| 1876 | } |
| 1877 | |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1878 | func (f *OpenOltFlowMgr) sendDeleteTcontToChild(ctx context.Context, intfID uint32, onuID uint32, uniID uint32, allocID uint32, tpPath string) error { |
| 1879 | onuDev, err := f.getOnuDevice(ctx, intfID, onuID) |
Girish Gowdra | 6b13058 | 2019-11-20 16:45:20 +0530 | [diff] [blame] | 1880 | if err != nil { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1881 | logger.Warnw(ctx, "couldnt-find-onu-child-device", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1882 | log.Fields{ |
| 1883 | "intf-id": intfID, |
| 1884 | "onu-id": onuID, |
| 1885 | "uni-id": uniID, |
| 1886 | "device-id": f.deviceHandler.device.Id}) |
Mahir Gunyel | 0f89fd2 | 2020-04-11 18:24:42 -0700 | [diff] [blame] | 1887 | return err |
Girish Gowdra | 6b13058 | 2019-11-20 16:45:20 +0530 | [diff] [blame] | 1888 | } |
| 1889 | |
khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 1890 | delTcontMsg := &ia.DeleteTcontMessage{ |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 1891 | DeviceId: onuDev.deviceID, |
| 1892 | UniId: uniID, |
| 1893 | TpInstancePath: tpPath, |
| 1894 | AllocId: allocID, |
| 1895 | } |
| 1896 | |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1897 | logger.Debugw(ctx, "sending-tcont-delete-to-openonu-adapter", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1898 | log.Fields{ |
| 1899 | "msg": *delTcontMsg, |
| 1900 | "device-id": f.deviceHandler.device.Id}) |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 1901 | |
| 1902 | if err := f.deviceHandler.sendDeleteTContToChildAdapter(ctx, onuDev.adapterEndpoint, delTcontMsg); err != nil { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1903 | return olterrors.NewErrCommunication("send-delete-tcont-to-onu-adapter", |
| 1904 | log.Fields{ |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 1905 | "from-adapter": f.deviceHandler.openOLT.config.AdapterEndpoint, |
| 1906 | "to-adapter": onuDev.adapterEndpoint, |
| 1907 | "onu-id": onuDev.deviceID, |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1908 | "proxyDeviceID": onuDev.proxyDeviceID, |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 1909 | "device-id": f.deviceHandler.device.Id}, err) |
| 1910 | |
Girish Gowdra | 6b13058 | 2019-11-20 16:45:20 +0530 | [diff] [blame] | 1911 | } |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 1912 | logger.Infow(ctx, "success-sending-del-tcont-to-onu-adapter", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 1913 | log.Fields{ |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 1914 | "msg": delTcontMsg, |
| 1915 | "device-id": f.deviceHandler.device.Id, |
| 1916 | "child-device-id": onuDev.deviceID}) |
Girish Gowdra | 6b13058 | 2019-11-20 16:45:20 +0530 | [diff] [blame] | 1917 | return nil |
| 1918 | } |
| 1919 | |
Abhilash Laxmeshwar | b7300fe | 2019-11-13 03:38:33 +0530 | [diff] [blame] | 1920 | //clearResources clears pon resources in kv store and the device |
Takahiro Suzuki | 2ba0e0b | 2020-06-05 14:23:03 -0700 | [diff] [blame] | 1921 | // nolint: gocyclo |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 1922 | func (f *OpenOltFlowMgr) clearResources(ctx context.Context, intfID uint32, onuID int32, uniID int32, |
Gamze Abaka | 411ef2f | 2021-11-22 08:38:08 +0000 | [diff] [blame] | 1923 | flowID uint64, portNum uint32, tpID uint32, sendDeleteGemRequest bool) error { |
Gamze Abaka | 745ccb7 | 2021-11-18 11:29:58 +0000 | [diff] [blame] | 1924 | |
| 1925 | logger.Debugw(ctx, "clearing-resources", log.Fields{"intfID": intfID, "onuID": onuID, "uniID": uniID, "tpID": tpID}) |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 1926 | |
Girish Gowdra | a482f27 | 2021-03-24 23:04:19 -0700 | [diff] [blame] | 1927 | uni := getUniPortPath(f.deviceHandler.device.Id, intfID, onuID, uniID) |
yasin sapli | bddc2d7 | 2022-02-08 13:10:17 +0000 | [diff] [blame] | 1928 | tpPath := f.getTPpath(ctx, uni, tpID) |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 1929 | logger.Debugw(ctx, "getting-techprofile-instance-for-subscriber", |
| 1930 | log.Fields{ |
| 1931 | "tpPath": tpPath, |
| 1932 | "device-id": f.deviceHandler.device.Id}) |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 1933 | |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 1934 | techprofileInst, err := f.techprofile.GetTPInstance(ctx, tpPath) |
Girish Gowdra | 78fd63d | 2021-10-18 14:34:53 -0700 | [diff] [blame] | 1935 | if err != nil || techprofileInst == nil { |
| 1936 | // The child device is possibly deleted which in turn had cleaned up all the resources (including tp instances), check.. |
| 1937 | childDevice, _ := f.getChildDevice(ctx, intfID, uint32(onuID)) // do not care about the error code |
| 1938 | if childDevice == nil { |
| 1939 | // happens when subscriber un-provision is immediately followed by child device delete |
| 1940 | // before all the flow removes are processed, the child device delete has already arrived and cleaned up all the resources |
| 1941 | logger.Warnw(ctx, "child device and its associated resources are already cleared", log.Fields{"intfID": intfID, "onuID": onuID, "uniID": uniID}) |
| 1942 | return nil |
| 1943 | } |
Elia Battiston | 2aaf434 | 2022-02-07 15:16:38 +0100 | [diff] [blame] | 1944 | // If the tech profile is not found, since we want to delete it, there is no need to throw an error |
| 1945 | _ = olterrors.NewErrNotFound("tech-profile-in-kv-store", |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 1946 | log.Fields{ |
| 1947 | "tp-id": tpID, |
Elia Battiston | 2aaf434 | 2022-02-07 15:16:38 +0100 | [diff] [blame] | 1948 | "path": tpPath}, err).Log() |
| 1949 | return nil |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 1950 | } |
Gamze Abaka | 745ccb7 | 2021-11-18 11:29:58 +0000 | [diff] [blame] | 1951 | |
| 1952 | var allGemPortsFree = true |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 1953 | switch techprofileInst := techprofileInst.(type) { |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 1954 | case *tp_pb.TechProfileInstance: |
Gamze Abaka | 745ccb7 | 2021-11-18 11:29:58 +0000 | [diff] [blame] | 1955 | for _, gemPort := range techprofileInst.UpstreamGemPortAttributeList { |
| 1956 | gemPortID := gemPort.GemportId |
yasin sapli | 9e4c509 | 2022-02-01 13:52:33 +0000 | [diff] [blame] | 1957 | used := f.resourceMgr.IsGemPortUsedByAnotherFlow(gemPortID, flowID) |
Gamze Abaka | 745ccb7 | 2021-11-18 11:29:58 +0000 | [diff] [blame] | 1958 | if used { |
yasin sapli | bddc2d7 | 2022-02-08 13:10:17 +0000 | [diff] [blame] | 1959 | flowIDs, err := f.resourceMgr.GetFlowIDsForGem(ctx, gemPortID) |
yasin sapli | 9e4c509 | 2022-02-01 13:52:33 +0000 | [diff] [blame] | 1960 | if err != nil { |
| 1961 | return err |
| 1962 | } |
Gamze Abaka | 745ccb7 | 2021-11-18 11:29:58 +0000 | [diff] [blame] | 1963 | for i, flowIDinMap := range flowIDs { |
| 1964 | if flowIDinMap == flowID { |
| 1965 | flowIDs = append(flowIDs[:i], flowIDs[i+1:]...) |
yasin sapli | bddc2d7 | 2022-02-08 13:10:17 +0000 | [diff] [blame] | 1966 | if err := f.resourceMgr.UpdateFlowIDsForGem(ctx, gemPortID, flowIDs); err != nil { |
Gamze Abaka | 745ccb7 | 2021-11-18 11:29:58 +0000 | [diff] [blame] | 1967 | return err |
| 1968 | } |
| 1969 | break |
| 1970 | } |
| 1971 | } |
| 1972 | logger.Debugw(ctx, "gem-port-id-is-still-used-by-other-flows", |
| 1973 | log.Fields{ |
| 1974 | "gemport-id": gemPortID, |
| 1975 | "usedByFlows": flowIDs, |
| 1976 | "currentFlow": flowID, |
| 1977 | "device-id": f.deviceHandler.device.Id}) |
| 1978 | allGemPortsFree = false |
| 1979 | } |
| 1980 | } |
| 1981 | if !allGemPortsFree { |
| 1982 | return nil |
| 1983 | } |
| 1984 | } |
| 1985 | |
| 1986 | logger.Debugw(ctx, "all-gem-ports-are-free-to-be-deleted", log.Fields{"intfID": intfID, "onuID": onuID, "uniID": uniID, "tpID": tpID}) |
Girish Gowdra | f3728b1 | 2022-02-02 21:46:51 -0800 | [diff] [blame] | 1987 | |
| 1988 | // Free TPInstance, TPID, GemPorts and Traffic Queues. AllocID and Schedulers will be cleared later only if they are not shared across all the UNIs |
Gamze Abaka | 745ccb7 | 2021-11-18 11:29:58 +0000 | [diff] [blame] | 1989 | switch techprofileInst := techprofileInst.(type) { |
| 1990 | case *tp_pb.TechProfileInstance: |
yasin sapli | bddc2d7 | 2022-02-08 13:10:17 +0000 | [diff] [blame] | 1991 | if err := f.resourceMgr.RemoveTechProfileIDForOnu(ctx, uint32(onuID), uint32(uniID), tpID); err != nil { |
Girish Gowdra | f3728b1 | 2022-02-02 21:46:51 -0800 | [diff] [blame] | 1992 | logger.Warn(ctx, err) |
| 1993 | } |
| 1994 | if err := f.DeleteTechProfileInstance(ctx, intfID, uint32(onuID), uint32(uniID), "", tpID); err != nil { |
| 1995 | logger.Warn(ctx, err) |
| 1996 | } |
| 1997 | |
| 1998 | for _, gemPort := range techprofileInst.UpstreamGemPortAttributeList { |
| 1999 | gemPortID := gemPort.GemportId |
yasin sapli | bddc2d7 | 2022-02-08 13:10:17 +0000 | [diff] [blame] | 2000 | _ = f.resourceMgr.RemoveGemFromOnuGemInfo(ctx, uint32(onuID), gemPortID) // ignore error and proceed. |
Girish Gowdra | f3728b1 | 2022-02-02 21:46:51 -0800 | [diff] [blame] | 2001 | |
yasin sapli | bddc2d7 | 2022-02-08 13:10:17 +0000 | [diff] [blame] | 2002 | if err := f.resourceMgr.DeleteFlowIDsForGem(ctx, gemPortID); err != nil { |
Girish Gowdra | f3728b1 | 2022-02-02 21:46:51 -0800 | [diff] [blame] | 2003 | logger.Errorw(ctx, "error-removing-flow-ids-of-gem-port", |
| 2004 | log.Fields{ |
| 2005 | "err": err, |
| 2006 | "intf": intfID, |
| 2007 | "onu-id": onuID, |
| 2008 | "uni-id": uniID, |
| 2009 | "device-id": f.deviceHandler.device.Id, |
| 2010 | "gemport-id": gemPortID}) |
| 2011 | } |
| 2012 | |
| 2013 | } |
| 2014 | // Remove queues at OLT in upstream and downstream direction |
| 2015 | schedQueue := schedQueue{direction: tp_pb.Direction_UPSTREAM, intfID: intfID, onuID: uint32(onuID), uniID: uint32(uniID), tpID: tpID, uniPort: portNum, tpInst: techprofileInst} |
| 2016 | if err := f.RemoveQueues(ctx, schedQueue); err != nil { |
| 2017 | logger.Warn(ctx, err) |
| 2018 | } |
| 2019 | schedQueue.direction = tp_pb.Direction_DOWNSTREAM |
| 2020 | if err := f.RemoveQueues(ctx, schedQueue); err != nil { |
| 2021 | logger.Warn(ctx, err) |
| 2022 | } |
| 2023 | } |
| 2024 | |
| 2025 | switch techprofileInst := techprofileInst.(type) { |
| 2026 | case *tp_pb.TechProfileInstance: |
| 2027 | // Proceed to free allocid and cleanup schedulers (US/DS) if no other references are found for this TP across all the UNIs on the ONU |
Andrea Campanella | 8a0d050 | 2022-01-31 15:31:59 +0100 | [diff] [blame] | 2028 | schedQueue := schedQueue{direction: tp_pb.Direction_UPSTREAM, intfID: intfID, onuID: uint32(onuID), uniID: uint32(uniID), tpID: tpID, uniPort: portNum, tpInst: techprofileInst} |
| 2029 | allocExists := f.isAllocUsedByAnotherUNI(ctx, schedQueue) |
| 2030 | if !allocExists { |
Girish Gowdra | f3728b1 | 2022-02-02 21:46:51 -0800 | [diff] [blame] | 2031 | // all alloc object references removed, remove upstream scheduler |
yasin sapli | bddc2d7 | 2022-02-08 13:10:17 +0000 | [diff] [blame] | 2032 | if KvStoreMeter, _ := f.resourceMgr.GetMeterInfoForOnu(ctx, "upstream", uint32(onuID), uint32(uniID), tpID); KvStoreMeter != nil { |
Girish Gowdra | f3728b1 | 2022-02-02 21:46:51 -0800 | [diff] [blame] | 2033 | if err := f.RemoveScheduler(ctx, schedQueue); err != nil { |
Andrea Campanella | 8a0d050 | 2022-01-31 15:31:59 +0100 | [diff] [blame] | 2034 | logger.Warn(ctx, err) |
| 2035 | } |
| 2036 | } |
Girish Gowdra | f3728b1 | 2022-02-02 21:46:51 -0800 | [diff] [blame] | 2037 | // remove alloc id from resource pool by setting the 'freeFromResourcePool' to true |
yasin sapli | bddc2d7 | 2022-02-08 13:10:17 +0000 | [diff] [blame] | 2038 | f.resourceMgr.FreeAllocID(ctx, uint32(onuID), uint32(uniID), techprofileInst.UsScheduler.AllocId, true) |
Girish Gowdra | f3728b1 | 2022-02-02 21:46:51 -0800 | [diff] [blame] | 2039 | } else { |
| 2040 | // just remove meter reference for the upstream direction for the current pon/onu/uni |
| 2041 | // The upstream scheduler, alloc id and meter-reference for the last remaining pon/onu/uni will be removed when no other alloc references that TP |
| 2042 | if err := f.removeMeterReference(ctx, "upstream", schedQueue); err != nil { |
| 2043 | return err |
Andrea Campanella | 8a0d050 | 2022-01-31 15:31:59 +0100 | [diff] [blame] | 2044 | } |
Girish Gowdra | f3728b1 | 2022-02-02 21:46:51 -0800 | [diff] [blame] | 2045 | // setting 'freeFromResourcePool' to false in resourceMgr.FreeAllocID will only remove alloc-id data for the given pon/onu/uni |
| 2046 | // but still preserve it on the resource pool. |
yasin sapli | bddc2d7 | 2022-02-08 13:10:17 +0000 | [diff] [blame] | 2047 | f.resourceMgr.FreeAllocID(ctx, uint32(onuID), uint32(uniID), techprofileInst.UsScheduler.AllocId, false) |
Girish Gowdra | f3728b1 | 2022-02-02 21:46:51 -0800 | [diff] [blame] | 2048 | } |
Andrea Campanella | 8a0d050 | 2022-01-31 15:31:59 +0100 | [diff] [blame] | 2049 | |
Girish Gowdra | f3728b1 | 2022-02-02 21:46:51 -0800 | [diff] [blame] | 2050 | // Downstream scheduler removal is simple, just invoke RemoveScheduler without all the complex handling we do for the alloc object. |
| 2051 | schedQueue.direction = tp_pb.Direction_DOWNSTREAM |
yasin sapli | bddc2d7 | 2022-02-08 13:10:17 +0000 | [diff] [blame] | 2052 | if KvStoreMeter, _ := f.resourceMgr.GetMeterInfoForOnu(ctx, "downstream", uint32(onuID), uint32(uniID), tpID); KvStoreMeter != nil { |
Girish Gowdra | f3728b1 | 2022-02-02 21:46:51 -0800 | [diff] [blame] | 2053 | if err := f.RemoveScheduler(ctx, schedQueue); err != nil { |
| 2054 | logger.Warn(ctx, err) |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 2055 | } |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 2056 | } |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 2057 | case *tp_pb.EponTechProfileInstance: |
yasin sapli | bddc2d7 | 2022-02-08 13:10:17 +0000 | [diff] [blame] | 2058 | if err := f.resourceMgr.RemoveTechProfileIDForOnu(ctx, uint32(onuID), uint32(uniID), tpID); err != nil { |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 2059 | logger.Warn(ctx, err) |
| 2060 | } |
Girish Gowdra | a482f27 | 2021-03-24 23:04:19 -0700 | [diff] [blame] | 2061 | if err := f.DeleteTechProfileInstance(ctx, intfID, uint32(onuID), uint32(uniID), "", tpID); err != nil { |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 2062 | logger.Warn(ctx, err) |
| 2063 | } |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 2064 | // Delete the TCONT on the ONU. |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 2065 | if err := f.sendDeleteTcontToChild(ctx, intfID, uint32(onuID), uint32(uniID), techprofileInst.AllocId, tpPath); err != nil { |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 2066 | logger.Errorw(ctx, "error-processing-delete-tcont-towards-onu", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 2067 | log.Fields{ |
Girish Gowdra | a482f27 | 2021-03-24 23:04:19 -0700 | [diff] [blame] | 2068 | "intf": intfID, |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 2069 | "onu-id": onuID, |
| 2070 | "uni-id": uniID, |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 2071 | "device-id": f.deviceHandler.device.Id, |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 2072 | "alloc-id": techprofileInst.AllocId, |
| 2073 | "error": err}) |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 2074 | } |
yasin sapli | bddc2d7 | 2022-02-08 13:10:17 +0000 | [diff] [blame] | 2075 | f.resourceMgr.FreeAllocID(ctx, uint32(onuID), uint32(uniID), techprofileInst.AllocId, true) |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 2076 | default: |
| 2077 | logger.Errorw(ctx, "error-unknown-tech", |
| 2078 | log.Fields{ |
| 2079 | "techprofileInst": techprofileInst}) |
Manjunath Vanarajulu | 28c3e82 | 2019-05-16 11:14:28 -0400 | [diff] [blame] | 2080 | } |
Girish Gowdra | f3728b1 | 2022-02-02 21:46:51 -0800 | [diff] [blame] | 2081 | |
| 2082 | // Free TPInstance, TPID, GemPorts and Traffic Queues. AllocID and Schedulers will be cleared later only if they are not shared across all the UNIs |
| 2083 | switch techprofileInst := techprofileInst.(type) { |
| 2084 | case *tp_pb.TechProfileInstance: |
| 2085 | for _, gemPort := range techprofileInst.UpstreamGemPortAttributeList { |
| 2086 | // Delete the gem port on the ONU. |
| 2087 | if sendDeleteGemRequest { |
| 2088 | if err := f.sendDeleteGemPortToChild(ctx, intfID, uint32(onuID), uint32(uniID), gemPort.GemportId, tpPath); err != nil { |
| 2089 | logger.Errorw(ctx, "error-processing-delete-gem-port-towards-onu", |
| 2090 | log.Fields{ |
| 2091 | "err": err, |
| 2092 | "intfID": intfID, |
| 2093 | "onu-id": onuID, |
| 2094 | "uni-id": uniID, |
| 2095 | "device-id": f.deviceHandler.device.Id, |
| 2096 | "gemport-id": gemPort.GemportId}) |
| 2097 | } |
yasin sapli | bddc2d7 | 2022-02-08 13:10:17 +0000 | [diff] [blame] | 2098 | f.resourceMgr.FreeGemPortID(ctx, uint32(onuID), uint32(uniID), gemPort.GemportId) |
Girish Gowdra | f3728b1 | 2022-02-02 21:46:51 -0800 | [diff] [blame] | 2099 | } |
| 2100 | } |
| 2101 | } |
| 2102 | |
Abhilash Laxmeshwar | b7300fe | 2019-11-13 03:38:33 +0530 | [diff] [blame] | 2103 | return nil |
| 2104 | } |
| 2105 | |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 2106 | // nolint: gocyclo |
Girish Gowdra | e8f473b | 2020-10-16 11:07:21 -0700 | [diff] [blame] | 2107 | func (f *OpenOltFlowMgr) clearFlowFromDeviceAndResourceManager(ctx context.Context, flow *ofp.OfpFlowStats, flowDirection string) error { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2108 | logger.Infow(ctx, "clear-flow-from-resource-manager", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 2109 | log.Fields{ |
| 2110 | "flowDirection": flowDirection, |
| 2111 | "flow": *flow, |
| 2112 | "device-id": f.deviceHandler.device.Id}) |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 2113 | |
| 2114 | if flowDirection == Multicast { |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 2115 | return f.clearMulticastFlowFromResourceManager(ctx, flow) |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 2116 | } |
| 2117 | |
Girish Gowdra | 5c00ef1 | 2021-12-01 17:19:41 +0530 | [diff] [blame] | 2118 | var ethType, ipProto, inPort uint32 |
| 2119 | for _, field := range flows.GetOfbFields(flow) { |
| 2120 | if field.Type == flows.IP_PROTO { |
| 2121 | ipProto = field.GetIpProto() |
| 2122 | logger.Debugw(ctx, "field-type-ip-proto", log.Fields{"ipProto": ipProto}) |
| 2123 | } else if field.Type == flows.ETH_TYPE { |
| 2124 | ethType = field.GetEthType() |
| 2125 | logger.Debugw(ctx, "field-type-eth-type", log.Fields{"ethType": ethType}) |
| 2126 | } else if field.Type == flows.IN_PORT { |
| 2127 | inPort = field.GetPort() |
| 2128 | logger.Debugw(ctx, "field-type-in-port", log.Fields{"inPort": inPort}) |
| 2129 | } |
| 2130 | } |
| 2131 | portType := plt.IntfIDToPortTypeName(inPort) |
| 2132 | if (ethType == uint32(LldpEthType) || ipProto == uint32(IPProtoDhcp) || ipProto == uint32(IgmpProto)) && |
| 2133 | (portType == voltha.Port_ETHERNET_NNI) { |
| 2134 | removeFlowMessage := openoltpb2.Flow{FlowId: flow.Id, AccessIntfId: -1, OnuId: -1, UniId: -1, TechProfileId: 0, FlowType: Downstream} |
| 2135 | logger.Debugw(ctx, "nni-trap-flow-to-be-deleted", log.Fields{"flow": flow}) |
| 2136 | return f.removeFlowFromDevice(ctx, &removeFlowMessage, flow.Id) |
| 2137 | // No more processing needed for trap from nni flows. |
| 2138 | } |
Abhilash Laxmeshwar | b7300fe | 2019-11-13 03:38:33 +0530 | [diff] [blame] | 2139 | |
Girish Gowdra | 5c00ef1 | 2021-12-01 17:19:41 +0530 | [diff] [blame] | 2140 | portNum, Intf, onu, uni, _, _, err := plt.FlowExtractInfo(ctx, flow, flowDirection) |
Abhilash Laxmeshwar | b7300fe | 2019-11-13 03:38:33 +0530 | [diff] [blame] | 2141 | if err != nil { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2142 | logger.Error(ctx, err) |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 2143 | return err |
Abhilash Laxmeshwar | b7300fe | 2019-11-13 03:38:33 +0530 | [diff] [blame] | 2144 | } |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 2145 | onuID := int32(onu) |
| 2146 | uniID := int32(uni) |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 2147 | tpID, err := getTpIDFromFlow(ctx, flow) |
| 2148 | if err != nil { |
| 2149 | return olterrors.NewErrNotFound("tp-id", |
| 2150 | log.Fields{ |
| 2151 | "flow": flow, |
| 2152 | "intf-id": Intf, |
| 2153 | "onu-id": onuID, |
| 2154 | "uni-id": uniID, |
| 2155 | "device-id": f.deviceHandler.device.Id}, err) |
| 2156 | } |
Abhilash Laxmeshwar | b7300fe | 2019-11-13 03:38:33 +0530 | [diff] [blame] | 2157 | |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2158 | logger.Infow(ctx, "extracted-access-info-from-flow-to-be-deleted", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 2159 | log.Fields{ |
Matteo Scandolo | 9218624 | 2020-06-12 10:54:18 -0700 | [diff] [blame] | 2160 | "flow-id": flow.Id, |
| 2161 | "intf-id": Intf, |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 2162 | "onu-id": onuID, |
| 2163 | "uni-id": uniID}) |
Abhilash Laxmeshwar | b7300fe | 2019-11-13 03:38:33 +0530 | [diff] [blame] | 2164 | |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 2165 | removeFlowMessage := openoltpb2.Flow{FlowId: flow.Id, AccessIntfId: int32(Intf), OnuId: onuID, UniId: uniID, TechProfileId: tpID, FlowType: flowDirection} |
| 2166 | logger.Debugw(ctx, "flow-to-be-deleted", log.Fields{"flow": flow}) |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 2167 | if err = f.removeFlowFromDevice(ctx, &removeFlowMessage, flow.Id); err != nil { |
| 2168 | return err |
| 2169 | } |
Girish Gowdra | 82c8098 | 2021-03-26 16:22:02 -0700 | [diff] [blame] | 2170 | |
Gamze Abaka | 411ef2f | 2021-11-22 08:38:08 +0000 | [diff] [blame] | 2171 | if err = f.clearResources(ctx, Intf, onuID, uniID, flow.Id, portNum, tpID, true); err != nil { |
Gamze Abaka | 745ccb7 | 2021-11-18 11:29:58 +0000 | [diff] [blame] | 2172 | logger.Errorw(ctx, "failed-to-clear-resources-for-flow", log.Fields{ |
| 2173 | "flow-id": flow.Id, |
| 2174 | "device-id": f.deviceHandler.device.Id, |
| 2175 | "onu-id": onuID, |
| 2176 | "intf": Intf, |
| 2177 | "err": err, |
| 2178 | }) |
| 2179 | return err |
Abhilash Laxmeshwar | b7300fe | 2019-11-13 03:38:33 +0530 | [diff] [blame] | 2180 | } |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 2181 | |
Girish Gowdra | 82c8098 | 2021-03-26 16:22:02 -0700 | [diff] [blame] | 2182 | // Decrement reference count for the meter associated with the given <(pon_id, onu_id, uni_id)>/<tp_id>/meter_id/<direction> |
yasin sapli | bddc2d7 | 2022-02-08 13:10:17 +0000 | [diff] [blame] | 2183 | if err := f.resourceMgr.HandleMeterInfoRefCntUpdate(ctx, flowDirection, uint32(onuID), uint32(uniID), tpID, false); err != nil { |
Girish Gowdra | 82c8098 | 2021-03-26 16:22:02 -0700 | [diff] [blame] | 2184 | return err |
| 2185 | } |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 2186 | return nil |
Manjunath Vanarajulu | 28c3e82 | 2019-05-16 11:14:28 -0400 | [diff] [blame] | 2187 | } |
| 2188 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 2189 | //RemoveFlow removes the flow from the device |
Girish Gowdra | cefae19 | 2020-03-19 18:14:10 -0700 | [diff] [blame] | 2190 | func (f *OpenOltFlowMgr) RemoveFlow(ctx context.Context, flow *ofp.OfpFlowStats) error { |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 2191 | |
Matteo Scandolo | f16389e | 2021-05-18 00:47:08 +0000 | [diff] [blame] | 2192 | logger.Infow(ctx, "removing-flow", log.Fields{"flow": *flow}) |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 2193 | var direction string |
| 2194 | actionInfo := make(map[string]interface{}) |
Manjunath Vanarajulu | 28c3e82 | 2019-05-16 11:14:28 -0400 | [diff] [blame] | 2195 | |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 2196 | for _, action := range flows.GetActions(flow) { |
| 2197 | if action.Type == flows.OUTPUT { |
| 2198 | if out := action.GetOutput(); out != nil { |
| 2199 | actionInfo[Output] = out.GetPort() |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2200 | logger.Debugw(ctx, "action-type-output", log.Fields{"out_port": actionInfo[Output].(uint32)}) |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 2201 | } else { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2202 | logger.Error(ctx, "invalid-output-port-in-action") |
Girish Gowdra | cefae19 | 2020-03-19 18:14:10 -0700 | [diff] [blame] | 2203 | return olterrors.NewErrInvalidValue(log.Fields{"invalid-out-port-action": 0}, nil) |
Manjunath Vanarajulu | 28c3e82 | 2019-05-16 11:14:28 -0400 | [diff] [blame] | 2204 | } |
| 2205 | } |
| 2206 | } |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 2207 | |
| 2208 | if flows.HasGroup(flow) { |
| 2209 | direction = Multicast |
Girish Gowdra | e8f473b | 2020-10-16 11:07:21 -0700 | [diff] [blame] | 2210 | return f.clearFlowFromDeviceAndResourceManager(ctx, flow, direction) |
Mahir Gunyel | 85f61c1 | 2021-10-06 11:53:45 -0700 | [diff] [blame] | 2211 | } else if plt.IsUpstream(actionInfo[Output].(uint32)) { |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 2212 | direction = Upstream |
| 2213 | } else { |
| 2214 | direction = Downstream |
| 2215 | } |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 2216 | |
Girish Gowdra | cefae19 | 2020-03-19 18:14:10 -0700 | [diff] [blame] | 2217 | // Serialize flow removes on a per subscriber basis |
Girish Gowdra | fb3d610 | 2020-10-16 16:32:36 -0700 | [diff] [blame] | 2218 | err := f.clearFlowFromDeviceAndResourceManager(ctx, flow, direction) |
Girish Gowdra | cefae19 | 2020-03-19 18:14:10 -0700 | [diff] [blame] | 2219 | |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 2220 | return err |
Manjunath Vanarajulu | 28c3e82 | 2019-05-16 11:14:28 -0400 | [diff] [blame] | 2221 | } |
| 2222 | |
Esin Karaman | ae41e2b | 2019-12-17 18:13:13 +0000 | [diff] [blame] | 2223 | //isIgmpTrapDownstreamFlow return true if the flow is a downsteam IGMP trap-to-host flow; false otherwise |
| 2224 | func isIgmpTrapDownstreamFlow(classifierInfo map[string]interface{}) bool { |
Mahir Gunyel | 85f61c1 | 2021-10-06 11:53:45 -0700 | [diff] [blame] | 2225 | if portType := plt.IntfIDToPortTypeName(classifierInfo[InPort].(uint32)); portType == voltha.Port_ETHERNET_NNI { |
Esin Karaman | ae41e2b | 2019-12-17 18:13:13 +0000 | [diff] [blame] | 2226 | if ethType, ok := classifierInfo[EthType]; ok { |
| 2227 | if ethType.(uint32) == IPv4EthType { |
| 2228 | if ipProto, ok := classifierInfo[IPProto]; ok { |
| 2229 | if ipProto.(uint32) == IgmpProto { |
| 2230 | return true |
| 2231 | } |
| 2232 | } |
| 2233 | } |
| 2234 | } |
| 2235 | } |
| 2236 | return false |
| 2237 | } |
| 2238 | |
Girish Gowdra | fb3d610 | 2020-10-16 16:32:36 -0700 | [diff] [blame] | 2239 | // RouteFlowToOnuChannel routes incoming flow to ONU specific channel |
khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 2240 | func (f *OpenOltFlowMgr) RouteFlowToOnuChannel(ctx context.Context, flow *ofp.OfpFlowStats, addFlow bool, flowMetadata *ofp.FlowMetadata) error { |
Girish Gowdra | 20e3dcd | 2021-11-18 22:56:49 -0800 | [diff] [blame] | 2241 | if f.deviceHandler.getDeviceDeletionInProgressFlag() { |
| 2242 | // The device itself is going to be reset as part of deletion. So nothing to be done. |
| 2243 | logger.Infow(ctx, "device-deletion-in-progress--not-handling-flows-or-groups", log.Fields{"device-id": f.deviceHandler.device.Id}) |
| 2244 | return nil |
| 2245 | } |
Girish Gowdra | fb3d610 | 2020-10-16 16:32:36 -0700 | [diff] [blame] | 2246 | // Step1 : Fill flowControlBlock |
| 2247 | // Step2 : Push the flowControlBlock to ONU channel |
| 2248 | // Step3 : Wait on response channel for response |
| 2249 | // Step4 : Return error value |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 2250 | startTime := time.Now() |
| 2251 | logger.Infow(ctx, "process-flow", log.Fields{"flow": flow, "addFlow": addFlow}) |
Girish Gowdra | fb3d610 | 2020-10-16 16:32:36 -0700 | [diff] [blame] | 2252 | errChan := make(chan error) |
| 2253 | flowCb := flowControlBlock{ |
| 2254 | ctx: ctx, |
| 2255 | addFlow: addFlow, |
| 2256 | flow: flow, |
| 2257 | flowMetadata: flowMetadata, |
| 2258 | errChan: &errChan, |
| 2259 | } |
| 2260 | inPort, outPort := getPorts(flow) |
| 2261 | var onuID uint32 |
| 2262 | if inPort != InvalidPort && outPort != InvalidPort { |
Mahir Gunyel | 85f61c1 | 2021-10-06 11:53:45 -0700 | [diff] [blame] | 2263 | _, _, onuID, _ = plt.ExtractAccessFromFlow(inPort, outPort) |
Girish Gowdra | fb3d610 | 2020-10-16 16:32:36 -0700 | [diff] [blame] | 2264 | } |
Girish Gowdra | 4736e5c | 2021-08-25 15:19:10 -0700 | [diff] [blame] | 2265 | if f.flowHandlerRoutineActive[onuID] { |
| 2266 | // inPort or outPort is InvalidPort for trap-from-nni flows. |
| 2267 | // In the that case onuID is 0 which is the reserved index for trap-from-nni flows in the f.incomingFlows slice |
| 2268 | // Send the flowCb on the ONU flow channel |
| 2269 | f.incomingFlows[onuID] <- flowCb |
| 2270 | // Wait on the channel for flow handlers return value |
| 2271 | err := <-errChan |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 2272 | logger.Infow(ctx, "process-flow-received-resp", log.Fields{"err": err, "totalTimeSeconds": time.Since(startTime).Seconds()}) |
Girish Gowdra | 4736e5c | 2021-08-25 15:19:10 -0700 | [diff] [blame] | 2273 | return err |
| 2274 | } |
| 2275 | logger.Errorw(ctx, "flow handler routine not active for onu", log.Fields{"onuID": onuID, "ponPortIdx": f.ponPortIdx}) |
| 2276 | return fmt.Errorf("flow-handler-routine-not-active-for-onu-%v-pon-%d", onuID, f.ponPortIdx) |
Girish Gowdra | fb3d610 | 2020-10-16 16:32:36 -0700 | [diff] [blame] | 2277 | } |
| 2278 | |
| 2279 | // This routine is unique per ONU ID and blocks on flowControlBlock channel for incoming flows |
| 2280 | // Each incoming flow is processed in a synchronous manner, i.e., the flow is processed to completion before picking another |
Girish Gowdra | 4736e5c | 2021-08-25 15:19:10 -0700 | [diff] [blame] | 2281 | func (f *OpenOltFlowMgr) perOnuFlowHandlerRoutine(handlerRoutineIndex int, subscriberFlowChannel chan flowControlBlock, stopHandler chan bool) { |
Girish Gowdra | 20e3dcd | 2021-11-18 22:56:49 -0800 | [diff] [blame] | 2282 | var flowCb flowControlBlock |
Girish Gowdra | fb3d610 | 2020-10-16 16:32:36 -0700 | [diff] [blame] | 2283 | for { |
Girish Gowdra | 4736e5c | 2021-08-25 15:19:10 -0700 | [diff] [blame] | 2284 | select { |
Girish Gowdra | fb3d610 | 2020-10-16 16:32:36 -0700 | [diff] [blame] | 2285 | // block on the channel to receive an incoming flow |
| 2286 | // process the flow completely before proceeding to handle the next flow |
Girish Gowdra | 20e3dcd | 2021-11-18 22:56:49 -0800 | [diff] [blame] | 2287 | case flowCb = <-subscriberFlowChannel: |
Girish Gowdra | 4736e5c | 2021-08-25 15:19:10 -0700 | [diff] [blame] | 2288 | if flowCb.addFlow { |
| 2289 | logger.Info(flowCb.ctx, "adding-flow-start") |
| 2290 | startTime := time.Now() |
| 2291 | err := f.AddFlow(flowCb.ctx, flowCb.flow, flowCb.flowMetadata) |
| 2292 | logger.Infow(flowCb.ctx, "adding-flow-complete", log.Fields{"processTimeSecs": time.Since(startTime).Seconds()}) |
| 2293 | // Pass the return value over the return channel |
| 2294 | *flowCb.errChan <- err |
| 2295 | } else { |
| 2296 | logger.Info(flowCb.ctx, "removing-flow-start") |
| 2297 | startTime := time.Now() |
| 2298 | err := f.RemoveFlow(flowCb.ctx, flowCb.flow) |
| 2299 | logger.Infow(flowCb.ctx, "removing-flow-complete", log.Fields{"processTimeSecs": time.Since(startTime).Seconds()}) |
| 2300 | // Pass the return value over the return channel |
| 2301 | *flowCb.errChan <- err |
| 2302 | } |
| 2303 | case <-stopHandler: |
| 2304 | f.flowHandlerRoutineActive[handlerRoutineIndex] = false |
| 2305 | return |
Girish Gowdra | fb3d610 | 2020-10-16 16:32:36 -0700 | [diff] [blame] | 2306 | } |
| 2307 | } |
| 2308 | } |
| 2309 | |
Girish Gowdra | 4736e5c | 2021-08-25 15:19:10 -0700 | [diff] [blame] | 2310 | // StopAllFlowHandlerRoutines stops all flow handler routines. Call this when device is being rebooted or deleted |
Girish Gowdra | 20e3dcd | 2021-11-18 22:56:49 -0800 | [diff] [blame] | 2311 | func (f *OpenOltFlowMgr) StopAllFlowHandlerRoutines(ctx context.Context, wg *sync.WaitGroup) { |
Girish Gowdra | 4736e5c | 2021-08-25 15:19:10 -0700 | [diff] [blame] | 2312 | for i, v := range f.stopFlowHandlerRoutine { |
| 2313 | if f.flowHandlerRoutineActive[i] { |
Girish Gowdra | 20e3dcd | 2021-11-18 22:56:49 -0800 | [diff] [blame] | 2314 | select { |
| 2315 | case v <- true: |
| 2316 | case <-time.After(time.Second * 5): |
| 2317 | logger.Warnw(ctx, "timeout stopping flow handler routine", log.Fields{"onuID": i, "deviceID": f.deviceHandler.device.Id}) |
| 2318 | } |
Girish Gowdra | 4736e5c | 2021-08-25 15:19:10 -0700 | [diff] [blame] | 2319 | } |
| 2320 | } |
Girish Gowdra | 20e3dcd | 2021-11-18 22:56:49 -0800 | [diff] [blame] | 2321 | wg.Done() |
Girish Gowdra | 4736e5c | 2021-08-25 15:19:10 -0700 | [diff] [blame] | 2322 | logger.Debugw(ctx, "stopped all flow handler routines", log.Fields{"ponPortIdx": f.ponPortIdx}) |
| 2323 | } |
| 2324 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 2325 | // AddFlow add flow to device |
Naga Manjunath | b8438aa | 2020-01-02 17:52:33 +0530 | [diff] [blame] | 2326 | // nolint: gocyclo |
khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 2327 | func (f *OpenOltFlowMgr) AddFlow(ctx context.Context, flow *ofp.OfpFlowStats, flowMetadata *ofp.FlowMetadata) error { |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 2328 | classifierInfo := make(map[string]interface{}) |
| 2329 | actionInfo := make(map[string]interface{}) |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 2330 | var UsMeterID uint32 |
| 2331 | var DsMeterID uint32 |
| 2332 | |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2333 | logger.Infow(ctx, "adding-flow", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 2334 | log.Fields{ |
| 2335 | "flow": flow, |
Matteo Scandolo | f16389e | 2021-05-18 00:47:08 +0000 | [diff] [blame] | 2336 | "flowmetadata": flowMetadata}) |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2337 | formulateClassifierInfoFromFlow(ctx, classifierInfo, flow) |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 2338 | |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2339 | err := formulateActionInfoFromFlow(ctx, actionInfo, classifierInfo, flow) |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 2340 | if err != nil { |
| 2341 | // Error logging is already done in the called function |
| 2342 | // So just return in case of error |
Andrea Campanella | c63bba9 | 2020-03-10 17:01:04 +0100 | [diff] [blame] | 2343 | return err |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 2344 | } |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 2345 | |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 2346 | if flows.HasGroup(flow) { |
| 2347 | // handle multicast flow |
Andrea Campanella | c63bba9 | 2020-03-10 17:01:04 +0100 | [diff] [blame] | 2348 | return f.handleFlowWithGroup(ctx, actionInfo, classifierInfo, flow) |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 2349 | } |
| 2350 | |
manikkaraj k | 17652a7 | 2019-05-06 09:06:36 -0400 | [diff] [blame] | 2351 | /* Controller bound trap flows */ |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2352 | err = formulateControllerBoundTrapFlowInfo(ctx, actionInfo, classifierInfo, flow) |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 2353 | if err != nil { |
| 2354 | // error if any, already logged in the called function |
Andrea Campanella | c63bba9 | 2020-03-10 17:01:04 +0100 | [diff] [blame] | 2355 | return err |
manikkaraj k | 17652a7 | 2019-05-06 09:06:36 -0400 | [diff] [blame] | 2356 | } |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 2357 | |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2358 | logger.Debugw(ctx, "flow-ports", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 2359 | log.Fields{ |
| 2360 | "classifierinfo_inport": classifierInfo[InPort], |
| 2361 | "action_output": actionInfo[Output]}) |
Mahir Gunyel | 85f61c1 | 2021-10-06 11:53:45 -0700 | [diff] [blame] | 2362 | portNo, intfID, onuID, uniID := plt.ExtractAccessFromFlow(classifierInfo[InPort].(uint32), actionInfo[Output].(uint32)) |
A R Karthick | 1f85b80 | 2019-10-11 05:06:05 +0000 | [diff] [blame] | 2363 | |
Humera Kouser | 94d7a84 | 2019-08-25 19:04:32 -0400 | [diff] [blame] | 2364 | if ethType, ok := classifierInfo[EthType]; ok { |
| 2365 | if ethType.(uint32) == LldpEthType { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2366 | logger.Info(ctx, "adding-lldp-flow") |
Andrea Campanella | c63bba9 | 2020-03-10 17:01:04 +0100 | [diff] [blame] | 2367 | return f.addLLDPFlow(ctx, flow, portNo) |
Humera Kouser | 94d7a84 | 2019-08-25 19:04:32 -0400 | [diff] [blame] | 2368 | } |
Marcos Aurelio Carrero (Furukawa) | 388fb0a | 2021-02-04 18:05:11 -0300 | [diff] [blame] | 2369 | if ethType.(uint32) == PPPoEDEthType { |
Mahir Gunyel | 85f61c1 | 2021-10-06 11:53:45 -0700 | [diff] [blame] | 2370 | if voltha.Port_ETHERNET_NNI == plt.IntfIDToPortTypeName(classifierInfo[InPort].(uint32)) { |
Marcos Aurelio Carrero (Furukawa) | 388fb0a | 2021-02-04 18:05:11 -0300 | [diff] [blame] | 2371 | logger.Debug(ctx, "trap-pppoed-from-nni-flow") |
| 2372 | return f.addTrapFlowOnNNI(ctx, flow, classifierInfo, portNo) |
| 2373 | } |
| 2374 | } |
Humera Kouser | 94d7a84 | 2019-08-25 19:04:32 -0400 | [diff] [blame] | 2375 | } |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 2376 | if ipProto, ok := classifierInfo[IPProto]; ok { |
| 2377 | if ipProto.(uint32) == IPProtoDhcp { |
| 2378 | if udpSrc, ok := classifierInfo[UDPSrc]; ok { |
Naga Manjunath | b8438aa | 2020-01-02 17:52:33 +0530 | [diff] [blame] | 2379 | if udpSrc.(uint32) == uint32(67) || udpSrc.(uint32) == uint32(546) { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2380 | logger.Debug(ctx, "trap-dhcp-from-nni-flow") |
Marcos Aurelio Carrero (Furukawa) | 388fb0a | 2021-02-04 18:05:11 -0300 | [diff] [blame] | 2381 | return f.addTrapFlowOnNNI(ctx, flow, classifierInfo, portNo) |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 2382 | } |
| 2383 | } |
| 2384 | } |
| 2385 | } |
Esin Karaman | ae41e2b | 2019-12-17 18:13:13 +0000 | [diff] [blame] | 2386 | if isIgmpTrapDownstreamFlow(classifierInfo) { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2387 | logger.Debug(ctx, "trap-igmp-from-nni-flow") |
Andrea Campanella | c63bba9 | 2020-03-10 17:01:04 +0100 | [diff] [blame] | 2388 | return f.addIgmpTrapFlowOnNNI(ctx, flow, classifierInfo, portNo) |
Esin Karaman | ae41e2b | 2019-12-17 18:13:13 +0000 | [diff] [blame] | 2389 | } |
A R Karthick | 1f85b80 | 2019-10-11 05:06:05 +0000 | [diff] [blame] | 2390 | |
yasin sapli | bddc2d7 | 2022-02-08 13:10:17 +0000 | [diff] [blame] | 2391 | f.resourceMgr.AddUniPortToOnuInfo(ctx, onuID, portNo) |
A R Karthick | 1f85b80 | 2019-10-11 05:06:05 +0000 | [diff] [blame] | 2392 | |
Girish Gowdra | 6071f38 | 2021-12-14 12:52:04 +0530 | [diff] [blame] | 2393 | tpID, err := getTpIDFromFlow(ctx, flow) |
Chaitrashree G S | 90a1795 | 2019-11-14 21:51:21 -0500 | [diff] [blame] | 2394 | if err != nil { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 2395 | return olterrors.NewErrNotFound("tpid-for-flow", |
| 2396 | log.Fields{ |
| 2397 | "flow": flow, |
| 2398 | "intf-id": IntfID, |
| 2399 | "onu-id": onuID, |
| 2400 | "uni-id": uniID}, err) |
Chaitrashree G S | 90a1795 | 2019-11-14 21:51:21 -0500 | [diff] [blame] | 2401 | } |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2402 | logger.Debugw(ctx, "tpid-for-this-subcriber", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 2403 | log.Fields{ |
Girish Gowdra | 6071f38 | 2021-12-14 12:52:04 +0530 | [diff] [blame] | 2404 | "tp-id": tpID, |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 2405 | "intf-id": intfID, |
| 2406 | "onu-id": onuID, |
| 2407 | "uni-id": uniID}) |
Mahir Gunyel | 85f61c1 | 2021-10-06 11:53:45 -0700 | [diff] [blame] | 2408 | if plt.IsUpstream(actionInfo[Output].(uint32)) { |
Scott Baker | 355d174 | 2019-10-24 10:57:52 -0700 | [diff] [blame] | 2409 | UsMeterID = flows.GetMeterIdFromFlow(flow) |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2410 | logger.Debugw(ctx, "upstream-flow-meter-id", log.Fields{"us-meter-id": UsMeterID}) |
Girish Gowdra | 6071f38 | 2021-12-14 12:52:04 +0530 | [diff] [blame] | 2411 | if err := f.validateMeter(ctx, Upstream, UsMeterID, intfID, onuID, uniID, tpID); err != nil { |
| 2412 | logger.Errorw(ctx, "meter-validation-failed", log.Fields{"err": err}) |
| 2413 | return err |
| 2414 | } |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 2415 | } else { |
Scott Baker | 355d174 | 2019-10-24 10:57:52 -0700 | [diff] [blame] | 2416 | DsMeterID = flows.GetMeterIdFromFlow(flow) |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2417 | logger.Debugw(ctx, "downstream-flow-meter-id", log.Fields{"ds-meter-id": DsMeterID}) |
Girish Gowdra | 6071f38 | 2021-12-14 12:52:04 +0530 | [diff] [blame] | 2418 | if err := f.validateMeter(ctx, Downstream, DsMeterID, intfID, onuID, uniID, tpID); err != nil { |
| 2419 | logger.Errorw(ctx, "meter-validation-failed", log.Fields{"err": err}) |
| 2420 | return err |
| 2421 | } |
Manikkaraj k | b1d5144 | 2019-07-23 10:41:02 -0400 | [diff] [blame] | 2422 | } |
Girish Gowdra | 6071f38 | 2021-12-14 12:52:04 +0530 | [diff] [blame] | 2423 | return f.processAddFlow(ctx, intfID, onuID, uniID, portNo, classifierInfo, actionInfo, flow, tpID, UsMeterID, DsMeterID, flowMetadata) |
Girish Gowdra | 9602eb4 | 2020-09-09 15:50:39 -0700 | [diff] [blame] | 2424 | } |
Girish Gowdra | 3d63303 | 2019-12-10 16:37:05 +0530 | [diff] [blame] | 2425 | |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 2426 | // handleFlowWithGroup adds multicast flow to the device. |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 2427 | func (f *OpenOltFlowMgr) handleFlowWithGroup(ctx context.Context, actionInfo, classifierInfo map[string]interface{}, flow *ofp.OfpFlowStats) error { |
Himani Chawla | b6296c4 | 2021-10-28 11:50:56 +0530 | [diff] [blame] | 2428 | classifierInfo[PacketTagType] = getPacketTypeFromClassifiers(classifierInfo) |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2429 | logger.Debugw(ctx, "add-multicast-flow", log.Fields{ |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 2430 | "classifier-info": classifierInfo, |
| 2431 | "actionInfo": actionInfo}) |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 2432 | |
Esin Karaman | 65409d8 | 2020-03-18 10:58:18 +0000 | [diff] [blame] | 2433 | networkInterfaceID, err := f.getNNIInterfaceIDOfMulticastFlow(ctx, classifierInfo) |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 2434 | if err != nil { |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 2435 | return olterrors.NewErrNotFound("multicast-in-port", log.Fields{"classifier": classifierInfo}, err) |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 2436 | } |
Esin Karaman | fcddfcf | 2020-03-04 13:34:38 +0000 | [diff] [blame] | 2437 | |
Esin Karaman | fcddfcf | 2020-03-04 13:34:38 +0000 | [diff] [blame] | 2438 | delete(classifierInfo, EthType) |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 2439 | |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 2440 | onuID := NoneOnuID |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 2441 | |
yasin sapli | bddc2d7 | 2022-02-08 13:10:17 +0000 | [diff] [blame] | 2442 | present, err := f.resourceMgr.IsFlowOnKvStore(ctx, int32(onuID), flow.Id) |
yasin sapli | d056627 | 2021-12-21 09:10:30 +0000 | [diff] [blame] | 2443 | if present { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2444 | logger.Infow(ctx, "multicast-flow-exists-not-re-adding", log.Fields{"classifier-info": classifierInfo}) |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 2445 | return nil |
yasin sapli | d056627 | 2021-12-21 09:10:30 +0000 | [diff] [blame] | 2446 | } else if err != nil { |
| 2447 | logger.Errorw(ctx, "aborting-handleFlowWithGroup--flow-may-already-exist", |
| 2448 | log.Fields{"intf-id": networkInterfaceID, "onu-id": onuID, "flow-id": flow.Id}) |
| 2449 | return err |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 2450 | } |
yasin sapli | d056627 | 2021-12-21 09:10:30 +0000 | [diff] [blame] | 2451 | |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 2452 | classifierProto, err := makeOpenOltClassifierField(classifierInfo) |
| 2453 | if err != nil { |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 2454 | return olterrors.NewErrInvalidValue(log.Fields{"classifier": classifierInfo}, err) |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 2455 | } |
| 2456 | groupID := actionInfo[GroupID].(uint32) |
| 2457 | multicastFlow := openoltpb2.Flow{ |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 2458 | FlowId: flow.Id, |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 2459 | FlowType: Multicast, |
| 2460 | NetworkIntfId: int32(networkInterfaceID), |
| 2461 | GroupId: groupID, |
| 2462 | Classifier: classifierProto, |
| 2463 | Priority: int32(flow.Priority), |
| 2464 | Cookie: flow.Cookie} |
| 2465 | |
Kent Hagerman | e6ff101 | 2020-07-14 15:07:53 -0400 | [diff] [blame] | 2466 | if err := f.addFlowToDevice(ctx, flow, &multicastFlow); err != nil { |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 2467 | return olterrors.NewErrFlowOp("add", flow.Id, log.Fields{"flow": multicastFlow}, err) |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 2468 | } |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2469 | logger.Info(ctx, "multicast-flow-added-to-device-successfully") |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 2470 | //get cached group |
Girish Gowdra | 9602eb4 | 2020-09-09 15:50:39 -0700 | [diff] [blame] | 2471 | if group, _, err := f.grpMgr.getFlowGroupFromKVStore(ctx, groupID, true); err == nil { |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 2472 | //calling groupAdd to set group members after multicast flow creation |
Girish Gowdra | 9602eb4 | 2020-09-09 15:50:39 -0700 | [diff] [blame] | 2473 | if err := f.grpMgr.ModifyGroup(ctx, group); err != nil { |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 2474 | return olterrors.NewErrGroupOp("modify", groupID, log.Fields{"group": group}, err) |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 2475 | } |
Kent Hagerman | e6ff101 | 2020-07-14 15:07:53 -0400 | [diff] [blame] | 2476 | //cached group can be removed now |
| 2477 | if err := f.resourceMgr.RemoveFlowGroupFromKVStore(ctx, groupID, true); err != nil { |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 2478 | logger.Warnw(ctx, "failed-to-remove-flow-group", log.Fields{"group-id": groupID, "err": err}) |
Kent Hagerman | e6ff101 | 2020-07-14 15:07:53 -0400 | [diff] [blame] | 2479 | } |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 2480 | } |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 2481 | |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 2482 | return nil |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 2483 | } |
| 2484 | |
Esin Karaman | 65409d8 | 2020-03-18 10:58:18 +0000 | [diff] [blame] | 2485 | //getNNIInterfaceIDOfMulticastFlow returns associated NNI interface id of the inPort criterion if exists; returns the first NNI interface of the device otherwise |
| 2486 | func (f *OpenOltFlowMgr) getNNIInterfaceIDOfMulticastFlow(ctx context.Context, classifierInfo map[string]interface{}) (uint32, error) { |
| 2487 | if inPort, ok := classifierInfo[InPort]; ok { |
Mahir Gunyel | 85f61c1 | 2021-10-06 11:53:45 -0700 | [diff] [blame] | 2488 | nniInterfaceID, err := plt.IntfIDFromNniPortNum(ctx, inPort.(uint32)) |
Esin Karaman | 65409d8 | 2020-03-18 10:58:18 +0000 | [diff] [blame] | 2489 | if err != nil { |
| 2490 | return 0, olterrors.NewErrInvalidValue(log.Fields{"nni-in-port-number": inPort}, err) |
| 2491 | } |
| 2492 | return nniInterfaceID, nil |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 2493 | } |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 2494 | |
| 2495 | // TODO: For now we support only one NNI port in VOLTHA. We shall use only the first NNI port, i.e., interface-id 0. |
| 2496 | return 0, nil |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 2497 | } |
| 2498 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 2499 | //sendTPDownloadMsgToChild send payload |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 2500 | func (f *OpenOltFlowMgr) sendTPDownloadMsgToChild(ctx context.Context, intfID uint32, onuID uint32, uniID uint32, uni string, TpID uint32, tpInst tp_pb.TechProfileInstance) error { |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 2501 | |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2502 | onuDev, err := f.getOnuDevice(ctx, intfID, onuID) |
Manikkaraj k | 884c124 | 2019-04-11 16:26:42 +0530 | [diff] [blame] | 2503 | if err != nil { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2504 | logger.Errorw(ctx, "couldnt-find-onu-child-device", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 2505 | log.Fields{ |
| 2506 | "intf-id": intfID, |
| 2507 | "onu-id": onuID, |
| 2508 | "uni-id": uniID}) |
Mahir Gunyel | 0f89fd2 | 2020-04-11 18:24:42 -0700 | [diff] [blame] | 2509 | return err |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 2510 | } |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2511 | logger.Debugw(ctx, "got-child-device-from-olt-device-handler", log.Fields{"onu-id": onuDev.deviceID}) |
manikkaraj k | 17652a7 | 2019-05-06 09:06:36 -0400 | [diff] [blame] | 2512 | |
yasin sapli | bddc2d7 | 2022-02-08 13:10:17 +0000 | [diff] [blame] | 2513 | tpPath := f.getTPpath(ctx, uni, TpID) |
khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 2514 | tpDownloadMsg := &ia.TechProfileDownloadMessage{ |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 2515 | DeviceId: onuDev.deviceID, |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 2516 | UniId: uniID, |
| 2517 | TpInstancePath: tpPath, |
khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 2518 | TechTpInstance: &ia.TechProfileDownloadMessage_TpInstance{TpInstance: &tpInst}, |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 2519 | } |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2520 | logger.Debugw(ctx, "sending-load-tech-profile-request-to-brcm-onu-adapter", log.Fields{"tpDownloadMsg": *tpDownloadMsg}) |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 2521 | |
| 2522 | err = f.deviceHandler.sendDownloadTechProfileToChildAdapter(ctx, onuDev.adapterEndpoint, tpDownloadMsg) |
| 2523 | if err != nil { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 2524 | return olterrors.NewErrCommunication("send-techprofile-download-request", |
| 2525 | log.Fields{ |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 2526 | "from-adapter": f.deviceHandler.openOLT.config.AdapterEndpoint, |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 2527 | "to-adapter": onuDev.deviceType, |
| 2528 | "onu-id": onuDev.deviceID, |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 2529 | "proxyDeviceID": onuDev.proxyDeviceID}, err) |
manikkaraj k | 17652a7 | 2019-05-06 09:06:36 -0400 | [diff] [blame] | 2530 | } |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2531 | logger.Infow(ctx, "success-sending-load-tech-profile-request-to-brcm-onu-adapter", log.Fields{"tpDownloadMsg": *tpDownloadMsg}) |
Manikkaraj k | 884c124 | 2019-04-11 16:26:42 +0530 | [diff] [blame] | 2532 | return nil |
manikkaraj k | bf256be | 2019-03-25 00:13:48 +0530 | [diff] [blame] | 2533 | } |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 2534 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 2535 | //GetLogicalPortFromPacketIn function computes logical port UNI/NNI port from packet-in indication and returns the same |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 2536 | func (f *OpenOltFlowMgr) GetLogicalPortFromPacketIn(ctx context.Context, packetIn *openoltpb2.PacketIndication) (uint32, error) { |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 2537 | var logicalPortNum uint32 |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 2538 | |
| 2539 | if packetIn.IntfType == "pon" { |
| 2540 | // packet indication does not have serial number , so sending as nil |
Esin Karaman | df392e1 | 2020-12-16 13:33:09 +0000 | [diff] [blame] | 2541 | // get onu and uni ids associated with the given pon and gem ports |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 2542 | onuID, uniID := packetIn.OnuId, packetIn.UniId |
| 2543 | logger.Debugf(ctx, "retrieved ONU and UNI IDs [%d, %d] by interface:%d, gem:%d", packetIn.OnuId, packetIn.UniId, packetIn.GemportId) |
Esin Karaman | df392e1 | 2020-12-16 13:33:09 +0000 | [diff] [blame] | 2544 | |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 2545 | if packetIn.PortNo != 0 { |
| 2546 | logicalPortNum = packetIn.PortNo |
| 2547 | } else { |
Mahir Gunyel | 85f61c1 | 2021-10-06 11:53:45 -0700 | [diff] [blame] | 2548 | logicalPortNum = plt.MkUniPortNum(ctx, packetIn.IntfId, onuID, uniID) |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 2549 | } |
| 2550 | // Store the gem port through which the packet_in came. Use the same gem port for packet_out |
Esin Karaman | 7fb80c2 | 2020-07-16 14:23:33 +0000 | [diff] [blame] | 2551 | f.UpdateGemPortForPktIn(ctx, packetIn.IntfId, onuID, logicalPortNum, packetIn.GemportId, packetIn.Pkt) |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 2552 | } else if packetIn.IntfType == "nni" { |
Mahir Gunyel | 85f61c1 | 2021-10-06 11:53:45 -0700 | [diff] [blame] | 2553 | logicalPortNum = plt.IntfIDToPortNo(packetIn.IntfId, voltha.Port_ETHERNET_NNI) |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 2554 | } |
Girish Gowdra | eb45029 | 2020-10-26 10:03:39 -0700 | [diff] [blame] | 2555 | |
| 2556 | if logger.V(log.DebugLevel) { |
| 2557 | logger.Debugw(ctx, "retrieved-logicalport-from-packet-in", |
| 2558 | log.Fields{ |
| 2559 | "logical-port-num": logicalPortNum, |
| 2560 | "intf-type": packetIn.IntfType, |
| 2561 | "packet": hex.EncodeToString(packetIn.Pkt), |
| 2562 | }) |
| 2563 | } |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 2564 | return logicalPortNum, nil |
| 2565 | } |
| 2566 | |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 2567 | //GetPacketOutGemPortID returns gemPortId |
Esin Karaman | 7fb80c2 | 2020-07-16 14:23:33 +0000 | [diff] [blame] | 2568 | func (f *OpenOltFlowMgr) GetPacketOutGemPortID(ctx context.Context, intfID uint32, onuID uint32, portNum uint32, packet []byte) (uint32, error) { |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 2569 | var gemPortID uint32 |
Esin Karaman | 7fb80c2 | 2020-07-16 14:23:33 +0000 | [diff] [blame] | 2570 | |
| 2571 | ctag, priority, err := getCTagFromPacket(ctx, packet) |
| 2572 | if err != nil { |
| 2573 | return 0, err |
| 2574 | } |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 2575 | |
Esin Karaman | 7fb80c2 | 2020-07-16 14:23:33 +0000 | [diff] [blame] | 2576 | pktInkey := rsrcMgr.PacketInInfoKey{IntfID: intfID, OnuID: onuID, LogicalPort: portNum, VlanID: ctag, Priority: priority} |
Matteo Scandolo | abf9c51 | 2020-06-23 19:31:14 -0700 | [diff] [blame] | 2577 | var ok bool |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 2578 | f.packetInGemPortLock.RLock() |
Matteo Scandolo | abf9c51 | 2020-06-23 19:31:14 -0700 | [diff] [blame] | 2579 | gemPortID, ok = f.packetInGemPort[pktInkey] |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 2580 | f.packetInGemPortLock.RUnlock() |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 2581 | if ok { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2582 | logger.Debugw(ctx, "found-gemport-for-pktin-key", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 2583 | log.Fields{ |
| 2584 | "pktinkey": pktInkey, |
| 2585 | "gem": gemPortID}) |
Matteo Scandolo | abf9c51 | 2020-06-23 19:31:14 -0700 | [diff] [blame] | 2586 | |
| 2587 | return gemPortID, nil |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 2588 | } |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 2589 | //If gem is not found in cache try to get it from kv store, if found in kv store, update the cache and return. |
Esin Karaman | 7fb80c2 | 2020-07-16 14:23:33 +0000 | [diff] [blame] | 2590 | gemPortID, err = f.resourceMgr.GetGemPortFromOnuPktIn(ctx, pktInkey) |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 2591 | if err == nil { |
| 2592 | if gemPortID != 0 { |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 2593 | f.packetInGemPortLock.Lock() |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 2594 | f.packetInGemPort[pktInkey] = gemPortID |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 2595 | f.packetInGemPortLock.Unlock() |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2596 | logger.Infow(ctx, "found-gem-port-from-kv-store-and-updating-cache-with-gemport", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 2597 | log.Fields{ |
| 2598 | "pktinkey": pktInkey, |
| 2599 | "gem": gemPortID}) |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 2600 | return gemPortID, nil |
| 2601 | } |
| 2602 | } |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 2603 | return uint32(0), olterrors.NewErrNotFound("gem-port", |
| 2604 | log.Fields{ |
| 2605 | "pktinkey": pktInkey, |
| 2606 | "gem": gemPortID}, err) |
Matteo Scandolo | abf9c51 | 2020-06-23 19:31:14 -0700 | [diff] [blame] | 2607 | |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 2608 | } |
| 2609 | |
Marcos Aurelio Carrero (Furukawa) | 388fb0a | 2021-02-04 18:05:11 -0300 | [diff] [blame] | 2610 | func (f *OpenOltFlowMgr) addTrapFlowOnNNI(ctx context.Context, logicalFlow *ofp.OfpFlowStats, classifier map[string]interface{}, portNo uint32) error { |
| 2611 | logger.Debug(ctx, "adding-trap-of-nni-flow") |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 2612 | action := make(map[string]interface{}) |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 2613 | classifier[PacketTagType] = DoubleTag |
| 2614 | action[TrapToHost] = true |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 2615 | /* We manage flowId resource pool on per PON port basis. |
| 2616 | Since this situation is tricky, as a hack, we pass the NNI port |
| 2617 | index (network_intf_id) as PON port Index for the flowId resource |
Marcos Aurelio Carrero (Furukawa) | 388fb0a | 2021-02-04 18:05:11 -0300 | [diff] [blame] | 2618 | pool. Also, there is no ONU Id available for trapping packets |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 2619 | on NNI port, use onu_id as -1 (invalid) |
| 2620 | ****************** CAVEAT ******************* |
| 2621 | This logic works if the NNI Port Id falls within the same valid |
| 2622 | range of PON Port Ids. If this doesn't work for some OLT Vendor |
| 2623 | we need to have a re-look at this. |
| 2624 | ********************************************* |
| 2625 | */ |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 2626 | onuID := -1 |
| 2627 | uniID := -1 |
| 2628 | gemPortID := -1 |
| 2629 | allocID := -1 |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2630 | networkInterfaceID, err := getNniIntfID(ctx, classifier, action) |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 2631 | if err != nil { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 2632 | return olterrors.NewErrNotFound("nni-intreface-id", |
| 2633 | log.Fields{ |
| 2634 | "classifier": classifier, |
| 2635 | "action": action}, |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 2636 | err) |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 2637 | } |
| 2638 | |
yasin sapli | bddc2d7 | 2022-02-08 13:10:17 +0000 | [diff] [blame] | 2639 | present, err := f.resourceMgr.IsFlowOnKvStore(ctx, int32(onuID), logicalFlow.Id) |
yasin sapli | d056627 | 2021-12-21 09:10:30 +0000 | [diff] [blame] | 2640 | if present { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2641 | logger.Info(ctx, "flow-exists-not-re-adding") |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 2642 | return nil |
yasin sapli | d056627 | 2021-12-21 09:10:30 +0000 | [diff] [blame] | 2643 | } else if err != nil { |
| 2644 | logger.Errorw(ctx, "aborting-addTrapFlowOnNNI--flow-may-already-exist", |
| 2645 | log.Fields{"intf-id": networkInterfaceID, "onu-id": onuID, "flow-id": logicalFlow.Id}) |
| 2646 | return err |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 2647 | } |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 2648 | |
Marcos Aurelio Carrero (Furukawa) | 388fb0a | 2021-02-04 18:05:11 -0300 | [diff] [blame] | 2649 | logger.Debugw(ctx, "creating-trap-of-nni-flow", |
| 2650 | log.Fields{ |
| 2651 | "classifier": classifier, |
| 2652 | "action": action, |
| 2653 | "flowId": logicalFlow.Id, |
| 2654 | "intf-id": networkInterfaceID}) |
| 2655 | |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 2656 | classifierProto, err := makeOpenOltClassifierField(classifier) |
| 2657 | if err != nil { |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 2658 | return olterrors.NewErrInvalidValue(log.Fields{"classifier": classifier}, err) |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 2659 | } |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2660 | logger.Debugw(ctx, "created-classifier-proto", log.Fields{"classifier": *classifierProto}) |
Gamze Abaka | 724d085 | 2020-03-18 12:10:24 +0000 | [diff] [blame] | 2661 | actionProto, err := makeOpenOltActionField(action, classifier) |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 2662 | if err != nil { |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 2663 | return olterrors.NewErrInvalidValue(log.Fields{"action": action}, err) |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 2664 | } |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2665 | logger.Debugw(ctx, "created-action-proto", log.Fields{"action": *actionProto}) |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 2666 | downstreamflow := openoltpb2.Flow{AccessIntfId: int32(-1), // AccessIntfId not required |
| 2667 | OnuId: int32(onuID), // OnuId not required |
| 2668 | UniId: int32(uniID), // UniId not used |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 2669 | FlowId: logicalFlow.Id, |
David K. Bainbridge | 82efc49 | 2019-09-04 09:57:11 -0700 | [diff] [blame] | 2670 | FlowType: Downstream, |
Girish Gowdru | 6a80bbd | 2019-07-02 07:36:09 -0700 | [diff] [blame] | 2671 | AllocId: int32(allocID), // AllocId not used |
| 2672 | NetworkIntfId: int32(networkInterfaceID), |
| 2673 | GemportId: int32(gemPortID), // GemportId not used |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 2674 | Classifier: classifierProto, |
| 2675 | Action: actionProto, |
| 2676 | Priority: int32(logicalFlow.Priority), |
| 2677 | Cookie: logicalFlow.Cookie, |
| 2678 | PortNo: portNo} |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 2679 | if err := f.addFlowToDevice(ctx, logicalFlow, &downstreamflow); err != nil { |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 2680 | return olterrors.NewErrFlowOp("add", logicalFlow.Id, log.Fields{"flow": downstreamflow}, err) |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 2681 | } |
Marcos Aurelio Carrero (Furukawa) | 388fb0a | 2021-02-04 18:05:11 -0300 | [diff] [blame] | 2682 | logger.Info(ctx, "trap-on-nni-flow-added–to-device-successfully") |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 2683 | return nil |
manikkaraj k | 9eb6cac | 2019-05-09 12:32:03 -0400 | [diff] [blame] | 2684 | } |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 2685 | |
Esin Karaman | ae41e2b | 2019-12-17 18:13:13 +0000 | [diff] [blame] | 2686 | //getPacketTypeFromClassifiers finds and returns packet type of a flow by checking flow classifiers |
| 2687 | func getPacketTypeFromClassifiers(classifierInfo map[string]interface{}) string { |
| 2688 | var packetType string |
| 2689 | ovid, ivid := false, false |
| 2690 | if vlanID, ok := classifierInfo[VlanVid].(uint32); ok { |
| 2691 | vid := vlanID & VlanvIDMask |
| 2692 | if vid != ReservedVlan { |
| 2693 | ovid = true |
| 2694 | } |
| 2695 | } |
| 2696 | if metadata, ok := classifierInfo[Metadata].(uint64); ok { |
| 2697 | vid := uint32(metadata) |
| 2698 | if vid != ReservedVlan { |
| 2699 | ivid = true |
| 2700 | } |
| 2701 | } |
| 2702 | if ovid && ivid { |
| 2703 | packetType = DoubleTag |
| 2704 | } else if !ovid && !ivid { |
| 2705 | packetType = Untagged |
| 2706 | } else { |
| 2707 | packetType = SingleTag |
| 2708 | } |
| 2709 | return packetType |
| 2710 | } |
| 2711 | |
| 2712 | //addIgmpTrapFlowOnNNI adds a trap-to-host flow on NNI |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 2713 | func (f *OpenOltFlowMgr) addIgmpTrapFlowOnNNI(ctx context.Context, logicalFlow *ofp.OfpFlowStats, classifier map[string]interface{}, portNo uint32) error { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2714 | logger.Infow(ctx, "adding-igmp-trap-of-nni-flow", log.Fields{"classifier-info": classifier}) |
Esin Karaman | ae41e2b | 2019-12-17 18:13:13 +0000 | [diff] [blame] | 2715 | action := make(map[string]interface{}) |
| 2716 | classifier[PacketTagType] = getPacketTypeFromClassifiers(classifier) |
| 2717 | action[TrapToHost] = true |
| 2718 | /* We manage flowId resource pool on per PON port basis. |
| 2719 | Since this situation is tricky, as a hack, we pass the NNI port |
| 2720 | index (network_intf_id) as PON port Index for the flowId resource |
| 2721 | pool. Also, there is no ONU Id available for trapping packets |
| 2722 | on NNI port, use onu_id as -1 (invalid) |
| 2723 | ****************** CAVEAT ******************* |
| 2724 | This logic works if the NNI Port Id falls within the same valid |
| 2725 | range of PON Port Ids. If this doesn't work for some OLT Vendor |
| 2726 | we need to have a re-look at this. |
| 2727 | ********************************************* |
| 2728 | */ |
| 2729 | onuID := -1 |
| 2730 | uniID := -1 |
| 2731 | gemPortID := -1 |
| 2732 | allocID := -1 |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2733 | networkInterfaceID, err := getNniIntfID(ctx, classifier, action) |
Esin Karaman | ae41e2b | 2019-12-17 18:13:13 +0000 | [diff] [blame] | 2734 | if err != nil { |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 2735 | return olterrors.NewErrNotFound("nni-interface-id", log.Fields{ |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 2736 | "classifier": classifier, |
| 2737 | "action": action}, |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 2738 | err) |
Esin Karaman | ae41e2b | 2019-12-17 18:13:13 +0000 | [diff] [blame] | 2739 | } |
yasin sapli | bddc2d7 | 2022-02-08 13:10:17 +0000 | [diff] [blame] | 2740 | present, err := f.resourceMgr.IsFlowOnKvStore(ctx, int32(onuID), logicalFlow.Id) |
yasin sapli | d056627 | 2021-12-21 09:10:30 +0000 | [diff] [blame] | 2741 | if present { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2742 | logger.Info(ctx, "igmp-flow-exists-not-re-adding") |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 2743 | return nil |
yasin sapli | d056627 | 2021-12-21 09:10:30 +0000 | [diff] [blame] | 2744 | } else if err != nil { |
| 2745 | logger.Errorw(ctx, "aborting-addIgmpTrapFlowOnNNI--flow-may-already-exist", |
| 2746 | log.Fields{"intf-id": networkInterfaceID, "onu-id": onuID, "flow-id": logicalFlow.Id}) |
| 2747 | return err |
Esin Karaman | ae41e2b | 2019-12-17 18:13:13 +0000 | [diff] [blame] | 2748 | } |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 2749 | |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 2750 | classifierProto, err := makeOpenOltClassifierField(classifier) |
| 2751 | if err != nil { |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 2752 | return olterrors.NewErrInvalidValue(log.Fields{"classifier": classifier}, err) |
Esin Karaman | ae41e2b | 2019-12-17 18:13:13 +0000 | [diff] [blame] | 2753 | } |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2754 | logger.Debugw(ctx, "created-classifier-proto-for-the-igmp-flow", log.Fields{"classifier": *classifierProto}) |
Gamze Abaka | 724d085 | 2020-03-18 12:10:24 +0000 | [diff] [blame] | 2755 | actionProto, err := makeOpenOltActionField(action, classifier) |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 2756 | if err != nil { |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 2757 | return olterrors.NewErrInvalidValue(log.Fields{"action": action}, err) |
Esin Karaman | ae41e2b | 2019-12-17 18:13:13 +0000 | [diff] [blame] | 2758 | } |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2759 | logger.Debugw(ctx, "created-action-proto-for-the-igmp-flow", log.Fields{"action": *actionProto}) |
Esin Karaman | ae41e2b | 2019-12-17 18:13:13 +0000 | [diff] [blame] | 2760 | downstreamflow := openoltpb2.Flow{AccessIntfId: int32(-1), // AccessIntfId not required |
| 2761 | OnuId: int32(onuID), // OnuId not required |
| 2762 | UniId: int32(uniID), // UniId not used |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 2763 | FlowId: logicalFlow.Id, |
Esin Karaman | ae41e2b | 2019-12-17 18:13:13 +0000 | [diff] [blame] | 2764 | FlowType: Downstream, |
| 2765 | AllocId: int32(allocID), // AllocId not used |
| 2766 | NetworkIntfId: int32(networkInterfaceID), |
| 2767 | GemportId: int32(gemPortID), // GemportId not used |
| 2768 | Classifier: classifierProto, |
| 2769 | Action: actionProto, |
| 2770 | Priority: int32(logicalFlow.Priority), |
| 2771 | Cookie: logicalFlow.Cookie, |
| 2772 | PortNo: portNo} |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 2773 | if err := f.addFlowToDevice(ctx, logicalFlow, &downstreamflow); err != nil { |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 2774 | return olterrors.NewErrFlowOp("add", logicalFlow.Id, log.Fields{"flow": downstreamflow}, err) |
Esin Karaman | ae41e2b | 2019-12-17 18:13:13 +0000 | [diff] [blame] | 2775 | } |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2776 | logger.Info(ctx, "igmp-trap-on-nni-flow-added-to-device-successfully") |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 2777 | |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 2778 | return nil |
Esin Karaman | ae41e2b | 2019-12-17 18:13:13 +0000 | [diff] [blame] | 2779 | } |
| 2780 | |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 2781 | func verifyMeterIDAndGetDirection(MeterID uint32, Dir tp_pb.Direction) (string, error) { |
| 2782 | if MeterID == 0 { // This should never happen |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 2783 | return "", olterrors.NewErrInvalidValue(log.Fields{"meter-id": MeterID}, nil).Log() |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 2784 | } |
| 2785 | if Dir == tp_pb.Direction_UPSTREAM { |
| 2786 | return "upstream", nil |
| 2787 | } else if Dir == tp_pb.Direction_DOWNSTREAM { |
| 2788 | return "downstream", nil |
| 2789 | } |
| 2790 | return "", nil |
| 2791 | } |
| 2792 | |
Kent Hagerman | e6ff101 | 2020-07-14 15:07:53 -0400 | [diff] [blame] | 2793 | // nolint: gocyclo |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 2794 | func (f *OpenOltFlowMgr) checkAndAddFlow(ctx context.Context, args map[string]uint32, classifierInfo map[string]interface{}, |
Takahiro Suzuki | 2ba0e0b | 2020-06-05 14:23:03 -0700 | [diff] [blame] | 2795 | actionInfo map[string]interface{}, flow *ofp.OfpFlowStats, TpInst interface{}, gemPorts []uint32, |
Gamze Abaka | 6d0a64f | 2021-11-18 08:08:33 +0000 | [diff] [blame] | 2796 | tpID uint32, uni string) error { |
Gamze Abaka | 7650be6 | 2021-02-26 10:50:36 +0000 | [diff] [blame] | 2797 | var gemPortID uint32 |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 2798 | intfID := args[IntfID] |
| 2799 | onuID := args[OnuID] |
| 2800 | uniID := args[UniID] |
| 2801 | portNo := args[PortNo] |
Takahiro Suzuki | 2ba0e0b | 2020-06-05 14:23:03 -0700 | [diff] [blame] | 2802 | allocID := args[AllocID] |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 2803 | pbitToGem := make(map[uint32]uint32) |
Gamze Abaka | 7650be6 | 2021-02-26 10:50:36 +0000 | [diff] [blame] | 2804 | gemToAes := make(map[uint32]bool) |
| 2805 | |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 2806 | var attributes []*tp_pb.GemPortAttributes |
Gamze Abaka | 7650be6 | 2021-02-26 10:50:36 +0000 | [diff] [blame] | 2807 | var direction = tp_pb.Direction_UPSTREAM |
| 2808 | switch TpInst := TpInst.(type) { |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 2809 | case *tp_pb.TechProfileInstance: |
Mahir Gunyel | 85f61c1 | 2021-10-06 11:53:45 -0700 | [diff] [blame] | 2810 | if plt.IsUpstream(actionInfo[Output].(uint32)) { |
Gamze Abaka | 7650be6 | 2021-02-26 10:50:36 +0000 | [diff] [blame] | 2811 | attributes = TpInst.UpstreamGemPortAttributeList |
| 2812 | } else { |
| 2813 | attributes = TpInst.DownstreamGemPortAttributeList |
| 2814 | direction = tp_pb.Direction_DOWNSTREAM |
| 2815 | } |
| 2816 | default: |
| 2817 | logger.Errorw(ctx, "unsupported-tech", log.Fields{"tpInst": TpInst}) |
Gamze Abaka | 6d0a64f | 2021-11-18 08:08:33 +0000 | [diff] [blame] | 2818 | return olterrors.NewErrInvalidValue(log.Fields{"tpInst": TpInst}, nil) |
Gamze Abaka | 7650be6 | 2021-02-26 10:50:36 +0000 | [diff] [blame] | 2819 | } |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 2820 | |
| 2821 | if len(gemPorts) == 1 { |
| 2822 | // If there is only single gemport use that and do not populate pbitToGem map |
Gamze Abaka | 7650be6 | 2021-02-26 10:50:36 +0000 | [diff] [blame] | 2823 | gemPortID = gemPorts[0] |
| 2824 | gemToAes[gemPortID], _ = strconv.ParseBool(attributes[0].AesEncryption) |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 2825 | } else if pcp, ok := classifierInfo[VlanPcp]; !ok { |
| 2826 | for idx, gemID := range gemPorts { |
Gamze Abaka | 7650be6 | 2021-02-26 10:50:36 +0000 | [diff] [blame] | 2827 | pBitMap := attributes[idx].PbitMap |
| 2828 | // Trim the bitMapPrefix form the binary string and then iterate each character in the binary string. |
| 2829 | // If the character is set to pbit1, extract the pcp value from the position of this character in the string. |
| 2830 | // Update the pbitToGem map with key being the pcp bit and the value being the gemPortID that consumes |
khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 2831 | // this pcp bit traffca. |
Gamze Abaka | 7650be6 | 2021-02-26 10:50:36 +0000 | [diff] [blame] | 2832 | for pos, pbitSet := range strings.TrimPrefix(pBitMap, bitMapPrefix) { |
| 2833 | if pbitSet == pbit1 { |
| 2834 | pcp := uint32(len(strings.TrimPrefix(pBitMap, bitMapPrefix))) - 1 - uint32(pos) |
| 2835 | pbitToGem[pcp] = gemID |
| 2836 | gemToAes[gemID], _ = strconv.ParseBool(attributes[idx].AesEncryption) |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 2837 | } |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 2838 | } |
| 2839 | } |
| 2840 | } else { // Extract the exact gemport which maps to the PCP classifier in the flow |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 2841 | if gem := f.techprofile.GetGemportForPbit(ctx, TpInst, direction, pcp.(uint32)); gem != nil { |
| 2842 | gemPortID = gem.(*tp_pb.GemPortAttributes).GemportId |
| 2843 | gemToAes[gemPortID], _ = strconv.ParseBool(gem.(*tp_pb.GemPortAttributes).AesEncryption) |
Gamze Abaka | 7650be6 | 2021-02-26 10:50:36 +0000 | [diff] [blame] | 2844 | } |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 2845 | } |
| 2846 | |
Gamze Abaka | 7650be6 | 2021-02-26 10:50:36 +0000 | [diff] [blame] | 2847 | flowContext := &flowContext{intfID, onuID, uniID, portNo, classifierInfo, actionInfo, |
| 2848 | flow, allocID, gemPortID, tpID, pbitToGem, gemToAes} |
| 2849 | |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 2850 | if ipProto, ok := classifierInfo[IPProto]; ok { |
| 2851 | if ipProto.(uint32) == IPProtoDhcp { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2852 | logger.Infow(ctx, "adding-dhcp-flow", log.Fields{ |
Matteo Scandolo | 9218624 | 2020-06-12 10:54:18 -0700 | [diff] [blame] | 2853 | "tp-id": tpID, |
| 2854 | "alloc-id": allocID, |
| 2855 | "intf-id": intfID, |
| 2856 | "onu-id": onuID, |
| 2857 | "uni-id": uniID, |
| 2858 | }) |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 2859 | //Adding DHCP upstream flow |
Gamze Abaka | 7650be6 | 2021-02-26 10:50:36 +0000 | [diff] [blame] | 2860 | if err := f.addDHCPTrapFlow(ctx, flowContext); err != nil { |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 2861 | logger.Warn(ctx, err) |
Gamze Abaka | 411ef2f | 2021-11-22 08:38:08 +0000 | [diff] [blame] | 2862 | logger.Errorw(ctx, "reverting-scheduler-and-queue-for-onu", log.Fields{"intf-id": intfID, "onu-id": onuID, "uni-id": uniID, "flow-id": flow.Id, "tp-id": tpID}) |
| 2863 | _ = f.clearResources(ctx, intfID, int32(onuID), int32(uniID), flow.Id, portNo, tpID, false) |
Gamze Abaka | 6d0a64f | 2021-11-18 08:08:33 +0000 | [diff] [blame] | 2864 | return err |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 2865 | } |
| 2866 | |
Girish Gowdra | 3262521 | 2020-04-29 11:26:35 -0700 | [diff] [blame] | 2867 | } else if ipProto.(uint32) == IgmpProto { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2868 | logger.Infow(ctx, "adding-us-igmp-flow", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 2869 | log.Fields{ |
| 2870 | "intf-id": intfID, |
| 2871 | "onu-id": onuID, |
| 2872 | "uni-id": uniID, |
| 2873 | "classifier-info:": classifierInfo}) |
Gamze Abaka | 7650be6 | 2021-02-26 10:50:36 +0000 | [diff] [blame] | 2874 | if err := f.addIGMPTrapFlow(ctx, flowContext); err != nil { |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 2875 | logger.Warn(ctx, err) |
Gamze Abaka | 411ef2f | 2021-11-22 08:38:08 +0000 | [diff] [blame] | 2876 | logger.Errorw(ctx, "reverting-scheduler-and-queue-for-onu", log.Fields{"intf-id": intfID, "onu-id": onuID, "uni-id": uniID, "flow-id": flow.Id, "tp-id": tpID}) |
| 2877 | _ = f.clearResources(ctx, intfID, int32(onuID), int32(uniID), flow.Id, portNo, tpID, false) |
Gamze Abaka | 6d0a64f | 2021-11-18 08:08:33 +0000 | [diff] [blame] | 2878 | return err |
Esin Karaman | ae41e2b | 2019-12-17 18:13:13 +0000 | [diff] [blame] | 2879 | } |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 2880 | } else { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2881 | logger.Errorw(ctx, "invalid-classifier-to-handle", log.Fields{"classifier": classifierInfo, "action": actionInfo}) |
Gamze Abaka | 6d0a64f | 2021-11-18 08:08:33 +0000 | [diff] [blame] | 2882 | return olterrors.NewErrInvalidValue(log.Fields{"classifier": classifierInfo, "action": actionInfo}, nil) |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 2883 | } |
| 2884 | } else if ethType, ok := classifierInfo[EthType]; ok { |
Marcos Aurelio Carrero (Furukawa) | 1dc2bfb | 2021-02-17 15:10:12 -0300 | [diff] [blame] | 2885 | if ethType.(uint32) == EapEthType { |
| 2886 | logger.Infow(ctx, "adding-eapol-flow", log.Fields{ |
Matteo Scandolo | 9218624 | 2020-06-12 10:54:18 -0700 | [diff] [blame] | 2887 | "intf-id": intfID, |
| 2888 | "onu-id": onuID, |
| 2889 | "uni-id": uniID, |
Marcos Aurelio Carrero (Furukawa) | 388fb0a | 2021-02-04 18:05:11 -0300 | [diff] [blame] | 2890 | "ethType": ethType, |
Matteo Scandolo | 9218624 | 2020-06-12 10:54:18 -0700 | [diff] [blame] | 2891 | }) |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 2892 | var vlanID uint32 |
| 2893 | if val, ok := classifierInfo[VlanVid]; ok { |
| 2894 | vlanID = (val.(uint32)) & VlanvIDMask |
| 2895 | } else { |
| 2896 | vlanID = DefaultMgmtVlan |
| 2897 | } |
Gamze Abaka | 7650be6 | 2021-02-26 10:50:36 +0000 | [diff] [blame] | 2898 | if err := f.addEthTypeBasedFlow(ctx, flowContext, vlanID, ethType.(uint32)); err != nil { |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 2899 | logger.Warn(ctx, err) |
Gamze Abaka | 411ef2f | 2021-11-22 08:38:08 +0000 | [diff] [blame] | 2900 | logger.Errorw(ctx, "reverting-scheduler-and-queue-for-onu", log.Fields{"intf-id": intfID, "onu-id": onuID, "uni-id": uniID, "flow-id": flow.Id, "tp-id": tpID}) |
| 2901 | _ = f.clearResources(ctx, intfID, int32(onuID), int32(uniID), flow.Id, portNo, tpID, false) |
Gamze Abaka | 6d0a64f | 2021-11-18 08:08:33 +0000 | [diff] [blame] | 2902 | return err |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 2903 | } |
Marcos Aurelio Carrero (Furukawa) | 1dc2bfb | 2021-02-17 15:10:12 -0300 | [diff] [blame] | 2904 | } else if ethType.(uint32) == PPPoEDEthType { |
| 2905 | logger.Infow(ctx, "adding-pppoed-flow", log.Fields{ |
| 2906 | "tp-id": tpID, |
| 2907 | "alloc-id": allocID, |
| 2908 | "intf-id": intfID, |
| 2909 | "onu-id": onuID, |
| 2910 | "uni-id": uniID, |
| 2911 | }) |
| 2912 | //Adding PPPOED upstream flow |
Gamze Abaka | 7650be6 | 2021-02-26 10:50:36 +0000 | [diff] [blame] | 2913 | if err := f.addUpstreamTrapFlow(ctx, flowContext); err != nil { |
Marcos Aurelio Carrero (Furukawa) | 1dc2bfb | 2021-02-17 15:10:12 -0300 | [diff] [blame] | 2914 | logger.Warn(ctx, err) |
Gamze Abaka | 411ef2f | 2021-11-22 08:38:08 +0000 | [diff] [blame] | 2915 | logger.Errorw(ctx, "reverting-scheduler-and-queue-for-onu", log.Fields{"intf-id": intfID, "onu-id": onuID, "uni-id": uniID, "flow-id": flow.Id, "tp-id": tpID}) |
| 2916 | _ = f.clearResources(ctx, intfID, int32(onuID), int32(uniID), flow.Id, portNo, tpID, false) |
Gamze Abaka | 6d0a64f | 2021-11-18 08:08:33 +0000 | [diff] [blame] | 2917 | return err |
Marcos Aurelio Carrero (Furukawa) | 1dc2bfb | 2021-02-17 15:10:12 -0300 | [diff] [blame] | 2918 | } |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 2919 | } |
Gamze Abaka | 7650be6 | 2021-02-26 10:50:36 +0000 | [diff] [blame] | 2920 | } else if direction == tp_pb.Direction_UPSTREAM { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2921 | logger.Infow(ctx, "adding-upstream-data-rule", log.Fields{ |
Matteo Scandolo | 9218624 | 2020-06-12 10:54:18 -0700 | [diff] [blame] | 2922 | "intf-id": intfID, |
| 2923 | "onu-id": onuID, |
| 2924 | "uni-id": uniID, |
| 2925 | }) |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 2926 | //Adding HSIA upstream flow |
Gamze Abaka | 7650be6 | 2021-02-26 10:50:36 +0000 | [diff] [blame] | 2927 | if err := f.addUpstreamDataPathFlow(ctx, flowContext); err != nil { |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 2928 | logger.Warn(ctx, err) |
Gamze Abaka | 411ef2f | 2021-11-22 08:38:08 +0000 | [diff] [blame] | 2929 | logger.Errorw(ctx, "reverting-scheduler-and-queue-for-onu", log.Fields{"intf-id": intfID, "onu-id": onuID, "uni-id": uniID, "flow-id": flow.Id, "tp-id": tpID}) |
| 2930 | _ = f.clearResources(ctx, intfID, int32(onuID), int32(uniID), flow.Id, portNo, tpID, false) |
Gamze Abaka | 6d0a64f | 2021-11-18 08:08:33 +0000 | [diff] [blame] | 2931 | return err |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 2932 | } |
Gamze Abaka | 7650be6 | 2021-02-26 10:50:36 +0000 | [diff] [blame] | 2933 | } else if direction == tp_pb.Direction_DOWNSTREAM { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2934 | logger.Infow(ctx, "adding-downstream-data-rule", log.Fields{ |
Matteo Scandolo | 9218624 | 2020-06-12 10:54:18 -0700 | [diff] [blame] | 2935 | "intf-id": intfID, |
| 2936 | "onu-id": onuID, |
| 2937 | "uni-id": uniID, |
| 2938 | }) |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 2939 | //Adding HSIA downstream flow |
Gamze Abaka | 7650be6 | 2021-02-26 10:50:36 +0000 | [diff] [blame] | 2940 | if err := f.addDownstreamDataPathFlow(ctx, flowContext); err != nil { |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 2941 | logger.Warn(ctx, err) |
Gamze Abaka | 411ef2f | 2021-11-22 08:38:08 +0000 | [diff] [blame] | 2942 | logger.Errorw(ctx, "reverting-scheduler-and-queue-for-onu", log.Fields{"intf-id": intfID, "onu-id": onuID, "uni-id": uniID, "flow-id": flow.Id, "tp-id": tpID}) |
| 2943 | _ = f.clearResources(ctx, intfID, int32(onuID), int32(uniID), flow.Id, portNo, tpID, false) |
Gamze Abaka | 6d0a64f | 2021-11-18 08:08:33 +0000 | [diff] [blame] | 2944 | return err |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 2945 | } |
| 2946 | } else { |
Gamze Abaka | 6d0a64f | 2021-11-18 08:08:33 +0000 | [diff] [blame] | 2947 | return olterrors.NewErrInvalidValue(log.Fields{ |
| 2948 | "intf-id": intfID, |
| 2949 | "onu-id": onuID, |
| 2950 | "uni-id": uniID, |
| 2951 | "classifier": classifierInfo, |
| 2952 | "action": actionInfo, |
| 2953 | "flow": flow}, |
| 2954 | nil).Log() |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 2955 | } |
| 2956 | // Send Techprofile download event to child device in go routine as it takes time |
Kent Hagerman | e6ff101 | 2020-07-14 15:07:53 -0400 | [diff] [blame] | 2957 | go func() { |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 2958 | if err := f.sendTPDownloadMsgToChild(ctx, intfID, onuID, uniID, uni, tpID, *(TpInst.(*tp_pb.TechProfileInstance))); err != nil { |
Kent Hagerman | e6ff101 | 2020-07-14 15:07:53 -0400 | [diff] [blame] | 2959 | logger.Warn(ctx, err) |
| 2960 | } |
| 2961 | }() |
Gamze Abaka | 6d0a64f | 2021-11-18 08:08:33 +0000 | [diff] [blame] | 2962 | return nil |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 2963 | } |
| 2964 | |
Gamze Abaka | cb0e677 | 2021-06-10 08:32:12 +0000 | [diff] [blame] | 2965 | func (f *OpenOltFlowMgr) isAllocUsedByAnotherUNI(ctx context.Context, sq schedQueue) bool { |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 2966 | tpInst := sq.tpInst.(*tp_pb.TechProfileInstance) |
| 2967 | if tpInst.InstanceControl.Onu == "single-instance" && sq.direction == tp_pb.Direction_UPSTREAM { |
| 2968 | tpInstances := f.techprofile.FindAllTpInstances(ctx, f.deviceHandler.device.Id, sq.tpID, sq.intfID, sq.onuID).([]tp_pb.TechProfileInstance) |
Girish Gowdra | 5493426 | 2019-11-13 14:19:55 +0530 | [diff] [blame] | 2969 | for i := 0; i < len(tpInstances); i++ { |
| 2970 | tpI := tpInstances[i] |
Gamze Abaka | cb0e677 | 2021-06-10 08:32:12 +0000 | [diff] [blame] | 2971 | if tpI.SubscriberIdentifier != tpInst.SubscriberIdentifier && |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 2972 | tpI.UsScheduler.AllocId == tpInst.UsScheduler.AllocId { |
Girish Gowdra | f3728b1 | 2022-02-02 21:46:51 -0800 | [diff] [blame] | 2973 | logger.Debugw(ctx, "alloc-is-in-use-on-another-uni", |
Gamze Abaka | cb0e677 | 2021-06-10 08:32:12 +0000 | [diff] [blame] | 2974 | log.Fields{ |
| 2975 | "device-id": f.deviceHandler.device.Id, |
| 2976 | "intfID": sq.intfID, |
| 2977 | "onuID": sq.onuID, |
| 2978 | "uniID": sq.uniID, |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 2979 | "allocID": tpI.UsScheduler.AllocId, |
Gamze Abaka | cb0e677 | 2021-06-10 08:32:12 +0000 | [diff] [blame] | 2980 | }) |
| 2981 | return true |
Girish Gowdra | 5493426 | 2019-11-13 14:19:55 +0530 | [diff] [blame] | 2982 | } |
| 2983 | } |
| 2984 | } |
Gamze Abaka | cb0e677 | 2021-06-10 08:32:12 +0000 | [diff] [blame] | 2985 | return false |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 2986 | } |
| 2987 | |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2988 | func formulateClassifierInfoFromFlow(ctx context.Context, classifierInfo map[string]interface{}, flow *ofp.OfpFlowStats) { |
Scott Baker | 355d174 | 2019-10-24 10:57:52 -0700 | [diff] [blame] | 2989 | for _, field := range flows.GetOfbFields(flow) { |
| 2990 | if field.Type == flows.ETH_TYPE { |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 2991 | classifierInfo[EthType] = field.GetEthType() |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 2992 | logger.Debug(ctx, "field-type-eth-type", log.Fields{"classifierInfo[ETH_TYPE]": classifierInfo[EthType].(uint32)}) |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 2993 | } else if field.Type == flows.ETH_DST { |
| 2994 | classifierInfo[EthDst] = field.GetEthDst() |
Girish Gowdra | ffa52e5 | 2022-02-16 15:48:10 -0800 | [diff] [blame^] | 2995 | logger.Debug(ctx, "field-type-eth-dst", log.Fields{"classifierInfo[ETH_DST]": classifierInfo[EthDst].([]uint8)}) |
| 2996 | } else if field.Type == flows.ETH_SRC { |
| 2997 | classifierInfo[EthSrc] = field.GetEthSrc() |
| 2998 | logger.Debug(ctx, "field-type-eth-src", log.Fields{"classifierInfo[ETH_SRC]": classifierInfo[EthSrc].([]uint8)}) |
Scott Baker | 355d174 | 2019-10-24 10:57:52 -0700 | [diff] [blame] | 2999 | } else if field.Type == flows.IP_PROTO { |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 3000 | classifierInfo[IPProto] = field.GetIpProto() |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 3001 | logger.Debug(ctx, "field-type-ip-proto", log.Fields{"classifierInfo[IP_PROTO]": classifierInfo[IPProto].(uint32)}) |
Scott Baker | 355d174 | 2019-10-24 10:57:52 -0700 | [diff] [blame] | 3002 | } else if field.Type == flows.IN_PORT { |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 3003 | classifierInfo[InPort] = field.GetPort() |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 3004 | logger.Debug(ctx, "field-type-in-port", log.Fields{"classifierInfo[IN_PORT]": classifierInfo[InPort].(uint32)}) |
Scott Baker | 355d174 | 2019-10-24 10:57:52 -0700 | [diff] [blame] | 3005 | } else if field.Type == flows.VLAN_VID { |
Andrea Campanella | faa4215 | 2021-10-28 11:50:56 +0530 | [diff] [blame] | 3006 | // The ReservedVlan is used to signify transparent vlan. Do not do any classification when we see ReservedVlan |
| 3007 | if field.GetVlanVid() != ReservedVlan { |
| 3008 | classifierInfo[VlanVid] = field.GetVlanVid() & 0xfff |
| 3009 | logger.Debug(ctx, "field-type-vlan-vid", log.Fields{"classifierInfo[VLAN_VID]": classifierInfo[VlanVid].(uint32)}) |
| 3010 | } |
Scott Baker | 355d174 | 2019-10-24 10:57:52 -0700 | [diff] [blame] | 3011 | } else if field.Type == flows.VLAN_PCP { |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 3012 | classifierInfo[VlanPcp] = field.GetVlanPcp() |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 3013 | logger.Debug(ctx, "field-type-vlan-pcp", log.Fields{"classifierInfo[VLAN_PCP]": classifierInfo[VlanPcp].(uint32)}) |
Scott Baker | 355d174 | 2019-10-24 10:57:52 -0700 | [diff] [blame] | 3014 | } else if field.Type == flows.UDP_DST { |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 3015 | classifierInfo[UDPDst] = field.GetUdpDst() |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 3016 | logger.Debug(ctx, "field-type-udp-dst", log.Fields{"classifierInfo[UDP_DST]": classifierInfo[UDPDst].(uint32)}) |
Scott Baker | 355d174 | 2019-10-24 10:57:52 -0700 | [diff] [blame] | 3017 | } else if field.Type == flows.UDP_SRC { |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 3018 | classifierInfo[UDPSrc] = field.GetUdpSrc() |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 3019 | logger.Debug(ctx, "field-type-udp-src", log.Fields{"classifierInfo[UDP_SRC]": classifierInfo[UDPSrc].(uint32)}) |
Scott Baker | 355d174 | 2019-10-24 10:57:52 -0700 | [diff] [blame] | 3020 | } else if field.Type == flows.IPV4_DST { |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 3021 | classifierInfo[Ipv4Dst] = field.GetIpv4Dst() |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 3022 | logger.Debug(ctx, "field-type-ipv4-dst", log.Fields{"classifierInfo[IPV4_DST]": classifierInfo[Ipv4Dst].(uint32)}) |
Scott Baker | 355d174 | 2019-10-24 10:57:52 -0700 | [diff] [blame] | 3023 | } else if field.Type == flows.IPV4_SRC { |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 3024 | classifierInfo[Ipv4Src] = field.GetIpv4Src() |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 3025 | logger.Debug(ctx, "field-type-ipv4-src", log.Fields{"classifierInfo[IPV4_SRC]": classifierInfo[Ipv4Src].(uint32)}) |
Scott Baker | 355d174 | 2019-10-24 10:57:52 -0700 | [diff] [blame] | 3026 | } else if field.Type == flows.METADATA { |
David K. Bainbridge | 82efc49 | 2019-09-04 09:57:11 -0700 | [diff] [blame] | 3027 | classifierInfo[Metadata] = field.GetTableMetadata() |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 3028 | logger.Debug(ctx, "field-type-metadata", log.Fields{"classifierInfo[Metadata]": classifierInfo[Metadata].(uint64)}) |
Scott Baker | 355d174 | 2019-10-24 10:57:52 -0700 | [diff] [blame] | 3029 | } else if field.Type == flows.TUNNEL_ID { |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 3030 | classifierInfo[TunnelID] = field.GetTunnelId() |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 3031 | logger.Debug(ctx, "field-type-tunnelId", log.Fields{"classifierInfo[TUNNEL_ID]": classifierInfo[TunnelID].(uint64)}) |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 3032 | } else { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 3033 | logger.Errorw(ctx, "un-supported-field-type", log.Fields{"type": field.Type}) |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 3034 | return |
| 3035 | } |
| 3036 | } |
| 3037 | } |
| 3038 | |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 3039 | func formulateActionInfoFromFlow(ctx context.Context, actionInfo, classifierInfo map[string]interface{}, flow *ofp.OfpFlowStats) error { |
Scott Baker | 355d174 | 2019-10-24 10:57:52 -0700 | [diff] [blame] | 3040 | for _, action := range flows.GetActions(flow) { |
| 3041 | if action.Type == flows.OUTPUT { |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 3042 | if out := action.GetOutput(); out != nil { |
David K. Bainbridge | 82efc49 | 2019-09-04 09:57:11 -0700 | [diff] [blame] | 3043 | actionInfo[Output] = out.GetPort() |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 3044 | logger.Debugw(ctx, "action-type-output", log.Fields{"out-port": actionInfo[Output].(uint32)}) |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 3045 | } else { |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 3046 | return olterrors.NewErrInvalidValue(log.Fields{"output-port": nil}, nil) |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 3047 | } |
Scott Baker | 355d174 | 2019-10-24 10:57:52 -0700 | [diff] [blame] | 3048 | } else if action.Type == flows.POP_VLAN { |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 3049 | actionInfo[PopVlan] = true |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 3050 | logger.Debugw(ctx, "action-type-pop-vlan", log.Fields{"in_port": classifierInfo[InPort].(uint32)}) |
Scott Baker | 355d174 | 2019-10-24 10:57:52 -0700 | [diff] [blame] | 3051 | } else if action.Type == flows.PUSH_VLAN { |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 3052 | if out := action.GetPush(); out != nil { |
| 3053 | if tpid := out.GetEthertype(); tpid != 0x8100 { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 3054 | logger.Errorw(ctx, "invalid ethertype in push action", log.Fields{"ethertype": actionInfo[PushVlan].(int32)}) |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 3055 | } else { |
| 3056 | actionInfo[PushVlan] = true |
| 3057 | actionInfo[TPID] = tpid |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 3058 | logger.Debugw(ctx, "action-type-push-vlan", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 3059 | log.Fields{ |
| 3060 | "push-tpid": actionInfo[TPID].(uint32), |
| 3061 | "in-port": classifierInfo[InPort].(uint32)}) |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 3062 | } |
| 3063 | } |
Scott Baker | 355d174 | 2019-10-24 10:57:52 -0700 | [diff] [blame] | 3064 | } else if action.Type == flows.SET_FIELD { |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 3065 | if out := action.GetSetField(); out != nil { |
| 3066 | if field := out.GetField(); field != nil { |
| 3067 | if ofClass := field.GetOxmClass(); ofClass != ofp.OfpOxmClass_OFPXMC_OPENFLOW_BASIC { |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 3068 | return olterrors.NewErrInvalidValue(log.Fields{"openflow-class": ofClass}, nil) |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 3069 | } |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 3070 | /*logger.Debugw(ctx, "action-type-set-field",log.Fields{"field": field, "in_port": classifierInfo[IN_PORT].(uint32)})*/ |
| 3071 | formulateSetFieldActionInfoFromFlow(ctx, field, actionInfo) |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 3072 | } |
| 3073 | } |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 3074 | } else if action.Type == flows.GROUP { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 3075 | formulateGroupActionInfoFromFlow(ctx, action, actionInfo) |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 3076 | } else { |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 3077 | return olterrors.NewErrInvalidValue(log.Fields{"action-type": action.Type}, nil) |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 3078 | } |
| 3079 | } |
| 3080 | return nil |
| 3081 | } |
| 3082 | |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 3083 | func formulateSetFieldActionInfoFromFlow(ctx context.Context, field *ofp.OfpOxmField, actionInfo map[string]interface{}) { |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 3084 | if ofbField := field.GetOfbField(); ofbField != nil { |
Gamze Abaka | c43a66e | 2020-05-11 11:00:42 +0000 | [diff] [blame] | 3085 | fieldtype := ofbField.GetType() |
| 3086 | if fieldtype == ofp.OxmOfbFieldTypes_OFPXMT_OFB_VLAN_VID { |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 3087 | if vlan := ofbField.GetVlanVid(); vlan != 0 { |
| 3088 | actionInfo[VlanVid] = vlan & 0xfff |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 3089 | logger.Debugw(ctx, "action-set-vlan-vid", log.Fields{"actionInfo[VLAN_VID]": actionInfo[VlanVid].(uint32)}) |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 3090 | } else { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 3091 | logger.Error(ctx, "no-invalid-vlan-id-in-set-vlan-vid-action") |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 3092 | } |
Gamze Abaka | c43a66e | 2020-05-11 11:00:42 +0000 | [diff] [blame] | 3093 | } else if fieldtype == ofp.OxmOfbFieldTypes_OFPXMT_OFB_VLAN_PCP { |
| 3094 | pcp := ofbField.GetVlanPcp() |
| 3095 | actionInfo[VlanPcp] = pcp |
Girish Kumar | a1ea2aa | 2020-08-19 18:14:22 +0000 | [diff] [blame] | 3096 | logger.Debugw(ctx, "action-set-vlan-pcp", log.Fields{"actionInfo[VLAN_PCP]": actionInfo[VlanPcp].(uint32)}) |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 3097 | } else { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 3098 | logger.Errorw(ctx, "unsupported-action-set-field-type", log.Fields{"type": fieldtype}) |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 3099 | } |
| 3100 | } |
| 3101 | } |
| 3102 | |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 3103 | func formulateGroupActionInfoFromFlow(ctx context.Context, action *ofp.OfpAction, actionInfo map[string]interface{}) { |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 3104 | if action.GetGroup() == nil { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 3105 | logger.Warn(ctx, "no-group-entry-found-in-the-group-action") |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 3106 | } else { |
| 3107 | actionInfo[GroupID] = action.GetGroup().GroupId |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 3108 | logger.Debugw(ctx, "action-group-id", log.Fields{"actionInfo[GroupID]": actionInfo[GroupID].(uint32)}) |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 3109 | } |
| 3110 | } |
| 3111 | |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 3112 | func formulateControllerBoundTrapFlowInfo(ctx context.Context, actionInfo, classifierInfo map[string]interface{}, flow *ofp.OfpFlowStats) error { |
Mahir Gunyel | 85f61c1 | 2021-10-06 11:53:45 -0700 | [diff] [blame] | 3113 | if isControllerFlow := plt.IsControllerBoundFlow(actionInfo[Output].(uint32)); isControllerFlow { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 3114 | logger.Debug(ctx, "controller-bound-trap-flows--getting-inport-from-tunnelid") |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 3115 | /* Get UNI port/ IN Port from tunnel ID field for upstream controller bound flows */ |
Mahir Gunyel | 85f61c1 | 2021-10-06 11:53:45 -0700 | [diff] [blame] | 3116 | if portType := plt.IntfIDToPortTypeName(classifierInfo[InPort].(uint32)); portType == voltha.Port_PON_OLT { |
Scott Baker | 355d174 | 2019-10-24 10:57:52 -0700 | [diff] [blame] | 3117 | if uniPort := flows.GetChildPortFromTunnelId(flow); uniPort != 0 { |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 3118 | classifierInfo[InPort] = uniPort |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 3119 | logger.Debugw(ctx, "upstream-pon-to-controller-flow--inport-in-tunnelid", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 3120 | log.Fields{ |
| 3121 | "newinport": classifierInfo[InPort].(uint32), |
| 3122 | "outport": actionInfo[Output].(uint32)}) |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 3123 | } else { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 3124 | return olterrors.NewErrNotFound("child-in-port", |
| 3125 | log.Fields{ |
| 3126 | "reason": "upstream-pon-to-controller-flow--no-inport-in-tunnelid", |
| 3127 | "flow": flow}, nil) |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 3128 | } |
| 3129 | } |
| 3130 | } else { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 3131 | logger.Debug(ctx, "non-controller-flows--getting-uniport-from-tunnelid") |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 3132 | // Downstream flow from NNI to PON port , Use tunnel ID as new OUT port / UNI port |
Mahir Gunyel | 85f61c1 | 2021-10-06 11:53:45 -0700 | [diff] [blame] | 3133 | if portType := plt.IntfIDToPortTypeName(actionInfo[Output].(uint32)); portType == voltha.Port_PON_OLT { |
Scott Baker | 355d174 | 2019-10-24 10:57:52 -0700 | [diff] [blame] | 3134 | if uniPort := flows.GetChildPortFromTunnelId(flow); uniPort != 0 { |
David K. Bainbridge | 82efc49 | 2019-09-04 09:57:11 -0700 | [diff] [blame] | 3135 | actionInfo[Output] = uniPort |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 3136 | logger.Debugw(ctx, "downstream-nni-to-pon-port-flow, outport-in-tunnelid", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 3137 | log.Fields{ |
| 3138 | "newoutport": actionInfo[Output].(uint32), |
| 3139 | "outport": actionInfo[Output].(uint32)}) |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 3140 | } else { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 3141 | return olterrors.NewErrNotFound("out-port", |
| 3142 | log.Fields{ |
| 3143 | "reason": "downstream-nni-to-pon-port-flow--no-outport-in-tunnelid", |
| 3144 | "flow": flow}, nil) |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 3145 | } |
| 3146 | // Upstream flow from PON to NNI port , Use tunnel ID as new IN port / UNI port |
Mahir Gunyel | 85f61c1 | 2021-10-06 11:53:45 -0700 | [diff] [blame] | 3147 | } else if portType := plt.IntfIDToPortTypeName(classifierInfo[InPort].(uint32)); portType == voltha.Port_PON_OLT { |
Scott Baker | 355d174 | 2019-10-24 10:57:52 -0700 | [diff] [blame] | 3148 | if uniPort := flows.GetChildPortFromTunnelId(flow); uniPort != 0 { |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 3149 | classifierInfo[InPort] = uniPort |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 3150 | logger.Debugw(ctx, "upstream-pon-to-nni-port-flow, inport-in-tunnelid", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 3151 | log.Fields{ |
| 3152 | "newinport": actionInfo[Output].(uint32), |
| 3153 | "outport": actionInfo[Output].(uint32)}) |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 3154 | } else { |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 3155 | return olterrors.NewErrNotFound("nni-port", |
| 3156 | log.Fields{ |
| 3157 | "reason": "upstream-pon-to-nni-port-flow--no-inport-in-tunnelid", |
| 3158 | "in-port": classifierInfo[InPort].(uint32), |
| 3159 | "out-port": actionInfo[Output].(uint32), |
| 3160 | "flow": flow}, nil) |
salmansiddiqui | 7ac6213 | 2019-08-22 03:58:50 +0000 | [diff] [blame] | 3161 | } |
| 3162 | } |
| 3163 | } |
| 3164 | return nil |
| 3165 | } |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 3166 | |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 3167 | func getTpIDFromFlow(ctx context.Context, flow *ofp.OfpFlowStats) (uint32, error) { |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 3168 | /* Metadata 8 bytes: |
| 3169 | Most Significant 2 Bytes = Inner VLAN |
| 3170 | Next 2 Bytes = Tech Profile ID(TPID) |
| 3171 | Least Significant 4 Bytes = Port ID |
| 3172 | Flow Metadata carries Tech-Profile (TP) ID and is mandatory in all |
| 3173 | subscriber related flows. |
| 3174 | */ |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 3175 | metadata := flows.GetMetadataFromWriteMetadataAction(ctx, flow) |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 3176 | if metadata == 0 { |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 3177 | return 0, olterrors.NewErrNotFound("metadata", log.Fields{"flow": flow}, nil) |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 3178 | } |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 3179 | TpID := flows.GetTechProfileIDFromWriteMetaData(ctx, metadata) |
Chaitrashree G S | 90a1795 | 2019-11-14 21:51:21 -0500 | [diff] [blame] | 3180 | return uint32(TpID), nil |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 3181 | } |
| 3182 | |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 3183 | func appendUnique32bit(slice []uint32, item uint32) []uint32 { |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 3184 | for _, sliceElement := range slice { |
| 3185 | if sliceElement == item { |
| 3186 | return slice |
| 3187 | } |
| 3188 | } |
| 3189 | return append(slice, item) |
| 3190 | } |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 3191 | |
| 3192 | // getNniIntfID gets nni intf id from the flow classifier/action |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 3193 | func getNniIntfID(ctx context.Context, classifier map[string]interface{}, action map[string]interface{}) (uint32, error) { |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 3194 | |
Mahir Gunyel | 85f61c1 | 2021-10-06 11:53:45 -0700 | [diff] [blame] | 3195 | portType := plt.IntfIDToPortTypeName(classifier[InPort].(uint32)) |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 3196 | if portType == voltha.Port_PON_OLT { |
Mahir Gunyel | 85f61c1 | 2021-10-06 11:53:45 -0700 | [diff] [blame] | 3197 | intfID, err := plt.IntfIDFromNniPortNum(ctx, action[Output].(uint32)) |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 3198 | if err != nil { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 3199 | logger.Debugw(ctx, "invalid-action-port-number", |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 3200 | log.Fields{ |
| 3201 | "port-number": action[Output].(uint32), |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 3202 | "err": err}) |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 3203 | return uint32(0), err |
| 3204 | } |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 3205 | logger.Infow(ctx, "output-nni-intfId-is", log.Fields{"intf-id": intfID}) |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 3206 | return intfID, nil |
| 3207 | } else if portType == voltha.Port_ETHERNET_NNI { |
Mahir Gunyel | 85f61c1 | 2021-10-06 11:53:45 -0700 | [diff] [blame] | 3208 | intfID, err := plt.IntfIDFromNniPortNum(ctx, classifier[InPort].(uint32)) |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 3209 | if err != nil { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 3210 | logger.Debugw(ctx, "invalid-classifier-port-number", |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 3211 | log.Fields{ |
| 3212 | "port-number": action[Output].(uint32), |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 3213 | "err": err}) |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 3214 | return uint32(0), err |
| 3215 | } |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 3216 | logger.Infow(ctx, "input-nni-intfId-is", log.Fields{"intf-id": intfID}) |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 3217 | return intfID, nil |
| 3218 | } |
| 3219 | return uint32(0), nil |
| 3220 | } |
| 3221 | |
| 3222 | // UpdateGemPortForPktIn updates gemport for packet-in in to the cache and to the kv store as well. |
Esin Karaman | 7fb80c2 | 2020-07-16 14:23:33 +0000 | [diff] [blame] | 3223 | func (f *OpenOltFlowMgr) UpdateGemPortForPktIn(ctx context.Context, intfID uint32, onuID uint32, logicalPort uint32, gemPort uint32, pkt []byte) { |
| 3224 | cTag, priority, err := getCTagFromPacket(ctx, pkt) |
| 3225 | if err != nil { |
| 3226 | logger.Errorw(ctx, "unable-to-update-gem-port-for-packet-in", |
| 3227 | log.Fields{"intfID": intfID, "onuID": onuID, "logicalPort": logicalPort, "gemPort": gemPort, "err": err}) |
| 3228 | return |
| 3229 | } |
| 3230 | pktInkey := rsrcMgr.PacketInInfoKey{IntfID: intfID, OnuID: onuID, LogicalPort: logicalPort, VlanID: cTag, Priority: priority} |
Matteo Scandolo | abf9c51 | 2020-06-23 19:31:14 -0700 | [diff] [blame] | 3231 | |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 3232 | f.packetInGemPortLock.RLock() |
Matt Jeanneret | 1719a07 | 2019-12-20 14:50:14 -0500 | [diff] [blame] | 3233 | lookupGemPort, ok := f.packetInGemPort[pktInkey] |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 3234 | f.packetInGemPortLock.RUnlock() |
| 3235 | |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 3236 | if ok { |
Matt Jeanneret | 1719a07 | 2019-12-20 14:50:14 -0500 | [diff] [blame] | 3237 | if lookupGemPort == gemPort { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 3238 | logger.Infow(ctx, "pktin-key/value-found-in-cache--no-need-to-update-kv--assume-both-in-sync", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 3239 | log.Fields{ |
| 3240 | "pktinkey": pktInkey, |
| 3241 | "gem": gemPort}) |
Matt Jeanneret | 1719a07 | 2019-12-20 14:50:14 -0500 | [diff] [blame] | 3242 | return |
| 3243 | } |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 3244 | } |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 3245 | f.packetInGemPortLock.Lock() |
Matt Jeanneret | 1719a07 | 2019-12-20 14:50:14 -0500 | [diff] [blame] | 3246 | f.packetInGemPort[pktInkey] = gemPort |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 3247 | f.packetInGemPortLock.Unlock() |
Matt Jeanneret | 1719a07 | 2019-12-20 14:50:14 -0500 | [diff] [blame] | 3248 | |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 3249 | f.resourceMgr.UpdateGemPortForPktIn(ctx, pktInkey, gemPort) |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 3250 | logger.Infow(ctx, "pktin-key-not-found-in-local-cache-value-is-different--updating-cache-and-kv-store", |
Shrey Baid | 2691297 | 2020-04-16 21:02:31 +0530 | [diff] [blame] | 3251 | log.Fields{ |
| 3252 | "pktinkey": pktInkey, |
| 3253 | "gem": gemPort}) |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 3254 | } |
| 3255 | |
Esin Karaman | 7fb80c2 | 2020-07-16 14:23:33 +0000 | [diff] [blame] | 3256 | //getCTagFromPacket retrieves and returns c-tag and priority value from a packet. |
| 3257 | func getCTagFromPacket(ctx context.Context, packet []byte) (uint16, uint8, error) { |
| 3258 | if packet == nil || len(packet) < 18 { |
Girish Kumar | a1ea2aa | 2020-08-19 18:14:22 +0000 | [diff] [blame] | 3259 | logger.Error(ctx, "unable-get-c-tag-from-the-packet--invalid-packet-length ") |
Esin Karaman | 7fb80c2 | 2020-07-16 14:23:33 +0000 | [diff] [blame] | 3260 | return 0, 0, errors.New("invalid packet length") |
| 3261 | } |
| 3262 | outerEthType := (uint16(packet[12]) << 8) | uint16(packet[13]) |
| 3263 | innerEthType := (uint16(packet[16]) << 8) | uint16(packet[17]) |
| 3264 | |
| 3265 | var index int8 |
| 3266 | if outerEthType == 0x8100 { |
| 3267 | if innerEthType == 0x8100 { |
| 3268 | // q-in-q 802.1ad or 802.1q double tagged packet. |
| 3269 | // get the inner vlanId |
| 3270 | index = 18 |
| 3271 | } else { |
| 3272 | index = 14 |
| 3273 | } |
| 3274 | priority := (packet[index] >> 5) & 0x7 |
| 3275 | //13 bits composes vlanId value |
| 3276 | vlan := ((uint16(packet[index]) << 8) & 0x0fff) | uint16(packet[index+1]) |
| 3277 | return vlan, priority, nil |
| 3278 | } |
| 3279 | logger.Debugf(ctx, "No vlanId found in the packet. Returning zero as c-tag") |
| 3280 | return 0, 0, nil |
| 3281 | } |
| 3282 | |
Girish Gowdra | 9602eb4 | 2020-09-09 15:50:39 -0700 | [diff] [blame] | 3283 | //clearMulticastFlowFromResourceManager removes a multicast flow from the KV store and |
| 3284 | // clears resources reserved for this multicast flow |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 3285 | func (f *OpenOltFlowMgr) clearMulticastFlowFromResourceManager(ctx context.Context, flow *ofp.OfpFlowStats) error { |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 3286 | removeFlowMessage := openoltpb2.Flow{FlowId: flow.Id, FlowType: Multicast} |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 3287 | logger.Debugw(ctx, "multicast-flow-to-be-deleted", |
| 3288 | log.Fields{ |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 3289 | "flow": flow, |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 3290 | "flow-id": flow.Id, |
| 3291 | "device-id": f.deviceHandler.device.Id}) |
| 3292 | // Remove from device |
| 3293 | if err := f.removeFlowFromDevice(ctx, &removeFlowMessage, flow.Id); err != nil { |
| 3294 | // DKB |
| 3295 | logger.Errorw(ctx, "failed-to-remove-multicast-flow", |
| 3296 | log.Fields{ |
| 3297 | "flow-id": flow.Id, |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 3298 | "err": err}) |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 3299 | return err |
| 3300 | } |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 3301 | |
| 3302 | return nil |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 3303 | } |
| 3304 | |
khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 3305 | func (f *OpenOltFlowMgr) getTechProfileDownloadMessage(ctx context.Context, tpPath string, uniID uint32, onuDeviceID string) (*ia.TechProfileDownloadMessage, error) { |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 3306 | tpInst, err := f.techprofile.GetTPInstance(ctx, tpPath) |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 3307 | if err != nil { |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 3308 | logger.Errorw(ctx, "error-fetching-tp-instance", log.Fields{"tpPath": tpPath}) |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 3309 | return nil, err |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 3310 | } |
| 3311 | |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 3312 | switch tpInst := tpInst.(type) { |
| 3313 | case *tp_pb.TechProfileInstance: |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 3314 | logger.Debugw(ctx, "fetched-tp-instance-successfully-formulating-tp-download-msg", log.Fields{"tpPath": tpPath}) |
khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 3315 | return &ia.TechProfileDownloadMessage{ |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 3316 | DeviceId: onuDeviceID, |
| 3317 | UniId: uniID, |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 3318 | TpInstancePath: tpPath, |
khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 3319 | TechTpInstance: &ia.TechProfileDownloadMessage_TpInstance{TpInstance: tpInst}, |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 3320 | }, nil |
khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 3321 | case *tp_pb.EponTechProfileInstance: |
| 3322 | return &ia.TechProfileDownloadMessage{ |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 3323 | DeviceId: onuDeviceID, |
| 3324 | UniId: uniID, |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 3325 | TpInstancePath: tpPath, |
khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 3326 | TechTpInstance: &ia.TechProfileDownloadMessage_EponTpInstance{EponTpInstance: tpInst}, |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 3327 | }, nil |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 3328 | default: |
| 3329 | logger.Errorw(ctx, "unknown-tech", log.Fields{"tpPath": tpPath}) |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 3330 | } |
khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 3331 | return &ia.TechProfileDownloadMessage{ |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 3332 | DeviceId: onuDeviceID, |
| 3333 | UniId: uniID, |
| 3334 | TpInstancePath: tpPath, |
| 3335 | TechTpInstance: nil, |
| 3336 | }, nil |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 3337 | } |
| 3338 | |
Gamze Abaka | 411ef2f | 2021-11-22 08:38:08 +0000 | [diff] [blame] | 3339 | // revertTechProfileInstance is called when CreateScheduler or CreateQueues request fails |
| 3340 | func (f *OpenOltFlowMgr) revertTechProfileInstance(ctx context.Context, sq schedQueue) { |
| 3341 | |
| 3342 | intfID := sq.intfID |
| 3343 | onuID := sq.onuID |
| 3344 | uniID := sq.uniID |
| 3345 | tpID := sq.tpID |
| 3346 | |
| 3347 | var reverseDirection string |
| 3348 | if sq.direction == tp_pb.Direction_UPSTREAM { |
| 3349 | reverseDirection = "downstream" |
| 3350 | } else { |
| 3351 | reverseDirection = "upstream" |
| 3352 | } |
| 3353 | |
| 3354 | // check reverse direction - if reverse meter exists, tech profile instance is in use - do not delete |
yasin sapli | bddc2d7 | 2022-02-08 13:10:17 +0000 | [diff] [blame] | 3355 | if KvStoreMeter, _ := f.resourceMgr.GetMeterInfoForOnu(ctx, reverseDirection, onuID, uniID, tpID); KvStoreMeter != nil { |
Gamze Abaka | 411ef2f | 2021-11-22 08:38:08 +0000 | [diff] [blame] | 3356 | return |
| 3357 | } |
| 3358 | |
| 3359 | // revert-delete tech-profile instance and delete tech profile id for onu |
| 3360 | logger.Warnw(ctx, "reverting-tech-profile-instance-and-tech-profile-id-for-onu", log.Fields{"intf-id": intfID, "onu-id": onuID, "uni-id": uniID, "tp-id": tpID}) |
| 3361 | uniPortName := getUniPortPath(f.deviceHandler.device.Id, intfID, int32(onuID), int32(uniID)) |
| 3362 | _ = f.DeleteTechProfileInstance(ctx, intfID, onuID, uniID, uniPortName, tpID) |
yasin sapli | bddc2d7 | 2022-02-08 13:10:17 +0000 | [diff] [blame] | 3363 | _ = f.resourceMgr.RemoveTechProfileIDForOnu(ctx, onuID, uniID, tpID) |
Gamze Abaka | 411ef2f | 2021-11-22 08:38:08 +0000 | [diff] [blame] | 3364 | |
| 3365 | // free gem/alloc |
| 3366 | switch techprofileInst := sq.tpInst.(type) { |
| 3367 | case *tp_pb.TechProfileInstance: |
| 3368 | for _, gem := range techprofileInst.UpstreamGemPortAttributeList { |
yasin sapli | bddc2d7 | 2022-02-08 13:10:17 +0000 | [diff] [blame] | 3369 | f.resourceMgr.FreeGemPortID(ctx, onuID, uniID, gem.GemportId) |
Gamze Abaka | 411ef2f | 2021-11-22 08:38:08 +0000 | [diff] [blame] | 3370 | } |
yasin sapli | bddc2d7 | 2022-02-08 13:10:17 +0000 | [diff] [blame] | 3371 | f.resourceMgr.FreeAllocID(ctx, onuID, uniID, techprofileInst.UsScheduler.AllocId, true) |
Gamze Abaka | 411ef2f | 2021-11-22 08:38:08 +0000 | [diff] [blame] | 3372 | } |
| 3373 | } |
| 3374 | |
| 3375 | // revertSchduler is called when CreateQueues request fails |
| 3376 | func (f *OpenOltFlowMgr) revertScheduler(ctx context.Context, sq schedQueue, TrafficSched []*tp_pb.TrafficScheduler) { |
| 3377 | // revert scheduler |
| 3378 | logger.Warnw(ctx, "reverting-scheduler-for-onu", log.Fields{"intf-id": sq.intfID, "onu-id": sq.onuID, "uni-id": sq.uniID, "tp-id": sq.tpID}) |
| 3379 | _, _ = f.deviceHandler.Client.RemoveTrafficSchedulers(ctx, &tp_pb.TrafficSchedulers{ |
| 3380 | IntfId: sq.intfID, OnuId: sq.onuID, |
| 3381 | UniId: sq.uniID, PortNo: sq.uniPort, |
| 3382 | TrafficScheds: TrafficSched}) |
| 3383 | } |
Girish Gowdra | 6071f38 | 2021-12-14 12:52:04 +0530 | [diff] [blame] | 3384 | |
| 3385 | // validateMeter validates if there is a meter mismatch for the given direction. It also clears the stale meter if the reference count is zero |
| 3386 | func (f *OpenOltFlowMgr) validateMeter(ctx context.Context, direction string, meterID uint32, intfID uint32, onuID uint32, uniID uint32, tpID uint32) error { |
yasin sapli | bddc2d7 | 2022-02-08 13:10:17 +0000 | [diff] [blame] | 3387 | meterInfo, err := f.resourceMgr.GetMeterInfoForOnu(ctx, direction, onuID, uniID, tpID) |
Girish Gowdra | 6071f38 | 2021-12-14 12:52:04 +0530 | [diff] [blame] | 3388 | if err != nil { |
| 3389 | return olterrors.NewErrNotFound("meter", |
| 3390 | log.Fields{"intf-id": intfID, |
| 3391 | "onu-id": onuID, |
| 3392 | "uni-id": uniID, |
| 3393 | "device-id": f.deviceHandler.device.Id}, err) |
| 3394 | } |
| 3395 | |
| 3396 | if meterInfo != nil { |
| 3397 | // If RefCnt become 0 clear the meter information from the DB. |
| 3398 | if meterInfo.MeterID != meterID && meterInfo.RefCnt == 0 { |
yasin sapli | bddc2d7 | 2022-02-08 13:10:17 +0000 | [diff] [blame] | 3399 | if err := f.resourceMgr.RemoveMeterInfoForOnu(ctx, direction, onuID, uniID, tpID); err != nil { |
Girish Gowdra | 6071f38 | 2021-12-14 12:52:04 +0530 | [diff] [blame] | 3400 | return err |
| 3401 | } |
| 3402 | } else if meterInfo.MeterID != meterID { |
| 3403 | logger.Errorw(ctx, "meter-mismatch-for-direction", |
| 3404 | log.Fields{"direction": direction, |
| 3405 | "kv-store-meter-id": meterInfo.MeterID, |
| 3406 | "meter-id-in-flow": meterID, |
| 3407 | "device-id": f.deviceHandler.device.Id}) |
| 3408 | return olterrors.NewErrInvalidValue(log.Fields{ |
| 3409 | "unsupported": "meter-id", |
| 3410 | "kv-store-meter-id": meterInfo.MeterID, |
| 3411 | "meter-id-in-flow": meterID, |
| 3412 | "device-id": f.deviceHandler.device.Id}, nil) |
| 3413 | } |
| 3414 | } |
| 3415 | return nil |
| 3416 | } |
Girish Gowdra | f3728b1 | 2022-02-02 21:46:51 -0800 | [diff] [blame] | 3417 | |
| 3418 | func (f *OpenOltFlowMgr) removeMeterReference(ctx context.Context, direction string, sq schedQueue) error { |
| 3419 | /* After we successfully remove the scheduler configuration on the OLT device, |
| 3420 | * delete the meter id on the KV store. |
| 3421 | */ |
yasin sapli | bddc2d7 | 2022-02-08 13:10:17 +0000 | [diff] [blame] | 3422 | err := f.resourceMgr.RemoveMeterInfoForOnu(ctx, direction, sq.onuID, sq.uniID, sq.tpID) |
Girish Gowdra | f3728b1 | 2022-02-02 21:46:51 -0800 | [diff] [blame] | 3423 | if err != nil { |
| 3424 | return olterrors.NewErrAdapter("unable-to-remove-meter", |
| 3425 | log.Fields{ |
| 3426 | "onu": sq.onuID, |
| 3427 | "device-id": f.deviceHandler.device.Id, |
| 3428 | "intf-id": sq.intfID, |
| 3429 | "onu-id": sq.onuID, |
| 3430 | "uni-id": sq.uniID, |
| 3431 | "uni-port": sq.uniPort}, err) |
| 3432 | } |
| 3433 | logger.Debugw(ctx, "removed-meter-from-KV-store-successfully", |
| 3434 | log.Fields{ |
| 3435 | "dir": direction, |
| 3436 | "device-id": f.deviceHandler.device.Id, |
| 3437 | "intf-id": sq.intfID, |
| 3438 | "onu-id": sq.onuID, |
| 3439 | "uni-id": sq.uniID, |
| 3440 | "uni-port": sq.uniPort}) |
| 3441 | return err |
| 3442 | } |