Jonathan Hart | 552e31f | 2015-02-06 11:11:59 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 Open Networking Laboratory |
| 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 | 552e31f | 2015-02-06 11:11:59 -0800 | [diff] [blame] | 17 | |
Jonathan Hart | 41349e9 | 2015-02-09 14:14:02 -0800 | [diff] [blame] | 18 | import com.google.common.base.MoreObjects; |
Jonathan Hart | 552e31f | 2015-02-06 11:11:59 -0800 | [diff] [blame] | 19 | import org.onlab.packet.IpAddress; |
| 20 | import org.onlab.packet.IpPrefix; |
| 21 | import org.onlab.packet.MacAddress; |
| 22 | |
Jonathan Hart | 41349e9 | 2015-02-09 14:14:02 -0800 | [diff] [blame] | 23 | import java.util.Objects; |
| 24 | |
Jonathan Hart | 552e31f | 2015-02-06 11:11:59 -0800 | [diff] [blame] | 25 | /** |
| 26 | * An entry in the Forwarding Information Base (FIB). |
| 27 | */ |
| 28 | public class FibEntry { |
| 29 | |
| 30 | private final IpPrefix prefix; |
| 31 | private final IpAddress nextHopIp; |
| 32 | private final MacAddress nextHopMac; |
| 33 | |
| 34 | /** |
| 35 | * Creates a new FIB entry. |
| 36 | * |
| 37 | * @param prefix IP prefix of the FIB entry |
| 38 | * @param nextHopIp IP address of the next hop |
| 39 | * @param nextHopMac MAC address of the next hop |
| 40 | */ |
| 41 | public FibEntry(IpPrefix prefix, IpAddress nextHopIp, MacAddress nextHopMac) { |
| 42 | this.prefix = prefix; |
| 43 | this.nextHopIp = nextHopIp; |
| 44 | this.nextHopMac = nextHopMac; |
| 45 | } |
| 46 | |
| 47 | /** |
| 48 | * Returns the IP prefix of the FIB entry. |
| 49 | * |
| 50 | * @return the IP prefix |
| 51 | */ |
| 52 | public IpPrefix prefix() { |
| 53 | return prefix; |
| 54 | } |
| 55 | |
| 56 | /** |
| 57 | * Returns the IP address of the next hop. |
| 58 | * |
| 59 | * @return the IP address |
| 60 | */ |
| 61 | public IpAddress nextHopIp() { |
| 62 | return nextHopIp; |
| 63 | } |
| 64 | |
| 65 | /** |
| 66 | * Returns the MAC address of the next hop. |
| 67 | * |
| 68 | * @return the MAC address |
| 69 | */ |
| 70 | public MacAddress nextHopMac() { |
| 71 | return nextHopMac; |
| 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 FibEntry)) { |
| 77 | return false; |
| 78 | } |
| 79 | |
| 80 | FibEntry that = (FibEntry) o; |
| 81 | |
| 82 | return Objects.equals(this.prefix, that.prefix) && |
| 83 | Objects.equals(this.nextHopIp, that.nextHopIp) && |
| 84 | Objects.equals(this.nextHopMac, that.nextHopMac); |
| 85 | } |
| 86 | |
| 87 | @Override |
| 88 | public int hashCode() { |
| 89 | return Objects.hash(prefix, nextHopIp, nextHopMac); |
| 90 | } |
| 91 | |
| 92 | @Override |
| 93 | public String toString() { |
| 94 | return MoreObjects.toStringHelper(getClass()) |
| 95 | .add("prefix", prefix) |
| 96 | .add("nextHopIp", nextHopIp) |
| 97 | .add("nextHopMac", nextHopMac) |
| 98 | .toString(); |
| 99 | } |
Jonathan Hart | 552e31f | 2015-02-06 11:11:59 -0800 | [diff] [blame] | 100 | } |