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