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 java.util.Objects.requireNonNull;
13 import org.opendaylight.protocol.pcep.PCEPSession;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.pcep.sync.optimizations.rev200720.Stateful1;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.pcep.sync.optimizations.rev200720.Tlvs3;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.pcep.sync.optimizations.rev200720.lsp.db.version.tlv.LspDbVersion;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev200720.Tlvs1;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.open.object.open.Tlvs;
20 final class SyncOptimization {
22 private final boolean dbVersionMatch;
23 private final boolean isSyncAvoidanceEnabled;
24 private final boolean isDeltaSyncEnabled;
25 private final boolean isDbVersionPresent;
26 private final boolean isTriggeredInitialSyncEnable;
27 private final boolean isTriggeredReSyncEnable;
29 SyncOptimization(final PCEPSession session) {
30 requireNonNull(session);
31 final Tlvs remote = session.getRemoteTlvs();
32 final Tlvs local = session.getLocalTlvs();
33 final LspDbVersion localLspDbVersion = getLspDbVersion(local);
34 final LspDbVersion remoteLspDbVersion = getLspDbVersion(remote);
35 this.dbVersionMatch = compareLspDbVersion(localLspDbVersion, remoteLspDbVersion);
36 this.isSyncAvoidanceEnabled = isSyncAvoidance(local) && isSyncAvoidance(remote);
37 this.isDeltaSyncEnabled = isDeltaSync(local) && isDeltaSync(remote);
38 this.isDbVersionPresent = localLspDbVersion != null || remoteLspDbVersion != null;
39 this.isTriggeredInitialSyncEnable = isTriggeredInitialSync(local) && isTriggeredInitialSync(remote)
40 && (this.isDeltaSyncEnabled || this.isSyncAvoidanceEnabled);
41 this.isTriggeredReSyncEnable = isTriggeredReSync(local) && isTriggeredReSync(remote);
44 boolean doesLspDbMatch() {
45 return this.dbVersionMatch;
48 boolean isSyncAvoidanceEnabled() {
49 return this.isSyncAvoidanceEnabled;
52 boolean isDeltaSyncEnabled() {
53 return this.isDeltaSyncEnabled;
56 boolean isTriggeredInitSyncEnabled() {
57 return this.isTriggeredInitialSyncEnable;
60 boolean isTriggeredReSyncEnabled() {
61 return this.isTriggeredReSyncEnable;
64 boolean isDbVersionPresent() {
65 return this.isDbVersionPresent;
68 private static LspDbVersion getLspDbVersion(final Tlvs openTlvs) {
69 if (openTlvs != null) {
70 final Tlvs3 tlvs3 = openTlvs.augmentation(Tlvs3.class);
71 if (tlvs3 != null && tlvs3.getLspDbVersion() != null
72 && tlvs3.getLspDbVersion().getLspDbVersionValue() != null) {
73 return tlvs3.getLspDbVersion();
79 private static boolean compareLspDbVersion(final LspDbVersion local, final LspDbVersion remote) {
80 if (local != null && remote != null) {
81 return local.equals(remote);
86 private static Stateful1 getStateful1(final Tlvs openTlvs) {
87 if (openTlvs != null) {
88 final Tlvs1 tlvs1 = openTlvs.augmentation(Tlvs1.class);
89 if (tlvs1 != null && tlvs1.getStateful() != null) {
90 return tlvs1.getStateful().augmentation(Stateful1.class);
96 private static boolean isSyncAvoidance(final Tlvs openTlvs) {
97 final Stateful1 stateful1 = getStateful1(openTlvs);
98 if (stateful1 != null && stateful1.isIncludeDbVersion() != null) {
99 return stateful1.isIncludeDbVersion();
104 private static boolean isDeltaSync(final Tlvs openTlvs) {
105 final Stateful1 stateful1 = getStateful1(openTlvs);
106 if (stateful1 != null && stateful1.isDeltaLspSyncCapability() != null) {
107 return stateful1.isDeltaLspSyncCapability();
112 private static boolean isTriggeredInitialSync(final Tlvs openTlvs) {
113 final Stateful1 stateful1 = getStateful1(openTlvs);
114 if (stateful1 != null && stateful1.isTriggeredInitialSync() != null) {
115 return stateful1.isTriggeredInitialSync();
120 private static boolean isTriggeredReSync(final Tlvs openTlvs) {
121 final Stateful1 stateful1 = getStateful1(openTlvs);
122 if (stateful1 != null && stateful1.isTriggeredResync() != null) {
123 return stateful1.isTriggeredResync();