e6b304917a7f1d08949ef1aaee932c18c8a5145f
[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.concepts.BGPAddressFamily;
13 import org.opendaylight.protocol.bgp.concepts.BGPSubsequentAddressFamily;
14 import org.opendaylight.protocol.bgp.concepts.BGPTableType;
15 import org.opendaylight.protocol.bgp.parser.BGPParameter;
16 import org.opendaylight.protocol.bgp.parser.parameter.AS4BytesCapability;
17 import org.opendaylight.protocol.bgp.parser.parameter.MultiprotocolCapability;
18 import org.opendaylight.protocol.bgp.rib.impl.spi.BGPSessionPreferences;
19 import org.opendaylight.protocol.bgp.rib.impl.spi.BGPSessionProposal;
20 import org.opendaylight.protocol.concepts.ASNumber;
21 import org.opendaylight.protocol.concepts.IPv4Address;
22
23 import com.google.common.collect.Lists;
24
25 /**
26  * Basic implementation of BGP Session Proposal. The values are taken from conf-bgp.
27  */
28 public final class BGPSessionProposalImpl implements BGPSessionProposal {
29
30         private final short holdTimer;
31
32         private final ASNumber as;
33
34         private final IPv4Address bgpId;
35
36         private final BGPSessionPreferences prefs;
37
38         public BGPSessionProposalImpl(final short holdTimer, final ASNumber as, final IPv4Address bgpId) {
39                 this.holdTimer = holdTimer;
40                 this.as = as;
41                 this.bgpId = bgpId;
42
43                 final BGPTableType ipv4 = new BGPTableType(BGPAddressFamily.IPv4, BGPSubsequentAddressFamily.Unicast);
44                 final BGPTableType linkstate = new BGPTableType(BGPAddressFamily.LinkState, BGPSubsequentAddressFamily.Linkstate);
45                 final List<BGPParameter> tlvs = Lists.newArrayList();
46                 tlvs.add(new MultiprotocolCapability(ipv4));
47                 tlvs.add(new MultiprotocolCapability(linkstate));
48                 // final Map<BGPTableType, Boolean> tableTypes = Maps.newHashMap();
49                 // tableTypes.put(ipv4, true);
50                 // tableTypes.put(linkstate,true);
51                 // tlvs.add(new GracefulCapability(true, 0, tableTypes));
52                 tlvs.add(new AS4BytesCapability(as));
53                 this.prefs = new BGPSessionPreferences(as, holdTimer, bgpId, tlvs);
54         }
55
56         @Override
57         public BGPSessionPreferences getProposal() {
58                 return this.prefs;
59         }
60
61         /**
62          * @return the holdTimer
63          */
64         public short getHoldTimer() {
65                 return this.holdTimer;
66         }
67
68         /**
69          * @return the as
70          */
71         public ASNumber getAs() {
72                 return this.as;
73         }
74
75         /**
76          * @return the bgpId
77          */
78         public IPv4Address getBgpId() {
79                 return this.bgpId;
80         }
81 }