Remove hand-written ServiceLoader services
[bgpcep.git] / pcep / ietf-p2mp-te-lsp / src / main / java / org / opendaylight / protocol / pcep / p2mp / te / lsp / P2MPTeLspCapability.java
1 /*
2  * Copyright (c) 2018 AT&T Intellectual Property. 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.p2mp.te.lsp;
9
10 import com.google.common.base.MoreObjects;
11 import java.net.InetSocketAddress;
12 import org.kohsuke.MetaInfServices;
13 import org.opendaylight.protocol.pcep.PCEPCapability;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.p2mp.te.lsp.rev181109.TlvsP2mpCapabilityAug;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.p2mp.te.lsp.rev181109.TlvsP2mpCapabilityAugBuilder;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.p2mp.te.lsp.rev181109.p2mp.pce.capability.tlv.P2mpPceCapabilityBuilder;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.open.object.open.TlvsBuilder;
18
19 @MetaInfServices
20 public final class P2MPTeLspCapability implements PCEPCapability {
21     private static final TlvsP2mpCapabilityAug PATH_COMPUTATION_CAP_AUG = new TlvsP2mpCapabilityAugBuilder()
22         .setP2mpPceCapability(new P2mpPceCapabilityBuilder().build())
23         .build();
24
25     private final boolean supportsPathComputation;
26
27     public P2MPTeLspCapability() {
28         this(true);
29     }
30
31     // FIXME: this should return distinct implementations
32     public P2MPTeLspCapability(final boolean supportsP2MPTeLspPathComputation) {
33         this.supportsPathComputation = supportsP2MPTeLspPathComputation;
34     }
35
36     @Override
37     public void setCapabilityProposal(final InetSocketAddress address, final TlvsBuilder builder) {
38         if (supportsPathComputation) {
39             builder.addAugmentation(PATH_COMPUTATION_CAP_AUG);
40         }
41     }
42
43     @Override
44     public boolean isStateful() {
45         return false;
46     }
47
48     @Override
49     public String toString() {
50         return MoreObjects.toStringHelper(this).add("pathComputation", supportsPathComputation).toString();
51     }
52 }