use of org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates in project bgpcep by opendaylight.
the class AbstractFlowspecRIBSupport method processDestination.
@Override
protected final void processDestination(final DOMDataWriteTransaction tx, final YangInstanceIdentifier routesPath, final ContainerNode destination, final ContainerNode attributes, final ApplyRoute function) {
if (destination != null) {
final YangInstanceIdentifier base = routesPath.node(routesContainerIdentifier()).node(routeQName());
final Optional<DataContainerChild<? extends PathArgument, ?>> maybePathIdLeaf = destination.getChild(routePathIdNid());
final String routeKeyValue = this.nlriParser.stringNlri(destination);
final NodeIdentifierWithPredicates routeKey = PathIdUtil.createNidKey(routeQName(), routeKeyQName(), pathIdQName(), routeKeyValue, maybePathIdLeaf);
function.apply(tx, base, routeKey, destination, attributes);
}
}
use of org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates in project bgpcep by opendaylight.
the class AbstractRIBTestSetup method ipv4Input.
public Collection<DataTreeCandidate> ipv4Input(final YangInstanceIdentifier target, final ModificationType type, final Ipv4Prefix... prefix) {
final Collection<DataTreeCandidate> col = new HashSet<>();
final DataTreeCandidate candidate = mock(DataTreeCandidate.class);
final DataTreeCandidateNode rootNode = mock(DataTreeCandidateNode.class);
doReturn(rootNode).when(candidate).getRootNode();
doReturn(type).when(rootNode).getModificationType();
doCallRealMethod().when(rootNode).toString();
doReturn(target).when(candidate).getRootPath();
doCallRealMethod().when(candidate).toString();
final Collection<DataTreeCandidateNode> children = new HashSet<>();
for (final Ipv4Prefix p : prefix) {
final NodeIdentifierWithPredicates routekey = new NodeIdentifierWithPredicates(Ipv4Route.QNAME, PREFIX_QNAME, p);
final DataContainerNodeBuilder<NodeIdentifierWithPredicates, MapEntryNode> b = ImmutableNodes.mapEntryBuilder();
b.withNodeIdentifier(routekey);
b.addChild(Builders.leafBuilder().withNodeIdentifier(new NodeIdentifier(PREFIX_QNAME)).withValue(p).build());
final DataTreeCandidateNode child = mock(DataTreeCandidateNode.class);
doReturn(createIdentifier(p)).when(child).getIdentifier();
doReturn(java.util.Optional.of(b.build())).when(child).getDataAfter();
doReturn(type).when(child).getModificationType();
children.add(child);
}
doReturn(children).when(rootNode).getChildNodes();
col.add(candidate);
return col;
}
use of org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates in project bgpcep by opendaylight.
the class RIBImpl method instantiateServiceInstance.
public synchronized void instantiateServiceInstance() {
this.isServiceInstantiated = true;
setActive(true);
this.domChain = this.domDataBroker.createTransactionChain(this);
LOG.debug("Instantiating RIB table {} at {}", this.ribId, this.yangRibId);
final ContainerNode bgpRib = Builders.containerBuilder().withNodeIdentifier(new NodeIdentifier(BgpRib.QNAME)).addChild(ImmutableNodes.mapNodeBuilder(Rib.QNAME).build()).build();
final MapEntryNode ribInstance = Builders.mapEntryBuilder().withNodeIdentifier(new NodeIdentifierWithPredicates(Rib.QNAME, RIB_ID_QNAME, this.ribId.getValue())).addChild(ImmutableNodes.leafNode(RIB_ID_QNAME, this.ribId.getValue())).addChild(ImmutableNodes.mapNodeBuilder(Peer.QNAME).build()).addChild(Builders.containerBuilder().withNodeIdentifier(new NodeIdentifier(LocRib.QNAME)).addChild(ImmutableNodes.mapNodeBuilder(Tables.QNAME).build()).build()).build();
final DOMDataWriteTransaction trans = this.domChain.newWriteOnlyTransaction();
// merge empty BgpRib + Rib, to make sure the top-level parent structure is present
trans.merge(LogicalDatastoreType.OPERATIONAL, YangInstanceIdentifier.builder().node(BgpRib.QNAME).build(), bgpRib);
trans.put(LogicalDatastoreType.OPERATIONAL, this.yangRibId, ribInstance);
try {
trans.submit().checkedGet();
} catch (final TransactionCommitFailedException e) {
LOG.error("Failed to initiate RIB {}", this.yangRibId, e);
}
LOG.debug("Effective RIB created.");
this.localTablesKeys.forEach(this::startLocRib);
this.localTablesKeys.forEach(this::createLocRibWriter);
}
use of org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates in project bgpcep by opendaylight.
the class RIBSupportContextImpl method createEmptyTableStructure.
@Override
public void createEmptyTableStructure(final DOMDataWriteTransaction tx, final YangInstanceIdentifier tableId) {
final DataContainerNodeBuilder<NodeIdentifierWithPredicates, MapEntryNode> tb = ImmutableNodes.mapEntryBuilder();
tb.withNodeIdentifier((NodeIdentifierWithPredicates) tableId.getLastPathArgument());
tb.withChild(EMPTY_TABLE_ATTRIBUTES);
// tableId is keyed, but that fact is not directly visible from YangInstanceIdentifier, see BUG-2796
final NodeIdentifierWithPredicates tableKey = (NodeIdentifierWithPredicates) tableId.getLastPathArgument();
for (final Entry<QName, Object> e : tableKey.getKeyValues().entrySet()) {
tb.withChild(ImmutableNodes.leafNode(e.getKey(), e.getValue()));
}
final ChoiceNode routes = this.ribSupport.emptyRoutes();
Verify.verifyNotNull(routes, "Null empty routes in %s", this.ribSupport);
Verify.verify(Routes.QNAME.equals(routes.getNodeType()), "Empty routes have unexpected identifier %s, expected %s", routes.getNodeType(), Routes.QNAME);
tx.put(LogicalDatastoreType.OPERATIONAL, tableId, tb.withChild(routes).build());
}
use of org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates in project bgpcep by opendaylight.
the class IdentifierUtils method firstKeyOf.
// FIXME: implement as id.firstIdentifierOf(IS_PEER), null indicating not found
private static NodeIdentifierWithPredicates firstKeyOf(final YangInstanceIdentifier id, final Predicate<PathArgument> match) {
final PathArgument ret = id.getPathArguments().stream().filter(match::apply).findFirst().get();
Preconditions.checkArgument(ret instanceof NodeIdentifierWithPredicates, "Non-key peer identifier %s", ret);
return (NodeIdentifierWithPredicates) ret;
}
Aggregations