blob: af762587de690be4f837edcfc0f75e50505d4772 [file] [log] [blame]
khenaidoob9203542018-09-17 22:56:37 -04001/*
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 */
npujar1d86a522019-11-14 17:11:16 +053016
khenaidoob9203542018-09-17 22:56:37 -040017package core
18
19import (
20 "context"
21 "errors"
David Bainbridgefd27f4b2020-03-26 18:27:41 -070022 "strings"
23 "sync"
24 "time"
25
sbarbari17d7e222019-11-05 10:02:29 -050026 "github.com/opencord/voltha-go/db/model"
serkant.uluderya2ae470f2020-01-21 11:13:09 -080027 "github.com/opencord/voltha-lib-go/v3/pkg/kafka"
28 "github.com/opencord/voltha-lib-go/v3/pkg/log"
29 "github.com/opencord/voltha-lib-go/v3/pkg/probe"
30 "github.com/opencord/voltha-protos/v3/go/openflow_13"
31 "github.com/opencord/voltha-protos/v3/go/voltha"
khenaidoob9203542018-09-17 22:56:37 -040032 "google.golang.org/grpc/codes"
33 "google.golang.org/grpc/status"
khenaidoob9203542018-09-17 22:56:37 -040034)
35
npujar1d86a522019-11-14 17:11:16 +053036// LogicalDeviceManager represent logical device manager attributes
khenaidoob9203542018-09-17 22:56:37 -040037type LogicalDeviceManager struct {
khenaidoo4c9e5592019-09-09 16:20:41 -040038 logicalDeviceAgents sync.Map
39 core *Core
40 deviceMgr *DeviceManager
41 grpcNbiHdlr *APIHandler
npujar467fe752020-01-16 20:17:45 +053042 kafkaICProxy kafka.InterContainerProxy
khenaidoo4c9e5592019-09-09 16:20:41 -040043 clusterDataProxy *model.Proxy
44 exitChannel chan int
khenaidoo442e7c72020-03-10 16:13:48 -040045 defaultTimeout time.Duration
khenaidoo4c9e5592019-09-09 16:20:41 -040046 logicalDevicesLoadingLock sync.RWMutex
47 logicalDeviceLoadingInProgress map[string][]chan int
khenaidoob9203542018-09-17 22:56:37 -040048}
49
khenaidoo442e7c72020-03-10 16:13:48 -040050func newLogicalDeviceManager(core *Core, deviceMgr *DeviceManager, kafkaICProxy kafka.InterContainerProxy, cdProxy *model.Proxy, timeout time.Duration) *LogicalDeviceManager {
khenaidoob9203542018-09-17 22:56:37 -040051 var logicalDeviceMgr LogicalDeviceManager
Richard Jankowski199fd862019-03-18 14:49:51 -040052 logicalDeviceMgr.core = core
khenaidoob9203542018-09-17 22:56:37 -040053 logicalDeviceMgr.exitChannel = make(chan int, 1)
khenaidoob9203542018-09-17 22:56:37 -040054 logicalDeviceMgr.deviceMgr = deviceMgr
khenaidoo43c82122018-11-22 18:38:28 -050055 logicalDeviceMgr.kafkaICProxy = kafkaICProxy
khenaidoo9a468962018-09-19 15:33:13 -040056 logicalDeviceMgr.clusterDataProxy = cdProxy
khenaidoo2c6a0992019-04-29 13:46:56 -040057 logicalDeviceMgr.defaultTimeout = timeout
khenaidoo4c9e5592019-09-09 16:20:41 -040058 logicalDeviceMgr.logicalDevicesLoadingLock = sync.RWMutex{}
59 logicalDeviceMgr.logicalDeviceLoadingInProgress = make(map[string][]chan int)
khenaidoob9203542018-09-17 22:56:37 -040060 return &logicalDeviceMgr
61}
62
Richard Jankowskidbab94a2018-12-06 16:20:25 -050063func (ldMgr *LogicalDeviceManager) setGrpcNbiHandler(grpcNbiHandler *APIHandler) {
64 ldMgr.grpcNbiHdlr = grpcNbiHandler
65}
66
khenaidoo4d4802d2018-10-04 21:59:49 -040067func (ldMgr *LogicalDeviceManager) start(ctx context.Context) {
Girish Kumarf56a4682020-03-20 20:07:46 +000068 logger.Info("starting-logical-device-manager")
David K. Bainbridgeb4a9ab02019-09-20 15:12:16 -070069 probe.UpdateStatusFromContext(ctx, "logical-device-manager", probe.ServiceStatusRunning)
Girish Kumarf56a4682020-03-20 20:07:46 +000070 logger.Info("logical-device-manager-started")
khenaidoob9203542018-09-17 22:56:37 -040071}
72
khenaidoo4d4802d2018-10-04 21:59:49 -040073func (ldMgr *LogicalDeviceManager) stop(ctx context.Context) {
Girish Kumarf56a4682020-03-20 20:07:46 +000074 logger.Info("stopping-logical-device-manager")
khenaidoob9203542018-09-17 22:56:37 -040075 ldMgr.exitChannel <- 1
David K. Bainbridgeb4a9ab02019-09-20 15:12:16 -070076 probe.UpdateStatusFromContext(ctx, "logical-device-manager", probe.ServiceStatusStopped)
Girish Kumarf56a4682020-03-20 20:07:46 +000077 logger.Info("logical-device-manager-stopped")
khenaidoob9203542018-09-17 22:56:37 -040078}
79
khenaidoo19d7b632018-10-30 10:49:50 -040080func sendAPIResponse(ctx context.Context, ch chan interface{}, result interface{}) {
81 if ctx.Err() == nil {
82 // Returned response only of the ctx has not been cancelled/timeout/etc
83 // Channel is automatically closed when a context is Done
84 ch <- result
Girish Kumarf56a4682020-03-20 20:07:46 +000085 logger.Debugw("sendResponse", log.Fields{"result": result})
khenaidoo19d7b632018-10-30 10:49:50 -040086 } else {
87 // Should the transaction be reverted back?
Girish Kumarf56a4682020-03-20 20:07:46 +000088 logger.Debugw("sendResponse-context-error", log.Fields{"context-error": ctx.Err()})
khenaidoo19d7b632018-10-30 10:49:50 -040089 }
90}
91
khenaidoob9203542018-09-17 22:56:37 -040092func (ldMgr *LogicalDeviceManager) addLogicalDeviceAgentToMap(agent *LogicalDeviceAgent) {
npujar1d86a522019-11-14 17:11:16 +053093 if _, exist := ldMgr.logicalDeviceAgents.Load(agent.logicalDeviceID); !exist {
94 ldMgr.logicalDeviceAgents.Store(agent.logicalDeviceID, agent)
khenaidoob9203542018-09-17 22:56:37 -040095 }
96}
97
khenaidoo8c3303d2019-02-13 14:59:39 -050098// getLogicalDeviceAgent returns the logical device agent. If the device is not in memory then the device will
99// be loaded from dB and a logical device agent created to managed it.
npujar467fe752020-01-16 20:17:45 +0530100func (ldMgr *LogicalDeviceManager) getLogicalDeviceAgent(ctx context.Context, logicalDeviceID string) *LogicalDeviceAgent {
npujar1d86a522019-11-14 17:11:16 +0530101 agent, ok := ldMgr.logicalDeviceAgents.Load(logicalDeviceID)
102 if ok {
khenaidoo93d5a3d2020-01-15 12:37:05 -0500103 lda := agent.(*LogicalDeviceAgent)
104 if lda.logicalDevice == nil {
105 // This can happen when an agent for the logical device has been created but the logical device
106 // itself is not ready for action as it is waiting for switch and port capabilities from the
107 // relevant adapter. In such a case prevent any request aimed at that logical device.
Girish Kumarf56a4682020-03-20 20:07:46 +0000108 logger.Debugf("Logical device %s is not ready to serve requests", logicalDeviceID)
khenaidoo93d5a3d2020-01-15 12:37:05 -0500109 return nil
110 }
111 return lda
npujar1d86a522019-11-14 17:11:16 +0530112 }
113 // Try to load into memory - loading will also create the logical device agent
npujar467fe752020-01-16 20:17:45 +0530114 if err := ldMgr.load(ctx, logicalDeviceID); err == nil {
npujar1d86a522019-11-14 17:11:16 +0530115 if agent, ok = ldMgr.logicalDeviceAgents.Load(logicalDeviceID); ok {
116 return agent.(*LogicalDeviceAgent)
khenaidoo8c3303d2019-02-13 14:59:39 -0500117 }
khenaidoob9203542018-09-17 22:56:37 -0400118 }
119 return nil
120}
121
npujar1d86a522019-11-14 17:11:16 +0530122func (ldMgr *LogicalDeviceManager) deleteLogicalDeviceAgent(logicalDeviceID string) {
123 ldMgr.logicalDeviceAgents.Delete(logicalDeviceID)
khenaidoo92e62c52018-10-03 14:02:54 -0400124}
125
khenaidoo8c3303d2019-02-13 14:59:39 -0500126// GetLogicalDevice provides a cloned most up to date logical device. If device is not in memory
127// it will be fetched from the dB
npujar467fe752020-01-16 20:17:45 +0530128func (ldMgr *LogicalDeviceManager) getLogicalDevice(ctx context.Context, id string) (*voltha.LogicalDevice, error) {
Girish Kumarf56a4682020-03-20 20:07:46 +0000129 logger.Debugw("getlogicalDevice", log.Fields{"logicaldeviceid": id})
npujar467fe752020-01-16 20:17:45 +0530130 if agent := ldMgr.getLogicalDeviceAgent(ctx, id); agent != nil {
khenaidoo442e7c72020-03-10 16:13:48 -0400131 return agent.GetLogicalDevice(ctx)
khenaidoob9203542018-09-17 22:56:37 -0400132 }
133 return nil, status.Errorf(codes.NotFound, "%s", id)
134}
135
khenaidooba6b6c42019-08-02 09:11:56 -0400136//listLogicalDevices returns the list of all logical devices
npujar467fe752020-01-16 20:17:45 +0530137func (ldMgr *LogicalDeviceManager) listLogicalDevices(ctx context.Context) (*voltha.LogicalDevices, error) {
Girish Kumarf56a4682020-03-20 20:07:46 +0000138 logger.Debug("ListAllLogicalDevices")
khenaidoob9203542018-09-17 22:56:37 -0400139 result := &voltha.LogicalDevices{}
npujar467fe752020-01-16 20:17:45 +0530140 logicalDevices, err := ldMgr.clusterDataProxy.List(ctx, "/logical_devices", 0, true, "")
Thomas Lee Se5a44012019-11-07 20:32:24 +0530141 if err != nil {
Girish Kumarf56a4682020-03-20 20:07:46 +0000142 logger.Errorw("failed-to-list-logical-devices-from-cluster-proxy", log.Fields{"error": err})
Thomas Lee Se5a44012019-11-07 20:32:24 +0530143 return nil, err
144 }
145 if logicalDevices != nil {
Stephane Barbarie1ab43272018-12-08 21:42:13 -0500146 for _, logicalDevice := range logicalDevices.([]interface{}) {
Stephane Barbarie1ab43272018-12-08 21:42:13 -0500147 result.Items = append(result.Items, logicalDevice.(*voltha.LogicalDevice))
khenaidoob9203542018-09-17 22:56:37 -0400148 }
149 }
150 return result, nil
151}
152
khenaidoo4d4802d2018-10-04 21:59:49 -0400153func (ldMgr *LogicalDeviceManager) createLogicalDevice(ctx context.Context, device *voltha.Device) (*string, error) {
Girish Kumarf56a4682020-03-20 20:07:46 +0000154 logger.Debugw("creating-logical-device", log.Fields{"deviceId": device.Id})
khenaidoob9203542018-09-17 22:56:37 -0400155 // Sanity check
156 if !device.Root {
khenaidoo2c6a0992019-04-29 13:46:56 -0400157 return nil, errors.New("device-not-root")
khenaidoob9203542018-09-17 22:56:37 -0400158 }
159
160 // Create a logical device agent - the logical device Id is based on the mac address of the device
161 // For now use the serial number - it may contain any combination of alphabetic characters and numbers,
162 // with length varying from eight characters to a maximum of 14 characters. Mac Address is part of oneof
163 // in the Device model. May need to be moved out.
David Bainbridgefd27f4b2020-03-26 18:27:41 -0700164 id := CreateLogicalDeviceID()
165 sn := strings.Replace(device.MacAddress, ":", "", -1)
khenaidoo92e62c52018-10-03 14:02:54 -0400166 if id == "" {
David Bainbridgefd27f4b2020-03-26 18:27:41 -0700167 logger.Errorw("mac-address-not-set", log.Fields{"deviceId": device.Id, "serial-number": sn})
khenaidoo92e62c52018-10-03 14:02:54 -0400168 return nil, errors.New("mac-address-not-set")
169 }
David Bainbridgefd27f4b2020-03-26 18:27:41 -0700170
Girish Kumarf56a4682020-03-20 20:07:46 +0000171 logger.Debugw("logical-device-id", log.Fields{"logicaldeviceId": id})
khenaidoob9203542018-09-17 22:56:37 -0400172
David Bainbridgefd27f4b2020-03-26 18:27:41 -0700173 agent := newLogicalDeviceAgent(id, sn, device.Id, ldMgr, ldMgr.deviceMgr, ldMgr.clusterDataProxy, ldMgr.defaultTimeout)
khenaidoob9203542018-09-17 22:56:37 -0400174 ldMgr.addLogicalDeviceAgentToMap(agent)
khenaidooad06fd72019-10-28 12:26:05 -0400175
176 // Update the root device with the logical device Id reference
npujar467fe752020-01-16 20:17:45 +0530177 if err := ldMgr.deviceMgr.setParentID(ctx, device, id); err != nil {
Girish Kumarf56a4682020-03-20 20:07:46 +0000178 logger.Errorw("failed-setting-parent-id", log.Fields{"logicalDeviceId": id, "deviceId": device.Id})
khenaidooad06fd72019-10-28 12:26:05 -0400179 return nil, err
180 }
181
npujar1d86a522019-11-14 17:11:16 +0530182 go func() {
khenaidoo442e7c72020-03-10 16:13:48 -0400183 //agent := newLogicalDeviceAgent(id, device.Id, ldMgr, ldMgr.deviceMgr, ldMgr.clusterDataProxy, ldMgr.defaultTimeout)
184 err := agent.start(context.Background(), false)
npujar1d86a522019-11-14 17:11:16 +0530185 if err != nil {
Girish Kumarf56a4682020-03-20 20:07:46 +0000186 logger.Errorw("unable-to-create-the-logical-device", log.Fields{"error": err})
khenaidoo442e7c72020-03-10 16:13:48 -0400187 ldMgr.deleteLogicalDeviceAgent(id)
npujar1d86a522019-11-14 17:11:16 +0530188 }
189 }()
khenaidoob9203542018-09-17 22:56:37 -0400190
Girish Kumarf56a4682020-03-20 20:07:46 +0000191 logger.Debug("creating-logical-device-ends")
khenaidoob9203542018-09-17 22:56:37 -0400192 return &id, nil
193}
194
khenaidoo6d62c002019-05-15 21:57:03 -0400195// stopManagingLogicalDeviceWithDeviceId stops the management of the logical device. This implies removal of any
196// reference of this logical device in cache. The device Id is passed as param because the logical device may already
197// have been removed from the model. This function returns the logical device Id if found
npujar467fe752020-01-16 20:17:45 +0530198func (ldMgr *LogicalDeviceManager) stopManagingLogicalDeviceWithDeviceID(ctx context.Context, id string) string {
Girish Kumarf56a4682020-03-20 20:07:46 +0000199 logger.Infow("stop-managing-logical-device", log.Fields{"deviceId": id})
khenaidoo6d62c002019-05-15 21:57:03 -0400200 // Go over the list of logical device agents to find the one which has rootDeviceId as id
npujar1d86a522019-11-14 17:11:16 +0530201 var ldID = ""
Stephane Barbarieef6650d2019-07-18 12:15:09 -0400202 ldMgr.logicalDeviceAgents.Range(func(key, value interface{}) bool {
203 ldAgent := value.(*LogicalDeviceAgent)
npujar1d86a522019-11-14 17:11:16 +0530204 if ldAgent.rootDeviceID == id {
Girish Kumarf56a4682020-03-20 20:07:46 +0000205 logger.Infow("stopping-logical-device-agent", log.Fields{"lDeviceId": key})
npujar467fe752020-01-16 20:17:45 +0530206 if err := ldAgent.stop(ctx); err != nil {
Girish Kumarf56a4682020-03-20 20:07:46 +0000207 logger.Errorw("failed-to-stop-LDAgent", log.Fields{"error": err})
Thomas Lee Se5a44012019-11-07 20:32:24 +0530208 return false
209 }
npujar1d86a522019-11-14 17:11:16 +0530210 ldID = key.(string)
211 ldMgr.logicalDeviceAgents.Delete(ldID)
khenaidoo6d62c002019-05-15 21:57:03 -0400212 }
Stephane Barbarieef6650d2019-07-18 12:15:09 -0400213 return true
214 })
npujar1d86a522019-11-14 17:11:16 +0530215 return ldID
khenaidoo6d62c002019-05-15 21:57:03 -0400216}
217
218//getLogicalDeviceFromModel retrieves the logical device data from the model.
npujar467fe752020-01-16 20:17:45 +0530219func (ldMgr *LogicalDeviceManager) getLogicalDeviceFromModel(ctx context.Context, lDeviceID string) (*voltha.LogicalDevice, error) {
220 logicalDevice, err := ldMgr.clusterDataProxy.Get(ctx, "/logical_devices/"+lDeviceID, 0, false, "")
Thomas Lee Se5a44012019-11-07 20:32:24 +0530221 if err != nil {
Girish Kumarf56a4682020-03-20 20:07:46 +0000222 logger.Errorw("failed-to-get-logical-devices-from-cluster-proxy", log.Fields{"error": err})
Thomas Lee Se5a44012019-11-07 20:32:24 +0530223 return nil, err
224 }
225 if logicalDevice != nil {
khenaidoo6d62c002019-05-15 21:57:03 -0400226 if lDevice, ok := logicalDevice.(*voltha.LogicalDevice); ok {
227 return lDevice, nil
228 }
229 }
npujar1d86a522019-11-14 17:11:16 +0530230 return nil, status.Error(codes.NotFound, lDeviceID)
khenaidoo6d62c002019-05-15 21:57:03 -0400231}
232
khenaidoo297cd252019-02-07 22:10:23 -0500233// load loads a logical device manager in memory
npujar467fe752020-01-16 20:17:45 +0530234func (ldMgr *LogicalDeviceManager) load(ctx context.Context, lDeviceID string) error {
npujar1d86a522019-11-14 17:11:16 +0530235 if lDeviceID == "" {
khenaidoo4c9e5592019-09-09 16:20:41 -0400236 return nil
khenaidoo297cd252019-02-07 22:10:23 -0500237 }
khenaidoo4c9e5592019-09-09 16:20:41 -0400238 // Add a lock to prevent two concurrent calls from loading the same device twice
239 ldMgr.logicalDevicesLoadingLock.Lock()
npujar1d86a522019-11-14 17:11:16 +0530240 if _, exist := ldMgr.logicalDeviceLoadingInProgress[lDeviceID]; !exist {
241 if ldAgent, _ := ldMgr.logicalDeviceAgents.Load(lDeviceID); ldAgent == nil {
242 ldMgr.logicalDeviceLoadingInProgress[lDeviceID] = []chan int{make(chan int, 1)}
khenaidoo4c9e5592019-09-09 16:20:41 -0400243 ldMgr.logicalDevicesLoadingLock.Unlock()
npujar467fe752020-01-16 20:17:45 +0530244 if _, err := ldMgr.getLogicalDeviceFromModel(ctx, lDeviceID); err == nil {
Girish Kumarf56a4682020-03-20 20:07:46 +0000245 logger.Debugw("loading-logical-device", log.Fields{"lDeviceId": lDeviceID})
David Bainbridgefd27f4b2020-03-26 18:27:41 -0700246 agent := newLogicalDeviceAgent(lDeviceID, "", "", ldMgr, ldMgr.deviceMgr, ldMgr.clusterDataProxy, ldMgr.defaultTimeout)
npujar467fe752020-01-16 20:17:45 +0530247 if err := agent.start(ctx, true); err != nil {
khenaidoo442e7c72020-03-10 16:13:48 -0400248 return err
khenaidoo4c9e5592019-09-09 16:20:41 -0400249 }
khenaidoo442e7c72020-03-10 16:13:48 -0400250 ldMgr.logicalDeviceAgents.Store(agent.logicalDeviceID, agent)
khenaidoo4c9e5592019-09-09 16:20:41 -0400251 } else {
Girish Kumarf56a4682020-03-20 20:07:46 +0000252 logger.Debugw("logicalDevice not in model", log.Fields{"lDeviceId": lDeviceID})
khenaidoo4c9e5592019-09-09 16:20:41 -0400253 }
254 // announce completion of task to any number of waiting channels
255 ldMgr.logicalDevicesLoadingLock.Lock()
npujar1d86a522019-11-14 17:11:16 +0530256 if v, ok := ldMgr.logicalDeviceLoadingInProgress[lDeviceID]; ok {
khenaidoo4c9e5592019-09-09 16:20:41 -0400257 for _, ch := range v {
258 close(ch)
259 }
npujar1d86a522019-11-14 17:11:16 +0530260 delete(ldMgr.logicalDeviceLoadingInProgress, lDeviceID)
khenaidoo4c9e5592019-09-09 16:20:41 -0400261 }
262 ldMgr.logicalDevicesLoadingLock.Unlock()
263 } else {
264 ldMgr.logicalDevicesLoadingLock.Unlock()
265 }
266 } else {
267 ch := make(chan int, 1)
npujar1d86a522019-11-14 17:11:16 +0530268 ldMgr.logicalDeviceLoadingInProgress[lDeviceID] = append(ldMgr.logicalDeviceLoadingInProgress[lDeviceID], ch)
khenaidoo4c9e5592019-09-09 16:20:41 -0400269 ldMgr.logicalDevicesLoadingLock.Unlock()
270 // Wait for the channel to be closed, implying the process loading this device is done.
271 <-ch
272 }
npujar1d86a522019-11-14 17:11:16 +0530273 if _, exist := ldMgr.logicalDeviceAgents.Load(lDeviceID); exist {
khenaidoo4c9e5592019-09-09 16:20:41 -0400274 return nil
275 }
npujar1d86a522019-11-14 17:11:16 +0530276 return status.Errorf(codes.Aborted, "Error loading logical device %s", lDeviceID)
khenaidoo297cd252019-02-07 22:10:23 -0500277}
278
khenaidoo4d4802d2018-10-04 21:59:49 -0400279func (ldMgr *LogicalDeviceManager) deleteLogicalDevice(ctx context.Context, device *voltha.Device) error {
Girish Kumarf56a4682020-03-20 20:07:46 +0000280 logger.Debugw("deleting-logical-device", log.Fields{"deviceId": device.Id})
khenaidoo92e62c52018-10-03 14:02:54 -0400281 // Sanity check
282 if !device.Root {
khenaidoo2c6a0992019-04-29 13:46:56 -0400283 return errors.New("device-not-root")
khenaidoo92e62c52018-10-03 14:02:54 -0400284 }
npujar1d86a522019-11-14 17:11:16 +0530285 logDeviceID := device.ParentId
npujar467fe752020-01-16 20:17:45 +0530286 if agent := ldMgr.getLogicalDeviceAgent(ctx, logDeviceID); agent != nil {
khenaidoo92e62c52018-10-03 14:02:54 -0400287 // Stop the logical device agent
Thomas Lee Se5a44012019-11-07 20:32:24 +0530288 if err := agent.stop(ctx); err != nil {
Girish Kumarf56a4682020-03-20 20:07:46 +0000289 logger.Errorw("failed-to-stop-agent", log.Fields{"error": err})
Thomas Lee Se5a44012019-11-07 20:32:24 +0530290 return err
291 }
khenaidoo92e62c52018-10-03 14:02:54 -0400292 //Remove the logical device agent from the Map
npujar1d86a522019-11-14 17:11:16 +0530293 ldMgr.deleteLogicalDeviceAgent(logDeviceID)
khenaidoo92e62c52018-10-03 14:02:54 -0400294 }
295
Girish Kumarf56a4682020-03-20 20:07:46 +0000296 logger.Debug("deleting-logical-device-ends")
khenaidoo92e62c52018-10-03 14:02:54 -0400297 return nil
298}
299
npujar467fe752020-01-16 20:17:45 +0530300func (ldMgr *LogicalDeviceManager) getLogicalDeviceID(ctx context.Context, device *voltha.Device) (*string, error) {
khenaidoo92e62c52018-10-03 14:02:54 -0400301 // Device can either be a parent or a child device
302 if device.Root {
303 // Parent device. The ID of a parent device is the logical device ID
304 return &device.ParentId, nil
305 }
306 // Device is child device
307 // retrieve parent device using child device ID
npujar467fe752020-01-16 20:17:45 +0530308 if parentDevice := ldMgr.deviceMgr.getParentDevice(ctx, device); parentDevice != nil {
khenaidoo92e62c52018-10-03 14:02:54 -0400309 return &parentDevice.ParentId, nil
310 }
311 return nil, status.Errorf(codes.NotFound, "%s", device.Id)
312}
313
npujar467fe752020-01-16 20:17:45 +0530314func (ldMgr *LogicalDeviceManager) getLogicalDeviceIDFromDeviceID(ctx context.Context, deviceID string) (*string, error) {
khenaidoo3ab34882019-05-02 21:33:30 -0400315 // Get the device
316 var device *voltha.Device
317 var err error
npujar467fe752020-01-16 20:17:45 +0530318 if device, err = ldMgr.deviceMgr.GetDevice(ctx, deviceID); err != nil {
khenaidoo3ab34882019-05-02 21:33:30 -0400319 return nil, err
320 }
npujar467fe752020-01-16 20:17:45 +0530321 return ldMgr.getLogicalDeviceID(ctx, device)
khenaidoo3ab34882019-05-02 21:33:30 -0400322}
323
npujar467fe752020-01-16 20:17:45 +0530324func (ldMgr *LogicalDeviceManager) getLogicalPortID(ctx context.Context, device *voltha.Device) (*voltha.LogicalPortId, error) {
khenaidoo19d7b632018-10-30 10:49:50 -0400325 // Get the logical device where this device is attached
npujar1d86a522019-11-14 17:11:16 +0530326 var lDeviceID *string
khenaidoo19d7b632018-10-30 10:49:50 -0400327 var err error
npujar467fe752020-01-16 20:17:45 +0530328 if lDeviceID, err = ldMgr.getLogicalDeviceID(ctx, device); err != nil {
khenaidoo19d7b632018-10-30 10:49:50 -0400329 return nil, err
330 }
331 var lDevice *voltha.LogicalDevice
npujar467fe752020-01-16 20:17:45 +0530332 if lDevice, err = ldMgr.getLogicalDevice(ctx, *lDeviceID); err != nil {
khenaidoo19d7b632018-10-30 10:49:50 -0400333 return nil, err
334 }
335 // Go over list of ports
336 for _, port := range lDevice.Ports {
337 if port.DeviceId == device.Id {
npujar1d86a522019-11-14 17:11:16 +0530338 return &voltha.LogicalPortId{Id: *lDeviceID, PortId: port.Id}, nil
khenaidoo19d7b632018-10-30 10:49:50 -0400339 }
340 }
341 return nil, status.Errorf(codes.NotFound, "%s", device.Id)
342}
343
npujar1d86a522019-11-14 17:11:16 +0530344// ListLogicalDeviceFlows returns the flows of logical device
khenaidoodd237172019-05-27 16:37:17 -0400345func (ldMgr *LogicalDeviceManager) ListLogicalDeviceFlows(ctx context.Context, id string) (*openflow_13.Flows, error) {
Girish Kumarf56a4682020-03-20 20:07:46 +0000346 logger.Debugw("ListLogicalDeviceFlows", log.Fields{"logicaldeviceid": id})
npujar467fe752020-01-16 20:17:45 +0530347 if agent := ldMgr.getLogicalDeviceAgent(ctx, id); agent != nil {
khenaidoo442e7c72020-03-10 16:13:48 -0400348 return agent.ListLogicalDeviceFlows(ctx)
khenaidoodd237172019-05-27 16:37:17 -0400349 }
350 return nil, status.Errorf(codes.NotFound, "%s", id)
351}
352
npujar1d86a522019-11-14 17:11:16 +0530353// ListLogicalDeviceFlowGroups returns logical device flow groups
khenaidoodd237172019-05-27 16:37:17 -0400354func (ldMgr *LogicalDeviceManager) ListLogicalDeviceFlowGroups(ctx context.Context, id string) (*openflow_13.FlowGroups, error) {
Girish Kumarf56a4682020-03-20 20:07:46 +0000355 logger.Debugw("ListLogicalDeviceFlowGroups", log.Fields{"logicaldeviceid": id})
npujar467fe752020-01-16 20:17:45 +0530356 if agent := ldMgr.getLogicalDeviceAgent(ctx, id); agent != nil {
khenaidoo442e7c72020-03-10 16:13:48 -0400357 return agent.ListLogicalDeviceFlowGroups(ctx)
khenaidoodd237172019-05-27 16:37:17 -0400358 }
359 return nil, status.Errorf(codes.NotFound, "%s", id)
360}
361
npujar1d86a522019-11-14 17:11:16 +0530362// ListLogicalDevicePorts returns logical device ports
khenaidoo19d7b632018-10-30 10:49:50 -0400363func (ldMgr *LogicalDeviceManager) ListLogicalDevicePorts(ctx context.Context, id string) (*voltha.LogicalPorts, error) {
Girish Kumarf56a4682020-03-20 20:07:46 +0000364 logger.Debugw("ListLogicalDevicePorts", log.Fields{"logicaldeviceid": id})
npujar467fe752020-01-16 20:17:45 +0530365 if agent := ldMgr.getLogicalDeviceAgent(ctx, id); agent != nil {
khenaidoo442e7c72020-03-10 16:13:48 -0400366 return agent.ListLogicalDevicePorts(ctx)
khenaidoo19d7b632018-10-30 10:49:50 -0400367 }
368 return nil, status.Errorf(codes.NotFound, "%s", id)
khenaidoo19d7b632018-10-30 10:49:50 -0400369}
370
npujar467fe752020-01-16 20:17:45 +0530371func (ldMgr *LogicalDeviceManager) getLogicalPort(ctx context.Context, lPortID *voltha.LogicalPortId) (*voltha.LogicalPort, error) {
khenaidoo19d7b632018-10-30 10:49:50 -0400372 // Get the logical device where this device is attached
373 var err error
374 var lDevice *voltha.LogicalDevice
npujar467fe752020-01-16 20:17:45 +0530375 if lDevice, err = ldMgr.getLogicalDevice(ctx, lPortID.Id); err != nil {
khenaidoo19d7b632018-10-30 10:49:50 -0400376 return nil, err
377 }
378 // Go over list of ports
379 for _, port := range lDevice.Ports {
npujar1d86a522019-11-14 17:11:16 +0530380 if port.Id == lPortID.PortId {
khenaidoo19d7b632018-10-30 10:49:50 -0400381 return port, nil
382 }
383 }
npujar1d86a522019-11-14 17:11:16 +0530384 return nil, status.Errorf(codes.NotFound, "%s-%s", lPortID.Id, lPortID.PortId)
khenaidoo19d7b632018-10-30 10:49:50 -0400385}
386
khenaidoo2c6a0992019-04-29 13:46:56 -0400387// updateLogicalPort sets up a logical port on the logical device based on the device port
388// information, if needed
npujar467fe752020-01-16 20:17:45 +0530389func (ldMgr *LogicalDeviceManager) updateLogicalPort(ctx context.Context, device *voltha.Device, port *voltha.Port) error {
390 ldID, err := ldMgr.getLogicalDeviceID(ctx, device)
npujar1d86a522019-11-14 17:11:16 +0530391 if err != nil || *ldID == "" {
khenaidoo2c6a0992019-04-29 13:46:56 -0400392 // This is not an error as the logical device may not have been created at this time. In such a case,
393 // the ports will be created when the logical device is ready.
394 return nil
khenaidoo2c6a0992019-04-29 13:46:56 -0400395 }
npujar467fe752020-01-16 20:17:45 +0530396 if agent := ldMgr.getLogicalDeviceAgent(ctx, *ldID); agent != nil {
397 if err := agent.updateLogicalPort(ctx, device, port); err != nil {
npujar1d86a522019-11-14 17:11:16 +0530398 return err
khenaidoofc1314d2019-03-14 09:34:21 -0400399 }
400 }
401 return nil
402}
403
khenaidoo0a822f92019-05-08 15:15:57 -0400404// deleteLogicalPort removes the logical port associated with a device
npujar1d86a522019-11-14 17:11:16 +0530405func (ldMgr *LogicalDeviceManager) deleteLogicalPort(ctx context.Context, lPortID *voltha.LogicalPortId) error {
Girish Kumarf56a4682020-03-20 20:07:46 +0000406 logger.Debugw("deleting-logical-port", log.Fields{"LDeviceId": lPortID.Id})
khenaidoo19d7b632018-10-30 10:49:50 -0400407 // Get logical port
408 var logicalPort *voltha.LogicalPort
409 var err error
npujar467fe752020-01-16 20:17:45 +0530410 if logicalPort, err = ldMgr.getLogicalPort(ctx, lPortID); err != nil {
Girish Kumarf56a4682020-03-20 20:07:46 +0000411 logger.Debugw("no-logical-device-port-present", log.Fields{"logicalPortId": lPortID.PortId})
khenaidoo19d7b632018-10-30 10:49:50 -0400412 return err
413 }
khenaidoo92e62c52018-10-03 14:02:54 -0400414 // Sanity check
khenaidoo19d7b632018-10-30 10:49:50 -0400415 if logicalPort.RootPort {
khenaidoo2c6a0992019-04-29 13:46:56 -0400416 return errors.New("device-root")
khenaidoo92e62c52018-10-03 14:02:54 -0400417 }
npujar467fe752020-01-16 20:17:45 +0530418 if agent := ldMgr.getLogicalDeviceAgent(ctx, lPortID.Id); agent != nil {
419 if err := agent.deleteLogicalPort(ctx, logicalPort); err != nil {
Girish Kumarf56a4682020-03-20 20:07:46 +0000420 logger.Warnw("deleting-logicalport-failed", log.Fields{"LDeviceId": lPortID.Id, "error": err})
khenaidoo0a822f92019-05-08 15:15:57 -0400421 }
khenaidoo92e62c52018-10-03 14:02:54 -0400422 }
423
Girish Kumarf56a4682020-03-20 20:07:46 +0000424 logger.Debug("deleting-logical-port-ends")
khenaidoo92e62c52018-10-03 14:02:54 -0400425 return nil
426}
427
khenaidoo0a822f92019-05-08 15:15:57 -0400428// deleteLogicalPort removes the logical port associated with a child device
npujar467fe752020-01-16 20:17:45 +0530429func (ldMgr *LogicalDeviceManager) deleteLogicalPorts(ctx context.Context, deviceID string) error {
Girish Kumarf56a4682020-03-20 20:07:46 +0000430 logger.Debugw("deleting-logical-ports", log.Fields{"deviceId": deviceID})
khenaidoo0a822f92019-05-08 15:15:57 -0400431 // Get logical port
npujar467fe752020-01-16 20:17:45 +0530432 ldID, err := ldMgr.getLogicalDeviceIDFromDeviceID(ctx, deviceID)
npujar1d86a522019-11-14 17:11:16 +0530433 if err != nil {
khenaidoo0a822f92019-05-08 15:15:57 -0400434 return err
npujar1d86a522019-11-14 17:11:16 +0530435 }
npujar467fe752020-01-16 20:17:45 +0530436 if agent := ldMgr.getLogicalDeviceAgent(ctx, *ldID); agent != nil {
437 if err = agent.deleteLogicalPorts(ctx, deviceID); err != nil {
Girish Kumarf56a4682020-03-20 20:07:46 +0000438 logger.Warnw("deleteLogicalPorts-failed", log.Fields{"ldeviceId": *ldID})
npujar1d86a522019-11-14 17:11:16 +0530439 return err
khenaidoo0a822f92019-05-08 15:15:57 -0400440 }
441 }
Girish Kumarf56a4682020-03-20 20:07:46 +0000442 logger.Debug("deleting-logical-port-ends")
khenaidoo0a822f92019-05-08 15:15:57 -0400443 return nil
444}
445
khenaidoofc1314d2019-03-14 09:34:21 -0400446func (ldMgr *LogicalDeviceManager) setupUNILogicalPorts(ctx context.Context, childDevice *voltha.Device) error {
Girish Kumarf56a4682020-03-20 20:07:46 +0000447 logger.Debugw("setupUNILogicalPorts", log.Fields{"childDeviceId": childDevice.Id, "parentDeviceId": childDevice.ParentId, "current-data": childDevice})
khenaidoob9203542018-09-17 22:56:37 -0400448 // Sanity check
449 if childDevice.Root {
450 return errors.New("Device-root")
451 }
452
453 // Get the logical device id parent device
npujar1d86a522019-11-14 17:11:16 +0530454 parentID := childDevice.ParentId
npujar467fe752020-01-16 20:17:45 +0530455 logDeviceID := ldMgr.deviceMgr.GetParentDeviceID(ctx, parentID)
khenaidoob9203542018-09-17 22:56:37 -0400456
Girish Kumarf56a4682020-03-20 20:07:46 +0000457 logger.Debugw("setupUNILogicalPorts", log.Fields{"logDeviceId": logDeviceID, "parentId": parentID})
khenaidoob9203542018-09-17 22:56:37 -0400458
npujar1d86a522019-11-14 17:11:16 +0530459 if parentID == "" || logDeviceID == "" {
khenaidoo2c6a0992019-04-29 13:46:56 -0400460 return errors.New("device-in-invalid-state")
khenaidoo5e677ae2019-02-28 17:26:29 -0500461 }
462
npujar467fe752020-01-16 20:17:45 +0530463 if agent := ldMgr.getLogicalDeviceAgent(ctx, logDeviceID); agent != nil {
khenaidoofc1314d2019-03-14 09:34:21 -0400464 if err := agent.setupUNILogicalPorts(ctx, childDevice); err != nil {
khenaidoobcf205b2019-01-25 22:21:14 -0500465 return err
466 }
khenaidoob9203542018-09-17 22:56:37 -0400467 }
khenaidoo21d51152019-02-01 13:48:37 -0500468 return nil
khenaidoob9203542018-09-17 22:56:37 -0400469}
khenaidoo19d7b632018-10-30 10:49:50 -0400470
npujar467fe752020-01-16 20:17:45 +0530471func (ldMgr *LogicalDeviceManager) deleteAllLogicalPorts(ctx context.Context, device *voltha.Device) error {
Girish Kumarf56a4682020-03-20 20:07:46 +0000472 logger.Debugw("deleteAllLogicalPorts", log.Fields{"deviceId": device.Id})
khenaidoo0a822f92019-05-08 15:15:57 -0400473
npujar1d86a522019-11-14 17:11:16 +0530474 var ldID *string
khenaidoo0a822f92019-05-08 15:15:57 -0400475 var err error
476 //Get the logical device Id for this device
npujar467fe752020-01-16 20:17:45 +0530477 if ldID, err = ldMgr.getLogicalDeviceID(ctx, device); err != nil {
Girish Kumarf56a4682020-03-20 20:07:46 +0000478 logger.Warnw("no-logical-device-found", log.Fields{"deviceId": device.Id, "error": err})
khenaidoo0a822f92019-05-08 15:15:57 -0400479 return err
480 }
npujar467fe752020-01-16 20:17:45 +0530481 if agent := ldMgr.getLogicalDeviceAgent(ctx, *ldID); agent != nil {
Girish Gowdra408cd962020-03-11 14:31:31 -0700482 if err := agent.deleteAllLogicalPorts(ctx); err != nil {
khenaidoo0a822f92019-05-08 15:15:57 -0400483 return err
484 }
485 }
486 return nil
487}
Hardik Windlassc704def2020-02-26 18:23:19 +0000488
489func (ldMgr *LogicalDeviceManager) deleteAllUNILogicalPorts(ctx context.Context, parentDevice *voltha.Device) error {
Girish Kumarf56a4682020-03-20 20:07:46 +0000490 logger.Debugw("delete-all-uni-logical-ports", log.Fields{"parent-device-id": parentDevice.Id})
Hardik Windlassc704def2020-02-26 18:23:19 +0000491
492 var ldID *string
493 var err error
494 //Get the logical device Id for this device
495 if ldID, err = ldMgr.getLogicalDeviceID(ctx, parentDevice); err != nil {
496 return err
497 }
498 if agent := ldMgr.getLogicalDeviceAgent(ctx, *ldID); agent != nil {
499 if err := agent.deleteAllUNILogicalPorts(ctx, parentDevice); err != nil {
500 return err
501 }
502 }
503 return nil
504}
505
npujar467fe752020-01-16 20:17:45 +0530506func (ldMgr *LogicalDeviceManager) updatePortState(ctx context.Context, deviceID string, portNo uint32, state voltha.OperStatus_Types) error {
Girish Kumarf56a4682020-03-20 20:07:46 +0000507 logger.Debugw("updatePortState", log.Fields{"deviceId": deviceID, "state": state, "portNo": portNo})
khenaidoo171b98e2019-10-31 11:48:15 -0400508
npujar1d86a522019-11-14 17:11:16 +0530509 var ldID *string
khenaidoo171b98e2019-10-31 11:48:15 -0400510 var err error
511 //Get the logical device Id for this device
npujar467fe752020-01-16 20:17:45 +0530512 if ldID, err = ldMgr.getLogicalDeviceIDFromDeviceID(ctx, deviceID); err != nil {
Girish Kumarf56a4682020-03-20 20:07:46 +0000513 logger.Warnw("no-logical-device-found", log.Fields{"deviceId": deviceID, "error": err})
khenaidoo171b98e2019-10-31 11:48:15 -0400514 return err
515 }
npujar467fe752020-01-16 20:17:45 +0530516 if agent := ldMgr.getLogicalDeviceAgent(ctx, *ldID); agent != nil {
517 if err := agent.updatePortState(ctx, deviceID, portNo, state); err != nil {
khenaidoo171b98e2019-10-31 11:48:15 -0400518 return err
519 }
520 }
521 return nil
522}
khenaidoo0a822f92019-05-08 15:15:57 -0400523
kesavandbc2d1622020-01-21 00:42:01 -0500524func (ldMgr *LogicalDeviceManager) updatePortsState(ctx context.Context, device *voltha.Device, state voltha.OperStatus_Types) error {
Girish Kumarf56a4682020-03-20 20:07:46 +0000525 logger.Debugw("updatePortsState", log.Fields{"deviceId": device.Id, "state": state, "current-data": device})
khenaidoo3ab34882019-05-02 21:33:30 -0400526
npujar1d86a522019-11-14 17:11:16 +0530527 var ldID *string
khenaidoo3ab34882019-05-02 21:33:30 -0400528 var err error
529 //Get the logical device Id for this device
npujar467fe752020-01-16 20:17:45 +0530530 if ldID, err = ldMgr.getLogicalDeviceID(ctx, device); err != nil {
Girish Kumarf56a4682020-03-20 20:07:46 +0000531 logger.Warnw("no-logical-device-found", log.Fields{"deviceId": device.Id, "error": err})
khenaidoo3ab34882019-05-02 21:33:30 -0400532 return err
533 }
npujar467fe752020-01-16 20:17:45 +0530534 if agent := ldMgr.getLogicalDeviceAgent(ctx, *ldID); agent != nil {
535 if err := agent.updatePortsState(ctx, device, state); err != nil {
khenaidoo3ab34882019-05-02 21:33:30 -0400536 return err
537 }
538 }
539 return nil
540}
541
khenaidoo19d7b632018-10-30 10:49:50 -0400542func (ldMgr *LogicalDeviceManager) updateFlowTable(ctx context.Context, id string, flow *openflow_13.OfpFlowMod, ch chan interface{}) {
Girish Kumarf56a4682020-03-20 20:07:46 +0000543 logger.Debugw("updateFlowTable", log.Fields{"logicalDeviceId": id})
khenaidoo19d7b632018-10-30 10:49:50 -0400544 var res interface{}
npujar467fe752020-01-16 20:17:45 +0530545 if agent := ldMgr.getLogicalDeviceAgent(ctx, id); agent != nil {
khenaidoo19d7b632018-10-30 10:49:50 -0400546 res = agent.updateFlowTable(ctx, flow)
Girish Kumarf56a4682020-03-20 20:07:46 +0000547 logger.Debugw("updateFlowTable-result", log.Fields{"result": res})
khenaidoo19d7b632018-10-30 10:49:50 -0400548 } else {
549 res = status.Errorf(codes.NotFound, "%s", id)
550 }
551 sendAPIResponse(ctx, ch, res)
552}
553
Manikkaraj kb1a10922019-07-29 12:10:34 -0400554func (ldMgr *LogicalDeviceManager) updateMeterTable(ctx context.Context, id string, meter *openflow_13.OfpMeterMod, ch chan interface{}) {
Girish Kumarf56a4682020-03-20 20:07:46 +0000555 logger.Debugw("updateMeterTable", log.Fields{"logicalDeviceId": id})
Manikkaraj kb1a10922019-07-29 12:10:34 -0400556 var res interface{}
npujar467fe752020-01-16 20:17:45 +0530557 if agent := ldMgr.getLogicalDeviceAgent(ctx, id); agent != nil {
Manikkaraj kb1a10922019-07-29 12:10:34 -0400558 res = agent.updateMeterTable(ctx, meter)
Girish Kumarf56a4682020-03-20 20:07:46 +0000559 logger.Debugw("updateMeterTable-result", log.Fields{"result": res})
Manikkaraj kb1a10922019-07-29 12:10:34 -0400560 } else {
561 res = status.Errorf(codes.NotFound, "%s", id)
562 }
563 sendAPIResponse(ctx, ch, res)
564}
565
npujar1d86a522019-11-14 17:11:16 +0530566// ListLogicalDeviceMeters returns logical device meters
Manikkaraj kb1a10922019-07-29 12:10:34 -0400567func (ldMgr *LogicalDeviceManager) ListLogicalDeviceMeters(ctx context.Context, id string) (*openflow_13.Meters, error) {
Girish Kumarf56a4682020-03-20 20:07:46 +0000568 logger.Debugw("ListLogicalDeviceMeters", log.Fields{"logicalDeviceId": id})
npujar467fe752020-01-16 20:17:45 +0530569 if agent := ldMgr.getLogicalDeviceAgent(ctx, id); agent != nil {
khenaidoo442e7c72020-03-10 16:13:48 -0400570 return agent.ListLogicalDeviceMeters(ctx)
Manikkaraj kb1a10922019-07-29 12:10:34 -0400571 }
572 return nil, status.Errorf(codes.NotFound, "%s", id)
573}
khenaidoo19d7b632018-10-30 10:49:50 -0400574func (ldMgr *LogicalDeviceManager) updateGroupTable(ctx context.Context, id string, groupMod *openflow_13.OfpGroupMod, ch chan interface{}) {
Girish Kumarf56a4682020-03-20 20:07:46 +0000575 logger.Debugw("updateGroupTable", log.Fields{"logicalDeviceId": id})
khenaidoo19d7b632018-10-30 10:49:50 -0400576 var res interface{}
npujar467fe752020-01-16 20:17:45 +0530577 if agent := ldMgr.getLogicalDeviceAgent(ctx, id); agent != nil {
khenaidoo19d7b632018-10-30 10:49:50 -0400578 res = agent.updateGroupTable(ctx, groupMod)
Girish Kumarf56a4682020-03-20 20:07:46 +0000579 logger.Debugw("updateGroupTable-result", log.Fields{"result": res})
khenaidoo19d7b632018-10-30 10:49:50 -0400580 } else {
581 res = status.Errorf(codes.NotFound, "%s", id)
582 }
583 sendAPIResponse(ctx, ch, res)
584}
585
586func (ldMgr *LogicalDeviceManager) enableLogicalPort(ctx context.Context, id *voltha.LogicalPortId, ch chan interface{}) {
Girish Kumarf56a4682020-03-20 20:07:46 +0000587 logger.Debugw("enableLogicalPort", log.Fields{"logicalDeviceId": id})
khenaidoo19d7b632018-10-30 10:49:50 -0400588 var res interface{}
npujar467fe752020-01-16 20:17:45 +0530589 if agent := ldMgr.getLogicalDeviceAgent(ctx, id.Id); agent != nil {
590 res = agent.enableLogicalPort(ctx, id.PortId)
Girish Kumarf56a4682020-03-20 20:07:46 +0000591 logger.Debugw("enableLogicalPort-result", log.Fields{"result": res})
khenaidoo19d7b632018-10-30 10:49:50 -0400592 } else {
593 res = status.Errorf(codes.NotFound, "%s", id.Id)
594 }
595 sendAPIResponse(ctx, ch, res)
596}
597
598func (ldMgr *LogicalDeviceManager) disableLogicalPort(ctx context.Context, id *voltha.LogicalPortId, ch chan interface{}) {
Girish Kumarf56a4682020-03-20 20:07:46 +0000599 logger.Debugw("disableLogicalPort", log.Fields{"logicalDeviceId": id})
khenaidoo19d7b632018-10-30 10:49:50 -0400600 var res interface{}
npujar467fe752020-01-16 20:17:45 +0530601 if agent := ldMgr.getLogicalDeviceAgent(ctx, id.Id); agent != nil {
602 res = agent.disableLogicalPort(ctx, id.PortId)
Girish Kumarf56a4682020-03-20 20:07:46 +0000603 logger.Debugw("disableLogicalPort-result", log.Fields{"result": res})
khenaidoo19d7b632018-10-30 10:49:50 -0400604 } else {
605 res = status.Errorf(codes.NotFound, "%s", id.Id)
606 }
607 sendAPIResponse(ctx, ch, res)
608}
khenaidoofdbad6e2018-11-06 22:26:38 -0500609
npujar467fe752020-01-16 20:17:45 +0530610func (ldMgr *LogicalDeviceManager) packetIn(ctx context.Context, logicalDeviceID string, port uint32, transactionID string, packet []byte) error {
Girish Kumarf56a4682020-03-20 20:07:46 +0000611 logger.Debugw("packetIn", log.Fields{"logicalDeviceId": logicalDeviceID, "port": port})
npujar467fe752020-01-16 20:17:45 +0530612 if agent := ldMgr.getLogicalDeviceAgent(ctx, logicalDeviceID); agent != nil {
npujar1d86a522019-11-14 17:11:16 +0530613 agent.packetIn(port, transactionID, packet)
khenaidoofdbad6e2018-11-06 22:26:38 -0500614 } else {
Girish Kumarf56a4682020-03-20 20:07:46 +0000615 logger.Error("logical-device-not-exist", log.Fields{"logicalDeviceId": logicalDeviceID})
khenaidoofdbad6e2018-11-06 22:26:38 -0500616 }
617 return nil
618}