blob: 10449130eeeba1495f31338428c1377adefcb5ef [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"
22 "github.com/opencord/voltha-protos/go/openolt"
23 "github.com/opencord/voltha-protos/go/tech_profile"
24 "google.golang.org/grpc"
25 "net"
26)
27
28type FlowAddSpy struct {
29 CallCount int
30 Calls map[int]*openolt.Flow
31}
32
33type mockClient struct {
34 FlowAddSpy
35 fail bool
36}
37
38func (s *mockClient) DisableOlt(ctx context.Context, in *openolt.Empty, opts ...grpc.CallOption) (*openolt.Empty, error) {
39 return nil, errors.New("unimplemented-in-mock-client")
40}
41func (s *mockClient) ReenableOlt(ctx context.Context, in *openolt.Empty, opts ...grpc.CallOption) (*openolt.Empty, error) {
42 return nil, errors.New("unimplemented-in-mock-client")
43}
44func (s *mockClient) ActivateOnu(ctx context.Context, in *openolt.Onu, opts ...grpc.CallOption) (*openolt.Empty, error) {
45 return nil, errors.New("unimplemented-in-mock-client")
46}
47func (s *mockClient) DeactivateOnu(ctx context.Context, in *openolt.Onu, opts ...grpc.CallOption) (*openolt.Empty, error) {
48 return nil, errors.New("unimplemented-in-mock-client")
49}
50func (s *mockClient) DeleteOnu(ctx context.Context, in *openolt.Onu, opts ...grpc.CallOption) (*openolt.Empty, error) {
51 return nil, errors.New("unimplemented-in-mock-client")
52}
53func (s *mockClient) OmciMsgOut(ctx context.Context, in *openolt.OmciMsg, opts ...grpc.CallOption) (*openolt.Empty, error) {
54 return nil, errors.New("unimplemented-in-mock-client")
55}
56func (s *mockClient) OnuPacketOut(ctx context.Context, in *openolt.OnuPacket, opts ...grpc.CallOption) (*openolt.Empty, error) {
57 return nil, errors.New("unimplemented-in-mock-client")
58}
59func (s *mockClient) UplinkPacketOut(ctx context.Context, in *openolt.UplinkPacket, opts ...grpc.CallOption) (*openolt.Empty, error) {
60 return nil, errors.New("unimplemented-in-mock-client")
61}
62func (s *mockClient) FlowAdd(ctx context.Context, in *openolt.Flow, opts ...grpc.CallOption) (*openolt.Empty, error) {
63 s.FlowAddSpy.CallCount++
64 if s.fail {
65 return nil, errors.New("fake-error")
66 }
67 s.FlowAddSpy.Calls[s.FlowAddSpy.CallCount] = in
68 return &openolt.Empty{}, nil
69}
70func (s *mockClient) FlowRemove(ctx context.Context, in *openolt.Flow, opts ...grpc.CallOption) (*openolt.Empty, error) {
71 return nil, errors.New("unimplemented-in-mock-client")
72}
73func (s *mockClient) HeartbeatCheck(ctx context.Context, in *openolt.Empty, opts ...grpc.CallOption) (*openolt.Heartbeat, error) {
74 return nil, errors.New("unimplemented-in-mock-client")
75}
76func (s *mockClient) EnablePonIf(ctx context.Context, in *openolt.Interface, opts ...grpc.CallOption) (*openolt.Empty, error) {
77 return nil, errors.New("unimplemented-in-mock-client")
78}
79func (s *mockClient) DisablePonIf(ctx context.Context, in *openolt.Interface, opts ...grpc.CallOption) (*openolt.Empty, error) {
80 return nil, errors.New("unimplemented-in-mock-client")
81}
82func (s *mockClient) GetDeviceInfo(ctx context.Context, in *openolt.Empty, opts ...grpc.CallOption) (*openolt.DeviceInfo, error) {
83 return nil, errors.New("unimplemented-in-mock-client")
84}
85func (s *mockClient) Reboot(ctx context.Context, in *openolt.Empty, opts ...grpc.CallOption) (*openolt.Empty, error) {
86 return nil, errors.New("unimplemented-in-mock-client")
87}
88func (s *mockClient) CollectStatistics(ctx context.Context, in *openolt.Empty, opts ...grpc.CallOption) (*openolt.Empty, error) {
89 return nil, errors.New("unimplemented-in-mock-client")
90}
91func (s *mockClient) CreateTrafficSchedulers(ctx context.Context, in *tech_profile.TrafficSchedulers, opts ...grpc.CallOption) (*openolt.Empty, error) {
92 return nil, errors.New("unimplemented-in-mock-client")
93}
94func (s *mockClient) RemoveTrafficSchedulers(ctx context.Context, in *tech_profile.TrafficSchedulers, opts ...grpc.CallOption) (*openolt.Empty, error) {
95 return nil, errors.New("unimplemented-in-mock-client")
96}
97func (s *mockClient) CreateTrafficQueues(ctx context.Context, in *tech_profile.TrafficQueues, opts ...grpc.CallOption) (*openolt.Empty, error) {
98 return nil, errors.New("unimplemented-in-mock-client")
99}
100func (s *mockClient) RemoveTrafficQueues(ctx context.Context, in *tech_profile.TrafficQueues, opts ...grpc.CallOption) (*openolt.Empty, error) {
101 return nil, errors.New("unimplemented-in-mock-client")
102}
103func (s *mockClient) EnableIndication(ctx context.Context, in *openolt.Empty, opts ...grpc.CallOption) (openolt.Openolt_EnableIndicationClient, error) {
104 return nil, errors.New("unimplemented-in-mock-client")
105}
106
107func createMockOnu(id uint32, ponPortId uint32, sTag int, cTag int) Onu {
108 o := Onu{
109 ID: id,
110 PonPortID: ponPortId,
111 STag: sTag,
112 CTag: cTag,
113 HwAddress: net.HardwareAddr{0x2e, 0x60, 0x70, 0x13, byte(ponPortId), byte(id)},
114 PortNo: 0,
115 }
116 o.SerialNumber = o.NewSN(0, ponPortId, o.ID)
117 return o
118}