Mohammad Shahid | 4c30ea3 | 2017-08-09 18:02:10 +0530 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package org.onosproject.evpnopenflow.rsc; |
| 18 | |
Ray Milkey | a95193c | 2017-08-10 15:35:36 -0700 | [diff] [blame] | 19 | import org.onosproject.evpnrouteservice.EvpnInstanceName; |
| 20 | import org.onosproject.evpnrouteservice.RouteDistinguisher; |
| 21 | import org.onosproject.evpnrouteservice.VpnRouteTarget; |
Mohammad Shahid | 4c30ea3 | 2017-08-09 18:02:10 +0530 | [diff] [blame] | 22 | |
| 23 | import java.util.Objects; |
| 24 | import java.util.Set; |
| 25 | |
| 26 | import static com.google.common.base.MoreObjects.toStringHelper; |
| 27 | import static com.google.common.base.Preconditions.checkNotNull; |
| 28 | import static org.onosproject.evpnopenflow.rsc.EvpnConstants.CONFIG_RT_CANNOT_BE_NULL; |
| 29 | import static org.onosproject.evpnopenflow.rsc.EvpnConstants.DESCRIPTION; |
| 30 | import static org.onosproject.evpnopenflow.rsc.EvpnConstants.DESCRIPTION_CANNOT_BE_NULL; |
| 31 | import static org.onosproject.evpnopenflow.rsc.EvpnConstants.EXPORT_RT_CANNOT_BE_NULL; |
| 32 | import static org.onosproject.evpnopenflow.rsc.EvpnConstants.ID; |
| 33 | import static org.onosproject.evpnopenflow.rsc.EvpnConstants.ID_CANNOT_BE_NULL; |
| 34 | import static org.onosproject.evpnopenflow.rsc.EvpnConstants.IMPORT_RT_CANNOT_BE_NULL; |
| 35 | import static org.onosproject.evpnopenflow.rsc.EvpnConstants.INSTANCE_NAME_CANNOT_BE_NULL; |
| 36 | import static org.onosproject.evpnopenflow.rsc.EvpnConstants.RD_CANNOT_BE_NULL; |
| 37 | import static org.onosproject.evpnopenflow.rsc.EvpnConstants.ROUTE_DISTINGUISHER; |
| 38 | import static org.onosproject.evpnopenflow.rsc.EvpnConstants.VPNINSTANCE_NAME; |
| 39 | |
| 40 | /** |
| 41 | * Default implementation of VPN instance. |
| 42 | */ |
| 43 | public class DefaultVpnInstance implements VpnInstance { |
| 44 | private final VpnInstanceId id; |
| 45 | private final String description; |
| 46 | private final EvpnInstanceName name; |
| 47 | private final RouteDistinguisher routeDistinguisher; |
| 48 | private final Set<VpnRouteTarget> exportRtSet; |
| 49 | private final Set<VpnRouteTarget> importRtSet; |
| 50 | private final Set<VpnRouteTarget> configRtSet; |
| 51 | |
| 52 | |
| 53 | /** |
| 54 | * creates vpn instance object. |
| 55 | * |
| 56 | * @param id vpn instance identifier |
| 57 | * @param instanceName the name of vpn instance |
| 58 | * @param description the description of vpn instance |
| 59 | * @param routeDistinguisher the routeDistinguisher of vpn instance |
| 60 | * @param exportRtSet the export route target information |
| 61 | * @param importRtSet the import route target information |
| 62 | * @param configRtSet the config route target information |
| 63 | */ |
| 64 | public DefaultVpnInstance(VpnInstanceId id, EvpnInstanceName instanceName, |
| 65 | String description, |
| 66 | RouteDistinguisher routeDistinguisher, |
| 67 | Set<VpnRouteTarget> exportRtSet, |
| 68 | Set<VpnRouteTarget> importRtSet, |
| 69 | Set<VpnRouteTarget> configRtSet) { |
| 70 | this.id = checkNotNull(id, ID_CANNOT_BE_NULL); |
| 71 | this.name = checkNotNull(instanceName, INSTANCE_NAME_CANNOT_BE_NULL); |
| 72 | this.description = checkNotNull(description, |
| 73 | DESCRIPTION_CANNOT_BE_NULL); |
| 74 | this.routeDistinguisher = checkNotNull(routeDistinguisher, |
| 75 | RD_CANNOT_BE_NULL); |
| 76 | this.exportRtSet = checkNotNull(exportRtSet, EXPORT_RT_CANNOT_BE_NULL); |
| 77 | this.importRtSet = checkNotNull(importRtSet, IMPORT_RT_CANNOT_BE_NULL); |
| 78 | this.configRtSet = checkNotNull(configRtSet, CONFIG_RT_CANNOT_BE_NULL); |
| 79 | } |
| 80 | |
| 81 | @Override |
| 82 | public VpnInstanceId id() { |
| 83 | return id; |
| 84 | } |
| 85 | |
| 86 | @Override |
| 87 | public String description() { |
| 88 | return description; |
| 89 | } |
| 90 | |
| 91 | @Override |
| 92 | public RouteDistinguisher routeDistinguisher() { |
| 93 | return routeDistinguisher; |
| 94 | } |
| 95 | |
| 96 | @Override |
| 97 | public EvpnInstanceName vpnInstanceName() { |
| 98 | return name; |
| 99 | } |
| 100 | |
| 101 | @Override |
| 102 | public Set<VpnRouteTarget> getExportRouteTargets() { |
| 103 | return exportRtSet; |
| 104 | } |
| 105 | |
| 106 | @Override |
| 107 | public Set<VpnRouteTarget> getImportRouteTargets() { |
| 108 | return importRtSet; |
| 109 | } |
| 110 | |
| 111 | @Override |
| 112 | public Set<VpnRouteTarget> getConfigRouteTargets() { |
| 113 | return configRtSet; |
| 114 | } |
| 115 | |
| 116 | @Override |
| 117 | public int hashCode() { |
| 118 | return Objects.hash(id, name, description, routeDistinguisher, |
| 119 | exportRtSet, importRtSet, configRtSet); |
| 120 | } |
| 121 | |
| 122 | @Override |
| 123 | public boolean equals(Object obj) { |
| 124 | if (this == obj) { |
| 125 | return true; |
| 126 | } |
| 127 | if (obj instanceof DefaultVpnInstance) { |
| 128 | final DefaultVpnInstance that = (DefaultVpnInstance) obj; |
| 129 | return Objects.equals(this.id, that.id) |
| 130 | && Objects.equals(this.name, that.name) |
| 131 | && Objects.equals(this.description, that.description) |
| 132 | && Objects.equals(this.routeDistinguisher, |
| 133 | that.routeDistinguisher) |
| 134 | && Objects.equals(this.exportRtSet, that.exportRtSet) |
| 135 | && Objects.equals(this.importRtSet, that.importRtSet) |
| 136 | && Objects.equals(this.configRtSet, that.configRtSet); |
| 137 | } |
| 138 | return false; |
| 139 | } |
| 140 | |
| 141 | @Override |
| 142 | public String toString() { |
| 143 | return toStringHelper(this) |
| 144 | .add(ID, id) |
| 145 | .add(DESCRIPTION, description) |
| 146 | .add(VPNINSTANCE_NAME, name) |
| 147 | .add(ROUTE_DISTINGUISHER, routeDistinguisher) |
| 148 | .add("exportRtSet", exportRtSet) |
| 149 | .add("importRtSet", importRtSet) |
| 150 | .add("configRtSet", configRtSet) |
| 151 | .toString(); |
| 152 | } |
| 153 | } |