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