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 | aeceb84 | 2020-08-21 12:10:39 -0700 | [diff] [blame^] | 47 | |
| 48 | defer subs.subWg.Done() |
| 49 | |
Girish Gowdra | 6450343 | 2020-01-07 10:59:10 +0530 | [diff] [blame] | 50 | var wf = getWorkFlow(subs) |
| 51 | |
Orhan Kupusoglu | 66b00d8 | 2020-03-13 12:06:33 +0300 | [diff] [blame] | 52 | if isGroup { |
| 53 | if err := wf.ProvisionMulticastFlow(subs); err != nil { |
| 54 | subs.Reason = err.Error() |
| 55 | return |
| 56 | } |
| 57 | } else { |
| 58 | // TODO: Catch and log errors for below items if needed. |
| 59 | if err := wf.ProvisionScheds(subs); err != nil { |
| 60 | subs.Reason = err.Error() |
| 61 | return |
| 62 | } |
Girish Gowdra | 6450343 | 2020-01-07 10:59:10 +0530 | [diff] [blame] | 63 | |
Orhan Kupusoglu | 66b00d8 | 2020-03-13 12:06:33 +0300 | [diff] [blame] | 64 | if err := wf.ProvisionQueues(subs); err != nil { |
| 65 | subs.Reason = err.Error() |
| 66 | return |
| 67 | } |
Girish Gowdra | 6450343 | 2020-01-07 10:59:10 +0530 | [diff] [blame] | 68 | |
Orhan Kupusoglu | 66b00d8 | 2020-03-13 12:06:33 +0300 | [diff] [blame] | 69 | if err := wf.ProvisionEapFlow(subs); err != nil { |
| 70 | subs.Reason = err.Error() |
| 71 | return |
| 72 | } |
Girish Gowdra | 6450343 | 2020-01-07 10:59:10 +0530 | [diff] [blame] | 73 | |
Orhan Kupusoglu | 66b00d8 | 2020-03-13 12:06:33 +0300 | [diff] [blame] | 74 | if err := wf.ProvisionDhcpIPV4Flow(subs); err != nil { |
| 75 | subs.Reason = err.Error() |
| 76 | return |
| 77 | } |
Girish Gowdra | ef1b7c4 | 2020-01-23 16:27:48 +0530 | [diff] [blame] | 78 | |
Orhan Kupusoglu | 66b00d8 | 2020-03-13 12:06:33 +0300 | [diff] [blame] | 79 | if err := wf.ProvisionDhcpIPV6Flow(subs); err != nil { |
| 80 | subs.Reason = err.Error() |
| 81 | return |
| 82 | } |
Girish Gowdra | 6450343 | 2020-01-07 10:59:10 +0530 | [diff] [blame] | 83 | |
Orhan Kupusoglu | 66b00d8 | 2020-03-13 12:06:33 +0300 | [diff] [blame] | 84 | if err := wf.ProvisionIgmpFlow(subs); err != nil { |
| 85 | subs.Reason = err.Error() |
| 86 | return |
| 87 | } |
Girish Gowdra | 6450343 | 2020-01-07 10:59:10 +0530 | [diff] [blame] | 88 | |
Orhan Kupusoglu | 66b00d8 | 2020-03-13 12:06:33 +0300 | [diff] [blame] | 89 | if err := wf.ProvisionHsiaFlow(subs); err != nil { |
| 90 | subs.Reason = err.Error() |
| 91 | return |
| 92 | } |
| 93 | |
| 94 | if err := wf.ProvisionVoipFlow(subs); err != nil { |
| 95 | subs.Reason = err.Error() |
| 96 | return |
| 97 | } |
| 98 | |
| 99 | if err := wf.ProvisionVodFlow(subs); err != nil { |
| 100 | subs.Reason = err.Error() |
| 101 | return |
| 102 | } |
| 103 | |
| 104 | if err := wf.ProvisionMgmtFlow(subs); err != nil { |
| 105 | subs.Reason = err.Error() |
| 106 | return |
| 107 | } |
Girish Gowdra | 6450343 | 2020-01-07 10:59:10 +0530 | [diff] [blame] | 108 | } |
| 109 | |
Girish Gowdra | aeceb84 | 2020-08-21 12:10:39 -0700 | [diff] [blame^] | 110 | log.Infow("subscriber-provision-completed-from-onu-manager", log.Fields{"subsName": subs.SubscriberName}) |
Girish Gowdra | 6450343 | 2020-01-07 10:59:10 +0530 | [diff] [blame] | 111 | subs.Reason = ReasonCodeToReasonString(SUBSCRIBER_PROVISION_SUCCESS) |
| 112 | } |
| 113 | |
| 114 | func getWorkFlow(subs *Subscriber) WorkFlow { |
| 115 | switch subs.TestConfig.WorkflowName { |
| 116 | case "ATT": |
| 117 | log.Info("chosen-att-workflow") |
| 118 | return AttWorkFlow{} |
Thiyagarajan Subramani | b83b043 | 2020-01-08 13:43:28 +0530 | [diff] [blame] | 119 | case "DT": |
| 120 | log.Info("chosen-dt-workflow") |
| 121 | return DtWorkFlow{} |
Orhan Kupusoglu | 66b00d8 | 2020-03-13 12:06:33 +0300 | [diff] [blame] | 122 | case "TT": |
| 123 | log.Info("chosen-tt-workflow") |
| 124 | return TtWorkFlow{} |
Girish Gowdra | 6450343 | 2020-01-07 10:59:10 +0530 | [diff] [blame] | 125 | // TODO: Add new workflow here |
| 126 | default: |
| 127 | log.Errorw("operator-workflow-not-supported-yet", log.Fields{"workflowName": subs.TestConfig.WorkflowName}) |
| 128 | } |
| 129 | return nil |
| 130 | } |
| 131 | |
| 132 | // This function should get called even before provisioning an ONUs to install trap-from-nni flows. |
| 133 | // The flows installed here are not related to any subscribers. |
| 134 | func ProvisionNniTrapFlow(oo oop.OpenoltClient, config *config.OpenOltScaleTesterConfig, rsrMgr *OpenOltResourceMgr) error { |
| 135 | switch config.WorkflowName { |
| 136 | case "ATT": |
| 137 | if err := ProvisionAttNniTrapFlow(oo, config, rsrMgr); err != nil { |
| 138 | log.Error("error-installing-flow", log.Fields{"err": err}) |
| 139 | return err |
| 140 | } |
Thiyagarajan Subramani | c4f8da8 | 2020-02-05 16:08:26 +0530 | [diff] [blame] | 141 | case "DT": |
| 142 | if err := ProvisionDtNniTrapFlow(oo, config, rsrMgr); err != nil { |
| 143 | log.Error("error-installing-flow", log.Fields{"err": err}) |
| 144 | return err |
| 145 | } |
Orhan Kupusoglu | 66b00d8 | 2020-03-13 12:06:33 +0300 | [diff] [blame] | 146 | case "TT": |
| 147 | if err := ProvisionTtNniTrapFlow(oo, config, rsrMgr); err != nil { |
| 148 | log.Error("error-installing-flow", log.Fields{"err": err}) |
| 149 | return err |
| 150 | } |
Girish Gowdra | 6450343 | 2020-01-07 10:59:10 +0530 | [diff] [blame] | 151 | // TODO: Add new items here |
| 152 | default: |
| 153 | log.Errorw("operator-workflow-not-supported-yet", log.Fields{"workflowName": config.WorkflowName}) |
| 154 | return errors.New("workflow-not-supported") |
| 155 | } |
| 156 | return nil |
| 157 | } |