Priyanka B

[ONOS] cherry picked from 1.6, bandwidth, CR and resilency fix

Change-Id: Ifd7bf886d2725db1f5e2f7a1eac739d9a446f868
......@@ -114,7 +114,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;
......@@ -1178,10 +1177,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:
......
......@@ -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);
}
......@@ -152,7 +150,16 @@ public class PcepBandwidthObjectVer1 implements PcepBandwidthObject {
throw new PcepParseException("Failed to write bandwidth object header. Index " + objLenIndex);
}
cb.writeInt(Float.floatToIntBits(iBandwidth));
//Convert to bytes per second
float bwBytes = iBandwidth / 8.0f;
//Bytes/sec to IEEE floating format
int bandwidth = Float.floatToIntBits(bwBytes);
cb.writeByte(bandwidth >>> 24);
cb.writeByte(bandwidth >> 16 & 0xff);
cb.writeByte(bandwidth >> 8 & 0xff);
cb.writeByte(bandwidth & 0xff);
short hLength = (short) (cb.writerIndex() - objStartIndex);
cb.setShort(objLenIndex, hLength);
//will be helpful during print().
......
......@@ -491,6 +491,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 bits/second , convert to MBPS to store in network config service
maxReservableBw = maxReservableBw / 1000000;
break;
default: // do nothing
}
......
......@@ -1005,7 +1005,8 @@ public class BgpTopologyProviderTest {
linkStateAttr.add(tlv);
tlv = BgpLinkAttrTeDefaultMetric.of(20);
linkStateAttr.add(tlv);
tlv = BgpLinkAttrMaxLinkBandwidth.of(70, LinkStateAttributes.ATTR_LINK_MAX_RES_BANDWIDTH);
tlv = BgpLinkAttrMaxLinkBandwidth.of((float) 70 * 1_000_000L,
LinkStateAttributes.ATTR_LINK_MAX_RES_BANDWIDTH);
linkStateAttr.add(tlv);
linkPathAttributes.add(new LinkStateAttributes(linkStateAttr));
details.setPathAttribute(linkPathAttributes);
......
......@@ -89,11 +89,14 @@ import org.onosproject.pcepio.types.PcepValueType;
import org.onosproject.pcepio.types.StatefulIPv4LspIdentifiersTlv;
import org.onosproject.pcepio.types.SymbolicPathNameTlv;
import org.onosproject.pcep.controller.LspType;
import org.onosproject.pcepio.protocol.PcepAttribute;
import org.onosproject.pcepio.protocol.PcepBandwidthObject;
import org.onosproject.pcep.controller.SrpIdGenerators;
import org.onosproject.pcep.controller.PcepAnnotationKeys;
import org.osgi.service.component.ComponentContext;
import org.slf4j.Logger;
import static org.onosproject.pcep.controller.PcepAnnotationKeys.BANDWIDTH;
import static org.onosproject.pcep.controller.PcepAnnotationKeys.DELEGATE;
import static org.onosproject.pcep.controller.PcepAnnotationKeys.LSP_SIG_TYPE;
import static org.onosproject.pcep.controller.PcepAnnotationKeys.PCE_INIT;
......@@ -530,8 +533,23 @@ public class BgpcepFlowRuleProvider extends AbstractProvider
.setSubObjects(subObjects)
.build();
float iBandwidth = 0;
if (tunnel.annotations().value(BANDWIDTH) != null) {
//iBandwidth = Float.floatToIntBits(Float.parseFloat(tunnel.annotations().value(BANDWIDTH)));
iBandwidth = Float.parseFloat(tunnel.annotations().value(BANDWIDTH));
}
// build bandwidth object
PcepBandwidthObject bandwidthObject = pc.factory().buildBandwidthObject()
.setBandwidth(iBandwidth)
.build();
// build pcep attribute
PcepAttribute pcepAttribute = pc.factory().buildPcepAttribute()
.setBandwidthObject(bandwidthObject)
.build();
PcepMsgPath msgPath = pc.factory().buildPcepMsgPath()
.setEroObject(eroObj)
.setPcepAttribute(pcepAttribute)
.build();
PcepUpdateRequest updateReq = pc.factory().buildPcepUpdateRequest()
......
......@@ -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>();
......@@ -609,6 +613,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());
......@@ -1012,9 +1017,9 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid
//build ERO object
PcepEroObject eroobj = pc.factory().buildEroObject().setSubObjects(llSubObjects).build();
int iBandwidth = DEFAULT_BANDWIDTH_VALUE;
float iBandwidth = DEFAULT_BANDWIDTH_VALUE;
if (tunnel.annotations().value(BANDWIDTH) != null) {
iBandwidth = Float.floatToIntBits(Float.parseFloat(tunnel.annotations().value(BANDWIDTH)));
iBandwidth = Float.valueOf(tunnel.annotations().value(BANDWIDTH));
}
// build bandwidth object
PcepBandwidthObject bandwidthObject = pc.factory().buildBandwidthObject().setBandwidth(iBandwidth).build();
......@@ -1680,8 +1685,8 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid
bandwidth, lspType,
tunnel.annotations().value(COST_TYPE));
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);
......@@ -1743,12 +1748,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));
isSrcSet = true;
} 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()))) {
src = l.src();
isSrcSet = true;
break;
} else if (l.dst().port().equals(PortNumber.portNumber(ipv4SubObj.getIpAddress()))) {
src = l.dst();
isSrcSet = true;
break;
}
}
} else {
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() == 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;
}
}
......