Pier Ventre | f5d7236 | 2016-07-17 12:02:14 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016-present Open Networking Laboratory |
| 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 | |
| 17 | package org.onosproject.net.behaviour; |
| 18 | |
| 19 | import com.google.common.annotations.Beta; |
| 20 | import com.google.common.base.MoreObjects; |
| 21 | import org.onlab.packet.VlanId; |
| 22 | import org.onosproject.net.AbstractDescription; |
| 23 | import org.onosproject.net.SparseAnnotations; |
| 24 | |
| 25 | import java.util.List; |
| 26 | import java.util.Optional; |
| 27 | |
| 28 | /** |
| 29 | * Default implementation of mirroring description entity. |
| 30 | */ |
| 31 | @Beta |
| 32 | public class DefaultMirroringDescription extends AbstractDescription |
| 33 | implements MirroringDescription { |
| 34 | |
| 35 | private final MirroringName mirroringName; |
| 36 | private final List<String> monitorSrcPorts; |
| 37 | private final List<String> monitorDstPorts; |
| 38 | private final List<VlanId> monitorVlans; |
| 39 | private final Optional<String> mirrorPort; |
| 40 | private final Optional<VlanId> mirrorVlan; |
| 41 | |
| 42 | /** |
| 43 | * Creates a mirroring description using the supplied information. |
| 44 | * |
| 45 | * @param name the name of the mirroring |
| 46 | * @param monitorsrcports the monitored src ports |
| 47 | * @param monitordstports the monitored dst ports |
| 48 | * @param monitorvlans the monitored vlans |
| 49 | * @param mirrorport the mirror port |
| 50 | * @param mirrorvlan the mirror vlan |
| 51 | * @param annotations optional key/value annotations |
| 52 | */ |
| 53 | public DefaultMirroringDescription(MirroringName name, |
| 54 | List<String> monitorsrcports, |
| 55 | List<String> monitordstports, |
| 56 | List<VlanId> monitorvlans, |
| 57 | Optional<String> mirrorport, |
| 58 | Optional<VlanId> mirrorvlan, |
| 59 | SparseAnnotations... annotations) { |
| 60 | super(annotations); |
| 61 | this.mirroringName = name; |
| 62 | this.monitorSrcPorts = monitorsrcports; |
| 63 | this.monitorDstPorts = monitordstports; |
| 64 | this.monitorVlans = monitorvlans; |
| 65 | this.mirrorPort = mirrorport; |
| 66 | this.mirrorVlan = mirrorvlan; |
| 67 | } |
| 68 | |
| 69 | |
| 70 | /** |
| 71 | * Returns mirroring name. |
| 72 | * |
| 73 | * @return mirroring name |
| 74 | */ |
| 75 | @Override |
| 76 | public MirroringName name() { |
| 77 | return mirroringName; |
| 78 | } |
| 79 | |
| 80 | /** |
| 81 | * Returns src ports to monitor. |
| 82 | * If it is empty, then no src port has |
| 83 | * to be monitored. |
| 84 | * |
| 85 | * @return set of src ports to monitor |
| 86 | */ |
| 87 | @Override |
| 88 | public List<String> monitorSrcPorts() { |
| 89 | return monitorSrcPorts; |
| 90 | } |
| 91 | |
| 92 | /** |
| 93 | * Returns dst ports to monitor. |
| 94 | * If it is empty, then no dst port has |
| 95 | * to be monitored. |
| 96 | * |
| 97 | * @return set of dst ports to monitor |
| 98 | */ |
| 99 | @Override |
| 100 | public List<String> monitorDstPorts() { |
| 101 | return monitorDstPorts; |
| 102 | } |
| 103 | |
| 104 | /** |
| 105 | * Returns vlans to monitor. |
| 106 | * If it is empty, then no vlan has |
| 107 | * to be monitored. |
| 108 | * |
| 109 | * @return monitored vlan |
| 110 | */ |
| 111 | @Override |
| 112 | public List<VlanId> monitorVlans() { |
| 113 | return monitorVlans; |
| 114 | } |
| 115 | |
| 116 | /** |
| 117 | * Returns mirror port. |
| 118 | * If it is not set, then no destination |
| 119 | * port for mirrored packets. |
| 120 | * |
| 121 | * @return mirror port |
| 122 | */ |
| 123 | @Override |
| 124 | public Optional<String> mirrorPort() { |
| 125 | return mirrorPort; |
| 126 | } |
| 127 | |
| 128 | /** |
| 129 | * Returns mirror vlan. |
| 130 | * If it is not set the no destination |
| 131 | * vlan for mirrored packets. |
| 132 | * |
| 133 | * @return mirror vlan |
| 134 | */ |
| 135 | @Override |
| 136 | public Optional<VlanId> mirrorVlan() { |
| 137 | return mirrorVlan; |
| 138 | } |
| 139 | |
| 140 | @Override |
| 141 | public String toString() { |
| 142 | return MoreObjects.toStringHelper(this) |
| 143 | .add("name", name()) |
| 144 | .add("monitorsrcports", monitorSrcPorts()) |
| 145 | .add("monitordstports", monitorDstPorts()) |
| 146 | .add("monitorvlans", monitorVlans()) |
| 147 | .add("mirrorport", mirrorPort()) |
| 148 | .add("mirrorvlan", mirrorVlan()) |
| 149 | .toString(); |
| 150 | } |
| 151 | } |