Jonathan Hart | 8f6dc09 | 2014-04-18 15:56:43 -0700 | [diff] [blame] | 1 | package net.onrc.onos.apps.sdnip; |
Jonathan Hart | e963a33 | 2013-07-26 15:56:20 +1200 | [diff] [blame] | 2 | |
Jonathan Hart | 8dc7d48 | 2014-08-25 23:15:54 -0700 | [diff] [blame] | 3 | import java.util.Objects; |
| 4 | |
| 5 | |
Jonathan Hart | 31e15f1 | 2014-04-10 10:33:00 -0700 | [diff] [blame] | 6 | /** |
| 7 | * Represents a route update received from BGPd. An update has an operation |
| 8 | * describing whether the update is adding a route or revoking a route. It also |
| 9 | * contains the route prefix, and {@link RibEntry} containing next hop and |
| 10 | * sequence number information for the update. |
| 11 | */ |
Jonathan Hart | e963a33 | 2013-07-26 15:56:20 +1200 | [diff] [blame] | 12 | public class RibUpdate { |
Jonathan Hart | 738980f | 2014-04-04 10:11:15 -0700 | [diff] [blame] | 13 | private final Operation operation; |
| 14 | private final Prefix prefix; |
| 15 | private final RibEntry ribEntry; |
Ray Milkey | 5d40601 | 2014-04-08 14:44:41 -0700 | [diff] [blame] | 16 | |
Jonathan Hart | 31e15f1 | 2014-04-10 10:33:00 -0700 | [diff] [blame] | 17 | /** |
| 18 | * Updates can either add new routes or revoke old routes. The |
Sho SHIMIZU | 88e3a7f | 2014-07-10 09:14:40 -0700 | [diff] [blame] | 19 | * {@link Operation} enum describes which action is being taken. |
Jonathan Hart | 31e15f1 | 2014-04-10 10:33:00 -0700 | [diff] [blame] | 20 | */ |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 21 | public enum Operation { |
Jonathan Hart | 31e15f1 | 2014-04-10 10:33:00 -0700 | [diff] [blame] | 22 | /** |
| 23 | * Represents a route update. ONOS should update its route information |
| 24 | * for this prefix to the new information provided in this |
| 25 | * {@link RibUpdate}. This means either add a new prefix, or update |
| 26 | * the information for an existing prefix. |
| 27 | */ |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 28 | UPDATE, |
Jonathan Hart | 31e15f1 | 2014-04-10 10:33:00 -0700 | [diff] [blame] | 29 | /** |
| 30 | * Represents a route delete. ONOS should remove this prefix and route |
| 31 | * information from its route table. |
| 32 | */ |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 33 | DELETE |
| 34 | } |
Jonathan Hart | e963a33 | 2013-07-26 15:56:20 +1200 | [diff] [blame] | 35 | |
Jonathan Hart | 31e15f1 | 2014-04-10 10:33:00 -0700 | [diff] [blame] | 36 | /** |
| 37 | * Class constructor, taking the operation of the update, the route prefix |
| 38 | * and the {@link RibEntry} describing the update. |
| 39 | * |
| 40 | * @param operation the operation of the update |
| 41 | * @param prefix the route prefix |
| 42 | * @param ribEntry the update entry |
| 43 | */ |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 44 | public RibUpdate(Operation operation, Prefix prefix, RibEntry ribEntry) { |
| 45 | this.operation = operation; |
| 46 | this.prefix = prefix; |
| 47 | this.ribEntry = ribEntry; |
| 48 | } |
Jonathan Hart | e963a33 | 2013-07-26 15:56:20 +1200 | [diff] [blame] | 49 | |
Jonathan Hart | 31e15f1 | 2014-04-10 10:33:00 -0700 | [diff] [blame] | 50 | /** |
| 51 | * Gets the operation of the update. |
| 52 | * |
| 53 | * @return the operation |
| 54 | */ |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 55 | public Operation getOperation() { |
| 56 | return operation; |
| 57 | } |
| 58 | |
Jonathan Hart | 31e15f1 | 2014-04-10 10:33:00 -0700 | [diff] [blame] | 59 | /** |
| 60 | * Gets the route prefix of the update. |
| 61 | * |
| 62 | * @return the prefix |
| 63 | */ |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 64 | public Prefix getPrefix() { |
| 65 | return prefix; |
| 66 | } |
| 67 | |
Jonathan Hart | 31e15f1 | 2014-04-10 10:33:00 -0700 | [diff] [blame] | 68 | /** |
| 69 | * Gets the {@link RibEntry} of the update. |
| 70 | * |
| 71 | * @return the entry |
| 72 | */ |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 73 | public RibEntry getRibEntry() { |
| 74 | return ribEntry; |
| 75 | } |
Jonathan Hart | 8dc7d48 | 2014-08-25 23:15:54 -0700 | [diff] [blame] | 76 | |
| 77 | @Override |
| 78 | public boolean equals(Object o) { |
| 79 | if (!(o instanceof RibUpdate)) { |
| 80 | return false; |
| 81 | } |
| 82 | |
| 83 | RibUpdate otherUpdate = (RibUpdate) o; |
| 84 | return Objects.equals(this.operation, otherUpdate.operation) |
| 85 | && Objects.equals(this.prefix, otherUpdate.prefix) |
| 86 | && Objects.equals(this.ribEntry, otherUpdate.ribEntry); |
| 87 | } |
| 88 | |
| 89 | @Override |
| 90 | public int hashCode() { |
| 91 | return Objects.hash(operation, prefix, ribEntry); |
| 92 | } |
Jonathan Hart | e963a33 | 2013-07-26 15:56:20 +1200 | [diff] [blame] | 93 | } |