blob: cf5cbae3c04de9fa2259e66299276f2fcd2a2f64 [file] [log] [blame]
Girish Gowdra64503432020-01-07 10:59:10 +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
17package core
18
19import (
20 "errors"
Girish Gowdrad4bdd372020-03-09 14:56:15 -070021 "strings"
Thiyagarajan Subramanib83b0432020-01-08 13:43:28 +053022
Girish Gowdra64503432020-01-07 10:59:10 +053023 "github.com/opencord/openolt-scale-tester/config"
Orhan Kupusoglu66b00d82020-03-13 12:06:33 +030024 "github.com/opencord/voltha-lib-go/v3/pkg/log"
25 "github.com/opencord/voltha-lib-go/v3/pkg/ponresourcemanager"
26 oop "github.com/opencord/voltha-protos/v3/go/openolt"
27 tp_pb "github.com/opencord/voltha-protos/v3/go/tech_profile"
Girish Gowdra64503432020-01-07 10:59:10 +053028 "golang.org/x/net/context"
29 "google.golang.org/grpc/codes"
30 "google.golang.org/grpc/status"
31)
32
33func init() {
34 _, _ = log.AddPackage(log.JSON, log.DebugLevel, nil)
35}
36
37// A dummy struct to comply with the WorkFlow interface.
38type AttWorkFlow struct {
39}
40
Girish Gowdraef1b7c42020-01-23 16:27:48 +053041func AddDhcpIPV4Flow(oo oop.OpenoltClient, config *config.OpenOltScaleTesterConfig, rsrMgr *OpenOltResourceMgr) error {
Girish Gowdra64503432020-01-07 10:59:10 +053042 var flowID []uint32
43 var err error
44
Orhan Kupusoglu66b00d82020-03-13 12:06:33 +030045 if flowID, err = rsrMgr.ResourceMgrs[uint32(config.NniIntfID)].GetResourceID(context.Background(), uint32(config.NniIntfID),
Girish Gowdra64503432020-01-07 10:59:10 +053046 ponresourcemanager.FLOW_ID, 1); err != nil {
47 return err
48 }
49
Girish Gowdraef1b7c42020-01-23 16:27:48 +053050 // DHCP IPV4
Girish Gowdra64503432020-01-07 10:59:10 +053051 flowClassifier := &oop.Classifier{EthType: 2048, IpProto: 17, SrcPort: 67, DstPort: 68, PktTagType: "double_tag"}
52 actionCmd := &oop.ActionCmd{TrapToHost: true}
53 actionInfo := &oop.Action{Cmd: actionCmd}
54
55 flow := oop.Flow{AccessIntfId: -1, OnuId: -1, UniId: -1, FlowId: flowID[0],
56 FlowType: "downstream", AllocId: -1, GemportId: -1,
57 Classifier: flowClassifier, Action: actionInfo,
Girish Gowdraef1b7c42020-01-23 16:27:48 +053058 Priority: 1000, PortNo: uint32(config.NniIntfID)}
Girish Gowdra64503432020-01-07 10:59:10 +053059
60 _, err = oo.FlowAdd(context.Background(), &flow)
61
62 st, _ := status.FromError(err)
63 if st.Code() == codes.AlreadyExists {
64 log.Debugw("Flow already exists", log.Fields{"err": err, "deviceFlow": flow})
65 return nil
66 }
67
68 if err != nil {
Girish Gowdraef1b7c42020-01-23 16:27:48 +053069 log.Errorw("Failed to Add DHCP IPv4 to device", log.Fields{"err": err, "deviceFlow": flow})
Orhan Kupusoglu66b00d82020-03-13 12:06:33 +030070 rsrMgr.ResourceMgrs[uint32(config.NniIntfID)].FreeResourceID(context.Background(), uint32(config.NniIntfID),
Thiyagarajan Subramanib83b0432020-01-08 13:43:28 +053071 ponresourcemanager.FLOW_ID, flowID)
Girish Gowdra64503432020-01-07 10:59:10 +053072 return err
73 }
Girish Gowdraef1b7c42020-01-23 16:27:48 +053074 log.Debugw("DHCP IPV4 added to device successfully ", log.Fields{"flow": flow})
75
76 return nil
77}
78
79func AddDhcpIPV6Flow(oo oop.OpenoltClient, config *config.OpenOltScaleTesterConfig, rsrMgr *OpenOltResourceMgr) error {
80 var flowID []uint32
81 var err error
82
Orhan Kupusoglu66b00d82020-03-13 12:06:33 +030083 if flowID, err = rsrMgr.ResourceMgrs[uint32(config.NniIntfID)].GetResourceID(context.Background(), uint32(config.NniIntfID),
Girish Gowdraef1b7c42020-01-23 16:27:48 +053084 ponresourcemanager.FLOW_ID, 1); err != nil {
85 return err
86 }
87
88 // DHCP IPV6
89 flowClassifier := &oop.Classifier{EthType: 34525, IpProto: 17, SrcPort: 546, DstPort: 547, PktTagType: "double_tag"}
90 actionCmd := &oop.ActionCmd{TrapToHost: true}
91 actionInfo := &oop.Action{Cmd: actionCmd}
92
93 flow := oop.Flow{AccessIntfId: -1, OnuId: -1, UniId: -1, FlowId: flowID[0],
94 FlowType: "downstream", AllocId: -1, GemportId: -1,
95 Classifier: flowClassifier, Action: actionInfo,
96 Priority: 1000, PortNo: uint32(config.NniIntfID)}
97
98 _, err = oo.FlowAdd(context.Background(), &flow)
99
100 st, _ := status.FromError(err)
101 if st.Code() == codes.AlreadyExists {
102 log.Debugw("Flow already exists", log.Fields{"err": err, "deviceFlow": flow})
103 return nil
104 }
105
106 if err != nil {
107 log.Errorw("Failed to Add DHCP IPV6 to device", log.Fields{"err": err, "deviceFlow": flow})
Orhan Kupusoglu66b00d82020-03-13 12:06:33 +0300108 rsrMgr.ResourceMgrs[uint32(config.NniIntfID)].FreeResourceID(context.Background(), uint32(config.NniIntfID),
Girish Gowdraef1b7c42020-01-23 16:27:48 +0530109 ponresourcemanager.FLOW_ID, flowID)
110 return err
111 }
112 log.Debugw("DHCP IPV6 added to device successfully ", log.Fields{"flow": flow})
113
114 return nil
115}
116
Girish Gowdraef1b7c42020-01-23 16:27:48 +0530117func ProvisionAttNniTrapFlow(oo oop.OpenoltClient, config *config.OpenOltScaleTesterConfig, rsrMgr *OpenOltResourceMgr) error {
118 _ = AddDhcpIPV4Flow(oo, config, rsrMgr)
119 _ = AddDhcpIPV6Flow(oo, config, rsrMgr)
120 _ = AddLldpFlow(oo, config, rsrMgr)
Girish Gowdra64503432020-01-07 10:59:10 +0530121
122 return nil
123}
124
Girish Gowdra64503432020-01-07 10:59:10 +0530125func (att AttWorkFlow) ProvisionScheds(subs *Subscriber) error {
126 var trafficSched []*tp_pb.TrafficScheduler
127
128 log.Info("provisioning-scheds")
129
130 if trafficSched = getTrafficSched(subs, tp_pb.Direction_DOWNSTREAM); trafficSched == nil {
131 log.Error("ds-traffic-sched-is-nil")
132 return errors.New(ReasonCodeToReasonString(SCHED_CREATION_FAILED))
133 }
134
135 log.Debugw("Sending Traffic scheduler create to device",
136 log.Fields{"Direction": tp_pb.Direction_DOWNSTREAM, "TrafficScheds": trafficSched})
137 if _, err := subs.OpenOltClient.CreateTrafficSchedulers(context.Background(), &tp_pb.TrafficSchedulers{
138 IntfId: subs.PonIntf, OnuId: subs.OnuID,
139 UniId: subs.UniID, PortNo: subs.UniPortNo,
140 TrafficScheds: trafficSched}); err != nil {
141 log.Errorw("Failed to create traffic schedulers", log.Fields{"error": err})
142 return errors.New(ReasonCodeToReasonString(SCHED_CREATION_FAILED))
143 }
144
145 if trafficSched = getTrafficSched(subs, tp_pb.Direction_UPSTREAM); trafficSched == nil {
146 log.Error("us-traffic-sched-is-nil")
147 return errors.New(ReasonCodeToReasonString(SCHED_CREATION_FAILED))
148 }
149
150 log.Debugw("Sending Traffic scheduler create to device",
151 log.Fields{"Direction": tp_pb.Direction_UPSTREAM, "TrafficScheds": trafficSched})
152 if _, err := subs.OpenOltClient.CreateTrafficSchedulers(context.Background(), &tp_pb.TrafficSchedulers{
153 IntfId: subs.PonIntf, OnuId: subs.OnuID,
154 UniId: subs.UniID, PortNo: subs.UniPortNo,
155 TrafficScheds: trafficSched}); err != nil {
156 log.Errorw("Failed to create traffic schedulers", log.Fields{"error": err})
157 return errors.New(ReasonCodeToReasonString(SCHED_CREATION_FAILED))
158 }
159
160 return nil
161}
162
Girish Gowdra64503432020-01-07 10:59:10 +0530163func (att AttWorkFlow) ProvisionQueues(subs *Subscriber) error {
164 log.Info("provisioning-queues")
165
166 var trafficQueues []*tp_pb.TrafficQueue
167 if trafficQueues = getTrafficQueues(subs, tp_pb.Direction_DOWNSTREAM); trafficQueues == nil {
168 log.Error("Failed to create traffic queues")
169 return errors.New(ReasonCodeToReasonString(QUEUE_CREATION_FAILED))
170 }
171
172 // On receiving the CreateTrafficQueues request, the driver should create corresponding
173 // downstream queues.
174 log.Debugw("Sending Traffic Queues create to device",
175 log.Fields{"Direction": tp_pb.Direction_DOWNSTREAM, "TrafficQueues": trafficQueues})
176 if _, err := subs.OpenOltClient.CreateTrafficQueues(context.Background(),
177 &tp_pb.TrafficQueues{IntfId: subs.PonIntf, OnuId: subs.OnuID,
178 UniId: subs.UniID, PortNo: subs.UniPortNo,
179 TrafficQueues: trafficQueues}); err != nil {
180 log.Errorw("Failed to create traffic queues in device", log.Fields{"error": err})
181 return errors.New(ReasonCodeToReasonString(QUEUE_CREATION_FAILED))
182 }
183
184 if trafficQueues = getTrafficQueues(subs, tp_pb.Direction_UPSTREAM); trafficQueues == nil {
185 log.Error("Failed to create traffic queues")
186 return errors.New(ReasonCodeToReasonString(QUEUE_CREATION_FAILED))
187 }
188
189 // On receiving the CreateTrafficQueues request, the driver should create corresponding
190 // upstream queues.
191 log.Debugw("Sending Traffic Queues create to device",
192 log.Fields{"Direction": tp_pb.Direction_UPSTREAM, "TrafficQueues": trafficQueues})
193 if _, err := subs.OpenOltClient.CreateTrafficQueues(context.Background(),
194 &tp_pb.TrafficQueues{IntfId: subs.PonIntf, OnuId: subs.OnuID,
195 UniId: subs.UniID, PortNo: subs.UniPortNo,
196 TrafficQueues: trafficQueues}); err != nil {
197 log.Errorw("Failed to create traffic queues in device", log.Fields{"error": err})
198 return errors.New(ReasonCodeToReasonString(QUEUE_CREATION_FAILED))
199 }
200
201 return nil
202}
203
204func (att AttWorkFlow) ProvisionEapFlow(subs *Subscriber) error {
Girish Gowdra64503432020-01-07 10:59:10 +0530205 var err error
206 var flowID []uint32
207 var gemPortIDs []uint32
208
209 var allocID = subs.TpInstance[subs.TestConfig.TpIDList[0]].UsScheduler.AllocID
Girish Gowdra64503432020-01-07 10:59:10 +0530210 for _, gem := range subs.TpInstance[subs.TestConfig.TpIDList[0]].UpstreamGemPortAttributeList {
211 gemPortIDs = append(gemPortIDs, gem.GemportID)
212 }
213
Girish Gowdrad4bdd372020-03-09 14:56:15 -0700214 for idx, gemID := range gemPortIDs {
215 pBitMap := subs.TpInstance[subs.TestConfig.TpIDList[0]].UpstreamGemPortAttributeList[idx].PbitMap
216 for pos, pbitSet := range strings.TrimPrefix(pBitMap, "0b") {
217 if pbitSet == '1' {
218 pcp := uint32(len(strings.TrimPrefix(pBitMap, "0b"))) - 1 - uint32(pos)
Orhan Kupusoglu66b00d82020-03-13 12:06:33 +0300219 if flowID, err = subs.RsrMgr.ResourceMgrs[uint32(subs.PonIntf)].GetResourceID(context.Background(), uint32(subs.PonIntf),
Girish Gowdrad4bdd372020-03-09 14:56:15 -0700220 ponresourcemanager.FLOW_ID, 1); err != nil {
221 return errors.New(ReasonCodeToReasonString(FLOW_ID_GENERATION_FAILED))
222 } else {
223 if err := AddFlow(subs, EapolFlow, Upstream, flowID[0], allocID, gemID, pcp); err != nil {
Orhan Kupusoglu66b00d82020-03-13 12:06:33 +0300224 subs.RsrMgr.ResourceMgrs[uint32(subs.PonIntf)].FreeResourceID(context.Background(), uint32(subs.PonIntf),
Girish Gowdrad4bdd372020-03-09 14:56:15 -0700225 ponresourcemanager.FLOW_ID, flowID)
226 return err
227 }
228 }
Thiyagarajan Subramanib83b0432020-01-08 13:43:28 +0530229 }
Girish Gowdra64503432020-01-07 10:59:10 +0530230 }
Girish Gowdra64503432020-01-07 10:59:10 +0530231 }
232 return nil
233}
234
Girish Gowdraef1b7c42020-01-23 16:27:48 +0530235func (att AttWorkFlow) ProvisionDhcpIPV4Flow(subs *Subscriber) error {
Thiyagarajan Subramanib83b0432020-01-08 13:43:28 +0530236 var err error
237 var flowID []uint32
238 var gemPortIDs []uint32
239
240 var allocID = subs.TpInstance[subs.TestConfig.TpIDList[0]].UsScheduler.AllocID
241 for _, gem := range subs.TpInstance[subs.TestConfig.TpIDList[0]].UpstreamGemPortAttributeList {
242 gemPortIDs = append(gemPortIDs, gem.GemportID)
243 }
244
Girish Gowdrad4bdd372020-03-09 14:56:15 -0700245 for idx, gemID := range gemPortIDs {
246 pBitMap := subs.TpInstance[subs.TestConfig.TpIDList[0]].UpstreamGemPortAttributeList[idx].PbitMap
247 for pos, pbitSet := range strings.TrimPrefix(pBitMap, "0b") {
248 if pbitSet == '1' {
249 pcp := uint32(len(strings.TrimPrefix(pBitMap, "0b"))) - 1 - uint32(pos)
Orhan Kupusoglu66b00d82020-03-13 12:06:33 +0300250 if flowID, err = subs.RsrMgr.ResourceMgrs[uint32(subs.PonIntf)].GetResourceID(context.Background(), uint32(subs.PonIntf),
Girish Gowdrad4bdd372020-03-09 14:56:15 -0700251 ponresourcemanager.FLOW_ID, 1); err != nil {
252 return errors.New(ReasonCodeToReasonString(FLOW_ID_GENERATION_FAILED))
253 } else {
254 if err := AddFlow(subs, DhcpFlowIPV4, Upstream, flowID[0], allocID, gemID, pcp); err != nil {
Orhan Kupusoglu66b00d82020-03-13 12:06:33 +0300255 subs.RsrMgr.ResourceMgrs[uint32(subs.PonIntf)].FreeResourceID(context.Background(), uint32(subs.PonIntf),
Girish Gowdrad4bdd372020-03-09 14:56:15 -0700256 ponresourcemanager.FLOW_ID, flowID)
257 return err
258 }
259 }
Girish Gowdraef1b7c42020-01-23 16:27:48 +0530260 }
261 }
262 }
263 return nil
264}
265
266func (att AttWorkFlow) ProvisionDhcpIPV6Flow(subs *Subscriber) error {
267 var err error
268 var flowID []uint32
269 var gemPortIDs []uint32
270
271 var allocID = subs.TpInstance[subs.TestConfig.TpIDList[0]].UsScheduler.AllocID
272 for _, gem := range subs.TpInstance[subs.TestConfig.TpIDList[0]].UpstreamGemPortAttributeList {
273 gemPortIDs = append(gemPortIDs, gem.GemportID)
274 }
275
Girish Gowdrad4bdd372020-03-09 14:56:15 -0700276 for idx, gemID := range gemPortIDs {
277 pBitMap := subs.TpInstance[subs.TestConfig.TpIDList[0]].UpstreamGemPortAttributeList[idx].PbitMap
278 for pos, pbitSet := range strings.TrimPrefix(pBitMap, "0b") {
279 if pbitSet == '1' {
280 pcp := uint32(len(strings.TrimPrefix(pBitMap, "0b"))) - 1 - uint32(pos)
Orhan Kupusoglu66b00d82020-03-13 12:06:33 +0300281 if flowID, err = subs.RsrMgr.ResourceMgrs[uint32(subs.PonIntf)].GetResourceID(context.Background(), uint32(subs.PonIntf),
Girish Gowdrad4bdd372020-03-09 14:56:15 -0700282 ponresourcemanager.FLOW_ID, 1); err != nil {
283 return errors.New(ReasonCodeToReasonString(FLOW_ID_GENERATION_FAILED))
284 } else {
285 if err := AddFlow(subs, DhcpFlowIPV6, Upstream, flowID[0], allocID, gemID, pcp); err != nil {
Orhan Kupusoglu66b00d82020-03-13 12:06:33 +0300286 subs.RsrMgr.ResourceMgrs[uint32(subs.PonIntf)].FreeResourceID(context.Background(), uint32(subs.PonIntf),
Girish Gowdrad4bdd372020-03-09 14:56:15 -0700287 ponresourcemanager.FLOW_ID, flowID)
288 return err
289 }
290 }
Thiyagarajan Subramanib83b0432020-01-08 13:43:28 +0530291 }
292 }
293 }
Girish Gowdra64503432020-01-07 10:59:10 +0530294 return nil
295}
296
297func (att AttWorkFlow) ProvisionIgmpFlow(subs *Subscriber) error {
298 log.Info("att-workflow-does-not-support-igmp-yet--nothing-to-do")
299 return nil
300}
301
302func (att AttWorkFlow) ProvisionHsiaFlow(subs *Subscriber) error {
Thiyagarajan Subramanib83b0432020-01-08 13:43:28 +0530303 var err error
304 var flowID []uint32
305 var gemPortIDs []uint32
306
307 var allocID = subs.TpInstance[subs.TestConfig.TpIDList[0]].UsScheduler.AllocID
308 for _, gem := range subs.TpInstance[subs.TestConfig.TpIDList[0]].UpstreamGemPortAttributeList {
309 gemPortIDs = append(gemPortIDs, gem.GemportID)
310 }
311
Girish Gowdrad4bdd372020-03-09 14:56:15 -0700312 for idx, gemID := range gemPortIDs {
313 pBitMap := subs.TpInstance[subs.TestConfig.TpIDList[0]].UpstreamGemPortAttributeList[idx].PbitMap
314 for pos, pbitSet := range strings.TrimPrefix(pBitMap, "0b") {
315 if pbitSet == '1' {
316 pcp := uint32(len(strings.TrimPrefix(pBitMap, "0b"))) - 1 - uint32(pos)
Orhan Kupusoglu66b00d82020-03-13 12:06:33 +0300317 if flowID, err = subs.RsrMgr.ResourceMgrs[uint32(subs.PonIntf)].GetResourceID(context.Background(), uint32(subs.PonIntf),
Girish Gowdrad4bdd372020-03-09 14:56:15 -0700318 ponresourcemanager.FLOW_ID, 1); err != nil {
319 return errors.New(ReasonCodeToReasonString(FLOW_ID_GENERATION_FAILED))
320 } else {
321 var errUs, errDs error
322 if errUs = AddFlow(subs, HsiaFlow, Upstream, flowID[0], allocID, gemID, pcp); errUs != nil {
323 log.Errorw("failed to install US HSIA flow",
324 log.Fields{"onuID": subs.OnuID, "uniID": subs.UniID, "intf": subs.PonIntf})
325 }
326 if errDs = AddFlow(subs, HsiaFlow, Downstream, flowID[0], allocID, gemID, pcp); errDs != nil {
327 log.Errorw("failed to install US HSIA flow",
328 log.Fields{"onuID": subs.OnuID, "uniID": subs.UniID, "intf": subs.PonIntf})
329 }
330 if errUs != nil && errDs != nil {
Orhan Kupusoglu66b00d82020-03-13 12:06:33 +0300331 subs.RsrMgr.ResourceMgrs[uint32(subs.PonIntf)].FreeResourceID(context.Background(), uint32(subs.PonIntf),
Girish Gowdrad4bdd372020-03-09 14:56:15 -0700332 ponresourcemanager.FLOW_ID, flowID)
333 }
334 if errUs != nil || errDs != nil {
335 if errUs != nil {
336 return errUs
337 }
338 return errDs
339 }
Girish Gowdraef1b7c42020-01-23 16:27:48 +0530340 }
Thiyagarajan Subramanib83b0432020-01-08 13:43:28 +0530341 }
342 }
343 }
Girish Gowdra64503432020-01-07 10:59:10 +0530344 return nil
345}
Orhan Kupusoglu66b00d82020-03-13 12:06:33 +0300346
347func (att AttWorkFlow) ProvisionVoipFlow(subs *Subscriber) error {
348 log.Info("att-workflow-does-not-support-voip-yet--nothing-to-do")
349 return nil
350}
351
352func (att AttWorkFlow) ProvisionVodFlow(subs *Subscriber) error {
353 log.Info("att-workflow-does-not-support-vod-yet--nothing-to-do")
354 return nil
355}
356
357func (att AttWorkFlow) ProvisionMgmtFlow(subs *Subscriber) error {
358 log.Info("att-workflow-does-not-support-mgmt-yet--nothing-to-do")
359 return nil
360}
361
362func (att AttWorkFlow) ProvisionMulticastFlow(subs *Subscriber) error {
363 log.Info("att-workflow-does-not-support-multicast-yet--nothing-to-do")
364 return nil
365}