bharat saraswal
Committed by Gerrit Code Review

Implementation of PcInitate and PcUpdate messages

Change-Id: I746a5860a8b4a8022d747a02075ed3237741c53a
Showing 53 changed files with 4701 additions and 31 deletions
...@@ -15,3 +15,4 @@ dependency-reduced-pom.xml ...@@ -15,3 +15,4 @@ dependency-reduced-pom.xml
15 15
16 core/store/trivial/data/ 16 core/store/trivial/data/
17 core/store/apps 17 core/store/apps
18 +/bin/
......
...@@ -19,6 +19,7 @@ package org.onosproject.pcepio.protocol; ...@@ -19,6 +19,7 @@ package org.onosproject.pcepio.protocol;
19 import java.util.LinkedList; 19 import java.util.LinkedList;
20 20
21 import org.jboss.netty.buffer.ChannelBuffer; 21 import org.jboss.netty.buffer.ChannelBuffer;
22 +import org.onosproject.pcepio.exceptions.PcepParseException;
22 import org.onosproject.pcepio.types.PcepObjectHeader; 23 import org.onosproject.pcepio.types.PcepObjectHeader;
23 import org.onosproject.pcepio.types.PcepValueType; 24 import org.onosproject.pcepio.types.PcepValueType;
24 25
...@@ -62,7 +63,7 @@ public interface PcepCloseMsg extends PcepObject, PcepMessage { ...@@ -62,7 +63,7 @@ public interface PcepCloseMsg extends PcepObject, PcepMessage {
62 void setOptionalTlv(LinkedList<PcepValueType> llOptionalTlv); 63 void setOptionalTlv(LinkedList<PcepValueType> llOptionalTlv);
63 64
64 @Override 65 @Override
65 - void writeTo(ChannelBuffer channelBuffer); 66 + void writeTo(ChannelBuffer channelBuffer) throws PcepParseException;
66 67
67 /** 68 /**
68 * Builder interface with get and set functions to build Close message. 69 * Builder interface with get and set functions to build Close message.
......
...@@ -18,6 +18,7 @@ package org.onosproject.pcepio.protocol; ...@@ -18,6 +18,7 @@ package org.onosproject.pcepio.protocol;
18 18
19 import org.jboss.netty.buffer.ChannelBuffer; 19 import org.jboss.netty.buffer.ChannelBuffer;
20 import org.onosproject.pcepio.exceptions.PcepParseException; 20 import org.onosproject.pcepio.exceptions.PcepParseException;
21 +import org.onosproject.pcepio.protocol.ver1.PcepFactoryVer1;
21 import org.slf4j.Logger; 22 import org.slf4j.Logger;
22 import org.slf4j.LoggerFactory; 23 import org.slf4j.LoggerFactory;
23 24
...@@ -35,15 +36,15 @@ public final class PcepFactories { ...@@ -35,15 +36,15 @@ public final class PcepFactories {
35 /* 36 /*
36 * Returns the instance of PCEP Version. 37 * Returns the instance of PCEP Version.
37 * 38 *
38 - * @param version 39 + * @param version PCEP version
39 * @return PCEP version 40 * @return PCEP version
40 */ 41 */
41 public static PcepFactory getFactory(PcepVersion version) { 42 public static PcepFactory getFactory(PcepVersion version) {
42 switch (version) { 43 switch (version) {
43 case PCEP_1: 44 case PCEP_1:
44 - // TODO : to get the pcep version 1 factory 45 + return PcepFactoryVer1.INSTANCE;
45 default: 46 default:
46 - throw new IllegalArgumentException("[PcepFactory:]Unknown version: " + version); 47 + throw new IllegalArgumentException("Unknown version: " + version);
47 } 48 }
48 } 49 }
49 50
...@@ -53,7 +54,6 @@ public final class PcepFactories { ...@@ -53,7 +54,6 @@ public final class PcepFactories {
53 public PcepMessage readFrom(ChannelBuffer bb) throws PcepParseException { 54 public PcepMessage readFrom(ChannelBuffer bb) throws PcepParseException {
54 55
55 if (!bb.readable()) { 56 if (!bb.readable()) {
56 - log.debug("Empty message received");
57 throw new PcepParseException("Empty message received"); 57 throw new PcepParseException("Empty message received");
58 } 58 }
59 59
...@@ -75,13 +75,12 @@ public final class PcepFactories { ...@@ -75,13 +75,12 @@ public final class PcepFactories {
75 switch (packetVersion) { 75 switch (packetVersion) {
76 76
77 case 1: 77 case 1:
78 - // TODO : get the factory for version 1 78 + factory = org.onosproject.pcepio.protocol.ver1.PcepFactoryVer1.INSTANCE;
79 break; 79 break;
80 default: 80 default:
81 throw new IllegalArgumentException("Unknown Packet version: " + packetVersion); 81 throw new IllegalArgumentException("Unknown Packet version: " + packetVersion);
82 } 82 }
83 - // TODO : Read the PCEP message from the factory 83 + return factory.getReader().readFrom(bb);
84 - return null;
85 } 84 }
86 } 85 }
87 86
......
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.PcepBandwidthObject;
22 +import org.onosproject.pcepio.types.PcepObjectHeader;
23 +import org.slf4j.Logger;
24 +import org.slf4j.LoggerFactory;
25 +
26 +import com.google.common.base.MoreObjects;
27 +
28 +/**
29 + * Provides PcepBandwidthObject.
30 + */
31 +public class PcepBandwidthObjectVer1 implements PcepBandwidthObject {
32 +
33 + /*
34 + * RFC : 5440 , section : 7.7.
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 + | Bandwidth |
39 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
40 +
41 + The BANDWIDTH Object format
42 + */
43 +
44 + protected static final Logger log = LoggerFactory.getLogger(PcepBandwidthObjectVer1.class);
45 + /*
46 + * Requested bandwidth: BANDWIDTH Object-Type is 1.
47 + Bandwidth of an existing TE LSP for which a re-optimization is
48 + requested. BANDWIDTH Object-Type is 2.
49 + */
50 + //Right now handling type 1
51 + public static final byte BANDWIDTH_OBJ_TYPE = 1;
52 + public static final byte BANDWIDTH_OBJ_CLASS = 5;
53 + public static final byte BANDWIDTH_OBJECT_VERSION = 1;
54 + public static final short BANDWIDTH_OBJ_MINIMUM_LENGTH = 8;
55 +
56 + static final PcepObjectHeader DEFAULT_BANDWIDTH_OBJECT_HEADER = new PcepObjectHeader(BANDWIDTH_OBJ_CLASS,
57 + BANDWIDTH_OBJ_TYPE, PcepObjectHeader.REQ_OBJ_OPTIONAL_PROCESS, PcepObjectHeader.RSP_OBJ_PROCESSED,
58 + BANDWIDTH_OBJ_MINIMUM_LENGTH);
59 +
60 + private PcepObjectHeader bandwidthObjHeader;
61 + private int iBandwidth;
62 +
63 + /**
64 + * Constructor to bandwidth object header and bandwidth.
65 + *
66 + * @param bandwidthObjHeader bandwidth object header
67 + * @param iBandwidth bandwidth value
68 + */
69 + public PcepBandwidthObjectVer1(PcepObjectHeader bandwidthObjHeader, int iBandwidth) {
70 + this.bandwidthObjHeader = bandwidthObjHeader;
71 + this.iBandwidth = iBandwidth;
72 + }
73 +
74 + /**
75 + * Constructor to initialize bandwidth.
76 + *
77 + * @param iBandwidth bandwidth value
78 + */
79 + public PcepBandwidthObjectVer1(int iBandwidth) {
80 + this.bandwidthObjHeader = DEFAULT_BANDWIDTH_OBJECT_HEADER;
81 + this.iBandwidth = iBandwidth;
82 + }
83 +
84 + /**
85 + * Returns Object Header.
86 + *
87 + * @return bandwidthObjHeader
88 + */
89 + public PcepObjectHeader getBandwidthObjHeader() {
90 + return this.bandwidthObjHeader;
91 + }
92 +
93 + /**
94 + * Sets Object Header.
95 + *
96 + * @param obj bandwidth object header
97 + */
98 + public void setBandwidthObjHeader(PcepObjectHeader obj) {
99 + this.bandwidthObjHeader = obj;
100 + }
101 +
102 + @Override
103 + public int getBandwidth() {
104 + return this.iBandwidth;
105 + }
106 +
107 + @Override
108 + public void setBandwidth(int iBandwidth) {
109 + this.iBandwidth = iBandwidth;
110 + }
111 +
112 + /**
113 + * Reads from channel buffer and returns object of PcepBandwidthObject.
114 + *
115 + * @param cb channel buffer to parse
116 + * @return object of PcepBandwidthObject
117 + * @throws PcepParseException while parsing channel buffer
118 + */
119 + public static PcepBandwidthObject read(ChannelBuffer cb) throws PcepParseException {
120 +
121 + PcepObjectHeader bandwidthObjHeader;
122 + int iBandwidth;
123 +
124 + bandwidthObjHeader = PcepObjectHeader.read(cb);
125 + iBandwidth = cb.readInt();
126 +
127 + return new PcepBandwidthObjectVer1(bandwidthObjHeader, iBandwidth);
128 + }
129 +
130 + @Override
131 + public int write(ChannelBuffer cb) throws PcepParseException {
132 +
133 + //write Object header
134 + int objStartIndex = cb.writerIndex();
135 + int objLenIndex = bandwidthObjHeader.write(cb);
136 +
137 + if (objLenIndex <= 0) {
138 + throw new PcepParseException("Failed to write bandwidth object header. Index " + objLenIndex);
139 + }
140 +
141 + cb.writeInt(iBandwidth);
142 + short hLength = (short) (cb.writerIndex() - objStartIndex);
143 + cb.setShort(objLenIndex, hLength);
144 + //will be helpful during print().
145 + bandwidthObjHeader.setObjLen(hLength);
146 +
147 + return cb.writerIndex() - objStartIndex;
148 + }
149 +
150 + /**
151 + * builder class for PCEP bandwidth object.
152 + */
153 + public static class Builder implements PcepBandwidthObject.Builder {
154 +
155 + private PcepObjectHeader bandwidthObjHeader;
156 + private boolean bIsHeaderSet = false;
157 +
158 + private int iBandwidth;
159 + private boolean bIsBandwidthSet = false;
160 +
161 + private boolean bPFlag;
162 + private boolean bIsPFlagSet = false;
163 +
164 + private boolean bIFlag;
165 + private boolean bIsIFlagSet = false;
166 +
167 + @Override
168 + public PcepBandwidthObject build() throws PcepParseException {
169 +
170 + PcepObjectHeader bandwidthObjHeader = this.bIsHeaderSet ? this.bandwidthObjHeader
171 + : DEFAULT_BANDWIDTH_OBJECT_HEADER;
172 +
173 + if (bIsPFlagSet) {
174 + bandwidthObjHeader.setPFlag(bPFlag);
175 + }
176 +
177 + if (bIsIFlagSet) {
178 + bandwidthObjHeader.setIFlag(bIFlag);
179 + }
180 +
181 + if (!this.bIsBandwidthSet) {
182 + throw new PcepParseException("bandwidth not Set while building Bandwidth Object.");
183 + }
184 +
185 + return new PcepBandwidthObjectVer1(bandwidthObjHeader, iBandwidth);
186 + }
187 +
188 + @Override
189 + public int getBandwidth() {
190 + return this.iBandwidth;
191 + }
192 +
193 + @Override
194 + public PcepObjectHeader getBandwidthObjHeader() {
195 + return this.bandwidthObjHeader;
196 + }
197 +
198 + @Override
199 + public Builder setBandwidthObjHeader(PcepObjectHeader obj) {
200 + this.bandwidthObjHeader = obj;
201 + return this;
202 + }
203 +
204 + @Override
205 + public Builder setBandwidth(int iBandwidth) {
206 + this.iBandwidth = iBandwidth;
207 + this.bIsBandwidthSet = true;
208 + return this;
209 + }
210 +
211 + @Override
212 + public Builder setPFlag(boolean value) {
213 + this.bPFlag = value;
214 + this.bIsPFlagSet = true;
215 + return this;
216 + }
217 +
218 + @Override
219 + public Builder setIFlag(boolean value) {
220 + this.bIFlag = value;
221 + this.bIsIFlagSet = true;
222 + return this;
223 + }
224 +
225 + }
226 +
227 + @Override
228 + public void print() {
229 +
230 + log.debug("BANDWIDTH OBJECT");
231 + bandwidthObjHeader.print();
232 + log.debug("Bandwidth: " + iBandwidth);
233 + }
234 +
235 + @Override
236 + public String toString() {
237 + return MoreObjects.toStringHelper(getClass())
238 + .add("bandwidth Object Header", bandwidthObjHeader)
239 + .add("Bandwidth", iBandwidth)
240 + .toString();
241 + }
242 +}
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.PcepEndPointsObject;
22 +import org.onosproject.pcepio.types.PcepObjectHeader;
23 +import org.slf4j.Logger;
24 +import org.slf4j.LoggerFactory;
25 +
26 +import com.google.common.base.MoreObjects;
27 +
28 +public class PcepEndPointsObjectVer1 implements PcepEndPointsObject {
29 +
30 + /*
31 + * RFC : 5440 , section : 7.6
32 + * An End point is defined as follows:
33 + END-POINTS Object-Class is 4.
34 +
35 + END-POINTS Object-Type is 1 for IPv4 and 2 for IPv6.
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 + | Object-Class | OT |Res|P|I| Object Length (bytes) |
40 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
41 + | Source IPv4 address |
42 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
43 + | Destination IPv4 address |
44 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
45 +
46 + */
47 + protected static final Logger log = LoggerFactory.getLogger(PcepEndPointsObjectVer1.class);
48 +
49 + static final byte END_POINTS_OBJ_TYPE = 1;
50 + static final byte END_POINTS_OBJ_CLASS = 4;
51 + static final byte END_POINTS_OBJECT_VERSION = 1;
52 + static final short END_POINTS_OBJ_MINIMUM_LENGTH = 12;
53 + public static byte endPointObjType;
54 +
55 + static final PcepObjectHeader DEFAULT_END_POINTS_OBJECT_HEADER = new PcepObjectHeader(END_POINTS_OBJ_CLASS,
56 + END_POINTS_OBJ_TYPE, PcepObjectHeader.REQ_OBJ_OPTIONAL_PROCESS, PcepObjectHeader.RSP_OBJ_PROCESSED,
57 + END_POINTS_OBJ_MINIMUM_LENGTH);
58 +
59 + private PcepObjectHeader endPointsObjHeader;
60 + public int sourceIpAddress;
61 + public int destIpAddress;
62 +
63 + /**
64 + * Constructor to initialize all variables.
65 + *
66 + * @param endPointsObjHeader end points object header
67 + * @param sourceIpAddress source IP address
68 + * @param destIpAddress destination IP address
69 + */
70 + public PcepEndPointsObjectVer1(PcepObjectHeader endPointsObjHeader, int sourceIpAddress, int destIpAddress) {
71 +
72 + this.endPointsObjHeader = endPointsObjHeader;
73 + this.sourceIpAddress = sourceIpAddress;
74 + this.destIpAddress = destIpAddress;
75 + }
76 +
77 + /**
78 + * Sets End Points Object Header.
79 + *
80 + * @param obj of PcepObjectHeader
81 + */
82 + public void setEndPointsObjHeader(PcepObjectHeader obj) {
83 + this.endPointsObjHeader = obj;
84 + }
85 +
86 + @Override
87 + public void setSourceIpAddress(int sourceIpAddress) {
88 + this.sourceIpAddress = sourceIpAddress;
89 + }
90 +
91 + @Override
92 + public void setDestIpAddress(int destIpAddress) {
93 + this.destIpAddress = destIpAddress;
94 + }
95 +
96 + @Override
97 + public int getSourceIpAddress() {
98 + return this.sourceIpAddress;
99 + }
100 +
101 + @Override
102 + public int getDestIpAddress() {
103 + return this.destIpAddress;
104 + }
105 +
106 + /**
107 + * Reads from channel buffer and returns object of PcepEndPointsObject.
108 + *
109 + * @param cb of channel buffer
110 + * @return object of PcepEndPointsObject
111 + * @throws PcepParseException while parsing channel buffer
112 + */
113 + public static PcepEndPointsObject read(ChannelBuffer cb) throws PcepParseException {
114 +
115 + PcepObjectHeader endPointsObjHeader;
116 + int sourceIpAddress;
117 + int destIpAddress;
118 +
119 + endPointsObjHeader = PcepObjectHeader.read(cb);
120 + if (END_POINTS_OBJ_TYPE == endPointsObjHeader.getObjType()
121 + && END_POINTS_OBJ_CLASS == endPointsObjHeader.getObjClass()) {
122 + sourceIpAddress = cb.readInt();
123 + destIpAddress = cb.readInt();
124 + } else {
125 + throw new PcepParseException("Expected PcepEndPointsObject.");
126 + }
127 + return new PcepEndPointsObjectVer1(endPointsObjHeader, sourceIpAddress, destIpAddress);
128 + }
129 +
130 + @Override
131 + public int write(ChannelBuffer cb) throws PcepParseException {
132 +
133 + int objStartIndex = cb.writerIndex();
134 + //write common header
135 + int objLenIndex = endPointsObjHeader.write(cb);
136 +
137 + //write source IPv4 IP
138 + cb.writeInt(sourceIpAddress);
139 + //write destination IPv4 IP
140 + cb.writeInt(destIpAddress);
141 +
142 + int length = cb.writerIndex() - objStartIndex;
143 + //now write EndPoints Object Length
144 + cb.setShort(objLenIndex, (short) length);
145 + //will be helpful during print().
146 + endPointsObjHeader.setObjLen((short) length);
147 +
148 + return cb.writerIndex();
149 +
150 + }
151 +
152 + /**
153 + * Builder class for PCEP end points objects.
154 + */
155 + public static class Builder implements PcepEndPointsObject.Builder {
156 +
157 + private boolean bIsHeaderSet = false;
158 + private boolean bIsSourceIpAddressset = false;
159 + private boolean bIsDestIpAddressset = false;
160 + private PcepObjectHeader endpointsObjHeader;
161 + private int sourceIpAddress;
162 + private int destIpAddress;
163 +
164 + private boolean bIsPFlagSet = false;
165 + private boolean bPFlag;
166 +
167 + private boolean bIsIFlagSet = false;
168 + private boolean bIFlag;
169 +
170 + @Override
171 + public PcepEndPointsObject build() throws PcepParseException {
172 +
173 + PcepObjectHeader endpointsObjHeader = this.bIsHeaderSet ? this.endpointsObjHeader
174 + : DEFAULT_END_POINTS_OBJECT_HEADER;
175 +
176 + if (bIsPFlagSet) {
177 + endpointsObjHeader.setPFlag(bPFlag);
178 + }
179 +
180 + if (bIsIFlagSet) {
181 + endpointsObjHeader.setIFlag(bIFlag);
182 + }
183 +
184 + if (!this.bIsSourceIpAddressset) {
185 + throw new PcepParseException("SourceIpAddress not set while building EndPoints object");
186 + }
187 +
188 + if (!this.bIsDestIpAddressset) {
189 + throw new PcepParseException("DestIpAddress not set while building EndPoints object");
190 + }
191 +
192 + return new PcepEndPointsObjectVer1(endpointsObjHeader, this.sourceIpAddress, this.destIpAddress);
193 + }
194 +
195 + @Override
196 + public PcepObjectHeader getEndPointsObjHeader() {
197 + return this.endpointsObjHeader;
198 + }
199 +
200 + @Override
201 + public Builder setEndPointsObjHeader(PcepObjectHeader obj) {
202 + this.endpointsObjHeader = obj;
203 + this.bIsHeaderSet = true;
204 + return this;
205 + }
206 +
207 + @Override
208 + public int getSourceIpAddress() {
209 + return this.sourceIpAddress;
210 + }
211 +
212 + @Override
213 + public Builder setSourceIpAddress(int sourceIpAddress) {
214 + this.sourceIpAddress = sourceIpAddress;
215 + this.bIsSourceIpAddressset = true;
216 + return this;
217 + }
218 +
219 + @Override
220 + public int getDestIpAddress() {
221 + return this.destIpAddress;
222 + }
223 +
224 + @Override
225 + public Builder setDestIpAddress(int destIpAddress) {
226 + this.destIpAddress = destIpAddress;
227 + this.bIsDestIpAddressset = true;
228 + return this;
229 + }
230 +
231 + @Override
232 + public Builder setPFlag(boolean value) {
233 + this.bPFlag = value;
234 + this.bIsPFlagSet = true;
235 + return this;
236 + }
237 +
238 + @Override
239 + public Builder setIFlag(boolean value) {
240 + this.bIFlag = value;
241 + this.bIsIFlagSet = true;
242 + return this;
243 + }
244 +
245 + }
246 +
247 + @Override
248 + public void print() {
249 +
250 + log.debug("ENDPOINT OBJECT");
251 + long lTemp;
252 + lTemp = sourceIpAddress & 0xFFFFFFFF;
253 + String str = "Source IP Address: " + lTemp;
254 + log.debug(str);
255 + lTemp = destIpAddress & 0xFFFFFFFF;
256 + str = "destination IP Address: " + lTemp;
257 + log.debug(str);
258 + }
259 +
260 + @Override
261 + public String toString() {
262 + return MoreObjects.toStringHelper(getClass())
263 + .add("sourceIpAddress", sourceIpAddress)
264 + .add("destIpAddress", destIpAddress)
265 + .toString();
266 + }
267 +
268 +}
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.onosproject.pcepio.protocol.PcInitiatedLspRequest;
20 +import org.onosproject.pcepio.protocol.PcepAttribute;
21 +import org.onosproject.pcepio.protocol.PcepBandwidthObject;
22 +import org.onosproject.pcepio.protocol.PcepCloseMsg;
23 +import org.onosproject.pcepio.protocol.PcepEndPointsObject;
24 +import org.onosproject.pcepio.protocol.PcepEroObject;
25 +import org.onosproject.pcepio.protocol.PcepFactory;
26 +import org.onosproject.pcepio.protocol.PcepInitiateMsg;
27 +import org.onosproject.pcepio.protocol.PcepKeepaliveMsg;
28 +import org.onosproject.pcepio.protocol.PcepLspObject;
29 +import org.onosproject.pcepio.protocol.PcepLspaObject;
30 +import org.onosproject.pcepio.protocol.PcepMessage;
31 +import org.onosproject.pcepio.protocol.PcepMessageReader;
32 +import org.onosproject.pcepio.protocol.PcepMetricObject;
33 +import org.onosproject.pcepio.protocol.PcepMsgPath;
34 +
35 +import org.onosproject.pcepio.protocol.PcepSrpObject;
36 +import org.onosproject.pcepio.protocol.PcepUpdateMsg;
37 +import org.onosproject.pcepio.protocol.PcepUpdateRequest;
38 +import org.onosproject.pcepio.protocol.PcepVersion;
39 +
40 +public class PcepFactoryVer1 implements PcepFactory {
41 +
42 + public static final PcepFactoryVer1 INSTANCE = new PcepFactoryVer1();
43 +
44 + @Override
45 + public org.onosproject.pcepio.protocol.PcepOpenMsg.Builder buildOpenMsg() {
46 + // TODO Auto-generated method stub
47 + return null;
48 + }
49 +
50 + @Override
51 + public org.onosproject.pcepio.protocol.PcepOpenObject.Builder buildOpenObject() {
52 + // TODO Auto-generated method stub
53 + return null;
54 + }
55 +
56 + @Override
57 + public PcepKeepaliveMsg.Builder buildKeepaliveMsg() {
58 + return new PcepKeepaliveMsgVer1.Builder();
59 + }
60 +
61 + @Override
62 + public PcepCloseMsg.Builder buildCloseMsg() {
63 + return new PcepCloseMsgVer1.Builder();
64 + }
65 +
66 + @Override
67 + public PcepUpdateMsg.Builder buildUpdateMsg() {
68 + return new PcepUpdateMsgVer1.Builder();
69 + }
70 +
71 + @Override
72 + public org.onosproject.pcepio.protocol.PcepReportMsg.Builder buildReportMsg() {
73 + // TODO Auto-generated method stub
74 + return null;
75 + }
76 +
77 + @Override
78 + public PcepInitiateMsg.Builder buildPcepInitiateMsg() {
79 + return new PcepInitiateMsgVer1.Builder();
80 + }
81 +
82 + @Override
83 + public PcepLspObject.Builder buildLspObject() {
84 + return new PcepLspObjectVer1.Builder();
85 + }
86 +
87 + @Override
88 + public PcepMessageReader<PcepMessage> getReader() {
89 + return PcepMessageVer1.READER;
90 + }
91 +
92 + @Override
93 + public PcepVersion getVersion() {
94 + return PcepVersion.PCEP_1;
95 + }
96 +
97 + @Override
98 + public PcepSrpObject.Builder buildSrpObject() {
99 + return new PcepSrpObjectVer1.Builder();
100 + }
101 +
102 + @Override
103 + public PcepEndPointsObject.Builder buildEndPointsObject() {
104 + return new PcepEndPointsObjectVer1.Builder();
105 + }
106 +
107 + @Override
108 + public PcepEroObject.Builder buildEroObject() {
109 + return new PcepEroObjectVer1.Builder();
110 + }
111 +
112 + @Override
113 + public org.onosproject.pcepio.protocol.PcepRroObject.Builder buildRroObject() {
114 + // TODO Auto-generated method stub
115 + return null;
116 + }
117 +
118 + @Override
119 + public PcepLspaObject.Builder buildLspaObject() {
120 + return new PcepLspaObjectVer1.Builder();
121 + }
122 +
123 + @Override
124 + public org.onosproject.pcepio.protocol.PcepIroObject.Builder buildIroObject() {
125 + // TODO Auto-generated method stub
126 + return null;
127 + }
128 +
129 + @Override
130 + public PcepMetricObject.Builder buildMetricObject() {
131 + return new PcepMetricObjectVer1.Builder();
132 + }
133 +
134 + @Override
135 + public PcepBandwidthObject.Builder buildBandwidthObject() {
136 + return new PcepBandwidthObjectVer1.Builder();
137 + }
138 +
139 + @Override
140 + public PcepMsgPath.Builder buildPcepMsgPath() {
141 + return new PcepMsgPathVer1.Builder();
142 + }
143 +
144 + @Override
145 + public org.onosproject.pcepio.protocol.PcepStateReport.Builder buildPcepStateReport() {
146 + // TODO Auto-generated method stub
147 + return null;
148 + }
149 +
150 + @Override
151 + public PcepUpdateRequest.Builder buildPcepUpdateRequest() {
152 + return new PcepUpdateRequestVer1.Builder();
153 + }
154 +
155 + @Override
156 + public PcInitiatedLspRequest.Builder buildPcInitiatedLspRequest() {
157 + return new PcInitiatedLspRequestVer1.Builder();
158 + }
159 +
160 + @Override
161 + public PcepAttribute.Builder buildPcepAttribute() {
162 + return new PcepAttributeVer1.Builder();
163 + }
164 +
165 + @Override
166 + public org.onosproject.pcepio.protocol.PcepLabelUpdateMsg.Builder buildPcepLabelUpdateMsg() {
167 + // TODO Auto-generated method stub
168 + return null;
169 + }
170 +
171 + @Override
172 + public org.onosproject.pcepio.protocol.PcepLabelUpdate.Builder buildPcepLabelUpdateObject() {
173 + // TODO Auto-generated method stub
174 + return null;
175 + }
176 +
177 + @Override
178 + public org.onosproject.pcepio.protocol.PcepLabelObject.Builder buildLabelObject() {
179 + // TODO Auto-generated method stub
180 + return null;
181 + }
182 +
183 + @Override
184 + public org.onosproject.pcepio.protocol.PcepErrorMsg.Builder buildPcepErrorMsg() {
185 + // TODO Auto-generated method stub
186 + return null;
187 + }
188 +
189 + @Override
190 + public org.onosproject.pcepio.protocol.PcepErrorObject.Builder buildPcepErrorObject() {
191 + // TODO Auto-generated method stub
192 + return null;
193 + }
194 +
195 + @Override
196 + public org.onosproject.pcepio.protocol.PcepFecObjectIPv4Adjacency.Builder buildFecIpv4Adjacency() {
197 + // TODO Auto-generated method stub
198 + return null;
199 + }
200 +
201 + @Override
202 + public org.onosproject.pcepio.protocol.PcepErrorInfo.Builder buildPcepErrorInfo() {
203 + // TODO Auto-generated method stub
204 + return null;
205 + }
206 +
207 + @Override
208 + public org.onosproject.pcepio.protocol.PcepError.Builder buildPcepError() {
209 + // TODO Auto-generated method stub
210 + return null;
211 + }
212 +
213 +}
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.PcepIroObject;
25 +import org.onosproject.pcepio.types.IPv4SubObject;
26 +import org.onosproject.pcepio.types.PcepObjectHeader;
27 +import org.onosproject.pcepio.types.PcepValueType;
28 +import org.slf4j.Logger;
29 +import org.slf4j.LoggerFactory;
30 +
31 +import com.google.common.base.MoreObjects;
32 +
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 + // (Sub-objects) //
39 + | |
40 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
41 +
42 + The IRO Object format
43 +
44 + Each IPV4 suboject
45 +
46 + 0 1 2 3
47 + 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
48 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
49 + |L| Type | Length | IPv4 address (4 bytes) |
50 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
51 + | IPv4 address (continued) | Prefix Length | Resvd |
52 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
53 + */
54 +public class PcepIroObjectVer1 implements PcepIroObject {
55 +
56 + protected static final Logger log = LoggerFactory.getLogger(PcepIroObjectVer1.class);
57 +
58 + public static final byte IRO_OBJ_TYPE = 1;
59 + public static final byte IRO_OBJ_CLASS = 10;
60 + public static final byte IRO_OBJECT_VERSION = 1;
61 + public static final short IRO_OBJ_MINIMUM_LENGTH = 12;
62 + public static final int OBJECT_HEADER_LENGTH = 4;
63 + public static final int YTYPE_SHIFT_VALUE = 0x7F;
64 +
65 + public static final PcepObjectHeader DEFAULT_IRO_OBJECT_HEADER = new PcepObjectHeader(IRO_OBJ_CLASS, IRO_OBJ_TYPE,
66 + PcepObjectHeader.REQ_OBJ_OPTIONAL_PROCESS, PcepObjectHeader.RSP_OBJ_PROCESSED, IRO_OBJ_MINIMUM_LENGTH);
67 +
68 + private short iroObjType = 0;
69 + private byte yLength;
70 + private byte yPrefixLength;
71 + private byte yResvd;
72 + private PcepObjectHeader iroObjHeader;
73 + private LinkedList<PcepValueType> llSubObjects = new LinkedList<PcepValueType>();
74 +
75 + /**
76 + * Default constructor.
77 + */
78 + public PcepIroObjectVer1() {
79 + this.iroObjHeader = null;
80 + this.iroObjType = 0;
81 + this.yLength = 0;
82 + }
83 +
84 + /**
85 + * Constructor to initialize member variables.
86 + *
87 + * @param iroObjHeader IRO object header
88 + * @param llSubObjects list of sub-objects
89 + */
90 + public PcepIroObjectVer1(PcepObjectHeader iroObjHeader, LinkedList<PcepValueType> llSubObjects) {
91 + this.iroObjHeader = iroObjHeader;
92 + this.llSubObjects = llSubObjects;
93 + }
94 +
95 + /**
96 + * Returns object header.
97 + *
98 + * @return iroObjHeader IRO object header
99 + */
100 + public PcepObjectHeader getIroObjHeader() {
101 + return this.iroObjHeader;
102 + }
103 +
104 + /**
105 + * Sets IRO Object Header.
106 + *
107 + * @param obj IRO object header
108 + */
109 + public void setIroObjHeader(PcepObjectHeader obj) {
110 + this.iroObjHeader = obj;
111 + }
112 +
113 + @Override
114 + public LinkedList<PcepValueType> getSubObjects() {
115 + return this.llSubObjects;
116 + }
117 +
118 + @Override
119 + public void setSubObjects(LinkedList<PcepValueType> llSubObjects) {
120 + this.llSubObjects = llSubObjects;
121 + }
122 +
123 + /**
124 + * Reads from channel buffer and return object of PcepIroObject.
125 + *
126 + * @param cb of type channel buffer
127 + * @return object of PcepIroObject
128 + * @throws PcepParseException while parsing from channel buffer
129 + */
130 + public static PcepIroObject read(ChannelBuffer cb) throws PcepParseException {
131 +
132 + PcepObjectHeader iroObjHeader;
133 + LinkedList<PcepValueType> llSubObjects;
134 +
135 + iroObjHeader = PcepObjectHeader.read(cb);
136 +
137 + //take only IroObject buffer.
138 + ChannelBuffer tempCb = cb.readBytes(iroObjHeader.getObjLen() - OBJECT_HEADER_LENGTH);
139 + llSubObjects = parseSubObjects(tempCb);
140 + return new PcepIroObjectVer1(iroObjHeader, llSubObjects);
141 + }
142 +
143 + /**
144 + * Returns linked list of sub objects.
145 + *
146 + * @param cb of type channel buffer
147 + * @return linked list of sub objects
148 + * @throws PcepParseException while parsing subobjects from channel buffer
149 + */
150 + protected static LinkedList<PcepValueType> parseSubObjects(ChannelBuffer cb) throws PcepParseException {
151 +
152 + LinkedList<PcepValueType> llSubObjects = new LinkedList<PcepValueType>();
153 +
154 + while (0 < cb.readableBytes()) {
155 +
156 + //check the Type of the Subobjects.
157 + byte yType = cb.readByte();
158 + yType = (byte) (yType & (YTYPE_SHIFT_VALUE));
159 + byte hLength = cb.readByte();
160 +
161 + PcepValueType subObj;
162 + switch (yType) {
163 +
164 + case IPv4SubObject.TYPE:
165 + subObj = IPv4SubObject.read(cb);
166 + break;
167 +
168 + default:
169 + throw new PcepParseException("Invalid sub object. Type: " + (int) yType);
170 + }
171 +
172 + // Check for the padding
173 + int pad = hLength % 4;
174 + if (0 < pad) {
175 + pad = 4 - pad;
176 + if (pad <= cb.readableBytes()) {
177 + cb.skipBytes(pad);
178 + }
179 + }
180 + llSubObjects.add(subObj);
181 + }
182 + return llSubObjects;
183 + }
184 +
185 + @Override
186 + public int write(ChannelBuffer cb) throws PcepParseException {
187 + //write Object header
188 + int objStartIndex = cb.writerIndex();
189 +
190 + int objLenIndex = iroObjHeader.write(cb);
191 +
192 + if (objLenIndex <= 0) {
193 + throw new PcepParseException(" ObjectLength is " + objLenIndex);
194 + }
195 +
196 + ListIterator<PcepValueType> listIterator = llSubObjects.listIterator();
197 + while (listIterator.hasNext()) {
198 + listIterator.next().write(cb);
199 + }
200 +
201 + //Update object length now
202 + int length = cb.writerIndex() - objStartIndex;
203 + //will be helpful during print().
204 + iroObjHeader.setObjLen((short) length);
205 + // As per RFC the length of object should be
206 + // multiples of 4
207 + int pad = length % 4;
208 + if (pad != 0) {
209 + pad = 4 - pad;
210 + for (int i = 0; i < pad; i++) {
211 + cb.writeByte((byte) 0);
212 + }
213 + length = length + pad;
214 + }
215 + cb.setShort(objLenIndex, (short) length);
216 + objLenIndex = cb.writerIndex();
217 + return objLenIndex;
218 + }
219 +
220 + public static class Builder implements PcepIroObject.Builder {
221 +
222 + private boolean bIsHeaderSet = false;
223 +
224 + private PcepObjectHeader iroObjHeader;
225 + LinkedList<PcepValueType> llSubObjects = new LinkedList<PcepValueType>();
226 +
227 + private boolean bIsPFlagSet = false;
228 + private boolean bPFlag;
229 +
230 + private boolean bIsIFlagSet = false;
231 + private boolean bIFlag;
232 +
233 + @Override
234 + public PcepIroObject build() {
235 +
236 + PcepObjectHeader iroObjHeader = this.bIsHeaderSet ? this.iroObjHeader : DEFAULT_IRO_OBJECT_HEADER;
237 +
238 + if (bIsPFlagSet) {
239 + iroObjHeader.setPFlag(bPFlag);
240 + }
241 +
242 + if (bIsIFlagSet) {
243 + iroObjHeader.setIFlag(bIFlag);
244 + }
245 +
246 + return new PcepIroObjectVer1(iroObjHeader, this.llSubObjects);
247 + }
248 +
249 + @Override
250 + public PcepObjectHeader getIroObjHeader() {
251 + return this.iroObjHeader;
252 + }
253 +
254 + @Override
255 + public Builder setIroObjHeader(PcepObjectHeader obj) {
256 + this.iroObjHeader = obj;
257 + this.bIsHeaderSet = true;
258 + return this;
259 + }
260 +
261 + @Override
262 + public LinkedList<PcepValueType> getSubObjects() {
263 + return this.llSubObjects;
264 + }
265 +
266 + @Override
267 + public Builder setSubObjects(LinkedList<PcepValueType> llSubObjects) {
268 + this.llSubObjects = llSubObjects;
269 + return this;
270 + }
271 +
272 + @Override
273 + public Builder setPFlag(boolean value) {
274 + this.bPFlag = value;
275 + this.bIsPFlagSet = true;
276 + return this;
277 + }
278 +
279 + @Override
280 + public Builder setIFlag(boolean value) {
281 + this.bIFlag = value;
282 + this.bIsIFlagSet = true;
283 + return this;
284 + }
285 +
286 + }
287 +
288 + @Override
289 + public void print() {
290 + log.debug("IRO OBJECT");
291 + iroObjHeader.print();
292 + log.debug("SUBOBJECTS:");
293 + ListIterator<PcepValueType> listIterator = llSubObjects.listIterator();
294 + while (listIterator.hasNext()) {
295 + listIterator.next().print();
296 + }
297 + }
298 +
299 + @Override
300 + public String toString() {
301 + return MoreObjects.toStringHelper(getClass())
302 + .add("IRO object header", iroObjHeader)
303 + .add("List of sub object", llSubObjects)
304 + .toString();
305 + }
306 +}
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.PcepKeepaliveMsg;
22 +import org.onosproject.pcepio.protocol.PcepMessageReader;
23 +import org.onosproject.pcepio.protocol.PcepMessageWriter;
24 +import org.onosproject.pcepio.protocol.PcepType;
25 +import org.onosproject.pcepio.protocol.PcepVersion;
26 +import org.slf4j.Logger;
27 +import org.slf4j.LoggerFactory;
28 +
29 +class PcepKeepaliveMsgVer1 implements PcepKeepaliveMsg {
30 +
31 + /*
32 + <Keepalive Message>::= <Common Header>
33 +
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 + | Ver | Flags | Message-Type | Message-Length |
37 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
38 + */
39 +
40 + protected static final Logger log = LoggerFactory.getLogger(PcepKeepaliveMsgVer1.class);
41 + // Pcep version: 1
42 + public static final byte PACKET_VERSION = 1;
43 + public static final int PACKET_MINIMUM_LENGTH = 4;
44 + public static final PcepType MSG_TYPE = PcepType.KEEP_ALIVE;
45 +
46 + public static final PcepKeepaliveMsgVer1.Reader READER = new Reader();
47 +
48 + static class Reader implements PcepMessageReader<PcepKeepaliveMsg> {
49 +
50 + @Override
51 + public PcepKeepaliveMsg readFrom(ChannelBuffer cb) throws PcepParseException {
52 +
53 + if (cb.readableBytes() < PACKET_MINIMUM_LENGTH) {
54 + throw new PcepParseException("Packet size is less than the minimum required length.");
55 + }
56 + // fixed value property version == 1
57 + byte version = cb.readByte();
58 + version = (byte) (version >> PcepMessageVer1.SHIFT_FLAG);
59 + if (version != PACKET_VERSION) {
60 + throw new PcepParseException("Wrong version: Expected=PcepVersion.KEEP_ALIVE_1(2), got=" + version);
61 + }
62 + // fixed value property type == 2
63 + byte type = cb.readByte();
64 + if (type != MSG_TYPE.getType()) {
65 + throw new PcepParseException("Wrong type: Expected=PcepType.KEEP_ALIVE_1(2), got=" + type);
66 + }
67 + short length = cb.readShort();
68 + if (length < PACKET_MINIMUM_LENGTH) {
69 + throw new PcepParseException("Wrong length: Expected to be >= " + PACKET_MINIMUM_LENGTH + ", was: "
70 + + length);
71 + }
72 + return new PcepKeepaliveMsgVer1();
73 + }
74 + }
75 +
76 + /**
77 + * Default constructor.
78 + */
79 + PcepKeepaliveMsgVer1() {
80 + }
81 +
82 + static class Builder implements PcepKeepaliveMsg.Builder {
83 + @Override
84 + public PcepVersion getVersion() {
85 + return PcepVersion.PCEP_1;
86 + }
87 +
88 + @Override
89 + public PcepType getType() {
90 + return PcepType.KEEP_ALIVE;
91 + }
92 +
93 + @Override
94 + public PcepKeepaliveMsg build() {
95 + return new PcepKeepaliveMsgVer1();
96 + }
97 + }
98 +
99 + @Override
100 + public void writeTo(ChannelBuffer cb) {
101 + WRITER.write(cb, this);
102 + }
103 +
104 + static final Writer WRITER = new Writer();
105 +
106 + static class Writer implements PcepMessageWriter<PcepKeepaliveMsgVer1> {
107 +
108 + @Override
109 + public void write(ChannelBuffer cb, PcepKeepaliveMsgVer1 message) {
110 + int startIndex = cb.writerIndex();
111 + // first 3 bits set to version
112 + cb.writeByte((byte) (PACKET_VERSION << PcepMessageVer1.SHIFT_FLAG));
113 + // message type
114 + cb.writeByte(MSG_TYPE.getType());
115 + // length is length of variable message, will be updated at the end
116 + // Store the position of message
117 + // length in buffer
118 + int msgLenIndex = cb.writerIndex();
119 + cb.writeShort((short) 0);
120 + // update message length field
121 + int length = cb.writerIndex() - startIndex;
122 + cb.setShort(msgLenIndex, (short) length);
123 + }
124 + }
125 +
126 + @Override
127 + public PcepVersion getVersion() {
128 + return PcepVersion.PCEP_1;
129 + }
130 +
131 + @Override
132 + public PcepType getType() {
133 + return MSG_TYPE;
134 + }
135 +
136 + @Override
137 + public void print() {
138 + log.debug("KEEPALIVE MESSAGE");
139 + }
140 +}
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.PcepFactories;
22 +import org.onosproject.pcepio.protocol.PcepMessage;
23 +import org.onosproject.pcepio.protocol.PcepMessageReader;
24 +import org.onosproject.pcepio.types.PcepErrorDetailInfo;
25 +import org.slf4j.Logger;
26 +import org.slf4j.LoggerFactory;
27 +
28 +public abstract class PcepMessageVer1 {
29 +
30 + protected static final Logger log = LoggerFactory.getLogger(PcepFactories.class);
31 +
32 + // version: 1.0
33 + static final byte WIRE_VERSION = 1;
34 + static final int MINIMUM_LENGTH = 4;
35 + static final int PACKET_VERSION = 1;
36 + static final byte OPEN_MSG_TYPE = 0x1;
37 + static final byte KEEPALIVE_MSG_TYPE = 0x2;
38 + static final byte REPORT_MSG_TYPE = 0xa;
39 + static final byte TE_REPORT_MSG_TYPE = 0xe;
40 + static final byte UPDATE_MSG_TYPE = 0xb;
41 + static final byte INITIATE_MSG_TYPE = 0xc;
42 + static final byte CLOSE_MSG_TYPE = 0x7;
43 + static final byte ERROR_MSG_TYPE = 0x6;
44 + static final byte LABEL_UPDATE_MSG_TYPE = 0xD;
45 + public static final int SHIFT_FLAG = 5;
46 + static final int MINIMUM_COMMON_HEADER_LENGTH = 4;
47 +
48 + public static final PcepMessageVer1.Reader READER = new Reader();
49 +
50 + static class Reader implements PcepMessageReader<PcepMessage> {
51 + @Override
52 + public PcepMessage readFrom(ChannelBuffer cb) throws PcepParseException {
53 +
54 + if (cb.readableBytes() < MINIMUM_LENGTH) {
55 + throw new PcepParseException("Packet should have minimum length: " + MINIMUM_LENGTH);
56 + }
57 +
58 + try {
59 + int start = cb.readerIndex();
60 + // fixed value property version == 1
61 + byte version = cb.readByte();
62 + version = (byte) (version >> PcepMessageVer1.SHIFT_FLAG);
63 + if (version != (byte) PACKET_VERSION) {
64 + throw new PcepParseException("Wrong version. Expected=PcepVersion.Message_1(1), got=" + version);
65 + }
66 +
67 + byte type = cb.readByte();
68 + short length = cb.readShort();
69 + cb.readerIndex(start);
70 +
71 + switch (type) {
72 +
73 + case OPEN_MSG_TYPE:
74 + log.debug("OPEN MESSAGE is received");
75 + // message type value 1 means it is open message
76 + // return
77 + // TODO: Read open message from channel buffer.
78 + case KEEPALIVE_MSG_TYPE:
79 + log.debug("KEEPALIVE MESSAGE is received");
80 + // message type value 2 means it is Keepalive message
81 + return PcepKeepaliveMsgVer1.READER.readFrom(cb.readBytes(length));
82 + case ERROR_MSG_TYPE:
83 + log.debug("ERROR MESSAGE is received");
84 + // message type value 6 means it is error message
85 + // return
86 + // TODO: Read Error message from channel buffer.
87 + case REPORT_MSG_TYPE:
88 + log.debug("REPORT MESSAGE is received");
89 + // message type value 10 means it is Report message
90 + // return
91 + // TODO: Read Report message from channel buffer.
92 + case UPDATE_MSG_TYPE:
93 + log.debug("UPDATE MESSAGE is received");
94 + //message type value 11 means it is Update message
95 + return PcepUpdateMsgVer1.READER.readFrom(cb.readBytes(length));
96 + case INITIATE_MSG_TYPE:
97 + log.debug("INITIATE MESSAGE is received");
98 + //message type value 12 means it is PcInitiate message
99 + return PcepInitiateMsgVer1.READER.readFrom(cb.readBytes(length));
100 + case CLOSE_MSG_TYPE:
101 + log.debug("CLOSE MESSAGE is received");
102 + // message type value 7 means it is Close message
103 + return PcepCloseMsgVer1.READER.readFrom(cb.readBytes(length));
104 + case TE_REPORT_MSG_TYPE:
105 + log.debug("TE REPORT MESSAGE is received");
106 + // message type value 14 means it is TE REPORT message
107 + // return
108 + // TODO: Read TE Report message from channel buffer.
109 + case LABEL_UPDATE_MSG_TYPE:
110 + log.debug("LABEL UPDATE MESSAGE is received");
111 + // message type value 13 means it is LABEL UPDATE message
112 + // return
113 + // TODO: Read Label update message from channel buffer.
114 + default:
115 + throw new PcepParseException("ERROR: UNKNOWN MESSAGE is received. Msg Type: " + type);
116 + }
117 + } catch (IndexOutOfBoundsException e) {
118 + throw new PcepParseException(PcepErrorDetailInfo.ERROR_TYPE_1, PcepErrorDetailInfo.ERROR_VALUE_1);
119 + }
120 + }
121 + }
122 +}
1 +package org.onosproject.pcepio.protocol.ver1;
2 +
3 +import org.jboss.netty.buffer.ChannelBuffer;
4 +import org.onosproject.pcepio.exceptions.PcepParseException;
5 +import org.onosproject.pcepio.protocol.PcepAttribute;
6 +import org.onosproject.pcepio.protocol.PcepEroObject;
7 +import org.onosproject.pcepio.protocol.PcepMsgPath;
8 +import org.slf4j.Logger;
9 +import org.slf4j.LoggerFactory;
10 +
11 +import com.google.common.base.MoreObjects;
12 +
13 +/**
14 + * Provides PCEP Message PAth for update message.
15 + * Reference :PCE extensions for stateful draft-ietf-pce-stateful-pce-10.
16 + */
17 +public class PcepMsgPathVer1 implements PcepMsgPath {
18 +
19 + /*
20 + * <path> ::= <ERO><attribute-list>
21 + */
22 +
23 + protected static final Logger log = LoggerFactory.getLogger(PcepMsgPathVer1.class);
24 + //PcepEroObject
25 + private PcepEroObject eroObj;
26 + private boolean isEroObjectSet;
27 + // PcepAttribute
28 + private PcepAttribute attrList;
29 + private boolean isAttributeListSet;
30 +
31 + /**
32 + * constructor to initialize objects.
33 + */
34 + public PcepMsgPathVer1() {
35 + eroObj = null;
36 + attrList = null;
37 + isEroObjectSet = false;
38 + isAttributeListSet = false;
39 + }
40 +
41 + @Override
42 + public PcepEroObject getEroObject() {
43 + return eroObj;
44 + }
45 +
46 + @Override
47 + public PcepAttribute getPcepAttribute() {
48 + return attrList;
49 + }
50 +
51 + @Override
52 + public void setEroObject(PcepEroObject eroObj) {
53 + this.eroObj = eroObj;
54 + }
55 +
56 + @Override
57 + public void setPcepAttribute(PcepAttribute attrList) {
58 + this.attrList = attrList;
59 + }
60 +
61 + /**
62 + * constructor to initialize member variables.
63 + *
64 + * @param eroObj pcep ero object
65 + * @param attrList pcep attribute
66 + */
67 + public PcepMsgPathVer1(PcepEroObject eroObj, PcepAttribute attrList) {
68 + this.eroObj = eroObj;
69 + isEroObjectSet = true;
70 + this.attrList = attrList;
71 + if (attrList == null) {
72 + isAttributeListSet = false;
73 + } else {
74 + isAttributeListSet = true;
75 + }
76 + }
77 +
78 + @Override
79 + public PcepMsgPath read(ChannelBuffer cb) throws PcepParseException {
80 + PcepEroObject eroObj;
81 + PcepAttribute attrList;
82 +
83 + eroObj = PcepEroObjectVer1.read(cb);
84 + attrList = PcepAttributeVer1.read(cb);
85 +
86 + return new PcepMsgPathVer1(eroObj, attrList);
87 + }
88 +
89 + @Override
90 + public int write(ChannelBuffer cb) throws PcepParseException {
91 + int iLenStartIndex = cb.writerIndex();
92 +
93 + //write Object header
94 + if (this.isEroObjectSet) {
95 + this.eroObj.write(cb);
96 + }
97 + if (this.isAttributeListSet) {
98 + attrList.write(cb);
99 + }
100 +
101 + return cb.writerIndex() - iLenStartIndex;
102 + }
103 +
104 + /**
105 + * builder class for PCEP Message path.
106 + */
107 + public static class Builder implements PcepMsgPath.Builder {
108 +
109 + private boolean bIsEROObjectSet = false;
110 + private boolean bIsPcepAttributeSet = false;
111 +
112 + //PCEP ERO Object
113 + private PcepEroObject eroObject;
114 + //PCEP Attribute list
115 + private PcepAttribute pcepAttribute;
116 +
117 + @Override
118 + public PcepMsgPath build() throws PcepParseException {
119 +
120 + //PCEP ERO Object
121 + PcepEroObject eroObject = null;
122 + //PCEP Attribute list
123 + PcepAttribute pcepAttribute = null;
124 +
125 + if (!this.bIsEROObjectSet) {
126 + throw new PcepParseException("ERO Object NOT Set while building PcepMsgPath.");
127 + } else {
128 + eroObject = this.eroObject;
129 + }
130 + if (!this.bIsPcepAttributeSet) {
131 + throw new PcepParseException("Pcep Attributes NOT Set while building PcepMsgPath.");
132 + } else {
133 + pcepAttribute = this.pcepAttribute;
134 + }
135 +
136 + return new PcepMsgPathVer1(eroObject, pcepAttribute);
137 + }
138 +
139 + @Override
140 + public PcepEroObject getEroObject() {
141 + return this.eroObject;
142 + }
143 +
144 + @Override
145 + public PcepAttribute getPcepAttribute() {
146 + return this.pcepAttribute;
147 + }
148 +
149 + @Override
150 + public Builder setEroObject(PcepEroObject eroObject) {
151 + this.eroObject = eroObject;
152 + this.bIsEROObjectSet = true;
153 + return this;
154 + }
155 +
156 + @Override
157 + public Builder setPcepAttribute(PcepAttribute pcepAttribute) {
158 + this.pcepAttribute = pcepAttribute;
159 + this.bIsPcepAttributeSet = true;
160 + return this;
161 + }
162 +
163 + }
164 +
165 + @Override
166 + public void print() {
167 +
168 + log.debug("PcepMsgPath");
169 + eroObj.print();
170 + attrList.print();
171 + }
172 +
173 + @Override
174 + public String toString() {
175 + return MoreObjects.toStringHelper(getClass())
176 + .add("ERO object", eroObj)
177 + .add("Attribute list", attrList)
178 + .toString();
179 + }
180 +}
...\ 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 +
17 +package org.onosproject.pcepio.protocol.ver1;
18 +
19 +import org.onosproject.pcepio.exceptions.PcepParseException;
20 +import org.onosproject.pcepio.protocol.PcepLspObject;
21 +import org.onosproject.pcepio.protocol.PcepMsgPath;
22 +import org.onosproject.pcepio.protocol.PcepSrpObject;
23 +import org.onosproject.pcepio.protocol.PcepUpdateRequest;
24 +import org.slf4j.Logger;
25 +import org.slf4j.LoggerFactory;
26 +
27 +import com.google.common.base.MoreObjects;
28 +
29 +/*
30 + * PCEP Update Request List.
31 + */
32 +public class PcepUpdateRequestVer1 implements PcepUpdateRequest {
33 +
34 + /* <update-request-list>
35 + * Where:
36 + * <update-request-list> ::= <update-request>[<update-request-list>]
37 + * <update-request> ::= <SRP>
38 + * <LSP>
39 + * <path>
40 + * Where:
41 + * <path> ::= <ERO><attribute-list>
42 + * Where:
43 + * <attribute-list> is defined in [RFC5440] and extended by PCEP extensions.
44 + */
45 +
46 + protected static final Logger log = LoggerFactory.getLogger(PcepUpdateRequestVer1.class);
47 +
48 + //PCEP SRP Object
49 + private PcepSrpObject srpObject;
50 + //PCEP LSP Object
51 + private PcepLspObject lspObject;
52 + //PCEP Message path
53 + private PcepMsgPath msgPath;
54 +
55 + /**
56 + * Default constructor.
57 + */
58 + public PcepUpdateRequestVer1() {
59 + srpObject = null;
60 + lspObject = null;
61 + msgPath = null;
62 + }
63 +
64 + /**
65 + * Constructor to initialize all member variables.
66 + *
67 + * @param srpObject srp object
68 + * @param lspObject lsp object
69 + * @param msgPath message path object
70 + */
71 + public PcepUpdateRequestVer1(PcepSrpObject srpObject, PcepLspObject lspObject, PcepMsgPath msgPath) {
72 + this.srpObject = srpObject;
73 + this.lspObject = lspObject;
74 + this.msgPath = msgPath;
75 + }
76 +
77 + @Override
78 + public PcepSrpObject getSrpObject() {
79 + return srpObject;
80 + }
81 +
82 + @Override
83 + public PcepLspObject getLspObject() {
84 + return lspObject;
85 + }
86 +
87 + @Override
88 + public PcepMsgPath getMsgPath() {
89 + return msgPath;
90 + }
91 +
92 + @Override
93 + public void setSrpObject(PcepSrpObject srpObject) {
94 + this.srpObject = srpObject;
95 +
96 + }
97 +
98 + @Override
99 + public void setLspObject(PcepLspObject lspObject) {
100 + this.lspObject = lspObject;
101 + }
102 +
103 + @Override
104 + public void setMsgPath(PcepMsgPath msgPath) {
105 + this.msgPath = msgPath;
106 + }
107 +
108 + /**
109 + * Builder class for PCEP update request.
110 + */
111 + public static class Builder implements PcepUpdateRequest.Builder {
112 +
113 + private boolean bIsSRPObjectSet = false;
114 + private boolean bIsLSPObjectSet = false;
115 + private boolean bIsPcepMsgPathSet = false;
116 +
117 + //PCEP SRP Object
118 + private PcepSrpObject srpObject;
119 + //PCEP LSP Object
120 + private PcepLspObject lspObject;
121 + //PCEP Attribute list
122 + private PcepMsgPath msgPath;
123 +
124 + @Override
125 + public PcepUpdateRequest build() throws PcepParseException {
126 +
127 + //PCEP SRP Object
128 + PcepSrpObject srpObject = null;
129 + //PCEP LSP Object
130 + PcepLspObject lspObject = null;
131 + //PCEP Attribute list
132 + PcepMsgPath msgPath = null;
133 +
134 + if (!this.bIsSRPObjectSet) {
135 + throw new PcepParseException(" SRP Object NOT Set while building PcepUpdateRequest.");
136 + } else {
137 + srpObject = this.srpObject;
138 + }
139 + if (!this.bIsLSPObjectSet) {
140 + throw new PcepParseException(" LSP Object NOT Set while building PcepUpdateRequest.");
141 + } else {
142 + lspObject = this.lspObject;
143 + }
144 + if (!this.bIsPcepMsgPathSet) {
145 + throw new PcepParseException(" Msg Path NOT Set while building PcepUpdateRequest.");
146 + } else {
147 + msgPath = this.msgPath;
148 + }
149 +
150 + return new PcepUpdateRequestVer1(srpObject, lspObject, msgPath);
151 + }
152 +
153 + @Override
154 + public PcepSrpObject getSrpObject() {
155 + return this.srpObject;
156 + }
157 +
158 + @Override
159 + public PcepLspObject getLspObject() {
160 + return this.lspObject;
161 + }
162 +
163 + @Override
164 + public PcepMsgPath getMsgPath() {
165 + return this.msgPath;
166 + }
167 +
168 + @Override
169 + public Builder setSrpObject(PcepSrpObject srpobj) {
170 + this.srpObject = srpobj;
171 + this.bIsSRPObjectSet = true;
172 + return this;
173 +
174 + }
175 +
176 + @Override
177 + public Builder setLspObject(PcepLspObject lspObject) {
178 + this.lspObject = lspObject;
179 + this.bIsLSPObjectSet = true;
180 + return this;
181 + }
182 +
183 + @Override
184 + public Builder setMsgPath(PcepMsgPath msgPath) {
185 + this.msgPath = msgPath;
186 + this.bIsPcepMsgPathSet = true;
187 + return this;
188 + }
189 + }
190 +
191 + @Override
192 + public void print() {
193 +
194 + log.debug("UPDATE REQUEST");
195 + srpObject.print();
196 + lspObject.print();
197 + }
198 +
199 + @Override
200 + public String toString() {
201 + return MoreObjects.toStringHelper(getClass())
202 + .add("SRP Object", srpObject)
203 + .add("LSP object", lspObject)
204 + .add("message path object", msgPath)
205 + .toString();
206 + }
207 +}
...\ 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 Autonomous System Tlv which contains opaque value (32 Bit AS Number).
29 + */
30 +public class AutonomousSystemTlv implements PcepValueType {
31 +
32 + /* Reference :RFC3209
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=[TBD10] | Length=4 |
37 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
38 + | opaque value (32 Bit AS Number) |
39 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
40 + */
41 +
42 + protected static final Logger log = LoggerFactory.getLogger(AutonomousSystemTlv.class);
43 +
44 + public static final short TYPE = 100; //TODD:change this TBD10
45 + public static final short LENGTH = 4;
46 +
47 + private final int rawValue;
48 +
49 + /**
50 + * constructor to initialize Autonomous system tlv value.
51 + *
52 + * @param rawValue value of Autonomous system tlv
53 + */
54 + public AutonomousSystemTlv(int rawValue) {
55 + this.rawValue = rawValue;
56 + }
57 +
58 + /**
59 + * To create instance of AutonomousSystemTlv.
60 + *
61 + * @param raw opaque value ofc 32 Bit AS Number
62 + * @return object of AutonomousSystemTlv
63 + */
64 + public static AutonomousSystemTlv of(final int raw) {
65 + return new AutonomousSystemTlv(raw);
66 + }
67 +
68 + /**
69 + * Returns opaque value of 32 Bit AS Number.
70 + *
71 + * @return int value of rawValue
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 AutonomousSystemTlv) {
103 + AutonomousSystemTlv other = (AutonomousSystemTlv) 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 AutonomousSystemTlv.
120 + *
121 + * @param c type of channel buffer
122 + * @return object of AutonomousSystemTlv
123 + */
124 + public static AutonomousSystemTlv read(ChannelBuffer c) {
125 + return AutonomousSystemTlv.of(c.readInt());
126 + }
127 +
128 + @Override
129 + public void print() {
130 + log.debug("AutonomousSystemTlv");
131 + log.debug("Type: " + TYPE);
132 + log.debug("Length: " + LENGTH);
133 + log.debug("Value: " + rawValue);
134 + }
135 +
136 + @Override
137 + public String toString() {
138 + return MoreObjects.toStringHelper(getClass())
139 + .add("TYPE", TYPE)
140 + .add("Length", LENGTH)
141 + .add("value", rawValue)
142 + .toString();
143 + }
144 +}
...@@ -10,14 +10,17 @@ import org.onosproject.pcepio.protocol.PcepOpenObject; ...@@ -10,14 +10,17 @@ import org.onosproject.pcepio.protocol.PcepOpenObject;
10 import org.slf4j.Logger; 10 import org.slf4j.Logger;
11 import org.slf4j.LoggerFactory; 11 import org.slf4j.LoggerFactory;
12 12
13 +import com.google.common.base.MoreObjects;
14 +import com.google.common.base.MoreObjects.ToStringHelper;
15 +
13 /* 16 /*
14 * Provide the error object list with open object. 17 * Provide the error object list with open object.
15 */ 18 */
16 public class ErrorObjListWithOpen { 19 public class ErrorObjListWithOpen {
17 //errorObjList is mandatory 20 //errorObjList is mandatory
18 - LinkedList<PcepErrorObject> llerrorObjList; 21 + private LinkedList<PcepErrorObject> llerrorObjList;
19 // openObject is optional 22 // openObject is optional
20 - PcepOpenObject openObject; 23 + private PcepOpenObject openObject;
21 // flag to check if open object is set or not 24 // flag to check if open object is set or not
22 public boolean isOpenObjectSet; 25 public boolean isOpenObjectSet;
23 protected static final Logger log = LoggerFactory.getLogger(ErrorObjListWithOpen.class); 26 protected static final Logger log = LoggerFactory.getLogger(ErrorObjListWithOpen.class);
...@@ -49,6 +52,11 @@ public class ErrorObjListWithOpen { ...@@ -49,6 +52,11 @@ public class ErrorObjListWithOpen {
49 isOpenObjectSet = false; 52 isOpenObjectSet = false;
50 } 53 }
51 54
55 + /**
56 + * Returns error type.
57 + *
58 + * @return error type
59 + */
52 public LinkedList<Integer> getErrorType() { 60 public LinkedList<Integer> getErrorType() {
53 LinkedList<Integer> errorType = new LinkedList<Integer>(); 61 LinkedList<Integer> errorType = new LinkedList<Integer>();
54 if (llerrorObjList != null) { 62 if (llerrorObjList != null) {
...@@ -56,7 +64,7 @@ public class ErrorObjListWithOpen { ...@@ -56,7 +64,7 @@ public class ErrorObjListWithOpen {
56 int error; 64 int error;
57 PcepErrorObject errorObj; 65 PcepErrorObject errorObj;
58 while (errObjListIterator.hasNext()) { 66 while (errObjListIterator.hasNext()) {
59 - errorObj = errObjListIterator.next(); 67 + errorObj = errObjListIterator.next();
60 error = errorObj.getErrorType(); 68 error = errorObj.getErrorType();
61 errorType.add(error); 69 errorType.add(error);
62 } 70 }
...@@ -64,6 +72,11 @@ public class ErrorObjListWithOpen { ...@@ -64,6 +72,11 @@ public class ErrorObjListWithOpen {
64 return errorType; 72 return errorType;
65 } 73 }
66 74
75 + /**
76 + * Returns error value.
77 + *
78 + * @return error value
79 + */
67 public LinkedList<Integer> getErrorValue() { 80 public LinkedList<Integer> getErrorValue() {
68 LinkedList<Integer> errorValue = new LinkedList<Integer>(); 81 LinkedList<Integer> errorValue = new LinkedList<Integer>();
69 if (llerrorObjList != null) { 82 if (llerrorObjList != null) {
...@@ -71,7 +84,7 @@ public class ErrorObjListWithOpen { ...@@ -71,7 +84,7 @@ public class ErrorObjListWithOpen {
71 int error; 84 int error;
72 PcepErrorObject errorObj; 85 PcepErrorObject errorObj;
73 while (errObjListIterator.hasNext()) { 86 while (errObjListIterator.hasNext()) {
74 - errorObj = errObjListIterator.next(); 87 + errorObj = errObjListIterator.next();
75 error = errorObj.getErrorValue(); 88 error = errorObj.getErrorValue();
76 errorValue.add(error); 89 errorValue.add(error);
77 90
...@@ -79,7 +92,8 @@ public class ErrorObjListWithOpen { ...@@ -79,7 +92,8 @@ public class ErrorObjListWithOpen {
79 } 92 }
80 return errorValue; 93 return errorValue;
81 } 94 }
82 - /* 95 +
96 + /**
83 * Checks whether error object list is empty or not. 97 * Checks whether error object list is empty or not.
84 * 98 *
85 * @return whether error object list is empty or not 99 * @return whether error object list is empty or not
...@@ -90,7 +104,7 @@ public class ErrorObjListWithOpen { ...@@ -90,7 +104,7 @@ public class ErrorObjListWithOpen {
90 return (!this.llerrorObjList.isEmpty()) ? true : false; 104 return (!this.llerrorObjList.isEmpty()) ? true : false;
91 } 105 }
92 106
93 - /* 107 + /**
94 * Write Error Object List and Open Object to channel buffer. 108 * Write Error Object List and Open Object to channel buffer.
95 * 109 *
96 * @param bb of type channel buffer 110 * @param bb of type channel buffer
...@@ -121,7 +135,7 @@ public class ErrorObjListWithOpen { ...@@ -121,7 +135,7 @@ public class ErrorObjListWithOpen {
121 return bb.writerIndex() - iLenStartIndex; 135 return bb.writerIndex() - iLenStartIndex;
122 } 136 }
123 137
124 - /* 138 + /**
125 * Prints the attributes of ErrorObject List with open Object. 139 * Prints the attributes of ErrorObject List with open Object.
126 */ 140 */
127 public void print() { 141 public void print() {
...@@ -137,4 +151,19 @@ public class ErrorObjListWithOpen { ...@@ -137,4 +151,19 @@ public class ErrorObjListWithOpen {
137 openObject.print(); 151 openObject.print();
138 } 152 }
139 } 153 }
154 +
155 + @Override
156 + public String toString() {
157 + ToStringHelper toStrHelper = MoreObjects.toStringHelper(getClass());
158 +
159 + if (openObject == null) {
160 + toStrHelper
161 + .add("error Obj List", llerrorObjList);
162 + } else {
163 + toStrHelper
164 + .add("error Obj List", llerrorObjList)
165 + .add("open Object", openObject);
166 + }
167 + return toStrHelper.toString();
168 + }
140 } 169 }
......
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 +/**
18 + * @author b00295750
19 + *
20 + */
21 +package org.onosproject.pcepio.types;
22 +
23 +import java.util.Objects;
24 +
25 +import org.jboss.netty.buffer.ChannelBuffer;
26 +import org.onosproject.pcepio.protocol.PcepVersion;
27 +import org.slf4j.Logger;
28 +import org.slf4j.LoggerFactory;
29 +
30 +import com.google.common.base.MoreObjects;
31 +
32 +/**
33 + * Provides IPv4 Sub Object.
34 + */
35 +public class IPv4SubObject implements PcepValueType {
36 +
37 + /*Reference : RFC 4874:3.1.1
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 + |L| Type | Length | IPv4 address (4 bytes) |
42 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
43 + | IPv4 address (continued) | Prefix Length | Resvd |
44 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
45 + */
46 + protected static final Logger log = LoggerFactory.getLogger(IPv4SubObject.class);
47 +
48 + public static final byte TYPE = 0x01;
49 + public static final byte LENGTH = 8;
50 + public static final byte VALUE_LENGTH = 6;
51 + public static final byte OBJ_LENGTH = 8;
52 + public static final byte LBIT = 0;
53 + public static final int SHIFT_LBIT_POSITION = 7;
54 + private int ipAddress;
55 + private byte prefixLen;
56 + private byte resvd;
57 +
58 + /**
59 + * Constructor to initialize ipv4 address.
60 + *
61 + * @param ipAddr ipv4 address
62 + */
63 + public IPv4SubObject(int ipAddr) {
64 + this.ipAddress = ipAddr;
65 + }
66 +
67 + /**
68 + * constructor to initialize ipAddress, prefixLen and resvd.
69 + *
70 + * @param ipAddress ipv4 address
71 + * @param prefixLen prefix length
72 + * @param resvd reserved flags value
73 + */
74 + public IPv4SubObject(int ipAddress, byte prefixLen, byte resvd) {
75 + this.ipAddress = ipAddress;
76 + this.prefixLen = prefixLen;
77 + this.resvd = resvd;
78 + }
79 +
80 + /**
81 + * Returns a new instance of IPv4SubObject.
82 + *
83 + * @param ipAddress ipv4 address
84 + * @param prefixLen prefix length
85 + * @param resvd reserved flags value
86 + * @return object of IPv4SubObject
87 + */
88 + public static IPv4SubObject of(int ipAddress, byte prefixLen, byte resvd) {
89 + return new IPv4SubObject(ipAddress, prefixLen, resvd);
90 + }
91 +
92 + /**
93 + * Returns prefixLen of IPv4 IP address.
94 + *
95 + * @return byte value of rawValue
96 + */
97 + public byte getPrefixLen() {
98 + return prefixLen;
99 + }
100 +
101 + /**
102 + * Returns value of IPv4 IP address.
103 + *
104 + * @return int value of ipv4 address
105 + */
106 + public int getIpAddress() {
107 + return ipAddress;
108 + }
109 +
110 + @Override
111 + public PcepVersion getVersion() {
112 + return PcepVersion.PCEP_1;
113 + }
114 +
115 + @Override
116 + public short getType() {
117 + return TYPE;
118 + }
119 +
120 + @Override
121 + public short getLength() {
122 + return LENGTH;
123 + }
124 +
125 + @Override
126 + public int hashCode() {
127 + return Objects.hash(ipAddress, prefixLen, resvd);
128 + }
129 +
130 + @Override
131 + public boolean equals(Object obj) {
132 + if (this == obj) {
133 + return true;
134 + }
135 + if (obj instanceof IPv4SubObject) {
136 + IPv4SubObject other = (IPv4SubObject) obj;
137 + return Objects.equals(this.ipAddress, other.ipAddress) && Objects.equals(this.prefixLen, other.prefixLen)
138 + && Objects.equals(this.resvd, other.resvd);
139 + }
140 + return false;
141 + }
142 +
143 + /**
144 + * Reads the channel buffer and returns object of IPv4SubObject.
145 + *
146 + * @param c type of channel buffer
147 + * @return object of IPv4SubObject
148 + */
149 + public static PcepValueType read(ChannelBuffer c) {
150 + int ipAddess = c.readInt();
151 + byte prefixLen = c.readByte();
152 + byte resvd = c.readByte();
153 + return new IPv4SubObject(ipAddess, prefixLen, resvd);
154 + }
155 +
156 + @Override
157 + public int write(ChannelBuffer c) {
158 + int iLenStartIndex = c.writerIndex();
159 + byte bValue = LBIT;
160 + bValue = (byte) (bValue << SHIFT_LBIT_POSITION);
161 + bValue = (byte) (bValue | TYPE);
162 + c.writeByte(bValue);
163 + c.writeByte(OBJ_LENGTH);
164 + c.writeInt(ipAddress);
165 + c.writeByte(prefixLen);
166 + c.writeByte(resvd);
167 +
168 + return c.writerIndex() - iLenStartIndex;
169 + }
170 +
171 + @Override
172 + public void print() {
173 + log.debug("IPv4SubObject");
174 + log.debug("Type: " + TYPE);
175 + log.debug("Length: " + LENGTH);
176 + log.debug("IPv4 address: " + String.format("%08X", ipAddress));
177 + log.debug("Prefix Length: " + prefixLen);
178 + }
179 +
180 + @Override
181 + public String toString() {
182 + return MoreObjects.toStringHelper(getClass())
183 + .add("Type", TYPE)
184 + .add("Length", LENGTH)
185 + .add("IPv4 Address", ipAddress)
186 + .add("Prefix Length", prefixLen)
187 + .toString();
188 + }
189 +}
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 IPv6 Sub Object.
30 + */
31 +public class IPv6SubObject implements PcepValueType {
32 +
33 + /* reference :RFC 4874.
34 + Subobject : IPv6 address
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 | Length | IPv6 address (16 bytes) |
40 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
41 + | IPv6 address (continued) |
42 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
43 + | IPv6 address (continued) |
44 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
45 + | IPv6 address (continued) |
46 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
47 + | IPv6 address (continued) | Prefix Length | Flags |
48 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
49 +
50 + Type
51 +
52 + 0x02 IPv6 address
53 +
54 + Length
55 +
56 + The Length contains the total length of the subobject in bytes,
57 + including the Type and Length fields. The Length is always 20.
58 +
59 + IPv6 address
60 +
61 + A 128-bit unicast host address.
62 +
63 + Prefix length
64 +
65 + 128
66 +
67 + Flags
68 +
69 + 0x01 Local protection available
70 +
71 + Indicates that the link downstream of this node is
72 + protected via a local repair mechanism. This flag can
73 + only be set if the Local protection flag was set in the
74 + SESSION_ATTRIBUTE object of the corresponding Path
75 + message.
76 +
77 + 0x02 Local protection in use
78 +
79 + Indicates that a local repair mechanism is in use to
80 + maintain this tunnel (usually in the face of an outage
81 + of the link it was previously routed over).
82 + */
83 + protected static final Logger log = LoggerFactory.getLogger(IPv6SubObject.class);
84 +
85 + public static final short TYPE = 0x02;
86 + public static final short LENGTH = 20;
87 + public static final byte VALUE_LENGTH = 18;
88 +
89 + 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 };
90 + public static final IPv6SubObject NONE = new IPv6SubObject(NONE_VAL);
91 +
92 + private static final byte[] NO_MASK_VAL = {(byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
93 + (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
94 + (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF };
95 + public static final IPv6SubObject NO_MASK = new IPv6SubObject(NO_MASK_VAL);
96 + public static final IPv6SubObject FULL_MASK = NONE;
97 +
98 + private final byte[] rawValue;
99 +
100 + /**
101 + * constructor to initialize rawValue with ipv6 address.
102 + *
103 + * @param rawValue ipv6 address
104 + */
105 + public IPv6SubObject(byte[] rawValue) {
106 + this.rawValue = rawValue;
107 + }
108 +
109 + /**
110 + * To create instance of IPv6SubObject.
111 + *
112 + * @param raw byte array of ipv6 address
113 + * @return object of IPv6SubObject
114 + */
115 + public static IPv6SubObject of(final byte[] raw) {
116 + //check NONE_VAL
117 + boolean bFoundNONE = true;
118 + //value starts from 3rd byte.
119 + for (int i = 2; i < 20; ++i) {
120 + if (NONE_VAL[i] != raw[i]) {
121 + bFoundNONE = false;
122 + }
123 + }
124 +
125 + if (bFoundNONE) {
126 + return NONE;
127 + }
128 +
129 + //check NO_MASK_VAL
130 + boolean bFoundNoMask = true;
131 + //value starts from 3rd byte.
132 + for (int i = 2; i < 20; ++i) {
133 + if (0xFF != raw[i]) {
134 + bFoundNoMask = false;
135 + }
136 + }
137 + if (bFoundNoMask) {
138 + return NO_MASK;
139 + }
140 +
141 + return new IPv6SubObject(raw);
142 + }
143 +
144 + /**
145 + * Returns value of IPv6 Sub Object.
146 + *
147 + * @return byte array of ipv6 address
148 + */
149 + public byte[] getValue() {
150 + return rawValue;
151 + }
152 +
153 + @Override
154 + public PcepVersion getVersion() {
155 + return PcepVersion.PCEP_1;
156 + }
157 +
158 + @Override
159 + public short getType() {
160 + return TYPE;
161 + }
162 +
163 + @Override
164 + public short getLength() {
165 + return LENGTH;
166 + }
167 +
168 + @Override
169 + public int hashCode() {
170 + return Objects.hash(rawValue);
171 + }
172 +
173 + @Override
174 + public boolean equals(Object obj) {
175 + if (this == obj) {
176 + return true;
177 + }
178 + if (obj instanceof IPv6SubObject) {
179 + IPv6SubObject other = (IPv6SubObject) obj;
180 + return Objects.equals(rawValue, other.rawValue);
181 + }
182 + return false;
183 + }
184 +
185 + @Override
186 + public int write(ChannelBuffer c) {
187 + int iStartIndex = c.writerIndex();
188 + c.writeShort(TYPE);
189 + c.writeShort(LENGTH);
190 + c.writeBytes(rawValue);
191 + return c.writerIndex() - iStartIndex;
192 + }
193 +
194 + /**
195 + * Reads the channel buffer and returns object of IPv6SubObject.
196 + *
197 + * @param c type of channel buffer
198 + * @return object of IPv6SubObject
199 + */
200 + public static IPv6SubObject read20Bytes(ChannelBuffer c) {
201 + byte[] yTemp = new byte[20];
202 + c.readBytes(yTemp, 0, 20);
203 + return IPv6SubObject.of(yTemp);
204 + }
205 +
206 + @Override
207 + public void print() {
208 + log.debug("IPv6SubObject");
209 + log.debug("Type: ", TYPE);
210 + log.debug("Length: ", LENGTH);
211 + if (null != rawValue) {
212 + StringBuffer result = new StringBuffer();
213 + for (byte b : rawValue) {
214 + result.append(String.format("%02X ", b));
215 + }
216 + log.debug(result.toString());
217 + }
218 + }
219 +
220 + @Override
221 + public String toString() {
222 + return MoreObjects.toStringHelper(getClass())
223 + .add("Type", TYPE)
224 + .add("Length", LENGTH)
225 + .add("IPv6 Address", rawValue)
226 + .toString();
227 + }
228 +}
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 + * Path Key SubObject: When a PCC needs to expand a path-key in order to expand a CPS, it
30 + * issues a Path Computation Request (PCReq) to the PCE identified in
31 + * the PKS in the RSVP-TE ERO that it is processing. The PCC supplies
32 + * the PKS to be expanded in a PATH-KEY SubObject in the PCReq message.
33 + */
34 +public class PathKeySubObject implements PcepValueType {
35 +
36 + /*
37 + Pathkey subobject(RFC 5520):
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 + |L| Type | Length | Path-Key |
42 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
43 + | PCE ID (4 bytes) |
44 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
45 + */
46 +
47 + protected static final Logger log = LoggerFactory.getLogger(PathKeySubObject.class);
48 +
49 + public static final byte TYPE = 0x40;
50 + public static final byte LENGTH = 8;
51 + private final short pathKey;
52 + private final int pceID;
53 +
54 + /**
55 + * Constructor for Path Key sub Object which initializes pathKey and pceId.
56 + *
57 + * @param pathKey path key provided by PCC
58 + * @param pceID ID for the PCE
59 + */
60 + public PathKeySubObject(short pathKey, int pceID) {
61 + this.pathKey = pathKey;
62 + this.pceID = pceID;
63 + }
64 +
65 + /**
66 + * Creates Path Key sub Object which initializes pathKey and pceId.
67 + *
68 + * @param pathKey path key provided by PCC
69 + * @param pceID PCE id
70 + * @return new object of type path key sub object
71 + */
72 + public static PathKeySubObject of(short pathKey, int pceID) {
73 + return new PathKeySubObject(pathKey, pceID);
74 + }
75 +
76 + /**
77 + * Returns Path Key.
78 + *
79 + * @return pathKey
80 + */
81 + public short getPathKey() {
82 + return pathKey;
83 + }
84 +
85 + /**
86 + * Returns pceID.
87 + *
88 + * @return pceID
89 + */
90 + public int getPceId() {
91 + return pceID;
92 + }
93 +
94 + @Override
95 + public PcepVersion getVersion() {
96 + return PcepVersion.PCEP_1;
97 + }
98 +
99 + @Override
100 + public short getType() {
101 + return TYPE;
102 + }
103 +
104 + @Override
105 + public short getLength() {
106 + return LENGTH;
107 + }
108 +
109 + @Override
110 + public int hashCode() {
111 + return Objects.hash(pathKey, pceID);
112 + }
113 +
114 + @Override
115 + public boolean equals(Object obj) {
116 + if (this == obj) {
117 + return true;
118 + }
119 + if (obj instanceof PathKeySubObject) {
120 + PathKeySubObject other = (PathKeySubObject) obj;
121 + return Objects.equals(this.pathKey, other.pathKey) && Objects.equals(this.pceID, other.pceID);
122 + }
123 + return false;
124 + }
125 +
126 + @Override
127 + public int write(ChannelBuffer c) {
128 + int iLenStartIndex = c.writerIndex();
129 + c.writeShort(TYPE);
130 + c.writeShort(LENGTH);
131 +
132 + c.writeShort(pathKey);
133 + c.writeInt(pceID);
134 +
135 + return c.writerIndex() - iLenStartIndex;
136 + }
137 +
138 + /**
139 + * Reads the channel buffer and returns new path key sub objects.
140 + *
141 + * @param c of type channel buffer
142 + * @return object of type path key sub object
143 + */
144 + public static PcepValueType read(ChannelBuffer c) {
145 + Short pathKey = c.readShort();
146 + int pceID = c.readInt();
147 + return new PathKeySubObject(pathKey, pceID);
148 + }
149 +
150 + @Override
151 + public void print() {
152 + log.debug("PathKeySubObject");
153 + log.debug("Type: " + TYPE);
154 + log.debug("Length: " + LENGTH);
155 + log.debug("Path Key: " + pathKey);
156 + log.debug("PCEID: " + pceID);
157 + }
158 +
159 + @Override
160 + public String toString() {
161 + return MoreObjects.toStringHelper(getClass())
162 + .add("Type", TYPE).add("Length", LENGTH)
163 + .add("Path Key", pathKey)
164 + .add("PCE ID", pceID)
165 + .toString();
166 + }
167 +}
1 +/*
2 + * Copyright 2015 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +
17 +package org.onosproject.pcepio.types;
18 +
19 +/*
20 + * Provide the PCEP Error Info Details.
21 + */
22 +public final class PcepErrorDetailInfo {
23 +
24 + private PcepErrorDetailInfo() {
25 + }
26 +
27 + // Error Types
28 + /**
29 + Error- Meaning Reference:RFC 5440
30 + Type
31 + 1 PCEP session establishment failure
32 + Error-value=1: reception of an invalid Open message or a non Open message.
33 + Error-value=2: no Open message received before the expiration of the OpenWait timer
34 + Error-value=3: unacceptable and non-negotiable session characteristics
35 + Error-value=4: unacceptable but negotiable session characteristics
36 + Error-value=5: reception of a second Open message with still unacceptable session characteristics
37 + Error-value=6: reception of a PCErr message proposing unacceptable session characteristics
38 + Error-value=7: No Keepalive or PCErr message received before the expiration of the KeepWait timer
39 + Error-value=8: PCEP version not supported
40 + 2 Capability not supported
41 + 3 Unknown Object
42 + Error-value=1: Unrecognized object class
43 + Error-value=2: Unrecognized object Type
44 + 4 Not supported object
45 + Error-value=1: Not supported object class
46 + Error-value=2: Not supported object Type
47 + 5 Policy violation
48 + Error-value=1: C bit of the METRIC object set (request rejected)
49 + Error-value=2: O bit of the RP object cleared (request rejected)
50 + 6 Mandatory Object missing
51 + Error-value=1: RP object missing
52 + Error-value=2: RRO missing for a re-optimization request (R bit of the RP object set)
53 + Error-value=3: END-POINTS object missing
54 + 7 Synchronized path computation request missing
55 + 8 Unknown request reference
56 + 9 Attempt to establish a second PCEP session
57 + 10 Reception of an invalid object
58 + Error-value=1: reception of an object with P flag not set although the P flag must be
59 + set according to this specification.
60 + */
61 + public static final byte ERROR_TYPE_1 = 1;
62 + public static final byte ERROR_TYPE_2 = 2;
63 + public static final byte ERROR_TYPE_3 = 3;
64 + public static final byte ERROR_TYPE_4 = 4;
65 + public static final byte ERROR_TYPE_5 = 5;
66 + public static final byte ERROR_TYPE_6 = 6;
67 + public static final byte ERROR_TYPE_7 = 7;
68 + public static final byte ERROR_TYPE_8 = 8;
69 + public static final byte ERROR_TYPE_9 = 9;
70 + public static final byte ERROR_TYPE_10 = 10;
71 +
72 + // Error Values
73 + public static final byte ERROR_VALUE_1 = 1;
74 + public static final byte ERROR_VALUE_2 = 2;
75 + public static final byte ERROR_VALUE_3 = 3;
76 + public static final byte ERROR_VALUE_4 = 4;
77 + public static final byte ERROR_VALUE_5 = 5;
78 + public static final byte ERROR_VALUE_6 = 6;
79 + public static final byte ERROR_VALUE_7 = 7;
80 + public static final byte ERROR_VALUE_8 = 8;
81 + public static final byte ERROR_VALUE_9 = 9;
82 + public static final byte ERROR_VALUE_10 = 10;
83 +}
...@@ -9,7 +9,9 @@ import org.onosproject.pcepio.protocol.PcepSrpObject; ...@@ -9,7 +9,9 @@ import org.onosproject.pcepio.protocol.PcepSrpObject;
9 import org.slf4j.Logger; 9 import org.slf4j.Logger;
10 import org.slf4j.LoggerFactory; 10 import org.slf4j.LoggerFactory;
11 11
12 -/* 12 +import com.google.common.base.MoreObjects;
13 +
14 +/**
13 * Provides Pcep Label. 15 * Provides Pcep Label.
14 * REference :draft-zhao-pce-pcep-extension-for-pce-controller-01. 16 * REference :draft-zhao-pce-pcep-extension-for-pce-controller-01.
15 */ 17 */
...@@ -18,13 +20,13 @@ public class PcepLabelDownload { ...@@ -18,13 +20,13 @@ public class PcepLabelDownload {
18 protected static final Logger log = LoggerFactory.getLogger(PcepLabelDownload.class); 20 protected static final Logger log = LoggerFactory.getLogger(PcepLabelDownload.class);
19 21
20 //PCEP SPR Object 22 //PCEP SPR Object
21 - PcepSrpObject srpObject; 23 + private PcepSrpObject srpObject;
22 //PCEP LSP Object 24 //PCEP LSP Object
23 - PcepLspObject lspObject; 25 + private PcepLspObject lspObject;
24 //LinkList of Labels 26 //LinkList of Labels
25 - LinkedList<PcepLabelObject> llLabelList; 27 + private LinkedList<PcepLabelObject> llLabelList;
26 28
27 - /* 29 + /**
28 * Returns SRP Object. 30 * Returns SRP Object.
29 * 31 *
30 * @return PCEP SRP Object 32 * @return PCEP SRP Object
...@@ -33,7 +35,7 @@ public class PcepLabelDownload { ...@@ -33,7 +35,7 @@ public class PcepLabelDownload {
33 return srpObject; 35 return srpObject;
34 } 36 }
35 37
36 - /* 38 + /**
37 * Sets the Pcep Srp Object. 39 * Sets the Pcep Srp Object.
38 * 40 *
39 * @param srpobj PCEP SRP Object 41 * @param srpobj PCEP SRP Object
...@@ -42,7 +44,7 @@ public class PcepLabelDownload { ...@@ -42,7 +44,7 @@ public class PcepLabelDownload {
42 this.srpObject = srpobj; 44 this.srpObject = srpobj;
43 } 45 }
44 46
45 - /* 47 + /**
46 * Returns LSP Object. 48 * Returns LSP Object.
47 * 49 *
48 * @return PCEP LSP Object 50 * @return PCEP LSP Object
...@@ -51,7 +53,7 @@ public class PcepLabelDownload { ...@@ -51,7 +53,7 @@ public class PcepLabelDownload {
51 return lspObject; 53 return lspObject;
52 } 54 }
53 55
54 - /* 56 + /**
55 * Sets the Pcep LSP Object. 57 * Sets the Pcep LSP Object.
56 * 58 *
57 * @param lspObject PCEP LSP Object 59 * @param lspObject PCEP LSP Object
...@@ -60,7 +62,7 @@ public class PcepLabelDownload { ...@@ -60,7 +62,7 @@ public class PcepLabelDownload {
60 this.lspObject = lspObject; 62 this.lspObject = lspObject;
61 } 63 }
62 64
63 - /* 65 + /**
64 * Returns a list of labels. 66 * Returns a list of labels.
65 * 67 *
66 * @return llLabelList list of pcep label objects 68 * @return llLabelList list of pcep label objects
...@@ -69,7 +71,7 @@ public class PcepLabelDownload { ...@@ -69,7 +71,7 @@ public class PcepLabelDownload {
69 return llLabelList; 71 return llLabelList;
70 } 72 }
71 73
72 - /* 74 + /**
73 * set the llLabelList list of type PcepLableObject. 75 * set the llLabelList list of type PcepLableObject.
74 * 76 *
75 * @param llLabelList list of pcep label objects 77 * @param llLabelList list of pcep label objects
...@@ -78,7 +80,7 @@ public class PcepLabelDownload { ...@@ -78,7 +80,7 @@ public class PcepLabelDownload {
78 this.llLabelList = llLabelList; 80 this.llLabelList = llLabelList;
79 } 81 }
80 82
81 - /* 83 + /**
82 * Prints the attribute of PcepLableObject. 84 * Prints the attribute of PcepLableObject.
83 */ 85 */
84 public void print() { 86 public void print() {
...@@ -92,4 +94,13 @@ public class PcepLabelDownload { ...@@ -92,4 +94,13 @@ public class PcepLabelDownload {
92 listIterator.next().print(); 94 listIterator.next().print();
93 } 95 }
94 } 96 }
97 +
98 + @Override
99 + public String toString() {
100 + return MoreObjects.toStringHelper(getClass())
101 + .add("SRP object", srpObject)
102 + .add("LSP object", lspObject)
103 + .add("label object list", llLabelList)
104 + .toString();
105 + }
95 } 106 }
......
...@@ -22,6 +22,8 @@ import org.onosproject.pcepio.protocol.PcepSrpObject; ...@@ -22,6 +22,8 @@ import org.onosproject.pcepio.protocol.PcepSrpObject;
22 import org.slf4j.Logger; 22 import org.slf4j.Logger;
23 import org.slf4j.LoggerFactory; 23 import org.slf4j.LoggerFactory;
24 24
25 +import com.google.common.base.MoreObjects;
26 +
25 /** 27 /**
26 * Provide PCEP Label Map. 28 * Provide PCEP Label Map.
27 * Reference :draft-zhao-pce-pcep-extension-for-pce-controller-01. 29 * Reference :draft-zhao-pce-pcep-extension-for-pce-controller-01.
...@@ -30,11 +32,11 @@ public class PcepLabelMap { ...@@ -30,11 +32,11 @@ public class PcepLabelMap {
30 32
31 protected static final Logger log = LoggerFactory.getLogger(PcepLabelMap.class); 33 protected static final Logger log = LoggerFactory.getLogger(PcepLabelMap.class);
32 //PCEP SRP Object 34 //PCEP SRP Object
33 - PcepSrpObject srpObject; 35 + private PcepSrpObject srpObject;
34 //PCEP Label Object 36 //PCEP Label Object
35 - PcepLabelObject labelObject; 37 + private PcepLabelObject labelObject;
36 //PCEP FEC Object 38 //PCEP FEC Object
37 - PcepFecObject fecObject; 39 + private PcepFecObject fecObject;
38 40
39 /** 41 /**
40 * Sets Fec Object. 42 * Sets Fec Object.
...@@ -99,4 +101,13 @@ public class PcepLabelMap { ...@@ -99,4 +101,13 @@ public class PcepLabelMap {
99 labelObject.print(); 101 labelObject.print();
100 fecObject.print(); 102 fecObject.print();
101 } 103 }
104 +
105 + @Override
106 + public String toString() {
107 + return MoreObjects.toStringHelper(getClass())
108 + .add("SRP object", srpObject)
109 + .add("Label object", labelObject)
110 + .add("Fec object", fecObject)
111 + .toString();
112 + }
102 } 113 }
......
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.PcepNai;
23 +
24 +import com.google.common.base.MoreObjects;
25 +
26 +public class PcepNaiIpv4Adjacency implements PcepNai {
27 +
28 + public static final byte ST_TYPE = 0x03;
29 + private final int localIpv4Addr;
30 + private final int remoteIpv4Addr;
31 +
32 + /**
33 + * Constructor to initialize variables.
34 + *
35 + * @param localIpv4 local ipv4 address
36 + * @param remoteIpv4 remote ipv4 address
37 + */
38 + public PcepNaiIpv4Adjacency(int localIpv4, int remoteIpv4) {
39 + this.localIpv4Addr = localIpv4;
40 + this.remoteIpv4Addr = remoteIpv4;
41 + }
42 +
43 + @Override
44 + public byte getType() {
45 + return ST_TYPE;
46 + }
47 +
48 + @Override
49 + public int write(ChannelBuffer bb) {
50 + int iLenStartIndex = bb.writerIndex();
51 + bb.writeInt(localIpv4Addr);
52 + bb.writeInt(remoteIpv4Addr);
53 + return bb.writerIndex() - iLenStartIndex;
54 + }
55 +
56 + /**
57 + * Reads the channel buffer and returns object of PcepNAIIpv4AdjacencyVer1.
58 + *
59 + * @param cb of channel buffer
60 + * @return object of PcepNAIIpv4Adjacency
61 + */
62 + public static PcepNaiIpv4Adjacency read(ChannelBuffer cb) {
63 + int localIpv4 = cb.readInt();
64 + int remoteIpv4 = cb.readInt();
65 + return new PcepNaiIpv4Adjacency(localIpv4, remoteIpv4);
66 + }
67 +
68 + @Override
69 + public int hashCode() {
70 + return Objects.hash(localIpv4Addr, remoteIpv4Addr);
71 + }
72 +
73 + @Override
74 + public boolean equals(Object obj) {
75 + if (this == obj) {
76 + return true;
77 + }
78 + if (obj instanceof PcepNaiIpv4Adjacency) {
79 + PcepNaiIpv4Adjacency other = (PcepNaiIpv4Adjacency) obj;
80 + return Objects.equals(this.localIpv4Addr, other.localIpv4Addr)
81 + && Objects.equals(this.remoteIpv4Addr, other.remoteIpv4Addr);
82 + }
83 + return false;
84 + }
85 +
86 + @Override
87 + public String toString() {
88 + return MoreObjects.toStringHelper(getClass())
89 + .add("local IPv4 Address", localIpv4Addr)
90 + .add("remote IPv4 Address", remoteIpv4Addr)
91 + .toString();
92 + }
93 +}
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.PcepNai;
23 +
24 +import com.google.common.base.MoreObjects;
25 +
26 +public class PcepNaiIpv4NodeId implements PcepNai {
27 +
28 + public static final byte ST_TYPE = 0x01;
29 +
30 + private final int ipv4NodeId;
31 +
32 + /**
33 + * Constructor to initialize ipv4NodeId.
34 + *
35 + * @param value ipv4 node id
36 + */
37 + public PcepNaiIpv4NodeId(int value) {
38 + this.ipv4NodeId = value;
39 + }
40 +
41 + /**
42 + * Returns an object of PcepNaiIpv4NodeId.
43 + *
44 + * @param value ipv4 node id
45 + * @return object of PcepNaiIpv4NodeId
46 + */
47 + public static PcepNaiIpv4NodeId of(int value) {
48 + return new PcepNaiIpv4NodeId(value);
49 + }
50 +
51 + @Override
52 + public byte getType() {
53 + return ST_TYPE;
54 + }
55 +
56 + @Override
57 + public int write(ChannelBuffer bb) {
58 + int iLenStartIndex = bb.writerIndex();
59 + bb.writeInt(ipv4NodeId);
60 + return bb.writerIndex() - iLenStartIndex;
61 + }
62 +
63 + /**
64 + * Reads from the channel buffer and returns object of PcepNAIIpv4NodeIdVer1.
65 + *
66 + * @param bb of channel buffer.
67 + * @return object of PcepNAIIpv4NodeIdVer1
68 + */
69 + public static PcepNaiIpv4NodeId read(ChannelBuffer bb) {
70 + return new PcepNaiIpv4NodeId(bb.readInt());
71 + }
72 +
73 + @Override
74 + public int hashCode() {
75 + return Objects.hash(ipv4NodeId);
76 + }
77 +
78 + @Override
79 + public boolean equals(Object obj) {
80 + if (this == obj) {
81 + return true;
82 + }
83 + if (obj instanceof PcepNaiIpv4NodeId) {
84 + PcepNaiIpv4NodeId other = (PcepNaiIpv4NodeId) obj;
85 + return Objects.equals(this.ipv4NodeId, other.ipv4NodeId);
86 + }
87 + return false;
88 + }
89 +
90 + @Override
91 + public String toString() {
92 + return MoreObjects.toStringHelper(getClass())
93 + .add("IPv4 Node Id", ipv4NodeId)
94 + .toString();
95 + }
96 +}
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.PcepNai;
23 +
24 +import com.google.common.base.MoreObjects;
25 +
26 +public class PcepNaiIpv6Adjacency implements PcepNai {
27 +
28 + public static final byte ST_TYPE = 0x04;
29 + public static final byte IPV6_LEN = 0x10;
30 +
31 + private final byte[] localIpv6Addr;
32 + private final byte[] remoteIpv6Addr;
33 +
34 + /**
35 + * Constructor to initialize local ipv6 and remote ipv6.
36 + *
37 + * @param localIpv6 local ipv6 address
38 + * @param remoteIpv6 remote ipv6 address
39 + */
40 + public PcepNaiIpv6Adjacency(byte[] localIpv6, byte[] remoteIpv6) {
41 + this.localIpv6Addr = localIpv6;
42 + this.remoteIpv6Addr = remoteIpv6;
43 + }
44 +
45 + @Override
46 + public byte getType() {
47 + return ST_TYPE;
48 + }
49 +
50 + @Override
51 + public int write(ChannelBuffer bb) {
52 + int iLenStartIndex = bb.writerIndex();
53 + bb.writeBytes(localIpv6Addr);
54 + bb.writeBytes(remoteIpv6Addr);
55 + return bb.writerIndex() - iLenStartIndex;
56 + }
57 +
58 + /**
59 + * Reads from channel buffer and returns object of PcepNAIIpv6AdjacencyVer1.
60 + *
61 + * @param bb of type channel buffer
62 + * @return object of PcepNAIIpv6AdjacencyVer1
63 + */
64 + public static PcepNaiIpv6Adjacency read(ChannelBuffer bb) {
65 + byte[] localIpv6 = new byte[IPV6_LEN];
66 + bb.readBytes(localIpv6, 0, IPV6_LEN);
67 + byte[] remoteIpv6 = new byte[IPV6_LEN];
68 + bb.readBytes(remoteIpv6, 0, IPV6_LEN);
69 + return new PcepNaiIpv6Adjacency(localIpv6, remoteIpv6);
70 + }
71 +
72 + @Override
73 + public int hashCode() {
74 + return Objects.hash(localIpv6Addr, remoteIpv6Addr);
75 + }
76 +
77 + @Override
78 + public boolean equals(Object obj) {
79 + if (this == obj) {
80 + return true;
81 + }
82 + if (obj instanceof PcepNaiIpv6Adjacency) {
83 + PcepNaiIpv6Adjacency other = (PcepNaiIpv6Adjacency) obj;
84 + return Objects.equals(this.localIpv6Addr, other.localIpv6Addr)
85 + && Objects.equals(this.remoteIpv6Addr, other.remoteIpv6Addr);
86 + }
87 + return false;
88 + }
89 +
90 + /**
91 + * Creates object of PcepNaiIpv6Adjacency with local ipv6 address and remote ipv6 address.
92 + *
93 + * @param localIpv6Addr local ipv6 address
94 + * @param remoteIpv6Addr remote ipv6 address
95 + * @return object of PcepNaiIpv6Adjacency
96 + */
97 +
98 + public static PcepNaiIpv6Adjacency of(final byte[] localIpv6Addr, final byte[] remoteIpv6Addr) {
99 + return new PcepNaiIpv6Adjacency(localIpv6Addr, remoteIpv6Addr);
100 + }
101 +
102 + @Override
103 + public String toString() {
104 + return MoreObjects.toStringHelper(getClass())
105 + .add("local IPV6 address", localIpv6Addr)
106 + .add("remote IPV6 address", remoteIpv6Addr)
107 + .toString();
108 + }
109 +
110 +}
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.PcepNai;
23 +
24 +import com.google.common.base.MoreObjects;
25 +
26 +public class PcepNaiIpv6NodeId implements PcepNai {
27 +
28 + public static final byte ST_TYPE = 0x02;
29 + public static final byte IPV6_LEN = 0x10;
30 +
31 + private final byte[] ipv6NodeId;
32 +
33 + /**
34 + * Constructor to initialize ipv6NodeId.
35 + *
36 + * @param value ipv6 node id
37 + */
38 + public PcepNaiIpv6NodeId(byte[] value) {
39 + this.ipv6NodeId = value;
40 + }
41 +
42 + @Override
43 + public byte getType() {
44 + return ST_TYPE;
45 + }
46 +
47 + @Override
48 + public int write(ChannelBuffer cb) {
49 + int iLenStartIndex = cb.writerIndex();
50 + cb.writeBytes(ipv6NodeId);
51 + return cb.writerIndex() - iLenStartIndex;
52 + }
53 +
54 + /**
55 + * Reads from the channel buffer and returns object of PcepNAIIpv6NodeId.
56 + *
57 + * @param cb of type channel buffer.
58 + * @return object of PcepNAIIpv6NodeId
59 + */
60 + public static PcepNaiIpv6NodeId read(ChannelBuffer cb) {
61 + byte[] ipv6NodeId = new byte[IPV6_LEN];
62 + cb.readBytes(ipv6NodeId, 0, IPV6_LEN);
63 + return new PcepNaiIpv6NodeId(ipv6NodeId);
64 + }
65 +
66 + @Override
67 + public int hashCode() {
68 + return Objects.hash(ipv6NodeId);
69 + }
70 +
71 + @Override
72 + public boolean equals(Object obj) {
73 + if (this == obj) {
74 + return true;
75 + }
76 + if (obj instanceof PcepNaiIpv6NodeId) {
77 + PcepNaiIpv6NodeId other = (PcepNaiIpv6NodeId) obj;
78 + return Objects.equals(this.ipv6NodeId, other.ipv6NodeId);
79 + }
80 + return false;
81 + }
82 +
83 + @Override
84 + public String toString() {
85 + return MoreObjects.toStringHelper(getClass())
86 + .add("IPV6 node ID", ipv6NodeId)
87 + .toString();
88 + }
89 +}
1 +package org.onosproject.pcepio.types;
2 +
3 +import java.util.Objects;
4 +
5 +import org.jboss.netty.buffer.ChannelBuffer;
6 +import org.onosproject.pcepio.protocol.PcepNai;
7 +
8 +import com.google.common.base.MoreObjects;
9 +
10 +public class PcepNaiUnnumberedAdjacencyIpv4 implements PcepNai {
11 + /**
12 + * draft-ietf-pce-segment-routing-03 section 5.3.2.
13 + */
14 + public static final byte ST_TYPE = 0x05;
15 +
16 + private final int localNodeId;
17 + private final int localInterfaceId;
18 + private final int remoteNodeId;
19 + private final int remoteInterfaceId;
20 +
21 + /**
22 + * Constructor to initialize all the member variables.
23 + *
24 + * @param localNodeId local node id
25 + * @param localInterfaceId local interface id
26 + * @param remoteNodeId remote node id
27 + * @param remoteInterfaceId remote interface id
28 + */
29 + public PcepNaiUnnumberedAdjacencyIpv4(int localNodeId, int localInterfaceId, int remoteNodeId,
30 + int remoteInterfaceId) {
31 + this.localNodeId = localNodeId;
32 + this.localInterfaceId = localInterfaceId;
33 + this.remoteNodeId = remoteNodeId;
34 + this.remoteInterfaceId = remoteInterfaceId;
35 + }
36 +
37 + /**
38 + * Returns PCEP Nai Unnumbered Adjacency Ipv4 object.
39 + *
40 + * @param localNodeId local node id
41 + * @param localInterfaceId local interface if
42 + * @param remoteNodeId remote node id
43 + * @param remoteInterfaceId remote interface id
44 + * @return PCEP Nai Unnumbered Adjacency Ipv4 object
45 + */
46 + public static PcepNaiUnnumberedAdjacencyIpv4 of(int localNodeId, int localInterfaceId, int remoteNodeId,
47 + int remoteInterfaceId) {
48 + return new PcepNaiUnnumberedAdjacencyIpv4(localNodeId, localInterfaceId, remoteNodeId, remoteInterfaceId);
49 + }
50 +
51 + @Override
52 + public byte getType() {
53 + return ST_TYPE;
54 + }
55 +
56 + @Override
57 + public int write(ChannelBuffer bb) {
58 + int iLenStartIndex = bb.writerIndex();
59 + bb.writeInt(localNodeId);
60 + bb.writeInt(localInterfaceId);
61 + bb.writeInt(remoteNodeId);
62 + bb.writeInt(remoteInterfaceId);
63 + return bb.writerIndex() - iLenStartIndex;
64 + }
65 +
66 + /**
67 + * Reads from channel buffer and return object of PcepNAIUnnumberedAdjacencyIpv4.
68 + *
69 + * @param bb of type channel buffer
70 + * @return object of PcepNAIUnnumberedAdjacencyIpv4
71 + */
72 + public static PcepNaiUnnumberedAdjacencyIpv4 read(ChannelBuffer bb) {
73 + int localNodeId;
74 + int localInterfaceId;
75 + int remoteNodeId;
76 + int remoteInterfaceId;
77 + localNodeId = bb.readInt();
78 + localInterfaceId = bb.readInt();
79 + remoteNodeId = bb.readInt();
80 + remoteInterfaceId = bb.readInt();
81 + return new PcepNaiUnnumberedAdjacencyIpv4(localNodeId, localInterfaceId, remoteNodeId, remoteInterfaceId);
82 + }
83 +
84 + @Override
85 + public int hashCode() {
86 + return Objects.hash(localNodeId, localInterfaceId, remoteNodeId, remoteInterfaceId);
87 + }
88 +
89 + @Override
90 + public boolean equals(Object obj) {
91 + if (this == obj) {
92 + return true;
93 + }
94 + if (obj instanceof PcepNaiUnnumberedAdjacencyIpv4) {
95 + PcepNaiUnnumberedAdjacencyIpv4 other = (PcepNaiUnnumberedAdjacencyIpv4) obj;
96 + return Objects.equals(this.localNodeId, other.localNodeId)
97 + && Objects.equals(this.localInterfaceId, other.localInterfaceId)
98 + && Objects.equals(this.remoteNodeId, other.remoteNodeId)
99 + && Objects.equals(this.remoteInterfaceId, other.remoteInterfaceId);
100 + }
101 + return false;
102 + }
103 +
104 + @Override
105 + public String toString() {
106 + return MoreObjects.toStringHelper(getClass())
107 + .add("local Node Id", localNodeId)
108 + .add("local Interface Id", localInterfaceId)
109 + .add("remote Node Id", remoteNodeId)
110 + .add("remote Interface Id:", remoteInterfaceId)
111 + .toString();
112 + }
113 +}
...@@ -20,6 +20,8 @@ import org.jboss.netty.buffer.ChannelBuffer; ...@@ -20,6 +20,8 @@ import org.jboss.netty.buffer.ChannelBuffer;
20 import org.slf4j.Logger; 20 import org.slf4j.Logger;
21 import org.slf4j.LoggerFactory; 21 import org.slf4j.LoggerFactory;
22 22
23 +import com.google.common.base.MoreObjects;
24 +
23 /** 25 /**
24 * Provides PCEP Object Header which is common for all the objects. 26 * Provides PCEP Object Header which is common for all the objects.
25 * Reference : RFC 5440. 27 * Reference : RFC 5440.
...@@ -66,7 +68,6 @@ public class PcepObjectHeader { ...@@ -66,7 +68,6 @@ public class PcepObjectHeader {
66 * @param bIFlag I flag 68 * @param bIFlag I flag
67 * @param objLen PCEP object length 69 * @param objLen PCEP object length
68 */ 70 */
69 -
70 public PcepObjectHeader(byte objClass, byte objType, boolean bPFlag, boolean bIFlag, short objLen) { 71 public PcepObjectHeader(byte objClass, byte objType, boolean bPFlag, boolean bIFlag, short objLen) {
71 this.objClass = objClass; 72 this.objClass = objClass;
72 this.objType = objType; 73 this.objType = objType;
...@@ -221,4 +222,15 @@ public class PcepObjectHeader { ...@@ -221,4 +222,15 @@ public class PcepObjectHeader {
221 log.debug("P flag: " + bPFlag); 222 log.debug("P flag: " + bPFlag);
222 log.debug("I flag: " + bIFlag); 223 log.debug("I flag: " + bIFlag);
223 } 224 }
225 +
226 + @Override
227 + public String toString() {
228 + return MoreObjects.toStringHelper(getClass())
229 + .add("Object class:", objClass)
230 + .add("Object type:", objType)
231 + .add("Object length:", objLen)
232 + .add("P flag:", bPFlag)
233 + .add("I flag:", bIFlag)
234 + .toString();
235 + }
224 } 236 }
......
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 org.jboss.netty.buffer.ChannelBuffer;
19 +
20 +public interface PcepRsvpErrorSpec extends PcepValueType {
21 +
22 + /**
23 + * To write the object information to channelBuffer.
24 + *
25 + * @param cb of type channel buffer
26 + */
27 + @Override
28 + int write(ChannelBuffer cb);
29 +
30 + /**
31 + * Returns class number.
32 + *
33 + * @return class number
34 + */
35 + byte getClassNum();
36 +
37 + /**
38 + * Returns class type.
39 + *
40 + * @return class type
41 + */
42 + byte getClassType();
43 +
44 + @Override
45 + String toString();
46 +
47 +}
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 org.jboss.netty.buffer.ChannelBuffer;
19 +import org.onosproject.pcepio.protocol.PcepVersion;
20 +
21 +import com.google.common.base.MoreObjects;
22 +
23 +public class PcepRsvpIpv4ErrorSpec implements PcepRsvpErrorSpec {
24 +
25 + /*
26 + RSVP error spec object header.
27 + 0 1 2 3
28 + +-------------+-------------+-------------+-------------+
29 + | Length (bytes) | Class-Num | C-Type |
30 + +-------------+-------------+-------------+-------------+
31 + | |
32 + // (Object contents) //
33 + | |
34 + +-------------+-------------+-------------+-------------+
35 +
36 + Ref : ERROR_SPEC @ RFC2205
37 +
38 + IPv4 ERROR_SPEC object: Class = 6, C-Type = 1
39 + +-------------+-------------+-------------+-------------+
40 + | IPv4 Error Node Address (4 bytes) |
41 + +-------------+-------------+-------------+-------------+
42 + | Flags | Error Code | Error Value |
43 + +-------------+-------------+-------------+-------------+
44 +
45 + */
46 +
47 + PcepRsvpSpecObjHeader objHeader;
48 + public static final byte CLASS_NUM = 0x06;
49 + public static final byte CLASS_TYPE = 0x01;
50 + public static final byte CLASS_LENGTH = 0x0c;
51 + private int ipv4Addr;
52 + private byte flags;
53 + private byte errCode;
54 + private short errValue;
55 +
56 + /**
57 + * Constructor to initialize obj header, ipv4 addr, flags, err code and err value.
58 + *
59 + * @param objHeader rsvp ipv4 error spec object header
60 + * @param ipv4Addr ipv4 address
61 + * @param flags flags value
62 + * @param errCode error code value
63 + * @param errValue error value
64 + */
65 + public PcepRsvpIpv4ErrorSpec(PcepRsvpSpecObjHeader objHeader, int ipv4Addr, byte flags, byte errCode,
66 + short errValue) {
67 + this.objHeader = objHeader;
68 + this.ipv4Addr = ipv4Addr;
69 + this.flags = flags;
70 + this.errCode = errCode;
71 + this.errValue = errValue;
72 + }
73 +
74 + /**
75 + * Constructor to initialize ipv4 address, flags, err code and err value.
76 + *
77 + * @param ipv4Addr ipv4 address
78 + * @param flags flags value
79 + * @param errCode error code
80 + * @param errValue error value
81 + */
82 + public PcepRsvpIpv4ErrorSpec(int ipv4Addr, byte flags, byte errCode, short errValue) {
83 + this.objHeader = new PcepRsvpSpecObjHeader(CLASS_LENGTH, CLASS_NUM, CLASS_TYPE);
84 + this.ipv4Addr = ipv4Addr;
85 + this.flags = flags;
86 + this.errCode = errCode;
87 + this.errValue = errValue;
88 + }
89 +
90 + @Override
91 + public int write(ChannelBuffer cb) {
92 + int objLenIndex = objHeader.write(cb);
93 + cb.writeInt(ipv4Addr);
94 + cb.writeByte(flags);
95 + cb.writeByte(errCode);
96 + cb.writeShort(errValue);
97 + short objLen = (short) (cb.writerIndex() - objLenIndex);
98 + cb.setShort(objLenIndex, objLen);
99 + return objLen;
100 + }
101 +
102 + /**
103 + * Reads PCPE RSVP error spec from channel buffer and returns PCEP rsvp IPv4 error spec object.
104 + *
105 + * @param cb channel buffer
106 + * @return PCEP rsvp IPv4 error spec object
107 + */
108 + public static PcepRsvpErrorSpec read(ChannelBuffer cb) {
109 + PcepRsvpSpecObjHeader objHeader;
110 + int ipv4Addr;
111 + byte flags;
112 + byte errCode;
113 + short errValue;
114 +
115 + objHeader = PcepRsvpSpecObjHeader.read(cb);
116 + ipv4Addr = cb.readInt();
117 + flags = cb.readByte();
118 + errCode = cb.readByte();
119 + errValue = cb.readShort();
120 + return new PcepRsvpIpv4ErrorSpec(objHeader, ipv4Addr, flags, errCode, errValue);
121 + }
122 +
123 + @Override
124 + public PcepVersion getVersion() {
125 + return PcepVersion.PCEP_1;
126 + }
127 +
128 + @Override
129 + public short getType() {
130 + return StatefulRsvpErrorSpecTlv.TYPE;
131 + }
132 +
133 + @Override
134 + public short getLength() {
135 + return CLASS_LENGTH;
136 + }
137 +
138 + @Override
139 + public byte getClassNum() {
140 + return CLASS_NUM;
141 + }
142 +
143 + @Override
144 + public byte getClassType() {
145 + return CLASS_TYPE;
146 + }
147 +
148 + @Override
149 + public void print() {
150 + // TODO Auto-generated method stub
151 + }
152 +
153 + @Override
154 + public String toString() {
155 + return MoreObjects.toStringHelper(getClass())
156 + .add("IPv4 Address:", ipv4Addr)
157 + .add("flags:", flags)
158 + .add("error Code:", errCode)
159 + .add("error Value:", errValue)
160 + .toString();
161 + }
162 +}
1 +package org.onosproject.pcepio.types;
2 +
3 +import org.jboss.netty.buffer.ChannelBuffer;
4 +import org.onosproject.pcepio.protocol.PcepVersion;
5 +
6 +import com.google.common.base.MoreObjects;
7 +
8 +public class PcepRsvpIpv6ErrorSpec implements PcepRsvpErrorSpec {
9 +
10 + /*
11 + 0 1 2 3
12 + +-------------+-------------+-------------+-------------+
13 + | Length (bytes) | Class-Num | C-Type |
14 + +-------------+-------------+-------------+-------------+
15 + | |
16 + // (Object contents) //
17 + | |
18 + +-------------+-------------+-------------+-------------+
19 +
20 + Ref : ERROR_SPEC @ RFC2205
21 +
22 + IPv6 ERROR_SPEC object: Class = 6, C-Type = 2
23 + +-------------+-------------+-------------+-------------+
24 + | |
25 + + +
26 + | |
27 + + IPv6 Error Node Address (16 bytes) +
28 + | |
29 + + +
30 + | |
31 + +-------------+-------------+-------------+-------------+
32 + | Flags | Error Code | Error Value |
33 + +-------------+-------------+-------------+-------------+ */
34 +
35 + PcepRsvpSpecObjHeader objHeader;
36 + public static final byte CLASS_NUM = 0x06;
37 + public static final byte CLASS_TYPE = 0x02;
38 + public static final byte CLASS_LENGTH = 0x18;
39 + public static final byte IPV6_LEN = 0x10;
40 +
41 + private byte[] ipv6Addr;
42 + private byte flags;
43 + private byte errCode;
44 + private short errValue;
45 +
46 + /**
47 + * Constructor to initialize obj header, ipv6 addr, flags, err code and err value.
48 + *
49 + * @param objHeader rsvp ipv6 error spec object header
50 + * @param ipv6Addr ipv6 address
51 + * @param flags flags value
52 + * @param errCode error code
53 + * @param errValue error value
54 + */
55 + public PcepRsvpIpv6ErrorSpec(PcepRsvpSpecObjHeader objHeader, byte[] ipv6Addr, byte flags, byte errCode,
56 + short errValue) {
57 + this.objHeader = objHeader;
58 + this.ipv6Addr = ipv6Addr;
59 + this.flags = flags;
60 + this.errCode = errCode;
61 + this.errValue = errValue;
62 + }
63 +
64 + /**
65 + * Constructor to initialize ipv6 addr, flags, err code and err value.
66 + *
67 + * @param ipv6Addr ipv6 address
68 + * @param flags flags value
69 + * @param errCode error code
70 + * @param errValue error value
71 + */
72 + public PcepRsvpIpv6ErrorSpec(byte[] ipv6Addr, byte flags, byte errCode, short errValue) {
73 + this.objHeader = new PcepRsvpSpecObjHeader(CLASS_LENGTH, CLASS_NUM, CLASS_TYPE);
74 + this.ipv6Addr = ipv6Addr;
75 + this.flags = flags;
76 + this.errCode = errCode;
77 + this.errValue = errValue;
78 + }
79 +
80 + @Override
81 + public int write(ChannelBuffer cb) {
82 + int objLenIndex = objHeader.write(cb);
83 + cb.writeBytes(ipv6Addr);
84 + cb.writeByte(flags);
85 + cb.writeByte(errCode);
86 + cb.writeShort(errValue);
87 + short objLen = (short) (cb.writerIndex() - objLenIndex);
88 + cb.setShort(objLenIndex, objLen);
89 + return objLen;
90 + }
91 +
92 + /**
93 + * Returns PCEP rsvp IPv6 error spce object.
94 + *
95 + * @param cb channel buffer
96 + * @return PCEP rsvp IPv6 error spce object
97 + */
98 + public static PcepRsvpErrorSpec read(ChannelBuffer cb) {
99 + PcepRsvpSpecObjHeader objHeader;
100 + byte[] ipv6Addr = new byte[IPV6_LEN];
101 + byte flags;
102 + byte errCode;
103 + short errValue;
104 +
105 + objHeader = PcepRsvpSpecObjHeader.read(cb);
106 + cb.readBytes(ipv6Addr, 0, IPV6_LEN);
107 + flags = cb.readByte();
108 + errCode = cb.readByte();
109 + errValue = cb.readShort();
110 + return new PcepRsvpIpv6ErrorSpec(objHeader, ipv6Addr, flags, errCode, errValue);
111 + }
112 +
113 + @Override
114 + public PcepVersion getVersion() {
115 + return PcepVersion.PCEP_1;
116 + }
117 +
118 + @Override
119 + public short getType() {
120 + return StatefulRsvpErrorSpecTlv.TYPE;
121 + }
122 +
123 + @Override
124 + public short getLength() {
125 + return CLASS_LENGTH;
126 + }
127 +
128 + @Override
129 + public byte getClassNum() {
130 + return CLASS_NUM;
131 + }
132 +
133 + @Override
134 + public byte getClassType() {
135 + return CLASS_TYPE;
136 + }
137 +
138 + @Override
139 + public void print() {
140 + // TODO Auto-generated method stub
141 + }
142 +
143 + @Override
144 + public String toString() {
145 + return MoreObjects.toStringHelper(getClass())
146 + .add("IPv6 Address:", ipv6Addr)
147 + .add("flags:", flags)
148 + .add("error Code:", errCode)
149 + .add("error Value:", errValue)
150 + .toString();
151 + }
152 +}
...@@ -20,6 +20,8 @@ import org.jboss.netty.buffer.ChannelBuffer; ...@@ -20,6 +20,8 @@ import org.jboss.netty.buffer.ChannelBuffer;
20 import org.slf4j.Logger; 20 import org.slf4j.Logger;
21 import org.slf4j.LoggerFactory; 21 import org.slf4j.LoggerFactory;
22 22
23 +import com.google.common.base.MoreObjects;
24 +
23 /** 25 /**
24 * Provides PcepRsvpObjectHeader. 26 * Provides PcepRsvpObjectHeader.
25 */ 27 */
...@@ -36,7 +38,7 @@ public class PcepRsvpObjectHeader { ...@@ -36,7 +38,7 @@ public class PcepRsvpObjectHeader {
36 +-------------+-------------+-------------+-------------+ 38 +-------------+-------------+-------------+-------------+
37 39
38 ERROR_SPEC object Header 40 ERROR_SPEC object Header
39 - */ 41 + */
40 42
41 protected static final Logger log = LoggerFactory.getLogger(PcepRsvpObjectHeader.class); 43 protected static final Logger log = LoggerFactory.getLogger(PcepRsvpObjectHeader.class);
42 44
...@@ -158,4 +160,13 @@ public class PcepRsvpObjectHeader { ...@@ -158,4 +160,13 @@ public class PcepRsvpObjectHeader {
158 log.debug("Object C-Type: " + objClassType); 160 log.debug("Object C-Type: " + objClassType);
159 log.debug("Object Length: " + objLen); 161 log.debug("Object Length: " + objLen);
160 } 162 }
163 +
164 + @Override
165 + public String toString() {
166 + return MoreObjects.toStringHelper(getClass())
167 + .add("Object Class-Num: " , objClassNum)
168 + .add("Object C-Type: " , objClassType)
169 + .add("Object Length: " , objLen)
170 + .toString();
171 + }
161 } 172 }
......
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 org.jboss.netty.buffer.ChannelBuffer;
20 +import org.slf4j.Logger;
21 +import org.slf4j.LoggerFactory;
22 +
23 +import com.google.common.base.MoreObjects;
24 +
25 +/**
26 + * Provides PcepRsvpObjectHeader.
27 + */
28 +public class PcepRsvpSpecObjHeader {
29 +
30 + /*
31 + 0 1 2 3
32 + +-------------+-------------+-------------+-------------+
33 + | Length (bytes) | Class-Num | C-Type |
34 + +-------------+-------------+-------------+-------------+
35 + | |
36 + // (Object contents) //
37 + | |
38 + +-------------+-------------+-------------+-------------+
39 +
40 + ERROR_SPEC object Header
41 + */
42 +
43 + protected static final Logger log = LoggerFactory.getLogger(PcepRsvpSpecObjHeader.class);
44 +
45 + private short objLen;
46 + private byte objClassNum;
47 + private byte objClassType;
48 +
49 + /**
50 + * Constructor to initialize length, class num and type.
51 + *
52 + * @param objLen object length
53 + * @param objClassNum pcep rsvp error spec object class num
54 + * @param objClassType pcep rsvp error spec object class type
55 + */
56 + public PcepRsvpSpecObjHeader(short objLen, byte objClassNum, byte objClassType) {
57 + this.objLen = objLen;
58 + this.objClassNum = objClassNum;
59 + this.objClassType = objClassType;
60 + }
61 +
62 + /**
63 + * Sets the Class num.
64 + *
65 + * @param value pcep rsvp error spec object class num
66 + */
67 + public void setObjClassNum(byte value) {
68 + this.objClassNum = value;
69 + }
70 +
71 + /**
72 + * Sets the Class type.
73 + *
74 + * @param value pcep rsvp error spec object class type
75 + */
76 + public void setObjClassType(byte value) {
77 + this.objClassType = value;
78 + }
79 +
80 + /**
81 + * Sets the Class Length.
82 + *
83 + * @param value pcep rsvp error spec object length
84 + */
85 + public void setObjLen(short value) {
86 + this.objLen = value;
87 + }
88 +
89 + /**
90 + * Returns Object Length.
91 + *
92 + * @return objLen pcep rsvp error spec object length
93 + */
94 + public short getObjLen() {
95 + return this.objLen;
96 + }
97 +
98 + /**
99 + * Returns Object num.
100 + *
101 + * @return objClassNum pcep rsvp error spec object class num
102 + */
103 + public byte getObjClassNum() {
104 + return this.objClassNum;
105 + }
106 +
107 + /**
108 + * Returns Object type.
109 + *
110 + * @return objClassType pcep rsvp error spec object class type
111 + */
112 + public byte getObjClassType() {
113 + return this.objClassType;
114 + }
115 +
116 + /**
117 + * Writes the byte stream of PcepRsvpObjectHeader to channel buffer.
118 + *
119 + * @param bb of type channel buffer
120 + * @return object length index
121 + */
122 + public int write(ChannelBuffer bb) {
123 + int objLenIndex = bb.writerIndex();
124 + bb.writeShort(objLen);
125 + bb.writeByte(objClassNum);
126 + bb.writeByte(objClassType);
127 + return bb.writerIndex() - objLenIndex;
128 + }
129 +
130 + /**
131 + * Reads the PcepRsvpObjectHeader.
132 + *
133 + * @param bb of type channel buffer
134 + * @return PcepRsvpObjectHeader
135 + */
136 + public static PcepRsvpSpecObjHeader read(ChannelBuffer bb) {
137 + byte objClassNum;
138 + byte objClassType;
139 + short objLen;
140 + objLen = bb.readShort();
141 + objClassNum = bb.readByte();
142 + objClassType = bb.readByte();
143 +
144 + return new PcepRsvpSpecObjHeader(objLen, objClassNum, objClassType);
145 + }
146 +
147 + /**
148 + * Prints the attribute of PcepRsvpObjectHeader.
149 + */
150 + public void print() {
151 +
152 + log.debug("PcepObjectHeader");
153 + log.debug("Object Class-Num: " + objClassNum);
154 + log.debug("Object C-Type: " + objClassType);
155 + log.debug("Object Length: " + objLen);
156 + }
157 + @Override
158 + public String toString() {
159 + return MoreObjects.toStringHelper(getClass())
160 + .add("Object Class-Num: " , objClassNum)
161 + .add("Object C-Type: " , objClassType)
162 + .add("Object Length: " , objLen)
163 + .toString();
164 + }
165 +}
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.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.PcepVersion;
24 +
25 +import com.google.common.base.MoreObjects;
26 +
27 +public class PcepRsvpUserErrorSpec implements PcepRsvpErrorSpec {
28 +
29 + /*
30 + RSVP error spec object header.
31 + 0 1 2 3
32 + +-------------+-------------+-------------+-------------+
33 + | Length (bytes) | Class-Num | C-Type |
34 + +-------------+-------------+-------------+-------------+
35 + | |
36 + // (Object contents) //
37 + | |
38 + +-------------+-------------+-------------+-------------+
39 +
40 + Ref : USER_ERROR_SPEC @ RFC5284.
41 + USER_ERROR_SPEC object: Class = 194, C-Type = 1
42 +
43 + 0 1 2 3
44 + 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
45 + +---------------+---------------+---------------+---------------+
46 + | Enterprise Number |
47 + +---------------+---------------+---------------+---------------+
48 + | Sub Org | Err Desc Len | User Error Value |
49 + +---------------+---------------+---------------+---------------+
50 + | |
51 + ~ Error Description ~
52 + | |
53 + +---------------+---------------+---------------+---------------+
54 + | |
55 + ~ User-Defined Subobjects ~
56 + | |
57 + +---------------+---------------+---------------+---------------+
58 + */
59 +
60 + public static final byte CLASS_NUM = (byte) 0xc2;
61 + public static final byte CLASS_TYPE = 0x01;
62 +
63 + private PcepRsvpSpecObjHeader objHeader;
64 + private int enterpriseNum;
65 + private byte subOrg;
66 + private byte errDescLen;
67 + private short userErrorValue;
68 + private byte[] errDesc;
69 + private LinkedList<PcepValueType> llRsvpUserSpecSubObj;
70 +
71 + /**
72 + * Default constructor.
73 + *
74 + * @param objHeader pcep rsvp spec object header
75 + * @param enterpriseNum enterprise number
76 + * @param subOrg organization identifier value
77 + * @param errDescLen error description length
78 + * @param userErrorValue user error value
79 + * @param errDesc error description
80 + * @param llRsvpUserSpecSubObj list of subobjects
81 + */
82 + public PcepRsvpUserErrorSpec(PcepRsvpSpecObjHeader objHeader, int enterpriseNum, byte subOrg, byte errDescLen,
83 + short userErrorValue, byte[] errDesc, LinkedList<PcepValueType> llRsvpUserSpecSubObj) {
84 + this.objHeader = objHeader;
85 + this.enterpriseNum = enterpriseNum;
86 + this.subOrg = subOrg;
87 + this.errDescLen = errDescLen;
88 + this.userErrorValue = userErrorValue;
89 + this.errDesc = errDesc;
90 + this.llRsvpUserSpecSubObj = llRsvpUserSpecSubObj;
91 + }
92 +
93 + @Override
94 + public int write(ChannelBuffer cb) {
95 + int objLenIndex = objHeader.write(cb);
96 + cb.writeInt(enterpriseNum);
97 + cb.writeByte(subOrg);
98 + cb.writeByte(errDescLen);
99 + cb.writeShort(userErrorValue);
100 + cb.writeBytes(errDesc);
101 +
102 + if (null != llRsvpUserSpecSubObj) {
103 +
104 + ListIterator<PcepValueType> listIterator = llRsvpUserSpecSubObj.listIterator();
105 +
106 + while (listIterator.hasNext()) {
107 + PcepValueType tlv = listIterator.next();
108 + if (null == tlv) {
109 + continue;
110 + }
111 + tlv.write(cb);
112 + // need to take care of padding
113 + int pad = tlv.getLength() % 4;
114 + if (0 != pad) {
115 + pad = 4 - pad;
116 + for (int i = 0; i < pad; ++i) {
117 + cb.writeByte((byte) 0);
118 + }
119 + }
120 + }
121 + }
122 + short objLen = (short) (cb.writerIndex() - objLenIndex);
123 + cb.setShort(objLenIndex, objLen);
124 + return objLen;
125 + }
126 +
127 + /**
128 + * Reads the channel buffer and returns object of PcepRsvpErrorSpec.
129 + *
130 + * @param cb of type channel buffer
131 + * @return object of PcepRsvpErrorSpec
132 + * @throws PcepParseException when expected object is not received
133 + */
134 + public static PcepRsvpErrorSpec read(ChannelBuffer cb) throws PcepParseException {
135 + PcepRsvpSpecObjHeader objHeader;
136 + int enterpriseNum;
137 + byte subOrg;
138 + byte errDescLen;
139 + short userErrorValue;
140 + byte[] errDesc;
141 + LinkedList<PcepValueType> llRsvpUserSpecSubObj = null;
142 +
143 + objHeader = PcepRsvpSpecObjHeader.read(cb);
144 +
145 + if (CLASS_NUM != objHeader.getObjClassNum() || CLASS_TYPE != objHeader.getObjClassType()) {
146 + throw new PcepParseException("Expected PcepRsvpUserErrorSpec object.");
147 + }
148 + enterpriseNum = cb.readInt();
149 + subOrg = cb.readByte();
150 + errDescLen = cb.readByte();
151 + userErrorValue = cb.readShort();
152 + errDesc = new byte[errDescLen];
153 + cb.readBytes(errDesc, 0, errDescLen);
154 +
155 + llRsvpUserSpecSubObj = parseErrSpecSubObj(cb);
156 +
157 + return new PcepRsvpUserErrorSpec(objHeader, enterpriseNum, subOrg, errDescLen, userErrorValue, errDesc,
158 + llRsvpUserSpecSubObj);
159 + }
160 +
161 + private static LinkedList<PcepValueType> parseErrSpecSubObj(ChannelBuffer cb) throws PcepParseException {
162 + LinkedList<PcepValueType> llRsvpUserSpecSubObj = new LinkedList<PcepValueType>();
163 + while (0 < cb.readableBytes()) {
164 + PcepValueType tlv = null;
165 + short hType = cb.readShort();
166 + int iValue = 0;
167 + //short hLength = cb.readShort();
168 + switch (hType) {
169 + case AutonomousSystemTlv.TYPE:
170 + iValue = cb.readInt();
171 + tlv = new AutonomousSystemTlv(iValue);
172 + break;
173 + default:
174 + throw new PcepParseException("Unsupported Sub TLV type :" + hType);
175 + }
176 + llRsvpUserSpecSubObj.add(tlv);
177 + }
178 + return llRsvpUserSpecSubObj;
179 + }
180 +
181 + @Override
182 + public PcepVersion getVersion() {
183 + return PcepVersion.PCEP_1;
184 + }
185 +
186 + @Override
187 + public short getType() {
188 + return StatefulRsvpErrorSpecTlv.TYPE;
189 + }
190 +
191 + @Override
192 + public short getLength() {
193 + return objHeader.getObjLen();
194 + }
195 +
196 + @Override
197 + public byte getClassNum() {
198 + return CLASS_NUM;
199 + }
200 +
201 + @Override
202 + public byte getClassType() {
203 + return CLASS_TYPE;
204 + }
205 +
206 + @Override
207 + public void print() {
208 + // TODO Auto-generated method stub
209 + }
210 +
211 + @Override
212 + public String toString() {
213 + return MoreObjects.toStringHelper(getClass())
214 + .add("enterprise Number:", enterpriseNum)
215 + .add("sub Organization:", subOrg)
216 + .add("err Desc Length:", errDescLen)
217 + .add("user Error Value:", userErrorValue)
218 + .add("err Desc:", errDesc)
219 + .add("Rsvp User Spec Sub Object:", llRsvpUserSpecSubObj)
220 + .toString();
221 + }
222 +}
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 StatefulIPv4LspIdentidiersTlv.
30 + */
31 +public class StatefulIPv4LspIdentidiersTlv implements PcepValueType {
32 +
33 + /* IPV4-LSP-IDENTIFIERS TLV format
34 + *
35 + * Reference :PCEP Extensions for Stateful PCE draft-ietf-pce-stateful-pce-10
36 + *
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 + | Type=18 | Length=16 |
42 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
43 + | IPv4 Tunnel Sender Address |
44 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
45 + | LSP ID | Tunnel ID |
46 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
47 + | Extended Tunnel ID |
48 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
49 + | IPv4 Tunnel Endpoint Address |
50 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
51 +
52 + */
53 + protected static final Logger log = LoggerFactory.getLogger(StatefulIPv4LspIdentidiersTlv.class);
54 +
55 + public static final short TYPE = 18;
56 + public static final short LENGTH = 16;
57 + public static final int VALUE_LENGTH = 16;
58 + private final int ipv4IngressAddress;
59 + private final short lspId;
60 + private final short tunnelId;
61 + private final int extendedTunnelId;
62 + private final int ipv4EgressAddress;
63 +
64 + /**
65 + * Constructor to initialize member variables.
66 + *
67 + * @param ipv4IngressAddress ingress ipv4 address
68 + * @param lspId lsp id
69 + * @param tunnelId tunnel id
70 + * @param extendedTunnelId extended tunnel id
71 + * @param ipv4EgressAddress egress ipv4 address
72 + */
73 + public StatefulIPv4LspIdentidiersTlv(int ipv4IngressAddress, short lspId, short tunnelId, int extendedTunnelId,
74 + int ipv4EgressAddress) {
75 +
76 + this.ipv4IngressAddress = ipv4IngressAddress;
77 + this.lspId = lspId;
78 + this.tunnelId = tunnelId;
79 + this.extendedTunnelId = extendedTunnelId;
80 + this.ipv4EgressAddress = ipv4EgressAddress;
81 + }
82 +
83 + /**
84 + * Creates object of StatefulIPv4LspIdentidiersTlv.
85 + *
86 + * @param ipv4IngressAddress ingress ipv4 address
87 + * @param lspId lsp id
88 + * @param tunnelId tunnel id
89 + * @param extendedTunnelId extended tunnel id
90 + * @param ipv4EgressAddress egress ipv4 address
91 + * @return object of StatefulIPv4LspIdentidiersTlv
92 + */
93 + public static StatefulIPv4LspIdentidiersTlv of(int ipv4IngressAddress, short lspId, short tunnelId,
94 + int extendedTunnelId, int ipv4EgressAddress) {
95 + return new StatefulIPv4LspIdentidiersTlv(ipv4IngressAddress, lspId, tunnelId, extendedTunnelId,
96 + ipv4EgressAddress);
97 + }
98 +
99 + /**
100 + * Returns tunnel id.
101 + *
102 + * @return tunnelId
103 + */
104 + public short getTunnelId() {
105 + return this.tunnelId;
106 + }
107 +
108 + /**
109 + * Returns extendedTunnelId.
110 + *
111 + * @return extendedTunnelId
112 + */
113 + public int getextendedTunnelId() {
114 + return this.extendedTunnelId;
115 + }
116 +
117 + @Override
118 + public PcepVersion getVersion() {
119 + return PcepVersion.PCEP_1;
120 + }
121 +
122 + /**
123 + * Returns ipv4IngressAddress.
124 + *
125 + * @return ipv4IngressAddress
126 + */
127 + public int getIpv4IngressAddress() {
128 + return ipv4IngressAddress;
129 + }
130 +
131 + /**
132 + * Returns ipv4EgressAddress.
133 + *
134 + * @return ipv4EgressAddress
135 + */
136 + public int getIpv4EgressAddress() {
137 + return ipv4EgressAddress;
138 + }
139 +
140 + @Override
141 + public short getType() {
142 + return TYPE;
143 + }
144 +
145 + @Override
146 + public short getLength() {
147 + return LENGTH;
148 + }
149 +
150 + @Override
151 + public int hashCode() {
152 + return Objects.hash(ipv4IngressAddress, lspId, tunnelId, extendedTunnelId, ipv4EgressAddress);
153 + }
154 +
155 + @Override
156 + public boolean equals(Object obj) {
157 + if (this == obj) {
158 + return true;
159 + }
160 + if (obj instanceof StatefulIPv4LspIdentidiersTlv) {
161 + StatefulIPv4LspIdentidiersTlv other = (StatefulIPv4LspIdentidiersTlv) obj;
162 + return Objects.equals(this.ipv4IngressAddress, other.ipv4IngressAddress)
163 + && Objects.equals(this.lspId, other.lspId) && Objects.equals(this.tunnelId, other.tunnelId)
164 + && Objects.equals(this.extendedTunnelId, other.extendedTunnelId)
165 + && Objects.equals(this.ipv4EgressAddress, other.ipv4EgressAddress);
166 + }
167 + return false;
168 + }
169 +
170 + @Override
171 + public int write(ChannelBuffer c) {
172 + int iLenStartIndex = c.writerIndex();
173 + c.writeShort(TYPE);
174 + c.writeShort(LENGTH);
175 + c.writeInt(ipv4IngressAddress);
176 + c.writeShort(lspId);
177 + c.writeShort(tunnelId);
178 + c.writeInt(extendedTunnelId);
179 + c.writeInt(ipv4EgressAddress);
180 +
181 + return c.writerIndex() - iLenStartIndex;
182 + }
183 +
184 + /**
185 + * Reads the channel buffer and returns object of StatefulIPv4LspIdentidiersTlv.
186 + *
187 + * @param c of type channel buffer
188 + * @return object of StatefulIPv4LspIdentidiersTlv
189 + */
190 + public static PcepValueType read(ChannelBuffer c) {
191 + int ipv4IngressAddress = c.readInt();
192 + short lspId = c.readShort();
193 + short tunnelId = c.readShort();
194 + int extendedTunnelId = c.readInt();
195 + int ipv4EgressAddress = c.readInt();
196 + return new StatefulIPv4LspIdentidiersTlv(ipv4IngressAddress, lspId, tunnelId, extendedTunnelId,
197 + ipv4EgressAddress);
198 + }
199 +
200 + @Override
201 + public void print() {
202 +
203 + log.debug("StatefulIPv4LspIdentidiersTlv");
204 + log.debug("Type: " + TYPE);
205 + log.debug("Length: " + LENGTH);
206 + log.debug("Ipv4IngressAddress: " + ipv4IngressAddress);
207 + log.debug("LspId: " + lspId);
208 + log.debug("TunnelId: " + tunnelId);
209 + log.debug("ExtendedTunnelId: " + extendedTunnelId);
210 + log.debug("Ipv4EgressAddress: " + ipv4EgressAddress);
211 + }
212 +
213 + @Override
214 + public String toString() {
215 + return MoreObjects.toStringHelper(getClass())
216 + .add("Type:", TYPE)
217 + .add("Length:", LENGTH)
218 + .add("Ipv4IngressAddress:", ipv4IngressAddress)
219 + .add("LspId:", lspId)
220 + .add("TunnelId:", tunnelId)
221 + .add("ExtendedTunnelId:", extendedTunnelId)
222 + .add("Ipv4EgressAddress:", ipv4EgressAddress)
223 + .toString();
224 + }
225 +}
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 StatefulLspErrorCodeTlv.
30 + */
31 +public class StatefulLspErrorCodeTlv implements PcepValueType {
32 +
33 + /* LSP-ERROR-CODE TLV format
34 + *
35 + * Reference :PCEP Extensions for Stateful PCE draft-ietf-pce-stateful-pce-10
36 + *
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 + | Type=20 | Length=4 |
42 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
43 + | LSP Error Code |
44 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
45 +
46 + */
47 +
48 + protected static final Logger log = LoggerFactory.getLogger(StatefulLspErrorCodeTlv.class);
49 +
50 + public static final short TYPE = 20;
51 + public static final short LENGTH = 4;
52 + private final int rawValue;
53 +
54 + /**
55 + * Constructor to initialize raw Value.
56 + *
57 + * @param rawValue lsp error code value
58 + */
59 + public StatefulLspErrorCodeTlv(int rawValue) {
60 + this.rawValue = rawValue;
61 + }
62 +
63 + /**
64 + * Creates object of StatefulLspErrorCodeTlv.
65 + *
66 + * @param raw lsp error code value
67 + * @return object of StatefulLspErrorCodeTlv
68 + */
69 + public static StatefulLspErrorCodeTlv of(int raw) {
70 + return new StatefulLspErrorCodeTlv(raw);
71 + }
72 +
73 + @Override
74 + public PcepVersion getVersion() {
75 + return PcepVersion.PCEP_1;
76 + }
77 +
78 + /**
79 + * Returns lsp error code value.
80 + *
81 + * @return lsp error code value
82 + */
83 + public int getInt() {
84 + return rawValue;
85 + }
86 +
87 + @Override
88 + public short getLength() {
89 + return LENGTH;
90 + }
91 +
92 + @Override
93 + public short getType() {
94 + return TYPE;
95 + }
96 +
97 + @Override
98 + public int hashCode() {
99 + return Objects.hash(rawValue);
100 + }
101 +
102 + @Override
103 + public boolean equals(Object obj) {
104 + if (this == obj) {
105 + return true;
106 + }
107 + if (obj instanceof StatefulLspErrorCodeTlv) {
108 + StatefulLspErrorCodeTlv other = (StatefulLspErrorCodeTlv) obj;
109 + return Objects.equals(this.rawValue, other.rawValue);
110 + }
111 + return false;
112 + }
113 +
114 + @Override
115 + public int write(ChannelBuffer c) {
116 + int iLenStartIndex = c.writerIndex();
117 + c.writeShort(TYPE);
118 + c.writeShort(LENGTH);
119 + c.writeInt(rawValue);
120 + return c.writerIndex() - iLenStartIndex;
121 + }
122 +
123 + /**
124 + * Reads the channel buffer and returns object of StatefulLspErrorCodeTlv.
125 + *
126 + * @param c of type channel buffer
127 + * @return object of StatefulLspErrorCodeTlv
128 + */
129 + public static StatefulLspErrorCodeTlv read(ChannelBuffer c) {
130 + return StatefulLspErrorCodeTlv.of(c.readInt());
131 + }
132 +
133 + @Override
134 + public void print() {
135 +
136 + log.debug("StatefulLspErrorCodeTlv");
137 + log.debug("Type: " + TYPE);
138 + log.debug("Length: " + LENGTH);
139 + log.debug("Value: " + rawValue);
140 + }
141 +
142 + @Override
143 + public String toString() {
144 + return MoreObjects.toStringHelper(getClass()).add("Type", TYPE).add("Length", LENGTH).add("Value", rawValue)
145 + .toString();
146 + }
147 +
148 +}
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.exceptions.PcepParseException;
23 +import org.onosproject.pcepio.protocol.PcepVersion;
24 +import org.slf4j.Logger;
25 +import org.slf4j.LoggerFactory;
26 +
27 +import com.google.common.base.MoreObjects;
28 +import com.google.common.base.MoreObjects.ToStringHelper;
29 +
30 +/**
31 + * Provides StatefulRsvpErrorSpecTlv.
32 + */
33 +public class StatefulRsvpErrorSpecTlv implements PcepValueType {
34 +
35 + protected static final Logger log = LoggerFactory.getLogger(StatefulRsvpErrorSpecTlv.class);
36 +
37 + /* RSVP-ERROR-SPEC TLV format
38 + * Reference :PCEP Extensions for Stateful PCE draft-ietf-pce-stateful-pce-10
39 + *
40 + *
41 +
42 + 0 1 2 3
43 + 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
44 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
45 + | Type=21 | Length (variable) |
46 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
47 + | |
48 + + RSVP ERROR_SPEC or USER_ERROR_SPEC Object +
49 + | |
50 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
51 +
52 + 0 1 2 3
53 + +-------------+-------------+-------------+-------------+
54 + | Length (bytes) | Class-Num | C-Type |
55 + +-------------+-------------+-------------+-------------+
56 + | |
57 + // (Object contents) //
58 + | |
59 + +-------------+-------------+-------------+-------------+
60 +
61 + Ref : ERROR_SPEC @ RFC2205
62 +
63 + IPv4 ERROR_SPEC object: Class = 6, C-Type = 1
64 + +-------------+-------------+-------------+-------------+
65 + | IPv4 Error Node Address (4 bytes) |
66 + +-------------+-------------+-------------+-------------+
67 + | Flags | Error Code | Error Value |
68 + +-------------+-------------+-------------+-------------+
69 +
70 +
71 + IPv6 ERROR_SPEC object: Class = 6, C-Type = 2
72 + +-------------+-------------+-------------+-------------+
73 + | |
74 + + +
75 + | |
76 + + IPv6 Error Node Address (16 bytes) +
77 + | |
78 + + +
79 + | |
80 + +-------------+-------------+-------------+-------------+
81 + | Flags | Error Code | Error Value |
82 + +-------------+-------------+-------------+-------------+
83 +
84 +
85 + Ref : USER_ERROR_SPEC @ RFC5284
86 + USER_ERROR_SPEC object: Class = 194, C-Type = 1
87 + 0 1 2 3
88 + 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
89 + +---------------+---------------+---------------+---------------+
90 + | Enterprise Number |
91 + +---------------+---------------+---------------+---------------+
92 + | Sub Org | Err Desc Len | User Error Value |
93 + +---------------+---------------+---------------+---------------+
94 + | |
95 + ~ Error Description ~
96 + | |
97 + +---------------+---------------+---------------+---------------+
98 + | |
99 + ~ User-Defined Subobjects ~
100 + | |
101 + +---------------+---------------+---------------+---------------+
102 +
103 + */
104 +
105 + public static final short TYPE = 21;
106 + public static final int OBJECT_HEADER_LENGTH = 4;
107 + private final short hLength;
108 +
109 + private final PcepRsvpErrorSpec rsvpErrSpecObj;
110 + private final boolean isErrSpceObjSet;
111 +
112 + /**
113 + * Constructor to initialize errSpecObj.
114 + *
115 + * @param rsvpErrSpecObj Rsvp error spec object
116 + * @param hLength length of rsvp error spec object
117 + */
118 + public StatefulRsvpErrorSpecTlv(PcepRsvpErrorSpec rsvpErrSpecObj, short hLength) {
119 + this.rsvpErrSpecObj = rsvpErrSpecObj;
120 + this.isErrSpceObjSet = true;
121 + this.hLength = hLength;
122 + }
123 +
124 + /**
125 + * Returns PcepRsvpErrorSpecObject.
126 + *
127 + * @return rsvpErrSpecObj
128 + */
129 + public PcepRsvpErrorSpec getPcepRsvpErrorSpec() {
130 + return this.rsvpErrSpecObj;
131 + }
132 +
133 + @Override
134 + public PcepVersion getVersion() {
135 + return PcepVersion.PCEP_1;
136 + }
137 +
138 + @Override
139 + public short getType() {
140 + return TYPE;
141 + }
142 +
143 + @Override
144 + public short getLength() {
145 + return hLength;
146 + }
147 +
148 + /**
149 + * Reads channel buffer and returns object of StatefulRsvpErrorSpecTlv.
150 + *
151 + * @param cb of type channel buffer
152 + * @return object of StatefulRsvpErrorSpecTlv
153 + */
154 + public static PcepValueType read(ChannelBuffer cb) throws PcepParseException {
155 +
156 + PcepRsvpErrorSpec rsvpErrSpecObj = null;
157 + PcepRsvpSpecObjHeader rsvpErrSpecObjHeader;
158 +
159 + cb.markReaderIndex();
160 + rsvpErrSpecObjHeader = PcepRsvpSpecObjHeader.read(cb);
161 + cb.resetReaderIndex();
162 +
163 + if (PcepRsvpIpv4ErrorSpec.CLASS_NUM == rsvpErrSpecObjHeader.getObjClassNum()
164 + && PcepRsvpIpv4ErrorSpec.CLASS_TYPE == rsvpErrSpecObjHeader.getObjClassType()) {
165 + rsvpErrSpecObj = PcepRsvpIpv4ErrorSpec.read(cb);
166 + } else if (PcepRsvpIpv6ErrorSpec.CLASS_NUM == rsvpErrSpecObjHeader.getObjClassNum()
167 + && PcepRsvpIpv6ErrorSpec.CLASS_TYPE == rsvpErrSpecObjHeader.getObjClassType()) {
168 + rsvpErrSpecObj = PcepRsvpIpv6ErrorSpec.read(cb);
169 + } else if (PcepRsvpUserErrorSpec.CLASS_NUM == rsvpErrSpecObjHeader.getObjClassNum()
170 + && PcepRsvpUserErrorSpec.CLASS_TYPE == rsvpErrSpecObjHeader.getObjClassType()) {
171 + rsvpErrSpecObj = PcepRsvpUserErrorSpec.read(cb);
172 + }
173 + return rsvpErrSpecObj;
174 + }
175 +
176 + @Override
177 + public int hashCode() {
178 + return Objects.hash(rsvpErrSpecObj.hashCode());
179 + }
180 +
181 + @Override
182 + public boolean equals(Object obj) {
183 + if (this == obj) {
184 + return true;
185 + }
186 + if (obj instanceof StatefulRsvpErrorSpecTlv) {
187 + StatefulRsvpErrorSpecTlv other = (StatefulRsvpErrorSpecTlv) obj;
188 + return Objects.equals(this.rsvpErrSpecObj, other.rsvpErrSpecObj);
189 + }
190 + return false;
191 + }
192 +
193 + @Override
194 + public int write(ChannelBuffer c) {
195 + int iStartIndex = c.writerIndex();
196 + c.writeShort(TYPE);
197 + int tlvLenIndex = c.writerIndex();
198 + c.writeShort(hLength);
199 + if (isErrSpceObjSet) {
200 + rsvpErrSpecObj.write(c);
201 + }
202 + short tlvLen = (short) (c.writerIndex() - iStartIndex + 4);
203 + c.setShort(tlvLenIndex, tlvLen);
204 +
205 + return tlvLen;
206 + }
207 +
208 + @Override
209 + public void print() {
210 +
211 + log.debug("StatefulRsvpErrorSpecTlv");
212 + log.debug("Type: " + TYPE);
213 + log.debug("Length: " + hLength);
214 + if (isErrSpceObjSet) {
215 + rsvpErrSpecObj.print();
216 + }
217 + }
218 +
219 + @Override
220 + public String toString() {
221 + ToStringHelper toStrHelper = MoreObjects.toStringHelper(getClass());
222 +
223 + if (!isErrSpceObjSet) {
224 + toStrHelper
225 + .add("Type", TYPE)
226 + .add("Length", hLength);
227 + } else {
228 + toStrHelper
229 + .add("Type", TYPE)
230 + .add("Length", hLength)
231 + .add("RSVP Error Spec Object", rsvpErrSpecObj);
232 + }
233 + return toStrHelper.toString();
234 + }
235 +}
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 SymbolicPathNameTlv.
30 + */
31 +public class SymbolicPathNameTlv implements PcepValueType {
32 +
33 + /*
34 + * SYMBOLIC-PATH-NAME TLV format
35 + * Reference :PCEP Extensions for Stateful PCE draft-ietf-pce-stateful-pce-10
36 + *
37 + 0 1 2 3
38 + 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
39 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
40 + | Type=17 | Length (variable) |
41 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
42 + | |
43 + // Symbolic Path Name //
44 + | |
45 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
46 + */
47 + protected static final Logger log = LoggerFactory.getLogger(SymbolicPathNameTlv.class);
48 +
49 + public static final short TYPE = 17;
50 + private short hLength;
51 +
52 + private final byte[] rawValue;
53 +
54 + /**
55 + * Constructor to initialize raw Value.
56 + *
57 + * @param rawValue Symbolic path name
58 + */
59 + public SymbolicPathNameTlv(byte[] rawValue) {
60 + this.rawValue = rawValue;
61 + this.hLength = (short) rawValue.length;
62 + }
63 +
64 + /**
65 + * Constructor to initialize raw Value.
66 + *
67 + * @param rawValue Symbolic path name
68 + * @param hLength length of Symbolic path name
69 + */
70 + public SymbolicPathNameTlv(byte[] rawValue, short hLength) {
71 + this.rawValue = rawValue;
72 + if (0 == hLength) {
73 + this.hLength = (short) rawValue.length;
74 + } else {
75 + this.hLength = hLength;
76 + }
77 + }
78 +
79 + /**
80 + * Creates an object of SymbolicPathNameTlv.
81 + *
82 + * @param raw Symbolic path name
83 + * @param hLength length of Symbolic path name
84 + * @return object of SymbolicPathNameTlv
85 + */
86 + public static SymbolicPathNameTlv of(final byte[] raw, short hLength) {
87 + return new SymbolicPathNameTlv(raw, hLength);
88 + }
89 +
90 + /**
91 + * Returns Symbolic path name.
92 + *
93 + * @return Symbolic path name byte array
94 + */
95 + public byte[] getValue() {
96 + return rawValue;
97 + }
98 +
99 + @Override
100 + public PcepVersion getVersion() {
101 + return PcepVersion.PCEP_1;
102 + }
103 +
104 + @Override
105 + public short getType() {
106 + return TYPE;
107 + }
108 +
109 + @Override
110 + public short getLength() {
111 + return hLength;
112 + }
113 +
114 + @Override
115 + public int hashCode() {
116 + return Objects.hash(rawValue);
117 + }
118 +
119 + @Override
120 + public boolean equals(Object obj) {
121 + if (this == obj) {
122 + return true;
123 + }
124 + if (obj instanceof SymbolicPathNameTlv) {
125 + SymbolicPathNameTlv other = (SymbolicPathNameTlv) obj;
126 + return Objects.equals(this.rawValue, other.rawValue);
127 + }
128 + return false;
129 + }
130 +
131 + @Override
132 + public int write(ChannelBuffer c) {
133 + int iLenStartIndex = c.writerIndex();
134 + c.writeShort(TYPE);
135 + c.writeShort(hLength);
136 + c.writeBytes(rawValue);
137 + return c.writerIndex() - iLenStartIndex;
138 + }
139 +
140 + /**
141 + * Reads channel buffer and returns object of SymbolicPathNameTlv.
142 + *
143 + * @param c of type channel buffer
144 + * @param hLength length of bytes to read
145 + * @return object of SymbolicPathNameTlv
146 + */
147 + public static SymbolicPathNameTlv read(ChannelBuffer c, short hLength) {
148 + byte[] symbolicPathName = new byte[hLength];
149 + c.readBytes(symbolicPathName, 0, hLength);
150 + return new SymbolicPathNameTlv(symbolicPathName, hLength);
151 + }
152 +
153 + @Override
154 + public void print() {
155 + log.debug("SymbolicPathNameTlv");
156 + log.debug("Type: " + TYPE);
157 + log.debug("Length: " + hLength);
158 + log.debug("Symbolic Path Name : " + rawValue);
159 + }
160 +
161 + @Override
162 + public String toString() {
163 + return MoreObjects.toStringHelper(getClass()).add("Symbolic Path Name ", rawValue).toString();
164 + }
165 +}
1 +/*
2 + * Copyright 2014-2015 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +package org.onosproject.pcepio;
17 +
18 +import org.jboss.netty.buffer.ChannelBuffer;
19 +import org.jboss.netty.buffer.ChannelBuffers;
20 +import org.junit.After;
21 +import org.junit.Assert;
22 +import org.junit.Before;
23 +import org.junit.Test;
24 +import org.onosproject.pcepio.exceptions.PcepParseException;
25 +import org.onosproject.pcepio.protocol.PcepFactories;
26 +import org.onosproject.pcepio.protocol.PcepMessage;
27 +import org.onosproject.pcepio.protocol.PcepMessageReader;
28 +import org.onosproject.pcepio.protocol.PcepCloseMsg;
29 +
30 +import java.util.Arrays;
31 +
32 +import org.slf4j.Logger;
33 +import org.slf4j.LoggerFactory;
34 +
35 +public class PcepCloseMsgTest {
36 + protected static final Logger log = LoggerFactory.getLogger(PcepCloseMsgTest.class);
37 +
38 + @Before
39 + public void startUp() {
40 + }
41 +
42 + @After
43 + public void tearDown() {
44 +
45 + }
46 +
47 + @Test
48 + public void closeMessageTest1() throws PcepParseException {
49 + byte[] closeMsg = new byte[] {0x20, 0x07, 0x00, 0x0C, /* common header */
50 + 0x0f, 0x10, 0x00, 0x08, 0x00, 0x00, 0x00, 0x02 };
51 +
52 + byte[] testCloseMsg = {0};
53 + ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
54 + buffer.writeBytes(closeMsg);
55 +
56 + PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader();
57 + PcepMessage message = null;
58 + try {
59 + message = reader.readFrom(buffer);
60 + } catch (PcepParseException e) {
61 + e.printStackTrace();
62 + }
63 +
64 + if (message instanceof PcepCloseMsg) {
65 + ChannelBuffer buf = ChannelBuffers.dynamicBuffer();
66 + message.writeTo(buf);
67 + testCloseMsg = buf.array();
68 +
69 + int iReadLen = buf.writerIndex() - 0;
70 + testCloseMsg = new byte[iReadLen];
71 + buf.readBytes(testCloseMsg, 0, iReadLen);
72 + if (Arrays.equals(closeMsg, testCloseMsg)) {
73 + Assert.assertArrayEquals(closeMsg, testCloseMsg);
74 + log.debug("CloseMsg are equal :" + closeMsg);
75 + } else {
76 + Assert.fail("test case failed");
77 + log.debug("not equal");
78 + }
79 + } else {
80 + Assert.fail("test case failed");
81 + log.debug("not equal");
82 + }
83 + }
84 +}