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