Mahesh Poojary S
Committed by Gerrit Code Review

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

Change-Id: Id4aa762caf1847a6b5e56517cb159608fd54eefb
Showing 83 changed files with 4960 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 +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 +
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 +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 +}