blob: 84164b2142f639e4fe47897cbe5242cc6d3f2bcc [file] [log] [blame]
hongtao100c4222015-11-11 17:48:32 +08001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2015-present Open Networking Foundation
hongtao100c4222015-11-11 17:48:32 +08003 *
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;
19import static com.google.common.base.Preconditions.checkNotNull;
20
21import java.util.Objects;
22
23/**
24 * Representation of a Router interface.
25 */
26public final class RouterInterface {
27 private final SubnetId subnetId;
28 private final VirtualPortId portId;
29 private final RouterId routerId;
30 private final TenantId tenantId;
31
32 // Public construction is prohibited
33 private RouterInterface(SubnetId subnetId, VirtualPortId portId,
34 RouterId routerId, TenantId tenantId) {
35 this.subnetId = checkNotNull(subnetId, "subnetId cannot be null");
36 this.portId = checkNotNull(portId, "portId cannot be null");
37 this.routerId = checkNotNull(routerId, "routerId cannot be null");
38 this.tenantId = checkNotNull(tenantId, "tenantId cannot be null");
39 }
40
41 /**
42 * Creates router interface object.
43 *
44 * @param subnetId subnet identifier
45 * @param portId port identifier
46 * @param routerId router identifier
47 * @param tenantId tenant identifier
48 * @return RouterInterface
49 */
50 public static RouterInterface routerInterface(SubnetId subnetId,
51 VirtualPortId portId,
52 RouterId routerId,
53 TenantId tenantId) {
54 return new RouterInterface(subnetId, portId, routerId, tenantId);
55 }
56
57 /**
58 * Returns subnet identifier.
59 *
60 * @return subnetId the subnet identifier
61 */
62 public SubnetId subnetId() {
63 return subnetId;
64 }
65
66 /**
67 * Returns port identifier.
68 *
69 * @return portId the port identifier
70 */
71 public VirtualPortId portId() {
72 return portId;
73 }
74
75 /**
76 * Returns router identifier.
77 *
78 * @return routerId the router identifier
79 */
80 public RouterId routerId() {
81 return routerId;
82 }
83
84 /**
85 * Returns tenant identifier.
86 *
87 * @return tenantId the tenant identifier
88 */
89 public TenantId tenantId() {
90 return tenantId;
91 }
92
93 @Override
94 public int hashCode() {
95 return Objects.hash(subnetId, portId, routerId, tenantId);
96 }
97
98 @Override
99 public boolean equals(Object obj) {
100 if (this == obj) {
101 return true;
102 }
103 if (obj instanceof RouterInterface) {
104 final RouterInterface that = (RouterInterface) obj;
105 return Objects.equals(this.subnetId, that.subnetId)
106 && Objects.equals(this.portId, that.portId)
107 && Objects.equals(this.routerId, that.routerId)
108 && Objects.equals(this.tenantId, that.tenantId);
109 }
110 return false;
111 }
112
113 @Override
114 public String toString() {
115 return toStringHelper(this).add("subnetId", subnetId)
116 .add("portId", portId).add("routerId", routerId)
117 .add("tenantId", tenantId).toString();
118 }
119}