private List<UnkeyedListEntryNode> unkeyedListEntries(UnkeyedListNode unkeyedListNode) { List<UnkeyedListEntryNode> unkeyedListEntries = Lists.newArrayList(); for (UnkeyedListEntryNode unkeyedListEntryNode : unkeyedListNode.getValue()) { unkeyedListEntries.add(unkeyedListEntryNode); } return unkeyedListEntries; }
public final List<Flowspec> extractFlowspec(final DataContainerNode<?> route) { Preconditions.checkNotNull(route, "Cannot extract flowspec from null route."); final List<Flowspec> fsList = new ArrayList<>(); final Optional<DataContainerChild<? extends PathArgument, ?>> flowspecs = route.getChild(FLOWSPEC_NID); if (flowspecs.isPresent()) { for (final UnkeyedListEntryNode flowspec : ((UnkeyedListNode) flowspecs.get()).getValue()) { final FlowspecBuilder fsBuilder = new FlowspecBuilder(); final Optional<DataContainerChild<?, ?>> flowspecType = flowspec.getChild(FLOWSPEC_TYPE_NID); if (flowspecType.isPresent()) { final ChoiceNode fsType = (ChoiceNode) flowspecType.get(); processFlowspecType(fsType, fsBuilder); } fsList.add(fsBuilder.build()); } } return fsList; }
private void processRoute(final Optional<DataContainerChild<? extends PathArgument, ?>> maybeRoutes, final YangInstanceIdentifier routesPath, final ContainerNode attributes, final ApplyRoute function, final DOMDataWriteTransaction tx) { if (maybeRoutes.isPresent()) { final DataContainerChild<? extends PathArgument, ?> routes = maybeRoutes.get(); if (routes instanceof UnkeyedListNode) { final YangInstanceIdentifier base = routesPath.node(routesContainerIdentifier()).node(this.route); 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); } } }
private static final List<FlowLabel> createFlowLabels(final UnkeyedListNode flowLabelsData) { final List<FlowLabel> flowLabels = new ArrayList<>(); for (final UnkeyedListEntryNode node : flowLabelsData.getValue()) { final FlowLabelBuilder flowLabelsBuilder = new FlowLabelBuilder(); final Optional<DataContainerChild<? extends PathArgument, ?>> opValue = node.getChild(AbstractFlowspecNlriParser.OP_NID); if (opValue.isPresent()) { flowLabelsBuilder.setOp(NumericOneByteOperandParser.INSTANCE.create((Set<String>) opValue.get().getValue())); } final Optional<DataContainerChild<? extends PathArgument, ?>> valueNode = node.getChild(AbstractFlowspecNlriParser.VALUE_NID); if (valueNode.isPresent()) { flowLabelsBuilder.setValue((Long) valueNode.get().getValue()); } flowLabels.add(flowLabelsBuilder.build()); } return flowLabels; }
private static List<Ports> createPorts(final UnkeyedListNode portsData) { final List<Ports> ports = new ArrayList<>(); for (final UnkeyedListEntryNode node : portsData.getValue()) { final PortsBuilder portsBuilder = new PortsBuilder(); final Optional<DataContainerChild<? extends PathArgument, ?>> opValue = node.getChild(OP_NID); if (opValue.isPresent()) { portsBuilder.setOp(NumericTwoByteOperandParser.INSTANCE.create((Set<String>) opValue.get().getValue())); } final Optional<DataContainerChild<? extends PathArgument, ?>> valueNode = node.getChild(VALUE_NID); if (valueNode.isPresent()) { portsBuilder.setValue((Integer) valueNode.get().getValue()); } ports.add(portsBuilder.build()); } return ports; }
private static List<SourcePorts> createSourcePorts(final UnkeyedListNode sourcePortsData) { final List<SourcePorts> sourcePorts = new ArrayList<>(); for (final UnkeyedListEntryNode node : sourcePortsData.getValue()) { final SourcePortsBuilder sourcePortsBuilder = new SourcePortsBuilder(); final Optional<DataContainerChild<? extends PathArgument, ?>> opValue = node.getChild(OP_NID); if (opValue.isPresent()) { sourcePortsBuilder.setOp(NumericTwoByteOperandParser.INSTANCE.create((Set<String>) opValue.get().getValue())); } final Optional<DataContainerChild<? extends PathArgument, ?>> valueNode = node.getChild(VALUE_NID); if (valueNode.isPresent()) { sourcePortsBuilder.setValue((Integer) valueNode.get().getValue()); } sourcePorts.add(sourcePortsBuilder.build()); } return sourcePorts; }
private static List<Codes> createCodes(final UnkeyedListNode codesData) { final List<Codes> codes = new ArrayList<>(); for (final UnkeyedListEntryNode node : codesData.getValue()) { final CodesBuilder codesBuilder = new CodesBuilder(); final Optional<DataContainerChild<? extends PathArgument, ?>> opValue = node.getChild(OP_NID); if (opValue.isPresent()) { codesBuilder.setOp(NumericOneByteOperandParser.INSTANCE.create((Set<String>) opValue.get().getValue())); } final Optional<DataContainerChild<? extends PathArgument, ?>> valueNode = node.getChild(VALUE_NID); if (valueNode.isPresent()) { codesBuilder.setValue((Short) valueNode.get().getValue()); } codes.add(codesBuilder.build()); } return codes; }
private static List<DestinationPorts> createDestinationPorts(final UnkeyedListNode destinationPortsData) { final List<DestinationPorts> destinationPorts = new ArrayList<>(); for (final UnkeyedListEntryNode node : destinationPortsData.getValue()) { final DestinationPortsBuilder destPortsBuilder = new DestinationPortsBuilder(); final Optional<DataContainerChild<? extends PathArgument, ?>> opValue = node.getChild(OP_NID); if (opValue.isPresent()) { destPortsBuilder.setOp(NumericTwoByteOperandParser.INSTANCE.create((Set<String>) opValue.get().getValue())); } final Optional<DataContainerChild<? extends PathArgument, ?>> valueNode = node.getChild(VALUE_NID); if (valueNode.isPresent()) { destPortsBuilder.setValue((Integer) valueNode.get().getValue()); } destinationPorts.add(destPortsBuilder.build()); } return destinationPorts; }
private static List<Types> createTypes(final UnkeyedListNode typesData) { final List<Types> types = new ArrayList<>(); for (final UnkeyedListEntryNode node : typesData.getValue()) { final TypesBuilder typesBuilder = new TypesBuilder(); final Optional<DataContainerChild<? extends PathArgument, ?>> opValue = node.getChild(OP_NID); if (opValue.isPresent()) { typesBuilder.setOp(NumericOneByteOperandParser.INSTANCE.create((Set<String>) opValue.get().getValue())); } final Optional<DataContainerChild<? extends PathArgument, ?>> valueNode = node.getChild(VALUE_NID); if (valueNode.isPresent()) { typesBuilder.setValue((Short) valueNode.get().getValue()); } types.add(typesBuilder.build()); } return types; }
private static final List<NextHeaders> createNextHeaders(final UnkeyedListNode nextHeadersData) { final List<NextHeaders> nextHeaders = new ArrayList<>(); for (final UnkeyedListEntryNode node : nextHeadersData.getValue()) { final NextHeadersBuilder nextHeadersBuilder = new NextHeadersBuilder(); final Optional<DataContainerChild<? extends PathArgument, ?>> opValue = node.getChild(AbstractFlowspecNlriParser.OP_NID); if (opValue.isPresent()) { nextHeadersBuilder.setOp(NumericOneByteOperandParser.INSTANCE.create((Set<String>) opValue.get().getValue())); } final Optional<DataContainerChild<? extends PathArgument, ?>> valueNode = node.getChild(AbstractFlowspecNlriParser.VALUE_NID); if (valueNode.isPresent()) { nextHeadersBuilder.setValue((Short) valueNode.get().getValue()); } nextHeaders.add(nextHeadersBuilder.build()); } return nextHeaders; }
private static List<Dscps> createDscpsLengths(final UnkeyedListNode dscpLengthsData) { final List<Dscps> dscpsLengths = new ArrayList<>(); for (final UnkeyedListEntryNode node : dscpLengthsData.getValue()) { final DscpsBuilder dscpsLengthsBuilder = new DscpsBuilder(); final Optional<DataContainerChild<? extends PathArgument, ?>> opValue = node.getChild(OP_NID); if (opValue.isPresent()) { dscpsLengthsBuilder.setOp(NumericOneByteOperandParser.INSTANCE.create((Set<String>) opValue.get().getValue())); } final Optional<DataContainerChild<? extends PathArgument, ?>> valueNode = node.getChild(VALUE_NID); if (valueNode.isPresent()) { dscpsLengthsBuilder.setValue(new Dscp((Short) valueNode.get().getValue())); } dscpsLengths.add(dscpsLengthsBuilder.build()); } return dscpsLengths; }
private static List<TcpFlags> createTcpFlags(final UnkeyedListNode tcpFlagsData) { final List<TcpFlags> tcpFlags = new ArrayList<>(); for (final UnkeyedListEntryNode node : tcpFlagsData.getValue()) { final TcpFlagsBuilder tcpFlagsBuilder = new TcpFlagsBuilder(); final Optional<DataContainerChild<? extends PathArgument, ?>> opValue = node.getChild(OP_NID); if (opValue.isPresent()) { tcpFlagsBuilder.setOp(BitmaskOperandParser.INSTANCE.create((Set<String>) opValue.get().getValue())); } final Optional<DataContainerChild<? extends PathArgument, ?>> valueNode = node.getChild(VALUE_NID); if (valueNode.isPresent()) { tcpFlagsBuilder.setValue((Integer) valueNode.get().getValue()); } tcpFlags.add(tcpFlagsBuilder.build()); } return tcpFlags; }
private static List<PacketLengths> createPacketLengths(final UnkeyedListNode packetLengthsData) { final List<PacketLengths> packetLengths = new ArrayList<>(); for (final UnkeyedListEntryNode node : packetLengthsData.getValue()) { final PacketLengthsBuilder packetLengthsBuilder = new PacketLengthsBuilder(); final Optional<DataContainerChild<? extends PathArgument, ?>> opValue = node.getChild(OP_NID); if (opValue.isPresent()) { packetLengthsBuilder.setOp(NumericTwoByteOperandParser.INSTANCE.create((Set<String>) opValue.get().getValue())); } final Optional<DataContainerChild<? extends PathArgument, ?>> valueNode = node.getChild(VALUE_NID); if (valueNode.isPresent()) { packetLengthsBuilder.setValue((Integer) valueNode.get().getValue()); } packetLengths.add(packetLengthsBuilder.build()); } return packetLengths; }
private static final List<ProtocolIps> createProtocolsIps(final UnkeyedListNode protocolIpsData) { final List<ProtocolIps> protocolIps = new ArrayList<>(); for (final UnkeyedListEntryNode node : protocolIpsData.getValue()) { final ProtocolIpsBuilder ipsBuilder = new ProtocolIpsBuilder(); final Optional<DataContainerChild<? extends PathArgument, ?>> opValue = node.getChild(AbstractFlowspecNlriParser.OP_NID); if (opValue.isPresent()) { ipsBuilder.setOp(NumericOneByteOperandParser.INSTANCE.create((Set<String>) opValue.get().getValue())); } final Optional<DataContainerChild<? extends PathArgument, ?>> valueNode = node.getChild(AbstractFlowspecNlriParser.VALUE_NID); if (valueNode.isPresent()) { ipsBuilder.setValue((Short) valueNode.get().getValue()); } protocolIps.add(ipsBuilder.build()); } return protocolIps; }
private static List<Fragments> createFragments(final UnkeyedListNode fragmentsData) { final List<Fragments> fragments = new ArrayList<>(); for (final UnkeyedListEntryNode node : fragmentsData.getValue()) { final FragmentsBuilder fragmentsBuilder = new FragmentsBuilder(); final Optional<DataContainerChild<? extends PathArgument, ?>> opValue = node.getChild(OP_NID); if (opValue.isPresent()) { fragmentsBuilder.setOp(BitmaskOperandParser.INSTANCE.create((Set<String>) opValue.get().getValue())); } final Optional<DataContainerChild<? extends PathArgument, ?>> valueNode = node.getChild(VALUE_NID); if (valueNode.isPresent()) { fragmentsBuilder.setValue(createFragment((Set<String>) valueNode.get().getValue())); } fragments.add(fragmentsBuilder.build()); } return fragments; }
@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); } } } }
@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(this.nlriRoutesList); if (maybeRoutes.isPresent()) { final DataContainerChild<? extends PathArgument, ?> routes = maybeRoutes.get(); if (routes instanceof UnkeyedListNode) { // Instance identifier to table/(choice routes)/(map of route) // FIXME: cache on per-table basis (in TableContext, for example) 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); } } } }
private DataContainerChild<?, ?> processUnkeyedListNode(final NormalizedNode<?, ?> node, final Integer depth) { CollectionNodeBuilder<UnkeyedListEntryNode, UnkeyedListNode> newUnkeyedListBuilder = Builders .unkeyedListBuilder(); if (depth > 1) { for (UnkeyedListEntryNode oldUnkeyedListEntry : ((UnkeyedListNode) node).getValue()) { DataContainerNodeAttrBuilder<NodeIdentifier, UnkeyedListEntryNode> newUnkeyedListEntry = Builders .unkeyedListEntryBuilder().withNodeIdentifier(oldUnkeyedListEntry.getIdentifier()); for (DataContainerChild<? extends PathArgument, ?> oldUnkeyedListEntryValue : oldUnkeyedListEntry .getValue()) { newUnkeyedListEntry.withChild(pruneDataAtDepth(oldUnkeyedListEntryValue, depth - 1)); } newUnkeyedListBuilder.addChild(newUnkeyedListEntry.build()); } } return newUnkeyedListBuilder.build(); }