ONOS-539 - Capture port names so CLI can display them
Change-Id: I40b24c401c782a452a66c081623f5bba5ea5c9af
Showing
1 changed file
with
25 additions
and
2 deletions
... | @@ -56,6 +56,8 @@ import org.slf4j.Logger; | ... | @@ -56,6 +56,8 @@ import org.slf4j.Logger; |
56 | import java.util.ArrayList; | 56 | import java.util.ArrayList; |
57 | import java.util.List; | 57 | import java.util.List; |
58 | 58 | ||
59 | +import com.google.common.base.Strings; | ||
60 | + | ||
59 | import static org.onosproject.net.DeviceId.deviceId; | 61 | import static org.onosproject.net.DeviceId.deviceId; |
60 | import static org.onosproject.net.Port.Type.COPPER; | 62 | import static org.onosproject.net.Port.Type.COPPER; |
61 | import static org.onosproject.net.Port.Type.FIBER; | 63 | import static org.onosproject.net.Port.Type.FIBER; |
... | @@ -265,6 +267,23 @@ public class OpenFlowDeviceProvider extends AbstractProvider implements DevicePr | ... | @@ -265,6 +267,23 @@ public class OpenFlowDeviceProvider extends AbstractProvider implements DevicePr |
265 | } | 267 | } |
266 | 268 | ||
267 | /** | 269 | /** |
270 | + * Creates an annotation for the port name if one is available. | ||
271 | + * | ||
272 | + * @param port description of the port | ||
273 | + * @return annotation containing the port name if one is found, | ||
274 | + * null otherwise | ||
275 | + */ | ||
276 | + private SparseAnnotations makePortNameAnnotation(OFPortDesc port) { | ||
277 | + SparseAnnotations annotations = null; | ||
278 | + String portName = Strings.emptyToNull(port.getName()); | ||
279 | + if (portName != null) { | ||
280 | + annotations = DefaultAnnotations.builder() | ||
281 | + .set("portName", portName).build(); | ||
282 | + } | ||
283 | + return annotations; | ||
284 | + } | ||
285 | + | ||
286 | + /** | ||
268 | * Build a portDescription from a given port. | 287 | * Build a portDescription from a given port. |
269 | * | 288 | * |
270 | * @param port the port to build from. | 289 | * @param port the port to build from. |
... | @@ -276,7 +295,9 @@ public class OpenFlowDeviceProvider extends AbstractProvider implements DevicePr | ... | @@ -276,7 +295,9 @@ public class OpenFlowDeviceProvider extends AbstractProvider implements DevicePr |
276 | !port.getState().contains(OFPortState.LINK_DOWN) && | 295 | !port.getState().contains(OFPortState.LINK_DOWN) && |
277 | !port.getConfig().contains(OFPortConfig.PORT_DOWN); | 296 | !port.getConfig().contains(OFPortConfig.PORT_DOWN); |
278 | Port.Type type = port.getCurr().contains(OFPortFeatures.PF_FIBER) ? FIBER : COPPER; | 297 | Port.Type type = port.getCurr().contains(OFPortFeatures.PF_FIBER) ? FIBER : COPPER; |
279 | - return new DefaultPortDescription(portNo, enabled, type, portSpeed(port)); | 298 | + SparseAnnotations annotations = makePortNameAnnotation(port); |
299 | + return new DefaultPortDescription(portNo, enabled, type, | ||
300 | + portSpeed(port), annotations); | ||
280 | } | 301 | } |
281 | 302 | ||
282 | private PortDescription buildPortDescription(OFPortStatus status) { | 303 | private PortDescription buildPortDescription(OFPortStatus status) { |
... | @@ -286,7 +307,9 @@ public class OpenFlowDeviceProvider extends AbstractProvider implements DevicePr | ... | @@ -286,7 +307,9 @@ public class OpenFlowDeviceProvider extends AbstractProvider implements DevicePr |
286 | } else { | 307 | } else { |
287 | PortNumber portNo = PortNumber.portNumber(port.getPortNo().getPortNumber()); | 308 | PortNumber portNo = PortNumber.portNumber(port.getPortNo().getPortNumber()); |
288 | Port.Type type = port.getCurr().contains(OFPortFeatures.PF_FIBER) ? FIBER : COPPER; | 309 | Port.Type type = port.getCurr().contains(OFPortFeatures.PF_FIBER) ? FIBER : COPPER; |
289 | - return new DefaultPortDescription(portNo, false, type, portSpeed(port)); | 310 | + SparseAnnotations annotations = makePortNameAnnotation(port); |
311 | + return new DefaultPortDescription(portNo, false, type, | ||
312 | + portSpeed(port), annotations); | ||
290 | } | 313 | } |
291 | } | 314 | } |
292 | 315 | ... | ... |
-
Please register or login to post a comment