Jonathan Hart | 382623d | 2014-04-03 09:48:11 -0700 | [diff] [blame] | 1 | package net.onrc.onos.apps.bgproute; |
Jonathan Hart | b39a67d | 2013-08-10 23:59:50 +1200 | [diff] [blame] | 2 | |
| 3 | import java.net.InetAddress; |
Jonathan Hart | abf1022 | 2013-08-13 10:19:34 +1200 | [diff] [blame] | 4 | |
| 5 | import com.google.common.net.InetAddresses; |
Jonathan Hart | b39a67d | 2013-08-10 23:59:50 +1200 | [diff] [blame] | 6 | |
| 7 | public class RibEntry { |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 8 | private final InetAddress routerId; |
| 9 | private final InetAddress nextHop; |
Jonathan Hart | e4c9869 | 2013-10-18 17:40:03 -0700 | [diff] [blame] | 10 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 11 | /* |
| 12 | * Store the sequence number information provided on the update here for |
| 13 | * now. I think this *should* really be in the RibUpdate, and we should |
| 14 | * store RibUpdates in the Ptrie. But, that's a bigger change to change |
| 15 | * what the Ptrie stores. |
| 16 | */ |
| 17 | private final long sysUpTime; |
| 18 | private final long sequenceNum; |
| 19 | |
| 20 | /* |
| 21 | * Marker for RibEntries where we don't have sequence number info. |
| 22 | * The user of this class should make sure they don't check this data |
| 23 | * if they don't provide it. |
| 24 | */ |
| 25 | private final static long NULL_TIME = -1; |
| 26 | |
| 27 | public RibEntry(InetAddress routerId, InetAddress nextHop) { |
| 28 | this.routerId = routerId; |
| 29 | this.nextHop = nextHop; |
| 30 | sequenceNum = NULL_TIME; |
| 31 | sysUpTime = NULL_TIME; |
| 32 | } |
| 33 | |
| 34 | public RibEntry(String routerId, String nextHop) { |
| 35 | this.routerId = InetAddresses.forString(routerId); |
| 36 | this.nextHop = InetAddresses.forString(nextHop); |
| 37 | sequenceNum = NULL_TIME; |
| 38 | sysUpTime = NULL_TIME; |
| 39 | } |
| 40 | |
| 41 | public RibEntry(String routerId, String nextHop, long sysUpTime |
| 42 | , long sequenceNum) { |
| 43 | this.routerId = InetAddresses.forString(routerId); |
| 44 | this.nextHop = InetAddresses.forString(nextHop); |
| 45 | this.sequenceNum = sequenceNum; |
| 46 | this.sysUpTime = sysUpTime; |
| 47 | } |
| 48 | |
| 49 | public InetAddress getNextHop() { |
| 50 | return nextHop; |
| 51 | } |
| 52 | |
| 53 | public long getSysUpTime() { |
| 54 | return sysUpTime; |
| 55 | } |
| 56 | |
| 57 | public long getSequenceNum() { |
| 58 | return sequenceNum; |
| 59 | } |
| 60 | |
| 61 | @Override |
| 62 | public boolean equals(Object other) { |
| 63 | if (other == null || !(other instanceof RibEntry)) { |
| 64 | return false; |
| 65 | } |
| 66 | |
| 67 | RibEntry otherRibEntry = (RibEntry) other; |
| 68 | |
| 69 | return this.routerId.equals(otherRibEntry.routerId) |
| 70 | && this.nextHop.equals(otherRibEntry.nextHop); |
| 71 | } |
| 72 | |
| 73 | @Override |
| 74 | public int hashCode() { |
| 75 | int hash = 17; |
| 76 | hash = 31 * hash + routerId.hashCode(); |
| 77 | hash = 31 * hash + nextHop.hashCode(); |
| 78 | return hash; |
| 79 | } |
Jonathan Hart | b39a67d | 2013-08-10 23:59:50 +1200 | [diff] [blame] | 80 | } |