Fix active path index in OplinkSwitchProtection
Change-Id: Ie1202a944242cb789749510ff2b319a55e83e275
diff --git a/drivers/optical/src/main/java/org/onosproject/driver/optical/protection/OplinkSwitchProtection.java b/drivers/optical/src/main/java/org/onosproject/driver/optical/protection/OplinkSwitchProtection.java
index 16009f7..01573870 100644
--- a/drivers/optical/src/main/java/org/onosproject/driver/optical/protection/OplinkSwitchProtection.java
+++ b/drivers/optical/src/main/java/org/onosproject/driver/optical/protection/OplinkSwitchProtection.java
@@ -210,7 +210,10 @@
return attributes;
}
- private int getActiveIndex() {
+ /*
+ * get activer port number
+ */
+ private int getActivePort() {
Port port = handler().get(DeviceService.class)
.getPort(data().deviceId(), PortNumber.portNumber(PRIMARY_PORT));
if (port != null) {
@@ -223,6 +226,21 @@
}
/*
+ * get active path index
+ */
+ private int getActiveIndex(List<TransportEndpointState> pathStates) {
+ long activePort = (long) getActivePort();
+ int activeIndex = 0;
+ for (TransportEndpointState state : pathStates) {
+ if (state.description().output().connectPoint().port().toLong() == activePort) {
+ return activeIndex;
+ }
+ ++activeIndex;
+ }
+ return ProtectedTransportEndpointState.ACTIVE_UNKNOWN;
+ }
+
+ /*
* get protected endpoint state
*/
private ProtectedTransportEndpointState getProtectedTransportEndpointState() {
@@ -254,7 +272,7 @@
return ProtectedTransportEndpointState.builder()
.withDescription(getProtectedTransportEndpointDescription())
.withPathStates(tess)
- .withActivePathIndex(getActiveIndex())
+ .withActivePathIndex(getActiveIndex(tess))
.build();
}