dc64b7259a1abd386bdb7dff4c0339b8f1ea9d44
[bgpcep.git] / pcep / segment-routing / src / main / java / org / opendaylight / controller / config / yang / pcep / sr / cfg / SrPCEPSessionProposalFactoryModule.java
1 /*
2  * Copyright (c) 2014 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.controller.config.yang.pcep.sr.cfg;
10
11 import com.google.common.base.Preconditions;
12 import java.net.InetSocketAddress;
13 import org.opendaylight.controller.config.api.JmxAttributeValidationException;
14 import org.opendaylight.protocol.pcep.PCEPSessionProposalFactory;
15 import org.opendaylight.protocol.pcep.segment.routing.SegmentRoutingSessionProposalFactory;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.Open;
17 import org.slf4j.Logger;
18 import org.slf4j.LoggerFactory;
19
20 public class SrPCEPSessionProposalFactoryModule extends org.opendaylight.controller.config.yang.pcep.sr.cfg.AbstractSrPCEPSessionProposalFactoryModule {
21
22     private static final String VALUE_IS_NOT_SET = "value is not set.";
23
24     private static final int DEADTIMER_KEEPALIVE_RATIO = 4;
25
26     private static final Logger LOG = LoggerFactory.getLogger(SrPCEPSessionProposalFactoryModule.class);
27
28     public SrPCEPSessionProposalFactoryModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) {
29         super(identifier, dependencyResolver);
30     }
31
32     public SrPCEPSessionProposalFactoryModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver, org.opendaylight.controller.config.yang.pcep.sr.cfg.SrPCEPSessionProposalFactoryModule oldModule, java.lang.AutoCloseable oldInstance) {
33         super(identifier, dependencyResolver, oldModule, oldInstance);
34     }
35
36     @Override
37     public void customValidation() {
38         JmxAttributeValidationException.checkNotNull(getActive(), VALUE_IS_NOT_SET, activeJmxAttribute);
39         JmxAttributeValidationException.checkNotNull(getInitiated(), VALUE_IS_NOT_SET, initiatedJmxAttribute);
40         JmxAttributeValidationException.checkNotNull(getDeadTimerValue(), VALUE_IS_NOT_SET, deadTimerValueJmxAttribute);
41         JmxAttributeValidationException.checkNotNull(getKeepAliveTimerValue(), VALUE_IS_NOT_SET, keepAliveTimerValueJmxAttribute);
42         if (getKeepAliveTimerValue() != 0) {
43             JmxAttributeValidationException.checkCondition(getKeepAliveTimerValue() >= 1, "minimum value is 1.",
44                     keepAliveTimerValueJmxAttribute);
45             if (getDeadTimerValue() != 0 && (getDeadTimerValue() / getKeepAliveTimerValue() != DEADTIMER_KEEPALIVE_RATIO)) {
46                 LOG.warn("DeadTimerValue should be 4 times greater than KeepAliveTimerValue");
47             }
48         }
49         if (getActive() && !getStateful()) {
50             setStateful(true);
51         }
52         JmxAttributeValidationException.checkNotNull(getStateful(), VALUE_IS_NOT_SET, statefulJmxAttribute);
53         JmxAttributeValidationException.checkNotNull(getSrCapable(), VALUE_IS_NOT_SET, srCapableJmxAttribute);
54     }
55
56     @Override
57     public java.lang.AutoCloseable createInstance() {
58         final SegmentRoutingSessionProposalFactory inner = new SegmentRoutingSessionProposalFactory(getDeadTimerValue(), getKeepAliveTimerValue(), getStateful(), getActive(), getInitiated(), getSrCapable());
59         return new PCEPSessionProposalFactoryCloseable(inner);
60     }
61
62     private static final class PCEPSessionProposalFactoryCloseable implements PCEPSessionProposalFactory, AutoCloseable {
63         private final SegmentRoutingSessionProposalFactory inner;
64
65         public PCEPSessionProposalFactoryCloseable(final SegmentRoutingSessionProposalFactory inner) {
66             this.inner = Preconditions.checkNotNull(inner);
67         }
68
69         @Override
70         public void close() {
71         }
72
73         @Override
74         public Open getSessionProposal(final InetSocketAddress inetSocketAddress, final int sessionId) {
75             return this.inner.getSessionProposal(inetSocketAddress, sessionId);
76         }
77     }
78
79 }