blob: 18c677fd9194938e01a9e6e4b06fac94f84dcfdd [file] [log] [blame]
Brian O'Connorbd7f8782015-11-19 23:12:37 -08001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2015-present Open Networking Foundation
Brian O'Connorbd7f8782015-11-19 23:12:37 -08003 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package org.onosproject.cli.net;
17
Ray Milkeyd84f89b2018-08-17 14:54:17 -070018import org.apache.karaf.shell.api.action.Argument;
19import org.apache.karaf.shell.api.action.Command;
20import org.apache.karaf.shell.api.action.lifecycle.Service;
Brian O'Connorbd7f8782015-11-19 23:12:37 -080021import org.onosproject.cli.AbstractShellCommand;
22import org.onosproject.incubator.net.domain.IntentDomainId;
23import org.onosproject.incubator.net.domain.IntentDomainService;
24import org.onosproject.incubator.net.domain.TunnelPrimitive;
25import org.onosproject.net.ConnectPoint;
26
27import java.util.NoSuchElementException;
28
29/**
30 * Installs intent domain tunnel primitive.
31 */
Ray Milkeyd84f89b2018-08-17 14:54:17 -070032@Service
Brian O'Connorbd7f8782015-11-19 23:12:37 -080033@Command(scope = "onos", name = "add-domain-tunnel",
34 description = "Installs intent domain tunnel primitive")
35public class AddTunnelCommand extends AbstractShellCommand {
36
37 @Argument(index = 0, name = "one",
38 description = "Port one",
39 required = true, multiValued = false)
40 String oneString = null;
41
42 @Argument(index = 1, name = "two",
43 description = "Port two",
44 required = true, multiValued = false)
45 String twoString = null;
46
47 @Override
Ray Milkeyd84f89b2018-08-17 14:54:17 -070048 protected void doExecute() {
Brian O'Connorbd7f8782015-11-19 23:12:37 -080049 IntentDomainService service = get(IntentDomainService.class);
50
51 ConnectPoint one = ConnectPoint.deviceConnectPoint(oneString);
52 ConnectPoint two = ConnectPoint.deviceConnectPoint(twoString);
53
54 TunnelPrimitive tunnel = new TunnelPrimitive(appId(), one, two);
55
56 // get the first domain (there should only be one)
57 final IntentDomainId domainId;
58 try {
59 domainId = service.getDomains().iterator().next().id();
60 } catch (NoSuchElementException | NullPointerException e) {
61 print("No domains found");
62 return;
63 }
64
65 service.request(domainId, tunnel).forEach(r -> service.submit(domainId, r));
66
67 print("Intent domain tunnel submitted:\n%s", tunnel);
68 }
69}