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;
import static org.onosproject.incubator.net.tunnel.Tunnel.State.INIT;
import static org.onosproject.incubator.net.tunnel.Tunnel.State.ESTABLISHED;
import static org.onosproject.incubator.net.tunnel.Tunnel.State.UNSTABLE;
import static org.onosproject.incubator.net.tunnel.Tunnel.State.FAILED;
import static org.onosproject.pce.pceservice.LspType.WITH_SIGNALLING;
import static org.onosproject.pce.pceservice.LspType.SR_WITHOUT_SIGNALLING;
import static org.onosproject.pce.pceservice.LspType.WITHOUT_SIGNALLING_AND_WITHOUT_SR;
......@@ -1185,10 +1184,6 @@ public class PceManager implements PceService {
tunnel.tunnelName().value(), constraints, lspType));
}
if (tunnel.state() == FAILED) {
// Check whether this ONOS instance is master, if yes, recompute and send update.
checkForMasterAndUpdateTunnel(tunnel.path().src().deviceId(), tunnel);
}
break;
case TUNNEL_REMOVED:
......
......@@ -664,6 +664,11 @@ public class PceWebTopovMessageHandler extends UiMessageHandler {
sendMessage(TopoJson.highlightsMessage(highlights));
return;
}
if (!tunnel.state().equals(Tunnel.State.ACTIVE)) {
log.debug("Tunnel state is not active");
sendMessage(TopoJson.highlightsMessage(highlights));
return;
}
Link firstLink = tunnel.path().links().get(0);
if (firstLink != null) {
if (firstLink.src() != null) {
......
......@@ -107,8 +107,6 @@ public final class BgpLinkAttrMaxLinkBandwidth implements BgpValueType {
* @return normal float
*/
static float ieeeToFloatRead(int iVal) {
iVal = (((iVal & 0xFF) << 24) | ((iVal & 0xFF00) << 8)
| ((iVal & 0xFF0000) >> 8) | ((iVal >> 24) & 0xFF));
return Float.intBitsToFloat(iVal);
}
......
......@@ -115,8 +115,6 @@ public class BgpLinkAttrUnRsrvdLinkBandwidth implements BgpValueType {
* @return normal float
*/
static float ieeeToFloatRead(int iVal) {
iVal = (((iVal & 0xFF) << 24) | ((iVal & 0xFF00) << 8)
| ((iVal & 0xFF0000) >> 8) | ((iVal >> 24) & 0xFF));
return Float.intBitsToFloat(iVal);
}
......
......@@ -135,8 +135,6 @@ public class PcepBandwidthObjectVer1 implements PcepBandwidthObject {
* @return normal float
*/
public static float ieeeToFloatRead(int iVal) {
iVal = (((iVal & 0xFF) << 24) | ((iVal & 0xFF00) << 8)
| ((iVal & 0xFF0000) >> 8) | ((iVal >> 24) & 0xFF));
return Float.intBitsToFloat(iVal);
}
......
......@@ -492,8 +492,8 @@ public class BgpTopologyProvider extends AbstractProvider implements DeviceProvi
switch (tlv.getType()) {
case LinkStateAttributes.ATTR_LINK_MAX_RES_BANDWIDTH:
maxReservableBw = ((BgpLinkAttrMaxLinkBandwidth) tlv).linkAttrMaxLinkBandwidth();
//will get in bytes/second , convert to MBPS to store in network config service
maxReservableBw = maxReservableBw * 8 / 1000000;
//will get in bits/second , convert to MBPS to store in network config service
maxReservableBw = maxReservableBw / 1000000;
break;
default: // do nothing
}
......
......@@ -1005,7 +1005,7 @@ public class BgpTopologyProviderTest {
linkStateAttr.add(tlv);
tlv = BgpLinkAttrTeDefaultMetric.of(20);
linkStateAttr.add(tlv);
tlv = BgpLinkAttrMaxLinkBandwidth.of((float) 8.75 * 1_000_000L,
tlv = BgpLinkAttrMaxLinkBandwidth.of((float) 70 * 1_000_000L,
LinkStateAttributes.ATTR_LINK_MAX_RES_BANDWIDTH);
linkStateAttr.add(tlv);
linkPathAttributes.add(new LinkStateAttributes(linkStateAttr));
......
......@@ -66,6 +66,7 @@ import org.onosproject.net.Path;
import org.onosproject.net.PortNumber;
import org.onosproject.net.SparseAnnotations;
import org.onosproject.net.device.DeviceService;
import org.onosproject.net.link.LinkService;
import org.onosproject.net.provider.AbstractProvider;
import org.onosproject.net.provider.ProviderId;
import org.onosproject.pcep.api.PcepController;
......@@ -213,6 +214,9 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected DeviceService deviceService;
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected LinkService linkService;
TunnelProviderService service;
HashMap<String, TunnelId> tunnelMap = new HashMap<String, TunnelId>();
......@@ -611,6 +615,7 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid
if (tunnel.type() == MPLS) {
pcepTunnelApiMapper.removeFromCoreTunnelRequestQueue(tunnel.id());
service.tunnelRemoved(tunnel);
return;
}
Tunnel tunnelOld = tunnelQueryById(tunnel.id());
......@@ -1681,8 +1686,8 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid
if (lspObj.getDFlag()) {
annotations = getAnnotations(lspObj, ipv4LspIdenTlv, bandwidth, lspType, costType);
td = new DefaultTunnelDescription(null, tunnelEndPointSrc, tunnelEndPointDst, MPLS, new DefaultGroupId(
0), providerId, TunnelName.tunnelName(new String(pathNameTlv.getValue())), path, labelStack,
annotations);
0), providerId, TunnelName.tunnelName(new String(pathNameTlv.getValue())),
tunnel.path(), labelStack, annotations);
tunnelUpdateInDelegatedCase(pccId, annotations, td, providerId);
}
removeOrUpdatetunnel(tunnel, pccId, lspObj, providerId, tunnelState);
......@@ -1744,12 +1749,29 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid
IPv4SubObject ipv4SubObj = (IPv4SubObject) subObj;
if (!isSrcSet) {
IpAddress srcIp = IpAddress.valueOf(ipv4SubObj.getIpAddress());
src = new ConnectPoint(IpElementId.ipElement(srcIp), PortNumber.portNumber(0));
Iterable<Link> links = linkService.getActiveLinks();
for (Link l : links) {
if (l.src().port().equals(PortNumber.portNumber(ipv4SubObj.getIpAddress()))) {
src = l.src();
isSrcSet = true;
break;
} else if (l.dst().port().equals(PortNumber.portNumber(ipv4SubObj.getIpAddress()))) {
src = l.dst();
isSrcSet = true;
break;
}
}
} else {
IpAddress dstIp = IpAddress.valueOf(ipv4SubObj.getIpAddress());
dst = new ConnectPoint(IpElementId.ipElement(dstIp), PortNumber.portNumber(0));
Iterable<Link> links = linkService.getActiveLinks();
for (Link l : links) {
if (l.src().port().equals(PortNumber.portNumber(ipv4SubObj.getIpAddress()))) {
dst = l.src();
break;
} else if (l.dst().port().equals(PortNumber.portNumber(ipv4SubObj.getIpAddress()))) {
dst = l.dst();
break;
}
}
Link link = DefaultLink.builder()
.providerId(providerId)
.src(src)
......
......@@ -28,6 +28,7 @@ import static org.onosproject.pcep.controller.PcepAnnotationKeys.DELEGATE;
import static org.onosproject.pcep.controller.LspType.WITHOUT_SIGNALLING_AND_WITHOUT_SR;
import static org.onosproject.pcep.controller.PcepSyncStatus.SYNCED;
import static org.onosproject.net.Device.Type.ROUTER;
import static org.onosproject.net.Link.State.ACTIVE;
import static org.onosproject.net.MastershipRole.MASTER;
import java.io.IOException;
......@@ -62,15 +63,20 @@ import org.onosproject.incubator.net.tunnel.TunnelProviderService;
import org.onosproject.incubator.net.tunnel.Tunnel.State;
import org.onosproject.mastership.MastershipServiceAdapter;
import org.onosproject.net.AnnotationKeys;
import org.onosproject.net.ConnectPoint;
import org.onosproject.net.DefaultAnnotations;
import org.onosproject.net.DefaultDevice;
import org.onosproject.net.DefaultLink;
import org.onosproject.net.Device;
import org.onosproject.net.DeviceId;
import org.onosproject.net.ElementId;
import org.onosproject.net.Link;
import org.onosproject.net.MastershipRole;
import org.onosproject.net.Path;
import org.onosproject.net.PortNumber;
import org.onosproject.net.SparseAnnotations;
import org.onosproject.net.device.DeviceServiceAdapter;
import org.onosproject.net.link.LinkServiceAdapter;
import org.onosproject.net.provider.ProviderId;
import org.onosproject.pcepio.exceptions.PcepOutOfBoundMessageException;
import org.onosproject.pcepio.exceptions.PcepParseException;
......@@ -82,6 +88,7 @@ import org.onosproject.pcep.controller.ClientCapability;
import org.onosproject.pcep.controller.LspKey;
import org.onosproject.pcep.controller.PccId;
import com.google.common.collect.FluentIterable;
import com.google.common.collect.ImmutableSet;
/**
......@@ -99,8 +106,23 @@ public class PcepTunnelAddedTest {
private final MockTunnelServiceAdapter tunnelService = new MockTunnelServiceAdapter();
public final MockDeviceService deviceService = new MockDeviceService();
private final MockMasterShipService masterShipService = new MockMasterShipService();
private final MockLinkService linkService = new MockLinkService();
private final MockTunnelAdminService tunnelAdminService = new MockTunnelAdminService();
private class MockLinkService extends LinkServiceAdapter {
LinkedList<Link> links = new LinkedList<>();
void addLink(Link link) {
links.add(link);
}
@Override
public Iterable<Link> getActiveLinks() {
return FluentIterable.from(links)
.filter(input -> input.state() == Link.State.ACTIVE);
}
}
private class MockTunnelAdminService implements TunnelAdminService {
@Override
......@@ -275,6 +297,7 @@ public class PcepTunnelAddedTest {
tunnelProvider.tunnelService = tunnelService;
tunnelProvider.tunnelAdminService = tunnelAdminService;
tunnelProvider.service = registry.register(tunnelProvider);
tunnelProvider.linkService = linkService;
tunnelProvider.activate();
}
......@@ -326,6 +349,14 @@ public class PcepTunnelAddedTest {
controller.getClient(PccId.pccId(IpAddress.valueOf("1.1.1.1"))).setCapability(
new ClientCapability(true, true, true, true, true));
masterShipService.setMaster(true);
Link link = DefaultLink.builder()
.src(new ConnectPoint(device.id(), PortNumber.portNumber(16843009)))
.dst(new ConnectPoint(device.id(), PortNumber.portNumber(84215045)))
.state(ACTIVE)
.type(Link.Type.DIRECT)
.providerId(ProviderId.NONE)
.build();
linkService.addLink(link);
controller.processClientMessage(PccId.pccId(IpAddress.valueOf("1.1.1.1")), message);
assertThat(registry.tunnelIdCounter, is((long) 1));
......@@ -444,6 +475,14 @@ public class PcepTunnelAddedTest {
controller.getClient(pccId).setLspDbSyncStatus(SYNCED);
controller.getClient(pccId).setCapability(new ClientCapability(true, true, true, true, true));
Link link = DefaultLink.builder()
.src(new ConnectPoint(device.id(), PortNumber.portNumber(16843009)))
.dst(new ConnectPoint(device.id(), PortNumber.portNumber(84215045)))
.state(ACTIVE)
.type(Link.Type.DIRECT)
.providerId(ProviderId.NONE)
.build();
linkService.addLink(link);
PcepClientAdapter pc = new PcepClientAdapter();
pc.init(pccId, PcepVersion.PCEP_1);
controller.getClient(pccId).setLspAndDelegationInfo(new LspKey(1, (short) 1), true);
......@@ -505,6 +544,14 @@ public class PcepTunnelAddedTest {
deviceService.addDevice(device);
controller.getClient(PccId.pccId(IpAddress.valueOf("1.1.1.1"))).setCapability(
new ClientCapability(true, true, true, true, true));
Link link = DefaultLink.builder()
.src(new ConnectPoint(device.id(), PortNumber.portNumber(16843009)))
.dst(new ConnectPoint(device.id(), PortNumber.portNumber(84215045)))
.state(ACTIVE)
.type(Link.Type.DIRECT)
.providerId(ProviderId.NONE)
.build();
linkService.addLink(link);
controller.processClientMessage(PccId.pccId(IpAddress.valueOf("1.1.1.1")), message);
assertThat(tunnelService.tunnelIdAsKeyStore.values().iterator().next().annotations().value(DELEGATE),
is("false"));
......@@ -624,6 +671,7 @@ public class PcepTunnelAddedTest {
tunnelProvider.tunnelAdminService = null;
tunnelProvider.deviceService = null;
tunnelProvider.mastershipService = null;
tunnelProvider.linkService = null;
tunnelProvider.service = null;
}
}
......