blob: 5e4b5842a04cbb457f9439557642fb43400bc8da [file] [log] [blame]
Matteo Scandolo99f18462019-10-28 14:14:28 -07001/*
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 devices
18
19import (
20 "context"
21 "errors"
Shrey Baid688b4242020-07-10 20:40:10 +053022 "net"
23 "time"
24
Matteo Scandolo3de9de02019-11-14 13:40:03 -080025 "github.com/opencord/voltha-protos/v2/go/openolt"
26 "github.com/opencord/voltha-protos/v2/go/tech_profile"
Matteo Scandolo99f18462019-10-28 14:14:28 -070027 "google.golang.org/grpc"
Matteo Scandolo99f18462019-10-28 14:14:28 -070028)
29
30type FlowAddSpy struct {
31 CallCount int
32 Calls map[int]*openolt.Flow
33}
34
35type mockClient struct {
36 FlowAddSpy
37 fail bool
38}
39
40func (s *mockClient) DisableOlt(ctx context.Context, in *openolt.Empty, opts ...grpc.CallOption) (*openolt.Empty, error) {
41 return nil, errors.New("unimplemented-in-mock-client")
42}
43func (s *mockClient) ReenableOlt(ctx context.Context, in *openolt.Empty, opts ...grpc.CallOption) (*openolt.Empty, error) {
44 return nil, errors.New("unimplemented-in-mock-client")
45}
46func (s *mockClient) ActivateOnu(ctx context.Context, in *openolt.Onu, opts ...grpc.CallOption) (*openolt.Empty, error) {
47 return nil, errors.New("unimplemented-in-mock-client")
48}
49func (s *mockClient) DeactivateOnu(ctx context.Context, in *openolt.Onu, opts ...grpc.CallOption) (*openolt.Empty, error) {
50 return nil, errors.New("unimplemented-in-mock-client")
51}
52func (s *mockClient) DeleteOnu(ctx context.Context, in *openolt.Onu, opts ...grpc.CallOption) (*openolt.Empty, error) {
53 return nil, errors.New("unimplemented-in-mock-client")
54}
55func (s *mockClient) OmciMsgOut(ctx context.Context, in *openolt.OmciMsg, opts ...grpc.CallOption) (*openolt.Empty, error) {
56 return nil, errors.New("unimplemented-in-mock-client")
57}
58func (s *mockClient) OnuPacketOut(ctx context.Context, in *openolt.OnuPacket, opts ...grpc.CallOption) (*openolt.Empty, error) {
59 return nil, errors.New("unimplemented-in-mock-client")
60}
61func (s *mockClient) UplinkPacketOut(ctx context.Context, in *openolt.UplinkPacket, opts ...grpc.CallOption) (*openolt.Empty, error) {
62 return nil, errors.New("unimplemented-in-mock-client")
63}
64func (s *mockClient) FlowAdd(ctx context.Context, in *openolt.Flow, opts ...grpc.CallOption) (*openolt.Empty, error) {
65 s.FlowAddSpy.CallCount++
66 if s.fail {
67 return nil, errors.New("fake-error")
68 }
69 s.FlowAddSpy.Calls[s.FlowAddSpy.CallCount] = in
70 return &openolt.Empty{}, nil
71}
72func (s *mockClient) FlowRemove(ctx context.Context, in *openolt.Flow, opts ...grpc.CallOption) (*openolt.Empty, error) {
73 return nil, errors.New("unimplemented-in-mock-client")
74}
75func (s *mockClient) HeartbeatCheck(ctx context.Context, in *openolt.Empty, opts ...grpc.CallOption) (*openolt.Heartbeat, error) {
76 return nil, errors.New("unimplemented-in-mock-client")
77}
78func (s *mockClient) EnablePonIf(ctx context.Context, in *openolt.Interface, opts ...grpc.CallOption) (*openolt.Empty, error) {
79 return nil, errors.New("unimplemented-in-mock-client")
80}
81func (s *mockClient) DisablePonIf(ctx context.Context, in *openolt.Interface, opts ...grpc.CallOption) (*openolt.Empty, error) {
82 return nil, errors.New("unimplemented-in-mock-client")
83}
84func (s *mockClient) GetDeviceInfo(ctx context.Context, in *openolt.Empty, opts ...grpc.CallOption) (*openolt.DeviceInfo, error) {
85 return nil, errors.New("unimplemented-in-mock-client")
86}
87func (s *mockClient) Reboot(ctx context.Context, in *openolt.Empty, opts ...grpc.CallOption) (*openolt.Empty, error) {
88 return nil, errors.New("unimplemented-in-mock-client")
89}
90func (s *mockClient) CollectStatistics(ctx context.Context, in *openolt.Empty, opts ...grpc.CallOption) (*openolt.Empty, error) {
91 return nil, errors.New("unimplemented-in-mock-client")
92}
93func (s *mockClient) CreateTrafficSchedulers(ctx context.Context, in *tech_profile.TrafficSchedulers, opts ...grpc.CallOption) (*openolt.Empty, error) {
94 return nil, errors.New("unimplemented-in-mock-client")
95}
96func (s *mockClient) RemoveTrafficSchedulers(ctx context.Context, in *tech_profile.TrafficSchedulers, opts ...grpc.CallOption) (*openolt.Empty, error) {
97 return nil, errors.New("unimplemented-in-mock-client")
98}
99func (s *mockClient) CreateTrafficQueues(ctx context.Context, in *tech_profile.TrafficQueues, opts ...grpc.CallOption) (*openolt.Empty, error) {
100 return nil, errors.New("unimplemented-in-mock-client")
101}
102func (s *mockClient) RemoveTrafficQueues(ctx context.Context, in *tech_profile.TrafficQueues, opts ...grpc.CallOption) (*openolt.Empty, error) {
103 return nil, errors.New("unimplemented-in-mock-client")
104}
105func (s *mockClient) EnableIndication(ctx context.Context, in *openolt.Empty, opts ...grpc.CallOption) (openolt.Openolt_EnableIndicationClient, error) {
106 return nil, errors.New("unimplemented-in-mock-client")
107}
108
Matteo Scandoloc1147092019-10-29 09:38:33 -0700109// this method creates a fake ONU used in the tests
Matteo Scandolo5ff80082019-12-20 13:20:57 -0800110func createMockOnu(id uint32, ponPortId uint32, sTag int, cTag int, auth bool, dhcp bool) *Onu {
Matteo Scandolo99f18462019-10-28 14:14:28 -0700111 o := Onu{
Matteo Scandolo5ff80082019-12-20 13:20:57 -0800112 ID: id,
113 PonPortID: ponPortId,
114 STag: sTag,
115 CTag: cTag,
116 HwAddress: net.HardwareAddr{0x2e, 0x60, 0x70, 0x13, byte(ponPortId), byte(id)},
117 PortNo: 0,
118 Auth: auth,
119 Dhcp: dhcp,
120 GemPortAdded: true,
Matteo Scandolo99f18462019-10-28 14:14:28 -0700121 }
122 o.SerialNumber = o.NewSN(0, ponPortId, o.ID)
Matteo Scandolo5ff80082019-12-20 13:20:57 -0800123 return &o
Matteo Scandolo99f18462019-10-28 14:14:28 -0700124}
Matteo Scandoloc1147092019-10-29 09:38:33 -0700125
126// this method creates a real ONU to be used in the tests
127func createTestOnu() *Onu {
128 olt := OltDevice{
129 ID: 0,
130 }
131 pon := PonPort{
Pragya Arya2225f202020-01-29 18:05:01 +0530132 ID: 1,
133 Olt: &olt,
Matteo Scandoloc1147092019-10-29 09:38:33 -0700134 }
Matteo Scandoloeb6b5af2020-06-24 16:23:58 -0700135 onu := CreateONU(&olt, &pon, 1, 900, 900, false, false, time.Duration(1*time.Millisecond), true)
Zdravko Bozakov681364d2019-11-10 14:28:46 +0100136 // NOTE we need this in order to create the OnuChannel
Shrey Baid688b4242020-07-10 20:40:10 +0530137 _ = onu.InternalState.Event("initialize")
Matteo Scandoloe811ae92019-12-10 17:50:14 -0800138 onu.DiscoveryRetryDelay = 100 * time.Millisecond
Matteo Scandoloc1147092019-10-29 09:38:33 -0700139 return onu
140}