blob: f20d8661cd45844a757deb05defa593ca02c6512 [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"
21 "github.com/opencord/openolt-scale-tester/config"
22 "github.com/opencord/voltha-lib-go/v2/pkg/log"
23 "github.com/opencord/voltha-lib-go/v2/pkg/ponresourcemanager"
24 oop "github.com/opencord/voltha-protos/v2/go/openolt"
25 tp_pb "github.com/opencord/voltha-protos/v2/go/tech_profile"
26 "golang.org/x/net/context"
27 "google.golang.org/grpc/codes"
28 "google.golang.org/grpc/status"
29)
30
31func init() {
32 _, _ = log.AddPackage(log.JSON, log.DebugLevel, nil)
33}
34
35// A dummy struct to comply with the WorkFlow interface.
36type AttWorkFlow struct {
37}
38
39func ProvisionAttNniTrapFlow(oo oop.OpenoltClient, config *config.OpenOltScaleTesterConfig, rsrMgr *OpenOltResourceMgr) error {
40 var flowID []uint32
41 var err error
42
43 if flowID, err = rsrMgr.ResourceMgrs[uint32(config.NniIntfID)].GetResourceID(uint32(config.NniIntfID),
44 ponresourcemanager.FLOW_ID, 1); err != nil {
45 return err
46 }
47
48 flowClassifier := &oop.Classifier{EthType: 2048, IpProto: 17, SrcPort: 67, DstPort: 68, PktTagType: "double_tag"}
49 actionCmd := &oop.ActionCmd{TrapToHost: true}
50 actionInfo := &oop.Action{Cmd: actionCmd}
51
52 flow := oop.Flow{AccessIntfId: -1, OnuId: -1, UniId: -1, FlowId: flowID[0],
53 FlowType: "downstream", AllocId: -1, GemportId: -1,
54 Classifier: flowClassifier, Action: actionInfo,
55 Priority: 1000, PortNo: 65536}
56
57 _, err = oo.FlowAdd(context.Background(), &flow)
58
59 st, _ := status.FromError(err)
60 if st.Code() == codes.AlreadyExists {
61 log.Debugw("Flow already exists", log.Fields{"err": err, "deviceFlow": flow})
62 return nil
63 }
64
65 if err != nil {
66 log.Errorw("Failed to Add flow to device", log.Fields{"err": err, "deviceFlow": flow})
67 rsrMgr.ResourceMgrs[uint32(config.NniIntfID)].FreeResourceID(uint32(config.NniIntfID), ponresourcemanager.FLOW_ID, flowID)
68 return err
69 }
70 log.Debugw("Flow added to device successfully ", log.Fields{"flow": flow})
71
72 return nil
73}
74
75func getTrafficSched(subs *Subscriber, direction tp_pb.Direction) []*tp_pb.TrafficScheduler {
76 var SchedCfg *tp_pb.SchedulerConfig
77
78 if direction == tp_pb.Direction_DOWNSTREAM {
79 SchedCfg = subs.RsrMgr.ResourceMgrs[subs.PonIntf].TechProfileMgr.
80 GetDsScheduler(subs.TpInstance[subs.TestConfig.TpIDList[0]])
81
82 } else {
83 SchedCfg = subs.RsrMgr.ResourceMgrs[subs.PonIntf].TechProfileMgr.
84 GetUsScheduler(subs.TpInstance[subs.TestConfig.TpIDList[0]])
85 }
86
87 // hard-code for now
88 cir := 16000
89 cbs := 5000
90 eir := 16000
91 ebs := 5000
92 pir := cir + eir
93 pbs := cbs + ebs
94
95 TrafficShaping := &tp_pb.TrafficShapingInfo{Cir: uint32(cir), Cbs: uint32(cbs), Pir: uint32(pir), Pbs: uint32(pbs)}
96
97 TrafficSched := []*tp_pb.TrafficScheduler{subs.RsrMgr.ResourceMgrs[subs.PonIntf].TechProfileMgr.
98 GetTrafficScheduler(subs.TpInstance[subs.TestConfig.TpIDList[0]], SchedCfg, TrafficShaping)}
99
100 return TrafficSched
101}
102
103func (att AttWorkFlow) ProvisionScheds(subs *Subscriber) error {
104 var trafficSched []*tp_pb.TrafficScheduler
105
106 log.Info("provisioning-scheds")
107
108 if trafficSched = getTrafficSched(subs, tp_pb.Direction_DOWNSTREAM); trafficSched == nil {
109 log.Error("ds-traffic-sched-is-nil")
110 return errors.New(ReasonCodeToReasonString(SCHED_CREATION_FAILED))
111 }
112
113 log.Debugw("Sending Traffic scheduler create to device",
114 log.Fields{"Direction": tp_pb.Direction_DOWNSTREAM, "TrafficScheds": trafficSched})
115 if _, err := subs.OpenOltClient.CreateTrafficSchedulers(context.Background(), &tp_pb.TrafficSchedulers{
116 IntfId: subs.PonIntf, OnuId: subs.OnuID,
117 UniId: subs.UniID, PortNo: subs.UniPortNo,
118 TrafficScheds: trafficSched}); err != nil {
119 log.Errorw("Failed to create traffic schedulers", log.Fields{"error": err})
120 return errors.New(ReasonCodeToReasonString(SCHED_CREATION_FAILED))
121 }
122
123 if trafficSched = getTrafficSched(subs, tp_pb.Direction_UPSTREAM); trafficSched == nil {
124 log.Error("us-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_UPSTREAM, "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 return nil
139}
140
141func getTrafficQueues(subs *Subscriber, direction tp_pb.Direction) []*tp_pb.TrafficQueue {
142
143 trafficQueues := subs.RsrMgr.ResourceMgrs[subs.PonIntf].TechProfileMgr.
144 GetTrafficQueues(subs.TpInstance[subs.TestConfig.TpIDList[0]], direction)
145
146 return trafficQueues
147}
148
149func (att AttWorkFlow) ProvisionQueues(subs *Subscriber) error {
150 log.Info("provisioning-queues")
151
152 var trafficQueues []*tp_pb.TrafficQueue
153 if trafficQueues = getTrafficQueues(subs, tp_pb.Direction_DOWNSTREAM); trafficQueues == nil {
154 log.Error("Failed to create traffic queues")
155 return errors.New(ReasonCodeToReasonString(QUEUE_CREATION_FAILED))
156 }
157
158 // On receiving the CreateTrafficQueues request, the driver should create corresponding
159 // downstream queues.
160 log.Debugw("Sending Traffic Queues create to device",
161 log.Fields{"Direction": tp_pb.Direction_DOWNSTREAM, "TrafficQueues": trafficQueues})
162 if _, err := subs.OpenOltClient.CreateTrafficQueues(context.Background(),
163 &tp_pb.TrafficQueues{IntfId: subs.PonIntf, OnuId: subs.OnuID,
164 UniId: subs.UniID, PortNo: subs.UniPortNo,
165 TrafficQueues: trafficQueues}); err != nil {
166 log.Errorw("Failed to create traffic queues in device", log.Fields{"error": err})
167 return errors.New(ReasonCodeToReasonString(QUEUE_CREATION_FAILED))
168 }
169
170 if trafficQueues = getTrafficQueues(subs, tp_pb.Direction_UPSTREAM); trafficQueues == nil {
171 log.Error("Failed to create traffic queues")
172 return errors.New(ReasonCodeToReasonString(QUEUE_CREATION_FAILED))
173 }
174
175 // On receiving the CreateTrafficQueues request, the driver should create corresponding
176 // upstream queues.
177 log.Debugw("Sending Traffic Queues create to device",
178 log.Fields{"Direction": tp_pb.Direction_UPSTREAM, "TrafficQueues": trafficQueues})
179 if _, err := subs.OpenOltClient.CreateTrafficQueues(context.Background(),
180 &tp_pb.TrafficQueues{IntfId: subs.PonIntf, OnuId: subs.OnuID,
181 UniId: subs.UniID, PortNo: subs.UniPortNo,
182 TrafficQueues: trafficQueues}); err != nil {
183 log.Errorw("Failed to create traffic queues in device", log.Fields{"error": err})
184 return errors.New(ReasonCodeToReasonString(QUEUE_CREATION_FAILED))
185 }
186
187 return nil
188}
189
190func (att AttWorkFlow) ProvisionEapFlow(subs *Subscriber) error {
191 log.Info("provisioning-eap--att")
192
193 var err error
194 var flowID []uint32
195 var gemPortIDs []uint32
196
197 var allocID = subs.TpInstance[subs.TestConfig.TpIDList[0]].UsScheduler.AllocID
198
199 for _, gem := range subs.TpInstance[subs.TestConfig.TpIDList[0]].UpstreamGemPortAttributeList {
200 gemPortIDs = append(gemPortIDs, gem.GemportID)
201 }
202
203 for _, gemID := range gemPortIDs {
204 if flowID, err = subs.RsrMgr.ResourceMgrs[uint32(subs.PonIntf)].GetResourceID(uint32(subs.PonIntf),
205 ponresourcemanager.FLOW_ID, 1); err != nil {
206 return errors.New(ReasonCodeToReasonString(FLOW_ADD_FAILED))
207 }
208 flowClassifier := &oop.Classifier{EthType: 34958, OVid: subs.Ctag, PktTagType: "single_tag"}
209 actionCmd := &oop.ActionCmd{TrapToHost: true}
210 actionInfo := &oop.Action{Cmd: actionCmd}
211
212 flow := oop.Flow{AccessIntfId: int32(subs.PonIntf), OnuId: int32(subs.OnuID),
213 UniId: int32(subs.UniID), FlowId: flowID[0],
214 FlowType: "upstream", AllocId: int32(allocID), GemportId: int32(gemID),
215 Classifier: flowClassifier, Action: actionInfo,
216 Priority: 1000, PortNo: subs.UniPortNo}
217
218 _, err = subs.OpenOltClient.FlowAdd(context.Background(), &flow)
219
220 st, _ := status.FromError(err)
221 if st.Code() == codes.AlreadyExists {
222 log.Debugw("Flow already exists", log.Fields{"err": err, "deviceFlow": flow})
223 continue
224 }
225
226 if err != nil {
227 log.Errorw("Failed to Add flow to device", log.Fields{"err": err, "deviceFlow": flow})
228 subs.RsrMgr.ResourceMgrs[uint32(subs.PonIntf)].FreeResourceID(uint32(subs.PonIntf),
229 ponresourcemanager.FLOW_ID, flowID)
230 return errors.New(ReasonCodeToReasonString(FLOW_ADD_FAILED))
231 }
232 log.Debugw("Flow added to device successfully ", log.Fields{"flow": flow})
233 }
234 return nil
235}
236
237func (att AttWorkFlow) ProvisionDhcpFlow(subs *Subscriber) error {
238 // TODO
239 log.Info("provisioning-dhcp")
240 return nil
241}
242
243func (att AttWorkFlow) ProvisionIgmpFlow(subs *Subscriber) error {
244 log.Info("att-workflow-does-not-support-igmp-yet--nothing-to-do")
245 return nil
246}
247
248func (att AttWorkFlow) ProvisionHsiaFlow(subs *Subscriber) error {
249 // TODO
250 log.Info("provisioning-hsia")
251 return nil
252}