blob: 2e4a59ec9d3622ca32329c1413b9cd97c7335421 [file] [log] [blame]
Hyunsun Moon699f46b2015-12-04 11:35:25 -08001/*
2 * Copyright 2015 Open Networking Laboratory
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 */
16package org.onosproject.cordvtn;
17
18import com.google.common.base.MoreObjects;
19import org.onlab.packet.IpAddress;
20import org.onlab.packet.IpPrefix;
21
22import java.util.Objects;
23
Hyunsun Moonbfc47d12015-12-07 14:06:28 -080024public final class CordService {
Hyunsun Moon699f46b2015-12-04 11:35:25 -080025
26 enum ServiceType {
27 PRIVATE,
28 PRIVATE_DIRECT,
29 PRIVATE_INDIRECT,
30 PUBLIC_DIRECT,
31 PUBLIC_INDIRECT
32 }
33
Hyunsun Moonbfc47d12015-12-07 14:06:28 -080034 private final CordServiceId id;
35 private final long segmentationId;
Hyunsun Moon699f46b2015-12-04 11:35:25 -080036 private final ServiceType serviceType;
37 private final IpPrefix serviceIpRange;
38 private final IpAddress serviceIp;
39
40 /**
41 * Default constructor.
42 *
Hyunsun Moonbfc47d12015-12-07 14:06:28 -080043 * @param id service id, which is identical to OpenStack network id
44 * @param segmentationId segmentation id, which is identical to VNI
Hyunsun Moon699f46b2015-12-04 11:35:25 -080045 * @param serviceType service type
46 * @param serviceIpRange service ip range
47 * @param serviceIp service ip
48 */
Hyunsun Moonbfc47d12015-12-07 14:06:28 -080049 public CordService(CordServiceId id, long segmentationId, ServiceType serviceType,
Hyunsun Moon699f46b2015-12-04 11:35:25 -080050 IpPrefix serviceIpRange, IpAddress serviceIp) {
Hyunsun Moonbfc47d12015-12-07 14:06:28 -080051 this.id = id;
52 this.segmentationId = segmentationId;
Hyunsun Moon699f46b2015-12-04 11:35:25 -080053 this.serviceType = serviceType;
54 this.serviceIpRange = serviceIpRange;
55 this.serviceIp = serviceIp;
56 }
57
58 /**
59 * Returns service ID.
60 *
61 * @return service id
62 */
Hyunsun Moonbfc47d12015-12-07 14:06:28 -080063 public CordServiceId id() {
64 return id;
Hyunsun Moon699f46b2015-12-04 11:35:25 -080065 }
66
67 /**
Hyunsun Moonbfc47d12015-12-07 14:06:28 -080068 * Returns segmentation ID of this service.
Hyunsun Moon699f46b2015-12-04 11:35:25 -080069 *
Hyunsun Moonbfc47d12015-12-07 14:06:28 -080070 * @return segmentation id
Hyunsun Moon699f46b2015-12-04 11:35:25 -080071 */
Hyunsun Moonbfc47d12015-12-07 14:06:28 -080072 public long segmentationId() {
73 return segmentationId;
Hyunsun Moon699f46b2015-12-04 11:35:25 -080074 }
75
76 /**
77 * Returns service type.
78 *
79 * @return service type
80 */
81 public ServiceType serviceType() {
82 return serviceType;
83 }
84
85 /**
86 * Returns service IP range.
87 *
88 * @return CIDR
89 */
90 public IpPrefix serviceIpRange() {
91 return serviceIpRange;
92 }
93
94 /**
95 * Returns service IP address.
96 *
97 * @return ip address
98 */
99 public IpAddress serviceIp() {
100 return serviceIp;
101 }
102
103 @Override
104 public int hashCode() {
Hyunsun Moonbfc47d12015-12-07 14:06:28 -0800105 return Objects.hash(id);
Hyunsun Moon699f46b2015-12-04 11:35:25 -0800106 }
107
108 @Override
109 public boolean equals(Object obj) {
110 if (this == obj) {
111 return true;
112 }
Hyunsun Moonbfc47d12015-12-07 14:06:28 -0800113 if (!(obj instanceof CordService)) {
Hyunsun Moon699f46b2015-12-04 11:35:25 -0800114 return false;
115 }
Hyunsun Moonbfc47d12015-12-07 14:06:28 -0800116 final CordService other = (CordService) obj;
117 return Objects.equals(this.id, other.id);
Hyunsun Moon699f46b2015-12-04 11:35:25 -0800118 }
119
120 @Override
121 public String toString() {
122 return MoreObjects.toStringHelper(this)
Hyunsun Moonbfc47d12015-12-07 14:06:28 -0800123 .add("id", id)
124 .add("segmentationId", segmentationId)
Hyunsun Moon699f46b2015-12-04 11:35:25 -0800125 .add("serviceType", serviceType)
126 .add("serviceIpRange", serviceIpRange)
127 .add("serviceIp", serviceIp)
128 .toString();
129 }
130}