blob: 4fd665bdb9bebc81915be6d810eb6b34bfdd1945 [file] [log] [blame]
Girish Gowdra64503432020-01-07 10:59:10 +05301/*
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
17package core
18
19import (
Girish Gowdra64503432020-01-07 10:59:10 +053020 "strconv"
Girish Gowdraaeceb842020-08-21 12:10:39 -070021 "sync"
Girish Gowdra64503432020-01-07 10:59:10 +053022 "time"
Orhan Kupusoglu66b00d82020-03-13 12:06:33 +030023
24 "github.com/opencord/openolt-scale-tester/config"
25 "github.com/opencord/voltha-lib-go/v3/pkg/log"
26 oop "github.com/opencord/voltha-protos/v3/go/openolt"
Girish Gowdra64503432020-01-07 10:59:10 +053027)
28
29func init() {
30 _, _ = log.AddPackage(log.JSON, log.DebugLevel, nil)
31}
32
33type SubscriberKey struct {
34 SubscriberName string
35}
36
37type OnuDevice struct {
38 SerialNum string `json:"onuSerialNum"`
39 OnuID uint32 `json:"onuID"`
40 PonIntf uint32 `json:"ponIntf"`
41 OnuProvisionStartTime time.Time `json:"onuProvisionStartTime"`
42 OnuProvisionEndTime time.Time `json:"onuProvisionEndTime"`
43 OnuProvisionDurationInMs int64 `json:"onuProvisionDurationInMilliSec"`
44 Reason string `json:"reason"` // If provisioning failed, this specifies the reason.
45 SubscriberMap map[SubscriberKey]*Subscriber `json:"subscriberMap"`
46 openOltClient oop.OpenoltClient
47 testConfig *config.OpenOltScaleTesterConfig
48 rsrMgr *OpenOltResourceMgr
Girish Gowdraaeceb842020-08-21 12:10:39 -070049 onuWg *sync.WaitGroup
Girish Gowdra64503432020-01-07 10:59:10 +053050}
51
Girish Gowdraaeceb842020-08-21 12:10:39 -070052func (onu *OnuDevice) Start() {
Girish Gowdra64503432020-01-07 10:59:10 +053053 onu.SubscriberMap = make(map[SubscriberKey]*Subscriber)
Girish Gowdra64503432020-01-07 10:59:10 +053054 var subs uint
Girish Gowdraaeceb842020-08-21 12:10:39 -070055 var subWg sync.WaitGroup
Girish Gowdra64503432020-01-07 10:59:10 +053056 log.Infow("onu-provision-started-from-onu-manager", log.Fields{"onuID": onu.OnuID, "ponIntf": onu.PonIntf})
57
58 for subs = 0; subs < onu.testConfig.SubscribersPerOnu; subs++ {
59 subsName := onu.SerialNum + "-" + strconv.Itoa(int(subs))
60 subs := Subscriber{
61 SubscriberName: subsName,
62 OnuID: onu.OnuID,
63 UniID: uint32(subs),
64 PonIntf: onu.PonIntf,
65 UniPortNo: MkUniPortNum(onu.PonIntf, onu.OnuID, uint32(subs)),
66 Ctag: GetCtag(onu.testConfig.WorkflowName, onu.PonIntf),
Thiyagarajan Subramanib83b0432020-01-08 13:43:28 +053067 Stag: GetStag(onu.testConfig.WorkflowName, onu.PonIntf, onu.OnuID, uint32(subs)),
Girish Gowdra64503432020-01-07 10:59:10 +053068 OpenOltClient: onu.openOltClient,
69 TestConfig: onu.testConfig,
70 RsrMgr: onu.rsrMgr,
Girish Gowdraaeceb842020-08-21 12:10:39 -070071 subWg: &subWg,
Girish Gowdra64503432020-01-07 10:59:10 +053072 }
73 subsKey := SubscriberKey{subsName}
74 onu.SubscriberMap[subsKey] = &subs
75
Girish Gowdraaeceb842020-08-21 12:10:39 -070076 subWg.Add(1)
Girish Gowdra64503432020-01-07 10:59:10 +053077 log.Infow("subscriber-provision-started-from-onu-manager", log.Fields{"subsName": subsName})
78 // Start provisioning the subscriber
Girish Gowdraaeceb842020-08-21 12:10:39 -070079 go subs.Start(onu.testConfig.IsGroupTest)
Girish Gowdra64503432020-01-07 10:59:10 +053080
Girish Gowdra64503432020-01-07 10:59:10 +053081 }
Girish Gowdraaeceb842020-08-21 12:10:39 -070082
83 // Wait for all the subscribers on the ONU to complete provisioning
84 subWg.Wait()
85 // Signal that ONU provisioning is complete
86 onu.onuWg.Done()
Girish Gowdra64503432020-01-07 10:59:10 +053087
88 log.Infow("onu-provision-completed-from-onu-manager", log.Fields{"onuID": onu.OnuID, "ponIntf": onu.PonIntf})
89}