Committed by
Gerrit Code Review
[onos-2603] - Implement LinkState attributes
Change-Id: I78192ba9e0ec930417ef4a0e71531dcfd9c6d3e5
Showing
1 changed file
with
308 additions
and
0 deletions
1 | +/* | ||
2 | + * Copyright 2015 Open Networking Laboratory | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | +package org.onosproject.bgpio.types; | ||
17 | + | ||
18 | +import java.util.LinkedList; | ||
19 | +import java.util.List; | ||
20 | + | ||
21 | +import org.jboss.netty.buffer.ChannelBuffer; | ||
22 | +import org.onosproject.bgpio.exceptions.BGPParseException; | ||
23 | +import org.onosproject.bgpio.types.attr.BgpAttrNodeFlagBitTlv; | ||
24 | +import org.onosproject.bgpio.types.attr.BgpAttrNodeIsIsAreaId; | ||
25 | +import org.onosproject.bgpio.types.attr.BgpAttrNodeMultiTopologyId; | ||
26 | +import org.onosproject.bgpio.types.attr.BgpAttrNodeName; | ||
27 | +import org.onosproject.bgpio.types.attr.BgpAttrOpaqueNode; | ||
28 | +import org.onosproject.bgpio.types.attr.BgpAttrRouterIdV4; | ||
29 | +import org.onosproject.bgpio.types.attr.BgpAttrRouterIdV6; | ||
30 | +import org.onosproject.bgpio.types.attr.BgpLinkAttrIgpMetric; | ||
31 | +import org.onosproject.bgpio.types.attr.BgpLinkAttrIsIsAdminstGrp; | ||
32 | +import org.onosproject.bgpio.types.attr.BgpLinkAttrMplsProtocolMask; | ||
33 | +import org.onosproject.bgpio.types.attr.BgpLinkAttrMaxLinkBandwidth; | ||
34 | +import org.onosproject.bgpio.types.attr.BgpLinkAttrName; | ||
35 | +import org.onosproject.bgpio.types.attr.BgpLinkAttrOpaqLnkAttrib; | ||
36 | +import org.onosproject.bgpio.types.attr.BgpLinkAttrProtectionType; | ||
37 | +import org.onosproject.bgpio.types.attr.BgpLinkAttrSrlg; | ||
38 | +import org.onosproject.bgpio.types.attr.BgpLinkAttrTeDefaultMetric; | ||
39 | +import org.onosproject.bgpio.types.attr.BgpLinkAttrUnRsrvdLinkBandwidth; | ||
40 | +import org.onosproject.bgpio.types.attr.BgpPrefixAttrExtRouteTag; | ||
41 | +import org.onosproject.bgpio.types.attr.BgpPrefixAttrIgpFlags; | ||
42 | +import org.onosproject.bgpio.types.attr.BgpPrefixAttrMetric; | ||
43 | +import org.onosproject.bgpio.types.attr.BgpPrefixAttrOspfFwdAddr; | ||
44 | +import org.onosproject.bgpio.types.attr.BgpPrefixAttrOpaqueData; | ||
45 | +import org.onosproject.bgpio.types.attr.BgpPrefixAttrRouteTag; | ||
46 | +import org.onosproject.bgpio.util.Validation; | ||
47 | +import org.slf4j.Logger; | ||
48 | +import org.slf4j.LoggerFactory; | ||
49 | + | ||
50 | +import com.google.common.base.MoreObjects; | ||
51 | + | ||
52 | +/** | ||
53 | + * Implements BGP Link state attribute. | ||
54 | + */ | ||
55 | +public class LinkStateAttributes implements BGPValueType { | ||
56 | + | ||
57 | + protected static final Logger log = LoggerFactory | ||
58 | + .getLogger(LinkStateAttributes.class); | ||
59 | + | ||
60 | + /* Node Attributes */ | ||
61 | + public static final short ATTR_NODE_MT_TOPOLOGY_ID = 263; | ||
62 | + public static final short ATTR_NODE_FLAG_BITS = 1024; | ||
63 | + public static final short ATTR_NODE_OPAQUE_NODE = 1025; | ||
64 | + public static final short ATTR_NODE_NAME = 1026; | ||
65 | + public static final short ATTR_NODE_ISIS_AREA_ID = 1027; | ||
66 | + public static final short ATTR_NODE_IPV4_LOCAL_ROUTER_ID = 1028; | ||
67 | + public static final short ATTR_NODE_IPV6_LOCAL_ROUTER_ID = 1029; | ||
68 | + | ||
69 | + /* Link Attributes */ | ||
70 | + public static final short ATTR_LINK_IPV4_REMOTE_ROUTER_ID = 1030; | ||
71 | + public static final short ATTR_LINK_IPV6_REMOTE_ROUTER_ID = 1031; | ||
72 | + public static final short ATTR_LINK_ADMINISTRATIVE_GRPS = 1088; | ||
73 | + public static final short ATTR_LINK_MAX_BANDWIDTH = 1089; | ||
74 | + public static final short ATTR_LINK_MAX_RES_BANDWIDTH = 1090; | ||
75 | + public static final short ATTR_LINK_UNRES_BANDWIDTH = 1091; | ||
76 | + public static final short ATTR_LINK_TE_DEFAULT_METRIC = 1092; | ||
77 | + public static final short ATTR_LINK_PROTECTION_TYPE = 1093; | ||
78 | + public static final short ATTR_LINK_MPLS_PROTOCOL_MASK = 1094; | ||
79 | + public static final short ATTR_LINK_IGP_METRIC = 1095; | ||
80 | + public static final short ATTR_LINK_SHR_RISK_GRP = 1096; | ||
81 | + public static final short ATTR_LINK_OPAQUE_ATTR = 1097; | ||
82 | + public static final short ATTR_LINK_NAME_ATTR = 1098; | ||
83 | + | ||
84 | + /* Prefix Attributes */ | ||
85 | + public static final short ATTR_PREFIX_IGP_FLAG = 1152; | ||
86 | + public static final short ATTR_PREFIX_ROUTE_TAG = 1153; | ||
87 | + public static final short ATTR_PREFIX_EXTENDED_TAG = 1154; | ||
88 | + public static final short ATTR_PREFIX_METRIC = 1155; | ||
89 | + public static final short ATTR_PREFIX_OSPF_FWD_ADDR = 1156; | ||
90 | + public static final short ATTR_PREFIX_OPAQUE_ATTR = 1157; | ||
91 | + | ||
92 | + public static final byte LINKSTATE_ATTRIB_TYPE = 50; | ||
93 | + public static final byte TYPE_AND_LEN = 4; | ||
94 | + private boolean isLinkStateAttribute = false; | ||
95 | + private List<BGPValueType> linkStateAttribList; | ||
96 | + | ||
97 | + /** | ||
98 | + * Constructor to reset parameters. | ||
99 | + */ | ||
100 | + LinkStateAttributes() { | ||
101 | + this.linkStateAttribList = null; | ||
102 | + } | ||
103 | + | ||
104 | + /** | ||
105 | + * Constructor to initialize parameters. | ||
106 | + * | ||
107 | + * @param linkStateAttribList Linked list of Link, Node and Prefix TLVs | ||
108 | + */ | ||
109 | + LinkStateAttributes(List<BGPValueType> linkStateAttribList) { | ||
110 | + this.linkStateAttribList = linkStateAttribList; | ||
111 | + this.isLinkStateAttribute = true; | ||
112 | + } | ||
113 | + | ||
114 | + /** | ||
115 | + * Returns linked list of Link, Node and Prefix TLVs. | ||
116 | + * | ||
117 | + * @return linked list of Link, Node and Prefix TLVs | ||
118 | + */ | ||
119 | + public List<BGPValueType> linkStateAttributes() { | ||
120 | + return this.linkStateAttribList; | ||
121 | + } | ||
122 | + | ||
123 | + /** | ||
124 | + * Returns if the Link state attributes are set or not. | ||
125 | + * | ||
126 | + * @return a boolean value to to check if the LS attributes are set or not | ||
127 | + */ | ||
128 | + public boolean isLinkStateAttributeSet() { | ||
129 | + return this.isLinkStateAttribute; | ||
130 | + } | ||
131 | + | ||
132 | + /** | ||
133 | + * Reads the Link state attribute TLVs. | ||
134 | + * | ||
135 | + * @param cb ChannelBuffer | ||
136 | + * @return constructor of LinkStateAttributes | ||
137 | + * @throws BGPParseException while parsing link state attributes | ||
138 | + */ | ||
139 | + public static LinkStateAttributes read(ChannelBuffer cb) | ||
140 | + throws BGPParseException { | ||
141 | + | ||
142 | + ChannelBuffer tempBuf = cb; | ||
143 | + Validation parseFlags = Validation.parseAttributeHeader(cb); | ||
144 | + int len = parseFlags.isShort() ? parseFlags.getLength() + TYPE_AND_LEN | ||
145 | + : parseFlags.getLength() + 3; | ||
146 | + | ||
147 | + ChannelBuffer data = tempBuf.readBytes(len); | ||
148 | + if (!parseFlags.getFirstBit() || parseFlags.getSecondBit() | ||
149 | + || parseFlags.getThirdBit()) { | ||
150 | + throw new BGPParseException(BGPErrorType.UPDATE_MESSAGE_ERROR, | ||
151 | + BGPErrorType.ATTRIBUTE_FLAGS_ERROR, | ||
152 | + data); | ||
153 | + } | ||
154 | + | ||
155 | + if (cb.readableBytes() < parseFlags.getLength()) { | ||
156 | + Validation.validateLen(BGPErrorType.UPDATE_MESSAGE_ERROR, | ||
157 | + BGPErrorType.BAD_MESSAGE_LENGTH, | ||
158 | + parseFlags.getLength()); | ||
159 | + } | ||
160 | + | ||
161 | + BGPValueType bgpLSAttrib = null; | ||
162 | + LinkedList<BGPValueType> linkStateAttribList; | ||
163 | + linkStateAttribList = new LinkedList<BGPValueType>(); | ||
164 | + ChannelBuffer tempCb = cb.readBytes(parseFlags.getLength()); | ||
165 | + while (tempCb.readableBytes() > 0) { | ||
166 | + short tlvCodePoint = tempCb.readShort(); | ||
167 | + switch (tlvCodePoint) { | ||
168 | + | ||
169 | + /********* 7 NODE ATTRIBUTES ********/ | ||
170 | + case ATTR_NODE_MT_TOPOLOGY_ID: /* 263 Multi-Topology Identifier*/ | ||
171 | + bgpLSAttrib = BgpAttrNodeMultiTopologyId.read(tempCb); | ||
172 | + break; | ||
173 | + | ||
174 | + case ATTR_NODE_FLAG_BITS: /*Node flag bit TLV*/ | ||
175 | + bgpLSAttrib = BgpAttrNodeFlagBitTlv.read(tempCb); | ||
176 | + break; | ||
177 | + | ||
178 | + case ATTR_NODE_OPAQUE_NODE: /*Opaque Node Attribute*/ | ||
179 | + bgpLSAttrib = BgpAttrOpaqueNode.read(tempCb); | ||
180 | + break; | ||
181 | + | ||
182 | + case ATTR_NODE_NAME: /*Node Name*/ | ||
183 | + bgpLSAttrib = BgpAttrNodeName.read(tempCb); | ||
184 | + break; | ||
185 | + | ||
186 | + case ATTR_NODE_ISIS_AREA_ID: /*IS-IS Area Identifier TLV*/ | ||
187 | + bgpLSAttrib = BgpAttrNodeIsIsAreaId.read(tempCb); | ||
188 | + break; | ||
189 | + | ||
190 | + case ATTR_NODE_IPV4_LOCAL_ROUTER_ID: /*IPv4 Router-ID of Local Node*/ | ||
191 | + bgpLSAttrib = BgpAttrRouterIdV4.read(tempCb, (short) ATTR_NODE_IPV4_LOCAL_ROUTER_ID); | ||
192 | + break; | ||
193 | + | ||
194 | + case ATTR_NODE_IPV6_LOCAL_ROUTER_ID: /*IPv6 Router-ID of Local Node*/ | ||
195 | + bgpLSAttrib = BgpAttrRouterIdV6.read(tempCb, (short) ATTR_NODE_IPV6_LOCAL_ROUTER_ID); | ||
196 | + break; | ||
197 | + | ||
198 | + /********* 15 LINK ATTRIBUTES ********/ | ||
199 | + | ||
200 | + case ATTR_LINK_IPV4_REMOTE_ROUTER_ID: /*IPv4 Router-ID of Remote Node*/ | ||
201 | + bgpLSAttrib = BgpAttrRouterIdV4.read(tempCb, (short) 1030); | ||
202 | + break; | ||
203 | + | ||
204 | + case ATTR_LINK_IPV6_REMOTE_ROUTER_ID: /*IPv6 Router-ID of Remote Node*/ | ||
205 | + bgpLSAttrib = BgpAttrRouterIdV6.read(tempCb, (short) 1031); | ||
206 | + break; | ||
207 | + | ||
208 | + case ATTR_LINK_ADMINISTRATIVE_GRPS: /*ISIS Administrative group STLV 3*/ | ||
209 | + bgpLSAttrib = BgpLinkAttrIsIsAdminstGrp.read(tempCb); | ||
210 | + break; | ||
211 | + | ||
212 | + case ATTR_LINK_MAX_BANDWIDTH: /*Maximum link bandwidth*/ | ||
213 | + bgpLSAttrib = BgpLinkAttrMaxLinkBandwidth.read(tempCb, | ||
214 | + (short) 1089); | ||
215 | + break; | ||
216 | + | ||
217 | + case ATTR_LINK_MAX_RES_BANDWIDTH: /* Maximum Reservable link bandwidth */ | ||
218 | + bgpLSAttrib = BgpLinkAttrMaxLinkBandwidth.read(tempCb, | ||
219 | + (short) 1090); | ||
220 | + break; | ||
221 | + | ||
222 | + case ATTR_LINK_UNRES_BANDWIDTH: /* UnReserved link bandwidth */ | ||
223 | + bgpLSAttrib = BgpLinkAttrUnRsrvdLinkBandwidth | ||
224 | + .read(tempCb, (short) 1091); | ||
225 | + break; | ||
226 | + | ||
227 | + case ATTR_LINK_TE_DEFAULT_METRIC: /* TE Default Metric */ | ||
228 | + bgpLSAttrib = BgpLinkAttrTeDefaultMetric.read(tempCb); | ||
229 | + break; | ||
230 | + | ||
231 | + case ATTR_LINK_PROTECTION_TYPE:/* Link Protection type */ | ||
232 | + bgpLSAttrib = BgpLinkAttrProtectionType.read(tempCb); | ||
233 | + break; | ||
234 | + | ||
235 | + case ATTR_LINK_MPLS_PROTOCOL_MASK: /* MPLS Protocol Mask */ | ||
236 | + bgpLSAttrib = BgpLinkAttrMplsProtocolMask.read(tempCb); // 2 | ||
237 | + break; | ||
238 | + | ||
239 | + case ATTR_LINK_IGP_METRIC: /* IGP Metric */ | ||
240 | + bgpLSAttrib = BgpLinkAttrIgpMetric.read(tempCb); // 2 | ||
241 | + break; | ||
242 | + | ||
243 | + case ATTR_LINK_SHR_RISK_GRP: /* Shared Risk Link Group */ | ||
244 | + bgpLSAttrib = BgpLinkAttrSrlg.read(tempCb); // 3 | ||
245 | + break; | ||
246 | + | ||
247 | + case ATTR_LINK_OPAQUE_ATTR: /* Opaque link attribute */ | ||
248 | + bgpLSAttrib = BgpLinkAttrOpaqLnkAttrib.read(tempCb); | ||
249 | + break; | ||
250 | + | ||
251 | + case ATTR_LINK_NAME_ATTR: /* Link Name attribute */ | ||
252 | + bgpLSAttrib = BgpLinkAttrName.read(tempCb); | ||
253 | + break; | ||
254 | + | ||
255 | + /********* 6 PREFIX ATTRIBUTES ********/ | ||
256 | + | ||
257 | + case ATTR_PREFIX_IGP_FLAG: /* IGP Flags */ | ||
258 | + bgpLSAttrib = BgpPrefixAttrIgpFlags.read(tempCb); | ||
259 | + break; | ||
260 | + | ||
261 | + case ATTR_PREFIX_ROUTE_TAG: /* Route Tag */ | ||
262 | + bgpLSAttrib = BgpPrefixAttrRouteTag.read(tempCb); | ||
263 | + break; | ||
264 | + | ||
265 | + case ATTR_PREFIX_EXTENDED_TAG: /* Extended Tag */ | ||
266 | + bgpLSAttrib = BgpPrefixAttrExtRouteTag.read(tempCb); | ||
267 | + break; | ||
268 | + | ||
269 | + case ATTR_PREFIX_METRIC: /* Prefix Metric */ | ||
270 | + bgpLSAttrib = BgpPrefixAttrMetric.read(tempCb); | ||
271 | + break; | ||
272 | + | ||
273 | + case ATTR_PREFIX_OSPF_FWD_ADDR: /* OSPF Forwarding Address */ | ||
274 | + bgpLSAttrib = BgpPrefixAttrOspfFwdAddr.read(tempCb); | ||
275 | + break; | ||
276 | + | ||
277 | + case ATTR_PREFIX_OPAQUE_ATTR: /* Opaque Prefix Attribute */ | ||
278 | + bgpLSAttrib = BgpPrefixAttrOpaqueData.read(tempCb); | ||
279 | + break; | ||
280 | + | ||
281 | + default: | ||
282 | + throw new BGPParseException( | ||
283 | + "The BGP-LS Attribute is not supported : " | ||
284 | + + tlvCodePoint); | ||
285 | + } | ||
286 | + | ||
287 | + linkStateAttribList.add(bgpLSAttrib); | ||
288 | + } | ||
289 | + return new LinkStateAttributes(linkStateAttribList); | ||
290 | + } | ||
291 | + | ||
292 | + @Override | ||
293 | + public short getType() { | ||
294 | + return LINKSTATE_ATTRIB_TYPE; | ||
295 | + } | ||
296 | + | ||
297 | + @Override | ||
298 | + public int write(ChannelBuffer cb) { | ||
299 | + // TODO This will be implemented in the next version | ||
300 | + return 0; | ||
301 | + } | ||
302 | + | ||
303 | + @Override | ||
304 | + public String toString() { | ||
305 | + return MoreObjects.toStringHelper(getClass()).omitNullValues() | ||
306 | + .add("linkStateAttribList", linkStateAttribList).toString(); | ||
307 | + } | ||
308 | +} |
-
Please register or login to post a comment