blob: 3cf65ad2dbc2da4e855f2ff129e3d1f40ece1900 [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"
Orhan Kupusoglu66b00d82020-03-13 12:06:33 +030024 "github.com/opencord/voltha-lib-go/v3/pkg/log"
25 "github.com/opencord/voltha-lib-go/v3/pkg/techprofile"
26 oop "github.com/opencord/voltha-protos/v3/go/openolt"
27 "golang.org/x/net/context"
Girish Gowdra64503432020-01-07 10:59:10 +053028)
29
30func init() {
31 _, _ = log.AddPackage(log.JSON, log.DebugLevel, nil)
32}
33
34const (
35 SUBSCRIBER_PROVISION_SUCCESS = iota
36 TP_INSTANCE_CREATION_FAILED
Thiyagarajan Subramanib83b0432020-01-08 13:43:28 +053037 FLOW_ID_GENERATION_FAILED
Girish Gowdra64503432020-01-07 10:59:10 +053038 FLOW_ADD_FAILED
39 SCHED_CREATION_FAILED
40 QUEUE_CREATION_FAILED
41)
42
43const (
44 UniPortName = "pon-{%d}/onu-{%d}/uni-{%d}"
45)
46
47var Reason = [...]string{
48 "SUBSCRIBER_PROVISION_SUCCESS",
49 "TP_INSTANCE_CREATION_FAILED",
Thiyagarajan Subramanib83b0432020-01-08 13:43:28 +053050 "FLOW_ID_GENERATION_FAILED",
Girish Gowdra64503432020-01-07 10:59:10 +053051 "FLOW_ADD_FAILED",
52 "SCHED_CREATION_FAILED",
53 "QUEUE_CREATION_FAILED",
54}
55
56func ReasonCodeToReasonString(reasonCode int) string {
57 return Reason[reasonCode]
58}
59
60type Subscriber struct {
61 SubscriberName string `json:"subscriberName"`
62 OnuID uint32 `json:"onuID"`
63 UniID uint32 `json:"uniID"`
64 PonIntf uint32 `json:"ponIntf"`
65 UniPortNo uint32 `json:"uniPortNo"`
66 Ctag uint32 `json:"ctag"`
67 Stag uint32 `json:"stag"`
68 GemPortIDs []uint32 `json:"gemPortIds"`
69 AllocIDs []uint32 `json:"allocIds"`
70 FlowIDs []uint32 `json:"flowIds"`
71 Reason string `json:"reason"`
72
73 FailedFlowCnt uint32 `json:"failedFlowCnt"`
74 SuccessFlowCnt uint32 `json:"successFlowCnt"`
75
76 FailedSchedCnt uint32 `json:"failedSchedCnt"`
77 SuccessSchedCnt uint32 `json:"successShedCnt"`
78
79 FailedQueueCnt uint32 `json:"failedQueueCnt"`
80 SuccessQueueCnt uint32 `json:"successQueueCnt"`
81
82 FailedFlows []oop.Flow `json:"failedFlows"`
83 FailedScheds []oop.TrafficScheduler `json:"failedScheds"`
84 FailedQueues []oop.TrafficQueue `json:"failedQueues"`
85
86 TpInstance map[int]*techprofile.TechProfile
87 OpenOltClient oop.OpenoltClient
88 TestConfig *config.OpenOltScaleTesterConfig
89 RsrMgr *OpenOltResourceMgr
Girish Gowdraaeceb842020-08-21 12:10:39 -070090 subWg *sync.WaitGroup
Girish Gowdra64503432020-01-07 10:59:10 +053091}
92
Girish Gowdraaeceb842020-08-21 12:10:39 -070093func (subs *Subscriber) Start(isGroup bool) {
94
Orhan Kupusoglu66b00d82020-03-13 12:06:33 +030095 var err error
Girish Gowdra64503432020-01-07 10:59:10 +053096
97 log.Infow("workflow-deploy-started-for-subscriber", log.Fields{"subsName": subs.SubscriberName})
98
99 subs.TpInstance = make(map[int]*techprofile.TechProfile)
100
101 for _, tpID := range subs.TestConfig.TpIDList {
102 uniPortName := fmt.Sprintf(UniPortName, subs.PonIntf, subs.OnuID, subs.UniID)
Girish Gowdraaeceb842020-08-21 12:10:39 -0700103 subs.RsrMgr.GemIDAllocIDLock[subs.PonIntf].Lock()
104 subs.TpInstance[tpID], err = subs.RsrMgr.ResourceMgrs[subs.PonIntf].TechProfileMgr.CreateTechProfInstance(context.Background(),
105 uint32(tpID), uniPortName, subs.PonIntf)
106 subs.RsrMgr.GemIDAllocIDLock[subs.PonIntf].Unlock()
107 if err != nil {
Girish Gowdra64503432020-01-07 10:59:10 +0530108 log.Errorw("error-creating-tp-instance-for-subs",
109 log.Fields{"subsName": subs.SubscriberName, "onuID": subs.OnuID, "tpID": tpID})
110
111 subs.Reason = ReasonCodeToReasonString(TP_INSTANCE_CREATION_FAILED)
Girish Gowdra64503432020-01-07 10:59:10 +0530112 return
113 }
114 }
115
Girish Gowdraaeceb842020-08-21 12:10:39 -0700116 go DeployWorkflow(subs, isGroup)
Girish Gowdra64503432020-01-07 10:59:10 +0530117
Girish Gowdraaeceb842020-08-21 12:10:39 -0700118 log.Infow("workflow-deploy-started-for-subscriber", log.Fields{"subsName": subs.SubscriberName})
Girish Gowdra64503432020-01-07 10:59:10 +0530119}