X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;ds=sidebyside;f=pcep%2Fserver%2Fserver-provider%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fbgpcep%2Fpcep%2Fserver%2Fprovider%2FPcepTopologyListener.java;h=6d42218d7af7929bc76ccd8024cb26d787eedc26;hb=61e4a03e5554241bcb21dce49abe3e089e6e0237;hp=37c4deb684aa7fec49dceda868ca0e1d8e43d101;hpb=610e2b397135d8428bed318ff9c2a7dea0b2e411;p=bgpcep.git diff --git a/pcep/server/server-provider/src/main/java/org/opendaylight/bgpcep/pcep/server/provider/PcepTopologyListener.java b/pcep/server/server-provider/src/main/java/org/opendaylight/bgpcep/pcep/server/provider/PcepTopologyListener.java index 37c4deb684..6d42218d7a 100644 --- a/pcep/server/server-provider/src/main/java/org/opendaylight/bgpcep/pcep/server/provider/PcepTopologyListener.java +++ b/pcep/server/server-provider/src/main/java/org/opendaylight/bgpcep/pcep/server/provider/PcepTopologyListener.java @@ -12,7 +12,6 @@ import static java.util.Objects.requireNonNull; import com.google.common.collect.Iterables; import java.nio.ByteBuffer; import java.util.ArrayList; -import java.util.Collection; import java.util.List; import java.util.stream.Collectors; import org.opendaylight.mdsal.binding.api.DataBroker; @@ -24,8 +23,8 @@ import org.opendaylight.mdsal.common.api.LogicalDatastoreType; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Address; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.graph.rev191125.DecimalBandwidth; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.graph.rev191125.Delay; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.graph.rev220720.DecimalBandwidth; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.graph.rev220720.Delay; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.path.computation.rev220324.AddressFamily; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.path.computation.rev220324.ComputationStatus; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.path.computation.rev220324.path.descriptions.PathDescription; @@ -35,8 +34,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.iet import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev200720.Path1; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev200720.lsp.identifiers.tlv.lsp.identifiers.address.family.Ipv4Case; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev200720.lsp.identifiers.tlv.lsp.identifiers.address.family.Ipv6Case; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev200720.lsp.identifiers.tlv.lsp.identifiers.address.family.ipv4._case.Ipv4; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev200720.lsp.identifiers.tlv.lsp.identifiers.address.family.ipv6._case.Ipv6; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev200720.lsp.object.Lsp; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.segment.routing.rev200720.SrSubobject; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.segment.routing.rev200720.sr.subobject.nai.IpAdjacency; @@ -50,23 +47,19 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ser import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.server.rev220321.pcc.configured.lsp.configured.lsp.IntendedPathBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.server.rev220321.pcc.configured.lsp.configured.lsp.intended.path.ConstraintsBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.explicit.route.object.Ero; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.explicit.route.object.ero.Subobject; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.lsp.attributes.Metrics; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.reported.route.object.Rro; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.SubobjectType; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.IpPrefixCase; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev200120.Node1; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev200120.PccSyncState; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev200120.pcep.client.attributes.PathComputationClient; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev200120.pcep.client.attributes.path.computation.client.ReportedLsp; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev200120.pcep.client.attributes.path.computation.client.reported.lsp.Path; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev220730.Node1; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev220730.PccSyncState; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev220730.pcep.client.attributes.PathComputationClient; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev220730.pcep.client.attributes.path.computation.client.ReportedLsp; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev220730.pcep.client.attributes.path.computation.client.reported.lsp.Path; import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId; import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology; import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyKey; import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node; -import org.opendaylight.yangtools.concepts.ListenerRegistration; +import org.opendaylight.yangtools.concepts.Registration; import org.opendaylight.yangtools.yang.binding.DataObject; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier; import org.opendaylight.yangtools.yang.common.Decimal64; import org.opendaylight.yangtools.yang.common.Uint32; @@ -82,17 +75,16 @@ import org.slf4j.LoggerFactory; public final class PcepTopologyListener implements DataTreeChangeListener, AutoCloseable { private static final Logger LOG = LoggerFactory.getLogger(PcepTopologyListener.class); - private ListenerRegistration listenerRegistration; + private final PathManagerProvider pathManager; + private Registration listenerRegistration; + public PcepTopologyListener(final DataBroker dataBroker, final KeyedInstanceIdentifier topology, final PathManagerProvider pathManager) { - requireNonNull(dataBroker); - requireNonNull(topology); this.pathManager = requireNonNull(pathManager); - final InstanceIdentifier nodeTopology = topology.child(Node.class); - listenerRegistration = dataBroker.registerDataTreeChangeListener( - DataTreeIdentifier.create(LogicalDatastoreType.OPERATIONAL, nodeTopology), this); + listenerRegistration = dataBroker.registerLegacyTreeChangeListener( + DataTreeIdentifier.of(LogicalDatastoreType.OPERATIONAL, topology.child(Node.class)), this); LOG.info("Registered PCE Server listener {} for Operational PCEP Topology {}", listenerRegistration, topology.getKey().getTopologyId().getValue()); } @@ -119,22 +111,21 @@ public final class PcepTopologyListener implements DataTreeChangeListener, for (DataObjectModification lsp : lspMod) { ReportedLsp rptLsp; - switch (lsp.getModificationType()) { + switch (lsp.modificationType()) { case DELETE: - rptLsp = (ReportedLsp) lsp.getDataBefore(); + rptLsp = (ReportedLsp) lsp.dataBefore(); LOG.debug("Un-Register Managed TE Path: {}", rptLsp.getName()); pathManager.unregisterTePath(nodeId, new ConfiguredLspKey(rptLsp.getName())); break; case SUBTREE_MODIFIED: case WRITE: - rptLsp = (ReportedLsp) lsp.getDataAfter(); + rptLsp = (ReportedLsp) lsp.dataAfter(); LOG.debug("Register Managed TE Path {}", rptLsp.getName()); pathManager.registerTePath(nodeId, getConfiguredLsp(rptLsp), getPathType(rptLsp)); break; default: break; } - } } @@ -149,7 +140,7 @@ public final class PcepTopologyListener implements DataTreeChangeListener, private void handlePccChange(final NodeId nodeId, final List> pccMod) { for (DataObjectModification node : pccMod) { /* First, process PCC modification */ - switch (node.getModificationType()) { + switch (node.modificationType()) { case DELETE: LOG.debug("Un-Register Managed TE Node: {}", nodeId); pathManager.disableManagedTeNode(nodeId); @@ -160,8 +151,8 @@ public final class PcepTopologyListener implements DataTreeChangeListener, /* First look if the PCC was already created or not yet */ if (pathManager.checkManagedTeNode(nodeId)) { /* Check if PCC State is Synchronized */ - if (node.getModifiedChildren() == null || node.getModifiedChildren().isEmpty()) { - PathComputationClient pcc = (PathComputationClient) node.getDataAfter(); + if (node.modifiedChildren() == null || node.modifiedChildren().isEmpty()) { + PathComputationClient pcc = (PathComputationClient) node.dataAfter(); if (pcc.getStateSync() == PccSyncState.Synchronized) { LOG.debug("Synchronize Managed TE Node {}", nodeId); pathManager.syncManagedTeNode(nodeId); @@ -178,8 +169,8 @@ public final class PcepTopologyListener implements DataTreeChangeListener, } /* Then, look to reported LSP modification */ - final List> lspMod = node.getModifiedChildren() - .stream().filter(mod -> mod.getDataType().equals(ReportedLsp.class)) + final List> lspMod = node.modifiedChildren() + .stream().filter(mod -> mod.dataType().equals(ReportedLsp.class)) .collect(Collectors.toList()); if (!lspMod.isEmpty()) { handleLspChange(nodeId, lspMod); @@ -197,8 +188,8 @@ public final class PcepTopologyListener implements DataTreeChangeListener, private void handleNode1Change(final NodeId nodeId, final List> node1Mod) { for (DataObjectModification child : node1Mod) { /* Then, look only to PathComputationClient.class modification */ - final List> pccMod = child.getModifiedChildren() - .stream().filter(mod -> mod.getDataType().equals(PathComputationClient.class)) + final List> pccMod = child.modifiedChildren() + .stream().filter(mod -> mod.dataType().equals(PathComputationClient.class)) .collect(Collectors.toList()); if (!pccMod.isEmpty()) { handlePccChange(nodeId, pccMod); @@ -207,18 +198,17 @@ public final class PcepTopologyListener implements DataTreeChangeListener, } @Override - public void onDataTreeChanged(final Collection> changes) { - for (DataTreeModification change : changes) { - DataObjectModification root = change.getRootNode(); + public void onDataTreeChanged(final List> changes) { + for (var change : changes) { + final var root = change.getRootNode(); final NodeId nodeId = - root.getModificationType() == DataObjectModification.ModificationType.DELETE - ? root.getDataBefore().getNodeId() - : root.getDataAfter().getNodeId(); + root.modificationType() == DataObjectModification.ModificationType.DELETE + ? root.dataBefore().getNodeId() : root.dataAfter().getNodeId(); /* Look only to Node1.class modification */ - final List> node1Mod = root.getModifiedChildren().stream() - .filter(mod -> mod.getDataType().equals(Node1.class)) + final List> node1Mod = root.modifiedChildren().stream() + .filter(mod -> mod.dataType().equals(Node1.class)) .collect(Collectors.toList()); if (!node1Mod.isEmpty()) { handleNode1Change(nodeId, node1Mod); @@ -235,42 +225,33 @@ public final class PcepTopologyListener implements DataTreeChangeListener, * @return Path Description of the corresponding ERO SubObject. */ private static PathDescription getSrPath(final SrSubobject srObj, final AddressFamily af) { - switch (af) { - case SrIpv4: - switch (srObj.getNaiType()) { - case Ipv4Adjacency: - return new PathDescriptionBuilder() - .setSid(srObj.getSid()) - .setIpv4(((IpAdjacency)srObj.getNai()).getLocalIpAddress().getIpv4AddressNoZone()) - .setRemoteIpv4(((IpAdjacency)srObj.getNai()).getRemoteIpAddress().getIpv4AddressNoZone()) - .build(); - case Ipv4NodeId: - return new PathDescriptionBuilder() - .setSid(srObj.getSid()) - .setRemoteIpv4(((IpNodeId)srObj.getNai()).getIpAddress().getIpv4AddressNoZone()) - .build(); - default: - return null; - } - case SrIpv6: - switch (srObj.getNaiType()) { - case Ipv6Adjacency: - return new PathDescriptionBuilder() - .setSid(srObj.getSid()) - .setIpv6(((IpAdjacency)srObj.getNai()).getLocalIpAddress().getIpv6AddressNoZone()) - .setRemoteIpv6(((IpAdjacency)srObj.getNai()).getRemoteIpAddress().getIpv6AddressNoZone()) - .build(); - case Ipv6NodeId: - return new PathDescriptionBuilder() - .setSid(srObj.getSid()) - .setRemoteIpv6(((IpNodeId)srObj.getNai()).getIpAddress().getIpv6AddressNoZone()) - .build(); - default: - return null; - } - default: - return null; - } + return switch (af) { + case SrIpv4 -> switch (srObj.getNaiType()) { + case Ipv4Adjacency -> new PathDescriptionBuilder() + .setSid(srObj.getSid()) + .setIpv4(((IpAdjacency)srObj.getNai()).getLocalIpAddress().getIpv4AddressNoZone()) + .setRemoteIpv4(((IpAdjacency)srObj.getNai()).getRemoteIpAddress().getIpv4AddressNoZone()) + .build(); + case Ipv4NodeId -> new PathDescriptionBuilder() + .setSid(srObj.getSid()) + .setRemoteIpv4(((IpNodeId)srObj.getNai()).getIpAddress().getIpv4AddressNoZone()) + .build(); + default -> null; + }; + case SrIpv6 -> switch (srObj.getNaiType()) { + case Ipv6Adjacency -> new PathDescriptionBuilder() + .setSid(srObj.getSid()) + .setIpv6(((IpAdjacency)srObj.getNai()).getLocalIpAddress().getIpv6AddressNoZone()) + .setRemoteIpv6(((IpAdjacency)srObj.getNai()).getRemoteIpAddress().getIpv6AddressNoZone()) + .build(); + case Ipv6NodeId -> new PathDescriptionBuilder() + .setSid(srObj.getSid()) + .setRemoteIpv6(((IpNodeId)srObj.getNai()).getIpAddress().getIpv6AddressNoZone()) + .build(); + default -> null; + }; + default -> null; + }; } /** @@ -282,18 +263,17 @@ public final class PcepTopologyListener implements DataTreeChangeListener, * @return Path Description of the corresponding ERO SubObject. */ private static PathDescription getIpPath(final IpPrefixCase ipc, final AddressFamily af) { - switch (af) { - case Ipv4: - return new PathDescriptionBuilder().setRemoteIpv4( - new Ipv4Address(ipc.getIpPrefix().getIpPrefix().getIpv4Prefix().getValue().split("/")[0])) - .build(); - case Ipv6: - return new PathDescriptionBuilder().setRemoteIpv6( - new Ipv6Address(ipc.getIpPrefix().getIpPrefix().getIpv6Prefix().getValue().split("/")[0])) - .build(); - default: - return null; - } + return switch (af) { + case Ipv4 -> new PathDescriptionBuilder() + .setRemoteIpv4( + new Ipv4Address(ipc.getIpPrefix().getIpPrefix().getIpv4Prefix().getValue().split("/")[0])) + .build(); + case Ipv6 -> new PathDescriptionBuilder() + .setRemoteIpv6( + new Ipv6Address(ipc.getIpPrefix().getIpPrefix().getIpv6Prefix().getValue().split("/")[0])) + .build(); + default -> null; + }; } /** @@ -306,18 +286,17 @@ public final class PcepTopologyListener implements DataTreeChangeListener, */ private static PathDescription getIpPath(final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang .rsvp.rev150820._record.route.subobjects.subobject.type.IpPrefixCase ipc, final AddressFamily af) { - switch (af) { - case Ipv4: - return new PathDescriptionBuilder().setRemoteIpv4( - new Ipv4Address(ipc.getIpPrefix().getIpPrefix().getIpv4Prefix().getValue().split("/")[0])) - .build(); - case Ipv6: - return new PathDescriptionBuilder().setRemoteIpv6( - new Ipv6Address(ipc.getIpPrefix().getIpPrefix().getIpv6Prefix().getValue().split("/")[0])) - .build(); - default: - return null; - } + return switch (af) { + case Ipv4 -> new PathDescriptionBuilder() + .setRemoteIpv4( + new Ipv4Address(ipc.getIpPrefix().getIpPrefix().getIpv4Prefix().getValue().split("/")[0])) + .build(); + case Ipv6 -> new PathDescriptionBuilder() + .setRemoteIpv6( + new Ipv6Address(ipc.getIpPrefix().getIpPrefix().getIpv6Prefix().getValue().split("/")[0])) + .build(); + default -> null; + }; } /** @@ -329,13 +308,13 @@ public final class PcepTopologyListener implements DataTreeChangeListener, * @return Path Description of the corresponding TE Path. */ private static List getPathDescription(final Ero ero, final AddressFamily af) { - final ArrayList pathDesc = new ArrayList<>(); - for (Subobject element : ero.getSubobject()) { - final SubobjectType sbt = element.getSubobjectType(); - if (sbt instanceof SrSubobject) { - pathDesc.add(getSrPath((SrSubobject) sbt, af)); - } else if (sbt instanceof IpPrefixCase) { - pathDesc.add(getIpPath((IpPrefixCase) sbt, af)); + final var pathDesc = new ArrayList(); + for (var element : ero.nonnullSubobject()) { + final var sbt = element.getSubobjectType(); + if (sbt instanceof SrSubobject sr) { + pathDesc.add(getSrPath(sr, af)); + } else if (sbt instanceof IpPrefixCase ip) { + pathDesc.add(getIpPath(ip, af)); } } return pathDesc.isEmpty() ? null : pathDesc; @@ -350,15 +329,15 @@ public final class PcepTopologyListener implements DataTreeChangeListener, * @return Path Description of the corresponding TE Path. */ private static List getPathDescription(final Rro rro, final AddressFamily af) { - final ArrayList pathDesc = new ArrayList<>(); + final var pathDesc = new ArrayList(); for (var element : rro.nonnullSubobject()) { final var sbt = element.getSubobjectType(); - if (sbt instanceof SrSubobject) { - pathDesc.add(getSrPath((SrSubobject) sbt, af)); - } else if (sbt instanceof org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820 - ._record.route.subobjects.subobject.type.IpPrefixCase) { - pathDesc.add(getIpPath((org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820 - ._record.route.subobjects.subobject.type.IpPrefixCase)sbt, af)); + if (sbt instanceof SrSubobject sr) { + pathDesc.add(getSrPath(sr, af)); + } else if (sbt + instanceof org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820._record + .route.subobjects.subobject.type.IpPrefixCase ip) { + pathDesc.add(getIpPath(ip, af)); } } return pathDesc.isEmpty() ? null : pathDesc; @@ -391,7 +370,7 @@ public final class PcepTopologyListener implements DataTreeChangeListener, cb.setBandwidth(new DecimalBandwidth(Decimal64.valueOf(2, convert.longValue()))); } if (path.getMetrics() != null) { - for (Metrics metric: path.getMetrics()) { + for (var metric : path.getMetrics()) { convert = ByteBuffer.wrap(metric.getMetric().getValue().getValue()).getFloat(); switch (metric.getMetric().getMetricType().intValue()) { case MessagesUtil.IGP_METRIC: @@ -416,17 +395,16 @@ public final class PcepTopologyListener implements DataTreeChangeListener, final Path1 p1 = path.augmentation(Path1.class); final Uint8 pst = p1.getPathSetupType() != null ? p1.getPathSetupType().getPst() : Uint8.ZERO; final Lsp lsp = p1.getLsp(); - final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev200720.lsp - .identifiers.tlv.lsp.identifiers.AddressFamily af = lsp.getTlvs().getLspIdentifiers().getAddressFamily(); + final var af = lsp.getTlvs().getLspIdentifiers().getAddressFamily(); IpAddress source = null; IpAddress destination = null; - if (af instanceof Ipv4Case) { - final Ipv4 ipv4 = ((Ipv4Case) af).getIpv4(); + if (af instanceof Ipv4Case v4) { + final var ipv4 = v4.getIpv4(); source = new IpAddress(ipv4.getIpv4TunnelSenderAddress()); destination = new IpAddress(ipv4.getIpv4TunnelEndpointAddress()); cb.setAddressFamily(pst == Uint8.ZERO ? AddressFamily.Ipv4 : AddressFamily.SrIpv4); - } else if (af instanceof Ipv6Case) { - final Ipv6 ipv6 = ((Ipv6Case) af).getIpv6(); + } else if (af instanceof Ipv6Case v6) { + final var ipv6 = v6.getIpv6(); source = new IpAddress(ipv6.getIpv6TunnelSenderAddress()); destination = new IpAddress(ipv6.getIpv6TunnelSenderAddress()); cb.setAddressFamily(pst == Uint8.ZERO ? AddressFamily.Ipv6 : AddressFamily.SrIpv6); @@ -496,6 +474,5 @@ public final class PcepTopologyListener implements DataTreeChangeListener, } return PathType.Initiated; } - }