7943aa38bf7c789a97935d1f589ea05b32f222ea
[bgpcep.git] / bgp / parser-api / src / main / java / org / opendaylight / protocol / bgp / parser / message / BGPNotificationMessage.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.Arrays;
11
12 import org.opendaylight.protocol.bgp.parser.BGPError;
13 import org.opendaylight.protocol.bgp.parser.BGPMessage;
14
15
16 /**
17  * Representation of BGPNotification message.
18  * 
19  * @see <a link="http://tools.ietf.org/html/rfc4271#section-4.5">BGP Notification Message</a>
20  */
21 public final class BGPNotificationMessage implements BGPMessage {
22
23         private static final long serialVersionUID = -5860147919167775673L;
24
25         private final BGPError error;
26
27         private final byte[] data;
28
29         /**
30          * Creates a BGPNotification message with no data.
31          * 
32          * @param error cause
33          */
34         public BGPNotificationMessage(final BGPError error) {
35                 this(error, null);
36         }
37
38         /**
39          * Creates a BGPNotification message with error cause and data.
40          * 
41          * @param error cause
42          * @param data associated with this message
43          */
44         public BGPNotificationMessage(final BGPError error, final byte[] data) {
45                 super();
46                 this.error = error;
47                 this.data = data;
48         }
49
50         /**
51          * Returns BGPError contained in this message.
52          * 
53          * @return the error
54          */
55         public BGPError getError() {
56                 return this.error;
57         }
58
59         /**
60          * Returns possible data associated with this message.
61          * 
62          * @return the data
63          */
64         public byte[] getData() {
65                 return this.data;
66         }
67
68         @Override
69         public String toString() {
70                 final StringBuilder builder = new StringBuilder();
71                 builder.append("BGPNotificationMessage [error=");
72                 builder.append(this.error);
73                 builder.append(", data=");
74                 builder.append(Arrays.toString(this.data));
75                 builder.append("]");
76                 return builder.toString();
77         }
78 }