+ public static TopologyShard createOtnLinks(String nodeA, String tpA, String nodeZ, String tpZ,
+ OtnLinkType linkType) {
+ List<Link> links = null;
+ if (OtnLinkType.OTU4.equals(linkType)) {
+ links = initialiseOtnLinks(nodeA, tpA, nodeZ, tpZ, linkType, "OTU4");
+ }
+ return new TopologyShard(null, links);
+ }
+
+ public static TopologyShard createOtnLinks(List<Link> suppOtu4Links, List<TerminationPoint> oldTps) {
+ List<Link> links = new ArrayList<>();
+ for (Link link : suppOtu4Links) {
+ if (link.augmentation(Link1.class) != null
+ && link.augmentation(Link1.class).getAvailableBandwidth().equals(Uint32.valueOf(100000))) {
+ links.add(updateOtnLinkBwParameters(link, 0L, 100000L));
+ } else {
+ LOG.error("Error with otn parameters of supported link {}", link.getLinkId().getValue());
+ }
+ }
+ if (links.size() == 2) {
+ links.addAll(initialiseOtnLinks(suppOtu4Links.get(0).getSource().getSourceNode().getValue(),
+ suppOtu4Links.get(0).getSource().getSourceTp().toString(),
+ suppOtu4Links.get(0).getDestination().getDestNode().getValue(),
+ suppOtu4Links.get(0).getDestination().getDestTp().toString(),
+ OtnLinkType.ODTU4, "ODU4"));
+ }
+ List<TerminationPoint> tps = new ArrayList<>();
+ for (TerminationPoint tp : oldTps) {
+ tps.add(updateTp(tp, true));
+ }
+ if (links.size() == 4 && tps.size() == 2) {
+ return new TopologyShard(null, links, tps);
+ } else {
+ return new TopologyShard(null, null, null);
+ }
+ }
+
+ public static TopologyShard updateOtnLinks(List<Link> suppOdu4Links, List<TerminationPoint> oldTps,
+ String serviceRate, Short tribPortNb, Short tribSoltNb, boolean isDeletion) {
+ List<Link> links = new ArrayList<>();
+ Long bwIncr = 10000L;
+ if ("1G".equals(serviceRate)) {
+ bwIncr = 1000L;
+ }
+ for (Link link : suppOdu4Links) {
+ if (link.augmentation(Link1.class) != null && link.augmentation(Link1.class).getAvailableBandwidth() != null
+ && link.augmentation(Link1.class).getUsedBandwidth() != null) {
+ Uint32 avlBw = link.augmentation(Link1.class).getAvailableBandwidth();
+ Uint32 usedBw = link.augmentation(Link1.class).getUsedBandwidth();
+ if (avlBw.toJava() < bwIncr) {
+ bwIncr = 0L;
+ }
+ if (isDeletion) {
+ links.add(updateOtnLinkBwParameters(link, avlBw.toJava() + bwIncr,
+ usedBw.toJava() - bwIncr));
+ } else {
+ links.add(updateOtnLinkBwParameters(link, avlBw.toJava() - bwIncr,
+ usedBw.toJava() + bwIncr));
+ }
+ } else {
+ LOG.error("Error with otn parameters of supported link {}", link.getLinkId().getValue());
+ }
+ }
+ List<TerminationPoint> tps = new ArrayList<>();
+ for (TerminationPoint tp : oldTps) {
+ if (bwIncr != 0) {
+ tps.add(updateNodeTpTsPool(tp, serviceRate, tribPortNb, tribSoltNb, isDeletion));
+ }
+ }
+ if (!links.isEmpty() && !tps.isEmpty()) {
+ return new TopologyShard(null, links, tps);
+ } else {
+ LOG.error("unable to update otn links");
+ return new TopologyShard(null, null, null);
+ }
+ }
+
+ public static TopologyShard deleteOtnLinks(List<Link> suppOtu4Links, List<TerminationPoint> oldTps) {
+ List<Link> links = new ArrayList<>();
+ for (Link link : suppOtu4Links) {
+ if (link.augmentation(Link1.class) != null) {
+ links.add(updateOtnLinkBwParameters(link, 100000L, 0L));
+ } else {
+ LOG.error("Error with otn parameters of supported link {}", link.getLinkId().getValue());
+ }
+ }
+ List<TerminationPoint> tps = new ArrayList<>();
+ for (TerminationPoint tp : oldTps) {
+ tps.add(updateTp(tp, false));
+ }
+ if (links.size() == 2 && tps.size() == 2) {
+ return new TopologyShard(null, links, tps);
+ } else {
+ return new TopologyShard(null, null, null);
+ }
+ }
+
+ private static List<Link> initialiseOtnLinks(String nodeA, String tpA, String nodeZ, String tpZ,
+ OtnLinkType linkType, String linkIdPrefix) {
+ List<Link> links = new ArrayList<>();
+ org.opendaylight.yang.gen.v1.http.transportpce.topology.rev201019.Link1 tpceLink1
+ = new org.opendaylight.yang.gen.v1.http.transportpce.topology.rev201019.Link1Builder()
+ .setOtnLinkType(linkType).build();
+ Link1 otnLink1 = new Link1Builder()
+ .setAvailableBandwidth(Uint32.valueOf(100000))
+ .setUsedBandwidth(Uint32.valueOf(0))
+ .build();
+ // create link A-Z
+ String nodeATopo;
+ String nodeZTopo;
+ if (nodeA.contains(XPDR) && nodeZ.contains(XPDR)) {
+ nodeATopo = nodeA;
+ nodeZTopo = nodeZ;
+ } else {
+ nodeATopo = nodeA + "-" + tpA.split("-")[0];
+ nodeZTopo = nodeZ + "-" + tpZ.split("-")[0];
+ }
+ LinkBuilder ietfLinkAZBldr = TopologyUtils.createLink(nodeATopo, nodeZTopo, tpA, tpZ, linkIdPrefix);
+ ietfLinkAZBldr
+ .addAugmentation(tpceLink1)
+ .addAugmentation(otnLink1)
+ .addAugmentation(
+ new org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev200529.Link1Builder(
+ ietfLinkAZBldr.augmentation(
+ org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev200529.Link1.class))
+ .setLinkType(OpenroadmLinkType.OTNLINK)
+ .setOperationalState(State.InService)
+ .setAdministrativeState(AdminStates.InService)
+ .build());
+ links.add(ietfLinkAZBldr.build());
+ // create link Z-A
+ LinkBuilder ietfLinkZABldr = TopologyUtils.createLink(nodeZTopo, nodeATopo, tpZ, tpA, linkIdPrefix);
+ ietfLinkZABldr
+ .addAugmentation(tpceLink1)
+ .addAugmentation(otnLink1)
+ .addAugmentation(
+ new org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev200529.Link1Builder(
+ ietfLinkZABldr.augmentation(
+ org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev200529.Link1.class))
+ .setLinkType(OpenroadmLinkType.OTNLINK)
+ .setOperationalState(State.InService)
+ .setAdministrativeState(AdminStates.InService)
+ .build());
+ links.add(ietfLinkZABldr.build());
+ return links;
+ }
+
+ private static Link updateOtnLinkBwParameters(Link link, Long availBw, Long usedBw) {
+ LOG.debug("in updateOtnLinkBwParameters with availBw = {}, usedBw = {}", availBw, usedBw);
+ LinkBuilder updatedLinkBldr = new LinkBuilder(link);
+ Link1Builder updatedLink1Bldr = new Link1Builder(link.augmentation(Link1.class))
+ .setAvailableBandwidth(Uint32.valueOf(availBw))
+ .setUsedBandwidth(Uint32.valueOf(usedBw));
+ updatedLinkBldr.addAugmentation(updatedLink1Bldr.build());
+ return updatedLinkBldr.build();
+ }
+
+ private static TerminationPoint updateTp(TerminationPoint originalTp, boolean addingTsTpnPoolTermination) {
+ LOG.debug("in updateTp");
+ TerminationPointBuilder tpBldr = new TerminationPointBuilder(originalTp);
+ TerminationPoint1Builder otnTp1Bldr = new TerminationPoint1Builder(
+ tpBldr.augmentation(TerminationPoint1.class));
+ XpdrTpPortConnectionAttributesBuilder xtpcaBldr = new XpdrTpPortConnectionAttributesBuilder(otnTp1Bldr
+ .getXpdrTpPortConnectionAttributes());
+ if (addingTsTpnPoolTermination) {
+ List<Uint16> tsPool = new ArrayList<>();
+ for (int i = 0; i < NB_TRIB_SLOTS; i++) {
+ tsPool.add(Uint16.valueOf(i + 1));
+ }
+ xtpcaBldr.setTsPool(tsPool);
+ List<Uint16> tpnPool = new ArrayList<>();
+ for (int i = 1; i <= NB_TRIB_PORTS; i++) {
+ tpnPool.add(Uint16.valueOf(i));
+ }
+ OdtuTpnPool oduTpnPool = new OdtuTpnPoolBuilder().setOdtuType(ODTU4TsAllocated.class)
+ .setTpnPool(tpnPool).build();
+ xtpcaBldr.setOdtuTpnPool(ImmutableMap.of(oduTpnPool.key(),oduTpnPool));
+ } else {
+ xtpcaBldr.setTsPool(null);
+ xtpcaBldr.setOdtuTpnPool(ImmutableMap.of());
+ }
+ return tpBldr.addAugmentation(otnTp1Bldr.setXpdrTpPortConnectionAttributes(xtpcaBldr.build()).build()).build();
+ }
+
+ private static TerminationPoint updateNodeTpTsPool(TerminationPoint tp, String serviceRate, Short tribPortNb,
+ Short tribSlotNb, boolean isDeletion) {
+ LOG.debug("in updateNodeTpTsPool");
+ TerminationPointBuilder tpBldr = new TerminationPointBuilder(tp);
+ @Nullable
+ XpdrTpPortConnectionAttributesBuilder xtpcaBldr = new XpdrTpPortConnectionAttributesBuilder(
+ tpBldr.augmentation(TerminationPoint1.class).getXpdrTpPortConnectionAttributes());
+ List<Uint16> tsPool = new ArrayList<>(xtpcaBldr.getTsPool());
+ switch (serviceRate) {
+ case "1G":
+ if (isDeletion) {
+ tsPool.add(Uint16.valueOf(tribSlotNb));
+ } else {
+ tsPool.remove(Uint16.valueOf(tribSlotNb));
+ }
+ break;
+ case "10G":
+ if (isDeletion) {
+ for (int i = 0; i < NB_TRIB_SLOT_PER_10GE; i++) {
+ tsPool.add(Uint16.valueOf(tribSlotNb + i));
+ }
+ } else {
+ for (int i = 0; i < NB_TRIB_SLOT_PER_10GE; i++) {
+ tsPool.remove(Uint16.valueOf(tribSlotNb + i));
+ }
+ }
+ break;
+ default:
+ LOG.error("error updating tpn and ts pool for tp {}", tp.getTpId().getValue());
+ break;
+ }
+ xtpcaBldr.setTsPool(tsPool);
+ List<Uint16> tpnPool;
+ List<OdtuTpnPool> odtuTpnPoolValues = new ArrayList<>(xtpcaBldr.getOdtuTpnPool().values());
+ if (odtuTpnPoolValues.get(0).getTpnPool() != null) {
+ tpnPool = new ArrayList<>(odtuTpnPoolValues.get(0).getTpnPool());
+ if (isDeletion) {
+ tpnPool.add(Uint16.valueOf(tribPortNb));
+ } else {
+ tpnPool.remove(Uint16.valueOf(tribPortNb));
+ }
+ } else {
+ tpnPool = new ArrayList<>();
+ }
+ OdtuTpnPool odtuTpnPool = new OdtuTpnPoolBuilder().setOdtuType(ODTU4TsAllocated.class)
+ .setTpnPool(tpnPool).build();
+ xtpcaBldr.setOdtuTpnPool(ImmutableMap.of(odtuTpnPool.key(),odtuTpnPool));
+
+ tpBldr.addAugmentation(new TerminationPoint1Builder(tp.augmentation(TerminationPoint1.class))
+ .setXpdrTpPortConnectionAttributes(xtpcaBldr.build()).build());
+ return tpBldr.build();
+ }
+