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 | "fmt" |
| 21 | "github.com/opencord/openolt-scale-tester/config" |
| 22 | "github.com/opencord/voltha-lib-go/v2/pkg/log" |
| 23 | "github.com/opencord/voltha-lib-go/v2/pkg/techprofile" |
| 24 | oop "github.com/opencord/voltha-protos/v2/go/openolt" |
| 25 | ) |
| 26 | |
| 27 | func init() { |
| 28 | _, _ = log.AddPackage(log.JSON, log.DebugLevel, nil) |
| 29 | } |
| 30 | |
| 31 | const ( |
| 32 | SUBSCRIBER_PROVISION_SUCCESS = iota |
| 33 | TP_INSTANCE_CREATION_FAILED |
| 34 | FLOW_ADD_FAILED |
| 35 | SCHED_CREATION_FAILED |
| 36 | QUEUE_CREATION_FAILED |
| 37 | ) |
| 38 | |
| 39 | const ( |
| 40 | UniPortName = "pon-{%d}/onu-{%d}/uni-{%d}" |
| 41 | ) |
| 42 | |
| 43 | var Reason = [...]string{ |
| 44 | "SUBSCRIBER_PROVISION_SUCCESS", |
| 45 | "TP_INSTANCE_CREATION_FAILED", |
| 46 | "FLOW_ADD_FAILED", |
| 47 | "SCHED_CREATION_FAILED", |
| 48 | "QUEUE_CREATION_FAILED", |
| 49 | } |
| 50 | |
| 51 | func ReasonCodeToReasonString(reasonCode int) string { |
| 52 | return Reason[reasonCode] |
| 53 | } |
| 54 | |
| 55 | type Subscriber struct { |
| 56 | SubscriberName string `json:"subscriberName"` |
| 57 | OnuID uint32 `json:"onuID"` |
| 58 | UniID uint32 `json:"uniID"` |
| 59 | PonIntf uint32 `json:"ponIntf"` |
| 60 | UniPortNo uint32 `json:"uniPortNo"` |
| 61 | Ctag uint32 `json:"ctag"` |
| 62 | Stag uint32 `json:"stag"` |
| 63 | GemPortIDs []uint32 `json:"gemPortIds"` |
| 64 | AllocIDs []uint32 `json:"allocIds"` |
| 65 | FlowIDs []uint32 `json:"flowIds"` |
| 66 | Reason string `json:"reason"` |
| 67 | |
| 68 | FailedFlowCnt uint32 `json:"failedFlowCnt"` |
| 69 | SuccessFlowCnt uint32 `json:"successFlowCnt"` |
| 70 | |
| 71 | FailedSchedCnt uint32 `json:"failedSchedCnt"` |
| 72 | SuccessSchedCnt uint32 `json:"successShedCnt"` |
| 73 | |
| 74 | FailedQueueCnt uint32 `json:"failedQueueCnt"` |
| 75 | SuccessQueueCnt uint32 `json:"successQueueCnt"` |
| 76 | |
| 77 | FailedFlows []oop.Flow `json:"failedFlows"` |
| 78 | FailedScheds []oop.TrafficScheduler `json:"failedScheds"` |
| 79 | FailedQueues []oop.TrafficQueue `json:"failedQueues"` |
| 80 | |
| 81 | TpInstance map[int]*techprofile.TechProfile |
| 82 | OpenOltClient oop.OpenoltClient |
| 83 | TestConfig *config.OpenOltScaleTesterConfig |
| 84 | RsrMgr *OpenOltResourceMgr |
| 85 | } |
| 86 | |
| 87 | func (subs *Subscriber) Start(onuCh chan bool) { |
| 88 | |
| 89 | log.Infow("workflow-deploy-started-for-subscriber", log.Fields{"subsName": subs.SubscriberName}) |
| 90 | |
| 91 | subs.TpInstance = make(map[int]*techprofile.TechProfile) |
| 92 | |
| 93 | for _, tpID := range subs.TestConfig.TpIDList { |
| 94 | uniPortName := fmt.Sprintf(UniPortName, subs.PonIntf, subs.OnuID, subs.UniID) |
| 95 | if subs.TpInstance[tpID] = |
| 96 | subs.RsrMgr.ResourceMgrs[subs.PonIntf].TechProfileMgr.CreateTechProfInstance( |
| 97 | uint32(tpID), uniPortName, subs.PonIntf); subs.TpInstance[tpID] == nil { |
| 98 | log.Errorw("error-creating-tp-instance-for-subs", |
| 99 | log.Fields{"subsName": subs.SubscriberName, "onuID": subs.OnuID, "tpID": tpID}) |
| 100 | |
| 101 | subs.Reason = ReasonCodeToReasonString(TP_INSTANCE_CREATION_FAILED) |
| 102 | onuCh <- true |
| 103 | |
| 104 | return |
| 105 | } |
| 106 | } |
| 107 | |
| 108 | DeployWorkflow(subs) |
| 109 | |
| 110 | log.Infow("workflow-deploy-completed-for-subscriber", log.Fields{"subsName": subs.SubscriberName}) |
| 111 | |
| 112 | onuCh <- true |
| 113 | } |