blob: 614bffe82202b4c23330f115c1cf857047867d91 [file] [log] [blame]
Jonathan Hart8f6dc092014-04-18 15:56:43 -07001package net.onrc.onos.apps.sdnip;
Jonathan Harte963a332013-07-26 15:56:20 +12002
Jonathan Hart8dc7d482014-08-25 23:15:54 -07003import java.util.Objects;
4
5
Jonathan Hart31e15f12014-04-10 10:33:00 -07006/**
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 Harte963a332013-07-26 15:56:20 +120012public class RibUpdate {
Jonathan Hart738980f2014-04-04 10:11:15 -070013 private final Operation operation;
14 private final Prefix prefix;
15 private final RibEntry ribEntry;
Ray Milkey5d406012014-04-08 14:44:41 -070016
Jonathan Hart31e15f12014-04-10 10:33:00 -070017 /**
18 * Updates can either add new routes or revoke old routes. The
Sho SHIMIZU88e3a7f2014-07-10 09:14:40 -070019 * {@link Operation} enum describes which action is being taken.
Jonathan Hart31e15f12014-04-10 10:33:00 -070020 */
Ray Milkey269ffb92014-04-03 14:43:30 -070021 public enum Operation {
Jonathan Hart31e15f12014-04-10 10:33:00 -070022 /**
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 Milkey269ffb92014-04-03 14:43:30 -070028 UPDATE,
Jonathan Hart31e15f12014-04-10 10:33:00 -070029 /**
30 * Represents a route delete. ONOS should remove this prefix and route
31 * information from its route table.
32 */
Ray Milkey269ffb92014-04-03 14:43:30 -070033 DELETE
34 }
Jonathan Harte963a332013-07-26 15:56:20 +120035
Jonathan Hart31e15f12014-04-10 10:33:00 -070036 /**
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 Milkey269ffb92014-04-03 14:43:30 -070044 public RibUpdate(Operation operation, Prefix prefix, RibEntry ribEntry) {
45 this.operation = operation;
46 this.prefix = prefix;
47 this.ribEntry = ribEntry;
48 }
Jonathan Harte963a332013-07-26 15:56:20 +120049
Jonathan Hart31e15f12014-04-10 10:33:00 -070050 /**
51 * Gets the operation of the update.
52 *
53 * @return the operation
54 */
Ray Milkey269ffb92014-04-03 14:43:30 -070055 public Operation getOperation() {
56 return operation;
57 }
58
Jonathan Hart31e15f12014-04-10 10:33:00 -070059 /**
60 * Gets the route prefix of the update.
61 *
62 * @return the prefix
63 */
Ray Milkey269ffb92014-04-03 14:43:30 -070064 public Prefix getPrefix() {
65 return prefix;
66 }
67
Jonathan Hart31e15f12014-04-10 10:33:00 -070068 /**
69 * Gets the {@link RibEntry} of the update.
70 *
71 * @return the entry
72 */
Ray Milkey269ffb92014-04-03 14:43:30 -070073 public RibEntry getRibEntry() {
74 return ribEntry;
75 }
Jonathan Hart8dc7d482014-08-25 23:15:54 -070076
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 Harte963a332013-07-26 15:56:20 +120093}