8169845bc729f7aa961564f2c7d6a5b832e8c111
[bgpcep.git] / bgp / extensions / linkstate / src / main / java / org / opendaylight / protocol / bgp / linkstate / impl / attribute / LinkAttributesParser.java
1 /*
2  * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.protocol.bgp.linkstate.impl.attribute;
9
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;
18 import java.util.Map.Entry;
19 import org.opendaylight.protocol.bgp.linkstate.impl.attribute.sr.SrLinkAttributesParser;
20 import org.opendaylight.protocol.bgp.linkstate.spi.TlvUtil;
21 import org.opendaylight.protocol.util.BitArray;
22 import org.opendaylight.protocol.util.ByteArray;
23 import org.opendaylight.protocol.util.Ipv4Util;
24 import org.opendaylight.protocol.util.Ipv6Util;
25 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
26 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Address;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.AdministrativeGroup;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.Delay;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.Ipv4RouterIdentifier;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.Ipv6RouterIdentifier;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.LinkProtectionType;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.Loss;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.MplsProtocolMask;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.ProtocolId;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.linkstate.attribute.LinkMinMaxDelay;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.linkstate.attribute.LinkMinMaxDelayBuilder;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.linkstate.attribute.PeerAdjSid;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.linkstate.attribute.PeerAdjSidBuilder;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.linkstate.attribute.PeerNodeSid;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.linkstate.attribute.PeerNodeSidBuilder;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.linkstate.attribute.PeerSetSids;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.linkstate.attribute.PeerSetSidsBuilder;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.linkstate.attribute.SrAdjIds;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.linkstate.attribute.SrLanAdjIds;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.linkstate.attribute.UnreservedBandwidth;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.linkstate.attribute.UnreservedBandwidthBuilder;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.linkstate.path.attribute.LinkStateAttribute;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.linkstate.path.attribute.link.state.attribute.LinkAttributesCase;
49 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.linkstate.path.attribute.link.state.attribute.LinkAttributesCaseBuilder;
50 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.linkstate.path.attribute.link.state.attribute.link.attributes._case.LinkAttributes;
51 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.linkstate.path.attribute.link.state.attribute.link.attributes._case.LinkAttributesBuilder;
52 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.concepts.rev131125.Bandwidth;
53 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.concepts.rev131125.Metric;
54 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.concepts.rev131125.TeMetric;
55 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.SrlgId;
56 import org.slf4j.Logger;
57 import org.slf4j.LoggerFactory;
58
59 @VisibleForTesting
60 public final class LinkAttributesParser {
61
62     public static final int SR_LAN_ADJ_ID = 1100;
63     private static final Logger LOG = LoggerFactory.getLogger(LinkAttributesParser.class);
64     private static final int UNRESERVED_BW_COUNT = 8;
65
66     private static final int BANDWIDTH_LENGTH = 4;
67
68     // MPLS protection mask bits
69     private static final int FLAGS_SIZE = 8;
70
71     private static final int LDP_BIT = 0;
72     private static final int RSVP_BIT = 1;
73
74     /* Link Attribute TLVs */
75     private static final int REMOTE_IPV4_ROUTER_ID = 1030;
76     private static final int REMOTE_IPV6_ROUTER_ID = 1031;
77     private static final int ADMIN_GROUP = 1088;
78     private static final int MAX_BANDWIDTH = 1089;
79     private static final int MAX_RESERVABLE_BANDWIDTH = 1090;
80     private static final int UNRESERVED_BANDWIDTH = 1091;
81     private static final int TE_METRIC = 1092;
82     private static final int LINK_PROTECTION_TYPE = 1093;
83     private static final int MPLS_PROTOCOL = 1094;
84     private static final int METRIC = 1095;
85     private static final int SHARED_RISK_LINK_GROUP = 1096;
86     private static final int LINK_OPAQUE = 1097;
87     private static final int LINK_NAME = 1098;
88     private static final int SR_ADJ_ID = 1099;
89     private static final int PEER_NODE_SID_CODE = 1101;
90     private static final int PEER_ADJ_SID_CODE = 1102;
91     private static final int PEER_SET_SID_CODE = 1103;
92     // Performance Metrics
93     private static final int LINK_DELAY = 1114;
94     private static final int LINK_MIN_MAX_DELAY = 1115;
95     private static final int DELAY_VARIATION = 1116;
96     private static final int LINK_LOSS = 1117;
97     private static final int RESIDUAL_BANDWIDTH = 1118;
98     private static final int AVAILABLE_BANDWIDTH = 1119;
99     private static final int UTILIZED_BANDWIDTH = 1120;
100
101     private LinkAttributesParser() {
102         throw new UnsupportedOperationException();
103     }
104
105     @FunctionalInterface
106     private interface SerializerInterface {
107         void check(Object cont);
108     }
109
110     /**
111      * Parse Link Attributes.
112      *
113      * @param attributes key is the tlv type and value is the value of the tlv
114      * @param protocolId to differentiate parsing methods
115      * @return {@link LinkStateAttribute}
116      */
117     static LinkStateAttribute parseLinkAttributes(final Multimap<Integer, ByteBuf> attributes, final ProtocolId protocolId) {
118         final LinkAttributesBuilder builder = new LinkAttributesBuilder();
119         final List<SrAdjIds> srAdjIds = new ArrayList<>();
120         final List<SrLanAdjIds> srLanAdjIds = new ArrayList<>();
121         final List<PeerSetSids> peerSetSids = new ArrayList<>();
122         for (final Entry<Integer, ByteBuf> entry : attributes.entries()) {
123             LOG.trace("Link attribute TLV {}", entry.getKey());
124             final int key = entry.getKey();
125             final ByteBuf value = entry.getValue();
126             switch (key) {
127             case TlvUtil.LOCAL_IPV4_ROUTER_ID:
128                 builder.setLocalIpv4RouterId(new Ipv4RouterIdentifier(Ipv4Util.addressForByteBuf(value)));
129                 LOG.debug("Parsed IPv4 Router-ID of local node: {}", builder.getLocalIpv4RouterId());
130                 break;
131             case TlvUtil.LOCAL_IPV6_ROUTER_ID:
132                 builder.setLocalIpv6RouterId(new Ipv6RouterIdentifier(Ipv6Util.addressForByteBuf(value)));
133                 LOG.debug("Parsed IPv6 Router-ID of local node: {}", builder.getLocalIpv6RouterId());
134                 break;
135             case REMOTE_IPV4_ROUTER_ID:
136                 builder.setRemoteIpv4RouterId(new Ipv4RouterIdentifier(Ipv4Util.addressForByteBuf(value)));
137                 LOG.debug("Parsed IPv4 Router-ID of remote node: {}", builder.getRemoteIpv4RouterId());
138                 break;
139             case REMOTE_IPV6_ROUTER_ID:
140                 builder.setRemoteIpv6RouterId(new Ipv6RouterIdentifier(Ipv6Util.addressForByteBuf(value)));
141                 LOG.debug("Parsed IPv6 Router-ID of remote node: {}", builder.getRemoteIpv6RouterId());
142                 break;
143             case ADMIN_GROUP:
144                 builder.setAdminGroup(new AdministrativeGroup(value.readUnsignedInt()));
145                 LOG.debug("Parsed Administrative Group {}", builder.getAdminGroup());
146                 break;
147             case MAX_BANDWIDTH:
148                 builder.setMaxLinkBandwidth(new Bandwidth(ByteArray.readAllBytes(value)));
149                 LOG.debug("Parsed Max Bandwidth {}", builder.getMaxLinkBandwidth());
150                 break;
151             case MAX_RESERVABLE_BANDWIDTH:
152                 builder.setMaxReservableBandwidth(new Bandwidth(ByteArray.readAllBytes(value)));
153                 LOG.debug("Parsed Max Reservable Bandwidth {}", builder.getMaxReservableBandwidth());
154                 break;
155             case UNRESERVED_BANDWIDTH:
156                 parseUnreservedBandwidth(value, builder);
157                 break;
158             case TE_METRIC:
159                 builder.setTeMetric(new TeMetric(ByteArray.bytesToLong(ByteArray.readAllBytes(value))));
160                 LOG.debug("Parsed Metric {}", builder.getTeMetric());
161                 break;
162             case LINK_PROTECTION_TYPE:
163                 builder.setLinkProtection(LinkProtectionType.forValue(value.readShort()));
164                 LOG.debug("Parsed Link Protection Type {}", builder.getLinkProtection());
165                 break;
166             case MPLS_PROTOCOL:
167                 final BitArray bits = BitArray.valueOf(value, FLAGS_SIZE);
168                 builder.setMplsProtocol(new MplsProtocolMask(bits.get(LDP_BIT), bits.get(RSVP_BIT)));
169                 LOG.debug("Parsed MPLS Protocols: {}", builder.getMplsProtocol());
170                 break;
171             case METRIC:
172                 // length can 3, 2 or 1
173                 builder.setMetric(new Metric(ByteArray.bytesToLong(ByteArray.readAllBytes(value))));
174                 LOG.debug("Parsed Metric {}", builder.getMetric());
175                 break;
176             case SHARED_RISK_LINK_GROUP:
177                 parseSrlg(value, builder);
178                 break;
179             case LINK_OPAQUE:
180                 LOG.debug("Parsed Opaque value : {}", ByteBufUtil.hexDump(value));
181                 break;
182             case LINK_NAME:
183                 builder.setLinkName(new String(ByteArray.readAllBytes(value), StandardCharsets.US_ASCII));
184                 LOG.debug("Parsed Link Name : {}", builder.getLinkName());
185                 break;
186             case SR_ADJ_ID:
187                 srAdjIds.add(SrLinkAttributesParser.parseAdjacencySegmentIdentifier(value, protocolId));
188                 LOG.debug("Parsed Adjacency Segment Identifier :{}", srAdjIds.get(srAdjIds.size() - 1));
189                 break;
190             case SR_LAN_ADJ_ID:
191                 srLanAdjIds.add(SrLinkAttributesParser.parseLanAdjacencySegmentIdentifier(value, protocolId));
192                 LOG.debug("Parsed Adjacency Segment Identifier :{}", srLanAdjIds.get(srLanAdjIds.size() - 1));
193                 break;
194             case PEER_NODE_SID_CODE:
195                 builder.setPeerNodeSid(new PeerNodeSidBuilder(SrLinkAttributesParser.parseEpeAdjacencySegmentIdentifier(value)).build());
196                 LOG.debug("Parsed Peer Segment Identifier :{}", builder.getPeerNodeSid());
197                 break;
198             case PEER_ADJ_SID_CODE:
199                 builder.setPeerAdjSid(new PeerAdjSidBuilder(SrLinkAttributesParser.parseEpeAdjacencySegmentIdentifier(value)).build());
200                 LOG.debug("Parsed Peer Segment Identifier :{}", builder.getPeerAdjSid());
201                 break;
202             case PEER_SET_SID_CODE:
203                 peerSetSids.add(new PeerSetSidsBuilder(SrLinkAttributesParser.parseEpeAdjacencySegmentIdentifier(value)).build());
204                 LOG.debug("Parsed Peer Set Sid :{}", peerSetSids.get(peerSetSids.size() - 1));
205                 break;
206             // Performance Metrics
207             case LINK_DELAY:
208                 builder.setLinkDelay(new Delay(value.readUnsignedInt()));
209                 LOG.debug("Parsed Link Delay {}", builder.getLinkDelay());
210                 break;
211             case LINK_MIN_MAX_DELAY:
212                 builder.setLinkMinMaxDelay(new LinkMinMaxDelayBuilder().setMinDelay(new Delay(value.readUnsignedInt()))
213                         .setMaxDelay(new Delay(value.readUnsignedInt())).build());
214                 LOG.debug("Parsed Link Min/Max Delay {}", builder.getLinkMinMaxDelay());
215                 break;
216             case DELAY_VARIATION:
217                 builder.setDelayVariation(new Delay(value.readUnsignedInt()));
218                 LOG.debug("Parsed Delay Variation {}", builder.getDelayVariation());
219                 break;
220             case LINK_LOSS:
221                 builder.setLinkLoss(new Loss(value.readUnsignedInt()));
222                 LOG.debug("Parsed Link Loss {}", builder.getLinkLoss());
223                 break;
224             case RESIDUAL_BANDWIDTH:
225                 builder.setResidualBandwidth(new Bandwidth(ByteArray.readAllBytes(value)));
226                 LOG.debug("Parsed Residual Bandwidth {}", builder.getResidualBandwidth());
227                 break;
228             case AVAILABLE_BANDWIDTH:
229                 builder.setAvailableBandwidth(new Bandwidth(ByteArray.readAllBytes(value)));
230                 LOG.debug("Parsed Available Bandwidth {}", builder.getAvailableBandwidth());
231                 break;
232             case UTILIZED_BANDWIDTH:
233                 builder.setUtilizedBandwidth(new Bandwidth(ByteArray.readAllBytes(value)));
234                 LOG.debug("Parsed Utilized Bandwidth {}", builder.getUtilizedBandwidth());
235                 break;
236             default:
237                 LOG.warn("TLV {} is not a valid link attribute, ignoring it", key);
238             }
239         }
240         if (!srAdjIds.isEmpty()) {
241             builder.setSrAdjIds(srAdjIds);
242         }
243         if (!srLanAdjIds.isEmpty()) {
244             builder.setSrLanAdjIds(srLanAdjIds);
245         }
246         if (!peerSetSids.isEmpty()) {
247             builder.setPeerSetSids(peerSetSids);
248         }
249         LOG.trace("Finished parsing Link Attributes.");
250         return new LinkAttributesCaseBuilder().setLinkAttributes(builder.build()).build();
251     }
252
253     private static void parseUnreservedBandwidth(final ByteBuf value, final LinkAttributesBuilder builder) {
254         final List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.linkstate.attribute.UnreservedBandwidth> unreservedBandwidth = new ArrayList<>(UNRESERVED_BW_COUNT);
255         for (int i = 0; i < UNRESERVED_BW_COUNT; i++) {
256             final ByteBuf v = value.readSlice(BANDWIDTH_LENGTH);
257             unreservedBandwidth.add(new UnreservedBandwidthBuilder().setBandwidth(new Bandwidth(ByteArray.readAllBytes(v))).setPriority((short) i).build());
258         }
259         builder.setUnreservedBandwidth(unreservedBandwidth);
260         LOG.debug("Parsed Unreserved Bandwidth {}", builder.getUnreservedBandwidth());
261     }
262
263     private static void parseSrlg(final ByteBuf value, final LinkAttributesBuilder builder) {
264         final List<SrlgId> sharedRiskLinkGroups = new ArrayList<>();
265         while (value.isReadable()) {
266             sharedRiskLinkGroups.add(new SrlgId(value.readUnsignedInt()));
267         }
268         builder.setSharedRiskLinkGroups(sharedRiskLinkGroups);
269         LOG.debug("Parsed Shared Risk Link Groups {}", builder.getSharedRiskLinkGroups());
270     }
271
272     private static void ifPresentApply(final Object tlv, final SerializerInterface serializer) {
273         if (tlv != null) {
274             serializer.check(tlv);
275         }
276     }
277
278
279     static void serializeLinkAttributes(final LinkAttributesCase linkAttributesCase, final ByteBuf output) {
280         final LinkAttributes linkAttributes = linkAttributesCase.getLinkAttributes();
281         LOG.trace("Started serializing Link Attributes");
282         ifPresentApply(linkAttributes.getLocalIpv4RouterId(), value -> TlvUtil.writeTLV(TlvUtil.LOCAL_IPV4_ROUTER_ID, Ipv4Util.byteBufForAddress((Ipv4Address) value), output));
283         ifPresentApply(linkAttributes.getLocalIpv6RouterId(), value -> TlvUtil.writeTLV(TlvUtil.LOCAL_IPV6_ROUTER_ID, Ipv6Util.byteBufForAddress((Ipv6Address) value), output));
284         ifPresentApply(linkAttributes.getRemoteIpv4RouterId(), value -> TlvUtil.writeTLV(REMOTE_IPV4_ROUTER_ID, Ipv4Util.byteBufForAddress((Ipv4Address) value), output));
285         ifPresentApply(linkAttributes.getRemoteIpv6RouterId(), value -> TlvUtil.writeTLV(REMOTE_IPV6_ROUTER_ID, Ipv6Util.byteBufForAddress((Ipv6Address) value), output));
286         ifPresentApply(linkAttributes.getAdminGroup(), value -> TlvUtil.writeTLV(ADMIN_GROUP, Unpooled.copyInt((((AdministrativeGroup) value).getValue()).intValue()), output));
287         ifPresentApply(linkAttributes.getMaxLinkBandwidth(), value -> TlvUtil.writeTLV(MAX_BANDWIDTH, Unpooled.wrappedBuffer(((Bandwidth) value).getValue()), output));
288         ifPresentApply(linkAttributes.getMaxReservableBandwidth(), value -> TlvUtil.writeTLV(MAX_RESERVABLE_BANDWIDTH, Unpooled.wrappedBuffer(((Bandwidth) value).getValue()), output));
289         serializeUnreservedBw(linkAttributes.getUnreservedBandwidth(), output);
290         ifPresentApply(linkAttributes.getTeMetric(), value -> TlvUtil.writeTLV(TE_METRIC, Unpooled.copyLong(((TeMetric) value).getValue()), output));
291         ifPresentApply(linkAttributes.getLinkProtection(), value -> TlvUtil.writeTLV(LINK_PROTECTION_TYPE, Unpooled.copyShort(((LinkProtectionType) value).getIntValue()), output));
292         serializeMplsProtocolMask(linkAttributes.getMplsProtocol(), output);
293         ifPresentApply(linkAttributes.getMetric(), value -> TlvUtil.writeTLV(METRIC, Unpooled.copyMedium(((Metric) value).getValue().intValue()), output));
294         serializeSrlg(linkAttributes.getSharedRiskLinkGroups(), output);
295         ifPresentApply(linkAttributes.getLinkName(), value -> TlvUtil.writeTLV(LINK_NAME, Unpooled.wrappedBuffer(StandardCharsets.UTF_8.encode((String) value)), output));
296         ifPresentApply(linkAttributes.getSrAdjIds(), value -> SrLinkAttributesParser.serializeAdjacencySegmentIdentifiers((List<SrAdjIds>) value, SR_ADJ_ID, output));
297         ifPresentApply(linkAttributes.getSrLanAdjIds(), value -> SrLinkAttributesParser.serializeLanAdjacencySegmentIdentifiers((List<SrLanAdjIds>) value, output));
298         ifPresentApply(linkAttributes.getPeerNodeSid(), value -> TlvUtil.writeTLV(PEER_NODE_SID_CODE, SrLinkAttributesParser.serializeAdjacencySegmentIdentifier((PeerNodeSid) value), output));
299         ifPresentApply(linkAttributes.getPeerAdjSid(), value -> TlvUtil.writeTLV(PEER_ADJ_SID_CODE, SrLinkAttributesParser.serializeAdjacencySegmentIdentifier((PeerAdjSid) value), output));
300         ifPresentApply(linkAttributes.getPeerSetSids(), value -> SrLinkAttributesParser.serializeAdjacencySegmentIdentifiers((List<PeerSetSids>) value, PEER_SET_SID_CODE, output));
301         // Performance Metrics
302         ifPresentApply(linkAttributes.getLinkDelay(), value -> TlvUtil.writeTLV(LINK_DELAY, Unpooled.copyInt((((Delay) value).getValue()).intValue()), output));
303         serializeLinkMinMaxDelay(linkAttributes.getLinkMinMaxDelay(), output);
304         ifPresentApply(linkAttributes.getDelayVariation(), value -> TlvUtil.writeTLV(DELAY_VARIATION, Unpooled.copyInt((((Delay) value).getValue()).intValue()), output));
305         ifPresentApply(linkAttributes.getLinkLoss(), value -> TlvUtil.writeTLV(LINK_LOSS, Unpooled.copyInt((((Loss) value).getValue()).intValue()), output));
306         ifPresentApply(linkAttributes.getResidualBandwidth(), value -> TlvUtil.writeTLV(RESIDUAL_BANDWIDTH, Unpooled.wrappedBuffer(((Bandwidth) value).getValue()), output));
307         ifPresentApply(linkAttributes.getAvailableBandwidth(), value -> TlvUtil.writeTLV(AVAILABLE_BANDWIDTH, Unpooled.wrappedBuffer(((Bandwidth) value).getValue()), output));
308         ifPresentApply(linkAttributes.getUtilizedBandwidth(), value -> TlvUtil.writeTLV(UTILIZED_BANDWIDTH, Unpooled.wrappedBuffer(((Bandwidth) value).getValue()), output));
309         LOG.trace("Finished serializing Link Attributes");
310     }
311
312     private static void serializeUnreservedBw(final List<UnreservedBandwidth> ubList, final ByteBuf byteAggregator) {
313         // this sub-TLV contains eight 32-bit IEEE floating point numbers
314         if (ubList != null) {
315             final ByteBuf unreservedBandwithBuf = Unpooled.buffer();
316             for (final UnreservedBandwidth unreservedBandwidth : ubList) {
317                 unreservedBandwithBuf.writeBytes(unreservedBandwidth.getBandwidth().getValue());
318             }
319             TlvUtil.writeTLV(UNRESERVED_BANDWIDTH, unreservedBandwithBuf, byteAggregator);
320         }
321     }
322
323     private static void serializeSrlg(final List<SrlgId> srlgList, final ByteBuf byteAggregator) {
324         if (srlgList != null) {
325             final ByteBuf sharedRLGBuf = Unpooled.buffer();
326             for (final SrlgId srlgId : srlgList) {
327                 sharedRLGBuf.writeInt(srlgId.getValue().intValue());
328             }
329             TlvUtil.writeTLV(SHARED_RISK_LINK_GROUP, sharedRLGBuf, byteAggregator);
330         }
331     }
332
333     private static void serializeMplsProtocolMask(final MplsProtocolMask mplsProtocolMask, final ByteBuf byteAggregator) {
334         if (mplsProtocolMask != null) {
335             final ByteBuf mplsProtocolMaskBuf = Unpooled.buffer(1);
336             final BitArray mask = new BitArray(FLAGS_SIZE);
337             mask.set(LDP_BIT, mplsProtocolMask.isLdp());
338             mask.set(RSVP_BIT, mplsProtocolMask.isRsvpte());
339             mask.toByteBuf(mplsProtocolMaskBuf);
340             TlvUtil.writeTLV(MPLS_PROTOCOL, mplsProtocolMaskBuf, byteAggregator);
341         }
342     }
343
344     private static void serializeLinkMinMaxDelay(final LinkMinMaxDelay linkMinMaxDelay, final ByteBuf byteAggregator) {
345         if (linkMinMaxDelay != null) {
346             final ByteBuf linkMinMaxDelayBuf = Unpooled.buffer();
347             linkMinMaxDelayBuf.writeInt(linkMinMaxDelay.getMinDelay().getValue().intValue());
348             linkMinMaxDelayBuf.writeInt(linkMinMaxDelay.getMaxDelay().getValue().intValue());
349             TlvUtil.writeTLV(LINK_MIN_MAX_DELAY, linkMinMaxDelayBuf, byteAggregator);
350         }
351     }
352 }