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