Zdravko Bozakov | 7401ff2 | 2019-05-28 22:45:12 +0200 | [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 flow |
| 18 | |
| 19 | import ( |
| 20 | "gerrit.opencord.org/voltha-bbsim/common/logger" |
| 21 | openolt "gerrit.opencord.org/voltha-bbsim/protos" |
Matteo Scandolo | 67add0c | 2019-08-01 16:41:14 -0700 | [diff] [blame] | 22 | log "github.com/sirupsen/logrus" |
Zdravko Bozakov | 7401ff2 | 2019-05-28 22:45:12 +0200 | [diff] [blame] | 23 | ) |
| 24 | |
| 25 | var flowManager FlowManager |
| 26 | |
| 27 | // FlowManager interface for common methods of controller |
| 28 | type FlowManager interface { |
| 29 | AddFlow(flow *openolt.Flow) error |
| 30 | DeleteFlow(flow *openolt.Flow) error |
| 31 | PortUp(portID uint32) error |
| 32 | PortDown(portID uint32) error |
| 33 | GetFlow(onuID uint32) ([]*openolt.Flow, error) |
| 34 | } |
| 35 | |
| 36 | // DefaultFlowController empty struct |
| 37 | type DefaultFlowController struct { |
| 38 | } |
| 39 | |
| 40 | // InitializeFlowManager starts godc controller |
| 41 | func InitializeFlowManager(OltID uint32) { |
| 42 | // Initialize flow controller as per custom implementation |
| 43 | logger.Debug("InitializeFlowManager for OLT %d", OltID) |
| 44 | flowManager = InitializeDefaultFlowController() |
| 45 | return |
| 46 | } |
| 47 | |
| 48 | // AddFlow abstracts actual implementation of flow addition |
| 49 | func AddFlow(flow *openolt.Flow) error { |
| 50 | return flowManager.AddFlow(flow) |
| 51 | } |
| 52 | |
| 53 | // DeleteFlow abstracts actual implementation of flow deletion |
| 54 | func DeleteFlow(flow *openolt.Flow) error { |
| 55 | return flowManager.DeleteFlow(flow) |
| 56 | } |
| 57 | |
| 58 | // PortUp abstracts actual implementation of port up |
| 59 | func PortUp(portID uint32) error { |
| 60 | return flowManager.PortUp(portID) |
| 61 | } |
| 62 | |
| 63 | // PortDown abstracts actual implementation of port down |
| 64 | func PortDown(portID uint32) error { |
| 65 | return flowManager.PortDown(portID) |
| 66 | } |
| 67 | |
| 68 | // InitializeDefaultFlowController method to initialize default controller |
| 69 | func InitializeDefaultFlowController() FlowManager { |
| 70 | logger.Debug("Default controller initialized") |
| 71 | return new(DefaultFlowController) |
| 72 | } |
| 73 | |
| 74 | // AddFlow method implemented for DefaultFlowController |
| 75 | func (fc *DefaultFlowController) AddFlow(flow *openolt.Flow) error { |
Matteo Scandolo | 67add0c | 2019-08-01 16:41:14 -0700 | [diff] [blame] | 76 | logger.WithFields(log.Fields{ |
| 77 | "flow_eth_type": flow.Classifier.EthType, |
| 78 | "ovid": flow.Classifier.OVid, |
| 79 | "ivid": flow.Classifier.IVid, |
| 80 | "onu_id": flow.OnuId, |
| 81 | "flow_id": flow.FlowId, |
| 82 | "flow_type": flow.FlowType, |
| 83 | }).Debugf("AddFlow invoked for onu %d", flow.OnuId) |
Zdravko Bozakov | 7401ff2 | 2019-05-28 22:45:12 +0200 | [diff] [blame] | 84 | return nil |
| 85 | } |
| 86 | |
| 87 | // DeleteFlow implemented for DefaultFlowController |
| 88 | func (fc *DefaultFlowController) DeleteFlow(flow *openolt.Flow) error { |
| 89 | logger.Debug("DeleteFlow invoked %v", flow) |
| 90 | return nil |
| 91 | } |
| 92 | |
| 93 | // GetFlow implemented for DefaultFlowController |
| 94 | func (fc *DefaultFlowController) GetFlow(onuID uint32) ([]*openolt.Flow, error) { |
| 95 | return nil, nil |
| 96 | } |
| 97 | |
| 98 | // PortUp implemented for DefaultFlowController |
| 99 | func (fc *DefaultFlowController) PortUp(portID uint32) error { |
| 100 | logger.Debug("PortUp invoked %d", portID) |
| 101 | return nil |
| 102 | } |
| 103 | |
| 104 | // PortDown implemented for DefaultFlowController |
| 105 | func (fc *DefaultFlowController) PortDown(portID uint32) error { |
| 106 | logger.Debug("PortDown invoked %d", portID) |
| 107 | return nil |
| 108 | } |