khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 1 | /* |
| 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 | */ |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 16 | |
Kent Hagerman | 2b21604 | 2020-04-03 18:28:56 -0400 | [diff] [blame] | 17 | package device |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 18 | |
| 19 | import ( |
| 20 | "context" |
| 21 | "errors" |
Kent Hagerman | 45a13e4 | 2020-04-13 12:23:50 -0400 | [diff] [blame] | 22 | "io" |
Kent Hagerman | fa9d6d4 | 2020-05-25 11:49:40 -0400 | [diff] [blame] | 23 | "strconv" |
David Bainbridge | d1afd66 | 2020-03-26 18:27:41 -0700 | [diff] [blame] | 24 | "strings" |
| 25 | "sync" |
| 26 | "time" |
| 27 | |
Kent Hagerman | 433a31a | 2020-05-20 19:04:48 -0400 | [diff] [blame] | 28 | "github.com/golang/protobuf/ptypes/empty" |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 29 | "github.com/opencord/voltha-go/db/model" |
Kent Hagerman | 433a31a | 2020-05-20 19:04:48 -0400 | [diff] [blame] | 30 | "github.com/opencord/voltha-go/rw_core/core/device/event" |
| 31 | "github.com/opencord/voltha-go/rw_core/utils" |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 32 | "github.com/opencord/voltha-lib-go/v7/pkg/log" |
serkant.uluderya | ad1e683 | 2020-12-17 21:08:38 +0300 | [diff] [blame] | 33 | "github.com/opencord/voltha-lib-go/v7/pkg/probe" |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 34 | "github.com/opencord/voltha-protos/v5/go/openflow_13" |
| 35 | "github.com/opencord/voltha-protos/v5/go/voltha" |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 36 | "google.golang.org/grpc/codes" |
| 37 | "google.golang.org/grpc/status" |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 38 | ) |
| 39 | |
Kent Hagerman | 2b21604 | 2020-04-03 18:28:56 -0400 | [diff] [blame] | 40 | // LogicalManager represent logical device manager attributes |
| 41 | type LogicalManager struct { |
Kent Hagerman | 45a13e4 | 2020-04-13 12:23:50 -0400 | [diff] [blame] | 42 | *event.Manager |
khenaidoo | 4c9e559 | 2019-09-09 16:20:41 -0400 | [diff] [blame] | 43 | logicalDeviceAgents sync.Map |
Kent Hagerman | 2b21604 | 2020-04-03 18:28:56 -0400 | [diff] [blame] | 44 | deviceMgr *Manager |
Mahir Gunyel | 03de0d3 | 2020-06-03 01:36:59 -0700 | [diff] [blame] | 45 | dbPath *model.Path |
Kent Hagerman | f5a6735 | 2020-04-30 15:15:26 -0400 | [diff] [blame] | 46 | ldProxy *model.Proxy |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 47 | internalTimeout time.Duration |
khenaidoo | 4c9e559 | 2019-09-09 16:20:41 -0400 | [diff] [blame] | 48 | logicalDevicesLoadingLock sync.RWMutex |
| 49 | logicalDeviceLoadingInProgress map[string][]chan int |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 50 | } |
| 51 | |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 52 | func (ldMgr *LogicalManager) Start(ctx context.Context, serviceName string) { |
khenaidoo | 7585a96 | 2021-06-10 16:15:38 -0400 | [diff] [blame] | 53 | logger.Info(ctx, "starting-logical-device-manager") |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 54 | probe.UpdateStatusFromContext(ctx, serviceName, probe.ServiceStatusPreparing) |
khenaidoo | 7585a96 | 2021-06-10 16:15:38 -0400 | [diff] [blame] | 55 | |
| 56 | // Load all the logical devices from the dB |
| 57 | var logicalDevices []*voltha.LogicalDevice |
| 58 | if err := ldMgr.ldProxy.List(ctx, &logicalDevices); err != nil { |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 59 | logger.Fatalw(ctx, "failed-to-list-logical-devices-from-cluster-proxy", log.Fields{"error": err, "service-name": serviceName}) |
khenaidoo | 7585a96 | 2021-06-10 16:15:38 -0400 | [diff] [blame] | 60 | } |
| 61 | for _, lDevice := range logicalDevices { |
| 62 | // Create an agent for each device |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 63 | agent := newLogicalAgent(ctx, lDevice.Id, "", "", ldMgr, ldMgr.deviceMgr, ldMgr.dbPath, ldMgr.ldProxy, ldMgr.internalTimeout) |
khenaidoo | 7585a96 | 2021-06-10 16:15:38 -0400 | [diff] [blame] | 64 | if err := agent.start(ctx, true, lDevice); err != nil { |
| 65 | logger.Warnw(ctx, "failure-starting-logical-agent", log.Fields{"logical-device-id": lDevice.Id}) |
| 66 | } else { |
| 67 | ldMgr.logicalDeviceAgents.Store(agent.logicalDeviceID, agent) |
| 68 | } |
| 69 | } |
| 70 | |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 71 | probe.UpdateStatusFromContext(ctx, serviceName, probe.ServiceStatusRunning) |
khenaidoo | 7585a96 | 2021-06-10 16:15:38 -0400 | [diff] [blame] | 72 | logger.Info(ctx, "logical-device-manager-started") |
| 73 | } |
| 74 | |
Kent Hagerman | 2b21604 | 2020-04-03 18:28:56 -0400 | [diff] [blame] | 75 | func (ldMgr *LogicalManager) addLogicalDeviceAgentToMap(agent *LogicalAgent) { |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 76 | if _, exist := ldMgr.logicalDeviceAgents.Load(agent.logicalDeviceID); !exist { |
| 77 | ldMgr.logicalDeviceAgents.Store(agent.logicalDeviceID, agent) |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 78 | } |
| 79 | } |
| 80 | |
khenaidoo | 8c3303d | 2019-02-13 14:59:39 -0500 | [diff] [blame] | 81 | // getLogicalDeviceAgent returns the logical device agent. If the device is not in memory then the device will |
| 82 | // be loaded from dB and a logical device agent created to managed it. |
Kent Hagerman | 2b21604 | 2020-04-03 18:28:56 -0400 | [diff] [blame] | 83 | func (ldMgr *LogicalManager) getLogicalDeviceAgent(ctx context.Context, logicalDeviceID string) *LogicalAgent { |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 84 | logger.Debugw(ctx, "get-logical-device-agent", log.Fields{"logical-device-id": logicalDeviceID}) |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 85 | agent, ok := ldMgr.logicalDeviceAgents.Load(logicalDeviceID) |
| 86 | if ok { |
Kent Hagerman | 2b21604 | 2020-04-03 18:28:56 -0400 | [diff] [blame] | 87 | lda := agent.(*LogicalAgent) |
khenaidoo | 93d5a3d | 2020-01-15 12:37:05 -0500 | [diff] [blame] | 88 | if lda.logicalDevice == nil { |
| 89 | // This can happen when an agent for the logical device has been created but the logical device |
| 90 | // itself is not ready for action as it is waiting for switch and port capabilities from the |
| 91 | // relevant adapter. In such a case prevent any request aimed at that logical device. |
Himani Chawla | b4c2591 | 2020-11-12 17:16:38 +0530 | [diff] [blame] | 92 | logger.Debugf(ctx, "logical-device-%s-is-not-ready-to-serve-requests", logicalDeviceID) |
khenaidoo | 93d5a3d | 2020-01-15 12:37:05 -0500 | [diff] [blame] | 93 | return nil |
| 94 | } |
| 95 | return lda |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 96 | } |
| 97 | // Try to load into memory - loading will also create the logical device agent |
npujar | 467fe75 | 2020-01-16 20:17:45 +0530 | [diff] [blame] | 98 | if err := ldMgr.load(ctx, logicalDeviceID); err == nil { |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 99 | if agent, ok = ldMgr.logicalDeviceAgents.Load(logicalDeviceID); ok { |
Kent Hagerman | 2b21604 | 2020-04-03 18:28:56 -0400 | [diff] [blame] | 100 | return agent.(*LogicalAgent) |
khenaidoo | 8c3303d | 2019-02-13 14:59:39 -0500 | [diff] [blame] | 101 | } |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 102 | } |
| 103 | return nil |
| 104 | } |
| 105 | |
Kent Hagerman | 2b21604 | 2020-04-03 18:28:56 -0400 | [diff] [blame] | 106 | func (ldMgr *LogicalManager) deleteLogicalDeviceAgent(logicalDeviceID string) { |
Andrea Campanella | 832cff6 | 2021-11-05 17:05:18 +0100 | [diff] [blame] | 107 | logger.Debugw(context.Background(), "delete-logical-device-agent", log.Fields{"logical-device-id": logicalDeviceID}) |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 108 | ldMgr.logicalDeviceAgents.Delete(logicalDeviceID) |
khenaidoo | 92e62c5 | 2018-10-03 14:02:54 -0400 | [diff] [blame] | 109 | } |
| 110 | |
khenaidoo | 8c3303d | 2019-02-13 14:59:39 -0500 | [diff] [blame] | 111 | // GetLogicalDevice provides a cloned most up to date logical device. If device is not in memory |
| 112 | // it will be fetched from the dB |
Kent Hagerman | 45a13e4 | 2020-04-13 12:23:50 -0400 | [diff] [blame] | 113 | func (ldMgr *LogicalManager) GetLogicalDevice(ctx context.Context, id *voltha.ID) (*voltha.LogicalDevice, error) { |
Himani Chawla | b4c2591 | 2020-11-12 17:16:38 +0530 | [diff] [blame] | 114 | ctx = utils.WithRPCMetadataContext(ctx, "GetLogicalDevice") |
| 115 | logger.Debugw(ctx, "get-logical-device", log.Fields{"logical-device-id": id}) |
Kent Hagerman | 45a13e4 | 2020-04-13 12:23:50 -0400 | [diff] [blame] | 116 | if agent := ldMgr.getLogicalDeviceAgent(ctx, id.Id); agent != nil { |
Kent Hagerman | cba2f30 | 2020-07-28 13:37:36 -0400 | [diff] [blame] | 117 | return agent.GetLogicalDeviceReadOnly(ctx) |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 118 | } |
| 119 | return nil, status.Errorf(codes.NotFound, "%s", id) |
| 120 | } |
| 121 | |
Kent Hagerman | 2b21604 | 2020-04-03 18:28:56 -0400 | [diff] [blame] | 122 | //ListLogicalDevices returns the list of all logical devices |
Kent Hagerman | 45a13e4 | 2020-04-13 12:23:50 -0400 | [diff] [blame] | 123 | func (ldMgr *LogicalManager) ListLogicalDevices(ctx context.Context, _ *empty.Empty) (*voltha.LogicalDevices, error) { |
Himani Chawla | b4c2591 | 2020-11-12 17:16:38 +0530 | [diff] [blame] | 124 | ctx = utils.WithRPCMetadataContext(ctx, "ListLogicalDevices") |
| 125 | logger.Debug(ctx, "list-all-logical-devices") |
Kent Hagerman | 4f355f5 | 2020-03-30 16:01:33 -0400 | [diff] [blame] | 126 | |
| 127 | var logicalDevices []*voltha.LogicalDevice |
Esin Karaman | a4e4e00 | 2021-03-02 10:42:16 +0000 | [diff] [blame] | 128 | ldMgr.logicalDeviceAgents.Range(func(key, value interface{}) bool { |
| 129 | if ld, err := value.(*LogicalAgent).GetLogicalDeviceReadOnly(ctx); err == nil { |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 130 | if ld != nil { |
| 131 | logicalDevices = append(logicalDevices, ld) |
| 132 | } |
Esin Karaman | a4e4e00 | 2021-03-02 10:42:16 +0000 | [diff] [blame] | 133 | } else { |
| 134 | logger.Errorw(ctx, "unable-to-get-logical-device", log.Fields{"err": err}) |
| 135 | } |
| 136 | return true |
| 137 | }) |
khenaidoo | 7585a96 | 2021-06-10 16:15:38 -0400 | [diff] [blame] | 138 | logger.Debugw(ctx, "list-all-logical-devices", log.Fields{"num-logical-devices": len(logicalDevices)}) |
| 139 | |
Kent Hagerman | 4f355f5 | 2020-03-30 16:01:33 -0400 | [diff] [blame] | 140 | return &voltha.LogicalDevices{Items: logicalDevices}, nil |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 141 | } |
| 142 | |
Kent Hagerman | 2b21604 | 2020-04-03 18:28:56 -0400 | [diff] [blame] | 143 | func (ldMgr *LogicalManager) createLogicalDevice(ctx context.Context, device *voltha.Device) (*string, error) { |
divyadesai | cb8b59d | 2020-08-18 09:55:47 +0000 | [diff] [blame] | 144 | logger.Debugw(ctx, "creating-logical-device", log.Fields{"device-id": device.Id}) |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 145 | // Sanity check |
| 146 | if !device.Root { |
khenaidoo | 2c6a099 | 2019-04-29 13:46:56 -0400 | [diff] [blame] | 147 | return nil, errors.New("device-not-root") |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 148 | } |
| 149 | |
| 150 | // Create a logical device agent - the logical device Id is based on the mac address of the device |
| 151 | // For now use the serial number - it may contain any combination of alphabetic characters and numbers, |
| 152 | // with length varying from eight characters to a maximum of 14 characters. Mac Address is part of oneof |
| 153 | // in the Device model. May need to be moved out. |
Kent Hagerman | 2b21604 | 2020-04-03 18:28:56 -0400 | [diff] [blame] | 154 | id := utils.CreateLogicalDeviceID() |
David Bainbridge | d1afd66 | 2020-03-26 18:27:41 -0700 | [diff] [blame] | 155 | sn := strings.Replace(device.MacAddress, ":", "", -1) |
khenaidoo | 92e62c5 | 2018-10-03 14:02:54 -0400 | [diff] [blame] | 156 | if id == "" { |
divyadesai | cb8b59d | 2020-08-18 09:55:47 +0000 | [diff] [blame] | 157 | logger.Errorw(ctx, "mac-address-not-set", log.Fields{"device-id": device.Id, "serial-number": sn}) |
khenaidoo | 92e62c5 | 2018-10-03 14:02:54 -0400 | [diff] [blame] | 158 | return nil, errors.New("mac-address-not-set") |
| 159 | } |
David Bainbridge | d1afd66 | 2020-03-26 18:27:41 -0700 | [diff] [blame] | 160 | |
divyadesai | cb8b59d | 2020-08-18 09:55:47 +0000 | [diff] [blame] | 161 | logger.Debugw(ctx, "logical-device-id", log.Fields{"logical-device-id": id}) |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 162 | |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 163 | agent := newLogicalAgent(ctx, id, sn, device.Id, ldMgr, ldMgr.deviceMgr, ldMgr.dbPath, ldMgr.ldProxy, ldMgr.internalTimeout) |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 164 | ldMgr.addLogicalDeviceAgentToMap(agent) |
khenaidoo | ad06fd7 | 2019-10-28 12:26:05 -0400 | [diff] [blame] | 165 | |
| 166 | // Update the root device with the logical device Id reference |
npujar | 467fe75 | 2020-01-16 20:17:45 +0530 | [diff] [blame] | 167 | if err := ldMgr.deviceMgr.setParentID(ctx, device, id); err != nil { |
divyadesai | cb8b59d | 2020-08-18 09:55:47 +0000 | [diff] [blame] | 168 | logger.Errorw(ctx, "failed-setting-parent-id", log.Fields{"logical-device-id": id, "device-id": device.Id}) |
khenaidoo | ad06fd7 | 2019-10-28 12:26:05 -0400 | [diff] [blame] | 169 | return nil, err |
| 170 | } |
| 171 | |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 172 | go func() { |
Kent Hagerman | f5a6735 | 2020-04-30 15:15:26 -0400 | [diff] [blame] | 173 | //TODO: either wait for the agent to be started before returning, or |
| 174 | // implement locks in the agent to ensure request are not processed before start() is complete |
Himani Chawla | b4c2591 | 2020-11-12 17:16:38 +0530 | [diff] [blame] | 175 | ldCtx := utils.WithSpanAndRPCMetadataFromContext(ctx) |
khenaidoo | 7585a96 | 2021-06-10 16:15:38 -0400 | [diff] [blame] | 176 | err := agent.start(ldCtx, false, nil) |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 177 | if err != nil { |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 178 | logger.Errorw(ctx, "unable-to-create-the-logical-device", log.Fields{"error": err}) |
khenaidoo | 442e7c7 | 2020-03-10 16:13:48 -0400 | [diff] [blame] | 179 | ldMgr.deleteLogicalDeviceAgent(id) |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 180 | } |
| 181 | }() |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 182 | |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 183 | logger.Debug(ctx, "creating-logical-device-ends") |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 184 | return &id, nil |
| 185 | } |
| 186 | |
khenaidoo | 6d62c00 | 2019-05-15 21:57:03 -0400 | [diff] [blame] | 187 | // stopManagingLogicalDeviceWithDeviceId stops the management of the logical device. This implies removal of any |
| 188 | // reference of this logical device in cache. The device Id is passed as param because the logical device may already |
| 189 | // have been removed from the model. This function returns the logical device Id if found |
Kent Hagerman | 2b21604 | 2020-04-03 18:28:56 -0400 | [diff] [blame] | 190 | func (ldMgr *LogicalManager) stopManagingLogicalDeviceWithDeviceID(ctx context.Context, id string) string { |
divyadesai | cb8b59d | 2020-08-18 09:55:47 +0000 | [diff] [blame] | 191 | logger.Infow(ctx, "stop-managing-logical-device", log.Fields{"device-id": id}) |
khenaidoo | 6d62c00 | 2019-05-15 21:57:03 -0400 | [diff] [blame] | 192 | // Go over the list of logical device agents to find the one which has rootDeviceId as id |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 193 | var ldID = "" |
Stephane Barbarie | ef6650d | 2019-07-18 12:15:09 -0400 | [diff] [blame] | 194 | ldMgr.logicalDeviceAgents.Range(func(key, value interface{}) bool { |
Kent Hagerman | 2b21604 | 2020-04-03 18:28:56 -0400 | [diff] [blame] | 195 | ldAgent := value.(*LogicalAgent) |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 196 | if ldAgent.rootDeviceID == id { |
divyadesai | cb8b59d | 2020-08-18 09:55:47 +0000 | [diff] [blame] | 197 | logger.Infow(ctx, "stopping-logical-device-agent", log.Fields{"logical-device-id": key}) |
npujar | 467fe75 | 2020-01-16 20:17:45 +0530 | [diff] [blame] | 198 | if err := ldAgent.stop(ctx); err != nil { |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 199 | logger.Errorw(ctx, "failed-to-stop-LDAgent", log.Fields{"error": err}) |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 200 | return false |
| 201 | } |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 202 | ldID = key.(string) |
| 203 | ldMgr.logicalDeviceAgents.Delete(ldID) |
khenaidoo | 6d62c00 | 2019-05-15 21:57:03 -0400 | [diff] [blame] | 204 | } |
Stephane Barbarie | ef6650d | 2019-07-18 12:15:09 -0400 | [diff] [blame] | 205 | return true |
| 206 | }) |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 207 | return ldID |
khenaidoo | 6d62c00 | 2019-05-15 21:57:03 -0400 | [diff] [blame] | 208 | } |
| 209 | |
| 210 | //getLogicalDeviceFromModel retrieves the logical device data from the model. |
Kent Hagerman | 2b21604 | 2020-04-03 18:28:56 -0400 | [diff] [blame] | 211 | func (ldMgr *LogicalManager) getLogicalDeviceFromModel(ctx context.Context, lDeviceID string) (*voltha.LogicalDevice, error) { |
Kent Hagerman | 4f355f5 | 2020-03-30 16:01:33 -0400 | [diff] [blame] | 212 | logicalDevice := &voltha.LogicalDevice{} |
Kent Hagerman | f5a6735 | 2020-04-30 15:15:26 -0400 | [diff] [blame] | 213 | if have, err := ldMgr.ldProxy.Get(ctx, lDeviceID, logicalDevice); err != nil { |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 214 | logger.Errorw(ctx, "failed-to-get-logical-devices-from-cluster-proxy", log.Fields{"error": err}) |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 215 | return nil, err |
Kent Hagerman | 4f355f5 | 2020-03-30 16:01:33 -0400 | [diff] [blame] | 216 | } else if !have { |
| 217 | return nil, status.Error(codes.NotFound, lDeviceID) |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 218 | } |
Kent Hagerman | 4f355f5 | 2020-03-30 16:01:33 -0400 | [diff] [blame] | 219 | |
| 220 | return logicalDevice, nil |
khenaidoo | 6d62c00 | 2019-05-15 21:57:03 -0400 | [diff] [blame] | 221 | } |
| 222 | |
khenaidoo | 297cd25 | 2019-02-07 22:10:23 -0500 | [diff] [blame] | 223 | // load loads a logical device manager in memory |
Kent Hagerman | 2b21604 | 2020-04-03 18:28:56 -0400 | [diff] [blame] | 224 | func (ldMgr *LogicalManager) load(ctx context.Context, lDeviceID string) error { |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 225 | if lDeviceID == "" { |
khenaidoo | 4c9e559 | 2019-09-09 16:20:41 -0400 | [diff] [blame] | 226 | return nil |
khenaidoo | 297cd25 | 2019-02-07 22:10:23 -0500 | [diff] [blame] | 227 | } |
khenaidoo | 4c9e559 | 2019-09-09 16:20:41 -0400 | [diff] [blame] | 228 | // Add a lock to prevent two concurrent calls from loading the same device twice |
| 229 | ldMgr.logicalDevicesLoadingLock.Lock() |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 230 | if _, exist := ldMgr.logicalDeviceLoadingInProgress[lDeviceID]; !exist { |
| 231 | if ldAgent, _ := ldMgr.logicalDeviceAgents.Load(lDeviceID); ldAgent == nil { |
| 232 | ldMgr.logicalDeviceLoadingInProgress[lDeviceID] = []chan int{make(chan int, 1)} |
khenaidoo | 4c9e559 | 2019-09-09 16:20:41 -0400 | [diff] [blame] | 233 | ldMgr.logicalDevicesLoadingLock.Unlock() |
npujar | 467fe75 | 2020-01-16 20:17:45 +0530 | [diff] [blame] | 234 | if _, err := ldMgr.getLogicalDeviceFromModel(ctx, lDeviceID); err == nil { |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 235 | logger.Debugw(ctx, "loading-logical-device", log.Fields{"lDeviceId": lDeviceID}) |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 236 | agent := newLogicalAgent(ctx, lDeviceID, "", "", ldMgr, ldMgr.deviceMgr, ldMgr.dbPath, ldMgr.ldProxy, ldMgr.internalTimeout) |
khenaidoo | 7585a96 | 2021-06-10 16:15:38 -0400 | [diff] [blame] | 237 | if err := agent.start(ctx, true, nil); err != nil { |
khenaidoo | 442e7c7 | 2020-03-10 16:13:48 -0400 | [diff] [blame] | 238 | return err |
khenaidoo | 4c9e559 | 2019-09-09 16:20:41 -0400 | [diff] [blame] | 239 | } |
khenaidoo | 442e7c7 | 2020-03-10 16:13:48 -0400 | [diff] [blame] | 240 | ldMgr.logicalDeviceAgents.Store(agent.logicalDeviceID, agent) |
khenaidoo | 4c9e559 | 2019-09-09 16:20:41 -0400 | [diff] [blame] | 241 | } else { |
Himani Chawla | b4c2591 | 2020-11-12 17:16:38 +0530 | [diff] [blame] | 242 | logger.Debugw(ctx, "logical-device-not-in-model", log.Fields{"logical-device-id": lDeviceID}) |
khenaidoo | 4c9e559 | 2019-09-09 16:20:41 -0400 | [diff] [blame] | 243 | } |
| 244 | // announce completion of task to any number of waiting channels |
| 245 | ldMgr.logicalDevicesLoadingLock.Lock() |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 246 | if v, ok := ldMgr.logicalDeviceLoadingInProgress[lDeviceID]; ok { |
khenaidoo | 4c9e559 | 2019-09-09 16:20:41 -0400 | [diff] [blame] | 247 | for _, ch := range v { |
| 248 | close(ch) |
| 249 | } |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 250 | delete(ldMgr.logicalDeviceLoadingInProgress, lDeviceID) |
khenaidoo | 4c9e559 | 2019-09-09 16:20:41 -0400 | [diff] [blame] | 251 | } |
| 252 | ldMgr.logicalDevicesLoadingLock.Unlock() |
| 253 | } else { |
| 254 | ldMgr.logicalDevicesLoadingLock.Unlock() |
| 255 | } |
| 256 | } else { |
| 257 | ch := make(chan int, 1) |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 258 | ldMgr.logicalDeviceLoadingInProgress[lDeviceID] = append(ldMgr.logicalDeviceLoadingInProgress[lDeviceID], ch) |
khenaidoo | 4c9e559 | 2019-09-09 16:20:41 -0400 | [diff] [blame] | 259 | ldMgr.logicalDevicesLoadingLock.Unlock() |
| 260 | // Wait for the channel to be closed, implying the process loading this device is done. |
| 261 | <-ch |
| 262 | } |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 263 | if _, exist := ldMgr.logicalDeviceAgents.Load(lDeviceID); exist { |
khenaidoo | 4c9e559 | 2019-09-09 16:20:41 -0400 | [diff] [blame] | 264 | return nil |
| 265 | } |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 266 | return status.Errorf(codes.Aborted, "Error loading logical device %s", lDeviceID) |
khenaidoo | 297cd25 | 2019-02-07 22:10:23 -0500 | [diff] [blame] | 267 | } |
| 268 | |
Kent Hagerman | 2b21604 | 2020-04-03 18:28:56 -0400 | [diff] [blame] | 269 | func (ldMgr *LogicalManager) deleteLogicalDevice(ctx context.Context, device *voltha.Device) error { |
Andrea Campanella | 77dde84 | 2021-05-27 15:31:54 +0200 | [diff] [blame] | 270 | logger.Infow(ctx, "deleting-logical-device", log.Fields{"device-id": device.Id}) |
khenaidoo | 92e62c5 | 2018-10-03 14:02:54 -0400 | [diff] [blame] | 271 | // Sanity check |
| 272 | if !device.Root { |
khenaidoo | 2c6a099 | 2019-04-29 13:46:56 -0400 | [diff] [blame] | 273 | return errors.New("device-not-root") |
khenaidoo | 92e62c5 | 2018-10-03 14:02:54 -0400 | [diff] [blame] | 274 | } |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 275 | logDeviceID := device.ParentId |
npujar | 467fe75 | 2020-01-16 20:17:45 +0530 | [diff] [blame] | 276 | if agent := ldMgr.getLogicalDeviceAgent(ctx, logDeviceID); agent != nil { |
khenaidoo | 92e62c5 | 2018-10-03 14:02:54 -0400 | [diff] [blame] | 277 | // Stop the logical device agent |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 278 | if err := agent.stop(ctx); err != nil { |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 279 | logger.Errorw(ctx, "failed-to-stop-agent", log.Fields{"error": err}) |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 280 | return err |
| 281 | } |
khenaidoo | 92e62c5 | 2018-10-03 14:02:54 -0400 | [diff] [blame] | 282 | //Remove the logical device agent from the Map |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 283 | ldMgr.deleteLogicalDeviceAgent(logDeviceID) |
Andrea Campanella | 77dde84 | 2021-05-27 15:31:54 +0200 | [diff] [blame] | 284 | ldMgr.SendDeviceDeletionEvent(ctx, logDeviceID) |
Andrea Campanella | 832cff6 | 2021-11-05 17:05:18 +0100 | [diff] [blame] | 285 | } else { |
| 286 | logger.Warnw(ctx, "no-logical-device-agent-on-deletion", log.Fields{"device-id": logDeviceID}) |
khenaidoo | 92e62c5 | 2018-10-03 14:02:54 -0400 | [diff] [blame] | 287 | } |
Andrea Campanella | 77dde84 | 2021-05-27 15:31:54 +0200 | [diff] [blame] | 288 | logger.Debugw(ctx, "deleting-logical-device-ends", log.Fields{"device-id": device.Id}) |
khenaidoo | 92e62c5 | 2018-10-03 14:02:54 -0400 | [diff] [blame] | 289 | return nil |
| 290 | } |
| 291 | |
Kent Hagerman | 2b21604 | 2020-04-03 18:28:56 -0400 | [diff] [blame] | 292 | func (ldMgr *LogicalManager) getLogicalDeviceID(ctx context.Context, device *voltha.Device) (*string, error) { |
khenaidoo | 92e62c5 | 2018-10-03 14:02:54 -0400 | [diff] [blame] | 293 | // Device can either be a parent or a child device |
| 294 | if device.Root { |
| 295 | // Parent device. The ID of a parent device is the logical device ID |
| 296 | return &device.ParentId, nil |
| 297 | } |
| 298 | // Device is child device |
| 299 | // retrieve parent device using child device ID |
Kent Hagerman | fa9d6d4 | 2020-05-25 11:49:40 -0400 | [diff] [blame] | 300 | // TODO: return (string, have) instead of *string |
| 301 | // also: If not root device, just return device.parentID instead of loading the parent device. |
npujar | 467fe75 | 2020-01-16 20:17:45 +0530 | [diff] [blame] | 302 | if parentDevice := ldMgr.deviceMgr.getParentDevice(ctx, device); parentDevice != nil { |
khenaidoo | 92e62c5 | 2018-10-03 14:02:54 -0400 | [diff] [blame] | 303 | return &parentDevice.ParentId, nil |
| 304 | } |
| 305 | return nil, status.Errorf(codes.NotFound, "%s", device.Id) |
| 306 | } |
| 307 | |
Kent Hagerman | 2b21604 | 2020-04-03 18:28:56 -0400 | [diff] [blame] | 308 | func (ldMgr *LogicalManager) getLogicalDeviceIDFromDeviceID(ctx context.Context, deviceID string) (*string, error) { |
khenaidoo | 3ab3488 | 2019-05-02 21:33:30 -0400 | [diff] [blame] | 309 | // Get the device |
| 310 | var device *voltha.Device |
| 311 | var err error |
Kent Hagerman | cba2f30 | 2020-07-28 13:37:36 -0400 | [diff] [blame] | 312 | if device, err = ldMgr.deviceMgr.getDeviceReadOnly(ctx, deviceID); err != nil { |
khenaidoo | 3ab3488 | 2019-05-02 21:33:30 -0400 | [diff] [blame] | 313 | return nil, err |
| 314 | } |
npujar | 467fe75 | 2020-01-16 20:17:45 +0530 | [diff] [blame] | 315 | return ldMgr.getLogicalDeviceID(ctx, device) |
khenaidoo | 3ab3488 | 2019-05-02 21:33:30 -0400 | [diff] [blame] | 316 | } |
| 317 | |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 318 | // ListLogicalDeviceFlows returns the flows of logical device |
Kent Hagerman | 45a13e4 | 2020-04-13 12:23:50 -0400 | [diff] [blame] | 319 | func (ldMgr *LogicalManager) ListLogicalDeviceFlows(ctx context.Context, id *voltha.ID) (*openflow_13.Flows, error) { |
Himani Chawla | b4c2591 | 2020-11-12 17:16:38 +0530 | [diff] [blame] | 320 | ctx = utils.WithRPCMetadataContext(ctx, "ListLogicalDeviceFlows") |
| 321 | logger.Debugw(ctx, "list-logical-device-flows", log.Fields{"logical-device-id": id.Id}) |
Kent Hagerman | 433a31a | 2020-05-20 19:04:48 -0400 | [diff] [blame] | 322 | agent := ldMgr.getLogicalDeviceAgent(ctx, id.Id) |
| 323 | if agent == nil { |
| 324 | return nil, status.Errorf(codes.NotFound, "%s", id.Id) |
khenaidoo | dd23717 | 2019-05-27 16:37:17 -0400 | [diff] [blame] | 325 | } |
Kent Hagerman | 433a31a | 2020-05-20 19:04:48 -0400 | [diff] [blame] | 326 | |
| 327 | flows := agent.listLogicalDeviceFlows() |
| 328 | ctr, ret := 0, make([]*openflow_13.OfpFlowStats, len(flows)) |
| 329 | for _, flow := range flows { |
| 330 | ret[ctr] = flow |
| 331 | ctr++ |
| 332 | } |
khenaidoo | 7585a96 | 2021-06-10 16:15:38 -0400 | [diff] [blame] | 333 | logger.Debugw(ctx, "list-logical-device-flows", log.Fields{"logical-device-id": id.Id, "num-flows": len(flows)}) |
Kent Hagerman | 433a31a | 2020-05-20 19:04:48 -0400 | [diff] [blame] | 334 | return &openflow_13.Flows{Items: ret}, nil |
khenaidoo | dd23717 | 2019-05-27 16:37:17 -0400 | [diff] [blame] | 335 | } |
| 336 | |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 337 | // ListLogicalDeviceFlowGroups returns logical device flow groups |
Kent Hagerman | 45a13e4 | 2020-04-13 12:23:50 -0400 | [diff] [blame] | 338 | func (ldMgr *LogicalManager) ListLogicalDeviceFlowGroups(ctx context.Context, id *voltha.ID) (*openflow_13.FlowGroups, error) { |
Himani Chawla | b4c2591 | 2020-11-12 17:16:38 +0530 | [diff] [blame] | 339 | ctx = utils.WithRPCMetadataContext(ctx, "ListLogicalDeviceFlowGroups") |
| 340 | logger.Debugw(ctx, "list-logical-device-flow-groups", log.Fields{"logical-device-id": id.Id}) |
Kent Hagerman | 433a31a | 2020-05-20 19:04:48 -0400 | [diff] [blame] | 341 | agent := ldMgr.getLogicalDeviceAgent(ctx, id.Id) |
| 342 | if agent == nil { |
| 343 | return nil, status.Errorf(codes.NotFound, "%s", id.Id) |
khenaidoo | dd23717 | 2019-05-27 16:37:17 -0400 | [diff] [blame] | 344 | } |
Kent Hagerman | 433a31a | 2020-05-20 19:04:48 -0400 | [diff] [blame] | 345 | |
| 346 | groups := agent.listLogicalDeviceGroups() |
| 347 | ctr, ret := 0, make([]*openflow_13.OfpGroupEntry, len(groups)) |
| 348 | for _, group := range groups { |
| 349 | ret[ctr] = group |
| 350 | ctr++ |
| 351 | } |
khenaidoo | 7585a96 | 2021-06-10 16:15:38 -0400 | [diff] [blame] | 352 | logger.Debugw(ctx, "list-logical-device-flow-groups", log.Fields{"logical-device-id": id.Id, "num-groups": len(groups)}) |
Kent Hagerman | 433a31a | 2020-05-20 19:04:48 -0400 | [diff] [blame] | 353 | return &openflow_13.FlowGroups{Items: ret}, nil |
khenaidoo | dd23717 | 2019-05-27 16:37:17 -0400 | [diff] [blame] | 354 | } |
| 355 | |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 356 | // ListLogicalDevicePorts returns logical device ports |
Kent Hagerman | 45a13e4 | 2020-04-13 12:23:50 -0400 | [diff] [blame] | 357 | func (ldMgr *LogicalManager) ListLogicalDevicePorts(ctx context.Context, id *voltha.ID) (*voltha.LogicalPorts, error) { |
Himani Chawla | b4c2591 | 2020-11-12 17:16:38 +0530 | [diff] [blame] | 358 | ctx = utils.WithRPCMetadataContext(ctx, "ListLogicalDevicePorts") |
| 359 | logger.Debugw(ctx, "list-logical-device-ports", log.Fields{"logical-device-id": id.Id}) |
Kent Hagerman | fa9d6d4 | 2020-05-25 11:49:40 -0400 | [diff] [blame] | 360 | agent := ldMgr.getLogicalDeviceAgent(ctx, id.Id) |
| 361 | if agent == nil { |
| 362 | return nil, status.Errorf(codes.NotFound, "%s", id.Id) |
khenaidoo | 19d7b63 | 2018-10-30 10:49:50 -0400 | [diff] [blame] | 363 | } |
Kent Hagerman | fa9d6d4 | 2020-05-25 11:49:40 -0400 | [diff] [blame] | 364 | |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 365 | ports := agent.listLogicalDevicePorts(ctx) |
Kent Hagerman | fa9d6d4 | 2020-05-25 11:49:40 -0400 | [diff] [blame] | 366 | ctr, ret := 0, make([]*voltha.LogicalPort, len(ports)) |
| 367 | for _, port := range ports { |
| 368 | ret[ctr] = port |
| 369 | ctr++ |
| 370 | } |
khenaidoo | 7585a96 | 2021-06-10 16:15:38 -0400 | [diff] [blame] | 371 | logger.Debugw(ctx, "list-logical-device-ports", log.Fields{"logical-device-id": id.Id, "num-ports": len(ports)}) |
Kent Hagerman | fa9d6d4 | 2020-05-25 11:49:40 -0400 | [diff] [blame] | 372 | return &voltha.LogicalPorts{Items: ret}, nil |
khenaidoo | 19d7b63 | 2018-10-30 10:49:50 -0400 | [diff] [blame] | 373 | } |
| 374 | |
Kent Hagerman | 45a13e4 | 2020-04-13 12:23:50 -0400 | [diff] [blame] | 375 | // GetLogicalDevicePort returns logical device port details |
| 376 | func (ldMgr *LogicalManager) GetLogicalDevicePort(ctx context.Context, lPortID *voltha.LogicalPortId) (*voltha.LogicalPort, error) { |
Himani Chawla | b4c2591 | 2020-11-12 17:16:38 +0530 | [diff] [blame] | 377 | ctx = utils.WithRPCMetadataContext(ctx, "GetLogicalDevicePort") |
Kent Hagerman | fa9d6d4 | 2020-05-25 11:49:40 -0400 | [diff] [blame] | 378 | // Get the logical device where this port is attached |
| 379 | agent := ldMgr.getLogicalDeviceAgent(ctx, lPortID.Id) |
| 380 | if agent == nil { |
| 381 | return nil, status.Errorf(codes.NotFound, "%s", lPortID.Id) |
khenaidoo | 19d7b63 | 2018-10-30 10:49:50 -0400 | [diff] [blame] | 382 | } |
Kent Hagerman | fa9d6d4 | 2020-05-25 11:49:40 -0400 | [diff] [blame] | 383 | |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 384 | for _, port := range agent.listLogicalDevicePorts(ctx) { |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 385 | if port.Id == lPortID.PortId { |
khenaidoo | 19d7b63 | 2018-10-30 10:49:50 -0400 | [diff] [blame] | 386 | return port, nil |
| 387 | } |
| 388 | } |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 389 | return nil, status.Errorf(codes.NotFound, "%s-%s", lPortID.Id, lPortID.PortId) |
khenaidoo | 19d7b63 | 2018-10-30 10:49:50 -0400 | [diff] [blame] | 390 | } |
| 391 | |
khenaidoo | 2c6a099 | 2019-04-29 13:46:56 -0400 | [diff] [blame] | 392 | // updateLogicalPort sets up a logical port on the logical device based on the device port |
| 393 | // information, if needed |
Kent Hagerman | 2a07b86 | 2020-06-19 15:23:07 -0400 | [diff] [blame] | 394 | func (ldMgr *LogicalManager) updateLogicalPort(ctx context.Context, device *voltha.Device, devicePorts map[uint32]*voltha.Port, port *voltha.Port) error { |
npujar | 467fe75 | 2020-01-16 20:17:45 +0530 | [diff] [blame] | 395 | ldID, err := ldMgr.getLogicalDeviceID(ctx, device) |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 396 | if err != nil || *ldID == "" { |
khenaidoo | 2c6a099 | 2019-04-29 13:46:56 -0400 | [diff] [blame] | 397 | // This is not an error as the logical device may not have been created at this time. In such a case, |
| 398 | // the ports will be created when the logical device is ready. |
| 399 | return nil |
khenaidoo | 2c6a099 | 2019-04-29 13:46:56 -0400 | [diff] [blame] | 400 | } |
npujar | 467fe75 | 2020-01-16 20:17:45 +0530 | [diff] [blame] | 401 | if agent := ldMgr.getLogicalDeviceAgent(ctx, *ldID); agent != nil { |
Kent Hagerman | 2a07b86 | 2020-06-19 15:23:07 -0400 | [diff] [blame] | 402 | if err := agent.updateLogicalPort(ctx, device, devicePorts, port); err != nil { |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 403 | return err |
khenaidoo | fc1314d | 2019-03-14 09:34:21 -0400 | [diff] [blame] | 404 | } |
| 405 | } |
| 406 | return nil |
| 407 | } |
| 408 | |
khenaidoo | 0a822f9 | 2019-05-08 15:15:57 -0400 | [diff] [blame] | 409 | // deleteLogicalPort removes the logical port associated with a child device |
Kent Hagerman | 2b21604 | 2020-04-03 18:28:56 -0400 | [diff] [blame] | 410 | func (ldMgr *LogicalManager) deleteLogicalPorts(ctx context.Context, deviceID string) error { |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 411 | logger.Debugw(ctx, "deleting-logical-ports", log.Fields{"device-id": deviceID}) |
khenaidoo | 0a822f9 | 2019-05-08 15:15:57 -0400 | [diff] [blame] | 412 | // Get logical port |
npujar | 467fe75 | 2020-01-16 20:17:45 +0530 | [diff] [blame] | 413 | ldID, err := ldMgr.getLogicalDeviceIDFromDeviceID(ctx, deviceID) |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 414 | if err != nil { |
khenaidoo | 0a822f9 | 2019-05-08 15:15:57 -0400 | [diff] [blame] | 415 | return err |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 416 | } |
npujar | 467fe75 | 2020-01-16 20:17:45 +0530 | [diff] [blame] | 417 | if agent := ldMgr.getLogicalDeviceAgent(ctx, *ldID); agent != nil { |
| 418 | if err = agent.deleteLogicalPorts(ctx, deviceID); err != nil { |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 419 | logger.Warnw(ctx, "delete-logical-ports-failed", log.Fields{"logical-device-id": *ldID}) |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 420 | return err |
khenaidoo | 0a822f9 | 2019-05-08 15:15:57 -0400 | [diff] [blame] | 421 | } |
| 422 | } |
Andrea Campanella | 77dde84 | 2021-05-27 15:31:54 +0200 | [diff] [blame] | 423 | logger.Debugw(ctx, "deleting-logical-ports-ends", log.Fields{"device-id": deviceID}) |
khenaidoo | 0a822f9 | 2019-05-08 15:15:57 -0400 | [diff] [blame] | 424 | return nil |
| 425 | } |
| 426 | |
Girish Gowdra | 06a0ce2 | 2021-12-14 11:09:10 +0530 | [diff] [blame] | 427 | // deleteAllLogicalMetersForLogicalDevice removes the logical meters associated with a the Logical Device ID |
| 428 | func (ldMgr *LogicalManager) deleteAllLogicalMetersForLogicalDevice(ctx context.Context, ldID string) error { |
| 429 | logger.Debugw(ctx, "delete-logical-meters", log.Fields{"logical-device-id": ldID}) |
| 430 | if agent := ldMgr.getLogicalDeviceAgent(ctx, ldID); agent != nil { |
serkant.uluderya | ad1e683 | 2020-12-17 21:08:38 +0300 | [diff] [blame] | 431 | for meterID := range agent.meterLoader.ListIDs() { |
| 432 | if meterHandle, have := agent.meterLoader.Lock(meterID); have { |
| 433 | // Update the store and cache |
| 434 | if err := meterHandle.Delete(ctx); err != nil { |
| 435 | meterHandle.Unlock() |
| 436 | logger.Errorw(ctx, "unable-to-delete-meter", log.Fields{"logical-device-id": ldID, "meterID": meterID}) |
| 437 | continue |
| 438 | } |
| 439 | meterHandle.Unlock() |
| 440 | } |
| 441 | } |
| 442 | } |
| 443 | return nil |
| 444 | } |
| 445 | |
Kent Hagerman | 2a07b86 | 2020-06-19 15:23:07 -0400 | [diff] [blame] | 446 | func (ldMgr *LogicalManager) setupUNILogicalPorts(ctx context.Context, childDevice *voltha.Device, childDevicePorts map[uint32]*voltha.Port) error { |
Himani Chawla | b4c2591 | 2020-11-12 17:16:38 +0530 | [diff] [blame] | 447 | logger.Debugw(ctx, "setup-uni-logical-ports", log.Fields{"child-device-id": childDevice.Id, "parent-device-id": childDevice.ParentId, "current-data": childDevice}) |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 448 | // Sanity check |
| 449 | if childDevice.Root { |
| 450 | return errors.New("Device-root") |
| 451 | } |
| 452 | |
| 453 | // Get the logical device id parent device |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 454 | parentID := childDevice.ParentId |
npujar | 467fe75 | 2020-01-16 20:17:45 +0530 | [diff] [blame] | 455 | logDeviceID := ldMgr.deviceMgr.GetParentDeviceID(ctx, parentID) |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 456 | |
Himani Chawla | b4c2591 | 2020-11-12 17:16:38 +0530 | [diff] [blame] | 457 | logger.Debugw(ctx, "setup-uni-logical-ports", log.Fields{"logical-device-id": logDeviceID, "parentId": parentID}) |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 458 | |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 459 | if parentID == "" || logDeviceID == "" { |
khenaidoo | 2c6a099 | 2019-04-29 13:46:56 -0400 | [diff] [blame] | 460 | return errors.New("device-in-invalid-state") |
khenaidoo | 5e677ae | 2019-02-28 17:26:29 -0500 | [diff] [blame] | 461 | } |
| 462 | |
npujar | 467fe75 | 2020-01-16 20:17:45 +0530 | [diff] [blame] | 463 | if agent := ldMgr.getLogicalDeviceAgent(ctx, logDeviceID); agent != nil { |
Kent Hagerman | 2a07b86 | 2020-06-19 15:23:07 -0400 | [diff] [blame] | 464 | if err := agent.setupUNILogicalPorts(ctx, childDevice, childDevicePorts); err != nil { |
khenaidoo | bcf205b | 2019-01-25 22:21:14 -0500 | [diff] [blame] | 465 | return err |
| 466 | } |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 467 | } |
khenaidoo | 21d5115 | 2019-02-01 13:48:37 -0500 | [diff] [blame] | 468 | return nil |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 469 | } |
khenaidoo | 19d7b63 | 2018-10-30 10:49:50 -0400 | [diff] [blame] | 470 | |
Kent Hagerman | 2b21604 | 2020-04-03 18:28:56 -0400 | [diff] [blame] | 471 | func (ldMgr *LogicalManager) deleteAllLogicalPorts(ctx context.Context, device *voltha.Device) error { |
Himani Chawla | b4c2591 | 2020-11-12 17:16:38 +0530 | [diff] [blame] | 472 | logger.Debugw(ctx, "delete-all-logical-ports", log.Fields{"device-id": device.Id}) |
khenaidoo | 0a822f9 | 2019-05-08 15:15:57 -0400 | [diff] [blame] | 473 | |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 474 | var ldID *string |
khenaidoo | 0a822f9 | 2019-05-08 15:15:57 -0400 | [diff] [blame] | 475 | var err error |
| 476 | //Get the logical device Id for this device |
npujar | 467fe75 | 2020-01-16 20:17:45 +0530 | [diff] [blame] | 477 | if ldID, err = ldMgr.getLogicalDeviceID(ctx, device); err != nil { |
divyadesai | cb8b59d | 2020-08-18 09:55:47 +0000 | [diff] [blame] | 478 | logger.Warnw(ctx, "no-logical-device-found", log.Fields{"device-id": device.Id, "error": err}) |
khenaidoo | 0a822f9 | 2019-05-08 15:15:57 -0400 | [diff] [blame] | 479 | return err |
| 480 | } |
npujar | 467fe75 | 2020-01-16 20:17:45 +0530 | [diff] [blame] | 481 | if agent := ldMgr.getLogicalDeviceAgent(ctx, *ldID); agent != nil { |
Girish Gowdra | 408cd96 | 2020-03-11 14:31:31 -0700 | [diff] [blame] | 482 | if err := agent.deleteAllLogicalPorts(ctx); err != nil { |
khenaidoo | 0a822f9 | 2019-05-08 15:15:57 -0400 | [diff] [blame] | 483 | return err |
| 484 | } |
| 485 | } |
| 486 | return nil |
| 487 | } |
Hardik Windlass | c704def | 2020-02-26 18:23:19 +0000 | [diff] [blame] | 488 | |
Kent Hagerman | 2b21604 | 2020-04-03 18:28:56 -0400 | [diff] [blame] | 489 | func (ldMgr *LogicalManager) updatePortState(ctx context.Context, deviceID string, portNo uint32, state voltha.OperStatus_Types) error { |
Himani Chawla | b4c2591 | 2020-11-12 17:16:38 +0530 | [diff] [blame] | 490 | logger.Debugw(ctx, "update-Port-state", log.Fields{"device-id": deviceID, "state": state, "port-no": portNo}) |
khenaidoo | 171b98e | 2019-10-31 11:48:15 -0400 | [diff] [blame] | 491 | |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 492 | var ldID *string |
khenaidoo | 171b98e | 2019-10-31 11:48:15 -0400 | [diff] [blame] | 493 | var err error |
| 494 | //Get the logical device Id for this device |
npujar | 467fe75 | 2020-01-16 20:17:45 +0530 | [diff] [blame] | 495 | if ldID, err = ldMgr.getLogicalDeviceIDFromDeviceID(ctx, deviceID); err != nil { |
divyadesai | cb8b59d | 2020-08-18 09:55:47 +0000 | [diff] [blame] | 496 | logger.Warnw(ctx, "no-logical-device-found", log.Fields{"device-id": deviceID, "error": err}) |
khenaidoo | 171b98e | 2019-10-31 11:48:15 -0400 | [diff] [blame] | 497 | return err |
| 498 | } |
npujar | 467fe75 | 2020-01-16 20:17:45 +0530 | [diff] [blame] | 499 | if agent := ldMgr.getLogicalDeviceAgent(ctx, *ldID); agent != nil { |
Kent Hagerman | fa9d6d4 | 2020-05-25 11:49:40 -0400 | [diff] [blame] | 500 | if err := agent.updatePortState(ctx, portNo, state); err != nil { |
khenaidoo | 171b98e | 2019-10-31 11:48:15 -0400 | [diff] [blame] | 501 | return err |
| 502 | } |
| 503 | } |
| 504 | return nil |
| 505 | } |
khenaidoo | 0a822f9 | 2019-05-08 15:15:57 -0400 | [diff] [blame] | 506 | |
Kent Hagerman | 45a13e4 | 2020-04-13 12:23:50 -0400 | [diff] [blame] | 507 | // UpdateLogicalDeviceFlowTable updates logical device flow table |
| 508 | func (ldMgr *LogicalManager) UpdateLogicalDeviceFlowTable(ctx context.Context, flow *openflow_13.FlowTableUpdate) (*empty.Empty, error) { |
Himani Chawla | b4c2591 | 2020-11-12 17:16:38 +0530 | [diff] [blame] | 509 | ctx = utils.WithRPCMetadataContext(ctx, "UpdateLogicalDeviceFlowTable") |
| 510 | logger.Debugw(ctx, "update-logical-device-flow-table", log.Fields{"logical-device-id": flow.Id}) |
Kent Hagerman | 45a13e4 | 2020-04-13 12:23:50 -0400 | [diff] [blame] | 511 | agent := ldMgr.getLogicalDeviceAgent(ctx, flow.Id) |
| 512 | if agent == nil { |
| 513 | return nil, status.Errorf(codes.NotFound, "%s", flow.Id) |
khenaidoo | 19d7b63 | 2018-10-30 10:49:50 -0400 | [diff] [blame] | 514 | } |
Maninder | f421da6 | 2020-12-04 11:44:58 +0530 | [diff] [blame] | 515 | return &empty.Empty{}, agent.updateFlowTable(ctx, flow) |
khenaidoo | 19d7b63 | 2018-10-30 10:49:50 -0400 | [diff] [blame] | 516 | } |
| 517 | |
Kent Hagerman | 45a13e4 | 2020-04-13 12:23:50 -0400 | [diff] [blame] | 518 | // UpdateLogicalDeviceMeterTable - This function sends meter mod request to logical device manager and waits for response |
| 519 | func (ldMgr *LogicalManager) UpdateLogicalDeviceMeterTable(ctx context.Context, meter *openflow_13.MeterModUpdate) (*empty.Empty, error) { |
Himani Chawla | b4c2591 | 2020-11-12 17:16:38 +0530 | [diff] [blame] | 520 | ctx = utils.WithRPCMetadataContext(ctx, "UpdateLogicalDeviceMeterTable") |
| 521 | logger.Debugw(ctx, "update-logical-device-meter-table", log.Fields{"logical-device-id": meter.Id}) |
Kent Hagerman | 45a13e4 | 2020-04-13 12:23:50 -0400 | [diff] [blame] | 522 | agent := ldMgr.getLogicalDeviceAgent(ctx, meter.Id) |
| 523 | if agent == nil { |
| 524 | return nil, status.Errorf(codes.NotFound, "%s", meter.Id) |
Manikkaraj k | b1a1092 | 2019-07-29 12:10:34 -0400 | [diff] [blame] | 525 | } |
Kent Hagerman | 45a13e4 | 2020-04-13 12:23:50 -0400 | [diff] [blame] | 526 | return &empty.Empty{}, agent.updateMeterTable(ctx, meter.MeterMod) |
Manikkaraj k | b1a1092 | 2019-07-29 12:10:34 -0400 | [diff] [blame] | 527 | } |
| 528 | |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 529 | // ListLogicalDeviceMeters returns logical device meters |
Kent Hagerman | 45a13e4 | 2020-04-13 12:23:50 -0400 | [diff] [blame] | 530 | func (ldMgr *LogicalManager) ListLogicalDeviceMeters(ctx context.Context, id *voltha.ID) (*openflow_13.Meters, error) { |
Himani Chawla | b4c2591 | 2020-11-12 17:16:38 +0530 | [diff] [blame] | 531 | ctx = utils.WithRPCMetadataContext(ctx, "ListLogicalDeviceMeters") |
| 532 | logger.Debugw(ctx, "list-logical-device-meters", log.Fields{"logical-device-id": id.Id}) |
Kent Hagerman | 45a13e4 | 2020-04-13 12:23:50 -0400 | [diff] [blame] | 533 | agent := ldMgr.getLogicalDeviceAgent(ctx, id.Id) |
| 534 | if agent == nil { |
| 535 | return nil, status.Errorf(codes.NotFound, "%s", id.Id) |
Manikkaraj k | b1a1092 | 2019-07-29 12:10:34 -0400 | [diff] [blame] | 536 | } |
khenaidoo | 1a0d622 | 2021-06-30 16:48:44 -0400 | [diff] [blame] | 537 | meters := agent.listLogicalDeviceMeters(ctx) |
Kent Hagerman | 433a31a | 2020-05-20 19:04:48 -0400 | [diff] [blame] | 538 | ctr, ret := 0, make([]*openflow_13.OfpMeterEntry, len(meters)) |
| 539 | for _, meter := range meters { |
| 540 | ret[ctr] = meter |
| 541 | ctr++ |
| 542 | } |
| 543 | return &openflow_13.Meters{Items: ret}, nil |
khenaidoo | 19d7b63 | 2018-10-30 10:49:50 -0400 | [diff] [blame] | 544 | } |
| 545 | |
Kent Hagerman | 45a13e4 | 2020-04-13 12:23:50 -0400 | [diff] [blame] | 546 | // UpdateLogicalDeviceFlowGroupTable updates logical device flow group table |
| 547 | func (ldMgr *LogicalManager) UpdateLogicalDeviceFlowGroupTable(ctx context.Context, flow *openflow_13.FlowGroupTableUpdate) (*empty.Empty, error) { |
Himani Chawla | b4c2591 | 2020-11-12 17:16:38 +0530 | [diff] [blame] | 548 | ctx = utils.WithRPCMetadataContext(ctx, "UpdateLogicalDeviceFlowGroupTable") |
| 549 | logger.Debugw(ctx, "update-group-table", log.Fields{"logical-device-id": flow.Id}) |
Kent Hagerman | 45a13e4 | 2020-04-13 12:23:50 -0400 | [diff] [blame] | 550 | agent := ldMgr.getLogicalDeviceAgent(ctx, flow.Id) |
| 551 | if agent == nil { |
| 552 | return nil, status.Errorf(codes.NotFound, "%s", flow.Id) |
khenaidoo | 19d7b63 | 2018-10-30 10:49:50 -0400 | [diff] [blame] | 553 | } |
Kent Hagerman | 45a13e4 | 2020-04-13 12:23:50 -0400 | [diff] [blame] | 554 | return &empty.Empty{}, agent.updateGroupTable(ctx, flow.GroupMod) |
khenaidoo | 19d7b63 | 2018-10-30 10:49:50 -0400 | [diff] [blame] | 555 | } |
| 556 | |
Kent Hagerman | 45a13e4 | 2020-04-13 12:23:50 -0400 | [diff] [blame] | 557 | // EnableLogicalDevicePort enables logical device port |
| 558 | func (ldMgr *LogicalManager) EnableLogicalDevicePort(ctx context.Context, id *voltha.LogicalPortId) (*empty.Empty, error) { |
Himani Chawla | b4c2591 | 2020-11-12 17:16:38 +0530 | [diff] [blame] | 559 | ctx = utils.WithRPCMetadataContext(ctx, "EnableLogicalDevicePort") |
| 560 | logger.Debugw(ctx, "enable-logical-device-port", log.Fields{"logical-device-id": id}) |
Kent Hagerman | 45a13e4 | 2020-04-13 12:23:50 -0400 | [diff] [blame] | 561 | agent := ldMgr.getLogicalDeviceAgent(ctx, id.Id) |
| 562 | if agent == nil { |
| 563 | return nil, status.Errorf(codes.NotFound, "%s", id.Id) |
khenaidoo | 19d7b63 | 2018-10-30 10:49:50 -0400 | [diff] [blame] | 564 | } |
Kent Hagerman | fa9d6d4 | 2020-05-25 11:49:40 -0400 | [diff] [blame] | 565 | portNo, err := strconv.ParseUint(id.PortId, 10, 32) |
| 566 | if err != nil { |
| 567 | return nil, status.Errorf(codes.InvalidArgument, "failed to parse %s as a number", id.PortId) |
| 568 | } |
| 569 | return &empty.Empty{}, agent.enableLogicalPort(ctx, uint32(portNo)) |
Kent Hagerman | 45a13e4 | 2020-04-13 12:23:50 -0400 | [diff] [blame] | 570 | } |
| 571 | |
| 572 | // DisableLogicalDevicePort disables logical device port |
| 573 | func (ldMgr *LogicalManager) DisableLogicalDevicePort(ctx context.Context, id *voltha.LogicalPortId) (*empty.Empty, error) { |
Himani Chawla | b4c2591 | 2020-11-12 17:16:38 +0530 | [diff] [blame] | 574 | ctx = utils.WithRPCMetadataContext(ctx, "DisableLogicalDevicePort") |
| 575 | logger.Debugw(ctx, "disable-logical-device-port", log.Fields{"logical-device-id": id}) |
Kent Hagerman | 45a13e4 | 2020-04-13 12:23:50 -0400 | [diff] [blame] | 576 | agent := ldMgr.getLogicalDeviceAgent(ctx, id.Id) |
| 577 | if agent == nil { |
| 578 | return nil, status.Errorf(codes.NotFound, "%s", id.Id) |
| 579 | } |
Kent Hagerman | fa9d6d4 | 2020-05-25 11:49:40 -0400 | [diff] [blame] | 580 | portNo, err := strconv.ParseUint(id.PortId, 10, 32) |
| 581 | if err != nil { |
| 582 | return nil, status.Errorf(codes.InvalidArgument, "failed to parse %s as a number", id.PortId) |
| 583 | } |
| 584 | return &empty.Empty{}, agent.disableLogicalPort(ctx, uint32(portNo)) |
khenaidoo | 19d7b63 | 2018-10-30 10:49:50 -0400 | [diff] [blame] | 585 | } |
khenaidoo | fdbad6e | 2018-11-06 22:26:38 -0500 | [diff] [blame] | 586 | |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 587 | func (ldMgr *LogicalManager) packetIn(ctx context.Context, logicalDeviceID string, port uint32, packet []byte) error { |
Himani Chawla | b4c2591 | 2020-11-12 17:16:38 +0530 | [diff] [blame] | 588 | logger.Debugw(ctx, "packet-in", log.Fields{"logical-device-id": logicalDeviceID, "port": port}) |
npujar | 467fe75 | 2020-01-16 20:17:45 +0530 | [diff] [blame] | 589 | if agent := ldMgr.getLogicalDeviceAgent(ctx, logicalDeviceID); agent != nil { |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 590 | agent.packetIn(ctx, port, packet) |
khenaidoo | fdbad6e | 2018-11-06 22:26:38 -0500 | [diff] [blame] | 591 | } else { |
divyadesai | cb8b59d | 2020-08-18 09:55:47 +0000 | [diff] [blame] | 592 | logger.Error(ctx, "logical-device-not-exist", log.Fields{"logical-device-id": logicalDeviceID}) |
khenaidoo | fdbad6e | 2018-11-06 22:26:38 -0500 | [diff] [blame] | 593 | } |
| 594 | return nil |
| 595 | } |
Kent Hagerman | 2b21604 | 2020-04-03 18:28:56 -0400 | [diff] [blame] | 596 | |
Kent Hagerman | 45a13e4 | 2020-04-13 12:23:50 -0400 | [diff] [blame] | 597 | // StreamPacketsOut sends packets to adapter |
| 598 | func (ldMgr *LogicalManager) StreamPacketsOut(packets voltha.VolthaService_StreamPacketsOutServer) error { |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 599 | ctx := context.Background() |
Himani Chawla | b4c2591 | 2020-11-12 17:16:38 +0530 | [diff] [blame] | 600 | logger.Debugw(ctx, "stream-packets-out-request", log.Fields{"packets": packets}) |
| 601 | |
Kent Hagerman | 45a13e4 | 2020-04-13 12:23:50 -0400 | [diff] [blame] | 602 | loop: |
| 603 | for { |
| 604 | select { |
| 605 | case <-packets.Context().Done(): |
Himani Chawla | b4c2591 | 2020-11-12 17:16:38 +0530 | [diff] [blame] | 606 | logger.Infow(ctx, "stream-packets-out-context-done", log.Fields{"packets": packets, "error": packets.Context().Err()}) |
Kent Hagerman | 45a13e4 | 2020-04-13 12:23:50 -0400 | [diff] [blame] | 607 | break loop |
| 608 | default: |
| 609 | } |
| 610 | |
| 611 | packet, err := packets.Recv() |
| 612 | |
Himani Chawla | b4c2591 | 2020-11-12 17:16:38 +0530 | [diff] [blame] | 613 | pktCtx := utils.WithRPCMetadataContext(packets.Context(), "StreamPacketsOut") |
| 614 | |
Kent Hagerman | 45a13e4 | 2020-04-13 12:23:50 -0400 | [diff] [blame] | 615 | if err == io.EOF { |
Himani Chawla | b4c2591 | 2020-11-12 17:16:38 +0530 | [diff] [blame] | 616 | logger.Debugw(ctx, "received-eof", log.Fields{"packets": packets}) |
Kent Hagerman | 45a13e4 | 2020-04-13 12:23:50 -0400 | [diff] [blame] | 617 | break loop |
| 618 | } |
Kent Hagerman | 45a13e4 | 2020-04-13 12:23:50 -0400 | [diff] [blame] | 619 | if err != nil { |
Himani Chawla | b4c2591 | 2020-11-12 17:16:38 +0530 | [diff] [blame] | 620 | logger.Errorw(ctx, "failed-to-receive-packet-out", log.Fields{"error": err}) |
Andrea Campanella | ff2d73a | 2021-03-04 14:47:17 +0100 | [diff] [blame] | 621 | // we do not have the resource Id here due to error in the packet, setting to empty |
Himani Chawla | 606a4f0 | 2021-03-23 19:45:58 +0530 | [diff] [blame] | 622 | ldMgr.SendRPCEvent(pktCtx, "", err.Error(), nil, |
| 623 | "RPC_ERROR_RAISE_EVENT", voltha.EventCategory_COMMUNICATION, nil, time.Now().Unix()) |
Kent Hagerman | 45a13e4 | 2020-04-13 12:23:50 -0400 | [diff] [blame] | 624 | continue |
| 625 | } |
| 626 | |
Himani Chawla | b4c2591 | 2020-11-12 17:16:38 +0530 | [diff] [blame] | 627 | if agent := ldMgr.getLogicalDeviceAgent(pktCtx, packet.Id); agent != nil { |
| 628 | agent.packetOut(pktCtx, packet.PacketOut) |
Kent Hagerman | 45a13e4 | 2020-04-13 12:23:50 -0400 | [diff] [blame] | 629 | } else { |
Himani Chawla | b4c2591 | 2020-11-12 17:16:38 +0530 | [diff] [blame] | 630 | logger.Errorf(ctx, "no-logical-device-agent-present", log.Fields{"logical-device-id": packet.Id}) |
Kent Hagerman | 45a13e4 | 2020-04-13 12:23:50 -0400 | [diff] [blame] | 631 | } |
Kent Hagerman | 2b21604 | 2020-04-03 18:28:56 -0400 | [diff] [blame] | 632 | } |
Kent Hagerman | 45a13e4 | 2020-04-13 12:23:50 -0400 | [diff] [blame] | 633 | |
Himani Chawla | b4c2591 | 2020-11-12 17:16:38 +0530 | [diff] [blame] | 634 | logger.Debugw(ctx, "stream-packets-out-request-done", log.Fields{"packets": packets}) |
Kent Hagerman | 45a13e4 | 2020-04-13 12:23:50 -0400 | [diff] [blame] | 635 | return nil |
Kent Hagerman | 2b21604 | 2020-04-03 18:28:56 -0400 | [diff] [blame] | 636 | } |
Himani Chawla | b4c2591 | 2020-11-12 17:16:38 +0530 | [diff] [blame] | 637 | |
| 638 | func (ldMgr *LogicalManager) SendRPCEvent(ctx context.Context, resourceID, desc string, context map[string]string, |
| 639 | id string, category voltha.EventCategory_Types, subCategory *voltha.EventSubCategory_Types, raisedTs int64) { |
Mahir Gunyel | b0343bf | 2021-05-11 14:14:26 -0700 | [diff] [blame] | 640 | ldMgr.Manager.Agent.GetAndSendRPCEvent(ctx, resourceID, desc, context, id, |
Himani Chawla | b4c2591 | 2020-11-12 17:16:38 +0530 | [diff] [blame] | 641 | category, subCategory, raisedTs) |
| 642 | } |