Matteo Scandolo | 99f1846 | 2019-10-28 14:14:28 -0700 | [diff] [blame] | 1 | /* |
| 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 devices |
| 18 | |
| 19 | import ( |
| 20 | "context" |
| 21 | "errors" |
Shrey Baid | 688b424 | 2020-07-10 20:40:10 +0530 | [diff] [blame^] | 22 | "net" |
| 23 | "time" |
| 24 | |
Matteo Scandolo | 3de9de0 | 2019-11-14 13:40:03 -0800 | [diff] [blame] | 25 | "github.com/opencord/voltha-protos/v2/go/openolt" |
| 26 | "github.com/opencord/voltha-protos/v2/go/tech_profile" |
Matteo Scandolo | 99f1846 | 2019-10-28 14:14:28 -0700 | [diff] [blame] | 27 | "google.golang.org/grpc" |
Matteo Scandolo | 99f1846 | 2019-10-28 14:14:28 -0700 | [diff] [blame] | 28 | ) |
| 29 | |
| 30 | type FlowAddSpy struct { |
| 31 | CallCount int |
| 32 | Calls map[int]*openolt.Flow |
| 33 | } |
| 34 | |
| 35 | type mockClient struct { |
| 36 | FlowAddSpy |
| 37 | fail bool |
| 38 | } |
| 39 | |
| 40 | func (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 | } |
| 43 | func (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 | } |
| 46 | func (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 | } |
| 49 | func (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 | } |
| 52 | func (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 | } |
| 55 | func (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 | } |
| 58 | func (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 | } |
| 61 | func (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 | } |
| 64 | func (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 | } |
| 72 | func (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 | } |
| 75 | func (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 | } |
| 78 | func (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 | } |
| 81 | func (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 | } |
| 84 | func (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 | } |
| 87 | func (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 | } |
| 90 | func (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 | } |
| 93 | func (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 | } |
| 96 | func (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 | } |
| 99 | func (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 | } |
| 102 | func (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 | } |
| 105 | func (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 Scandolo | c114709 | 2019-10-29 09:38:33 -0700 | [diff] [blame] | 109 | // this method creates a fake ONU used in the tests |
Matteo Scandolo | 5ff8008 | 2019-12-20 13:20:57 -0800 | [diff] [blame] | 110 | func createMockOnu(id uint32, ponPortId uint32, sTag int, cTag int, auth bool, dhcp bool) *Onu { |
Matteo Scandolo | 99f1846 | 2019-10-28 14:14:28 -0700 | [diff] [blame] | 111 | o := Onu{ |
Matteo Scandolo | 5ff8008 | 2019-12-20 13:20:57 -0800 | [diff] [blame] | 112 | 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 Scandolo | 99f1846 | 2019-10-28 14:14:28 -0700 | [diff] [blame] | 121 | } |
| 122 | o.SerialNumber = o.NewSN(0, ponPortId, o.ID) |
Matteo Scandolo | 5ff8008 | 2019-12-20 13:20:57 -0800 | [diff] [blame] | 123 | return &o |
Matteo Scandolo | 99f1846 | 2019-10-28 14:14:28 -0700 | [diff] [blame] | 124 | } |
Matteo Scandolo | c114709 | 2019-10-29 09:38:33 -0700 | [diff] [blame] | 125 | |
| 126 | // this method creates a real ONU to be used in the tests |
| 127 | func createTestOnu() *Onu { |
| 128 | olt := OltDevice{ |
| 129 | ID: 0, |
| 130 | } |
| 131 | pon := PonPort{ |
Pragya Arya | 2225f20 | 2020-01-29 18:05:01 +0530 | [diff] [blame] | 132 | ID: 1, |
| 133 | Olt: &olt, |
Matteo Scandolo | c114709 | 2019-10-29 09:38:33 -0700 | [diff] [blame] | 134 | } |
Matteo Scandolo | eb6b5af | 2020-06-24 16:23:58 -0700 | [diff] [blame] | 135 | onu := CreateONU(&olt, &pon, 1, 900, 900, false, false, time.Duration(1*time.Millisecond), true) |
Zdravko Bozakov | 681364d | 2019-11-10 14:28:46 +0100 | [diff] [blame] | 136 | // NOTE we need this in order to create the OnuChannel |
Shrey Baid | 688b424 | 2020-07-10 20:40:10 +0530 | [diff] [blame^] | 137 | _ = onu.InternalState.Event("initialize") |
Matteo Scandolo | e811ae9 | 2019-12-10 17:50:14 -0800 | [diff] [blame] | 138 | onu.DiscoveryRetryDelay = 100 * time.Millisecond |
Matteo Scandolo | c114709 | 2019-10-29 09:38:33 -0700 | [diff] [blame] | 139 | return onu |
| 140 | } |