blob: b8674ac555e92ef5ae1a00ba171e4aeddd9e61f8 [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
34 ProvisionDhcpFlow(subs *Subscriber) error
35 ProvisionIgmpFlow(subs *Subscriber) error
36 ProvisionHsiaFlow(subs *Subscriber) error
37 // TODO: Add new items here as needed.
38}
39
40func DeployWorkflow(subs *Subscriber) {
41 var wf = getWorkFlow(subs)
42
43 // TODO: Catch and log errors for below items if needed.
44 if err := wf.ProvisionScheds(subs); err != nil {
45 subs.Reason = err.Error()
46 return
47 }
48
49 if err := wf.ProvisionQueues(subs); err != nil {
50 subs.Reason = err.Error()
51 return
52 }
53
54 if err := wf.ProvisionEapFlow(subs); err != nil {
55 subs.Reason = err.Error()
56 return
57 }
58
59 if err := wf.ProvisionDhcpFlow(subs); err != nil {
60 subs.Reason = err.Error()
61 return
62 }
63
64 if err := wf.ProvisionIgmpFlow(subs); err != nil {
65 subs.Reason = err.Error()
66 return
67 }
68
69 if err := wf.ProvisionHsiaFlow(subs); err != nil {
70 subs.Reason = err.Error()
71 return
72 }
73
74 subs.Reason = ReasonCodeToReasonString(SUBSCRIBER_PROVISION_SUCCESS)
75}
76
77func getWorkFlow(subs *Subscriber) WorkFlow {
78 switch subs.TestConfig.WorkflowName {
79 case "ATT":
80 log.Info("chosen-att-workflow")
81 return AttWorkFlow{}
82 // TODO: Add new workflow here
83 default:
84 log.Errorw("operator-workflow-not-supported-yet", log.Fields{"workflowName": subs.TestConfig.WorkflowName})
85 }
86 return nil
87}
88
89// This function should get called even before provisioning an ONUs to install trap-from-nni flows.
90// The flows installed here are not related to any subscribers.
91func ProvisionNniTrapFlow(oo oop.OpenoltClient, config *config.OpenOltScaleTesterConfig, rsrMgr *OpenOltResourceMgr) error {
92 switch config.WorkflowName {
93 case "ATT":
94 if err := ProvisionAttNniTrapFlow(oo, config, rsrMgr); err != nil {
95 log.Error("error-installing-flow", log.Fields{"err": err})
96 return err
97 }
98 // TODO: Add new items here
99 default:
100 log.Errorw("operator-workflow-not-supported-yet", log.Fields{"workflowName": config.WorkflowName})
101 return errors.New("workflow-not-supported")
102 }
103 return nil
104}