Add OTN links support in TAPI topology
[transportpce.git] / tapi / src / test / java / org / opendaylight / transportpce / tapi / topology / TapiTopologyImplTest.java
1 /*
2  * Copyright © 2019 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.assertNotNull;
17
18 import com.google.common.util.concurrent.ListenableFuture;
19 import com.google.common.util.concurrent.ListeningExecutorService;
20 import com.google.common.util.concurrent.MoreExecutors;
21 import java.nio.charset.Charset;
22 import java.util.ArrayList;
23 import java.util.List;
24 import java.util.UUID;
25 import java.util.concurrent.CountDownLatch;
26 import java.util.concurrent.ExecutionException;
27 import java.util.concurrent.Executors;
28 import java.util.stream.Collectors;
29 import org.eclipse.jdt.annotation.Nullable;
30 import org.junit.Before;
31 import org.junit.Test;
32 import org.opendaylight.transportpce.common.InstanceIdentifiers;
33 import org.opendaylight.transportpce.common.NetworkUtils;
34 import org.opendaylight.transportpce.tapi.utils.TopologyDataUtils;
35 import org.opendaylight.transportpce.test.AbstractTest;
36 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.AdministrativeState;
37 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.CapacityUnit;
38 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.ForwardingDirection;
39 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.LayerProtocolName;
40 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.LifecycleState;
41 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.OperationalState;
42 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.PortDirection;
43 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.PortRole;
44 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.TerminationDirection;
45 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.TerminationState;
46 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.Uuid;
47 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.global._class.Name;
48 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.global._class.NameKey;
49 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.dsr.rev181210.DIGITALSIGNALTYPE100GigE;
50 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.dsr.rev181210.DIGITALSIGNALTYPE10GigELAN;
51 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.odu.rev181210.ODUTYPEODU2E;
52 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.odu.rev181210.ODUTYPEODU4;
53 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.photonic.media.rev181210.PHOTONICLAYERQUALIFIEROMS;
54 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.photonic.media.rev181210.PHOTONICLAYERQUALIFIEROTSi;
55 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.ForwardingRule;
56 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.GetTopologyDetailsInput;
57 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.GetTopologyDetailsOutput;
58 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.RuleType;
59 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.get.topology.details.output.Topology;
60 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.node.NodeRuleGroup;
61 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.node.OwnedNodeEdgePoint;
62 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.node.rule.group.NodeEdgePoint;
63 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.node.rule.group.Rule;
64 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.topology.Link;
65 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.topology.Node;
66 import org.opendaylight.yangtools.yang.common.RpcResult;
67 import org.opendaylight.yangtools.yang.common.Uint64;
68 import org.slf4j.Logger;
69 import org.slf4j.LoggerFactory;
70
71 public class TapiTopologyImplTest extends AbstractTest {
72     private static final Logger LOG = LoggerFactory.getLogger(TapiTopologyImplTest.class);
73
74     private static ListeningExecutorService executorService;
75     private static CountDownLatch endSignal;
76     private static final int NUM_THREADS = 3;
77
78     @Before
79     public void setUp() throws InterruptedException, ExecutionException {
80         executorService = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(NUM_THREADS));
81         endSignal = new CountDownLatch(1);
82         TopologyDataUtils.writeTopologyFromFileToDatastore(getDataStoreContextUtil(),
83             TopologyDataUtils.OPENROADM_TOPOLOGY_FILE, InstanceIdentifiers.OVERLAY_NETWORK_II);
84         TopologyDataUtils.writeTopologyFromFileToDatastore(getDataStoreContextUtil(),
85             TopologyDataUtils.OTN_TOPOLOGY_FILE, InstanceIdentifiers.OTN_NETWORK_II);
86         TopologyDataUtils.writePortmappingFromFileToDatastore(getDataStoreContextUtil());
87         LOG.info("setup done");
88     }
89
90     @Test
91     public void getTopologyDetailsForOpenroadmTopologyWhenSuccessful() throws ExecutionException, InterruptedException {
92         GetTopologyDetailsInput input = TopologyDataUtils.buildGetTopologyDetailsInput(NetworkUtils.OVERLAY_NETWORK_ID);
93         TapiTopologyImpl tapiTopoImpl = new TapiTopologyImpl(getDataBroker());
94         ListenableFuture<RpcResult<GetTopologyDetailsOutput>> result = tapiTopoImpl.getTopologyDetails(input);
95         result.addListener(new Runnable() {
96             @Override
97             public void run() {
98                 endSignal.countDown();
99             }
100         }, executorService);
101         endSignal.await();
102         RpcResult<GetTopologyDetailsOutput> rpcResult = result.get();
103         @Nullable
104         Topology topology = rpcResult.getResult().getTopology();
105         assertNotNull("Topology should not be null", topology);
106         assertEquals("Nodes list size should be 1", 1, topology.getNode().size());
107         List<Node> topologyNodeList = new ArrayList<>(topology.nonnullNode().values());
108         List<Node> nodeList = new ArrayList<>(topologyNodeList);
109         List<Name> nameList = new ArrayList<>(nodeList.get(0).nonnullName().values());
110         assertEquals("Node name should be TAPI Ethernet Node",
111             "TAPI Ethernet Node", nameList.get(0).getValue());
112         Uuid topoUuid = new Uuid(UUID.nameUUIDFromBytes("Ethernet Topology".getBytes()).toString());
113         Uuid nodeUuid = new Uuid(UUID.nameUUIDFromBytes("TAPI Ethernet Node".getBytes()).toString());
114         assertEquals("incorrect topology uuid", topoUuid, topology.getUuid());
115         assertEquals("incorrect node uuid", nodeUuid, topologyNodeList.get(0).getUuid());
116         Uuid onep1Uuid = new Uuid(UUID.nameUUIDFromBytes("OwnedNodeEdgePoint 0".getBytes()).toString());
117         Uuid onep2Uuid = new Uuid(UUID.nameUUIDFromBytes("OwnedNodeEdgePoint 1".getBytes()).toString());
118         List<OwnedNodeEdgePoint> edgePointList = new ArrayList<>(topologyNodeList.get(0)
119                 .nonnullOwnedNodeEdgePoint().values());
120         assertEquals("incorrect uuid for nep1",
121             onep1Uuid, edgePointList.get(1).getUuid());
122         assertEquals("incorrect uuid for nep1",
123             onep2Uuid, edgePointList.get(0).getUuid());
124     }
125
126     @Test
127     public void getTopologyDetailsForOtnTopologyWhenSuccessful() throws ExecutionException, InterruptedException {
128         GetTopologyDetailsInput input = TopologyDataUtils.buildGetTopologyDetailsInput(NetworkUtils.OTN_NETWORK_ID);
129         TapiTopologyImpl tapiTopoImpl = new TapiTopologyImpl(getDataBroker());
130         ListenableFuture<RpcResult<GetTopologyDetailsOutput>> result = tapiTopoImpl.getTopologyDetails(input);
131         result.addListener(new Runnable() {
132             @Override
133             public void run() {
134                 endSignal.countDown();
135             }
136         }, executorService);
137         endSignal.await();
138         RpcResult<GetTopologyDetailsOutput> rpcResult = result.get();
139         @Nullable
140         Topology topology = rpcResult.getResult().getTopology();
141         assertNotNull("Topology should not be null", topology);
142         assertEquals("Node list size should be 4", 4, topology.getNode().size());
143         assertEquals("Link list size should be 5", 5, topology.getLink().size());
144         Uuid topoUuid = new Uuid(UUID.nameUUIDFromBytes("T0 - Multi-layer topology".getBytes()).toString());
145         assertEquals("incorrect topology uuid", topoUuid, topology.getUuid());
146         assertEquals("topology name should be T0 - Multi-layer topology",
147             "T0 - Multi-layer topology",
148             topology.nonnullName().values().stream().findFirst().get().getValue());
149
150         List<Node> nodes = topology.nonnullNode().values().stream()
151             .sorted((n1,n2) -> n1.getUuid().getValue().compareTo(n2.getUuid().getValue()))
152             .collect(Collectors.toList());
153         Uuid node1Uuid = new Uuid(UUID.nameUUIDFromBytes("SPDR-SA1-XPDR1+DSR".getBytes(Charset.forName("UTF-8")))
154             .toString());
155         checkDsrNode(nodes.get(0), node1Uuid, false, "SPDR-SA1-XPDR1");
156         Uuid node2Uuid = new Uuid(UUID.nameUUIDFromBytes("SPDR-SA1-XPDR2+DSR".getBytes(Charset.forName("UTF-8")))
157             .toString());
158         checkDsrNode(nodes.get(1), node2Uuid, true, "SPDR-SA1-XPDR2");
159         Uuid node3Uuid = new Uuid(UUID.nameUUIDFromBytes("SPDR-SA1-XPDR1+OTSi".getBytes(Charset.forName("UTF-8")))
160             .toString());
161         checkOtsiNode(nodes.get(2), node3Uuid, false, "SPDR-SA1-XPDR1");
162         Uuid node4Uuid = new Uuid(UUID.nameUUIDFromBytes("SPDR-SA1-XPDR2+OTSi".getBytes(Charset.forName("UTF-8")))
163             .toString());
164         checkOtsiNode(nodes.get(3), node4Uuid, true, "SPDR-SA1-XPDR2");
165
166         List<Link> links = topology.nonnullLink().values().stream()
167             .sorted((l1, l2) -> l1.getUuid().getValue().compareTo(l2.getUuid().getValue()))
168             .collect(Collectors.toList());
169         checkTransitionalLink(links.get(4), topoUuid, node1Uuid, node3Uuid, "SPDR-SA1-XPDR1+DSR+XPDR1-NETWORK1",
170             "SPDR-SA1-XPDR1+iOTSi+XPDR1-NETWORK1", "SPDR-SA1-XPDR1");
171         checkTransitionalLink(links.get(2), topoUuid, node2Uuid, node4Uuid, "SPDR-SA1-XPDR2+DSR+XPDR2-NETWORK1",
172             "SPDR-SA1-XPDR2+iOTSi+XPDR2-NETWORK1", "SPDR-SA1-XPDR2");
173     }
174
175     @Test
176     public void getTopologyDetailsForOtnTopologyWithOtnLinksWhenSuccessful()
177         throws ExecutionException, InterruptedException {
178         executorService = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(NUM_THREADS));
179         endSignal = new CountDownLatch(1);
180         TopologyDataUtils.writeTopologyFromFileToDatastore(getDataStoreContextUtil(),
181             TopologyDataUtils.OTN_TOPOLOGY_WITH_OTN_LINKS_FILE, InstanceIdentifiers.OTN_NETWORK_II);
182
183         GetTopologyDetailsInput input = TopologyDataUtils.buildGetTopologyDetailsInput(NetworkUtils.OTN_NETWORK_ID);
184         TapiTopologyImpl tapiTopoImpl = new TapiTopologyImpl(getDataBroker());
185         ListenableFuture<RpcResult<GetTopologyDetailsOutput>> result = tapiTopoImpl.getTopologyDetails(input);
186         result.addListener(new Runnable() {
187             @Override
188             public void run() {
189                 endSignal.countDown();
190             }
191         }, executorService);
192         endSignal.await();
193         RpcResult<GetTopologyDetailsOutput> rpcResult = result.get();
194         @Nullable
195         Topology topology = rpcResult.getResult().getTopology();
196         assertNotNull("Topology should not be null", topology);
197         assertEquals("Node list size should be 8", 8, topology.getNode().size());
198         assertEquals("Link list size should be 12", 12, topology.getLink().size());
199
200         Uuid topoUuid = new Uuid(UUID.nameUUIDFromBytes("T0 - Multi-layer topology".getBytes()).toString());
201         Uuid node1Uuid = new Uuid(UUID.nameUUIDFromBytes("SPDR-SA1-XPDR1+DSR".getBytes(Charset.forName("UTF-8")))
202             .toString());
203         Uuid node2Uuid = new Uuid(UUID.nameUUIDFromBytes("SPDR-SC1-XPDR1+DSR".getBytes(Charset.forName("UTF-8")))
204             .toString());
205         Uuid node3Uuid = new Uuid(UUID.nameUUIDFromBytes("SPDR-SA1-XPDR1+OTSi".getBytes(Charset.forName("UTF-8")))
206             .toString());
207         Uuid node4Uuid = new Uuid(UUID.nameUUIDFromBytes("SPDR-SC1-XPDR1+OTSi".getBytes(Charset.forName("UTF-8")))
208             .toString());
209         Uuid tp1Uuid = new Uuid(UUID.nameUUIDFromBytes("SPDR-SA1-XPDR1+DSR+XPDR1-NETWORK1"
210             .getBytes(Charset.forName("UTF-8"))).toString());
211         Uuid tp2Uuid = new Uuid(UUID.nameUUIDFromBytes("SPDR-SC1-XPDR1+DSR+XPDR1-NETWORK1"
212             .getBytes(Charset.forName("UTF-8"))).toString());
213         Uuid tp3Uuid = new Uuid(UUID.nameUUIDFromBytes("SPDR-SA1-XPDR1+iOTSi+XPDR1-NETWORK1"
214             .getBytes(Charset.forName("UTF-8"))).toString());
215         Uuid tp4Uuid = new Uuid(UUID.nameUUIDFromBytes("SPDR-SC1-XPDR1+iOTSi+XPDR1-NETWORK1"
216             .getBytes(Charset.forName("UTF-8"))).toString());
217         Uuid link1Uuid =
218             new Uuid(UUID.nameUUIDFromBytes("ODU4-SPDR-SA1-XPDR1-XPDR1-NETWORK1toSPDR-SC1-XPDR1-XPDR1-NETWORK1"
219                 .getBytes(Charset.forName("UTF-8"))).toString());
220         Uuid link2Uuid =
221             new Uuid(UUID.nameUUIDFromBytes("OTU4-SPDR-SA1-XPDR1-XPDR1-NETWORK1toSPDR-SC1-XPDR1-XPDR1-NETWORK1"
222                 .getBytes(Charset.forName("UTF-8"))).toString());
223
224         List<Link> links = topology.nonnullLink().values().stream()
225             .sorted((l1, l2) -> l1.getUuid().getValue().compareTo(l2.getUuid().getValue()))
226             .collect(Collectors.toList());
227         checkOtnLink(links.get(3), topoUuid, node1Uuid, node2Uuid, tp1Uuid, tp2Uuid, link1Uuid,
228             "ODU4-SPDR-SA1-XPDR1-XPDR1-NETWORK1toSPDR-SC1-XPDR1-XPDR1-NETWORK1");
229         checkOtnLink(links.get(9), topoUuid, node3Uuid, node4Uuid, tp3Uuid, tp4Uuid, link2Uuid,
230             "OTU4-SPDR-SA1-XPDR1-XPDR1-NETWORK1toSPDR-SC1-XPDR1-XPDR1-NETWORK1");
231     }
232
233     private void checkDsrNode(Node node, Uuid nodeUuid, boolean isSwitch, String nodeId) {
234         assertEquals("incorrect node uuid", nodeUuid, node.getUuid());
235         assertEquals("administrative state should be UNLOCKED",
236             AdministrativeState.UNLOCKED, node.getAdministrativeState());
237         assertEquals("life-cycle state should be INSTALLED", LifecycleState.INSTALLED, node.getLifecycleState());
238         assertEquals("operational state should be ENABLED", OperationalState.ENABLED, node.getOperationalState());
239         assertEquals("value-name should be 'dsr/odu node name'",
240              "dsr/odu node name", node.nonnullName().values().stream().findFirst().get().getValueName());
241         assertEquals("dsr node should manage 2 protocol layers : dsr and odu",
242             2, node.getLayerProtocolName().size());
243         assertThat("dsr node should manage 2 protocol layers : dsr and odu",
244             node.getLayerProtocolName(), hasItems(LayerProtocolName.DSR, LayerProtocolName.ODU));
245         List<OwnedNodeEdgePoint> neps = node.nonnullOwnedNodeEdgePoint().values().stream()
246             .sorted((nep1, nep2) -> nep1.getUuid().getValue().compareTo(nep2.getUuid().getValue()))
247             .collect(Collectors.toList());
248         if (isSwitch) {
249             assertEquals("Switch-DSR node should have 8 NEPs", 8, neps.size());
250             OwnedNodeEdgePoint nep1 = neps.get(3);
251             Uuid client4NepUuid = new Uuid(
252                     UUID.nameUUIDFromBytes((nodeId + "+DSR+XPDR2-CLIENT4").getBytes(Charset.forName("UTF-8")))
253                     .toString());
254             checkNepClient100G(nep1, client4NepUuid, "XPDR2-CLIENT4", "NodeEdgePoint_C4");
255             OwnedNodeEdgePoint nep2 = neps.get(4);
256             Uuid networkNepUuid = new Uuid(
257                     UUID.nameUUIDFromBytes((nodeId + "+DSR+XPDR2-NETWORK1").getBytes(Charset.forName("UTF-8")))
258                     .toString());
259             checkNepNetworkODU4(nep2, networkNepUuid, "XPDR2-NETWORK1", "NodeEdgePoint_N1");
260             List<NodeRuleGroup> nrgList = node.nonnullNodeRuleGroup().values().stream()
261                 .sorted((nrg1, nrg2) -> nrg1.getUuid().getValue().compareTo(nrg2.getUuid().getValue()))
262                 .collect(Collectors.toList());
263             checkNodeRuleGroupForSwitchDSR(nrgList, client4NepUuid, networkNepUuid, nodeUuid);
264         } else {
265             assertEquals("Mux-DSR node should have 5 NEPs", 5, neps.size());
266             OwnedNodeEdgePoint nep1 = neps.get(0);
267             Uuid client4NepUuid = new Uuid(
268                     UUID.nameUUIDFromBytes((nodeId + "+DSR+XPDR1-CLIENT4").getBytes(Charset.forName("UTF-8")))
269                     .toString());
270             checkNepClient10G(nep1, client4NepUuid, "XPDR1-CLIENT4", "NodeEdgePoint_C4");
271
272             OwnedNodeEdgePoint nep2 = neps.get(1);
273             Uuid networkNepUuid = new Uuid(
274                     UUID.nameUUIDFromBytes((nodeId + "+DSR+XPDR1-NETWORK1").getBytes(Charset.forName("UTF-8")))
275                     .toString());
276             checkNepNetworkODU4(nep2, networkNepUuid, "XPDR1-NETWORK1", "NodeEdgePoint_N1");
277             List<NodeRuleGroup> nrgList = node.nonnullNodeRuleGroup().values().stream()
278                 .sorted((nrg1, nrg2) -> nrg1.getUuid().getValue().compareTo(nrg2.getUuid().getValue()))
279                 .collect(Collectors.toList());
280             checkNodeRuleGroupForMuxDSR(nrgList, client4NepUuid, networkNepUuid, nodeUuid);
281         }
282     }
283
284     private void checkOtsiNode(Node node, Uuid nodeUuid, boolean isSwitch, String nodeId) {
285         assertEquals("incorrect node uuid", nodeUuid, node.getUuid());
286         assertEquals("administrative state should be UNLOCKED",
287             AdministrativeState.UNLOCKED, node.getAdministrativeState());
288         assertEquals("life-cycle state should be INSTALLED", LifecycleState.INSTALLED, node.getLifecycleState());
289         assertEquals("operational state should be ENABLED", OperationalState.ENABLED, node.getOperationalState());
290         assertEquals("value-name should be 'dsr/odu node name'",
291              "otsi node name", node.nonnullName().values().stream().findFirst().get().getValueName());
292         assertEquals("otsi node should manage a single protocol layer : PHOTONIC_MEDIA",
293             1, node.getLayerProtocolName().size());
294         assertEquals("otsi node should manage a single protocol layer : PHOTONIC_MEDIA",
295             LayerProtocolName.PHOTONICMEDIA, node.getLayerProtocolName().get(0));
296         List<OwnedNodeEdgePoint> neps = node.nonnullOwnedNodeEdgePoint().values().stream()
297             .sorted((nep1, nep2) -> nep1.getUuid().getValue().compareTo(nep2.getUuid().getValue()))
298             .collect(Collectors.toList());
299         if (isSwitch) {
300             assertEquals("Switch-OTSi node should have 8 NEPs", 8, neps.size());
301             OwnedNodeEdgePoint nep1 = neps.get(2);
302             Uuid inepUuid = new Uuid(
303                     UUID.nameUUIDFromBytes((nodeId + "+iOTSi+XPDR2-NETWORK2").getBytes(Charset.forName("UTF-8")))
304                     .toString());
305             checkNepOtsiNode(nep1, inepUuid, "XPDR2-NETWORK2", "iNodeEdgePoint_2");
306             OwnedNodeEdgePoint nep2 = neps.get(0);
307             Uuid enepUuid = new Uuid(
308                     UUID.nameUUIDFromBytes((nodeId + "+eOTSi+XPDR2-NETWORK2").getBytes(Charset.forName("UTF-8")))
309                     .toString());
310             checkNepOtsiNode(nep2, enepUuid, "XPDR2-NETWORK2", "eNodeEdgePoint_2");
311             List<NodeRuleGroup> nrgList = node.nonnullNodeRuleGroup().values().stream()
312                 .sorted((nrg1, nrg2) -> nrg1.getUuid().getValue().compareTo(nrg2.getUuid().getValue()))
313                 .collect(Collectors.toList());
314             checkNodeRuleGroupForSwitchOTSi(nrgList, enepUuid, inepUuid, nodeUuid);
315         } else {
316             assertEquals("Mux-OTSi node should have 2 NEPs", 2, neps.size());
317             OwnedNodeEdgePoint nep1 = neps.get(0);
318             Uuid enepUuid = new Uuid(
319                     UUID.nameUUIDFromBytes((nodeId + "+eOTSi+XPDR1-NETWORK1").getBytes(Charset.forName("UTF-8")))
320                     .toString());
321             checkNepOtsiNode(nep1, enepUuid, "XPDR1-NETWORK1", "eNodeEdgePoint_1");
322             OwnedNodeEdgePoint nep2 = neps.get(1);
323             Uuid inepUuid = new Uuid(
324                     UUID.nameUUIDFromBytes((nodeId + "+iOTSi+XPDR1-NETWORK1").getBytes(Charset.forName("UTF-8")))
325                     .toString());
326             checkNepOtsiNode(nep2, inepUuid, "XPDR1-NETWORK1", "iNodeEdgePoint_1");
327             List<NodeRuleGroup> nrgList = node.nonnullNodeRuleGroup().values().stream()
328                 .sorted((nrg1, nrg2) -> nrg1.getUuid().getValue().compareTo(nrg2.getUuid().getValue()))
329                 .collect(Collectors.toList());
330             checkNodeRuleGroupForMuxOTSi(nrgList, enepUuid, inepUuid, nodeUuid);
331         }
332     }
333
334     private void checkNepClient10G(OwnedNodeEdgePoint nep, Uuid nepUuid, String portName, String nepName) {
335         assertEquals("bad uuid for " + portName, nepUuid, nep.getUuid());
336         List<Name> nameList = new ArrayList<>(nep.nonnullName().values());
337         Name name = nameList.get(0);
338         assertEquals("value of client nep should be '" + portName + "'",
339             portName, name.getValue());
340         assertEquals("value-name of client nep for '" + portName + "' should be '" + nepName + "'",
341             nepName, name.getValueName());
342         assertEquals("Client nep should support 2 kind of cep",
343             2, nep.getSupportedCepLayerProtocolQualifier().size());
344         assertThat("client nep should support 2 kind of cep",
345             nep.getSupportedCepLayerProtocolQualifier(),
346             hasItems(ODUTYPEODU2E.class, DIGITALSIGNALTYPE10GigELAN.class));
347         assertEquals("client nep should be of ETH protocol type", LayerProtocolName.ETH, nep.getLayerProtocolName());
348         checkCommonPartOfNep(nep);
349     }
350
351     private void checkNepNetworkODU4(OwnedNodeEdgePoint nep, Uuid nepUuid, String portName, String nepName) {
352         assertEquals("bad uuid for " + portName, nepUuid, nep.getUuid());
353         List<Name> nameList = new ArrayList<>(nep.nonnullName().values());
354         Name name = nameList.get(0);
355         assertEquals("value of network nep should be '" + portName + "'",
356             portName, name.getValue());
357         assertEquals("value-name of client nep for '" + portName + "' should be '" + nepName + "'",
358             nepName, name.getValueName());
359         assertEquals("Network nep should support 1 kind of cep",
360             1, nep.getSupportedCepLayerProtocolQualifier().size());
361         assertThat("network nep should support 1 kind of cep",
362             nep.getSupportedCepLayerProtocolQualifier(),
363             hasItem(ODUTYPEODU4.class));
364         assertEquals("network nep should be of ODU protocol type", LayerProtocolName.ODU, nep.getLayerProtocolName());
365         checkCommonPartOfNep(nep);
366     }
367
368     private void checkNodeRuleGroupForMuxDSR(List<NodeRuleGroup> nrgList, Uuid clientNepUuid, Uuid networkNepUuid,
369         Uuid nodeUuid) {
370         assertEquals("muxponder DSR should contain 4 node rule group", 4, nrgList.size());
371         for (NodeRuleGroup nodeRuleGroup : nrgList) {
372             assertEquals("each node-rule-group should contain 2 NEP for muxponder DSR",
373                 2, nodeRuleGroup.getNodeEdgePoint().size());
374         }
375         List<NodeEdgePoint> nodeEdgePointList = new ArrayList<>(nrgList.get(0).nonnullNodeEdgePoint().values());
376         assertThat("node-rule-group nb 2 should be between nep-client4 and nep-network1",
377             nodeEdgePointList.get(0).getNodeEdgePointUuid().getValue(),
378             either(containsString(networkNepUuid.getValue())).or(containsString(clientNepUuid.getValue())));
379         assertThat("node-rule-group nb 2 should be between nep-client4 and nep-network1",
380             nodeEdgePointList.get(1).getNodeEdgePointUuid().getValue(),
381             either(containsString(networkNepUuid.getValue())).or(containsString(clientNepUuid.getValue())));
382         assertEquals("node-rule-group nb 2 should be between nep-client4 and nep-network1 of the same node",
383             nodeEdgePointList.get(0).getNodeUuid(), nodeUuid);
384         assertEquals("node-rule-group nb 2 should be between nep-client4 and nep-network1 of the same node",
385             nodeEdgePointList.get(1).getNodeUuid(), nodeUuid);
386         List<Rule> rule = new ArrayList<>(nrgList.get(1).nonnullRule().values());
387         assertEquals("node-rule-group nb 2 should contain a single rule", 1, rule.size());
388         assertEquals("local-id of the rule should be 'forward'",
389             "forward", rule.get(0).getLocalId());
390         assertEquals("the forwarding rule should be 'MAYFORWARDACROSSGROUP'",
391             ForwardingRule.MAYFORWARDACROSSGROUP, rule.get(0).getForwardingRule());
392         assertEquals("the rule type should be 'FORWARDING'",
393             RuleType.FORWARDING, rule.get(0).getRuleType());
394     }
395
396     private void checkNodeRuleGroupForSwitchDSR(List<NodeRuleGroup> nrgList, Uuid clientNepUuid, Uuid networkNepUuid,
397         Uuid nodeUuid) {
398         assertEquals("Switch-DSR should contain a single node rule group", 1, nrgList.size());
399         assertEquals("Switch-DSR node-rule-group should contain 8 NEP", 8, nrgList.get(0).getNodeEdgePoint().size());
400         List<NodeEdgePoint> nrg = nrgList.get(0).nonnullNodeEdgePoint().values().stream()
401             .sorted((nrg1, nrg2) -> nrg1.getNodeEdgePointUuid().getValue()
402                 .compareTo(nrg2.getNodeEdgePointUuid().getValue()))
403             .collect(Collectors.toList());
404         assertEquals("in the sorted node-rule-group, nep number 2 should be XPDR2-NETWORK1",
405             networkNepUuid, nrg.get(4).getNodeEdgePointUuid());
406         assertEquals("in the sorted node-rule-group, nep number 6 should be XPDR2-CLIENT4",
407             clientNepUuid, nrg.get(3).getNodeEdgePointUuid());
408         assertEquals("any item of the node-rule-group should have the same nodeUuid",
409             nodeUuid, nrg.get(4).getNodeUuid());
410         assertEquals("any item of the node-rule-group should have the same nodeUuid",
411             nodeUuid, nrg.get(3).getNodeUuid());
412         @Nullable
413         List<Rule> ruleList = new ArrayList<>(nrgList.get(0).nonnullRule().values());
414         assertEquals("node-rule-group should contain a single rule", 1, ruleList.size());
415         assertEquals("local-id of the rule should be 'forward'",
416             "forward", ruleList.get(0).getLocalId());
417         assertEquals("the forwarding rule should be 'MAYFORWARDACROSSGROUP'",
418             ForwardingRule.MAYFORWARDACROSSGROUP, ruleList.get(0).getForwardingRule());
419         assertEquals("the rule type should be 'FORWARDING'",
420             RuleType.FORWARDING, ruleList.get(0).getRuleType());
421     }
422
423     private void checkNodeRuleGroupForMuxOTSi(List<NodeRuleGroup> nrgList, Uuid enepUuid, Uuid inepUuid,
424         Uuid nodeUuid) {
425         assertEquals("Mux-OTSi should contain a single node rule group", 1, nrgList.size());
426         List<NodeEdgePoint> nodeEdgePointList = new ArrayList<>(nrgList.get(0).getNodeEdgePoint().values());
427         assertEquals("Mux-OTSi node-rule-group should contain 2 NEP", 2, nodeEdgePointList.size());
428         assertThat("Mux-OTSi node-rule-group should be between eNEP and iNEP of XPDR1-NETWORK1",
429             nodeEdgePointList.get(0).getNodeEdgePointUuid().getValue(),
430             either(containsString(enepUuid.getValue())).or(containsString(inepUuid.getValue())));
431         assertThat("Mux-OTSi node-rule-group should be between eNEP and iNEP of XPDR1-NETWORK1",
432             nodeEdgePointList.get(1).getNodeEdgePointUuid().getValue(),
433             either(containsString(enepUuid.getValue())).or(containsString(inepUuid.getValue())));
434         assertEquals("any item of the node-rule-group should have the same nodeUuid",
435             nodeUuid, nodeEdgePointList.get(0).getNodeUuid());
436         assertEquals("any item of the node-rule-group should have the same nodeUuid",
437             nodeUuid, nodeEdgePointList.get(1).getNodeUuid());
438         List<Rule> ruleList = new ArrayList<>(nrgList.get(0).nonnullRule().values());
439         assertEquals("node-rule-group should contain a single rule", 1, ruleList.size());
440         assertEquals("local-id of the rule should be 'forward'",
441             "forward", ruleList.get(0).getLocalId());
442         assertEquals("the forwarding rule should be 'MAYFORWARDACROSSGROUP'",
443             ForwardingRule.MAYFORWARDACROSSGROUP, ruleList.get(0).getForwardingRule());
444         assertEquals("the rule type should be 'FORWARDING'",
445             RuleType.FORWARDING, ruleList.get(0).getRuleType());
446     }
447
448     private void checkNodeRuleGroupForSwitchOTSi(List<NodeRuleGroup> nrgList, Uuid enepUuid, Uuid inepUuid,
449         Uuid nodeUuid) {
450         assertEquals("Switch-OTSi should contain 4 node rule group", 4, nrgList.size());
451         for (NodeRuleGroup nodeRuleGroup : nrgList) {
452             assertEquals("each node-rule-group should contain 2 NEP for Switch-OTSi",
453                 2, nodeRuleGroup.getNodeEdgePoint().size());
454         }
455         List<NodeEdgePoint> nodeEdgePointList1 = new ArrayList<>(nrgList.get(3).nonnullNodeEdgePoint().values());
456         assertThat("Switch-OTSi node-rule-group nb 4 should be between eNEP and iNEP of XPDR2-NETWORK2",
457             nodeEdgePointList1.get(0).getNodeEdgePointUuid().getValue(),
458             either(containsString(enepUuid.getValue())).or(containsString(inepUuid.getValue())));
459         assertThat("Switch-OTSi node-rule-group nb 4 should be between eNEP and iNEP of XPDR2-NETWORK2",
460             nodeEdgePointList1.get(1).getNodeEdgePointUuid().getValue(),
461             either(containsString(enepUuid.getValue())).or(containsString(inepUuid.getValue())));
462         List<NodeEdgePoint> nodeEdgePointList0 = new ArrayList<>(nrgList.get(0).getNodeEdgePoint().values());
463         assertEquals("any item of the node-rule-group should have the same nodeUuid",
464             nodeUuid, nodeEdgePointList0.get(0).getNodeUuid());
465         assertEquals("any item of the node-rule-group should have the same nodeUuid",
466             nodeUuid, nodeEdgePointList0.get(1).getNodeUuid());
467         List<Rule> ruleList0 = new ArrayList<>(nrgList.get(0).nonnullRule().values());
468         assertEquals("node-rule-group should contain a single rule", 1, ruleList0.size());
469         assertEquals("local-id of the rule should be 'forward'",
470             "forward", ruleList0.get(0).getLocalId());
471         assertEquals("the forwarding rule should be 'MAYFORWARDACROSSGROUP'",
472             ForwardingRule.MAYFORWARDACROSSGROUP, ruleList0.get(0).getForwardingRule());
473         assertEquals("the rule type should be 'FORWARDING'",
474             RuleType.FORWARDING, ruleList0.get(0).getRuleType());
475     }
476
477     private void checkNepClient100G(OwnedNodeEdgePoint nep, Uuid nepUuid, String portName, String nepName) {
478         assertEquals("bad uuid for " + portName, nepUuid, nep.getUuid());
479         List<Name> nameList = new ArrayList<>(nep.nonnullName().values());
480         assertEquals("value of client nep should be '" + portName + "'",
481             portName, nameList.get(0).getValue());
482         assertEquals("value-name of client nep for '" + portName + "' should be '" + nepName + "'",
483             nepName, nameList.get(0).getValueName());
484         assertEquals("Client nep should support 2 kind of cep",
485             2, nep.getSupportedCepLayerProtocolQualifier().size());
486         assertThat("client nep should support 2 kind of cep",
487             nep.getSupportedCepLayerProtocolQualifier(),
488             hasItems(ODUTYPEODU4.class, DIGITALSIGNALTYPE100GigE.class));
489         assertEquals("client nep should be of ETH protocol type", LayerProtocolName.ETH, nep.getLayerProtocolName());
490         checkCommonPartOfNep(nep);
491     }
492
493     private void checkNepOtsiNode(OwnedNodeEdgePoint nep, Uuid nepUuid, String portName, String nepName) {
494         assertEquals("bad uuid for " + portName, nepUuid, nep.getUuid());
495         List<Name> nameList = new ArrayList<>(nep.nonnullName().values());
496         assertEquals("value of OTSi nep should be '" + portName + "'",
497             portName, nameList.get(0).getValue());
498         assertEquals("value-name of OTSi nep should be '" + nepName + "'",
499             nepName, nameList.get(0).getValueName());
500         assertEquals("OTSi nep should support 2 kind of cep",
501             2, nep.getSupportedCepLayerProtocolQualifier().size());
502         assertThat("OTSi nep should support 2 kind of cep",
503             nep.getSupportedCepLayerProtocolQualifier(),
504             hasItems(PHOTONICLAYERQUALIFIEROMS.class, PHOTONICLAYERQUALIFIEROTSi.class));
505         assertEquals("OTSi nep should be of PHOTONIC_MEDIA protocol type",
506             LayerProtocolName.PHOTONICMEDIA, nep.getLayerProtocolName());
507         assertEquals("OTSi nep should support one SIP", 1, nep.getMappedServiceInterfacePoint().size());
508         checkCommonPartOfNep(nep);
509     }
510
511     private void checkCommonPartOfNep(OwnedNodeEdgePoint nep) {
512         assertEquals("link port direction should be DIRECTIONAL",
513             PortDirection.BIDIRECTIONAL, nep.getLinkPortDirection());
514         assertEquals("administrative state should be UNLOCKED",
515             AdministrativeState.UNLOCKED, nep.getAdministrativeState());
516         assertEquals("termination state should be TERMINATED BIDIRECTIONAL",
517             TerminationState.TERMINATEDBIDIRECTIONAL, nep.getTerminationState());
518         assertEquals("life-cycle state should be INSTALLED", LifecycleState.INSTALLED, nep.getLifecycleState());
519         assertEquals("client nep should support 1 SIP", 1, nep.getMappedServiceInterfacePoint().size());
520         assertEquals("termination direction should be BIDIRECTIONAL",
521             TerminationDirection.BIDIRECTIONAL, nep.getTerminationDirection());
522         assertEquals("operational state of client nep should be ENABLED",
523             OperationalState.ENABLED, nep.getOperationalState());
524         assertEquals("link-port-role of client nep should be SYMMETRIC",
525             PortRole.SYMMETRIC, nep.getLinkPortRole());
526     }
527
528     private void checkTransitionalLink(Link link, Uuid topoUuid, Uuid node1Uuid, Uuid node2Uuid, String tp1,
529         String tp2, String ietfNodeId) {
530         Uuid linkUuid = new Uuid(UUID.nameUUIDFromBytes((ietfNodeId + "--" + tp1 + "--" + tp2)
531             .getBytes(Charset.forName("UTF-8"))).toString());
532         assertEquals("bad uuid for link between DSR node " + tp1 + " and iOTSI port " + tp2, linkUuid, link.getUuid());
533         assertEquals("Available capacity unit should be GBPS",
534             CapacityUnit.GBPS, link.getAvailableCapacity().getTotalSize().getUnit());
535         assertEquals("Available capacity -total size value should be 100",
536             Uint64.valueOf(100), link.getAvailableCapacity().getTotalSize().getValue());
537         assertEquals("transitional link should be between 2 nodes of protocol layers ODU and PHOTONIC_MEDIA",
538             2, link.getTransitionedLayerProtocolName().size());
539         assertThat("transitional link should be between 2 nodes of protocol layers ODU and PHOTONIC_MEDIA",
540             link.getTransitionedLayerProtocolName(),
541             hasItems(LayerProtocolName.ODU.getName(), LayerProtocolName.PHOTONICMEDIA.getName()));
542         assertEquals("transitional link should be BIDIRECTIONAL",
543             ForwardingDirection.BIDIRECTIONAL, link.getDirection());
544         List<org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210
545             .link.NodeEdgePoint> nodeEdgePointList = new ArrayList<>(link.nonnullNodeEdgePoint().values());
546         assertEquals("topology uuid should be the same for the two termination point of the link",
547             topoUuid, nodeEdgePointList.get(0).getTopologyUuid());
548         assertEquals("topology uuid should be the same for the two termination point of the link",
549             topoUuid, nodeEdgePointList.get(1).getTopologyUuid());
550         assertThat("transitional links should terminate on DSR node and Photonic node",
551             nodeEdgePointList.get(0).getNodeUuid().getValue(),
552             either(containsString(node1Uuid.getValue())).or(containsString(node2Uuid.getValue())));
553         assertThat("transitional links should terminate on DSR node and Photonic node",
554             nodeEdgePointList.get(1).getNodeUuid().getValue(),
555             either(containsString(node1Uuid.getValue())).or(containsString(node2Uuid.getValue())));
556         Uuid nep1Uuid = new Uuid(UUID.nameUUIDFromBytes(tp1.getBytes(Charset.forName("UTF-8"))).toString());
557         Uuid nep2Uuid = new Uuid(UUID.nameUUIDFromBytes(tp2.getBytes(Charset.forName("UTF-8"))).toString());
558         assertThat("transitional links should terminate on " + tp1 + " and " + tp2 + " neps",
559             nodeEdgePointList.get(0).getNodeEdgePointUuid().getValue(),
560             either(containsString(nep1Uuid.getValue())).or(containsString(nep2Uuid.getValue())));
561         assertThat("transitional links should terminate on DSR node and Photonic node",
562             nodeEdgePointList.get(1).getNodeEdgePointUuid().getValue(),
563             either(containsString(nep1Uuid.getValue())).or(containsString(nep2Uuid.getValue())));
564     }
565
566     private void checkOtnLink(Link link, Uuid topoUuid, Uuid node1Uuid, Uuid node2Uuid, Uuid tp1Uuid, Uuid tp2Uuid,
567         Uuid linkUuid, String linkName) {
568         assertEquals("bad name for the link", linkName, link.getName().get(new NameKey("otn link name")).getValue());
569         assertEquals("bad uuid for link", linkUuid, link.getUuid());
570         assertEquals("Available capacity unit should be MBPS",
571             CapacityUnit.MBPS, link.getAvailableCapacity().getTotalSize().getUnit());
572         String prefix = linkName.split("-")[0];
573         if ("OTU4".equals(prefix)) {
574             assertEquals("Available capacity -total size value should be 0",
575                 Uint64.valueOf(0), link.getAvailableCapacity().getTotalSize().getValue());
576         } else if ("ODU4".equals(prefix)) {
577             assertEquals("Available capacity -total size value should be 100 000",
578                 Uint64.valueOf(100000), link.getAvailableCapacity().getTotalSize().getValue());
579         }
580         assertEquals("Total capacity unit should be GBPS",
581             CapacityUnit.GBPS, link.getTotalPotentialCapacity().getTotalSize().getUnit());
582         assertEquals("Total capacity -total size value should be 100",
583             Uint64.valueOf(100), link.getTotalPotentialCapacity().getTotalSize().getValue());
584         if ("OTU4".equals(prefix)) {
585             assertEquals("otn link should be between 2 nodes of protocol layers PHOTONIC_MEDIA",
586                 LayerProtocolName.PHOTONICMEDIA.getName(), link.getLayerProtocolName().get(0).getName());
587         } else if ("ODU4".equals(prefix)) {
588             assertEquals("otn link should be between 2 nodes of protocol layers ODU",
589                 LayerProtocolName.ODU.getName(), link.getLayerProtocolName().get(0).getName());
590         }
591         assertEquals("transitional link should be BIDIRECTIONAL",
592             ForwardingDirection.BIDIRECTIONAL, link.getDirection());
593         List<org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210
594             .link.NodeEdgePoint> nodeEdgePointList = new ArrayList<>(link.nonnullNodeEdgePoint().values());
595         assertEquals("topology uuid should be the same for the two termination point of the link",
596             topoUuid, nodeEdgePointList.get(0).getTopologyUuid());
597         assertEquals("topology uuid should be the same for the two termination point of the link",
598             topoUuid, nodeEdgePointList.get(1).getTopologyUuid());
599         assertThat("otn links should terminate on two distinct nodes",
600             nodeEdgePointList.get(0).getNodeUuid().getValue(),
601             either(containsString(node1Uuid.getValue())).or(containsString(node2Uuid.getValue())));
602         assertThat("otn links should terminate on two distinct nodes",
603             nodeEdgePointList.get(1).getNodeUuid().getValue(),
604             either(containsString(node1Uuid.getValue())).or(containsString(node2Uuid.getValue())));
605         assertThat("otn links should terminate on two distinct tps",
606             nodeEdgePointList.get(0).getNodeEdgePointUuid().getValue(),
607             either(containsString(tp1Uuid.getValue())).or(containsString(tp2Uuid.getValue())));
608         assertThat("otn links should terminate on two distinct tps",
609             nodeEdgePointList.get(1).getNodeEdgePointUuid().getValue(),
610             either(containsString(tp1Uuid.getValue())).or(containsString(tp2Uuid.getValue())));
611         assertEquals("operational state should be ENABLED",
612             OperationalState.ENABLED, link.getOperationalState());
613         assertEquals("administrative state should be UNLOCKED",
614             AdministrativeState.UNLOCKED, link.getAdministrativeState());
615     }
616
617 }