blob: de63e4456b213205bb693e60090aa152006193d0 [file] [log] [blame]
Kalhee Kimba366062017-11-07 16:32:09 +00001/*
2 * Copyright 2017-present Open Networking Foundation
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 */
16
17package org.onosproject.routing.fpm.api;
18
19import org.onlab.packet.IpAddress;
20import org.onlab.packet.IpPrefix;
21import java.util.Objects;
22import com.google.common.base.MoreObjects;
23import static com.google.common.base.Preconditions.checkNotNull;
24
25/**
26 * A class to define a Fpm record.
27 */
28public class FpmRecord {
29
30 public enum Type {
31 /**
32 * Signifies that record came from Dhcp Relay.
33 */
34 DHCP_RELAY,
35
36 /**
37 * Signifies that record came from RIP.
38 */
39 RIP
40 }
41
42 private IpPrefix prefix;
43 private IpAddress nextHop;
44 private Type type;
45
46 public FpmRecord(IpPrefix prefix, IpAddress nextHop, Type type) {
47 checkNotNull(prefix, "prefix cannot be null");
48 checkNotNull(nextHop, "ipAddress cannot be null");
49
50 this.prefix = prefix;
51 this.nextHop = nextHop;
52 this.type = type;
53 }
54
55 /**
56 * Gets IP prefix of record.
57 *
58 * @return the IP prefix
59 */
60 public IpPrefix ipPrefix() {
61 return prefix;
62 }
63
64 /**
65 * Gets IP address of record.
66 *
67 * @return the IP address
68 */
69 public IpAddress nextHop() {
70 return nextHop;
71 }
72
73 /**
74 * Gets type of record.
75 *
76 * @return the type
77 */
78 public Type type() {
79 return type;
80 }
81
82 @Override
83 public int hashCode() {
84 return Objects.hash(prefix, nextHop, type);
85 }
86
87 @Override
88 public boolean equals(Object obj) {
89 if (this == obj) {
90 return true;
91 }
92 if (!(obj instanceof FpmRecord)) {
93 return false;
94 }
95 FpmRecord that = (FpmRecord) obj;
96 return Objects.equals(prefix, that.prefix) &&
97 Objects.equals(nextHop, that.nextHop) &&
98 Objects.equals(type, that.type);
99 }
100
101 @Override
102 public String toString() {
103 return MoreObjects.toStringHelper(getClass())
104 .add("prefix", prefix)
105 .add("ipAddress", nextHop)
106 .add("type", type)
107 .toString();
108 }
109}