blob: 8c92b56d30e071d41203fdf72a7cdb53fd5d1111 [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 Gowdra390f12f2021-07-01 15:53:49 -070021 "github.com/opencord/voltha-protos/v5/go/tech_profile"
Girish Gowdraaeceb842020-08-21 12:10:39 -070022 "sync"
Orhan Kupusoglu66b00d82020-03-13 12:06:33 +030023
Girish Gowdra64503432020-01-07 10:59:10 +053024 "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"
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
Girish Gowdra390f12f2021-07-01 15:53:49 -070082 TpInstance map[int]*tech_profile.TechProfileInstance
Girish Gowdra64503432020-01-07 10:59:10 +053083 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
Girish Gowdra390f12f2021-07-01 15:53:49 -070093 subs.TpInstance = make(map[int]*tech_profile.TechProfileInstance)
Girish Gowdra64503432020-01-07 10:59:10 +053094
95 for _, tpID := range subs.TestConfig.TpIDList {
96 uniPortName := fmt.Sprintf(UniPortName, subs.PonIntf, subs.OnuID, subs.UniID)
Girish Gowdra390f12f2021-07-01 15:53:49 -070097 tpInstInterface, err := subs.RsrMgr.TechprofileRef.CreateTechProfileInstance(context.Background(), uint32(tpID), uniPortName, subs.PonIntf)
Girish Gowdra5d7d6442020-09-08 17:03:11 -070098 // 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.
Girish Gowdra390f12f2021-07-01 15:53:49 -070099 subs.TpInstance[tpID] = tpInstInterface.(*tech_profile.TechProfileInstance)
Girish Gowdra5d7d6442020-09-08 17:03:11 -0700100
Girish Gowdraaeceb842020-08-21 12:10:39 -0700101 if err != nil {
Girish Gowdra5d7d6442020-09-08 17:03:11 -0700102 logger.Errorw(nil, "error-creating-tp-instance-for-subs",
Girish Gowdra64503432020-01-07 10:59:10 +0530103 log.Fields{"subsName": subs.SubscriberName, "onuID": subs.OnuID, "tpID": tpID})
104
105 subs.Reason = ReasonCodeToReasonString(TP_INSTANCE_CREATION_FAILED)
Girish Gowdra64503432020-01-07 10:59:10 +0530106 return
107 }
108 }
109
Girish Gowdraaeceb842020-08-21 12:10:39 -0700110 go DeployWorkflow(subs, isGroup)
Girish Gowdra64503432020-01-07 10:59:10 +0530111
Girish Gowdra5d7d6442020-09-08 17:03:11 -0700112 logger.Infow(nil, "workflow-deploy-started-for-subscriber", log.Fields{"subsName": subs.SubscriberName})
Girish Gowdra64503432020-01-07 10:59:10 +0530113}