blob: ccf895127c6c0886710892c88245b8d958ccd2c2 [file] [log] [blame]
Jonathan Hartb39a67d2013-08-10 23:59:50 +12001package net.onrc.onos.ofcontroller.bgproute;
2
3import java.net.InetAddress;
Jonathan Hartabf10222013-08-13 10:19:34 +12004
5import com.google.common.net.InetAddresses;
Jonathan Hartb39a67d2013-08-10 23:59:50 +12006
7public class RibEntry {
Jonathan Hart08ee8522013-09-22 17:34:43 +12008 private final InetAddress routerId;
9 private final InetAddress nextHop;
Jonathan Harte4c98692013-10-18 17:40:03 -070010
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 Hartb39a67d2013-08-10 23:59:50 +120026
27 public RibEntry(InetAddress routerId, InetAddress nextHop) {
28 this.routerId = routerId;
29 this.nextHop = nextHop;
Jonathan Harte4c98692013-10-18 17:40:03 -070030 sequenceNum = NULL_TIME;
31 sysUpTime = NULL_TIME;
Jonathan Hartb39a67d2013-08-10 23:59:50 +120032 }
33
34 public RibEntry(String routerId, String nextHop) {
Jonathan Hartabf10222013-08-13 10:19:34 +120035 this.routerId = InetAddresses.forString(routerId);
36 this.nextHop = InetAddresses.forString(nextHop);
Jonathan Harte4c98692013-10-18 17:40:03 -070037 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 Hartb39a67d2013-08-10 23:59:50 +120047 }
48
49 public InetAddress getNextHop() {
50 return nextHop;
51 }
52
Jonathan Harte4c98692013-10-18 17:40:03 -070053 public long getSysUpTime() {
54 return sysUpTime;
55 }
56
57 public long getSequenceNum() {
58 return sequenceNum;
59 }
60
Jonathan Hartb39a67d2013-08-10 23:59:50 +120061 @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}