Orhan Kupusoglu | 66b00d8 | 2020-03-13 12:06:33 +0300 | [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 | "strings" |
| 22 | "sync/atomic" |
| 23 | |
| 24 | "github.com/opencord/openolt-scale-tester/config" |
| 25 | "github.com/opencord/voltha-lib-go/v3/pkg/log" |
Orhan Kupusoglu | 66b00d8 | 2020-03-13 12:06:33 +0300 | [diff] [blame] | 26 | oop "github.com/opencord/voltha-protos/v3/go/openolt" |
| 27 | tp_pb "github.com/opencord/voltha-protos/v3/go/tech_profile" |
| 28 | "golang.org/x/net/context" |
| 29 | "google.golang.org/grpc/codes" |
| 30 | "google.golang.org/grpc/status" |
| 31 | ) |
| 32 | |
| 33 | var lastPonIntf *uint32 = new(uint32) |
| 34 | |
| 35 | func init() { |
| 36 | _, _ = log.AddPackage(log.JSON, log.DebugLevel, nil) |
| 37 | } |
| 38 | |
| 39 | // A dummy struct to comply with the WorkFlow interface. |
| 40 | type TtWorkFlow struct { |
| 41 | } |
| 42 | |
| 43 | func AddTtDhcpIPV4Flow(oo oop.OpenoltClient, config *config.OpenOltScaleTesterConfig, rsrMgr *OpenOltResourceMgr) error { |
Girish Gowdra | aeceb84 | 2020-08-21 12:10:39 -0700 | [diff] [blame^] | 44 | var flowID uint32 |
Orhan Kupusoglu | 66b00d8 | 2020-03-13 12:06:33 +0300 | [diff] [blame] | 45 | var err error |
| 46 | |
Girish Gowdra | aeceb84 | 2020-08-21 12:10:39 -0700 | [diff] [blame^] | 47 | // Allocating flowID from PON0 pool for an trap-from-nni flow |
| 48 | if flowID, err = rsrMgr.GetFlowID(context.Background(), uint32(0)); err != nil { |
Orhan Kupusoglu | 66b00d8 | 2020-03-13 12:06:33 +0300 | [diff] [blame] | 49 | return err |
| 50 | } |
| 51 | |
| 52 | // DHCP IPV4 |
| 53 | flowClassifier := &oop.Classifier{EthType: 2048, IpProto: 17, SrcPort: 67, DstPort: 68, PktTagType: "double_tag"} |
| 54 | actionCmd := &oop.ActionCmd{TrapToHost: true} |
| 55 | actionInfo := &oop.Action{Cmd: actionCmd} |
| 56 | |
Girish Gowdra | aeceb84 | 2020-08-21 12:10:39 -0700 | [diff] [blame^] | 57 | flow := oop.Flow{AccessIntfId: -1, OnuId: -1, UniId: -1, FlowId: flowID, |
Orhan Kupusoglu | 66b00d8 | 2020-03-13 12:06:33 +0300 | [diff] [blame] | 58 | FlowType: "downstream", AllocId: -1, GemportId: -1, |
| 59 | Classifier: flowClassifier, Action: actionInfo, |
| 60 | Priority: 1000, PortNo: uint32(config.NniIntfID)} |
| 61 | |
| 62 | _, err = oo.FlowAdd(context.Background(), &flow) |
| 63 | |
| 64 | st, _ := status.FromError(err) |
| 65 | if st.Code() == codes.AlreadyExists { |
| 66 | log.Debugw("Flow already exists", log.Fields{"err": err, "deviceFlow": flow}) |
| 67 | return nil |
| 68 | } |
| 69 | |
| 70 | if err != nil { |
| 71 | log.Errorw("Failed to Add DHCP IPv4 to device", log.Fields{"err": err, "deviceFlow": flow}) |
Orhan Kupusoglu | 66b00d8 | 2020-03-13 12:06:33 +0300 | [diff] [blame] | 72 | return err |
| 73 | } |
| 74 | log.Debugw("DHCP IPV4 added to device successfully ", log.Fields{"flow": flow}) |
| 75 | |
| 76 | return nil |
| 77 | } |
| 78 | |
| 79 | func AddTtDhcpIPV6Flow(oo oop.OpenoltClient, config *config.OpenOltScaleTesterConfig, rsrMgr *OpenOltResourceMgr) error { |
| 80 | log.Info("tt-workflow-does-not-require-dhcp-ipv6-support--nothing-to-do") |
| 81 | return nil |
| 82 | } |
| 83 | |
| 84 | func ProvisionTtNniTrapFlow(oo oop.OpenoltClient, config *config.OpenOltScaleTesterConfig, rsrMgr *OpenOltResourceMgr) error { |
| 85 | _ = AddTtDhcpIPV4Flow(oo, config, rsrMgr) |
| 86 | return nil |
| 87 | } |
| 88 | |
| 89 | func FormatTtClassfierAction(flowType string, direction string, subs *Subscriber) (oop.Classifier, oop.Action) { |
| 90 | var flowClassifier oop.Classifier |
| 91 | var actionCmd oop.ActionCmd |
| 92 | var actionInfo oop.Action |
| 93 | |
| 94 | if direction == Upstream { |
| 95 | switch flowType { |
| 96 | case IgmpFlow: |
| 97 | flowClassifier.EthType = IPv4EthType |
| 98 | flowClassifier.IpProto = IgmpProto |
| 99 | flowClassifier.SrcPort = 0 |
| 100 | flowClassifier.DstPort = 0 |
| 101 | flowClassifier.PktTagType = SingleTag |
| 102 | actionCmd.TrapToHost = true |
| 103 | actionInfo.Cmd = &actionCmd |
| 104 | case HsiaFlow: |
| 105 | actionCmd.AddOuterTag = true |
| 106 | actionInfo.Cmd = &actionCmd |
| 107 | actionInfo.IVid = 33 |
| 108 | actionInfo.OVid = 7 |
| 109 | flowClassifier.IPbits = 255 |
| 110 | flowClassifier.OVid = 33 |
| 111 | flowClassifier.PktTagType = SingleTag |
| 112 | case VoipFlow: |
| 113 | actionCmd.AddOuterTag = true |
| 114 | actionInfo.Cmd = &actionCmd |
| 115 | actionInfo.OPbits = 7 |
| 116 | actionInfo.IVid = 63 |
| 117 | actionInfo.OVid = 10 |
| 118 | flowClassifier.IPbits = 255 |
| 119 | flowClassifier.OPbits = 7 |
| 120 | flowClassifier.OVid = 63 |
| 121 | flowClassifier.PktTagType = SingleTag |
| 122 | case VodFlow: |
| 123 | actionCmd.AddOuterTag = true |
| 124 | actionInfo.Cmd = &actionCmd |
| 125 | actionInfo.OPbits = 5 |
| 126 | actionInfo.IVid = 55 |
| 127 | actionInfo.OVid = 555 |
| 128 | flowClassifier.IPbits = 255 |
| 129 | flowClassifier.OPbits = 5 |
| 130 | flowClassifier.OVid = 55 |
| 131 | flowClassifier.PktTagType = SingleTag |
| 132 | case MgmtFlow: |
| 133 | actionCmd.AddOuterTag = true |
| 134 | actionInfo.Cmd = &actionCmd |
| 135 | actionInfo.OPbits = 7 |
| 136 | actionInfo.IVid = 75 |
| 137 | actionInfo.OVid = 575 |
| 138 | flowClassifier.IPbits = 255 |
| 139 | flowClassifier.OPbits = 7 |
| 140 | flowClassifier.OVid = 75 |
| 141 | flowClassifier.PktTagType = SingleTag |
| 142 | default: |
| 143 | log.Errorw("Unsupported TT flow type", log.Fields{"flowtype": flowType, |
| 144 | "direction": direction}) |
| 145 | } |
| 146 | } else if direction == Downstream { |
| 147 | switch flowType { |
| 148 | case IgmpFlow: |
| 149 | log.Errorw("Downstream IGMP flows are not required instead we have "+ |
| 150 | "IGMP trap flows already installed", log.Fields{"flowtype": flowType, |
| 151 | "direction": direction}) |
| 152 | case HsiaFlow: |
| 153 | actionCmd.RemoveOuterTag = true |
| 154 | actionInfo.Cmd = &actionCmd |
| 155 | actionInfo.IVid = 33 |
| 156 | flowClassifier.IPbits = 255 |
| 157 | flowClassifier.OPbits = 255 |
| 158 | flowClassifier.IVid = 33 |
| 159 | flowClassifier.OVid = 7 |
| 160 | flowClassifier.PktTagType = DoubleTag |
| 161 | case VoipFlow: |
| 162 | actionCmd.RemoveOuterTag = true |
| 163 | actionInfo.Cmd = &actionCmd |
| 164 | actionInfo.IPbits = 7 |
| 165 | actionInfo.IVid = 63 |
| 166 | flowClassifier.IPbits = 255 |
| 167 | flowClassifier.OPbits = 255 |
| 168 | flowClassifier.IVid = 63 |
| 169 | flowClassifier.OVid = 10 |
| 170 | flowClassifier.DstMac = GenerateMac(true) |
| 171 | flowClassifier.PktTagType = DoubleTag |
| 172 | case VodFlow: |
| 173 | actionCmd.RemoveOuterTag = true |
| 174 | actionInfo.Cmd = &actionCmd |
| 175 | actionInfo.IPbits = 5 |
| 176 | actionInfo.IVid = 55 |
| 177 | flowClassifier.IPbits = 255 |
| 178 | flowClassifier.OPbits = 255 |
| 179 | flowClassifier.IVid = 55 |
| 180 | flowClassifier.OVid = 555 |
| 181 | flowClassifier.DstMac = GenerateMac(true) |
| 182 | flowClassifier.PktTagType = DoubleTag |
| 183 | case MgmtFlow: |
| 184 | actionCmd.RemoveOuterTag = true |
| 185 | actionInfo.Cmd = &actionCmd |
| 186 | actionInfo.IPbits = 7 |
| 187 | actionInfo.IVid = 75 |
| 188 | flowClassifier.IPbits = 255 |
| 189 | flowClassifier.OPbits = 255 |
| 190 | flowClassifier.IVid = 75 |
| 191 | flowClassifier.OVid = 575 |
| 192 | flowClassifier.DstMac = GenerateMac(true) |
| 193 | flowClassifier.PktTagType = DoubleTag |
| 194 | default: |
| 195 | log.Errorw("Unsupported TT flow type", log.Fields{"flowtype": flowType, |
| 196 | "direction": direction}) |
| 197 | } |
| 198 | } |
| 199 | return flowClassifier, actionInfo |
| 200 | } |
| 201 | |
| 202 | func AddTtFlow(subs *Subscriber, flowType string, direction string, flowID uint32, |
| 203 | allocID uint32, gemID uint32, pcp uint32) error { |
| 204 | log.Infow("add-flow", log.Fields{"WorkFlow": subs.TestConfig.WorkflowName, "FlowType": flowType, |
| 205 | "direction": direction, "flowID": flowID}) |
| 206 | var err error |
| 207 | |
| 208 | flowClassifier, actionInfo := FormatTtClassfierAction(flowType, direction, subs) |
| 209 | // Update the o_pbit for which this flow has to be classified |
| 210 | flowClassifier.OPbits = pcp |
| 211 | flow := oop.Flow{AccessIntfId: int32(subs.PonIntf), OnuId: int32(subs.OnuID), |
| 212 | UniId: int32(subs.UniID), FlowId: flowID, |
| 213 | FlowType: direction, AllocId: int32(allocID), GemportId: int32(gemID), |
| 214 | Classifier: &flowClassifier, Action: &actionInfo, |
| 215 | Priority: 1000, PortNo: subs.UniPortNo} |
| 216 | |
| 217 | _, err = subs.OpenOltClient.FlowAdd(context.Background(), &flow) |
| 218 | |
| 219 | st, _ := status.FromError(err) |
| 220 | if st.Code() == codes.AlreadyExists { |
| 221 | log.Debugw("Flow already exists", log.Fields{"err": err, "deviceFlow": flow}) |
| 222 | return nil |
| 223 | } |
| 224 | |
| 225 | if err != nil { |
| 226 | log.Errorw("Failed to Add flow to device", log.Fields{"err": err, "deviceFlow": flow}) |
| 227 | return errors.New(ReasonCodeToReasonString(FLOW_ADD_FAILED)) |
| 228 | } |
| 229 | log.Debugw("Flow added to device successfully ", log.Fields{"flow": flow}) |
| 230 | |
| 231 | return nil |
| 232 | } |
| 233 | |
| 234 | func (tt TtWorkFlow) ProvisionScheds(subs *Subscriber) error { |
| 235 | var trafficSched []*tp_pb.TrafficScheduler |
| 236 | |
| 237 | log.Info("provisioning-scheds") |
| 238 | |
| 239 | if trafficSched = getTrafficSched(subs, tp_pb.Direction_DOWNSTREAM); trafficSched == nil { |
| 240 | log.Error("ds-traffic-sched-is-nil") |
| 241 | return errors.New(ReasonCodeToReasonString(SCHED_CREATION_FAILED)) |
| 242 | } |
| 243 | |
| 244 | log.Debugw("Sending Traffic scheduler create to device", |
| 245 | log.Fields{"Direction": tp_pb.Direction_DOWNSTREAM, "TrafficScheds": trafficSched}) |
| 246 | if _, err := subs.OpenOltClient.CreateTrafficSchedulers(context.Background(), &tp_pb.TrafficSchedulers{ |
| 247 | IntfId: subs.PonIntf, OnuId: subs.OnuID, |
| 248 | UniId: subs.UniID, PortNo: subs.UniPortNo, |
| 249 | TrafficScheds: trafficSched}); err != nil { |
| 250 | log.Errorw("Failed to create traffic schedulers", log.Fields{"error": err}) |
| 251 | return errors.New(ReasonCodeToReasonString(SCHED_CREATION_FAILED)) |
| 252 | } |
| 253 | |
| 254 | if trafficSched = getTrafficSched(subs, tp_pb.Direction_UPSTREAM); trafficSched == nil { |
| 255 | log.Error("us-traffic-sched-is-nil") |
| 256 | return errors.New(ReasonCodeToReasonString(SCHED_CREATION_FAILED)) |
| 257 | } |
| 258 | |
| 259 | log.Debugw("Sending Traffic scheduler create to device", |
| 260 | log.Fields{"Direction": tp_pb.Direction_UPSTREAM, "TrafficScheds": trafficSched}) |
| 261 | if _, err := subs.OpenOltClient.CreateTrafficSchedulers(context.Background(), &tp_pb.TrafficSchedulers{ |
| 262 | IntfId: subs.PonIntf, OnuId: subs.OnuID, |
| 263 | UniId: subs.UniID, PortNo: subs.UniPortNo, |
| 264 | TrafficScheds: trafficSched}); err != nil { |
| 265 | log.Errorw("Failed to create traffic schedulers", log.Fields{"error": err}) |
| 266 | return errors.New(ReasonCodeToReasonString(SCHED_CREATION_FAILED)) |
| 267 | } |
| 268 | return nil |
| 269 | } |
| 270 | |
| 271 | func (tt TtWorkFlow) ProvisionQueues(subs *Subscriber) error { |
| 272 | log.Info("provisioning-queues") |
| 273 | |
| 274 | var trafficQueues []*tp_pb.TrafficQueue |
| 275 | if trafficQueues = getTrafficQueues(subs, tp_pb.Direction_DOWNSTREAM); trafficQueues == nil { |
| 276 | log.Error("Failed to create traffic queues") |
| 277 | return errors.New(ReasonCodeToReasonString(QUEUE_CREATION_FAILED)) |
| 278 | } |
| 279 | |
| 280 | // On receiving the CreateTrafficQueues request, the driver should create corresponding |
| 281 | // downstream queues. |
| 282 | log.Debugw("Sending Traffic Queues create to device", |
| 283 | log.Fields{"Direction": tp_pb.Direction_DOWNSTREAM, "TrafficQueues": trafficQueues}) |
| 284 | if _, err := subs.OpenOltClient.CreateTrafficQueues(context.Background(), |
| 285 | &tp_pb.TrafficQueues{IntfId: subs.PonIntf, OnuId: subs.OnuID, |
| 286 | UniId: subs.UniID, PortNo: subs.UniPortNo, |
| 287 | TrafficQueues: trafficQueues}); err != nil { |
| 288 | log.Errorw("Failed to create traffic queues in device", log.Fields{"error": err}) |
| 289 | return errors.New(ReasonCodeToReasonString(QUEUE_CREATION_FAILED)) |
| 290 | } |
| 291 | |
| 292 | if trafficQueues = getTrafficQueues(subs, tp_pb.Direction_UPSTREAM); trafficQueues == nil { |
| 293 | log.Error("Failed to create traffic queues") |
| 294 | return errors.New(ReasonCodeToReasonString(QUEUE_CREATION_FAILED)) |
| 295 | } |
| 296 | |
| 297 | // On receiving the CreateTrafficQueues request, the driver should create corresponding |
| 298 | // upstream queues. |
| 299 | log.Debugw("Sending Traffic Queues create to device", |
| 300 | log.Fields{"Direction": tp_pb.Direction_UPSTREAM, "TrafficQueues": trafficQueues}) |
| 301 | if _, err := subs.OpenOltClient.CreateTrafficQueues(context.Background(), |
| 302 | &tp_pb.TrafficQueues{IntfId: subs.PonIntf, OnuId: subs.OnuID, |
| 303 | UniId: subs.UniID, PortNo: subs.UniPortNo, |
| 304 | TrafficQueues: trafficQueues}); err != nil { |
| 305 | log.Errorw("Failed to create traffic queues in device", log.Fields{"error": err}) |
| 306 | return errors.New(ReasonCodeToReasonString(QUEUE_CREATION_FAILED)) |
| 307 | } |
| 308 | |
| 309 | return nil |
| 310 | } |
| 311 | |
| 312 | func (tt TtWorkFlow) ProvisionEapFlow(subs *Subscriber) error { |
| 313 | log.Info("tt-workflow-does-not-support-eap-yet--nothing-to-do") |
| 314 | return nil |
| 315 | } |
| 316 | |
| 317 | func (tt TtWorkFlow) ProvisionDhcpIPV4Flow(subs *Subscriber) error { |
| 318 | log.Info("tt-workflow-does-not-require-dhcp-ipv4-yet--nothing-to-do") |
| 319 | return nil |
| 320 | } |
| 321 | |
| 322 | func (tt TtWorkFlow) ProvisionDhcpIPV6Flow(subs *Subscriber) error { |
| 323 | log.Info("tt-workflow-does-not-require-dhcp-ipv6-support--nothing-to-do") |
| 324 | return nil |
| 325 | } |
| 326 | |
| 327 | func (tt TtWorkFlow) ProvisionIgmpFlow(subs *Subscriber) error { |
| 328 | log.Info("tt-workflow-does-not-require-igmp-support--nothing-to-do") |
| 329 | return nil |
| 330 | } |
| 331 | |
| 332 | func (tt TtWorkFlow) ProvisionHsiaFlow(subs *Subscriber) error { |
| 333 | var err error |
Girish Gowdra | aeceb84 | 2020-08-21 12:10:39 -0700 | [diff] [blame^] | 334 | var flowID uint32 |
Orhan Kupusoglu | 66b00d8 | 2020-03-13 12:06:33 +0300 | [diff] [blame] | 335 | var gemPortIDs []uint32 |
| 336 | |
| 337 | var allocID = subs.TpInstance[subs.TestConfig.TpIDList[0]].UsScheduler.AllocID |
| 338 | for _, gem := range subs.TpInstance[subs.TestConfig.TpIDList[0]].UpstreamGemPortAttributeList { |
| 339 | gemPortIDs = append(gemPortIDs, gem.GemportID) |
| 340 | } |
| 341 | |
| 342 | for idx, gemID := range gemPortIDs { |
| 343 | pBitMap := subs.TpInstance[subs.TestConfig.TpIDList[0]].UpstreamGemPortAttributeList[idx].PbitMap |
| 344 | for pos, pbitSet := range strings.TrimPrefix(pBitMap, "0b") { |
| 345 | if pbitSet == '1' { |
| 346 | pcp := uint32(len(strings.TrimPrefix(pBitMap, "0b"))) - 1 - uint32(pos) |
Girish Gowdra | aeceb84 | 2020-08-21 12:10:39 -0700 | [diff] [blame^] | 347 | if flowID, err = subs.RsrMgr.GetFlowID(context.Background(), uint32(subs.PonIntf)); err != nil { |
Orhan Kupusoglu | 66b00d8 | 2020-03-13 12:06:33 +0300 | [diff] [blame] | 348 | return errors.New(ReasonCodeToReasonString(FLOW_ID_GENERATION_FAILED)) |
| 349 | } else { |
| 350 | var errUs, errDs error |
Girish Gowdra | aeceb84 | 2020-08-21 12:10:39 -0700 | [diff] [blame^] | 351 | if errUs = AddTtFlow(subs, HsiaFlow, Upstream, flowID, allocID, gemID, pcp); errUs != nil { |
Orhan Kupusoglu | 66b00d8 | 2020-03-13 12:06:33 +0300 | [diff] [blame] | 352 | log.Errorw("failed to install US HSIA flow", |
| 353 | log.Fields{"onuID": subs.OnuID, "uniID": subs.UniID, "intf": subs.PonIntf}) |
| 354 | } |
Girish Gowdra | aeceb84 | 2020-08-21 12:10:39 -0700 | [diff] [blame^] | 355 | if errDs = AddTtFlow(subs, HsiaFlow, Downstream, flowID, allocID, gemID, pcp); errDs != nil { |
Orhan Kupusoglu | 66b00d8 | 2020-03-13 12:06:33 +0300 | [diff] [blame] | 356 | log.Errorw("failed to install DS HSIA flow", |
| 357 | log.Fields{"onuID": subs.OnuID, "uniID": subs.UniID, "intf": subs.PonIntf}) |
| 358 | } |
Girish Gowdra | aeceb84 | 2020-08-21 12:10:39 -0700 | [diff] [blame^] | 359 | |
Orhan Kupusoglu | 66b00d8 | 2020-03-13 12:06:33 +0300 | [diff] [blame] | 360 | if errUs != nil || errDs != nil { |
| 361 | if errUs != nil { |
| 362 | return errUs |
| 363 | } |
| 364 | return errDs |
| 365 | } |
| 366 | } |
| 367 | } |
| 368 | } |
| 369 | } |
| 370 | return nil |
| 371 | } |
| 372 | |
| 373 | func (tt TtWorkFlow) ProvisionVoipFlow(subs *Subscriber) error { |
| 374 | var err error |
Girish Gowdra | aeceb84 | 2020-08-21 12:10:39 -0700 | [diff] [blame^] | 375 | var flowID uint32 |
Orhan Kupusoglu | 66b00d8 | 2020-03-13 12:06:33 +0300 | [diff] [blame] | 376 | var gemPortIDs []uint32 |
| 377 | |
| 378 | var allocID = subs.TpInstance[subs.TestConfig.TpIDList[0]].UsScheduler.AllocID |
| 379 | for _, gem := range subs.TpInstance[subs.TestConfig.TpIDList[0]].UpstreamGemPortAttributeList { |
| 380 | gemPortIDs = append(gemPortIDs, gem.GemportID) |
| 381 | } |
| 382 | |
| 383 | for idx, gemID := range gemPortIDs { |
| 384 | pBitMap := subs.TpInstance[subs.TestConfig.TpIDList[0]].UpstreamGemPortAttributeList[idx].PbitMap |
| 385 | for pos, pbitSet := range strings.TrimPrefix(pBitMap, "0b") { |
| 386 | if pbitSet == '1' { |
| 387 | pcp := uint32(len(strings.TrimPrefix(pBitMap, "0b"))) - 1 - uint32(pos) |
Girish Gowdra | aeceb84 | 2020-08-21 12:10:39 -0700 | [diff] [blame^] | 388 | if flowID, err = subs.RsrMgr.GetFlowID(context.Background(), uint32(subs.PonIntf)); err != nil { |
Orhan Kupusoglu | 66b00d8 | 2020-03-13 12:06:33 +0300 | [diff] [blame] | 389 | return errors.New(ReasonCodeToReasonString(FLOW_ID_GENERATION_FAILED)) |
| 390 | } else { |
| 391 | var errUs, errDs, errDhcp error |
Girish Gowdra | aeceb84 | 2020-08-21 12:10:39 -0700 | [diff] [blame^] | 392 | if errUs = AddTtFlow(subs, VoipFlow, Upstream, flowID, allocID, gemID, pcp); errUs != nil { |
Orhan Kupusoglu | 66b00d8 | 2020-03-13 12:06:33 +0300 | [diff] [blame] | 393 | log.Errorw("failed to install US VOIP flow", |
| 394 | log.Fields{"onuID": subs.OnuID, "uniID": subs.UniID, "intf": subs.PonIntf}) |
| 395 | } |
Girish Gowdra | aeceb84 | 2020-08-21 12:10:39 -0700 | [diff] [blame^] | 396 | if errDs = AddTtFlow(subs, VoipFlow, Downstream, flowID, allocID, gemID, pcp); errDs != nil { |
Orhan Kupusoglu | 66b00d8 | 2020-03-13 12:06:33 +0300 | [diff] [blame] | 397 | log.Errorw("failed to install DS VOIP flow", |
| 398 | log.Fields{"onuID": subs.OnuID, "uniID": subs.UniID, "intf": subs.PonIntf}) |
| 399 | } |
Girish Gowdra | aeceb84 | 2020-08-21 12:10:39 -0700 | [diff] [blame^] | 400 | if errDhcp = AddFlow(subs, DhcpFlowIPV4, Upstream, flowID, allocID, gemID, pcp); errDhcp != nil { |
Orhan Kupusoglu | 66b00d8 | 2020-03-13 12:06:33 +0300 | [diff] [blame] | 401 | log.Errorw("failed to install US VOIP-DHCP flow", |
| 402 | log.Fields{"onuID": subs.OnuID, "uniID": subs.UniID, "intf": subs.PonIntf}) |
| 403 | } |
Girish Gowdra | aeceb84 | 2020-08-21 12:10:39 -0700 | [diff] [blame^] | 404 | |
Orhan Kupusoglu | 66b00d8 | 2020-03-13 12:06:33 +0300 | [diff] [blame] | 405 | if errUs != nil || errDs != nil || errDhcp != nil { |
| 406 | if errUs != nil { |
| 407 | return errUs |
| 408 | } |
| 409 | if errDs != nil { |
| 410 | return errDs |
| 411 | } |
| 412 | return errDhcp |
| 413 | } |
| 414 | } |
| 415 | } |
| 416 | } |
| 417 | } |
| 418 | return nil |
| 419 | } |
| 420 | |
| 421 | func (tt TtWorkFlow) ProvisionVodFlow(subs *Subscriber) error { |
| 422 | var err error |
Girish Gowdra | aeceb84 | 2020-08-21 12:10:39 -0700 | [diff] [blame^] | 423 | var flowID uint32 |
Orhan Kupusoglu | 66b00d8 | 2020-03-13 12:06:33 +0300 | [diff] [blame] | 424 | var gemPortIDs []uint32 |
| 425 | |
| 426 | var allocID = subs.TpInstance[subs.TestConfig.TpIDList[0]].UsScheduler.AllocID |
| 427 | for _, gem := range subs.TpInstance[subs.TestConfig.TpIDList[0]].UpstreamGemPortAttributeList { |
| 428 | gemPortIDs = append(gemPortIDs, gem.GemportID) |
| 429 | } |
| 430 | |
| 431 | for idx, gemID := range gemPortIDs { |
| 432 | pBitMap := subs.TpInstance[subs.TestConfig.TpIDList[0]].UpstreamGemPortAttributeList[idx].PbitMap |
| 433 | for pos, pbitSet := range strings.TrimPrefix(pBitMap, "0b") { |
| 434 | if pbitSet == '1' { |
| 435 | pcp := uint32(len(strings.TrimPrefix(pBitMap, "0b"))) - 1 - uint32(pos) |
Girish Gowdra | aeceb84 | 2020-08-21 12:10:39 -0700 | [diff] [blame^] | 436 | if flowID, err = subs.RsrMgr.GetFlowID(context.Background(), uint32(subs.PonIntf)); err != nil { |
Orhan Kupusoglu | 66b00d8 | 2020-03-13 12:06:33 +0300 | [diff] [blame] | 437 | return errors.New(ReasonCodeToReasonString(FLOW_ID_GENERATION_FAILED)) |
| 438 | } else { |
| 439 | var errUs, errDs, errDhcp, errIgmp error |
Girish Gowdra | aeceb84 | 2020-08-21 12:10:39 -0700 | [diff] [blame^] | 440 | if errUs = AddTtFlow(subs, VodFlow, Upstream, flowID, allocID, gemID, pcp); errUs != nil { |
Orhan Kupusoglu | 66b00d8 | 2020-03-13 12:06:33 +0300 | [diff] [blame] | 441 | log.Errorw("failed to install US VOIP flow", |
| 442 | log.Fields{"onuID": subs.OnuID, "uniID": subs.UniID, "intf": subs.PonIntf}) |
| 443 | } |
Girish Gowdra | aeceb84 | 2020-08-21 12:10:39 -0700 | [diff] [blame^] | 444 | if errDs = AddTtFlow(subs, VodFlow, Downstream, flowID, allocID, gemID, pcp); errDs != nil { |
Orhan Kupusoglu | 66b00d8 | 2020-03-13 12:06:33 +0300 | [diff] [blame] | 445 | log.Errorw("failed to install DS VOIP flow", |
| 446 | log.Fields{"onuID": subs.OnuID, "uniID": subs.UniID, "intf": subs.PonIntf}) |
| 447 | } |
Girish Gowdra | aeceb84 | 2020-08-21 12:10:39 -0700 | [diff] [blame^] | 448 | if errDhcp = AddFlow(subs, DhcpFlowIPV4, Upstream, flowID, allocID, gemID, pcp); errDhcp != nil { |
Orhan Kupusoglu | 66b00d8 | 2020-03-13 12:06:33 +0300 | [diff] [blame] | 449 | log.Errorw("failed to install US VOIP-DHCP flow", |
| 450 | log.Fields{"onuID": subs.OnuID, "uniID": subs.UniID, "intf": subs.PonIntf}) |
| 451 | } |
Girish Gowdra | aeceb84 | 2020-08-21 12:10:39 -0700 | [diff] [blame^] | 452 | if errIgmp = AddTtFlow(subs, IgmpFlow, Upstream, flowID, allocID, gemID, pcp); errIgmp != nil { |
Orhan Kupusoglu | 66b00d8 | 2020-03-13 12:06:33 +0300 | [diff] [blame] | 453 | log.Errorw("failed to install US VOIP-IGMP flow", |
| 454 | log.Fields{"onuID": subs.OnuID, "uniID": subs.UniID, "intf": subs.PonIntf}) |
| 455 | } |
Girish Gowdra | aeceb84 | 2020-08-21 12:10:39 -0700 | [diff] [blame^] | 456 | |
Orhan Kupusoglu | 66b00d8 | 2020-03-13 12:06:33 +0300 | [diff] [blame] | 457 | if errUs != nil || errDs != nil || errDhcp != nil || errIgmp != nil { |
| 458 | if errUs != nil { |
| 459 | return errUs |
| 460 | } |
| 461 | if errDs != nil { |
| 462 | return errDs |
| 463 | } |
| 464 | if errDhcp != nil { |
| 465 | return errDhcp |
| 466 | } |
| 467 | return errIgmp |
| 468 | } |
| 469 | } |
| 470 | } |
| 471 | } |
| 472 | } |
| 473 | return nil |
| 474 | } |
| 475 | |
| 476 | func (tt TtWorkFlow) ProvisionMgmtFlow(subs *Subscriber) error { |
| 477 | var err error |
Girish Gowdra | aeceb84 | 2020-08-21 12:10:39 -0700 | [diff] [blame^] | 478 | var flowID uint32 |
Orhan Kupusoglu | 66b00d8 | 2020-03-13 12:06:33 +0300 | [diff] [blame] | 479 | var gemPortIDs []uint32 |
| 480 | |
| 481 | var allocID = subs.TpInstance[subs.TestConfig.TpIDList[0]].UsScheduler.AllocID |
| 482 | for _, gem := range subs.TpInstance[subs.TestConfig.TpIDList[0]].UpstreamGemPortAttributeList { |
| 483 | gemPortIDs = append(gemPortIDs, gem.GemportID) |
| 484 | } |
| 485 | |
| 486 | for idx, gemID := range gemPortIDs { |
| 487 | pBitMap := subs.TpInstance[subs.TestConfig.TpIDList[0]].UpstreamGemPortAttributeList[idx].PbitMap |
| 488 | for pos, pbitSet := range strings.TrimPrefix(pBitMap, "0b") { |
| 489 | if pbitSet == '1' { |
| 490 | pcp := uint32(len(strings.TrimPrefix(pBitMap, "0b"))) - 1 - uint32(pos) |
Girish Gowdra | aeceb84 | 2020-08-21 12:10:39 -0700 | [diff] [blame^] | 491 | if flowID, err = subs.RsrMgr.GetFlowID(context.Background(), uint32(subs.PonIntf)); err != nil { |
Orhan Kupusoglu | 66b00d8 | 2020-03-13 12:06:33 +0300 | [diff] [blame] | 492 | return errors.New(ReasonCodeToReasonString(FLOW_ID_GENERATION_FAILED)) |
| 493 | } else { |
| 494 | var errUs, errDs, errDhcp error |
Girish Gowdra | aeceb84 | 2020-08-21 12:10:39 -0700 | [diff] [blame^] | 495 | if errUs = AddTtFlow(subs, MgmtFlow, Upstream, flowID, allocID, gemID, pcp); errUs != nil { |
Orhan Kupusoglu | 66b00d8 | 2020-03-13 12:06:33 +0300 | [diff] [blame] | 496 | log.Errorw("failed to install US MGMT flow", |
| 497 | log.Fields{"onuID": subs.OnuID, "uniID": subs.UniID, "intf": subs.PonIntf}) |
| 498 | } |
Girish Gowdra | aeceb84 | 2020-08-21 12:10:39 -0700 | [diff] [blame^] | 499 | if errDs = AddTtFlow(subs, MgmtFlow, Downstream, flowID, allocID, gemID, pcp); errDs != nil { |
Orhan Kupusoglu | 66b00d8 | 2020-03-13 12:06:33 +0300 | [diff] [blame] | 500 | log.Errorw("failed to install DS MGMT flow", |
| 501 | log.Fields{"onuID": subs.OnuID, "uniID": subs.UniID, "intf": subs.PonIntf}) |
| 502 | } |
Girish Gowdra | aeceb84 | 2020-08-21 12:10:39 -0700 | [diff] [blame^] | 503 | if errDhcp = AddFlow(subs, DhcpFlowIPV4, Upstream, flowID, allocID, gemID, pcp); errDhcp != nil { |
Orhan Kupusoglu | 66b00d8 | 2020-03-13 12:06:33 +0300 | [diff] [blame] | 504 | log.Errorw("failed to install US MGMT-DHCP flow", |
| 505 | log.Fields{"onuID": subs.OnuID, "uniID": subs.UniID, "intf": subs.PonIntf}) |
| 506 | } |
Girish Gowdra | aeceb84 | 2020-08-21 12:10:39 -0700 | [diff] [blame^] | 507 | |
Orhan Kupusoglu | 66b00d8 | 2020-03-13 12:06:33 +0300 | [diff] [blame] | 508 | if errUs != nil || errDs != nil || errDhcp != nil { |
| 509 | if errUs != nil { |
| 510 | return errUs |
| 511 | } |
| 512 | if errDs != nil { |
| 513 | return errDs |
| 514 | } |
| 515 | return errDhcp |
| 516 | } |
| 517 | } |
| 518 | } |
| 519 | } |
| 520 | } |
| 521 | return nil |
| 522 | } |
| 523 | |
| 524 | func (tt TtWorkFlow) ProvisionMulticastFlow(subs *Subscriber) error { |
| 525 | var grp GroupData |
| 526 | var err error |
| 527 | |
| 528 | numOfONUsPerPon := uint32(subs.TestConfig.NumOfOnu / uint(subs.RsrMgr.deviceInfo.GetPonPorts())) |
| 529 | |
| 530 | grp.Subs = *subs |
| 531 | grp.Weight = 20 |
| 532 | grp.Priority = 0 |
| 533 | grp.OnuID = 6666 |
| 534 | grp.UniID = 6666 |
| 535 | grp.AllocID = 0 |
| 536 | grp.GemPortID = 4069 |
| 537 | grp.SchedPolicy = tp_pb.SchedulingPolicy_WRR |
| 538 | |
| 539 | log.Debugw("Group data", log.Fields{"OnuID": subs.OnuID, "GroupID": grp.GroupID, "numOfONUsPerPon": numOfONUsPerPon}) |
| 540 | |
| 541 | grp.GroupID = subs.OnuID |
| 542 | |
| 543 | if subs.PonIntf == 0 { |
| 544 | grp.AddGroup = true |
| 545 | grp.AddFlow = true |
| 546 | } else { |
| 547 | grp.AddFlow = false |
| 548 | grp.AddGroup = false |
| 549 | } |
| 550 | |
| 551 | if subs.PonIntf == atomic.LoadUint32(lastPonIntf) { |
| 552 | _ = atomic.AddUint32(lastPonIntf, 1) |
| 553 | grp.AddSched = true |
| 554 | grp.AddQueue = true |
| 555 | } else { |
| 556 | grp.AddSched = false |
| 557 | grp.AddQueue = false |
| 558 | } |
| 559 | |
| 560 | grp.AddMember = true |
| 561 | |
| 562 | err = AddMulticastQueueFlow(&grp) |
| 563 | |
| 564 | if err != nil { |
| 565 | log.Errorw("Failed to add multicast flow", log.Fields{"error": err}) |
| 566 | } |
| 567 | |
| 568 | return err |
| 569 | } |