blob: f57f3f7ec7d3698058934e65a44bb04698370992 [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
Ray Milkeyd84f89b2018-08-17 14:54:17 -070019import org.apache.karaf.shell.api.action.Argument;
20import org.apache.karaf.shell.api.action.Command;
Ray Milkey0068fd02018-10-11 15:45:39 -070021import org.apache.karaf.shell.api.action.Completion;
Ray Milkeyd84f89b2018-08-17 14:54:17 -070022import org.apache.karaf.shell.api.action.lifecycle.Service;
Brian Stanke11f6d532016-07-05 16:17:59 -040023import org.onosproject.cli.net.ConnectivityIntentCommand;
24import org.onosproject.incubator.net.virtual.NetworkId;
25import org.onosproject.incubator.net.virtual.VirtualNetworkIntent;
26import org.onosproject.incubator.net.virtual.VirtualNetworkService;
27import org.onosproject.net.ConnectPoint;
28import org.onosproject.net.flow.TrafficSelector;
29import org.onosproject.net.flow.TrafficTreatment;
30import org.onosproject.net.intent.Constraint;
31import org.onosproject.net.intent.Intent;
32import org.onosproject.net.intent.IntentService;
33
34import java.util.List;
35
36/**
37 * Installs virtual network intents.
38 */
Ray Milkeyd84f89b2018-08-17 14:54:17 -070039@Service
Brian Stanke11f6d532016-07-05 16:17:59 -040040@Command(scope = "onos", name = "add-vnet-intent",
41 description = "Installs virtual network connectivity intent")
42public class VirtualNetworkIntentCreateCommand extends ConnectivityIntentCommand {
43
44 @Argument(index = 0, name = "networkId", description = "Network ID",
45 required = true, multiValued = false)
Ray Milkey0068fd02018-10-11 15:45:39 -070046 @Completion(VirtualNetworkCompleter.class)
Brian Stanke11f6d532016-07-05 16:17:59 -040047 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 Milkeyd84f89b2018-08-17 14:54:17 -070060 protected void doExecute() {
Brian Stanke11f6d532016-07-05 16:17:59 -040061 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}