use of org.opendaylight.yangtools.yang.data.api.schema.ContainerNode in project bgpcep by opendaylight.
the class CodecsImpl method serializeAttributes.
@Override
public ContainerNode serializeAttributes(final Attributes pathAttr) {
Preconditions.checkState(this.attributesCodec != null, "Attributes codec not available");
final AttributesBuilder a = new AttributesBuilder(pathAttr);
a.addAugmentation(Attributes1.class, null);
a.addAugmentation(Attributes2.class, null);
return (ContainerNode) this.attributesCodec.serialize(a.build());
}
use of org.opendaylight.yangtools.yang.data.api.schema.ContainerNode 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.ContainerNode in project bgpcep by opendaylight.
the class TableContext method serializeAttributes.
private ContainerNode serializeAttributes(final Attributes pathAttr) {
Preconditions.checkState(this.attributesCodec != null, "Attributes codec not available");
final AttributesBuilder a = new AttributesBuilder(pathAttr);
a.addAugmentation(Attributes1.class, null);
a.addAugmentation(Attributes2.class, null);
return (ContainerNode) this.attributesCodec.serialize(a.build());
}
use of org.opendaylight.yangtools.yang.data.api.schema.ContainerNode in project bgpcep by opendaylight.
the class AbstractRIBSupportTest method createNlriAdvertiseRoute.
protected final ContainerNode createNlriAdvertiseRoute(final DestinationType destReach) {
final MpReachNlri mpReach = new MpReachNlriBuilder().setAdvertizedRoutes(new AdvertizedRoutesBuilder().setDestinationType(destReach).build()).build();
final Map.Entry<YangInstanceIdentifier, NormalizedNode<?, ?>> result = this.mappingService.toNormalizedNode(MP_REACH_IID, mpReach);
return (ContainerNode) result.getValue();
}
use of org.opendaylight.yangtools.yang.data.api.schema.ContainerNode in project bgpcep by opendaylight.
the class MultiPathAbstractRIBSupportTest method setUp.
@Before
public void setUp() {
this.routesMap = new HashMap<>();
MockitoAnnotations.initMocks(this);
this.emptyTree = Mockito.mock(DataTreeCandidateNode.class);
this.emptySubTree = Mockito.mock(DataTreeCandidateNode.class);
this.subTree = Mockito.mock(DataTreeCandidateNode.class);
final DataTreeCandidateNode emptyNode = Mockito.mock(DataTreeCandidateNode.class);
final DataTreeCandidateNode node = Mockito.mock(DataTreeCandidateNode.class);
doReturn(null).when(this.emptyTree).getModifiedChild(IPV4_ROUTES_IDENTIFIER);
doReturn(emptyNode).when(this.emptySubTree).getModifiedChild(IPV4_ROUTES_IDENTIFIER);
doReturn(null).when(emptyNode).getModifiedChild(new NodeIdentifier(Ipv4Route.QNAME));
doReturn(node).when(this.subTree).getModifiedChild(IPV4_ROUTES_IDENTIFIER);
doReturn(node).when(node).getModifiedChild(new NodeIdentifier(Ipv4Route.QNAME));
final Collection<DataTreeCandidateNode> emptyCollection = new HashSet<>();
doReturn(emptyCollection).when(node).getChildNodes();
this.tx = Mockito.mock(DOMDataWriteTransaction.class);
this.nlri = Mockito.mock(ContainerNode.class);
this.attributes = ImmutableContainerNodeBuilder.create().withNodeIdentifier(new NodeIdentifier(QName.create(Ipv4Routes.QNAME, Attributes.QNAME.getLocalName().intern()))).build();
final ContainerNode destination = Mockito.mock(ContainerNode.class);
final ChoiceNode destinations = Mockito.mock(ChoiceNode.class);
final ContainerNode route = Mockito.mock(ContainerNode.class);
final Optional<?> optional = Optional.of(destination);
final Optional<?> destinationOptional = Optional.of(destinations);
final Optional<?> destinationsOptional = Optional.of(route);
doReturn(optional).when(this.nlri).getChild(new NodeIdentifier(WithdrawnRoutes.QNAME));
doReturn(optional).when(this.nlri).getChild(new NodeIdentifier(AdvertizedRoutes.QNAME));
doReturn(destinationOptional).when(destination).getChild(new NodeIdentifier(DestinationType.QNAME));
doReturn(destinationsOptional).when(destinations).getChild(new NodeIdentifier(Ipv4Prefixes.QNAME));
doReturn(emptyCollection).when(route).getValue();
doAnswer(invocation -> {
final Object[] args = invocation.getArguments();
MultiPathAbstractRIBSupportTest.this.routesMap.remove(args[1]);
return args[1];
}).when(this.tx).delete(Mockito.eq(LogicalDatastoreType.OPERATIONAL), any(YangInstanceIdentifier.class));
doAnswer(invocation -> {
final Object[] args = invocation.getArguments();
final NormalizedNode<?, ?> node1 = (NormalizedNode<?, ?>) args[2];
MultiPathAbstractRIBSupportTest.this.routesMap.put((YangInstanceIdentifier) args[1], node1);
return args[1];
}).when(this.tx).put(Mockito.eq(LogicalDatastoreType.OPERATIONAL), any(YangInstanceIdentifier.class), any(NormalizedNode.class));
this.mapEntryNode = Mockito.mock(MapEntryNode.class);
}
Aggregations