blob: 5610d2cd74d9dd207dbceff2674a4a1023a8d767 [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"
21 "github.com/opencord/openolt-scale-tester/config"
22 "github.com/opencord/voltha-lib-go/v2/pkg/log"
23 "github.com/opencord/voltha-lib-go/v2/pkg/techprofile"
24 oop "github.com/opencord/voltha-protos/v2/go/openolt"
25)
26
27func init() {
28 _, _ = log.AddPackage(log.JSON, log.DebugLevel, nil)
29}
30
31const (
32 SUBSCRIBER_PROVISION_SUCCESS = iota
33 TP_INSTANCE_CREATION_FAILED
Thiyagarajan Subramanib83b0432020-01-08 13:43:28 +053034 FLOW_ID_GENERATION_FAILED
Girish Gowdra64503432020-01-07 10:59:10 +053035 FLOW_ADD_FAILED
36 SCHED_CREATION_FAILED
37 QUEUE_CREATION_FAILED
38)
39
40const (
41 UniPortName = "pon-{%d}/onu-{%d}/uni-{%d}"
42)
43
44var Reason = [...]string{
45 "SUBSCRIBER_PROVISION_SUCCESS",
46 "TP_INSTANCE_CREATION_FAILED",
Thiyagarajan Subramanib83b0432020-01-08 13:43:28 +053047 "FLOW_ID_GENERATION_FAILED",
Girish Gowdra64503432020-01-07 10:59:10 +053048 "FLOW_ADD_FAILED",
49 "SCHED_CREATION_FAILED",
50 "QUEUE_CREATION_FAILED",
51}
52
53func ReasonCodeToReasonString(reasonCode int) string {
54 return Reason[reasonCode]
55}
56
57type Subscriber struct {
58 SubscriberName string `json:"subscriberName"`
59 OnuID uint32 `json:"onuID"`
60 UniID uint32 `json:"uniID"`
61 PonIntf uint32 `json:"ponIntf"`
62 UniPortNo uint32 `json:"uniPortNo"`
63 Ctag uint32 `json:"ctag"`
64 Stag uint32 `json:"stag"`
65 GemPortIDs []uint32 `json:"gemPortIds"`
66 AllocIDs []uint32 `json:"allocIds"`
67 FlowIDs []uint32 `json:"flowIds"`
68 Reason string `json:"reason"`
69
70 FailedFlowCnt uint32 `json:"failedFlowCnt"`
71 SuccessFlowCnt uint32 `json:"successFlowCnt"`
72
73 FailedSchedCnt uint32 `json:"failedSchedCnt"`
74 SuccessSchedCnt uint32 `json:"successShedCnt"`
75
76 FailedQueueCnt uint32 `json:"failedQueueCnt"`
77 SuccessQueueCnt uint32 `json:"successQueueCnt"`
78
79 FailedFlows []oop.Flow `json:"failedFlows"`
80 FailedScheds []oop.TrafficScheduler `json:"failedScheds"`
81 FailedQueues []oop.TrafficQueue `json:"failedQueues"`
82
83 TpInstance map[int]*techprofile.TechProfile
84 OpenOltClient oop.OpenoltClient
85 TestConfig *config.OpenOltScaleTesterConfig
86 RsrMgr *OpenOltResourceMgr
87}
88
89func (subs *Subscriber) Start(onuCh chan bool) {
90
91 log.Infow("workflow-deploy-started-for-subscriber", log.Fields{"subsName": subs.SubscriberName})
92
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)
97 if subs.TpInstance[tpID] =
98 subs.RsrMgr.ResourceMgrs[subs.PonIntf].TechProfileMgr.CreateTechProfInstance(
99 uint32(tpID), uniPortName, subs.PonIntf); subs.TpInstance[tpID] == nil {
100 log.Errorw("error-creating-tp-instance-for-subs",
101 log.Fields{"subsName": subs.SubscriberName, "onuID": subs.OnuID, "tpID": tpID})
102
103 subs.Reason = ReasonCodeToReasonString(TP_INSTANCE_CREATION_FAILED)
104 onuCh <- true
105
106 return
107 }
108 }
109
110 DeployWorkflow(subs)
111
112 log.Infow("workflow-deploy-completed-for-subscriber", log.Fields{"subsName": subs.SubscriberName})
113
114 onuCh <- true
115}