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 static org.opendaylight.yangtools.yang.common.netty.ByteBufUtils.readUint32;
11 import static org.opendaylight.yangtools.yang.common.netty.ByteBufUtils.writeUint32;
13 import com.google.common.annotations.VisibleForTesting;
14 import com.google.common.collect.ImmutableSet;
15 import com.google.common.collect.Multimap;
16 import io.netty.buffer.ByteBuf;
17 import io.netty.buffer.ByteBufUtil;
18 import io.netty.buffer.Unpooled;
19 import java.nio.charset.StandardCharsets;
20 import java.util.ArrayList;
21 import java.util.List;
23 import java.util.Map.Entry;
25 import org.opendaylight.protocol.bgp.linkstate.impl.attribute.sr.SrLinkAttributesParser;
26 import org.opendaylight.protocol.bgp.linkstate.spi.TlvUtil;
27 import org.opendaylight.protocol.util.BitArray;
28 import org.opendaylight.protocol.util.ByteArray;
29 import org.opendaylight.protocol.util.Ipv4Util;
30 import org.opendaylight.protocol.util.Ipv6Util;
31 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4AddressNoZone;
32 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6AddressNoZone;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.AdministrativeGroup;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.Delay;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.Ipv4RouterIdentifier;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.Ipv6RouterIdentifier;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.LinkProtectionType;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.Loss;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.MplsProtocolMask;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.ProtocolId;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.linkstate.attribute.LinkMinMaxDelay;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.linkstate.attribute.LinkMinMaxDelayBuilder;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.linkstate.attribute.PeerAdjSid;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.linkstate.attribute.PeerAdjSidBuilder;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.linkstate.attribute.PeerNodeSid;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.linkstate.attribute.PeerNodeSidBuilder;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.linkstate.attribute.PeerSetSids;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.linkstate.attribute.PeerSetSidsBuilder;
49 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.linkstate.attribute.SrAdjIds;
50 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.linkstate.attribute.SrLanAdjIds;
51 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.linkstate.attribute.UnreservedBandwidth;
52 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.linkstate.attribute.UnreservedBandwidthBuilder;
53 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.linkstate.attribute.UnreservedBandwidthKey;
54 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.linkstate.path.attribute.LinkStateAttribute;
55 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.linkstate.path.attribute.link.state.attribute.LinkAttributesCase;
56 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev200120.linkstate.path.attribute.link.state.attribute.LinkAttributesCaseBuilder;
57 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;
58 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;
59 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.concepts.rev131125.Bandwidth;
60 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.concepts.rev131125.Metric;
61 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.concepts.rev131125.TeMetric;
62 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.SrlgId;
63 import org.opendaylight.yangtools.yang.binding.util.BindingMap;
64 import org.opendaylight.yangtools.yang.common.Uint32;
65 import org.opendaylight.yangtools.yang.common.Uint8;
66 import org.slf4j.Logger;
67 import org.slf4j.LoggerFactory;
70 public final class LinkAttributesParser {
71 public static final int SR_LAN_ADJ_ID = 1100;
73 private static final Logger LOG = LoggerFactory.getLogger(LinkAttributesParser.class);
74 private static final int UNRESERVED_BW_COUNT = 8;
76 private static final int BANDWIDTH_LENGTH = 4;
78 // MPLS protection mask bits
79 private static final int FLAGS_SIZE = 8;
81 private static final int LDP_BIT = 0;
82 private static final int RSVP_BIT = 1;
84 // Link Attribute TLVs
85 private static final int REMOTE_IPV4_ROUTER_ID = 1030;
86 private static final int REMOTE_IPV6_ROUTER_ID = 1031;
87 private static final int ADMIN_GROUP = 1088;
88 private static final int MAX_BANDWIDTH = 1089;
89 private static final int MAX_RESERVABLE_BANDWIDTH = 1090;
90 private static final int UNRESERVED_BANDWIDTH = 1091;
91 private static final int TE_METRIC = 1092;
92 private static final int LINK_PROTECTION_TYPE = 1093;
93 private static final int MPLS_PROTOCOL = 1094;
94 private static final int METRIC = 1095;
95 private static final int SHARED_RISK_LINK_GROUP = 1096;
96 private static final int LINK_OPAQUE = 1097;
97 private static final int LINK_NAME = 1098;
98 private static final int SR_ADJ_ID = 1099;
99 private static final int PEER_NODE_SID_CODE = 1101;
100 private static final int PEER_ADJ_SID_CODE = 1102;
101 private static final int PEER_SET_SID_CODE = 1103;
103 // RFC9104 Traffic Engineering Extended Administrative Groups
104 private static final int EXTENDED_ADMIN_GROUP = 1173;
106 // Performance Metrics
107 private static final int LINK_DELAY = 1114;
108 private static final int LINK_MIN_MAX_DELAY = 1115;
109 private static final int DELAY_VARIATION = 1116;
110 private static final int LINK_LOSS = 1117;
111 private static final int RESIDUAL_BANDWIDTH = 1118;
112 private static final int AVAILABLE_BANDWIDTH = 1119;
113 private static final int UTILIZED_BANDWIDTH = 1120;
116 private LinkAttributesParser() {
121 private interface SerializerInterface {
122 void check(Object cont);
126 * Parse Link Attributes.
128 * @param attributes key is the tlv type and value is the value of the tlv
129 * @param protocolId to differentiate parsing methods
130 * @return {@link LinkStateAttribute}
132 static LinkStateAttribute parseLinkAttributes(final Multimap<Integer, ByteBuf> attributes,
133 final ProtocolId protocolId) {
134 final LinkAttributesBuilder builder = new LinkAttributesBuilder();
135 final List<SrAdjIds> srAdjIds = new ArrayList<>();
136 final List<SrLanAdjIds> srLanAdjIds = new ArrayList<>();
137 final List<PeerSetSids> peerSetSids = new ArrayList<>();
138 for (final Entry<Integer, ByteBuf> entry : attributes.entries()) {
139 LOG.trace("Link attribute TLV {}", entry.getKey());
140 final int key = entry.getKey();
141 final ByteBuf value = entry.getValue();
143 case TlvUtil.LOCAL_IPV4_ROUTER_ID:
144 builder.setLocalIpv4RouterId(new Ipv4RouterIdentifier(Ipv4Util.addressForByteBuf(value)));
145 LOG.debug("Parsed IPv4 Router-ID of local node: {}", builder.getLocalIpv4RouterId());
147 case TlvUtil.LOCAL_IPV6_ROUTER_ID:
148 builder.setLocalIpv6RouterId(new Ipv6RouterIdentifier(Ipv6Util.addressForByteBuf(value)));
149 LOG.debug("Parsed IPv6 Router-ID of local node: {}", builder.getLocalIpv6RouterId());
151 case REMOTE_IPV4_ROUTER_ID:
152 builder.setRemoteIpv4RouterId(new Ipv4RouterIdentifier(Ipv4Util.addressForByteBuf(value)));
153 LOG.debug("Parsed IPv4 Router-ID of remote node: {}", builder.getRemoteIpv4RouterId());
155 case REMOTE_IPV6_ROUTER_ID:
156 builder.setRemoteIpv6RouterId(new Ipv6RouterIdentifier(Ipv6Util.addressForByteBuf(value)));
157 LOG.debug("Parsed IPv6 Router-ID of remote node: {}", builder.getRemoteIpv6RouterId());
160 builder.setAdminGroup(new AdministrativeGroup(readUint32(value)));
161 LOG.debug("Parsed Administrative Group {}", builder.getAdminGroup());
163 case EXTENDED_ADMIN_GROUP:
164 // FIXME: BGPCEP-895: add proper implementation
165 LOG.info("Support for Extended Administrative Group not implemented, ignoring it");
168 builder.setMaxLinkBandwidth(new Bandwidth(ByteArray.readAllBytes(value)));
169 LOG.debug("Parsed Max Bandwidth {}", builder.getMaxLinkBandwidth());
171 case MAX_RESERVABLE_BANDWIDTH:
172 builder.setMaxReservableBandwidth(new Bandwidth(ByteArray.readAllBytes(value)));
173 LOG.debug("Parsed Max Reservable Bandwidth {}", builder.getMaxReservableBandwidth());
175 case UNRESERVED_BANDWIDTH:
176 parseUnreservedBandwidth(value, builder);
179 builder.setTeMetric(new TeMetric(readUint32(value)));
180 LOG.debug("Parsed Metric {}", builder.getTeMetric());
182 case LINK_PROTECTION_TYPE:
183 builder.setLinkProtection(LinkProtectionType.forValue(value.readShort()));
184 LOG.debug("Parsed Link Protection Type {}", builder.getLinkProtection());
187 final BitArray bits = BitArray.valueOf(value, FLAGS_SIZE);
188 builder.setMplsProtocol(new MplsProtocolMask(bits.get(LDP_BIT), bits.get(RSVP_BIT)));
189 LOG.debug("Parsed MPLS Protocols: {}", builder.getMplsProtocol());
192 // length can 3, 2 or 1
193 builder.setMetric(new Metric(Uint32.valueOf(ByteArray.bytesToLong(ByteArray.readAllBytes(value)))));
194 LOG.debug("Parsed Metric {}", builder.getMetric());
196 case SHARED_RISK_LINK_GROUP:
197 parseSrlg(value, builder);
200 if (LOG.isDebugEnabled()) {
201 LOG.debug("Parsed Opaque value : {}", ByteBufUtil.hexDump(value));
205 builder.setLinkName(new String(ByteArray.readAllBytes(value), StandardCharsets.US_ASCII));
206 LOG.debug("Parsed Link Name : {}", builder.getLinkName());
209 srAdjIds.add(SrLinkAttributesParser.parseAdjacencySegmentIdentifier(value, protocolId));
210 LOG.debug("Parsed Adjacency Segment Identifier :{}", srAdjIds.get(srAdjIds.size() - 1));
213 srLanAdjIds.add(SrLinkAttributesParser.parseLanAdjacencySegmentIdentifier(value, protocolId));
214 LOG.debug("Parsed Adjacency Segment Identifier :{}", srLanAdjIds.get(srLanAdjIds.size() - 1));
216 case PEER_NODE_SID_CODE:
217 builder.setPeerNodeSid(new PeerNodeSidBuilder(
218 SrLinkAttributesParser.parseEpeAdjacencySegmentIdentifier(value)).build());
219 LOG.debug("Parsed Peer Segment Identifier :{}", builder.getPeerNodeSid());
221 case PEER_ADJ_SID_CODE:
222 builder.setPeerAdjSid(new PeerAdjSidBuilder(
223 SrLinkAttributesParser.parseEpeAdjacencySegmentIdentifier(value)).build());
224 LOG.debug("Parsed Peer Segment Identifier :{}", builder.getPeerAdjSid());
226 case PEER_SET_SID_CODE:
227 peerSetSids.add(new PeerSetSidsBuilder(
228 SrLinkAttributesParser.parseEpeAdjacencySegmentIdentifier(value)).build());
229 LOG.debug("Parsed Peer Set Sid :{}", peerSetSids.get(peerSetSids.size() - 1));
231 // Performance Metrics
233 builder.setLinkDelay(new Delay(readUint32(value)));
234 LOG.debug("Parsed Link Delay {}", builder.getLinkDelay());
236 case LINK_MIN_MAX_DELAY:
237 builder.setLinkMinMaxDelay(new LinkMinMaxDelayBuilder()
238 .setMinDelay(new Delay(readUint32(value)))
239 .setMaxDelay(new Delay(readUint32(value)))
241 LOG.debug("Parsed Link Min/Max Delay {}", builder.getLinkMinMaxDelay());
243 case DELAY_VARIATION:
244 builder.setDelayVariation(new Delay(readUint32(value)));
245 LOG.debug("Parsed Delay Variation {}", builder.getDelayVariation());
248 builder.setLinkLoss(new Loss(readUint32(value)));
249 LOG.debug("Parsed Link Loss {}", builder.getLinkLoss());
251 case RESIDUAL_BANDWIDTH:
252 builder.setResidualBandwidth(new Bandwidth(ByteArray.readAllBytes(value)));
253 LOG.debug("Parsed Residual Bandwidth {}", builder.getResidualBandwidth());
255 case AVAILABLE_BANDWIDTH:
256 builder.setAvailableBandwidth(new Bandwidth(ByteArray.readAllBytes(value)));
257 LOG.debug("Parsed Available Bandwidth {}", builder.getAvailableBandwidth());
259 case UTILIZED_BANDWIDTH:
260 builder.setUtilizedBandwidth(new Bandwidth(ByteArray.readAllBytes(value)));
261 LOG.debug("Parsed Utilized Bandwidth {}", builder.getUtilizedBandwidth());
264 LOG.warn("TLV {} is not a recognized link attribute, ignoring it", key);
267 if (!srAdjIds.isEmpty()) {
268 builder.setSrAdjIds(srAdjIds);
270 if (!srLanAdjIds.isEmpty()) {
271 builder.setSrLanAdjIds(srLanAdjIds);
273 if (!peerSetSids.isEmpty()) {
274 builder.setPeerSetSids(peerSetSids);
276 LOG.trace("Finished parsing Link Attributes.");
277 return new LinkAttributesCaseBuilder().setLinkAttributes(builder.build()).build();
280 private static void parseUnreservedBandwidth(final ByteBuf value, final LinkAttributesBuilder builder) {
281 final var unreservedBandwidth =
282 BindingMap.<UnreservedBandwidthKey, UnreservedBandwidth>orderedBuilder(UNRESERVED_BW_COUNT);
283 for (int i = 0; i < UNRESERVED_BW_COUNT; i++) {
284 final ByteBuf v = value.readSlice(BANDWIDTH_LENGTH);
285 unreservedBandwidth.add(new UnreservedBandwidthBuilder()
286 .setBandwidth(new Bandwidth(ByteArray.readAllBytes(v)))
287 .setPriority(Uint8.valueOf(i))
290 builder.setUnreservedBandwidth(unreservedBandwidth.build());
291 LOG.debug("Parsed Unreserved Bandwidth {}", builder.getUnreservedBandwidth());
294 private static void parseSrlg(final ByteBuf value, final LinkAttributesBuilder builder) {
295 final var sharedRiskLinkGroups = ImmutableSet.<SrlgId>builder();
296 while (value.isReadable()) {
297 sharedRiskLinkGroups.add(new SrlgId(readUint32(value)));
299 builder.setSharedRiskLinkGroups(sharedRiskLinkGroups.build());
300 LOG.debug("Parsed Shared Risk Link Groups {}", builder.getSharedRiskLinkGroups());
303 private static void ifPresentApply(final Object tlv, final SerializerInterface serializer) {
305 serializer.check(tlv);
309 static void serializeLinkAttributes(final LinkAttributesCase linkAttributesCase, final ByteBuf output) {
310 final LinkAttributes linkAttributes = linkAttributesCase.getLinkAttributes();
311 LOG.trace("Started serializing Link Attributes");
312 ifPresentApply(linkAttributes.getLocalIpv4RouterId(), value -> TlvUtil.writeTLV(TlvUtil.LOCAL_IPV4_ROUTER_ID,
313 Ipv4Util.byteBufForAddress((Ipv4AddressNoZone) value), output));
314 ifPresentApply(linkAttributes.getLocalIpv6RouterId(), value -> TlvUtil.writeTLV(TlvUtil.LOCAL_IPV6_ROUTER_ID,
315 Ipv6Util.byteBufForAddress((Ipv6AddressNoZone) value), output));
316 ifPresentApply(linkAttributes.getRemoteIpv4RouterId(), value -> TlvUtil.writeTLV(REMOTE_IPV4_ROUTER_ID,
317 Ipv4Util.byteBufForAddress((Ipv4AddressNoZone) value), output));
318 ifPresentApply(linkAttributes.getRemoteIpv6RouterId(), value -> TlvUtil.writeTLV(REMOTE_IPV6_ROUTER_ID,
319 Ipv6Util.byteBufForAddress((Ipv6AddressNoZone) value), output));
320 ifPresentApply(linkAttributes.getAdminGroup(), value -> TlvUtil.writeTLV(ADMIN_GROUP,
321 Unpooled.copyInt(((AdministrativeGroup) value).getValue().intValue()), output));
322 ifPresentApply(linkAttributes.getMaxLinkBandwidth(), value -> TlvUtil.writeTLV(MAX_BANDWIDTH,
323 Unpooled.wrappedBuffer(((Bandwidth) value).getValue()), output));
324 ifPresentApply(linkAttributes.getMaxReservableBandwidth(), value -> TlvUtil.writeTLV(MAX_RESERVABLE_BANDWIDTH,
325 Unpooled.wrappedBuffer(((Bandwidth) value).getValue()), output));
326 serializeUnreservedBw(linkAttributes.getUnreservedBandwidth(), output);
327 ifPresentApply(linkAttributes.getTeMetric(), value -> TlvUtil.writeTLV(TE_METRIC,
328 Unpooled.copyLong(((TeMetric) value).getValue().toJava()), output));
329 ifPresentApply(linkAttributes.getLinkProtection(), value -> TlvUtil.writeTLV(LINK_PROTECTION_TYPE,
330 Unpooled.copyShort(((LinkProtectionType) value).getIntValue()), output));
331 serializeMplsProtocolMask(linkAttributes.getMplsProtocol(), output);
332 ifPresentApply(linkAttributes.getMetric(), value -> TlvUtil.writeTLV(METRIC,
333 Unpooled.copyMedium(((Metric) value).getValue().intValue()), output));
334 serializeSrlg(linkAttributes.getSharedRiskLinkGroups(), output);
335 ifPresentApply(linkAttributes.getLinkName(), value -> TlvUtil.writeTLV(LINK_NAME,
336 Unpooled.wrappedBuffer(StandardCharsets.UTF_8.encode((String) value)), output));
337 ifPresentApply(linkAttributes.getSrAdjIds(),
338 value -> SrLinkAttributesParser.serializeAdjacencySegmentIdentifiers((List<SrAdjIds>) value, SR_ADJ_ID,
340 ifPresentApply(linkAttributes.getSrLanAdjIds(),
341 value -> SrLinkAttributesParser.serializeLanAdjacencySegmentIdentifiers((List<SrLanAdjIds>) value, output));
342 ifPresentApply(linkAttributes.getPeerNodeSid(), value -> TlvUtil.writeTLV(PEER_NODE_SID_CODE,
343 SrLinkAttributesParser.serializeAdjacencySegmentIdentifier((PeerNodeSid) value), output));
344 ifPresentApply(linkAttributes.getPeerAdjSid(), value -> TlvUtil.writeTLV(PEER_ADJ_SID_CODE,
345 SrLinkAttributesParser.serializeAdjacencySegmentIdentifier((PeerAdjSid) value), output));
346 ifPresentApply(linkAttributes.getPeerSetSids(),
347 value -> SrLinkAttributesParser.serializeAdjacencySegmentIdentifiers((List<PeerSetSids>) value,
348 PEER_SET_SID_CODE, output));
349 // Performance Metrics
350 ifPresentApply(linkAttributes.getLinkDelay(), value -> TlvUtil.writeTLV(LINK_DELAY,
351 Unpooled.copyInt(((Delay) value).getValue().intValue()), output));
352 serializeLinkMinMaxDelay(linkAttributes.getLinkMinMaxDelay(), output);
353 ifPresentApply(linkAttributes.getDelayVariation(), value -> TlvUtil.writeTLV(DELAY_VARIATION,
354 Unpooled.copyInt(((Delay) value).getValue().intValue()), output));
355 ifPresentApply(linkAttributes.getLinkLoss(), value -> TlvUtil.writeTLV(LINK_LOSS,
356 Unpooled.copyInt(((Loss) value).getValue().intValue()), output));
357 ifPresentApply(linkAttributes.getResidualBandwidth(), value -> TlvUtil.writeTLV(RESIDUAL_BANDWIDTH,
358 Unpooled.wrappedBuffer(((Bandwidth) value).getValue()), output));
359 ifPresentApply(linkAttributes.getAvailableBandwidth(), value -> TlvUtil.writeTLV(AVAILABLE_BANDWIDTH,
360 Unpooled.wrappedBuffer(((Bandwidth) value).getValue()), output));
361 ifPresentApply(linkAttributes.getUtilizedBandwidth(), value -> TlvUtil.writeTLV(UTILIZED_BANDWIDTH,
362 Unpooled.wrappedBuffer(((Bandwidth) value).getValue()), output));
363 LOG.trace("Finished serializing Link Attributes");
366 private static void serializeUnreservedBw(final Map<UnreservedBandwidthKey, UnreservedBandwidth> ubList,
367 final ByteBuf byteAggregator) {
368 // this sub-TLV contains eight 32-bit IEEE floating point numbers
369 if (ubList != null) {
370 final ByteBuf unreservedBandwithBuf = Unpooled.buffer();
371 for (final UnreservedBandwidth unreservedBandwidth : ubList.values()) {
372 unreservedBandwithBuf.writeBytes(unreservedBandwidth.getBandwidth().getValue());
374 TlvUtil.writeTLV(UNRESERVED_BANDWIDTH, unreservedBandwithBuf, byteAggregator);
378 private static void serializeSrlg(final Set<SrlgId> srlgList, final ByteBuf byteAggregator) {
379 if (srlgList != null) {
380 final ByteBuf sharedRLGBuf = Unpooled.buffer();
381 for (final SrlgId srlgId : srlgList) {
382 writeUint32(sharedRLGBuf, srlgId.getValue());
384 TlvUtil.writeTLV(SHARED_RISK_LINK_GROUP, sharedRLGBuf, byteAggregator);
388 private static void serializeMplsProtocolMask(final MplsProtocolMask mplsProtocolMask,
389 final ByteBuf byteAggregator) {
390 if (mplsProtocolMask != null) {
391 final ByteBuf mplsProtocolMaskBuf = Unpooled.buffer(1);
392 final BitArray mask = new BitArray(FLAGS_SIZE);
393 mask.set(LDP_BIT, mplsProtocolMask.getLdp());
394 mask.set(RSVP_BIT, mplsProtocolMask.getRsvpte());
395 mask.toByteBuf(mplsProtocolMaskBuf);
396 TlvUtil.writeTLV(MPLS_PROTOCOL, mplsProtocolMaskBuf, byteAggregator);
400 private static void serializeLinkMinMaxDelay(final LinkMinMaxDelay linkMinMaxDelay, final ByteBuf byteAggregator) {
401 if (linkMinMaxDelay != null) {
402 final ByteBuf linkMinMaxDelayBuf = Unpooled.buffer(8);
403 writeUint32(linkMinMaxDelayBuf, linkMinMaxDelay.getMinDelay().getValue());
404 writeUint32(linkMinMaxDelayBuf, linkMinMaxDelay.getMaxDelay().getValue());
405 TlvUtil.writeTLV(LINK_MIN_MAX_DELAY, linkMinMaxDelayBuf, byteAggregator);