blob: 22beccedbb2d4ff8255ad9ce5b2969b39639da15 [file] [log] [blame]
khenaidoo26721882021-08-11 17:42:52 -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"
khenaidooa5feb8e2021-10-19 17:29:22 -040025 ca "github.com/opencord/voltha-protos/v5/go/core_adapter"
26 "github.com/opencord/voltha-protos/v5/go/health"
khenaidoo26721882021-08-11 17:42:52 -040027 "github.com/opencord/voltha-protos/v5/go/voltha"
28)
29
30//MockCoreServiceHandler implements the methods in the core service
31type MockCoreServiceHandler struct{}
32
khenaidooa5feb8e2021-10-19 17:29:22 -040033func (handler *MockCoreServiceHandler) RegisterAdapter(ctx context.Context, reg *ca.AdapterRegistration) (*empty.Empty, error) {
khenaidoo26721882021-08-11 17:42:52 -040034 //logger.Debugw(ctx, "registration-received", log.Fields{"input": reg})
35 return &empty.Empty{}, nil
36}
37
38func (handler *MockCoreServiceHandler) DeviceUpdate(context.Context, *voltha.Device) (*empty.Empty, error) {
39 return &empty.Empty{}, nil
40}
41
42func (handler *MockCoreServiceHandler) PortCreated(context.Context, *voltha.Port) (*empty.Empty, error) {
43 return &empty.Empty{}, nil
44}
45
khenaidooa5feb8e2021-10-19 17:29:22 -040046func (handler *MockCoreServiceHandler) PortsStateUpdate(context.Context, *ca.PortStateFilter) (*empty.Empty, error) {
khenaidoo26721882021-08-11 17:42:52 -040047 return &empty.Empty{}, nil
48}
49
50func (handler *MockCoreServiceHandler) DeleteAllPorts(context.Context, *common.ID) (*empty.Empty, error) {
51 return &empty.Empty{}, nil
52}
53
khenaidooa5feb8e2021-10-19 17:29:22 -040054func (handler *MockCoreServiceHandler) GetDevicePort(context.Context, *ca.PortFilter) (*voltha.Port, error) {
khenaidoo26721882021-08-11 17:42:52 -040055 return &voltha.Port{}, nil
56}
57
58func (handler *MockCoreServiceHandler) ListDevicePorts(context.Context, *common.ID) (*voltha.Ports, error) {
59 return &voltha.Ports{}, nil
60}
61
khenaidooa5feb8e2021-10-19 17:29:22 -040062func (handler *MockCoreServiceHandler) DeviceStateUpdate(context.Context, *ca.DeviceStateFilter) (*empty.Empty, error) {
khenaidoo26721882021-08-11 17:42:52 -040063 return &empty.Empty{}, nil
64}
65
66func (handler *MockCoreServiceHandler) DevicePMConfigUpdate(context.Context, *voltha.PmConfigs) (*empty.Empty, error) {
67 return &empty.Empty{}, nil
68}
69
khenaidooa5feb8e2021-10-19 17:29:22 -040070func (handler *MockCoreServiceHandler) ChildDeviceDetected(context.Context, *ca.DeviceDiscovery) (*voltha.Device, error) {
khenaidoo26721882021-08-11 17:42:52 -040071 return &voltha.Device{}, nil
72}
73
74func (handler *MockCoreServiceHandler) ChildDevicesLost(context.Context, *common.ID) (*empty.Empty, error) {
75 return &empty.Empty{}, nil
76}
77
78func (handler *MockCoreServiceHandler) ChildDevicesDetected(context.Context, *common.ID) (*empty.Empty, error) {
79 time.Sleep(50 * time.Millisecond)
80 return &empty.Empty{}, nil
81}
82
83func (handler *MockCoreServiceHandler) GetDevice(ctx context.Context, id *common.ID) (*voltha.Device, error) {
84 time.Sleep(50 * time.Millisecond)
85 vlan, _ := strconv.Atoi(id.Id)
86 return &voltha.Device{
87 Id: id.Id,
88 Type: "test-1234",
89 Vlan: uint32(vlan),
90 }, nil
91}
92
khenaidooa5feb8e2021-10-19 17:29:22 -040093func (handler *MockCoreServiceHandler) GetChildDevice(context.Context, *ca.ChildDeviceFilter) (*voltha.Device, error) {
khenaidoo26721882021-08-11 17:42:52 -040094 return nil, nil
95}
96
97func (handler *MockCoreServiceHandler) GetChildDevices(context.Context, *common.ID) (*voltha.Devices, error) {
98 return &voltha.Devices{}, nil
99}
100
khenaidooa5feb8e2021-10-19 17:29:22 -0400101func (handler *MockCoreServiceHandler) SendPacketIn(context.Context, *ca.PacketIn) (*empty.Empty, error) {
khenaidoo26721882021-08-11 17:42:52 -0400102 return &empty.Empty{}, nil
103}
104
khenaidooa5feb8e2021-10-19 17:29:22 -0400105func (handler *MockCoreServiceHandler) DeviceReasonUpdate(context.Context, *ca.DeviceReason) (*empty.Empty, error) {
khenaidoo26721882021-08-11 17:42:52 -0400106 return &empty.Empty{}, nil
107}
108
khenaidooa5feb8e2021-10-19 17:29:22 -0400109func (handler *MockCoreServiceHandler) PortStateUpdate(context.Context, *ca.PortState) (*empty.Empty, error) {
khenaidoo26721882021-08-11 17:42:52 -0400110 return &empty.Empty{}, nil
111}
112
113// Additional API found in the Core - unused?
114func (handler *MockCoreServiceHandler) ReconcileChildDevices(context.Context, *common.ID) (*empty.Empty, error) {
115 return &empty.Empty{}, nil
116}
117
118func (handler *MockCoreServiceHandler) GetChildDeviceWithProxyAddress(context.Context, *voltha.Device_ProxyAddress) (*voltha.Device, error) {
119 return &voltha.Device{}, nil
120}
121
khenaidooa5feb8e2021-10-19 17:29:22 -0400122func (handler *MockCoreServiceHandler) GetPorts(context.Context, *ca.PortFilter) (*voltha.Ports, error) {
khenaidoo26721882021-08-11 17:42:52 -0400123 return &voltha.Ports{}, nil
124}
125
khenaidooa5feb8e2021-10-19 17:29:22 -0400126func (handler *MockCoreServiceHandler) ChildrenStateUpdate(context.Context, *ca.DeviceStateFilter) (*empty.Empty, error) {
khenaidoo26721882021-08-11 17:42:52 -0400127 return &empty.Empty{}, nil
128}
129
130func (handler *MockCoreServiceHandler) UpdateImageDownload(context.Context, *voltha.ImageDownload) (*empty.Empty, error) {
131 return &empty.Empty{}, nil
132}
133
khenaidoob9503212021-12-08 14:22:21 -0500134func (handler *MockCoreServiceHandler) GetHealthStatus(ctx context.Context, conn *common.Connection) (*health.HealthStatus, error) {
khenaidooa5feb8e2021-10-19 17:29:22 -0400135 return &health.HealthStatus{State: health.HealthStatus_HEALTHY}, nil
khenaidoo26721882021-08-11 17:42:52 -0400136}