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