[ONOS-4986] [ONOS-4985] Json defect fix
Change-Id: I87392a93236b608934f55511ed11faec39145570
Showing
7 changed files
with
55 additions
and
22 deletions
... | @@ -80,7 +80,8 @@ public class PceQueryPathCommand extends AbstractShellCommand { | ... | @@ -80,7 +80,8 @@ public class PceQueryPathCommand extends AbstractShellCommand { |
80 | "constraints: \n" + | 80 | "constraints: \n" + |
81 | " cost : %s \n" + | 81 | " cost : %s \n" + |
82 | " bandwidth : %s", | 82 | " bandwidth : %s", |
83 | - tunnel.tunnelId().id(), tunnel.src().toString(), tunnel.dst().toString(), | 83 | + tunnel.tunnelId().id(), tunnel.path().src().deviceId().toString(), |
84 | + tunnel.path().dst().deviceId().toString(), | ||
84 | tunnel.type().name(), tunnel.tunnelName(), tunnel.annotations().value(COST_TYPE), | 85 | tunnel.type().name(), tunnel.tunnelName(), tunnel.annotations().value(COST_TYPE), |
85 | tunnel.annotations().value(AnnotationKeys.BANDWIDTH)); | 86 | tunnel.annotations().value(AnnotationKeys.BANDWIDTH)); |
86 | } | 87 | } | ... | ... |
... | @@ -162,13 +162,14 @@ public final class DefaultPcePath implements PcePath { | ... | @@ -162,13 +162,14 @@ public final class DefaultPcePath implements PcePath { |
162 | @Override | 162 | @Override |
163 | public String toString() { | 163 | public String toString() { |
164 | return toStringHelper(this) | 164 | return toStringHelper(this) |
165 | + .omitNullValues() | ||
165 | .add("id", id()) | 166 | .add("id", id()) |
166 | .add("source", source) | 167 | .add("source", source) |
167 | .add("destination", destination) | 168 | .add("destination", destination) |
168 | .add("lsptype", lspType) | 169 | .add("lsptype", lspType) |
169 | .add("name", name) | 170 | .add("name", name) |
170 | - .add("costConstraint", costConstraint.toString()) | 171 | + .add("costConstraint", costConstraint) |
171 | - .add("bandwidthConstraint", bandwidthConstraint.toString()) | 172 | + .add("bandwidthConstraint", bandwidthConstraint) |
172 | .toString(); | 173 | .toString(); |
173 | } | 174 | } |
174 | 175 | ||
... | @@ -241,8 +242,8 @@ public final class DefaultPcePath implements PcePath { | ... | @@ -241,8 +242,8 @@ public final class DefaultPcePath implements PcePath { |
241 | @Override | 242 | @Override |
242 | public Builder of(Tunnel tunnel) { | 243 | public Builder of(Tunnel tunnel) { |
243 | this.id = TunnelId.valueOf(tunnel.tunnelId().id()); | 244 | this.id = TunnelId.valueOf(tunnel.tunnelId().id()); |
244 | - this.source = tunnel.src().toString(); | 245 | + this.source = tunnel.path().src().deviceId().toString(); |
245 | - this.destination = tunnel.dst().toString(); | 246 | + this.destination = tunnel.path().dst().deviceId().toString(); |
246 | this.name = tunnel.tunnelName().toString(); | 247 | this.name = tunnel.tunnelName().toString(); |
247 | // LSP type | 248 | // LSP type |
248 | String lspType = tunnel.annotations().value(PcepAnnotationKeys.LSP_SIG_TYPE); | 249 | String lspType = tunnel.annotations().value(PcepAnnotationKeys.LSP_SIG_TYPE); | ... | ... |
... | @@ -525,6 +525,11 @@ public class PceManager implements PceService { | ... | @@ -525,6 +525,11 @@ public class PceManager implements PceService { |
525 | constraints.add(CapabilityConstraint.of(CapabilityType.valueOf(lspSigType))); | 525 | constraints.add(CapabilityConstraint.of(CapabilityType.valueOf(lspSigType))); |
526 | if (costConstraint != null) { | 526 | if (costConstraint != null) { |
527 | constraints.add(costConstraint); | 527 | constraints.add(costConstraint); |
528 | + } else { | ||
529 | + //Take cost constraint from old tunnel if it is not specified in update flow | ||
530 | + costType = tunnel.annotations().value(COST_TYPE); | ||
531 | + costConstraint = CostConstraint.of(CostConstraint.Type.valueOf(costType)); | ||
532 | + constraints.add(costConstraint); | ||
528 | } | 533 | } |
529 | 534 | ||
530 | computedPathSet = computePath(links.get(0).src().deviceId(), links.get(links.size() - 1).dst().deviceId(), | 535 | computedPathSet = computePath(links.get(0).src().deviceId(), links.get(links.size() - 1).dst().deviceId(), |
... | @@ -844,6 +849,10 @@ public class PceManager implements PceService { | ... | @@ -844,6 +849,10 @@ public class PceManager implements PceService { |
844 | return; | 849 | return; |
845 | } | 850 | } |
846 | 851 | ||
852 | + if (pceStore.getTunnelInfo(tunnel.tunnelId()) == null) { | ||
853 | + //If bandwidth for old tunnel is not allocated i,e 0 then no need to release | ||
854 | + return; | ||
855 | + } | ||
847 | resourceService.release(pceStore.getTunnelInfo(tunnel.tunnelId()).tunnelConsumerId()); | 856 | resourceService.release(pceStore.getTunnelInfo(tunnel.tunnelId()).tunnelConsumerId()); |
848 | return; | 857 | return; |
849 | 858 | ||
... | @@ -1210,7 +1219,7 @@ public class PceManager implements PceService { | ... | @@ -1210,7 +1219,7 @@ public class PceManager implements PceService { |
1210 | localLspIdFreeList.add(Short.valueOf(tunnel.annotations().value(LOCAL_LSP_ID))); | 1219 | localLspIdFreeList.add(Short.valueOf(tunnel.annotations().value(LOCAL_LSP_ID))); |
1211 | } | 1220 | } |
1212 | // If not zero bandwidth, and delegated (initiated LSPs will also be delegated). | 1221 | // If not zero bandwidth, and delegated (initiated LSPs will also be delegated). |
1213 | - if (Float.parseFloat(tunnel.annotations().value(BANDWIDTH)) != 0 | 1222 | + if (bwConstraintValue != 0 |
1214 | && mastershipService.getLocalRole(tunnel.path().src().deviceId()) == MastershipRole.MASTER) { | 1223 | && mastershipService.getLocalRole(tunnel.path().src().deviceId()) == MastershipRole.MASTER) { |
1215 | releaseBandwidth(tunnel); | 1224 | releaseBandwidth(tunnel); |
1216 | } | 1225 | } | ... | ... |
... | @@ -98,6 +98,17 @@ public class DistributedPceStore implements PceStore { | ... | @@ -98,6 +98,17 @@ public class DistributedPceStore implements PceStore { |
98 | // List of PCC LSR ids whose BGP device information was not available to perform | 98 | // List of PCC LSR ids whose BGP device information was not available to perform |
99 | // label db sync. | 99 | // label db sync. |
100 | private HashSet<DeviceId> pendinglabelDbSyncPccMap = new HashSet(); | 100 | private HashSet<DeviceId> pendinglabelDbSyncPccMap = new HashSet(); |
101 | + private static final Serializer SERIALIZER = Serializer | ||
102 | + .using(new KryoNamespace.Builder().register(KryoNamespaces.API) | ||
103 | + .register(PcePathInfo.class) | ||
104 | + .register(CostConstraint.class) | ||
105 | + .register(CostConstraint.Type.class) | ||
106 | + .register(BandwidthConstraint.class) | ||
107 | + .register(SharedBandwidthConstraint.class) | ||
108 | + .register(CapabilityConstraint.class) | ||
109 | + .register(CapabilityConstraint.CapabilityType.class) | ||
110 | + .register(LspType.class) | ||
111 | + .build()); | ||
101 | 112 | ||
102 | @Activate | 113 | @Activate |
103 | protected void activate() { | 114 | protected void activate() { |
... | @@ -136,19 +147,7 @@ public class DistributedPceStore implements PceStore { | ... | @@ -136,19 +147,7 @@ public class DistributedPceStore implements PceStore { |
136 | 147 | ||
137 | failedPathSet = storageService.<PcePathInfo>setBuilder() | 148 | failedPathSet = storageService.<PcePathInfo>setBuilder() |
138 | .withName("failed-path-info") | 149 | .withName("failed-path-info") |
139 | - .withSerializer(Serializer.using( | 150 | + .withSerializer(SERIALIZER) |
140 | - new KryoNamespace.Builder() | ||
141 | - .register(KryoNamespaces.API) | ||
142 | - .register(PcePathInfo.class, | ||
143 | - CostConstraint.class, | ||
144 | - CostConstraint.Type.class, | ||
145 | - BandwidthConstraint.class, | ||
146 | - SharedBandwidthConstraint.class, | ||
147 | - CapabilityConstraint.class, | ||
148 | - CapabilityConstraint.CapabilityType.class, | ||
149 | - LspType.class) | ||
150 | - .build())) | ||
151 | - | ||
152 | .build() | 151 | .build() |
153 | .asDistributedSet(); | 152 | .asDistributedSet(); |
154 | 153 | ... | ... |
... | @@ -618,7 +618,10 @@ public class PceManagerTest { | ... | @@ -618,7 +618,10 @@ public class PceManagerTest { |
618 | build4RouterTopo(false, true, true, true, 100); | 618 | build4RouterTopo(false, true, true, true, 100); |
619 | 619 | ||
620 | // Setup tunnel. | 620 | // Setup tunnel. |
621 | - boolean result = pceManager.setupPath(D1.deviceId(), D2.deviceId(), "T123", null, WITH_SIGNALLING); | 621 | + List<Constraint> constraints = new LinkedList<Constraint>(); |
622 | + CostConstraint costConstraint = new CostConstraint(TE_COST); | ||
623 | + constraints.add(costConstraint); | ||
624 | + boolean result = pceManager.setupPath(D1.deviceId(), D2.deviceId(), "T123", constraints, WITH_SIGNALLING); | ||
622 | assertThat(result, is(true)); | 625 | assertThat(result, is(true)); |
623 | 626 | ||
624 | Collection<Tunnel> tunnels = (Collection<Tunnel>) pceManager.queryAllPath(); | 627 | Collection<Tunnel> tunnels = (Collection<Tunnel>) pceManager.queryAllPath(); | ... | ... |
... | @@ -21,6 +21,8 @@ import org.onosproject.codec.CodecContext; | ... | @@ -21,6 +21,8 @@ import org.onosproject.codec.CodecContext; |
21 | import org.onosproject.codec.JsonCodec; | 21 | import org.onosproject.codec.JsonCodec; |
22 | import org.onosproject.pce.pceservice.PcePath; | 22 | import org.onosproject.pce.pceservice.PcePath; |
23 | import org.onosproject.pce.pceservice.DefaultPcePath; | 23 | import org.onosproject.pce.pceservice.DefaultPcePath; |
24 | +import org.onosproject.net.intent.constraint.BandwidthConstraint; | ||
25 | +import org.onosproject.pce.pceservice.constraint.CostConstraint; | ||
24 | import org.slf4j.Logger; | 26 | import org.slf4j.Logger; |
25 | import org.slf4j.LoggerFactory; | 27 | import org.slf4j.LoggerFactory; |
26 | 28 | ||
... | @@ -70,6 +72,11 @@ public final class PcePathCodec extends JsonCodec<PcePath> { | ... | @@ -70,6 +72,11 @@ public final class PcePathCodec extends JsonCodec<PcePath> { |
70 | jNode = json.get(LSP_TYPE); | 72 | jNode = json.get(LSP_TYPE); |
71 | if (jNode != null) { | 73 | if (jNode != null) { |
72 | String lspType = jNode.asText(); | 74 | String lspType = jNode.asText(); |
75 | + //Validating LSP type | ||
76 | + int type = Integer.parseInt(lspType); | ||
77 | + if ((type < 0) || (type > 2)) { | ||
78 | + return null; | ||
79 | + } | ||
73 | resultBuilder.lspType(lspType); | 80 | resultBuilder.lspType(lspType); |
74 | } | 81 | } |
75 | 82 | ||
... | @@ -87,6 +94,11 @@ public final class PcePathCodec extends JsonCodec<PcePath> { | ... | @@ -87,6 +94,11 @@ public final class PcePathCodec extends JsonCodec<PcePath> { |
87 | jNode = constraintJNode.get(COST); | 94 | jNode = constraintJNode.get(COST); |
88 | if (jNode != null) { | 95 | if (jNode != null) { |
89 | String cost = jNode.asText(); | 96 | String cost = jNode.asText(); |
97 | + //Validating Cost type | ||
98 | + int costType = Integer.parseInt(cost); | ||
99 | + if ((costType < 1) || (costType > 2)) { | ||
100 | + return null; | ||
101 | + } | ||
90 | resultBuilder.costConstraint(cost); | 102 | resultBuilder.costConstraint(cost); |
91 | } | 103 | } |
92 | 104 | ||
... | @@ -94,6 +106,10 @@ public final class PcePathCodec extends JsonCodec<PcePath> { | ... | @@ -94,6 +106,10 @@ public final class PcePathCodec extends JsonCodec<PcePath> { |
94 | jNode = constraintJNode.get(BANDWIDTH); | 106 | jNode = constraintJNode.get(BANDWIDTH); |
95 | if (jNode != null) { | 107 | if (jNode != null) { |
96 | String bandwidth = jNode.asText(); | 108 | String bandwidth = jNode.asText(); |
109 | + double bw = Double.parseDouble(bandwidth); | ||
110 | + if (bw < 0) { | ||
111 | + return null; | ||
112 | + } | ||
97 | resultBuilder.bandwidthConstraint(bandwidth); | 113 | resultBuilder.bandwidthConstraint(bandwidth); |
98 | } | 114 | } |
99 | } | 115 | } |
... | @@ -114,8 +130,8 @@ public final class PcePathCodec extends JsonCodec<PcePath> { | ... | @@ -114,8 +130,8 @@ public final class PcePathCodec extends JsonCodec<PcePath> { |
114 | 130 | ||
115 | ObjectNode constraintNode = context.mapper() | 131 | ObjectNode constraintNode = context.mapper() |
116 | .createObjectNode() | 132 | .createObjectNode() |
117 | - .put(COST, path.costConstraint().toString()) | 133 | + .put(COST, ((CostConstraint) path.costConstraint()).type().type()) |
118 | - .put(BANDWIDTH, path.bandwidthConstraint().toString()); | 134 | + .put(BANDWIDTH, ((BandwidthConstraint) path.bandwidthConstraint()).bandwidth().bps()); |
119 | 135 | ||
120 | result.set(CONSTRAINT, constraintNode); | 136 | result.set(CONSTRAINT, constraintNode); |
121 | return result; | 137 | return result; | ... | ... |
... | @@ -122,6 +122,10 @@ public class PcePathWebResource extends AbstractWebResource { | ... | @@ -122,6 +122,10 @@ public class PcePathWebResource extends AbstractWebResource { |
122 | JsonNode port = jsonTree.get("path"); | 122 | JsonNode port = jsonTree.get("path"); |
123 | TunnelService tunnelService = get(TunnelService.class); | 123 | TunnelService tunnelService = get(TunnelService.class); |
124 | PcePath path = codec(PcePath.class).decode((ObjectNode) port, this); | 124 | PcePath path = codec(PcePath.class).decode((ObjectNode) port, this); |
125 | + if (path == null) { | ||
126 | + return Response.status(OK).entity(PCE_SETUP_PATH_FAILED).build(); | ||
127 | + } | ||
128 | + | ||
125 | //Validating tunnel name, duplicated tunnel names not allowed | 129 | //Validating tunnel name, duplicated tunnel names not allowed |
126 | Collection<Tunnel> existingTunnels = tunnelService.queryTunnel(Tunnel.Type.MPLS); | 130 | Collection<Tunnel> existingTunnels = tunnelService.queryTunnel(Tunnel.Type.MPLS); |
127 | if (existingTunnels != null) { | 131 | if (existingTunnels != null) { | ... | ... |
-
Please register or login to post a comment