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 |
Girish Gowdra | ef1b7c4 | 2020-01-23 16:27:48 +0530 | [diff] [blame^] | 34 | ProvisionDhcpIPV4Flow(subs *Subscriber) error |
| 35 | ProvisionDhcpIPV6Flow(subs *Subscriber) error |
Girish Gowdra | 6450343 | 2020-01-07 10:59:10 +0530 | [diff] [blame] | 36 | ProvisionIgmpFlow(subs *Subscriber) error |
| 37 | ProvisionHsiaFlow(subs *Subscriber) error |
| 38 | // TODO: Add new items here as needed. |
| 39 | } |
| 40 | |
| 41 | func 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 Gowdra | ef1b7c4 | 2020-01-23 16:27:48 +0530 | [diff] [blame^] | 60 | 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 Gowdra | 6450343 | 2020-01-07 10:59:10 +0530 | [diff] [blame] | 66 | 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 | |
| 83 | func getWorkFlow(subs *Subscriber) WorkFlow { |
| 84 | switch subs.TestConfig.WorkflowName { |
| 85 | case "ATT": |
| 86 | log.Info("chosen-att-workflow") |
| 87 | return AttWorkFlow{} |
Thiyagarajan Subramani | b83b043 | 2020-01-08 13:43:28 +0530 | [diff] [blame] | 88 | case "DT": |
| 89 | log.Info("chosen-dt-workflow") |
| 90 | return DtWorkFlow{} |
Girish Gowdra | 6450343 | 2020-01-07 10:59:10 +0530 | [diff] [blame] | 91 | // 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. |
| 100 | func 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 | } |
| 107 | // TODO: Add new items here |
| 108 | default: |
| 109 | log.Errorw("operator-workflow-not-supported-yet", log.Fields{"workflowName": config.WorkflowName}) |
| 110 | return errors.New("workflow-not-supported") |
| 111 | } |
| 112 | return nil |
| 113 | } |