Priyanka B

[ONOS] Bandwidth issue fix

Change-Id: I72007a2e211b807906d58172d3c58b07f6613a55
......@@ -152,7 +152,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().
......
......@@ -492,6 +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;
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) 8.75 * 1_000_000L,
LinkStateAttributes.ATTR_LINK_MAX_RES_BANDWIDTH);
linkStateAttr.add(tlv);
linkPathAttributes.add(new LinkStateAttributes(linkStateAttr));
details.setPathAttribute(linkPathAttributes);
......
......@@ -1010,9 +1010,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();
......