blob: 8ab8551dab0daf615deacfdda5f88ccf7630081e [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"
21 "github.com/opencord/openolt-scale-tester/config"
22 "github.com/opencord/voltha-lib-go/v2/pkg/log"
23 oop "github.com/opencord/voltha-protos/v2/go/openolt"
24)
25
26func init() {
27 _, _ = log.AddPackage(log.JSON, log.DebugLevel, nil)
28}
29
30type WorkFlow interface {
31 ProvisionScheds(subs *Subscriber) error
32 ProvisionQueues(subs *Subscriber) error
33 ProvisionEapFlow(subs *Subscriber) error
Girish Gowdraef1b7c42020-01-23 16:27:48 +053034 ProvisionDhcpIPV4Flow(subs *Subscriber) error
35 ProvisionDhcpIPV6Flow(subs *Subscriber) error
Girish Gowdra64503432020-01-07 10:59:10 +053036 ProvisionIgmpFlow(subs *Subscriber) error
37 ProvisionHsiaFlow(subs *Subscriber) error
38 // TODO: Add new items here as needed.
39}
40
41func DeployWorkflow(subs *Subscriber) {
42 var wf = getWorkFlow(subs)
43
44 // TODO: Catch and log errors for below items if needed.
45 if err := wf.ProvisionScheds(subs); err != nil {
46 subs.Reason = err.Error()
47 return
48 }
49
50 if err := wf.ProvisionQueues(subs); err != nil {
51 subs.Reason = err.Error()
52 return
53 }
54
55 if err := wf.ProvisionEapFlow(subs); err != nil {
56 subs.Reason = err.Error()
57 return
58 }
59
Girish Gowdraef1b7c42020-01-23 16:27:48 +053060 if err := wf.ProvisionDhcpIPV4Flow(subs); err != nil {
61 subs.Reason = err.Error()
62 return
63 }
64
65 if err := wf.ProvisionDhcpIPV6Flow(subs); err != nil {
Girish Gowdra64503432020-01-07 10:59:10 +053066 subs.Reason = err.Error()
67 return
68 }
69
70 if err := wf.ProvisionIgmpFlow(subs); err != nil {
71 subs.Reason = err.Error()
72 return
73 }
74
75 if err := wf.ProvisionHsiaFlow(subs); err != nil {
76 subs.Reason = err.Error()
77 return
78 }
79
80 subs.Reason = ReasonCodeToReasonString(SUBSCRIBER_PROVISION_SUCCESS)
81}
82
83func getWorkFlow(subs *Subscriber) WorkFlow {
84 switch subs.TestConfig.WorkflowName {
85 case "ATT":
86 log.Info("chosen-att-workflow")
87 return AttWorkFlow{}
Thiyagarajan Subramanib83b0432020-01-08 13:43:28 +053088 case "DT":
89 log.Info("chosen-dt-workflow")
90 return DtWorkFlow{}
Girish Gowdra64503432020-01-07 10:59:10 +053091 // TODO: Add new workflow here
92 default:
93 log.Errorw("operator-workflow-not-supported-yet", log.Fields{"workflowName": subs.TestConfig.WorkflowName})
94 }
95 return nil
96}
97
98// This function should get called even before provisioning an ONUs to install trap-from-nni flows.
99// The flows installed here are not related to any subscribers.
100func ProvisionNniTrapFlow(oo oop.OpenoltClient, config *config.OpenOltScaleTesterConfig, rsrMgr *OpenOltResourceMgr) error {
101 switch config.WorkflowName {
102 case "ATT":
103 if err := ProvisionAttNniTrapFlow(oo, config, rsrMgr); err != nil {
104 log.Error("error-installing-flow", log.Fields{"err": err})
105 return err
106 }
Thiyagarajan Subramanic4f8da82020-02-05 16:08:26 +0530107 case "DT":
108 if err := ProvisionDtNniTrapFlow(oo, config, rsrMgr); err != nil {
109 log.Error("error-installing-flow", log.Fields{"err": err})
110 return err
111 }
Girish Gowdra64503432020-01-07 10:59:10 +0530112 // TODO: Add new items here
113 default:
114 log.Errorw("operator-workflow-not-supported-yet", log.Fields{"workflowName": config.WorkflowName})
115 return errors.New("workflow-not-supported")
116 }
117 return nil
118}