Changed to use XOS client to get service and port information
XOS client still gets these information from OpenStack temporarily until XOS provides these APIs Change-Id: I1ef9302f719a18a7377221f63b84431c2cdface8
Showing
18 changed files
with
417 additions
and
375 deletions
... | @@ -6,13 +6,9 @@ COMPILE_DEPS = [ | ... | @@ -6,13 +6,9 @@ COMPILE_DEPS = [ |
6 | '//lib:org.apache.karaf.shell.console', | 6 | '//lib:org.apache.karaf.shell.console', |
7 | '//lib:javax.ws.rs-api', | 7 | '//lib:javax.ws.rs-api', |
8 | '//lib:jsch', | 8 | '//lib:jsch', |
9 | - '//lib:openstack4j-core', | ||
10 | - '//lib:openstack4j-http-connector', | ||
11 | - '//lib:openstack4j-httpclient', | ||
12 | '//utils/rest:onlab-rest', | 9 | '//utils/rest:onlab-rest', |
13 | '//cli:onos-cli', | 10 | '//cli:onos-cli', |
14 | '//core/store/serializers:onos-core-serializers', | 11 | '//core/store/serializers:onos-core-serializers', |
15 | - '//apps/openstackinterface/api:onos-apps-openstackinterface-api', | ||
16 | '//apps/dhcp/api:onos-apps-dhcp-api', | 12 | '//apps/dhcp/api:onos-apps-dhcp-api', |
17 | '//apps/xosclient:onos-apps-xosclient', | 13 | '//apps/xosclient:onos-apps-xosclient', |
18 | '//protocols/ovsdb/api:onos-protocols-ovsdb-api', | 14 | '//protocols/ovsdb/api:onos-protocols-ovsdb-api', |
... | @@ -20,11 +16,7 @@ COMPILE_DEPS = [ | ... | @@ -20,11 +16,7 @@ COMPILE_DEPS = [ |
20 | ] | 16 | ] |
21 | 17 | ||
22 | BUNDLES = [ | 18 | BUNDLES = [ |
23 | - '//apps/openstackinterface/api:onos-apps-openstackinterface-api', | ||
24 | '//apps/cordvtn:onos-apps-cordvtn', | 19 | '//apps/cordvtn:onos-apps-cordvtn', |
25 | - '//lib:openstack4j-core', | ||
26 | - '//lib:openstack4j-http-connector', | ||
27 | - '//lib:openstack4j-httpclient', | ||
28 | ] | 20 | ] |
29 | 21 | ||
30 | EXCLUDED_BUNDLES = [ | 22 | EXCLUDED_BUNDLES = [ |
... | @@ -43,5 +35,5 @@ onos_app ( | ... | @@ -43,5 +35,5 @@ onos_app ( |
43 | included_bundles = BUNDLES, | 35 | included_bundles = BUNDLES, |
44 | excluded_bundles = EXCLUDED_BUNDLES, | 36 | excluded_bundles = EXCLUDED_BUNDLES, |
45 | description = 'APIs for interacting with the CORD VTN application.', | 37 | description = 'APIs for interacting with the CORD VTN application.', |
46 | - required_apps = [ 'org.onosproject.xosclient', 'org.onosproject.dhcp', 'org.onosproject.ovsdb', 'org.onosproject.openstackinterface' ], | 38 | + required_apps = [ 'org.onosproject.xosclient', 'org.onosproject.dhcp', 'org.onosproject.ovsdb' ], |
47 | ) | 39 | ) | ... | ... |
... | @@ -112,21 +112,6 @@ | ... | @@ -112,21 +112,6 @@ |
112 | <artifactId>jsch</artifactId> | 112 | <artifactId>jsch</artifactId> |
113 | <version>0.1.53</version> | 113 | <version>0.1.53</version> |
114 | </dependency> | 114 | </dependency> |
115 | - <dependency> | ||
116 | - <groupId>org.pacesys</groupId> | ||
117 | - <artifactId>openstack4j-core</artifactId> | ||
118 | - <version>2.11</version> | ||
119 | - </dependency> | ||
120 | - <dependency> | ||
121 | - <groupId>org.pacesys.openstack4j.connectors</groupId> | ||
122 | - <artifactId>openstack4j-http-connector</artifactId> | ||
123 | - <version>2.11</version> | ||
124 | - </dependency> | ||
125 | - <dependency> | ||
126 | - <groupId>org.pacesys.openstack4j.connectors</groupId> | ||
127 | - <artifactId>openstack4j-httpclient</artifactId> | ||
128 | - <version>2.11</version> | ||
129 | - </dependency> | ||
130 | </dependencies> | 115 | </dependencies> |
131 | 116 | ||
132 | <build> | 117 | <build> |
... | @@ -146,15 +131,8 @@ | ... | @@ -146,15 +131,8 @@ |
146 | ${project.groupId}.${project.artifactId} | 131 | ${project.groupId}.${project.artifactId} |
147 | </Bundle-SymbolicName> | 132 | </Bundle-SymbolicName> |
148 | <Import-Package> | 133 | <Import-Package> |
149 | - !org.apache.http.*, | ||
150 | - !com.fasterxml.jackson.dataformat.*, | ||
151 | *,org.glassfish.jersey.servlet | 134 | *,org.glassfish.jersey.servlet |
152 | </Import-Package> | 135 | </Import-Package> |
153 | - <Embed-Dependency> | ||
154 | - openstack4j-core, | ||
155 | - openstack4j-http-connector, | ||
156 | - openstack4j-httpclient | ||
157 | - </Embed-Dependency> | ||
158 | <Web-ContextPath>${web.context}</Web-ContextPath> | 136 | <Web-ContextPath>${web.context}</Web-ContextPath> |
159 | </instructions> | 137 | </instructions> |
160 | </configuration> | 138 | </configuration> | ... | ... |
1 | -/* | ||
2 | - * Copyright 2015-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 | - */ | ||
16 | -package org.onosproject.cordvtn.api; | ||
17 | - | ||
18 | -import com.google.common.base.MoreObjects; | ||
19 | -import org.onlab.packet.IpAddress; | ||
20 | -import org.onlab.packet.IpPrefix; | ||
21 | -import org.onosproject.net.Host; | ||
22 | -import org.openstack4j.model.network.Network; | ||
23 | -import org.openstack4j.model.network.Subnet; | ||
24 | - | ||
25 | -import java.util.Map; | ||
26 | -import java.util.Objects; | ||
27 | -import java.util.Set; | ||
28 | - | ||
29 | -import static com.google.common.base.Preconditions.checkNotNull; | ||
30 | - | ||
31 | -public final class CordService { | ||
32 | - | ||
33 | - public enum ServiceType { | ||
34 | - PRIVATE, | ||
35 | - PUBLIC, | ||
36 | - MANAGEMENT | ||
37 | - } | ||
38 | - | ||
39 | - private final CordServiceId id; | ||
40 | - private final long segmentationId; | ||
41 | - private final ServiceType serviceType; | ||
42 | - private final IpPrefix serviceIpRange; | ||
43 | - private final IpAddress serviceIp; | ||
44 | - private final Map<Host, IpAddress> hosts; | ||
45 | - private final Set<CordServiceId> tenantServices; | ||
46 | - private final Set<CordServiceId> providerServices; | ||
47 | - | ||
48 | - /** | ||
49 | - * Default constructor. | ||
50 | - * | ||
51 | - * @param osNet OpenStack network | ||
52 | - * @param osSubnet OpenStack subnet | ||
53 | - * @param hosts host and tunnel ip map | ||
54 | - * @param tenantServices list of tenant service ids | ||
55 | - * @param providerServices list of provider service ids | ||
56 | - */ | ||
57 | - public CordService(Network osNet, Subnet osSubnet, | ||
58 | - Map<Host, IpAddress> hosts, Set<CordServiceId> tenantServices, | ||
59 | - Set<CordServiceId> providerServices) { | ||
60 | - this.id = CordServiceId.of(osNet.getId()); | ||
61 | - this.segmentationId = Long.parseLong(osNet.getProviderSegID()); | ||
62 | - this.serviceType = getServiceType(osNet.getName()); | ||
63 | - this.serviceIpRange = IpPrefix.valueOf(osSubnet.getCidr()); | ||
64 | - this.serviceIp = IpAddress.valueOf(osSubnet.getGateway()); | ||
65 | - this.hosts = hosts; | ||
66 | - this.tenantServices = tenantServices; | ||
67 | - this.providerServices = providerServices; | ||
68 | - } | ||
69 | - | ||
70 | - /** | ||
71 | - * Returns service ID. | ||
72 | - * | ||
73 | - * @return service id | ||
74 | - */ | ||
75 | - public CordServiceId id() { | ||
76 | - return id; | ||
77 | - } | ||
78 | - | ||
79 | - /** | ||
80 | - * Returns segmentation ID of this service. | ||
81 | - * | ||
82 | - * @return segmentation id | ||
83 | - */ | ||
84 | - public long segmentationId() { | ||
85 | - return segmentationId; | ||
86 | - } | ||
87 | - | ||
88 | - /** | ||
89 | - * Returns service type. | ||
90 | - * | ||
91 | - * @return service type | ||
92 | - */ | ||
93 | - public ServiceType serviceType() { | ||
94 | - return serviceType; | ||
95 | - } | ||
96 | - | ||
97 | - /** | ||
98 | - * Returns service IP range. | ||
99 | - * | ||
100 | - * @return CIDR | ||
101 | - */ | ||
102 | - public IpPrefix serviceIpRange() { | ||
103 | - return serviceIpRange; | ||
104 | - } | ||
105 | - | ||
106 | - /** | ||
107 | - * Returns service IP address. | ||
108 | - * | ||
109 | - * @return ip address | ||
110 | - */ | ||
111 | - public IpAddress serviceIp() { | ||
112 | - return serviceIp; | ||
113 | - } | ||
114 | - | ||
115 | - /** | ||
116 | - * Returns hosts associated with this service. | ||
117 | - * | ||
118 | - * @return list of hosts | ||
119 | - */ | ||
120 | - public Map<Host, IpAddress> hosts() { | ||
121 | - return hosts; | ||
122 | - } | ||
123 | - | ||
124 | - /** | ||
125 | - * Returns tenant service IDs. | ||
126 | - * | ||
127 | - * @return list of tenant service id | ||
128 | - */ | ||
129 | - public Set<CordServiceId> tenantServices() { | ||
130 | - return tenantServices; | ||
131 | - } | ||
132 | - | ||
133 | - /** | ||
134 | - * Returns provider service IDs. | ||
135 | - * | ||
136 | - * @return list of provider service id | ||
137 | - */ | ||
138 | - public Set<CordServiceId> providerServices() { | ||
139 | - return providerServices; | ||
140 | - } | ||
141 | - | ||
142 | - @Override | ||
143 | - public int hashCode() { | ||
144 | - return Objects.hash(id); | ||
145 | - } | ||
146 | - | ||
147 | - @Override | ||
148 | - public boolean equals(Object obj) { | ||
149 | - if (this == obj) { | ||
150 | - return true; | ||
151 | - } | ||
152 | - if (!(obj instanceof CordService)) { | ||
153 | - return false; | ||
154 | - } | ||
155 | - final CordService other = (CordService) obj; | ||
156 | - return Objects.equals(this.id, other.id); | ||
157 | - } | ||
158 | - | ||
159 | - @Override | ||
160 | - public String toString() { | ||
161 | - return MoreObjects.toStringHelper(this) | ||
162 | - .add("id", id) | ||
163 | - .add("segmentationId", segmentationId) | ||
164 | - .add("serviceType", serviceType) | ||
165 | - .add("serviceIpRange", serviceIpRange) | ||
166 | - .add("serviceIp", serviceIp) | ||
167 | - .add("tenantServices", tenantServices) | ||
168 | - .add("providerServices", providerServices) | ||
169 | - .toString(); | ||
170 | - } | ||
171 | - | ||
172 | - /** | ||
173 | - * Returns network type from network name. | ||
174 | - * It assumes that network name contains network type. | ||
175 | - * | ||
176 | - * @param netName network name | ||
177 | - * @return network type, or PRIVATE if it doesn't match any type | ||
178 | - */ | ||
179 | - private ServiceType getServiceType(String netName) { | ||
180 | - checkNotNull(netName); | ||
181 | - | ||
182 | - String name = netName.toUpperCase(); | ||
183 | - if (name.contains(ServiceType.PUBLIC.toString())) { | ||
184 | - return ServiceType.PUBLIC; | ||
185 | - } else if (name.contains(ServiceType.MANAGEMENT.toString())) { | ||
186 | - return ServiceType.MANAGEMENT; | ||
187 | - } else { | ||
188 | - return ServiceType.PRIVATE; | ||
189 | - } | ||
190 | - } | ||
191 | -} |
1 | -/* | ||
2 | - * Copyright 2015-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 | - */ | ||
16 | -package org.onosproject.cordvtn.api; | ||
17 | - | ||
18 | -import org.onlab.util.Identifier; | ||
19 | - | ||
20 | -import static com.google.common.base.Preconditions.checkNotNull; | ||
21 | - | ||
22 | -/** | ||
23 | - * Representation of service identifier. | ||
24 | - */ | ||
25 | -public final class CordServiceId extends Identifier<String> { | ||
26 | - /** | ||
27 | - * Default constructor. | ||
28 | - * | ||
29 | - * @param id service identifier | ||
30 | - */ | ||
31 | - private CordServiceId(String id) { | ||
32 | - super(id); | ||
33 | - } | ||
34 | - | ||
35 | - /** | ||
36 | - * Returns the CordServiceId with value. | ||
37 | - * | ||
38 | - * @param id service id | ||
39 | - * @return CordServiceId | ||
40 | - */ | ||
41 | - public static CordServiceId of(String id) { | ||
42 | - checkNotNull(id); | ||
43 | - return new CordServiceId(id); | ||
44 | - } | ||
45 | -} |
... | @@ -25,6 +25,7 @@ import org.onlab.packet.TpPort; | ... | @@ -25,6 +25,7 @@ import org.onlab.packet.TpPort; |
25 | import org.onosproject.core.ApplicationId; | 25 | import org.onosproject.core.ApplicationId; |
26 | import org.onosproject.net.DeviceId; | 26 | import org.onosproject.net.DeviceId; |
27 | import org.onosproject.net.config.Config; | 27 | import org.onosproject.net.config.Config; |
28 | +import org.onosproject.xosclient.api.OpenStackAccess; | ||
28 | import org.onosproject.xosclient.api.XosAccess; | 29 | import org.onosproject.xosclient.api.XosAccess; |
29 | import org.slf4j.Logger; | 30 | import org.slf4j.Logger; |
30 | 31 | ||
... | @@ -209,9 +210,9 @@ public class CordVtnConfig extends Config<ApplicationId> { | ... | @@ -209,9 +210,9 @@ public class CordVtnConfig extends Config<ApplicationId> { |
209 | /** | 210 | /** |
210 | * Returns OpenStack API access information. | 211 | * Returns OpenStack API access information. |
211 | * | 212 | * |
212 | - * @return openstack config | 213 | + * @return openstack access |
213 | */ | 214 | */ |
214 | - public OpenStackConfig openstackConfig() { | 215 | + public OpenStackAccess openstackAccess() { |
215 | JsonNode jsonNode = object.get(OPENSTACK); | 216 | JsonNode jsonNode = object.get(OPENSTACK); |
216 | if (jsonNode == null) { | 217 | if (jsonNode == null) { |
217 | log.error("Failed to get OpenStack configurations"); | 218 | log.error("Failed to get OpenStack configurations"); |
... | @@ -219,7 +220,7 @@ public class CordVtnConfig extends Config<ApplicationId> { | ... | @@ -219,7 +220,7 @@ public class CordVtnConfig extends Config<ApplicationId> { |
219 | } | 220 | } |
220 | 221 | ||
221 | try { | 222 | try { |
222 | - return new OpenStackConfig( | 223 | + return new OpenStackAccess( |
223 | jsonNode.path(ENDPOINT).asText(), | 224 | jsonNode.path(ENDPOINT).asText(), |
224 | jsonNode.path(TENANT).asText(), | 225 | jsonNode.path(TENANT).asText(), |
225 | jsonNode.path(USER).asText(), | 226 | jsonNode.path(USER).asText(), |
... | @@ -229,66 +230,4 @@ public class CordVtnConfig extends Config<ApplicationId> { | ... | @@ -229,66 +230,4 @@ public class CordVtnConfig extends Config<ApplicationId> { |
229 | return null; | 230 | return null; |
230 | } | 231 | } |
231 | } | 232 | } |
232 | - | ||
233 | - /** | ||
234 | - * Configuration for OpenStack API access. | ||
235 | - */ | ||
236 | - public static class OpenStackConfig { | ||
237 | - | ||
238 | - private final String endpoint; | ||
239 | - private final String tenant; | ||
240 | - private final String user; | ||
241 | - private final String password; | ||
242 | - | ||
243 | - /** | ||
244 | - * Default constructor. | ||
245 | - * | ||
246 | - * @param endpoint Keystone endpoint | ||
247 | - * @param tenant tenant name | ||
248 | - * @param user user name | ||
249 | - * @param password passwowrd | ||
250 | - */ | ||
251 | - public OpenStackConfig(String endpoint, String tenant, String user, String password) { | ||
252 | - this.endpoint = endpoint; | ||
253 | - this.tenant = tenant; | ||
254 | - this.user = user; | ||
255 | - this.password = password; | ||
256 | - } | ||
257 | - | ||
258 | - /** | ||
259 | - * Returns OpenStack API endpoint. | ||
260 | - * | ||
261 | - * @return endpoint | ||
262 | - */ | ||
263 | - public String endpoint() { | ||
264 | - return this.endpoint; | ||
265 | - } | ||
266 | - | ||
267 | - /** | ||
268 | - * Returns OpenStack tenant name. | ||
269 | - * | ||
270 | - * @return tenant name | ||
271 | - */ | ||
272 | - public String tenant() { | ||
273 | - return this.tenant; | ||
274 | - } | ||
275 | - | ||
276 | - /** | ||
277 | - * Returns OpenStack user. | ||
278 | - * | ||
279 | - * @return user name | ||
280 | - */ | ||
281 | - public String user() { | ||
282 | - return this.user; | ||
283 | - } | ||
284 | - | ||
285 | - /** | ||
286 | - * Returns OpenStack password for the user. | ||
287 | - * | ||
288 | - * @return password | ||
289 | - */ | ||
290 | - public String password() { | ||
291 | - return this.password; | ||
292 | - } | ||
293 | - } | ||
294 | } | 233 | } | ... | ... |
... | @@ -19,6 +19,7 @@ import org.onlab.packet.IpAddress; | ... | @@ -19,6 +19,7 @@ import org.onlab.packet.IpAddress; |
19 | import org.onlab.packet.MacAddress; | 19 | import org.onlab.packet.MacAddress; |
20 | import org.onosproject.net.ConnectPoint; | 20 | import org.onosproject.net.ConnectPoint; |
21 | import org.onosproject.net.HostId; | 21 | import org.onosproject.net.HostId; |
22 | +import org.onosproject.xosclient.api.VtnServiceId; | ||
22 | 23 | ||
23 | import java.util.Map; | 24 | import java.util.Map; |
24 | 25 | ||
... | @@ -51,8 +52,7 @@ public interface CordVtnService { | ... | @@ -51,8 +52,7 @@ public interface CordVtnService { |
51 | * @param pServiceId id of the service which provide dependency | 52 | * @param pServiceId id of the service which provide dependency |
52 | * @param isBidirectional true to enable bidirectional connectivity between two services | 53 | * @param isBidirectional true to enable bidirectional connectivity between two services |
53 | */ | 54 | */ |
54 | - void createServiceDependency(CordServiceId tServiceId, | 55 | + void createServiceDependency(VtnServiceId tServiceId, VtnServiceId pServiceId, |
55 | - CordServiceId pServiceId, | ||
56 | boolean isBidirectional); | 56 | boolean isBidirectional); |
57 | 57 | ||
58 | /** | 58 | /** |
... | @@ -61,7 +61,7 @@ public interface CordVtnService { | ... | @@ -61,7 +61,7 @@ public interface CordVtnService { |
61 | * @param tServiceId id of the service which has a dependency | 61 | * @param tServiceId id of the service which has a dependency |
62 | * @param pServiceId id of the service which provide dependency | 62 | * @param pServiceId id of the service which provide dependency |
63 | */ | 63 | */ |
64 | - void removeServiceDependency(CordServiceId tServiceId, CordServiceId pServiceId); | 64 | + void removeServiceDependency(VtnServiceId tServiceId, VtnServiceId pServiceId); |
65 | 65 | ||
66 | /** | 66 | /** |
67 | * Updates virtual service gateways. | 67 | * Updates virtual service gateways. | ... | ... |
This diff is collapsed. Click to expand it.
... | @@ -237,6 +237,7 @@ public class CordVtnNodeManager { | ... | @@ -237,6 +237,7 @@ public class CordVtnNodeManager { |
237 | ruleInstaller = new CordVtnRuleInstaller(appId, flowRuleService, | 237 | ruleInstaller = new CordVtnRuleInstaller(appId, flowRuleService, |
238 | deviceService, | 238 | deviceService, |
239 | groupService, | 239 | groupService, |
240 | + hostService, | ||
240 | configRegistry, | 241 | configRegistry, |
241 | DEFAULT_TUNNEL); | 242 | DEFAULT_TUNNEL); |
242 | 243 | ... | ... |
... | @@ -28,8 +28,6 @@ import org.onlab.packet.MacAddress; | ... | @@ -28,8 +28,6 @@ import org.onlab.packet.MacAddress; |
28 | import org.onlab.packet.TpPort; | 28 | import org.onlab.packet.TpPort; |
29 | import org.onlab.packet.VlanId; | 29 | import org.onlab.packet.VlanId; |
30 | import org.onlab.util.ItemNotFoundException; | 30 | import org.onlab.util.ItemNotFoundException; |
31 | -import org.onosproject.cordvtn.api.CordService; | ||
32 | -import org.onosproject.cordvtn.api.CordServiceId; | ||
33 | import org.onosproject.cordvtn.api.CordVtnConfig; | 31 | import org.onosproject.cordvtn.api.CordVtnConfig; |
34 | import org.onosproject.cordvtn.api.CordVtnNode; | 32 | import org.onosproject.cordvtn.api.CordVtnNode; |
35 | import org.onosproject.core.ApplicationId; | 33 | import org.onosproject.core.ApplicationId; |
... | @@ -68,6 +66,9 @@ import org.onosproject.net.group.GroupBuckets; | ... | @@ -68,6 +66,9 @@ import org.onosproject.net.group.GroupBuckets; |
68 | import org.onosproject.net.group.GroupDescription; | 66 | import org.onosproject.net.group.GroupDescription; |
69 | import org.onosproject.net.group.GroupKey; | 67 | import org.onosproject.net.group.GroupKey; |
70 | import org.onosproject.net.group.GroupService; | 68 | import org.onosproject.net.group.GroupService; |
69 | +import org.onosproject.net.host.HostService; | ||
70 | +import org.onosproject.xosclient.api.VtnService; | ||
71 | +import org.onosproject.xosclient.api.VtnServiceId; | ||
71 | import org.slf4j.Logger; | 72 | import org.slf4j.Logger; |
72 | 73 | ||
73 | import java.util.ArrayList; | 74 | import java.util.ArrayList; |
... | @@ -76,6 +77,7 @@ import java.util.Map; | ... | @@ -76,6 +77,7 @@ import java.util.Map; |
76 | import java.util.Objects; | 77 | import java.util.Objects; |
77 | import java.util.Set; | 78 | import java.util.Set; |
78 | import java.util.stream.Collectors; | 79 | import java.util.stream.Collectors; |
80 | +import java.util.stream.StreamSupport; | ||
79 | 81 | ||
80 | import static com.google.common.base.Preconditions.checkNotNull; | 82 | import static com.google.common.base.Preconditions.checkNotNull; |
81 | import static org.onosproject.net.flow.criteria.Criterion.Type.IPV4_DST; | 83 | import static org.onosproject.net.flow.criteria.Criterion.Type.IPV4_DST; |
... | @@ -112,11 +114,13 @@ public class CordVtnRuleInstaller { | ... | @@ -112,11 +114,13 @@ public class CordVtnRuleInstaller { |
112 | private static final String DATA_PLANE_INTF = "dataPlaneIntf"; | 114 | private static final String DATA_PLANE_INTF = "dataPlaneIntf"; |
113 | private static final String DATA_PLANE_IP = "dataPlaneIp"; | 115 | private static final String DATA_PLANE_IP = "dataPlaneIp"; |
114 | private static final String S_TAG = "stag"; | 116 | private static final String S_TAG = "stag"; |
117 | + private static final String SERVICE_ID = "serviceId"; | ||
115 | 118 | ||
116 | private final ApplicationId appId; | 119 | private final ApplicationId appId; |
117 | private final FlowRuleService flowRuleService; | 120 | private final FlowRuleService flowRuleService; |
118 | private final DeviceService deviceService; | 121 | private final DeviceService deviceService; |
119 | private final GroupService groupService; | 122 | private final GroupService groupService; |
123 | + private final HostService hostService; | ||
120 | private final NetworkConfigRegistry configRegistry; | 124 | private final NetworkConfigRegistry configRegistry; |
121 | private final String tunnelType; | 125 | private final String tunnelType; |
122 | 126 | ||
... | @@ -134,12 +138,14 @@ public class CordVtnRuleInstaller { | ... | @@ -134,12 +138,14 @@ public class CordVtnRuleInstaller { |
134 | FlowRuleService flowRuleService, | 138 | FlowRuleService flowRuleService, |
135 | DeviceService deviceService, | 139 | DeviceService deviceService, |
136 | GroupService groupService, | 140 | GroupService groupService, |
141 | + HostService hostService, | ||
137 | NetworkConfigRegistry configRegistry, | 142 | NetworkConfigRegistry configRegistry, |
138 | String tunnelType) { | 143 | String tunnelType) { |
139 | this.appId = appId; | 144 | this.appId = appId; |
140 | this.flowRuleService = flowRuleService; | 145 | this.flowRuleService = flowRuleService; |
141 | this.deviceService = deviceService; | 146 | this.deviceService = deviceService; |
142 | this.groupService = groupService; | 147 | this.groupService = groupService; |
148 | + this.hostService = hostService; | ||
143 | this.configRegistry = configRegistry; | 149 | this.configRegistry = configRegistry; |
144 | this.tunnelType = checkNotNull(tunnelType); | 150 | this.tunnelType = checkNotNull(tunnelType); |
145 | } | 151 | } |
... | @@ -177,7 +183,7 @@ public class CordVtnRuleInstaller { | ... | @@ -177,7 +183,7 @@ public class CordVtnRuleInstaller { |
177 | * @param service cord service | 183 | * @param service cord service |
178 | * @param install true to install or false to remove | 184 | * @param install true to install or false to remove |
179 | */ | 185 | */ |
180 | - public void populateBasicConnectionRules(Host host, CordService service, boolean install) { | 186 | + public void populateBasicConnectionRules(Host host, VtnService service, boolean install) { |
181 | checkNotNull(host); | 187 | checkNotNull(host); |
182 | checkNotNull(service); | 188 | checkNotNull(service); |
183 | 189 | ||
... | @@ -186,8 +192,8 @@ public class CordVtnRuleInstaller { | ... | @@ -186,8 +192,8 @@ public class CordVtnRuleInstaller { |
186 | MacAddress dstMac = host.mac(); | 192 | MacAddress dstMac = host.mac(); |
187 | IpAddress hostIp = host.ipAddresses().stream().findFirst().get(); | 193 | IpAddress hostIp = host.ipAddresses().stream().findFirst().get(); |
188 | 194 | ||
189 | - long tunnelId = service.segmentationId(); | 195 | + long tunnelId = service.vni(); |
190 | - Ip4Prefix serviceIpRange = service.serviceIpRange().getIp4Prefix(); | 196 | + Ip4Prefix serviceIpRange = service.subnet().getIp4Prefix(); |
191 | 197 | ||
192 | populateLocalInPortRule(deviceId, inPort, hostIp, install); | 198 | populateLocalInPortRule(deviceId, inPort, hostIp, install); |
193 | populateDstIpRule(deviceId, inPort, dstMac, hostIp, tunnelId, getTunnelIp(host), install); | 199 | populateDstIpRule(deviceId, inPort, dstMac, hostIp, tunnelId, getTunnelIp(host), install); |
... | @@ -196,7 +202,7 @@ public class CordVtnRuleInstaller { | ... | @@ -196,7 +202,7 @@ public class CordVtnRuleInstaller { |
196 | if (install) { | 202 | if (install) { |
197 | populateDirectAccessRule(serviceIpRange, serviceIpRange, true); | 203 | populateDirectAccessRule(serviceIpRange, serviceIpRange, true); |
198 | populateServiceIsolationRule(serviceIpRange, true); | 204 | populateServiceIsolationRule(serviceIpRange, true); |
199 | - } else if (service.hosts().isEmpty()) { | 205 | + } else if (getInstances(service.id()).isEmpty()) { |
200 | // removes network related rules only if there's no hosts left in this network | 206 | // removes network related rules only if there's no hosts left in this network |
201 | populateDirectAccessRule(serviceIpRange, serviceIpRange, false); | 207 | populateDirectAccessRule(serviceIpRange, serviceIpRange, false); |
202 | populateServiceIsolationRule(serviceIpRange, false); | 208 | populateServiceIsolationRule(serviceIpRange, false); |
... | @@ -211,13 +217,13 @@ public class CordVtnRuleInstaller { | ... | @@ -211,13 +217,13 @@ public class CordVtnRuleInstaller { |
211 | * @param isBidirectional true to enable bidirectional connection between two services | 217 | * @param isBidirectional true to enable bidirectional connection between two services |
212 | * @param install true to install or false to remove | 218 | * @param install true to install or false to remove |
213 | */ | 219 | */ |
214 | - public void populateServiceDependencyRules(CordService tService, CordService pService, | 220 | + public void populateServiceDependencyRules(VtnService tService, VtnService pService, |
215 | boolean isBidirectional, boolean install) { | 221 | boolean isBidirectional, boolean install) { |
216 | checkNotNull(tService); | 222 | checkNotNull(tService); |
217 | checkNotNull(pService); | 223 | checkNotNull(pService); |
218 | 224 | ||
219 | - Ip4Prefix srcRange = tService.serviceIpRange().getIp4Prefix(); | 225 | + Ip4Prefix srcRange = tService.subnet().getIp4Prefix(); |
220 | - Ip4Prefix dstRange = pService.serviceIpRange().getIp4Prefix(); | 226 | + Ip4Prefix dstRange = pService.subnet().getIp4Prefix(); |
221 | Ip4Address serviceIp = pService.serviceIp().getIp4Address(); | 227 | Ip4Address serviceIp = pService.serviceIp().getIp4Address(); |
222 | 228 | ||
223 | Map<DeviceId, GroupId> outGroups = Maps.newHashMap(); | 229 | Map<DeviceId, GroupId> outGroups = Maps.newHashMap(); |
... | @@ -227,7 +233,7 @@ public class CordVtnRuleInstaller { | ... | @@ -227,7 +233,7 @@ public class CordVtnRuleInstaller { |
227 | GroupId groupId = createServiceGroup(deviceId, pService); | 233 | GroupId groupId = createServiceGroup(deviceId, pService); |
228 | outGroups.put(deviceId, groupId); | 234 | outGroups.put(deviceId, groupId); |
229 | 235 | ||
230 | - Set<PortNumber> tServiceVms = tService.hosts().keySet() | 236 | + Set<PortNumber> tServiceVms = getInstances(tService.id()) |
231 | .stream() | 237 | .stream() |
232 | .filter(host -> host.location().deviceId().equals(deviceId)) | 238 | .filter(host -> host.location().deviceId().equals(deviceId)) |
233 | .map(host -> host.location().port()) | 239 | .map(host -> host.location().port()) |
... | @@ -248,7 +254,7 @@ public class CordVtnRuleInstaller { | ... | @@ -248,7 +254,7 @@ public class CordVtnRuleInstaller { |
248 | * | 254 | * |
249 | * @param service cord service | 255 | * @param service cord service |
250 | */ | 256 | */ |
251 | - public void updateProviderServiceGroup(CordService service) { | 257 | + public void updateProviderServiceGroup(VtnService service) { |
252 | checkNotNull(service); | 258 | checkNotNull(service); |
253 | 259 | ||
254 | GroupKey groupKey = getGroupKey(service.id()); | 260 | GroupKey groupKey = getGroupKey(service.id()); |
... | @@ -262,7 +268,7 @@ public class CordVtnRuleInstaller { | ... | @@ -262,7 +268,7 @@ public class CordVtnRuleInstaller { |
262 | 268 | ||
263 | List<GroupBucket> oldBuckets = group.buckets().buckets(); | 269 | List<GroupBucket> oldBuckets = group.buckets().buckets(); |
264 | List<GroupBucket> newBuckets = getServiceGroupBuckets( | 270 | List<GroupBucket> newBuckets = getServiceGroupBuckets( |
265 | - deviceId, service.segmentationId(), service.hosts()).buckets(); | 271 | + deviceId, service.vni(), getInstances(service.id())).buckets(); |
266 | 272 | ||
267 | if (oldBuckets.equals(newBuckets)) { | 273 | if (oldBuckets.equals(newBuckets)) { |
268 | continue; | 274 | continue; |
... | @@ -296,7 +302,7 @@ public class CordVtnRuleInstaller { | ... | @@ -296,7 +302,7 @@ public class CordVtnRuleInstaller { |
296 | * @param host removed vm | 302 | * @param host removed vm |
297 | * @param service tenant service | 303 | * @param service tenant service |
298 | */ | 304 | */ |
299 | - public void updateTenantServiceVm(Host host, CordService service) { | 305 | + public void updateTenantServiceVm(Host host, VtnService service) { |
300 | checkNotNull(host); | 306 | checkNotNull(host); |
301 | checkNotNull(service); | 307 | checkNotNull(service); |
302 | 308 | ||
... | @@ -320,7 +326,7 @@ public class CordVtnRuleInstaller { | ... | @@ -320,7 +326,7 @@ public class CordVtnRuleInstaller { |
320 | * @param host host which has management network interface | 326 | * @param host host which has management network interface |
321 | * @param mService management network service | 327 | * @param mService management network service |
322 | */ | 328 | */ |
323 | - public void populateManagementNetworkRules(Host host, CordService mService) { | 329 | + public void populateManagementNetworkRules(Host host, VtnService mService) { |
324 | checkNotNull(mService); | 330 | checkNotNull(mService); |
325 | 331 | ||
326 | DeviceId deviceId = host.location().deviceId(); | 332 | DeviceId deviceId = host.location().deviceId(); |
... | @@ -372,7 +378,7 @@ public class CordVtnRuleInstaller { | ... | @@ -372,7 +378,7 @@ public class CordVtnRuleInstaller { |
372 | selector = DefaultTrafficSelector.builder() | 378 | selector = DefaultTrafficSelector.builder() |
373 | .matchInPort(PortNumber.LOCAL) | 379 | .matchInPort(PortNumber.LOCAL) |
374 | .matchEthType(Ethernet.TYPE_IPV4) | 380 | .matchEthType(Ethernet.TYPE_IPV4) |
375 | - .matchIPDst(mService.serviceIpRange()) | 381 | + .matchIPDst(mService.subnet()) |
376 | .build(); | 382 | .build(); |
377 | 383 | ||
378 | treatment = DefaultTrafficTreatment.builder() | 384 | treatment = DefaultTrafficTreatment.builder() |
... | @@ -1237,7 +1243,7 @@ public class CordVtnRuleInstaller { | ... | @@ -1237,7 +1243,7 @@ public class CordVtnRuleInstaller { |
1237 | * @param service cord service | 1243 | * @param service cord service |
1238 | * @return group id, or null if it fails to create | 1244 | * @return group id, or null if it fails to create |
1239 | */ | 1245 | */ |
1240 | - private GroupId createServiceGroup(DeviceId deviceId, CordService service) { | 1246 | + private GroupId createServiceGroup(DeviceId deviceId, VtnService service) { |
1241 | checkNotNull(service); | 1247 | checkNotNull(service); |
1242 | 1248 | ||
1243 | GroupKey groupKey = getGroupKey(service.id()); | 1249 | GroupKey groupKey = getGroupKey(service.id()); |
... | @@ -1250,7 +1256,7 @@ public class CordVtnRuleInstaller { | ... | @@ -1250,7 +1256,7 @@ public class CordVtnRuleInstaller { |
1250 | } | 1256 | } |
1251 | 1257 | ||
1252 | GroupBuckets buckets = getServiceGroupBuckets( | 1258 | GroupBuckets buckets = getServiceGroupBuckets( |
1253 | - deviceId, service.segmentationId(), service.hosts()); | 1259 | + deviceId, service.vni(), getInstances(service.id())); |
1254 | GroupDescription groupDescription = new DefaultGroupDescription( | 1260 | GroupDescription groupDescription = new DefaultGroupDescription( |
1255 | deviceId, | 1261 | deviceId, |
1256 | GroupDescription.Type.SELECT, | 1262 | GroupDescription.Type.SELECT, |
... | @@ -1273,33 +1279,26 @@ public class CordVtnRuleInstaller { | ... | @@ -1273,33 +1279,26 @@ public class CordVtnRuleInstaller { |
1273 | * @return group buckets | 1279 | * @return group buckets |
1274 | */ | 1280 | */ |
1275 | private GroupBuckets getServiceGroupBuckets(DeviceId deviceId, long tunnelId, | 1281 | private GroupBuckets getServiceGroupBuckets(DeviceId deviceId, long tunnelId, |
1276 | - Map<Host, IpAddress> hosts) { | 1282 | + Set<Host> hosts) { |
1277 | List<GroupBucket> buckets = Lists.newArrayList(); | 1283 | List<GroupBucket> buckets = Lists.newArrayList(); |
1278 | 1284 | ||
1279 | - for (Map.Entry<Host, IpAddress> entry : hosts.entrySet()) { | 1285 | + hosts.stream().forEach(host -> { |
1280 | - Host host = entry.getKey(); | 1286 | + Ip4Address tunnelIp = getTunnelIp(host).getIp4Address(); |
1281 | - Ip4Address remoteIp = entry.getValue().getIp4Address(); | ||
1282 | DeviceId hostDevice = host.location().deviceId(); | 1287 | DeviceId hostDevice = host.location().deviceId(); |
1283 | 1288 | ||
1284 | TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment | 1289 | TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment |
1285 | .builder() | 1290 | .builder() |
1286 | .setEthDst(host.mac()); | 1291 | .setEthDst(host.mac()); |
1287 | - | ||
1288 | if (deviceId.equals(hostDevice)) { | 1292 | if (deviceId.equals(hostDevice)) { |
1289 | tBuilder.setOutput(host.location().port()); | 1293 | tBuilder.setOutput(host.location().port()); |
1290 | } else { | 1294 | } else { |
1291 | - ExtensionTreatment tunnelDst = getTunnelDst(deviceId, remoteIp); | 1295 | + ExtensionTreatment tunnelDst = getTunnelDst(deviceId, tunnelIp); |
1292 | - if (tunnelDst == null) { | ||
1293 | - continue; | ||
1294 | - } | ||
1295 | - | ||
1296 | tBuilder.extension(tunnelDst, deviceId) | 1296 | tBuilder.extension(tunnelDst, deviceId) |
1297 | .setTunnelId(tunnelId) | 1297 | .setTunnelId(tunnelId) |
1298 | .setOutput(getTunnelPort(hostDevice)); | 1298 | .setOutput(getTunnelPort(hostDevice)); |
1299 | } | 1299 | } |
1300 | - | ||
1301 | buckets.add(DefaultGroupBucket.createSelectGroupBucket(tBuilder.build())); | 1300 | buckets.add(DefaultGroupBucket.createSelectGroupBucket(tBuilder.build())); |
1302 | - } | 1301 | + }); |
1303 | 1302 | ||
1304 | return new GroupBuckets(buckets); | 1303 | return new GroupBuckets(buckets); |
1305 | } | 1304 | } |
... | @@ -1311,7 +1310,7 @@ public class CordVtnRuleInstaller { | ... | @@ -1311,7 +1310,7 @@ public class CordVtnRuleInstaller { |
1311 | * @param deviceId device id | 1310 | * @param deviceId device id |
1312 | * @return group id | 1311 | * @return group id |
1313 | */ | 1312 | */ |
1314 | - private GroupId getGroupId(CordServiceId serviceId, DeviceId deviceId) { | 1313 | + private GroupId getGroupId(VtnServiceId serviceId, DeviceId deviceId) { |
1315 | return new DefaultGroupId(Objects.hash(serviceId, deviceId)); | 1314 | return new DefaultGroupId(Objects.hash(serviceId, deviceId)); |
1316 | } | 1315 | } |
1317 | 1316 | ||
... | @@ -1321,7 +1320,7 @@ public class CordVtnRuleInstaller { | ... | @@ -1321,7 +1320,7 @@ public class CordVtnRuleInstaller { |
1321 | * @param serviceId service id | 1320 | * @param serviceId service id |
1322 | * @return group key | 1321 | * @return group key |
1323 | */ | 1322 | */ |
1324 | - private GroupKey getGroupKey(CordServiceId serviceId) { | 1323 | + private GroupKey getGroupKey(VtnServiceId serviceId) { |
1325 | return new DefaultGroupKey(serviceId.id().getBytes()); | 1324 | return new DefaultGroupKey(serviceId.id().getBytes()); |
1326 | } | 1325 | } |
1327 | 1326 | ||
... | @@ -1370,5 +1369,19 @@ public class CordVtnRuleInstaller { | ... | @@ -1370,5 +1369,19 @@ public class CordVtnRuleInstaller { |
1370 | return config.cordVtnNodes().stream() | 1369 | return config.cordVtnNodes().stream() |
1371 | .map(CordVtnNode::intBrId).collect(Collectors.toSet()); | 1370 | .map(CordVtnNode::intBrId).collect(Collectors.toSet()); |
1372 | } | 1371 | } |
1372 | + | ||
1373 | + /** | ||
1374 | + * Returns instances with a given network service. | ||
1375 | + * | ||
1376 | + * @param serviceId service id | ||
1377 | + * @return set of hosts | ||
1378 | + */ | ||
1379 | + private Set<Host> getInstances(VtnServiceId serviceId) { | ||
1380 | + return StreamSupport.stream(hostService.getHosts().spliterator(), false) | ||
1381 | + .filter(host -> Objects.equals( | ||
1382 | + serviceId.id(), | ||
1383 | + host.annotations().value(SERVICE_ID))) | ||
1384 | + .collect(Collectors.toSet()); | ||
1385 | + } | ||
1373 | } | 1386 | } |
1374 | 1387 | ... | ... |
... | @@ -16,8 +16,8 @@ | ... | @@ -16,8 +16,8 @@ |
16 | package org.onosproject.cordvtn.rest; | 16 | package org.onosproject.cordvtn.rest; |
17 | 17 | ||
18 | import org.onosproject.cordvtn.api.CordVtnService; | 18 | import org.onosproject.cordvtn.api.CordVtnService; |
19 | -import org.onosproject.cordvtn.api.CordServiceId; | ||
20 | import org.onosproject.rest.AbstractWebResource; | 19 | import org.onosproject.rest.AbstractWebResource; |
20 | +import org.onosproject.xosclient.api.VtnServiceId; | ||
21 | 21 | ||
22 | import javax.ws.rs.DELETE; | 22 | import javax.ws.rs.DELETE; |
23 | import javax.ws.rs.POST; | 23 | import javax.ws.rs.POST; |
... | @@ -48,8 +48,8 @@ public class ServiceDependencyWebResource extends AbstractWebResource { | ... | @@ -48,8 +48,8 @@ public class ServiceDependencyWebResource extends AbstractWebResource { |
48 | @Produces(MediaType.APPLICATION_JSON) | 48 | @Produces(MediaType.APPLICATION_JSON) |
49 | public Response createServiceDependency(@PathParam("tenantServiceId") String tServiceId, | 49 | public Response createServiceDependency(@PathParam("tenantServiceId") String tServiceId, |
50 | @PathParam("providerServiceId") String pServiceId) { | 50 | @PathParam("providerServiceId") String pServiceId) { |
51 | - service.createServiceDependency(CordServiceId.of(tServiceId), | 51 | + service.createServiceDependency(VtnServiceId.of(tServiceId), |
52 | - CordServiceId.of(pServiceId), | 52 | + VtnServiceId.of(pServiceId), |
53 | false); | 53 | false); |
54 | return Response.status(Response.Status.OK).build(); | 54 | return Response.status(Response.Status.OK).build(); |
55 | } | 55 | } |
... | @@ -68,8 +68,8 @@ public class ServiceDependencyWebResource extends AbstractWebResource { | ... | @@ -68,8 +68,8 @@ public class ServiceDependencyWebResource extends AbstractWebResource { |
68 | public Response createServiceDependency(@PathParam("tenantServiceId") String tServiceId, | 68 | public Response createServiceDependency(@PathParam("tenantServiceId") String tServiceId, |
69 | @PathParam("providerServiceId") String pServiceId, | 69 | @PathParam("providerServiceId") String pServiceId, |
70 | @PathParam("direction") String direction) { | 70 | @PathParam("direction") String direction) { |
71 | - service.createServiceDependency(CordServiceId.of(tServiceId), | 71 | + service.createServiceDependency(VtnServiceId.of(tServiceId), |
72 | - CordServiceId.of(pServiceId), | 72 | + VtnServiceId.of(pServiceId), |
73 | direction.equals(BIDIRECTION)); | 73 | direction.equals(BIDIRECTION)); |
74 | return Response.status(Response.Status.OK).build(); | 74 | return Response.status(Response.Status.OK).build(); |
75 | } | 75 | } |
... | @@ -85,7 +85,7 @@ public class ServiceDependencyWebResource extends AbstractWebResource { | ... | @@ -85,7 +85,7 @@ public class ServiceDependencyWebResource extends AbstractWebResource { |
85 | @Path("{tenantServiceId}/{providerServiceId}") | 85 | @Path("{tenantServiceId}/{providerServiceId}") |
86 | public Response removeServiceDependency(@PathParam("tenantServiceId") String tServiceId, | 86 | public Response removeServiceDependency(@PathParam("tenantServiceId") String tServiceId, |
87 | @PathParam("providerServiceId") String pServiceId) { | 87 | @PathParam("providerServiceId") String pServiceId) { |
88 | - service.removeServiceDependency(CordServiceId.of(tServiceId), CordServiceId.of(pServiceId)); | 88 | + service.removeServiceDependency(VtnServiceId.of(tServiceId), VtnServiceId.of(pServiceId)); |
89 | return Response.noContent().build(); | 89 | return Response.noContent().build(); |
90 | } | 90 | } |
91 | } | 91 | } | ... | ... |
1 | COMPILE_DEPS = [ | 1 | COMPILE_DEPS = [ |
2 | '//lib:CORE_DEPS', | 2 | '//lib:CORE_DEPS', |
3 | '//lib:javax.ws.rs-api', | 3 | '//lib:javax.ws.rs-api', |
4 | + '//lib:openstack4j-core', | ||
5 | + '//lib:openstack4j-http-connector', | ||
6 | + '//lib:openstack4j-httpclient', | ||
4 | ] | 7 | ] |
5 | 8 | ||
6 | osgi_jar_with_tests ( | 9 | osgi_jar_with_tests ( | ... | ... |
... | @@ -49,6 +49,45 @@ | ... | @@ -49,6 +49,45 @@ |
49 | <artifactId>onlab-misc</artifactId> | 49 | <artifactId>onlab-misc</artifactId> |
50 | <version>${project.version}</version> | 50 | <version>${project.version}</version> |
51 | </dependency> | 51 | </dependency> |
52 | + <dependency> | ||
53 | + <groupId>org.pacesys</groupId> | ||
54 | + <artifactId>openstack4j-core</artifactId> | ||
55 | + <version>2.11</version> | ||
56 | + </dependency> | ||
57 | + <dependency> | ||
58 | + <groupId>org.pacesys.openstack4j.connectors</groupId> | ||
59 | + <artifactId>openstack4j-http-connector</artifactId> | ||
60 | + <version>2.11</version> | ||
61 | + </dependency> | ||
62 | + <dependency> | ||
63 | + <groupId>org.pacesys.openstack4j.connectors</groupId> | ||
64 | + <artifactId>openstack4j-httpclient</artifactId> | ||
65 | + <version>2.11</version> | ||
66 | + </dependency> | ||
52 | </dependencies> | 67 | </dependencies> |
53 | 68 | ||
69 | + <build> | ||
70 | + <plugins> | ||
71 | + <plugin> | ||
72 | + <groupId>org.apache.felix</groupId> | ||
73 | + <artifactId>maven-bundle-plugin</artifactId> | ||
74 | + <extensions>true</extensions> | ||
75 | + <configuration> | ||
76 | + <instructions> | ||
77 | + <Import-Package> | ||
78 | + !org.apache.http.*, | ||
79 | + !com.fasterxml.jackson.dataformat.*, | ||
80 | + !javax.annotation,* | ||
81 | + </Import-Package> | ||
82 | + <Embed-Dependency> | ||
83 | + openstack4j-core, | ||
84 | + openstack4j-http-connector, | ||
85 | + openstack4j-httpclient | ||
86 | + </Embed-Dependency> | ||
87 | + </instructions> | ||
88 | + </configuration> | ||
89 | + </plugin> | ||
90 | + </plugins> | ||
91 | + </build> | ||
92 | + | ||
54 | </project> | 93 | </project> | ... | ... |
1 | +/* | ||
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 | + */ | ||
16 | +package org.onosproject.xosclient.api; | ||
17 | + | ||
18 | +import com.google.common.base.MoreObjects; | ||
19 | + | ||
20 | +import java.util.Objects; | ||
21 | + | ||
22 | +/** | ||
23 | + * Object holding OpenStack API access information. | ||
24 | + */ | ||
25 | +// TODO remove this when XOS provides this information | ||
26 | +public class OpenStackAccess { | ||
27 | + | ||
28 | + private final String endpoint; | ||
29 | + private final String tenant; | ||
30 | + private final String user; | ||
31 | + private final String password; | ||
32 | + | ||
33 | + /** | ||
34 | + * Default constructor. | ||
35 | + * | ||
36 | + * @param endpoint Keystone endpoint | ||
37 | + * @param tenant tenant name | ||
38 | + * @param user user name | ||
39 | + * @param password password | ||
40 | + */ | ||
41 | + public OpenStackAccess(String endpoint, String tenant, String user, String password) { | ||
42 | + this.endpoint = endpoint; | ||
43 | + this.tenant = tenant; | ||
44 | + this.user = user; | ||
45 | + this.password = password; | ||
46 | + } | ||
47 | + | ||
48 | + /** | ||
49 | + * Returns OpenStack API endpoint. | ||
50 | + * | ||
51 | + * @return endpoint | ||
52 | + */ | ||
53 | + public String endpoint() { | ||
54 | + return this.endpoint; | ||
55 | + } | ||
56 | + | ||
57 | + /** | ||
58 | + * Returns OpenStack tenant name. | ||
59 | + * | ||
60 | + * @return tenant name | ||
61 | + */ | ||
62 | + public String tenant() { | ||
63 | + return this.tenant; | ||
64 | + } | ||
65 | + | ||
66 | + /** | ||
67 | + * Returns OpenStack user. | ||
68 | + * | ||
69 | + * @return user name | ||
70 | + */ | ||
71 | + public String user() { | ||
72 | + return this.user; | ||
73 | + } | ||
74 | + | ||
75 | + /** | ||
76 | + * Returns OpenStack password for the user. | ||
77 | + * | ||
78 | + * @return password | ||
79 | + */ | ||
80 | + public String password() { | ||
81 | + return this.password; | ||
82 | + } | ||
83 | + | ||
84 | + @Override | ||
85 | + public int hashCode() { | ||
86 | + return Objects.hash(endpoint, tenant, user, password); | ||
87 | + } | ||
88 | + | ||
89 | + @Override | ||
90 | + public boolean equals(Object obj) { | ||
91 | + if (this == obj) { | ||
92 | + return true; | ||
93 | + } | ||
94 | + if ((obj instanceof OpenStackAccess)) { | ||
95 | + OpenStackAccess that = (OpenStackAccess) obj; | ||
96 | + if (Objects.equals(endpoint, that.endpoint) && | ||
97 | + Objects.equals(tenant, that.tenant) && | ||
98 | + Objects.equals(user, that.user) && | ||
99 | + Objects.equals(password, that.password)) { | ||
100 | + return true; | ||
101 | + } | ||
102 | + } | ||
103 | + return false; | ||
104 | + } | ||
105 | + | ||
106 | + @Override | ||
107 | + public String toString() { | ||
108 | + return MoreObjects.toStringHelper(getClass()) | ||
109 | + .add("endpoint", endpoint) | ||
110 | + .add("tenant", tenant) | ||
111 | + .add("user", user) | ||
112 | + .add("password", password) | ||
113 | + .toString(); | ||
114 | + } | ||
115 | +} |
... | @@ -44,4 +44,22 @@ public interface VtnPortApi { | ... | @@ -44,4 +44,22 @@ public interface VtnPortApi { |
44 | * @return vtn port; null if it fails to get port information | 44 | * @return vtn port; null if it fails to get port information |
45 | */ | 45 | */ |
46 | VtnPort vtnPort(VtnPortId portId); | 46 | VtnPort vtnPort(VtnPortId portId); |
47 | + | ||
48 | + /** | ||
49 | + * Returns port information from OpenStack with port id. | ||
50 | + * | ||
51 | + * @param portId port id | ||
52 | + * @return vtn port; null if it fails to get port information | ||
53 | + */ | ||
54 | + // TODO remove this when XOS provides port information | ||
55 | + VtnPort vtnPort(VtnPortId portId, OpenStackAccess osAccess); | ||
56 | + | ||
57 | + /** | ||
58 | + * Returns port information from OpenStack with port name. | ||
59 | + * | ||
60 | + * @param portName port name | ||
61 | + * @return vtn port; null if it fails to get port information | ||
62 | + */ | ||
63 | + // TODO remove this when XOS provides port information | ||
64 | + VtnPort vtnPort(String portName, OpenStackAccess osAccess); | ||
47 | } | 65 | } | ... | ... |
... | @@ -52,4 +52,14 @@ public interface VtnServiceApi { | ... | @@ -52,4 +52,14 @@ public interface VtnServiceApi { |
52 | * @return set of service ids | 52 | * @return set of service ids |
53 | */ | 53 | */ |
54 | Set<VtnServiceId> providerServices(VtnServiceId tServiceId); | 54 | Set<VtnServiceId> providerServices(VtnServiceId tServiceId); |
55 | + | ||
56 | + /** | ||
57 | + * Returns VTN service from OpenStack. | ||
58 | + * | ||
59 | + * @param serviceId service id | ||
60 | + * @param osAccess openstack access | ||
61 | + * @return vtn service | ||
62 | + */ | ||
63 | + // TODO remove this when XOS provides service information | ||
64 | + VtnService service(VtnServiceId serviceId, OpenStackAccess osAccess); | ||
55 | } | 65 | } | ... | ... |
... | @@ -15,18 +15,33 @@ | ... | @@ -15,18 +15,33 @@ |
15 | */ | 15 | */ |
16 | package org.onosproject.xosclient.impl; | 16 | package org.onosproject.xosclient.impl; |
17 | 17 | ||
18 | +import com.google.common.collect.Maps; | ||
19 | +import org.onlab.packet.IpAddress; | ||
20 | +import org.onlab.packet.MacAddress; | ||
21 | +import org.onosproject.xosclient.api.OpenStackAccess; | ||
18 | import org.onosproject.xosclient.api.VtnPort; | 22 | import org.onosproject.xosclient.api.VtnPort; |
19 | import org.onosproject.xosclient.api.VtnPortApi; | 23 | import org.onosproject.xosclient.api.VtnPortApi; |
20 | import org.onosproject.xosclient.api.VtnPortId; | 24 | import org.onosproject.xosclient.api.VtnPortId; |
21 | import org.onosproject.xosclient.api.VtnServiceId; | 25 | import org.onosproject.xosclient.api.VtnServiceId; |
22 | import org.onosproject.xosclient.api.XosAccess; | 26 | import org.onosproject.xosclient.api.XosAccess; |
27 | +import org.openstack4j.api.OSClient; | ||
28 | +import org.openstack4j.model.network.IP; | ||
29 | +import org.openstack4j.model.network.Port; | ||
30 | +import org.openstack4j.openstack.OSFactory; | ||
31 | +import org.slf4j.Logger; | ||
32 | +import org.slf4j.LoggerFactory; | ||
23 | 33 | ||
34 | +import java.util.Map; | ||
24 | import java.util.Set; | 35 | import java.util.Set; |
25 | 36 | ||
37 | +import static com.google.common.base.Preconditions.checkNotNull; | ||
38 | + | ||
26 | /** | 39 | /** |
27 | * Provides CORD VTN port APIs. | 40 | * Provides CORD VTN port APIs. |
28 | */ | 41 | */ |
29 | -public class DefaultVtnPortApi extends XosApi implements VtnPortApi { | 42 | +public final class DefaultVtnPortApi extends XosApi implements VtnPortApi { |
43 | + | ||
44 | + private final Logger log = LoggerFactory.getLogger(getClass()); | ||
30 | 45 | ||
31 | /** | 46 | /** |
32 | * Default constructor. | 47 | * Default constructor. |
... | @@ -55,4 +70,72 @@ public class DefaultVtnPortApi extends XosApi implements VtnPortApi { | ... | @@ -55,4 +70,72 @@ public class DefaultVtnPortApi extends XosApi implements VtnPortApi { |
55 | // TODO implement this when XOS provides this information | 70 | // TODO implement this when XOS provides this information |
56 | return null; | 71 | return null; |
57 | } | 72 | } |
73 | + | ||
74 | + @Override | ||
75 | + // TODO remove this when XOS provides this information | ||
76 | + public VtnPort vtnPort(String portName, OpenStackAccess osAccess) { | ||
77 | + checkNotNull(osAccess); | ||
78 | + | ||
79 | + OSClient osClient = getOpenStackClient(osAccess); | ||
80 | + Port osPort = osClient.networking().port().list() | ||
81 | + .stream() | ||
82 | + .filter(p -> p.getId().contains(portName.substring(3))) | ||
83 | + .findFirst().orElse(null); | ||
84 | + if (osPort == null) { | ||
85 | + log.warn("Failed to get OpenStack port for {}", portName); | ||
86 | + return null; | ||
87 | + } | ||
88 | + return getVtnPort(osPort); | ||
89 | + } | ||
90 | + | ||
91 | + @Override | ||
92 | + // TODO remove this when XOS provides this information | ||
93 | + public VtnPort vtnPort(VtnPortId portId, OpenStackAccess osAccess) { | ||
94 | + checkNotNull(osAccess); | ||
95 | + | ||
96 | + OSClient osClient = getOpenStackClient(osAccess); | ||
97 | + Port osPort = osClient.networking().port().get(portId.id()); | ||
98 | + if (osPort == null) { | ||
99 | + log.warn("Failed to get OpenStack port {}", portId); | ||
100 | + return null; | ||
101 | + } | ||
102 | + return getVtnPort(osPort); | ||
103 | + } | ||
104 | + | ||
105 | + // TODO remove this when XOS provides this information | ||
106 | + private VtnPort getVtnPort(Port osPort) { | ||
107 | + checkNotNull(osPort); | ||
108 | + | ||
109 | + // assumes all vtn port has single IP address | ||
110 | + IP ipAddr = osPort.getFixedIps().stream().findFirst().orElse(null); | ||
111 | + if (ipAddr == null) { | ||
112 | + log.warn("Failed to get IP address for {}", osPort); | ||
113 | + return null; | ||
114 | + } | ||
115 | + | ||
116 | + Map<IpAddress, MacAddress> addressPairs = Maps.newHashMap(); | ||
117 | + osPort.getAllowedAddressPairs().stream().forEach( | ||
118 | + pair -> addressPairs.put(IpAddress.valueOf(pair.getIpAddress()), | ||
119 | + MacAddress.valueOf(pair.getMacAddress()))); | ||
120 | + | ||
121 | + return new VtnPort(VtnPortId.of(osPort.getId()), | ||
122 | + osPort.getName(), | ||
123 | + VtnServiceId.of(osPort.getNetworkId()), | ||
124 | + MacAddress.valueOf(osPort.getMacAddress()), | ||
125 | + IpAddress.valueOf(ipAddr.getIpAddress()), | ||
126 | + addressPairs); | ||
127 | + } | ||
128 | + | ||
129 | + // TODO remove this when XOS provides this information | ||
130 | + private OSClient getOpenStackClient(OpenStackAccess osAccess) { | ||
131 | + checkNotNull(osAccess); | ||
132 | + | ||
133 | + // creating a client every time must be inefficient, but this method | ||
134 | + // will be removed once XOS provides equivalent APIs | ||
135 | + return OSFactory.builder() | ||
136 | + .endpoint(osAccess.endpoint()) | ||
137 | + .credentials(osAccess.user(), osAccess.password()) | ||
138 | + .tenantName(osAccess.tenant()) | ||
139 | + .authenticate(); | ||
140 | + } | ||
58 | } | 141 | } | ... | ... |
... | @@ -17,12 +17,22 @@ package org.onosproject.xosclient.impl; | ... | @@ -17,12 +17,22 @@ package org.onosproject.xosclient.impl; |
17 | 17 | ||
18 | import com.fasterxml.jackson.databind.JsonNode; | 18 | import com.fasterxml.jackson.databind.JsonNode; |
19 | import com.fasterxml.jackson.databind.ObjectMapper; | 19 | import com.fasterxml.jackson.databind.ObjectMapper; |
20 | +import com.google.common.base.Strings; | ||
20 | import com.google.common.collect.Sets; | 21 | import com.google.common.collect.Sets; |
22 | +import org.onlab.packet.IpAddress; | ||
23 | +import org.onlab.packet.IpPrefix; | ||
24 | +import org.onosproject.xosclient.api.OpenStackAccess; | ||
25 | +import org.onosproject.xosclient.api.VtnService.NetworkType; | ||
26 | +import org.onosproject.xosclient.api.VtnService.ServiceType; | ||
21 | import org.onosproject.xosclient.api.VtnServiceApi; | 27 | import org.onosproject.xosclient.api.VtnServiceApi; |
22 | import org.onosproject.xosclient.api.XosAccess; | 28 | import org.onosproject.xosclient.api.XosAccess; |
23 | import org.onosproject.xosclient.api.VtnService; | 29 | import org.onosproject.xosclient.api.VtnService; |
24 | import org.onosproject.xosclient.api.VtnServiceId; | 30 | import org.onosproject.xosclient.api.VtnServiceId; |
25 | 31 | ||
32 | +import org.openstack4j.api.OSClient; | ||
33 | +import org.openstack4j.model.network.Network; | ||
34 | +import org.openstack4j.model.network.Subnet; | ||
35 | +import org.openstack4j.openstack.OSFactory; | ||
26 | import org.slf4j.Logger; | 36 | import org.slf4j.Logger; |
27 | import org.slf4j.LoggerFactory; | 37 | import org.slf4j.LoggerFactory; |
28 | 38 | ||
... | @@ -30,6 +40,9 @@ import java.io.IOException; | ... | @@ -30,6 +40,9 @@ import java.io.IOException; |
30 | import java.util.Set; | 40 | import java.util.Set; |
31 | 41 | ||
32 | import static com.google.common.base.Preconditions.checkNotNull; | 42 | import static com.google.common.base.Preconditions.checkNotNull; |
43 | +import static com.google.common.base.Preconditions.checkArgument; | ||
44 | +import static org.onosproject.xosclient.api.VtnService.NetworkType.*; | ||
45 | +import static org.onosproject.xosclient.api.VtnService.ServiceType.*; | ||
33 | 46 | ||
34 | /** | 47 | /** |
35 | * Provides CORD VTN service and service dependency APIs. | 48 | * Provides CORD VTN service and service dependency APIs. |
... | @@ -113,4 +126,76 @@ public final class DefaultVtnServiceApi extends XosApi implements VtnServiceApi | ... | @@ -113,4 +126,76 @@ public final class DefaultVtnServiceApi extends XosApi implements VtnServiceApi |
113 | } | 126 | } |
114 | return tServices; | 127 | return tServices; |
115 | } | 128 | } |
129 | + | ||
130 | + @Override | ||
131 | + // TODO remove this when XOS provides this information | ||
132 | + public VtnService service(VtnServiceId serviceId, OpenStackAccess osAccess) { | ||
133 | + checkNotNull(osAccess); | ||
134 | + | ||
135 | + OSClient osClient = getOpenStackClient(osAccess); | ||
136 | + Network osNet = osClient.networking().network().get(serviceId.id()); | ||
137 | + if (osNet == null) { | ||
138 | + log.warn("Failed to get OpenStack network {}", serviceId); | ||
139 | + return null; | ||
140 | + } | ||
141 | + | ||
142 | + // assumes all cord service networks has single subnet | ||
143 | + Subnet osSubnet = osNet.getNeutronSubnets().stream() | ||
144 | + .findFirst().orElse(null); | ||
145 | + if (osSubnet == null) { | ||
146 | + log.warn("Failed to get OpenStack subnet of network {}", serviceId); | ||
147 | + return null; | ||
148 | + } | ||
149 | + | ||
150 | + return new VtnService(serviceId, | ||
151 | + osNet.getName(), | ||
152 | + serviceType(osNet.getName()), | ||
153 | + networkType(osNet.getName()), | ||
154 | + Long.parseLong(osNet.getProviderSegID()), | ||
155 | + IpPrefix.valueOf(osSubnet.getCidr()), | ||
156 | + IpAddress.valueOf(osSubnet.getGateway()), | ||
157 | + providerServices(serviceId), | ||
158 | + tenantServices(serviceId)); | ||
159 | + } | ||
160 | + | ||
161 | + // TODO remove this when XOS provides this information | ||
162 | + private OSClient getOpenStackClient(OpenStackAccess osAccess) { | ||
163 | + checkNotNull(osAccess); | ||
164 | + | ||
165 | + // creating a client every time must be inefficient, but this method | ||
166 | + // will be removed once XOS provides equivalent APIs | ||
167 | + return OSFactory.builder() | ||
168 | + .endpoint(osAccess.endpoint()) | ||
169 | + .credentials(osAccess.user(), osAccess.password()) | ||
170 | + .tenantName(osAccess.tenant()) | ||
171 | + .authenticate(); | ||
172 | + } | ||
173 | + | ||
174 | + // TODO remove this when XOS provides this information | ||
175 | + private NetworkType networkType(String netName) { | ||
176 | + checkArgument(!Strings.isNullOrEmpty(netName)); | ||
177 | + | ||
178 | + String name = netName.toUpperCase(); | ||
179 | + if (name.contains(PUBLIC.toString())) { | ||
180 | + return PUBLIC; | ||
181 | + } else if (name.contains(MANAGEMENT.toString())) { | ||
182 | + return MANAGEMENT; | ||
183 | + } else { | ||
184 | + return PRIVATE; | ||
185 | + } | ||
186 | + } | ||
187 | + | ||
188 | + // TODO remove this when XOS provides this information | ||
189 | + private ServiceType serviceType(String netName) { | ||
190 | + checkArgument(!Strings.isNullOrEmpty(netName)); | ||
191 | + | ||
192 | + String name = netName.toUpperCase(); | ||
193 | + if (name.contains(VSG.toString())) { | ||
194 | + return VSG; | ||
195 | + } else if (name.contains(OLT_AGENT.toString())) { | ||
196 | + return OLT_AGENT; | ||
197 | + } else { | ||
198 | + return DUMMY; | ||
199 | + } | ||
200 | + } | ||
116 | } | 201 | } | ... | ... |
... | @@ -81,13 +81,15 @@ public class XosApi { | ... | @@ -81,13 +81,15 @@ public class XosApi { |
81 | public String restGet(String path) { | 81 | public String restGet(String path) { |
82 | WebTarget wt = client.target(access.endpoint() + baseUrl).path(path); | 82 | WebTarget wt = client.target(access.endpoint() + baseUrl).path(path); |
83 | Invocation.Builder builder = wt.request(JSON_UTF_8.toString()); | 83 | Invocation.Builder builder = wt.request(JSON_UTF_8.toString()); |
84 | - | 84 | + try { |
85 | Response response = builder.get(); | 85 | Response response = builder.get(); |
86 | if (response.getStatus() != HTTP_OK) { | 86 | if (response.getStatus() != HTTP_OK) { |
87 | log.warn("Failed to get resource {}", access.endpoint() + baseUrl + path); | 87 | log.warn("Failed to get resource {}", access.endpoint() + baseUrl + path); |
88 | return EMPTY_JSON_STRING; | 88 | return EMPTY_JSON_STRING; |
89 | } | 89 | } |
90 | - | 90 | + } catch (javax.ws.rs.ProcessingException e) { |
91 | + return EMPTY_JSON_STRING; | ||
92 | + } | ||
91 | return builder.get(String.class); | 93 | return builder.get(String.class); |
92 | } | 94 | } |
93 | } | 95 | } | ... | ... |
-
Please register or login to post a comment