/** * 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; }
public static Node createBasicNode(String nodeIdStr) { NodeId nodeId = new NodeId(nodeIdStr); NodeKey nodeKey = new NodeKey(nodeId); NodeBuilder nodeBuilder = new NodeBuilder(); nodeBuilder.setKey(nodeKey); nodeBuilder.setNodeId(nodeId); List<SupportingNode> childNodeList = new ArrayList<>(); nodeBuilder.setSupportingNode(childNodeList); List<TerminationPoint> ports = new ArrayList<>(); TerminationPoint tpWest = createTp(VC_NODE_TP_WEST); ports.add(tpWest); TerminationPoint tpEast = createTp(VC_NODE_TP_EAST); ports.add(tpEast); nodeBuilder.setTerminationPoint(ports); return nodeBuilder.build(); }
/** * 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 InstanceIdentifier<TerminationPoint> createTP(final IpAddress addr, final InstanceIdentifier<Node> sni, final Boolean inControl, final ReadWriteTransaction trans) { final String url = "ip://" + addr.toString(); final TerminationPointKey tpk = new TerminationPointKey(new TpId(url)); final TerminationPointBuilder tpb = new TerminationPointBuilder(); tpb.setKey(tpk).setTpId(tpk.getTpId()); tpb.addAugmentation(TerminationPoint1.class, new TerminationPoint1Builder().setIgpTerminationPointAttributes( new IgpTerminationPointAttributesBuilder().setTerminationPointType( new IpBuilder().setIpAddress(Lists.newArrayList(addr)).build()).build()).build()); final NodeKey nk = new NodeKey(new NodeId(url)); final NodeBuilder nb = new NodeBuilder(); nb.setKey(nk).setNodeId(nk.getNodeId()); nb.setTerminationPoint(Lists.newArrayList(tpb.build())); if (sni != null) { nb.setSupportingNode(Lists.newArrayList(createSupportingNode(InstanceIdentifier.keyOf(sni).getNodeId(), inControl))); } final InstanceIdentifier<Node> nid = this.target.child(Node.class, nb.getKey()); trans.put(LogicalDatastoreType.OPERATIONAL, nid, nb.build()); return nid.child(TerminationPoint.class, tpb.getKey()); }