blob: ae16c8fef810834cb24911cd83f5a60a15c9d01c [file] [log] [blame]
Jonathan Hart382623d2014-04-03 09:48:11 -07001package net.onrc.onos.apps.bgproute;
Jonathan Hartb39a67d2013-08-10 23:59:50 +12002
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 {
Ray Milkey269ffb92014-04-03 14:43:30 -07008 private final InetAddress routerId;
9 private final InetAddress nextHop;
Jonathan Harte4c98692013-10-18 17:40:03 -070010
Ray Milkey269ffb92014-04-03 14:43:30 -070011 /*
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 */
Ray Milkeyec838942014-04-09 11:28:43 -070025 private static final long NULL_TIME = -1;
Ray Milkey269ffb92014-04-03 14:43:30 -070026
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) {
Jonathan Hart738980f2014-04-04 10:11:15 -070063 if (!(other instanceof RibEntry)) {
Ray Milkey269ffb92014-04-03 14:43:30 -070064 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 Hartb39a67d2013-08-10 23:59:50 +120080}