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" |
Thiyagarajan Subramani | b83b043 | 2020-01-08 13:43:28 +0530 | [diff] [blame] | 24 | "github.com/opencord/voltha-lib-go/v2/pkg/log" |
| 25 | "github.com/opencord/voltha-lib-go/v2/pkg/ponresourcemanager" |
Thiyagarajan Subramani | c4f8da8 | 2020-02-05 16:08:26 +0530 | [diff] [blame] | 26 | oop "github.com/opencord/voltha-protos/v2/go/openolt" |
Thiyagarajan Subramani | b83b043 | 2020-01-08 13:43:28 +0530 | [diff] [blame] | 27 | tp_pb "github.com/opencord/voltha-protos/v2/go/tech_profile" |
| 28 | "golang.org/x/net/context" |
| 29 | ) |
| 30 | |
| 31 | func init() { |
| 32 | _, _ = log.AddPackage(log.JSON, log.DebugLevel, nil) |
| 33 | } |
| 34 | |
| 35 | // A dummy struct to comply with the WorkFlow interface. |
| 36 | type DtWorkFlow struct { |
| 37 | } |
| 38 | |
Thiyagarajan Subramani | c4f8da8 | 2020-02-05 16:08:26 +0530 | [diff] [blame] | 39 | func ProvisionDtNniTrapFlow(oo oop.OpenoltClient, config *config.OpenOltScaleTesterConfig, rsrMgr *OpenOltResourceMgr) error { |
| 40 | _ = AddLldpFlow(oo, config, rsrMgr) |
| 41 | |
| 42 | return nil |
| 43 | } |
| 44 | |
Thiyagarajan Subramani | b83b043 | 2020-01-08 13:43:28 +0530 | [diff] [blame] | 45 | func (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 | |
| 83 | func (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 | |
| 124 | func (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 Gowdra | ef1b7c4 | 2020-01-23 16:27:48 +0530 | [diff] [blame] | 129 | func (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 | |
| 134 | func (dt DtWorkFlow) ProvisionDhcpIPV6Flow(subs *Subscriber) error { |
| 135 | log.Info("dt-workflow-does-not-require-dhcp-ipv6-support--nothing-to-do") |
Thiyagarajan Subramani | b83b043 | 2020-01-08 13:43:28 +0530 | [diff] [blame] | 136 | return nil |
| 137 | } |
| 138 | |
| 139 | func (dt DtWorkFlow) ProvisionIgmpFlow(subs *Subscriber) error { |
| 140 | log.Info("dt-workflow-does-not-support-igmp-yet--nothing-to-do") |
| 141 | return nil |
| 142 | } |
| 143 | |
| 144 | func (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 Gowdra | d4bdd37 | 2020-03-09 14:56:15 -0700 | [diff] [blame^] | 154 | 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) |
| 159 | if flowID, err = subs.RsrMgr.ResourceMgrs[uint32(subs.PonIntf)].GetResourceID(uint32(subs.PonIntf), |
| 160 | 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 { |
| 164 | subs.RsrMgr.ResourceMgrs[uint32(subs.PonIntf)].FreeResourceID(uint32(subs.PonIntf), |
| 165 | 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 Subramani | b83b043 | 2020-01-08 13:43:28 +0530 | [diff] [blame] | 172 | } |
| 173 | } |
| 174 | } |
| 175 | return nil |
| 176 | } |