Committed by
Gerrit Code Review
[ONOS-2344]Implementation of PCEP report messages.
Change-Id: I9258a34ad7b09a583dcd0e56f90a36958c3acb34
Showing
5 changed files
with
425 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 | +} |
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
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