2 * Copyright (c) 2015 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.assertFalse;
12 import static org.junit.Assert.assertTrue;
14 import java.math.BigInteger;
15 import org.junit.Before;
16 import org.junit.Test;
17 import org.mockito.Mock;
18 import org.mockito.Mockito;
19 import org.mockito.MockitoAnnotations;
20 import org.opendaylight.protocol.pcep.PCEPSession;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.pcep.sync.optimizations.rev181109.Stateful1;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.pcep.sync.optimizations.rev181109.Stateful1Builder;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.pcep.sync.optimizations.rev181109.Tlvs3;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.pcep.sync.optimizations.rev181109.Tlvs3Builder;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.pcep.sync.optimizations.rev181109.lsp.db.version.tlv.LspDbVersionBuilder;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev181109.Tlvs1;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev181109.Tlvs1Builder;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev181109.stateful.capability.tlv.StatefulBuilder;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.open.object.open.Tlvs;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.open.object.open.TlvsBuilder;
32 public class SyncOptimizationTest {
35 private PCEPSession pcepSession;
39 MockitoAnnotations.initMocks(this);
43 public void testDoesLspDbMatchPositive() {
44 final Tlvs tlvs = createTlvs(1L, false, false);
45 Mockito.doReturn(tlvs).when(this.pcepSession).getLocalTlvs();
46 Mockito.doReturn(tlvs).when(this.pcepSession).getRemoteTlvs();
47 final SyncOptimization syncOpt = new SyncOptimization(this.pcepSession);
48 assertTrue(syncOpt.doesLspDbMatch());
52 public void testDoesLspDbMatchNegative() {
53 final Tlvs localTlvs = createTlvs(1L, false, false);
54 final Tlvs remoteTlvs = createTlvs(2L, false, false);
55 Mockito.doReturn(localTlvs).when(this.pcepSession).getLocalTlvs();
56 Mockito.doReturn(remoteTlvs).when(this.pcepSession).getRemoteTlvs();
57 final SyncOptimization syncOpt = new SyncOptimization(this.pcepSession);
58 assertFalse(syncOpt.doesLspDbMatch());
62 public void testIsSyncAvoidanceEnabledPositive() {
63 final Tlvs tlvs = createTlvs(1L, true, false);
64 Mockito.doReturn(tlvs).when(this.pcepSession).getLocalTlvs();
65 Mockito.doReturn(tlvs).when(this.pcepSession).getRemoteTlvs();
66 final SyncOptimization syncOpt = new SyncOptimization(this.pcepSession);
67 assertTrue(syncOpt.isSyncAvoidanceEnabled());
71 public void testIsSyncAvoidanceEnabledNegative() {
72 final Tlvs localTlvs = createTlvs(1L, true, false);
73 final Tlvs remoteTlvs = createTlvs(2L, false, false);
74 Mockito.doReturn(localTlvs).when(this.pcepSession).getLocalTlvs();
75 Mockito.doReturn(remoteTlvs).when(this.pcepSession).getRemoteTlvs();
76 final SyncOptimization syncOpt = new SyncOptimization(this.pcepSession);
77 assertFalse(syncOpt.isSyncAvoidanceEnabled());
81 public void testIsDeltaSyncEnabledPositive() {
82 final Tlvs tlvs = createTlvs(1L, true, true);
83 Mockito.doReturn(tlvs).when(this.pcepSession).getLocalTlvs();
84 Mockito.doReturn(tlvs).when(this.pcepSession).getRemoteTlvs();
85 final SyncOptimization syncOpt = new SyncOptimization(this.pcepSession);
86 assertTrue(syncOpt.isDeltaSyncEnabled());
90 public void testIsDeltaSyncEnabledNegative() {
91 final Tlvs localTlvs = createTlvs(1L, true, true);
92 final Tlvs remoteTlvs = createTlvs(2L, false, false);
93 Mockito.doReturn(localTlvs).when(this.pcepSession).getLocalTlvs();
94 Mockito.doReturn(remoteTlvs).when(this.pcepSession).getRemoteTlvs();
95 final SyncOptimization syncOpt = new SyncOptimization(this.pcepSession);
96 assertFalse(syncOpt.isDeltaSyncEnabled());
100 public void testIsDbVersionPresentPositive() {
101 final Tlvs localTlvs = createTlvs(null, false, false);
102 final Tlvs remoteTlvs = createTlvs(2L, false, false);
103 Mockito.doReturn(localTlvs).when(this.pcepSession).getLocalTlvs();
104 Mockito.doReturn(remoteTlvs).when(this.pcepSession).getRemoteTlvs();
105 final SyncOptimization syncOpt = new SyncOptimization(this.pcepSession);
106 assertTrue(syncOpt.isDbVersionPresent());
110 public void testIsDbVersionPresentNegative() {
111 final Tlvs tlvs = createTlvs(null, true, false);
112 Mockito.doReturn(tlvs).when(this.pcepSession).getLocalTlvs();
113 Mockito.doReturn(tlvs).when(this.pcepSession).getRemoteTlvs();
114 final SyncOptimization syncOpt = new SyncOptimization(this.pcepSession);
115 assertFalse(syncOpt.isDbVersionPresent());
118 private static Tlvs createTlvs(final Long lspDbVersion, final boolean includeDbVresion,
119 final boolean includeDeltaSync) {
120 return new TlvsBuilder()
121 .addAugmentation(Tlvs1.class, new Tlvs1Builder().setStateful(new StatefulBuilder()
122 .addAugmentation(Stateful1.class, new Stateful1Builder().setIncludeDbVersion(includeDbVresion)
123 .setDeltaLspSyncCapability(includeDeltaSync).build()).build()).build())
124 .addAugmentation(Tlvs3.class, new Tlvs3Builder().setLspDbVersion(
125 new LspDbVersionBuilder().setLspDbVersionValue(lspDbVersion != null
126 ? BigInteger.valueOf(lspDbVersion) : null).build()).build()).build();