blob: 142b12e541dbea2e2a3eb0bcb7683f8b4dc73ae3 [file] [log] [blame]
Mohammad Shahid30fedc52017-08-09 11:49:40 +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
17package org.onosproject.bgpio.types;
18
19import org.onlab.packet.Ip4Address;
20
21import java.util.Objects;
22
23import static com.google.common.base.MoreObjects.toStringHelper;
24
25/**
26 * Represents the Evpn prefix.
27 */
28public class BgpEvpnPrefix {
29 private Ip4Address nextHop;
30 private RouteTarget rt;
31 BgpEvpnLabel label;
32
33 /**
34 * Constructor for initializing the evpn prefix.
35 *
36 * @param nextHop next hop
37 * @param rt route target
38 * @param label label
39 */
40 public BgpEvpnPrefix(Ip4Address nextHop, RouteTarget rt, BgpEvpnLabel label) {
41 this.nextHop = nextHop;
42 this.rt = rt;
43 this.label = label;
44 }
45
46 /**
47 * Constructor for initializing the evpn prefix.
48 *
49 * @param nextHop next hop
50 * @param label label
51 */
52 public BgpEvpnPrefix(Ip4Address nextHop, BgpEvpnLabel label) {
53 this.nextHop = nextHop;
54 this.label = label;
55 }
56
57 /**
58 * Get next hop address.
59 *
60 * @return next hop
61 */
62 public Ip4Address getNextHop() {
63 return nextHop;
64 }
65
66 /**
67 * Get the route target.
68 *
69 * @return route target
70 */
71 public RouteTarget getRouteTarget() {
72 return rt;
73 }
74
75 /**
76 * Get the label.
77 *
78 * @return label
79 */
80 public BgpEvpnLabel getLabel() {
81 return label;
82
83 }
84
85 /**
86 * Set the next hop address.
87 *
88 * @param nextHop next hop
89 */
90 public void setNetHop(Ip4Address nextHop) {
91 this.nextHop = nextHop;
92 }
93
94 /**
95 * Set the route target.
96 *
97 * @param rt route target
98 */
99 public void setRouteTarget(RouteTarget rt) {
100 this.rt = rt;
101 }
102
103 /**
104 * Set the label.
105 *
106 * @param label label.
107 */
108 public void setLabel(BgpEvpnLabel label) {
109 this.label = label;
110 }
111
112 @Override
113 public int hashCode() {
114 return Objects.hash(nextHop,
115 rt,
116 label);
117 }
118
119 @Override
120 public boolean equals(Object other) {
121 if (this == other) {
122 return true;
123 }
124
125 if (!(other instanceof BgpEvpnPrefix)) {
126 return false;
127 }
128
129 BgpEvpnPrefix that = (BgpEvpnPrefix) other;
130
131 return Objects.equals(nextHop, that.nextHop)
132 && Objects.equals(rt, that.rt)
133 && Objects.equals(label, that.label);
134 }
135
136 @Override
137 public String toString() {
138 return toStringHelper(this)
139 .add("next hop", nextHop)
140 .add("route target", rt)
141 .add("label", label)
142 .toString();
143 }
144}