Thiyagarajan Subramani | b83b043 | 2020-01-08 13:43:28 +0530 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package core |
| 18 | |
| 19 | import ( |
| 20 | "errors" |
Girish Gowdra | d4bdd37 | 2020-03-09 14:56:15 -0700 | [diff] [blame] | 21 | "strings" |
Thiyagarajan Subramani | b83b043 | 2020-01-08 13:43:28 +0530 | [diff] [blame] | 22 | |
Thiyagarajan Subramani | c4f8da8 | 2020-02-05 16:08:26 +0530 | [diff] [blame] | 23 | "github.com/opencord/openolt-scale-tester/config" |
Girish Gowdra | 390f12f | 2021-07-01 15:53:49 -0700 | [diff] [blame] | 24 | "github.com/opencord/voltha-lib-go/v7/pkg/log" |
| 25 | oop "github.com/opencord/voltha-protos/v5/go/openolt" |
| 26 | tp_pb "github.com/opencord/voltha-protos/v5/go/tech_profile" |
Thiyagarajan Subramani | b83b043 | 2020-01-08 13:43:28 +0530 | [diff] [blame] | 27 | "golang.org/x/net/context" |
| 28 | ) |
| 29 | |
Thiyagarajan Subramani | b83b043 | 2020-01-08 13:43:28 +0530 | [diff] [blame] | 30 | // A dummy struct to comply with the WorkFlow interface. |
| 31 | type DtWorkFlow struct { |
| 32 | } |
| 33 | |
Thiyagarajan Subramani | c4f8da8 | 2020-02-05 16:08:26 +0530 | [diff] [blame] | 34 | func ProvisionDtNniTrapFlow(oo oop.OpenoltClient, config *config.OpenOltScaleTesterConfig, rsrMgr *OpenOltResourceMgr) error { |
| 35 | _ = AddLldpFlow(oo, config, rsrMgr) |
| 36 | |
| 37 | return nil |
| 38 | } |
| 39 | |
Thiyagarajan Subramani | b83b043 | 2020-01-08 13:43:28 +0530 | [diff] [blame] | 40 | func (dt DtWorkFlow) ProvisionScheds(subs *Subscriber) error { |
| 41 | var trafficSched []*tp_pb.TrafficScheduler |
| 42 | |
Girish Gowdra | 5d7d644 | 2020-09-08 17:03:11 -0700 | [diff] [blame] | 43 | logger.Info(nil, "provisioning-scheds") |
Thiyagarajan Subramani | b83b043 | 2020-01-08 13:43:28 +0530 | [diff] [blame] | 44 | |
| 45 | if trafficSched = getTrafficSched(subs, tp_pb.Direction_DOWNSTREAM); trafficSched == nil { |
Girish Gowdra | 5d7d644 | 2020-09-08 17:03:11 -0700 | [diff] [blame] | 46 | logger.Error(nil, "ds-traffic-sched-is-nil") |
Thiyagarajan Subramani | b83b043 | 2020-01-08 13:43:28 +0530 | [diff] [blame] | 47 | return errors.New(ReasonCodeToReasonString(SCHED_CREATION_FAILED)) |
| 48 | } |
| 49 | |
Girish Gowdra | 5d7d644 | 2020-09-08 17:03:11 -0700 | [diff] [blame] | 50 | logger.Debugw(nil, "Sending Traffic scheduler create to device", |
Thiyagarajan Subramani | b83b043 | 2020-01-08 13:43:28 +0530 | [diff] [blame] | 51 | 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 Gowdra | 5d7d644 | 2020-09-08 17:03:11 -0700 | [diff] [blame] | 56 | logger.Errorw(nil, "Failed to create traffic schedulers", log.Fields{"error": err}) |
Thiyagarajan Subramani | b83b043 | 2020-01-08 13:43:28 +0530 | [diff] [blame] | 57 | return errors.New(ReasonCodeToReasonString(SCHED_CREATION_FAILED)) |
| 58 | } |
| 59 | |
| 60 | if trafficSched = getTrafficSched(subs, tp_pb.Direction_UPSTREAM); trafficSched == nil { |
Girish Gowdra | 5d7d644 | 2020-09-08 17:03:11 -0700 | [diff] [blame] | 61 | logger.Error(nil, "us-traffic-sched-is-nil") |
Thiyagarajan Subramani | b83b043 | 2020-01-08 13:43:28 +0530 | [diff] [blame] | 62 | return errors.New(ReasonCodeToReasonString(SCHED_CREATION_FAILED)) |
| 63 | } |
| 64 | |
Girish Gowdra | 5d7d644 | 2020-09-08 17:03:11 -0700 | [diff] [blame] | 65 | logger.Debugw(nil, "Sending Traffic scheduler create to device", |
Thiyagarajan Subramani | b83b043 | 2020-01-08 13:43:28 +0530 | [diff] [blame] | 66 | 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 Gowdra | 5d7d644 | 2020-09-08 17:03:11 -0700 | [diff] [blame] | 71 | logger.Errorw(nil, "Failed to create traffic schedulers", log.Fields{"error": err}) |
Thiyagarajan Subramani | b83b043 | 2020-01-08 13:43:28 +0530 | [diff] [blame] | 72 | return errors.New(ReasonCodeToReasonString(SCHED_CREATION_FAILED)) |
| 73 | } |
| 74 | |
| 75 | return nil |
| 76 | } |
| 77 | |
| 78 | func (dt DtWorkFlow) ProvisionQueues(subs *Subscriber) error { |
Girish Gowdra | 5d7d644 | 2020-09-08 17:03:11 -0700 | [diff] [blame] | 79 | logger.Info(nil, "provisioning-queues") |
Thiyagarajan Subramani | b83b043 | 2020-01-08 13:43:28 +0530 | [diff] [blame] | 80 | |
| 81 | var trafficQueues []*tp_pb.TrafficQueue |
| 82 | if trafficQueues = getTrafficQueues(subs, tp_pb.Direction_DOWNSTREAM); trafficQueues == nil { |
Girish Gowdra | 5d7d644 | 2020-09-08 17:03:11 -0700 | [diff] [blame] | 83 | logger.Error(nil, "Failed to create traffic queues") |
Thiyagarajan Subramani | b83b043 | 2020-01-08 13:43:28 +0530 | [diff] [blame] | 84 | return errors.New(ReasonCodeToReasonString(QUEUE_CREATION_FAILED)) |
| 85 | } |
| 86 | |
| 87 | // On receiving the CreateTrafficQueues request, the driver should create corresponding |
| 88 | // downstream queues. |
Girish Gowdra | 5d7d644 | 2020-09-08 17:03:11 -0700 | [diff] [blame] | 89 | logger.Debugw(nil, "Sending Traffic Queues create to device", |
Thiyagarajan Subramani | b83b043 | 2020-01-08 13:43:28 +0530 | [diff] [blame] | 90 | 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 Gowdra | 5d7d644 | 2020-09-08 17:03:11 -0700 | [diff] [blame] | 95 | logger.Errorw(nil, "Failed to create traffic queues in device", log.Fields{"error": err}) |
Thiyagarajan Subramani | b83b043 | 2020-01-08 13:43:28 +0530 | [diff] [blame] | 96 | return errors.New(ReasonCodeToReasonString(QUEUE_CREATION_FAILED)) |
| 97 | } |
| 98 | |
| 99 | if trafficQueues = getTrafficQueues(subs, tp_pb.Direction_UPSTREAM); trafficQueues == nil { |
Girish Gowdra | 5d7d644 | 2020-09-08 17:03:11 -0700 | [diff] [blame] | 100 | logger.Error(nil, "Failed to create traffic queues") |
Thiyagarajan Subramani | b83b043 | 2020-01-08 13:43:28 +0530 | [diff] [blame] | 101 | return errors.New(ReasonCodeToReasonString(QUEUE_CREATION_FAILED)) |
| 102 | } |
| 103 | |
| 104 | // On receiving the CreateTrafficQueues request, the driver should create corresponding |
| 105 | // upstream queues. |
Girish Gowdra | 5d7d644 | 2020-09-08 17:03:11 -0700 | [diff] [blame] | 106 | logger.Debugw(nil, "Sending Traffic Queues create to device", |
Thiyagarajan Subramani | b83b043 | 2020-01-08 13:43:28 +0530 | [diff] [blame] | 107 | 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 Gowdra | 5d7d644 | 2020-09-08 17:03:11 -0700 | [diff] [blame] | 112 | logger.Errorw(nil, "Failed to create traffic queues in device", log.Fields{"error": err}) |
Thiyagarajan Subramani | b83b043 | 2020-01-08 13:43:28 +0530 | [diff] [blame] | 113 | return errors.New(ReasonCodeToReasonString(QUEUE_CREATION_FAILED)) |
| 114 | } |
| 115 | |
| 116 | return nil |
| 117 | } |
| 118 | |
| 119 | func (dt DtWorkFlow) ProvisionEapFlow(subs *Subscriber) error { |
Girish Gowdra | 5d7d644 | 2020-09-08 17:03:11 -0700 | [diff] [blame] | 120 | logger.Info(nil, "dt-workflow-does-not-require-eap-support--nothing-to-do") |
Thiyagarajan Subramani | b83b043 | 2020-01-08 13:43:28 +0530 | [diff] [blame] | 121 | return nil |
| 122 | } |
| 123 | |
Girish Gowdra | ef1b7c4 | 2020-01-23 16:27:48 +0530 | [diff] [blame] | 124 | func (dt DtWorkFlow) ProvisionDhcpIPV4Flow(subs *Subscriber) error { |
Girish Gowdra | 5d7d644 | 2020-09-08 17:03:11 -0700 | [diff] [blame] | 125 | logger.Info(nil, "dt-workflow-does-not-require-dhcp-ipv4-support--nothing-to-do") |
Girish Gowdra | ef1b7c4 | 2020-01-23 16:27:48 +0530 | [diff] [blame] | 126 | return nil |
| 127 | } |
| 128 | |
| 129 | func (dt DtWorkFlow) ProvisionDhcpIPV6Flow(subs *Subscriber) error { |
Girish Gowdra | 5d7d644 | 2020-09-08 17:03:11 -0700 | [diff] [blame] | 130 | logger.Info(nil, "dt-workflow-does-not-require-dhcp-ipv6-support--nothing-to-do") |
Thiyagarajan Subramani | b83b043 | 2020-01-08 13:43:28 +0530 | [diff] [blame] | 131 | return nil |
| 132 | } |
| 133 | |
| 134 | func (dt DtWorkFlow) ProvisionIgmpFlow(subs *Subscriber) error { |
Girish Gowdra | 5d7d644 | 2020-09-08 17:03:11 -0700 | [diff] [blame] | 135 | logger.Info(nil, "dt-workflow-does-not-support-igmp-yet--nothing-to-do") |
Thiyagarajan Subramani | b83b043 | 2020-01-08 13:43:28 +0530 | [diff] [blame] | 136 | return nil |
| 137 | } |
| 138 | |
| 139 | func (dt DtWorkFlow) ProvisionHsiaFlow(subs *Subscriber) error { |
| 140 | var err error |
Girish Gowdra | 5d7d644 | 2020-09-08 17:03:11 -0700 | [diff] [blame] | 141 | var flowIDUs, flowIDDs uint64 |
Thiyagarajan Subramani | b83b043 | 2020-01-08 13:43:28 +0530 | [diff] [blame] | 142 | var gemPortIDs []uint32 |
Girish Gowdra | 5d7d644 | 2020-09-08 17:03:11 -0700 | [diff] [blame] | 143 | pbitToGem := make(map[uint32]uint32) |
Thiyagarajan Subramani | b83b043 | 2020-01-08 13:43:28 +0530 | [diff] [blame] | 144 | |
Girish Gowdra | 390f12f | 2021-07-01 15:53:49 -0700 | [diff] [blame] | 145 | var allocID = subs.TpInstance[subs.TestConfig.TpIDList[0]].UsScheduler.AllocId |
Thiyagarajan Subramani | b83b043 | 2020-01-08 13:43:28 +0530 | [diff] [blame] | 146 | for _, gem := range subs.TpInstance[subs.TestConfig.TpIDList[0]].UpstreamGemPortAttributeList { |
Girish Gowdra | 390f12f | 2021-07-01 15:53:49 -0700 | [diff] [blame] | 147 | gemPortIDs = append(gemPortIDs, gem.GemportId) |
Thiyagarajan Subramani | b83b043 | 2020-01-08 13:43:28 +0530 | [diff] [blame] | 148 | } |
| 149 | |
Girish Gowdra | d4bdd37 | 2020-03-09 14:56:15 -0700 | [diff] [blame] | 150 | 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 Gowdra | 5d7d644 | 2020-09-08 17:03:11 -0700 | [diff] [blame] | 155 | pbitToGem[pcp] = gemID |
Thiyagarajan Subramani | b83b043 | 2020-01-08 13:43:28 +0530 | [diff] [blame] | 156 | } |
| 157 | } |
| 158 | } |
Girish Gowdra | 5d7d644 | 2020-09-08 17:03:11 -0700 | [diff] [blame] | 159 | |
| 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 Subramani | b83b043 | 2020-01-08 13:43:28 +0530 | [diff] [blame] | 176 | return nil |
| 177 | } |
Orhan Kupusoglu | 66b00d8 | 2020-03-13 12:06:33 +0300 | [diff] [blame] | 178 | |
| 179 | func (dt DtWorkFlow) ProvisionVoipFlow(subs *Subscriber) error { |
Girish Gowdra | 5d7d644 | 2020-09-08 17:03:11 -0700 | [diff] [blame] | 180 | logger.Info(nil, "dt-workflow-does-not-support-voip-yet--nothing-to-do") |
Orhan Kupusoglu | 66b00d8 | 2020-03-13 12:06:33 +0300 | [diff] [blame] | 181 | return nil |
| 182 | } |
| 183 | |
| 184 | func (dt DtWorkFlow) ProvisionVodFlow(subs *Subscriber) error { |
Girish Gowdra | 5d7d644 | 2020-09-08 17:03:11 -0700 | [diff] [blame] | 185 | logger.Info(nil, "dt-workflow-does-not-support-vod-yet--nothing-to-do") |
Orhan Kupusoglu | 66b00d8 | 2020-03-13 12:06:33 +0300 | [diff] [blame] | 186 | return nil |
| 187 | } |
| 188 | |
| 189 | func (dt DtWorkFlow) ProvisionMgmtFlow(subs *Subscriber) error { |
Girish Gowdra | 5d7d644 | 2020-09-08 17:03:11 -0700 | [diff] [blame] | 190 | logger.Info(nil, "dt-workflow-does-not-support-mgmt-yet--nothing-to-do") |
Orhan Kupusoglu | 66b00d8 | 2020-03-13 12:06:33 +0300 | [diff] [blame] | 191 | return nil |
| 192 | } |
| 193 | |
| 194 | func (dt DtWorkFlow) ProvisionMulticastFlow(subs *Subscriber) error { |
Girish Gowdra | 5d7d644 | 2020-09-08 17:03:11 -0700 | [diff] [blame] | 195 | logger.Info(nil, "dt-workflow-does-not-support-multicast-yet--nothing-to-do") |
Orhan Kupusoglu | 66b00d8 | 2020-03-13 12:06:33 +0300 | [diff] [blame] | 196 | return nil |
| 197 | } |