use of org.opendaylight.yangtools.yang.binding.Identifier 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.yangtools.yang.binding.Identifier in project bgpcep by opendaylight.
the class BaseAbstractRouteEntry method initializeBestPaths.
@Override
@SuppressWarnings("unchecked")
public void initializeBestPaths(final RouteEntryDependenciesContainer entryDep, final RouteEntryInfo entryInfo, final WriteTransaction tx) {
if (this.bestPath == null) {
return;
}
final TablesKey localTK = entryDep.getLocalTablesKey();
final Peer toPeer = entryInfo.getToPeer();
if (!filterRoutes(this.bestPath.getPeerId(), toPeer, localTK)) {
return;
}
final Identifier oldRouteKey = entryInfo.getRouteKey();
final RIBSupport ribSupport = entryDep.getRibSupport();
Identifier newRouteKey = ribSupport.createNewRouteKey(this.bestPath.getPathId(), oldRouteKey);
if (newRouteKey == null) {
newRouteKey = oldRouteKey;
}
final BGPRouteEntryExportParameters routeEntry = new BGPRouteEntryExportParametersImpl(this.peerTracker.getPeer(this.bestPath.getPeerId()), toPeer);
final Optional<Attributes> effAttrib = entryDep.getRoutingPolicies().applyExportPolicies(routeEntry, this.bestPath.getAttributes());
final Route route = createRoute(ribSupport, newRouteKey, this.bestPath.getPathId(), this.bestPath);
InstanceIdentifier ribOutIId = ribSupport.createRouteIdentifier(toPeer.getRibOutIId(localTK), newRouteKey);
if (effAttrib.isPresent() && route != null) {
LOG.debug("Write route {} to peer AdjRibsOut {}", route, toPeer.getPeerId());
tx.put(LogicalDatastoreType.OPERATIONAL, ribOutIId, route);
tx.put(LogicalDatastoreType.OPERATIONAL, ribOutIId.child(Attributes.class), effAttrib.get());
}
}
use of org.opendaylight.yangtools.yang.binding.Identifier in project bgpcep by opendaylight.
the class BaseAbstractRouteEntry method removePathFromDataStore.
@SuppressWarnings("unchecked")
private void removePathFromDataStore(final RouteEntryDependenciesContainer entryDep, final Identifier routeKey, final WriteTransaction tx) {
LOG.trace("Best Path removed {}", this.removedBestPath);
final KeyedInstanceIdentifier<Tables, TablesKey> locRibTarget = entryDep.getLocRibTableTarget();
final RIBSupport ribSup = entryDep.getRibSupport();
Identifier newRouteKey = ribSup.createNewRouteKey(this.removedBestPath.getPathId(), routeKey);
if (newRouteKey == null) {
newRouteKey = routeKey;
}
final InstanceIdentifier routeTarget = ribSup.createRouteIdentifier(locRibTarget, newRouteKey);
LOG.debug("Delete route from LocRib {}", routeTarget);
tx.delete(LogicalDatastoreType.OPERATIONAL, routeTarget);
fillAdjRibsOut(null, null, newRouteKey, this.removedBestPath.getPeerId(), entryDep, tx);
}
use of org.opendaylight.yangtools.yang.binding.Identifier in project bgpcep by opendaylight.
the class BaseAbstractRouteEntry method addPathToDataStore.
@SuppressWarnings("unchecked")
private void addPathToDataStore(final RouteEntryDependenciesContainer entryDep, final Identifier routeKey, final WriteTransaction tx) {
final RIBSupport ribSup = entryDep.getRibSupport();
Identifier newRouteKey = ribSup.createNewRouteKey(this.bestPath.getPathId(), routeKey);
if (newRouteKey == null) {
newRouteKey = routeKey;
}
final Route route = createRoute(ribSup, newRouteKey, this.bestPath.getPathId(), this.bestPath);
LOG.trace("Selected best route {}", route);
final KeyedInstanceIdentifier<Tables, TablesKey> locRibTarget = entryDep.getLocRibTableTarget();
final InstanceIdentifier routeTarget = ribSup.createRouteIdentifier(locRibTarget, newRouteKey);
LOG.debug("Write route to LocRib {}", route);
tx.put(LogicalDatastoreType.OPERATIONAL, routeTarget, route);
fillAdjRibsOut(this.bestPath.getAttributes(), route, newRouteKey, this.bestPath.getPeerId(), entryDep, tx);
}
use of org.opendaylight.yangtools.yang.binding.Identifier in project bgpcep by opendaylight.
the class LocRibWriter method updateRoutesEntries.
@SuppressWarnings("unchecked")
private void updateRoutesEntries(final Collection<DataObjectModification<? extends DataObject>> routeChanges, final UnsignedInteger routerId, final Map<RouteUpdateKey, RouteEntry> routes) {
for (final DataObjectModification<? extends DataObject> route : routeChanges) {
final Identifier routeKey = ((InstanceIdentifier.IdentifiableItem) route.getIdentifier()).getKey();
RouteEntry entry = this.routeEntries.get(routeKey);
final Route newRoute = (Route) route.getDataAfter();
final Route oldRoute = (Route) route.getDataBefore();
if (newRoute != null) {
if (entry == null) {
entry = createEntry(routeKey);
}
final long pathId = this.ribSupport.extractPathId(newRoute);
entry.addRoute(routerId, pathId, newRoute);
this.totalPathsCounter.increment();
} else if (oldRoute != null && entry != null) {
this.totalPathsCounter.decrement();
final long pathId = this.ribSupport.extractPathId(oldRoute);
if (entry.removeRoute(routerId, pathId)) {
this.routeEntries.remove(routeKey);
this.totalPrefixesCounter.decrement();
LOG.trace("Removed route from {}", routerId);
}
}
final RouteUpdateKey routeUpdateKey = new RouteUpdateKey(routerId, routeKey);
LOG.debug("Updated route {} entry {}", routeKey, entry);
routes.put(routeUpdateKey, entry);
}
}
Aggregations