Committed by
Gerrit Code Review
[ONOS-5070] Adds mirroring functionality.
Changes: - Adds mirroring behaviour; - Adds mirroring description; - Adds mirroring name; - Implements for Ovsdb the mirroring; - Adds OvsdbMirror entity; - Adds constants related to Mirror table; - Fix one issue related to Mirror table - Extends OvsdbClientService introducing mirroring; - Implements mirroring functionality in DefaulOvsdbClient; - Support for different types of device id Change-Id: Ie291f49b3c61b7998010f555ae11deb8c021063d
Showing
14 changed files
with
753 additions
and
2 deletions
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 | +} |
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 org.onosproject.net.driver.HandlerBehaviour; | ||
21 | + | ||
22 | +import java.util.Collection; | ||
23 | + | ||
24 | +/** | ||
25 | + * Behaviour for handling various drivers for mirroring configurations. | ||
26 | + */ | ||
27 | +@Beta | ||
28 | +public interface MirroringConfig extends HandlerBehaviour { | ||
29 | + | ||
30 | + /** | ||
31 | + * Adds a mirroring with a given description. | ||
32 | + * | ||
33 | + * @param bridge the bridge name | ||
34 | + * @param mirroringDescription mirroring description | ||
35 | + * @return true if succeeds, or false | ||
36 | + */ | ||
37 | + boolean addMirroring(BridgeName bridge, MirroringDescription mirroringDescription); | ||
38 | + | ||
39 | + /** | ||
40 | + * Removes a mirroring. | ||
41 | + * | ||
42 | + * @param mirroringName mirroring name | ||
43 | + */ | ||
44 | + void deleteMirroring(MirroringName mirroringName); | ||
45 | + | ||
46 | + /** | ||
47 | + * Returns a collection of MirroringStatistics. | ||
48 | + * | ||
49 | + * @return statistics collection | ||
50 | + */ | ||
51 | + Collection<MirroringStatistics> getMirroringStatistics(); | ||
52 | + | ||
53 | +} |
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 org.onlab.packet.VlanId; | ||
21 | +import org.onosproject.net.Annotated; | ||
22 | +import org.onosproject.net.Description; | ||
23 | + | ||
24 | +import java.util.List; | ||
25 | +import java.util.Optional; | ||
26 | + | ||
27 | +/** | ||
28 | + * The abstraction of a mirroring. Port mirroring is a method of monitoring | ||
29 | + * network traffic that forwards a copy of each incoming or outgoing packet from | ||
30 | + * one port (Monitor port) on a network switch to another port (Mirror port) | ||
31 | + * where the packet can be analyzed. | ||
32 | + */ | ||
33 | +@Beta | ||
34 | +public interface MirroringDescription extends Description, Annotated { | ||
35 | + | ||
36 | + /** | ||
37 | + * Returns mirroring name. | ||
38 | + * | ||
39 | + * @return mirroring name | ||
40 | + */ | ||
41 | + MirroringName name(); | ||
42 | + | ||
43 | + /** | ||
44 | + * Returns src ports to monitor. | ||
45 | + * If it is empty, then no src port has | ||
46 | + * to be monitored. | ||
47 | + * | ||
48 | + * @return set of src ports to monitor | ||
49 | + */ | ||
50 | + List<String> monitorSrcPorts(); | ||
51 | + | ||
52 | + /** | ||
53 | + * Returns dst ports to monitor. | ||
54 | + * If it is empty, then no dst port has | ||
55 | + * to be monitored. | ||
56 | + * | ||
57 | + * @return set of dst ports to monitor | ||
58 | + */ | ||
59 | + List<String> monitorDstPorts(); | ||
60 | + | ||
61 | + /** | ||
62 | + * Returns vlans to monitor. | ||
63 | + * If it is empty, then no vlan has | ||
64 | + * to be monitored. | ||
65 | + * | ||
66 | + * @return monitored vlan | ||
67 | + */ | ||
68 | + List<VlanId> monitorVlans(); | ||
69 | + | ||
70 | + /** | ||
71 | + * Returns mirror port. | ||
72 | + * If it is not set, then no destination | ||
73 | + * port for mirrored packets. | ||
74 | + * | ||
75 | + * @return mirror port | ||
76 | + */ | ||
77 | + Optional<String> mirrorPort(); | ||
78 | + | ||
79 | + /** | ||
80 | + * Returns mirror vlan. | ||
81 | + * If it is not set then no destination | ||
82 | + * vlan for mirrored packets. | ||
83 | + * | ||
84 | + * @return mirror vlan | ||
85 | + */ | ||
86 | + Optional<VlanId> mirrorVlan(); | ||
87 | + | ||
88 | +} |
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.base.MoreObjects; | ||
20 | + | ||
21 | +import java.util.Objects; | ||
22 | + | ||
23 | +/** | ||
24 | + * Represents for a mirroring name. | ||
25 | + */ | ||
26 | +public final class MirroringName { | ||
27 | + | ||
28 | + private final String name; | ||
29 | + | ||
30 | + private MirroringName(String name) { | ||
31 | + this.name = name; | ||
32 | + } | ||
33 | + | ||
34 | + /** | ||
35 | + * Creates a mirroring name using the supplied string. | ||
36 | + * | ||
37 | + * @param name mirroring name | ||
38 | + * @return a port mirroring name | ||
39 | + */ | ||
40 | + public static MirroringName mirroringName(String name) { | ||
41 | + return new MirroringName(name); | ||
42 | + } | ||
43 | + | ||
44 | + /** | ||
45 | + * Returns the mirroring name string. | ||
46 | + * | ||
47 | + * @return name string | ||
48 | + */ | ||
49 | + public String name() { | ||
50 | + return name; | ||
51 | + } | ||
52 | + | ||
53 | + @Override | ||
54 | + public int hashCode() { | ||
55 | + return name.hashCode(); | ||
56 | + } | ||
57 | + | ||
58 | + @Override | ||
59 | + public boolean equals(Object obj) { | ||
60 | + if (this == obj) { | ||
61 | + return true; | ||
62 | + } | ||
63 | + if (obj instanceof MirroringName) { | ||
64 | + final MirroringName that = (MirroringName) obj; | ||
65 | + return this.getClass() == that.getClass() && | ||
66 | + Objects.equals(this.name, that.name); | ||
67 | + } | ||
68 | + return false; | ||
69 | + } | ||
70 | + | ||
71 | + @Override | ||
72 | + public String toString() { | ||
73 | + return MoreObjects.toStringHelper(getClass()) | ||
74 | + .add("name", name) | ||
75 | + .toString(); | ||
76 | + } | ||
77 | + | ||
78 | +} |
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.base.MoreObjects; | ||
20 | + | ||
21 | +import java.util.Map; | ||
22 | +import java.util.Objects; | ||
23 | + | ||
24 | +/** | ||
25 | + * Represents statistics associated to a mirroring. | ||
26 | + */ | ||
27 | +public final class MirroringStatistics { | ||
28 | + | ||
29 | + private MirroringName mirroringName; | ||
30 | + private int txBytes; | ||
31 | + private int txPackets; | ||
32 | + | ||
33 | + /** | ||
34 | + * Statistics associated to a named mirroring. | ||
35 | + * | ||
36 | + * @param name the name of the mirroring | ||
37 | + * @param bytes transmitted bytes | ||
38 | + * @param packets transmitted packets | ||
39 | + */ | ||
40 | + private MirroringStatistics(String name, int bytes, int packets) { | ||
41 | + this.mirroringName = MirroringName.mirroringName(name); | ||
42 | + this.txBytes = bytes; | ||
43 | + this.txPackets = packets; | ||
44 | + } | ||
45 | + | ||
46 | + /** | ||
47 | + * | ||
48 | + * Creates a MirroringStatistics using the supplied information. | ||
49 | + * | ||
50 | + * @param name the name of the mirroring | ||
51 | + * @param statistics the associated statistics | ||
52 | + * @return the MirroringStatistics object | ||
53 | + */ | ||
54 | + public static MirroringStatistics mirroringStatistics(String name, Map<String, Integer> statistics) { | ||
55 | + return new MirroringStatistics(name, statistics.get("tx_bytes"), statistics.get("tx_packets")); | ||
56 | + } | ||
57 | + | ||
58 | + /** | ||
59 | + * Returns the mirroring name string. | ||
60 | + * | ||
61 | + * @return name string | ||
62 | + */ | ||
63 | + public MirroringName name() { | ||
64 | + return mirroringName; | ||
65 | + } | ||
66 | + | ||
67 | + /** | ||
68 | + * Returns the transmitted bytes. | ||
69 | + * | ||
70 | + * @return the bytes | ||
71 | + */ | ||
72 | + public long bytes() { | ||
73 | + return txBytes; | ||
74 | + } | ||
75 | + | ||
76 | + /** | ||
77 | + * Returns the transmitted packtes. | ||
78 | + * | ||
79 | + * @return the packets | ||
80 | + */ | ||
81 | + public long packtes() { | ||
82 | + return txPackets; | ||
83 | + } | ||
84 | + | ||
85 | + @Override | ||
86 | + public int hashCode() { | ||
87 | + return Objects.hash(name().name(), txBytes, txPackets); | ||
88 | + } | ||
89 | + | ||
90 | + @Override | ||
91 | + public boolean equals(Object obj) { | ||
92 | + if (this == obj) { | ||
93 | + return true; | ||
94 | + } | ||
95 | + if (obj instanceof MirroringStatistics) { | ||
96 | + final MirroringStatistics that = (MirroringStatistics) obj; | ||
97 | + return this.getClass() == that.getClass() && | ||
98 | + Objects.equals(this.mirroringName, that.mirroringName) && | ||
99 | + Objects.equals(this.txBytes, that.txBytes) && | ||
100 | + Objects.equals(this.txPackets, that.txPackets); | ||
101 | + } | ||
102 | + return false; | ||
103 | + } | ||
104 | + | ||
105 | + @Override | ||
106 | + public String toString() { | ||
107 | + return MoreObjects.toStringHelper(getClass()) | ||
108 | + .add("name", name()) | ||
109 | + .add("tx_bytes", bytes()) | ||
110 | + .add("tx_packets", packtes()) | ||
111 | + .toString(); | ||
112 | + } | ||
113 | + | ||
114 | +} |
... | @@ -28,6 +28,7 @@ import org.onosproject.net.driver.AbstractHandlerBehaviour; | ... | @@ -28,6 +28,7 @@ import org.onosproject.net.driver.AbstractHandlerBehaviour; |
28 | import org.onosproject.net.driver.DriverHandler; | 28 | import org.onosproject.net.driver.DriverHandler; |
29 | import org.onosproject.ovsdb.controller.OvsdbBridge; | 29 | import org.onosproject.ovsdb.controller.OvsdbBridge; |
30 | import org.onosproject.ovsdb.controller.OvsdbClientService; | 30 | import org.onosproject.ovsdb.controller.OvsdbClientService; |
31 | +import org.onosproject.ovsdb.controller.OvsdbConstant; | ||
31 | import org.onosproject.ovsdb.controller.OvsdbController; | 32 | import org.onosproject.ovsdb.controller.OvsdbController; |
32 | import org.onosproject.ovsdb.controller.OvsdbNodeId; | 33 | import org.onosproject.ovsdb.controller.OvsdbNodeId; |
33 | 34 | ||
... | @@ -83,7 +84,7 @@ public class OvsdbControllerConfig extends AbstractHandlerBehaviour implements C | ... | @@ -83,7 +84,7 @@ public class OvsdbControllerConfig extends AbstractHandlerBehaviour implements C |
83 | if (nodeIds.size() == 0) { | 84 | if (nodeIds.size() == 0) { |
84 | //TODO decide what port? | 85 | //TODO decide what port? |
85 | ovsController.connect(IpAddress.valueOf(targetIp), | 86 | ovsController.connect(IpAddress.valueOf(targetIp), |
86 | - targetPort == null ? TpPort.tpPort(6640) : targetPort); | 87 | + targetPort == null ? TpPort.tpPort(OvsdbConstant.OVSDBPORT) : targetPort); |
87 | delay(1000); //FIXME... connect is async | 88 | delay(1000); //FIXME... connect is async |
88 | } | 89 | } |
89 | List<OvsdbClientService> clientServices = ovsController.getNodeIds().stream() | 90 | List<OvsdbClientService> clientServices = ovsController.getNodeIds().stream() | ... | ... |
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.drivers.ovsdb; | ||
18 | + | ||
19 | +import org.onlab.packet.IpAddress; | ||
20 | +import org.onlab.packet.TpPort; | ||
21 | +import org.onosproject.net.AnnotationKeys; | ||
22 | +import org.onosproject.net.DeviceId; | ||
23 | +import org.onosproject.net.behaviour.BridgeName; | ||
24 | +import org.onosproject.net.behaviour.MirroringConfig; | ||
25 | +import org.onosproject.net.behaviour.MirroringDescription; | ||
26 | +import org.onosproject.net.behaviour.MirroringStatistics; | ||
27 | +import org.onosproject.net.behaviour.MirroringName; | ||
28 | +import org.onosproject.net.device.DeviceService; | ||
29 | +import org.onosproject.net.driver.AbstractHandlerBehaviour; | ||
30 | +import org.onosproject.net.driver.DriverHandler; | ||
31 | +import org.onosproject.ovsdb.controller.OvsdbBridge; | ||
32 | +import org.onosproject.ovsdb.controller.OvsdbClientService; | ||
33 | +import org.onosproject.ovsdb.controller.OvsdbConstant; | ||
34 | +import org.onosproject.ovsdb.controller.OvsdbController; | ||
35 | +import org.onosproject.ovsdb.controller.OvsdbMirror; | ||
36 | +import org.onosproject.ovsdb.controller.OvsdbNodeId; | ||
37 | +import org.slf4j.Logger; | ||
38 | +import org.slf4j.LoggerFactory; | ||
39 | + | ||
40 | +import java.util.Collection; | ||
41 | +import java.util.List; | ||
42 | +import java.util.stream.Collectors; | ||
43 | + | ||
44 | +import static com.google.common.base.Preconditions.checkArgument; | ||
45 | +import static com.google.common.base.Preconditions.checkState; | ||
46 | +import static org.onlab.util.Tools.delay; | ||
47 | + | ||
48 | +/** | ||
49 | + * Implementation of mirror config which allows to add, delete and get mirrorings statistics. | ||
50 | + */ | ||
51 | +public class OvsdbMirroringConfig extends AbstractHandlerBehaviour implements MirroringConfig { | ||
52 | + | ||
53 | + private static Logger log = LoggerFactory.getLogger(OvsdbMirroringConfig.class); | ||
54 | + | ||
55 | + /** | ||
56 | + * Adds a mirroring with a given description. | ||
57 | + * | ||
58 | + * @param bridge the bridge name | ||
59 | + * @param mirroringDescription mirroring description | ||
60 | + * @return true if succeeds, or false | ||
61 | + */ | ||
62 | + @Override | ||
63 | + public boolean addMirroring(BridgeName bridge, MirroringDescription mirroringDescription) { | ||
64 | + DriverHandler handler = handler(); | ||
65 | + OvsdbClientService ovsdbClient = getOvsdbClientService(handler); | ||
66 | + OvsdbMirror mirror = OvsdbMirror.builder(mirroringDescription).build(); | ||
67 | + return ovsdbClient.createMirror(bridge.name(), mirror); | ||
68 | + } | ||
69 | + | ||
70 | + /** | ||
71 | + * Removes a mirroring. | ||
72 | + * | ||
73 | + * @param mirroringName mirroring name | ||
74 | + */ | ||
75 | + @Override | ||
76 | + public void deleteMirroring(MirroringName mirroringName) { | ||
77 | + DriverHandler handler = handler(); | ||
78 | + OvsdbClientService ovsdbClient = getOvsdbClientService(handler); | ||
79 | + ovsdbClient.dropMirror(mirroringName); | ||
80 | + } | ||
81 | + | ||
82 | + /** | ||
83 | + * Returns a collection of MirroringStatistics. | ||
84 | + * | ||
85 | + * @return statistics collection | ||
86 | + */ | ||
87 | + @Override | ||
88 | + public Collection<MirroringStatistics> getMirroringStatistics() { | ||
89 | + DriverHandler handler = handler(); | ||
90 | + OvsdbClientService ovsdbClient = getOvsdbClientService(handler); | ||
91 | + return ovsdbClient.getMirroringStatistics(handler.data().deviceId()); | ||
92 | + } | ||
93 | + | ||
94 | + /** | ||
95 | + * Helper method which is used for getting OvsdbClientService. | ||
96 | + */ | ||
97 | + private OvsdbClientService getOvsdbClientService(DriverHandler handler) { | ||
98 | + | ||
99 | + OvsdbController ovsController = handler.get(OvsdbController.class); | ||
100 | + DeviceService deviceService = handler.get(DeviceService.class); | ||
101 | + DeviceId deviceId = handler.data().deviceId(); | ||
102 | + | ||
103 | + String[] splits = deviceId.toString().split(":"); | ||
104 | + if (splits == null || splits.length < 1) { | ||
105 | + log.warn("Wrong deviceId format"); | ||
106 | + return null; | ||
107 | + } | ||
108 | + | ||
109 | + /** | ||
110 | + * Each type of device has to be managed in a different way. | ||
111 | + */ | ||
112 | + switch (splits[0]) { | ||
113 | + case "ovsdb": | ||
114 | + OvsdbNodeId nodeId = changeDeviceIdToNodeId(deviceId); | ||
115 | + return ovsController.getOvsdbClient(nodeId); | ||
116 | + case "of": | ||
117 | + String[] mgmtAddress = deviceService.getDevice(deviceId) | ||
118 | + .annotations().value(AnnotationKeys.MANAGEMENT_ADDRESS).split(":"); | ||
119 | + String targetIp = mgmtAddress[0]; | ||
120 | + TpPort targetPort = null; | ||
121 | + if (mgmtAddress.length > 1) { | ||
122 | + targetPort = TpPort.tpPort(Integer.parseInt(mgmtAddress[1])); | ||
123 | + } | ||
124 | + List<OvsdbNodeId> nodeIds = ovsController.getNodeIds().stream() | ||
125 | + .filter(nodeID -> nodeID.getIpAddress().equals(targetIp)) | ||
126 | + .collect(Collectors.toList()); | ||
127 | + if (nodeIds.size() == 0) { | ||
128 | + //TODO decide what port? | ||
129 | + ovsController.connect(IpAddress.valueOf(targetIp), | ||
130 | + targetPort == null ? TpPort.tpPort(OvsdbConstant.OVSDBPORT) : targetPort); | ||
131 | + delay(1000); //FIXME... connect is async | ||
132 | + } | ||
133 | + List<OvsdbClientService> clientServices = ovsController.getNodeIds().stream() | ||
134 | + .filter(nodeID -> nodeID.getIpAddress().equals(targetIp)) | ||
135 | + .map(ovsController::getOvsdbClient) | ||
136 | + .filter(cs -> cs.getBridges().stream().anyMatch(b -> dpidMatches(b, deviceId))) | ||
137 | + .collect(Collectors.toList()); | ||
138 | + checkState(clientServices.size() > 0, "No clientServices found"); | ||
139 | + //FIXME add connection to management address if null --> done ? | ||
140 | + return clientServices.size() > 0 ? clientServices.get(0) : null; | ||
141 | + default: | ||
142 | + log.warn("Unmanaged device type"); | ||
143 | + } | ||
144 | + return null; | ||
145 | + | ||
146 | + } | ||
147 | + | ||
148 | + private static boolean dpidMatches(OvsdbBridge bridge, DeviceId deviceId) { | ||
149 | + checkArgument(bridge.datapathId().isPresent()); | ||
150 | + | ||
151 | + String bridgeDpid = "of:" + bridge.datapathId().get(); | ||
152 | + String ofDpid = deviceId.toString(); | ||
153 | + return bridgeDpid.equals(ofDpid); | ||
154 | + } | ||
155 | + | ||
156 | + /** | ||
157 | + * OvsdbNodeId(IP) is used in the adaptor while DeviceId(ovsdb:IP) | ||
158 | + * is used in the core. So DeviceId need be changed to OvsdbNodeId. | ||
159 | + * | ||
160 | + * @param deviceId the device id in ovsdb:ip format | ||
161 | + * @return the ovsdb node id | ||
162 | + */ | ||
163 | + private OvsdbNodeId changeDeviceIdToNodeId(DeviceId deviceId) { | ||
164 | + String[] splits = deviceId.toString().split(":"); | ||
165 | + if (splits == null || splits.length < 1) { | ||
166 | + return null; | ||
167 | + } | ||
168 | + IpAddress ipAddress = IpAddress.valueOf(splits[1]); | ||
169 | + return new OvsdbNodeId(ipAddress, 0); | ||
170 | + } | ||
171 | + | ||
172 | +} |
... | @@ -28,6 +28,8 @@ | ... | @@ -28,6 +28,8 @@ |
28 | manufacturer="Nicira, Inc\." hwVersion="Open vSwitch" swVersion="2\..*"> | 28 | manufacturer="Nicira, Inc\." hwVersion="Open vSwitch" swVersion="2\..*"> |
29 | <behaviour api="org.onosproject.net.behaviour.ControllerConfig" | 29 | <behaviour api="org.onosproject.net.behaviour.ControllerConfig" |
30 | impl="org.onosproject.drivers.ovsdb.OvsdbControllerConfig"/> | 30 | impl="org.onosproject.drivers.ovsdb.OvsdbControllerConfig"/> |
31 | + <behaviour api="org.onosproject.net.behaviour.MirroringConfig" | ||
32 | + impl="org.onosproject.drivers.ovsdb.OvsdbMirroringConfig"/> | ||
31 | </driver> | 33 | </driver> |
32 | </drivers> | 34 | </drivers> |
33 | 35 | ... | ... |
... | @@ -19,6 +19,8 @@ import com.google.common.util.concurrent.ListenableFuture; | ... | @@ -19,6 +19,8 @@ import com.google.common.util.concurrent.ListenableFuture; |
19 | import org.onlab.packet.IpAddress; | 19 | import org.onlab.packet.IpAddress; |
20 | import org.onosproject.net.DeviceId; | 20 | import org.onosproject.net.DeviceId; |
21 | import org.onosproject.net.behaviour.ControllerInfo; | 21 | import org.onosproject.net.behaviour.ControllerInfo; |
22 | +import org.onosproject.net.behaviour.MirroringStatistics; | ||
23 | +import org.onosproject.net.behaviour.MirroringName; | ||
22 | import org.onosproject.ovsdb.rfc.jsonrpc.OvsdbRpc; | 24 | import org.onosproject.ovsdb.rfc.jsonrpc.OvsdbRpc; |
23 | import org.onosproject.ovsdb.rfc.message.TableUpdates; | 25 | import org.onosproject.ovsdb.rfc.message.TableUpdates; |
24 | import org.onosproject.ovsdb.rfc.notation.Row; | 26 | import org.onosproject.ovsdb.rfc.notation.Row; |
... | @@ -40,6 +42,41 @@ public interface OvsdbClientService extends OvsdbRpc { | ... | @@ -40,6 +42,41 @@ public interface OvsdbClientService extends OvsdbRpc { |
40 | OvsdbNodeId nodeId(); | 42 | OvsdbNodeId nodeId(); |
41 | 43 | ||
42 | /** | 44 | /** |
45 | + * Creates a mirror port. Mirrors the traffic | ||
46 | + * that goes to selectDstPort or comes from | ||
47 | + * selectSrcPort or packets containing selectVlan | ||
48 | + * to mirrorPort or to all ports that trunk mirrorVlan. | ||
49 | + * | ||
50 | + * @param bridgeName the name of the bridge | ||
51 | + * @param mirror the OVSDB mirror description | ||
52 | + * @return true if mirror creation is successful, false otherwise | ||
53 | + */ | ||
54 | + boolean createMirror(String bridgeName, OvsdbMirror mirror); | ||
55 | + | ||
56 | + /** | ||
57 | + * Gets the Mirror uuid. | ||
58 | + * | ||
59 | + * @param mirrorName mirror name | ||
60 | + * @return mirror uuid, empty if no uuid is found | ||
61 | + */ | ||
62 | + String getMirrorUuid(String mirrorName); | ||
63 | + | ||
64 | + /** | ||
65 | + * Gets mirroring statistics of the device. | ||
66 | + * | ||
67 | + * @param deviceId target device id | ||
68 | + * @return set of mirroring statistics; empty if no mirror is found | ||
69 | + */ | ||
70 | + Set<MirroringStatistics> getMirroringStatistics(DeviceId deviceId); | ||
71 | + | ||
72 | + /** | ||
73 | + * Drops the configuration for mirror. | ||
74 | + * | ||
75 | + * @param mirroringName | ||
76 | + */ | ||
77 | + void dropMirror(MirroringName mirroringName); | ||
78 | + | ||
79 | + /** | ||
43 | * Creates a tunnel port with given options. | 80 | * Creates a tunnel port with given options. |
44 | * | 81 | * |
45 | * @deprecated version 1.7.0 - Hummingbird | 82 | * @deprecated version 1.7.0 - Hummingbird | ... | ... |
... | @@ -41,6 +41,7 @@ public final class OvsdbConstant { | ... | @@ -41,6 +41,7 @@ public final class OvsdbConstant { |
41 | /** Bridge table. */ | 41 | /** Bridge table. */ |
42 | public static final String BRIDGE = "Bridge"; | 42 | public static final String BRIDGE = "Bridge"; |
43 | public static final String PORTS = "ports"; | 43 | public static final String PORTS = "ports"; |
44 | + public static final String MIRRORS = "mirrors"; | ||
44 | // other configs | 45 | // other configs |
45 | public static final String DATAPATH_ID = "datapath-id"; | 46 | public static final String DATAPATH_ID = "datapath-id"; |
46 | public static final String DISABLE_INBAND = "disable-in-band"; | 47 | public static final String DISABLE_INBAND = "disable-in-band"; |
... | @@ -66,6 +67,9 @@ public final class OvsdbConstant { | ... | @@ -66,6 +67,9 @@ public final class OvsdbConstant { |
66 | /** Controller table. */ | 67 | /** Controller table. */ |
67 | public static final String CONTROLLER = "Controller"; | 68 | public static final String CONTROLLER = "Controller"; |
68 | 69 | ||
70 | + /** Mirror table. */ | ||
71 | + public static final String MIRROR = "Mirror"; | ||
72 | + | ||
69 | /** Ovsdb bridge name. */ | 73 | /** Ovsdb bridge name. */ |
70 | // TODO remove this particular bridge name from OVSDB provider | 74 | // TODO remove this particular bridge name from OVSDB provider |
71 | public static final String INTEGRATION_BRIDGE = "br-int"; | 75 | public static final String INTEGRATION_BRIDGE = "br-int"; | ... | ... |
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
... | @@ -22,9 +22,12 @@ import com.google.common.util.concurrent.ListenableFuture; | ... | @@ -22,9 +22,12 @@ import com.google.common.util.concurrent.ListenableFuture; |
22 | import org.onlab.packet.IpAddress; | 22 | import org.onlab.packet.IpAddress; |
23 | import org.onosproject.net.DeviceId; | 23 | import org.onosproject.net.DeviceId; |
24 | import org.onosproject.net.behaviour.ControllerInfo; | 24 | import org.onosproject.net.behaviour.ControllerInfo; |
25 | +import org.onosproject.net.behaviour.MirroringStatistics; | ||
26 | +import org.onosproject.net.behaviour.MirroringName; | ||
25 | import org.onosproject.ovsdb.controller.OvsdbBridge; | 27 | import org.onosproject.ovsdb.controller.OvsdbBridge; |
26 | import org.onosproject.ovsdb.controller.OvsdbClientService; | 28 | import org.onosproject.ovsdb.controller.OvsdbClientService; |
27 | import org.onosproject.ovsdb.controller.OvsdbInterface; | 29 | import org.onosproject.ovsdb.controller.OvsdbInterface; |
30 | +import org.onosproject.ovsdb.controller.OvsdbMirror; | ||
28 | import org.onosproject.ovsdb.controller.OvsdbNodeId; | 31 | import org.onosproject.ovsdb.controller.OvsdbNodeId; |
29 | import org.onosproject.ovsdb.controller.OvsdbPort; | 32 | import org.onosproject.ovsdb.controller.OvsdbPort; |
30 | import org.onosproject.ovsdb.rfc.message.TableUpdates; | 33 | import org.onosproject.ovsdb.rfc.message.TableUpdates; |
... | @@ -46,6 +49,54 @@ public class OvsdbClientServiceAdapter implements OvsdbClientService { | ... | @@ -46,6 +49,54 @@ public class OvsdbClientServiceAdapter implements OvsdbClientService { |
46 | return null; | 49 | return null; |
47 | } | 50 | } |
48 | 51 | ||
52 | + /** | ||
53 | + * Creates a mirror port. Mirrors the traffic | ||
54 | + * that goes to selectDstPort or comes from | ||
55 | + * selectSrcPort or packets containing selectVlan | ||
56 | + * to mirrorPort or to all ports that trunk mirrorVlan. | ||
57 | + * | ||
58 | + * @param bridgeName the name of the bridge | ||
59 | + * @param mirror the OVSDB mirror description | ||
60 | + * @return true if mirror creation is successful, false otherwise | ||
61 | + */ | ||
62 | + @Override | ||
63 | + public boolean createMirror(String bridgeName, OvsdbMirror mirror) { | ||
64 | + return true; | ||
65 | + } | ||
66 | + | ||
67 | + /** | ||
68 | + * Gets the Mirror uuid. | ||
69 | + * | ||
70 | + * @param mirrorName mirror name | ||
71 | + * @return mirror uuid, empty if no uuid is found | ||
72 | + */ | ||
73 | + @Override | ||
74 | + public String getMirrorUuid(String mirrorName) { | ||
75 | + return null; | ||
76 | + } | ||
77 | + | ||
78 | + /** | ||
79 | + * Gets mirroring statistics of the device. | ||
80 | + * | ||
81 | + * @param deviceId target device id | ||
82 | + * @return set of mirroring statistics; empty if no mirror is found | ||
83 | + */ | ||
84 | + @Override | ||
85 | + public Set<MirroringStatistics> getMirroringStatistics(DeviceId deviceId) { | ||
86 | + return null; | ||
87 | + } | ||
88 | + | ||
89 | + | ||
90 | + /** | ||
91 | + * Drops the configuration for mirror. | ||
92 | + * | ||
93 | + * @param mirroringName | ||
94 | + */ | ||
95 | + @Override | ||
96 | + public void dropMirror(MirroringName mirroringName) { | ||
97 | + | ||
98 | + } | ||
99 | + | ||
49 | @Override | 100 | @Override |
50 | public boolean createTunnel(String bridgeName, String portName, String tunnelType, Map<String, String> options) { | 101 | public boolean createTunnel(String bridgeName, String portName, String tunnelType, Map<String, String> options) { |
51 | return true; | 102 | return true; | ... | ... |
... | @@ -203,7 +203,7 @@ public class Mirror extends AbstractOvsdbTableService { | ... | @@ -203,7 +203,7 @@ public class Mirror extends AbstractOvsdbTableService { |
203 | * of attributes. | 203 | * of attributes. |
204 | * @param outputVlan the column data which column name is "output_vlan" | 204 | * @param outputVlan the column data which column name is "output_vlan" |
205 | */ | 205 | */ |
206 | - public void setOutputVlan(Set<Short> outputVlan) { | 206 | + public void setOutputVlan(Short outputVlan) { |
207 | ColumnDescription columndesc = new ColumnDescription(MirrorColumn.OUTPUTVLAN.columnName(), | 207 | ColumnDescription columndesc = new ColumnDescription(MirrorColumn.OUTPUTVLAN.columnName(), |
208 | "setOutputVlan", VersionNum.VERSION100); | 208 | "setOutputVlan", VersionNum.VERSION100); |
209 | super.setDataHandler(columndesc, outputVlan); | 209 | super.setDataHandler(columndesc, outputVlan); | ... | ... |
-
Please register or login to post a comment