Jonathan Hart | 552e31f | 2015-02-06 11:11:59 -0800 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Laboratory |
Jonathan Hart | 552e31f | 2015-02-06 11:11:59 -0800 | [diff] [blame] | 3 | * |
| 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 Hart | 2da1e60 | 2015-02-18 19:09:24 -0800 | [diff] [blame] | 16 | package org.onosproject.routing; |
Jonathan Hart | 41349e9 | 2015-02-09 14:14:02 -0800 | [diff] [blame] | 17 | |
| 18 | import com.google.common.base.MoreObjects; |
| 19 | |
| 20 | import java.util.Objects; |
Jonathan Hart | 552e31f | 2015-02-06 11:11:59 -0800 | [diff] [blame] | 21 | |
| 22 | /** |
| 23 | * Represents a change to the Forwarding Information Base (FIB). |
| 24 | */ |
| 25 | public 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 Hart | 41349e9 | 2015-02-09 14:14:02 -0800 | [diff] [blame] | 73 | |
| 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 Hart | 552e31f | 2015-02-06 11:11:59 -0800 | [diff] [blame] | 98 | } |