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