ed0e6d1447e19a1d055199565e1a6be429df62c1
[bgpcep.git] / pcep / pcc-mock / src / test / java / org / opendaylight / protocol / pcep / pcc / mock / PCCIncrementalSyncTest.java
1 /*
2  * Copyright (c) 2015 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.protocol.pcep.pcc.mock;
10
11 import static org.junit.Assert.assertFalse;
12
13 import com.google.common.base.Optional;
14 import io.netty.channel.Channel;
15 import java.math.BigInteger;
16 import java.net.UnknownHostException;
17 import java.util.ArrayList;
18 import java.util.List;
19 import java.util.concurrent.ExecutionException;
20 import org.junit.Test;
21 import org.opendaylight.protocol.pcep.PCEPCapability;
22 import org.opendaylight.protocol.pcep.ietf.stateful07.PCEPStatefulCapability;
23 import org.opendaylight.protocol.pcep.pcc.mock.protocol.PCCServerPeerProposal;
24
25 public class PCCIncrementalSyncTest extends PCCMockCommon {
26
27     private BigInteger lsp = BigInteger.valueOf(8);
28     /**
29      * Test Incremental Synchronization
30      * Create 8 lsp, then it disconnects after 5 sec and then after 5 sec reconnects with Pcc DBVersion 10
31      * After reconnection PCE has DBVersion 10, therefore there is 9 changes missed. 9 Pcrt + 1 Pcrt-Sync
32      */
33     private final String[] mainInputIncrementalSync = new String[]{"--local-address", PCCMockTest.LOCAL_ADDRESS, "--remote-address",
34         PCCMockTest.REMOTE_ADDRESS + ":4578", "--pcc", "1", "--lsp", lsp.toString(), "--log-level", "DEBUG", "-ka", "40", "-d", "120",
35         "--reconnect", "-1", "--redelegation-timeout", "0", "--state-timeout", "-1", "--incremental-sync-procedure", "10", "5", "5"};
36
37     @Test
38     public void testSessionIncrementalSyncEstablishment() throws UnknownHostException, InterruptedException, ExecutionException {
39         final TestingSessionListenerFactory factory = new TestingSessionListenerFactory();
40         final BigInteger numberOflspAndDBv = BigInteger.valueOf(8);
41         final Channel channel = createServer(factory, socket, new PCCServerPeerProposal(numberOflspAndDBv));
42         Main.main(mainInputIncrementalSync);
43         Thread.sleep(1000);
44         final TestingSessionListener pceSessionListener = getListener(factory);
45         checkSynchronizedSession(8, pceSessionListener, numberOflspAndDBv);
46         Thread.sleep(4000);
47         assertFalse(pceSessionListener.isUp());
48         final int expetedNumberOfLspAndEndOfSync = 3;
49         final BigInteger expectedFinalDBVersion = BigInteger.valueOf(10);
50         final TestingSessionListener sessionListenerAfterReconnect = getListener(factory);
51         checkResyncSession(Optional.absent(), expetedNumberOfLspAndEndOfSync, numberOflspAndDBv, expectedFinalDBVersion, sessionListenerAfterReconnect);
52         channel.close().get();
53     }
54
55     @Override
56     protected List<PCEPCapability> getCapabilities() {
57         final List<PCEPCapability> caps = new ArrayList<>();
58         caps.add(new PCEPStatefulCapability(true, true, true, false, false, true, true));
59         return caps;
60     }
61
62     @Override
63     protected int getPort() {
64         return 4578;
65     }
66 }