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 | "github.com/opencord/openolt-scale-tester/config" |
| 21 | "github.com/opencord/voltha-lib-go/v2/pkg/log" |
| 22 | oop "github.com/opencord/voltha-protos/v2/go/openolt" |
| 23 | "strconv" |
| 24 | "time" |
| 25 | ) |
| 26 | |
| 27 | func init() { |
| 28 | _, _ = log.AddPackage(log.JSON, log.DebugLevel, nil) |
| 29 | } |
| 30 | |
| 31 | type SubscriberKey struct { |
| 32 | SubscriberName string |
| 33 | } |
| 34 | |
| 35 | type OnuDevice struct { |
| 36 | SerialNum string `json:"onuSerialNum"` |
| 37 | OnuID uint32 `json:"onuID"` |
| 38 | PonIntf uint32 `json:"ponIntf"` |
| 39 | OnuProvisionStartTime time.Time `json:"onuProvisionStartTime"` |
| 40 | OnuProvisionEndTime time.Time `json:"onuProvisionEndTime"` |
| 41 | OnuProvisionDurationInMs int64 `json:"onuProvisionDurationInMilliSec"` |
| 42 | Reason string `json:"reason"` // If provisioning failed, this specifies the reason. |
| 43 | SubscriberMap map[SubscriberKey]*Subscriber `json:"subscriberMap"` |
| 44 | openOltClient oop.OpenoltClient |
| 45 | testConfig *config.OpenOltScaleTesterConfig |
| 46 | rsrMgr *OpenOltResourceMgr |
| 47 | } |
| 48 | |
| 49 | func (onu *OnuDevice) Start(oltCh chan bool) { |
| 50 | onu.SubscriberMap = make(map[SubscriberKey]*Subscriber) |
| 51 | onuCh := make(chan bool) |
| 52 | var subs uint |
| 53 | |
| 54 | log.Infow("onu-provision-started-from-onu-manager", log.Fields{"onuID": onu.OnuID, "ponIntf": onu.PonIntf}) |
| 55 | |
| 56 | for subs = 0; subs < onu.testConfig.SubscribersPerOnu; subs++ { |
| 57 | subsName := onu.SerialNum + "-" + strconv.Itoa(int(subs)) |
| 58 | subs := Subscriber{ |
| 59 | SubscriberName: subsName, |
| 60 | OnuID: onu.OnuID, |
| 61 | UniID: uint32(subs), |
| 62 | PonIntf: onu.PonIntf, |
| 63 | UniPortNo: MkUniPortNum(onu.PonIntf, onu.OnuID, uint32(subs)), |
| 64 | Ctag: GetCtag(onu.testConfig.WorkflowName, onu.PonIntf), |
| 65 | Stag: GetStag(onu.testConfig.WorkflowName, onu.PonIntf), |
| 66 | OpenOltClient: onu.openOltClient, |
| 67 | TestConfig: onu.testConfig, |
| 68 | RsrMgr: onu.rsrMgr, |
| 69 | } |
| 70 | subsKey := SubscriberKey{subsName} |
| 71 | onu.SubscriberMap[subsKey] = &subs |
| 72 | |
| 73 | log.Infow("subscriber-provision-started-from-onu-manager", log.Fields{"subsName": subsName}) |
| 74 | // Start provisioning the subscriber |
| 75 | go subs.Start(onuCh) |
| 76 | |
| 77 | // Wait for subscriber provision to complete |
| 78 | <-onuCh |
| 79 | |
| 80 | log.Infow("subscriber-provision-completed-from-onu-manager", log.Fields{"subsName": subsName}) |
| 81 | |
| 82 | //Sleep for configured interval before provisioning another subscriber |
| 83 | time.Sleep(time.Duration(onu.testConfig.TimeIntervalBetweenSubs)) |
| 84 | } |
| 85 | // Indicate that the ONU provisioning is complete |
| 86 | oltCh <- true |
| 87 | |
| 88 | log.Infow("onu-provision-completed-from-onu-manager", log.Fields{"onuID": onu.OnuID, "ponIntf": onu.PonIntf}) |
| 89 | } |