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