8d772568c4eee88b8d90843fb489edeb8d206fb8
[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 io.netty.channel.Channel;
12 import java.math.BigInteger;
13 import java.util.ArrayList;
14 import java.util.List;
15 import java.util.Optional;
16 import org.junit.Test;
17 import org.opendaylight.protocol.pcep.PCEPCapability;
18 import org.opendaylight.protocol.pcep.ietf.stateful07.PCEPStatefulCapability;
19 import org.opendaylight.protocol.pcep.pcc.mock.protocol.PCCServerPeerProposal;
20 import org.opendaylight.protocol.util.InetSocketAddressUtil;
21 import org.opendaylight.yangtools.yang.common.Uint64;
22
23 public class PCCIncrementalSyncTest extends PCCMockCommon {
24
25     private final BigInteger lsp = BigInteger.valueOf(8);
26     /**
27      * Test Incremental Synchronization
28      * Create 8 lsp, then it disconnects after 5 sec and then after 5 sec reconnects with Pcc DBVersion 10
29      * After reconnection PCE has DBVersion 10, therefore there is 9 changes missed. 9 Pcrt + 1 Pcrt-Sync
30      */
31     private final String[] mainInputIncrementalSync = new String[]{"--local-address", this.localAddress.getHostString(),
32         "--remote-address", InetSocketAddressUtil.toHostAndPort(this.remoteAddress).toString(), "--pcc", "1", "--lsp",
33         this.lsp.toString(), "--log-level", "DEBUG", "-ka", "30", "-d", "120", "--reconnect", "-1",
34         "--redelegation-timeout", "0", "--state-timeout", "-1", "--incremental-sync-procedure", "10", "5", "5"};
35
36     @Test
37     public void testSessionIncrementalSyncEstablishment() throws Exception {
38         final TestingSessionListenerFactory factory = new TestingSessionListenerFactory();
39         final Uint64 numberOflspAndDBv = Uint64.valueOf(8);
40         final Channel channel = createServer(factory, this.remoteAddress, new PCCServerPeerProposal(numberOflspAndDBv));
41         Main.main(this.mainInputIncrementalSync);
42         final TestingSessionListener pceSessionListener = getListener(factory);
43         checkSynchronizedSession(8, pceSessionListener, numberOflspAndDBv);
44         Thread.sleep(6000);
45         final int expetecdNumberOfLspAndEndOfSync = 3;
46         final Uint64 expectedFinalDBVersion = Uint64.valueOf(10);
47         final TestingSessionListener sessionListenerAfterReconnect = getListener(factory);
48         checkResyncSession(Optional.empty(), expetecdNumberOfLspAndEndOfSync, 3, numberOflspAndDBv,
49                 expectedFinalDBVersion, sessionListenerAfterReconnect);
50         channel.close().get();
51     }
52
53     @Override
54     protected List<PCEPCapability> getCapabilities() {
55         final List<PCEPCapability> caps = new ArrayList<>();
56         caps.add(new PCEPStatefulCapability(true, true, true, false, false, true, true));
57         return caps;
58     }
59 }