dab318e215ba49dd14c421b7e04870dc8686487a
[bgpcep.git] / bgp / parser-api / src / main / java / org / opendaylight / protocol / bgp / parser / message / BGPOpenMessage.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.parser.message;
9
10 import java.util.List;
11
12 import org.opendaylight.protocol.bgp.parser.BGPMessage;
13 import org.opendaylight.protocol.bgp.parser.BGPParameter;
14 import org.opendaylight.protocol.concepts.IPv4Address;
15 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.AsNumber;
16
17 /**
18  * Representation of BGPOpen message.
19  * 
20  * @see <a href="http://tools.ietf.org/html/rfc4271#section-4.2">BGP Open Message</a>
21  */
22 public final class BGPOpenMessage implements BGPMessage {
23
24         private static final long serialVersionUID = -3507481736478860117L;
25
26         /**
27          * Current BGP version.
28          */
29         public static final int BGP_VERSION = 4;
30
31         private final AsNumber myAS;
32
33         private final short holdTime;
34
35         private final IPv4Address bgpId;
36
37         private final List<BGPParameter> optParams;
38
39         /**
40          * Creates BGPOpen message.
41          * 
42          * @param myAS ASNumber of the BGP speaker
43          * @param holdTime proposed value of the Hold Timer
44          * @param bgpId IPv4 Address of the BGP speaker
45          * @param optParams List of optional parameters
46          */
47         public BGPOpenMessage(final AsNumber myAS, final short holdTime, final IPv4Address bgpId, final List<BGPParameter> optParams) {
48                 super();
49                 this.myAS = myAS;
50                 this.holdTime = holdTime;
51                 this.bgpId = bgpId;
52                 this.optParams = optParams;
53         }
54
55         /**
56          * Returns the AS number of the BGP speaker.
57          * 
58          * @return myAS
59          */
60         public AsNumber getMyAS() {
61                 return this.myAS;
62         }
63
64         /**
65          * Returns the value of the Hold timer.
66          * 
67          * @return the holdTime
68          */
69         public short getHoldTime() {
70                 return this.holdTime;
71         }
72
73         /**
74          * Returns BGP identifier of the speaker (his IP address).
75          * 
76          * @return the bgpId
77          */
78         public IPv4Address getBgpId() {
79                 return this.bgpId;
80         }
81
82         /**
83          * Returns optional parameters in form of TLVs.
84          * 
85          * @return the optParams
86          */
87         public List<BGPParameter> getOptParams() {
88                 return this.optParams;
89         }
90
91         @Override
92         public String toString() {
93                 final StringBuilder builder = new StringBuilder();
94                 builder.append("BGPOpenMessage [myAS=");
95                 builder.append(this.myAS);
96                 builder.append(", holdTime=");
97                 builder.append(this.holdTime);
98                 builder.append(", bgpId=");
99                 builder.append(this.bgpId);
100                 builder.append(", optParams=");
101                 builder.append(this.optParams);
102                 builder.append("]");
103                 return builder.toString();
104         }
105 }