Thomas Vachuska | 7d693f5 | 2014-10-21 19:17:57 -0700 | [diff] [blame] | 1 | /* |
Ray Milkey | 34c9590 | 2015-04-15 09:47:53 -0700 | [diff] [blame] | 2 | * Copyright 2014-2015 Open Networking Laboratory |
Thomas Vachuska | 7d693f5 | 2014-10-21 19:17:57 -0700 | [diff] [blame] | 3 | * |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 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 |
Thomas Vachuska | 7d693f5 | 2014-10-21 19:17:57 -0700 | [diff] [blame] | 7 | * |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 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. |
Thomas Vachuska | 7d693f5 | 2014-10-21 19:17:57 -0700 | [diff] [blame] | 15 | */ |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 16 | package org.onosproject.cli.net; |
tom | f5c9d92 | 2014-10-03 15:22:03 -0700 | [diff] [blame] | 17 | |
Ray Milkey | ebc5d22 | 2015-03-18 15:45:36 -0700 | [diff] [blame] | 18 | import java.util.List; |
| 19 | |
tom | f5c9d92 | 2014-10-03 15:22:03 -0700 | [diff] [blame] | 20 | import org.apache.karaf.shell.commands.Argument; |
| 21 | import org.apache.karaf.shell.commands.Command; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 22 | import org.onosproject.net.HostId; |
Charles M.C. Chan | 41aff9f | 2015-04-30 00:34:41 +0800 | [diff] [blame] | 23 | import org.onosproject.net.flow.TrafficSelector; |
| 24 | import org.onosproject.net.flow.TrafficTreatment; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 25 | import org.onosproject.net.intent.Constraint; |
| 26 | import org.onosproject.net.intent.HostToHostIntent; |
| 27 | import org.onosproject.net.intent.IntentService; |
tom | f5c9d92 | 2014-10-03 15:22:03 -0700 | [diff] [blame] | 28 | |
| 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 Milkey | 460f402 | 2014-11-05 15:41:43 -0800 | [diff] [blame] | 34 | public class AddHostToHostIntentCommand extends ConnectivityIntentCommand { |
tom | f5c9d92 | 2014-10-03 15:22:03 -0700 | [diff] [blame] | 35 | |
| 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 | |
tom | f5c9d92 | 2014-10-03 15:22:03 -0700 | [diff] [blame] | 44 | @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. Chan | 41aff9f | 2015-04-30 00:34:41 +0800 | [diff] [blame] | 51 | TrafficSelector selector = buildTrafficSelector(); |
| 52 | TrafficTreatment treatment = buildTrafficTreatment(); |
Ray Milkey | 460f402 | 2014-11-05 15:41:43 -0800 | [diff] [blame] | 53 | List<Constraint> constraints = buildConstraints(); |
tom | f5c9d92 | 2014-10-03 15:22:03 -0700 | [diff] [blame] | 54 | |
Ray Milkey | ebc5d22 | 2015-03-18 15:45:36 -0700 | [diff] [blame] | 55 | HostToHostIntent intent = HostToHostIntent.builder() |
| 56 | .appId(appId()) |
| 57 | .key(key()) |
| 58 | .one(oneId) |
| 59 | .two(twoId) |
Charles M.C. Chan | 41aff9f | 2015-04-30 00:34:41 +0800 | [diff] [blame] | 60 | .selector(selector) |
| 61 | .treatment(treatment) |
Ray Milkey | ebc5d22 | 2015-03-18 15:45:36 -0700 | [diff] [blame] | 62 | .constraints(constraints) |
| 63 | .priority(priority()) |
| 64 | .build(); |
tom | f5c9d92 | 2014-10-03 15:22:03 -0700 | [diff] [blame] | 65 | service.submit(intent); |
Ray Milkey | cb33a13 | 2015-02-02 10:05:12 -0800 | [diff] [blame] | 66 | print("Host to Host intent submitted:\n%s", intent.toString()); |
tom | f5c9d92 | 2014-10-03 15:22:03 -0700 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | } |