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