blob: 3a8aef33dbc813384f1d8b5b7e3fc9c5616dd517 [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"
Girish Gowdra390f12f2021-07-01 15:53:49 -070025 "github.com/opencord/voltha-lib-go/v7/pkg/log"
26 oop "github.com/opencord/voltha-protos/v5/go/openolt"
Girish Gowdra64503432020-01-07 10:59:10 +053027)
28
Girish Gowdra64503432020-01-07 10:59:10 +053029type SubscriberKey struct {
30 SubscriberName string
31}
32
33type 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 Gowdraaeceb842020-08-21 12:10:39 -070045 onuWg *sync.WaitGroup
Girish Gowdra64503432020-01-07 10:59:10 +053046}
47
Girish Gowdraaeceb842020-08-21 12:10:39 -070048func (onu *OnuDevice) Start() {
Girish Gowdra64503432020-01-07 10:59:10 +053049 onu.SubscriberMap = make(map[SubscriberKey]*Subscriber)
Girish Gowdra64503432020-01-07 10:59:10 +053050 var subs uint
Girish Gowdraaeceb842020-08-21 12:10:39 -070051 var subWg sync.WaitGroup
Girish Gowdra5d7d6442020-09-08 17:03:11 -070052 logger.Infow(nil, "onu-provision-started-from-onu-manager", log.Fields{"onuID": onu.OnuID, "ponIntf": onu.PonIntf})
Girish Gowdra64503432020-01-07 10:59:10 +053053
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 Subramanib83b0432020-01-08 13:43:28 +053063 Stag: GetStag(onu.testConfig.WorkflowName, onu.PonIntf, onu.OnuID, uint32(subs)),
Girish Gowdra64503432020-01-07 10:59:10 +053064 OpenOltClient: onu.openOltClient,
65 TestConfig: onu.testConfig,
66 RsrMgr: onu.rsrMgr,
Girish Gowdraaeceb842020-08-21 12:10:39 -070067 subWg: &subWg,
Girish Gowdra64503432020-01-07 10:59:10 +053068 }
69 subsKey := SubscriberKey{subsName}
70 onu.SubscriberMap[subsKey] = &subs
71
Girish Gowdraaeceb842020-08-21 12:10:39 -070072 subWg.Add(1)
Girish Gowdra5d7d6442020-09-08 17:03:11 -070073 logger.Infow(nil, "subscriber-provision-started-from-onu-manager", log.Fields{"subsName": subsName})
Girish Gowdra64503432020-01-07 10:59:10 +053074 // Start provisioning the subscriber
Girish Gowdraaeceb842020-08-21 12:10:39 -070075 go subs.Start(onu.testConfig.IsGroupTest)
Girish Gowdra64503432020-01-07 10:59:10 +053076
Girish Gowdra64503432020-01-07 10:59:10 +053077 }
Girish Gowdraaeceb842020-08-21 12:10:39 -070078
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 Gowdra64503432020-01-07 10:59:10 +053083
Girish Gowdra5d7d6442020-09-08 17:03:11 -070084 logger.Infow(nil, "onu-provision-completed-from-onu-manager", log.Fields{"onuID": onu.OnuID, "ponIntf": onu.PonIntf})
Girish Gowdra64503432020-01-07 10:59:10 +053085}