Girish Gowdra | 6450343 | 2020-01-07 10:59:10 +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" |
Thiyagarajan Subramani | b83b043 | 2020-01-08 13:43:28 +0530 | [diff] [blame] | 21 | |
Girish Gowdra | 6450343 | 2020-01-07 10:59:10 +0530 | [diff] [blame] | 22 | "github.com/opencord/openolt-scale-tester/config" |
| 23 | "github.com/opencord/voltha-lib-go/v2/pkg/log" |
| 24 | "github.com/opencord/voltha-lib-go/v2/pkg/ponresourcemanager" |
| 25 | oop "github.com/opencord/voltha-protos/v2/go/openolt" |
| 26 | tp_pb "github.com/opencord/voltha-protos/v2/go/tech_profile" |
| 27 | "golang.org/x/net/context" |
| 28 | "google.golang.org/grpc/codes" |
| 29 | "google.golang.org/grpc/status" |
| 30 | ) |
| 31 | |
| 32 | func init() { |
| 33 | _, _ = log.AddPackage(log.JSON, log.DebugLevel, nil) |
| 34 | } |
| 35 | |
| 36 | // A dummy struct to comply with the WorkFlow interface. |
| 37 | type AttWorkFlow struct { |
| 38 | } |
| 39 | |
Girish Gowdra | ef1b7c4 | 2020-01-23 16:27:48 +0530 | [diff] [blame] | 40 | func AddDhcpIPV4Flow(oo oop.OpenoltClient, config *config.OpenOltScaleTesterConfig, rsrMgr *OpenOltResourceMgr) error { |
Girish Gowdra | 6450343 | 2020-01-07 10:59:10 +0530 | [diff] [blame] | 41 | var flowID []uint32 |
| 42 | var err error |
| 43 | |
| 44 | if flowID, err = rsrMgr.ResourceMgrs[uint32(config.NniIntfID)].GetResourceID(uint32(config.NniIntfID), |
| 45 | ponresourcemanager.FLOW_ID, 1); err != nil { |
| 46 | return err |
| 47 | } |
| 48 | |
Girish Gowdra | ef1b7c4 | 2020-01-23 16:27:48 +0530 | [diff] [blame] | 49 | // DHCP IPV4 |
Girish Gowdra | 6450343 | 2020-01-07 10:59:10 +0530 | [diff] [blame] | 50 | flowClassifier := &oop.Classifier{EthType: 2048, IpProto: 17, SrcPort: 67, DstPort: 68, PktTagType: "double_tag"} |
| 51 | actionCmd := &oop.ActionCmd{TrapToHost: true} |
| 52 | actionInfo := &oop.Action{Cmd: actionCmd} |
| 53 | |
| 54 | flow := oop.Flow{AccessIntfId: -1, OnuId: -1, UniId: -1, FlowId: flowID[0], |
| 55 | FlowType: "downstream", AllocId: -1, GemportId: -1, |
| 56 | Classifier: flowClassifier, Action: actionInfo, |
Girish Gowdra | ef1b7c4 | 2020-01-23 16:27:48 +0530 | [diff] [blame] | 57 | Priority: 1000, PortNo: uint32(config.NniIntfID)} |
Girish Gowdra | 6450343 | 2020-01-07 10:59:10 +0530 | [diff] [blame] | 58 | |
| 59 | _, err = oo.FlowAdd(context.Background(), &flow) |
| 60 | |
| 61 | st, _ := status.FromError(err) |
| 62 | if st.Code() == codes.AlreadyExists { |
| 63 | log.Debugw("Flow already exists", log.Fields{"err": err, "deviceFlow": flow}) |
| 64 | return nil |
| 65 | } |
| 66 | |
| 67 | if err != nil { |
Girish Gowdra | ef1b7c4 | 2020-01-23 16:27:48 +0530 | [diff] [blame] | 68 | log.Errorw("Failed to Add DHCP IPv4 to device", log.Fields{"err": err, "deviceFlow": flow}) |
Thiyagarajan Subramani | b83b043 | 2020-01-08 13:43:28 +0530 | [diff] [blame] | 69 | rsrMgr.ResourceMgrs[uint32(config.NniIntfID)].FreeResourceID(uint32(config.NniIntfID), |
| 70 | ponresourcemanager.FLOW_ID, flowID) |
Girish Gowdra | 6450343 | 2020-01-07 10:59:10 +0530 | [diff] [blame] | 71 | return err |
| 72 | } |
Girish Gowdra | ef1b7c4 | 2020-01-23 16:27:48 +0530 | [diff] [blame] | 73 | log.Debugw("DHCP IPV4 added to device successfully ", log.Fields{"flow": flow}) |
| 74 | |
| 75 | return nil |
| 76 | } |
| 77 | |
| 78 | func AddDhcpIPV6Flow(oo oop.OpenoltClient, config *config.OpenOltScaleTesterConfig, rsrMgr *OpenOltResourceMgr) error { |
| 79 | var flowID []uint32 |
| 80 | var err error |
| 81 | |
| 82 | if flowID, err = rsrMgr.ResourceMgrs[uint32(config.NniIntfID)].GetResourceID(uint32(config.NniIntfID), |
| 83 | ponresourcemanager.FLOW_ID, 1); err != nil { |
| 84 | return err |
| 85 | } |
| 86 | |
| 87 | // DHCP IPV6 |
| 88 | flowClassifier := &oop.Classifier{EthType: 34525, IpProto: 17, SrcPort: 546, DstPort: 547, PktTagType: "double_tag"} |
| 89 | actionCmd := &oop.ActionCmd{TrapToHost: true} |
| 90 | actionInfo := &oop.Action{Cmd: actionCmd} |
| 91 | |
| 92 | flow := oop.Flow{AccessIntfId: -1, OnuId: -1, UniId: -1, FlowId: flowID[0], |
| 93 | FlowType: "downstream", AllocId: -1, GemportId: -1, |
| 94 | Classifier: flowClassifier, Action: actionInfo, |
| 95 | Priority: 1000, PortNo: uint32(config.NniIntfID)} |
| 96 | |
| 97 | _, err = oo.FlowAdd(context.Background(), &flow) |
| 98 | |
| 99 | st, _ := status.FromError(err) |
| 100 | if st.Code() == codes.AlreadyExists { |
| 101 | log.Debugw("Flow already exists", log.Fields{"err": err, "deviceFlow": flow}) |
| 102 | return nil |
| 103 | } |
| 104 | |
| 105 | if err != nil { |
| 106 | log.Errorw("Failed to Add DHCP IPV6 to device", log.Fields{"err": err, "deviceFlow": flow}) |
| 107 | rsrMgr.ResourceMgrs[uint32(config.NniIntfID)].FreeResourceID(uint32(config.NniIntfID), |
| 108 | ponresourcemanager.FLOW_ID, flowID) |
| 109 | return err |
| 110 | } |
| 111 | log.Debugw("DHCP IPV6 added to device successfully ", log.Fields{"flow": flow}) |
| 112 | |
| 113 | return nil |
| 114 | } |
| 115 | |
Girish Gowdra | ef1b7c4 | 2020-01-23 16:27:48 +0530 | [diff] [blame] | 116 | func ProvisionAttNniTrapFlow(oo oop.OpenoltClient, config *config.OpenOltScaleTesterConfig, rsrMgr *OpenOltResourceMgr) error { |
| 117 | _ = AddDhcpIPV4Flow(oo, config, rsrMgr) |
| 118 | _ = AddDhcpIPV6Flow(oo, config, rsrMgr) |
| 119 | _ = AddLldpFlow(oo, config, rsrMgr) |
Girish Gowdra | 6450343 | 2020-01-07 10:59:10 +0530 | [diff] [blame] | 120 | |
| 121 | return nil |
| 122 | } |
| 123 | |
Girish Gowdra | 6450343 | 2020-01-07 10:59:10 +0530 | [diff] [blame] | 124 | func (att AttWorkFlow) ProvisionScheds(subs *Subscriber) error { |
| 125 | var trafficSched []*tp_pb.TrafficScheduler |
| 126 | |
| 127 | log.Info("provisioning-scheds") |
| 128 | |
| 129 | if trafficSched = getTrafficSched(subs, tp_pb.Direction_DOWNSTREAM); trafficSched == nil { |
| 130 | log.Error("ds-traffic-sched-is-nil") |
| 131 | return errors.New(ReasonCodeToReasonString(SCHED_CREATION_FAILED)) |
| 132 | } |
| 133 | |
| 134 | log.Debugw("Sending Traffic scheduler create to device", |
| 135 | log.Fields{"Direction": tp_pb.Direction_DOWNSTREAM, "TrafficScheds": trafficSched}) |
| 136 | if _, err := subs.OpenOltClient.CreateTrafficSchedulers(context.Background(), &tp_pb.TrafficSchedulers{ |
| 137 | IntfId: subs.PonIntf, OnuId: subs.OnuID, |
| 138 | UniId: subs.UniID, PortNo: subs.UniPortNo, |
| 139 | TrafficScheds: trafficSched}); err != nil { |
| 140 | log.Errorw("Failed to create traffic schedulers", log.Fields{"error": err}) |
| 141 | return errors.New(ReasonCodeToReasonString(SCHED_CREATION_FAILED)) |
| 142 | } |
| 143 | |
| 144 | if trafficSched = getTrafficSched(subs, tp_pb.Direction_UPSTREAM); trafficSched == nil { |
| 145 | log.Error("us-traffic-sched-is-nil") |
| 146 | return errors.New(ReasonCodeToReasonString(SCHED_CREATION_FAILED)) |
| 147 | } |
| 148 | |
| 149 | log.Debugw("Sending Traffic scheduler create to device", |
| 150 | log.Fields{"Direction": tp_pb.Direction_UPSTREAM, "TrafficScheds": trafficSched}) |
| 151 | if _, err := subs.OpenOltClient.CreateTrafficSchedulers(context.Background(), &tp_pb.TrafficSchedulers{ |
| 152 | IntfId: subs.PonIntf, OnuId: subs.OnuID, |
| 153 | UniId: subs.UniID, PortNo: subs.UniPortNo, |
| 154 | TrafficScheds: trafficSched}); err != nil { |
| 155 | log.Errorw("Failed to create traffic schedulers", log.Fields{"error": err}) |
| 156 | return errors.New(ReasonCodeToReasonString(SCHED_CREATION_FAILED)) |
| 157 | } |
| 158 | |
| 159 | return nil |
| 160 | } |
| 161 | |
Girish Gowdra | 6450343 | 2020-01-07 10:59:10 +0530 | [diff] [blame] | 162 | func (att AttWorkFlow) ProvisionQueues(subs *Subscriber) error { |
| 163 | log.Info("provisioning-queues") |
| 164 | |
| 165 | var trafficQueues []*tp_pb.TrafficQueue |
| 166 | if trafficQueues = getTrafficQueues(subs, tp_pb.Direction_DOWNSTREAM); trafficQueues == nil { |
| 167 | log.Error("Failed to create traffic queues") |
| 168 | return errors.New(ReasonCodeToReasonString(QUEUE_CREATION_FAILED)) |
| 169 | } |
| 170 | |
| 171 | // On receiving the CreateTrafficQueues request, the driver should create corresponding |
| 172 | // downstream queues. |
| 173 | log.Debugw("Sending Traffic Queues create to device", |
| 174 | log.Fields{"Direction": tp_pb.Direction_DOWNSTREAM, "TrafficQueues": trafficQueues}) |
| 175 | if _, err := subs.OpenOltClient.CreateTrafficQueues(context.Background(), |
| 176 | &tp_pb.TrafficQueues{IntfId: subs.PonIntf, OnuId: subs.OnuID, |
| 177 | UniId: subs.UniID, PortNo: subs.UniPortNo, |
| 178 | TrafficQueues: trafficQueues}); err != nil { |
| 179 | log.Errorw("Failed to create traffic queues in device", log.Fields{"error": err}) |
| 180 | return errors.New(ReasonCodeToReasonString(QUEUE_CREATION_FAILED)) |
| 181 | } |
| 182 | |
| 183 | if trafficQueues = getTrafficQueues(subs, tp_pb.Direction_UPSTREAM); trafficQueues == nil { |
| 184 | log.Error("Failed to create traffic queues") |
| 185 | return errors.New(ReasonCodeToReasonString(QUEUE_CREATION_FAILED)) |
| 186 | } |
| 187 | |
| 188 | // On receiving the CreateTrafficQueues request, the driver should create corresponding |
| 189 | // upstream queues. |
| 190 | log.Debugw("Sending Traffic Queues create to device", |
| 191 | log.Fields{"Direction": tp_pb.Direction_UPSTREAM, "TrafficQueues": trafficQueues}) |
| 192 | if _, err := subs.OpenOltClient.CreateTrafficQueues(context.Background(), |
| 193 | &tp_pb.TrafficQueues{IntfId: subs.PonIntf, OnuId: subs.OnuID, |
| 194 | UniId: subs.UniID, PortNo: subs.UniPortNo, |
| 195 | TrafficQueues: trafficQueues}); err != nil { |
| 196 | log.Errorw("Failed to create traffic queues in device", log.Fields{"error": err}) |
| 197 | return errors.New(ReasonCodeToReasonString(QUEUE_CREATION_FAILED)) |
| 198 | } |
| 199 | |
| 200 | return nil |
| 201 | } |
| 202 | |
| 203 | func (att AttWorkFlow) ProvisionEapFlow(subs *Subscriber) error { |
Girish Gowdra | 6450343 | 2020-01-07 10:59:10 +0530 | [diff] [blame] | 204 | var err error |
| 205 | var flowID []uint32 |
| 206 | var gemPortIDs []uint32 |
| 207 | |
| 208 | var allocID = subs.TpInstance[subs.TestConfig.TpIDList[0]].UsScheduler.AllocID |
Girish Gowdra | 6450343 | 2020-01-07 10:59:10 +0530 | [diff] [blame] | 209 | for _, gem := range subs.TpInstance[subs.TestConfig.TpIDList[0]].UpstreamGemPortAttributeList { |
| 210 | gemPortIDs = append(gemPortIDs, gem.GemportID) |
| 211 | } |
| 212 | |
| 213 | for _, gemID := range gemPortIDs { |
| 214 | if flowID, err = subs.RsrMgr.ResourceMgrs[uint32(subs.PonIntf)].GetResourceID(uint32(subs.PonIntf), |
| 215 | ponresourcemanager.FLOW_ID, 1); err != nil { |
Thiyagarajan Subramani | b83b043 | 2020-01-08 13:43:28 +0530 | [diff] [blame] | 216 | return errors.New(ReasonCodeToReasonString(FLOW_ID_GENERATION_FAILED)) |
| 217 | } else { |
| 218 | if err := AddFlow(subs, EapolFlow, Upstream, flowID[0], allocID, gemID); err != nil { |
| 219 | subs.RsrMgr.ResourceMgrs[uint32(subs.PonIntf)].FreeResourceID(uint32(subs.PonIntf), |
| 220 | ponresourcemanager.FLOW_ID, flowID) |
| 221 | return err |
| 222 | } |
Girish Gowdra | 6450343 | 2020-01-07 10:59:10 +0530 | [diff] [blame] | 223 | } |
Girish Gowdra | 6450343 | 2020-01-07 10:59:10 +0530 | [diff] [blame] | 224 | } |
| 225 | return nil |
| 226 | } |
| 227 | |
Girish Gowdra | ef1b7c4 | 2020-01-23 16:27:48 +0530 | [diff] [blame] | 228 | func (att AttWorkFlow) ProvisionDhcpIPV4Flow(subs *Subscriber) error { |
Thiyagarajan Subramani | b83b043 | 2020-01-08 13:43:28 +0530 | [diff] [blame] | 229 | var err error |
| 230 | var flowID []uint32 |
| 231 | var gemPortIDs []uint32 |
| 232 | |
| 233 | var allocID = subs.TpInstance[subs.TestConfig.TpIDList[0]].UsScheduler.AllocID |
| 234 | for _, gem := range subs.TpInstance[subs.TestConfig.TpIDList[0]].UpstreamGemPortAttributeList { |
| 235 | gemPortIDs = append(gemPortIDs, gem.GemportID) |
| 236 | } |
| 237 | |
| 238 | for _, gemID := range gemPortIDs { |
| 239 | if flowID, err = subs.RsrMgr.ResourceMgrs[uint32(subs.PonIntf)].GetResourceID(uint32(subs.PonIntf), |
| 240 | ponresourcemanager.FLOW_ID, 1); err != nil { |
| 241 | return errors.New(ReasonCodeToReasonString(FLOW_ID_GENERATION_FAILED)) |
| 242 | } else { |
Girish Gowdra | ef1b7c4 | 2020-01-23 16:27:48 +0530 | [diff] [blame] | 243 | if err := AddFlow(subs, DhcpFlowIPV4, Upstream, flowID[0], allocID, gemID); err != nil { |
| 244 | subs.RsrMgr.ResourceMgrs[uint32(subs.PonIntf)].FreeResourceID(uint32(subs.PonIntf), |
| 245 | ponresourcemanager.FLOW_ID, flowID) |
| 246 | return err |
| 247 | } |
| 248 | } |
| 249 | } |
| 250 | return nil |
| 251 | } |
| 252 | |
| 253 | func (att AttWorkFlow) ProvisionDhcpIPV6Flow(subs *Subscriber) error { |
| 254 | var err error |
| 255 | var flowID []uint32 |
| 256 | var gemPortIDs []uint32 |
| 257 | |
| 258 | var allocID = subs.TpInstance[subs.TestConfig.TpIDList[0]].UsScheduler.AllocID |
| 259 | for _, gem := range subs.TpInstance[subs.TestConfig.TpIDList[0]].UpstreamGemPortAttributeList { |
| 260 | gemPortIDs = append(gemPortIDs, gem.GemportID) |
| 261 | } |
| 262 | |
| 263 | for _, gemID := range gemPortIDs { |
| 264 | if flowID, err = subs.RsrMgr.ResourceMgrs[uint32(subs.PonIntf)].GetResourceID(uint32(subs.PonIntf), |
| 265 | ponresourcemanager.FLOW_ID, 1); err != nil { |
| 266 | return errors.New(ReasonCodeToReasonString(FLOW_ID_GENERATION_FAILED)) |
| 267 | } else { |
| 268 | if err := AddFlow(subs, DhcpFlowIPV6, Upstream, flowID[0], allocID, gemID); err != nil { |
Thiyagarajan Subramani | b83b043 | 2020-01-08 13:43:28 +0530 | [diff] [blame] | 269 | subs.RsrMgr.ResourceMgrs[uint32(subs.PonIntf)].FreeResourceID(uint32(subs.PonIntf), |
| 270 | ponresourcemanager.FLOW_ID, flowID) |
| 271 | return err |
| 272 | } |
| 273 | } |
| 274 | } |
Girish Gowdra | 6450343 | 2020-01-07 10:59:10 +0530 | [diff] [blame] | 275 | return nil |
| 276 | } |
| 277 | |
| 278 | func (att AttWorkFlow) ProvisionIgmpFlow(subs *Subscriber) error { |
| 279 | log.Info("att-workflow-does-not-support-igmp-yet--nothing-to-do") |
| 280 | return nil |
| 281 | } |
| 282 | |
| 283 | func (att AttWorkFlow) ProvisionHsiaFlow(subs *Subscriber) error { |
Thiyagarajan Subramani | b83b043 | 2020-01-08 13:43:28 +0530 | [diff] [blame] | 284 | var err error |
| 285 | var flowID []uint32 |
| 286 | var gemPortIDs []uint32 |
| 287 | |
| 288 | var allocID = subs.TpInstance[subs.TestConfig.TpIDList[0]].UsScheduler.AllocID |
| 289 | for _, gem := range subs.TpInstance[subs.TestConfig.TpIDList[0]].UpstreamGemPortAttributeList { |
| 290 | gemPortIDs = append(gemPortIDs, gem.GemportID) |
| 291 | } |
| 292 | |
| 293 | for _, gemID := range gemPortIDs { |
| 294 | if flowID, err = subs.RsrMgr.ResourceMgrs[uint32(subs.PonIntf)].GetResourceID(uint32(subs.PonIntf), |
| 295 | ponresourcemanager.FLOW_ID, 1); err != nil { |
| 296 | return errors.New(ReasonCodeToReasonString(FLOW_ID_GENERATION_FAILED)) |
| 297 | } else { |
Girish Gowdra | ef1b7c4 | 2020-01-23 16:27:48 +0530 | [diff] [blame] | 298 | var errUs, errDs error |
| 299 | if errUs = AddFlow(subs, HsiaFlow, Upstream, flowID[0], allocID, gemID); errUs != nil { |
| 300 | log.Errorw("failed to install US HSIA flow", |
| 301 | log.Fields{"onuID": subs.OnuID, "uniID": subs.UniID, "intf": subs.PonIntf}) |
| 302 | } |
| 303 | if errDs = AddFlow(subs, HsiaFlow, Downstream, flowID[0], allocID, gemID); errDs != nil { |
| 304 | log.Errorw("failed to install US HSIA flow", |
| 305 | log.Fields{"onuID": subs.OnuID, "uniID": subs.UniID, "intf": subs.PonIntf}) |
| 306 | } |
| 307 | if errUs != nil && errDs != nil { |
Thiyagarajan Subramani | b83b043 | 2020-01-08 13:43:28 +0530 | [diff] [blame] | 308 | subs.RsrMgr.ResourceMgrs[uint32(subs.PonIntf)].FreeResourceID(uint32(subs.PonIntf), |
| 309 | ponresourcemanager.FLOW_ID, flowID) |
Thiyagarajan Subramani | b83b043 | 2020-01-08 13:43:28 +0530 | [diff] [blame] | 310 | } |
Girish Gowdra | ef1b7c4 | 2020-01-23 16:27:48 +0530 | [diff] [blame] | 311 | if errUs != nil || errDs != nil { |
| 312 | if errUs != nil { |
| 313 | return errUs |
| 314 | } |
| 315 | return errDs |
Thiyagarajan Subramani | b83b043 | 2020-01-08 13:43:28 +0530 | [diff] [blame] | 316 | } |
| 317 | } |
| 318 | } |
Girish Gowdra | 6450343 | 2020-01-07 10:59:10 +0530 | [diff] [blame] | 319 | return nil |
| 320 | } |