blob: c6efc3f1c60e3fdf9b83b7b4c8e7f1a365138bf1 [file] [log] [blame]
Jonathan Hart552e31f2015-02-06 11:11:59 -08001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2015-present Open Networking Laboratory
Jonathan Hart552e31f2015-02-06 11:11:59 -08003 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
Jonathan Hart2da1e602015-02-18 19:09:24 -080016package org.onosproject.routing;
Jonathan Hart41349e92015-02-09 14:14:02 -080017
18import com.google.common.base.MoreObjects;
19
20import java.util.Objects;
Jonathan Hart552e31f2015-02-06 11:11:59 -080021
22/**
23 * Represents a change to the Forwarding Information Base (FIB).
24 */
25public class FibUpdate {
26
27 /**
28 * Specifies the type of the FIB update.
29 */
30 public enum Type {
31 /**
32 * The update contains a new or updated FIB entry for a prefix.
33 */
34 UPDATE,
35
36 /**
37 * The update signals that a prefix should be removed from the FIB.
38 */
39 DELETE
40 }
41
42 private final Type type;
43 private final FibEntry entry;
44
45 /**
46 * Creates a new FIB update.
47 *
48 * @param type type of the update
49 * @param entry FIB entry describing the update
50 */
51 public FibUpdate(Type type, FibEntry entry) {
52 this.type = type;
53 this.entry = entry;
54 }
55
56 /**
57 * Returns the type of the update.
58 *
59 * @return update type
60 */
61 public Type type() {
62 return type;
63 }
64
65 /**
66 * Returns the FIB entry which contains update information.
67 *
68 * @return the FIB entry
69 */
70 public FibEntry entry() {
71 return entry;
72 }
Jonathan Hart41349e92015-02-09 14:14:02 -080073
74 @Override
75 public boolean equals(Object o) {
76 if (!(o instanceof FibUpdate)) {
77 return false;
78 }
79
80 FibUpdate that = (FibUpdate) o;
81
82 return Objects.equals(this.type, that.type) &&
83 Objects.equals(this.entry, that.entry);
84 }
85
86 @Override
87 public int hashCode() {
88 return Objects.hash(type, entry);
89 }
90
91 @Override
92 public String toString() {
93 return MoreObjects.toStringHelper(getClass())
94 .add("type", type)
95 .add("entry", entry)
96 .toString();
97 }
Jonathan Hart552e31f2015-02-06 11:11:59 -080098}