blob: 8d03bb5c3e00715b7bea0321bed75da84b8cc836 [file] [log] [blame]
Zdravko Bozakov7401ff22019-05-28 22:45:12 +02001/*
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
17package flow
18
19import (
20 "gerrit.opencord.org/voltha-bbsim/common/logger"
21 openolt "gerrit.opencord.org/voltha-bbsim/protos"
Matteo Scandolo67add0c2019-08-01 16:41:14 -070022 log "github.com/sirupsen/logrus"
Zdravko Bozakov7401ff22019-05-28 22:45:12 +020023)
24
25var flowManager FlowManager
26
27// FlowManager interface for common methods of controller
28type 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
37type DefaultFlowController struct {
38}
39
40// InitializeFlowManager starts godc controller
41func 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
49func AddFlow(flow *openolt.Flow) error {
50 return flowManager.AddFlow(flow)
51}
52
53// DeleteFlow abstracts actual implementation of flow deletion
54func DeleteFlow(flow *openolt.Flow) error {
55 return flowManager.DeleteFlow(flow)
56}
57
58// PortUp abstracts actual implementation of port up
59func PortUp(portID uint32) error {
60 return flowManager.PortUp(portID)
61}
62
63// PortDown abstracts actual implementation of port down
64func PortDown(portID uint32) error {
65 return flowManager.PortDown(portID)
66}
67
68// InitializeDefaultFlowController method to initialize default controller
69func InitializeDefaultFlowController() FlowManager {
70 logger.Debug("Default controller initialized")
71 return new(DefaultFlowController)
72}
73
74// AddFlow method implemented for DefaultFlowController
75func (fc *DefaultFlowController) AddFlow(flow *openolt.Flow) error {
Matteo Scandolo67add0c2019-08-01 16:41:14 -070076 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 Bozakov7401ff22019-05-28 22:45:12 +020084 return nil
85}
86
87// DeleteFlow implemented for DefaultFlowController
88func (fc *DefaultFlowController) DeleteFlow(flow *openolt.Flow) error {
89 logger.Debug("DeleteFlow invoked %v", flow)
90 return nil
91}
92
93// GetFlow implemented for DefaultFlowController
94func (fc *DefaultFlowController) GetFlow(onuID uint32) ([]*openolt.Flow, error) {
95 return nil, nil
96}
97
98// PortUp implemented for DefaultFlowController
99func (fc *DefaultFlowController) PortUp(portID uint32) error {
100 logger.Debug("PortUp invoked %d", portID)
101 return nil
102}
103
104// PortDown implemented for DefaultFlowController
105func (fc *DefaultFlowController) PortDown(portID uint32) error {
106 logger.Debug("PortDown invoked %d", portID)
107 return nil
108}