blob: ba58d2fef7f67b42419e70f21406953e8f040163 [file] [log] [blame]
Mahir Gunyel03de0d32020-06-03 01:36:59 -07001/*
2 * Copyright 2018-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
17package device
18
19import (
Mahir Gunyelfa6ea272020-06-10 17:03:51 -070020 "context"
Maninder9a1bc0d2020-10-26 11:34:02 +053021 "fmt"
Mahir Gunyelfa6ea272020-06-10 17:03:51 -070022 "strconv"
23
24 "github.com/gogo/protobuf/proto"
25 coreutils "github.com/opencord/voltha-go/rw_core/utils"
yasin sapli5458a1c2021-06-14 22:24:38 +000026 "github.com/opencord/voltha-lib-go/v5/pkg/log"
Maninder9a1bc0d2020-10-26 11:34:02 +053027 "github.com/opencord/voltha-protos/v4/go/common"
Maninderdfadc982020-10-28 14:04:33 +053028 ofp "github.com/opencord/voltha-protos/v4/go/openflow_13"
29 "github.com/opencord/voltha-protos/v4/go/voltha"
Mahir Gunyelfa6ea272020-06-10 17:03:51 -070030 "google.golang.org/grpc/codes"
31 "google.golang.org/grpc/status"
Mahir Gunyel03de0d32020-06-03 01:36:59 -070032)
33
34// listDeviceGroups returns logical device flow groups
35func (agent *Agent) listDeviceGroups() map[uint32]*ofp.OfpGroupEntry {
khenaidoo7585a962021-06-10 16:15:38 -040036 groupIDs := agent.groupCache.ListIDs()
Mahir Gunyel03de0d32020-06-03 01:36:59 -070037 groups := make(map[uint32]*ofp.OfpGroupEntry, len(groupIDs))
38 for groupID := range groupIDs {
khenaidoo7585a962021-06-10 16:15:38 -040039 if groupHandle, have := agent.groupCache.Lock(groupID); have {
Mahir Gunyel03de0d32020-06-03 01:36:59 -070040 groups[groupID] = groupHandle.GetReadOnly()
41 groupHandle.Unlock()
42 }
43 }
44 return groups
45}
Mahir Gunyelfa6ea272020-06-10 17:03:51 -070046
47func (agent *Agent) addGroupsToAdapter(ctx context.Context, newGroups []*ofp.OfpGroupEntry, flowMetadata *voltha.FlowMetadata) (coreutils.Response, error) {
Rohan Agrawal31f21802020-06-12 05:38:46 +000048 logger.Debugw(ctx, "add-groups-to-adapters", log.Fields{"device-id": agent.deviceID, "groups": newGroups, "flow-metadata": flowMetadata})
Mahir Gunyelfa6ea272020-06-10 17:03:51 -070049
Maninder9a1bc0d2020-10-26 11:34:02 +053050 var desc string
51 operStatus := &common.OperationResp{Code: common.OperationResp_OPERATION_FAILURE}
52
Mahir Gunyelfa6ea272020-06-10 17:03:51 -070053 if (len(newGroups)) == 0 {
Rohan Agrawal31f21802020-06-12 05:38:46 +000054 logger.Debugw(ctx, "nothing-to-update", log.Fields{"device-id": agent.deviceID, "groups": newGroups})
Mahir Gunyelfa6ea272020-06-10 17:03:51 -070055 return coreutils.DoneResponse(), nil
56 }
57
Kent Hagermancba2f302020-07-28 13:37:36 -040058 device, err := agent.getDeviceReadOnly(ctx)
59 if err != nil {
Maninder9a1bc0d2020-10-26 11:34:02 +053060 desc = err.Error()
61 agent.logDeviceUpdate(ctx, "addGroupsToAdapter", nil, nil, operStatus, &desc)
Kent Hagermancba2f302020-07-28 13:37:36 -040062 return coreutils.DoneResponse(), status.Errorf(codes.Aborted, "%s", err)
63 }
Maninder2195ccc2021-06-23 20:23:01 +053064
65 if !agent.proceedWithRequest(device) {
66 desc = fmt.Sprintf("deviceId:%s, Cannot complete operation as device deletion is in progress or reconciling is in progress/failed", device.Id)
67 agent.logDeviceUpdate(ctx, "addGroupsToAdapter", nil, nil, operStatus, &desc)
68 return coreutils.DoneResponse(), status.Errorf(codes.FailedPrecondition, "%s", desc)
69 }
70
Mahir Gunyelfa6ea272020-06-10 17:03:51 -070071 dType, err := agent.adapterMgr.GetDeviceType(ctx, &voltha.ID{Id: device.Type})
72 if err != nil {
Maninder9a1bc0d2020-10-26 11:34:02 +053073 desc = fmt.Sprintf("non-existent-device-type-%s", device.Type)
74 agent.logDeviceUpdate(ctx, "addGroupsToAdapter", nil, nil, operStatus, &desc)
Mahir Gunyelfa6ea272020-06-10 17:03:51 -070075 return coreutils.DoneResponse(), status.Errorf(codes.FailedPrecondition, "non-existent-device-type-%s", device.Type)
76 }
Mahir Gunyelfa6ea272020-06-10 17:03:51 -070077
78 groupsToAdd := make([]*ofp.OfpGroupEntry, 0)
79 groupsToDelete := make([]*ofp.OfpGroupEntry, 0)
80 for _, group := range newGroups {
khenaidoo7585a962021-06-10 16:15:38 -040081 groupHandle, created, err := agent.groupCache.LockOrCreate(ctx, group)
Mahir Gunyelfa6ea272020-06-10 17:03:51 -070082 if err != nil {
Maninder9a1bc0d2020-10-26 11:34:02 +053083 desc = err.Error()
84 agent.logDeviceUpdate(ctx, "addGroupsToAdapter", nil, nil, operStatus, &desc)
Mahir Gunyelfa6ea272020-06-10 17:03:51 -070085 return coreutils.DoneResponse(), err
86 }
87
88 if created {
89 groupsToAdd = append(groupsToAdd, group)
Mahir Gunyelfa6ea272020-06-10 17:03:51 -070090 } else {
91 groupToChange := groupHandle.GetReadOnly()
92 if !proto.Equal(groupToChange, group) {
93 //Group needs to be updated.
94 if err := groupHandle.Update(ctx, group); err != nil {
95 groupHandle.Unlock()
Maninder9a1bc0d2020-10-26 11:34:02 +053096 desc = fmt.Sprintf("failure-updating-group-%s-to-device-%s", strconv.Itoa(int(group.Desc.GroupId)), agent.deviceID)
97 agent.logDeviceUpdate(ctx, "addGroupsToAdapter", nil, nil, operStatus, &desc)
Mahir Gunyelfa6ea272020-06-10 17:03:51 -070098 return coreutils.DoneResponse(), status.Errorf(codes.Internal, "failure-updating-group-%s-to-device-%s", strconv.Itoa(int(group.Desc.GroupId)), agent.deviceID)
99 }
100 groupsToDelete = append(groupsToDelete, groupToChange)
101 groupsToAdd = append(groupsToAdd, group)
Mahir Gunyelfa6ea272020-06-10 17:03:51 -0700102 } else {
103 //No need to change the group. It is already exist.
Himani Chawlab4c25912020-11-12 17:16:38 +0530104 logger.Debugw(ctx, "no-need-to-change-already-existing-group", log.Fields{"device-id": agent.deviceID, "group": newGroups, "flow-metadata": flowMetadata})
Mahir Gunyelfa6ea272020-06-10 17:03:51 -0700105 }
106 }
107
108 groupHandle.Unlock()
109 }
110 // Sanity check
111 if (len(groupsToAdd)) == 0 {
Rohan Agrawal31f21802020-06-12 05:38:46 +0000112 logger.Debugw(ctx, "no-groups-to-update", log.Fields{"device-id": agent.deviceID, "groups": newGroups})
Mahir Gunyelfa6ea272020-06-10 17:03:51 -0700113 return coreutils.DoneResponse(), nil
114 }
115
116 // Send update to adapters
Rohan Agrawalcf12f202020-08-03 04:42:01 +0000117 subCtx, cancel := context.WithTimeout(log.WithSpanFromContext(context.Background(), ctx), agent.defaultTimeout)
Himani Chawlab4c25912020-11-12 17:16:38 +0530118 subCtx = coreutils.WithRPCMetadataFromContext(subCtx, ctx)
119
Mahir Gunyelfa6ea272020-06-10 17:03:51 -0700120 response := coreutils.NewResponse()
121 if !dType.AcceptsAddRemoveFlowUpdates {
Kent Hagermana7c9d792020-07-16 17:39:01 -0400122 updatedAllGroups := agent.listDeviceGroups()
123 rpcResponse, err := agent.adapterProxy.UpdateFlowsBulk(subCtx, device, nil, updatedAllGroups, flowMetadata)
Mahir Gunyelfa6ea272020-06-10 17:03:51 -0700124 if err != nil {
125 cancel()
Maninder9a1bc0d2020-10-26 11:34:02 +0530126 desc = err.Error()
127 agent.logDeviceUpdate(ctx, "addGroupsToAdapter", nil, nil, operStatus, &desc)
Mahir Gunyelfa6ea272020-06-10 17:03:51 -0700128 return coreutils.DoneResponse(), err
129 }
Maninder9a1bc0d2020-10-26 11:34:02 +0530130 go agent.waitForAdapterFlowResponse(subCtx, cancel, "addGroupsToAdapter", rpcResponse, response)
Mahir Gunyelfa6ea272020-06-10 17:03:51 -0700131 } else {
132 flowChanges := &ofp.FlowChanges{
133 ToAdd: &voltha.Flows{Items: []*ofp.OfpFlowStats{}},
134 ToRemove: &voltha.Flows{Items: []*ofp.OfpFlowStats{}},
135 }
136 groupChanges := &ofp.FlowGroupChanges{
137 ToAdd: &voltha.FlowGroups{Items: groupsToAdd},
138 ToRemove: &voltha.FlowGroups{Items: groupsToDelete},
139 ToUpdate: &voltha.FlowGroups{Items: []*ofp.OfpGroupEntry{}},
140 }
141 rpcResponse, err := agent.adapterProxy.UpdateFlowsIncremental(subCtx, device, flowChanges, groupChanges, flowMetadata)
142 if err != nil {
143 cancel()
Maninder9a1bc0d2020-10-26 11:34:02 +0530144 desc = err.Error()
145 agent.logDeviceUpdate(ctx, "addGroupsToAdapter", nil, nil, operStatus, &desc)
Mahir Gunyelfa6ea272020-06-10 17:03:51 -0700146 return coreutils.DoneResponse(), err
147 }
Maninder9a1bc0d2020-10-26 11:34:02 +0530148 go agent.waitForAdapterFlowResponse(subCtx, cancel, "addGroupsToAdapter", rpcResponse, response)
Mahir Gunyelfa6ea272020-06-10 17:03:51 -0700149 }
Maninder9a1bc0d2020-10-26 11:34:02 +0530150 operStatus.Code = common.OperationResp_OPERATION_IN_PROGRESS
151 agent.logDeviceUpdate(ctx, "addGroupsToAdapter", nil, nil, operStatus, &desc)
Mahir Gunyelfa6ea272020-06-10 17:03:51 -0700152 return response, nil
153}
154
155func (agent *Agent) deleteGroupsFromAdapter(ctx context.Context, groupsToDel []*ofp.OfpGroupEntry, flowMetadata *voltha.FlowMetadata) (coreutils.Response, error) {
Rohan Agrawal31f21802020-06-12 05:38:46 +0000156 logger.Debugw(ctx, "delete-groups-from-adapter", log.Fields{"device-id": agent.deviceID, "groups": groupsToDel})
Mahir Gunyelfa6ea272020-06-10 17:03:51 -0700157
158 if (len(groupsToDel)) == 0 {
Rohan Agrawal31f21802020-06-12 05:38:46 +0000159 logger.Debugw(ctx, "nothing-to-delete", log.Fields{"device-id": agent.deviceID})
Mahir Gunyelfa6ea272020-06-10 17:03:51 -0700160 return coreutils.DoneResponse(), nil
161 }
Maninder9a1bc0d2020-10-26 11:34:02 +0530162
163 var desc string
164 operStatus := &common.OperationResp{Code: common.OperationResp_OPERATION_FAILURE}
165
166 defer agent.logDeviceUpdate(ctx, "deleteGroupsFromAdapter", nil, nil, operStatus, &desc)
167
Kent Hagermancba2f302020-07-28 13:37:36 -0400168 device, err := agent.getDeviceReadOnly(ctx)
169 if err != nil {
Maninder9a1bc0d2020-10-26 11:34:02 +0530170 desc = err.Error()
Kent Hagermancba2f302020-07-28 13:37:36 -0400171 return coreutils.DoneResponse(), status.Errorf(codes.Aborted, "%s", err)
172 }
Maninder2195ccc2021-06-23 20:23:01 +0530173
174 if !agent.proceedWithRequest(device) {
175 desc = fmt.Sprintf("deviceId:%s, Cannot complete operation as device deletion is in progress or reconciling is in progress/failed", device.Id)
176 agent.logDeviceUpdate(ctx, "deleteGroupsFromAdapter", nil, nil, operStatus, &desc)
177 return coreutils.DoneResponse(), status.Errorf(codes.FailedPrecondition, "%s", desc)
178 }
179
Mahir Gunyelfa6ea272020-06-10 17:03:51 -0700180 dType, err := agent.adapterMgr.GetDeviceType(ctx, &voltha.ID{Id: device.Type})
181 if err != nil {
Maninder9a1bc0d2020-10-26 11:34:02 +0530182 desc = fmt.Sprintf("non-existent-device-type-%s", device.Type)
Mahir Gunyelfa6ea272020-06-10 17:03:51 -0700183 return coreutils.DoneResponse(), status.Errorf(codes.FailedPrecondition, "non-existent-device-type-%s", device.Type)
184 }
Mahir Gunyelfa6ea272020-06-10 17:03:51 -0700185
186 for _, group := range groupsToDel {
khenaidoo7585a962021-06-10 16:15:38 -0400187 if groupHandle, have := agent.groupCache.Lock(group.Desc.GroupId); have {
Mahir Gunyelfa6ea272020-06-10 17:03:51 -0700188 // Update the store and cache
189 if err := groupHandle.Delete(ctx); err != nil {
190 groupHandle.Unlock()
Maninder9a1bc0d2020-10-26 11:34:02 +0530191 desc = err.Error()
Mahir Gunyelfa6ea272020-06-10 17:03:51 -0700192 return coreutils.DoneResponse(), err
193 }
Mahir Gunyelfa6ea272020-06-10 17:03:51 -0700194 groupHandle.Unlock()
195 }
196 }
197
198 // Send update to adapters
Rohan Agrawalcf12f202020-08-03 04:42:01 +0000199 subCtx, cancel := context.WithTimeout(log.WithSpanFromContext(context.Background(), ctx), agent.defaultTimeout)
Himani Chawlab4c25912020-11-12 17:16:38 +0530200 subCtx = coreutils.WithRPCMetadataFromContext(subCtx, ctx)
201
Mahir Gunyelfa6ea272020-06-10 17:03:51 -0700202 response := coreutils.NewResponse()
203 if !dType.AcceptsAddRemoveFlowUpdates {
Kent Hagermana7c9d792020-07-16 17:39:01 -0400204 updatedAllGroups := agent.listDeviceGroups()
205 rpcResponse, err := agent.adapterProxy.UpdateFlowsBulk(subCtx, device, nil, updatedAllGroups, flowMetadata)
Mahir Gunyelfa6ea272020-06-10 17:03:51 -0700206 if err != nil {
207 cancel()
Maninder9a1bc0d2020-10-26 11:34:02 +0530208 desc = err.Error()
Mahir Gunyelfa6ea272020-06-10 17:03:51 -0700209 return coreutils.DoneResponse(), err
210 }
Maninder9a1bc0d2020-10-26 11:34:02 +0530211 go agent.waitForAdapterFlowResponse(subCtx, cancel, "deleteGroupsFromAdapter", rpcResponse, response)
Mahir Gunyelfa6ea272020-06-10 17:03:51 -0700212 } else {
213 flowChanges := &ofp.FlowChanges{
214 ToAdd: &voltha.Flows{Items: []*ofp.OfpFlowStats{}},
215 ToRemove: &voltha.Flows{Items: []*ofp.OfpFlowStats{}},
216 }
217 groupChanges := &ofp.FlowGroupChanges{
218 ToAdd: &voltha.FlowGroups{Items: []*ofp.OfpGroupEntry{}},
219 ToRemove: &voltha.FlowGroups{Items: groupsToDel},
220 ToUpdate: &voltha.FlowGroups{Items: []*ofp.OfpGroupEntry{}},
221 }
222 rpcResponse, err := agent.adapterProxy.UpdateFlowsIncremental(subCtx, device, flowChanges, groupChanges, flowMetadata)
223 if err != nil {
224 cancel()
Maninder9a1bc0d2020-10-26 11:34:02 +0530225 desc = err.Error()
Mahir Gunyelfa6ea272020-06-10 17:03:51 -0700226 return coreutils.DoneResponse(), err
227 }
Maninder9a1bc0d2020-10-26 11:34:02 +0530228 go agent.waitForAdapterFlowResponse(subCtx, cancel, "deleteGroupsFromAdapter", rpcResponse, response)
Mahir Gunyelfa6ea272020-06-10 17:03:51 -0700229 }
Maninder9a1bc0d2020-10-26 11:34:02 +0530230 operStatus.Code = common.OperationResp_OPERATION_IN_PROGRESS
Mahir Gunyelfa6ea272020-06-10 17:03:51 -0700231 return response, nil
232}
233
234func (agent *Agent) updateGroupsToAdapter(ctx context.Context, updatedGroups []*ofp.OfpGroupEntry, flowMetadata *voltha.FlowMetadata) (coreutils.Response, error) {
Himani Chawlab4c25912020-11-12 17:16:38 +0530235 logger.Debugw(ctx, "update-groups-to-adapter", log.Fields{"device-id": agent.deviceID, "groups": updatedGroups})
Mahir Gunyelfa6ea272020-06-10 17:03:51 -0700236
Maninder9a1bc0d2020-10-26 11:34:02 +0530237 var desc string
238 operStatus := &common.OperationResp{Code: common.OperationResp_OPERATION_FAILURE}
239
Mahir Gunyelfa6ea272020-06-10 17:03:51 -0700240 if (len(updatedGroups)) == 0 {
Rohan Agrawal31f21802020-06-12 05:38:46 +0000241 logger.Debugw(ctx, "nothing-to-update", log.Fields{"device-id": agent.deviceID, "groups": updatedGroups})
Mahir Gunyelfa6ea272020-06-10 17:03:51 -0700242 return coreutils.DoneResponse(), nil
243 }
244
Kent Hagermancba2f302020-07-28 13:37:36 -0400245 device, err := agent.getDeviceReadOnly(ctx)
246 if err != nil {
Maninder9a1bc0d2020-10-26 11:34:02 +0530247 desc = err.Error()
248 agent.logDeviceUpdate(ctx, "updateGroupsToAdapter", nil, nil, operStatus, &desc)
Kent Hagermancba2f302020-07-28 13:37:36 -0400249 return coreutils.DoneResponse(), status.Errorf(codes.Aborted, "%s", err)
250 }
Maninder2195ccc2021-06-23 20:23:01 +0530251
252 if !agent.proceedWithRequest(device) {
253 desc = fmt.Sprintf("deviceId:%s, Cannot complete operation as device deletion is in progress or Reconciling is in progress/failed", device.Id)
254 agent.logDeviceUpdate(ctx, "updateGroupsToAdapter", nil, nil, operStatus, &desc)
255 return coreutils.DoneResponse(), status.Errorf(codes.FailedPrecondition, "%s", desc)
256 }
257
Mahir Gunyelfa6ea272020-06-10 17:03:51 -0700258 if device.OperStatus != voltha.OperStatus_ACTIVE || device.ConnectStatus != voltha.ConnectStatus_REACHABLE || device.AdminState != voltha.AdminState_ENABLED {
Maninder9a1bc0d2020-10-26 11:34:02 +0530259 desc = fmt.Sprintf("invalid device states-oper-%s-connect-%s-admin-%s", device.OperStatus, device.ConnectStatus, device.AdminState)
260 agent.logDeviceUpdate(ctx, "updateGroupsToAdapter", nil, nil, operStatus, &desc)
Mahir Gunyelfa6ea272020-06-10 17:03:51 -0700261 return coreutils.DoneResponse(), status.Errorf(codes.FailedPrecondition, "invalid device states-oper-%s-connect-%s-admin-%s", device.OperStatus, device.ConnectStatus, device.AdminState)
262 }
Maninder2195ccc2021-06-23 20:23:01 +0530263
Mahir Gunyelfa6ea272020-06-10 17:03:51 -0700264 dType, err := agent.adapterMgr.GetDeviceType(ctx, &voltha.ID{Id: device.Type})
265 if err != nil {
Maninder9a1bc0d2020-10-26 11:34:02 +0530266 desc = fmt.Sprintf("non-existent-device-type-%s", device.Type)
267 agent.logDeviceUpdate(ctx, "updateGroupsToAdapter", nil, nil, operStatus, &desc)
Mahir Gunyelfa6ea272020-06-10 17:03:51 -0700268 return coreutils.DoneResponse(), status.Errorf(codes.FailedPrecondition, "non-existent-device-type-%s", device.Type)
269 }
Mahir Gunyelfa6ea272020-06-10 17:03:51 -0700270
Kent Hagermana7c9d792020-07-16 17:39:01 -0400271 groupsToUpdate := make([]*ofp.OfpGroupEntry, 0)
Mahir Gunyelfa6ea272020-06-10 17:03:51 -0700272 for _, group := range updatedGroups {
khenaidoo7585a962021-06-10 16:15:38 -0400273 if groupHandle, have := agent.groupCache.Lock(group.Desc.GroupId); have {
Mahir Gunyelfa6ea272020-06-10 17:03:51 -0700274 // Update the store and cache
275 if err := groupHandle.Update(ctx, group); err != nil {
276 groupHandle.Unlock()
Maninder9a1bc0d2020-10-26 11:34:02 +0530277 desc = err.Error()
278 agent.logDeviceUpdate(ctx, "updateGroupsToAdapter", nil, nil, operStatus, &desc)
Mahir Gunyelfa6ea272020-06-10 17:03:51 -0700279 return coreutils.DoneResponse(), err
280 }
281 groupsToUpdate = append(groupsToUpdate, group)
Mahir Gunyelfa6ea272020-06-10 17:03:51 -0700282 groupHandle.Unlock()
283 }
284 }
285
Rohan Agrawalcf12f202020-08-03 04:42:01 +0000286 subCtx, cancel := context.WithTimeout(log.WithSpanFromContext(context.Background(), ctx), agent.defaultTimeout)
Himani Chawlab4c25912020-11-12 17:16:38 +0530287 subCtx = coreutils.WithRPCMetadataFromContext(subCtx, ctx)
288
Mahir Gunyelfa6ea272020-06-10 17:03:51 -0700289 response := coreutils.NewResponse()
290 // Process bulk flow update differently than incremental update
291 if !dType.AcceptsAddRemoveFlowUpdates {
Kent Hagermana7c9d792020-07-16 17:39:01 -0400292 updatedAllGroups := agent.listDeviceGroups()
293 rpcResponse, err := agent.adapterProxy.UpdateFlowsBulk(subCtx, device, nil, updatedAllGroups, nil)
Mahir Gunyelfa6ea272020-06-10 17:03:51 -0700294 if err != nil {
295 cancel()
Maninder9a1bc0d2020-10-26 11:34:02 +0530296 desc = err.Error()
297 agent.logDeviceUpdate(ctx, "updateGroupsToAdapter", nil, nil, operStatus, &desc)
Mahir Gunyelfa6ea272020-06-10 17:03:51 -0700298 return coreutils.DoneResponse(), err
299 }
Maninder9a1bc0d2020-10-26 11:34:02 +0530300 go agent.waitForAdapterFlowResponse(subCtx, cancel, "updateGroupsToAdapter", rpcResponse, response)
Mahir Gunyelfa6ea272020-06-10 17:03:51 -0700301 } else {
Rohan Agrawal31f21802020-06-12 05:38:46 +0000302 logger.Debugw(ctx, "updating-groups",
Mahir Gunyelfa6ea272020-06-10 17:03:51 -0700303 log.Fields{
304 "device-id": agent.deviceID,
305 "groups-to-update": groupsToUpdate,
306 })
307
308 // Sanity check
309 if (len(groupsToUpdate)) == 0 {
Rohan Agrawal31f21802020-06-12 05:38:46 +0000310 logger.Debugw(ctx, "nothing-to-update", log.Fields{"device-id": agent.deviceID, "groups": groupsToUpdate})
Mahir Gunyelfa6ea272020-06-10 17:03:51 -0700311 cancel()
312 return coreutils.DoneResponse(), nil
313 }
314
315 flowChanges := &ofp.FlowChanges{
316 ToAdd: &voltha.Flows{Items: []*ofp.OfpFlowStats{}},
317 ToRemove: &voltha.Flows{Items: []*ofp.OfpFlowStats{}},
318 }
319 groupChanges := &ofp.FlowGroupChanges{
320 ToAdd: &voltha.FlowGroups{Items: []*ofp.OfpGroupEntry{}},
321 ToRemove: &voltha.FlowGroups{Items: []*ofp.OfpGroupEntry{}},
322 ToUpdate: &voltha.FlowGroups{Items: groupsToUpdate},
323 }
324 rpcResponse, err := agent.adapterProxy.UpdateFlowsIncremental(subCtx, device, flowChanges, groupChanges, flowMetadata)
325 if err != nil {
326 cancel()
Maninder9a1bc0d2020-10-26 11:34:02 +0530327 desc = err.Error()
328 agent.logDeviceUpdate(ctx, "updateGroupsToAdapter", nil, nil, operStatus, &desc)
Mahir Gunyelfa6ea272020-06-10 17:03:51 -0700329 return coreutils.DoneResponse(), err
330 }
Maninder9a1bc0d2020-10-26 11:34:02 +0530331 go agent.waitForAdapterFlowResponse(subCtx, cancel, "updateGroupsToAdapter", rpcResponse, response)
Mahir Gunyelfa6ea272020-06-10 17:03:51 -0700332 }
333
Maninder9a1bc0d2020-10-26 11:34:02 +0530334 operStatus.Code = common.OperationResp_OPERATION_IN_PROGRESS
335 agent.logDeviceUpdate(ctx, "updateGroupsToAdapter", nil, nil, operStatus, &desc)
Mahir Gunyelfa6ea272020-06-10 17:03:51 -0700336 return response, nil
337}