blob: 27a7dca5b0134eab232ca01b91d115c7ec697780 [file] [log] [blame]
Thomas Vachuska7d693f52014-10-21 19:17:57 -07001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2014-present Open Networking Foundation
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
Ray Milkeyd84f89b2018-08-17 14:54:17 -070020import org.apache.karaf.shell.api.action.Argument;
21import org.apache.karaf.shell.api.action.Command;
Ray Milkey0068fd02018-10-11 15:45:39 -070022import org.apache.karaf.shell.api.action.Completion;
Ray Milkeyd84f89b2018-08-17 14:54:17 -070023import org.apache.karaf.shell.api.action.lifecycle.Service;
Brian O'Connorabafb502014-12-02 22:26:20 -080024import org.onosproject.net.HostId;
Charles M.C. Chan41aff9f2015-04-30 00:34:41 +080025import org.onosproject.net.flow.TrafficSelector;
26import org.onosproject.net.flow.TrafficTreatment;
Brian O'Connorabafb502014-12-02 22:26:20 -080027import org.onosproject.net.intent.Constraint;
28import org.onosproject.net.intent.HostToHostIntent;
29import org.onosproject.net.intent.IntentService;
tomf5c9d922014-10-03 15:22:03 -070030
31/**
32 * Installs host-to-host connectivity intent.
33 */
Ray Milkeyd84f89b2018-08-17 14:54:17 -070034@Service
tomf5c9d922014-10-03 15:22:03 -070035@Command(scope = "onos", name = "add-host-intent",
36 description = "Installs host-to-host connectivity intent")
Ray Milkey460f4022014-11-05 15:41:43 -080037public class AddHostToHostIntentCommand extends ConnectivityIntentCommand {
tomf5c9d922014-10-03 15:22:03 -070038
39 @Argument(index = 0, name = "one", description = "One host ID",
40 required = true, multiValued = false)
Ray Milkey0068fd02018-10-11 15:45:39 -070041 @Completion(HostIdCompleter.class)
tomf5c9d922014-10-03 15:22:03 -070042 String one = null;
43
44 @Argument(index = 1, name = "two", description = "Another host ID",
45 required = true, multiValued = false)
Ray Milkey0068fd02018-10-11 15:45:39 -070046 @Completion(HostIdCompleter.class)
tomf5c9d922014-10-03 15:22:03 -070047 String two = null;
48
tomf5c9d922014-10-03 15:22:03 -070049 @Override
Ray Milkeyd84f89b2018-08-17 14:54:17 -070050 protected void doExecute() {
tomf5c9d922014-10-03 15:22:03 -070051 IntentService service = get(IntentService.class);
52
53 HostId oneId = HostId.hostId(one);
54 HostId twoId = HostId.hostId(two);
55
Charles M.C. Chan41aff9f2015-04-30 00:34:41 +080056 TrafficSelector selector = buildTrafficSelector();
57 TrafficTreatment treatment = buildTrafficTreatment();
Ray Milkey460f4022014-11-05 15:41:43 -080058 List<Constraint> constraints = buildConstraints();
tomf5c9d922014-10-03 15:22:03 -070059
Ray Milkeyebc5d222015-03-18 15:45:36 -070060 HostToHostIntent intent = HostToHostIntent.builder()
61 .appId(appId())
62 .key(key())
63 .one(oneId)
64 .two(twoId)
Charles M.C. Chan41aff9f2015-04-30 00:34:41 +080065 .selector(selector)
66 .treatment(treatment)
Ray Milkeyebc5d222015-03-18 15:45:36 -070067 .constraints(constraints)
68 .priority(priority())
Luca Prete670ac5d2017-02-03 15:55:43 -080069 .resourceGroup(resourceGroup())
Ray Milkeyebc5d222015-03-18 15:45:36 -070070 .build();
tomf5c9d922014-10-03 15:22:03 -070071 service.submit(intent);
Ray Milkeycb33a132015-02-02 10:05:12 -080072 print("Host to Host intent submitted:\n%s", intent.toString());
tomf5c9d922014-10-03 15:22:03 -070073 }
74
75}