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