blob: 015f667f46c75be19c61eef3f2177b80377869df [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"
khenaidoo9beaaf12021-10-19 17:32:01 -040025 ca "github.com/opencord/voltha-protos/v5/go/core_adapter"
26 "github.com/opencord/voltha-protos/v5/go/health"
khenaidood948f772021-08-11 17:49:24 -040027 "github.com/opencord/voltha-protos/v5/go/voltha"
28)
29
30//MockCoreServiceHandler implements the methods in the core service
31type MockCoreServiceHandler struct{}
32
khenaidoo9beaaf12021-10-19 17:32:01 -040033func (handler *MockCoreServiceHandler) RegisterAdapter(ctx context.Context, reg *ca.AdapterRegistration) (*empty.Empty, error) {
khenaidood948f772021-08-11 17:49:24 -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
khenaidoo9beaaf12021-10-19 17:32:01 -040046func (handler *MockCoreServiceHandler) PortsStateUpdate(context.Context, *ca.PortStateFilter) (*empty.Empty, error) {
khenaidood948f772021-08-11 17:49:24 -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
khenaidoo9beaaf12021-10-19 17:32:01 -040054func (handler *MockCoreServiceHandler) GetDevicePort(context.Context, *ca.PortFilter) (*voltha.Port, error) {
khenaidood948f772021-08-11 17:49:24 -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
khenaidoo9beaaf12021-10-19 17:32:01 -040062func (handler *MockCoreServiceHandler) DeviceStateUpdate(context.Context, *ca.DeviceStateFilter) (*empty.Empty, error) {
khenaidood948f772021-08-11 17:49:24 -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
khenaidoo9beaaf12021-10-19 17:32:01 -040070func (handler *MockCoreServiceHandler) ChildDeviceDetected(context.Context, *ca.DeviceDiscovery) (*voltha.Device, error) {
khenaidood948f772021-08-11 17:49:24 -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
khenaidoo9beaaf12021-10-19 17:32:01 -040093func (handler *MockCoreServiceHandler) GetChildDevice(context.Context, *ca.ChildDeviceFilter) (*voltha.Device, error) {
khenaidood948f772021-08-11 17:49:24 -040094 return nil, nil
95}
96
97func (handler *MockCoreServiceHandler) GetChildDevices(context.Context, *common.ID) (*voltha.Devices, error) {
98 return &voltha.Devices{}, nil
99}
100
khenaidoo9beaaf12021-10-19 17:32:01 -0400101func (handler *MockCoreServiceHandler) SendPacketIn(context.Context, *ca.PacketIn) (*empty.Empty, error) {
khenaidood948f772021-08-11 17:49:24 -0400102 return &empty.Empty{}, nil
103}
104
khenaidoo9beaaf12021-10-19 17:32:01 -0400105func (handler *MockCoreServiceHandler) DeviceReasonUpdate(context.Context, *ca.DeviceReason) (*empty.Empty, error) {
khenaidood948f772021-08-11 17:49:24 -0400106 return &empty.Empty{}, nil
107}
108
khenaidoo9beaaf12021-10-19 17:32:01 -0400109func (handler *MockCoreServiceHandler) PortStateUpdate(context.Context, *ca.PortState) (*empty.Empty, error) {
khenaidood948f772021-08-11 17:49:24 -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
khenaidoo9beaaf12021-10-19 17:32:01 -0400122func (handler *MockCoreServiceHandler) GetPorts(context.Context, *ca.PortFilter) (*voltha.Ports, error) {
khenaidood948f772021-08-11 17:49:24 -0400123 return &voltha.Ports{}, nil
124}
125
khenaidoo9beaaf12021-10-19 17:32:01 -0400126func (handler *MockCoreServiceHandler) ChildrenStateUpdate(context.Context, *ca.DeviceStateFilter) (*empty.Empty, error) {
khenaidood948f772021-08-11 17:49:24 -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
khenaidoo9beaaf12021-10-19 17:32:01 -0400134func (handler *MockCoreServiceHandler) GetHealthStatus(ctx context.Context, empty *empty.Empty) (*health.HealthStatus, error) {
135 return &health.HealthStatus{State: health.HealthStatus_HEALTHY}, nil
khenaidood948f772021-08-11 17:49:24 -0400136}