blob: fb95646eefb046058027ca37baa693eae0a98d6d [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;
22import org.apache.karaf.shell.api.action.lifecycle.Service;
Brian O'Connorabafb502014-12-02 22:26:20 -080023import org.onosproject.net.HostId;
Charles M.C. Chan41aff9f2015-04-30 00:34:41 +080024import org.onosproject.net.flow.TrafficSelector;
25import org.onosproject.net.flow.TrafficTreatment;
Brian O'Connorabafb502014-12-02 22:26:20 -080026import org.onosproject.net.intent.Constraint;
27import org.onosproject.net.intent.HostToHostIntent;
28import org.onosproject.net.intent.IntentService;
tomf5c9d922014-10-03 15:22:03 -070029
30/**
31 * Installs host-to-host connectivity intent.
32 */
Ray Milkeyd84f89b2018-08-17 14:54:17 -070033@Service
tomf5c9d922014-10-03 15:22:03 -070034@Command(scope = "onos", name = "add-host-intent",
35 description = "Installs host-to-host connectivity intent")
Ray Milkey460f4022014-11-05 15:41:43 -080036public class AddHostToHostIntentCommand extends ConnectivityIntentCommand {
tomf5c9d922014-10-03 15:22:03 -070037
38 @Argument(index = 0, name = "one", description = "One host ID",
39 required = true, multiValued = false)
40 String one = null;
41
42 @Argument(index = 1, name = "two", description = "Another host ID",
43 required = true, multiValued = false)
44 String two = null;
45
tomf5c9d922014-10-03 15:22:03 -070046 @Override
Ray Milkeyd84f89b2018-08-17 14:54:17 -070047 protected void doExecute() {
tomf5c9d922014-10-03 15:22:03 -070048 IntentService service = get(IntentService.class);
49
50 HostId oneId = HostId.hostId(one);
51 HostId twoId = HostId.hostId(two);
52
Charles M.C. Chan41aff9f2015-04-30 00:34:41 +080053 TrafficSelector selector = buildTrafficSelector();
54 TrafficTreatment treatment = buildTrafficTreatment();
Ray Milkey460f4022014-11-05 15:41:43 -080055 List<Constraint> constraints = buildConstraints();
tomf5c9d922014-10-03 15:22:03 -070056
Ray Milkeyebc5d222015-03-18 15:45:36 -070057 HostToHostIntent intent = HostToHostIntent.builder()
58 .appId(appId())
59 .key(key())
60 .one(oneId)
61 .two(twoId)
Charles M.C. Chan41aff9f2015-04-30 00:34:41 +080062 .selector(selector)
63 .treatment(treatment)
Ray Milkeyebc5d222015-03-18 15:45:36 -070064 .constraints(constraints)
65 .priority(priority())
Luca Prete670ac5d2017-02-03 15:55:43 -080066 .resourceGroup(resourceGroup())
Ray Milkeyebc5d222015-03-18 15:45:36 -070067 .build();
tomf5c9d922014-10-03 15:22:03 -070068 service.submit(intent);
Ray Milkeycb33a132015-02-02 10:05:12 -080069 print("Host to Host intent submitted:\n%s", intent.toString());
tomf5c9d922014-10-03 15:22:03 -070070 }
71
72}