Jonathan Hart | b39a67d | 2013-08-10 23:59:50 +1200 | [diff] [blame^] | 1 | package net.onrc.onos.ofcontroller.bgproute; |
| 2 | |
| 3 | import java.net.InetAddress; |
| 4 | import java.net.UnknownHostException; |
| 5 | |
| 6 | public class RibEntry { |
| 7 | private InetAddress routerId; |
| 8 | private InetAddress nextHop; |
| 9 | |
| 10 | public RibEntry(InetAddress routerId, InetAddress nextHop) { |
| 11 | this.routerId = routerId; |
| 12 | this.nextHop = nextHop; |
| 13 | } |
| 14 | |
| 15 | public RibEntry(String routerId, String nextHop) { |
| 16 | try { |
| 17 | this.routerId = InetAddress.getByName(routerId); |
| 18 | this.nextHop = InetAddress.getByName(nextHop); |
| 19 | } catch (UnknownHostException e) { |
| 20 | throw new IllegalArgumentException("Invalid address format"); |
| 21 | } |
| 22 | } |
| 23 | |
| 24 | public InetAddress getNextHop() { |
| 25 | return nextHop; |
| 26 | } |
| 27 | |
| 28 | @Override |
| 29 | public boolean equals(Object other) { |
| 30 | if (other == null || !(other instanceof RibEntry)) { |
| 31 | return false; |
| 32 | } |
| 33 | |
| 34 | RibEntry otherRibEntry = (RibEntry) other; |
| 35 | |
| 36 | return this.routerId.equals(otherRibEntry.routerId) |
| 37 | && this.nextHop.equals(otherRibEntry.nextHop); |
| 38 | } |
| 39 | |
| 40 | @Override |
| 41 | public int hashCode() { |
| 42 | int hash = 17; |
| 43 | hash = 31 * hash + routerId.hashCode(); |
| 44 | hash = 31 * hash + nextHop.hashCode(); |
| 45 | return hash; |
| 46 | } |
| 47 | } |