2 * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.bgpcep.pcep.topology.provider;
10 import static org.mockito.ArgumentMatchers.any;
11 import static org.mockito.Mockito.doAnswer;
12 import static org.mockito.Mockito.doNothing;
13 import static org.mockito.Mockito.doReturn;
15 import com.google.common.util.concurrent.ListenableFuture;
16 import java.util.concurrent.Executor;
17 import org.junit.Assert;
18 import org.junit.Before;
19 import org.junit.Test;
20 import org.mockito.Mock;
21 import org.mockito.Mockito;
22 import org.opendaylight.bgpcep.pcep.topology.provider.TopologyProgrammingTest.MockedTopologySessionListenerFactory;
23 import org.opendaylight.bgpcep.programming.spi.Instruction;
24 import org.opendaylight.bgpcep.programming.spi.InstructionScheduler;
25 import org.opendaylight.protocol.pcep.PCEPSession;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev171025.Tlvs1;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev171025.Tlvs1Builder;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev171025.stateful.capability.tlv.StatefulBuilder;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.Open;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.OpenBuilder;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.rev150720.InstructionStatus;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.rev150720.SubmitInstructionInput;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.programming.rev150720.instruction.status.changed.Details;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.programming.rev171025.SubmitAddLspInputBuilder;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.programming.rev171025.SubmitEnsureLspOperationalInputBuilder;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.programming.rev171025.SubmitRemoveLspInputBuilder;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.programming.rev171025.SubmitTriggerSyncInputBuilder;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.programming.rev171025.SubmitUpdateLspInputBuilder;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev171025.AddLspArgs;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev171025.AddLspOutput;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev171025.EnsureLspOperationalInput;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev171025.EnsureLspOperationalOutput;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev171025.RemoveLspArgs;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev171025.RemoveLspOutput;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev171025.TriggerSyncArgs;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev171025.TriggerSyncOutput;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev171025.UpdateLspArgs;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev171025.UpdateLspOutput;
49 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev171025.ensure.lsp.operational.args.ArgumentsBuilder;
50 import org.opendaylight.yangtools.yang.common.RpcResult;
52 public class TopologyProgrammingTest extends AbstractPCEPSessionTest<MockedTopologySessionListenerFactory> {
54 private static final String NAME = "test-tunnel";
55 private static Stateful07TopologySessionListener listener;
58 private InstructionScheduler scheduler;
60 private ListenableFuture<Instruction> instructionFuture;
62 private Instruction instruction;
64 private AddLspArgs addLspArgs;
65 private UpdateLspArgs updateLspArgs;
66 private RemoveLspArgs removeLspArgs;
67 private TriggerSyncArgs triggerSyncArgs;
68 private EnsureLspOperationalInput ensureLspInput;
71 private ListenableFuture<RpcResult<AddLspOutput>> futureAddLspOutput;
73 private ListenableFuture<RpcResult<UpdateLspOutput>> futureUpdateLspOutput;
75 private ListenableFuture<RpcResult<RemoveLspOutput>> futureRemoveLspOutput;
77 private ListenableFuture<RpcResult<TriggerSyncOutput>> futureTriggerSyncOutput;
79 private ListenableFuture<RpcResult<EnsureLspOperationalOutput>> futureEnsureLspOutput;
81 private TopologyProgramming topologyProgramming;
85 public void setUp() throws Exception {
87 doReturn(true).when(this.instruction).checkedExecutionStart();
88 doNothing().when(this.instruction).executionCompleted(InstructionStatus.Failed, null);
89 doAnswer(invocation -> {
90 final Runnable callback = (Runnable) invocation.getArguments()[0];
93 }).when(this.instructionFuture).addListener(any(Runnable.class), any(Executor.class));
94 doAnswer(invocation -> {
95 final Runnable callback = (Runnable) invocation.getArguments()[0];
98 }).when(this.futureAddLspOutput).addListener(any(Runnable.class), any(Executor.class));
99 doAnswer(invocation -> {
100 final Runnable callback = (Runnable) invocation.getArguments()[0];
103 }).when(this.futureUpdateLspOutput).addListener(any(Runnable.class), any(Executor.class));
104 doAnswer(invocation -> {
105 final Runnable callback = (Runnable) invocation.getArguments()[0];
108 }).when(this.futureRemoveLspOutput).addListener(any(Runnable.class), any(Executor.class));
109 doAnswer(invocation -> {
110 final Runnable callback = (Runnable) invocation.getArguments()[0];
113 }).when(this.futureTriggerSyncOutput).addListener(any(Runnable.class), any(Executor.class));
114 doAnswer(invocation -> {
115 final Runnable callback = (Runnable) invocation.getArguments()[0];
118 }).when(this.futureEnsureLspOutput).addListener(any(Runnable.class), any(Executor.class));
119 doAnswer(invocation -> {
120 TopologyProgrammingTest.this.addLspArgs = (AddLspArgs) invocation.getArguments()[0];
121 return TopologyProgrammingTest.this.futureAddLspOutput;
122 }).when(listener).addLsp(any());
123 doAnswer(invocation -> {
124 TopologyProgrammingTest.this.updateLspArgs = (UpdateLspArgs) invocation.getArguments()[0];
125 return TopologyProgrammingTest.this.futureUpdateLspOutput;
126 }).when(listener).updateLsp(any());
127 doAnswer(invocation -> {
128 TopologyProgrammingTest.this.removeLspArgs = (RemoveLspArgs) invocation.getArguments()[0];
129 return TopologyProgrammingTest.this.futureRemoveLspOutput;
130 }).when(listener).removeLsp(any());
131 doAnswer(invocation -> {
132 TopologyProgrammingTest.this.triggerSyncArgs = (TriggerSyncArgs) invocation.getArguments()[0];
133 return TopologyProgrammingTest.this.futureTriggerSyncOutput;
134 }).when(listener).triggerSync(any());
135 doAnswer(invocation -> {
136 TopologyProgrammingTest.this.ensureLspInput = (EnsureLspOperationalInput) invocation.getArguments()[0];
137 return TopologyProgrammingTest.this.futureEnsureLspOutput;
138 }).when(listener).ensureLspOperational(any(EnsureLspOperationalInput.class));
139 doNothing().when(listener).close();
140 doReturn(this.instruction).when(this.instructionFuture).get();
141 doReturn(true).when(this.instructionFuture).isDone();
142 doNothing().when(this.instruction).executionCompleted(any(InstructionStatus.class), any(Details.class));
143 doReturn(this.instructionFuture).when(this.scheduler).scheduleInstruction(any(SubmitInstructionInput.class));
144 this.topologyProgramming = new TopologyProgramming(this.scheduler, this.manager);
145 final PCEPSession session = getPCEPSession(getLocalPref(), getRemotePref());
146 listener.onSessionUp(session);
150 public void testSubmitAddLsp() {
151 final SubmitAddLspInputBuilder inputBuilder = new SubmitAddLspInputBuilder();
152 inputBuilder.setName(NAME);
153 inputBuilder.setNode(this.nodeId);
154 inputBuilder.setArguments(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep
155 .rev171025.add.lsp.args.ArgumentsBuilder().build());
156 this.topologyProgramming.submitAddLsp(inputBuilder.build());
157 Assert.assertNotNull(this.addLspArgs);
158 Assert.assertEquals(NAME, this.addLspArgs.getName());
159 Assert.assertEquals(this.nodeId, this.addLspArgs.getNode());
163 public void testSubmitUpdateLsp() {
164 final SubmitUpdateLspInputBuilder inputBuilder = new SubmitUpdateLspInputBuilder();
165 inputBuilder.setName(NAME);
166 inputBuilder.setNode(this.nodeId);
167 this.topologyProgramming.submitUpdateLsp(inputBuilder.build());
168 Assert.assertNotNull(this.updateLspArgs);
169 Assert.assertEquals(NAME, this.updateLspArgs.getName());
170 Assert.assertEquals(this.nodeId, this.updateLspArgs.getNode());
174 public void testSubmitEnsureLsp() {
175 final SubmitEnsureLspOperationalInputBuilder inputBuilder = new SubmitEnsureLspOperationalInputBuilder();
176 inputBuilder.setName(NAME);
177 inputBuilder.setNode(this.nodeId);
178 inputBuilder.setArguments(new ArgumentsBuilder().build());
179 this.topologyProgramming.submitEnsureLspOperational(inputBuilder.build());
180 Assert.assertNotNull(this.ensureLspInput);
181 Assert.assertEquals(NAME, this.ensureLspInput.getName());
182 Assert.assertEquals(this.nodeId, this.ensureLspInput.getNode());
186 public void testSubmitRemoveLsp() {
187 final SubmitRemoveLspInputBuilder inputBuilder = new SubmitRemoveLspInputBuilder();
188 inputBuilder.setName(NAME);
189 inputBuilder.setNode(this.nodeId);
190 this.topologyProgramming.submitRemoveLsp(inputBuilder.build());
191 Assert.assertNotNull(this.removeLspArgs);
192 Assert.assertEquals(NAME, this.removeLspArgs.getName());
193 Assert.assertEquals(this.nodeId, this.removeLspArgs.getNode());
197 public void testSubmitTriggerSync() {
198 final SubmitTriggerSyncInputBuilder inputBuilder = new SubmitTriggerSyncInputBuilder();
199 inputBuilder.setName(NAME);
200 inputBuilder.setNode(this.nodeId);
201 this.topologyProgramming.submitTriggerSync(inputBuilder.build());
202 Assert.assertNotNull(this.triggerSyncArgs);
203 Assert.assertEquals(NAME, this.triggerSyncArgs.getName());
204 Assert.assertEquals(this.nodeId, this.triggerSyncArgs.getNode());
207 protected static final class MockedTopologySessionListenerFactory implements TopologySessionListenerFactory {
209 public TopologySessionListener createTopologySessionListener(final ServerSessionManager manager) {
210 listener = Mockito.spy(new Stateful07TopologySessionListener(manager));
216 protected Open getLocalPref() {
217 return new OpenBuilder(super.getLocalPref()).setTlvs(new org.opendaylight.yang.gen.v1.urn.opendaylight.params
218 .xml.ns.yang.pcep.types.rev131005.open.object.open.TlvsBuilder().addAugmentation(Tlvs1.class,
219 new Tlvs1Builder().setStateful(new StatefulBuilder().build()).build()).build()).build();