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