blob: e9bb24e0aaff401082d0e1a2ca5565b807e5da18 [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 "errors"
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 oop "github.com/opencord/voltha-protos/v3/go/openolt"
Girish Gowdra64503432020-01-07 10:59:10 +053025)
26
27func init() {
28 _, _ = log.AddPackage(log.JSON, log.DebugLevel, nil)
29}
30
31type WorkFlow interface {
32 ProvisionScheds(subs *Subscriber) error
33 ProvisionQueues(subs *Subscriber) error
34 ProvisionEapFlow(subs *Subscriber) error
Girish Gowdraef1b7c42020-01-23 16:27:48 +053035 ProvisionDhcpIPV4Flow(subs *Subscriber) error
36 ProvisionDhcpIPV6Flow(subs *Subscriber) error
Girish Gowdra64503432020-01-07 10:59:10 +053037 ProvisionIgmpFlow(subs *Subscriber) error
38 ProvisionHsiaFlow(subs *Subscriber) error
Orhan Kupusoglu66b00d82020-03-13 12:06:33 +030039 ProvisionVoipFlow(subs *Subscriber) error
40 ProvisionVodFlow(subs *Subscriber) error
41 ProvisionMgmtFlow(subs *Subscriber) error
42 ProvisionMulticastFlow(subs *Subscriber) error
Girish Gowdra64503432020-01-07 10:59:10 +053043 // TODO: Add new items here as needed.
44}
45
Orhan Kupusoglu66b00d82020-03-13 12:06:33 +030046func DeployWorkflow(subs *Subscriber, isGroup bool) {
Girish Gowdraaeceb842020-08-21 12:10:39 -070047
48 defer subs.subWg.Done()
49
Girish Gowdra64503432020-01-07 10:59:10 +053050 var wf = getWorkFlow(subs)
51
Orhan Kupusoglu66b00d82020-03-13 12:06:33 +030052 if isGroup {
53 if err := wf.ProvisionMulticastFlow(subs); err != nil {
54 subs.Reason = err.Error()
55 return
56 }
57 } else {
58 // TODO: Catch and log errors for below items if needed.
59 if err := wf.ProvisionScheds(subs); err != nil {
60 subs.Reason = err.Error()
61 return
62 }
Girish Gowdra64503432020-01-07 10:59:10 +053063
Orhan Kupusoglu66b00d82020-03-13 12:06:33 +030064 if err := wf.ProvisionQueues(subs); err != nil {
65 subs.Reason = err.Error()
66 return
67 }
Girish Gowdra64503432020-01-07 10:59:10 +053068
Orhan Kupusoglu66b00d82020-03-13 12:06:33 +030069 if err := wf.ProvisionEapFlow(subs); err != nil {
70 subs.Reason = err.Error()
71 return
72 }
Girish Gowdra64503432020-01-07 10:59:10 +053073
Orhan Kupusoglu66b00d82020-03-13 12:06:33 +030074 if err := wf.ProvisionDhcpIPV4Flow(subs); err != nil {
75 subs.Reason = err.Error()
76 return
77 }
Girish Gowdraef1b7c42020-01-23 16:27:48 +053078
Orhan Kupusoglu66b00d82020-03-13 12:06:33 +030079 if err := wf.ProvisionDhcpIPV6Flow(subs); err != nil {
80 subs.Reason = err.Error()
81 return
82 }
Girish Gowdra64503432020-01-07 10:59:10 +053083
Orhan Kupusoglu66b00d82020-03-13 12:06:33 +030084 if err := wf.ProvisionIgmpFlow(subs); err != nil {
85 subs.Reason = err.Error()
86 return
87 }
Girish Gowdra64503432020-01-07 10:59:10 +053088
Orhan Kupusoglu66b00d82020-03-13 12:06:33 +030089 if err := wf.ProvisionHsiaFlow(subs); err != nil {
90 subs.Reason = err.Error()
91 return
92 }
93
94 if err := wf.ProvisionVoipFlow(subs); err != nil {
95 subs.Reason = err.Error()
96 return
97 }
98
99 if err := wf.ProvisionVodFlow(subs); err != nil {
100 subs.Reason = err.Error()
101 return
102 }
103
104 if err := wf.ProvisionMgmtFlow(subs); err != nil {
105 subs.Reason = err.Error()
106 return
107 }
Girish Gowdra64503432020-01-07 10:59:10 +0530108 }
109
Girish Gowdraaeceb842020-08-21 12:10:39 -0700110 log.Infow("subscriber-provision-completed-from-onu-manager", log.Fields{"subsName": subs.SubscriberName})
Girish Gowdra64503432020-01-07 10:59:10 +0530111 subs.Reason = ReasonCodeToReasonString(SUBSCRIBER_PROVISION_SUCCESS)
112}
113
114func getWorkFlow(subs *Subscriber) WorkFlow {
115 switch subs.TestConfig.WorkflowName {
116 case "ATT":
117 log.Info("chosen-att-workflow")
118 return AttWorkFlow{}
Thiyagarajan Subramanib83b0432020-01-08 13:43:28 +0530119 case "DT":
120 log.Info("chosen-dt-workflow")
121 return DtWorkFlow{}
Orhan Kupusoglu66b00d82020-03-13 12:06:33 +0300122 case "TT":
123 log.Info("chosen-tt-workflow")
124 return TtWorkFlow{}
Girish Gowdra64503432020-01-07 10:59:10 +0530125 // TODO: Add new workflow here
126 default:
127 log.Errorw("operator-workflow-not-supported-yet", log.Fields{"workflowName": subs.TestConfig.WorkflowName})
128 }
129 return nil
130}
131
132// This function should get called even before provisioning an ONUs to install trap-from-nni flows.
133// The flows installed here are not related to any subscribers.
134func ProvisionNniTrapFlow(oo oop.OpenoltClient, config *config.OpenOltScaleTesterConfig, rsrMgr *OpenOltResourceMgr) error {
135 switch config.WorkflowName {
136 case "ATT":
137 if err := ProvisionAttNniTrapFlow(oo, config, rsrMgr); err != nil {
138 log.Error("error-installing-flow", log.Fields{"err": err})
139 return err
140 }
Thiyagarajan Subramanic4f8da82020-02-05 16:08:26 +0530141 case "DT":
142 if err := ProvisionDtNniTrapFlow(oo, config, rsrMgr); err != nil {
143 log.Error("error-installing-flow", log.Fields{"err": err})
144 return err
145 }
Orhan Kupusoglu66b00d82020-03-13 12:06:33 +0300146 case "TT":
147 if err := ProvisionTtNniTrapFlow(oo, config, rsrMgr); err != nil {
148 log.Error("error-installing-flow", log.Fields{"err": err})
149 return err
150 }
Girish Gowdra64503432020-01-07 10:59:10 +0530151 // TODO: Add new items here
152 default:
153 log.Errorw("operator-workflow-not-supported-yet", log.Fields{"workflowName": config.WorkflowName})
154 return errors.New("workflow-not-supported")
155 }
156 return nil
157}