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 ( |
Girish Gowdra | 6450343 | 2020-01-07 10:59:10 +0530 | [diff] [blame] | 20 | "strconv" |
Girish Gowdra | aeceb84 | 2020-08-21 12:10:39 -0700 | [diff] [blame] | 21 | "sync" |
Girish Gowdra | 6450343 | 2020-01-07 10:59:10 +0530 | [diff] [blame] | 22 | "time" |
Orhan Kupusoglu | 66b00d8 | 2020-03-13 12:06:33 +0300 | [diff] [blame] | 23 | |
| 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" |
Girish Gowdra | 6450343 | 2020-01-07 10:59:10 +0530 | [diff] [blame] | 27 | ) |
| 28 | |
Girish Gowdra | 6450343 | 2020-01-07 10:59:10 +0530 | [diff] [blame] | 29 | type SubscriberKey struct { |
| 30 | SubscriberName string |
| 31 | } |
| 32 | |
| 33 | type OnuDevice struct { |
| 34 | SerialNum string `json:"onuSerialNum"` |
| 35 | OnuID uint32 `json:"onuID"` |
| 36 | PonIntf uint32 `json:"ponIntf"` |
| 37 | OnuProvisionStartTime time.Time `json:"onuProvisionStartTime"` |
| 38 | OnuProvisionEndTime time.Time `json:"onuProvisionEndTime"` |
| 39 | OnuProvisionDurationInMs int64 `json:"onuProvisionDurationInMilliSec"` |
| 40 | Reason string `json:"reason"` // If provisioning failed, this specifies the reason. |
| 41 | SubscriberMap map[SubscriberKey]*Subscriber `json:"subscriberMap"` |
| 42 | openOltClient oop.OpenoltClient |
| 43 | testConfig *config.OpenOltScaleTesterConfig |
| 44 | rsrMgr *OpenOltResourceMgr |
Girish Gowdra | aeceb84 | 2020-08-21 12:10:39 -0700 | [diff] [blame] | 45 | onuWg *sync.WaitGroup |
Girish Gowdra | 6450343 | 2020-01-07 10:59:10 +0530 | [diff] [blame] | 46 | } |
| 47 | |
Girish Gowdra | aeceb84 | 2020-08-21 12:10:39 -0700 | [diff] [blame] | 48 | func (onu *OnuDevice) Start() { |
Girish Gowdra | 6450343 | 2020-01-07 10:59:10 +0530 | [diff] [blame] | 49 | onu.SubscriberMap = make(map[SubscriberKey]*Subscriber) |
Girish Gowdra | 6450343 | 2020-01-07 10:59:10 +0530 | [diff] [blame] | 50 | var subs uint |
Girish Gowdra | aeceb84 | 2020-08-21 12:10:39 -0700 | [diff] [blame] | 51 | var subWg sync.WaitGroup |
Girish Gowdra | 5d7d644 | 2020-09-08 17:03:11 -0700 | [diff] [blame] | 52 | logger.Infow(nil, "onu-provision-started-from-onu-manager", log.Fields{"onuID": onu.OnuID, "ponIntf": onu.PonIntf}) |
Girish Gowdra | 6450343 | 2020-01-07 10:59:10 +0530 | [diff] [blame] | 53 | |
| 54 | for subs = 0; subs < onu.testConfig.SubscribersPerOnu; subs++ { |
| 55 | subsName := onu.SerialNum + "-" + strconv.Itoa(int(subs)) |
| 56 | subs := Subscriber{ |
| 57 | SubscriberName: subsName, |
| 58 | OnuID: onu.OnuID, |
| 59 | UniID: uint32(subs), |
| 60 | PonIntf: onu.PonIntf, |
| 61 | UniPortNo: MkUniPortNum(onu.PonIntf, onu.OnuID, uint32(subs)), |
| 62 | Ctag: GetCtag(onu.testConfig.WorkflowName, onu.PonIntf), |
Thiyagarajan Subramani | b83b043 | 2020-01-08 13:43:28 +0530 | [diff] [blame] | 63 | Stag: GetStag(onu.testConfig.WorkflowName, onu.PonIntf, onu.OnuID, uint32(subs)), |
Girish Gowdra | 6450343 | 2020-01-07 10:59:10 +0530 | [diff] [blame] | 64 | OpenOltClient: onu.openOltClient, |
| 65 | TestConfig: onu.testConfig, |
| 66 | RsrMgr: onu.rsrMgr, |
Girish Gowdra | aeceb84 | 2020-08-21 12:10:39 -0700 | [diff] [blame] | 67 | subWg: &subWg, |
Girish Gowdra | 6450343 | 2020-01-07 10:59:10 +0530 | [diff] [blame] | 68 | } |
| 69 | subsKey := SubscriberKey{subsName} |
| 70 | onu.SubscriberMap[subsKey] = &subs |
| 71 | |
Girish Gowdra | aeceb84 | 2020-08-21 12:10:39 -0700 | [diff] [blame] | 72 | subWg.Add(1) |
Girish Gowdra | 5d7d644 | 2020-09-08 17:03:11 -0700 | [diff] [blame] | 73 | logger.Infow(nil, "subscriber-provision-started-from-onu-manager", log.Fields{"subsName": subsName}) |
Girish Gowdra | 6450343 | 2020-01-07 10:59:10 +0530 | [diff] [blame] | 74 | // Start provisioning the subscriber |
Girish Gowdra | aeceb84 | 2020-08-21 12:10:39 -0700 | [diff] [blame] | 75 | go subs.Start(onu.testConfig.IsGroupTest) |
Girish Gowdra | 6450343 | 2020-01-07 10:59:10 +0530 | [diff] [blame] | 76 | |
Girish Gowdra | 6450343 | 2020-01-07 10:59:10 +0530 | [diff] [blame] | 77 | } |
Girish Gowdra | aeceb84 | 2020-08-21 12:10:39 -0700 | [diff] [blame] | 78 | |
| 79 | // Wait for all the subscribers on the ONU to complete provisioning |
| 80 | subWg.Wait() |
| 81 | // Signal that ONU provisioning is complete |
| 82 | onu.onuWg.Done() |
Girish Gowdra | 6450343 | 2020-01-07 10:59:10 +0530 | [diff] [blame] | 83 | |
Girish Gowdra | 5d7d644 | 2020-09-08 17:03:11 -0700 | [diff] [blame] | 84 | logger.Infow(nil, "onu-provision-completed-from-onu-manager", log.Fields{"onuID": onu.OnuID, "ponIntf": onu.PonIntf}) |
Girish Gowdra | 6450343 | 2020-01-07 10:59:10 +0530 | [diff] [blame] | 85 | } |