private Object getNodeId() { return this.nb.getNodeId(); } }
private void putNode(final WriteTransaction trans, final NodeHolder holder) { if (holder.syncState(trans)) { this.nodes.remove(holder.getNodeId()); } }
private void checkNodeForRemoval(final WriteTransaction trans, final NodeHolder holder) { if (holder.checkForRemoval(trans)) { this.nodes.remove(holder.getNodeId()); } }
private void advertized(final NodeBuilder nb, final IgpNodeAttributesBuilder inab) { this.nb = Preconditions.checkNotNull(nb); this.inab = Preconditions.checkNotNull(inab); this.advertized = true; LOG.debug("Node {} is advertized", nb.getNodeId()); }
private boolean checkForRemoval(final WriteTransaction trans) { final InstanceIdentifier<Node> nid = getNodeInstanceIdentifier(this.nb.getKey()); if (!this.advertized) { if (this.tps.isEmpty() && this.prefixes.isEmpty()) { trans.delete(LogicalDatastoreType.OPERATIONAL, nid); LOG.debug("Removing unadvertized unused node {}", this.nb.getNodeId()); return true; } LOG.debug("Node {} is still implied by {} TPs and {} prefixes", this.nb.getNodeId(), this.tps.size(), this.prefixes.size()); } return false; }
private NodeImpl(NodeBuilder base) { if (base.getKey() == null) { this._key = new NodeKey( base.getNodeId() ); this._nodeId = base.getNodeId(); } else { this._key = base.getKey(); this._nodeId = _key.getNodeId(); } this._supportingNode = base.getSupportingNode(); this._terminationPoint = base.getTerminationPoint(); switch (base.augmentation.size()) { case 0: this.augmentation = Collections.emptyMap(); break; case 1: final Map.Entry<java.lang.Class<? extends Augmentation<org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node>>, Augmentation<org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node>> e = base.augmentation.entrySet().iterator().next(); this.augmentation = Collections.<java.lang.Class<? extends Augmentation<org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node>>, Augmentation<org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node>>singletonMap(e.getKey(), e.getValue()); break; default : this.augmentation = new HashMap<>(base.augmentation); } }
private void removeTp(final WriteTransaction trans, final NodeId node, final TpId tp, final LinkId link, final boolean isRemote) { final NodeHolder nh = this.nodes.get(node); if (nh != null) { final InstanceIdentifier<Node> nid = getNodeInstanceIdentifier(new NodeKey((NodeId) nh.getNodeId())); trans.delete(LogicalDatastoreType.OPERATIONAL, nid.child(TerminationPoint.class, new TerminationPointKey(tp))); nh.removeTp(tp, link, isRemote); checkNodeForRemoval(trans, nh); } else { LOG.warn("Removed non-existent node {}", node); } }
/** * Synchronized in-core state of a node into the backing store using the transaction * * @param trans data modification transaction which to use * @return True if the node has been purged, false otherwise. */ private boolean syncState(final WriteTransaction trans) { final InstanceIdentifier<Node> nid = getNodeInstanceIdentifier(this.nb.getKey()); /* * Transaction's putOperationalData() does a merge. Force it onto a replace * by removing the data. If we decide to remove the node -- we just skip the put. */ trans.delete(LogicalDatastoreType.OPERATIONAL, nid); if (!this.advertized) { if (this.tps.isEmpty() && this.prefixes.isEmpty()) { LOG.debug("Removing unadvertized unused node {}", this.nb.getNodeId()); return true; } LOG.debug("Node {} is still implied by {} TPs and {} prefixes", this.nb.getNodeId(), this.tps.size(), this.prefixes.size()); } // Re-generate termination points this.nb.setTerminationPoint(Lists.newArrayList(Collections2.transform(this.tps.values(), input -> input.getTp()))); // Re-generate prefixes this.inab.setPrefix(Lists.newArrayList(this.prefixes.values())); // Write the node out final Node n = this.nb.addAugmentation(Node1.class, new Node1Builder().setIgpNodeAttributes(this.inab.build()).build()).build(); trans.put(LogicalDatastoreType.OPERATIONAL, nid, n); LOG.debug("Created node {} at {}", n, nid); return false; }
NodeImpl(NodeBuilder base) { if (base.key() != null) { this.key = base.key(); } else { this.key = new NodeKey(base.getNodeId()); } this._nodeId = key.getNodeId(); this._supportingNode = base.getSupportingNode(); this._terminationPoint = base.getTerminationPoint(); this.augmentation = ImmutableMap.copyOf(base.augmentation); }
/** * Creates a NodeBuilder based on the given HostNodeBuilder. * * @param hostNode * The HostNodeBuilder where the AttachmentPoints and Id are. * @return A NodeBuilder with the same Id of HostNodeBuilder and a list of * TerminationPoint corresponding to each HostNodeBuilder's * AttachmentPoints. */ private NodeBuilder createNodeBuilder(HostNodeBuilder hostNode, List<AttachmentPointsBuilder> apbs) { List<TerminationPoint> tps = new ArrayList<>(); for (AttachmentPointsBuilder atb : apbs) { TerminationPoint tp = createTerminationPoint(hostNode); tps.add(tp); atb.setCorrespondingTp(tp.getTpId()); } NodeBuilder node = new NodeBuilder().setNodeId(createNodeId(hostNode)).setTerminationPoint(tps); node.setKey(new NodeKey(node.getNodeId())); return node; }
/** * Creates a NodeBuilder based on the given HostNodeBuilder. * * @param hostNode The HostNodeBuilder where the AttachmentPoints and Id * are. * @return A NodeBuilder with the same Id of HostNodeBuilder and a list of * TerminationPoint corresponding to each HostNodeBuilder's * AttachmentPoints. */ private NodeBuilder createNodeBuilder(HostNodeBuilder hostNode, List<AttachmentPointsBuilder> apbs) { List<TerminationPoint> tps = new ArrayList<>(); for (AttachmentPointsBuilder atb : apbs) { TerminationPoint tp = createTerminationPoint(hostNode); tps.add(tp); atb.setCorrespondingTp(tp.getTpId()); } NodeBuilder node = new NodeBuilder().setNodeId(createNodeId(hostNode)) .setTerminationPoint(tps); node.setKey(new NodeKey(node.getNodeId())); return node; }
private void removePrefix(final WriteTransaction trans, final UriBuilder base, final PrefixCase p) { final NodeId node = buildNodeId(base, p.getAdvertisingNodeDescriptors()); final NodeHolder nh = this.nodes.get(node); if (nh != null) { LOG.debug("Removed prefix {}", p); final InstanceIdentifier<Node> nid = getNodeInstanceIdentifier(new NodeKey((NodeId) nh.getNodeId())); final InstanceIdentifier<IgpNodeAttributes> inaId = nid.builder().augmentation(Node1.class).child(IgpNodeAttributes.class).build(); final IpPrefix ippfx = p.getPrefixDescriptors().getIpReachabilityInformation(); if (ippfx == null) { LOG.warn("IP reachability not present in prefix {}, skipping it", p); return; } final PrefixKey pk = new PrefixKey(ippfx); trans.delete(LogicalDatastoreType.OPERATIONAL, inaId.child(Prefix.class, pk)); nh.removePrefix(p); checkNodeForRemoval(trans, nh); } else { LOG.warn("Removing prefix from non-existing node {}", node); } }
/** * Creates links that have this Host's AttachmentPoints in the given * dstNode. * * @param dstNode Node that could have Host's AttachmentPoints. * @return A list of links containing a link from this Host's * TerminationPoint to the given dstNode and vice-versa. */ public synchronized List<Link> createLinks(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node dstNode) { for (AttachmentPointsBuilder apb : apbs) { if (apb.isActive()) { for (NodeConnector nc : dstNode.getNodeConnector()) { if (nc.getId().getValue().equals(apb.getTpId().getValue())) { return Utilities.createLinks(nodeBuilder.getNodeId(), apb.getCorrespondingTp(), new NodeId(dstNode.getId().getValue()), apb.getTpId()); } } } } return null; }
nb.setKey(new NodeKey(nb.getNodeId()));
} else { nh.addPrefix(pfx); final InstanceIdentifier<Node> nid = getNodeInstanceIdentifier(new NodeKey((NodeId) nh.getNodeId())); final InstanceIdentifier<IgpNodeAttributes> inaId = nid.builder().augmentation(Node1.class).child(IgpNodeAttributes.class).build(); trans.put(LogicalDatastoreType.OPERATIONAL, inaId.child(Prefix.class, pk), pfx);
} else { snh.addTp(srcTp, lb.getLinkId(), false); final InstanceIdentifier<Node> nid = getNodeInstanceIdentifier(new NodeKey((NodeId) snh.getNodeId())); trans.put(LogicalDatastoreType.OPERATIONAL, nid.child(TerminationPoint.class, srcTp.getKey()), srcTp); final InstanceIdentifier<Node> nid = getInstanceIdentifier().child( org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node.class, new NodeKey((NodeId) dnh.getNodeId())); trans.put(LogicalDatastoreType.OPERATIONAL, nid.child(TerminationPoint.class, dstTp.getKey()), dstTp);