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