blob: c036a5f36ba739e904b7bd85aa9d33b936b27528 [file] [log] [blame]
Mohammad Shahid4c30ea32017-08-09 18:02:10 +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.evpnopenflow.rsc;
18
19import java.util.Objects;
20
21import static com.google.common.base.MoreObjects.toStringHelper;
22import static com.google.common.base.Preconditions.checkNotNull;
23import static org.onosproject.evpnopenflow.rsc.EvpnConstants.ID;
24import static org.onosproject.evpnopenflow.rsc.EvpnConstants.ID_CANNOT_BE_NULL;
25import static org.onosproject.evpnopenflow.rsc.EvpnConstants.VPN_INSTANCE_ID;
26import static org.onosproject.evpnopenflow.rsc.EvpnConstants.VPN_INSTANCE_ID_CANNOT_BE_NULL;
27
28/**
29 * Default implementation of VPN port.
30 */
31public class DefaultVpnPort implements VpnPort {
32
33 private final VpnPortId id;
34 private final VpnInstanceId vpnInstanceId;
35
36 /**
37 * creates vpn port object.
38 *
39 * @param id vpn port id
40 * @param vpnInstanceId vpn instance id
41 */
42 public DefaultVpnPort(VpnPortId id, VpnInstanceId vpnInstanceId) {
43 this.id = checkNotNull(id, ID_CANNOT_BE_NULL);
44 this.vpnInstanceId = checkNotNull(vpnInstanceId,
45 VPN_INSTANCE_ID_CANNOT_BE_NULL);
46 }
47
48 @Override
49 public VpnPortId id() {
50 return id;
51 }
52
53 @Override
54 public VpnInstanceId vpnInstanceId() {
55 return vpnInstanceId;
56 }
57
58 @Override
59 public int hashCode() {
60 return Objects.hash(id, vpnInstanceId);
61 }
62
63 @Override
64 public boolean equals(Object obj) {
65 if (this == obj) {
66 return true;
67 }
68 if (obj instanceof DefaultVpnPort) {
69 final DefaultVpnPort that = (DefaultVpnPort) obj;
70 return Objects.equals(this.id, that.id)
71 && Objects.equals(this.vpnInstanceId, that.vpnInstanceId);
72 }
73 return false;
74 }
75
76 @Override
77 public String toString() {
78 return toStringHelper(this).add(ID, id)
79 .add(VPN_INSTANCE_ID, vpnInstanceId).toString();
80 }
81}