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; |
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 { |
Jonathan Hart | 08ee852 | 2013-09-22 17:34:43 +1200 | [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 | |
| 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; |
Jonathan Hart | b39a67d | 2013-08-10 23:59:50 +1200 | [diff] [blame] | 26 | |
| 27 | public RibEntry(InetAddress routerId, InetAddress nextHop) { |
| 28 | this.routerId = routerId; |
| 29 | this.nextHop = nextHop; |
Jonathan Hart | e4c9869 | 2013-10-18 17:40:03 -0700 | [diff] [blame] | 30 | sequenceNum = NULL_TIME; |
| 31 | sysUpTime = NULL_TIME; |
Jonathan Hart | b39a67d | 2013-08-10 23:59:50 +1200 | [diff] [blame] | 32 | } |
| 33 | |
| 34 | public RibEntry(String routerId, String nextHop) { |
Jonathan Hart | abf1022 | 2013-08-13 10:19:34 +1200 | [diff] [blame] | 35 | this.routerId = InetAddresses.forString(routerId); |
| 36 | this.nextHop = InetAddresses.forString(nextHop); |
Jonathan Hart | e4c9869 | 2013-10-18 17:40:03 -0700 | [diff] [blame] | 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; |
Jonathan Hart | b39a67d | 2013-08-10 23:59:50 +1200 | [diff] [blame] | 47 | } |
| 48 | |
| 49 | public InetAddress getNextHop() { |
| 50 | return nextHop; |
| 51 | } |
| 52 | |
Jonathan Hart | e4c9869 | 2013-10-18 17:40:03 -0700 | [diff] [blame] | 53 | public long getSysUpTime() { |
| 54 | return sysUpTime; |
| 55 | } |
| 56 | |
| 57 | public long getSequenceNum() { |
| 58 | return sequenceNum; |
| 59 | } |
| 60 | |
Jonathan Hart | b39a67d | 2013-08-10 23:59:50 +1200 | [diff] [blame] | 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 | } |
| 80 | } |