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" |
Orhan Kupusoglu | 66b00d8 | 2020-03-13 12:06:33 +0300 | [diff] [blame] | 24 | "github.com/opencord/voltha-lib-go/v3/pkg/log" |
Orhan Kupusoglu | 66b00d8 | 2020-03-13 12:06:33 +0300 | [diff] [blame] | 25 | oop "github.com/opencord/voltha-protos/v3/go/openolt" |
| 26 | tp_pb "github.com/opencord/voltha-protos/v3/go/tech_profile" |
Thiyagarajan Subramani | b83b043 | 2020-01-08 13:43:28 +0530 | [diff] [blame] | 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 |
Girish Gowdra | aeceb84 | 2020-08-21 12:10:39 -0700 | [diff] [blame^] | 145 | var flowID uint32 |
Thiyagarajan Subramani | b83b043 | 2020-01-08 13:43:28 +0530 | [diff] [blame] | 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 | |
Girish Gowdra | d4bdd37 | 2020-03-09 14:56:15 -0700 | [diff] [blame] | 153 | for idx, gemID := range gemPortIDs { |
| 154 | pBitMap := subs.TpInstance[subs.TestConfig.TpIDList[0]].UpstreamGemPortAttributeList[idx].PbitMap |
| 155 | for pos, pbitSet := range strings.TrimPrefix(pBitMap, "0b") { |
| 156 | if pbitSet == '1' { |
| 157 | pcp := uint32(len(strings.TrimPrefix(pBitMap, "0b"))) - 1 - uint32(pos) |
Girish Gowdra | aeceb84 | 2020-08-21 12:10:39 -0700 | [diff] [blame^] | 158 | if flowID, err = subs.RsrMgr.GetFlowID(context.Background(), uint32(subs.PonIntf)); err != nil { |
Girish Gowdra | d4bdd37 | 2020-03-09 14:56:15 -0700 | [diff] [blame] | 159 | return errors.New(ReasonCodeToReasonString(FLOW_ID_GENERATION_FAILED)) |
| 160 | } else { |
Girish Gowdra | aeceb84 | 2020-08-21 12:10:39 -0700 | [diff] [blame^] | 161 | if err := AddFlow(subs, HsiaFlow, Upstream, flowID, allocID, gemID, pcp); err != nil { |
Girish Gowdra | d4bdd37 | 2020-03-09 14:56:15 -0700 | [diff] [blame] | 162 | return err |
| 163 | } |
Girish Gowdra | aeceb84 | 2020-08-21 12:10:39 -0700 | [diff] [blame^] | 164 | if err := AddFlow(subs, HsiaFlow, Downstream, flowID, allocID, gemID, pcp); err != nil { |
Girish Gowdra | d4bdd37 | 2020-03-09 14:56:15 -0700 | [diff] [blame] | 165 | return err |
| 166 | } |
| 167 | } |
Thiyagarajan Subramani | b83b043 | 2020-01-08 13:43:28 +0530 | [diff] [blame] | 168 | } |
| 169 | } |
| 170 | } |
| 171 | return nil |
| 172 | } |
Orhan Kupusoglu | 66b00d8 | 2020-03-13 12:06:33 +0300 | [diff] [blame] | 173 | |
| 174 | func (dt DtWorkFlow) ProvisionVoipFlow(subs *Subscriber) error { |
| 175 | log.Info("dt-workflow-does-not-support-voip-yet--nothing-to-do") |
| 176 | return nil |
| 177 | } |
| 178 | |
| 179 | func (dt DtWorkFlow) ProvisionVodFlow(subs *Subscriber) error { |
| 180 | log.Info("dt-workflow-does-not-support-vod-yet--nothing-to-do") |
| 181 | return nil |
| 182 | } |
| 183 | |
| 184 | func (dt DtWorkFlow) ProvisionMgmtFlow(subs *Subscriber) error { |
| 185 | log.Info("dt-workflow-does-not-support-mgmt-yet--nothing-to-do") |
| 186 | return nil |
| 187 | } |
| 188 | |
| 189 | func (dt DtWorkFlow) ProvisionMulticastFlow(subs *Subscriber) error { |
| 190 | log.Info("dt-workflow-does-not-support-multicast-yet--nothing-to-do") |
| 191 | return nil |
| 192 | } |