blob: 67dbd76e4d578f0249cb0bc1f0968c9c9f76f208 [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;
tomf5c9d922014-10-03 15:22:03 -070017
Ray Milkeyebc5d222015-03-18 15:45:36 -070018import java.util.List;
19
tomf5c9d922014-10-03 15:22:03 -070020import org.apache.karaf.shell.commands.Argument;
21import org.apache.karaf.shell.commands.Command;
Brian O'Connorabafb502014-12-02 22:26:20 -080022import org.onosproject.net.HostId;
Charles M.C. Chan41aff9f2015-04-30 00:34:41 +080023import org.onosproject.net.flow.TrafficSelector;
24import org.onosproject.net.flow.TrafficTreatment;
Brian O'Connorabafb502014-12-02 22:26:20 -080025import org.onosproject.net.intent.Constraint;
26import org.onosproject.net.intent.HostToHostIntent;
27import org.onosproject.net.intent.IntentService;
tomf5c9d922014-10-03 15:22:03 -070028
29/**
30 * Installs host-to-host connectivity intent.
31 */
32@Command(scope = "onos", name = "add-host-intent",
33 description = "Installs host-to-host connectivity intent")
Ray Milkey460f4022014-11-05 15:41:43 -080034public class AddHostToHostIntentCommand extends ConnectivityIntentCommand {
tomf5c9d922014-10-03 15:22:03 -070035
36 @Argument(index = 0, name = "one", description = "One host ID",
37 required = true, multiValued = false)
38 String one = null;
39
40 @Argument(index = 1, name = "two", description = "Another host ID",
41 required = true, multiValued = false)
42 String two = null;
43
tomf5c9d922014-10-03 15:22:03 -070044 @Override
45 protected void execute() {
46 IntentService service = get(IntentService.class);
47
48 HostId oneId = HostId.hostId(one);
49 HostId twoId = HostId.hostId(two);
50
Charles M.C. Chan41aff9f2015-04-30 00:34:41 +080051 TrafficSelector selector = buildTrafficSelector();
52 TrafficTreatment treatment = buildTrafficTreatment();
Ray Milkey460f4022014-11-05 15:41:43 -080053 List<Constraint> constraints = buildConstraints();
tomf5c9d922014-10-03 15:22:03 -070054
Ray Milkeyebc5d222015-03-18 15:45:36 -070055 HostToHostIntent intent = HostToHostIntent.builder()
56 .appId(appId())
57 .key(key())
58 .one(oneId)
59 .two(twoId)
Charles M.C. Chan41aff9f2015-04-30 00:34:41 +080060 .selector(selector)
61 .treatment(treatment)
Ray Milkeyebc5d222015-03-18 15:45:36 -070062 .constraints(constraints)
63 .priority(priority())
64 .build();
tomf5c9d922014-10-03 15:22:03 -070065 service.submit(intent);
Ray Milkeycb33a132015-02-02 10:05:12 -080066 print("Host to Host intent submitted:\n%s", intent.toString());
tomf5c9d922014-10-03 15:22:03 -070067 }
68
69}