blob: 0bc0f69e197d15e689009e340065f5315d45aeba [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
Thiyagarajan Subramanib83b0432020-01-08 13:43:28 +053040func ProvisionAttNniTrapFlow(oo oop.OpenoltClient, config *config.OpenOltScaleTesterConfig,
41 rsrMgr *OpenOltResourceMgr) error {
Girish Gowdra64503432020-01-07 10:59:10 +053042 var flowID []uint32
43 var err error
44
45 if flowID, err = rsrMgr.ResourceMgrs[uint32(config.NniIntfID)].GetResourceID(uint32(config.NniIntfID),
46 ponresourcemanager.FLOW_ID, 1); err != nil {
47 return err
48 }
49
50 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,
57 Priority: 1000, PortNo: 65536}
58
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 {
68 log.Errorw("Failed to Add flow 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 }
73 log.Debugw("Flow added to device successfully ", log.Fields{"flow": flow})
74
75 return nil
76}
77
Girish Gowdra64503432020-01-07 10:59:10 +053078func (att AttWorkFlow) ProvisionScheds(subs *Subscriber) error {
79 var trafficSched []*tp_pb.TrafficScheduler
80
81 log.Info("provisioning-scheds")
82
83 if trafficSched = getTrafficSched(subs, tp_pb.Direction_DOWNSTREAM); trafficSched == nil {
84 log.Error("ds-traffic-sched-is-nil")
85 return errors.New(ReasonCodeToReasonString(SCHED_CREATION_FAILED))
86 }
87
88 log.Debugw("Sending Traffic scheduler create to device",
89 log.Fields{"Direction": tp_pb.Direction_DOWNSTREAM, "TrafficScheds": trafficSched})
90 if _, err := subs.OpenOltClient.CreateTrafficSchedulers(context.Background(), &tp_pb.TrafficSchedulers{
91 IntfId: subs.PonIntf, OnuId: subs.OnuID,
92 UniId: subs.UniID, PortNo: subs.UniPortNo,
93 TrafficScheds: trafficSched}); err != nil {
94 log.Errorw("Failed to create traffic schedulers", log.Fields{"error": err})
95 return errors.New(ReasonCodeToReasonString(SCHED_CREATION_FAILED))
96 }
97
98 if trafficSched = getTrafficSched(subs, tp_pb.Direction_UPSTREAM); trafficSched == nil {
99 log.Error("us-traffic-sched-is-nil")
100 return errors.New(ReasonCodeToReasonString(SCHED_CREATION_FAILED))
101 }
102
103 log.Debugw("Sending Traffic scheduler create to device",
104 log.Fields{"Direction": tp_pb.Direction_UPSTREAM, "TrafficScheds": trafficSched})
105 if _, err := subs.OpenOltClient.CreateTrafficSchedulers(context.Background(), &tp_pb.TrafficSchedulers{
106 IntfId: subs.PonIntf, OnuId: subs.OnuID,
107 UniId: subs.UniID, PortNo: subs.UniPortNo,
108 TrafficScheds: trafficSched}); err != nil {
109 log.Errorw("Failed to create traffic schedulers", log.Fields{"error": err})
110 return errors.New(ReasonCodeToReasonString(SCHED_CREATION_FAILED))
111 }
112
113 return nil
114}
115
Girish Gowdra64503432020-01-07 10:59:10 +0530116func (att AttWorkFlow) ProvisionQueues(subs *Subscriber) error {
117 log.Info("provisioning-queues")
118
119 var trafficQueues []*tp_pb.TrafficQueue
120 if trafficQueues = getTrafficQueues(subs, tp_pb.Direction_DOWNSTREAM); trafficQueues == nil {
121 log.Error("Failed to create traffic queues")
122 return errors.New(ReasonCodeToReasonString(QUEUE_CREATION_FAILED))
123 }
124
125 // On receiving the CreateTrafficQueues request, the driver should create corresponding
126 // downstream queues.
127 log.Debugw("Sending Traffic Queues create to device",
128 log.Fields{"Direction": tp_pb.Direction_DOWNSTREAM, "TrafficQueues": trafficQueues})
129 if _, err := subs.OpenOltClient.CreateTrafficQueues(context.Background(),
130 &tp_pb.TrafficQueues{IntfId: subs.PonIntf, OnuId: subs.OnuID,
131 UniId: subs.UniID, PortNo: subs.UniPortNo,
132 TrafficQueues: trafficQueues}); err != nil {
133 log.Errorw("Failed to create traffic queues in device", log.Fields{"error": err})
134 return errors.New(ReasonCodeToReasonString(QUEUE_CREATION_FAILED))
135 }
136
137 if trafficQueues = getTrafficQueues(subs, tp_pb.Direction_UPSTREAM); trafficQueues == nil {
138 log.Error("Failed to create traffic queues")
139 return errors.New(ReasonCodeToReasonString(QUEUE_CREATION_FAILED))
140 }
141
142 // On receiving the CreateTrafficQueues request, the driver should create corresponding
143 // upstream queues.
144 log.Debugw("Sending Traffic Queues create to device",
145 log.Fields{"Direction": tp_pb.Direction_UPSTREAM, "TrafficQueues": trafficQueues})
146 if _, err := subs.OpenOltClient.CreateTrafficQueues(context.Background(),
147 &tp_pb.TrafficQueues{IntfId: subs.PonIntf, OnuId: subs.OnuID,
148 UniId: subs.UniID, PortNo: subs.UniPortNo,
149 TrafficQueues: trafficQueues}); err != nil {
150 log.Errorw("Failed to create traffic queues in device", log.Fields{"error": err})
151 return errors.New(ReasonCodeToReasonString(QUEUE_CREATION_FAILED))
152 }
153
154 return nil
155}
156
157func (att AttWorkFlow) ProvisionEapFlow(subs *Subscriber) error {
Girish Gowdra64503432020-01-07 10:59:10 +0530158 var err error
159 var flowID []uint32
160 var gemPortIDs []uint32
161
162 var allocID = subs.TpInstance[subs.TestConfig.TpIDList[0]].UsScheduler.AllocID
Girish Gowdra64503432020-01-07 10:59:10 +0530163 for _, gem := range subs.TpInstance[subs.TestConfig.TpIDList[0]].UpstreamGemPortAttributeList {
164 gemPortIDs = append(gemPortIDs, gem.GemportID)
165 }
166
167 for _, gemID := range gemPortIDs {
168 if flowID, err = subs.RsrMgr.ResourceMgrs[uint32(subs.PonIntf)].GetResourceID(uint32(subs.PonIntf),
169 ponresourcemanager.FLOW_ID, 1); err != nil {
Thiyagarajan Subramanib83b0432020-01-08 13:43:28 +0530170 return errors.New(ReasonCodeToReasonString(FLOW_ID_GENERATION_FAILED))
171 } else {
172 if err := AddFlow(subs, EapolFlow, Upstream, flowID[0], allocID, gemID); err != nil {
173 subs.RsrMgr.ResourceMgrs[uint32(subs.PonIntf)].FreeResourceID(uint32(subs.PonIntf),
174 ponresourcemanager.FLOW_ID, flowID)
175 return err
176 }
Girish Gowdra64503432020-01-07 10:59:10 +0530177 }
Girish Gowdra64503432020-01-07 10:59:10 +0530178 }
179 return nil
180}
181
182func (att AttWorkFlow) ProvisionDhcpFlow(subs *Subscriber) error {
Thiyagarajan Subramanib83b0432020-01-08 13:43:28 +0530183 var err error
184 var flowID []uint32
185 var gemPortIDs []uint32
186
187 var allocID = subs.TpInstance[subs.TestConfig.TpIDList[0]].UsScheduler.AllocID
188 for _, gem := range subs.TpInstance[subs.TestConfig.TpIDList[0]].UpstreamGemPortAttributeList {
189 gemPortIDs = append(gemPortIDs, gem.GemportID)
190 }
191
192 for _, gemID := range gemPortIDs {
193 if flowID, err = subs.RsrMgr.ResourceMgrs[uint32(subs.PonIntf)].GetResourceID(uint32(subs.PonIntf),
194 ponresourcemanager.FLOW_ID, 1); err != nil {
195 return errors.New(ReasonCodeToReasonString(FLOW_ID_GENERATION_FAILED))
196 } else {
197 if err := AddFlow(subs, DhcpFlow, Upstream, flowID[0], allocID, gemID); err != nil {
198 subs.RsrMgr.ResourceMgrs[uint32(subs.PonIntf)].FreeResourceID(uint32(subs.PonIntf),
199 ponresourcemanager.FLOW_ID, flowID)
200 return err
201 }
202 }
203 }
Girish Gowdra64503432020-01-07 10:59:10 +0530204 return nil
205}
206
207func (att AttWorkFlow) ProvisionIgmpFlow(subs *Subscriber) error {
208 log.Info("att-workflow-does-not-support-igmp-yet--nothing-to-do")
209 return nil
210}
211
212func (att AttWorkFlow) ProvisionHsiaFlow(subs *Subscriber) error {
Thiyagarajan Subramanib83b0432020-01-08 13:43:28 +0530213 var err error
214 var flowID []uint32
215 var gemPortIDs []uint32
216
217 var allocID = subs.TpInstance[subs.TestConfig.TpIDList[0]].UsScheduler.AllocID
218 for _, gem := range subs.TpInstance[subs.TestConfig.TpIDList[0]].UpstreamGemPortAttributeList {
219 gemPortIDs = append(gemPortIDs, gem.GemportID)
220 }
221
222 for _, gemID := range gemPortIDs {
223 if flowID, err = subs.RsrMgr.ResourceMgrs[uint32(subs.PonIntf)].GetResourceID(uint32(subs.PonIntf),
224 ponresourcemanager.FLOW_ID, 1); err != nil {
225 return errors.New(ReasonCodeToReasonString(FLOW_ID_GENERATION_FAILED))
226 } else {
227 if err := AddFlow(subs, HsiaFlow, Upstream, flowID[0], allocID, gemID); err != nil {
228 subs.RsrMgr.ResourceMgrs[uint32(subs.PonIntf)].FreeResourceID(uint32(subs.PonIntf),
229 ponresourcemanager.FLOW_ID, flowID)
230 return err
231 }
232 if err := AddFlow(subs, HsiaFlow, Downstream, flowID[0], allocID, gemID); err != nil {
233 return err
234 }
235 }
236 }
Girish Gowdra64503432020-01-07 10:59:10 +0530237 return nil
238}