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