blob: 2c31cccdd7fec65d5fe9236a8e46c5f92665d087 [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
24public final class Service {
25
26 enum ServiceType {
27 PRIVATE,
28 PRIVATE_DIRECT,
29 PRIVATE_INDIRECT,
30 PUBLIC_DIRECT,
31 PUBLIC_INDIRECT
32 }
33
34 private final ServiceId serviceId;
35 private final String networkId;
36 private final ServiceType serviceType;
37 private final IpPrefix serviceIpRange;
38 private final IpAddress serviceIp;
39
40 /**
41 * Default constructor.
42 *
43 * @param serviceId service id
44 * @param networkId OpenStack Neutron network id
45 * @param serviceType service type
46 * @param serviceIpRange service ip range
47 * @param serviceIp service ip
48 */
49 public Service(ServiceId serviceId, String networkId, ServiceType serviceType,
50 IpPrefix serviceIpRange, IpAddress serviceIp) {
51 this.serviceId = serviceId;
52 this.networkId = networkId;
53 this.serviceType = serviceType;
54 this.serviceIpRange = serviceIpRange;
55 this.serviceIp = serviceIp;
56 }
57
58 /**
59 * Returns service ID.
60 *
61 * @return service id
62 */
63 public ServiceId serviceId() {
64 return serviceId;
65 }
66
67 /**
68 * Returns OpenStack Neutron network ID of this service.
69 *
70 * @return network id
71 */
72 public String networkId() {
73 return networkId;
74 }
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() {
105 return Objects.hash(serviceId);
106 }
107
108 @Override
109 public boolean equals(Object obj) {
110 if (this == obj) {
111 return true;
112 }
113 if (!(obj instanceof Service)) {
114 return false;
115 }
116 final Service other = (Service) obj;
117 return Objects.equals(this.serviceId, other.serviceId);
118 }
119
120 @Override
121 public String toString() {
122 return MoreObjects.toStringHelper(this)
123 .add("serviceId", serviceId)
124 .add("networkId", networkId)
125 .add("serviceType", serviceType)
126 .add("serviceIpRange", serviceIpRange)
127 .add("serviceIp", serviceIp)
128 .toString();
129 }
130}