72f44134481cf78d28df4d53a61234a189779725
[bgpcep.git] / bgp / rib-spi / src / main / java / org / opendaylight / protocol / bgp / rib / spi / PeerRoleUtil.java
1 /*
2  * Copyright (c) 2016 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.protocol.bgp.rib.spi;
10
11 import com.google.common.base.Optional;
12 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.PeerRole;
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.bgp.rib.rib.Peer;
14 import org.opendaylight.yangtools.yang.binding.BindingMapping;
15 import org.opendaylight.yangtools.yang.common.QName;
16 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
17 import org.opendaylight.yangtools.yang.data.api.schema.LeafNode;
18 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
19
20 public final class PeerRoleUtil {
21     public static final NodeIdentifier PEER_ROLE_NID = new NodeIdentifier(QName.create(Peer.QNAME,
22             "peer-role").intern());
23
24     private PeerRoleUtil() {
25         throw new UnsupportedOperationException();
26     }
27
28     public static PeerRole roleForChange(final Optional<NormalizedNode<?, ?>> maybePeerRole) {
29         if (maybePeerRole.isPresent()) {
30             final LeafNode<?> peerRoleLeaf = (LeafNode<?>) maybePeerRole.get();
31             return PeerRole.valueOf(BindingMapping.getClassName((String) peerRoleLeaf.getValue()));
32         }
33         return null;
34     }
35
36     public static String roleForString(final PeerRole role) {
37         switch (role) {
38             case Ebgp:
39                 return "ebgp";
40             case Ibgp:
41                 return "ibgp";
42             case RrClient:
43                 return "rr-client";
44             case Internal:
45                 return "internal";
46             default:
47                 throw new IllegalArgumentException("Unhandled role " + role);
48         }
49     }
50 }