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