Jonathan Hart

Remove old XOS-integration application

Change-Id: Ie4207f34714f75618fd3db52dd5c9474d91cb151
...@@ -44,7 +44,6 @@ ...@@ -44,7 +44,6 @@
44 <module>bgprouter</module> 44 <module>bgprouter</module>
45 <module>test</module> 45 <module>test</module>
46 <module>segmentrouting</module> 46 <module>segmentrouting</module>
47 - <module>xos-integration</module>
48 <module>kafka-integration</module> 47 <module>kafka-integration</module>
49 <module>pcep-api</module> 48 <module>pcep-api</module>
50 <module>iptopology-api</module> 49 <module>iptopology-api</module>
......
1 -COMPILE_DEPS = [
2 - '//lib:CORE_DEPS',
3 - '//lib:jersey-client',
4 - '//lib:javax.ws.rs-api',
5 - '//lib:org.apache.karaf.shell.console',
6 - '//cli:onos-cli',
7 - '//utils/rest:onlab-rest',
8 -]
9 -
10 -osgi_jar_with_tests (
11 - deps = COMPILE_DEPS,
12 - import_packages = '*,org.onosproject.cli.net',
13 - resources_root = 'src/main/resources',
14 - resources = glob(['src/main/resources/**']),
15 -)
16 -
17 -onos_app (
18 - title = 'ONOS XOS Integration App',
19 - category = 'Utility',
20 - url = 'http://onosproject.org',
21 - description = 'ONOS XOS integration application.',
22 -)
1 -<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
2 -<!--
3 - ~ Copyright 2015-present Open Networking Laboratory
4 - ~
5 - ~ Licensed under the Apache License, Version 2.0 (the "License");
6 - ~ you may not use this file except in compliance with the License.
7 - ~ You may obtain a copy of the License at
8 - ~
9 - ~ http://www.apache.org/licenses/LICENSE-2.0
10 - ~
11 - ~ Unless required by applicable law or agreed to in writing, software
12 - ~ distributed under the License is distributed on an "AS IS" BASIS,
13 - ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 - ~ See the License for the specific language governing permissions and
15 - ~ limitations under the License.
16 - -->
17 -<features xmlns="http://karaf.apache.org/xmlns/features/v1.2.0" name="${project.artifactId}-${project.version}">
18 - <feature name="${project.artifactId}" version="${project.version}"
19 - description="${project.description}">
20 - <bundle>mvn:org.glassfish.jersey.core/jersey-client/2.22.2</bundle>
21 - <bundle>mvn:${project.groupId}/${project.artifactId}/${project.version}</bundle>
22 - </feature>
23 -</features>
1 -<?xml version="1.0" encoding="UTF-8"?>
2 -<!--
3 - ~ Copyright 2015-present Open Networking Laboratory
4 - ~
5 - ~ Licensed under the Apache License, Version 2.0 (the "License");
6 - ~ you may not use this file except in compliance with the License.
7 - ~ You may obtain a copy of the License at
8 - ~
9 - ~ http://www.apache.org/licenses/LICENSE-2.0
10 - ~
11 - ~ Unless required by applicable law or agreed to in writing, software
12 - ~ distributed under the License is distributed on an "AS IS" BASIS,
13 - ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 - ~ See the License for the specific language governing permissions and
15 - ~ limitations under the License.
16 - -->
17 -<project xmlns="http://maven.apache.org/POM/4.0.0"
18 - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
19 - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
20 - <modelVersion>4.0.0</modelVersion>
21 -
22 - <parent>
23 - <groupId>org.onosproject</groupId>
24 - <artifactId>onos-apps</artifactId>
25 - <version>1.7.0-SNAPSHOT</version>
26 - </parent>
27 -
28 - <artifactId>onos-app-xos-integration</artifactId>
29 - <packaging>bundle</packaging>
30 -
31 - <description>ONOS XOS integration application</description>
32 -
33 - <properties>
34 - <onos.app.name>org.onosproject.xosintegration</onos.app.name>
35 - <onos.app.title>ONOS XOS Integration App</onos.app.title>
36 - <onos.app.category>Utility</onos.app.category>
37 - <onos.app.url>http://onosproject.org</onos.app.url>
38 - <onos.app.readme>ONOS XOS integration application.</onos.app.readme>
39 - </properties>
40 -
41 - <dependencies>
42 - <dependency>
43 - <groupId>org.osgi</groupId>
44 - <artifactId>org.osgi.compendium</artifactId>
45 - </dependency>
46 - <dependency>
47 - <groupId>org.glassfish.jersey.core</groupId>
48 - <artifactId>jersey-client</artifactId>
49 - <version>2.22.2</version>
50 - </dependency>
51 - <dependency>
52 - <groupId>org.onosproject</groupId>
53 - <artifactId>onos-cli</artifactId>
54 - <version>${project.version}</version>
55 - </dependency>
56 - <dependency>
57 - <groupId>org.osgi</groupId>
58 - <artifactId>org.osgi.core</artifactId>
59 - </dependency>
60 - <dependency>
61 - <groupId>org.apache.karaf.shell</groupId>
62 - <artifactId>org.apache.karaf.shell.console</artifactId>
63 - </dependency>
64 - <dependency>
65 - <groupId>org.onosproject</groupId>
66 - <artifactId>onlab-misc</artifactId>
67 - </dependency>
68 - </dependencies>
69 -
70 -</project>
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.xosintegration;
17 -
18 -import com.eclipsesource.json.JsonArray;
19 -import com.eclipsesource.json.JsonObject;
20 -import com.google.common.collect.Maps;
21 -import org.apache.felix.scr.annotations.Activate;
22 -import org.apache.felix.scr.annotations.Component;
23 -import org.apache.felix.scr.annotations.Deactivate;
24 -import org.apache.felix.scr.annotations.Modified;
25 -import org.apache.felix.scr.annotations.Property;
26 -import org.apache.felix.scr.annotations.Reference;
27 -import org.apache.felix.scr.annotations.ReferenceCardinality;
28 -import org.apache.felix.scr.annotations.Service;
29 -import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature;
30 -import org.onlab.packet.VlanId;
31 -import org.onlab.util.Tools;
32 -import org.onosproject.cfg.ComponentConfigService;
33 -import org.onosproject.core.ApplicationId;
34 -import org.onosproject.core.CoreService;
35 -import org.onosproject.net.ConnectPoint;
36 -import org.onosproject.net.DeviceId;
37 -import org.onosproject.net.PortNumber;
38 -import org.onosproject.net.flow.DefaultTrafficSelector;
39 -import org.onosproject.net.flow.DefaultTrafficTreatment;
40 -import org.onosproject.net.flow.TrafficSelector;
41 -import org.onosproject.net.flow.TrafficTreatment;
42 -import org.onosproject.net.flowobjective.DefaultForwardingObjective;
43 -import org.onosproject.net.flowobjective.FlowObjectiveService;
44 -import org.onosproject.net.flowobjective.ForwardingObjective;
45 -import org.osgi.service.component.ComponentContext;
46 -import org.slf4j.Logger;
47 -
48 -import javax.ws.rs.client.Client;
49 -import javax.ws.rs.client.ClientBuilder;
50 -import javax.ws.rs.client.Entity;
51 -import javax.ws.rs.client.Invocation;
52 -import javax.ws.rs.client.WebTarget;
53 -import javax.ws.rs.core.Response;
54 -import java.util.Dictionary;
55 -import java.util.Map;
56 -import java.util.Set;
57 -import java.util.stream.Collectors;
58 -import java.util.stream.IntStream;
59 -
60 -import static com.google.common.base.Strings.isNullOrEmpty;
61 -import static com.google.common.net.MediaType.JSON_UTF_8;
62 -import static java.net.HttpURLConnection.HTTP_CREATED;
63 -import static java.net.HttpURLConnection.HTTP_NO_CONTENT;
64 -import static java.net.HttpURLConnection.HTTP_OK;
65 -import static org.slf4j.LoggerFactory.getLogger;
66 -
67 -
68 -/**
69 - * XOS interface application.
70 - */
71 -@Component(immediate = true)
72 -@Service
73 -public class OnosXosIntegrationManager implements VoltTenantService {
74 - private static final String XOS_SERVER_ADDRESS_PROPERTY_NAME =
75 - "xosServerAddress";
76 - private static final String XOS_SERVER_PORT_PROPERTY_NAME =
77 - "xosServerPort";
78 - private static final String XOS_PROVIDER_SERVICE_PROPERTY_NAME =
79 - "xosProviderService";
80 -
81 - private static final String TEST_XOS_SERVER_ADDRESS = "10.254.1.22";
82 - private static final int TEST_XOS_SERVER_PORT = 8000;
83 - private static final String XOS_TENANT_BASE_URI = "/xoslib/volttenant/";
84 - private static final int TEST_XOS_PROVIDER_SERVICE = 1;
85 -
86 - private static final int PRIORITY = 50000;
87 - private static final DeviceId FABRIC_DEVICE_ID = DeviceId.deviceId("of:5e3e486e73000187");
88 - private static final PortNumber FABRIC_OLT_CONNECT_POINT = PortNumber.portNumber(2);
89 - private static final PortNumber FABRIC_VCPE_CONNECT_POINT = PortNumber.portNumber(3);
90 - private static final String FABRIC_CONTROLLER_ADDRESS = "10.0.3.136";
91 - private static final int FABRIC_SERVER_PORT = 8181;
92 - private static final String FABRIC_BASE_URI = "/onos/cordfabric/vlans/add";
93 -
94 - private static final DeviceId OLT_DEVICE_ID = DeviceId.deviceId("of:90e2ba82f97791e9");
95 - private static final int OLT_UPLINK_PORT = 129;
96 -
97 - private static final ConnectPoint FABRIC_PORT = new ConnectPoint(
98 - DeviceId.deviceId("of:000090e2ba82f974"),
99 - PortNumber.portNumber(2));
100 -
101 - private final Logger log = getLogger(getClass());
102 - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
103 - protected CoreService coreService;
104 - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
105 - protected ComponentConfigService cfgService;
106 -
107 - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
108 - protected FlowObjectiveService flowObjectiveService;
109 -
110 - @Property(name = XOS_SERVER_ADDRESS_PROPERTY_NAME,
111 - value = TEST_XOS_SERVER_ADDRESS,
112 - label = "XOS Server address")
113 - protected String xosServerAddress = TEST_XOS_SERVER_ADDRESS;
114 -
115 - @Property(name = XOS_SERVER_PORT_PROPERTY_NAME,
116 - intValue = TEST_XOS_SERVER_PORT,
117 - label = "XOS Server port")
118 - protected int xosServerPort = TEST_XOS_SERVER_PORT;
119 -
120 - @Property(name = XOS_PROVIDER_SERVICE_PROPERTY_NAME,
121 - intValue = TEST_XOS_PROVIDER_SERVICE,
122 - label = "XOS Provider Service")
123 - protected int xosProviderService = TEST_XOS_PROVIDER_SERVICE;
124 -
125 - private ApplicationId appId;
126 - private Map<String, ConnectPoint> nodeToPort;
127 - private Map<Long, Short> portToVlan;
128 - private Map<ConnectPoint, String> portToSsid;
129 -
130 - @Activate
131 - public void activate(ComponentContext context) {
132 - log.info("XOS app is starting");
133 - cfgService.registerProperties(getClass());
134 - appId = coreService.registerApplication("org.onosproject.xosintegration");
135 -
136 - setupMap();
137 -
138 - readComponentConfiguration(context);
139 -
140 - log.info("XOS({}) started", appId.id());
141 - }
142 -
143 - @Deactivate
144 - public void deactivate() {
145 - cfgService.unregisterProperties(getClass(), false);
146 - log.info("XOS({}) stopped", appId.id());
147 - }
148 -
149 - @Modified
150 - public void modified(ComponentContext context) {
151 - readComponentConfiguration(context);
152 - }
153 -
154 - private void setupMap() {
155 - nodeToPort = Maps.newHashMap();
156 -
157 - nodeToPort.put("cordcompute01.onlab.us", new ConnectPoint(FABRIC_DEVICE_ID,
158 - PortNumber.portNumber(4)));
159 -
160 - nodeToPort.put("cordcompute02.onlab.us", new ConnectPoint(FABRIC_DEVICE_ID,
161 - PortNumber.portNumber(3)));
162 -
163 - portToVlan = Maps.newHashMap();
164 - portToVlan.putIfAbsent(1L, (short) 201);
165 - portToVlan.putIfAbsent(6L, (short) 401);
166 -
167 - portToSsid = Maps.newHashMap();
168 - portToSsid.put(new ConnectPoint(OLT_DEVICE_ID, PortNumber.portNumber(1)), "0");
169 - portToSsid.put(new ConnectPoint(FABRIC_DEVICE_ID, PortNumber.portNumber(6)), "1");
170 - }
171 -
172 - /**
173 - * Converts a JSON representation of a tenant into a tenant object.
174 - *
175 - * @param jsonTenant JSON object representing the tenant
176 - * @return volt tenant object
177 - */
178 - private VoltTenant jsonToTenant(JsonObject jsonTenant) {
179 - return VoltTenant.builder()
180 - .withHumanReadableName(jsonTenant.get("humanReadableName").asString())
181 - .withId(jsonTenant.get("id").asInt())
182 - .withProviderService(jsonTenant.get("provider_service").asInt())
183 - .withServiceSpecificId(jsonTenant.get("service_specific_id").asString())
184 - .withVlanId(jsonTenant.get("vlan_id").asString())
185 - .build();
186 - }
187 -
188 - /**
189 - * Converts a tenant object into a JSON string.
190 - *
191 - * @param tenant volt tenant object to convert
192 - * @return JSON string for the tenant
193 - */
194 - private String tenantToJson(VoltTenant tenant) {
195 - return "{"
196 - + "\"humanReadableName\": \"" + tenant.humanReadableName() + "\","
197 - + "\"id\": \"" + tenant.id() + "\","
198 - + "\"provider_service\": \"" + tenant.providerService() + "\","
199 - + "\"service_specific_id\": \"" + tenant.serviceSpecificId() + "\","
200 - + "\"vlan_id\": \"" + tenant.vlanId() + "\""
201 - + "}";
202 - }
203 -
204 - /**
205 - * Gets a client web resource builder for the base XOS REST API
206 - * with no additional URI.
207 - *
208 - * @return web resource builder
209 - * @deprecated in Cardinal Release
210 - */
211 - @Deprecated
212 - private Invocation.Builder getClientBuilder() {
213 - return getClientBuilder("");
214 - }
215 -
216 - /**
217 - * Gets a client web resource builder for the base XOS REST API
218 - * with an optional additional URI.
219 - *
220 - * @return web resource builder
221 - * @deprecated in Cardinal Release
222 - */
223 - @Deprecated
224 - private Invocation.Builder getClientBuilder(String uri) {
225 - String baseUrl = "http://" + xosServerAddress + ":"
226 - + Integer.toString(xosServerPort);
227 - Client client = ClientBuilder.newClient();
228 - client.register(HttpAuthenticationFeature.basic("padmin@vicci.org", "letmein"));
229 - WebTarget wt = client.target(baseUrl
230 - + XOS_TENANT_BASE_URI + uri);
231 - return wt.request(JSON_UTF_8.toString());
232 - }
233 -
234 - /**
235 - * Performs a REST GET operation on the base XOS REST URI.
236 - *
237 - * @return JSON string fetched by the GET operation
238 - * @deprecated in Cardinal Release
239 - */
240 - @Deprecated
241 - private String getRest() {
242 - return getRest("");
243 - }
244 -
245 - /**
246 - * Performs a REST GET operation on the base XOS REST URI with
247 - * an optional additional URI.
248 - *
249 - * @return JSON string fetched by the GET operation
250 - * @deprecated in Cardinal Release
251 - */
252 - @Deprecated
253 - private String getRest(String uri) {
254 - Invocation.Builder builder = getClientBuilder(uri);
255 - Response response = builder.get();
256 -
257 - if (response.getStatus() != HTTP_OK) {
258 - log.info("REST GET request returned error code {}",
259 - response.getStatus());
260 - }
261 - String jsonString = builder.get(String.class);
262 - log.info("JSON read:\n{}", jsonString);
263 -
264 - return jsonString;
265 - }
266 -
267 - /**
268 - * Performs a REST POST operation of a json string on the base
269 - * XOS REST URI with an optional additional URI.
270 - *
271 - * @param json JSON string to post
272 - * @deprecated in Cardinal Release
273 - */
274 - @Deprecated
275 - private String postRest(String json) {
276 - Invocation.Builder builder = getClientBuilder();
277 - Response response = builder.post(Entity.json(json));
278 -
279 - if (response.getStatus() != HTTP_CREATED) {
280 - log.info("REST POST request returned error code {}",
281 - response.getStatus());
282 - }
283 - return builder.post(Entity.json(json), String.class);
284 - }
285 -
286 - /**
287 - * Performs a REST DELETE operation on the base
288 - * XOS REST URI with an optional additional URI.
289 - *
290 - * @param uri optional additional URI
291 - * @deprecated in Cardinal Release
292 - */
293 - @Deprecated
294 - private void deleteRest(String uri) {
295 - Invocation.Builder builder = getClientBuilder(uri);
296 - Response response = builder.delete();
297 -
298 - if (response.getStatus() != HTTP_NO_CONTENT) {
299 - log.info("REST DELETE request returned error code {}",
300 - response.getStatus());
301 - }
302 - }
303 -
304 - /**
305 - * Deletes the tenant with the given ID.
306 - *
307 - * @param tenantId ID of tenant to delete
308 - */
309 - private void deleteTenant(long tenantId) {
310 - deleteRest(Long.toString(tenantId));
311 - }
312 -
313 - @Override
314 - public Set<VoltTenant> getAllTenants() {
315 - String jsonString = getRest();
316 -
317 - JsonArray voltTenantItems = JsonArray.readFrom(jsonString);
318 -
319 - return IntStream.range(0, voltTenantItems.size())
320 - .mapToObj(index -> jsonToTenant(voltTenantItems.get(index).asObject()))
321 - .collect(Collectors.toSet());
322 - }
323 -
324 - @Override
325 - public void removeTenant(long id) {
326 - deleteTenant(id);
327 - }
328 -
329 - @Override
330 - public VoltTenant addTenant(VoltTenant newTenant) {
331 - long providerServiceId = newTenant.providerService();
332 - if (providerServiceId == -1) {
333 - providerServiceId = xosProviderService;
334 - }
335 -
336 - PortNumber onuPort = newTenant.port().port();
337 - VlanId subscriberVlan;
338 - try {
339 - subscriberVlan = VlanId.vlanId(portToVlan.get(onuPort.toLong()));
340 - } catch (NullPointerException npe) {
341 - log.error("No matched port in portToVlan map", npe);
342 - return newTenant;
343 - }
344 -
345 - VoltTenant tenantToCreate = VoltTenant.builder()
346 - .withProviderService(providerServiceId)
347 - .withServiceSpecificId(portToSsid.get(newTenant.port()))
348 - .withVlanId(String.valueOf(subscriberVlan.toShort()))
349 - .withPort(newTenant.port())
350 - .build();
351 - String json = tenantToJson(tenantToCreate);
352 -
353 -
354 - provisionVlanOnPort(OLT_DEVICE_ID, OLT_UPLINK_PORT, onuPort, subscriberVlan.toShort());
355 -
356 - String retJson = postRest(json);
357 -
358 - fetchCpeLocation(tenantToCreate, retJson);
359 -
360 - return newTenant;
361 - }
362 -
363 - private void fetchCpeLocation(VoltTenant newTenant, String jsonString) {
364 - JsonObject json = JsonObject.readFrom(jsonString);
365 -
366 - if (json.get("computeNodeName") != null) {
367 - ConnectPoint point = nodeToPort.get(json.get("computeNodeName").asString());
368 - //ConnectPoint fromPoint = newTenant.port();
369 - ConnectPoint oltPort = new ConnectPoint(FABRIC_DEVICE_ID, FABRIC_OLT_CONNECT_POINT);
370 -
371 - provisionFabric(VlanId.vlanId(Short.parseShort(newTenant.vlanId())),
372 - point, oltPort);
373 - }
374 -
375 - }
376 -
377 - @Override
378 - public VoltTenant getTenant(long id) {
379 - String jsonString = getRest(Long.toString(id));
380 - JsonObject jsonTenant = JsonObject.readFrom(jsonString);
381 - if (jsonTenant.get("id") != null) {
382 - return jsonToTenant(jsonTenant);
383 - } else {
384 - return null;
385 - }
386 - }
387 -
388 - private void provisionVlanOnPort(DeviceId deviceId, int uplinkPort, PortNumber p, short vlanId) {
389 -
390 - TrafficSelector upstream = DefaultTrafficSelector.builder()
391 - .matchVlanId(VlanId.ANY)
392 - .matchInPort(p)
393 - .build();
394 -
395 - TrafficSelector downstream = DefaultTrafficSelector.builder()
396 - .matchVlanId(VlanId.vlanId(vlanId))
397 - .matchInPort(PortNumber.portNumber(uplinkPort))
398 - .build();
399 -
400 - TrafficTreatment upstreamTreatment = DefaultTrafficTreatment.builder()
401 - .setVlanId(VlanId.vlanId(vlanId))
402 - .setOutput(PortNumber.portNumber(uplinkPort))
403 - .build();
404 -
405 - TrafficTreatment downstreamTreatment = DefaultTrafficTreatment.builder()
406 - .popVlan()
407 - .setOutput(p)
408 - .build();
409 -
410 -
411 - ForwardingObjective upFwd = DefaultForwardingObjective.builder()
412 - .withFlag(ForwardingObjective.Flag.VERSATILE)
413 - .withPriority(1000)
414 - .makePermanent()
415 - .withSelector(upstream)
416 - .fromApp(appId)
417 - .withTreatment(upstreamTreatment)
418 - .add();
419 -
420 - ForwardingObjective downFwd = DefaultForwardingObjective.builder()
421 - .withFlag(ForwardingObjective.Flag.VERSATILE)
422 - .withPriority(1000)
423 - .makePermanent()
424 - .withSelector(downstream)
425 - .fromApp(appId)
426 - .withTreatment(downstreamTreatment)
427 - .add();
428 -
429 - flowObjectiveService.forward(deviceId, upFwd);
430 - flowObjectiveService.forward(deviceId, downFwd);
431 -
432 - }
433 -
434 - private void provisionDataPlane(VoltTenant tenant) {
435 - VlanId vlan = VlanId.vlanId(Short.parseShort(tenant.vlanId()));
436 -
437 - TrafficSelector fromGateway = DefaultTrafficSelector.builder()
438 - .matchInPhyPort(tenant.port().port())
439 - .build();
440 -
441 - TrafficSelector fromFabric = DefaultTrafficSelector.builder()
442 - .matchInPhyPort(FABRIC_PORT.port())
443 - .matchVlanId(vlan)
444 - .build();
445 -
446 - TrafficTreatment toFabric = DefaultTrafficTreatment.builder()
447 - .pushVlan()
448 - .setVlanId(vlan)
449 - .setOutput(FABRIC_PORT.port())
450 - .build();
451 -
452 - TrafficTreatment toGateway = DefaultTrafficTreatment.builder()
453 - .popVlan()
454 - .setOutput(tenant.port().port())
455 - .build();
456 -
457 - ForwardingObjective forwardToFabric = DefaultForwardingObjective.builder()
458 - .withFlag(ForwardingObjective.Flag.VERSATILE)
459 - .withPriority(PRIORITY)
460 - .makePermanent()
461 - .fromApp(appId)
462 - .withSelector(fromGateway)
463 - .withTreatment(toFabric)
464 - .add();
465 -
466 - ForwardingObjective forwardToGateway = DefaultForwardingObjective.builder()
467 - .withFlag(ForwardingObjective.Flag.VERSATILE)
468 - .withPriority(PRIORITY)
469 - .makePermanent()
470 - .fromApp(appId)
471 - .withSelector(fromFabric)
472 - .withTreatment(toGateway)
473 - .add();
474 -
475 - flowObjectiveService.forward(FABRIC_PORT.deviceId(), forwardToFabric);
476 - flowObjectiveService.forward(FABRIC_PORT.deviceId(), forwardToGateway);
477 - }
478 -
479 - private void provisionFabric(VlanId vlanId, ConnectPoint point, ConnectPoint fromPoint) {
480 -
481 - long vlan = vlanId.toShort();
482 -
483 - JsonObject node = new JsonObject();
484 - node.add("vlan", vlan);
485 - if (vlan == 201) {
486 - node.add("iptv", true);
487 - } else {
488 - node.add("iptv", false);
489 - }
490 - JsonArray array = new JsonArray();
491 - JsonObject cp1 = new JsonObject();
492 - JsonObject cp2 = new JsonObject();
493 - cp1.add("device", point.deviceId().toString());
494 - cp1.add("port", point.port().toLong());
495 - cp2.add("device", fromPoint.deviceId().toString());
496 - cp2.add("port", fromPoint.port().toLong());
497 - array.add(cp1);
498 - array.add(cp2);
499 - node.add("ports", array);
500 -
501 -
502 - String baseUrl = "http://" + FABRIC_CONTROLLER_ADDRESS + ":"
503 - + Integer.toString(FABRIC_SERVER_PORT);
504 - Client client = ClientBuilder.newClient();
505 - WebTarget wt = client.target(baseUrl + FABRIC_BASE_URI);
506 - Invocation.Builder builder = wt.request(JSON_UTF_8.toString());
507 -
508 - builder.post(Entity.json(node.toString()));
509 - }
510 -
511 - /**
512 - * Extracts properties from the component configuration context.
513 - *
514 - * @param context the component context
515 - */
516 - private void readComponentConfiguration(ComponentContext context) {
517 - Dictionary<?, ?> properties = context.getProperties();
518 -
519 - String newXosServerAddress =
520 - Tools.get(properties, XOS_SERVER_ADDRESS_PROPERTY_NAME);
521 - if (!isNullOrEmpty(newXosServerAddress)) {
522 - xosServerAddress = newXosServerAddress;
523 - }
524 -
525 - String newXosServerPortString =
526 - Tools.get(properties, XOS_SERVER_PORT_PROPERTY_NAME);
527 - if (!isNullOrEmpty(newXosServerPortString)) {
528 - xosServerPort = Integer.parseInt(newXosServerPortString);
529 - }
530 -
531 - String newXosProviderServiceString =
532 - Tools.get(properties, XOS_PROVIDER_SERVICE_PROPERTY_NAME);
533 - if (!isNullOrEmpty(newXosProviderServiceString)) {
534 - xosProviderService = Integer.parseInt(newXosProviderServiceString);
535 - }
536 - }
537 -}
538 -
539 -
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.xosintegration;
17 -
18 -import com.google.common.base.MoreObjects;
19 -import org.onosproject.net.ConnectPoint;
20 -
21 -public final class VoltTenant {
22 -
23 - private final String humanReadableName;
24 - private final long id;
25 - private final long providerService;
26 - private final String serviceSpecificId;
27 - private final String vlanId;
28 - private final ConnectPoint port;
29 -
30 - /**
31 - * Constructs a vOLT tenant object.
32 - *
33 - * @param humanReadableName name string
34 - * @param id identifier for the tenant
35 - * @param providerService provider service ID
36 - * @param serviceSpecificId id for the user
37 - * @param vlanId vlan id for the user
38 - */
39 - private VoltTenant(String humanReadableName, long id, long providerService,
40 - String serviceSpecificId, String vlanId, ConnectPoint port) {
41 - this.humanReadableName = humanReadableName;
42 - this.id = id;
43 - this.providerService = providerService;
44 - this.serviceSpecificId = serviceSpecificId;
45 - this.vlanId = vlanId;
46 - this.port = port;
47 - }
48 -
49 - /**
50 - * Fetches a builder to make a tenant.
51 - *
52 - * @return tenant builder
53 - */
54 - public static Builder builder() {
55 - return new Builder();
56 - }
57 -
58 - /**
59 - * Fetches the name of the tenant.
60 - *
61 - * @return human readable name
62 - */
63 - public String humanReadableName() {
64 - return humanReadableName;
65 - }
66 -
67 - /**
68 - * Fetches the ID of the tenant object.
69 - *
70 - * @return ID of tenant object.
71 - */
72 - public long id() {
73 - return id;
74 - }
75 -
76 - /**
77 - * Fetches the identifier for the provider service.
78 - *
79 - * @return provider service ID
80 - */
81 - public long providerService() {
82 - return providerService;
83 - }
84 -
85 - /**
86 - * Fetches the server specific ID (user id).
87 - *
88 - * @return server specific ID
89 - */
90 - public String serviceSpecificId() {
91 - return serviceSpecificId;
92 - }
93 -
94 - /**
95 - * Fetches the vlan id for this tenant.
96 - *
97 - * @return VLAN ID
98 - */
99 - public String vlanId() {
100 - return vlanId;
101 - }
102 -
103 - public ConnectPoint port() {
104 - return port;
105 - }
106 -
107 - /**
108 - * Builder class to allow callers to assemble tenants.
109 - */
110 -
111 - public static final class Builder {
112 - private String humanReadableName = "unknown";
113 - private long id = 0;
114 - private long providerService = -1;
115 - private String serviceSpecificId = "unknown";
116 - private String vlanId = "unknown";
117 - private ConnectPoint port;
118 -
119 - /**
120 - * Sets the name string for the tenant.
121 - *
122 - * @param humanReadableName name
123 - * @return self
124 - */
125 - public Builder withHumanReadableName(String humanReadableName) {
126 - this.humanReadableName = humanReadableName;
127 - return this;
128 - }
129 -
130 - /**
131 - * Sets the identifier for the tenant.
132 - *
133 - * @param id identifier for the tenant
134 - * @return self
135 - */
136 - public Builder withId(long id) {
137 - this.id = id;
138 - return this;
139 - }
140 -
141 - /**
142 - * Sets the server specific id (user id) for the tenant.
143 - *
144 - * @param serviceSpecificId server specific (user) id
145 - * @return self
146 - */
147 - public Builder withServiceSpecificId(String serviceSpecificId) {
148 - this.serviceSpecificId = serviceSpecificId;
149 - return this;
150 - }
151 -
152 - /**
153 - * Sets the VLAN ID for the tenant.
154 - *
155 - * @param vlanId VLAN ID
156 - * @return self
157 - */
158 - public Builder withVlanId(String vlanId) {
159 - this.vlanId = vlanId;
160 - return this;
161 - }
162 -
163 - /**
164 - * Sets the provider service ID.
165 - *
166 - * @param providerService provider service ID
167 - * @return self
168 - */
169 - public Builder withProviderService(long providerService) {
170 - this.providerService = providerService;
171 - return this;
172 - }
173 -
174 - public Builder withPort(ConnectPoint port) {
175 - this.port = port;
176 - return this;
177 - }
178 -
179 - /**
180 - * Constructs a VoltTenant from the assembled data.
181 - *
182 - * @return constructed tenant object
183 - */
184 - public VoltTenant build() {
185 - return new VoltTenant(humanReadableName, id, providerService,
186 - serviceSpecificId, vlanId, port);
187 - }
188 - }
189 -
190 - @Override
191 - public String toString() {
192 - return MoreObjects.toStringHelper(getClass())
193 - .add("humanReadableName", humanReadableName())
194 - .add("id", id())
195 - .add("providerService", providerService())
196 - .add("serviceSpecificId", serviceSpecificId())
197 - .add("vlanId", vlanId())
198 - .add("port", port())
199 - .toString();
200 - }
201 -
202 -}
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.xosintegration;
17 -
18 -import java.util.Set;
19 -
20 -public interface VoltTenantService {
21 -
22 - /**
23 - * Queries all the tenants.
24 - *
25 - * @return Set of all of the tenants
26 - */
27 - Set<VoltTenant> getAllTenants();
28 -
29 - /**
30 - * Removes a tenant given its ID.
31 - *
32 - * @param id if od tenant to remove.
33 - */
34 - void removeTenant(long id);
35 -
36 - /**
37 - * Creates a new tenant and adds it to the XOS instance.
38 - *
39 - * @param newTenant tenant to add
40 - * @return the added tenant
41 - */
42 - VoltTenant addTenant(VoltTenant newTenant);
43 -
44 - /**
45 - * Gets a single tenant for the given ID.
46 - *
47 - * @param id ID of the tenant to fetch
48 - * @return tenant that was fetched
49 - */
50 - VoltTenant getTenant(long id);
51 -}
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.xosintegration.cli;
17 -
18 -import java.util.List;
19 -
20 -import org.onosproject.cli.AbstractChoicesCompleter;
21 -import org.onosproject.xosintegration.VoltTenant;
22 -import org.onosproject.xosintegration.VoltTenantService;
23 -import static java.util.stream.Collectors.toList;
24 -
25 -import static org.onosproject.cli.AbstractShellCommand.get;
26 -
27 -
28 -/**
29 - * Application command completer.
30 - */
31 -public class TenantIdCompleter extends AbstractChoicesCompleter {
32 - @Override
33 - public List<String> choices() {
34 - VoltTenantService service = get(VoltTenantService.class);
35 -
36 - return service.getAllTenants().stream()
37 - .map(VoltTenant::id)
38 - .map(Object::toString)
39 - .collect(toList());
40 -
41 - }
42 -
43 -}
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.xosintegration.cli;
17 -
18 -import org.apache.karaf.shell.commands.Argument;
19 -import org.apache.karaf.shell.commands.Command;
20 -import org.onosproject.cli.AbstractShellCommand;
21 -import org.onosproject.xosintegration.VoltTenantService;
22 -
23 -/**
24 - * CLI command to remove an existing tenant from the system.
25 - */
26 -@Command(scope = "onos", name = "remove-tenant",
27 - description = "Removes a tenant")
28 -public class VoltRemoveTenantCommand extends AbstractShellCommand {
29 -
30 - @Argument(index = 0, name = "tenant",
31 - description = "Tenant ID",
32 - required = true, multiValued = false)
33 - String tenantIdString = null;
34 -
35 - @Override
36 - protected void execute() {
37 - VoltTenantService service = get(VoltTenantService.class);
38 -
39 - service.removeTenant(Long.parseLong(tenantIdString));
40 - }
41 -}
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.xosintegration.cli;
17 -
18 -import org.apache.karaf.shell.commands.Argument;
19 -import org.apache.karaf.shell.commands.Command;
20 -import org.onosproject.cli.AbstractShellCommand;
21 -import org.onosproject.net.ConnectPoint;
22 -import org.onosproject.xosintegration.VoltTenant;
23 -import org.onosproject.xosintegration.VoltTenantService;
24 -
25 -/**
26 - * CLI command to create a new tenant.
27 - */
28 -@Command(scope = "onos", name = "add-tenant",
29 - description = "Lists the inventory of VOLT tenants and their contents")
30 -public class VoltTenantsCreateCommand extends AbstractShellCommand {
31 -
32 - @Argument(index = 0, name = "service specific ID",
33 - description = "service specific ID",
34 - required = true, multiValued = false)
35 - String serviceSpecificId;
36 -
37 - @Argument(index = 1, name = "vlan ID",
38 - description = "vlan ID",
39 - required = true, multiValued = false)
40 - String vlanId;
41 -
42 - @Argument(index = 2, name = "port",
43 - description = "Port",
44 - required = true, multiValued = false)
45 - String port;
46 -
47 - @Override
48 - protected void execute() {
49 - VoltTenantService service = get(VoltTenantService.class);
50 -
51 - VoltTenant newTenant = VoltTenant.builder()
52 - .withServiceSpecificId(serviceSpecificId)
53 - .withVlanId(vlanId)
54 - .withPort(ConnectPoint.deviceConnectPoint(port))
55 - .build();
56 -
57 - service.addTenant(newTenant);
58 - }
59 -}
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.xosintegration.cli;
17 -
18 -import java.util.Set;
19 -
20 -import org.apache.karaf.shell.commands.Argument;
21 -import org.apache.karaf.shell.commands.Command;
22 -import org.onosproject.cli.AbstractShellCommand;
23 -import org.onosproject.xosintegration.VoltTenant;
24 -import org.onosproject.xosintegration.VoltTenantService;
25 -
26 -/**
27 - * CLI command for listing VOLT tenant objects.
28 - */
29 -
30 -/**
31 - * CLI command to list the existing tenants.
32 - */
33 -@Command(scope = "onos", name = "tenants",
34 - description = "Lists the inventory of VOLT tenants and their contents")
35 -public class VoltTenantsListCommand extends AbstractShellCommand {
36 -
37 - @Argument(index = 0, name = "tenantId",
38 - description = "Tenant ID",
39 - required = false, multiValued = false)
40 - private String tenantId = null;
41 -
42 - @Override
43 - protected void execute() {
44 - VoltTenantService service = get(VoltTenantService.class);
45 -
46 - if (tenantId != null) {
47 - VoltTenant tenant = service.getTenant(Long.parseLong(tenantId));
48 - if (tenant != null) {
49 - print(tenant.toString());
50 - } else {
51 - error("Tenant not found {}", tenantId);
52 - }
53 - } else {
54 - Set<VoltTenant> tenants = service.getAllTenants();
55 - for (VoltTenant tenant : tenants) {
56 - print(tenant.toString());
57 - }
58 - }
59 - }
60 -
61 -}
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 -
17 -/**
18 - * XOS integration application CLI commands.
19 - */
20 -package org.onosproject.xosintegration.cli;
...\ No newline at end of file ...\ No newline at end of file
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 -
17 -/**
18 - * XOS integration application which relies on XOS REST APIs to manage VMs.
19 - */
20 -package org.onosproject.xosintegration;
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 -<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0">
17 - <command-bundle xmlns="http://karaf.apache.org/xmlns/shell/v1.1.0">
18 - <command>
19 - <action class="org.onosproject.xosintegration.cli.VoltTenantsListCommand"/>
20 - <completers>
21 - <ref component-id="tenantIdCompleter"/>
22 - <null/>
23 - </completers>
24 - </command>
25 - <command>
26 - <action class="org.onosproject.xosintegration.cli.VoltTenantsCreateCommand"/>
27 - <completers>
28 - <ref component-id="placeholderCompleter"/>
29 - <ref component-id="placeholderCompleter"/>
30 - <ref component-id="connectPointCompleter"/>
31 - <null/>
32 - </completers>
33 - </command>
34 - <command>
35 - <action class="org.onosproject.xosintegration.cli.VoltRemoveTenantCommand"/>
36 - <completers>
37 - <ref component-id="tenantIdCompleter"/>
38 - <null/>
39 - </completers>
40 - </command>
41 - </command-bundle>
42 - <bean id="tenantIdCompleter" class="org.onosproject.xosintegration.cli.TenantIdCompleter"/>
43 - <bean id="placeholderCompleter" class="org.onosproject.cli.PlaceholderCompleter"/>
44 - <bean id="connectPointCompleter" class="org.onosproject.cli.net.ConnectPointCompleter"/>
45 -</blueprint>