Girish Gowdra | 6450343 | 2020-01-07 10:59:10 +0530 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package core |
| 18 | |
| 19 | import ( |
| 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 | |
| 26 | func init() { |
| 27 | _, _ = log.AddPackage(log.JSON, log.DebugLevel, nil) |
| 28 | } |
| 29 | |
| 30 | type 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 | |
| 40 | func 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 | |
| 77 | func getWorkFlow(subs *Subscriber) WorkFlow { |
| 78 | switch subs.TestConfig.WorkflowName { |
| 79 | case "ATT": |
| 80 | log.Info("chosen-att-workflow") |
| 81 | return AttWorkFlow{} |
Thiyagarajan Subramani | b83b043 | 2020-01-08 13:43:28 +0530 | [diff] [blame] | 82 | case "DT": |
| 83 | log.Info("chosen-dt-workflow") |
| 84 | return DtWorkFlow{} |
Girish Gowdra | 6450343 | 2020-01-07 10:59:10 +0530 | [diff] [blame] | 85 | // TODO: Add new workflow here |
| 86 | default: |
| 87 | log.Errorw("operator-workflow-not-supported-yet", log.Fields{"workflowName": subs.TestConfig.WorkflowName}) |
| 88 | } |
| 89 | return nil |
| 90 | } |
| 91 | |
| 92 | // This function should get called even before provisioning an ONUs to install trap-from-nni flows. |
| 93 | // The flows installed here are not related to any subscribers. |
| 94 | func ProvisionNniTrapFlow(oo oop.OpenoltClient, config *config.OpenOltScaleTesterConfig, rsrMgr *OpenOltResourceMgr) error { |
| 95 | switch config.WorkflowName { |
| 96 | case "ATT": |
| 97 | if err := ProvisionAttNniTrapFlow(oo, config, rsrMgr); err != nil { |
| 98 | log.Error("error-installing-flow", log.Fields{"err": err}) |
| 99 | return err |
| 100 | } |
| 101 | // TODO: Add new items here |
| 102 | default: |
| 103 | log.Errorw("operator-workflow-not-supported-yet", log.Fields{"workflowName": config.WorkflowName}) |
| 104 | return errors.New("workflow-not-supported") |
| 105 | } |
| 106 | return nil |
| 107 | } |