Jian Li | b2a5888 | 2019-02-20 17:39:41 +0900 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2019-present Open Networking Foundation |
| 3 | * |
| 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 | */ |
| 16 | package org.onosproject.openstacktelemetry.cli; |
| 17 | |
| 18 | import org.apache.karaf.shell.api.action.Argument; |
| 19 | import org.apache.karaf.shell.api.action.Command; |
| 20 | import org.apache.karaf.shell.api.action.lifecycle.Service; |
| 21 | import org.onlab.packet.IpPrefix; |
| 22 | import org.onlab.packet.TpPort; |
| 23 | import org.onosproject.cli.AbstractShellCommand; |
| 24 | import org.onosproject.openstacktelemetry.api.DefaultStatsFlowRule; |
| 25 | import org.onosproject.openstacktelemetry.api.StatsFlowRule; |
| 26 | import org.onosproject.openstacktelemetry.api.StatsFlowRuleAdminService; |
| 27 | |
| 28 | import static org.onosproject.openstacktelemetry.util.OpenstackTelemetryUtil.getProtocolTypeFromString; |
| 29 | |
| 30 | /** |
| 31 | * Removes vFlow telemetry rule. |
| 32 | */ |
| 33 | @Service |
| 34 | @Command(scope = "onos", name = "telemetry-delete-vflow", |
| 35 | description = "Adds a telemetry virtual flow rule") |
| 36 | public class TelemetryVflowDeleteCommand extends AbstractShellCommand { |
| 37 | |
| 38 | @Argument(index = 0, name = "Source IP", description = "Source IP address", |
| 39 | required = true, multiValued = false) |
| 40 | private String srcIp = null; |
| 41 | |
| 42 | @Argument(index = 1, name = "Source port", description = "Source port number", |
| 43 | required = true, multiValued = false) |
| 44 | private String srcTpPort = null; |
| 45 | |
| 46 | @Argument(index = 2, name = "Destination IP", description = "Destination IP address", |
| 47 | required = true, multiValued = false) |
| 48 | private String dstIp = null; |
| 49 | |
| 50 | @Argument(index = 3, name = "Destination port", description = "Destination port number", |
| 51 | required = true, multiValued = false) |
| 52 | private String dstTpPort = null; |
| 53 | |
| 54 | @Argument(index = 4, name = "IP protocol", description = "IP protocol (TCP/UDP/ANY)", |
| 55 | required = true, multiValued = false) |
| 56 | private String ipProto = null; |
| 57 | |
| 58 | @Override |
| 59 | protected void doExecute() { |
| 60 | StatsFlowRuleAdminService statsService = get(StatsFlowRuleAdminService.class); |
| 61 | |
| 62 | StatsFlowRule statsFlowRule = DefaultStatsFlowRule.builder() |
| 63 | .srcIpPrefix(IpPrefix.valueOf(srcIp)) |
| 64 | .dstIpPrefix(IpPrefix.valueOf(dstIp)) |
| 65 | .srcTpPort(TpPort.tpPort(Integer.valueOf(srcTpPort))) |
| 66 | .dstTpPort(TpPort.tpPort(Integer.valueOf(dstTpPort))) |
| 67 | .ipProtocol(getProtocolTypeFromString(ipProto)) |
| 68 | .build(); |
| 69 | |
| 70 | statsService.deleteStatFlowRule(statsFlowRule); |
| 71 | |
| 72 | print("Removed the stat flow rule."); |
| 73 | } |
| 74 | } |