blob: 9abec13429d01526d1c7efafac5834fca1202b45 [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 (
20 "fmt"
Girish Gowdraaeceb842020-08-21 12:10:39 -070021 "sync"
Orhan Kupusoglu66b00d82020-03-13 12:06:33 +030022
Girish Gowdra64503432020-01-07 10:59:10 +053023 "github.com/opencord/openolt-scale-tester/config"
Girish Gowdra5d7d6442020-09-08 17:03:11 -070024 "github.com/opencord/voltha-lib-go/v4/pkg/log"
25 "github.com/opencord/voltha-lib-go/v4/pkg/techprofile"
26 oop "github.com/opencord/voltha-protos/v4/go/openolt"
Orhan Kupusoglu66b00d82020-03-13 12:06:33 +030027 "golang.org/x/net/context"
Girish Gowdra64503432020-01-07 10:59:10 +053028)
29
Girish Gowdra64503432020-01-07 10:59:10 +053030const (
31 SUBSCRIBER_PROVISION_SUCCESS = iota
32 TP_INSTANCE_CREATION_FAILED
Thiyagarajan Subramanib83b0432020-01-08 13:43:28 +053033 FLOW_ID_GENERATION_FAILED
Girish Gowdra64503432020-01-07 10:59:10 +053034 FLOW_ADD_FAILED
35 SCHED_CREATION_FAILED
36 QUEUE_CREATION_FAILED
37)
38
39const (
Girish Gowdra5d7d6442020-09-08 17:03:11 -070040 UniPortName = "olt-{1}/pon-{%d}/onu-{%d}/uni-{%d}"
Girish Gowdra64503432020-01-07 10:59:10 +053041)
42
43var Reason = [...]string{
44 "SUBSCRIBER_PROVISION_SUCCESS",
45 "TP_INSTANCE_CREATION_FAILED",
Thiyagarajan Subramanib83b0432020-01-08 13:43:28 +053046 "FLOW_ID_GENERATION_FAILED",
Girish Gowdra64503432020-01-07 10:59:10 +053047 "FLOW_ADD_FAILED",
48 "SCHED_CREATION_FAILED",
49 "QUEUE_CREATION_FAILED",
50}
51
52func ReasonCodeToReasonString(reasonCode int) string {
53 return Reason[reasonCode]
54}
55
56type Subscriber struct {
57 SubscriberName string `json:"subscriberName"`
58 OnuID uint32 `json:"onuID"`
59 UniID uint32 `json:"uniID"`
60 PonIntf uint32 `json:"ponIntf"`
61 UniPortNo uint32 `json:"uniPortNo"`
62 Ctag uint32 `json:"ctag"`
63 Stag uint32 `json:"stag"`
64 GemPortIDs []uint32 `json:"gemPortIds"`
65 AllocIDs []uint32 `json:"allocIds"`
66 FlowIDs []uint32 `json:"flowIds"`
67 Reason string `json:"reason"`
68
69 FailedFlowCnt uint32 `json:"failedFlowCnt"`
70 SuccessFlowCnt uint32 `json:"successFlowCnt"`
71
72 FailedSchedCnt uint32 `json:"failedSchedCnt"`
73 SuccessSchedCnt uint32 `json:"successShedCnt"`
74
75 FailedQueueCnt uint32 `json:"failedQueueCnt"`
76 SuccessQueueCnt uint32 `json:"successQueueCnt"`
77
78 FailedFlows []oop.Flow `json:"failedFlows"`
79 FailedScheds []oop.TrafficScheduler `json:"failedScheds"`
80 FailedQueues []oop.TrafficQueue `json:"failedQueues"`
81
82 TpInstance map[int]*techprofile.TechProfile
83 OpenOltClient oop.OpenoltClient
84 TestConfig *config.OpenOltScaleTesterConfig
85 RsrMgr *OpenOltResourceMgr
Girish Gowdraaeceb842020-08-21 12:10:39 -070086 subWg *sync.WaitGroup
Girish Gowdra64503432020-01-07 10:59:10 +053087}
88
Girish Gowdraaeceb842020-08-21 12:10:39 -070089func (subs *Subscriber) Start(isGroup bool) {
90
Girish Gowdra5d7d6442020-09-08 17:03:11 -070091 logger.Infow(nil, "workflow-deploy-started-for-subscriber", log.Fields{"subsName": subs.SubscriberName})
Girish Gowdra64503432020-01-07 10:59:10 +053092
93 subs.TpInstance = make(map[int]*techprofile.TechProfile)
94
95 for _, tpID := range subs.TestConfig.TpIDList {
96 uniPortName := fmt.Sprintf(UniPortName, subs.PonIntf, subs.OnuID, subs.UniID)
Girish Gowdraaeceb842020-08-21 12:10:39 -070097 subs.RsrMgr.GemIDAllocIDLock[subs.PonIntf].Lock()
Girish Gowdra5d7d6442020-09-08 17:03:11 -070098 tpInstInterface, err := subs.RsrMgr.ResourceMgrs[subs.PonIntf].TechProfileMgr.CreateTechProfInstance(context.Background(), uint32(tpID), uniPortName, subs.PonIntf)
99 // TODO: Assumes the techprofile is of type TechProfile (XGPON, GPON). But it could also be EPON TechProfile type. But we do not support that at the moment, so it is OK.
100 subs.TpInstance[tpID] = tpInstInterface.(*techprofile.TechProfile)
101
Girish Gowdraaeceb842020-08-21 12:10:39 -0700102 subs.RsrMgr.GemIDAllocIDLock[subs.PonIntf].Unlock()
103 if err != nil {
Girish Gowdra5d7d6442020-09-08 17:03:11 -0700104 logger.Errorw(nil, "error-creating-tp-instance-for-subs",
Girish Gowdra64503432020-01-07 10:59:10 +0530105 log.Fields{"subsName": subs.SubscriberName, "onuID": subs.OnuID, "tpID": tpID})
106
107 subs.Reason = ReasonCodeToReasonString(TP_INSTANCE_CREATION_FAILED)
Girish Gowdra64503432020-01-07 10:59:10 +0530108 return
109 }
110 }
111
Girish Gowdraaeceb842020-08-21 12:10:39 -0700112 go DeployWorkflow(subs, isGroup)
Girish Gowdra64503432020-01-07 10:59:10 +0530113
Girish Gowdra5d7d6442020-09-08 17:03:11 -0700114 logger.Infow(nil, "workflow-deploy-started-for-subscriber", log.Fields{"subsName": subs.SubscriberName})
Girish Gowdra64503432020-01-07 10:59:10 +0530115}