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" |
Orhan Kupusoglu | 66b00d8 | 2020-03-13 12:06:33 +0300 | [diff] [blame] | 21 | |
Girish Gowdra | 6450343 | 2020-01-07 10:59:10 +0530 | [diff] [blame] | 22 | "github.com/opencord/openolt-scale-tester/config" |
Orhan Kupusoglu | 66b00d8 | 2020-03-13 12:06:33 +0300 | [diff] [blame] | 23 | "github.com/opencord/voltha-lib-go/v3/pkg/log" |
| 24 | oop "github.com/opencord/voltha-protos/v3/go/openolt" |
Girish Gowdra | 6450343 | 2020-01-07 10:59:10 +0530 | [diff] [blame] | 25 | ) |
| 26 | |
| 27 | func init() { |
| 28 | _, _ = log.AddPackage(log.JSON, log.DebugLevel, nil) |
| 29 | } |
| 30 | |
| 31 | type WorkFlow interface { |
| 32 | ProvisionScheds(subs *Subscriber) error |
| 33 | ProvisionQueues(subs *Subscriber) error |
| 34 | ProvisionEapFlow(subs *Subscriber) error |
Girish Gowdra | ef1b7c4 | 2020-01-23 16:27:48 +0530 | [diff] [blame] | 35 | ProvisionDhcpIPV4Flow(subs *Subscriber) error |
| 36 | ProvisionDhcpIPV6Flow(subs *Subscriber) error |
Girish Gowdra | 6450343 | 2020-01-07 10:59:10 +0530 | [diff] [blame] | 37 | ProvisionIgmpFlow(subs *Subscriber) error |
| 38 | ProvisionHsiaFlow(subs *Subscriber) error |
Orhan Kupusoglu | 66b00d8 | 2020-03-13 12:06:33 +0300 | [diff] [blame] | 39 | ProvisionVoipFlow(subs *Subscriber) error |
| 40 | ProvisionVodFlow(subs *Subscriber) error |
| 41 | ProvisionMgmtFlow(subs *Subscriber) error |
| 42 | ProvisionMulticastFlow(subs *Subscriber) error |
Girish Gowdra | 6450343 | 2020-01-07 10:59:10 +0530 | [diff] [blame] | 43 | // TODO: Add new items here as needed. |
| 44 | } |
| 45 | |
Orhan Kupusoglu | 66b00d8 | 2020-03-13 12:06:33 +0300 | [diff] [blame] | 46 | func DeployWorkflow(subs *Subscriber, isGroup bool) { |
Girish Gowdra | 6450343 | 2020-01-07 10:59:10 +0530 | [diff] [blame] | 47 | var wf = getWorkFlow(subs) |
| 48 | |
Orhan Kupusoglu | 66b00d8 | 2020-03-13 12:06:33 +0300 | [diff] [blame] | 49 | 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 Gowdra | 6450343 | 2020-01-07 10:59:10 +0530 | [diff] [blame] | 60 | |
Orhan Kupusoglu | 66b00d8 | 2020-03-13 12:06:33 +0300 | [diff] [blame] | 61 | if err := wf.ProvisionQueues(subs); err != nil { |
| 62 | subs.Reason = err.Error() |
| 63 | return |
| 64 | } |
Girish Gowdra | 6450343 | 2020-01-07 10:59:10 +0530 | [diff] [blame] | 65 | |
Orhan Kupusoglu | 66b00d8 | 2020-03-13 12:06:33 +0300 | [diff] [blame] | 66 | if err := wf.ProvisionEapFlow(subs); err != nil { |
| 67 | subs.Reason = err.Error() |
| 68 | return |
| 69 | } |
Girish Gowdra | 6450343 | 2020-01-07 10:59:10 +0530 | [diff] [blame] | 70 | |
Orhan Kupusoglu | 66b00d8 | 2020-03-13 12:06:33 +0300 | [diff] [blame] | 71 | if err := wf.ProvisionDhcpIPV4Flow(subs); err != nil { |
| 72 | subs.Reason = err.Error() |
| 73 | return |
| 74 | } |
Girish Gowdra | ef1b7c4 | 2020-01-23 16:27:48 +0530 | [diff] [blame] | 75 | |
Orhan Kupusoglu | 66b00d8 | 2020-03-13 12:06:33 +0300 | [diff] [blame] | 76 | if err := wf.ProvisionDhcpIPV6Flow(subs); err != nil { |
| 77 | subs.Reason = err.Error() |
| 78 | return |
| 79 | } |
Girish Gowdra | 6450343 | 2020-01-07 10:59:10 +0530 | [diff] [blame] | 80 | |
Orhan Kupusoglu | 66b00d8 | 2020-03-13 12:06:33 +0300 | [diff] [blame] | 81 | if err := wf.ProvisionIgmpFlow(subs); err != nil { |
| 82 | subs.Reason = err.Error() |
| 83 | return |
| 84 | } |
Girish Gowdra | 6450343 | 2020-01-07 10:59:10 +0530 | [diff] [blame] | 85 | |
Orhan Kupusoglu | 66b00d8 | 2020-03-13 12:06:33 +0300 | [diff] [blame] | 86 | 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 Gowdra | 6450343 | 2020-01-07 10:59:10 +0530 | [diff] [blame] | 105 | } |
| 106 | |
| 107 | subs.Reason = ReasonCodeToReasonString(SUBSCRIBER_PROVISION_SUCCESS) |
| 108 | } |
| 109 | |
| 110 | func getWorkFlow(subs *Subscriber) WorkFlow { |
| 111 | switch subs.TestConfig.WorkflowName { |
| 112 | case "ATT": |
| 113 | log.Info("chosen-att-workflow") |
| 114 | return AttWorkFlow{} |
Thiyagarajan Subramani | b83b043 | 2020-01-08 13:43:28 +0530 | [diff] [blame] | 115 | case "DT": |
| 116 | log.Info("chosen-dt-workflow") |
| 117 | return DtWorkFlow{} |
Orhan Kupusoglu | 66b00d8 | 2020-03-13 12:06:33 +0300 | [diff] [blame] | 118 | case "TT": |
| 119 | log.Info("chosen-tt-workflow") |
| 120 | return TtWorkFlow{} |
Girish Gowdra | 6450343 | 2020-01-07 10:59:10 +0530 | [diff] [blame] | 121 | // 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. |
| 130 | func 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 Subramani | c4f8da8 | 2020-02-05 16:08:26 +0530 | [diff] [blame] | 137 | 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 Kupusoglu | 66b00d8 | 2020-03-13 12:06:33 +0300 | [diff] [blame] | 142 | 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 Gowdra | 6450343 | 2020-01-07 10:59:10 +0530 | [diff] [blame] | 147 | // 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 | } |