BUG-8156 : conflicting listener fix
[bgpcep.git] / bgp / parser-spi / src / main / java / org / opendaylight / protocol / bgp / parser / spi / pojo / MultiPathSupportImpl.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.parser.spi.pojo;
10
11 import com.google.common.base.Preconditions;
12 import com.google.common.collect.ImmutableSet;
13 import java.util.List;
14 import java.util.Set;
15 import java.util.stream.Collectors;
16 import javax.annotation.Nonnull;
17 import org.opendaylight.protocol.bgp.parser.BgpTableTypeImpl;
18 import org.opendaylight.protocol.bgp.parser.spi.MultiPathSupport;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.BgpTableType;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.SendReceive;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.mp.capabilities.add.path.capability.AddressFamilies;
22
23 public final class MultiPathSupportImpl implements MultiPathSupport {
24
25     private final Set<BgpTableType> supportedTables;
26
27     private MultiPathSupportImpl(final Set<BgpTableType> supportedTables) {
28         this.supportedTables = ImmutableSet.copyOf(supportedTables);
29     }
30
31     /**
32      * Creates instance of {@link MultiPathSupport} holder to be used
33      * as a parser constraint, hence only "send" add-path capabilities are
34      * taken into the account.
35      *
36      * @param addPathCapabilities The remote add-path capabilities list.
37      * @return MultiPathSupport instance.
38      */
39     public static MultiPathSupport createParserMultiPathSupport(@Nonnull final List<AddressFamilies> addPathCapabilities) {
40         Preconditions.checkNotNull(addPathCapabilities);
41         final Set<BgpTableType> support = addPathCapabilities
42             .stream()
43             .filter(e -> e.getSendReceive() == SendReceive.Both || e.getSendReceive() == SendReceive.Send)
44             .map(e -> new BgpTableTypeImpl(e.getAfi(), e.getSafi()))
45             .collect(Collectors.toSet());
46         return new MultiPathSupportImpl(support);
47     }
48
49     @Override
50     public boolean isTableTypeSupported(final BgpTableType tableType) {
51         return this.supportedTables.contains(tableType);
52     }
53
54 }