Mahesh Poojary S
Committed by Gerrit Code Review

[ONOS-4164] todo removal

Change-Id: Iaed7a5d2960529ecd548897b546a8804bbc9da27
......@@ -24,9 +24,12 @@ import org.apache.karaf.shell.commands.Argument;
import org.apache.karaf.shell.commands.Command;
import org.apache.karaf.shell.commands.Option;
import org.onlab.util.DataRateUnit;
import org.onosproject.cli.AbstractShellCommand;
import org.onosproject.net.DeviceId;
import org.onosproject.net.intent.constraint.BandwidthConstraint;
import org.onosproject.net.intent.Constraint;
import org.onosproject.pce.pceservice.constraint.CostConstraint;
import org.onosproject.pce.pceservice.LspType;
import org.onosproject.pce.pceservice.api.PceService;
......@@ -71,20 +74,32 @@ public class PceSetupPathCommand extends AbstractShellCommand {
DeviceId srcDevice = DeviceId.deviceId(src);
DeviceId dstDevice = DeviceId.deviceId(dst);
LspType lspType = LspType.values()[type];
List<Constraint> listConstrnt = new LinkedList<>();
// add cost
//TODO: need to uncomment below lines once CostConstraint is ready
//CostConstraint.Type costType = CostConstraint.Type.values()[cost];
//listConstrnt.add(CostConstraint.of(costType));
// LSP type validation
if ((type < 0) || (type > 2)) {
error("The LSP type value can be PCE tunnel with signalling in network (0), " +
"PCE tunnel without signalling in network with segment routing (1), " +
"PCE tunnel without signalling in network (2).");
return;
}
LspType lspType = LspType.values()[type];
// add bandwidth
// Add bandwidth
// bandwidth default data rate unit is in BPS
if (bandwidth != 0.0) {
//TODO: need to uncomment below line once BandwidthConstraint is ready
//listConstrnt.add(LocalBandwidthConstraint.of(bandwidth, DataRateUnit.valueOf("BPS")));
listConstrnt.add(BandwidthConstraint.of(bandwidth, DataRateUnit.valueOf("BPS")));
}
// Add cost
// Cost validation
if ((cost < 1) || (cost > 2)) {
error("The cost attribute value either IGP cost(1) or TE cost(2).");
return;
}
// Here 'cost - 1' indicates the index of enum
CostConstraint.Type costType = CostConstraint.Type.values()[cost - 1];
listConstrnt.add(CostConstraint.of(costType));
if (!service.setupPath(srcDevice, dstDevice, name, listConstrnt, lspType)) {
error("Path creation failed.");
......
......@@ -24,8 +24,12 @@ import org.apache.karaf.shell.commands.Argument;
import org.apache.karaf.shell.commands.Command;
import org.apache.karaf.shell.commands.Option;
import org.onlab.util.DataRateUnit;
import org.onosproject.cli.AbstractShellCommand;
import org.onosproject.incubator.net.tunnel.TunnelId;
import org.onosproject.net.intent.constraint.BandwidthConstraint;
import org.onosproject.net.intent.Constraint;
import org.onosproject.pce.pceservice.constraint.CostConstraint;
import org.onosproject.pce.pceservice.api.PceService;
import org.slf4j.Logger;
......@@ -56,23 +60,25 @@ public class PceUpdatePathCommand extends AbstractShellCommand {
PceService service = get(PceService.class);
List<Constraint> constrntList = new LinkedList<>();
// Assign bandwidth. Data rate unit is in Bps.
if (bandwidth != 0.0) {
constrntList.add(BandwidthConstraint.of(Double.valueOf(bandwidth), DataRateUnit.valueOf("BPS")));
}
// Assign cost
if (cost != 0) {
//TODO: need to uncomment below lines once CostConstraint is ready
//CostConstraint.Type costType = CostConstraint.Type.values()[Integer.valueOf(cost)];
//constrntList.add(CostConstraint.of(costType));
// Cost validation
if ((cost < 1) || (cost > 2)) {
error("The cost attribute value is either IGP cost(1) or TE cost(2).");
return;
}
CostConstraint.Type costType = CostConstraint.Type.values()[cost - 1];
constrntList.add(CostConstraint.of(costType));
}
// Assign bandwidth. Data rate unit is in Bps.
if (bandwidth != 0.0) {
//TODO: need to uncomment below line once BandwidthConstraint is ready
//constrntList.add(LocalBandwidthConstraint.of(Double.valueOf(bandwidth), DataRateUnit.valueOf("BPS")));
if (!service.updatePath(TunnelId.valueOf(id), constrntList)) {
error("Path updation failed.");
return;
}
//TODO: need to uncomment below lines once updatePath method is added to PceService
//if (null == service.updatePath(PcePathId.of(id), constrntList)) {
// error("Path updation failed.");
// return;
//}
}
}
......
......@@ -20,9 +20,12 @@ import static com.google.common.base.MoreObjects.toStringHelper;
import java.util.Objects;
import org.onlab.util.DataRateUnit;
import org.onosproject.incubator.net.tunnel.Tunnel;
import org.onosproject.incubator.net.tunnel.TunnelId;
import org.onosproject.net.intent.constraint.BandwidthConstraint;
import org.onosproject.net.intent.Constraint;
import org.onosproject.pce.pceservice.constraint.CostConstraint;
/**
* Implementation of an entity which provides functionalities of pce path.
......@@ -43,9 +46,10 @@ public final class DefaultPcePath implements PcePath {
* @param id path id
* @param src ingress
* @param dst egress
* @param lspType lsp type
* @param lspType LSP type
* @param name symbolic-path-name
* @param constrnt pce constraint
* @param costConstrnt cost constraint
* @param bandwidthConstrnt bandwidth constraint
*/
private DefaultPcePath(TunnelId id, String src, String dst, LspType lspType,
String name, Constraint costConstrnt, Constraint bandwidthConstrnt) {
......@@ -210,7 +214,7 @@ public final class DefaultPcePath implements PcePath {
@Override
public Builder lspType(String type) {
if (null != type) {
this.lspType = LspType.values()[Integer.valueOf(type) - 1];
this.lspType = LspType.values()[Integer.valueOf(type)];
}
return this;
}
......@@ -223,19 +227,14 @@ public final class DefaultPcePath implements PcePath {
@Override
public Builder costConstraint(String cost) {
this.costConstraint = null;
//TODO: below lines will be uncommented once CostConstraint class is ready
// this.costConstraint = CostConstraint.of(cost);
//}
this.costConstraint = CostConstraint.of(CostConstraint.Type.values()[Integer.valueOf(cost) - 1]);
return this;
}
@Override
public Builder bandwidthConstraint(String bandwidth) {
this.bandwidthConstraint = null;
//TODO: below lines will be uncommented once LocalBandwidthConstraint class is ready
// this.bandwidthConstraint = LocalBandwidthConstraint.of(bandwidth);
//}
this.bandwidthConstraint = BandwidthConstraint.of(Double.valueOf(bandwidth), DataRateUnit
.valueOf("BPS"));
return this;
}
......@@ -244,14 +243,24 @@ public final class DefaultPcePath implements PcePath {
this.id = TunnelId.valueOf(tunnel.tunnelId().id());
this.source = tunnel.src().toString();
this.destination = tunnel.dst().toString();
//TODO: need to uncomment below line once LSP_SIG_TYPE is added to AnnotationKeys.
this.lspType = null; // = LspType.valueOf(tunnel.annotations()
//.value(AnnotationKeys.LSP_SIG_TYPE));
this.name = tunnel.tunnelName().toString();
//TODO: uncomment below lines once CostConstraint and LocalBandwidthConstraint classes are ready
this.costConstraint = null; // = CostConstraint.of(tunnel.path().cost());
this.bandwidthConstraint = null; // = LocalBandwidthConstraint.of(tunnel.annotations()
//.value(AnnotationKeys.BANDWIDTH));
// LSP type
String lspType = tunnel.annotations().value(PcepAnnotationKeys.LSP_SIG_TYPE);
if (lspType != null) {
this.lspType = LspType.values()[Integer.valueOf(lspType) - 1];
}
// Cost type
String costType = tunnel.annotations().value(PcepAnnotationKeys.COST_TYPE);
if (costType != null) {
this.costConstraint = CostConstraint.of(CostConstraint.Type.values()[Integer.valueOf(costType) - 1]);
}
// Bandwidth
String bandwidth = tunnel.annotations().value(PcepAnnotationKeys.BANDWIDTH);
if (bandwidth != null) {
this.bandwidthConstraint = BandwidthConstraint.of(Double.parseDouble(bandwidth),
DataRateUnit.valueOf("BPS"));
}
return this;
}
......
......@@ -34,10 +34,11 @@ import org.onlab.util.KryoNamespace;
import org.onosproject.incubator.net.tunnel.TunnelId;
import org.onosproject.incubator.net.resource.label.LabelResource;
import org.onosproject.incubator.net.resource.label.LabelResourceId;
import org.onosproject.net.intent.constraint.BandwidthConstraint;
import org.onosproject.net.DeviceId;
import org.onosproject.net.intent.Constraint;
import org.onosproject.net.Link;
import org.onosproject.net.resource.ResourceConsumer;
import org.onosproject.pce.pceservice.constraint.CostConstraint;
import org.onosproject.pce.pceservice.TunnelConsumerId;
import org.onosproject.pce.pceservice.LspType;
import org.onosproject.pce.pcestore.api.LspLocalLabelInfo;
......@@ -128,10 +129,9 @@ public class DistributedPceStore implements PceStore {
new KryoNamespace.Builder()
.register(KryoNamespaces.API)
.register(PcePathInfo.class,
//TODO: Instead of Constraint.class need to add actual implemented class
//TODO: on this interface like CostConstraint.class and
//TODO: BandwidthConstraint.class. Will be added once it is confirmed.
Constraint.class,
CostConstraint.class,
CostConstraint.Type.class,
BandwidthConstraint.class,
LspType.class)
.build()))
......
......@@ -15,10 +15,10 @@
*/
package org.onosproject.pce.pcestore;
import java.util.List;
import com.google.common.base.MoreObjects;
import java.util.Objects;
import java.util.List;
import org.onosproject.net.resource.ResourceConsumer;
import org.onosproject.pce.pcestore.api.LspLocalLabelInfo;
......
......@@ -87,7 +87,7 @@ public final class PcePathCodec extends JsonCodec<PcePath> {
jNode = constraintJNode.get(COST);
if (jNode != null) {
String cost = jNode.asText();
resultBuilder.bandwidthConstraint(cost);
resultBuilder.costConstraint(cost);
}
// retrieve bandwidth
......
......@@ -53,7 +53,6 @@ import com.fasterxml.jackson.databind.node.ObjectNode;
/**
* Query and program pce path.
*/
@Path("path")
public class PcePathWebResource extends AbstractWebResource {
......@@ -124,14 +123,11 @@ public class PcePathWebResource extends AbstractWebResource {
LspType lspType = path.lspType();
List<Constraint> listConstrnt = new LinkedList<Constraint>();
// add cost
//TODO: need to uncomment below lines once Bandwidth and Cost constraint classes are ready
//CostConstraint.Type costType = CostConstraint.Type.values()[Integer.valueOf(path.constraint().cost())];
//listConstrnt.add(CostConstraint.of(costType));
// Add bandwidth
listConstrnt.add(path.bandwidthConstraint());
// add bandwidth. Data rate unit is in BPS.
//listConstrnt.add(LocalBandwidthConstraint.of(Double.valueOf(path.constraint().bandwidth()), DataRateUnit
// .valueOf("BPS")));
// Add cost
listConstrnt.add(path.costConstraint());
Boolean issuccess = nullIsNotFound(get(PceService.class)
.setupPath(srcDevice, dstDevice, path.name(), listConstrnt, lspType),
......@@ -161,19 +157,15 @@ public class PcePathWebResource extends AbstractWebResource {
ObjectNode jsonTree = (ObjectNode) mapper().readTree(stream);
JsonNode pathNode = jsonTree.get("path");
PcePath path = codec(PcePath.class).decode((ObjectNode) pathNode, this);
// Assign cost
List<Constraint> constrntList = new LinkedList<Constraint>();
//TODO: need to uncomment below lines once CostConstraint class is ready
if (path.costConstraint() != null) {
//CostConstraint.Type costType = CostConstraint.Type.values()[path.constraint().cost()];
//constrntList.add(CostConstraint.of(costType));
// Assign bandwidth
if (path.bandwidthConstraint() != null) {
constrntList.add(path.bandwidthConstraint());
}
// Assign bandwidth. Data rate unit is in BPS.
if (path.bandwidthConstraint() != null) {
//TODO: need to uncomment below lines once BandwidthConstraint class is ready
//constrntList.add(LocalBandwidthConstraint
// .of(path.constraint().bandwidth(), DataRateUnit.valueOf("BPS")));
// Assign cost
if (path.costConstraint() != null) {
constrntList.add(path.costConstraint());
}
Boolean result = nullIsNotFound(get(PceService.class).updatePath(TunnelId.valueOf(id), constrntList),
......
......@@ -21,7 +21,11 @@ import org.junit.Test;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import com.google.common.testing.EqualsTester;
import org.onosproject.incubator.net.tunnel.TunnelId;
import org.onosproject.pce.pceservice.constraint.CostConstraint;
import org.onosproject.net.intent.constraint.BandwidthConstraint;
/**
* Unit tests for DefaultPcePath class.
......@@ -78,8 +82,8 @@ public class DefaultPcePathTest {
.bandwidthConstraint(bandwidth2)
.build();
path2.id(TunnelId.valueOf("2"));
//TODO: will be uncommented below line once CostConstraint and LocalBandwidthConstraint classes are ready
//new EqualsTester().addEqualityGroup(path1, samePath1).addEqualityGroup(path2).testEquals();
new EqualsTester().addEqualityGroup(path1, samePath1).addEqualityGroup(path2).testEquals();
}
/**
......@@ -91,7 +95,7 @@ public class DefaultPcePathTest {
final String bandwidth = "600";
final String src = "indiatimes";
final String dst = "deccan";
final String type = "3";
final String type = "2";
final String name = "pcc4";
PcePath path = DefaultPcePath.builder()
......@@ -103,12 +107,14 @@ public class DefaultPcePathTest {
.bandwidthConstraint(bandwidth)
.build();
assertThat(src, is(path.source()));
assertThat(dst, is(path.destination()));
assertThat(LspType.WITHOUT_SIGNALLING_AND_WITHOUT_SR, is(path.lspType()));
assertThat(name, is(path.name()));
//TODO: will be uncommented below lines once CostConstraint and LocalBandwidthConstraint classes are ready
//assertThat(cost, is(path.costConstraint().toString()));
//assertThat(bandwidth, is(path.bandwidthConstraint().toString()));
assertThat(path.source(), is(src));
assertThat(path.destination(), is(dst));
assertThat(path.lspType(), is(LspType.WITHOUT_SIGNALLING_AND_WITHOUT_SR));
assertThat(path.name(), is(name));
CostConstraint costConstExpected = CostConstraint.of(CostConstraint.Type.values()[Integer.valueOf(cost) - 1]);
CostConstraint costConstActual = (CostConstraint) path.costConstraint();
assertThat(costConstActual.type(), is(costConstExpected.type()));
BandwidthConstraint bandwidthActual = (BandwidthConstraint) path.bandwidthConstraint();
assertThat(bandwidthActual.bandwidth().bps(), is(Double.valueOf(bandwidth)));
}
}
......
......@@ -48,7 +48,6 @@ public class MockPceCodecContext implements CodecContext {
@SuppressWarnings("unchecked")
@Override
public <T> T getService(Class<T> serviceClass) {
// TODO
return null;
}
......
......@@ -24,8 +24,13 @@ import java.io.InputStream;
import org.junit.Before;
import org.junit.Test;
import org.onlab.util.DataRateUnit;
import org.onosproject.codec.JsonCodec;
import org.onosproject.pce.pceservice.PcePath;
import org.onosproject.net.intent.constraint.BandwidthConstraint;
import org.onosproject.net.intent.Constraint;
import org.onosproject.pce.pceservice.constraint.CostConstraint;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
......@@ -80,9 +85,15 @@ public class PcePathCodecTest {
assertThat(pcePath.source().toString(), is("11.0.0.1"));
assertThat(pcePath.destination(), is("11.0.0.2"));
assertThat(pcePath.lspType().toString(), is("SR_WITHOUT_SIGNALLING"));
//TODO: uncomment below lines once CostConstraint and LocalBandwidthConstraint are ready
//assertThat(pcePath.costConstraint().toString(), is(2));
//assertThat(pcePath.bandwidthConstraint().toString(), is(200.0));
assertThat(pcePath.lspType().toString(), is("WITHOUT_SIGNALLING_AND_WITHOUT_SR"));
// testing cost type
String cost = "2";
Constraint costConstraint = CostConstraint.of(CostConstraint.Type.values()[Integer.valueOf(cost) - 1]);
assertThat(pcePath.costConstraint(), is(costConstraint));
// testing bandwidth
String bandwidth = "200";
Constraint bandwidthConstraint = BandwidthConstraint.of(Double.valueOf(bandwidth), DataRateUnit
.valueOf("BPS"));
assertThat(pcePath.bandwidthConstraint(), is(bandwidthConstraint));
}
}
......
......@@ -21,15 +21,14 @@ import static org.easymock.EasyMock.expect;
import static org.easymock.EasyMock.replay;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.is;
//TODO: below imports needs to be uncommented once TODO in DefaultPcePath class are removed
//import static org.hamcrest.Matchers.notNullValue;
import static org.hamcrest.Matchers.notNullValue;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.fail;
import static org.onosproject.net.Link.Type.DIRECT;
//import com.eclipsesource.json.Json;
//import com.eclipsesource.json.JsonObject;
import com.eclipsesource.json.Json;
import com.eclipsesource.json.JsonObject;
import java.io.InputStream;
import java.net.HttpURLConnection;
......@@ -64,6 +63,7 @@ import org.onosproject.net.DefaultPath;
import org.onosproject.net.DeviceId;
import org.onosproject.net.Link;
import org.onosproject.pce.pceservice.api.PceService;
import org.onosproject.pce.pceservice.PcepAnnotationKeys;
import org.onosproject.net.Path;
import org.onosproject.net.PortNumber;
import org.onosproject.net.provider.ProviderId;
......@@ -158,10 +158,16 @@ public class PcePathResourceTest extends PceResourceTest {
// Path
path = new DefaultPath(providerId, linkList, 10);
// Annotations
DefaultAnnotations.Builder builderAnn = DefaultAnnotations.builder();
builderAnn.set(PcepAnnotationKeys.LSP_SIG_TYPE, "2");
builderAnn.set(PcepAnnotationKeys.COST_TYPE, "2");
builderAnn.set(PcepAnnotationKeys.BANDWIDTH, "200");
// Tunnel
tunnel = new DefaultTunnel(producerName, src, dst, Tunnel.Type.VXLAN,
Tunnel.State.ACTIVE, groupId, tunnelId,
tunnelName, path);
tunnelName, path, builderAnn.build());
}
/**
......@@ -190,16 +196,15 @@ public class PcePathResourceTest extends PceResourceTest {
*/
@Test
public void testGetTunnelId() {
//TODO: uncomment below lines once TODO in DefaultPcePath class are removed
//expect(pceService.queryPath(anyObject()))
// .andReturn(tunnel)
// .anyTimes();
//replay(pceService);
expect(pceService.queryPath(anyObject()))
.andReturn(tunnel)
.anyTimes();
replay(pceService);
//WebTarget wt = target();
//String response = wt.path("path/1").request().get(String.class);
//JsonObject result = Json.parse(response).asObject();
//assertThat(result, notNullValue());
WebTarget wt = target();
String response = wt.path("path/1").request().get(String.class);
JsonObject result = Json.parse(response).asObject();
assertThat(result, notNullValue());
}
/**
......
......@@ -38,121 +38,99 @@ public class TunnelServiceAdapter implements TunnelService {
@Override
public void addListener(TunnelListener listener) {
// TODO Auto-generated method stub
}
@Override
public void removeListener(TunnelListener listener) {
// TODO Auto-generated method stub
}
@Override
public Tunnel borrowTunnel(ApplicationId consumerId, TunnelId tunnelId, Annotations... annotations) {
// TODO Auto-generated method stub
return null;
}
@Override
public Collection<Tunnel> borrowTunnel(ApplicationId consumerId, TunnelName tunnelName,
Annotations... annotations) {
// TODO Auto-generated method stub
return null;
}
@Override
public Collection<Tunnel> borrowTunnel(ApplicationId consumerId, TunnelEndPoint src, TunnelEndPoint dst,
Annotations... annotations) {
// TODO Auto-generated method stub
return null;
}
@Override
public Collection<Tunnel> borrowTunnel(ApplicationId consumerId, TunnelEndPoint src, TunnelEndPoint dst, Type type,
Annotations... annotations) {
// TODO Auto-generated method stub
return null;
}
@Override
public TunnelId setupTunnel(ApplicationId producerId, ElementId srcElementId, Tunnel tunnel, Path path) {
// TODO Auto-generated method stub
return null;
}
@Override
public boolean downTunnel(ApplicationId producerId, TunnelId tunnelId) {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean returnTunnel(ApplicationId consumerId, TunnelId tunnelId, Annotations... annotations) {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean returnTunnel(ApplicationId consumerId, TunnelName tunnelName, Annotations... annotations) {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean returnTunnel(ApplicationId consumerId, TunnelEndPoint src, TunnelEndPoint dst, Type type,
Annotations... annotations) {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean returnTunnel(ApplicationId consumerId, TunnelEndPoint src, TunnelEndPoint dst,
Annotations... annotations) {
// TODO Auto-generated method stub
return false;
}
@Override
public Tunnel queryTunnel(TunnelId tunnelId) {
// TODO Auto-generated method stub
return null;
}
@Override
public Collection<TunnelSubscription> queryTunnelSubscription(ApplicationId consumerId) {
// TODO Auto-generated method stub
return null;
}
@Override
public Collection<Tunnel> queryTunnel(Type type) {
// TODO Auto-generated method stub
return null;
}
@Override
public Collection<Tunnel> queryTunnel(TunnelEndPoint src, TunnelEndPoint dst) {
// TODO Auto-generated method stub
return null;
}
@Override
public Collection<Tunnel> queryAllTunnels() {
// TODO Auto-generated method stub
return null;
}
@Override
public int tunnelCount() {
// TODO Auto-generated method stub
return 0;
}
@Override
public Iterable<Tunnel> getTunnels(DeviceId deviceId) {
// TODO Auto-generated method stub
return null;
}
}
......