@Override public Esi parseEsiModel(final ChoiceNode esiChoice) { Preconditions.checkArgument(esiChoice != null && !esiChoice.getValue().isEmpty(), "ESI is mandatory. Can't be null or empty."); final ContainerNode cont = (ContainerNode) Iterables.getOnlyElement(esiChoice.getValue()); final EsiSerializer serializer = this.modelHandlers.get(cont.getIdentifier()); if (serializer != null) { return serializer.serializeEsi(cont); } LOG.warn("Unrecognized ESI {}", esiChoice); return null; }
public static boolean isTeLsp(final ChoiceNode objectType) { return objectType.getChild(ADDRESS_FAMILY).isPresent(); }
@Override protected NormalizedNode<?, ?> createEmptyValue(final NormalizedNode<?, ?> original) { checkArgument(original instanceof ChoiceNode); return ImmutableChoiceNodeBuilder.create().withNodeIdentifier(((ChoiceNode) original).getIdentifier()).build(); } }
writer.startChoiceNode(n.getIdentifier(), OrderedNormalizedNodeWriter.childSizeHint(n.getValue())); return writeChildren(n.getValue(), dataSchemaNode, true);
@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()); }
writer.startChoiceNode(n.getIdentifier(), childSizeHint(n.getValue())); processedAsCompositeNode = writeChildren(n.getValue());
writer.startChoiceNode(n.getIdentifier(), childSizeHint(n.getValue())); return writeChildren(n.getValue());
private EvpnChoice getEvpnCase(final ChoiceNode evpnChoice, final SerializerInterface serializerInterface) { Preconditions.checkArgument(evpnChoice != null && !evpnChoice.getValue().isEmpty(), "Evpn case is mandatory. Can't be null or empty."); final ContainerNode cont = (ContainerNode) Iterables.getOnlyElement(evpnChoice.getValue()); final EvpnSerializer serializer = this.modelHandlers.get(cont.getIdentifier()); if (serializer == null) { return null; } return serializerInterface.check(serializer, cont); } }
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; }
@Override protected NormalizedNode<?, ?> createEmptyValue(final NormalizedNode<?, ?> original) { checkArgument(original instanceof ChoiceNode); return ImmutableChoiceNodeBuilder.create().withNodeIdentifier(((ChoiceNode) original).getIdentifier()).build(); } }
writer.startChoiceNode(n.getIdentifier(), childSizeHint(n.getValue())); return writeChildren(n.getValue());
@SuppressWarnings("unchecked") @Override public D deserialize(final NormalizedNode<?, ?> data) { checkArgument(data instanceof ChoiceNode); final ChoiceNode casted = (ChoiceNode) data; final NormalizedNode<?, ?> first = Iterables.getFirst(casted.getValue(), null); if (first == null) { // FIXME: this needs to be sorted out return null; } final DataContainerCodecPrototype<?> caze = byYangCaseChild.get(first.getIdentifier()); return (D) caze.get().deserialize(data); }
private static ContainerNode getDestination(final DataContainerChild<? extends PathArgument, ?> routes, final NodeIdentifier destinationId) { if (routes instanceof ContainerNode) { final Optional<DataContainerChild<? extends PathArgument, ?>> maybeDestination = ((ContainerNode)routes).getChild(DESTINATION_TYPE); if (maybeDestination.isPresent()) { final DataContainerChild<? extends PathArgument, ?> destination = maybeDestination.get(); if (destination instanceof ChoiceNode) { final Optional<DataContainerChild<? extends PathArgument, ?>> maybeRet = ((ChoiceNode)destination).getChild(destinationId); if (maybeRet.isPresent()) { final DataContainerChild<? extends PathArgument, ?> ret = maybeRet.get(); if (ret instanceof ContainerNode) { return (ContainerNode)ret; } else { LOG.debug("Specified node {} is not a container, ignoring it", ret); } } else { LOG.debug("Specified container {} is not present in destination {}", destinationId, destination); } } else { LOG.warn("Destination {} is not a choice, ignoring it", destination); } } else { LOG.debug("Destination is not present in routes {}", routes); } } else { LOG.warn("Advertized routes {} are not a container, ignoring it", routes); } return null; }
private DataContainerChild<?, ?> processChoiceNode(final NormalizedNode<?, ?> node, final Integer depth) { final ChoiceNode choiceNode = (ChoiceNode) node; DataContainerNodeBuilder<NodeIdentifier, ChoiceNode> newChoiceBuilder = Builders.choiceBuilder() .withNodeIdentifier(choiceNode.getIdentifier()); processDataContainerChild((DataContainerNode<?>) node, depth, newChoiceBuilder); return newChoiceBuilder.build(); }
private void enforceCases(final NormalizedNode<?, ?> normalizedNode) { Verify.verify(normalizedNode instanceof ChoiceNode); final Collection<DataContainerChild<?, ?>> children = ((ChoiceNode) normalizedNode).getValue(); if (!children.isEmpty()) { final DataContainerChild<?, ?> firstChild = children.iterator().next(); final CaseEnforcer enforcer = Verify.verifyNotNull(caseEnforcers.get(firstChild.getIdentifier()), "Case enforcer cannot be null. Most probably, child node %s of choice node %s does not belong " + "in current tree type.", firstChild.getIdentifier(), normalizedNode.getIdentifier()); // Make sure no leaves from other cases are present for (final CaseEnforcer other : exclusions.get(enforcer)) { for (final PathArgument id : other.getAllChildIdentifiers()) { final Optional<NormalizedNode<?, ?>> maybeChild = NormalizedNodes.getDirectChild(normalizedNode, id); Preconditions.checkArgument(!maybeChild.isPresent(), "Child %s (from case %s) implies non-presence of child %s (from case %s), which is %s", firstChild.getIdentifier(), enforcer, id, other, maybeChild.orElse(null)); } } // Make sure all mandatory children are present enforcer.enforceOnTreeNode(normalizedNode); } }
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(); }
private void enforceCases(final NormalizedNode<?, ?> normalizedNode) { Verify.verify(normalizedNode instanceof ChoiceNode); final Collection<DataContainerChild<?, ?>> children = ((ChoiceNode) normalizedNode).getValue(); if (!children.isEmpty()) { final DataContainerChild<?, ?> firstChild = children.iterator().next(); final CaseEnforcer enforcer = Verify.verifyNotNull(caseEnforcers.get(firstChild.getIdentifier()), "Case enforcer cannot be null. Most probably, child node %s of choice node %s does not belong " + "in current tree type.", firstChild.getIdentifier(), normalizedNode.getIdentifier()); // Make sure no leaves from other cases are present for (final CaseEnforcer other : exclusions.get(enforcer)) { for (final PathArgument id : other.getAllChildIdentifiers()) { final Optional<NormalizedNode<?, ?>> maybeChild = NormalizedNodes.getDirectChild(normalizedNode, id); Preconditions.checkArgument(!maybeChild.isPresent(), "Child %s (from case %s) implies non-presence of child %s (from case %s), which is %s", firstChild.getIdentifier(), enforcer, id, other, maybeChild.orElse(null)); } } // Make sure all mandatory children are present enforcer.enforceOnTreeNode(normalizedNode); } }
private static void serializeLocalNodeDescriptor(final CLinkstateDestinationBuilder builder, final ChoiceNode objectType) { // link local node descriptors final LinkCaseBuilder linkBuilder = new LinkCaseBuilder(); linkBuilder.setLocalNodeDescriptors(NodeNlriParser.serializeLocalNodeDescriptors((ContainerNode) objectType.getChild(LOCAL_NODE_DESCRIPTORS_NID).get())); // link remote node descriptors if (objectType.getChild(REMOTE_NODE_DESCRIPTORS_NID).isPresent()) { linkBuilder.setRemoteNodeDescriptors(NodeNlriParser.serializeRemoteNodeDescriptors((ContainerNode) objectType.getChild(REMOTE_NODE_DESCRIPTORS_NID).get())); } // link descriptors final Optional<DataContainerChild<? extends PathArgument, ?>> linkDescriptors = objectType.getChild(LINK_DESCRIPTORS_NID); if (linkDescriptors.isPresent()) { linkBuilder.setLinkDescriptors(LinkNlriParser.serializeLinkDescriptors((ContainerNode) linkDescriptors.get())); } builder.setObjectType(linkBuilder.build()); }
for (DataContainerChild<? extends YangInstanceIdentifier.PathArgument, ?> child : modification.get().getValue()) { Optional<ChoiceCaseNode> detectedCaseForChild = SchemaUtils.detectCase(schema, child);
private static void serializeAdvertisedNodeDescriptor(final CLinkstateDestinationBuilder builder, final ChoiceNode objectType) { // prefix node descriptors final PrefixCaseBuilder prefixBuilder = new PrefixCaseBuilder(); prefixBuilder.setAdvertisingNodeDescriptors(NodeNlriParser.serializeAdvNodeDescriptors((ContainerNode) objectType.getChild( ADVERTISING_NODE_DESCRIPTORS_NID).get())); // prefix descriptors final Optional<DataContainerChild<? extends PathArgument, ?>> prefixDescriptors = objectType.getChild(PREFIX_DESCRIPTORS_NID); if (prefixDescriptors.isPresent()) { prefixBuilder.setPrefixDescriptors(AbstractPrefixNlriParser.serializePrefixDescriptors((ContainerNode) prefixDescriptors.get())); } builder.setObjectType(prefixBuilder.build()); }