blob: 745753cfc7c2541086095f7329ba619564d7e963 [file] [log] [blame]
khenaidood948f772021-08-11 17:49:24 -04001/*
2 * Copyright 2021-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 */
16package grpc
17
18import (
19 "context"
20 "strconv"
21 "time"
22
23 "github.com/golang/protobuf/ptypes/empty"
24 "github.com/opencord/voltha-protos/v5/go/common"
25 ic "github.com/opencord/voltha-protos/v5/go/inter_container"
26 "github.com/opencord/voltha-protos/v5/go/voltha"
27)
28
29//MockCoreServiceHandler implements the methods in the core service
30type MockCoreServiceHandler struct{}
31
32func (handler *MockCoreServiceHandler) RegisterAdapter(ctx context.Context, reg *ic.AdapterRegistration) (*empty.Empty, error) {
33 //logger.Debugw(ctx, "registration-received", log.Fields{"input": reg})
34 return &empty.Empty{}, nil
35}
36
37func (handler *MockCoreServiceHandler) DeviceUpdate(context.Context, *voltha.Device) (*empty.Empty, error) {
38 return &empty.Empty{}, nil
39}
40
41func (handler *MockCoreServiceHandler) PortCreated(context.Context, *voltha.Port) (*empty.Empty, error) {
42 return &empty.Empty{}, nil
43}
44
45func (handler *MockCoreServiceHandler) PortsStateUpdate(context.Context, *ic.PortStateFilter) (*empty.Empty, error) {
46 return &empty.Empty{}, nil
47}
48
49func (handler *MockCoreServiceHandler) DeleteAllPorts(context.Context, *common.ID) (*empty.Empty, error) {
50 return &empty.Empty{}, nil
51}
52
53func (handler *MockCoreServiceHandler) GetDevicePort(context.Context, *ic.PortFilter) (*voltha.Port, error) {
54 return &voltha.Port{}, nil
55}
56
57func (handler *MockCoreServiceHandler) ListDevicePorts(context.Context, *common.ID) (*voltha.Ports, error) {
58 return &voltha.Ports{}, nil
59}
60
61func (handler *MockCoreServiceHandler) DeviceStateUpdate(context.Context, *ic.DeviceStateFilter) (*empty.Empty, error) {
62 return &empty.Empty{}, nil
63}
64
65func (handler *MockCoreServiceHandler) DevicePMConfigUpdate(context.Context, *voltha.PmConfigs) (*empty.Empty, error) {
66 return &empty.Empty{}, nil
67}
68
69func (handler *MockCoreServiceHandler) ChildDeviceDetected(context.Context, *ic.DeviceDiscovery) (*voltha.Device, error) {
70 return &voltha.Device{}, nil
71}
72
73func (handler *MockCoreServiceHandler) ChildDevicesLost(context.Context, *common.ID) (*empty.Empty, error) {
74 return &empty.Empty{}, nil
75}
76
77func (handler *MockCoreServiceHandler) ChildDevicesDetected(context.Context, *common.ID) (*empty.Empty, error) {
78 time.Sleep(50 * time.Millisecond)
79 return &empty.Empty{}, nil
80}
81
82func (handler *MockCoreServiceHandler) GetDevice(ctx context.Context, id *common.ID) (*voltha.Device, error) {
83 time.Sleep(50 * time.Millisecond)
84 vlan, _ := strconv.Atoi(id.Id)
85 return &voltha.Device{
86 Id: id.Id,
87 Type: "test-1234",
88 Vlan: uint32(vlan),
89 }, nil
90}
91
92func (handler *MockCoreServiceHandler) GetChildDevice(context.Context, *ic.ChildDeviceFilter) (*voltha.Device, error) {
93 return nil, nil
94}
95
96func (handler *MockCoreServiceHandler) GetChildDevices(context.Context, *common.ID) (*voltha.Devices, error) {
97 return &voltha.Devices{}, nil
98}
99
100func (handler *MockCoreServiceHandler) SendPacketIn(context.Context, *ic.PacketIn) (*empty.Empty, error) {
101 return &empty.Empty{}, nil
102}
103
104func (handler *MockCoreServiceHandler) DeviceReasonUpdate(context.Context, *ic.DeviceReason) (*empty.Empty, error) {
105 return &empty.Empty{}, nil
106}
107
108func (handler *MockCoreServiceHandler) PortStateUpdate(context.Context, *ic.PortState) (*empty.Empty, error) {
109 return &empty.Empty{}, nil
110}
111
112// Additional API found in the Core - unused?
113func (handler *MockCoreServiceHandler) ReconcileChildDevices(context.Context, *common.ID) (*empty.Empty, error) {
114 return &empty.Empty{}, nil
115}
116
117func (handler *MockCoreServiceHandler) GetChildDeviceWithProxyAddress(context.Context, *voltha.Device_ProxyAddress) (*voltha.Device, error) {
118 return &voltha.Device{}, nil
119}
120
121func (handler *MockCoreServiceHandler) GetPorts(context.Context, *ic.PortFilter) (*voltha.Ports, error) {
122 return &voltha.Ports{}, nil
123}
124
125func (handler *MockCoreServiceHandler) ChildrenStateUpdate(context.Context, *ic.DeviceStateFilter) (*empty.Empty, error) {
126 return &empty.Empty{}, nil
127}
128
129func (handler *MockCoreServiceHandler) UpdateImageDownload(context.Context, *voltha.ImageDownload) (*empty.Empty, error) {
130 return &empty.Empty{}, nil
131}
132
133func (handler *MockCoreServiceHandler) GetHealthStatus(ctx context.Context, empty *empty.Empty) (*voltha.HealthStatus, error) {
134 return &voltha.HealthStatus{State: voltha.HealthStatus_HEALTHY}, nil
135}