Initial code drop
[bgpcep.git] / bgp / parser-impl / src / main / java / org / opendaylight / protocol / bgp / parser / impl / BGPLinkMP.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.impl;
9
10 import java.util.Set;
11
12 import org.opendaylight.protocol.bgp.linkstate.LinkIdentifier;
13 import org.opendaylight.protocol.bgp.linkstate.SourceProtocol;
14
15 /**
16  * 
17  * Link State MP_(UN)REACH_NLRI (contains BGP Link inf.)
18  * 
19  */
20 public class BGPLinkMP extends AbstractLinkstateMP<LinkIdentifier> {
21
22         private final Set<LinkIdentifier> link;
23
24         /**
25          * Creates BGP LINK MP Reach.
26          * 
27          * @param identifier long
28          * @param sourceProtocol {@link SourceProtocol}
29          * @param prefixes set of prefix descriptors
30          * @param reachable true if the attribute is MPReach, false if the attribute is MPUnreach
31          */
32         public BGPLinkMP(final long identifier, final SourceProtocol sourceProtocol, final boolean reachable, final Set<LinkIdentifier> link) {
33                 super(identifier, sourceProtocol, reachable);
34                 this.link = link;
35         }
36
37         @Override
38         public Set<LinkIdentifier> getNlri() {
39                 return this.link;
40         }
41
42         /* (non-Javadoc)
43          * @see java.lang.Object#hashCode()
44          */
45         @Override
46         public int hashCode() {
47                 final int prime = 31;
48                 int result = super.hashCode();
49                 result = prime * result + ((this.link == null) ? 0 : this.link.hashCode());
50                 return result;
51         }
52
53         /* (non-Javadoc)
54          * @see java.lang.Object#equals(java.lang.Object)
55          */
56         @Override
57         public boolean equals(final Object obj) {
58                 if (this == obj)
59                         return true;
60                 if (!super.equals(obj))
61                         return false;
62                 if (this.getClass() != obj.getClass())
63                         return false;
64                 final BGPLinkMP other = (BGPLinkMP) obj;
65                 if (this.link == null) {
66                         if (other.link != null)
67                                 return false;
68                 } else if (!this.link.equals(other.link))
69                         return false;
70                 return true;
71         }
72
73         /* (non-Javadoc)
74          * @see java.lang.Object#toString()
75          */
76         @Override
77         public String toString() {
78                 final StringBuilder builder = new StringBuilder();
79                 builder.append("BGPLinkMP [link=");
80                 builder.append(this.link);
81                 builder.append("]");
82                 return builder.toString();
83         }
84 }