From: Robert Varga Date: Wed, 13 Mar 2019 14:42:59 +0000 (+0100) Subject: Enforce checkstyle in bgp-linkstate X-Git-Tag: release/sodium~63 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=commitdiff_plain;h=a4535e95320c33f50fd6a260a6b88c6eca7f55e7;p=bgpcep.git Enforce checkstyle in bgp-linkstate This fixes up a pile of warnings and flips the switch. JIRA: BGPCEP-713 Change-Id: I0ed6c260558a4fee42c4432da4c137245984c42a Signed-off-by: Robert Varga --- diff --git a/bgp/extensions/linkstate/pom.xml b/bgp/extensions/linkstate/pom.xml index f621381b45..f8f4615b60 100644 --- a/bgp/extensions/linkstate/pom.xml +++ b/bgp/extensions/linkstate/pom.xml @@ -89,18 +89,6 @@ - - - - org.apache.maven.plugins - maven-checkstyle-plugin - - warn - - - - - scm:git:ssh://git.opendaylight.org:29418/bgpcep.git scm:git:ssh://git.opendaylight.org:29418/bgpcep.git diff --git a/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/LinkstateRIBSupport.java b/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/LinkstateRIBSupport.java index 71bf22c305..dd0462a019 100644 --- a/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/LinkstateRIBSupport.java +++ b/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/LinkstateRIBSupport.java @@ -75,8 +75,8 @@ public final class LinkstateRIBSupport DestinationLinkstate.QNAME); } - public synchronized static LinkstateRIBSupport getInstance(final BindingNormalizedNodeSerializer mappingService) { - if(SINGLETON == null){ + public static synchronized LinkstateRIBSupport getInstance(final BindingNormalizedNodeSerializer mappingService) { + if (SINGLETON == null) { SINGLETON = new LinkstateRIBSupport(mappingService); } return SINGLETON; diff --git a/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/attribute/LinkAttributesParser.java b/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/attribute/LinkAttributesParser.java index 8169845bc7..8f77c5ef3a 100644 --- a/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/attribute/LinkAttributesParser.java +++ b/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/attribute/LinkAttributesParser.java @@ -99,7 +99,7 @@ public final class LinkAttributesParser { private static final int UTILIZED_BANDWIDTH = 1120; private LinkAttributesParser() { - throw new UnsupportedOperationException(); + } @FunctionalInterface @@ -114,7 +114,8 @@ public final class LinkAttributesParser { * @param protocolId to differentiate parsing methods * @return {@link LinkStateAttribute} */ - static LinkStateAttribute parseLinkAttributes(final Multimap attributes, final ProtocolId protocolId) { + static LinkStateAttribute parseLinkAttributes(final Multimap attributes, + final ProtocolId protocolId) { final LinkAttributesBuilder builder = new LinkAttributesBuilder(); final List srAdjIds = new ArrayList<>(); final List srLanAdjIds = new ArrayList<>(); @@ -124,117 +125,121 @@ public final class LinkAttributesParser { final int key = entry.getKey(); final ByteBuf value = entry.getValue(); switch (key) { - case TlvUtil.LOCAL_IPV4_ROUTER_ID: - builder.setLocalIpv4RouterId(new Ipv4RouterIdentifier(Ipv4Util.addressForByteBuf(value))); - LOG.debug("Parsed IPv4 Router-ID of local node: {}", builder.getLocalIpv4RouterId()); - break; - case TlvUtil.LOCAL_IPV6_ROUTER_ID: - builder.setLocalIpv6RouterId(new Ipv6RouterIdentifier(Ipv6Util.addressForByteBuf(value))); - LOG.debug("Parsed IPv6 Router-ID of local node: {}", builder.getLocalIpv6RouterId()); - break; - case REMOTE_IPV4_ROUTER_ID: - builder.setRemoteIpv4RouterId(new Ipv4RouterIdentifier(Ipv4Util.addressForByteBuf(value))); - LOG.debug("Parsed IPv4 Router-ID of remote node: {}", builder.getRemoteIpv4RouterId()); - break; - case REMOTE_IPV6_ROUTER_ID: - builder.setRemoteIpv6RouterId(new Ipv6RouterIdentifier(Ipv6Util.addressForByteBuf(value))); - LOG.debug("Parsed IPv6 Router-ID of remote node: {}", builder.getRemoteIpv6RouterId()); - break; - case ADMIN_GROUP: - builder.setAdminGroup(new AdministrativeGroup(value.readUnsignedInt())); - LOG.debug("Parsed Administrative Group {}", builder.getAdminGroup()); - break; - case MAX_BANDWIDTH: - builder.setMaxLinkBandwidth(new Bandwidth(ByteArray.readAllBytes(value))); - LOG.debug("Parsed Max Bandwidth {}", builder.getMaxLinkBandwidth()); - break; - case MAX_RESERVABLE_BANDWIDTH: - builder.setMaxReservableBandwidth(new Bandwidth(ByteArray.readAllBytes(value))); - LOG.debug("Parsed Max Reservable Bandwidth {}", builder.getMaxReservableBandwidth()); - break; - case UNRESERVED_BANDWIDTH: - parseUnreservedBandwidth(value, builder); - break; - case TE_METRIC: - builder.setTeMetric(new TeMetric(ByteArray.bytesToLong(ByteArray.readAllBytes(value)))); - LOG.debug("Parsed Metric {}", builder.getTeMetric()); - break; - case LINK_PROTECTION_TYPE: - builder.setLinkProtection(LinkProtectionType.forValue(value.readShort())); - LOG.debug("Parsed Link Protection Type {}", builder.getLinkProtection()); - break; - case MPLS_PROTOCOL: - final BitArray bits = BitArray.valueOf(value, FLAGS_SIZE); - builder.setMplsProtocol(new MplsProtocolMask(bits.get(LDP_BIT), bits.get(RSVP_BIT))); - LOG.debug("Parsed MPLS Protocols: {}", builder.getMplsProtocol()); - break; - case METRIC: - // length can 3, 2 or 1 - builder.setMetric(new Metric(ByteArray.bytesToLong(ByteArray.readAllBytes(value)))); - LOG.debug("Parsed Metric {}", builder.getMetric()); - break; - case SHARED_RISK_LINK_GROUP: - parseSrlg(value, builder); - break; - case LINK_OPAQUE: - LOG.debug("Parsed Opaque value : {}", ByteBufUtil.hexDump(value)); - break; - case LINK_NAME: - builder.setLinkName(new String(ByteArray.readAllBytes(value), StandardCharsets.US_ASCII)); - LOG.debug("Parsed Link Name : {}", builder.getLinkName()); - break; - case SR_ADJ_ID: - srAdjIds.add(SrLinkAttributesParser.parseAdjacencySegmentIdentifier(value, protocolId)); - LOG.debug("Parsed Adjacency Segment Identifier :{}", srAdjIds.get(srAdjIds.size() - 1)); - break; - case SR_LAN_ADJ_ID: - srLanAdjIds.add(SrLinkAttributesParser.parseLanAdjacencySegmentIdentifier(value, protocolId)); - LOG.debug("Parsed Adjacency Segment Identifier :{}", srLanAdjIds.get(srLanAdjIds.size() - 1)); - break; - case PEER_NODE_SID_CODE: - builder.setPeerNodeSid(new PeerNodeSidBuilder(SrLinkAttributesParser.parseEpeAdjacencySegmentIdentifier(value)).build()); - LOG.debug("Parsed Peer Segment Identifier :{}", builder.getPeerNodeSid()); - break; - case PEER_ADJ_SID_CODE: - builder.setPeerAdjSid(new PeerAdjSidBuilder(SrLinkAttributesParser.parseEpeAdjacencySegmentIdentifier(value)).build()); - LOG.debug("Parsed Peer Segment Identifier :{}", builder.getPeerAdjSid()); - break; - case PEER_SET_SID_CODE: - peerSetSids.add(new PeerSetSidsBuilder(SrLinkAttributesParser.parseEpeAdjacencySegmentIdentifier(value)).build()); - LOG.debug("Parsed Peer Set Sid :{}", peerSetSids.get(peerSetSids.size() - 1)); - break; - // Performance Metrics - case LINK_DELAY: - builder.setLinkDelay(new Delay(value.readUnsignedInt())); - LOG.debug("Parsed Link Delay {}", builder.getLinkDelay()); - break; - case LINK_MIN_MAX_DELAY: - builder.setLinkMinMaxDelay(new LinkMinMaxDelayBuilder().setMinDelay(new Delay(value.readUnsignedInt())) + case TlvUtil.LOCAL_IPV4_ROUTER_ID: + builder.setLocalIpv4RouterId(new Ipv4RouterIdentifier(Ipv4Util.addressForByteBuf(value))); + LOG.debug("Parsed IPv4 Router-ID of local node: {}", builder.getLocalIpv4RouterId()); + break; + case TlvUtil.LOCAL_IPV6_ROUTER_ID: + builder.setLocalIpv6RouterId(new Ipv6RouterIdentifier(Ipv6Util.addressForByteBuf(value))); + LOG.debug("Parsed IPv6 Router-ID of local node: {}", builder.getLocalIpv6RouterId()); + break; + case REMOTE_IPV4_ROUTER_ID: + builder.setRemoteIpv4RouterId(new Ipv4RouterIdentifier(Ipv4Util.addressForByteBuf(value))); + LOG.debug("Parsed IPv4 Router-ID of remote node: {}", builder.getRemoteIpv4RouterId()); + break; + case REMOTE_IPV6_ROUTER_ID: + builder.setRemoteIpv6RouterId(new Ipv6RouterIdentifier(Ipv6Util.addressForByteBuf(value))); + LOG.debug("Parsed IPv6 Router-ID of remote node: {}", builder.getRemoteIpv6RouterId()); + break; + case ADMIN_GROUP: + builder.setAdminGroup(new AdministrativeGroup(value.readUnsignedInt())); + LOG.debug("Parsed Administrative Group {}", builder.getAdminGroup()); + break; + case MAX_BANDWIDTH: + builder.setMaxLinkBandwidth(new Bandwidth(ByteArray.readAllBytes(value))); + LOG.debug("Parsed Max Bandwidth {}", builder.getMaxLinkBandwidth()); + break; + case MAX_RESERVABLE_BANDWIDTH: + builder.setMaxReservableBandwidth(new Bandwidth(ByteArray.readAllBytes(value))); + LOG.debug("Parsed Max Reservable Bandwidth {}", builder.getMaxReservableBandwidth()); + break; + case UNRESERVED_BANDWIDTH: + parseUnreservedBandwidth(value, builder); + break; + case TE_METRIC: + builder.setTeMetric(new TeMetric(ByteArray.bytesToLong(ByteArray.readAllBytes(value)))); + LOG.debug("Parsed Metric {}", builder.getTeMetric()); + break; + case LINK_PROTECTION_TYPE: + builder.setLinkProtection(LinkProtectionType.forValue(value.readShort())); + LOG.debug("Parsed Link Protection Type {}", builder.getLinkProtection()); + break; + case MPLS_PROTOCOL: + final BitArray bits = BitArray.valueOf(value, FLAGS_SIZE); + builder.setMplsProtocol(new MplsProtocolMask(bits.get(LDP_BIT), bits.get(RSVP_BIT))); + LOG.debug("Parsed MPLS Protocols: {}", builder.getMplsProtocol()); + break; + case METRIC: + // length can 3, 2 or 1 + builder.setMetric(new Metric(ByteArray.bytesToLong(ByteArray.readAllBytes(value)))); + LOG.debug("Parsed Metric {}", builder.getMetric()); + break; + case SHARED_RISK_LINK_GROUP: + parseSrlg(value, builder); + break; + case LINK_OPAQUE: + LOG.debug("Parsed Opaque value : {}", ByteBufUtil.hexDump(value)); + break; + case LINK_NAME: + builder.setLinkName(new String(ByteArray.readAllBytes(value), StandardCharsets.US_ASCII)); + LOG.debug("Parsed Link Name : {}", builder.getLinkName()); + break; + case SR_ADJ_ID: + srAdjIds.add(SrLinkAttributesParser.parseAdjacencySegmentIdentifier(value, protocolId)); + LOG.debug("Parsed Adjacency Segment Identifier :{}", srAdjIds.get(srAdjIds.size() - 1)); + break; + case SR_LAN_ADJ_ID: + srLanAdjIds.add(SrLinkAttributesParser.parseLanAdjacencySegmentIdentifier(value, protocolId)); + LOG.debug("Parsed Adjacency Segment Identifier :{}", srLanAdjIds.get(srLanAdjIds.size() - 1)); + break; + case PEER_NODE_SID_CODE: + builder.setPeerNodeSid(new PeerNodeSidBuilder( + SrLinkAttributesParser.parseEpeAdjacencySegmentIdentifier(value)).build()); + LOG.debug("Parsed Peer Segment Identifier :{}", builder.getPeerNodeSid()); + break; + case PEER_ADJ_SID_CODE: + builder.setPeerAdjSid(new PeerAdjSidBuilder( + SrLinkAttributesParser.parseEpeAdjacencySegmentIdentifier(value)).build()); + LOG.debug("Parsed Peer Segment Identifier :{}", builder.getPeerAdjSid()); + break; + case PEER_SET_SID_CODE: + peerSetSids.add(new PeerSetSidsBuilder( + SrLinkAttributesParser.parseEpeAdjacencySegmentIdentifier(value)).build()); + LOG.debug("Parsed Peer Set Sid :{}", peerSetSids.get(peerSetSids.size() - 1)); + break; + // Performance Metrics + case LINK_DELAY: + builder.setLinkDelay(new Delay(value.readUnsignedInt())); + LOG.debug("Parsed Link Delay {}", builder.getLinkDelay()); + break; + case LINK_MIN_MAX_DELAY: + builder.setLinkMinMaxDelay(new LinkMinMaxDelayBuilder() + .setMinDelay(new Delay(value.readUnsignedInt())) .setMaxDelay(new Delay(value.readUnsignedInt())).build()); - LOG.debug("Parsed Link Min/Max Delay {}", builder.getLinkMinMaxDelay()); - break; - case DELAY_VARIATION: - builder.setDelayVariation(new Delay(value.readUnsignedInt())); - LOG.debug("Parsed Delay Variation {}", builder.getDelayVariation()); - break; - case LINK_LOSS: - builder.setLinkLoss(new Loss(value.readUnsignedInt())); - LOG.debug("Parsed Link Loss {}", builder.getLinkLoss()); - break; - case RESIDUAL_BANDWIDTH: - builder.setResidualBandwidth(new Bandwidth(ByteArray.readAllBytes(value))); - LOG.debug("Parsed Residual Bandwidth {}", builder.getResidualBandwidth()); - break; - case AVAILABLE_BANDWIDTH: - builder.setAvailableBandwidth(new Bandwidth(ByteArray.readAllBytes(value))); - LOG.debug("Parsed Available Bandwidth {}", builder.getAvailableBandwidth()); - break; - case UTILIZED_BANDWIDTH: - builder.setUtilizedBandwidth(new Bandwidth(ByteArray.readAllBytes(value))); - LOG.debug("Parsed Utilized Bandwidth {}", builder.getUtilizedBandwidth()); - break; - default: - LOG.warn("TLV {} is not a valid link attribute, ignoring it", key); + LOG.debug("Parsed Link Min/Max Delay {}", builder.getLinkMinMaxDelay()); + break; + case DELAY_VARIATION: + builder.setDelayVariation(new Delay(value.readUnsignedInt())); + LOG.debug("Parsed Delay Variation {}", builder.getDelayVariation()); + break; + case LINK_LOSS: + builder.setLinkLoss(new Loss(value.readUnsignedInt())); + LOG.debug("Parsed Link Loss {}", builder.getLinkLoss()); + break; + case RESIDUAL_BANDWIDTH: + builder.setResidualBandwidth(new Bandwidth(ByteArray.readAllBytes(value))); + LOG.debug("Parsed Residual Bandwidth {}", builder.getResidualBandwidth()); + break; + case AVAILABLE_BANDWIDTH: + builder.setAvailableBandwidth(new Bandwidth(ByteArray.readAllBytes(value))); + LOG.debug("Parsed Available Bandwidth {}", builder.getAvailableBandwidth()); + break; + case UTILIZED_BANDWIDTH: + builder.setUtilizedBandwidth(new Bandwidth(ByteArray.readAllBytes(value))); + LOG.debug("Parsed Utilized Bandwidth {}", builder.getUtilizedBandwidth()); + break; + default: + LOG.warn("TLV {} is not a valid link attribute, ignoring it", key); } } if (!srAdjIds.isEmpty()) { @@ -251,10 +256,12 @@ public final class LinkAttributesParser { } private static void parseUnreservedBandwidth(final ByteBuf value, final LinkAttributesBuilder builder) { - final List unreservedBandwidth = new ArrayList<>(UNRESERVED_BW_COUNT); + final List unreservedBandwidth = new ArrayList<>(UNRESERVED_BW_COUNT); for (int i = 0; i < UNRESERVED_BW_COUNT; i++) { final ByteBuf v = value.readSlice(BANDWIDTH_LENGTH); - unreservedBandwidth.add(new UnreservedBandwidthBuilder().setBandwidth(new Bandwidth(ByteArray.readAllBytes(v))).setPriority((short) i).build()); + unreservedBandwidth.add(new UnreservedBandwidthBuilder().setBandwidth( + new Bandwidth(ByteArray.readAllBytes(v))).setPriority((short) i).build()); } builder.setUnreservedBandwidth(unreservedBandwidth); LOG.debug("Parsed Unreserved Bandwidth {}", builder.getUnreservedBandwidth()); @@ -279,33 +286,57 @@ public final class LinkAttributesParser { static void serializeLinkAttributes(final LinkAttributesCase linkAttributesCase, final ByteBuf output) { final LinkAttributes linkAttributes = linkAttributesCase.getLinkAttributes(); LOG.trace("Started serializing Link Attributes"); - ifPresentApply(linkAttributes.getLocalIpv4RouterId(), value -> TlvUtil.writeTLV(TlvUtil.LOCAL_IPV4_ROUTER_ID, Ipv4Util.byteBufForAddress((Ipv4Address) value), output)); - ifPresentApply(linkAttributes.getLocalIpv6RouterId(), value -> TlvUtil.writeTLV(TlvUtil.LOCAL_IPV6_ROUTER_ID, Ipv6Util.byteBufForAddress((Ipv6Address) value), output)); - ifPresentApply(linkAttributes.getRemoteIpv4RouterId(), value -> TlvUtil.writeTLV(REMOTE_IPV4_ROUTER_ID, Ipv4Util.byteBufForAddress((Ipv4Address) value), output)); - ifPresentApply(linkAttributes.getRemoteIpv6RouterId(), value -> TlvUtil.writeTLV(REMOTE_IPV6_ROUTER_ID, Ipv6Util.byteBufForAddress((Ipv6Address) value), output)); - ifPresentApply(linkAttributes.getAdminGroup(), value -> TlvUtil.writeTLV(ADMIN_GROUP, Unpooled.copyInt((((AdministrativeGroup) value).getValue()).intValue()), output)); - ifPresentApply(linkAttributes.getMaxLinkBandwidth(), value -> TlvUtil.writeTLV(MAX_BANDWIDTH, Unpooled.wrappedBuffer(((Bandwidth) value).getValue()), output)); - ifPresentApply(linkAttributes.getMaxReservableBandwidth(), value -> TlvUtil.writeTLV(MAX_RESERVABLE_BANDWIDTH, Unpooled.wrappedBuffer(((Bandwidth) value).getValue()), output)); + ifPresentApply(linkAttributes.getLocalIpv4RouterId(), value -> TlvUtil.writeTLV(TlvUtil.LOCAL_IPV4_ROUTER_ID, + Ipv4Util.byteBufForAddress((Ipv4Address) value), output)); + ifPresentApply(linkAttributes.getLocalIpv6RouterId(), value -> TlvUtil.writeTLV(TlvUtil.LOCAL_IPV6_ROUTER_ID, + Ipv6Util.byteBufForAddress((Ipv6Address) value), output)); + ifPresentApply(linkAttributes.getRemoteIpv4RouterId(), value -> TlvUtil.writeTLV(REMOTE_IPV4_ROUTER_ID, + Ipv4Util.byteBufForAddress((Ipv4Address) value), output)); + ifPresentApply(linkAttributes.getRemoteIpv6RouterId(), value -> TlvUtil.writeTLV(REMOTE_IPV6_ROUTER_ID, + Ipv6Util.byteBufForAddress((Ipv6Address) value), output)); + ifPresentApply(linkAttributes.getAdminGroup(), value -> TlvUtil.writeTLV(ADMIN_GROUP, + Unpooled.copyInt(((AdministrativeGroup) value).getValue().intValue()), output)); + ifPresentApply(linkAttributes.getMaxLinkBandwidth(), value -> TlvUtil.writeTLV(MAX_BANDWIDTH, + Unpooled.wrappedBuffer(((Bandwidth) value).getValue()), output)); + ifPresentApply(linkAttributes.getMaxReservableBandwidth(), value -> TlvUtil.writeTLV(MAX_RESERVABLE_BANDWIDTH, + Unpooled.wrappedBuffer(((Bandwidth) value).getValue()), output)); serializeUnreservedBw(linkAttributes.getUnreservedBandwidth(), output); - ifPresentApply(linkAttributes.getTeMetric(), value -> TlvUtil.writeTLV(TE_METRIC, Unpooled.copyLong(((TeMetric) value).getValue()), output)); - ifPresentApply(linkAttributes.getLinkProtection(), value -> TlvUtil.writeTLV(LINK_PROTECTION_TYPE, Unpooled.copyShort(((LinkProtectionType) value).getIntValue()), output)); + ifPresentApply(linkAttributes.getTeMetric(), value -> TlvUtil.writeTLV(TE_METRIC, + Unpooled.copyLong(((TeMetric) value).getValue()), output)); + ifPresentApply(linkAttributes.getLinkProtection(), value -> TlvUtil.writeTLV(LINK_PROTECTION_TYPE, + Unpooled.copyShort(((LinkProtectionType) value).getIntValue()), output)); serializeMplsProtocolMask(linkAttributes.getMplsProtocol(), output); - ifPresentApply(linkAttributes.getMetric(), value -> TlvUtil.writeTLV(METRIC, Unpooled.copyMedium(((Metric) value).getValue().intValue()), output)); + ifPresentApply(linkAttributes.getMetric(), value -> TlvUtil.writeTLV(METRIC, + Unpooled.copyMedium(((Metric) value).getValue().intValue()), output)); serializeSrlg(linkAttributes.getSharedRiskLinkGroups(), output); - ifPresentApply(linkAttributes.getLinkName(), value -> TlvUtil.writeTLV(LINK_NAME, Unpooled.wrappedBuffer(StandardCharsets.UTF_8.encode((String) value)), output)); - ifPresentApply(linkAttributes.getSrAdjIds(), value -> SrLinkAttributesParser.serializeAdjacencySegmentIdentifiers((List) value, SR_ADJ_ID, output)); - ifPresentApply(linkAttributes.getSrLanAdjIds(), value -> SrLinkAttributesParser.serializeLanAdjacencySegmentIdentifiers((List) value, output)); - ifPresentApply(linkAttributes.getPeerNodeSid(), value -> TlvUtil.writeTLV(PEER_NODE_SID_CODE, SrLinkAttributesParser.serializeAdjacencySegmentIdentifier((PeerNodeSid) value), output)); - ifPresentApply(linkAttributes.getPeerAdjSid(), value -> TlvUtil.writeTLV(PEER_ADJ_SID_CODE, SrLinkAttributesParser.serializeAdjacencySegmentIdentifier((PeerAdjSid) value), output)); - ifPresentApply(linkAttributes.getPeerSetSids(), value -> SrLinkAttributesParser.serializeAdjacencySegmentIdentifiers((List) value, PEER_SET_SID_CODE, output)); + ifPresentApply(linkAttributes.getLinkName(), value -> TlvUtil.writeTLV(LINK_NAME, + Unpooled.wrappedBuffer(StandardCharsets.UTF_8.encode((String) value)), output)); + ifPresentApply(linkAttributes.getSrAdjIds(), + value -> SrLinkAttributesParser.serializeAdjacencySegmentIdentifiers((List) value, SR_ADJ_ID, + output)); + ifPresentApply(linkAttributes.getSrLanAdjIds(), + value -> SrLinkAttributesParser.serializeLanAdjacencySegmentIdentifiers((List) value, output)); + ifPresentApply(linkAttributes.getPeerNodeSid(), value -> TlvUtil.writeTLV(PEER_NODE_SID_CODE, + SrLinkAttributesParser.serializeAdjacencySegmentIdentifier((PeerNodeSid) value), output)); + ifPresentApply(linkAttributes.getPeerAdjSid(), value -> TlvUtil.writeTLV(PEER_ADJ_SID_CODE, + SrLinkAttributesParser.serializeAdjacencySegmentIdentifier((PeerAdjSid) value), output)); + ifPresentApply(linkAttributes.getPeerSetSids(), + value -> SrLinkAttributesParser.serializeAdjacencySegmentIdentifiers((List) value, + PEER_SET_SID_CODE, output)); // Performance Metrics - ifPresentApply(linkAttributes.getLinkDelay(), value -> TlvUtil.writeTLV(LINK_DELAY, Unpooled.copyInt((((Delay) value).getValue()).intValue()), output)); + ifPresentApply(linkAttributes.getLinkDelay(), value -> TlvUtil.writeTLV(LINK_DELAY, + Unpooled.copyInt(((Delay) value).getValue().intValue()), output)); serializeLinkMinMaxDelay(linkAttributes.getLinkMinMaxDelay(), output); - ifPresentApply(linkAttributes.getDelayVariation(), value -> TlvUtil.writeTLV(DELAY_VARIATION, Unpooled.copyInt((((Delay) value).getValue()).intValue()), output)); - ifPresentApply(linkAttributes.getLinkLoss(), value -> TlvUtil.writeTLV(LINK_LOSS, Unpooled.copyInt((((Loss) value).getValue()).intValue()), output)); - ifPresentApply(linkAttributes.getResidualBandwidth(), value -> TlvUtil.writeTLV(RESIDUAL_BANDWIDTH, Unpooled.wrappedBuffer(((Bandwidth) value).getValue()), output)); - ifPresentApply(linkAttributes.getAvailableBandwidth(), value -> TlvUtil.writeTLV(AVAILABLE_BANDWIDTH, Unpooled.wrappedBuffer(((Bandwidth) value).getValue()), output)); - ifPresentApply(linkAttributes.getUtilizedBandwidth(), value -> TlvUtil.writeTLV(UTILIZED_BANDWIDTH, Unpooled.wrappedBuffer(((Bandwidth) value).getValue()), output)); + ifPresentApply(linkAttributes.getDelayVariation(), value -> TlvUtil.writeTLV(DELAY_VARIATION, + Unpooled.copyInt(((Delay) value).getValue().intValue()), output)); + ifPresentApply(linkAttributes.getLinkLoss(), value -> TlvUtil.writeTLV(LINK_LOSS, + Unpooled.copyInt(((Loss) value).getValue().intValue()), output)); + ifPresentApply(linkAttributes.getResidualBandwidth(), value -> TlvUtil.writeTLV(RESIDUAL_BANDWIDTH, + Unpooled.wrappedBuffer(((Bandwidth) value).getValue()), output)); + ifPresentApply(linkAttributes.getAvailableBandwidth(), value -> TlvUtil.writeTLV(AVAILABLE_BANDWIDTH, + Unpooled.wrappedBuffer(((Bandwidth) value).getValue()), output)); + ifPresentApply(linkAttributes.getUtilizedBandwidth(), value -> TlvUtil.writeTLV(UTILIZED_BANDWIDTH, + Unpooled.wrappedBuffer(((Bandwidth) value).getValue()), output)); LOG.trace("Finished serializing Link Attributes"); } @@ -330,7 +361,8 @@ public final class LinkAttributesParser { } } - private static void serializeMplsProtocolMask(final MplsProtocolMask mplsProtocolMask, final ByteBuf byteAggregator) { + private static void serializeMplsProtocolMask(final MplsProtocolMask mplsProtocolMask, + final ByteBuf byteAggregator) { if (mplsProtocolMask != null) { final ByteBuf mplsProtocolMaskBuf = Unpooled.buffer(1); final BitArray mask = new BitArray(FLAGS_SIZE); diff --git a/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/attribute/LinkstateAttributeParser.java b/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/attribute/LinkstateAttributeParser.java index c0af0f37e9..02adbb1887 100644 --- a/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/attribute/LinkstateAttributeParser.java +++ b/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/attribute/LinkstateAttributeParser.java @@ -92,16 +92,20 @@ public final class LinkstateAttributeParser extends AbstractAttributeParser impl } final ObjectType nlriType = lsDestination.getObjectType(); final ProtocolId protocolId = lsDestination.getProtocolId(); - final Attributes1 a = new Attributes1Builder().setLinkStateAttribute(parseLinkState(nlriType, protocolId, buffer)).build(); + final Attributes1 a = new Attributes1Builder().setLinkStateAttribute( + parseLinkState(nlriType, protocolId, buffer)).build(); builder.addAugmentation(Attributes1.class, a); } private static CLinkstateDestination getNlriType(final AttributesBuilder pab) { - final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.Attributes1 mpr = pab.augmentation(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.Attributes1.class); + final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329 + .Attributes1 mpr = pab.augmentation(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp + .multiprotocol.rev180329.Attributes1.class); if (mpr != null && mpr.getMpReachNlri() != null) { final DestinationType dt = mpr.getMpReachNlri().getAdvertizedRoutes().getDestinationType(); if (dt instanceof DestinationLinkstateCase) { - for (final CLinkstateDestination d : ((DestinationLinkstateCase) dt).getDestinationLinkstate().getCLinkstateDestination()) { + for (final CLinkstateDestination d : ((DestinationLinkstateCase) dt).getDestinationLinkstate() + .getCLinkstateDestination()) { return d; } } @@ -109,9 +113,11 @@ public final class LinkstateAttributeParser extends AbstractAttributeParser impl final Attributes2 mpu = pab.augmentation(Attributes2.class); if (mpu != null && mpu.getMpUnreachNlri() != null) { final DestinationType dt = mpu.getMpUnreachNlri().getWithdrawnRoutes().getDestinationType(); - if (dt instanceof org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationLinkstateCase) { - for(final CLinkstateDestination d :((org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.update.attributes.mp.unreach.nlri.withdrawn. - routes.destination.type.DestinationLinkstateCase) dt).getDestinationLinkstate().getCLinkstateDestination()) { + if (dt instanceof org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329 + .update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationLinkstateCase) { + for (final CLinkstateDestination d : ((org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang + .bgp.linkstate.rev180329.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type + .DestinationLinkstateCase) dt).getDestinationLinkstate().getCLinkstateDestination()) { return d; } } @@ -119,8 +125,8 @@ public final class LinkstateAttributeParser extends AbstractAttributeParser impl return null; } - private LinkStateAttribute parseLinkState(final ObjectType nlri, final ProtocolId protocolId, final ByteBuf buffer) throws BGPParsingException { - + private LinkStateAttribute parseLinkState(final ObjectType nlri, final ProtocolId protocolId, final ByteBuf buffer) + throws BGPParsingException { if (nlri instanceof PrefixCase) { return PrefixAttributesParser.parsePrefixAttributes(getAttributesMap(buffer), protocolId); } else if (nlri instanceof LinkCase) { @@ -157,7 +163,8 @@ public final class LinkstateAttributeParser extends AbstractAttributeParser impl } else if (linkState instanceof PrefixAttributesCase) { PrefixAttributesParser.serializePrefixAttributes((PrefixAttributesCase) linkState, lsBuffer); } else if (linkState instanceof TeLspAttributesCase) { - TeLspAttributesParser.serializeLspAttributes(this.rsvpTeObjectRegistry, (TeLspAttributesCase) linkState, lsBuffer); + TeLspAttributesParser.serializeLspAttributes(this.rsvpTeObjectRegistry, (TeLspAttributesCase) linkState, + lsBuffer); byteAggregator.writeBytes(lsBuffer); return; } diff --git a/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/attribute/NodeAttributesParser.java b/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/attribute/NodeAttributesParser.java index 70c5cb46a7..125e0a2b76 100644 --- a/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/attribute/NodeAttributesParser.java +++ b/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/attribute/NodeAttributesParser.java @@ -12,10 +12,10 @@ import com.google.common.collect.Multimap; import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBufUtil; import io.netty.buffer.Unpooled; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.List; import java.util.Map.Entry; -import java.nio.charset.StandardCharsets; import org.opendaylight.protocol.bgp.linkstate.impl.attribute.sr.SrNodeAttributesParser; import org.opendaylight.protocol.bgp.linkstate.spi.TlvUtil; import org.opendaylight.protocol.util.BitArray; @@ -58,9 +58,9 @@ public final class NodeAttributesParser { /* Segment routing TLVs */ private static final int SR_CAPABILITIES = 1034; private static final int SR_ALGORITHMS = 1035; - + private NodeAttributesParser() { - throw new UnsupportedOperationException(); + } /** @@ -70,7 +70,8 @@ public final class NodeAttributesParser { * @param protocolId to differentiate parsing methods * @return {@link LinkStateAttribute} */ - static LinkStateAttribute parseNodeAttributes(final Multimap attributes, final ProtocolId protocolId) { + static LinkStateAttribute parseNodeAttributes(final Multimap attributes, + final ProtocolId protocolId) { final List topologyMembership = new ArrayList<>(); final List areaMembership = new ArrayList<>(); final NodeAttributesBuilder builder = new NodeAttributesBuilder(); @@ -79,48 +80,48 @@ public final class NodeAttributesParser { final ByteBuf value = entry.getValue(); LOG.trace("Node attribute TLV {}", key); switch (key) { - case TlvUtil.MULTI_TOPOLOGY_ID: - parseTopologyId(topologyMembership, value); - break; - case NODE_FLAG_BITS: - parseNodeFlags(value, builder); - break; - case NODE_OPAQUE: - if (LOG.isDebugEnabled()) { - LOG.debug("Ignoring opaque value: {}.", ByteBufUtil.hexDump(value)); - } - break; - case DYNAMIC_HOSTNAME: - builder.setDynamicHostname(new String(ByteArray.readAllBytes(value), StandardCharsets.US_ASCII)); - LOG.debug("Parsed Node Name {}", builder.getDynamicHostname()); - break; - case ISIS_AREA_IDENTIFIER: - final IsisAreaIdentifier ai = new IsisAreaIdentifier(ByteArray.readAllBytes(value)); - areaMembership.add(ai); - LOG.debug("Parsed AreaIdentifier {}", ai); - break; - case TlvUtil.LOCAL_IPV4_ROUTER_ID: - final Ipv4RouterIdentifier ip4 = new Ipv4RouterIdentifier(Ipv4Util.addressForByteBuf(value)); - builder.setIpv4RouterId(ip4); - LOG.debug("Parsed IPv4 Router Identifier {}", ip4); - break; - case TlvUtil.LOCAL_IPV6_ROUTER_ID: - final Ipv6RouterIdentifier ip6 = new Ipv6RouterIdentifier(Ipv6Util.addressForByteBuf(value)); - builder.setIpv6RouterId(ip6); - LOG.debug("Parsed IPv6 Router Identifier {}", ip6); - break; - case SR_CAPABILITIES: - final SrCapabilities caps = SrNodeAttributesParser.parseSrCapabilities(value, protocolId); - builder.setSrCapabilities(caps); - LOG.debug("Parsed SR Capabilities {}", caps); - break; - case SR_ALGORITHMS: - final SrAlgorithm algs = SrNodeAttributesParser.parseSrAlgorithms(value); - builder.setSrAlgorithm(algs); - LOG.debug("Parsed SR Algorithms {}", algs); - break; - default: - LOG.warn("TLV {} is not a valid node attribute, ignoring it", key); + case TlvUtil.MULTI_TOPOLOGY_ID: + parseTopologyId(topologyMembership, value); + break; + case NODE_FLAG_BITS: + parseNodeFlags(value, builder); + break; + case NODE_OPAQUE: + if (LOG.isDebugEnabled()) { + LOG.debug("Ignoring opaque value: {}.", ByteBufUtil.hexDump(value)); + } + break; + case DYNAMIC_HOSTNAME: + builder.setDynamicHostname(new String(ByteArray.readAllBytes(value), StandardCharsets.US_ASCII)); + LOG.debug("Parsed Node Name {}", builder.getDynamicHostname()); + break; + case ISIS_AREA_IDENTIFIER: + final IsisAreaIdentifier ai = new IsisAreaIdentifier(ByteArray.readAllBytes(value)); + areaMembership.add(ai); + LOG.debug("Parsed AreaIdentifier {}", ai); + break; + case TlvUtil.LOCAL_IPV4_ROUTER_ID: + final Ipv4RouterIdentifier ip4 = new Ipv4RouterIdentifier(Ipv4Util.addressForByteBuf(value)); + builder.setIpv4RouterId(ip4); + LOG.debug("Parsed IPv4 Router Identifier {}", ip4); + break; + case TlvUtil.LOCAL_IPV6_ROUTER_ID: + final Ipv6RouterIdentifier ip6 = new Ipv6RouterIdentifier(Ipv6Util.addressForByteBuf(value)); + builder.setIpv6RouterId(ip6); + LOG.debug("Parsed IPv6 Router Identifier {}", ip6); + break; + case SR_CAPABILITIES: + final SrCapabilities caps = SrNodeAttributesParser.parseSrCapabilities(value, protocolId); + builder.setSrCapabilities(caps); + LOG.debug("Parsed SR Capabilities {}", caps); + break; + case SR_ALGORITHMS: + final SrAlgorithm algs = SrNodeAttributesParser.parseSrAlgorithms(value); + builder.setSrAlgorithm(algs); + LOG.debug("Parsed SR Algorithms {}", algs); + break; + default: + LOG.warn("TLV {} is not a valid node attribute, ignoring it", key); } } LOG.trace("Finished parsing Node Attributes."); @@ -131,15 +132,16 @@ public final class NodeAttributesParser { private static void parseNodeFlags(final ByteBuf value, final NodeAttributesBuilder builder) { final BitArray flags = BitArray.valueOf(value, FLAGS_SIZE); - builder.setNodeFlags(new NodeFlagBits(flags.get(OVERLOAD_BIT), flags.get(ATTACHED_BIT), flags.get - (EXTERNAL_BIT), flags.get(ABBR_BIT), flags.get(ROUTER_BIT), flags.get(V6_BIT))); + builder.setNodeFlags(new NodeFlagBits(flags.get(OVERLOAD_BIT), flags.get(ATTACHED_BIT), flags.get(EXTERNAL_BIT), + flags.get(ABBR_BIT), flags.get(ROUTER_BIT), flags.get(V6_BIT))); LOG.debug("Parsed Overload bit: {}, attached bit: {}, external bit: {}, area border router: {}.", flags.get(OVERLOAD_BIT), flags.get(ATTACHED_BIT), flags.get(EXTERNAL_BIT), flags.get(ABBR_BIT)); } private static void parseTopologyId(final List topologyMembership, final ByteBuf value) { while (value.isReadable()) { - final TopologyIdentifier topId = new TopologyIdentifier(value.readUnsignedShort() & TlvUtil.TOPOLOGY_ID_OFFSET); + final TopologyIdentifier topId = new TopologyIdentifier( + value.readUnsignedShort() & TlvUtil.TOPOLOGY_ID_OFFSET); topologyMembership.add(topId); LOG.debug("Parsed Topology Identifier: {}", topId); } @@ -151,19 +153,23 @@ public final class NodeAttributesParser { serializeTopologyId(nodeAttributes.getTopologyIdentifier(), byteAggregator); serializeNodeFlagBits(nodeAttributes.getNodeFlags(), byteAggregator); if (nodeAttributes.getDynamicHostname() != null) { - TlvUtil.writeTLV(DYNAMIC_HOSTNAME, Unpooled.wrappedBuffer(StandardCharsets.UTF_8.encode(nodeAttributes.getDynamicHostname())), byteAggregator); + TlvUtil.writeTLV(DYNAMIC_HOSTNAME, Unpooled.wrappedBuffer(StandardCharsets.UTF_8.encode( + nodeAttributes.getDynamicHostname())), byteAggregator); } final List isisList = nodeAttributes.getIsisAreaId(); if (isisList != null) { for (final IsisAreaIdentifier isisAreaIdentifier : isisList) { - TlvUtil.writeTLV(ISIS_AREA_IDENTIFIER, Unpooled.wrappedBuffer(isisAreaIdentifier.getValue()), byteAggregator); + TlvUtil.writeTLV(ISIS_AREA_IDENTIFIER, Unpooled.wrappedBuffer(isisAreaIdentifier.getValue()), + byteAggregator); } } if (nodeAttributes.getIpv4RouterId() != null) { - TlvUtil.writeTLV(TlvUtil.LOCAL_IPV4_ROUTER_ID, Ipv4Util.byteBufForAddress(nodeAttributes.getIpv4RouterId()), byteAggregator); + TlvUtil.writeTLV(TlvUtil.LOCAL_IPV4_ROUTER_ID, Ipv4Util.byteBufForAddress(nodeAttributes.getIpv4RouterId()), + byteAggregator); } if (nodeAttributes.getIpv6RouterId() != null) { - TlvUtil.writeTLV(TlvUtil.LOCAL_IPV6_ROUTER_ID, Ipv6Util.byteBufForAddress(nodeAttributes.getIpv6RouterId()), byteAggregator); + TlvUtil.writeTLV(TlvUtil.LOCAL_IPV6_ROUTER_ID, Ipv6Util.byteBufForAddress(nodeAttributes.getIpv6RouterId()), + byteAggregator); } if (nodeAttributes.getSrCapabilities() != null) { final ByteBuf capBuffer = Unpooled.buffer(); diff --git a/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/attribute/PrefixAttributesParser.java b/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/attribute/PrefixAttributesParser.java index aac5138921..96c79a2ce5 100644 --- a/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/attribute/PrefixAttributesParser.java +++ b/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/attribute/PrefixAttributesParser.java @@ -70,7 +70,7 @@ public final class PrefixAttributesParser { private static final int RANGE = 1159; private PrefixAttributesParser() { - throw new UnsupportedOperationException(); + } /** @@ -80,7 +80,8 @@ public final class PrefixAttributesParser { * @param protocolId to differentiate parsing methods * @return {@link LinkStateAttribute} */ - static LinkStateAttribute parsePrefixAttributes(final Multimap attributes, final ProtocolId protocolId) { + static LinkStateAttribute parsePrefixAttributes(final Multimap attributes, + final ProtocolId protocolId) { final PrefixAttributesBuilder builder = new PrefixAttributesBuilder(); final List routeTags = new ArrayList<>(); final List exRouteTags = new ArrayList<>(); @@ -96,64 +97,69 @@ public final class PrefixAttributesParser { return new PrefixAttributesCaseBuilder().setPrefixAttributes(builder.build()).build(); } - private static void parseAttribute(final int key, final ByteBuf value, final ProtocolId protocolId, final PrefixAttributesBuilder builder, final List routeTags, final List exRouteTags) { + private static void parseAttribute(final int key, final ByteBuf value, final ProtocolId protocolId, + final PrefixAttributesBuilder builder, final List routeTags, + final List exRouteTags) { switch (key) { - case IGP_FLAGS: - parseIgpFags(builder, value); - break; - case ROUTE_TAG: - parseRouteTags(routeTags, value); - break; - case EXTENDED_ROUTE_TAG: - parseExtendedRouteTags(exRouteTags, value); - break; - case PREFIX_METRIC: - final IgpMetric metric = new IgpMetric(value.readUnsignedInt()); - builder.setPrefixMetric(metric); - LOG.debug("Parsed Metric: {}", metric); - break; - case FORWARDING_ADDRESS: - final IpAddress fwdAddress = parseForwardingAddress(value); - builder.setOspfForwardingAddress(fwdAddress); - LOG.debug("Parsed FWD Address: {}", fwdAddress); - break; - case PREFIX_OPAQUE: - if (LOG.isDebugEnabled()) { - LOG.debug("Parsed Opaque value: {}, not preserving it", ByteBufUtil.hexDump(value)); - } - break; - case PREFIX_SID: - final SrPrefix prefix = SrPrefixAttributesParser.parseSrPrefix(value, protocolId); - builder.setSrPrefix(prefix); - LOG.debug("Parsed SR Prefix: {}", prefix); - break; - case IPV6_PREFIX_SID: - final Ipv6SrPrefix ipv6Prefix = Ipv6SrPrefixAttributesParser.parseSrIpv6Prefix(value); - builder.setIpv6SrPrefix(ipv6Prefix); - LOG.debug("Parsed Ipv6 SR Prefix: {}", ipv6Prefix); - break; - case RANGE: - final SrRange range = RangeTlvParser.parseSrRange(value, protocolId); - builder.setSrRange(range); - LOG.debug("Parsed SR Range: {}", range); - break; - case BINDING_SID: - parseBindingSid(builder, value, protocolId); - break; - default: - LOG.warn("TLV {} is not a valid prefix attribute, ignoring it", key); + case IGP_FLAGS: + parseIgpFags(builder, value); + break; + case ROUTE_TAG: + parseRouteTags(routeTags, value); + break; + case EXTENDED_ROUTE_TAG: + parseExtendedRouteTags(exRouteTags, value); + break; + case PREFIX_METRIC: + final IgpMetric metric = new IgpMetric(value.readUnsignedInt()); + builder.setPrefixMetric(metric); + LOG.debug("Parsed Metric: {}", metric); + break; + case FORWARDING_ADDRESS: + final IpAddress fwdAddress = parseForwardingAddress(value); + builder.setOspfForwardingAddress(fwdAddress); + LOG.debug("Parsed FWD Address: {}", fwdAddress); + break; + case PREFIX_OPAQUE: + if (LOG.isDebugEnabled()) { + LOG.debug("Parsed Opaque value: {}, not preserving it", ByteBufUtil.hexDump(value)); + } + break; + case PREFIX_SID: + final SrPrefix prefix = SrPrefixAttributesParser.parseSrPrefix(value, protocolId); + builder.setSrPrefix(prefix); + LOG.debug("Parsed SR Prefix: {}", prefix); + break; + case IPV6_PREFIX_SID: + final Ipv6SrPrefix ipv6Prefix = Ipv6SrPrefixAttributesParser.parseSrIpv6Prefix(value); + builder.setIpv6SrPrefix(ipv6Prefix); + LOG.debug("Parsed Ipv6 SR Prefix: {}", ipv6Prefix); + break; + case RANGE: + final SrRange range = RangeTlvParser.parseSrRange(value, protocolId); + builder.setSrRange(range); + LOG.debug("Parsed SR Range: {}", range); + break; + case BINDING_SID: + parseBindingSid(builder, value, protocolId); + break; + default: + LOG.warn("TLV {} is not a valid prefix attribute, ignoring it", key); } } private static void parseIgpFags(final PrefixAttributesBuilder builder, final ByteBuf value) { final BitArray flags = BitArray.valueOf(value, FLAGS_SIZE); final boolean upDownBit = flags.get(UP_DOWN_BIT); - builder.setIgpBits(new IgpBitsBuilder().setUpDown(new UpDown(upDownBit)).setIsIsUpDown(upDownBit).setOspfNoUnicast(flags.get(OSPF_NO_UNICAST)) - .setOspfLocalAddress(flags.get(OSPF_LOCAL_ADDRESS)).setOspfPropagateNssa(flags.get(OSPF_PROPAGATE_ADDRESS)).build()); + builder.setIgpBits(new IgpBitsBuilder().setUpDown(new UpDown(upDownBit)).setIsIsUpDown(upDownBit) + .setOspfNoUnicast(flags.get(OSPF_NO_UNICAST)) + .setOspfLocalAddress(flags.get(OSPF_LOCAL_ADDRESS)) + .setOspfPropagateNssa(flags.get(OSPF_PROPAGATE_ADDRESS)).build()); LOG.debug("Parsed IGP flag (up/down bit) : {}", upDownBit); } - private static void parseBindingSid(final PrefixAttributesBuilder builder, final ByteBuf value, final ProtocolId protocolId) { + private static void parseBindingSid(final PrefixAttributesBuilder builder, final ByteBuf value, + final ProtocolId protocolId) { final List labels; if (builder.getSrBindingSidLabels() != null) { labels = builder.getSrBindingSidLabels(); @@ -176,28 +182,27 @@ public final class PrefixAttributesParser { private static void parseExtendedRouteTags(final List exRouteTags, final ByteBuf value) { while (value.isReadable()) { - final ExtendedRouteTag exRouteTag = new ExtendedRouteTag(ByteArray.readBytes(value, EXTENDED_ROUTE_TAG_LENGTH)); + final ExtendedRouteTag exRouteTag = new ExtendedRouteTag(ByteArray.readBytes(value, + EXTENDED_ROUTE_TAG_LENGTH)); exRouteTags.add(exRouteTag); LOG.debug("Parsed Extended Route Tag: {}", exRouteTag); } } private static IpAddress parseForwardingAddress(final ByteBuf value) { - IpAddress fwdAddress = null; switch (value.readableBytes()) { - case Ipv4Util.IP4_LENGTH: - fwdAddress = new IpAddress(Ipv4Util.addressForByteBuf(value)); - break; - case Ipv6Util.IPV6_LENGTH: - fwdAddress = new IpAddress(Ipv6Util.addressForByteBuf(value)); - break; - default: - LOG.debug("Ignoring unsupported forwarding address length {}", value.readableBytes()); + case Ipv4Util.IP4_LENGTH: + return new IpAddress(Ipv4Util.addressForByteBuf(value)); + case Ipv6Util.IPV6_LENGTH: + return new IpAddress(Ipv6Util.addressForByteBuf(value)); + default: + LOG.debug("Ignoring unsupported forwarding address length {}", value.readableBytes()); + return null; } - return fwdAddress; } - static void serializePrefixAttributes(final PrefixAttributesCase prefixAttributesCase, final ByteBuf byteAggregator) { + static void serializePrefixAttributes(final PrefixAttributesCase prefixAttributesCase, + final ByteBuf byteAggregator) { final PrefixAttributes prefixAtrributes = prefixAttributesCase.getPrefixAttributes(); if (prefixAtrributes.getIgpBits() != null) { final BitArray igpBit = new BitArray(FLAGS_SIZE); @@ -218,11 +223,13 @@ public final class PrefixAttributesParser { serializeSrBindingLabel(prefixAtrributes.getSrBindingSidLabels(), byteAggregator); } - private static void serializeSrBindingLabel(final List srBindingSidLabels, final ByteBuf byteAggregator) { + private static void serializeSrBindingLabel(final List srBindingSidLabels, + final ByteBuf byteAggregator) { if (srBindingSidLabels != null) { for (final SrBindingSidLabels bindingSid : srBindingSidLabels) { final ByteBuf sidBuffer = Unpooled.buffer(); - BindingSidLabelParser.serializeBindingSidAttributes(bindingSid.getWeight(), bindingSid.getFlags(), bindingSid.getBindingSubTlvs(), sidBuffer); + BindingSidLabelParser.serializeBindingSidAttributes(bindingSid.getWeight(), bindingSid.getFlags(), + bindingSid.getBindingSubTlvs(), sidBuffer); TlvUtil.writeTLV(PrefixAttributesParser.BINDING_SID, sidBuffer, byteAggregator); } } @@ -268,7 +275,8 @@ public final class PrefixAttributesParser { } } - private static void serializeExtendedRouteTags(final List exRouteTags, final ByteBuf byteAggregator) { + private static void serializeExtendedRouteTags(final List exRouteTags, + final ByteBuf byteAggregator) { if (exRouteTags != null) { final ByteBuf extendedBuf = Unpooled.buffer(); for (final ExtendedRouteTag exRouteTag : exRouteTags) { diff --git a/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/attribute/TeLspAttributesParser.java b/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/attribute/TeLspAttributesParser.java index d1fae35c97..82bc6c3c6c 100644 --- a/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/attribute/TeLspAttributesParser.java +++ b/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/attribute/TeLspAttributesParser.java @@ -60,7 +60,8 @@ final class TeLspAttributesParser { throw new UnsupportedOperationException(); } - static LinkStateAttribute parseTeLspAttributes(final RSVPTeObjectRegistry registry, final ByteBuf attributes) throws BGPParsingException { + static LinkStateAttribute parseTeLspAttributes(final RSVPTeObjectRegistry registry, final ByteBuf attributes) + throws BGPParsingException { final TeLspAttributesBuilder builder = new TeLspAttributesBuilder(); LOG.trace("Initiated parsing TE LSP Objects."); @@ -72,8 +73,9 @@ final class TeLspAttributesParser { try { addObject(builder, registry.parseRSPVTe(classNum, cType, value)); } catch (final RSVPParsingException e) { - LOG.debug("Parsering TE LSP Object error. class number: {} cType: {} value: {}", classNum, cType, value, e); - throw new BGPParsingException(e.getMessage()); + LOG.debug("Parsering TE LSP Object error. class number: {} cType: {} value: {}", classNum, cType, value, + e); + throw new BGPParsingException(e.getMessage(), e); } } LOG.trace("Finished parsing TE LSP Objects."); @@ -123,7 +125,8 @@ final class TeLspAttributesParser { } - static void serializeLspAttributes(final RSVPTeObjectRegistry registry, final TeLspAttributesCase linkState, final ByteBuf output) { + static void serializeLspAttributes(final RSVPTeObjectRegistry registry, final TeLspAttributesCase linkState, + final ByteBuf output) { LOG.trace("Started serializing TE LSP Objects"); final ByteBuf byteBuf = Unpooled.buffer(); diff --git a/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/attribute/sr/BindingSidLabelParser.java b/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/attribute/sr/BindingSidLabelParser.java index a3db1271c6..7421a7944e 100644 --- a/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/attribute/sr/BindingSidLabelParser.java +++ b/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/attribute/sr/BindingSidLabelParser.java @@ -36,7 +36,7 @@ public final class BindingSidLabelParser { private static final int RESERVED_BINDING_SID = 2; private BindingSidLabelParser() { - throw new UnsupportedOperationException(); + } public static SrBindingSidLabels parseBindingSidLabel(final ByteBuf buffer, final ProtocolId protocolId) { @@ -45,25 +45,29 @@ public final class BindingSidLabelParser { final BitArray flags = BitArray.valueOf(buffer, FLAGS_SIZE); bindingSid.setFlags(parseBindingSidFlags(flags, protocolId)); buffer.skipBytes(RESERVED_BINDING_SID); - bindingSid.setBindingSubTlvs(SimpleBindingSubTlvsRegistry.getInstance().parseBindingSubTlvs(buffer, protocolId)); + bindingSid.setBindingSubTlvs( + SimpleBindingSubTlvsRegistry.getInstance().parseBindingSubTlvs(buffer, protocolId)); return bindingSid.build(); } private static Flags parseBindingSidFlags(final BitArray flags, final ProtocolId protocol) { switch (protocol) { - case IsisLevel1: - case IsisLevel2: - return new IsisBindingFlagsCaseBuilder().setAddressFamily(flags.get(AFI)).setMirrorContext(flags.get(MIRROR_CONTEXT)) - .setSpreadTlv(flags.get(SPREAD_TLV)).setLeakedFromLevel2(flags.get(LEAKED)).setAttachedFlag(flags.get(ATTACHED)).build(); - case Ospf: - case OspfV3: - return new OspfBindingFlagsCaseBuilder().setMirroring(flags.get(MIRROR_CONTEXT_OSPF)).build(); - default: - return null; + case IsisLevel1: + case IsisLevel2: + return new IsisBindingFlagsCaseBuilder().setAddressFamily(flags.get(AFI)) + .setMirrorContext(flags.get(MIRROR_CONTEXT)) + .setSpreadTlv(flags.get(SPREAD_TLV)).setLeakedFromLevel2(flags.get(LEAKED)) + .setAttachedFlag(flags.get(ATTACHED)).build(); + case Ospf: + case OspfV3: + return new OspfBindingFlagsCaseBuilder().setMirroring(flags.get(MIRROR_CONTEXT_OSPF)).build(); + default: + return null; } } - public static void serializeBindingSidAttributes(final Weight weight, final Flags flags, final List bindingSubTlvs, final ByteBuf aggregator) { + public static void serializeBindingSidAttributes(final Weight weight, final Flags flags, + final List bindingSubTlvs, final ByteBuf aggregator) { aggregator.writeByte(weight.getValue()); final BitArray bitFlags = serializeBindingSidFlags(flags); bitFlags.toByteBuf(aggregator); diff --git a/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/attribute/sr/Ipv6SrPrefixAttributesParser.java b/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/attribute/sr/Ipv6SrPrefixAttributesParser.java index 17a60c2b18..67ea6eb252 100644 --- a/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/attribute/sr/Ipv6SrPrefixAttributesParser.java +++ b/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/attribute/sr/Ipv6SrPrefixAttributesParser.java @@ -5,10 +5,8 @@ * terms of the Eclipse Public License v1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/epl-v10.html */ - package org.opendaylight.protocol.bgp.linkstate.impl.attribute.sr; - import io.netty.buffer.ByteBuf; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.prefix.state.Ipv6SrPrefix; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.prefix.state.Ipv6SrPrefixBuilder; @@ -18,7 +16,7 @@ public final class Ipv6SrPrefixAttributesParser { private static final int FLAGS_SIZE = 2; private Ipv6SrPrefixAttributesParser() { - throw new UnsupportedOperationException(); + } public static Ipv6SrPrefix parseSrIpv6Prefix(final ByteBuf buffer) { diff --git a/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/attribute/sr/RangeTlvParser.java b/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/attribute/sr/RangeTlvParser.java index 854e5c1c6a..333b93d0f3 100644 --- a/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/attribute/sr/RangeTlvParser.java +++ b/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/attribute/sr/RangeTlvParser.java @@ -44,7 +44,7 @@ public final class RangeTlvParser { private static final int RESERVED = 1; private RangeTlvParser() { - throw new UnsupportedOperationException(); + } public static SrRange parseSrRange(final ByteBuf buffer, final ProtocolId protocolId) { @@ -69,22 +69,27 @@ public final class RangeTlvParser { final int type = buffer.readUnsignedShort(); final int length = buffer.readUnsignedShort(); switch (type) { - case PREFIX_SID: - subTlvCase = new PrefixSidTlvCaseBuilder(SrPrefixAttributesParser.parseSrPrefix(buffer.readSlice(length), protocolId)).build(); - break; - case IPV6_PREFIX_SID: - subTlvCase = new Ipv6PrefixSidTlvCaseBuilder(Ipv6SrPrefixAttributesParser.parseSrIpv6Prefix(buffer.readSlice(length))).build(); - break; - case BINDING_SID: - subTlvCase = new BindingSidTlvCaseBuilder(BindingSidLabelParser.parseBindingSidLabel(buffer.readSlice(length), protocolId)).build(); - break; - case SID_TYPE: - subTlvCase = new SidLabelTlvCaseBuilder().setSidLabelIndex(SidLabelIndexParser.parseSidLabelIndex(Size.forValue(length), buffer.readSlice(length))).build(); - break; - default: - LOG.info("Unknown type of range sub-tlv: {}", type); - buffer.skipBytes(length); - continue; + case PREFIX_SID: + subTlvCase = new PrefixSidTlvCaseBuilder( + SrPrefixAttributesParser.parseSrPrefix(buffer.readSlice(length), protocolId)).build(); + break; + case IPV6_PREFIX_SID: + subTlvCase = new Ipv6PrefixSidTlvCaseBuilder( + Ipv6SrPrefixAttributesParser.parseSrIpv6Prefix(buffer.readSlice(length))).build(); + break; + case BINDING_SID: + subTlvCase = new BindingSidTlvCaseBuilder( + BindingSidLabelParser.parseBindingSidLabel(buffer.readSlice(length), protocolId)).build(); + break; + case SID_TYPE: + subTlvCase = new SidLabelTlvCaseBuilder().setSidLabelIndex( + SidLabelIndexParser.parseSidLabelIndex(Size.forValue(length), buffer.readSlice(length))) + .build(); + break; + default: + LOG.info("Unknown type of range sub-tlv: {}", type); + buffer.skipBytes(length); + continue; } subTlvs.add(subTlv.setRangeSubTlv(subTlvCase).build()); } diff --git a/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/attribute/sr/SidLabelIndexParser.java b/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/attribute/sr/SidLabelIndexParser.java index 0017b37379..f2f78867cd 100644 --- a/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/attribute/sr/SidLabelIndexParser.java +++ b/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/attribute/sr/SidLabelIndexParser.java @@ -32,7 +32,7 @@ public final class SidLabelIndexParser { private static final int LABEL_MASK = 0xfffff; private SidLabelIndexParser() { - throw new UnsupportedOperationException(); + } public enum Size { @@ -81,15 +81,15 @@ public final class SidLabelIndexParser { public static SidLabelIndex parseSidLabelIndex(final Size length, final ByteBuf buffer) { switch (length) { - case LABEL: - return new LocalLabelCaseBuilder() - .setLocalLabel(new MplsLabel(Long.valueOf(buffer.readUnsignedMedium() & LABEL_MASK))).build(); - case SID: - return new SidCaseBuilder().setSid(buffer.readUnsignedInt()).build(); - case IPV6_ADD: - return new Ipv6AddressCaseBuilder().setIpv6Address(Ipv6Util.addressForByteBuf(buffer)).build(); - default: - return null; + case LABEL: + return new LocalLabelCaseBuilder() + .setLocalLabel(new MplsLabel(Long.valueOf(buffer.readUnsignedMedium() & LABEL_MASK))).build(); + case SID: + return new SidCaseBuilder().setSid(buffer.readUnsignedInt()).build(); + case IPV6_ADD: + return new Ipv6AddressCaseBuilder().setIpv6Address(Ipv6Util.addressForByteBuf(buffer)).build(); + default: + return null; } } diff --git a/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/attribute/sr/SrLinkAttributesParser.java b/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/attribute/sr/SrLinkAttributesParser.java index c1a4ed73ee..94729123de 100644 --- a/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/attribute/sr/SrLinkAttributesParser.java +++ b/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/attribute/sr/SrLinkAttributesParser.java @@ -53,7 +53,8 @@ public final class SrLinkAttributesParser { private static final int FLAGS_BITS_SIZE = 8; private static final int FLAGS_BYTE_SIZE = 1; - /** OSPF flags + /* + OSPF flags 0 1 2 3 4 5 6 7 +-+-+-+-+-+-+-+-+ |B|V|L|S| | @@ -67,7 +68,7 @@ public final class SrLinkAttributesParser { */ private SrLinkAttributesParser() { - throw new UnsupportedOperationException(); + } public static SrAdjIds parseAdjacencySegmentIdentifier(final ByteBuf buffer, final ProtocolId protocolId) { @@ -105,10 +106,12 @@ public final class SrLinkAttributesParser { public Class getImplementedInterface() { return EpeAdjSidTlv.class; } + @Override public Weight getWeight() { return weight; } + @Override public SidLabelIndex getSidLabelIndex() { return sidValue; @@ -126,19 +129,21 @@ public final class SrLinkAttributesParser { srLanAdjIdBuilder.setWeight(new Weight(buffer.readUnsignedByte())); buffer.skipBytes(RESERVED); switch (protocolId) { - case IsisLevel1: - case IsisLevel2: - srLanAdjIdBuilder.setIsoSystemId(new IsoSystemIdentifier(ByteArray.readBytes(buffer, ISO_SYSTEM_ID_SIZE))); - break; - case Ospf: - case OspfV3: - srLanAdjIdBuilder.setNeighborId(Ipv4Util.addressForByteBuf(buffer)); - break; - default: - return null; + case IsisLevel1: + case IsisLevel2: + srLanAdjIdBuilder.setIsoSystemId(new IsoSystemIdentifier( + ByteArray.readBytes(buffer, ISO_SYSTEM_ID_SIZE))); + break; + case Ospf: + case OspfV3: + srLanAdjIdBuilder.setNeighborId(Ipv4Util.addressForByteBuf(buffer)); + break; + default: + return null; } // length determines a type of next field, which is used for parsing - srLanAdjIdBuilder.setSidLabelIndex(SidLabelIndexParser.parseSidLabelIndex(Size.forValue(buffer.readableBytes()), buffer)); + srLanAdjIdBuilder.setSidLabelIndex(SidLabelIndexParser.parseSidLabelIndex( + Size.forValue(buffer.readableBytes()), buffer)); return srLanAdjIdBuilder.build(); } @@ -147,28 +152,31 @@ public final class SrLinkAttributesParser { return null; } switch (protocol) { - case IsisLevel1: - case IsisLevel2: - return new IsisAdjFlagsCaseBuilder().setAddressFamily(flags.get(ADDRESS_FAMILY_FLAG)).setBackup(flags.get(BACKUP_ISIS)) - .setSet(flags.get(SET_ISIS)).build(); - case Ospf: - case OspfV3: - return new OspfAdjFlagsCaseBuilder().setBackup(flags.get(BACKUP_OSPF)).setSet(flags.get(SET_OSPF)).build(); - default: - return null; + case IsisLevel1: + case IsisLevel2: + return new IsisAdjFlagsCaseBuilder().setAddressFamily(flags.get(ADDRESS_FAMILY_FLAG)) + .setBackup(flags.get(BACKUP_ISIS)) + .setSet(flags.get(SET_ISIS)).build(); + case Ospf: + case OspfV3: + return new OspfAdjFlagsCaseBuilder().setBackup(flags.get(BACKUP_OSPF)).setSet(flags.get(SET_OSPF)) + .build(); + default: + return null; } } - public static void serializeAdjacencySegmentIdentifiers(final List adjSids, final int type, final ByteBuf byteAggregator) { + public static void serializeAdjacencySegmentIdentifiers(final List adjSids, + final int type, final ByteBuf byteAggregator) { adjSids.forEach(id -> TlvUtil.writeTLV(type, serializeAdjacencySegmentIdentifier(id), byteAggregator)); } public static ByteBuf serializeAdjacencySegmentIdentifier(final T adjSid) { final ByteBuf value = Unpooled.buffer(); - if(adjSid instanceof SrAdjIds) { + if (adjSid instanceof SrAdjIds) { final BitArray flags = serializeAdjFlags(((SrAdjIds) adjSid).getFlags(), adjSid.getSidLabelIndex()); flags.toByteBuf(value); - }else { + } else { value.writeZero(FLAGS_BYTE_SIZE); } value.writeByte(adjSid.getWeight().getValue()); @@ -177,7 +185,8 @@ public final class SrLinkAttributesParser { return value; } - public static void serializeLanAdjacencySegmentIdentifiers(final List srLanAdjIds, final ByteBuf byteAggregator) { + public static void serializeLanAdjacencySegmentIdentifiers(final List srLanAdjIds, + final ByteBuf byteAggregator) { for (final SrLanAdjIds id : srLanAdjIds) { TlvUtil.writeTLV(SR_LAN_ADJ_ID, serializeLanAdjacencySegmentIdentifier(id), byteAggregator); } @@ -211,10 +220,9 @@ public final class SrLinkAttributesParser { bitFlags.set(BACKUP_ISIS, isisFlags.isBackup()); bitFlags.set(SET_ISIS, isisFlags.isSet()); SidLabelIndexParser.setFlags(sidLabelIndex, bitFlags, VALUE_ISIS, LOCAL_ISIS); - } else if (flags == null){ + } else if (flags == null) { SidLabelIndexParser.setFlags(sidLabelIndex, bitFlags, VALUE_EPE, LOCAL_EPE); } return bitFlags; } - } diff --git a/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/attribute/sr/SrNodeAttributesParser.java b/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/attribute/sr/SrNodeAttributesParser.java index 5d5d49de59..c0e956ad83 100644 --- a/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/attribute/sr/SrNodeAttributesParser.java +++ b/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/attribute/sr/SrNodeAttributesParser.java @@ -31,7 +31,7 @@ public final class SrNodeAttributesParser { private static final int RESERVERED = 1; private SrNodeAttributesParser() { - throw new UnsupportedOperationException(); + } public static SrCapabilities parseSrCapabilities(final ByteBuf buffer, final ProtocolId protocol) { diff --git a/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/attribute/sr/SrPrefixAttributesParser.java b/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/attribute/sr/SrPrefixAttributesParser.java index a5aa167d9a..f2c32dfad5 100644 --- a/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/attribute/sr/SrPrefixAttributesParser.java +++ b/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/attribute/sr/SrPrefixAttributesParser.java @@ -36,7 +36,7 @@ public final class SrPrefixAttributesParser { private static final int RESERVED_PREFIX = 2; private SrPrefixAttributesParser() { - throw new UnsupportedOperationException(); + } public static SrPrefix parseSrPrefix(final ByteBuf buffer, final ProtocolId protocol) { @@ -50,24 +50,27 @@ public final class SrPrefixAttributesParser { private static Flags parsePrefixFlags(final BitArray flags, final ProtocolId protocol) { switch (protocol) { - case IsisLevel1: - case IsisLevel2: - return new IsisPrefixFlagsCaseBuilder().setReadvertisement(flags.get(RE_ADVERTISEMENT)) - .setNodeSid(flags.get(NODE_SID)).setNoPhp(flags.get(NO_PHP)).setExplicitNull(flags.get(EXPLICIT_NULL)).build(); - case Ospf: - case OspfV3: - return new OspfPrefixFlagsCaseBuilder().setExplicitNull(flags.get(EXPLICIT_NULL)) - .setMappingServer(flags.get(MAPPING_SERVER)).setNoPhp(flags.get(NO_PHP_OSPF)).build(); - default: - return null; + case IsisLevel1: + case IsisLevel2: + return new IsisPrefixFlagsCaseBuilder().setReadvertisement(flags.get(RE_ADVERTISEMENT)) + .setNodeSid(flags.get(NODE_SID)).setNoPhp(flags.get(NO_PHP)) + .setExplicitNull(flags.get(EXPLICIT_NULL)).build(); + case Ospf: + case OspfV3: + return new OspfPrefixFlagsCaseBuilder().setExplicitNull(flags.get(EXPLICIT_NULL)) + .setMappingServer(flags.get(MAPPING_SERVER)).setNoPhp(flags.get(NO_PHP_OSPF)).build(); + default: + return null; } } public static void serializeSrPrefix(final SrPrefix srPrefix, final ByteBuf aggregator) { - serializePrefixAttributes(srPrefix.getFlags(), srPrefix.getAlgorithm(), srPrefix.getSidLabelIndex(), aggregator); + serializePrefixAttributes(srPrefix.getFlags(), srPrefix.getAlgorithm(), srPrefix.getSidLabelIndex(), + aggregator); } - public static void serializePrefixAttributes(final Flags flags, final Algorithm algorithm, final SidLabelIndex sidLabelIndex, final ByteBuf buffer) { + public static void serializePrefixAttributes(final Flags flags, final Algorithm algorithm, + final SidLabelIndex sidLabelIndex, final ByteBuf buffer) { final BitArray bitFlags = serializePrefixFlags(flags, sidLabelIndex); bitFlags.toByteBuf(buffer); buffer.writeByte(algorithm.getIntValue()); diff --git a/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/attribute/sr/binding/sid/sub/tlvs/BackupUnnumberedParser.java b/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/attribute/sr/binding/sid/sub/tlvs/BackupUnnumberedParser.java index 0fe1bbf789..53b0b203eb 100644 --- a/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/attribute/sr/binding/sid/sub/tlvs/BackupUnnumberedParser.java +++ b/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/attribute/sr/binding/sid/sub/tlvs/BackupUnnumberedParser.java @@ -5,13 +5,12 @@ * terms of the Eclipse Public License v1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/epl-v10.html */ - package org.opendaylight.protocol.bgp.linkstate.impl.attribute.sr.binding.sid.sub.tlvs; +import static com.google.common.base.Preconditions.checkArgument; import static org.opendaylight.protocol.bgp.linkstate.impl.attribute.sr.binding.sid.sub.tlvs.UnnumberedEroParser.parseUnnumberedEroCase; import static org.opendaylight.protocol.bgp.linkstate.impl.attribute.sr.binding.sid.sub.tlvs.UnnumberedEroParser.serializeUnnumberedIdEro; -import com.google.common.base.Preconditions; import io.netty.buffer.ByteBuf; import org.opendaylight.protocol.bgp.linkstate.spi.BindingSubTlvsParser; import org.opendaylight.protocol.bgp.linkstate.spi.BindingSubTlvsSerializer; @@ -39,9 +38,10 @@ public final class BackupUnnumberedParser implements BindingSubTlvsParser, Bindi @Override public void serializeSubTlv(final BindingSubTlv bindingSubTlv, final ByteBuf aggregator) { - Preconditions.checkArgument(bindingSubTlv instanceof UnnumberedInterfaceIdBackupEroCase, "Wrong BindingSubTlv instance expected", bindingSubTlv); + checkArgument(bindingSubTlv instanceof UnnumberedInterfaceIdBackupEroCase, + "Wrong BindingSubTlv instance expected", bindingSubTlv); final UnnumberedInterfaceIdBackupEroCase unnumberedBackup = (UnnumberedInterfaceIdBackupEroCase) bindingSubTlv; - TlvUtil.writeTLV(BACKUP_UNNUMBERED_ERO, serializeUnnumberedIdEro(unnumberedBackup.isLoose(), unnumberedBackup.getRouterId(), - unnumberedBackup.getInterfaceId()), aggregator); + TlvUtil.writeTLV(BACKUP_UNNUMBERED_ERO, serializeUnnumberedIdEro(unnumberedBackup.isLoose(), + unnumberedBackup.getRouterId(), unnumberedBackup.getInterfaceId()), aggregator); } } diff --git a/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/attribute/sr/binding/sid/sub/tlvs/EroMetricParser.java b/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/attribute/sr/binding/sid/sub/tlvs/EroMetricParser.java index 5c6f6384f9..eb7f164137 100644 --- a/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/attribute/sr/binding/sid/sub/tlvs/EroMetricParser.java +++ b/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/attribute/sr/binding/sid/sub/tlvs/EroMetricParser.java @@ -5,10 +5,10 @@ * terms of the Eclipse Public License v1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/epl-v10.html */ - package org.opendaylight.protocol.bgp.linkstate.impl.attribute.sr.binding.sid.sub.tlvs; -import com.google.common.base.Preconditions; +import static com.google.common.base.Preconditions.checkArgument; + import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; import org.opendaylight.protocol.bgp.linkstate.spi.BindingSubTlvsParser; @@ -35,7 +35,8 @@ public final class EroMetricParser implements BindingSubTlvsParser, BindingSubTl @Override public void serializeSubTlv(final BindingSubTlv bindingSubTlv, final ByteBuf aggregator) { - Preconditions.checkArgument(bindingSubTlv instanceof EroMetricCase, "Wrong BindingSubTlv instance expected", bindingSubTlv); + checkArgument(bindingSubTlv instanceof EroMetricCase, "Wrong BindingSubTlv instance expected", + bindingSubTlv); final ByteBuf buffer = Unpooled.buffer(); buffer.writeInt(((EroMetricCase) bindingSubTlv).getEroMetric().getValue().intValue()); TlvUtil.writeTLV(getType(), buffer, aggregator); diff --git a/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/attribute/sr/binding/sid/sub/tlvs/Ipv4BackupEro.java b/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/attribute/sr/binding/sid/sub/tlvs/Ipv4BackupEro.java index 2514250cc9..2607925712 100644 --- a/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/attribute/sr/binding/sid/sub/tlvs/Ipv4BackupEro.java +++ b/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/attribute/sr/binding/sid/sub/tlvs/Ipv4BackupEro.java @@ -5,10 +5,10 @@ * terms of the Eclipse Public License v1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/epl-v10.html */ - package org.opendaylight.protocol.bgp.linkstate.impl.attribute.sr.binding.sid.sub.tlvs; -import com.google.common.base.Preconditions; +import static com.google.common.base.Preconditions.checkArgument; + import io.netty.buffer.ByteBuf; import org.opendaylight.protocol.bgp.linkstate.spi.BindingSubTlvsParser; import org.opendaylight.protocol.bgp.linkstate.spi.BindingSubTlvsSerializer; @@ -25,7 +25,8 @@ public final class Ipv4BackupEro implements BindingSubTlvsParser, BindingSubTlvs @Override public BindingSubTlv parseSubTlv(final ByteBuf slice, final ProtocolId protocolId) { final Ipv4EroCase ipv4Backup = Ipv4EroParser.parseIpv4EroCase(slice); - return new Ipv4EroBackupCaseBuilder().setAddress(ipv4Backup.getAddress()).setLoose(ipv4Backup.isLoose()).build(); + return new Ipv4EroBackupCaseBuilder().setAddress(ipv4Backup.getAddress()).setLoose(ipv4Backup.isLoose()) + .build(); } @Override @@ -35,8 +36,10 @@ public final class Ipv4BackupEro implements BindingSubTlvsParser, BindingSubTlvs @Override public void serializeSubTlv(final BindingSubTlv bindingSubTlv, final ByteBuf aggregator) { - Preconditions.checkArgument(bindingSubTlv instanceof Ipv4EroBackupCase, "Wrong BindingSubTlv instance expected", bindingSubTlv); + checkArgument(bindingSubTlv instanceof Ipv4EroBackupCase, "Wrong BindingSubTlv instance expected", + bindingSubTlv); final Ipv4EroBackupCase ipv4Backup = (Ipv4EroBackupCase) bindingSubTlv; - TlvUtil.writeTLV(getType(), Ipv4EroParser.serializeIpv4EroCase(ipv4Backup.isLoose(), ipv4Backup.getAddress()), aggregator); + TlvUtil.writeTLV(getType(), Ipv4EroParser.serializeIpv4EroCase(ipv4Backup.isLoose(), ipv4Backup.getAddress()), + aggregator); } } diff --git a/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/attribute/sr/binding/sid/sub/tlvs/Ipv4EroParser.java b/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/attribute/sr/binding/sid/sub/tlvs/Ipv4EroParser.java index eb0cc7b57e..87bd142561 100644 --- a/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/attribute/sr/binding/sid/sub/tlvs/Ipv4EroParser.java +++ b/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/attribute/sr/binding/sid/sub/tlvs/Ipv4EroParser.java @@ -5,10 +5,10 @@ * terms of the Eclipse Public License v1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/epl-v10.html */ - package org.opendaylight.protocol.bgp.linkstate.impl.attribute.sr.binding.sid.sub.tlvs; -import com.google.common.base.Preconditions; +import static com.google.common.base.Preconditions.checkArgument; + import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; import org.opendaylight.protocol.bgp.linkstate.spi.BindingSubTlvsParser; @@ -41,7 +41,8 @@ public final class Ipv4EroParser implements BindingSubTlvsParser, BindingSubTlvs @Override public void serializeSubTlv(final BindingSubTlv bindingSubTlv, final ByteBuf aggregator) { - Preconditions.checkArgument(bindingSubTlv instanceof Ipv4EroCase, "Wrong BindingSubTlv instance expected", bindingSubTlv); + checkArgument(bindingSubTlv instanceof Ipv4EroCase, "Wrong BindingSubTlv instance expected", + bindingSubTlv); final Ipv4EroCase ipv4Ero = (Ipv4EroCase) bindingSubTlv; TlvUtil.writeTLV(getType(), serializeIpv4EroCase(ipv4Ero.isLoose(), ipv4Ero.getAddress()), aggregator); } diff --git a/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/attribute/sr/binding/sid/sub/tlvs/Ipv4PrefixSidParser.java b/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/attribute/sr/binding/sid/sub/tlvs/Ipv4PrefixSidParser.java index 858a9ed51b..5cce7dd3a0 100644 --- a/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/attribute/sr/binding/sid/sub/tlvs/Ipv4PrefixSidParser.java +++ b/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/attribute/sr/binding/sid/sub/tlvs/Ipv4PrefixSidParser.java @@ -5,10 +5,10 @@ * terms of the Eclipse Public License v1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/epl-v10.html */ - package org.opendaylight.protocol.bgp.linkstate.impl.attribute.sr.binding.sid.sub.tlvs; -import com.google.common.base.Preconditions; +import static com.google.common.base.Preconditions.checkArgument; + import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; import org.opendaylight.protocol.bgp.linkstate.impl.attribute.sr.SrPrefixAttributesParser; @@ -38,10 +38,12 @@ public final class Ipv4PrefixSidParser implements BindingSubTlvsParser, BindingS @Override public void serializeSubTlv(final BindingSubTlv bindingSubTlv, final ByteBuf aggregator) { - Preconditions.checkArgument(bindingSubTlv instanceof PrefixSidCase, "Wrong BindingSubTlv instance expected", bindingSubTlv); + checkArgument(bindingSubTlv instanceof PrefixSidCase, "Wrong BindingSubTlv instance expected", + bindingSubTlv); final PrefixSidCase prefix = (PrefixSidCase) bindingSubTlv; final ByteBuf buffer = Unpooled.buffer(); - SrPrefixAttributesParser.serializePrefixAttributes(prefix.getFlags(), prefix.getAlgorithm(), prefix.getSidLabelIndex(), buffer); + SrPrefixAttributesParser.serializePrefixAttributes(prefix.getFlags(), prefix.getAlgorithm(), + prefix.getSidLabelIndex(), buffer); TlvUtil.writeTLV(getType(), buffer, aggregator); } } diff --git a/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/attribute/sr/binding/sid/sub/tlvs/Ipv6BackupEro.java b/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/attribute/sr/binding/sid/sub/tlvs/Ipv6BackupEro.java index 2cc229e766..babfe1e9e0 100644 --- a/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/attribute/sr/binding/sid/sub/tlvs/Ipv6BackupEro.java +++ b/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/attribute/sr/binding/sid/sub/tlvs/Ipv6BackupEro.java @@ -5,10 +5,10 @@ * terms of the Eclipse Public License v1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/epl-v10.html */ - package org.opendaylight.protocol.bgp.linkstate.impl.attribute.sr.binding.sid.sub.tlvs; -import com.google.common.base.Preconditions; +import static com.google.common.base.Preconditions.checkArgument; + import io.netty.buffer.ByteBuf; import org.opendaylight.protocol.bgp.linkstate.spi.BindingSubTlvsParser; import org.opendaylight.protocol.bgp.linkstate.spi.BindingSubTlvsSerializer; @@ -25,7 +25,8 @@ public final class Ipv6BackupEro implements BindingSubTlvsParser, BindingSubTlvs @Override public BindingSubTlv parseSubTlv(final ByteBuf slice, final ProtocolId protocolId) { final Ipv6EroCase ipv6backup = Ipv6EroParser.parseIpv6EroCase(slice); - return new Ipv6EroBackupCaseBuilder().setAddress(ipv6backup.getAddress()).setLoose(ipv6backup.isLoose()).build(); + return new Ipv6EroBackupCaseBuilder().setAddress(ipv6backup.getAddress()).setLoose(ipv6backup.isLoose()) + .build(); } @Override @@ -35,8 +36,10 @@ public final class Ipv6BackupEro implements BindingSubTlvsParser, BindingSubTlvs @Override public void serializeSubTlv(final BindingSubTlv bindingSubTlv, final ByteBuf aggregator) { - Preconditions.checkArgument(bindingSubTlv instanceof Ipv6EroBackupCase, "Wrong BindingSubTlv instance expected", bindingSubTlv); + checkArgument(bindingSubTlv instanceof Ipv6EroBackupCase, "Wrong BindingSubTlv instance expected", + bindingSubTlv); final Ipv6EroBackupCase ipv6Backup = (Ipv6EroBackupCase) bindingSubTlv; - TlvUtil.writeTLV(getType(), Ipv6EroParser.serializeIpv6EroCase(ipv6Backup.isLoose(), ipv6Backup.getAddress()), aggregator); + TlvUtil.writeTLV(getType(), Ipv6EroParser.serializeIpv6EroCase(ipv6Backup.isLoose(), ipv6Backup.getAddress()), + aggregator); } } diff --git a/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/attribute/sr/binding/sid/sub/tlvs/Ipv6EroParser.java b/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/attribute/sr/binding/sid/sub/tlvs/Ipv6EroParser.java index 5fa2dc9bba..556b632aa3 100644 --- a/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/attribute/sr/binding/sid/sub/tlvs/Ipv6EroParser.java +++ b/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/attribute/sr/binding/sid/sub/tlvs/Ipv6EroParser.java @@ -5,10 +5,10 @@ * terms of the Eclipse Public License v1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/epl-v10.html */ - package org.opendaylight.protocol.bgp.linkstate.impl.attribute.sr.binding.sid.sub.tlvs; -import com.google.common.base.Preconditions; +import static com.google.common.base.Preconditions.checkArgument; + import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; import org.opendaylight.protocol.bgp.linkstate.spi.BindingSubTlvsParser; @@ -38,7 +38,8 @@ public final class Ipv6EroParser implements BindingSubTlvsParser, BindingSubTlvs @Override public void serializeSubTlv(final BindingSubTlv bindingSubTlv, final ByteBuf aggregator) { - Preconditions.checkArgument(bindingSubTlv instanceof Ipv6EroCase, "Wrong BindingSubTlv instance expected", bindingSubTlv); + checkArgument(bindingSubTlv instanceof Ipv6EroCase, "Wrong BindingSubTlv instance expected", + bindingSubTlv); final Ipv6EroCase ipv6Ero = (Ipv6EroCase) bindingSubTlv; TlvUtil.writeTLV(getType(), serializeIpv6EroCase(ipv6Ero.isLoose(), ipv6Ero.getAddress()), aggregator); } diff --git a/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/attribute/sr/binding/sid/sub/tlvs/Ipv6PrefixSidParser.java b/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/attribute/sr/binding/sid/sub/tlvs/Ipv6PrefixSidParser.java index a1389bf100..f3a2e84362 100644 --- a/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/attribute/sr/binding/sid/sub/tlvs/Ipv6PrefixSidParser.java +++ b/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/attribute/sr/binding/sid/sub/tlvs/Ipv6PrefixSidParser.java @@ -5,10 +5,10 @@ * terms of the Eclipse Public License v1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/epl-v10.html */ - package org.opendaylight.protocol.bgp.linkstate.impl.attribute.sr.binding.sid.sub.tlvs; -import com.google.common.base.Preconditions; +import static com.google.common.base.Preconditions.checkArgument; + import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; import org.opendaylight.protocol.bgp.linkstate.impl.attribute.sr.Ipv6SrPrefixAttributesParser; @@ -37,7 +37,8 @@ public final class Ipv6PrefixSidParser implements BindingSubTlvsParser, BindingS @Override public void serializeSubTlv(final BindingSubTlv bindingSubTlv, final ByteBuf aggregator) { - Preconditions.checkArgument(bindingSubTlv instanceof Ipv6PrefixSidCase, "Wrong BindingSubTlv instance expected", bindingSubTlv); + checkArgument(bindingSubTlv instanceof Ipv6PrefixSidCase, "Wrong BindingSubTlv instance expected", + bindingSubTlv); final Ipv6PrefixSidCase prefix = (Ipv6PrefixSidCase) bindingSubTlv; final ByteBuf buffer = Unpooled.buffer(); Ipv6SrPrefixAttributesParser.serializePrefixAttributes(prefix.getAlgorithm(), buffer); diff --git a/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/attribute/sr/binding/sid/sub/tlvs/SIDParser.java b/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/attribute/sr/binding/sid/sub/tlvs/SIDParser.java index ef96ccf607..87366c2f50 100644 --- a/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/attribute/sr/binding/sid/sub/tlvs/SIDParser.java +++ b/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/attribute/sr/binding/sid/sub/tlvs/SIDParser.java @@ -5,10 +5,10 @@ * terms of the Eclipse Public License v1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/epl-v10.html */ - package org.opendaylight.protocol.bgp.linkstate.impl.attribute.sr.binding.sid.sub.tlvs; -import com.google.common.base.Preconditions; +import static com.google.common.base.Preconditions.checkArgument; + import io.netty.buffer.ByteBuf; import org.opendaylight.protocol.bgp.linkstate.impl.attribute.sr.SidLabelIndexParser; import org.opendaylight.protocol.bgp.linkstate.spi.BindingSubTlvsParser; @@ -25,7 +25,8 @@ public final class SIDParser implements BindingSubTlvsParser, BindingSubTlvsSeri @Override public BindingSubTlv parseSubTlv(final ByteBuf slice, final ProtocolId protocolId) { - final SidLabelIndex sid = SidLabelIndexParser.parseSidLabelIndex(SidLabelIndexParser.Size.forValue(slice.readableBytes()), slice); + final SidLabelIndex sid = SidLabelIndexParser.parseSidLabelIndex(SidLabelIndexParser.Size.forValue( + slice.readableBytes()), slice); return new SidLabelCaseBuilder().setSidLabelIndex(sid).build(); } @@ -36,7 +37,9 @@ public final class SIDParser implements BindingSubTlvsParser, BindingSubTlvsSeri @Override public void serializeSubTlv(final BindingSubTlv bindingSubTlv, final ByteBuf aggregator) { - Preconditions.checkArgument(bindingSubTlv instanceof SidLabelCase, "Wrong BindingSubTlv instance expected", bindingSubTlv); - TlvUtil.writeTLV(getType(), SidLabelIndexParser.serializeSidValue(((SidLabelCase) bindingSubTlv).getSidLabelIndex()), aggregator); + checkArgument(bindingSubTlv instanceof SidLabelCase, "Wrong BindingSubTlv instance expected", + bindingSubTlv); + TlvUtil.writeTLV(getType(), SidLabelIndexParser.serializeSidValue( + ((SidLabelCase) bindingSubTlv).getSidLabelIndex()), aggregator); } } diff --git a/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/attribute/sr/binding/sid/sub/tlvs/UnnumberedEroParser.java b/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/attribute/sr/binding/sid/sub/tlvs/UnnumberedEroParser.java index 7e9865d589..bccacbc15b 100644 --- a/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/attribute/sr/binding/sid/sub/tlvs/UnnumberedEroParser.java +++ b/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/attribute/sr/binding/sid/sub/tlvs/UnnumberedEroParser.java @@ -5,10 +5,10 @@ * terms of the Eclipse Public License v1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/epl-v10.html */ - package org.opendaylight.protocol.bgp.linkstate.impl.attribute.sr.binding.sid.sub.tlvs; -import com.google.common.base.Preconditions; +import static com.google.common.base.Preconditions.checkArgument; + import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; import org.opendaylight.protocol.bgp.linkstate.spi.BindingSubTlvsParser; @@ -26,8 +26,9 @@ public final class UnnumberedEroParser implements BindingSubTlvsParser, BindingS @Override public BindingSubTlv parseSubTlv(final ByteBuf slice, final ProtocolId protocolId) { final UnnumberedInterfaceIdEroCase unnumbered = parseUnnumberedEroCase(slice); - return new UnnumberedInterfaceIdEroCaseBuilder().setLoose(unnumbered.isLoose()).setRouterId(unnumbered.getRouterId()) - .setInterfaceId(unnumbered.getInterfaceId()).build(); + return new UnnumberedInterfaceIdEroCaseBuilder().setLoose(unnumbered.isLoose()) + .setRouterId(unnumbered.getRouterId()) + .setInterfaceId(unnumbered.getInterfaceId()).build(); } @Override @@ -37,9 +38,11 @@ public final class UnnumberedEroParser implements BindingSubTlvsParser, BindingS @Override public void serializeSubTlv(final BindingSubTlv bindingSubTlv, final ByteBuf aggregator) { - Preconditions.checkArgument(bindingSubTlv instanceof UnnumberedInterfaceIdEroCase, "Wrong BindingSubTlv instance expected", bindingSubTlv); + checkArgument(bindingSubTlv instanceof UnnumberedInterfaceIdEroCase, + "Wrong BindingSubTlv instance expected", bindingSubTlv); final UnnumberedInterfaceIdEroCase unnumberedEro = (UnnumberedInterfaceIdEroCase) bindingSubTlv; - TlvUtil.writeTLV(getType(), serializeUnnumberedIdEro(unnumberedEro.isLoose(), unnumberedEro.getRouterId(), unnumberedEro.getInterfaceId()), aggregator); + TlvUtil.writeTLV(getType(), serializeUnnumberedIdEro(unnumberedEro.isLoose(), unnumberedEro.getRouterId(), + unnumberedEro.getInterfaceId()), aggregator); } static UnnumberedInterfaceIdEroCase parseUnnumberedEroCase(final ByteBuf buffer) { diff --git a/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/nlri/AbstractPrefixNlriParser.java b/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/nlri/AbstractPrefixNlriParser.java index 1257270bed..93e8c54e07 100644 --- a/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/nlri/AbstractPrefixNlriParser.java +++ b/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/nlri/AbstractPrefixNlriParser.java @@ -5,7 +5,6 @@ * terms of the Eclipse Public License v1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/epl-v10.html */ - package org.opendaylight.protocol.bgp.linkstate.impl.nlri; import io.netty.buffer.ByteBuf; @@ -42,7 +41,8 @@ abstract class AbstractPrefixNlriParser extends AbstractNlriTypeCodec { @Override protected final void serializeObjectType(final ObjectType objectType, final ByteBuf buffer) { final PrefixCase prefix = (PrefixCase) objectType; - SimpleNlriTypeRegistry.getInstance().serializeTlv(AdvertisingNodeDescriptors.QNAME, prefix.getAdvertisingNodeDescriptors(), buffer); + SimpleNlriTypeRegistry.getInstance().serializeTlv(AdvertisingNodeDescriptors.QNAME, + prefix.getAdvertisingNodeDescriptors(), buffer); serializePrefixDescriptor(prefix.getPrefixDescriptors(), buffer); } diff --git a/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/nlri/LinkNlriParser.java b/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/nlri/LinkNlriParser.java index 3e5cfdc9a7..9af5f9c4ef 100644 --- a/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/nlri/LinkNlriParser.java +++ b/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/nlri/LinkNlriParser.java @@ -38,15 +38,21 @@ public final class LinkNlriParser extends AbstractNlriTypeCodec { /* Link Descriptor QNames */ @VisibleForTesting - public static final NodeIdentifier IPV4_IFACE_NID = new NodeIdentifier(Ipv4InterfaceTlvParser.IPV4_IFACE_ADDRESS_QNAME); + public static final NodeIdentifier IPV4_IFACE_NID = NodeIdentifier.create( + Ipv4InterfaceTlvParser.IPV4_IFACE_ADDRESS_QNAME); @VisibleForTesting - public static final NodeIdentifier IPV4_NEIGHBOR_NID = new NodeIdentifier(Ipv4NeighborTlvParser.IPV4_NEIGHBOR_ADDRESS_QNAME); + public static final NodeIdentifier IPV4_NEIGHBOR_NID = NodeIdentifier.create( + Ipv4NeighborTlvParser.IPV4_NEIGHBOR_ADDRESS_QNAME); @VisibleForTesting - public static final NodeIdentifier LINK_LOCAL_NID = new NodeIdentifier(QName.create(LinkDescriptors.QNAME, "link-local-identifier").intern()); + public static final NodeIdentifier LINK_LOCAL_NID = NodeIdentifier.create( + QName.create(LinkDescriptors.QNAME, "link-local-identifier").intern()); @VisibleForTesting - public static final NodeIdentifier LINK_REMOTE_NID = new NodeIdentifier(QName.create(LinkDescriptors.QNAME, "link-remote-identifier").intern()); - private static final NodeIdentifier IPV6_IFACE_NID = new NodeIdentifier(Ipv6InterfaceTlvParser.IPV6_IFACE_ADDRESS_QNAME); - private static final NodeIdentifier IPV6_NEIGHBOR_NID = new NodeIdentifier(Ipv6NeighborTlvParser.IPV6_NEIGHBOR_ADDRESS_QNAME); + public static final NodeIdentifier LINK_REMOTE_NID = NodeIdentifier.create( + QName.create(LinkDescriptors.QNAME, "link-remote-identifier").intern()); + private static final NodeIdentifier IPV6_IFACE_NID = NodeIdentifier.create( + Ipv6InterfaceTlvParser.IPV6_IFACE_ADDRESS_QNAME); + private static final NodeIdentifier IPV6_NEIGHBOR_NID = NodeIdentifier.create( + Ipv6NeighborTlvParser.IPV6_NEIGHBOR_ADDRESS_QNAME); @FunctionalInterface private interface SerializerInterface { @@ -60,15 +66,21 @@ public final class LinkNlriParser extends AbstractNlriTypeCodec { linkDescBuilder.setLinkLocalIdentifier((Long) descriptors.getChild(LINK_LOCAL_NID).get().getValue()); linkDescBuilder.setLinkRemoteIdentifier((Long) descriptors.getChild(LINK_REMOTE_NID).get().getValue()); } - ifPresentApply(descriptors, IPV4_IFACE_NID, value -> linkDescBuilder.setIpv4InterfaceAddress(new Ipv4InterfaceIdentifier((String) value))); - ifPresentApply(descriptors, IPV6_IFACE_NID, value -> linkDescBuilder.setIpv6InterfaceAddress(new Ipv6InterfaceIdentifier((String) value))); - ifPresentApply(descriptors, IPV4_NEIGHBOR_NID, value -> linkDescBuilder.setIpv4NeighborAddress(new Ipv4InterfaceIdentifier((String) value))); - ifPresentApply(descriptors, IPV6_NEIGHBOR_NID, value -> linkDescBuilder.setIpv6NeighborAddress(new Ipv6InterfaceIdentifier((String) value))); - ifPresentApply(descriptors, TlvUtil.MULTI_TOPOLOGY_NID, value -> linkDescBuilder.setMultiTopologyId(new TopologyIdentifier((Integer) value))); + ifPresentApply(descriptors, IPV4_IFACE_NID, + value -> linkDescBuilder.setIpv4InterfaceAddress(new Ipv4InterfaceIdentifier((String) value))); + ifPresentApply(descriptors, IPV6_IFACE_NID, + value -> linkDescBuilder.setIpv6InterfaceAddress(new Ipv6InterfaceIdentifier((String) value))); + ifPresentApply(descriptors, IPV4_NEIGHBOR_NID, + value -> linkDescBuilder.setIpv4NeighborAddress(new Ipv4InterfaceIdentifier((String) value))); + ifPresentApply(descriptors, IPV6_NEIGHBOR_NID, + value -> linkDescBuilder.setIpv6NeighborAddress(new Ipv6InterfaceIdentifier((String) value))); + ifPresentApply(descriptors, TlvUtil.MULTI_TOPOLOGY_NID, + value -> linkDescBuilder.setMultiTopologyId(new TopologyIdentifier((Integer) value))); return linkDescBuilder.build(); } - private static void ifPresentApply(final ContainerNode descriptors, final NodeIdentifier nid, final SerializerInterface serializer) { + private static void ifPresentApply(final ContainerNode descriptors, final NodeIdentifier nid, + final SerializerInterface serializer) { if (descriptors.getChild(nid).isPresent()) { serializer.check(descriptors.getChild(nid).get().getValue()); } @@ -83,10 +95,14 @@ public final class LinkNlriParser extends AbstractNlriTypeCodec { builder.setLinkLocalIdentifier(linkIdentifiers.getLinkLocalIdentifier()); builder.setLinkRemoteIdentifier(linkIdentifiers.getLinkRemoteIdentifier()); } - builder.setIpv4InterfaceAddress((Ipv4InterfaceIdentifier) tlvs.get(Ipv4InterfaceTlvParser.IPV4_IFACE_ADDRESS_QNAME)); - builder.setIpv4NeighborAddress((Ipv4InterfaceIdentifier) tlvs.get(Ipv4NeighborTlvParser.IPV4_NEIGHBOR_ADDRESS_QNAME)); - builder.setIpv6InterfaceAddress((Ipv6InterfaceIdentifier) tlvs.get(Ipv6InterfaceTlvParser.IPV6_IFACE_ADDRESS_QNAME)); - builder.setIpv6NeighborAddress((Ipv6InterfaceIdentifier) tlvs.get(Ipv6NeighborTlvParser.IPV6_NEIGHBOR_ADDRESS_QNAME)); + builder.setIpv4InterfaceAddress( + (Ipv4InterfaceIdentifier) tlvs.get(Ipv4InterfaceTlvParser.IPV4_IFACE_ADDRESS_QNAME)); + builder.setIpv4NeighborAddress( + (Ipv4InterfaceIdentifier) tlvs.get(Ipv4NeighborTlvParser.IPV4_NEIGHBOR_ADDRESS_QNAME)); + builder.setIpv6InterfaceAddress( + (Ipv6InterfaceIdentifier) tlvs.get(Ipv6InterfaceTlvParser.IPV6_IFACE_ADDRESS_QNAME)); + builder.setIpv6NeighborAddress( + (Ipv6InterfaceIdentifier) tlvs.get(Ipv6NeighborTlvParser.IPV6_NEIGHBOR_ADDRESS_QNAME)); builder.setMultiTopologyId((TopologyIdentifier) tlvs.get(MultiTopoIdTlvParser.MULTI_TOPOLOGY_ID_QNAME)); return builder.build(); @@ -119,10 +135,14 @@ public final class LinkNlriParser extends AbstractNlriTypeCodec { if (linkDescriptor.getLinkLocalIdentifier() != null && linkDescriptor.getLinkRemoteIdentifier() != null) { reg.serializeTlv(LinkLrIdentifiers.QNAME, linkDescriptor, body); } - reg.serializeTlv(Ipv4InterfaceTlvParser.IPV4_IFACE_ADDRESS_QNAME, linkDescriptor.getIpv4InterfaceAddress(), body); - reg.serializeTlv(Ipv4NeighborTlvParser.IPV4_NEIGHBOR_ADDRESS_QNAME, linkDescriptor.getIpv4NeighborAddress(), body); - reg.serializeTlv(Ipv6InterfaceTlvParser.IPV6_IFACE_ADDRESS_QNAME, linkDescriptor.getIpv6InterfaceAddress(), body); - reg.serializeTlv(Ipv6NeighborTlvParser.IPV6_NEIGHBOR_ADDRESS_QNAME, linkDescriptor.getIpv6NeighborAddress(), body); + reg.serializeTlv(Ipv4InterfaceTlvParser.IPV4_IFACE_ADDRESS_QNAME, linkDescriptor.getIpv4InterfaceAddress(), + body); + reg.serializeTlv(Ipv4NeighborTlvParser.IPV4_NEIGHBOR_ADDRESS_QNAME, linkDescriptor.getIpv4NeighborAddress(), + body); + reg.serializeTlv(Ipv6InterfaceTlvParser.IPV6_IFACE_ADDRESS_QNAME, linkDescriptor.getIpv6InterfaceAddress(), + body); + reg.serializeTlv(Ipv6NeighborTlvParser.IPV6_NEIGHBOR_ADDRESS_QNAME, linkDescriptor.getIpv6NeighborAddress(), + body); reg.serializeTlv(MultiTopoIdTlvParser.MULTI_TOPOLOGY_ID_QNAME, linkDescriptor.getMultiTopologyId(), body); } diff --git a/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/nlri/LinkstateNlriParser.java b/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/nlri/LinkstateNlriParser.java index 34dd366928..7d71126e59 100644 --- a/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/nlri/LinkstateNlriParser.java +++ b/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/nlri/LinkstateNlriParser.java @@ -63,29 +63,29 @@ public final class LinkstateNlriParser implements NlriParser, NlriSerializer { private static final Logger LOG = LoggerFactory.getLogger(LinkstateNlriParser.class); @VisibleForTesting - public static final NodeIdentifier OBJECT_TYPE_NID = new NodeIdentifier(ObjectType.QNAME); + public static final NodeIdentifier OBJECT_TYPE_NID = NodeIdentifier.create(ObjectType.QNAME); @VisibleForTesting - public static final NodeIdentifier NODE_DESCRIPTORS_NID = new NodeIdentifier(NodeDescriptors.QNAME); + public static final NodeIdentifier NODE_DESCRIPTORS_NID = NodeIdentifier.create(NodeDescriptors.QNAME); @VisibleForTesting - public static final NodeIdentifier LOCAL_NODE_DESCRIPTORS_NID = new NodeIdentifier(LocalNodeDescriptors.QNAME); + public static final NodeIdentifier LOCAL_NODE_DESCRIPTORS_NID = NodeIdentifier.create(LocalNodeDescriptors.QNAME); @VisibleForTesting - public static final NodeIdentifier REMOTE_NODE_DESCRIPTORS_NID = new NodeIdentifier(RemoteNodeDescriptors.QNAME); + public static final NodeIdentifier REMOTE_NODE_DESCRIPTORS_NID = NodeIdentifier.create(RemoteNodeDescriptors.QNAME); @VisibleForTesting - public static final NodeIdentifier ADVERTISING_NODE_DESCRIPTORS_NID - = new NodeIdentifier(AdvertisingNodeDescriptors.QNAME); + public static final NodeIdentifier ADVERTISING_NODE_DESCRIPTORS_NID = NodeIdentifier.create( + AdvertisingNodeDescriptors.QNAME); @VisibleForTesting - public static final NodeIdentifier PREFIX_DESCRIPTORS_NID = new NodeIdentifier(PrefixDescriptors.QNAME); + public static final NodeIdentifier PREFIX_DESCRIPTORS_NID = NodeIdentifier.create(PrefixDescriptors.QNAME); @VisibleForTesting - public static final NodeIdentifier LINK_DESCRIPTORS_NID = new NodeIdentifier(LinkDescriptors.QNAME); + public static final NodeIdentifier LINK_DESCRIPTORS_NID = NodeIdentifier.create(LinkDescriptors.QNAME); @VisibleForTesting - public static final NodeIdentifier PROTOCOL_ID_NID = new NodeIdentifier( - QName.create(CLinkstateDestination.QNAME.getModule(), "protocol-id")); + public static final NodeIdentifier PROTOCOL_ID_NID = NodeIdentifier.create( + QName.create(CLinkstateDestination.QNAME.getModule(), "protocol-id").intern()); @VisibleForTesting - public static final NodeIdentifier IDENTIFIER_NID = new NodeIdentifier( - QName.create(CLinkstateDestination.QNAME.getModule(), "identifier")); + public static final NodeIdentifier IDENTIFIER_NID = NodeIdentifier.create( + QName.create(CLinkstateDestination.QNAME.getModule(), "identifier").intern()); @VisibleForTesting - private static final NodeIdentifier DISTINGUISHER_NID = new NodeIdentifier( - QName.create(CLinkstateDestination.QNAME.getModule(), "route-distinguisher")); + private static final NodeIdentifier DISTINGUISHER_NID = NodeIdentifier.create( + QName.create(CLinkstateDestination.QNAME.getModule(), "route-distinguisher").intern()); private final SimpleNlriTypeRegistry nlriTypeReg = SimpleNlriTypeRegistry.getInstance(); @@ -152,9 +152,9 @@ public final class LinkstateNlriParser implements NlriParser, NlriSerializer { if (withdrawnRoutes != null && withdrawnRoutes.getDestinationType() instanceof DestinationLinkstateCase) { final DestinationLinkstateCase linkstateCase = (DestinationLinkstateCase) withdrawnRoutes.getDestinationType(); - for (final CLinkstateDestination cLinkstateDestination : linkstateCase.getDestinationLinkstate() + for (final CLinkstateDestination linkstateDestinationCase : linkstateCase.getDestinationLinkstate() .getCLinkstateDestination()) { - this.nlriTypeReg.serializeNlriType(cLinkstateDestination, byteAggregator); + this.nlriTypeReg.serializeNlriType(linkstateDestinationCase, byteAggregator); } } } @@ -170,9 +170,9 @@ public final class LinkstateNlriParser implements NlriParser, NlriSerializer { .rev180329.update.attributes.mp.reach.nlri.advertized.routes.destination.type .DestinationLinkstateCase) advertizedRoutes.getDestinationType(); - for (final CLinkstateDestination cLinkstateDestination : linkstateCase.getDestinationLinkstate() + for (final CLinkstateDestination linkstateDestinationCase : linkstateCase.getDestinationLinkstate() .getCLinkstateDestination()) { - this.nlriTypeReg.serializeNlriType(cLinkstateDestination, byteAggregator); + this.nlriTypeReg.serializeNlriType(linkstateDestinationCase, byteAggregator); } } } @@ -180,26 +180,26 @@ public final class LinkstateNlriParser implements NlriParser, NlriSerializer { // FIXME : use codec private static int domProtocolIdValue(final String protocolId) { switch (protocolId) { - case "isis-level1": - return ProtocolId.IsisLevel1.getIntValue(); - case "isis-level2": - return ProtocolId.IsisLevel2.getIntValue(); - case "ospf": - return ProtocolId.Ospf.getIntValue(); - case "direct": - return ProtocolId.Direct.getIntValue(); - case "static": - return ProtocolId.Static.getIntValue(); - case "ospf-v3": - return ProtocolId.OspfV3.getIntValue(); - case "rsvp-te": - return ProtocolId.RsvpTe.getIntValue(); - case "bgp-epe": - return ProtocolId.BgpEpe.getIntValue(); - case "segment-routing": - return ProtocolId.SegmentRouting.getIntValue(); - default: - return 0; + case "isis-level1": + return ProtocolId.IsisLevel1.getIntValue(); + case "isis-level2": + return ProtocolId.IsisLevel2.getIntValue(); + case "ospf": + return ProtocolId.Ospf.getIntValue(); + case "direct": + return ProtocolId.Direct.getIntValue(); + case "static": + return ProtocolId.Static.getIntValue(); + case "ospf-v3": + return ProtocolId.OspfV3.getIntValue(); + case "rsvp-te": + return ProtocolId.RsvpTe.getIntValue(); + case "bgp-epe": + return ProtocolId.BgpEpe.getIntValue(); + case "segment-routing": + return ProtocolId.SegmentRouting.getIntValue(); + default: + return 0; } } diff --git a/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/nlri/NodeNlriParser.java b/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/nlri/NodeNlriParser.java index 14704f59c4..9b8b189b56 100644 --- a/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/nlri/NodeNlriParser.java +++ b/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/nlri/NodeNlriParser.java @@ -63,41 +63,41 @@ public final class NodeNlriParser extends AbstractNlriTypeCodec { /* Node Descriptor QNames */ @VisibleForTesting - public static final NodeIdentifier AS_NUMBER_NID = new NodeIdentifier(AsNumTlvParser.AS_NUMBER_QNAME); + public static final NodeIdentifier AS_NUMBER_NID = NodeIdentifier.create(AsNumTlvParser.AS_NUMBER_QNAME); @VisibleForTesting - public static final NodeIdentifier AREA_NID = new NodeIdentifier(AreaIdTlvParser.AREA_ID_QNAME); + public static final NodeIdentifier AREA_NID = NodeIdentifier.create(AreaIdTlvParser.AREA_ID_QNAME); @VisibleForTesting - public static final NodeIdentifier DOMAIN_NID = new NodeIdentifier(DomainIdTlvParser.DOMAIN_ID_QNAME); + public static final NodeIdentifier DOMAIN_NID = NodeIdentifier.create(DomainIdTlvParser.DOMAIN_ID_QNAME); @VisibleForTesting - private static final NodeIdentifier ROUTER_NID = new NodeIdentifier(CRouterIdentifier.QNAME); + private static final NodeIdentifier ROUTER_NID = NodeIdentifier.create(CRouterIdentifier.QNAME); @VisibleForTesting - public static final NodeIdentifier BGP_ROUTER_NID = new NodeIdentifier(BgpRouterIdTlvParser.BGP_ROUTER_ID_QNAME); + public static final NodeIdentifier BGP_ROUTER_NID = NodeIdentifier.create(BgpRouterIdTlvParser.BGP_ROUTER_ID_QNAME); @VisibleForTesting - public static final NodeIdentifier MEMBER_ASN_NID = new NodeIdentifier(MemAsNumTlvParser.MEMBER_AS_NUMBER_QNAME); + public static final NodeIdentifier MEMBER_ASN_NID = NodeIdentifier.create(MemAsNumTlvParser.MEMBER_AS_NUMBER_QNAME); /* Router Identifier QNames */ @VisibleForTesting - public static final NodeIdentifier ISIS_NODE_NID = new NodeIdentifier(IsisNode.QNAME); + public static final NodeIdentifier ISIS_NODE_NID = NodeIdentifier.create(IsisNode.QNAME); @VisibleForTesting - public static final NodeIdentifier ISIS_PSEUDONODE_NID = new NodeIdentifier(IsisPseudonode.QNAME); + public static final NodeIdentifier ISIS_PSEUDONODE_NID = NodeIdentifier.create(IsisPseudonode.QNAME); @VisibleForTesting - public static final NodeIdentifier OSPF_NODE_NID = new NodeIdentifier(OspfNode.QNAME); + public static final NodeIdentifier OSPF_NODE_NID = NodeIdentifier.create(OspfNode.QNAME); @VisibleForTesting - private static final NodeIdentifier OSPF_PSEUDONODE_NID = new NodeIdentifier(OspfPseudonode.QNAME); + private static final NodeIdentifier OSPF_PSEUDONODE_NID = NodeIdentifier.create(OspfPseudonode.QNAME); @VisibleForTesting - public static final NodeIdentifier ISO_SYSTEM_NID = new NodeIdentifier( - QName.create(NodeDescriptors.QNAME.getModule(), "iso-system-id")); + public static final NodeIdentifier ISO_SYSTEM_NID = NodeIdentifier.create( + QName.create(NodeDescriptors.QNAME, "iso-system-id")); @VisibleForTesting - public static final NodeIdentifier ISIS_ROUTER_NID = new NodeIdentifier( - QName.create(NodeDescriptors.QNAME.getModule(),"is-is-router-identifier")); + public static final NodeIdentifier ISIS_ROUTER_NID = NodeIdentifier.create( + QName.create(NodeDescriptors.QNAME, "is-is-router-identifier").intern()); @VisibleForTesting - public static final NodeIdentifier PSN_NID = new NodeIdentifier( - QName.create(NodeDescriptors.QNAME.getModule(),"psn")); + public static final NodeIdentifier PSN_NID = NodeIdentifier.create( + QName.create(NodeDescriptors.QNAME, "psn").intern()); @VisibleForTesting - public static final NodeIdentifier OSPF_ROUTER_NID = new NodeIdentifier( - QName.create(NodeDescriptors.QNAME.getModule(),"ospf-router-id")); - private static final NodeIdentifier LAN_IFACE_NID = new NodeIdentifier( - QName.create(NodeDescriptors.QNAME.getModule(),"lan-interface")); + public static final NodeIdentifier OSPF_ROUTER_NID = NodeIdentifier.create( + QName.create(NodeDescriptors.QNAME, "ospf-router-id").intern()); + private static final NodeIdentifier LAN_IFACE_NID = NodeIdentifier.create( + QName.create(NodeDescriptors.QNAME, "lan-interface").intern()); @Override protected ObjectType parseObjectType(final ByteBuf buffer) { @@ -120,11 +120,10 @@ public final class NodeNlriParser extends AbstractNlriTypeCodec { } private static IsisNodeCase serializeIsisNode(final ContainerNode isis) { - final IsisNodeCaseBuilder builder = new IsisNodeCaseBuilder(); - final IsisNodeBuilder isisBuilder = new IsisNodeBuilder(); - isisBuilder.setIsoSystemId(new IsoSystemIdentifier((byte[]) isis.getChild(ISO_SYSTEM_NID).get().getValue())); - builder.setIsisNode(isisBuilder.build()); - return builder.build(); + return new IsisNodeCaseBuilder() + .setIsisNode(new IsisNodeBuilder().setIsoSystemId( + new IsoSystemIdentifier((byte[]) isis.getChild(ISO_SYSTEM_NID).get().getValue())).build()) + .build(); } private static IsisPseudonodeCase serializeIsisPseudoNode(final ContainerNode pseudoIsisNode) { @@ -174,92 +173,86 @@ public final class NodeNlriParser extends AbstractNlriTypeCodec { } private static CRouterIdentifier serializeRouterId(final ContainerNode descriptorsData) { - CRouterIdentifier cRouterId = null; - final Optional> maybeRouterId - = descriptorsData.getChild(ROUTER_NID); + CRouterIdentifier ret = null; + final Optional> maybeRouterId = + descriptorsData.getChild(ROUTER_NID); if (maybeRouterId.isPresent()) { final ChoiceNode routerId = (ChoiceNode) maybeRouterId.get(); if (routerId.getChild(ISIS_NODE_NID).isPresent()) { - cRouterId = serializeIsisNode((ContainerNode) routerId.getChild(ISIS_NODE_NID).get()); + ret = serializeIsisNode((ContainerNode) routerId.getChild(ISIS_NODE_NID).get()); } else if (routerId.getChild(ISIS_PSEUDONODE_NID).isPresent()) { - cRouterId = serializeIsisPseudoNode((ContainerNode) routerId.getChild(ISIS_PSEUDONODE_NID).get()); + ret = serializeIsisPseudoNode((ContainerNode) routerId.getChild(ISIS_PSEUDONODE_NID).get()); } else if (routerId.getChild(OSPF_NODE_NID).isPresent()) { - cRouterId = serializeOspfNode((ContainerNode) routerId.getChild(OSPF_NODE_NID).get()); + ret = serializeOspfNode((ContainerNode) routerId.getChild(OSPF_NODE_NID).get()); } else if (routerId.getChild(OSPF_PSEUDONODE_NID).isPresent()) { - cRouterId = serializeOspfPseudoNode((ContainerNode) routerId.getChild(OSPF_PSEUDONODE_NID).get()); + ret = serializeOspfPseudoNode((ContainerNode) routerId.getChild(OSPF_PSEUDONODE_NID).get()); } } - return cRouterId; + return ret; } private static AsNumber serializeAsNumber(final ContainerNode descriptorsData) { - final Optional> asNumber - = descriptorsData.getChild(AS_NUMBER_NID); - return asNumber.map(dataContainerChild -> new AsNumber((Long) dataContainerChild.getValue())).orElse(null); + return descriptorsData.getChild(AS_NUMBER_NID).map( + dataContainerChild -> new AsNumber((Long) dataContainerChild.getValue())).orElse(null); } private static DomainIdentifier serializeDomainId(final ContainerNode descriptorsData) { - final Optional> domainId = descriptorsData.getChild(DOMAIN_NID); - return domainId.map(dataContainerChild - -> new DomainIdentifier((Long) dataContainerChild.getValue())).orElse(null); + return descriptorsData.getChild(DOMAIN_NID).map( + dataContainerChild -> new DomainIdentifier((Long) dataContainerChild.getValue())).orElse(null); } private static AreaIdentifier serializeAreaId(final ContainerNode descriptorsData) { - final Optional> areaId = descriptorsData.getChild(AREA_NID); - return areaId.map(dataContainerChild - -> new AreaIdentifier((Long) dataContainerChild.getValue())).orElse(null); + return descriptorsData.getChild(AREA_NID).map( + dataContainerChild -> new AreaIdentifier((Long) dataContainerChild.getValue())).orElse(null); } private static Ipv4Address serializeBgpRouterId(final ContainerNode descriptorsData) { - final Optional> bgpRouterId - = descriptorsData.getChild(BGP_ROUTER_NID); - return bgpRouterId.map(dataContainerChild - -> new Ipv4Address((String) dataContainerChild.getValue())).orElse(null); + return descriptorsData.getChild(BGP_ROUTER_NID).map( + dataContainerChild -> new Ipv4Address((String) dataContainerChild.getValue())).orElse(null); } private static AsNumber serializeMemberAsn(final ContainerNode descriptorsData) { - final Optional> memberAsn - = descriptorsData.getChild(MEMBER_ASN_NID); - return memberAsn.map(dataContainerChild -> new AsNumber((Long) dataContainerChild.getValue())).orElse(null); + return descriptorsData.getChild(MEMBER_ASN_NID).map( + dataContainerChild -> new AsNumber((Long) dataContainerChild.getValue())).orElse(null); } static LocalNodeDescriptors serializeLocalNodeDescriptors(final ContainerNode descriptorsData) { - final LocalNodeDescriptorsBuilder builder = new LocalNodeDescriptorsBuilder(); - builder.setAsNumber(serializeAsNumber(descriptorsData)); - builder.setDomainId(serializeDomainId(descriptorsData)); - builder.setAreaId(serializeAreaId(descriptorsData)); - builder.setCRouterIdentifier(serializeRouterId(descriptorsData)); - builder.setBgpRouterId(serializeBgpRouterId(descriptorsData)); - builder.setMemberAsn(serializeMemberAsn(descriptorsData)); - return builder.build(); + return new LocalNodeDescriptorsBuilder() + .setAsNumber(serializeAsNumber(descriptorsData)) + .setDomainId(serializeDomainId(descriptorsData)) + .setAreaId(serializeAreaId(descriptorsData)) + .setCRouterIdentifier(serializeRouterId(descriptorsData)) + .setBgpRouterId(serializeBgpRouterId(descriptorsData)) + .setMemberAsn(serializeMemberAsn(descriptorsData)) + .build(); } static RemoteNodeDescriptors serializeRemoteNodeDescriptors(final ContainerNode descriptorsData) { - final RemoteNodeDescriptorsBuilder builder = new RemoteNodeDescriptorsBuilder(); - builder.setAsNumber(serializeAsNumber(descriptorsData)); - builder.setDomainId(serializeDomainId(descriptorsData)); - builder.setAreaId(serializeAreaId(descriptorsData)); - builder.setCRouterIdentifier(serializeRouterId(descriptorsData)); - builder.setBgpRouterId(serializeBgpRouterId(descriptorsData)); - builder.setMemberAsn(serializeMemberAsn(descriptorsData)); - return builder.build(); + return new RemoteNodeDescriptorsBuilder() + .setAsNumber(serializeAsNumber(descriptorsData)) + .setDomainId(serializeDomainId(descriptorsData)) + .setAreaId(serializeAreaId(descriptorsData)) + .setCRouterIdentifier(serializeRouterId(descriptorsData)) + .setBgpRouterId(serializeBgpRouterId(descriptorsData)) + .setMemberAsn(serializeMemberAsn(descriptorsData)) + .build(); } static AdvertisingNodeDescriptors serializeAdvNodeDescriptors(final ContainerNode descriptorsData) { - final AdvertisingNodeDescriptorsBuilder builder = new AdvertisingNodeDescriptorsBuilder(); - builder.setAsNumber(serializeAsNumber(descriptorsData)); - builder.setDomainId(serializeDomainId(descriptorsData)); - builder.setAreaId(serializeAreaId(descriptorsData)); - builder.setCRouterIdentifier(serializeRouterId(descriptorsData)); - return builder.build(); + return new AdvertisingNodeDescriptorsBuilder() + .setAsNumber(serializeAsNumber(descriptorsData)) + .setDomainId(serializeDomainId(descriptorsData)) + .setAreaId(serializeAreaId(descriptorsData)) + .setCRouterIdentifier(serializeRouterId(descriptorsData)) + .build(); } static NodeDescriptors serializeNodeDescriptors(final ContainerNode descriptorsData) { - final NodeDescriptorsBuilder builder = new NodeDescriptorsBuilder(); - builder.setAsNumber(serializeAsNumber(descriptorsData)); - builder.setDomainId(serializeDomainId(descriptorsData)); - builder.setAreaId(serializeAreaId(descriptorsData)); - builder.setCRouterIdentifier(serializeRouterId(descriptorsData)); - return builder.build(); + return new NodeDescriptorsBuilder() + .setAsNumber(serializeAsNumber(descriptorsData)) + .setDomainId(serializeDomainId(descriptorsData)) + .setAreaId(serializeAreaId(descriptorsData)) + .setCRouterIdentifier(serializeRouterId(descriptorsData)) + .build(); } } diff --git a/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/tlvs/AbstractLocalNodeDescriptorTlvCodec.java b/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/tlvs/AbstractLocalNodeDescriptorTlvCodec.java index 474054340d..caef4ae722 100644 --- a/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/tlvs/AbstractLocalNodeDescriptorTlvCodec.java +++ b/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/tlvs/AbstractLocalNodeDescriptorTlvCodec.java @@ -5,7 +5,6 @@ * terms of the Eclipse Public License v1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/epl-v10.html */ - package org.opendaylight.protocol.bgp.linkstate.impl.tlvs; import io.netty.buffer.ByteBuf; @@ -19,16 +18,17 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.link import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.linkstate.object.type.link._case.LocalNodeDescriptorsBuilder; import org.opendaylight.yangtools.yang.common.QName; - -public abstract class AbstractLocalNodeDescriptorTlvCodec extends AbstractNodeDescriptorTlvCodec implements - LinkstateTlvParser, LinkstateTlvParser.LinkstateTlvSerializer { +public abstract class AbstractLocalNodeDescriptorTlvCodec + extends AbstractNodeDescriptorTlvCodec implements LinkstateTlvParser, + LinkstateTlvParser.LinkstateTlvSerializer { private static final int LOCAL_NODE_DESCRIPTORS_TYPE = 256; @Override public final LocalNodeDescriptors parseTlvBody(final ByteBuf value) { final Map parsedSubTlvs = new HashMap<>(); - final LocalNodeDescriptorsBuilder builder = new LocalNodeDescriptorsBuilder(parseNodeDescriptor(value, parsedSubTlvs)); + final LocalNodeDescriptorsBuilder builder = new LocalNodeDescriptorsBuilder( + parseNodeDescriptor(value, parsedSubTlvs)); builder.setBgpRouterId((Ipv4Address) parsedSubTlvs.get(BgpRouterIdTlvParser.BGP_ROUTER_ID_QNAME)); builder.setMemberAsn((AsNumber) parsedSubTlvs.get(MemAsNumTlvParser.MEMBER_AS_NUMBER_QNAME)); return builder.build(); @@ -38,5 +38,4 @@ public abstract class AbstractLocalNodeDescriptorTlvCodec getImplementedInterface() { return NodeIdentifier.class; } + @Override public AsNumber getAsNumber() { return asNumber; } + @Override public DomainIdentifier getDomainId() { return domainId; } + @Override public AreaIdentifier getAreaId() { return areaId; } + @Override public CRouterIdentifier getCRouterIdentifier() { return routerId; @@ -58,5 +61,4 @@ abstract class AbstractNodeDescriptorTlvCodec { tlvReg.serializeTlv(AreaIdTlvParser.AREA_ID_QNAME, tlv.getAreaId(), body); tlvReg.serializeTlv(CRouterIdentifier.QNAME, tlv.getCRouterIdentifier(), body); } - } diff --git a/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/tlvs/AdvertisingNodeDescriptorTlvParser.java b/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/tlvs/AdvertisingNodeDescriptorTlvParser.java index 409453123a..b0e898e548 100644 --- a/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/tlvs/AdvertisingNodeDescriptorTlvParser.java +++ b/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/tlvs/AdvertisingNodeDescriptorTlvParser.java @@ -5,14 +5,14 @@ * terms of the Eclipse Public License v1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/epl-v10.html */ - package org.opendaylight.protocol.bgp.linkstate.impl.tlvs; import io.netty.buffer.ByteBuf; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.linkstate.object.type.prefix._case.AdvertisingNodeDescriptors; import org.opendaylight.yangtools.yang.common.QName; -public final class AdvertisingNodeDescriptorTlvParser extends AbstractLocalNodeDescriptorTlvCodec { +public final class AdvertisingNodeDescriptorTlvParser extends + AbstractLocalNodeDescriptorTlvCodec { @Override public void serializeTlvBody(final AdvertisingNodeDescriptors tlv, final ByteBuf body) { serializeNodeDescriptor(tlv, body); @@ -22,5 +22,4 @@ public final class AdvertisingNodeDescriptorTlvParser extends AbstractLocalNodeD public QName getTlvQName() { return AdvertisingNodeDescriptors.QNAME; } - } diff --git a/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/tlvs/AreaIdTlvParser.java b/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/tlvs/AreaIdTlvParser.java index 0bb1a81a00..f3115b0875 100644 --- a/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/tlvs/AreaIdTlvParser.java +++ b/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/tlvs/AreaIdTlvParser.java @@ -14,7 +14,8 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.link import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.linkstate.object.type.node._case.NodeDescriptors; import org.opendaylight.yangtools.yang.common.QName; -public final class AreaIdTlvParser implements LinkstateTlvParser, LinkstateTlvParser.LinkstateTlvSerializer { +public final class AreaIdTlvParser implements LinkstateTlvParser, + LinkstateTlvParser.LinkstateTlvSerializer { private static final int AREA_ID = 514; @@ -39,5 +40,4 @@ public final class AreaIdTlvParser implements LinkstateTlvParser public QName getTlvQName() { return AREA_ID_QNAME; } - } diff --git a/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/tlvs/AsNumTlvParser.java b/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/tlvs/AsNumTlvParser.java index c7a4e713d0..147a4b09b0 100644 --- a/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/tlvs/AsNumTlvParser.java +++ b/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/tlvs/AsNumTlvParser.java @@ -14,7 +14,8 @@ import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types. import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.linkstate.object.type.node._case.NodeDescriptors; import org.opendaylight.yangtools.yang.common.QName; -public final class AsNumTlvParser implements LinkstateTlvParser, LinkstateTlvParser.LinkstateTlvSerializer { +public final class AsNumTlvParser implements LinkstateTlvParser, + LinkstateTlvParser.LinkstateTlvSerializer { private static final int AS_NUMBER = 512; @@ -39,5 +40,4 @@ public final class AsNumTlvParser implements LinkstateTlvParser, Links public QName getTlvQName() { return AS_NUMBER_QNAME; } - } diff --git a/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/tlvs/BgpRouterIdTlvParser.java b/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/tlvs/BgpRouterIdTlvParser.java index b1dc10dc8c..1dde64647f 100644 --- a/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/tlvs/BgpRouterIdTlvParser.java +++ b/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/tlvs/BgpRouterIdTlvParser.java @@ -15,13 +15,13 @@ import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types. import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.epe.rev150622.EpeNodeDescriptors; import org.opendaylight.yangtools.yang.common.QName; -public final class BgpRouterIdTlvParser implements LinkstateTlvParser, LinkstateTlvParser.LinkstateTlvSerializer { +public final class BgpRouterIdTlvParser implements LinkstateTlvParser, + LinkstateTlvParser.LinkstateTlvSerializer { private static final int BGP_ROUTER_ID = 516; public static final QName BGP_ROUTER_ID_QNAME = QName.create(EpeNodeDescriptors.QNAME, "bgp-router-id").intern(); - @Override public void serializeTlvBody(final Ipv4Address tlv, final ByteBuf body) { ByteBufWriteUtil.writeIpv4Address(tlv, body); @@ -41,5 +41,4 @@ public final class BgpRouterIdTlvParser implements LinkstateTlvParser, LinkstateTlvParser.LinkstateTlvSerializer { +public final class DomainIdTlvParser implements LinkstateTlvParser, + LinkstateTlvParser.LinkstateTlvSerializer { private static final int BGP_LS_ID = 513; @@ -39,5 +40,4 @@ public final class DomainIdTlvParser implements LinkstateTlvParser, LinkstateTlvParser.LinkstateTlvSerializer { +public final class Ipv4InterfaceTlvParser implements LinkstateTlvParser, + LinkstateTlvParser.LinkstateTlvSerializer { private static final int IPV4_IFACE_ADDRESS = 259; - public static final QName IPV4_IFACE_ADDRESS_QNAME = QName.create(LinkDescriptors.QNAME, "ipv4-interface-address").intern(); - + public static final QName IPV4_IFACE_ADDRESS_QNAME = QName.create(LinkDescriptors.QNAME, "ipv4-interface-address") + .intern(); @Override public void serializeTlvBody(final Ipv4InterfaceIdentifier tlv, final ByteBuf body) { @@ -41,5 +42,4 @@ public final class Ipv4InterfaceTlvParser implements LinkstateTlvParser, LinkstateTlvParser.LinkstateTlvSerializer { +public final class Ipv4NeighborTlvParser implements LinkstateTlvParser, + LinkstateTlvParser.LinkstateTlvSerializer { private static final int IPV4_NEIGHBOR_ADDRESS = 260; - public static final QName IPV4_NEIGHBOR_ADDRESS_QNAME = QName.create(LinkDescriptors.QNAME, "ipv4-neighbor-address").intern(); - + public static final QName IPV4_NEIGHBOR_ADDRESS_QNAME = QName.create(LinkDescriptors.QNAME, "ipv4-neighbor-address") + .intern(); @Override public void serializeTlvBody(final Ipv4InterfaceIdentifier tlv, final ByteBuf body) { @@ -41,5 +42,4 @@ public final class Ipv4NeighborTlvParser implements LinkstateTlvParser, LinkstateTlvParser.LinkstateTlvSerializer { +public final class Ipv6InterfaceTlvParser implements LinkstateTlvParser, + LinkstateTlvParser.LinkstateTlvSerializer { private static final int IPV6_IFACE_ADDRESS = 261; - public static final QName IPV6_IFACE_ADDRESS_QNAME = QName.create(LinkDescriptors.QNAME, "ipv6-interface-address").intern(); - + public static final QName IPV6_IFACE_ADDRESS_QNAME = QName.create(LinkDescriptors.QNAME, "ipv6-interface-address") + .intern(); @Override public void serializeTlvBody(final Ipv6InterfaceIdentifier tlv, final ByteBuf body) { @@ -41,6 +42,5 @@ public final class Ipv6InterfaceTlvParser implements LinkstateTlvParser, LinkstateTlvParser.LinkstateTlvSerializer { +public final class Ipv6NeighborTlvParser implements LinkstateTlvParser, + LinkstateTlvParser.LinkstateTlvSerializer { private static final int IPV6_NEIGHBOR_ADDRESS = 262; - public static final QName IPV6_NEIGHBOR_ADDRESS_QNAME = QName.create(LinkDescriptors.QNAME, "ipv6-neighbor-address").intern(); - + public static final QName IPV6_NEIGHBOR_ADDRESS_QNAME = QName.create(LinkDescriptors.QNAME, "ipv6-neighbor-address") + .intern(); @Override public void serializeTlvBody(final Ipv6InterfaceIdentifier tlv, final ByteBuf body) { @@ -41,7 +42,4 @@ public final class Ipv6NeighborTlvParser implements LinkstateTlvParser, LinkstateTlvParser { +public final class LinkIdTlvParser implements LinkstateTlvParser.LinkstateTlvSerializer, + LinkstateTlvParser { private static final int LINK_LR_IDENTIFIERS = 258; @@ -33,10 +34,12 @@ public final class LinkIdTlvParser implements LinkstateTlvParser.LinkstateTlvSer public Class getImplementedInterface() { return LinkLrIdentifiers.class; } + @Override public Long getLinkRemoteIdentifier() { return remoteId; } + @Override public Long getLinkLocalIdentifier() { return localId; diff --git a/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/tlvs/MemAsNumTlvParser.java b/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/tlvs/MemAsNumTlvParser.java index fec4593ef5..75fc24fc6e 100644 --- a/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/tlvs/MemAsNumTlvParser.java +++ b/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/tlvs/MemAsNumTlvParser.java @@ -14,7 +14,8 @@ import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types. import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.epe.rev150622.EpeNodeDescriptors; import org.opendaylight.yangtools.yang.common.QName; -public final class MemAsNumTlvParser implements LinkstateTlvParser, LinkstateTlvParser.LinkstateTlvSerializer { +public final class MemAsNumTlvParser implements LinkstateTlvParser, + LinkstateTlvParser.LinkstateTlvSerializer { private static final int MEMBER_AS_NUMBER = 517; @@ -39,5 +40,4 @@ public final class MemAsNumTlvParser implements LinkstateTlvParser, Li public QName getTlvQName() { return MEMBER_AS_NUMBER_QNAME; } - } diff --git a/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/tlvs/MultiTopoIdTlvParser.java b/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/tlvs/MultiTopoIdTlvParser.java index 3fc4eb1df3..119b84d2e7 100644 --- a/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/tlvs/MultiTopoIdTlvParser.java +++ b/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/tlvs/MultiTopoIdTlvParser.java @@ -16,9 +16,11 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.link import org.opendaylight.yangtools.yang.common.QName; import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode; -public final class MultiTopoIdTlvParser implements LinkstateTlvParser, LinkstateTlvParser.LinkstateTlvSerializer { +public final class MultiTopoIdTlvParser implements LinkstateTlvParser, + LinkstateTlvParser.LinkstateTlvSerializer { - public static final QName MULTI_TOPOLOGY_ID_QNAME = QName.create(LinkDescriptors.QNAME, "multi-topology-id").intern(); + public static final QName MULTI_TOPOLOGY_ID_QNAME = QName.create(LinkDescriptors.QNAME, "multi-topology-id") + .intern(); @Override public void serializeTlvBody(final TopologyIdentifier tlv, final ByteBuf body) { diff --git a/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/tlvs/OspfRouteTlvParser.java b/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/tlvs/OspfRouteTlvParser.java index 725bbec2e3..2feab94bf7 100644 --- a/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/tlvs/OspfRouteTlvParser.java +++ b/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/tlvs/OspfRouteTlvParser.java @@ -8,16 +8,13 @@ package org.opendaylight.protocol.bgp.linkstate.impl.tlvs; import io.netty.buffer.ByteBuf; -import java.util.Optional; import org.opendaylight.protocol.bgp.linkstate.spi.LinkstateTlvParser; import org.opendaylight.protocol.util.ByteBufWriteUtil; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.OspfRouteType; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.linkstate.object.type.prefix._case.PrefixDescriptors; import org.opendaylight.yangtools.yang.common.QName; -import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier; import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode; -import org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild; public final class OspfRouteTlvParser implements LinkstateTlvParser, LinkstateTlvParser.LinkstateTlvSerializer { @@ -48,31 +45,28 @@ public final class OspfRouteTlvParser implements LinkstateTlvParser> ospfRoute - = prefixDesc.getChild(OSPF_ROUTE_NID); - return ospfRoute.map(dataContainerChild - -> OspfRouteType.forValue(domOspfRouteTypeValue((String) dataContainerChild.getValue()))) - .orElse(null); + return prefixDesc.getChild(OSPF_ROUTE_NID).map( + dataContainerChild -> OspfRouteType.forValue(domOspfRouteTypeValue((String) dataContainerChild.getValue()))) + .orElse(null); } - // FIXME : use codec private static int domOspfRouteTypeValue(final String ospfRouteType) { switch (ospfRouteType) { - case "intra-area": - return OspfRouteType.IntraArea.getIntValue(); - case "inter-area": - return OspfRouteType.InterArea.getIntValue(); - case "external1": - return OspfRouteType.External1.getIntValue(); - case "external2": - return OspfRouteType.External2.getIntValue(); - case "nssa1": - return OspfRouteType.Nssa1.getIntValue(); - case "nssa2": - return OspfRouteType.Nssa2.getIntValue(); - default: - return 0; + case "intra-area": + return OspfRouteType.IntraArea.getIntValue(); + case "inter-area": + return OspfRouteType.InterArea.getIntValue(); + case "external1": + return OspfRouteType.External1.getIntValue(); + case "external2": + return OspfRouteType.External2.getIntValue(); + case "nssa1": + return OspfRouteType.Nssa1.getIntValue(); + case "nssa2": + return OspfRouteType.Nssa2.getIntValue(); + default: + return 0; } } } diff --git a/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/tlvs/ReachTlvParser.java b/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/tlvs/ReachTlvParser.java index 08fcc107d7..1ca75ec1c1 100644 --- a/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/tlvs/ReachTlvParser.java +++ b/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/tlvs/ReachTlvParser.java @@ -5,7 +5,6 @@ * terms of the Eclipse Public License v1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/epl-v10.html */ - package org.opendaylight.protocol.bgp.linkstate.impl.tlvs; import com.google.common.annotations.VisibleForTesting; @@ -19,15 +18,17 @@ import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types. import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Prefix; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.linkstate.object.type.prefix._case.PrefixDescriptors; import org.opendaylight.yangtools.yang.common.QName; -import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; +import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier; import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -public final class ReachTlvParser implements LinkstateTlvParser.LinkstateTlvSerializer, LinkstateTlvParser { - public static final QName IP_REACHABILITY_QNAME = QName.create(PrefixDescriptors.QNAME, "ip-reachability-information").intern(); +public final class ReachTlvParser implements LinkstateTlvParser.LinkstateTlvSerializer, + LinkstateTlvParser { + public static final QName IP_REACHABILITY_QNAME = QName.create(PrefixDescriptors.QNAME, + "ip-reachability-information").intern(); @VisibleForTesting - public static final YangInstanceIdentifier.NodeIdentifier IP_REACH_NID = new YangInstanceIdentifier.NodeIdentifier(IP_REACHABILITY_QNAME); + public static final NodeIdentifier IP_REACH_NID = NodeIdentifier.create(IP_REACHABILITY_QNAME); private static final Logger LOG = LoggerFactory.getLogger(ReachTlvParser.class); private static final int IP_REACHABILITY = 265; diff --git a/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/tlvs/RemoteNodeDescriptorTlvParser.java b/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/tlvs/RemoteNodeDescriptorTlvParser.java index 5cfc79f9b7..0d89c81472 100644 --- a/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/tlvs/RemoteNodeDescriptorTlvParser.java +++ b/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/tlvs/RemoteNodeDescriptorTlvParser.java @@ -5,21 +5,22 @@ * terms of the Eclipse Public License v1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/epl-v10.html */ - package org.opendaylight.protocol.bgp.linkstate.impl.tlvs; import io.netty.buffer.ByteBuf; import java.util.HashMap; import java.util.Map; -import org.opendaylight.protocol.bgp.linkstate.spi.pojo.SimpleNlriTypeRegistry; import org.opendaylight.protocol.bgp.linkstate.spi.LinkstateTlvParser; +import org.opendaylight.protocol.bgp.linkstate.spi.pojo.SimpleNlriTypeRegistry; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.linkstate.object.type.link._case.RemoteNodeDescriptors; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.linkstate.object.type.link._case.RemoteNodeDescriptorsBuilder; import org.opendaylight.yangtools.yang.common.QName; -public final class RemoteNodeDescriptorTlvParser extends AbstractNodeDescriptorTlvCodec implements LinkstateTlvParser, LinkstateTlvParser.LinkstateTlvSerializer { +public final class RemoteNodeDescriptorTlvParser extends AbstractNodeDescriptorTlvCodec + implements LinkstateTlvParser, + LinkstateTlvParser.LinkstateTlvSerializer { private static final int REMOTE_NODE_DESCRIPTORS_TYPE = 257; @Override @@ -33,7 +34,8 @@ public final class RemoteNodeDescriptorTlvParser extends AbstractNodeDescriptorT @Override public RemoteNodeDescriptors parseTlvBody(final ByteBuf value) { final Map parsedSubTlvs = new HashMap<>(); - final RemoteNodeDescriptorsBuilder builder = new RemoteNodeDescriptorsBuilder(parseNodeDescriptor(value, parsedSubTlvs)); + final RemoteNodeDescriptorsBuilder builder = new RemoteNodeDescriptorsBuilder( + parseNodeDescriptor(value, parsedSubTlvs)); builder.setBgpRouterId((Ipv4Address) parsedSubTlvs.get(BgpRouterIdTlvParser.BGP_ROUTER_ID_QNAME)); builder.setMemberAsn((AsNumber) parsedSubTlvs.get(MemAsNumTlvParser.MEMBER_AS_NUMBER_QNAME)); return builder.build(); @@ -48,5 +50,4 @@ public final class RemoteNodeDescriptorTlvParser extends AbstractNodeDescriptorT public int getType() { return REMOTE_NODE_DESCRIPTORS_TYPE; } - } diff --git a/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/tlvs/RouterIdTlvParser.java b/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/tlvs/RouterIdTlvParser.java index 4af561b4f7..76f5094ef0 100644 --- a/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/tlvs/RouterIdTlvParser.java +++ b/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/impl/tlvs/RouterIdTlvParser.java @@ -33,7 +33,8 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.link import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.concepts.rev131125.IsoSystemIdentifier; import org.opendaylight.yangtools.yang.common.QName; -public final class RouterIdTlvParser implements LinkstateTlvParser, LinkstateTlvParser.LinkstateTlvSerializer { +public final class RouterIdTlvParser implements LinkstateTlvParser, + LinkstateTlvParser.LinkstateTlvSerializer { private static final int OSPF_PSEUDONODE_ROUTER_ID_LENGTH = 8; private static final int OSPF_ROUTER_ID_LENGTH = 4; @@ -62,14 +63,17 @@ public final class RouterIdTlvParser implements LinkstateTlvParser { interface LinkstateTlvSerializer { - void serializeTlvBody(final T tlv, final ByteBuf body); + void serializeTlvBody(T tlv, ByteBuf body); int getType(); diff --git a/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/spi/TlvUtil.java b/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/spi/TlvUtil.java index 45b7749662..00b7920a11 100644 --- a/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/spi/TlvUtil.java +++ b/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/spi/TlvUtil.java @@ -19,12 +19,13 @@ public final class TlvUtil { public static final int TOPOLOGY_ID_OFFSET = 0x3fff; public static final int MULTI_TOPOLOGY_ID = 263; - public static final NodeIdentifier MULTI_TOPOLOGY_NID = new NodeIdentifier(QName.create(PrefixDescriptors.QNAME, "topology-identifier").intern()); + public static final NodeIdentifier MULTI_TOPOLOGY_NID = new NodeIdentifier(QName.create(PrefixDescriptors.QNAME, + "topology-identifier").intern()); public static final int LOCAL_IPV4_ROUTER_ID = 1028; public static final int LOCAL_IPV6_ROUTER_ID = 1029; private static final Logger LOG = LoggerFactory.getLogger(TlvUtil.class); + private TlvUtil() { - throw new UnsupportedOperationException(); } /** diff --git a/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/spi/pojo/SimpleNlriTypeRegistry.java b/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/spi/pojo/SimpleNlriTypeRegistry.java index 484354a0ad..84ae4d0de7 100644 --- a/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/spi/pojo/SimpleNlriTypeRegistry.java +++ b/bgp/extensions/linkstate/src/main/java/org/opendaylight/protocol/bgp/linkstate/spi/pojo/SimpleNlriTypeRegistry.java @@ -94,6 +94,15 @@ public final class SimpleNlriTypeRegistry { return parseTlv(buffer, getParser(buffer)); } + private static T parseTlv(final ByteBuf buffer, final LinkstateTlvParser parser) { + if (parser == null) { + return null; + } + checkArgument(buffer != null && buffer.isReadable()); + final int length = buffer.readUnsignedShort(); + return parser.parseTlvBody(buffer.readSlice(length)); + } + public Map parseSubTlvs(final ByteBuf buffer) { final Map tlvs = new HashMap<>(); while (buffer.isReadable()) { @@ -116,16 +125,6 @@ public final class SimpleNlriTypeRegistry { return parser; } - private static T parseTlv(final ByteBuf buffer, final LinkstateTlvParser parser) { - if (parser == null) { - return null; - } - checkArgument(buffer != null && buffer.isReadable()); - final int length = buffer.readUnsignedShort(); - return parser.parseTlvBody(buffer.readSlice(length)); - } - - public void serializeTlv(final QName tlvQName, final T tlv, final ByteBuf buffer) { if (tlv == null) { return; diff --git a/bgp/extensions/linkstate/src/test/java/org/opendaylight/protocol/bgp/linkstate/LinkstateAttributeParserTest.java b/bgp/extensions/linkstate/src/test/java/org/opendaylight/protocol/bgp/linkstate/LinkstateAttributeParserTest.java index 08f4e7ef0e..b5fbf2b929 100644 --- a/bgp/extensions/linkstate/src/test/java/org/opendaylight/protocol/bgp/linkstate/LinkstateAttributeParserTest.java +++ b/bgp/extensions/linkstate/src/test/java/org/opendaylight/protocol/bgp/linkstate/LinkstateAttributeParserTest.java @@ -16,15 +16,10 @@ import static org.junit.Assert.assertTrue; import com.google.common.collect.Lists; import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; -import java.lang.reflect.Constructor; -import java.lang.reflect.InvocationTargetException; import java.util.Arrays; import org.junit.Before; import org.junit.Test; -import org.opendaylight.protocol.bgp.linkstate.impl.attribute.LinkAttributesParser; import org.opendaylight.protocol.bgp.linkstate.impl.attribute.LinkstateAttributeParser; -import org.opendaylight.protocol.bgp.linkstate.impl.attribute.NodeAttributesParser; -import org.opendaylight.protocol.bgp.linkstate.impl.attribute.PrefixAttributesParser; import org.opendaylight.protocol.bgp.parser.BGPDocumentedException; import org.opendaylight.protocol.bgp.parser.BGPParsingException; import org.opendaylight.protocol.rsvp.parser.impl.RSVPActivator; @@ -78,7 +73,8 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev public class LinkstateAttributeParserTest { - private static final byte[] TE_LSP_ATTR = {0x00, (byte) 0x63, 0x00, (byte) 0x30, // TE LSP Attribute Type, length, value + private static final byte[] TE_LSP_ATTR = { + 0x00, (byte) 0x63, 0x00, (byte) 0x30, // TE LSP Attribute Type, length, value 0x00, (byte) 0x20, (byte) 0x0c, 0x02, // Length, Class, Ctype 0x00, 0x00, 0x00, 0x07, 0x01, 0x00, 0x00, 0x06, @@ -90,14 +86,16 @@ public class LinkstateAttributeParserTest { 0x00, 0x00, 0x00, 0x05, //Maximum Packet Size 0x00, (byte) 0x08, (byte) 0xc7, 0x01, // Length, Class, Ctype 0x00, 0x01, 0x00, 0x02, - 0x01, 0x02, 0x03, 0x04,}; - - private static final byte[] LINK_ATTR = {0x04, 0x04, 0, 0x04, 0x2a, 0x2a, 0x2a, 0x2a, 0x04, 0x06, 0, 0x04, 0x2b, 0x2b, 0x2b, 0x2b, - 0x04, 0x40, 0, 0x04, 0, 0, 0, 0, 0x04, 0x41, 0, 0x04, 0x49, (byte) 0x98, (byte) 0x96, (byte) 0x80, 0x04, 0x42, 0, 0x04, - 0x46, 0x43, 0x50, 0, 0x04, 0x43, 0, 0x20, 0x46, 0x43, 0x50, 0, 0x46, 0x43, 0x50, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x04, 0x44, 0, 0x08, 0, 0, 0, 0, 0, 0, 0, 0, 0x04, 0x45, 0, 0x02, 0, 0x08, 0x04, 0x46, 0, 0x01, - (byte) 0xc0, 0x04, 0x47, 0, 0x03, 0, 0, 0x0a, 0x04, 0x48, 0, 0x08, 0x12, 0x34, 0x56, 0x78, 0x10, 0x30, 0x50, 0x70, 0x04, 0x4a, - 0, 0x05, 0x31, 0x32, 0x4b, 0x2d, 0x32, + 0x01, 0x02, 0x03, 0x04 + }; + + private static final byte[] LINK_ATTR = { + 0x04, 0x04, 0, 0x04, 0x2a, 0x2a, 0x2a, 0x2a, 0x04, 0x06, 0, 0x04, 0x2b, 0x2b, 0x2b, 0x2b, 0x04, 0x40, 0, 0x04, + 0, 0, 0, 0, 0x04, 0x41, 0, 0x04, 0x49, (byte) 0x98, (byte) 0x96, (byte) 0x80, 0x04, 0x42, 0, 0x04, 0x46, 0x43, + 0x50, 0, 0x04, 0x43, 0, 0x20, 0x46, 0x43, 0x50, 0, 0x46, 0x43, 0x50, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x04, 0x44, 0, 0x08, 0, 0, 0, 0, 0, 0, 0, 0, 0x04, 0x45, 0, 0x02, 0, 0x08, + 0x04, 0x46, 0, 0x01, (byte) 0xc0, 0x04, 0x47, 0, 0x03, 0, 0, 0x0a, 0x04, 0x48, 0, 0x08, 0x12, 0x34, 0x56, 0x78, + 0x10, 0x30, 0x50, 0x70, 0x04, 0x4a, 0, 0x05, 0x31, 0x32, 0x4b, 0x2d, 0x32, 0x04, 0x4b, 0, 0x07, (byte)-80, 10, 0, 0, (byte)0x0f, (byte)0xff, (byte)0xff, // sr-adj 0x04, 0x4b, 0, 0x07, (byte)-80, 10, 0, 0, (byte)0x0f, (byte)0xff, (byte)0xef, // sr-adj 0x04, 0x4c, 0, 0x0d, (byte)-80, 10, 0, 0, 1, 2, 3, 4, 5, 6, (byte)0x0f, (byte)0xff, (byte)0xff, // sr-lan-adj @@ -113,29 +111,32 @@ public class LinkstateAttributeParserTest { 0x04, 0x5e, 0, 0x04, 0x46, 0x43, 0x50, 0, // Residual Bandwidth 0x04, 0x5f, 0, 0x04, 0x46, 0x43, 0x50, 0, // Available Bandwidth 0x04, 0x60, 0, 0x04, 0, 0, 0, 0, // Utilized Bandwidth - 0x04, (byte) 0x88, 0, 0x01, 0x0a }; + 0x04, (byte) 0x88, 0, 0x01, 0x0a + }; - private static final byte[] NODE_ATTR = { 0x01, 0x07, 0, 0x04, 0, 0x2a, 0, 0x2b, 0x04, 0, 0, 0x01, (byte) 0xbc, 0x04, 0x02, 0, - 0x05, 0x31, 0x32, 0x4b, 0x2d, 0x32, 0x04, 0x03, 0, 0x01, 0x72, 0x04, 0x03, 0, 0x01, 0x73, 0x04, 0x04, 0, 0x04, - 0x29, 0x29, 0x29, 0x29, 0x04, (byte) 0x88, 0, 0x01, 0x0a, + private static final byte[] NODE_ATTR = { + 0x01, 0x07, 0, 0x04, 0, 0x2a, 0, 0x2b, 0x04, 0, 0, 0x01, (byte) 0xbc, 0x04, 0x02, 0, 0x05, 0x31, 0x32, 0x4b, + 0x2d, 0x32, 0x04, 0x03, 0, 0x01, 0x72, 0x04, 0x03, 0, 0x01, 0x73, 0x04, 0x04, 0, 0x04, 0x29, 0x29, 0x29, 0x29, + 0x04, (byte) 0x88, 0, 0x01, 0x0a, 4, 0x0a, 0, 0x0c, (byte)0xe0, 0, 1, 2, 3, 4, (byte)0x89, 0, 3, 1, 2, 0, // sr-caps 4, 0x0b, 0, 2, 0, 1 // sr-algorythms - }; + }; - private static final byte[] NODE_ATTR_S = { 0x01, 0x07, 0, 0x04, 0, 0x2a, 0, 0x2b, 0x04, 0, 0, 0x01, (byte) 0xbc, 0x04, 0x02, 0, - 0x05, 0x31, 0x32, 0x4b, 0x2d, 0x32, 0x04, 0x03, 0, 0x01, 0x72, 0x04, 0x03, 0, 0x01, 0x73, 0x04, 0x04, 0, 0x04, - 0x29, 0x29, 0x29, 0x29, + private static final byte[] NODE_ATTR_S = { + 0x01, 0x07, 0, 0x04, 0, 0x2a, 0, 0x2b, 0x04, 0, 0, 0x01, (byte) 0xbc, 0x04, 0x02, 0, 0x05, 0x31, 0x32, 0x4b, + 0x2d, 0x32, 0x04, 0x03, 0, 0x01, 0x72, 0x04, 0x03, 0, 0x01, 0x73, 0x04, 0x04, 0, 0x04, 0x29, 0x29, 0x29, 0x29, 4, 0x0a, 0, 0x0c, (byte)0xe0, 0, 1, 2, 3, 4, (byte)0x89, 0, 3, 1, 2, 0, // sr-caps 4, 0x0b, 0, 2, 0, 1 // sr-algorythms - }; + }; - private static final byte[] P4_ATTR = { 0x04, (byte) 0x80, 0, 0x01, (byte) 0xF0, 0x04, (byte) 0x81, 0, 0x08, 0x12, 0x34, 0x56, 0x78, + private static final byte[] P4_ATTR = { + 0x04, (byte) 0x80, 0, 0x01, (byte) 0xF0, 0x04, (byte) 0x81, 0, 0x08, 0x12, 0x34, 0x56, 0x78, 0x10, 0x30, 0x50, 0x70, 0x04, (byte) 0x82, 0, 0x08, 0x12, 0x34, 0x56, 0x78, 0x10, 0x30, 0x50, 0x70, 0x04, (byte) 0x83, 0, 0x04, 0, 0, 0, 0x0a, 0x04, (byte) 0x84, 0, 0x04, 0x0a, 0x19, 0x02, 0x1b, 4, (byte)0x86, 0,8, (byte)0xf0, 0, 0,0, 1,2,3,4, // prefix-sid tlv 4, (byte)0x87, 0,0x0c, 0, 0, 0, 5, 4, (byte)0x89, 0, 4, 1,2,3,4, // range tlv 4, (byte)0x88, 0, 4, 1, (byte)0xf0, 0, 0 // binding sid tlv - }; + }; private RSVPExtensionProviderContext context; private RSVPActivator rsvpActivator; @@ -148,26 +149,34 @@ public class LinkstateAttributeParserTest { this.rsvpActivator.start(this.context); this.parser = new LinkstateAttributeParser(false,this.context.getRsvpRegistry()); } + private static AttributesBuilder createBuilder(final ObjectType type) { - return new AttributesBuilder().addAugmentation( - org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.Attributes1.class, - new Attributes1Builder().setMpReachNlri( - new MpReachNlriBuilder().setAfi(LinkstateAddressFamily.class).setSafi(LinkstateSubsequentAddressFamily.class).setAdvertizedRoutes( - new AdvertizedRoutesBuilder().setDestinationType( - new DestinationLinkstateCaseBuilder().setDestinationLinkstate( - new DestinationLinkstateBuilder().setCLinkstateDestination( - Lists.newArrayList(new CLinkstateDestinationBuilder().setObjectType(type).setProtocolId(ProtocolId.IsisLevel1).build())).build()).build()).build()).build()).build()); + return new AttributesBuilder().addAugmentation(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang + .bgp.multiprotocol.rev180329.Attributes1.class, new Attributes1Builder().setMpReachNlri( + new MpReachNlriBuilder().setAfi(LinkstateAddressFamily.class) + .setSafi(LinkstateSubsequentAddressFamily.class) + .setAdvertizedRoutes(new AdvertizedRoutesBuilder().setDestinationType( + new DestinationLinkstateCaseBuilder().setDestinationLinkstate( + new DestinationLinkstateBuilder().setCLinkstateDestination( + Lists.newArrayList(new CLinkstateDestinationBuilder().setObjectType(type) + .setProtocolId(ProtocolId.IsisLevel1).build())).build()).build()).build()).build()) + .build()); } private static AttributesBuilder createUnreachBuilder(final ObjectType type) { - return new AttributesBuilder().addAugmentation( - org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.Attributes2.class, - new Attributes2Builder().setMpUnreachNlri( - new MpUnreachNlriBuilder().setAfi(LinkstateAddressFamily.class).setSafi(LinkstateSubsequentAddressFamily.class).setWithdrawnRoutes( - new WithdrawnRoutesBuilder().setDestinationType( - new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationLinkstateCaseBuilder().setDestinationLinkstate( - new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.destination.linkstate._case.DestinationLinkstateBuilder().setCLinkstateDestination( - Lists.newArrayList(new CLinkstateDestinationBuilder().setObjectType(type).setProtocolId(ProtocolId.IsisLevel1).build())).build()).build()).build()).build()).build()); + return new AttributesBuilder().addAugmentation(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang + .bgp.multiprotocol.rev180329.Attributes2.class, new Attributes2Builder().setMpUnreachNlri( + new MpUnreachNlriBuilder().setAfi(LinkstateAddressFamily.class) + .setSafi(LinkstateSubsequentAddressFamily.class) + .setWithdrawnRoutes(new WithdrawnRoutesBuilder().setDestinationType( + new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.update + .attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationLinkstateCaseBuilder() + .setDestinationLinkstate(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang + .bgp.linkstate.rev180329.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type + .destination.linkstate._case.DestinationLinkstateBuilder().setCLinkstateDestination( + Lists.newArrayList(new CLinkstateDestinationBuilder().setObjectType(type) + .setProtocolId(ProtocolId.IsisLevel1).build())).build()).build()).build()).build()) + .build()); } @Test @@ -265,7 +274,7 @@ public class LinkstateAttributeParserTest { buff.skipBytes(4); // there is unresolved TLV at the end, that needs to be cut off - assertArrayEquals(ByteArray.subByte(LINK_ATTR, 0, LINK_ATTR.length -5), ByteArray.getAllBytes(buff)); + assertArrayEquals(ByteArray.subByte(LINK_ATTR, 0, LINK_ATTR.length - 5), ByteArray.getAllBytes(buff)); } @Test @@ -322,8 +331,9 @@ public class LinkstateAttributeParserTest { assertArrayEquals(new byte[] { (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78 }, ls.getRouteTags().get(0) .getValue()); assertEquals(1, ls.getExtendedTags().size()); - assertArrayEquals(new byte[] { (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78, (byte) 0x10, (byte) 0x30, - (byte) 0x50, (byte) 0x70 }, ls.getExtendedTags().get(0).getValue()); + assertArrayEquals(new byte[] { + (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78, (byte) 0x10, (byte) 0x30, (byte) 0x50, (byte) 0x70 + }, ls.getExtendedTags().get(0).getValue()); assertEquals(10, ls.getPrefixMetric().getValue().intValue()); assertEquals("10.25.2.27", ls.getOspfForwardingAddress().getIpv4Address().getValue()); @@ -369,37 +379,4 @@ public class LinkstateAttributeParserTest { assertArrayEquals(TE_LSP_ATTR, ByteArray.getAllBytes(buff)); assertTrue(Arrays.equals(TE_LSP_ATTR, ByteArray.getAllBytes(buff))); } - - @Test(expected=UnsupportedOperationException.class) - public void testLinkAttributesPrivateConstructor() throws Throwable { - final Constructor c = LinkAttributesParser.class.getDeclaredConstructor(); - c.setAccessible(true); - try { - c.newInstance(); - } catch (final InvocationTargetException e) { - throw e.getCause(); - } - } - - @Test(expected=UnsupportedOperationException.class) - public void testNodeAttributesPrivateConstructor() throws Throwable { - final Constructor c = NodeAttributesParser.class.getDeclaredConstructor(); - c.setAccessible(true); - try { - c.newInstance(); - } catch (final InvocationTargetException e) { - throw e.getCause(); - } - } - - @Test(expected=UnsupportedOperationException.class) - public void testPrefixAttributesPrivateConstructor() throws Throwable { - final Constructor c = PrefixAttributesParser.class.getDeclaredConstructor(); - c.setAccessible(true); - try { - c.newInstance(); - } catch (final InvocationTargetException e) { - throw e.getCause(); - } - } } diff --git a/bgp/extensions/linkstate/src/test/java/org/opendaylight/protocol/bgp/linkstate/LinkstateNlriParserTest.java b/bgp/extensions/linkstate/src/test/java/org/opendaylight/protocol/bgp/linkstate/LinkstateNlriParserTest.java index edfde7ce7e..879969cd84 100644 --- a/bgp/extensions/linkstate/src/test/java/org/opendaylight/protocol/bgp/linkstate/LinkstateNlriParserTest.java +++ b/bgp/extensions/linkstate/src/test/java/org/opendaylight/protocol/bgp/linkstate/LinkstateNlriParserTest.java @@ -20,12 +20,12 @@ import java.math.BigInteger; import java.util.List; import org.junit.Test; import org.opendaylight.protocol.bgp.linkstate.impl.BGPActivator; -import org.opendaylight.protocol.bgp.linkstate.spi.AbstractTeLspNlriCodec; import org.opendaylight.protocol.bgp.linkstate.impl.nlri.LinkNlriParser; import org.opendaylight.protocol.bgp.linkstate.impl.nlri.LinkstateNlriParser; import org.opendaylight.protocol.bgp.linkstate.impl.nlri.NodeNlriParser; -import org.opendaylight.protocol.bgp.linkstate.spi.pojo.SimpleNlriTypeRegistry; +import org.opendaylight.protocol.bgp.linkstate.spi.AbstractTeLspNlriCodec; import org.opendaylight.protocol.bgp.linkstate.spi.TlvUtil; +import org.opendaylight.protocol.bgp.linkstate.spi.pojo.SimpleNlriTypeRegistry; import org.opendaylight.protocol.bgp.parser.BGPParsingException; import org.opendaylight.protocol.bgp.parser.spi.BGPExtensionProviderContext; import org.opendaylight.protocol.bgp.parser.spi.pojo.SimpleBGPExtensionProviderContext; @@ -93,47 +93,61 @@ public class LinkstateNlriParserTest { private static final NodeIdentifier C_LINKSTATE_NID = new NodeIdentifier(CLinkstateDestination.QNAME); private static final NodeIdentifier C_ROUTER_ID_NID = new NodeIdentifier(CRouterIdentifier.QNAME); - private final byte[] nodeNlri = new byte[] { (byte) 0x00, (byte) 0x01, (byte) 0x00, (byte) 0x30, (byte) 0x02, (byte) 0x00, (byte) 0x00, - (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x01, (byte) 0x01, (byte) 0x00, (byte) 0x00, (byte) 0x23, - (byte) 0x02, (byte) 0x00, (byte) 0x00, (byte) 0x04, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x48, (byte) 0x02, (byte) 0x01, - (byte) 0x00, (byte) 0x04, (byte) 0x28, (byte) 0x28, (byte) 0x28, (byte) 0x28, (byte) 0x02, (byte) 0x02, (byte) 0x00, (byte) 0x04, - (byte) 0x00, (byte) 0x29, (byte) 0x29, (byte) 0x29, (byte) 0x02, (byte) 0x03, (byte) 0x00, (byte) 0x07, (byte) 0x00, (byte) 0x00, - (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x39, (byte) 0x05 }; + private final byte[] nodeNlri = new byte[] { + (byte) 0x00, (byte) 0x01, (byte) 0x00, (byte) 0x30, (byte) 0x02, (byte) 0x00, (byte) 0x00, (byte) 0x00, + (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x01, (byte) 0x01, (byte) 0x00, (byte) 0x00, + (byte) 0x23, (byte) 0x02, (byte) 0x00, (byte) 0x00, (byte) 0x04, (byte) 0x00, (byte) 0x00, (byte) 0x00, + (byte) 0x48, (byte) 0x02, (byte) 0x01, (byte) 0x00, (byte) 0x04, (byte) 0x28, (byte) 0x28, (byte) 0x28, + (byte) 0x28, (byte) 0x02, (byte) 0x02, (byte) 0x00, (byte) 0x04, (byte) 0x00, (byte) 0x29, (byte) 0x29, + (byte) 0x29, (byte) 0x02, (byte) 0x03, (byte) 0x00, (byte) 0x07, (byte) 0x00, (byte) 0x00, (byte) 0x00, + (byte) 0x00, (byte) 0x00, (byte) 0x39, (byte) 0x05 }; + + private final byte[] linkNlri = new byte[] { + (byte) 0x00, (byte) 0x02, (byte) 0x00, (byte) 0x85, (byte) 0x02, (byte) 0x00, (byte) 0x00, (byte) 0x00, + (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x01, - private final byte[] linkNlri = new byte[] { (byte) 0x00, (byte) 0x02, (byte) 0x00, (byte) 0x85, (byte) 0x02, (byte) 0x00, (byte) 0x00, - (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x01, // local node descriptors (byte) 0x01, (byte) 0x00, (byte) 0x00, (byte) 0x2a, - (byte) 0x02, (byte) 0x00, (byte) 0x00, (byte) 0x04, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x48, (byte) 0x02, (byte) 0x01, - (byte) 0x00, (byte) 0x04, (byte) 0x28, (byte) 0x28, (byte) 0x28, (byte) 0x28, (byte) 0x02, (byte) 0x03, (byte) 0x00, (byte) 0x06, + (byte) 0x02, (byte) 0x00, (byte) 0x00, (byte) 0x04, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x48, + (byte) 0x02, (byte) 0x01, + (byte) 0x00, (byte) 0x04, (byte) 0x28, (byte) 0x28, (byte) 0x28, (byte) 0x28, (byte) 0x02, (byte) 0x03, + (byte) 0x00, (byte) 0x06, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x42, 2, 4, 0, 4, 1, 1, 1, 1, 2, 5, 0, 4, 0, 0, 1, 2, // remote node descriptors (byte) 0x01, (byte) 0x01, (byte) 0x00, (byte) 0x28, - (byte) 0x02, (byte) 0x00, (byte) 0x00, (byte) 0x04, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x48, (byte) 0x02, (byte) 0x01, - (byte) 0x00, (byte) 0x04, (byte) 0x28, (byte) 0x28, (byte) 0x28, (byte) 0x28, (byte) 0x02, (byte) 0x03, (byte) 0x00, (byte) 0x04, + (byte) 0x02, (byte) 0x00, (byte) 0x00, (byte) 0x04, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x48, + (byte) 0x02, (byte) 0x01, + (byte) 0x00, (byte) 0x04, (byte) 0x28, (byte) 0x28, (byte) 0x28, (byte) 0x28, (byte) 0x02, (byte) 0x03, + (byte) 0x00, (byte) 0x04, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x40, 2, 4, 0, 4, 1, 1, 1, 2, 2, 5, 0, 4, 0, 0, 1, 3, // link descriptors 1, 2, 0, 8, 1, 2, 3, 4, 0x0a, - 0x0b, 0x0c, 0x0d, (byte) 0x01, (byte) 0x03, (byte) 0x00, (byte) 0x04, (byte) 0xc5, (byte) 0x14, (byte) 0xa0, (byte) 0x2a, + 0x0b, 0x0c, 0x0d, (byte) 0x01, (byte) 0x03, (byte) 0x00, (byte) 0x04, (byte) 0xc5, (byte) 0x14, (byte) 0xa0, + (byte) 0x2a, (byte) 0x01, (byte) 0x04, (byte) 0x00, (byte) 0x04, (byte) 0xc5, (byte) 0x14, (byte) 0xa0, (byte) 0x28, 1, 7, 0, 2, 0, 3 }; - private final byte[] prefixNlri = new byte[] { (byte) 0x00, (byte) 0x03, (byte) 0x00, (byte) 0x39, (byte) 0x02, (byte) 0x00, - (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x01, (byte) 0x01, (byte) 0x00, (byte) 0x00, - (byte) 0x1a, (byte) 0x02, (byte) 0x00, (byte) 0x00, (byte) 0x04, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x48, (byte) 0x02, - (byte) 0x01, (byte) 0x00, (byte) 0x04, (byte) 0x28, (byte) 0x28, (byte) 0x28, (byte) 0x28, (byte) 0x02, (byte) 0x03, (byte) 0x00, - (byte) 0x06, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x42, (byte) 0x01, (byte) 0x07, (byte) 0x00, - (byte) 0x02, (byte) 0x00, (byte) 0x0F, (byte) 0x01, (byte) 0x08, (byte) 0x00, (byte) 0x01, (byte) 0x03, (byte) 0x01, (byte) 0x09, - (byte) 0x00, (byte) 0x03, (byte) 0x10, (byte) 0xFF, (byte) 0xFF }; - - private final byte[] teLspNlri = new byte[] { (byte) 0x00, (byte) 0x05, //NLRI Type Te-IPV4 + private final byte[] prefixNlri = new byte[] { + (byte) 0x00, (byte) 0x03, (byte) 0x00, (byte) 0x39, (byte) 0x02, (byte) 0x00, (byte) 0x00, (byte) 0x00, + (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x01, (byte) 0x01, (byte) 0x00, (byte) 0x00, + (byte) 0x1a, (byte) 0x02, (byte) 0x00, (byte) 0x00, (byte) 0x04, (byte) 0x00, (byte) 0x00, (byte) 0x00, + (byte) 0x48, (byte) 0x02, (byte) 0x01, (byte) 0x00, (byte) 0x04, (byte) 0x28, (byte) 0x28, (byte) 0x28, + (byte) 0x28, (byte) 0x02, (byte) 0x03, (byte) 0x00, (byte) 0x06, (byte) 0x00, (byte) 0x00, (byte) 0x00, + (byte) 0x00, (byte) 0x00, (byte) 0x42, (byte) 0x01, (byte) 0x07, (byte) 0x00, (byte) 0x02, (byte) 0x00, + (byte) 0x0F, (byte) 0x01, (byte) 0x08, (byte) 0x00, (byte) 0x01, (byte) 0x03, (byte) 0x01, (byte) 0x09, + (byte) 0x00, (byte) 0x03, (byte) 0x10, (byte) 0xFF, (byte) 0xFF + }; + + private final byte[] teLspNlri = new byte[] { + (byte) 0x00, (byte) 0x05, //NLRI Type Te-IPV4 (byte) 0x00, (byte) 0x15, // length (byte) 0x08, //Protocol-ID - (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x01, // Identifier + // Identifier + (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x01, (byte) 0x01, (byte) 0x02, (byte) 0x03, (byte) 0x04, //IPv4 Tunnel Sender Address (byte) 0x00, (byte) 0x01, //Tunnel ID (byte) 0x00, (byte) 0x01, //LSP ID @@ -146,13 +160,15 @@ public class LinkstateNlriParserTest { final LinkstateNlriParser parser = new LinkstateNlriParser(); final MpReachNlriBuilder builder = new MpReachNlriBuilder(); this.registry = SimpleNlriTypeRegistry.getInstance(); - final BGPActivator act = new BGPActivator(true, ServiceLoaderRSVPExtensionProviderContext.getSingletonInstance().getRsvpRegistry()); + final BGPActivator act = new BGPActivator(true, + ServiceLoaderRSVPExtensionProviderContext.getSingletonInstance().getRsvpRegistry()); final BGPExtensionProviderContext context = new SimpleBGPExtensionProviderContext(); act.start(context); parser.parseNlri(Unpooled.copiedBuffer(data), builder, null); - final DestinationLinkstate ls = ((DestinationLinkstateCase) builder.getAdvertizedRoutes().getDestinationType()).getDestinationLinkstate(); + final DestinationLinkstate ls = ((DestinationLinkstateCase) builder.getAdvertizedRoutes().getDestinationType()) + .getDestinationLinkstate(); assertEquals(1, ls.getCLinkstateDestination().size()); this.dest = ls.getCLinkstateDestination().get(0); @@ -166,22 +182,24 @@ public class LinkstateNlriParserTest { assertNull(this.dest.getRouteDistinguisher()); assertEquals(ProtocolId.IsisLevel2, this.dest.getProtocolId()); assertEquals(BigInteger.ONE, this.dest.getIdentifier().getValue()); - final NodeCase nCase = ((NodeCase) this.dest.getObjectType()); + final NodeCase nCase = (NodeCase) this.dest.getObjectType(); final NodeDescriptors nodeD = nCase.getNodeDescriptors(); assertEquals(new AsNumber(72L), nodeD.getAsNumber()); assertEquals(new DomainIdentifier(0x28282828L), nodeD.getDomainId()); assertEquals(new IsisPseudonodeCaseBuilder().setIsisPseudonode( new IsisPseudonodeBuilder().setPsn((short) 5).setIsIsRouterIdentifier( - new IsIsRouterIdentifierBuilder().setIsoSystemId(new IsoSystemIdentifier(new byte[] { 0, 0, 0, 0, 0, (byte) 0x39 })).build()).build()).build(), nodeD.getCRouterIdentifier()); + new IsIsRouterIdentifierBuilder().setIsoSystemId( + new IsoSystemIdentifier(new byte[] { 0, 0, 0, 0, 0, (byte) 0x39 })).build()).build()).build(), + nodeD.getCRouterIdentifier()); final ByteBuf buffer = Unpooled.buffer(); this.registry.serializeNlriType(this.dest, buffer); assertArrayEquals(this.nodeNlri, ByteArray.readAllBytes(buffer)); // test BI form - final DataContainerNodeAttrBuilder linkstateBI = ImmutableUnkeyedListEntryNodeBuilder - .create(); + final DataContainerNodeAttrBuilder linkstateBI = + ImmutableUnkeyedListEntryNodeBuilder.create(); linkstateBI.withNodeIdentifier(C_LINKSTATE_NID); final ImmutableLeafNodeBuilder protocolId = new ImmutableLeafNodeBuilder<>(); @@ -207,7 +225,8 @@ public class LinkstateNlriParserTest { final ImmutableLeafNodeBuilder areaID = new ImmutableLeafNodeBuilder<>(); areaID.withNodeIdentifier(NodeNlriParser.AREA_NID); - areaID.withValue(2697513L); nodeDescriptors.addChild(areaID.build()); + areaID.withValue(2697513L); + nodeDescriptors.addChild(areaID.build()); final ImmutableLeafNodeBuilder domainID = new ImmutableLeafNodeBuilder<>(); domainID.withNodeIdentifier(NodeNlriParser.DOMAIN_NID); @@ -224,12 +243,14 @@ public class LinkstateNlriParserTest { isoSystemID.withNodeIdentifier(NodeNlriParser.ISO_SYSTEM_NID); isoSystemID.withValue(new byte[]{0, 0, 0, 0, 0, (byte) 0x39}); - final DataContainerNodeAttrBuilder isisPseudoRouter = Builders.containerBuilder(); + final DataContainerNodeAttrBuilder isisPseudoRouter = + Builders.containerBuilder(); isisPseudoRouter.withNodeIdentifier(NodeNlriParser.ISIS_ROUTER_NID); isisPseudoRouter.addChild(isoSystemID.build()); isisNode.addChild(isisPseudoRouter.build()); - isisNode.addChild(Builders.leafBuilder().withNodeIdentifier(NodeNlriParser.PSN_NID).withValue((short) 5).build()); + isisNode.addChild(Builders.leafBuilder().withNodeIdentifier(NodeNlriParser.PSN_NID).withValue((short) 5) + .build()); crouterId.addChild(isisNode.build()); nodeDescriptors.addChild(crouterId.build()); @@ -248,23 +269,24 @@ public class LinkstateNlriParserTest { assertEquals(ProtocolId.IsisLevel2, this.dest.getProtocolId()); assertEquals(BigInteger.ONE, this.dest.getIdentifier().getValue()); - final LinkCase lCase = ((LinkCase) this.dest.getObjectType()); + final LinkCase lCase = (LinkCase) this.dest.getObjectType(); final LocalNodeDescriptors local = lCase.getLocalNodeDescriptors(); assertEquals(new AsNumber(72L), local.getAsNumber()); assertEquals(new DomainIdentifier(0x28282828L), local.getDomainId()); assertEquals( new IsisNodeCaseBuilder().setIsisNode( - new IsisNodeBuilder().setIsoSystemId( - new IsoSystemIdentifier(new byte[] { (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, - (byte) 0x42 })).build()).build(), local.getCRouterIdentifier()); + new IsisNodeBuilder().setIsoSystemId(new IsoSystemIdentifier(new byte[] { + (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x42 })).build()).build(), + local.getCRouterIdentifier()); assertEquals("1.1.1.1", local.getBgpRouterId().getValue()); assertEquals(new AsNumber(258L), local.getMemberAsn()); final RemoteNodeDescriptors remote = lCase.getRemoteNodeDescriptors(); assertEquals(new AsNumber(72L), remote.getAsNumber()); assertEquals(new DomainIdentifier(0x28282828L), remote.getDomainId()); - assertEquals(new OspfNodeCaseBuilder().setOspfNode(new OspfNodeBuilder().setOspfRouterId(0x00000040L).build()).build(), + assertEquals(new OspfNodeCaseBuilder().setOspfNode(new OspfNodeBuilder().setOspfRouterId(0x00000040L).build()) + .build(), remote.getCRouterIdentifier()); assertEquals(new AsNumber(259L), remote.getMemberAsn()); assertEquals("1.1.1.2", remote.getBgpRouterId().getValue()); @@ -278,7 +300,8 @@ public class LinkstateNlriParserTest { assertArrayEquals(this.linkNlri, ByteArray.readAllBytes(buffer)); // test BI form - final DataContainerNodeAttrBuilder linkstateBI = ImmutableUnkeyedListEntryNodeBuilder.create(); + final DataContainerNodeAttrBuilder linkstateBI = + ImmutableUnkeyedListEntryNodeBuilder.create(); linkstateBI.withNodeIdentifier(C_LINKSTATE_NID); final ImmutableLeafNodeBuilder protocolId = new ImmutableLeafNodeBuilder<>(); @@ -295,7 +318,8 @@ public class LinkstateNlriParserTest { objectType.withNodeIdentifier(LinkstateNlriParser.OBJECT_TYPE_NID); // local node descriptors - final DataContainerNodeAttrBuilder localNodeDescriptors = Builders.containerBuilder(); + final DataContainerNodeAttrBuilder localNodeDescriptors = + Builders.containerBuilder(); localNodeDescriptors.withNodeIdentifier(LinkstateNlriParser.LOCAL_NODE_DESCRIPTORS_NID); final ImmutableLeafNodeBuilder asNumber = new ImmutableLeafNodeBuilder<>(); @@ -334,7 +358,8 @@ public class LinkstateNlriParserTest { localNodeDescriptors.addChild(memberAsn.build()); // remote descriptors - final DataContainerNodeAttrBuilder remoteNodeDescriptors = Builders.containerBuilder(); + final DataContainerNodeAttrBuilder remoteNodeDescriptors = + Builders.containerBuilder(); remoteNodeDescriptors.withNodeIdentifier(LinkstateNlriParser.REMOTE_NODE_DESCRIPTORS_NID); remoteNodeDescriptors.addChild(asNumber.build()); remoteNodeDescriptors.addChild(domainID.build()); @@ -408,16 +433,15 @@ public class LinkstateNlriParserTest { assertEquals(ProtocolId.IsisLevel2, this.dest.getProtocolId()); assertEquals(BigInteger.ONE, this.dest.getIdentifier().getValue()); - final PrefixCase pCase = ((PrefixCase) this.dest.getObjectType()); + final PrefixCase pCase = (PrefixCase) this.dest.getObjectType(); final AdvertisingNodeDescriptors local = pCase.getAdvertisingNodeDescriptors(); assertEquals(new AsNumber(72L), local.getAsNumber()); assertEquals(new DomainIdentifier(0x28282828L), local.getDomainId()); assertEquals( - new IsisNodeCaseBuilder().setIsisNode( - new IsisNodeBuilder().setIsoSystemId( - new IsoSystemIdentifier(new byte[] { (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, - (byte) 0x42 })).build()).build(), local.getCRouterIdentifier()); + new IsisNodeCaseBuilder().setIsisNode(new IsisNodeBuilder().setIsoSystemId( + new IsoSystemIdentifier(new byte[] { (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, + (byte) 0x42 })).build()).build(), local.getCRouterIdentifier()); final PrefixDescriptors pd = pCase.getPrefixDescriptors(); assertEquals(OspfRouteType.External1, pd.getOspfRouteType()); @@ -429,7 +453,8 @@ public class LinkstateNlriParserTest { assertArrayEquals(this.prefixNlri, ByteArray.readAllBytes(buffer)); // test BI form - final DataContainerNodeAttrBuilder linkstateBI = ImmutableUnkeyedListEntryNodeBuilder.create(); + final DataContainerNodeAttrBuilder linkstateBI = + ImmutableUnkeyedListEntryNodeBuilder.create(); linkstateBI.withNodeIdentifier(C_LINKSTATE_NID); final ImmutableLeafNodeBuilder protocolId = new ImmutableLeafNodeBuilder<>(); @@ -446,7 +471,8 @@ public class LinkstateNlriParserTest { objectType.withNodeIdentifier(LinkstateNlriParser.OBJECT_TYPE_NID); // advertising node descriptors - final DataContainerNodeAttrBuilder advertisingNodeDescriptors = Builders.containerBuilder(); + final DataContainerNodeAttrBuilder advertisingNodeDescriptors = + Builders.containerBuilder(); advertisingNodeDescriptors.withNodeIdentifier(LinkstateNlriParser.ADVERTISING_NODE_DESCRIPTORS_NID); final ImmutableLeafNodeBuilder asNumber = new ImmutableLeafNodeBuilder<>(); @@ -474,7 +500,8 @@ public class LinkstateNlriParserTest { advertisingNodeDescriptors.addChild(crouterId.build()); // prefix descriptors - final DataContainerNodeAttrBuilder prefixDescriptors = Builders.containerBuilder(); + final DataContainerNodeAttrBuilder prefixDescriptors = + Builders.containerBuilder(); prefixDescriptors.withNodeIdentifier(LinkstateNlriParser.PREFIX_DESCRIPTORS_NID); prefixDescriptors.addChild(asNumber.build()); prefixDescriptors.addChild(domainID.build()); @@ -519,7 +546,8 @@ public class LinkstateNlriParserTest { assertEquals(new Ipv4Address("4.3.2.1"), ((Ipv4Case) teCase.getAddressFamily()).getIpv4TunnelEndpointAddress()); // test BI form - final DataContainerNodeAttrBuilder linkstateBI = ImmutableUnkeyedListEntryNodeBuilder.create(); + final DataContainerNodeAttrBuilder linkstateBI = + ImmutableUnkeyedListEntryNodeBuilder.create(); linkstateBI.withNodeIdentifier(C_LINKSTATE_NID); final ImmutableLeafNodeBuilder protocolId = new ImmutableLeafNodeBuilder<>(); @@ -564,14 +592,17 @@ public class LinkstateNlriParserTest { linkstateBI.addChild(objectType.build()); assertEquals(this.dest, LinkstateNlriParser.extractLinkstateDestination(linkstateBI.build())); } + @Test public void testSerializeAttribute() throws BGPParsingException { final LinkstateNlriParser parser = new LinkstateNlriParser(); setUp(this.prefixNlri); final List dests = Lists.newArrayList(this.dest); - final DestinationLinkstateCase dlc = new DestinationLinkstateCaseBuilder().setDestinationLinkstate(new DestinationLinkstateBuilder().setCLinkstateDestination(dests).build()).build(); + final DestinationLinkstateCase dlc = new DestinationLinkstateCaseBuilder().setDestinationLinkstate( + new DestinationLinkstateBuilder().setCLinkstateDestination(dests).build()).build(); final AdvertizedRoutes aroutes = new AdvertizedRoutesBuilder().setDestinationType(dlc).build(); - final Attributes1 reach = new Attributes1Builder().setMpReachNlri(new MpReachNlriBuilder().setAdvertizedRoutes(aroutes).build()).build(); + final Attributes1 reach = new Attributes1Builder().setMpReachNlri(new MpReachNlriBuilder() + .setAdvertizedRoutes(aroutes).build()).build(); Attributes pa = new AttributesBuilder().addAugmentation(Attributes1.class, reach).build(); @@ -581,11 +612,17 @@ public class LinkstateNlriParserTest { setUp(this.nodeNlri); final List destsU = Lists.newArrayList(this.dest); - final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationLinkstateCase dlcU = - new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationLinkstateCaseBuilder().setDestinationLinkstate( - new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type.destination.linkstate._case.DestinationLinkstateBuilder().setCLinkstateDestination(destsU).build()).build(); + final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.update + .attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationLinkstateCase dlcU = + new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.update + .attributes.mp.unreach.nlri.withdrawn.routes.destination.type.DestinationLinkstateCaseBuilder() + .setDestinationLinkstate(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp + .linkstate.rev180329.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type + .destination.linkstate._case.DestinationLinkstateBuilder().setCLinkstateDestination(destsU) + .build()).build(); final WithdrawnRoutes wroutes = new WithdrawnRoutesBuilder().setDestinationType(dlcU).build(); - final Attributes2 unreach = new Attributes2Builder().setMpUnreachNlri(new MpUnreachNlriBuilder().setWithdrawnRoutes(wroutes).build()).build(); + final Attributes2 unreach = new Attributes2Builder().setMpUnreachNlri(new MpUnreachNlriBuilder() + .setWithdrawnRoutes(wroutes).build()).build(); pa = new AttributesBuilder().addAugmentation(Attributes2.class, unreach).build(); diff --git a/bgp/extensions/linkstate/src/test/java/org/opendaylight/protocol/bgp/linkstate/LinkstateRIBSupportTest.java b/bgp/extensions/linkstate/src/test/java/org/opendaylight/protocol/bgp/linkstate/LinkstateRIBSupportTest.java index b3b038724b..32c67df2f3 100644 --- a/bgp/extensions/linkstate/src/test/java/org/opendaylight/protocol/bgp/linkstate/LinkstateRIBSupportTest.java +++ b/bgp/extensions/linkstate/src/test/java/org/opendaylight/protocol/bgp/linkstate/LinkstateRIBSupportTest.java @@ -77,9 +77,11 @@ public final class LinkstateRIBSupportTest extends AbstractRIBSupportTest inputBytes = new ArrayList<>(); + // Used by other tests as well + private static final List INPUT_BYTES = new ArrayList<>(); private static final int COUNTER = 4; @@ -114,19 +112,19 @@ public class ParserTest { .getSingletonInstance().getAttributeRegistry(), mock(NlriRegistry.class)); for (int i = 1; i <= COUNTER; i++) { final String name = "/up" + i + ".bin"; - try (final InputStream is = ParserTest.class.getResourceAsStream(name)){ + try (InputStream is = ParserTest.class.getResourceAsStream(name)) { if (is == null) { throw new IOException("Failed to get resource " + name); } final ByteArrayOutputStream bis = new ByteArrayOutputStream(); final byte[] data = new byte[MAX_SIZE]; - int nRead; - while ((nRead = is.read(data, 0, data.length)) != -1) { - bis.write(data, 0, nRead); + int numRead; + while ((numRead = is.read(data, 0, data.length)) != -1) { + bis.write(data, 0, numRead); } bis.flush(); - inputBytes.add(bis.toByteArray()); + INPUT_BYTES.add(bis.toByteArray()); is.close(); } } @@ -135,7 +133,7 @@ public class ParserTest { @Test public void testResource() { - assertNotNull(inputBytes); + assertNotNull(INPUT_BYTES); } /* @@ -154,8 +152,8 @@ public class ParserTest { */ @Test public void testEORLS() throws Exception { - final byte[] body = ByteArray.cutBytes(inputBytes.get(0), MessageUtil.COMMON_HEADER_LENGTH); - final int messageLength = ByteArray.bytesToInt(ByteArray.subByte(inputBytes.get(0), + final byte[] body = ByteArray.cutBytes(INPUT_BYTES.get(0), MessageUtil.COMMON_HEADER_LENGTH); + final int messageLength = ByteArray.bytesToInt(ByteArray.subByte(INPUT_BYTES.get(0), MessageUtil.MARKER_LENGTH, LENGTH_FIELD_LENGTH)); final Update message = ParserTest.updateParser.parseMessageBody(Unpooled.copiedBuffer(body), messageLength, null); @@ -170,7 +168,7 @@ public class ParserTest { final ByteBuf buffer = Unpooled.buffer(); ParserTest.updateParser.serializeMessage(message, buffer); - assertArrayEquals(inputBytes.get(0), ByteArray.readAllBytes(buffer)); + assertArrayEquals(INPUT_BYTES.get(0), ByteArray.readAllBytes(buffer)); } /* @@ -324,8 +322,8 @@ public class ParserTest { */ @Test public void testBGPLink() throws Exception { - final byte[] body = ByteArray.cutBytes(inputBytes.get(1), MessageUtil.COMMON_HEADER_LENGTH); - final int messageLength = ByteArray.bytesToInt(ByteArray.subByte(inputBytes.get(1), + final byte[] body = ByteArray.cutBytes(INPUT_BYTES.get(1), MessageUtil.COMMON_HEADER_LENGTH); + final int messageLength = ByteArray.bytesToInt(ByteArray.subByte(INPUT_BYTES.get(1), MessageUtil.MARKER_LENGTH, LENGTH_FIELD_LENGTH)); final Update message = ParserTest.updateParser.parseMessageBody(Unpooled.copiedBuffer(body), messageLength, null); @@ -415,9 +413,9 @@ public class ParserTest { paBuilder.addAugmentation(Attributes1.class, lsBuilder.build()); - final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329. - Attributes1Builder lsAttrBuilder = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang. - bgp.linkstate.rev180329.Attributes1Builder(); + final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329 + .Attributes1Builder lsAttrBuilder = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang + .bgp.linkstate.rev180329.Attributes1Builder(); lsAttrBuilder.setLinkStateAttribute( new LinkAttributesCaseBuilder().setLinkAttributes(new LinkAttributesBuilder() @@ -444,7 +442,7 @@ public class ParserTest { final ByteBuf buffer = Unpooled.buffer(); ParserTest.updateParser.serializeMessage(message, buffer); - assertArrayEquals(inputBytes.get(1), ByteArray.readAllBytes(buffer)); + assertArrayEquals(INPUT_BYTES.get(1), ByteArray.readAllBytes(buffer)); } /* @@ -532,9 +530,9 @@ public class ParserTest { */ @Test public void testBGPNode() throws Exception { - final byte[] body = ByteArray.cutBytes(inputBytes.get(2), MessageUtil.COMMON_HEADER_LENGTH); + final byte[] body = ByteArray.cutBytes(INPUT_BYTES.get(2), MessageUtil.COMMON_HEADER_LENGTH); final int messageLength = ByteArray - .bytesToInt(ByteArray.subByte(inputBytes.get(2), MessageUtil.MARKER_LENGTH, LENGTH_FIELD_LENGTH)); + .bytesToInt(ByteArray.subByte(INPUT_BYTES.get(2), MessageUtil.MARKER_LENGTH, LENGTH_FIELD_LENGTH)); final Update message = ParserTest.updateParser.parseMessageBody(Unpooled.copiedBuffer(body), messageLength, null); @@ -623,7 +621,7 @@ public class ParserTest { final ByteBuf buffer = Unpooled.buffer(); ParserTest.updateParser.serializeMessage(message, buffer); - assertArrayEquals(inputBytes.get(2), ByteArray.readAllBytes(buffer)); + assertArrayEquals(INPUT_BYTES.get(2), ByteArray.readAllBytes(buffer)); } /* @@ -660,13 +658,13 @@ public class ParserTest { public void testOpenMessage() throws Exception { final MessageRegistry msgReg = ServiceLoaderBGPExtensionProviderContext .getSingletonInstance().getMessageRegistry(); - final Notification o = msgReg.parseMessage(Unpooled.copiedBuffer(inputBytes.get(3)), null); + final Notification o = msgReg.parseMessage(Unpooled.copiedBuffer(INPUT_BYTES.get(3)), null); final Open open = (Open) o; final Set types = Sets.newHashSet(); for (final BgpParameters param : open.getBgpParameters()) { for (final OptionalCapabilities optCapa : param.getOptionalCapabilities()) { final CParameters cParam = optCapa.getCParameters(); - if(cParam != null && cParam.augmentation(CParameters1.class) != null + if (cParam != null && cParam.augmentation(CParameters1.class) != null && cParam.augmentation(CParameters1.class).getMultiprotocolCapability() != null) { final MultiprotocolCapability mp = cParam.augmentation(CParameters1.class) .getMultiprotocolCapability(); @@ -683,6 +681,6 @@ public class ParserTest { final ByteBuf buffer = Unpooled.buffer(); msgReg.serializeMessage(o, buffer); - assertArrayEquals(inputBytes.get(3), ByteArray.readAllBytes(buffer)); + assertArrayEquals(INPUT_BYTES.get(3), ByteArray.readAllBytes(buffer)); } } diff --git a/bgp/extensions/linkstate/src/test/java/org/opendaylight/protocol/bgp/linkstate/SrAttributeParserTest.java b/bgp/extensions/linkstate/src/test/java/org/opendaylight/protocol/bgp/linkstate/SrAttributeParserTest.java index 6c6dc2c245..79b22963da 100644 --- a/bgp/extensions/linkstate/src/test/java/org/opendaylight/protocol/bgp/linkstate/SrAttributeParserTest.java +++ b/bgp/extensions/linkstate/src/test/java/org/opendaylight/protocol/bgp/linkstate/SrAttributeParserTest.java @@ -14,18 +14,14 @@ import com.google.common.collect.Lists; import com.google.common.primitives.Bytes; import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; -import java.lang.reflect.Constructor; -import java.lang.reflect.InvocationTargetException; import java.util.ArrayList; import java.util.Collections; import java.util.List; import org.junit.Before; import org.junit.Test; import org.opendaylight.protocol.bgp.linkstate.impl.BGPActivator; -import org.opendaylight.protocol.bgp.linkstate.impl.attribute.sr.BindingSidLabelParser; import org.opendaylight.protocol.bgp.linkstate.impl.attribute.sr.Ipv6SrPrefixAttributesParser; import org.opendaylight.protocol.bgp.linkstate.impl.attribute.sr.RangeTlvParser; -import org.opendaylight.protocol.bgp.linkstate.impl.attribute.sr.SidLabelIndexParser; import org.opendaylight.protocol.bgp.linkstate.impl.attribute.sr.SrLinkAttributesParser; import org.opendaylight.protocol.bgp.linkstate.impl.attribute.sr.SrNodeAttributesParser; import org.opendaylight.protocol.bgp.linkstate.impl.attribute.sr.SrPrefixAttributesParser; @@ -93,8 +89,11 @@ public class SrAttributeParserTest { private static final byte[] IPV6_B_BYTES = { 0x20, 1, 0x0d, (byte) 0xb8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2 }; private static final Ipv6Address IPV6_B = new Ipv6Address("2001:db8::2"); - private static final IsisPrefixFlagsCase ISIS_PREFIX_FLAGS = new IsisPrefixFlagsCaseBuilder().setReadvertisement(Boolean.TRUE).setNodeSid(Boolean.FALSE).setNoPhp(Boolean.TRUE).setExplicitNull(Boolean.FALSE).build(); - private static final OspfPrefixFlagsCase OSPF_PREFIX_FLAGS = new OspfPrefixFlagsCaseBuilder().setNoPhp(Boolean.FALSE).setMappingServer(Boolean.TRUE).setExplicitNull(Boolean.FALSE).build(); + private static final IsisPrefixFlagsCase ISIS_PREFIX_FLAGS = new IsisPrefixFlagsCaseBuilder() + .setReadvertisement(Boolean.TRUE).setNodeSid(Boolean.FALSE).setNoPhp(Boolean.TRUE) + .setExplicitNull(Boolean.FALSE).build(); + private static final OspfPrefixFlagsCase OSPF_PREFIX_FLAGS = new OspfPrefixFlagsCaseBuilder() + .setNoPhp(Boolean.FALSE).setMappingServer(Boolean.TRUE).setExplicitNull(Boolean.FALSE).build(); private static final IsisBindingFlagsCase BINDING_FLAGS = new IsisBindingFlagsCaseBuilder() .setAddressFamily(Boolean.FALSE) @@ -116,7 +115,8 @@ public class SrAttributeParserTest { @Before public void setUp() throws Exception { - final BGPActivator act = new BGPActivator(true, ServiceLoaderRSVPExtensionProviderContext.getSingletonInstance().getRsvpRegistry()); + final BGPActivator act = new BGPActivator(true, + ServiceLoaderRSVPExtensionProviderContext.getSingletonInstance().getRsvpRegistry()); final BGPExtensionProviderContext context = new SimpleBGPExtensionProviderContext(); act.start(context); } @@ -124,7 +124,8 @@ public class SrAttributeParserTest { @Test public void testSrAlgorithm() { final byte[] bytes = { 0 }; - final SrAlgorithm alg = new SrAlgorithmBuilder().setAlgorithms(Lists.newArrayList(Algorithm.ShortestPathFirst)).build(); + final SrAlgorithm alg = new SrAlgorithmBuilder().setAlgorithms(Lists.newArrayList(Algorithm.ShortestPathFirst)) + .build(); final SrAlgorithm empty = new SrAlgorithmBuilder().setAlgorithms(Collections.emptyList()).build(); assertEquals(alg, SrNodeAttributesParser.parseSrAlgorithms(Unpooled.wrappedBuffer(bytes))); final ByteBuf b = Unpooled.buffer(); @@ -141,10 +142,16 @@ public class SrAttributeParserTest { public void testSrCapabilities() { final byte[] bytesIsis = { (byte)0xC0, 0, 0, 0, 10, 4, (byte)0x89, 0, 4, 1, 2, 3, 4 }; final byte[] bytesOspf = { 0, 0, 0, 0, 10, 4, (byte)0x89, 0, 4, 1, 2, 3, 4 }; - final SrCapabilities capsIsis = new SrCapabilitiesBuilder().setMplsIpv4(Boolean.TRUE).setMplsIpv6(Boolean.TRUE).setSrIpv6(Boolean.FALSE).setSidLabelIndex(new SidCaseBuilder().setSid(16909060L).build()).setRangeSize((long) 10).build(); - final SrCapabilities capsOspf = new SrCapabilitiesBuilder().setMplsIpv4(Boolean.FALSE).setMplsIpv6(Boolean.FALSE).setSrIpv6(Boolean.FALSE).setSidLabelIndex(new SidCaseBuilder().setSid(16909060L).build()).setRangeSize((long) 10).build(); - assertEquals(capsIsis, SrNodeAttributesParser.parseSrCapabilities(Unpooled.wrappedBuffer(bytesIsis), ProtocolId.IsisLevel1)); - assertEquals(capsOspf, SrNodeAttributesParser.parseSrCapabilities(Unpooled.wrappedBuffer(bytesIsis), ProtocolId.Ospf)); + final SrCapabilities capsIsis = new SrCapabilitiesBuilder().setMplsIpv4(Boolean.TRUE).setMplsIpv6(Boolean.TRUE) + .setSrIpv6(Boolean.FALSE).setSidLabelIndex(new SidCaseBuilder().setSid(16909060L).build()) + .setRangeSize((long) 10).build(); + final SrCapabilities capsOspf = new SrCapabilitiesBuilder().setMplsIpv4(Boolean.FALSE) + .setMplsIpv6(Boolean.FALSE).setSrIpv6(Boolean.FALSE).setSidLabelIndex(new SidCaseBuilder() + .setSid(16909060L).build()).setRangeSize((long) 10).build(); + assertEquals(capsIsis, + SrNodeAttributesParser.parseSrCapabilities(Unpooled.wrappedBuffer(bytesIsis), ProtocolId.IsisLevel1)); + assertEquals(capsOspf, + SrNodeAttributesParser.parseSrCapabilities(Unpooled.wrappedBuffer(bytesIsis), ProtocolId.Ospf)); final ByteBuf encodedIsis = Unpooled.buffer(); final ByteBuf encodedOspf = Unpooled.buffer(); SrNodeAttributesParser.serializeSrCapabilities(capsIsis, encodedIsis); @@ -160,12 +167,16 @@ public class SrAttributeParserTest { final byte[] bytesOspf = { (byte)0x20, 0, 0, 0, 1, 2, 3, 4 }; final SrPrefix prefixIsis = new SrPrefixBuilder() .setFlags(ISIS_PREFIX_FLAGS) - .setAlgorithm(Algorithm.ShortestPathFirst).setSidLabelIndex(new SidCaseBuilder().setSid(16909060L).build()).build(); + .setAlgorithm(Algorithm.ShortestPathFirst).setSidLabelIndex(new SidCaseBuilder().setSid(16909060L).build()) + .build(); final SrPrefix prefixOspf = new SrPrefixBuilder() .setFlags(OSPF_PREFIX_FLAGS) - .setAlgorithm(Algorithm.ShortestPathFirst).setSidLabelIndex(new SidCaseBuilder().setSid(16909060L).build()).build(); - assertEquals(prefixIsis, SrPrefixAttributesParser.parseSrPrefix(Unpooled.wrappedBuffer(bytes), ProtocolId.IsisLevel1)); - assertEquals(prefixOspf, SrPrefixAttributesParser.parseSrPrefix(Unpooled.wrappedBuffer(bytes), ProtocolId.Ospf)); + .setAlgorithm(Algorithm.ShortestPathFirst).setSidLabelIndex(new SidCaseBuilder().setSid(16909060L).build()) + .build(); + assertEquals(prefixIsis, + SrPrefixAttributesParser.parseSrPrefix(Unpooled.wrappedBuffer(bytes), ProtocolId.IsisLevel1)); + assertEquals(prefixOspf, + SrPrefixAttributesParser.parseSrPrefix(Unpooled.wrappedBuffer(bytes), ProtocolId.Ospf)); final ByteBuf serializedPrefix = Unpooled.buffer(); final ByteBuf serializedPrefixOspf = Unpooled.buffer(); SrPrefixAttributesParser.serializeSrPrefix(prefixIsis, serializedPrefix); @@ -206,7 +217,8 @@ public class SrAttributeParserTest { final List rangeSubTlvs = new ArrayList<>(); addSubTlvs(rangeSubTlvs); - final SrRange expected = new SrRangeBuilder().setInterArea(Boolean.FALSE).setRangeSize(5).setSubTlvs(rangeSubTlvs).build(); + final SrRange expected = new SrRangeBuilder().setInterArea(Boolean.FALSE).setRangeSize(5) + .setSubTlvs(rangeSubTlvs).build(); assertEquals(expected, parsedRange); @@ -223,7 +235,8 @@ public class SrAttributeParserTest { new PrefixSidTlvCaseBuilder() .setFlags(ISIS_PREFIX_FLAGS) .setAlgorithm(Algorithm.StrictShortestPathFirst) - .setSidLabelIndex(new LocalLabelCaseBuilder().setLocalLabel(new MplsLabel(66048L)).build()).build()).build()); + .setSidLabelIndex(new LocalLabelCaseBuilder().setLocalLabel(new MplsLabel(66048L)).build()).build()) + .build()); final List bindingSubTlvs = new ArrayList<>(); addBindingSubTlvs(bindingSubTlvs); rangeSubTlvs.add(new SubTlvsBuilder().setRangeSubTlv( @@ -241,17 +254,21 @@ public class SrAttributeParserTest { .setSidLabelIndex(new SidCaseBuilder().setSid(16909060L).build()) .build()).build()); bindingSubTlvs.add(new BindingSubTlvsBuilder().setBindingSubTlv( - new SidLabelCaseBuilder().setSidLabelIndex(new SidCaseBuilder().setSid(16909060L).build()).build()).build()); + new SidLabelCaseBuilder().setSidLabelIndex(new SidCaseBuilder().setSid(16909060L).build()).build()) + .build()); bindingSubTlvs.add(new BindingSubTlvsBuilder().setBindingSubTlv( new EroMetricCaseBuilder().setEroMetric(new TeMetric(6L)).build()).build()); bindingSubTlvs.add(new BindingSubTlvsBuilder().setBindingSubTlv( new Ipv4EroCaseBuilder().setLoose(Boolean.FALSE).setAddress(new Ipv4Address("9.8.7.6")).build()).build()); bindingSubTlvs.add(new BindingSubTlvsBuilder().setBindingSubTlv( - new UnnumberedInterfaceIdEroCaseBuilder().setLoose(Boolean.FALSE).setRouterId(16843009L).setInterfaceId(33686018L).build()).build()); + new UnnumberedInterfaceIdEroCaseBuilder().setLoose(Boolean.FALSE).setRouterId(16843009L) + .setInterfaceId(33686018L).build()).build()); bindingSubTlvs.add(new BindingSubTlvsBuilder().setBindingSubTlv( - new Ipv4EroBackupCaseBuilder().setLoose(Boolean.FALSE).setAddress(new Ipv4Address("3.4.5.6")).build()).build()); + new Ipv4EroBackupCaseBuilder().setLoose(Boolean.FALSE).setAddress(new Ipv4Address("3.4.5.6")).build()) + .build()); bindingSubTlvs.add(new BindingSubTlvsBuilder().setBindingSubTlv( - new UnnumberedInterfaceIdBackupEroCaseBuilder().setLoose(Boolean.FALSE).setRouterId(50529027L).setInterfaceId(67372036L).build()).build()); + new UnnumberedInterfaceIdBackupEroCaseBuilder().setLoose(Boolean.FALSE).setRouterId(50529027L) + .setInterfaceId(67372036L).build()).build()); } @Test @@ -271,13 +288,15 @@ public class SrAttributeParserTest { bindingSubTlvs.add(new BindingSubTlvsBuilder().setBindingSubTlv( new Ipv6EroCaseBuilder().setLoose(Boolean.FALSE).setAddress(new Ipv6Address(IPV6_A)).build()).build()); bindingSubTlvs.add(new BindingSubTlvsBuilder().setBindingSubTlv( - new Ipv6EroBackupCaseBuilder().setLoose(Boolean.FALSE).setAddress(new Ipv6Address(IPV6_B)).build()).build()); + new Ipv6EroBackupCaseBuilder().setLoose(Boolean.FALSE).setAddress(new Ipv6Address(IPV6_B)).build()) + .build()); rangeSubTlvs.add(new SubTlvsBuilder().setRangeSubTlv( new BindingSidTlvCaseBuilder() .setWeight(new Weight((short) 5)) .setFlags(BINDING_FLAGS) .setBindingSubTlvs(bindingSubTlvs).build()).build()); - final SrRange expected = new SrRangeBuilder().setInterArea(Boolean.FALSE).setRangeSize(5).setSubTlvs(rangeSubTlvs).build(); + final SrRange expected = new SrRangeBuilder().setInterArea(Boolean.FALSE).setRangeSize(5) + .setSubTlvs(rangeSubTlvs).build(); assertEquals(expected, parsedRange); @@ -295,14 +314,18 @@ public class SrAttributeParserTest { final SrAdjIds srAdjId = new SrAdjIdsBuilder() .setFlags(ISIS_ADJ_FLAGS) .setWeight(new Weight((short) 10)) - .setSidLabelIndex(new Ipv6AddressCaseBuilder().setIpv6Address(Ipv6Util.addressForByteBuf(Unpooled.copiedBuffer(sidLabel))).build()).build(); + .setSidLabelIndex(new Ipv6AddressCaseBuilder().setIpv6Address( + Ipv6Util.addressForByteBuf(Unpooled.copiedBuffer(sidLabel))).build()).build(); final SrAdjIds ospfAdj = new SrAdjIdsBuilder() .setFlags(OSPF_ADJ_FLAGS) .setWeight(new Weight((short) 10)) - .setSidLabelIndex(new Ipv6AddressCaseBuilder().setIpv6Address(Ipv6Util.addressForByteBuf(Unpooled.copiedBuffer(sidLabel))).build()).build(); + .setSidLabelIndex(new Ipv6AddressCaseBuilder().setIpv6Address( + Ipv6Util.addressForByteBuf(Unpooled.copiedBuffer(sidLabel))).build()).build(); - assertEquals(srAdjId, new SrAdjIdsBuilder(SrLinkAttributesParser.parseAdjacencySegmentIdentifier(Unpooled.wrappedBuffer(tested), ProtocolId.IsisLevel1)).build()); - assertEquals(ospfAdj, new SrAdjIdsBuilder(SrLinkAttributesParser.parseAdjacencySegmentIdentifier(Unpooled.wrappedBuffer(testedOspf), ProtocolId.Ospf)).build()); + assertEquals(srAdjId, new SrAdjIdsBuilder(SrLinkAttributesParser.parseAdjacencySegmentIdentifier( + Unpooled.wrappedBuffer(tested), ProtocolId.IsisLevel1)).build()); + assertEquals(ospfAdj, new SrAdjIdsBuilder(SrLinkAttributesParser.parseAdjacencySegmentIdentifier( + Unpooled.wrappedBuffer(testedOspf), ProtocolId.Ospf)).build()); final ByteBuf serializedData = SrLinkAttributesParser.serializeAdjacencySegmentIdentifier(srAdjId); final ByteBuf serializedOspf = SrLinkAttributesParser.serializeAdjacencySegmentIdentifier(ospfAdj); assertArrayEquals(tested, ByteArray.readAllBytes(serializedData)); @@ -317,100 +340,27 @@ public class SrAttributeParserTest { .setWeight(new Weight((short)10)) .setNeighborId(new Ipv4Address("1.2.3.4")) .setSidLabelIndex(new LocalLabelCaseBuilder().setLocalLabel(new MplsLabel(24000L)).build()).build(); - assertEquals(srLanAdjId, SrLinkAttributesParser.parseLanAdjacencySegmentIdentifier(Unpooled.wrappedBuffer(tested), ProtocolId.Ospf)); + assertEquals(srLanAdjId, SrLinkAttributesParser.parseLanAdjacencySegmentIdentifier( + Unpooled.wrappedBuffer(tested), ProtocolId.Ospf)); final ByteBuf serializedData = SrLinkAttributesParser.serializeLanAdjacencySegmentIdentifier(srLanAdjId); assertArrayEquals(tested, ByteArray.readAllBytes(serializedData)); } @Test public void testSrLanAdjIdIsis() { - final byte[] tested = { (byte)0x60, 10, 0, 0, 1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 }; + final byte[] tested = { (byte)0x60, 10, 0, 0, 1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, + 15, 16 }; final byte[] sidLabel = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}; final byte[] systemId = { 1, 2, 3, 4, 5, 6 }; final SrLanAdjIds srLanAdjId = new SrLanAdjIdsBuilder() .setFlags(ISIS_ADJ_FLAGS) .setWeight(new Weight((short)10)) .setIsoSystemId(new IsoSystemIdentifier(systemId)) - .setSidLabelIndex(new Ipv6AddressCaseBuilder().setIpv6Address(Ipv6Util.addressForByteBuf(Unpooled.copiedBuffer(sidLabel))).build()).build(); - assertEquals(srLanAdjId, SrLinkAttributesParser.parseLanAdjacencySegmentIdentifier(Unpooled.wrappedBuffer(tested), ProtocolId.IsisLevel1)); + .setSidLabelIndex(new Ipv6AddressCaseBuilder().setIpv6Address(Ipv6Util.addressForByteBuf( + Unpooled.copiedBuffer(sidLabel))).build()).build(); + assertEquals(srLanAdjId, SrLinkAttributesParser.parseLanAdjacencySegmentIdentifier( + Unpooled.wrappedBuffer(tested), ProtocolId.IsisLevel1)); final ByteBuf serializedData = SrLinkAttributesParser.serializeLanAdjacencySegmentIdentifier(srLanAdjId); assertArrayEquals(tested, ByteArray.readAllBytes(serializedData)); } - - @Test(expected=UnsupportedOperationException.class) - public void testSrLinkAttributesPrivateConstructor() throws Throwable { - final Constructor c = SrLinkAttributesParser.class.getDeclaredConstructor(); - c.setAccessible(true); - try { - c.newInstance(); - } catch (final InvocationTargetException e) { - throw e.getCause(); - } - } - - @Test(expected=UnsupportedOperationException.class) - public void testSrNodeAttributesPrivateConstructor() throws Throwable { - final Constructor c = SrNodeAttributesParser.class.getDeclaredConstructor(); - c.setAccessible(true); - try { - c.newInstance(); - } catch (final InvocationTargetException e) { - throw e.getCause(); - } - } - - @Test(expected=UnsupportedOperationException.class) - public void testSrPrefixAttributesPrivateConstructor() throws Throwable { - final Constructor c = SrPrefixAttributesParser.class.getDeclaredConstructor(); - c.setAccessible(true); - try { - c.newInstance(); - } catch (final InvocationTargetException e) { - throw e.getCause(); - } - } - - @Test(expected=UnsupportedOperationException.class) - public void testIpv6SrPrefixAttributesPrivateConstructor() throws Throwable { - final Constructor c = Ipv6SrPrefixAttributesParser.class.getDeclaredConstructor(); - c.setAccessible(true); - try { - c.newInstance(); - } catch (final InvocationTargetException e) { - throw e.getCause(); - } - } - - @Test(expected=UnsupportedOperationException.class) - public void testBindingParserPrivateConstructor() throws Throwable { - final Constructor c = BindingSidLabelParser.class.getDeclaredConstructor(); - c.setAccessible(true); - try { - c.newInstance(); - } catch (final InvocationTargetException e) { - throw e.getCause(); - } - } - - @Test(expected=UnsupportedOperationException.class) - public void testRangeTlvParserPrivateConstructor() throws Throwable { - final Constructor c = RangeTlvParser.class.getDeclaredConstructor(); - c.setAccessible(true); - try { - c.newInstance(); - } catch (final InvocationTargetException e) { - throw e.getCause(); - } - } - - @Test(expected=UnsupportedOperationException.class) - public void testSidLabelIndexParserPrivateConstructor() throws Throwable { - final Constructor c = SidLabelIndexParser.class.getDeclaredConstructor(); - c.setAccessible(true); - try { - c.newInstance(); - } catch (final InvocationTargetException e) { - throw e.getCause(); - } - } } diff --git a/bgp/extensions/linkstate/src/test/java/org/opendaylight/protocol/bgp/linkstate/TlvUtilTest.java b/bgp/extensions/linkstate/src/test/java/org/opendaylight/protocol/bgp/linkstate/TlvUtilTest.java deleted file mode 100644 index dc60bd44ed..0000000000 --- a/bgp/extensions/linkstate/src/test/java/org/opendaylight/protocol/bgp/linkstate/TlvUtilTest.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ - -package org.opendaylight.protocol.bgp.linkstate; - -import java.lang.reflect.Constructor; -import java.lang.reflect.InvocationTargetException; -import org.junit.Test; -import org.opendaylight.protocol.bgp.linkstate.spi.TlvUtil; - -public class TlvUtilTest { - - @Test(expected=UnsupportedOperationException.class) - public void testPrivateConstructor() throws Throwable { - final Constructor c = TlvUtil.class.getDeclaredConstructor(); - c.setAccessible(true); - try { - c.newInstance(); - } catch (final InvocationTargetException e) { - throw e.getCause(); - } - } -}