0794d50a826c6be4aaf64d4a0414a658fcfb4c95
[transportpce.git] / tapi / src / test / java / org / opendaylight / transportpce / tapi / topology / ConvertORTopoToTapiTopoTest.java
1 /*
2  * Copyright © 2020 Orange, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.transportpce.tapi.topology;
9
10 import static org.hamcrest.CoreMatchers.containsString;
11 import static org.hamcrest.CoreMatchers.either;
12 import static org.hamcrest.CoreMatchers.hasItem;
13 import static org.hamcrest.CoreMatchers.hasItems;
14 import static org.hamcrest.MatcherAssert.assertThat;
15 import static org.junit.jupiter.api.Assertions.assertEquals;
16 import static org.junit.jupiter.api.Assertions.assertNull;
17 import static org.junit.jupiter.api.Assertions.fail;
18
19 import com.google.common.util.concurrent.FluentFuture;
20 import java.nio.charset.Charset;
21 import java.util.ArrayList;
22 import java.util.HashMap;
23 import java.util.Iterator;
24 import java.util.List;
25 import java.util.Map;
26 import java.util.Optional;
27 import java.util.UUID;
28 import java.util.concurrent.ExecutionException;
29 import java.util.stream.Collectors;
30 import org.eclipse.jdt.annotation.Nullable;
31 import org.junit.jupiter.api.BeforeAll;
32 import org.junit.jupiter.api.Test;
33 import org.opendaylight.mdsal.binding.api.DataBroker;
34 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
35 import org.opendaylight.transportpce.common.InstanceIdentifiers;
36 import org.opendaylight.transportpce.common.network.NetworkTransactionImpl;
37 import org.opendaylight.transportpce.common.network.NetworkTransactionService;
38 import org.opendaylight.transportpce.tapi.TapiStringConstants;
39 import org.opendaylight.transportpce.tapi.utils.TapiLink;
40 import org.opendaylight.transportpce.tapi.utils.TapiLinkImpl;
41 import org.opendaylight.transportpce.tapi.utils.TapiTopologyDataUtils;
42 import org.opendaylight.transportpce.test.AbstractTest;
43 import org.opendaylight.transportpce.test.utils.TopologyDataUtils;
44 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev230526.Link1;
45 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev230526.Link1Builder;
46 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev230526.TerminationPoint1;
47 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev230526.TerminationPoint1Builder;
48 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.state.types.rev191129.State;
49 import org.opendaylight.yang.gen.v1.http.org.openroadm.equipment.states.types.rev191129.AdminStates;
50 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev230526.OpenroadmTpType;
51 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.NetworkId;
52 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.Networks;
53 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.NodeId;
54 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.networks.NetworkKey;
55 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.networks.network.Node;
56 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.networks.network.NodeBuilder;
57 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.networks.network.NodeKey;
58 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.LinkId;
59 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.Network1;
60 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.Node1;
61 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.TpId;
62 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network.LinkKey;
63 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network.node.TerminationPoint;
64 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network.node.TerminationPointBuilder;
65 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network.node.TerminationPointKey;
66 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev221121.AdministrativeState;
67 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev221121.CAPACITYUNITGBPS;
68 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev221121.Direction;
69 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev221121.ForwardingDirection;
70 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev221121.LAYERPROTOCOLQUALIFIER;
71 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev221121.LayerProtocolName;
72 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev221121.LifecycleState;
73 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev221121.OperationalState;
74 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev221121.PortRole;
75 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev221121.Uuid;
76 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev221121.global._class.Name;
77 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev221121.global._class.NameKey;
78 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.digital.otn.rev221121.ODUTYPEODU2;
79 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.digital.otn.rev221121.ODUTYPEODU2E;
80 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.digital.otn.rev221121.ODUTYPEODU4;
81 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.dsr.rev221121.DIGITALSIGNALTYPE100GigE;
82 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.dsr.rev221121.DIGITALSIGNALTYPE10GigELAN;
83 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.photonic.media.rev221121.PHOTONICLAYERQUALIFIEROMS;
84 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.photonic.media.rev221121.PHOTONICLAYERQUALIFIEROTSi;
85 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.FORWARDINGRULEMAYFORWARDACROSSGROUP;
86 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.RuleType;
87 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.node.NodeRuleGroup;
88 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.node.OwnedNodeEdgePoint;
89 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.node.OwnedNodeEdgePointKey;
90 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.node.edge.point.MappedServiceInterfacePointKey;
91 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.node.edge.point.SupportedCepLayerProtocolQualifierInstances;
92 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.node.rule.group.NodeEdgePoint;
93 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.node.rule.group.Rule;
94 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.topology.Link;
95 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
96 import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
97 import org.opendaylight.yangtools.yang.common.Uint64;
98 import org.slf4j.Logger;
99 import org.slf4j.LoggerFactory;
100
101
102 public class ConvertORTopoToTapiTopoTest extends AbstractTest {
103     private static final Logger LOG = LoggerFactory.getLogger(ConvertORTopoToTapiTopoTest.class);
104
105     private static Node otnMuxA;
106     private static Node otnMuxC;
107     private static Node otnSwitch;
108     private static Node tpdr100G;
109     private static Map<LinkKey,org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226
110         .networks.network.Link> otnLinks;
111     private static Uuid topologyUuid;
112     private static NetworkTransactionService networkTransactionService;
113     private static TapiLink tapiLink;
114     private static DataBroker dataBroker = getDataBroker();
115
116     @BeforeAll
117     static void setUp() throws InterruptedException, ExecutionException {
118         TopologyDataUtils.writeTopologyFromFileToDatastore(getDataStoreContextUtil(),
119             TapiTopologyDataUtils.OPENROADM_TOPOLOGY_FILE, InstanceIdentifiers.OVERLAY_NETWORK_II);
120         TopologyDataUtils.writeTopologyFromFileToDatastore(getDataStoreContextUtil(),
121             TapiTopologyDataUtils.OTN_TOPOLOGY_FILE, InstanceIdentifiers.OTN_NETWORK_II);
122         TopologyDataUtils.writePortmappingFromFileToDatastore(getDataStoreContextUtil(),
123             TapiTopologyDataUtils.PORTMAPPING_FILE);
124
125         KeyedInstanceIdentifier<Node, NodeKey> muxAIID = InstanceIdentifier.create(Networks.class)
126             .child(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.networks.Network
127                 .class, new NetworkKey(new NetworkId("otn-topology")))
128             .child(Node.class, new NodeKey(new NodeId("SPDR-SA1-XPDR1")));
129         FluentFuture<Optional<Node>> muxAFuture = dataBroker.newReadOnlyTransaction()
130             .read(LogicalDatastoreType.CONFIGURATION, muxAIID);
131         KeyedInstanceIdentifier<Node, NodeKey> muxCIID = InstanceIdentifier.create(Networks.class)
132             .child(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.networks.Network
133                 .class, new NetworkKey(new NetworkId("otn-topology")))
134             .child(Node.class, new NodeKey(new NodeId("SPDR-SC1-XPDR1")));
135         FluentFuture<Optional<Node>> muxCFuture = dataBroker.newReadOnlyTransaction()
136             .read(LogicalDatastoreType.CONFIGURATION, muxCIID);
137         KeyedInstanceIdentifier<Node, NodeKey> switchIID = InstanceIdentifier.create(Networks.class)
138             .child(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.networks.Network
139                 .class, new NetworkKey(new NetworkId("otn-topology")))
140             .child(Node.class, new NodeKey(new NodeId("SPDR-SA1-XPDR2")));
141         FluentFuture<Optional<Node>> switchFuture = dataBroker.newReadOnlyTransaction()
142             .read(LogicalDatastoreType.CONFIGURATION, switchIID);
143
144         otnMuxA = muxAFuture.get().orElseThrow();
145         otnMuxC = muxCFuture.get().orElseThrow();
146         otnSwitch = switchFuture.get().orElseThrow();
147
148         KeyedInstanceIdentifier<Node, NodeKey> tpdrIID = InstanceIdentifier.create(Networks.class)
149             .child(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.networks.Network
150                 .class, new NetworkKey(new NetworkId("otn-topology")))
151             .child(Node.class, new NodeKey(new NodeId("XPDR-A1-XPDR1")));
152         FluentFuture<Optional<Node>> tpdrFuture = dataBroker.newReadOnlyTransaction()
153             .read(LogicalDatastoreType.CONFIGURATION, tpdrIID);
154         tpdr100G = tpdrFuture.get().orElseThrow();
155
156         InstanceIdentifier<Network1> linksIID = InstanceIdentifier.create(Networks.class)
157             .child(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.networks.Network
158                 .class, new NetworkKey(new NetworkId("otn-topology")))
159             .augmentation(Network1.class);
160         FluentFuture<Optional<Network1>> linksFuture = dataBroker.newReadOnlyTransaction()
161             .read(LogicalDatastoreType.CONFIGURATION, linksIID);
162         otnLinks = linksFuture.get().orElseThrow().getLink();
163
164         topologyUuid = new Uuid(UUID.nameUUIDFromBytes(TapiStringConstants.T0_MULTILAYER.getBytes(
165             Charset.forName("UTF-8"))).toString());
166         networkTransactionService = new NetworkTransactionImpl(getDataBroker());
167         tapiLink = new TapiLinkImpl(networkTransactionService);
168         LOG.info("TEST SETUP READY");
169     }
170
171     @Test
172     void convertNodeWhenNoStates() {
173         Node tpdr = changeTerminationPointState(tpdr100G, "XPDR1-NETWORK1", null, null);
174         List<String> networkPortList = new ArrayList<>();
175         for (TerminationPoint tp : tpdr100G.augmentation(Node1.class).getTerminationPoint().values()) {
176             if (tp.augmentation(TerminationPoint1.class).getTpType().equals(OpenroadmTpType.XPONDERNETWORK)) {
177                 networkPortList.add(tp.getTpId().getValue());
178             }
179         }
180         ConvertORTopoToTapiTopo tapiFactory = new ConvertORTopoToTapiTopo(topologyUuid, tapiLink);
181         tapiFactory.convertNode(tpdr, networkPortList);
182
183         Uuid dsrNodeUuid = new Uuid(UUID.nameUUIDFromBytes("XPDR-A1-XPDR1+DSR".getBytes(Charset.forName("UTF-8")))
184             .toString());
185         org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.topology.Node dsrNode = tapiFactory
186             .getTapiNodes().get(new
187                 org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.topology.NodeKey(dsrNodeUuid));
188         Uuid networkNepUuid = new Uuid(
189             UUID.nameUUIDFromBytes(("XPDR-A1-XPDR1+iODU+XPDR1-NETWORK1").getBytes(Charset.forName("UTF-8")))
190                 .toString());
191         OwnedNodeEdgePoint nepN = dsrNode.nonnullOwnedNodeEdgePoint().get(new OwnedNodeEdgePointKey(networkNepUuid));
192         assertNull(nepN.getAdministrativeState(), "Administrative State should not be present");
193         assertNull(nepN.getOperationalState(), "Operational State should not be present");
194
195         Uuid otsiNodeUuid = new Uuid(UUID.nameUUIDFromBytes("XPDR-A1-XPDR1+OTSi".getBytes(Charset.forName("UTF-8")))
196             .toString());
197         org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.topology.Node otsiNode = tapiFactory
198             .getTapiNodes().get(new
199                 org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.topology.NodeKey(otsiNodeUuid));
200         Uuid enepUuid = new Uuid(
201             UUID.nameUUIDFromBytes(("XPDR-A1-XPDR1+eOTSi+XPDR1-NETWORK1").getBytes(Charset.forName("UTF-8")))
202                 .toString());
203         Uuid inepUuid = new Uuid(
204             UUID.nameUUIDFromBytes(("XPDR-A1-XPDR1+iOTSi+XPDR1-NETWORK1").getBytes(Charset.forName("UTF-8")))
205                 .toString());
206         OwnedNodeEdgePoint enep = otsiNode.nonnullOwnedNodeEdgePoint().get(new OwnedNodeEdgePointKey(enepUuid));
207         assertNull(enep.getAdministrativeState(), "Administrative State should not be present");
208         assertNull(enep.getOperationalState(), "Operational State should not be present");
209
210         OwnedNodeEdgePoint inep = otsiNode.nonnullOwnedNodeEdgePoint().get(new OwnedNodeEdgePointKey(inepUuid));
211         assertNull(inep.getAdministrativeState(), "Administrative State should not be present");
212         assertNull(inep.getOperationalState(), "Operational State should not be present");
213     }
214
215     @Test
216     void convertNodeWhenBadStates1() {
217         Node tpdr = changeTerminationPointState(tpdr100G, "XPDR1-NETWORK1", AdminStates.OutOfService,
218             State.OutOfService);
219         List<String> networkPortList = new ArrayList<>();
220         for (TerminationPoint tp : tpdr100G.augmentation(Node1.class).getTerminationPoint().values()) {
221             if (tp.augmentation(TerminationPoint1.class).getTpType().equals(OpenroadmTpType.XPONDERNETWORK)) {
222                 networkPortList.add(tp.getTpId().getValue());
223             }
224         }
225         ConvertORTopoToTapiTopo tapiFactory = new ConvertORTopoToTapiTopo(topologyUuid, tapiLink);
226         tapiFactory.convertNode(tpdr, networkPortList);
227
228         Uuid dsrNodeUuid = new Uuid(UUID.nameUUIDFromBytes("XPDR-A1-XPDR1+DSR".getBytes(Charset.forName("UTF-8")))
229             .toString());
230         org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.topology.Node dsrNode = tapiFactory
231             .getTapiNodes().get(new
232                 org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.topology.NodeKey(dsrNodeUuid));
233         Uuid networkNepUuid = new Uuid(
234             UUID.nameUUIDFromBytes(("XPDR-A1-XPDR1+iODU+XPDR1-NETWORK1").getBytes(Charset.forName("UTF-8")))
235                 .toString());
236         OwnedNodeEdgePoint nepN = dsrNode.nonnullOwnedNodeEdgePoint().get(new OwnedNodeEdgePointKey(networkNepUuid));
237         assertEquals(AdministrativeState.LOCKED, nepN.getAdministrativeState(),
238             "Administrative State should be Locked");
239         assertEquals(OperationalState.DISABLED, nepN.getOperationalState(), "Operational State should be Disabled");
240
241         Uuid otsiNodeUuid = new Uuid(UUID.nameUUIDFromBytes("XPDR-A1-XPDR1+OTSi".getBytes(Charset.forName("UTF-8")))
242             .toString());
243         org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.topology.Node otsiNode = tapiFactory
244             .getTapiNodes().get(new
245                 org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.topology.NodeKey(otsiNodeUuid));
246         Uuid enepUuid = new Uuid(
247             UUID.nameUUIDFromBytes(("XPDR-A1-XPDR1+eOTSi+XPDR1-NETWORK1").getBytes(Charset.forName("UTF-8")))
248                 .toString());
249         Uuid inepUuid = new Uuid(
250             UUID.nameUUIDFromBytes(("XPDR-A1-XPDR1+iOTSi+XPDR1-NETWORK1").getBytes(Charset.forName("UTF-8")))
251                 .toString());
252         OwnedNodeEdgePoint enep = otsiNode.nonnullOwnedNodeEdgePoint().get(new OwnedNodeEdgePointKey(enepUuid));
253         assertEquals(AdministrativeState.LOCKED, enep.getAdministrativeState(),
254             "Administrative State should be Locked");
255         assertEquals(OperationalState.DISABLED, enep.getOperationalState(), "Operational State should be Disabled");
256
257         OwnedNodeEdgePoint inep = otsiNode.nonnullOwnedNodeEdgePoint().get(new OwnedNodeEdgePointKey(inepUuid));
258         assertEquals(AdministrativeState.LOCKED, inep.getAdministrativeState(),
259             "Administrative State should be Locked");
260         assertEquals(OperationalState.DISABLED, inep.getOperationalState(), "Operational State should be Disabled");
261     }
262
263     @Test
264     void convertNodeWhenBadStates2() {
265         Node tpdr = changeTerminationPointState(tpdr100G, "XPDR1-NETWORK1", AdminStates.Maintenance,
266             State.Degraded);
267         List<String> networkPortList = new ArrayList<>();
268         for (TerminationPoint tp : tpdr100G.augmentation(Node1.class).getTerminationPoint().values()) {
269             if (tp.augmentation(TerminationPoint1.class).getTpType().equals(OpenroadmTpType.XPONDERNETWORK)) {
270                 networkPortList.add(tp.getTpId().getValue());
271             }
272         }
273         ConvertORTopoToTapiTopo tapiFactory = new ConvertORTopoToTapiTopo(topologyUuid, tapiLink);
274         tapiFactory.convertNode(tpdr, networkPortList);
275
276         Uuid dsrNodeUuid = new Uuid(UUID.nameUUIDFromBytes("XPDR-A1-XPDR1+DSR".getBytes(Charset.forName("UTF-8")))
277             .toString());
278         org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.topology.Node dsrNode = tapiFactory
279             .getTapiNodes().get(new
280                 org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.topology.NodeKey(dsrNodeUuid));
281         Uuid networkNepUuid = new Uuid(
282             UUID.nameUUIDFromBytes(("XPDR-A1-XPDR1+iODU+XPDR1-NETWORK1").getBytes(Charset.forName("UTF-8")))
283                 .toString());
284         OwnedNodeEdgePoint nepN = dsrNode.nonnullOwnedNodeEdgePoint().get(new OwnedNodeEdgePointKey(networkNepUuid));
285         assertEquals(AdministrativeState.LOCKED, nepN.getAdministrativeState(),
286             "Administrative State should be Locked");
287         assertEquals(OperationalState.DISABLED, nepN.getOperationalState(), "Operational State should be Disabled");
288
289         Uuid otsiNodeUuid = new Uuid(UUID.nameUUIDFromBytes("XPDR-A1-XPDR1+OTSi".getBytes(Charset.forName("UTF-8")))
290             .toString());
291         org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.topology.Node otsiNode = tapiFactory
292             .getTapiNodes().get(new
293                 org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.topology.NodeKey(otsiNodeUuid));
294         Uuid enepUuid = new Uuid(
295             UUID.nameUUIDFromBytes(("XPDR-A1-XPDR1+eOTSi+XPDR1-NETWORK1").getBytes(Charset.forName("UTF-8")))
296                 .toString());
297         Uuid inepUuid = new Uuid(
298             UUID.nameUUIDFromBytes(("XPDR-A1-XPDR1+iOTSi+XPDR1-NETWORK1").getBytes(Charset.forName("UTF-8")))
299                 .toString());
300         OwnedNodeEdgePoint enep = otsiNode.nonnullOwnedNodeEdgePoint().get(new OwnedNodeEdgePointKey(enepUuid));
301         assertEquals(AdministrativeState.LOCKED, enep.getAdministrativeState(),
302             "Administrative State should be Locked");
303         assertEquals(OperationalState.DISABLED, enep.getOperationalState(), "Operational State should be Disabled");
304
305         OwnedNodeEdgePoint inep = otsiNode.nonnullOwnedNodeEdgePoint().get(new OwnedNodeEdgePointKey(inepUuid));
306         assertEquals(AdministrativeState.LOCKED, inep.getAdministrativeState(),
307             "Administrative State should be Locked");
308         assertEquals(OperationalState.DISABLED, inep.getOperationalState(), "Operational State should be Disabled");
309     }
310
311     @Test
312     void convertOtnLinkWhenNoState() {
313         HashMap<LinkKey, org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226
314             .networks.network.Link> otnLinksAlt = new HashMap<>(otnLinks);
315         org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network.Link
316             link = changeOtnLinkState(otnLinks.get(new LinkKey(
317                 new LinkId("ODTU4-SPDR-SA1-XPDR1-XPDR1-NETWORK1toSPDR-SC1-XPDR1-XPDR1-NETWORK1"))), null, null);
318         otnLinksAlt.replace(link.key(), link);
319
320         ConvertORTopoToTapiTopo tapiFactory = new ConvertORTopoToTapiTopo(topologyUuid, tapiLink);
321         List<String> networkPortListA = new ArrayList<>();
322         for (TerminationPoint tp : otnMuxA.augmentation(Node1.class).getTerminationPoint().values()) {
323             if (tp.augmentation(TerminationPoint1.class).getTpType().equals(OpenroadmTpType.XPONDERNETWORK)) {
324                 networkPortListA.add(tp.getTpId().getValue());
325             }
326         }
327         tapiFactory.convertNode(otnMuxA, networkPortListA);
328         List<String> networkPortListC = new ArrayList<>();
329         for (TerminationPoint tp : otnMuxC.augmentation(Node1.class).getTerminationPoint().values()) {
330             if (tp.augmentation(TerminationPoint1.class).getTpType().equals(OpenroadmTpType.XPONDERNETWORK)) {
331                 networkPortListC.add(tp.getTpId().getValue());
332             }
333         }
334         tapiFactory.convertNode(otnMuxC, networkPortListC);
335         tapiFactory.convertLinks(otnLinksAlt);
336
337         List<Link> tapiLinks = tapiFactory.getTapiLinks().values().stream()
338             .sorted((l1, l2) -> l1.getUuid().getValue().compareTo(l2.getUuid().getValue()))
339             .collect(Collectors.toList());
340         assertNull(tapiLinks.get(3).getAdministrativeState(), "Administrative State should not be present");
341         assertEquals(AdministrativeState.UNLOCKED, tapiLinks.get(0).getAdministrativeState(),
342             "Administrative state should be UNLOCKED");
343         assertNull(tapiLinks.get(3).getOperationalState(), "Operational State should not be present");
344         assertEquals(OperationalState.ENABLED, tapiLinks.get(0).getOperationalState(),
345             "Operational state should be ENABLED");
346     }
347
348     @Test
349     void convertOtnLinkWhenNoStateOnOppositeLink() {
350         HashMap<LinkKey, org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226
351             .networks.network.Link> otnLinksAlt = new HashMap<>(otnLinks);
352         org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network.Link
353             link = changeOtnLinkState(otnLinks.get(new LinkKey(
354                 new LinkId("ODTU4-SPDR-SC1-XPDR1-XPDR1-NETWORK1toSPDR-SA1-XPDR1-XPDR1-NETWORK1"))), null, null);
355         otnLinksAlt.replace(link.key(), link);
356
357         ConvertORTopoToTapiTopo tapiFactory = new ConvertORTopoToTapiTopo(topologyUuid, tapiLink);
358         List<String> networkPortListA = new ArrayList<>();
359         for (TerminationPoint tp : otnMuxA.augmentation(Node1.class).getTerminationPoint().values()) {
360             if (tp.augmentation(TerminationPoint1.class).getTpType().equals(OpenroadmTpType.XPONDERNETWORK)) {
361                 networkPortListA.add(tp.getTpId().getValue());
362             }
363         }
364         tapiFactory.convertNode(otnMuxA, networkPortListA);
365         List<String> networkPortListC = new ArrayList<>();
366         for (TerminationPoint tp : otnMuxC.augmentation(Node1.class).getTerminationPoint().values()) {
367             if (tp.augmentation(TerminationPoint1.class).getTpType().equals(OpenroadmTpType.XPONDERNETWORK)) {
368                 networkPortListC.add(tp.getTpId().getValue());
369             }
370         }
371         tapiFactory.convertNode(otnMuxC, networkPortListC);
372         tapiFactory.convertLinks(otnLinksAlt);
373
374         List<Link> tapiLinks = tapiFactory.getTapiLinks().values().stream()
375             .sorted((l1, l2) -> l1.getUuid().getValue().compareTo(l2.getUuid().getValue()))
376             .collect(Collectors.toList());
377         assertNull(tapiLinks.get(3).getAdministrativeState(), "Administrative State should not be present");
378         assertEquals(AdministrativeState.UNLOCKED, tapiLinks.get(0).getAdministrativeState(),
379             "Administrative state should be UNLOCKED");
380         assertNull(tapiLinks.get(3).getOperationalState(), "Operational State should not be present");
381         assertEquals(OperationalState.ENABLED, tapiLinks.get(0).getOperationalState(),
382             "Operational state should be ENABLED");
383     }
384
385     @Test
386     void convertOtnLinkWhenBadState1() {
387         HashMap<LinkKey, org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226
388             .networks.network.Link> otnLinksAlt = new HashMap<>(otnLinks);
389         org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network.Link
390             link = changeOtnLinkState(otnLinks.get(new LinkKey(
391                 new LinkId("ODTU4-SPDR-SA1-XPDR1-XPDR1-NETWORK1toSPDR-SC1-XPDR1-XPDR1-NETWORK1"))),
392                 AdminStates.OutOfService, State.OutOfService);
393         otnLinksAlt.replace(link.key(), link);
394
395         ConvertORTopoToTapiTopo tapiFactory = new ConvertORTopoToTapiTopo(topologyUuid, tapiLink);
396         List<String> networkPortListA = new ArrayList<>();
397         for (TerminationPoint tp : otnMuxA.augmentation(Node1.class).getTerminationPoint().values()) {
398             if (tp.augmentation(TerminationPoint1.class).getTpType().equals(OpenroadmTpType.XPONDERNETWORK)) {
399                 networkPortListA.add(tp.getTpId().getValue());
400             }
401         }
402         tapiFactory.convertNode(otnMuxA, networkPortListA);
403         List<String> networkPortListC = new ArrayList<>();
404         for (TerminationPoint tp : otnMuxC.augmentation(Node1.class).getTerminationPoint().values()) {
405             if (tp.augmentation(TerminationPoint1.class).getTpType().equals(OpenroadmTpType.XPONDERNETWORK)) {
406                 networkPortListC.add(tp.getTpId().getValue());
407             }
408         }
409         tapiFactory.convertNode(otnMuxC, networkPortListC);
410         tapiFactory.convertLinks(otnLinksAlt);
411
412         List<Link> tapiLinks = tapiFactory.getTapiLinks().values().stream()
413             .sorted((l1, l2) -> l1.getUuid().getValue().compareTo(l2.getUuid().getValue()))
414             .collect(Collectors.toList());
415         assertEquals(AdministrativeState.LOCKED, tapiLinks.get(3).getAdministrativeState(),
416             "Administrative state should be LOCKED");
417         assertEquals(AdministrativeState.UNLOCKED, tapiLinks.get(0).getAdministrativeState(),
418             "Administrative state should be UNLOCKED");
419         assertEquals(OperationalState.DISABLED, tapiLinks.get(3).getOperationalState(),
420             "Operational state should be DISABLED");
421         assertEquals(OperationalState.ENABLED, tapiLinks.get(0).getOperationalState(),
422             "Operational state should be ENABLED");
423     }
424
425     @Test
426     void convertOtnLinkWhenBadState2() {
427         HashMap<LinkKey, org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226
428             .networks.network.Link> otnLinksAlt = new HashMap<>(otnLinks);
429         org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network.Link
430             link = changeOtnLinkState(otnLinks.get(new LinkKey(
431                 new LinkId("ODTU4-SPDR-SA1-XPDR1-XPDR1-NETWORK1toSPDR-SC1-XPDR1-XPDR1-NETWORK1"))),
432                 AdminStates.Maintenance, State.Degraded);
433         otnLinksAlt.replace(link.key(), link);
434
435         ConvertORTopoToTapiTopo tapiFactory = new ConvertORTopoToTapiTopo(topologyUuid, tapiLink);
436         List<String> networkPortListA = new ArrayList<>();
437         for (TerminationPoint tp : otnMuxA.augmentation(Node1.class).getTerminationPoint().values()) {
438             if (tp.augmentation(TerminationPoint1.class).getTpType().equals(OpenroadmTpType.XPONDERNETWORK)) {
439                 networkPortListA.add(tp.getTpId().getValue());
440             }
441         }
442         tapiFactory.convertNode(otnMuxA, networkPortListA);
443         List<String> networkPortListC = new ArrayList<>();
444         for (TerminationPoint tp : otnMuxC.augmentation(Node1.class).getTerminationPoint().values()) {
445             if (tp.augmentation(TerminationPoint1.class).getTpType().equals(OpenroadmTpType.XPONDERNETWORK)) {
446                 networkPortListC.add(tp.getTpId().getValue());
447             }
448         }
449         tapiFactory.convertNode(otnMuxC, networkPortListC);
450         tapiFactory.convertLinks(otnLinksAlt);
451
452         List<Link> tapiLinks = tapiFactory.getTapiLinks().values().stream()
453             .sorted((l1, l2) -> l1.getUuid().getValue().compareTo(l2.getUuid().getValue()))
454             .collect(Collectors.toList());
455         assertEquals(AdministrativeState.LOCKED, tapiLinks.get(3).getAdministrativeState(),
456             "Administrative state should be LOCKED");
457         assertEquals(AdministrativeState.UNLOCKED, tapiLinks.get(0).getAdministrativeState(),
458             "Administrative state should be UNLOCKED");
459         assertEquals(OperationalState.DISABLED, tapiLinks.get(3).getOperationalState(),
460             "Operational state should be DISABLED");
461         assertEquals(OperationalState.ENABLED, tapiLinks.get(0).getOperationalState(),
462             "Operational state should be ENABLED");
463     }
464
465     @Test
466     void convertOtnLinkWhenBadStateOnOppositeLink() {
467         HashMap<LinkKey, org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226
468             .networks.network.Link> otnLinksAlt = new HashMap<>(otnLinks);
469         org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network.Link
470             link = changeOtnLinkState(otnLinks.get(new LinkKey(
471                 new LinkId("ODTU4-SPDR-SC1-XPDR1-XPDR1-NETWORK1toSPDR-SA1-XPDR1-XPDR1-NETWORK1"))),
472                 AdminStates.OutOfService, State.OutOfService);
473         otnLinksAlt.replace(link.key(), link);
474
475         ConvertORTopoToTapiTopo tapiFactory = new ConvertORTopoToTapiTopo(topologyUuid, tapiLink);
476         List<String> networkPortListA = new ArrayList<>();
477         for (TerminationPoint tp : otnMuxA.augmentation(Node1.class).getTerminationPoint().values()) {
478             if (tp.augmentation(TerminationPoint1.class).getTpType().equals(OpenroadmTpType.XPONDERNETWORK)) {
479                 networkPortListA.add(tp.getTpId().getValue());
480             }
481         }
482         tapiFactory.convertNode(otnMuxA, networkPortListA);
483         List<String> networkPortListC = new ArrayList<>();
484         for (TerminationPoint tp : otnMuxC.augmentation(Node1.class).getTerminationPoint().values()) {
485             if (tp.augmentation(TerminationPoint1.class).getTpType().equals(OpenroadmTpType.XPONDERNETWORK)) {
486                 networkPortListC.add(tp.getTpId().getValue());
487             }
488         }
489         tapiFactory.convertNode(otnMuxC, networkPortListC);
490         tapiFactory.convertLinks(otnLinksAlt);
491
492         List<Link> tapiLinks = tapiFactory.getTapiLinks().values().stream()
493             .sorted((l1, l2) -> l1.getUuid().getValue().compareTo(l2.getUuid().getValue()))
494             .collect(Collectors.toList());
495         assertEquals(AdministrativeState.LOCKED, tapiLinks.get(3).getAdministrativeState(),
496             "Administrative state should be LOCKED");
497         assertEquals(AdministrativeState.UNLOCKED, tapiLinks.get(0).getAdministrativeState(),
498             "Administrative state should be UNLOCKED");
499         assertEquals(OperationalState.DISABLED, tapiLinks.get(3).getOperationalState(),
500             "Operational state should be DISABLED");
501         assertEquals(OperationalState.ENABLED, tapiLinks.get(0).getOperationalState(),
502             "Operational state should be ENABLED");
503     }
504
505     @Test
506     void convertNodeForTransponder100G() {
507         ConvertORTopoToTapiTopo tapiFactory = new ConvertORTopoToTapiTopo(topologyUuid, tapiLink);
508         List<String> networkPortList = new ArrayList<>();
509         for (TerminationPoint tp : tpdr100G.augmentation(Node1.class).getTerminationPoint().values()) {
510             if (tp.augmentation(TerminationPoint1.class).getTpType().equals(OpenroadmTpType.XPONDERNETWORK)) {
511                 networkPortList.add(tp.getTpId().getValue());
512             }
513         }
514         tapiFactory.convertNode(tpdr100G, networkPortList);
515         List<org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.topology.Node> tapiNodes
516             = tapiFactory.getTapiNodes().values().stream()
517             .sorted((n1, n2) -> n1.getUuid().getValue().compareTo(n2.getUuid().getValue()))
518             .collect(Collectors.toList());
519
520         assertEquals(2, tapiFactory.getTapiNodes().size(), "Node list size should be 2");
521         assertEquals(2, tapiFactory.getTapiLinks().size(), "Link list size should be 2");
522
523         Uuid dsrNodeUuid = new Uuid(UUID.nameUUIDFromBytes("XPDR-A1-XPDR1+DSR".getBytes(Charset.forName("UTF-8")))
524             .toString());
525         checkDsrNode(tapiNodes.get(1), dsrNodeUuid, "tpdr", "XPDR-A1-XPDR1+DSR");
526         Uuid otsiNodeUuid = new Uuid(UUID.nameUUIDFromBytes("XPDR-A1-XPDR1+OTSi".getBytes(Charset.forName("UTF-8")))
527             .toString());
528         checkOtsiNode(tapiNodes.get(0), otsiNodeUuid, "tpdr", "XPDR-A1-XPDR1+OTSi");
529
530         List<Link> tapiLinks = tapiFactory.getTapiLinks().values().stream()
531             .sorted((l1, l2) -> l1.getUuid().getValue().compareTo(l2.getUuid().getValue()))
532             .collect(Collectors.toList());
533         checkTransitionalLink(tapiLinks.get(1), dsrNodeUuid, otsiNodeUuid,
534             "XPDR-A1-XPDR1+iODU+XPDR1-NETWORK1", "XPDR-A1-XPDR1+iOTSi+XPDR1-NETWORK1", "XPDR-A1-XPDR1");
535     }
536
537     @Test
538     void convertNodeForOtnMuxponder() {
539         ConvertORTopoToTapiTopo tapiFactory = new ConvertORTopoToTapiTopo(topologyUuid, tapiLink);
540         List<String> networkPortList = new ArrayList<>();
541         for (TerminationPoint tp : otnMuxA.augmentation(Node1.class).getTerminationPoint().values()) {
542             if (tp.augmentation(TerminationPoint1.class).getTpType().equals(OpenroadmTpType.XPONDERNETWORK)) {
543                 networkPortList.add(tp.getTpId().getValue());
544             }
545         }
546         tapiFactory.convertNode(otnMuxA, networkPortList);
547         List<org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.topology.Node> tapiNodes
548             = tapiFactory.getTapiNodes().values().stream()
549             .sorted((n1, n2) -> n1.getUuid().getValue().compareTo(n2.getUuid().getValue()))
550             .collect(Collectors.toList());
551
552         assertEquals(2, tapiFactory.getTapiNodes().size(), "Node list size should be 2");
553         assertEquals(1, tapiFactory.getTapiLinks().size(), "Link list size should be 1");
554         Uuid dsrNodeUuid = new Uuid(UUID.nameUUIDFromBytes("SPDR-SA1-XPDR1+DSR".getBytes(Charset.forName("UTF-8")))
555             .toString());
556         checkDsrNode(tapiNodes.get(0), dsrNodeUuid, "mux", "SPDR-SA1-XPDR1+DSR");
557         Uuid otsiNodeUuid = new Uuid(UUID.nameUUIDFromBytes("SPDR-SA1-XPDR1+OTSi".getBytes(Charset.forName("UTF-8")))
558             .toString());
559         checkOtsiNode(tapiNodes.get(1), otsiNodeUuid, "mux", "SPDR-SA1-XPDR1+OTSi");
560
561         List<Link> tapiLinks = tapiFactory.getTapiLinks().values().stream()
562             .sorted((l1, l2) -> l1.getUuid().getValue().compareTo(l2.getUuid().getValue()))
563             .collect(Collectors.toList());
564         checkTransitionalLink(tapiLinks.get(0), dsrNodeUuid, otsiNodeUuid,
565             "SPDR-SA1-XPDR1+iODU+XPDR1-NETWORK1", "SPDR-SA1-XPDR1+iOTSi+XPDR1-NETWORK1", "SPDR-SA1-XPDR1");
566     }
567
568     @Test
569     void convertNodeForOtnSwitch() {
570         ConvertORTopoToTapiTopo tapiFactory = new ConvertORTopoToTapiTopo(topologyUuid, tapiLink);
571         List<String> networkPortList = new ArrayList<>();
572         for (TerminationPoint tp : otnSwitch.augmentation(Node1.class).getTerminationPoint().values()) {
573             if (tp.augmentation(TerminationPoint1.class).getTpType().equals(OpenroadmTpType.XPONDERNETWORK)) {
574                 networkPortList.add(tp.getTpId().getValue());
575             }
576         }
577         tapiFactory.convertNode(otnSwitch, networkPortList);
578         List<org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.topology.Node> tapiNodes
579             = tapiFactory.getTapiNodes().values().stream()
580             .sorted((n1, n2) -> n1.getUuid().getValue().compareTo(n2.getUuid().getValue()))
581             .collect(Collectors.toList());
582
583         assertEquals(2, tapiFactory.getTapiNodes().size(), "Node list size should be 2");
584         assertEquals(4, tapiFactory.getTapiLinks().size(), "Link list size should be 4");
585
586         Uuid dsrNodeUuid = new Uuid(UUID.nameUUIDFromBytes("SPDR-SA1-XPDR2+DSR".getBytes(Charset.forName("UTF-8")))
587             .toString());
588         checkDsrNode(tapiNodes.get(0), dsrNodeUuid, "switch", "SPDR-SA1-XPDR2+DSR");
589         Uuid otsiNodeUuid = new Uuid(UUID.nameUUIDFromBytes("SPDR-SA1-XPDR2+OTSi".getBytes(Charset.forName("UTF-8")))
590             .toString());
591         checkOtsiNode(tapiNodes.get(1), otsiNodeUuid, "switch", "SPDR-SA1-XPDR2+OTSi");
592
593         List<Link> tapiLinks = tapiFactory.getTapiLinks().values().stream()
594             .sorted((l1, l2) -> l1.getUuid().getValue().compareTo(l2.getUuid().getValue()))
595             .collect(Collectors.toList());
596         checkTransitionalLink(tapiLinks.get(2), dsrNodeUuid, otsiNodeUuid,
597             "SPDR-SA1-XPDR2+iODU+XPDR2-NETWORK4", "SPDR-SA1-XPDR2+iOTSi+XPDR2-NETWORK4", "SPDR-SA1-XPDR2");
598     }
599
600     @Test
601     void convertOtnLink() {
602         ConvertORTopoToTapiTopo tapiFactory = new ConvertORTopoToTapiTopo(topologyUuid, tapiLink);
603         List<String> networkPortListA = new ArrayList<>();
604         for (TerminationPoint tp : otnMuxA.augmentation(Node1.class).getTerminationPoint().values()) {
605             if (tp.augmentation(TerminationPoint1.class).getTpType().equals(OpenroadmTpType.XPONDERNETWORK)) {
606                 networkPortListA.add(tp.getTpId().getValue());
607             }
608         }
609         tapiFactory.convertNode(otnMuxA, networkPortListA);
610         List<String> networkPortListC = new ArrayList<>();
611         for (TerminationPoint tp : otnMuxC.augmentation(Node1.class).getTerminationPoint().values()) {
612             if (tp.augmentation(TerminationPoint1.class).getTpType().equals(OpenroadmTpType.XPONDERNETWORK)) {
613                 networkPortListC.add(tp.getTpId().getValue());
614             }
615         }
616         tapiFactory.convertNode(otnMuxC, networkPortListC);
617         tapiFactory.convertLinks(otnLinks);
618         assertEquals(4, tapiFactory.getTapiLinks().size(), "Link list size should be 4");
619
620         Uuid node1Uuid = new Uuid(UUID.nameUUIDFromBytes("SPDR-SA1-XPDR1+DSR".getBytes(Charset.forName("UTF-8")))
621             .toString());
622         Uuid node2Uuid = new Uuid(UUID.nameUUIDFromBytes("SPDR-SC1-XPDR1+DSR".getBytes(Charset.forName("UTF-8")))
623             .toString());
624         Uuid node3Uuid = new Uuid(UUID.nameUUIDFromBytes("SPDR-SA1-XPDR1+OTSi".getBytes(Charset.forName("UTF-8")))
625             .toString());
626         Uuid node4Uuid = new Uuid(UUID.nameUUIDFromBytes("SPDR-SC1-XPDR1+OTSi".getBytes(Charset.forName("UTF-8")))
627             .toString());
628         Uuid tp1Uuid = new Uuid(UUID.nameUUIDFromBytes("SPDR-SA1-XPDR1+eODU+XPDR1-NETWORK1"
629             .getBytes(Charset.forName("UTF-8"))).toString());
630         Uuid tp2Uuid = new Uuid(UUID.nameUUIDFromBytes("SPDR-SC1-XPDR1+eODU+XPDR1-NETWORK1"
631             .getBytes(Charset.forName("UTF-8"))).toString());
632         Uuid tp3Uuid = new Uuid(UUID.nameUUIDFromBytes("SPDR-SA1-XPDR1+iOTSi+XPDR1-NETWORK1"
633             .getBytes(Charset.forName("UTF-8"))).toString());
634         Uuid tp4Uuid = new Uuid(UUID.nameUUIDFromBytes("SPDR-SC1-XPDR1+iOTSi+XPDR1-NETWORK1"
635             .getBytes(Charset.forName("UTF-8"))).toString());
636         Uuid link1Uuid =
637             new Uuid(UUID.nameUUIDFromBytes("SPDR-SA1-XPDR1+eODU+XPDR1-NETWORK1toSPDR-SC1-XPDR1+eODU+XPDR1-NETWORK1"
638                 .getBytes(Charset.forName("UTF-8"))).toString());
639         Uuid link2Uuid =
640             new Uuid(UUID.nameUUIDFromBytes("SPDR-SA1-XPDR1+iOTSi+XPDR1-NETWORK1toSPDR-SC1-XPDR1+iOTSi+XPDR1-NETWORK1"
641                 .getBytes(Charset.forName("UTF-8"))).toString());
642
643         List<Link> links = tapiFactory.getTapiLinks().values().stream()
644             .sorted((l1, l2) -> l1.getUuid().getValue().compareTo(l2.getUuid().getValue()))
645             .collect(Collectors.toList());
646         checkOtnLink(links.get(3), node1Uuid, node2Uuid, tp1Uuid, tp2Uuid, link1Uuid,
647             "SPDR-SA1-XPDR1+eODU+XPDR1-NETWORK1toSPDR-SC1-XPDR1+eODU+XPDR1-NETWORK1");
648         checkOtnLink(links.get(2), node3Uuid, node4Uuid, tp3Uuid, tp4Uuid, link2Uuid,
649             "SPDR-SA1-XPDR1+iOTSi+XPDR1-NETWORK1toSPDR-SC1-XPDR1+iOTSi+XPDR1-NETWORK1");
650     }
651
652     @Test
653     void convertRoadmInfrastructureWhenNoXponderAttached() {
654         ConvertORTopoToTapiTopo tapiFactory = new ConvertORTopoToTapiTopo(topologyUuid, tapiLink);
655         tapiFactory.convertRoadmInfrastructure();
656
657         assertEquals(1, tapiFactory.getTapiNodes().size(), "Node list size should be 1");
658         assertEquals(0, tapiFactory.getTapiLinks().size(), "Link list size should be empty");
659         List<org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.topology.Node> tapiNodes
660             = tapiFactory.getTapiNodes().values().stream().collect(Collectors.toList());
661         Uuid otsiNodeUuid = new Uuid(UUID.nameUUIDFromBytes("ROADM-infra".getBytes(Charset.forName("UTF-8")))
662             .toString());
663         checkOtsiNode(tapiNodes.get(0), otsiNodeUuid, "infra", "ROADM-infra");
664     }
665
666     @Test
667     void convertRoadmInfrastructureWhenOtnMuxAttached() {
668         ConvertORTopoToTapiTopo tapiFactory = new ConvertORTopoToTapiTopo(topologyUuid, tapiLink);
669         List<String> networkPortListA = new ArrayList<>();
670         for (TerminationPoint tp : otnMuxA.augmentation(Node1.class).getTerminationPoint().values()) {
671             if (tp.augmentation(TerminationPoint1.class).getTpType().equals(OpenroadmTpType.XPONDERNETWORK)) {
672                 networkPortListA.add(tp.getTpId().getValue());
673             }
674         }
675         tapiFactory.convertNode(otnMuxA, networkPortListA);
676         tapiFactory.convertRoadmInfrastructure();
677
678         assertEquals(3, tapiFactory.getTapiNodes().size(), "Node list size should be 3");
679         assertEquals(2, tapiFactory.getTapiLinks().size(), "Link list size should be 2");
680         List<org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.topology.Node> tapiNodes
681             = tapiFactory.getTapiNodes().values().stream()
682             .sorted((n1, n2) -> n1.getUuid().getValue().compareTo(n2.getUuid().getValue()))
683             .collect(Collectors.toList());
684         Uuid otsiNodeUuid = new Uuid(UUID.nameUUIDFromBytes("ROADM-infra".getBytes(Charset.forName("UTF-8")))
685             .toString());
686         checkOtsiNode(tapiNodes.get(2), otsiNodeUuid, "infra", "ROADM-infra");
687
688         List<Link> links = tapiFactory.getTapiLinks().values().stream()
689             .sorted((l1, l2) -> l1.getUuid().getValue().compareTo(l2.getUuid().getValue()))
690             .collect(Collectors.toList());
691         Uuid node1Uuid = new Uuid(UUID.nameUUIDFromBytes("SPDR-SA1-XPDR1+OTSi".getBytes(Charset.forName("UTF-8")))
692             .toString());
693         Uuid node2Uuid = new Uuid(UUID.nameUUIDFromBytes("ROADM-infra".getBytes(Charset.forName("UTF-8")))
694             .toString());
695         Uuid tp1Uuid = new Uuid(UUID.nameUUIDFromBytes("SPDR-SA1-XPDR1+eOTSi+XPDR1-NETWORK1"
696             .getBytes(Charset.forName("UTF-8"))).toString());
697         Uuid tp2Uuid = new Uuid(UUID.nameUUIDFromBytes(("roadm node+nep+1")
698             .getBytes(Charset.forName("UTF-8"))).toString());
699         Uuid linkUuid =
700             new Uuid(UUID.nameUUIDFromBytes(
701                 "SPDR-SA1-XPDR1+OTSi--SPDR-SA1-XPDR1+eOTSi+XPDR1-NETWORK1 and ROADM-infra--NodeEdgePoint_1"
702                     .getBytes(Charset.forName("UTF-8"))).toString());
703         checkOmsLink(links.get(1), node1Uuid, node2Uuid, tp1Uuid, tp2Uuid, linkUuid,
704             "SPDR-SA1-XPDR1+OTSi--SPDR-SA1-XPDR1+eOTSi+XPDR1-NETWORK1 and ROADM-infra--NodeEdgePoint_1");
705     }
706
707     private void checkDsrNode(org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.topology.Node node,
708                               Uuid nodeUuid, String dsrNodeType, String nodeId) {
709         assertEquals(nodeUuid, node.getUuid(), "incorrect node uuid");
710         assertEquals(nodeId, node.getName().get(new NameKey("dsr/odu node name")).getValue(), "incorrect node name");
711         assertEquals(AdministrativeState.UNLOCKED, node.getAdministrativeState(),
712             "administrative state should be UNLOCKED");
713         assertEquals(LifecycleState.INSTALLED, node.getLifecycleState(), "life-cycle state should be INSTALLED");
714         assertEquals(OperationalState.ENABLED, node.getOperationalState(), "operational state should be ENABLED");
715         assertThat("one value-name should be 'dsr/odu node name'",
716             new ArrayList<>(node.nonnullName().keySet()), hasItem(new NameKey("dsr/odu node name")));
717         assertEquals(2, node.getLayerProtocolName().size(),
718             "dsr node should manage 2 protocol layers : dsr and odu");
719         assertThat("dsr node should manage 2 protocol layers : dsr and odu",
720             node.getLayerProtocolName(), hasItems(LayerProtocolName.DSR, LayerProtocolName.ODU));
721         List<OwnedNodeEdgePoint> nepsN = node.nonnullOwnedNodeEdgePoint().values().stream()
722             .filter(n -> n.getName().containsKey(new NameKey("iNodeEdgePoint_N")))
723             .sorted((nep1, nep2) -> nep1.getUuid().getValue().compareTo(nep2.getUuid().getValue()))
724             .collect(Collectors.toList());
725         List<OwnedNodeEdgePoint> nepsC;
726         switch (dsrNodeType) {
727             case "switch":
728                 nepsC = node.nonnullOwnedNodeEdgePoint().values().stream()
729                     .filter(n -> n.getName().containsKey(new NameKey("NodeEdgePoint_C")))
730                     .sorted((nep1, nep2) -> nep1.getUuid().getValue().compareTo(nep2.getUuid().getValue()))
731                     .collect(Collectors.toList());
732                 assertEquals(4, nepsN.size(), "Switch-DSR node should have 4 NEPs network");
733                 assertEquals(4, nepsC.size(), "Switch-DSR node should have 4 NEPs client");
734                 OwnedNodeEdgePoint nep1 = nepsC.get(2);
735                 Uuid client4NepUuid = new Uuid(
736                     UUID.nameUUIDFromBytes((nodeId.split("\\+")[0] + "+DSR+XPDR2-CLIENT4")
737                         .getBytes(Charset.forName("UTF-8"))).toString());
738                 checkNepClient100GSwitch(nep1, client4NepUuid, "XPDR2-CLIENT4", "NodeEdgePoint_C",
739                     otnSwitch.getNodeId().getValue(), TapiStringConstants.DSR);
740                 OwnedNodeEdgePoint nep2 = nepsN.get(3);
741                 Uuid networkNepUuid = new Uuid(
742                     UUID.nameUUIDFromBytes((nodeId.split("\\+")[0] + "+iODU+XPDR2-NETWORK1")
743                         .getBytes(Charset.forName("UTF-8"))).toString());
744                 checkNepNetworkODU4(nep2, networkNepUuid, "XPDR2-NETWORK1", "iNodeEdgePoint_N",
745                     otnSwitch.getNodeId().getValue(), TapiStringConstants.I_ODU);
746                 List<NodeRuleGroup> nrgList = node.nonnullNodeRuleGroup().values().stream()
747                     .sorted((nrg1, nrg2) -> nrg1.getUuid().getValue().compareTo(nrg2.getUuid().getValue()))
748                     .collect(Collectors.toList());
749                 checkNodeRuleGroupForSwitchDSR(nrgList, client4NepUuid, networkNepUuid, nodeUuid);
750                 break;
751             case "mux":
752                 nepsC = node.nonnullOwnedNodeEdgePoint().values().stream()
753                     .filter(n -> n.getName().containsKey(new NameKey("NodeEdgePoint_C")))
754                     .sorted((nep3, nep4) -> nep3.getUuid().getValue().compareTo(nep4.getUuid().getValue()))
755                     .collect(Collectors.toList());
756                 assertEquals(1, nepsN.size(), "Mux-DSR node should have 1 NEP network");
757                 assertEquals(4, nepsC.size(), "Mux-DSR node should have 4 NEPs client");
758                 OwnedNodeEdgePoint nep3 = nepsC.get(2);
759                 Uuid client3NepUuid = new Uuid(
760                     UUID.nameUUIDFromBytes((nodeId.split("\\+")[0] + "+DSR+XPDR1-CLIENT3")
761                         .getBytes(Charset.forName("UTF-8"))).toString());
762                 checkNepClient10G(nep3, client3NepUuid, "XPDR1-CLIENT3", "NodeEdgePoint_C",
763                     otnMuxA.getNodeId().getValue(), TapiStringConstants.DSR);
764
765                 OwnedNodeEdgePoint nep4 = nepsN.get(0);
766                 Uuid networkNepUuid2 = new Uuid(
767                     UUID.nameUUIDFromBytes((nodeId.split("\\+")[0] + "+iODU+XPDR1-NETWORK1")
768                         .getBytes(Charset.forName("UTF-8"))).toString());
769                 checkNepNetworkODU4(nep4, networkNepUuid2, "XPDR1-NETWORK1", "iNodeEdgePoint_N",
770                     otnMuxA.getNodeId().getValue(), TapiStringConstants.I_ODU);
771                 List<NodeRuleGroup> nrgList2 = node.nonnullNodeRuleGroup().values().stream()
772                     .sorted((nrg1, nrg2) -> nrg1.getUuid().getValue().compareTo(nrg2.getUuid().getValue()))
773                     .collect(Collectors.toList());
774                 checkNodeRuleGroupForMuxDSR(nrgList2, client3NepUuid, networkNepUuid2, nodeUuid);
775                 break;
776             case "tpdr":
777                 nepsC = node.nonnullOwnedNodeEdgePoint().values().stream()
778                     .filter(n -> n.getName().containsKey(new NameKey("100G-tpdr")))
779                     .sorted((nep5, nep6) -> nep5.getUuid().getValue().compareTo(nep6.getUuid().getValue()))
780                     .collect(Collectors.toList());
781                 assertEquals(2, nepsN.size(), "Tpdr-DSR node should have 2 NEPs network");
782                 assertEquals(2, nepsC.size(), "Tpdr-DSR node should have 2 NEPs client");
783                 OwnedNodeEdgePoint nep5 = nepsC.get(0);
784                 Uuid client1NepUuid = new Uuid(
785                     UUID.nameUUIDFromBytes((nodeId.split("\\+")[0] + "+DSR+XPDR1-CLIENT1")
786                         .getBytes(Charset.forName("UTF-8"))).toString());
787                 checkNepClient100GTpdr(nep5, client1NepUuid, "XPDR1-CLIENT1", "100G-tpdr",
788                     tpdr100G.getNodeId().getValue(), TapiStringConstants.DSR);
789
790                 OwnedNodeEdgePoint nep6 = nepsN.get(1);
791                 Uuid networkNepUuid3 = new Uuid(
792                     UUID.nameUUIDFromBytes((nodeId.split("\\+")[0] + "+iODU+XPDR1-NETWORK1")
793                         .getBytes(Charset.forName("UTF-8"))).toString());
794                 checkNepNetworkODU4(nep6, networkNepUuid3, "XPDR1-NETWORK1", "iNodeEdgePoint_N",
795                     tpdr100G.getNodeId().getValue(), TapiStringConstants.I_ODU);
796                 List<NodeRuleGroup> nrgList3 = node.nonnullNodeRuleGroup().values().stream()
797                     .sorted((nrg1, nrg2) -> nrg1.getUuid().getValue().compareTo(nrg2.getUuid().getValue()))
798                     .collect(Collectors.toList());
799                 checkNodeRuleGroupForTpdrDSR(nrgList3, client1NepUuid, networkNepUuid3, nodeUuid);
800                 break;
801             default:
802                 fail();
803                 break;
804         }
805     }
806
807     private void checkOtsiNode(
808         org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.topology.Node node,
809         Uuid nodeUuid, String otsiNodeType, String nodeId) {
810         assertEquals(nodeUuid, node.getUuid(), "incorrect node uuid");
811         assertEquals(nodeId, node.getName().get(new NameKey("otsi node name")).getValue(), "incorrect node name");
812         assertEquals(AdministrativeState.UNLOCKED, node.getAdministrativeState(),
813             "administrative state should be UNLOCKED");
814         assertEquals(LifecycleState.INSTALLED, node.getLifecycleState(), "life-cycle state should be INSTALLED");
815         assertEquals(OperationalState.ENABLED, node.getOperationalState(), "operational state should be ENABLED");
816         assertThat("one value-name should be 'dsr/odu node name'",
817             new ArrayList<>(node.nonnullName().keySet()), hasItem(new NameKey("otsi node name")));
818         assertEquals(1, node.getLayerProtocolName().size(),
819             "otsi node should manage a single protocol layer : PHOTONIC_MEDIA");
820         assertEquals(LayerProtocolName.PHOTONICMEDIA, node.getLayerProtocolName().stream().findFirst().orElseThrow(),
821             "otsi node should manage a single protocol layer : PHOTONIC_MEDIA");
822         List<OwnedNodeEdgePoint> nepsI = node.nonnullOwnedNodeEdgePoint().values().stream()
823             .filter(n -> n.getName().containsKey(new NameKey("iNodeEdgePoint")))
824             .sorted((nep1, nep2) -> nep1.getUuid().getValue().compareTo(nep2.getUuid().getValue()))
825             .collect(Collectors.toList());
826         List<OwnedNodeEdgePoint> nepsE = node.nonnullOwnedNodeEdgePoint().values().stream()
827             .filter(n -> n.getName().containsKey(new NameKey("eNodeEdgePoint")))
828             .sorted((nep1, nep2) -> nep1.getUuid().getValue().compareTo(nep2.getUuid().getValue()))
829             .collect(Collectors.toList());
830         switch (otsiNodeType) {
831             case "switch":
832                 assertEquals(4, nepsE.size(), "Switch-OTSi node should have 4 eNEPs");
833                 assertEquals(4, nepsI.size(), "Switch-OTSi node should have 4 iNEPs");
834                 OwnedNodeEdgePoint nep1 = nepsI.get(1);
835                 Uuid inepUuid = new Uuid(
836                     UUID.nameUUIDFromBytes((nodeId.split("\\+")[0] + "+iOTSi+XPDR2-NETWORK2")
837                         .getBytes(Charset.forName("UTF-8"))).toString());
838                 checkNepOtsiNode(nep1, inepUuid, "XPDR2-NETWORK2", "iNodeEdgePoint",
839                     otnSwitch.getNodeId().getValue(), TapiStringConstants.I_OTSI);
840                 OwnedNodeEdgePoint nep2 = nepsE.get(0);
841                 Uuid enepUuid = new Uuid(
842                     UUID.nameUUIDFromBytes((nodeId.split("\\+")[0] + "+eOTSi+XPDR2-NETWORK2")
843                         .getBytes(Charset.forName("UTF-8"))).toString());
844                 checkNepOtsiNode(nep2, enepUuid, "XPDR2-NETWORK2", "eNodeEdgePoint",
845                     otnSwitch.getNodeId().getValue(), TapiStringConstants.E_OTSI);
846                 List<NodeRuleGroup> nrgList = node.nonnullNodeRuleGroup().values().stream()
847                     .sorted((nrg1, nrg2) -> nrg1.getUuid().getValue().compareTo(nrg2.getUuid().getValue()))
848                     .collect(Collectors.toList());
849                 checkNodeRuleGroupForSwitchOTSi(nrgList, enepUuid, inepUuid, nodeUuid);
850                 break;
851             case "mux":
852                 assertEquals(1, nepsE.size(), "Mux-OTSi node should have 1 eNEP");
853                 assertEquals(1, nepsI.size(), "Mux-OTSi node should have 1 iNEPs");
854                 OwnedNodeEdgePoint nep3 = nepsE.get(0);
855                 Uuid enepUuid2 = new Uuid(
856                     UUID.nameUUIDFromBytes((nodeId.split("\\+")[0] + "+eOTSi+XPDR1-NETWORK1")
857                         .getBytes(Charset.forName("UTF-8"))).toString());
858                 checkNepOtsiNode(nep3, enepUuid2, "XPDR1-NETWORK1", "eNodeEdgePoint",
859                     otnMuxA.getNodeId().getValue(), TapiStringConstants.E_OTSI);
860                 OwnedNodeEdgePoint nep4 = nepsI.get(0);
861                 Uuid inepUuid2 = new Uuid(
862                     UUID.nameUUIDFromBytes((nodeId.split("\\+")[0] + "+iOTSi+XPDR1-NETWORK1")
863                         .getBytes(Charset.forName("UTF-8"))).toString());
864                 checkNepOtsiNode(nep4, inepUuid2, "XPDR1-NETWORK1", "iNodeEdgePoint",
865                     otnMuxA.getNodeId().getValue(), TapiStringConstants.I_OTSI);
866                 List<NodeRuleGroup> nrgList2 = node.nonnullNodeRuleGroup().values().stream()
867                     .sorted((nrg1, nrg2) -> nrg1.getUuid().getValue().compareTo(nrg2.getUuid().getValue()))
868                     .collect(Collectors.toList());
869                 checkNodeRuleGroupForMuxOTSi(nrgList2, enepUuid2, inepUuid2, nodeUuid);
870                 break;
871             case "tpdr":
872                 assertEquals(2, nepsE.size(), "Tpdr-OTSi node should have 2 eNEPs");
873                 assertEquals(2, nepsI.size(), "Tpdr-OTSi node should have 2 iNEPs");
874                 OwnedNodeEdgePoint nep5 = nepsE.get(0);
875                 Uuid enepUuid3 = new Uuid(
876                     UUID.nameUUIDFromBytes((nodeId.split("\\+")[0] + "+eOTSi+XPDR1-NETWORK1")
877                         .getBytes(Charset.forName("UTF-8"))).toString());
878                 checkNepOtsiNode(nep5, enepUuid3, "XPDR1-NETWORK1", "eNodeEdgePoint",
879                     tpdr100G.getNodeId().getValue(), TapiStringConstants.E_OTSI);
880                 OwnedNodeEdgePoint nep6 = nepsI.get(0);
881                 Uuid inepUuid3 = new Uuid(
882                     UUID.nameUUIDFromBytes((nodeId.split("\\+")[0] + "+iOTSi+XPDR1-NETWORK1")
883                         .getBytes(Charset.forName("UTF-8"))).toString());
884                 checkNepOtsiNode(nep6, inepUuid3, "XPDR1-NETWORK1", "iNodeEdgePoint",
885                     tpdr100G.getNodeId().getValue(), TapiStringConstants.I_OTSI);
886                 List<NodeRuleGroup> nrgList3 = node.nonnullNodeRuleGroup().values().stream()
887                     .sorted((nrg1, nrg2) -> nrg1.getUuid().getValue().compareTo(nrg2.getUuid().getValue()))
888                     .collect(Collectors.toList());
889                 checkNodeRuleGroupForTpdrOTSi(nrgList3, enepUuid3, inepUuid3, nodeUuid);
890                 break;
891             default:
892                 Iterator<OwnedNodeEdgePoint> nepIterator = node.nonnullOwnedNodeEdgePoint().values().iterator();
893                 int count = 1;
894                 while (nepIterator.hasNext()) {
895                     OwnedNodeEdgePoint nep = nepIterator.next();
896                     Uuid nepUuid = new Uuid(
897                         UUID.nameUUIDFromBytes((String.join("+", "roadm node", "nep", String.valueOf(count)))
898                             .getBytes(Charset.forName("UTF-8"))).toString());
899                     checkNepOtsiRdmNode(nep, nepUuid, new StringBuilder("NodeEdgePoint_").append(count).toString(),
900                         "NodeEdgePoint name");
901                     count++;
902                 }
903                 List<NodeRuleGroup> nrgList4 = node.nonnullNodeRuleGroup().values().stream()
904                     .sorted((nrg1, nrg2) -> nrg1.getUuid().getValue().compareTo(nrg2.getUuid().getValue()))
905                     .collect(Collectors.toList());
906                 checkNodeRuleGroupForRdmInfra(nrgList4, count - 1);
907                 break;
908         }
909     }
910
911     private void checkNepClient10G(OwnedNodeEdgePoint nep, Uuid nepUuid, String portName, String nepName,
912                                    String nodeId, String extension) {
913         assertEquals(nepUuid, nep.getUuid(), "bad uuid for " + portName);
914         List<Name> nameList = new ArrayList<>(nep.nonnullName().values());
915         Name name = nameList.get(0);
916         assertEquals(String.join("+", nodeId, extension, portName), name.getValue(),
917             "value of client nep should be '" + portName + "'");
918         assertEquals(nepName, name.getValueName(),
919             "value-name of client nep for '" + portName + "' should be '" + nepName + "'");
920         List<LAYERPROTOCOLQUALIFIER> lpql = new ArrayList<>();
921         List<SupportedCepLayerProtocolQualifierInstances> lsclpqi = nep
922                 .getSupportedCepLayerProtocolQualifierInstances();
923         for (SupportedCepLayerProtocolQualifierInstances entry : lsclpqi) {
924             lpql.add(entry.getLayerProtocolQualifier());
925         }
926         assertEquals(3, lpql.size(), "Client nep should support 3 kind of cep");
927         assertThat("client nep should support 3 kind of cep", lpql,
928             hasItems(ODUTYPEODU2.VALUE, ODUTYPEODU2E.VALUE, DIGITALSIGNALTYPE10GigELAN.VALUE));
929         assertEquals(LayerProtocolName.ETH, nep.getLayerProtocolName(), "client nep should be of ETH protocol type");
930         checkCommonPartOfNep(nep, false);
931         checkSIP(nep, portName, nodeId, extension);
932     }
933
934     private void checkNepNetworkODU4(OwnedNodeEdgePoint nep, Uuid nepUuid, String portName, String nepName,
935                                      String nodeId, String extension) {
936         assertEquals(nepUuid, nep.getUuid(), "bad uuid for " + portName);
937         List<Name> nameList = new ArrayList<>(nep.nonnullName().values());
938         Name name = nameList.get(0);
939         assertEquals(String.join("+", nodeId, extension, portName), name.getValue(),
940             "value of network nep should be '" + portName + "'");
941         assertEquals(nepName, name.getValueName(),
942             "value-name of network nep for '" + portName + "' should be '" + nepName + "'");
943         List<LAYERPROTOCOLQUALIFIER> lpql = new ArrayList<>();
944         List<SupportedCepLayerProtocolQualifierInstances> lsclpqi = nep
945                 .getSupportedCepLayerProtocolQualifierInstances();
946         for (SupportedCepLayerProtocolQualifierInstances entry : lsclpqi) {
947             lpql.add(entry.getLayerProtocolQualifier());
948         }
949         assertEquals(1, lpql.size(), "Network nep should support 1 kind of cep");
950         assertThat("network nep should support 1 kind of cep", lpql, hasItem(ODUTYPEODU4.VALUE));
951         assertEquals(LayerProtocolName.ODU, nep.getLayerProtocolName(), "network nep should be of ODU protocol type");
952         checkCommonPartOfNep(nep, false);
953         checkSIP(nep, portName, nodeId, extension);
954     }
955
956     private void checkNodeRuleGroupForTpdrDSR(List<NodeRuleGroup> nrgList, Uuid clientNepUuid, Uuid networkNepUuid,
957                                               Uuid nodeUuid) {
958         assertEquals(2, nrgList.size(), "transponder DSR should contain 2 node rule group");
959         for (NodeRuleGroup nodeRuleGroup : nrgList) {
960             assertEquals(2, nodeRuleGroup.getNodeEdgePoint().size(),
961                 "each node-rule-group should contain 2 NEP for transponder DSR");
962         }
963         List<NodeEdgePoint> nodeEdgePointList = new ArrayList<>(nrgList.get(0).nonnullNodeEdgePoint().values());
964         assertThat("node-rule-group nb 1 should be between nep-client1 and nep-network1",
965             nodeEdgePointList.get(0).getNodeEdgePointUuid().getValue(),
966             either(containsString(networkNepUuid.getValue())).or(containsString(clientNepUuid.getValue())));
967         assertThat("node-rule-group nb 1 should be between nep-client1 and nep-network1",
968             nodeEdgePointList.get(1).getNodeEdgePointUuid().getValue(),
969             either(containsString(networkNepUuid.getValue())).or(containsString(clientNepUuid.getValue())));
970         assertEquals(nodeEdgePointList.get(0).getNodeUuid(), nodeUuid,
971             "node-rule-group nb 1 should be between nep-client1 and nep-network1 of the same node");
972         assertEquals(nodeEdgePointList.get(1).getNodeUuid(), nodeUuid,
973             "node-rule-group nb 1 should be between nep-client1 and nep-network1 of the same node");
974         List<Rule> rule = new ArrayList<>(nrgList.get(1).nonnullRule().values());
975         assertEquals(1, rule.size(), "node-rule-group nb 1 should contain a single rule");
976         assertEquals("forward", rule.get(0).getLocalId(), "local-id of the rule should be 'forward'");
977         assertEquals(FORWARDINGRULEMAYFORWARDACROSSGROUP.VALUE, rule.get(0).getForwardingRule(),
978             "the forwarding rule should be 'MAYFORWARDACROSSGROUP'");
979         assertEquals(RuleType.FORWARDING, rule.get(0).getRuleType(), "the rule type should be 'FORWARDING'");
980     }
981
982     private void checkNodeRuleGroupForMuxDSR(List<NodeRuleGroup> nrgList, Uuid clientNepUuid, Uuid networkNepUuid,
983                                              Uuid nodeUuid) {
984         assertEquals(4, nrgList.size(), "muxponder DSR should contain 4 node rule group");
985         for (NodeRuleGroup nodeRuleGroup : nrgList) {
986             assertEquals(2, nodeRuleGroup.getNodeEdgePoint().size(),
987                 "each node-rule-group should contain 2 NEP for muxponder DSR");
988         }
989         List<NodeEdgePoint> nodeEdgePointList = new ArrayList<>(nrgList.get(0).nonnullNodeEdgePoint().values());
990         assertThat("node-rule-group nb 2 should be between nep-client4 and nep-network1",
991             nodeEdgePointList.get(1).getNodeEdgePointUuid().getValue(),
992             either(containsString(networkNepUuid.getValue())).or(containsString(clientNepUuid.getValue())));
993         assertThat("node-rule-group nb 2 should be between nep-client4 and nep-network1",
994             nodeEdgePointList.get(1).getNodeEdgePointUuid().getValue(),
995             either(containsString(networkNepUuid.getValue())).or(containsString(clientNepUuid.getValue())));
996         assertEquals(nodeEdgePointList.get(0).getNodeUuid(), nodeUuid,
997             "node-rule-group nb 2 should be between nep-client4 and nep-network1 of the same node");
998         assertEquals(nodeEdgePointList.get(1).getNodeUuid(), nodeUuid,
999             "node-rule-group nb 2 should be between nep-client4 and nep-network1 of the same node");
1000         List<Rule> rule = new ArrayList<>(nrgList.get(1).nonnullRule().values());
1001         assertEquals(1, rule.size(), "node-rule-group nb 2 should contain a single rule");
1002         assertEquals("forward", rule.get(0).getLocalId(), "local-id of the rule should be 'forward'");
1003         assertEquals(FORWARDINGRULEMAYFORWARDACROSSGROUP.VALUE, rule.get(0).getForwardingRule(),
1004             "the forwarding rule should be 'MAYFORWARDACROSSGROUP'");
1005         assertEquals(RuleType.FORWARDING, rule.get(0).getRuleType(), "the rule type should be 'FORWARDING'");
1006     }
1007
1008     private void checkNodeRuleGroupForSwitchDSR(List<NodeRuleGroup> nrgList, Uuid clientNepUuid, Uuid networkNepUuid,
1009                                                 Uuid nodeUuid) {
1010         assertEquals(1, nrgList.size(), "Switch-DSR should contain a single node rule group");
1011         assertEquals(8, nrgList.get(0).getNodeEdgePoint().size(), "Switch-DSR node-rule-group should contain 8 NEP");
1012         List<NodeEdgePoint> nrg = nrgList.get(0).nonnullNodeEdgePoint().values().stream()
1013             .sorted((nrg1, nrg2) -> nrg1.getNodeEdgePointUuid().getValue()
1014                 .compareTo(nrg2.getNodeEdgePointUuid().getValue()))
1015             .collect(Collectors.toList());
1016         assertEquals(networkNepUuid, nrg.get(6).getNodeEdgePointUuid(),
1017             "in the sorted node-rule-group, nep number 7 should be XPDR2-NETWORK1");
1018         assertEquals(clientNepUuid, nrg.get(5).getNodeEdgePointUuid(),
1019             "in the sorted node-rule-group, nep number 6 should be XPDR2-CLIENT4");
1020         assertEquals(nodeUuid, nrg.get(4).getNodeUuid(),
1021             "any item of the node-rule-group should have the same nodeUuid");
1022         assertEquals(nodeUuid, nrg.get(3).getNodeUuid(),
1023             "any item of the node-rule-group should have the same nodeUuid");
1024         @Nullable
1025         List<Rule> ruleList = new ArrayList<>(nrgList.get(0).nonnullRule().values());
1026         assertEquals(1, ruleList.size(), "node-rule-group should contain a single rule");
1027         assertEquals("forward", ruleList.get(0).getLocalId(), "local-id of the rule should be 'forward'");
1028         assertEquals(FORWARDINGRULEMAYFORWARDACROSSGROUP.VALUE, ruleList.get(0).getForwardingRule(),
1029             "the forwarding rule should be 'MAYFORWARDACROSSGROUP'");
1030         assertEquals(RuleType.FORWARDING, ruleList.get(0).getRuleType(), "the rule type should be 'FORWARDING'");
1031     }
1032
1033     private void checkNodeRuleGroupForRdmInfra(List<NodeRuleGroup> nrgList, int nbNeps) {
1034         assertEquals(1, nrgList.size(), "RDM infra node - OTSi should contain a single node rule groups");
1035         if (nbNeps > 0) {
1036             List<NodeEdgePoint> nodeEdgePointList = new ArrayList<>(nrgList.get(0).getNodeEdgePoint().values());
1037             assertEquals(nbNeps, nodeEdgePointList.size(),
1038                 "RDM infra node -rule-group should contain " + nbNeps + " NEP");
1039         } else {
1040             assertNull(nrgList.get(0).getNodeEdgePoint(), "RDM infra node -rule-group should contain no NEP");
1041         }
1042         List<Rule> ruleList = new ArrayList<>(nrgList.get(0).nonnullRule().values());
1043         assertEquals(1, ruleList.size(), "node-rule-group should contain a single rule");
1044         assertEquals("forward", ruleList.get(0).getLocalId(), "local-id of the rule should be 'forward'");
1045         assertEquals(FORWARDINGRULEMAYFORWARDACROSSGROUP.VALUE, ruleList.get(0).getForwardingRule(),
1046             "the forwarding rule should be 'MAYFORWARDACROSSGROUP'");
1047         assertEquals(RuleType.FORWARDING, ruleList.get(0).getRuleType(), "the rule type should be 'FORWARDING'");
1048     }
1049
1050     private void checkNodeRuleGroupForTpdrOTSi(List<NodeRuleGroup> nrgList, Uuid enepUuid, Uuid inepUuid,
1051                                                Uuid nodeUuid) {
1052         assertEquals(2, nrgList.size(), "Tpdr-OTSi should contain two node rule groups");
1053         List<NodeEdgePoint> nodeEdgePointList = new ArrayList<>(nrgList.get(0).getNodeEdgePoint().values());
1054         assertEquals(2, nodeEdgePointList.size(), "Tpdr-OTSi node-rule-group should contain 2 NEP");
1055         assertThat("Tpdr-OTSi node-rule-group should be between eNEP and iNEP of XPDR1-NETWORK1",
1056             nodeEdgePointList.get(0).getNodeEdgePointUuid().getValue(),
1057             either(containsString(enepUuid.getValue())).or(containsString(inepUuid.getValue())));
1058         assertThat("Tpdr-OTSi node-rule-group should be between eNEP and iNEP of XPDR1-NETWORK1",
1059             nodeEdgePointList.get(1).getNodeEdgePointUuid().getValue(),
1060             either(containsString(enepUuid.getValue())).or(containsString(inepUuid.getValue())));
1061         assertEquals(nodeUuid, nodeEdgePointList.get(0).getNodeUuid(),
1062             "any item of the node-rule-group should have the same nodeUuid");
1063         assertEquals(nodeUuid, nodeEdgePointList.get(1).getNodeUuid(),
1064             "any item of the node-rule-group should have the same nodeUuid");
1065         List<Rule> ruleList = new ArrayList<>(nrgList.get(0).nonnullRule().values());
1066         assertEquals(1, ruleList.size(), "node-rule-group should contain a single rule");
1067         assertEquals("forward", ruleList.get(0).getLocalId(), "local-id of the rule should be 'forward'");
1068         assertEquals(FORWARDINGRULEMAYFORWARDACROSSGROUP.VALUE, ruleList.get(0).getForwardingRule(),
1069             "the forwarding rule should be 'MAYFORWARDACROSSGROUP'");
1070         assertEquals(RuleType.FORWARDING, ruleList.get(0).getRuleType(), "the rule type should be 'FORWARDING'");
1071     }
1072
1073     private void checkNodeRuleGroupForMuxOTSi(List<NodeRuleGroup> nrgList, Uuid enepUuid, Uuid inepUuid,
1074                                               Uuid nodeUuid) {
1075         assertEquals(1, nrgList.size(), "Mux-OTSi should contain a single node rule group");
1076         List<NodeEdgePoint> nodeEdgePointList = new ArrayList<>(nrgList.get(0).getNodeEdgePoint().values());
1077         assertEquals(2, nodeEdgePointList.size(), "Mux-OTSi node-rule-group should contain 2 NEP");
1078         assertThat("Mux-OTSi node-rule-group should be between eNEP and iNEP of XPDR1-NETWORK1",
1079             nodeEdgePointList.get(0).getNodeEdgePointUuid().getValue(),
1080             either(containsString(enepUuid.getValue())).or(containsString(inepUuid.getValue())));
1081         assertThat("Mux-OTSi node-rule-group should be between eNEP and iNEP of XPDR1-NETWORK1",
1082             nodeEdgePointList.get(1).getNodeEdgePointUuid().getValue(),
1083             either(containsString(enepUuid.getValue())).or(containsString(inepUuid.getValue())));
1084         assertEquals(nodeUuid, nodeEdgePointList.get(0).getNodeUuid(),
1085             "any item of the node-rule-group should have the same nodeUuid");
1086         assertEquals(nodeUuid, nodeEdgePointList.get(1).getNodeUuid(),
1087             "any item of the node-rule-group should have the same nodeUuid");
1088         List<Rule> ruleList = new ArrayList<>(nrgList.get(0).nonnullRule().values());
1089         assertEquals(1, ruleList.size(), "node-rule-group should contain a single rule");
1090         assertEquals("forward", ruleList.get(0).getLocalId(), "local-id of the rule should be 'forward'");
1091         assertEquals(FORWARDINGRULEMAYFORWARDACROSSGROUP.VALUE, ruleList.get(0).getForwardingRule(),
1092             "the forwarding rule should be 'MAYFORWARDACROSSGROUP'");
1093         assertEquals(RuleType.FORWARDING, ruleList.get(0).getRuleType(), "the rule type should be 'FORWARDING'");
1094     }
1095
1096     private void checkNodeRuleGroupForSwitchOTSi(List<NodeRuleGroup> nrgList, Uuid enepUuid, Uuid inepUuid,
1097                                                  Uuid nodeUuid) {
1098         assertEquals(4, nrgList.size(), "Switch-OTSi should contain 4 node rule group");
1099         for (NodeRuleGroup nodeRuleGroup : nrgList) {
1100             assertEquals(2, nodeRuleGroup.getNodeEdgePoint().size(),
1101                 "each node-rule-group should contain 2 NEP for Switch-OTSi");
1102         }
1103         List<NodeEdgePoint> nodeEdgePointList1 = new ArrayList<>(nrgList.get(3).nonnullNodeEdgePoint().values());
1104         assertThat("Switch-OTSi node-rule-group nb 4 should be between eNEP and iNEP of XPDR2-NETWORK2",
1105             nodeEdgePointList1.get(0).getNodeEdgePointUuid().getValue(),
1106             either(containsString(enepUuid.getValue())).or(containsString(inepUuid.getValue())));
1107         assertThat("Switch-OTSi node-rule-group nb 4 should be between eNEP and iNEP of XPDR2-NETWORK2",
1108             nodeEdgePointList1.get(1).getNodeEdgePointUuid().getValue(),
1109             either(containsString(enepUuid.getValue())).or(containsString(inepUuid.getValue())));
1110         List<NodeEdgePoint> nodeEdgePointList0 = new ArrayList<>(nrgList.get(0).getNodeEdgePoint().values());
1111         assertEquals(nodeUuid, nodeEdgePointList0.get(0).getNodeUuid(),
1112             "any item of the node-rule-group should have the same nodeUuid");
1113         assertEquals(nodeUuid, nodeEdgePointList0.get(1).getNodeUuid(),
1114             "any item of the node-rule-group should have the same nodeUuid");
1115         List<Rule> ruleList0 = new ArrayList<>(nrgList.get(0).nonnullRule().values());
1116         assertEquals(1, ruleList0.size(), "node-rule-group should contain a single rule");
1117         assertEquals("forward", ruleList0.get(0).getLocalId(),"local-id of the rule should be 'forward'");
1118         assertEquals(FORWARDINGRULEMAYFORWARDACROSSGROUP.VALUE, ruleList0.get(0).getForwardingRule(),
1119             "the forwarding rule should be 'MAYFORWARDACROSSGROUP'");
1120         assertEquals(RuleType.FORWARDING, ruleList0.get(0).getRuleType(), "the rule type should be 'FORWARDING'");
1121     }
1122
1123     private void checkNepClient100GSwitch(OwnedNodeEdgePoint nep, Uuid nepUuid, String portName, String nepName,
1124                                           String nodeId, String extension) {
1125         assertEquals(nepUuid, nep.getUuid(), "bad uuid for " + portName);
1126         List<Name> nameList = new ArrayList<>(nep.nonnullName().values());
1127         assertEquals(String.join("+", nodeId, extension, portName), nameList.get(0).getValue(),
1128             "value of client nep should be '" + portName + "'");
1129         assertEquals(nepName, nameList.get(0).getValueName(),
1130             "value-name of client nep for '" + portName + "' should be '" + nepName + "'");
1131         List<LAYERPROTOCOLQUALIFIER> lpql = new ArrayList<>();
1132         List<SupportedCepLayerProtocolQualifierInstances> lsclpqi = nep
1133                 .getSupportedCepLayerProtocolQualifierInstances();
1134         for (SupportedCepLayerProtocolQualifierInstances entry : lsclpqi) {
1135             lpql.add(entry.getLayerProtocolQualifier());
1136         }
1137         assertEquals(2, lpql.size(), "Client nep should support 2 kind of cep");
1138         assertThat("client nep should support 2 kind of cep", lpql,
1139             hasItems(ODUTYPEODU4.VALUE, DIGITALSIGNALTYPE100GigE.VALUE));
1140         assertEquals(LayerProtocolName.ETH, nep.getLayerProtocolName(), "client nep should be of ETH protocol type");
1141         checkCommonPartOfNep(nep, false);
1142         checkSIP(nep, portName, nodeId, extension);
1143     }
1144
1145     private void checkNepClient100GTpdr(OwnedNodeEdgePoint nep, Uuid nepUuid, String portName, String nepName,
1146                                         String nodeId, String extension) {
1147         assertEquals(nepUuid, nep.getUuid(), "bad uuid for " + portName);
1148         List<Name> nameList = new ArrayList<>(nep.nonnullName().values());
1149         assertEquals(String.join("+", nodeId, extension, portName), nameList.get(0).getValue(),
1150             "value of client nep should be '" + portName + "'");
1151         assertEquals(nepName, nameList.get(0).getValueName(),
1152             "value-name of client nep for '" + portName + "' should be 100G-tpdr'");
1153         List<LAYERPROTOCOLQUALIFIER> lpql = new ArrayList<>();
1154         List<SupportedCepLayerProtocolQualifierInstances> lsclpqi = nep
1155                 .getSupportedCepLayerProtocolQualifierInstances();
1156         for (SupportedCepLayerProtocolQualifierInstances entry : lsclpqi) {
1157             lpql.add(entry.getLayerProtocolQualifier());
1158         }
1159         assertEquals(1, lpql.size(), "Client nep should support 1 kind of cep");
1160         assertThat("client nep should support 2 kind of cep", lpql, hasItems(DIGITALSIGNALTYPE100GigE.VALUE));
1161         assertEquals(LayerProtocolName.ETH, nep.getLayerProtocolName(), "client nep should be of ETH protocol type");
1162         checkCommonPartOfNep(nep, false);
1163         checkSIP(nep, portName, nodeId, extension);
1164     }
1165
1166     private void checkNepOtsiNode(OwnedNodeEdgePoint nep, Uuid nepUuid, String portName, String nepName,
1167                                   String nodeId, String extension) {
1168         assertEquals(nepUuid, nep.getUuid(), "bad uuid for " + portName);
1169         List<Name> nameList = new ArrayList<>(nep.nonnullName().values());
1170         assertEquals(String.join("+", nodeId, extension, portName), nameList.get(0).getValue(),
1171             "value of OTSi nep should be '" + portName + "'");
1172         assertEquals(nepName, nameList.get(0).getValueName(), "value-name of OTSi nep should be '" + nepName + "'");
1173         List<LAYERPROTOCOLQUALIFIER> lpql = new ArrayList<>();
1174         List<SupportedCepLayerProtocolQualifierInstances> lsclpqi = nep
1175                 .getSupportedCepLayerProtocolQualifierInstances();
1176         for (SupportedCepLayerProtocolQualifierInstances entry : lsclpqi) {
1177             lpql.add(entry.getLayerProtocolQualifier());
1178         }
1179         assertEquals(2, lpql.size(), "OTSi nep should support 2 kind of cep");
1180         assertThat("OTSi nep should support 2 kind of cep", lpql,
1181             hasItems(PHOTONICLAYERQUALIFIEROMS.VALUE, PHOTONICLAYERQUALIFIEROTSi.VALUE));
1182         assertEquals(LayerProtocolName.PHOTONICMEDIA, nep.getLayerProtocolName(),
1183             "OTSi nep should be of PHOTONIC_MEDIA protocol type");
1184         assertEquals(1, nep.getMappedServiceInterfacePoint().size(), "OTSi nep should support one SIP");
1185         checkCommonPartOfNep(nep, false);
1186         checkSIP(nep, portName, nodeId, extension);
1187     }
1188
1189     private void checkSIP(OwnedNodeEdgePoint nep, String portName, String nodeId, String extension) {
1190         Uuid sipUuid = new Uuid(UUID.nameUUIDFromBytes((String.join("+", "SIP", nodeId, extension, portName))
1191             .getBytes(Charset.forName("UTF-8"))).toString());
1192         assertEquals(
1193             sipUuid,
1194             nep.getMappedServiceInterfacePoint().get(new MappedServiceInterfacePointKey(sipUuid))
1195                 .getServiceInterfacePointUuid(),
1196             "service-interface-point-uuid of network nep for '" + portName + "' should be '"
1197                 + String.join("+", "SIP", portName) + "'");
1198     }
1199
1200     private void checkNepOtsiRdmNode(OwnedNodeEdgePoint nep, Uuid nepUuid, String portName, String nepName) {
1201         assertEquals(nepUuid, nep.getUuid(), "bad uuid for " + portName);
1202         List<Name> nameList = new ArrayList<>(nep.nonnullName().values());
1203         assertEquals(portName, nameList.get(0).getValue(), "value of OTSi nep should be '" + portName + "'");
1204         assertEquals(nepName, nameList.get(0).getValueName(), "value-name of OTSi nep should be '" + nepName + "'");
1205         List<LAYERPROTOCOLQUALIFIER> lpql = new ArrayList<>();
1206         List<SupportedCepLayerProtocolQualifierInstances> lsclpqi = nep
1207                 .getSupportedCepLayerProtocolQualifierInstances();
1208         for (SupportedCepLayerProtocolQualifierInstances entry : lsclpqi) {
1209             lpql.add(entry.getLayerProtocolQualifier());
1210         }
1211         assertEquals(1, lpql.size(), "OTSi nep of RDM infra node should support only 1 kind of cep");
1212         assertThat("OTSi nep should support 2 kind of cep", lpql, hasItems(PHOTONICLAYERQUALIFIEROMS.VALUE));
1213         assertEquals(LayerProtocolName.PHOTONICMEDIA, nep.getLayerProtocolName(),
1214             "OTSi nep should be of PHOTONIC_MEDIA protocol type");
1215         assertEquals(0, nep.nonnullMappedServiceInterfacePoint().size(), "OTSi nep of RDM infra should support no SIP");
1216         checkCommonPartOfNep(nep, true);
1217     }
1218
1219     private void checkCommonPartOfNep(OwnedNodeEdgePoint nep, boolean isRdm) {
1220         assertEquals(Direction.BIDIRECTIONAL, nep.getDirection(),
1221             "link port direction should be DIRECTIONAL");
1222         assertEquals(AdministrativeState.UNLOCKED, nep.getAdministrativeState(),
1223             "administrative state should be UNLOCKED");
1224 //      TODO: convert this test since terminationState is migrated to CEP attribute in TAPI 2.4
1225 //        assertEquals(TerminationState.TERMINATEDBIDIRECTIONAL, nep.getTerminationState(),
1226 //            "termination state should be TERMINATED BIDIRECTIONAL");
1227         assertEquals(LifecycleState.INSTALLED, nep.getLifecycleState(),
1228             "life-cycle state should be INSTALLED");
1229         if (!isRdm) {
1230             assertEquals(1, nep.getMappedServiceInterfacePoint().size(), "client nep should support 1 SIP");
1231         }
1232 //      TODO: convert this test since terminationState is migrated to CEP attribute in TAPI 2.4
1233 //        assertEquals(TerminationDirection.BIDIRECTIONAL, nep.getTerminationDirection(),
1234 //            "termination direction should be BIDIRECTIONAL");
1235         assertEquals(OperationalState.ENABLED, nep.getOperationalState(),
1236             "operational state of client nep should be ENABLED");
1237         assertEquals(PortRole.SYMMETRIC, nep.getLinkPortRole(), "link-port-role of client nep should be SYMMETRIC");
1238     }
1239
1240     private void checkTransitionalLink(Link link, Uuid node1Uuid, Uuid node2Uuid, String tp1, String tp2,
1241                                        String ietfNodeId) {
1242         Uuid linkUuid = new Uuid(UUID.nameUUIDFromBytes((tp1 + "to" + tp2)
1243             .getBytes(Charset.forName("UTF-8"))).toString());
1244         assertEquals(linkUuid, link.getUuid(), "bad uuid for link between DSR node " + tp1 + " and iOTSI port " + tp2);
1245         assertEquals(CAPACITYUNITGBPS.VALUE, link.getAvailableCapacity().getTotalSize().getUnit(),
1246             "Available capacity unit should be GBPS");
1247         assertEquals(Uint64.valueOf(100), link.getAvailableCapacity().getTotalSize().getValue(),
1248             "Available capacity -total size value should be 100");
1249         assertEquals(2, link.getTransitionedLayerProtocolName().size(),
1250             "transitional link should be between 2 nodes of protocol layers ODU and PHOTONIC_MEDIA");
1251         assertThat("transitional link should be between 2 nodes of protocol layers ODU and PHOTONIC_MEDIA",
1252             link.getTransitionedLayerProtocolName(),
1253             hasItems(LayerProtocolName.ODU.getName(), LayerProtocolName.PHOTONICMEDIA.getName()));
1254         assertEquals(ForwardingDirection.BIDIRECTIONAL, link.getDirection(),
1255             "transitional link should be BIDIRECTIONAL");
1256         List<org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121
1257             .link.NodeEdgePoint> nodeEdgePointList = new ArrayList<>(link.nonnullNodeEdgePoint().values());
1258         assertEquals(topologyUuid, nodeEdgePointList.get(0).getTopologyUuid(),
1259             "topology uuid should be the same for the two termination point of the link");
1260         assertEquals(topologyUuid, nodeEdgePointList.get(1).getTopologyUuid(),
1261             "topology uuid should be the same for the two termination point of the link");
1262         assertThat("transitional links should terminate on DSR node and Photonic node",
1263             nodeEdgePointList.get(0).getNodeUuid().getValue(),
1264             either(containsString(node1Uuid.getValue())).or(containsString(node2Uuid.getValue())));
1265         assertThat("transitional links should terminate on DSR node and Photonic node",
1266             nodeEdgePointList.get(1).getNodeUuid().getValue(),
1267             either(containsString(node1Uuid.getValue())).or(containsString(node2Uuid.getValue())));
1268         Uuid nep1Uuid = new Uuid(UUID.nameUUIDFromBytes(tp1.getBytes(Charset.forName("UTF-8"))).toString());
1269         Uuid nep2Uuid = new Uuid(UUID.nameUUIDFromBytes(tp2.getBytes(Charset.forName("UTF-8"))).toString());
1270         assertThat("transitional links should terminate on " + tp1 + " and " + tp2 + " neps",
1271             nodeEdgePointList.get(0).getNodeEdgePointUuid().getValue(),
1272             either(containsString(nep1Uuid.getValue())).or(containsString(nep2Uuid.getValue())));
1273         assertThat("transitional links should terminate on DSR node and Photonic node",
1274             nodeEdgePointList.get(1).getNodeEdgePointUuid().getValue(),
1275             either(containsString(nep1Uuid.getValue())).or(containsString(nep2Uuid.getValue())));
1276     }
1277
1278     private void checkOtnLink(Link link, Uuid node1Uuid, Uuid node2Uuid, Uuid tp1Uuid, Uuid tp2Uuid, Uuid linkUuid,
1279                               String linkName) {
1280         assertEquals(linkName, link.getName().get(new NameKey("otn link name")).getValue(), "bad name for the link");
1281         assertEquals(linkUuid, link.getUuid(), "bad uuid for link");
1282         assertEquals(CAPACITYUNITGBPS.VALUE, link.getAvailableCapacity().getTotalSize().getUnit(),
1283             "Available capacity unit should be MBPS");
1284         String prefix = linkName.split("-")[0];
1285         if ("OTU4".equals(prefix)) {
1286             assertEquals(Uint64.valueOf(0), link.getAvailableCapacity().getTotalSize().getValue(),
1287                 "Available capacity -total size value should be 0");
1288         } else if ("ODTU4".equals(prefix)) {
1289             assertEquals(Uint64.valueOf(100000), link.getAvailableCapacity().getTotalSize().getValue(),
1290                 "Available capacity -total size value should be 100 000");
1291         }
1292         assertEquals(CAPACITYUNITGBPS.VALUE, link.getTotalPotentialCapacity().getTotalSize().getUnit(),
1293             "Total capacity unit should be GBPS");
1294         assertEquals(Uint64.valueOf(100), link.getTotalPotentialCapacity().getTotalSize().getValue(),
1295             "Total capacity -total size value should be 100");
1296         if ("OTU4".equals(prefix)) {
1297             assertEquals(
1298                 LayerProtocolName.PHOTONICMEDIA.getName(),
1299                 link.getLayerProtocolName().stream().findFirst().orElseThrow().getName(),
1300                 "otn link should be between 2 nodes of protocol layers PHOTONIC_MEDIA");
1301         } else if ("ODTU4".equals(prefix)) {
1302             assertEquals(
1303                 LayerProtocolName.ODU.getName(),
1304                 link.getLayerProtocolName().stream().findFirst().orElseThrow().getName(),
1305                 "otn link should be between 2 nodes of protocol layers ODU");
1306         }
1307         assertEquals(ForwardingDirection.BIDIRECTIONAL, link.getDirection(), "otn tapi link should be BIDIRECTIONAL");
1308         List<org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121
1309             .link.NodeEdgePoint> nodeEdgePointList = new ArrayList<>(link.nonnullNodeEdgePoint().values());
1310         assertEquals(topologyUuid, nodeEdgePointList.get(0).getTopologyUuid(),
1311             "topology uuid should be the same for the two termination point of the link");
1312         assertEquals(topologyUuid, nodeEdgePointList.get(1).getTopologyUuid(),
1313             "topology uuid should be the same for the two termination point of the link");
1314         assertThat("otn links should terminate on two distinct nodes",
1315             nodeEdgePointList.get(0).getNodeUuid().getValue(),
1316             either(containsString(node1Uuid.getValue())).or(containsString(node2Uuid.getValue())));
1317         assertThat("otn links should terminate on two distinct nodes",
1318             nodeEdgePointList.get(1).getNodeUuid().getValue(),
1319             either(containsString(node1Uuid.getValue())).or(containsString(node2Uuid.getValue())));
1320         assertThat("otn links should terminate on two distinct tps",
1321             nodeEdgePointList.get(0).getNodeEdgePointUuid().getValue(),
1322             either(containsString(tp1Uuid.getValue())).or(containsString(tp2Uuid.getValue())));
1323         assertThat("otn links should terminate on two distinct tps",
1324             nodeEdgePointList.get(1).getNodeEdgePointUuid().getValue(),
1325             either(containsString(tp1Uuid.getValue())).or(containsString(tp2Uuid.getValue())));
1326         assertEquals(OperationalState.ENABLED, link.getOperationalState(), "operational state should be ENABLED");
1327         assertEquals(AdministrativeState.UNLOCKED, link.getAdministrativeState(),
1328             "administrative state should be UNLOCKED");
1329     }
1330
1331     private void checkOmsLink(Link link, Uuid node1Uuid, Uuid node2Uuid, Uuid tp1Uuid, Uuid tp2Uuid, Uuid linkUuid,
1332                               String linkName) {
1333         assertEquals(linkName, link.getName().get(new NameKey("OMS link name")).getValue(), "bad name for the link");
1334         assertEquals(linkUuid, link.getUuid(), "bad uuid for link");
1335         assertEquals(
1336             LayerProtocolName.PHOTONICMEDIA.getName(),
1337             link.getLayerProtocolName().stream().findFirst().orElseThrow().getName(),
1338             "oms link should be between 2 nodes of protocol layers PHOTONIC_MEDIA");
1339         assertEquals(ForwardingDirection.BIDIRECTIONAL, link.getDirection(), "otn tapi link should be BIDIRECTIONAL");
1340         List<org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121
1341             .link.NodeEdgePoint> nodeEdgePointList = new ArrayList<>(link.nonnullNodeEdgePoint().values());
1342         assertEquals(2, nodeEdgePointList.size(), "oms link should be between 2 neps");
1343         assertEquals(topologyUuid, nodeEdgePointList.get(0).getTopologyUuid(),
1344             "topology uuid should be the same for the two termination point of the link");
1345         assertEquals(topologyUuid, nodeEdgePointList.get(1).getTopologyUuid(),
1346             "topology uuid should be the same for the two termination point of the link");
1347         assertThat("oms links should terminate on two distinct nodes",
1348             nodeEdgePointList.get(0).getNodeUuid().getValue(),
1349             either(containsString(node1Uuid.getValue())).or(containsString(node2Uuid.getValue())));
1350         assertThat("oms links should terminate on two distinct nodes",
1351             nodeEdgePointList.get(1).getNodeUuid().getValue(),
1352             either(containsString(node1Uuid.getValue())).or(containsString(node2Uuid.getValue())));
1353         assertThat("oms links should terminate on two distinct tps",
1354             nodeEdgePointList.get(0).getNodeEdgePointUuid().getValue(),
1355             either(containsString(tp1Uuid.getValue())).or(containsString(tp2Uuid.getValue())));
1356         assertThat("oms links should terminate on two distinct tps",
1357             nodeEdgePointList.get(1).getNodeEdgePointUuid().getValue(),
1358             either(containsString(tp1Uuid.getValue())).or(containsString(tp2Uuid.getValue())));
1359     }
1360
1361     private Node changeTerminationPointState(Node initialNode, String tpid, AdminStates admin, State oper) {
1362         org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.Node1Builder tpdr1Bldr
1363             = new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.Node1Builder(
1364             initialNode.augmentation(Node1.class));
1365         Map<TerminationPointKey, TerminationPoint> tps = new HashMap<>(tpdr1Bldr.getTerminationPoint());
1366         TerminationPointBuilder tpBldr = new TerminationPointBuilder(
1367             tps.get(new TerminationPointKey(new TpId(tpid))));
1368         TerminationPoint1Builder tp1Bldr = new TerminationPoint1Builder(tpBldr.augmentation(TerminationPoint1.class));
1369         tp1Bldr.setAdministrativeState(admin)
1370             .setOperationalState(oper);
1371         tpBldr.addAugmentation(tp1Bldr.build());
1372         tps.replace(tpBldr.key(), tpBldr.build());
1373         tpdr1Bldr.setTerminationPoint(tps);
1374         return new NodeBuilder(initialNode).addAugmentation(tpdr1Bldr.build()).build();
1375     }
1376
1377     private org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network
1378             .Link changeOtnLinkState(
1379             org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network
1380             .Link initiallink, AdminStates admin, State oper) {
1381
1382         org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network
1383             .LinkBuilder linkBldr = new
1384             org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network
1385             .LinkBuilder(initiallink);
1386         Link1Builder link1Bldr = new Link1Builder(linkBldr.augmentation(Link1.class));
1387         link1Bldr.setAdministrativeState(admin)
1388             .setOperationalState(oper);
1389         linkBldr.addAugmentation(link1Bldr.build());
1390         return linkBldr.build();
1391     }
1392 }