Jonathan Hart | 8f6dc09 | 2014-04-18 15:56:43 -0700 | [diff] [blame] | 1 | package net.onrc.onos.apps.sdnip; |
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 | |
Jonathan Hart | 31e15f1 | 2014-04-10 10:33:00 -0700 | [diff] [blame] | 7 | /** |
| 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 Hart | b39a67d | 2013-08-10 23:59:50 +1200 | [diff] [blame] | 15 | public class RibEntry { |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 16 | private final InetAddress routerId; |
| 17 | private final InetAddress nextHop; |
Jonathan Hart | e4c9869 | 2013-10-18 17:40:03 -0700 | [diff] [blame] | 18 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 19 | /* |
| 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 Hart | 5e54f2e | 2014-04-17 13:43:40 -0700 | [diff] [blame] | 22 | * store RibUpdates in the Ptree. But, that's a bigger change to change |
| 23 | * what the Ptree stores. |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 24 | */ |
| 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 Milkey | ec83894 | 2014-04-09 11:28:43 -0700 | [diff] [blame] | 33 | private static final long NULL_TIME = -1; |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 34 | |
Jonathan Hart | 31e15f1 | 2014-04-10 10:33:00 -0700 | [diff] [blame] | 35 | /** |
| 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 Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 43 | 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 Hart | 31e15f1 | 2014-04-10 10:33:00 -0700 | [diff] [blame] | 50 | /** |
| 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 Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 59 | 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 Hart | 31e15f1 | 2014-04-10 10:33:00 -0700 | [diff] [blame] | 66 | /** |
| 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 Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 80 | this.routerId = InetAddresses.forString(routerId); |
| 81 | this.nextHop = InetAddresses.forString(nextHop); |
| 82 | this.sequenceNum = sequenceNum; |
| 83 | this.sysUpTime = sysUpTime; |
| 84 | } |
| 85 | |
Jonathan Hart | 31e15f1 | 2014-04-10 10:33:00 -0700 | [diff] [blame] | 86 | /** |
| 87 | * Gets the next hop IP address of this route entry. |
| 88 | * |
| 89 | * @return the next hop IP address |
| 90 | */ |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 91 | public InetAddress getNextHop() { |
| 92 | return nextHop; |
| 93 | } |
| 94 | |
Jonathan Hart | 31e15f1 | 2014-04-10 10:33:00 -0700 | [diff] [blame] | 95 | /** |
| 96 | * Gets the sysuptime parameter sent with the update from BGPd. |
| 97 | * |
| 98 | * @return the sysuptime parameter |
| 99 | */ |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 100 | public long getSysUpTime() { |
| 101 | return sysUpTime; |
| 102 | } |
| 103 | |
Jonathan Hart | 31e15f1 | 2014-04-10 10:33:00 -0700 | [diff] [blame] | 104 | /** |
| 105 | * Gets the sequencenum parameter sent with the update from BGPd. |
| 106 | * |
| 107 | * @return the sequencenum parameter |
| 108 | */ |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 109 | public long getSequenceNum() { |
| 110 | return sequenceNum; |
| 111 | } |
| 112 | |
| 113 | @Override |
| 114 | public boolean equals(Object other) { |
Jonathan Hart | 738980f | 2014-04-04 10:11:15 -0700 | [diff] [blame] | 115 | if (!(other instanceof RibEntry)) { |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 116 | 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 Hart | b39a67d | 2013-08-10 23:59:50 +1200 | [diff] [blame] | 132 | } |