blob: 1112a7e5eaec6adddc94a7ccfd801ff40cd4eea5 [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 Gowdra64503432020-01-07 10:59:10 +053047 var wf = getWorkFlow(subs)
48
Orhan Kupusoglu66b00d82020-03-13 12:06:33 +030049 if isGroup {
50 if err := wf.ProvisionMulticastFlow(subs); err != nil {
51 subs.Reason = err.Error()
52 return
53 }
54 } else {
55 // TODO: Catch and log errors for below items if needed.
56 if err := wf.ProvisionScheds(subs); err != nil {
57 subs.Reason = err.Error()
58 return
59 }
Girish Gowdra64503432020-01-07 10:59:10 +053060
Orhan Kupusoglu66b00d82020-03-13 12:06:33 +030061 if err := wf.ProvisionQueues(subs); err != nil {
62 subs.Reason = err.Error()
63 return
64 }
Girish Gowdra64503432020-01-07 10:59:10 +053065
Orhan Kupusoglu66b00d82020-03-13 12:06:33 +030066 if err := wf.ProvisionEapFlow(subs); err != nil {
67 subs.Reason = err.Error()
68 return
69 }
Girish Gowdra64503432020-01-07 10:59:10 +053070
Orhan Kupusoglu66b00d82020-03-13 12:06:33 +030071 if err := wf.ProvisionDhcpIPV4Flow(subs); err != nil {
72 subs.Reason = err.Error()
73 return
74 }
Girish Gowdraef1b7c42020-01-23 16:27:48 +053075
Orhan Kupusoglu66b00d82020-03-13 12:06:33 +030076 if err := wf.ProvisionDhcpIPV6Flow(subs); err != nil {
77 subs.Reason = err.Error()
78 return
79 }
Girish Gowdra64503432020-01-07 10:59:10 +053080
Orhan Kupusoglu66b00d82020-03-13 12:06:33 +030081 if err := wf.ProvisionIgmpFlow(subs); err != nil {
82 subs.Reason = err.Error()
83 return
84 }
Girish Gowdra64503432020-01-07 10:59:10 +053085
Orhan Kupusoglu66b00d82020-03-13 12:06:33 +030086 if err := wf.ProvisionHsiaFlow(subs); err != nil {
87 subs.Reason = err.Error()
88 return
89 }
90
91 if err := wf.ProvisionVoipFlow(subs); err != nil {
92 subs.Reason = err.Error()
93 return
94 }
95
96 if err := wf.ProvisionVodFlow(subs); err != nil {
97 subs.Reason = err.Error()
98 return
99 }
100
101 if err := wf.ProvisionMgmtFlow(subs); err != nil {
102 subs.Reason = err.Error()
103 return
104 }
Girish Gowdra64503432020-01-07 10:59:10 +0530105 }
106
107 subs.Reason = ReasonCodeToReasonString(SUBSCRIBER_PROVISION_SUCCESS)
108}
109
110func getWorkFlow(subs *Subscriber) WorkFlow {
111 switch subs.TestConfig.WorkflowName {
112 case "ATT":
113 log.Info("chosen-att-workflow")
114 return AttWorkFlow{}
Thiyagarajan Subramanib83b0432020-01-08 13:43:28 +0530115 case "DT":
116 log.Info("chosen-dt-workflow")
117 return DtWorkFlow{}
Orhan Kupusoglu66b00d82020-03-13 12:06:33 +0300118 case "TT":
119 log.Info("chosen-tt-workflow")
120 return TtWorkFlow{}
Girish Gowdra64503432020-01-07 10:59:10 +0530121 // TODO: Add new workflow here
122 default:
123 log.Errorw("operator-workflow-not-supported-yet", log.Fields{"workflowName": subs.TestConfig.WorkflowName})
124 }
125 return nil
126}
127
128// This function should get called even before provisioning an ONUs to install trap-from-nni flows.
129// The flows installed here are not related to any subscribers.
130func ProvisionNniTrapFlow(oo oop.OpenoltClient, config *config.OpenOltScaleTesterConfig, rsrMgr *OpenOltResourceMgr) error {
131 switch config.WorkflowName {
132 case "ATT":
133 if err := ProvisionAttNniTrapFlow(oo, config, rsrMgr); err != nil {
134 log.Error("error-installing-flow", log.Fields{"err": err})
135 return err
136 }
Thiyagarajan Subramanic4f8da82020-02-05 16:08:26 +0530137 case "DT":
138 if err := ProvisionDtNniTrapFlow(oo, config, rsrMgr); err != nil {
139 log.Error("error-installing-flow", log.Fields{"err": err})
140 return err
141 }
Orhan Kupusoglu66b00d82020-03-13 12:06:33 +0300142 case "TT":
143 if err := ProvisionTtNniTrapFlow(oo, config, rsrMgr); err != nil {
144 log.Error("error-installing-flow", log.Fields{"err": err})
145 return err
146 }
Girish Gowdra64503432020-01-07 10:59:10 +0530147 // TODO: Add new items here
148 default:
149 log.Errorw("operator-workflow-not-supported-yet", log.Fields{"workflowName": config.WorkflowName})
150 return errors.New("workflow-not-supported")
151 }
152 return nil
153}