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 com.google.common.base.Preconditions;
12 import org.opendaylight.protocol.pcep.PCEPSession;
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.pcep.sync.optimizations.rev150714.Stateful1;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.pcep.sync.optimizations.rev150714.Tlvs3;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.pcep.sync.optimizations.rev150714.lsp.db.version.tlv.LspDbVersion;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.Tlvs1;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.open.Tlvs;
19 final class SyncOptimization {
21 private final boolean dbVersionMatch;
22 private final boolean isSyncAvoidanceEnabled;
23 private final boolean isDeltaSyncEnabled;
24 private final boolean isDbVersionPresent;
25 private final boolean isTriggeredInitialSyncEnable;
26 private final boolean isTriggeredReSyncEnable;
28 public SyncOptimization(final PCEPSession session) {
29 Preconditions.checkNotNull(session);
30 final Tlvs remote = session.getRemoteTlvs();
31 final Tlvs local = session.localSessionCharacteristics();
32 final LspDbVersion localLspDbVersion = getLspDbVersion(local);
33 final LspDbVersion remoteLspDbVersion = getLspDbVersion(remote);
34 this.dbVersionMatch = compareLspDbVersion(localLspDbVersion, remoteLspDbVersion);
35 this.isSyncAvoidanceEnabled = isSyncAvoidance(local) && isSyncAvoidance(remote);
36 this.isDeltaSyncEnabled = isDeltaSync(local) && isDeltaSync(remote);
37 this.isDbVersionPresent = localLspDbVersion != null || remoteLspDbVersion != null;
38 this.isTriggeredInitialSyncEnable = isTriggeredInitialSync(local) && isTriggeredInitialSync(remote) &&
39 (this.isDeltaSyncEnabled || this.isSyncAvoidanceEnabled);
40 this.isTriggeredReSyncEnable = isTriggeredReSync(local) && isTriggeredReSync(remote);
43 public boolean doesLspDbMatch() {
44 return this.dbVersionMatch;
47 public boolean isSyncAvoidanceEnabled() {
48 return this.isSyncAvoidanceEnabled;
51 public boolean isDeltaSyncEnabled() {
52 return this.isDeltaSyncEnabled;
55 public boolean isTriggeredInitSyncEnabled() {
56 return this.isTriggeredInitialSyncEnable;
58 public boolean isTriggeredReSyncEnabled() {
59 return this.isTriggeredReSyncEnable;
62 public boolean isDbVersionPresent() {
63 return this.isDbVersionPresent;
66 private static LspDbVersion getLspDbVersion(final Tlvs openTlvs) {
67 if (openTlvs != null) {
68 final Tlvs3 tlvs3 = openTlvs.getAugmentation(Tlvs3.class);
69 if (tlvs3 != null && tlvs3.getLspDbVersion() != null
70 && tlvs3.getLspDbVersion().getLspDbVersionValue() != null) {
71 return tlvs3.getLspDbVersion();
77 private static boolean compareLspDbVersion(final LspDbVersion local, final LspDbVersion remote) {
78 if (local != null && remote != null) {
79 return local.equals(remote);
84 private static Stateful1 getStateful1(final Tlvs openTlvs) {
85 if (openTlvs != null) {
86 final Tlvs1 tlvs1 = openTlvs.getAugmentation(Tlvs1.class);
87 if (tlvs1 != null && tlvs1.getStateful() != null) {
88 return tlvs1.getStateful().getAugmentation(Stateful1.class);
94 private static boolean isSyncAvoidance(final Tlvs openTlvs) {
95 final Stateful1 stateful1 = getStateful1(openTlvs);
96 if (stateful1 != null && stateful1.isIncludeDbVersion() != null) {
97 return stateful1.isIncludeDbVersion();
102 private static boolean isDeltaSync(final Tlvs openTlvs) {
103 final Stateful1 stateful1 = getStateful1(openTlvs);
104 if (stateful1 != null && stateful1.isDeltaLspSyncCapability() != null) {
105 return stateful1.isDeltaLspSyncCapability();
110 private static boolean isTriggeredInitialSync(final Tlvs openTlvs) {
111 final Stateful1 stateful1 = getStateful1(openTlvs);
112 if (stateful1 != null && stateful1.isTriggeredInitialSync() != null) {
113 return stateful1.isTriggeredInitialSync();
118 private static boolean isTriggeredReSync(final Tlvs openTlvs) {
119 final Stateful1 stateful1 = getStateful1(openTlvs);
120 if (stateful1 != null && stateful1.isTriggeredResync() != null) {
121 return stateful1.isTriggeredResync();