Brian O'Connor | bd7f878 | 2015-11-19 23:12:37 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 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.cli.net; |
| 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.incubator.net.domain.IntentDomainId; |
| 22 | import org.onosproject.incubator.net.domain.IntentDomainService; |
| 23 | import org.onosproject.incubator.net.domain.TunnelPrimitive; |
| 24 | import org.onosproject.net.ConnectPoint; |
| 25 | |
| 26 | import 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") |
| 33 | public 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 | } |