blob: d84fad9fa2f8fb53cb7246e8776392262c0dfa29 [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"
Orhan Kupusoglu66b00d82020-03-13 12:06:33 +030021
Girish Gowdra64503432020-01-07 10:59:10 +053022 "github.com/opencord/openolt-scale-tester/config"
Orhan Kupusoglu66b00d82020-03-13 12:06:33 +030023 "github.com/opencord/voltha-lib-go/v3/pkg/log"
24 "github.com/opencord/voltha-lib-go/v3/pkg/techprofile"
25 oop "github.com/opencord/voltha-protos/v3/go/openolt"
26 "golang.org/x/net/context"
Girish Gowdra64503432020-01-07 10:59:10 +053027)
28
29func init() {
30 _, _ = log.AddPackage(log.JSON, log.DebugLevel, nil)
31}
32
33const (
34 SUBSCRIBER_PROVISION_SUCCESS = iota
35 TP_INSTANCE_CREATION_FAILED
Thiyagarajan Subramanib83b0432020-01-08 13:43:28 +053036 FLOW_ID_GENERATION_FAILED
Girish Gowdra64503432020-01-07 10:59:10 +053037 FLOW_ADD_FAILED
38 SCHED_CREATION_FAILED
39 QUEUE_CREATION_FAILED
40)
41
42const (
43 UniPortName = "pon-{%d}/onu-{%d}/uni-{%d}"
44)
45
46var Reason = [...]string{
47 "SUBSCRIBER_PROVISION_SUCCESS",
48 "TP_INSTANCE_CREATION_FAILED",
Thiyagarajan Subramanib83b0432020-01-08 13:43:28 +053049 "FLOW_ID_GENERATION_FAILED",
Girish Gowdra64503432020-01-07 10:59:10 +053050 "FLOW_ADD_FAILED",
51 "SCHED_CREATION_FAILED",
52 "QUEUE_CREATION_FAILED",
53}
54
55func ReasonCodeToReasonString(reasonCode int) string {
56 return Reason[reasonCode]
57}
58
59type Subscriber struct {
60 SubscriberName string `json:"subscriberName"`
61 OnuID uint32 `json:"onuID"`
62 UniID uint32 `json:"uniID"`
63 PonIntf uint32 `json:"ponIntf"`
64 UniPortNo uint32 `json:"uniPortNo"`
65 Ctag uint32 `json:"ctag"`
66 Stag uint32 `json:"stag"`
67 GemPortIDs []uint32 `json:"gemPortIds"`
68 AllocIDs []uint32 `json:"allocIds"`
69 FlowIDs []uint32 `json:"flowIds"`
70 Reason string `json:"reason"`
71
72 FailedFlowCnt uint32 `json:"failedFlowCnt"`
73 SuccessFlowCnt uint32 `json:"successFlowCnt"`
74
75 FailedSchedCnt uint32 `json:"failedSchedCnt"`
76 SuccessSchedCnt uint32 `json:"successShedCnt"`
77
78 FailedQueueCnt uint32 `json:"failedQueueCnt"`
79 SuccessQueueCnt uint32 `json:"successQueueCnt"`
80
81 FailedFlows []oop.Flow `json:"failedFlows"`
82 FailedScheds []oop.TrafficScheduler `json:"failedScheds"`
83 FailedQueues []oop.TrafficQueue `json:"failedQueues"`
84
85 TpInstance map[int]*techprofile.TechProfile
86 OpenOltClient oop.OpenoltClient
87 TestConfig *config.OpenOltScaleTesterConfig
88 RsrMgr *OpenOltResourceMgr
89}
90
Orhan Kupusoglu66b00d82020-03-13 12:06:33 +030091func (subs *Subscriber) Start(onuCh chan bool, isGroup bool) {
92 var err error
Girish Gowdra64503432020-01-07 10:59:10 +053093
94 log.Infow("workflow-deploy-started-for-subscriber", log.Fields{"subsName": subs.SubscriberName})
95
96 subs.TpInstance = make(map[int]*techprofile.TechProfile)
97
98 for _, tpID := range subs.TestConfig.TpIDList {
99 uniPortName := fmt.Sprintf(UniPortName, subs.PonIntf, subs.OnuID, subs.UniID)
Orhan Kupusoglu66b00d82020-03-13 12:06:33 +0300100 if subs.TpInstance[tpID], err =
101 subs.RsrMgr.ResourceMgrs[subs.PonIntf].TechProfileMgr.CreateTechProfInstance(context.Background(),
102 uint32(tpID), uniPortName, subs.PonIntf); err != nil {
Girish Gowdra64503432020-01-07 10:59:10 +0530103 log.Errorw("error-creating-tp-instance-for-subs",
104 log.Fields{"subsName": subs.SubscriberName, "onuID": subs.OnuID, "tpID": tpID})
105
106 subs.Reason = ReasonCodeToReasonString(TP_INSTANCE_CREATION_FAILED)
107 onuCh <- true
108
109 return
110 }
111 }
112
Orhan Kupusoglu66b00d82020-03-13 12:06:33 +0300113 DeployWorkflow(subs, isGroup)
Girish Gowdra64503432020-01-07 10:59:10 +0530114
115 log.Infow("workflow-deploy-completed-for-subscriber", log.Fields{"subsName": subs.SubscriberName})
116
117 onuCh <- true
118}