blob: b68f263b58e0cad6382fd92b306a01731f7bf73d [file] [log] [blame]
amit.ghosh258d14c2020-10-02 15:13:38 +02001/*
Joey Armstrong2c039362024-02-04 18:51:52 -05002 * Copyright 2018-2024 Open Networking Foundation (ONF) and the ONF Contributors
amit.ghosh258d14c2020-10-02 15:13:38 +02003
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
17package dmiserver
18
19import (
20 "context"
21
22 dmi "github.com/opencord/device-management-interface/go/dmi"
ssiddiqui6ca40702021-03-08 18:20:21 +053023 "google.golang.org/grpc/codes"
24 "google.golang.org/grpc/status"
amit.ghosh258d14c2020-10-02 15:13:38 +020025)
26
Abhay Kumarc5723cc2023-06-08 12:09:30 +053027// GetSoftwareVersion gets the software version information of the Active and Standby images
amit.ghosh258d14c2020-10-02 15:13:38 +020028func (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 Kousera4442952020-11-23 23:51:19 +053032 Status: dmi.Status_OK_STATUS,
ssiddiqui6ca40702021-03-08 18:20:21 +053033 Reason: dmi.GetSoftwareVersionInformationResponse_UNDEFINED_REASON,
amit.ghosh258d14c2020-10-02 15:13:38 +020034 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 Kumarc5723cc2023-06-08 12:09:30 +053047// DownloadImage downloads and installs the image in the standby partition, returns the status/progress of the Install
amit.ghosh258d14c2020-10-02 15:13:38 +020048func (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 Kousera4442952020-11-23 23:51:19 +053051 Status: dmi.Status_OK_STATUS,
amit.ghosh258d14c2020-10-02 15:13:38 +020052 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 Kumarc5723cc2023-06-08 12:09:30 +053062// ActivateImage Activates and runs the OLT with the image in the standby partition
amit.ghosh258d14c2020-10-02 15:13:38 +020063func (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 Kousera4442952020-11-23 23:51:19 +053066 Status: dmi.Status_OK_STATUS,
amit.ghosh258d14c2020-10-02 15:13:38 +020067 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 Kumarc5723cc2023-06-08 12:09:30 +053078// 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.ghosh258d14c2020-10-02 15:13:38 +020079func (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 Kousera4442952020-11-23 23:51:19 +053082 Status: dmi.Status_OK_STATUS,
amit.ghosh258d14c2020-10-02 15:13:38 +020083 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 Kousera4442952020-11-23 23:51:19 +053092
93// UpdateStartupConfiguration API can be used to let the devices pickup their properitary configuration which they need at startup.
ssiddiqui6ca40702021-03-08 18:20:21 +053094func (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 Battistone8d1fa42022-04-01 10:47:37 +0200101 if request.DeviceUuid == nil || request.DeviceUuid.Uuid != dms.uuid.Uuid {
ssiddiqui6ca40702021-03-08 18:20:21 +0530102 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 Kousera4442952020-11-23 23:51:19 +0530117 return nil
118}
ssiddiqui6ca40702021-03-08 18:20:21 +0530119
120// GetStartupConfigurationInfo API is used to return the 'StartUp' config present on the device
121func (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 Battistone8d1fa42022-04-01 10:47:37 +0200132 if request.DeviceUuid.Uuid != dms.uuid.Uuid {
ssiddiqui6ca40702021-03-08 18:20:21 +0530133 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}