Bharat saraswal
Committed by Gerrit Code Review

[ONOS-2356] Implementation for PCEP label update message.

Change-Id: I510a9a7c7c868da1fc3d6e2625501f094faf8115
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.PcepFecObjectIPv4Adjacency;
22 +import org.onosproject.pcepio.protocol.PcepVersion;
23 +import org.onosproject.pcepio.types.PcepObjectHeader;
24 +import org.slf4j.Logger;
25 +import org.slf4j.LoggerFactory;
26 +
27 +import com.google.common.base.MoreObjects;
28 +
29 +public class PcepFecObjectIPv4AdjacencyVer1 implements PcepFecObjectIPv4Adjacency {
30 +
31 + /*
32 + * ref : draft-zhao-pce-pcep-extension-for-pce-controller-01 , section : 7.5
33 + *
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 + | Local IPv4 address |
38 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
39 + | Remote IPv4 address |
40 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
41 +
42 + FEC Object-Type is 3 IPv4 Adjacency
43 + */
44 + protected static final Logger log = LoggerFactory.getLogger(PcepFecObjectIPv4AdjacencyVer1.class);
45 +
46 + public static final byte FEC_OBJ_TYPE = 3;
47 + public static final byte FEC_OBJ_CLASS = 36; //to be defined
48 + public static final byte FEC_OBJECT_VERSION = 1;
49 + public static final short FEC_OBJ_MINIMUM_LENGTH = 12;
50 + public static final int MINIMUM_COMMON_HEADER_LENGTH = 4;
51 +
52 + static final PcepObjectHeader DEFAULT_FEC_OBJECT_HEADER = new PcepObjectHeader(FEC_OBJ_CLASS, FEC_OBJ_TYPE,
53 + PcepObjectHeader.REQ_OBJ_OPTIONAL_PROCESS, PcepObjectHeader.RSP_OBJ_PROCESSED, FEC_OBJ_MINIMUM_LENGTH);
54 +
55 + private PcepObjectHeader fecObjHeader;
56 + private int localIPv4Address;
57 + private int remoteIPv4Address;
58 +
59 + /**
60 + * Constructor to initialize parameters for PCEP fec object .
61 + *
62 + * @param fecObjHeader FEC Object header
63 + * @param localIPv4Address Local IPv4 Address
64 + * @param remoteIPv4Address Remote IPv4 Address
65 + */
66 + public PcepFecObjectIPv4AdjacencyVer1(PcepObjectHeader fecObjHeader, int localIPv4Address, int remoteIPv4Address) {
67 + this.fecObjHeader = fecObjHeader;
68 + this.localIPv4Address = localIPv4Address;
69 + this.remoteIPv4Address = remoteIPv4Address;
70 + }
71 +
72 + /**
73 + * Sets Object header.
74 + *
75 + * @param obj Pcep fec Object Header
76 + */
77 + public void setFecIpv4ObjHeader(PcepObjectHeader obj) {
78 + this.fecObjHeader = obj;
79 + }
80 +
81 + @Override
82 + public int getLocalIPv4Address() {
83 + return this.localIPv4Address;
84 + }
85 +
86 + @Override
87 + public void seLocalIPv4Address(int value) {
88 + this.localIPv4Address = value;
89 + }
90 +
91 + @Override
92 + public int getRemoteIPv4Address() {
93 + return this.remoteIPv4Address;
94 + }
95 +
96 + @Override
97 + public void seRemoteIPv4Address(int value) {
98 + this.remoteIPv4Address = value;
99 + }
100 +
101 + /**
102 + * Reads from channel buffer and Returns object of PcepFecObjectIPv4Adjacency.
103 + *
104 + * @param cb of channel buffer.
105 + * @return object of PcepFecObjectIPv4Adjacency
106 + * @throws PcepParseException when fails to read from channel buffer
107 + */
108 + public static PcepFecObjectIPv4Adjacency read(ChannelBuffer cb) throws PcepParseException {
109 +
110 + PcepObjectHeader fecObjHeader;
111 + int localIPv4Address;
112 + int remoteIPv4Address;
113 +
114 + fecObjHeader = PcepObjectHeader.read(cb);
115 +
116 + //take only FEC IPv4 Adjacency Object buffer.
117 + ChannelBuffer tempCb = cb.readBytes(fecObjHeader.getObjLen() - MINIMUM_COMMON_HEADER_LENGTH);
118 + localIPv4Address = tempCb.readInt();
119 + remoteIPv4Address = tempCb.readInt();
120 +
121 + return new PcepFecObjectIPv4AdjacencyVer1(fecObjHeader, localIPv4Address, remoteIPv4Address);
122 + }
123 +
124 + @Override
125 + public int write(ChannelBuffer cb) throws PcepParseException {
126 +
127 + int objStartIndex = cb.writerIndex();
128 +
129 + //Write common header
130 + int objLenIndex = fecObjHeader.write(cb);
131 + cb.writeInt(localIPv4Address);
132 + cb.writeInt(remoteIPv4Address);
133 +
134 + //Now write FEC IPv4 Adjacency Object Length
135 + cb.setShort(objLenIndex, (short) (cb.writerIndex() - objStartIndex));
136 + return cb.writerIndex();
137 + }
138 +
139 + /**
140 + * Builder class for PCEP fec object IPv4 Adjacency.
141 + */
142 + public static class Builder implements PcepFecObjectIPv4Adjacency.Builder {
143 + private boolean bIsHeaderSet = false;
144 + private boolean bIsLocalIPv4Addressset = false;
145 + private boolean bIsRemoteIPv4Addressset = false;
146 +
147 + private PcepObjectHeader fecObjHeader;
148 + int localIPv4Address;
149 + int remoteIPv4Address;
150 +
151 + private boolean bIsPFlagSet = false;
152 + private boolean bPFlag;
153 +
154 + private boolean bIsIFlagSet = false;
155 + private boolean bIFlag;
156 +
157 + @Override
158 + public PcepFecObjectIPv4Adjacency build() throws PcepParseException {
159 + PcepObjectHeader fecObjHeader = this.bIsHeaderSet ? this.fecObjHeader : DEFAULT_FEC_OBJECT_HEADER;
160 +
161 + if (!this.bIsLocalIPv4Addressset) {
162 + throw new PcepParseException(
163 + "Local IPv4 Address not set while building PcepFecObjectIPv4Adjacency object.");
164 + }
165 +
166 + if (!this.bIsRemoteIPv4Addressset) {
167 + throw new PcepParseException(
168 + " Remote IPv4 Address not set while building PcepFecObjectIPv4Adjacency object.");
169 + }
170 +
171 + if (bIsPFlagSet) {
172 + fecObjHeader.setPFlag(bPFlag);
173 + }
174 +
175 + if (bIsIFlagSet) {
176 + fecObjHeader.setIFlag(bIFlag);
177 + }
178 + return new PcepFecObjectIPv4AdjacencyVer1(fecObjHeader, this.localIPv4Address, this.remoteIPv4Address);
179 + }
180 +
181 + @Override
182 + public Builder setPFlag(boolean value) {
183 + this.bPFlag = value;
184 + this.bIsPFlagSet = true;
185 + return this;
186 + }
187 +
188 + @Override
189 + public Builder setIFlag(boolean value) {
190 + this.bIFlag = value;
191 + this.bIsIFlagSet = true;
192 + return this;
193 + }
194 +
195 + @Override
196 + public PcepObjectHeader getFecIpv4AdjacencyObjHeader() {
197 + return this.fecObjHeader;
198 + }
199 +
200 + @Override
201 + public Builder setFecIpv4AdjacencyObjHeader(PcepObjectHeader obj) {
202 + this.fecObjHeader = obj;
203 + this.bIsHeaderSet = true;
204 + return this;
205 + }
206 +
207 + @Override
208 + public int getLocalIPv4Address() {
209 + return this.localIPv4Address;
210 + }
211 +
212 + @Override
213 + public Builder seLocalIPv4Address(int value) {
214 + this.localIPv4Address = value;
215 + this.bIsLocalIPv4Addressset = true;
216 + return this;
217 + }
218 +
219 + @Override
220 + public int getRemoteIPv4Address() {
221 + return this.remoteIPv4Address;
222 + }
223 +
224 + @Override
225 + public Builder seRemoteIPv4Address(int value) {
226 + this.remoteIPv4Address = value;
227 + this.bIsRemoteIPv4Addressset = true;
228 + return this;
229 + }
230 +
231 + }
232 +
233 + @Override
234 + public PcepVersion getVersion() {
235 + return PcepVersion.PCEP_1;
236 + }
237 +
238 + @Override
239 + public int getType() {
240 + return FEC_OBJ_TYPE;
241 + }
242 +
243 + @Override
244 + public String toString() {
245 + return MoreObjects.toStringHelper(getClass()).add("fecObjHeader", fecObjHeader)
246 + .add("localIPv4Address", localIPv4Address).add("remoteIPv4Address", remoteIPv4Address).toString();
247 + }
248 +}
1 +/*
2 + * Copyright 2015 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +
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.PcepFecObjectIPv4UnnumberedAdjacency;
22 +import org.onosproject.pcepio.protocol.PcepVersion;
23 +import org.onosproject.pcepio.types.PcepObjectHeader;
24 +import org.slf4j.Logger;
25 +import org.slf4j.LoggerFactory;
26 +
27 +import com.google.common.base.MoreObjects;
28 +
29 +public class PcepFecObjectIPv4UnnumberedAdjacencyVer1 implements PcepFecObjectIPv4UnnumberedAdjacency {
30 +
31 + /*
32 + * ref : draft-zhao-pce-pcep-extension-for-pce-controller-01 , section : 7.5
33 + *
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 + | Local Node-ID |
38 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
39 + | Local Interface ID |
40 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
41 + | Remote Node-ID |
42 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
43 + | Remote Interface ID |
44 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
45 +
46 + FEC Object-Type is 5, Unnumbered Adjacency with IPv4 NodeIDs
47 + */
48 + protected static final Logger log = LoggerFactory.getLogger(PcepFecObjectIPv4UnnumberedAdjacencyVer1.class);
49 +
50 + public static final byte FEC_OBJ_TYPE = 5;
51 + public static final byte FEC_OBJ_CLASS = 63; //to be defined
52 + public static final byte FEC_OBJECT_VERSION = 1;
53 + public static final short FEC_OBJ_MINIMUM_LENGTH = 20;
54 + public static final int MINIMUM_COMMON_HEADER_LENGTH = 4;
55 +
56 + static final PcepObjectHeader DEFAULT_FEC_OBJECT_HEADER = new PcepObjectHeader(FEC_OBJ_CLASS, FEC_OBJ_TYPE,
57 + PcepObjectHeader.REQ_OBJ_OPTIONAL_PROCESS, PcepObjectHeader.RSP_OBJ_PROCESSED, FEC_OBJ_MINIMUM_LENGTH);
58 +
59 + private PcepObjectHeader fecObjHeader;
60 + private int localNodeID;
61 + private int localInterfaceID;
62 + private int remoteNodeID;
63 + private int remoteInterfaceID;
64 +
65 + /**
66 + * Constructor to initialize parameter for PCEP fec object.
67 + *
68 + * @param fecObjHeader fec object header
69 + * @param localNodeID local node ID
70 + * @param localInterfaceID local interface ID
71 + * @param remoteNodeID remote node ID
72 + * @param remoteInterfaceID remote interface ID
73 + */
74 + public PcepFecObjectIPv4UnnumberedAdjacencyVer1(PcepObjectHeader fecObjHeader, int localNodeID,
75 + int localInterfaceID, int remoteNodeID, int remoteInterfaceID) {
76 + this.fecObjHeader = fecObjHeader;
77 + this.localNodeID = localNodeID;
78 + this.localInterfaceID = localInterfaceID;
79 + this.remoteNodeID = remoteNodeID;
80 + this.remoteInterfaceID = remoteInterfaceID;
81 + }
82 +
83 + /**
84 + * Sets Object Header.
85 + *
86 + * @param obj object header
87 + */
88 + public void setFecIpv4UnnumberedAdjacencyObjHeader(PcepObjectHeader obj) {
89 + this.fecObjHeader = obj;
90 + }
91 +
92 + @Override
93 + public void setLocalNodeID(int localNodeID) {
94 + this.localNodeID = localNodeID;
95 + }
96 +
97 + /**
98 + * Returns Object Header.
99 + *
100 + * @return fecObjHeader fec object header
101 + */
102 + public PcepObjectHeader getFecIpv4UnnumberedAdjacencyObjHeader() {
103 + return this.fecObjHeader;
104 + }
105 +
106 + @Override
107 + public int getLocalNodeID() {
108 + return this.localNodeID;
109 + }
110 +
111 + @Override
112 + public int getLocalInterfaceID() {
113 + return this.localInterfaceID;
114 + }
115 +
116 + @Override
117 + public void setLocalInterfaceID(int localInterfaceID) {
118 + this.localInterfaceID = localInterfaceID;
119 + }
120 +
121 + @Override
122 + public int getRemoteNodeID() {
123 + return this.remoteNodeID;
124 + }
125 +
126 + @Override
127 + public void setRemoteNodeID(int remoteNodeID) {
128 + this.remoteNodeID = remoteNodeID;
129 + }
130 +
131 + @Override
132 + public int getRemoteInterfaceID() {
133 + return this.remoteInterfaceID;
134 + }
135 +
136 + @Override
137 + public void setRemoteInterfaceID(int remoteInterfaceID) {
138 + this.remoteInterfaceID = remoteInterfaceID;
139 + }
140 +
141 + /**
142 + * Reads from channel buffer and returns object of PcepFecObjectIPv4UnnumberedAdjacency.
143 + *
144 + * @param cb of channel buffer
145 + * @return object of PcepFecObjectIPv4UnnumberedAdjacency
146 + * @throws PcepParseException when fails to read from channel buffer
147 + */
148 + public static PcepFecObjectIPv4UnnumberedAdjacency read(ChannelBuffer cb) throws PcepParseException {
149 +
150 + PcepObjectHeader fecObjHeader;
151 + int localNodeID;
152 + int localInterfaceID;
153 + int remoteNodeID;
154 + int remoteInterfaceID;
155 +
156 + fecObjHeader = PcepObjectHeader.read(cb);
157 +
158 + //take only FEC IPv4 Unnumbered Adjacency Object buffer.
159 + ChannelBuffer tempCb = cb.readBytes(fecObjHeader.getObjLen() - MINIMUM_COMMON_HEADER_LENGTH);
160 + localNodeID = tempCb.readInt();
161 + localInterfaceID = tempCb.readInt();
162 + remoteNodeID = tempCb.readInt();
163 + remoteInterfaceID = tempCb.readInt();
164 +
165 + return new PcepFecObjectIPv4UnnumberedAdjacencyVer1(fecObjHeader, localNodeID, localInterfaceID, remoteNodeID,
166 + remoteInterfaceID);
167 + }
168 +
169 + @Override
170 + public int write(ChannelBuffer cb) throws PcepParseException {
171 +
172 + int objStartIndex = cb.writerIndex();
173 +
174 + //Write common header
175 + int objLenIndex = fecObjHeader.write(cb);
176 + cb.writeInt(localNodeID);
177 + cb.writeInt(localInterfaceID);
178 + cb.writeInt(remoteNodeID);
179 + cb.writeInt(remoteInterfaceID);
180 +
181 + //Now write FEC IPv4 Unnumbered Adjacency Object Length
182 + cb.setShort(objLenIndex, (short) (cb.writerIndex() - objStartIndex));
183 +
184 + return cb.writerIndex();
185 + }
186 +
187 + /**
188 + * Builder class for PCEP Fec object IPv4 unnumbered Adjacency.
189 + */
190 + public static class Builder implements PcepFecObjectIPv4UnnumberedAdjacency.Builder {
191 + private boolean bIsHeaderSet = false;
192 + private boolean bIsLocalNodeIDset = false;
193 + private boolean bIsLocalInterfaceIDset = false;
194 + private boolean bIsRemoteNodeIDset = false;
195 + private boolean bIsRemoteInterfaceIDset = false;
196 +
197 + private PcepObjectHeader fecObjHeader;
198 + private int localNodeID;
199 + private int localInterfaceID;
200 + private int remoteNodeID;
201 + private int remoteInterfaceID;
202 +
203 + private boolean bIsPFlagSet = false;
204 + private boolean bPFlag;
205 +
206 + private boolean bIsIFlagSet = false;
207 + private boolean bIFlag;
208 +
209 + @Override
210 + public PcepFecObjectIPv4UnnumberedAdjacency build() throws PcepParseException {
211 + PcepObjectHeader fecObjHeader = this.bIsHeaderSet ? this.fecObjHeader : DEFAULT_FEC_OBJECT_HEADER;
212 +
213 + if (!this.bIsLocalNodeIDset) {
214 + throw new PcepParseException(
215 + " Local Node ID not set while building PcepFecObjectIPv4UnnumberedAdjacency object.");
216 + }
217 + if (!this.bIsLocalInterfaceIDset) {
218 + throw new PcepParseException(
219 + " Local Interface ID not set while building PcepFecObjectIPv4UnnumberedAdjacency object.");
220 + }
221 + if (!this.bIsRemoteNodeIDset) {
222 + throw new PcepParseException(
223 + " Remote Node ID not set while building PcepFecObjectIPv4UnnumberedAdjacency object.");
224 + }
225 + if (!this.bIsRemoteInterfaceIDset) {
226 + throw new PcepParseException(
227 + " Remote Interface ID not set while building PcepFecObjectIPv4UnnumberedAdjacency object.");
228 + }
229 + if (bIsPFlagSet) {
230 + fecObjHeader.setPFlag(bPFlag);
231 + }
232 + if (bIsIFlagSet) {
233 + fecObjHeader.setIFlag(bIFlag);
234 + }
235 + return new PcepFecObjectIPv4UnnumberedAdjacencyVer1(fecObjHeader, this.localNodeID, this.localInterfaceID,
236 + this.remoteNodeID, this.remoteInterfaceID);
237 + }
238 +
239 + @Override
240 + public Builder setPFlag(boolean value) {
241 + this.bPFlag = value;
242 + this.bIsPFlagSet = true;
243 + return this;
244 + }
245 +
246 + @Override
247 + public Builder setIFlag(boolean value) {
248 + this.bIFlag = value;
249 + this.bIsIFlagSet = true;
250 + return this;
251 + }
252 +
253 + @Override
254 + public PcepObjectHeader getFecIpv4UnnumberedAdjacencyObjHeader() {
255 + return this.fecObjHeader;
256 + }
257 +
258 + @Override
259 + public Builder setFecIpv4UnnumberedAdjacencyObjHeader(PcepObjectHeader obj) {
260 + this.fecObjHeader = obj;
261 + this.bIsHeaderSet = true;
262 + return this;
263 + }
264 +
265 + @Override
266 + public int getLocalNodeID() {
267 + return this.localNodeID;
268 + }
269 +
270 + @Override
271 + public Builder setLocalNodeID(int value) {
272 + this.localNodeID = value;
273 + this.bIsLocalNodeIDset = true;
274 + return this;
275 + }
276 +
277 + @Override
278 + public int getLocalInterfaceID() {
279 + return this.localInterfaceID;
280 + }
281 +
282 + @Override
283 + public Builder setLocalInterfaceID(int value) {
284 + this.localInterfaceID = value;
285 + this.bIsLocalInterfaceIDset = true;
286 + return this;
287 + }
288 +
289 + @Override
290 + public int getRemoteNodeID() {
291 + return this.remoteNodeID;
292 + }
293 +
294 + @Override
295 + public Builder setRemoteNodeID(int value) {
296 + this.remoteNodeID = value;
297 + this.bIsRemoteNodeIDset = true;
298 + return this;
299 + }
300 +
301 + @Override
302 + public int getRemoteInterfaceID() {
303 + return this.remoteInterfaceID;
304 + }
305 +
306 + @Override
307 + public Builder setRemoteInterfaceID(int value) {
308 + this.remoteInterfaceID = value;
309 + this.bIsRemoteInterfaceIDset = true;
310 + return this;
311 + }
312 + }
313 +
314 + @Override
315 + public PcepVersion getVersion() {
316 + return PcepVersion.PCEP_1;
317 + }
318 +
319 + @Override
320 + public int getType() {
321 + return FEC_OBJ_TYPE;
322 + }
323 +
324 + @Override
325 + public String toString() {
326 + return MoreObjects.toStringHelper(getClass()).add("LocalNodeID: ", localNodeID)
327 + .add("LocalInterfaceID: ", localInterfaceID).add("RemoteNodeID: ", remoteNodeID)
328 + .add("RemoteInterfaceID: ", remoteInterfaceID).toString();
329 + }
330 +}
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.PcepFecObjectIPv4;
22 +import org.onosproject.pcepio.protocol.PcepVersion;
23 +import org.onosproject.pcepio.types.PcepObjectHeader;
24 +import org.slf4j.Logger;
25 +import org.slf4j.LoggerFactory;
26 +
27 +import com.google.common.base.MoreObjects;
28 +
29 +public class PcepFecObjectIPv4Ver1 implements PcepFecObjectIPv4 {
30 +
31 + /*
32 + * ref : draft-zhao-pce-pcep-extension-for-pce-controller-01 , section : 7.5
33 + *
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 + | IPv4 Node ID |
38 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
39 +
40 + FEC Object-Type is 1 IPv4 Node ID
41 + */
42 + protected static final Logger log = LoggerFactory.getLogger(PcepFecObjectIPv4Ver1.class);
43 +
44 + public static final byte FEC_OBJ_TYPE = 1;
45 + public static final byte FEC_OBJ_CLASS = 63; //to be defined
46 + public static final byte FEC_OBJECT_VERSION = 1;
47 + public static final short FEC_OBJ_MINIMUM_LENGTH = 8;
48 + public static final int MINIMUM_COMMON_HEADER_LENGTH = 4;
49 +
50 + static final PcepObjectHeader DEFAULT_FEC_OBJECT_HEADER = new PcepObjectHeader(FEC_OBJ_CLASS, FEC_OBJ_TYPE,
51 + PcepObjectHeader.REQ_OBJ_OPTIONAL_PROCESS, PcepObjectHeader.RSP_OBJ_PROCESSED, FEC_OBJ_MINIMUM_LENGTH);
52 +
53 + private PcepObjectHeader fecObjHeader;
54 + private int nodeID;
55 +
56 + /**
57 + * Constructor to initialize parameters for PCEP fec object.
58 + *
59 + * @param fecObjHeader fec object header
60 + * @param nodeID node id
61 + */
62 + public PcepFecObjectIPv4Ver1(PcepObjectHeader fecObjHeader, int nodeID) {
63 + this.fecObjHeader = fecObjHeader;
64 + this.nodeID = nodeID;
65 + }
66 +
67 + /**
68 + * Sets the Object Header.
69 + *
70 + * @param obj object header
71 + */
72 + public void setFecIpv4ObjHeader(PcepObjectHeader obj) {
73 + this.fecObjHeader = obj;
74 + }
75 +
76 + @Override
77 + public void setNodeID(int nodeID) {
78 + this.nodeID = nodeID;
79 + }
80 +
81 + /**
82 + * Returns Object Header.
83 + *
84 + * @return fecObjHeader fec object header
85 + */
86 + public PcepObjectHeader getFecIpv4ObjHeader() {
87 + return this.fecObjHeader;
88 + }
89 +
90 + @Override
91 + public int getNodeID() {
92 + return this.nodeID;
93 + }
94 +
95 + /**
96 + * Reads from channel buffer and returns object of PcepFecObjectIPv4.
97 + *
98 + * @param cb of channel buffer
99 + * @return object of PcepFecObjectIPv4
100 + * @throws PcepParseException when fails to read from channel buffer
101 + */
102 + public static PcepFecObjectIPv4 read(ChannelBuffer cb) throws PcepParseException {
103 +
104 + PcepObjectHeader fecObjHeader;
105 + int nodeID;
106 + fecObjHeader = PcepObjectHeader.read(cb);
107 + nodeID = cb.readInt();
108 + return new PcepFecObjectIPv4Ver1(fecObjHeader, nodeID);
109 + }
110 +
111 + @Override
112 + public int write(ChannelBuffer cb) throws PcepParseException {
113 +
114 + int objStartIndex = cb.writerIndex();
115 +
116 + //write common header
117 + int objLenIndex = fecObjHeader.write(cb);
118 + cb.writeInt(nodeID);
119 +
120 + //now write FEC IPv4 Object Length
121 + cb.setShort(objLenIndex, (short) (cb.writerIndex() - objStartIndex));
122 + return cb.writerIndex();
123 + }
124 +
125 + /**
126 + * Builder class for PCEP fec pobject IPv4.
127 + */
128 + public static class Builder implements PcepFecObjectIPv4.Builder {
129 + private boolean bIsHeaderSet = false;
130 + private boolean bIsNodeIdset = false;
131 +
132 + private PcepObjectHeader fecObjHeader;
133 + private int nodeID;
134 +
135 + private boolean bIsPFlagSet = false;
136 + private boolean bPFlag;
137 +
138 + private boolean bIsIFlagSet = false;
139 + private boolean bIFlag;
140 +
141 + @Override
142 + public PcepFecObjectIPv4 build() throws PcepParseException {
143 + PcepObjectHeader fecObjHeader = this.bIsHeaderSet ? this.fecObjHeader : DEFAULT_FEC_OBJECT_HEADER;
144 +
145 + if (!this.bIsNodeIdset) {
146 + throw new PcepParseException("NodeID not set while building PcepFecObjectIPv4 object.");
147 + }
148 + if (bIsPFlagSet) {
149 + fecObjHeader.setPFlag(bPFlag);
150 + }
151 + if (bIsIFlagSet) {
152 + fecObjHeader.setIFlag(bIFlag);
153 + }
154 + return new PcepFecObjectIPv4Ver1(fecObjHeader, this.nodeID);
155 + }
156 +
157 + @Override
158 + public Builder setPFlag(boolean value) {
159 + this.bPFlag = value;
160 + this.bIsPFlagSet = true;
161 + return this;
162 + }
163 +
164 + @Override
165 + public Builder setIFlag(boolean value) {
166 + this.bIFlag = value;
167 + this.bIsIFlagSet = true;
168 + return this;
169 + }
170 +
171 + @Override
172 + public PcepObjectHeader getFecIpv4ObjHeader() {
173 + return this.fecObjHeader;
174 + }
175 +
176 + @Override
177 + public Builder setFecIpv4ObjHeader(PcepObjectHeader obj) {
178 + this.fecObjHeader = obj;
179 + this.bIsHeaderSet = true;
180 + return this;
181 + }
182 +
183 + @Override
184 + public int getNodeID() {
185 + return this.nodeID;
186 + }
187 +
188 + @Override
189 + public Builder setNodeID(int value) {
190 + this.nodeID = value;
191 + this.bIsNodeIdset = true;
192 + return this;
193 + }
194 +
195 + }
196 +
197 + @Override
198 + public PcepVersion getVersion() {
199 + return PcepVersion.PCEP_1;
200 + }
201 +
202 + @Override
203 + public int getType() {
204 + return FEC_OBJ_TYPE;
205 + }
206 +
207 + @Override
208 + public String toString() {
209 + return MoreObjects.toStringHelper(getClass()).add("fecObjHeader", fecObjHeader).add("nodeID: ", nodeID)
210 + .toString();
211 + }
212 +}
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.PcepFecObjectIPv6Adjacency;
22 +import org.onosproject.pcepio.protocol.PcepVersion;
23 +import org.onosproject.pcepio.types.PcepObjectHeader;
24 +import org.slf4j.Logger;
25 +import org.slf4j.LoggerFactory;
26 +
27 +import com.google.common.base.MoreObjects;
28 +
29 +public class PcepFecObjectIPv6AdjacencyVer1 implements PcepFecObjectIPv6Adjacency {
30 +
31 + /*
32 + * ref : draft-zhao-pce-pcep-extension-for-pce-controller-01 , section : 7.5
33 + *
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 + | |
38 + // Local IPv6 address (16 bytes) //
39 + | |
40 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
41 + | |
42 + // Remote IPv6 address (16 bytes) //
43 + | |
44 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
45 +
46 + FEC Object-Type is 4 IPv6 Adjacency
47 + */
48 + protected static final Logger log = LoggerFactory.getLogger(PcepFecObjectIPv6AdjacencyVer1.class);
49 +
50 + public static final byte FEC_OBJ_TYPE = 4;
51 + public static final byte FEC_OBJ_CLASS = 63; //to be defined
52 + public static final byte FEC_OBJECT_VERSION = 1;
53 + public static final short FEC_OBJ_MINIMUM_LENGTH = 36;
54 + public static final int MINIMUM_COMMON_HEADER_LENGTH = 4;
55 + public static final int IPV6_ADDRESS_LENGTH = 16;
56 +
57 + static final PcepObjectHeader DEFAULT_FEC_OBJECT_HEADER = new PcepObjectHeader(FEC_OBJ_CLASS, FEC_OBJ_TYPE,
58 + PcepObjectHeader.REQ_OBJ_OPTIONAL_PROCESS, PcepObjectHeader.RSP_OBJ_PROCESSED, FEC_OBJ_MINIMUM_LENGTH);
59 +
60 + private PcepObjectHeader fecObjHeader;
61 + private byte[] localIPv6Address = new byte[IPV6_ADDRESS_LENGTH];
62 + private byte[] remoteIPv6Address = new byte[IPV6_ADDRESS_LENGTH];
63 +
64 + /**
65 + * Constructor to initialize parameters for PCEP fec object.
66 + *
67 + * @param fecObjHeader fec object header
68 + * @param localIPv6Address local IPv6 address
69 + * @param remoteIPv6Address remote IPv6 address
70 + */
71 + public PcepFecObjectIPv6AdjacencyVer1(PcepObjectHeader fecObjHeader, byte[] localIPv6Address,
72 + byte[] remoteIPv6Address) {
73 + this.fecObjHeader = fecObjHeader;
74 + this.localIPv6Address = localIPv6Address;
75 + this.remoteIPv6Address = remoteIPv6Address;
76 + }
77 +
78 + /**
79 + * Sets Object Header.
80 + *
81 + * @param obj object header
82 + */
83 + public void setFecIpv4ObjHeader(PcepObjectHeader obj) {
84 + this.fecObjHeader = obj;
85 + }
86 +
87 + @Override
88 + public byte[] getLocalIPv6Address() {
89 + return this.localIPv6Address;
90 + }
91 +
92 + @Override
93 + public void seLocalIPv6Address(byte[] value) {
94 + this.localIPv6Address = value;
95 + }
96 +
97 + @Override
98 + public byte[] getRemoteIPv6Address() {
99 + return this.remoteIPv6Address;
100 + }
101 +
102 + @Override
103 + public void seRemoteIPv6Address(byte[] value) {
104 + this.remoteIPv6Address = value;
105 + }
106 +
107 + /**
108 + * Reads channel buffer and Returns object of PcepFecObjectIPv6Adjacency.
109 + *
110 + * @param cb of channel buffer
111 + * @return object of PcepFecObjectIPv6Adjacency
112 + * @throws PcepParseException when fails tp read from channel buffer
113 + */
114 + public static PcepFecObjectIPv6Adjacency read(ChannelBuffer cb) throws PcepParseException {
115 +
116 + PcepObjectHeader fecObjHeader;
117 + byte[] localIPv6Address = new byte[IPV6_ADDRESS_LENGTH];
118 + byte[] remoteIPv6Address = new byte[IPV6_ADDRESS_LENGTH];
119 + fecObjHeader = PcepObjectHeader.read(cb);
120 + cb.readBytes(localIPv6Address, 0, IPV6_ADDRESS_LENGTH);
121 + cb.readBytes(remoteIPv6Address, 0, IPV6_ADDRESS_LENGTH);
122 + return new PcepFecObjectIPv6AdjacencyVer1(fecObjHeader, localIPv6Address, remoteIPv6Address);
123 + }
124 +
125 + @Override
126 + public int write(ChannelBuffer cb) throws PcepParseException {
127 +
128 + int objStartIndex = cb.writerIndex();
129 +
130 + //write common header
131 + int objLenIndex = fecObjHeader.write(cb);
132 + cb.writeBytes(localIPv6Address);
133 + cb.writeBytes(remoteIPv6Address);
134 + //now write FEC IPv6 Adjacency Object Length
135 + cb.setShort(objLenIndex, (short) (cb.writerIndex() - objStartIndex));
136 + return cb.writerIndex();
137 + }
138 +
139 + /**
140 + * Builder class for PCEP fec object IPv6 Adjacency.
141 + */
142 + public static class Builder implements PcepFecObjectIPv6Adjacency.Builder {
143 + private boolean bIsHeaderSet = false;
144 + private boolean bIsLocalIPv6Addressset = false;
145 + private boolean bIsRemoteIPv6Addressset = false;
146 +
147 + private PcepObjectHeader fecObjHeader;
148 + byte[] localIPv6Address = new byte[IPV6_ADDRESS_LENGTH];
149 + byte[] remoteIPv6Address = new byte[IPV6_ADDRESS_LENGTH];
150 +
151 + private boolean bIsPFlagSet = false;
152 + private boolean bPFlag;
153 +
154 + private boolean bIsIFlagSet = false;
155 + private boolean bIFlag;
156 +
157 + @Override
158 + public PcepFecObjectIPv6Adjacency build() throws PcepParseException {
159 + PcepObjectHeader fecObjHeader = this.bIsHeaderSet ? this.fecObjHeader : DEFAULT_FEC_OBJECT_HEADER;
160 +
161 + if (!this.bIsLocalIPv6Addressset) {
162 + throw new PcepParseException(
163 + "Local IPv6 Address not set while building PcepFecObjectIPv6Adjacency object.");
164 + }
165 + if (!this.bIsRemoteIPv6Addressset) {
166 + throw new PcepParseException(
167 + "Remote IPv6 Address not set while building PcepFecObjectIPv6Adjacency object.");
168 + }
169 + if (bIsPFlagSet) {
170 + fecObjHeader.setPFlag(bPFlag);
171 + }
172 + if (bIsIFlagSet) {
173 + fecObjHeader.setIFlag(bIFlag);
174 + }
175 + return new PcepFecObjectIPv6AdjacencyVer1(fecObjHeader, this.localIPv6Address, this.remoteIPv6Address);
176 + }
177 +
178 + @Override
179 + public Builder setPFlag(boolean value) {
180 + this.bPFlag = value;
181 + this.bIsPFlagSet = true;
182 + return this;
183 + }
184 +
185 + @Override
186 + public Builder setIFlag(boolean value) {
187 + this.bIFlag = value;
188 + this.bIsIFlagSet = true;
189 + return this;
190 + }
191 +
192 + @Override
193 + public PcepObjectHeader getFecIpv6AdjacencyObjHeader() {
194 + return this.fecObjHeader;
195 + }
196 +
197 + @Override
198 + public Builder setFecIpv6AdjacencyObjHeader(PcepObjectHeader obj) {
199 + this.fecObjHeader = obj;
200 + this.bIsHeaderSet = true;
201 + return this;
202 + }
203 +
204 + @Override
205 + public byte[] getLocalIPv6Address() {
206 + return this.localIPv6Address;
207 + }
208 +
209 + @Override
210 + public Builder setLocalIPv6Address(byte[] value) {
211 + this.localIPv6Address = value;
212 + this.bIsLocalIPv6Addressset = true;
213 + return this;
214 + }
215 +
216 + @Override
217 + public byte[] getRemoteIPv6Address() {
218 + return this.remoteIPv6Address;
219 + }
220 +
221 + @Override
222 + public Builder setRemoteIPv6Address(byte[] value) {
223 + this.remoteIPv6Address = value;
224 + this.bIsRemoteIPv6Addressset = true;
225 + return this;
226 + }
227 + }
228 +
229 + @Override
230 + public PcepVersion getVersion() {
231 + return PcepVersion.PCEP_1;
232 + }
233 +
234 + @Override
235 + public int getType() {
236 + return FEC_OBJ_TYPE;
237 + }
238 +
239 + @Override
240 + public String toString() {
241 + return MoreObjects.toStringHelper(getClass()).add("localIPv6Address", localIPv6Address)
242 + .add("remoteIPv6Address: ", remoteIPv6Address).toString();
243 + }
244 +}
1 +/*
2 + * Copyright 2015 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +
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.PcepFecObjectIPv6;
22 +import org.onosproject.pcepio.protocol.PcepVersion;
23 +import org.onosproject.pcepio.types.PcepObjectHeader;
24 +import org.slf4j.Logger;
25 +import org.slf4j.LoggerFactory;
26 +
27 +import com.google.common.base.MoreObjects;
28 +
29 +public class PcepFecObjectIPv6Ver1 implements PcepFecObjectIPv6 {
30 +
31 + /*
32 + * ref : draft-zhao-pce-pcep-extension-for-pce-controller-01 , section : 7.5
33 + *
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 + | |
38 + // IPv6 Node ID (16 bytes) //
39 + | |
40 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
41 +
42 + FEC Object-Type is 2 IPv6 Node ID
43 + */
44 + protected static final Logger log = LoggerFactory.getLogger(PcepFecObjectIPv6Ver1.class);
45 +
46 + public static final byte FEC_OBJ_TYPE = 2;
47 + public static final byte FEC_OBJ_CLASS = 63; //to be defined
48 + public static final byte FEC_OBJECT_VERSION = 1;
49 + public static final short FEC_OBJ_MINIMUM_LENGTH = 20;
50 + public static final int MINIMUM_COMMON_HEADER_LENGTH = 4;
51 + public static final int IPV6_ADDRESS_LENGTH = 16;
52 +
53 + static final PcepObjectHeader DEFAULT_FEC_OBJECT_HEADER = new PcepObjectHeader(FEC_OBJ_CLASS, FEC_OBJ_TYPE,
54 + PcepObjectHeader.REQ_OBJ_OPTIONAL_PROCESS, PcepObjectHeader.RSP_OBJ_PROCESSED, FEC_OBJ_MINIMUM_LENGTH);
55 +
56 + private PcepObjectHeader fecObjHeader;
57 + private byte[] nodeID = new byte[IPV6_ADDRESS_LENGTH];
58 +
59 + /**
60 + * Constructor to initialize parameters for PCEP fec object.
61 + *
62 + * @param fecObjHeader Fec object header
63 + * @param nodeID node ID
64 + */
65 + public PcepFecObjectIPv6Ver1(PcepObjectHeader fecObjHeader, byte[] nodeID) {
66 + this.fecObjHeader = fecObjHeader;
67 + this.nodeID = nodeID;
68 + }
69 +
70 + /**
71 + * Sets the Object header.
72 + *
73 + * @param obj object header
74 + */
75 + public void setFecIpv6ObjHeader(PcepObjectHeader obj) {
76 + this.fecObjHeader = obj;
77 + }
78 +
79 + @Override
80 + public void setNodeID(byte[] nodeID) {
81 + this.nodeID = nodeID;
82 + }
83 +
84 + /**
85 + * Returns object header.
86 + *
87 + * @return fec Object Header
88 + */
89 + public PcepObjectHeader getFecIpv6ObjHeader() {
90 + return this.fecObjHeader;
91 + }
92 +
93 + @Override
94 + public byte[] getNodeID() {
95 + return this.nodeID;
96 + }
97 +
98 + /**
99 + * reads the channel buffer and returns object of PcepFecObjectIPv6.
100 + *
101 + * @param cb of channel buffer.
102 + * @return object of PcepFecObjectIPv6
103 + * @throws PcepParseException when fails to read from channel buffer
104 + */
105 + public static PcepFecObjectIPv6 read(ChannelBuffer cb) throws PcepParseException {
106 +
107 + PcepObjectHeader fecObjHeader;
108 + byte[] nodeID = new byte[IPV6_ADDRESS_LENGTH];
109 + fecObjHeader = PcepObjectHeader.read(cb);
110 + cb.readBytes(nodeID, 0, IPV6_ADDRESS_LENGTH);
111 + return new PcepFecObjectIPv6Ver1(fecObjHeader, nodeID);
112 + }
113 +
114 + @Override
115 + public int write(ChannelBuffer cb) throws PcepParseException {
116 +
117 + int objStartIndex = cb.writerIndex();
118 +
119 + //write common header
120 + int objLenIndex = fecObjHeader.write(cb);
121 + cb.writeBytes(nodeID);
122 +
123 + //now write FEC IPv4 Object Length
124 + cb.setShort(objLenIndex, (short) (cb.writerIndex() - objStartIndex));
125 + return cb.writerIndex();
126 + }
127 +
128 + /**
129 + * Builder class for PCEP fec object IPv6.
130 + */
131 + public static class Builder implements PcepFecObjectIPv6.Builder {
132 + private boolean bIsHeaderSet = false;
133 + private boolean bIsNodeIdset = false;
134 +
135 + private PcepObjectHeader fecObjHeader;
136 + private byte[] nodeID = new byte[IPV6_ADDRESS_LENGTH];
137 +
138 + private boolean bIsPFlagSet = false;
139 + private boolean bPFlag;
140 +
141 + private boolean bIsIFlagSet = false;
142 + private boolean bIFlag;
143 +
144 + @Override
145 + public PcepFecObjectIPv6 build() throws PcepParseException {
146 + PcepObjectHeader fecObjHeader = this.bIsHeaderSet ? this.fecObjHeader : DEFAULT_FEC_OBJECT_HEADER;
147 +
148 + if (!this.bIsNodeIdset) {
149 + throw new PcepParseException(" NodeID not set while building PcepFecObjectIPv6 object.");
150 + }
151 + if (bIsPFlagSet) {
152 + fecObjHeader.setPFlag(bPFlag);
153 + }
154 + if (bIsIFlagSet) {
155 + fecObjHeader.setIFlag(bIFlag);
156 + }
157 + return new PcepFecObjectIPv6Ver1(fecObjHeader, this.nodeID);
158 + }
159 +
160 + @Override
161 + public Builder setPFlag(boolean value) {
162 + this.bPFlag = value;
163 + this.bIsPFlagSet = true;
164 + return this;
165 + }
166 +
167 + @Override
168 + public Builder setIFlag(boolean value) {
169 + this.bIFlag = value;
170 + this.bIsIFlagSet = true;
171 + return this;
172 + }
173 +
174 + @Override
175 + public PcepObjectHeader getFecIpv6ObjHeader() {
176 + return this.fecObjHeader;
177 + }
178 +
179 + @Override
180 + public Builder setFecIpv6ObjHeader(PcepObjectHeader obj) {
181 + this.fecObjHeader = obj;
182 + this.bIsHeaderSet = true;
183 + return this;
184 + }
185 +
186 + @Override
187 + public byte[] getNodeID() {
188 + return this.nodeID;
189 + }
190 +
191 + @Override
192 + public Builder setNodeID(byte[] value) {
193 + this.nodeID = value;
194 + this.bIsNodeIdset = true;
195 + return this;
196 + }
197 +
198 + }
199 +
200 + @Override
201 + public PcepVersion getVersion() {
202 + return PcepVersion.PCEP_1;
203 + }
204 +
205 + @Override
206 + public int getType() {
207 + return FEC_OBJ_TYPE;
208 + }
209 +
210 + @Override
211 + public String toString() {
212 + return MoreObjects.toStringHelper(getClass()).add("fecObjHeader", fecObjHeader).add("NodeID: ", nodeID)
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 +
17 +package org.onosproject.pcepio.protocol.ver1;
18 +
19 +import java.util.LinkedList;
20 +import java.util.ListIterator;
21 +
22 +import org.jboss.netty.buffer.ChannelBuffer;
23 +import org.onosproject.pcepio.exceptions.PcepParseException;
24 +import org.onosproject.pcepio.protocol.PcepLabelObject;
25 +import org.onosproject.pcepio.types.NexthopIPv4addressTlv;
26 +import org.onosproject.pcepio.types.NexthopIPv6addressTlv;
27 +import org.onosproject.pcepio.types.NexthopUnnumberedIPv4IDTlv;
28 +import org.onosproject.pcepio.types.PcepObjectHeader;
29 +import org.onosproject.pcepio.types.PcepValueType;
30 +import org.slf4j.Logger;
31 +import org.slf4j.LoggerFactory;
32 +
33 +import com.google.common.base.MoreObjects;
34 +
35 +/*
36 + * ref : draft-zhao-pce-pcep-extension-for-pce-controller-01 , section : 7.4.
37 +
38 + 0 1 2 3
39 + 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
40 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
41 + | Reserved | Flags |O|
42 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
43 + | Label |
44 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
45 + | |
46 + // Optional TLV //
47 + | |
48 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
49 + The LABEL Object format
50 + */
51 +public class PcepLabelObjectVer1 implements PcepLabelObject {
52 +
53 + protected static final Logger log = LoggerFactory.getLogger(PcepLspObjectVer1.class);
54 +
55 + public static final byte LABEL_OBJ_TYPE = 1;
56 + public static final byte LABEL_OBJ_CLASS = 35; //TBD : to be defined
57 + public static final byte LABEL_OBJECT_VERSION = 1;
58 + public static final byte OBJECT_HEADER_LENGTH = 4;
59 + public static final boolean DEFAULT_OFLAG = false;
60 +
61 + // LSP_OBJ_MINIMUM_LENGTH = CommonHeaderLen(4)+ LspObjectHeaderLen(8)
62 + public static final short LABEL_OBJ_MINIMUM_LENGTH = 12;
63 +
64 + public static final int OFLAG_SET = 1;
65 + public static final int OFLAG_RESET = 0;
66 + public static final int MINIMUM_COMMON_HEADER_LENGTH = 4;
67 +
68 + static final PcepObjectHeader DEFAULT_LABEL_OBJECT_HEADER = new PcepObjectHeader(LABEL_OBJ_CLASS, LABEL_OBJ_TYPE,
69 + PcepObjectHeader.REQ_OBJ_OPTIONAL_PROCESS, PcepObjectHeader.RSP_OBJ_PROCESSED, LABEL_OBJ_MINIMUM_LENGTH);
70 +
71 + private PcepObjectHeader labelObjHeader;
72 + private boolean bOFlag;
73 + private int label;
74 + // Optional TLV
75 + private LinkedList<PcepValueType> llOptionalTlv;
76 +
77 + /**
78 + * Constructor to initialize parameters for PCEP label object.
79 + *
80 + * @param labelObjHeader label object header
81 + * @param bOFlag O flag
82 + * @param label label
83 + * @param llOptionalTlv list of optional tlvs
84 + */
85 + public PcepLabelObjectVer1(PcepObjectHeader labelObjHeader, boolean bOFlag, int label,
86 + LinkedList<PcepValueType> llOptionalTlv) {
87 + this.labelObjHeader = labelObjHeader;
88 + this.bOFlag = bOFlag;
89 + this.label = label;
90 + this.llOptionalTlv = llOptionalTlv;
91 + }
92 +
93 + @Override
94 + public LinkedList<PcepValueType> getOptionalTlv() {
95 + return this.llOptionalTlv;
96 + }
97 +
98 + @Override
99 + public void setOptionalTlv(LinkedList<PcepValueType> llOptionalTlv) {
100 + this.llOptionalTlv = llOptionalTlv;
101 + }
102 +
103 + @Override
104 + public boolean getOFlag() {
105 + return this.bOFlag;
106 + }
107 +
108 + @Override
109 + public void setOFlag(boolean value) {
110 + this.bOFlag = value;
111 + }
112 +
113 + @Override
114 + public int getLabel() {
115 + return this.label;
116 + }
117 +
118 + @Override
119 + public void setLabel(int value) {
120 + this.label = value;
121 + }
122 +
123 + /**
124 + * Reads form channel buffer and returns objects of PcepLabelObject.
125 + *
126 + * @param cb of type channel buffer
127 + * @return objects of PcepLabelObject
128 + * @throws PcepParseException when fails to read from channel buffer
129 + */
130 + public static PcepLabelObject read(ChannelBuffer cb) throws PcepParseException {
131 +
132 + PcepObjectHeader labelObjHeader;
133 +
134 + boolean bOFlag;
135 + int label;
136 +
137 + // Optional TLV
138 + LinkedList<PcepValueType> llOptionalTlv = new LinkedList<PcepValueType>();
139 + labelObjHeader = PcepObjectHeader.read(cb);
140 +
141 + //take only LspObject buffer.
142 + ChannelBuffer tempCb = cb.readBytes(labelObjHeader.getObjLen() - OBJECT_HEADER_LENGTH);
143 +
144 + int iTemp = tempCb.readInt();
145 + bOFlag = (iTemp & (byte) 0x01) == 1 ? true : false;
146 + label = tempCb.readInt();
147 +
148 + // parse optional TLV
149 + llOptionalTlv = parseOptionalTlv(tempCb);
150 + return new PcepLabelObjectVer1(labelObjHeader, bOFlag, label, llOptionalTlv);
151 + }
152 +
153 + @Override
154 + public int write(ChannelBuffer cb) throws PcepParseException {
155 +
156 + //write Object header
157 + int objStartIndex = cb.writerIndex();
158 + int objLenIndex = labelObjHeader.write(cb);
159 +
160 + if (objLenIndex <= 0) {
161 + throw new PcepParseException(" ObjectLength Index is " + objLenIndex);
162 + }
163 +
164 + byte oFlag;
165 +
166 + oFlag = (byte) ((bOFlag) ? OFLAG_SET : OFLAG_RESET);
167 + cb.writeInt(oFlag);
168 + cb.writeInt(label);
169 +
170 + // Add optional TLV
171 + packOptionalTlv(cb);
172 +
173 + //Update object length now
174 + int length = cb.writerIndex() - objStartIndex;
175 +
176 + //will be helpful during print().
177 + labelObjHeader.setObjLen((short) length);
178 + cb.setShort(objLenIndex, (short) length);
179 + return cb.writerIndex();
180 + }
181 +
182 + /**
183 + * Returns list of optional tlvs.
184 + *
185 + * @param cb of type channel buffer
186 + * @return list of optional tlvs.
187 + * @throws PcepParseException when fails to parse list of optional tlvs
188 + */
189 + protected static LinkedList<PcepValueType> parseOptionalTlv(ChannelBuffer cb) throws PcepParseException {
190 +
191 + LinkedList<PcepValueType> llOutOptionalTlv = new LinkedList<PcepValueType>();
192 +
193 + while (MINIMUM_COMMON_HEADER_LENGTH <= cb.readableBytes()) {
194 +
195 + PcepValueType tlv;
196 + short hType = cb.readShort();
197 + short hLength = cb.readShort();
198 + int iValue = 0;
199 +
200 + switch (hType) {
201 +
202 + case NexthopIPv4addressTlv.TYPE:
203 + iValue = cb.readInt();
204 + tlv = new NexthopIPv4addressTlv(iValue);
205 + break;
206 + case NexthopIPv6addressTlv.TYPE:
207 + byte[] ipv6Value = new byte[NexthopIPv6addressTlv.VALUE_LENGTH];
208 + cb.readBytes(ipv6Value, 0, NexthopIPv6addressTlv.VALUE_LENGTH);
209 + tlv = new NexthopIPv6addressTlv(ipv6Value);
210 + break;
211 + case NexthopUnnumberedIPv4IDTlv.TYPE:
212 + tlv = NexthopUnnumberedIPv4IDTlv.read(cb);
213 + break;
214 + default:
215 + throw new PcepParseException("Unsupported TLV type :" + hType);
216 + }
217 +
218 + // Check for the padding
219 + int pad = hLength % 4;
220 + if (0 < pad) {
221 + pad = 4 - pad;
222 + if (pad <= cb.readableBytes()) {
223 + cb.skipBytes(pad);
224 + }
225 + }
226 +
227 + llOutOptionalTlv.add(tlv);
228 + }
229 +
230 + if (0 < cb.readableBytes()) {
231 +
232 + throw new PcepParseException("Optional Tlv parsing error. Extra bytes received.");
233 + }
234 + return llOutOptionalTlv;
235 + }
236 +
237 + /**
238 + * Returns the writer index.
239 + *
240 + * @param cb of channel buffer.
241 + * @return writer index
242 + */
243 + protected int packOptionalTlv(ChannelBuffer cb) {
244 +
245 + ListIterator<PcepValueType> listIterator = llOptionalTlv.listIterator();
246 +
247 + while (listIterator.hasNext()) {
248 + PcepValueType tlv = listIterator.next();
249 +
250 + if (null == tlv) {
251 + log.debug("tlv is null from OptionalTlv list");
252 + continue;
253 + }
254 + tlv.write(cb);
255 + }
256 + return cb.writerIndex();
257 + }
258 +
259 + /**
260 + * Builder class for PCEP label object.
261 + */
262 + public static class Builder implements PcepLabelObject.Builder {
263 +
264 + private boolean bIsHeaderSet = false;
265 + private boolean bIsOFlagSet = false;
266 + private boolean bIsLabelSet = false;
267 +
268 + private PcepObjectHeader labelObjHeader;
269 + private boolean bOFlag;
270 + private int label;
271 +
272 + LinkedList<PcepValueType> llOptionalTlv = new LinkedList<PcepValueType>();
273 +
274 + private boolean bIsPFlagSet = false;
275 + private boolean bPFlag;
276 +
277 + private boolean bIsIFlagSet = false;
278 + private boolean bIFlag;
279 +
280 + @Override
281 + public PcepLabelObject build() throws PcepParseException {
282 + PcepObjectHeader labelObjHeader = this.bIsHeaderSet ? this.labelObjHeader : DEFAULT_LABEL_OBJECT_HEADER;
283 + boolean bOFlag = this.bIsOFlagSet ? this.bOFlag : DEFAULT_OFLAG;
284 +
285 + if (!this.bIsLabelSet) {
286 + throw new PcepParseException(" Label NOT Set while building PcepLabelObject.");
287 + }
288 + if (bIsPFlagSet) {
289 + labelObjHeader.setPFlag(bPFlag);
290 + }
291 + if (bIsIFlagSet) {
292 + labelObjHeader.setIFlag(bIFlag);
293 + }
294 + return new PcepLabelObjectVer1(labelObjHeader, bOFlag, this.label, this.llOptionalTlv);
295 + }
296 +
297 + @Override
298 + public PcepObjectHeader getLabelObjHeader() {
299 + return this.labelObjHeader;
300 + }
301 +
302 + @Override
303 + public Builder setLabelObjHeader(PcepObjectHeader obj) {
304 + this.labelObjHeader = obj;
305 + this.bIsHeaderSet = true;
306 + return this;
307 + }
308 +
309 + @Override
310 + public boolean getOFlag() {
311 + return this.bOFlag;
312 + }
313 +
314 + @Override
315 + public Builder setOFlag(boolean value) {
316 + this.bOFlag = value;
317 + this.bIsOFlagSet = true;
318 + return this;
319 + }
320 +
321 + @Override
322 + public int getLabel() {
323 + return this.label;
324 + }
325 +
326 + @Override
327 + public Builder setLabel(int value) {
328 + this.label = value;
329 + this.bIsLabelSet = true;
330 + return this;
331 + }
332 +
333 + @Override
334 + public LinkedList<PcepValueType> getOptionalTlv() {
335 + return this.llOptionalTlv;
336 + }
337 +
338 + @Override
339 + public Builder setOptionalTlv(LinkedList<PcepValueType> llOptionalTlv) {
340 + this.llOptionalTlv = llOptionalTlv;
341 + return this;
342 + }
343 +
344 + @Override
345 + public Builder setPFlag(boolean value) {
346 + this.bPFlag = value;
347 + this.bIsPFlagSet = true;
348 + return this;
349 + }
350 +
351 + @Override
352 + public Builder setIFlag(boolean value) {
353 + this.bIFlag = value;
354 + this.bIsIFlagSet = true;
355 + return this;
356 + }
357 + }
358 +
359 + @Override
360 + public String toString() {
361 + return MoreObjects.toStringHelper(getClass()).add("OFlag", bOFlag).add("label", label)
362 + .add("OptionalTlvList", llOptionalTlv).toString();
363 + }
364 +}
1 +/*
2 + * Copyright 2015 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +
17 +package org.onosproject.pcepio.protocol.ver1;
18 +
19 +import java.util.LinkedList;
20 +import java.util.ListIterator;
21 +
22 +import org.jboss.netty.buffer.ChannelBuffer;
23 +import org.onosproject.pcepio.exceptions.PcepParseException;
24 +import org.onosproject.pcepio.protocol.PcepLabelUpdate;
25 +import org.onosproject.pcepio.protocol.PcepLabelUpdateMsg;
26 +import org.onosproject.pcepio.protocol.PcepMessageReader;
27 +import org.onosproject.pcepio.protocol.PcepMessageWriter;
28 +import org.onosproject.pcepio.protocol.PcepType;
29 +import org.onosproject.pcepio.protocol.PcepVersion;
30 +import org.slf4j.Logger;
31 +import org.slf4j.LoggerFactory;
32 +
33 +import com.google.common.base.MoreObjects;
34 +
35 +class PcepLabelUpdateMsgVer1 implements PcepLabelUpdateMsg {
36 +
37 + // Pcep version: 1
38 +
39 + /*
40 + The format of the PCLabelUpd message:
41 +
42 + <PCLabelUpd Message> ::= <Common Header>
43 + <pce-label-update-list>
44 + Where:
45 +
46 + <pce-label-update-list> ::= <pce-label-update>
47 + [<pce-label-update-list>]
48 + <pce-label-update> ::= (<pce-label-download>|<pce-label-map>)
49 +
50 + Where:
51 + <pce-label-download> ::= <SRP>
52 + <LSP>
53 + <label-list>
54 +
55 + <pce-label-map> ::= <SRP>
56 + <LABEL>
57 + <FEC>
58 +
59 + <label-list > ::= <LABEL>
60 + [<label-list>]
61 +
62 + */
63 + protected static final Logger log = LoggerFactory.getLogger(PcepLabelUpdateMsgVer1.class);
64 +
65 + public static final byte PACKET_VERSION = 1;
66 +
67 + //LabelUpdateMsgMinLength = COMMON-HEADER(4)+SrpObjMinLentgh(12)+LabelObjectMinLength(12)+FECType1Object(8)
68 + public static final int PACKET_MINIMUM_LENGTH = 36;
69 + public static final PcepType MSG_TYPE = PcepType.LABEL_UPDATE;
70 + //pce-label-update-list
71 + private LinkedList<PcepLabelUpdate> llPcLabelUpdateList;
72 +
73 + static final PcepLabelUpdateMsgVer1.Reader READER = new Reader();
74 +
75 + //Reader reads LabelUpdate Message from the channel.
76 + static class Reader implements PcepMessageReader<PcepLabelUpdateMsg> {
77 +
78 + @Override
79 + public PcepLabelUpdateMsg readFrom(ChannelBuffer cb) throws PcepParseException {
80 +
81 + if (cb.readableBytes() < PACKET_MINIMUM_LENGTH) {
82 + throw new PcepParseException("Readable bytes are less than Packet minimum length.");
83 + }
84 +
85 + // fixed value property version == 1
86 + byte version = cb.readByte();
87 + version = (byte) (version >> PcepMessageVer1.SHIFT_FLAG);
88 + if (version != PACKET_VERSION) {
89 + throw new PcepParseException("Wrong version.Expected=PcepVersion.PCEP_1(1), got=" + version);
90 + }
91 + // fixed value property type == 13
92 + byte type = cb.readByte();
93 + if (type != MSG_TYPE.getType()) {
94 + throw new PcepParseException("Wrong type. Expected=PcepType.LABEL_UPDATE(13), got=" + type);
95 + }
96 + short length = cb.readShort();
97 + if (length < PACKET_MINIMUM_LENGTH) {
98 + throw new PcepParseException("Wrong length. Expected to be >= " + PACKET_MINIMUM_LENGTH + ", is: "
99 + + length);
100 + }
101 + // parse <pce-label-download> / <pce-label-map>
102 + LinkedList<PcepLabelUpdate> llPcLabelUpdateList = parsePcLabelUpdateList(cb);
103 + return new PcepLabelUpdateMsgVer1(llPcLabelUpdateList);
104 + }
105 +
106 + /**
107 + * Returns list of PCEP Label Update object.
108 + *
109 + * @param cb of type channel buffer
110 + * @return llPcLabelUpdateList list of PCEP label update object
111 + * @throws PcepParseException when fails to parse list of PCEP label update object
112 + */
113 + public LinkedList<PcepLabelUpdate> parsePcLabelUpdateList(ChannelBuffer cb) throws PcepParseException {
114 +
115 + LinkedList<PcepLabelUpdate> llPcLabelUpdateList;
116 + llPcLabelUpdateList = new LinkedList<PcepLabelUpdate>();
117 +
118 + while (0 < cb.readableBytes()) {
119 + llPcLabelUpdateList.add(PcepLabelUpdateVer1.read(cb));
120 + }
121 + return llPcLabelUpdateList;
122 + }
123 + }
124 +
125 + /**
126 + * Constructor to initialize PCEP Label Update List.
127 + *
128 + * @param llPcLabelUpdateList list of PCEP Label Update object
129 + */
130 + PcepLabelUpdateMsgVer1(LinkedList<PcepLabelUpdate> llPcLabelUpdateList) {
131 + this.llPcLabelUpdateList = llPcLabelUpdateList;
132 + }
133 +
134 + static class Builder implements PcepLabelUpdateMsg.Builder {
135 +
136 + LinkedList<PcepLabelUpdate> llPcLabelUpdateList;
137 +
138 + @Override
139 + public PcepVersion getVersion() {
140 + return PcepVersion.PCEP_1;
141 + }
142 +
143 + @Override
144 + public PcepType getType() {
145 + return PcepType.LABEL_UPDATE;
146 + }
147 +
148 + @Override
149 + public PcepLabelUpdateMsg build() {
150 + return new PcepLabelUpdateMsgVer1(this.llPcLabelUpdateList);
151 + }
152 +
153 + @Override
154 + public LinkedList<PcepLabelUpdate> getPcLabelUpdateList() {
155 + return this.llPcLabelUpdateList;
156 + }
157 +
158 + @Override
159 + public Builder setPcLabelUpdateList(LinkedList<PcepLabelUpdate> ll) {
160 + this.llPcLabelUpdateList = ll;
161 + return this;
162 + }
163 + }
164 +
165 + @Override
166 + public void writeTo(ChannelBuffer cb) throws PcepParseException {
167 + WRITER.write(cb, this);
168 + }
169 +
170 + static final Writer WRITER = new Writer();
171 +
172 + //Writer writes LabelUpdate Message to the channel.
173 + static class Writer implements PcepMessageWriter<PcepLabelUpdateMsgVer1> {
174 +
175 + @Override
176 + public void write(ChannelBuffer cb, PcepLabelUpdateMsgVer1 message) throws PcepParseException {
177 +
178 + int startIndex = cb.writerIndex();
179 +
180 + // first 3 bits set to version
181 + cb.writeByte((byte) (PACKET_VERSION << PcepMessageVer1.SHIFT_FLAG));
182 +
183 + // message type
184 + cb.writeByte(MSG_TYPE.getType());
185 +
186 + // Length will be set after calculating length, but currently set it as 0.
187 + int msgLenIndex = cb.writerIndex();
188 +
189 + cb.writeShort((short) 0);
190 + ListIterator<PcepLabelUpdate> listIterator = message.llPcLabelUpdateList.listIterator();
191 +
192 + while (listIterator.hasNext()) {
193 + PcepLabelUpdate labelUpdate = listIterator.next();
194 + labelUpdate.write(cb);
195 + }
196 +
197 + // update message length field
198 + int length = cb.writerIndex() - startIndex;
199 + cb.setShort(msgLenIndex, (short) length);
200 + }
201 + }
202 +
203 + @Override
204 + public PcepVersion getVersion() {
205 + return PcepVersion.PCEP_1;
206 + }
207 +
208 + @Override
209 + public PcepType getType() {
210 + return MSG_TYPE;
211 + }
212 +
213 + @Override
214 + public LinkedList<PcepLabelUpdate> getPcLabelUpdateList() {
215 + return this.llPcLabelUpdateList;
216 + }
217 +
218 + @Override
219 + public void setPcLabelUpdateList(LinkedList<PcepLabelUpdate> ll) {
220 + this.llPcLabelUpdateList = ll;
221 + }
222 +
223 + @Override
224 + public String toString() {
225 + return MoreObjects.toStringHelper(getClass()).add("PcLabelUpdateList", llPcLabelUpdateList).toString();
226 + }
227 +}
1 +/*
2 + * Copyright 2015 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +
17 +package org.onosproject.pcepio.protocol.ver1;
18 +
19 +import java.util.LinkedList;
20 +import java.util.ListIterator;
21 +
22 +import org.jboss.netty.buffer.ChannelBuffer;
23 +import org.onosproject.pcepio.exceptions.PcepParseException;
24 +import org.onosproject.pcepio.protocol.PcepFecObject;
25 +import org.onosproject.pcepio.protocol.PcepLabelObject;
26 +import org.onosproject.pcepio.protocol.PcepLabelUpdate;
27 +import org.onosproject.pcepio.protocol.PcepLspObject;
28 +import org.onosproject.pcepio.protocol.PcepSrpObject;
29 +import org.onosproject.pcepio.types.PcepLabelDownload;
30 +import org.onosproject.pcepio.types.PcepLabelMap;
31 +import org.onosproject.pcepio.types.PcepObjectHeader;
32 +import org.slf4j.Logger;
33 +import org.slf4j.LoggerFactory;
34 +
35 +import com.google.common.base.MoreObjects;
36 +import com.google.common.base.MoreObjects.ToStringHelper;
37 +
38 +/**
39 + * Provides PCEP LABEL update .
40 + * Reference :draft-zhao-pce-pcep-extension-for-pce-controller-01.
41 + */
42 +public class PcepLabelUpdateVer1 implements PcepLabelUpdate {
43 +
44 + /*
45 + * <pce-label-update> ::= (<pce-label-download>|<pce-label-map>)
46 +
47 + Where:
48 + <pce-label-download> ::= <SRP>
49 + <LSP>
50 + <label-list>
51 +
52 + <pce-label-map> ::= <SRP>
53 + <LABEL>
54 + <FEC>
55 +
56 + <label-list > ::= <LABEL>
57 + [<label-list>]
58 + */
59 + protected static final Logger log = LoggerFactory.getLogger(PcepLabelUpdateVer1.class);
60 +
61 + //Either PceLabelDownload or PceLabelMap is mandatory.
62 + //label Download
63 + private PcepLabelDownload labelDownload;
64 + private boolean isLabelDownloadSet;
65 + //label Map
66 + private PcepLabelMap labelMap;
67 + private boolean isLabelMapSet;
68 +
69 + /**
70 + * Constructor to reset parameters.
71 + */
72 + public PcepLabelUpdateVer1() {
73 + this.labelDownload = null;
74 + this.isLabelDownloadSet = false;
75 + this.labelMap = null;
76 + this.isLabelMapSet = false;
77 + }
78 +
79 + /**
80 + * Constructor to initialize PCEP label download.
81 + *
82 + * @param labelDownload PCEP label download
83 + */
84 + public PcepLabelUpdateVer1(PcepLabelDownload labelDownload) {
85 + this.labelDownload = labelDownload;
86 + this.isLabelDownloadSet = true;
87 + this.labelMap = null;
88 + this.isLabelMapSet = false;
89 + }
90 +
91 + /**
92 + * Constructor to initialize PCEP label map.
93 + *
94 + * @param labelMap PCEP label map
95 + */
96 + public PcepLabelUpdateVer1(PcepLabelMap labelMap) {
97 + this.labelDownload = null;
98 + this.isLabelDownloadSet = false;
99 + this.labelMap = labelMap;
100 + this.isLabelMapSet = true;
101 + }
102 +
103 + /**
104 + * builder class for PCEP label update.
105 + */
106 + static class Builder implements PcepLabelUpdate.Builder {
107 +
108 + private PcepLabelDownload labelDownload;
109 + private boolean isLabelDownloadSet;
110 + private PcepLabelMap labelMap;
111 + private boolean isLabelMapSet;
112 +
113 + @Override
114 + public PcepLabelUpdate build() throws PcepParseException {
115 +
116 + if (isLabelDownloadSet) {
117 + return new PcepLabelUpdateVer1(labelDownload);
118 + }
119 + if (isLabelMapSet) {
120 + return new PcepLabelUpdateVer1(labelMap);
121 + }
122 + if (!isLabelDownloadSet && !isLabelMapSet) {
123 + throw new PcepParseException(
124 + "Label Download or Label Map is not set while building PcepLabelUpdate Message");
125 + }
126 + return new PcepLabelUpdateVer1();
127 + }
128 +
129 + @Override
130 + public Builder setLabelDownload(PcepLabelDownload labelDownload) {
131 + this.labelDownload = labelDownload;
132 + this.isLabelDownloadSet = true;
133 + return this;
134 + }
135 +
136 + @Override
137 + public PcepLabelDownload getLabelDownload() {
138 + return labelDownload;
139 + }
140 +
141 + @Override
142 + public Builder setLabelMap(PcepLabelMap labelMap) {
143 + this.labelMap = labelMap;
144 + this.isLabelMapSet = true;
145 + return this;
146 + }
147 +
148 + @Override
149 + public PcepLabelMap getLabelMap() {
150 + return labelMap;
151 + }
152 + }
153 +
154 + /**
155 + * Reads PcepLabels from the byte stream received from channel buffer.
156 + *
157 + * @param cb of type channel buffer.
158 + * @return PcepLabelUpdate object.
159 + * @throws PcepParseException when fails to read from channel buffer
160 + */
161 + public static PcepLabelUpdate read(ChannelBuffer cb) throws PcepParseException {
162 +
163 + PcepLabelUpdateVer1 pceLabelUpdate = new PcepLabelUpdateVer1();
164 +
165 + PcepSrpObject srpObject;
166 + PcepObjectHeader tempObjHeader;
167 +
168 + //read SRP mandatory Object
169 + srpObject = PcepSrpObjectVer1.read(cb);
170 +
171 + //checking next object
172 + cb.markReaderIndex();
173 +
174 + tempObjHeader = PcepObjectHeader.read(cb);
175 + cb.resetReaderIndex();
176 +
177 + if (tempObjHeader.getObjClass() == PcepLspObjectVer1.LSP_OBJ_CLASS) {
178 +
179 + //now it is belong to <pce-label-download>
180 + PcepLabelDownload labelDownload = new PcepLabelDownload();
181 +
182 + //set SRP
183 + labelDownload.setSrpObject(srpObject);
184 +
185 + //read and set LSP
186 + labelDownload.setLspObject(PcepLspObjectVer1.read(cb));
187 +
188 + //<label-list>
189 + LinkedList<PcepLabelObject> llLabelList = new LinkedList<PcepLabelObject>();
190 + PcepLabelObject labelObject;
191 +
192 + while (0 < cb.readableBytes()) {
193 +
194 + cb.markReaderIndex();
195 + tempObjHeader = PcepObjectHeader.read(cb);
196 + cb.resetReaderIndex();
197 +
198 + if (tempObjHeader.getObjClass() != PcepLabelObjectVer1.LABEL_OBJ_CLASS) {
199 + break;
200 + }
201 + labelObject = PcepLabelObjectVer1.read(cb);
202 + llLabelList.add(labelObject);
203 + }
204 + labelDownload.setLabelList(llLabelList);
205 + pceLabelUpdate.setLabelDownload(labelDownload);
206 + } else if (tempObjHeader.getObjClass() == PcepLabelObjectVer1.LABEL_OBJ_CLASS) {
207 + //belong to <pce-label-map>
208 + PcepLabelMap labelMap = new PcepLabelMap();
209 +
210 + //set SRP Object
211 + labelMap.setSrpObject(srpObject);
212 +
213 + //read and set Label Object
214 + labelMap.setLabelObject(PcepLabelObjectVer1.read(cb));
215 +
216 + cb.markReaderIndex();
217 + tempObjHeader = PcepObjectHeader.read(cb);
218 + cb.resetReaderIndex();
219 +
220 + PcepFecObject fecObject = null;
221 + switch (tempObjHeader.getObjType()) {
222 + case PcepFecObjectIPv4Ver1.FEC_OBJ_TYPE:
223 + fecObject = PcepFecObjectIPv4Ver1.read(cb);
224 + break;
225 + case PcepFecObjectIPv6Ver1.FEC_OBJ_TYPE:
226 + fecObject = PcepFecObjectIPv6Ver1.read(cb);
227 + break;
228 + case PcepFecObjectIPv4AdjacencyVer1.FEC_OBJ_TYPE:
229 + fecObject = PcepFecObjectIPv4AdjacencyVer1.read(cb);
230 + break;
231 + case PcepFecObjectIPv6AdjacencyVer1.FEC_OBJ_TYPE:
232 + fecObject = PcepFecObjectIPv6AdjacencyVer1.read(cb);
233 + break;
234 + case PcepFecObjectIPv4UnnumberedAdjacencyVer1.FEC_OBJ_TYPE:
235 + fecObject = PcepFecObjectIPv4UnnumberedAdjacencyVer1.read(cb);
236 + break;
237 + default:
238 + throw new PcepParseException("Unkown FEC object type " + tempObjHeader.getObjType());
239 + }
240 + labelMap.setFECObject(fecObject);
241 + pceLabelUpdate.setLabelMap(labelMap);
242 + } else {
243 + throw new PcepParseException(
244 + "Either <pce-label-download> or <pce-label-map> should be present. Received Class: "
245 + + tempObjHeader.getObjClass());
246 + }
247 + return pceLabelUpdate;
248 + }
249 +
250 + @Override
251 + public void write(ChannelBuffer cb) throws PcepParseException {
252 +
253 + if ((labelDownload != null) && (labelMap != null)) {
254 + throw new PcepParseException("Label Download and Label Map both can't be present.");
255 + }
256 +
257 + if ((labelDownload == null) && (labelMap == null)) {
258 + throw new PcepParseException("Either Label Download or Label Map should be present.");
259 + }
260 +
261 + if (labelDownload != null) {
262 +
263 + PcepLspObject lspObject;
264 + PcepSrpObject srpObject;
265 + PcepLabelObject labelObject;
266 + LinkedList<PcepLabelObject> llLabelList;
267 +
268 + srpObject = labelDownload.getSrpObject();
269 + if (srpObject == null) {
270 + throw new PcepParseException("SRP Object is mandatory object for Label Download.");
271 + } else {
272 + srpObject.write(cb);
273 + }
274 +
275 + lspObject = labelDownload.getLspObject();
276 + if (lspObject == null) {
277 + throw new PcepParseException("LSP Object is mandatory object for Label Download.");
278 + } else {
279 + lspObject.write(cb);
280 + }
281 +
282 + llLabelList = labelDownload.getLabelList();
283 + if (llLabelList == null) {
284 + throw new PcepParseException("Label list is mandatory object for Label Download.");
285 + } else {
286 + ListIterator<PcepLabelObject> listIterator = llLabelList.listIterator();
287 + while (listIterator.hasNext()) {
288 + labelObject = listIterator.next();
289 + labelObject.write(cb);
290 + }
291 + }
292 + }
293 +
294 + if (labelMap != null) {
295 +
296 + PcepSrpObject srpObject;
297 + PcepLabelObject labelObject;
298 + PcepFecObject fecObject;
299 +
300 + srpObject = labelMap.getSrpObject();
301 + if (srpObject == null) {
302 + throw new PcepParseException("SRP Object is mandatory object for Label map.");
303 + } else {
304 + srpObject.write(cb);
305 + }
306 + labelObject = labelMap.getLabelObject();
307 + if (labelObject == null) {
308 + throw new PcepParseException("label Object is mandatory object for Label map.");
309 + } else {
310 + labelObject.write(cb);
311 + }
312 + fecObject = labelMap.getFECObject();
313 + if (fecObject == null) {
314 + throw new PcepParseException("fec Object is mandatory object for Label map.");
315 + } else {
316 + fecObject.write(cb);
317 + }
318 + }
319 + }
320 +
321 + @Override
322 + public void setLabelDownload(PcepLabelDownload labelDownload) {
323 + if (this.isLabelMapSet) {
324 + return;
325 + }
326 + this.labelDownload = labelDownload;
327 + this.isLabelDownloadSet = true;
328 + }
329 +
330 + @Override
331 + public PcepLabelDownload getLabelDownload() {
332 + return this.labelDownload;
333 + }
334 +
335 + @Override
336 + public void setLabelMap(PcepLabelMap labelMap) {
337 + if (this.isLabelDownloadSet) {
338 + return;
339 + }
340 + this.labelMap = labelMap;
341 + this.isLabelMapSet = true;
342 + }
343 +
344 + @Override
345 + public PcepLabelMap getLabelMap() {
346 + return this.labelMap;
347 + }
348 +
349 + @Override
350 + public String toString() {
351 + ToStringHelper toStrHelper = MoreObjects.toStringHelper(getClass());
352 +
353 + if (labelDownload instanceof PcepLabelDownload) {
354 + toStrHelper.add("LabelDownload", labelDownload);
355 + }
356 + if (labelMap instanceof PcepLabelMap) {
357 + toStrHelper.add("LabelMap", labelMap);
358 + }
359 + return toStrHelper.toString();
360 + }
361 +}
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 + * NexthopIPv6addressTlv provides Ipv4 address of next hop.
30 + */
31 +public class NexthopIPv4addressTlv implements PcepValueType {
32 +
33 + /*
34 + Reference :draft-zhao-pce-pcep-extension-for-pce-controller-01
35 +
36 + 0 1 2 3
37 + 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
38 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
39 + | Type=TBD | Length = 8 |
40 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
41 + | nexthop IPv4 address |
42 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
43 +
44 + NEXTHOP-IPV4-ADDRESS TLV
45 +
46 + */
47 + protected static final Logger log = LoggerFactory.getLogger(NexthopIPv4addressTlv.class);
48 +
49 + public static final short TYPE = 2; //to be defined
50 + //Length is header + value
51 + public static final short LENGTH = 8;
52 + public static final short VALUE_LENGTH = 4;
53 +
54 + private final int rawValue;
55 +
56 + /**
57 + * Constructor to initialize next hop IPv4 address.
58 + *
59 + * @param rawValue next hop IPv4 address
60 + */
61 + public NexthopIPv4addressTlv(int rawValue) {
62 + this.rawValue = rawValue;
63 + }
64 +
65 + /**
66 + * Return next hop IPv4 address tlv.
67 + *
68 + * @param raw of next hop IPv4 address
69 + * @return object of NexthopIPv4addressTlv
70 + */
71 + public static NexthopIPv4addressTlv of(final int raw) {
72 + return new NexthopIPv4addressTlv(raw);
73 + }
74 +
75 + /**
76 + * Returns next hop IPv4 address.
77 + *
78 + * @return next hop IPv4 address
79 + */
80 + public int getInt() {
81 + return rawValue;
82 + }
83 +
84 + @Override
85 + public PcepVersion getVersion() {
86 + return PcepVersion.PCEP_1;
87 + }
88 +
89 + @Override
90 + public short getType() {
91 + return TYPE;
92 + }
93 +
94 + @Override
95 + public short getLength() {
96 + return LENGTH;
97 + }
98 +
99 + @Override
100 + public int hashCode() {
101 + return Objects.hash(rawValue);
102 + }
103 +
104 + @Override
105 + public boolean equals(Object obj) {
106 + if (this == obj) {
107 + return true;
108 + }
109 + if (obj instanceof NexthopIPv4addressTlv) {
110 + NexthopIPv4addressTlv other = (NexthopIPv4addressTlv) obj;
111 + return Objects.equals(this.rawValue, other.rawValue);
112 + }
113 + return false;
114 + }
115 +
116 + @Override
117 + public int write(ChannelBuffer c) {
118 + int iStartIndex = c.writerIndex();
119 + c.writeShort(TYPE);
120 + c.writeShort(LENGTH);
121 + c.writeInt(rawValue);
122 + return c.writerIndex() - iStartIndex;
123 + }
124 +
125 + /**
126 + * Reads the channel buffer and returns object of NexthopIPv4addressTlv.
127 + *
128 + * @param c type of channel buffer
129 + * @return object of NexthopIPv4addressTlv
130 + */
131 + public static NexthopIPv4addressTlv read(ChannelBuffer c) {
132 + return NexthopIPv4addressTlv.of(c.readInt());
133 + }
134 +
135 + @Override
136 + public String toString() {
137 + return MoreObjects.toStringHelper(getClass())
138 + .add("Type", TYPE)
139 + .add("Length", LENGTH)
140 + .add("Ipv4Address ", rawValue)
141 + .toString();
142 + }
143 +}
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 +import com.google.common.base.MoreObjects.ToStringHelper;
28 +
29 +/**
30 + * NexthopIPv6addressTlv provides Ipv6 address of next hop.
31 + */
32 +public class NexthopIPv6addressTlv implements PcepValueType {
33 +
34 + /*
35 + Reference: draft-zhao-pce-pcep-extension-for-pce-controller-01.
36 +
37 + 0 1 2 3
38 + 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
39 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
40 + | Type=TBD | Length = 20 |
41 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
42 + | |
43 + // nexthop IPv6 address (16 bytes) //
44 + | |
45 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
46 +
47 + NEXTHOP-IPV6-ADDRESS TLV:
48 +
49 + */
50 + protected static final Logger log = LoggerFactory.getLogger(NexthopIPv6addressTlv.class);
51 +
52 + public static final short TYPE = 100; //to be defined
53 + //Length is header + value
54 + public static final short LENGTH = 20;
55 + public static final short VALUE_LENGTH = 16;
56 +
57 + 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 };
58 + public static final NexthopIPv6addressTlv NONE = new NexthopIPv6addressTlv(NONE_VAL);
59 +
60 + private static final byte[] NO_MASK_VAL = {(byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
61 + (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
62 + (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF };
63 + public static final NexthopIPv6addressTlv NO_MASK = new NexthopIPv6addressTlv(NO_MASK_VAL);
64 + public static final NexthopIPv6addressTlv FULL_MASK = NONE;
65 +
66 + private final byte[] rawValue;
67 +
68 + /**
69 + * Constructor to initialize IP address for next hop IPv6 address tlv.
70 + *
71 + * @param rawValue value of Next hop ipAddress
72 + */
73 + public NexthopIPv6addressTlv(byte[] rawValue) {
74 + log.debug("NexthopIPv6addressTlv");
75 + this.rawValue = rawValue;
76 + }
77 +
78 + /**
79 + * Creates next hop IPv6 address tlv.
80 + *
81 + * @param raw value of Next hop ipAddress
82 + * @return object of NexthopIPv6addressTlv
83 + */
84 + //logic to be checked
85 + public static NexthopIPv6addressTlv of(final byte[] raw) {
86 + //check NONE_VAL
87 + boolean bFoundNONE = true;
88 + //value starts from 3rd byte.
89 + for (int i = 5; i < 20; ++i) {
90 + if (NONE_VAL[i] != raw[i]) {
91 + bFoundNONE = false;
92 + }
93 + }
94 +
95 + if (bFoundNONE) {
96 + return NONE;
97 + }
98 +
99 + //check NO_MASK_VAL
100 + boolean bFoundNoMask = true;
101 + //value starts from 3rd byte.
102 + for (int i = 5; i < 20; ++i) {
103 + if (0xFF != raw[i]) {
104 + bFoundNoMask = false;
105 + }
106 + }
107 + if (bFoundNoMask) {
108 + return NO_MASK;
109 + }
110 + return new NexthopIPv6addressTlv(raw);
111 + }
112 +
113 + /**
114 + * Returns next hop IPv6 address.
115 + *
116 + * @return next hop IPv6 address
117 + */
118 + public byte[] getBytes() {
119 + return rawValue;
120 + }
121 +
122 + @Override
123 + public PcepVersion getVersion() {
124 + return PcepVersion.PCEP_1;
125 + }
126 +
127 + @Override
128 + public short getType() {
129 + return TYPE;
130 + }
131 +
132 + @Override
133 + public short getLength() {
134 + return LENGTH;
135 + }
136 +
137 + @Override
138 + public int hashCode() {
139 + return Objects.hash(rawValue);
140 + }
141 +
142 + @Override
143 + public boolean equals(Object obj) {
144 + if (this == obj) {
145 + return true;
146 + }
147 + if (obj instanceof NexthopIPv6addressTlv) {
148 + NexthopIPv6addressTlv other = (NexthopIPv6addressTlv) obj;
149 + return Objects.equals(this.rawValue, other.rawValue);
150 + }
151 + return false;
152 + }
153 +
154 + @Override
155 + public int write(ChannelBuffer c) {
156 + int iStartIndex = c.writerIndex();
157 + c.writeShort(TYPE);
158 + c.writeShort(LENGTH);
159 + c.writeBytes(rawValue);
160 + return c.writerIndex() - iStartIndex;
161 + }
162 +
163 + /**
164 + * Reads the channel buffer and returns object of NexthopIPv6addressTlv.
165 + *
166 + * @param c type of channel buffer
167 + * @return object of NexthopIPv6addressTlv
168 + */
169 + public static NexthopIPv6addressTlv read(ChannelBuffer c) {
170 + byte[] yTemp = new byte[20];
171 + c.readBytes(yTemp, 0, 20);
172 + return NexthopIPv6addressTlv.of(yTemp);
173 + }
174 +
175 + @Override
176 + public String toString() {
177 + ToStringHelper toStrHelper = MoreObjects.toStringHelper(getClass());
178 +
179 + toStrHelper.add("Type", TYPE);
180 + toStrHelper.add("Length", LENGTH);
181 +
182 + StringBuffer result = new StringBuffer();
183 + for (byte b : rawValue) {
184 + result.append(String.format("%02X ", b));
185 + }
186 + toStrHelper.add("IpAddress", result);
187 +
188 + return toStrHelper.toString();
189 + }
190 +}
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 + * NexthopUnnumberedIPv4IDTlv provides the next node's ID and Interface ID.
30 + */
31 +public class NexthopUnnumberedIPv4IDTlv implements PcepValueType {
32 +
33 + /*
34 + Reference : draft-zhao-pce-pcep-extension-for-pce-controller-01.
35 +
36 + 0 1 2 3
37 + 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
38 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
39 + | Type=TBD | Length = 12 |
40 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
41 + | Node-ID |
42 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
43 + | Interface ID |
44 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
45 +
46 + NEXTHOP-UNNUMBERED-IPV4-ID TLV
47 +
48 + */
49 + protected static final Logger log = LoggerFactory.getLogger(NexthopUnnumberedIPv4IDTlv.class);
50 +
51 + public static final short TYPE = 1; //to be defined
52 + //Length is header + value
53 + public static final short LENGTH = 12;
54 +
55 + private final int nodeID;
56 + private final int interfaceID;
57 +
58 + /**
59 + * constructor to initialize nodeID and interfaceID.
60 + *
61 + * @param nodeID node ID
62 + * @param interfaceID interface ID
63 + */
64 + public NexthopUnnumberedIPv4IDTlv(int nodeID, int interfaceID) {
65 + this.nodeID = nodeID;
66 + this.interfaceID = interfaceID;
67 + }
68 +
69 + /**
70 + * Returns new object of NexthopUnnumberedIPv4IDTlv.
71 + *
72 + * @param nodeID node ID
73 + * @param interfaceID interface ID
74 + * @return NexthopUnnumberedIPv4IDTlv
75 + */
76 + public static NexthopUnnumberedIPv4IDTlv of(int nodeID, int interfaceID) {
77 + return new NexthopUnnumberedIPv4IDTlv(nodeID, interfaceID);
78 + }
79 +
80 + /**
81 + * Returns Node Id.
82 + *
83 + * @return node ID
84 + */
85 + public int getNodeID() {
86 + return nodeID;
87 + }
88 +
89 + /**
90 + * Returns Interface Id.
91 + *
92 + * @return interface ID
93 + */
94 + public int getInterfaceID() {
95 + return interfaceID;
96 + }
97 +
98 + @Override
99 + public PcepVersion getVersion() {
100 + return PcepVersion.PCEP_1;
101 + }
102 +
103 + @Override
104 + public short getType() {
105 + return TYPE;
106 + }
107 +
108 + @Override
109 + public short getLength() {
110 + return LENGTH;
111 + }
112 +
113 + @Override
114 + public int hashCode() {
115 + return Objects.hash(nodeID, interfaceID);
116 + }
117 +
118 + @Override
119 + public boolean equals(Object obj) {
120 + if (this == obj) {
121 + return true;
122 + }
123 + if (obj instanceof NexthopUnnumberedIPv4IDTlv) {
124 + NexthopUnnumberedIPv4IDTlv other = (NexthopUnnumberedIPv4IDTlv) obj;
125 + return Objects.equals(this.nodeID, other.nodeID) && Objects.equals(this.interfaceID, other.interfaceID);
126 + }
127 + return false;
128 + }
129 +
130 + @Override
131 + public int write(ChannelBuffer c) {
132 + int iLenStartIndex = c.writerIndex();
133 + c.writeShort(TYPE);
134 + c.writeShort(LENGTH);
135 +
136 + c.writeInt(nodeID);
137 + c.writeInt(interfaceID);
138 +
139 + return c.writerIndex() - iLenStartIndex;
140 + }
141 +
142 + /**
143 + * Reads the channel buffer and returns object of NexthopUnnumberedIPv4IDTlv.
144 + *
145 + * @param cb type of channel buffer
146 + * @return object of NexthopUnnumberedIPv4IDTlv
147 + */
148 + public static NexthopUnnumberedIPv4IDTlv read(ChannelBuffer cb) {
149 + int nodeID = cb.readInt();
150 + int interfaceID = cb.readInt();
151 + return new NexthopUnnumberedIPv4IDTlv(nodeID, interfaceID);
152 + }
153 +
154 + @Override
155 + public String toString() {
156 + return MoreObjects.toStringHelper(getClass()).add("Type", TYPE).add("Length", LENGTH).add("NodeId", nodeID)
157 + .add("InterfaceId", interfaceID).toString();
158 + }
159 +}