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" |
| 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 |
| 30 | type MockCoreServiceHandler struct{} |
| 31 | |
| 32 | func (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 | |
| 37 | func (handler *MockCoreServiceHandler) DeviceUpdate(context.Context, *voltha.Device) (*empty.Empty, error) { |
| 38 | return &empty.Empty{}, nil |
| 39 | } |
| 40 | |
| 41 | func (handler *MockCoreServiceHandler) PortCreated(context.Context, *voltha.Port) (*empty.Empty, error) { |
| 42 | return &empty.Empty{}, nil |
| 43 | } |
| 44 | |
| 45 | func (handler *MockCoreServiceHandler) PortsStateUpdate(context.Context, *ic.PortStateFilter) (*empty.Empty, error) { |
| 46 | return &empty.Empty{}, nil |
| 47 | } |
| 48 | |
| 49 | func (handler *MockCoreServiceHandler) DeleteAllPorts(context.Context, *common.ID) (*empty.Empty, error) { |
| 50 | return &empty.Empty{}, nil |
| 51 | } |
| 52 | |
| 53 | func (handler *MockCoreServiceHandler) GetDevicePort(context.Context, *ic.PortFilter) (*voltha.Port, error) { |
| 54 | return &voltha.Port{}, nil |
| 55 | } |
| 56 | |
| 57 | func (handler *MockCoreServiceHandler) ListDevicePorts(context.Context, *common.ID) (*voltha.Ports, error) { |
| 58 | return &voltha.Ports{}, nil |
| 59 | } |
| 60 | |
| 61 | func (handler *MockCoreServiceHandler) DeviceStateUpdate(context.Context, *ic.DeviceStateFilter) (*empty.Empty, error) { |
| 62 | return &empty.Empty{}, nil |
| 63 | } |
| 64 | |
| 65 | func (handler *MockCoreServiceHandler) DevicePMConfigUpdate(context.Context, *voltha.PmConfigs) (*empty.Empty, error) { |
| 66 | return &empty.Empty{}, nil |
| 67 | } |
| 68 | |
| 69 | func (handler *MockCoreServiceHandler) ChildDeviceDetected(context.Context, *ic.DeviceDiscovery) (*voltha.Device, error) { |
| 70 | return &voltha.Device{}, nil |
| 71 | } |
| 72 | |
| 73 | func (handler *MockCoreServiceHandler) ChildDevicesLost(context.Context, *common.ID) (*empty.Empty, error) { |
| 74 | return &empty.Empty{}, nil |
| 75 | } |
| 76 | |
| 77 | func (handler *MockCoreServiceHandler) ChildDevicesDetected(context.Context, *common.ID) (*empty.Empty, error) { |
| 78 | time.Sleep(50 * time.Millisecond) |
| 79 | return &empty.Empty{}, nil |
| 80 | } |
| 81 | |
| 82 | func (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 | |
| 92 | func (handler *MockCoreServiceHandler) GetChildDevice(context.Context, *ic.ChildDeviceFilter) (*voltha.Device, error) { |
| 93 | return nil, nil |
| 94 | } |
| 95 | |
| 96 | func (handler *MockCoreServiceHandler) GetChildDevices(context.Context, *common.ID) (*voltha.Devices, error) { |
| 97 | return &voltha.Devices{}, nil |
| 98 | } |
| 99 | |
| 100 | func (handler *MockCoreServiceHandler) SendPacketIn(context.Context, *ic.PacketIn) (*empty.Empty, error) { |
| 101 | return &empty.Empty{}, nil |
| 102 | } |
| 103 | |
| 104 | func (handler *MockCoreServiceHandler) DeviceReasonUpdate(context.Context, *ic.DeviceReason) (*empty.Empty, error) { |
| 105 | return &empty.Empty{}, nil |
| 106 | } |
| 107 | |
| 108 | func (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? |
| 113 | func (handler *MockCoreServiceHandler) ReconcileChildDevices(context.Context, *common.ID) (*empty.Empty, error) { |
| 114 | return &empty.Empty{}, nil |
| 115 | } |
| 116 | |
| 117 | func (handler *MockCoreServiceHandler) GetChildDeviceWithProxyAddress(context.Context, *voltha.Device_ProxyAddress) (*voltha.Device, error) { |
| 118 | return &voltha.Device{}, nil |
| 119 | } |
| 120 | |
| 121 | func (handler *MockCoreServiceHandler) GetPorts(context.Context, *ic.PortFilter) (*voltha.Ports, error) { |
| 122 | return &voltha.Ports{}, nil |
| 123 | } |
| 124 | |
| 125 | func (handler *MockCoreServiceHandler) ChildrenStateUpdate(context.Context, *ic.DeviceStateFilter) (*empty.Empty, error) { |
| 126 | return &empty.Empty{}, nil |
| 127 | } |
| 128 | |
| 129 | func (handler *MockCoreServiceHandler) UpdateImageDownload(context.Context, *voltha.ImageDownload) (*empty.Empty, error) { |
| 130 | return &empty.Empty{}, nil |
| 131 | } |
| 132 | |
| 133 | func (handler *MockCoreServiceHandler) GetHealthStatus(ctx context.Context, empty *empty.Empty) (*voltha.HealthStatus, error) { |
| 134 | return &voltha.HealthStatus{State: voltha.HealthStatus_HEALTHY}, nil |
| 135 | } |