blob: e06d0169b6b2f34ea73b7f51a3354950b63b263b [file] [log] [blame]
kdarapub26b4502019-10-05 03:02:33 +05301/*
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 mocks provides the mocks for openolt-adapter.
18package mocks
19
20import (
npujarec5762e2020-01-01 14:08:48 +053021 "context"
Takahiro Suzuki2ba0e0b2020-06-05 14:23:03 -070022
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -070023 "github.com/opencord/voltha-lib-go/v5/pkg/db"
Girish Gowdraa09aeab2020-09-14 16:30:52 -070024 tp_pb "github.com/opencord/voltha-protos/v4/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
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -070037// GetTPInstance to mock techprofile GetTPInstance method
38func (m MockTechProfile) GetTPInstance(ctx context.Context, path string) (interface{}, error) {
Girish Gowdra0aca4982021-01-04 12:44:27 -080039 logger.Debug(ctx, "GetTPInstanceFromKVStore")
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -070040 var usGemPortAttributeList []*tp_pb.GemPortAttributes
41 var dsGemPortAttributeList []*tp_pb.GemPortAttributes
42 usGemPortAttributeList = append(usGemPortAttributeList, &tp_pb.GemPortAttributes{
43 GemportId: 1,
44 PbitMap: "0b11111111",
45 })
46 dsGemPortAttributeList = append(dsGemPortAttributeList, &tp_pb.GemPortAttributes{
47 GemportId: 1,
48 PbitMap: "0b11111111",
49 })
50 return &tp_pb.TechProfileInstance{
51 Name: "mock-tech-profile",
52 SubscriberIdentifier: "257",
53 ProfileType: "mock",
54 Version: 0,
55 NumGemPorts: 1,
56 InstanceControl: &tp_pb.InstanceControl{
57 Onu: "multi-instance",
58 Uni: "single-instance",
59 MaxGemPayloadSize: "",
60 },
61 UsScheduler: &tp_pb.SchedulerAttributes{
62 AllocId: 1,
63 Direction: tp_pb.Direction_UPSTREAM,
64 AdditionalBw: tp_pb.AdditionalBW_AdditionalBW_None,
65 Priority: 0,
66 Weight: 0,
67 QSchedPolicy: tp_pb.SchedulingPolicy_WRR,
68 },
69 DsScheduler: &tp_pb.SchedulerAttributes{
70 AllocId: 1,
71 Direction: tp_pb.Direction_DOWNSTREAM,
72 AdditionalBw: tp_pb.AdditionalBW_AdditionalBW_None,
73 Priority: 0,
74 Weight: 0,
75 QSchedPolicy: tp_pb.SchedulingPolicy_WRR,
76 },
77 UpstreamGemPortAttributeList: usGemPortAttributeList,
78 DownstreamGemPortAttributeList: dsGemPortAttributeList,
79 }, nil
80
kdarapub26b4502019-10-05 03:02:33 +053081}
82
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -070083// CreateTechProfileInstance to mock techprofile CreateTechProfileInstance method
84func (m MockTechProfile) CreateTechProfileInstance(ctx context.Context, techProfiletblID uint32, uniPortName string, intfID uint32) (interface{}, error) {
kdarapub26b4502019-10-05 03:02:33 +053085
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -070086 var usGemPortAttributeList []*tp_pb.GemPortAttributes
87 var dsGemPortAttributeList []*tp_pb.GemPortAttributes
Takahiro Suzuki2ba0e0b2020-06-05 14:23:03 -070088 if techProfiletblID == 64 {
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -070089 usGemPortAttributeList = append(usGemPortAttributeList, &tp_pb.GemPortAttributes{
90 GemportId: 1,
91 PbitMap: "0b11111111",
92 })
93 dsGemPortAttributeList = append(dsGemPortAttributeList, &tp_pb.GemPortAttributes{
94 GemportId: 1,
95 PbitMap: "0b11111111",
96 })
97 return &tp_pb.TechProfileInstance{
Girish Gowdrafb3d6102020-10-16 16:32:36 -070098 Name: "mock-tech-profile",
99 SubscriberIdentifier: "257",
100 ProfileType: "mock",
101 Version: 0,
102 NumGemPorts: 1,
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700103 InstanceControl: &tp_pb.InstanceControl{
104 Onu: "multi-instance",
105 Uni: "single-instance",
106 MaxGemPayloadSize: "",
107 },
108 UsScheduler: &tp_pb.SchedulerAttributes{
109 AllocId: 1,
110 Direction: tp_pb.Direction_UPSTREAM,
111 AdditionalBw: tp_pb.AdditionalBW_AdditionalBW_None,
Girish Gowdrafb3d6102020-10-16 16:32:36 -0700112 Priority: 0,
113 Weight: 0,
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700114 QSchedPolicy: tp_pb.SchedulingPolicy_WRR,
Girish Gowdrafb3d6102020-10-16 16:32:36 -0700115 },
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700116 DsScheduler: &tp_pb.SchedulerAttributes{
117 AllocId: 1,
118 Direction: tp_pb.Direction_DOWNSTREAM,
119 AdditionalBw: tp_pb.AdditionalBW_AdditionalBW_None,
Girish Gowdrafb3d6102020-10-16 16:32:36 -0700120 Priority: 0,
121 Weight: 0,
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700122 QSchedPolicy: tp_pb.SchedulingPolicy_WRR,
Girish Gowdrafb3d6102020-10-16 16:32:36 -0700123 },
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700124 UpstreamGemPortAttributeList: usGemPortAttributeList,
125 DownstreamGemPortAttributeList: dsGemPortAttributeList,
Takahiro Suzuki2ba0e0b2020-06-05 14:23:03 -0700126 }, nil
127 } else if techProfiletblID == 65 {
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700128 return &tp_pb.EponTechProfileInstance{
Takahiro Suzuki2ba0e0b2020-06-05 14:23:03 -0700129 Name: "mock-epon-profile",
130 SubscriberIdentifier: "257",
131 ProfileType: "mock",
132 Version: 0,
133 NumGemPorts: 2,
134 UpstreamQueueAttributeList: nil,
135 DownstreamQueueAttributeList: nil,
136 }, nil
137 } else {
138 return nil, nil
139 }
kdarapub26b4502019-10-05 03:02:33 +0530140}
141
Girish Gowdra54934262019-11-13 14:19:55 +0530142// DeleteTechProfileInstance to mock techprofile DeleteTechProfileInstance method
npujarec5762e2020-01-01 14:08:48 +0530143func (m MockTechProfile) DeleteTechProfileInstance(ctx context.Context, techProfiletblID uint32, uniPortName string) error {
kdarapub26b4502019-10-05 03:02:33 +0530144 return nil
145}
146
Girish Gowdra54934262019-11-13 14:19:55 +0530147// GetprotoBufParamValue to mock techprofile GetprotoBufParamValue method
Neha Sharma96b7bf22020-06-15 10:37:32 +0000148func (m MockTechProfile) GetprotoBufParamValue(ctx context.Context, paramType string, paramKey string) int32 {
kdarapub26b4502019-10-05 03:02:33 +0530149 return 0
150
151}
152
Girish Gowdra54934262019-11-13 14:19:55 +0530153// GetUsScheduler to mock techprofile GetUsScheduler method
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700154func (m MockTechProfile) GetUsScheduler(tpInstance *tp_pb.TechProfileInstance) *tp_pb.SchedulerConfig {
155 return &tp_pb.SchedulerConfig{}
kdarapub26b4502019-10-05 03:02:33 +0530156
157}
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{}
168
169}
170
Girish Gowdra54934262019-11-13 14:19:55 +0530171// GetTrafficQueues to mock techprofile GetTrafficQueues method
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700172func (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 +0000173 return []*tp_pb.TrafficQueue{{}}, nil
kdarapub26b4502019-10-05 03:02:33 +0530174}
175
Scott Bakeree7c0a02020-01-07 11:12:26 -0800176// GetMulticastTrafficQueues to mock techprofile GetMulticastTrafficQueues method
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700177func (m MockTechProfile) GetMulticastTrafficQueues(ctx context.Context, tp *tp_pb.TechProfileInstance) []*tp_pb.TrafficQueue {
Scott Bakeree7c0a02020-01-07 11:12:26 -0800178 return []*tp_pb.TrafficQueue{{}}
179}
180
Gamze Abaka7650be62021-02-26 10:50:36 +0000181// GetGemportForPbit to mock techprofile GetGemportForPbit method
182func (m MockTechProfile) GetGemportForPbit(ctx context.Context, tpInst interface{}, Dir tp_pb.Direction, pbit uint32) interface{} {
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700183 return &tp_pb.GemPortAttributes{
184 GemportId: 1,
Gamze Abaka7650be62021-02-26 10:50:36 +0000185 PbitMap: "0b11111111",
186 AesEncryption: "false",
187 }
kdarapub26b4502019-10-05 03:02:33 +0530188}
Girish Gowdra54934262019-11-13 14:19:55 +0530189
190// FindAllTpInstances to mock techprofile FindAllTpInstances method
Gamze Abakacb0e6772021-06-10 08:32:12 +0000191func (m MockTechProfile) FindAllTpInstances(ctx context.Context, oltDeviceID string, tpID uint32, ponIntf uint32, onuID uint32) interface{} {
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700192 return []tp_pb.TechProfileInstance{}
Girish Gowdra54934262019-11-13 14:19:55 +0530193}
Matteo Scandolo84585372021-03-18 14:21:22 -0700194
195// GetResourceID to mock techprofile GetResourceID method
196func (m MockTechProfile) GetResourceID(ctx context.Context, IntfID uint32, ResourceType string, NumIDs uint32) ([]uint32, error) {
197 return []uint32{}, nil
198}
199
200// FreeResourceID to mock techprofile FreeResourceID method
201func (m MockTechProfile) FreeResourceID(ctx context.Context, IntfID uint32, ResourceType string, ReleaseContent []uint32) error {
202 return nil
203}
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700204
205// GetTechProfileInstanceKey to mock techprofile GetTechProfileInstanceKey method
206func (m MockTechProfile) GetTechProfileInstanceKey(ctx context.Context, tpID uint32, uniPortName string) string {
207 return ""
208}