blob: 5684ae51fe198aeff683c541ab149dd3b9a86590 [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;
21import org.apache.karaf.shell.api.action.lifecycle.Service;
Brian Stanke11f6d532016-07-05 16:17:59 -040022import org.onosproject.cli.net.ConnectivityIntentCommand;
23import org.onosproject.incubator.net.virtual.NetworkId;
24import org.onosproject.incubator.net.virtual.VirtualNetworkIntent;
25import org.onosproject.incubator.net.virtual.VirtualNetworkService;
26import org.onosproject.net.ConnectPoint;
27import org.onosproject.net.flow.TrafficSelector;
28import org.onosproject.net.flow.TrafficTreatment;
29import org.onosproject.net.intent.Constraint;
30import org.onosproject.net.intent.Intent;
31import org.onosproject.net.intent.IntentService;
32
33import java.util.List;
34
35/**
36 * Installs virtual network intents.
37 */
Ray Milkeyd84f89b2018-08-17 14:54:17 -070038@Service
Brian Stanke11f6d532016-07-05 16:17:59 -040039@Command(scope = "onos", name = "add-vnet-intent",
40 description = "Installs virtual network connectivity intent")
41public class VirtualNetworkIntentCreateCommand extends ConnectivityIntentCommand {
42
43 @Argument(index = 0, name = "networkId", description = "Network ID",
44 required = true, multiValued = false)
45 Long networkId = null;
46
47 @Argument(index = 1, name = "ingressDevice",
48 description = "Ingress Device/Port Description",
49 required = true, multiValued = false)
50 String ingressDeviceString = null;
51
52 @Argument(index = 2, name = "egressDevice",
53 description = "Egress Device/Port Description",
54 required = true, multiValued = false)
55 String egressDeviceString = null;
56
57 @Override
Ray Milkeyd84f89b2018-08-17 14:54:17 -070058 protected void doExecute() {
Brian Stanke11f6d532016-07-05 16:17:59 -040059 VirtualNetworkService service = get(VirtualNetworkService.class);
60 IntentService virtualNetworkIntentService = service.get(NetworkId.networkId(networkId), IntentService.class);
61
62 ConnectPoint ingress = ConnectPoint.deviceConnectPoint(ingressDeviceString);
63 ConnectPoint egress = ConnectPoint.deviceConnectPoint(egressDeviceString);
64
65 TrafficSelector selector = buildTrafficSelector();
66 TrafficTreatment treatment = buildTrafficTreatment();
67
68 List<Constraint> constraints = buildConstraints();
69
70 Intent intent = VirtualNetworkIntent.builder()
71 .networkId(NetworkId.networkId(networkId))
72 .appId(appId())
73 .key(key())
74 .selector(selector)
75 .treatment(treatment)
76 .ingressPoint(ingress)
77 .egressPoint(egress)
78 .constraints(constraints)
79 .priority(priority())
80 .build();
81 virtualNetworkIntentService.submit(intent);
82 print("Virtual intent submitted:\n%s", intent.toString());
83 }
84}