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; ...@@ -19,9 +19,9 @@ package org.onosproject.pcep.api;
19 import java.util.List; 19 import java.util.List;
20 20
21 /** 21 /**
22 - * Abstraction of a generalized PCEP Tunnel entity (bandwidth pipe) for 22 + * Abstraction of a generalized PCEP Tunnel entity (bandwidth pipe) for L2
23 - * L2 networks or L1/L0 networks, representation of e.g., VLAN, L1 ODUk 23 + * networks or L1/L0 networks, representation of e.g., VLAN, L1 ODUk connection,
24 - * connection, WDM OCH, etc.. 24 + * WDM OCH, etc..
25 */ 25 */
26 public interface PcepTunnel extends PcepOperator { 26 public interface PcepTunnel extends PcepOperator {
27 27
...@@ -72,96 +72,111 @@ public interface PcepTunnel extends PcepOperator { ...@@ -72,96 +72,111 @@ public interface PcepTunnel extends PcepOperator {
72 public static enum PATHTYPE { 72 public static enum PATHTYPE {
73 73
74 /** 74 /**
75 - * the preferred path. 75 + * Indicates path is the preferred path.
76 */ 76 */
77 FIRST, 77 FIRST,
78 78
79 /** 79 /**
80 - * the alternate path. 80 + * Indicates path is the alternate path.
81 */ 81 */
82 SECOND 82 SECOND
83 } 83 }
84 84
85 /** 85 /**
86 - * Get the type of a tunnel. 86 + * Represents state of the path, work normally or broken down.
87 + *
88 + */
89 + public static enum PathState {
90 + NORMAL, BROKEN
91 + }
92 +
93 + /**
94 + * Returns the type of a tunnel.
87 * 95 *
88 * @return tunnel type 96 * @return tunnel type
89 */ 97 */
90 public Type type(); 98 public Type type();
91 99
92 /** 100 /**
93 - * Get the name of a tunnel. 101 + * Returns the name of a tunnel.
94 * 102 *
95 * @return tunnel name 103 * @return tunnel name
96 */ 104 */
97 public String name(); 105 public String name();
98 106
99 /** 107 /**
100 - * Get the device id of destination endpoint of a tunnel. 108 + * Returns the device id of destination endpoint of a tunnel.
101 * 109 *
102 * @return device id 110 * @return device id
103 */ 111 */
104 public PcepDpid srcDeviceID(); 112 public PcepDpid srcDeviceID();
105 113
106 /** 114 /**
107 - * Get the device id of source endpoint of a tunnel. 115 + * Returns the device id of source endpoint of a tunnel.
108 * 116 *
109 * @return device id 117 * @return device id
110 */ 118 */
111 public PcepDpid dstDeviceId(); 119 public PcepDpid dstDeviceId();
112 120
113 /** 121 /**
114 - * Get source port of a tunnel. 122 + * Returns source port of a tunnel.
115 * 123 *
116 * @return port number 124 * @return port number
117 */ 125 */
118 public long srcPort(); 126 public long srcPort();
119 127
120 /** 128 /**
121 - * Get destination port of a tunnel. 129 + * Returns destination port of a tunnel.
122 * 130 *
123 * @return port number 131 * @return port number
124 */ 132 */
125 public long dstPort(); 133 public long dstPort();
126 134
127 /** 135 /**
128 - * Get the bandwidth of a tunnel. 136 + * Returns the bandwidth of a tunnel.
129 * 137 *
130 * @return bandwidth 138 * @return bandwidth
131 */ 139 */
132 public long bandWidth(); 140 public long bandWidth();
133 141
134 /** 142 /**
135 - * Get the tunnel id. 143 + * Returns the tunnel id.
136 * 144 *
137 * @return id of the PCEP tunnel 145 * @return id of the PCEP tunnel
138 */ 146 */
139 public long id(); 147 public long id();
140 148
141 /** 149 /**
142 - * Get the detail hop list of a tunnel. 150 + * Returns the detail hop list of a tunnel.
143 * 151 *
144 * @return hop list 152 * @return hop list
145 */ 153 */
146 public List<PcepHopNodeDescription> getHopList(); 154 public List<PcepHopNodeDescription> getHopList();
147 155
148 /** 156 /**
149 - * Get the instance of a pcep tunnel,a instance is used to mark the times of a tunnel created. 157 + * Returns the instance of a pcep tunnel,a instance is used to mark the times of
150 - * instance and id identify a tunnel together. 158 + * a tunnel created. instance and id identify a tunnel together.
151 * 159 *
152 * @return the instance of a tunnel. 160 * @return the instance of a tunnel.
153 */ 161 */
154 public int getInstance(); 162 public int getInstance();
155 163
156 /** 164 /**
157 - * Get the ability of a tunnel.NOPROTECTED,SILVER,or DIAMOND. 165 + * Returns the state of a path.
166 + *
167 + * @return normal or broken
168 + */
169 + public PathState getPathState();
170 +
171 + /**
172 + * Returns the ability of a tunnel.
158 * 173 *
159 * @return ability of the tunenl 174 * @return ability of the tunenl
160 */ 175 */
161 public Ability getSla(); 176 public Ability getSla();
162 177
163 /** 178 /**
164 - * Get the path type of a path if the tunnel's ability is diamond . 179 + * Returns the path type of a path if the tunnel's ability is diamond .
165 * 180 *
166 * @return the type of a path, the preferred or alternate. 181 * @return the type of a path, the preferred or alternate.
167 */ 182 */
...@@ -172,6 +187,6 @@ public interface PcepTunnel extends PcepOperator { ...@@ -172,6 +187,6 @@ public interface PcepTunnel extends PcepOperator {
172 * 187 *
173 * @return the tunnel id of a OCH tunnel under lay of a VLAN tunnel. 188 * @return the tunnel id of a OCH tunnel under lay of a VLAN tunnel.
174 */ 189 */
175 - public long underLayTunnelId(); 190 + public long underlayTunnelId();
176 191
177 } 192 }
......
...@@ -72,7 +72,7 @@ public class TunnelCreateCommand extends AbstractShellCommand { ...@@ -72,7 +72,7 @@ public class TunnelCreateCommand extends AbstractShellCommand {
72 72
73 @Option(name = "-b", aliases = "--bandwidth", 73 @Option(name = "-b", aliases = "--bandwidth",
74 description = "The bandwidth attribute of tunnel", required = false, multiValued = false) 74 description = "The bandwidth attribute of tunnel", required = false, multiValued = false)
75 - String bandwidth = null; 75 + String bandwidth = "1024";
76 76
77 private static final String FMT = "The tunnel identity is %s"; 77 private static final String FMT = "The tunnel identity is %s";
78 78
...@@ -181,7 +181,7 @@ public class TunnelCreateCommand extends AbstractShellCommand { ...@@ -181,7 +181,7 @@ public class TunnelCreateCommand extends AbstractShellCommand {
181 181
182 SparseAnnotations annotations = DefaultAnnotations 182 SparseAnnotations annotations = DefaultAnnotations
183 .builder() 183 .builder()
184 - .set("bandwidth", bandwidth == null && "".equals(bandwidth) ? "0" : bandwidth) 184 + .set("bandwidth", bandwidth == null || "".equals(bandwidth) ? "0" : bandwidth)
185 .build(); 185 .build();
186 TunnelDescription tunnel = new DefaultTunnelDescription( 186 TunnelDescription tunnel = new DefaultTunnelDescription(
187 null, 187 null,
...@@ -197,6 +197,10 @@ public class TunnelCreateCommand extends AbstractShellCommand { ...@@ -197,6 +197,10 @@ public class TunnelCreateCommand extends AbstractShellCommand {
197 null, 197 null,
198 annotations); 198 annotations);
199 TunnelId tunnelId = service.tunnelAdded(tunnel); 199 TunnelId tunnelId = service.tunnelAdded(tunnel);
200 + if (tunnelId == null) {
201 + error("Create tunnel failed.");
202 + return;
203 + }
200 print(FMT, tunnelId.id()); 204 print(FMT, tunnelId.id());
201 } 205 }
202 206
......
...@@ -205,7 +205,7 @@ public class TunnelQueryCommand extends AbstractShellCommand { ...@@ -205,7 +205,7 @@ public class TunnelQueryCommand extends AbstractShellCommand {
205 205
206 private String showPath(Path path) { 206 private String showPath(Path path) {
207 if (path == null) { 207 if (path == null) {
208 - return ""; 208 + return "null";
209 } 209 }
210 StringBuilder builder = new StringBuilder("("); 210 StringBuilder builder = new StringBuilder("(");
211 for (Link link : path.links()) { 211 for (Link link : path.links()) {
......
...@@ -60,6 +60,7 @@ import org.onosproject.pcep.api.PcepDpid; ...@@ -60,6 +60,7 @@ import org.onosproject.pcep.api.PcepDpid;
60 import org.onosproject.pcep.api.PcepHopNodeDescription; 60 import org.onosproject.pcep.api.PcepHopNodeDescription;
61 import org.onosproject.pcep.api.PcepOperator.OperationType; 61 import org.onosproject.pcep.api.PcepOperator.OperationType;
62 import org.onosproject.pcep.api.PcepTunnel; 62 import org.onosproject.pcep.api.PcepTunnel;
63 +import org.onosproject.pcep.api.PcepTunnel.PathState;
63 import org.onosproject.pcep.api.PcepTunnel.PATHTYPE; 64 import org.onosproject.pcep.api.PcepTunnel.PATHTYPE;
64 import org.onosproject.pcep.api.PcepTunnelListener; 65 import org.onosproject.pcep.api.PcepTunnelListener;
65 import org.slf4j.Logger; 66 import org.slf4j.Logger;
...@@ -199,7 +200,7 @@ public class PcepTunnelProvider extends AbstractProvider ...@@ -199,7 +200,7 @@ public class PcepTunnelProvider extends AbstractProvider
199 Tunnel tunnelOld = tunnelQueryById(tunnel.id()); 200 Tunnel tunnelOld = tunnelQueryById(tunnel.id());
200 checkNotNull(tunnelOld, "The tunnel id is not exsited."); 201 checkNotNull(tunnelOld, "The tunnel id is not exsited.");
201 if (tunnelOld.type() != Tunnel.Type.VLAN) { 202 if (tunnelOld.type() != Tunnel.Type.VLAN) {
202 - error("Llegal tunnel type. Only support VLAN tunnel deletion."); 203 + error("Illegal tunnel type. Only support VLAN tunnel deletion.");
203 return; 204 return;
204 } 205 }
205 String pcepTunnelId = getPCEPTunnelKey(tunnel.id()); 206 String pcepTunnelId = getPCEPTunnelKey(tunnel.id());
...@@ -217,7 +218,7 @@ public class PcepTunnelProvider extends AbstractProvider ...@@ -217,7 +218,7 @@ public class PcepTunnelProvider extends AbstractProvider
217 218
218 Tunnel tunnelOld = tunnelQueryById(tunnel.id()); 219 Tunnel tunnelOld = tunnelQueryById(tunnel.id());
219 if (tunnelOld.type() != Tunnel.Type.VLAN) { 220 if (tunnelOld.type() != Tunnel.Type.VLAN) {
220 - error("Llegal tunnel type. Only support VLAN tunnel update."); 221 + error("Illegal tunnel type. Only support VLAN tunnel update.");
221 return; 222 return;
222 } 223 }
223 long bandwidth = Long 224 long bandwidth = Long
...@@ -256,7 +257,7 @@ public class PcepTunnelProvider extends AbstractProvider ...@@ -256,7 +257,7 @@ public class PcepTunnelProvider extends AbstractProvider
256 257
257 // Creates a path that leads through the given devices. 258 // Creates a path that leads through the given devices.
258 private Path createPath(List<PcepHopNodeDescription> hopList, 259 private Path createPath(List<PcepHopNodeDescription> hopList,
259 - PATHTYPE pathtype) { 260 + PATHTYPE pathtype, PathState pathState) {
260 if (hopList == null || hopList.size() == 0) { 261 if (hopList == null || hopList.size() == 0) {
261 return null; 262 return null;
262 } 263 }
...@@ -270,6 +271,7 @@ public class PcepTunnelProvider extends AbstractProvider ...@@ -270,6 +271,7 @@ public class PcepTunnelProvider extends AbstractProvider
270 int hopNum = hopList.size() - 2; 271 int hopNum = hopList.size() - 2;
271 DefaultAnnotations extendAnnotations = DefaultAnnotations.builder() 272 DefaultAnnotations extendAnnotations = DefaultAnnotations.builder()
272 .set("pathNum", String.valueOf(hopNum)) 273 .set("pathNum", String.valueOf(hopNum))
274 + .set("pathState", String.valueOf(pathState))
273 .set("pathType", String.valueOf(pathtype)).build(); 275 .set("pathType", String.valueOf(pathtype)).build();
274 return new DefaultPath(id(), links, hopNum, extendAnnotations); 276 return new DefaultPath(id(), links, hopNum, extendAnnotations);
275 } 277 }
...@@ -299,7 +301,8 @@ public class PcepTunnelProvider extends AbstractProvider ...@@ -299,7 +301,8 @@ public class PcepTunnelProvider extends AbstractProvider
299 301
300 // add path after codes of tunnel's path merged 302 // add path after codes of tunnel's path merged
301 Path path = createPath(pcepTunnel.getHopList(), 303 Path path = createPath(pcepTunnel.getHopList(),
302 - pcepTunnel.getPathType()); 304 + pcepTunnel.getPathType(),
305 + pcepTunnel.getPathState());
303 306
304 OpticalTunnelEndPoint.Type endPointType = null; 307 OpticalTunnelEndPoint.Type endPointType = null;
305 switch (pcepTunnel.type()) { 308 switch (pcepTunnel.type()) {
...@@ -347,11 +350,11 @@ public class PcepTunnelProvider extends AbstractProvider ...@@ -347,11 +350,11 @@ public class PcepTunnelProvider extends AbstractProvider
347 350
348 // a VLAN tunnel always carry OCH tunnel, this annotation is the index 351 // a VLAN tunnel always carry OCH tunnel, this annotation is the index
349 // of a OCH tunnel. 352 // of a OCH tunnel.
350 - if (pcepTunnel.underLayTunnelId() != 0) { 353 + if (pcepTunnel.underlayTunnelId() != 0) {
351 DefaultAnnotations extendAnnotations = DefaultAnnotations 354 DefaultAnnotations extendAnnotations = DefaultAnnotations
352 .builder() 355 .builder()
353 .set("underLayTunnelIndex", 356 .set("underLayTunnelIndex",
354 - String.valueOf(pcepTunnel.underLayTunnelId())).build(); 357 + String.valueOf(pcepTunnel.underlayTunnelId())).build();
355 annotations = DefaultAnnotations.merge(annotations, 358 annotations = DefaultAnnotations.merge(annotations,
356 extendAnnotations); 359 extendAnnotations);
357 360
......