blob: 5288db7dad16ea505449e39d9be30deda5d7a02e [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;
Mohammad Shahidaa7c1232017-08-09 11:13:15 +053018
19import java.util.List;
20import java.util.Objects;
21
22import static com.google.common.base.MoreObjects.toStringHelper;
23import static com.google.common.base.Preconditions.checkNotNull;
24
25/**
26 * Represents a evpn instance.
27 */
28public final class EvpnInstance {
29
30 private final RouteDistinguisher rd;
31 private final List<VpnRouteTarget> importRtList;
32 private final List<VpnRouteTarget> exportRtList;
33 private final EvpnInstanceName evpnName;
34
35 /**
36 * Constructor to initialize the parameters.
37 *
38 * @param rd route distinguisher
39 * @param importRtList import rotue targets
40 * @param exportRtList export rotue targets
41 * @param evpnName vpn instance name
42 */
43 private EvpnInstance(RouteDistinguisher rd,
44 List<VpnRouteTarget> importRtList,
45 List<VpnRouteTarget> exportRtList,
46 EvpnInstanceName evpnName) {
47 checkNotNull(rd);
48 //checkNotNull(rt);
49 checkNotNull(evpnName);
50 this.rd = rd;
51 this.importRtList = importRtList;
52 this.exportRtList = exportRtList;
53 this.evpnName = evpnName;
54 }
55
56 /**
57 * Creats the instance of EvpnInstance.
58 *
59 * @param rd route distinguisher
60 * @param importRtList import rotue targets
61 * @param exportRtList export rotue targets
62 * @param evpnName vpn instance name
63 * @return EvpnInstance
64 */
65 public static EvpnInstance evpnInstance(RouteDistinguisher rd,
66 List<VpnRouteTarget> importRtList,
67 List<VpnRouteTarget> exportRtList,
68 EvpnInstanceName evpnName) {
69 return new EvpnInstance(rd, importRtList, exportRtList, evpnName);
70 }
71
72 /**
73 * Getter of RouteDistinguisher.
74 *
75 * @return RouteDistinguisher
76 */
77 public RouteDistinguisher routeDistinguisher() {
78 return rd;
79 }
80
81 /**
82 * Returns the Route targets.
83 *
84 * @return RouteTarget List
85 */
86
87 public List<VpnRouteTarget> importRouteTarget() {
88 return importRtList;
89 }
90
91 /**
92 * Returns the Route targets.
93 *
94 * @return RouteTarget List
95 */
96 public List<VpnRouteTarget> exportRouteTarget() {
97 return exportRtList;
98 }
99
100 /**
101 * Getter of vpn instance name.
102 *
103 * @return evpnName
104 */
105 public EvpnInstanceName evpnName() {
106 return evpnName;
107 }
108
109 @Override
110 public int hashCode() {
111 return Objects.hash(rd, importRtList, exportRtList, evpnName);
112 }
113
114 @Override
115 public boolean equals(Object other) {
116 if (this == other) {
117 return true;
118 }
119
120 if (!(other instanceof EvpnInstance)) {
121 return false;
122 }
123
124 EvpnInstance that = (EvpnInstance) other;
125
126 return Objects.equals(this.evpnName, that.evpnName)
127 && Objects.equals(this.rd, that.rd)
128 && Objects.equals(this.importRtList, that.importRtList)
129 && Objects.equals(this.exportRtList, that.exportRtList);
130 }
131
132 @Override
133 public String toString() {
134 return toStringHelper(this).add("evpnName", this.evpnName)
135 .add("rd", this.rd).add("import rt", this.importRtList)
136 .add("export rt", this.exportRtList).toString();
137 }
138}