Bug-2081: PCEP statistics
[bgpcep.git] / pcep / topology-provider / src / test / java / org / opendaylight / bgpcep / pcep / topology / provider / Stateful07TopologySessionListenerTest.java
1 /*
2  * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8
9 package org.opendaylight.bgpcep.pcep.topology.provider;
10
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
18 import com.google.common.base.Optional;
19 import com.google.common.collect.Lists;
20 import java.net.InetAddress;
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 org.junit.Before;
27 import org.junit.Test;
28 import org.opendaylight.controller.config.yang.pcep.topology.provider.SessionState;
29 import org.opendaylight.protocol.pcep.PCEPCloseTermination;
30 import org.opendaylight.protocol.pcep.TerminationReason;
31 import org.opendaylight.protocol.pcep.pcc.mock.MsgBuilderUtil;
32 import org.opendaylight.protocol.pcep.spi.AbstractMessageParser;
33 import org.opendaylight.protocol.pcep.spi.PCEPErrors;
34 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.topology.rev140113.NetworkTopologyRef;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.initiated.rev131126.Pcinitiate;
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.add.lsp.args.ArgumentsBuilder;
87 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.pcep.client.attributes.PathComputationClient;
88 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.pcep.client.attributes.path.computation.client.ReportedLsp;
89 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.pcep.client.attributes.path.computation.client.reported.lsp.Path;
90 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
91 import org.opendaylight.yangtools.yang.common.RpcResult;
92
93 public class Stateful07TopologySessionListenerTest extends AbstractPCEPSessionTest<Stateful07TopologySessionListenerFactory> {
94
95     private Stateful07TopologySessionListener listener;
96
97     @Before
98     public void setUp() throws Exception {
99         super.setUp();
100         this.listener = (Stateful07TopologySessionListener) this.manager.getSessionListener();
101     }
102
103     @Test
104     public void testStateful07TopologySessionListener() throws Exception {
105         this.listener.onSessionUp(this.session);
106
107         assertEquals(TEST_ADDRESS, this.listener.getPeerId());
108         final SessionState state = this.listener.getSessionState();
109         assertNotNull(state);
110         assertEquals(DEAD_TIMER, state.getLocalPref().getDeadtimer().shortValue());
111         assertEquals(KEEP_ALIVE, state.getLocalPref().getKeepalive().shortValue());
112         assertEquals(0, state.getLocalPref().getSessionId().intValue());
113         assertEquals(TEST_ADDRESS, state.getLocalPref().getIpAddress());
114         assertEquals(DEAD_TIMER, state.getPeerPref().getDeadtimer().shortValue());
115         assertEquals(KEEP_ALIVE, state.getPeerPref().getKeepalive().shortValue());
116         assertEquals(0, state.getPeerPref().getSessionId().intValue());
117         assertEquals(TEST_ADDRESS, state.getPeerPref().getIpAddress());
118
119         // add-lsp
120         this.topologyRpcs.addLsp(createAddLspInput());
121         assertEquals(1, this.receivedMsgs.size());
122         assertTrue(this.receivedMsgs.get(0) instanceof Pcinitiate);
123         final Pcinitiate pcinitiate = (Pcinitiate) this.receivedMsgs.get(0);
124         final Requests req = pcinitiate.getPcinitiateMessage().getRequests().get(0);
125         final long srpId = req.getSrp().getOperationId().getValue();
126         final InetAddress inetAddress = InetAddress.getByName(TEST_ADDRESS);
127         final Tlvs tlvs = createLspTlvs(req.getLsp().getPlspId().getValue(), true,
128                 inetAddress, inetAddress, inetAddress);
129         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()));
130         final Pcrpt esm = MsgBuilderUtil.createPcRtpMessage(new LspBuilder().setSync(false).build(), Optional.of(MsgBuilderUtil.createSrp(0L)), null);
131         this.listener.onMessage(this.session, esm);
132
133         final Optional<Topology> topoOptional = getTopology();
134         assertTrue(topoOptional.isPresent());
135         Topology topology = topoOptional.get();
136         assertEquals(1, topology.getNode().size());
137         final Node1 node = topology.getNode().get(0).getAugmentation(Node1.class);
138         assertNotNull(node);
139         PathComputationClient pcc = node.getPathComputationClient();
140         assertEquals(TEST_ADDRESS, pcc.getIpAddress().getIpv4Address().getValue());
141         // reported lsp so far empty, has not received response (PcRpt) yet
142         assertTrue(pcc.getReportedLsp().isEmpty());
143         this.listener.onMessage(this.session, pcRpt);
144         // check created lsp
145         topology = getTopology().get();
146         pcc = topology.getNode().get(0).getAugmentation(Node1.class).getPathComputationClient();
147         assertEquals(1, pcc.getReportedLsp().size());
148         ReportedLsp reportedLsp = pcc.getReportedLsp().get(0);
149         assertEquals(TEST_LSP_NAME, reportedLsp.getName());
150         assertEquals(1, reportedLsp.getPath().size());
151         Path path = reportedLsp.getPath().get(0);
152         assertEquals(1, path.getEro().getSubobject().size());
153         assertEquals(ERO_IP_PREFIX, getLastEroIpPrefix(path.getEro()));
154         // check stats
155         assertEquals(1, this.listener.getDelegatedLspsCount().intValue());
156         assertTrue(this.listener.getSynchronized());
157         assertTrue(this.listener.getStatefulMessages().getLastReceivedRptMsgTimestamp() > 0);
158         assertEquals(2, this.listener.getStatefulMessages().getReceivedRptMsgCount().intValue());
159         assertEquals(1, this.listener.getStatefulMessages().getSentInitMsgCount().intValue());
160         assertEquals(0, this.listener.getStatefulMessages().getSentUpdMsgCount().intValue());
161         assertNotNull(this.listener.getSessionState());
162
163         // update-lsp
164         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();
165         updArgsBuilder.setEro(createEroWithIpPrefixes(Lists.newArrayList(ERO_IP_PREFIX, DST_IP_PREFIX)));
166         updArgsBuilder.addAugmentation(Arguments3.class, new Arguments3Builder().setLsp(new LspBuilder().setDelegate(true).setAdministrative(true).build()).build());
167         final UpdateLspInput update = new UpdateLspInputBuilder().setArguments(updArgsBuilder.build()).setName(TEST_LSP_NAME).setNetworkTopologyRef(new NetworkTopologyRef(TOPO_IID)).setNode(NODE_ID).build();
168         this.topologyRpcs.updateLsp(update);
169         assertEquals(2, this.receivedMsgs.size());
170         assertTrue(this.receivedMsgs.get(1) instanceof Pcupd);
171         final Pcupd updateMsg = (Pcupd) this.receivedMsgs.get(1);
172         final Updates upd = updateMsg.getPcupdMessage().getUpdates().get(0);
173         final long srpId2 = upd.getSrp().getOperationId().getValue();
174         final Tlvs tlvs2 = createLspTlvs(upd.getLsp().getPlspId().getValue(), false,
175                 InetAddress.getByName(NEW_DESTINATION_ADDRESS), inetAddress, inetAddress);
176         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()));
177         this.listener.onMessage(this.session, pcRpt2);
178         //check updated lsp
179         topology = getTopology().get();
180         pcc = topology.getNode().get(0).getAugmentation(Node1.class).getPathComputationClient();
181         assertEquals(1, pcc.getReportedLsp().size());
182         reportedLsp = pcc.getReportedLsp().get(0);
183         assertEquals(TEST_LSP_NAME, reportedLsp.getName());
184         assertEquals(1, reportedLsp.getPath().size());
185         path = reportedLsp.getPath().get(0);
186         assertEquals(2, path.getEro().getSubobject().size());
187         assertEquals(DST_IP_PREFIX, getLastEroIpPrefix(path.getEro()));
188         // check stats
189         assertEquals(1, this.listener.getDelegatedLspsCount().intValue());
190         assertTrue(this.listener.getSynchronized());
191         assertTrue(this.listener.getStatefulMessages().getLastReceivedRptMsgTimestamp() > 0);
192         assertEquals(3, this.listener.getStatefulMessages().getReceivedRptMsgCount().intValue());
193         assertEquals(1, this.listener.getStatefulMessages().getSentInitMsgCount().intValue());
194         assertEquals(1, this.listener.getStatefulMessages().getSentUpdMsgCount().intValue());
195         assertTrue(this.listener.getReplyTime().getAverageTime() > 0);
196         assertTrue(this.listener.getReplyTime().getMaxTime() > 0);
197         assertFalse(this.listener.getPeerCapabilities().getActive());
198         assertFalse(this.listener.getPeerCapabilities().getInstantiation());
199         assertTrue(this.listener.getPeerCapabilities().getStateful());
200
201         // ensure-operational
202         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();
203         ensureArgs.addAugmentation(Arguments1.class, new Arguments1Builder().setOperational(OperationalStatus.Active).build());
204         final EnsureLspOperationalInput ensure = new EnsureLspOperationalInputBuilder().setArguments(ensureArgs.build()).setName(TEST_LSP_NAME).setNetworkTopologyRef(new NetworkTopologyRef(TOPO_IID)).setNode(NODE_ID).build();
205         final OperationResult result = this.topologyRpcs.ensureLspOperational(ensure).get().getResult();
206         //check result
207         assertNull(result.getFailure());
208
209         // remove-lsp
210         final RemoveLspInput remove = new RemoveLspInputBuilder().setName(TEST_LSP_NAME).setNetworkTopologyRef(new NetworkTopologyRef(TOPO_IID)).setNode(NODE_ID).build();
211         this.topologyRpcs.removeLsp(remove);
212         assertEquals(3, this.receivedMsgs.size());
213         assertTrue(this.receivedMsgs.get(2) instanceof Pcinitiate);
214         final Pcinitiate pcinitiate2 = (Pcinitiate) this.receivedMsgs.get(2);
215         final Requests req2 = pcinitiate2.getPcinitiateMessage().getRequests().get(0);
216         final long srpId3 = req2.getSrp().getOperationId().getValue();
217         final Tlvs tlvs3 = createLspTlvs(req2.getLsp().getPlspId().getValue(), false,
218                 inetAddress, inetAddress, inetAddress);
219         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()));
220         this.listener.onMessage(this.session, pcRpt3);
221         // check if lsp was removed
222         topology = getTopology().get();
223         pcc = topology.getNode().get(0).getAugmentation(Node1.class).getPathComputationClient();
224         assertEquals(0, pcc.getReportedLsp().size());
225         // check stats
226         assertEquals(0, this.listener.getDelegatedLspsCount().intValue());
227         assertTrue(this.listener.getSynchronized());
228         assertTrue(this.listener.getStatefulMessages().getLastReceivedRptMsgTimestamp() > 0);
229         assertEquals(4, this.listener.getStatefulMessages().getReceivedRptMsgCount().intValue());
230         assertEquals(2, this.listener.getStatefulMessages().getSentInitMsgCount().intValue());
231         assertEquals(1, this.listener.getStatefulMessages().getSentUpdMsgCount().intValue());
232         this.listener.resetStats();
233         assertEquals(0, this.listener.getStatefulMessages().getLastReceivedRptMsgTimestamp().longValue());
234         assertEquals(0, this.listener.getStatefulMessages().getReceivedRptMsgCount().intValue());
235         assertEquals(0, this.listener.getStatefulMessages().getSentInitMsgCount().intValue());
236         assertEquals(0, this.listener.getStatefulMessages().getSentUpdMsgCount().intValue());
237         assertEquals(0, this.listener.getReplyTime().getAverageTime().longValue());
238         assertEquals(0, this.listener.getReplyTime().getMaxTime().longValue());
239         assertEquals(0, this.listener.getReplyTime().getMinTime().longValue());
240     }
241
242     @Test
243     public void testOnUnhandledErrorMessage() {
244         final Message errorMsg = AbstractMessageParser.createErrorMsg(PCEPErrors.NON_ZERO_PLSPID, Optional.<Rp>absent());
245         this.listener.onSessionUp(this.session);
246         assertTrue(this.listener.onMessage(Optional.<AbstractTopologySessionListener.MessageContext>absent().orNull(), errorMsg));
247     }
248
249     @Test
250     public void testOnErrorMessage() throws InterruptedException, ExecutionException {
251         final Message errorMsg = MsgBuilderUtil.createErrorMsg(PCEPErrors.NON_ZERO_PLSPID, 1L);
252         this.listener.onSessionUp(this.session);
253         final Future<RpcResult<AddLspOutput>> futureOutput = this.topologyRpcs.addLsp(createAddLspInput());
254         this.listener.onMessage(this.session, errorMsg);
255
256         final AddLspOutput output = futureOutput.get().getResult();
257         assertEquals(FailureType.Failed ,output.getFailure());
258         assertEquals(1, output.getError().size());
259         final ErrorObject err = output.getError().get(0).getErrorObject();
260         assertEquals(PCEPErrors.NON_ZERO_PLSPID.getErrorType(), err.getType().shortValue());
261         assertEquals(PCEPErrors.NON_ZERO_PLSPID.getErrorValue(), err.getValue().shortValue());
262     }
263
264     @Test
265     public void testOnSessionDown() throws InterruptedException, ExecutionException {
266         this.listener.onSessionUp(this.session);
267         // send request
268         final Future<RpcResult<AddLspOutput>> futureOutput = this.topologyRpcs.addLsp(createAddLspInput());
269         this.listener.onSessionDown(this.session, new IllegalArgumentException());
270         final AddLspOutput output = futureOutput.get().getResult();
271         // deal with unsent request after session down
272         assertEquals(FailureType.Unsent, output.getFailure());
273     }
274
275     @Test
276     public void testOnSessionTermination() throws UnknownHostException, InterruptedException, ExecutionException {
277         this.listener.onSessionUp(this.session);
278
279         // create node
280         this.topologyRpcs.addLsp(createAddLspInput());
281         final Pcinitiate pcinitiate = (Pcinitiate) this.receivedMsgs.get(0);
282         final Requests req = pcinitiate.getPcinitiateMessage().getRequests().get(0);
283         final long srpId = req.getSrp().getOperationId().getValue();
284         final InetAddress inetAddress = InetAddress.getByName(TEST_ADDRESS);
285         final Tlvs tlvs = createLspTlvs(req.getLsp().getPlspId().getValue(), true,
286                 inetAddress, inetAddress, inetAddress);
287         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()));
288         this.listener.onMessage(this.session, pcRpt);
289         assertEquals(1, getTopology().get().getNode().size());
290
291         // node should be removed after termination
292         this.listener.onSessionTerminated(this.session, new PCEPCloseTermination(TerminationReason.Unknown));
293         assertEquals(0, getTopology().get().getNode().size());
294     }
295
296     @Test
297     public void testUnknownLsp() throws Exception {
298         final List<Reports> reports = Lists.newArrayList(new ReportsBuilder().setPath(new PathBuilder().setEro(new EroBuilder().build()).build()).setLsp(
299                 new LspBuilder().setPlspId(new PlspId(5L)).setSync(false).setRemove(false).setTlvs(
300                         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(
301                                 new SymbolicPathNameBuilder().setPathName(new SymbolicPathName(new byte[] { 22, 34 })).build()).build()).build()).build());
302         final Pcrpt rptmsg = new PcrptBuilder().setPcrptMessage(new PcrptMessageBuilder().setReports(reports).build()).build();
303         this.session.sessionUp();
304         this.session.handleMessage(rptmsg);
305         final Topology topology = getTopology().get();
306         assertFalse(topology.getNode().isEmpty());
307     }
308
309     @Override
310     protected Open getLocalPref() {
311         return new OpenBuilder(super.getLocalPref()).setTlvs(new TlvsBuilder().addAugmentation(Tlvs1.class, new Tlvs1Builder().setStateful(new StatefulBuilder().build()).build()).build()).build();
312     }
313
314     private AddLspInput createAddLspInput() {
315         final ArgumentsBuilder argsBuilder = new ArgumentsBuilder();
316         final Ipv4CaseBuilder ipv4Builder = new Ipv4CaseBuilder();
317         ipv4Builder.setIpv4(new Ipv4Builder().setSourceIpv4Address(new Ipv4Address(TEST_ADDRESS)).setDestinationIpv4Address(new Ipv4Address(TEST_ADDRESS)).build());
318         argsBuilder.setEndpointsObj(new EndpointsObjBuilder().setAddressFamily(ipv4Builder.build()).build());
319         argsBuilder.setEro(createEroWithIpPrefixes(Lists.newArrayList(ERO_IP_PREFIX)));
320         argsBuilder.addAugmentation(Arguments2.class, new Arguments2Builder().setLsp(new LspBuilder().setDelegate(true).setAdministrative(true).build()).build());
321         return new AddLspInputBuilder().setName(TEST_LSP_NAME).setArguments(argsBuilder.build()).setNetworkTopologyRef(new NetworkTopologyRef(TOPO_IID)).setNode(NODE_ID).build();
322     }
323 }