Remove hand-written ServiceLoader services
[bgpcep.git] / pcep / segment-routing / src / main / java / org / opendaylight / protocol / pcep / segment / routing / PCEPSegmentRoutingCapability.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 package org.opendaylight.protocol.pcep.segment.routing;
9
10 import com.google.common.base.MoreObjects;
11 import java.net.InetSocketAddress;
12 import org.eclipse.jdt.annotation.NonNull;
13 import org.kohsuke.MetaInfServices;
14 import org.opendaylight.protocol.pcep.PCEPCapability;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.segment.routing.rev200720.Tlvs1;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.segment.routing.rev200720.Tlvs1Builder;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.segment.routing.rev200720.sr.pce.capability.tlv.SrPceCapabilityBuilder;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.open.object.open.TlvsBuilder;
19 import org.opendaylight.yangtools.yang.common.Uint8;
20
21 @MetaInfServices
22 public class PCEPSegmentRoutingCapability implements PCEPCapability {
23     private static final @NonNull Tlvs1 AUGMENTATION = new Tlvs1Builder()
24         .setSrPceCapability(new SrPceCapabilityBuilder()
25             .setNFlag(Boolean.FALSE)
26             .setXFlag(Boolean.FALSE)
27             .setMsd(Uint8.ZERO)
28             .build())
29         .build();
30
31     private final boolean isSegmentRoutingCapable;
32
33     public PCEPSegmentRoutingCapability() {
34         this(true);
35     }
36
37     public PCEPSegmentRoutingCapability(final boolean isSegmentRoutingCapable) {
38         this.isSegmentRoutingCapable = isSegmentRoutingCapable;
39     }
40
41     @Override
42     public void setCapabilityProposal(final InetSocketAddress address, final TlvsBuilder builder) {
43         if (isSegmentRoutingCapable) {
44             builder.addAugmentation(AUGMENTATION);
45         }
46     }
47
48     public boolean isSegmentRoutingCapable() {
49         return isSegmentRoutingCapable;
50     }
51
52     @Override
53     public boolean isStateful() {
54         return false;
55     }
56
57     @Override
58     public String toString() {
59         return MoreObjects.toStringHelper(this).add("srCapable", isSegmentRoutingCapable).toString();
60     }
61 }