2 * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.protocol.bgp.linkstate.impl.attribute;
10 import com.google.common.annotations.VisibleForTesting;
11 import com.google.common.collect.Multimap;
12 import io.netty.buffer.ByteBuf;
13 import io.netty.buffer.ByteBufUtil;
14 import io.netty.buffer.Unpooled;
15 import java.nio.charset.StandardCharsets;
16 import java.util.ArrayList;
17 import java.util.List;
19 import java.util.Map.Entry;
20 import org.opendaylight.protocol.bgp.linkstate.impl.attribute.sr.SrLinkAttributesParser;
21 import org.opendaylight.protocol.bgp.linkstate.spi.TlvUtil;
22 import org.opendaylight.protocol.util.BitArray;
23 import org.opendaylight.protocol.util.ByteArray;
24 import org.opendaylight.protocol.util.Ipv4Util;
25 import org.opendaylight.protocol.util.Ipv6Util;
26 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4AddressNoZone;
27 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6AddressNoZone;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.AdministrativeGroup;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.Delay;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.Ipv4RouterIdentifier;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.Ipv6RouterIdentifier;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.LinkProtectionType;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.Loss;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.MplsProtocolMask;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.ProtocolId;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.linkstate.attribute.LinkMinMaxDelay;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.linkstate.attribute.LinkMinMaxDelayBuilder;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.linkstate.attribute.PeerAdjSid;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.linkstate.attribute.PeerAdjSidBuilder;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.linkstate.attribute.PeerNodeSid;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.linkstate.attribute.PeerNodeSidBuilder;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.linkstate.attribute.PeerSetSids;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.linkstate.attribute.PeerSetSidsBuilder;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.linkstate.attribute.SrAdjIds;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.linkstate.attribute.SrLanAdjIds;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.linkstate.attribute.UnreservedBandwidth;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.linkstate.attribute.UnreservedBandwidthBuilder;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.linkstate.attribute.UnreservedBandwidthKey;
49 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.linkstate.path.attribute.LinkStateAttribute;
50 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.linkstate.path.attribute.link.state.attribute.LinkAttributesCase;
51 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.linkstate.path.attribute.link.state.attribute.LinkAttributesCaseBuilder;
52 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.linkstate.path.attribute.link.state.attribute.link.attributes._case.LinkAttributes;
53 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.linkstate.path.attribute.link.state.attribute.link.attributes._case.LinkAttributesBuilder;
54 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.concepts.rev131125.Bandwidth;
55 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.concepts.rev131125.Metric;
56 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.concepts.rev131125.TeMetric;
57 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.SrlgId;
58 import org.opendaylight.yangtools.yang.common.Uint32;
59 import org.opendaylight.yangtools.yang.common.Uint8;
60 import org.opendaylight.yangtools.yang.common.netty.ByteBufUtils;
61 import org.slf4j.Logger;
62 import org.slf4j.LoggerFactory;
65 public final class LinkAttributesParser {
66 public static final int SR_LAN_ADJ_ID = 1100;
68 private static final Logger LOG = LoggerFactory.getLogger(LinkAttributesParser.class);
69 private static final int UNRESERVED_BW_COUNT = 8;
71 private static final int BANDWIDTH_LENGTH = 4;
73 // MPLS protection mask bits
74 private static final int FLAGS_SIZE = 8;
76 private static final int LDP_BIT = 0;
77 private static final int RSVP_BIT = 1;
79 /* Link Attribute TLVs */
80 private static final int REMOTE_IPV4_ROUTER_ID = 1030;
81 private static final int REMOTE_IPV6_ROUTER_ID = 1031;
82 private static final int ADMIN_GROUP = 1088;
83 private static final int MAX_BANDWIDTH = 1089;
84 private static final int MAX_RESERVABLE_BANDWIDTH = 1090;
85 private static final int UNRESERVED_BANDWIDTH = 1091;
86 private static final int TE_METRIC = 1092;
87 private static final int LINK_PROTECTION_TYPE = 1093;
88 private static final int MPLS_PROTOCOL = 1094;
89 private static final int METRIC = 1095;
90 private static final int SHARED_RISK_LINK_GROUP = 1096;
91 private static final int LINK_OPAQUE = 1097;
92 private static final int LINK_NAME = 1098;
93 private static final int SR_ADJ_ID = 1099;
94 private static final int PEER_NODE_SID_CODE = 1101;
95 private static final int PEER_ADJ_SID_CODE = 1102;
96 private static final int PEER_SET_SID_CODE = 1103;
97 // Performance Metrics
98 private static final int LINK_DELAY = 1114;
99 private static final int LINK_MIN_MAX_DELAY = 1115;
100 private static final int DELAY_VARIATION = 1116;
101 private static final int LINK_LOSS = 1117;
102 private static final int RESIDUAL_BANDWIDTH = 1118;
103 private static final int AVAILABLE_BANDWIDTH = 1119;
104 private static final int UTILIZED_BANDWIDTH = 1120;
106 private LinkAttributesParser() {
111 private interface SerializerInterface {
112 void check(Object cont);
116 * Parse Link Attributes.
118 * @param attributes key is the tlv type and value is the value of the tlv
119 * @param protocolId to differentiate parsing methods
120 * @return {@link LinkStateAttribute}
122 static LinkStateAttribute parseLinkAttributes(final Multimap<Integer, ByteBuf> attributes,
123 final ProtocolId protocolId) {
124 final LinkAttributesBuilder builder = new LinkAttributesBuilder();
125 final List<SrAdjIds> srAdjIds = new ArrayList<>();
126 final List<SrLanAdjIds> srLanAdjIds = new ArrayList<>();
127 final List<PeerSetSids> peerSetSids = new ArrayList<>();
128 for (final Entry<Integer, ByteBuf> entry : attributes.entries()) {
129 LOG.trace("Link attribute TLV {}", entry.getKey());
130 final int key = entry.getKey();
131 final ByteBuf value = entry.getValue();
133 case TlvUtil.LOCAL_IPV4_ROUTER_ID:
134 builder.setLocalIpv4RouterId(new Ipv4RouterIdentifier(Ipv4Util.addressForByteBuf(value)));
135 LOG.debug("Parsed IPv4 Router-ID of local node: {}", builder.getLocalIpv4RouterId());
137 case TlvUtil.LOCAL_IPV6_ROUTER_ID:
138 builder.setLocalIpv6RouterId(new Ipv6RouterIdentifier(Ipv6Util.addressForByteBuf(value)));
139 LOG.debug("Parsed IPv6 Router-ID of local node: {}", builder.getLocalIpv6RouterId());
141 case REMOTE_IPV4_ROUTER_ID:
142 builder.setRemoteIpv4RouterId(new Ipv4RouterIdentifier(Ipv4Util.addressForByteBuf(value)));
143 LOG.debug("Parsed IPv4 Router-ID of remote node: {}", builder.getRemoteIpv4RouterId());
145 case REMOTE_IPV6_ROUTER_ID:
146 builder.setRemoteIpv6RouterId(new Ipv6RouterIdentifier(Ipv6Util.addressForByteBuf(value)));
147 LOG.debug("Parsed IPv6 Router-ID of remote node: {}", builder.getRemoteIpv6RouterId());
150 builder.setAdminGroup(new AdministrativeGroup(ByteBufUtils.readUint32(value)));
151 LOG.debug("Parsed Administrative Group {}", builder.getAdminGroup());
154 builder.setMaxLinkBandwidth(new Bandwidth(ByteArray.readAllBytes(value)));
155 LOG.debug("Parsed Max Bandwidth {}", builder.getMaxLinkBandwidth());
157 case MAX_RESERVABLE_BANDWIDTH:
158 builder.setMaxReservableBandwidth(new Bandwidth(ByteArray.readAllBytes(value)));
159 LOG.debug("Parsed Max Reservable Bandwidth {}", builder.getMaxReservableBandwidth());
161 case UNRESERVED_BANDWIDTH:
162 parseUnreservedBandwidth(value, builder);
165 builder.setTeMetric(new TeMetric(ByteBufUtils.readUint32(value)));
166 LOG.debug("Parsed Metric {}", builder.getTeMetric());
168 case LINK_PROTECTION_TYPE:
169 builder.setLinkProtection(LinkProtectionType.forValue(value.readShort()));
170 LOG.debug("Parsed Link Protection Type {}", builder.getLinkProtection());
173 final BitArray bits = BitArray.valueOf(value, FLAGS_SIZE);
174 builder.setMplsProtocol(new MplsProtocolMask(bits.get(LDP_BIT), bits.get(RSVP_BIT)));
175 LOG.debug("Parsed MPLS Protocols: {}", builder.getMplsProtocol());
178 // length can 3, 2 or 1
179 builder.setMetric(new Metric(Uint32.valueOf(ByteArray.bytesToLong(ByteArray.readAllBytes(value)))));
180 LOG.debug("Parsed Metric {}", builder.getMetric());
182 case SHARED_RISK_LINK_GROUP:
183 parseSrlg(value, builder);
186 LOG.debug("Parsed Opaque value : {}", ByteBufUtil.hexDump(value));
189 builder.setLinkName(new String(ByteArray.readAllBytes(value), StandardCharsets.US_ASCII));
190 LOG.debug("Parsed Link Name : {}", builder.getLinkName());
193 srAdjIds.add(SrLinkAttributesParser.parseAdjacencySegmentIdentifier(value, protocolId));
194 LOG.debug("Parsed Adjacency Segment Identifier :{}", srAdjIds.get(srAdjIds.size() - 1));
197 srLanAdjIds.add(SrLinkAttributesParser.parseLanAdjacencySegmentIdentifier(value, protocolId));
198 LOG.debug("Parsed Adjacency Segment Identifier :{}", srLanAdjIds.get(srLanAdjIds.size() - 1));
200 case PEER_NODE_SID_CODE:
201 builder.setPeerNodeSid(new PeerNodeSidBuilder(
202 SrLinkAttributesParser.parseEpeAdjacencySegmentIdentifier(value)).build());
203 LOG.debug("Parsed Peer Segment Identifier :{}", builder.getPeerNodeSid());
205 case PEER_ADJ_SID_CODE:
206 builder.setPeerAdjSid(new PeerAdjSidBuilder(
207 SrLinkAttributesParser.parseEpeAdjacencySegmentIdentifier(value)).build());
208 LOG.debug("Parsed Peer Segment Identifier :{}", builder.getPeerAdjSid());
210 case PEER_SET_SID_CODE:
211 peerSetSids.add(new PeerSetSidsBuilder(
212 SrLinkAttributesParser.parseEpeAdjacencySegmentIdentifier(value)).build());
213 LOG.debug("Parsed Peer Set Sid :{}", peerSetSids.get(peerSetSids.size() - 1));
215 // Performance Metrics
217 builder.setLinkDelay(new Delay(ByteBufUtils.readUint32(value)));
218 LOG.debug("Parsed Link Delay {}", builder.getLinkDelay());
220 case LINK_MIN_MAX_DELAY:
221 builder.setLinkMinMaxDelay(new LinkMinMaxDelayBuilder()
222 .setMinDelay(new Delay(ByteBufUtils.readUint32(value)))
223 .setMaxDelay(new Delay(ByteBufUtils.readUint32(value)))
225 LOG.debug("Parsed Link Min/Max Delay {}", builder.getLinkMinMaxDelay());
227 case DELAY_VARIATION:
228 builder.setDelayVariation(new Delay(ByteBufUtils.readUint32(value)));
229 LOG.debug("Parsed Delay Variation {}", builder.getDelayVariation());
232 builder.setLinkLoss(new Loss(ByteBufUtils.readUint32(value)));
233 LOG.debug("Parsed Link Loss {}", builder.getLinkLoss());
235 case RESIDUAL_BANDWIDTH:
236 builder.setResidualBandwidth(new Bandwidth(ByteArray.readAllBytes(value)));
237 LOG.debug("Parsed Residual Bandwidth {}", builder.getResidualBandwidth());
239 case AVAILABLE_BANDWIDTH:
240 builder.setAvailableBandwidth(new Bandwidth(ByteArray.readAllBytes(value)));
241 LOG.debug("Parsed Available Bandwidth {}", builder.getAvailableBandwidth());
243 case UTILIZED_BANDWIDTH:
244 builder.setUtilizedBandwidth(new Bandwidth(ByteArray.readAllBytes(value)));
245 LOG.debug("Parsed Utilized Bandwidth {}", builder.getUtilizedBandwidth());
248 LOG.warn("TLV {} is not a valid link attribute, ignoring it", key);
251 if (!srAdjIds.isEmpty()) {
252 builder.setSrAdjIds(srAdjIds);
254 if (!srLanAdjIds.isEmpty()) {
255 builder.setSrLanAdjIds(srLanAdjIds);
257 if (!peerSetSids.isEmpty()) {
258 builder.setPeerSetSids(peerSetSids);
260 LOG.trace("Finished parsing Link Attributes.");
261 return new LinkAttributesCaseBuilder().setLinkAttributes(builder.build()).build();
264 private static void parseUnreservedBandwidth(final ByteBuf value, final LinkAttributesBuilder builder) {
265 final List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.linkstate
266 .attribute.UnreservedBandwidth> unreservedBandwidth = new ArrayList<>(UNRESERVED_BW_COUNT);
267 for (int i = 0; i < UNRESERVED_BW_COUNT; i++) {
268 final ByteBuf v = value.readSlice(BANDWIDTH_LENGTH);
269 unreservedBandwidth.add(new UnreservedBandwidthBuilder().setBandwidth(
270 new Bandwidth(ByteArray.readAllBytes(v))).setPriority(Uint8.valueOf(i)).build());
272 builder.setUnreservedBandwidth(unreservedBandwidth);
273 LOG.debug("Parsed Unreserved Bandwidth {}", builder.getUnreservedBandwidth());
276 private static void parseSrlg(final ByteBuf value, final LinkAttributesBuilder builder) {
277 final List<SrlgId> sharedRiskLinkGroups = new ArrayList<>();
278 while (value.isReadable()) {
279 sharedRiskLinkGroups.add(new SrlgId(ByteBufUtils.readUint32(value)));
281 builder.setSharedRiskLinkGroups(sharedRiskLinkGroups);
282 LOG.debug("Parsed Shared Risk Link Groups {}", builder.getSharedRiskLinkGroups());
285 private static void ifPresentApply(final Object tlv, final SerializerInterface serializer) {
287 serializer.check(tlv);
292 static void serializeLinkAttributes(final LinkAttributesCase linkAttributesCase, final ByteBuf output) {
293 final LinkAttributes linkAttributes = linkAttributesCase.getLinkAttributes();
294 LOG.trace("Started serializing Link Attributes");
295 ifPresentApply(linkAttributes.getLocalIpv4RouterId(), value -> TlvUtil.writeTLV(TlvUtil.LOCAL_IPV4_ROUTER_ID,
296 Ipv4Util.byteBufForAddress((Ipv4AddressNoZone) value), output));
297 ifPresentApply(linkAttributes.getLocalIpv6RouterId(), value -> TlvUtil.writeTLV(TlvUtil.LOCAL_IPV6_ROUTER_ID,
298 Ipv6Util.byteBufForAddress((Ipv6AddressNoZone) value), output));
299 ifPresentApply(linkAttributes.getRemoteIpv4RouterId(), value -> TlvUtil.writeTLV(REMOTE_IPV4_ROUTER_ID,
300 Ipv4Util.byteBufForAddress((Ipv4AddressNoZone) value), output));
301 ifPresentApply(linkAttributes.getRemoteIpv6RouterId(), value -> TlvUtil.writeTLV(REMOTE_IPV6_ROUTER_ID,
302 Ipv6Util.byteBufForAddress((Ipv6AddressNoZone) value), output));
303 ifPresentApply(linkAttributes.getAdminGroup(), value -> TlvUtil.writeTLV(ADMIN_GROUP,
304 Unpooled.copyInt(((AdministrativeGroup) value).getValue().intValue()), output));
305 ifPresentApply(linkAttributes.getMaxLinkBandwidth(), value -> TlvUtil.writeTLV(MAX_BANDWIDTH,
306 Unpooled.wrappedBuffer(((Bandwidth) value).getValue()), output));
307 ifPresentApply(linkAttributes.getMaxReservableBandwidth(), value -> TlvUtil.writeTLV(MAX_RESERVABLE_BANDWIDTH,
308 Unpooled.wrappedBuffer(((Bandwidth) value).getValue()), output));
309 serializeUnreservedBw(linkAttributes.getUnreservedBandwidth(), output);
310 ifPresentApply(linkAttributes.getTeMetric(), value -> TlvUtil.writeTLV(TE_METRIC,
311 Unpooled.copyLong(((TeMetric) value).getValue().toJava()), output));
312 ifPresentApply(linkAttributes.getLinkProtection(), value -> TlvUtil.writeTLV(LINK_PROTECTION_TYPE,
313 Unpooled.copyShort(((LinkProtectionType) value).getIntValue()), output));
314 serializeMplsProtocolMask(linkAttributes.getMplsProtocol(), output);
315 ifPresentApply(linkAttributes.getMetric(), value -> TlvUtil.writeTLV(METRIC,
316 Unpooled.copyMedium(((Metric) value).getValue().intValue()), output));
317 serializeSrlg(linkAttributes.getSharedRiskLinkGroups(), output);
318 ifPresentApply(linkAttributes.getLinkName(), value -> TlvUtil.writeTLV(LINK_NAME,
319 Unpooled.wrappedBuffer(StandardCharsets.UTF_8.encode((String) value)), output));
320 ifPresentApply(linkAttributes.getSrAdjIds(),
321 value -> SrLinkAttributesParser.serializeAdjacencySegmentIdentifiers((List<SrAdjIds>) value, SR_ADJ_ID,
323 ifPresentApply(linkAttributes.getSrLanAdjIds(),
324 value -> SrLinkAttributesParser.serializeLanAdjacencySegmentIdentifiers((List<SrLanAdjIds>) value, output));
325 ifPresentApply(linkAttributes.getPeerNodeSid(), value -> TlvUtil.writeTLV(PEER_NODE_SID_CODE,
326 SrLinkAttributesParser.serializeAdjacencySegmentIdentifier((PeerNodeSid) value), output));
327 ifPresentApply(linkAttributes.getPeerAdjSid(), value -> TlvUtil.writeTLV(PEER_ADJ_SID_CODE,
328 SrLinkAttributesParser.serializeAdjacencySegmentIdentifier((PeerAdjSid) value), output));
329 ifPresentApply(linkAttributes.getPeerSetSids(),
330 value -> SrLinkAttributesParser.serializeAdjacencySegmentIdentifiers((List<PeerSetSids>) value,
331 PEER_SET_SID_CODE, output));
332 // Performance Metrics
333 ifPresentApply(linkAttributes.getLinkDelay(), value -> TlvUtil.writeTLV(LINK_DELAY,
334 Unpooled.copyInt(((Delay) value).getValue().intValue()), output));
335 serializeLinkMinMaxDelay(linkAttributes.getLinkMinMaxDelay(), output);
336 ifPresentApply(linkAttributes.getDelayVariation(), value -> TlvUtil.writeTLV(DELAY_VARIATION,
337 Unpooled.copyInt(((Delay) value).getValue().intValue()), output));
338 ifPresentApply(linkAttributes.getLinkLoss(), value -> TlvUtil.writeTLV(LINK_LOSS,
339 Unpooled.copyInt(((Loss) value).getValue().intValue()), output));
340 ifPresentApply(linkAttributes.getResidualBandwidth(), value -> TlvUtil.writeTLV(RESIDUAL_BANDWIDTH,
341 Unpooled.wrappedBuffer(((Bandwidth) value).getValue()), output));
342 ifPresentApply(linkAttributes.getAvailableBandwidth(), value -> TlvUtil.writeTLV(AVAILABLE_BANDWIDTH,
343 Unpooled.wrappedBuffer(((Bandwidth) value).getValue()), output));
344 ifPresentApply(linkAttributes.getUtilizedBandwidth(), value -> TlvUtil.writeTLV(UTILIZED_BANDWIDTH,
345 Unpooled.wrappedBuffer(((Bandwidth) value).getValue()), output));
346 LOG.trace("Finished serializing Link Attributes");
349 private static void serializeUnreservedBw(final Map<UnreservedBandwidthKey, UnreservedBandwidth> ubList,
350 final ByteBuf byteAggregator) {
351 // this sub-TLV contains eight 32-bit IEEE floating point numbers
352 if (ubList != null) {
353 final ByteBuf unreservedBandwithBuf = Unpooled.buffer();
354 for (final UnreservedBandwidth unreservedBandwidth : ubList.values()) {
355 unreservedBandwithBuf.writeBytes(unreservedBandwidth.getBandwidth().getValue());
357 TlvUtil.writeTLV(UNRESERVED_BANDWIDTH, unreservedBandwithBuf, byteAggregator);
361 private static void serializeSrlg(final List<SrlgId> srlgList, final ByteBuf byteAggregator) {
362 if (srlgList != null) {
363 final ByteBuf sharedRLGBuf = Unpooled.buffer();
364 for (final SrlgId srlgId : srlgList) {
365 sharedRLGBuf.writeInt(srlgId.getValue().intValue());
367 TlvUtil.writeTLV(SHARED_RISK_LINK_GROUP, sharedRLGBuf, byteAggregator);
371 private static void serializeMplsProtocolMask(final MplsProtocolMask mplsProtocolMask,
372 final ByteBuf byteAggregator) {
373 if (mplsProtocolMask != null) {
374 final ByteBuf mplsProtocolMaskBuf = Unpooled.buffer(1);
375 final BitArray mask = new BitArray(FLAGS_SIZE);
376 mask.set(LDP_BIT, mplsProtocolMask.isLdp());
377 mask.set(RSVP_BIT, mplsProtocolMask.isRsvpte());
378 mask.toByteBuf(mplsProtocolMaskBuf);
379 TlvUtil.writeTLV(MPLS_PROTOCOL, mplsProtocolMaskBuf, byteAggregator);
383 private static void serializeLinkMinMaxDelay(final LinkMinMaxDelay linkMinMaxDelay, final ByteBuf byteAggregator) {
384 if (linkMinMaxDelay != null) {
385 final ByteBuf linkMinMaxDelayBuf = Unpooled.buffer();
386 linkMinMaxDelayBuf.writeInt(linkMinMaxDelay.getMinDelay().getValue().intValue());
387 linkMinMaxDelayBuf.writeInt(linkMinMaxDelay.getMaxDelay().getValue().intValue());
388 TlvUtil.writeTLV(LINK_MIN_MAX_DELAY, linkMinMaxDelayBuf, byteAggregator);