Mahesh Poojary S
Committed by Gerrit Code Review

[ONOS-2363]Implementation of Open and Error messages.

Change-Id: Id4aa762caf1847a6b5e56517cb159608fd54eefb
Showing 83 changed files with 10916 additions and 0 deletions
1 +/*
2 + * Copyright 2015 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +package org.onosproject.pcepio.protocol.ver1;
17 +
18 +import java.util.LinkedList;
19 +import java.util.ListIterator;
20 +
21 +import org.jboss.netty.buffer.ChannelBuffer;
22 +import org.onosproject.pcepio.exceptions.PcepParseException;
23 +import org.onosproject.pcepio.protocol.PcepError;
24 +import org.onosproject.pcepio.protocol.PcepErrorInfo;
25 +import org.onosproject.pcepio.protocol.PcepErrorObject;
26 +import org.onosproject.pcepio.protocol.PcepRPObject;
27 +import org.onosproject.pcepio.protocol.PcepTEObject;
28 +import org.onosproject.pcepio.types.PcepObjectHeader;
29 +import org.slf4j.Logger;
30 +import org.slf4j.LoggerFactory;
31 +
32 +import com.google.common.base.MoreObjects;
33 +
34 +/**
35 + * Provides PCEP Error Info.
36 + * Reference :PCEP Extension for Transporting TE Data draft-dhodylee-pce-pcep-te-data-extn-02.
37 + */
38 +public class PcepErrorInfoVer1 implements PcepErrorInfo {
39 +
40 + protected static final Logger log = LoggerFactory.getLogger(PcepErrorInfoVer1.class);
41 + //Error list is optional
42 + private LinkedList<PcepError> errList;
43 +
44 + /**
45 + * Constructor to add PCEP error object to the list.
46 + *
47 + * @param llRPObjList list of PCEP RP object
48 + * @param llTEObjList list of PCEP TE object
49 + * @param llErrObjList list of PCEP error object
50 + */
51 + public PcepErrorInfoVer1(LinkedList<PcepRPObject> llRPObjList, LinkedList<PcepTEObject> llTEObjList,
52 + LinkedList<PcepErrorObject> llErrObjList) {
53 + this.errList = new LinkedList<PcepError>();
54 + if ((null != llErrObjList) && (!llErrObjList.isEmpty())) {
55 + this.errList.add(new PcepErrorVer1(llRPObjList, llTEObjList, llErrObjList));
56 + }
57 + }
58 +
59 + /**
60 + * Constructor to initialize error info.
61 + *
62 + * @param errll linked list or pcep error
63 + */
64 + public PcepErrorInfoVer1(LinkedList<PcepError> errll) {
65 + this.errList = errll;
66 + }
67 +
68 + @Override
69 + public boolean isErrorInfoPresent() {
70 + return (!this.errList.isEmpty()) ? true : false;
71 + }
72 +
73 + @Override
74 + public void read(ChannelBuffer cb) throws PcepParseException {
75 + PcepObjectHeader tempObjHeader;
76 +
77 + while (0 < cb.readableBytes()) {
78 + cb.markReaderIndex();
79 + tempObjHeader = PcepObjectHeader.read(cb);
80 + cb.resetReaderIndex();
81 + byte yObjClass = tempObjHeader.getObjClass();
82 + if ((yObjClass != PcepRPObjectVer1.RP_OBJ_CLASS) && (yObjClass != PcepTEObjectVer1.TE_OBJ_CLASS)
83 + && (yObjClass != PcepErrorObjectVer1.ERROR_OBJ_CLASS)) {
84 + throw new PcepParseException("Unknown Object is present in PCEP-ERROR. Object Class: " + yObjClass);
85 + }
86 +
87 + this.errList.add(PcepErrorVer1.read(cb));
88 + }
89 + }
90 +
91 + @Override
92 + public void write(ChannelBuffer cb) throws PcepParseException {
93 + //write <error>
94 + ListIterator<PcepError> listIterator = errList.listIterator();
95 + while (listIterator.hasNext()) {
96 + PcepError pcepError = listIterator.next();
97 +
98 + //RP Object list is optional
99 + LinkedList<PcepRPObject> llRPObjList = pcepError.getRPObjList();
100 + if (llRPObjList != null) {
101 + ListIterator<PcepRPObject> rpListIterator = llRPObjList.listIterator();
102 + while (rpListIterator.hasNext()) {
103 + rpListIterator.next().write(cb);
104 + }
105 + }
106 +
107 + //TE Object list is optional
108 + LinkedList<PcepTEObject> llTEObjList = pcepError.getTEObjList();
109 + if (llTEObjList != null) {
110 + ListIterator<PcepTEObject> teListIterator = llTEObjList.listIterator();
111 + while (teListIterator.hasNext()) {
112 + teListIterator.next().write(cb);
113 + }
114 + }
115 +
116 + // <error-obj-list> is mandatory
117 + boolean bIsErrorObjListFound = false;
118 +
119 + LinkedList<PcepErrorObject> llErrObjList = pcepError.getErrorObjList();
120 + if (llErrObjList != null) {
121 + ListIterator<PcepErrorObject> errObjListIterator = llErrObjList.listIterator();
122 + while (errObjListIterator.hasNext()) {
123 + errObjListIterator.next().write(cb);
124 + bIsErrorObjListFound = true;
125 + }
126 + }
127 +
128 + if (!bIsErrorObjListFound) {
129 + throw new PcepParseException("<error-obj-list> is mandatory.");
130 + }
131 + }
132 + }
133 +
134 + @Override
135 + public LinkedList<Integer> getErrorType() {
136 + LinkedList<Integer> errorType = new LinkedList<Integer>();
137 + ListIterator<PcepError> listIterator = errList.listIterator();
138 + PcepErrorObject errObj;
139 + int error;
140 + while (listIterator.hasNext()) {
141 + PcepError pcepError = listIterator.next();
142 + LinkedList<PcepErrorObject> llErrObjList = pcepError.getErrorObjList();
143 + if (llErrObjList != null) {
144 + ListIterator<PcepErrorObject> errObjListIterator = llErrObjList.listIterator();
145 + while (errObjListIterator.hasNext()) {
146 + errObj = errObjListIterator.next();
147 + error = errObj.getErrorType();
148 + errorType.add(error);
149 + }
150 + }
151 + }
152 + return errorType;
153 + }
154 +
155 + @Override
156 + public LinkedList<Integer> getErrorValue() {
157 + LinkedList<Integer> errorValue = new LinkedList<Integer>();
158 + ListIterator<PcepError> listIterator = errList.listIterator();
159 + PcepErrorObject errObj;
160 + int error;
161 + while (listIterator.hasNext()) {
162 + PcepError pcepError = listIterator.next();
163 + LinkedList<PcepErrorObject> llErrObjList = pcepError.getErrorObjList();
164 + if (llErrObjList != null) {
165 + ListIterator<PcepErrorObject> errObjListIterator = llErrObjList.listIterator();
166 + while (errObjListIterator.hasNext()) {
167 + errObj = errObjListIterator.next();
168 + error = errObj.getErrorValue();
169 + errorValue.add(error);
170 + }
171 + }
172 + }
173 + return errorValue;
174 + }
175 +
176 + /**
177 + * Builder class for PCEP error info.
178 + */
179 + public static class Builder implements PcepErrorInfo.Builder {
180 + private LinkedList<PcepError> errll;
181 +
182 + @Override
183 + public PcepErrorInfo build() {
184 + return new PcepErrorInfoVer1(errll);
185 + }
186 +
187 + @Override
188 + public LinkedList<PcepError> getPcepErrorList() {
189 + return this.errll;
190 + }
191 +
192 + @Override
193 + public Builder setPcepErrorList(LinkedList<PcepError> errll) {
194 + this.errll = errll;
195 + return this;
196 + }
197 + }
198 +
199 + @Override
200 + public String toString() {
201 + return MoreObjects.toStringHelper(getClass()).add("ErrorList", errList).toString();
202 + }
203 +}
1 +package org.onosproject.pcepio.protocol.ver1;
2 +
3 +import java.util.LinkedList;
4 +
5 +import org.jboss.netty.buffer.ChannelBuffer;
6 +import org.onosproject.pcepio.exceptions.PcepParseException;
7 +import org.onosproject.pcepio.protocol.PcepErrorInfo;
8 +import org.onosproject.pcepio.protocol.PcepErrorMsg;
9 +import org.onosproject.pcepio.protocol.PcepErrorObject;
10 +import org.onosproject.pcepio.protocol.PcepMessageReader;
11 +import org.onosproject.pcepio.protocol.PcepMessageWriter;
12 +import org.onosproject.pcepio.protocol.PcepOpenObject;
13 +import org.onosproject.pcepio.protocol.PcepType;
14 +import org.onosproject.pcepio.protocol.PcepVersion;
15 +import org.onosproject.pcepio.types.ErrorObjListWithOpen;
16 +import org.onosproject.pcepio.types.PcepObjectHeader;
17 +import org.slf4j.Logger;
18 +import org.slf4j.LoggerFactory;
19 +
20 +import com.google.common.base.MoreObjects;
21 +import com.google.common.base.MoreObjects.ToStringHelper;
22 +
23 +public class PcepErrorMsgVer1 implements PcepErrorMsg {
24 +
25 + /*
26 + * PCE Error message format.
27 +
28 + <PCErr Message> ::= <Common Header>
29 + ( <error-obj-list> [<Open>] ) | <error>
30 + [<error-list>]
31 +
32 + <error-obj-list> ::=<PCEP-ERROR>[<error-obj-list>]
33 +
34 + <error> ::=[<request-id-list> | <te-id-list>]
35 + <error-obj-list>
36 +
37 + <request-id-list> ::=<RP>[<request-id-list>]
38 +
39 + <te-id-list> ::=<TE>[<te-id-list>]
40 +
41 + <error-list> ::=<error>[<error-list>]
42 + */
43 +
44 + protected static final Logger log = LoggerFactory.getLogger(PcepOpenMsgVer1.class);
45 + public static final byte PACKET_VERSION = 1;
46 + public static final int PACKET_MINIMUM_LENGTH = 12;
47 + public static final PcepType MSG_TYPE = PcepType.ERROR;
48 +
49 + //Below either one should be present.
50 + private ErrorObjListWithOpen errObjListWithOpen; //optional ( <error-obj-list> [<Open>] )
51 + private PcepErrorInfo errInfo; //optional <error> [<error-list>]
52 +
53 + public static final PcepErrorMsgVer1.Reader READER = new Reader();
54 +
55 + /**
56 + * constructor to initialize variables.
57 + */
58 + public PcepErrorMsgVer1() {
59 + errObjListWithOpen = null;
60 + errInfo = null;
61 + }
62 +
63 + /**
64 + * Constructor to initialize variables.
65 + *
66 + * @param errObjListWithOpen error-object-list with open object
67 + * @param errInfo error information
68 + */
69 + public PcepErrorMsgVer1(ErrorObjListWithOpen errObjListWithOpen, PcepErrorInfo errInfo) {
70 + this.errObjListWithOpen = errObjListWithOpen;
71 + this.errInfo = errInfo;
72 + }
73 +
74 + public static class Reader implements PcepMessageReader<PcepErrorMsg> {
75 +
76 + ErrorObjListWithOpen errObjListWithOpen;
77 + PcepErrorInfo errInfo;
78 + PcepObjectHeader tempObjHeader;
79 +
80 + @Override
81 + public PcepErrorMsg readFrom(ChannelBuffer cb) throws PcepParseException {
82 +
83 + errObjListWithOpen = null;
84 + errInfo = null;
85 + tempObjHeader = null;
86 +
87 + if (cb.readableBytes() < PACKET_MINIMUM_LENGTH) {
88 + throw new PcepParseException("Packet size is less than the minimum length.");
89 + }
90 +
91 + byte version = cb.readByte();
92 + version = (byte) (version >> PcepMessageVer1.SHIFT_FLAG);
93 + if (version != PACKET_VERSION) {
94 + throw new PcepParseException("Wrong version: Expected=PcepVersion.PCEP_1(1), got=" + version);
95 + }
96 + // fixed value property type == 1
97 + byte type = cb.readByte();
98 + if (type != MSG_TYPE.getType()) {
99 + throw new PcepParseException("Wrong type: Expected=PcepType.ERROR(6), got=" + type);
100 + }
101 + int length = cb.readShort();
102 + if (length < PACKET_MINIMUM_LENGTH) {
103 + throw new PcepParseException(
104 + "Wrong length: Expected to be >= " + PACKET_MINIMUM_LENGTH + ", was: " + length);
105 + }
106 +
107 + //parse <PCErr Message>
108 + parsePCErrMsg(cb);
109 +
110 + // If other than RP or TE or PCEP-ERROR present then it is error.
111 + if (0 < cb.readableBytes()) {
112 + PcepObjectHeader tempObjHeader = PcepObjectHeader.read(cb);
113 + throw new PcepParseException("Unexpected Object found. Object Class : " + tempObjHeader.getObjClass());
114 + }
115 +
116 + return new PcepErrorMsgVer1(errObjListWithOpen, errInfo);
117 + }
118 +
119 + /**
120 + * Parsing PCErr Message.
121 + *
122 + * @param cb channel buffer.
123 + * @throws PcepParseException if mandatory fields are missing
124 + * output: this.errObjListWithOpen, this.errInfo
125 + */
126 + public void parsePCErrMsg(ChannelBuffer cb) throws PcepParseException {
127 + //If PCEP-ERROR list is followed by OPEN Object then store into ErrorObjListWithOpen.
128 + // ( <error-obj-list> [<Open>]
129 + //If PCEP-ERROR list is followed by RP or TE Object then store into errInfo. <error> [<error-list>]
130 + //If only PCEP-ERROR list is present then store into ErrorObjListWithOpen.
131 + PcepObjectHeader tempObjHeader;
132 + LinkedList<PcepErrorObject> llErrObjList;
133 +
134 + if (0 >= cb.readableBytes()) {
135 + throw new PcepParseException("PCEP-ERROR message came with empty objects.");
136 + }
137 +
138 + //parse PCEP-ERROR list
139 + llErrObjList = new LinkedList<PcepErrorObject>();
140 + tempObjHeader = parseErrorObjectList(llErrObjList, cb);
141 +
142 + //check whether OPEN-OBJECT is present.
143 + if ((tempObjHeader instanceof PcepObjectHeader)
144 + && (tempObjHeader.getObjClass() == PcepOpenObjectVer1.OPEN_OBJ_CLASS)) {
145 +
146 + if (llErrObjList.isEmpty()) {
147 + throw new PcepParseException("<error-obj-list> should be present if OPEN-OBJECT exists");
148 + }
149 +
150 + PcepOpenObject pcepOpenObj = PcepOpenObjectVer1.read(cb);
151 + this.errObjListWithOpen = new ErrorObjListWithOpen(llErrObjList, pcepOpenObj);
152 +
153 + } else if ((tempObjHeader instanceof PcepObjectHeader) //check whether RP or TE Object is present.
154 + && ((tempObjHeader.getObjClass() == PcepRPObjectVer1.RP_OBJ_CLASS)
155 + || (tempObjHeader.getObjClass() == PcepTEObjectVer1.TE_OBJ_CLASS))) {
156 +
157 + this.errInfo = new PcepErrorInfoVer1(null, null, llErrObjList);
158 + this.errInfo.read(cb);
159 +
160 + } else if ((null != llErrObjList) && (!llErrObjList.isEmpty())) {
161 + //If only PCEP-ERROR list is present then store it in errObjListWithOpen.
162 + this.errObjListWithOpen = new ErrorObjListWithOpen(llErrObjList);
163 + } else {
164 + throw new PcepParseException("Empty PCEP-ERROR message.");
165 + }
166 + }
167 +
168 + /**
169 + * Parse error-obj-list.
170 + *
171 + * @param llErrObjList error object list output
172 + * @param cb channel buffer input
173 + * @throws PcepParseException if mandatory fields are missing
174 + * @return error object header
175 + */
176 + public PcepObjectHeader parseErrorObjectList(LinkedList<PcepErrorObject> llErrObjList, ChannelBuffer cb)
177 + throws PcepParseException {
178 + PcepObjectHeader tempObjHeader = null;
179 +
180 + while (0 < cb.readableBytes()) {
181 + cb.markReaderIndex();
182 + tempObjHeader = PcepObjectHeader.read(cb);
183 + cb.resetReaderIndex();
184 + if (tempObjHeader.getObjClass() == PcepErrorObjectVer1.ERROR_OBJ_CLASS) {
185 + llErrObjList.add(PcepErrorObjectVer1.read(cb));
186 + } else {
187 + break;
188 + }
189 + }
190 +
191 + return tempObjHeader;
192 + }
193 + }
194 +
195 + /**
196 + * Builder class for PCEP error message.
197 + */
198 + public static class Builder implements PcepErrorMsg.Builder {
199 + // Pcep error message fields
200 +
201 + private ErrorObjListWithOpen errObjListWithOpen = null; //optional ( <error-obj-list> [<Open>] )
202 + private PcepErrorInfo errInfo = null; //optional <error> [<error-list>]
203 +
204 + @Override
205 + public PcepVersion getVersion() {
206 + return PcepVersion.PCEP_1;
207 + }
208 +
209 + @Override
210 + public PcepType getType() {
211 + return PcepType.ERROR;
212 + }
213 +
214 + @Override
215 + public PcepErrorMsg build() {
216 + return new PcepErrorMsgVer1(this.errObjListWithOpen, this.errInfo);
217 + }
218 +
219 + @Override
220 + public ErrorObjListWithOpen getErrorObjListWithOpen() {
221 + return this.errObjListWithOpen;
222 + }
223 +
224 + @Override
225 + public Builder setErrorObjListWithOpen(ErrorObjListWithOpen errObjListWithOpen) {
226 + this.errObjListWithOpen = errObjListWithOpen;
227 + return this;
228 + }
229 +
230 + @Override
231 + public PcepErrorInfo getPcepErrorInfo() {
232 + return this.errInfo;
233 + }
234 +
235 + @Override
236 + public Builder setPcepErrorInfo(PcepErrorInfo errInfo) {
237 + this.errInfo = errInfo;
238 + return this;
239 + }
240 + }
241 +
242 + @Override
243 + public void writeTo(ChannelBuffer cb) throws PcepParseException {
244 + WRITER.write(cb, this);
245 + }
246 +
247 + public static final Writer WRITER = new Writer();
248 +
249 + static class Writer implements PcepMessageWriter<PcepErrorMsgVer1> {
250 + @Override
251 + public void write(ChannelBuffer cb, PcepErrorMsgVer1 message) throws PcepParseException {
252 + int startIndex = cb.writerIndex();
253 + // first 3 bits set to version
254 + cb.writeByte((byte) (PACKET_VERSION << PcepMessageVer1.SHIFT_FLAG));
255 + // message type 0xC
256 + cb.writeByte(MSG_TYPE.getType());
257 + // length is length of variable message, will be updated at the end
258 + // Store the position of message
259 + // length in buffer
260 + int msgLenIndex = cb.writerIndex();
261 + cb.writeShort(0);
262 + ErrorObjListWithOpen errObjListWithOpen = message.getErrorObjListWithOpen();
263 + PcepErrorInfo errInfo = message.getPcepErrorInfo();
264 +
265 + // write ( <error-obj-list> [<Open>] ) if exists.
266 + // otherwise write <error> [<error-list>]
267 +
268 + if ((errObjListWithOpen instanceof ErrorObjListWithOpen)
269 + && (errObjListWithOpen.isErrorObjListWithOpenPresent())) {
270 + errObjListWithOpen.write(cb);
271 + } else if ((errInfo instanceof PcepErrorInfo) && (errInfo.isErrorInfoPresent())) {
272 + errInfo.write(cb);
273 + } else {
274 + throw new PcepParseException("Empty PCEP-ERROR message.");
275 + }
276 + // PcepErrorMessage message length field
277 + int length = cb.writerIndex() - startIndex;
278 + cb.setShort(msgLenIndex, (short) length);
279 + }
280 + }
281 +
282 + @Override
283 + public PcepVersion getVersion() {
284 + return PcepVersion.PCEP_1;
285 + }
286 +
287 + @Override
288 + public PcepType getType() {
289 + return MSG_TYPE;
290 + }
291 +
292 + @Override
293 + public ErrorObjListWithOpen getErrorObjListWithOpen() {
294 + return this.errObjListWithOpen;
295 + }
296 +
297 + @Override
298 + public void setErrorObjListWithOpen(ErrorObjListWithOpen errObjListWithOpen) {
299 + this.errObjListWithOpen = errObjListWithOpen;
300 + }
301 +
302 + @Override
303 + public PcepErrorInfo getPcepErrorInfo() {
304 + return this.errInfo;
305 + }
306 +
307 + @Override
308 + public void setPcepErrorInfo(PcepErrorInfo errInfo) {
309 + this.errInfo = errInfo;
310 + }
311 +
312 + /**
313 + * Return list of Error types.
314 + *
315 + * @return error types list
316 + */
317 + public LinkedList<Integer> getErrorType() {
318 + LinkedList<Integer> llErrorType = new LinkedList<Integer>();
319 + if ((errObjListWithOpen instanceof ErrorObjListWithOpen)
320 + && (errObjListWithOpen.isErrorObjListWithOpenPresent())) {
321 + llErrorType = errObjListWithOpen.getErrorType();
322 + } else if ((errInfo instanceof PcepErrorInfo) && (errInfo.isErrorInfoPresent())) {
323 + llErrorType = errInfo.getErrorType();
324 + }
325 +
326 + return llErrorType;
327 + }
328 +
329 + /**
330 + * Return list of Error values.
331 + *
332 + * @return error value list
333 + */
334 + public LinkedList<Integer> getErrorValue() {
335 + LinkedList<Integer> llErrorValue = new LinkedList<Integer>();
336 + if ((errObjListWithOpen instanceof ErrorObjListWithOpen)
337 + && (errObjListWithOpen.isErrorObjListWithOpenPresent())) {
338 + llErrorValue = errObjListWithOpen.getErrorValue();
339 + } else if ((errInfo instanceof PcepErrorInfo) && (errInfo.isErrorInfoPresent())) {
340 + llErrorValue = errInfo.getErrorValue();
341 + }
342 +
343 + return llErrorValue;
344 + }
345 +
346 + @Override
347 + public String toString() {
348 + ToStringHelper toStrHelper = MoreObjects.toStringHelper(getClass());
349 +
350 + if ((errObjListWithOpen instanceof ErrorObjListWithOpen)
351 + && (errObjListWithOpen.isErrorObjListWithOpenPresent())) {
352 + toStrHelper.add("ErrorObjectListWithOpen", errObjListWithOpen);
353 + }
354 + if ((errInfo instanceof PcepErrorInfo) && (errInfo.isErrorInfoPresent())) {
355 + toStrHelper.add("ErrorInfo", errInfo);
356 + }
357 +
358 + return toStrHelper.toString();
359 + }
360 +}
1 +package org.onosproject.pcepio.protocol.ver1;
2 +
3 +import java.util.LinkedList;
4 +import java.util.ListIterator;
5 +
6 +import org.jboss.netty.buffer.ChannelBuffer;
7 +import org.onosproject.pcepio.exceptions.PcepParseException;
8 +import org.onosproject.pcepio.protocol.PcepErrorObject;
9 +import org.onosproject.pcepio.types.PcepObjectHeader;
10 +import org.onosproject.pcepio.types.PcepValueType;
11 +import org.slf4j.Logger;
12 +import org.slf4j.LoggerFactory;
13 +
14 +import com.google.common.base.MoreObjects;
15 +
16 +/*
17 +0 1 2 3
18 +0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
19 ++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
20 +| Object-Class | OT |Res|P|I| Object Length (bytes) |
21 ++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
22 +| Reserved | Flags | Error-Type | Error-value |
23 ++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
24 +| |
25 +// Optional TLVs //
26 +| |
27 ++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
28 + */
29 +
30 +public class PcepErrorObjectVer1 implements PcepErrorObject {
31 +
32 + protected static final Logger log = LoggerFactory.getLogger(PcepErrorObjectVer1.class);
33 +
34 + public static final byte ERROR_OBJ_TYPE = 1;
35 + public static final byte ERROR_OBJ_CLASS = 13;
36 + public static final byte ERROR_OBJECT_VERSION = 1;
37 + //ERROR_OBJ_MINIMUM_LENGTH = CommonHeaderLen(4)+ErrorObjectHeaderLen(4)
38 + public static final short ERROR_OBJ_MINIMUM_LENGTH = 8;
39 + public static final int OBJECT_HEADER_LENGTH = 4;
40 +
41 + public static final PcepObjectHeader DEFAULT_ERROR_OBJECT_HEADER = new PcepObjectHeader(ERROR_OBJ_CLASS,
42 + ERROR_OBJ_TYPE, PcepObjectHeader.REQ_OBJ_OPTIONAL_PROCESS, PcepObjectHeader.RSP_OBJ_PROCESSED,
43 + ERROR_OBJ_MINIMUM_LENGTH);
44 +
45 + private PcepObjectHeader errorObjHeader;
46 + private byte yErrorType;
47 + private byte yErrorValue;
48 + private LinkedList<PcepValueType> llOptionalTlv; // Optional TLV
49 +
50 + /**
51 + * Constructor to initialize variables.
52 + *
53 + * @param errorObjHeader ERROR Object header
54 + * @param yErrorType Error Type
55 + * @param yErrorValue Error Value
56 + * @param llOptionalTlv list of optional TLV
57 + */
58 +
59 + public PcepErrorObjectVer1(PcepObjectHeader errorObjHeader, byte yErrorType, byte yErrorValue,
60 + LinkedList<PcepValueType> llOptionalTlv) {
61 + this.errorObjHeader = errorObjHeader;
62 + this.yErrorType = yErrorType;
63 + this.yErrorValue = yErrorValue;
64 + this.llOptionalTlv = llOptionalTlv;
65 + }
66 +
67 + /**
68 + * sets Object Header.
69 + *
70 + * @param obj Error-Object header
71 + */
72 + public void setLspObjHeader(PcepObjectHeader obj) {
73 + this.errorObjHeader = obj;
74 + }
75 +
76 + @Override
77 + public void setErrorType(byte yErrorType) {
78 + this.yErrorType = yErrorType;
79 + }
80 +
81 + @Override
82 + public void setErrorValue(byte yErrorValue) {
83 + this.yErrorValue = yErrorValue;
84 + }
85 +
86 + /**
87 + * returns object header.
88 + *
89 + * @return errorObjHeader Error-Object header
90 + */
91 + public PcepObjectHeader getErrorObjHeader() {
92 + return this.errorObjHeader;
93 + }
94 +
95 + @Override
96 + public int getErrorType() {
97 + return this.yErrorType;
98 + }
99 +
100 + @Override
101 + public byte getErrorValue() {
102 + return this.yErrorValue;
103 + }
104 +
105 + @Override
106 + public LinkedList<PcepValueType> getOptionalTlv() {
107 + return this.llOptionalTlv;
108 + }
109 +
110 + @Override
111 + public void setOptionalTlv(LinkedList<PcepValueType> llOptionalTlv) {
112 + this.llOptionalTlv = llOptionalTlv;
113 + }
114 +
115 + /**
116 + * Reads from channel buffer and returns object of PcepErrorObject.
117 + *
118 + * @param cb of channel buffer.
119 + * @return object of PCEP-ERROR-OBJECT
120 + */
121 + public static PcepErrorObject read(ChannelBuffer cb) {
122 +
123 + PcepObjectHeader errorObjHeader;
124 + byte yErrorType;
125 + byte yErrorValue;
126 + LinkedList<PcepValueType> llOptionalTlv;
127 +
128 + errorObjHeader = PcepObjectHeader.read(cb);
129 +
130 + //take only ErrorObject buffer.
131 + ChannelBuffer tempCb = cb.readBytes(errorObjHeader.getObjLen() - OBJECT_HEADER_LENGTH);
132 + tempCb.readByte(); //ignore Reserved
133 + tempCb.readByte(); //ignore Flags
134 + yErrorType = tempCb.readByte();
135 + yErrorValue = tempCb.readByte();
136 +
137 + llOptionalTlv = parseOptionalTlv(tempCb);
138 +
139 + return new PcepErrorObjectVer1(errorObjHeader, yErrorType, yErrorValue, llOptionalTlv);
140 + }
141 +
142 + /**
143 + * returns Linked list of optional tlvs.
144 + *
145 + * @param cb channel buffer.
146 + * @return Linked list of optional tlvs
147 + */
148 + protected static LinkedList<PcepValueType> parseOptionalTlv(ChannelBuffer cb) {
149 +
150 + LinkedList<PcepValueType> llOutOptionalTlv = new LinkedList<PcepValueType>();
151 +
152 + byte[] yTemp = new byte[cb.readableBytes()];
153 + cb.readBytes(yTemp);
154 +
155 + return llOutOptionalTlv;
156 + }
157 +
158 + @Override
159 + public int write(ChannelBuffer cb) throws PcepParseException {
160 +
161 + //write Object header
162 + int objStartIndex = cb.writerIndex();
163 +
164 + int objLenIndex = errorObjHeader.write(cb);
165 +
166 + if (objLenIndex <= 0) {
167 + throw new PcepParseException("While writing Error Object Header.");
168 + }
169 +
170 + //write Reserved
171 + cb.writeByte(0);
172 + //write Flags
173 + cb.writeByte(0);
174 + //write ErrorType and ErrorValue
175 + cb.writeByte(this.yErrorType);
176 + cb.writeByte(this.yErrorValue);
177 +
178 + // Add optional TLV
179 + packOptionalTlv(cb);
180 +
181 + //Update object length now
182 + int length = cb.writerIndex() - objStartIndex;
183 + //will be helpful during print().
184 + errorObjHeader.setObjLen((short) length);
185 + // As per RFC the length of object should be
186 + // multiples of 4
187 + int pad = length % 4;
188 + if (pad != 0) {
189 + pad = 4 - pad;
190 + for (int i = 0; i < pad; i++) {
191 + cb.writeByte((byte) 0);
192 + }
193 + length = length + pad;
194 + }
195 +
196 + cb.setShort(objLenIndex, (short) length);
197 + return length;
198 + }
199 +
200 + /**
201 + * Pack the Optional tlvs.
202 + *
203 + * @param cb channel buffer.
204 + * @return writer index.
205 + */
206 + protected int packOptionalTlv(ChannelBuffer cb) {
207 +
208 + ListIterator<PcepValueType> listIterator = llOptionalTlv.listIterator();
209 + int startIndex = cb.writerIndex();
210 + while (listIterator.hasNext()) {
211 + PcepValueType tlv = listIterator.next();
212 +
213 + if (null == tlv) {
214 + log.debug("TLV is null from OptionalTlv list");
215 + continue;
216 + }
217 + tlv.write(cb);
218 + }
219 +
220 + return cb.writerIndex() - startIndex;
221 + }
222 +
223 + /**
224 + * Builder class for PCEP error object.
225 + */
226 + public static class Builder implements PcepErrorObject.Builder {
227 +
228 + private boolean bIsHeaderSet = false;
229 +
230 + private PcepObjectHeader errorObjHeader;
231 + private byte yErrorType;
232 + private byte yErrorValue;
233 +
234 + private boolean bIsPFlagSet = false;
235 + private boolean bPFlag;
236 +
237 + private boolean bIsIFlagSet = false;
238 + private boolean bIFlag;
239 +
240 + private LinkedList<PcepValueType> llOptionalTlv = new LinkedList<PcepValueType>();
241 +
242 + @Override
243 + public PcepErrorObject build() {
244 +
245 + PcepObjectHeader errorObjHeader = this.bIsHeaderSet ? this.errorObjHeader : DEFAULT_ERROR_OBJECT_HEADER;
246 +
247 + if (bIsPFlagSet) {
248 + errorObjHeader.setPFlag(bPFlag);
249 + }
250 +
251 + if (bIsIFlagSet) {
252 + errorObjHeader.setIFlag(bIFlag);
253 + }
254 +
255 + return new PcepErrorObjectVer1(errorObjHeader, yErrorType, yErrorValue, llOptionalTlv);
256 + }
257 +
258 + @Override
259 + public PcepObjectHeader getErrorObjHeader() {
260 + return this.errorObjHeader;
261 + }
262 +
263 + @Override
264 + public Builder setErrorObjHeader(PcepObjectHeader obj) {
265 + this.errorObjHeader = obj;
266 + this.bIsHeaderSet = true;
267 + return this;
268 + }
269 +
270 + @Override
271 + public int getErrorType() {
272 + return this.yErrorType;
273 + }
274 +
275 + @Override
276 + public Builder setErrorType(byte value) {
277 + this.yErrorType = value;
278 + return this;
279 + }
280 +
281 + @Override
282 + public byte getErrorValue() {
283 + return this.yErrorValue;
284 + }
285 +
286 + @Override
287 + public Builder setErrorValue(byte value) {
288 + this.yErrorValue = value;
289 + return this;
290 + }
291 +
292 + @Override
293 + public Builder setOptionalTlv(LinkedList<PcepValueType> llOptionalTlv) {
294 + this.llOptionalTlv = llOptionalTlv;
295 + return this;
296 + }
297 +
298 + @Override
299 + public LinkedList<PcepValueType> getOptionalTlv() {
300 + return this.llOptionalTlv;
301 + }
302 +
303 + @Override
304 + public Builder setPFlag(boolean value) {
305 + this.bPFlag = value;
306 + this.bIsPFlagSet = true;
307 + return this;
308 + }
309 +
310 + @Override
311 + public Builder setIFlag(boolean value) {
312 + this.bIFlag = value;
313 + this.bIsIFlagSet = true;
314 + return this;
315 + }
316 + }
317 +
318 + @Override
319 + public String toString() {
320 + return MoreObjects.toStringHelper(getClass()).add("ObjectHeader", errorObjHeader).add("ErrorType", yErrorType)
321 + .add("ErrorValue", yErrorValue).add("OptionalTlv", llOptionalTlv).toString();
322 + }
323 +}
1 +/*
2 + * Copyright 2015 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +package org.onosproject.pcepio.protocol.ver1;
17 +
18 +import java.util.LinkedList;
19 +import java.util.ListIterator;
20 +
21 +import org.jboss.netty.buffer.ChannelBuffer;
22 +import org.onosproject.pcepio.exceptions.PcepParseException;
23 +import org.onosproject.pcepio.protocol.PcepError;
24 +import org.onosproject.pcepio.protocol.PcepErrorObject;
25 +import org.onosproject.pcepio.protocol.PcepRPObject;
26 +import org.onosproject.pcepio.protocol.PcepTEObject;
27 +import org.onosproject.pcepio.types.PcepObjectHeader;
28 +import org.slf4j.Logger;
29 +import org.slf4j.LoggerFactory;
30 +
31 +import com.google.common.base.MoreObjects;
32 +import com.google.common.base.MoreObjects.ToStringHelper;
33 +
34 +/**
35 + * Provides PcepError list which contains RP or TE objects.
36 + * Reference:PCEP Extension for Transporting TE Data draft-dhodylee-pce-pcep-te-data-extn-02.
37 + */
38 +public class PcepErrorVer1 implements PcepError {
39 +
40 + /*
41 + <error>::=[<request-id-list> | <te-id-list>]
42 + <error-obj-list>
43 +
44 + <request-id-list>::=<RP>[<request-id-list>]
45 +
46 + <te-id-list>::=<TE>[<te-id-list>]
47 + */
48 +
49 + protected static final Logger log = LoggerFactory.getLogger(PcepErrorVer1.class);
50 +
51 + private boolean isErroInfoSet;
52 + //PcepErrorObject list
53 + private LinkedList<PcepErrorObject> llErrObjList;
54 + //PcepRPObject list
55 + private LinkedList<PcepRPObject> llRPObjList;
56 + //PcepTEObject list
57 + private LinkedList<PcepTEObject> llTEObjList;
58 + private boolean isTEObjListSet;
59 +
60 + public static final int OBJECT_HEADER_LENGTH = 4;
61 +
62 + /**
63 + * Constructor to initialize variable.
64 + */
65 + public PcepErrorVer1() {
66 + this.llRPObjList = null;
67 + this.llTEObjList = null;
68 + this.llErrObjList = null;
69 + }
70 +
71 + /**
72 + * Constructor to initialize variable.
73 + *
74 + * @param llRPObjList list of PcepRPObject
75 + * @param llTEObjList list of PcepTEObject
76 + * @param llErrObjListObjList list of PcepErrorObject
77 + */
78 + public PcepErrorVer1(LinkedList<PcepRPObject> llRPObjList, LinkedList<PcepTEObject> llTEObjList,
79 + LinkedList<PcepErrorObject> llErrObjListObjList) {
80 + this.llRPObjList = llRPObjList;
81 + this.llTEObjList = llTEObjList;
82 + this.llErrObjList = llErrObjListObjList;
83 + }
84 +
85 + /**
86 + * Constructor to initialize PcepError.
87 + *
88 + * @param llErrObjList list of PcepErrorObject
89 + */
90 + public PcepErrorVer1(LinkedList<PcepErrorObject> llErrObjList) {
91 + this.llRPObjList = null;
92 + this.llTEObjList = null;
93 + this.llErrObjList = llErrObjList;
94 + }
95 +
96 + @Override
97 + public LinkedList<PcepRPObject> getRPObjList() {
98 + return this.llRPObjList;
99 + }
100 +
101 + @Override
102 + public LinkedList<PcepTEObject> getTEObjList() {
103 + return this.llTEObjList;
104 + }
105 +
106 + @Override
107 + public LinkedList<PcepErrorObject> getErrorObjList() {
108 + return this.llErrObjList;
109 + }
110 +
111 + /**
112 + * Parse RP List from the channel buffer.
113 + *
114 + * @throws PcepParseException if mandatory fields are missing
115 + * @param cb of type channel buffer
116 + */
117 + public void parseRPList(ChannelBuffer cb) throws PcepParseException {
118 + byte yObjClass;
119 + byte yObjType;
120 +
121 + llRPObjList = new LinkedList<PcepRPObject>();
122 +
123 + // caller should verify for RP object
124 + if (cb.readableBytes() < OBJECT_HEADER_LENGTH) {
125 + log.debug("Unable to find RP Object");
126 + return;
127 + }
128 +
129 + cb.markReaderIndex();
130 + PcepObjectHeader tempObjHeader = PcepObjectHeader.read(cb);
131 + cb.resetReaderIndex();
132 + yObjClass = tempObjHeader.getObjClass();
133 + yObjType = tempObjHeader.getObjType();
134 + PcepRPObject rpObj;
135 + while ((yObjClass == PcepRPObjectVer1.RP_OBJ_CLASS) && (yObjType == PcepRPObjectVer1.RP_OBJ_TYPE)) {
136 + rpObj = PcepRPObjectVer1.read(cb);
137 + llRPObjList.add(rpObj);
138 +
139 + if (cb.readableBytes() > OBJECT_HEADER_LENGTH) {
140 + cb.markReaderIndex();
141 + tempObjHeader = PcepObjectHeader.read(cb);
142 + cb.resetReaderIndex();
143 + yObjClass = tempObjHeader.getObjClass();
144 + yObjType = tempObjHeader.getObjType();
145 + } else {
146 + break;
147 + }
148 + }
149 + }
150 +
151 + /**
152 + * Parse TE List from the channel buffer.
153 + *
154 + * @param cb of type channel buffer
155 + * @throws PcepParseException if mandatory fields are missing
156 + */
157 + public void parseTEList(ChannelBuffer cb) throws PcepParseException {
158 + byte yObjClass;
159 + byte yObjType;
160 +
161 + llTEObjList = new LinkedList<PcepTEObject>();
162 +
163 + // caller should verify for TE object
164 + if (cb.readableBytes() < OBJECT_HEADER_LENGTH) {
165 + log.debug("Unable to find TE Object");
166 + return;
167 + }
168 +
169 + cb.markReaderIndex();
170 + PcepObjectHeader tempObjHeader = PcepObjectHeader.read(cb);
171 + cb.resetReaderIndex();
172 + yObjClass = tempObjHeader.getObjClass();
173 + yObjType = tempObjHeader.getObjType();
174 + PcepTEObject teObj;
175 + while ((yObjClass == PcepTEObjectVer1.TE_OBJ_CLASS) && ((yObjType == PcepTEObjectVer1.TE_OBJ_TYPE_NODE_VALUE)
176 + || (yObjType == PcepTEObjectVer1.TE_OBJ_TYPE_LINK_VALUE))) {
177 + teObj = PcepTEObjectVer1.read(cb);
178 + llTEObjList.add(teObj);
179 +
180 + if (cb.readableBytes() > OBJECT_HEADER_LENGTH) {
181 + cb.markReaderIndex();
182 + tempObjHeader = PcepObjectHeader.read(cb);
183 + cb.resetReaderIndex();
184 + yObjClass = tempObjHeader.getObjClass();
185 + yObjType = tempObjHeader.getObjType();
186 + } else {
187 + break;
188 + }
189 + }
190 + }
191 +
192 + /**
193 + * parseErrObjList from the channel buffer.
194 + *
195 + * @param cb of type channel buffer
196 + * @throws PcepParseException if mandatory fields are missing
197 + */
198 + public void parseErrObjList(ChannelBuffer cb) throws PcepParseException {
199 + byte yObjClass;
200 + byte yObjType;
201 + boolean bIsErrorObjFound = false;
202 +
203 + llErrObjList = new LinkedList<PcepErrorObject>();
204 +
205 + // caller should verify for RP object
206 + if (cb.readableBytes() < OBJECT_HEADER_LENGTH) {
207 + throw new PcepParseException("Unable to find PCEP-ERROR Object");
208 + }
209 +
210 + cb.markReaderIndex();
211 + PcepObjectHeader tempObjHeader = PcepObjectHeader.read(cb);
212 + cb.resetReaderIndex();
213 + yObjClass = tempObjHeader.getObjClass();
214 + yObjType = tempObjHeader.getObjType();
215 + PcepErrorObject errorObject;
216 + while ((yObjClass == PcepErrorObjectVer1.ERROR_OBJ_CLASS) && (yObjType == PcepErrorObjectVer1.ERROR_OBJ_TYPE)) {
217 + errorObject = PcepErrorObjectVer1.read(cb);
218 + llErrObjList.add(errorObject);
219 + bIsErrorObjFound = true;
220 +
221 + if (cb.readableBytes() > OBJECT_HEADER_LENGTH) {
222 + cb.markReaderIndex();
223 + tempObjHeader = PcepObjectHeader.read(cb);
224 + cb.resetReaderIndex();
225 + yObjClass = tempObjHeader.getObjClass();
226 + yObjType = tempObjHeader.getObjType();
227 + } else {
228 + break;
229 + }
230 + }
231 +
232 + if (!bIsErrorObjFound) {
233 + throw new PcepParseException("At least one PCEP-ERROR Object should be present.");
234 + }
235 + }
236 +
237 + /**
238 + * Reads the byte stream of PcepError from channel buffer.
239 + *
240 + * @param cb of type channel buffer
241 + * @return PcepError error part of PCEP-ERROR
242 + * @throws PcepParseException if mandatory fields are missing
243 + */
244 + public static PcepErrorVer1 read(ChannelBuffer cb) throws PcepParseException {
245 + if (cb.readableBytes() < OBJECT_HEADER_LENGTH) {
246 + throw new PcepParseException("Unknown Object");
247 + }
248 +
249 + PcepErrorVer1 pcepError = new PcepErrorVer1();
250 + // check whether any PCEP Error Info is present
251 + cb.markReaderIndex();
252 + PcepObjectHeader tempObjHeader = PcepObjectHeader.read(cb);
253 + cb.resetReaderIndex();
254 + byte yObjClass = tempObjHeader.getObjClass();
255 +
256 + //If RPlist present then store it.RPList and TEList are optional
257 + if (yObjClass == PcepRPObjectVer1.RP_OBJ_CLASS) {
258 + log.debug("RP_LIST");
259 + pcepError.parseRPList(cb);
260 + yObjClass = checkNextObject(cb);
261 + } else if (yObjClass == PcepTEObjectVer1.TE_OBJ_CLASS) {
262 + log.debug("TE_LIST");
263 + pcepError.parseTEList(cb);
264 + yObjClass = checkNextObject(cb);
265 + }
266 +
267 + if (yObjClass == PcepErrorObjectVer1.ERROR_OBJ_CLASS) {
268 + log.debug("PCEP-ERROR obj list");
269 + pcepError.parseErrObjList(cb);
270 + yObjClass = checkNextObject(cb);
271 + }
272 +
273 + return pcepError;
274 + }
275 +
276 + /**
277 + * Checks Next Object.
278 + *
279 + * @param cb of type channel buffer.
280 + * @return object type class.
281 + */
282 + private static byte checkNextObject(ChannelBuffer cb) {
283 + if (cb.readableBytes() < OBJECT_HEADER_LENGTH) {
284 + return 0;
285 + }
286 + cb.markReaderIndex();
287 + PcepObjectHeader tempObjHeader = PcepObjectHeader.read(cb);
288 + cb.resetReaderIndex();
289 + return tempObjHeader.getObjClass();
290 + }
291 +
292 + /**
293 + * Writes the byte stream of PCEP error to the channel buffer.
294 + *
295 + * @param cb of type channel buffer
296 + * @return object length index
297 + * @throws PcepParseException if mandatory fields are missing
298 + */
299 + @Override
300 + public int write(ChannelBuffer cb) throws PcepParseException {
301 + int iLenStartIndex = cb.writerIndex();
302 +
303 + // RPlist is optional
304 + if (this.isErroInfoSet) {
305 + ListIterator<PcepRPObject> rpObjlistIterator = this.llRPObjList.listIterator();
306 + while (rpObjlistIterator.hasNext()) {
307 + rpObjlistIterator.next().write(cb);
308 + }
309 + }
310 +
311 + // TElist is optional
312 + if (this.isTEObjListSet) {
313 + ListIterator<PcepTEObject> teObjlistIterator = this.llTEObjList.listIterator();
314 + while (teObjlistIterator.hasNext()) {
315 + teObjlistIterator.next().write(cb);
316 + }
317 + }
318 + //ErrList is mandatory
319 + ListIterator<PcepErrorObject> errlistIterator = this.llErrObjList.listIterator();
320 + while (errlistIterator.hasNext()) {
321 + errlistIterator.next().write(cb);
322 + }
323 +
324 + return cb.writerIndex() - iLenStartIndex;
325 + }
326 +
327 + /**
328 + * Builder for error part of PCEP-ERROR.
329 + */
330 + public static class Builder implements PcepError.Builder {
331 +
332 + private LinkedList<PcepRPObject> llRPObjList;
333 + private LinkedList<PcepTEObject> llTEObjList;
334 + private LinkedList<PcepErrorObject> llErrObjList;
335 +
336 + @Override
337 + public PcepError build() {
338 + return new PcepErrorVer1(llRPObjList, llTEObjList, llErrObjList);
339 + }
340 +
341 + @Override
342 + public LinkedList<PcepRPObject> getRPObjList() {
343 + return this.llRPObjList;
344 + }
345 +
346 + @Override
347 + public Builder setRPObjList(LinkedList<PcepRPObject> llRPObjList) {
348 + this.llRPObjList = llRPObjList;
349 + return this;
350 + }
351 +
352 + @Override
353 + public LinkedList<PcepTEObject> getTEObjList() {
354 + return this.llTEObjList;
355 + }
356 +
357 + @Override
358 + public Builder setTEObjList(LinkedList<PcepTEObject> llTEObjList) {
359 + this.llTEObjList = llTEObjList;
360 + return this;
361 + }
362 +
363 + @Override
364 + public LinkedList<PcepErrorObject> getErrorObjList() {
365 + return this.llErrObjList;
366 + }
367 +
368 + @Override
369 + public Builder setErrorObjList(LinkedList<PcepErrorObject> llErrObjList) {
370 + this.llErrObjList = llErrObjList;
371 + return this;
372 + }
373 +
374 + }
375 +
376 + @Override
377 + public void setRPObjList(LinkedList<PcepRPObject> llRPObjList) {
378 + this.llRPObjList = llRPObjList;
379 + }
380 +
381 + @Override
382 + public void setTEObjList(LinkedList<PcepTEObject> llTEObjList) {
383 + this.llTEObjList = llTEObjList;
384 + }
385 +
386 + @Override
387 + public void setErrorObjList(LinkedList<PcepErrorObject> llErrObjList) {
388 + this.llErrObjList = llErrObjList;
389 + }
390 +
391 + @Override
392 + public String toString() {
393 + ToStringHelper toStrHelper = MoreObjects.toStringHelper(getClass());
394 +
395 + //RP Object list is optional
396 + if (null != llRPObjList) {
397 + toStrHelper.add("RpObjectList", llRPObjList);
398 + }
399 +
400 + //TE Object list is optional
401 + if (null != llTEObjList) {
402 + toStrHelper.add("TeObjectList", llTEObjList);
403 + }
404 +
405 + //Error Object List is mandatory
406 + return toStrHelper.add("ErrorObjectList", llErrObjList).toString();
407 + }
408 +}
1 +/*
2 + * Copyright 2015 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +
17 +package org.onosproject.pcepio.protocol.ver1;
18 +
19 +import org.jboss.netty.buffer.ChannelBuffer;
20 +import org.onosproject.pcepio.exceptions.PcepParseException;
21 +import org.onosproject.pcepio.protocol.PcepMessageReader;
22 +import org.onosproject.pcepio.protocol.PcepMessageWriter;
23 +import org.onosproject.pcepio.protocol.PcepOpenMsg;
24 +import org.onosproject.pcepio.protocol.PcepOpenObject;
25 +import org.onosproject.pcepio.protocol.PcepType;
26 +import org.onosproject.pcepio.protocol.PcepVersion;
27 +import org.onosproject.pcepio.types.PcepErrorDetailInfo;
28 +import org.slf4j.Logger;
29 +import org.slf4j.LoggerFactory;
30 +
31 +import com.google.common.base.MoreObjects;
32 +
33 +public class PcepOpenMsgVer1 implements PcepOpenMsg {
34 +
35 + /*
36 + * <Open Message>::= <Common Header> <OPEN>
37 + 0 1 2 3
38 + 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
39 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
40 + | Ver | Flags | Message-Type | Message-Length |
41 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
42 + | Object-Class | OT |Res|P|I| Object Length (bytes) |
43 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
44 + | Ver | Flags | Keepalive | DeadTimer | SID |
45 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
46 + | |
47 + // Optional TLVs //
48 + | |
49 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
50 + */
51 +
52 + protected static final Logger log = LoggerFactory.getLogger(PcepOpenMsgVer1.class);
53 +
54 + public static final byte PACKET_VERSION = 1;
55 + public static final int PACKET_MINIMUM_LENGTH = 12;
56 + public static final PcepType MSG_TYPE = PcepType.OPEN;
57 + private PcepOpenObject pcepOpenObj;
58 +
59 + public static final PcepOpenMsgVer1.Reader READER = new Reader();
60 +
61 + /**
62 + * Constructor to initialize PcepOpenObject.
63 + *
64 + * @param pcepOpenObj PCEP-OPEN-OBJECT
65 + */
66 + public PcepOpenMsgVer1(PcepOpenObject pcepOpenObj) {
67 + this.pcepOpenObj = pcepOpenObj;
68 + }
69 +
70 + @Override
71 + public PcepOpenObject getPcepOpenObject() {
72 + return this.pcepOpenObj;
73 + }
74 +
75 + @Override
76 + public void setPcepOpenObject(PcepOpenObject pcepOpenObj) {
77 + this.pcepOpenObj = pcepOpenObj;
78 + }
79 +
80 + @Override
81 + public PcepVersion getVersion() {
82 + return PcepVersion.PCEP_1;
83 + }
84 +
85 + @Override
86 + public PcepType getType() {
87 + return MSG_TYPE;
88 + }
89 +
90 + public static class Reader implements PcepMessageReader<PcepOpenMsg> {
91 +
92 + @Override
93 + public PcepOpenMsg readFrom(ChannelBuffer cb) throws PcepParseException {
94 +
95 + if (cb.readableBytes() < PACKET_MINIMUM_LENGTH) {
96 + throw new PcepParseException("Packet size is less than the minimum length.");
97 + }
98 +
99 + byte version = cb.readByte();
100 + version = (byte) (version >> PcepMessageVer1.SHIFT_FLAG);
101 + if (version != PACKET_VERSION) {
102 + log.error("[readFrom] Invalid version: " + version);
103 + throw new PcepParseException(PcepErrorDetailInfo.ERROR_TYPE_1, PcepErrorDetailInfo.ERROR_VALUE_1);
104 + }
105 + // fixed value property type == 1
106 + byte type = cb.readByte();
107 +
108 + if (type != MSG_TYPE.getType()) {
109 + log.error("[readFrom] Unexpected type: " + type);
110 + throw new PcepParseException(PcepErrorDetailInfo.ERROR_TYPE_1, PcepErrorDetailInfo.ERROR_VALUE_1);
111 + }
112 + int length = cb.readShort();
113 + if (length < PACKET_MINIMUM_LENGTH) {
114 + throw new PcepParseException(
115 + "Wrong length: Expected to be >= " + PACKET_MINIMUM_LENGTH + ", was: " + length);
116 + }
117 + return new PcepOpenMsgVer1(PcepOpenObjectVer1.read(cb));
118 + }
119 + }
120 +
121 + /**
122 + * Builder class for PCEP open message.
123 + */
124 + static class Builder implements PcepOpenMsg.Builder {
125 +
126 + private PcepOpenObject pcepOpenObj;
127 +
128 + @Override
129 + public PcepOpenMsg build() throws PcepParseException {
130 + if (!(pcepOpenObj instanceof PcepOpenObjectVer1)) {
131 + throw new NullPointerException("PcepOpenObject is null.");
132 + }
133 + return new PcepOpenMsgVer1(pcepOpenObj);
134 + }
135 +
136 + @Override
137 + public PcepVersion getVersion() {
138 + return PcepVersion.PCEP_1;
139 + }
140 +
141 + @Override
142 + public PcepType getType() {
143 + return PcepType.OPEN;
144 + }
145 +
146 + @Override
147 + public PcepOpenObject getPcepOpenObj() {
148 + return this.pcepOpenObj;
149 + }
150 +
151 + @Override
152 + public Builder setPcepOpenObj(PcepOpenObject obj) {
153 + this.pcepOpenObj = obj;
154 + return this;
155 + }
156 + }
157 +
158 + @Override
159 + public void writeTo(ChannelBuffer cb) throws PcepParseException {
160 + WRITER.write(cb, this);
161 + }
162 +
163 + public static final Writer WRITER = new Writer();
164 +
165 + public static class Writer implements PcepMessageWriter<PcepOpenMsgVer1> {
166 +
167 + @Override
168 + public void write(ChannelBuffer cb, PcepOpenMsgVer1 message) throws PcepParseException {
169 + int startIndex = cb.writerIndex();
170 + // first 3 bits set to version
171 + cb.writeByte((byte) (PACKET_VERSION << PcepMessageVer1.SHIFT_FLAG));
172 + // message type
173 + cb.writeByte(MSG_TYPE.getType());
174 + // length is length of variable message, will be updated at the end
175 + // Store the position of message
176 + // length in buffer
177 +
178 + int msgLenIndex = cb.writerIndex();
179 + cb.writeShort(0);
180 +
181 + message.getPcepOpenObject().write(cb);
182 +
183 + // update message length field
184 + int iLength = cb.writerIndex() - startIndex;
185 + cb.setShort(msgLenIndex, (short) iLength);
186 + }
187 + }
188 +
189 + @Override
190 + public String toString() {
191 + return MoreObjects.toStringHelper(getClass()).add("OpenObject", pcepOpenObj).toString();
192 + }
193 +}
1 +/*
2 + * Copyright 2015 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +
17 +package org.onosproject.pcepio.protocol.ver1;
18 +
19 +import java.util.LinkedList;
20 +import java.util.ListIterator;
21 +
22 +import org.jboss.netty.buffer.ChannelBuffer;
23 +import org.onosproject.pcepio.exceptions.PcepParseException;
24 +import org.onosproject.pcepio.protocol.PcepOpenObject;
25 +import org.onosproject.pcepio.protocol.PcepType;
26 +import org.onosproject.pcepio.protocol.PcepVersion;
27 +import org.onosproject.pcepio.types.GmplsCapabilityTlv;
28 +import org.onosproject.pcepio.types.PceccCapabilityTlv;
29 +import org.onosproject.pcepio.types.PcepLabelDbVerTlv;
30 +import org.onosproject.pcepio.types.PcepObjectHeader;
31 +import org.onosproject.pcepio.types.PcepValueType;
32 +import org.onosproject.pcepio.types.StatefulLspDbVerTlv;
33 +import org.onosproject.pcepio.types.StatefulPceCapabilityTlv;
34 +import org.onosproject.pcepio.types.TedCapabilityTlv;
35 +import org.slf4j.Logger;
36 +import org.slf4j.LoggerFactory;
37 +
38 +import com.google.common.base.MoreObjects;
39 +
40 +/*
41 + message format.
42 + 0 1 2 3
43 + 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
44 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
45 + | Object-Class | OT |Res|P|I| Object Length (bytes) |
46 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
47 + | Ver | Flags | Keepalive | DeadTimer | SID |
48 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
49 + | |
50 + // Optional TLVs //
51 + | |
52 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
53 +
54 + The OPEN Object format
55 + */
56 +
57 +public class PcepOpenObjectVer1 implements PcepOpenObject {
58 +
59 + protected static final Logger log = LoggerFactory.getLogger(PcepOpenObjectVer1.class);
60 +
61 + public static final PcepType MSG_TYPE = PcepType.OPEN;
62 + public static final byte OPEN_OBJECT_VERSION = 1;
63 + public static final byte OPEN_OBJ_TYPE = 1;
64 + public static final byte OPEN_OBJ_CLASS = 1;
65 + public static final byte DEFAULT_KEEPALIVE_TIME = 30;
66 + public static final byte DEFAULT_DEAD_TIME = 120;
67 + public static final short OPEN_OBJ_MINIMUM_LENGTH = 8;
68 + public static final int DEFAULT_GMPLS_CAPABILITY_TLV_IVALUE = 0X0;
69 + public static final int DEFAULT_STATEFUL_PCE_CAPABILITY_TLV_IVALUE = 0xf;
70 + public static final int DEFAULT_PCECC_CAPABILITY_TLV_IVALUE = 0x7;
71 + public static final int DEFAULT_PCEP_LABEL_DB_VER_TLV_IVALUE = 0X0;
72 +
73 + public static final PcepObjectHeader DEFAULT_OPEN_HEADER = new PcepObjectHeader(OPEN_OBJ_CLASS, OPEN_OBJ_TYPE,
74 + PcepObjectHeader.REQ_OBJ_OPTIONAL_PROCESS, PcepObjectHeader.RSP_OBJ_PROCESSED, OPEN_OBJ_MINIMUM_LENGTH);
75 +
76 + private PcepObjectHeader openObjHeader;
77 + private byte keepAliveTime;
78 + private byte deadTime;
79 + private byte sessionId;
80 + private LinkedList<PcepValueType> llOptionalTlv;
81 +
82 + /**
83 + * Default constructor.
84 + */
85 + public PcepOpenObjectVer1() {
86 + this.openObjHeader = null;
87 + this.keepAliveTime = 0;
88 + this.deadTime = 0;
89 + this.sessionId = 0;
90 + this.llOptionalTlv = null;
91 + }
92 +
93 + /**
94 + * Constructor to initialize all member variables.
95 + *
96 + * @param openObjHeader Open Object Header
97 + * @param keepAliveTime Keepalive timer value
98 + * @param deadTime Dead timer value
99 + * @param sessionID session id
100 + * @param llOptionalTlv Optional TLV
101 + */
102 + public PcepOpenObjectVer1(PcepObjectHeader openObjHeader, byte keepAliveTime, byte deadTime, byte sessionID,
103 + LinkedList<PcepValueType> llOptionalTlv) {
104 + this.openObjHeader = openObjHeader;
105 + this.keepAliveTime = keepAliveTime;
106 + this.deadTime = deadTime;
107 + this.sessionId = sessionID;
108 + this.llOptionalTlv = llOptionalTlv;
109 + }
110 +
111 + @Override
112 + public PcepObjectHeader getOpenObjHeader() {
113 + return this.openObjHeader;
114 + }
115 +
116 + @Override
117 + public void setOpenObjHeader(PcepObjectHeader obj) {
118 + this.openObjHeader = obj;
119 + }
120 +
121 + @Override
122 + public byte getKeepAliveTime() {
123 + return this.keepAliveTime;
124 + }
125 +
126 + @Override
127 + public void setKeepAliveTime(byte value) {
128 + this.keepAliveTime = value;
129 + }
130 +
131 + @Override
132 + public PcepVersion getVersion() {
133 + return PcepVersion.PCEP_1;
134 + }
135 +
136 + @Override
137 + public byte getDeadTime() {
138 + return this.deadTime;
139 + }
140 +
141 + @Override
142 + public void setDeadTime(byte value) {
143 + this.deadTime = value;
144 + }
145 +
146 + @Override
147 + public byte getSessionId() {
148 + return this.sessionId;
149 + }
150 +
151 + @Override
152 + public void setSessionId(byte value) {
153 + this.sessionId = value;
154 + }
155 +
156 + @Override
157 + public LinkedList<PcepValueType> getOptionalTlv() {
158 + return this.llOptionalTlv;
159 + }
160 +
161 + @Override
162 + public void setOptionalTlv(LinkedList<PcepValueType> llOptionalTlv) {
163 + this.llOptionalTlv = llOptionalTlv;
164 + }
165 +
166 + /**
167 + * Reads from channel buffer and returns object of PcepOpenObject.
168 + *
169 + * @param cb of type channel buffer
170 + * @return object of PcepOpenObject
171 + * @throws PcepParseException if mandatory fields are missing
172 + */
173 + public static PcepOpenObject read(ChannelBuffer cb) throws PcepParseException {
174 +
175 + PcepObjectHeader openObjHeader;
176 + byte version;
177 + byte keepAliveTime;
178 + byte deadTime;
179 + byte sessionID;
180 + LinkedList<PcepValueType> llOptionalTlv;
181 +
182 + openObjHeader = PcepObjectHeader.read(cb);
183 + version = cb.readByte();
184 + version = (byte) (version >> PcepMessageVer1.SHIFT_FLAG);
185 + if (version != OPEN_OBJECT_VERSION) {
186 + throw new PcepParseException("Wrong version: Expected=PcepVersion.PCEP_1(1), got=" + version);
187 + }
188 + /* Keepalive */
189 + keepAliveTime = cb.readByte();
190 +
191 + /* DeadTimer */
192 + deadTime = cb.readByte();
193 +
194 + /* SID */
195 + sessionID = cb.readByte();
196 +
197 + // Optional TLV
198 + llOptionalTlv = parseOptionalTlv(cb);
199 +
200 + return new PcepOpenObjectVer1(openObjHeader, keepAliveTime, deadTime, sessionID, llOptionalTlv);
201 + }
202 +
203 + /**
204 + * Returns linkedlist of optional tlvs.
205 + *
206 + * @param cb of type channel buffer
207 + * @return llOptionalTlv Optional TLV
208 + * @throws PcepParseException if mandatory fields are missing
209 + */
210 + protected static LinkedList<PcepValueType> parseOptionalTlv(ChannelBuffer cb) throws PcepParseException {
211 +
212 + LinkedList<PcepValueType> llOptionalTlv;
213 +
214 + llOptionalTlv = new LinkedList<PcepValueType>();
215 +
216 + while (4 <= cb.readableBytes()) {
217 + PcepValueType tlv;
218 + short hType = cb.readShort();
219 + short hLength = cb.readShort();
220 +
221 + switch (hType) {
222 + case GmplsCapabilityTlv.TYPE:
223 + log.debug("GmplsCapabilityTlv");
224 + if (GmplsCapabilityTlv.LENGTH != hLength) {
225 + throw new PcepParseException("Invalid length received for Gmpls_Capability_Tlv.");
226 + }
227 + int iValue = cb.readInt();
228 + tlv = new GmplsCapabilityTlv(iValue);
229 + break;
230 + case StatefulPceCapabilityTlv.TYPE:
231 + log.debug("StatefulPceCapabilityTlv");
232 + if (StatefulPceCapabilityTlv.LENGTH != hLength) {
233 + throw new PcepParseException("Invalid length received for StatefulPceCapabilityTlv.");
234 + }
235 + tlv = StatefulPceCapabilityTlv.read(cb);
236 + break;
237 + case PceccCapabilityTlv.TYPE:
238 + log.debug("PceccCapabilityTlv");
239 + if (PceccCapabilityTlv.LENGTH != hLength) {
240 + throw new PcepParseException("Invalid length for PceccCapabilityTlv.");
241 + }
242 + iValue = cb.readInt();
243 + tlv = new PceccCapabilityTlv(iValue);
244 + break;
245 + case StatefulLspDbVerTlv.TYPE:
246 + log.debug("StatefulLspDbVerTlv");
247 + if (StatefulLspDbVerTlv.LENGTH != hLength) {
248 + throw new PcepParseException("Invalid length received for StatefulLspDbVerTlv.");
249 + }
250 + long lValue = cb.readLong();
251 + tlv = new StatefulLspDbVerTlv(lValue);
252 + break;
253 + case TedCapabilityTlv.TYPE:
254 + log.debug("TedCapabilityTlv");
255 + if (TedCapabilityTlv.LENGTH != hLength) {
256 + throw new PcepParseException("Invalid length received for TedCapabilityTlv.");
257 + }
258 + iValue = cb.readInt();
259 + tlv = new TedCapabilityTlv(iValue);
260 + break;
261 + case PcepLabelDbVerTlv.TYPE:
262 + log.debug("PcepLabelDbVerTlv");
263 + if (PcepLabelDbVerTlv.LENGTH != hLength) {
264 + throw new PcepParseException("Invalid length received for PcepLabelDbVerTlv.");
265 + }
266 + lValue = cb.readLong();
267 + tlv = new PcepLabelDbVerTlv(lValue);
268 + break;
269 + default:
270 + log.debug("Unsupported TLV: " + hType);
271 + cb.skipBytes(hLength);
272 + continue;
273 + }
274 +
275 + llOptionalTlv.add(tlv);
276 + }
277 +
278 + if (0 < cb.readableBytes()) {
279 + throw new PcepParseException("Optional Tlv parsing error. Extra bytes received.");
280 + }
281 +
282 + return llOptionalTlv;
283 + }
284 +
285 + @Override
286 + public int write(ChannelBuffer cb) throws PcepParseException {
287 +
288 + int objStartIndex = cb.writerIndex();
289 +
290 + //write common header
291 + int objLenIndex = openObjHeader.write(cb);
292 +
293 + if (objLenIndex <= 0) {
294 + throw new PcepParseException("Unable to write Open object header.");
295 + }
296 +
297 + cb.writeByte((byte) (OPEN_OBJECT_VERSION << PcepMessageVer1.SHIFT_FLAG));
298 + cb.writeByte(this.keepAliveTime);
299 + cb.writeByte(this.deadTime);
300 + cb.writeByte(this.sessionId);
301 +
302 + //Pack optional TLV
303 + packOptionalTlv(cb);
304 +
305 + //now write OPEN Object Length
306 + int length = cb.writerIndex() - objStartIndex;
307 + cb.setShort(objLenIndex, (short) length);
308 + //will be helpful during print().
309 + this.openObjHeader.setObjLen((short) length);
310 +
311 + return length;
312 + }
313 +
314 + /**
315 + * Returns writer index.
316 + *
317 + * @param cb of type channel buffer.
318 + * @return writer index
319 + */
320 + protected int packOptionalTlv(ChannelBuffer cb) {
321 + int startIndex = cb.writerIndex();
322 +
323 + LinkedList<PcepValueType> llOptionalTlv = this.llOptionalTlv;
324 + ListIterator<PcepValueType> listIterator = llOptionalTlv.listIterator();
325 + while (listIterator.hasNext()) {
326 + PcepValueType tlv = listIterator.next();
327 + if (null == tlv) {
328 + log.debug("TLV is null from OptionalTlv list");
329 + continue;
330 + }
331 +
332 + tlv.write(cb);
333 +
334 + // need to take care of padding
335 + int pad = tlv.getLength() % 4;
336 +
337 + if (0 != pad) {
338 + pad = 4 - pad;
339 + for (int i = 0; i < pad; ++i) {
340 + cb.writeByte((byte) 0);
341 + }
342 + }
343 + }
344 +
345 + return cb.writerIndex() - startIndex;
346 + }
347 +
348 + public static class Builder implements PcepOpenObject.Builder {
349 + // Pcep open message fields
350 + private boolean bIsHeaderSet = false;
351 + private PcepObjectHeader openObjHeader;
352 + private boolean bIsKeepAliveTimeSet = false;
353 + private byte keepAliveTime;
354 + private boolean bIsDeadTimeSet = false;
355 + private byte deadTime;
356 + private boolean bIsSessionIDSet = false;
357 + private byte sessionID;
358 + private boolean bIsOptionalTlvSet = false;
359 + private LinkedList<PcepValueType> llOptionalTlv = new LinkedList<PcepValueType>();
360 +
361 + private boolean bIsPFlagSet = false;
362 + private boolean bPFlag;
363 +
364 + private boolean bIsIFlagSet = false;
365 + private boolean bIFlag;
366 +
367 + @Override
368 + public PcepOpenObject build() throws PcepParseException {
369 + PcepObjectHeader openObjHeader = this.bIsHeaderSet ? this.openObjHeader : DEFAULT_OPEN_HEADER;
370 + byte keepAliveTime = this.bIsKeepAliveTimeSet ? this.keepAliveTime : DEFAULT_KEEPALIVE_TIME;
371 + byte deadTime = this.bIsDeadTimeSet ? this.deadTime : DEFAULT_DEAD_TIME;
372 +
373 + if (!this.bIsSessionIDSet) {
374 + throw new PcepParseException("SessionID is not set (mandatory)");
375 + }
376 + if (!this.bIsOptionalTlvSet) {
377 + //Add tlv to list
378 + //Add GmplsCapabilityTlv
379 + PcepValueType tlv;
380 + int iValue = DEFAULT_GMPLS_CAPABILITY_TLV_IVALUE;
381 + tlv = new GmplsCapabilityTlv(iValue);
382 + this.llOptionalTlv.add(tlv);
383 +
384 + //Add StatefulPceCapabilityTlv
385 + iValue = DEFAULT_STATEFUL_PCE_CAPABILITY_TLV_IVALUE;
386 + tlv = new StatefulPceCapabilityTlv(iValue);
387 + this.llOptionalTlv.add(tlv);
388 +
389 + }
390 +
391 + if (bIsPFlagSet) {
392 + openObjHeader.setPFlag(bPFlag);
393 + }
394 +
395 + if (bIsIFlagSet) {
396 + openObjHeader.setIFlag(bIFlag);
397 + }
398 +
399 + return new PcepOpenObjectVer1(openObjHeader, keepAliveTime, deadTime, this.sessionID, this.llOptionalTlv);
400 + }
401 +
402 + @Override
403 + public PcepObjectHeader getOpenObjHeader() {
404 + return this.openObjHeader;
405 + }
406 +
407 + @Override
408 + public Builder setOpenObjHeader(PcepObjectHeader obj) {
409 + this.openObjHeader = obj;
410 + this.bIsHeaderSet = true;
411 + return this;
412 + }
413 +
414 + @Override
415 + public byte getKeepAliveTime() {
416 + return this.keepAliveTime;
417 + }
418 +
419 + @Override
420 + public Builder setKeepAliveTime(byte value) {
421 + this.keepAliveTime = value;
422 + this.bIsKeepAliveTimeSet = true;
423 + return this;
424 + }
425 +
426 + @Override
427 + public byte getDeadTime() {
428 + return this.deadTime;
429 + }
430 +
431 + @Override
432 + public Builder setDeadTime(byte value) {
433 + this.deadTime = value;
434 + this.bIsDeadTimeSet = true;
435 + return this;
436 + }
437 +
438 + @Override
439 + public byte getSessionId() {
440 + return this.sessionID;
441 + }
442 +
443 + @Override
444 + public Builder setSessionId(byte value) {
445 + this.sessionID = value;
446 + this.bIsSessionIDSet = true;
447 + return this;
448 + }
449 +
450 + @Override
451 + public Builder setOptionalTlv(LinkedList<PcepValueType> llOptionalTlv) {
452 + this.llOptionalTlv = llOptionalTlv;
453 + this.bIsOptionalTlvSet = true;
454 + return this;
455 + }
456 +
457 + @Override
458 + public LinkedList<PcepValueType> getOptionalTlv() {
459 + return this.llOptionalTlv;
460 + }
461 +
462 + @Override
463 + public Builder setPFlag(boolean value) {
464 + this.bPFlag = value;
465 + this.bIsPFlagSet = true;
466 + return this;
467 + }
468 +
469 + @Override
470 + public Builder setIFlag(boolean value) {
471 + this.bIFlag = value;
472 + this.bIsIFlagSet = true;
473 + return this;
474 + }
475 + }
476 +
477 + @Override
478 + public String toString() {
479 + return MoreObjects.toStringHelper(getClass()).add("ObjectHeader", openObjHeader)
480 + .add("Keepalive", keepAliveTime).add("DeadTimer", deadTime).add("SessionId", sessionId)
481 + .add("OptionalTlv", llOptionalTlv).toString();
482 + }
483 +}
1 +/*
2 + * Copyright 2015 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +package org.onosproject.pcepio.protocol.ver1;
17 +
18 +import java.util.LinkedList;
19 +import java.util.ListIterator;
20 +
21 +import org.jboss.netty.buffer.ChannelBuffer;
22 +import org.onosproject.pcepio.exceptions.PcepParseException;
23 +import org.onosproject.pcepio.protocol.PcepRPObject;
24 +import org.onosproject.pcepio.types.PcepObjectHeader;
25 +import org.onosproject.pcepio.types.PcepValueType;
26 +import org.slf4j.Logger;
27 +import org.slf4j.LoggerFactory;
28 +
29 +import com.google.common.base.MoreObjects;
30 +
31 +public class PcepRPObjectVer1 implements PcepRPObject {
32 +
33 + /*
34 + * RP Object.
35 + 0 1 2 3
36 + 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
37 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
38 + | Flags |O|B|R| Pri |
39 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
40 + | Request-ID-number |
41 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
42 + | |
43 + // Optional TLVs //
44 + | |
45 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
46 + */
47 +
48 + protected static final Logger log = LoggerFactory.getLogger(PcepRPObjectVer1.class);
49 +
50 + public static final byte RP_OBJ_TYPE = 1;
51 + public static final byte RP_OBJ_CLASS = 2;
52 + public static final byte RP_OBJECT_VERSION = 1;
53 + public static final short RP_OBJ_MINIMUM_LENGTH = 12;
54 +
55 + public static final int DEFAULT_REQUEST_ID_NUM = 0;
56 + //Signalled , all default values to be checked.
57 + public static final boolean DEFAULT_OFLAG = false;
58 + public static final boolean DEFAULT_BFLAG = false;
59 + public static final boolean DEFAULT_RFLAG = false;
60 + public static final byte DEFAULT_PRIFLAG = 0;
61 + public static final int OBJECT_HEADER_LENGTH = 4;
62 + public static final int OFLAG_SHIFT_VALUE = 5;
63 + public static final int BFLAG_SHIFT_VALUE = 4;
64 + public static final int RFLAG_SHIFT_VALUE = 3;
65 + public static final int OFLAG_TEMP_SHIFT_VALUE = 0x20;
66 + public static final int BFLAG_TEMP_SHIFT_VALUE = 0x10;
67 + public static final int RFLAG_TEMP_SHIFT_VALUE = 0x08;
68 + public static final int PRIFLAG_TEMP_SHIFT_VALUE = 0x07;
69 + public static final int BIT_SET = 1;
70 + public static final int BIT_RESET = 0;
71 + public static final int MINIMUM_COMMON_HEADER_LENGTH = 4;
72 +
73 + public static final PcepObjectHeader DEFAULT_RP_OBJECT_HEADER = new PcepObjectHeader(RP_OBJ_CLASS, RP_OBJ_TYPE,
74 + PcepObjectHeader.REQ_OBJ_OPTIONAL_PROCESS, PcepObjectHeader.RSP_OBJ_PROCESSED, RP_OBJ_MINIMUM_LENGTH);
75 +
76 + private PcepObjectHeader rpObjHeader;
77 + private int iRequestIdNum;
78 + private boolean bOFlag;
79 + private boolean bBFlag;
80 + private boolean bRFlag;
81 + private byte yPriFlag; // 3bytes
82 + private LinkedList<PcepValueType> llOptionalTlv;
83 +
84 + /**
85 + * Constructor to initialize variables.
86 + *
87 + * @param rpObjHeader RP-OBJECT header
88 + * @param iRequestIdNum Request-ID-number
89 + * @param bOFlag O-flag
90 + * @param bBFlag B-flag
91 + * @param bRFlag R-flag
92 + * @param yPriFlag Pri-flag
93 + * @param llOptionalTlv linked list of Optional TLV
94 + */
95 + public PcepRPObjectVer1(PcepObjectHeader rpObjHeader, int iRequestIdNum, boolean bOFlag, boolean bBFlag,
96 + boolean bRFlag, byte yPriFlag, LinkedList<PcepValueType> llOptionalTlv) {
97 + this.rpObjHeader = rpObjHeader;
98 + this.iRequestIdNum = iRequestIdNum;
99 + this.bOFlag = bOFlag;
100 + this.bBFlag = bBFlag;
101 + this.bRFlag = bRFlag;
102 + this.yPriFlag = yPriFlag;
103 + this.llOptionalTlv = llOptionalTlv;
104 + }
105 +
106 + /**
107 + * Sets RP Object header.
108 + *
109 + * @param obj RP Object header
110 + */
111 + public void setRPObjHeader(PcepObjectHeader obj) {
112 + this.rpObjHeader = obj;
113 + }
114 +
115 + @Override
116 + public void setRequestIdNum(int iRequestIdNum) {
117 + this.iRequestIdNum = iRequestIdNum;
118 + }
119 +
120 + @Override
121 + public void setOFlag(boolean bOFlag) {
122 + this.bOFlag = bOFlag;
123 + }
124 +
125 + @Override
126 + public void setBFlag(boolean bBFlag) {
127 + this.bBFlag = bBFlag;
128 + }
129 +
130 + @Override
131 + public void setRFlag(boolean bRFlag) {
132 + this.bRFlag = bRFlag;
133 + }
134 +
135 + @Override
136 + public void setPriFlag(byte yPriFlag) {
137 + this.yPriFlag = yPriFlag;
138 + }
139 +
140 + /**
141 + * Returns RP Object header.
142 + *
143 + * @return rpObjHeader
144 + */
145 + public PcepObjectHeader getRPObjHeader() {
146 + return this.rpObjHeader;
147 + }
148 +
149 + @Override
150 + public int getRequestIdNum() {
151 + return this.iRequestIdNum;
152 + }
153 +
154 + @Override
155 + public boolean getOFlag() {
156 + return this.bOFlag;
157 + }
158 +
159 + @Override
160 + public boolean getBFlag() {
161 + return this.bBFlag;
162 + }
163 +
164 + @Override
165 + public boolean getRFlag() {
166 + return this.bRFlag;
167 + }
168 +
169 + @Override
170 + public byte getPriFlag() {
171 + return this.yPriFlag;
172 + }
173 +
174 + /**
175 + * Reads the channel buffer and returns the object of PcepRPObject.
176 + *
177 + * @param cb of type channel buffer
178 + * @return the object of PcepRPObject
179 + * @throws PcepParseException if mandatory fields are missing
180 + */
181 + public static PcepRPObject read(ChannelBuffer cb) throws PcepParseException {
182 + log.debug("read");
183 + PcepObjectHeader rpObjHeader;
184 + int iRequestIdNum;
185 + boolean bOFlag;
186 + boolean bBFlag;
187 + boolean bRFlag;
188 + byte yPriFlag; // 3bytes
189 + LinkedList<PcepValueType> llOptionalTlv = new LinkedList<PcepValueType>();
190 +
191 + rpObjHeader = PcepObjectHeader.read(cb);
192 +
193 + //take only LspObject buffer.
194 + ChannelBuffer tempCb = cb.readBytes(rpObjHeader.getObjLen() - OBJECT_HEADER_LENGTH);
195 +
196 + int iTemp = tempCb.readInt();
197 + yPriFlag = (byte) (iTemp & PRIFLAG_TEMP_SHIFT_VALUE);
198 + bOFlag = (iTemp & OFLAG_TEMP_SHIFT_VALUE) == OFLAG_TEMP_SHIFT_VALUE ? true : false;
199 + bBFlag = (iTemp & BFLAG_TEMP_SHIFT_VALUE) == BFLAG_TEMP_SHIFT_VALUE ? true : false;
200 + bRFlag = (iTemp & RFLAG_TEMP_SHIFT_VALUE) == RFLAG_TEMP_SHIFT_VALUE ? true : false;
201 +
202 + iRequestIdNum = tempCb.readInt();
203 +
204 + // parse optional TLV
205 + llOptionalTlv = parseOptionalTlv(tempCb);
206 +
207 + return new PcepRPObjectVer1(rpObjHeader, iRequestIdNum, bOFlag, bBFlag, bRFlag, yPriFlag, llOptionalTlv);
208 + }
209 +
210 + @Override
211 + public int write(ChannelBuffer cb) throws PcepParseException {
212 +
213 + //write Object header
214 + int objStartIndex = cb.writerIndex();
215 +
216 + int objLenIndex = rpObjHeader.write(cb);
217 +
218 + if (objLenIndex <= 0) {
219 + throw new PcepParseException("ObjectLength Index is " + objLenIndex);
220 + }
221 + int iTemp;
222 + iTemp = (yPriFlag);
223 +
224 + iTemp = (bOFlag) ? (iTemp | OFLAG_SHIFT_VALUE) : iTemp;
225 + iTemp = (bBFlag) ? (iTemp | BFLAG_SHIFT_VALUE) : iTemp;
226 + iTemp = (bRFlag) ? (iTemp | RFLAG_SHIFT_VALUE) : iTemp;
227 +
228 + cb.writeInt(iTemp);
229 + cb.writeInt(iRequestIdNum);
230 +
231 + // Add optional TLV
232 + packOptionalTlv(cb);
233 +
234 + //Update object length now
235 + int length = cb.writerIndex() - objStartIndex;
236 +
237 + //will be helpful during print().
238 + rpObjHeader.setObjLen((short) length);
239 +
240 + cb.setShort(objLenIndex, (short) length);
241 + return cb.writerIndex();
242 + }
243 +
244 + /**
245 + * Returns list of optional tlvs.
246 + *
247 + * @param cb of type channel buffer.
248 + * @return llOutOptionalTlv linked list of Optional TLV
249 + * @throws PcepParseException if mandatory fields are missing
250 + */
251 + protected static LinkedList<PcepValueType> parseOptionalTlv(ChannelBuffer cb) throws PcepParseException {
252 +
253 + LinkedList<PcepValueType> llOutOptionalTlv = new LinkedList<PcepValueType>();
254 + //Currently no optional TLvs, will be added based on requirements.
255 + return llOutOptionalTlv;
256 + }
257 +
258 + /**
259 + * Returns optional tlvs.
260 + *
261 + * @param cb of type channel buffer
262 + * @return llOptionalTlv linked list of Optional TLV
263 + */
264 + protected int packOptionalTlv(ChannelBuffer cb) {
265 +
266 + ListIterator<PcepValueType> listIterator = llOptionalTlv.listIterator();
267 + while (listIterator.hasNext()) {
268 + listIterator.next().write(cb);
269 + }
270 +
271 + return cb.writerIndex();
272 + }
273 +
274 + public static class Builder implements PcepRPObject.Builder {
275 +
276 + private boolean bIsHeaderSet = false;
277 + private boolean bIsRequestIdNumSet = false;
278 + private boolean bIsOFlagSet = false;
279 + private boolean bIsRFlagset = false;
280 + private boolean bIsBFlagSet = false;
281 + private boolean bIsPriFlagSet = false;
282 +
283 + private PcepObjectHeader rpObjHeader;
284 + private int requestIdNum;
285 + private boolean bOFlag;
286 + private boolean bBFlag;
287 + private boolean bRFlag;
288 + private byte yPriFlag;
289 + private LinkedList<PcepValueType> llOptionalTlv = new LinkedList<PcepValueType>();
290 +
291 + private boolean bIsPFlagSet = false;
292 + private boolean bPFlag;
293 +
294 + private boolean bIsIFlagSet = false;
295 + private boolean bIFlag;
296 +
297 + @Override
298 + public PcepRPObject build() {
299 + PcepObjectHeader lspObjHeader = this.bIsHeaderSet ? this.rpObjHeader : DEFAULT_RP_OBJECT_HEADER;
300 +
301 + int requestIdNum = this.bIsRequestIdNumSet ? this.requestIdNum : DEFAULT_REQUEST_ID_NUM;
302 + boolean bOFlag = this.bIsOFlagSet ? this.bOFlag : DEFAULT_OFLAG;
303 + boolean bBFlag = this.bIsBFlagSet ? this.bBFlag : DEFAULT_BFLAG;
304 + boolean bRFlag = this.bIsRFlagset ? this.bRFlag : DEFAULT_RFLAG;
305 + byte yPriFlag = this.bIsPriFlagSet ? this.yPriFlag : DEFAULT_PRIFLAG;
306 +
307 + if (bIsPFlagSet) {
308 + lspObjHeader.setPFlag(bPFlag);
309 + }
310 +
311 + if (bIsIFlagSet) {
312 + lspObjHeader.setIFlag(bIFlag);
313 + }
314 +
315 + return new PcepRPObjectVer1(lspObjHeader, requestIdNum, bOFlag, bBFlag, bRFlag, yPriFlag, llOptionalTlv);
316 + }
317 +
318 + @Override
319 + public PcepObjectHeader getRPObjHeader() {
320 + return this.rpObjHeader;
321 + }
322 +
323 + @Override
324 + public Builder setRPObjHeader(PcepObjectHeader obj) {
325 + this.rpObjHeader = obj;
326 + this.bIsHeaderSet = true;
327 + return this;
328 + }
329 +
330 + @Override
331 + public int getRequestIdNum() {
332 + return this.requestIdNum;
333 + }
334 +
335 + @Override
336 + public Builder setRequestIdNum(int value) {
337 + this.requestIdNum = value;
338 + this.bIsRequestIdNumSet = true;
339 + return this;
340 + }
341 +
342 + @Override
343 + public Builder setOFlag(boolean value) {
344 + this.bOFlag = value;
345 + this.bIsOFlagSet = true;
346 + return this;
347 + }
348 +
349 + @Override
350 + public boolean getBFlag() {
351 + return this.bBFlag;
352 + }
353 +
354 + @Override
355 + public Builder setBFlag(boolean value) {
356 + this.bBFlag = value;
357 + this.bIsBFlagSet = true;
358 + return this;
359 + }
360 +
361 + @Override
362 + public boolean getRFlag() {
363 + return this.bRFlag;
364 + }
365 +
366 + @Override
367 + public Builder setRFlag(boolean value) {
368 + this.bRFlag = value;
369 + this.bIsRFlagset = true;
370 + return this;
371 + }
372 +
373 + @Override
374 + public byte getPriFlag() {
375 + return this.yPriFlag;
376 + }
377 +
378 + @Override
379 + public Builder setPriFlag(byte value) {
380 + this.yPriFlag = value;
381 + this.bIsPriFlagSet = true;
382 + return this;
383 + }
384 +
385 + @Override
386 + public Builder setOptionalTlv(LinkedList<PcepValueType> llOptionalTlv) {
387 + this.llOptionalTlv = llOptionalTlv;
388 + return this;
389 + }
390 +
391 + @Override
392 + public LinkedList<PcepValueType> getOptionalTlv() {
393 + return this.llOptionalTlv;
394 + }
395 +
396 + @Override
397 + public Builder setPFlag(boolean value) {
398 + this.bPFlag = value;
399 + this.bIsPFlagSet = true;
400 + return this;
401 + }
402 +
403 + @Override
404 + public Builder setIFlag(boolean value) {
405 + this.bIFlag = value;
406 + this.bIsIFlagSet = true;
407 + return this;
408 + }
409 +
410 + @Override
411 + public boolean getOFlag() {
412 + return this.bOFlag;
413 + }
414 +
415 + }
416 +
417 + @Override
418 + public LinkedList<PcepValueType> getOptionalTlv() {
419 + return this.llOptionalTlv;
420 + }
421 +
422 + @Override
423 + public void setOptionalTlv(LinkedList<PcepValueType> llOptionalTlv) {
424 + this.llOptionalTlv = llOptionalTlv;
425 + }
426 +
427 + @Override
428 + public String toString() {
429 + return MoreObjects.toStringHelper(getClass()).add("ObjectHeader", rpObjHeader).add("OFlag", (bOFlag) ? 1 : 0)
430 + .add("BFlag", (bBFlag) ? 1 : 0).add("RFlag", (bRFlag) ? 1 : 0).add("PriFlag", yPriFlag)
431 + .add("RequestIdNumber", iRequestIdNum).add("OptionalTlv", llOptionalTlv).toString();
432 + }
433 +}
1 +/*
2 + * Copyright 2015 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +
17 +package org.onosproject.pcepio.protocol.ver1;
18 +
19 +import java.util.LinkedList;
20 +import java.util.ListIterator;
21 +
22 +import org.jboss.netty.buffer.ChannelBuffer;
23 +import org.onosproject.pcepio.exceptions.PcepParseException;
24 +import org.onosproject.pcepio.protocol.PcepTEObject;
25 +import org.onosproject.pcepio.types.LocalTENodeDescriptorsTLV;
26 +import org.onosproject.pcepio.types.PcepObjectHeader;
27 +import org.onosproject.pcepio.types.PcepValueType;
28 +import org.onosproject.pcepio.types.RemoteTENodeDescriptorsTLV;
29 +import org.onosproject.pcepio.types.RoutingUniverseTLV;
30 +import org.onosproject.pcepio.types.TELinkAttributesTlv;
31 +import org.onosproject.pcepio.types.TELinkDescriptorsTLV;
32 +import org.onosproject.pcepio.types.TENodeAttributesTlv;
33 +import org.slf4j.Logger;
34 +import org.slf4j.LoggerFactory;
35 +
36 +import com.google.common.base.MoreObjects;
37 +
38 +public class PcepTEObjectVer1 implements PcepTEObject {
39 + /*
40 + *
41 + reference: PCEP Extension for Transporting TE Data draft-dhodylee-pce-pcep-te-data-extn-02.
42 + TE Object-Class is [TBD6].
43 +
44 + Two Object-Type values are defined for the TE object:
45 +
46 + o TE Node: TE Object-Type is 1.
47 +
48 + o TE Link: TE Object-Type is 2.
49 +
50 + The format of the TE object body is as follows:
51 +
52 + 0 1 2 3
53 + 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
54 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
55 + | Protocol-ID | Flag |R|S|
56 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
57 + | TE-ID |
58 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
59 + // TLVs //
60 + | |
61 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
62 + */
63 +
64 + protected static final Logger log = LoggerFactory.getLogger(PcepTEObjectVer1.class);
65 +
66 + public static final byte TE_OBJ_TYPE_NODE_VALUE = 1;
67 + public static final byte TE_OBJ_TYPE_LINK_VALUE = 2;
68 +
69 + public static final byte TE_OBJ_CLASS = 101; //TBD6 in RFC.
70 + public static final byte TE_OBJECT_VERSION = 1;
71 +
72 + // TE_OBJ_MINIMUM_LENGTH = TEObjectHeaderLen(4)+ TEObjectLen(8)
73 + public static final short TE_OBJ_MINIMUM_LENGTH = 12;
74 +
75 + // Signaled ,all default values to be checked.
76 + public static final byte DEFAULT_PROTOCOL_ID = 1; //IS-IS Level 1
77 + public static final boolean DEFAULT_R_FLAG = false;
78 + public static final boolean DEFAULT_S_FLAG = false;
79 + public static final int DEFAULT_TE_ID = 0;
80 +
81 + public static final int OBJECT_HEADER_LENGTH = 4;
82 + public static final int RIGHT_SHIFT_ONE = 1;
83 + public static final int RIGHT_FIRST_FLAG = 0x1;
84 + public static final int FLAG_SET_R_FLAG = 0x2;
85 + public static final int FLAG_SET_S_FLAG = 0x1;
86 + public static final int MINIMUM_COMMON_HEADER_LENGTH = 4;
87 + public static final int MINIMUM_TLV_HEADER_LENGTH = 4;
88 +
89 + public static final PcepObjectHeader DEFAULT_TE_OBJECT_HEADER = new PcepObjectHeader(TE_OBJ_CLASS,
90 + TE_OBJ_TYPE_NODE_VALUE, PcepObjectHeader.REQ_OBJ_OPTIONAL_PROCESS, PcepObjectHeader.RSP_OBJ_PROCESSED,
91 + TE_OBJ_MINIMUM_LENGTH);
92 +
93 + private PcepObjectHeader teObjHeader;
94 + private byte yProtocolId;
95 + // 2-flags
96 + private boolean bRFlag;
97 + private boolean bSFlag;
98 + private int iTEId;
99 + // Optional TLV
100 + private LinkedList<PcepValueType> llOptionalTlv;
101 +
102 + /**
103 + * Constructor to initialize variables.
104 + *
105 + * @param teObjHeader TE Object header
106 + * @param yProtocolId Protocol-ID
107 + * @param bRFlag R-flag
108 + * @param bSFlag S-flag
109 + * @param iTEId TE-ID
110 + * @param llOptionalTlv linked list of Optional TLV
111 + */
112 + public PcepTEObjectVer1(PcepObjectHeader teObjHeader, byte yProtocolId, boolean bRFlag, boolean bSFlag, int iTEId,
113 + LinkedList<PcepValueType> llOptionalTlv) {
114 +
115 + this.teObjHeader = teObjHeader;
116 + this.yProtocolId = yProtocolId;
117 + this.bRFlag = bRFlag;
118 + this.bSFlag = bSFlag;
119 + this.iTEId = iTEId;
120 + this.llOptionalTlv = llOptionalTlv;
121 + }
122 +
123 + @Override
124 + public PcepObjectHeader getTEObjHeader() {
125 + return this.teObjHeader;
126 + }
127 +
128 + @Override
129 + public void setTEObjHeader(PcepObjectHeader obj) {
130 + this.teObjHeader = obj;
131 + }
132 +
133 + @Override
134 + public byte getProtocolId() {
135 + return this.yProtocolId;
136 + }
137 +
138 + @Override
139 + public void setProtocolId(byte yProtId) {
140 + this.yProtocolId = yProtId;
141 + }
142 +
143 + @Override
144 + public boolean getRFlag() {
145 + return this.bRFlag;
146 + }
147 +
148 + @Override
149 + public void setRFlag(boolean bRFlag) {
150 + this.bRFlag = bRFlag;
151 + }
152 +
153 + @Override
154 + public boolean getSFlag() {
155 + return this.bSFlag;
156 + }
157 +
158 + @Override
159 + public void setSFlag(boolean bSFlag) {
160 + this.bSFlag = bSFlag;
161 + }
162 +
163 + @Override
164 + public int getTEId() {
165 + return this.iTEId;
166 + }
167 +
168 + @Override
169 + public void setTEId(int iTEId) {
170 + this.iTEId = iTEId;
171 + }
172 +
173 + @Override
174 + public LinkedList<PcepValueType> getOptionalTlv() {
175 + return this.llOptionalTlv;
176 + }
177 +
178 + @Override
179 + public void setOptionalTlv(LinkedList<PcepValueType> llOptionalTlv) {
180 + this.llOptionalTlv = llOptionalTlv;
181 + }
182 +
183 + /**
184 + * Reads from the channel buffer and returns Object of PcepTEObject.
185 + *
186 + * @param cb of type channel buffer
187 + * @return Object of PcepTEObject
188 + * @throws PcepParseException if mandatory fields are missing
189 + */
190 + public static PcepTEObject read(ChannelBuffer cb) throws PcepParseException {
191 + log.debug("read");
192 +
193 + PcepObjectHeader teObjHeader;
194 + byte yProtocolId;
195 + // 2-flags
196 + boolean bRFlag;
197 + boolean bSFlag;
198 + int iTEId;
199 + LinkedList<PcepValueType> llOptionalTlv;
200 +
201 + teObjHeader = PcepObjectHeader.read(cb);
202 +
203 + //take only TEObject buffer.
204 + ChannelBuffer tempCb = cb.readBytes(teObjHeader.getObjLen() - OBJECT_HEADER_LENGTH);
205 +
206 + yProtocolId = tempCb.readByte();
207 + //ignore first two bytes of Flags
208 + tempCb.readShort();
209 +
210 + Integer iTemp = (int) tempCb.readByte(); //read 3rd byte Flag
211 + bSFlag = ((iTemp & FLAG_SET_S_FLAG) == FLAG_SET_S_FLAG) ? true : false;
212 + bRFlag = ((iTemp & FLAG_SET_R_FLAG) == FLAG_SET_R_FLAG) ? true : false;
213 +
214 + iTEId = tempCb.readInt();
215 +
216 + // parse optional TLV
217 + llOptionalTlv = parseOptionalTlv(tempCb);
218 +
219 + return new PcepTEObjectVer1(teObjHeader, yProtocolId, bRFlag, bSFlag, iTEId, llOptionalTlv);
220 + }
221 +
222 + @Override
223 + public int write(ChannelBuffer cb) throws PcepParseException {
224 +
225 + //write Object header
226 + int objStartIndex = cb.writerIndex();
227 + int objLenIndex = teObjHeader.write(cb);
228 +
229 + if (objLenIndex <= 0) {
230 + throw new PcepParseException("ObjectLength Index is " + objLenIndex);
231 + }
232 +
233 + //write Protocol ID
234 + cb.writeByte(this.yProtocolId);
235 +
236 + //write Flag
237 + cb.writeShort(0);
238 +
239 + byte bTemp = 0;
240 + if (bSFlag) {
241 + bTemp = FLAG_SET_S_FLAG;
242 + }
243 +
244 + if (bRFlag) {
245 + bTemp = (byte) (bTemp | FLAG_SET_R_FLAG);
246 + }
247 + cb.writeByte(bTemp);
248 +
249 + //write TEId
250 + cb.writeInt(iTEId);
251 +
252 + // Add optional TLV
253 + packOptionalTlv(cb);
254 +
255 + //Update object length now
256 + int length = cb.writerIndex() - objStartIndex;
257 +
258 + //will be helpful during print().
259 + teObjHeader.setObjLen((short) length);
260 +
261 + cb.setShort(objLenIndex, (short) length);
262 +
263 + return cb.writerIndex();
264 + }
265 +
266 + /**
267 + * Returns Linked list of PCEP Value Type.
268 + *
269 + * @param cb of channel buffer
270 + * @return Linked list of PCEP Value Type
271 + * @throws PcepParseException if mandatory fields are missing
272 + */
273 + protected static LinkedList<PcepValueType> parseOptionalTlv(ChannelBuffer cb) throws PcepParseException {
274 +
275 + LinkedList<PcepValueType> llOutOptionalTlv;
276 +
277 + llOutOptionalTlv = new LinkedList<PcepValueType>();
278 +
279 + while (MINIMUM_TLV_HEADER_LENGTH <= cb.readableBytes()) {
280 +
281 + PcepValueType tlv;
282 + short hType = cb.readShort();
283 + short hLength = cb.readShort();
284 + long lValue = 0;
285 +
286 + switch (hType) {
287 +
288 + case RoutingUniverseTLV.TYPE:
289 + lValue = cb.readLong();
290 + tlv = new RoutingUniverseTLV(lValue);
291 + break;
292 + case LocalTENodeDescriptorsTLV.TYPE:
293 + tlv = LocalTENodeDescriptorsTLV.read(cb, hLength);
294 + break;
295 + case RemoteTENodeDescriptorsTLV.TYPE:
296 + RemoteTENodeDescriptorsTLV.hLength = hLength;
297 + tlv = RemoteTENodeDescriptorsTLV.read(cb);
298 + break;
299 + case TELinkDescriptorsTLV.TYPE:
300 + tlv = TELinkDescriptorsTLV.read(cb, hLength);
301 + break;
302 + case TENodeAttributesTlv.TYPE:
303 + tlv = TENodeAttributesTlv.read(cb, hLength);
304 + break;
305 + case TELinkAttributesTlv.TYPE:
306 + tlv = TELinkAttributesTlv.read(cb, hLength);
307 + break;
308 + default:
309 + throw new PcepParseException("Unsupported TLV type :" + hType);
310 + }
311 +
312 + // Check for the padding
313 + int pad = hLength % 4;
314 + if (0 < pad) {
315 + pad = 4 - pad;
316 + if (pad <= cb.readableBytes()) {
317 + cb.skipBytes(pad);
318 + }
319 + }
320 +
321 + llOutOptionalTlv.add(tlv);
322 + }
323 +
324 + if (0 < cb.readableBytes()) {
325 +
326 + throw new PcepParseException("Optional Tlv parsing error. Extra bytes received.");
327 + }
328 +
329 + return llOutOptionalTlv;
330 + }
331 +
332 + /**
333 + * Returns the writer index.
334 + *
335 + * @param cb of type channel buffer
336 + * @return the writer index.
337 + */
338 + protected int packOptionalTlv(ChannelBuffer cb) {
339 +
340 + ListIterator<PcepValueType> listIterator = llOptionalTlv.listIterator();
341 +
342 + while (listIterator.hasNext()) {
343 + PcepValueType tlv = listIterator.next();
344 +
345 + if (null == tlv) {
346 + log.debug("TLV is null from OptionalTlv list");
347 + continue;
348 + }
349 + tlv.write(cb);
350 +
351 + // need to take care of padding
352 + int pad = tlv.getLength() % 4;
353 +
354 + if (0 != pad) {
355 + pad = 4 - pad;
356 + for (int i = 0; i < pad; ++i) {
357 + cb.writeByte((byte) 0);
358 + }
359 + }
360 + }
361 +
362 + return cb.writerIndex();
363 + }
364 +
365 + public static class Builder implements PcepTEObject.Builder {
366 + private boolean bIsHeaderSet = false;
367 + private boolean bIsProtocolIdSet = false;
368 + private boolean bIsRFlagSet = false;
369 + private boolean bIsSFlagSet = false;
370 + private boolean bIsTEIdSet = false;
371 +
372 + private PcepObjectHeader teObjHeader;
373 + private byte yProtocolId;
374 + private boolean bRFlag;
375 + private boolean bSFlag;
376 + private int iTEId;
377 + private LinkedList<PcepValueType> llOptionalTlv = new LinkedList<PcepValueType>();
378 +
379 + private boolean bIsPFlagSet = false;
380 + private boolean bPFlag;
381 +
382 + private boolean bIsIFlagSet = false;
383 + private boolean bIFlag;
384 +
385 + @Override
386 + public PcepTEObject build() {
387 + PcepObjectHeader teObjHeader = this.bIsHeaderSet ? this.teObjHeader : DEFAULT_TE_OBJECT_HEADER;
388 +
389 + byte yProtocolId = this.bIsProtocolIdSet ? this.yProtocolId : DEFAULT_PROTOCOL_ID;
390 + boolean bRFlag = this.bIsRFlagSet ? this.bRFlag : DEFAULT_R_FLAG;
391 + boolean bSFlag = this.bIsSFlagSet ? this.bSFlag : DEFAULT_S_FLAG;
392 + int iTEId = this.bIsTEIdSet ? this.iTEId : DEFAULT_TE_ID;
393 +
394 + if (bIsPFlagSet) {
395 + teObjHeader.setPFlag(bPFlag);
396 + }
397 +
398 + if (bIsIFlagSet) {
399 + teObjHeader.setIFlag(bIFlag);
400 + }
401 +
402 + return new PcepTEObjectVer1(teObjHeader, yProtocolId, bRFlag, bSFlag, iTEId, llOptionalTlv);
403 +
404 + }
405 +
406 + @Override
407 + public PcepObjectHeader getTEObjHeader() {
408 + return this.teObjHeader;
409 + }
410 +
411 + @Override
412 + public Builder setTEObjHeader(PcepObjectHeader obj) {
413 + this.teObjHeader = obj;
414 + this.bIsHeaderSet = true;
415 + return this;
416 + }
417 +
418 + @Override
419 + public byte getProtocolId() {
420 + return this.yProtocolId;
421 + }
422 +
423 + @Override
424 + public Builder setProtocolId(byte yProtId) {
425 + this.yProtocolId = yProtId;
426 + this.bIsProtocolIdSet = true;
427 + return this;
428 + }
429 +
430 + @Override
431 + public boolean getRFlag() {
432 + return this.bRFlag;
433 + }
434 +
435 + @Override
436 + public Builder setRFlag(boolean bRFlag) {
437 + this.bRFlag = bRFlag;
438 + this.bIsRFlagSet = true;
439 + return this;
440 + }
441 +
442 + @Override
443 + public boolean getSFlag() {
444 + return this.bSFlag;
445 + }
446 +
447 + @Override
448 + public Builder setSFlag(boolean bSFlag) {
449 + this.bSFlag = bSFlag;
450 + this.bIsSFlagSet = true;
451 + return this;
452 + }
453 +
454 + @Override
455 + public int getTEId() {
456 + return this.iTEId;
457 + }
458 +
459 + @Override
460 + public Builder setTEId(int iTEId) {
461 + this.iTEId = iTEId;
462 + this.bIsTEIdSet = true;
463 + return this;
464 + }
465 +
466 + @Override
467 + public LinkedList<PcepValueType> getOptionalTlv() {
468 + return this.llOptionalTlv;
469 + }
470 +
471 + @Override
472 + public Builder setOptionalTlv(LinkedList<PcepValueType> llOptionalTlv) {
473 + this.llOptionalTlv = llOptionalTlv;
474 + return this;
475 + }
476 +
477 + @Override
478 + public Builder setPFlag(boolean value) {
479 + this.bPFlag = value;
480 + this.bIsPFlagSet = true;
481 + return this;
482 + }
483 +
484 + @Override
485 + public Builder setIFlag(boolean value) {
486 + this.bIFlag = value;
487 + this.bIsIFlagSet = true;
488 + return this;
489 + }
490 + }
491 +
492 + @Override
493 + public String toString() {
494 + return MoreObjects.toStringHelper(getClass()).add("ObjectHeader", teObjHeader).add("ProtocolId", yProtocolId)
495 + .add("RFlag", (bRFlag) ? 1 : 0).add("SFlag", (bSFlag) ? 1 : 0).add("TeId", iTEId)
496 + .add("OptionalTlv", llOptionalTlv).toString();
497 + }
498 +}
1 +/*
2 + * Copyright 2015 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +package org.onosproject.pcepio.types;
17 +
18 +import java.util.Objects;
19 +
20 +import org.jboss.netty.buffer.ChannelBuffer;
21 +import org.onosproject.pcepio.protocol.PcepVersion;
22 +import org.slf4j.Logger;
23 +import org.slf4j.LoggerFactory;
24 +
25 +import com.google.common.base.MoreObjects;
26 +
27 +/**
28 + * Provides Administrative Group Tlv which contains value (32 Bit ).
29 + */
30 +public class AdministrativeGroupTlv implements PcepValueType {
31 +
32 + /* REFERENCE :[RFC5305]/3.1
33 + * 0 1 2 3
34 + 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
35 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
36 + | Type=[TDB33] | Length=4 |
37 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
38 + | value (32 Bit ) |
39 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
40 + */
41 +
42 + protected static final Logger log = LoggerFactory.getLogger(AdministrativeGroupTlv.class);
43 +
44 + public static final short TYPE = 3; //TDB33
45 + public static final short LENGTH = 4;
46 +
47 + private final int rawValue;
48 +
49 + /**
50 + * Constructor to initialize rawValue.
51 + *
52 + * @param rawValue of Administrative-Group-Tlv.
53 + */
54 + public AdministrativeGroupTlv(int rawValue) {
55 + this.rawValue = rawValue;
56 + }
57 +
58 + /**
59 + * Returns newly created AdministrativeGroupTlv object.
60 + *
61 + * @param raw value.
62 + * @return object of Administrative-Group-Tlv
63 + */
64 + public static AdministrativeGroupTlv of(final int raw) {
65 + return new AdministrativeGroupTlv(raw);
66 + }
67 +
68 + /**
69 + * Returns raw value.
70 + *
71 + * @return rawValue raw value
72 + */
73 + public int getInt() {
74 + return rawValue;
75 + }
76 +
77 + @Override
78 + public PcepVersion getVersion() {
79 + return PcepVersion.PCEP_1;
80 + }
81 +
82 + @Override
83 + public short getType() {
84 + return TYPE;
85 + }
86 +
87 + @Override
88 + public short getLength() {
89 + return LENGTH;
90 + }
91 +
92 + @Override
93 + public int hashCode() {
94 + return Objects.hash(rawValue);
95 + }
96 +
97 + @Override
98 + public boolean equals(Object obj) {
99 + if (this == obj) {
100 + return true;
101 + }
102 + if (obj instanceof AdministrativeGroupTlv) {
103 + AdministrativeGroupTlv other = (AdministrativeGroupTlv) obj;
104 + return Objects.equals(rawValue, other.rawValue);
105 + }
106 + return false;
107 + }
108 +
109 + @Override
110 + public int write(ChannelBuffer c) {
111 + int iLenStartIndex = c.writerIndex();
112 + c.writeShort(TYPE);
113 + c.writeShort(LENGTH);
114 + c.writeInt(rawValue);
115 + return c.writerIndex() - iLenStartIndex;
116 + }
117 +
118 + /**
119 + * Reads the channel buffer and returns object of Administrative-Group-Tlv.
120 + *
121 + * @param c input channel buffer
122 + * @return object of Administrative-Group-Tlv
123 + */
124 + public static AdministrativeGroupTlv read(ChannelBuffer c) {
125 + return AdministrativeGroupTlv.of(c.readInt());
126 + }
127 +
128 + @Override
129 + public String toString() {
130 + return MoreObjects.toStringHelper(getClass()).add("Type", TYPE).add("Length", LENGTH).add("Value", rawValue)
131 + .toString();
132 + }
133 +}
1 +/*
2 + * Copyright 2014 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +package org.onosproject.pcepio.types;
17 +
18 +import java.util.Objects;
19 +
20 +import org.jboss.netty.buffer.ChannelBuffer;
21 +import org.onosproject.pcepio.protocol.PcepVersion;
22 +import org.slf4j.Logger;
23 +import org.slf4j.LoggerFactory;
24 +
25 +import com.google.common.base.MoreObjects;
26 +
27 +/**
28 + * Provides BGP LS identifier which contains opaque value (32 Bit ID).
29 + */
30 +public class BGPLSidentifierTlv implements PcepValueType {
31 +
32 + /* Reference :draft-ietf-idr-ls-distribution-10
33 + * 0 1 2 3
34 + 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
35 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
36 + | Type=[TBD11] | Length=4 |
37 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
38 + | opaque value (32 Bit ID). |
39 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
40 + */
41 +
42 + protected static final Logger log = LoggerFactory.getLogger(BGPLSidentifierTlv.class);
43 +
44 + public static final short TYPE = 17; //TODD:change this TBD11
45 + public static final short LENGTH = 4;
46 +
47 + private final int rawValue;
48 +
49 + /**
50 + * constructor to initialize rawValue.
51 + *
52 + * @param rawValue BGP LS identifier Tlv
53 + */
54 + public BGPLSidentifierTlv(int rawValue) {
55 + this.rawValue = rawValue;
56 + }
57 +
58 + /**
59 + * Returns newly created BGPLSidentifierTlv object.
60 + *
61 + * @param raw value
62 + * @return object of BGPLSidentifierTlv
63 + */
64 + public static BGPLSidentifierTlv of(final int raw) {
65 + return new BGPLSidentifierTlv(raw);
66 + }
67 +
68 + /**
69 + * Returns opaque value.
70 + *
71 + * @return rawValue opaque value
72 + */
73 + public int getInt() {
74 + return rawValue;
75 + }
76 +
77 + @Override
78 + public PcepVersion getVersion() {
79 + return PcepVersion.PCEP_1;
80 + }
81 +
82 + @Override
83 + public short getType() {
84 + return TYPE;
85 + }
86 +
87 + @Override
88 + public short getLength() {
89 + return LENGTH;
90 + }
91 +
92 + @Override
93 + public int hashCode() {
94 + return Objects.hash(rawValue);
95 + }
96 +
97 + @Override
98 + public boolean equals(Object obj) {
99 + if (this == obj) {
100 + return true;
101 + }
102 + if (obj instanceof BGPLSidentifierTlv) {
103 + BGPLSidentifierTlv other = (BGPLSidentifierTlv) obj;
104 + return Objects.equals(rawValue, other.rawValue);
105 + }
106 + return false;
107 + }
108 +
109 + @Override
110 + public int write(ChannelBuffer c) {
111 + int iLenStartIndex = c.writerIndex();
112 + c.writeShort(TYPE);
113 + c.writeShort(LENGTH);
114 + c.writeInt(rawValue);
115 + return c.writerIndex() - iLenStartIndex;
116 + }
117 +
118 + /**
119 + * Reads the channel buffer and returns object of BGPLSidentifierTlv.
120 + *
121 + * @param c input channel buffer
122 + * @return object of BGP LS identifier Tlv
123 + */
124 + public static BGPLSidentifierTlv read(ChannelBuffer c) {
125 + return BGPLSidentifierTlv.of(c.readInt());
126 + }
127 +
128 + @Override
129 + public String toString() {
130 + return MoreObjects.toStringHelper(getClass()).add("Type", TYPE).add("Length", LENGTH).add("Value", rawValue)
131 + .toString();
132 + }
133 +}
1 +/*
2 + * Copyright 2015 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +
17 +package org.onosproject.pcepio.types;
18 +
19 +import java.util.Objects;
20 +
21 +import org.jboss.netty.buffer.ChannelBuffer;
22 +import org.onosproject.pcepio.protocol.PcepVersion;
23 +import org.slf4j.Logger;
24 +import org.slf4j.LoggerFactory;
25 +
26 +import com.google.common.base.MoreObjects;
27 +
28 +/**
29 + * Provides GMPLS Capability Tlv.
30 + */
31 +public class GmplsCapabilityTlv implements PcepValueType {
32 +
33 + /*
34 + * GMPLS-CAPABILITY TLV format
35 + * reference :draft-ietf-pce-gmpls-pcep-extensions -2.1.1
36 + 0 1 2 3
37 + 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
38 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
39 + | Type=14 | Length |
40 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
41 + | Flags |
42 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
43 + */
44 + protected static final Logger log = LoggerFactory.getLogger(GmplsCapabilityTlv.class);
45 +
46 + public static final short TYPE = 14;
47 + public static final short LENGTH = 4;
48 +
49 + private final int rawValue;
50 +
51 + /**
52 + * Constructor to initialize raw value.
53 + *
54 + * @param rawValue of Gmpls-Capability-Tlv
55 + */
56 + public GmplsCapabilityTlv(int rawValue) {
57 + this.rawValue = rawValue;
58 + }
59 +
60 + /**
61 + * Returns newly created GmplsCapabilityTlv object.
62 + *
63 + * @param raw Flags value
64 + * @return object of Gmpls-Capability-Tlv
65 + */
66 + public static GmplsCapabilityTlv of(final int raw) {
67 + return new GmplsCapabilityTlv(raw);
68 + }
69 +
70 + /**
71 + * Returns value of Flags.
72 + *
73 + * @return rawValue Flags
74 + */
75 + public int getInt() {
76 + return rawValue;
77 + }
78 +
79 + @Override
80 + public PcepVersion getVersion() {
81 + return PcepVersion.PCEP_1;
82 + }
83 +
84 + @Override
85 + public short getType() {
86 + return TYPE;
87 + }
88 +
89 + @Override
90 + public short getLength() {
91 + return LENGTH;
92 + }
93 +
94 + @Override
95 + public int hashCode() {
96 + return Objects.hash(rawValue);
97 + }
98 +
99 + @Override
100 + public boolean equals(Object obj) {
101 + if (this == obj) {
102 + return true;
103 + }
104 + if (obj instanceof GmplsCapabilityTlv) {
105 + GmplsCapabilityTlv other = (GmplsCapabilityTlv) obj;
106 + return Objects.equals(rawValue, other.rawValue);
107 + }
108 + return false;
109 + }
110 +
111 + @Override
112 + public int write(ChannelBuffer c) {
113 + int iLenStartIndex = c.writerIndex();
114 + c.writeShort(TYPE);
115 + c.writeShort(LENGTH);
116 + c.writeInt(rawValue);
117 + return c.writerIndex() - iLenStartIndex;
118 + }
119 +
120 + /**
121 + * Reads the channel buffer and returns object of Gmpls-Capability-Tlv.
122 + *
123 + * @param c input channel buffer
124 + * @return object of Gmpls-Capability-Tlv
125 + */
126 + public static GmplsCapabilityTlv read(ChannelBuffer c) {
127 + return GmplsCapabilityTlv.of(c.readInt());
128 + }
129 +
130 + @Override
131 + public String toString() {
132 + return MoreObjects.toStringHelper(getClass()).add("Type", TYPE).add("Length", LENGTH).add("Value", rawValue)
133 + .toString();
134 + }
135 +}
1 +/*
2 + * Copyright 2015 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +package org.onosproject.pcepio.types;
17 +
18 +import java.util.Objects;
19 +
20 +import org.jboss.netty.buffer.ChannelBuffer;
21 +import org.onosproject.pcepio.protocol.PcepVersion;
22 +import org.slf4j.Logger;
23 +import org.slf4j.LoggerFactory;
24 +
25 +import com.google.common.base.MoreObjects;
26 +import com.google.common.base.MoreObjects.ToStringHelper;
27 +
28 +/**
29 + * Provides IGP Link Metric .
30 + */
31 +public class IGPMetricTlv implements PcepValueType {
32 +
33 + /* Reference :[I-D.ietf-idr-ls-distribution] /3.3.2.4
34 + * 0 1 2 3
35 + 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
36 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
37 + | Type=TDB40 | Length |
38 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
39 + // IGP Link Metric (variable length) //
40 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
41 + */
42 +
43 + protected static final Logger log = LoggerFactory.getLogger(IGPMetricTlv.class);
44 +
45 + public static final short TYPE = 1095; //TODO:NEED TO HANDLE TDB40
46 + private short hLength;
47 +
48 + private final byte[] rawValue;
49 +
50 + /**
51 + * Constructor to initialize raw value.
52 + *
53 + * @param rawValue IGP Link Metric
54 + * @param hLength length
55 + */
56 + public IGPMetricTlv(byte[] rawValue, short hLength) {
57 + this.rawValue = rawValue;
58 + this.hLength = hLength;
59 + }
60 +
61 + /**
62 + * Returns newly created IGPMetricTlv object.
63 + *
64 + * @param raw value of IGP Link Metric
65 + * @param hLength length
66 + * @return object of IGPMetricTlv
67 + */
68 + public static IGPMetricTlv of(final byte[] raw, short hLength) {
69 + return new IGPMetricTlv(raw, hLength);
70 + }
71 +
72 + /**
73 + * Returns value of IGP Link Metric.
74 + *
75 + * @return rawValue of IGP Link Metric
76 + */
77 + public byte[] getValue() {
78 + return rawValue;
79 + }
80 +
81 + @Override
82 + public PcepVersion getVersion() {
83 + return PcepVersion.PCEP_1;
84 + }
85 +
86 + @Override
87 + public short getType() {
88 + return TYPE;
89 + }
90 +
91 + @Override
92 + public short getLength() {
93 + return hLength;
94 + }
95 +
96 + @Override
97 + public int hashCode() {
98 + return Objects.hash(rawValue);
99 + }
100 +
101 + @Override
102 + public boolean equals(Object obj) {
103 + if (this == obj) {
104 + return true;
105 + }
106 + if (obj instanceof IGPMetricTlv) {
107 + IGPMetricTlv other = (IGPMetricTlv) obj;
108 + return Objects.equals(rawValue, other.rawValue);
109 + }
110 + return false;
111 + }
112 +
113 + @Override
114 + public int write(ChannelBuffer c) {
115 + int iLenStartIndex = c.writerIndex();
116 + c.writeShort(TYPE);
117 + c.writeShort(hLength);
118 + c.writeBytes(rawValue);
119 + return c.writerIndex() - iLenStartIndex;
120 + }
121 +
122 + /**
123 + * Reads the channel buffer and returns object of IGPMetricTlv.
124 + *
125 + * @param c input channel buffer
126 + * @param hLength length
127 + * @return object of IGPMetricTlv
128 + */
129 + public static PcepValueType read(ChannelBuffer c, short hLength) {
130 + byte[] iIGPMetric = new byte[hLength];
131 + c.readBytes(iIGPMetric, 0, hLength);
132 + return new IGPMetricTlv(iIGPMetric, hLength);
133 + }
134 +
135 + @Override
136 + public String toString() {
137 + ToStringHelper toStrHelper = MoreObjects.toStringHelper(getClass());
138 +
139 + toStrHelper.add("Type", TYPE);
140 + toStrHelper.add("Length", hLength);
141 +
142 + StringBuffer result = new StringBuffer();
143 + for (byte b : rawValue) {
144 + result.append(String.format("%02X ", b));
145 + }
146 + toStrHelper.add("Value", result);
147 +
148 + return toStrHelper.toString();
149 + }
150 +}
1 +/*
2 + * Copyright 2015 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +package org.onosproject.pcepio.types;
17 +
18 +import java.util.Objects;
19 +
20 +import org.jboss.netty.buffer.ChannelBuffer;
21 +import org.onosproject.pcepio.protocol.PcepVersion;
22 +import org.slf4j.Logger;
23 +import org.slf4j.LoggerFactory;
24 +
25 +import com.google.common.base.MoreObjects;
26 +
27 +/**
28 + * Provides IPv4 Interface Address .
29 + */
30 +public class IPv4InterfaceAddressTlv implements PcepValueType {
31 +
32 + /*
33 + * reference :[RFC5305]/3.2
34 + 0 1 2 3
35 + 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
36 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
37 + | Type=6 | Length=4 |
38 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
39 + | IPv4 Interface Address |
40 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
41 + */
42 +
43 + protected static final Logger log = LoggerFactory.getLogger(IPv4InterfaceAddressTlv.class);
44 +
45 + public static final short TYPE = 6;
46 + public static final short LENGTH = 4;
47 +
48 + private final int rawValue;
49 +
50 + /**
51 + * Constructor to initialize rawValue.
52 + *
53 + * @param rawValue of IPv4-Interface-Address.
54 + */
55 + public IPv4InterfaceAddressTlv(int rawValue) {
56 + this.rawValue = rawValue;
57 + }
58 +
59 + /**
60 + * Returns newly created IPv4InterfaceAddressTlv object.
61 + *
62 + * @param raw value of IPv4-Interface-Address
63 + * @return object of IPv4-Interface-Address-Tlv
64 + */
65 + public static IPv4InterfaceAddressTlv of(final int raw) {
66 + return new IPv4InterfaceAddressTlv(raw);
67 + }
68 +
69 + /**
70 + * Returns value of IPv4 Interface Address.
71 + *
72 + * @return rawValue IPv4 Interface Address
73 + */
74 + public int getInt() {
75 + return rawValue;
76 + }
77 +
78 + @Override
79 + public PcepVersion getVersion() {
80 + return PcepVersion.PCEP_1;
81 + }
82 +
83 + @Override
84 + public short getType() {
85 + return TYPE;
86 + }
87 +
88 + @Override
89 + public short getLength() {
90 + return LENGTH;
91 + }
92 +
93 + @Override
94 + public int hashCode() {
95 + return Objects.hash(rawValue);
96 + }
97 +
98 + @Override
99 + public boolean equals(Object obj) {
100 + if (this == obj) {
101 + return true;
102 + }
103 + if (obj instanceof IPv4InterfaceAddressTlv) {
104 + IPv4InterfaceAddressTlv other = (IPv4InterfaceAddressTlv) obj;
105 + return Objects.equals(rawValue, other.rawValue);
106 + }
107 + return false;
108 + }
109 +
110 + @Override
111 + public int write(ChannelBuffer c) {
112 + int iLenStartIndex = c.writerIndex();
113 + c.writeShort(TYPE);
114 + c.writeShort(LENGTH);
115 + c.writeInt(rawValue);
116 + return c.writerIndex() - iLenStartIndex;
117 + }
118 +
119 + /**
120 + * Reads the channel buffer and returns object of IPv4InterfaceAddressTlv.
121 + *
122 + * @param c input channel buffer
123 + * @return object of IPv4-Interface-Address-Tlv
124 + */
125 + public static IPv4InterfaceAddressTlv read(ChannelBuffer c) {
126 + return IPv4InterfaceAddressTlv.of(c.readInt());
127 + }
128 +
129 + @Override
130 + public String toString() {
131 + return MoreObjects.toStringHelper(getClass()).add("Type", TYPE).add("Length", LENGTH).add("Value", rawValue)
132 + .toString();
133 + }
134 +}
...\ No newline at end of file ...\ No newline at end of file
1 +/*
2 + * Copyright 2015 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +package org.onosproject.pcepio.types;
17 +
18 +import java.util.Objects;
19 +
20 +import org.jboss.netty.buffer.ChannelBuffer;
21 +import org.onosproject.pcepio.protocol.PcepVersion;
22 +import org.slf4j.Logger;
23 +import org.slf4j.LoggerFactory;
24 +
25 +import com.google.common.base.MoreObjects;
26 +
27 +/**
28 + * Provides IPv4 Neighbor Address .
29 + */
30 +public class IPv4NeighborAddressTlv implements PcepValueType {
31 +
32 + /* Reference :[RFC5305]/3.3
33 + 0 1 2 3
34 + 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
35 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
36 + | Type=8 | Length=4 |
37 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
38 + | IPv4 Neighbor Address |
39 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
40 + */
41 +
42 + protected static final Logger log = LoggerFactory.getLogger(IPv4NeighborAddressTlv.class);
43 +
44 + public static final short TYPE = 8;
45 + public static final short LENGTH = 4;
46 +
47 + private final int rawValue;
48 +
49 + /**
50 + * Constructor to initialize rawValue.
51 + *
52 + * @param rawValue IPv4-Neighbor-Address-Tlv
53 + */
54 + public IPv4NeighborAddressTlv(int rawValue) {
55 + log.debug("IPv4NeighborAddressTlv");
56 + this.rawValue = rawValue;
57 + }
58 +
59 + /**
60 + * Returns newly created IPv4NeighborAddressTlv object.
61 + *
62 + * @param raw value of IPv4-Neighbor-Address
63 + * @return object of IPv4NeighborAddressTlv
64 + */
65 + public static IPv4NeighborAddressTlv of(final int raw) {
66 + return new IPv4NeighborAddressTlv(raw);
67 + }
68 +
69 + /**
70 + * Returns value of IPv4 Neighbor Address.
71 + *
72 + * @return rawValue IPv4 Neighbor Address
73 + */
74 + public int getInt() {
75 + return rawValue;
76 + }
77 +
78 + @Override
79 + public PcepVersion getVersion() {
80 + return PcepVersion.PCEP_1;
81 + }
82 +
83 + @Override
84 + public short getType() {
85 + return TYPE;
86 + }
87 +
88 + @Override
89 + public short getLength() {
90 + return LENGTH;
91 + }
92 +
93 + @Override
94 + public int hashCode() {
95 + return Objects.hash(rawValue);
96 + }
97 +
98 + @Override
99 + public boolean equals(Object obj) {
100 + if (this == obj) {
101 + return true;
102 + }
103 + if (obj instanceof IPv4NeighborAddressTlv) {
104 + IPv4NeighborAddressTlv other = (IPv4NeighborAddressTlv) obj;
105 + return Objects.equals(rawValue, other.rawValue);
106 + }
107 + return false;
108 + }
109 +
110 + @Override
111 + public int write(ChannelBuffer c) {
112 + int iLenStartIndex = c.writerIndex();
113 + c.writeShort(TYPE);
114 + c.writeShort(LENGTH);
115 + c.writeInt(rawValue);
116 + return c.writerIndex() - iLenStartIndex;
117 + }
118 +
119 + /**
120 + * Reads the channel buffer and returns object of IPv4-Neighbor-Address-Tlv.
121 + *
122 + * @param c input channel buffer
123 + * @return object of IPv4-Neighbor-Address-Tlv
124 + */
125 + public static IPv4NeighborAddressTlv read(ChannelBuffer c) {
126 + return IPv4NeighborAddressTlv.of(c.readInt());
127 + }
128 +
129 + @Override
130 + public String toString() {
131 + return MoreObjects.toStringHelper(getClass()).add("Type", TYPE).add("Length", LENGTH).add("Value", rawValue)
132 + .toString();
133 + }
134 +}
...\ No newline at end of file ...\ No newline at end of file
1 +/*
2 + * Copyright 2015 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +package org.onosproject.pcepio.types;
17 +
18 +import java.util.Objects;
19 +
20 +import org.jboss.netty.buffer.ChannelBuffer;
21 +import org.onosproject.pcepio.protocol.PcepVersion;
22 +import org.slf4j.Logger;
23 +import org.slf4j.LoggerFactory;
24 +
25 +import com.google.common.base.MoreObjects;
26 +
27 +/**
28 + * Provides IPv4 TE Router Id Of Local Node.
29 + */
30 +public class IPv4TERouterIdOfLocalNodeTlv implements PcepValueType {
31 +
32 + /* Reference:[RFC5305]/4.3
33 + * 0 1 2 3
34 + 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
35 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
36 + | Type=[TDB25] | Length=4 |
37 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
38 + | IPv4 TE Router Id Of Local Node |
39 + +-+-+-+-+-+-+-+-+-++-+-+-+-+-+-+-+-+-++-+-+-+-+-+-+-+-+-++-+-+-+-
40 + */
41 +
42 + protected static final Logger log = LoggerFactory.getLogger(IPv4TERouterIdOfLocalNodeTlv.class);
43 +
44 + public static final short TYPE = 134; //TDB25
45 + public static final short LENGTH = 4;
46 +
47 + private final int rawValue;
48 +
49 + /**
50 + * Constructor to initialize rawValue.
51 + *
52 + * @param rawValue IPv4-TE-RouterId-Of-Local-Node-Tlv
53 + */
54 + public IPv4TERouterIdOfLocalNodeTlv(int rawValue) {
55 + this.rawValue = rawValue;
56 + }
57 +
58 + /**
59 + * Returns newly created IPv4TERouterIdOfLocalNodeTlv object.
60 + *
61 + * @param raw value of IPv4-TE-RouterId-Of-Local-Node
62 + * @return object of IPv4TERouterIdOfLocalNodeTlv
63 + */
64 + public static IPv4TERouterIdOfLocalNodeTlv of(final int raw) {
65 + return new IPv4TERouterIdOfLocalNodeTlv(raw);
66 + }
67 +
68 + /**
69 + * Returns value of IPv4 TE Router Id Of Local Node.
70 + *
71 + * @return rawValue IPv4 TE Router Id Of Local Node
72 + */
73 + public int getInt() {
74 + return rawValue;
75 + }
76 +
77 + @Override
78 + public PcepVersion getVersion() {
79 + return PcepVersion.PCEP_1;
80 + }
81 +
82 + @Override
83 + public short getType() {
84 + return TYPE;
85 + }
86 +
87 + @Override
88 + public short getLength() {
89 + return LENGTH;
90 + }
91 +
92 + @Override
93 + public int hashCode() {
94 + return Objects.hash(rawValue);
95 + }
96 +
97 + @Override
98 + public boolean equals(Object obj) {
99 + if (this == obj) {
100 + return true;
101 + }
102 + if (obj instanceof IPv4TERouterIdOfLocalNodeTlv) {
103 + IPv4TERouterIdOfLocalNodeTlv other = (IPv4TERouterIdOfLocalNodeTlv) obj;
104 + return Objects.equals(rawValue, other.rawValue);
105 + }
106 + return false;
107 + }
108 +
109 + @Override
110 + public int write(ChannelBuffer c) {
111 + int iLenStartIndex = c.writerIndex();
112 + c.writeShort(TYPE);
113 + c.writeShort(LENGTH);
114 + c.writeInt(rawValue);
115 + return c.writerIndex() - iLenStartIndex;
116 + }
117 +
118 + /**
119 + * Reads the channel buffer and returns object of IPv4TERouterIdOfLocalNodeTlv.
120 + *
121 + * @param c input channel buffer
122 + * @return object of IPv4TERouterIdOfLocalNodeTlv
123 + */
124 + public static IPv4TERouterIdOfLocalNodeTlv read(ChannelBuffer c) {
125 + return IPv4TERouterIdOfLocalNodeTlv.of(c.readInt());
126 + }
127 +
128 + @Override
129 + public String toString() {
130 + return MoreObjects.toStringHelper(getClass()).add("Type", TYPE).add("Length", LENGTH).add("Value", rawValue)
131 + .toString();
132 + }
133 +}
1 +/*
2 + * Copyright 2015 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +package org.onosproject.pcepio.types;
17 +
18 +import java.util.Objects;
19 +
20 +import org.jboss.netty.buffer.ChannelBuffer;
21 +import org.onosproject.pcepio.protocol.PcepVersion;
22 +import org.slf4j.Logger;
23 +import org.slf4j.LoggerFactory;
24 +
25 +import com.google.common.base.MoreObjects;
26 +
27 +/**
28 + * Provides IPv4 TE Router Id Of Remote Node.
29 + */
30 +public class IPv4TERouterIdOfRemoteNodeTlv implements PcepValueType {
31 +
32 + /* Reference :[RFC5305]/4.3
33 + * 0 1 2 3
34 + 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
35 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
36 + | Type=[TDB28] | Length=4 |
37 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
38 + | IPv4 TE Router Id Of Remote Node |
39 + +-+-+-+-+-+-+-+-+-++-+-+-+-+-+-+-+-+-++-+-+-+-+-+-+-+-+-++-+-+-+-
40 + */
41 +
42 + protected static final Logger log = LoggerFactory.getLogger(IPv4TERouterIdOfRemoteNodeTlv.class);
43 +
44 + public static final short TYPE = 1340; //TDB28
45 + public static final short LENGTH = 4;
46 +
47 + private final int rawValue;
48 +
49 + /**
50 + * Constructor to initialize rawValue.
51 + *
52 + * @param rawValue IPv4 TE RouterId Of Remote Node Tlv
53 + */
54 + public IPv4TERouterIdOfRemoteNodeTlv(int rawValue) {
55 + log.debug("IPv4TERouterIdOfRemoteNodeTlv");
56 + this.rawValue = rawValue;
57 + }
58 +
59 + /**
60 + * Returns newly created IPv4TERouterIdOfRemoteNodeTlv object.
61 + *
62 + * @param raw IPv4 TE RouterId Of Remote Node
63 + * @return object of IPv4TERouterIdOfRemoteNodeTlv
64 + */
65 + public static IPv4TERouterIdOfRemoteNodeTlv of(final int raw) {
66 + return new IPv4TERouterIdOfRemoteNodeTlv(raw);
67 + }
68 +
69 + /**
70 + * Returns value of IPv4 TE Router Id Of Remote Node.
71 + *
72 + * @return rawValue IPv4 TE Router Id Of Remote Node
73 + */
74 + public int getInt() {
75 + return rawValue;
76 + }
77 +
78 + @Override
79 + public PcepVersion getVersion() {
80 + return PcepVersion.PCEP_1;
81 + }
82 +
83 + @Override
84 + public short getType() {
85 + return TYPE;
86 + }
87 +
88 + @Override
89 + public short getLength() {
90 + return LENGTH;
91 + }
92 +
93 + @Override
94 + public int hashCode() {
95 + return Objects.hash(rawValue);
96 + }
97 +
98 + @Override
99 + public boolean equals(Object obj) {
100 + if (this == obj) {
101 + return true;
102 + }
103 + if (obj instanceof IPv4TERouterIdOfRemoteNodeTlv) {
104 + IPv4TERouterIdOfRemoteNodeTlv other = (IPv4TERouterIdOfRemoteNodeTlv) obj;
105 + return Objects.equals(rawValue, other.rawValue);
106 + }
107 + return false;
108 + }
109 +
110 + @Override
111 + public int write(ChannelBuffer c) {
112 + int iLenStartIndex = c.writerIndex();
113 + c.writeShort(TYPE);
114 + c.writeShort(LENGTH);
115 + c.writeInt(rawValue);
116 + return c.writerIndex() - iLenStartIndex;
117 + }
118 +
119 + /**
120 + * Reads the channel buffer and returns object of IPv4TERouterIdOfRemoteNodeTlv.
121 + *
122 + * @param c input channel buffer
123 + * @return object of IPv4TERouterIdOfRemoteNodeTlv
124 + */
125 + public static IPv4TERouterIdOfRemoteNodeTlv read(ChannelBuffer c) {
126 + return IPv4TERouterIdOfRemoteNodeTlv.of(c.readInt());
127 + }
128 +
129 + @Override
130 + public String toString() {
131 + return MoreObjects.toStringHelper(getClass()).add("Type", TYPE).add("Length", LENGTH).add("Value", rawValue)
132 + .toString();
133 + }
134 +}
1 +/*
2 + * Copyright 2015 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +package org.onosproject.pcepio.types;
17 +
18 +import java.util.Objects;
19 +
20 +import org.jboss.netty.buffer.ChannelBuffer;
21 +import org.onosproject.pcepio.protocol.PcepVersion;
22 +import org.slf4j.Logger;
23 +import org.slf4j.LoggerFactory;
24 +
25 +import com.google.common.base.MoreObjects;
26 +import com.google.common.base.MoreObjects.ToStringHelper;
27 +
28 +/**
29 + * Provides IPv6 Interface Address. REFERENCE :[RFC6119]/4.2.
30 + */
31 +public class IPv6InterfaceAddressTlv implements PcepValueType {
32 +
33 + protected static final Logger log = LoggerFactory.getLogger(IPv6InterfaceAddressTlv.class);
34 +
35 + public static final short TYPE = 12; //TDB18
36 + public static final short LENGTH = 20;
37 + public static final byte VALUE_LENGTH = 18;
38 +
39 + private static final byte[] NONE_VAL = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
40 + public static final IPv6InterfaceAddressTlv NONE = new IPv6InterfaceAddressTlv(NONE_VAL);
41 +
42 + private static final byte[] NO_MASK_VAL = {(byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
43 + (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
44 + (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF};
45 + public static final IPv6InterfaceAddressTlv NO_MASK = new IPv6InterfaceAddressTlv(NO_MASK_VAL);
46 + public static final IPv6InterfaceAddressTlv FULL_MASK = NONE;
47 +
48 + private final byte[] rawValue;
49 +
50 + /**
51 + * Constructor to initialize rawValue.
52 + *
53 + * @param rawValue IPv6 Interface Address Tlv
54 + */
55 + public IPv6InterfaceAddressTlv(byte[] rawValue) {
56 + log.debug("IPv6InterfaceAddressTlv");
57 + this.rawValue = rawValue;
58 + }
59 +
60 + /**
61 + * Returns newly created IPv6InterfaceAddressTlv object.
62 + *
63 + * @param raw IPv6 Interface Address
64 + * @return object of IPv6InterfaceAddressTlv
65 + */
66 + public static IPv6InterfaceAddressTlv of(final byte[] raw) {
67 + //check NONE_VAL
68 + boolean bFoundNONE = true;
69 + //value starts from 3rd byte.
70 + for (int i = 2; i < 20; ++i) {
71 + if (NONE_VAL[i] != raw[i]) {
72 + bFoundNONE = false;
73 + }
74 + }
75 +
76 + if (bFoundNONE) {
77 + return NONE;
78 + }
79 +
80 + //check NO_MASK_VAL
81 + boolean bFoundNoMask = true;
82 + //value starts from 3rd byte.
83 + for (int i = 2; i < 20; ++i) {
84 + if (0xFF != raw[i]) {
85 + bFoundNoMask = false;
86 + }
87 + }
88 + if (bFoundNoMask) {
89 + return NO_MASK;
90 + }
91 +
92 + return new IPv6InterfaceAddressTlv(raw);
93 + }
94 +
95 + /**
96 + * Returns value of IPv6 Interface Address.
97 + *
98 + * @return rawValue raw value
99 + */
100 + public byte[] getBytes() {
101 + return rawValue;
102 + }
103 +
104 + /**
105 + * Returns value of IPv6 Interface Address.
106 + *
107 + * @return rawValue raw value
108 + */
109 + public byte[] getValue() {
110 + return rawValue;
111 + }
112 +
113 + @Override
114 + public PcepVersion getVersion() {
115 + return PcepVersion.PCEP_1;
116 + }
117 +
118 + @Override
119 + public short getType() {
120 + return TYPE;
121 + }
122 +
123 + @Override
124 + public short getLength() {
125 + return LENGTH;
126 + }
127 +
128 + @Override
129 + public int hashCode() {
130 + return Objects.hash(rawValue);
131 + }
132 +
133 + @Override
134 + public boolean equals(Object obj) {
135 + if (this == obj) {
136 + return true;
137 + }
138 + if (obj instanceof IPv6InterfaceAddressTlv) {
139 + IPv6InterfaceAddressTlv other = (IPv6InterfaceAddressTlv) obj;
140 + return Objects.equals(rawValue, other.rawValue);
141 + }
142 + return false;
143 + }
144 +
145 + @Override
146 + public int write(ChannelBuffer c) {
147 + int iLenStartIndex = c.writerIndex();
148 + c.writeShort(TYPE);
149 + c.writeShort(LENGTH);
150 + c.writeBytes(rawValue);
151 + return c.writerIndex() - iLenStartIndex;
152 + }
153 +
154 + /**
155 + * Reads the channel buffer and returns object of IPv6InterfaceAddressTlv.
156 + *
157 + * @param c input channel buffer
158 + * @return object of IPv6InterfaceAddressTlv
159 + */
160 + public static IPv6InterfaceAddressTlv read20Bytes(ChannelBuffer c) {
161 + byte[] yTemp = new byte[20];
162 + c.readBytes(yTemp, 0, 20);
163 + return IPv6InterfaceAddressTlv.of(yTemp);
164 + }
165 +
166 + @Override
167 + public String toString() {
168 + ToStringHelper toStrHelper = MoreObjects.toStringHelper(getClass());
169 +
170 + toStrHelper.add("Type", TYPE);
171 + toStrHelper.add("Length", LENGTH);
172 +
173 + StringBuffer result = new StringBuffer();
174 + for (byte b : rawValue) {
175 + result.append(String.format("%02X ", b));
176 + }
177 + toStrHelper.add("Value", result);
178 +
179 + return toStrHelper.toString();
180 + }
181 +}
1 +/*
2 + * Copyright 2015 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +package org.onosproject.pcepio.types;
17 +
18 +import java.util.Objects;
19 +
20 +import org.jboss.netty.buffer.ChannelBuffer;
21 +import org.onosproject.pcepio.protocol.PcepVersion;
22 +import org.slf4j.Logger;
23 +import org.slf4j.LoggerFactory;
24 +
25 +import com.google.common.base.MoreObjects;
26 +import com.google.common.base.MoreObjects.ToStringHelper;
27 +
28 +/**
29 + * Provides IPv6 Neighbor Address. Reference :[RFC6119]/4.3.
30 + */
31 +public class IPv6NeighborAddressTlv implements PcepValueType {
32 + protected static final Logger log = LoggerFactory.getLogger(IPv6NeighborAddressTlv.class);
33 +
34 + public static final short TYPE = 13; // TDB19
35 + public static final short LENGTH = 20;
36 + public static final byte VALUE_LENGTH = 18;
37 +
38 + private static final byte[] NONE_VAL = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
39 + public static final IPv6NeighborAddressTlv NONE = new IPv6NeighborAddressTlv(NONE_VAL);
40 +
41 + private static final byte[] NO_MASK_VAL = {(byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
42 + (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
43 + (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF};
44 + public static final IPv6NeighborAddressTlv NO_MASK = new IPv6NeighborAddressTlv(NO_MASK_VAL);
45 + public static final IPv6NeighborAddressTlv FULL_MASK = NONE;
46 +
47 + private final byte[] rawValue;
48 +
49 + /**
50 + * Constructor to initialize rawValue.
51 + *
52 + * @param rawValue IPv6 Neighbor Address Tlv
53 + */
54 + public IPv6NeighborAddressTlv(byte[] rawValue) {
55 + this.rawValue = rawValue;
56 + }
57 +
58 + /**
59 + * Returns newly created IPv6NeighborAddressTlv object.
60 + *
61 + * @param raw IPv6 Neighbor Address
62 + * @return object of IPv6 Neighbor Address Tlv
63 + */
64 + public static IPv6NeighborAddressTlv of(final byte[] raw) {
65 + //check NONE_VAL
66 + boolean bFoundNONE = true;
67 + //value starts from 3rd byte.
68 + for (int i = 2; i < 20; ++i) {
69 + if (NONE_VAL[i] != raw[i]) {
70 + bFoundNONE = false;
71 + }
72 + }
73 +
74 + if (bFoundNONE) {
75 + return NONE;
76 + }
77 +
78 + //check NO_MASK_VAL
79 + boolean bFoundNoMask = true;
80 + //value starts from 3rd byte.
81 + for (int i = 2; i < 20; ++i) {
82 + if (0xFF != raw[i]) {
83 + bFoundNoMask = false;
84 + }
85 + }
86 + if (bFoundNoMask) {
87 + return NO_MASK;
88 + }
89 +
90 + return new IPv6NeighborAddressTlv(raw);
91 + }
92 +
93 + /**
94 + * Returns value of IPv6 Neighbor Address.
95 + *
96 + * @return rawValue raw value
97 + */
98 + public byte[] getBytes() {
99 + return rawValue;
100 + }
101 +
102 + /**
103 + * Returns value of IPv6 Neighbor Address.
104 + *
105 + * @return rawValue raw value
106 + */
107 + public byte[] getValue() {
108 + return rawValue;
109 + }
110 +
111 + @Override
112 + public PcepVersion getVersion() {
113 + return PcepVersion.PCEP_1;
114 + }
115 +
116 + @Override
117 + public short getType() {
118 + return TYPE;
119 + }
120 +
121 + @Override
122 + public short getLength() {
123 + return LENGTH;
124 + }
125 +
126 + @Override
127 + public int hashCode() {
128 + return Objects.hash(rawValue);
129 + }
130 +
131 + @Override
132 + public boolean equals(Object obj) {
133 + if (this == obj) {
134 + return true;
135 + }
136 + if (obj instanceof IPv6NeighborAddressTlv) {
137 + IPv6NeighborAddressTlv other = (IPv6NeighborAddressTlv) obj;
138 + return Objects.equals(rawValue, other.rawValue);
139 + }
140 + return false;
141 + }
142 +
143 + @Override
144 + public int write(ChannelBuffer c) {
145 + int iStartIndex = c.writerIndex();
146 + c.writeShort(TYPE);
147 + c.writeShort(LENGTH);
148 + c.writeBytes(rawValue);
149 + return c.writerIndex() - iStartIndex;
150 + }
151 +
152 + /**
153 + * Reads the channel buffer and returns object of IPv6NeighborAddressTlv.
154 + *
155 + * @param c input channel buffer
156 + * @return object of IPv6NeighborAddressTlv
157 + */
158 + public static IPv6NeighborAddressTlv read20Bytes(ChannelBuffer c) {
159 + byte[] yTemp = new byte[20];
160 + c.readBytes(yTemp, 0, 20);
161 + return IPv6NeighborAddressTlv.of(yTemp);
162 + }
163 +
164 + @Override
165 + public String toString() {
166 + ToStringHelper toStrHelper = MoreObjects.toStringHelper(getClass());
167 +
168 + toStrHelper.add("Type", TYPE);
169 + toStrHelper.add("Length", LENGTH);
170 +
171 + StringBuffer result = new StringBuffer();
172 + for (byte b : rawValue) {
173 + result.append(String.format("%02X ", b));
174 + }
175 + toStrHelper.add("Value", result);
176 +
177 + return toStrHelper.toString();
178 + }
179 +}
1 +/*
2 + * Copyright 2015 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +package org.onosproject.pcepio.types;
17 +
18 +import java.util.Objects;
19 +
20 +import org.jboss.netty.buffer.ChannelBuffer;
21 +import org.onosproject.pcepio.protocol.PcepVersion;
22 +import org.slf4j.Logger;
23 +import org.slf4j.LoggerFactory;
24 +
25 +import com.google.common.base.MoreObjects;
26 +import com.google.common.base.MoreObjects.ToStringHelper;
27 +
28 +/**
29 + * Provides IPv6 TE Router Id of Local Node. Reference :[RFC6119]/4.1.
30 + */
31 +public class IPv6TERouterIdofLocalNodeTlv implements PcepValueType {
32 + protected static final Logger log = LoggerFactory.getLogger(IPv6TERouterIdofLocalNodeTlv.class);
33 +
34 + public static final short TYPE = 140; //TDB26
35 + public static final short LENGTH = 20;
36 + public static final byte VALUE_LENGTH = 18;
37 +
38 + private static final byte[] NONE_VAL = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
39 + public static final IPv6TERouterIdofLocalNodeTlv NONE = new IPv6TERouterIdofLocalNodeTlv(NONE_VAL);
40 +
41 + private static final byte[] NO_MASK_VAL = {(byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
42 + (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
43 + (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF };
44 + public static final IPv6TERouterIdofLocalNodeTlv NO_MASK = new IPv6TERouterIdofLocalNodeTlv(NO_MASK_VAL);
45 + public static final IPv6TERouterIdofLocalNodeTlv FULL_MASK = NONE;
46 +
47 + private final byte[] rawValue;
48 +
49 + /**
50 + * Constructor to initialize rawValue.
51 + *
52 + * @param rawValue IPv6TERouterIdofLocalNodeTlv
53 + */
54 + public IPv6TERouterIdofLocalNodeTlv(byte[] rawValue) {
55 + this.rawValue = rawValue;
56 + }
57 +
58 + /**
59 + * Returns newly created IPv6TERouterIdofLocalNodeTlv object.
60 + *
61 + * @param raw IPv6 TE Router Id of Local Node
62 + * @return object of IPv6TERouterIdofLocalNodeTlv
63 + */
64 + public static IPv6TERouterIdofLocalNodeTlv of(final byte[] raw) {
65 + //check NONE_VAL
66 + boolean bFoundNONE = true;
67 + //value starts from 3rd byte.
68 + for (int i = 2; i < 20; ++i) {
69 + if (NONE_VAL[i] != raw[i]) {
70 + bFoundNONE = false;
71 + }
72 + }
73 +
74 + if (bFoundNONE) {
75 + return NONE;
76 + }
77 +
78 + //check NO_MASK_VAL
79 + boolean bFoundNoMask = true;
80 + //value starts from 3rd byte.
81 + for (int i = 2; i < 20; ++i) {
82 + if (0xFF != raw[i]) {
83 + bFoundNoMask = false;
84 + }
85 + }
86 + if (bFoundNoMask) {
87 + return NO_MASK;
88 + }
89 +
90 + return new IPv6TERouterIdofLocalNodeTlv(raw);
91 + }
92 +
93 + /**
94 + * Returns value of IPv6 TE Router Id of Local Node.
95 + *
96 + * @return byte array value of rawValue
97 + */
98 + public byte[] getBytes() {
99 + return rawValue;
100 + }
101 +
102 + /**
103 + * Returns value of IPv6 TE Router Id of Local Node.
104 + *
105 + * @return byte array value of rawValue
106 + */
107 + public byte[] getValue() {
108 + return rawValue;
109 + }
110 +
111 + @Override
112 + public PcepVersion getVersion() {
113 + return PcepVersion.PCEP_1;
114 + }
115 +
116 + @Override
117 + public short getType() {
118 + return TYPE;
119 + }
120 +
121 + @Override
122 + public short getLength() {
123 + return LENGTH;
124 + }
125 +
126 + @Override
127 + public int hashCode() {
128 + return Objects.hash(rawValue);
129 + }
130 +
131 + @Override
132 + public boolean equals(Object obj) {
133 + if (this == obj) {
134 + return true;
135 + }
136 + if (obj instanceof IPv6TERouterIdofLocalNodeTlv) {
137 + IPv6TERouterIdofLocalNodeTlv other = (IPv6TERouterIdofLocalNodeTlv) obj;
138 + return Objects.equals(rawValue, other.rawValue);
139 + }
140 + return false;
141 + }
142 +
143 + @Override
144 + public int write(ChannelBuffer c) {
145 + int iStartIndex = c.writerIndex();
146 + c.writeShort(TYPE);
147 + c.writeShort(LENGTH);
148 + c.writeBytes(rawValue);
149 + return c.writerIndex() - iStartIndex;
150 + }
151 +
152 + /**
153 + * Reads the channel buffer and returns object of IPv6TERouterIdofLocalNodeTlv.
154 + *
155 + * @param c input channel buffer
156 + * @return object of IPv6TERouterIdofLocalNodeTlv
157 + */
158 + public static IPv6TERouterIdofLocalNodeTlv read20Bytes(ChannelBuffer c) {
159 + byte[] yTemp = new byte[20];
160 + c.readBytes(yTemp, 0, 20);
161 + return IPv6TERouterIdofLocalNodeTlv.of(yTemp);
162 + }
163 +
164 + @Override
165 + public String toString() {
166 + ToStringHelper toStrHelper = MoreObjects.toStringHelper(getClass());
167 +
168 + toStrHelper.add("Type", TYPE);
169 + toStrHelper.add("Length", LENGTH);
170 +
171 + StringBuffer result = new StringBuffer();
172 + for (byte b : rawValue) {
173 + result.append(String.format("%02X ", b));
174 + }
175 + toStrHelper.add("Value", result);
176 +
177 + return toStrHelper.toString();
178 + }
179 +}
1 +/*
2 + * Copyright 2015 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +package org.onosproject.pcepio.types;
17 +
18 +import java.util.Objects;
19 +
20 +import org.jboss.netty.buffer.ChannelBuffer;
21 +import org.onosproject.pcepio.protocol.PcepVersion;
22 +import org.slf4j.Logger;
23 +import org.slf4j.LoggerFactory;
24 +
25 +import com.google.common.base.MoreObjects;
26 +import com.google.common.base.MoreObjects.ToStringHelper;
27 +
28 +/**
29 + * Provides IPv6 TE Router Id of Remote Node. Reference :[RFC6119]/4.1.
30 + */
31 +public class IPv6TERouterIdofRemoteNodeTlv implements PcepValueType {
32 + protected static final Logger log = LoggerFactory.getLogger(IPv6TERouterIdofRemoteNodeTlv.class);
33 +
34 + public static final short TYPE = 1400; //TDB29
35 + public static final short LENGTH = 20;
36 + public static final byte VALUE_LENGTH = 18;
37 +
38 + private static final byte[] NONE_VAL = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
39 + public static final IPv6TERouterIdofRemoteNodeTlv NONE = new IPv6TERouterIdofRemoteNodeTlv(NONE_VAL);
40 +
41 + private static final byte[] NO_MASK_VAL = {(byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
42 + (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
43 + (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF};
44 + public static final IPv6TERouterIdofRemoteNodeTlv NO_MASK = new IPv6TERouterIdofRemoteNodeTlv(NO_MASK_VAL);
45 + public static final IPv6TERouterIdofRemoteNodeTlv FULL_MASK = NONE;
46 +
47 + private final byte[] rawValue;
48 +
49 + /**
50 + * constructor to initialize rawValue.
51 + *
52 + * @param rawValue IPv6TERouterIdofRemoteNodeTlv
53 + */
54 + public IPv6TERouterIdofRemoteNodeTlv(byte[] rawValue) {
55 + log.debug("IPv6TERouterIdofRemoteNodeTlv");
56 + this.rawValue = rawValue;
57 + }
58 +
59 + /**
60 + * Returns newly created IPv6TERouterIdofRemoteNodeTlv object.
61 + *
62 + * @param raw IPv6 TE Router Id of RemoteNode
63 + * @return object of IPv6TERouterIdofRemoteNodeTlv
64 + */
65 + public static IPv6TERouterIdofRemoteNodeTlv of(final byte[] raw) {
66 + //check NONE_VAL
67 + boolean bFoundNONE = true;
68 + //value starts from 3rd byte.
69 + for (int i = 2; i < 20; ++i) {
70 + if (NONE_VAL[i] != raw[i]) {
71 + bFoundNONE = false;
72 + }
73 + }
74 +
75 + if (bFoundNONE) {
76 + return NONE;
77 + }
78 +
79 + //check NO_MASK_VAL
80 + boolean bFoundNoMask = true;
81 + //value starts from 3rd byte.
82 + for (int i = 2; i < 20; ++i) {
83 + if (0xFF != raw[i]) {
84 + bFoundNoMask = false;
85 + }
86 + }
87 + if (bFoundNoMask) {
88 + return NO_MASK;
89 + }
90 +
91 + return new IPv6TERouterIdofRemoteNodeTlv(raw);
92 + }
93 +
94 + /**
95 + * Returns value of IPv6 TE Router Id of Remote Node.
96 + *
97 + * @return byte array value of rawValue
98 + */
99 + public byte[] getBytes() {
100 + return rawValue;
101 + }
102 +
103 + @Override
104 + public PcepVersion getVersion() {
105 + return PcepVersion.PCEP_1;
106 + }
107 +
108 + @Override
109 + public short getType() {
110 + return TYPE;
111 + }
112 +
113 + @Override
114 + public short getLength() {
115 + return LENGTH;
116 + }
117 +
118 + @Override
119 + public int hashCode() {
120 + return Objects.hash(rawValue);
121 + }
122 +
123 + @Override
124 + public boolean equals(Object obj) {
125 + if (this == obj) {
126 + return true;
127 + }
128 + if (obj instanceof IPv6TERouterIdofRemoteNodeTlv) {
129 + IPv6TERouterIdofRemoteNodeTlv other = (IPv6TERouterIdofRemoteNodeTlv) obj;
130 + return Objects.equals(rawValue, other.rawValue);
131 + }
132 + return false;
133 + }
134 +
135 + @Override
136 + public int write(ChannelBuffer c) {
137 + int iStartIndex = c.writerIndex();
138 + c.writeShort(TYPE);
139 + c.writeShort(LENGTH);
140 + c.writeBytes(rawValue);
141 + return c.writerIndex() - iStartIndex;
142 + }
143 +
144 + /**
145 + * Reads the channel buffer and returns object of IPv6TERouterIdofRemoteNodeTlv.
146 + *
147 + * @param c input channel buffer
148 + * @return object of IPv6TERouterIdofRemoteNodeTlv
149 + */
150 + public static IPv6TERouterIdofRemoteNodeTlv read20Bytes(ChannelBuffer c) {
151 + byte[] yTemp = new byte[20];
152 + c.readBytes(yTemp, 0, 20);
153 + return IPv6TERouterIdofRemoteNodeTlv.of(yTemp);
154 + }
155 +
156 + @Override
157 + public String toString() {
158 + ToStringHelper toStrHelper = MoreObjects.toStringHelper(getClass());
159 +
160 + toStrHelper.add("Type", TYPE);
161 + toStrHelper.add("Length", LENGTH);
162 +
163 + StringBuffer result = new StringBuffer();
164 + for (byte b : rawValue) {
165 + result.append(String.format("%02X ", b));
166 + }
167 + toStrHelper.add("Value", result);
168 +
169 + return toStrHelper.toString();
170 + }
171 +}
1 +/*
2 + * Copyright 2015 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +package org.onosproject.pcepio.types;
17 +
18 +import java.util.Objects;
19 +
20 +import org.jboss.netty.buffer.ChannelBuffer;
21 +import org.onosproject.pcepio.protocol.PcepVersion;
22 +import org.slf4j.Logger;
23 +import org.slf4j.LoggerFactory;
24 +
25 +import com.google.common.base.MoreObjects;
26 +import com.google.common.base.MoreObjects.ToStringHelper;
27 +
28 +/**
29 + * Provides ISIS Area Identifier.
30 + */
31 +public class ISISAreaIdentifierTlv implements PcepValueType {
32 +
33 + /* Reference :[I-D.ietf-idr- ls-distribution]/3.3.1.2
34 + * 0 1 2 3
35 + 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
36 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
37 + | Type=[TBD24] | Length |
38 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
39 + // Area Identifier (variable) //
40 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
41 + */
42 +
43 + protected static final Logger log = LoggerFactory.getLogger(ISISAreaIdentifierTlv.class);
44 +
45 + public static final short TYPE = 107; //TODO:NEED TO HANDLE TBD24
46 + private short hLength;
47 +
48 + private final byte[] rawValue;
49 +
50 + /**
51 + * Constructor to initialize rawValue.
52 + *
53 + * @param rawValue ISIS-Area-Identifier
54 + * @param hLength length
55 + */
56 + public ISISAreaIdentifierTlv(byte[] rawValue, short hLength) {
57 + log.debug("ISISAreaIdentifierTlv");
58 + this.rawValue = rawValue;
59 + if (0 == hLength) {
60 + this.hLength = (short) rawValue.length;
61 + } else {
62 + this.hLength = hLength;
63 + }
64 + }
65 +
66 + /**
67 + * Returns newly created ISISAreaIdentifierTlv object.
68 + *
69 + * @param raw ISIS-Area-Identifier
70 + * @param hLength length
71 + * @return object of ISISAreaIdentifierTlv
72 + */
73 + public static ISISAreaIdentifierTlv of(final byte[] raw, short hLength) {
74 + return new ISISAreaIdentifierTlv(raw, hLength);
75 + }
76 +
77 + /**
78 + * Returns value of ISIS-Area-Identifier.
79 + *
80 + * @return byte array of rawValue
81 + */
82 + public byte[] getValue() {
83 + return rawValue;
84 + }
85 +
86 + @Override
87 + public PcepVersion getVersion() {
88 + return PcepVersion.PCEP_1;
89 + }
90 +
91 + @Override
92 + public short getType() {
93 + return TYPE;
94 + }
95 +
96 + @Override
97 + public short getLength() {
98 + return hLength;
99 + }
100 +
101 + @Override
102 + public int hashCode() {
103 + return Objects.hash(rawValue);
104 + }
105 +
106 + @Override
107 + public boolean equals(Object obj) {
108 + if (this == obj) {
109 + return true;
110 + }
111 + if (obj instanceof ISISAreaIdentifierTlv) {
112 + ISISAreaIdentifierTlv other = (ISISAreaIdentifierTlv) obj;
113 + return Objects.equals(hLength, other.hLength) && Objects.equals(rawValue, other.rawValue);
114 + }
115 + return false;
116 + }
117 +
118 + @Override
119 + public int write(ChannelBuffer c) {
120 + int iLenStartIndex = c.writerIndex();
121 + c.writeShort(TYPE);
122 + c.writeShort(hLength);
123 + c.writeBytes(rawValue);
124 + return c.writerIndex() - iLenStartIndex;
125 + }
126 +
127 + /**
128 + * Reads the channel buffer and returns object of ISISAreaIdentifierTlv.
129 + *
130 + * @param c input channel buffer
131 + * @param hLength length
132 + * @return object of ISISAreaIdentifierTlv
133 + */
134 + public static PcepValueType read(ChannelBuffer c, short hLength) {
135 + byte[] iISISAreaIdentifier = new byte[hLength];
136 + c.readBytes(iISISAreaIdentifier, 0, hLength);
137 + return new ISISAreaIdentifierTlv(iISISAreaIdentifier, hLength);
138 + }
139 +
140 + @Override
141 + public String toString() {
142 + ToStringHelper toStrHelper = MoreObjects.toStringHelper(getClass());
143 +
144 + toStrHelper.add("Type", TYPE);
145 + toStrHelper.add("Length", hLength);
146 +
147 + StringBuffer result = new StringBuffer();
148 + for (byte b : rawValue) {
149 + result.append(String.format("%02X ", b));
150 + }
151 + toStrHelper.add("Value", result);
152 +
153 + return toStrHelper.toString();
154 + }
155 +}
1 +/*
2 + * Copyright 2015 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +package org.onosproject.pcepio.types;
17 +
18 +import java.util.Objects;
19 +
20 +import org.jboss.netty.buffer.ChannelBuffer;
21 +import org.onosproject.pcepio.protocol.PcepVersion;
22 +import org.slf4j.Logger;
23 +import org.slf4j.LoggerFactory;
24 +
25 +import com.google.common.base.MoreObjects;
26 +
27 +/**
28 + * Provides Local and remote Link Identifiers.
29 + */
30 +public class LinkLocalRemoteIdentifiersTlv implements PcepValueType {
31 +
32 + /* Reference :RFC5307
33 + * 0 1 2 3
34 + 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
35 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
36 + | Type=4 | Length=8 |
37 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
38 + | Link Local Identifier |
39 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
40 + | Link Remote Identifier |
41 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
42 +
43 + */
44 + protected static final Logger log = LoggerFactory.getLogger(LinkLocalRemoteIdentifiersTlv.class);
45 +
46 + public static final short TYPE = 4;
47 + public static final short LENGTH = 8;
48 + private final int iLinkLocalIdentifier;
49 + private final int iLinkRemoteIdentifier;
50 +
51 + /**
52 + * Constructor to initialize iLinkLocalIdentifier , iLinkRemoteIdentifier.
53 + *
54 + * @param iLinkLocalIdentifier Link Local identifier
55 + * @param iLinkRemoteIdentifier Link Remote identifier
56 + */
57 + public LinkLocalRemoteIdentifiersTlv(int iLinkLocalIdentifier, int iLinkRemoteIdentifier) {
58 + this.iLinkLocalIdentifier = iLinkLocalIdentifier;
59 + this.iLinkRemoteIdentifier = iLinkRemoteIdentifier;
60 + }
61 +
62 + /**
63 + * Retruns an object of Link Local Remote Identifiers Tlv.
64 + *
65 + * @param iLinkLocalIdentifier Link Local identifier
66 + * @param iLinkRemoteIdentifier Link Remote identifier
67 + * @return object of LinkLocalRemoteIdentifiersTlv
68 + */
69 + public static LinkLocalRemoteIdentifiersTlv of(int iLinkLocalIdentifier, int iLinkRemoteIdentifier) {
70 + return new LinkLocalRemoteIdentifiersTlv(iLinkLocalIdentifier, iLinkRemoteIdentifier);
71 + }
72 +
73 + /**
74 + * Returns Link-Local-Identifier.
75 + *
76 + * @return iLinkLocalIdentifier Link Local Identifier
77 + */
78 + public int getLinkLocalIdentifier() {
79 + return iLinkLocalIdentifier;
80 + }
81 +
82 + /**
83 + * Returns Link-Remote-Identifier.
84 + *
85 + * @return iLinkRemoteIdentifier Link Remote Identifier.
86 + */
87 + public int getLinkRemoteIdentifier() {
88 + return iLinkRemoteIdentifier;
89 + }
90 +
91 + @Override
92 + public PcepVersion getVersion() {
93 + return PcepVersion.PCEP_1;
94 + }
95 +
96 + @Override
97 + public short getLength() {
98 + return LENGTH;
99 + }
100 +
101 + @Override
102 + public short getType() {
103 + return TYPE;
104 + }
105 +
106 + @Override
107 + public int hashCode() {
108 + return Objects.hash(iLinkLocalIdentifier, iLinkRemoteIdentifier);
109 + }
110 +
111 + @Override
112 + public boolean equals(Object obj) {
113 + if (this == obj) {
114 + return true;
115 + }
116 + if (obj instanceof LinkLocalRemoteIdentifiersTlv) {
117 + LinkLocalRemoteIdentifiersTlv other = (LinkLocalRemoteIdentifiersTlv) obj;
118 + return Objects.equals(iLinkLocalIdentifier, other.iLinkLocalIdentifier)
119 + && Objects.equals(iLinkRemoteIdentifier, other.iLinkRemoteIdentifier);
120 + }
121 + return false;
122 + }
123 +
124 + @Override
125 + public int write(ChannelBuffer c) {
126 + int iStartIndex = c.writerIndex();
127 + c.writeShort(TYPE);
128 + c.writeShort(LENGTH);
129 + c.writeInt(iLinkLocalIdentifier);
130 + c.writeInt(iLinkRemoteIdentifier);
131 + return c.writerIndex() - iStartIndex;
132 + }
133 +
134 + /**
135 + * Reads the channel buffer and returns object of LinkLocalRemoteIdentifiersTlv.
136 + *
137 + * @param c input channel buffer
138 + * @return object of LinkLocalRemoteIdentifiersTlv
139 + */
140 + public static PcepValueType read(ChannelBuffer c) {
141 + int iLinkLocalIdentifier = c.readInt();
142 + int iLinkRemoteIdentifier = c.readInt();
143 + return new LinkLocalRemoteIdentifiersTlv(iLinkLocalIdentifier, iLinkRemoteIdentifier);
144 + }
145 +
146 + @Override
147 + public String toString() {
148 + return MoreObjects.toStringHelper(getClass()).add("Type", TYPE).add("Length", LENGTH)
149 + .add("LinkLocalIdentifier", iLinkLocalIdentifier).add("LinkRemoteIdentifier", iLinkRemoteIdentifier)
150 + .toString();
151 + }
152 +}
1 +/*
2 + * Copyright 2015 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +package org.onosproject.pcepio.types;
17 +
18 +import java.util.Objects;
19 +
20 +import org.jboss.netty.buffer.ChannelBuffer;
21 +import org.onosproject.pcepio.protocol.PcepVersion;
22 +import org.slf4j.Logger;
23 +import org.slf4j.LoggerFactory;
24 +
25 +import com.google.common.base.MoreObjects;
26 +import com.google.common.base.MoreObjects.ToStringHelper;
27 +
28 +/**
29 + * Provides the Link Name.
30 + */
31 +public class LinkNameTlv implements PcepValueType {
32 +
33 + /* Reference :[I-D.ietf-idr- ls-distribution] /3.3.2.7
34 + * Link name tlv format.
35 + 0 1 2 3
36 + 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
37 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
38 + | Type=TDB43 | Length |
39 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
40 + // Link Name (variable) //
41 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
42 + */
43 +
44 + protected static final Logger log = LoggerFactory.getLogger(LinkNameTlv.class);
45 +
46 + public static final short TYPE = 1098; //TODO:NEED TO HANDLE TDB43
47 + private short hLength;
48 +
49 + private final byte[] rawValue;
50 +
51 + /**
52 + * Constructor to initialize rawValue.
53 + *
54 + * @param rawValue Link-Name
55 + * @param hLength length
56 + */
57 + public LinkNameTlv(byte[] rawValue, short hLength) {
58 + this.rawValue = rawValue;
59 + if (0 == hLength) {
60 + this.hLength = (short) rawValue.length;
61 + } else {
62 + this.hLength = hLength;
63 + }
64 + }
65 +
66 + /**
67 + * Returns newly created LinkNameTlv object.
68 + *
69 + * @param raw Link-Name
70 + * @param hLength length
71 + * @return object of LinkNameTlv
72 + */
73 + public static LinkNameTlv of(final byte[] raw, short hLength) {
74 + return new LinkNameTlv(raw, hLength);
75 + }
76 +
77 + /**
78 + * Returns value of Link-Name.
79 + *
80 + * @return raw value
81 + */
82 + public byte[] getValue() {
83 + return rawValue;
84 + }
85 +
86 + @Override
87 + public PcepVersion getVersion() {
88 + return PcepVersion.PCEP_1;
89 + }
90 +
91 + @Override
92 + public short getType() {
93 + return TYPE;
94 + }
95 +
96 + @Override
97 + public short getLength() {
98 + return hLength;
99 + }
100 +
101 + @Override
102 + public int hashCode() {
103 + return Objects.hash(rawValue);
104 + }
105 +
106 + @Override
107 + public boolean equals(Object obj) {
108 + if (this == obj) {
109 + return true;
110 + }
111 + if (obj instanceof LinkNameTlv) {
112 + LinkNameTlv other = (LinkNameTlv) obj;
113 + return Objects.equals(rawValue, other.rawValue);
114 + }
115 + return false;
116 + }
117 +
118 + @Override
119 + public int write(ChannelBuffer c) {
120 + int iLenStartIndex = c.writerIndex();
121 + c.writeShort(TYPE);
122 + c.writeShort(hLength);
123 + c.writeBytes(rawValue);
124 + return c.writerIndex() - iLenStartIndex;
125 + }
126 +
127 + /**
128 + * Reads the channel buffer and returns object of LinkNameTlv.
129 + *
130 + * @param c input channel buffer
131 + * @param hLength length
132 + * @return object of LinkNameTlv
133 + */
134 + public static PcepValueType read(ChannelBuffer c, short hLength) {
135 + byte[] linkName = new byte[hLength];
136 + c.readBytes(linkName, 0, hLength);
137 + return new LinkNameTlv(linkName, hLength);
138 + }
139 +
140 + @Override
141 + public String toString() {
142 + ToStringHelper toStrHelper = MoreObjects.toStringHelper(getClass());
143 +
144 + toStrHelper.add("Type", TYPE);
145 + toStrHelper.add("Length", hLength);
146 +
147 + StringBuffer result = new StringBuffer();
148 + for (byte b : rawValue) {
149 + result.append(String.format("%02X ", b));
150 + }
151 + toStrHelper.add("Value", result);
152 +
153 + return toStrHelper.toString();
154 + }
155 +}
1 +/*
2 + * Copyright 2015 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +package org.onosproject.pcepio.types;
17 +
18 +import java.util.Objects;
19 +
20 +import org.jboss.netty.buffer.ChannelBuffer;
21 +import org.onosproject.pcepio.protocol.PcepVersion;
22 +import org.slf4j.Logger;
23 +import org.slf4j.LoggerFactory;
24 +
25 +import com.google.common.base.MoreObjects;
26 +
27 +/**
28 + * Provide Link Protection Type.
29 + */
30 +
31 +public class LinkProtectionTypeTlv implements PcepValueType {
32 +
33 + /* Reference :[RFC5307]/1.2
34 + * 0 1 2 3
35 + 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
36 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
37 + | Type=[TDB38] | Length=2 |
38 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
39 + |Protection Cap | Reserved |
40 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
41 + */
42 + protected static final Logger log = LoggerFactory.getLogger(LinkProtectionTypeTlv.class);
43 +
44 + public static final short TYPE = 20; //TDB38
45 + public static final short LENGTH = 2;
46 + private final byte protectionCap;
47 + private final byte reserved;
48 +
49 + /**
50 + * Constructor to initialize protectionCap.
51 + *
52 + * @param protectionCap Protection Cap
53 + */
54 + public LinkProtectionTypeTlv(byte protectionCap) {
55 + this.protectionCap = protectionCap;
56 + this.reserved = 0;
57 + }
58 +
59 + /**
60 + * Constructor to initialize protectionCap, reserved.
61 + *
62 + * @param protectionCap Protection Cap
63 + * @param reserved Reserved value
64 + */
65 + public LinkProtectionTypeTlv(byte protectionCap, byte reserved) {
66 + this.protectionCap = protectionCap;
67 + this.reserved = reserved;
68 + }
69 +
70 + /**
71 + * Returns Protection Cap.
72 + *
73 + * @return protectionCap Protection Cap
74 + */
75 + public byte getProtectionCap() {
76 + return protectionCap;
77 + }
78 +
79 + @Override
80 + public PcepVersion getVersion() {
81 + return PcepVersion.PCEP_1;
82 + }
83 +
84 + @Override
85 + public short getType() {
86 + return TYPE;
87 + }
88 +
89 + @Override
90 + public short getLength() {
91 + return LENGTH;
92 + }
93 +
94 + @Override
95 + public int hashCode() {
96 + return Objects.hash(protectionCap, reserved);
97 + }
98 +
99 + @Override
100 + public boolean equals(Object obj) {
101 + if (this == obj) {
102 + return true;
103 + }
104 + if (obj instanceof LinkProtectionTypeTlv) {
105 + LinkProtectionTypeTlv other = (LinkProtectionTypeTlv) obj;
106 + return Objects.equals(protectionCap, other.protectionCap) && Objects.equals(reserved, other.reserved);
107 + }
108 +
109 + return false;
110 + }
111 +
112 + @Override
113 + public int write(ChannelBuffer c) {
114 + int iLenStartIndex = c.writerIndex();
115 + c.writeShort(TYPE);
116 + c.writeShort(LENGTH);
117 + c.writeByte(protectionCap);
118 + c.writeByte(reserved);
119 + return c.writerIndex() - iLenStartIndex;
120 + }
121 +
122 + /**
123 + * Reads the channel buffer and returns object of LinkProtectionTypeTlv.
124 + *
125 + * @param c input channel buffer
126 + * @return object of LinkProtectionTypeTlv
127 + */
128 + public static PcepValueType read(ChannelBuffer c) {
129 + byte protectionCap = c.readByte();
130 + byte reserved = c.readByte();
131 + return new LinkProtectionTypeTlv(protectionCap, reserved);
132 + }
133 +
134 + @Override
135 + public String toString() {
136 + return MoreObjects.toStringHelper(getClass()).add("Type", TYPE).add("Length", LENGTH)
137 + .add("ProtectionCap", protectionCap).toString();
138 + }
139 +}
...\ No newline at end of file ...\ No newline at end of file
1 +/*
2 + * Copyright 2015 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +package org.onosproject.pcepio.types;
17 +
18 +import java.util.Iterator;
19 +import java.util.LinkedList;
20 +import java.util.ListIterator;
21 +import java.util.Objects;
22 +
23 +import org.jboss.netty.buffer.ChannelBuffer;
24 +import org.onosproject.pcepio.exceptions.PcepParseException;
25 +import org.onosproject.pcepio.protocol.PcepVersion;
26 +import org.slf4j.Logger;
27 +import org.slf4j.LoggerFactory;
28 +
29 +import com.google.common.base.MoreObjects;
30 +
31 +/**
32 + * Provides Local TE Node Descriptors TLV which contains Node Descriptor Sub-TLVs.
33 + */
34 +public class LocalTENodeDescriptorsTLV implements PcepValueType {
35 +
36 + /* REFERENCE :draft-ietf-idr-ls-distribution-10
37 + * 0 1 2 3
38 + 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
39 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
40 + | Type=[TBD8] | Length |
41 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
42 + | |
43 + // Node Descriptor Sub-TLVs (variable) //
44 + | |
45 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
46 + Note: Length is including header here. Refer Routing Universe TLV.
47 + */
48 +
49 + protected static final Logger log = LoggerFactory.getLogger(LocalTENodeDescriptorsTLV.class);
50 +
51 + public static final short TYPE = 1637; //TODD:change this TBD8
52 + public short hLength;
53 +
54 + public static final int TLV_HEADER_LENGTH = 4;
55 + // Node Descriptor Sub-TLVs (variable)
56 + private LinkedList<PcepValueType> llNodeDescriptorSubTLVs;
57 +
58 + /**
59 + * Constructor to initialize llNodeDescriptorSubTLVs.
60 + *
61 + * @param llNodeDescriptorSubTLVs LinkedList of PcepValueType
62 + */
63 + public LocalTENodeDescriptorsTLV(LinkedList<PcepValueType> llNodeDescriptorSubTLVs) {
64 + this.llNodeDescriptorSubTLVs = llNodeDescriptorSubTLVs;
65 + }
66 +
67 + /**
68 + * Returns a new object of LocalTENodeDescriptorsTLV.
69 + *
70 + * @param llNodeDescriptorSubTLVs linked list of Node Descriptor Sub TLVs
71 + * @return object of LocalTENodeDescriptorsTLV
72 + */
73 + public static LocalTENodeDescriptorsTLV of(final LinkedList<PcepValueType> llNodeDescriptorSubTLVs) {
74 + return new LocalTENodeDescriptorsTLV(llNodeDescriptorSubTLVs);
75 + }
76 +
77 + /**
78 + * Returns Linked List of tlvs.
79 + *
80 + * @return llNodeDescriptorSubTLVs linked list of Node Descriptor Sub TLV
81 + */
82 + public LinkedList<PcepValueType> getllNodeDescriptorSubTLVs() {
83 + return llNodeDescriptorSubTLVs;
84 + }
85 +
86 + @Override
87 + public PcepVersion getVersion() {
88 + return PcepVersion.PCEP_1;
89 + }
90 +
91 + @Override
92 + public short getType() {
93 + return TYPE;
94 + }
95 +
96 + @Override
97 + public short getLength() {
98 + return hLength;
99 + }
100 +
101 + @Override
102 + public int hashCode() {
103 + return Objects.hash(llNodeDescriptorSubTLVs.hashCode());
104 + }
105 +
106 + @Override
107 + public boolean equals(Object obj) {
108 + if (this == obj) {
109 + return true;
110 + }
111 +
112 + /*
113 + * Here we have a list of Tlv so to compare each sub tlv between the object
114 + * we have to take a list iterator so one by one we can get each sub tlv object
115 + * and can compare them.
116 + * it may be possible that the size of 2 lists is not equal so we have to first check
117 + * the size, if both are same then we should check for the subtlv objects otherwise
118 + * we should return false.
119 + */
120 + if (obj instanceof LocalTENodeDescriptorsTLV) {
121 + int countObjSubTlv = 0;
122 + int countOtherSubTlv = 0;
123 + boolean isCommonSubTlv = true;
124 + LocalTENodeDescriptorsTLV other = (LocalTENodeDescriptorsTLV) obj;
125 + Iterator<PcepValueType> objListIterator = ((LocalTENodeDescriptorsTLV) obj).llNodeDescriptorSubTLVs
126 + .iterator();
127 + countObjSubTlv = ((LocalTENodeDescriptorsTLV) obj).llNodeDescriptorSubTLVs.size();
128 + countOtherSubTlv = other.llNodeDescriptorSubTLVs.size();
129 + if (countObjSubTlv != countOtherSubTlv) {
130 + return false;
131 + } else {
132 + while (objListIterator.hasNext() && isCommonSubTlv) {
133 + PcepValueType subTlv = objListIterator.next();
134 + isCommonSubTlv = Objects.equals(llNodeDescriptorSubTLVs.contains(subTlv),
135 + other.llNodeDescriptorSubTLVs.contains(subTlv));
136 + }
137 + return isCommonSubTlv;
138 + }
139 + }
140 + return false;
141 + }
142 +
143 + @Override
144 + public int write(ChannelBuffer c) {
145 + int tlvStartIndex = c.writerIndex();
146 + c.writeShort(TYPE);
147 + int tlvLenIndex = c.writerIndex();
148 + hLength = 0;
149 + c.writeShort(0);
150 +
151 + ListIterator<PcepValueType> listIterator = llNodeDescriptorSubTLVs.listIterator();
152 +
153 + while (listIterator.hasNext()) {
154 + PcepValueType tlv = listIterator.next();
155 + if (null == tlv) {
156 + log.debug("TLV is null from subTlv list");
157 + continue;
158 + }
159 + tlv.write(c);
160 +
161 + // need to take care of padding
162 + int pad = tlv.getLength() % 4;
163 +
164 + if (0 != pad) {
165 + pad = 4 - pad;
166 + for (int i = 0; i < pad; ++i) {
167 + c.writeByte((byte) 0);
168 + }
169 + }
170 + }
171 + hLength = (short) (c.writerIndex() - tlvStartIndex);
172 + c.setShort(tlvLenIndex, hLength);
173 + return c.writerIndex() - tlvStartIndex;
174 + }
175 +
176 + /**
177 + * Reads the channel buffer and returns object of AutonomousSystemTlv.
178 + *
179 + * @param c input channel buffer
180 + * @param hLength length of subtlvs.
181 + * @return object of AutonomousSystemTlv
182 + * @throws PcepParseException if mandatory fields are missing
183 + */
184 + public static PcepValueType read(ChannelBuffer c, short hLength) throws PcepParseException {
185 +
186 + // Node Descriptor Sub-TLVs (variable)
187 + LinkedList<PcepValueType> llNodeDescriptorSubTLVs = new LinkedList<PcepValueType>();
188 +
189 + ChannelBuffer tempCb = c.readBytes(hLength - TLV_HEADER_LENGTH);
190 +
191 + while (TLV_HEADER_LENGTH <= tempCb.readableBytes()) {
192 +
193 + PcepValueType tlv;
194 + short hType = tempCb.readShort();
195 + int iValue = 0;
196 + short length = tempCb.readShort();
197 +
198 + switch (hType) {
199 +
200 + case AutonomousSystemTlv.TYPE:
201 + iValue = tempCb.readInt();
202 + tlv = new AutonomousSystemTlv(iValue);
203 + break;
204 + case BGPLSidentifierTlv.TYPE:
205 + iValue = tempCb.readInt();
206 + tlv = new BGPLSidentifierTlv(iValue);
207 + break;
208 + case OSPFareaIDsubTlv.TYPE:
209 + iValue = tempCb.readInt();
210 + tlv = new OSPFareaIDsubTlv(iValue);
211 + break;
212 + case RouterIDSubTlv.TYPE:
213 + tlv = RouterIDSubTlv.read(tempCb, length);
214 + break;
215 +
216 + default:
217 + throw new PcepParseException("Unsupported Sub TLV type :" + hType);
218 + }
219 +
220 + // Check for the padding
221 + int pad = length % 4;
222 + if (0 < pad) {
223 + pad = 4 - pad;
224 + if (pad <= tempCb.readableBytes()) {
225 + tempCb.skipBytes(pad);
226 + }
227 + }
228 +
229 + llNodeDescriptorSubTLVs.add(tlv);
230 + }
231 +
232 + if (0 < tempCb.readableBytes()) {
233 + throw new PcepParseException("Sub Tlv parsing error. Extra bytes received.");
234 + }
235 + return new LocalTENodeDescriptorsTLV(llNodeDescriptorSubTLVs);
236 + }
237 +
238 + @Override
239 + public String toString() {
240 + return MoreObjects.toStringHelper(getClass()).add("Type", TYPE).add("Length", hLength)
241 + .add("NodeDescriptorSubTLVs", llNodeDescriptorSubTLVs).toString();
242 + }
243 +}
1 +/*
2 + * Copyright 2015 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +package org.onosproject.pcepio.types;
17 +
18 +import java.util.Objects;
19 +
20 +import org.jboss.netty.buffer.ChannelBuffer;
21 +import org.onosproject.pcepio.protocol.PcepVersion;
22 +import org.slf4j.Logger;
23 +import org.slf4j.LoggerFactory;
24 +
25 +import com.google.common.base.MoreObjects;
26 +
27 +/**
28 + * Provides MPLS Protocol Mask.
29 + */
30 +public class MPLSProtocolMaskTlv implements PcepValueType {
31 +
32 + /* Reference :[I-D.ietf-idr-ls-distribution]/3.3.2.2
33 + * 0 1 2 3
34 + 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
35 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
36 + | Type=TDB39 | Length =1 |
37 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
38 + |L|R| Reserved |
39 + +-+-+-+-+-+-+-+-+
40 + */
41 + protected static final Logger log = LoggerFactory.getLogger(MPLSProtocolMaskTlv.class);
42 +
43 + public static final short TYPE = 1094; //TDB39
44 + public static final short LENGTH = 1;
45 + public static final int SET = 1;
46 + public static final byte LFLAG_SET = (byte) 0x80;
47 + public static final byte RFLAG_SET = 0x40;
48 +
49 + private final byte rawValue;
50 + private final boolean bLFlag;
51 + private final boolean bRFlag;
52 + private final boolean isRawValueSet;
53 +
54 + /**
55 + * constructor to initialize rawValue.
56 + *
57 + * @param rawValue MPLS Protocol Mask Flag Bits
58 + */
59 + public MPLSProtocolMaskTlv(byte rawValue) {
60 + this.rawValue = rawValue;
61 + isRawValueSet = true;
62 + byte temp = rawValue;
63 + if ((temp & LFLAG_SET) == SET) {
64 + this.bLFlag = true;
65 +
66 + } else {
67 + this.bLFlag = false;
68 + }
69 + if ((temp & RFLAG_SET) == SET) {
70 + this.bRFlag = true;
71 + } else {
72 + this.bRFlag = false;
73 + }
74 + }
75 +
76 + /**
77 + * constructor to initialize different Flags.
78 + *
79 + * @param bLFlag L-flag
80 + * @param bRFlag R-flag
81 + */
82 + public MPLSProtocolMaskTlv(boolean bLFlag, boolean bRFlag) {
83 + this.bLFlag = bLFlag;
84 + this.bRFlag = bRFlag;
85 + this.rawValue = 0;
86 + isRawValueSet = false;
87 + }
88 +
89 + /**
90 + * Returns newly created MPLSProtocolMaskTlv object.
91 + *
92 + * @param raw MPLS Protocol Mask Tlv
93 + * @return new object of MPLS Protocol Mask Tlv
94 + */
95 + public static MPLSProtocolMaskTlv of(final byte raw) {
96 + return new MPLSProtocolMaskTlv(raw);
97 + }
98 +
99 + /**
100 + * Returns L-flag.
101 + *
102 + * @return bLFlag L-flag
103 + */
104 + public boolean getbLFlag() {
105 + return bLFlag;
106 + }
107 +
108 + /**
109 + * Returns R-flag.
110 + *
111 + * @return bRFlag R-flag
112 + */
113 + public boolean getbRFlag() {
114 + return bRFlag;
115 + }
116 +
117 + /**
118 + * Returns raw value.
119 + *
120 + * @return rawValue raw value
121 + */
122 + public byte getByte() {
123 + return rawValue;
124 + }
125 +
126 + @Override
127 + public PcepVersion getVersion() {
128 + return PcepVersion.PCEP_1;
129 + }
130 +
131 + @Override
132 + public short getType() {
133 + return TYPE;
134 + }
135 +
136 + @Override
137 + public short getLength() {
138 + return LENGTH;
139 + }
140 +
141 + @Override
142 + public int hashCode() {
143 + if (isRawValueSet) {
144 + return Objects.hash(rawValue);
145 + } else {
146 + return Objects.hash(bLFlag, bRFlag);
147 + }
148 + }
149 +
150 + @Override
151 + public boolean equals(Object obj) {
152 + if (this == obj) {
153 + return true;
154 + }
155 + if (obj instanceof MPLSProtocolMaskTlv) {
156 + MPLSProtocolMaskTlv other = (MPLSProtocolMaskTlv) obj;
157 + if (isRawValueSet) {
158 + return Objects.equals(this.bLFlag, other.bLFlag) && Objects.equals(this.bRFlag, other.bRFlag);
159 + } else {
160 + return Objects.equals(this.rawValue, other.rawValue);
161 + }
162 + }
163 + return false;
164 + }
165 +
166 + @Override
167 + public int write(ChannelBuffer c) {
168 + int iLenStartIndex = c.writerIndex();
169 + c.writeShort(TYPE);
170 + c.writeShort(LENGTH);
171 + if (isRawValueSet) {
172 + c.writeByte(rawValue);
173 + } else {
174 + byte temp = 0;
175 + if (bLFlag) {
176 + temp = (byte) (temp | LFLAG_SET);
177 + }
178 + if (bRFlag) {
179 + temp = (byte) (temp | RFLAG_SET);
180 + }
181 + c.writeByte(temp);
182 + }
183 + return c.writerIndex() - iLenStartIndex;
184 + }
185 +
186 + /**
187 + * Reads the channel buffer and returns object of MPLS Protocol Mask Tlv.
188 + *
189 + * @param c input channel buffer
190 + * @return object of MPLS Protocol Mask Tlv
191 + */
192 + public static PcepValueType read(ChannelBuffer c) {
193 + byte temp = c.readByte();
194 + boolean bLFlag;
195 + boolean bRFlag;
196 +
197 + if ((temp & LFLAG_SET) == SET) {
198 + bLFlag = true;
199 + } else {
200 + bLFlag = false;
201 + }
202 + if ((temp & RFLAG_SET) == SET) {
203 + bRFlag = true;
204 + } else {
205 + bRFlag = false;
206 + }
207 + return new MPLSProtocolMaskTlv(bLFlag, bRFlag);
208 + }
209 +
210 + @Override
211 + public String toString() {
212 + return MoreObjects.toStringHelper(getClass()).add("Type", TYPE).add("Length", LENGTH).add("Value", rawValue)
213 + .toString();
214 + }
215 +}
1 +/*
2 + * Copyright 2015 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +package org.onosproject.pcepio.types;
17 +
18 +import java.util.Objects;
19 +
20 +import org.jboss.netty.buffer.ChannelBuffer;
21 +import org.onosproject.pcepio.protocol.PcepVersion;
22 +import org.slf4j.Logger;
23 +import org.slf4j.LoggerFactory;
24 +
25 +import com.google.common.base.MoreObjects;
26 +
27 +/**
28 + * Provide the Maximum Link Bandwidth.
29 + */
30 +public class MaximumLinkBandwidthTlv implements PcepValueType {
31 +
32 + /* Reference :[RFC5305]/3.3.
33 + * 0 1 2 3
34 + 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
35 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
36 + | Type=[TDB34] | Length=4 |
37 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
38 + | Maximum Link Bandwidth |
39 + +-+-+-+-+-+-+-+-+-++-+-+-+-+-+-+-+-+-++-+-+-+-+-+-+-+-+-++-+-+-+-
40 + */
41 +
42 + protected static final Logger log = LoggerFactory.getLogger(MaximumLinkBandwidthTlv.class);
43 +
44 + public static final short TYPE = 9; //TDB34
45 + public static final short LENGTH = 4;
46 +
47 + private final int rawValue;
48 +
49 + /**
50 + * Constructor to initialize rawValue.
51 + *
52 + * @param rawValue Maximum-Link-Bandwidth
53 + */
54 +
55 + public MaximumLinkBandwidthTlv(int rawValue) {
56 + this.rawValue = rawValue;
57 + }
58 +
59 + /**
60 + * Returns newly created MaximumLinkBandwidthTlv object.
61 + *
62 + * @param raw value of Maximum-Link-Bandwidth
63 + * @return object of MaximumLinkBandwidthTlv
64 + */
65 + public static MaximumLinkBandwidthTlv of(final int raw) {
66 + return new MaximumLinkBandwidthTlv(raw);
67 + }
68 +
69 + /**
70 + * Returns value of Maximum Link Bandwidth.
71 + *
72 + * @return rawValue Maximum Link Bandwidth
73 + */
74 + public int getInt() {
75 + return rawValue;
76 + }
77 +
78 + @Override
79 + public PcepVersion getVersion() {
80 + return PcepVersion.PCEP_1;
81 + }
82 +
83 + @Override
84 + public short getType() {
85 + return TYPE;
86 + }
87 +
88 + @Override
89 + public short getLength() {
90 + return LENGTH;
91 + }
92 +
93 + @Override
94 + public int hashCode() {
95 + return Objects.hash(rawValue);
96 + }
97 +
98 + @Override
99 + public boolean equals(Object obj) {
100 + if (this == obj) {
101 + return true;
102 + }
103 + if (obj instanceof MaximumLinkBandwidthTlv) {
104 + MaximumLinkBandwidthTlv other = (MaximumLinkBandwidthTlv) obj;
105 + return Objects.equals(rawValue, other.rawValue);
106 + }
107 + return false;
108 + }
109 +
110 + @Override
111 + public int write(ChannelBuffer c) {
112 + int iLenStartIndex = c.writerIndex();
113 + c.writeShort(TYPE);
114 + c.writeShort(LENGTH);
115 + c.writeInt(rawValue);
116 + return c.writerIndex() - iLenStartIndex;
117 + }
118 +
119 + /**
120 + * Reads the channel buffer and returns object of MaximumLinkBandwidthTlv.
121 + *
122 + * @param c input channel buffer
123 + * @return object of MaximumLinkBandwidthTlv
124 + */
125 + public static MaximumLinkBandwidthTlv read(ChannelBuffer c) {
126 + return MaximumLinkBandwidthTlv.of(c.readInt());
127 + }
128 +
129 + @Override
130 + public String toString() {
131 + return MoreObjects.toStringHelper(getClass()).add("Type", TYPE).add("Length", LENGTH).add("Value", rawValue)
132 + .toString();
133 + }
134 +}
1 +/*
2 + * Copyright 2015 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +package org.onosproject.pcepio.types;
17 +
18 +import java.util.Objects;
19 +
20 +import org.jboss.netty.buffer.ChannelBuffer;
21 +import org.onosproject.pcepio.protocol.PcepVersion;
22 +import org.slf4j.Logger;
23 +import org.slf4j.LoggerFactory;
24 +
25 +import com.google.common.base.MoreObjects;
26 +
27 +/**
28 + * Provide the Maximum Reservable Link Bandwidth.
29 + */
30 +public class MaximumReservableLinkBandwidthTlv implements PcepValueType {
31 +
32 + /* Reference :[RFC5305]/3.5.
33 + * 0 1 2 3
34 + 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
35 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
36 + | Type=[TDB35] | Length=4 |
37 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
38 + | Maximum Reservable Link Bandwidth |
39 + +-+-+-+-+-+-+-+-+-++-+-+-+-+-+-+-+-+-++-+-+-+-+-+-+-+-+-++-+-+-+-
40 + */
41 +
42 + protected static final Logger log = LoggerFactory.getLogger(MaximumReservableLinkBandwidthTlv.class);
43 +
44 + public static final short TYPE = 10; // TDB35
45 + public static final short LENGTH = 4;
46 +
47 + private final int rawValue;
48 +
49 + /**
50 + * constructor to initialize rawValue.
51 + *
52 + * @param rawValue MaximumReservableLinkBandwidth
53 + */
54 + public MaximumReservableLinkBandwidthTlv(int rawValue) {
55 + log.debug("MaximumReservableLinkBandwidthTlv");
56 + this.rawValue = rawValue;
57 + }
58 +
59 + /**
60 + * Returns newly created MaximumReservableLinkBandwidth object.
61 + *
62 + * @param raw MaximumReservableLinkBandwidth
63 + * @return object of MaximumReservableLinkBandwidthTlv
64 + */
65 + public static MaximumReservableLinkBandwidthTlv of(final int raw) {
66 + return new MaximumReservableLinkBandwidthTlv(raw);
67 + }
68 +
69 + /**
70 + * Returns value of Maximum Reservable Link Bandwidth.
71 + * @return rawValue Maximum Reservable Link Bandwidth
72 + */
73 + public int getInt() {
74 + return rawValue;
75 + }
76 +
77 + @Override
78 + public PcepVersion getVersion() {
79 + return PcepVersion.PCEP_1;
80 + }
81 +
82 + @Override
83 + public short getType() {
84 + return TYPE;
85 + }
86 +
87 + @Override
88 + public short getLength() {
89 + return LENGTH;
90 + }
91 +
92 + @Override
93 + public int hashCode() {
94 + return Objects.hash(rawValue);
95 + }
96 +
97 + @Override
98 + public boolean equals(Object obj) {
99 + if (this == obj) {
100 + return true;
101 + }
102 + if (obj instanceof MaximumReservableLinkBandwidthTlv) {
103 + MaximumReservableLinkBandwidthTlv other = (MaximumReservableLinkBandwidthTlv) obj;
104 + return Objects.equals(this.rawValue, other.rawValue);
105 + }
106 + return false;
107 + }
108 +
109 + @Override
110 + public int write(ChannelBuffer c) {
111 + int iLenStartIndex = c.writerIndex();
112 + c.writeShort(TYPE);
113 + c.writeShort(LENGTH);
114 + c.writeInt(rawValue);
115 + return c.writerIndex() - iLenStartIndex;
116 + }
117 +
118 + /**
119 + * Reads the channel buffer and returns object of MaximumReservableLinkBandwidthTlv.
120 + *
121 + * @param c input channel buffer
122 + * @return object of MaximumReservableLinkBandwidthTlv
123 + */
124 + public static MaximumReservableLinkBandwidthTlv read(ChannelBuffer c) {
125 + return MaximumReservableLinkBandwidthTlv.of(c.readInt());
126 + }
127 +
128 + @Override
129 + public String toString() {
130 + return MoreObjects.toStringHelper(getClass()).add("Type", TYPE).add("Length", LENGTH).add("Value", rawValue)
131 + .toString();
132 + }
133 +}
1 +/*
2 + * Copyright 2015 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +package org.onosproject.pcepio.types;
17 +
18 +import java.util.Objects;
19 +import org.jboss.netty.buffer.ChannelBuffer;
20 +import org.onosproject.pcepio.protocol.PcepVersion;
21 +import org.slf4j.Logger;
22 +import org.slf4j.LoggerFactory;
23 +
24 +import com.google.common.base.MoreObjects;
25 +
26 +/**
27 + * Provide node Flags bits.
28 + */
29 +public class NodeFlagBitsTlv implements PcepValueType {
30 +
31 + /* Reference :[I-D.ietf-idr- ls-distribution] /3.3.1.1
32 + * 0 1 2 3
33 + 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
34 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
35 + | Type=[TBD21] | Length=1 |
36 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
37 + |O|T|E|B| Reserved|
38 + +-+-+-+-+-+-+-+-+-+
39 + */
40 +
41 + protected static final Logger log = LoggerFactory.getLogger(NodeFlagBitsTlv.class);
42 +
43 + public static final short TYPE = 14;
44 + public static final short LENGTH = 1;
45 + public static final int SET = 1;
46 + public static final byte OFLAG_SET = (byte) 0x80;
47 + public static final byte TFLAG_SET = 0x40;
48 + public static final byte EFLAG_SET = 0x20;
49 + public static final byte BFLAG_SET = 0x10;
50 +
51 + private final byte rawValue;
52 + private final boolean bOFlag;
53 + private final boolean bTFlag;
54 + private final boolean bEFlag;
55 + private final boolean bBFlag;
56 + private final boolean isRawValueSet;
57 +
58 + /**
59 + * constructor to initialize rawValue.
60 + *
61 + * @param rawValue of Node Flag Bits TLV
62 + */
63 + public NodeFlagBitsTlv(byte rawValue) {
64 + this.rawValue = rawValue;
65 + isRawValueSet = true;
66 + byte temp = rawValue;
67 + this.bOFlag = (temp & OFLAG_SET) == OFLAG_SET ? true : false;
68 + this.bTFlag = (temp & TFLAG_SET) == TFLAG_SET ? true : false;
69 + this.bEFlag = (temp & EFLAG_SET) == EFLAG_SET ? true : false;
70 + this.bBFlag = (temp & BFLAG_SET) == BFLAG_SET ? true : false;
71 + }
72 +
73 + /**
74 + * constructor to initialize different Flags.
75 + *
76 + * @param bOFlag O-flag
77 + * @param bTFlag T-flag
78 + * @param bEFlag E-flag
79 + * @param bBFlag B-flag
80 + */
81 + public NodeFlagBitsTlv(boolean bOFlag, boolean bTFlag, boolean bEFlag, boolean bBFlag) {
82 + this.bOFlag = bOFlag;
83 + this.bTFlag = bTFlag;
84 + this.bEFlag = bEFlag;
85 + this.bBFlag = bBFlag;
86 + this.rawValue = 0;
87 + this.isRawValueSet = false;
88 + }
89 +
90 + /**
91 + * Returns newly created NodeFlagBitsTlv object.
92 + *
93 + * @param raw of Node Flag Bits TLV
94 + * @return new object of NodeFlagBitsTlv
95 + */
96 + public static NodeFlagBitsTlv of(final byte raw) {
97 + return new NodeFlagBitsTlv(raw);
98 + }
99 +
100 + /**
101 + * Returns raw value of NodeFlagBitsTlv.
102 + *
103 + * @return rawValue raw value
104 + */
105 + public byte getbyte() {
106 + return rawValue;
107 + }
108 +
109 + /**
110 + * Returns O-flag.
111 + *
112 + * @return bOFlag O-flag
113 + */
114 + public boolean getOFlag() {
115 + return bOFlag;
116 + }
117 +
118 + /**
119 + * Returns T-flag.
120 + *
121 + * @return bTFlag T-flag
122 + */
123 + public boolean getTFlag() {
124 + return bTFlag;
125 + }
126 +
127 + /**
128 + * Returns E-flag.
129 + *
130 + * @return bEFlag E-flag
131 + */
132 + public boolean getEFlag() {
133 + return bEFlag;
134 + }
135 +
136 + /**
137 + * Returns B-flag.
138 + *
139 + * @return bBFlag B-flag
140 + */
141 + public boolean getBFlag() {
142 + return bBFlag;
143 + }
144 +
145 + @Override
146 + public PcepVersion getVersion() {
147 + return PcepVersion.PCEP_1;
148 + }
149 +
150 + @Override
151 + public short getType() {
152 + return TYPE;
153 + }
154 +
155 + @Override
156 + public short getLength() {
157 + return LENGTH;
158 + }
159 +
160 + @Override
161 + public int hashCode() {
162 + if (isRawValueSet) {
163 + return Objects.hash(rawValue);
164 + } else {
165 + return Objects.hash(bOFlag, bTFlag, bEFlag, bBFlag);
166 + }
167 + }
168 +
169 + @Override
170 + public boolean equals(Object obj) {
171 + if (this == obj) {
172 + return true;
173 + }
174 + if (obj instanceof NodeFlagBitsTlv) {
175 + NodeFlagBitsTlv other = (NodeFlagBitsTlv) obj;
176 + if (isRawValueSet) {
177 + return Objects.equals(this.bOFlag, other.bOFlag) && Objects.equals(this.bTFlag, other.bTFlag)
178 + && Objects.equals(this.bEFlag, other.bEFlag) && Objects.equals(this.bBFlag, other.bBFlag);
179 + } else {
180 + return Objects.equals(this.rawValue, other.rawValue);
181 + }
182 + }
183 + return false;
184 + }
185 +
186 + @Override
187 + public int write(ChannelBuffer c) {
188 + int iLenStartIndex = c.writerIndex();
189 + c.writeShort(TYPE);
190 + c.writeShort(LENGTH);
191 + if (isRawValueSet) {
192 + c.writeByte(rawValue);
193 + } else {
194 + byte temp = 0;
195 + if (bOFlag) {
196 + temp = (byte) (temp | OFLAG_SET);
197 + }
198 + if (bTFlag) {
199 + temp = (byte) (temp | TFLAG_SET);
200 + }
201 + if (bEFlag) {
202 + temp = (byte) (temp | EFLAG_SET);
203 + }
204 + if (bBFlag) {
205 + temp = (byte) (temp | BFLAG_SET);
206 + }
207 + c.writeByte(temp);
208 + }
209 + return c.writerIndex() - iLenStartIndex;
210 + }
211 +
212 + /**
213 + * Reads the channel buffer and returns object of NodeFlagBitsTlv.
214 + *
215 + * @param c input channel buffer
216 + * @return object of NodeFlagBitsTlv
217 + */
218 + public static PcepValueType read(ChannelBuffer c) {
219 +
220 + return NodeFlagBitsTlv.of(c.readByte());
221 + }
222 +
223 + @Override
224 + public String toString() {
225 + return MoreObjects.toStringHelper(getClass()).add("Type", TYPE).add("Length", LENGTH)
226 + .add("OFlag", (bOFlag) ? 1 : 0).add("TFlag", (bTFlag) ? 1 : 0).add("EFlag", (bEFlag) ? 1 : 0)
227 + .add("BFlag", (bBFlag) ? 1 : 0).toString();
228 + }
229 +}
1 +/*
2 + * Copyright 2015 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +package org.onosproject.pcepio.types;
17 +
18 +import java.util.Objects;
19 +import org.jboss.netty.buffer.ChannelBuffer;
20 +import org.onosproject.pcepio.protocol.PcepVersion;
21 +import org.slf4j.Logger;
22 +import org.slf4j.LoggerFactory;
23 +
24 +import com.google.common.base.MoreObjects;
25 +import com.google.common.base.MoreObjects.ToStringHelper;
26 +
27 +/**
28 + * Provide the name for the node.
29 + */
30 +public class NodeNameTlv implements PcepValueType {
31 +
32 + /* reference :[I-D.ietf-idr-ls-distribution]/3.3.1.3
33 + * 0 1 2 3
34 + 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
35 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
36 + | Type=[TBD23] | Length |
37 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
38 + // Node Name (variable) //
39 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
40 + */
41 +
42 + protected static final Logger log = LoggerFactory.getLogger(NodeNameTlv.class);
43 +
44 + public static final short TYPE = 1007; //TODO:check and change TBD23
45 + public final short hLength;
46 +
47 + private final byte[] rawValue;
48 +
49 + /**
50 + * constructor to initialize rawValue.
51 + *
52 + * @param rawValue of Node Name
53 + * @param hLength length
54 + */
55 + public NodeNameTlv(byte[] rawValue, short hLength) {
56 + log.debug("NodeNameTlv");
57 + this.rawValue = rawValue;
58 + if (0 == hLength) {
59 + this.hLength = (short) rawValue.length;
60 + } else {
61 + this.hLength = hLength;
62 + }
63 + }
64 +
65 + /**
66 + * Returns newly created NodeNameTlv object.
67 + *
68 + * @param raw of NodeName
69 + * @param hLength length
70 + * @return new object of Node Name Tlv
71 + */
72 + public static NodeNameTlv of(final byte[] raw, short hLength) {
73 + return new NodeNameTlv(raw, hLength);
74 + }
75 +
76 + /**
77 + * Returns RawValue for NodeName.
78 + *
79 + * @return rawValue raw value
80 + */
81 + public byte[] getValue() {
82 + return rawValue;
83 + }
84 +
85 + @Override
86 + public PcepVersion getVersion() {
87 + return PcepVersion.PCEP_1;
88 + }
89 +
90 + @Override
91 + public short getType() {
92 + return TYPE;
93 + }
94 +
95 + @Override
96 + public short getLength() {
97 + return hLength;
98 + }
99 +
100 + @Override
101 + public int hashCode() {
102 + return Objects.hash(rawValue);
103 + }
104 +
105 + @Override
106 + public boolean equals(Object obj) {
107 + if (this == obj) {
108 + return true;
109 + }
110 + if (obj instanceof NodeNameTlv) {
111 + NodeNameTlv other = (NodeNameTlv) obj;
112 + return Objects.equals(this.rawValue, other.rawValue);
113 + }
114 + return false;
115 + }
116 +
117 + @Override
118 + public int write(ChannelBuffer c) {
119 + int iLenStartIndex = c.writerIndex();
120 + c.writeShort(TYPE);
121 + c.writeShort(hLength);
122 + c.writeBytes(rawValue);
123 + return c.writerIndex() - iLenStartIndex;
124 + }
125 +
126 + /**
127 + * Reads the channel buffer and returns object of NodeNameTlv.
128 + *
129 + * @param c input channel buffer
130 + * @param hLength length
131 + * @return object of Node Name TLV
132 + */
133 + public static PcepValueType read(ChannelBuffer c, short hLength) {
134 + byte[] iNodeName = new byte[hLength];
135 + c.readBytes(iNodeName, 0, hLength);
136 + return new NodeNameTlv(iNodeName, hLength);
137 + }
138 +
139 + @Override
140 + public String toString() {
141 + ToStringHelper toStrHelper = MoreObjects.toStringHelper(getClass());
142 +
143 + toStrHelper.add("Type", TYPE);
144 + toStrHelper.add("Length", hLength);
145 +
146 + StringBuffer result = new StringBuffer();
147 + for (byte b : rawValue) {
148 + result.append(String.format("%02X ", b));
149 + }
150 + toStrHelper.add("Value", result);
151 +
152 + return toStrHelper.toString();
153 + }
154 +}
1 +/*
2 + * Copyright 2014 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +package org.onosproject.pcepio.types;
17 +
18 +import java.util.Objects;
19 +import org.jboss.netty.buffer.ChannelBuffer;
20 +import org.onosproject.pcepio.protocol.PcepVersion;
21 +import org.slf4j.Logger;
22 +import org.slf4j.LoggerFactory;
23 +
24 +import com.google.common.base.MoreObjects;
25 +
26 +/**
27 + * Provides area ID for OSPF area.
28 + */
29 +public class OSPFareaIDsubTlv implements PcepValueType {
30 +
31 + /* Reference :draft-ietf-idr-ls-distribution-10.
32 + * 0 1 2 3
33 + 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
34 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
35 + | Type=[TBD12] | Length=4 |
36 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
37 + | opaque value (32 Bit AS Number) |
38 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
39 + */
40 +
41 + protected static final Logger log = LoggerFactory.getLogger(OSPFareaIDsubTlv.class);
42 +
43 + public static final short TYPE = 600; //TODD:change this TBD12
44 + public static final short LENGTH = 4;
45 +
46 + private final int rawValue;
47 +
48 + /**
49 + * constructor to initialize rawValue.
50 + *
51 + * @param rawValue area ID for OSPF area.
52 + */
53 + public OSPFareaIDsubTlv(int rawValue) {
54 + this.rawValue = rawValue;
55 + }
56 +
57 + /**
58 + * Returns newly created OSPFareaIDsubTlv object.
59 + *
60 + * @param raw opaque value of AreaID
61 + * @return new object of OSPF area ID sub TLV
62 + */
63 + public static OSPFareaIDsubTlv of(final int raw) {
64 + return new OSPFareaIDsubTlv(raw);
65 + }
66 +
67 + /**
68 + * Returns RawValue opaque value of AreaID.
69 + *
70 + * @return rawValue Area ID
71 + */
72 + public int getInt() {
73 + return rawValue;
74 + }
75 +
76 + @Override
77 + public PcepVersion getVersion() {
78 + return PcepVersion.PCEP_1;
79 + }
80 +
81 + @Override
82 + public short getType() {
83 + return TYPE;
84 + }
85 +
86 + @Override
87 + public short getLength() {
88 + return LENGTH;
89 + }
90 +
91 + @Override
92 + public int hashCode() {
93 + return Objects.hash(rawValue);
94 + }
95 +
96 + @Override
97 + public boolean equals(Object obj) {
98 + if (this == obj) {
99 + return true;
100 + }
101 + if (obj instanceof OSPFareaIDsubTlv) {
102 + OSPFareaIDsubTlv other = (OSPFareaIDsubTlv) obj;
103 + return Objects.equals(this.rawValue, other.rawValue);
104 + }
105 + return false;
106 + }
107 +
108 + @Override
109 + public int write(ChannelBuffer c) {
110 + int iLenStartIndex = c.writerIndex();
111 + c.writeShort(TYPE);
112 + c.writeShort(LENGTH);
113 + c.writeInt(rawValue);
114 + return c.writerIndex() - iLenStartIndex;
115 + }
116 +
117 + /**
118 + * Reads the channel buffer and returns object of OSPFAreaIdSubTlv.
119 + *
120 + * @param c input channel buffer
121 + * @return object of OSPFAreaIdSubTlv
122 + */
123 + public static OSPFareaIDsubTlv read(ChannelBuffer c) {
124 + return OSPFareaIDsubTlv.of(c.readInt());
125 + }
126 +
127 + @Override
128 + public String toString() {
129 + return MoreObjects.toStringHelper(getClass()).add("Type", TYPE).add("Length", LENGTH).add("Value", rawValue)
130 + .toString();
131 + }
132 +}
1 +/*
2 + * Copyright 2015 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +package org.onosproject.pcepio.types;
17 +
18 +import java.util.Objects;
19 +import org.jboss.netty.buffer.ChannelBuffer;
20 +import org.onosproject.pcepio.protocol.PcepVersion;
21 +import org.slf4j.Logger;
22 +import org.slf4j.LoggerFactory;
23 +
24 +import com.google.common.base.MoreObjects;
25 +import com.google.common.base.MoreObjects.ToStringHelper;
26 +
27 +/**
28 + * Provides Opaque Link Attribute.
29 + */
30 +public class OpaqueLinkAttributeTlv implements PcepValueType {
31 +
32 + /*
33 + * TLV format.
34 + * Reference :[I-D.ietf-idr-attributesls-distribution] /3.3.2.6
35 + 0 1 2 3
36 + 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
37 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
38 + | Type=TBD42 | Length |
39 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
40 + // Opaque link attributes (variable) //
41 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
42 + */
43 +
44 + protected static final Logger log = LoggerFactory.getLogger(OpaqueLinkAttributeTlv.class);
45 +
46 + public static final short TYPE = 1097; //TODO:NEED TO HANDLE TDB42
47 + private final short hLength;
48 +
49 + private final byte[] rawValue;
50 +
51 + /**
52 + * constructor to initialize rawValue.
53 + *
54 + * @param rawValue of Opaque Link Attribute
55 + * @param hLength length
56 + */
57 + public OpaqueLinkAttributeTlv(byte[] rawValue, short hLength) {
58 + log.debug("OpaqueLinkAttributeTlv");
59 + this.rawValue = rawValue;
60 + if (0 == hLength) {
61 + this.hLength = (short) rawValue.length;
62 + } else {
63 + this.hLength = hLength;
64 + }
65 + }
66 +
67 + /**
68 + * Returns newly created OpaqueLinkAttributeTlv object.
69 + *
70 + * @param raw of Opaque Link Attribute
71 + * @param hLength length
72 + * @return new object of OpaqueLinkAttributeTlv
73 + */
74 + public static OpaqueLinkAttributeTlv of(final byte[] raw, short hLength) {
75 + return new OpaqueLinkAttributeTlv(raw, hLength);
76 + }
77 +
78 + /**
79 + * Returns raw value of Opaque Link Attribute Tlv.
80 + * @return rawValue raw value
81 + */
82 + public byte[] getValue() {
83 + return rawValue;
84 + }
85 +
86 + @Override
87 + public PcepVersion getVersion() {
88 + return PcepVersion.PCEP_1;
89 + }
90 +
91 + @Override
92 + public short getType() {
93 + return TYPE;
94 + }
95 +
96 + @Override
97 + public short getLength() {
98 + return hLength;
99 + }
100 +
101 + @Override
102 + public int hashCode() {
103 + return Objects.hash(rawValue);
104 + }
105 +
106 + @Override
107 + public boolean equals(Object obj) {
108 + if (this == obj) {
109 + return true;
110 + }
111 + if (obj instanceof OpaqueLinkAttributeTlv) {
112 + OpaqueLinkAttributeTlv other = (OpaqueLinkAttributeTlv) obj;
113 + return Objects.equals(this.rawValue, other.rawValue);
114 + }
115 + return false;
116 + }
117 +
118 + @Override
119 + public int write(ChannelBuffer c) {
120 + int iLenStartIndex = c.writerIndex();
121 + c.writeShort(TYPE);
122 + c.writeShort(hLength);
123 + c.writeBytes(rawValue);
124 + return c.writerIndex() - iLenStartIndex;
125 + }
126 +
127 + /**
128 + * Reads the channel buffer and returns object of OpaqueLinkAttributeTlv.
129 + *
130 + * @param c input channel buffer
131 + * @param hLength length
132 + * @return object of Opaque Link Attribute Tlv
133 + */
134 + public static PcepValueType read(ChannelBuffer c, short hLength) {
135 + byte[] iOpaqueValue = new byte[hLength];
136 + c.readBytes(iOpaqueValue, 0, hLength);
137 + return new OpaqueLinkAttributeTlv(iOpaqueValue, hLength);
138 + }
139 +
140 + @Override
141 + public String toString() {
142 + ToStringHelper toStrHelper = MoreObjects.toStringHelper(getClass());
143 +
144 + toStrHelper.add("Type", TYPE);
145 + toStrHelper.add("Length", hLength);
146 +
147 + StringBuffer result = new StringBuffer();
148 + for (byte b : rawValue) {
149 + result.append(String.format("%02X ", b));
150 + }
151 + toStrHelper.add("Value", result);
152 +
153 + return toStrHelper.toString();
154 + }
155 +}
1 +/*
2 + * Copyright 2015 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +package org.onosproject.pcepio.types;
17 +
18 +import java.util.Objects;
19 +import org.jboss.netty.buffer.ChannelBuffer;
20 +import org.onosproject.pcepio.protocol.PcepVersion;
21 +import org.slf4j.Logger;
22 +import org.slf4j.LoggerFactory;
23 +
24 +import com.google.common.base.MoreObjects;
25 +import com.google.common.base.MoreObjects.ToStringHelper;
26 +
27 +/**
28 + * Provides Opaque node attributes.
29 + */
30 +public class OpaqueNodeAttributeTlv implements PcepValueType {
31 + /*
32 + * Reference [I-D.ietf-idr-Properties ls-distribution] /3.3.1.5
33 + * 0 1 2 3
34 + 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
35 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
36 + | Type=[TBD22] | Length |
37 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
38 + // Opaque node attributes (variable) //
39 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
40 + */
41 +
42 + protected static final Logger log = LoggerFactory.getLogger(OpaqueNodeAttributeTlv.class);
43 +
44 + public static final short TYPE = 1001;
45 + private final short hLength;
46 +
47 + private final byte[] rawValue;
48 +
49 + /**
50 + * constructor to initialize rawValue.
51 + *
52 + * @param rawValue Opaque Node Attribute
53 + * @param hLength length
54 + */
55 + public OpaqueNodeAttributeTlv(byte[] rawValue, short hLength) {
56 +
57 + this.rawValue = rawValue;
58 + if (0 == hLength) {
59 + this.hLength = (short) rawValue.length;
60 + } else {
61 + this.hLength = hLength;
62 + }
63 + }
64 +
65 + /**
66 + * Returns newly created OpaqueNodeAttributeTlv object.
67 + *
68 + * @param raw value of Opaque Node Attribute
69 + * @param hLength length
70 + * @return new object of Opaque Node Attribute Tlv
71 + */
72 + public static OpaqueNodeAttributeTlv of(final byte[] raw, short hLength) {
73 + return new OpaqueNodeAttributeTlv(raw, hLength);
74 + }
75 +
76 + /**
77 + * Returns raw value of Opaque Node Attribute Tlv.
78 + *
79 + * @return rawValue of Opaque Node Attribute
80 + */
81 + public byte[] getValue() {
82 + return rawValue;
83 + }
84 +
85 + @Override
86 + public PcepVersion getVersion() {
87 + return PcepVersion.PCEP_1;
88 + }
89 +
90 + @Override
91 + public short getType() {
92 + return TYPE;
93 + }
94 +
95 + @Override
96 + public short getLength() {
97 + return hLength;
98 + }
99 +
100 + @Override
101 + public int hashCode() {
102 + return Objects.hash(rawValue);
103 + }
104 +
105 + @Override
106 + public boolean equals(Object obj) {
107 + if (this == obj) {
108 + return true;
109 + }
110 + if (obj instanceof OpaqueLinkAttributeTlv) {
111 + OpaqueNodeAttributeTlv other = (OpaqueNodeAttributeTlv) obj;
112 + return Objects.equals(this.rawValue, other.rawValue);
113 + }
114 + return false;
115 + }
116 +
117 + @Override
118 + public int write(ChannelBuffer c) {
119 + int iLenStartIndex = c.writerIndex();
120 + c.writeShort(TYPE);
121 + c.writeShort(hLength);
122 + c.writeBytes(rawValue);
123 + return c.writerIndex() - iLenStartIndex;
124 + }
125 +
126 + /**
127 + * Reads the channel buffer and returns object of Opaque Node Attribute Tlv.
128 + *
129 + * @param c input channel buffer
130 + * @param hLength length
131 + * @return object of OpaqueNodeAttributeTlv
132 + */
133 + public static PcepValueType read(ChannelBuffer c, short hLength) {
134 + byte[] iOpaqueValue = new byte[hLength];
135 + c.readBytes(iOpaqueValue, 0, hLength);
136 + return new OpaqueNodeAttributeTlv(iOpaqueValue, hLength);
137 + }
138 +
139 + @Override
140 + public String toString() {
141 + ToStringHelper toStrHelper = MoreObjects.toStringHelper(getClass());
142 +
143 + toStrHelper.add("Type", TYPE);
144 + toStrHelper.add("Length", hLength);
145 +
146 + StringBuffer result = new StringBuffer();
147 + for (byte b : rawValue) {
148 + result.append(String.format("%02X ", b));
149 + }
150 + toStrHelper.add("Value", result);
151 +
152 + return toStrHelper.toString();
153 + }
154 +}
1 +package org.onosproject.pcepio.types;
2 +
3 +import java.util.Objects;
4 +import org.jboss.netty.buffer.ChannelBuffer;
5 +import org.onosproject.pcepio.protocol.PcepVersion;
6 +import org.slf4j.Logger;
7 +import org.slf4j.LoggerFactory;
8 +
9 +import com.google.common.base.MoreObjects;
10 +
11 +/**
12 + * Provides PceccCapabilityTlv.
13 + */
14 +public class PceccCapabilityTlv implements PcepValueType {
15 +
16 + /* PCECC CAPABILITY TLV
17 + * Reference : draft-zhao-pce-pcep-extension-for-pce-controller-01, section-7.1.1
18 +
19 + 0 1 2 3
20 + 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
21 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
22 + | Type=32 | Length=4 |
23 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
24 + | Flags |G|L|
25 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
26 +
27 + */
28 + protected static final Logger log = LoggerFactory.getLogger(PceccCapabilityTlv.class);
29 +
30 + public static final short TYPE = 32;
31 + public static final short LENGTH = 4;
32 + public static final int SET = 1;
33 + public static final byte LFLAG_CHECK = 0x01;
34 + public static final byte GFLAG_CHECK = 0x02;
35 +
36 + private final boolean bGFlag;
37 + private final boolean bLFlag;
38 +
39 + private final int rawValue;
40 + private final boolean isRawValueSet;
41 +
42 + /**
43 + * Constructor to initialize raw Value.
44 + *
45 + * @param rawValue raw value
46 + */
47 + public PceccCapabilityTlv(final int rawValue) {
48 + this.rawValue = rawValue;
49 + this.isRawValueSet = true;
50 +
51 + bLFlag = (rawValue & LFLAG_CHECK) == LFLAG_CHECK ? true : false;
52 + bGFlag = (rawValue & GFLAG_CHECK) == GFLAG_CHECK ? true : false;
53 + }
54 +
55 + /**
56 + * Constructor to initialize G-flag L-flag.
57 + * @param bGFlag G-flag
58 + * @param bLFlag L-flag
59 + */
60 + public PceccCapabilityTlv(boolean bGFlag, boolean bLFlag) {
61 + this.bGFlag = bGFlag;
62 + this.bLFlag = bLFlag;
63 + this.rawValue = 0;
64 + this.isRawValueSet = false;
65 + }
66 +
67 + /**
68 + * Returns newly created PceccCapabilityTlv object.
69 + *
70 + * @param raw value
71 + * @return object of Pcecc Capability Tlv
72 + */
73 + public static PceccCapabilityTlv of(final int raw) {
74 + return new PceccCapabilityTlv(raw);
75 + }
76 +
77 + @Override
78 + public PcepVersion getVersion() {
79 + return PcepVersion.PCEP_1;
80 + }
81 +
82 + /**
83 + * Returns G-flag.
84 + * @return bGFlag G-flag
85 + */
86 + public boolean getGFlag() {
87 + return bGFlag;
88 + }
89 +
90 + /**
91 + * Returns L-flag.
92 + * @return bLFlag L-flag
93 + */
94 + public boolean getLFlag() {
95 + return bLFlag;
96 + }
97 +
98 + /**
99 + * Returns the raw value.
100 + * @return rawValue Flags
101 + */
102 + public int getInt() {
103 + return rawValue;
104 + }
105 +
106 + @Override
107 + public short getType() {
108 + return TYPE;
109 + }
110 +
111 + @Override
112 + public short getLength() {
113 + return LENGTH;
114 + }
115 +
116 + @Override
117 + public int hashCode() {
118 + if (isRawValueSet) {
119 + return Objects.hash(rawValue);
120 + } else {
121 + return Objects.hash(bLFlag, bGFlag);
122 + }
123 + }
124 +
125 + @Override
126 + public boolean equals(Object obj) {
127 + if (this == obj) {
128 + return true;
129 + }
130 + if (obj instanceof PceccCapabilityTlv) {
131 + PceccCapabilityTlv other = (PceccCapabilityTlv) obj;
132 + if (isRawValueSet) {
133 + return Objects.equals(this.rawValue, other.rawValue);
134 + } else {
135 + return Objects.equals(this.bGFlag, other.bGFlag) && Objects.equals(this.bLFlag, other.bLFlag);
136 + }
137 + }
138 + return false;
139 + }
140 +
141 + @Override
142 + public int write(ChannelBuffer c) {
143 + int iLenStartIndex = c.writerIndex();
144 + int temp = 0;
145 + c.writeShort(TYPE);
146 + c.writeShort(LENGTH);
147 + if (isRawValueSet) {
148 + c.writeInt(rawValue);
149 + } else {
150 + if (bGFlag) {
151 + temp = temp | GFLAG_CHECK;
152 + }
153 + if (bLFlag) {
154 + temp = temp | LFLAG_CHECK;
155 + }
156 + c.writeInt(temp);
157 + }
158 + return c.writerIndex() - iLenStartIndex;
159 + }
160 +
161 + /**
162 + * Reads channel buffer and returns object of PceccCapabilityTlv.
163 + *
164 + * @param c input channel buffer
165 + * @return object of PceccCapabilityTlv
166 + */
167 + public static PceccCapabilityTlv read(ChannelBuffer c) {
168 + return PceccCapabilityTlv.of(c.readInt());
169 + }
170 +
171 + @Override
172 + public String toString() {
173 + return MoreObjects.toStringHelper(getClass()).add("Type", TYPE).add("Length", LENGTH).add("Value", rawValue)
174 + .toString();
175 + }
176 +}
1 +package org.onosproject.pcepio.types;
2 +
3 +import java.util.Objects;
4 +import org.jboss.netty.buffer.ChannelBuffer;
5 +import org.onosproject.pcepio.protocol.PcepVersion;
6 +import org.slf4j.Logger;
7 +import org.slf4j.LoggerFactory;
8 +
9 +import com.google.common.base.MoreObjects;
10 +
11 +/**
12 + * Provides CEP LABEL DB VERSION TLV which contains LSP State DB Version (32 Bit ).
13 + */
14 +public class PcepLabelDbVerTlv implements PcepValueType {
15 +
16 + /* PCEP LABEL DB VERSION TLV format
17 +
18 + Reference : draft-ietf-pce-stateful-sync-optimizations-02, section 3.3.1
19 + 0 1 2 3
20 + 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
21 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
22 + | Type=23 | Length=8 |
23 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
24 + | LSP State DB Version |
25 + | |
26 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
27 +
28 + */
29 + protected static final Logger log = LoggerFactory.getLogger(PcepLabelDbVerTlv.class);
30 +
31 + public static final short TYPE = 34;
32 + public static final short LENGTH = 8;
33 + private final long rawValue;
34 +
35 + /**
36 + * constructor to initialize rawValue.
37 + *
38 + * @param rawValue of Pcep Label Db Version Tlv
39 + */
40 + public PcepLabelDbVerTlv(final long rawValue) {
41 + log.debug("PcepLabelDbVerTlv");
42 + this.rawValue = rawValue;
43 + }
44 +
45 + /**
46 + * Returns newly created PcepLabelDbVerTlv object.
47 + *
48 + * @param raw LSP State DB Version
49 + * @return object of PcepLabelDbVerTlv
50 + */
51 + public static PcepLabelDbVerTlv of(final long raw) {
52 + return new PcepLabelDbVerTlv(raw);
53 + }
54 +
55 + @Override
56 + public PcepVersion getVersion() {
57 + return PcepVersion.PCEP_1;
58 + }
59 +
60 + /**
61 + * Returns LSP State DB Version.
62 + * @return raw value
63 + */
64 + public long getLong() {
65 + return rawValue;
66 + }
67 +
68 + @Override
69 + public short getLength() {
70 + return LENGTH;
71 + }
72 +
73 + @Override
74 + public short getType() {
75 + return TYPE;
76 + }
77 +
78 + @Override
79 + public int hashCode() {
80 + return Objects.hash(rawValue);
81 + }
82 +
83 + @Override
84 + public boolean equals(Object obj) {
85 + if (this == obj) {
86 + return true;
87 + }
88 + if (obj instanceof PceccCapabilityTlv) {
89 + PcepLabelDbVerTlv other = (PcepLabelDbVerTlv) obj;
90 + return Objects.equals(this.rawValue, other.rawValue);
91 + }
92 + return false;
93 + }
94 +
95 + @Override
96 + public int write(ChannelBuffer c) {
97 + int iLenStartIndex = c.writerIndex();
98 + c.writeShort(TYPE);
99 + c.writeShort(LENGTH);
100 + c.writeLong(rawValue);
101 + return c.writerIndex() - iLenStartIndex;
102 + }
103 +
104 + /**
105 + * Reads the channel buffer and returns object of PcepLabelDbVerTlv.
106 + *
107 + * @param c input channel buffer
108 + * @return object of PcepLabelDbVerTlv
109 + */
110 + public static PcepLabelDbVerTlv read(ChannelBuffer c) {
111 + return PcepLabelDbVerTlv.of(c.readLong());
112 + }
113 +
114 + @Override
115 + public String toString() {
116 + return MoreObjects.toStringHelper(getClass()).add("Type", TYPE).add("Length", LENGTH).add("Value", rawValue)
117 + .toString();
118 + }
119 +}
1 +/*
2 + * Copyright 2015 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +package org.onosproject.pcepio.types;
17 +
18 +import java.util.Iterator;
19 +import java.util.LinkedList;
20 +import java.util.ListIterator;
21 +import java.util.Objects;
22 +
23 +import org.jboss.netty.buffer.ChannelBuffer;
24 +import org.onosproject.pcepio.exceptions.PcepParseException;
25 +import org.onosproject.pcepio.protocol.PcepVersion;
26 +import org.slf4j.Logger;
27 +import org.slf4j.LoggerFactory;
28 +
29 +import com.google.common.base.MoreObjects;
30 +
31 +/**
32 + * Provides Remote TE Node Descriptors TLV.
33 + */
34 +public class RemoteTENodeDescriptorsTLV implements PcepValueType {
35 +
36 + /* Reference :PCEP Extension for Transporting TE Data
37 + draft-dhodylee-pce-pcep-te-data-extn-02
38 + *
39 + 0 1 2 3
40 + 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
41 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
42 + | Type=[TBD9] | Length |
43 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
44 + | |
45 + // Node Descriptor Sub-TLVs (variable) //
46 + | |
47 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
48 + */
49 +
50 + protected static final Logger log = LoggerFactory.getLogger(RemoteTENodeDescriptorsTLV.class);
51 +
52 + public static final short TYPE = 1003; //TODD:change this TBD9
53 + public static short hLength;
54 +
55 + public static final int TLV_HEADER_LENGTH = 4;
56 + // Node Descriptor Sub-TLVs (variable)
57 + private LinkedList<PcepValueType> llRemoteTENodeDescriptorSubTLVs;
58 +
59 + /**
60 + * Constructor to initialize llRemoteTENodeDescriptorSubTLVs.
61 + *
62 + * @param llRemoteTENodeDescriptorSubTLVs LinkedList of PcepValueType
63 + */
64 + public RemoteTENodeDescriptorsTLV(LinkedList<PcepValueType> llRemoteTENodeDescriptorSubTLVs) {
65 + this.llRemoteTENodeDescriptorSubTLVs = llRemoteTENodeDescriptorSubTLVs;
66 + }
67 +
68 + /**
69 + * Returns object of Remote TE Node Descriptors TLV.
70 + *
71 + * @param llRemoteTENodeDescriptorSubTLVs LinkedList of PcepValueType
72 + * @return object of RemoteTENodeDescriptorsTLV
73 + */
74 + public static RemoteTENodeDescriptorsTLV of(final LinkedList<PcepValueType> llRemoteTENodeDescriptorSubTLVs) {
75 + return new RemoteTENodeDescriptorsTLV(llRemoteTENodeDescriptorSubTLVs);
76 + }
77 +
78 + /**
79 + * Returns Remote TE Node Descriptor Sub TLVs.
80 + *
81 + * @return llRemoteTENodeDescriptorSubTLVs
82 + */
83 + public LinkedList<PcepValueType> getllRemoteTENodeDescriptorSubTLVs() {
84 + return llRemoteTENodeDescriptorSubTLVs;
85 + }
86 +
87 + @Override
88 + public PcepVersion getVersion() {
89 + return PcepVersion.PCEP_1;
90 + }
91 +
92 + @Override
93 + public short getType() {
94 + return TYPE;
95 + }
96 +
97 + @Override
98 + public short getLength() {
99 + return hLength;
100 + }
101 +
102 + @Override
103 + public int hashCode() {
104 + return Objects.hash(llRemoteTENodeDescriptorSubTLVs.hashCode());
105 + }
106 +
107 + @Override
108 + public boolean equals(Object obj) {
109 + if (this == obj) {
110 + return true;
111 + }
112 + /*
113 + * Here we have a list of Tlv so to compare each sub tlv between the object
114 + * we have to take a list iterator so one by one we can get each sub tlv object
115 + * and can compare them.
116 + * it may be possible that the size of 2 lists is not equal so we have to first check
117 + * the size, if both are same then we should check for the subtlv objects otherwise
118 + * we should return false.
119 + */
120 + if (obj instanceof RemoteTENodeDescriptorsTLV) {
121 + int countObjSubTlv = 0;
122 + int countOtherSubTlv = 0;
123 + boolean isCommonSubTlv = true;
124 + RemoteTENodeDescriptorsTLV other = (RemoteTENodeDescriptorsTLV) obj;
125 + Iterator<PcepValueType> objListIterator = ((RemoteTENodeDescriptorsTLV) obj).llRemoteTENodeDescriptorSubTLVs
126 + .iterator();
127 + countObjSubTlv = ((RemoteTENodeDescriptorsTLV) obj).llRemoteTENodeDescriptorSubTLVs.size();
128 + countOtherSubTlv = other.llRemoteTENodeDescriptorSubTLVs.size();
129 + if (countObjSubTlv != countOtherSubTlv) {
130 + return false;
131 + } else {
132 + while (objListIterator.hasNext() && isCommonSubTlv) {
133 + PcepValueType subTlv = objListIterator.next();
134 + isCommonSubTlv = Objects.equals(llRemoteTENodeDescriptorSubTLVs.contains(subTlv),
135 + other.llRemoteTENodeDescriptorSubTLVs.contains(subTlv));
136 + }
137 + return isCommonSubTlv;
138 + }
139 + }
140 + return false;
141 + }
142 +
143 + @Override
144 + public int write(ChannelBuffer c) {
145 +
146 + int tlvStartIndex = c.writerIndex();
147 + c.writeShort(TYPE);
148 + int tlvLenIndex = c.writerIndex();
149 + hLength = 0;
150 + c.writeShort(hLength);
151 +
152 + ListIterator<PcepValueType> listIterator = llRemoteTENodeDescriptorSubTLVs.listIterator();
153 +
154 + while (listIterator.hasNext()) {
155 + PcepValueType tlv = listIterator.next();
156 +
157 + if (null == tlv) {
158 + log.debug("TLV is null from subTlv list");
159 + continue;
160 + }
161 + tlv.write(c);
162 +
163 + // need to take care of padding
164 + int pad = tlv.getLength() % 4;
165 +
166 + if (0 != pad) {
167 + pad = 4 - pad;
168 + for (int i = 0; i < pad; ++i) {
169 + c.writeByte((byte) 0);
170 + }
171 + }
172 + }
173 +
174 + hLength = (short) (c.writerIndex() - tlvStartIndex);
175 + c.setShort(tlvLenIndex, hLength);
176 +
177 + return c.writerIndex() - tlvStartIndex;
178 + }
179 +
180 + /**
181 + * Reads channel buffer and returns object of Remote TE Node Descriptors TLV.
182 + *
183 + * @param c input channel buffer
184 + * @return object of RemoteTENodeDescriptorsTLV
185 + * @throws PcepParseException if mandatory fields are missing
186 + */
187 + public static PcepValueType read(ChannelBuffer c) throws PcepParseException {
188 +
189 + // Node Descriptor Sub-TLVs (variable)
190 + LinkedList<PcepValueType> llRemoteTENodeDescriptorSubTLVs = new LinkedList<PcepValueType>();
191 +
192 + ChannelBuffer tempCb = c.readBytes(hLength - TLV_HEADER_LENGTH);
193 +
194 + while (TLV_HEADER_LENGTH <= tempCb.readableBytes()) {
195 +
196 + PcepValueType tlv;
197 + short hType = tempCb.readShort();
198 + int iValue = 0;
199 + short hLength = tempCb.readShort();
200 + switch (hType) {
201 +
202 + case AutonomousSystemTlv.TYPE:
203 + iValue = tempCb.readInt();
204 + tlv = new AutonomousSystemTlv(iValue);
205 + break;
206 + case BGPLSidentifierTlv.TYPE:
207 + iValue = tempCb.readInt();
208 + tlv = new BGPLSidentifierTlv(iValue);
209 + break;
210 + case OSPFareaIDsubTlv.TYPE:
211 + iValue = tempCb.readInt();
212 + tlv = new OSPFareaIDsubTlv(iValue);
213 + break;
214 + case RouterIDSubTlv.TYPE:
215 + tlv = RouterIDSubTlv.read(tempCb, hLength);
216 + break;
217 +
218 + default:
219 + throw new PcepParseException("Unsupported Sub TLV type :" + hType);
220 + }
221 +
222 + // Check for the padding
223 + int pad = hLength % 4;
224 + if (0 < pad) {
225 + pad = 4 - pad;
226 + if (pad <= tempCb.readableBytes()) {
227 + tempCb.skipBytes(pad);
228 + }
229 + }
230 +
231 + llRemoteTENodeDescriptorSubTLVs.add(tlv);
232 + }
233 +
234 + if (0 < tempCb.readableBytes()) {
235 +
236 + throw new PcepParseException("Sub Tlv parsing error. Extra bytes received.");
237 + }
238 + return new RemoteTENodeDescriptorsTLV(llRemoteTENodeDescriptorSubTLVs);
239 + }
240 +
241 + @Override
242 + public String toString() {
243 + return MoreObjects.toStringHelper(getClass()).add("Type", TYPE).add("Length", hLength)
244 + .add("RemoteTeNodeDescriptorSubTLVs", llRemoteTENodeDescriptorSubTLVs).toString();
245 + }
246 +}
1 +/*
2 + * Copyright 2015 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +package org.onosproject.pcepio.types;
17 +
18 +import java.util.Objects;
19 +
20 +import org.jboss.netty.buffer.ChannelBuffer;
21 +import org.onosproject.pcepio.protocol.PcepVersion;
22 +import org.slf4j.Logger;
23 +import org.slf4j.LoggerFactory;
24 +
25 +import com.google.common.base.MoreObjects;
26 +import com.google.common.base.MoreObjects.ToStringHelper;
27 +
28 +/**
29 + * Provides router id.
30 + */
31 +public class RouterIDSubTlv implements PcepValueType {
32 +
33 + /* reference :I-D.ietf-idr-ls-distribution.
34 + * 0 1 2 3
35 + 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
36 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
37 + | Type=[TBD13] | Length |
38 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
39 + | opaque value |
40 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
41 + */
42 +
43 + protected static final Logger log = LoggerFactory.getLogger(RouterIDSubTlv.class);
44 +
45 + public static final short TYPE = 1000; //TODD:change this TBD13
46 + private final short hLength;
47 +
48 + private final byte[] rawValue;
49 +
50 + /**
51 + * constructor to initialize rawValue.
52 + *
53 + * @param rawValue raw value
54 + * @param hLength length
55 + */
56 + public RouterIDSubTlv(byte[] rawValue, short hLength) {
57 + this.rawValue = rawValue;
58 + if (0 == hLength) {
59 + this.hLength = (short) rawValue.length;
60 + } else {
61 + this.hLength = hLength;
62 + }
63 + }
64 +
65 + /**
66 + * Returns object of Router ID Sub Tlv.
67 + *
68 + * @param raw value
69 + * @param hLength length
70 + * @return object of Router ID Sub Tlv
71 + */
72 + public static RouterIDSubTlv of(final byte[] raw, short hLength) {
73 + return new RouterIDSubTlv(raw, hLength);
74 + }
75 +
76 + /**
77 + * Returns raw value.
78 + *
79 + * @return rawValue value
80 + */
81 + public byte[] getValue() {
82 + return rawValue;
83 + }
84 +
85 + @Override
86 + public PcepVersion getVersion() {
87 + return PcepVersion.PCEP_1;
88 + }
89 +
90 + @Override
91 + public short getType() {
92 + return TYPE;
93 + }
94 +
95 + @Override
96 + public short getLength() {
97 + return hLength;
98 + }
99 +
100 + @Override
101 + public int hashCode() {
102 + return Objects.hash(rawValue);
103 + }
104 +
105 + @Override
106 + public boolean equals(Object obj) {
107 + if (this == obj) {
108 + return true;
109 + }
110 + if (obj instanceof RouterIDSubTlv) {
111 + RouterIDSubTlv other = (RouterIDSubTlv) obj;
112 + return Objects.equals(this.rawValue, other.rawValue);
113 + }
114 + return false;
115 + }
116 +
117 + @Override
118 + public int write(ChannelBuffer c) {
119 + int iLenStartIndex = c.writerIndex();
120 + c.writeShort(TYPE);
121 + c.writeShort(hLength);
122 + c.writeBytes(rawValue);
123 + return c.writerIndex() - iLenStartIndex;
124 + }
125 +
126 + /**
127 + * Reads channel buffer and returns object of RouterIDSubTlv.
128 + *
129 + * @param c input channel buffer
130 + * @param hLength length
131 + * @return object of RouterIDSubTlv
132 + */
133 + public static PcepValueType read(ChannelBuffer c, short hLength) {
134 + byte[] iOpaqueValue = new byte[hLength];
135 + c.readBytes(iOpaqueValue, 0, hLength);
136 + return new RouterIDSubTlv(iOpaqueValue, hLength);
137 + }
138 +
139 + @Override
140 + public String toString() {
141 + ToStringHelper toStrHelper = MoreObjects.toStringHelper(getClass());
142 +
143 + toStrHelper.add("Type", TYPE);
144 + toStrHelper.add("Length", hLength);
145 +
146 + StringBuffer result = new StringBuffer();
147 + for (byte b : rawValue) {
148 + result.append(String.format("%02X ", b));
149 + }
150 + toStrHelper.add("Value", result);
151 +
152 + return toStrHelper.toString();
153 + }
154 +}
1 +/*
2 + * Copyright 2015 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +package org.onosproject.pcepio.types;
17 +
18 +import java.util.Objects;
19 +
20 +import org.jboss.netty.buffer.ChannelBuffer;
21 +import org.onosproject.pcepio.protocol.PcepVersion;
22 +import org.slf4j.Logger;
23 +import org.slf4j.LoggerFactory;
24 +
25 +import com.google.common.base.MoreObjects;
26 +
27 +/**
28 + * Provides RoutingUniverseTLV identifiers.
29 + */
30 +public class RoutingUniverseTLV implements PcepValueType {
31 +
32 + /*
33 + * Reference : draft-dhodylee-pce-pcep-te-data-extn-02, section 9.2.1.
34 + * 0 1 2 3
35 + 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
36 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
37 + | Type=[TBD7] | Length=8 |
38 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
39 + | Identifier |
40 + | |
41 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
42 +
43 + *
44 + *
45 + * +------------+---------------------+
46 + | Identifier | Routing Universe |
47 + +------------+---------------------+
48 + | 0 | L3 packet topology |
49 + | 1 | L1 optical topology |
50 + +------------+---------------------+
51 + */
52 +
53 + protected static final Logger log = LoggerFactory.getLogger(RoutingUniverseTLV.class);
54 +
55 + public static final short TYPE = 14; // TODO:need to change TBD7
56 + public static final short LENGTH = 8;
57 +
58 + private final long rawValue;
59 +
60 + /**
61 + * Constructor to initialize raw value.
62 + *
63 + * @param rawValue raw value
64 + */
65 + public RoutingUniverseTLV(long rawValue) {
66 + this.rawValue = rawValue;
67 + }
68 +
69 + /**
70 + * Returns object of RoutingUniverseTLV.
71 + *
72 + * @param raw value
73 + * @return object of RoutingUniverseTLV
74 + */
75 + public static RoutingUniverseTLV of(final long raw) {
76 + return new RoutingUniverseTLV(raw);
77 + }
78 +
79 + /**
80 + * Returns raw value as Identifier.
81 + *
82 + * @return rawValue Identifier
83 + */
84 + public long getLong() {
85 + return rawValue;
86 + }
87 +
88 + @Override
89 + public PcepVersion getVersion() {
90 + return PcepVersion.PCEP_1;
91 + }
92 +
93 + @Override
94 + public short getType() {
95 + return TYPE;
96 + }
97 +
98 + @Override
99 + public short getLength() {
100 + return LENGTH;
101 + }
102 +
103 + @Override
104 + public int hashCode() {
105 + return Objects.hash(rawValue);
106 + }
107 +
108 + @Override
109 + public boolean equals(Object obj) {
110 + if (this == obj) {
111 + return true;
112 + }
113 + if (obj instanceof RoutingUniverseTLV) {
114 + RoutingUniverseTLV other = (RoutingUniverseTLV) obj;
115 + return Objects.equals(this.rawValue, other.rawValue);
116 + }
117 + return false;
118 + }
119 +
120 + @Override
121 + public int write(ChannelBuffer c) {
122 + int iLenStartIndex = c.writerIndex();
123 + c.writeShort(TYPE);
124 + c.writeShort(LENGTH);
125 + c.writeLong(rawValue);
126 + return c.writerIndex() - iLenStartIndex;
127 + }
128 +
129 + /**
130 + * Reads from channel buffer and returns object of RoutingUniverseTLV.
131 + *
132 + * @param c input channel buffer
133 + * @return object of RoutingUniverseTLV
134 + */
135 + public static RoutingUniverseTLV read(ChannelBuffer c) {
136 + return RoutingUniverseTLV.of(c.readLong());
137 + }
138 +
139 + @Override
140 + public String toString() {
141 + return MoreObjects.toStringHelper(getClass()).add("Type", TYPE).add("Length", LENGTH).add("Value", rawValue)
142 + .toString();
143 + }
144 +}
1 +/*
2 + * Copyright 2015 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +package org.onosproject.pcepio.types;
17 +
18 +import java.util.Objects;
19 +
20 +import org.jboss.netty.buffer.ChannelBuffer;
21 +import org.onosproject.pcepio.protocol.PcepVersion;
22 +import org.slf4j.Logger;
23 +import org.slf4j.LoggerFactory;
24 +
25 +import com.google.common.base.MoreObjects;
26 +import com.google.common.base.MoreObjects.ToStringHelper;
27 +
28 +/**
29 + * Provides SharedRiskLinkGroupTlv.
30 + */
31 +public class SharedRiskLinkGroupTlv implements PcepValueType {
32 +
33 + /*
34 + * Reference :[I-D.ietf-idr- Group ls-distribution] /3.3.2.5
35 + *
36 + * 0 1 2 3
37 + 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
38 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
39 + | Type =TDB41 | Length |
40 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
41 + | Shared Risk Link Group Value |
42 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
43 + // ............ //
44 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
45 + | Shared Risk Link Group Value |
46 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
47 + */
48 +
49 + protected static final Logger log = LoggerFactory.getLogger(SharedRiskLinkGroupTlv.class);
50 +
51 + public static final short TYPE = 1096; //TODO:NEED TO HANDLE TDB41
52 +
53 + private final short hLength;
54 +
55 + private final int[] srlgValue;
56 +
57 + /**
58 + * Constructor to initialize SRLG value.
59 + *
60 + * @param srlgValue Shared Risk Link Group Value
61 + * @param hLength length
62 + */
63 + public SharedRiskLinkGroupTlv(int[] srlgValue, short hLength) {
64 + this.srlgValue = srlgValue;
65 + if (0 == hLength) {
66 + this.hLength = (short) ((srlgValue.length) * 4);
67 + } else {
68 + this.hLength = hLength;
69 + }
70 + }
71 +
72 + /**
73 + * Returns object of SharedRiskLinkGroupTlv.
74 + *
75 + * @param raw value
76 + * @param hLength length
77 + * @return object of SharedRiskLinkGroupTlv
78 + */
79 + public static SharedRiskLinkGroupTlv of(final int[] raw, short hLength) {
80 + return new SharedRiskLinkGroupTlv(raw, hLength);
81 + }
82 +
83 + /**
84 + * Returns SRLG Value.
85 + *
86 + * @return srlgValue
87 + */
88 + public int[] getValue() {
89 + return srlgValue;
90 + }
91 +
92 + @Override
93 + public PcepVersion getVersion() {
94 + return PcepVersion.PCEP_1;
95 + }
96 +
97 + @Override
98 + public short getType() {
99 + return TYPE;
100 + }
101 +
102 + @Override
103 + public short getLength() {
104 + return hLength;
105 + }
106 +
107 + @Override
108 + public int hashCode() {
109 + return Objects.hash(srlgValue);
110 + }
111 +
112 + @Override
113 + public boolean equals(Object obj) {
114 + if (this == obj) {
115 + return true;
116 + }
117 + if (obj instanceof SharedRiskLinkGroupTlv) {
118 + SharedRiskLinkGroupTlv other = (SharedRiskLinkGroupTlv) obj;
119 + return Objects.equals(this.srlgValue, other.srlgValue);
120 + }
121 + return false;
122 + }
123 +
124 + @Override
125 + public int write(ChannelBuffer c) {
126 + int iLenStartIndex = c.writerIndex();
127 + c.writeShort(TYPE);
128 + c.writeShort(hLength);
129 + for (int b : srlgValue) {
130 + c.writeInt(b);
131 + }
132 + return c.writerIndex() - iLenStartIndex;
133 + }
134 +
135 + /**
136 + * Reads from channel buffer and returns object of SharedRiskLinkGroupTlv.
137 + *
138 + * @param c input channel buffer
139 + * @param hLength length
140 + * @return object of SharedRiskLinkGroupTlv
141 + */
142 + public static PcepValueType read(ChannelBuffer c, short hLength) {
143 + int iLength = hLength / 4;
144 + int[] iSharedRiskLinkGroup = new int[iLength];
145 + for (int i = 0; i < iLength; i++) {
146 + iSharedRiskLinkGroup[i] = c.readInt();
147 + }
148 + return new SharedRiskLinkGroupTlv(iSharedRiskLinkGroup, hLength);
149 + }
150 +
151 +
152 + @Override
153 + public String toString() {
154 + ToStringHelper toStrHelper = MoreObjects.toStringHelper(getClass());
155 +
156 + toStrHelper.add("Type", TYPE);
157 + toStrHelper.add("Length", hLength);
158 +
159 + StringBuffer result = new StringBuffer();
160 + for (int b : srlgValue) {
161 + result.append(String.format("%02X ", b));
162 + }
163 + toStrHelper.add("Value", result);
164 +
165 + return toStrHelper.toString();
166 + }
167 +}
1 +/*
2 + * Copyright 2015 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +
17 +package org.onosproject.pcepio.types;
18 +
19 +import java.util.Objects;
20 +
21 +import org.jboss.netty.buffer.ChannelBuffer;
22 +import org.onosproject.pcepio.protocol.PcepVersion;
23 +import org.slf4j.Logger;
24 +import org.slf4j.LoggerFactory;
25 +
26 +import com.google.common.base.MoreObjects;
27 +
28 +/**
29 + * Provides StatefulLspDbVerTlv.
30 + */
31 +public class StatefulLspDbVerTlv implements PcepValueType {
32 +
33 + /* LSP-DB-VERSION TLV format
34 + *
35 + * Reference : Optimizations of Label Switched Path State Synchronization Procedures
36 + for a Stateful PCE draft-ietf-pce-stateful-sync-optimizations-02
37 + *
38 + *
39 +
40 + 0 1 2 3
41 + 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
42 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
43 + | Type=23 | Length=8 |
44 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
45 + | LSP State DB Version |
46 + | |
47 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
48 +
49 + */
50 + protected static final Logger log = LoggerFactory.getLogger(StatefulLspDbVerTlv.class);
51 +
52 + public static final short TYPE = 23;
53 + public static final short LENGTH = 8;
54 + private final long rawValue;
55 +
56 + /**
57 + * Constructor to initialize rawValue.
58 + *
59 + * @param rawValue value
60 + */
61 + public StatefulLspDbVerTlv(final long rawValue) {
62 + this.rawValue = rawValue;
63 + }
64 +
65 + /**
66 + * Returns object of StatefulLspDbVerTlv.
67 + *
68 + * @param raw is LSP State DB Version
69 + * @return object of StatefulLspDbVerTlv
70 + */
71 + public static StatefulLspDbVerTlv of(final long raw) {
72 + return new StatefulLspDbVerTlv(raw);
73 + }
74 +
75 + @Override
76 + public PcepVersion getVersion() {
77 + return PcepVersion.PCEP_1;
78 + }
79 +
80 + /**
81 + * Returns LSP State DB Version.
82 + *
83 + * @return rawValue value
84 + */
85 + public long getLong() {
86 + return rawValue;
87 + }
88 +
89 + @Override
90 + public short getLength() {
91 + return LENGTH;
92 + }
93 +
94 + @Override
95 + public short getType() {
96 + return TYPE;
97 + }
98 +
99 + @Override
100 + public int hashCode() {
101 + return Objects.hash(rawValue);
102 + }
103 +
104 + @Override
105 + public boolean equals(Object obj) {
106 + if (this == obj) {
107 + return true;
108 + }
109 + if (obj instanceof StatefulLspDbVerTlv) {
110 + StatefulLspDbVerTlv other = (StatefulLspDbVerTlv) obj;
111 + return Objects.equals(this.rawValue, other.rawValue);
112 + }
113 + return false;
114 + }
115 +
116 + @Override
117 + public int write(ChannelBuffer c) {
118 + c.writeShort(TYPE);
119 + c.writeShort(LENGTH);
120 + c.writeLong(rawValue);
121 + return c.writerIndex();
122 + }
123 +
124 + /**
125 + * Reads the channel buffer and returns object of StatefulLspDbVerTlv.
126 + *
127 + * @param c input channel buffer
128 + * @return object of StatefulLspDbVerTlv
129 + */
130 + public static StatefulLspDbVerTlv read(ChannelBuffer c) {
131 + return StatefulLspDbVerTlv.of(c.readLong());
132 + }
133 +
134 + @Override
135 + public String toString() {
136 + return MoreObjects.toStringHelper(getClass()).add("Type", TYPE).add("Length", LENGTH).add("Value", rawValue)
137 + .toString();
138 + }
139 +}
1 +/*
2 + * Copyright 2015 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +
17 +package org.onosproject.pcepio.types;
18 +
19 +import java.util.Objects;
20 +
21 +import org.jboss.netty.buffer.ChannelBuffer;
22 +import org.onosproject.pcepio.protocol.PcepVersion;
23 +import org.slf4j.Logger;
24 +import org.slf4j.LoggerFactory;
25 +
26 +import com.google.common.base.MoreObjects;
27 +
28 +/**
29 + * Provides StatefulPceCapabilityTlv.
30 + */
31 +public class StatefulPceCapabilityTlv implements PcepValueType {
32 +
33 + /* STATEFUL-PCE-CAPABILITY TLV format
34 + *
35 + * Reference :PCEP Extensions for Stateful PCE draft-ietf-pce-stateful-pce-10
36 +
37 + 0 1 2 3
38 + 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
39 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
40 + | Type=16 | Length=4 |
41 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
42 + | Flags |D|T|I|S|U|
43 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
44 +
45 + */
46 + protected static final Logger log = LoggerFactory.getLogger(StatefulPceCapabilityTlv.class);
47 +
48 + public static final short TYPE = 16;
49 + public static final short LENGTH = 4;
50 + public static final byte UFLAG_SET = 0x01;
51 + public static final byte SFLAG_SET = 0x02;
52 + public static final byte IFLAG_SET = 0x04;
53 + public static final byte TFLAG_SET = 0x08;
54 + public static final byte DFLAG_SET = 0x10;
55 + public static final int SET = 1;
56 +
57 + private final int rawValue;
58 + private final boolean bDFlag;
59 + private final boolean bTFlag;
60 + private final boolean bIFlag;
61 + private final boolean bSFlag;
62 + private final boolean bUFlag;
63 + private final boolean isRawValueSet;
64 +
65 + /**
66 + * Constructor to initialize variables.
67 + *
68 + * @param rawValue Flags
69 + */
70 + public StatefulPceCapabilityTlv(int rawValue) {
71 + this.rawValue = rawValue;
72 + isRawValueSet = true;
73 + this.bUFlag = (rawValue & UFLAG_SET) == UFLAG_SET ? true : false;
74 + this.bSFlag = (rawValue & SFLAG_SET) == SFLAG_SET ? true : false;
75 + this.bIFlag = (rawValue & IFLAG_SET) == IFLAG_SET ? true : false;
76 + this.bTFlag = (rawValue & TFLAG_SET) == TFLAG_SET ? true : false;
77 + this.bDFlag = (rawValue & DFLAG_SET) == DFLAG_SET ? true : false;
78 + }
79 +
80 + /**
81 + * Constructor to initialize variables.
82 + *
83 + * @param bDFlag D-flag
84 + * @param bTFlag T-flag
85 + * @param bIFlag I-flag
86 + * @param bSFlag S-flag
87 + * @param bUFlag U-flag
88 + */
89 + public StatefulPceCapabilityTlv(boolean bDFlag, boolean bTFlag, boolean bIFlag, boolean bSFlag, boolean bUFlag) {
90 + this.bDFlag = bDFlag;
91 + this.bTFlag = bTFlag;
92 + this.bIFlag = bIFlag;
93 + this.bSFlag = bSFlag;
94 + this.bUFlag = bUFlag;
95 + this.rawValue = 0;
96 + isRawValueSet = false;
97 + }
98 +
99 + /**
100 + * Returns object of StatefulPceCapabilityTlv.
101 + *
102 + * @param raw value Flags
103 + * @return object of StatefulPceCapabilityTlv
104 + */
105 + public static StatefulPceCapabilityTlv of(final int raw) {
106 + return new StatefulPceCapabilityTlv(raw);
107 + }
108 +
109 + @Override
110 + public PcepVersion getVersion() {
111 + return PcepVersion.PCEP_1;
112 + }
113 +
114 + /**
115 + * Returns D-flag.
116 + *
117 + * @return bDFlag D-flag
118 + */
119 + public boolean getDFlag() {
120 + return bDFlag;
121 + }
122 +
123 + /**
124 + * Returns T-flag.
125 + *
126 + * @return bTFlag T-flag
127 + */
128 + public boolean getTFlag() {
129 + return bTFlag;
130 + }
131 +
132 + /**
133 + * Returns I-flag.
134 + *
135 + * @return bIFlag I-flag
136 + */
137 + public boolean getIFlag() {
138 + return bIFlag;
139 + }
140 +
141 + /**
142 + * Returns S-flag.
143 + *
144 + * @return bSFlag S-flag
145 + */
146 + public boolean getSFlag() {
147 + return bSFlag;
148 + }
149 +
150 + /**
151 + * Returns U-flag.
152 + *
153 + * @return bUFlag U-flag
154 + */
155 + public boolean getUFlag() {
156 + return bUFlag;
157 + }
158 +
159 + /**
160 + * Returns raw value Flags.
161 + *
162 + * @return rawValue Flags
163 + */
164 + public int getInt() {
165 + return rawValue;
166 + }
167 +
168 + @Override
169 + public short getType() {
170 + return TYPE;
171 + }
172 +
173 + @Override
174 + public short getLength() {
175 + return LENGTH;
176 + }
177 +
178 + @Override
179 + public int hashCode() {
180 + if (isRawValueSet) {
181 + return Objects.hash(rawValue);
182 + } else {
183 + return Objects.hash(bDFlag, bTFlag, bIFlag, bSFlag, bUFlag);
184 + }
185 + }
186 +
187 + @Override
188 + public boolean equals(Object obj) {
189 + if (this == obj) {
190 + return true;
191 + }
192 + if (obj instanceof StatefulPceCapabilityTlv) {
193 + StatefulPceCapabilityTlv other = (StatefulPceCapabilityTlv) obj;
194 + if (isRawValueSet) {
195 + return Objects.equals(this.rawValue, other.rawValue);
196 + } else {
197 + return Objects.equals(this.bDFlag, other.bDFlag) && Objects.equals(this.bTFlag, other.bTFlag)
198 + && Objects.equals(this.bIFlag, other.bIFlag) && Objects.equals(this.bSFlag, other.bSFlag)
199 + && Objects.equals(this.bUFlag, other.bUFlag);
200 + }
201 + }
202 + return false;
203 + }
204 +
205 + @Override
206 + public int write(ChannelBuffer c) {
207 + int iLenStartIndex = c.writerIndex();
208 + c.writeShort(TYPE);
209 + c.writeShort(LENGTH);
210 + if (isRawValueSet) {
211 + c.writeInt(rawValue);
212 + } else {
213 + int temp = 0;
214 + if (bUFlag) {
215 + temp = temp | UFLAG_SET;
216 + }
217 + if (bSFlag) {
218 + temp = temp | SFLAG_SET;
219 + }
220 + if (bIFlag) {
221 + temp = temp | IFLAG_SET;
222 + }
223 + if (bTFlag) {
224 + temp = temp | TFLAG_SET;
225 + }
226 + if (bDFlag) {
227 + temp = temp | DFLAG_SET;
228 + }
229 + c.writeInt(temp);
230 + }
231 + return c.writerIndex() - iLenStartIndex;
232 + }
233 +
234 + /**
235 + * Reads from channel buffer and returns object of StatefulPceCapabilityTlv.
236 + *
237 + * @param c input channel buffer
238 + * @return object of StatefulPceCapabilityTlv
239 + */
240 + public static PcepValueType read(ChannelBuffer c) {
241 + int temp = c.readInt();
242 + boolean bDFlag;
243 + boolean bTFlag;
244 + boolean bIFlag;
245 + boolean bSFlag;
246 + boolean bUFlag;
247 +
248 + bUFlag = (temp & UFLAG_SET) == UFLAG_SET ? true : false;
249 + bSFlag = (temp & SFLAG_SET) == SFLAG_SET ? true : false;
250 + bIFlag = (temp & IFLAG_SET) == IFLAG_SET ? true : false;
251 + bTFlag = (temp & TFLAG_SET) == TFLAG_SET ? true : false;
252 + bDFlag = (temp & DFLAG_SET) == DFLAG_SET ? true : false;
253 +
254 + return new StatefulPceCapabilityTlv(bDFlag, bTFlag, bIFlag, bSFlag, bUFlag);
255 + }
256 +
257 + @Override
258 + public String toString() {
259 + return MoreObjects.toStringHelper(getClass()).add("type", TYPE).add("Length", LENGTH).add("DFlag", bDFlag)
260 + .add("TFlag", bTFlag).add("IFlag", bIFlag).add("SFlag", bSFlag).add("UFlag", bUFlag).toString();
261 + }
262 +}
1 +/*
2 + * Copyright 2015 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +package org.onosproject.pcepio.types;
17 +
18 +import java.util.Objects;
19 +
20 +import org.jboss.netty.buffer.ChannelBuffer;
21 +import org.onosproject.pcepio.protocol.PcepVersion;
22 +import org.slf4j.Logger;
23 +import org.slf4j.LoggerFactory;
24 +
25 +import com.google.common.base.MoreObjects;
26 +
27 +/**
28 + * Provides TEDefaultMetricTlv.
29 + */
30 +public class TEDefaultMetricTlv implements PcepValueType {
31 +
32 + /*
33 + * Reference :| [I-D.ietf-idr- ls-distribution] /3.3.2.3
34 + * 0 1 2 3
35 + 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
36 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
37 + | Type=TDB37 | Length=4 |
38 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
39 + | TE Default Link Metric |
40 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
41 +
42 + */
43 + protected static final Logger log = LoggerFactory.getLogger(TEDefaultMetricTlv.class);
44 +
45 + public static final short TYPE = 13400; //TDB37
46 + public static final short LENGTH = 4;
47 +
48 + private final int rawValue;
49 +
50 + /**
51 + * Constructor to initialize rawValue.
52 + *
53 + * @param rawValue TE Default Link Metric
54 + */
55 + public TEDefaultMetricTlv(int rawValue) {
56 + this.rawValue = rawValue;
57 + }
58 +
59 + /**
60 + * Returns newly created TEDefaultMetricTlv object.
61 + *
62 + * @param raw raw value
63 + * @return object of TEDefaultMetricTlv.
64 + */
65 + public static TEDefaultMetricTlv of(final int raw) {
66 + return new TEDefaultMetricTlv(raw);
67 + }
68 +
69 + /**
70 + * Returns raw value.
71 + *
72 + * @return rawValue TE Default Link Metric
73 + */
74 + public int getInt() {
75 + return rawValue;
76 + }
77 +
78 + @Override
79 + public PcepVersion getVersion() {
80 + return PcepVersion.PCEP_1;
81 + }
82 +
83 + @Override
84 + public short getType() {
85 + return TYPE;
86 + }
87 +
88 + @Override
89 + public short getLength() {
90 + return LENGTH;
91 + }
92 +
93 + @Override
94 + public int hashCode() {
95 + return Objects.hash(rawValue);
96 + }
97 +
98 + @Override
99 + public boolean equals(Object obj) {
100 + if (this == obj) {
101 + return true;
102 + }
103 + if (obj instanceof TEDefaultMetricTlv) {
104 + TEDefaultMetricTlv other = (TEDefaultMetricTlv) obj;
105 + return Objects.equals(this.rawValue, other.rawValue);
106 + }
107 + return false;
108 + }
109 +
110 + @Override
111 + public int write(ChannelBuffer c) {
112 + int iLenStartIndex = c.writerIndex();
113 + c.writeShort(TYPE);
114 + c.writeShort(LENGTH);
115 + c.writeInt(rawValue);
116 + return c.writerIndex() - iLenStartIndex;
117 + }
118 +
119 + /**
120 + * Reads channel buffer and returns object of TEDefaultMetricTlv.
121 + *
122 + * @param c input channel buffer
123 + * @return object of TEDefaultMetricTlv
124 + */
125 + public static TEDefaultMetricTlv read(ChannelBuffer c) {
126 + return TEDefaultMetricTlv.of(c.readInt());
127 + }
128 +
129 + @Override
130 + public String toString() {
131 + return MoreObjects.toStringHelper(getClass()).add("Type", TYPE).add("Length", LENGTH).add("Value", rawValue)
132 + .toString();
133 + }
134 +}
1 +/*
2 + * Copyright 2015 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +package org.onosproject.pcepio.types;
17 +
18 +import java.util.Iterator;
19 +import java.util.LinkedList;
20 +import java.util.ListIterator;
21 +import java.util.Objects;
22 +
23 +import org.jboss.netty.buffer.ChannelBuffer;
24 +import org.onosproject.pcepio.exceptions.PcepParseException;
25 +import org.onosproject.pcepio.protocol.PcepVersion;
26 +import org.slf4j.Logger;
27 +import org.slf4j.LoggerFactory;
28 +
29 +import com.google.common.base.MoreObjects;
30 +
31 +/**
32 + * Provides TELinkAttributesTlv.
33 + */
34 +public class TELinkAttributesTlv implements PcepValueType {
35 +
36 + /*
37 + * Reference :PCEP Extension for Transporting TE Data draft-dhodylee-pce-pcep-te-data-extn-02
38 + * 0 1 2 3
39 + 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
40 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
41 + | Type=[TBD27] | Length |
42 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
43 + | |
44 + // Link Attributes Sub-TLVs (variable) //
45 + | |
46 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
47 + */
48 +
49 + protected static final Logger log = LoggerFactory.getLogger(TELinkAttributesTlv.class);
50 +
51 + public static final short TYPE = 1897; //TODD:change this TBD27
52 + public short hLength;
53 +
54 + public static final int TLV_HEADER_LENGTH = 4;
55 +
56 + // LinkDescriptors Sub-TLVs (variable)
57 + private LinkedList<PcepValueType> llLinkAttributesSubTLVs;
58 +
59 + /**
60 + * Constructor to initialize Link Attributes Sub TLVs.
61 + *
62 + * @param llLinkAttributesSubTLVs linked list of PcepValueType
63 + */
64 + public TELinkAttributesTlv(LinkedList<PcepValueType> llLinkAttributesSubTLVs) {
65 + this.llLinkAttributesSubTLVs = llLinkAttributesSubTLVs;
66 +
67 + }
68 +
69 + /**
70 + * Returns object of TE Link Attributes TLV.
71 + *
72 + * @param llLinkAttributesSubTLVs linked list of Link Attribute of Sub TLV
73 + * @return object of TELinkAttributesTlv
74 + */
75 + public static TELinkAttributesTlv of(final LinkedList<PcepValueType> llLinkAttributesSubTLVs) {
76 + return new TELinkAttributesTlv(llLinkAttributesSubTLVs);
77 + }
78 +
79 + /**
80 + * Returns linked list of Link Attribute of Sub TLV.
81 + *
82 + * @return llLinkAttributesSubTLVs linked list of Link Attribute of Sub TLV
83 + */
84 + public LinkedList<PcepValueType> getllLinkAttributesSubTLVs() {
85 + return llLinkAttributesSubTLVs;
86 + }
87 +
88 + @Override
89 + public PcepVersion getVersion() {
90 + return PcepVersion.PCEP_1;
91 + }
92 +
93 + @Override
94 + public short getType() {
95 + return TYPE;
96 + }
97 +
98 + @Override
99 + public short getLength() {
100 + return hLength;
101 + }
102 +
103 + @Override
104 + public int hashCode() {
105 + return Objects.hash(llLinkAttributesSubTLVs.hashCode());
106 + }
107 +
108 + @Override
109 + public boolean equals(Object obj) {
110 + if (this == obj) {
111 + return true;
112 + }
113 + /*
114 + * Here we have a list of Tlv so to compare each sub tlv between the object
115 + * we have to take a list iterator so one by one we can get each sub tlv object
116 + * and can compare them.
117 + * it may be possible that the size of 2 lists is not equal so we have to first check
118 + * the size, if both are same then we should check for the subtlv objects otherwise
119 + * we should return false.
120 + */
121 + if (obj instanceof TELinkAttributesTlv) {
122 + int countObjSubTlv = 0;
123 + int countOtherSubTlv = 0;
124 + boolean isCommonSubTlv = true;
125 + TELinkAttributesTlv other = (TELinkAttributesTlv) obj;
126 + Iterator<PcepValueType> objListIterator = ((TELinkAttributesTlv) obj).llLinkAttributesSubTLVs.iterator();
127 + countObjSubTlv = ((TELinkAttributesTlv) obj).llLinkAttributesSubTLVs.size();
128 + countOtherSubTlv = other.llLinkAttributesSubTLVs.size();
129 + if (countObjSubTlv != countOtherSubTlv) {
130 + return false;
131 + } else {
132 + while (objListIterator.hasNext() && isCommonSubTlv) {
133 + PcepValueType subTlv = objListIterator.next();
134 + isCommonSubTlv = Objects.equals(llLinkAttributesSubTLVs.contains(subTlv),
135 + other.llLinkAttributesSubTLVs.contains(subTlv));
136 + }
137 + return isCommonSubTlv;
138 + }
139 + }
140 + return false;
141 + }
142 +
143 + @Override
144 + public int write(ChannelBuffer c) {
145 + int tlvStartIndex = c.writerIndex();
146 + c.writeShort(TYPE);
147 + int tlvLenIndex = c.writerIndex();
148 + hLength = 0;
149 + c.writeShort(hLength);
150 +
151 + ListIterator<PcepValueType> listIterator = llLinkAttributesSubTLVs.listIterator();
152 +
153 + while (listIterator.hasNext()) {
154 + PcepValueType tlv = listIterator.next();
155 +
156 + if (null == tlv) {
157 + log.debug("TLV is null from subTlv list");
158 + continue;
159 + }
160 + tlv.write(c);
161 +
162 + // need to take care of padding
163 + int pad = tlv.getLength() % 4;
164 +
165 + if (0 != pad) {
166 + pad = 4 - pad;
167 + for (int i = 0; i < pad; ++i) {
168 + c.writeByte((byte) 0);
169 + }
170 + }
171 + }
172 +
173 + hLength = (short) (c.writerIndex() - tlvStartIndex);
174 + c.setShort(tlvLenIndex, hLength);
175 +
176 + return c.writerIndex() - tlvStartIndex;
177 + }
178 +
179 + /**
180 + * Reads channel buffer and returns object of TE Link Attributes TLV.
181 + *
182 + * @param c input channel buffer
183 + * @param hLength length
184 + * @return object of TELinkAttributesTlv
185 + * @throws PcepParseException if mandatory fields are missing
186 + */
187 + public static PcepValueType read(ChannelBuffer c, short hLength) throws PcepParseException {
188 +
189 + // Node Descriptor Sub-TLVs (variable)
190 + LinkedList<PcepValueType> llLinkAttributesSubTLVs = new LinkedList<PcepValueType>();
191 +
192 + ChannelBuffer tempCb = c.readBytes(hLength - TLV_HEADER_LENGTH);
193 +
194 + while (TLV_HEADER_LENGTH <= tempCb.readableBytes()) {
195 +
196 + PcepValueType tlv;
197 + short hType = tempCb.readShort();
198 + int iValue = 0;
199 + short length = tempCb.readShort();
200 + switch (hType) {
201 +
202 + case IPv4TERouterIdOfLocalNodeTlv.TYPE:
203 + iValue = tempCb.readInt();
204 + tlv = new IPv4TERouterIdOfLocalNodeTlv(iValue);
205 + break;
206 + case IPv6TERouterIdofLocalNodeTlv.TYPE:
207 + byte[] ipv6LValue = new byte[IPv6TERouterIdofLocalNodeTlv.VALUE_LENGTH];
208 + tempCb.readBytes(ipv6LValue, 0, IPv6TERouterIdofLocalNodeTlv.VALUE_LENGTH);
209 + tlv = new IPv6TERouterIdofLocalNodeTlv(ipv6LValue);
210 + break;
211 + case IPv4TERouterIdOfRemoteNodeTlv.TYPE:
212 + iValue = tempCb.readInt();
213 + tlv = new IPv4TERouterIdOfRemoteNodeTlv(iValue);
214 + break;
215 + case IPv6TERouterIdofRemoteNodeTlv.TYPE:
216 + byte[] ipv6RValue = new byte[IPv6TERouterIdofRemoteNodeTlv.VALUE_LENGTH];
217 + tempCb.readBytes(ipv6RValue, 0, IPv6TERouterIdofRemoteNodeTlv.VALUE_LENGTH);
218 + tlv = new IPv6TERouterIdofRemoteNodeTlv(ipv6RValue);
219 + break;
220 + case LinkLocalRemoteIdentifiersTlv.TYPE:
221 + tlv = LinkLocalRemoteIdentifiersTlv.read(tempCb);
222 + break;
223 + case AdministrativeGroupTlv.TYPE:
224 + iValue = tempCb.readInt();
225 + tlv = new AdministrativeGroupTlv(iValue);
226 + break;
227 + case MaximumLinkBandwidthTlv.TYPE:
228 + iValue = tempCb.readInt();
229 + tlv = new MaximumLinkBandwidthTlv(iValue);
230 + break;
231 + case MaximumReservableLinkBandwidthTlv.TYPE:
232 + iValue = tempCb.readInt();
233 + tlv = new MaximumReservableLinkBandwidthTlv(iValue);
234 + break;
235 + case UnreservedBandwidthTlv.TYPE:
236 + iValue = tempCb.readInt();
237 + tlv = new UnreservedBandwidthTlv(iValue);
238 + break;
239 + case TEDefaultMetricTlv.TYPE:
240 + iValue = tempCb.readInt();
241 + tlv = new TEDefaultMetricTlv(iValue);
242 + break;
243 + case LinkProtectionTypeTlv.TYPE:
244 + tlv = LinkProtectionTypeTlv.read(tempCb);
245 + break;
246 + case MPLSProtocolMaskTlv.TYPE:
247 + byte cValue = tempCb.readByte();
248 + tlv = new MPLSProtocolMaskTlv(cValue);
249 + break;
250 + case IGPMetricTlv.TYPE:
251 + tlv = IGPMetricTlv.read(tempCb, length);
252 + break;
253 + case SharedRiskLinkGroupTlv.TYPE:
254 + tlv = SharedRiskLinkGroupTlv.read(tempCb, length);
255 + break;
256 + case OpaqueLinkAttributeTlv.TYPE:
257 + tlv = OpaqueLinkAttributeTlv.read(tempCb, length);
258 + break;
259 + case LinkNameTlv.TYPE:
260 + tlv = LinkNameTlv.read(tempCb, length);
261 + break;
262 + default:
263 + throw new PcepParseException("Unsupported Sub TLV type :" + hType);
264 + }
265 +
266 + // Check for the padding
267 + int pad = length % 4;
268 + if (0 < pad) {
269 + pad = 4 - pad;
270 + if (pad <= tempCb.readableBytes()) {
271 + tempCb.skipBytes(pad);
272 + }
273 + }
274 + llLinkAttributesSubTLVs.add(tlv);
275 + }
276 +
277 + if (0 < tempCb.readableBytes()) {
278 +
279 + throw new PcepParseException("Sub Tlv parsing error. Extra bytes received.");
280 + }
281 +
282 + return new TELinkAttributesTlv(llLinkAttributesSubTLVs);
283 + }
284 +
285 + @Override
286 + public String toString() {
287 + return MoreObjects.toStringHelper(getClass()).add("Type", TYPE).add("Length", hLength)
288 + .add("LinkAttributesSubTLVs", llLinkAttributesSubTLVs).toString();
289 + }
290 +}
1 +/*
2 + * Copyright 2015 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +package org.onosproject.pcepio.types;
17 +
18 +import java.util.Iterator;
19 +import java.util.LinkedList;
20 +import java.util.ListIterator;
21 +import java.util.Objects;
22 +
23 +import org.jboss.netty.buffer.ChannelBuffer;
24 +import org.onosproject.pcepio.exceptions.PcepParseException;
25 +import org.onosproject.pcepio.protocol.PcepVersion;
26 +import org.slf4j.Logger;
27 +import org.slf4j.LoggerFactory;
28 +
29 +import com.google.common.base.MoreObjects;
30 +
31 +/**
32 + * Provides TE Link Descriptors TLV.
33 + */
34 +public class TELinkDescriptorsTLV implements PcepValueType {
35 +
36 + /*
37 + * Reference: PCEP Extension for Transporting TE Data draft-dhodylee-pce-pcep-te-data-extn-02
38 + * 0 1 2 3
39 + 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
40 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
41 + | Type=[TBD14] | Length |
42 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
43 + | |
44 + // Link Descriptor Sub-TLVs (variable) //
45 + | |
46 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
47 +
48 + */
49 +
50 + protected static final Logger log = LoggerFactory.getLogger(TELinkDescriptorsTLV.class);
51 +
52 + public static final short TYPE = 1070; //TODD:change this TBD14
53 + public short hLength;
54 +
55 + public static final int TLV_HEADER_LENGTH = 4;
56 +
57 + // LinkDescriptors Sub-TLVs (variable)
58 + private LinkedList<PcepValueType> llLinkDescriptorsSubTLVs;
59 +
60 + /**
61 + * Constructor to initialize llLinkDescriptorsSubTLVs.
62 + *
63 + * @param llLinkDescriptorsSubTLVs of PcepValueType
64 + */
65 + public TELinkDescriptorsTLV(LinkedList<PcepValueType> llLinkDescriptorsSubTLVs) {
66 + this.llLinkDescriptorsSubTLVs = llLinkDescriptorsSubTLVs;
67 + }
68 +
69 + /**
70 + * Returns object of TELinkDescriptorsTLV.
71 + *
72 + * @param llLinkDescriptorsSubTLVs of PcepValueType
73 + * @return object of TELinkDescriptorsTLV
74 + */
75 + public static TELinkDescriptorsTLV of(final LinkedList<PcepValueType> llLinkDescriptorsSubTLVs) {
76 + return new TELinkDescriptorsTLV(llLinkDescriptorsSubTLVs);
77 + }
78 +
79 + /**
80 + * Returns linked list of Link Attribute of Sub TLV.
81 + *
82 + * @return llLinkDescriptorsSubTLVs linked list of Link Attribute of Sub TLV
83 + */
84 + public LinkedList<PcepValueType> getllLinkDescriptorsSubTLVs() {
85 + return llLinkDescriptorsSubTLVs;
86 + }
87 +
88 + @Override
89 + public PcepVersion getVersion() {
90 + return PcepVersion.PCEP_1;
91 + }
92 +
93 + @Override
94 + public short getType() {
95 + return TYPE;
96 + }
97 +
98 + @Override
99 + public short getLength() {
100 + return hLength;
101 + }
102 +
103 + @Override
104 + public int hashCode() {
105 + return Objects.hash(llLinkDescriptorsSubTLVs.hashCode());
106 + }
107 +
108 + @Override
109 + public boolean equals(Object obj) {
110 + if (this == obj) {
111 + return true;
112 + }
113 + /*
114 + * Here we have a list of Tlv so to compare each sub tlv between the object
115 + * we have to take a list iterator so one by one we can get each sub tlv object
116 + * and can compare them.
117 + * it may be possible that the size of 2 lists is not equal so we have to first check
118 + * the size, if both are same then we should check for the subtlv objects otherwise
119 + * we should return false.
120 + */
121 + if (obj instanceof TELinkDescriptorsTLV) {
122 + int countObjSubTlv = 0;
123 + int countOtherSubTlv = 0;
124 + boolean isCommonSubTlv = true;
125 + TELinkDescriptorsTLV other = (TELinkDescriptorsTLV) obj;
126 + Iterator<PcepValueType> objListIterator = ((TELinkDescriptorsTLV) obj).llLinkDescriptorsSubTLVs.iterator();
127 + countObjSubTlv = ((TELinkDescriptorsTLV) obj).llLinkDescriptorsSubTLVs.size();
128 + countOtherSubTlv = other.llLinkDescriptorsSubTLVs.size();
129 + if (countObjSubTlv != countOtherSubTlv) {
130 + return false;
131 + } else {
132 + while (objListIterator.hasNext() && isCommonSubTlv) {
133 + PcepValueType subTlv = objListIterator.next();
134 + isCommonSubTlv = Objects.equals(llLinkDescriptorsSubTLVs.contains(subTlv),
135 + other.llLinkDescriptorsSubTLVs.contains(subTlv));
136 + }
137 + return isCommonSubTlv;
138 + }
139 + }
140 + return false;
141 + }
142 +
143 + @Override
144 + public int write(ChannelBuffer c) {
145 + int tlvStartIndex = c.writerIndex();
146 + c.writeShort(TYPE);
147 + int tlvLenIndex = c.writerIndex();
148 + hLength = 0;
149 + c.writeShort(hLength);
150 +
151 + ListIterator<PcepValueType> listIterator = llLinkDescriptorsSubTLVs.listIterator();
152 +
153 + while (listIterator.hasNext()) {
154 + PcepValueType tlv = listIterator.next();
155 +
156 + tlv.write(c);
157 +
158 + // need to take care of padding
159 + int pad = tlv.getLength() % 4;
160 +
161 + if (0 != pad) {
162 + pad = 4 - pad;
163 + for (int i = 0; i < pad; ++i) {
164 + c.writeByte((byte) 0);
165 + }
166 + }
167 + }
168 +
169 + hLength = (short) (c.writerIndex() - tlvStartIndex);
170 + c.setShort(tlvLenIndex, hLength);
171 +
172 + return c.writerIndex() - tlvStartIndex;
173 + }
174 +
175 + /**
176 + * Reads channel buffer and returns object of TELinkDescriptorsTLV.
177 + *
178 + * @param c input channel buffer
179 + * @param length length
180 + * @return object of TELinkDescriptorsTLV
181 + * @throws PcepParseException if mandatory fields are missing
182 + */
183 + public static PcepValueType read(ChannelBuffer c, short length) throws PcepParseException {
184 +
185 + // Node Descriptor Sub-TLVs (variable)
186 + LinkedList<PcepValueType> llLinkDescriptorsSubTLVs = new LinkedList<PcepValueType>();
187 +
188 + ChannelBuffer tempCb = c.readBytes(length - TLV_HEADER_LENGTH);
189 +
190 + while (TLV_HEADER_LENGTH <= tempCb.readableBytes()) {
191 +
192 + PcepValueType tlv;
193 + short hType = tempCb.readShort();
194 + int iValue = 0;
195 + short hLength = tempCb.readShort();
196 + log.debug("sub Tlv Length" + hLength);
197 + switch (hType) {
198 +
199 + case LinkLocalRemoteIdentifiersTlv.TYPE:
200 + tlv = LinkLocalRemoteIdentifiersTlv.read(tempCb);
201 + break;
202 + case IPv4InterfaceAddressTlv.TYPE:
203 + iValue = tempCb.readInt();
204 + tlv = new IPv4InterfaceAddressTlv(iValue);
205 + break;
206 + case IPv4NeighborAddressTlv.TYPE:
207 + iValue = tempCb.readInt();
208 + tlv = new IPv4NeighborAddressTlv(iValue);
209 + break;
210 + case IPv6InterfaceAddressTlv.TYPE:
211 + byte[] ipv6Value = new byte[IPv6InterfaceAddressTlv.VALUE_LENGTH];
212 + tempCb.readBytes(ipv6Value, 0, IPv6InterfaceAddressTlv.VALUE_LENGTH);
213 + tlv = new IPv6InterfaceAddressTlv(ipv6Value);
214 + break;
215 + case IPv6NeighborAddressTlv.TYPE:
216 + byte[] ipv6NeighborAdd = new byte[IPv6NeighborAddressTlv.VALUE_LENGTH];
217 + tempCb.readBytes(ipv6NeighborAdd, 0, IPv6NeighborAddressTlv.VALUE_LENGTH);
218 + tlv = new IPv6NeighborAddressTlv(ipv6NeighborAdd);
219 + break;
220 + default:
221 + throw new PcepParseException("Unsupported Sub TLV type:" + hType);
222 + }
223 +
224 + // Check for the padding
225 + int pad = hLength % 4;
226 + if (0 < pad) {
227 + pad = 4 - pad;
228 + if (pad <= tempCb.readableBytes()) {
229 + tempCb.skipBytes(pad);
230 + }
231 + }
232 + llLinkDescriptorsSubTLVs.add(tlv);
233 +
234 + }
235 +
236 + if (0 < tempCb.readableBytes()) {
237 +
238 + throw new PcepParseException("Sub Tlv parsing error. Extra bytes received.");
239 + }
240 + return new TELinkDescriptorsTLV(llLinkDescriptorsSubTLVs);
241 + }
242 +
243 + @Override
244 + public String toString() {
245 + return MoreObjects.toStringHelper(getClass()).add("Type", TYPE).add("Length", hLength)
246 + .add("LinkDescriptorsSubTLVs", llLinkDescriptorsSubTLVs).toString();
247 + }
248 +}
1 +/*
2 + * Copyright 2015 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +package org.onosproject.pcepio.types;
17 +
18 +import java.util.Iterator;
19 +import java.util.LinkedList;
20 +import java.util.ListIterator;
21 +import java.util.Objects;
22 +
23 +import org.jboss.netty.buffer.ChannelBuffer;
24 +import org.onosproject.pcepio.exceptions.PcepParseException;
25 +import org.onosproject.pcepio.protocol.PcepVersion;
26 +import org.slf4j.Logger;
27 +import org.slf4j.LoggerFactory;
28 +
29 +import com.google.common.base.MoreObjects;
30 +
31 +public class TENodeAttributesTlv implements PcepValueType {
32 + /*
33 + * Reference :PCEP Extension for Transporting TE Data draft-dhodylee-pce-pcep-te-data-extn-02
34 + *
35 + 0 1 2 3
36 + 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
37 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
38 + | Type=[TBD20] | Length |
39 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
40 + | |
41 + // Node Attributes Sub-TLVs (variable) //
42 + | |
43 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
44 +
45 +
46 + */
47 +
48 + protected static final Logger log = LoggerFactory.getLogger(TENodeAttributesTlv.class);
49 +
50 + public static final short TYPE = 1267; //TODD:change this TBD20
51 + public short hLength;
52 +
53 + public static final int TLV_HEADER_LENGTH = 4;
54 + // LinkDescriptors Sub-TLVs (variable)
55 + private LinkedList<PcepValueType> llNodeAttributesSubTLVs;
56 +
57 + /**
58 + * Constructor to initialize llNodeAttributesSubTLVs.
59 + *
60 + * @param llNodeAttributesSubTLVs linked list of Node Attributes Sub-TLVs
61 + */
62 + public TENodeAttributesTlv(LinkedList<PcepValueType> llNodeAttributesSubTLVs) {
63 + this.llNodeAttributesSubTLVs = llNodeAttributesSubTLVs;
64 + }
65 +
66 + /**
67 + * Returns object of TENodeAttributesTlv.
68 + *
69 + * @param llNodeAttributesSubTLVs LinkedList of PcepValueType
70 + * @return object of TENodeAttributesTlv
71 + */
72 + public static TENodeAttributesTlv of(LinkedList<PcepValueType> llNodeAttributesSubTLVs) {
73 + return new TENodeAttributesTlv(llNodeAttributesSubTLVs);
74 + }
75 +
76 + /**
77 + * Returns Node Attributes Sub-TLVs.
78 + *
79 + * @return llNodeAttributesSubTLVs linked list of Node Attributes Sub-TLVs
80 + */
81 + public LinkedList<PcepValueType> getllNodeAttributesSubTLVs() {
82 + return llNodeAttributesSubTLVs;
83 + }
84 +
85 + @Override
86 + public PcepVersion getVersion() {
87 + return PcepVersion.PCEP_1;
88 + }
89 +
90 + @Override
91 + public short getType() {
92 + return TYPE;
93 + }
94 +
95 + @Override
96 + public short getLength() {
97 + return hLength;
98 + }
99 +
100 + @Override
101 + public int hashCode() {
102 + return Objects.hash(llNodeAttributesSubTLVs.hashCode());
103 + }
104 +
105 + @Override
106 + public boolean equals(Object obj) {
107 + if (this == obj) {
108 + return true;
109 + }
110 + /*
111 + * Here we have a list of Tlv so to compare each sub tlv between the object
112 + * we have to take a list iterator so one by one we can get each sub tlv object
113 + * and can compare them.
114 + * it may be possible that the size of 2 lists is not equal so we have to first check
115 + * the size, if both are same then we should check for the subtlv objects otherwise
116 + * we should return false.
117 + */
118 + if (obj instanceof TENodeAttributesTlv) {
119 + int countObjSubTlv = 0;
120 + int countOtherSubTlv = 0;
121 + boolean isCommonSubTlv = true;
122 + TENodeAttributesTlv other = (TENodeAttributesTlv) obj;
123 + Iterator<PcepValueType> objListIterator = ((TENodeAttributesTlv) obj).llNodeAttributesSubTLVs.iterator();
124 + countObjSubTlv = ((TENodeAttributesTlv) obj).llNodeAttributesSubTLVs.size();
125 + countOtherSubTlv = other.llNodeAttributesSubTLVs.size();
126 + if (countObjSubTlv != countOtherSubTlv) {
127 + return false;
128 + } else {
129 + while (objListIterator.hasNext() && isCommonSubTlv) {
130 + PcepValueType subTlv = objListIterator.next();
131 + isCommonSubTlv = Objects.equals(llNodeAttributesSubTLVs.contains(subTlv),
132 + other.llNodeAttributesSubTLVs.contains(subTlv));
133 + }
134 + return isCommonSubTlv;
135 + }
136 + }
137 + return false;
138 + }
139 +
140 + @Override
141 + public int write(ChannelBuffer c) {
142 + int tlvStartIndex = c.writerIndex();
143 + c.writeShort(TYPE);
144 + int tlvLenIndex = c.writerIndex();
145 + hLength = 0;
146 + c.writeShort(hLength);
147 +
148 + ListIterator<PcepValueType> listIterator = llNodeAttributesSubTLVs.listIterator();
149 +
150 + while (listIterator.hasNext()) {
151 + PcepValueType tlv = listIterator.next();
152 +
153 + tlv.write(c);
154 +
155 + // need to take care of padding
156 + int pad = tlv.getLength() % 4;
157 +
158 + if (0 != pad) {
159 + pad = 4 - pad;
160 + for (int i = 0; i < pad; ++i) {
161 + c.writeByte((byte) 0);
162 + }
163 + }
164 + }
165 +
166 + hLength = (short) (c.writerIndex() - tlvStartIndex);
167 + c.setShort(tlvLenIndex, hLength);
168 +
169 + return c.writerIndex() - tlvStartIndex;
170 + }
171 +
172 + /**
173 + * Reads the channel buffer and returns object of TENodeAttributesTlv.
174 + *
175 + * @param c input channel buffer
176 + * @param hLength length
177 + * @return object of TENodeAttributesTlv
178 + * @throws PcepParseException if mandatory fields are missing
179 + */
180 + public static PcepValueType read(ChannelBuffer c, short hLength) throws PcepParseException {
181 +
182 + // Node Descriptor Sub-TLVs (variable)
183 + LinkedList<PcepValueType> llNodeAttributesSubTLVs = new LinkedList<PcepValueType>();
184 +
185 + ChannelBuffer tempCb = c.readBytes(hLength - TLV_HEADER_LENGTH);
186 +
187 + while (TLV_HEADER_LENGTH <= tempCb.readableBytes()) {
188 + PcepValueType tlv;
189 + short hType = tempCb.readShort();
190 + int iValue = 0;
191 + short length = tempCb.readShort();
192 + switch (hType) {
193 +
194 + case NodeFlagBitsTlv.TYPE:
195 + byte cValue = tempCb.readByte();
196 + tlv = new NodeFlagBitsTlv(cValue);
197 + break;
198 + case OpaqueNodeAttributeTlv.TYPE:
199 + tlv = OpaqueNodeAttributeTlv.read(tempCb, length);
200 + break;
201 + case NodeNameTlv.TYPE:
202 + tlv = NodeNameTlv.read(tempCb, length);
203 + break;
204 + case ISISAreaIdentifierTlv.TYPE:
205 + tlv = ISISAreaIdentifierTlv.read(tempCb, length);
206 + break;
207 + case IPv4TERouterIdOfLocalNodeTlv.TYPE:
208 + iValue = tempCb.readInt();
209 + tlv = new IPv4TERouterIdOfLocalNodeTlv(iValue);
210 + break;
211 + case IPv6TERouterIdofLocalNodeTlv.TYPE:
212 + byte[] ipv6Value = new byte[IPv6TERouterIdofLocalNodeTlv.VALUE_LENGTH];
213 + tempCb.readBytes(ipv6Value, 0, IPv6TERouterIdofLocalNodeTlv.VALUE_LENGTH);
214 + tlv = new IPv6TERouterIdofLocalNodeTlv(ipv6Value);
215 + break;
216 + default:
217 + throw new PcepParseException("Unsupported Sub TLV type :" + hType);
218 + }
219 +
220 + // Check for the padding
221 + int pad = length % 4;
222 + if (0 < pad) {
223 + pad = 4 - pad;
224 + if (pad <= tempCb.readableBytes()) {
225 + tempCb.skipBytes(pad);
226 + }
227 + }
228 +
229 + llNodeAttributesSubTLVs.add(tlv);
230 + }
231 +
232 + if (0 < tempCb.readableBytes()) {
233 +
234 + throw new PcepParseException("Sub Tlv parsing error. Extra bytes received.");
235 + }
236 + return new TENodeAttributesTlv(llNodeAttributesSubTLVs);
237 + }
238 +
239 + @Override
240 + public String toString() {
241 + return MoreObjects.toStringHelper(getClass()).add("Type", TYPE).add("Length", hLength)
242 + .add("NodeAttributesSubTLVs", llNodeAttributesSubTLVs).toString();
243 + }
244 +}
1 +/*
2 + * Copyright 2015 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +package org.onosproject.pcepio.types;
17 +
18 +import java.util.Objects;
19 +
20 +import org.jboss.netty.buffer.ChannelBuffer;
21 +import org.onosproject.pcepio.protocol.PcepVersion;
22 +import org.slf4j.Logger;
23 +import org.slf4j.LoggerFactory;
24 +
25 +import com.google.common.base.MoreObjects;
26 +
27 +/**
28 + * Provides TED Capability Tlv.
29 + */
30 +public class TedCapabilityTlv implements PcepValueType {
31 +
32 + /*
33 + * Reference :PCEP Extension for Transporting TE Data draft-dhodylee-pce-pcep-te-data-extn-02
34 + * 0 1 2 3
35 + 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
36 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
37 + | Type=[TBD5] | Length=4 |
38 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
39 + | Flags |R|
40 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
41 + */
42 +
43 + protected static final Logger log = LoggerFactory.getLogger(TedCapabilityTlv.class);
44 +
45 + public static final short TYPE = 132; //TODO: need to change this TBD5
46 + public static final short LENGTH = 4;
47 + public static final int SET = 1;
48 + public static final byte RFLAG_CHECK = 0x01;
49 +
50 + private final boolean bRFlag;
51 + private final int rawValue;
52 + private final boolean isRawValueSet;
53 +
54 + /**
55 + * Constructor to initialize raw Value.
56 + *
57 + * @param rawValue Flags
58 + */
59 + public TedCapabilityTlv(final int rawValue) {
60 + this.rawValue = rawValue;
61 + this.isRawValueSet = true;
62 + int temp = rawValue;
63 + temp = temp & RFLAG_CHECK;
64 + if (temp == SET) {
65 + this.bRFlag = true;
66 + } else {
67 + this.bRFlag = false;
68 + }
69 +
70 + }
71 +
72 + /**
73 + * Constructor to initialize bRFlag.
74 + *
75 + * @param bRFlag R-flag
76 + */
77 + public TedCapabilityTlv(boolean bRFlag) {
78 + this.bRFlag = bRFlag;
79 + this.rawValue = 0;
80 + this.isRawValueSet = false;
81 + }
82 +
83 + /**
84 + * Returns R-flag.
85 + *
86 + * @return bRFlag
87 + */
88 + public boolean getbRFlag() {
89 + return bRFlag;
90 + }
91 +
92 + /**
93 + * Returns an object of TedCapabilityTlv.
94 + *
95 + * @param raw value Flags
96 + * @return object of TedCapabilityTlv
97 + */
98 + public static TedCapabilityTlv of(final int raw) {
99 + return new TedCapabilityTlv(raw);
100 + }
101 +
102 + @Override
103 + public PcepVersion getVersion() {
104 + return PcepVersion.PCEP_1;
105 + }
106 +
107 + public int getInt() {
108 + return rawValue;
109 + }
110 +
111 + @Override
112 + public short getType() {
113 + return TYPE;
114 + }
115 +
116 + @Override
117 + public short getLength() {
118 + return LENGTH;
119 + }
120 +
121 + @Override
122 + public int hashCode() {
123 + if (isRawValueSet) {
124 + return Objects.hash(rawValue);
125 + } else {
126 + return Objects.hash(bRFlag);
127 + }
128 + }
129 +
130 + @Override
131 + public boolean equals(Object obj) {
132 + if (this == obj) {
133 + return true;
134 + }
135 + if (obj instanceof TedCapabilityTlv) {
136 + TedCapabilityTlv other = (TedCapabilityTlv) obj;
137 + if (isRawValueSet) {
138 + return Objects.equals(this.rawValue, other.rawValue);
139 + } else {
140 + return Objects.equals(this.bRFlag, other.bRFlag);
141 + }
142 + }
143 + return false;
144 + }
145 +
146 + @Override
147 + public int write(ChannelBuffer c) {
148 + int iStartIndex = c.writerIndex();
149 + int temp = 0;
150 + c.writeShort(TYPE);
151 + c.writeShort(LENGTH);
152 + if (isRawValueSet) {
153 + c.writeInt(rawValue);
154 + } else {
155 + if (bRFlag) {
156 + temp = temp | RFLAG_CHECK;
157 + }
158 + c.writeInt(temp);
159 + }
160 + return c.writerIndex() - iStartIndex;
161 + }
162 +
163 + /**
164 + * Reads channel buffer and returns object of TedCapabilityTlv.
165 + *
166 + * @param c input channel buffer
167 + * @return object of TedCapabilityTlv
168 + */
169 + public static TedCapabilityTlv read(ChannelBuffer c) {
170 + return TedCapabilityTlv.of(c.readInt());
171 + }
172 +
173 + @Override
174 + public String toString() {
175 + return MoreObjects.toStringHelper(getClass()).add("Type", TYPE).add("Length", LENGTH).add("Value", rawValue)
176 + .toString();
177 + }
178 +}
1 +/*
2 + * Copyright 2015 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +package org.onosproject.pcepio.types;
17 +
18 +import java.util.Objects;
19 +
20 +import org.jboss.netty.buffer.ChannelBuffer;
21 +import org.onosproject.pcepio.protocol.PcepVersion;
22 +import org.slf4j.Logger;
23 +import org.slf4j.LoggerFactory;
24 +
25 +import com.google.common.base.MoreObjects;
26 +
27 +/**
28 + * Provides Unreserved Bandwidth Tlv.
29 + */
30 +public class UnreservedBandwidthTlv implements PcepValueType {
31 +
32 + /* Reference :[RFC5305]/3.6
33 + 0 1 2 3
34 + 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
35 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
36 + | Type=[TDB36] | Length=4 |
37 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
38 + | Unreserved Bandwidth |
39 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
40 + */
41 +
42 + protected static final Logger log = LoggerFactory.getLogger(UnreservedBandwidthTlv.class);
43 +
44 + public static final short TYPE = 11; //TDB36
45 + public static final short LENGTH = 4;
46 +
47 + private final int rawValue;
48 +
49 + /**
50 + * Constructor to initialize rawValue.
51 + *
52 + * @param rawValue Unreserved Bandwidth
53 + */
54 + public UnreservedBandwidthTlv(int rawValue) {
55 + this.rawValue = rawValue;
56 + }
57 +
58 + /**
59 + * Returns newly created UnreservedBandwidthTlv object.
60 + *
61 + * @param raw as Unreserved Bandwidth
62 + * @return object of UnreservedBandwidthTlv
63 + */
64 + public static UnreservedBandwidthTlv of(final int raw) {
65 + return new UnreservedBandwidthTlv(raw);
66 + }
67 +
68 + /**
69 + * Returns Unreserved Bandwidth.
70 + *
71 + * @return rawValue Unreserved Bandwidth
72 + */
73 + public int getInt() {
74 + return rawValue;
75 + }
76 +
77 + @Override
78 + public PcepVersion getVersion() {
79 + return PcepVersion.PCEP_1;
80 + }
81 +
82 + @Override
83 + public short getType() {
84 + return TYPE;
85 + }
86 +
87 + @Override
88 + public short getLength() {
89 + return LENGTH;
90 + }
91 +
92 + @Override
93 + public int hashCode() {
94 + return Objects.hash(rawValue);
95 + }
96 +
97 + @Override
98 + public boolean equals(Object obj) {
99 + if (this == obj) {
100 + return true;
101 + }
102 + if (obj instanceof UnreservedBandwidthTlv) {
103 + UnreservedBandwidthTlv other = (UnreservedBandwidthTlv) obj;
104 + return Objects.equals(this.rawValue, other.rawValue);
105 + }
106 + return false;
107 + }
108 +
109 + @Override
110 + public int write(ChannelBuffer c) {
111 + int iLenStartIndex = c.writerIndex();
112 + c.writeShort(TYPE);
113 + c.writeShort(LENGTH);
114 + c.writeInt(rawValue);
115 + return c.writerIndex() - iLenStartIndex;
116 + }
117 +
118 + /**
119 + * Reads byte stream from channel buffer and returns object of UnreservedBandwidthTlv.
120 + *
121 + * @param c input channel buffer
122 + * @return object of UnreservedBandwidthTlv
123 + */
124 + public static UnreservedBandwidthTlv read(ChannelBuffer c) {
125 + return UnreservedBandwidthTlv.of(c.readInt());
126 + }
127 +
128 + @Override
129 + public String toString() {
130 + return MoreObjects.toStringHelper(getClass()).add("Type", TYPE).add("Length", LENGTH).add("Value", rawValue)
131 + .toString();
132 + }
133 +}
1 +/*
2 + * Copyright 2015 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +package org.onosproject.pcepio;
17 +
18 +import com.google.common.testing.EqualsTester;
19 +
20 +import org.junit.Test;
21 +import org.onosproject.pcepio.types.AdministrativeGroupTlv;
22 +
23 +/**
24 + * Test of the AdministrativeGroupTlv.
25 + */
26 +public class AdministrativeGroupTlvTest {
27 + private final AdministrativeGroupTlv tlv1 = AdministrativeGroupTlv.of(1);
28 + private final AdministrativeGroupTlv sameAsTlv1 = AdministrativeGroupTlv.of(1);
29 + private final AdministrativeGroupTlv tlv2 = AdministrativeGroupTlv.of(2);
30 +
31 + @Test
32 + public void basics() {
33 + new EqualsTester()
34 + .addEqualityGroup(tlv1, sameAsTlv1)
35 + .addEqualityGroup(tlv2)
36 + .testEquals();
37 + }
38 +}
1 +/*
2 + * Copyright 2014 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +package org.onosproject.pcepio;
17 +
18 +import com.google.common.testing.EqualsTester;
19 +
20 +import org.junit.Test;
21 +import org.onosproject.pcepio.types.AutonomousSystemTlv;
22 +
23 +/**
24 + * Test of the AutonomousSystemTlv.
25 + */
26 +public class AutonomousSystemTlvTest {
27 + private final AutonomousSystemTlv tlv1 = AutonomousSystemTlv.of(1);
28 + private final AutonomousSystemTlv sameAsTlv1 = AutonomousSystemTlv.of(1);
29 + private final AutonomousSystemTlv tlv2 = AutonomousSystemTlv.of(2);
30 +
31 + @Test
32 + public void basics() {
33 + new EqualsTester()
34 + .addEqualityGroup(tlv1, sameAsTlv1)
35 + .addEqualityGroup(tlv2)
36 + .testEquals();
37 + }
38 +}
1 +/*
2 + * Copyright 2014 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +package org.onosproject.pcepio;
17 +
18 +import com.google.common.testing.EqualsTester;
19 +
20 +import org.junit.Test;
21 +import org.onosproject.pcepio.types.BGPLSidentifierTlv;
22 +
23 +/**
24 + * Test of the BGPLSidentifierTlv.
25 + */
26 +public class BGPLSidentifierTlvTest {
27 + private final BGPLSidentifierTlv tlv1 = BGPLSidentifierTlv.of(1);
28 + private final BGPLSidentifierTlv sameAsTlv1 = BGPLSidentifierTlv.of(1);
29 + private final BGPLSidentifierTlv tlv2 = BGPLSidentifierTlv.of(2);
30 +
31 + @Test
32 + public void basics() {
33 + new EqualsTester()
34 + .addEqualityGroup(tlv1, sameAsTlv1)
35 + .addEqualityGroup(tlv2)
36 + .testEquals();
37 + }
38 +}
1 +/*
2 + * Copyright 2014 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +package org.onosproject.pcepio;
17 +
18 +import com.google.common.testing.EqualsTester;
19 +
20 +import org.junit.Test;
21 +import org.onosproject.pcepio.types.GmplsCapabilityTlv;
22 +
23 +/**
24 + * Test of the GmplsCapabilityTlv.
25 + */
26 +public class GmplsCapabilityTlvTest {
27 + private final GmplsCapabilityTlv tlv1 = GmplsCapabilityTlv.of(1);
28 + private final GmplsCapabilityTlv sameAsTlv1 = GmplsCapabilityTlv.of(1);
29 + private final GmplsCapabilityTlv tlv2 = GmplsCapabilityTlv.of(2);
30 +
31 + @Test
32 + public void basics() {
33 + new EqualsTester()
34 + .addEqualityGroup(tlv1, sameAsTlv1)
35 + .addEqualityGroup(tlv2)
36 + .testEquals();
37 + }
38 +}
1 +/*
2 + * Copyright 2014 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +package org.onosproject.pcepio;
17 +
18 +import com.google.common.testing.EqualsTester;
19 +
20 +import org.junit.Test;
21 +import org.onosproject.pcepio.types.IGPMetricTlv;
22 +
23 +/**
24 + * Test of the IGPMetricTlv.
25 + */
26 +public class IGPMetricTlvTest {
27 + private byte[] b1 = new byte[] {0x01, 0x02};
28 + private byte[] b2 = new byte[] {0x01, 0x02};
29 + private final IGPMetricTlv tlv1 = IGPMetricTlv.of(b1, (short) 2);
30 + private final IGPMetricTlv sameAsTlv1 = IGPMetricTlv.of(b1, (short) 2);
31 + private final IGPMetricTlv tlv2 = IGPMetricTlv.of(b2, (short) 2);
32 +
33 + @Test
34 + public void basics() {
35 + new EqualsTester()
36 + .addEqualityGroup(tlv1, sameAsTlv1)
37 + .addEqualityGroup(tlv2)
38 + .testEquals();
39 + }
40 +}
1 +/*
2 + * Copyright 2014 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +package org.onosproject.pcepio;
17 +
18 +import com.google.common.testing.EqualsTester;
19 +
20 +import org.junit.Test;
21 +import org.onosproject.pcepio.types.IPv4InterfaceAddressTlv;
22 +
23 +/**
24 + * Test of the IPv4InterfaceAddressTlv.
25 + */
26 +public class IPv4InterfaceAddressTlvTest {
27 +
28 + private final IPv4InterfaceAddressTlv tlv1 = IPv4InterfaceAddressTlv.of(2);
29 + private final IPv4InterfaceAddressTlv sameAsTlv1 = IPv4InterfaceAddressTlv.of(2);
30 + private final IPv4InterfaceAddressTlv tlv2 = IPv4InterfaceAddressTlv.of(3);
31 +
32 + @Test
33 + public void basics() {
34 + new EqualsTester()
35 + .addEqualityGroup(tlv1, sameAsTlv1)
36 + .addEqualityGroup(tlv2)
37 + .testEquals();
38 + }
39 +}
1 +/*
2 + * Copyright 2014 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +package org.onosproject.pcepio;
17 +
18 +import com.google.common.testing.EqualsTester;
19 +
20 +import org.junit.Test;
21 +import org.onosproject.pcepio.types.IPv4NeighborAddressTlv;
22 +
23 +/**
24 + * Test of the IPv4NeighborAddressTlv.
25 + */
26 +public class IPv4NeighborAddressTlvTest {
27 +
28 + private final IPv4NeighborAddressTlv tlv1 = IPv4NeighborAddressTlv.of(2);
29 + private final IPv4NeighborAddressTlv sameAsTlv1 = IPv4NeighborAddressTlv.of(2);
30 + private final IPv4NeighborAddressTlv tlv2 = IPv4NeighborAddressTlv.of(3);
31 +
32 + @Test
33 + public void basics() {
34 + new EqualsTester()
35 + .addEqualityGroup(tlv1, sameAsTlv1)
36 + .addEqualityGroup(tlv2)
37 + .testEquals();
38 + }
39 +}
1 +/*
2 + * Copyright 2014 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +package org.onosproject.pcepio;
17 +
18 +import com.google.common.testing.EqualsTester;
19 +
20 +import org.junit.Test;
21 +import org.onosproject.pcepio.types.IPv4TERouterIdOfLocalNodeTlv;
22 +
23 +/**
24 + * Test of the IPv4TERouterIdOfLocalNodeTlv.
25 + */
26 +public class IPv4TERouterIdOfLocalNodeTlvTest {
27 +
28 + private final IPv4TERouterIdOfLocalNodeTlv tlv1 = IPv4TERouterIdOfLocalNodeTlv.of(2);
29 + private final IPv4TERouterIdOfLocalNodeTlv sameAsTlv1 = IPv4TERouterIdOfLocalNodeTlv.of(2);
30 + private final IPv4TERouterIdOfLocalNodeTlv tlv2 = IPv4TERouterIdOfLocalNodeTlv.of(3);
31 +
32 + @Test
33 + public void basics() {
34 + new EqualsTester()
35 + .addEqualityGroup(tlv1, sameAsTlv1)
36 + .addEqualityGroup(tlv2)
37 + .testEquals();
38 + }
39 +}
1 +/*
2 + * Copyright 2014 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +package org.onosproject.pcepio;
17 +
18 +import com.google.common.testing.EqualsTester;
19 +
20 +import org.junit.Test;
21 +import org.onosproject.pcepio.types.IPv4TERouterIdOfRemoteNodeTlv;
22 +
23 +/**
24 + * Test of the IPv4TERouterIdOfRemoteNodeTlv.
25 + */
26 +public class IPv4TERouterIdOfRemoteNodeTlvTest {
27 +
28 + private final IPv4TERouterIdOfRemoteNodeTlv tlv1 = IPv4TERouterIdOfRemoteNodeTlv.of(2);
29 + private final IPv4TERouterIdOfRemoteNodeTlv sameAsTlv1 = IPv4TERouterIdOfRemoteNodeTlv.of(2);
30 + private final IPv4TERouterIdOfRemoteNodeTlv tlv2 = IPv4TERouterIdOfRemoteNodeTlv.of(3);
31 +
32 + @Test
33 + public void basics() {
34 + new EqualsTester()
35 + .addEqualityGroup(tlv1, sameAsTlv1)
36 + .addEqualityGroup(tlv2)
37 + .testEquals();
38 + }
39 +}
1 +/*
2 + * Copyright 2014 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +package org.onosproject.pcepio;
17 +
18 +import com.google.common.testing.EqualsTester;
19 +
20 +import org.junit.Test;
21 +import org.onosproject.pcepio.types.IPv6InterfaceAddressTlv;
22 +
23 +/**
24 + * Test of the IPv6InterfaceAddressTlv.
25 + */
26 +public class IPv6InterfaceAddressTlvTest {
27 +
28 + private byte[] b1 = new byte[] {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 };
29 + private byte[] b2 = new byte[] {2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 };
30 +
31 + private final IPv6InterfaceAddressTlv tlv1 = IPv6InterfaceAddressTlv.of(b1);
32 + private final IPv6InterfaceAddressTlv sameAsTlv1 = IPv6InterfaceAddressTlv.of(b1);
33 + private final IPv6InterfaceAddressTlv tlv2 = IPv6InterfaceAddressTlv.of(b2);
34 +
35 + @Test
36 + public void basics() {
37 + new EqualsTester()
38 + .addEqualityGroup(tlv1, sameAsTlv1)
39 + .addEqualityGroup(tlv2)
40 + .testEquals();
41 + }
42 +}
1 +/*
2 + * Copyright 2014 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +package org.onosproject.pcepio;
17 +
18 +import com.google.common.testing.EqualsTester;
19 +
20 +import org.junit.Test;
21 +import org.onosproject.pcepio.types.IPv6NeighborAddressTlv;
22 +
23 +/**
24 + * Test of the IPv6NeighborAddressTlv.
25 + */
26 +public class IPv6NeighborAddressTlvTest {
27 +
28 + private byte[] b1 = new byte[] {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 };
29 + private byte[] b2 = new byte[] {2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 };
30 +
31 + private final IPv6NeighborAddressTlv tlv1 = IPv6NeighborAddressTlv.of(b1);
32 + private final IPv6NeighborAddressTlv sameAsTlv1 = IPv6NeighborAddressTlv.of(b1);
33 + private final IPv6NeighborAddressTlv tlv2 = IPv6NeighborAddressTlv.of(b2);
34 +
35 + @Test
36 + public void basics() {
37 + new EqualsTester()
38 + .addEqualityGroup(tlv1, sameAsTlv1)
39 + .addEqualityGroup(tlv2)
40 + .testEquals();
41 + }
42 +}
1 +/*
2 + * Copyright 2014 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +package org.onosproject.pcepio;
17 +
18 +import com.google.common.testing.EqualsTester;
19 +
20 +import org.junit.Test;
21 +import org.onosproject.pcepio.types.IPv6TERouterIdofLocalNodeTlv;
22 +
23 +/**
24 + * Test of the IPv6TERouterIdofLocalNodeTlv.
25 + */
26 +public class IPv6TERouterIdofLocalNodeTlvTest {
27 +
28 + private byte[] b1 = new byte[] {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 };
29 + private byte[] b2 = new byte[] {2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 };
30 +
31 + private final IPv6TERouterIdofLocalNodeTlv tlv1 = IPv6TERouterIdofLocalNodeTlv.of(b1);
32 + private final IPv6TERouterIdofLocalNodeTlv sameAsTlv1 = IPv6TERouterIdofLocalNodeTlv.of(b1);
33 + private final IPv6TERouterIdofLocalNodeTlv tlv2 = IPv6TERouterIdofLocalNodeTlv.of(b2);
34 +
35 + @Test
36 + public void basics() {
37 + new EqualsTester()
38 + .addEqualityGroup(tlv1, sameAsTlv1)
39 + .addEqualityGroup(tlv2)
40 + .testEquals();
41 + }
42 +}
1 +/*
2 + * Copyright 2014 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +package org.onosproject.pcepio;
17 +
18 +import com.google.common.testing.EqualsTester;
19 +
20 +import org.junit.Test;
21 +import org.onosproject.pcepio.types.IPv6TERouterIdofRemoteNodeTlv;
22 +
23 +/**
24 + * Test of the IPv6TERouterIdofRemoteNodeTlv.
25 + */
26 +public class IPv6TERouterIdofRemoteNodeTlvTest {
27 +
28 + private byte[] b1 = new byte[] {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 };
29 + private byte[] b2 = new byte[] {2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 };
30 +
31 + private final IPv6TERouterIdofRemoteNodeTlv tlv1 = IPv6TERouterIdofRemoteNodeTlv.of(b1);
32 + private final IPv6TERouterIdofRemoteNodeTlv sameAsTlv1 = IPv6TERouterIdofRemoteNodeTlv.of(b1);
33 + private final IPv6TERouterIdofRemoteNodeTlv tlv2 = IPv6TERouterIdofRemoteNodeTlv.of(b2);
34 +
35 + @Test
36 + public void basics() {
37 + new EqualsTester()
38 + .addEqualityGroup(tlv1, sameAsTlv1)
39 + .addEqualityGroup(tlv2)
40 + .testEquals();
41 + }
42 +}
1 +/*
2 + * Copyright 2014 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +package org.onosproject.pcepio;
17 +
18 +import com.google.common.testing.EqualsTester;
19 +
20 +import org.junit.Test;
21 +import org.onosproject.pcepio.types.ISISAreaIdentifierTlv;
22 +
23 +/**
24 + * Test of the ISISAreaIdentifierTlv.
25 + */
26 +public class ISISAreaIdentifierTlvTest {
27 +
28 + private byte[] b1 = new byte[] {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 };
29 + private byte[] b2 = new byte[] {2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 };
30 +
31 + private final ISISAreaIdentifierTlv tlv1 = ISISAreaIdentifierTlv.of(b1, (short) 20);
32 + private final ISISAreaIdentifierTlv sameAsTlv1 = ISISAreaIdentifierTlv.of(b1, (short) 20);
33 + private final ISISAreaIdentifierTlv tlv2 = ISISAreaIdentifierTlv.of(b2, (short) 20);
34 +
35 + @Test
36 + public void basics() {
37 + new EqualsTester()
38 + .addEqualityGroup(tlv1, sameAsTlv1)
39 + .addEqualityGroup(tlv2)
40 + .testEquals();
41 + }
42 +}
1 +/*
2 + * Copyright 2014 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +package org.onosproject.pcepio;
17 +
18 +import com.google.common.testing.EqualsTester;
19 +
20 +import org.junit.Test;
21 +import org.onosproject.pcepio.types.LinkLocalRemoteIdentifiersTlv;
22 +
23 +/**
24 + * Test of the LinkLocalRemoteIdentifiersTlv.
25 + */
26 +public class LinkLocalRemoteIdentifiersTlvTest {
27 +
28 + private final LinkLocalRemoteIdentifiersTlv tlv1 = LinkLocalRemoteIdentifiersTlv.of(10, 20);
29 + private final LinkLocalRemoteIdentifiersTlv sameAsTlv1 = LinkLocalRemoteIdentifiersTlv.of(10, 20);
30 + private final LinkLocalRemoteIdentifiersTlv tlv2 = LinkLocalRemoteIdentifiersTlv.of(20, 30);
31 +
32 + @Test
33 + public void basics() {
34 + new EqualsTester()
35 + .addEqualityGroup(tlv1, sameAsTlv1)
36 + .addEqualityGroup(tlv2)
37 + .testEquals();
38 + }
39 +}
1 +/*
2 + * Copyright 2014 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +package org.onosproject.pcepio;
17 +
18 +import com.google.common.testing.EqualsTester;
19 +
20 +import org.junit.Test;
21 +import org.onosproject.pcepio.types.LinkNameTlv;
22 +
23 +/**
24 + * Test of the LinkNameTlv.
25 + */
26 +public class LinkNameTlvTest {
27 + private final byte[] rawValue1 = new byte[] {0x01, 0x00};
28 + private final byte[] rawValue2 = new byte[] {0x02, 0x00};
29 +
30 + private final LinkNameTlv tlv1 = new LinkNameTlv(rawValue1, (short) rawValue1.length);
31 + private final LinkNameTlv sameAsTlv1 = LinkNameTlv.of(tlv1.getValue(), tlv1.getLength());
32 + private final LinkNameTlv tlv2 = new LinkNameTlv(rawValue2, (short) 0);
33 + private final LinkNameTlv sameAsTlv2 = new LinkNameTlv(rawValue2, (short) rawValue2.length);
34 +
35 + @Test
36 + public void basics() {
37 + new EqualsTester()
38 + .addEqualityGroup(tlv1, sameAsTlv1)
39 + .addEqualityGroup(tlv2, sameAsTlv2)
40 + .testEquals();
41 + }
42 +}
1 +/* * Copyright 2014 Open Networking Laboratory * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */package org.onosproject.pcepio; import com.google.common.testing.EqualsTester; import org.junit.Test;import org.onosproject.pcepio.types.LinkProtectionTypeTlv; /** * Test of the LinkProtectionTypeTlv. */public class LinkProtectionTypeTlvTest { private final byte rawValue1 = 0x0A; private final byte rawValue2 = 0x0A; private final LinkProtectionTypeTlv tlv1 = new LinkProtectionTypeTlv(rawValue1); private final LinkProtectionTypeTlv tlv2 = new LinkProtectionTypeTlv(rawValue2, (byte) 0); @Test public void basics() { new EqualsTester() .addEqualityGroup(tlv1, tlv2) .testEquals(); }}
...\ No newline at end of file ...\ No newline at end of file
1 +/*
2 + * Copyright 2014 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +package org.onosproject.pcepio;
17 +
18 +import com.google.common.testing.EqualsTester;
19 +
20 +import org.junit.Test;
21 +import org.onosproject.pcepio.types.MPLSProtocolMaskTlv;
22 +
23 +/**
24 + * Test of the MPLSProtocolMaskTlv.
25 + */
26 +public class MPLSProtocolMaskTlvTest {
27 + private final byte rawValue1 = 0x0A;
28 + private final byte rawValue2 = 0x0A;
29 +
30 + private final MPLSProtocolMaskTlv tlv1 = new MPLSProtocolMaskTlv(rawValue1);
31 + private final MPLSProtocolMaskTlv tlv2 = MPLSProtocolMaskTlv.of(rawValue2);
32 +
33 + @Test
34 + public void basics() {
35 + new EqualsTester()
36 + .addEqualityGroup(tlv1, tlv2)
37 + .testEquals();
38 + }
39 +}
1 +/*
2 + * Copyright 2014 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +package org.onosproject.pcepio;
17 +
18 +import org.junit.Test;
19 +import org.onosproject.pcepio.types.MaximumLinkBandwidthTlv;
20 +
21 +import com.google.common.testing.EqualsTester;
22 +
23 +/**
24 + * Test of the MaximumLinkBandwidthTlv.
25 + */
26 +public class MaximumLinkBandwidthTlvTest {
27 + private final int rawValue1 = 0x0A;
28 + private final int rawValue2 = 0x0A;
29 +
30 + private final MaximumLinkBandwidthTlv tlv1 = new MaximumLinkBandwidthTlv(rawValue1);
31 + private final MaximumLinkBandwidthTlv tlv2 = MaximumLinkBandwidthTlv.of(rawValue2);
32 +
33 + @Test
34 + public void basics() {
35 + new EqualsTester()
36 + .addEqualityGroup(tlv1, tlv2)
37 + .testEquals();
38 + }
39 +}
1 +/*
2 + * Copyright 2014 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +package org.onosproject.pcepio;
17 +
18 +import org.junit.Test;
19 +import org.onosproject.pcepio.types.MaximumReservableLinkBandwidthTlv;
20 +
21 +import com.google.common.testing.EqualsTester;
22 +
23 +/**
24 + * Test of the MaximumReservableLinkBandwidthTlv.
25 + */
26 +public class MaximumReservableLinkBandwidthTlvTest {
27 + private final int rawValue1 = 0x0A;
28 + private final int rawValue2 = 0x0A;
29 +
30 + private final MaximumReservableLinkBandwidthTlv tlv1 = new MaximumReservableLinkBandwidthTlv(rawValue1);
31 + private final MaximumReservableLinkBandwidthTlv tlv2 = MaximumReservableLinkBandwidthTlv.of(rawValue2);
32 +
33 + @Test
34 + public void basics() {
35 + new EqualsTester()
36 + .addEqualityGroup(tlv1, tlv2)
37 + .testEquals();
38 + }
39 +}
1 +/*
2 + * Copyright 2014 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +package org.onosproject.pcepio;
17 +
18 +import com.google.common.testing.EqualsTester;
19 +
20 +import org.junit.Test;
21 +import org.onosproject.pcepio.types.NodeFlagBitsTlv;
22 +
23 +/**
24 + * Test of the NodeFlagBitsTlv.
25 + */
26 +public class NodeFlagBitsTlvTest {
27 + private final byte rawValue1 = 0x0A;
28 +
29 + private final NodeFlagBitsTlv tlv1 = new NodeFlagBitsTlv(rawValue1);
30 + private final NodeFlagBitsTlv tlv2 = NodeFlagBitsTlv.of(tlv1.getbyte());
31 +
32 + @Test
33 + public void basics() {
34 + new EqualsTester()
35 + .addEqualityGroup(tlv1, tlv2)
36 + .testEquals();
37 + }
38 +}
1 +/*
2 + * Copyright 2014 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +package org.onosproject.pcepio;
17 +
18 +import com.google.common.testing.EqualsTester;
19 +
20 +import org.junit.Test;
21 +import org.onosproject.pcepio.types.NodeNameTlv;
22 +
23 +/**
24 + * Test of the NodeNameTlv.
25 + */
26 +public class NodeNameTlvTest {
27 + private final byte[] rawValue1 = new byte[] {0x01, 0x02};
28 + private final byte[] rawValue2 = new byte[] {0x14, 0x15};
29 +
30 + private final NodeNameTlv tlv1 = new NodeNameTlv(rawValue1, (short) rawValue1.length);
31 + private final NodeNameTlv sameAsTlv1 = NodeNameTlv.of(tlv1.getValue(), tlv1.getLength());
32 + private final NodeNameTlv tlv2 = new NodeNameTlv(rawValue2, (short) 0);
33 + private final NodeNameTlv sameAsTlv2 = new NodeNameTlv(rawValue2, (short) rawValue2.length);
34 +
35 + @Test
36 + public void basics() {
37 + new EqualsTester()
38 + .addEqualityGroup(tlv1, sameAsTlv1)
39 + .addEqualityGroup(tlv2, sameAsTlv2)
40 + .testEquals();
41 + }
42 +}
1 +/*
2 + * Copyright 2014 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +package org.onosproject.pcepio;
17 +
18 +import com.google.common.testing.EqualsTester;
19 +
20 +import org.junit.Test;
21 +import org.onosproject.pcepio.types.OSPFareaIDsubTlv;
22 +
23 +/**
24 + * Test of the OSPFareaIDsubTlv.
25 + */
26 +public class OSPFareaIDsubTlvTest {
27 + private final int rawValue1 = 0x0A;
28 +
29 + private final OSPFareaIDsubTlv tlv1 = new OSPFareaIDsubTlv(rawValue1);
30 + private final OSPFareaIDsubTlv tlv2 = OSPFareaIDsubTlv.of(tlv1.getInt());
31 +
32 + @Test
33 + public void basics() {
34 + new EqualsTester()
35 + .addEqualityGroup(tlv1, tlv2)
36 + .testEquals();
37 + }
38 +}
1 +/*
2 + * Copyright 2014 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +package org.onosproject.pcepio;
17 +
18 +import com.google.common.testing.EqualsTester;
19 +
20 +import org.junit.Test;
21 +import org.onosproject.pcepio.types.OpaqueLinkAttributeTlv;
22 +
23 +/**
24 + * Test of the OpaqueLinkAttributeTlv.
25 + */
26 +public class OpaqueLinkAttributeTlvTest {
27 + private final byte[] rawValue1 = new byte[] {0x01, 0x02};
28 + private final byte[] rawValue2 = new byte[] {0x14, 0x15};
29 +
30 + private final OpaqueLinkAttributeTlv tlv1 = new OpaqueLinkAttributeTlv(rawValue1, (short) rawValue1.length);
31 + private final OpaqueLinkAttributeTlv sameAsTlv1 = OpaqueLinkAttributeTlv.of(tlv1.getValue(), tlv1.getLength());
32 + private final OpaqueLinkAttributeTlv tlv2 = new OpaqueLinkAttributeTlv(rawValue2, (short) 0);
33 + private final OpaqueLinkAttributeTlv sameAsTlv2 = new OpaqueLinkAttributeTlv(rawValue2, (short) rawValue2.length);
34 +
35 + @Test
36 + public void basics() {
37 + new EqualsTester()
38 + .addEqualityGroup(tlv1, sameAsTlv1)
39 + .addEqualityGroup(tlv2, sameAsTlv2)
40 + .testEquals();
41 + }
42 +}
1 +/*
2 + * Copyright 2014 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +package org.onosproject.pcepio;
17 +
18 +import com.google.common.testing.EqualsTester;
19 +
20 +import org.junit.Test;
21 +import org.onosproject.pcepio.types.PceccCapabilityTlv;
22 +
23 +/**
24 + * Test of the PceccCapabilityTlv.
25 + */
26 +public class PceccCapabilityTlvTest {
27 + private final int rawValue1 = 0x0A;
28 + private final int rawValue2 = 0x0A;
29 +
30 + private final PceccCapabilityTlv tlv1 = new PceccCapabilityTlv(rawValue1);
31 + private final PceccCapabilityTlv tlv2 = PceccCapabilityTlv.of(rawValue2);
32 +
33 + @Test
34 + public void basics() {
35 + new EqualsTester()
36 + .addEqualityGroup(tlv1, tlv2)
37 + .testEquals();
38 + }
39 +}
1 +/*
2 + * Copyright 2015 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +package org.onosproject.pcepio;
17 +
18 +import java.util.LinkedList;
19 +
20 +import org.junit.Test;
21 +import org.onosproject.pcepio.types.AutonomousSystemTlv;
22 +import org.onosproject.pcepio.types.BGPLSidentifierTlv;
23 +import org.onosproject.pcepio.types.PcepValueType;
24 +import org.onosproject.pcepio.types.RemoteTENodeDescriptorsTLV;
25 +
26 +import com.google.common.testing.EqualsTester;
27 +
28 +/**
29 + * Test case for Remote TE Node Descriptors tlv.
30 + */
31 +public class RemoteTENodeDescriptorsTLVTest {
32 +
33 + AutonomousSystemTlv autonomousSystemTlv1 = new AutonomousSystemTlv(10);
34 + BGPLSidentifierTlv bGPLSidentifierTlv1 = new BGPLSidentifierTlv(20);;
35 + LinkedList<PcepValueType> llRemoteTENodeDescriptorSubTLVs1 = new LinkedList<PcepValueType>();
36 + LinkedList<PcepValueType> llRemoteTENodeDescriptorSubTLVs2 = new LinkedList<PcepValueType>();
37 + LinkedList<PcepValueType> llRemoteTENodeDescriptorSubTLVs3 = new LinkedList<PcepValueType>();
38 +
39 + boolean b = llRemoteTENodeDescriptorSubTLVs1.add(autonomousSystemTlv1);
40 +
41 + boolean c = llRemoteTENodeDescriptorSubTLVs2.add(autonomousSystemTlv1);
42 + boolean d = llRemoteTENodeDescriptorSubTLVs3.add(bGPLSidentifierTlv1);
43 +
44 + final RemoteTENodeDescriptorsTLV tlv1 = RemoteTENodeDescriptorsTLV.of(llRemoteTENodeDescriptorSubTLVs1);
45 + final RemoteTENodeDescriptorsTLV tlv2 = RemoteTENodeDescriptorsTLV.of(llRemoteTENodeDescriptorSubTLVs2);
46 + final RemoteTENodeDescriptorsTLV tlv3 = RemoteTENodeDescriptorsTLV.of(llRemoteTENodeDescriptorSubTLVs3);
47 +
48 + @Test
49 + public void basics() {
50 + new EqualsTester().addEqualityGroup(tlv1, tlv2).addEqualityGroup(tlv3).testEquals();
51 + }
52 +
53 +}
1 +/*
2 + * Copyright 2015 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +package org.onosproject.pcepio;
17 +
18 +import org.junit.Test;
19 +import org.onosproject.pcepio.types.RouterIDSubTlv;
20 +
21 +import com.google.common.testing.EqualsTester;
22 +
23 +/**
24 + * Test case for Router ID Sub tlv.
25 + */
26 +public class RouterIDSubTlvTest {
27 +
28 + private byte[] value1 = {1, 2 };
29 + private Short length1 = new Short((short) 2);
30 + private final RouterIDSubTlv tlv1 = RouterIDSubTlv.of(value1, length1);
31 +
32 + private Short length2 = new Short((short) 2);
33 + private final RouterIDSubTlv tlv2 = RouterIDSubTlv.of(value1, length2);
34 +
35 + private byte[] value3 = {1, 2, 3 };
36 + private Short length3 = new Short((short) 3);
37 + private final RouterIDSubTlv tlv3 = RouterIDSubTlv.of(value3, length3);
38 +
39 + @Test
40 + public void basics() {
41 + new EqualsTester().addEqualityGroup(tlv1, tlv2).addEqualityGroup(tlv3).testEquals();
42 + }
43 +
44 +}
1 +/*
2 + * Copyright 2015 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +package org.onosproject.pcepio;
17 +
18 +import org.junit.Test;
19 +import org.onosproject.pcepio.types.SharedRiskLinkGroupTlv;
20 +
21 +import com.google.common.testing.EqualsTester;
22 +
23 +/**
24 + * Test case for Shared Risk Link Group tlv.
25 + */
26 +public class SharedRiskLinkGroupTlvTest {
27 +
28 + private int[] raw = {1 };
29 + private Short hLength = new Short((short) 2);
30 + private final SharedRiskLinkGroupTlv tlv1 = SharedRiskLinkGroupTlv.of(raw, hLength);
31 +
32 + private Short hLength1 = new Short((short) 2);
33 + private final SharedRiskLinkGroupTlv tlv2 = SharedRiskLinkGroupTlv.of(raw, hLength1);
34 +
35 + private int[] raw2 = {2 };
36 + private Short hLength2 = new Short((short) 3);
37 + private SharedRiskLinkGroupTlv tlv3 = SharedRiskLinkGroupTlv.of(raw2, hLength2);
38 +
39 + @Test
40 + public void basics() {
41 + new EqualsTester().addEqualityGroup(tlv1, tlv2).addEqualityGroup(tlv3).testEquals();
42 + }
43 +
44 +}
1 +/*
2 + * Copyright 2015 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +package org.onosproject.pcepio;
17 +
18 +import org.junit.Test;
19 +import org.onosproject.pcepio.types.StatefulLspDbVerTlv;
20 +
21 +import com.google.common.testing.EqualsTester;
22 +
23 +/**
24 + * Test case for Stateful Lsp Db Ver tlv.
25 + */
26 +public class StatefulLspDbVerTlvTest {
27 +
28 + private final StatefulLspDbVerTlv tlv1 = StatefulLspDbVerTlv.of(1);
29 + private final StatefulLspDbVerTlv tlv2 = StatefulLspDbVerTlv.of(1);
30 + private final StatefulLspDbVerTlv tlv3 = StatefulLspDbVerTlv.of(2);
31 +
32 + @Test
33 + public void basics() {
34 + new EqualsTester().addEqualityGroup(tlv1, tlv2).addEqualityGroup(tlv3).testEquals();
35 + }
36 +
37 +}
1 +/*
2 + * Copyright 2015 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +package org.onosproject.pcepio;
17 +
18 +import org.junit.Test;
19 +import org.onosproject.pcepio.types.StatefulPceCapabilityTlv;
20 +import com.google.common.testing.EqualsTester;
21 +
22 +/**
23 + * Test case for Stateful Pce Capability tlv.
24 + */
25 +public class StatefulPceCapabilityTlvTest {
26 +
27 + private final StatefulPceCapabilityTlv tlv1 = StatefulPceCapabilityTlv.of(1);
28 + private final StatefulPceCapabilityTlv tlv2 = StatefulPceCapabilityTlv.of(1);
29 + private final StatefulPceCapabilityTlv tlv3 = StatefulPceCapabilityTlv.of(2);
30 +
31 + @Test
32 + public void basics() {
33 + new EqualsTester().addEqualityGroup(tlv1, tlv2).addEqualityGroup(tlv3).testEquals();
34 + }
35 +}
1 +/*
2 + * Copyright 2015 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +package org.onosproject.pcepio;
17 +
18 +import org.junit.Test;
19 +import org.onosproject.pcepio.types.TEDefaultMetricTlv;
20 +
21 +import com.google.common.testing.EqualsTester;
22 +
23 +/**
24 + * Test case for TE Default Metric tlv.
25 + */
26 +public class TEDefaultMetricTlvTest {
27 +
28 + private final TEDefaultMetricTlv tlv1 = TEDefaultMetricTlv.of(1);
29 + private final TEDefaultMetricTlv tlv2 = TEDefaultMetricTlv.of(1);
30 + private final TEDefaultMetricTlv tlv3 = TEDefaultMetricTlv.of(2);
31 +
32 + @Test
33 + public void basics() {
34 + new EqualsTester().addEqualityGroup(tlv1, tlv2).addEqualityGroup(tlv3).testEquals();
35 + }
36 +}
...\ No newline at end of file ...\ No newline at end of file
1 +/*
2 + * Copyright 2015 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +package org.onosproject.pcepio;
17 +
18 +import java.util.LinkedList;
19 +
20 +import org.junit.Test;
21 +import org.onosproject.pcepio.types.AdministrativeGroupTlv;
22 +import org.onosproject.pcepio.types.MaximumReservableLinkBandwidthTlv;
23 +import org.onosproject.pcepio.types.PcepValueType;
24 +import org.onosproject.pcepio.types.TELinkAttributesTlv;
25 +
26 +import com.google.common.testing.EqualsTester;
27 +
28 +/**
29 + * Test case for TE Link Attribute Tlv.
30 + */
31 +public class TELinkAttributesTlvTest {
32 +
33 + AdministrativeGroupTlv administrativeGroupTlv1 = new AdministrativeGroupTlv(10);
34 + MaximumReservableLinkBandwidthTlv maximumReservableLinkBandwidthTlv1 = new MaximumReservableLinkBandwidthTlv(20);;
35 + LinkedList<PcepValueType> llLinkAttributesSubTLVs = new LinkedList<PcepValueType>();
36 + LinkedList<PcepValueType> llLinkAttributesSubTLVs2 = new LinkedList<PcepValueType>();
37 + LinkedList<PcepValueType> llLinkAttributesSubTLVs3 = new LinkedList<PcepValueType>();
38 +
39 + boolean b = llLinkAttributesSubTLVs.add(administrativeGroupTlv1);
40 +
41 + boolean c = llLinkAttributesSubTLVs2.add(administrativeGroupTlv1);
42 + boolean d = llLinkAttributesSubTLVs3.add(maximumReservableLinkBandwidthTlv1);
43 +
44 + final TELinkAttributesTlv tlv1 = TELinkAttributesTlv.of(llLinkAttributesSubTLVs);
45 + final TELinkAttributesTlv tlv2 = TELinkAttributesTlv.of(llLinkAttributesSubTLVs2);
46 + final TELinkAttributesTlv tlv3 = TELinkAttributesTlv.of(llLinkAttributesSubTLVs3);
47 +
48 + @Test
49 + public void basics() {
50 + new EqualsTester().addEqualityGroup(tlv1, tlv2).addEqualityGroup(tlv3).testEquals();
51 + }
52 +
53 +}
1 +/*
2 + * Copyright 2015 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +package org.onosproject.pcepio;
17 +
18 +import java.util.LinkedList;
19 +
20 +import org.junit.Test;
21 +import org.onosproject.pcepio.types.IPv4InterfaceAddressTlv;
22 +import org.onosproject.pcepio.types.LinkLocalRemoteIdentifiersTlv;
23 +import org.onosproject.pcepio.types.PcepValueType;
24 +import org.onosproject.pcepio.types.TELinkDescriptorsTLV;
25 +
26 +import com.google.common.testing.EqualsTester;
27 +
28 +/**
29 + * Test case for TE link descriptors Tlv.
30 + */
31 +public class TELinkDescriptorsTLVTest {
32 + LinkLocalRemoteIdentifiersTlv linkLocalRemoteIdentifiersTlv1 = new LinkLocalRemoteIdentifiersTlv(10, 10);
33 + IPv4InterfaceAddressTlv iPv4InterfaceAddressTlv1 = new IPv4InterfaceAddressTlv((int) 0x01010101);
34 + LinkedList<PcepValueType> llLinkDescriptorsSubTLVs1 = new LinkedList<PcepValueType>();
35 + LinkedList<PcepValueType> llLinkDescriptorsSubTLVs2 = new LinkedList<PcepValueType>();
36 + LinkedList<PcepValueType> llLinkDescriptorsSubTLVs3 = new LinkedList<PcepValueType>();
37 +
38 + boolean b = llLinkDescriptorsSubTLVs1.add(linkLocalRemoteIdentifiersTlv1);
39 + boolean c = llLinkDescriptorsSubTLVs2.add(linkLocalRemoteIdentifiersTlv1);
40 + boolean d = llLinkDescriptorsSubTLVs3.add(iPv4InterfaceAddressTlv1);
41 +
42 + final TELinkDescriptorsTLV tlv1 = TELinkDescriptorsTLV.of(llLinkDescriptorsSubTLVs1);
43 + final TELinkDescriptorsTLV tlv2 = TELinkDescriptorsTLV.of(llLinkDescriptorsSubTLVs2);
44 + final TELinkDescriptorsTLV tlv3 = TELinkDescriptorsTLV.of(llLinkDescriptorsSubTLVs3);
45 +
46 + @Test
47 + public void basics() {
48 + new EqualsTester().addEqualityGroup(tlv1, tlv2).addEqualityGroup(tlv3).testEquals();
49 + }
50 +
51 +}
1 +/*
2 + * Copyright 2015 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +package org.onosproject.pcepio;
17 +
18 +import java.util.LinkedList;
19 +
20 +import org.junit.Test;
21 +import org.onosproject.pcepio.types.IPv4TERouterIdOfLocalNodeTlv;
22 +import org.onosproject.pcepio.types.NodeFlagBitsTlv;
23 +import org.onosproject.pcepio.types.PcepValueType;
24 +import org.onosproject.pcepio.types.TENodeAttributesTlv;
25 +
26 +import com.google.common.testing.EqualsTester;
27 +
28 +/**
29 + * Test case for TE Node Attribute tlv.
30 + */
31 +public class TENodeAttributesTlvTest {
32 +
33 + NodeFlagBitsTlv nodeFlagBitsTlv1 = new NodeFlagBitsTlv((byte) 10);
34 + IPv4TERouterIdOfLocalNodeTlv iPv4TERouterIdOfLocalNodeTlv1 = new IPv4TERouterIdOfLocalNodeTlv((int) 0x01010101);;
35 + LinkedList<PcepValueType> llNodeAttributesSubTLVs1 = new LinkedList<PcepValueType>();
36 + LinkedList<PcepValueType> llNodeAttributesSubTLVs2 = new LinkedList<PcepValueType>();
37 + LinkedList<PcepValueType> llNodeAttributesSubTLVs3 = new LinkedList<PcepValueType>();
38 +
39 + boolean b = llNodeAttributesSubTLVs1.add(nodeFlagBitsTlv1);
40 +
41 + boolean c = llNodeAttributesSubTLVs2.add(nodeFlagBitsTlv1);
42 + boolean d = llNodeAttributesSubTLVs3.add(iPv4TERouterIdOfLocalNodeTlv1);
43 +
44 + final TENodeAttributesTlv tlv1 = TENodeAttributesTlv.of(llNodeAttributesSubTLVs1);
45 + final TENodeAttributesTlv tlv2 = TENodeAttributesTlv.of(llNodeAttributesSubTLVs2);
46 + final TENodeAttributesTlv tlv3 = TENodeAttributesTlv.of(llNodeAttributesSubTLVs3);
47 +
48 + @Test
49 + public void basics() {
50 + new EqualsTester().addEqualityGroup(tlv1, tlv2).addEqualityGroup(tlv3).testEquals();
51 + }
52 +
53 +}
1 +/*
2 + * Copyright 2015 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +package org.onosproject.pcepio;
17 +
18 +import org.junit.Test;
19 +import org.onosproject.pcepio.types.TedCapabilityTlv;
20 +
21 +import com.google.common.testing.EqualsTester;
22 +
23 +/**
24 + * Test case for TED Capability tlv.
25 + */
26 +public class TedCapabilityTlvTest {
27 +
28 + private final TedCapabilityTlv tlv1 = TedCapabilityTlv.of(1);
29 + private final TedCapabilityTlv tlv2 = TedCapabilityTlv.of(1);
30 + private final TedCapabilityTlv tlv3 = TedCapabilityTlv.of(2);
31 +
32 + @Test
33 + public void basics() {
34 + new EqualsTester().addEqualityGroup(tlv1, tlv2).addEqualityGroup(tlv3).testEquals();
35 + }
36 +}
1 +/*
2 + * Copyright 2015 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +package org.onosproject.pcepio;
17 +
18 +import org.junit.Test;
19 +import org.onosproject.pcepio.types.UnreservedBandwidthTlv;
20 +import com.google.common.testing.EqualsTester;
21 +
22 +/**
23 + * Unit Test case for Unreserved Bandwidth Tlv.
24 + */
25 +public class UnreservedBandwidthTlvTest {
26 +
27 + // Objects of unreserved bandwidth tlv
28 + private final UnreservedBandwidthTlv tlv1 = UnreservedBandwidthTlv.of(100);
29 + private final UnreservedBandwidthTlv tlv2 = UnreservedBandwidthTlv.of(100);
30 + private final UnreservedBandwidthTlv tlv3 = UnreservedBandwidthTlv.of(200);
31 +
32 + @Test
33 + public void basics() {
34 + new EqualsTester().addEqualityGroup(tlv1, tlv2).addEqualityGroup(tlv3).testEquals();
35 + }
36 +
37 +}