Search in sources :

Example 31 with ChoiceNode

use of org.opendaylight.yangtools.yang.data.api.schema.ChoiceNode in project bgpcep by opendaylight.

the class LinkstateNlriParserTest method testNodeNlri.

@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();
    this.registry.serializeNlriType(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 });
    final DataContainerNodeAttrBuilder<NodeIdentifier, ContainerNode> 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());
    crouterId.addChild(isisNode.build());
    nodeDescriptors.addChild(crouterId.build());
    objectType.addChild(nodeDescriptors.build());
    linkstateBI.addChild(objectType.build());
    assertEquals(this.dest, LinkstateNlriParser.extractLinkstateDestination(linkstateBI.build()));
}
Also used : IsisPseudonodeBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev171207.node.identifier.c.router.identifier.isis.pseudonode._case.IsisPseudonodeBuilder) UnkeyedListEntryNode(org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListEntryNode) NodeDescriptors(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev171207.linkstate.object.type.node._case.NodeDescriptors) AdvertisingNodeDescriptors(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev171207.linkstate.object.type.prefix._case.AdvertisingNodeDescriptors) LocalNodeDescriptors(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev171207.linkstate.object.type.link._case.LocalNodeDescriptors) RemoteNodeDescriptors(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev171207.linkstate.object.type.link._case.RemoteNodeDescriptors) IsoSystemIdentifier(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.concepts.rev131125.IsoSystemIdentifier) ByteBuf(io.netty.buffer.ByteBuf) AsNumber(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber) IsisPseudonodeCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev171207.node.identifier.c.router.identifier.IsisPseudonodeCaseBuilder) NodeCase(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev171207.linkstate.object.type.NodeCase) NodeIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier) BigInteger(java.math.BigInteger) ChoiceNode(org.opendaylight.yangtools.yang.data.api.schema.ChoiceNode) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) ImmutableLeafNodeBuilder(org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableLeafNodeBuilder) IsIsRouterIdentifierBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev171207.isis.lan.identifier.IsIsRouterIdentifierBuilder) DomainIdentifier(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev171207.DomainIdentifier) Test(org.junit.Test)

Example 32 with ChoiceNode

use of org.opendaylight.yangtools.yang.data.api.schema.ChoiceNode in project bgpcep by opendaylight.

the class LinkstateNlriParserTest method testPrefixNlri.

@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();
    this.registry.serializeNlriType(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(IP_REACH_NID);
    ipReachabilityInformation.withValue("255.255.0.0/16");
    prefixDescriptors.addChild(ipReachabilityInformation.build());
    final ImmutableLeafNodeBuilder<String> ospfRouteType = new ImmutableLeafNodeBuilder<>();
    ospfRouteType.withNodeIdentifier(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()));
}
Also used : PrefixDescriptors(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev171207.linkstate.object.type.prefix._case.PrefixDescriptors) UnkeyedListEntryNode(org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListEntryNode) ByteBuf(io.netty.buffer.ByteBuf) IsisNodeCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev171207.node.identifier.c.router.identifier.IsisNodeCaseBuilder) AdvertisingNodeDescriptors(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev171207.linkstate.object.type.prefix._case.AdvertisingNodeDescriptors) ChoiceNode(org.opendaylight.yangtools.yang.data.api.schema.ChoiceNode) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) Ipv4Prefix(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix) DomainIdentifier(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev171207.DomainIdentifier) TopologyIdentifier(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev171207.TopologyIdentifier) PrefixCase(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev171207.linkstate.object.type.PrefixCase) IsoSystemIdentifier(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.concepts.rev131125.IsoSystemIdentifier) AsNumber(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber) BigInteger(java.math.BigInteger) IsisNodeBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev171207.node.identifier.c.router.identifier.isis.node._case.IsisNodeBuilder) NodeIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier) BigInteger(java.math.BigInteger) ImmutableLeafNodeBuilder(org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableLeafNodeBuilder) Test(org.junit.Test)

Example 33 with ChoiceNode

use of org.opendaylight.yangtools.yang.data.api.schema.ChoiceNode in project bgpcep by opendaylight.

the class NodeNlriParser method serializeRouterId.

private static CRouterIdentifier serializeRouterId(final ContainerNode descriptorsData) {
    CRouterIdentifier cRouterId = null;
    final Optional<DataContainerChild<? extends PathArgument, ?>> 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());
        } else if (routerId.getChild(ISIS_PSEUDONODE_NID).isPresent()) {
            cRouterId = 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());
        } else if (routerId.getChild(OSPF_PSEUDONODE_NID).isPresent()) {
            cRouterId = serializeOspfPseudoNode((ContainerNode) routerId.getChild(OSPF_PSEUDONODE_NID).get());
        }
    }
    return cRouterId;
}
Also used : CRouterIdentifier(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev171207.node.identifier.CRouterIdentifier) DataContainerChild(org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild) ChoiceNode(org.opendaylight.yangtools.yang.data.api.schema.ChoiceNode) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) PathArgument(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument)

Example 34 with ChoiceNode

use of org.opendaylight.yangtools.yang.data.api.schema.ChoiceNode in project bgpcep by opendaylight.

the class AbstractTeLspNlriCodec method serializeTeLsp.

public static TeLspCase serializeTeLsp(final ChoiceNode objectType) {
    final TeLspCaseBuilder teLsp = new TeLspCaseBuilder();
    teLsp.setLspId(new LspId((Long) objectType.getChild(LSP_ID).get().getValue()));
    teLsp.setTunnelId(new TunnelId((Integer) objectType.getChild(TUNNEL_ID).get().getValue()));
    final ChoiceNode addressFamily = (ChoiceNode) objectType.getChild(ADDRESS_FAMILY).get();
    teLsp.setAddressFamily(serializeAddressFamily(addressFamily, addressFamily.getChild(IPV4_TUNNEL_SENDER_ADDRESS).isPresent()));
    return teLsp.build();
}
Also used : LspId(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.LspId) ChoiceNode(org.opendaylight.yangtools.yang.data.api.schema.ChoiceNode) TeLspCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev171207.linkstate.object.type.TeLspCaseBuilder) TunnelId(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.TunnelId)

Aggregations

ChoiceNode (org.opendaylight.yangtools.yang.data.api.schema.ChoiceNode)34 Test (org.junit.Test)22 AbstractRIBSupportTest (org.opendaylight.protocol.bgp.rib.spi.AbstractRIBSupportTest)12 Routes (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.rib.tables.Routes)12 NodeIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier)11 ContainerNode (org.opendaylight.yangtools.yang.data.api.schema.ContainerNode)9 UnkeyedListEntryNode (org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListEntryNode)6 EvpnChoice (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev171213.evpn.EvpnChoice)5 MapEntryNode (org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode)5 BigInteger (java.math.BigInteger)4 ImmutableLeafNodeBuilder (org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableLeafNodeBuilder)4 ByteBuf (io.netty.buffer.ByteBuf)3 LanParserTest (org.opendaylight.protocol.bgp.evpn.impl.esi.types.LanParserTest)3 AsNumber (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber)3 QName (org.opendaylight.yangtools.yang.common.QName)3 Before (org.junit.Before)2 DOMDataWriteTransaction (org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction)2 EsRouteBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev171213.es.route.EsRouteBuilder)2 EsRouteCase (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev171213.evpn.evpn.choice.EsRouteCase)2 EsRouteCaseBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev171213.evpn.evpn.choice.EsRouteCaseBuilder)2