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 | |
| 19 | import org.onlab.packet.MacAddress; |
| 20 | import org.onosproject.net.DeviceId; |
| 21 | import org.onosproject.vtnrsc.AllowedAddressPair; |
| 22 | import org.onosproject.vtnrsc.BindingHostId; |
| 23 | import org.onosproject.vtnrsc.FixedIp; |
| 24 | import org.onosproject.vtnrsc.SecurityGroup; |
| 25 | import org.onosproject.vtnrsc.TenantId; |
| 26 | import org.onosproject.vtnrsc.TenantNetworkId; |
| 27 | |
| 28 | import java.util.Collection; |
| 29 | import java.util.Map; |
| 30 | import java.util.Objects; |
| 31 | import java.util.Set; |
| 32 | |
| 33 | import static com.google.common.base.MoreObjects.toStringHelper; |
| 34 | |
| 35 | /** |
| 36 | * Default implementation of Base port. |
| 37 | */ |
| 38 | public final class DefaultBasePort implements BasePort { |
| 39 | private final BasePortId id; |
| 40 | private final TenantNetworkId networkId; |
| 41 | private final Boolean adminStateUp; |
| 42 | private final String name; |
| 43 | private final String state; |
| 44 | private final MacAddress macAddress; |
| 45 | private final TenantId tenantId; |
| 46 | private final String deviceOwner; |
| 47 | private final DeviceId deviceId; |
| 48 | private final Set<FixedIp> fixedIps; |
| 49 | private final BindingHostId bindingHostId; |
| 50 | private final String bindingVnicType; |
| 51 | private final String bindingVifType; |
| 52 | private final String bindingVifDetails; |
| 53 | private final Set<AllowedAddressPair> allowedAddressPairs; |
| 54 | private final Set<SecurityGroup> securityGroups; |
| 55 | |
| 56 | /** |
| 57 | * Creates a BasePort object. |
| 58 | * |
| 59 | * @param id the base port identifier |
| 60 | * @param networkId the network identifier |
| 61 | * @param adminStateUp adminStateup true or false |
| 62 | * @param strMap the map of properties of base port |
| 63 | * @param state base port state |
| 64 | * @param macAddress the MAC address |
| 65 | * @param tenantId the tenant identifier |
| 66 | * @param deviceId the device identifier |
| 67 | * @param fixedIps set of fixed IP |
| 68 | * @param bindingHostId the binding host identifier |
| 69 | * @param allowedAddressPairs the collection of allowdeAddressPairs |
| 70 | * @param securityGroups the collection of securityGroups |
| 71 | */ |
| 72 | public DefaultBasePort(BasePortId id, |
| 73 | TenantNetworkId networkId, |
| 74 | Boolean adminStateUp, |
| 75 | Map<String, String> strMap, |
| 76 | String state, |
| 77 | MacAddress macAddress, |
| 78 | TenantId tenantId, |
| 79 | DeviceId deviceId, |
| 80 | Set<FixedIp> fixedIps, |
| 81 | BindingHostId bindingHostId, |
| 82 | Set<AllowedAddressPair> allowedAddressPairs, |
| 83 | Set<SecurityGroup> securityGroups) { |
| 84 | this.id = id; |
| 85 | this.networkId = networkId; |
| 86 | this.adminStateUp = adminStateUp; |
| 87 | this.name = strMap.get("name"); |
| 88 | this.state = state; |
| 89 | this.macAddress = macAddress; |
| 90 | this.tenantId = tenantId; |
| 91 | this.deviceOwner = strMap.get("deviceOwner"); |
| 92 | this.deviceId = deviceId; |
| 93 | this.fixedIps = fixedIps; |
| 94 | this.bindingHostId = bindingHostId; |
| 95 | this.bindingVnicType = strMap.get("bindingVnicType"); |
| 96 | this.bindingVifType = strMap.get("bindingVifType"); |
| 97 | this.bindingVifDetails = strMap.get("bindingVifDetails"); |
| 98 | this.allowedAddressPairs = allowedAddressPairs; |
| 99 | this.securityGroups = securityGroups; |
| 100 | } |
| 101 | |
| 102 | @Override |
| 103 | public BasePortId portId() { |
| 104 | return id; |
| 105 | } |
| 106 | |
| 107 | @Override |
| 108 | public TenantNetworkId networkId() { |
| 109 | return networkId; |
| 110 | } |
| 111 | |
| 112 | @Override |
| 113 | public String name() { |
| 114 | return name; |
| 115 | } |
| 116 | |
| 117 | @Override |
| 118 | public boolean adminStateUp() { |
| 119 | return adminStateUp; |
| 120 | } |
| 121 | |
| 122 | @Override |
| 123 | public String state() { |
| 124 | return state; |
| 125 | } |
| 126 | |
| 127 | @Override |
| 128 | public MacAddress macAddress() { |
| 129 | return macAddress; |
| 130 | } |
| 131 | |
| 132 | @Override |
| 133 | public TenantId tenantId() { |
| 134 | return tenantId; |
| 135 | } |
| 136 | |
| 137 | @Override |
| 138 | public DeviceId deviceId() { |
| 139 | return deviceId; |
| 140 | } |
| 141 | |
| 142 | @Override |
| 143 | public String deviceOwner() { |
| 144 | return deviceOwner; |
| 145 | } |
| 146 | |
| 147 | @Override |
| 148 | public Collection<AllowedAddressPair> allowedAddressPairs() { |
| 149 | return allowedAddressPairs; |
| 150 | } |
| 151 | |
| 152 | @Override |
| 153 | public Set<FixedIp> fixedIps() { |
| 154 | return fixedIps; |
| 155 | } |
| 156 | |
| 157 | @Override |
| 158 | public BindingHostId bindingHostId() { |
| 159 | return bindingHostId; |
| 160 | } |
| 161 | |
| 162 | @Override |
| 163 | public String bindingVnicType() { |
| 164 | return bindingVifType; |
| 165 | } |
| 166 | |
| 167 | @Override |
| 168 | public String bindingVifType() { |
| 169 | return bindingVifType; |
| 170 | } |
| 171 | |
| 172 | @Override |
| 173 | public String bindingVifDetails() { |
| 174 | return bindingVifDetails; |
| 175 | } |
| 176 | |
| 177 | @Override |
| 178 | public Collection<SecurityGroup> securityGroups() { |
| 179 | return securityGroups; |
| 180 | } |
| 181 | |
| 182 | @Override |
| 183 | public int hashCode() { |
| 184 | return Objects.hash(id, networkId, adminStateUp, name, state, |
| 185 | macAddress, tenantId, deviceId, deviceOwner, |
| 186 | allowedAddressPairs, fixedIps, bindingHostId, |
| 187 | bindingVnicType, bindingVifType, bindingVifDetails, |
| 188 | securityGroups); |
| 189 | } |
| 190 | |
| 191 | @Override |
| 192 | public boolean equals(Object obj) { |
| 193 | if (this == obj) { |
| 194 | return true; |
| 195 | } |
| 196 | if (obj instanceof DefaultBasePort) { |
| 197 | final DefaultBasePort that = (DefaultBasePort) obj; |
| 198 | return Objects.equals(this.id, that.id) |
| 199 | && Objects.equals(this.networkId, that.networkId) |
| 200 | && Objects.equals(this.adminStateUp, that.adminStateUp) |
| 201 | && Objects.equals(this.state, that.state) |
| 202 | && Objects.equals(this.name, that.name) |
| 203 | && Objects.equals(this.tenantId, that.tenantId) |
| 204 | && Objects.equals(this.macAddress, that.macAddress) |
| 205 | && Objects.equals(this.deviceId, that.deviceId) |
| 206 | && Objects.equals(this.deviceOwner, that.deviceOwner) |
| 207 | && Objects.equals(this.allowedAddressPairs, |
| 208 | that.allowedAddressPairs) |
| 209 | && Objects.equals(this.fixedIps, that.fixedIps) |
| 210 | && Objects.equals(this.bindingHostId, that.bindingHostId) |
| 211 | && Objects.equals(this.bindingVifDetails, |
| 212 | that.bindingVifDetails) |
| 213 | && Objects.equals(this.bindingVifType, that.bindingVifType) |
| 214 | && Objects.equals(this.bindingVnicType, |
| 215 | that.bindingVnicType) |
| 216 | && Objects.equals(this.securityGroups, that.securityGroups); |
| 217 | } |
| 218 | return false; |
| 219 | } |
| 220 | |
| 221 | @Override |
| 222 | public String toString() { |
| 223 | return toStringHelper(this).add("id", id).add("network_id", networkId) |
| 224 | .add("adminStateUp", adminStateUp).add("state", state) |
| 225 | .add("name", name).add("state", state) |
| 226 | .add("macAddress", macAddress).add("tenantId", tenantId) |
| 227 | .add("deviced", deviceId).add("deviceOwner", deviceOwner) |
| 228 | .add("allowedAddressPairs", allowedAddressPairs) |
| 229 | .add("fixedIp", fixedIps).add("bindingHostId", bindingHostId) |
| 230 | .add("bindingVnicType", bindingVnicType) |
| 231 | .add("bindingVifDetails", bindingVifDetails) |
| 232 | .add("bindingVifType", bindingVifType) |
| 233 | .add("securityGroups", securityGroups).toString(); |
| 234 | } |
| 235 | |
| 236 | } |