blob: 9c08a8697369e5c15cc7bb38120d2eab5572615e [file] [log] [blame]
Jordi Ortiz1d8cc492017-01-27 14:28:53 +01001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2017-present Open Networking Foundation
Jordi Ortiz1d8cc492017-01-27 14:28:53 +01003 *
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
Ray Milkeyd84f89b2018-08-17 14:54:17 -070018import org.apache.karaf.shell.api.action.Argument;
19import org.apache.karaf.shell.api.action.Command;
20import org.apache.karaf.shell.api.action.lifecycle.Service;
Jordi Ortiz1d8cc492017-01-27 14:28:53 +010021import org.onosproject.cli.AbstractShellCommand;
22import org.onosproject.core.CoreService;
23import org.onosproject.net.DeviceId;
24import org.onosproject.net.meter.Band;
25import org.onosproject.net.meter.DefaultBand;
26import org.onosproject.net.meter.DefaultMeterRequest;
27import org.onosproject.net.meter.Meter;
28import org.onosproject.net.meter.MeterId;
29import org.onosproject.net.meter.MeterRequest;
30import org.onosproject.net.meter.MeterService;
31
32import java.util.Collections;
33
34/**
35 * Remove existing meter from device.
36 */
Ray Milkeyd84f89b2018-08-17 14:54:17 -070037@Service
Jordi Ortiz1d8cc492017-01-27 14:28:53 +010038@Command(scope = "onos", name = "meter-remove",
39 description = "Removes a meter from a device (currently for testing)")
40public class MeterRemoveCommand extends AbstractShellCommand {
41
42 @Argument(index = 0, name = "uri", description = "Device ID",
43 required = true, multiValued = false)
44 private String uri = null;
45
Jordi Ortiza19c1882017-04-21 19:37:09 +020046 @Argument(index = 1, name = "meterId", description = "Meter ID hexadecimal value",
Jordi Ortiz1d8cc492017-01-27 14:28:53 +010047 required = true, multiValued = false)
48 private String meterIdstr = null;
49
50 private final String appId = "org.onosproject.cli.meterCmd";
51
52 @Override
Ray Milkeyd84f89b2018-08-17 14:54:17 -070053 protected void doExecute() {
Jordi Ortiz1d8cc492017-01-27 14:28:53 +010054 MeterService service = get(MeterService.class);
55 CoreService coreService = get(CoreService.class);
56
57 DeviceId deviceId = DeviceId.deviceId(uri);
Jordi Ortiza19c1882017-04-21 19:37:09 +020058 MeterId meterId = MeterId.meterId(Long.parseLong(meterIdstr, 16));
Jordi Ortiz1d8cc492017-01-27 14:28:53 +010059
60 Band b = new DefaultBand(Band.Type.DROP, 0L, 0L, (short) 0);
61
62 MeterRequest.Builder builder = DefaultMeterRequest.builder()
63 .forDevice(deviceId)
64 .withBands(Collections.singleton(b))
65 .withUnit(Meter.Unit.PKTS_PER_SEC)
66 .fromApp(coreService.registerApplication(appId));
67 MeterRequest meterRequest = builder.remove();
68 service.withdraw(meterRequest, meterId);
Jordi Ortiz1002b0a2017-02-27 14:25:49 +010069 log.info("Requested meter removal: {}", meterRequest.toString());
70
71 print("Requested meter removal: %s", meterRequest.toString());
Jordi Ortiz1d8cc492017-01-27 14:28:53 +010072 }
73}