cheng fan
Committed by Gerrit Code Review

1. fix javadoc mistakes

2. add path state proverty to tunnel
3. fix bugs in tunnel creation and query commands.

Change-Id: I69b992e47630effe45764c887864d59d3a1eb870
......@@ -19,9 +19,9 @@ package org.onosproject.pcep.api;
import java.util.List;
/**
* Abstraction of a generalized PCEP Tunnel entity (bandwidth pipe) for
* L2 networks or L1/L0 networks, representation of e.g., VLAN, L1 ODUk
* connection, WDM OCH, etc..
* Abstraction of a generalized PCEP Tunnel entity (bandwidth pipe) for L2
* networks or L1/L0 networks, representation of e.g., VLAN, L1 ODUk connection,
* WDM OCH, etc..
*/
public interface PcepTunnel extends PcepOperator {
......@@ -72,96 +72,111 @@ public interface PcepTunnel extends PcepOperator {
public static enum PATHTYPE {
/**
* the preferred path.
* Indicates path is the preferred path.
*/
FIRST,
/**
* the alternate path.
* Indicates path is the alternate path.
*/
SECOND
}
/**
* Get the type of a tunnel.
* Represents state of the path, work normally or broken down.
*
*/
public static enum PathState {
NORMAL, BROKEN
}
/**
* Returns the type of a tunnel.
*
* @return tunnel type
*/
public Type type();
/**
* Get the name of a tunnel.
* Returns the name of a tunnel.
*
* @return tunnel name
*/
public String name();
/**
* Get the device id of destination endpoint of a tunnel.
* Returns the device id of destination endpoint of a tunnel.
*
* @return device id
*/
public PcepDpid srcDeviceID();
/**
* Get the device id of source endpoint of a tunnel.
* Returns the device id of source endpoint of a tunnel.
*
* @return device id
*/
public PcepDpid dstDeviceId();
/**
* Get source port of a tunnel.
* Returns source port of a tunnel.
*
* @return port number
*/
public long srcPort();
/**
* Get destination port of a tunnel.
* Returns destination port of a tunnel.
*
* @return port number
*/
public long dstPort();
/**
* Get the bandwidth of a tunnel.
* Returns the bandwidth of a tunnel.
*
* @return bandwidth
*/
public long bandWidth();
/**
* Get the tunnel id.
* Returns the tunnel id.
*
* @return id of the PCEP tunnel
*/
public long id();
/**
* Get the detail hop list of a tunnel.
* Returns the detail hop list of a tunnel.
*
* @return hop list
*/
public List<PcepHopNodeDescription> getHopList();
/**
* Get the instance of a pcep tunnel,a instance is used to mark the times of a tunnel created.
* instance and id identify a tunnel together.
* Returns the instance of a pcep tunnel,a instance is used to mark the times of
* a tunnel created. instance and id identify a tunnel together.
*
* @return the instance of a tunnel.
*/
public int getInstance();
/**
* Get the ability of a tunnel.NOPROTECTED,SILVER,or DIAMOND.
* Returns the state of a path.
*
* @return normal or broken
*/
public PathState getPathState();
/**
* Returns the ability of a tunnel.
*
* @return ability of the tunenl
*/
public Ability getSla();
/**
* Get the path type of a path if the tunnel's ability is diamond .
* Returns the path type of a path if the tunnel's ability is diamond .
*
* @return the type of a path, the preferred or alternate.
*/
......@@ -172,6 +187,6 @@ public interface PcepTunnel extends PcepOperator {
*
* @return the tunnel id of a OCH tunnel under lay of a VLAN tunnel.
*/
public long underLayTunnelId();
public long underlayTunnelId();
}
......
......@@ -72,7 +72,7 @@ public class TunnelCreateCommand extends AbstractShellCommand {
@Option(name = "-b", aliases = "--bandwidth",
description = "The bandwidth attribute of tunnel", required = false, multiValued = false)
String bandwidth = null;
String bandwidth = "1024";
private static final String FMT = "The tunnel identity is %s";
......@@ -181,7 +181,7 @@ public class TunnelCreateCommand extends AbstractShellCommand {
SparseAnnotations annotations = DefaultAnnotations
.builder()
.set("bandwidth", bandwidth == null && "".equals(bandwidth) ? "0" : bandwidth)
.set("bandwidth", bandwidth == null || "".equals(bandwidth) ? "0" : bandwidth)
.build();
TunnelDescription tunnel = new DefaultTunnelDescription(
null,
......@@ -197,6 +197,10 @@ public class TunnelCreateCommand extends AbstractShellCommand {
null,
annotations);
TunnelId tunnelId = service.tunnelAdded(tunnel);
if (tunnelId == null) {
error("Create tunnel failed.");
return;
}
print(FMT, tunnelId.id());
}
......
......@@ -205,7 +205,7 @@ public class TunnelQueryCommand extends AbstractShellCommand {
private String showPath(Path path) {
if (path == null) {
return "";
return "null";
}
StringBuilder builder = new StringBuilder("(");
for (Link link : path.links()) {
......
......@@ -60,6 +60,7 @@ import org.onosproject.pcep.api.PcepDpid;
import org.onosproject.pcep.api.PcepHopNodeDescription;
import org.onosproject.pcep.api.PcepOperator.OperationType;
import org.onosproject.pcep.api.PcepTunnel;
import org.onosproject.pcep.api.PcepTunnel.PathState;
import org.onosproject.pcep.api.PcepTunnel.PATHTYPE;
import org.onosproject.pcep.api.PcepTunnelListener;
import org.slf4j.Logger;
......@@ -199,7 +200,7 @@ public class PcepTunnelProvider extends AbstractProvider
Tunnel tunnelOld = tunnelQueryById(tunnel.id());
checkNotNull(tunnelOld, "The tunnel id is not exsited.");
if (tunnelOld.type() != Tunnel.Type.VLAN) {
error("Llegal tunnel type. Only support VLAN tunnel deletion.");
error("Illegal tunnel type. Only support VLAN tunnel deletion.");
return;
}
String pcepTunnelId = getPCEPTunnelKey(tunnel.id());
......@@ -217,7 +218,7 @@ public class PcepTunnelProvider extends AbstractProvider
Tunnel tunnelOld = tunnelQueryById(tunnel.id());
if (tunnelOld.type() != Tunnel.Type.VLAN) {
error("Llegal tunnel type. Only support VLAN tunnel update.");
error("Illegal tunnel type. Only support VLAN tunnel update.");
return;
}
long bandwidth = Long
......@@ -256,7 +257,7 @@ public class PcepTunnelProvider extends AbstractProvider
// Creates a path that leads through the given devices.
private Path createPath(List<PcepHopNodeDescription> hopList,
PATHTYPE pathtype) {
PATHTYPE pathtype, PathState pathState) {
if (hopList == null || hopList.size() == 0) {
return null;
}
......@@ -270,6 +271,7 @@ public class PcepTunnelProvider extends AbstractProvider
int hopNum = hopList.size() - 2;
DefaultAnnotations extendAnnotations = DefaultAnnotations.builder()
.set("pathNum", String.valueOf(hopNum))
.set("pathState", String.valueOf(pathState))
.set("pathType", String.valueOf(pathtype)).build();
return new DefaultPath(id(), links, hopNum, extendAnnotations);
}
......@@ -299,7 +301,8 @@ public class PcepTunnelProvider extends AbstractProvider
// add path after codes of tunnel's path merged
Path path = createPath(pcepTunnel.getHopList(),
pcepTunnel.getPathType());
pcepTunnel.getPathType(),
pcepTunnel.getPathState());
OpticalTunnelEndPoint.Type endPointType = null;
switch (pcepTunnel.type()) {
......@@ -347,11 +350,11 @@ public class PcepTunnelProvider extends AbstractProvider
// a VLAN tunnel always carry OCH tunnel, this annotation is the index
// of a OCH tunnel.
if (pcepTunnel.underLayTunnelId() != 0) {
if (pcepTunnel.underlayTunnelId() != 0) {
DefaultAnnotations extendAnnotations = DefaultAnnotations
.builder()
.set("underLayTunnelIndex",
String.valueOf(pcepTunnel.underLayTunnelId())).build();
String.valueOf(pcepTunnel.underlayTunnelId())).build();
annotations = DefaultAnnotations.merge(annotations,
extendAnnotations);
......