blob: a06b29b3788a26452b7a90e9a608d1ec433226be [file] [log] [blame]
Thiyagarajan Subramanib83b0432020-01-08 13:43:28 +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
Thiyagarajan Subramanic4f8da82020-02-05 16:08:26 +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"
Thiyagarajan Subramanib83b0432020-01-08 13:43:28 +053028 "golang.org/x/net/context"
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 DtWorkFlow struct {
37}
38
Thiyagarajan Subramanic4f8da82020-02-05 16:08:26 +053039func ProvisionDtNniTrapFlow(oo oop.OpenoltClient, config *config.OpenOltScaleTesterConfig, rsrMgr *OpenOltResourceMgr) error {
40 _ = AddLldpFlow(oo, config, rsrMgr)
41
42 return nil
43}
44
Thiyagarajan Subramanib83b0432020-01-08 13:43:28 +053045func (dt DtWorkFlow) ProvisionScheds(subs *Subscriber) error {
46 var trafficSched []*tp_pb.TrafficScheduler
47
48 log.Info("provisioning-scheds")
49
50 if trafficSched = getTrafficSched(subs, tp_pb.Direction_DOWNSTREAM); trafficSched == nil {
51 log.Error("ds-traffic-sched-is-nil")
52 return errors.New(ReasonCodeToReasonString(SCHED_CREATION_FAILED))
53 }
54
55 log.Debugw("Sending Traffic scheduler create to device",
56 log.Fields{"Direction": tp_pb.Direction_DOWNSTREAM, "TrafficScheds": trafficSched})
57 if _, err := subs.OpenOltClient.CreateTrafficSchedulers(context.Background(), &tp_pb.TrafficSchedulers{
58 IntfId: subs.PonIntf, OnuId: subs.OnuID,
59 UniId: subs.UniID, PortNo: subs.UniPortNo,
60 TrafficScheds: trafficSched}); err != nil {
61 log.Errorw("Failed to create traffic schedulers", log.Fields{"error": err})
62 return errors.New(ReasonCodeToReasonString(SCHED_CREATION_FAILED))
63 }
64
65 if trafficSched = getTrafficSched(subs, tp_pb.Direction_UPSTREAM); trafficSched == nil {
66 log.Error("us-traffic-sched-is-nil")
67 return errors.New(ReasonCodeToReasonString(SCHED_CREATION_FAILED))
68 }
69
70 log.Debugw("Sending Traffic scheduler create to device",
71 log.Fields{"Direction": tp_pb.Direction_UPSTREAM, "TrafficScheds": trafficSched})
72 if _, err := subs.OpenOltClient.CreateTrafficSchedulers(context.Background(), &tp_pb.TrafficSchedulers{
73 IntfId: subs.PonIntf, OnuId: subs.OnuID,
74 UniId: subs.UniID, PortNo: subs.UniPortNo,
75 TrafficScheds: trafficSched}); err != nil {
76 log.Errorw("Failed to create traffic schedulers", log.Fields{"error": err})
77 return errors.New(ReasonCodeToReasonString(SCHED_CREATION_FAILED))
78 }
79
80 return nil
81}
82
83func (dt DtWorkFlow) ProvisionQueues(subs *Subscriber) error {
84 log.Info("provisioning-queues")
85
86 var trafficQueues []*tp_pb.TrafficQueue
87 if trafficQueues = getTrafficQueues(subs, tp_pb.Direction_DOWNSTREAM); trafficQueues == nil {
88 log.Error("Failed to create traffic queues")
89 return errors.New(ReasonCodeToReasonString(QUEUE_CREATION_FAILED))
90 }
91
92 // On receiving the CreateTrafficQueues request, the driver should create corresponding
93 // downstream queues.
94 log.Debugw("Sending Traffic Queues create to device",
95 log.Fields{"Direction": tp_pb.Direction_DOWNSTREAM, "TrafficQueues": trafficQueues})
96 if _, err := subs.OpenOltClient.CreateTrafficQueues(context.Background(),
97 &tp_pb.TrafficQueues{IntfId: subs.PonIntf, OnuId: subs.OnuID,
98 UniId: subs.UniID, PortNo: subs.UniPortNo,
99 TrafficQueues: trafficQueues}); err != nil {
100 log.Errorw("Failed to create traffic queues in device", log.Fields{"error": err})
101 return errors.New(ReasonCodeToReasonString(QUEUE_CREATION_FAILED))
102 }
103
104 if trafficQueues = getTrafficQueues(subs, tp_pb.Direction_UPSTREAM); trafficQueues == nil {
105 log.Error("Failed to create traffic queues")
106 return errors.New(ReasonCodeToReasonString(QUEUE_CREATION_FAILED))
107 }
108
109 // On receiving the CreateTrafficQueues request, the driver should create corresponding
110 // upstream queues.
111 log.Debugw("Sending Traffic Queues create to device",
112 log.Fields{"Direction": tp_pb.Direction_UPSTREAM, "TrafficQueues": trafficQueues})
113 if _, err := subs.OpenOltClient.CreateTrafficQueues(context.Background(),
114 &tp_pb.TrafficQueues{IntfId: subs.PonIntf, OnuId: subs.OnuID,
115 UniId: subs.UniID, PortNo: subs.UniPortNo,
116 TrafficQueues: trafficQueues}); err != nil {
117 log.Errorw("Failed to create traffic queues in device", log.Fields{"error": err})
118 return errors.New(ReasonCodeToReasonString(QUEUE_CREATION_FAILED))
119 }
120
121 return nil
122}
123
124func (dt DtWorkFlow) ProvisionEapFlow(subs *Subscriber) error {
125 log.Info("dt-workflow-does-not-require-eap-support--nothing-to-do")
126 return nil
127}
128
Girish Gowdraef1b7c42020-01-23 16:27:48 +0530129func (dt DtWorkFlow) ProvisionDhcpIPV4Flow(subs *Subscriber) error {
130 log.Info("dt-workflow-does-not-require-dhcp-ipv4-support--nothing-to-do")
131 return nil
132}
133
134func (dt DtWorkFlow) ProvisionDhcpIPV6Flow(subs *Subscriber) error {
135 log.Info("dt-workflow-does-not-require-dhcp-ipv6-support--nothing-to-do")
Thiyagarajan Subramanib83b0432020-01-08 13:43:28 +0530136 return nil
137}
138
139func (dt DtWorkFlow) ProvisionIgmpFlow(subs *Subscriber) error {
140 log.Info("dt-workflow-does-not-support-igmp-yet--nothing-to-do")
141 return nil
142}
143
144func (dt DtWorkFlow) ProvisionHsiaFlow(subs *Subscriber) error {
145 var err error
146 var flowID []uint32
147 var gemPortIDs []uint32
148
149 var allocID = subs.TpInstance[subs.TestConfig.TpIDList[0]].UsScheduler.AllocID
150 for _, gem := range subs.TpInstance[subs.TestConfig.TpIDList[0]].UpstreamGemPortAttributeList {
151 gemPortIDs = append(gemPortIDs, gem.GemportID)
152 }
153
Girish Gowdrad4bdd372020-03-09 14:56:15 -0700154 for idx, gemID := range gemPortIDs {
155 pBitMap := subs.TpInstance[subs.TestConfig.TpIDList[0]].UpstreamGemPortAttributeList[idx].PbitMap
156 for pos, pbitSet := range strings.TrimPrefix(pBitMap, "0b") {
157 if pbitSet == '1' {
158 pcp := uint32(len(strings.TrimPrefix(pBitMap, "0b"))) - 1 - uint32(pos)
Orhan Kupusoglu66b00d82020-03-13 12:06:33 +0300159 if flowID, err = subs.RsrMgr.ResourceMgrs[uint32(subs.PonIntf)].GetResourceID(context.Background(), uint32(subs.PonIntf),
Girish Gowdrad4bdd372020-03-09 14:56:15 -0700160 ponresourcemanager.FLOW_ID, 1); err != nil {
161 return errors.New(ReasonCodeToReasonString(FLOW_ID_GENERATION_FAILED))
162 } else {
163 if err := AddFlow(subs, HsiaFlow, Upstream, flowID[0], allocID, gemID, pcp); err != nil {
Orhan Kupusoglu66b00d82020-03-13 12:06:33 +0300164 subs.RsrMgr.ResourceMgrs[uint32(subs.PonIntf)].FreeResourceID(context.Background(), uint32(subs.PonIntf),
Girish Gowdrad4bdd372020-03-09 14:56:15 -0700165 ponresourcemanager.FLOW_ID, flowID)
166 return err
167 }
168 if err := AddFlow(subs, HsiaFlow, Downstream, flowID[0], allocID, gemID, pcp); err != nil {
169 return err
170 }
171 }
Thiyagarajan Subramanib83b0432020-01-08 13:43:28 +0530172 }
173 }
174 }
175 return nil
176}
Orhan Kupusoglu66b00d82020-03-13 12:06:33 +0300177
178func (dt DtWorkFlow) ProvisionVoipFlow(subs *Subscriber) error {
179 log.Info("dt-workflow-does-not-support-voip-yet--nothing-to-do")
180 return nil
181}
182
183func (dt DtWorkFlow) ProvisionVodFlow(subs *Subscriber) error {
184 log.Info("dt-workflow-does-not-support-vod-yet--nothing-to-do")
185 return nil
186}
187
188func (dt DtWorkFlow) ProvisionMgmtFlow(subs *Subscriber) error {
189 log.Info("dt-workflow-does-not-support-mgmt-yet--nothing-to-do")
190 return nil
191}
192
193func (dt DtWorkFlow) ProvisionMulticastFlow(subs *Subscriber) error {
194 log.Info("dt-workflow-does-not-support-multicast-yet--nothing-to-do")
195 return nil
196}