Avantika-Huawei

[ONOS-4170] Label Db sync

Change-Id: I7322d962551e3c5a046b64884ebc7a2f15ee0cd3
...@@ -57,6 +57,20 @@ public interface PcepSrpObject { ...@@ -57,6 +57,20 @@ public interface PcepSrpObject {
57 void setRFlag(boolean bRFlag); 57 void setRFlag(boolean bRFlag);
58 58
59 /** 59 /**
60 + * Returns S flag of SRP Object.
61 + *
62 + * @return S flag of SRP Object
63 + */
64 + boolean getSFlag();
65 +
66 + /**
67 + * Sets S(sync) flag with specified value.
68 + *
69 + * @param bSFlag S Flag of SRP Object
70 + */
71 + void setSFlag(boolean bSFlag);
72 +
73 + /**
60 * sets the optional TLvs. 74 * sets the optional TLvs.
61 * 75 *
62 * @param llOptionalTlv list of optional tlvs 76 * @param llOptionalTlv list of optional tlvs
...@@ -130,6 +144,13 @@ public interface PcepSrpObject { ...@@ -130,6 +144,13 @@ public interface PcepSrpObject {
130 boolean getRFlag(); 144 boolean getRFlag();
131 145
132 /** 146 /**
147 + * Returns S(sync) flag of SRP Object.
148 + *
149 + * @return S flag of SRP Object
150 + */
151 + boolean getSFlag();
152 +
153 + /**
133 * Sets R flag and returns its builder. 154 * Sets R flag and returns its builder.
134 * 155 *
135 * @param bRFlag R flag 156 * @param bRFlag R flag
...@@ -138,6 +159,14 @@ public interface PcepSrpObject { ...@@ -138,6 +159,14 @@ public interface PcepSrpObject {
138 Builder setRFlag(boolean bRFlag); 159 Builder setRFlag(boolean bRFlag);
139 160
140 /** 161 /**
162 + * Sets S flag and returns its builder.
163 + *
164 + * @param bSFlag S flag
165 + * @return Builder by setting S flag
166 + */
167 + Builder setSFlag(boolean bSFlag);
168 +
169 + /**
141 * Returns list of optional tlvs. 170 * Returns list of optional tlvs.
142 * 171 *
143 * @return llOptionalTlv list of optional tlvs 172 * @return llOptionalTlv list of optional tlvs
......
...@@ -43,7 +43,7 @@ public class PcepSrpObjectVer1 implements PcepSrpObject { ...@@ -43,7 +43,7 @@ public class PcepSrpObjectVer1 implements PcepSrpObject {
43 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 43 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
44 | Object-Class | OT |Res|P|I| Object Length (bytes) | 44 | Object-Class | OT |Res|P|I| Object Length (bytes) |
45 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 45 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
46 - | Flags |R| 46 + | Flags |S|R|
47 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 47 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
48 | SRP-ID-number | 48 | SRP-ID-number |
49 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 49 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
...@@ -60,7 +60,7 @@ public class PcepSrpObjectVer1 implements PcepSrpObject { ...@@ -60,7 +60,7 @@ public class PcepSrpObjectVer1 implements PcepSrpObject {
60 public static final byte SRP_OBJECT_VERSION = 1; 60 public static final byte SRP_OBJECT_VERSION = 1;
61 public static final short SRP_OBJ_MINIMUM_LENGTH = 12; 61 public static final short SRP_OBJ_MINIMUM_LENGTH = 12;
62 public static final int MINIMUM_COMMON_HEADER_LENGTH = 4; 62 public static final int MINIMUM_COMMON_HEADER_LENGTH = 4;
63 - public static final boolean DEFAULT_RFLAG = false; 63 + public static final boolean FLAG_DEFAULT_VALUE = false;
64 64
65 static final PcepObjectHeader DEFAULT_SRP_OBJECT_HEADER = new PcepObjectHeader(SRP_OBJ_CLASS, SRP_OBJ_TYPE, 65 static final PcepObjectHeader DEFAULT_SRP_OBJECT_HEADER = new PcepObjectHeader(SRP_OBJ_CLASS, SRP_OBJ_TYPE,
66 PcepObjectHeader.REQ_OBJ_OPTIONAL_PROCESS, PcepObjectHeader.RSP_OBJ_PROCESSED, SRP_OBJ_MINIMUM_LENGTH); 66 PcepObjectHeader.REQ_OBJ_OPTIONAL_PROCESS, PcepObjectHeader.RSP_OBJ_PROCESSED, SRP_OBJ_MINIMUM_LENGTH);
...@@ -68,6 +68,7 @@ public class PcepSrpObjectVer1 implements PcepSrpObject { ...@@ -68,6 +68,7 @@ public class PcepSrpObjectVer1 implements PcepSrpObject {
68 private PcepObjectHeader srpObjHeader; 68 private PcepObjectHeader srpObjHeader;
69 private static int flags; 69 private static int flags;
70 private boolean bRFlag; 70 private boolean bRFlag;
71 + private boolean bSFlag;
71 private int srpId; 72 private int srpId;
72 73
73 //Optional TLV 74 //Optional TLV
...@@ -80,14 +81,16 @@ public class PcepSrpObjectVer1 implements PcepSrpObject { ...@@ -80,14 +81,16 @@ public class PcepSrpObjectVer1 implements PcepSrpObject {
80 * 81 *
81 * @param srpObjHeader srp object header 82 * @param srpObjHeader srp object header
82 * @param bRFlag R flag 83 * @param bRFlag R flag
84 + * @param bSFlag S (sync) flag
83 * @param srpID srp Id 85 * @param srpID srp Id
84 * @param llOptionalTlv list of optional tlv 86 * @param llOptionalTlv list of optional tlv
85 */ 87 */
86 - public PcepSrpObjectVer1(PcepObjectHeader srpObjHeader, boolean bRFlag, int srpID, 88 + public PcepSrpObjectVer1(PcepObjectHeader srpObjHeader, boolean bRFlag, boolean bSFlag, int srpID,
87 LinkedList<PcepValueType> llOptionalTlv) { 89 LinkedList<PcepValueType> llOptionalTlv) {
88 90
89 this.srpObjHeader = srpObjHeader; 91 this.srpObjHeader = srpObjHeader;
90 this.bRFlag = bRFlag; 92 this.bRFlag = bRFlag;
93 + this.bSFlag = bSFlag;
91 this.srpId = srpID; 94 this.srpId = srpID;
92 this.llOptionalTlv = llOptionalTlv; 95 this.llOptionalTlv = llOptionalTlv;
93 } 96 }
...@@ -111,6 +114,11 @@ public class PcepSrpObjectVer1 implements PcepSrpObject { ...@@ -111,6 +114,11 @@ public class PcepSrpObjectVer1 implements PcepSrpObject {
111 this.bRFlag = bRFlag; 114 this.bRFlag = bRFlag;
112 } 115 }
113 116
117 + @Override
118 + public void setSFlag(boolean bSFlag) {
119 + this.bSFlag = bSFlag;
120 + }
121 +
114 /** 122 /**
115 * Returns SRP object header. 123 * Returns SRP object header.
116 * 124 *
...@@ -131,6 +139,11 @@ public class PcepSrpObjectVer1 implements PcepSrpObject { ...@@ -131,6 +139,11 @@ public class PcepSrpObjectVer1 implements PcepSrpObject {
131 } 139 }
132 140
133 @Override 141 @Override
142 + public boolean getSFlag() {
143 + return this.bSFlag;
144 + }
145 +
146 + @Override
134 public void setOptionalTlv(LinkedList<PcepValueType> llOptionalTlv) { 147 public void setOptionalTlv(LinkedList<PcepValueType> llOptionalTlv) {
135 this.llOptionalTlv = llOptionalTlv; 148 this.llOptionalTlv = llOptionalTlv;
136 149
...@@ -153,6 +166,7 @@ public class PcepSrpObjectVer1 implements PcepSrpObject { ...@@ -153,6 +166,7 @@ public class PcepSrpObjectVer1 implements PcepSrpObject {
153 log.debug("SrpObject::read"); 166 log.debug("SrpObject::read");
154 PcepObjectHeader srpObjHeader; 167 PcepObjectHeader srpObjHeader;
155 boolean bRFlag; 168 boolean bRFlag;
169 + boolean bSFlag;
156 170
157 int srpID; 171 int srpID;
158 int flags; 172 int flags;
...@@ -167,12 +181,13 @@ public class PcepSrpObjectVer1 implements PcepSrpObject { ...@@ -167,12 +181,13 @@ public class PcepSrpObjectVer1 implements PcepSrpObject {
167 //take only SrpObject buffer. 181 //take only SrpObject buffer.
168 ChannelBuffer tempCb = cb.readBytes(srpObjHeader.getObjLen() - MINIMUM_COMMON_HEADER_LENGTH); 182 ChannelBuffer tempCb = cb.readBytes(srpObjHeader.getObjLen() - MINIMUM_COMMON_HEADER_LENGTH);
169 flags = tempCb.readInt(); 183 flags = tempCb.readInt();
170 - bRFlag = 0 < flags; 184 + bRFlag = 0 < (flags & 0x1);
185 + bSFlag = 0 < ((flags >> 1) & 0x1);
171 srpID = tempCb.readInt(); 186 srpID = tempCb.readInt();
172 187
173 llOptionalTlv = parseOptionalTlv(tempCb); 188 llOptionalTlv = parseOptionalTlv(tempCb);
174 189
175 - return new PcepSrpObjectVer1(srpObjHeader, bRFlag, srpID, llOptionalTlv); 190 + return new PcepSrpObjectVer1(srpObjHeader, bRFlag, bSFlag, srpID, llOptionalTlv);
176 } 191 }
177 192
178 @Override 193 @Override
...@@ -187,6 +202,7 @@ public class PcepSrpObjectVer1 implements PcepSrpObject { ...@@ -187,6 +202,7 @@ public class PcepSrpObjectVer1 implements PcepSrpObject {
187 byte bFlag; 202 byte bFlag;
188 203
189 bFlag = (bRFlag) ? BBIT_SET : BBIT_RESET; 204 bFlag = (bRFlag) ? BBIT_SET : BBIT_RESET;
205 + bFlag |= (((bSFlag) ? BBIT_SET : BBIT_RESET) << 1);
190 206
191 cb.writeInt(bFlag); 207 cb.writeInt(bFlag);
192 208
...@@ -292,10 +308,12 @@ public class PcepSrpObjectVer1 implements PcepSrpObject { ...@@ -292,10 +308,12 @@ public class PcepSrpObjectVer1 implements PcepSrpObject {
292 private boolean bIsHeaderSet = false; 308 private boolean bIsHeaderSet = false;
293 private boolean bIsSrpIdset = false; 309 private boolean bIsSrpIdset = false;
294 private boolean bIsRFlagSet = false; 310 private boolean bIsRFlagSet = false;
311 + private boolean bIsSFlagSet = false;
295 312
296 private PcepObjectHeader srpObjHeader; 313 private PcepObjectHeader srpObjHeader;
297 private int srpId; 314 private int srpId;
298 private boolean bRFlag; 315 private boolean bRFlag;
316 + private boolean bSFlag;
299 LinkedList<PcepValueType> llOptionalTlv = new LinkedList<>(); 317 LinkedList<PcepValueType> llOptionalTlv = new LinkedList<>();
300 318
301 private boolean bIsPFlagSet = false; 319 private boolean bIsPFlagSet = false;
...@@ -308,7 +326,8 @@ public class PcepSrpObjectVer1 implements PcepSrpObject { ...@@ -308,7 +326,8 @@ public class PcepSrpObjectVer1 implements PcepSrpObject {
308 public PcepSrpObject build() throws PcepParseException { 326 public PcepSrpObject build() throws PcepParseException {
309 PcepObjectHeader srpObjHeader = this.bIsHeaderSet ? this.srpObjHeader : DEFAULT_SRP_OBJECT_HEADER; 327 PcepObjectHeader srpObjHeader = this.bIsHeaderSet ? this.srpObjHeader : DEFAULT_SRP_OBJECT_HEADER;
310 328
311 - boolean bRFlag = this.bIsRFlagSet ? this.bRFlag : DEFAULT_RFLAG; 329 + boolean bRFlag = this.bIsRFlagSet ? this.bRFlag : FLAG_DEFAULT_VALUE;
330 + boolean bSFlag = this.bIsSFlagSet ? this.bSFlag : FLAG_DEFAULT_VALUE;
312 331
313 if (!this.bIsSrpIdset) { 332 if (!this.bIsSrpIdset) {
314 throw new PcepParseException("SrpID not set while building SRP Object."); 333 throw new PcepParseException("SrpID not set while building SRP Object.");
...@@ -322,7 +341,7 @@ public class PcepSrpObjectVer1 implements PcepSrpObject { ...@@ -322,7 +341,7 @@ public class PcepSrpObjectVer1 implements PcepSrpObject {
322 srpObjHeader.setIFlag(bIFlag); 341 srpObjHeader.setIFlag(bIFlag);
323 } 342 }
324 343
325 - return new PcepSrpObjectVer1(srpObjHeader, bRFlag, this.srpId, this.llOptionalTlv); 344 + return new PcepSrpObjectVer1(srpObjHeader, bRFlag, bSFlag, this.srpId, this.llOptionalTlv);
326 } 345 }
327 346
328 @Override 347 @Override
...@@ -362,6 +381,18 @@ public class PcepSrpObjectVer1 implements PcepSrpObject { ...@@ -362,6 +381,18 @@ public class PcepSrpObjectVer1 implements PcepSrpObject {
362 } 381 }
363 382
364 @Override 383 @Override
384 + public boolean getSFlag() {
385 + return this.bSFlag;
386 + }
387 +
388 + @Override
389 + public Builder setSFlag(boolean bSFlag) {
390 + this.bSFlag = bSFlag;
391 + this.bIsSFlagSet = true;
392 + return this;
393 + }
394 +
395 + @Override
365 public Builder setOptionalTlv(LinkedList<PcepValueType> llOptionalTlv) { 396 public Builder setOptionalTlv(LinkedList<PcepValueType> llOptionalTlv) {
366 this.llOptionalTlv = llOptionalTlv; 397 this.llOptionalTlv = llOptionalTlv;
367 return this; 398 return this;
...@@ -392,6 +423,7 @@ public class PcepSrpObjectVer1 implements PcepSrpObject { ...@@ -392,6 +423,7 @@ public class PcepSrpObjectVer1 implements PcepSrpObject {
392 public String toString() { 423 public String toString() {
393 return MoreObjects.toStringHelper(getClass()) 424 return MoreObjects.toStringHelper(getClass())
394 .add("RFlag", bRFlag) 425 .add("RFlag", bRFlag)
426 + .add("SFlag", bSFlag)
395 .add("SRPID", srpId) 427 .add("SRPID", srpId)
396 .add("OptionalTlvList", llOptionalTlv) 428 .add("OptionalTlvList", llOptionalTlv)
397 .toString(); 429 .toString();
......
...@@ -74,6 +74,9 @@ import org.onosproject.provider.pcep.tunnel.impl.PcepAnnotationKeys; ...@@ -74,6 +74,9 @@ import org.onosproject.provider.pcep.tunnel.impl.PcepAnnotationKeys;
74 import org.osgi.service.component.ComponentContext; 74 import org.osgi.service.component.ComponentContext;
75 import org.slf4j.Logger; 75 import org.slf4j.Logger;
76 76
77 +import static org.onosproject.pcep.controller.PcepSyncStatus.IN_SYNC;
78 +import static org.onosproject.pcep.controller.PcepSyncStatus.SYNCED;
79 +import static com.google.common.base.Preconditions.checkNotNull;
77 import static org.slf4j.LoggerFactory.getLogger; 80 import static org.slf4j.LoggerFactory.getLogger;
78 81
79 /** 82 /**
...@@ -188,7 +191,13 @@ public class BgpcepFlowRuleProvider extends AbstractProvider ...@@ -188,7 +191,13 @@ public class BgpcepFlowRuleProvider extends AbstractProvider
188 191
189 //Pushes node labels to the specified device. 192 //Pushes node labels to the specified device.
190 private void pushGlobalNodeLabel(DeviceId deviceId, LabelResourceId labelId, 193 private void pushGlobalNodeLabel(DeviceId deviceId, LabelResourceId labelId,
191 - IpPrefix ipPrefix, Objective.Operation type) throws PcepParseException { 194 + IpPrefix ipPrefix, Objective.Operation type, boolean isBos) throws PcepParseException {
195 +
196 + checkNotNull(deviceId);
197 + checkNotNull(labelId);
198 + checkNotNull(ipPrefix);
199 + checkNotNull(type);
200 +
192 PcepClient pc = getPcepClient(deviceId); 201 PcepClient pc = getPcepClient(deviceId);
193 if (pc == null) { 202 if (pc == null) {
194 log.error("PCEP client not found"); 203 log.error("PCEP client not found");
...@@ -201,7 +210,20 @@ public class BgpcepFlowRuleProvider extends AbstractProvider ...@@ -201,7 +210,20 @@ public class BgpcepFlowRuleProvider extends AbstractProvider
201 .setNodeID(ipPrefix.address().getIp4Address().toInt()) 210 .setNodeID(ipPrefix.address().getIp4Address().toInt())
202 .build(); 211 .build();
203 212
204 - PcepSrpObject srpObj = getSrpObject(pc, type); 213 + boolean bSFlag = false;
214 + if (pc.labelDbSyncStatus() == IN_SYNC) {
215 + if (isBos) {
216 + /*
217 + * Now the sync is completed.
218 + * Need to send label DB end-of-sync msg, i.e. S flag in SRP id is reset.
219 + */
220 + pc.setLabelDbSyncStatus(SYNCED);
221 + } else {
222 + bSFlag = true;
223 + }
224 + }
225 +
226 + PcepSrpObject srpObj = getSrpObject(pc, type, bSFlag);
205 227
206 //Global NODE-SID as label object 228 //Global NODE-SID as label object
207 PcepLabelObject labelObject = pc.factory().buildLabelObject() 229 PcepLabelObject labelObject = pc.factory().buildLabelObject()
...@@ -224,26 +246,35 @@ public class BgpcepFlowRuleProvider extends AbstractProvider ...@@ -224,26 +246,35 @@ public class BgpcepFlowRuleProvider extends AbstractProvider
224 pc.sendMessage(labelMsg); 246 pc.sendMessage(labelMsg);
225 } 247 }
226 248
227 - private PcepSrpObject getSrpObject(PcepClient pc, Objective.Operation type) throws PcepParseException { 249 + private PcepSrpObject getSrpObject(PcepClient pc, Objective.Operation type, boolean bSFlag)
250 + throws PcepParseException {
228 PcepSrpObject srpObj; 251 PcepSrpObject srpObj;
229 - if (type.equals(Objective.Operation.ADD)) { 252 + boolean bRFlag = false;
230 - srpObj = pc.factory().buildSrpObject() 253 +
231 - .setRFlag(false) 254 + if (!type.equals(Objective.Operation.ADD)) {
232 - .setSrpID(SrpIdGenerators.create()) 255 + // To cleanup labels, R bit is set
233 - .build(); 256 + bRFlag = true;
234 - } else { 257 + }
235 - //To cleanup labels, R bit is set 258 +
236 srpObj = pc.factory().buildSrpObject() 259 srpObj = pc.factory().buildSrpObject()
237 - .setRFlag(true) 260 + .setRFlag(bRFlag)
261 + .setSFlag(bSFlag)
238 .setSrpID(SrpIdGenerators.create()) 262 .setSrpID(SrpIdGenerators.create())
239 .build(); 263 .build();
240 - } 264 +
241 return srpObj; 265 return srpObj;
242 } 266 }
243 267
244 //Pushes adjacency labels to the specified device. 268 //Pushes adjacency labels to the specified device.
245 private void pushAdjacencyLabel(DeviceId deviceId, LabelResourceId labelId, 269 private void pushAdjacencyLabel(DeviceId deviceId, LabelResourceId labelId,
246 PortNumber srcPortNum, PortNumber dstPortNum, Objective.Operation type) throws PcepParseException { 270 PortNumber srcPortNum, PortNumber dstPortNum, Objective.Operation type) throws PcepParseException {
271 +
272 + checkNotNull(deviceId);
273 + checkNotNull(labelId);
274 + checkNotNull(srcPortNum);
275 + checkNotNull(dstPortNum);
276 + checkNotNull(type);
277 +
247 PcepClient pc = getPcepClient(deviceId); 278 PcepClient pc = getPcepClient(deviceId);
248 if (pc == null) { 279 if (pc == null) {
249 log.error("PCEP client not found"); 280 log.error("PCEP client not found");
...@@ -262,7 +293,7 @@ public class BgpcepFlowRuleProvider extends AbstractProvider ...@@ -262,7 +293,7 @@ public class BgpcepFlowRuleProvider extends AbstractProvider
262 .seLocalIPv4Address((int) srcPortNo) 293 .seLocalIPv4Address((int) srcPortNo)
263 .build(); 294 .build();
264 295
265 - PcepSrpObject srpObj = getSrpObject(pc, type); 296 + PcepSrpObject srpObj = getSrpObject(pc, type, false);
266 297
267 //Adjacency label object 298 //Adjacency label object
268 PcepLabelObject labelObject = pc.factory().buildLabelObject() 299 PcepLabelObject labelObject = pc.factory().buildLabelObject()
...@@ -290,6 +321,13 @@ public class BgpcepFlowRuleProvider extends AbstractProvider ...@@ -290,6 +321,13 @@ public class BgpcepFlowRuleProvider extends AbstractProvider
290 PortNumber portNum, TunnelId tunnelId, 321 PortNumber portNum, TunnelId tunnelId,
291 Boolean isBos, Long labelType, Objective.Operation type) throws PcepParseException { 322 Boolean isBos, Long labelType, Objective.Operation type) throws PcepParseException {
292 323
324 + checkNotNull(deviceId);
325 + checkNotNull(labelId);
326 + checkNotNull(portNum);
327 + checkNotNull(tunnelId);
328 + checkNotNull(labelType);
329 + checkNotNull(type);
330 +
293 PcepClient pc = getPcepClient(deviceId); 331 PcepClient pc = getPcepClient(deviceId);
294 if (pc == null) { 332 if (pc == null) {
295 log.error("PCEP client not found"); 333 log.error("PCEP client not found");
...@@ -335,7 +373,7 @@ public class BgpcepFlowRuleProvider extends AbstractProvider ...@@ -335,7 +373,7 @@ public class BgpcepFlowRuleProvider extends AbstractProvider
335 //Add OUT label object in case of transit node 373 //Add OUT label object in case of transit node
336 labelObjects.add(labelObj); 374 labelObjects.add(labelObj);
337 375
338 - srpObj = getSrpObject(pc, type); 376 + srpObj = getSrpObject(pc, type, false);
339 377
340 String lspId = tunnel.annotations().value(PcepAnnotationKeys.PLSP_ID); 378 String lspId = tunnel.annotations().value(PcepAnnotationKeys.PLSP_ID);
341 String plspId = tunnel.annotations().value(PcepAnnotationKeys.LOCAL_LSP_ID); 379 String plspId = tunnel.annotations().value(PcepAnnotationKeys.LOCAL_LSP_ID);
......