Priyanka B
Committed by Gerrit Code Review

[ONOS-4738], [ONOS-4737], [ONOS-4741]resilency defect fix

Change-Id: Ie708e932d95d3eedad417075f39135aae31064d9
...@@ -116,7 +116,6 @@ import static org.onosproject.incubator.net.tunnel.Tunnel.Type.MPLS; ...@@ -116,7 +116,6 @@ import static org.onosproject.incubator.net.tunnel.Tunnel.Type.MPLS;
116 import static org.onosproject.incubator.net.tunnel.Tunnel.State.INIT; 116 import static org.onosproject.incubator.net.tunnel.Tunnel.State.INIT;
117 import static org.onosproject.incubator.net.tunnel.Tunnel.State.ESTABLISHED; 117 import static org.onosproject.incubator.net.tunnel.Tunnel.State.ESTABLISHED;
118 import static org.onosproject.incubator.net.tunnel.Tunnel.State.UNSTABLE; 118 import static org.onosproject.incubator.net.tunnel.Tunnel.State.UNSTABLE;
119 -import static org.onosproject.incubator.net.tunnel.Tunnel.State.FAILED;
120 import static org.onosproject.pce.pceservice.LspType.WITH_SIGNALLING; 119 import static org.onosproject.pce.pceservice.LspType.WITH_SIGNALLING;
121 import static org.onosproject.pce.pceservice.LspType.SR_WITHOUT_SIGNALLING; 120 import static org.onosproject.pce.pceservice.LspType.SR_WITHOUT_SIGNALLING;
122 import static org.onosproject.pce.pceservice.LspType.WITHOUT_SIGNALLING_AND_WITHOUT_SR; 121 import static org.onosproject.pce.pceservice.LspType.WITHOUT_SIGNALLING_AND_WITHOUT_SR;
...@@ -1185,10 +1184,6 @@ public class PceManager implements PceService { ...@@ -1185,10 +1184,6 @@ public class PceManager implements PceService {
1185 tunnel.tunnelName().value(), constraints, lspType)); 1184 tunnel.tunnelName().value(), constraints, lspType));
1186 } 1185 }
1187 1186
1188 - if (tunnel.state() == FAILED) {
1189 - // Check whether this ONOS instance is master, if yes, recompute and send update.
1190 - checkForMasterAndUpdateTunnel(tunnel.path().src().deviceId(), tunnel);
1191 - }
1192 break; 1187 break;
1193 1188
1194 case TUNNEL_REMOVED: 1189 case TUNNEL_REMOVED:
......
...@@ -664,6 +664,11 @@ public class PceWebTopovMessageHandler extends UiMessageHandler { ...@@ -664,6 +664,11 @@ public class PceWebTopovMessageHandler extends UiMessageHandler {
664 sendMessage(TopoJson.highlightsMessage(highlights)); 664 sendMessage(TopoJson.highlightsMessage(highlights));
665 return; 665 return;
666 } 666 }
667 + if (!tunnel.state().equals(Tunnel.State.ACTIVE)) {
668 + log.debug("Tunnel state is not active");
669 + sendMessage(TopoJson.highlightsMessage(highlights));
670 + return;
671 + }
667 Link firstLink = tunnel.path().links().get(0); 672 Link firstLink = tunnel.path().links().get(0);
668 if (firstLink != null) { 673 if (firstLink != null) {
669 if (firstLink.src() != null) { 674 if (firstLink.src() != null) {
......
...@@ -107,8 +107,6 @@ public final class BgpLinkAttrMaxLinkBandwidth implements BgpValueType { ...@@ -107,8 +107,6 @@ public final class BgpLinkAttrMaxLinkBandwidth implements BgpValueType {
107 * @return normal float 107 * @return normal float
108 */ 108 */
109 static float ieeeToFloatRead(int iVal) { 109 static float ieeeToFloatRead(int iVal) {
110 - iVal = (((iVal & 0xFF) << 24) | ((iVal & 0xFF00) << 8)
111 - | ((iVal & 0xFF0000) >> 8) | ((iVal >> 24) & 0xFF));
112 110
113 return Float.intBitsToFloat(iVal); 111 return Float.intBitsToFloat(iVal);
114 } 112 }
......
...@@ -115,8 +115,6 @@ public class BgpLinkAttrUnRsrvdLinkBandwidth implements BgpValueType { ...@@ -115,8 +115,6 @@ public class BgpLinkAttrUnRsrvdLinkBandwidth implements BgpValueType {
115 * @return normal float 115 * @return normal float
116 */ 116 */
117 static float ieeeToFloatRead(int iVal) { 117 static float ieeeToFloatRead(int iVal) {
118 - iVal = (((iVal & 0xFF) << 24) | ((iVal & 0xFF00) << 8)
119 - | ((iVal & 0xFF0000) >> 8) | ((iVal >> 24) & 0xFF));
120 118
121 return Float.intBitsToFloat(iVal); 119 return Float.intBitsToFloat(iVal);
122 } 120 }
......
...@@ -135,8 +135,6 @@ public class PcepBandwidthObjectVer1 implements PcepBandwidthObject { ...@@ -135,8 +135,6 @@ public class PcepBandwidthObjectVer1 implements PcepBandwidthObject {
135 * @return normal float 135 * @return normal float
136 */ 136 */
137 public static float ieeeToFloatRead(int iVal) { 137 public static float ieeeToFloatRead(int iVal) {
138 - iVal = (((iVal & 0xFF) << 24) | ((iVal & 0xFF00) << 8)
139 - | ((iVal & 0xFF0000) >> 8) | ((iVal >> 24) & 0xFF));
140 138
141 return Float.intBitsToFloat(iVal); 139 return Float.intBitsToFloat(iVal);
142 } 140 }
......
...@@ -492,8 +492,8 @@ public class BgpTopologyProvider extends AbstractProvider implements DeviceProvi ...@@ -492,8 +492,8 @@ public class BgpTopologyProvider extends AbstractProvider implements DeviceProvi
492 switch (tlv.getType()) { 492 switch (tlv.getType()) {
493 case LinkStateAttributes.ATTR_LINK_MAX_RES_BANDWIDTH: 493 case LinkStateAttributes.ATTR_LINK_MAX_RES_BANDWIDTH:
494 maxReservableBw = ((BgpLinkAttrMaxLinkBandwidth) tlv).linkAttrMaxLinkBandwidth(); 494 maxReservableBw = ((BgpLinkAttrMaxLinkBandwidth) tlv).linkAttrMaxLinkBandwidth();
495 - //will get in bytes/second , convert to MBPS to store in network config service 495 + //will get in bits/second , convert to MBPS to store in network config service
496 - maxReservableBw = maxReservableBw * 8 / 1000000; 496 + maxReservableBw = maxReservableBw / 1000000;
497 break; 497 break;
498 default: // do nothing 498 default: // do nothing
499 } 499 }
......
...@@ -1005,7 +1005,7 @@ public class BgpTopologyProviderTest { ...@@ -1005,7 +1005,7 @@ public class BgpTopologyProviderTest {
1005 linkStateAttr.add(tlv); 1005 linkStateAttr.add(tlv);
1006 tlv = BgpLinkAttrTeDefaultMetric.of(20); 1006 tlv = BgpLinkAttrTeDefaultMetric.of(20);
1007 linkStateAttr.add(tlv); 1007 linkStateAttr.add(tlv);
1008 - tlv = BgpLinkAttrMaxLinkBandwidth.of((float) 8.75 * 1_000_000L, 1008 + tlv = BgpLinkAttrMaxLinkBandwidth.of((float) 70 * 1_000_000L,
1009 LinkStateAttributes.ATTR_LINK_MAX_RES_BANDWIDTH); 1009 LinkStateAttributes.ATTR_LINK_MAX_RES_BANDWIDTH);
1010 linkStateAttr.add(tlv); 1010 linkStateAttr.add(tlv);
1011 linkPathAttributes.add(new LinkStateAttributes(linkStateAttr)); 1011 linkPathAttributes.add(new LinkStateAttributes(linkStateAttr));
......
...@@ -66,6 +66,7 @@ import org.onosproject.net.Path; ...@@ -66,6 +66,7 @@ import org.onosproject.net.Path;
66 import org.onosproject.net.PortNumber; 66 import org.onosproject.net.PortNumber;
67 import org.onosproject.net.SparseAnnotations; 67 import org.onosproject.net.SparseAnnotations;
68 import org.onosproject.net.device.DeviceService; 68 import org.onosproject.net.device.DeviceService;
69 +import org.onosproject.net.link.LinkService;
69 import org.onosproject.net.provider.AbstractProvider; 70 import org.onosproject.net.provider.AbstractProvider;
70 import org.onosproject.net.provider.ProviderId; 71 import org.onosproject.net.provider.ProviderId;
71 import org.onosproject.pcep.api.PcepController; 72 import org.onosproject.pcep.api.PcepController;
...@@ -213,6 +214,9 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid ...@@ -213,6 +214,9 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid
213 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 214 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
214 protected DeviceService deviceService; 215 protected DeviceService deviceService;
215 216
217 + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
218 + protected LinkService linkService;
219 +
216 TunnelProviderService service; 220 TunnelProviderService service;
217 221
218 HashMap<String, TunnelId> tunnelMap = new HashMap<String, TunnelId>(); 222 HashMap<String, TunnelId> tunnelMap = new HashMap<String, TunnelId>();
...@@ -611,6 +615,7 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid ...@@ -611,6 +615,7 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid
611 if (tunnel.type() == MPLS) { 615 if (tunnel.type() == MPLS) {
612 pcepTunnelApiMapper.removeFromCoreTunnelRequestQueue(tunnel.id()); 616 pcepTunnelApiMapper.removeFromCoreTunnelRequestQueue(tunnel.id());
613 service.tunnelRemoved(tunnel); 617 service.tunnelRemoved(tunnel);
618 + return;
614 } 619 }
615 620
616 Tunnel tunnelOld = tunnelQueryById(tunnel.id()); 621 Tunnel tunnelOld = tunnelQueryById(tunnel.id());
...@@ -1681,8 +1686,8 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid ...@@ -1681,8 +1686,8 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid
1681 if (lspObj.getDFlag()) { 1686 if (lspObj.getDFlag()) {
1682 annotations = getAnnotations(lspObj, ipv4LspIdenTlv, bandwidth, lspType, costType); 1687 annotations = getAnnotations(lspObj, ipv4LspIdenTlv, bandwidth, lspType, costType);
1683 td = new DefaultTunnelDescription(null, tunnelEndPointSrc, tunnelEndPointDst, MPLS, new DefaultGroupId( 1688 td = new DefaultTunnelDescription(null, tunnelEndPointSrc, tunnelEndPointDst, MPLS, new DefaultGroupId(
1684 - 0), providerId, TunnelName.tunnelName(new String(pathNameTlv.getValue())), path, labelStack, 1689 + 0), providerId, TunnelName.tunnelName(new String(pathNameTlv.getValue())),
1685 - annotations); 1690 + tunnel.path(), labelStack, annotations);
1686 tunnelUpdateInDelegatedCase(pccId, annotations, td, providerId); 1691 tunnelUpdateInDelegatedCase(pccId, annotations, td, providerId);
1687 } 1692 }
1688 removeOrUpdatetunnel(tunnel, pccId, lspObj, providerId, tunnelState); 1693 removeOrUpdatetunnel(tunnel, pccId, lspObj, providerId, tunnelState);
...@@ -1744,12 +1749,29 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid ...@@ -1744,12 +1749,29 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid
1744 1749
1745 IPv4SubObject ipv4SubObj = (IPv4SubObject) subObj; 1750 IPv4SubObject ipv4SubObj = (IPv4SubObject) subObj;
1746 if (!isSrcSet) { 1751 if (!isSrcSet) {
1747 - IpAddress srcIp = IpAddress.valueOf(ipv4SubObj.getIpAddress()); 1752 + Iterable<Link> links = linkService.getActiveLinks();
1748 - src = new ConnectPoint(IpElementId.ipElement(srcIp), PortNumber.portNumber(0)); 1753 + for (Link l : links) {
1749 - isSrcSet = true; 1754 + if (l.src().port().equals(PortNumber.portNumber(ipv4SubObj.getIpAddress()))) {
1750 - } else { 1755 + src = l.src();
1751 - IpAddress dstIp = IpAddress.valueOf(ipv4SubObj.getIpAddress()); 1756 + isSrcSet = true;
1752 - dst = new ConnectPoint(IpElementId.ipElement(dstIp), PortNumber.portNumber(0)); 1757 + break;
1758 + } else if (l.dst().port().equals(PortNumber.portNumber(ipv4SubObj.getIpAddress()))) {
1759 + src = l.dst();
1760 + isSrcSet = true;
1761 + break;
1762 + }
1763 + }
1764 + } else {
1765 + Iterable<Link> links = linkService.getActiveLinks();
1766 + for (Link l : links) {
1767 + if (l.src().port().equals(PortNumber.portNumber(ipv4SubObj.getIpAddress()))) {
1768 + dst = l.src();
1769 + break;
1770 + } else if (l.dst().port().equals(PortNumber.portNumber(ipv4SubObj.getIpAddress()))) {
1771 + dst = l.dst();
1772 + break;
1773 + }
1774 + }
1753 Link link = DefaultLink.builder() 1775 Link link = DefaultLink.builder()
1754 .providerId(providerId) 1776 .providerId(providerId)
1755 .src(src) 1777 .src(src)
......
...@@ -28,6 +28,7 @@ import static org.onosproject.pcep.controller.PcepAnnotationKeys.DELEGATE; ...@@ -28,6 +28,7 @@ import static org.onosproject.pcep.controller.PcepAnnotationKeys.DELEGATE;
28 import static org.onosproject.pcep.controller.LspType.WITHOUT_SIGNALLING_AND_WITHOUT_SR; 28 import static org.onosproject.pcep.controller.LspType.WITHOUT_SIGNALLING_AND_WITHOUT_SR;
29 import static org.onosproject.pcep.controller.PcepSyncStatus.SYNCED; 29 import static org.onosproject.pcep.controller.PcepSyncStatus.SYNCED;
30 import static org.onosproject.net.Device.Type.ROUTER; 30 import static org.onosproject.net.Device.Type.ROUTER;
31 +import static org.onosproject.net.Link.State.ACTIVE;
31 import static org.onosproject.net.MastershipRole.MASTER; 32 import static org.onosproject.net.MastershipRole.MASTER;
32 33
33 import java.io.IOException; 34 import java.io.IOException;
...@@ -62,15 +63,20 @@ import org.onosproject.incubator.net.tunnel.TunnelProviderService; ...@@ -62,15 +63,20 @@ import org.onosproject.incubator.net.tunnel.TunnelProviderService;
62 import org.onosproject.incubator.net.tunnel.Tunnel.State; 63 import org.onosproject.incubator.net.tunnel.Tunnel.State;
63 import org.onosproject.mastership.MastershipServiceAdapter; 64 import org.onosproject.mastership.MastershipServiceAdapter;
64 import org.onosproject.net.AnnotationKeys; 65 import org.onosproject.net.AnnotationKeys;
66 +import org.onosproject.net.ConnectPoint;
65 import org.onosproject.net.DefaultAnnotations; 67 import org.onosproject.net.DefaultAnnotations;
66 import org.onosproject.net.DefaultDevice; 68 import org.onosproject.net.DefaultDevice;
69 +import org.onosproject.net.DefaultLink;
67 import org.onosproject.net.Device; 70 import org.onosproject.net.Device;
68 import org.onosproject.net.DeviceId; 71 import org.onosproject.net.DeviceId;
69 import org.onosproject.net.ElementId; 72 import org.onosproject.net.ElementId;
73 +import org.onosproject.net.Link;
70 import org.onosproject.net.MastershipRole; 74 import org.onosproject.net.MastershipRole;
71 import org.onosproject.net.Path; 75 import org.onosproject.net.Path;
76 +import org.onosproject.net.PortNumber;
72 import org.onosproject.net.SparseAnnotations; 77 import org.onosproject.net.SparseAnnotations;
73 import org.onosproject.net.device.DeviceServiceAdapter; 78 import org.onosproject.net.device.DeviceServiceAdapter;
79 +import org.onosproject.net.link.LinkServiceAdapter;
74 import org.onosproject.net.provider.ProviderId; 80 import org.onosproject.net.provider.ProviderId;
75 import org.onosproject.pcepio.exceptions.PcepOutOfBoundMessageException; 81 import org.onosproject.pcepio.exceptions.PcepOutOfBoundMessageException;
76 import org.onosproject.pcepio.exceptions.PcepParseException; 82 import org.onosproject.pcepio.exceptions.PcepParseException;
...@@ -82,6 +88,7 @@ import org.onosproject.pcep.controller.ClientCapability; ...@@ -82,6 +88,7 @@ import org.onosproject.pcep.controller.ClientCapability;
82 import org.onosproject.pcep.controller.LspKey; 88 import org.onosproject.pcep.controller.LspKey;
83 import org.onosproject.pcep.controller.PccId; 89 import org.onosproject.pcep.controller.PccId;
84 90
91 +import com.google.common.collect.FluentIterable;
85 import com.google.common.collect.ImmutableSet; 92 import com.google.common.collect.ImmutableSet;
86 93
87 /** 94 /**
...@@ -99,8 +106,23 @@ public class PcepTunnelAddedTest { ...@@ -99,8 +106,23 @@ public class PcepTunnelAddedTest {
99 private final MockTunnelServiceAdapter tunnelService = new MockTunnelServiceAdapter(); 106 private final MockTunnelServiceAdapter tunnelService = new MockTunnelServiceAdapter();
100 public final MockDeviceService deviceService = new MockDeviceService(); 107 public final MockDeviceService deviceService = new MockDeviceService();
101 private final MockMasterShipService masterShipService = new MockMasterShipService(); 108 private final MockMasterShipService masterShipService = new MockMasterShipService();
109 + private final MockLinkService linkService = new MockLinkService();
102 private final MockTunnelAdminService tunnelAdminService = new MockTunnelAdminService(); 110 private final MockTunnelAdminService tunnelAdminService = new MockTunnelAdminService();
103 111
112 + private class MockLinkService extends LinkServiceAdapter {
113 + LinkedList<Link> links = new LinkedList<>();
114 + void addLink(Link link) {
115 + links.add(link);
116 + }
117 +
118 + @Override
119 + public Iterable<Link> getActiveLinks() {
120 +
121 + return FluentIterable.from(links)
122 + .filter(input -> input.state() == Link.State.ACTIVE);
123 + }
124 + }
125 +
104 private class MockTunnelAdminService implements TunnelAdminService { 126 private class MockTunnelAdminService implements TunnelAdminService {
105 127
106 @Override 128 @Override
...@@ -275,6 +297,7 @@ public class PcepTunnelAddedTest { ...@@ -275,6 +297,7 @@ public class PcepTunnelAddedTest {
275 tunnelProvider.tunnelService = tunnelService; 297 tunnelProvider.tunnelService = tunnelService;
276 tunnelProvider.tunnelAdminService = tunnelAdminService; 298 tunnelProvider.tunnelAdminService = tunnelAdminService;
277 tunnelProvider.service = registry.register(tunnelProvider); 299 tunnelProvider.service = registry.register(tunnelProvider);
300 + tunnelProvider.linkService = linkService;
278 tunnelProvider.activate(); 301 tunnelProvider.activate();
279 } 302 }
280 303
...@@ -326,6 +349,14 @@ public class PcepTunnelAddedTest { ...@@ -326,6 +349,14 @@ public class PcepTunnelAddedTest {
326 controller.getClient(PccId.pccId(IpAddress.valueOf("1.1.1.1"))).setCapability( 349 controller.getClient(PccId.pccId(IpAddress.valueOf("1.1.1.1"))).setCapability(
327 new ClientCapability(true, true, true, true, true)); 350 new ClientCapability(true, true, true, true, true));
328 masterShipService.setMaster(true); 351 masterShipService.setMaster(true);
352 + Link link = DefaultLink.builder()
353 + .src(new ConnectPoint(device.id(), PortNumber.portNumber(16843009)))
354 + .dst(new ConnectPoint(device.id(), PortNumber.portNumber(84215045)))
355 + .state(ACTIVE)
356 + .type(Link.Type.DIRECT)
357 + .providerId(ProviderId.NONE)
358 + .build();
359 + linkService.addLink(link);
329 controller.processClientMessage(PccId.pccId(IpAddress.valueOf("1.1.1.1")), message); 360 controller.processClientMessage(PccId.pccId(IpAddress.valueOf("1.1.1.1")), message);
330 361
331 assertThat(registry.tunnelIdCounter, is((long) 1)); 362 assertThat(registry.tunnelIdCounter, is((long) 1));
...@@ -444,6 +475,14 @@ public class PcepTunnelAddedTest { ...@@ -444,6 +475,14 @@ public class PcepTunnelAddedTest {
444 controller.getClient(pccId).setLspDbSyncStatus(SYNCED); 475 controller.getClient(pccId).setLspDbSyncStatus(SYNCED);
445 controller.getClient(pccId).setCapability(new ClientCapability(true, true, true, true, true)); 476 controller.getClient(pccId).setCapability(new ClientCapability(true, true, true, true, true));
446 477
478 + Link link = DefaultLink.builder()
479 + .src(new ConnectPoint(device.id(), PortNumber.portNumber(16843009)))
480 + .dst(new ConnectPoint(device.id(), PortNumber.portNumber(84215045)))
481 + .state(ACTIVE)
482 + .type(Link.Type.DIRECT)
483 + .providerId(ProviderId.NONE)
484 + .build();
485 + linkService.addLink(link);
447 PcepClientAdapter pc = new PcepClientAdapter(); 486 PcepClientAdapter pc = new PcepClientAdapter();
448 pc.init(pccId, PcepVersion.PCEP_1); 487 pc.init(pccId, PcepVersion.PCEP_1);
449 controller.getClient(pccId).setLspAndDelegationInfo(new LspKey(1, (short) 1), true); 488 controller.getClient(pccId).setLspAndDelegationInfo(new LspKey(1, (short) 1), true);
...@@ -505,6 +544,14 @@ public class PcepTunnelAddedTest { ...@@ -505,6 +544,14 @@ public class PcepTunnelAddedTest {
505 deviceService.addDevice(device); 544 deviceService.addDevice(device);
506 controller.getClient(PccId.pccId(IpAddress.valueOf("1.1.1.1"))).setCapability( 545 controller.getClient(PccId.pccId(IpAddress.valueOf("1.1.1.1"))).setCapability(
507 new ClientCapability(true, true, true, true, true)); 546 new ClientCapability(true, true, true, true, true));
547 + Link link = DefaultLink.builder()
548 + .src(new ConnectPoint(device.id(), PortNumber.portNumber(16843009)))
549 + .dst(new ConnectPoint(device.id(), PortNumber.portNumber(84215045)))
550 + .state(ACTIVE)
551 + .type(Link.Type.DIRECT)
552 + .providerId(ProviderId.NONE)
553 + .build();
554 + linkService.addLink(link);
508 controller.processClientMessage(PccId.pccId(IpAddress.valueOf("1.1.1.1")), message); 555 controller.processClientMessage(PccId.pccId(IpAddress.valueOf("1.1.1.1")), message);
509 assertThat(tunnelService.tunnelIdAsKeyStore.values().iterator().next().annotations().value(DELEGATE), 556 assertThat(tunnelService.tunnelIdAsKeyStore.values().iterator().next().annotations().value(DELEGATE),
510 is("false")); 557 is("false"));
...@@ -624,6 +671,7 @@ public class PcepTunnelAddedTest { ...@@ -624,6 +671,7 @@ public class PcepTunnelAddedTest {
624 tunnelProvider.tunnelAdminService = null; 671 tunnelProvider.tunnelAdminService = null;
625 tunnelProvider.deviceService = null; 672 tunnelProvider.deviceService = null;
626 tunnelProvider.mastershipService = null; 673 tunnelProvider.mastershipService = null;
674 + tunnelProvider.linkService = null;
627 tunnelProvider.service = null; 675 tunnelProvider.service = null;
628 } 676 }
629 } 677 }
......