amit.ghosh | 258d14c | 2020-10-02 15:13:38 +0200 | [diff] [blame] | 1 | /* |
Joey Armstrong | 14628cd | 2023-01-10 08:38:31 -0500 | [diff] [blame] | 2 | * Copyright 2018-2023 Open Networking Foundation (ONF) and the ONF Contributors |
amit.ghosh | 258d14c | 2020-10-02 15:13:38 +0200 | [diff] [blame] | 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 | |
| 17 | package dmiserver |
| 18 | |
| 19 | import ( |
| 20 | "context" |
| 21 | |
| 22 | dmi "github.com/opencord/device-management-interface/go/dmi" |
ssiddiqui | 6ca4070 | 2021-03-08 18:20:21 +0530 | [diff] [blame] | 23 | "google.golang.org/grpc/codes" |
| 24 | "google.golang.org/grpc/status" |
amit.ghosh | 258d14c | 2020-10-02 15:13:38 +0200 | [diff] [blame] | 25 | ) |
| 26 | |
Abhay Kumar | c5723cc | 2023-06-08 12:09:30 +0530 | [diff] [blame^] | 27 | // GetSoftwareVersion gets the software version information of the Active and Standby images |
amit.ghosh | 258d14c | 2020-10-02 15:13:38 +0200 | [diff] [blame] | 28 | func (dms *DmiAPIServer) GetSoftwareVersion(ctx context.Context, req *dmi.HardwareID) (*dmi.GetSoftwareVersionInformationResponse, error) { |
| 29 | // TODO: Make this more interesting by taking values from BBSim if available |
| 30 | logger.Debugf("GetSoftwareVersion invoked with for device %+v", req) |
| 31 | return &dmi.GetSoftwareVersionInformationResponse{ |
Humera Kouser | a444295 | 2020-11-23 23:51:19 +0530 | [diff] [blame] | 32 | Status: dmi.Status_OK_STATUS, |
ssiddiqui | 6ca4070 | 2021-03-08 18:20:21 +0530 | [diff] [blame] | 33 | Reason: dmi.GetSoftwareVersionInformationResponse_UNDEFINED_REASON, |
amit.ghosh | 258d14c | 2020-10-02 15:13:38 +0200 | [diff] [blame] | 34 | Info: &dmi.SoftwareVersionInformation{ |
| 35 | ActiveVersions: []*dmi.ImageVersion{{ |
| 36 | ImageName: "BBSIM-DUMMY-IMAGE-1", |
| 37 | Version: "BBSIM-DUMMY-VERSION-1", |
| 38 | }}, |
| 39 | StandbyVersions: []*dmi.ImageVersion{{ |
| 40 | ImageName: "BBSIM-DUMMY-IMAGE-2", |
| 41 | Version: "BBSIM-DUMMY-VERSION-2", |
| 42 | }}, |
| 43 | }, |
| 44 | }, nil |
| 45 | } |
| 46 | |
Abhay Kumar | c5723cc | 2023-06-08 12:09:30 +0530 | [diff] [blame^] | 47 | // DownloadImage downloads and installs the image in the standby partition, returns the status/progress of the Install |
amit.ghosh | 258d14c | 2020-10-02 15:13:38 +0200 | [diff] [blame] | 48 | func (dms *DmiAPIServer) DownloadImage(req *dmi.DownloadImageRequest, stream dmi.NativeSoftwareManagementService_DownloadImageServer) error { |
| 49 | logger.Debugf("DownloadImage invoked with request %+v", req) |
| 50 | err := stream.Send(&dmi.ImageStatus{ |
Humera Kouser | a444295 | 2020-11-23 23:51:19 +0530 | [diff] [blame] | 51 | Status: dmi.Status_OK_STATUS, |
amit.ghosh | 258d14c | 2020-10-02 15:13:38 +0200 | [diff] [blame] | 52 | State: dmi.ImageStatus_COPYING_IMAGE, |
| 53 | }) |
| 54 | if err != nil { |
| 55 | logger.Errorf("Error sending image-status for DownloadImage, %v", err) |
| 56 | return err |
| 57 | } |
| 58 | return nil |
| 59 | |
| 60 | } |
| 61 | |
Abhay Kumar | c5723cc | 2023-06-08 12:09:30 +0530 | [diff] [blame^] | 62 | // ActivateImage Activates and runs the OLT with the image in the standby partition |
amit.ghosh | 258d14c | 2020-10-02 15:13:38 +0200 | [diff] [blame] | 63 | func (dms *DmiAPIServer) ActivateImage(req *dmi.HardwareID, stream dmi.NativeSoftwareManagementService_ActivateImageServer) error { |
| 64 | logger.Debugf("ActivateImage invoked with request %+v", req) |
| 65 | err := stream.Send(&dmi.ImageStatus{ |
Humera Kouser | a444295 | 2020-11-23 23:51:19 +0530 | [diff] [blame] | 66 | Status: dmi.Status_OK_STATUS, |
amit.ghosh | 258d14c | 2020-10-02 15:13:38 +0200 | [diff] [blame] | 67 | State: dmi.ImageStatus_ACTIVATION_COMPLETE, |
| 68 | }) |
| 69 | |
| 70 | if err != nil { |
| 71 | logger.Errorf("Error sending image-status for ActivateImage, %v", err) |
| 72 | return err |
| 73 | } |
| 74 | return nil |
| 75 | |
| 76 | } |
| 77 | |
Abhay Kumar | c5723cc | 2023-06-08 12:09:30 +0530 | [diff] [blame^] | 78 | // RevertToStandbyImage marks the image in the Standby as Active and reboots the device, so that it boots from that image which was in the standby. |
amit.ghosh | 258d14c | 2020-10-02 15:13:38 +0200 | [diff] [blame] | 79 | func (dms *DmiAPIServer) RevertToStandbyImage(req *dmi.HardwareID, stream dmi.NativeSoftwareManagementService_RevertToStandbyImageServer) error { |
| 80 | logger.Debugf("RevertToStandbyImage invoked with request %+v", req) |
| 81 | err := stream.Send(&dmi.ImageStatus{ |
Humera Kouser | a444295 | 2020-11-23 23:51:19 +0530 | [diff] [blame] | 82 | Status: dmi.Status_OK_STATUS, |
amit.ghosh | 258d14c | 2020-10-02 15:13:38 +0200 | [diff] [blame] | 83 | State: dmi.ImageStatus_ACTIVATION_COMPLETE, |
| 84 | }) |
| 85 | |
| 86 | if err != nil { |
| 87 | logger.Errorf("Error sending image-status for RevertToStandbyImage, %v", err) |
| 88 | return err |
| 89 | } |
| 90 | return nil |
| 91 | } |
Humera Kouser | a444295 | 2020-11-23 23:51:19 +0530 | [diff] [blame] | 92 | |
| 93 | // UpdateStartupConfiguration API can be used to let the devices pickup their properitary configuration which they need at startup. |
ssiddiqui | 6ca4070 | 2021-03-08 18:20:21 +0530 | [diff] [blame] | 94 | func (dms *DmiAPIServer) UpdateStartupConfiguration(request *dmi.ConfigRequest, stream dmi.NativeSoftwareManagementService_UpdateStartupConfigurationServer) error { |
| 95 | logger.Debugf("UpdateStartupConfiguration invoked with request %+v", request) |
| 96 | |
| 97 | if request == nil { |
| 98 | return status.Errorf(codes.InvalidArgument, "ConfigRequest is nil") |
| 99 | } |
| 100 | |
Elia Battiston | e8d1fa4 | 2022-04-01 10:47:37 +0200 | [diff] [blame] | 101 | if request.DeviceUuid == nil || request.DeviceUuid.Uuid != dms.uuid.Uuid { |
ssiddiqui | 6ca4070 | 2021-03-08 18:20:21 +0530 | [diff] [blame] | 102 | if err := stream.Send(&dmi.ConfigResponse{ |
| 103 | Status: dmi.Status_ERROR_STATUS, |
| 104 | Reason: dmi.ConfigResponse_UNKNOWN_DEVICE, |
| 105 | }); err != nil { |
| 106 | return status.Errorf(codes.Internal, "error sending response to client") |
| 107 | } |
| 108 | return nil |
| 109 | } |
| 110 | |
| 111 | if err := stream.Send(&dmi.ConfigResponse{ |
| 112 | Status: dmi.Status_OK_STATUS, |
| 113 | }); err != nil { |
| 114 | return status.Errorf(codes.Internal, "error sending response to client") |
| 115 | } |
| 116 | |
Humera Kouser | a444295 | 2020-11-23 23:51:19 +0530 | [diff] [blame] | 117 | return nil |
| 118 | } |
ssiddiqui | 6ca4070 | 2021-03-08 18:20:21 +0530 | [diff] [blame] | 119 | |
| 120 | // GetStartupConfigurationInfo API is used to return the 'StartUp' config present on the device |
| 121 | func (dms *DmiAPIServer) GetStartupConfigurationInfo(ctx context.Context, request *dmi.StartupConfigInfoRequest) (*dmi.StartupConfigInfoResponse, error) { |
| 122 | logger.Debugf("GetStartupConfigurationInfo invoked for device %s", request.DeviceUuid.String()) |
| 123 | |
| 124 | if request == nil { |
| 125 | return nil, status.Errorf(codes.InvalidArgument, "ConfigRequest is nil") |
| 126 | } |
| 127 | |
| 128 | if request.DeviceUuid == nil { |
| 129 | return nil, status.Errorf(codes.InvalidArgument, "DeviceUuid is nil") |
| 130 | } |
| 131 | |
Elia Battiston | e8d1fa4 | 2022-04-01 10:47:37 +0200 | [diff] [blame] | 132 | if request.DeviceUuid.Uuid != dms.uuid.Uuid { |
ssiddiqui | 6ca4070 | 2021-03-08 18:20:21 +0530 | [diff] [blame] | 133 | return &dmi.StartupConfigInfoResponse{ |
| 134 | Status: dmi.Status_ERROR_STATUS, |
| 135 | Reason: dmi.StartupConfigInfoResponse_UNKNOWN_DEVICE, |
| 136 | }, status.Errorf(codes.InvalidArgument, "device-uuid %s not found", request.DeviceUuid.Uuid) |
| 137 | } |
| 138 | |
| 139 | return &dmi.StartupConfigInfoResponse{ |
| 140 | Status: dmi.Status_OK_STATUS, |
| 141 | Version: "BBSIM-STARTUP-CONFIG-DUMMY-VERSION", |
| 142 | }, nil |
| 143 | } |