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