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