blob: d68b8f8e2b8ce09ca10316c9c65d4e83ffbbce96 [file] [log] [blame]
manikkaraj kbf256be2019-03-25 00:13:48 +05301/*
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 Bakerdbd960e2020-02-28 08:57:51 -080017//Package core provides the utility for olt devices, flows and statistics
18package core
manikkaraj kbf256be2019-03-25 00:13:48 +053019
20import (
21 "context"
22 "crypto/md5"
Matteo Scandolo6056e822019-11-13 14:05:29 -080023 "encoding/hex"
manikkaraj kbf256be2019-03-25 00:13:48 +053024 "encoding/json"
Girish Gowdracefae192020-03-19 18:14:10 -070025 "errors"
manikkaraj kbf256be2019-03-25 00:13:48 +053026 "fmt"
Manikkaraj kb1d51442019-07-23 10:41:02 -040027 "math/big"
Girish Gowdrafae935c2020-02-17 19:21:44 +053028 "strings"
William Kurkian740a09c2019-10-23 17:07:38 -040029 "sync"
Girish Gowdra3d633032019-12-10 16:37:05 +053030 "time"
Manikkaraj kb1d51442019-07-23 10:41:02 -040031
Esin Karamanccb714b2019-11-29 15:02:06 +000032 "github.com/opencord/voltha-lib-go/v3/pkg/flows"
33 "github.com/opencord/voltha-lib-go/v3/pkg/log"
34 tp "github.com/opencord/voltha-lib-go/v3/pkg/techprofile"
Scott Bakerdbd960e2020-02-28 08:57:51 -080035 rsrcMgr "github.com/opencord/voltha-openolt-adapter/internal/pkg/resourcemanager"
Esin Karamanccb714b2019-11-29 15:02:06 +000036 "github.com/opencord/voltha-protos/v3/go/common"
37 ic "github.com/opencord/voltha-protos/v3/go/inter_container"
38 ofp "github.com/opencord/voltha-protos/v3/go/openflow_13"
39 openoltpb2 "github.com/opencord/voltha-protos/v3/go/openolt"
40 tp_pb "github.com/opencord/voltha-protos/v3/go/tech_profile"
41 "github.com/opencord/voltha-protos/v3/go/voltha"
Chaitrashree G S579fe732019-08-20 20:50:47 -040042
Manjunath Vanarajulu28c3e822019-05-16 11:14:28 -040043 //deepcopy "github.com/getlantern/deepcopy"
Girish Gowdra3d633032019-12-10 16:37:05 +053044 "github.com/EagleChen/mapmutex"
Thomas Lee S94109f12020-03-03 16:39:29 +053045 "github.com/opencord/voltha-openolt-adapter/internal/pkg/olterrors"
Daniele Rossi22db98e2019-07-11 11:50:00 +000046 "google.golang.org/grpc/codes"
47 "google.golang.org/grpc/status"
manikkaraj kbf256be2019-03-25 00:13:48 +053048)
49
50const (
51 // Flow categories
manikkaraj kbf256be2019-03-25 00:13:48 +053052
Girish Gowdru6a80bbd2019-07-02 07:36:09 -070053 //HsiaFlow flow category
54 HsiaFlow = "HSIA_FLOW"
manikkaraj kbf256be2019-03-25 00:13:48 +053055
Girish Gowdru6a80bbd2019-07-02 07:36:09 -070056 //EapolFlow flow category
57 EapolFlow = "EAPOL_FLOW"
manikkaraj kbf256be2019-03-25 00:13:48 +053058
Manikkaraj kb1d51442019-07-23 10:41:02 -040059 //DhcpFlow flow category
60 DhcpFlow = "DHCP_FLOW"
61
Esin Karamanccb714b2019-11-29 15:02:06 +000062 //MulticastFlow flow category
63 MulticastFlow = "MULTICAST_FLOW"
64
Esin Karamanae41e2b2019-12-17 18:13:13 +000065 //IgmpFlow flow category
66 IgmpFlow = "IGMP_FLOW"
67
Girish Gowdru6a80bbd2019-07-02 07:36:09 -070068 //IPProtoDhcp flow category
69 IPProtoDhcp = 17
manikkaraj kbf256be2019-03-25 00:13:48 +053070
Girish Gowdru6a80bbd2019-07-02 07:36:09 -070071 //IPProtoIgmp flow category
72 IPProtoIgmp = 2
73
74 //EapEthType eapethtype value
75 EapEthType = 0x888e
76 //LldpEthType lldp ethtype value
77 LldpEthType = 0x88cc
Esin Karamanae41e2b2019-12-17 18:13:13 +000078 //IPv4EthType IPv4 ethernet type value
79 IPv4EthType = 0x800
Girish Gowdru6a80bbd2019-07-02 07:36:09 -070080
81 //IgmpProto proto value
82 IgmpProto = 2
manikkaraj kbf256be2019-03-25 00:13:48 +053083
Andrea Campanella7acc0b92020-02-14 09:20:49 +010084 //ReservedVlan Transparent Vlan (Masked Vlan, VLAN_ANY in ONOS Flows)
85 ReservedVlan = 4096
Harsh Awasthiea45af72019-08-26 02:39:00 -040086
Girish Gowdru6a80bbd2019-07-02 07:36:09 -070087 //DefaultMgmtVlan default vlan value
88 DefaultMgmtVlan = 4091
manikkaraj kbf256be2019-03-25 00:13:48 +053089
manikkaraj kbf256be2019-03-25 00:13:48 +053090 // Openolt Flow
Girish Gowdru6a80bbd2019-07-02 07:36:09 -070091
David K. Bainbridge82efc492019-09-04 09:57:11 -070092 //Upstream constant
93 Upstream = "upstream"
94 //Downstream constant
95 Downstream = "downstream"
Esin Karamanccb714b2019-11-29 15:02:06 +000096 //Multicast constant
97 Multicast = "multicast"
Girish Gowdru6a80bbd2019-07-02 07:36:09 -070098 //PacketTagType constant
99 PacketTagType = "pkt_tag_type"
David K. Bainbridge82efc492019-09-04 09:57:11 -0700100 //Untagged constant
101 Untagged = "untagged"
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700102 //SingleTag constant
103 SingleTag = "single_tag"
104 //DoubleTag constant
105 DoubleTag = "double_tag"
manikkaraj kbf256be2019-03-25 00:13:48 +0530106
107 // classifierInfo
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700108
109 //EthType constant
110 EthType = "eth_type"
Esin Karamanccb714b2019-11-29 15:02:06 +0000111 //EthDst constant
112 EthDst = "eth_dst"
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700113 //TPID constant
114 TPID = "tpid"
115 //IPProto constant
116 IPProto = "ip_proto"
117 //InPort constant
118 InPort = "in_port"
119 //VlanVid constant
120 VlanVid = "vlan_vid"
121 //VlanPcp constant
122 VlanPcp = "vlan_pcp"
123
124 //UDPDst constant
125 UDPDst = "udp_dst"
126 //UDPSrc constant
127 UDPSrc = "udp_src"
128 //Ipv4Dst constant
129 Ipv4Dst = "ipv4_dst"
130 //Ipv4Src constant
131 Ipv4Src = "ipv4_src"
David K. Bainbridge82efc492019-09-04 09:57:11 -0700132 //Metadata constant
133 Metadata = "metadata"
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700134 //TunnelID constant
135 TunnelID = "tunnel_id"
David K. Bainbridge82efc492019-09-04 09:57:11 -0700136 //Output constant
137 Output = "output"
Esin Karamanccb714b2019-11-29 15:02:06 +0000138 //GroupID constant
139 GroupID = "group_id"
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700140 // Actions
141
142 //PopVlan constant
143 PopVlan = "pop_vlan"
144 //PushVlan constant
145 PushVlan = "push_vlan"
146 //TrapToHost constant
147 TrapToHost = "trap_to_host"
Manikkaraj kb1d51442019-07-23 10:41:02 -0400148 //MaxMeterBand constant
149 MaxMeterBand = 2
150 //VlanPCPMask contant
151 VlanPCPMask = 0xFF
152 //VlanvIDMask constant
153 VlanvIDMask = 0xFFF
Gamze Abakafee36392019-10-03 11:17:24 +0000154 //IntfID constant
155 IntfID = "intfId"
156 //OnuID constant
157 OnuID = "onuId"
158 //UniID constant
159 UniID = "uniId"
160 //PortNo constant
161 PortNo = "portNo"
162 //AllocID constant
163 AllocID = "allocId"
Esin Karamanccb714b2019-11-29 15:02:06 +0000164
165 //NoneOnuID constant
166 NoneOnuID = -1
167 //NoneUniID constant
168 NoneUniID = -1
169 //NoneGemPortID constant
170 NoneGemPortID = -1
Girish Gowdrafae935c2020-02-17 19:21:44 +0530171
172 // BinaryStringPrefix is binary string prefix
173 BinaryStringPrefix = "0b"
174 // BinaryBit1 is binary bit 1 expressed as a character
175 BinaryBit1 = '1'
Matteo Scandolo738c52a2020-08-03 11:14:22 -0700176
177 // MapMutex
178 maxRetry = 300
179 maxDelay = 100000000
180 baseDelay = 10000000
181 factor = 1.1
182 jitter = 0.2
manikkaraj kbf256be2019-03-25 00:13:48 +0530183)
184
manikkaraj k9eb6cac2019-05-09 12:32:03 -0400185type gemPortKey struct {
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700186 intfID uint32
manikkaraj k9eb6cac2019-05-09 12:32:03 -0400187 gemPort uint32
188}
189
Girish Gowdra3d633032019-12-10 16:37:05 +0530190type pendingFlowDeleteKey struct {
191 intfID uint32
192 onuID uint32
193 uniID uint32
194}
195
196type tpLockKey struct {
197 intfID uint32
198 onuID uint32
199 uniID uint32
200}
201
Gamze Abakafee36392019-10-03 11:17:24 +0000202type schedQueue struct {
203 direction tp_pb.Direction
204 intfID uint32
205 onuID uint32
206 uniID uint32
207 tpID uint32
208 uniPort uint32
Takahiro Suzuki2ba0e0b2020-06-05 14:23:03 -0700209 tpInst interface{}
Gamze Abakafee36392019-10-03 11:17:24 +0000210 meterID uint32
211 flowMetadata *voltha.FlowMetadata
212}
213
Esin Karamanccb714b2019-11-29 15:02:06 +0000214type queueInfoBrief struct {
215 gemPortID uint32
216 servicePriority uint32
217}
218
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700219//OpenOltFlowMgr creates the Structure of OpenOltFlowMgr obj
manikkaraj kbf256be2019-03-25 00:13:48 +0530220type OpenOltFlowMgr struct {
Amit Ghoshd4cbe482019-11-21 12:07:14 +0000221 techprofile map[uint32]tp.TechProfileIf
Gamze Abakafee36392019-10-03 11:17:24 +0000222 deviceHandler *DeviceHandler
223 resourceMgr *rsrcMgr.OpenOltResourceMgr
Gamze Abakafee36392019-10-03 11:17:24 +0000224 onuIdsLock sync.RWMutex
Matteo Scandolo738c52a2020-08-03 11:14:22 -0700225 perGemPortLock *mapmutex.Mutex // lock to be used to access the flowsUsedByGemPort map
Abhilash Laxmeshwarab0bd522019-10-21 15:05:15 +0530226 flowsUsedByGemPort map[gemPortKey][]uint32 //gem port id to flow ids
227 packetInGemPort map[rsrcMgr.PacketInInfoKey]uint32 //packet in gem port local cache
Matteo Scandolo2c0d2742020-06-10 11:28:42 -0700228 // TODO create a type rsrcMgr.OnuGemInfos to be used instead of []rsrcMgr.OnuGemInfo
Matteo Scandoloabf9c512020-06-23 19:31:14 -0700229 onuGemInfo map[uint32][]rsrcMgr.OnuGemInfo //onu, gem and uni info local cache, indexed by IntfId
230 // We need to have a global lock on the onuGemInfo map
231 onuGemInfoLock sync.RWMutex
Matteo Scandolo2c0d2742020-06-10 11:28:42 -0700232 pendingFlowDelete sync.Map
Girish Gowdra3d633032019-12-10 16:37:05 +0530233 // The mapmutex.Mutex can be fine tuned to use mapmutex.NewCustomizedMapMutex
Esin Karamanccb714b2019-11-29 15:02:06 +0000234 perUserFlowHandleLock *mapmutex.Mutex
235 interfaceToMcastQueueMap map[uint32]*queueInfoBrief /*pon interface -> multicast queue map. Required to assign GEM to a bucket during group population*/
manikkaraj kbf256be2019-03-25 00:13:48 +0530236}
237
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700238//NewFlowManager creates OpenOltFlowMgr object and initializes the parameters
npujarec5762e2020-01-01 14:08:48 +0530239func NewFlowManager(ctx context.Context, dh *DeviceHandler, rMgr *rsrcMgr.OpenOltResourceMgr) *OpenOltFlowMgr {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000240 logger.Infow(ctx, "initializing-flow-manager", log.Fields{"device-id": dh.device.Id})
manikkaraj kbf256be2019-03-25 00:13:48 +0530241 var flowMgr OpenOltFlowMgr
Abhilash Laxmeshwarab0bd522019-10-21 15:05:15 +0530242 var err error
243 var idx uint32
244
manikkaraj kbf256be2019-03-25 00:13:48 +0530245 flowMgr.deviceHandler = dh
Abhilash Laxmeshwarab0bd522019-10-21 15:05:15 +0530246 flowMgr.resourceMgr = rMgr
Amit Ghoshd4cbe482019-11-21 12:07:14 +0000247 flowMgr.techprofile = make(map[uint32]tp.TechProfileIf)
Neha Sharma96b7bf22020-06-15 10:37:32 +0000248 if err = flowMgr.populateTechProfilePerPonPort(ctx); err != nil {
249 logger.Errorw(ctx, "error-while-populating-tech-profile-mgr", log.Fields{"error": err})
manikkaraj kbf256be2019-03-25 00:13:48 +0530250 return nil
251 }
William Kurkian740a09c2019-10-23 17:07:38 -0400252 flowMgr.onuIdsLock = sync.RWMutex{}
Abhilash Laxmeshwarab0bd522019-10-21 15:05:15 +0530253 flowMgr.flowsUsedByGemPort = make(map[gemPortKey][]uint32)
254 flowMgr.packetInGemPort = make(map[rsrcMgr.PacketInInfoKey]uint32)
Abhilash Laxmeshwarab0bd522019-10-21 15:05:15 +0530255 ponPorts := rMgr.DevInfo.GetPonPorts()
Matteo Scandoloabf9c512020-06-23 19:31:14 -0700256 flowMgr.onuGemInfo = make(map[uint32][]rsrcMgr.OnuGemInfo, ponPorts)
Girish Gowdra1183b4d2020-08-25 16:12:01 -0700257 flowMgr.onuGemInfoLock = sync.RWMutex{}
258 flowMgr.pendingFlowDelete = sync.Map{}
259 flowMgr.perUserFlowHandleLock = mapmutex.NewCustomizedMapMutex(maxRetry, maxDelay, baseDelay, factor, jitter)
260 flowMgr.perGemPortLock = mapmutex.NewCustomizedMapMutex(maxRetry, maxDelay, baseDelay, factor, jitter)
261 flowMgr.interfaceToMcastQueueMap = make(map[uint32]*queueInfoBrief)
Abhilash Laxmeshwarab0bd522019-10-21 15:05:15 +0530262 //Load the onugem info cache from kv store on flowmanager start
263 for idx = 0; idx < ponPorts; idx++ {
npujarec5762e2020-01-01 14:08:48 +0530264 if flowMgr.onuGemInfo[idx], err = rMgr.GetOnuGemInfo(ctx, idx); err != nil {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000265 logger.Error(ctx, "failed-to-load-onu-gem-info-cache")
Abhilash Laxmeshwarab0bd522019-10-21 15:05:15 +0530266 }
Abhilash Laxmeshwar275c0742019-11-25 16:47:02 +0530267 //Load flowID list per gem map per interface from the kvstore.
npujarec5762e2020-01-01 14:08:48 +0530268 flowMgr.loadFlowIDlistForGem(ctx, idx)
Abhilash Laxmeshwarab0bd522019-10-21 15:05:15 +0530269 }
Esin Karamanccb714b2019-11-29 15:02:06 +0000270 //load interface to multicast queue map from kv store
npujarec5762e2020-01-01 14:08:48 +0530271 flowMgr.loadInterfaceToMulticastQueueMap(ctx)
Neha Sharma96b7bf22020-06-15 10:37:32 +0000272 logger.Info(ctx, "initialization-of-flow-manager-success")
manikkaraj kbf256be2019-03-25 00:13:48 +0530273 return &flowMgr
274}
275
Kent Hagermane6ff1012020-07-14 15:07:53 -0400276func (f *OpenOltFlowMgr) registerFlow(ctx context.Context, flowFromCore *ofp.OfpFlowStats, deviceFlow *openoltpb2.Flow) error {
Gamze Abakafee36392019-10-03 11:17:24 +0000277 gemPK := gemPortKey{uint32(deviceFlow.AccessIntfId), uint32(deviceFlow.GemportId)}
Matteo Scandolo738c52a2020-08-03 11:14:22 -0700278 if f.perGemPortLock.TryLock(gemPK) {
279 logger.Debugw(ctx, "registering-flow-for-device ",
280 log.Fields{
281 "flow": flowFromCore,
282 "device-id": f.deviceHandler.device.Id})
283 flowIDList, ok := f.flowsUsedByGemPort[gemPK]
284 if !ok {
285 flowIDList = []uint32{deviceFlow.FlowId}
286 }
287 flowIDList = appendUnique(flowIDList, deviceFlow.FlowId)
288 f.flowsUsedByGemPort[gemPK] = flowIDList
289
290 f.perGemPortLock.Unlock(gemPK)
291
292 // update the flowids for a gem to the KVstore
293 return f.resourceMgr.UpdateFlowIDsForGem(ctx, uint32(deviceFlow.AccessIntfId), uint32(deviceFlow.GemportId), flowIDList)
Gamze Abakafee36392019-10-03 11:17:24 +0000294 }
Matteo Scandolo738c52a2020-08-03 11:14:22 -0700295 logger.Error(ctx, "failed-to-acquire-per-gem-port-lock",
296 log.Fields{
297 "flow-from-core": flowFromCore,
298 "device-id": f.deviceHandler.device.Id,
299 "key": gemPK,
300 })
301 return olterrors.NewErrAdapter("failed-to-acquire-per-gem-port-lock", log.Fields{
302 "flow-from-core": flowFromCore,
303 "device-id": f.deviceHandler.device.Id,
304 "key": gemPK,
305 }, nil)
Manjunath Vanarajulu28c3e822019-05-16 11:14:28 -0400306}
307
npujarec5762e2020-01-01 14:08:48 +0530308func (f *OpenOltFlowMgr) divideAndAddFlow(ctx context.Context, intfID uint32, onuID uint32, uniID uint32, portNo uint32,
salmansiddiqui7ac62132019-08-22 03:58:50 +0000309 classifierInfo map[string]interface{}, actionInfo map[string]interface{}, flow *ofp.OfpFlowStats, TpID uint32,
Andrea Campanellabfe08432020-09-11 17:07:03 +0200310 UsMeterID uint32, DsMeterID uint32, flowMetadata *voltha.FlowMetadata) error {
Gamze Abakafee36392019-10-03 11:17:24 +0000311 var allocID uint32
manikkaraj kbf256be2019-03-25 00:13:48 +0530312 var gemPorts []uint32
Takahiro Suzuki2ba0e0b2020-06-05 14:23:03 -0700313 var TpInst interface{}
manikkaraj kbf256be2019-03-25 00:13:48 +0530314
Neha Sharma96b7bf22020-06-15 10:37:32 +0000315 logger.Infow(ctx, "dividing-flow", log.Fields{
Shrey Baid26912972020-04-16 21:02:31 +0530316 "device-id": f.deviceHandler.device.Id,
317 "intf-id": intfID,
318 "onu-id": onuID,
319 "uni-id": uniID,
320 "port-no": portNo,
Matteo Scandolod625b4c2020-04-02 16:16:01 -0700321 "classifier": classifierInfo,
Shrey Baid26912972020-04-16 21:02:31 +0530322 "action": actionInfo,
323 "usmeter-iD": UsMeterID,
324 "dsmeter-iD": DsMeterID,
325 "tp-id": TpID})
Matt Jeanneret77199612019-07-26 18:08:35 -0400326 // only create tcont/gemports if there is actually an onu id. otherwise BAL throws an error. Usually this
327 // is because the flow is an NNI flow and there would be no onu resources associated with it
328 // TODO: properly deal with NNI flows
Kent Hagermane6ff1012020-07-14 15:07:53 -0400329 if onuID == 0 {
Andrea Campanellabfe08432020-09-11 17:07:03 +0200330 cause := "no-onu-id-for-flow"
331 fields := log.Fields{
332 "onu": onuID,
333 "port-no": portNo,
334 "classifer": classifierInfo,
335 "action": actionInfo,
336 "device-id": f.deviceHandler.device.Id}
337 logger.Errorw(ctx, cause, fields)
338 return olterrors.NewErrNotFound(cause, fields, nil)
manikkaraj kbf256be2019-03-25 00:13:48 +0530339 }
340
Matteo Scandolod625b4c2020-04-02 16:16:01 -0700341 uni := getUniPortPath(f.deviceHandler.device.Id, intfID, int32(onuID), int32(uniID))
Neha Sharma96b7bf22020-06-15 10:37:32 +0000342 logger.Debugw(ctx, "uni-port-path", log.Fields{
Shrey Baid26912972020-04-16 21:02:31 +0530343 "uni": uni,
344 "device-id": f.deviceHandler.device.Id})
Girish Gowdra3d633032019-12-10 16:37:05 +0530345
346 tpLockMapKey := tpLockKey{intfID, onuID, uniID}
347 if f.perUserFlowHandleLock.TryLock(tpLockMapKey) {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000348 logger.Debugw(ctx, "dividing-flow-create-tcont-gem-ports", log.Fields{
Shrey Baid26912972020-04-16 21:02:31 +0530349 "device-id": f.deviceHandler.device.Id,
350 "intf-id": intfID,
351 "onu-id": onuID,
352 "uni-id": uniID,
353 "port-no": portNo,
Matteo Scandolod625b4c2020-04-02 16:16:01 -0700354 "classifier": classifierInfo,
Shrey Baid26912972020-04-16 21:02:31 +0530355 "action": actionInfo,
356 "usmeter-id": UsMeterID,
357 "dsmeter-id": DsMeterID,
358 "tp-id": TpID})
npujarec5762e2020-01-01 14:08:48 +0530359 allocID, gemPorts, TpInst = f.createTcontGemports(ctx, intfID, onuID, uniID, uni, portNo, TpID, UsMeterID, DsMeterID, flowMetadata)
Girish Gowdra3d633032019-12-10 16:37:05 +0530360 if allocID == 0 || gemPorts == nil || TpInst == nil {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000361 logger.Error(ctx, "alloc-id-gem-ports-tp-unavailable")
Girish Gowdra3d633032019-12-10 16:37:05 +0530362 f.perUserFlowHandleLock.Unlock(tpLockMapKey)
Andrea Campanellabfe08432020-09-11 17:07:03 +0200363 return olterrors.NewErrNotFound(
364 "alloc-id-gem-ports-tp-unavailable",
365 nil, nil)
Girish Gowdra3d633032019-12-10 16:37:05 +0530366 }
367 args := make(map[string]uint32)
368 args[IntfID] = intfID
369 args[OnuID] = onuID
370 args[UniID] = uniID
371 args[PortNo] = portNo
372 args[AllocID] = allocID
373
374 /* Flows can be added specific to gemport if p-bits are received.
375 * If no pbit mentioned then adding flows for all gemports
376 */
npujarec5762e2020-01-01 14:08:48 +0530377 f.checkAndAddFlow(ctx, args, classifierInfo, actionInfo, flow, TpInst, gemPorts, TpID, uni)
Girish Gowdra3d633032019-12-10 16:37:05 +0530378 f.perUserFlowHandleLock.Unlock(tpLockMapKey)
379 } else {
Andrea Campanellabfe08432020-09-11 17:07:03 +0200380 cause := "failed-to-acquire-per-user-flow-handle-lock"
381 fields := log.Fields{
382 "intf-id": intfID,
383 "onu-id": onuID,
384 "uni-id": uniID,
385 "flow-id": flow.Id,
386 "flow-cookie": flow.Cookie,
387 "device-id": f.deviceHandler.device.Id}
388 logger.Errorw(ctx, cause, fields)
389 return olterrors.NewErrAdapter(cause, fields, nil)
Manikkaraj kb1d51442019-07-23 10:41:02 -0400390 }
Andrea Campanellabfe08432020-09-11 17:07:03 +0200391 return nil
manikkaraj kbf256be2019-03-25 00:13:48 +0530392}
393
salmansiddiqui7ac62132019-08-22 03:58:50 +0000394// CreateSchedulerQueues creates traffic schedulers on the device with the given scheduler configuration and traffic shaping info
npujarec5762e2020-01-01 14:08:48 +0530395func (f *OpenOltFlowMgr) CreateSchedulerQueues(ctx context.Context, sq schedQueue) error {
Manikkaraj kb1d51442019-07-23 10:41:02 -0400396
Neha Sharma96b7bf22020-06-15 10:37:32 +0000397 logger.Debugw(ctx, "CreateSchedulerQueues",
Shrey Baid26912972020-04-16 21:02:31 +0530398 log.Fields{"dir": sq.direction,
399 "intf-id": sq.intfID,
400 "onu-id": sq.onuID,
401 "uni-id": sq.uniID,
402 "tp-id": sq.tpID,
403 "meter-id": sq.meterID,
404 "tp-inst": sq.tpInst,
405 "flowmetadata": sq.flowMetadata,
406 "device-id": f.deviceHandler.device.Id})
Manikkaraj kb1d51442019-07-23 10:41:02 -0400407
Gamze Abakafee36392019-10-03 11:17:24 +0000408 Direction, err := verifyMeterIDAndGetDirection(sq.meterID, sq.direction)
salmansiddiqui7ac62132019-08-22 03:58:50 +0000409 if err != nil {
410 return err
Manikkaraj kb1d51442019-07-23 10:41:02 -0400411 }
412
413 /* Lets make a simple assumption that if the meter-id is present on the KV store,
414 * then the scheduler and queues configuration is applied on the OLT device
415 * in the given direction.
416 */
salmansiddiqui7ac62132019-08-22 03:58:50 +0000417
Manikkaraj kb1d51442019-07-23 10:41:02 -0400418 var SchedCfg *tp_pb.SchedulerConfig
npujarec5762e2020-01-01 14:08:48 +0530419 KvStoreMeter, err := f.resourceMgr.GetMeterIDForOnu(ctx, Direction, sq.intfID, sq.onuID, sq.uniID, sq.tpID)
Manikkaraj kb1d51442019-07-23 10:41:02 -0400420 if err != nil {
Shrey Baid26912972020-04-16 21:02:31 +0530421 return olterrors.NewErrNotFound("meter",
422 log.Fields{"intf-id": sq.intfID,
423 "onu-id": sq.onuID,
424 "uni-id": sq.uniID,
425 "device-id": f.deviceHandler.device.Id}, err)
Manikkaraj kb1d51442019-07-23 10:41:02 -0400426 }
Girish Kumarf26e4882020-03-05 06:49:10 +0000427
Manikkaraj kb1d51442019-07-23 10:41:02 -0400428 if KvStoreMeter != nil {
Gamze Abakafee36392019-10-03 11:17:24 +0000429 if KvStoreMeter.MeterId == sq.meterID {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000430 logger.Debugw(ctx, "scheduler-already-created-for-upstream", log.Fields{"device-id": f.deviceHandler.device.Id})
Manikkaraj kb1d51442019-07-23 10:41:02 -0400431 return nil
Manikkaraj kb1d51442019-07-23 10:41:02 -0400432 }
Thomas Lee S94109f12020-03-03 16:39:29 +0530433 return olterrors.NewErrInvalidValue(log.Fields{
David K. Bainbridge794735f2020-02-11 21:01:37 -0800434 "unsupported": "meter-id",
435 "kv-store-meter-id": KvStoreMeter.MeterId,
Shrey Baid26912972020-04-16 21:02:31 +0530436 "meter-id-in-flow": sq.meterID,
437 "device-id": f.deviceHandler.device.Id}, nil)
Manikkaraj kb1d51442019-07-23 10:41:02 -0400438 }
Girish Kumar8f73fe02019-12-09 13:19:37 +0000439
Neha Sharma96b7bf22020-06-15 10:37:32 +0000440 logger.Debugw(ctx, "meter-does-not-exist-creating-new",
Shrey Baid26912972020-04-16 21:02:31 +0530441 log.Fields{
442 "meter-id": sq.meterID,
443 "direction": Direction,
444 "device-id": f.deviceHandler.device.Id})
Girish Kumar8f73fe02019-12-09 13:19:37 +0000445
Gamze Abakafee36392019-10-03 11:17:24 +0000446 if sq.direction == tp_pb.Direction_UPSTREAM {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000447 SchedCfg, err = f.techprofile[sq.intfID].GetUsScheduler(ctx, sq.tpInst.(*tp.TechProfile))
Gamze Abakafee36392019-10-03 11:17:24 +0000448 } else if sq.direction == tp_pb.Direction_DOWNSTREAM {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000449 SchedCfg, err = f.techprofile[sq.intfID].GetDsScheduler(ctx, sq.tpInst.(*tp.TechProfile))
Manikkaraj kb1d51442019-07-23 10:41:02 -0400450 }
Girish Kumar8f73fe02019-12-09 13:19:37 +0000451
452 if err != nil {
Shrey Baid26912972020-04-16 21:02:31 +0530453 return olterrors.NewErrNotFound("scheduler-config",
454 log.Fields{
455 "intf-id": sq.intfID,
456 "direction": sq.direction,
457 "tp-inst": sq.tpInst,
458 "device-id": f.deviceHandler.device.Id}, err)
Girish Kumar8f73fe02019-12-09 13:19:37 +0000459 }
460
Manikkaraj kb1d51442019-07-23 10:41:02 -0400461 var meterConfig *ofp.OfpMeterConfig
Gamze Abakafee36392019-10-03 11:17:24 +0000462 if sq.flowMetadata != nil {
463 for _, meter := range sq.flowMetadata.Meters {
464 if sq.meterID == meter.MeterId {
Manikkaraj kb1d51442019-07-23 10:41:02 -0400465 meterConfig = meter
Neha Sharma96b7bf22020-06-15 10:37:32 +0000466 logger.Debugw(ctx, "found-meter-config-from-flowmetadata",
Shrey Baid26912972020-04-16 21:02:31 +0530467 log.Fields{"meterConfig": meterConfig,
468 "device-id": f.deviceHandler.device.Id})
Manikkaraj kb1d51442019-07-23 10:41:02 -0400469 break
470 }
471 }
472 } else {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000473 logger.Errorw(ctx, "flow-metadata-not-present-in-flow", log.Fields{"device-id": f.deviceHandler.device.Id})
Manikkaraj kb1d51442019-07-23 10:41:02 -0400474 }
475 if meterConfig == nil {
Thomas Lee S94109f12020-03-03 16:39:29 +0530476 return olterrors.NewErrNotFound("meterbands", log.Fields{
David K. Bainbridge794735f2020-02-11 21:01:37 -0800477 "reason": "Could-not-get-meterbands-from-flowMetadata",
478 "flow-metadata": sq.flowMetadata,
Shrey Baid26912972020-04-16 21:02:31 +0530479 "meter-id": sq.meterID,
480 "device-id": f.deviceHandler.device.Id}, nil)
Manikkaraj kb1d51442019-07-23 10:41:02 -0400481 } else if len(meterConfig.Bands) < MaxMeterBand {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000482 logger.Errorw(ctx, "invalid-number-of-bands-in-meter",
Shrey Baid26912972020-04-16 21:02:31 +0530483 log.Fields{"Bands": meterConfig.Bands,
484 "meter-id": sq.meterID,
485 "device-id": f.deviceHandler.device.Id})
Thomas Lee S94109f12020-03-03 16:39:29 +0530486 return olterrors.NewErrInvalidValue(log.Fields{
David K. Bainbridge794735f2020-02-11 21:01:37 -0800487 "reason": "Invalid-number-of-bands-in-meter",
488 "meterband-count": len(meterConfig.Bands),
489 "metabands": meterConfig.Bands,
Shrey Baid26912972020-04-16 21:02:31 +0530490 "meter-id": sq.meterID,
491 "device-id": f.deviceHandler.device.Id}, nil)
Manikkaraj kb1d51442019-07-23 10:41:02 -0400492 }
493 cir := meterConfig.Bands[0].Rate
494 cbs := meterConfig.Bands[0].BurstSize
495 eir := meterConfig.Bands[1].Rate
496 ebs := meterConfig.Bands[1].BurstSize
497 pir := cir + eir
498 pbs := cbs + ebs
499 TrafficShaping := &tp_pb.TrafficShapingInfo{Cir: cir, Cbs: cbs, Pir: pir, Pbs: pbs}
500
Takahiro Suzuki2ba0e0b2020-06-05 14:23:03 -0700501 TrafficSched := []*tp_pb.TrafficScheduler{f.techprofile[sq.intfID].GetTrafficScheduler(sq.tpInst.(*tp.TechProfile), SchedCfg, TrafficShaping)}
Gamze Abaka78a1d2a2020-04-27 10:17:27 +0000502 TrafficSched[0].TechProfileId = sq.tpID
Manikkaraj kb1d51442019-07-23 10:41:02 -0400503
npujarec5762e2020-01-01 14:08:48 +0530504 if err := f.pushSchedulerQueuesToDevice(ctx, sq, TrafficShaping, TrafficSched); err != nil {
Shrey Baid26912972020-04-16 21:02:31 +0530505 return olterrors.NewErrAdapter("failure-pushing-traffic-scheduler-and-queues-to-device",
506 log.Fields{"intf-id": sq.intfID,
507 "direction": sq.direction,
508 "device-id": f.deviceHandler.device.Id}, err)
Manikkaraj kb1d51442019-07-23 10:41:02 -0400509 }
510
salmansiddiqui7ac62132019-08-22 03:58:50 +0000511 /* After we successfully applied the scheduler configuration on the OLT device,
Manikkaraj kb1d51442019-07-23 10:41:02 -0400512 * store the meter id on the KV store, for further reference.
513 */
npujarec5762e2020-01-01 14:08:48 +0530514 if err := f.resourceMgr.UpdateMeterIDForOnu(ctx, Direction, sq.intfID, sq.onuID, sq.uniID, sq.tpID, meterConfig); err != nil {
Shrey Baid26912972020-04-16 21:02:31 +0530515 return olterrors.NewErrAdapter("failed-updating-meter-id",
516 log.Fields{"onu-id": sq.onuID,
517 "meter-id": sq.meterID,
518 "device-id": f.deviceHandler.device.Id}, err)
Manikkaraj kb1d51442019-07-23 10:41:02 -0400519 }
Neha Sharma96b7bf22020-06-15 10:37:32 +0000520 logger.Infow(ctx, "updated-meter-info-into-kv-store-successfully",
Shrey Baid26912972020-04-16 21:02:31 +0530521 log.Fields{"direction": Direction,
522 "Meter": meterConfig,
523 "device-id": f.deviceHandler.device.Id})
Manikkaraj kb1d51442019-07-23 10:41:02 -0400524 return nil
525}
526
npujarec5762e2020-01-01 14:08:48 +0530527func (f *OpenOltFlowMgr) pushSchedulerQueuesToDevice(ctx context.Context, sq schedQueue, TrafficShaping *tp_pb.TrafficShapingInfo, TrafficSched []*tp_pb.TrafficScheduler) error {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000528 trafficQueues, err := f.techprofile[sq.intfID].GetTrafficQueues(ctx, sq.tpInst.(*tp.TechProfile), sq.direction)
Girish Kumar8f73fe02019-12-09 13:19:37 +0000529
530 if err != nil {
Shrey Baid26912972020-04-16 21:02:31 +0530531 return olterrors.NewErrAdapter("unable-to-construct-traffic-queue-configuration",
532 log.Fields{"intf-id": sq.intfID,
533 "direction": sq.direction,
534 "device-id": f.deviceHandler.device.Id}, err)
Girish Kumar8f73fe02019-12-09 13:19:37 +0000535 }
536
Neha Sharma96b7bf22020-06-15 10:37:32 +0000537 logger.Debugw(ctx, "sending-traffic-scheduler-create-to-device",
Shrey Baid26912972020-04-16 21:02:31 +0530538 log.Fields{
539 "direction": sq.direction,
540 "TrafficScheds": TrafficSched,
541 "device-id": f.deviceHandler.device.Id})
npujarec5762e2020-01-01 14:08:48 +0530542 if _, err := f.deviceHandler.Client.CreateTrafficSchedulers(ctx, &tp_pb.TrafficSchedulers{
Girish Kumar8f73fe02019-12-09 13:19:37 +0000543 IntfId: sq.intfID, OnuId: sq.onuID,
544 UniId: sq.uniID, PortNo: sq.uniPort,
545 TrafficScheds: TrafficSched}); err != nil {
Girish Kumarf26e4882020-03-05 06:49:10 +0000546 return olterrors.NewErrAdapter("failed-to-create-traffic-schedulers-in-device", log.Fields{"TrafficScheds": TrafficSched}, err)
Girish Kumar8f73fe02019-12-09 13:19:37 +0000547 }
Neha Sharma96b7bf22020-06-15 10:37:32 +0000548 logger.Infow(ctx, "successfully-created-traffic-schedulers", log.Fields{
Shrey Baid26912972020-04-16 21:02:31 +0530549 "direction": sq.direction,
550 "traffic-queues": trafficQueues,
551 "device-id": f.deviceHandler.device.Id})
Girish Kumar8f73fe02019-12-09 13:19:37 +0000552
553 // On receiving the CreateTrafficQueues request, the driver should create corresponding
554 // downstream queues.
Neha Sharma96b7bf22020-06-15 10:37:32 +0000555 logger.Debugw(ctx, "sending-traffic-queues-create-to-device",
Shrey Baid26912972020-04-16 21:02:31 +0530556 log.Fields{"direction": sq.direction,
557 "traffic-queues": trafficQueues,
558 "device-id": f.deviceHandler.device.Id})
npujarec5762e2020-01-01 14:08:48 +0530559 if _, err := f.deviceHandler.Client.CreateTrafficQueues(ctx,
Girish Kumar8f73fe02019-12-09 13:19:37 +0000560 &tp_pb.TrafficQueues{IntfId: sq.intfID, OnuId: sq.onuID,
561 UniId: sq.uniID, PortNo: sq.uniPort,
Gamze Abaka78a1d2a2020-04-27 10:17:27 +0000562 TrafficQueues: trafficQueues,
563 TechProfileId: TrafficSched[0].TechProfileId}); err != nil {
Shrey Baid26912972020-04-16 21:02:31 +0530564 return olterrors.NewErrAdapter("failed-to-create-traffic-queues-in-device", log.Fields{"traffic-queues": trafficQueues}, err)
Girish Kumar8f73fe02019-12-09 13:19:37 +0000565 }
Neha Sharma96b7bf22020-06-15 10:37:32 +0000566 logger.Infow(ctx, "successfully-created-traffic-schedulers", log.Fields{
Shrey Baid26912972020-04-16 21:02:31 +0530567 "direction": sq.direction,
568 "traffic-queues": trafficQueues,
569 "device-id": f.deviceHandler.device.Id})
Girish Kumar8f73fe02019-12-09 13:19:37 +0000570
Esin Karamanccb714b2019-11-29 15:02:06 +0000571 if sq.direction == tp_pb.Direction_DOWNSTREAM {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000572 multicastTrafficQueues := f.techprofile[sq.intfID].GetMulticastTrafficQueues(ctx, sq.tpInst.(*tp.TechProfile))
Esin Karamanccb714b2019-11-29 15:02:06 +0000573 if len(multicastTrafficQueues) > 0 {
574 if _, present := f.interfaceToMcastQueueMap[sq.intfID]; !present {
575 //assumed that there is only one queue per PON for the multicast service
576 //the default queue with multicastQueuePerPonPort.Priority per a pon interface is used for multicast service
577 //just put it in interfaceToMcastQueueMap to use for building group members
Neha Sharma96b7bf22020-06-15 10:37:32 +0000578 logger.Debugw(ctx, "multicast-traffic-queues", log.Fields{"device-id": f.deviceHandler.device.Id})
Esin Karamanccb714b2019-11-29 15:02:06 +0000579 multicastQueuePerPonPort := multicastTrafficQueues[0]
580 f.interfaceToMcastQueueMap[sq.intfID] = &queueInfoBrief{
581 gemPortID: multicastQueuePerPonPort.GemportId,
582 servicePriority: multicastQueuePerPonPort.Priority,
583 }
584 //also store the queue info in kv store
Kent Hagermane6ff1012020-07-14 15:07:53 -0400585 if err := f.resourceMgr.AddMcastQueueForIntf(ctx, sq.intfID, multicastQueuePerPonPort.GemportId, multicastQueuePerPonPort.Priority); err != nil {
586 logger.Errorw(ctx, "failed-to-add-mcast-queue", log.Fields{"error": err})
587 return err
588 }
Shrey Baid26912972020-04-16 21:02:31 +0530589
Neha Sharma96b7bf22020-06-15 10:37:32 +0000590 logger.Infow(ctx, "multicast-queues-successfully-updated", log.Fields{"device-id": f.deviceHandler.device.Id})
Esin Karamanccb714b2019-11-29 15:02:06 +0000591 }
592 }
593 }
Girish Kumar8f73fe02019-12-09 13:19:37 +0000594 return nil
595}
596
salmansiddiqui7ac62132019-08-22 03:58:50 +0000597// RemoveSchedulerQueues removes the traffic schedulers from the device based on the given scheduler configuration and traffic shaping info
npujarec5762e2020-01-01 14:08:48 +0530598func (f *OpenOltFlowMgr) RemoveSchedulerQueues(ctx context.Context, sq schedQueue) error {
Manikkaraj kb1d51442019-07-23 10:41:02 -0400599
600 var Direction string
601 var SchedCfg *tp_pb.SchedulerConfig
602 var err error
Neha Sharma96b7bf22020-06-15 10:37:32 +0000603 logger.Infow(ctx, "removing-schedulers-and-queues-in-olt",
Shrey Baid26912972020-04-16 21:02:31 +0530604 log.Fields{
605 "direction": sq.direction,
606 "intf-id": sq.intfID,
607 "onu-id": sq.onuID,
608 "uni-id": sq.uniID,
609 "uni-port": sq.uniPort,
610 "device-id": f.deviceHandler.device.Id})
Gamze Abakafee36392019-10-03 11:17:24 +0000611 if sq.direction == tp_pb.Direction_UPSTREAM {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000612 SchedCfg, err = f.techprofile[sq.intfID].GetUsScheduler(ctx, sq.tpInst.(*tp.TechProfile))
Manikkaraj kb1d51442019-07-23 10:41:02 -0400613 Direction = "upstream"
Gamze Abakafee36392019-10-03 11:17:24 +0000614 } else if sq.direction == tp_pb.Direction_DOWNSTREAM {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000615 SchedCfg, err = f.techprofile[sq.intfID].GetDsScheduler(ctx, sq.tpInst.(*tp.TechProfile))
Manikkaraj kb1d51442019-07-23 10:41:02 -0400616 Direction = "downstream"
617 }
618
Girish Kumar8f73fe02019-12-09 13:19:37 +0000619 if err != nil {
Shrey Baid26912972020-04-16 21:02:31 +0530620 return olterrors.NewErrNotFound("scheduler-config",
621 log.Fields{
622 "int-id": sq.intfID,
623 "direction": sq.direction,
624 "device-id": f.deviceHandler.device.Id}, err)
Girish Kumar8f73fe02019-12-09 13:19:37 +0000625 }
626
npujarec5762e2020-01-01 14:08:48 +0530627 KVStoreMeter, err := f.resourceMgr.GetMeterIDForOnu(ctx, Direction, sq.intfID, sq.onuID, sq.uniID, sq.tpID)
Manikkaraj kb1d51442019-07-23 10:41:02 -0400628 if err != nil {
Shrey Baid26912972020-04-16 21:02:31 +0530629 return olterrors.NewErrNotFound("meter",
630 log.Fields{
631 "onu-id": sq.onuID,
632 "device-id": f.deviceHandler.device.Id}, err)
Manikkaraj kb1d51442019-07-23 10:41:02 -0400633 }
634 if KVStoreMeter == nil {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000635 logger.Warnw(ctx, "no-meter-installed-yet",
Shrey Baid26912972020-04-16 21:02:31 +0530636 log.Fields{
637 "direction": Direction,
638 "intf-id": sq.intfID,
639 "onu-id": sq.onuID,
640 "uni-id": sq.uniID,
641 "device-id": f.deviceHandler.device.Id})
Manikkaraj kb1d51442019-07-23 10:41:02 -0400642 return nil
643 }
644 cir := KVStoreMeter.Bands[0].Rate
645 cbs := KVStoreMeter.Bands[0].BurstSize
646 eir := KVStoreMeter.Bands[1].Rate
647 ebs := KVStoreMeter.Bands[1].BurstSize
648 pir := cir + eir
649 pbs := cbs + ebs
650
651 TrafficShaping := &tp_pb.TrafficShapingInfo{Cir: cir, Cbs: cbs, Pir: pir, Pbs: pbs}
652
Takahiro Suzuki2ba0e0b2020-06-05 14:23:03 -0700653 TrafficSched := []*tp_pb.TrafficScheduler{f.techprofile[sq.intfID].GetTrafficScheduler(sq.tpInst.(*tp.TechProfile), SchedCfg, TrafficShaping)}
Gamze Abaka78a1d2a2020-04-27 10:17:27 +0000654 TrafficSched[0].TechProfileId = sq.tpID
Girish Kumar8f73fe02019-12-09 13:19:37 +0000655
Neha Sharma96b7bf22020-06-15 10:37:32 +0000656 TrafficQueues, err := f.techprofile[sq.intfID].GetTrafficQueues(ctx, sq.tpInst.(*tp.TechProfile), sq.direction)
Girish Kumar8f73fe02019-12-09 13:19:37 +0000657 if err != nil {
Shrey Baid26912972020-04-16 21:02:31 +0530658 return olterrors.NewErrAdapter("unable-to-construct-traffic-queue-configuration",
659 log.Fields{
660 "intf-id": sq.intfID,
661 "direction": sq.direction,
662 "device-id": f.deviceHandler.device.Id}, err)
Girish Kumar8f73fe02019-12-09 13:19:37 +0000663 }
Manikkaraj kb1d51442019-07-23 10:41:02 -0400664
npujarec5762e2020-01-01 14:08:48 +0530665 if _, err = f.deviceHandler.Client.RemoveTrafficQueues(ctx,
Gamze Abakafee36392019-10-03 11:17:24 +0000666 &tp_pb.TrafficQueues{IntfId: sq.intfID, OnuId: sq.onuID,
667 UniId: sq.uniID, PortNo: sq.uniPort,
Gamze Abaka78a1d2a2020-04-27 10:17:27 +0000668 TrafficQueues: TrafficQueues,
669 TechProfileId: TrafficSched[0].TechProfileId}); err != nil {
Girish Kumarf26e4882020-03-05 06:49:10 +0000670 return olterrors.NewErrAdapter("unable-to-remove-traffic-queues-from-device",
Shrey Baid26912972020-04-16 21:02:31 +0530671 log.Fields{
672 "intf-id": sq.intfID,
673 "traffic-queues": TrafficQueues,
674 "device-id": f.deviceHandler.device.Id}, err)
Manikkaraj kb1d51442019-07-23 10:41:02 -0400675 }
Neha Sharma96b7bf22020-06-15 10:37:32 +0000676 logger.Infow(ctx, "removed-traffic-queues-successfully", log.Fields{"device-id": f.deviceHandler.device.Id})
npujarec5762e2020-01-01 14:08:48 +0530677 if _, err = f.deviceHandler.Client.RemoveTrafficSchedulers(ctx, &tp_pb.TrafficSchedulers{
Gamze Abakafee36392019-10-03 11:17:24 +0000678 IntfId: sq.intfID, OnuId: sq.onuID,
679 UniId: sq.uniID, PortNo: sq.uniPort,
Manikkaraj kb1d51442019-07-23 10:41:02 -0400680 TrafficScheds: TrafficSched}); err != nil {
Girish Kumarf26e4882020-03-05 06:49:10 +0000681 return olterrors.NewErrAdapter("unable-to-remove-traffic-schedulers-from-device",
Shrey Baid26912972020-04-16 21:02:31 +0530682 log.Fields{
683 "intf-id": sq.intfID,
684 "traffic-schedulers": TrafficSched}, err)
Manikkaraj kb1d51442019-07-23 10:41:02 -0400685 }
686
Neha Sharma96b7bf22020-06-15 10:37:32 +0000687 logger.Infow(ctx, "removed-traffic-schedulers-successfully", log.Fields{"device-id": f.deviceHandler.device.Id})
salmansiddiqui7ac62132019-08-22 03:58:50 +0000688
689 /* After we successfully remove the scheduler configuration on the OLT device,
Manikkaraj kb1d51442019-07-23 10:41:02 -0400690 * delete the meter id on the KV store.
691 */
npujarec5762e2020-01-01 14:08:48 +0530692 err = f.resourceMgr.RemoveMeterIDForOnu(ctx, Direction, sq.intfID, sq.onuID, sq.uniID, sq.tpID)
Manikkaraj kb1d51442019-07-23 10:41:02 -0400693 if err != nil {
Shrey Baid26912972020-04-16 21:02:31 +0530694 return olterrors.NewErrAdapter("unable-to-remove-meter",
695 log.Fields{
696 "onu": sq.onuID,
697 "meter": KVStoreMeter.MeterId,
698 "device-id": f.deviceHandler.device.Id}, err)
Manikkaraj kb1d51442019-07-23 10:41:02 -0400699 }
Neha Sharma96b7bf22020-06-15 10:37:32 +0000700 logger.Infow(ctx, "removed-meter-from-KV-store-successfully",
Shrey Baid26912972020-04-16 21:02:31 +0530701 log.Fields{
702 "meter-id": KVStoreMeter.MeterId,
703 "dir": Direction,
704 "device-id": f.deviceHandler.device.Id})
Manikkaraj kb1d51442019-07-23 10:41:02 -0400705 return err
706}
707
Gamze Abakafee36392019-10-03 11:17:24 +0000708// This function allocates tconts and GEM ports for an ONU
Takahiro Suzuki2ba0e0b2020-06-05 14:23:03 -0700709func (f *OpenOltFlowMgr) createTcontGemports(ctx context.Context, intfID uint32, onuID uint32, uniID uint32, uni string, uniPort uint32, TpID uint32, UsMeterID uint32, DsMeterID uint32, flowMetadata *voltha.FlowMetadata) (uint32, []uint32, interface{}) {
Gamze Abakafee36392019-10-03 11:17:24 +0000710 var allocIDs []uint32
711 var allgemPortIDs []uint32
manikkaraj kbf256be2019-03-25 00:13:48 +0530712 var gemPortIDs []uint32
Girish Gowdra3d633032019-12-10 16:37:05 +0530713 tpInstanceExists := false
Girish Kumar8f73fe02019-12-09 13:19:37 +0000714 var err error
Gamze Abakafee36392019-10-03 11:17:24 +0000715
npujarec5762e2020-01-01 14:08:48 +0530716 allocIDs = f.resourceMgr.GetCurrentAllocIDsForOnu(ctx, intfID, onuID, uniID)
717 allgemPortIDs = f.resourceMgr.GetCurrentGEMPortIDsForOnu(ctx, intfID, onuID, uniID)
Manikkaraj kb1d51442019-07-23 10:41:02 -0400718
Neha Sharma96b7bf22020-06-15 10:37:32 +0000719 tpPath := f.getTPpath(ctx, intfID, uni, TpID)
Girish Gowdra54934262019-11-13 14:19:55 +0530720
Neha Sharma96b7bf22020-06-15 10:37:32 +0000721 logger.Debugw(ctx, "creating-new-tcont-and-gem", log.Fields{
Shrey Baid26912972020-04-16 21:02:31 +0530722 "intf-id": intfID,
723 "onu-id": onuID,
724 "uni-id": uniID,
725 "device-id": f.deviceHandler.device.Id,
726 "tp-id": TpID})
Girish Gowdra54934262019-11-13 14:19:55 +0530727
Manikkaraj kb1d51442019-07-23 10:41:02 -0400728 // Check tech profile instance already exists for derived port name
npujarec5762e2020-01-01 14:08:48 +0530729 techProfileInstance, _ := f.techprofile[intfID].GetTPInstanceFromKVStore(ctx, TpID, tpPath)
salmansiddiqui7ac62132019-08-22 03:58:50 +0000730 if techProfileInstance == nil {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000731 logger.Infow(ctx, "tp-instance-not-found--creating-new",
Shrey Baid26912972020-04-16 21:02:31 +0530732 log.Fields{
733 "path": tpPath,
734 "device-id": f.deviceHandler.device.Id})
npujarec5762e2020-01-01 14:08:48 +0530735 techProfileInstance, err = f.techprofile[intfID].CreateTechProfInstance(ctx, TpID, uni, intfID)
Girish Kumar8f73fe02019-12-09 13:19:37 +0000736 if err != nil {
Girish Gowdra54934262019-11-13 14:19:55 +0530737 // This should not happen, something wrong in KV backend transaction
Neha Sharma96b7bf22020-06-15 10:37:32 +0000738 logger.Errorw(ctx, "tp-instance-create-failed",
Shrey Baid26912972020-04-16 21:02:31 +0530739 log.Fields{
740 "error": err,
741 "tp-id": TpID,
742 "device-id": f.deviceHandler.device.Id})
Gamze Abakafee36392019-10-03 11:17:24 +0000743 return 0, nil, nil
manikkaraj kbf256be2019-03-25 00:13:48 +0530744 }
Kent Hagermane6ff1012020-07-14 15:07:53 -0400745 if err := f.resourceMgr.UpdateTechProfileIDForOnu(ctx, intfID, onuID, uniID, TpID); err != nil {
746 logger.Warnw(ctx, "failed-to-update-tech-profile-id", log.Fields{"error": err})
747 }
manikkaraj kbf256be2019-03-25 00:13:48 +0530748 } else {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000749 logger.Debugw(ctx, "tech-profile-instance-already-exist-for-given port-name",
Shrey Baid26912972020-04-16 21:02:31 +0530750 log.Fields{
751 "uni": uni,
752 "device-id": f.deviceHandler.device.Id})
Girish Gowdra3d633032019-12-10 16:37:05 +0530753 tpInstanceExists = true
manikkaraj kbf256be2019-03-25 00:13:48 +0530754 }
Gamze Abakafee36392019-10-03 11:17:24 +0000755
Takahiro Suzuki2ba0e0b2020-06-05 14:23:03 -0700756 switch tpInst := techProfileInstance.(type) {
757 case *tp.TechProfile:
758 if UsMeterID != 0 {
759 sq := schedQueue{direction: tp_pb.Direction_UPSTREAM, intfID: intfID, onuID: onuID, uniID: uniID, tpID: TpID,
760 uniPort: uniPort, tpInst: techProfileInstance, meterID: UsMeterID, flowMetadata: flowMetadata}
761 if err := f.CreateSchedulerQueues(ctx, sq); err != nil {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000762 logger.Errorw(ctx, "CreateSchedulerQueues-failed-upstream",
Takahiro Suzuki2ba0e0b2020-06-05 14:23:03 -0700763 log.Fields{
764 "error": err,
765 "meter-id": UsMeterID,
766 "device-id": f.deviceHandler.device.Id})
767 return 0, nil, nil
768 }
769 }
770 if DsMeterID != 0 {
771 sq := schedQueue{direction: tp_pb.Direction_DOWNSTREAM, intfID: intfID, onuID: onuID, uniID: uniID, tpID: TpID,
772 uniPort: uniPort, tpInst: techProfileInstance, meterID: DsMeterID, flowMetadata: flowMetadata}
773 if err := f.CreateSchedulerQueues(ctx, sq); err != nil {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000774 logger.Errorw(ctx, "CreateSchedulerQueues-failed-downstream",
Takahiro Suzuki2ba0e0b2020-06-05 14:23:03 -0700775 log.Fields{
776 "error": err,
777 "meter-id": DsMeterID,
778 "device-id": f.deviceHandler.device.Id})
779 return 0, nil, nil
780 }
781 }
782 allocID := tpInst.UsScheduler.AllocID
783 for _, gem := range tpInst.UpstreamGemPortAttributeList {
784 gemPortIDs = append(gemPortIDs, gem.GemportID)
785 }
786 allocIDs = appendUnique(allocIDs, allocID)
Gamze Abakafee36392019-10-03 11:17:24 +0000787
Takahiro Suzuki2ba0e0b2020-06-05 14:23:03 -0700788 if tpInstanceExists {
789 return allocID, gemPortIDs, techProfileInstance
790 }
791
792 for _, gemPortID := range gemPortIDs {
793 allgemPortIDs = appendUnique(allgemPortIDs, gemPortID)
794 }
Neha Sharma96b7bf22020-06-15 10:37:32 +0000795 logger.Infow(ctx, "allocated-tcont-and-gem-ports",
Takahiro Suzuki2ba0e0b2020-06-05 14:23:03 -0700796 log.Fields{
797 "alloc-ids": allocIDs,
798 "gemports": allgemPortIDs,
799 "device-id": f.deviceHandler.device.Id})
800 // Send Tconts and GEM ports to KV store
801 f.storeTcontsGEMPortsIntoKVStore(ctx, intfID, onuID, uniID, allocIDs, allgemPortIDs)
Girish Gowdra3d633032019-12-10 16:37:05 +0530802 return allocID, gemPortIDs, techProfileInstance
Takahiro Suzuki2ba0e0b2020-06-05 14:23:03 -0700803 case *tp.EponProfile:
804 // CreateSchedulerQueues for EPON needs to be implemented here
805 // when voltha-protos for EPON is completed.
806 allocID := tpInst.AllocID
807 for _, gem := range tpInst.UpstreamQueueAttributeList {
808 gemPortIDs = append(gemPortIDs, gem.GemportID)
809 }
810 allocIDs = appendUnique(allocIDs, allocID)
811
812 if tpInstanceExists {
813 return allocID, gemPortIDs, techProfileInstance
814 }
815
816 for _, gemPortID := range gemPortIDs {
817 allgemPortIDs = appendUnique(allgemPortIDs, gemPortID)
818 }
Neha Sharma96b7bf22020-06-15 10:37:32 +0000819 logger.Infow(ctx, "allocated-tcont-and-gem-ports",
Takahiro Suzuki2ba0e0b2020-06-05 14:23:03 -0700820 log.Fields{
821 "alloc-ids": allocIDs,
822 "gemports": allgemPortIDs,
823 "device-id": f.deviceHandler.device.Id})
824 // Send Tconts and GEM ports to KV store
825 f.storeTcontsGEMPortsIntoKVStore(ctx, intfID, onuID, uniID, allocIDs, allgemPortIDs)
826 return allocID, gemPortIDs, techProfileInstance
827 default:
Neha Sharma96b7bf22020-06-15 10:37:32 +0000828 logger.Errorw(ctx, "unknown-tech",
Takahiro Suzuki2ba0e0b2020-06-05 14:23:03 -0700829 log.Fields{
830 "tpInst": tpInst})
831 return 0, nil, nil
Girish Gowdra3d633032019-12-10 16:37:05 +0530832 }
manikkaraj kbf256be2019-03-25 00:13:48 +0530833}
834
npujarec5762e2020-01-01 14:08:48 +0530835func (f *OpenOltFlowMgr) storeTcontsGEMPortsIntoKVStore(ctx context.Context, intfID uint32, onuID uint32, uniID uint32, allocID []uint32, gemPortIDs []uint32) {
manikkaraj kbf256be2019-03-25 00:13:48 +0530836
Neha Sharma96b7bf22020-06-15 10:37:32 +0000837 logger.Debugw(ctx, "storing-allocated-tconts-and-gem-ports-into-KV-store",
Shrey Baid26912972020-04-16 21:02:31 +0530838 log.Fields{
839 "intf-id": intfID,
840 "onu-id": onuID,
841 "uni-id": uniID,
842 "alloc-id": allocID,
843 "gemport-ids": gemPortIDs,
844 "device-id": f.deviceHandler.device.Id})
manikkaraj kbf256be2019-03-25 00:13:48 +0530845 /* Update the allocated alloc_id and gem_port_id for the ONU/UNI to KV store */
npujarec5762e2020-01-01 14:08:48 +0530846 if err := f.resourceMgr.UpdateAllocIdsForOnu(ctx, intfID, onuID, uniID, allocID); err != nil {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000847 logger.Errorw(ctx, "error-while-uploading-allocid-to-kv-store", log.Fields{"device-id": f.deviceHandler.device.Id})
manikkaraj kbf256be2019-03-25 00:13:48 +0530848 }
npujarec5762e2020-01-01 14:08:48 +0530849 if err := f.resourceMgr.UpdateGEMPortIDsForOnu(ctx, intfID, onuID, uniID, gemPortIDs); err != nil {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000850 logger.Errorw(ctx, "error-while-uploading-gemports-to-kv-store", log.Fields{"device-id": f.deviceHandler.device.Id})
manikkaraj kbf256be2019-03-25 00:13:48 +0530851 }
npujarec5762e2020-01-01 14:08:48 +0530852 if err := f.resourceMgr.UpdateGEMportsPonportToOnuMapOnKVStore(ctx, gemPortIDs, intfID, onuID, uniID); err != nil {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000853 logger.Error(ctx, "error-while-uploading-gemtopon-map-to-kv-store", log.Fields{"device-id": f.deviceHandler.device.Id})
manikkaraj kbf256be2019-03-25 00:13:48 +0530854 }
Neha Sharma96b7bf22020-06-15 10:37:32 +0000855 logger.Infow(ctx, "stored-tconts-and-gem-into-kv-store-successfully", log.Fields{"device-id": f.deviceHandler.device.Id})
manikkaraj k9eb6cac2019-05-09 12:32:03 -0400856 for _, gemPort := range gemPortIDs {
npujarec5762e2020-01-01 14:08:48 +0530857 f.addGemPortToOnuInfoMap(ctx, intfID, onuID, gemPort)
manikkaraj k9eb6cac2019-05-09 12:32:03 -0400858 }
manikkaraj kbf256be2019-03-25 00:13:48 +0530859}
860
Neha Sharma96b7bf22020-06-15 10:37:32 +0000861func (f *OpenOltFlowMgr) populateTechProfilePerPonPort(ctx context.Context) error {
salmansiddiqui7ac62132019-08-22 03:58:50 +0000862 var tpCount int
manikkaraj kbf256be2019-03-25 00:13:48 +0530863 for _, techRange := range f.resourceMgr.DevInfo.Ranges {
salmansiddiqui7ac62132019-08-22 03:58:50 +0000864 for _, intfID := range techRange.IntfIds {
865 f.techprofile[intfID] = f.resourceMgr.ResourceMgrs[uint32(intfID)].TechProfileMgr
Manikkaraj kb1d51442019-07-23 10:41:02 -0400866 tpCount++
Neha Sharma96b7bf22020-06-15 10:37:32 +0000867 logger.Debugw(ctx, "init-tech-profile-done",
Shrey Baid26912972020-04-16 21:02:31 +0530868 log.Fields{
869 "intf-id": intfID,
870 "device-id": f.deviceHandler.device.Id})
manikkaraj kbf256be2019-03-25 00:13:48 +0530871 }
872 }
873 //Make sure we have as many tech_profiles as there are pon ports on the device
Manikkaraj kb1d51442019-07-23 10:41:02 -0400874 if tpCount != int(f.resourceMgr.DevInfo.GetPonPorts()) {
Thomas Lee S94109f12020-03-03 16:39:29 +0530875 return olterrors.NewErrInvalidValue(log.Fields{
Shrey Baid26912972020-04-16 21:02:31 +0530876 "reason": "tP-count-does-not-match-number-of-pon-ports",
David K. Bainbridge794735f2020-02-11 21:01:37 -0800877 "tech-profile-count": tpCount,
Shrey Baid26912972020-04-16 21:02:31 +0530878 "pon-port-count": f.resourceMgr.DevInfo.GetPonPorts(),
879 "device-id": f.deviceHandler.device.Id}, nil)
manikkaraj kbf256be2019-03-25 00:13:48 +0530880 }
Neha Sharma96b7bf22020-06-15 10:37:32 +0000881 logger.Infow(ctx, "populated-techprofile-for-ponports-successfully",
Shrey Baid26912972020-04-16 21:02:31 +0530882 log.Fields{
883 "numofTech": tpCount,
884 "numPonPorts": f.resourceMgr.DevInfo.GetPonPorts(),
885 "device-id": f.deviceHandler.device.Id})
manikkaraj kbf256be2019-03-25 00:13:48 +0530886 return nil
887}
888
npujarec5762e2020-01-01 14:08:48 +0530889func (f *OpenOltFlowMgr) addUpstreamDataFlow(ctx context.Context, intfID uint32, onuID uint32, uniID uint32,
Manikkaraj k884c1242019-04-11 16:26:42 +0530890 portNo uint32, uplinkClassifier map[string]interface{},
891 uplinkAction map[string]interface{}, logicalFlow *ofp.OfpFlowStats,
Gamze Abaka78a1d2a2020-04-27 10:17:27 +0000892 allocID uint32, gemportID uint32, tpID uint32) error {
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700893 uplinkClassifier[PacketTagType] = SingleTag
Neha Sharma96b7bf22020-06-15 10:37:32 +0000894 logger.Debugw(ctx, "adding-upstream-data-flow",
Shrey Baid26912972020-04-16 21:02:31 +0530895 log.Fields{
896 "uplinkClassifier": uplinkClassifier,
897 "uplinkAction": uplinkAction})
David K. Bainbridge794735f2020-02-11 21:01:37 -0800898 return f.addHSIAFlow(ctx, intfID, onuID, uniID, portNo, uplinkClassifier, uplinkAction,
Gamze Abaka78a1d2a2020-04-27 10:17:27 +0000899 Upstream, logicalFlow, allocID, gemportID, tpID)
Manikkaraj k884c1242019-04-11 16:26:42 +0530900 /* TODO: Install Secondary EAP on the subscriber vlan */
manikkaraj kbf256be2019-03-25 00:13:48 +0530901}
902
npujarec5762e2020-01-01 14:08:48 +0530903func (f *OpenOltFlowMgr) addDownstreamDataFlow(ctx context.Context, intfID uint32, onuID uint32, uniID uint32,
Manikkaraj k884c1242019-04-11 16:26:42 +0530904 portNo uint32, downlinkClassifier map[string]interface{},
905 downlinkAction map[string]interface{}, logicalFlow *ofp.OfpFlowStats,
Gamze Abaka78a1d2a2020-04-27 10:17:27 +0000906 allocID uint32, gemportID uint32, tpID uint32) error {
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700907 downlinkClassifier[PacketTagType] = DoubleTag
Neha Sharma96b7bf22020-06-15 10:37:32 +0000908 logger.Debugw(ctx, "adding-downstream-data-flow",
Shrey Baid26912972020-04-16 21:02:31 +0530909 log.Fields{
910 "downlinkClassifier": downlinkClassifier,
911 "downlinkAction": downlinkAction})
Manikkaraj kb1d51442019-07-23 10:41:02 -0400912 // Ignore Downlink trap flow given by core, cannot do anything with this flow */
913 if vlan, exists := downlinkClassifier[VlanVid]; exists {
914 if vlan.(uint32) == (uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 4000) { //private VLAN given by core
David K. Bainbridge82efc492019-09-04 09:57:11 -0700915 if metadata, exists := downlinkClassifier[Metadata]; exists { // inport is filled in metadata by core
Neha Sharma96b7bf22020-06-15 10:37:32 +0000916 if uint32(metadata.(uint64)) == MkUniPortNum(ctx, intfID, onuID, uniID) {
917 logger.Infow(ctx, "ignoring-dl-trap-device-flow-from-core",
Shrey Baid26912972020-04-16 21:02:31 +0530918 log.Fields{
919 "flow": logicalFlow,
920 "device-id": f.deviceHandler.device.Id,
921 "onu-id": onuID,
922 "intf-id": intfID})
David K. Bainbridge794735f2020-02-11 21:01:37 -0800923 return nil
Manikkaraj kb1d51442019-07-23 10:41:02 -0400924 }
925 }
926 }
Manikkaraj k884c1242019-04-11 16:26:42 +0530927 }
Manikkaraj kb1d51442019-07-23 10:41:02 -0400928
Manikkaraj k884c1242019-04-11 16:26:42 +0530929 /* Already this info available classifier? */
Girish Gowdru6a80bbd2019-07-02 07:36:09 -0700930 downlinkAction[PopVlan] = true
Matt Jeannereted16b7c2019-11-01 13:31:35 -0400931 // vlan_vid is a uint32. must be type asserted as such or conversion fails
932 dlClVid, ok := downlinkClassifier[VlanVid].(uint32)
Girish Gowdra26f344b2019-10-23 14:39:13 +0530933 if ok {
934 downlinkAction[VlanVid] = dlClVid & 0xfff
935 } else {
Thomas Lee S94109f12020-03-03 16:39:29 +0530936 return olterrors.NewErrInvalidValue(log.Fields{
Shrey Baid26912972020-04-16 21:02:31 +0530937 "reason": "failed-to-convert-vlanid-classifier",
938 "vlan-id": VlanVid,
939 "device-id": f.deviceHandler.device.Id}, nil).Log()
Girish Gowdra26f344b2019-10-23 14:39:13 +0530940 }
941
David K. Bainbridge794735f2020-02-11 21:01:37 -0800942 return f.addHSIAFlow(ctx, intfID, onuID, uniID, portNo, downlinkClassifier, downlinkAction,
Gamze Abaka78a1d2a2020-04-27 10:17:27 +0000943 Downstream, logicalFlow, allocID, gemportID, tpID)
manikkaraj kbf256be2019-03-25 00:13:48 +0530944}
945
npujarec5762e2020-01-01 14:08:48 +0530946func (f *OpenOltFlowMgr) addHSIAFlow(ctx context.Context, intfID uint32, onuID uint32, uniID uint32, portNo uint32, classifier map[string]interface{},
Manikkaraj k884c1242019-04-11 16:26:42 +0530947 action map[string]interface{}, direction string, logicalFlow *ofp.OfpFlowStats,
Gamze Abaka78a1d2a2020-04-27 10:17:27 +0000948 allocID uint32, gemPortID uint32, tpID uint32) error {
Manikkaraj k884c1242019-04-11 16:26:42 +0530949 /* One of the OLT platform (Broadcom BAL) requires that symmetric
950 flows require the same flow_id to be used across UL and DL.
951 Since HSIA flow is the only symmetric flow currently, we need to
952 re-use the flow_id across both direction. The 'flow_category'
953 takes priority over flow_cookie to find any available HSIA_FLOW
954 id for the ONU.
955 */
Neha Sharma96b7bf22020-06-15 10:37:32 +0000956 logger.Infow(ctx, "adding-hsia-flow",
Shrey Baid26912972020-04-16 21:02:31 +0530957 log.Fields{
958 "intf-id": intfID,
959 "onu-id": onuID,
960 "uni-id": uniID,
961 "device-id": f.deviceHandler.device.Id,
962 "classifier": classifier,
963 "action": action,
964 "direction": direction,
965 "alloc-id": allocID,
966 "gemport-id": gemPortID,
967 "logicalflow": *logicalFlow})
Girish Gowdrafae935c2020-02-17 19:21:44 +0530968 var vlanPbit uint32 = 0xff // means no pbit
Gamze Abaka724d0852020-03-18 12:10:24 +0000969 var vlanVid uint32
Manikkaraj kb1d51442019-07-23 10:41:02 -0400970 if _, ok := classifier[VlanPcp]; ok {
Gamze Abakafee36392019-10-03 11:17:24 +0000971 vlanPbit = classifier[VlanPcp].(uint32)
Neha Sharma96b7bf22020-06-15 10:37:32 +0000972 logger.Debugw(ctx, "found-pbit-in-flow",
Shrey Baid26912972020-04-16 21:02:31 +0530973 log.Fields{
974 "vlan-pbit": vlanPbit,
975 "intf-id": intfID,
976 "onu-id": onuID,
977 "device-id": f.deviceHandler.device.Id})
David K. Bainbridge794735f2020-02-11 21:01:37 -0800978 } else {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000979 logger.Debugw(ctx, "pbit-not-found-in-flow",
Shrey Baid26912972020-04-16 21:02:31 +0530980 log.Fields{
981 "vlan-pcp": VlanPcp,
982 "intf-id": intfID,
983 "onu-id": onuID,
984 "device-id": f.deviceHandler.device.Id})
Manikkaraj kb1d51442019-07-23 10:41:02 -0400985 }
Gamze Abaka724d0852020-03-18 12:10:24 +0000986 if _, ok := classifier[VlanVid]; ok {
987 vlanVid = classifier[VlanVid].(uint32)
Girish Kumara1ea2aa2020-08-19 18:14:22 +0000988 logger.Debugw(ctx, "found-vlan-in-the-flow",
Shrey Baid26912972020-04-16 21:02:31 +0530989 log.Fields{
990 "vlan-vid": vlanVid,
991 "intf-id": intfID,
992 "onu-id": onuID,
993 "device-id": f.deviceHandler.device.Id})
Gamze Abaka724d0852020-03-18 12:10:24 +0000994 }
Neha Sharma96b7bf22020-06-15 10:37:32 +0000995 flowStoreCookie := getFlowStoreCookie(ctx, classifier, gemPortID)
npujarec5762e2020-01-01 14:08:48 +0530996 if present := f.resourceMgr.IsFlowCookieOnKVStore(ctx, uint32(intfID), int32(onuID), int32(uniID), flowStoreCookie); present {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000997 logger.Infow(ctx, "flow-already-exists",
Shrey Baid26912972020-04-16 21:02:31 +0530998 log.Fields{
999 "device-id": f.deviceHandler.device.Id,
1000 "intf-id": intfID,
1001 "onu-id": onuID})
David K. Bainbridge794735f2020-02-11 21:01:37 -08001002 return nil
Girish Gowdra3d633032019-12-10 16:37:05 +05301003 }
Gamze Abaka724d0852020-03-18 12:10:24 +00001004 flowID, err := f.resourceMgr.GetFlowID(ctx, intfID, int32(onuID), int32(uniID), gemPortID, flowStoreCookie, HsiaFlow, vlanVid, vlanPbit)
Manikkaraj k884c1242019-04-11 16:26:42 +05301005 if err != nil {
Shrey Baid26912972020-04-16 21:02:31 +05301006 return olterrors.NewErrNotFound("hsia-flow-id",
1007 log.Fields{
1008 "direction": direction,
1009 "device-id": f.deviceHandler.device.Id,
1010 "intf-id": intfID,
1011 "onu-id": onuID,
1012 }, err).Log()
Manikkaraj k884c1242019-04-11 16:26:42 +05301013 }
David K. Bainbridge794735f2020-02-11 21:01:37 -08001014 classifierProto, err := makeOpenOltClassifierField(classifier)
1015 if err != nil {
Shrey Baid26912972020-04-16 21:02:31 +05301016 return olterrors.NewErrInvalidValue(log.Fields{"classifier": classifier, "device-id": f.deviceHandler.device.Id}, err).Log()
Manikkaraj k884c1242019-04-11 16:26:42 +05301017 }
Neha Sharma96b7bf22020-06-15 10:37:32 +00001018 logger.Debugw(ctx, "created-classifier-proto",
Shrey Baid26912972020-04-16 21:02:31 +05301019 log.Fields{
1020 "classifier": *classifierProto,
1021 "device-id": f.deviceHandler.device.Id})
Gamze Abaka724d0852020-03-18 12:10:24 +00001022 actionProto, err := makeOpenOltActionField(action, classifier)
David K. Bainbridge794735f2020-02-11 21:01:37 -08001023 if err != nil {
Shrey Baid26912972020-04-16 21:02:31 +05301024 return olterrors.NewErrInvalidValue(log.Fields{"action": action, "device-id": f.deviceHandler.device.Id}, err).Log()
Manikkaraj k884c1242019-04-11 16:26:42 +05301025 }
Neha Sharma96b7bf22020-06-15 10:37:32 +00001026 logger.Debugw(ctx, "created-action-proto",
Shrey Baid26912972020-04-16 21:02:31 +05301027 log.Fields{
1028 "action": *actionProto,
1029 "device-id": f.deviceHandler.device.Id})
Neha Sharma96b7bf22020-06-15 10:37:32 +00001030 networkIntfID, err := getNniIntfID(ctx, classifier, action)
Abhilash Laxmeshwarab0bd522019-10-21 15:05:15 +05301031 if err != nil {
Thomas Lee S94109f12020-03-03 16:39:29 +05301032 return olterrors.NewErrNotFound("nni-interface-id",
David K. Bainbridge794735f2020-02-11 21:01:37 -08001033 log.Fields{
1034 "classifier": classifier,
1035 "action": action,
Shrey Baid26912972020-04-16 21:02:31 +05301036 "device-id": f.deviceHandler.device.Id,
David K. Bainbridge794735f2020-02-11 21:01:37 -08001037 }, err).Log()
Abhilash Laxmeshwarab0bd522019-10-21 15:05:15 +05301038 }
Girish Gowdru6a80bbd2019-07-02 07:36:09 -07001039 flow := openoltpb2.Flow{AccessIntfId: int32(intfID),
1040 OnuId: int32(onuID),
1041 UniId: int32(uniID),
salmansiddiqui7ac62132019-08-22 03:58:50 +00001042 FlowId: flowID,
Manikkaraj k884c1242019-04-11 16:26:42 +05301043 FlowType: direction,
Girish Gowdru6a80bbd2019-07-02 07:36:09 -07001044 AllocId: int32(allocID),
1045 NetworkIntfId: int32(networkIntfID),
1046 GemportId: int32(gemPortID),
Manikkaraj k884c1242019-04-11 16:26:42 +05301047 Classifier: classifierProto,
1048 Action: actionProto,
1049 Priority: int32(logicalFlow.Priority),
1050 Cookie: logicalFlow.Cookie,
Gamze Abaka78a1d2a2020-04-27 10:17:27 +00001051 PortNo: portNo,
1052 TechProfileId: tpID,
1053 }
David K. Bainbridge794735f2020-02-11 21:01:37 -08001054 if err := f.addFlowToDevice(ctx, logicalFlow, &flow); err != nil {
Thomas Lee S94109f12020-03-03 16:39:29 +05301055 return olterrors.NewErrFlowOp("add", flowID, nil, err).Log()
Manikkaraj k884c1242019-04-11 16:26:42 +05301056 }
Neha Sharma96b7bf22020-06-15 10:37:32 +00001057 logger.Infow(ctx, "hsia-flow-added-to-device-successfully",
Shrey Baid26912972020-04-16 21:02:31 +05301058 log.Fields{"direction": direction,
1059 "device-id": f.deviceHandler.device.Id,
1060 "flow": flow,
1061 "intf-id": intfID,
1062 "onu-id": onuID})
David K. Bainbridge794735f2020-02-11 21:01:37 -08001063 flowsToKVStore := f.getUpdatedFlowInfo(ctx, &flow, flowStoreCookie, HsiaFlow, flowID, logicalFlow.Id)
1064 if err := f.updateFlowInfoToKVStore(ctx, flow.AccessIntfId,
1065 flow.OnuId,
1066 flow.UniId,
1067 flow.FlowId /*flowCategory,*/, flowsToKVStore); err != nil {
Shrey Baid26912972020-04-16 21:02:31 +05301068 return olterrors.NewErrPersistence("update", "flow", flowID,
1069 log.Fields{
1070 "flow": flow,
1071 "device-id": f.deviceHandler.device.Id,
1072 "intf-id": intfID,
1073 "onu-id": onuID}, err).Log()
David K. Bainbridge794735f2020-02-11 21:01:37 -08001074 }
1075 return nil
Manikkaraj k884c1242019-04-11 16:26:42 +05301076}
Esin Karamanae41e2b2019-12-17 18:13:13 +00001077
Gamze Abaka78a1d2a2020-04-27 10:17:27 +00001078func (f *OpenOltFlowMgr) addDHCPTrapFlow(ctx context.Context, intfID uint32, onuID uint32, uniID uint32, portNo uint32,
1079 classifier map[string]interface{}, action map[string]interface{}, logicalFlow *ofp.OfpFlowStats, allocID uint32,
1080 gemPortID uint32, tpID uint32) error {
Manjunath Vanarajuluadc57d12019-04-23 11:07:21 +05301081
Neha Sharma96b7bf22020-06-15 10:37:32 +00001082 networkIntfID, err := getNniIntfID(ctx, classifier, action)
Abhilash Laxmeshwarab0bd522019-10-21 15:05:15 +05301083 if err != nil {
Thomas Lee S94109f12020-03-03 16:39:29 +05301084 return olterrors.NewErrNotFound("nni-interface-id", log.Fields{
David K. Bainbridge794735f2020-02-11 21:01:37 -08001085 "classifier": classifier,
Shrey Baid26912972020-04-16 21:02:31 +05301086 "action": action,
1087 "device-id": f.deviceHandler.device.Id},
David K. Bainbridge794735f2020-02-11 21:01:37 -08001088 err).Log()
Abhilash Laxmeshwarab0bd522019-10-21 15:05:15 +05301089 }
Manjunath Vanarajuluadc57d12019-04-23 11:07:21 +05301090
1091 // Clear the action map
1092 for k := range action {
1093 delete(action, k)
1094 }
1095
Girish Gowdru6a80bbd2019-07-02 07:36:09 -07001096 action[TrapToHost] = true
1097 classifier[UDPSrc] = uint32(68)
1098 classifier[UDPDst] = uint32(67)
1099 classifier[PacketTagType] = SingleTag
Manjunath Vanarajuluadc57d12019-04-23 11:07:21 +05301100
Neha Sharma96b7bf22020-06-15 10:37:32 +00001101 flowStoreCookie := getFlowStoreCookie(ctx, classifier, gemPortID)
npujarec5762e2020-01-01 14:08:48 +05301102 if present := f.resourceMgr.IsFlowCookieOnKVStore(ctx, uint32(intfID), int32(onuID), int32(uniID), flowStoreCookie); present {
Neha Sharma96b7bf22020-06-15 10:37:32 +00001103 logger.Infow(ctx, "flow-exists--not-re-adding",
Shrey Baid26912972020-04-16 21:02:31 +05301104 log.Fields{
1105 "device-id": f.deviceHandler.device.Id,
1106 "intf-id": intfID,
1107 "onu-id": onuID})
David K. Bainbridge794735f2020-02-11 21:01:37 -08001108 return nil
Girish Gowdra3d633032019-12-10 16:37:05 +05301109 }
Manjunath Vanarajuluadc57d12019-04-23 11:07:21 +05301110
David K. Bainbridge794735f2020-02-11 21:01:37 -08001111 flowID, err := f.resourceMgr.GetFlowID(ctx, intfID, int32(onuID), int32(uniID), gemPortID, flowStoreCookie, DhcpFlow, 0 /*classifier[VLAN_PCP].(uint32)*/)
Manjunath Vanarajuluadc57d12019-04-23 11:07:21 +05301112
1113 if err != nil {
Shrey Baid26912972020-04-16 21:02:31 +05301114 return olterrors.NewErrNotFound("flow",
1115 log.Fields{
1116 "interface-id": intfID,
1117 "gem-port": gemPortID,
1118 "cookie": flowStoreCookie,
1119 "device-id": f.deviceHandler.device.Id},
David K. Bainbridge794735f2020-02-11 21:01:37 -08001120 err).Log()
Manjunath Vanarajuluadc57d12019-04-23 11:07:21 +05301121 }
1122
Neha Sharma96b7bf22020-06-15 10:37:32 +00001123 logger.Debugw(ctx, "creating-ul-dhcp-flow",
Shrey Baid26912972020-04-16 21:02:31 +05301124 log.Fields{
1125 "ul_classifier": classifier,
1126 "ul_action": action,
1127 "uplinkFlowId": flowID,
1128 "intf-id": intfID,
1129 "onu-id": onuID,
1130 "device-id": f.deviceHandler.device.Id})
Manjunath Vanarajuluadc57d12019-04-23 11:07:21 +05301131
David K. Bainbridge794735f2020-02-11 21:01:37 -08001132 classifierProto, err := makeOpenOltClassifierField(classifier)
1133 if err != nil {
Thomas Lee S94109f12020-03-03 16:39:29 +05301134 return olterrors.NewErrInvalidValue(log.Fields{"classifier": classifier}, err).Log()
Manjunath Vanarajuluadc57d12019-04-23 11:07:21 +05301135 }
Neha Sharma96b7bf22020-06-15 10:37:32 +00001136 logger.Debugw(ctx, "created-classifier-proto", log.Fields{"classifier": *classifierProto})
Gamze Abaka724d0852020-03-18 12:10:24 +00001137 actionProto, err := makeOpenOltActionField(action, classifier)
David K. Bainbridge794735f2020-02-11 21:01:37 -08001138 if err != nil {
Thomas Lee S94109f12020-03-03 16:39:29 +05301139 return olterrors.NewErrInvalidValue(log.Fields{"action": action}, err).Log()
Manjunath Vanarajuluadc57d12019-04-23 11:07:21 +05301140 }
1141
David K. Bainbridge794735f2020-02-11 21:01:37 -08001142 dhcpFlow := openoltpb2.Flow{AccessIntfId: int32(intfID),
Girish Gowdru6a80bbd2019-07-02 07:36:09 -07001143 OnuId: int32(onuID),
1144 UniId: int32(uniID),
Manjunath Vanarajuluadc57d12019-04-23 11:07:21 +05301145 FlowId: flowID,
David K. Bainbridge82efc492019-09-04 09:57:11 -07001146 FlowType: Upstream,
Girish Gowdru6a80bbd2019-07-02 07:36:09 -07001147 AllocId: int32(allocID),
1148 NetworkIntfId: int32(networkIntfID),
1149 GemportId: int32(gemPortID),
Manjunath Vanarajuluadc57d12019-04-23 11:07:21 +05301150 Classifier: classifierProto,
1151 Action: actionProto,
1152 Priority: int32(logicalFlow.Priority),
1153 Cookie: logicalFlow.Cookie,
Gamze Abaka78a1d2a2020-04-27 10:17:27 +00001154 PortNo: portNo,
1155 TechProfileId: tpID,
1156 }
David K. Bainbridge794735f2020-02-11 21:01:37 -08001157 if err := f.addFlowToDevice(ctx, logicalFlow, &dhcpFlow); err != nil {
Thomas Lee S94109f12020-03-03 16:39:29 +05301158 return olterrors.NewErrFlowOp("add", flowID, log.Fields{"dhcp-flow": dhcpFlow}, err).Log()
David K. Bainbridge794735f2020-02-11 21:01:37 -08001159 }
Neha Sharma96b7bf22020-06-15 10:37:32 +00001160 logger.Infow(ctx, "dhcp-ul-flow-added-to-device-successfully",
Shrey Baid26912972020-04-16 21:02:31 +05301161 log.Fields{
1162 "device-id": f.deviceHandler.device.Id,
1163 "flow-id": flowID,
1164 "intf-id": intfID,
1165 "onu-id": onuID})
David K. Bainbridge794735f2020-02-11 21:01:37 -08001166 flowsToKVStore := f.getUpdatedFlowInfo(ctx, &dhcpFlow, flowStoreCookie, "DHCP", flowID, logicalFlow.Id)
1167 if err := f.updateFlowInfoToKVStore(ctx, dhcpFlow.AccessIntfId,
1168 dhcpFlow.OnuId,
1169 dhcpFlow.UniId,
1170 dhcpFlow.FlowId, flowsToKVStore); err != nil {
Shrey Baid26912972020-04-16 21:02:31 +05301171 return olterrors.NewErrPersistence("update", "flow", dhcpFlow.FlowId,
1172 log.Fields{
1173 "flow": dhcpFlow,
1174 "device-id": f.deviceHandler.device.Id}, err).Log()
Manjunath Vanarajuluadc57d12019-04-23 11:07:21 +05301175 }
1176
David K. Bainbridge794735f2020-02-11 21:01:37 -08001177 return nil
manikkaraj kbf256be2019-03-25 00:13:48 +05301178}
1179
Esin Karamanae41e2b2019-12-17 18:13:13 +00001180//addIGMPTrapFlow creates IGMP trap-to-host flow
npujarec5762e2020-01-01 14:08:48 +05301181func (f *OpenOltFlowMgr) addIGMPTrapFlow(ctx context.Context, intfID uint32, onuID uint32, uniID uint32, portNo uint32, classifier map[string]interface{},
Gamze Abaka78a1d2a2020-04-27 10:17:27 +00001182 action map[string]interface{}, logicalFlow *ofp.OfpFlowStats, allocID uint32, gemPortID uint32, tpID uint32) error {
1183 return f.addUpstreamTrapFlow(ctx, intfID, onuID, uniID, portNo, classifier, action, logicalFlow, allocID, gemPortID, IgmpFlow, tpID)
Esin Karamanae41e2b2019-12-17 18:13:13 +00001184}
1185
1186//addUpstreamTrapFlow creates a trap-to-host flow
npujarec5762e2020-01-01 14:08:48 +05301187func (f *OpenOltFlowMgr) addUpstreamTrapFlow(ctx context.Context, intfID uint32, onuID uint32, uniID uint32, portNo uint32, classifier map[string]interface{},
Gamze Abaka78a1d2a2020-04-27 10:17:27 +00001188 action map[string]interface{}, logicalFlow *ofp.OfpFlowStats, allocID uint32, gemPortID uint32, flowType string, tpID uint32) error {
Esin Karamanae41e2b2019-12-17 18:13:13 +00001189
Neha Sharma96b7bf22020-06-15 10:37:32 +00001190 networkIntfID, err := getNniIntfID(ctx, classifier, action)
Esin Karamanae41e2b2019-12-17 18:13:13 +00001191 if err != nil {
Shrey Baid26912972020-04-16 21:02:31 +05301192 return olterrors.NewErrNotFound("nni-interface-id",
1193 log.Fields{
1194 "classifier": classifier,
1195 "action": action,
1196 "device-id": f.deviceHandler.device.Id},
David K. Bainbridge794735f2020-02-11 21:01:37 -08001197 err).Log()
Esin Karamanae41e2b2019-12-17 18:13:13 +00001198 }
1199
1200 // Clear the action map
1201 for k := range action {
1202 delete(action, k)
1203 }
1204
1205 action[TrapToHost] = true
1206 classifier[PacketTagType] = SingleTag
1207 delete(classifier, VlanVid)
1208
Neha Sharma96b7bf22020-06-15 10:37:32 +00001209 flowStoreCookie := getFlowStoreCookie(ctx, classifier, gemPortID)
npujarec5762e2020-01-01 14:08:48 +05301210 if present := f.resourceMgr.IsFlowCookieOnKVStore(ctx, uint32(networkIntfID), int32(onuID), int32(uniID), flowStoreCookie); present {
Neha Sharma96b7bf22020-06-15 10:37:32 +00001211 logger.Infow(ctx, "flow-exists-not-re-adding", log.Fields{"device-id": f.deviceHandler.device.Id})
David K. Bainbridge794735f2020-02-11 21:01:37 -08001212 return nil
Esin Karamanae41e2b2019-12-17 18:13:13 +00001213 }
1214
npujarec5762e2020-01-01 14:08:48 +05301215 flowID, err := f.resourceMgr.GetFlowID(ctx, intfID, int32(onuID), int32(uniID), gemPortID, flowStoreCookie, flowType, 0, 0 /*classifier[VLAN_PCP].(uint32)*/)
Esin Karamanae41e2b2019-12-17 18:13:13 +00001216
1217 if err != nil {
Shrey Baid26912972020-04-16 21:02:31 +05301218 return olterrors.NewErrNotFound("flow-id",
1219 log.Fields{
1220 "intf-id": intfID,
1221 "oni-id": onuID,
1222 "cookie": flowStoreCookie,
1223 "flow-type": flowType,
1224 "device-id": f.deviceHandler.device.Id,
1225 "onu-id": onuID},
David K. Bainbridge794735f2020-02-11 21:01:37 -08001226 err).Log()
Esin Karamanae41e2b2019-12-17 18:13:13 +00001227 }
1228
Neha Sharma96b7bf22020-06-15 10:37:32 +00001229 logger.Debugw(ctx, "creating-upstream-trap-flow",
Shrey Baid26912972020-04-16 21:02:31 +05301230 log.Fields{
1231 "ul_classifier": classifier,
1232 "ul_action": action,
1233 "uplinkFlowId": flowID,
1234 "flowType": flowType,
1235 "device-id": f.deviceHandler.device.Id,
1236 "intf-id": intfID,
1237 "onu-id": onuID})
Esin Karamanae41e2b2019-12-17 18:13:13 +00001238
David K. Bainbridge794735f2020-02-11 21:01:37 -08001239 classifierProto, err := makeOpenOltClassifierField(classifier)
1240 if err != nil {
Shrey Baid26912972020-04-16 21:02:31 +05301241 return olterrors.NewErrInvalidValue(log.Fields{"classifier": classifier, "device-id": f.deviceHandler.device.Id}, err).Log()
Esin Karamanae41e2b2019-12-17 18:13:13 +00001242 }
Neha Sharma96b7bf22020-06-15 10:37:32 +00001243 logger.Debugw(ctx, "created-classifier-proto",
Shrey Baid26912972020-04-16 21:02:31 +05301244 log.Fields{
1245 "classifier": *classifierProto,
1246 "device-id": f.deviceHandler.device.Id})
Gamze Abaka724d0852020-03-18 12:10:24 +00001247 actionProto, err := makeOpenOltActionField(action, classifier)
David K. Bainbridge794735f2020-02-11 21:01:37 -08001248 if err != nil {
Shrey Baid26912972020-04-16 21:02:31 +05301249 return olterrors.NewErrInvalidValue(log.Fields{"action": action, "device-id": f.deviceHandler.device.Id}, err).Log()
Esin Karamanae41e2b2019-12-17 18:13:13 +00001250 }
1251
David K. Bainbridge794735f2020-02-11 21:01:37 -08001252 flow := openoltpb2.Flow{AccessIntfId: int32(intfID),
Esin Karamanae41e2b2019-12-17 18:13:13 +00001253 OnuId: int32(onuID),
1254 UniId: int32(uniID),
1255 FlowId: flowID,
1256 FlowType: Upstream,
1257 AllocId: int32(allocID),
1258 NetworkIntfId: int32(networkIntfID),
1259 GemportId: int32(gemPortID),
1260 Classifier: classifierProto,
1261 Action: actionProto,
1262 Priority: int32(logicalFlow.Priority),
1263 Cookie: logicalFlow.Cookie,
Gamze Abaka78a1d2a2020-04-27 10:17:27 +00001264 PortNo: portNo,
1265 TechProfileId: tpID,
1266 }
Esin Karamanae41e2b2019-12-17 18:13:13 +00001267
David K. Bainbridge794735f2020-02-11 21:01:37 -08001268 if err := f.addFlowToDevice(ctx, logicalFlow, &flow); err != nil {
Shrey Baid26912972020-04-16 21:02:31 +05301269 return olterrors.NewErrFlowOp("add", flowID, log.Fields{"flow": flow, "device-id": f.deviceHandler.device.Id}, err).Log()
David K. Bainbridge794735f2020-02-11 21:01:37 -08001270 }
Neha Sharma96b7bf22020-06-15 10:37:32 +00001271 logger.Infof(ctx, "%s ul-flow-added-to-device-successfully", flowType)
Esin Karamanae41e2b2019-12-17 18:13:13 +00001272
David K. Bainbridge794735f2020-02-11 21:01:37 -08001273 flowsToKVStore := f.getUpdatedFlowInfo(ctx, &flow, flowStoreCookie, flowType, flowID, logicalFlow.Id)
1274 if err := f.updateFlowInfoToKVStore(ctx, flow.AccessIntfId,
1275 flow.OnuId,
1276 flow.UniId,
1277 flow.FlowId, flowsToKVStore); err != nil {
Shrey Baid26912972020-04-16 21:02:31 +05301278 return olterrors.NewErrPersistence("update", "flow", flow.FlowId, log.Fields{"flow": flow, "device-id": f.deviceHandler.device.Id}, err).Log()
Esin Karamanae41e2b2019-12-17 18:13:13 +00001279 }
1280
David K. Bainbridge794735f2020-02-11 21:01:37 -08001281 return nil
Esin Karamanae41e2b2019-12-17 18:13:13 +00001282}
1283
Girish Gowdru6a80bbd2019-07-02 07:36:09 -07001284// Add EAPOL flow to device with mac, vlanId as classifier for upstream and downstream
Gamze Abaka78a1d2a2020-04-27 10:17:27 +00001285func (f *OpenOltFlowMgr) addEAPOLFlow(ctx context.Context, intfID uint32, onuID uint32, uniID uint32, portNo uint32,
1286 classifier map[string]interface{}, action map[string]interface{}, logicalFlow *ofp.OfpFlowStats, allocID uint32,
1287 gemPortID uint32, vlanID uint32, tpID uint32) error {
Neha Sharma96b7bf22020-06-15 10:37:32 +00001288 logger.Infow(ctx, "adding-eapol-to-device",
Shrey Baid26912972020-04-16 21:02:31 +05301289 log.Fields{
1290 "intf-id": intfID,
1291 "onu-id": onuID,
1292 "port-no": portNo,
1293 "alloc-id": allocID,
1294 "gemport-id": gemPortID,
1295 "vlan-id": vlanID,
1296 "flow": logicalFlow})
manikkaraj kbf256be2019-03-25 00:13:48 +05301297
1298 uplinkClassifier := make(map[string]interface{})
1299 uplinkAction := make(map[string]interface{})
Girish Gowdra3d633032019-12-10 16:37:05 +05301300
manikkaraj kbf256be2019-03-25 00:13:48 +05301301 // Fill Classfier
Girish Gowdru6a80bbd2019-07-02 07:36:09 -07001302 uplinkClassifier[EthType] = uint32(EapEthType)
1303 uplinkClassifier[PacketTagType] = SingleTag
1304 uplinkClassifier[VlanVid] = vlanID
Gamze Abaka724d0852020-03-18 12:10:24 +00001305 uplinkClassifier[VlanPcp] = classifier[VlanPcp]
manikkaraj kbf256be2019-03-25 00:13:48 +05301306 // Fill action
Girish Gowdru6a80bbd2019-07-02 07:36:09 -07001307 uplinkAction[TrapToHost] = true
Neha Sharma96b7bf22020-06-15 10:37:32 +00001308 flowStoreCookie := getFlowStoreCookie(ctx, uplinkClassifier, gemPortID)
npujarec5762e2020-01-01 14:08:48 +05301309 if present := f.resourceMgr.IsFlowCookieOnKVStore(ctx, uint32(intfID), int32(onuID), int32(uniID), flowStoreCookie); present {
Neha Sharma96b7bf22020-06-15 10:37:32 +00001310 logger.Infow(ctx, "flow-exists-not-re-adding", log.Fields{
Shrey Baid26912972020-04-16 21:02:31 +05301311 "device-id": f.deviceHandler.device.Id,
1312 "onu-id": onuID,
1313 "intf-id": intfID})
David K. Bainbridge794735f2020-02-11 21:01:37 -08001314 return nil
Girish Gowdra3d633032019-12-10 16:37:05 +05301315 }
manikkaraj kbf256be2019-03-25 00:13:48 +05301316 //Add Uplink EAPOL Flow
Gamze Abaka724d0852020-03-18 12:10:24 +00001317 uplinkFlowID, err := f.resourceMgr.GetFlowID(ctx, intfID, int32(onuID), int32(uniID), gemPortID, flowStoreCookie, "", 0, 0)
manikkaraj kbf256be2019-03-25 00:13:48 +05301318 if err != nil {
Shrey Baid26912972020-04-16 21:02:31 +05301319 return olterrors.NewErrNotFound("flow-id",
1320 log.Fields{
1321 "intf-id": intfID,
1322 "onu-id": onuID,
1323 "coookie": flowStoreCookie,
1324 "device-id": f.deviceHandler.device.Id},
David K. Bainbridge794735f2020-02-11 21:01:37 -08001325 err).Log()
manikkaraj kbf256be2019-03-25 00:13:48 +05301326 }
Neha Sharma96b7bf22020-06-15 10:37:32 +00001327 logger.Debugw(ctx, "creating-ul-eapol-flow",
Shrey Baid26912972020-04-16 21:02:31 +05301328 log.Fields{
1329 "ul_classifier": uplinkClassifier,
1330 "ul_action": uplinkAction,
1331 "uplinkFlowId": uplinkFlowID,
1332 "device-id": f.deviceHandler.device.Id,
1333 "intf-id": intfID,
1334 "onu-id": onuID})
manikkaraj kbf256be2019-03-25 00:13:48 +05301335
David K. Bainbridge794735f2020-02-11 21:01:37 -08001336 classifierProto, err := makeOpenOltClassifierField(uplinkClassifier)
1337 if err != nil {
Shrey Baid26912972020-04-16 21:02:31 +05301338 return olterrors.NewErrInvalidValue(log.Fields{
1339 "classifier": uplinkClassifier,
1340 "device-id": f.deviceHandler.device.Id}, err).Log()
manikkaraj kbf256be2019-03-25 00:13:48 +05301341 }
Neha Sharma96b7bf22020-06-15 10:37:32 +00001342 logger.Debugw(ctx, "created-classifier-proto",
Shrey Baid26912972020-04-16 21:02:31 +05301343 log.Fields{
1344 "classifier": *classifierProto,
1345 "device-id": f.deviceHandler.device.Id})
Gamze Abaka724d0852020-03-18 12:10:24 +00001346 actionProto, err := makeOpenOltActionField(uplinkAction, uplinkClassifier)
David K. Bainbridge794735f2020-02-11 21:01:37 -08001347 if err != nil {
Shrey Baid26912972020-04-16 21:02:31 +05301348 return olterrors.NewErrInvalidValue(log.Fields{"action": uplinkAction, "device-id": f.deviceHandler.device.Id}, err).Log()
manikkaraj kbf256be2019-03-25 00:13:48 +05301349 }
Neha Sharma96b7bf22020-06-15 10:37:32 +00001350 logger.Debugw(ctx, "created-action-proto",
Shrey Baid26912972020-04-16 21:02:31 +05301351 log.Fields{
1352 "action": *actionProto,
1353 "device-id": f.deviceHandler.device.Id})
Neha Sharma96b7bf22020-06-15 10:37:32 +00001354 networkIntfID, err := getNniIntfID(ctx, classifier, action)
Abhilash Laxmeshwarab0bd522019-10-21 15:05:15 +05301355 if err != nil {
Thomas Lee S94109f12020-03-03 16:39:29 +05301356 return olterrors.NewErrNotFound("nni-interface-id", log.Fields{
David K. Bainbridge794735f2020-02-11 21:01:37 -08001357 "classifier": classifier,
Shrey Baid26912972020-04-16 21:02:31 +05301358 "action": action,
1359 "device-id": f.deviceHandler.device.Id},
David K. Bainbridge794735f2020-02-11 21:01:37 -08001360 err).Log()
Abhilash Laxmeshwarab0bd522019-10-21 15:05:15 +05301361 }
1362
David K. Bainbridge794735f2020-02-11 21:01:37 -08001363 upstreamFlow := openoltpb2.Flow{AccessIntfId: int32(intfID),
Girish Gowdru6a80bbd2019-07-02 07:36:09 -07001364 OnuId: int32(onuID),
1365 UniId: int32(uniID),
1366 FlowId: uplinkFlowID,
David K. Bainbridge82efc492019-09-04 09:57:11 -07001367 FlowType: Upstream,
Girish Gowdru6a80bbd2019-07-02 07:36:09 -07001368 AllocId: int32(allocID),
1369 NetworkIntfId: int32(networkIntfID),
1370 GemportId: int32(gemPortID),
manikkaraj kbf256be2019-03-25 00:13:48 +05301371 Classifier: classifierProto,
1372 Action: actionProto,
1373 Priority: int32(logicalFlow.Priority),
1374 Cookie: logicalFlow.Cookie,
Gamze Abaka78a1d2a2020-04-27 10:17:27 +00001375 PortNo: portNo,
1376 TechProfileId: tpID,
1377 }
David K. Bainbridge794735f2020-02-11 21:01:37 -08001378 if err := f.addFlowToDevice(ctx, logicalFlow, &upstreamFlow); err != nil {
Thomas Lee S94109f12020-03-03 16:39:29 +05301379 return olterrors.NewErrFlowOp("add", uplinkFlowID, log.Fields{"flow": upstreamFlow}, err).Log()
David K. Bainbridge794735f2020-02-11 21:01:37 -08001380 }
Neha Sharma96b7bf22020-06-15 10:37:32 +00001381 logger.Infow(ctx, "eapol-ul-flow-added-to-device-successfully",
Shrey Baid26912972020-04-16 21:02:31 +05301382 log.Fields{
1383 "device-id": f.deviceHandler.device.Id,
1384 "onu-id": onuID,
1385 "intf-id": intfID,
1386 })
David K. Bainbridge794735f2020-02-11 21:01:37 -08001387 flowCategory := "EAPOL"
1388 flowsToKVStore := f.getUpdatedFlowInfo(ctx, &upstreamFlow, flowStoreCookie, flowCategory, uplinkFlowID, logicalFlow.Id)
1389 if err := f.updateFlowInfoToKVStore(ctx, upstreamFlow.AccessIntfId,
1390 upstreamFlow.OnuId,
1391 upstreamFlow.UniId,
1392 upstreamFlow.FlowId,
1393 /* lowCategory, */
1394 flowsToKVStore); err != nil {
Shrey Baid26912972020-04-16 21:02:31 +05301395 return olterrors.NewErrPersistence("update", "flow", upstreamFlow.FlowId,
1396 log.Fields{
1397 "flow": upstreamFlow,
1398 "device-id": f.deviceHandler.device.Id}, err).Log()
manikkaraj kbf256be2019-03-25 00:13:48 +05301399 }
David K. Bainbridge794735f2020-02-11 21:01:37 -08001400 return nil
manikkaraj kbf256be2019-03-25 00:13:48 +05301401}
1402
David K. Bainbridge794735f2020-02-11 21:01:37 -08001403func makeOpenOltClassifierField(classifierInfo map[string]interface{}) (*openoltpb2.Classifier, error) {
Girish Gowdru6a80bbd2019-07-02 07:36:09 -07001404 var classifier openoltpb2.Classifier
David K. Bainbridge82efc492019-09-04 09:57:11 -07001405
1406 classifier.EthType, _ = classifierInfo[EthType].(uint32)
1407 classifier.IpProto, _ = classifierInfo[IPProto].(uint32)
1408 if vlanID, ok := classifierInfo[VlanVid].(uint32); ok {
Andrea Campanella7acc0b92020-02-14 09:20:49 +01001409 if vlanID != ReservedVlan {
1410 vid := vlanID & VlanvIDMask
Harsh Awasthiea45af72019-08-26 02:39:00 -04001411 classifier.OVid = vid
1412 }
manikkaraj kbf256be2019-03-25 00:13:48 +05301413 }
David K. Bainbridge82efc492019-09-04 09:57:11 -07001414 if metadata, ok := classifierInfo[Metadata].(uint64); ok {
1415 vid := uint32(metadata)
1416 if vid != ReservedVlan {
Harsh Awasthiea45af72019-08-26 02:39:00 -04001417 classifier.IVid = vid
1418 }
manikkaraj kbf256be2019-03-25 00:13:48 +05301419 }
Girish Gowdrafae935c2020-02-17 19:21:44 +05301420 // Use VlanPCPMask (0xff) to signify NO PCP. Else use valid PCP (0 to 7)
David K. Bainbridge82efc492019-09-04 09:57:11 -07001421 if vlanPcp, ok := classifierInfo[VlanPcp].(uint32); ok {
Girish Gowdrafae935c2020-02-17 19:21:44 +05301422 classifier.OPbits = vlanPcp
1423 } else {
1424 classifier.OPbits = VlanPCPMask
manikkaraj kbf256be2019-03-25 00:13:48 +05301425 }
David K. Bainbridge82efc492019-09-04 09:57:11 -07001426 classifier.SrcPort, _ = classifierInfo[UDPSrc].(uint32)
1427 classifier.DstPort, _ = classifierInfo[UDPDst].(uint32)
1428 classifier.DstIp, _ = classifierInfo[Ipv4Dst].(uint32)
1429 classifier.SrcIp, _ = classifierInfo[Ipv4Src].(uint32)
Esin Karamanccb714b2019-11-29 15:02:06 +00001430 classifier.DstMac, _ = classifierInfo[EthDst].([]uint8)
David K. Bainbridge82efc492019-09-04 09:57:11 -07001431 if pktTagType, ok := classifierInfo[PacketTagType].(string); ok {
1432 classifier.PktTagType = pktTagType
1433
1434 switch pktTagType {
1435 case SingleTag:
1436 case DoubleTag:
1437 case Untagged:
1438 default:
Girish Kumarf26e4882020-03-05 06:49:10 +00001439 return nil, olterrors.NewErrInvalidValue(log.Fields{"packet-tag-type": pktTagType}, nil)
manikkaraj kbf256be2019-03-25 00:13:48 +05301440 }
1441 }
David K. Bainbridge794735f2020-02-11 21:01:37 -08001442 return &classifier, nil
manikkaraj kbf256be2019-03-25 00:13:48 +05301443}
1444
Gamze Abaka724d0852020-03-18 12:10:24 +00001445func makeOpenOltActionField(actionInfo map[string]interface{}, classifierInfo map[string]interface{}) (*openoltpb2.Action, error) {
Girish Gowdru6a80bbd2019-07-02 07:36:09 -07001446 var actionCmd openoltpb2.ActionCmd
1447 var action openoltpb2.Action
manikkaraj kbf256be2019-03-25 00:13:48 +05301448 action.Cmd = &actionCmd
Girish Gowdru6a80bbd2019-07-02 07:36:09 -07001449 if _, ok := actionInfo[PopVlan]; ok {
manikkaraj kbf256be2019-03-25 00:13:48 +05301450 action.Cmd.RemoveOuterTag = true
Gamze Abaka724d0852020-03-18 12:10:24 +00001451 if _, ok := actionInfo[VlanPcp]; ok {
1452 action.Cmd.RemarkInnerPbits = true
1453 action.IPbits = actionInfo[VlanPcp].(uint32)
1454 if _, ok := actionInfo[VlanVid]; ok {
1455 action.Cmd.TranslateInnerTag = true
1456 action.IVid = actionInfo[VlanVid].(uint32)
1457 }
1458 }
Girish Gowdru6a80bbd2019-07-02 07:36:09 -07001459 } else if _, ok := actionInfo[PushVlan]; ok {
1460 action.OVid = actionInfo[VlanVid].(uint32)
manikkaraj kbf256be2019-03-25 00:13:48 +05301461 action.Cmd.AddOuterTag = true
Gamze Abaka724d0852020-03-18 12:10:24 +00001462 if _, ok := actionInfo[VlanPcp]; ok {
1463 action.OPbits = actionInfo[VlanPcp].(uint32)
1464 action.Cmd.RemarkOuterPbits = true
1465 if _, ok := classifierInfo[VlanVid]; ok {
1466 action.IVid = classifierInfo[VlanVid].(uint32)
1467 action.Cmd.TranslateInnerTag = true
1468 }
1469 }
Girish Gowdru6a80bbd2019-07-02 07:36:09 -07001470 } else if _, ok := actionInfo[TrapToHost]; ok {
1471 action.Cmd.TrapToHost = actionInfo[TrapToHost].(bool)
manikkaraj kbf256be2019-03-25 00:13:48 +05301472 } else {
Girish Kumarf26e4882020-03-05 06:49:10 +00001473 return nil, olterrors.NewErrInvalidValue(log.Fields{"action-command": actionInfo}, nil)
manikkaraj kbf256be2019-03-25 00:13:48 +05301474 }
David K. Bainbridge794735f2020-02-11 21:01:37 -08001475 return &action, nil
manikkaraj kbf256be2019-03-25 00:13:48 +05301476}
1477
Matteo Scandolod625b4c2020-04-02 16:16:01 -07001478// getTPpath return the ETCD path for a given UNI port
Neha Sharma96b7bf22020-06-15 10:37:32 +00001479func (f *OpenOltFlowMgr) getTPpath(ctx context.Context, intfID uint32, uniPath string, TpID uint32) string {
1480 return f.techprofile[intfID].GetTechProfileInstanceKVPath(ctx, TpID, uniPath)
manikkaraj kbf256be2019-03-25 00:13:48 +05301481}
1482
Gamze Abakafee36392019-10-03 11:17:24 +00001483// DeleteTechProfileInstances removes the tech profile instances from persistent storage
npujarec5762e2020-01-01 14:08:48 +05301484func (f *OpenOltFlowMgr) DeleteTechProfileInstances(ctx context.Context, intfID uint32, onuID uint32, uniID uint32, sn string) error {
1485 tpIDList := f.resourceMgr.GetTechProfileIDForOnu(ctx, intfID, onuID, uniID)
Matteo Scandolod625b4c2020-04-02 16:16:01 -07001486 uniPortName := getUniPortPath(f.deviceHandler.device.Id, intfID, int32(onuID), int32(uniID))
1487
Gamze Abakafee36392019-10-03 11:17:24 +00001488 for _, tpID := range tpIDList {
npujarec5762e2020-01-01 14:08:48 +05301489 if err := f.DeleteTechProfileInstance(ctx, intfID, onuID, uniID, uniPortName, tpID); err != nil {
Kent Hagermane6ff1012020-07-14 15:07:53 -04001490 _ = olterrors.NewErrAdapter("delete-tech-profile-failed", log.Fields{"device-id": f.deviceHandler.device.Id}, err).Log()
Girish Gowdra54934262019-11-13 14:19:55 +05301491 // return err
1492 // We should continue to delete tech-profile instances for other TP IDs
Gamze Abakafee36392019-10-03 11:17:24 +00001493 }
Girish Kumara1ea2aa2020-08-19 18:14:22 +00001494 logger.Debugw(ctx, "tech-profile-deleted", log.Fields{"device-id": f.deviceHandler.device.Id, "tp-id": tpID})
Gamze Abakafee36392019-10-03 11:17:24 +00001495 }
1496 return nil
1497}
1498
1499// DeleteTechProfileInstance removes the tech profile instance from persistent storage
npujarec5762e2020-01-01 14:08:48 +05301500func (f *OpenOltFlowMgr) DeleteTechProfileInstance(ctx context.Context, intfID uint32, onuID uint32, uniID uint32, uniPortName string, tpID uint32) error {
Gamze Abakafee36392019-10-03 11:17:24 +00001501 if uniPortName == "" {
Matteo Scandolod625b4c2020-04-02 16:16:01 -07001502 uniPortName = getUniPortPath(f.deviceHandler.device.Id, intfID, int32(onuID), int32(uniID))
Gamze Abakafee36392019-10-03 11:17:24 +00001503 }
npujarec5762e2020-01-01 14:08:48 +05301504 if err := f.techprofile[intfID].DeleteTechProfileInstance(ctx, tpID, uniPortName); err != nil {
Shrey Baid26912972020-04-16 21:02:31 +05301505 return olterrors.NewErrAdapter("failed-to-delete-tp-instance-from-kv-store",
1506 log.Fields{
1507 "tp-id": tpID,
1508 "uni-port-name": uniPortName,
1509 "device-id": f.deviceHandler.device.Id}, err)
Devmalya Paul495b94a2019-08-27 19:42:00 -04001510 }
1511 return nil
1512}
1513
Neha Sharma96b7bf22020-06-15 10:37:32 +00001514func getFlowStoreCookie(ctx context.Context, classifier map[string]interface{}, gemPortID uint32) uint64 {
manikkaraj kbf256be2019-03-25 00:13:48 +05301515 if len(classifier) == 0 { // should never happen
Neha Sharma96b7bf22020-06-15 10:37:32 +00001516 logger.Error(ctx, "invalid-classfier-object")
manikkaraj kbf256be2019-03-25 00:13:48 +05301517 return 0
1518 }
Neha Sharma96b7bf22020-06-15 10:37:32 +00001519 logger.Debugw(ctx, "generating-flow-store-cookie",
Shrey Baid26912972020-04-16 21:02:31 +05301520 log.Fields{
1521 "classifier": classifier,
1522 "gemport-id": gemPortID})
manikkaraj kbf256be2019-03-25 00:13:48 +05301523 var jsonData []byte
1524 var flowString string
1525 var err error
1526 // TODO: Do we need to marshall ??
1527 if jsonData, err = json.Marshal(classifier); err != nil {
Neha Sharma96b7bf22020-06-15 10:37:32 +00001528 logger.Error(ctx, "failed-to-encode-classifier")
manikkaraj kbf256be2019-03-25 00:13:48 +05301529 return 0
1530 }
1531 flowString = string(jsonData)
Girish Gowdru6a80bbd2019-07-02 07:36:09 -07001532 if gemPortID != 0 {
1533 flowString = fmt.Sprintf("%s%s", string(jsonData), string(gemPortID))
manikkaraj kbf256be2019-03-25 00:13:48 +05301534 }
1535 h := md5.New()
Girish Gowdru6a80bbd2019-07-02 07:36:09 -07001536 _, _ = h.Write([]byte(flowString))
manikkaraj kbf256be2019-03-25 00:13:48 +05301537 hash := big.NewInt(0)
1538 hash.SetBytes(h.Sum(nil))
Girish Gowdra3d633032019-12-10 16:37:05 +05301539 generatedHash := hash.Uint64()
Neha Sharma96b7bf22020-06-15 10:37:32 +00001540 logger.Debugw(ctx, "hash-generated", log.Fields{"hash": generatedHash})
Girish Gowdra3d633032019-12-10 16:37:05 +05301541 return generatedHash
manikkaraj kbf256be2019-03-25 00:13:48 +05301542}
1543
npujarec5762e2020-01-01 14:08:48 +05301544func (f *OpenOltFlowMgr) getUpdatedFlowInfo(ctx context.Context, flow *openoltpb2.Flow, flowStoreCookie uint64, flowCategory string, deviceFlowID uint32, logicalFlowID uint64) *[]rsrcMgr.FlowInfo {
Abhilash Laxmeshwarab0bd522019-10-21 15:05:15 +05301545 var flows = []rsrcMgr.FlowInfo{{Flow: flow, FlowCategory: flowCategory, FlowStoreCookie: flowStoreCookie, LogicalFlowID: logicalFlowID}}
Girish Gowdru6a80bbd2019-07-02 07:36:09 -07001546 var intfID uint32
manikkaraj k9eb6cac2019-05-09 12:32:03 -04001547 /* For flows which trap out of the NNI, the AccessIntfId is invalid
1548 (set to -1). In such cases, we need to refer to the NetworkIntfId .
1549 */
1550 if flow.AccessIntfId != -1 {
Girish Gowdru6a80bbd2019-07-02 07:36:09 -07001551 intfID = uint32(flow.AccessIntfId)
manikkaraj k9eb6cac2019-05-09 12:32:03 -04001552 } else {
Girish Gowdru6a80bbd2019-07-02 07:36:09 -07001553 intfID = uint32(flow.NetworkIntfId)
manikkaraj k9eb6cac2019-05-09 12:32:03 -04001554 }
Girish Gowdru6a80bbd2019-07-02 07:36:09 -07001555 // Get existing flows matching flowid for given subscriber from KV store
npujarec5762e2020-01-01 14:08:48 +05301556 existingFlows := f.resourceMgr.GetFlowIDInfo(ctx, intfID, flow.OnuId, flow.UniId, flow.FlowId)
manikkaraj k17652a72019-05-06 09:06:36 -04001557 if existingFlows != nil {
Neha Sharma96b7bf22020-06-15 10:37:32 +00001558 logger.Debugw(ctx, "flow-exists-for-given-flowID--appending-it-to-current-flow",
Shrey Baid26912972020-04-16 21:02:31 +05301559 log.Fields{
1560 "flow-id": flow.FlowId,
1561 "device-id": f.deviceHandler.device.Id,
1562 "intf-id": intfID,
1563 "onu-id": flow.OnuId})
Girish Gowdru6a80bbd2019-07-02 07:36:09 -07001564 //for _, f := range *existingFlows {
1565 // flows = append(flows, f)
1566 //}
1567 flows = append(flows, *existingFlows...)
manikkaraj k17652a72019-05-06 09:06:36 -04001568 }
Neha Sharma96b7bf22020-06-15 10:37:32 +00001569 logger.Debugw(ctx, "updated-flows-for-given-flowID-and-onuid",
Shrey Baid26912972020-04-16 21:02:31 +05301570 log.Fields{
1571 "updatedflow": flows,
1572 "flow-id": flow.FlowId,
1573 "onu-id": flow.OnuId,
1574 "device-id": f.deviceHandler.device.Id})
manikkaraj kbf256be2019-03-25 00:13:48 +05301575 return &flows
1576}
1577
npujarec5762e2020-01-01 14:08:48 +05301578func (f *OpenOltFlowMgr) updateFlowInfoToKVStore(ctx context.Context, intfID int32, onuID int32, uniID int32, flowID uint32, flows *[]rsrcMgr.FlowInfo) error {
Neha Sharma96b7bf22020-06-15 10:37:32 +00001579 logger.Debugw(ctx, "storing-flow(s)-into-kv-store", log.Fields{
Shrey Baid26912972020-04-16 21:02:31 +05301580 "flow-id": flowID,
1581 "device-id": f.deviceHandler.device.Id,
1582 "intf-id": intfID,
1583 "onu-id": onuID})
npujarec5762e2020-01-01 14:08:48 +05301584 if err := f.resourceMgr.UpdateFlowIDInfo(ctx, intfID, onuID, uniID, flowID, flows); err != nil {
Neha Sharma96b7bf22020-06-15 10:37:32 +00001585 logger.Warnw(ctx, "error-while-storing-flow-into-kv-store", log.Fields{
Shrey Baid26912972020-04-16 21:02:31 +05301586 "device-id": f.deviceHandler.device.Id,
1587 "onu-id": onuID,
1588 "intf-id": intfID,
1589 "flow-id": flowID})
manikkaraj k17652a72019-05-06 09:06:36 -04001590 return err
1591 }
Neha Sharma96b7bf22020-06-15 10:37:32 +00001592 logger.Infow(ctx, "stored-flow(s)-into-kv-store-successfully!", log.Fields{
Shrey Baid26912972020-04-16 21:02:31 +05301593 "device-id": f.deviceHandler.device.Id,
1594 "onu-id": onuID,
1595 "intf-id": intfID,
1596 "flow-id": flowID})
manikkaraj kbf256be2019-03-25 00:13:48 +05301597 return nil
1598}
1599
David K. Bainbridge794735f2020-02-11 21:01:37 -08001600func (f *OpenOltFlowMgr) addFlowToDevice(ctx context.Context, logicalFlow *ofp.OfpFlowStats, deviceFlow *openoltpb2.Flow) error {
Daniele Rossi22db98e2019-07-11 11:50:00 +00001601
1602 var intfID uint32
1603 /* For flows which trap out of the NNI, the AccessIntfId is invalid
1604 (set to -1). In such cases, we need to refer to the NetworkIntfId .
1605 */
1606 if deviceFlow.AccessIntfId != -1 {
1607 intfID = uint32(deviceFlow.AccessIntfId)
1608 } else {
Manikkaraj kb1d51442019-07-23 10:41:02 -04001609 // REVIST : Why ponport is given as network port?
Daniele Rossi22db98e2019-07-11 11:50:00 +00001610 intfID = uint32(deviceFlow.NetworkIntfId)
1611 }
1612
Neha Sharma96b7bf22020-06-15 10:37:32 +00001613 logger.Debugw(ctx, "sending-flow-to-device-via-grpc", log.Fields{
Shrey Baid26912972020-04-16 21:02:31 +05301614 "flow": *deviceFlow,
1615 "device-id": f.deviceHandler.device.Id,
1616 "intf-id": intfID})
Neha Sharma8f4e4322020-08-06 10:51:53 +00001617 _, err := f.deviceHandler.Client.FlowAdd(log.WithSpanFromContext(context.Background(), ctx), deviceFlow)
Daniele Rossi22db98e2019-07-11 11:50:00 +00001618
1619 st, _ := status.FromError(err)
1620 if st.Code() == codes.AlreadyExists {
Neha Sharma96b7bf22020-06-15 10:37:32 +00001621 logger.Debug(ctx, "flow-already-exists", log.Fields{
Matteo Scandolod625b4c2020-04-02 16:16:01 -07001622 "err": err,
1623 "deviceFlow": deviceFlow,
Shrey Baid26912972020-04-16 21:02:31 +05301624 "device-id": f.deviceHandler.device.Id,
1625 "intf-id": intfID})
David K. Bainbridge794735f2020-02-11 21:01:37 -08001626 return nil
manikkaraj kbf256be2019-03-25 00:13:48 +05301627 }
Daniele Rossi22db98e2019-07-11 11:50:00 +00001628
1629 if err != nil {
Neha Sharma96b7bf22020-06-15 10:37:32 +00001630 logger.Errorw(ctx, "failed-to-add-flow-to-device",
Shrey Baid26912972020-04-16 21:02:31 +05301631 log.Fields{"err": err,
1632 "device-flow": deviceFlow,
1633 "device-id": f.deviceHandler.device.Id,
1634 "intf-id": intfID})
npujarec5762e2020-01-01 14:08:48 +05301635 f.resourceMgr.FreeFlowID(ctx, intfID, deviceFlow.OnuId, deviceFlow.UniId, deviceFlow.FlowId)
David K. Bainbridge794735f2020-02-11 21:01:37 -08001636 return err
Daniele Rossi22db98e2019-07-11 11:50:00 +00001637 }
Abhilash Laxmeshwar6d1acb92020-01-17 15:43:03 +05301638 if deviceFlow.GemportId != -1 {
1639 // No need to register the flow if it is a trap on nni flow.
Kent Hagermane6ff1012020-07-14 15:07:53 -04001640 if err := f.registerFlow(ctx, logicalFlow, deviceFlow); err != nil {
1641 logger.Errorw(ctx, "failed-to-register-flow", log.Fields{"err": err})
1642 return err
1643 }
Abhilash Laxmeshwar6d1acb92020-01-17 15:43:03 +05301644 }
Neha Sharma96b7bf22020-06-15 10:37:32 +00001645 logger.Infow(ctx, "flow-added-to-device-successfully ",
Shrey Baid26912972020-04-16 21:02:31 +05301646 log.Fields{
1647 "flow": *deviceFlow,
1648 "device-id": f.deviceHandler.device.Id,
1649 "intf-id": intfID})
David K. Bainbridge794735f2020-02-11 21:01:37 -08001650 return nil
Manjunath Vanarajulu28c3e822019-05-16 11:14:28 -04001651}
1652
Neha Sharma96b7bf22020-06-15 10:37:32 +00001653func (f *OpenOltFlowMgr) removeFlowFromDevice(ctx context.Context, deviceFlow *openoltpb2.Flow, ofFlowID uint64) error {
1654 logger.Debugw(ctx, "sending-flow-to-device-via-grpc",
Shrey Baid26912972020-04-16 21:02:31 +05301655 log.Fields{
1656 "flow": *deviceFlow,
1657 "device-id": f.deviceHandler.device.Id})
Neha Sharma8f4e4322020-08-06 10:51:53 +00001658 _, err := f.deviceHandler.Client.FlowRemove(log.WithSpanFromContext(context.Background(), ctx), deviceFlow)
Manjunath Vanarajulu28c3e822019-05-16 11:14:28 -04001659 if err != nil {
serkant.uluderya245caba2019-09-24 23:15:29 -07001660 if f.deviceHandler.device.ConnectStatus == common.ConnectStatus_UNREACHABLE {
Neha Sharma96b7bf22020-06-15 10:37:32 +00001661 logger.Warnw(ctx, "can-not-remove-flow-from-device--unreachable",
Shrey Baid26912972020-04-16 21:02:31 +05301662 log.Fields{
1663 "err": err,
1664 "deviceFlow": deviceFlow,
1665 "device-id": f.deviceHandler.device.Id})
serkant.uluderya245caba2019-09-24 23:15:29 -07001666 //Assume the flow is removed
David K. Bainbridge794735f2020-02-11 21:01:37 -08001667 return nil
serkant.uluderya245caba2019-09-24 23:15:29 -07001668 }
Girish Kumarf26e4882020-03-05 06:49:10 +00001669 return olterrors.NewErrFlowOp("remove", deviceFlow.FlowId, log.Fields{"deviceFlow": deviceFlow}, err)
serkant.uluderya245caba2019-09-24 23:15:29 -07001670
Manjunath Vanarajulu28c3e822019-05-16 11:14:28 -04001671 }
Neha Sharma96b7bf22020-06-15 10:37:32 +00001672 logger.Infow(ctx, "flow-removed-from-device-successfully", log.Fields{
Matteo Scandolo92186242020-06-12 10:54:18 -07001673 "of-flow-id": ofFlowID,
1674 "flow": *deviceFlow,
1675 "device-id": f.deviceHandler.device.Id,
1676 })
David K. Bainbridge794735f2020-02-11 21:01:37 -08001677 return nil
manikkaraj kbf256be2019-03-25 00:13:48 +05301678}
1679
David K. Bainbridge794735f2020-02-11 21:01:37 -08001680func (f *OpenOltFlowMgr) addLLDPFlow(ctx context.Context, flow *ofp.OfpFlowStats, portNo uint32) error {
Humera Kouser94d7a842019-08-25 19:04:32 -04001681
1682 classifierInfo := make(map[string]interface{})
1683 actionInfo := make(map[string]interface{})
1684
1685 classifierInfo[EthType] = uint32(LldpEthType)
1686 classifierInfo[PacketTagType] = Untagged
1687 actionInfo[TrapToHost] = true
1688
1689 // LLDP flow is installed to trap LLDP packets on the NNI port.
1690 // We manage flow_id resource pool on per PON port basis.
1691 // Since this situation is tricky, as a hack, we pass the NNI port
1692 // index (network_intf_id) as PON port Index for the flow_id resource
1693 // pool. Also, there is no ONU Id available for trapping LLDP packets
1694 // on NNI port, use onu_id as -1 (invalid)
1695 // ****************** CAVEAT *******************
1696 // This logic works if the NNI Port Id falls within the same valid
1697 // range of PON Port Ids. If this doesn't work for some OLT Vendor
1698 // we need to have a re-look at this.
1699 // *********************************************
1700
1701 var onuID = -1
1702 var uniID = -1
1703 var gemPortID = -1
1704
Neha Sharma96b7bf22020-06-15 10:37:32 +00001705 networkInterfaceID, err := IntfIDFromNniPortNum(ctx, portNo)
David K. Bainbridge794735f2020-02-11 21:01:37 -08001706 if err != nil {
Thomas Lee S94109f12020-03-03 16:39:29 +05301707 return olterrors.NewErrInvalidValue(log.Fields{"nni-port-number": portNo}, err).Log()
David K. Bainbridge794735f2020-02-11 21:01:37 -08001708 }
Neha Sharma96b7bf22020-06-15 10:37:32 +00001709 var flowStoreCookie = getFlowStoreCookie(ctx, classifierInfo, uint32(0))
npujarec5762e2020-01-01 14:08:48 +05301710 if present := f.resourceMgr.IsFlowCookieOnKVStore(ctx, uint32(networkInterfaceID), int32(onuID), int32(uniID), flowStoreCookie); present {
Neha Sharma96b7bf22020-06-15 10:37:32 +00001711 logger.Infow(ctx, "flow-exists--not-re-adding", log.Fields{"device-id": f.deviceHandler.device.Id})
David K. Bainbridge794735f2020-02-11 21:01:37 -08001712 return nil
Humera Kouser94d7a842019-08-25 19:04:32 -04001713 }
npujarec5762e2020-01-01 14:08:48 +05301714 flowID, err := f.resourceMgr.GetFlowID(ctx, uint32(networkInterfaceID), int32(onuID), int32(uniID), uint32(gemPortID), flowStoreCookie, "", 0)
Humera Kouser94d7a842019-08-25 19:04:32 -04001715
1716 if err != nil {
Shrey Baid26912972020-04-16 21:02:31 +05301717 return olterrors.NewErrNotFound("flow-id",
1718 log.Fields{
1719 "interface-id": networkInterfaceID,
1720 "onu-id": onuID,
1721 "uni-id": uniID,
1722 "gem-port-id": gemPortID,
1723 "cookie": flowStoreCookie,
1724 "device-id": f.deviceHandler.device.Id},
Girish Kumarf26e4882020-03-05 06:49:10 +00001725 err)
Humera Kouser94d7a842019-08-25 19:04:32 -04001726 }
David K. Bainbridge794735f2020-02-11 21:01:37 -08001727 classifierProto, err := makeOpenOltClassifierField(classifierInfo)
1728 if err != nil {
Shrey Baid26912972020-04-16 21:02:31 +05301729 return olterrors.NewErrInvalidValue(
1730 log.Fields{
1731 "classifier": classifierInfo,
1732 "device-id": f.deviceHandler.device.Id}, err)
Humera Kouser94d7a842019-08-25 19:04:32 -04001733 }
Neha Sharma96b7bf22020-06-15 10:37:32 +00001734 logger.Debugw(ctx, "created-classifier-proto",
Shrey Baid26912972020-04-16 21:02:31 +05301735 log.Fields{
1736 "classifier": *classifierProto,
1737 "device-id": f.deviceHandler.device.Id})
Gamze Abaka724d0852020-03-18 12:10:24 +00001738 actionProto, err := makeOpenOltActionField(actionInfo, classifierInfo)
David K. Bainbridge794735f2020-02-11 21:01:37 -08001739 if err != nil {
Shrey Baid26912972020-04-16 21:02:31 +05301740 return olterrors.NewErrInvalidValue(
1741 log.Fields{
1742 "action": actionInfo,
1743 "device-id": f.deviceHandler.device.Id}, err)
Humera Kouser94d7a842019-08-25 19:04:32 -04001744 }
Neha Sharma96b7bf22020-06-15 10:37:32 +00001745 logger.Debugw(ctx, "created-action-proto",
Shrey Baid26912972020-04-16 21:02:31 +05301746 log.Fields{
1747 "action": *actionProto,
1748 "device-id": f.deviceHandler.device.Id})
Humera Kouser94d7a842019-08-25 19:04:32 -04001749
1750 downstreamflow := openoltpb2.Flow{AccessIntfId: int32(-1), // AccessIntfId not required
1751 OnuId: int32(onuID), // OnuId not required
1752 UniId: int32(uniID), // UniId not used
1753 FlowId: flowID,
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. Bainbridge794735f2020-02-11 21:01:37 -08001762 if err := f.addFlowToDevice(ctx, flow, &downstreamflow); err != nil {
Shrey Baid26912972020-04-16 21:02:31 +05301763 return olterrors.NewErrFlowOp("add", flowID,
1764 log.Fields{
1765 "flow": downstreamflow,
1766 "device-id": f.deviceHandler.device.Id}, err)
Humera Kouser94d7a842019-08-25 19:04:32 -04001767 }
Neha Sharma96b7bf22020-06-15 10:37:32 +00001768 logger.Infow(ctx, "lldp-trap-on-nni-flow-added-to-device-successfully",
Shrey Baid26912972020-04-16 21:02:31 +05301769 log.Fields{
1770 "device-id": f.deviceHandler.device.Id,
1771 "onu-id": onuID,
1772 "flow-id": flowID})
David K. Bainbridge794735f2020-02-11 21:01:37 -08001773 flowsToKVStore := f.getUpdatedFlowInfo(ctx, &downstreamflow, flowStoreCookie, "", flowID, flow.Id)
1774 if err := f.updateFlowInfoToKVStore(ctx, int32(networkInterfaceID),
1775 int32(onuID),
1776 int32(uniID),
1777 flowID, flowsToKVStore); err != nil {
Shrey Baid26912972020-04-16 21:02:31 +05301778 return olterrors.NewErrPersistence("update", "flow", flowID,
1779 log.Fields{
1780 "flow": downstreamflow,
1781 "device-id": f.deviceHandler.device.Id}, err)
David K. Bainbridge794735f2020-02-11 21:01:37 -08001782 }
1783 return nil
manikkaraj kbf256be2019-03-25 00:13:48 +05301784}
1785
Matteo Scandolod625b4c2020-04-02 16:16:01 -07001786func getUniPortPath(oltID string, intfID uint32, onuID int32, uniID int32) string {
1787 return fmt.Sprintf("olt-{%s}/pon-{%d}/onu-{%d}/uni-{%d}", oltID, intfID, onuID, uniID)
Girish Gowdru6a80bbd2019-07-02 07:36:09 -07001788}
1789
Mahir Gunyel0f89fd22020-04-11 18:24:42 -07001790//getOnuDevice to fetch onu from cache or core.
Neha Sharma96b7bf22020-06-15 10:37:32 +00001791func (f *OpenOltFlowMgr) getOnuDevice(ctx context.Context, intfID uint32, onuID uint32) (*OnuDevice, error) {
Mahir Gunyel0f89fd22020-04-11 18:24:42 -07001792 onuKey := f.deviceHandler.formOnuKey(intfID, onuID)
1793 onuDev, ok := f.deviceHandler.onus.Load(onuKey)
1794 if !ok {
Neha Sharma96b7bf22020-06-15 10:37:32 +00001795 logger.Debugw(ctx, "couldnt-find-onu-in-cache",
Shrey Baid26912972020-04-16 21:02:31 +05301796 log.Fields{
1797 "intf-id": intfID,
1798 "onu-id": onuID,
1799 "device-id": f.deviceHandler.device.Id})
Neha Sharma96b7bf22020-06-15 10:37:32 +00001800 onuDevice, err := f.getChildDevice(ctx, intfID, onuID)
Mahir Gunyel0f89fd22020-04-11 18:24:42 -07001801 if err != nil {
Shrey Baid26912972020-04-16 21:02:31 +05301802 return nil, olterrors.NewErrNotFound("onu-child-device",
1803 log.Fields{
1804 "onu-id": onuID,
1805 "intf-id": intfID,
1806 "device-id": f.deviceHandler.device.Id}, err)
Mahir Gunyel0f89fd22020-04-11 18:24:42 -07001807 }
1808 onuDev = NewOnuDevice(onuDevice.Id, onuDevice.Type, onuDevice.SerialNumber, onuDevice.ProxyAddress.OnuId, onuDevice.ProxyAddress.ChannelId, onuDevice.ProxyAddress.DeviceId, false)
1809 //better to ad the device to cache here.
1810 f.deviceHandler.StoreOnuDevice(onuDev.(*OnuDevice))
1811 } else {
Neha Sharma96b7bf22020-06-15 10:37:32 +00001812 logger.Debugw(ctx, "found-onu-in-cache",
Shrey Baid26912972020-04-16 21:02:31 +05301813 log.Fields{
1814 "intf-id": intfID,
1815 "onu-id": onuID,
1816 "device-id": f.deviceHandler.device.Id})
Mahir Gunyel0f89fd22020-04-11 18:24:42 -07001817 }
1818
1819 return onuDev.(*OnuDevice), nil
1820}
1821
1822//getChildDevice to fetch onu
Neha Sharma96b7bf22020-06-15 10:37:32 +00001823func (f *OpenOltFlowMgr) getChildDevice(ctx context.Context, intfID uint32, onuID uint32) (*voltha.Device, error) {
1824 logger.Infow(ctx, "GetChildDevice",
Shrey Baid26912972020-04-16 21:02:31 +05301825 log.Fields{
1826 "pon-port": intfID,
1827 "onu-id": onuID,
1828 "device-id": f.deviceHandler.device.Id})
Girish Gowdru6a80bbd2019-07-02 07:36:09 -07001829 parentPortNo := IntfIDToPortNo(intfID, voltha.Port_PON_OLT)
Neha Sharma96b7bf22020-06-15 10:37:32 +00001830 onuDevice, err := f.deviceHandler.GetChildDevice(ctx, parentPortNo, onuID)
David K. Bainbridge794735f2020-02-11 21:01:37 -08001831 if err != nil {
Shrey Baid26912972020-04-16 21:02:31 +05301832 return nil, olterrors.NewErrNotFound("onu",
1833 log.Fields{
1834 "interface-id": parentPortNo,
1835 "onu-id": onuID,
1836 "device-id": f.deviceHandler.device.Id},
Girish Kumarf26e4882020-03-05 06:49:10 +00001837 err)
manikkaraj kbf256be2019-03-25 00:13:48 +05301838 }
Neha Sharma96b7bf22020-06-15 10:37:32 +00001839 logger.Infow(ctx, "successfully-received-child-device-from-core",
Shrey Baid26912972020-04-16 21:02:31 +05301840 log.Fields{
1841 "device-id": f.deviceHandler.device.Id,
1842 "child_device_id": onuDevice.Id,
1843 "child_device_sn": onuDevice.SerialNumber})
Manikkaraj k884c1242019-04-11 16:26:42 +05301844 return onuDevice, nil
manikkaraj kbf256be2019-03-25 00:13:48 +05301845}
1846
Neha Sharma96b7bf22020-06-15 10:37:32 +00001847func (f *OpenOltFlowMgr) sendDeleteGemPortToChild(ctx context.Context, intfID uint32, onuID uint32, uniID uint32, gemPortID uint32, tpPath string) error {
1848 onuDev, err := f.getOnuDevice(ctx, intfID, onuID)
Girish Gowdra6b130582019-11-20 16:45:20 +05301849 if err != nil {
Neha Sharma96b7bf22020-06-15 10:37:32 +00001850 logger.Debugw(ctx, "couldnt-find-onu-child-device",
Shrey Baid26912972020-04-16 21:02:31 +05301851 log.Fields{
1852 "intf-id": intfID,
1853 "onu-id": onuID,
1854 "uni-id": uniID,
1855 "device-id": f.deviceHandler.device.Id})
Mahir Gunyel0f89fd22020-04-11 18:24:42 -07001856 return err
Girish Gowdra6b130582019-11-20 16:45:20 +05301857 }
1858
1859 delGemPortMsg := &ic.InterAdapterDeleteGemPortMessage{UniId: uniID, TpPath: tpPath, GemPortId: gemPortID}
Neha Sharma96b7bf22020-06-15 10:37:32 +00001860 logger.Debugw(ctx, "sending-gem-port-delete-to-openonu-adapter",
Shrey Baid26912972020-04-16 21:02:31 +05301861 log.Fields{
1862 "msg": *delGemPortMsg,
1863 "device-id": f.deviceHandler.device.Id})
Neha Sharma8f4e4322020-08-06 10:51:53 +00001864 if sendErr := f.deviceHandler.AdapterProxy.SendInterAdapterMessage(log.WithSpanFromContext(context.Background(), ctx),
Girish Gowdra6b130582019-11-20 16:45:20 +05301865 delGemPortMsg,
1866 ic.InterAdapterMessageType_DELETE_GEM_PORT_REQUEST,
Thomas Lee S985938d2020-05-04 11:40:41 +05301867 f.deviceHandler.device.Type,
Mahir Gunyel0f89fd22020-04-11 18:24:42 -07001868 onuDev.deviceType,
1869 onuDev.deviceID,
1870 onuDev.proxyDeviceID, ""); sendErr != nil {
Shrey Baid26912972020-04-16 21:02:31 +05301871 return olterrors.NewErrCommunication("send-delete-gem-port-to-onu-adapter",
1872 log.Fields{
1873 "from-adapter": f.deviceHandler.device.Type,
1874 "to-adapter": onuDev.deviceType,
1875 "onu-id": onuDev.deviceID,
1876 "proxyDeviceID": onuDev.proxyDeviceID,
1877 "device-id": f.deviceHandler.device.Id}, sendErr)
Girish Gowdra6b130582019-11-20 16:45:20 +05301878 }
Neha Sharma96b7bf22020-06-15 10:37:32 +00001879 logger.Infow(ctx, "success-sending-del-gem-port-to-onu-adapter",
Shrey Baid26912972020-04-16 21:02:31 +05301880 log.Fields{
1881 "msg": delGemPortMsg,
1882 "from-adapter": f.deviceHandler.device.Type,
1883 "to-adapter": onuDev.deviceType,
1884 "device-id": f.deviceHandler.device.Id})
Girish Gowdra6b130582019-11-20 16:45:20 +05301885 return nil
1886}
1887
Neha Sharma96b7bf22020-06-15 10:37:32 +00001888func (f *OpenOltFlowMgr) sendDeleteTcontToChild(ctx context.Context, intfID uint32, onuID uint32, uniID uint32, allocID uint32, tpPath string) error {
1889 onuDev, err := f.getOnuDevice(ctx, intfID, onuID)
Girish Gowdra6b130582019-11-20 16:45:20 +05301890 if err != nil {
Neha Sharma96b7bf22020-06-15 10:37:32 +00001891 logger.Warnw(ctx, "couldnt-find-onu-child-device",
Shrey Baid26912972020-04-16 21:02:31 +05301892 log.Fields{
1893 "intf-id": intfID,
1894 "onu-id": onuID,
1895 "uni-id": uniID,
1896 "device-id": f.deviceHandler.device.Id})
Mahir Gunyel0f89fd22020-04-11 18:24:42 -07001897 return err
Girish Gowdra6b130582019-11-20 16:45:20 +05301898 }
1899
1900 delTcontMsg := &ic.InterAdapterDeleteTcontMessage{UniId: uniID, TpPath: tpPath, AllocId: allocID}
Neha Sharma96b7bf22020-06-15 10:37:32 +00001901 logger.Debugw(ctx, "sending-tcont-delete-to-openonu-adapter",
Shrey Baid26912972020-04-16 21:02:31 +05301902 log.Fields{
1903 "msg": *delTcontMsg,
1904 "device-id": f.deviceHandler.device.Id})
Neha Sharma8f4e4322020-08-06 10:51:53 +00001905 if sendErr := f.deviceHandler.AdapterProxy.SendInterAdapterMessage(log.WithSpanFromContext(context.Background(), ctx),
Girish Gowdra6b130582019-11-20 16:45:20 +05301906 delTcontMsg,
1907 ic.InterAdapterMessageType_DELETE_TCONT_REQUEST,
Thomas Lee S985938d2020-05-04 11:40:41 +05301908 f.deviceHandler.device.Type,
Mahir Gunyel0f89fd22020-04-11 18:24:42 -07001909 onuDev.deviceType,
1910 onuDev.deviceID,
1911 onuDev.proxyDeviceID, ""); sendErr != nil {
Shrey Baid26912972020-04-16 21:02:31 +05301912 return olterrors.NewErrCommunication("send-delete-tcont-to-onu-adapter",
1913 log.Fields{
1914 "from-adapter": f.deviceHandler.device.Type,
1915 "to-adapter": onuDev.deviceType, "onu-id": onuDev.deviceID,
1916 "proxyDeviceID": onuDev.proxyDeviceID,
1917 "device-id": f.deviceHandler.device.Id}, sendErr)
Girish Gowdra6b130582019-11-20 16:45:20 +05301918 }
Neha Sharma96b7bf22020-06-15 10:37:32 +00001919 logger.Infow(ctx, "success-sending-del-tcont-to-onu-adapter",
Shrey Baid26912972020-04-16 21:02:31 +05301920 log.Fields{
1921 "msg": delTcontMsg,
1922 "device-id": f.deviceHandler.device.Id})
Girish Gowdra6b130582019-11-20 16:45:20 +05301923 return nil
1924}
1925
Neha Sharma96b7bf22020-06-15 10:37:32 +00001926func (f *OpenOltFlowMgr) deletePendingFlows(ctx context.Context, Intf uint32, onuID int32, uniID int32) {
Girish Gowdra3d633032019-12-10 16:37:05 +05301927 pnFlDelKey := pendingFlowDeleteKey{Intf, uint32(onuID), uint32(uniID)}
1928 if val, ok := f.pendingFlowDelete.Load(pnFlDelKey); ok {
1929 if val.(int) > 0 {
1930 pnFlDels := val.(int) - 1
1931 if pnFlDels > 0 {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000