blob: 93a8f7a48d8843566fa6e4a0019a8cc02b762c31 [file] [log] [blame]
Brian O'Connorbd7f8782015-11-19 23:12:37 -08001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2015-present Open Networking Laboratory
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
18import org.apache.karaf.shell.commands.Argument;
19import org.apache.karaf.shell.commands.Command;
20import org.onosproject.cli.AbstractShellCommand;
21import org.onosproject.incubator.net.domain.IntentDomainId;
22import org.onosproject.incubator.net.domain.IntentDomainService;
23import org.onosproject.incubator.net.domain.TunnelPrimitive;
24import org.onosproject.net.ConnectPoint;
25
26import java.util.NoSuchElementException;
27
28/**
29 * Installs intent domain tunnel primitive.
30 */
31@Command(scope = "onos", name = "add-domain-tunnel",
32 description = "Installs intent domain tunnel primitive")
33public class AddTunnelCommand extends AbstractShellCommand {
34
35 @Argument(index = 0, name = "one",
36 description = "Port one",
37 required = true, multiValued = false)
38 String oneString = null;
39
40 @Argument(index = 1, name = "two",
41 description = "Port two",
42 required = true, multiValued = false)
43 String twoString = null;
44
45 @Override
46 protected void execute() {
47 IntentDomainService service = get(IntentDomainService.class);
48
49 ConnectPoint one = ConnectPoint.deviceConnectPoint(oneString);
50 ConnectPoint two = ConnectPoint.deviceConnectPoint(twoString);
51
52 TunnelPrimitive tunnel = new TunnelPrimitive(appId(), one, two);
53
54 // get the first domain (there should only be one)
55 final IntentDomainId domainId;
56 try {
57 domainId = service.getDomains().iterator().next().id();
58 } catch (NoSuchElementException | NullPointerException e) {
59 print("No domains found");
60 return;
61 }
62
63 service.request(domainId, tunnel).forEach(r -> service.submit(domainId, r));
64
65 print("Intent domain tunnel submitted:\n%s", tunnel);
66 }
67}