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
9 package org.opendaylight.bgpcep.pcep.topology.provider;
11 import static org.junit.Assert.assertEquals;
12 import static org.junit.Assert.assertFalse;
13 import static org.junit.Assert.assertNotNull;
14 import static org.junit.Assert.assertNull;
15 import static org.junit.Assert.assertTrue;
16 import static org.junit.Assert.fail;
17 import static org.opendaylight.protocol.pcep.pcc.mock.spi.MsgBuilderUtil.createLspTlvs;
19 import com.google.common.base.Optional;
20 import com.google.common.collect.Lists;
21 import java.net.UnknownHostException;
22 import java.util.Collections;
23 import java.util.List;
24 import java.util.concurrent.ExecutionException;
25 import java.util.concurrent.Future;
26 import java.util.concurrent.TimeUnit;
27 import java.util.concurrent.TimeoutException;
28 import org.junit.Before;
29 import org.junit.Test;
30 import org.opendaylight.controller.config.yang.pcep.topology.provider.SessionState;
31 import org.opendaylight.protocol.pcep.PCEPCloseTermination;
32 import org.opendaylight.protocol.pcep.PCEPSession;
33 import org.opendaylight.protocol.pcep.TerminationReason;
34 import org.opendaylight.protocol.pcep.pcc.mock.spi.MsgBuilderUtil;
35 import org.opendaylight.protocol.pcep.spi.AbstractMessageParser;
36 import org.opendaylight.protocol.pcep.spi.PCEPErrors;
37 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.topology.rev140113.NetworkTopologyRef;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.initiated.rev131126.Pcinitiate;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.initiated.rev131126.Stateful1;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.initiated.rev131126.Stateful1Builder;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.initiated.rev131126.pcinitiate.message.pcinitiate.message.Requests;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.Arguments1;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.Arguments1Builder;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.Arguments2;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.Arguments2Builder;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.Arguments3;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.Arguments3Builder;
49 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.OperationalStatus;
50 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.Pcrpt;
51 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.PcrptBuilder;
52 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.Pcupd;
53 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.PlspId;
54 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.SymbolicPathName;
55 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.Tlvs1;
56 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.Tlvs1Builder;
57 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.lsp.identifiers.tlv.LspIdentifiersBuilder;
58 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.lsp.object.LspBuilder;
59 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.lsp.object.lsp.Tlvs;
60 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.pcrpt.message.PcrptMessageBuilder;
61 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.pcrpt.message.pcrpt.message.Reports;
62 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.pcrpt.message.pcrpt.message.ReportsBuilder;
63 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.pcrpt.message.pcrpt.message.reports.PathBuilder;
64 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.pcupd.message.pcupd.message.Updates;
65 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.stateful.capability.tlv.StatefulBuilder;
66 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.symbolic.path.name.tlv.SymbolicPathNameBuilder;
67 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Message;
68 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.endpoints.address.family.Ipv4CaseBuilder;
69 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.endpoints.address.family.ipv4._case.Ipv4Builder;
70 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.endpoints.object.EndpointsObjBuilder;
71 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.EroBuilder;
72 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.ero.Subobject;
73 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.Open;
74 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.OpenBuilder;
75 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.open.TlvsBuilder;
76 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcep.error.object.ErrorObject;
77 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.rp.object.Rp;
78 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.LspId;
79 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.AddLspInput;
80 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.AddLspInputBuilder;
81 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.AddLspOutput;
82 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.EnsureLspOperationalInput;
83 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.EnsureLspOperationalInputBuilder;
84 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.FailureType;
85 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.Node1;
86 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.OperationResult;
87 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.RemoveLspInput;
88 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.RemoveLspInputBuilder;
89 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.UpdateLspInput;
90 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.UpdateLspInputBuilder;
91 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.UpdateLspOutput;
92 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.add.lsp.args.ArgumentsBuilder;
93 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.pcep.client.attributes.PathComputationClient;
94 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.pcep.client.attributes.path.computation.client.ReportedLsp;
95 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.pcep.client.attributes.path.computation.client.reported.lsp.Path;
96 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
97 import org.opendaylight.yangtools.yang.common.RpcResult;
99 public class Stateful07TopologySessionListenerTest extends AbstractPCEPSessionTest<Stateful07TopologySessionListenerFactory> {
101 private final String TUNNEL_NAME = "pcc_" + testAddress + "_tunnel_0";
103 private Stateful07TopologySessionListener listener;
105 private PCEPSession session;
109 public void setUp() throws Exception {
111 this.listener = (Stateful07TopologySessionListener) getSessionListener();
112 this.session = getPCEPSession(getLocalPref(), getRemotePref());
116 public void testStateful07TopologySessionListener() throws Exception {
117 this.listener.onSessionUp(this.session);
119 assertEquals(testAddress, this.listener.getPeerId());
120 final SessionState state = this.listener.getSessionState();
121 assertNotNull(state);
122 assertEquals(DEAD_TIMER, state.getLocalPref().getDeadtimer().shortValue());
123 assertEquals(KEEP_ALIVE, state.getLocalPref().getKeepalive().shortValue());
124 assertEquals(0, state.getLocalPref().getSessionId().intValue());
125 assertEquals(testAddress, state.getLocalPref().getIpAddress());
126 assertEquals(DEAD_TIMER, state.getPeerPref().getDeadtimer().shortValue());
127 assertEquals(KEEP_ALIVE, state.getPeerPref().getKeepalive().shortValue());
128 assertEquals(0, state.getPeerPref().getSessionId().intValue());
129 assertEquals(testAddress, state.getPeerPref().getIpAddress());
132 this.topologyRpcs.addLsp(createAddLspInput());
133 assertEquals(1, this.receivedMsgs.size());
134 assertTrue(this.receivedMsgs.get(0) instanceof Pcinitiate);
135 final Pcinitiate pcinitiate = (Pcinitiate) this.receivedMsgs.get(0);
136 final Requests req = pcinitiate.getPcinitiateMessage().getRequests().get(0);
137 final long srpId = req.getSrp().getOperationId().getValue();
138 final Tlvs tlvs = createLspTlvs(req.getLsp().getPlspId().getValue(), true,
139 testAddress, testAddress, testAddress, Optional.absent());
140 final Pcrpt pcRpt = MsgBuilderUtil.createPcRtpMessage(new LspBuilder(req.getLsp()).setTlvs(tlvs).setPlspId(new PlspId(1L)).setSync(false).setRemove(false).setOperational(OperationalStatus.Active).build(), Optional.of(MsgBuilderUtil.createSrp(srpId)), MsgBuilderUtil.createPath(req.getEro().getSubobject()));
141 final Pcrpt esm = MsgBuilderUtil.createPcRtpMessage(new LspBuilder().setSync(false).build(), Optional.of(MsgBuilderUtil.createSrp(0L)), null);
142 this.listener.onMessage(this.session, esm);
144 final Optional<Topology> topoOptional = getTopology();
145 assertTrue(topoOptional.isPresent());
146 Topology topology = topoOptional.get();
147 assertEquals(1, topology.getNode().size());
148 final Node1 node = topology.getNode().get(0).getAugmentation(Node1.class);
150 PathComputationClient pcc = node.getPathComputationClient();
151 assertEquals(testAddress, pcc.getIpAddress().getIpv4Address().getValue());
152 // reported lsp so far empty, has not received response (PcRpt) yet
153 assertTrue(pcc.getReportedLsp().isEmpty());
154 this.listener.onMessage(this.session, pcRpt);
156 topology = getTopology().get();
157 pcc = topology.getNode().get(0).getAugmentation(Node1.class).getPathComputationClient();
158 assertEquals(1, pcc.getReportedLsp().size());
159 ReportedLsp reportedLsp = pcc.getReportedLsp().get(0);
160 assertEquals(TUNNEL_NAME, reportedLsp.getName());
161 assertEquals(1, reportedLsp.getPath().size());
162 Path path = reportedLsp.getPath().get(0);
163 assertEquals(1, path.getEro().getSubobject().size());
164 assertEquals(eroIpPrefix, getLastEroIpPrefix(path.getEro()));
166 assertEquals(1, this.listener.getDelegatedLspsCount().intValue());
167 assertTrue(this.listener.getSynchronized());
168 assertTrue(this.listener.getStatefulMessages().getLastReceivedRptMsgTimestamp() > 0);
169 assertEquals(2, this.listener.getStatefulMessages().getReceivedRptMsgCount().intValue());
170 assertEquals(1, this.listener.getStatefulMessages().getSentInitMsgCount().intValue());
171 assertEquals(0, this.listener.getStatefulMessages().getSentUpdMsgCount().intValue());
172 assertNotNull(this.listener.getSessionState());
175 final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.update.lsp.args.ArgumentsBuilder updArgsBuilder = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.update.lsp.args.ArgumentsBuilder();
176 updArgsBuilder.setEro(createEroWithIpPrefixes(Lists.newArrayList(eroIpPrefix, dstIpPrefix)));
177 updArgsBuilder.addAugmentation(Arguments3.class, new Arguments3Builder().setLsp(new LspBuilder().setDelegate(true).setAdministrative(true).build()).build());
178 final UpdateLspInput update = new UpdateLspInputBuilder().setArguments(updArgsBuilder.build()).setName(TUNNEL_NAME).setNetworkTopologyRef(new NetworkTopologyRef(TOPO_IID)).setNode(nodeId).build();
179 this.topologyRpcs.updateLsp(update);
180 assertEquals(2, this.receivedMsgs.size());
181 assertTrue(this.receivedMsgs.get(1) instanceof Pcupd);
182 final Pcupd updateMsg = (Pcupd) this.receivedMsgs.get(1);
183 final Updates upd = updateMsg.getPcupdMessage().getUpdates().get(0);
184 final long srpId2 = upd.getSrp().getOperationId().getValue();
185 final Tlvs tlvs2 = createLspTlvs(upd.getLsp().getPlspId().getValue(), false,
186 newDestinationAddress, testAddress, testAddress, Optional.absent());
187 final Pcrpt pcRpt2 = MsgBuilderUtil.createPcRtpMessage(new LspBuilder(upd.getLsp()).setTlvs(tlvs2).setSync(true).setRemove(false).setOperational(OperationalStatus.Active).build(), Optional.of(MsgBuilderUtil.createSrp(srpId2)), MsgBuilderUtil.createPath(upd.getPath().getEro().getSubobject()));
188 this.listener.onMessage(this.session, pcRpt2);
190 topology = getTopology().get();
191 pcc = topology.getNode().get(0).getAugmentation(Node1.class).getPathComputationClient();
192 assertEquals(1, pcc.getReportedLsp().size());
193 reportedLsp = pcc.getReportedLsp().get(0);
194 assertEquals(TUNNEL_NAME, reportedLsp.getName());
195 assertEquals(1, reportedLsp.getPath().size());
196 path = reportedLsp.getPath().get(0);
197 assertEquals(2, path.getEro().getSubobject().size());
198 assertEquals(dstIpPrefix, getLastEroIpPrefix(path.getEro()));
200 assertEquals(1, this.listener.getDelegatedLspsCount().intValue());
201 assertTrue(this.listener.getSynchronized());
202 assertTrue(this.listener.getStatefulMessages().getLastReceivedRptMsgTimestamp() > 0);
203 assertEquals(3, this.listener.getStatefulMessages().getReceivedRptMsgCount().intValue());
204 assertEquals(1, this.listener.getStatefulMessages().getSentInitMsgCount().intValue());
205 assertEquals(1, this.listener.getStatefulMessages().getSentUpdMsgCount().intValue());
206 assertTrue(this.listener.getReplyTime().getAverageTime() > 0);
207 assertTrue(this.listener.getReplyTime().getMaxTime() > 0);
208 assertFalse(this.listener.getPeerCapabilities().getActive());
209 assertTrue(this.listener.getPeerCapabilities().getInstantiation());
210 assertTrue(this.listener.getPeerCapabilities().getStateful());
212 // ensure-operational
213 final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.ensure.lsp.operational.args.ArgumentsBuilder ensureArgs = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.ensure.lsp.operational.args.ArgumentsBuilder();
214 ensureArgs.addAugmentation(Arguments1.class, new Arguments1Builder().setOperational(OperationalStatus.Active).build());
215 final EnsureLspOperationalInput ensure = new EnsureLspOperationalInputBuilder().setArguments(ensureArgs.build()).setName(TUNNEL_NAME).setNetworkTopologyRef(new NetworkTopologyRef(TOPO_IID)).setNode(nodeId).build();
216 final OperationResult result = this.topologyRpcs.ensureLspOperational(ensure).get().getResult();
218 assertNull(result.getFailure());
221 final RemoveLspInput remove = new RemoveLspInputBuilder().setName(TUNNEL_NAME).setNetworkTopologyRef(new NetworkTopologyRef(TOPO_IID)).setNode(nodeId).build();
222 this.topologyRpcs.removeLsp(remove);
223 assertEquals(3, this.receivedMsgs.size());
224 assertTrue(this.receivedMsgs.get(2) instanceof Pcinitiate);
225 final Pcinitiate pcinitiate2 = (Pcinitiate) this.receivedMsgs.get(2);
226 final Requests req2 = pcinitiate2.getPcinitiateMessage().getRequests().get(0);
227 final long srpId3 = req2.getSrp().getOperationId().getValue();
228 final Tlvs tlvs3 = createLspTlvs(req2.getLsp().getPlspId().getValue(), false,
229 testAddress, testAddress, testAddress, Optional.absent());
230 final Pcrpt pcRpt3 = MsgBuilderUtil.createPcRtpMessage(new LspBuilder(req2.getLsp()).setTlvs(tlvs3).setRemove(true).setSync(true).setOperational(OperationalStatus.Down).build(), Optional.of(MsgBuilderUtil.createSrp(srpId3)), MsgBuilderUtil.createPath(Collections.emptyList()));
231 this.listener.onMessage(this.session, pcRpt3);
232 // check if lsp was removed
233 topology = getTopology().get();
234 pcc = topology.getNode().get(0).getAugmentation(Node1.class).getPathComputationClient();
235 assertEquals(0, pcc.getReportedLsp().size());
237 assertEquals(0, this.listener.getDelegatedLspsCount().intValue());
238 assertTrue(this.listener.getSynchronized());
239 assertTrue(this.listener.getStatefulMessages().getLastReceivedRptMsgTimestamp() > 0);
240 assertEquals(4, this.listener.getStatefulMessages().getReceivedRptMsgCount().intValue());
241 assertEquals(2, this.listener.getStatefulMessages().getSentInitMsgCount().intValue());
242 assertEquals(1, this.listener.getStatefulMessages().getSentUpdMsgCount().intValue());
243 this.listener.resetStats();
244 assertEquals(0, this.listener.getStatefulMessages().getLastReceivedRptMsgTimestamp().longValue());
245 assertEquals(0, this.listener.getStatefulMessages().getReceivedRptMsgCount().intValue());
246 assertEquals(0, this.listener.getStatefulMessages().getSentInitMsgCount().intValue());
247 assertEquals(0, this.listener.getStatefulMessages().getSentUpdMsgCount().intValue());
248 assertEquals(0, this.listener.getReplyTime().getAverageTime().longValue());
249 assertEquals(0, this.listener.getReplyTime().getMaxTime().longValue());
250 assertEquals(0, this.listener.getReplyTime().getMinTime().longValue());
254 public void testOnUnhandledErrorMessage() {
255 final Message errorMsg = AbstractMessageParser.createErrorMsg(PCEPErrors.NON_ZERO_PLSPID, Optional.absent());
256 this.listener.onSessionUp(this.session);
257 assertTrue(this.listener.onMessage(Optional.<AbstractTopologySessionListener.MessageContext>absent().orNull(), errorMsg));
261 public void testOnErrorMessage() throws InterruptedException, ExecutionException {
262 final Message errorMsg = MsgBuilderUtil.createErrorMsg(PCEPErrors.NON_ZERO_PLSPID, 1L);
263 this.listener.onSessionUp(this.session);
264 final Future<RpcResult<AddLspOutput>> futureOutput = this.topologyRpcs.addLsp(createAddLspInput());
265 this.listener.onMessage(this.session, errorMsg);
267 final AddLspOutput output = futureOutput.get().getResult();
268 assertEquals(FailureType.Failed ,output.getFailure());
269 assertEquals(1, output.getError().size());
270 final ErrorObject err = output.getError().get(0).getErrorObject();
271 assertEquals(PCEPErrors.NON_ZERO_PLSPID.getErrorType(), err.getType().shortValue());
272 assertEquals(PCEPErrors.NON_ZERO_PLSPID.getErrorValue(), err.getValue().shortValue());
276 public void testOnSessionDown() throws InterruptedException, ExecutionException {
277 this.listener.onSessionUp(this.session);
279 final Future<RpcResult<AddLspOutput>> futureOutput = this.topologyRpcs.addLsp(createAddLspInput());
280 this.listener.onSessionDown(this.session, new IllegalArgumentException());
281 final AddLspOutput output = futureOutput.get().getResult();
282 // deal with unsent request after session down
283 assertEquals(FailureType.Unsent, output.getFailure());
287 public void testOnSessionTermination() throws UnknownHostException, InterruptedException, ExecutionException {
288 this.listener.onSessionUp(this.session);
291 this.topologyRpcs.addLsp(createAddLspInput());
292 final Pcinitiate pcinitiate = (Pcinitiate) this.receivedMsgs.get(0);
293 final Requests req = pcinitiate.getPcinitiateMessage().getRequests().get(0);
294 final long srpId = req.getSrp().getOperationId().getValue();
295 final Tlvs tlvs = createLspTlvs(req.getLsp().getPlspId().getValue(), true,
296 testAddress, testAddress, testAddress, Optional.absent());
297 final Pcrpt pcRpt = MsgBuilderUtil.createPcRtpMessage(new LspBuilder(req.getLsp()).setTlvs(tlvs).setSync(true).setRemove(false).setOperational(OperationalStatus.Active).build(), Optional.of(MsgBuilderUtil.createSrp(srpId)), MsgBuilderUtil.createPath(req.getEro().getSubobject()));
298 this.listener.onMessage(this.session, pcRpt);
299 assertEquals(1, getTopology().get().getNode().size());
301 // node should be removed after termination
302 this.listener.onSessionTerminated(this.session, new PCEPCloseTermination(TerminationReason.UNKNOWN));
303 assertEquals(0, getTopology().get().getNode().size());
307 public void testUnknownLsp() throws Exception {
308 final List<Reports> reports = Lists.newArrayList(new ReportsBuilder().setPath(new PathBuilder().setEro(new EroBuilder().build()).build()).setLsp(
309 new LspBuilder().setPlspId(new PlspId(5L)).setSync(false).setRemove(false).setTlvs(
310 new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.lsp.object.lsp.TlvsBuilder().setLspIdentifiers(new LspIdentifiersBuilder().setLspId(new LspId(1L)).build()).setSymbolicPathName(
311 new SymbolicPathNameBuilder().setPathName(new SymbolicPathName(new byte[] { 22, 34 })).build()).build()).build()).build());
312 final Pcrpt rptmsg = new PcrptBuilder().setPcrptMessage(new PcrptMessageBuilder().setReports(reports).build()).build();
313 this.listener.onSessionUp(this.session);
314 this.listener.onMessage(this.session, rptmsg);
315 final Topology topology = getTopology().get();
316 assertFalse(topology.getNode().isEmpty());
320 public void testUpdateUnknownLsp() throws InterruptedException, ExecutionException {
321 this.listener.onSessionUp(this.session);
322 final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.update.lsp.args.ArgumentsBuilder updArgsBuilder = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.update.lsp.args.ArgumentsBuilder();
323 updArgsBuilder.setEro(createEroWithIpPrefixes(Lists.newArrayList(eroIpPrefix, dstIpPrefix)));
324 updArgsBuilder.addAugmentation(Arguments3.class, new Arguments3Builder().setLsp(new LspBuilder().setDelegate(true).setAdministrative(true).build()).build());
325 final UpdateLspInput update = new UpdateLspInputBuilder().setArguments(updArgsBuilder.build()).setName(TUNNEL_NAME).setNetworkTopologyRef(new NetworkTopologyRef(TOPO_IID)).setNode(nodeId).build();
326 final UpdateLspOutput result = this.topologyRpcs.updateLsp(update).get().getResult();
327 assertEquals(FailureType.Unsent, result.getFailure());
328 assertEquals(1, result.getError().size());
329 final ErrorObject errorObject = result.getError().get(0).getErrorObject();
330 assertNotNull(errorObject);
331 assertEquals(PCEPErrors.UNKNOWN_PLSP_ID, PCEPErrors.forValue(errorObject.getType(), errorObject.getValue()));
335 public void testRemoveUnknownLsp() throws InterruptedException, ExecutionException {
336 this.listener.onSessionUp(this.session);
337 final RemoveLspInput remove = new RemoveLspInputBuilder().setName(TUNNEL_NAME).setNetworkTopologyRef(new NetworkTopologyRef(TOPO_IID)).setNode(nodeId).build();
338 final OperationResult result = this.topologyRpcs.removeLsp(remove).get().getResult();
339 assertEquals(FailureType.Unsent, result.getFailure());
340 assertEquals(1, result.getError().size());
341 final ErrorObject errorObject = result.getError().get(0).getErrorObject();
342 assertNotNull(errorObject);
343 assertEquals(PCEPErrors.UNKNOWN_PLSP_ID, PCEPErrors.forValue(errorObject.getType(), errorObject.getValue()));
347 public void testAddAlreadyExistingLsp() throws UnknownHostException, InterruptedException, ExecutionException {
348 this.listener.onSessionUp(this.session);
349 this.topologyRpcs.addLsp(createAddLspInput());
350 assertEquals(1, this.receivedMsgs.size());
351 assertTrue(this.receivedMsgs.get(0) instanceof Pcinitiate);
352 final Pcinitiate pcinitiate = (Pcinitiate) this.receivedMsgs.get(0);
353 final Requests req = pcinitiate.getPcinitiateMessage().getRequests().get(0);
354 final long srpId = req.getSrp().getOperationId().getValue();
355 final Tlvs tlvs = createLspTlvs(req.getLsp().getPlspId().getValue(), true,
356 testAddress, testAddress, testAddress, Optional.absent());
357 final Pcrpt pcRpt = MsgBuilderUtil.createPcRtpMessage(new LspBuilder(req.getLsp()).setTlvs(tlvs).setPlspId(new PlspId(1L)).setSync(false).setRemove(false).setOperational(OperationalStatus.Active).build(), Optional.of(MsgBuilderUtil.createSrp(srpId)), MsgBuilderUtil.createPath(req.getEro().getSubobject()));
358 this.listener.onMessage(this.session, pcRpt);
360 //try to add already existing LSP
361 final AddLspOutput result = this.topologyRpcs.addLsp(createAddLspInput()).get().getResult();
362 assertEquals(FailureType.Unsent, result.getFailure());
363 assertEquals(1, result.getError().size());
364 final ErrorObject errorObject = result.getError().get(0).getErrorObject();
365 assertNotNull(errorObject);
366 assertEquals(PCEPErrors.USED_SYMBOLIC_PATH_NAME, PCEPErrors.forValue(errorObject.getType(), errorObject.getValue()));
370 public void testPccResponseTimeout() throws InterruptedException, ExecutionException {
371 this.listener.onSessionUp(this.session);
372 Future<RpcResult<AddLspOutput>> addLspResult = this.topologyRpcs.addLsp(createAddLspInput());
374 addLspResult.get(2, TimeUnit.SECONDS);
376 } catch (Exception e) {
377 assertTrue(e instanceof TimeoutException);
379 Thread.sleep(AbstractPCEPSessionTest.RPC_TIMEOUT);
380 RpcResult<AddLspOutput> rpcResult = addLspResult.get();
381 assertNotNull(rpcResult);
382 assertEquals(rpcResult.getResult().getFailure(), FailureType.Unsent);
386 protected Open getLocalPref() {
387 return new OpenBuilder(super.getLocalPref()).setTlvs(new TlvsBuilder().addAugmentation(Tlvs1.class, new Tlvs1Builder().setStateful(new StatefulBuilder()
388 .addAugmentation(Stateful1.class, new Stateful1Builder().setInitiation(Boolean.TRUE).build())
389 .addAugmentation(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.pcep.sync.optimizations.rev150714.Stateful1.class, new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.pcep.sync.optimizations.rev150714.Stateful1Builder().setTriggeredInitialSync(Boolean.TRUE).build())
390 .build()).build()).build()).build();
394 protected Open getRemotePref() {
395 return getLocalPref();
398 private AddLspInput createAddLspInput() {
399 final ArgumentsBuilder argsBuilder = new ArgumentsBuilder();
400 final Ipv4CaseBuilder ipv4Builder = new Ipv4CaseBuilder();
401 ipv4Builder.setIpv4(new Ipv4Builder().setSourceIpv4Address(new Ipv4Address(testAddress)).setDestinationIpv4Address(new Ipv4Address(testAddress)).build());
402 argsBuilder.setEndpointsObj(new EndpointsObjBuilder().setAddressFamily(ipv4Builder.build()).build());
403 argsBuilder.setEro(createEroWithIpPrefixes(Lists.newArrayList(eroIpPrefix)));
404 argsBuilder.addAugmentation(Arguments2.class, new Arguments2Builder().setLsp(new LspBuilder().setDelegate(true).setAdministrative(true).build()).build());
405 return new AddLspInputBuilder().setName(TUNNEL_NAME).setArguments(argsBuilder.build()).setNetworkTopologyRef(new NetworkTopologyRef(TOPO_IID)).setNode(nodeId).build();