9c7e1410e9ad51a372a9d1634cce5e176095c102
[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.io.Closeable;
11 import java.io.IOException;
12 import java.util.List;
13
14 import org.opendaylight.protocol.bgp.concepts.BGPAddressFamily;
15 import org.opendaylight.protocol.bgp.concepts.BGPSubsequentAddressFamily;
16 import org.opendaylight.protocol.bgp.concepts.BGPTableType;
17 import org.opendaylight.protocol.bgp.parser.BGPParameter;
18 import org.opendaylight.protocol.bgp.parser.parameter.AS4BytesCapability;
19 import org.opendaylight.protocol.bgp.parser.parameter.MultiprotocolCapability;
20 import org.opendaylight.protocol.bgp.rib.impl.spi.BGPSessionPreferences;
21 import org.opendaylight.protocol.bgp.rib.impl.spi.BGPSessionProposal;
22
23 import org.opendaylight.protocol.concepts.ASNumber;
24 import org.opendaylight.protocol.concepts.IPv4Address;
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 extends BGPSessionProposal implements Closeable {
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(BGPAddressFamily.IPv4, BGPSubsequentAddressFamily.Unicast);
46                 final BGPTableType linkstate = new BGPTableType(BGPAddressFamily.LinkState, BGPSubsequentAddressFamily.Linkstate);
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
59         @Override
60         public BGPSessionPreferences getProposal() {
61                 return this.prefs;
62         }
63
64         @Override
65         public void close() throws IOException {
66                 // nothing to close
67         }
68
69         /**
70          * @return the holdTimer
71          */
72         public short getHoldTimer() {
73                 return this.holdTimer;
74         }
75
76         /**
77          * @return the as
78          */
79         public ASNumber getAs() {
80                 return this.as;
81         }
82
83         /**
84          * @return the bgpId
85          */
86         public IPv4Address getBgpId() {
87                 return this.bgpId;
88         }
89 }