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.opendaylight.protocol.pcep.pcc.mock.MsgBuilderUtil.createLspTlvs;
18 import com.google.common.base.Optional;
19 import com.google.common.collect.Lists;
20 import java.net.UnknownHostException;
21 import java.util.Collections;
22 import java.util.List;
23 import java.util.concurrent.ExecutionException;
24 import java.util.concurrent.Future;
25 import org.junit.Before;
26 import org.junit.Test;
27 import org.opendaylight.controller.config.yang.pcep.topology.provider.SessionState;
28 import org.opendaylight.protocol.pcep.PCEPCloseTermination;
29 import org.opendaylight.protocol.pcep.TerminationReason;
30 import org.opendaylight.protocol.pcep.pcc.mock.MsgBuilderUtil;
31 import org.opendaylight.protocol.pcep.spi.AbstractMessageParser;
32 import org.opendaylight.protocol.pcep.spi.PCEPErrors;
33 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.topology.rev140113.NetworkTopologyRef;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.initiated.rev131126.Pcinitiate;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.initiated.rev131126.Stateful1;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.initiated.rev131126.Stateful1Builder;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.initiated.rev131126.pcinitiate.message.pcinitiate.message.Requests;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.Arguments1;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.Arguments1Builder;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.Arguments2;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.Arguments2Builder;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.Arguments3;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.Arguments3Builder;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.OperationalStatus;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.Pcrpt;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.PcrptBuilder;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.Pcupd;
49 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.PlspId;
50 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.SymbolicPathName;
51 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.Tlvs1;
52 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.Tlvs1Builder;
53 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.lsp.identifiers.tlv.LspIdentifiersBuilder;
54 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.lsp.object.LspBuilder;
55 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.lsp.object.lsp.Tlvs;
56 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.pcrpt.message.PcrptMessageBuilder;
57 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.pcrpt.message.pcrpt.message.Reports;
58 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.pcrpt.message.pcrpt.message.ReportsBuilder;
59 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.pcrpt.message.pcrpt.message.reports.PathBuilder;
60 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.pcupd.message.pcupd.message.Updates;
61 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.stateful.capability.tlv.StatefulBuilder;
62 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.symbolic.path.name.tlv.SymbolicPathNameBuilder;
63 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Message;
64 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.endpoints.address.family.Ipv4CaseBuilder;
65 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.endpoints.address.family.ipv4._case.Ipv4Builder;
66 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.endpoints.object.EndpointsObjBuilder;
67 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.EroBuilder;
68 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.ero.Subobject;
69 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.Open;
70 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.OpenBuilder;
71 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.open.TlvsBuilder;
72 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcep.error.object.ErrorObject;
73 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.rp.object.Rp;
74 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.LspId;
75 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.AddLspInput;
76 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.AddLspInputBuilder;
77 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.AddLspOutput;
78 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.EnsureLspOperationalInput;
79 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.EnsureLspOperationalInputBuilder;
80 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.FailureType;
81 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.Node1;
82 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.OperationResult;
83 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.RemoveLspInput;
84 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.RemoveLspInputBuilder;
85 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.UpdateLspInput;
86 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.UpdateLspInputBuilder;
87 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.UpdateLspOutput;
88 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.add.lsp.args.ArgumentsBuilder;
89 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.pcep.client.attributes.PathComputationClient;
90 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.pcep.client.attributes.path.computation.client.ReportedLsp;
91 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.pcep.client.attributes.path.computation.client.reported.lsp.Path;
92 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
93 import org.opendaylight.yangtools.yang.common.RpcResult;
95 public class Stateful07TopologySessionListenerTest extends AbstractPCEPSessionTest<Stateful07TopologySessionListenerFactory> {
97 private static final String TUNNEL_NAME = "pcc_" + TEST_ADDRESS + "_tunnel_0";
99 private Stateful07TopologySessionListener listener;
103 public void setUp() throws Exception {
105 this.listener = (Stateful07TopologySessionListener) getSessionListener();
109 public void testStateful07TopologySessionListener() throws Exception {
110 this.listener.onSessionUp(this.session);
112 assertEquals(TEST_ADDRESS, this.listener.getPeerId());
113 final SessionState state = this.listener.getSessionState();
114 assertNotNull(state);
115 assertEquals(DEAD_TIMER, state.getLocalPref().getDeadtimer().shortValue());
116 assertEquals(KEEP_ALIVE, state.getLocalPref().getKeepalive().shortValue());
117 assertEquals(0, state.getLocalPref().getSessionId().intValue());
118 assertEquals(TEST_ADDRESS, state.getLocalPref().getIpAddress());
119 assertEquals(DEAD_TIMER, state.getPeerPref().getDeadtimer().shortValue());
120 assertEquals(KEEP_ALIVE, state.getPeerPref().getKeepalive().shortValue());
121 assertEquals(0, state.getPeerPref().getSessionId().intValue());
122 assertEquals(TEST_ADDRESS, state.getPeerPref().getIpAddress());
125 this.topologyRpcs.addLsp(createAddLspInput());
126 assertEquals(1, this.receivedMsgs.size());
127 assertTrue(this.receivedMsgs.get(0) instanceof Pcinitiate);
128 final Pcinitiate pcinitiate = (Pcinitiate) this.receivedMsgs.get(0);
129 final Requests req = pcinitiate.getPcinitiateMessage().getRequests().get(0);
130 final long srpId = req.getSrp().getOperationId().getValue();
131 final Tlvs tlvs = createLspTlvs(req.getLsp().getPlspId().getValue(), true,
132 TEST_ADDRESS, TEST_ADDRESS, TEST_ADDRESS, Optional.<byte[]>absent());
133 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()));
134 final Pcrpt esm = MsgBuilderUtil.createPcRtpMessage(new LspBuilder().setSync(false).build(), Optional.of(MsgBuilderUtil.createSrp(0L)), null);
135 this.listener.onMessage(this.session, esm);
137 final Optional<Topology> topoOptional = getTopology();
138 assertTrue(topoOptional.isPresent());
139 Topology topology = topoOptional.get();
140 assertEquals(1, topology.getNode().size());
141 final Node1 node = topology.getNode().get(0).getAugmentation(Node1.class);
143 PathComputationClient pcc = node.getPathComputationClient();
144 assertEquals(TEST_ADDRESS, pcc.getIpAddress().getIpv4Address().getValue());
145 // reported lsp so far empty, has not received response (PcRpt) yet
146 assertTrue(pcc.getReportedLsp().isEmpty());
147 this.listener.onMessage(this.session, pcRpt);
149 topology = getTopology().get();
150 pcc = topology.getNode().get(0).getAugmentation(Node1.class).getPathComputationClient();
151 assertEquals(1, pcc.getReportedLsp().size());
152 ReportedLsp reportedLsp = pcc.getReportedLsp().get(0);
153 assertEquals(TUNNEL_NAME, reportedLsp.getName());
154 assertEquals(1, reportedLsp.getPath().size());
155 Path path = reportedLsp.getPath().get(0);
156 assertEquals(1, path.getEro().getSubobject().size());
157 assertEquals(ERO_IP_PREFIX, getLastEroIpPrefix(path.getEro()));
159 assertEquals(1, this.listener.getDelegatedLspsCount().intValue());
160 assertTrue(this.listener.getSynchronized());
161 assertTrue(this.listener.getStatefulMessages().getLastReceivedRptMsgTimestamp() > 0);
162 assertEquals(2, this.listener.getStatefulMessages().getReceivedRptMsgCount().intValue());
163 assertEquals(1, this.listener.getStatefulMessages().getSentInitMsgCount().intValue());
164 assertEquals(0, this.listener.getStatefulMessages().getSentUpdMsgCount().intValue());
165 assertNotNull(this.listener.getSessionState());
168 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();
169 updArgsBuilder.setEro(createEroWithIpPrefixes(Lists.newArrayList(ERO_IP_PREFIX, DST_IP_PREFIX)));
170 updArgsBuilder.addAugmentation(Arguments3.class, new Arguments3Builder().setLsp(new LspBuilder().setDelegate(true).setAdministrative(true).build()).build());
171 final UpdateLspInput update = new UpdateLspInputBuilder().setArguments(updArgsBuilder.build()).setName(TUNNEL_NAME).setNetworkTopologyRef(new NetworkTopologyRef(TOPO_IID)).setNode(NODE_ID).build();
172 this.topologyRpcs.updateLsp(update);
173 assertEquals(2, this.receivedMsgs.size());
174 assertTrue(this.receivedMsgs.get(1) instanceof Pcupd);
175 final Pcupd updateMsg = (Pcupd) this.receivedMsgs.get(1);
176 final Updates upd = updateMsg.getPcupdMessage().getUpdates().get(0);
177 final long srpId2 = upd.getSrp().getOperationId().getValue();
178 final Tlvs tlvs2 = createLspTlvs(upd.getLsp().getPlspId().getValue(), false,
179 NEW_DESTINATION_ADDRESS, TEST_ADDRESS, TEST_ADDRESS, Optional.<byte[]>absent());
180 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()));
181 this.listener.onMessage(this.session, pcRpt2);
183 topology = getTopology().get();
184 pcc = topology.getNode().get(0).getAugmentation(Node1.class).getPathComputationClient();
185 assertEquals(1, pcc.getReportedLsp().size());
186 reportedLsp = pcc.getReportedLsp().get(0);
187 assertEquals(TUNNEL_NAME, reportedLsp.getName());
188 assertEquals(1, reportedLsp.getPath().size());
189 path = reportedLsp.getPath().get(0);
190 assertEquals(2, path.getEro().getSubobject().size());
191 assertEquals(DST_IP_PREFIX, getLastEroIpPrefix(path.getEro()));
193 assertEquals(1, this.listener.getDelegatedLspsCount().intValue());
194 assertTrue(this.listener.getSynchronized());
195 assertTrue(this.listener.getStatefulMessages().getLastReceivedRptMsgTimestamp() > 0);
196 assertEquals(3, this.listener.getStatefulMessages().getReceivedRptMsgCount().intValue());
197 assertEquals(1, this.listener.getStatefulMessages().getSentInitMsgCount().intValue());
198 assertEquals(1, this.listener.getStatefulMessages().getSentUpdMsgCount().intValue());
199 assertTrue(this.listener.getReplyTime().getAverageTime() > 0);
200 assertTrue(this.listener.getReplyTime().getMaxTime() > 0);
201 assertFalse(this.listener.getPeerCapabilities().getActive());
202 assertTrue(this.listener.getPeerCapabilities().getInstantiation());
203 assertTrue(this.listener.getPeerCapabilities().getStateful());
205 // ensure-operational
206 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();
207 ensureArgs.addAugmentation(Arguments1.class, new Arguments1Builder().setOperational(OperationalStatus.Active).build());
208 final EnsureLspOperationalInput ensure = new EnsureLspOperationalInputBuilder().setArguments(ensureArgs.build()).setName(TUNNEL_NAME).setNetworkTopologyRef(new NetworkTopologyRef(TOPO_IID)).setNode(NODE_ID).build();
209 final OperationResult result = this.topologyRpcs.ensureLspOperational(ensure).get().getResult();
211 assertNull(result.getFailure());
214 final RemoveLspInput remove = new RemoveLspInputBuilder().setName(TUNNEL_NAME).setNetworkTopologyRef(new NetworkTopologyRef(TOPO_IID)).setNode(NODE_ID).build();
215 this.topologyRpcs.removeLsp(remove);
216 assertEquals(3, this.receivedMsgs.size());
217 assertTrue(this.receivedMsgs.get(2) instanceof Pcinitiate);
218 final Pcinitiate pcinitiate2 = (Pcinitiate) this.receivedMsgs.get(2);
219 final Requests req2 = pcinitiate2.getPcinitiateMessage().getRequests().get(0);
220 final long srpId3 = req2.getSrp().getOperationId().getValue();
221 final Tlvs tlvs3 = createLspTlvs(req2.getLsp().getPlspId().getValue(), false,
222 TEST_ADDRESS, TEST_ADDRESS, TEST_ADDRESS, Optional.<byte[]>absent());
223 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.<Subobject>emptyList()));
224 this.listener.onMessage(this.session, pcRpt3);
225 // check if lsp was removed
226 topology = getTopology().get();
227 pcc = topology.getNode().get(0).getAugmentation(Node1.class).getPathComputationClient();
228 assertEquals(0, pcc.getReportedLsp().size());
230 assertEquals(0, this.listener.getDelegatedLspsCount().intValue());
231 assertTrue(this.listener.getSynchronized());
232 assertTrue(this.listener.getStatefulMessages().getLastReceivedRptMsgTimestamp() > 0);
233 assertEquals(4, this.listener.getStatefulMessages().getReceivedRptMsgCount().intValue());
234 assertEquals(2, this.listener.getStatefulMessages().getSentInitMsgCount().intValue());
235 assertEquals(1, this.listener.getStatefulMessages().getSentUpdMsgCount().intValue());
236 this.listener.resetStats();
237 assertEquals(0, this.listener.getStatefulMessages().getLastReceivedRptMsgTimestamp().longValue());
238 assertEquals(0, this.listener.getStatefulMessages().getReceivedRptMsgCount().intValue());
239 assertEquals(0, this.listener.getStatefulMessages().getSentInitMsgCount().intValue());
240 assertEquals(0, this.listener.getStatefulMessages().getSentUpdMsgCount().intValue());
241 assertEquals(0, this.listener.getReplyTime().getAverageTime().longValue());
242 assertEquals(0, this.listener.getReplyTime().getMaxTime().longValue());
243 assertEquals(0, this.listener.getReplyTime().getMinTime().longValue());
247 public void testOnUnhandledErrorMessage() {
248 final Message errorMsg = AbstractMessageParser.createErrorMsg(PCEPErrors.NON_ZERO_PLSPID, Optional.<Rp>absent());
249 this.listener.onSessionUp(this.session);
250 assertTrue(this.listener.onMessage(Optional.<AbstractTopologySessionListener.MessageContext>absent().orNull(), errorMsg));
254 public void testOnErrorMessage() throws InterruptedException, ExecutionException {
255 final Message errorMsg = MsgBuilderUtil.createErrorMsg(PCEPErrors.NON_ZERO_PLSPID, 1L);
256 this.listener.onSessionUp(this.session);
257 final Future<RpcResult<AddLspOutput>> futureOutput = this.topologyRpcs.addLsp(createAddLspInput());
258 this.listener.onMessage(this.session, errorMsg);
260 final AddLspOutput output = futureOutput.get().getResult();
261 assertEquals(FailureType.Failed ,output.getFailure());
262 assertEquals(1, output.getError().size());
263 final ErrorObject err = output.getError().get(0).getErrorObject();
264 assertEquals(PCEPErrors.NON_ZERO_PLSPID.getErrorType(), err.getType().shortValue());
265 assertEquals(PCEPErrors.NON_ZERO_PLSPID.getErrorValue(), err.getValue().shortValue());
269 public void testOnSessionDown() throws InterruptedException, ExecutionException {
270 this.listener.onSessionUp(this.session);
272 final Future<RpcResult<AddLspOutput>> futureOutput = this.topologyRpcs.addLsp(createAddLspInput());
273 this.listener.onSessionDown(this.session, new IllegalArgumentException());
274 final AddLspOutput output = futureOutput.get().getResult();
275 // deal with unsent request after session down
276 assertEquals(FailureType.Unsent, output.getFailure());
280 public void testOnSessionTermination() throws UnknownHostException, InterruptedException, ExecutionException {
281 this.listener.onSessionUp(this.session);
284 this.topologyRpcs.addLsp(createAddLspInput());
285 final Pcinitiate pcinitiate = (Pcinitiate) this.receivedMsgs.get(0);
286 final Requests req = pcinitiate.getPcinitiateMessage().getRequests().get(0);
287 final long srpId = req.getSrp().getOperationId().getValue();
288 final Tlvs tlvs = createLspTlvs(req.getLsp().getPlspId().getValue(), true,
289 TEST_ADDRESS, TEST_ADDRESS, TEST_ADDRESS, Optional.<byte[]>absent());
290 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()));
291 this.listener.onMessage(this.session, pcRpt);
292 assertEquals(1, getTopology().get().getNode().size());
294 // node should be removed after termination
295 this.listener.onSessionTerminated(this.session, new PCEPCloseTermination(TerminationReason.UNKNOWN));
296 assertEquals(0, getTopology().get().getNode().size());
300 public void testUnknownLsp() throws Exception {
301 final List<Reports> reports = Lists.newArrayList(new ReportsBuilder().setPath(new PathBuilder().setEro(new EroBuilder().build()).build()).setLsp(
302 new LspBuilder().setPlspId(new PlspId(5L)).setSync(false).setRemove(false).setTlvs(
303 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(
304 new SymbolicPathNameBuilder().setPathName(new SymbolicPathName(new byte[] { 22, 34 })).build()).build()).build()).build());
305 final Pcrpt rptmsg = new PcrptBuilder().setPcrptMessage(new PcrptMessageBuilder().setReports(reports).build()).build();
306 this.session.sessionUp();
307 this.session.handleMessage(rptmsg);
308 final Topology topology = getTopology().get();
309 assertFalse(topology.getNode().isEmpty());
313 public void testUpdateUnknownLsp() throws InterruptedException, ExecutionException {
314 this.listener.onSessionUp(this.session);
315 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();
316 updArgsBuilder.setEro(createEroWithIpPrefixes(Lists.newArrayList(ERO_IP_PREFIX, DST_IP_PREFIX)));
317 updArgsBuilder.addAugmentation(Arguments3.class, new Arguments3Builder().setLsp(new LspBuilder().setDelegate(true).setAdministrative(true).build()).build());
318 final UpdateLspInput update = new UpdateLspInputBuilder().setArguments(updArgsBuilder.build()).setName(TUNNEL_NAME).setNetworkTopologyRef(new NetworkTopologyRef(TOPO_IID)).setNode(NODE_ID).build();
319 final UpdateLspOutput result = this.topologyRpcs.updateLsp(update).get().getResult();
320 assertEquals(FailureType.Unsent, result.getFailure());
321 assertEquals(1, result.getError().size());
322 final ErrorObject errorObject = result.getError().get(0).getErrorObject();
323 assertNotNull(errorObject);
324 assertEquals(PCEPErrors.UNKNOWN_PLSP_ID, PCEPErrors.forValue(errorObject.getType(), errorObject.getValue()));
328 public void testRemoveUnknownLsp() throws InterruptedException, ExecutionException {
329 this.listener.onSessionUp(this.session);
330 final RemoveLspInput remove = new RemoveLspInputBuilder().setName(TUNNEL_NAME).setNetworkTopologyRef(new NetworkTopologyRef(TOPO_IID)).setNode(NODE_ID).build();
331 final OperationResult result = this.topologyRpcs.removeLsp(remove).get().getResult();
332 assertEquals(FailureType.Unsent, result.getFailure());
333 assertEquals(1, result.getError().size());
334 final ErrorObject errorObject = result.getError().get(0).getErrorObject();
335 assertNotNull(errorObject);
336 assertEquals(PCEPErrors.UNKNOWN_PLSP_ID, PCEPErrors.forValue(errorObject.getType(), errorObject.getValue()));
340 public void testAddAlreadyExistingLsp() throws UnknownHostException, InterruptedException, ExecutionException {
341 this.listener.onSessionUp(this.session);
342 this.topologyRpcs.addLsp(createAddLspInput());
343 assertEquals(1, this.receivedMsgs.size());
344 assertTrue(this.receivedMsgs.get(0) instanceof Pcinitiate);
345 final Pcinitiate pcinitiate = (Pcinitiate) this.receivedMsgs.get(0);
346 final Requests req = pcinitiate.getPcinitiateMessage().getRequests().get(0);
347 final long srpId = req.getSrp().getOperationId().getValue();
348 final Tlvs tlvs = createLspTlvs(req.getLsp().getPlspId().getValue(), true,
349 TEST_ADDRESS, TEST_ADDRESS, TEST_ADDRESS, Optional.<byte[]>absent());
350 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()));
351 this.listener.onMessage(this.session, pcRpt);
353 //try to add already existing LSP
354 final AddLspOutput result = this.topologyRpcs.addLsp(createAddLspInput()).get().getResult();
355 assertEquals(FailureType.Unsent, result.getFailure());
356 assertEquals(1, result.getError().size());
357 final ErrorObject errorObject = result.getError().get(0).getErrorObject();
358 assertNotNull(errorObject);
359 assertEquals(PCEPErrors.USED_SYMBOLIC_PATH_NAME, PCEPErrors.forValue(errorObject.getType(), errorObject.getValue()));
363 protected Open getLocalPref() {
364 return new OpenBuilder(super.getLocalPref()).setTlvs(new TlvsBuilder().addAugmentation(Tlvs1.class, new Tlvs1Builder().setStateful(new StatefulBuilder().addAugmentation(Stateful1.class, new Stateful1Builder().setInitiation(Boolean.TRUE).build()).build()).build()).build()).build();
367 private AddLspInput createAddLspInput() {
368 final ArgumentsBuilder argsBuilder = new ArgumentsBuilder();
369 final Ipv4CaseBuilder ipv4Builder = new Ipv4CaseBuilder();
370 ipv4Builder.setIpv4(new Ipv4Builder().setSourceIpv4Address(new Ipv4Address(TEST_ADDRESS)).setDestinationIpv4Address(new Ipv4Address(TEST_ADDRESS)).build());
371 argsBuilder.setEndpointsObj(new EndpointsObjBuilder().setAddressFamily(ipv4Builder.build()).build());
372 argsBuilder.setEro(createEroWithIpPrefixes(Lists.newArrayList(ERO_IP_PREFIX)));
373 argsBuilder.addAugmentation(Arguments2.class, new Arguments2Builder().setLsp(new LspBuilder().setDelegate(true).setAdministrative(true).build()).build());
374 return new AddLspInputBuilder().setName(TUNNEL_NAME).setArguments(argsBuilder.build()).setNetworkTopologyRef(new NetworkTopologyRef(TOPO_IID)).setNode(NODE_ID).build();