Brian Stanke | 11f6d53 | 2016-07-05 16:17:59 -0400 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Foundation |
Brian Stanke | 11f6d53 | 2016-07-05 16:17:59 -0400 | [diff] [blame] | 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 | package org.onosproject.cli.net.vnet; |
| 18 | |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 19 | import org.apache.karaf.shell.api.action.Argument; |
| 20 | import org.apache.karaf.shell.api.action.Command; |
Ray Milkey | 0068fd0 | 2018-10-11 15:45:39 -0700 | [diff] [blame] | 21 | import org.apache.karaf.shell.api.action.Completion; |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 22 | import org.apache.karaf.shell.api.action.lifecycle.Service; |
Brian Stanke | 11f6d53 | 2016-07-05 16:17:59 -0400 | [diff] [blame] | 23 | import org.onosproject.cli.net.ConnectivityIntentCommand; |
| 24 | import org.onosproject.incubator.net.virtual.NetworkId; |
| 25 | import org.onosproject.incubator.net.virtual.VirtualNetworkIntent; |
| 26 | import org.onosproject.incubator.net.virtual.VirtualNetworkService; |
| 27 | import org.onosproject.net.ConnectPoint; |
| 28 | import org.onosproject.net.flow.TrafficSelector; |
| 29 | import org.onosproject.net.flow.TrafficTreatment; |
| 30 | import org.onosproject.net.intent.Constraint; |
| 31 | import org.onosproject.net.intent.Intent; |
| 32 | import org.onosproject.net.intent.IntentService; |
| 33 | |
| 34 | import java.util.List; |
| 35 | |
| 36 | /** |
| 37 | * Installs virtual network intents. |
| 38 | */ |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 39 | @Service |
Brian Stanke | 11f6d53 | 2016-07-05 16:17:59 -0400 | [diff] [blame] | 40 | @Command(scope = "onos", name = "add-vnet-intent", |
| 41 | description = "Installs virtual network connectivity intent") |
| 42 | public class VirtualNetworkIntentCreateCommand extends ConnectivityIntentCommand { |
| 43 | |
| 44 | @Argument(index = 0, name = "networkId", description = "Network ID", |
| 45 | required = true, multiValued = false) |
Ray Milkey | 0068fd0 | 2018-10-11 15:45:39 -0700 | [diff] [blame] | 46 | @Completion(VirtualNetworkCompleter.class) |
Brian Stanke | 11f6d53 | 2016-07-05 16:17:59 -0400 | [diff] [blame] | 47 | Long networkId = null; |
| 48 | |
| 49 | @Argument(index = 1, name = "ingressDevice", |
| 50 | description = "Ingress Device/Port Description", |
| 51 | required = true, multiValued = false) |
| 52 | String ingressDeviceString = null; |
| 53 | |
| 54 | @Argument(index = 2, name = "egressDevice", |
| 55 | description = "Egress Device/Port Description", |
| 56 | required = true, multiValued = false) |
| 57 | String egressDeviceString = null; |
| 58 | |
| 59 | @Override |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 60 | protected void doExecute() { |
Brian Stanke | 11f6d53 | 2016-07-05 16:17:59 -0400 | [diff] [blame] | 61 | VirtualNetworkService service = get(VirtualNetworkService.class); |
| 62 | IntentService virtualNetworkIntentService = service.get(NetworkId.networkId(networkId), IntentService.class); |
| 63 | |
| 64 | ConnectPoint ingress = ConnectPoint.deviceConnectPoint(ingressDeviceString); |
| 65 | ConnectPoint egress = ConnectPoint.deviceConnectPoint(egressDeviceString); |
| 66 | |
| 67 | TrafficSelector selector = buildTrafficSelector(); |
| 68 | TrafficTreatment treatment = buildTrafficTreatment(); |
| 69 | |
| 70 | List<Constraint> constraints = buildConstraints(); |
| 71 | |
| 72 | Intent intent = VirtualNetworkIntent.builder() |
| 73 | .networkId(NetworkId.networkId(networkId)) |
| 74 | .appId(appId()) |
| 75 | .key(key()) |
| 76 | .selector(selector) |
| 77 | .treatment(treatment) |
| 78 | .ingressPoint(ingress) |
| 79 | .egressPoint(egress) |
| 80 | .constraints(constraints) |
| 81 | .priority(priority()) |
| 82 | .build(); |
| 83 | virtualNetworkIntentService.submit(intent); |
| 84 | print("Virtual intent submitted:\n%s", intent.toString()); |
| 85 | } |
| 86 | } |