blob: f673ee0c8df0c074c6606425ff49acb1c63e876b [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"
Orhan Kupusoglu66b00d82020-03-13 12:06:33 +030025 oop "github.com/opencord/voltha-protos/v3/go/openolt"
26 tp_pb "github.com/opencord/voltha-protos/v3/go/tech_profile"
Girish Gowdra64503432020-01-07 10:59:10 +053027 "golang.org/x/net/context"
28 "google.golang.org/grpc/codes"
29 "google.golang.org/grpc/status"
30)
31
32func init() {
33 _, _ = log.AddPackage(log.JSON, log.DebugLevel, nil)
34}
35
36// A dummy struct to comply with the WorkFlow interface.
37type AttWorkFlow struct {
38}
39
Girish Gowdraef1b7c42020-01-23 16:27:48 +053040func AddDhcpIPV4Flow(oo oop.OpenoltClient, config *config.OpenOltScaleTesterConfig, rsrMgr *OpenOltResourceMgr) error {
Girish Gowdraaeceb842020-08-21 12:10:39 -070041 var flowID uint32
Girish Gowdra64503432020-01-07 10:59:10 +053042 var err error
43
Girish Gowdraaeceb842020-08-21 12:10:39 -070044 if flowID, err = rsrMgr.GetFlowID(context.Background(), uint32(config.NniIntfID)); err != nil {
Girish Gowdra64503432020-01-07 10:59:10 +053045 return err
46 }
47
Girish Gowdraef1b7c42020-01-23 16:27:48 +053048 // DHCP IPV4
Girish Gowdra64503432020-01-07 10:59:10 +053049 flowClassifier := &oop.Classifier{EthType: 2048, IpProto: 17, SrcPort: 67, DstPort: 68, PktTagType: "double_tag"}
50 actionCmd := &oop.ActionCmd{TrapToHost: true}
51 actionInfo := &oop.Action{Cmd: actionCmd}
52
Girish Gowdraaeceb842020-08-21 12:10:39 -070053 flow := oop.Flow{AccessIntfId: -1, OnuId: -1, UniId: -1, FlowId: flowID,
Girish Gowdra64503432020-01-07 10:59:10 +053054 FlowType: "downstream", AllocId: -1, GemportId: -1,
55 Classifier: flowClassifier, Action: actionInfo,
Girish Gowdraef1b7c42020-01-23 16:27:48 +053056 Priority: 1000, PortNo: uint32(config.NniIntfID)}
Girish Gowdra64503432020-01-07 10:59:10 +053057
58 _, err = oo.FlowAdd(context.Background(), &flow)
59
60 st, _ := status.FromError(err)
61 if st.Code() == codes.AlreadyExists {
62 log.Debugw("Flow already exists", log.Fields{"err": err, "deviceFlow": flow})
63 return nil
64 }
65
66 if err != nil {
Girish Gowdraef1b7c42020-01-23 16:27:48 +053067 log.Errorw("Failed to Add DHCP IPv4 to device", log.Fields{"err": err, "deviceFlow": flow})
Girish Gowdra64503432020-01-07 10:59:10 +053068 return err
69 }
Girish Gowdraef1b7c42020-01-23 16:27:48 +053070 log.Debugw("DHCP IPV4 added to device successfully ", log.Fields{"flow": flow})
71
72 return nil
73}
74
75func AddDhcpIPV6Flow(oo oop.OpenoltClient, config *config.OpenOltScaleTesterConfig, rsrMgr *OpenOltResourceMgr) error {
Girish Gowdraaeceb842020-08-21 12:10:39 -070076 var flowID uint32
Girish Gowdraef1b7c42020-01-23 16:27:48 +053077 var err error
78
Girish Gowdraaeceb842020-08-21 12:10:39 -070079 if flowID, err = rsrMgr.GetFlowID(context.Background(), uint32(config.NniIntfID)); err != nil {
Girish Gowdraef1b7c42020-01-23 16:27:48 +053080 return err
81 }
82
83 // DHCP IPV6
84 flowClassifier := &oop.Classifier{EthType: 34525, IpProto: 17, SrcPort: 546, DstPort: 547, PktTagType: "double_tag"}
85 actionCmd := &oop.ActionCmd{TrapToHost: true}
86 actionInfo := &oop.Action{Cmd: actionCmd}
87
Girish Gowdraaeceb842020-08-21 12:10:39 -070088 flow := oop.Flow{AccessIntfId: -1, OnuId: -1, UniId: -1, FlowId: flowID,
Girish Gowdraef1b7c42020-01-23 16:27:48 +053089 FlowType: "downstream", AllocId: -1, GemportId: -1,
90 Classifier: flowClassifier, Action: actionInfo,
91 Priority: 1000, PortNo: uint32(config.NniIntfID)}
92
93 _, err = oo.FlowAdd(context.Background(), &flow)
94
95 st, _ := status.FromError(err)
96 if st.Code() == codes.AlreadyExists {
97 log.Debugw("Flow already exists", log.Fields{"err": err, "deviceFlow": flow})
98 return nil
99 }
100
101 if err != nil {
102 log.Errorw("Failed to Add DHCP IPV6 to device", log.Fields{"err": err, "deviceFlow": flow})
Girish Gowdraef1b7c42020-01-23 16:27:48 +0530103 return err
104 }
105 log.Debugw("DHCP IPV6 added to device successfully ", log.Fields{"flow": flow})
106
107 return nil
108}
109
Girish Gowdraef1b7c42020-01-23 16:27:48 +0530110func ProvisionAttNniTrapFlow(oo oop.OpenoltClient, config *config.OpenOltScaleTesterConfig, rsrMgr *OpenOltResourceMgr) error {
111 _ = AddDhcpIPV4Flow(oo, config, rsrMgr)
112 _ = AddDhcpIPV6Flow(oo, config, rsrMgr)
113 _ = AddLldpFlow(oo, config, rsrMgr)
Girish Gowdra64503432020-01-07 10:59:10 +0530114
115 return nil
116}
117
Girish Gowdra64503432020-01-07 10:59:10 +0530118func (att AttWorkFlow) ProvisionScheds(subs *Subscriber) error {
119 var trafficSched []*tp_pb.TrafficScheduler
120
121 log.Info("provisioning-scheds")
122
123 if trafficSched = getTrafficSched(subs, tp_pb.Direction_DOWNSTREAM); trafficSched == nil {
124 log.Error("ds-traffic-sched-is-nil")
125 return errors.New(ReasonCodeToReasonString(SCHED_CREATION_FAILED))
126 }
127
128 log.Debugw("Sending Traffic scheduler create to device",
129 log.Fields{"Direction": tp_pb.Direction_DOWNSTREAM, "TrafficScheds": trafficSched})
130 if _, err := subs.OpenOltClient.CreateTrafficSchedulers(context.Background(), &tp_pb.TrafficSchedulers{
131 IntfId: subs.PonIntf, OnuId: subs.OnuID,
132 UniId: subs.UniID, PortNo: subs.UniPortNo,
133 TrafficScheds: trafficSched}); err != nil {
134 log.Errorw("Failed to create traffic schedulers", log.Fields{"error": err})
135 return errors.New(ReasonCodeToReasonString(SCHED_CREATION_FAILED))
136 }
137
138 if trafficSched = getTrafficSched(subs, tp_pb.Direction_UPSTREAM); trafficSched == nil {
139 log.Error("us-traffic-sched-is-nil")
140 return errors.New(ReasonCodeToReasonString(SCHED_CREATION_FAILED))
141 }
142
143 log.Debugw("Sending Traffic scheduler create to device",
144 log.Fields{"Direction": tp_pb.Direction_UPSTREAM, "TrafficScheds": trafficSched})
145 if _, err := subs.OpenOltClient.CreateTrafficSchedulers(context.Background(), &tp_pb.TrafficSchedulers{
146 IntfId: subs.PonIntf, OnuId: subs.OnuID,
147 UniId: subs.UniID, PortNo: subs.UniPortNo,
148 TrafficScheds: trafficSched}); err != nil {
149 log.Errorw("Failed to create traffic schedulers", log.Fields{"error": err})
150 return errors.New(ReasonCodeToReasonString(SCHED_CREATION_FAILED))
151 }
Girish Gowdra64503432020-01-07 10:59:10 +0530152 return nil
153}
154
Girish Gowdra64503432020-01-07 10:59:10 +0530155func (att AttWorkFlow) ProvisionQueues(subs *Subscriber) error {
156 log.Info("provisioning-queues")
157
158 var trafficQueues []*tp_pb.TrafficQueue
159 if trafficQueues = getTrafficQueues(subs, tp_pb.Direction_DOWNSTREAM); trafficQueues == nil {
160 log.Error("Failed to create traffic queues")
161 return errors.New(ReasonCodeToReasonString(QUEUE_CREATION_FAILED))
162 }
163
164 // On receiving the CreateTrafficQueues request, the driver should create corresponding
165 // downstream queues.
166 log.Debugw("Sending Traffic Queues create to device",
167 log.Fields{"Direction": tp_pb.Direction_DOWNSTREAM, "TrafficQueues": trafficQueues})
168 if _, err := subs.OpenOltClient.CreateTrafficQueues(context.Background(),
169 &tp_pb.TrafficQueues{IntfId: subs.PonIntf, OnuId: subs.OnuID,
170 UniId: subs.UniID, PortNo: subs.UniPortNo,
171 TrafficQueues: trafficQueues}); err != nil {
172 log.Errorw("Failed to create traffic queues in device", log.Fields{"error": err})
173 return errors.New(ReasonCodeToReasonString(QUEUE_CREATION_FAILED))
174 }
175
176 if trafficQueues = getTrafficQueues(subs, tp_pb.Direction_UPSTREAM); trafficQueues == nil {
177 log.Error("Failed to create traffic queues")
178 return errors.New(ReasonCodeToReasonString(QUEUE_CREATION_FAILED))
179 }
180
181 // On receiving the CreateTrafficQueues request, the driver should create corresponding
182 // upstream queues.
183 log.Debugw("Sending Traffic Queues create to device",
184 log.Fields{"Direction": tp_pb.Direction_UPSTREAM, "TrafficQueues": trafficQueues})
185 if _, err := subs.OpenOltClient.CreateTrafficQueues(context.Background(),
186 &tp_pb.TrafficQueues{IntfId: subs.PonIntf, OnuId: subs.OnuID,
187 UniId: subs.UniID, PortNo: subs.UniPortNo,
188 TrafficQueues: trafficQueues}); err != nil {
189 log.Errorw("Failed to create traffic queues in device", log.Fields{"error": err})
190 return errors.New(ReasonCodeToReasonString(QUEUE_CREATION_FAILED))
191 }
192
193 return nil
194}
195
196func (att AttWorkFlow) ProvisionEapFlow(subs *Subscriber) error {
Girish Gowdra64503432020-01-07 10:59:10 +0530197 var err error
Girish Gowdraaeceb842020-08-21 12:10:39 -0700198 var flowID uint32
Girish Gowdra64503432020-01-07 10:59:10 +0530199 var gemPortIDs []uint32
200
201 var allocID = subs.TpInstance[subs.TestConfig.TpIDList[0]].UsScheduler.AllocID
Girish Gowdra64503432020-01-07 10:59:10 +0530202 for _, gem := range subs.TpInstance[subs.TestConfig.TpIDList[0]].UpstreamGemPortAttributeList {
203 gemPortIDs = append(gemPortIDs, gem.GemportID)
204 }
205
Girish Gowdrad4bdd372020-03-09 14:56:15 -0700206 for idx, gemID := range gemPortIDs {
207 pBitMap := subs.TpInstance[subs.TestConfig.TpIDList[0]].UpstreamGemPortAttributeList[idx].PbitMap
208 for pos, pbitSet := range strings.TrimPrefix(pBitMap, "0b") {
209 if pbitSet == '1' {
210 pcp := uint32(len(strings.TrimPrefix(pBitMap, "0b"))) - 1 - uint32(pos)
Girish Gowdraaeceb842020-08-21 12:10:39 -0700211 if flowID, err = subs.RsrMgr.GetFlowID(context.Background(), uint32(subs.PonIntf)); err != nil {
Girish Gowdrad4bdd372020-03-09 14:56:15 -0700212 return errors.New(ReasonCodeToReasonString(FLOW_ID_GENERATION_FAILED))
213 } else {
Girish Gowdraaeceb842020-08-21 12:10:39 -0700214 if err := AddFlow(subs, EapolFlow, Upstream, flowID, allocID, gemID, pcp); err != nil {
Girish Gowdrad4bdd372020-03-09 14:56:15 -0700215 return err
216 }
217 }
Thiyagarajan Subramanib83b0432020-01-08 13:43:28 +0530218 }
Girish Gowdra64503432020-01-07 10:59:10 +0530219 }
Girish Gowdra64503432020-01-07 10:59:10 +0530220 }
221 return nil
222}
223
Girish Gowdraef1b7c42020-01-23 16:27:48 +0530224func (att AttWorkFlow) ProvisionDhcpIPV4Flow(subs *Subscriber) error {
Thiyagarajan Subramanib83b0432020-01-08 13:43:28 +0530225 var err error
Girish Gowdraaeceb842020-08-21 12:10:39 -0700226 var flowID uint32
Thiyagarajan Subramanib83b0432020-01-08 13:43:28 +0530227 var gemPortIDs []uint32
228
229 var allocID = subs.TpInstance[subs.TestConfig.TpIDList[0]].UsScheduler.AllocID
230 for _, gem := range subs.TpInstance[subs.TestConfig.TpIDList[0]].UpstreamGemPortAttributeList {
231 gemPortIDs = append(gemPortIDs, gem.GemportID)
232 }
233
Girish Gowdrad4bdd372020-03-09 14:56:15 -0700234 for idx, gemID := range gemPortIDs {
235 pBitMap := subs.TpInstance[subs.TestConfig.TpIDList[0]].UpstreamGemPortAttributeList[idx].PbitMap
236 for pos, pbitSet := range strings.TrimPrefix(pBitMap, "0b") {
237 if pbitSet == '1' {
238 pcp := uint32(len(strings.TrimPrefix(pBitMap, "0b"))) - 1 - uint32(pos)
Girish Gowdraaeceb842020-08-21 12:10:39 -0700239 if flowID, err = subs.RsrMgr.GetFlowID(context.Background(), uint32(subs.PonIntf)); err != nil {
Girish Gowdrad4bdd372020-03-09 14:56:15 -0700240 return errors.New(ReasonCodeToReasonString(FLOW_ID_GENERATION_FAILED))
241 } else {
Girish Gowdraaeceb842020-08-21 12:10:39 -0700242 if err := AddFlow(subs, DhcpFlowIPV4, Upstream, flowID, allocID, gemID, pcp); err != nil {
Girish Gowdrad4bdd372020-03-09 14:56:15 -0700243 return err
244 }
245 }
Girish Gowdraef1b7c42020-01-23 16:27:48 +0530246 }
247 }
248 }
249 return nil
250}
251
252func (att AttWorkFlow) ProvisionDhcpIPV6Flow(subs *Subscriber) error {
253 var err error
Girish Gowdraaeceb842020-08-21 12:10:39 -0700254 var flowID uint32
Girish Gowdraef1b7c42020-01-23 16:27:48 +0530255 var gemPortIDs []uint32
256
257 var allocID = subs.TpInstance[subs.TestConfig.TpIDList[0]].UsScheduler.AllocID
258 for _, gem := range subs.TpInstance[subs.TestConfig.TpIDList[0]].UpstreamGemPortAttributeList {
259 gemPortIDs = append(gemPortIDs, gem.GemportID)
260 }
261
Girish Gowdrad4bdd372020-03-09 14:56:15 -0700262 for idx, gemID := range gemPortIDs {
263 pBitMap := subs.TpInstance[subs.TestConfig.TpIDList[0]].UpstreamGemPortAttributeList[idx].PbitMap
264 for pos, pbitSet := range strings.TrimPrefix(pBitMap, "0b") {
265 if pbitSet == '1' {
266 pcp := uint32(len(strings.TrimPrefix(pBitMap, "0b"))) - 1 - uint32(pos)
Girish Gowdraaeceb842020-08-21 12:10:39 -0700267 if flowID, err = subs.RsrMgr.GetFlowID(context.Background(), uint32(subs.PonIntf)); err != nil {
Girish Gowdrad4bdd372020-03-09 14:56:15 -0700268 return errors.New(ReasonCodeToReasonString(FLOW_ID_GENERATION_FAILED))
269 } else {
Girish Gowdraaeceb842020-08-21 12:10:39 -0700270 if err := AddFlow(subs, DhcpFlowIPV6, Upstream, flowID, allocID, gemID, pcp); err != nil {
Girish Gowdrad4bdd372020-03-09 14:56:15 -0700271 return err
272 }
273 }
Thiyagarajan Subramanib83b0432020-01-08 13:43:28 +0530274 }
275 }
276 }
Girish Gowdra64503432020-01-07 10:59:10 +0530277 return nil
278}
279
280func (att AttWorkFlow) ProvisionIgmpFlow(subs *Subscriber) error {
281 log.Info("att-workflow-does-not-support-igmp-yet--nothing-to-do")
282 return nil
283}
284
285func (att AttWorkFlow) ProvisionHsiaFlow(subs *Subscriber) error {
Thiyagarajan Subramanib83b0432020-01-08 13:43:28 +0530286 var err error
Girish Gowdraaeceb842020-08-21 12:10:39 -0700287 var flowID uint32
Thiyagarajan Subramanib83b0432020-01-08 13:43:28 +0530288 var gemPortIDs []uint32
289
290 var allocID = subs.TpInstance[subs.TestConfig.TpIDList[0]].UsScheduler.AllocID
291 for _, gem := range subs.TpInstance[subs.TestConfig.TpIDList[0]].UpstreamGemPortAttributeList {
292 gemPortIDs = append(gemPortIDs, gem.GemportID)
293 }
294
Girish Gowdrad4bdd372020-03-09 14:56:15 -0700295 for idx, gemID := range gemPortIDs {
296 pBitMap := subs.TpInstance[subs.TestConfig.TpIDList[0]].UpstreamGemPortAttributeList[idx].PbitMap
297 for pos, pbitSet := range strings.TrimPrefix(pBitMap, "0b") {
298 if pbitSet == '1' {
299 pcp := uint32(len(strings.TrimPrefix(pBitMap, "0b"))) - 1 - uint32(pos)
Girish Gowdraaeceb842020-08-21 12:10:39 -0700300 if flowID, err = subs.RsrMgr.GetFlowID(context.Background(), uint32(subs.PonIntf)); err != nil {
Girish Gowdrad4bdd372020-03-09 14:56:15 -0700301 return errors.New(ReasonCodeToReasonString(FLOW_ID_GENERATION_FAILED))
302 } else {
303 var errUs, errDs error
Girish Gowdraaeceb842020-08-21 12:10:39 -0700304 if errUs = AddFlow(subs, HsiaFlow, Upstream, flowID, allocID, gemID, pcp); errUs != nil {
Girish Gowdrad4bdd372020-03-09 14:56:15 -0700305 log.Errorw("failed to install US HSIA flow",
306 log.Fields{"onuID": subs.OnuID, "uniID": subs.UniID, "intf": subs.PonIntf})
307 }
Girish Gowdraaeceb842020-08-21 12:10:39 -0700308 if errDs = AddFlow(subs, HsiaFlow, Downstream, flowID, allocID, gemID, pcp); errDs != nil {
Girish Gowdrad4bdd372020-03-09 14:56:15 -0700309 log.Errorw("failed to install US HSIA flow",
310 log.Fields{"onuID": subs.OnuID, "uniID": subs.UniID, "intf": subs.PonIntf})
311 }
312 if errUs != nil && errDs != nil {
Girish Gowdrad4bdd372020-03-09 14:56:15 -0700313 }
314 if errUs != nil || errDs != nil {
315 if errUs != nil {
316 return errUs
317 }
318 return errDs
319 }
Girish Gowdraef1b7c42020-01-23 16:27:48 +0530320 }
Thiyagarajan Subramanib83b0432020-01-08 13:43:28 +0530321 }
322 }
323 }
Girish Gowdra64503432020-01-07 10:59:10 +0530324 return nil
325}
Orhan Kupusoglu66b00d82020-03-13 12:06:33 +0300326
327func (att AttWorkFlow) ProvisionVoipFlow(subs *Subscriber) error {
328 log.Info("att-workflow-does-not-support-voip-yet--nothing-to-do")
329 return nil
330}
331
332func (att AttWorkFlow) ProvisionVodFlow(subs *Subscriber) error {
333 log.Info("att-workflow-does-not-support-vod-yet--nothing-to-do")
334 return nil
335}
336
337func (att AttWorkFlow) ProvisionMgmtFlow(subs *Subscriber) error {
338 log.Info("att-workflow-does-not-support-mgmt-yet--nothing-to-do")
339 return nil
340}
341
342func (att AttWorkFlow) ProvisionMulticastFlow(subs *Subscriber) error {
343 log.Info("att-workflow-does-not-support-multicast-yet--nothing-to-do")
344 return nil
345}