Kent Hagerman | 3136fbd | 2020-05-14 10:30:45 -0400 | [diff] [blame] | 1 | /* |
Joey Armstrong | 5f51f2e | 2023-01-17 17:06:26 -0500 | [diff] [blame] | 2 | * Copyright 2018-2023 Open Networking Foundation (ONF) and the ONF Contributors |
Kent Hagerman | 3136fbd | 2020-05-14 10:30:45 -0400 | [diff] [blame] | 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 | |
| 17 | package device |
| 18 | |
| 19 | import ( |
| 20 | "context" |
| 21 | "fmt" |
Kent Hagerman | fa9d6d4 | 2020-05-25 11:49:40 -0400 | [diff] [blame] | 22 | "sync" |
Kent Hagerman | 3136fbd | 2020-05-14 10:30:45 -0400 | [diff] [blame] | 23 | |
Kent Hagerman | 3136fbd | 2020-05-14 10:30:45 -0400 | [diff] [blame] | 24 | coreutils "github.com/opencord/voltha-go/rw_core/utils" |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 25 | fu "github.com/opencord/voltha-lib-go/v7/pkg/flows" |
| 26 | "github.com/opencord/voltha-lib-go/v7/pkg/log" |
| 27 | ofp "github.com/opencord/voltha-protos/v5/go/openflow_13" |
| 28 | "github.com/opencord/voltha-protos/v5/go/voltha" |
Kent Hagerman | 3136fbd | 2020-05-14 10:30:45 -0400 | [diff] [blame] | 29 | "google.golang.org/grpc/codes" |
| 30 | "google.golang.org/grpc/status" |
| 31 | ) |
| 32 | |
Kent Hagerman | fa9d6d4 | 2020-05-25 11:49:40 -0400 | [diff] [blame] | 33 | // listLogicalDevicePorts returns logical device ports |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 34 | func (agent *LogicalAgent) listLogicalDevicePorts(ctx context.Context) map[uint32]*voltha.LogicalPort { |
Kent Hagerman | fa9d6d4 | 2020-05-25 11:49:40 -0400 | [diff] [blame] | 35 | portIDs := agent.portLoader.ListIDs() |
khenaidoo | 7585a96 | 2021-06-10 16:15:38 -0400 | [diff] [blame] | 36 | logger.Debugw(ctx, "list-logical-device-ports", log.Fields{"num-ports": len(portIDs)}) |
Kent Hagerman | fa9d6d4 | 2020-05-25 11:49:40 -0400 | [diff] [blame] | 37 | ret := make(map[uint32]*voltha.LogicalPort, len(portIDs)) |
| 38 | for portID := range portIDs { |
| 39 | if portHandle, have := agent.portLoader.Lock(portID); have { |
| 40 | ret[portID] = portHandle.GetReadOnly() |
| 41 | portHandle.Unlock() |
| 42 | } |
Kent Hagerman | 3136fbd | 2020-05-14 10:30:45 -0400 | [diff] [blame] | 43 | } |
Kent Hagerman | fa9d6d4 | 2020-05-25 11:49:40 -0400 | [diff] [blame] | 44 | return ret |
Kent Hagerman | 3136fbd | 2020-05-14 10:30:45 -0400 | [diff] [blame] | 45 | } |
| 46 | |
Kent Hagerman | 2a07b86 | 2020-06-19 15:23:07 -0400 | [diff] [blame] | 47 | func (agent *LogicalAgent) updateLogicalPort(ctx context.Context, device *voltha.Device, devicePorts map[uint32]*voltha.Port, port *voltha.Port) error { |
Himani Chawla | b4c2591 | 2020-11-12 17:16:38 +0530 | [diff] [blame] | 48 | logger.Debugw(ctx, "update-logical-port", log.Fields{"device-id": device.Id, "port": port}) |
khenaidoo | 0db4c81 | 2020-05-27 15:27:30 -0400 | [diff] [blame] | 49 | switch port.Type { |
| 50 | case voltha.Port_ETHERNET_NNI: |
Kent Hagerman | 2a07b86 | 2020-06-19 15:23:07 -0400 | [diff] [blame] | 51 | if err := agent.addNNILogicalPort(ctx, device.Id, devicePorts, port); err != nil { |
Kent Hagerman | 3136fbd | 2020-05-14 10:30:45 -0400 | [diff] [blame] | 52 | return err |
| 53 | } |
khenaidoo | 0db4c81 | 2020-05-27 15:27:30 -0400 | [diff] [blame] | 54 | case voltha.Port_ETHERNET_UNI: |
Kent Hagerman | 2a07b86 | 2020-06-19 15:23:07 -0400 | [diff] [blame] | 55 | if err := agent.addUNILogicalPort(ctx, device.Id, device.AdminState, device.OperStatus, devicePorts, port); err != nil { |
Kent Hagerman | 3136fbd | 2020-05-14 10:30:45 -0400 | [diff] [blame] | 56 | return err |
| 57 | } |
khenaidoo | 0db4c81 | 2020-05-27 15:27:30 -0400 | [diff] [blame] | 58 | case voltha.Port_PON_OLT: |
| 59 | // Rebuilt the routes on Parent PON port addition |
Himani Chawla | b4c2591 | 2020-11-12 17:16:38 +0530 | [diff] [blame] | 60 | |
nikesh.krishnan | 95142d5 | 2023-02-24 15:32:11 +0530 | [diff] [blame] | 61 | if err := agent.buildRoutes(ctx); err != nil { |
| 62 | // Not an error - temporary state |
| 63 | logger.Infow(ctx, "failed-to-update-routes-after-adding-parent-pon-port", log.Fields{"device-id": device.Id, "port": port, "ports-count": len(devicePorts), "error": err}) |
| 64 | } |
| 65 | |
khenaidoo | 0db4c81 | 2020-05-27 15:27:30 -0400 | [diff] [blame] | 66 | //fallthrough |
| 67 | case voltha.Port_PON_ONU: |
| 68 | // Add the routes corresponding to that child device |
nikesh.krishnan | 95142d5 | 2023-02-24 15:32:11 +0530 | [diff] [blame] | 69 | |
| 70 | if err := agent.updateAllRoutes(ctx, device.Id, devicePorts); err != nil { |
| 71 | // Not an error - temporary state |
| 72 | logger.Infow(ctx, "failed-to-update-routes-after-adding-child-pon-port", log.Fields{"device-id": device.Id, "port": port, "ports-count": len(devicePorts), "error": err}) |
| 73 | } |
| 74 | |
khenaidoo | 0db4c81 | 2020-05-27 15:27:30 -0400 | [diff] [blame] | 75 | default: |
| 76 | return fmt.Errorf("invalid port type %v", port) |
Kent Hagerman | 3136fbd | 2020-05-14 10:30:45 -0400 | [diff] [blame] | 77 | } |
| 78 | return nil |
| 79 | } |
| 80 | |
| 81 | // setupLogicalPorts is invoked once the logical device has been created and is ready to get ports |
| 82 | // added to it. While the logical device was being created we could have received requests to add |
| 83 | // NNI and UNI ports which were discarded. Now is the time to add them if needed |
| 84 | func (agent *LogicalAgent) setupLogicalPorts(ctx context.Context) error { |
Himani Chawla | b4c2591 | 2020-11-12 17:16:38 +0530 | [diff] [blame] | 85 | logger.Infow(ctx, "setup-logical-ports", log.Fields{"logical-device-id": agent.logicalDeviceID}) |
Kent Hagerman | 3136fbd | 2020-05-14 10:30:45 -0400 | [diff] [blame] | 86 | // First add any NNI ports which could have been missing |
| 87 | if err := agent.setupNNILogicalPorts(ctx, agent.rootDeviceID); err != nil { |
Himani Chawla | b4c2591 | 2020-11-12 17:16:38 +0530 | [diff] [blame] | 88 | logger.Errorw(ctx, "error-setting-up-nni-ports", log.Fields{"error": err, "device-id": agent.rootDeviceID}) |
Kent Hagerman | 3136fbd | 2020-05-14 10:30:45 -0400 | [diff] [blame] | 89 | return err |
| 90 | } |
| 91 | |
| 92 | // Now, set up the UNI ports if needed. |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 93 | children, err := agent.deviceMgr.getAllChildDevices(ctx, agent.rootDeviceID) |
Kent Hagerman | 3136fbd | 2020-05-14 10:30:45 -0400 | [diff] [blame] | 94 | if err != nil { |
divyadesai | cb8b59d | 2020-08-18 09:55:47 +0000 | [diff] [blame] | 95 | logger.Errorw(ctx, "error-getting-child-devices", log.Fields{"error": err, "device-id": agent.rootDeviceID}) |
Kent Hagerman | 3136fbd | 2020-05-14 10:30:45 -0400 | [diff] [blame] | 96 | return err |
| 97 | } |
| 98 | responses := make([]coreutils.Response, 0) |
| 99 | for _, child := range children.Items { |
| 100 | response := coreutils.NewResponse() |
| 101 | responses = append(responses, response) |
Himani Chawla | b4c2591 | 2020-11-12 17:16:38 +0530 | [diff] [blame] | 102 | subCtx := coreutils.WithSpanAndRPCMetadataFromContext(ctx) |
Kent Hagerman | 2a07b86 | 2020-06-19 15:23:07 -0400 | [diff] [blame] | 103 | go func(ctx context.Context, child *voltha.Device) { |
| 104 | defer response.Done() |
| 105 | |
| 106 | childPorts, err := agent.deviceMgr.listDevicePorts(ctx, child.Id) |
| 107 | if err != nil { |
Himani Chawla | b4c2591 | 2020-11-12 17:16:38 +0530 | [diff] [blame] | 108 | logger.Error(ctx, "setting-up-uni-ports-failed", log.Fields{"device-id": child.Id}) |
Kent Hagerman | 2a07b86 | 2020-06-19 15:23:07 -0400 | [diff] [blame] | 109 | response.Error(status.Errorf(codes.Internal, "UNI-ports-setup-failed: %s", child.Id)) |
| 110 | return |
| 111 | } |
| 112 | |
| 113 | if err = agent.setupUNILogicalPorts(ctx, child, childPorts); err != nil { |
Himani Chawla | b4c2591 | 2020-11-12 17:16:38 +0530 | [diff] [blame] | 114 | logger.Error(ctx, "setting-up-uni-ports-failed", log.Fields{"device-id": child.Id}) |
Kent Hagerman | 3136fbd | 2020-05-14 10:30:45 -0400 | [diff] [blame] | 115 | response.Error(status.Errorf(codes.Internal, "UNI-ports-setup-failed: %s", child.Id)) |
| 116 | } |
Himani Chawla | b4c2591 | 2020-11-12 17:16:38 +0530 | [diff] [blame] | 117 | }(subCtx, child) |
Kent Hagerman | 3136fbd | 2020-05-14 10:30:45 -0400 | [diff] [blame] | 118 | } |
| 119 | // Wait for completion |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 120 | if res := coreutils.WaitForNilOrErrorResponses(agent.internalTimeout, responses...); res != nil { |
Kent Hagerman | 3136fbd | 2020-05-14 10:30:45 -0400 | [diff] [blame] | 121 | return status.Errorf(codes.Aborted, "errors-%s", res) |
| 122 | } |
| 123 | return nil |
| 124 | } |
| 125 | |
| 126 | // setupNNILogicalPorts creates an NNI port on the logical device that represents an NNI interface on a root device |
| 127 | func (agent *LogicalAgent) setupNNILogicalPorts(ctx context.Context, deviceID string) error { |
Himani Chawla | b4c2591 | 2020-11-12 17:16:38 +0530 | [diff] [blame] | 128 | logger.Infow(ctx, "setup-nni-logical-ports-start", log.Fields{"logical-device-id": agent.logicalDeviceID}) |
Kent Hagerman | 3136fbd | 2020-05-14 10:30:45 -0400 | [diff] [blame] | 129 | // Build the logical device based on information retrieved from the device adapter |
Kent Hagerman | 3136fbd | 2020-05-14 10:30:45 -0400 | [diff] [blame] | 130 | |
Kent Hagerman | 2a07b86 | 2020-06-19 15:23:07 -0400 | [diff] [blame] | 131 | devicePorts, err := agent.deviceMgr.listDevicePorts(ctx, deviceID) |
| 132 | if err != nil { |
divyadesai | cb8b59d | 2020-08-18 09:55:47 +0000 | [diff] [blame] | 133 | logger.Errorw(ctx, "error-retrieving-device-ports", log.Fields{"error": err, "device-id": deviceID}) |
Kent Hagerman | 3136fbd | 2020-05-14 10:30:45 -0400 | [diff] [blame] | 134 | return err |
| 135 | } |
| 136 | |
| 137 | //Get UNI port number |
Kent Hagerman | 2a07b86 | 2020-06-19 15:23:07 -0400 | [diff] [blame] | 138 | for _, port := range devicePorts { |
Kent Hagerman | 3136fbd | 2020-05-14 10:30:45 -0400 | [diff] [blame] | 139 | if port.Type == voltha.Port_ETHERNET_NNI { |
Kent Hagerman | 2a07b86 | 2020-06-19 15:23:07 -0400 | [diff] [blame] | 140 | if err = agent.addNNILogicalPort(ctx, deviceID, devicePorts, port); err != nil { |
Himani Chawla | b4c2591 | 2020-11-12 17:16:38 +0530 | [diff] [blame] | 141 | logger.Errorw(ctx, "error-adding-nni-port", log.Fields{"error": err}) |
Kent Hagerman | 3136fbd | 2020-05-14 10:30:45 -0400 | [diff] [blame] | 142 | } |
Kent Hagerman | 3136fbd | 2020-05-14 10:30:45 -0400 | [diff] [blame] | 143 | } |
| 144 | } |
| 145 | return err |
| 146 | } |
| 147 | |
| 148 | // updatePortState updates the port state of the device |
Kent Hagerman | fa9d6d4 | 2020-05-25 11:49:40 -0400 | [diff] [blame] | 149 | func (agent *LogicalAgent) updatePortState(ctx context.Context, portNo uint32, operStatus voltha.OperStatus_Types) error { |
Himani Chawla | b4c2591 | 2020-11-12 17:16:38 +0530 | [diff] [blame] | 150 | logger.Infow(ctx, "update-port-state-start", log.Fields{"logical-device-id": agent.logicalDeviceID, "port-no": portNo, "state": operStatus}) |
Kent Hagerman | fa9d6d4 | 2020-05-25 11:49:40 -0400 | [diff] [blame] | 151 | |
| 152 | portHandle, have := agent.portLoader.Lock(portNo) |
| 153 | if !have { |
| 154 | return status.Errorf(codes.NotFound, "port-%d-not-exist", portNo) |
| 155 | } |
| 156 | defer portHandle.Unlock() |
| 157 | |
| 158 | newPort := clonePortSetState(portHandle.GetReadOnly(), operStatus) |
| 159 | if err := portHandle.Update(ctx, newPort); err != nil { |
Kent Hagerman | 3136fbd | 2020-05-14 10:30:45 -0400 | [diff] [blame] | 160 | return err |
| 161 | } |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 162 | agent.orderedEvents.send(ctx, agent, agent.logicalDeviceID, ofp.OfpPortReason_OFPPR_MODIFY, newPort.OfpPort) |
Kent Hagerman | fa9d6d4 | 2020-05-25 11:49:40 -0400 | [diff] [blame] | 163 | return nil |
Kent Hagerman | 3136fbd | 2020-05-14 10:30:45 -0400 | [diff] [blame] | 164 | } |
| 165 | |
Kent Hagerman | fa9d6d4 | 2020-05-25 11:49:40 -0400 | [diff] [blame] | 166 | func clonePortSetState(oldPort *voltha.LogicalPort, state voltha.OperStatus_Types) *voltha.LogicalPort { |
| 167 | newPort := *oldPort // only clone the struct(s) that will be changed |
| 168 | newOfpPort := *oldPort.OfpPort |
| 169 | newPort.OfpPort = &newOfpPort |
| 170 | |
| 171 | if state == voltha.OperStatus_ACTIVE { |
Andrey Pozolotin | 34dd63f | 2021-05-31 21:26:40 +0300 | [diff] [blame] | 172 | newOfpPort.Config &= ^uint32(ofp.OfpPortConfig_OFPPC_PORT_DOWN) |
Kent Hagerman | fa9d6d4 | 2020-05-25 11:49:40 -0400 | [diff] [blame] | 173 | newOfpPort.State = uint32(ofp.OfpPortState_OFPPS_LIVE) |
| 174 | } else { |
Andrey Pozolotin | 34dd63f | 2021-05-31 21:26:40 +0300 | [diff] [blame] | 175 | newOfpPort.Config |= uint32(ofp.OfpPortConfig_OFPPC_PORT_DOWN) |
Kent Hagerman | fa9d6d4 | 2020-05-25 11:49:40 -0400 | [diff] [blame] | 176 | newOfpPort.State = uint32(ofp.OfpPortState_OFPPS_LINK_DOWN) |
| 177 | } |
| 178 | return &newPort |
| 179 | } |
| 180 | |
Kent Hagerman | 3136fbd | 2020-05-14 10:30:45 -0400 | [diff] [blame] | 181 | // setupUNILogicalPorts creates a UNI port on the logical device that represents a child UNI interface |
Kent Hagerman | 2a07b86 | 2020-06-19 15:23:07 -0400 | [diff] [blame] | 182 | func (agent *LogicalAgent) 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] | 183 | logger.Infow(ctx, "setup-uni-logical-ports", log.Fields{"logical-device-id": agent.logicalDeviceID}) |
Kent Hagerman | 3136fbd | 2020-05-14 10:30:45 -0400 | [diff] [blame] | 184 | // Build the logical device based on information retrieved from the device adapter |
| 185 | var err error |
Kent Hagerman | 3136fbd | 2020-05-14 10:30:45 -0400 | [diff] [blame] | 186 | //Get UNI port number |
Kent Hagerman | 2a07b86 | 2020-06-19 15:23:07 -0400 | [diff] [blame] | 187 | for _, port := range childDevicePorts { |
Kent Hagerman | 3136fbd | 2020-05-14 10:30:45 -0400 | [diff] [blame] | 188 | if port.Type == voltha.Port_ETHERNET_UNI { |
Kent Hagerman | 2a07b86 | 2020-06-19 15:23:07 -0400 | [diff] [blame] | 189 | if err = agent.addUNILogicalPort(ctx, childDevice.Id, childDevice.AdminState, childDevice.OperStatus, childDevicePorts, port); err != nil { |
Himani Chawla | b4c2591 | 2020-11-12 17:16:38 +0530 | [diff] [blame] | 190 | logger.Errorw(ctx, "error-adding-uni-port", log.Fields{"error": err}) |
Kent Hagerman | 3136fbd | 2020-05-14 10:30:45 -0400 | [diff] [blame] | 191 | } |
Kent Hagerman | 3136fbd | 2020-05-14 10:30:45 -0400 | [diff] [blame] | 192 | } |
| 193 | } |
| 194 | return err |
| 195 | } |
| 196 | |
| 197 | // deleteAllLogicalPorts deletes all logical ports associated with this logical device |
| 198 | func (agent *LogicalAgent) deleteAllLogicalPorts(ctx context.Context) error { |
Himani Chawla | b4c2591 | 2020-11-12 17:16:38 +0530 | [diff] [blame] | 199 | logger.Infow(ctx, "update-ports-state-start", log.Fields{"logical-device-id": agent.logicalDeviceID}) |
Kent Hagerman | 3136fbd | 2020-05-14 10:30:45 -0400 | [diff] [blame] | 200 | |
Kent Hagerman | fa9d6d4 | 2020-05-25 11:49:40 -0400 | [diff] [blame] | 201 | // for each port |
| 202 | for portID := range agent.portLoader.ListIDs() { |
| 203 | // TODO: can just call agent.deleteLogicalPort()? |
| 204 | if portHandle, have := agent.portLoader.Lock(portID); have { |
| 205 | oldPort := portHandle.GetReadOnly() |
| 206 | // delete |
| 207 | err := portHandle.Delete(ctx) |
| 208 | portHandle.Unlock() |
| 209 | if err != nil { |
| 210 | return err |
Kent Hagerman | 3136fbd | 2020-05-14 10:30:45 -0400 | [diff] [blame] | 211 | } |
Kent Hagerman | fa9d6d4 | 2020-05-25 11:49:40 -0400 | [diff] [blame] | 212 | // and send event |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 213 | agent.orderedEvents.send(ctx, agent, agent.logicalDeviceID, ofp.OfpPortReason_OFPPR_DELETE, oldPort.OfpPort) |
Kent Hagerman | fa9d6d4 | 2020-05-25 11:49:40 -0400 | [diff] [blame] | 214 | } |
Kent Hagerman | 3136fbd | 2020-05-14 10:30:45 -0400 | [diff] [blame] | 215 | } |
Kent Hagerman | fa9d6d4 | 2020-05-25 11:49:40 -0400 | [diff] [blame] | 216 | |
| 217 | // Reset the logical device routes |
nikesh.krishnan | 95142d5 | 2023-02-24 15:32:11 +0530 | [diff] [blame] | 218 | if err := agent.removeRoutes(ctx); err != nil { |
| 219 | logger.Warnw(ctx, "error-removing-routes", log.Fields{"logical-device-id": agent.logicalDeviceID, "error": err}) |
| 220 | } |
| 221 | |
Kent Hagerman | 3136fbd | 2020-05-14 10:30:45 -0400 | [diff] [blame] | 222 | return nil |
| 223 | } |
| 224 | |
| 225 | // deleteLogicalPorts removes the logical ports associated with that deviceId |
| 226 | func (agent *LogicalAgent) deleteLogicalPorts(ctx context.Context, deviceID string) error { |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 227 | logger.Debugw(ctx, "deleting-logical-ports", log.Fields{"device-id": deviceID}) |
Kent Hagerman | 3136fbd | 2020-05-14 10:30:45 -0400 | [diff] [blame] | 228 | |
Kent Hagerman | fa9d6d4 | 2020-05-25 11:49:40 -0400 | [diff] [blame] | 229 | // for each port |
| 230 | for portNo := range agent.portLoader.ListIDsForDevice(deviceID) { |
| 231 | if portHandle, have := agent.portLoader.Lock(portNo); have { |
| 232 | // if belongs to this device |
| 233 | if oldPort := portHandle.GetReadOnly(); oldPort.DeviceId == deviceID { |
| 234 | // delete |
| 235 | if err := portHandle.Delete(ctx); err != nil { |
| 236 | portHandle.Unlock() |
| 237 | return err |
| 238 | } |
| 239 | // and send event |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 240 | agent.orderedEvents.send(ctx, agent, agent.logicalDeviceID, ofp.OfpPortReason_OFPPR_DELETE, oldPort.OfpPort) |
Kent Hagerman | fa9d6d4 | 2020-05-25 11:49:40 -0400 | [diff] [blame] | 241 | } |
| 242 | portHandle.Unlock() |
Kent Hagerman | 3136fbd | 2020-05-14 10:30:45 -0400 | [diff] [blame] | 243 | } |
| 244 | } |
Kent Hagerman | 3136fbd | 2020-05-14 10:30:45 -0400 | [diff] [blame] | 245 | |
| 246 | // Reset the logical device routes |
nikesh.krishnan | 95142d5 | 2023-02-24 15:32:11 +0530 | [diff] [blame] | 247 | |
| 248 | if err := agent.buildRoutes(ctx); err != nil { |
| 249 | logger.Warnw(ctx, "routes-not-ready", log.Fields{"logical-device-id": agent.logicalDeviceID, "error": err}) |
| 250 | } |
| 251 | |
Kent Hagerman | 3136fbd | 2020-05-14 10:30:45 -0400 | [diff] [blame] | 252 | return nil |
| 253 | } |
| 254 | |
| 255 | // enableLogicalPort enables the logical port |
Kent Hagerman | fa9d6d4 | 2020-05-25 11:49:40 -0400 | [diff] [blame] | 256 | func (agent *LogicalAgent) enableLogicalPort(ctx context.Context, lPortNo uint32) error { |
| 257 | portHandle, have := agent.portLoader.Lock(lPortNo) |
| 258 | if !have { |
| 259 | return status.Errorf(codes.NotFound, "port-%d-not-exist", lPortNo) |
| 260 | } |
| 261 | defer portHandle.Unlock() |
| 262 | |
| 263 | oldPort := portHandle.GetReadOnly() |
| 264 | |
| 265 | newPort := *oldPort // only clone the struct(s) that will be changed |
| 266 | newOfpPort := *oldPort.OfpPort |
| 267 | newPort.OfpPort = &newOfpPort |
| 268 | |
Andrey Pozolotin | 34dd63f | 2021-05-31 21:26:40 +0300 | [diff] [blame] | 269 | newOfpPort.Config &= ^uint32(ofp.OfpPortConfig_OFPPC_PORT_DOWN) |
Kent Hagerman | fa9d6d4 | 2020-05-25 11:49:40 -0400 | [diff] [blame] | 270 | if err := portHandle.Update(ctx, &newPort); err != nil { |
Kent Hagerman | 3136fbd | 2020-05-14 10:30:45 -0400 | [diff] [blame] | 271 | return err |
| 272 | } |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 273 | agent.orderedEvents.send(ctx, agent, agent.logicalDeviceID, ofp.OfpPortReason_OFPPR_MODIFY, newPort.OfpPort) |
Kent Hagerman | 3136fbd | 2020-05-14 10:30:45 -0400 | [diff] [blame] | 274 | return nil |
| 275 | } |
| 276 | |
Kent Hagerman | fa9d6d4 | 2020-05-25 11:49:40 -0400 | [diff] [blame] | 277 | // disableLogicalPort disabled the logical port |
| 278 | func (agent *LogicalAgent) disableLogicalPort(ctx context.Context, lPortNo uint32) error { |
| 279 | portHandle, have := agent.portLoader.Lock(lPortNo) |
| 280 | if !have { |
| 281 | return status.Errorf(codes.NotFound, "port-%d-not-exist", lPortNo) |
| 282 | } |
| 283 | defer portHandle.Unlock() |
| 284 | |
| 285 | oldPort := portHandle.GetReadOnly() |
| 286 | |
| 287 | newPort := *oldPort // only clone the struct(s) that will be changed |
| 288 | newOfpPort := *oldPort.OfpPort |
| 289 | newPort.OfpPort = &newOfpPort |
| 290 | |
| 291 | newOfpPort.Config = (newOfpPort.Config & ^uint32(ofp.OfpPortConfig_OFPPC_PORT_DOWN)) | uint32(ofp.OfpPortConfig_OFPPC_PORT_DOWN) |
| 292 | if err := portHandle.Update(ctx, &newPort); err != nil { |
khenaidoo | 0db4c81 | 2020-05-27 15:27:30 -0400 | [diff] [blame] | 293 | return err |
| 294 | } |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 295 | agent.orderedEvents.send(ctx, agent, agent.logicalDeviceID, ofp.OfpPortReason_OFPPR_MODIFY, newPort.OfpPort) |
Kent Hagerman | fa9d6d4 | 2020-05-25 11:49:40 -0400 | [diff] [blame] | 296 | return nil |
| 297 | } |
| 298 | |
| 299 | // addNNILogicalPort adds an NNI port to the logical device. It returns a bool representing whether a port has been |
| 300 | // added and an error in case a valid error is encountered. If the port was successfully added it will return |
| 301 | // (true, nil). If the device is not in the correct state it will return (false, nil) as this is a valid |
| 302 | // scenario. This also applies to the case where the port was already added. |
Kent Hagerman | 2a07b86 | 2020-06-19 15:23:07 -0400 | [diff] [blame] | 303 | func (agent *LogicalAgent) addNNILogicalPort(ctx context.Context, deviceID string, devicePorts map[uint32]*voltha.Port, port *voltha.Port) error { |
Himani Chawla | b4c2591 | 2020-11-12 17:16:38 +0530 | [diff] [blame] | 304 | logger.Debugw(ctx, "add-nni-logical-port", log.Fields{"logical-device-id": agent.logicalDeviceID, "nni-port": port}) |
Kent Hagerman | fa9d6d4 | 2020-05-25 11:49:40 -0400 | [diff] [blame] | 305 | |
| 306 | label := fmt.Sprintf("nni-%d", port.PortNo) |
khenaidoo | c6c7bda | 2020-06-17 17:20:18 -0400 | [diff] [blame] | 307 | ofpPort := *port.OfpPort |
| 308 | ofpPort.HwAddr = append([]uint32{}, port.OfpPort.HwAddr...) |
| 309 | ofpPort.PortNo = port.PortNo |
| 310 | ofpPort.Name = label |
| 311 | nniPort := &voltha.LogicalPort{ |
Kent Hagerman | fa9d6d4 | 2020-05-25 11:49:40 -0400 | [diff] [blame] | 312 | RootPort: true, |
Kent Hagerman | 2a07b86 | 2020-06-19 15:23:07 -0400 | [diff] [blame] | 313 | DeviceId: deviceID, |
Kent Hagerman | fa9d6d4 | 2020-05-25 11:49:40 -0400 | [diff] [blame] | 314 | Id: label, |
| 315 | DevicePortNo: port.PortNo, |
khenaidoo | c6c7bda | 2020-06-17 17:20:18 -0400 | [diff] [blame] | 316 | OfpPort: &ofpPort, |
Kent Hagerman | fa9d6d4 | 2020-05-25 11:49:40 -0400 | [diff] [blame] | 317 | OfpPortStats: &ofp.OfpPortStats{}, |
| 318 | } |
| 319 | |
khenaidoo | c6c7bda | 2020-06-17 17:20:18 -0400 | [diff] [blame] | 320 | portHandle, created, err := agent.portLoader.LockOrCreate(ctx, nniPort) |
Kent Hagerman | fa9d6d4 | 2020-05-25 11:49:40 -0400 | [diff] [blame] | 321 | if err != nil { |
| 322 | return err |
| 323 | } |
| 324 | defer portHandle.Unlock() |
| 325 | |
| 326 | if !created { |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 327 | logger.Debugw(ctx, "port-already-exist", log.Fields{"port": port}) |
Kent Hagerman | fa9d6d4 | 2020-05-25 11:49:40 -0400 | [diff] [blame] | 328 | return nil |
| 329 | } |
| 330 | |
Kent Hagerman | fa9d6d4 | 2020-05-25 11:49:40 -0400 | [diff] [blame] | 331 | // ensure that no events will be sent until this one is |
| 332 | queuePosition := agent.orderedEvents.assignQueuePosition() |
khenaidoo | 0db4c81 | 2020-05-27 15:27:30 -0400 | [diff] [blame] | 333 | |
| 334 | // Setup the routes for this device and then send the port update event to the OF Controller |
| 335 | go func() { |
| 336 | // First setup the routes |
Himani Chawla | b4c2591 | 2020-11-12 17:16:38 +0530 | [diff] [blame] | 337 | subCtx := coreutils.WithSpanAndRPCMetadataFromContext(ctx) |
| 338 | if err := agent.updateRoutes(subCtx, deviceID, devicePorts, nniPort, agent.listLogicalDevicePorts(ctx)); err != nil { |
khenaidoo | 0db4c81 | 2020-05-27 15:27:30 -0400 | [diff] [blame] | 339 | // This is not an error as we may not have enough logical ports to set up routes or some PON ports have not been |
| 340 | // created yet. |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 341 | logger.Infow(ctx, "routes-not-ready", log.Fields{"logical-device-id": agent.logicalDeviceID, "logical-port": nniPort.OfpPort.PortNo, "error": err}) |
khenaidoo | 0db4c81 | 2020-05-27 15:27:30 -0400 | [diff] [blame] | 342 | } |
Kent Hagerman | fa9d6d4 | 2020-05-25 11:49:40 -0400 | [diff] [blame] | 343 | // send event, and allow any queued events to be sent as well |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 344 | queuePosition.send(ctx, agent, agent.logicalDeviceID, ofp.OfpPortReason_OFPPR_ADD, nniPort.OfpPort) |
khenaidoo | 0db4c81 | 2020-05-27 15:27:30 -0400 | [diff] [blame] | 345 | }() |
khenaidoo | 0db4c81 | 2020-05-27 15:27:30 -0400 | [diff] [blame] | 346 | return nil |
| 347 | } |
| 348 | |
Kent Hagerman | fa9d6d4 | 2020-05-25 11:49:40 -0400 | [diff] [blame] | 349 | // addUNILogicalPort adds an UNI port to the logical device. It returns a bool representing whether a port has been |
| 350 | // added and an error in case a valid error is encountered. If the port was successfully added it will return |
| 351 | // (true, nil). If the device is not in the correct state it will return (false, nil) as this is a valid |
| 352 | // scenario. This also applies to the case where the port was already added. |
Kent Hagerman | 2a07b86 | 2020-06-19 15:23:07 -0400 | [diff] [blame] | 353 | func (agent *LogicalAgent) addUNILogicalPort(ctx context.Context, deviceID string, deviceAdminState voltha.AdminState_Types, deviceOperStatus voltha.OperStatus_Types, devicePorts map[uint32]*voltha.Port, port *voltha.Port) error { |
Himani Chawla | b4c2591 | 2020-11-12 17:16:38 +0530 | [diff] [blame] | 354 | logger.Debugw(ctx, "add-uni-logical-port", log.Fields{"port": port}) |
Kent Hagerman | 2a07b86 | 2020-06-19 15:23:07 -0400 | [diff] [blame] | 355 | if deviceAdminState != voltha.AdminState_ENABLED || deviceOperStatus != voltha.OperStatus_ACTIVE { |
divyadesai | cb8b59d | 2020-08-18 09:55:47 +0000 | [diff] [blame] | 356 | logger.Infow(ctx, "device-not-ready", log.Fields{"device-id": deviceID, "admin": deviceAdminState, "oper": deviceOperStatus}) |
Kent Hagerman | fa9d6d4 | 2020-05-25 11:49:40 -0400 | [diff] [blame] | 357 | return nil |
Kent Hagerman | 3136fbd | 2020-05-14 10:30:45 -0400 | [diff] [blame] | 358 | } |
khenaidoo | c6c7bda | 2020-06-17 17:20:18 -0400 | [diff] [blame] | 359 | ofpPort := *port.OfpPort |
| 360 | ofpPort.HwAddr = append([]uint32{}, port.OfpPort.HwAddr...) |
| 361 | ofpPort.PortNo = port.PortNo |
| 362 | uniPort := &voltha.LogicalPort{ |
Kent Hagerman | fa9d6d4 | 2020-05-25 11:49:40 -0400 | [diff] [blame] | 363 | RootPort: false, |
Kent Hagerman | 2a07b86 | 2020-06-19 15:23:07 -0400 | [diff] [blame] | 364 | DeviceId: deviceID, |
Kent Hagerman | fa9d6d4 | 2020-05-25 11:49:40 -0400 | [diff] [blame] | 365 | Id: port.Label, |
| 366 | DevicePortNo: port.PortNo, |
khenaidoo | c6c7bda | 2020-06-17 17:20:18 -0400 | [diff] [blame] | 367 | OfpPort: &ofpPort, |
Kent Hagerman | fa9d6d4 | 2020-05-25 11:49:40 -0400 | [diff] [blame] | 368 | OfpPortStats: &ofp.OfpPortStats{}, |
| 369 | } |
| 370 | |
khenaidoo | c6c7bda | 2020-06-17 17:20:18 -0400 | [diff] [blame] | 371 | portHandle, created, err := agent.portLoader.LockOrCreate(ctx, uniPort) |
Kent Hagerman | fa9d6d4 | 2020-05-25 11:49:40 -0400 | [diff] [blame] | 372 | if err != nil { |
| 373 | return err |
| 374 | } |
| 375 | defer portHandle.Unlock() |
| 376 | |
| 377 | if !created { |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 378 | logger.Debugw(ctx, "port-already-exist", log.Fields{"port": port}) |
Kent Hagerman | fa9d6d4 | 2020-05-25 11:49:40 -0400 | [diff] [blame] | 379 | return nil |
| 380 | } |
| 381 | |
Kent Hagerman | fa9d6d4 | 2020-05-25 11:49:40 -0400 | [diff] [blame] | 382 | // ensure that no events will be sent until this one is |
| 383 | queuePosition := agent.orderedEvents.assignQueuePosition() |
Kent Hagerman | 3136fbd | 2020-05-14 10:30:45 -0400 | [diff] [blame] | 384 | |
Kent Hagerman | fa9d6d4 | 2020-05-25 11:49:40 -0400 | [diff] [blame] | 385 | // Setup the routes for this device and then send the port update event to the OF Controller |
| 386 | go func() { |
Himani Chawla | b4c2591 | 2020-11-12 17:16:38 +0530 | [diff] [blame] | 387 | subCtx := coreutils.WithSpanAndRPCMetadataFromContext(ctx) |
Kent Hagerman | fa9d6d4 | 2020-05-25 11:49:40 -0400 | [diff] [blame] | 388 | // First setup the routes |
Himani Chawla | b4c2591 | 2020-11-12 17:16:38 +0530 | [diff] [blame] | 389 | if err := agent.updateRoutes(subCtx, deviceID, devicePorts, uniPort, agent.listLogicalDevicePorts(ctx)); err != nil { |
Kent Hagerman | fa9d6d4 | 2020-05-25 11:49:40 -0400 | [diff] [blame] | 390 | // This is not an error as we may not have enough logical ports to set up routes or some PON ports have not been |
| 391 | // created yet. |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 392 | logger.Infow(ctx, "routes-not-ready", log.Fields{"logical-device-id": agent.logicalDeviceID, "logical-port": uniPort.OfpPort.PortNo, "error": err}) |
Kent Hagerman | fa9d6d4 | 2020-05-25 11:49:40 -0400 | [diff] [blame] | 393 | } |
| 394 | // send event, and allow any queued events to be sent as well |
nikesh.krishnan | 95142d5 | 2023-02-24 15:32:11 +0530 | [diff] [blame] | 395 | queuePosition.send(ctx, agent, agent.logicalDeviceID, ofp.OfpPortReason_OFPPR_ADD, uniPort.OfpPort) |
Kent Hagerman | fa9d6d4 | 2020-05-25 11:49:40 -0400 | [diff] [blame] | 396 | }() |
Kent Hagerman | 3136fbd | 2020-05-14 10:30:45 -0400 | [diff] [blame] | 397 | return nil |
| 398 | } |
Himani Chawla | 40af270 | 2021-01-27 15:06:30 +0530 | [diff] [blame] | 399 | func (e *orderedEvents) waitForAllEventsToBeSent(ctx context.Context, cancel context.CancelFunc) error { |
| 400 | defer cancel() |
| 401 | ch := make(chan struct{}) |
| 402 | e.sendCompletion(ch) |
| 403 | select { |
| 404 | case <-ctx.Done(): |
| 405 | logger.Error(ctx, "timeout-while-waiting-for-event-queue-to-be-cleared") |
| 406 | return ctx.Err() |
| 407 | case <-ch: |
| 408 | logger.Debug(ctx, "event-queue-is-empty") |
| 409 | return nil |
| 410 | } |
| 411 | } |
Kent Hagerman | 3136fbd | 2020-05-14 10:30:45 -0400 | [diff] [blame] | 412 | |
Kent Hagerman | fa9d6d4 | 2020-05-25 11:49:40 -0400 | [diff] [blame] | 413 | // send is a convenience to avoid calling both assignQueuePosition and qp.send |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 414 | func (e *orderedEvents) send(ctx context.Context, agent *LogicalAgent, deviceID string, reason ofp.OfpPortReason, desc *ofp.OfpPort) { |
Kent Hagerman | fa9d6d4 | 2020-05-25 11:49:40 -0400 | [diff] [blame] | 415 | qp := e.assignQueuePosition() |
Himani Chawla | b4c2591 | 2020-11-12 17:16:38 +0530 | [diff] [blame] | 416 | subCtx := coreutils.WithSpanAndRPCMetadataFromContext(ctx) |
| 417 | go qp.send(subCtx, agent, deviceID, reason, desc) |
Kent Hagerman | 3136fbd | 2020-05-14 10:30:45 -0400 | [diff] [blame] | 418 | } |
| 419 | |
Himani Chawla | 40af270 | 2021-01-27 15:06:30 +0530 | [diff] [blame] | 420 | // sendCompletion will make sure that given channel is notified when queue is empty |
| 421 | func (e *orderedEvents) sendCompletion(ch chan struct{}) { |
| 422 | qp := e.assignQueuePosition() |
| 423 | go qp.sendCompletion(ch) |
| 424 | } |
| 425 | |
Kent Hagerman | fa9d6d4 | 2020-05-25 11:49:40 -0400 | [diff] [blame] | 426 | // TODO: shouldn't need to guarantee event ordering like this |
| 427 | // event ordering should really be protected by per-LogicalPort lock |
| 428 | // once routing uses on-demand calculation only, this should be changed |
| 429 | // assignQueuePosition ensures that no events will be sent until this thread calls send() on the returned queuePosition |
| 430 | func (e *orderedEvents) assignQueuePosition() queuePosition { |
| 431 | e.mutex.Lock() |
| 432 | defer e.mutex.Unlock() |
Kent Hagerman | 3136fbd | 2020-05-14 10:30:45 -0400 | [diff] [blame] | 433 | |
Kent Hagerman | fa9d6d4 | 2020-05-25 11:49:40 -0400 | [diff] [blame] | 434 | prev := e.last |
| 435 | next := make(chan struct{}) |
| 436 | e.last = next |
| 437 | return queuePosition{ |
| 438 | prev: prev, |
| 439 | next: next, |
Kent Hagerman | 3136fbd | 2020-05-14 10:30:45 -0400 | [diff] [blame] | 440 | } |
| 441 | } |
| 442 | |
Kent Hagerman | fa9d6d4 | 2020-05-25 11:49:40 -0400 | [diff] [blame] | 443 | // orderedEvents guarantees the order that events are sent, while allowing events to back up. |
| 444 | type orderedEvents struct { |
| 445 | mutex sync.Mutex |
| 446 | last <-chan struct{} |
Kent Hagerman | 3136fbd | 2020-05-14 10:30:45 -0400 | [diff] [blame] | 447 | } |
| 448 | |
Kent Hagerman | fa9d6d4 | 2020-05-25 11:49:40 -0400 | [diff] [blame] | 449 | type queuePosition struct { |
| 450 | prev <-chan struct{} |
| 451 | next chan<- struct{} |
Kent Hagerman | 3136fbd | 2020-05-14 10:30:45 -0400 | [diff] [blame] | 452 | } |
| 453 | |
Kent Hagerman | fa9d6d4 | 2020-05-25 11:49:40 -0400 | [diff] [blame] | 454 | // send waits for its turn, then sends the event, then notifies the next in line |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 455 | func (qp queuePosition) send(ctx context.Context, agent *LogicalAgent, deviceID string, reason ofp.OfpPortReason, desc *ofp.OfpPort) { |
Kent Hagerman | fa9d6d4 | 2020-05-25 11:49:40 -0400 | [diff] [blame] | 456 | if qp.prev != nil { |
| 457 | <-qp.prev // wait for turn |
| 458 | } |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 459 | agent.ldeviceMgr.SendChangeEvent(ctx, deviceID, reason, desc) |
Kent Hagerman | fa9d6d4 | 2020-05-25 11:49:40 -0400 | [diff] [blame] | 460 | close(qp.next) // notify next |
Himani Chawla | 40af270 | 2021-01-27 15:06:30 +0530 | [diff] [blame] | 461 | |
| 462 | } |
| 463 | |
| 464 | // sendCompletion waits for its turn, then notifies the given channel that queue is empty |
| 465 | func (qp queuePosition) sendCompletion(ch chan struct{}) { |
| 466 | if qp.prev != nil { |
| 467 | <-qp.prev // wait for turn |
| 468 | } |
| 469 | close(ch) |
| 470 | close(qp.next) |
Kent Hagerman | fa9d6d4 | 2020-05-25 11:49:40 -0400 | [diff] [blame] | 471 | } |
| 472 | |
| 473 | // GetWildcardInputPorts filters out the logical port number from the set of logical ports on the device and |
| 474 | // returns their port numbers. |
Rohan Agrawal | 31f2180 | 2020-06-12 05:38:46 +0000 | [diff] [blame] | 475 | func (agent *LogicalAgent) GetWildcardInputPorts(ctx context.Context, excludePort uint32) map[uint32]struct{} { |
Kent Hagerman | fa9d6d4 | 2020-05-25 11:49:40 -0400 | [diff] [blame] | 476 | portIDs := agent.portLoader.ListIDs() |
| 477 | delete(portIDs, excludePort) |
| 478 | return portIDs |
| 479 | } |
| 480 | |
| 481 | // isNNIPort return true iff the specified port belongs to the parent (OLT) device |
Kent Hagerman | 3136fbd | 2020-05-14 10:30:45 -0400 | [diff] [blame] | 482 | func (agent *LogicalAgent) isNNIPort(portNo uint32) bool { |
Kent Hagerman | fa9d6d4 | 2020-05-25 11:49:40 -0400 | [diff] [blame] | 483 | portHandle, have := agent.portLoader.Lock(portNo) |
| 484 | if !have { |
| 485 | return false |
Kent Hagerman | 3136fbd | 2020-05-14 10:30:45 -0400 | [diff] [blame] | 486 | } |
Kent Hagerman | fa9d6d4 | 2020-05-25 11:49:40 -0400 | [diff] [blame] | 487 | defer portHandle.Unlock() |
| 488 | |
| 489 | // any root-device logical port is an NNI port |
| 490 | return portHandle.GetReadOnly().RootPort |
Kent Hagerman | 3136fbd | 2020-05-14 10:30:45 -0400 | [diff] [blame] | 491 | } |
| 492 | |
Kent Hagerman | fa9d6d4 | 2020-05-25 11:49:40 -0400 | [diff] [blame] | 493 | // getAnyNNIPort returns an NNI port |
| 494 | func (agent *LogicalAgent) getAnyNNIPort() (uint32, error) { |
| 495 | for portID := range agent.portLoader.ListIDsForDevice(agent.rootDeviceID) { |
| 496 | return portID, nil |
Kent Hagerman | 3136fbd | 2020-05-14 10:30:45 -0400 | [diff] [blame] | 497 | } |
| 498 | return 0, status.Error(codes.NotFound, "No NNI port found") |
| 499 | } |
| 500 | |
Kent Hagerman | fa9d6d4 | 2020-05-25 11:49:40 -0400 | [diff] [blame] | 501 | //GetNNIPorts returns all NNI ports |
| 502 | func (agent *LogicalAgent) GetNNIPorts() map[uint32]struct{} { |
| 503 | return agent.portLoader.ListIDsForDevice(agent.rootDeviceID) |
Kent Hagerman | 3136fbd | 2020-05-14 10:30:45 -0400 | [diff] [blame] | 504 | } |
| 505 | |
| 506 | // getUNILogicalPortNo returns the UNI logical port number specified in the flow |
| 507 | func (agent *LogicalAgent) getUNILogicalPortNo(flow *ofp.OfpFlowStats) (uint32, error) { |
Kent Hagerman | 3136fbd | 2020-05-14 10:30:45 -0400 | [diff] [blame] | 508 | inPortNo := fu.GetInPort(flow) |
| 509 | outPortNo := fu.GetOutPort(flow) |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 510 | if inPortNo == 0 && outPortNo == 0 { |
| 511 | return 0, status.Errorf(codes.NotFound, "no-uni-port: %v", flow) |
Kent Hagerman | 3136fbd | 2020-05-14 10:30:45 -0400 | [diff] [blame] | 512 | } |
khenaidoo | d948f77 | 2021-08-11 17:49:24 -0400 | [diff] [blame] | 513 | if inPortNo != 0 && !agent.isNNIPort(inPortNo) { |
| 514 | return inPortNo, nil |
| 515 | } |
| 516 | if outPortNo != 0 && !agent.isNNIPort(outPortNo) { |
| 517 | return outPortNo, nil |
Kent Hagerman | 3136fbd | 2020-05-14 10:30:45 -0400 | [diff] [blame] | 518 | } |
| 519 | return 0, status.Errorf(codes.NotFound, "no-uni-port: %v", flow) |
| 520 | } |