ac5147c5c21635cdb5759d7f4667fd30b85923ce
[bgpcep.git] / bgp / rib-impl / src / main / java / org / opendaylight / protocol / bgp / rib / impl / spi / BGPSessionPreferences.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.spi;
9
10 import java.util.List;
11 import java.util.Optional;
12 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber;
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.open.message.BgpParameters;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.BgpId;
15
16 /**
17  * DTO for BGP Session preferences, that contains BGP Open message.
18  */
19 public final class BGPSessionPreferences {
20
21     private final AsNumber as;
22
23     private final int hold;
24
25     private final BgpId bgpId;
26
27     private final List<BgpParameters> params;
28
29     private final AsNumber remoteAs;
30
31     private final Optional<byte[]> md5Password;
32
33     /**
34      * Creates a new DTO for Open message.
35      *
36      * @param as local AS number
37      * @param hold preferred hold timer value, in seconds
38      * @param bgpId local BGP Identifier
39      * @param remoteAs expected remote As Number
40      * @param params list of advertised parameters
41      * @param md5Password - md5password
42      */
43     public BGPSessionPreferences(final AsNumber as, final int hold, final BgpId bgpId, final AsNumber remoteAs,
44             final List<BgpParameters> params, final Optional<byte[]> md5Password) {
45         this.as = as;
46         this.hold = hold;
47         this.bgpId = (bgpId != null) ? new BgpId(bgpId) : null;
48         this.remoteAs = remoteAs;
49         this.params = params;
50         this.md5Password = md5Password;
51     }
52
53     public BGPSessionPreferences(final AsNumber as, final int hold, final BgpId bgpId, final AsNumber remoteAs,
54             final List<BgpParameters> params) {
55         this(as, hold, bgpId, remoteAs, params, Optional.empty());
56     }
57     /**
58      * Returns my AS number.
59      *
60      * @return AS number
61      */
62     public AsNumber getMyAs() {
63         return this.as;
64     }
65
66     /**
67      * Returns initial value of HoldTimer.
68      *
69      * @return initial value of HoldTimer
70      */
71     public int getHoldTime() {
72         return this.hold;
73     }
74
75     /**
76      * Returns my BGP Identifier.
77      *
78      * @return BGP identifier
79      */
80     public BgpId getBgpId() {
81         return this.bgpId;
82     }
83
84     /**
85      * Returns expected remote AS number.
86      *
87      * @return AS number
88      */
89     public AsNumber getExpectedRemoteAs() {
90         return this.remoteAs;
91     }
92
93     /**
94      * Gets a list of advertised bgp parameters.
95      *
96      * @return a list of advertised bgp parameters
97      */
98     public List<BgpParameters> getParams() {
99         return this.params;
100     }
101
102     /**
103      * Optionally returns peer's MD5 password.
104      * @return Encoded MD5 password.
105      */
106     public Optional<byte[]> getMd5Password() {
107         return this.md5Password;
108     }
109 }