use of org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListEntryNode in project bgpcep by opendaylight.
the class AbstractLabeledUnicastRIBSupport method processDestination.
@Override
protected void processDestination(final DOMDataWriteTransaction tx, final YangInstanceIdentifier routesPath, final ContainerNode destination, final ContainerNode attributes, final ApplyRoute function) {
if (destination != null) {
final Optional<DataContainerChild<? extends PathArgument, ?>> maybeRoutes = destination.getChild(NLRI_ROUTES_LIST);
if (maybeRoutes.isPresent()) {
final DataContainerChild<? extends PathArgument, ?> routes = maybeRoutes.get();
if (routes instanceof UnkeyedListNode) {
final YangInstanceIdentifier base = routesPath.node(routesContainerIdentifier()).node(routeNid());
for (final UnkeyedListEntryNode e : ((UnkeyedListNode) routes).getValue()) {
final NodeIdentifierWithPredicates routeKey = createRouteKey(e);
function.apply(tx, base, routeKey, e, attributes);
}
} else {
LOG.warn("Routes {} are not a map", routes);
}
}
}
}
use of org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListEntryNode in project bgpcep by opendaylight.
the class AbstractLabeledUnicastRIBSupport method extractLabel.
public static List<LabelStack> extractLabel(final DataContainerNode<? extends PathArgument> route, final NodeIdentifier labelStackNid, final NodeIdentifier labelValueNid) {
final List<LabelStack> labels = new ArrayList<>();
final Optional<DataContainerChild<? extends PathArgument, ?>> labelStacks = route.getChild(labelStackNid);
if (labelStacks.isPresent()) {
for (final UnkeyedListEntryNode label : ((UnkeyedListNode) labelStacks.get()).getValue()) {
final Optional<DataContainerChild<? extends PathArgument, ?>> labelStack = label.getChild(labelValueNid);
if (labelStack.isPresent()) {
final LabelStackBuilder labelStackbuilder = new LabelStackBuilder();
labelStackbuilder.setLabelValue(new MplsLabel((Long) labelStack.get().getValue()));
labels.add(labelStackbuilder.build());
}
}
}
return labels;
}
use of org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListEntryNode in project bgpcep by opendaylight.
the class LinkstateNlriParserTest method testLinkNlri.
@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();
this.registry.serializeNlriType(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()));
}
use of org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListEntryNode in project bgpcep by opendaylight.
the class LinkstateNlriParserTest method testTELspNlri.
@Test
public void testTELspNlri() throws BGPParsingException {
setUp(this.teLspNlri);
// test BA form
assertNull(this.dest.getDistinguisher());
assertEquals(ProtocolId.RsvpTe, this.dest.getProtocolId());
assertEquals(BigInteger.ONE, this.dest.getIdentifier().getValue());
final TeLspCase teCase = (TeLspCase) this.dest.getObjectType();
assertEquals(new LspId(1L), teCase.getLspId());
assertEquals(new TunnelId(1), teCase.getTunnelId());
assertEquals(new Ipv4Address("1.2.3.4"), ((Ipv4Case) teCase.getAddressFamily()).getIpv4TunnelSenderAddress());
assertEquals(new Ipv4Address("4.3.2.1"), ((Ipv4Case) teCase.getAddressFamily()).getIpv4TunnelEndpointAddress());
// 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("rsvp-te");
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 ImmutableLeafNodeBuilder<Long> lspId = new ImmutableLeafNodeBuilder<>();
lspId.withNodeIdentifier(AbstractTeLspNlriCodec.LSP_ID);
lspId.withValue(1L);
final ImmutableLeafNodeBuilder<Integer> tunnelId = new ImmutableLeafNodeBuilder<>();
tunnelId.withNodeIdentifier(AbstractTeLspNlriCodec.TUNNEL_ID);
tunnelId.withValue(1);
final DataContainerNodeBuilder<NodeIdentifier, ChoiceNode> addressFamily = Builders.choiceBuilder();
addressFamily.withNodeIdentifier(AbstractTeLspNlriCodec.ADDRESS_FAMILY);
final ImmutableLeafNodeBuilder<String> ipv4TunnelSenderAddress = new ImmutableLeafNodeBuilder<>();
ipv4TunnelSenderAddress.withNodeIdentifier(AbstractTeLspNlriCodec.IPV4_TUNNEL_SENDER_ADDRESS);
ipv4TunnelSenderAddress.withValue("1.2.3.4");
final ImmutableLeafNodeBuilder<String> ipv4TunnelEndPointAddress = new ImmutableLeafNodeBuilder<>();
ipv4TunnelEndPointAddress.withNodeIdentifier(AbstractTeLspNlriCodec.IPV4_TUNNEL_ENDPOINT_ADDRESS);
ipv4TunnelEndPointAddress.withValue("4.3.2.1");
addressFamily.addChild(ipv4TunnelSenderAddress.build());
addressFamily.addChild(ipv4TunnelEndPointAddress.build());
objectType.addChild(lspId.build());
objectType.addChild(tunnelId.build());
objectType.addChild(addressFamily.build());
linkstateBI.addChild(objectType.build());
assertEquals(this.dest, LinkstateNlriParser.extractLinkstateDestination(linkstateBI.build()));
}
use of org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListEntryNode in project bgpcep by opendaylight.
the class EvpnNlriParserTest method testExtractRouteKey.
@Test
public void testExtractRouteKey() throws BGPParsingException {
final DataContainerNodeAttrBuilder<NodeIdentifier, UnkeyedListEntryNode> evpnBI = ImmutableUnkeyedListEntryNodeBuilder.create();
evpnBI.withNodeIdentifier(EVPN_CHOICE_NID);
evpnBI.withChild(createValueBuilder(RD_MODEL, RD_NID).build());
evpnBI.withChild(createMACIpAdvChoice());
final EvpnDestination destResult = EvpnNlriParser.extractRouteKeyDestination(evpnBI.build());
final EvpnDestination expected = new EvpnDestinationBuilder().setRouteDistinguisher(RD).setEvpnChoice(MACIpAdvRParserTest.createdExpectedRouteKey()).build();
assertEquals(expected, destResult);
}
Aggregations