blob: ec33b9f0058b2b0bfbd4f3fc0fbe85a6d2534b58 [file] [log] [blame]
Hyunsun Moon4c396632016-05-13 04:17:53 -07001/*
2 * Copyright 2016-present 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.xosclient.api;
17
18import com.google.common.base.MoreObjects;
19import com.google.common.collect.Sets;
20import org.onlab.packet.IpAddress;
21import org.onlab.packet.IpPrefix;
Hyunsun Moon91ba41a2016-06-10 16:52:39 -070022import org.onosproject.xosclient.api.VtnServiceApi.NetworkType;
23import org.onosproject.xosclient.api.VtnServiceApi.ServiceType;
Hyunsun Moon4c396632016-05-13 04:17:53 -070024
25import java.util.Objects;
26import java.util.Set;
27
28import static com.google.common.base.Preconditions.checkNotNull;
29
30/**
31 * Representation of CORD VTN controlled network service.
32 */
33public final class VtnService {
34
Hyunsun Moon4c396632016-05-13 04:17:53 -070035 private final VtnServiceId id;
36 private final String name;
37 private final ServiceType serviceType;
38 private final NetworkType networkType;
39 private final long vni;
40 private final IpPrefix subnet;
41 private final IpAddress serviceIp;
42 private final Set<VtnServiceId> providerServices;
43 private final Set<VtnServiceId> tenantServices;
44
45 /**
46 * Creates a new VTN service with the specified entities.
47 *
48 * @param id service id
49 * @param name user friendly name
50 * @param serviceType service type
51 * @param networkType network type
52 * @param vni vni of this service network
53 * @param subnet service network subnet range
54 * @param serviceIp service ip for indirect service access
55 * @param providerServices provider services
56 * @param tenantServices tenant services
57 */
58 public VtnService(VtnServiceId id,
59 String name,
60 ServiceType serviceType,
61 NetworkType networkType,
62 long vni,
63 IpPrefix subnet,
64 IpAddress serviceIp,
65 Set<VtnServiceId> providerServices,
66 Set<VtnServiceId> tenantServices) {
67 this.id = checkNotNull(id);
68 this.name = name;
69 this.serviceType = serviceType;
70 this.networkType = networkType;
71 this.vni = vni;
72 this.subnet = checkNotNull(subnet);
73 this.serviceIp = checkNotNull(serviceIp);
74 this.providerServices = providerServices == null ? Sets.newHashSet() : providerServices;
75 this.tenantServices = tenantServices == null ? Sets.newHashSet() : tenantServices;
76 }
77
78 /**
79 * Returns service ID.
80 *
81 * @return service id
82 */
83 public VtnServiceId id() {
84 return id;
85 }
86
87 /**
88 * Returns service name.
89 *
90 * @return name
91 */
92 public String name() {
93 return name;
94 }
95
96 /**
97 * Returns service type.
98 *
99 * @return service type
100 */
101 public ServiceType serviceType() {
102 return serviceType;
103 }
104
105 /**
106 * Returns segmentation ID of this service.
107 *
108 * @return segmentation id
109 */
110 public long vni() {
111 return vni;
112 }
113
114 /**
115 * Returns network type.
116 *
117 * @return network type
118 */
119 public NetworkType networkType() {
120 return networkType;
121 }
122
123 /**
124 * Returns service IP range.
125 *
126 * @return subnet cidr
127 */
128 public IpPrefix subnet() {
129 return subnet;
130 }
131
132 /**
133 * Returns service IP address.
134 *
135 * @return ip address
136 */
137 public IpAddress serviceIp() {
138 return serviceIp;
139 }
140
141 /**
142 * Returns provider service IDs.
143 *
144 * @return list of provider service id
145 */
146 public Set<VtnServiceId> providerServices() {
147 return providerServices;
148 }
149
150 /**
151 * Returns tenant service IDs.
152 *
153 * @return list of tenant service id
154 */
155 public Set<VtnServiceId> tenantServices() {
156 return tenantServices;
157 }
158
159 @Override
160 public int hashCode() {
161 return Objects.hash(id);
162 }
163
164 @Override
165 public boolean equals(Object obj) {
166 if (this == obj) {
167 return true;
168 }
169 if (!(obj instanceof VtnService)) {
170 return false;
171 }
172 final VtnService other = (VtnService) obj;
173 return Objects.equals(this.id, other.id);
174 }
175
176 @Override
177 public String toString() {
178 return MoreObjects.toStringHelper(this)
179 .add("id", id)
180 .add("name", name)
181 .add("serviceType", serviceType)
182 .add("networkType", networkType)
183 .add("vni", vni)
184 .add("subnet", subnet)
185 .add("serviceIp", serviceIp)
186 .add("providerServices", providerServices)
187 .add("tenantServices", tenantServices)
188 .toString();
189 }
190}