blob: 97870ee859ea9cb75ae1f922c8ae41e0907a91c7 [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"
Girish Gowdra5d7d6442020-09-08 17:03:11 -070024 "github.com/opencord/voltha-lib-go/v4/pkg/log"
25 oop "github.com/opencord/voltha-protos/v4/go/openolt"
26 tp_pb "github.com/opencord/voltha-protos/v4/go/tech_profile"
Thiyagarajan Subramanib83b0432020-01-08 13:43:28 +053027 "golang.org/x/net/context"
28)
29
Thiyagarajan Subramanib83b0432020-01-08 13:43:28 +053030// A dummy struct to comply with the WorkFlow interface.
31type DtWorkFlow struct {
32}
33
Thiyagarajan Subramanic4f8da82020-02-05 16:08:26 +053034func ProvisionDtNniTrapFlow(oo oop.OpenoltClient, config *config.OpenOltScaleTesterConfig, rsrMgr *OpenOltResourceMgr) error {
35 _ = AddLldpFlow(oo, config, rsrMgr)
36
37 return nil
38}
39
Thiyagarajan Subramanib83b0432020-01-08 13:43:28 +053040func (dt DtWorkFlow) ProvisionScheds(subs *Subscriber) error {
41 var trafficSched []*tp_pb.TrafficScheduler
42
Girish Gowdra5d7d6442020-09-08 17:03:11 -070043 logger.Info(nil, "provisioning-scheds")
Thiyagarajan Subramanib83b0432020-01-08 13:43:28 +053044
45 if trafficSched = getTrafficSched(subs, tp_pb.Direction_DOWNSTREAM); trafficSched == nil {
Girish Gowdra5d7d6442020-09-08 17:03:11 -070046 logger.Error(nil, "ds-traffic-sched-is-nil")
Thiyagarajan Subramanib83b0432020-01-08 13:43:28 +053047 return errors.New(ReasonCodeToReasonString(SCHED_CREATION_FAILED))
48 }
49
Girish Gowdra5d7d6442020-09-08 17:03:11 -070050 logger.Debugw(nil, "Sending Traffic scheduler create to device",
Thiyagarajan Subramanib83b0432020-01-08 13:43:28 +053051 log.Fields{"Direction": tp_pb.Direction_DOWNSTREAM, "TrafficScheds": trafficSched})
52 if _, err := subs.OpenOltClient.CreateTrafficSchedulers(context.Background(), &tp_pb.TrafficSchedulers{
53 IntfId: subs.PonIntf, OnuId: subs.OnuID,
54 UniId: subs.UniID, PortNo: subs.UniPortNo,
55 TrafficScheds: trafficSched}); err != nil {
Girish Gowdra5d7d6442020-09-08 17:03:11 -070056 logger.Errorw(nil, "Failed to create traffic schedulers", log.Fields{"error": err})
Thiyagarajan Subramanib83b0432020-01-08 13:43:28 +053057 return errors.New(ReasonCodeToReasonString(SCHED_CREATION_FAILED))
58 }
59
60 if trafficSched = getTrafficSched(subs, tp_pb.Direction_UPSTREAM); trafficSched == nil {
Girish Gowdra5d7d6442020-09-08 17:03:11 -070061 logger.Error(nil, "us-traffic-sched-is-nil")
Thiyagarajan Subramanib83b0432020-01-08 13:43:28 +053062 return errors.New(ReasonCodeToReasonString(SCHED_CREATION_FAILED))
63 }
64
Girish Gowdra5d7d6442020-09-08 17:03:11 -070065 logger.Debugw(nil, "Sending Traffic scheduler create to device",
Thiyagarajan Subramanib83b0432020-01-08 13:43:28 +053066 log.Fields{"Direction": tp_pb.Direction_UPSTREAM, "TrafficScheds": trafficSched})
67 if _, err := subs.OpenOltClient.CreateTrafficSchedulers(context.Background(), &tp_pb.TrafficSchedulers{
68 IntfId: subs.PonIntf, OnuId: subs.OnuID,
69 UniId: subs.UniID, PortNo: subs.UniPortNo,
70 TrafficScheds: trafficSched}); err != nil {
Girish Gowdra5d7d6442020-09-08 17:03:11 -070071 logger.Errorw(nil, "Failed to create traffic schedulers", log.Fields{"error": err})
Thiyagarajan Subramanib83b0432020-01-08 13:43:28 +053072 return errors.New(ReasonCodeToReasonString(SCHED_CREATION_FAILED))
73 }
74
75 return nil
76}
77
78func (dt DtWorkFlow) ProvisionQueues(subs *Subscriber) error {
Girish Gowdra5d7d6442020-09-08 17:03:11 -070079 logger.Info(nil, "provisioning-queues")
Thiyagarajan Subramanib83b0432020-01-08 13:43:28 +053080
81 var trafficQueues []*tp_pb.TrafficQueue
82 if trafficQueues = getTrafficQueues(subs, tp_pb.Direction_DOWNSTREAM); trafficQueues == nil {
Girish Gowdra5d7d6442020-09-08 17:03:11 -070083 logger.Error(nil, "Failed to create traffic queues")
Thiyagarajan Subramanib83b0432020-01-08 13:43:28 +053084 return errors.New(ReasonCodeToReasonString(QUEUE_CREATION_FAILED))
85 }
86
87 // On receiving the CreateTrafficQueues request, the driver should create corresponding
88 // downstream queues.
Girish Gowdra5d7d6442020-09-08 17:03:11 -070089 logger.Debugw(nil, "Sending Traffic Queues create to device",
Thiyagarajan Subramanib83b0432020-01-08 13:43:28 +053090 log.Fields{"Direction": tp_pb.Direction_DOWNSTREAM, "TrafficQueues": trafficQueues})
91 if _, err := subs.OpenOltClient.CreateTrafficQueues(context.Background(),
92 &tp_pb.TrafficQueues{IntfId: subs.PonIntf, OnuId: subs.OnuID,
93 UniId: subs.UniID, PortNo: subs.UniPortNo,
94 TrafficQueues: trafficQueues}); err != nil {
Girish Gowdra5d7d6442020-09-08 17:03:11 -070095 logger.Errorw(nil, "Failed to create traffic queues in device", log.Fields{"error": err})
Thiyagarajan Subramanib83b0432020-01-08 13:43:28 +053096 return errors.New(ReasonCodeToReasonString(QUEUE_CREATION_FAILED))
97 }
98
99 if trafficQueues = getTrafficQueues(subs, tp_pb.Direction_UPSTREAM); trafficQueues == nil {
Girish Gowdra5d7d6442020-09-08 17:03:11 -0700100 logger.Error(nil, "Failed to create traffic queues")
Thiyagarajan Subramanib83b0432020-01-08 13:43:28 +0530101 return errors.New(ReasonCodeToReasonString(QUEUE_CREATION_FAILED))
102 }
103
104 // On receiving the CreateTrafficQueues request, the driver should create corresponding
105 // upstream queues.
Girish Gowdra5d7d6442020-09-08 17:03:11 -0700106 logger.Debugw(nil, "Sending Traffic Queues create to device",
Thiyagarajan Subramanib83b0432020-01-08 13:43:28 +0530107 log.Fields{"Direction": tp_pb.Direction_UPSTREAM, "TrafficQueues": trafficQueues})
108 if _, err := subs.OpenOltClient.CreateTrafficQueues(context.Background(),
109 &tp_pb.TrafficQueues{IntfId: subs.PonIntf, OnuId: subs.OnuID,
110 UniId: subs.UniID, PortNo: subs.UniPortNo,
111 TrafficQueues: trafficQueues}); err != nil {
Girish Gowdra5d7d6442020-09-08 17:03:11 -0700112 logger.Errorw(nil, "Failed to create traffic queues in device", log.Fields{"error": err})
Thiyagarajan Subramanib83b0432020-01-08 13:43:28 +0530113 return errors.New(ReasonCodeToReasonString(QUEUE_CREATION_FAILED))
114 }
115
116 return nil
117}
118
119func (dt DtWorkFlow) ProvisionEapFlow(subs *Subscriber) error {
Girish Gowdra5d7d6442020-09-08 17:03:11 -0700120 logger.Info(nil, "dt-workflow-does-not-require-eap-support--nothing-to-do")
Thiyagarajan Subramanib83b0432020-01-08 13:43:28 +0530121 return nil
122}
123
Girish Gowdraef1b7c42020-01-23 16:27:48 +0530124func (dt DtWorkFlow) ProvisionDhcpIPV4Flow(subs *Subscriber) error {
Girish Gowdra5d7d6442020-09-08 17:03:11 -0700125 logger.Info(nil, "dt-workflow-does-not-require-dhcp-ipv4-support--nothing-to-do")
Girish Gowdraef1b7c42020-01-23 16:27:48 +0530126 return nil
127}
128
129func (dt DtWorkFlow) ProvisionDhcpIPV6Flow(subs *Subscriber) error {
Girish Gowdra5d7d6442020-09-08 17:03:11 -0700130 logger.Info(nil, "dt-workflow-does-not-require-dhcp-ipv6-support--nothing-to-do")
Thiyagarajan Subramanib83b0432020-01-08 13:43:28 +0530131 return nil
132}
133
134func (dt DtWorkFlow) ProvisionIgmpFlow(subs *Subscriber) error {
Girish Gowdra5d7d6442020-09-08 17:03:11 -0700135 logger.Info(nil, "dt-workflow-does-not-support-igmp-yet--nothing-to-do")
Thiyagarajan Subramanib83b0432020-01-08 13:43:28 +0530136 return nil
137}
138
139func (dt DtWorkFlow) ProvisionHsiaFlow(subs *Subscriber) error {
140 var err error
Girish Gowdra5d7d6442020-09-08 17:03:11 -0700141 var flowIDUs, flowIDDs uint64
Thiyagarajan Subramanib83b0432020-01-08 13:43:28 +0530142 var gemPortIDs []uint32
Girish Gowdra5d7d6442020-09-08 17:03:11 -0700143 pbitToGem := make(map[uint32]uint32)
Thiyagarajan Subramanib83b0432020-01-08 13:43:28 +0530144
145 var allocID = subs.TpInstance[subs.TestConfig.TpIDList[0]].UsScheduler.AllocID
146 for _, gem := range subs.TpInstance[subs.TestConfig.TpIDList[0]].UpstreamGemPortAttributeList {
147 gemPortIDs = append(gemPortIDs, gem.GemportID)
148 }
149
Girish Gowdrad4bdd372020-03-09 14:56:15 -0700150 for idx, gemID := range gemPortIDs {
151 pBitMap := subs.TpInstance[subs.TestConfig.TpIDList[0]].UpstreamGemPortAttributeList[idx].PbitMap
152 for pos, pbitSet := range strings.TrimPrefix(pBitMap, "0b") {
153 if pbitSet == '1' {
154 pcp := uint32(len(strings.TrimPrefix(pBitMap, "0b"))) - 1 - uint32(pos)
Girish Gowdra5d7d6442020-09-08 17:03:11 -0700155 pbitToGem[pcp] = gemID
Thiyagarajan Subramanib83b0432020-01-08 13:43:28 +0530156 }
157 }
158 }
Girish Gowdra5d7d6442020-09-08 17:03:11 -0700159
160 // This flowID is not the BAL flow ID now, it is the voltha-flow-id
161 if flowIDUs, err = subs.RsrMgr.GetFlowID(context.Background(), uint32(subs.PonIntf)); err != nil {
162 return errors.New(ReasonCodeToReasonString(FLOW_ID_GENERATION_FAILED))
163 }
164 if err := AddFlow(subs, HsiaFlow, Upstream, flowIDUs, allocID, 0, 0xff,
165 true, 0, pbitToGem); err != nil {
166 return err
167 }
168 if flowIDDs, err = subs.RsrMgr.GetFlowID(context.Background(), uint32(subs.PonIntf)); err != nil {
169 return errors.New(ReasonCodeToReasonString(FLOW_ID_GENERATION_FAILED))
170 }
171 if err := AddFlow(subs, HsiaFlow, Downstream, flowIDDs, allocID, 0, 0xff,
172 true, flowIDUs, pbitToGem); err != nil {
173 return err
174 }
175
Thiyagarajan Subramanib83b0432020-01-08 13:43:28 +0530176 return nil
177}
Orhan Kupusoglu66b00d82020-03-13 12:06:33 +0300178
179func (dt DtWorkFlow) ProvisionVoipFlow(subs *Subscriber) error {
Girish Gowdra5d7d6442020-09-08 17:03:11 -0700180 logger.Info(nil, "dt-workflow-does-not-support-voip-yet--nothing-to-do")
Orhan Kupusoglu66b00d82020-03-13 12:06:33 +0300181 return nil
182}
183
184func (dt DtWorkFlow) ProvisionVodFlow(subs *Subscriber) error {
Girish Gowdra5d7d6442020-09-08 17:03:11 -0700185 logger.Info(nil, "dt-workflow-does-not-support-vod-yet--nothing-to-do")
Orhan Kupusoglu66b00d82020-03-13 12:06:33 +0300186 return nil
187}
188
189func (dt DtWorkFlow) ProvisionMgmtFlow(subs *Subscriber) error {
Girish Gowdra5d7d6442020-09-08 17:03:11 -0700190 logger.Info(nil, "dt-workflow-does-not-support-mgmt-yet--nothing-to-do")
Orhan Kupusoglu66b00d82020-03-13 12:06:33 +0300191 return nil
192}
193
194func (dt DtWorkFlow) ProvisionMulticastFlow(subs *Subscriber) error {
Girish Gowdra5d7d6442020-09-08 17:03:11 -0700195 logger.Info(nil, "dt-workflow-does-not-support-multicast-yet--nothing-to-do")
Orhan Kupusoglu66b00d82020-03-13 12:06:33 +0300196 return nil
197}