blob: 4417c271d065e3b2a633fc71a83923d55119c5eb [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"
Thiyagarajan Subramanib83b0432020-01-08 13:43:28 +053021
Girish Gowdra64503432020-01-07 10:59:10 +053022 "github.com/opencord/openolt-scale-tester/config"
23 "github.com/opencord/voltha-lib-go/v2/pkg/log"
24 "github.com/opencord/voltha-lib-go/v2/pkg/ponresourcemanager"
25 oop "github.com/opencord/voltha-protos/v2/go/openolt"
26 tp_pb "github.com/opencord/voltha-protos/v2/go/tech_profile"
27 "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 Gowdra64503432020-01-07 10:59:10 +053041 var flowID []uint32
42 var err error
43
44 if flowID, err = rsrMgr.ResourceMgrs[uint32(config.NniIntfID)].GetResourceID(uint32(config.NniIntfID),
45 ponresourcemanager.FLOW_ID, 1); err != nil {
46 return err
47 }
48
Girish Gowdraef1b7c42020-01-23 16:27:48 +053049 // DHCP IPV4
Girish Gowdra64503432020-01-07 10:59:10 +053050 flowClassifier := &oop.Classifier{EthType: 2048, IpProto: 17, SrcPort: 67, DstPort: 68, PktTagType: "double_tag"}
51 actionCmd := &oop.ActionCmd{TrapToHost: true}
52 actionInfo := &oop.Action{Cmd: actionCmd}
53
54 flow := oop.Flow{AccessIntfId: -1, OnuId: -1, UniId: -1, FlowId: flowID[0],
55 FlowType: "downstream", AllocId: -1, GemportId: -1,
56 Classifier: flowClassifier, Action: actionInfo,
Girish Gowdraef1b7c42020-01-23 16:27:48 +053057 Priority: 1000, PortNo: uint32(config.NniIntfID)}
Girish Gowdra64503432020-01-07 10:59:10 +053058
59 _, err = oo.FlowAdd(context.Background(), &flow)
60
61 st, _ := status.FromError(err)
62 if st.Code() == codes.AlreadyExists {
63 log.Debugw("Flow already exists", log.Fields{"err": err, "deviceFlow": flow})
64 return nil
65 }
66
67 if err != nil {
Girish Gowdraef1b7c42020-01-23 16:27:48 +053068 log.Errorw("Failed to Add DHCP IPv4 to device", log.Fields{"err": err, "deviceFlow": flow})
Thiyagarajan Subramanib83b0432020-01-08 13:43:28 +053069 rsrMgr.ResourceMgrs[uint32(config.NniIntfID)].FreeResourceID(uint32(config.NniIntfID),
70 ponresourcemanager.FLOW_ID, flowID)
Girish Gowdra64503432020-01-07 10:59:10 +053071 return err
72 }
Girish Gowdraef1b7c42020-01-23 16:27:48 +053073 log.Debugw("DHCP IPV4 added to device successfully ", log.Fields{"flow": flow})
74
75 return nil
76}
77
78func AddDhcpIPV6Flow(oo oop.OpenoltClient, config *config.OpenOltScaleTesterConfig, rsrMgr *OpenOltResourceMgr) error {
79 var flowID []uint32
80 var err error
81
82 if flowID, err = rsrMgr.ResourceMgrs[uint32(config.NniIntfID)].GetResourceID(uint32(config.NniIntfID),
83 ponresourcemanager.FLOW_ID, 1); err != nil {
84 return err
85 }
86
87 // DHCP IPV6
88 flowClassifier := &oop.Classifier{EthType: 34525, IpProto: 17, SrcPort: 546, DstPort: 547, PktTagType: "double_tag"}
89 actionCmd := &oop.ActionCmd{TrapToHost: true}
90 actionInfo := &oop.Action{Cmd: actionCmd}
91
92 flow := oop.Flow{AccessIntfId: -1, OnuId: -1, UniId: -1, FlowId: flowID[0],
93 FlowType: "downstream", AllocId: -1, GemportId: -1,
94 Classifier: flowClassifier, Action: actionInfo,
95 Priority: 1000, PortNo: uint32(config.NniIntfID)}
96
97 _, err = oo.FlowAdd(context.Background(), &flow)
98
99 st, _ := status.FromError(err)
100 if st.Code() == codes.AlreadyExists {
101 log.Debugw("Flow already exists", log.Fields{"err": err, "deviceFlow": flow})
102 return nil
103 }
104
105 if err != nil {
106 log.Errorw("Failed to Add DHCP IPV6 to device", log.Fields{"err": err, "deviceFlow": flow})
107 rsrMgr.ResourceMgrs[uint32(config.NniIntfID)].FreeResourceID(uint32(config.NniIntfID),
108 ponresourcemanager.FLOW_ID, flowID)
109 return err
110 }
111 log.Debugw("DHCP IPV6 added to device successfully ", log.Fields{"flow": flow})
112
113 return nil
114}
115
116func AddLldpFlow(oo oop.OpenoltClient, config *config.OpenOltScaleTesterConfig, rsrMgr *OpenOltResourceMgr) error {
117 var flowID []uint32
118 var err error
119
120 if flowID, err = rsrMgr.ResourceMgrs[uint32(config.NniIntfID)].GetResourceID(uint32(config.NniIntfID),
121 ponresourcemanager.FLOW_ID, 1); err != nil {
122 return err
123 }
124
125 // DHCP IPV4
126 flowClassifier := &oop.Classifier{EthType: 35020, PktTagType: "untagged"}
127 actionCmd := &oop.ActionCmd{TrapToHost: true}
128 actionInfo := &oop.Action{Cmd: actionCmd}
129
130 flow := oop.Flow{AccessIntfId: -1, OnuId: -1, UniId: -1, FlowId: flowID[0],
131 FlowType: "downstream", AllocId: -1, GemportId: -1,
132 Classifier: flowClassifier, Action: actionInfo,
133 Priority: 1000, PortNo: uint32(config.NniIntfID)}
134
135 _, err = oo.FlowAdd(context.Background(), &flow)
136
137 st, _ := status.FromError(err)
138 if st.Code() == codes.AlreadyExists {
139 log.Debugw("Flow already exists", log.Fields{"err": err, "deviceFlow": flow})
140 return nil
141 }
142
143 if err != nil {
144 log.Errorw("Failed to Add LLDP flow to device", log.Fields{"err": err, "deviceFlow": flow})
145 rsrMgr.ResourceMgrs[uint32(config.NniIntfID)].FreeResourceID(uint32(config.NniIntfID),
146 ponresourcemanager.FLOW_ID, flowID)
147 return err
148 }
149 log.Debugw("LLDP flow added to device successfully ", log.Fields{"flow": flow})
150
151 return nil
152}
153
154func ProvisionAttNniTrapFlow(oo oop.OpenoltClient, config *config.OpenOltScaleTesterConfig, rsrMgr *OpenOltResourceMgr) error {
155 _ = AddDhcpIPV4Flow(oo, config, rsrMgr)
156 _ = AddDhcpIPV6Flow(oo, config, rsrMgr)
157 _ = AddLldpFlow(oo, config, rsrMgr)
Girish Gowdra64503432020-01-07 10:59:10 +0530158
159 return nil
160}
161
Girish Gowdra64503432020-01-07 10:59:10 +0530162func (att AttWorkFlow) ProvisionScheds(subs *Subscriber) error {
163 var trafficSched []*tp_pb.TrafficScheduler
164
165 log.Info("provisioning-scheds")
166
167 if trafficSched = getTrafficSched(subs, tp_pb.Direction_DOWNSTREAM); trafficSched == nil {
168 log.Error("ds-traffic-sched-is-nil")
169 return errors.New(ReasonCodeToReasonString(SCHED_CREATION_FAILED))
170 }
171
172 log.Debugw("Sending Traffic scheduler create to device",
173 log.Fields{"Direction": tp_pb.Direction_DOWNSTREAM, "TrafficScheds": trafficSched})
174 if _, err := subs.OpenOltClient.CreateTrafficSchedulers(context.Background(), &tp_pb.TrafficSchedulers{
175 IntfId: subs.PonIntf, OnuId: subs.OnuID,
176 UniId: subs.UniID, PortNo: subs.UniPortNo,
177 TrafficScheds: trafficSched}); err != nil {
178 log.Errorw("Failed to create traffic schedulers", log.Fields{"error": err})
179 return errors.New(ReasonCodeToReasonString(SCHED_CREATION_FAILED))
180 }
181
182 if trafficSched = getTrafficSched(subs, tp_pb.Direction_UPSTREAM); trafficSched == nil {
183 log.Error("us-traffic-sched-is-nil")
184 return errors.New(ReasonCodeToReasonString(SCHED_CREATION_FAILED))
185 }
186
187 log.Debugw("Sending Traffic scheduler create to device",
188 log.Fields{"Direction": tp_pb.Direction_UPSTREAM, "TrafficScheds": trafficSched})
189 if _, err := subs.OpenOltClient.CreateTrafficSchedulers(context.Background(), &tp_pb.TrafficSchedulers{
190 IntfId: subs.PonIntf, OnuId: subs.OnuID,
191 UniId: subs.UniID, PortNo: subs.UniPortNo,
192 TrafficScheds: trafficSched}); err != nil {
193 log.Errorw("Failed to create traffic schedulers", log.Fields{"error": err})
194 return errors.New(ReasonCodeToReasonString(SCHED_CREATION_FAILED))
195 }
196
197 return nil
198}
199
Girish Gowdra64503432020-01-07 10:59:10 +0530200func (att AttWorkFlow) ProvisionQueues(subs *Subscriber) error {
201 log.Info("provisioning-queues")
202
203 var trafficQueues []*tp_pb.TrafficQueue
204 if trafficQueues = getTrafficQueues(subs, tp_pb.Direction_DOWNSTREAM); trafficQueues == nil {
205 log.Error("Failed to create traffic queues")
206 return errors.New(ReasonCodeToReasonString(QUEUE_CREATION_FAILED))
207 }
208
209 // On receiving the CreateTrafficQueues request, the driver should create corresponding
210 // downstream queues.
211 log.Debugw("Sending Traffic Queues create to device",
212 log.Fields{"Direction": tp_pb.Direction_DOWNSTREAM, "TrafficQueues": trafficQueues})
213 if _, err := subs.OpenOltClient.CreateTrafficQueues(context.Background(),
214 &tp_pb.TrafficQueues{IntfId: subs.PonIntf, OnuId: subs.OnuID,
215 UniId: subs.UniID, PortNo: subs.UniPortNo,
216 TrafficQueues: trafficQueues}); err != nil {
217 log.Errorw("Failed to create traffic queues in device", log.Fields{"error": err})
218 return errors.New(ReasonCodeToReasonString(QUEUE_CREATION_FAILED))
219 }
220
221 if trafficQueues = getTrafficQueues(subs, tp_pb.Direction_UPSTREAM); trafficQueues == nil {
222 log.Error("Failed to create traffic queues")
223 return errors.New(ReasonCodeToReasonString(QUEUE_CREATION_FAILED))
224 }
225
226 // On receiving the CreateTrafficQueues request, the driver should create corresponding
227 // upstream queues.
228 log.Debugw("Sending Traffic Queues create to device",
229 log.Fields{"Direction": tp_pb.Direction_UPSTREAM, "TrafficQueues": trafficQueues})
230 if _, err := subs.OpenOltClient.CreateTrafficQueues(context.Background(),
231 &tp_pb.TrafficQueues{IntfId: subs.PonIntf, OnuId: subs.OnuID,
232 UniId: subs.UniID, PortNo: subs.UniPortNo,
233 TrafficQueues: trafficQueues}); err != nil {
234 log.Errorw("Failed to create traffic queues in device", log.Fields{"error": err})
235 return errors.New(ReasonCodeToReasonString(QUEUE_CREATION_FAILED))
236 }
237
238 return nil
239}
240
241func (att AttWorkFlow) ProvisionEapFlow(subs *Subscriber) error {
Girish Gowdra64503432020-01-07 10:59:10 +0530242 var err error
243 var flowID []uint32
244 var gemPortIDs []uint32
245
246 var allocID = subs.TpInstance[subs.TestConfig.TpIDList[0]].UsScheduler.AllocID
Girish Gowdra64503432020-01-07 10:59:10 +0530247 for _, gem := range subs.TpInstance[subs.TestConfig.TpIDList[0]].UpstreamGemPortAttributeList {
248 gemPortIDs = append(gemPortIDs, gem.GemportID)
249 }
250
251 for _, gemID := range gemPortIDs {
252 if flowID, err = subs.RsrMgr.ResourceMgrs[uint32(subs.PonIntf)].GetResourceID(uint32(subs.PonIntf),
253 ponresourcemanager.FLOW_ID, 1); err != nil {
Thiyagarajan Subramanib83b0432020-01-08 13:43:28 +0530254 return errors.New(ReasonCodeToReasonString(FLOW_ID_GENERATION_FAILED))
255 } else {
256 if err := AddFlow(subs, EapolFlow, Upstream, flowID[0], allocID, gemID); err != nil {
257 subs.RsrMgr.ResourceMgrs[uint32(subs.PonIntf)].FreeResourceID(uint32(subs.PonIntf),
258 ponresourcemanager.FLOW_ID, flowID)
259 return err
260 }
Girish Gowdra64503432020-01-07 10:59:10 +0530261 }
Girish Gowdra64503432020-01-07 10:59:10 +0530262 }
263 return nil
264}
265
Girish Gowdraef1b7c42020-01-23 16:27:48 +0530266func (att AttWorkFlow) ProvisionDhcpIPV4Flow(subs *Subscriber) error {
Thiyagarajan Subramanib83b0432020-01-08 13:43:28 +0530267 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
276 for _, gemID := range gemPortIDs {
277 if flowID, err = subs.RsrMgr.ResourceMgrs[uint32(subs.PonIntf)].GetResourceID(uint32(subs.PonIntf),
278 ponresourcemanager.FLOW_ID, 1); err != nil {
279 return errors.New(ReasonCodeToReasonString(FLOW_ID_GENERATION_FAILED))
280 } else {
Girish Gowdraef1b7c42020-01-23 16:27:48 +0530281 if err := AddFlow(subs, DhcpFlowIPV4, Upstream, flowID[0], allocID, gemID); err != nil {
282 subs.RsrMgr.ResourceMgrs[uint32(subs.PonIntf)].FreeResourceID(uint32(subs.PonIntf),
283 ponresourcemanager.FLOW_ID, flowID)
284 return err
285 }
286 }
287 }
288 return nil
289}
290
291func (att AttWorkFlow) ProvisionDhcpIPV6Flow(subs *Subscriber) error {
292 var err error
293 var flowID []uint32
294 var gemPortIDs []uint32
295
296 var allocID = subs.TpInstance[subs.TestConfig.TpIDList[0]].UsScheduler.AllocID
297 for _, gem := range subs.TpInstance[subs.TestConfig.TpIDList[0]].UpstreamGemPortAttributeList {
298 gemPortIDs = append(gemPortIDs, gem.GemportID)
299 }
300
301 for _, gemID := range gemPortIDs {
302 if flowID, err = subs.RsrMgr.ResourceMgrs[uint32(subs.PonIntf)].GetResourceID(uint32(subs.PonIntf),
303 ponresourcemanager.FLOW_ID, 1); err != nil {
304 return errors.New(ReasonCodeToReasonString(FLOW_ID_GENERATION_FAILED))
305 } else {
306 if err := AddFlow(subs, DhcpFlowIPV6, Upstream, flowID[0], allocID, gemID); err != nil {
Thiyagarajan Subramanib83b0432020-01-08 13:43:28 +0530307 subs.RsrMgr.ResourceMgrs[uint32(subs.PonIntf)].FreeResourceID(uint32(subs.PonIntf),
308 ponresourcemanager.FLOW_ID, flowID)
309 return err
310 }
311 }
312 }
Girish Gowdra64503432020-01-07 10:59:10 +0530313 return nil
314}
315
316func (att AttWorkFlow) ProvisionIgmpFlow(subs *Subscriber) error {
317 log.Info("att-workflow-does-not-support-igmp-yet--nothing-to-do")
318 return nil
319}
320
321func (att AttWorkFlow) ProvisionHsiaFlow(subs *Subscriber) error {
Thiyagarajan Subramanib83b0432020-01-08 13:43:28 +0530322 var err error
323 var flowID []uint32
324 var gemPortIDs []uint32
325
326 var allocID = subs.TpInstance[subs.TestConfig.TpIDList[0]].UsScheduler.AllocID
327 for _, gem := range subs.TpInstance[subs.TestConfig.TpIDList[0]].UpstreamGemPortAttributeList {
328 gemPortIDs = append(gemPortIDs, gem.GemportID)
329 }
330
331 for _, gemID := range gemPortIDs {
332 if flowID, err = subs.RsrMgr.ResourceMgrs[uint32(subs.PonIntf)].GetResourceID(uint32(subs.PonIntf),
333 ponresourcemanager.FLOW_ID, 1); err != nil {
334 return errors.New(ReasonCodeToReasonString(FLOW_ID_GENERATION_FAILED))
335 } else {
Girish Gowdraef1b7c42020-01-23 16:27:48 +0530336 var errUs, errDs error
337 if errUs = AddFlow(subs, HsiaFlow, Upstream, flowID[0], allocID, gemID); errUs != nil {
338 log.Errorw("failed to install US HSIA flow",
339 log.Fields{"onuID": subs.OnuID, "uniID": subs.UniID, "intf": subs.PonIntf})
340 }
341 if errDs = AddFlow(subs, HsiaFlow, Downstream, flowID[0], allocID, gemID); errDs != nil {
342 log.Errorw("failed to install US HSIA flow",
343 log.Fields{"onuID": subs.OnuID, "uniID": subs.UniID, "intf": subs.PonIntf})
344 }
345 if errUs != nil && errDs != nil {
Thiyagarajan Subramanib83b0432020-01-08 13:43:28 +0530346 subs.RsrMgr.ResourceMgrs[uint32(subs.PonIntf)].FreeResourceID(uint32(subs.PonIntf),
347 ponresourcemanager.FLOW_ID, flowID)
Thiyagarajan Subramanib83b0432020-01-08 13:43:28 +0530348 }
Girish Gowdraef1b7c42020-01-23 16:27:48 +0530349 if errUs != nil || errDs != nil {
350 if errUs != nil {
351 return errUs
352 }
353 return errDs
Thiyagarajan Subramanib83b0432020-01-08 13:43:28 +0530354 }
355 }
356 }
Girish Gowdra64503432020-01-07 10:59:10 +0530357 return nil
358}