Committed by
Gerrit Code Review
[ONOS-2356] Implementation for PCEP label update message.
Change-Id: I510a9a7c7c868da1fc3d6e2625501f094faf8115
Showing
11 changed files
with
1638 additions
and
0 deletions
pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepFecObjectIPv4AdjacencyVer1.java
0 → 100644
1 | +/* | ||
2 | + * Copyright 2015 Open Networking Laboratory | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | + | ||
17 | +package org.onosproject.pcepio.protocol.ver1; | ||
18 | + | ||
19 | +import org.jboss.netty.buffer.ChannelBuffer; | ||
20 | +import org.onosproject.pcepio.exceptions.PcepParseException; | ||
21 | +import org.onosproject.pcepio.protocol.PcepFecObjectIPv4Adjacency; | ||
22 | +import org.onosproject.pcepio.protocol.PcepVersion; | ||
23 | +import org.onosproject.pcepio.types.PcepObjectHeader; | ||
24 | +import org.slf4j.Logger; | ||
25 | +import org.slf4j.LoggerFactory; | ||
26 | + | ||
27 | +import com.google.common.base.MoreObjects; | ||
28 | + | ||
29 | +public class PcepFecObjectIPv4AdjacencyVer1 implements PcepFecObjectIPv4Adjacency { | ||
30 | + | ||
31 | + /* | ||
32 | + * ref : draft-zhao-pce-pcep-extension-for-pce-controller-01 , section : 7.5 | ||
33 | + * | ||
34 | + 0 1 2 3 | ||
35 | + 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 | ||
36 | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
37 | + | Local IPv4 address | | ||
38 | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
39 | + | Remote IPv4 address | | ||
40 | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
41 | + | ||
42 | + FEC Object-Type is 3 IPv4 Adjacency | ||
43 | + */ | ||
44 | + protected static final Logger log = LoggerFactory.getLogger(PcepFecObjectIPv4AdjacencyVer1.class); | ||
45 | + | ||
46 | + public static final byte FEC_OBJ_TYPE = 3; | ||
47 | + public static final byte FEC_OBJ_CLASS = 36; //to be defined | ||
48 | + public static final byte FEC_OBJECT_VERSION = 1; | ||
49 | + public static final short FEC_OBJ_MINIMUM_LENGTH = 12; | ||
50 | + public static final int MINIMUM_COMMON_HEADER_LENGTH = 4; | ||
51 | + | ||
52 | + static final PcepObjectHeader DEFAULT_FEC_OBJECT_HEADER = new PcepObjectHeader(FEC_OBJ_CLASS, FEC_OBJ_TYPE, | ||
53 | + PcepObjectHeader.REQ_OBJ_OPTIONAL_PROCESS, PcepObjectHeader.RSP_OBJ_PROCESSED, FEC_OBJ_MINIMUM_LENGTH); | ||
54 | + | ||
55 | + private PcepObjectHeader fecObjHeader; | ||
56 | + private int localIPv4Address; | ||
57 | + private int remoteIPv4Address; | ||
58 | + | ||
59 | + /** | ||
60 | + * Constructor to initialize parameters for PCEP fec object . | ||
61 | + * | ||
62 | + * @param fecObjHeader FEC Object header | ||
63 | + * @param localIPv4Address Local IPv4 Address | ||
64 | + * @param remoteIPv4Address Remote IPv4 Address | ||
65 | + */ | ||
66 | + public PcepFecObjectIPv4AdjacencyVer1(PcepObjectHeader fecObjHeader, int localIPv4Address, int remoteIPv4Address) { | ||
67 | + this.fecObjHeader = fecObjHeader; | ||
68 | + this.localIPv4Address = localIPv4Address; | ||
69 | + this.remoteIPv4Address = remoteIPv4Address; | ||
70 | + } | ||
71 | + | ||
72 | + /** | ||
73 | + * Sets Object header. | ||
74 | + * | ||
75 | + * @param obj Pcep fec Object Header | ||
76 | + */ | ||
77 | + public void setFecIpv4ObjHeader(PcepObjectHeader obj) { | ||
78 | + this.fecObjHeader = obj; | ||
79 | + } | ||
80 | + | ||
81 | + @Override | ||
82 | + public int getLocalIPv4Address() { | ||
83 | + return this.localIPv4Address; | ||
84 | + } | ||
85 | + | ||
86 | + @Override | ||
87 | + public void seLocalIPv4Address(int value) { | ||
88 | + this.localIPv4Address = value; | ||
89 | + } | ||
90 | + | ||
91 | + @Override | ||
92 | + public int getRemoteIPv4Address() { | ||
93 | + return this.remoteIPv4Address; | ||
94 | + } | ||
95 | + | ||
96 | + @Override | ||
97 | + public void seRemoteIPv4Address(int value) { | ||
98 | + this.remoteIPv4Address = value; | ||
99 | + } | ||
100 | + | ||
101 | + /** | ||
102 | + * Reads from channel buffer and Returns object of PcepFecObjectIPv4Adjacency. | ||
103 | + * | ||
104 | + * @param cb of channel buffer. | ||
105 | + * @return object of PcepFecObjectIPv4Adjacency | ||
106 | + * @throws PcepParseException when fails to read from channel buffer | ||
107 | + */ | ||
108 | + public static PcepFecObjectIPv4Adjacency read(ChannelBuffer cb) throws PcepParseException { | ||
109 | + | ||
110 | + PcepObjectHeader fecObjHeader; | ||
111 | + int localIPv4Address; | ||
112 | + int remoteIPv4Address; | ||
113 | + | ||
114 | + fecObjHeader = PcepObjectHeader.read(cb); | ||
115 | + | ||
116 | + //take only FEC IPv4 Adjacency Object buffer. | ||
117 | + ChannelBuffer tempCb = cb.readBytes(fecObjHeader.getObjLen() - MINIMUM_COMMON_HEADER_LENGTH); | ||
118 | + localIPv4Address = tempCb.readInt(); | ||
119 | + remoteIPv4Address = tempCb.readInt(); | ||
120 | + | ||
121 | + return new PcepFecObjectIPv4AdjacencyVer1(fecObjHeader, localIPv4Address, remoteIPv4Address); | ||
122 | + } | ||
123 | + | ||
124 | + @Override | ||
125 | + public int write(ChannelBuffer cb) throws PcepParseException { | ||
126 | + | ||
127 | + int objStartIndex = cb.writerIndex(); | ||
128 | + | ||
129 | + //Write common header | ||
130 | + int objLenIndex = fecObjHeader.write(cb); | ||
131 | + cb.writeInt(localIPv4Address); | ||
132 | + cb.writeInt(remoteIPv4Address); | ||
133 | + | ||
134 | + //Now write FEC IPv4 Adjacency Object Length | ||
135 | + cb.setShort(objLenIndex, (short) (cb.writerIndex() - objStartIndex)); | ||
136 | + return cb.writerIndex(); | ||
137 | + } | ||
138 | + | ||
139 | + /** | ||
140 | + * Builder class for PCEP fec object IPv4 Adjacency. | ||
141 | + */ | ||
142 | + public static class Builder implements PcepFecObjectIPv4Adjacency.Builder { | ||
143 | + private boolean bIsHeaderSet = false; | ||
144 | + private boolean bIsLocalIPv4Addressset = false; | ||
145 | + private boolean bIsRemoteIPv4Addressset = false; | ||
146 | + | ||
147 | + private PcepObjectHeader fecObjHeader; | ||
148 | + int localIPv4Address; | ||
149 | + int remoteIPv4Address; | ||
150 | + | ||
151 | + private boolean bIsPFlagSet = false; | ||
152 | + private boolean bPFlag; | ||
153 | + | ||
154 | + private boolean bIsIFlagSet = false; | ||
155 | + private boolean bIFlag; | ||
156 | + | ||
157 | + @Override | ||
158 | + public PcepFecObjectIPv4Adjacency build() throws PcepParseException { | ||
159 | + PcepObjectHeader fecObjHeader = this.bIsHeaderSet ? this.fecObjHeader : DEFAULT_FEC_OBJECT_HEADER; | ||
160 | + | ||
161 | + if (!this.bIsLocalIPv4Addressset) { | ||
162 | + throw new PcepParseException( | ||
163 | + "Local IPv4 Address not set while building PcepFecObjectIPv4Adjacency object."); | ||
164 | + } | ||
165 | + | ||
166 | + if (!this.bIsRemoteIPv4Addressset) { | ||
167 | + throw new PcepParseException( | ||
168 | + " Remote IPv4 Address not set while building PcepFecObjectIPv4Adjacency object."); | ||
169 | + } | ||
170 | + | ||
171 | + if (bIsPFlagSet) { | ||
172 | + fecObjHeader.setPFlag(bPFlag); | ||
173 | + } | ||
174 | + | ||
175 | + if (bIsIFlagSet) { | ||
176 | + fecObjHeader.setIFlag(bIFlag); | ||
177 | + } | ||
178 | + return new PcepFecObjectIPv4AdjacencyVer1(fecObjHeader, this.localIPv4Address, this.remoteIPv4Address); | ||
179 | + } | ||
180 | + | ||
181 | + @Override | ||
182 | + public Builder setPFlag(boolean value) { | ||
183 | + this.bPFlag = value; | ||
184 | + this.bIsPFlagSet = true; | ||
185 | + return this; | ||
186 | + } | ||
187 | + | ||
188 | + @Override | ||
189 | + public Builder setIFlag(boolean value) { | ||
190 | + this.bIFlag = value; | ||
191 | + this.bIsIFlagSet = true; | ||
192 | + return this; | ||
193 | + } | ||
194 | + | ||
195 | + @Override | ||
196 | + public PcepObjectHeader getFecIpv4AdjacencyObjHeader() { | ||
197 | + return this.fecObjHeader; | ||
198 | + } | ||
199 | + | ||
200 | + @Override | ||
201 | + public Builder setFecIpv4AdjacencyObjHeader(PcepObjectHeader obj) { | ||
202 | + this.fecObjHeader = obj; | ||
203 | + this.bIsHeaderSet = true; | ||
204 | + return this; | ||
205 | + } | ||
206 | + | ||
207 | + @Override | ||
208 | + public int getLocalIPv4Address() { | ||
209 | + return this.localIPv4Address; | ||
210 | + } | ||
211 | + | ||
212 | + @Override | ||
213 | + public Builder seLocalIPv4Address(int value) { | ||
214 | + this.localIPv4Address = value; | ||
215 | + this.bIsLocalIPv4Addressset = true; | ||
216 | + return this; | ||
217 | + } | ||
218 | + | ||
219 | + @Override | ||
220 | + public int getRemoteIPv4Address() { | ||
221 | + return this.remoteIPv4Address; | ||
222 | + } | ||
223 | + | ||
224 | + @Override | ||
225 | + public Builder seRemoteIPv4Address(int value) { | ||
226 | + this.remoteIPv4Address = value; | ||
227 | + this.bIsRemoteIPv4Addressset = true; | ||
228 | + return this; | ||
229 | + } | ||
230 | + | ||
231 | + } | ||
232 | + | ||
233 | + @Override | ||
234 | + public PcepVersion getVersion() { | ||
235 | + return PcepVersion.PCEP_1; | ||
236 | + } | ||
237 | + | ||
238 | + @Override | ||
239 | + public int getType() { | ||
240 | + return FEC_OBJ_TYPE; | ||
241 | + } | ||
242 | + | ||
243 | + @Override | ||
244 | + public String toString() { | ||
245 | + return MoreObjects.toStringHelper(getClass()).add("fecObjHeader", fecObjHeader) | ||
246 | + .add("localIPv4Address", localIPv4Address).add("remoteIPv4Address", remoteIPv4Address).toString(); | ||
247 | + } | ||
248 | +} |
This diff is collapsed. Click to expand it.
pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepFecObjectIPv4Ver1.java
0 → 100644
1 | +/* | ||
2 | + * Copyright 2015 Open Networking Laboratory | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | + | ||
17 | +package org.onosproject.pcepio.protocol.ver1; | ||
18 | + | ||
19 | +import org.jboss.netty.buffer.ChannelBuffer; | ||
20 | +import org.onosproject.pcepio.exceptions.PcepParseException; | ||
21 | +import org.onosproject.pcepio.protocol.PcepFecObjectIPv4; | ||
22 | +import org.onosproject.pcepio.protocol.PcepVersion; | ||
23 | +import org.onosproject.pcepio.types.PcepObjectHeader; | ||
24 | +import org.slf4j.Logger; | ||
25 | +import org.slf4j.LoggerFactory; | ||
26 | + | ||
27 | +import com.google.common.base.MoreObjects; | ||
28 | + | ||
29 | +public class PcepFecObjectIPv4Ver1 implements PcepFecObjectIPv4 { | ||
30 | + | ||
31 | + /* | ||
32 | + * ref : draft-zhao-pce-pcep-extension-for-pce-controller-01 , section : 7.5 | ||
33 | + * | ||
34 | + 0 1 2 3 | ||
35 | + 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 | ||
36 | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
37 | + | IPv4 Node ID | | ||
38 | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
39 | + | ||
40 | + FEC Object-Type is 1 IPv4 Node ID | ||
41 | + */ | ||
42 | + protected static final Logger log = LoggerFactory.getLogger(PcepFecObjectIPv4Ver1.class); | ||
43 | + | ||
44 | + public static final byte FEC_OBJ_TYPE = 1; | ||
45 | + public static final byte FEC_OBJ_CLASS = 63; //to be defined | ||
46 | + public static final byte FEC_OBJECT_VERSION = 1; | ||
47 | + public static final short FEC_OBJ_MINIMUM_LENGTH = 8; | ||
48 | + public static final int MINIMUM_COMMON_HEADER_LENGTH = 4; | ||
49 | + | ||
50 | + static final PcepObjectHeader DEFAULT_FEC_OBJECT_HEADER = new PcepObjectHeader(FEC_OBJ_CLASS, FEC_OBJ_TYPE, | ||
51 | + PcepObjectHeader.REQ_OBJ_OPTIONAL_PROCESS, PcepObjectHeader.RSP_OBJ_PROCESSED, FEC_OBJ_MINIMUM_LENGTH); | ||
52 | + | ||
53 | + private PcepObjectHeader fecObjHeader; | ||
54 | + private int nodeID; | ||
55 | + | ||
56 | + /** | ||
57 | + * Constructor to initialize parameters for PCEP fec object. | ||
58 | + * | ||
59 | + * @param fecObjHeader fec object header | ||
60 | + * @param nodeID node id | ||
61 | + */ | ||
62 | + public PcepFecObjectIPv4Ver1(PcepObjectHeader fecObjHeader, int nodeID) { | ||
63 | + this.fecObjHeader = fecObjHeader; | ||
64 | + this.nodeID = nodeID; | ||
65 | + } | ||
66 | + | ||
67 | + /** | ||
68 | + * Sets the Object Header. | ||
69 | + * | ||
70 | + * @param obj object header | ||
71 | + */ | ||
72 | + public void setFecIpv4ObjHeader(PcepObjectHeader obj) { | ||
73 | + this.fecObjHeader = obj; | ||
74 | + } | ||
75 | + | ||
76 | + @Override | ||
77 | + public void setNodeID(int nodeID) { | ||
78 | + this.nodeID = nodeID; | ||
79 | + } | ||
80 | + | ||
81 | + /** | ||
82 | + * Returns Object Header. | ||
83 | + * | ||
84 | + * @return fecObjHeader fec object header | ||
85 | + */ | ||
86 | + public PcepObjectHeader getFecIpv4ObjHeader() { | ||
87 | + return this.fecObjHeader; | ||
88 | + } | ||
89 | + | ||
90 | + @Override | ||
91 | + public int getNodeID() { | ||
92 | + return this.nodeID; | ||
93 | + } | ||
94 | + | ||
95 | + /** | ||
96 | + * Reads from channel buffer and returns object of PcepFecObjectIPv4. | ||
97 | + * | ||
98 | + * @param cb of channel buffer | ||
99 | + * @return object of PcepFecObjectIPv4 | ||
100 | + * @throws PcepParseException when fails to read from channel buffer | ||
101 | + */ | ||
102 | + public static PcepFecObjectIPv4 read(ChannelBuffer cb) throws PcepParseException { | ||
103 | + | ||
104 | + PcepObjectHeader fecObjHeader; | ||
105 | + int nodeID; | ||
106 | + fecObjHeader = PcepObjectHeader.read(cb); | ||
107 | + nodeID = cb.readInt(); | ||
108 | + return new PcepFecObjectIPv4Ver1(fecObjHeader, nodeID); | ||
109 | + } | ||
110 | + | ||
111 | + @Override | ||
112 | + public int write(ChannelBuffer cb) throws PcepParseException { | ||
113 | + | ||
114 | + int objStartIndex = cb.writerIndex(); | ||
115 | + | ||
116 | + //write common header | ||
117 | + int objLenIndex = fecObjHeader.write(cb); | ||
118 | + cb.writeInt(nodeID); | ||
119 | + | ||
120 | + //now write FEC IPv4 Object Length | ||
121 | + cb.setShort(objLenIndex, (short) (cb.writerIndex() - objStartIndex)); | ||
122 | + return cb.writerIndex(); | ||
123 | + } | ||
124 | + | ||
125 | + /** | ||
126 | + * Builder class for PCEP fec pobject IPv4. | ||
127 | + */ | ||
128 | + public static class Builder implements PcepFecObjectIPv4.Builder { | ||
129 | + private boolean bIsHeaderSet = false; | ||
130 | + private boolean bIsNodeIdset = false; | ||
131 | + | ||
132 | + private PcepObjectHeader fecObjHeader; | ||
133 | + private int nodeID; | ||
134 | + | ||
135 | + private boolean bIsPFlagSet = false; | ||
136 | + private boolean bPFlag; | ||
137 | + | ||
138 | + private boolean bIsIFlagSet = false; | ||
139 | + private boolean bIFlag; | ||
140 | + | ||
141 | + @Override | ||
142 | + public PcepFecObjectIPv4 build() throws PcepParseException { | ||
143 | + PcepObjectHeader fecObjHeader = this.bIsHeaderSet ? this.fecObjHeader : DEFAULT_FEC_OBJECT_HEADER; | ||
144 | + | ||
145 | + if (!this.bIsNodeIdset) { | ||
146 | + throw new PcepParseException("NodeID not set while building PcepFecObjectIPv4 object."); | ||
147 | + } | ||
148 | + if (bIsPFlagSet) { | ||
149 | + fecObjHeader.setPFlag(bPFlag); | ||
150 | + } | ||
151 | + if (bIsIFlagSet) { | ||
152 | + fecObjHeader.setIFlag(bIFlag); | ||
153 | + } | ||
154 | + return new PcepFecObjectIPv4Ver1(fecObjHeader, this.nodeID); | ||
155 | + } | ||
156 | + | ||
157 | + @Override | ||
158 | + public Builder setPFlag(boolean value) { | ||
159 | + this.bPFlag = value; | ||
160 | + this.bIsPFlagSet = true; | ||
161 | + return this; | ||
162 | + } | ||
163 | + | ||
164 | + @Override | ||
165 | + public Builder setIFlag(boolean value) { | ||
166 | + this.bIFlag = value; | ||
167 | + this.bIsIFlagSet = true; | ||
168 | + return this; | ||
169 | + } | ||
170 | + | ||
171 | + @Override | ||
172 | + public PcepObjectHeader getFecIpv4ObjHeader() { | ||
173 | + return this.fecObjHeader; | ||
174 | + } | ||
175 | + | ||
176 | + @Override | ||
177 | + public Builder setFecIpv4ObjHeader(PcepObjectHeader obj) { | ||
178 | + this.fecObjHeader = obj; | ||
179 | + this.bIsHeaderSet = true; | ||
180 | + return this; | ||
181 | + } | ||
182 | + | ||
183 | + @Override | ||
184 | + public int getNodeID() { | ||
185 | + return this.nodeID; | ||
186 | + } | ||
187 | + | ||
188 | + @Override | ||
189 | + public Builder setNodeID(int value) { | ||
190 | + this.nodeID = value; | ||
191 | + this.bIsNodeIdset = true; | ||
192 | + return this; | ||
193 | + } | ||
194 | + | ||
195 | + } | ||
196 | + | ||
197 | + @Override | ||
198 | + public PcepVersion getVersion() { | ||
199 | + return PcepVersion.PCEP_1; | ||
200 | + } | ||
201 | + | ||
202 | + @Override | ||
203 | + public int getType() { | ||
204 | + return FEC_OBJ_TYPE; | ||
205 | + } | ||
206 | + | ||
207 | + @Override | ||
208 | + public String toString() { | ||
209 | + return MoreObjects.toStringHelper(getClass()).add("fecObjHeader", fecObjHeader).add("nodeID: ", nodeID) | ||
210 | + .toString(); | ||
211 | + } | ||
212 | +} |
pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepFecObjectIPv6AdjacencyVer1.java
0 → 100644
1 | +/* | ||
2 | + * Copyright 2015 Open Networking Laboratory | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | + | ||
17 | +package org.onosproject.pcepio.protocol.ver1; | ||
18 | + | ||
19 | +import org.jboss.netty.buffer.ChannelBuffer; | ||
20 | +import org.onosproject.pcepio.exceptions.PcepParseException; | ||
21 | +import org.onosproject.pcepio.protocol.PcepFecObjectIPv6Adjacency; | ||
22 | +import org.onosproject.pcepio.protocol.PcepVersion; | ||
23 | +import org.onosproject.pcepio.types.PcepObjectHeader; | ||
24 | +import org.slf4j.Logger; | ||
25 | +import org.slf4j.LoggerFactory; | ||
26 | + | ||
27 | +import com.google.common.base.MoreObjects; | ||
28 | + | ||
29 | +public class PcepFecObjectIPv6AdjacencyVer1 implements PcepFecObjectIPv6Adjacency { | ||
30 | + | ||
31 | + /* | ||
32 | + * ref : draft-zhao-pce-pcep-extension-for-pce-controller-01 , section : 7.5 | ||
33 | + * | ||
34 | + 0 1 2 3 | ||
35 | + 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 | ||
36 | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
37 | + | | | ||
38 | + // Local IPv6 address (16 bytes) // | ||
39 | + | | | ||
40 | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
41 | + | | | ||
42 | + // Remote IPv6 address (16 bytes) // | ||
43 | + | | | ||
44 | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
45 | + | ||
46 | + FEC Object-Type is 4 IPv6 Adjacency | ||
47 | + */ | ||
48 | + protected static final Logger log = LoggerFactory.getLogger(PcepFecObjectIPv6AdjacencyVer1.class); | ||
49 | + | ||
50 | + public static final byte FEC_OBJ_TYPE = 4; | ||
51 | + public static final byte FEC_OBJ_CLASS = 63; //to be defined | ||
52 | + public static final byte FEC_OBJECT_VERSION = 1; | ||
53 | + public static final short FEC_OBJ_MINIMUM_LENGTH = 36; | ||
54 | + public static final int MINIMUM_COMMON_HEADER_LENGTH = 4; | ||
55 | + public static final int IPV6_ADDRESS_LENGTH = 16; | ||
56 | + | ||
57 | + static final PcepObjectHeader DEFAULT_FEC_OBJECT_HEADER = new PcepObjectHeader(FEC_OBJ_CLASS, FEC_OBJ_TYPE, | ||
58 | + PcepObjectHeader.REQ_OBJ_OPTIONAL_PROCESS, PcepObjectHeader.RSP_OBJ_PROCESSED, FEC_OBJ_MINIMUM_LENGTH); | ||
59 | + | ||
60 | + private PcepObjectHeader fecObjHeader; | ||
61 | + private byte[] localIPv6Address = new byte[IPV6_ADDRESS_LENGTH]; | ||
62 | + private byte[] remoteIPv6Address = new byte[IPV6_ADDRESS_LENGTH]; | ||
63 | + | ||
64 | + /** | ||
65 | + * Constructor to initialize parameters for PCEP fec object. | ||
66 | + * | ||
67 | + * @param fecObjHeader fec object header | ||
68 | + * @param localIPv6Address local IPv6 address | ||
69 | + * @param remoteIPv6Address remote IPv6 address | ||
70 | + */ | ||
71 | + public PcepFecObjectIPv6AdjacencyVer1(PcepObjectHeader fecObjHeader, byte[] localIPv6Address, | ||
72 | + byte[] remoteIPv6Address) { | ||
73 | + this.fecObjHeader = fecObjHeader; | ||
74 | + this.localIPv6Address = localIPv6Address; | ||
75 | + this.remoteIPv6Address = remoteIPv6Address; | ||
76 | + } | ||
77 | + | ||
78 | + /** | ||
79 | + * Sets Object Header. | ||
80 | + * | ||
81 | + * @param obj object header | ||
82 | + */ | ||
83 | + public void setFecIpv4ObjHeader(PcepObjectHeader obj) { | ||
84 | + this.fecObjHeader = obj; | ||
85 | + } | ||
86 | + | ||
87 | + @Override | ||
88 | + public byte[] getLocalIPv6Address() { | ||
89 | + return this.localIPv6Address; | ||
90 | + } | ||
91 | + | ||
92 | + @Override | ||
93 | + public void seLocalIPv6Address(byte[] value) { | ||
94 | + this.localIPv6Address = value; | ||
95 | + } | ||
96 | + | ||
97 | + @Override | ||
98 | + public byte[] getRemoteIPv6Address() { | ||
99 | + return this.remoteIPv6Address; | ||
100 | + } | ||
101 | + | ||
102 | + @Override | ||
103 | + public void seRemoteIPv6Address(byte[] value) { | ||
104 | + this.remoteIPv6Address = value; | ||
105 | + } | ||
106 | + | ||
107 | + /** | ||
108 | + * Reads channel buffer and Returns object of PcepFecObjectIPv6Adjacency. | ||
109 | + * | ||
110 | + * @param cb of channel buffer | ||
111 | + * @return object of PcepFecObjectIPv6Adjacency | ||
112 | + * @throws PcepParseException when fails tp read from channel buffer | ||
113 | + */ | ||
114 | + public static PcepFecObjectIPv6Adjacency read(ChannelBuffer cb) throws PcepParseException { | ||
115 | + | ||
116 | + PcepObjectHeader fecObjHeader; | ||
117 | + byte[] localIPv6Address = new byte[IPV6_ADDRESS_LENGTH]; | ||
118 | + byte[] remoteIPv6Address = new byte[IPV6_ADDRESS_LENGTH]; | ||
119 | + fecObjHeader = PcepObjectHeader.read(cb); | ||
120 | + cb.readBytes(localIPv6Address, 0, IPV6_ADDRESS_LENGTH); | ||
121 | + cb.readBytes(remoteIPv6Address, 0, IPV6_ADDRESS_LENGTH); | ||
122 | + return new PcepFecObjectIPv6AdjacencyVer1(fecObjHeader, localIPv6Address, remoteIPv6Address); | ||
123 | + } | ||
124 | + | ||
125 | + @Override | ||
126 | + public int write(ChannelBuffer cb) throws PcepParseException { | ||
127 | + | ||
128 | + int objStartIndex = cb.writerIndex(); | ||
129 | + | ||
130 | + //write common header | ||
131 | + int objLenIndex = fecObjHeader.write(cb); | ||
132 | + cb.writeBytes(localIPv6Address); | ||
133 | + cb.writeBytes(remoteIPv6Address); | ||
134 | + //now write FEC IPv6 Adjacency Object Length | ||
135 | + cb.setShort(objLenIndex, (short) (cb.writerIndex() - objStartIndex)); | ||
136 | + return cb.writerIndex(); | ||
137 | + } | ||
138 | + | ||
139 | + /** | ||
140 | + * Builder class for PCEP fec object IPv6 Adjacency. | ||
141 | + */ | ||
142 | + public static class Builder implements PcepFecObjectIPv6Adjacency.Builder { | ||
143 | + private boolean bIsHeaderSet = false; | ||
144 | + private boolean bIsLocalIPv6Addressset = false; | ||
145 | + private boolean bIsRemoteIPv6Addressset = false; | ||
146 | + | ||
147 | + private PcepObjectHeader fecObjHeader; | ||
148 | + byte[] localIPv6Address = new byte[IPV6_ADDRESS_LENGTH]; | ||
149 | + byte[] remoteIPv6Address = new byte[IPV6_ADDRESS_LENGTH]; | ||
150 | + | ||
151 | + private boolean bIsPFlagSet = false; | ||
152 | + private boolean bPFlag; | ||
153 | + | ||
154 | + private boolean bIsIFlagSet = false; | ||
155 | + private boolean bIFlag; | ||
156 | + | ||
157 | + @Override | ||
158 | + public PcepFecObjectIPv6Adjacency build() throws PcepParseException { | ||
159 | + PcepObjectHeader fecObjHeader = this.bIsHeaderSet ? this.fecObjHeader : DEFAULT_FEC_OBJECT_HEADER; | ||
160 | + | ||
161 | + if (!this.bIsLocalIPv6Addressset) { | ||
162 | + throw new PcepParseException( | ||
163 | + "Local IPv6 Address not set while building PcepFecObjectIPv6Adjacency object."); | ||
164 | + } | ||
165 | + if (!this.bIsRemoteIPv6Addressset) { | ||
166 | + throw new PcepParseException( | ||
167 | + "Remote IPv6 Address not set while building PcepFecObjectIPv6Adjacency object."); | ||
168 | + } | ||
169 | + if (bIsPFlagSet) { | ||
170 | + fecObjHeader.setPFlag(bPFlag); | ||
171 | + } | ||
172 | + if (bIsIFlagSet) { | ||
173 | + fecObjHeader.setIFlag(bIFlag); | ||
174 | + } | ||
175 | + return new PcepFecObjectIPv6AdjacencyVer1(fecObjHeader, this.localIPv6Address, this.remoteIPv6Address); | ||
176 | + } | ||
177 | + | ||
178 | + @Override | ||
179 | + public Builder setPFlag(boolean value) { | ||
180 | + this.bPFlag = value; | ||
181 | + this.bIsPFlagSet = true; | ||
182 | + return this; | ||
183 | + } | ||
184 | + | ||
185 | + @Override | ||
186 | + public Builder setIFlag(boolean value) { | ||
187 | + this.bIFlag = value; | ||
188 | + this.bIsIFlagSet = true; | ||
189 | + return this; | ||
190 | + } | ||
191 | + | ||
192 | + @Override | ||
193 | + public PcepObjectHeader getFecIpv6AdjacencyObjHeader() { | ||
194 | + return this.fecObjHeader; | ||
195 | + } | ||
196 | + | ||
197 | + @Override | ||
198 | + public Builder setFecIpv6AdjacencyObjHeader(PcepObjectHeader obj) { | ||
199 | + this.fecObjHeader = obj; | ||
200 | + this.bIsHeaderSet = true; | ||
201 | + return this; | ||
202 | + } | ||
203 | + | ||
204 | + @Override | ||
205 | + public byte[] getLocalIPv6Address() { | ||
206 | + return this.localIPv6Address; | ||
207 | + } | ||
208 | + | ||
209 | + @Override | ||
210 | + public Builder setLocalIPv6Address(byte[] value) { | ||
211 | + this.localIPv6Address = value; | ||
212 | + this.bIsLocalIPv6Addressset = true; | ||
213 | + return this; | ||
214 | + } | ||
215 | + | ||
216 | + @Override | ||
217 | + public byte[] getRemoteIPv6Address() { | ||
218 | + return this.remoteIPv6Address; | ||
219 | + } | ||
220 | + | ||
221 | + @Override | ||
222 | + public Builder setRemoteIPv6Address(byte[] value) { | ||
223 | + this.remoteIPv6Address = value; | ||
224 | + this.bIsRemoteIPv6Addressset = true; | ||
225 | + return this; | ||
226 | + } | ||
227 | + } | ||
228 | + | ||
229 | + @Override | ||
230 | + public PcepVersion getVersion() { | ||
231 | + return PcepVersion.PCEP_1; | ||
232 | + } | ||
233 | + | ||
234 | + @Override | ||
235 | + public int getType() { | ||
236 | + return FEC_OBJ_TYPE; | ||
237 | + } | ||
238 | + | ||
239 | + @Override | ||
240 | + public String toString() { | ||
241 | + return MoreObjects.toStringHelper(getClass()).add("localIPv6Address", localIPv6Address) | ||
242 | + .add("remoteIPv6Address: ", remoteIPv6Address).toString(); | ||
243 | + } | ||
244 | +} |
pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepFecObjectIPv6Ver1.java
0 → 100644
1 | +/* | ||
2 | + * Copyright 2015 Open Networking Laboratory | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | + | ||
17 | +package org.onosproject.pcepio.protocol.ver1; | ||
18 | + | ||
19 | +import org.jboss.netty.buffer.ChannelBuffer; | ||
20 | +import org.onosproject.pcepio.exceptions.PcepParseException; | ||
21 | +import org.onosproject.pcepio.protocol.PcepFecObjectIPv6; | ||
22 | +import org.onosproject.pcepio.protocol.PcepVersion; | ||
23 | +import org.onosproject.pcepio.types.PcepObjectHeader; | ||
24 | +import org.slf4j.Logger; | ||
25 | +import org.slf4j.LoggerFactory; | ||
26 | + | ||
27 | +import com.google.common.base.MoreObjects; | ||
28 | + | ||
29 | +public class PcepFecObjectIPv6Ver1 implements PcepFecObjectIPv6 { | ||
30 | + | ||
31 | + /* | ||
32 | + * ref : draft-zhao-pce-pcep-extension-for-pce-controller-01 , section : 7.5 | ||
33 | + * | ||
34 | + 0 1 2 3 | ||
35 | + 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 | ||
36 | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
37 | + | | | ||
38 | + // IPv6 Node ID (16 bytes) // | ||
39 | + | | | ||
40 | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
41 | + | ||
42 | + FEC Object-Type is 2 IPv6 Node ID | ||
43 | + */ | ||
44 | + protected static final Logger log = LoggerFactory.getLogger(PcepFecObjectIPv6Ver1.class); | ||
45 | + | ||
46 | + public static final byte FEC_OBJ_TYPE = 2; | ||
47 | + public static final byte FEC_OBJ_CLASS = 63; //to be defined | ||
48 | + public static final byte FEC_OBJECT_VERSION = 1; | ||
49 | + public static final short FEC_OBJ_MINIMUM_LENGTH = 20; | ||
50 | + public static final int MINIMUM_COMMON_HEADER_LENGTH = 4; | ||
51 | + public static final int IPV6_ADDRESS_LENGTH = 16; | ||
52 | + | ||
53 | + static final PcepObjectHeader DEFAULT_FEC_OBJECT_HEADER = new PcepObjectHeader(FEC_OBJ_CLASS, FEC_OBJ_TYPE, | ||
54 | + PcepObjectHeader.REQ_OBJ_OPTIONAL_PROCESS, PcepObjectHeader.RSP_OBJ_PROCESSED, FEC_OBJ_MINIMUM_LENGTH); | ||
55 | + | ||
56 | + private PcepObjectHeader fecObjHeader; | ||
57 | + private byte[] nodeID = new byte[IPV6_ADDRESS_LENGTH]; | ||
58 | + | ||
59 | + /** | ||
60 | + * Constructor to initialize parameters for PCEP fec object. | ||
61 | + * | ||
62 | + * @param fecObjHeader Fec object header | ||
63 | + * @param nodeID node ID | ||
64 | + */ | ||
65 | + public PcepFecObjectIPv6Ver1(PcepObjectHeader fecObjHeader, byte[] nodeID) { | ||
66 | + this.fecObjHeader = fecObjHeader; | ||
67 | + this.nodeID = nodeID; | ||
68 | + } | ||
69 | + | ||
70 | + /** | ||
71 | + * Sets the Object header. | ||
72 | + * | ||
73 | + * @param obj object header | ||
74 | + */ | ||
75 | + public void setFecIpv6ObjHeader(PcepObjectHeader obj) { | ||
76 | + this.fecObjHeader = obj; | ||
77 | + } | ||
78 | + | ||
79 | + @Override | ||
80 | + public void setNodeID(byte[] nodeID) { | ||
81 | + this.nodeID = nodeID; | ||
82 | + } | ||
83 | + | ||
84 | + /** | ||
85 | + * Returns object header. | ||
86 | + * | ||
87 | + * @return fec Object Header | ||
88 | + */ | ||
89 | + public PcepObjectHeader getFecIpv6ObjHeader() { | ||
90 | + return this.fecObjHeader; | ||
91 | + } | ||
92 | + | ||
93 | + @Override | ||
94 | + public byte[] getNodeID() { | ||
95 | + return this.nodeID; | ||
96 | + } | ||
97 | + | ||
98 | + /** | ||
99 | + * reads the channel buffer and returns object of PcepFecObjectIPv6. | ||
100 | + * | ||
101 | + * @param cb of channel buffer. | ||
102 | + * @return object of PcepFecObjectIPv6 | ||
103 | + * @throws PcepParseException when fails to read from channel buffer | ||
104 | + */ | ||
105 | + public static PcepFecObjectIPv6 read(ChannelBuffer cb) throws PcepParseException { | ||
106 | + | ||
107 | + PcepObjectHeader fecObjHeader; | ||
108 | + byte[] nodeID = new byte[IPV6_ADDRESS_LENGTH]; | ||
109 | + fecObjHeader = PcepObjectHeader.read(cb); | ||
110 | + cb.readBytes(nodeID, 0, IPV6_ADDRESS_LENGTH); | ||
111 | + return new PcepFecObjectIPv6Ver1(fecObjHeader, nodeID); | ||
112 | + } | ||
113 | + | ||
114 | + @Override | ||
115 | + public int write(ChannelBuffer cb) throws PcepParseException { | ||
116 | + | ||
117 | + int objStartIndex = cb.writerIndex(); | ||
118 | + | ||
119 | + //write common header | ||
120 | + int objLenIndex = fecObjHeader.write(cb); | ||
121 | + cb.writeBytes(nodeID); | ||
122 | + | ||
123 | + //now write FEC IPv4 Object Length | ||
124 | + cb.setShort(objLenIndex, (short) (cb.writerIndex() - objStartIndex)); | ||
125 | + return cb.writerIndex(); | ||
126 | + } | ||
127 | + | ||
128 | + /** | ||
129 | + * Builder class for PCEP fec object IPv6. | ||
130 | + */ | ||
131 | + public static class Builder implements PcepFecObjectIPv6.Builder { | ||
132 | + private boolean bIsHeaderSet = false; | ||
133 | + private boolean bIsNodeIdset = false; | ||
134 | + | ||
135 | + private PcepObjectHeader fecObjHeader; | ||
136 | + private byte[] nodeID = new byte[IPV6_ADDRESS_LENGTH]; | ||
137 | + | ||
138 | + private boolean bIsPFlagSet = false; | ||
139 | + private boolean bPFlag; | ||
140 | + | ||
141 | + private boolean bIsIFlagSet = false; | ||
142 | + private boolean bIFlag; | ||
143 | + | ||
144 | + @Override | ||
145 | + public PcepFecObjectIPv6 build() throws PcepParseException { | ||
146 | + PcepObjectHeader fecObjHeader = this.bIsHeaderSet ? this.fecObjHeader : DEFAULT_FEC_OBJECT_HEADER; | ||
147 | + | ||
148 | + if (!this.bIsNodeIdset) { | ||
149 | + throw new PcepParseException(" NodeID not set while building PcepFecObjectIPv6 object."); | ||
150 | + } | ||
151 | + if (bIsPFlagSet) { | ||
152 | + fecObjHeader.setPFlag(bPFlag); | ||
153 | + } | ||
154 | + if (bIsIFlagSet) { | ||
155 | + fecObjHeader.setIFlag(bIFlag); | ||
156 | + } | ||
157 | + return new PcepFecObjectIPv6Ver1(fecObjHeader, this.nodeID); | ||
158 | + } | ||
159 | + | ||
160 | + @Override | ||
161 | + public Builder setPFlag(boolean value) { | ||
162 | + this.bPFlag = value; | ||
163 | + this.bIsPFlagSet = true; | ||
164 | + return this; | ||
165 | + } | ||
166 | + | ||
167 | + @Override | ||
168 | + public Builder setIFlag(boolean value) { | ||
169 | + this.bIFlag = value; | ||
170 | + this.bIsIFlagSet = true; | ||
171 | + return this; | ||
172 | + } | ||
173 | + | ||
174 | + @Override | ||
175 | + public PcepObjectHeader getFecIpv6ObjHeader() { | ||
176 | + return this.fecObjHeader; | ||
177 | + } | ||
178 | + | ||
179 | + @Override | ||
180 | + public Builder setFecIpv6ObjHeader(PcepObjectHeader obj) { | ||
181 | + this.fecObjHeader = obj; | ||
182 | + this.bIsHeaderSet = true; | ||
183 | + return this; | ||
184 | + } | ||
185 | + | ||
186 | + @Override | ||
187 | + public byte[] getNodeID() { | ||
188 | + return this.nodeID; | ||
189 | + } | ||
190 | + | ||
191 | + @Override | ||
192 | + public Builder setNodeID(byte[] value) { | ||
193 | + this.nodeID = value; | ||
194 | + this.bIsNodeIdset = true; | ||
195 | + return this; | ||
196 | + } | ||
197 | + | ||
198 | + } | ||
199 | + | ||
200 | + @Override | ||
201 | + public PcepVersion getVersion() { | ||
202 | + return PcepVersion.PCEP_1; | ||
203 | + } | ||
204 | + | ||
205 | + @Override | ||
206 | + public int getType() { | ||
207 | + return FEC_OBJ_TYPE; | ||
208 | + } | ||
209 | + | ||
210 | + @Override | ||
211 | + public String toString() { | ||
212 | + return MoreObjects.toStringHelper(getClass()).add("fecObjHeader", fecObjHeader).add("NodeID: ", nodeID) | ||
213 | + .toString(); | ||
214 | + } | ||
215 | +} |
This diff is collapsed. Click to expand it.
pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepLabelUpdateMsgVer1.java
0 → 100644
1 | +/* | ||
2 | + * Copyright 2015 Open Networking Laboratory | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | + | ||
17 | +package org.onosproject.pcepio.protocol.ver1; | ||
18 | + | ||
19 | +import java.util.LinkedList; | ||
20 | +import java.util.ListIterator; | ||
21 | + | ||
22 | +import org.jboss.netty.buffer.ChannelBuffer; | ||
23 | +import org.onosproject.pcepio.exceptions.PcepParseException; | ||
24 | +import org.onosproject.pcepio.protocol.PcepLabelUpdate; | ||
25 | +import org.onosproject.pcepio.protocol.PcepLabelUpdateMsg; | ||
26 | +import org.onosproject.pcepio.protocol.PcepMessageReader; | ||
27 | +import org.onosproject.pcepio.protocol.PcepMessageWriter; | ||
28 | +import org.onosproject.pcepio.protocol.PcepType; | ||
29 | +import org.onosproject.pcepio.protocol.PcepVersion; | ||
30 | +import org.slf4j.Logger; | ||
31 | +import org.slf4j.LoggerFactory; | ||
32 | + | ||
33 | +import com.google.common.base.MoreObjects; | ||
34 | + | ||
35 | +class PcepLabelUpdateMsgVer1 implements PcepLabelUpdateMsg { | ||
36 | + | ||
37 | + // Pcep version: 1 | ||
38 | + | ||
39 | + /* | ||
40 | + The format of the PCLabelUpd message: | ||
41 | + | ||
42 | + <PCLabelUpd Message> ::= <Common Header> | ||
43 | + <pce-label-update-list> | ||
44 | + Where: | ||
45 | + | ||
46 | + <pce-label-update-list> ::= <pce-label-update> | ||
47 | + [<pce-label-update-list>] | ||
48 | + <pce-label-update> ::= (<pce-label-download>|<pce-label-map>) | ||
49 | + | ||
50 | + Where: | ||
51 | + <pce-label-download> ::= <SRP> | ||
52 | + <LSP> | ||
53 | + <label-list> | ||
54 | + | ||
55 | + <pce-label-map> ::= <SRP> | ||
56 | + <LABEL> | ||
57 | + <FEC> | ||
58 | + | ||
59 | + <label-list > ::= <LABEL> | ||
60 | + [<label-list>] | ||
61 | + | ||
62 | + */ | ||
63 | + protected static final Logger log = LoggerFactory.getLogger(PcepLabelUpdateMsgVer1.class); | ||
64 | + | ||
65 | + public static final byte PACKET_VERSION = 1; | ||
66 | + | ||
67 | + //LabelUpdateMsgMinLength = COMMON-HEADER(4)+SrpObjMinLentgh(12)+LabelObjectMinLength(12)+FECType1Object(8) | ||
68 | + public static final int PACKET_MINIMUM_LENGTH = 36; | ||
69 | + public static final PcepType MSG_TYPE = PcepType.LABEL_UPDATE; | ||
70 | + //pce-label-update-list | ||
71 | + private LinkedList<PcepLabelUpdate> llPcLabelUpdateList; | ||
72 | + | ||
73 | + static final PcepLabelUpdateMsgVer1.Reader READER = new Reader(); | ||
74 | + | ||
75 | + //Reader reads LabelUpdate Message from the channel. | ||
76 | + static class Reader implements PcepMessageReader<PcepLabelUpdateMsg> { | ||
77 | + | ||
78 | + @Override | ||
79 | + public PcepLabelUpdateMsg readFrom(ChannelBuffer cb) throws PcepParseException { | ||
80 | + | ||
81 | + if (cb.readableBytes() < PACKET_MINIMUM_LENGTH) { | ||
82 | + throw new PcepParseException("Readable bytes are less than Packet minimum length."); | ||
83 | + } | ||
84 | + | ||
85 | + // fixed value property version == 1 | ||
86 | + byte version = cb.readByte(); | ||
87 | + version = (byte) (version >> PcepMessageVer1.SHIFT_FLAG); | ||
88 | + if (version != PACKET_VERSION) { | ||
89 | + throw new PcepParseException("Wrong version.Expected=PcepVersion.PCEP_1(1), got=" + version); | ||
90 | + } | ||
91 | + // fixed value property type == 13 | ||
92 | + byte type = cb.readByte(); | ||
93 | + if (type != MSG_TYPE.getType()) { | ||
94 | + throw new PcepParseException("Wrong type. Expected=PcepType.LABEL_UPDATE(13), got=" + type); | ||
95 | + } | ||
96 | + short length = cb.readShort(); | ||
97 | + if (length < PACKET_MINIMUM_LENGTH) { | ||
98 | + throw new PcepParseException("Wrong length. Expected to be >= " + PACKET_MINIMUM_LENGTH + ", is: " | ||
99 | + + length); | ||
100 | + } | ||
101 | + // parse <pce-label-download> / <pce-label-map> | ||
102 | + LinkedList<PcepLabelUpdate> llPcLabelUpdateList = parsePcLabelUpdateList(cb); | ||
103 | + return new PcepLabelUpdateMsgVer1(llPcLabelUpdateList); | ||
104 | + } | ||
105 | + | ||
106 | + /** | ||
107 | + * Returns list of PCEP Label Update object. | ||
108 | + * | ||
109 | + * @param cb of type channel buffer | ||
110 | + * @return llPcLabelUpdateList list of PCEP label update object | ||
111 | + * @throws PcepParseException when fails to parse list of PCEP label update object | ||
112 | + */ | ||
113 | + public LinkedList<PcepLabelUpdate> parsePcLabelUpdateList(ChannelBuffer cb) throws PcepParseException { | ||
114 | + | ||
115 | + LinkedList<PcepLabelUpdate> llPcLabelUpdateList; | ||
116 | + llPcLabelUpdateList = new LinkedList<PcepLabelUpdate>(); | ||
117 | + | ||
118 | + while (0 < cb.readableBytes()) { | ||
119 | + llPcLabelUpdateList.add(PcepLabelUpdateVer1.read(cb)); | ||
120 | + } | ||
121 | + return llPcLabelUpdateList; | ||
122 | + } | ||
123 | + } | ||
124 | + | ||
125 | + /** | ||
126 | + * Constructor to initialize PCEP Label Update List. | ||
127 | + * | ||
128 | + * @param llPcLabelUpdateList list of PCEP Label Update object | ||
129 | + */ | ||
130 | + PcepLabelUpdateMsgVer1(LinkedList<PcepLabelUpdate> llPcLabelUpdateList) { | ||
131 | + this.llPcLabelUpdateList = llPcLabelUpdateList; | ||
132 | + } | ||
133 | + | ||
134 | + static class Builder implements PcepLabelUpdateMsg.Builder { | ||
135 | + | ||
136 | + LinkedList<PcepLabelUpdate> llPcLabelUpdateList; | ||
137 | + | ||
138 | + @Override | ||
139 | + public PcepVersion getVersion() { | ||
140 | + return PcepVersion.PCEP_1; | ||
141 | + } | ||
142 | + | ||
143 | + @Override | ||
144 | + public PcepType getType() { | ||
145 | + return PcepType.LABEL_UPDATE; | ||
146 | + } | ||
147 | + | ||
148 | + @Override | ||
149 | + public PcepLabelUpdateMsg build() { | ||
150 | + return new PcepLabelUpdateMsgVer1(this.llPcLabelUpdateList); | ||
151 | + } | ||
152 | + | ||
153 | + @Override | ||
154 | + public LinkedList<PcepLabelUpdate> getPcLabelUpdateList() { | ||
155 | + return this.llPcLabelUpdateList; | ||
156 | + } | ||
157 | + | ||
158 | + @Override | ||
159 | + public Builder setPcLabelUpdateList(LinkedList<PcepLabelUpdate> ll) { | ||
160 | + this.llPcLabelUpdateList = ll; | ||
161 | + return this; | ||
162 | + } | ||
163 | + } | ||
164 | + | ||
165 | + @Override | ||
166 | + public void writeTo(ChannelBuffer cb) throws PcepParseException { | ||
167 | + WRITER.write(cb, this); | ||
168 | + } | ||
169 | + | ||
170 | + static final Writer WRITER = new Writer(); | ||
171 | + | ||
172 | + //Writer writes LabelUpdate Message to the channel. | ||
173 | + static class Writer implements PcepMessageWriter<PcepLabelUpdateMsgVer1> { | ||
174 | + | ||
175 | + @Override | ||
176 | + public void write(ChannelBuffer cb, PcepLabelUpdateMsgVer1 message) throws PcepParseException { | ||
177 | + | ||
178 | + int startIndex = cb.writerIndex(); | ||
179 | + | ||
180 | + // first 3 bits set to version | ||
181 | + cb.writeByte((byte) (PACKET_VERSION << PcepMessageVer1.SHIFT_FLAG)); | ||
182 | + | ||
183 | + // message type | ||
184 | + cb.writeByte(MSG_TYPE.getType()); | ||
185 | + | ||
186 | + // Length will be set after calculating length, but currently set it as 0. | ||
187 | + int msgLenIndex = cb.writerIndex(); | ||
188 | + | ||
189 | + cb.writeShort((short) 0); | ||
190 | + ListIterator<PcepLabelUpdate> listIterator = message.llPcLabelUpdateList.listIterator(); | ||
191 | + | ||
192 | + while (listIterator.hasNext()) { | ||
193 | + PcepLabelUpdate labelUpdate = listIterator.next(); | ||
194 | + labelUpdate.write(cb); | ||
195 | + } | ||
196 | + | ||
197 | + // update message length field | ||
198 | + int length = cb.writerIndex() - startIndex; | ||
199 | + cb.setShort(msgLenIndex, (short) length); | ||
200 | + } | ||
201 | + } | ||
202 | + | ||
203 | + @Override | ||
204 | + public PcepVersion getVersion() { | ||
205 | + return PcepVersion.PCEP_1; | ||
206 | + } | ||
207 | + | ||
208 | + @Override | ||
209 | + public PcepType getType() { | ||
210 | + return MSG_TYPE; | ||
211 | + } | ||
212 | + | ||
213 | + @Override | ||
214 | + public LinkedList<PcepLabelUpdate> getPcLabelUpdateList() { | ||
215 | + return this.llPcLabelUpdateList; | ||
216 | + } | ||
217 | + | ||
218 | + @Override | ||
219 | + public void setPcLabelUpdateList(LinkedList<PcepLabelUpdate> ll) { | ||
220 | + this.llPcLabelUpdateList = ll; | ||
221 | + } | ||
222 | + | ||
223 | + @Override | ||
224 | + public String toString() { | ||
225 | + return MoreObjects.toStringHelper(getClass()).add("PcLabelUpdateList", llPcLabelUpdateList).toString(); | ||
226 | + } | ||
227 | +} |
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 | + * NexthopIPv6addressTlv provides Ipv4 address of next hop. | ||
30 | + */ | ||
31 | +public class NexthopIPv4addressTlv implements PcepValueType { | ||
32 | + | ||
33 | + /* | ||
34 | + Reference :draft-zhao-pce-pcep-extension-for-pce-controller-01 | ||
35 | + | ||
36 | + 0 1 2 3 | ||
37 | + 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 | ||
38 | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
39 | + | Type=TBD | Length = 8 | | ||
40 | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
41 | + | nexthop IPv4 address | | ||
42 | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
43 | + | ||
44 | + NEXTHOP-IPV4-ADDRESS TLV | ||
45 | + | ||
46 | + */ | ||
47 | + protected static final Logger log = LoggerFactory.getLogger(NexthopIPv4addressTlv.class); | ||
48 | + | ||
49 | + public static final short TYPE = 2; //to be defined | ||
50 | + //Length is header + value | ||
51 | + public static final short LENGTH = 8; | ||
52 | + public static final short VALUE_LENGTH = 4; | ||
53 | + | ||
54 | + private final int rawValue; | ||
55 | + | ||
56 | + /** | ||
57 | + * Constructor to initialize next hop IPv4 address. | ||
58 | + * | ||
59 | + * @param rawValue next hop IPv4 address | ||
60 | + */ | ||
61 | + public NexthopIPv4addressTlv(int rawValue) { | ||
62 | + this.rawValue = rawValue; | ||
63 | + } | ||
64 | + | ||
65 | + /** | ||
66 | + * Return next hop IPv4 address tlv. | ||
67 | + * | ||
68 | + * @param raw of next hop IPv4 address | ||
69 | + * @return object of NexthopIPv4addressTlv | ||
70 | + */ | ||
71 | + public static NexthopIPv4addressTlv of(final int raw) { | ||
72 | + return new NexthopIPv4addressTlv(raw); | ||
73 | + } | ||
74 | + | ||
75 | + /** | ||
76 | + * Returns next hop IPv4 address. | ||
77 | + * | ||
78 | + * @return next hop IPv4 address | ||
79 | + */ | ||
80 | + public int getInt() { | ||
81 | + return rawValue; | ||
82 | + } | ||
83 | + | ||
84 | + @Override | ||
85 | + public PcepVersion getVersion() { | ||
86 | + return PcepVersion.PCEP_1; | ||
87 | + } | ||
88 | + | ||
89 | + @Override | ||
90 | + public short getType() { | ||
91 | + return TYPE; | ||
92 | + } | ||
93 | + | ||
94 | + @Override | ||
95 | + public short getLength() { | ||
96 | + return LENGTH; | ||
97 | + } | ||
98 | + | ||
99 | + @Override | ||
100 | + public int hashCode() { | ||
101 | + return Objects.hash(rawValue); | ||
102 | + } | ||
103 | + | ||
104 | + @Override | ||
105 | + public boolean equals(Object obj) { | ||
106 | + if (this == obj) { | ||
107 | + return true; | ||
108 | + } | ||
109 | + if (obj instanceof NexthopIPv4addressTlv) { | ||
110 | + NexthopIPv4addressTlv other = (NexthopIPv4addressTlv) obj; | ||
111 | + return Objects.equals(this.rawValue, other.rawValue); | ||
112 | + } | ||
113 | + return false; | ||
114 | + } | ||
115 | + | ||
116 | + @Override | ||
117 | + public int write(ChannelBuffer c) { | ||
118 | + int iStartIndex = c.writerIndex(); | ||
119 | + c.writeShort(TYPE); | ||
120 | + c.writeShort(LENGTH); | ||
121 | + c.writeInt(rawValue); | ||
122 | + return c.writerIndex() - iStartIndex; | ||
123 | + } | ||
124 | + | ||
125 | + /** | ||
126 | + * Reads the channel buffer and returns object of NexthopIPv4addressTlv. | ||
127 | + * | ||
128 | + * @param c type of channel buffer | ||
129 | + * @return object of NexthopIPv4addressTlv | ||
130 | + */ | ||
131 | + public static NexthopIPv4addressTlv read(ChannelBuffer c) { | ||
132 | + return NexthopIPv4addressTlv.of(c.readInt()); | ||
133 | + } | ||
134 | + | ||
135 | + @Override | ||
136 | + public String toString() { | ||
137 | + return MoreObjects.toStringHelper(getClass()) | ||
138 | + .add("Type", TYPE) | ||
139 | + .add("Length", LENGTH) | ||
140 | + .add("Ipv4Address ", rawValue) | ||
141 | + .toString(); | ||
142 | + } | ||
143 | +} |
1 | +/* | ||
2 | + * Copyright 2015 Open Networking Laboratory | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | + | ||
17 | +package org.onosproject.pcepio.types; | ||
18 | + | ||
19 | +import java.util.Objects; | ||
20 | + | ||
21 | +import org.jboss.netty.buffer.ChannelBuffer; | ||
22 | +import org.onosproject.pcepio.protocol.PcepVersion; | ||
23 | +import org.slf4j.Logger; | ||
24 | +import org.slf4j.LoggerFactory; | ||
25 | + | ||
26 | +import com.google.common.base.MoreObjects; | ||
27 | +import com.google.common.base.MoreObjects.ToStringHelper; | ||
28 | + | ||
29 | +/** | ||
30 | + * NexthopIPv6addressTlv provides Ipv6 address of next hop. | ||
31 | + */ | ||
32 | +public class NexthopIPv6addressTlv implements PcepValueType { | ||
33 | + | ||
34 | + /* | ||
35 | + Reference: draft-zhao-pce-pcep-extension-for-pce-controller-01. | ||
36 | + | ||
37 | + 0 1 2 3 | ||
38 | + 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 | ||
39 | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
40 | + | Type=TBD | Length = 20 | | ||
41 | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
42 | + | | | ||
43 | + // nexthop IPv6 address (16 bytes) // | ||
44 | + | | | ||
45 | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
46 | + | ||
47 | + NEXTHOP-IPV6-ADDRESS TLV: | ||
48 | + | ||
49 | + */ | ||
50 | + protected static final Logger log = LoggerFactory.getLogger(NexthopIPv6addressTlv.class); | ||
51 | + | ||
52 | + public static final short TYPE = 100; //to be defined | ||
53 | + //Length is header + value | ||
54 | + public static final short LENGTH = 20; | ||
55 | + public static final short VALUE_LENGTH = 16; | ||
56 | + | ||
57 | + private static final byte[] NONE_VAL = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; | ||
58 | + public static final NexthopIPv6addressTlv NONE = new NexthopIPv6addressTlv(NONE_VAL); | ||
59 | + | ||
60 | + private static final byte[] NO_MASK_VAL = {(byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, | ||
61 | + (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, | ||
62 | + (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF }; | ||
63 | + public static final NexthopIPv6addressTlv NO_MASK = new NexthopIPv6addressTlv(NO_MASK_VAL); | ||
64 | + public static final NexthopIPv6addressTlv FULL_MASK = NONE; | ||
65 | + | ||
66 | + private final byte[] rawValue; | ||
67 | + | ||
68 | + /** | ||
69 | + * Constructor to initialize IP address for next hop IPv6 address tlv. | ||
70 | + * | ||
71 | + * @param rawValue value of Next hop ipAddress | ||
72 | + */ | ||
73 | + public NexthopIPv6addressTlv(byte[] rawValue) { | ||
74 | + log.debug("NexthopIPv6addressTlv"); | ||
75 | + this.rawValue = rawValue; | ||
76 | + } | ||
77 | + | ||
78 | + /** | ||
79 | + * Creates next hop IPv6 address tlv. | ||
80 | + * | ||
81 | + * @param raw value of Next hop ipAddress | ||
82 | + * @return object of NexthopIPv6addressTlv | ||
83 | + */ | ||
84 | + //logic to be checked | ||
85 | + public static NexthopIPv6addressTlv of(final byte[] raw) { | ||
86 | + //check NONE_VAL | ||
87 | + boolean bFoundNONE = true; | ||
88 | + //value starts from 3rd byte. | ||
89 | + for (int i = 5; i < 20; ++i) { | ||
90 | + if (NONE_VAL[i] != raw[i]) { | ||
91 | + bFoundNONE = false; | ||
92 | + } | ||
93 | + } | ||
94 | + | ||
95 | + if (bFoundNONE) { | ||
96 | + return NONE; | ||
97 | + } | ||
98 | + | ||
99 | + //check NO_MASK_VAL | ||
100 | + boolean bFoundNoMask = true; | ||
101 | + //value starts from 3rd byte. | ||
102 | + for (int i = 5; i < 20; ++i) { | ||
103 | + if (0xFF != raw[i]) { | ||
104 | + bFoundNoMask = false; | ||
105 | + } | ||
106 | + } | ||
107 | + if (bFoundNoMask) { | ||
108 | + return NO_MASK; | ||
109 | + } | ||
110 | + return new NexthopIPv6addressTlv(raw); | ||
111 | + } | ||
112 | + | ||
113 | + /** | ||
114 | + * Returns next hop IPv6 address. | ||
115 | + * | ||
116 | + * @return next hop IPv6 address | ||
117 | + */ | ||
118 | + public byte[] getBytes() { | ||
119 | + return rawValue; | ||
120 | + } | ||
121 | + | ||
122 | + @Override | ||
123 | + public PcepVersion getVersion() { | ||
124 | + return PcepVersion.PCEP_1; | ||
125 | + } | ||
126 | + | ||
127 | + @Override | ||
128 | + public short getType() { | ||
129 | + return TYPE; | ||
130 | + } | ||
131 | + | ||
132 | + @Override | ||
133 | + public short getLength() { | ||
134 | + return LENGTH; | ||
135 | + } | ||
136 | + | ||
137 | + @Override | ||
138 | + public int hashCode() { | ||
139 | + return Objects.hash(rawValue); | ||
140 | + } | ||
141 | + | ||
142 | + @Override | ||
143 | + public boolean equals(Object obj) { | ||
144 | + if (this == obj) { | ||
145 | + return true; | ||
146 | + } | ||
147 | + if (obj instanceof NexthopIPv6addressTlv) { | ||
148 | + NexthopIPv6addressTlv other = (NexthopIPv6addressTlv) obj; | ||
149 | + return Objects.equals(this.rawValue, other.rawValue); | ||
150 | + } | ||
151 | + return false; | ||
152 | + } | ||
153 | + | ||
154 | + @Override | ||
155 | + public int write(ChannelBuffer c) { | ||
156 | + int iStartIndex = c.writerIndex(); | ||
157 | + c.writeShort(TYPE); | ||
158 | + c.writeShort(LENGTH); | ||
159 | + c.writeBytes(rawValue); | ||
160 | + return c.writerIndex() - iStartIndex; | ||
161 | + } | ||
162 | + | ||
163 | + /** | ||
164 | + * Reads the channel buffer and returns object of NexthopIPv6addressTlv. | ||
165 | + * | ||
166 | + * @param c type of channel buffer | ||
167 | + * @return object of NexthopIPv6addressTlv | ||
168 | + */ | ||
169 | + public static NexthopIPv6addressTlv read(ChannelBuffer c) { | ||
170 | + byte[] yTemp = new byte[20]; | ||
171 | + c.readBytes(yTemp, 0, 20); | ||
172 | + return NexthopIPv6addressTlv.of(yTemp); | ||
173 | + } | ||
174 | + | ||
175 | + @Override | ||
176 | + public String toString() { | ||
177 | + ToStringHelper toStrHelper = MoreObjects.toStringHelper(getClass()); | ||
178 | + | ||
179 | + toStrHelper.add("Type", TYPE); | ||
180 | + toStrHelper.add("Length", LENGTH); | ||
181 | + | ||
182 | + StringBuffer result = new StringBuffer(); | ||
183 | + for (byte b : rawValue) { | ||
184 | + result.append(String.format("%02X ", b)); | ||
185 | + } | ||
186 | + toStrHelper.add("IpAddress", result); | ||
187 | + | ||
188 | + return toStrHelper.toString(); | ||
189 | + } | ||
190 | +} |
1 | +/* | ||
2 | + * Copyright 2015 Open Networking Laboratory | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | + | ||
17 | +package org.onosproject.pcepio.types; | ||
18 | + | ||
19 | +import java.util.Objects; | ||
20 | + | ||
21 | +import org.jboss.netty.buffer.ChannelBuffer; | ||
22 | +import org.onosproject.pcepio.protocol.PcepVersion; | ||
23 | +import org.slf4j.Logger; | ||
24 | +import org.slf4j.LoggerFactory; | ||
25 | + | ||
26 | +import com.google.common.base.MoreObjects; | ||
27 | + | ||
28 | +/** | ||
29 | + * NexthopUnnumberedIPv4IDTlv provides the next node's ID and Interface ID. | ||
30 | + */ | ||
31 | +public class NexthopUnnumberedIPv4IDTlv implements PcepValueType { | ||
32 | + | ||
33 | + /* | ||
34 | + Reference : draft-zhao-pce-pcep-extension-for-pce-controller-01. | ||
35 | + | ||
36 | + 0 1 2 3 | ||
37 | + 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 | ||
38 | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
39 | + | Type=TBD | Length = 12 | | ||
40 | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
41 | + | Node-ID | | ||
42 | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
43 | + | Interface ID | | ||
44 | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
45 | + | ||
46 | + NEXTHOP-UNNUMBERED-IPV4-ID TLV | ||
47 | + | ||
48 | + */ | ||
49 | + protected static final Logger log = LoggerFactory.getLogger(NexthopUnnumberedIPv4IDTlv.class); | ||
50 | + | ||
51 | + public static final short TYPE = 1; //to be defined | ||
52 | + //Length is header + value | ||
53 | + public static final short LENGTH = 12; | ||
54 | + | ||
55 | + private final int nodeID; | ||
56 | + private final int interfaceID; | ||
57 | + | ||
58 | + /** | ||
59 | + * constructor to initialize nodeID and interfaceID. | ||
60 | + * | ||
61 | + * @param nodeID node ID | ||
62 | + * @param interfaceID interface ID | ||
63 | + */ | ||
64 | + public NexthopUnnumberedIPv4IDTlv(int nodeID, int interfaceID) { | ||
65 | + this.nodeID = nodeID; | ||
66 | + this.interfaceID = interfaceID; | ||
67 | + } | ||
68 | + | ||
69 | + /** | ||
70 | + * Returns new object of NexthopUnnumberedIPv4IDTlv. | ||
71 | + * | ||
72 | + * @param nodeID node ID | ||
73 | + * @param interfaceID interface ID | ||
74 | + * @return NexthopUnnumberedIPv4IDTlv | ||
75 | + */ | ||
76 | + public static NexthopUnnumberedIPv4IDTlv of(int nodeID, int interfaceID) { | ||
77 | + return new NexthopUnnumberedIPv4IDTlv(nodeID, interfaceID); | ||
78 | + } | ||
79 | + | ||
80 | + /** | ||
81 | + * Returns Node Id. | ||
82 | + * | ||
83 | + * @return node ID | ||
84 | + */ | ||
85 | + public int getNodeID() { | ||
86 | + return nodeID; | ||
87 | + } | ||
88 | + | ||
89 | + /** | ||
90 | + * Returns Interface Id. | ||
91 | + * | ||
92 | + * @return interface ID | ||
93 | + */ | ||
94 | + public int getInterfaceID() { | ||
95 | + return interfaceID; | ||
96 | + } | ||
97 | + | ||
98 | + @Override | ||
99 | + public PcepVersion getVersion() { | ||
100 | + return PcepVersion.PCEP_1; | ||
101 | + } | ||
102 | + | ||
103 | + @Override | ||
104 | + public short getType() { | ||
105 | + return TYPE; | ||
106 | + } | ||
107 | + | ||
108 | + @Override | ||
109 | + public short getLength() { | ||
110 | + return LENGTH; | ||
111 | + } | ||
112 | + | ||
113 | + @Override | ||
114 | + public int hashCode() { | ||
115 | + return Objects.hash(nodeID, interfaceID); | ||
116 | + } | ||
117 | + | ||
118 | + @Override | ||
119 | + public boolean equals(Object obj) { | ||
120 | + if (this == obj) { | ||
121 | + return true; | ||
122 | + } | ||
123 | + if (obj instanceof NexthopUnnumberedIPv4IDTlv) { | ||
124 | + NexthopUnnumberedIPv4IDTlv other = (NexthopUnnumberedIPv4IDTlv) obj; | ||
125 | + return Objects.equals(this.nodeID, other.nodeID) && Objects.equals(this.interfaceID, other.interfaceID); | ||
126 | + } | ||
127 | + return false; | ||
128 | + } | ||
129 | + | ||
130 | + @Override | ||
131 | + public int write(ChannelBuffer c) { | ||
132 | + int iLenStartIndex = c.writerIndex(); | ||
133 | + c.writeShort(TYPE); | ||
134 | + c.writeShort(LENGTH); | ||
135 | + | ||
136 | + c.writeInt(nodeID); | ||
137 | + c.writeInt(interfaceID); | ||
138 | + | ||
139 | + return c.writerIndex() - iLenStartIndex; | ||
140 | + } | ||
141 | + | ||
142 | + /** | ||
143 | + * Reads the channel buffer and returns object of NexthopUnnumberedIPv4IDTlv. | ||
144 | + * | ||
145 | + * @param cb type of channel buffer | ||
146 | + * @return object of NexthopUnnumberedIPv4IDTlv | ||
147 | + */ | ||
148 | + public static NexthopUnnumberedIPv4IDTlv read(ChannelBuffer cb) { | ||
149 | + int nodeID = cb.readInt(); | ||
150 | + int interfaceID = cb.readInt(); | ||
151 | + return new NexthopUnnumberedIPv4IDTlv(nodeID, interfaceID); | ||
152 | + } | ||
153 | + | ||
154 | + @Override | ||
155 | + public String toString() { | ||
156 | + return MoreObjects.toStringHelper(getClass()).add("Type", TYPE).add("Length", LENGTH).add("NodeId", nodeID) | ||
157 | + .add("InterfaceId", interfaceID).toString(); | ||
158 | + } | ||
159 | +} |
-
Please register or login to post a comment