blob: 2392e01af956b41c638d730a2635f92d411acd10 [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
Jonathan Hart31e15f12014-04-10 10:33:00 -07007/**
8 * Represents an entry in the Routing Information Base (RIB) of a router.
9 * <p/>
10 * A route update from the BGP daemon contains a prefix and a RibEntry
11 * containing the next hop for the route. The RibEntry also contains
12 * information related to the synchronization mechanism between BGPd and
13 * SDN-IP, such as sequence numbers.
14 */
Jonathan Hartb39a67d2013-08-10 23:59:50 +120015public class RibEntry {
Ray Milkey269ffb92014-04-03 14:43:30 -070016 private final InetAddress routerId;
17 private final InetAddress nextHop;
Jonathan Harte4c98692013-10-18 17:40:03 -070018
Ray Milkey269ffb92014-04-03 14:43:30 -070019 /*
20 * Store the sequence number information provided on the update here for
21 * now. I think this *should* really be in the RibUpdate, and we should
Jonathan Hart5e54f2e2014-04-17 13:43:40 -070022 * store RibUpdates in the Ptree. But, that's a bigger change to change
23 * what the Ptree stores.
Ray Milkey269ffb92014-04-03 14:43:30 -070024 */
25 private final long sysUpTime;
26 private final long sequenceNum;
27
28 /*
29 * Marker for RibEntries where we don't have sequence number info.
30 * The user of this class should make sure they don't check this data
31 * if they don't provide it.
32 */
Ray Milkeyec838942014-04-09 11:28:43 -070033 private static final long NULL_TIME = -1;
Ray Milkey269ffb92014-04-03 14:43:30 -070034
Jonathan Hart31e15f12014-04-10 10:33:00 -070035 /**
36 * Class constructor, taking the router ID and next hop IP address as
37 * {@link InetAddress} objects.
38 *
39 * @param routerId the router ID which identifies the route table in BGPd
40 * that this update came from
41 * @param nextHop next hop IP address for this route entry
42 */
Ray Milkey269ffb92014-04-03 14:43:30 -070043 public RibEntry(InetAddress routerId, InetAddress nextHop) {
44 this.routerId = routerId;
45 this.nextHop = nextHop;
46 sequenceNum = NULL_TIME;
47 sysUpTime = NULL_TIME;
48 }
49
Jonathan Hart31e15f12014-04-10 10:33:00 -070050 /**
51 * Class constructor, taking the router ID and next hop IP address as
52 * Strings. The addresses must be in dot-notation form
53 * (e.g. {@code 0.0.0.0}).
54 *
55 * @param routerId the router ID which identifies the route table in BGPd
56 * that this update came from
57 * @param nextHop next hop IP address for this route entry
58 */
Ray Milkey269ffb92014-04-03 14:43:30 -070059 public RibEntry(String routerId, String nextHop) {
60 this.routerId = InetAddresses.forString(routerId);
61 this.nextHop = InetAddresses.forString(nextHop);
62 sequenceNum = NULL_TIME;
63 sysUpTime = NULL_TIME;
64 }
65
Jonathan Hart31e15f12014-04-10 10:33:00 -070066 /**
67 * Class constructor, taking the router ID and next hop IP address as
68 * Strings, as well as the sequence numbers of the updates. Sequence
69 * numbers are used to establish ordering of updates from BGPd. The
70 * addresses must be in dot-notation form (e.g. {@code 0.0.0.0}).
71 *
72 * @param routerId the router ID which identifies the route table in BGPd
73 * that this update came from
74 * @param nextHop next hop IP address for this route entry
75 * @param sysUpTime the sysuptime parameter on the update from BGPd
76 * @param sequenceNum the sequencenum parameter on the update from BGPd
77 */
78 public RibEntry(String routerId, String nextHop, long sysUpTime,
79 long sequenceNum) {
Ray Milkey269ffb92014-04-03 14:43:30 -070080 this.routerId = InetAddresses.forString(routerId);
81 this.nextHop = InetAddresses.forString(nextHop);
82 this.sequenceNum = sequenceNum;
83 this.sysUpTime = sysUpTime;
84 }
85
Jonathan Hart31e15f12014-04-10 10:33:00 -070086 /**
87 * Gets the next hop IP address of this route entry.
88 *
89 * @return the next hop IP address
90 */
Ray Milkey269ffb92014-04-03 14:43:30 -070091 public InetAddress getNextHop() {
92 return nextHop;
93 }
94
Jonathan Hart31e15f12014-04-10 10:33:00 -070095 /**
96 * Gets the sysuptime parameter sent with the update from BGPd.
97 *
98 * @return the sysuptime parameter
99 */
Ray Milkey269ffb92014-04-03 14:43:30 -0700100 public long getSysUpTime() {
101 return sysUpTime;
102 }
103
Jonathan Hart31e15f12014-04-10 10:33:00 -0700104 /**
105 * Gets the sequencenum parameter sent with the update from BGPd.
106 *
107 * @return the sequencenum parameter
108 */
Ray Milkey269ffb92014-04-03 14:43:30 -0700109 public long getSequenceNum() {
110 return sequenceNum;
111 }
112
113 @Override
114 public boolean equals(Object other) {
Jonathan Hart738980f2014-04-04 10:11:15 -0700115 if (!(other instanceof RibEntry)) {
Ray Milkey269ffb92014-04-03 14:43:30 -0700116 return false;
117 }
118
119 RibEntry otherRibEntry = (RibEntry) other;
120
121 return this.routerId.equals(otherRibEntry.routerId)
122 && this.nextHop.equals(otherRibEntry.nextHop);
123 }
124
125 @Override
126 public int hashCode() {
127 int hash = 17;
128 hash = 31 * hash + routerId.hashCode();
129 hash = 31 * hash + nextHop.hashCode();
130 return hash;
131 }
Jonathan Hartb39a67d2013-08-10 23:59:50 +1200132}