use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev171025.Node1 in project netvirt by opendaylight.
the class L2GwValidateCli method compareNodes.
private boolean compareNodes(Node node1, Node node2, boolean parentChildComparison, LogicalDatastoreType datastoreType) {
if (node1 == null || node2 == null) {
return false;
}
InstanceIdentifier<Node> nodeIid1 = HwvtepSouthboundUtils.createInstanceIdentifier(node1.getNodeId());
InstanceIdentifier<Node> nodeIid2 = HwvtepSouthboundUtils.createInstanceIdentifier(node2.getNodeId());
NodeId nodeId1 = nodeIid1.firstKeyOf(Node.class).getNodeId();
NodeId nodeId2 = nodeIid2.firstKeyOf(Node.class).getNodeId();
PhysicalSwitchAugmentation psAug1 = node1.getAugmentation(PhysicalSwitchAugmentation.class);
PhysicalSwitchAugmentation psAug2 = node2.getAugmentation(PhysicalSwitchAugmentation.class);
HwvtepGlobalAugmentation aug1 = node1.getAugmentation(HwvtepGlobalAugmentation.class);
HwvtepGlobalAugmentation aug2 = node2.getAugmentation(HwvtepGlobalAugmentation.class);
boolean globalNodes = psAug1 == null && psAug2 == null ? true : false;
MergeCommand[] commands = globalNodes ? globalCommands : physicalSwitchCommands;
for (MergeCommand cmd : commands) {
List<DataObject> data1 = null;
List<DataObject> data2 = null;
if (globalNodes) {
data1 = cmd.getData(aug1);
data2 = cmd.getData(aug2);
} else {
data1 = cmd.getData(node1);
data2 = cmd.getData(node2);
}
data1 = data1 == null ? Collections.EMPTY_LIST : data1;
data2 = data2 == null ? Collections.EMPTY_LIST : data2;
if (parentChildComparison) {
data2 = cmd.transform(nodeIid1, data2);
}
Function<DataObject, DataObject> withoutUuidTransformer = cmd::withoutUuid;
data1 = Lists.transform(data1, withoutUuidTransformer);
data2 = Lists.transform(data2, withoutUuidTransformer);
Map<Identifier<?>, DataObject> map1 = new HashMap<>();
Map<Identifier<?>, DataObject> map2 = new HashMap<>();
for (DataObject dataObject : data1) {
map1.put(cmd.getKey(dataObject), dataObject);
}
for (DataObject dataObject : data2) {
map2.put(cmd.getKey(dataObject), dataObject);
}
Set<DataObject> diff = Sets.newHashSet();
for (Entry<Identifier<?>, DataObject> entry : map1.entrySet()) {
DataObject obj1 = entry.getValue();
DataObject obj2 = map2.get(entry.getKey());
if (obj2 == null || !cmd.areEqual(obj1, obj2)) {
diff.add(obj1);
}
}
if (!diff.isEmpty()) {
if (parentChildComparison) {
pw.println("Missing " + cmd.getDescription() + " child entries in " + datastoreType + " parent node " + nodeId1 + " contain " + " more entries than child " + nodeId2 + " " + diff.size());
} else {
pw.println("Missing " + cmd.getDescription() + " op entries config " + nodeId1 + " contain " + " more entries than operational node " + diff.size());
}
if (diff.size() < 10) {
for (Object obj : diff) {
pw.println(cmd.getKey((DataObject) obj));
}
}
}
diff = Sets.newHashSet();
for (Entry<Identifier<?>, DataObject> entry : map2.entrySet()) {
DataObject obj1 = entry.getValue();
DataObject obj2 = map1.get(entry.getKey());
if (globalNodes || parentChildComparison) {
if (obj2 == null || !cmd.areEqual(obj1, obj2)) {
diff.add(obj1);
}
}
}
if (!diff.isEmpty()) {
if (parentChildComparison) {
pw.println("Extra " + cmd.getDescription() + " child entries in " + datastoreType + " node " + nodeId2 + " contain " + " more entries than parent node " + nodeId1 + " " + diff.size());
} else {
pw.println("Extra " + cmd.getDescription() + " operational node " + nodeId2 + " contain " + " more entries than config node " + diff.size());
}
if (diff.size() < 10) {
for (Object obj : diff) {
pw.println(cmd.getKey((DataObject) obj));
}
}
}
}
return true;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev171025.Node1 in project bgpcep by opendaylight.
the class NodeChangedListenerTest method createNode.
private void createNode(final NodeId nodeId, final String ipv4Address, final String lspName, final long lspId, final String dstIpv4Address) throws TransactionCommitFailedException {
final NodeBuilder nodeBuilder = new NodeBuilder();
nodeBuilder.setKey(new NodeKey(nodeId));
nodeBuilder.setNodeId(nodeId);
final PathBuilder pathBuilder = new PathBuilder();
pathBuilder.setKey(new PathKey(new LspId(lspId)));
pathBuilder.setBandwidth(new BandwidthBuilder().setBandwidth(new Bandwidth(new byte[] { 0x00, 0x00, (byte) 0xff, (byte) 0xff })).build());
pathBuilder.addAugmentation(Path1.class, new Path1Builder().setLsp(new LspBuilder().setTlvs(new TlvsBuilder().setLspIdentifiers(new LspIdentifiersBuilder().setAddressFamily(new Ipv4CaseBuilder().setIpv4(new Ipv4Builder().setIpv4TunnelSenderAddress(new Ipv4Address(ipv4Address)).setIpv4ExtendedTunnelId(new Ipv4ExtendedTunnelId(ipv4Address)).setIpv4TunnelEndpointAddress(new Ipv4Address(dstIpv4Address)).build()).build()).build()).build()).setAdministrative(true).setDelegate(true).build()).build());
final ReportedLsp reportedLps = new ReportedLspBuilder().setKey(new ReportedLspKey(lspName)).setPath(Collections.singletonList(pathBuilder.build())).build();
final Node1Builder node1Builder = new Node1Builder();
node1Builder.setPathComputationClient(new PathComputationClientBuilder().setStateSync(PccSyncState.Synchronized).setReportedLsp(Lists.newArrayList(reportedLps)).setIpAddress(new IpAddress(new Ipv4Address(ipv4Address))).build());
nodeBuilder.addAugmentation(Node1.class, node1Builder.build());
final WriteTransaction wTx = getDataBroker().newWriteOnlyTransaction();
wTx.put(LogicalDatastoreType.OPERATIONAL, PCEP_TOPO_IID.builder().child(Node.class, new NodeKey(nodeId)).build(), nodeBuilder.build());
wTx.submit().checkedGet();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev171025.Node1 in project bgpcep by opendaylight.
the class AbstractTopologySessionListener method onSessionUp.
@Override
public final synchronized void onSessionUp(final PCEPSession psession) {
/*
* The session went up. Look up the router in Inventory model,
* create it if it is not there (marking that fact for later
* deletion), and mark it as synchronizing. Also create it in
* the topology model, with empty LSP list.
*/
final InetAddress peerAddress = psession.getRemoteAddress();
this.syncOptimization = new SyncOptimization(psession);
final TopologyNodeState state = this.serverSessionManager.takeNodeState(peerAddress, this, isLspDbRetreived());
// takeNodeState(..) may fail when the server session manager is being restarted due to configuration change
if (state == null) {
LOG.error("Unable to fetch topology node state for PCEP session. Closing session {}", psession);
psession.close(TerminationReason.UNKNOWN);
this.onSessionTerminated(psession, new PCEPCloseTermination(TerminationReason.UNKNOWN));
return;
}
if (this.session != null || this.nodeState != null) {
LOG.error("PCEP session is already up with {}. Closing session {}", psession.getRemoteAddress(), psession);
psession.close(TerminationReason.UNKNOWN);
this.onSessionTerminated(psession, new PCEPCloseTermination(TerminationReason.UNKNOWN));
return;
}
this.session = psession;
this.nodeState = state;
this.serverSessionManager.bind(this.nodeState.getNodeId(), this.listenerState);
LOG.trace("Peer {} resolved to topology node {}", peerAddress, state.getNodeId());
// Our augmentation in the topology node
final PathComputationClientBuilder pccBuilder = new PathComputationClientBuilder();
onSessionUp(psession, pccBuilder);
this.synced.set(isSynchronized());
pccBuilder.setIpAddress(IpAddressBuilder.getDefaultInstance(peerAddress.getHostAddress()));
final InstanceIdentifier<Node1> topologyAugment = state.getNodeId().augmentation(Node1.class);
this.pccIdentifier = topologyAugment.child(PathComputationClient.class);
final Node initialNodeState = state.getInitialNodeState();
final boolean isNodePresent = isLspDbRetreived() && initialNodeState != null;
if (isNodePresent) {
loadLspData(initialNodeState, this.lspData, this.lsps, isIncrementalSynchro());
pccBuilder.setReportedLsp(initialNodeState.getAugmentation(Node1.class).getPathComputationClient().getReportedLsp());
}
state.storeNode(topologyAugment, new Node1Builder().setPathComputationClient(pccBuilder.build()).build(), this.session);
this.listenerState.init(psession);
LOG.info("Session with {} attached to topology node {}", psession.getRemoteAddress(), state.getNodeId());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev171025.Node1 in project bgpcep by opendaylight.
the class Stateful07TopologySessionListener method loadLspData.
/**
* Recover lspData and mark any LSPs in the LSP database that were previously reported by the PCC as stale.
*/
@Override
protected synchronized void loadLspData(final Node node, final Map<String, ReportedLsp> lspData, final Map<PlspId, String> lsps, final boolean incrementalSynchro) {
// load node's lsps from DS
final PathComputationClient pcc = node.getAugmentation(Node1.class).getPathComputationClient();
final List<ReportedLsp> reportedLsps = pcc.getReportedLsp();
for (final ReportedLsp reportedLsp : reportedLsps) {
final String lspName = reportedLsp.getName();
lspData.put(lspName, reportedLsp);
if (!reportedLsp.getPath().isEmpty()) {
final Path1 path1 = reportedLsp.getPath().get(0).getAugmentation(Path1.class);
if (path1 != null) {
final PlspId plspId = path1.getLsp().getPlspId();
if (!incrementalSynchro) {
this.staleLsps.add(plspId);
}
lsps.put(plspId, lspName);
}
}
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev171025.Node1 in project bgpcep by opendaylight.
the class AbstractReachabilityTopologyBuilder method ensureNodePresent.
private InstanceIdentifier<IgpNodeAttributes> ensureNodePresent(final ReadWriteTransaction trans, final NodeId ni) {
final NodeUsage present = this.nodes.get(ni);
if (present != null) {
return present.attrId;
}
final KeyedInstanceIdentifier<Node, NodeKey> nii = nodeInstanceId(ni);
final InstanceIdentifier<IgpNodeAttributes> ret = nii.builder().augmentation(Node1.class).child(IgpNodeAttributes.class).build();
trans.merge(LogicalDatastoreType.OPERATIONAL, nii, new NodeBuilder().setKey(nii.getKey()).setNodeId(ni).addAugmentation(Node1.class, new Node1Builder().setIgpNodeAttributes(new IgpNodeAttributesBuilder().setPrefix(Collections.emptyList()).build()).build()).build());
this.nodes.put(ni, new NodeUsage(ret));
return ret;
}
Aggregations