blob: 9bfd199c948a09bef18ff6e9eb5fc89377d032c6 [file] [log] [blame]
Thomas Vachuska7d693f52014-10-21 19:17:57 -07001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2014-present Open Networking Laboratory
Thomas Vachuska7d693f52014-10-21 19:17:57 -07003 *
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07004 * 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
Thomas Vachuska7d693f52014-10-21 19:17:57 -07007 *
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07008 * 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.
Thomas Vachuska7d693f52014-10-21 19:17:57 -070015 */
Brian O'Connorabafb502014-12-02 22:26:20 -080016package org.onosproject.cli.net;
Ray Milkeya058c732014-10-08 13:52:34 -070017
18import org.apache.karaf.shell.commands.Argument;
19import org.apache.karaf.shell.commands.Command;
Brian O'Connorabafb502014-12-02 22:26:20 -080020import org.onosproject.net.ConnectPoint;
Brian O'Connorabafb502014-12-02 22:26:20 -080021import org.onosproject.net.flow.TrafficSelector;
22import org.onosproject.net.flow.TrafficTreatment;
23import org.onosproject.net.intent.Constraint;
24import org.onosproject.net.intent.Intent;
25import org.onosproject.net.intent.IntentService;
26import org.onosproject.net.intent.PointToPointIntent;
Thomas Vachuskab97cf282014-10-20 23:31:12 -070027
Jonathan Hartc3af35a2015-04-30 22:20:29 -070028import java.util.List;
Ray Milkey5b3717e2015-02-05 11:44:08 -080029
Ray Milkeya058c732014-10-08 13:52:34 -070030/**
31 * Installs point-to-point connectivity intents.
32 */
33@Command(scope = "onos", name = "add-point-intent",
34 description = "Installs point-to-point connectivity intent")
Ray Milkey9fdf1ea2014-10-21 09:48:02 -070035public class AddPointToPointIntentCommand extends ConnectivityIntentCommand {
Ray Milkeya058c732014-10-08 13:52:34 -070036
37 @Argument(index = 0, name = "ingressDevice",
38 description = "Ingress Device/Port Description",
39 required = true, multiValued = false)
40 String ingressDeviceString = null;
41
42 @Argument(index = 1, name = "egressDevice",
43 description = "Egress Device/Port Description",
44 required = true, multiValued = false)
45 String egressDeviceString = null;
46
Ray Milkeya058c732014-10-08 13:52:34 -070047 @Override
48 protected void execute() {
49 IntentService service = get(IntentService.class);
50
Jonathan Hartc3af35a2015-04-30 22:20:29 -070051 ConnectPoint ingress = ConnectPoint.deviceConnectPoint(ingressDeviceString);
Ray Milkeya058c732014-10-08 13:52:34 -070052
Jonathan Hartc3af35a2015-04-30 22:20:29 -070053 ConnectPoint egress = ConnectPoint.deviceConnectPoint(egressDeviceString);
Ray Milkeya058c732014-10-08 13:52:34 -070054
Ray Milkey9fdf1ea2014-10-21 09:48:02 -070055 TrafficSelector selector = buildTrafficSelector();
Ray Milkeyac1441d2014-11-13 09:31:47 -080056 TrafficTreatment treatment = buildTrafficTreatment();
Ray Milkeya058c732014-10-08 13:52:34 -070057
Ray Milkey460f4022014-11-05 15:41:43 -080058 List<Constraint> constraints = buildConstraints();
59
Ray Milkey3e3ec5f2015-03-17 17:00:38 -070060 Intent intent = PointToPointIntent.builder()
61 .appId(appId())
62 .key(key())
63 .selector(selector)
64 .treatment(treatment)
65 .ingressPoint(ingress)
66 .egressPoint(egress)
67 .constraints(constraints)
68 .priority(priority())
69 .build();
Ray Milkeya058c732014-10-08 13:52:34 -070070 service.submit(intent);
Ray Milkeycb33a132015-02-02 10:05:12 -080071 print("Point to point intent submitted:\n%s", intent.toString());
Ray Milkeya058c732014-10-08 13:52:34 -070072 }
Ray Milkeya058c732014-10-08 13:52:34 -070073}