blob: 1590ae7561ee9ee0ef45f353fc1279dbb2de674f [file] [log] [blame]
Ray Milkeycaa450b2014-10-29 15:54:24 -07001/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19package org.onlab.onos.cli.net;
20
21import org.apache.karaf.shell.commands.Argument;
22import org.apache.karaf.shell.commands.Command;
23import org.onlab.onos.net.ConnectPoint;
24import org.onlab.onos.net.DeviceId;
25import org.onlab.onos.net.PortNumber;
26import org.onlab.onos.net.flow.TrafficSelector;
27import org.onlab.onos.net.flow.TrafficTreatment;
28import org.onlab.onos.net.intent.Intent;
29import org.onlab.onos.net.intent.IntentService;
Thomas Vachuskaedc944c2014-11-04 15:42:25 -080030import org.onlab.onos.net.intent.PointToPointIntent;
Ray Milkeycaa450b2014-10-29 15:54:24 -070031
32import static org.onlab.onos.net.DeviceId.deviceId;
33import static org.onlab.onos.net.PortNumber.portNumber;
34import static org.onlab.onos.net.flow.DefaultTrafficTreatment.builder;
35
36/**
37 * Installs point-to-point connectivity intents.
38 */
39@Command(scope = "onos", name = "add-point-intent-bw",
40 description = "Installs point-to-point connectivity intent with bandwidth constraint")
41public class AddPointToPointIntentWithBandwidthConstraintCommand extends ConnectivityIntentCommand {
42
43 @Argument(index = 0, name = "ingressDevice",
44 description = "Ingress Device/Port Description",
45 required = true, multiValued = false)
46 String ingressDeviceString = null;
47
48 @Argument(index = 1, name = "egressDevice",
49 description = "Egress Device/Port Description",
50 required = true, multiValued = false)
51 String egressDeviceString = null;
52
53 @Argument(index = 2, name = "bandwidth",
54 description = "Bandwidth",
55 required = true, multiValued = false)
56 String bandwidthString = null;
57
58 @Override
59 protected void execute() {
60 IntentService service = get(IntentService.class);
61
62 DeviceId ingressDeviceId = deviceId(getDeviceId(ingressDeviceString));
63 PortNumber ingressPortNumber = portNumber(getPortNumber(ingressDeviceString));
64 ConnectPoint ingress = new ConnectPoint(ingressDeviceId, ingressPortNumber);
65
66 DeviceId egressDeviceId = deviceId(getDeviceId(egressDeviceString));
67 PortNumber egressPortNumber = portNumber(getPortNumber(egressDeviceString));
68 ConnectPoint egress = new ConnectPoint(egressDeviceId, egressPortNumber);
69
70 long bandwidth = Long.parseLong(bandwidthString);
71
72 TrafficSelector selector = buildTrafficSelector();
73 TrafficTreatment treatment = builder().build();
74
Thomas Vachuskaedc944c2014-11-04 15:42:25 -080075 // FIXME: add bandwitdh constraint
76 Intent intent = new PointToPointIntent(
Ray Milkeycaa450b2014-10-29 15:54:24 -070077 appId(), selector, treatment,
Thomas Vachuskaedc944c2014-11-04 15:42:25 -080078 ingress, egress);
Ray Milkeycaa450b2014-10-29 15:54:24 -070079 service.submit(intent);
80 }
81
82 /**
83 * Extracts the port number portion of the ConnectPoint.
84 *
85 * @param deviceString string representing the device/port
86 * @return port number as a string, empty string if the port is not found
87 */
88 private String getPortNumber(String deviceString) {
89 int slash = deviceString.indexOf('/');
90 if (slash <= 0) {
91 return "";
92 }
93 return deviceString.substring(slash + 1, deviceString.length());
94 }
95
96 /**
97 * Extracts the device ID portion of the ConnectPoint.
98 *
99 * @param deviceString string representing the device/port
100 * @return device ID string
101 */
102 private String getDeviceId(String deviceString) {
103 int slash = deviceString.indexOf('/');
104 if (slash <= 0) {
105 return "";
106 }
107 return deviceString.substring(0, slash);
108 }
109}