moved BGP Table type from concepts to parser-api.
[bgpcep.git] / bgp / rib-impl / src / main / java / org / opendaylight / protocol / bgp / rib / impl / BGPSessionProposalImpl.java
1 /*
2  * Copyright (c) 2013 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.bgp.rib.impl;
9
10 import java.util.List;
11
12 import org.opendaylight.protocol.bgp.parser.BGPParameter;
13 import org.opendaylight.protocol.bgp.parser.BGPTableType;
14 import org.opendaylight.protocol.bgp.parser.parameter.AS4BytesCapability;
15 import org.opendaylight.protocol.bgp.parser.parameter.MultiprotocolCapability;
16 import org.opendaylight.protocol.bgp.rib.impl.spi.BGPSessionPreferences;
17 import org.opendaylight.protocol.bgp.rib.impl.spi.BGPSessionProposal;
18 import org.opendaylight.protocol.concepts.IPv4Address;
19 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.AsNumber;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.LinkstateAddressFamily;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev130918.LinkstateSubsequentAddressFamily;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Ipv4AddressFamily;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.UnicastSubsequentAddressFamily;
24
25 import com.google.common.collect.Lists;
26
27 /**
28  * Basic implementation of BGP Session Proposal. The values are taken from conf-bgp.
29  */
30 public final class BGPSessionProposalImpl implements BGPSessionProposal {
31
32         private final short holdTimer;
33
34         private final AsNumber as;
35
36         private final IPv4Address bgpId;
37
38         private final BGPSessionPreferences prefs;
39
40         public BGPSessionProposalImpl(final short holdTimer, final AsNumber as, final IPv4Address bgpId) {
41                 this.holdTimer = holdTimer;
42                 this.as = as;
43                 this.bgpId = bgpId;
44
45                 final BGPTableType ipv4 = new BGPTableType(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class);
46                 final BGPTableType linkstate = new BGPTableType(LinkstateAddressFamily.class, LinkstateSubsequentAddressFamily.class);
47                 final List<BGPParameter> tlvs = Lists.newArrayList();
48                 tlvs.add(new MultiprotocolCapability(ipv4));
49                 tlvs.add(new MultiprotocolCapability(linkstate));
50                 // final Map<BGPTableType, Boolean> tableTypes = Maps.newHashMap();
51                 // tableTypes.put(ipv4, true);
52                 // tableTypes.put(linkstate,true);
53                 // tlvs.add(new GracefulCapability(true, 0, tableTypes));
54                 tlvs.add(new AS4BytesCapability(as));
55                 this.prefs = new BGPSessionPreferences(as, holdTimer, bgpId, tlvs);
56         }
57
58         @Override
59         public BGPSessionPreferences getProposal() {
60                 return this.prefs;
61         }
62
63         /**
64          * @return the holdTimer
65          */
66         public short getHoldTimer() {
67                 return this.holdTimer;
68         }
69
70         /**
71          * @return the as
72          */
73         public AsNumber getAs() {
74                 return this.as;
75         }
76
77         /**
78          * @return the bgpId
79          */
80         public IPv4Address getBgpId() {
81                 return this.bgpId;
82         }
83 }