Thomas Vachuska | 7d693f5 | 2014-10-21 19:17:57 -0700 | [diff] [blame] | 1 | /* |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 2 | * Copyright 2014 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; |
Ray Milkey | a058c73 | 2014-10-08 13:52:34 -0700 | [diff] [blame] | 17 | |
Ray Milkey | 460f402 | 2014-11-05 15:41:43 -0800 | [diff] [blame] | 18 | import java.util.List; |
| 19 | |
Ray Milkey | a058c73 | 2014-10-08 13:52:34 -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.ConnectPoint; |
| 23 | import org.onosproject.net.DeviceId; |
| 24 | import org.onosproject.net.PortNumber; |
| 25 | import org.onosproject.net.flow.TrafficSelector; |
| 26 | import org.onosproject.net.flow.TrafficTreatment; |
| 27 | import org.onosproject.net.intent.Constraint; |
| 28 | import org.onosproject.net.intent.Intent; |
| 29 | import org.onosproject.net.intent.IntentService; |
| 30 | import org.onosproject.net.intent.PointToPointIntent; |
Thomas Vachuska | b97cf28 | 2014-10-20 23:31:12 -0700 | [diff] [blame] | 31 | |
Ray Milkey | 5b3717e | 2015-02-05 11:44:08 -0800 | [diff] [blame] | 32 | import static org.onosproject.net.DeviceId.deviceId; |
| 33 | import static org.onosproject.net.PortNumber.portNumber; |
| 34 | |
Ray Milkey | a058c73 | 2014-10-08 13:52:34 -0700 | [diff] [blame] | 35 | /** |
| 36 | * Installs point-to-point connectivity intents. |
| 37 | */ |
| 38 | @Command(scope = "onos", name = "add-point-intent", |
| 39 | description = "Installs point-to-point connectivity intent") |
Ray Milkey | 9fdf1ea | 2014-10-21 09:48:02 -0700 | [diff] [blame] | 40 | public class AddPointToPointIntentCommand extends ConnectivityIntentCommand { |
Ray Milkey | a058c73 | 2014-10-08 13:52:34 -0700 | [diff] [blame] | 41 | |
| 42 | @Argument(index = 0, name = "ingressDevice", |
| 43 | description = "Ingress Device/Port Description", |
| 44 | required = true, multiValued = false) |
| 45 | String ingressDeviceString = null; |
| 46 | |
| 47 | @Argument(index = 1, name = "egressDevice", |
| 48 | description = "Egress Device/Port Description", |
| 49 | required = true, multiValued = false) |
| 50 | String egressDeviceString = null; |
| 51 | |
Ray Milkey | ac1441d | 2014-11-13 09:31:47 -0800 | [diff] [blame] | 52 | |
Ray Milkey | a058c73 | 2014-10-08 13:52:34 -0700 | [diff] [blame] | 53 | @Override |
| 54 | protected void execute() { |
| 55 | IntentService service = get(IntentService.class); |
| 56 | |
Thomas Vachuska | b97cf28 | 2014-10-20 23:31:12 -0700 | [diff] [blame] | 57 | DeviceId ingressDeviceId = deviceId(getDeviceId(ingressDeviceString)); |
| 58 | PortNumber ingressPortNumber = portNumber(getPortNumber(ingressDeviceString)); |
Ray Milkey | a058c73 | 2014-10-08 13:52:34 -0700 | [diff] [blame] | 59 | ConnectPoint ingress = new ConnectPoint(ingressDeviceId, ingressPortNumber); |
| 60 | |
Thomas Vachuska | b97cf28 | 2014-10-20 23:31:12 -0700 | [diff] [blame] | 61 | DeviceId egressDeviceId = deviceId(getDeviceId(egressDeviceString)); |
| 62 | PortNumber egressPortNumber = portNumber(getPortNumber(egressDeviceString)); |
Ray Milkey | a058c73 | 2014-10-08 13:52:34 -0700 | [diff] [blame] | 63 | ConnectPoint egress = new ConnectPoint(egressDeviceId, egressPortNumber); |
| 64 | |
Ray Milkey | 9fdf1ea | 2014-10-21 09:48:02 -0700 | [diff] [blame] | 65 | TrafficSelector selector = buildTrafficSelector(); |
Ray Milkey | ac1441d | 2014-11-13 09:31:47 -0800 | [diff] [blame] | 66 | TrafficTreatment treatment = buildTrafficTreatment(); |
Ray Milkey | a058c73 | 2014-10-08 13:52:34 -0700 | [diff] [blame] | 67 | |
Ray Milkey | 460f402 | 2014-11-05 15:41:43 -0800 | [diff] [blame] | 68 | List<Constraint> constraints = buildConstraints(); |
| 69 | |
Ray Milkey | 5b3717e | 2015-02-05 11:44:08 -0800 | [diff] [blame] | 70 | Intent intent = new PointToPointIntent(appId(), |
| 71 | key(), |
| 72 | selector, treatment, |
| 73 | ingress, egress, constraints); |
Ray Milkey | a058c73 | 2014-10-08 13:52:34 -0700 | [diff] [blame] | 74 | service.submit(intent); |
Ray Milkey | cb33a13 | 2015-02-02 10:05:12 -0800 | [diff] [blame] | 75 | print("Point to point intent submitted:\n%s", intent.toString()); |
Ray Milkey | a058c73 | 2014-10-08 13:52:34 -0700 | [diff] [blame] | 76 | } |
| 77 | |
| 78 | /** |
| 79 | * Extracts the port number portion of the ConnectPoint. |
| 80 | * |
| 81 | * @param deviceString string representing the device/port |
| 82 | * @return port number as a string, empty string if the port is not found |
| 83 | */ |
Brian O'Connor | fe0f4b1 | 2014-10-30 21:19:02 -0700 | [diff] [blame] | 84 | public static String getPortNumber(String deviceString) { |
Ray Milkey | a058c73 | 2014-10-08 13:52:34 -0700 | [diff] [blame] | 85 | int slash = deviceString.indexOf('/'); |
| 86 | if (slash <= 0) { |
| 87 | return ""; |
| 88 | } |
| 89 | return deviceString.substring(slash + 1, deviceString.length()); |
| 90 | } |
| 91 | |
| 92 | /** |
| 93 | * Extracts the device ID portion of the ConnectPoint. |
| 94 | * |
| 95 | * @param deviceString string representing the device/port |
| 96 | * @return device ID string |
| 97 | */ |
Brian O'Connor | fe0f4b1 | 2014-10-30 21:19:02 -0700 | [diff] [blame] | 98 | public static String getDeviceId(String deviceString) { |
Ray Milkey | a058c73 | 2014-10-08 13:52:34 -0700 | [diff] [blame] | 99 | int slash = deviceString.indexOf('/'); |
| 100 | if (slash <= 0) { |
| 101 | return ""; |
| 102 | } |
| 103 | return deviceString.substring(0, slash); |
| 104 | } |
| 105 | } |