package org.opendaylight.transportpce.tapi.topology;
import com.google.common.collect.ImmutableClassToInstanceMap;
-import com.google.common.util.concurrent.FluentFuture;
import com.google.common.util.concurrent.ListenableFuture;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.stream.Collectors;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.Nullable;
-import org.opendaylight.mdsal.binding.api.DataBroker;
import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
import org.opendaylight.transportpce.common.InstanceIdentifiers;
import org.opendaylight.transportpce.common.NetworkUtils;
+import org.opendaylight.transportpce.common.network.NetworkTransactionService;
import org.opendaylight.transportpce.tapi.TapiStringConstants;
import org.opendaylight.transportpce.tapi.utils.TapiContext;
import org.opendaylight.transportpce.tapi.utils.TapiLink;
import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.TapiTopologyService;
import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.get.link.details.output.LinkBuilder;
import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.get.node.edge.point.details.output.NodeEdgePointBuilder;
-import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.get.topology.details.output.Topology;
-import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.get.topology.details.output.TopologyBuilder;
import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.node.NodeRuleGroup;
import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.node.NodeRuleGroupBuilder;
import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.node.NodeRuleGroupKey;
public class TapiTopologyImpl implements TapiTopologyService, TapiCommonService {
private static final Logger LOG = LoggerFactory.getLogger(TapiTopologyImpl.class);
- private final DataBroker dataBroker;
+ private final NetworkTransactionService networkTransactionService;
private final TapiContext tapiContext;
private final TopologyUtils topologyUtils;
private final TapiLink tapiLink;
+ private Map<ServiceInterfacePointKey, ServiceInterfacePoint> tapiSips;
- public TapiTopologyImpl(DataBroker dataBroker, TapiContext tapiContext, TopologyUtils topologyUtils,
- TapiLink tapiLink) {
- this.dataBroker = dataBroker;
+ public TapiTopologyImpl(NetworkTransactionService networkTransactionService, TapiContext tapiContext,
+ TopologyUtils topologyUtils, TapiLink tapiLink) {
+ this.networkTransactionService = networkTransactionService;
this.tapiContext = tapiContext;
this.topologyUtils = topologyUtils;
this.tapiLink = tapiLink;
+ this.tapiSips = new HashMap<>();
+
}
@Override
@Override
public ListenableFuture<RpcResult<GetTopologyDetailsOutput>> getTopologyDetails(GetTopologyDetailsInput input) {
- // TODO -> Add check for Full T0 Multilayer
- Uuid topologyUuid = new Uuid(UUID.nameUUIDFromBytes(TapiStringConstants.T0_FULL_MULTILAYER.getBytes(
+ org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.topology.context.Topology topology;
+ Uuid topologyUuidAbs = new Uuid(UUID.nameUUIDFromBytes(TapiStringConstants.T0_MULTILAYER.getBytes(
+ Charset.forName("UTF-8"))).toString());
+ Uuid topologyUuidFull = new Uuid(UUID.nameUUIDFromBytes(TapiStringConstants.T0_FULL_MULTILAYER.getBytes(
Charset.forName("UTF-8"))).toString());
- if (input.getTopologyId().equals(topologyUuid)) {
+ if (input.getTopologyId().equals(topologyUuidFull)) {
Context context = this.tapiContext.getTapiContext();
Map<TopologyKey,
org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.topology.context.Topology>
topologyMap = context.augmentation(Context1.class).getTopologyContext().getTopology();
- if (topologyMap == null || !topologyMap.containsKey(new TopologyKey(topologyUuid))) {
+ if (topologyMap == null || !topologyMap.containsKey(new TopologyKey(topologyUuidFull))) {
LOG.error("Topology {} not found in datastore", input.getTopologyId());
return RpcResultBuilder.<GetTopologyDetailsOutput>failed()
.withError(ErrorType.RPC, "Invalid Topology name")
.buildFuture();
}
- org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.topology.context.Topology
- topology = topologyMap.get(new TopologyKey(topologyUuid));
+ topology = topologyMap.get(new TopologyKey(input.getTopologyId()));
return RpcResultBuilder.success(new GetTopologyDetailsOutputBuilder()
- .setTopology(this.topologyUtils.transformTopology(topology))
- .build())
+ .setTopology(this.topologyUtils.transformTopology(topology))
+ .build())
.buildFuture();
}
- topologyUuid = new Uuid(UUID.nameUUIDFromBytes(TapiStringConstants.TPDR_100G.getBytes(
+ Uuid topologyUuid100G = new Uuid(UUID.nameUUIDFromBytes(TapiStringConstants.TPDR_100G.getBytes(
Charset.forName("UTF-8"))).toString());
- try {
- LOG.info("Building TAPI Topology abstraction for {}", input.getTopologyId());
- Topology topology = createAbstractedOtnTopology();
- if (topologyUuid.equals(input.getTopologyId())) {
+ if (topologyUuid100G.equals(input.getTopologyId()) || topologyUuidAbs.equals(input.getTopologyId())) {
+ try {
+ LOG.info("Building TAPI Topology abstraction for {}", input.getTopologyId());
+ topology = createAbstractedOtnTopology();
+ if (input.getTopologyId().equals(topologyUuidAbs)) {
+ return RpcResultBuilder.success(new GetTopologyDetailsOutputBuilder()
+ .setTopology(this.topologyUtils.transformTopology(topology)).build())
+ .buildFuture();
+ }
topology = createAbstracted100GTpdrTopology(topology);
+ return RpcResultBuilder.success(new GetTopologyDetailsOutputBuilder()
+ .setTopology(this.topologyUtils.transformTopology(topology)).build())
+ .buildFuture();
+ } catch (TapiTopologyException e) {
+ LOG.error("error building TAPI topology");
+ return RpcResultBuilder.<GetTopologyDetailsOutput>failed()
+ .withError(ErrorType.RPC, "Error building topology")
+ .buildFuture();
}
- return RpcResultBuilder.success(new GetTopologyDetailsOutputBuilder().setTopology(topology).build())
- .buildFuture();
- } catch (TapiTopologyException e) {
- LOG.error("error building TAPI topology");
- return RpcResultBuilder.<GetTopologyDetailsOutput>failed()
- .withError(ErrorType.RPC, "Error building topology")
- .buildFuture();
}
+ return RpcResultBuilder.<GetTopologyDetailsOutput>failed()
+ .withError(ErrorType.RPC, "Invalid Topology name")
+ .buildFuture();
}
@Override
.build();
}
- private Topology createAbstracted100GTpdrTopology(Topology topology) {
+ public org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.topology.context.Topology
+ createAbstracted100GTpdrTopology(
+ org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.topology.context.Topology topology) {
List<org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.topology.Node> dsrNodes =
topology.nonnullNode().values().stream()
.filter(node -> node.getLayerProtocolName().contains(LayerProtocolName.DSR))
TapiStringConstants.TPDR_100G.getBytes(Charset.forName("UTF-8"))).toString());
org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.topology.Node node =
createTapiNode(nep100GTpdrList, topoUuid);
- return new TopologyBuilder()
+ return new org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.topology.context
+ .TopologyBuilder()
.setName(Map.of(topoName.key(), topoName))
.setUuid(topoUuid)
.setNode(Map.of(node.key(), node))
+ .setLayerProtocolName(Set.of(LayerProtocolName.DSR, LayerProtocolName.ETH))
.build();
}
- private Network readTopology(InstanceIdentifier<Network> networkIID) throws TapiTopologyException {
- Network topology = null;
- FluentFuture<Optional<Network>> topologyFuture = dataBroker.newReadOnlyTransaction()
- .read(LogicalDatastoreType.CONFIGURATION, networkIID);
- try {
- topology = topologyFuture.get().orElseThrow();
- } catch (InterruptedException e) {
- Thread.currentThread().interrupt();
- throw new TapiTopologyException("Unable to get from mdsal topology: " + networkIID
- .firstKeyOf(Network.class).getNetworkId().getValue(), e);
- } catch (ExecutionException e) {
- throw new TapiTopologyException("Unable to get from mdsal topology: " + networkIID
- .firstKeyOf(Network.class).getNetworkId().getValue(), e);
- }
- return topology;
- }
-
- private Topology createAbstractedOtnTopology() throws TapiTopologyException {
+ public org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.topology.context.Topology
+ createAbstractedOtnTopology() throws TapiTopologyException {
// read openroadm-topology
Network openroadmTopo = readTopology(InstanceIdentifiers.OVERLAY_NETWORK_II);
List<Link> linkList = new ArrayList<>();
.setValue(TapiStringConstants.T0_MULTILAYER)
.setValueName("TAPI Topology Name")
.build();
- return new TopologyBuilder()
- .setName(Map.of(name.key(), name))
- .setUuid(topoUuid)
- .setNode(tapiNodeList)
- .setLink(tapiLinkList).build();
+ LOG.info("TOPOABSTRACTED : the list of node is as follows {}", tapiNodeList.toString());
+ this.tapiSips.putAll(tapiAbstractFactory.getTapiSips());
+ return new org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.topology.context
+ .TopologyBuilder()
+ .setName(Map.of(name.key(), name))
+ .setUuid(topoUuid)
+ .setNode(tapiNodeList)
+ .setLayerProtocolName(Set.of(LayerProtocolName.PHOTONICMEDIA, LayerProtocolName.DIGITALOTN))
+ .setLink(tapiLinkList).build();
+ }
+
+ private Network readTopology(InstanceIdentifier<Network> networkIID) throws TapiTopologyException {
+ Network topology = null;
+ ListenableFuture<Optional<Network>> topologyFuture = networkTransactionService
+ .read(LogicalDatastoreType.CONFIGURATION, networkIID);
+ try {
+ topology = topologyFuture.get().orElseThrow();
+ } catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
+ throw new TapiTopologyException("Unable to get from mdsal topology: " + networkIID
+ .firstKeyOf(Network.class).getNetworkId().getValue(), e);
+ } catch (ExecutionException e) {
+ throw new TapiTopologyException("Unable to get from mdsal topology: " + networkIID
+ .firstKeyOf(Network.class).getNetworkId().getValue(), e);
+ }
+ return topology;
}
private org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.topology.Node
KeyedInstanceIdentifier<Mapping, MappingKey> pmIID = InstanceIdentifier.create(
org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev220922.Network.class)
.child(Nodes.class, new NodesKey(nodeIdPortMap)).child(Mapping.class, new MappingKey(networkLcp));
- @NonNull
- FluentFuture<Optional<Mapping>> mappingOpt = dataBroker.newReadOnlyTransaction().read(
- LogicalDatastoreType.CONFIGURATION, pmIID);
+ ListenableFuture<Optional<Mapping>> mappingOpt = networkTransactionService
+ .read(LogicalDatastoreType.CONFIGURATION, pmIID);
Mapping mapping = null;
if (mappingOpt.isDone()) {
try {
return nodeRuleGroupMap;
}
+ public Map<ServiceInterfacePointKey, ServiceInterfacePoint> getSipMap() {
+ return tapiSips;
+ }
+
}