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