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" |
| 21 | |
Thiyagarajan Subramani | c4f8da8 | 2020-02-05 16:08:26 +0530 | [diff] [blame^] | 22 | "github.com/opencord/openolt-scale-tester/config" |
Thiyagarajan Subramani | b83b043 | 2020-01-08 13:43:28 +0530 | [diff] [blame] | 23 | "github.com/opencord/voltha-lib-go/v2/pkg/log" |
| 24 | "github.com/opencord/voltha-lib-go/v2/pkg/ponresourcemanager" |
Thiyagarajan Subramani | c4f8da8 | 2020-02-05 16:08:26 +0530 | [diff] [blame^] | 25 | oop "github.com/opencord/voltha-protos/v2/go/openolt" |
Thiyagarajan Subramani | b83b043 | 2020-01-08 13:43:28 +0530 | [diff] [blame] | 26 | tp_pb "github.com/opencord/voltha-protos/v2/go/tech_profile" |
| 27 | "golang.org/x/net/context" |
| 28 | ) |
| 29 | |
| 30 | func init() { |
| 31 | _, _ = log.AddPackage(log.JSON, log.DebugLevel, nil) |
| 32 | } |
| 33 | |
| 34 | // A dummy struct to comply with the WorkFlow interface. |
| 35 | type DtWorkFlow struct { |
| 36 | } |
| 37 | |
Thiyagarajan Subramani | c4f8da8 | 2020-02-05 16:08:26 +0530 | [diff] [blame^] | 38 | func ProvisionDtNniTrapFlow(oo oop.OpenoltClient, config *config.OpenOltScaleTesterConfig, rsrMgr *OpenOltResourceMgr) error { |
| 39 | _ = AddLldpFlow(oo, config, rsrMgr) |
| 40 | |
| 41 | return nil |
| 42 | } |
| 43 | |
Thiyagarajan Subramani | b83b043 | 2020-01-08 13:43:28 +0530 | [diff] [blame] | 44 | func (dt DtWorkFlow) ProvisionScheds(subs *Subscriber) error { |
| 45 | var trafficSched []*tp_pb.TrafficScheduler |
| 46 | |
| 47 | log.Info("provisioning-scheds") |
| 48 | |
| 49 | if trafficSched = getTrafficSched(subs, tp_pb.Direction_DOWNSTREAM); trafficSched == nil { |
| 50 | log.Error("ds-traffic-sched-is-nil") |
| 51 | return errors.New(ReasonCodeToReasonString(SCHED_CREATION_FAILED)) |
| 52 | } |
| 53 | |
| 54 | log.Debugw("Sending Traffic scheduler create to device", |
| 55 | log.Fields{"Direction": tp_pb.Direction_DOWNSTREAM, "TrafficScheds": trafficSched}) |
| 56 | if _, err := subs.OpenOltClient.CreateTrafficSchedulers(context.Background(), &tp_pb.TrafficSchedulers{ |
| 57 | IntfId: subs.PonIntf, OnuId: subs.OnuID, |
| 58 | UniId: subs.UniID, PortNo: subs.UniPortNo, |
| 59 | TrafficScheds: trafficSched}); err != nil { |
| 60 | log.Errorw("Failed to create traffic schedulers", log.Fields{"error": err}) |
| 61 | return errors.New(ReasonCodeToReasonString(SCHED_CREATION_FAILED)) |
| 62 | } |
| 63 | |
| 64 | if trafficSched = getTrafficSched(subs, tp_pb.Direction_UPSTREAM); trafficSched == nil { |
| 65 | log.Error("us-traffic-sched-is-nil") |
| 66 | return errors.New(ReasonCodeToReasonString(SCHED_CREATION_FAILED)) |
| 67 | } |
| 68 | |
| 69 | log.Debugw("Sending Traffic scheduler create to device", |
| 70 | log.Fields{"Direction": tp_pb.Direction_UPSTREAM, "TrafficScheds": trafficSched}) |
| 71 | if _, err := subs.OpenOltClient.CreateTrafficSchedulers(context.Background(), &tp_pb.TrafficSchedulers{ |
| 72 | IntfId: subs.PonIntf, OnuId: subs.OnuID, |
| 73 | UniId: subs.UniID, PortNo: subs.UniPortNo, |
| 74 | TrafficScheds: trafficSched}); err != nil { |
| 75 | log.Errorw("Failed to create traffic schedulers", log.Fields{"error": err}) |
| 76 | return errors.New(ReasonCodeToReasonString(SCHED_CREATION_FAILED)) |
| 77 | } |
| 78 | |
| 79 | return nil |
| 80 | } |
| 81 | |
| 82 | func (dt DtWorkFlow) ProvisionQueues(subs *Subscriber) error { |
| 83 | log.Info("provisioning-queues") |
| 84 | |
| 85 | var trafficQueues []*tp_pb.TrafficQueue |
| 86 | if trafficQueues = getTrafficQueues(subs, tp_pb.Direction_DOWNSTREAM); trafficQueues == nil { |
| 87 | log.Error("Failed to create traffic queues") |
| 88 | return errors.New(ReasonCodeToReasonString(QUEUE_CREATION_FAILED)) |
| 89 | } |
| 90 | |
| 91 | // On receiving the CreateTrafficQueues request, the driver should create corresponding |
| 92 | // downstream queues. |
| 93 | log.Debugw("Sending Traffic Queues create to device", |
| 94 | log.Fields{"Direction": tp_pb.Direction_DOWNSTREAM, "TrafficQueues": trafficQueues}) |
| 95 | if _, err := subs.OpenOltClient.CreateTrafficQueues(context.Background(), |
| 96 | &tp_pb.TrafficQueues{IntfId: subs.PonIntf, OnuId: subs.OnuID, |
| 97 | UniId: subs.UniID, PortNo: subs.UniPortNo, |
| 98 | TrafficQueues: trafficQueues}); err != nil { |
| 99 | log.Errorw("Failed to create traffic queues in device", log.Fields{"error": err}) |
| 100 | return errors.New(ReasonCodeToReasonString(QUEUE_CREATION_FAILED)) |
| 101 | } |
| 102 | |
| 103 | if trafficQueues = getTrafficQueues(subs, tp_pb.Direction_UPSTREAM); trafficQueues == nil { |
| 104 | log.Error("Failed to create traffic queues") |
| 105 | return errors.New(ReasonCodeToReasonString(QUEUE_CREATION_FAILED)) |
| 106 | } |
| 107 | |
| 108 | // On receiving the CreateTrafficQueues request, the driver should create corresponding |
| 109 | // upstream queues. |
| 110 | log.Debugw("Sending Traffic Queues create to device", |
| 111 | log.Fields{"Direction": tp_pb.Direction_UPSTREAM, "TrafficQueues": trafficQueues}) |
| 112 | if _, err := subs.OpenOltClient.CreateTrafficQueues(context.Background(), |
| 113 | &tp_pb.TrafficQueues{IntfId: subs.PonIntf, OnuId: subs.OnuID, |
| 114 | UniId: subs.UniID, PortNo: subs.UniPortNo, |
| 115 | TrafficQueues: trafficQueues}); err != nil { |
| 116 | log.Errorw("Failed to create traffic queues in device", log.Fields{"error": err}) |
| 117 | return errors.New(ReasonCodeToReasonString(QUEUE_CREATION_FAILED)) |
| 118 | } |
| 119 | |
| 120 | return nil |
| 121 | } |
| 122 | |
| 123 | func (dt DtWorkFlow) ProvisionEapFlow(subs *Subscriber) error { |
| 124 | log.Info("dt-workflow-does-not-require-eap-support--nothing-to-do") |
| 125 | return nil |
| 126 | } |
| 127 | |
Girish Gowdra | ef1b7c4 | 2020-01-23 16:27:48 +0530 | [diff] [blame] | 128 | func (dt DtWorkFlow) ProvisionDhcpIPV4Flow(subs *Subscriber) error { |
| 129 | log.Info("dt-workflow-does-not-require-dhcp-ipv4-support--nothing-to-do") |
| 130 | return nil |
| 131 | } |
| 132 | |
| 133 | func (dt DtWorkFlow) ProvisionDhcpIPV6Flow(subs *Subscriber) error { |
| 134 | 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] | 135 | return nil |
| 136 | } |
| 137 | |
| 138 | func (dt DtWorkFlow) ProvisionIgmpFlow(subs *Subscriber) error { |
| 139 | log.Info("dt-workflow-does-not-support-igmp-yet--nothing-to-do") |
| 140 | return nil |
| 141 | } |
| 142 | |
| 143 | func (dt DtWorkFlow) ProvisionHsiaFlow(subs *Subscriber) error { |
| 144 | var err error |
| 145 | var flowID []uint32 |
| 146 | var gemPortIDs []uint32 |
| 147 | |
| 148 | var allocID = subs.TpInstance[subs.TestConfig.TpIDList[0]].UsScheduler.AllocID |
| 149 | for _, gem := range subs.TpInstance[subs.TestConfig.TpIDList[0]].UpstreamGemPortAttributeList { |
| 150 | gemPortIDs = append(gemPortIDs, gem.GemportID) |
| 151 | } |
| 152 | |
| 153 | for _, gemID := range gemPortIDs { |
| 154 | if flowID, err = subs.RsrMgr.ResourceMgrs[uint32(subs.PonIntf)].GetResourceID(uint32(subs.PonIntf), |
| 155 | ponresourcemanager.FLOW_ID, 1); err != nil { |
| 156 | return errors.New(ReasonCodeToReasonString(FLOW_ID_GENERATION_FAILED)) |
| 157 | } else { |
| 158 | if err := AddFlow(subs, HsiaFlow, Upstream, flowID[0], allocID, gemID); err != nil { |
| 159 | subs.RsrMgr.ResourceMgrs[uint32(subs.PonIntf)].FreeResourceID(uint32(subs.PonIntf), |
| 160 | ponresourcemanager.FLOW_ID, flowID) |
| 161 | return err |
| 162 | } |
| 163 | if err := AddFlow(subs, HsiaFlow, Downstream, flowID[0], allocID, gemID); err != nil { |
| 164 | return err |
| 165 | } |
| 166 | } |
| 167 | } |
| 168 | return nil |
| 169 | } |