blob: 39721455e57ec1de5a87b83b2d40c6b3410445ae [file] [log] [blame]
kdarapub26b4502019-10-05 03:02:33 +05301/*
Joey Armstrong11f5a572024-01-12 19:11:32 -05002 * Copyright 2018-2024 Open Networking Foundation (ONF) and the ONF Contributors
kdarapub26b4502019-10-05 03:02:33 +05303
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
Joey Armstrong3f0e2422023-07-05 18:25:41 -040017// Package mocks provides the mocks for openolt-adapter.
kdarapub26b4502019-10-05 03:02:33 +053018package mocks
19
20import (
npujarec5762e2020-01-01 14:08:48 +053021 "context"
Takahiro Suzuki2ba0e0b2020-06-05 14:23:03 -070022
khenaidoo106c61a2021-08-11 18:05:46 -040023 "github.com/opencord/voltha-lib-go/v7/pkg/db"
24 tp_pb "github.com/opencord/voltha-protos/v5/go/tech_profile"
kdarapub26b4502019-10-05 03:02:33 +053025)
26
27// MockTechProfile mock struct for OpenoltClient.
28type MockTechProfile struct {
29 TpID uint32
30}
31
Girish Gowdra54934262019-11-13 14:19:55 +053032// SetKVClient to mock techprofile SetKVClient method
Matteo Scandolod9d6f512020-11-24 13:57:53 -080033func (m MockTechProfile) SetKVClient(ctx context.Context, pathPrefix string) *db.Backend {
sbarbaria8910ba2019-11-05 10:12:23 -050034 return &db.Backend{Client: &MockKVClient{}}
kdarapub26b4502019-10-05 03:02:33 +053035}
36
Holger Hildebrandt143b5be2023-02-10 08:28:15 +000037// CloseKVClient to mock techprofile CloseKVClient method
38func (m MockTechProfile) CloseKVClient(ctx context.Context) {
39}
40
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -070041// GetTPInstance to mock techprofile GetTPInstance method
42func (m MockTechProfile) GetTPInstance(ctx context.Context, path string) (interface{}, error) {
Girish Gowdra0aca4982021-01-04 12:44:27 -080043 logger.Debug(ctx, "GetTPInstanceFromKVStore")
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -070044 var usGemPortAttributeList []*tp_pb.GemPortAttributes
45 var dsGemPortAttributeList []*tp_pb.GemPortAttributes
46 usGemPortAttributeList = append(usGemPortAttributeList, &tp_pb.GemPortAttributes{
47 GemportId: 1,
48 PbitMap: "0b11111111",
49 })
50 dsGemPortAttributeList = append(dsGemPortAttributeList, &tp_pb.GemPortAttributes{
51 GemportId: 1,
52 PbitMap: "0b11111111",
53 })
54 return &tp_pb.TechProfileInstance{
55 Name: "mock-tech-profile",
56 SubscriberIdentifier: "257",
57 ProfileType: "mock",
58 Version: 0,
59 NumGemPorts: 1,
60 InstanceControl: &tp_pb.InstanceControl{
61 Onu: "multi-instance",
62 Uni: "single-instance",
63 MaxGemPayloadSize: "",
64 },
65 UsScheduler: &tp_pb.SchedulerAttributes{
66 AllocId: 1,
67 Direction: tp_pb.Direction_UPSTREAM,
68 AdditionalBw: tp_pb.AdditionalBW_AdditionalBW_None,
69 Priority: 0,
70 Weight: 0,
71 QSchedPolicy: tp_pb.SchedulingPolicy_WRR,
72 },
73 DsScheduler: &tp_pb.SchedulerAttributes{
74 AllocId: 1,
75 Direction: tp_pb.Direction_DOWNSTREAM,
76 AdditionalBw: tp_pb.AdditionalBW_AdditionalBW_None,
77 Priority: 0,
78 Weight: 0,
79 QSchedPolicy: tp_pb.SchedulingPolicy_WRR,
80 },
81 UpstreamGemPortAttributeList: usGemPortAttributeList,
82 DownstreamGemPortAttributeList: dsGemPortAttributeList,
83 }, nil
kdarapub26b4502019-10-05 03:02:33 +053084}
85
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -070086// CreateTechProfileInstance to mock techprofile CreateTechProfileInstance method
87func (m MockTechProfile) CreateTechProfileInstance(ctx context.Context, techProfiletblID uint32, uniPortName string, intfID uint32) (interface{}, error) {
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -070088 var usGemPortAttributeList []*tp_pb.GemPortAttributes
89 var dsGemPortAttributeList []*tp_pb.GemPortAttributes
Takahiro Suzuki2ba0e0b2020-06-05 14:23:03 -070090 if techProfiletblID == 64 {
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -070091 usGemPortAttributeList = append(usGemPortAttributeList, &tp_pb.GemPortAttributes{
92 GemportId: 1,
93 PbitMap: "0b11111111",
94 })
95 dsGemPortAttributeList = append(dsGemPortAttributeList, &tp_pb.GemPortAttributes{
96 GemportId: 1,
97 PbitMap: "0b11111111",
98 })
99 return &tp_pb.TechProfileInstance{
Girish Gowdrafb3d6102020-10-16 16:32:36 -0700100 Name: "mock-tech-profile",
101 SubscriberIdentifier: "257",
102 ProfileType: "mock",
103 Version: 0,
104 NumGemPorts: 1,
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700105 InstanceControl: &tp_pb.InstanceControl{
106 Onu: "multi-instance",
107 Uni: "single-instance",
108 MaxGemPayloadSize: "",
109 },
110 UsScheduler: &tp_pb.SchedulerAttributes{
111 AllocId: 1,
112 Direction: tp_pb.Direction_UPSTREAM,
113 AdditionalBw: tp_pb.AdditionalBW_AdditionalBW_None,
Girish Gowdrafb3d6102020-10-16 16:32:36 -0700114 Priority: 0,
115 Weight: 0,
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700116 QSchedPolicy: tp_pb.SchedulingPolicy_WRR,
Girish Gowdrafb3d6102020-10-16 16:32:36 -0700117 },
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700118 DsScheduler: &tp_pb.SchedulerAttributes{
119 AllocId: 1,
120 Direction: tp_pb.Direction_DOWNSTREAM,
121 AdditionalBw: tp_pb.AdditionalBW_AdditionalBW_None,
Girish Gowdrafb3d6102020-10-16 16:32:36 -0700122 Priority: 0,
123 Weight: 0,
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700124 QSchedPolicy: tp_pb.SchedulingPolicy_WRR,
Girish Gowdrafb3d6102020-10-16 16:32:36 -0700125 },
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700126 UpstreamGemPortAttributeList: usGemPortAttributeList,
127 DownstreamGemPortAttributeList: dsGemPortAttributeList,
Takahiro Suzuki2ba0e0b2020-06-05 14:23:03 -0700128 }, nil
129 } else if techProfiletblID == 65 {
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700130 return &tp_pb.EponTechProfileInstance{
Takahiro Suzuki2ba0e0b2020-06-05 14:23:03 -0700131 Name: "mock-epon-profile",
132 SubscriberIdentifier: "257",
133 ProfileType: "mock",
134 Version: 0,
135 NumGemPorts: 2,
136 UpstreamQueueAttributeList: nil,
137 DownstreamQueueAttributeList: nil,
138 }, nil
139 } else {
140 return nil, nil
141 }
kdarapub26b4502019-10-05 03:02:33 +0530142}
143
Girish Gowdra54934262019-11-13 14:19:55 +0530144// DeleteTechProfileInstance to mock techprofile DeleteTechProfileInstance method
npujarec5762e2020-01-01 14:08:48 +0530145func (m MockTechProfile) DeleteTechProfileInstance(ctx context.Context, techProfiletblID uint32, uniPortName string) error {
kdarapub26b4502019-10-05 03:02:33 +0530146 return nil
147}
148
Girish Gowdra54934262019-11-13 14:19:55 +0530149// GetprotoBufParamValue to mock techprofile GetprotoBufParamValue method
Neha Sharma96b7bf22020-06-15 10:37:32 +0000150func (m MockTechProfile) GetprotoBufParamValue(ctx context.Context, paramType string, paramKey string) int32 {
kdarapub26b4502019-10-05 03:02:33 +0530151 return 0
kdarapub26b4502019-10-05 03:02:33 +0530152}
153
Girish Gowdra54934262019-11-13 14:19:55 +0530154// GetUsScheduler to mock techprofile GetUsScheduler method
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700155func (m MockTechProfile) GetUsScheduler(tpInstance *tp_pb.TechProfileInstance) *tp_pb.SchedulerConfig {
156 return &tp_pb.SchedulerConfig{}
kdarapub26b4502019-10-05 03:02:33 +0530157}
158
Girish Gowdra54934262019-11-13 14:19:55 +0530159// GetDsScheduler to mock techprofile GetDsScheduler method
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700160func (m MockTechProfile) GetDsScheduler(tpInstance *tp_pb.TechProfileInstance) *tp_pb.SchedulerConfig {
161 return &tp_pb.SchedulerConfig{}
kdarapub26b4502019-10-05 03:02:33 +0530162}
163
Girish Gowdra54934262019-11-13 14:19:55 +0530164// GetTrafficScheduler to mock techprofile GetTrafficScheduler method
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700165func (m MockTechProfile) GetTrafficScheduler(tpInstance *tp_pb.TechProfileInstance, SchedCfg *tp_pb.SchedulerConfig,
kdarapub26b4502019-10-05 03:02:33 +0530166 ShapingCfg *tp_pb.TrafficShapingInfo) *tp_pb.TrafficScheduler {
167 return &tp_pb.TrafficScheduler{}
kdarapub26b4502019-10-05 03:02:33 +0530168}
169
Girish Gowdra54934262019-11-13 14:19:55 +0530170// GetTrafficQueues to mock techprofile GetTrafficQueues method
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700171func (m MockTechProfile) GetTrafficQueues(ctx context.Context, tp *tp_pb.TechProfileInstance, Dir tp_pb.Direction) ([]*tp_pb.TrafficQueue, error) {
Girish Kumar8f73fe02019-12-09 13:19:37 +0000172 return []*tp_pb.TrafficQueue{{}}, nil
kdarapub26b4502019-10-05 03:02:33 +0530173}
174
Scott Bakeree7c0a02020-01-07 11:12:26 -0800175// GetMulticastTrafficQueues to mock techprofile GetMulticastTrafficQueues method
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700176func (m MockTechProfile) GetMulticastTrafficQueues(ctx context.Context, tp *tp_pb.TechProfileInstance) []*tp_pb.TrafficQueue {
Scott Bakeree7c0a02020-01-07 11:12:26 -0800177 return []*tp_pb.TrafficQueue{{}}
178}
179
Gamze Abaka7650be62021-02-26 10:50:36 +0000180// GetGemportForPbit to mock techprofile GetGemportForPbit method
181func (m MockTechProfile) GetGemportForPbit(ctx context.Context, tpInst interface{}, Dir tp_pb.Direction, pbit uint32) interface{} {
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700182 return &tp_pb.GemPortAttributes{
183 GemportId: 1,
Gamze Abaka7650be62021-02-26 10:50:36 +0000184 PbitMap: "0b11111111",
185 AesEncryption: "false",
186 }
kdarapub26b4502019-10-05 03:02:33 +0530187}
Girish Gowdra54934262019-11-13 14:19:55 +0530188
189// FindAllTpInstances to mock techprofile FindAllTpInstances method
Gamze Abakacb0e6772021-06-10 08:32:12 +0000190func (m MockTechProfile) FindAllTpInstances(ctx context.Context, oltDeviceID string, tpID uint32, ponIntf uint32, onuID uint32) interface{} {
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700191 return []tp_pb.TechProfileInstance{}
Girish Gowdra54934262019-11-13 14:19:55 +0530192}
Matteo Scandolo84585372021-03-18 14:21:22 -0700193
194// GetResourceID to mock techprofile GetResourceID method
195func (m MockTechProfile) GetResourceID(ctx context.Context, IntfID uint32, ResourceType string, NumIDs uint32) ([]uint32, error) {
196 return []uint32{}, nil
197}
198
199// FreeResourceID to mock techprofile FreeResourceID method
200func (m MockTechProfile) FreeResourceID(ctx context.Context, IntfID uint32, ResourceType string, ReleaseContent []uint32) error {
201 return nil
202}
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700203
204// GetTechProfileInstanceKey to mock techprofile GetTechProfileInstanceKey method
205func (m MockTechProfile) GetTechProfileInstanceKey(ctx context.Context, tpID uint32, uniPortName string) string {
206 return ""
207}