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