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 | */ |
| 16 | package core |
| 17 | |
| 18 | import ( |
| 19 | "context" |
| 20 | "errors" |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 21 | "github.com/opencord/voltha-go/db/model" |
Scott Baker | 807addd | 2019-10-24 15:16:21 -0700 | [diff] [blame] | 22 | "github.com/opencord/voltha-lib-go/v2/pkg/kafka" |
| 23 | "github.com/opencord/voltha-lib-go/v2/pkg/log" |
| 24 | "github.com/opencord/voltha-lib-go/v2/pkg/probe" |
Scott Baker | 555307d | 2019-11-04 08:58:01 -0800 | [diff] [blame] | 25 | "github.com/opencord/voltha-protos/v2/go/openflow_13" |
| 26 | "github.com/opencord/voltha-protos/v2/go/voltha" |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 27 | "google.golang.org/grpc/codes" |
| 28 | "google.golang.org/grpc/status" |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 29 | "strings" |
| 30 | "sync" |
| 31 | ) |
| 32 | |
| 33 | type LogicalDeviceManager struct { |
khenaidoo | 4c9e559 | 2019-09-09 16:20:41 -0400 | [diff] [blame] | 34 | logicalDeviceAgents sync.Map |
| 35 | core *Core |
| 36 | deviceMgr *DeviceManager |
| 37 | grpcNbiHdlr *APIHandler |
| 38 | adapterProxy *AdapterProxy |
| 39 | kafkaICProxy *kafka.InterContainerProxy |
| 40 | clusterDataProxy *model.Proxy |
| 41 | exitChannel chan int |
| 42 | defaultTimeout int64 |
| 43 | logicalDevicesLoadingLock sync.RWMutex |
| 44 | logicalDeviceLoadingInProgress map[string][]chan int |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 45 | } |
| 46 | |
khenaidoo | 2c6a099 | 2019-04-29 13:46:56 -0400 | [diff] [blame] | 47 | func newLogicalDeviceManager(core *Core, deviceMgr *DeviceManager, kafkaICProxy *kafka.InterContainerProxy, cdProxy *model.Proxy, timeout int64) *LogicalDeviceManager { |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 48 | var logicalDeviceMgr LogicalDeviceManager |
Richard Jankowski | 199fd86 | 2019-03-18 14:49:51 -0400 | [diff] [blame] | 49 | logicalDeviceMgr.core = core |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 50 | logicalDeviceMgr.exitChannel = make(chan int, 1) |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 51 | logicalDeviceMgr.deviceMgr = deviceMgr |
khenaidoo | 43c8212 | 2018-11-22 18:38:28 -0500 | [diff] [blame] | 52 | logicalDeviceMgr.kafkaICProxy = kafkaICProxy |
khenaidoo | 9a46896 | 2018-09-19 15:33:13 -0400 | [diff] [blame] | 53 | logicalDeviceMgr.clusterDataProxy = cdProxy |
khenaidoo | 2c6a099 | 2019-04-29 13:46:56 -0400 | [diff] [blame] | 54 | logicalDeviceMgr.defaultTimeout = timeout |
khenaidoo | 4c9e559 | 2019-09-09 16:20:41 -0400 | [diff] [blame] | 55 | logicalDeviceMgr.logicalDevicesLoadingLock = sync.RWMutex{} |
| 56 | logicalDeviceMgr.logicalDeviceLoadingInProgress = make(map[string][]chan int) |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 57 | return &logicalDeviceMgr |
| 58 | } |
| 59 | |
Richard Jankowski | dbab94a | 2018-12-06 16:20:25 -0500 | [diff] [blame] | 60 | func (ldMgr *LogicalDeviceManager) setGrpcNbiHandler(grpcNbiHandler *APIHandler) { |
| 61 | ldMgr.grpcNbiHdlr = grpcNbiHandler |
| 62 | } |
| 63 | |
khenaidoo | 4d4802d | 2018-10-04 21:59:49 -0400 | [diff] [blame] | 64 | func (ldMgr *LogicalDeviceManager) start(ctx context.Context) { |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 65 | log.Info("starting-logical-device-manager") |
David K. Bainbridge | b4a9ab0 | 2019-09-20 15:12:16 -0700 | [diff] [blame] | 66 | probe.UpdateStatusFromContext(ctx, "logical-device-manager", probe.ServiceStatusRunning) |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 67 | log.Info("logical-device-manager-started") |
| 68 | } |
| 69 | |
khenaidoo | 4d4802d | 2018-10-04 21:59:49 -0400 | [diff] [blame] | 70 | func (ldMgr *LogicalDeviceManager) stop(ctx context.Context) { |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 71 | log.Info("stopping-logical-device-manager") |
| 72 | ldMgr.exitChannel <- 1 |
David K. Bainbridge | b4a9ab0 | 2019-09-20 15:12:16 -0700 | [diff] [blame] | 73 | probe.UpdateStatusFromContext(ctx, "logical-device-manager", probe.ServiceStatusStopped) |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 74 | log.Info("logical-device-manager-stopped") |
| 75 | } |
| 76 | |
khenaidoo | 19d7b63 | 2018-10-30 10:49:50 -0400 | [diff] [blame] | 77 | func sendAPIResponse(ctx context.Context, ch chan interface{}, result interface{}) { |
| 78 | if ctx.Err() == nil { |
| 79 | // Returned response only of the ctx has not been cancelled/timeout/etc |
| 80 | // Channel is automatically closed when a context is Done |
| 81 | ch <- result |
| 82 | log.Debugw("sendResponse", log.Fields{"result": result}) |
| 83 | } else { |
| 84 | // Should the transaction be reverted back? |
| 85 | log.Debugw("sendResponse-context-error", log.Fields{"context-error": ctx.Err()}) |
| 86 | } |
| 87 | } |
| 88 | |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 89 | func (ldMgr *LogicalDeviceManager) addLogicalDeviceAgentToMap(agent *LogicalDeviceAgent) { |
Stephane Barbarie | ef6650d | 2019-07-18 12:15:09 -0400 | [diff] [blame] | 90 | if _, exist := ldMgr.logicalDeviceAgents.Load(agent.logicalDeviceId); !exist { |
| 91 | ldMgr.logicalDeviceAgents.Store(agent.logicalDeviceId, agent) |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 92 | } |
| 93 | } |
| 94 | |
khenaidoo | 6d62c00 | 2019-05-15 21:57:03 -0400 | [diff] [blame] | 95 | func (ldMgr *LogicalDeviceManager) isLogicalDeviceInCache(logicalDeviceId string) bool { |
Stephane Barbarie | ef6650d | 2019-07-18 12:15:09 -0400 | [diff] [blame] | 96 | _, inCache := ldMgr.logicalDeviceAgents.Load(logicalDeviceId) |
khenaidoo | 6d62c00 | 2019-05-15 21:57:03 -0400 | [diff] [blame] | 97 | return inCache |
| 98 | } |
| 99 | |
khenaidoo | 8c3303d | 2019-02-13 14:59:39 -0500 | [diff] [blame] | 100 | // getLogicalDeviceAgent returns the logical device agent. If the device is not in memory then the device will |
| 101 | // be loaded from dB and a logical device agent created to managed it. |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 102 | func (ldMgr *LogicalDeviceManager) getLogicalDeviceAgent(logicalDeviceId string) *LogicalDeviceAgent { |
Stephane Barbarie | ef6650d | 2019-07-18 12:15:09 -0400 | [diff] [blame] | 103 | if agent, ok := ldMgr.logicalDeviceAgents.Load(logicalDeviceId); ok { |
| 104 | return agent.(*LogicalDeviceAgent) |
khenaidoo | 8c3303d | 2019-02-13 14:59:39 -0500 | [diff] [blame] | 105 | } else { |
| 106 | // Try to load into memory - loading will also create the logical device agent |
khenaidoo | 8c3303d | 2019-02-13 14:59:39 -0500 | [diff] [blame] | 107 | if err := ldMgr.load(logicalDeviceId); err == nil { |
Stephane Barbarie | ef6650d | 2019-07-18 12:15:09 -0400 | [diff] [blame] | 108 | if agent, ok = ldMgr.logicalDeviceAgents.Load(logicalDeviceId); ok { |
| 109 | return agent.(*LogicalDeviceAgent) |
khenaidoo | 8c3303d | 2019-02-13 14:59:39 -0500 | [diff] [blame] | 110 | } |
| 111 | } |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 112 | } |
| 113 | return nil |
| 114 | } |
| 115 | |
khenaidoo | 92e62c5 | 2018-10-03 14:02:54 -0400 | [diff] [blame] | 116 | func (ldMgr *LogicalDeviceManager) deleteLogicalDeviceAgent(logicalDeviceId string) { |
Stephane Barbarie | ef6650d | 2019-07-18 12:15:09 -0400 | [diff] [blame] | 117 | ldMgr.logicalDeviceAgents.Delete(logicalDeviceId) |
khenaidoo | 92e62c5 | 2018-10-03 14:02:54 -0400 | [diff] [blame] | 118 | } |
| 119 | |
khenaidoo | 8c3303d | 2019-02-13 14:59:39 -0500 | [diff] [blame] | 120 | // GetLogicalDevice provides a cloned most up to date logical device. If device is not in memory |
| 121 | // it will be fetched from the dB |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 122 | func (ldMgr *LogicalDeviceManager) getLogicalDevice(id string) (*voltha.LogicalDevice, error) { |
khenaidoo | 92e62c5 | 2018-10-03 14:02:54 -0400 | [diff] [blame] | 123 | log.Debugw("getlogicalDevice", log.Fields{"logicaldeviceid": id}) |
| 124 | if agent := ldMgr.getLogicalDeviceAgent(id); agent != nil { |
khenaidoo | 19d7b63 | 2018-10-30 10:49:50 -0400 | [diff] [blame] | 125 | return agent.GetLogicalDevice() |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 126 | } |
| 127 | return nil, status.Errorf(codes.NotFound, "%s", id) |
| 128 | } |
| 129 | |
khenaidoo | 43aa6bd | 2019-05-29 13:35:13 -0400 | [diff] [blame] | 130 | func (ldMgr *LogicalDeviceManager) listManagedLogicalDevices() (*voltha.LogicalDevices, error) { |
| 131 | log.Debug("listManagedLogicalDevices") |
| 132 | result := &voltha.LogicalDevices{} |
Stephane Barbarie | ef6650d | 2019-07-18 12:15:09 -0400 | [diff] [blame] | 133 | ldMgr.logicalDeviceAgents.Range(func(key, value interface{}) bool { |
| 134 | agent := value.(*LogicalDeviceAgent) |
khenaidoo | 43aa6bd | 2019-05-29 13:35:13 -0400 | [diff] [blame] | 135 | if ld, _ := agent.GetLogicalDevice(); ld != nil { |
| 136 | result.Items = append(result.Items, ld) |
| 137 | } |
Stephane Barbarie | ef6650d | 2019-07-18 12:15:09 -0400 | [diff] [blame] | 138 | return true |
| 139 | }) |
| 140 | |
khenaidoo | 43aa6bd | 2019-05-29 13:35:13 -0400 | [diff] [blame] | 141 | return result, nil |
| 142 | } |
| 143 | |
khenaidoo | ba6b6c4 | 2019-08-02 09:11:56 -0400 | [diff] [blame] | 144 | //listLogicalDevices returns the list of all logical devices |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 145 | func (ldMgr *LogicalDeviceManager) listLogicalDevices() (*voltha.LogicalDevices, error) { |
Stephane Barbarie | 1ab4327 | 2018-12-08 21:42:13 -0500 | [diff] [blame] | 146 | log.Debug("ListAllLogicalDevices") |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 147 | result := &voltha.LogicalDevices{} |
khenaidoo | a9cc6d0 | 2019-11-20 14:56:59 -0500 | [diff] [blame^] | 148 | if logicalDevices := ldMgr.clusterDataProxy.List(context.Background(), "/logical_devices", 0, true, ""); logicalDevices != nil { |
Stephane Barbarie | 1ab4327 | 2018-12-08 21:42:13 -0500 | [diff] [blame] | 149 | for _, logicalDevice := range logicalDevices.([]interface{}) { |
Stephane Barbarie | 1ab4327 | 2018-12-08 21:42:13 -0500 | [diff] [blame] | 150 | result.Items = append(result.Items, logicalDevice.(*voltha.LogicalDevice)) |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 151 | } |
| 152 | } |
| 153 | return result, nil |
| 154 | } |
| 155 | |
khenaidoo | 4d4802d | 2018-10-04 21:59:49 -0400 | [diff] [blame] | 156 | func (ldMgr *LogicalDeviceManager) createLogicalDevice(ctx context.Context, device *voltha.Device) (*string, error) { |
khenaidoo | 92e62c5 | 2018-10-03 14:02:54 -0400 | [diff] [blame] | 157 | log.Debugw("creating-logical-device", log.Fields{"deviceId": device.Id}) |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 158 | // Sanity check |
| 159 | if !device.Root { |
khenaidoo | 2c6a099 | 2019-04-29 13:46:56 -0400 | [diff] [blame] | 160 | return nil, errors.New("device-not-root") |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 161 | } |
| 162 | |
| 163 | // Create a logical device agent - the logical device Id is based on the mac address of the device |
| 164 | // For now use the serial number - it may contain any combination of alphabetic characters and numbers, |
| 165 | // with length varying from eight characters to a maximum of 14 characters. Mac Address is part of oneof |
| 166 | // in the Device model. May need to be moved out. |
| 167 | macAddress := device.MacAddress |
| 168 | id := strings.Replace(macAddress, ":", "", -1) |
khenaidoo | 92e62c5 | 2018-10-03 14:02:54 -0400 | [diff] [blame] | 169 | if id == "" { |
| 170 | log.Errorw("mac-address-not-set", log.Fields{"deviceId": device.Id}) |
| 171 | return nil, errors.New("mac-address-not-set") |
| 172 | } |
| 173 | log.Debugw("logical-device-id", log.Fields{"logicaldeviceId": id}) |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 174 | |
khenaidoo | 2c6a099 | 2019-04-29 13:46:56 -0400 | [diff] [blame] | 175 | agent := newLogicalDeviceAgent(id, device.Id, ldMgr, ldMgr.deviceMgr, ldMgr.clusterDataProxy, ldMgr.defaultTimeout) |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 176 | ldMgr.addLogicalDeviceAgentToMap(agent) |
khenaidoo | ad06fd7 | 2019-10-28 12:26:05 -0400 | [diff] [blame] | 177 | |
| 178 | // Update the root device with the logical device Id reference |
| 179 | if err := ldMgr.deviceMgr.setParentId(device, id); err != nil { |
| 180 | log.Errorw("failed-setting-parent-id", log.Fields{"logicalDeviceId": id, "deviceId": device.Id}) |
| 181 | return nil, err |
| 182 | } |
| 183 | |
khenaidoo | 297cd25 | 2019-02-07 22:10:23 -0500 | [diff] [blame] | 184 | go agent.start(ctx, false) |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 185 | |
khenaidoo | 92e62c5 | 2018-10-03 14:02:54 -0400 | [diff] [blame] | 186 | log.Debug("creating-logical-device-ends") |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 187 | return &id, nil |
| 188 | } |
| 189 | |
khenaidoo | 6d62c00 | 2019-05-15 21:57:03 -0400 | [diff] [blame] | 190 | // stopManagingLogicalDeviceWithDeviceId stops the management of the logical device. This implies removal of any |
| 191 | // reference of this logical device in cache. The device Id is passed as param because the logical device may already |
| 192 | // have been removed from the model. This function returns the logical device Id if found |
| 193 | func (ldMgr *LogicalDeviceManager) stopManagingLogicalDeviceWithDeviceId(id string) string { |
| 194 | log.Infow("stop-managing-logical-device", log.Fields{"deviceId": id}) |
| 195 | // Go over the list of logical device agents to find the one which has rootDeviceId as id |
Stephane Barbarie | ef6650d | 2019-07-18 12:15:09 -0400 | [diff] [blame] | 196 | var ldId = "" |
| 197 | ldMgr.logicalDeviceAgents.Range(func(key, value interface{}) bool { |
| 198 | ldAgent := value.(*LogicalDeviceAgent) |
khenaidoo | 6d62c00 | 2019-05-15 21:57:03 -0400 | [diff] [blame] | 199 | if ldAgent.rootDeviceId == id { |
Stephane Barbarie | ef6650d | 2019-07-18 12:15:09 -0400 | [diff] [blame] | 200 | log.Infow("stopping-logical-device-agent", log.Fields{"lDeviceId": key}) |
khenaidoo | 6d62c00 | 2019-05-15 21:57:03 -0400 | [diff] [blame] | 201 | ldAgent.stop(nil) |
Stephane Barbarie | ef6650d | 2019-07-18 12:15:09 -0400 | [diff] [blame] | 202 | ldId = key.(string) |
Stephane Barbarie | eb33605 | 2019-10-24 15:40:59 -0400 | [diff] [blame] | 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 | }) |
| 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. |
| 211 | func (ldMgr *LogicalDeviceManager) getLogicalDeviceFromModel(lDeviceId string) (*voltha.LogicalDevice, error) { |
Stephane Barbarie | ef6650d | 2019-07-18 12:15:09 -0400 | [diff] [blame] | 212 | if logicalDevice := ldMgr.clusterDataProxy.Get(context.Background(), "/logical_devices/"+lDeviceId, 0, false, ""); logicalDevice != nil { |
khenaidoo | 6d62c00 | 2019-05-15 21:57:03 -0400 | [diff] [blame] | 213 | if lDevice, ok := logicalDevice.(*voltha.LogicalDevice); ok { |
| 214 | return lDevice, nil |
| 215 | } |
| 216 | } |
| 217 | return nil, status.Error(codes.NotFound, lDeviceId) |
| 218 | } |
| 219 | |
khenaidoo | 297cd25 | 2019-02-07 22:10:23 -0500 | [diff] [blame] | 220 | // load loads a logical device manager in memory |
| 221 | func (ldMgr *LogicalDeviceManager) load(lDeviceId string) error { |
khenaidoo | 4c9e559 | 2019-09-09 16:20:41 -0400 | [diff] [blame] | 222 | if lDeviceId == "" { |
| 223 | return nil |
khenaidoo | 297cd25 | 2019-02-07 22:10:23 -0500 | [diff] [blame] | 224 | } |
khenaidoo | 4c9e559 | 2019-09-09 16:20:41 -0400 | [diff] [blame] | 225 | // Add a lock to prevent two concurrent calls from loading the same device twice |
| 226 | ldMgr.logicalDevicesLoadingLock.Lock() |
| 227 | if _, exist := ldMgr.logicalDeviceLoadingInProgress[lDeviceId]; !exist { |
| 228 | if ldAgent, _ := ldMgr.logicalDeviceAgents.Load(lDeviceId); ldAgent == nil { |
| 229 | ldMgr.logicalDeviceLoadingInProgress[lDeviceId] = []chan int{make(chan int, 1)} |
| 230 | ldMgr.logicalDevicesLoadingLock.Unlock() |
| 231 | if _, err := ldMgr.getLogicalDeviceFromModel(lDeviceId); err == nil { |
| 232 | log.Debugw("loading-logical-device", log.Fields{"lDeviceId": lDeviceId}) |
| 233 | agent := newLogicalDeviceAgent(lDeviceId, "", ldMgr, ldMgr.deviceMgr, ldMgr.clusterDataProxy, ldMgr.defaultTimeout) |
| 234 | if err := agent.start(nil, true); err != nil { |
| 235 | agent.stop(nil) |
| 236 | } else { |
| 237 | ldMgr.logicalDeviceAgents.Store(agent.logicalDeviceId, agent) |
| 238 | } |
| 239 | } else { |
| 240 | log.Debugw("logicalDevice not in model", log.Fields{"lDeviceId": lDeviceId}) |
| 241 | } |
| 242 | // announce completion of task to any number of waiting channels |
| 243 | ldMgr.logicalDevicesLoadingLock.Lock() |
| 244 | if v, ok := ldMgr.logicalDeviceLoadingInProgress[lDeviceId]; ok { |
| 245 | for _, ch := range v { |
| 246 | close(ch) |
| 247 | } |
| 248 | delete(ldMgr.logicalDeviceLoadingInProgress, lDeviceId) |
| 249 | } |
| 250 | ldMgr.logicalDevicesLoadingLock.Unlock() |
| 251 | } else { |
| 252 | ldMgr.logicalDevicesLoadingLock.Unlock() |
| 253 | } |
| 254 | } else { |
| 255 | ch := make(chan int, 1) |
| 256 | ldMgr.logicalDeviceLoadingInProgress[lDeviceId] = append(ldMgr.logicalDeviceLoadingInProgress[lDeviceId], ch) |
| 257 | ldMgr.logicalDevicesLoadingLock.Unlock() |
| 258 | // Wait for the channel to be closed, implying the process loading this device is done. |
| 259 | <-ch |
| 260 | } |
| 261 | if _, exist := ldMgr.logicalDeviceAgents.Load(lDeviceId); exist { |
| 262 | return nil |
| 263 | } |
| 264 | return status.Errorf(codes.Aborted, "Error loading logical device %s", lDeviceId) |
khenaidoo | 297cd25 | 2019-02-07 22:10:23 -0500 | [diff] [blame] | 265 | } |
| 266 | |
khenaidoo | 4d4802d | 2018-10-04 21:59:49 -0400 | [diff] [blame] | 267 | func (ldMgr *LogicalDeviceManager) deleteLogicalDevice(ctx context.Context, device *voltha.Device) error { |
khenaidoo | 92e62c5 | 2018-10-03 14:02:54 -0400 | [diff] [blame] | 268 | log.Debugw("deleting-logical-device", log.Fields{"deviceId": device.Id}) |
| 269 | // Sanity check |
| 270 | if !device.Root { |
khenaidoo | 2c6a099 | 2019-04-29 13:46:56 -0400 | [diff] [blame] | 271 | return errors.New("device-not-root") |
khenaidoo | 92e62c5 | 2018-10-03 14:02:54 -0400 | [diff] [blame] | 272 | } |
| 273 | logDeviceId := device.ParentId |
| 274 | if agent := ldMgr.getLogicalDeviceAgent(logDeviceId); agent != nil { |
| 275 | // Stop the logical device agent |
khenaidoo | 4d4802d | 2018-10-04 21:59:49 -0400 | [diff] [blame] | 276 | agent.stop(ctx) |
khenaidoo | 92e62c5 | 2018-10-03 14:02:54 -0400 | [diff] [blame] | 277 | //Remove the logical device agent from the Map |
| 278 | ldMgr.deleteLogicalDeviceAgent(logDeviceId) |
Richard Jankowski | 199fd86 | 2019-03-18 14:49:51 -0400 | [diff] [blame] | 279 | ldMgr.core.deviceOwnership.AbandonDevice(logDeviceId) |
khenaidoo | 92e62c5 | 2018-10-03 14:02:54 -0400 | [diff] [blame] | 280 | } |
| 281 | |
| 282 | log.Debug("deleting-logical-device-ends") |
| 283 | return nil |
| 284 | } |
| 285 | |
| 286 | func (ldMgr *LogicalDeviceManager) getLogicalDeviceId(device *voltha.Device) (*string, error) { |
| 287 | // Device can either be a parent or a child device |
| 288 | if device.Root { |
| 289 | // Parent device. The ID of a parent device is the logical device ID |
| 290 | return &device.ParentId, nil |
| 291 | } |
| 292 | // Device is child device |
| 293 | // retrieve parent device using child device ID |
| 294 | if parentDevice := ldMgr.deviceMgr.getParentDevice(device); parentDevice != nil { |
| 295 | return &parentDevice.ParentId, nil |
| 296 | } |
| 297 | return nil, status.Errorf(codes.NotFound, "%s", device.Id) |
| 298 | } |
| 299 | |
khenaidoo | 3ab3488 | 2019-05-02 21:33:30 -0400 | [diff] [blame] | 300 | func (ldMgr *LogicalDeviceManager) getLogicalDeviceIdFromDeviceId(deviceId string) (*string, error) { |
| 301 | // Get the device |
| 302 | var device *voltha.Device |
| 303 | var err error |
| 304 | if device, err = ldMgr.deviceMgr.GetDevice(deviceId); err != nil { |
| 305 | return nil, err |
| 306 | } |
| 307 | return ldMgr.getLogicalDeviceId(device) |
| 308 | } |
| 309 | |
khenaidoo | 19d7b63 | 2018-10-30 10:49:50 -0400 | [diff] [blame] | 310 | func (ldMgr *LogicalDeviceManager) getLogicalPortId(device *voltha.Device) (*voltha.LogicalPortId, error) { |
| 311 | // Get the logical device where this device is attached |
| 312 | var lDeviceId *string |
| 313 | var err error |
| 314 | if lDeviceId, err = ldMgr.getLogicalDeviceId(device); err != nil { |
| 315 | return nil, err |
| 316 | } |
| 317 | var lDevice *voltha.LogicalDevice |
| 318 | if lDevice, err = ldMgr.getLogicalDevice(*lDeviceId); err != nil { |
| 319 | return nil, err |
| 320 | } |
| 321 | // Go over list of ports |
| 322 | for _, port := range lDevice.Ports { |
| 323 | if port.DeviceId == device.Id { |
| 324 | return &voltha.LogicalPortId{Id: *lDeviceId, PortId: port.Id}, nil |
| 325 | } |
| 326 | } |
| 327 | return nil, status.Errorf(codes.NotFound, "%s", device.Id) |
| 328 | } |
| 329 | |
khenaidoo | dd23717 | 2019-05-27 16:37:17 -0400 | [diff] [blame] | 330 | func (ldMgr *LogicalDeviceManager) ListLogicalDeviceFlows(ctx context.Context, id string) (*openflow_13.Flows, error) { |
| 331 | log.Debugw("ListLogicalDeviceFlows", log.Fields{"logicaldeviceid": id}) |
| 332 | if agent := ldMgr.getLogicalDeviceAgent(id); agent != nil { |
| 333 | return agent.ListLogicalDeviceFlows() |
| 334 | } |
| 335 | return nil, status.Errorf(codes.NotFound, "%s", id) |
| 336 | } |
| 337 | |
| 338 | func (ldMgr *LogicalDeviceManager) ListLogicalDeviceFlowGroups(ctx context.Context, id string) (*openflow_13.FlowGroups, error) { |
| 339 | log.Debugw("ListLogicalDeviceFlowGroups", log.Fields{"logicaldeviceid": id}) |
| 340 | if agent := ldMgr.getLogicalDeviceAgent(id); agent != nil { |
| 341 | return agent.ListLogicalDeviceFlowGroups() |
| 342 | } |
| 343 | return nil, status.Errorf(codes.NotFound, "%s", id) |
| 344 | } |
| 345 | |
khenaidoo | 19d7b63 | 2018-10-30 10:49:50 -0400 | [diff] [blame] | 346 | func (ldMgr *LogicalDeviceManager) ListLogicalDevicePorts(ctx context.Context, id string) (*voltha.LogicalPorts, error) { |
| 347 | log.Debugw("ListLogicalDevicePorts", log.Fields{"logicaldeviceid": id}) |
| 348 | if agent := ldMgr.getLogicalDeviceAgent(id); agent != nil { |
| 349 | return agent.ListLogicalDevicePorts() |
| 350 | } |
| 351 | return nil, status.Errorf(codes.NotFound, "%s", id) |
khenaidoo | 19d7b63 | 2018-10-30 10:49:50 -0400 | [diff] [blame] | 352 | } |
| 353 | |
| 354 | func (ldMgr *LogicalDeviceManager) getLogicalPort(lPortId *voltha.LogicalPortId) (*voltha.LogicalPort, error) { |
| 355 | // Get the logical device where this device is attached |
| 356 | var err error |
| 357 | var lDevice *voltha.LogicalDevice |
| 358 | if lDevice, err = ldMgr.getLogicalDevice(lPortId.Id); err != nil { |
| 359 | return nil, err |
| 360 | } |
| 361 | // Go over list of ports |
| 362 | for _, port := range lDevice.Ports { |
| 363 | if port.Id == lPortId.PortId { |
| 364 | return port, nil |
| 365 | } |
| 366 | } |
Kent Hagerman | 0ab4cb2 | 2019-04-24 13:13:35 -0400 | [diff] [blame] | 367 | return nil, status.Errorf(codes.NotFound, "%s-%s", lPortId.Id, lPortId.PortId) |
khenaidoo | 19d7b63 | 2018-10-30 10:49:50 -0400 | [diff] [blame] | 368 | } |
| 369 | |
khenaidoo | 2c6a099 | 2019-04-29 13:46:56 -0400 | [diff] [blame] | 370 | // updateLogicalPort sets up a logical port on the logical device based on the device port |
| 371 | // information, if needed |
| 372 | func (ldMgr *LogicalDeviceManager) updateLogicalPort(device *voltha.Device, port *voltha.Port) error { |
| 373 | if ldID, err := ldMgr.getLogicalDeviceId(device); err != nil || *ldID == "" { |
| 374 | // This is not an error as the logical device may not have been created at this time. In such a case, |
| 375 | // the ports will be created when the logical device is ready. |
| 376 | return nil |
| 377 | } else { |
| 378 | if agent := ldMgr.getLogicalDeviceAgent(*ldID); agent != nil { |
| 379 | if err := agent.updateLogicalPort(device, port); err != nil { |
| 380 | return err |
| 381 | } |
| 382 | } |
| 383 | } |
| 384 | return nil |
| 385 | } |
| 386 | |
khenaidoo | fc1314d | 2019-03-14 09:34:21 -0400 | [diff] [blame] | 387 | // addLogicalPort sets up a logical port on the logical device based on the device port |
| 388 | // information. |
| 389 | func (ldMgr *LogicalDeviceManager) addLogicalPort(device *voltha.Device, port *voltha.Port) error { |
Stephane Barbarie | 40fd3b2 | 2019-04-23 21:50:47 -0400 | [diff] [blame] | 390 | if ldID, err := ldMgr.getLogicalDeviceId(device); err != nil || *ldID == "" { |
khenaidoo | fc1314d | 2019-03-14 09:34:21 -0400 | [diff] [blame] | 391 | // This is not an error as the logical device may not have been created at this time. In such a case, |
| 392 | // the ports will be created when the logical device is ready. |
| 393 | return nil |
| 394 | } else { |
| 395 | if agent := ldMgr.getLogicalDeviceAgent(*ldID); agent != nil { |
| 396 | if err := agent.addLogicalPort(device, port); err != nil { |
| 397 | return err |
| 398 | } |
| 399 | } |
| 400 | } |
| 401 | return nil |
| 402 | } |
| 403 | |
khenaidoo | 0a822f9 | 2019-05-08 15:15:57 -0400 | [diff] [blame] | 404 | // deleteLogicalPort removes the logical port associated with a device |
khenaidoo | 19d7b63 | 2018-10-30 10:49:50 -0400 | [diff] [blame] | 405 | func (ldMgr *LogicalDeviceManager) deleteLogicalPort(ctx context.Context, lPortId *voltha.LogicalPortId) error { |
| 406 | log.Debugw("deleting-logical-port", log.Fields{"LDeviceId": lPortId.Id}) |
| 407 | // Get logical port |
| 408 | var logicalPort *voltha.LogicalPort |
| 409 | var err error |
| 410 | if logicalPort, err = ldMgr.getLogicalPort(lPortId); err != nil { |
| 411 | log.Debugw("no-logical-device-port-present", log.Fields{"logicalPortId": lPortId.PortId}) |
| 412 | return err |
| 413 | } |
khenaidoo | 92e62c5 | 2018-10-03 14:02:54 -0400 | [diff] [blame] | 414 | // Sanity check |
khenaidoo | 19d7b63 | 2018-10-30 10:49:50 -0400 | [diff] [blame] | 415 | if logicalPort.RootPort { |
khenaidoo | 2c6a099 | 2019-04-29 13:46:56 -0400 | [diff] [blame] | 416 | return errors.New("device-root") |
khenaidoo | 92e62c5 | 2018-10-03 14:02:54 -0400 | [diff] [blame] | 417 | } |
khenaidoo | 19d7b63 | 2018-10-30 10:49:50 -0400 | [diff] [blame] | 418 | if agent := ldMgr.getLogicalDeviceAgent(lPortId.Id); agent != nil { |
khenaidoo | 0a822f9 | 2019-05-08 15:15:57 -0400 | [diff] [blame] | 419 | if err := agent.deleteLogicalPort(logicalPort); err != nil { |
| 420 | log.Warnw("deleting-logicalport-failed", log.Fields{"LDeviceId": lPortId.Id, "error": err}) |
| 421 | } |
khenaidoo | 92e62c5 | 2018-10-03 14:02:54 -0400 | [diff] [blame] | 422 | } |
| 423 | |
| 424 | log.Debug("deleting-logical-port-ends") |
| 425 | return nil |
| 426 | } |
| 427 | |
khenaidoo | 0a822f9 | 2019-05-08 15:15:57 -0400 | [diff] [blame] | 428 | // deleteLogicalPort removes the logical port associated with a child device |
| 429 | func (ldMgr *LogicalDeviceManager) deleteLogicalPorts(deviceId string) error { |
| 430 | log.Debugw("deleting-logical-ports", log.Fields{"deviceId": deviceId}) |
| 431 | // Get logical port |
| 432 | if ldId, err := ldMgr.getLogicalDeviceIdFromDeviceId(deviceId); err != nil { |
khenaidoo | 0a822f9 | 2019-05-08 15:15:57 -0400 | [diff] [blame] | 433 | return err |
| 434 | } else { |
| 435 | if agent := ldMgr.getLogicalDeviceAgent(*ldId); agent != nil { |
| 436 | if err = agent.deleteLogicalPorts(deviceId); err != nil { |
| 437 | log.Warnw("deleteLogicalPorts-failed", log.Fields{"ldeviceId": *ldId}) |
| 438 | return err |
| 439 | } |
| 440 | } |
| 441 | } |
| 442 | log.Debug("deleting-logical-port-ends") |
| 443 | return nil |
| 444 | } |
| 445 | |
khenaidoo | fc1314d | 2019-03-14 09:34:21 -0400 | [diff] [blame] | 446 | func (ldMgr *LogicalDeviceManager) setupUNILogicalPorts(ctx context.Context, childDevice *voltha.Device) error { |
Stephane Barbarie | ef6650d | 2019-07-18 12:15:09 -0400 | [diff] [blame] | 447 | log.Debugw("setupUNILogicalPorts", log.Fields{"childDeviceId": childDevice.Id, "parentDeviceId": 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 |
| 454 | parentId := childDevice.ParentId |
| 455 | logDeviceId := ldMgr.deviceMgr.GetParentDeviceId(parentId) |
| 456 | |
khenaidoo | fc1314d | 2019-03-14 09:34:21 -0400 | [diff] [blame] | 457 | log.Debugw("setupUNILogicalPorts", log.Fields{"logDeviceId": logDeviceId, "parentId": parentId}) |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 458 | |
khenaidoo | 4c9e559 | 2019-09-09 16:20:41 -0400 | [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 | |
khenaidoo | 4c9e559 | 2019-09-09 16:20:41 -0400 | [diff] [blame] | 463 | if agent := ldMgr.getLogicalDeviceAgent(logDeviceId); agent != nil { |
khenaidoo | fc1314d | 2019-03-14 09:34:21 -0400 | [diff] [blame] | 464 | if err := agent.setupUNILogicalPorts(ctx, childDevice); 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 | |
khenaidoo | 0a822f9 | 2019-05-08 15:15:57 -0400 | [diff] [blame] | 471 | func (ldMgr *LogicalDeviceManager) deleteAllLogicalPorts(device *voltha.Device) error { |
| 472 | log.Debugw("deleteAllLogicalPorts", log.Fields{"deviceId": device.Id}) |
| 473 | |
| 474 | var ldId *string |
| 475 | var err error |
| 476 | //Get the logical device Id for this device |
| 477 | if ldId, err = ldMgr.getLogicalDeviceId(device); err != nil { |
| 478 | log.Warnw("no-logical-device-found", log.Fields{"deviceId": device.Id, "error": err}) |
| 479 | return err |
| 480 | } |
| 481 | if agent := ldMgr.getLogicalDeviceAgent(*ldId); agent != nil { |
| 482 | if err := agent.deleteAllLogicalPorts(device); err != nil { |
| 483 | return err |
| 484 | } |
| 485 | } |
| 486 | return nil |
| 487 | } |
khenaidoo | 171b98e | 2019-10-31 11:48:15 -0400 | [diff] [blame] | 488 | func (ldMgr *LogicalDeviceManager) updatePortState(deviceId string, portNo uint32, state voltha.OperStatus_OperStatus) error { |
| 489 | log.Debugw("updatePortState", log.Fields{"deviceId": deviceId, "state": state, "portNo": portNo}) |
| 490 | |
| 491 | var ldId *string |
| 492 | var err error |
| 493 | //Get the logical device Id for this device |
| 494 | if ldId, err = ldMgr.getLogicalDeviceIdFromDeviceId(deviceId); err != nil { |
| 495 | log.Warnw("no-logical-device-found", log.Fields{"deviceId": deviceId, "error": err}) |
| 496 | return err |
| 497 | } |
| 498 | if agent := ldMgr.getLogicalDeviceAgent(*ldId); agent != nil { |
| 499 | if err := agent.updatePortState(deviceId, portNo, state); err != nil { |
| 500 | return err |
| 501 | } |
| 502 | } |
| 503 | return nil |
| 504 | } |
khenaidoo | 0a822f9 | 2019-05-08 15:15:57 -0400 | [diff] [blame] | 505 | |
khenaidoo | 3ab3488 | 2019-05-02 21:33:30 -0400 | [diff] [blame] | 506 | func (ldMgr *LogicalDeviceManager) updatePortsState(device *voltha.Device, state voltha.AdminState_AdminState) error { |
Stephane Barbarie | ef6650d | 2019-07-18 12:15:09 -0400 | [diff] [blame] | 507 | log.Debugw("updatePortsState", log.Fields{"deviceId": device.Id, "state": state, "current-data": device}) |
khenaidoo | 3ab3488 | 2019-05-02 21:33:30 -0400 | [diff] [blame] | 508 | |
| 509 | var ldId *string |
| 510 | var err error |
| 511 | //Get the logical device Id for this device |
| 512 | if ldId, err = ldMgr.getLogicalDeviceId(device); err != nil { |
| 513 | log.Warnw("no-logical-device-found", log.Fields{"deviceId": device.Id, "error": err}) |
| 514 | return err |
| 515 | } |
| 516 | if agent := ldMgr.getLogicalDeviceAgent(*ldId); agent != nil { |
| 517 | if err := agent.updatePortsState(device, state); err != nil { |
| 518 | return err |
| 519 | } |
| 520 | } |
| 521 | return nil |
| 522 | } |
| 523 | |
khenaidoo | 19d7b63 | 2018-10-30 10:49:50 -0400 | [diff] [blame] | 524 | func (ldMgr *LogicalDeviceManager) updateFlowTable(ctx context.Context, id string, flow *openflow_13.OfpFlowMod, ch chan interface{}) { |
| 525 | log.Debugw("updateFlowTable", log.Fields{"logicalDeviceId": id}) |
| 526 | var res interface{} |
| 527 | if agent := ldMgr.getLogicalDeviceAgent(id); agent != nil { |
| 528 | res = agent.updateFlowTable(ctx, flow) |
| 529 | log.Debugw("updateFlowTable-result", log.Fields{"result": res}) |
| 530 | } else { |
| 531 | res = status.Errorf(codes.NotFound, "%s", id) |
| 532 | } |
| 533 | sendAPIResponse(ctx, ch, res) |
| 534 | } |
| 535 | |
Manikkaraj k | b1a1092 | 2019-07-29 12:10:34 -0400 | [diff] [blame] | 536 | func (ldMgr *LogicalDeviceManager) updateMeterTable(ctx context.Context, id string, meter *openflow_13.OfpMeterMod, ch chan interface{}) { |
| 537 | log.Debugw("updateMeterTable", log.Fields{"logicalDeviceId": id}) |
| 538 | var res interface{} |
| 539 | if agent := ldMgr.getLogicalDeviceAgent(id); agent != nil { |
| 540 | res = agent.updateMeterTable(ctx, meter) |
| 541 | log.Debugw("updateMeterTable-result", log.Fields{"result": res}) |
| 542 | } else { |
| 543 | res = status.Errorf(codes.NotFound, "%s", id) |
| 544 | } |
| 545 | sendAPIResponse(ctx, ch, res) |
| 546 | } |
| 547 | |
| 548 | func (ldMgr *LogicalDeviceManager) ListLogicalDeviceMeters(ctx context.Context, id string) (*openflow_13.Meters, error) { |
| 549 | log.Debugw("ListLogicalDeviceMeters", log.Fields{"logicalDeviceId": id}) |
| 550 | if agent := ldMgr.getLogicalDeviceAgent(id); agent != nil { |
| 551 | return agent.ListLogicalDeviceMeters() |
| 552 | } |
| 553 | return nil, status.Errorf(codes.NotFound, "%s", id) |
| 554 | } |
khenaidoo | 19d7b63 | 2018-10-30 10:49:50 -0400 | [diff] [blame] | 555 | func (ldMgr *LogicalDeviceManager) updateGroupTable(ctx context.Context, id string, groupMod *openflow_13.OfpGroupMod, ch chan interface{}) { |
| 556 | log.Debugw("updateGroupTable", log.Fields{"logicalDeviceId": id}) |
| 557 | var res interface{} |
| 558 | if agent := ldMgr.getLogicalDeviceAgent(id); agent != nil { |
| 559 | res = agent.updateGroupTable(ctx, groupMod) |
| 560 | log.Debugw("updateGroupTable-result", log.Fields{"result": res}) |
| 561 | } else { |
| 562 | res = status.Errorf(codes.NotFound, "%s", id) |
| 563 | } |
| 564 | sendAPIResponse(ctx, ch, res) |
| 565 | } |
| 566 | |
| 567 | func (ldMgr *LogicalDeviceManager) enableLogicalPort(ctx context.Context, id *voltha.LogicalPortId, ch chan interface{}) { |
| 568 | log.Debugw("enableLogicalPort", log.Fields{"logicalDeviceId": id}) |
| 569 | var res interface{} |
Girish Kumar | 0d4597e | 2019-10-24 18:13:14 +0000 | [diff] [blame] | 570 | |
khenaidoo | 19d7b63 | 2018-10-30 10:49:50 -0400 | [diff] [blame] | 571 | if agent := ldMgr.getLogicalDeviceAgent(id.Id); agent != nil { |
Girish Kumar | 0d4597e | 2019-10-24 18:13:14 +0000 | [diff] [blame] | 572 | res = agent.enableLogicalPort(id.PortId) |
khenaidoo | 19d7b63 | 2018-10-30 10:49:50 -0400 | [diff] [blame] | 573 | log.Debugw("enableLogicalPort-result", log.Fields{"result": res}) |
| 574 | } else { |
| 575 | res = status.Errorf(codes.NotFound, "%s", id.Id) |
| 576 | } |
| 577 | sendAPIResponse(ctx, ch, res) |
| 578 | } |
| 579 | |
| 580 | func (ldMgr *LogicalDeviceManager) disableLogicalPort(ctx context.Context, id *voltha.LogicalPortId, ch chan interface{}) { |
| 581 | log.Debugw("disableLogicalPort", log.Fields{"logicalDeviceId": id}) |
| 582 | var res interface{} |
Girish Kumar | 0d4597e | 2019-10-24 18:13:14 +0000 | [diff] [blame] | 583 | |
khenaidoo | 19d7b63 | 2018-10-30 10:49:50 -0400 | [diff] [blame] | 584 | if agent := ldMgr.getLogicalDeviceAgent(id.Id); agent != nil { |
Girish Kumar | 0d4597e | 2019-10-24 18:13:14 +0000 | [diff] [blame] | 585 | res = agent.disableLogicalPort(id.PortId) |
khenaidoo | 19d7b63 | 2018-10-30 10:49:50 -0400 | [diff] [blame] | 586 | log.Debugw("disableLogicalPort-result", log.Fields{"result": res}) |
| 587 | } else { |
| 588 | res = status.Errorf(codes.NotFound, "%s", id.Id) |
| 589 | } |
| 590 | sendAPIResponse(ctx, ch, res) |
| 591 | } |
khenaidoo | fdbad6e | 2018-11-06 22:26:38 -0500 | [diff] [blame] | 592 | |
khenaidoo | 43c8212 | 2018-11-22 18:38:28 -0500 | [diff] [blame] | 593 | func (ldMgr *LogicalDeviceManager) packetOut(packetOut *openflow_13.PacketOut) { |
khenaidoo | fdbad6e | 2018-11-06 22:26:38 -0500 | [diff] [blame] | 594 | log.Debugw("packetOut", log.Fields{"logicalDeviceId": packetOut.Id}) |
| 595 | if agent := ldMgr.getLogicalDeviceAgent(packetOut.Id); agent != nil { |
| 596 | agent.packetOut(packetOut.PacketOut) |
| 597 | } else { |
| 598 | log.Error("logical-device-not-exist", log.Fields{"logicalDeviceId": packetOut.Id}) |
| 599 | } |
| 600 | } |
| 601 | |
khenaidoo | 297cd25 | 2019-02-07 22:10:23 -0500 | [diff] [blame] | 602 | func (ldMgr *LogicalDeviceManager) packetIn(logicalDeviceId string, port uint32, transactionId string, packet []byte) error { |
khenaidoo | fdbad6e | 2018-11-06 22:26:38 -0500 | [diff] [blame] | 603 | log.Debugw("packetIn", log.Fields{"logicalDeviceId": logicalDeviceId, "port": port}) |
| 604 | if agent := ldMgr.getLogicalDeviceAgent(logicalDeviceId); agent != nil { |
khenaidoo | 297cd25 | 2019-02-07 22:10:23 -0500 | [diff] [blame] | 605 | agent.packetIn(port, transactionId, packet) |
khenaidoo | fdbad6e | 2018-11-06 22:26:38 -0500 | [diff] [blame] | 606 | } else { |
| 607 | log.Error("logical-device-not-exist", log.Fields{"logicalDeviceId": logicalDeviceId}) |
| 608 | } |
| 609 | return nil |
| 610 | } |