blob: 3f70ef5722d17d406c722920ed5c848995a2d881 [file] [log] [blame]
Mohammad Shahidaa7c1232017-08-09 11:13:15 +05301/*
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
Ray Milkeya95193c2017-08-10 15:35:36 -070017package org.onosproject.evpnrouteservice;
18
19import java.util.Objects;
Mohammad Shahidaa7c1232017-08-09 11:13:15 +053020
21import org.onlab.packet.IpPrefix;
22import org.onlab.packet.MacAddress;
23
Mohammad Shahidaa7c1232017-08-09 11:13:15 +053024import static com.google.common.base.MoreObjects.toStringHelper;
25import static com.google.common.base.Preconditions.checkNotNull;
26
27/**
28 * Represents a evpn prefix.
29 */
30public final class EvpnPrefix {
31
32 private final RouteDistinguisher rd;
33 private final MacAddress macAddress;
34 private final IpPrefix ipAddress;
35
36 /**
37 * Constructor to initialize the parameters.
38 *
39 * @param rd route distinguisher
40 * @param macAddress mac address
41 * @param ipAddress IP address
42 */
43 public EvpnPrefix(RouteDistinguisher rd, MacAddress macAddress,
44 IpPrefix ipAddress) {
45 checkNotNull(rd);
46 checkNotNull(macAddress);
47 checkNotNull(ipAddress);
48 this.rd = rd;
49 this.macAddress = macAddress;
50 this.ipAddress = ipAddress;
51 }
52
53 /**
54 * Creates the evpn prefix by given parameters.
55 *
56 * @param rd route distinguisher
57 * @param macAddress mac address
58 * @param ipAddress ip address
59 * @return EvpnPrefix
60 */
61 public static EvpnPrefix evpnPrefix(RouteDistinguisher rd,
62 MacAddress macAddress,
63 IpPrefix ipAddress) {
64 return new EvpnPrefix(rd, macAddress, ipAddress);
65 }
66
67 /**
68 * Returns the route distinguisher.
69 *
70 * @return RouteDistinguisher
71 */
72 public RouteDistinguisher routeDistinguisher() {
73 return rd;
74 }
75
76 /**
77 * Returns the mac address.
78 *
79 * @return MacAddress
80 */
81 public MacAddress macAddress() {
82 return macAddress;
83 }
84
85 /**
86 * Returns the IP address.
87 *
88 * @return Ip4Address
89 */
90 public IpPrefix ipAddress() {
91 return ipAddress;
92 }
93
94 @Override
95 public int hashCode() {
96 return Objects.hash(rd, macAddress, ipAddress);
97 }
98
99 @Override
100 public boolean equals(Object other) {
101 if (this == other) {
102 return true;
103 }
104
105 if (!(other instanceof EvpnPrefix)) {
106 return false;
107 }
108
109 EvpnPrefix that = (EvpnPrefix) other;
110
111 return Objects.equals(this.macAddress(), that.macAddress())
112 && Objects.equals(this.ipAddress, that.ipAddress)
113 && Objects.equals(this.rd, that.rd);
114 }
115
116 @Override
117 public String toString() {
118 return toStringHelper(this).add("macAddress", this.macAddress())
119 .add("ipAddress", this.ipAddress()).add("rd", this.rd)
120 .toString();
121 }
122}