@Test
  public void testSerializeAttribute() throws BGPParsingException {
    final LinkstateNlriParser parser = new LinkstateNlriParser(true);
    setUp(this.prefixNlri);
    final List<CLinkstateDestination> dests = Lists.newArrayList(this.dest);
    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();

    Attributes pa = new AttributesBuilder().addAugmentation(Attributes1.class, reach).build();

    ByteBuf result = Unpooled.buffer();
    parser.serializeAttribute(pa, result);
    assertArrayEquals(this.prefixNlri, ByteArray.getAllBytes(result));

    setUp(this.nodeNlri);
    final List<CLinkstateDestination> destsU = Lists.newArrayList(this.dest);
    final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev150210
            .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
                    .rev150210.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.rev150210.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();

    pa = new AttributesBuilder().addAugmentation(Attributes2.class, unreach).build();

    result = Unpooled.buffer();
    parser.serializeAttribute(pa, result);
    assertArrayEquals(this.nodeNlri, ByteArray.getAllBytes(result));
  }
Ejemplo n.º 2
0
  public static List<byte[]> parseMessages(final String c) {
    final String content = clearWhiteSpaceToUpper(c);
    final int sixteen = 16;
    final int four = 4;
    // search for 16 FFs

    final List<byte[]> messages = Lists.newLinkedList();
    int idx = content.indexOf(FF_16, 0);
    while (idx > -1) {
      // next 2 bytes are length
      final int lengthIdx = idx + sixteen * 2;
      final int messageIdx = lengthIdx + four;
      final String hexLength = content.substring(lengthIdx, messageIdx);
      final byte[] byteLength = BaseEncoding.base16().decode(hexLength);
      final int length = ByteArray.bytesToInt(byteLength);
      final int messageEndIdx = idx + length * 2;

      // Assert that message is longer than minimum 19(header.length == 19)
      // If length in BGP message would be 0, loop would never end
      Preconditions.checkArgument(
          length >= MINIMAL_LENGTH,
          "Invalid message at index " + idx + ", length atribute is lower than " + MINIMAL_LENGTH);

      final String hexMessage = content.substring(idx, messageEndIdx);
      final byte[] message = BaseEncoding.base16().decode(hexMessage);
      messages.add(message);
      idx = messageEndIdx;
      idx = content.indexOf(FF_16, idx);
    }
    LOG.info("Succesfully extracted {} messages", messages.size());
    return messages;
  }
Ejemplo n.º 3
0
 @Override
 public Tlv parseTlv(final ByteBuf buffer) throws BmpDeserializationException {
   if (buffer == null) {
     return null;
   }
   return new PerAfiSafiLocRibTlvBuilder()
       .setAfi(this.afiRegistry.classForFamily(buffer.readUnsignedShort()))
       .setSafi(this.safiRegistry.classForFamily(buffer.readUnsignedByte()))
       .setCount(new Gauge64(new BigInteger(ByteArray.readAllBytes(buffer))))
       .build();
 }
 @Override
 public SubobjectContainer parseSubobject(final ByteBuf buffer) throws RSVPParsingException {
   Preconditions.checkArgument(
       buffer != null && buffer.isReadable(),
       "Array of bytes is mandatory. Can't be null or empty.");
   if (buffer.readableBytes() != CONTENT_LENGTH) {
     throw new RSVPParsingException(
         "Wrong length of array of bytes. Passed: "
             + buffer.readableBytes()
             + "; Expected: >"
             + CONTENT_LENGTH
             + ".");
   }
   final int pathKey = buffer.readUnsignedShort();
   final byte[] pceId = ByteArray.readBytes(buffer, PCE_ID_F_LENGTH);
   final SubobjectContainerBuilder builder = new SubobjectContainerBuilder();
   final PathKeyBuilder pBuilder = new PathKeyBuilder();
   pBuilder.setPceId(new PceId(pceId));
   pBuilder.setPathKey(new PathKey(pathKey));
   builder.setSubobjectType(new PathKeyCaseBuilder().setPathKey(pBuilder.build()).build());
   return builder.build();
 }
 @Override
 public ExtendedCommunities parseExtendedCommunity(
     final ReferenceCache refCache, final ExtendedCommunitiesBuilder comm, final ByteBuf buffer)
     throws BGPDocumentedException {
   ExtendedCommunity c = null;
   if (comm.getCommType().equals(FS_TYPE)) {
     switch (comm.getCommSubType()) {
       case TRAFFIC_RATE_SUBTYPE:
         final ShortAsNumber as = new ShortAsNumber((long) buffer.readUnsignedShort());
         final Bandwidth value = new Bandwidth(ByteArray.readBytes(buffer, TRAFFIC_RATE_SIZE));
         c =
             new TrafficRateExtendedCommunityCaseBuilder()
                 .setTrafficRateExtendedCommunity(
                     new TrafficRateExtendedCommunityBuilder()
                         .setInformativeAs(as)
                         .setLocalAdministrator(value)
                         .build())
                 .build();
         break;
       case TRAFFIC_ACTION_SUBTYPE:
         buffer.skipBytes(RESERVED);
         final BitArray flags = BitArray.valueOf(buffer, FLAGS_SIZE);
         final boolean sample = flags.get(SAMPLE_BIT);
         final boolean terminal = flags.get(TERMINAL_BIT);
         c =
             new TrafficActionExtendedCommunityCaseBuilder()
                 .setTrafficActionExtendedCommunity(
                     new TrafficActionExtendedCommunityBuilder()
                         .setSample(sample)
                         .setTerminalAction(terminal)
                         .build())
                 .build();
         break;
       case REDIRECT_SUBTYPE:
         final ShortAsNumber as1 = new ShortAsNumber((long) buffer.readUnsignedShort());
         final byte[] byteValue = ByteArray.readBytes(buffer, TRAFFIC_RATE_SIZE);
         c =
             new RedirectExtendedCommunityCaseBuilder()
                 .setRedirectExtendedCommunity(
                     new RedirectExtendedCommunityBuilder()
                         .setGlobalAdministrator(as1)
                         .setLocalAdministrator(byteValue)
                         .build())
                 .build();
         break;
       case TRAFFIC_MARKING_SUBTYPE:
         buffer.skipBytes(RESERVED);
         final Dscp dscp = new Dscp(buffer.readUnsignedByte());
         c =
             new TrafficMarkingExtendedCommunityCaseBuilder()
                 .setTrafficMarkingExtendedCommunity(
                     new TrafficMarkingExtendedCommunityBuilder()
                         .setGlobalAdministrator(dscp)
                         .build())
                 .build();
         break;
       default:
         throw new BGPDocumentedException(
             "Could not parse Flowspec Extended Community type: " + comm.getCommSubType(),
             BGPError.OPT_ATTR_ERROR);
     }
   }
   if (c == null) {
     LOG.debug("Extended community is not from Flowspec, fallback to original communities.");
     return super.parseExtendedCommunity(refCache, comm, buffer);
   }
   return comm.setExtendedCommunity(c).build();
 }
  @Test
  public void testPrefixNlri() throws BGPParsingException {
    setUp(this.prefixNlri);

    // test BA form
    assertNull(this.dest.getDistinguisher());
    assertEquals(ProtocolId.IsisLevel2, this.dest.getProtocolId());
    assertEquals(BigInteger.ONE, this.dest.getIdentifier().getValue());

    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());

    final PrefixDescriptors pd = pCase.getPrefixDescriptors();
    assertEquals(OspfRouteType.External1, pd.getOspfRouteType());
    assertEquals(new TopologyIdentifier(15), pd.getMultiTopologyId());
    assertEquals(
        new Ipv4Prefix("255.255.0.0/16"), pd.getIpReachabilityInformation().getIpv4Prefix());

    final ByteBuf buffer = Unpooled.buffer();
    LinkstateNlriParser.serializeNlri(this.dest, buffer);
    assertArrayEquals(this.prefixNlri, ByteArray.readAllBytes(buffer));

    // test BI form
    final DataContainerNodeAttrBuilder<YangInstanceIdentifier.NodeIdentifier, UnkeyedListEntryNode>
        linkstateBI = ImmutableUnkeyedListEntryNodeBuilder.create();
    linkstateBI.withNodeIdentifier(C_LINKSTATE_NID);

    final ImmutableLeafNodeBuilder<String> protocolId = new ImmutableLeafNodeBuilder<>();
    protocolId.withNodeIdentifier(LinkstateNlriParser.PROTOCOL_ID_NID);
    protocolId.withValue("isis-level2");
    linkstateBI.addChild(protocolId.build());

    final ImmutableLeafNodeBuilder<BigInteger> identifier = new ImmutableLeafNodeBuilder<>();
    identifier.withNodeIdentifier(LinkstateNlriParser.IDENTIFIER_NID);
    identifier.withValue(BigInteger.ONE);
    linkstateBI.addChild(identifier.build());

    final DataContainerNodeBuilder<NodeIdentifier, ChoiceNode> objectType =
        Builders.choiceBuilder();
    objectType.withNodeIdentifier(LinkstateNlriParser.OBJECT_TYPE_NID);

    // advertising node descriptors
    final DataContainerNodeAttrBuilder<NodeIdentifier, ContainerNode> advertisingNodeDescriptors =
        Builders.containerBuilder();
    advertisingNodeDescriptors.withNodeIdentifier(
        LinkstateNlriParser.ADVERTISING_NODE_DESCRIPTORS_NID);

    final ImmutableLeafNodeBuilder<Long> asNumber = new ImmutableLeafNodeBuilder<>();
    asNumber.withNodeIdentifier(NodeNlriParser.AS_NUMBER_NID);
    asNumber.withValue(72L);
    advertisingNodeDescriptors.addChild(asNumber.build());

    final ImmutableLeafNodeBuilder<Long> domainID = new ImmutableLeafNodeBuilder<>();
    domainID.withNodeIdentifier(NodeNlriParser.DOMAIN_NID);
    domainID.withValue(673720360L);
    advertisingNodeDescriptors.addChild(domainID.build());

    final DataContainerNodeBuilder<NodeIdentifier, ChoiceNode> crouterId = Builders.choiceBuilder();
    crouterId.withNodeIdentifier(C_ROUTER_ID_NID);

    final DataContainerNodeAttrBuilder<NodeIdentifier, ContainerNode> isisNode =
        Builders.containerBuilder();
    isisNode.withNodeIdentifier(NodeNlriParser.ISIS_NODE_NID);

    final ImmutableLeafNodeBuilder<byte[]> isoSystemID = new ImmutableLeafNodeBuilder<>();
    isoSystemID.withNodeIdentifier(NodeNlriParser.ISO_SYSTEM_NID);
    isoSystemID.withValue(new byte[] {0, 0, 0, 0, 0, (byte) 0x42});

    isisNode.addChild(isoSystemID.build());
    crouterId.addChild(isisNode.build());
    advertisingNodeDescriptors.addChild(crouterId.build());

    // prefix descriptors
    final DataContainerNodeAttrBuilder<NodeIdentifier, ContainerNode> prefixDescriptors =
        Builders.containerBuilder();
    prefixDescriptors.withNodeIdentifier(LinkstateNlriParser.PREFIX_DESCRIPTORS_NID);
    prefixDescriptors.addChild(asNumber.build());
    prefixDescriptors.addChild(domainID.build());

    final ImmutableLeafNodeBuilder<Integer> multiTopologyId = new ImmutableLeafNodeBuilder<>();
    multiTopologyId.withNodeIdentifier(TlvUtil.MULTI_TOPOLOGY_NID);
    multiTopologyId.withValue(15);

    prefixDescriptors.addChild(multiTopologyId.build());

    final ImmutableLeafNodeBuilder<String> ipReachabilityInformation =
        new ImmutableLeafNodeBuilder<>();
    ipReachabilityInformation.withNodeIdentifier(PrefixNlriParser.IP_REACH_NID);
    ipReachabilityInformation.withValue("255.255.0.0/16");

    prefixDescriptors.addChild(ipReachabilityInformation.build());

    final ImmutableLeafNodeBuilder<String> ospfRouteType = new ImmutableLeafNodeBuilder<>();
    ospfRouteType.withNodeIdentifier(PrefixNlriParser.OSPF_ROUTE_NID);
    ospfRouteType.withValue("external1");

    prefixDescriptors.addChild(ospfRouteType.build());

    objectType.addChild(advertisingNodeDescriptors.build());
    objectType.addChild(prefixDescriptors.build());

    linkstateBI.addChild(objectType.build());
    assertEquals(this.dest, LinkstateNlriParser.extractLinkstateDestination(linkstateBI.build()));
  }
  @Test
  public void testLinkNlri() throws BGPParsingException {
    setUp(this.linkNlri);

    // test BA form
    assertNull(this.dest.getDistinguisher());
    assertEquals(ProtocolId.IsisLevel2, this.dest.getProtocolId());
    assertEquals(BigInteger.ONE, this.dest.getIdentifier().getValue());

    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());
    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(),
        remote.getCRouterIdentifier());
    assertEquals(new AsNumber(259L), remote.getMemberAsn());
    assertEquals("1.1.1.2", remote.getBgpRouterId().getValue());

    final LinkDescriptors ld = lCase.getLinkDescriptors();
    assertEquals("197.20.160.42", ld.getIpv4InterfaceAddress().getValue());
    assertEquals("197.20.160.40", ld.getIpv4NeighborAddress().getValue());

    final ByteBuf buffer = Unpooled.buffer();
    LinkstateNlriParser.serializeNlri(this.dest, buffer);
    assertArrayEquals(this.linkNlri, ByteArray.readAllBytes(buffer));

    // test BI form
    final DataContainerNodeAttrBuilder<YangInstanceIdentifier.NodeIdentifier, UnkeyedListEntryNode>
        linkstateBI = ImmutableUnkeyedListEntryNodeBuilder.create();
    linkstateBI.withNodeIdentifier(C_LINKSTATE_NID);

    final ImmutableLeafNodeBuilder<String> protocolId = new ImmutableLeafNodeBuilder<>();
    protocolId.withNodeIdentifier(LinkstateNlriParser.PROTOCOL_ID_NID);
    protocolId.withValue("isis-level2");
    linkstateBI.addChild(protocolId.build());

    final ImmutableLeafNodeBuilder<BigInteger> identifier = new ImmutableLeafNodeBuilder<>();
    identifier.withNodeIdentifier(LinkstateNlriParser.IDENTIFIER_NID);
    identifier.withValue(BigInteger.ONE);
    linkstateBI.addChild(identifier.build());

    final DataContainerNodeBuilder<NodeIdentifier, ChoiceNode> objectType =
        Builders.choiceBuilder();
    objectType.withNodeIdentifier(LinkstateNlriParser.OBJECT_TYPE_NID);

    // local node descriptors
    final DataContainerNodeAttrBuilder<NodeIdentifier, ContainerNode> localNodeDescriptors =
        Builders.containerBuilder();
    localNodeDescriptors.withNodeIdentifier(LinkstateNlriParser.LOCAL_NODE_DESCRIPTORS_NID);

    final ImmutableLeafNodeBuilder<Long> asNumber = new ImmutableLeafNodeBuilder<>();
    asNumber.withNodeIdentifier(NodeNlriParser.AS_NUMBER_NID);
    asNumber.withValue(72L);
    localNodeDescriptors.addChild(asNumber.build());

    final ImmutableLeafNodeBuilder<Long> domainID = new ImmutableLeafNodeBuilder<>();
    domainID.withNodeIdentifier(NodeNlriParser.DOMAIN_NID);
    domainID.withValue(0x28282828L);
    localNodeDescriptors.addChild(domainID.build());

    final DataContainerNodeBuilder<NodeIdentifier, ChoiceNode> crouterId = Builders.choiceBuilder();
    crouterId.withNodeIdentifier(C_ROUTER_ID_NID);

    final DataContainerNodeAttrBuilder<NodeIdentifier, ContainerNode> isisNode =
        Builders.containerBuilder();
    isisNode.withNodeIdentifier(NodeNlriParser.ISIS_NODE_NID);

    final ImmutableLeafNodeBuilder<byte[]> isoSystemID = new ImmutableLeafNodeBuilder<>();
    isoSystemID.withNodeIdentifier(NodeNlriParser.ISO_SYSTEM_NID);
    isoSystemID.withValue(new byte[] {0, 0, 0, 0, 0, (byte) 0x42});

    isisNode.addChild(isoSystemID.build());
    crouterId.addChild(isisNode.build());
    localNodeDescriptors.addChild(crouterId.build());

    final ImmutableLeafNodeBuilder<String> bgpRouterId = new ImmutableLeafNodeBuilder<>();
    bgpRouterId.withNodeIdentifier(NodeNlriParser.BGP_ROUTER_NID);
    bgpRouterId.withValue("1.1.1.1");

    final ImmutableLeafNodeBuilder<Long> memberAsn = new ImmutableLeafNodeBuilder<>();
    memberAsn.withNodeIdentifier(NodeNlriParser.MEMBER_ASN_NID);
    memberAsn.withValue(258L);

    localNodeDescriptors.addChild(bgpRouterId.build());
    localNodeDescriptors.addChild(memberAsn.build());

    // remote descriptors
    final DataContainerNodeAttrBuilder<NodeIdentifier, ContainerNode> remoteNodeDescriptors =
        Builders.containerBuilder();
    remoteNodeDescriptors.withNodeIdentifier(LinkstateNlriParser.REMOTE_NODE_DESCRIPTORS_NID);
    remoteNodeDescriptors.addChild(asNumber.build());
    remoteNodeDescriptors.addChild(domainID.build());

    final DataContainerNodeBuilder<NodeIdentifier, ChoiceNode> crouterId2 =
        Builders.choiceBuilder();
    crouterId2.withNodeIdentifier(C_ROUTER_ID_NID);

    final DataContainerNodeAttrBuilder<NodeIdentifier, ContainerNode> ospfNode =
        Builders.containerBuilder();
    ospfNode.withNodeIdentifier(NodeNlriParser.OSPF_NODE_NID);

    final ImmutableLeafNodeBuilder<Long> ospfRouterId = new ImmutableLeafNodeBuilder<>();
    ospfRouterId.withNodeIdentifier(NodeNlriParser.OSPF_ROUTER_NID);
    ospfRouterId.withValue(0x00000040L);
    ospfNode.addChild(ospfRouterId.build());
    crouterId2.addChild(ospfNode.build());
    remoteNodeDescriptors.addChild(crouterId2.build());
    final ImmutableLeafNodeBuilder<String> bgpRouterIdRemote = new ImmutableLeafNodeBuilder<>();
    bgpRouterIdRemote.withNodeIdentifier(NodeNlriParser.BGP_ROUTER_NID);
    bgpRouterIdRemote.withValue("1.1.1.2");
    remoteNodeDescriptors.addChild(bgpRouterIdRemote.build());

    final ImmutableLeafNodeBuilder<Long> memberAsnRemote = new ImmutableLeafNodeBuilder<>();
    memberAsnRemote.withNodeIdentifier(NodeNlriParser.MEMBER_ASN_NID);
    memberAsnRemote.withValue(259L);
    remoteNodeDescriptors.addChild(memberAsnRemote.build());

    // link descritpors
    final DataContainerNodeAttrBuilder<NodeIdentifier, ContainerNode> linkDescriptors =
        Builders.containerBuilder();
    linkDescriptors.withNodeIdentifier(LinkstateNlriParser.LINK_DESCRIPTORS_NID);

    final ImmutableLeafNodeBuilder<Long> linkLocalIdentifier = new ImmutableLeafNodeBuilder<>();
    linkLocalIdentifier.withNodeIdentifier(LinkNlriParser.LINK_LOCAL_NID);
    linkLocalIdentifier.withValue(16909060L);

    final ImmutableLeafNodeBuilder<Long> linkRemoteIdentifier = new ImmutableLeafNodeBuilder<>();
    linkRemoteIdentifier.withNodeIdentifier(LinkNlriParser.LINK_REMOTE_NID);
    linkRemoteIdentifier.withValue(168496141L);

    final ImmutableLeafNodeBuilder<String> ipv4InterfaceAddress = new ImmutableLeafNodeBuilder<>();
    ipv4InterfaceAddress.withNodeIdentifier(LinkNlriParser.IPV4_IFACE_NID);
    ipv4InterfaceAddress.withValue("197.20.160.42");

    final ImmutableLeafNodeBuilder<String> ipv4NeighborAddress = new ImmutableLeafNodeBuilder<>();
    ipv4NeighborAddress.withNodeIdentifier(LinkNlriParser.IPV4_NEIGHBOR_NID);
    ipv4NeighborAddress.withValue("197.20.160.40");

    final ImmutableLeafNodeBuilder<Integer> multiTopologyId = new ImmutableLeafNodeBuilder<>();
    multiTopologyId.withNodeIdentifier(TlvUtil.MULTI_TOPOLOGY_NID);
    multiTopologyId.withValue(3);

    linkDescriptors.addChild(linkLocalIdentifier.build());
    linkDescriptors.addChild(linkRemoteIdentifier.build());
    linkDescriptors.addChild(ipv4InterfaceAddress.build());
    linkDescriptors.addChild(ipv4NeighborAddress.build());
    linkDescriptors.addChild(multiTopologyId.build());

    objectType.addChild(localNodeDescriptors.build());
    objectType.addChild(remoteNodeDescriptors.build());
    objectType.addChild(linkDescriptors.build());

    linkstateBI.addChild(objectType.build());
    assertEquals(this.dest, LinkstateNlriParser.extractLinkstateDestination(linkstateBI.build()));
  }
  @Test
  public void testNodeNlri() throws BGPParsingException {
    setUp(this.nodeNlri);

    // test BA form
    assertNull(this.dest.getDistinguisher());
    assertEquals(ProtocolId.IsisLevel2, this.dest.getProtocolId());
    assertEquals(BigInteger.ONE, this.dest.getIdentifier().getValue());
    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());

    final ByteBuf buffer = Unpooled.buffer();
    LinkstateNlriParser.serializeNlri(this.dest, buffer);
    assertArrayEquals(this.nodeNlri, ByteArray.readAllBytes(buffer));

    // test BI form
    final DataContainerNodeAttrBuilder<YangInstanceIdentifier.NodeIdentifier, UnkeyedListEntryNode>
        linkstateBI = ImmutableUnkeyedListEntryNodeBuilder.create();
    linkstateBI.withNodeIdentifier(C_LINKSTATE_NID);

    final ImmutableLeafNodeBuilder<String> protocolId = new ImmutableLeafNodeBuilder<>();
    protocolId.withNodeIdentifier(LinkstateNlriParser.PROTOCOL_ID_NID);
    protocolId.withValue("isis-level2");
    linkstateBI.addChild(protocolId.build());

    final ImmutableLeafNodeBuilder<BigInteger> identifier = new ImmutableLeafNodeBuilder<>();
    identifier.withNodeIdentifier(LinkstateNlriParser.IDENTIFIER_NID);
    identifier.withValue(BigInteger.ONE);
    linkstateBI.addChild(identifier.build());

    final DataContainerNodeBuilder<NodeIdentifier, ChoiceNode> objectType =
        Builders.choiceBuilder();
    objectType.withNodeIdentifier(LinkstateNlriParser.OBJECT_TYPE_NID);

    final DataContainerNodeAttrBuilder<NodeIdentifier, ContainerNode> nodeDescriptors =
        Builders.containerBuilder();
    nodeDescriptors.withNodeIdentifier(LinkstateNlriParser.NODE_DESCRIPTORS_NID);

    final ImmutableLeafNodeBuilder<Long> asNumber = new ImmutableLeafNodeBuilder<>();
    asNumber.withNodeIdentifier(NodeNlriParser.AS_NUMBER_NID);
    asNumber.withValue(72L);
    nodeDescriptors.addChild(asNumber.build());

    final ImmutableLeafNodeBuilder<Long> areaID = new ImmutableLeafNodeBuilder<>();
    areaID.withNodeIdentifier(NodeNlriParser.AREA_NID);
    areaID.withValue(2697513L);
    nodeDescriptors.addChild(areaID.build());

    final ImmutableLeafNodeBuilder<Long> domainID = new ImmutableLeafNodeBuilder<>();
    domainID.withNodeIdentifier(NodeNlriParser.DOMAIN_NID);
    domainID.withValue(0x28282828L);
    nodeDescriptors.addChild(domainID.build());

    final DataContainerNodeBuilder<NodeIdentifier, ChoiceNode> crouterId = Builders.choiceBuilder();
    crouterId.withNodeIdentifier(C_ROUTER_ID_NID);

    final DataContainerNodeAttrBuilder<NodeIdentifier, ContainerNode> isisNode =
        Builders.containerBuilder();
    isisNode.withNodeIdentifier(NodeNlriParser.ISIS_PSEUDONODE_NID);

    final ImmutableLeafNodeBuilder<byte[]> isoSystemID = new ImmutableLeafNodeBuilder<>();
    isoSystemID.withNodeIdentifier(NodeNlriParser.ISO_SYSTEM_NID);
    isoSystemID.withValue(new byte[] {0, 0, 0, 0, 0, (byte) 0x39});
    isisNode.addChild(isoSystemID.build());
    isisNode.addChild(
        Builders.leafBuilder()
            .withNodeIdentifier(NodeNlriParser.PSN_NID)
            .withValue((short) 5)
            .build());
    crouterId.addChild(isisNode.build());

    nodeDescriptors.addChild(crouterId.build());
    objectType.addChild(nodeDescriptors.build());
    linkstateBI.addChild(objectType.build());

    assertEquals(this.dest, LinkstateNlriParser.extractLinkstateDestination(linkstateBI.build()));
  }