Committed by
Gerrit Code Review
[ONOS-2344]Implementation of PCEP report messages.
Change-Id: I9258a34ad7b09a583dcd0e56f90a36958c3acb34
Showing
5 changed files
with
1489 additions
and
0 deletions
pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepInterLayerObjectVer1.java
0 → 100644
1 | +/* | ||
2 | + * Copyright 2014 Open Networking Laboratory | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | +package org.onosproject.pcepio.protocol.ver1; | ||
17 | + | ||
18 | +import org.jboss.netty.buffer.ChannelBuffer; | ||
19 | +import org.onosproject.pcepio.exceptions.PcepParseException; | ||
20 | +import org.onosproject.pcepio.protocol.PcepInterLayerObject; | ||
21 | +import org.onosproject.pcepio.types.PcepObjectHeader; | ||
22 | +import org.slf4j.Logger; | ||
23 | +import org.slf4j.LoggerFactory; | ||
24 | + | ||
25 | +import com.google.common.base.MoreObjects; | ||
26 | + | ||
27 | +/* | ||
28 | + * 0 1 2 3 | ||
29 | + 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 | ||
30 | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
31 | + | Reserved |N|I| | ||
32 | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
33 | + */ | ||
34 | +public class PcepInterLayerObjectVer1 implements PcepInterLayerObject { | ||
35 | + | ||
36 | + protected static final Logger log = LoggerFactory.getLogger(PcepInterLayerObjectVer1.class); | ||
37 | + | ||
38 | + public static final byte INTER_LAYER_OBJ_TYPE = 1; | ||
39 | + public static final byte INTER_LAYER_OBJ_CLASS = 18; | ||
40 | + public static final byte INTER_LAYER_OBJECT_VERSION = 1; | ||
41 | + public static final short INTER_LAYER_OBJ_MINIMUM_LENGTH = 8; | ||
42 | + public static final boolean DEFAULT_IFLAG = false; | ||
43 | + public static final boolean DEFAULT_NFLAG = false; | ||
44 | + public static final int OBJECT_HEADER_LENGTH = 4; | ||
45 | + public static final int NFLAG_SHIFT_VALUE = 0x02; | ||
46 | + public static final int IFLAG_SHIFT_VALUE = 0x01; | ||
47 | + public static final int FLAGS_SET_VALUE = 1; | ||
48 | + | ||
49 | + static final PcepObjectHeader DEFAULT_INTER_LAYER_OBJECT_HEADER = new PcepObjectHeader(INTER_LAYER_OBJ_CLASS, | ||
50 | + INTER_LAYER_OBJ_TYPE, PcepObjectHeader.REQ_OBJ_OPTIONAL_PROCESS, PcepObjectHeader.RSP_OBJ_PROCESSED, | ||
51 | + INTER_LAYER_OBJ_MINIMUM_LENGTH); | ||
52 | + | ||
53 | + private PcepObjectHeader interLayerObjHeader; | ||
54 | + private boolean bNFlag; | ||
55 | + private boolean bIFlag; | ||
56 | + | ||
57 | + /** | ||
58 | + * Constructor to initialize all parameters for Pcep Inter Layer Object. | ||
59 | + * | ||
60 | + * @param interLayerObjHeader inter layer object header | ||
61 | + * @param bNFlag N flag | ||
62 | + * @param bIFlag I flag | ||
63 | + */ | ||
64 | + public PcepInterLayerObjectVer1(PcepObjectHeader interLayerObjHeader, boolean bNFlag, boolean bIFlag) { | ||
65 | + | ||
66 | + this.interLayerObjHeader = interLayerObjHeader; | ||
67 | + this.bNFlag = bNFlag; | ||
68 | + this.bIFlag = bIFlag; | ||
69 | + } | ||
70 | + | ||
71 | + /** | ||
72 | + * Sets Object Header. | ||
73 | + * | ||
74 | + * @param obj object header | ||
75 | + */ | ||
76 | + public void setInterLayerObjHeader(PcepObjectHeader obj) { | ||
77 | + this.interLayerObjHeader = obj; | ||
78 | + } | ||
79 | + | ||
80 | + @Override | ||
81 | + public void setbNFlag(boolean bNFlag) { | ||
82 | + this.bNFlag = bNFlag; | ||
83 | + } | ||
84 | + | ||
85 | + @Override | ||
86 | + public void setbIFlag(boolean bIFlag) { | ||
87 | + this.bIFlag = bIFlag; | ||
88 | + } | ||
89 | + | ||
90 | + /** | ||
91 | + * Returns object header. | ||
92 | + * | ||
93 | + * @return inter Layer Object Header | ||
94 | + */ | ||
95 | + public PcepObjectHeader getInterLayerObjHeader() { | ||
96 | + return this.interLayerObjHeader; | ||
97 | + } | ||
98 | + | ||
99 | + @Override | ||
100 | + public boolean getbNFlag() { | ||
101 | + return this.bNFlag; | ||
102 | + } | ||
103 | + | ||
104 | + @Override | ||
105 | + public boolean getbIFlag() { | ||
106 | + return this.bIFlag; | ||
107 | + } | ||
108 | + | ||
109 | + /** | ||
110 | + * Reads channel buffer and returns object of PcepInterLayerObject. | ||
111 | + * | ||
112 | + * @param cb of type channel buffer | ||
113 | + * @return object of PcepInterLayerObject | ||
114 | + * @throws PcepParseException when fails to read from channel buffer | ||
115 | + */ | ||
116 | + public static PcepInterLayerObject read(ChannelBuffer cb) throws PcepParseException { | ||
117 | + | ||
118 | + PcepObjectHeader interLayerObjHeader; | ||
119 | + boolean bNFlag; | ||
120 | + boolean bIFlag; | ||
121 | + | ||
122 | + interLayerObjHeader = PcepObjectHeader.read(cb); | ||
123 | + | ||
124 | + //take only InterLayerObject buffer. | ||
125 | + ChannelBuffer tempCb = cb.readBytes(interLayerObjHeader.getObjLen() - OBJECT_HEADER_LENGTH); | ||
126 | + | ||
127 | + int iTemp = tempCb.readInt(); | ||
128 | + bIFlag = ((iTemp & (byte) IFLAG_SHIFT_VALUE) == FLAGS_SET_VALUE) ? true : false; | ||
129 | + bNFlag = ((iTemp & (byte) NFLAG_SHIFT_VALUE) == FLAGS_SET_VALUE) ? true : false; | ||
130 | + | ||
131 | + return new PcepInterLayerObjectVer1(interLayerObjHeader, bNFlag, bIFlag); | ||
132 | + } | ||
133 | + | ||
134 | + @Override | ||
135 | + public int write(ChannelBuffer cb) throws PcepParseException { | ||
136 | + | ||
137 | + //write Object header | ||
138 | + int objStartIndex = cb.writerIndex(); | ||
139 | + | ||
140 | + int objLenIndex = interLayerObjHeader.write(cb); | ||
141 | + | ||
142 | + if (objLenIndex <= 0) { | ||
143 | + throw new PcepParseException(" ObjectLength Index is " + objLenIndex); | ||
144 | + } | ||
145 | + | ||
146 | + int iTemp = 0; | ||
147 | + | ||
148 | + if (bIFlag) { | ||
149 | + iTemp = iTemp | (byte) IFLAG_SHIFT_VALUE; | ||
150 | + } | ||
151 | + if (bNFlag) { | ||
152 | + iTemp = iTemp | (byte) NFLAG_SHIFT_VALUE; | ||
153 | + } | ||
154 | + | ||
155 | + cb.writeInt(iTemp); | ||
156 | + | ||
157 | + //Update object length now | ||
158 | + int length = cb.writerIndex() - objStartIndex; | ||
159 | + //will be helpful during print(). | ||
160 | + interLayerObjHeader.setObjLen((short) length); | ||
161 | + cb.setShort(objLenIndex, (short) length); | ||
162 | + | ||
163 | + objLenIndex = cb.writerIndex(); | ||
164 | + return objLenIndex; | ||
165 | + } | ||
166 | + | ||
167 | + /** | ||
168 | + * Builder class for PCEP inter layer object. | ||
169 | + */ | ||
170 | + public static class Builder implements PcepInterLayerObject.Builder { | ||
171 | + | ||
172 | + private boolean bIsHeaderSet = false; | ||
173 | + private boolean bIsNFlagset = false; | ||
174 | + private boolean bIsIFlagset = false; | ||
175 | + | ||
176 | + private PcepObjectHeader interLayerObjHeader; | ||
177 | + private boolean bNFlag; | ||
178 | + private boolean bIFlag; | ||
179 | + | ||
180 | + private boolean bIsPFlagSet = false; | ||
181 | + private boolean bPFalg; | ||
182 | + | ||
183 | + private boolean bIsIFlagSet = false; | ||
184 | + private boolean iFlag; | ||
185 | + | ||
186 | + @Override | ||
187 | + public PcepInterLayerObject build() { | ||
188 | + PcepObjectHeader interLayerObjHeader = this.bIsHeaderSet ? this.interLayerObjHeader | ||
189 | + : DEFAULT_INTER_LAYER_OBJECT_HEADER; | ||
190 | + | ||
191 | + boolean bNFlag = this.bIsNFlagset ? this.bNFlag : DEFAULT_NFLAG; | ||
192 | + boolean bIFlag = this.bIsIFlagset ? this.bIFlag : DEFAULT_IFLAG; | ||
193 | + | ||
194 | + if (bIsPFlagSet) { | ||
195 | + interLayerObjHeader.setPFlag(bPFalg); | ||
196 | + } | ||
197 | + | ||
198 | + if (bIsIFlagSet) { | ||
199 | + interLayerObjHeader.setIFlag(iFlag); | ||
200 | + } | ||
201 | + return new PcepInterLayerObjectVer1(interLayerObjHeader, bNFlag, bIFlag); | ||
202 | + } | ||
203 | + | ||
204 | + @Override | ||
205 | + public PcepObjectHeader getInterLayerObjHeader() { | ||
206 | + return this.interLayerObjHeader; | ||
207 | + } | ||
208 | + | ||
209 | + @Override | ||
210 | + public Builder setInterLayerObjHeader(PcepObjectHeader obj) { | ||
211 | + this.interLayerObjHeader = obj; | ||
212 | + this.bIsHeaderSet = true; | ||
213 | + return this; | ||
214 | + } | ||
215 | + | ||
216 | + @Override | ||
217 | + public boolean getbNFlag() { | ||
218 | + return this.bNFlag; | ||
219 | + } | ||
220 | + | ||
221 | + @Override | ||
222 | + public Builder setbNFlag(boolean value) { | ||
223 | + this.bNFlag = value; | ||
224 | + this.bIsNFlagset = true; | ||
225 | + return this; | ||
226 | + } | ||
227 | + | ||
228 | + @Override | ||
229 | + public boolean getbIFlag() { | ||
230 | + return this.bIFlag; | ||
231 | + } | ||
232 | + | ||
233 | + @Override | ||
234 | + public Builder setbIFlag(boolean value) { | ||
235 | + this.bIFlag = value; | ||
236 | + this.bIsIFlagset = true; | ||
237 | + return this; | ||
238 | + } | ||
239 | + | ||
240 | + @Override | ||
241 | + public Builder setPFlag(boolean value) { | ||
242 | + this.bPFalg = value; | ||
243 | + this.bIsPFlagSet = true; | ||
244 | + return this; | ||
245 | + } | ||
246 | + | ||
247 | + @Override | ||
248 | + public Builder setIFlag(boolean value) { | ||
249 | + this.iFlag = value; | ||
250 | + this.bIsIFlagSet = true; | ||
251 | + return this; | ||
252 | + } | ||
253 | + } | ||
254 | + | ||
255 | + @Override | ||
256 | + public String toString() { | ||
257 | + return MoreObjects.toStringHelper(getClass()).add("IFlag", bIFlag).add("NFlag", bNFlag).toString(); | ||
258 | + } | ||
259 | +} |
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.PcepLspObject; | ||
25 | +import org.onosproject.pcepio.protocol.PcepMessageReader; | ||
26 | +import org.onosproject.pcepio.protocol.PcepMessageWriter; | ||
27 | +import org.onosproject.pcepio.protocol.PcepReportMsg; | ||
28 | +import org.onosproject.pcepio.protocol.PcepSrpObject; | ||
29 | +import org.onosproject.pcepio.protocol.PcepStateReport; | ||
30 | +import org.onosproject.pcepio.protocol.PcepType; | ||
31 | +import org.onosproject.pcepio.protocol.PcepVersion; | ||
32 | +import org.onosproject.pcepio.types.PcepObjectHeader; | ||
33 | +import org.slf4j.Logger; | ||
34 | +import org.slf4j.LoggerFactory; | ||
35 | + | ||
36 | +import com.google.common.base.MoreObjects; | ||
37 | + | ||
38 | +class PcepReportMsgVer1 implements PcepReportMsg { | ||
39 | + | ||
40 | + // Pcep version: 1 | ||
41 | + | ||
42 | + /* | ||
43 | + * The format of the PCRpt message is as follows: | ||
44 | + * <PCRpt Message> ::= <Common Header> | ||
45 | + * <state-report-list> | ||
46 | + *Where: | ||
47 | + * <state-report-list> ::= <state-report>[<state-report-list>] | ||
48 | + * <state-report> ::= [<SRP>] | ||
49 | + * <LSP> | ||
50 | + * <path> | ||
51 | + * Where: | ||
52 | + * <path> ::= <ERO><attribute-list>[<RRO>] | ||
53 | + * Where: | ||
54 | + * <attribute-list> is defined in [RFC5440] and extended by PCEP extensions. | ||
55 | + * where: | ||
56 | + * <attribute-list> ::=[<LSPA>] | ||
57 | + * [<BANDWIDTH>] | ||
58 | + * [<metric-list>] | ||
59 | + * [<IRO>] | ||
60 | + * <metric-list> ::=<METRIC>[<metric-list>] | ||
61 | + */ | ||
62 | + protected static final Logger log = LoggerFactory.getLogger(PcepReportMsgVer1.class); | ||
63 | + | ||
64 | + public static final byte PACKET_VERSION = 1; | ||
65 | + //PACKET_MINIMUM_LENGTH = CommonHeaderLen(4)+LspObjMinLen(8)+EroObjMinLen(12) | ||
66 | + public static final int PACKET_MINIMUM_LENGTH = 24; | ||
67 | + public static final PcepType MSG_TYPE = PcepType.REPORT; | ||
68 | + public static final byte REPORT_OBJ_TYPE = 1; | ||
69 | + //Optional TLV | ||
70 | + private LinkedList<PcepStateReport> llStateReportList; | ||
71 | + | ||
72 | + public static final PcepReportMsgVer1.Reader READER = new Reader(); | ||
73 | + | ||
74 | + static class Reader implements PcepMessageReader<PcepReportMsg> { | ||
75 | + | ||
76 | + LinkedList<PcepStateReport> llStateReportList; | ||
77 | + | ||
78 | + @Override | ||
79 | + public PcepReportMsg readFrom(ChannelBuffer cb) throws PcepParseException { | ||
80 | + | ||
81 | + if (cb.readableBytes() < PACKET_MINIMUM_LENGTH) { | ||
82 | + throw new PcepParseException("Received packet size " + cb.readableBytes() | ||
83 | + + " is less than the expected size: " + PACKET_MINIMUM_LENGTH); | ||
84 | + } | ||
85 | + llStateReportList = new LinkedList<PcepStateReport>(); | ||
86 | + byte version = cb.readByte(); | ||
87 | + version = (byte) (version >> PcepMessageVer1.SHIFT_FLAG); | ||
88 | + | ||
89 | + if (version != PACKET_VERSION) { | ||
90 | + throw new PcepParseException(" Invalid version: " + version); | ||
91 | + } | ||
92 | + | ||
93 | + byte type = cb.readByte(); | ||
94 | + | ||
95 | + if (type != MSG_TYPE.getType()) { | ||
96 | + throw new PcepParseException("Unexpected type: " + type); | ||
97 | + } | ||
98 | + | ||
99 | + short length = cb.readShort(); | ||
100 | + | ||
101 | + if (length < PACKET_MINIMUM_LENGTH) { | ||
102 | + throw new PcepParseException("Wrong length. Expected to be >= " + PACKET_MINIMUM_LENGTH + ", was: " | ||
103 | + + length); | ||
104 | + } | ||
105 | + // parse state report list | ||
106 | + parseStateReportList(cb); | ||
107 | + return new PcepReportMsgVer1(llStateReportList); | ||
108 | + } | ||
109 | + | ||
110 | + // Parse State Report list | ||
111 | + public void parseStateReportList(ChannelBuffer cb) throws PcepParseException { | ||
112 | + | ||
113 | + /* | ||
114 | + <state-report-list> | ||
115 | + Where: | ||
116 | + <state-report-list> ::= <state-report>[<state-report-list>] | ||
117 | + <state-report> ::= [<SRP>] | ||
118 | + <LSP> | ||
119 | + <path> | ||
120 | + Where: | ||
121 | + <path> ::= <ERO><attribute-list>[<RRO>] | ||
122 | + Where: | ||
123 | + <attribute-list> is defined in [RFC5440] and extended by PCEP extensions. | ||
124 | + | ||
125 | + */ | ||
126 | + | ||
127 | + while (0 < cb.readableBytes()) { | ||
128 | + | ||
129 | + PcepStateReport pcestateReq = new PcepStateReportVer1(); | ||
130 | + | ||
131 | + /* | ||
132 | + * SRP is optional | ||
133 | + * Check whether SRP Object is available, if yes store it. | ||
134 | + * First read common object header and check the Object Class whether it is SRP or LSP | ||
135 | + * If it is LSP then store only LSP. So, SRP is optional. then read path and store. | ||
136 | + * If it is SRP then store SRP and then read LSP, path and store them. | ||
137 | + */ | ||
138 | + | ||
139 | + //mark the reader index to reset | ||
140 | + cb.markReaderIndex(); | ||
141 | + PcepObjectHeader tempObjHeader = PcepObjectHeader.read(cb); | ||
142 | + | ||
143 | + byte yObjectClass = tempObjHeader.getObjClass(); | ||
144 | + byte yObjectType = tempObjHeader.getObjType(); | ||
145 | + | ||
146 | + //reset reader index | ||
147 | + cb.resetReaderIndex(); | ||
148 | + //If SRP present then store it. | ||
149 | + if ((PcepSrpObjectVer1.SRP_OBJ_CLASS == yObjectClass) | ||
150 | + && (PcepSrpObjectVer1.SRP_OBJ_TYPE == yObjectType)) { | ||
151 | + PcepSrpObject srpObj; | ||
152 | + srpObj = PcepSrpObjectVer1.read(cb); | ||
153 | + pcestateReq.setSrpObject(srpObj); | ||
154 | + } | ||
155 | + | ||
156 | + //store LSP object | ||
157 | + PcepLspObject lspObj; | ||
158 | + lspObj = PcepLspObjectVer1.read(cb); | ||
159 | + pcestateReq.setLspObject(lspObj); | ||
160 | + | ||
161 | + //store path | ||
162 | + PcepStateReport.PcepMsgPath msgPath = new PcepStateReportVer1().new PcepMsgPath().read(cb); | ||
163 | + pcestateReq.setMsgPath(msgPath); | ||
164 | + | ||
165 | + llStateReportList.add(pcestateReq); | ||
166 | + } | ||
167 | + } | ||
168 | + } | ||
169 | + | ||
170 | + /** | ||
171 | + * Constructor to initialize State Report List. | ||
172 | + * | ||
173 | + * @param llStateReportList list of type Pcep state report | ||
174 | + */ | ||
175 | + PcepReportMsgVer1(LinkedList<PcepStateReport> llStateReportList) { | ||
176 | + this.llStateReportList = llStateReportList; | ||
177 | + } | ||
178 | + | ||
179 | + /** | ||
180 | + * Builder class for PCEP Report message. | ||
181 | + */ | ||
182 | + static class Builder implements PcepReportMsg.Builder { | ||
183 | + // Pcep report message fields | ||
184 | + LinkedList<PcepStateReport> llStateReportList; | ||
185 | + | ||
186 | + @Override | ||
187 | + public PcepVersion getVersion() { | ||
188 | + return PcepVersion.PCEP_1; | ||
189 | + } | ||
190 | + | ||
191 | + @Override | ||
192 | + public PcepType getType() { | ||
193 | + return PcepType.REPORT; | ||
194 | + } | ||
195 | + | ||
196 | + @Override | ||
197 | + public PcepReportMsg build() { | ||
198 | + return new PcepReportMsgVer1(this.llStateReportList); | ||
199 | + } | ||
200 | + | ||
201 | + @Override | ||
202 | + public LinkedList<PcepStateReport> getStateReportList() { | ||
203 | + return this.llStateReportList; | ||
204 | + } | ||
205 | + | ||
206 | + @Override | ||
207 | + public Builder setStateReportList(LinkedList<PcepStateReport> ll) { | ||
208 | + this.llStateReportList = ll; | ||
209 | + return this; | ||
210 | + } | ||
211 | + } | ||
212 | + | ||
213 | + @Override | ||
214 | + public void writeTo(ChannelBuffer cb) throws PcepParseException { | ||
215 | + WRITER.write(cb, this); | ||
216 | + } | ||
217 | + | ||
218 | + static final Writer WRITER = new Writer(); | ||
219 | + | ||
220 | + static class Writer implements PcepMessageWriter<PcepReportMsgVer1> { | ||
221 | + | ||
222 | + @Override | ||
223 | + public void write(ChannelBuffer cb, PcepReportMsgVer1 message) throws PcepParseException { | ||
224 | + | ||
225 | + int startIndex = cb.writerIndex(); | ||
226 | + | ||
227 | + // first 3 bits set to version | ||
228 | + cb.writeByte((byte) (PACKET_VERSION << PcepMessageVer1.SHIFT_FLAG)); | ||
229 | + | ||
230 | + // message type | ||
231 | + cb.writeByte(MSG_TYPE.getType()); | ||
232 | + | ||
233 | + // length is length of variable message, will be updated at the end | ||
234 | + // Store the position of message | ||
235 | + // length in buffer | ||
236 | + int msgLenIndex = cb.writerIndex(); | ||
237 | + | ||
238 | + cb.writeShort((short) 0); | ||
239 | + ListIterator<PcepStateReport> listIterator = message.llStateReportList.listIterator(); | ||
240 | + | ||
241 | + while (listIterator.hasNext()) { | ||
242 | + | ||
243 | + PcepStateReport stateRpt = listIterator.next(); | ||
244 | + PcepSrpObject srpObj = stateRpt.getSrpObject(); | ||
245 | + | ||
246 | + //SRP object is optional | ||
247 | + if (null != srpObj) { | ||
248 | + srpObj.write(cb); | ||
249 | + } | ||
250 | + | ||
251 | + //LSP object is mandatory | ||
252 | + PcepLspObject lspObj = stateRpt.getLspObject(); | ||
253 | + if (lspObj == null) { | ||
254 | + throw new PcepParseException("LSP Object is mandatory object for PcRpt message."); | ||
255 | + } else { | ||
256 | + lspObj.write(cb); | ||
257 | + } | ||
258 | + | ||
259 | + //path is mandatory | ||
260 | + PcepStateReport.PcepMsgPath msgPath = stateRpt.getMsgPath(); | ||
261 | + if (msgPath == null) { | ||
262 | + throw new PcepParseException("Message path is mandatory object for PcRpt message."); | ||
263 | + } else { | ||
264 | + msgPath.write(cb); | ||
265 | + } | ||
266 | + } | ||
267 | + | ||
268 | + // update message length field | ||
269 | + int length = cb.writerIndex() - startIndex; | ||
270 | + cb.setShort(msgLenIndex, (short) length); | ||
271 | + } | ||
272 | + } | ||
273 | + | ||
274 | + @Override | ||
275 | + public PcepVersion getVersion() { | ||
276 | + return PcepVersion.PCEP_1; | ||
277 | + } | ||
278 | + | ||
279 | + @Override | ||
280 | + public PcepType getType() { | ||
281 | + return MSG_TYPE; | ||
282 | + } | ||
283 | + | ||
284 | + @Override | ||
285 | + public LinkedList<PcepStateReport> getStateReportList() { | ||
286 | + return this.llStateReportList; | ||
287 | + } | ||
288 | + | ||
289 | + @Override | ||
290 | + public void setStateReportList(LinkedList<PcepStateReport> ll) { | ||
291 | + this.llStateReportList = ll; | ||
292 | + } | ||
293 | + | ||
294 | + @Override | ||
295 | + public String toString() { | ||
296 | + return MoreObjects.toStringHelper(getClass()).add("StateReportList", llStateReportList).toString(); | ||
297 | + } | ||
298 | +} |
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.PcepRroObject; | ||
25 | +import org.onosproject.pcepio.types.IPv4SubObject; | ||
26 | +import org.onosproject.pcepio.types.IPv6SubObject; | ||
27 | +import org.onosproject.pcepio.types.LabelSubObject; | ||
28 | +import org.onosproject.pcepio.types.PcepObjectHeader; | ||
29 | +import org.onosproject.pcepio.types.PcepValueType; | ||
30 | +import org.slf4j.Logger; | ||
31 | +import org.slf4j.LoggerFactory; | ||
32 | + | ||
33 | +import com.google.common.base.MoreObjects; | ||
34 | + | ||
35 | +/* | ||
36 | + * rfc3209 | ||
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 | + | Object-Class | OT |Res|P|I| Object Length (bytes) | | ||
41 | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
42 | + | | | ||
43 | + // (Subobjects) // | ||
44 | + | | | ||
45 | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
46 | + | ||
47 | + Each subobject has its own Length | ||
48 | + field. The length contains the total length of the subobject in | ||
49 | + bytes, including the Type and Length fields. The length MUST always | ||
50 | + be a multiple of 4, and at least 4. | ||
51 | + | ||
52 | + An empty RRO with no subobjects is considered illegal. | ||
53 | + Three kinds of subobjects are currently defined. | ||
54 | + | ||
55 | + Subobject 1: IPv4 address | ||
56 | + | ||
57 | + 0 1 2 3 | ||
58 | + 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 | ||
59 | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
60 | + | Type | Length | IPv4 address (4 bytes) | | ||
61 | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
62 | + | IPv4 address (continued) | Prefix Length | Flags | | ||
63 | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
64 | + | ||
65 | + Subobject 2: IPv6 address | ||
66 | + | ||
67 | + 0 1 2 3 | ||
68 | + 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 | ||
69 | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
70 | + | Type | Length | IPv6 address (16 bytes) | | ||
71 | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
72 | + | IPv6 address (continued) | | ||
73 | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
74 | + | IPv6 address (continued) | | ||
75 | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
76 | + | IPv6 address (continued) | | ||
77 | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
78 | + | IPv6 address (continued) | Prefix Length | Flags | | ||
79 | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
80 | + | ||
81 | + Subobject 3, Label | ||
82 | + | ||
83 | + 0 1 2 3 | ||
84 | + 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 | ||
85 | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
86 | + | Type | Length | Flags | C-Type | | ||
87 | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
88 | + | Contents of Label Object | | ||
89 | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
90 | + | ||
91 | + */ | ||
92 | +public class PcepRroObjectVer1 implements PcepRroObject { | ||
93 | + | ||
94 | + protected static final Logger log = LoggerFactory.getLogger(PcepRroObjectVer1.class); | ||
95 | + | ||
96 | + public static final byte RRO_OBJ_TYPE = 1; | ||
97 | + public static final byte RRO_OBJ_CLASS = 8; | ||
98 | + public static final byte RRO_OBJECT_VERSION = 1; | ||
99 | + public static final short RRO_OBJ_MINIMUM_LENGTH = 12; | ||
100 | + public static final int OBJECT_HEADER_LENGTH = 4; | ||
101 | + public static final int YTYPE_SHIFT_VALUE = 0x7F; | ||
102 | + | ||
103 | + static final PcepObjectHeader DEFAULT_RRO_OBJECT_HEADER = new PcepObjectHeader(RRO_OBJ_CLASS, RRO_OBJ_TYPE, | ||
104 | + PcepObjectHeader.REQ_OBJ_OPTIONAL_PROCESS, PcepObjectHeader.RSP_OBJ_PROCESSED, RRO_OBJ_MINIMUM_LENGTH); | ||
105 | + | ||
106 | + private short rroObjType = 0; | ||
107 | + private byte length; | ||
108 | + private byte prefixLength; | ||
109 | + private byte resvd; | ||
110 | + PcepObjectHeader rroObjHeader; | ||
111 | + private LinkedList<PcepValueType> llSubObjects = new LinkedList<PcepValueType>(); | ||
112 | + | ||
113 | + /** | ||
114 | + * Reset variables. | ||
115 | + */ | ||
116 | + public PcepRroObjectVer1() { | ||
117 | + this.rroObjHeader = null; | ||
118 | + this.rroObjType = 0; | ||
119 | + this.length = 0; | ||
120 | + } | ||
121 | + | ||
122 | + /** | ||
123 | + * constructor to initialize parameters for RRO object. | ||
124 | + * | ||
125 | + * @param rroObjHeader RRO object header | ||
126 | + * @param llSubObjects list of sub objects | ||
127 | + */ | ||
128 | + public PcepRroObjectVer1(PcepObjectHeader rroObjHeader, LinkedList<PcepValueType> llSubObjects) { | ||
129 | + this.rroObjHeader = rroObjHeader; | ||
130 | + this.llSubObjects = llSubObjects; | ||
131 | + } | ||
132 | + | ||
133 | + /** | ||
134 | + * Returns PCEP RRO Object Header. | ||
135 | + * | ||
136 | + * @return rroObjHeader RRO Object header | ||
137 | + */ | ||
138 | + public PcepObjectHeader getRroObjHeader() { | ||
139 | + return this.rroObjHeader; | ||
140 | + } | ||
141 | + | ||
142 | + /** | ||
143 | + * Sets PCEP RRO Object Header. | ||
144 | + * | ||
145 | + * @param obj Object header | ||
146 | + */ | ||
147 | + public void setRroObjHeader(PcepObjectHeader obj) { | ||
148 | + this.rroObjHeader = obj; | ||
149 | + } | ||
150 | + | ||
151 | + @Override | ||
152 | + public LinkedList<PcepValueType> getSubObjects() { | ||
153 | + return this.llSubObjects; | ||
154 | + } | ||
155 | + | ||
156 | + @Override | ||
157 | + public void setSubObjects(LinkedList<PcepValueType> llSubObjects) { | ||
158 | + this.llSubObjects = llSubObjects; | ||
159 | + } | ||
160 | + | ||
161 | + /** | ||
162 | + * Reads the channel buffer and returns object of PcepRroObject. | ||
163 | + * | ||
164 | + * @param cb of type channel buffer | ||
165 | + * @return object of PcepRroObject | ||
166 | + * @throws PcepParseException when fails to read from channel buffer | ||
167 | + */ | ||
168 | + public static PcepRroObject read(ChannelBuffer cb) throws PcepParseException { | ||
169 | + | ||
170 | + PcepObjectHeader rroObjHeader; | ||
171 | + LinkedList<PcepValueType> llSubObjects; | ||
172 | + rroObjHeader = PcepObjectHeader.read(cb); | ||
173 | + | ||
174 | + //take only RroObject buffer. | ||
175 | + ChannelBuffer tempCb = cb.readBytes(rroObjHeader.getObjLen() - OBJECT_HEADER_LENGTH); | ||
176 | + llSubObjects = parseSubObjects(tempCb); | ||
177 | + | ||
178 | + return new PcepRroObjectVer1(rroObjHeader, llSubObjects); | ||
179 | + } | ||
180 | + | ||
181 | + /** | ||
182 | + * Returns list of sub objects. | ||
183 | + * | ||
184 | + * @param cb of type channel buffer | ||
185 | + * @return list of sub objects | ||
186 | + * @throws PcepParseException when fails to parse list of sub objects | ||
187 | + */ | ||
188 | + protected static LinkedList<PcepValueType> parseSubObjects(ChannelBuffer cb) throws PcepParseException { | ||
189 | + | ||
190 | + LinkedList<PcepValueType> llSubObjects = new LinkedList<PcepValueType>(); | ||
191 | + | ||
192 | + while (0 < cb.readableBytes()) { | ||
193 | + | ||
194 | + //check the Type of the Sub objects | ||
195 | + byte yType = cb.readByte(); | ||
196 | + yType = (byte) (yType & (YTYPE_SHIFT_VALUE)); | ||
197 | + byte hLength = cb.readByte(); | ||
198 | + | ||
199 | + PcepValueType subObj; | ||
200 | + | ||
201 | + switch (yType) { | ||
202 | + | ||
203 | + case IPv4SubObject.TYPE: | ||
204 | + subObj = IPv4SubObject.read(cb); | ||
205 | + break; | ||
206 | + case IPv6SubObject.TYPE: | ||
207 | + byte[] ipv6Value = new byte[IPv6SubObject.VALUE_LENGTH]; | ||
208 | + cb.readBytes(ipv6Value, 0, IPv6SubObject.VALUE_LENGTH); | ||
209 | + subObj = new IPv6SubObject(ipv6Value); | ||
210 | + break; | ||
211 | + case LabelSubObject.TYPE: | ||
212 | + subObj = LabelSubObject.read(cb); | ||
213 | + break; | ||
214 | + default: | ||
215 | + throw new PcepParseException(" Unexpected sub object. Type: " + (int) yType); | ||
216 | + } | ||
217 | + // Check for the padding | ||
218 | + int pad = hLength % 4; | ||
219 | + if (0 < pad) { | ||
220 | + pad = 4 - pad; | ||
221 | + if (pad <= cb.readableBytes()) { | ||
222 | + cb.skipBytes(pad); | ||
223 | + } | ||
224 | + } | ||
225 | + llSubObjects.add(subObj); | ||
226 | + } | ||
227 | + | ||
228 | + return llSubObjects; | ||
229 | + } | ||
230 | + | ||
231 | + @Override | ||
232 | + public int write(ChannelBuffer cb) throws PcepParseException { | ||
233 | + //write Object header | ||
234 | + int objStartIndex = cb.writerIndex(); | ||
235 | + | ||
236 | + int objLenIndex = rroObjHeader.write(cb); | ||
237 | + | ||
238 | + if (objLenIndex <= 0) { | ||
239 | + throw new PcepParseException(" object Length Index" + objLenIndex); | ||
240 | + } | ||
241 | + | ||
242 | + ListIterator<PcepValueType> listIterator = llSubObjects.listIterator(); | ||
243 | + | ||
244 | + while (listIterator.hasNext()) { | ||
245 | + listIterator.next().write(cb); | ||
246 | + } | ||
247 | + | ||
248 | + //Update object length now | ||
249 | + int length = cb.writerIndex() - objStartIndex; | ||
250 | + cb.setShort(objLenIndex, (short) length); | ||
251 | + //will be helpful during print(). | ||
252 | + rroObjHeader.setObjLen((short) length); | ||
253 | + | ||
254 | + //As per RFC the length of object should be multiples of 4 | ||
255 | + int pad = length % 4; | ||
256 | + | ||
257 | + if (0 != pad) { | ||
258 | + pad = 4 - pad; | ||
259 | + for (int i = 0; i < pad; i++) { | ||
260 | + cb.writeByte((byte) 0); | ||
261 | + } | ||
262 | + length = length + pad; | ||
263 | + } | ||
264 | + objLenIndex = cb.writerIndex(); | ||
265 | + return objLenIndex; | ||
266 | + } | ||
267 | + | ||
268 | + /** | ||
269 | + * Builder class for PCEP RRO object. | ||
270 | + */ | ||
271 | + public static class Builder implements PcepRroObject.Builder { | ||
272 | + private boolean bIsHeaderSet = false; | ||
273 | + | ||
274 | + private PcepObjectHeader rroObjHeader; | ||
275 | + LinkedList<PcepValueType> llSubObjects = new LinkedList<PcepValueType>(); | ||
276 | + | ||
277 | + private boolean bIsPFlagSet = false; | ||
278 | + private boolean bPFlag; | ||
279 | + | ||
280 | + private boolean bIsIFlagSet = false; | ||
281 | + private boolean bIFlag; | ||
282 | + | ||
283 | + @Override | ||
284 | + public PcepRroObject build() { | ||
285 | + | ||
286 | + PcepObjectHeader rroObjHeader = this.bIsHeaderSet ? this.rroObjHeader : DEFAULT_RRO_OBJECT_HEADER; | ||
287 | + | ||
288 | + if (bIsPFlagSet) { | ||
289 | + rroObjHeader.setPFlag(bPFlag); | ||
290 | + } | ||
291 | + | ||
292 | + if (bIsIFlagSet) { | ||
293 | + rroObjHeader.setIFlag(bIFlag); | ||
294 | + } | ||
295 | + return new PcepRroObjectVer1(rroObjHeader, this.llSubObjects); | ||
296 | + } | ||
297 | + | ||
298 | + @Override | ||
299 | + public PcepObjectHeader getRroObjHeader() { | ||
300 | + return this.rroObjHeader; | ||
301 | + } | ||
302 | + | ||
303 | + @Override | ||
304 | + public Builder setRroObjHeader(PcepObjectHeader obj) { | ||
305 | + this.rroObjHeader = obj; | ||
306 | + this.bIsHeaderSet = true; | ||
307 | + return this; | ||
308 | + } | ||
309 | + | ||
310 | + @Override | ||
311 | + public LinkedList<PcepValueType> getSubObjects() { | ||
312 | + return this.llSubObjects; | ||
313 | + } | ||
314 | + | ||
315 | + @Override | ||
316 | + public Builder setSubObjects(LinkedList<PcepValueType> llSubObjects) { | ||
317 | + this.llSubObjects = llSubObjects; | ||
318 | + return this; | ||
319 | + } | ||
320 | + | ||
321 | + @Override | ||
322 | + public Builder setPFlag(boolean value) { | ||
323 | + this.bPFlag = value; | ||
324 | + this.bIsPFlagSet = true; | ||
325 | + return this; | ||
326 | + } | ||
327 | + | ||
328 | + @Override | ||
329 | + public Builder setIFlag(boolean value) { | ||
330 | + this.bIFlag = value; | ||
331 | + this.bIsIFlagSet = true; | ||
332 | + return this; | ||
333 | + } | ||
334 | + } | ||
335 | + | ||
336 | + @Override | ||
337 | + public String toString() { | ||
338 | + return MoreObjects.toStringHelper(getClass()).add("SubObjects", llSubObjects).toString(); | ||
339 | + } | ||
340 | +} |
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.PcepAttribute; | ||
22 | +import org.onosproject.pcepio.protocol.PcepBandwidthObject; | ||
23 | +import org.onosproject.pcepio.protocol.PcepEroObject; | ||
24 | +import org.onosproject.pcepio.protocol.PcepLspObject; | ||
25 | +import org.onosproject.pcepio.protocol.PcepRroObject; | ||
26 | +import org.onosproject.pcepio.protocol.PcepSrpObject; | ||
27 | +import org.onosproject.pcepio.protocol.PcepStateReport; | ||
28 | +import org.onosproject.pcepio.types.PcepObjectHeader; | ||
29 | +import org.slf4j.Logger; | ||
30 | +import org.slf4j.LoggerFactory; | ||
31 | + | ||
32 | +import com.google.common.base.MoreObjects; | ||
33 | +import com.google.common.base.MoreObjects.ToStringHelper; | ||
34 | + | ||
35 | +/** | ||
36 | + * Provide the State Report for the Pcep Report Message. | ||
37 | + * Reference :PCE extensions for stateful draft-ietf-pce-stateful-pce-10. | ||
38 | + */ | ||
39 | +public class PcepStateReportVer1 implements PcepStateReport { | ||
40 | + /* | ||
41 | + * <state-report> ::= [<SRP>] | ||
42 | + <LSP> | ||
43 | + <path> | ||
44 | + Where: | ||
45 | + <path> ::= <ERO><attribute-list>[<RRO>] | ||
46 | + */ | ||
47 | + | ||
48 | + protected static final Logger log = LoggerFactory.getLogger(PcepStateReport.class); | ||
49 | + | ||
50 | + public static final int OBJECT_HEADER_LENGTH = 4; | ||
51 | + | ||
52 | + /** | ||
53 | + * Provides PCEP Message path for report message. | ||
54 | + */ | ||
55 | + public class PcepMsgPath implements PcepStateReport.PcepMsgPath { | ||
56 | + | ||
57 | + /* | ||
58 | + * <path> ::= <ERO><attribute-list>[<RRO>] | ||
59 | + */ | ||
60 | + | ||
61 | + //PcepEroObject | ||
62 | + private PcepEroObject eroObj; | ||
63 | + private boolean isEroObjectSet; | ||
64 | + //PcepAttribute List | ||
65 | + private PcepAttribute attrList; | ||
66 | + private boolean isAttributeListSet; | ||
67 | + //PcepRroObject | ||
68 | + private PcepRroObject rroObj; | ||
69 | + private boolean isRroObjectSet; | ||
70 | + private PcepBandwidthObject bandwidth; | ||
71 | + private boolean isBandwidthObjectSet; | ||
72 | + | ||
73 | + /** | ||
74 | + * Constructor to reset the parameters. | ||
75 | + */ | ||
76 | + public PcepMsgPath() { | ||
77 | + eroObj = null; | ||
78 | + attrList = null; | ||
79 | + rroObj = null; | ||
80 | + this.isEroObjectSet = false; | ||
81 | + this.isAttributeListSet = false; | ||
82 | + this.isRroObjectSet = false; | ||
83 | + this.isBandwidthObjectSet = false; | ||
84 | + } | ||
85 | + | ||
86 | + /** | ||
87 | + * Constructor to initialize the parameters from PCEP Message path. | ||
88 | + * | ||
89 | + * @param eroObj PCEP ERO Object | ||
90 | + * @param attrList PCEP Attribute | ||
91 | + * @param rroObj PCEP Rro Object | ||
92 | + */ | ||
93 | + public PcepMsgPath(PcepEroObject eroObj, PcepAttribute attrList, PcepRroObject rroObj, | ||
94 | + PcepBandwidthObject bandwidth) { | ||
95 | + | ||
96 | + this.eroObj = eroObj; | ||
97 | + this.attrList = attrList; | ||
98 | + this.rroObj = rroObj; | ||
99 | + this.bandwidth = bandwidth; | ||
100 | + if (null == rroObj) { | ||
101 | + this.isRroObjectSet = false; | ||
102 | + } else { | ||
103 | + this.isRroObjectSet = true; | ||
104 | + } | ||
105 | + if (null == eroObj) { | ||
106 | + this.isEroObjectSet = false; | ||
107 | + } else { | ||
108 | + this.isEroObjectSet = true; | ||
109 | + } | ||
110 | + if (null == attrList) { | ||
111 | + this.isAttributeListSet = false; | ||
112 | + } else { | ||
113 | + this.isAttributeListSet = true; | ||
114 | + } | ||
115 | + if (null == bandwidth) { | ||
116 | + this.isBandwidthObjectSet = false; | ||
117 | + } else { | ||
118 | + this.isBandwidthObjectSet = true; | ||
119 | + } | ||
120 | + } | ||
121 | + | ||
122 | + /** | ||
123 | + * Returns PcepEroObject. | ||
124 | + * | ||
125 | + * @return eroObj PCEP ERO Object | ||
126 | + */ | ||
127 | + @Override | ||
128 | + public PcepEroObject getEroObject() { | ||
129 | + return this.eroObj; | ||
130 | + } | ||
131 | + | ||
132 | + /** | ||
133 | + * Returns PCEP Attribute. | ||
134 | + * | ||
135 | + * @return attrList Attribute list | ||
136 | + */ | ||
137 | + @Override | ||
138 | + public PcepAttribute getPcepAttribute() { | ||
139 | + return this.attrList; | ||
140 | + } | ||
141 | + | ||
142 | + /** | ||
143 | + * Returns PcepRroObject. | ||
144 | + * | ||
145 | + * @return rroObj PCEP RRO Object | ||
146 | + */ | ||
147 | + @Override | ||
148 | + public PcepRroObject getRroObject() { | ||
149 | + return this.rroObj; | ||
150 | + } | ||
151 | + | ||
152 | + @Override | ||
153 | + public PcepBandwidthObject getBandwidthObject() { | ||
154 | + return this.bandwidth; | ||
155 | + } | ||
156 | + | ||
157 | + @Override | ||
158 | + public void setEroObject(PcepEroObject eroObj) { | ||
159 | + this.eroObj = eroObj; | ||
160 | + } | ||
161 | + | ||
162 | + @Override | ||
163 | + public void setPcepAttribute(PcepAttribute attrList) { | ||
164 | + this.attrList = attrList; | ||
165 | + } | ||
166 | + | ||
167 | + @Override | ||
168 | + public void setRroObject(PcepRroObject rroObj) { | ||
169 | + this.rroObj = rroObj; | ||
170 | + } | ||
171 | + | ||
172 | + @Override | ||
173 | + public void setBandwidthObject(PcepBandwidthObject bandwidth) { | ||
174 | + this.bandwidth = bandwidth; | ||
175 | + } | ||
176 | + | ||
177 | + /** | ||
178 | + * Reads all the Objects for PCEP Message Path. | ||
179 | + * | ||
180 | + * @param bb of type channel buffer | ||
181 | + * @return PCEP Message path | ||
182 | + * @throws PcepParseException when fails to read pcep message path | ||
183 | + */ | ||
184 | + @Override | ||
185 | + public PcepMsgPath read(ChannelBuffer bb) throws PcepParseException { | ||
186 | + | ||
187 | + PcepEroObject eroObj; | ||
188 | + PcepAttribute attrList; | ||
189 | + PcepRroObject rroObj = null; | ||
190 | + PcepBandwidthObject bandwidth = null; | ||
191 | + | ||
192 | + eroObj = PcepEroObjectVer1.read(bb); | ||
193 | + attrList = PcepAttributeVer1.read(bb); | ||
194 | + | ||
195 | + boolean bBreakWhile = false; | ||
196 | + while (0 < bb.readableBytes()) { | ||
197 | + | ||
198 | + if (bb.readableBytes() < OBJECT_HEADER_LENGTH) { | ||
199 | + break; | ||
200 | + } | ||
201 | + bb.markReaderIndex(); | ||
202 | + PcepObjectHeader tempObjHeader = PcepObjectHeader.read(bb); | ||
203 | + bb.resetReaderIndex(); | ||
204 | + byte yObjClass = tempObjHeader.getObjClass(); | ||
205 | + | ||
206 | + switch (yObjClass) { | ||
207 | + case PcepRroObjectVer1.RRO_OBJ_CLASS: | ||
208 | + rroObj = PcepRroObjectVer1.read(bb); | ||
209 | + break; | ||
210 | + case PcepInterLayerObjectVer1.INTER_LAYER_OBJ_CLASS: | ||
211 | + bb.skipBytes(tempObjHeader.getObjLen()); | ||
212 | + break; | ||
213 | + case PcepBandwidthObjectVer1.BANDWIDTH_OBJ_CLASS: | ||
214 | + bandwidth = PcepBandwidthObjectVer1.read(bb); | ||
215 | + break; | ||
216 | + default: | ||
217 | + //Otherthan above objects handle those objects in caller. | ||
218 | + bBreakWhile = true; | ||
219 | + break; | ||
220 | + } | ||
221 | + if (bBreakWhile) { | ||
222 | + break; | ||
223 | + } | ||
224 | + } | ||
225 | + return new PcepMsgPath(eroObj, attrList, rroObj, bandwidth); | ||
226 | + } | ||
227 | + | ||
228 | + /** | ||
229 | + * Writes all the objects for PCEP message path. | ||
230 | + * | ||
231 | + * @param bb of type channel buffer. | ||
232 | + * @return object length index | ||
233 | + * @throws PcepParseException when fails to write to channel buffer | ||
234 | + */ | ||
235 | + @Override | ||
236 | + public int write(ChannelBuffer bb) throws PcepParseException { | ||
237 | + int iLenStartIndex = bb.writerIndex(); | ||
238 | + | ||
239 | + //write Object header | ||
240 | + if (this.isEroObjectSet) { | ||
241 | + this.eroObj.write(bb); | ||
242 | + } else { | ||
243 | + throw new PcepParseException("Ero object is not set in path"); | ||
244 | + } | ||
245 | + | ||
246 | + if (this.isAttributeListSet) { | ||
247 | + this.attrList.write(bb); | ||
248 | + } | ||
249 | + | ||
250 | + // RRO is optional check and read | ||
251 | + if (this.isRroObjectSet) { | ||
252 | + this.rroObj.write(bb); | ||
253 | + // bandwidth should come along with RRO. | ||
254 | + if (this.isBandwidthObjectSet) { | ||
255 | + this.bandwidth.write(bb); | ||
256 | + } | ||
257 | + } | ||
258 | + return bb.writerIndex() - iLenStartIndex; | ||
259 | + } | ||
260 | + | ||
261 | + @Override | ||
262 | + public String toString() { | ||
263 | + ToStringHelper toStrHelper = MoreObjects.toStringHelper(getClass()); | ||
264 | + | ||
265 | + if (attrList instanceof PcepAttribute) { | ||
266 | + toStrHelper.add("AttributeList", attrList); | ||
267 | + } | ||
268 | + if (rroObj instanceof PcepRroObjectVer1) { | ||
269 | + toStrHelper.add("RroObject", rroObj); | ||
270 | + } | ||
271 | + if (bandwidth instanceof PcepBandwidthObjectVer1) { | ||
272 | + toStrHelper.add("bandwidthObject", bandwidth); | ||
273 | + } | ||
274 | + return toStrHelper.toString(); | ||
275 | + } | ||
276 | + } | ||
277 | + | ||
278 | + //SRP Object | ||
279 | + private PcepSrpObject srpObject; | ||
280 | + //LSP Object | ||
281 | + private PcepLspObject lspObject; | ||
282 | + //PcepMsgPath | ||
283 | + private PcepStateReport.PcepMsgPath msgPath; | ||
284 | + | ||
285 | + /** | ||
286 | + * Constructor to reset objects. | ||
287 | + */ | ||
288 | + public PcepStateReportVer1() { | ||
289 | + this.srpObject = null; | ||
290 | + this.lspObject = null; | ||
291 | + this.msgPath = null; | ||
292 | + } | ||
293 | + | ||
294 | + public PcepStateReportVer1(PcepSrpObject srpObject, PcepLspObject lspObject, PcepStateReport.PcepMsgPath msgPath) { | ||
295 | + this.srpObject = srpObject; | ||
296 | + this.lspObject = lspObject; | ||
297 | + this.msgPath = msgPath; | ||
298 | + } | ||
299 | + | ||
300 | + @Override | ||
301 | + public PcepSrpObject getSrpObject() { | ||
302 | + return srpObject; | ||
303 | + } | ||
304 | + | ||
305 | + @Override | ||
306 | + public PcepLspObject getLspObject() { | ||
307 | + return lspObject; | ||
308 | + } | ||
309 | + | ||
310 | + @Override | ||
311 | + public PcepStateReport.PcepMsgPath getMsgPath() { | ||
312 | + return msgPath; | ||
313 | + } | ||
314 | + | ||
315 | + @Override | ||
316 | + public void setSrpObject(PcepSrpObject srpObj) { | ||
317 | + this.srpObject = srpObj; | ||
318 | + } | ||
319 | + | ||
320 | + @Override | ||
321 | + public void setLspObject(PcepLspObject lspObject) { | ||
322 | + this.lspObject = lspObject; | ||
323 | + } | ||
324 | + | ||
325 | + @Override | ||
326 | + public void setMsgPath(PcepStateReport.PcepMsgPath msgPath) { | ||
327 | + this.msgPath = msgPath; | ||
328 | + } | ||
329 | + | ||
330 | + /** | ||
331 | + * Builder class for PCEP state report. | ||
332 | + */ | ||
333 | + public static class Builder implements PcepStateReport.Builder { | ||
334 | + | ||
335 | + private boolean bIsSRPObjectSet = false; | ||
336 | + private boolean bIsLSPObjectSet = false; | ||
337 | + private boolean bIsPcepMsgPathSet = false; | ||
338 | + | ||
339 | + //PCEP SRP Object | ||
340 | + private PcepSrpObject srpObject; | ||
341 | + //PCEP LSP Object | ||
342 | + private PcepLspObject lspObject; | ||
343 | + //PCEP Attribute list | ||
344 | + private PcepStateReport.PcepMsgPath msgPath; | ||
345 | + | ||
346 | + @Override | ||
347 | + public PcepStateReport build() throws PcepParseException { | ||
348 | + | ||
349 | + //PCEP SRP Object | ||
350 | + PcepSrpObject srpObject = null; | ||
351 | + //PCEP LSP Object | ||
352 | + PcepLspObject lspObject = null; | ||
353 | + //PCEP Attribute list | ||
354 | + PcepStateReport.PcepMsgPath msgPath = null; | ||
355 | + | ||
356 | + if (this.bIsSRPObjectSet) { | ||
357 | + srpObject = this.srpObject; | ||
358 | + } | ||
359 | + | ||
360 | + if (!this.bIsLSPObjectSet) { | ||
361 | + throw new PcepParseException(" LSP Object NOT Set while building PcepStateReport."); | ||
362 | + } else { | ||
363 | + lspObject = this.lspObject; | ||
364 | + } | ||
365 | + if (!this.bIsPcepMsgPathSet) { | ||
366 | + throw new PcepParseException(" Message Path NOT Set while building PcepStateReport."); | ||
367 | + } else { | ||
368 | + msgPath = this.msgPath; | ||
369 | + } | ||
370 | + | ||
371 | + return new PcepStateReportVer1(srpObject, lspObject, msgPath); | ||
372 | + } | ||
373 | + | ||
374 | + @Override | ||
375 | + public PcepSrpObject getSrpObject() { | ||
376 | + return this.srpObject; | ||
377 | + } | ||
378 | + | ||
379 | + @Override | ||
380 | + public PcepLspObject getLspObject() { | ||
381 | + return this.lspObject; | ||
382 | + } | ||
383 | + | ||
384 | + @Override | ||
385 | + public PcepStateReport.PcepMsgPath getMsgPath() { | ||
386 | + return this.msgPath; | ||
387 | + } | ||
388 | + | ||
389 | + @Override | ||
390 | + public Builder setSrpObject(PcepSrpObject srpobj) { | ||
391 | + this.srpObject = srpobj; | ||
392 | + this.bIsSRPObjectSet = true; | ||
393 | + return this; | ||
394 | + } | ||
395 | + | ||
396 | + @Override | ||
397 | + public Builder setLspObject(PcepLspObject lspObject) { | ||
398 | + this.lspObject = lspObject; | ||
399 | + this.bIsLSPObjectSet = true; | ||
400 | + return this; | ||
401 | + } | ||
402 | + | ||
403 | + @Override | ||
404 | + public Builder setMsgPath(PcepStateReport.PcepMsgPath msgPath) { | ||
405 | + this.msgPath = msgPath; | ||
406 | + this.bIsPcepMsgPathSet = true; | ||
407 | + return this; | ||
408 | + } | ||
409 | + } | ||
410 | + | ||
411 | + @Override | ||
412 | + public String toString() { | ||
413 | + ToStringHelper toStrHelper = MoreObjects.toStringHelper(getClass()); | ||
414 | + | ||
415 | + if (this.srpObject instanceof PcepSrpObject) { | ||
416 | + toStrHelper.add("SrpObject", srpObject); | ||
417 | + } | ||
418 | + if (this.lspObject instanceof PcepLspObject) { | ||
419 | + toStrHelper.add("LspObject", lspObject); | ||
420 | + } | ||
421 | + if (this.msgPath instanceof PcepStateReport.PcepMsgPath) { | ||
422 | + toStrHelper.add("MsgPath", msgPath); | ||
423 | + } | ||
424 | + return toStrHelper.toString(); | ||
425 | + } | ||
426 | +} | ||
... | \ 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.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 | + * LabelSubObject: Provides a LabelSubObject. | ||
30 | + */ | ||
31 | +public class LabelSubObject implements PcepValueType { | ||
32 | + | ||
33 | + /* Reference : RFC 3209 | ||
34 | + * LABEL Sub Object | ||
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 | Flags | C-Type | | ||
40 | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
41 | + | Contents of Label Object | | ||
42 | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
43 | + */ | ||
44 | + protected static final Logger log = LoggerFactory.getLogger(LabelSubObject.class); | ||
45 | + | ||
46 | + public static final short TYPE = 0x03; | ||
47 | + public static final short LENGTH = 8; | ||
48 | + private final byte flags; | ||
49 | + private final byte cType; | ||
50 | + private final int contents; | ||
51 | + | ||
52 | + /** | ||
53 | + * constructor to initialize parameters for LabelSubObject. | ||
54 | + * | ||
55 | + * @param flags flags | ||
56 | + * @param cType C-Type | ||
57 | + * @param contents Contents of label object | ||
58 | + */ | ||
59 | + public LabelSubObject(byte flags, byte cType, int contents) { | ||
60 | + this.flags = flags; | ||
61 | + this.cType = cType; | ||
62 | + this.contents = contents; | ||
63 | + } | ||
64 | + | ||
65 | + /** | ||
66 | + * Return an object of LabelSubObject. | ||
67 | + * | ||
68 | + * @param flags flags | ||
69 | + * @param cType C-type | ||
70 | + * @param contents contents of label objects | ||
71 | + * @return object of LabelSubObject | ||
72 | + */ | ||
73 | + public static LabelSubObject of(byte flags, byte cType, int contents) { | ||
74 | + return new LabelSubObject(flags, cType, contents); | ||
75 | + } | ||
76 | + | ||
77 | + /** | ||
78 | + * Returns Flags. | ||
79 | + * | ||
80 | + * @return flags | ||
81 | + */ | ||
82 | + public byte getFlags() { | ||
83 | + return flags; | ||
84 | + } | ||
85 | + | ||
86 | + /** | ||
87 | + * Returns cType. | ||
88 | + * | ||
89 | + * @return cType | ||
90 | + */ | ||
91 | + public byte getCtype() { | ||
92 | + return cType; | ||
93 | + } | ||
94 | + | ||
95 | + /** | ||
96 | + * Returns contents. | ||
97 | + * | ||
98 | + * @return contents | ||
99 | + */ | ||
100 | + public int getContents() { | ||
101 | + return contents; | ||
102 | + } | ||
103 | + | ||
104 | + @Override | ||
105 | + public PcepVersion getVersion() { | ||
106 | + return PcepVersion.PCEP_1; | ||
107 | + } | ||
108 | + | ||
109 | + @Override | ||
110 | + public short getType() { | ||
111 | + return TYPE; | ||
112 | + } | ||
113 | + | ||
114 | + @Override | ||
115 | + public short getLength() { | ||
116 | + return LENGTH; | ||
117 | + } | ||
118 | + | ||
119 | + @Override | ||
120 | + public int hashCode() { | ||
121 | + return Objects.hash(flags, cType, contents); | ||
122 | + } | ||
123 | + | ||
124 | + @Override | ||
125 | + public boolean equals(Object obj) { | ||
126 | + if (this == obj) { | ||
127 | + return true; | ||
128 | + } | ||
129 | + if (obj instanceof LabelSubObject) { | ||
130 | + LabelSubObject other = (LabelSubObject) obj; | ||
131 | + return Objects.equals(this.flags, other.flags) && Objects.equals(this.cType, other.cType) | ||
132 | + && Objects.equals(this.contents, other.contents); | ||
133 | + } | ||
134 | + return false; | ||
135 | + } | ||
136 | + | ||
137 | + @Override | ||
138 | + public int write(ChannelBuffer c) { | ||
139 | + int iStartIndex = c.writerIndex(); | ||
140 | + c.writeShort(TYPE); | ||
141 | + c.writeShort(LENGTH); | ||
142 | + c.writeByte(flags); | ||
143 | + c.writeByte(cType); | ||
144 | + c.writeByte(contents); | ||
145 | + return c.writerIndex() - iStartIndex; | ||
146 | + } | ||
147 | + | ||
148 | + /** | ||
149 | + * Reads the channel buffer and returns object of LabelSubObject. | ||
150 | + * | ||
151 | + * @param c type of channel buffer | ||
152 | + * @return object of LabelSubObject | ||
153 | + */ | ||
154 | + public static PcepValueType read(ChannelBuffer c) { | ||
155 | + byte flags = c.readByte(); | ||
156 | + byte cType = c.readByte(); | ||
157 | + int contents = c.readInt(); | ||
158 | + return new LabelSubObject(flags, cType, contents); | ||
159 | + } | ||
160 | + | ||
161 | + @Override | ||
162 | + public String toString() { | ||
163 | + return MoreObjects.toStringHelper(getClass()).add("type", TYPE).add("Length", LENGTH).add("flags", flags) | ||
164 | + .add("C-type", cType).add("contents", contents).toString(); | ||
165 | + } | ||
166 | +} |
-
Please register or login to post a comment