TAPI topology consolidation - step3
[transportpce.git] / tapi / src / test / java / org / opendaylight / transportpce / tapi / topology / ConvertORTopoObjectToTapiTooObjectTest.java
1 /*
2  * Copyright © 2020 Orange, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.transportpce.tapi.topology;
9
10 import static org.hamcrest.CoreMatchers.containsString;
11 import static org.hamcrest.CoreMatchers.either;
12 import static org.hamcrest.CoreMatchers.hasItem;
13 import static org.hamcrest.CoreMatchers.hasItems;
14 import static org.hamcrest.MatcherAssert.assertThat;
15 import static org.junit.Assert.assertEquals;
16 import static org.junit.Assert.assertNull;
17 import static org.junit.Assert.fail;
18
19 import com.google.common.util.concurrent.FluentFuture;
20 import java.nio.charset.Charset;
21 import java.util.ArrayList;
22 import java.util.Collections;
23 import java.util.Iterator;
24 import java.util.List;
25 import java.util.Optional;
26 import java.util.UUID;
27 import java.util.concurrent.ExecutionException;
28 import java.util.stream.Collectors;
29 import org.eclipse.jdt.annotation.Nullable;
30 import org.junit.BeforeClass;
31 import org.junit.Test;
32 import org.opendaylight.mdsal.binding.api.DataBroker;
33 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
34 import org.opendaylight.transportpce.common.InstanceIdentifiers;
35 import org.opendaylight.transportpce.tapi.utils.TopologyDataUtils;
36 import org.opendaylight.transportpce.test.AbstractTest;
37 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev181130.TerminationPoint1;
38 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev181130.OpenroadmTpType;
39 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.NetworkId;
40 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.Networks;
41 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.NodeId;
42 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.networks.NetworkKey;
43 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.networks.network.Node;
44 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.networks.network.NodeKey;
45 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.Network1;
46 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.Node1;
47 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network.node.TerminationPoint;
48 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.AdministrativeState;
49 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.CapacityUnit;
50 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.ForwardingDirection;
51 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.LayerProtocolName;
52 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.LifecycleState;
53 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.OperationalState;
54 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.PortDirection;
55 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.PortRole;
56 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.TerminationDirection;
57 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.TerminationState;
58 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.Uuid;
59 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.global._class.Name;
60 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.global._class.NameKey;
61 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.dsr.rev181210.DIGITALSIGNALTYPE100GigE;
62 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.dsr.rev181210.DIGITALSIGNALTYPE10GigELAN;
63 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.odu.rev181210.ODUTYPEODU2E;
64 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.odu.rev181210.ODUTYPEODU4;
65 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.photonic.media.rev181210.PHOTONICLAYERQUALIFIEROMS;
66 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.photonic.media.rev181210.PHOTONICLAYERQUALIFIEROTSi;
67 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.ForwardingRule;
68 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.RuleType;
69 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.node.NodeRuleGroup;
70 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.node.OwnedNodeEdgePoint;
71 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.node.rule.group.NodeEdgePoint;
72 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.node.rule.group.Rule;
73 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.topology.Link;
74 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
75 import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
76 import org.opendaylight.yangtools.yang.common.Uint64;
77 import org.slf4j.Logger;
78 import org.slf4j.LoggerFactory;
79
80 public class ConvertORTopoObjectToTapiTooObjectTest extends AbstractTest {
81     private static final Logger LOG = LoggerFactory.getLogger(ConvertORTopoObjectToTapiTooObjectTest.class);
82
83     private static Node otnMuxA;
84     private static Node otnMuxC;
85     private static Node otnSwitch;
86     private static Node tpdr100G;
87     private static List<org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226
88         .networks.network.Link> otnLinks;
89     private static Uuid topologyUuid;
90     private static DataBroker dataBroker = getDataBroker();
91
92     @BeforeClass
93     public static void setUp() throws InterruptedException, ExecutionException {
94         TopologyDataUtils.writeTopologyFromFileToDatastore(getDataStoreContextUtil(),
95             TopologyDataUtils.OPENROADM_TOPOLOGY_FILE, InstanceIdentifiers.OVERLAY_NETWORK_II);
96         TopologyDataUtils.writeTopologyFromFileToDatastore(getDataStoreContextUtil(),
97             TopologyDataUtils.OTN_TOPOLOGY_FILE, InstanceIdentifiers.OTN_NETWORK_II);
98         TopologyDataUtils.writePortmappingFromFileToDatastore(getDataStoreContextUtil());
99
100         KeyedInstanceIdentifier<Node, NodeKey> muxAIID = InstanceIdentifier.create(Networks.class)
101             .child(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.networks.Network
102                 .class, new NetworkKey(new NetworkId("otn-topology")))
103             .child(Node.class, new NodeKey(new NodeId("SPDR-SA1-XPDR1")));
104         FluentFuture<Optional<Node>> muxAFuture = dataBroker.newReadOnlyTransaction()
105             .read(LogicalDatastoreType.CONFIGURATION, muxAIID);
106         KeyedInstanceIdentifier<Node, NodeKey> muxCIID = InstanceIdentifier.create(Networks.class)
107             .child(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.networks.Network
108                 .class, new NetworkKey(new NetworkId("otn-topology")))
109             .child(Node.class, new NodeKey(new NodeId("SPDR-SC1-XPDR1")));
110         FluentFuture<Optional<Node>> muxCFuture = dataBroker.newReadOnlyTransaction()
111             .read(LogicalDatastoreType.CONFIGURATION, muxCIID);
112         KeyedInstanceIdentifier<Node, NodeKey> switchIID = InstanceIdentifier.create(Networks.class)
113             .child(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.networks.Network
114                 .class, new NetworkKey(new NetworkId("otn-topology")))
115             .child(Node.class, new NodeKey(new NodeId("SPDR-SA1-XPDR2")));
116         FluentFuture<Optional<Node>> switchFuture = dataBroker.newReadOnlyTransaction()
117             .read(LogicalDatastoreType.CONFIGURATION, switchIID);
118
119         otnMuxA = muxAFuture.get().get();
120         otnMuxC = muxCFuture.get().get();
121         otnSwitch = switchFuture.get().get();
122
123         KeyedInstanceIdentifier<Node, NodeKey> tpdrIID = InstanceIdentifier.create(Networks.class)
124             .child(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.networks.Network
125                 .class, new NetworkKey(new NetworkId("otn-topology")))
126             .child(Node.class, new NodeKey(new NodeId("XPDR-A1-XPDR1")));
127         FluentFuture<Optional<Node>> tpdrFuture = dataBroker.newReadOnlyTransaction()
128             .read(LogicalDatastoreType.CONFIGURATION, tpdrIID);
129         tpdr100G = tpdrFuture.get().get();
130
131         InstanceIdentifier<Network1> linksIID = InstanceIdentifier.create(Networks.class)
132             .child(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.networks.Network
133                 .class, new NetworkKey(new NetworkId("otn-topology")))
134             .augmentation(Network1.class);
135         FluentFuture<Optional<Network1>> linksFuture = dataBroker.newReadOnlyTransaction()
136             .read(LogicalDatastoreType.CONFIGURATION, linksIID);
137         otnLinks = linksFuture.get().get().getLink().values().stream().collect(Collectors.toList());
138         Collections.sort(otnLinks, (l1, l2) -> l1.getLinkId().getValue().compareTo(l2.getLinkId().getValue()));
139         topologyUuid = new Uuid(UUID.nameUUIDFromBytes("T0 - Multi-layer topology".getBytes(Charset.forName("UTF-8")))
140             .toString());
141         LOG.info("TEST SETUP READY");
142     }
143
144     @Test
145     public void convertNodeForTransponder100G() {
146         ConvertORTopoToTapiTopo tapiFactory = new ConvertORTopoToTapiTopo(topologyUuid);
147         List<String> networkPortList = new ArrayList<>();
148         for (TerminationPoint tp : tpdr100G.augmentation(Node1.class).getTerminationPoint().values()) {
149             if (tp.augmentation(TerminationPoint1.class).getTpType().equals(OpenroadmTpType.XPONDERNETWORK)) {
150                 networkPortList.add(tp.getTpId().getValue());
151             }
152         }
153         tapiFactory.convertNode(tpdr100G, networkPortList);
154         List<org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.topology.Node> tapiNodes
155             = tapiFactory.getTapiNodes().values().stream()
156             .sorted((n1, n2) -> n1.getUuid().getValue().compareTo(n2.getUuid().getValue()))
157             .collect(Collectors.toList());
158
159         assertEquals("Node list size should be 2", 2, tapiFactory.getTapiNodes().size());
160         assertEquals("Link list size should be 2", 2, tapiFactory.getTapiLinks().size());
161
162         Uuid dsrNodeUuid = new Uuid(UUID.nameUUIDFromBytes("XPDR-A1-XPDR1+DSR".getBytes(Charset.forName("UTF-8")))
163             .toString());
164         checkDsrNode(tapiNodes.get(1), dsrNodeUuid, "tpdr", "XPDR-A1-XPDR1");
165         Uuid otsiNodeUuid = new Uuid(UUID.nameUUIDFromBytes("XPDR-A1-XPDR1+OTSi".getBytes(Charset.forName("UTF-8")))
166             .toString());
167         checkOtsiNode(tapiNodes.get(0), otsiNodeUuid, "tpdr", "XPDR-A1-XPDR1");
168
169         List<Link> tapiLinks = tapiFactory.getTapiLinks().values().stream()
170             .sorted((l1, l2) -> l1.getUuid().getValue().compareTo(l2.getUuid().getValue()))
171             .collect(Collectors.toList());
172         checkTransitionalLink(tapiLinks.get(1), dsrNodeUuid, otsiNodeUuid,
173             "XPDR-A1-XPDR1+DSR+XPDR1-NETWORK1", "XPDR-A1-XPDR1+iOTSi+XPDR1-NETWORK1", "XPDR-A1-XPDR1");
174     }
175
176     @Test
177     public void convertNodeForOtnMuxponder() {
178         ConvertORTopoToTapiTopo tapiFactory = new ConvertORTopoToTapiTopo(topologyUuid);
179         List<String> networkPortList = new ArrayList<>();
180         for (TerminationPoint tp : otnMuxA.augmentation(Node1.class).getTerminationPoint().values()) {
181             if (tp.augmentation(TerminationPoint1.class).getTpType().equals(OpenroadmTpType.XPONDERNETWORK)) {
182                 networkPortList.add(tp.getTpId().getValue());
183             }
184         }
185         tapiFactory.convertNode(otnMuxA, networkPortList);
186         List<org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.topology.Node> tapiNodes
187             = tapiFactory.getTapiNodes().values().stream()
188             .sorted((n1, n2) -> n1.getUuid().getValue().compareTo(n2.getUuid().getValue()))
189             .collect(Collectors.toList());
190
191         assertEquals("Node list size should be 2", 2, tapiFactory.getTapiNodes().size());
192         assertEquals("Link list size should be 1", 1, tapiFactory.getTapiLinks().size());
193         Uuid dsrNodeUuid = new Uuid(UUID.nameUUIDFromBytes("SPDR-SA1-XPDR1+DSR".getBytes(Charset.forName("UTF-8")))
194             .toString());
195         checkDsrNode(tapiNodes.get(0), dsrNodeUuid, "mux", "SPDR-SA1-XPDR1");
196         Uuid otsiNodeUuid = new Uuid(UUID.nameUUIDFromBytes("SPDR-SA1-XPDR1+OTSi".getBytes(Charset.forName("UTF-8")))
197             .toString());
198         checkOtsiNode(tapiNodes.get(1), otsiNodeUuid, "mux", "SPDR-SA1-XPDR1");
199
200         List<Link> tapiLinks = tapiFactory.getTapiLinks().values().stream()
201             .sorted((l1, l2) -> l1.getUuid().getValue().compareTo(l2.getUuid().getValue()))
202             .collect(Collectors.toList());
203         checkTransitionalLink(tapiLinks.get(0), dsrNodeUuid, otsiNodeUuid,
204             "SPDR-SA1-XPDR1+DSR+XPDR1-NETWORK1", "SPDR-SA1-XPDR1+iOTSi+XPDR1-NETWORK1", "SPDR-SA1-XPDR1");
205     }
206
207     @Test
208     public void convertNodeForOtnSwitch() {
209         ConvertORTopoToTapiTopo tapiFactory = new ConvertORTopoToTapiTopo(topologyUuid);
210         List<String> networkPortList = new ArrayList<>();
211         for (TerminationPoint tp : otnSwitch.augmentation(Node1.class).getTerminationPoint().values()) {
212             if (tp.augmentation(TerminationPoint1.class).getTpType().equals(OpenroadmTpType.XPONDERNETWORK)) {
213                 networkPortList.add(tp.getTpId().getValue());
214             }
215         }
216         tapiFactory.convertNode(otnSwitch, networkPortList);
217         List<org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.topology.Node> tapiNodes
218             = tapiFactory.getTapiNodes().values().stream()
219             .sorted((n1, n2) -> n1.getUuid().getValue().compareTo(n2.getUuid().getValue()))
220             .collect(Collectors.toList());
221
222         assertEquals("Node list size should be 2", 2, tapiFactory.getTapiNodes().size());
223         assertEquals("Link list size should be 4", 4, tapiFactory.getTapiLinks().size());
224
225         Uuid dsrNodeUuid = new Uuid(UUID.nameUUIDFromBytes("SPDR-SA1-XPDR2+DSR".getBytes(Charset.forName("UTF-8")))
226             .toString());
227         checkDsrNode(tapiNodes.get(0), dsrNodeUuid, "switch", "SPDR-SA1-XPDR2");
228         Uuid otsiNodeUuid = new Uuid(UUID.nameUUIDFromBytes("SPDR-SA1-XPDR2+OTSi".getBytes(Charset.forName("UTF-8")))
229             .toString());
230         checkOtsiNode(tapiNodes.get(1), otsiNodeUuid, "switch", "SPDR-SA1-XPDR2");
231
232         List<Link> tapiLinks = tapiFactory.getTapiLinks().values().stream()
233             .sorted((l1, l2) -> l1.getUuid().getValue().compareTo(l2.getUuid().getValue()))
234             .collect(Collectors.toList());
235         checkTransitionalLink(tapiLinks.get(0), dsrNodeUuid, otsiNodeUuid,
236             "SPDR-SA1-XPDR2+DSR+XPDR2-NETWORK4", "SPDR-SA1-XPDR2+iOTSi+XPDR2-NETWORK4", "SPDR-SA1-XPDR2");
237     }
238
239     @Test
240     public void convertOtnLink() {
241         ConvertORTopoToTapiTopo tapiFactory = new ConvertORTopoToTapiTopo(topologyUuid);
242         List<String> networkPortListA = new ArrayList<>();
243         for (TerminationPoint tp : otnMuxA.augmentation(Node1.class).getTerminationPoint().values()) {
244             if (tp.augmentation(TerminationPoint1.class).getTpType().equals(OpenroadmTpType.XPONDERNETWORK)) {
245                 networkPortListA.add(tp.getTpId().getValue());
246             }
247         }
248         tapiFactory.convertNode(otnMuxA, networkPortListA);
249         List<String> networkPortListC = new ArrayList<>();
250         for (TerminationPoint tp : otnMuxC.augmentation(Node1.class).getTerminationPoint().values()) {
251             if (tp.augmentation(TerminationPoint1.class).getTpType().equals(OpenroadmTpType.XPONDERNETWORK)) {
252                 networkPortListC.add(tp.getTpId().getValue());
253             }
254         }
255         tapiFactory.convertNode(otnMuxC, networkPortListC);
256         tapiFactory.convertLinks(otnLinks);
257         assertEquals("Link list size should be 4", 4, tapiFactory.getTapiLinks().size());
258
259         Uuid node1Uuid = new Uuid(UUID.nameUUIDFromBytes("SPDR-SA1-XPDR1+DSR".getBytes(Charset.forName("UTF-8")))
260             .toString());
261         Uuid node2Uuid = new Uuid(UUID.nameUUIDFromBytes("SPDR-SC1-XPDR1+DSR".getBytes(Charset.forName("UTF-8")))
262             .toString());
263         Uuid node3Uuid = new Uuid(UUID.nameUUIDFromBytes("SPDR-SA1-XPDR1+OTSi".getBytes(Charset.forName("UTF-8")))
264             .toString());
265         Uuid node4Uuid = new Uuid(UUID.nameUUIDFromBytes("SPDR-SC1-XPDR1+OTSi".getBytes(Charset.forName("UTF-8")))
266             .toString());
267         Uuid tp1Uuid = new Uuid(UUID.nameUUIDFromBytes("SPDR-SA1-XPDR1+DSR+XPDR1-NETWORK1"
268             .getBytes(Charset.forName("UTF-8"))).toString());
269         Uuid tp2Uuid = new Uuid(UUID.nameUUIDFromBytes("SPDR-SC1-XPDR1+DSR+XPDR1-NETWORK1"
270             .getBytes(Charset.forName("UTF-8"))).toString());
271         Uuid tp3Uuid = new Uuid(UUID.nameUUIDFromBytes("SPDR-SA1-XPDR1+iOTSi+XPDR1-NETWORK1"
272             .getBytes(Charset.forName("UTF-8"))).toString());
273         Uuid tp4Uuid = new Uuid(UUID.nameUUIDFromBytes("SPDR-SC1-XPDR1+iOTSi+XPDR1-NETWORK1"
274             .getBytes(Charset.forName("UTF-8"))).toString());
275         Uuid link1Uuid =
276             new Uuid(UUID.nameUUIDFromBytes("ODU4-SPDR-SA1-XPDR1-XPDR1-NETWORK1toSPDR-SC1-XPDR1-XPDR1-NETWORK1"
277                 .getBytes(Charset.forName("UTF-8"))).toString());
278         Uuid link2Uuid =
279             new Uuid(UUID.nameUUIDFromBytes("OTU4-SPDR-SA1-XPDR1-XPDR1-NETWORK1toSPDR-SC1-XPDR1-XPDR1-NETWORK1"
280                 .getBytes(Charset.forName("UTF-8"))).toString());
281
282         List<Link> links = tapiFactory.getTapiLinks().values().stream()
283             .sorted((l1, l2) -> l1.getUuid().getValue().compareTo(l2.getUuid().getValue()))
284             .collect(Collectors.toList());
285         checkOtnLink(links.get(0), node1Uuid, node2Uuid, tp1Uuid, tp2Uuid, link1Uuid,
286             "ODU4-SPDR-SA1-XPDR1-XPDR1-NETWORK1toSPDR-SC1-XPDR1-XPDR1-NETWORK1");
287         checkOtnLink(links.get(2), node3Uuid, node4Uuid, tp3Uuid, tp4Uuid, link2Uuid,
288             "OTU4-SPDR-SA1-XPDR1-XPDR1-NETWORK1toSPDR-SC1-XPDR1-XPDR1-NETWORK1");
289     }
290
291     @Test
292     public void convertRoadmInfrastructureWhenNoXponderAttached() {
293         ConvertORTopoToTapiTopo tapiFactory = new ConvertORTopoToTapiTopo(topologyUuid);
294         tapiFactory.convertRoadmInfrastructure();
295
296         assertEquals("Node list size should be 1", 1, tapiFactory.getTapiNodes().size());
297         assertEquals("Link list size should be empty", 0, tapiFactory.getTapiLinks().size());
298         List<org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.topology.Node> tapiNodes
299             = tapiFactory.getTapiNodes().values().stream().collect(Collectors.toList());
300         Uuid otsiNodeUuid = new Uuid(UUID.nameUUIDFromBytes("ROADM-infra".getBytes(Charset.forName("UTF-8")))
301             .toString());
302         checkOtsiNode(tapiNodes.get(0), otsiNodeUuid, "infra", "ROADM-infra");
303     }
304
305     @Test
306     public void convertRoadmInfrastructureWhenOtnMuxAttached() {
307         ConvertORTopoToTapiTopo tapiFactory = new ConvertORTopoToTapiTopo(topologyUuid);
308         List<String> networkPortListA = new ArrayList<>();
309         for (TerminationPoint tp : otnMuxA.augmentation(Node1.class).getTerminationPoint().values()) {
310             if (tp.augmentation(TerminationPoint1.class).getTpType().equals(OpenroadmTpType.XPONDERNETWORK)) {
311                 networkPortListA.add(tp.getTpId().getValue());
312             }
313         }
314         tapiFactory.convertNode(otnMuxA, networkPortListA);
315         tapiFactory.convertRoadmInfrastructure();
316
317         assertEquals("Node list size should be 3", 3, tapiFactory.getTapiNodes().size());
318         assertEquals("Link list size should be 2", 2, tapiFactory.getTapiLinks().size());
319         List<org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.topology.Node> tapiNodes
320             = tapiFactory.getTapiNodes().values().stream()
321                 .sorted((n1, n2) -> n1.getUuid().getValue().compareTo(n2.getUuid().getValue()))
322                 .collect(Collectors.toList());
323         Uuid otsiNodeUuid = new Uuid(UUID.nameUUIDFromBytes("ROADM-infra".getBytes(Charset.forName("UTF-8")))
324             .toString());
325         checkOtsiNode(tapiNodes.get(2), otsiNodeUuid, "infra", "ROADM-infra");
326
327         List<Link> links = tapiFactory.getTapiLinks().values().stream()
328             .sorted((l1, l2) -> l1.getUuid().getValue().compareTo(l2.getUuid().getValue()))
329             .collect(Collectors.toList());
330         Uuid node1Uuid = new Uuid(UUID.nameUUIDFromBytes("SPDR-SA1-XPDR1+OTSi".getBytes(Charset.forName("UTF-8")))
331             .toString());
332         Uuid node2Uuid = new Uuid(UUID.nameUUIDFromBytes("ROADM-infra".getBytes(Charset.forName("UTF-8")))
333             .toString());
334         Uuid tp1Uuid = new Uuid(UUID.nameUUIDFromBytes("SPDR-SA1-XPDR1+eOTSi+XPDR1-NETWORK1"
335             .getBytes(Charset.forName("UTF-8"))).toString());
336         Uuid tp2Uuid = new Uuid(UUID.nameUUIDFromBytes(("roadm node+nep+1")
337             .getBytes(Charset.forName("UTF-8"))).toString());
338         Uuid linkUuid =
339             new Uuid(UUID.nameUUIDFromBytes("SPDR-SA1-XPDR1--XPDR1-NETWORK1 and ROADM-infra--NodeEdgePoint_1"
340                 .getBytes(Charset.forName("UTF-8"))).toString());
341         checkOmsLink(links.get(0), node1Uuid, node2Uuid, tp1Uuid, tp2Uuid, linkUuid,
342             "SPDR-SA1-XPDR1--XPDR1-NETWORK1 and ROADM-infra--NodeEdgePoint_1");
343     }
344
345     private void checkDsrNode(org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.topology.Node node,
346         Uuid nodeUuid, String dsrNodeType, String nodeId) {
347         assertEquals("incorrect node uuid", nodeUuid, node.getUuid());
348         assertEquals("incorrect node name", nodeId, node.getName().get(new NameKey("dsr/odu node name")).getValue());
349         assertEquals("administrative state should be UNLOCKED",
350             AdministrativeState.UNLOCKED, node.getAdministrativeState());
351         assertEquals("life-cycle state should be INSTALLED", LifecycleState.INSTALLED, node.getLifecycleState());
352         assertEquals("operational state should be ENABLED", OperationalState.ENABLED, node.getOperationalState());
353         assertEquals("value-name should be 'dsr/odu node name'",
354              "dsr/odu node name", node.nonnullName().values().stream().findFirst().get().getValueName());
355         assertEquals("dsr node should manage 2 protocol layers : dsr and odu",
356             2, node.getLayerProtocolName().size());
357         assertThat("dsr node should manage 2 protocol layers : dsr and odu",
358             node.getLayerProtocolName(), hasItems(LayerProtocolName.DSR, LayerProtocolName.ODU));
359         List<OwnedNodeEdgePoint> nepsN = node.nonnullOwnedNodeEdgePoint().values().stream()
360             .filter(n -> n.getName().containsKey(new NameKey("NodeEdgePoint_N")))
361             .sorted((nep1, nep2) -> nep1.getUuid().getValue().compareTo(nep2.getUuid().getValue()))
362             .collect(Collectors.toList());
363         List<OwnedNodeEdgePoint> nepsC;
364         switch (dsrNodeType) {
365             case "switch":
366                 nepsC = node.nonnullOwnedNodeEdgePoint().values().stream()
367                     .filter(n -> n.getName().containsKey(new NameKey("NodeEdgePoint_C")))
368                     .sorted((nep1, nep2) -> nep1.getUuid().getValue().compareTo(nep2.getUuid().getValue()))
369                     .collect(Collectors.toList());
370                 assertEquals("Switch-DSR node should have 4 NEPs network", 4, nepsN.size());
371                 assertEquals("Switch-DSR node should have 4 NEPs client", 4, nepsC.size());
372                 OwnedNodeEdgePoint nep1 = nepsC.get(2);
373                 Uuid client4NepUuid = new Uuid(
374                         UUID.nameUUIDFromBytes((nodeId + "+DSR+XPDR2-CLIENT4").getBytes(Charset.forName("UTF-8")))
375                         .toString());
376                 checkNepClient100GSwitch(nep1, client4NepUuid, "XPDR2-CLIENT4", "NodeEdgePoint_C");
377                 OwnedNodeEdgePoint nep2 = nepsN.get(1);
378                 Uuid networkNepUuid = new Uuid(
379                         UUID.nameUUIDFromBytes((nodeId + "+DSR+XPDR2-NETWORK1").getBytes(Charset.forName("UTF-8")))
380                         .toString());
381                 checkNepNetworkODU4(nep2, networkNepUuid, "XPDR2-NETWORK1", "NodeEdgePoint_N");
382                 List<NodeRuleGroup> nrgList = node.nonnullNodeRuleGroup().values().stream()
383                     .sorted((nrg1, nrg2) -> nrg1.getUuid().getValue().compareTo(nrg2.getUuid().getValue()))
384                     .collect(Collectors.toList());
385                 checkNodeRuleGroupForSwitchDSR(nrgList, client4NepUuid, networkNepUuid, nodeUuid);
386                 break;
387             case "mux":
388                 nepsC = node.nonnullOwnedNodeEdgePoint().values().stream()
389                     .filter(n -> n.getName().containsKey(new NameKey("NodeEdgePoint_C")))
390                     .sorted((nep3, nep4) -> nep3.getUuid().getValue().compareTo(nep4.getUuid().getValue()))
391                     .collect(Collectors.toList());
392                 assertEquals("Mux-DSR node should have 1 NEP network", 1, nepsN.size());
393                 assertEquals("Mux-DSR node should have 4 NEPs client", 4, nepsC.size());
394                 OwnedNodeEdgePoint nep3 = nepsC.get(2);
395                 Uuid client3NepUuid = new Uuid(
396                         UUID.nameUUIDFromBytes((nodeId + "+DSR+XPDR1-CLIENT3").getBytes(Charset.forName("UTF-8")))
397                         .toString());
398                 checkNepClient10G(nep3, client3NepUuid, "XPDR1-CLIENT3", "NodeEdgePoint_C");
399
400                 OwnedNodeEdgePoint nep4 = nepsN.get(0);
401                 Uuid networkNepUuid2 = new Uuid(
402                         UUID.nameUUIDFromBytes((nodeId + "+DSR+XPDR1-NETWORK1").getBytes(Charset.forName("UTF-8")))
403                         .toString());
404                 checkNepNetworkODU4(nep4, networkNepUuid2, "XPDR1-NETWORK1", "NodeEdgePoint_N");
405                 List<NodeRuleGroup> nrgList2 = node.nonnullNodeRuleGroup().values().stream()
406                     .sorted((nrg1, nrg2) -> nrg1.getUuid().getValue().compareTo(nrg2.getUuid().getValue()))
407                     .collect(Collectors.toList());
408                 checkNodeRuleGroupForMuxDSR(nrgList2, client3NepUuid, networkNepUuid2, nodeUuid);
409                 break;
410             case "tpdr":
411                 nepsC = node.nonnullOwnedNodeEdgePoint().values().stream()
412                     .filter(n -> n.getName().containsKey(new NameKey("100G-tpdr")))
413                     .sorted((nep5, nep6) -> nep5.getUuid().getValue().compareTo(nep6.getUuid().getValue()))
414                     .collect(Collectors.toList());
415                 assertEquals("Tpdr-DSR node should have 2 NEPs network", 2, nepsN.size());
416                 assertEquals("Tpdr-DSR node should have 2 NEPs client", 2, nepsC.size());
417                 OwnedNodeEdgePoint nep5 = nepsC.get(0);
418                 Uuid client1NepUuid = new Uuid(
419                         UUID.nameUUIDFromBytes((nodeId + "+DSR+XPDR1-CLIENT1").getBytes(Charset.forName("UTF-8")))
420                         .toString());
421                 checkNepClient100GTpdr(nep5, client1NepUuid, "XPDR1-CLIENT1", "100G-tpdr");
422
423                 OwnedNodeEdgePoint nep6 = nepsN.get(0);
424                 Uuid networkNepUuid3 = new Uuid(
425                         UUID.nameUUIDFromBytes((nodeId + "+DSR+XPDR1-NETWORK1").getBytes(Charset.forName("UTF-8")))
426                         .toString());
427                 checkNepNetworkODU4(nep6, networkNepUuid3, "XPDR1-NETWORK1", "NodeEdgePoint_N");
428                 List<NodeRuleGroup> nrgList3 = node.nonnullNodeRuleGroup().values().stream()
429                     .sorted((nrg1, nrg2) -> nrg1.getUuid().getValue().compareTo(nrg2.getUuid().getValue()))
430                     .collect(Collectors.toList());
431                 checkNodeRuleGroupForTpdrDSR(nrgList3, client1NepUuid, networkNepUuid3, nodeUuid);
432                 break;
433             default:
434                 fail();
435                 break;
436         }
437     }
438
439     private void checkOtsiNode(
440             org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.topology.Node node,
441         Uuid nodeUuid, String otsiNodeType, String nodeId) {
442         assertEquals("incorrect node uuid", nodeUuid, node.getUuid());
443         assertEquals("incorrect node name", nodeId, node.getName().get(new NameKey("otsi node name")).getValue());
444         assertEquals("administrative state should be UNLOCKED",
445             AdministrativeState.UNLOCKED, node.getAdministrativeState());
446         assertEquals("life-cycle state should be INSTALLED", LifecycleState.INSTALLED, node.getLifecycleState());
447         assertEquals("operational state should be ENABLED", OperationalState.ENABLED, node.getOperationalState());
448         assertEquals("value-name should be 'dsr/odu node name'",
449              "otsi node name", node.nonnullName().values().stream().findFirst().get().getValueName());
450         assertEquals("otsi node should manage a single protocol layer : PHOTONIC_MEDIA",
451             1, node.getLayerProtocolName().size());
452         assertEquals("otsi node should manage a single protocol layer : PHOTONIC_MEDIA",
453             LayerProtocolName.PHOTONICMEDIA, node.getLayerProtocolName().get(0));
454         List<OwnedNodeEdgePoint> nepsI = node.nonnullOwnedNodeEdgePoint().values().stream()
455             .filter(n -> n.getName().containsKey(new NameKey("iNodeEdgePoint")))
456             .sorted((nep1, nep2) -> nep1.getUuid().getValue().compareTo(nep2.getUuid().getValue()))
457             .collect(Collectors.toList());
458         List<OwnedNodeEdgePoint> nepsE = node.nonnullOwnedNodeEdgePoint().values().stream()
459             .filter(n -> n.getName().containsKey(new NameKey("eNodeEdgePoint")))
460             .sorted((nep1, nep2) -> nep1.getUuid().getValue().compareTo(nep2.getUuid().getValue()))
461             .collect(Collectors.toList());
462         switch (otsiNodeType) {
463             case "switch":
464                 assertEquals("Switch-OTSi node should have 4 eNEPs", 4, nepsE.size());
465                 assertEquals("Switch-OTSi node should have 4 iNEPs", 4, nepsI.size());
466                 OwnedNodeEdgePoint nep1 = nepsI.get(1);
467                 Uuid inepUuid = new Uuid(
468                         UUID.nameUUIDFromBytes((nodeId + "+iOTSi+XPDR2-NETWORK2").getBytes(Charset.forName("UTF-8")))
469                         .toString());
470                 checkNepOtsiNode(nep1, inepUuid, "XPDR2-NETWORK2", "iNodeEdgePoint");
471                 OwnedNodeEdgePoint nep2 = nepsE.get(0);
472                 Uuid enepUuid = new Uuid(
473                         UUID.nameUUIDFromBytes((nodeId + "+eOTSi+XPDR2-NETWORK2").getBytes(Charset.forName("UTF-8")))
474                         .toString());
475                 checkNepOtsiNode(nep2, enepUuid, "XPDR2-NETWORK2", "eNodeEdgePoint");
476                 List<NodeRuleGroup> nrgList = node.nonnullNodeRuleGroup().values().stream()
477                     .sorted((nrg1, nrg2) -> nrg1.getUuid().getValue().compareTo(nrg2.getUuid().getValue()))
478                     .collect(Collectors.toList());
479                 checkNodeRuleGroupForSwitchOTSi(nrgList, enepUuid, inepUuid, nodeUuid);
480                 break;
481             case "mux":
482                 assertEquals("Mux-OTSi node should have 1 eNEP", 1, nepsE.size());
483                 assertEquals("Mux-OTSi node should have 1 iNEPs", 1, nepsI.size());
484                 OwnedNodeEdgePoint nep3 = nepsE.get(0);
485                 Uuid enepUuid2 = new Uuid(
486                         UUID.nameUUIDFromBytes((nodeId + "+eOTSi+XPDR1-NETWORK1").getBytes(Charset.forName("UTF-8")))
487                         .toString());
488                 checkNepOtsiNode(nep3, enepUuid2, "XPDR1-NETWORK1", "eNodeEdgePoint");
489                 OwnedNodeEdgePoint nep4 = nepsI.get(0);
490                 Uuid inepUuid2 = new Uuid(
491                         UUID.nameUUIDFromBytes((nodeId + "+iOTSi+XPDR1-NETWORK1").getBytes(Charset.forName("UTF-8")))
492                         .toString());
493                 checkNepOtsiNode(nep4, inepUuid2, "XPDR1-NETWORK1", "iNodeEdgePoint");
494                 List<NodeRuleGroup> nrgList2 = node.nonnullNodeRuleGroup().values().stream()
495                     .sorted((nrg1, nrg2) -> nrg1.getUuid().getValue().compareTo(nrg2.getUuid().getValue()))
496                     .collect(Collectors.toList());
497                 checkNodeRuleGroupForMuxOTSi(nrgList2, enepUuid2, inepUuid2, nodeUuid);
498                 break;
499             case "tpdr":
500                 assertEquals("Tpdr-OTSi node should have 2 eNEPs", 2, nepsE.size());
501                 assertEquals("Tpdr-OTSi node should have 2 iNEPs", 2, nepsI.size());
502                 OwnedNodeEdgePoint nep5 = nepsE.get(0);
503                 Uuid enepUuid3 = new Uuid(
504                         UUID.nameUUIDFromBytes((nodeId + "+eOTSi+XPDR1-NETWORK1").getBytes(Charset.forName("UTF-8")))
505                         .toString());
506                 checkNepOtsiNode(nep5, enepUuid3, "XPDR1-NETWORK1", "eNodeEdgePoint");
507                 OwnedNodeEdgePoint nep6 = nepsI.get(0);
508                 Uuid inepUuid3 = new Uuid(
509                         UUID.nameUUIDFromBytes((nodeId + "+iOTSi+XPDR1-NETWORK1").getBytes(Charset.forName("UTF-8")))
510                         .toString());
511                 checkNepOtsiNode(nep6, inepUuid3, "XPDR1-NETWORK1", "iNodeEdgePoint");
512                 List<NodeRuleGroup> nrgList3 = node.nonnullNodeRuleGroup().values().stream()
513                     .sorted((nrg1, nrg2) -> nrg1.getUuid().getValue().compareTo(nrg2.getUuid().getValue()))
514                     .collect(Collectors.toList());
515                 checkNodeRuleGroupForTpdrOTSi(nrgList3, enepUuid3, inepUuid3, nodeUuid);
516                 break;
517             default:
518                 Iterator<OwnedNodeEdgePoint> nepIterator = node.nonnullOwnedNodeEdgePoint().values().iterator();
519                 int count = 1;
520                 while (nepIterator.hasNext()) {
521                     OwnedNodeEdgePoint nep = nepIterator.next();
522                     Uuid nepUuid = new Uuid(
523                         UUID.nameUUIDFromBytes((String.join("+", "roadm node", "nep", String.valueOf(count)))
524                             .getBytes(Charset.forName("UTF-8"))).toString());
525                     checkNepOtsiRdmNode(nep, nepUuid, new StringBuilder("NodeEdgePoint_").append(count).toString(),
526                         "NodeEdgePoint name");
527                     count++;
528                 }
529                 List<NodeRuleGroup> nrgList4 = node.nonnullNodeRuleGroup().values().stream()
530                     .sorted((nrg1, nrg2) -> nrg1.getUuid().getValue().compareTo(nrg2.getUuid().getValue()))
531                     .collect(Collectors.toList());
532                 checkNodeRuleGroupForRdmInfra(nrgList4, count - 1);
533                 break;
534         }
535     }
536
537     private void checkNepClient10G(OwnedNodeEdgePoint nep, Uuid nepUuid, String portName, String nepName) {
538         assertEquals("bad uuid for " + portName, nepUuid, nep.getUuid());
539         List<Name> nameList = new ArrayList<>(nep.nonnullName().values());
540         Name name = nameList.get(0);
541         assertEquals("value of client nep should be '" + portName + "'",
542             portName, name.getValue());
543         assertEquals("value-name of client nep for '" + portName + "' should be '" + nepName + "'",
544             nepName, name.getValueName());
545         assertEquals("Client nep should support 2 kind of cep",
546             2, nep.getSupportedCepLayerProtocolQualifier().size());
547         assertThat("client nep should support 2 kind of cep",
548             nep.getSupportedCepLayerProtocolQualifier(),
549             hasItems(ODUTYPEODU2E.class, DIGITALSIGNALTYPE10GigELAN.class));
550         assertEquals("client nep should be of ETH protocol type", LayerProtocolName.ETH, nep.getLayerProtocolName());
551         checkCommonPartOfNep(nep, false);
552     }
553
554     private void checkNepNetworkODU4(OwnedNodeEdgePoint nep, Uuid nepUuid, String portName, String nepName) {
555         assertEquals("bad uuid for " + portName, nepUuid, nep.getUuid());
556         List<Name> nameList = new ArrayList<>(nep.nonnullName().values());
557         Name name = nameList.get(0);
558         assertEquals("value of network nep should be '" + portName + "'",
559             portName, name.getValue());
560         assertEquals("value-name of client nep for '" + portName + "' should be '" + nepName + "'",
561             nepName, name.getValueName());
562         assertEquals("Network nep should support 1 kind of cep",
563             1, nep.getSupportedCepLayerProtocolQualifier().size());
564         assertThat("network nep should support 1 kind of cep",
565             nep.getSupportedCepLayerProtocolQualifier(),
566             hasItem(ODUTYPEODU4.class));
567         assertEquals("network nep should be of ODU protocol type", LayerProtocolName.ODU, nep.getLayerProtocolName());
568         checkCommonPartOfNep(nep, false);
569     }
570
571     private void checkNodeRuleGroupForTpdrDSR(List<NodeRuleGroup> nrgList, Uuid clientNepUuid, Uuid networkNepUuid,
572         Uuid nodeUuid) {
573         assertEquals("transponder DSR should contain 2 node rule group", 2, nrgList.size());
574         for (NodeRuleGroup nodeRuleGroup : nrgList) {
575             assertEquals("each node-rule-group should contain 2 NEP for transponder DSR",
576                 2, nodeRuleGroup.getNodeEdgePoint().size());
577         }
578         List<NodeEdgePoint> nodeEdgePointList = new ArrayList<>(nrgList.get(0).nonnullNodeEdgePoint().values());
579         assertThat("node-rule-group nb 1 should be between nep-client1 and nep-network1",
580             nodeEdgePointList.get(0).getNodeEdgePointUuid().getValue(),
581             either(containsString(networkNepUuid.getValue())).or(containsString(clientNepUuid.getValue())));
582         assertThat("node-rule-group nb 1 should be between nep-client1 and nep-network1",
583             nodeEdgePointList.get(1).getNodeEdgePointUuid().getValue(),
584             either(containsString(networkNepUuid.getValue())).or(containsString(clientNepUuid.getValue())));
585         assertEquals("node-rule-group nb 1 should be between nep-client1 and nep-network1 of the same node",
586             nodeEdgePointList.get(0).getNodeUuid(), nodeUuid);
587         assertEquals("node-rule-group nb 1 should be between nep-client1 and nep-network1 of the same node",
588             nodeEdgePointList.get(1).getNodeUuid(), nodeUuid);
589         List<Rule> rule = new ArrayList<>(nrgList.get(1).nonnullRule().values());
590         assertEquals("node-rule-group nb 1 should contain a single rule", 1, rule.size());
591         assertEquals("local-id of the rule should be 'forward'",
592             "forward", rule.get(0).getLocalId());
593         assertEquals("the forwarding rule should be 'MAYFORWARDACROSSGROUP'",
594             ForwardingRule.MAYFORWARDACROSSGROUP, rule.get(0).getForwardingRule());
595         assertEquals("the rule type should be 'FORWARDING'",
596             RuleType.FORWARDING, rule.get(0).getRuleType());
597     }
598
599     private void checkNodeRuleGroupForMuxDSR(List<NodeRuleGroup> nrgList, Uuid clientNepUuid, Uuid networkNepUuid,
600         Uuid nodeUuid) {
601         assertEquals("muxponder DSR should contain 4 node rule group", 4, nrgList.size());
602         for (NodeRuleGroup nodeRuleGroup : nrgList) {
603             assertEquals("each node-rule-group should contain 2 NEP for muxponder DSR",
604                 2, nodeRuleGroup.getNodeEdgePoint().size());
605         }
606         List<NodeEdgePoint> nodeEdgePointList = new ArrayList<>(nrgList.get(0).nonnullNodeEdgePoint().values());
607         assertThat("node-rule-group nb 2 should be between nep-client4 and nep-network1",
608             nodeEdgePointList.get(1).getNodeEdgePointUuid().getValue(),
609             either(containsString(networkNepUuid.getValue())).or(containsString(clientNepUuid.getValue())));
610         assertThat("node-rule-group nb 2 should be between nep-client4 and nep-network1",
611             nodeEdgePointList.get(1).getNodeEdgePointUuid().getValue(),
612             either(containsString(networkNepUuid.getValue())).or(containsString(clientNepUuid.getValue())));
613         assertEquals("node-rule-group nb 2 should be between nep-client4 and nep-network1 of the same node",
614             nodeEdgePointList.get(0).getNodeUuid(), nodeUuid);
615         assertEquals("node-rule-group nb 2 should be between nep-client4 and nep-network1 of the same node",
616             nodeEdgePointList.get(1).getNodeUuid(), nodeUuid);
617         List<Rule> rule = new ArrayList<>(nrgList.get(1).nonnullRule().values());
618         assertEquals("node-rule-group nb 2 should contain a single rule", 1, rule.size());
619         assertEquals("local-id of the rule should be 'forward'",
620             "forward", rule.get(0).getLocalId());
621         assertEquals("the forwarding rule should be 'MAYFORWARDACROSSGROUP'",
622             ForwardingRule.MAYFORWARDACROSSGROUP, rule.get(0).getForwardingRule());
623         assertEquals("the rule type should be 'FORWARDING'",
624             RuleType.FORWARDING, rule.get(0).getRuleType());
625     }
626
627     private void checkNodeRuleGroupForSwitchDSR(List<NodeRuleGroup> nrgList, Uuid clientNepUuid, Uuid networkNepUuid,
628         Uuid nodeUuid) {
629         assertEquals("Switch-DSR should contain a single node rule group", 1, nrgList.size());
630         assertEquals("Switch-DSR node-rule-group should contain 8 NEP", 8, nrgList.get(0).getNodeEdgePoint().size());
631         List<NodeEdgePoint> nrg = nrgList.get(0).nonnullNodeEdgePoint().values().stream()
632             .sorted((nrg1, nrg2) -> nrg1.getNodeEdgePointUuid().getValue()
633                 .compareTo(nrg2.getNodeEdgePointUuid().getValue()))
634             .collect(Collectors.toList());
635         assertEquals("in the sorted node-rule-group, nep number 2 should be XPDR2-NETWORK1",
636             networkNepUuid, nrg.get(4).getNodeEdgePointUuid());
637         assertEquals("in the sorted node-rule-group, nep number 6 should be XPDR2-CLIENT4",
638             clientNepUuid, nrg.get(3).getNodeEdgePointUuid());
639         assertEquals("any item of the node-rule-group should have the same nodeUuid",
640             nodeUuid, nrg.get(4).getNodeUuid());
641         assertEquals("any item of the node-rule-group should have the same nodeUuid",
642             nodeUuid, nrg.get(3).getNodeUuid());
643         @Nullable
644         List<Rule> ruleList = new ArrayList<>(nrgList.get(0).nonnullRule().values());
645         assertEquals("node-rule-group should contain a single rule", 1, ruleList.size());
646         assertEquals("local-id of the rule should be 'forward'",
647             "forward", ruleList.get(0).getLocalId());
648         assertEquals("the forwarding rule should be 'MAYFORWARDACROSSGROUP'",
649             ForwardingRule.MAYFORWARDACROSSGROUP, ruleList.get(0).getForwardingRule());
650         assertEquals("the rule type should be 'FORWARDING'",
651             RuleType.FORWARDING, ruleList.get(0).getRuleType());
652     }
653
654     private void checkNodeRuleGroupForRdmInfra(List<NodeRuleGroup> nrgList, int nbNeps) {
655         assertEquals("RDM infra node - OTSi should contain a single node rule groups", 1, nrgList.size());
656         if (nbNeps > 0) {
657             List<NodeEdgePoint> nodeEdgePointList = new ArrayList<>(nrgList.get(0).getNodeEdgePoint().values());
658             assertEquals("RDM infra node -rule-group should contain " + nbNeps + " NEP",
659                 nbNeps, nodeEdgePointList.size());
660         } else {
661             assertNull("RDM infra node -rule-group should contain no NEP", nrgList.get(0).getNodeEdgePoint());
662         }
663         List<Rule> ruleList = new ArrayList<>(nrgList.get(0).nonnullRule().values());
664         assertEquals("node-rule-group should contain a single rule", 1, ruleList.size());
665         assertEquals("local-id of the rule should be 'forward'",
666             "forward", ruleList.get(0).getLocalId());
667         assertEquals("the forwarding rule should be 'MAYFORWARDACROSSGROUP'",
668             ForwardingRule.MAYFORWARDACROSSGROUP, ruleList.get(0).getForwardingRule());
669         assertEquals("the rule type should be 'FORWARDING'",
670             RuleType.FORWARDING, ruleList.get(0).getRuleType());
671     }
672
673     private void checkNodeRuleGroupForTpdrOTSi(List<NodeRuleGroup> nrgList, Uuid enepUuid, Uuid inepUuid,
674         Uuid nodeUuid) {
675         assertEquals("Tpdr-OTSi should contain two node rule groups", 2, nrgList.size());
676         List<NodeEdgePoint> nodeEdgePointList = new ArrayList<>(nrgList.get(0).getNodeEdgePoint().values());
677         assertEquals("Tpdr-OTSi node-rule-group should contain 2 NEP", 2, nodeEdgePointList.size());
678         assertThat("Tpdr-OTSi node-rule-group should be between eNEP and iNEP of XPDR1-NETWORK1",
679             nodeEdgePointList.get(0).getNodeEdgePointUuid().getValue(),
680             either(containsString(enepUuid.getValue())).or(containsString(inepUuid.getValue())));
681         assertThat("Tpdr-OTSi node-rule-group should be between eNEP and iNEP of XPDR1-NETWORK1",
682             nodeEdgePointList.get(1).getNodeEdgePointUuid().getValue(),
683             either(containsString(enepUuid.getValue())).or(containsString(inepUuid.getValue())));
684         assertEquals("any item of the node-rule-group should have the same nodeUuid",
685             nodeUuid, nodeEdgePointList.get(0).getNodeUuid());
686         assertEquals("any item of the node-rule-group should have the same nodeUuid",
687             nodeUuid, nodeEdgePointList.get(1).getNodeUuid());
688         List<Rule> ruleList = new ArrayList<>(nrgList.get(0).nonnullRule().values());
689         assertEquals("node-rule-group should contain a single rule", 1, ruleList.size());
690         assertEquals("local-id of the rule should be 'forward'",
691             "forward", ruleList.get(0).getLocalId());
692         assertEquals("the forwarding rule should be 'MAYFORWARDACROSSGROUP'",
693             ForwardingRule.MAYFORWARDACROSSGROUP, ruleList.get(0).getForwardingRule());
694         assertEquals("the rule type should be 'FORWARDING'",
695             RuleType.FORWARDING, ruleList.get(0).getRuleType());
696     }
697
698     private void checkNodeRuleGroupForMuxOTSi(List<NodeRuleGroup> nrgList, Uuid enepUuid, Uuid inepUuid,
699         Uuid nodeUuid) {
700         assertEquals("Mux-OTSi should contain a single node rule group", 1, nrgList.size());
701         List<NodeEdgePoint> nodeEdgePointList = new ArrayList<>(nrgList.get(0).getNodeEdgePoint().values());
702         assertEquals("Mux-OTSi node-rule-group should contain 2 NEP", 2, nodeEdgePointList.size());
703         assertThat("Mux-OTSi node-rule-group should be between eNEP and iNEP of XPDR1-NETWORK1",
704             nodeEdgePointList.get(0).getNodeEdgePointUuid().getValue(),
705             either(containsString(enepUuid.getValue())).or(containsString(inepUuid.getValue())));
706         assertThat("Mux-OTSi node-rule-group should be between eNEP and iNEP of XPDR1-NETWORK1",
707             nodeEdgePointList.get(1).getNodeEdgePointUuid().getValue(),
708             either(containsString(enepUuid.getValue())).or(containsString(inepUuid.getValue())));
709         assertEquals("any item of the node-rule-group should have the same nodeUuid",
710             nodeUuid, nodeEdgePointList.get(0).getNodeUuid());
711         assertEquals("any item of the node-rule-group should have the same nodeUuid",
712             nodeUuid, nodeEdgePointList.get(1).getNodeUuid());
713         List<Rule> ruleList = new ArrayList<>(nrgList.get(0).nonnullRule().values());
714         assertEquals("node-rule-group should contain a single rule", 1, ruleList.size());
715         assertEquals("local-id of the rule should be 'forward'",
716             "forward", ruleList.get(0).getLocalId());
717         assertEquals("the forwarding rule should be 'MAYFORWARDACROSSGROUP'",
718             ForwardingRule.MAYFORWARDACROSSGROUP, ruleList.get(0).getForwardingRule());
719         assertEquals("the rule type should be 'FORWARDING'",
720             RuleType.FORWARDING, ruleList.get(0).getRuleType());
721     }
722
723     private void checkNodeRuleGroupForSwitchOTSi(List<NodeRuleGroup> nrgList, Uuid enepUuid, Uuid inepUuid,
724         Uuid nodeUuid) {
725         assertEquals("Switch-OTSi should contain 4 node rule group", 4, nrgList.size());
726         for (NodeRuleGroup nodeRuleGroup : nrgList) {
727             assertEquals("each node-rule-group should contain 2 NEP for Switch-OTSi",
728                 2, nodeRuleGroup.getNodeEdgePoint().size());
729         }
730         List<NodeEdgePoint> nodeEdgePointList1 = new ArrayList<>(nrgList.get(3).nonnullNodeEdgePoint().values());
731         assertThat("Switch-OTSi node-rule-group nb 4 should be between eNEP and iNEP of XPDR2-NETWORK2",
732             nodeEdgePointList1.get(0).getNodeEdgePointUuid().getValue(),
733             either(containsString(enepUuid.getValue())).or(containsString(inepUuid.getValue())));
734         assertThat("Switch-OTSi node-rule-group nb 4 should be between eNEP and iNEP of XPDR2-NETWORK2",
735             nodeEdgePointList1.get(1).getNodeEdgePointUuid().getValue(),
736             either(containsString(enepUuid.getValue())).or(containsString(inepUuid.getValue())));
737         List<NodeEdgePoint> nodeEdgePointList0 = new ArrayList<>(nrgList.get(0).getNodeEdgePoint().values());
738         assertEquals("any item of the node-rule-group should have the same nodeUuid",
739             nodeUuid, nodeEdgePointList0.get(0).getNodeUuid());
740         assertEquals("any item of the node-rule-group should have the same nodeUuid",
741             nodeUuid, nodeEdgePointList0.get(1).getNodeUuid());
742         List<Rule> ruleList0 = new ArrayList<>(nrgList.get(0).nonnullRule().values());
743         assertEquals("node-rule-group should contain a single rule", 1, ruleList0.size());
744         assertEquals("local-id of the rule should be 'forward'",
745             "forward", ruleList0.get(0).getLocalId());
746         assertEquals("the forwarding rule should be 'MAYFORWARDACROSSGROUP'",
747             ForwardingRule.MAYFORWARDACROSSGROUP, ruleList0.get(0).getForwardingRule());
748         assertEquals("the rule type should be 'FORWARDING'",
749             RuleType.FORWARDING, ruleList0.get(0).getRuleType());
750     }
751
752     private void checkNepClient100GSwitch(OwnedNodeEdgePoint nep, Uuid nepUuid, String portName, String nepName) {
753         assertEquals("bad uuid for " + portName, nepUuid, nep.getUuid());
754         List<Name> nameList = new ArrayList<>(nep.nonnullName().values());
755         assertEquals("value of client nep should be '" + portName + "'",
756             portName, nameList.get(0).getValue());
757         assertEquals("value-name of client nep for '" + portName + "' should be '" + nepName + "'",
758             nepName, nameList.get(0).getValueName());
759         assertEquals("Client nep should support 2 kind of cep",
760             2, nep.getSupportedCepLayerProtocolQualifier().size());
761         assertThat("client nep should support 2 kind of cep",
762             nep.getSupportedCepLayerProtocolQualifier(),
763             hasItems(ODUTYPEODU4.class, DIGITALSIGNALTYPE100GigE.class));
764         assertEquals("client nep should be of ETH protocol type", LayerProtocolName.ETH, nep.getLayerProtocolName());
765         checkCommonPartOfNep(nep, false);
766     }
767
768     private void checkNepClient100GTpdr(OwnedNodeEdgePoint nep, Uuid nepUuid, String portName, String nepName) {
769         assertEquals("bad uuid for " + portName, nepUuid, nep.getUuid());
770         List<Name> nameList = new ArrayList<>(nep.nonnullName().values());
771         assertEquals("value of client nep should be '" + portName + "'",
772             portName, nameList.get(0).getValue());
773         assertEquals("value-name of client nep for '" + portName + "' should be 100G-tpdr'",
774             nepName, nameList.get(0).getValueName());
775         assertEquals("Client nep should support 1 kind of cep",
776             1, nep.getSupportedCepLayerProtocolQualifier().size());
777         assertThat("client nep should support 2 kind of cep",
778             nep.getSupportedCepLayerProtocolQualifier(),
779             hasItems(DIGITALSIGNALTYPE100GigE.class));
780         assertEquals("client nep should be of ETH protocol type", LayerProtocolName.ETH, nep.getLayerProtocolName());
781         checkCommonPartOfNep(nep, false);
782     }
783
784     private void checkNepOtsiNode(OwnedNodeEdgePoint nep, Uuid nepUuid, String portName, String nepName) {
785         assertEquals("bad uuid for " + portName, nepUuid, nep.getUuid());
786         List<Name> nameList = new ArrayList<>(nep.nonnullName().values());
787         assertEquals("value of OTSi nep should be '" + portName + "'",
788             portName, nameList.get(0).getValue());
789         assertEquals("value-name of OTSi nep should be '" + nepName + "'",
790             nepName, nameList.get(0).getValueName());
791         assertEquals("OTSi nep should support 2 kind of cep",
792             2, nep.getSupportedCepLayerProtocolQualifier().size());
793         assertThat("OTSi nep should support 2 kind of cep",
794             nep.getSupportedCepLayerProtocolQualifier(),
795             hasItems(PHOTONICLAYERQUALIFIEROMS.class, PHOTONICLAYERQUALIFIEROTSi.class));
796         assertEquals("OTSi nep should be of PHOTONIC_MEDIA protocol type",
797             LayerProtocolName.PHOTONICMEDIA, nep.getLayerProtocolName());
798         assertEquals("OTSi nep should support one SIP", 1, nep.getMappedServiceInterfacePoint().size());
799         checkCommonPartOfNep(nep, false);
800     }
801
802     private void checkNepOtsiRdmNode(OwnedNodeEdgePoint nep, Uuid nepUuid, String portName, String nepName) {
803         assertEquals("bad uuid for " + portName, nepUuid, nep.getUuid());
804         List<Name> nameList = new ArrayList<>(nep.nonnullName().values());
805         assertEquals("value of OTSi nep should be '" + portName + "'",
806             portName, nameList.get(0).getValue());
807         assertEquals("value-name of OTSi nep should be '" + nepName + "'",
808             nepName, nameList.get(0).getValueName());
809         assertEquals("OTSi nep of RDM infra node should support only 1 kind of cep",
810             1, nep.getSupportedCepLayerProtocolQualifier().size());
811         assertThat("OTSi nep should support 2 kind of cep",
812             nep.getSupportedCepLayerProtocolQualifier(),
813             hasItems(PHOTONICLAYERQUALIFIEROMS.class));
814         assertEquals("OTSi nep should be of PHOTONIC_MEDIA protocol type",
815             LayerProtocolName.PHOTONICMEDIA, nep.getLayerProtocolName());
816         assertEquals("OTSi nep of RDM infra should support no SIP", 0, nep.nonnullMappedServiceInterfacePoint().size());
817         checkCommonPartOfNep(nep, true);
818     }
819
820     private void checkCommonPartOfNep(OwnedNodeEdgePoint nep, boolean isRdm) {
821         assertEquals("link port direction should be DIRECTIONAL",
822             PortDirection.BIDIRECTIONAL, nep.getLinkPortDirection());
823         assertEquals("administrative state should be UNLOCKED",
824             AdministrativeState.UNLOCKED, nep.getAdministrativeState());
825         assertEquals("termination state should be TERMINATED BIDIRECTIONAL",
826             TerminationState.TERMINATEDBIDIRECTIONAL, nep.getTerminationState());
827         assertEquals("life-cycle state should be INSTALLED", LifecycleState.INSTALLED, nep.getLifecycleState());
828         if (!isRdm) {
829             assertEquals("client nep should support 1 SIP", 1, nep.getMappedServiceInterfacePoint().size());
830         }
831         assertEquals("termination direction should be BIDIRECTIONAL",
832             TerminationDirection.BIDIRECTIONAL, nep.getTerminationDirection());
833         assertEquals("operational state of client nep should be ENABLED",
834             OperationalState.ENABLED, nep.getOperationalState());
835         assertEquals("link-port-role of client nep should be SYMMETRIC",
836             PortRole.SYMMETRIC, nep.getLinkPortRole());
837     }
838
839     private void checkTransitionalLink(Link link, Uuid node1Uuid, Uuid node2Uuid, String tp1, String tp2,
840         String ietfNodeId) {
841         Uuid linkUuid = new Uuid(UUID.nameUUIDFromBytes((ietfNodeId + "--" + tp1 + "--" + tp2)
842             .getBytes(Charset.forName("UTF-8"))).toString());
843         assertEquals("bad uuid for link between DSR node " + tp1 + " and iOTSI port " + tp2, linkUuid, link.getUuid());
844         assertEquals("Available capacity unit should be GBPS",
845             CapacityUnit.GBPS, link.getAvailableCapacity().getTotalSize().getUnit());
846         assertEquals("Available capacity -total size value should be 100",
847             Uint64.valueOf(100), link.getAvailableCapacity().getTotalSize().getValue());
848         assertEquals("transitional link should be between 2 nodes of protocol layers ODU and PHOTONIC_MEDIA",
849             2, link.getTransitionedLayerProtocolName().size());
850         assertThat("transitional link should be between 2 nodes of protocol layers ODU and PHOTONIC_MEDIA",
851             link.getTransitionedLayerProtocolName(),
852             hasItems(LayerProtocolName.ODU.getName(), LayerProtocolName.PHOTONICMEDIA.getName()));
853         assertEquals("transitional link should be BIDIRECTIONAL",
854             ForwardingDirection.BIDIRECTIONAL, link.getDirection());
855         List<org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210
856             .link.NodeEdgePoint> nodeEdgePointList = new ArrayList<>(link.nonnullNodeEdgePoint().values());
857         assertEquals("topology uuid should be the same for the two termination point of the link",
858             topologyUuid, nodeEdgePointList.get(0).getTopologyUuid());
859         assertEquals("topology uuid should be the same for the two termination point of the link",
860             topologyUuid, nodeEdgePointList.get(1).getTopologyUuid());
861         assertThat("transitional links should terminate on DSR node and Photonic node",
862             nodeEdgePointList.get(0).getNodeUuid().getValue(),
863             either(containsString(node1Uuid.getValue())).or(containsString(node2Uuid.getValue())));
864         assertThat("transitional links should terminate on DSR node and Photonic node",
865             nodeEdgePointList.get(1).getNodeUuid().getValue(),
866             either(containsString(node1Uuid.getValue())).or(containsString(node2Uuid.getValue())));
867         Uuid nep1Uuid = new Uuid(UUID.nameUUIDFromBytes(tp1.getBytes(Charset.forName("UTF-8"))).toString());
868         Uuid nep2Uuid = new Uuid(UUID.nameUUIDFromBytes(tp2.getBytes(Charset.forName("UTF-8"))).toString());
869         assertThat("transitional links should terminate on " + tp1 + " and " + tp2 + " neps",
870             nodeEdgePointList.get(0).getNodeEdgePointUuid().getValue(),
871             either(containsString(nep1Uuid.getValue())).or(containsString(nep2Uuid.getValue())));
872         assertThat("transitional links should terminate on DSR node and Photonic node",
873             nodeEdgePointList.get(1).getNodeEdgePointUuid().getValue(),
874             either(containsString(nep1Uuid.getValue())).or(containsString(nep2Uuid.getValue())));
875     }
876
877     private void checkOtnLink(Link link, Uuid node1Uuid, Uuid node2Uuid, Uuid tp1Uuid, Uuid tp2Uuid, Uuid linkUuid,
878         String linkName) {
879         assertEquals("bad name for the link", linkName, link.getName().get(new NameKey("otn link name")).getValue());
880         assertEquals("bad uuid for link", linkUuid, link.getUuid());
881         assertEquals("Available capacity unit should be MBPS",
882             CapacityUnit.MBPS, link.getAvailableCapacity().getTotalSize().getUnit());
883         String prefix = linkName.split("-")[0];
884         if ("OTU4".equals(prefix)) {
885             assertEquals("Available capacity -total size value should be 0",
886                 Uint64.valueOf(0), link.getAvailableCapacity().getTotalSize().getValue());
887         } else if ("ODU4".equals(prefix)) {
888             assertEquals("Available capacity -total size value should be 100 000",
889                 Uint64.valueOf(100000), link.getAvailableCapacity().getTotalSize().getValue());
890         }
891         assertEquals("Total capacity unit should be GBPS",
892             CapacityUnit.GBPS, link.getTotalPotentialCapacity().getTotalSize().getUnit());
893         assertEquals("Total capacity -total size value should be 100",
894             Uint64.valueOf(100), link.getTotalPotentialCapacity().getTotalSize().getValue());
895         if ("OTU4".equals(prefix)) {
896             assertEquals("otn link should be between 2 nodes of protocol layers PHOTONIC_MEDIA",
897                 LayerProtocolName.PHOTONICMEDIA.getName(), link.getLayerProtocolName().get(0).getName());
898         } else if ("ODU4".equals(prefix)) {
899             assertEquals("otn link should be between 2 nodes of protocol layers ODU",
900                 LayerProtocolName.ODU.getName(), link.getLayerProtocolName().get(0).getName());
901         }
902         assertEquals("otn tapi link should be BIDIRECTIONAL",
903             ForwardingDirection.BIDIRECTIONAL, link.getDirection());
904         List<org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210
905             .link.NodeEdgePoint> nodeEdgePointList = new ArrayList<>(link.nonnullNodeEdgePoint().values());
906         assertEquals("topology uuid should be the same for the two termination point of the link",
907             topologyUuid, nodeEdgePointList.get(0).getTopologyUuid());
908         assertEquals("topology uuid should be the same for the two termination point of the link",
909             topologyUuid, nodeEdgePointList.get(1).getTopologyUuid());
910         assertThat("otn links should terminate on two distinct nodes",
911             nodeEdgePointList.get(0).getNodeUuid().getValue(),
912             either(containsString(node1Uuid.getValue())).or(containsString(node2Uuid.getValue())));
913         assertThat("otn links should terminate on two distinct nodes",
914             nodeEdgePointList.get(1).getNodeUuid().getValue(),
915             either(containsString(node1Uuid.getValue())).or(containsString(node2Uuid.getValue())));
916         assertThat("otn links should terminate on two distinct tps",
917             nodeEdgePointList.get(0).getNodeEdgePointUuid().getValue(),
918             either(containsString(tp1Uuid.getValue())).or(containsString(tp2Uuid.getValue())));
919         assertThat("otn links should terminate on two distinct tps",
920             nodeEdgePointList.get(1).getNodeEdgePointUuid().getValue(),
921             either(containsString(tp1Uuid.getValue())).or(containsString(tp2Uuid.getValue())));
922         assertEquals("operational state should be ENABLED",
923             OperationalState.ENABLED, link.getOperationalState());
924         assertEquals("administrative state should be UNLOCKED",
925             AdministrativeState.UNLOCKED, link.getAdministrativeState());
926     }
927
928     private void checkOmsLink(Link link, Uuid node1Uuid, Uuid node2Uuid, Uuid tp1Uuid, Uuid tp2Uuid, Uuid linkUuid,
929         String linkName) {
930         assertEquals("bad name for the link", linkName, link.getName().get(new NameKey("OMS link name")).getValue());
931         assertEquals("bad uuid for link", linkUuid, link.getUuid());
932         assertEquals("oms link should be between 2 nodes of protocol layers PHOTONIC_MEDIA",
933             LayerProtocolName.PHOTONICMEDIA.getName(), link.getLayerProtocolName().get(0).getName());
934         assertEquals("otn tapi link should be BIDIRECTIONAL",
935             ForwardingDirection.BIDIRECTIONAL, link.getDirection());
936         List<org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210
937             .link.NodeEdgePoint> nodeEdgePointList = new ArrayList<>(link.nonnullNodeEdgePoint().values());
938         assertEquals("oms link should be between 2 neps",2 , nodeEdgePointList.size());
939         assertEquals("topology uuid should be the same for the two termination point of the link",
940             topologyUuid, nodeEdgePointList.get(0).getTopologyUuid());
941         assertEquals("topology uuid should be the same for the two termination point of the link",
942             topologyUuid, nodeEdgePointList.get(1).getTopologyUuid());
943         assertThat("oms links should terminate on two distinct nodes",
944             nodeEdgePointList.get(0).getNodeUuid().getValue(),
945             either(containsString(node1Uuid.getValue())).or(containsString(node2Uuid.getValue())));
946         assertThat("oms links should terminate on two distinct nodes",
947             nodeEdgePointList.get(1).getNodeUuid().getValue(),
948             either(containsString(node1Uuid.getValue())).or(containsString(node2Uuid.getValue())));
949         assertThat("oms links should terminate on two distinct tps",
950             nodeEdgePointList.get(0).getNodeEdgePointUuid().getValue(),
951             either(containsString(tp1Uuid.getValue())).or(containsString(tp2Uuid.getValue())));
952         assertThat("oms links should terminate on two distinct tps",
953             nodeEdgePointList.get(1).getNodeEdgePointUuid().getValue(),
954             either(containsString(tp1Uuid.getValue())).or(containsString(tp2Uuid.getValue())));
955     }
956
957 }