Priyanka B

[ONOS-4986] [ONOS-4985] Json defect fix

Change-Id: I87392a93236b608934f55511ed11faec39145570
......@@ -80,7 +80,8 @@ public class PceQueryPathCommand extends AbstractShellCommand {
"constraints: \n" +
" cost : %s \n" +
" bandwidth : %s",
tunnel.tunnelId().id(), tunnel.src().toString(), tunnel.dst().toString(),
tunnel.tunnelId().id(), tunnel.path().src().deviceId().toString(),
tunnel.path().dst().deviceId().toString(),
tunnel.type().name(), tunnel.tunnelName(), tunnel.annotations().value(COST_TYPE),
tunnel.annotations().value(AnnotationKeys.BANDWIDTH));
}
......
......@@ -162,13 +162,14 @@ public final class DefaultPcePath implements PcePath {
@Override
public String toString() {
return toStringHelper(this)
.omitNullValues()
.add("id", id())
.add("source", source)
.add("destination", destination)
.add("lsptype", lspType)
.add("name", name)
.add("costConstraint", costConstraint.toString())
.add("bandwidthConstraint", bandwidthConstraint.toString())
.add("costConstraint", costConstraint)
.add("bandwidthConstraint", bandwidthConstraint)
.toString();
}
......@@ -241,8 +242,8 @@ public final class DefaultPcePath implements PcePath {
@Override
public Builder of(Tunnel tunnel) {
this.id = TunnelId.valueOf(tunnel.tunnelId().id());
this.source = tunnel.src().toString();
this.destination = tunnel.dst().toString();
this.source = tunnel.path().src().deviceId().toString();
this.destination = tunnel.path().dst().deviceId().toString();
this.name = tunnel.tunnelName().toString();
// LSP type
String lspType = tunnel.annotations().value(PcepAnnotationKeys.LSP_SIG_TYPE);
......
......@@ -525,6 +525,11 @@ public class PceManager implements PceService {
constraints.add(CapabilityConstraint.of(CapabilityType.valueOf(lspSigType)));
if (costConstraint != null) {
constraints.add(costConstraint);
} else {
//Take cost constraint from old tunnel if it is not specified in update flow
costType = tunnel.annotations().value(COST_TYPE);
costConstraint = CostConstraint.of(CostConstraint.Type.valueOf(costType));
constraints.add(costConstraint);
}
computedPathSet = computePath(links.get(0).src().deviceId(), links.get(links.size() - 1).dst().deviceId(),
......@@ -844,6 +849,10 @@ public class PceManager implements PceService {
return;
}
if (pceStore.getTunnelInfo(tunnel.tunnelId()) == null) {
//If bandwidth for old tunnel is not allocated i,e 0 then no need to release
return;
}
resourceService.release(pceStore.getTunnelInfo(tunnel.tunnelId()).tunnelConsumerId());
return;
......@@ -1210,7 +1219,7 @@ public class PceManager implements PceService {
localLspIdFreeList.add(Short.valueOf(tunnel.annotations().value(LOCAL_LSP_ID)));
}
// If not zero bandwidth, and delegated (initiated LSPs will also be delegated).
if (Float.parseFloat(tunnel.annotations().value(BANDWIDTH)) != 0
if (bwConstraintValue != 0
&& mastershipService.getLocalRole(tunnel.path().src().deviceId()) == MastershipRole.MASTER) {
releaseBandwidth(tunnel);
}
......
......@@ -98,6 +98,17 @@ public class DistributedPceStore implements PceStore {
// List of PCC LSR ids whose BGP device information was not available to perform
// label db sync.
private HashSet<DeviceId> pendinglabelDbSyncPccMap = new HashSet();
private static final Serializer SERIALIZER = Serializer
.using(new KryoNamespace.Builder().register(KryoNamespaces.API)
.register(PcePathInfo.class)
.register(CostConstraint.class)
.register(CostConstraint.Type.class)
.register(BandwidthConstraint.class)
.register(SharedBandwidthConstraint.class)
.register(CapabilityConstraint.class)
.register(CapabilityConstraint.CapabilityType.class)
.register(LspType.class)
.build());
@Activate
protected void activate() {
......@@ -136,19 +147,7 @@ public class DistributedPceStore implements PceStore {
failedPathSet = storageService.<PcePathInfo>setBuilder()
.withName("failed-path-info")
.withSerializer(Serializer.using(
new KryoNamespace.Builder()
.register(KryoNamespaces.API)
.register(PcePathInfo.class,
CostConstraint.class,
CostConstraint.Type.class,
BandwidthConstraint.class,
SharedBandwidthConstraint.class,
CapabilityConstraint.class,
CapabilityConstraint.CapabilityType.class,
LspType.class)
.build()))
.withSerializer(SERIALIZER)
.build()
.asDistributedSet();
......
......@@ -618,7 +618,10 @@ public class PceManagerTest {
build4RouterTopo(false, true, true, true, 100);
// Setup tunnel.
boolean result = pceManager.setupPath(D1.deviceId(), D2.deviceId(), "T123", null, WITH_SIGNALLING);
List<Constraint> constraints = new LinkedList<Constraint>();
CostConstraint costConstraint = new CostConstraint(TE_COST);
constraints.add(costConstraint);
boolean result = pceManager.setupPath(D1.deviceId(), D2.deviceId(), "T123", constraints, WITH_SIGNALLING);
assertThat(result, is(true));
Collection<Tunnel> tunnels = (Collection<Tunnel>) pceManager.queryAllPath();
......
......@@ -21,6 +21,8 @@ import org.onosproject.codec.CodecContext;
import org.onosproject.codec.JsonCodec;
import org.onosproject.pce.pceservice.PcePath;
import org.onosproject.pce.pceservice.DefaultPcePath;
import org.onosproject.net.intent.constraint.BandwidthConstraint;
import org.onosproject.pce.pceservice.constraint.CostConstraint;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -70,6 +72,11 @@ public final class PcePathCodec extends JsonCodec<PcePath> {
jNode = json.get(LSP_TYPE);
if (jNode != null) {
String lspType = jNode.asText();
//Validating LSP type
int type = Integer.parseInt(lspType);
if ((type < 0) || (type > 2)) {
return null;
}
resultBuilder.lspType(lspType);
}
......@@ -87,6 +94,11 @@ public final class PcePathCodec extends JsonCodec<PcePath> {
jNode = constraintJNode.get(COST);
if (jNode != null) {
String cost = jNode.asText();
//Validating Cost type
int costType = Integer.parseInt(cost);
if ((costType < 1) || (costType > 2)) {
return null;
}
resultBuilder.costConstraint(cost);
}
......@@ -94,6 +106,10 @@ public final class PcePathCodec extends JsonCodec<PcePath> {
jNode = constraintJNode.get(BANDWIDTH);
if (jNode != null) {
String bandwidth = jNode.asText();
double bw = Double.parseDouble(bandwidth);
if (bw < 0) {
return null;
}
resultBuilder.bandwidthConstraint(bandwidth);
}
}
......@@ -114,8 +130,8 @@ public final class PcePathCodec extends JsonCodec<PcePath> {
ObjectNode constraintNode = context.mapper()
.createObjectNode()
.put(COST, path.costConstraint().toString())
.put(BANDWIDTH, path.bandwidthConstraint().toString());
.put(COST, ((CostConstraint) path.costConstraint()).type().type())
.put(BANDWIDTH, ((BandwidthConstraint) path.bandwidthConstraint()).bandwidth().bps());
result.set(CONSTRAINT, constraintNode);
return result;
......
......@@ -122,6 +122,10 @@ public class PcePathWebResource extends AbstractWebResource {
JsonNode port = jsonTree.get("path");
TunnelService tunnelService = get(TunnelService.class);
PcePath path = codec(PcePath.class).decode((ObjectNode) port, this);
if (path == null) {
return Response.status(OK).entity(PCE_SETUP_PATH_FAILED).build();
}
//Validating tunnel name, duplicated tunnel names not allowed
Collection<Tunnel> existingTunnels = tunnelService.queryTunnel(Tunnel.Type.MPLS);
if (existingTunnels != null) {
......