blob: 1adeba8d0f898a4339445151f2fd8310a3266192 [file] [log] [blame]
alshabib58fe6dc2015-08-19 17:16:13 -07001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2015-present Open Networking Laboratory
alshabib58fe6dc2015-08-19 17:16:13 -07003 *
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
7 *
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.
15 */
16package org.onosproject.cli.net;
17
18import org.apache.karaf.shell.commands.Argument;
19import org.apache.karaf.shell.commands.Command;
20import org.onosproject.cli.AbstractShellCommand;
21import org.onosproject.core.CoreService;
22import org.onosproject.net.DeviceId;
23import org.onosproject.net.meter.Band;
24import org.onosproject.net.meter.DefaultBand;
alshabibe1248b62015-08-20 17:21:55 -070025import org.onosproject.net.meter.DefaultMeterRequest;
alshabib58fe6dc2015-08-19 17:16:13 -070026import org.onosproject.net.meter.Meter;
alshabibe1248b62015-08-20 17:21:55 -070027import org.onosproject.net.meter.MeterRequest;
alshabib58fe6dc2015-08-19 17:16:13 -070028import org.onosproject.net.meter.MeterService;
29
30import java.util.Collections;
31
32/**
sangyun-han483731c2016-06-06 12:03:16 +090033 * Add a meter to a device.
alshabib58fe6dc2015-08-19 17:16:13 -070034 */
35@Command(scope = "onos", name = "add-meter",
36 description = "Adds a meter to a device (currently for testing)")
sangyun-han483731c2016-06-06 12:03:16 +090037public class AddMeterCommand extends AbstractShellCommand {
alshabib58fe6dc2015-08-19 17:16:13 -070038
39 @Argument(index = 0, name = "uri", description = "Device ID",
40 required = true, multiValued = false)
41 String uri = null;
42
alshabibe1248b62015-08-20 17:21:55 -070043 private final String appId = "org.onosproject.cli.meterCmd";
alshabib58fe6dc2015-08-19 17:16:13 -070044
45 @Override
46 protected void execute() {
47 MeterService service = get(MeterService.class);
48 CoreService coreService = get(CoreService.class);
49
50 DeviceId deviceId = DeviceId.deviceId(uri);
51
alshabib58fe6dc2015-08-19 17:16:13 -070052 Band band = DefaultBand.builder()
53 .ofType(Band.Type.DROP)
54 .withRate(500)
55 .build();
56
57
alshabibe1248b62015-08-20 17:21:55 -070058 MeterRequest request = DefaultMeterRequest.builder()
alshabib58fe6dc2015-08-19 17:16:13 -070059 .forDevice(deviceId)
60 .fromApp(coreService.registerApplication(appId))
alshabib58fe6dc2015-08-19 17:16:13 -070061 .withUnit(Meter.Unit.KB_PER_SEC)
62 .withBands(Collections.singleton(band))
alshabibe1248b62015-08-20 17:21:55 -070063 .add();
alshabib58fe6dc2015-08-19 17:16:13 -070064
alshabibe1248b62015-08-20 17:21:55 -070065 service.submit(request);
alshabib58fe6dc2015-08-19 17:16:13 -070066
67 }
68}