Thomas Vachuska | 781d18b | 2014-10-27 10:31:25 -0700 | [diff] [blame] | 1 | /* |
Ray Milkey | 34c9590 | 2015-04-15 09:47:53 -0700 | [diff] [blame] | 2 | * Copyright 2014-2015 Open Networking Laboratory |
Thomas Vachuska | 781d18b | 2014-10-27 10:31:25 -0700 | [diff] [blame] | 3 | * |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 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 |
Thomas Vachuska | 781d18b | 2014-10-27 10:31:25 -0700 | [diff] [blame] | 7 | * |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 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. |
Thomas Vachuska | 781d18b | 2014-10-27 10:31:25 -0700 | [diff] [blame] | 15 | */ |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 16 | package org.onosproject.fwd; |
alshabib | 030111e | 2014-09-15 15:56:42 -0700 | [diff] [blame] | 17 | |
Sahil Lele | a69534f | 2015-07-16 15:14:57 -0700 | [diff] [blame] | 18 | import com.google.common.collect.ImmutableSet; |
alshabib | 030111e | 2014-09-15 15:56:42 -0700 | [diff] [blame] | 19 | import org.apache.felix.scr.annotations.Activate; |
| 20 | import org.apache.felix.scr.annotations.Component; |
| 21 | import org.apache.felix.scr.annotations.Deactivate; |
tom | c16656f | 2014-10-15 18:30:31 -0700 | [diff] [blame] | 22 | import org.apache.felix.scr.annotations.Modified; |
| 23 | import org.apache.felix.scr.annotations.Property; |
alshabib | 030111e | 2014-09-15 15:56:42 -0700 | [diff] [blame] | 24 | import org.apache.felix.scr.annotations.Reference; |
| 25 | import org.apache.felix.scr.annotations.ReferenceCardinality; |
Jonathan Hart | e8600eb | 2015-01-12 10:30:45 -0800 | [diff] [blame] | 26 | import org.onlab.packet.Ethernet; |
Dusan Pajin | 0d1d48f | 2015-02-20 16:05:11 +0100 | [diff] [blame] | 27 | import org.onlab.packet.ICMP; |
| 28 | import org.onlab.packet.ICMP6; |
Jonathan Hart | 430223a | 2015-04-22 17:39:02 -0700 | [diff] [blame] | 29 | import org.onlab.packet.IPv4; |
| 30 | import org.onlab.packet.IPv6; |
Dusan Pajin | 0d1d48f | 2015-02-20 16:05:11 +0100 | [diff] [blame] | 31 | import org.onlab.packet.Ip4Prefix; |
| 32 | import org.onlab.packet.Ip6Prefix; |
Sahil Lele | a69534f | 2015-07-16 15:14:57 -0700 | [diff] [blame] | 33 | import org.onlab.packet.MacAddress; |
Jonathan Hart | 430223a | 2015-04-22 17:39:02 -0700 | [diff] [blame] | 34 | import org.onlab.packet.TCP; |
Hyunsun Moon | cf732fb | 2015-08-22 21:04:23 -0700 | [diff] [blame] | 35 | import org.onlab.packet.TpPort; |
Jonathan Hart | 430223a | 2015-04-22 17:39:02 -0700 | [diff] [blame] | 36 | import org.onlab.packet.UDP; |
Dusan Pajin | 0d1d48f | 2015-02-20 16:05:11 +0100 | [diff] [blame] | 37 | import org.onlab.packet.VlanId; |
Thomas Vachuska | 6519e6f | 2015-03-11 02:29:31 -0700 | [diff] [blame] | 38 | import org.onosproject.cfg.ComponentConfigService; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 39 | import org.onosproject.core.ApplicationId; |
| 40 | import org.onosproject.core.CoreService; |
Sahil Lele | a69534f | 2015-07-16 15:14:57 -0700 | [diff] [blame] | 41 | import org.onosproject.event.Event; |
| 42 | import org.onosproject.net.ConnectPoint; |
| 43 | import org.onosproject.net.DeviceId; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 44 | import org.onosproject.net.Host; |
| 45 | import org.onosproject.net.HostId; |
Sahil Lele | a69534f | 2015-07-16 15:14:57 -0700 | [diff] [blame] | 46 | import org.onosproject.net.Link; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 47 | import org.onosproject.net.Path; |
| 48 | import org.onosproject.net.PortNumber; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 49 | import org.onosproject.net.flow.DefaultTrafficSelector; |
| 50 | import org.onosproject.net.flow.DefaultTrafficTreatment; |
Sahil Lele | a69534f | 2015-07-16 15:14:57 -0700 | [diff] [blame] | 51 | import org.onosproject.net.flow.FlowEntry; |
| 52 | import org.onosproject.net.flow.FlowRule; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 53 | import org.onosproject.net.flow.FlowRuleService; |
| 54 | import org.onosproject.net.flow.TrafficSelector; |
| 55 | import org.onosproject.net.flow.TrafficTreatment; |
Sahil Lele | a69534f | 2015-07-16 15:14:57 -0700 | [diff] [blame] | 56 | import org.onosproject.net.flow.criteria.Criterion; |
| 57 | import org.onosproject.net.flow.criteria.EthCriterion; |
| 58 | import org.onosproject.net.flow.instructions.Instruction; |
| 59 | import org.onosproject.net.flow.instructions.Instructions; |
Jonathan Hart | 3b881aa | 2015-04-22 18:03:50 -0700 | [diff] [blame] | 60 | import org.onosproject.net.flowobjective.DefaultForwardingObjective; |
| 61 | import org.onosproject.net.flowobjective.FlowObjectiveService; |
| 62 | import org.onosproject.net.flowobjective.ForwardingObjective; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 63 | import org.onosproject.net.host.HostService; |
Sahil Lele | a69534f | 2015-07-16 15:14:57 -0700 | [diff] [blame] | 64 | import org.onosproject.net.link.LinkEvent; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 65 | import org.onosproject.net.packet.InboundPacket; |
| 66 | import org.onosproject.net.packet.PacketContext; |
Jonathan Hart | 3cfce8e | 2015-01-14 16:43:27 -0800 | [diff] [blame] | 67 | import org.onosproject.net.packet.PacketPriority; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 68 | import org.onosproject.net.packet.PacketProcessor; |
| 69 | import org.onosproject.net.packet.PacketService; |
Sahil Lele | a69534f | 2015-07-16 15:14:57 -0700 | [diff] [blame] | 70 | import org.onosproject.net.topology.TopologyEvent; |
| 71 | import org.onosproject.net.topology.TopologyListener; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 72 | import org.onosproject.net.topology.TopologyService; |
tom | c16656f | 2014-10-15 18:30:31 -0700 | [diff] [blame] | 73 | import org.osgi.service.component.ComponentContext; |
tom | c370ebd | 2014-09-16 01:25:21 -0700 | [diff] [blame] | 74 | import org.slf4j.Logger; |
alshabib | 030111e | 2014-09-15 15:56:42 -0700 | [diff] [blame] | 75 | |
Jonathan Hart | 430223a | 2015-04-22 17:39:02 -0700 | [diff] [blame] | 76 | import java.util.Dictionary; |
Sahil Lele | 7b96166 | 2015-07-20 15:06:04 -0700 | [diff] [blame] | 77 | import java.util.HashMap; |
Sahil Lele | a69534f | 2015-07-16 15:14:57 -0700 | [diff] [blame] | 78 | import java.util.List; |
Sahil Lele | 7b96166 | 2015-07-20 15:06:04 -0700 | [diff] [blame] | 79 | import java.util.Map; |
Sahil Lele | a69534f | 2015-07-16 15:14:57 -0700 | [diff] [blame] | 80 | import java.util.Objects; |
Jonathan Hart | 430223a | 2015-04-22 17:39:02 -0700 | [diff] [blame] | 81 | import java.util.Set; |
| 82 | |
| 83 | import static com.google.common.base.Strings.isNullOrEmpty; |
| 84 | import static org.slf4j.LoggerFactory.getLogger; |
| 85 | |
tom | c370ebd | 2014-09-16 01:25:21 -0700 | [diff] [blame] | 86 | /** |
| 87 | * Sample reactive forwarding application. |
| 88 | */ |
| 89 | @Component(immediate = true) |
alshabib | 030111e | 2014-09-15 15:56:42 -0700 | [diff] [blame] | 90 | public class ReactiveForwarding { |
| 91 | |
Dusan Pajin | 0d1d48f | 2015-02-20 16:05:11 +0100 | [diff] [blame] | 92 | private static final int DEFAULT_TIMEOUT = 10; |
| 93 | private static final int DEFAULT_PRIORITY = 10; |
alshabib | ba5ac48 | 2014-10-02 17:15:20 -0700 | [diff] [blame] | 94 | |
tom | c370ebd | 2014-09-16 01:25:21 -0700 | [diff] [blame] | 95 | private final Logger log = getLogger(getClass()); |
| 96 | |
alshabib | 030111e | 2014-09-15 15:56:42 -0700 | [diff] [blame] | 97 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 98 | protected TopologyService topologyService; |
| 99 | |
| 100 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 101 | protected PacketService packetService; |
| 102 | |
alshabib | 8aef1ad | 2014-09-15 17:47:31 -0700 | [diff] [blame] | 103 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 104 | protected HostService hostService; |
| 105 | |
alshabib | 7b2748f | 2014-09-16 20:21:11 -0700 | [diff] [blame] | 106 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 107 | protected FlowRuleService flowRuleService; |
| 108 | |
alshabib | 92c65ad | 2014-10-08 21:56:05 -0700 | [diff] [blame] | 109 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
Jonathan Hart | 3b881aa | 2015-04-22 18:03:50 -0700 | [diff] [blame] | 110 | protected FlowObjectiveService flowObjectiveService; |
| 111 | |
| 112 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
alshabib | 92c65ad | 2014-10-08 21:56:05 -0700 | [diff] [blame] | 113 | protected CoreService coreService; |
| 114 | |
Thomas Vachuska | 6519e6f | 2015-03-11 02:29:31 -0700 | [diff] [blame] | 115 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 116 | protected ComponentConfigService cfgService; |
| 117 | |
tom | c370ebd | 2014-09-16 01:25:21 -0700 | [diff] [blame] | 118 | private ReactivePacketProcessor processor = new ReactivePacketProcessor(); |
alshabib | 030111e | 2014-09-15 15:56:42 -0700 | [diff] [blame] | 119 | |
alshabib | a68eb96 | 2014-09-24 20:34:13 -0700 | [diff] [blame] | 120 | private ApplicationId appId; |
| 121 | |
Thomas Vachuska | bd7f4b3 | 2014-12-04 20:54:55 -0800 | [diff] [blame] | 122 | @Property(name = "packetOutOnly", boolValue = false, |
| 123 | label = "Enable packet-out only forwarding; default is false") |
| 124 | private boolean packetOutOnly = false; |
tom | c16656f | 2014-10-15 18:30:31 -0700 | [diff] [blame] | 125 | |
Dusan Pajin | 0d1d48f | 2015-02-20 16:05:11 +0100 | [diff] [blame] | 126 | @Property(name = "packetOutOfppTable", boolValue = false, |
| 127 | label = "Enable first packet forwarding using OFPP_TABLE port " + |
Thomas Vachuska | 27bee09 | 2015-06-23 19:03:10 -0700 | [diff] [blame] | 128 | "instead of PacketOut with actual port; default is false") |
Dusan Pajin | 0d1d48f | 2015-02-20 16:05:11 +0100 | [diff] [blame] | 129 | private boolean packetOutOfppTable = false; |
| 130 | |
| 131 | @Property(name = "flowTimeout", intValue = DEFAULT_TIMEOUT, |
| 132 | label = "Configure Flow Timeout for installed flow rules; " + |
Thomas Vachuska | 27bee09 | 2015-06-23 19:03:10 -0700 | [diff] [blame] | 133 | "default is 10 sec") |
Dusan Pajin | 0d1d48f | 2015-02-20 16:05:11 +0100 | [diff] [blame] | 134 | private int flowTimeout = DEFAULT_TIMEOUT; |
| 135 | |
| 136 | @Property(name = "flowPriority", intValue = DEFAULT_PRIORITY, |
| 137 | label = "Configure Flow Priority for installed flow rules; " + |
Thomas Vachuska | 27bee09 | 2015-06-23 19:03:10 -0700 | [diff] [blame] | 138 | "default is 10") |
Dusan Pajin | 0d1d48f | 2015-02-20 16:05:11 +0100 | [diff] [blame] | 139 | private int flowPriority = DEFAULT_PRIORITY; |
| 140 | |
Kunihiro Ishiguro | d37c9ca | 2014-12-31 16:05:40 +0900 | [diff] [blame] | 141 | @Property(name = "ipv6Forwarding", boolValue = false, |
| 142 | label = "Enable IPv6 forwarding; default is false") |
| 143 | private boolean ipv6Forwarding = false; |
| 144 | |
Dusan Pajin | 0d1d48f | 2015-02-20 16:05:11 +0100 | [diff] [blame] | 145 | @Property(name = "matchDstMacOnly", boolValue = false, |
| 146 | label = "Enable matching Dst Mac Only; default is false") |
| 147 | private boolean matchDstMacOnly = false; |
| 148 | |
| 149 | @Property(name = "matchVlanId", boolValue = false, |
| 150 | label = "Enable matching Vlan ID; default is false") |
| 151 | private boolean matchVlanId = false; |
| 152 | |
| 153 | @Property(name = "matchIpv4Address", boolValue = false, |
| 154 | label = "Enable matching IPv4 Addresses; default is false") |
| 155 | private boolean matchIpv4Address = false; |
| 156 | |
| 157 | @Property(name = "matchIpv4Dscp", boolValue = false, |
| 158 | label = "Enable matching IPv4 DSCP and ECN; default is false") |
| 159 | private boolean matchIpv4Dscp = false; |
| 160 | |
| 161 | @Property(name = "matchIpv6Address", boolValue = false, |
| 162 | label = "Enable matching IPv6 Addresses; default is false") |
| 163 | private boolean matchIpv6Address = false; |
| 164 | |
| 165 | @Property(name = "matchIpv6FlowLabel", boolValue = false, |
| 166 | label = "Enable matching IPv6 FlowLabel; default is false") |
| 167 | private boolean matchIpv6FlowLabel = false; |
| 168 | |
| 169 | @Property(name = "matchTcpUdpPorts", boolValue = false, |
| 170 | label = "Enable matching TCP/UDP ports; default is false") |
| 171 | private boolean matchTcpUdpPorts = false; |
| 172 | |
| 173 | @Property(name = "matchIcmpFields", boolValue = false, |
| 174 | label = "Enable matching ICMPv4 and ICMPv6 fields; " + |
Thomas Vachuska | 27bee09 | 2015-06-23 19:03:10 -0700 | [diff] [blame] | 175 | "default is false") |
Dusan Pajin | 0d1d48f | 2015-02-20 16:05:11 +0100 | [diff] [blame] | 176 | private boolean matchIcmpFields = false; |
| 177 | |
Sahil Lele | a69534f | 2015-07-16 15:14:57 -0700 | [diff] [blame] | 178 | |
Rusty Eddy | 29acad6 | 2015-07-07 19:33:47 -0700 | [diff] [blame] | 179 | @Property(name = "ignoreIPv4Multicast", boolValue = false, |
| 180 | label = "Ignore (do not forward) IPv4 multicast packets; default is false") |
| 181 | private boolean ignoreIpv4McastPackets = false; |
Dusan Pajin | 0d1d48f | 2015-02-20 16:05:11 +0100 | [diff] [blame] | 182 | |
Sahil Lele | a69534f | 2015-07-16 15:14:57 -0700 | [diff] [blame] | 183 | private final TopologyListener topologyListener = new InternalTopologyListener(); |
| 184 | |
| 185 | |
alshabib | 030111e | 2014-09-15 15:56:42 -0700 | [diff] [blame] | 186 | @Activate |
Kunihiro Ishiguro | d37c9ca | 2014-12-31 16:05:40 +0900 | [diff] [blame] | 187 | public void activate(ComponentContext context) { |
Thomas Vachuska | 6519e6f | 2015-03-11 02:29:31 -0700 | [diff] [blame] | 188 | cfgService.registerProperties(getClass()); |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 189 | appId = coreService.registerApplication("org.onosproject.fwd"); |
Jonathan Hart | 3cfce8e | 2015-01-14 16:43:27 -0800 | [diff] [blame] | 190 | |
Brian O'Connor | 3b78326 | 2015-07-29 17:49:24 -0700 | [diff] [blame] | 191 | packetService.addProcessor(processor, PacketProcessor.director(2)); |
Sahil Lele | a69534f | 2015-07-16 15:14:57 -0700 | [diff] [blame] | 192 | topologyService.addListener(topologyListener); |
Kunihiro Ishiguro | d37c9ca | 2014-12-31 16:05:40 +0900 | [diff] [blame] | 193 | readComponentConfiguration(context); |
Thomas Vachuska | 27bee09 | 2015-06-23 19:03:10 -0700 | [diff] [blame] | 194 | requestIntercepts(); |
Jonathan Hart | 3cfce8e | 2015-01-14 16:43:27 -0800 | [diff] [blame] | 195 | |
Thomas Vachuska | 8d03367 | 2015-07-21 16:15:04 -0700 | [diff] [blame] | 196 | log.info("Started", appId.id()); |
Charles M.C. Chan | e148de8 | 2015-05-06 12:38:21 +0800 | [diff] [blame] | 197 | } |
| 198 | |
| 199 | @Deactivate |
| 200 | public void deactivate() { |
Charles M.C. Chan | e148de8 | 2015-05-06 12:38:21 +0800 | [diff] [blame] | 201 | cfgService.unregisterProperties(getClass(), false); |
Thomas Vachuska | 27bee09 | 2015-06-23 19:03:10 -0700 | [diff] [blame] | 202 | withdrawIntercepts(); |
Charles M.C. Chan | e148de8 | 2015-05-06 12:38:21 +0800 | [diff] [blame] | 203 | flowRuleService.removeFlowRulesById(appId); |
| 204 | packetService.removeProcessor(processor); |
Sahil Lele | a69534f | 2015-07-16 15:14:57 -0700 | [diff] [blame] | 205 | topologyService.removeListener(topologyListener); |
Charles M.C. Chan | e148de8 | 2015-05-06 12:38:21 +0800 | [diff] [blame] | 206 | processor = null; |
| 207 | log.info("Stopped"); |
| 208 | } |
| 209 | |
| 210 | @Modified |
| 211 | public void modified(ComponentContext context) { |
Charles M.C. Chan | e148de8 | 2015-05-06 12:38:21 +0800 | [diff] [blame] | 212 | readComponentConfiguration(context); |
Thomas Vachuska | 27bee09 | 2015-06-23 19:03:10 -0700 | [diff] [blame] | 213 | requestIntercepts(); |
Charles M.C. Chan | e148de8 | 2015-05-06 12:38:21 +0800 | [diff] [blame] | 214 | } |
| 215 | |
| 216 | /** |
Thomas Vachuska | 8d03367 | 2015-07-21 16:15:04 -0700 | [diff] [blame] | 217 | * Request packet in via packet service. |
Charles M.C. Chan | e148de8 | 2015-05-06 12:38:21 +0800 | [diff] [blame] | 218 | */ |
Thomas Vachuska | 27bee09 | 2015-06-23 19:03:10 -0700 | [diff] [blame] | 219 | private void requestIntercepts() { |
Jonathan Hart | 3cfce8e | 2015-01-14 16:43:27 -0800 | [diff] [blame] | 220 | TrafficSelector.Builder selector = DefaultTrafficSelector.builder(); |
| 221 | selector.matchEthType(Ethernet.TYPE_IPV4); |
Thomas Vachuska | 27bee09 | 2015-06-23 19:03:10 -0700 | [diff] [blame] | 222 | packetService.requestPackets(selector.build(), PacketPriority.REACTIVE, appId); |
Dusan Pajin | 0d1d48f | 2015-02-20 16:05:11 +0100 | [diff] [blame] | 223 | selector.matchEthType(Ethernet.TYPE_ARP); |
Thomas Vachuska | 27bee09 | 2015-06-23 19:03:10 -0700 | [diff] [blame] | 224 | packetService.requestPackets(selector.build(), PacketPriority.REACTIVE, appId); |
Dusan Pajin | 0d1d48f | 2015-02-20 16:05:11 +0100 | [diff] [blame] | 225 | |
Thomas Vachuska | 27bee09 | 2015-06-23 19:03:10 -0700 | [diff] [blame] | 226 | selector.matchEthType(Ethernet.TYPE_IPV6); |
Dusan Pajin | 0d1d48f | 2015-02-20 16:05:11 +0100 | [diff] [blame] | 227 | if (ipv6Forwarding) { |
Thomas Vachuska | 27bee09 | 2015-06-23 19:03:10 -0700 | [diff] [blame] | 228 | packetService.requestPackets(selector.build(), PacketPriority.REACTIVE, appId); |
| 229 | } else { |
| 230 | packetService.cancelPackets(selector.build(), PacketPriority.REACTIVE, appId); |
Dusan Pajin | 0d1d48f | 2015-02-20 16:05:11 +0100 | [diff] [blame] | 231 | } |
Kunihiro Ishiguro | d37c9ca | 2014-12-31 16:05:40 +0900 | [diff] [blame] | 232 | } |
| 233 | |
| 234 | /** |
Thomas Vachuska | 8d03367 | 2015-07-21 16:15:04 -0700 | [diff] [blame] | 235 | * Cancel request for packet in via packet service. |
Thomas Vachuska | 27bee09 | 2015-06-23 19:03:10 -0700 | [diff] [blame] | 236 | */ |
| 237 | private void withdrawIntercepts() { |
| 238 | TrafficSelector.Builder selector = DefaultTrafficSelector.builder(); |
| 239 | selector.matchEthType(Ethernet.TYPE_IPV4); |
| 240 | packetService.cancelPackets(selector.build(), PacketPriority.REACTIVE, appId); |
| 241 | selector.matchEthType(Ethernet.TYPE_ARP); |
| 242 | packetService.cancelPackets(selector.build(), PacketPriority.REACTIVE, appId); |
| 243 | selector.matchEthType(Ethernet.TYPE_IPV6); |
| 244 | packetService.cancelPackets(selector.build(), PacketPriority.REACTIVE, appId); |
| 245 | } |
| 246 | |
| 247 | /** |
Kunihiro Ishiguro | d37c9ca | 2014-12-31 16:05:40 +0900 | [diff] [blame] | 248 | * Extracts properties from the component configuration context. |
| 249 | * |
| 250 | * @param context the component context |
| 251 | */ |
| 252 | private void readComponentConfiguration(ComponentContext context) { |
| 253 | Dictionary<?, ?> properties = context.getProperties(); |
Dusan Pajin | 0d1d48f | 2015-02-20 16:05:11 +0100 | [diff] [blame] | 254 | boolean packetOutOnlyEnabled = |
Thomas Vachuska | 27bee09 | 2015-06-23 19:03:10 -0700 | [diff] [blame] | 255 | isPropertyEnabled(properties, "packetOutOnly"); |
Kunihiro Ishiguro | d37c9ca | 2014-12-31 16:05:40 +0900 | [diff] [blame] | 256 | if (packetOutOnly != packetOutOnlyEnabled) { |
| 257 | packetOutOnly = packetOutOnlyEnabled; |
| 258 | log.info("Configured. Packet-out only forwarding is {}", |
Thomas Vachuska | 27bee09 | 2015-06-23 19:03:10 -0700 | [diff] [blame] | 259 | packetOutOnly ? "enabled" : "disabled"); |
tom | c16656f | 2014-10-15 18:30:31 -0700 | [diff] [blame] | 260 | } |
Dusan Pajin | 0d1d48f | 2015-02-20 16:05:11 +0100 | [diff] [blame] | 261 | boolean packetOutOfppTableEnabled = |
Thomas Vachuska | 27bee09 | 2015-06-23 19:03:10 -0700 | [diff] [blame] | 262 | isPropertyEnabled(properties, "packetOutOfppTable"); |
Dusan Pajin | 0d1d48f | 2015-02-20 16:05:11 +0100 | [diff] [blame] | 263 | if (packetOutOfppTable != packetOutOfppTableEnabled) { |
| 264 | packetOutOfppTable = packetOutOfppTableEnabled; |
| 265 | log.info("Configured. Forwarding using OFPP_TABLE port is {}", |
Thomas Vachuska | 27bee09 | 2015-06-23 19:03:10 -0700 | [diff] [blame] | 266 | packetOutOfppTable ? "enabled" : "disabled"); |
Dusan Pajin | 0d1d48f | 2015-02-20 16:05:11 +0100 | [diff] [blame] | 267 | } |
| 268 | boolean ipv6ForwardingEnabled = |
Thomas Vachuska | 27bee09 | 2015-06-23 19:03:10 -0700 | [diff] [blame] | 269 | isPropertyEnabled(properties, "ipv6Forwarding"); |
Kunihiro Ishiguro | d37c9ca | 2014-12-31 16:05:40 +0900 | [diff] [blame] | 270 | if (ipv6Forwarding != ipv6ForwardingEnabled) { |
| 271 | ipv6Forwarding = ipv6ForwardingEnabled; |
| 272 | log.info("Configured. IPv6 forwarding is {}", |
Thomas Vachuska | 27bee09 | 2015-06-23 19:03:10 -0700 | [diff] [blame] | 273 | ipv6Forwarding ? "enabled" : "disabled"); |
Kunihiro Ishiguro | d37c9ca | 2014-12-31 16:05:40 +0900 | [diff] [blame] | 274 | } |
Dusan Pajin | 0d1d48f | 2015-02-20 16:05:11 +0100 | [diff] [blame] | 275 | boolean matchDstMacOnlyEnabled = |
Thomas Vachuska | 27bee09 | 2015-06-23 19:03:10 -0700 | [diff] [blame] | 276 | isPropertyEnabled(properties, "matchDstMacOnly"); |
Dusan Pajin | 0d1d48f | 2015-02-20 16:05:11 +0100 | [diff] [blame] | 277 | if (matchDstMacOnly != matchDstMacOnlyEnabled) { |
| 278 | matchDstMacOnly = matchDstMacOnlyEnabled; |
| 279 | log.info("Configured. Match Dst MAC Only is {}", |
Thomas Vachuska | 27bee09 | 2015-06-23 19:03:10 -0700 | [diff] [blame] | 280 | matchDstMacOnly ? "enabled" : "disabled"); |
Dusan Pajin | 0d1d48f | 2015-02-20 16:05:11 +0100 | [diff] [blame] | 281 | } |
| 282 | boolean matchVlanIdEnabled = |
Thomas Vachuska | 27bee09 | 2015-06-23 19:03:10 -0700 | [diff] [blame] | 283 | isPropertyEnabled(properties, "matchVlanId"); |
Dusan Pajin | 0d1d48f | 2015-02-20 16:05:11 +0100 | [diff] [blame] | 284 | if (matchVlanId != matchVlanIdEnabled) { |
| 285 | matchVlanId = matchVlanIdEnabled; |
| 286 | log.info("Configured. Matching Vlan ID is {}", |
Thomas Vachuska | 27bee09 | 2015-06-23 19:03:10 -0700 | [diff] [blame] | 287 | matchVlanId ? "enabled" : "disabled"); |
Dusan Pajin | 0d1d48f | 2015-02-20 16:05:11 +0100 | [diff] [blame] | 288 | } |
| 289 | boolean matchIpv4AddressEnabled = |
Thomas Vachuska | 27bee09 | 2015-06-23 19:03:10 -0700 | [diff] [blame] | 290 | isPropertyEnabled(properties, "matchIpv4Address"); |
Dusan Pajin | 0d1d48f | 2015-02-20 16:05:11 +0100 | [diff] [blame] | 291 | if (matchIpv4Address != matchIpv4AddressEnabled) { |
| 292 | matchIpv4Address = matchIpv4AddressEnabled; |
| 293 | log.info("Configured. Matching IPv4 Addresses is {}", |
Thomas Vachuska | 27bee09 | 2015-06-23 19:03:10 -0700 | [diff] [blame] | 294 | matchIpv4Address ? "enabled" : "disabled"); |
Dusan Pajin | 0d1d48f | 2015-02-20 16:05:11 +0100 | [diff] [blame] | 295 | } |
| 296 | boolean matchIpv4DscpEnabled = |
Thomas Vachuska | 27bee09 | 2015-06-23 19:03:10 -0700 | [diff] [blame] | 297 | isPropertyEnabled(properties, "matchIpv4Dscp"); |
Dusan Pajin | 0d1d48f | 2015-02-20 16:05:11 +0100 | [diff] [blame] | 298 | if (matchIpv4Dscp != matchIpv4DscpEnabled) { |
| 299 | matchIpv4Dscp = matchIpv4DscpEnabled; |
| 300 | log.info("Configured. Matching IPv4 DSCP and ECN is {}", |
Thomas Vachuska | 27bee09 | 2015-06-23 19:03:10 -0700 | [diff] [blame] | 301 | matchIpv4Dscp ? "enabled" : "disabled"); |
Dusan Pajin | 0d1d48f | 2015-02-20 16:05:11 +0100 | [diff] [blame] | 302 | } |
| 303 | boolean matchIpv6AddressEnabled = |
Thomas Vachuska | 27bee09 | 2015-06-23 19:03:10 -0700 | [diff] [blame] | 304 | isPropertyEnabled(properties, "matchIpv6Address"); |
Dusan Pajin | 0d1d48f | 2015-02-20 16:05:11 +0100 | [diff] [blame] | 305 | if (matchIpv6Address != matchIpv6AddressEnabled) { |
| 306 | matchIpv6Address = matchIpv6AddressEnabled; |
| 307 | log.info("Configured. Matching IPv6 Addresses is {}", |
Thomas Vachuska | 27bee09 | 2015-06-23 19:03:10 -0700 | [diff] [blame] | 308 | matchIpv6Address ? "enabled" : "disabled"); |
Dusan Pajin | 0d1d48f | 2015-02-20 16:05:11 +0100 | [diff] [blame] | 309 | } |
| 310 | boolean matchIpv6FlowLabelEnabled = |
Thomas Vachuska | 27bee09 | 2015-06-23 19:03:10 -0700 | [diff] [blame] | 311 | isPropertyEnabled(properties, "matchIpv6FlowLabel"); |
Dusan Pajin | 0d1d48f | 2015-02-20 16:05:11 +0100 | [diff] [blame] | 312 | if (matchIpv6FlowLabel != matchIpv6FlowLabelEnabled) { |
| 313 | matchIpv6FlowLabel = matchIpv6FlowLabelEnabled; |
| 314 | log.info("Configured. Matching IPv6 FlowLabel is {}", |
Thomas Vachuska | 27bee09 | 2015-06-23 19:03:10 -0700 | [diff] [blame] | 315 | matchIpv6FlowLabel ? "enabled" : "disabled"); |
Dusan Pajin | 0d1d48f | 2015-02-20 16:05:11 +0100 | [diff] [blame] | 316 | } |
| 317 | boolean matchTcpUdpPortsEnabled = |
Thomas Vachuska | 27bee09 | 2015-06-23 19:03:10 -0700 | [diff] [blame] | 318 | isPropertyEnabled(properties, "matchTcpUdpPorts"); |
Dusan Pajin | 0d1d48f | 2015-02-20 16:05:11 +0100 | [diff] [blame] | 319 | if (matchTcpUdpPorts != matchTcpUdpPortsEnabled) { |
| 320 | matchTcpUdpPorts = matchTcpUdpPortsEnabled; |
| 321 | log.info("Configured. Matching TCP/UDP fields is {}", |
Thomas Vachuska | 27bee09 | 2015-06-23 19:03:10 -0700 | [diff] [blame] | 322 | matchTcpUdpPorts ? "enabled" : "disabled"); |
Dusan Pajin | 0d1d48f | 2015-02-20 16:05:11 +0100 | [diff] [blame] | 323 | } |
| 324 | boolean matchIcmpFieldsEnabled = |
Thomas Vachuska | 27bee09 | 2015-06-23 19:03:10 -0700 | [diff] [blame] | 325 | isPropertyEnabled(properties, "matchIcmpFields"); |
Dusan Pajin | 0d1d48f | 2015-02-20 16:05:11 +0100 | [diff] [blame] | 326 | if (matchIcmpFields != matchIcmpFieldsEnabled) { |
| 327 | matchIcmpFields = matchIcmpFieldsEnabled; |
| 328 | log.info("Configured. Matching ICMP (v4 and v6) fields is {}", |
Thomas Vachuska | 27bee09 | 2015-06-23 19:03:10 -0700 | [diff] [blame] | 329 | matchIcmpFields ? "enabled" : "disabled"); |
Dusan Pajin | 0d1d48f | 2015-02-20 16:05:11 +0100 | [diff] [blame] | 330 | } |
| 331 | Integer flowTimeoutConfigured = |
Thomas Vachuska | 27bee09 | 2015-06-23 19:03:10 -0700 | [diff] [blame] | 332 | getIntegerProperty(properties, "flowTimeout"); |
Dusan Pajin | 0d1d48f | 2015-02-20 16:05:11 +0100 | [diff] [blame] | 333 | if (flowTimeoutConfigured == null) { |
| 334 | log.info("Flow Timeout is not configured, default value is {}", |
| 335 | flowTimeout); |
| 336 | } else { |
| 337 | flowTimeout = flowTimeoutConfigured; |
| 338 | log.info("Configured. Flow Timeout is configured to {}", |
| 339 | flowTimeout, " seconds"); |
| 340 | } |
| 341 | Integer flowPriorityConfigured = |
Thomas Vachuska | 27bee09 | 2015-06-23 19:03:10 -0700 | [diff] [blame] | 342 | getIntegerProperty(properties, "flowPriority"); |
Dusan Pajin | 0d1d48f | 2015-02-20 16:05:11 +0100 | [diff] [blame] | 343 | if (flowPriorityConfigured == null) { |
| 344 | log.info("Flow Priority is not configured, default value is {}", |
| 345 | flowPriority); |
| 346 | } else { |
| 347 | flowPriority = flowPriorityConfigured; |
| 348 | log.info("Configured. Flow Priority is configured to {}", |
| 349 | flowPriority); |
| 350 | } |
Rusty Eddy | 29acad6 | 2015-07-07 19:33:47 -0700 | [diff] [blame] | 351 | |
| 352 | boolean ignoreIpv4McastPacketsEnabled = |
| 353 | isPropertyEnabled(properties, "ignoreIpv4McastPackets"); |
| 354 | if (ignoreIpv4McastPackets != ignoreIpv4McastPacketsEnabled) { |
| 355 | ignoreIpv4McastPackets = ignoreIpv4McastPacketsEnabled; |
| 356 | log.info("Configured. Ignore IPv4 multicast packets is {}", |
Thomas Vachuska | 8d03367 | 2015-07-21 16:15:04 -0700 | [diff] [blame] | 357 | ignoreIpv4McastPackets ? "enabled" : "disabled"); |
Rusty Eddy | 29acad6 | 2015-07-07 19:33:47 -0700 | [diff] [blame] | 358 | } |
Dusan Pajin | 0d1d48f | 2015-02-20 16:05:11 +0100 | [diff] [blame] | 359 | } |
| 360 | |
| 361 | /** |
| 362 | * Get Integer property from the propertyName |
| 363 | * Return null if propertyName is not found. |
| 364 | * |
Thomas Vachuska | 27bee09 | 2015-06-23 19:03:10 -0700 | [diff] [blame] | 365 | * @param properties properties to be looked up |
Dusan Pajin | 0d1d48f | 2015-02-20 16:05:11 +0100 | [diff] [blame] | 366 | * @param propertyName the name of the property to look up |
| 367 | * @return value when the propertyName is defined or return null |
| 368 | */ |
| 369 | private static Integer getIntegerProperty(Dictionary<?, ?> properties, |
| 370 | String propertyName) { |
| 371 | Integer value = null; |
| 372 | try { |
| 373 | String s = (String) properties.get(propertyName); |
| 374 | value = isNullOrEmpty(s) ? value : Integer.parseInt(s.trim()); |
Pavlin Radoslavov | b9e50df | 2015-02-20 20:01:26 -0800 | [diff] [blame] | 375 | } catch (NumberFormatException | ClassCastException e) { |
Dusan Pajin | 0d1d48f | 2015-02-20 16:05:11 +0100 | [diff] [blame] | 376 | value = null; |
| 377 | } |
| 378 | return value; |
Kunihiro Ishiguro | d37c9ca | 2014-12-31 16:05:40 +0900 | [diff] [blame] | 379 | } |
| 380 | |
| 381 | /** |
| 382 | * Check property name is defined and set to true. |
| 383 | * |
Thomas Vachuska | 27bee09 | 2015-06-23 19:03:10 -0700 | [diff] [blame] | 384 | * @param properties properties to be looked up |
Kunihiro Ishiguro | d37c9ca | 2014-12-31 16:05:40 +0900 | [diff] [blame] | 385 | * @param propertyName the name of the property to look up |
| 386 | * @return true when the propertyName is defined and set to true |
| 387 | */ |
Dusan Pajin | 0d1d48f | 2015-02-20 16:05:11 +0100 | [diff] [blame] | 388 | private static boolean isPropertyEnabled(Dictionary<?, ?> properties, |
| 389 | String propertyName) { |
Kunihiro Ishiguro | d37c9ca | 2014-12-31 16:05:40 +0900 | [diff] [blame] | 390 | boolean enabled = false; |
| 391 | try { |
| 392 | String flag = (String) properties.get(propertyName); |
| 393 | if (flag != null) { |
Ayaka Koshibe | 8851ed9 | 2015-01-22 12:07:24 -0800 | [diff] [blame] | 394 | enabled = flag.trim().equals("true"); |
Kunihiro Ishiguro | d37c9ca | 2014-12-31 16:05:40 +0900 | [diff] [blame] | 395 | } |
| 396 | } catch (ClassCastException e) { |
| 397 | // No propertyName defined. |
| 398 | enabled = false; |
| 399 | } |
| 400 | return enabled; |
tom | c16656f | 2014-10-15 18:30:31 -0700 | [diff] [blame] | 401 | } |
tom | c370ebd | 2014-09-16 01:25:21 -0700 | [diff] [blame] | 402 | |
| 403 | /** |
| 404 | * Packet processor responsible for forwarding packets along their paths. |
| 405 | */ |
| 406 | private class ReactivePacketProcessor implements PacketProcessor { |
| 407 | |
| 408 | @Override |
| 409 | public void process(PacketContext context) { |
tom | dc95b8a | 2014-09-17 08:07:26 -0700 | [diff] [blame] | 410 | // Stop processing if the packet has been handled, since we |
| 411 | // can't do any more to it. |
Sahil Lele | a69534f | 2015-07-16 15:14:57 -0700 | [diff] [blame] | 412 | |
Thomas Vachuska | bd7f4b3 | 2014-12-04 20:54:55 -0800 | [diff] [blame] | 413 | if (context.isHandled()) { |
alshabib | 7b2748f | 2014-09-16 20:21:11 -0700 | [diff] [blame] | 414 | return; |
| 415 | } |
tom | dc95b8a | 2014-09-17 08:07:26 -0700 | [diff] [blame] | 416 | |
tom | c370ebd | 2014-09-16 01:25:21 -0700 | [diff] [blame] | 417 | InboundPacket pkt = context.inPacket(); |
tom | 642b226 | 2014-09-17 13:52:55 -0700 | [diff] [blame] | 418 | Ethernet ethPkt = pkt.parsed(); |
alshabib | 6eb438a | 2014-10-01 16:39:37 -0700 | [diff] [blame] | 419 | |
Jonathan Hart | e8600eb | 2015-01-12 10:30:45 -0800 | [diff] [blame] | 420 | if (ethPkt == null) { |
| 421 | return; |
| 422 | } |
| 423 | |
Kunihiro Ishiguro | d37c9ca | 2014-12-31 16:05:40 +0900 | [diff] [blame] | 424 | // Bail if this is deemed to be a control packet. |
| 425 | if (isControlPacket(ethPkt)) { |
| 426 | return; |
| 427 | } |
| 428 | |
| 429 | // Skip IPv6 multicast packet when IPv6 forward is disabled. |
| 430 | if (!ipv6Forwarding && isIpv6Multicast(ethPkt)) { |
Thomas Vachuska | 01a6ec0 | 2014-11-05 09:54:09 -0800 | [diff] [blame] | 431 | return; |
| 432 | } |
| 433 | |
tom | 642b226 | 2014-09-17 13:52:55 -0700 | [diff] [blame] | 434 | HostId id = HostId.hostId(ethPkt.getDestinationMAC()); |
tom | c370ebd | 2014-09-16 01:25:21 -0700 | [diff] [blame] | 435 | |
Thomas Vachuska | e1bcb0b | 2014-10-27 17:45:10 -0700 | [diff] [blame] | 436 | // Do not process link-local addresses in any way. |
| 437 | if (id.mac().isLinkLocal()) { |
| 438 | return; |
| 439 | } |
| 440 | |
Rusty Eddy | 29acad6 | 2015-07-07 19:33:47 -0700 | [diff] [blame] | 441 | // Do not process IPv4 multicast packets, let mfwd handle them |
| 442 | if (ignoreIpv4McastPackets && ethPkt.getEtherType() == Ethernet.TYPE_IPV4) { |
| 443 | if (id.mac().isMulticast()) { |
| 444 | return; |
| 445 | } |
| 446 | } |
| 447 | |
tom | c370ebd | 2014-09-16 01:25:21 -0700 | [diff] [blame] | 448 | // Do we know who this is for? If not, flood and bail. |
| 449 | Host dst = hostService.getHost(id); |
| 450 | if (dst == null) { |
| 451 | flood(context); |
| 452 | return; |
| 453 | } |
| 454 | |
| 455 | // Are we on an edge switch that our destination is on? If so, |
| 456 | // simply forward out to the destination and bail. |
| 457 | if (pkt.receivedFrom().deviceId().equals(dst.location().deviceId())) { |
alshabib | 6eb438a | 2014-10-01 16:39:37 -0700 | [diff] [blame] | 458 | if (!context.inPacket().receivedFrom().port().equals(dst.location().port())) { |
| 459 | installRule(context, dst.location().port()); |
| 460 | } |
tom | c370ebd | 2014-09-16 01:25:21 -0700 | [diff] [blame] | 461 | return; |
| 462 | } |
| 463 | |
| 464 | // Otherwise, get a set of paths that lead from here to the |
| 465 | // destination edge switch. |
Dusan Pajin | 0d1d48f | 2015-02-20 16:05:11 +0100 | [diff] [blame] | 466 | Set<Path> paths = |
Thomas Vachuska | 27bee09 | 2015-06-23 19:03:10 -0700 | [diff] [blame] | 467 | topologyService.getPaths(topologyService.currentTopology(), |
| 468 | pkt.receivedFrom().deviceId(), |
| 469 | dst.location().deviceId()); |
tom | c370ebd | 2014-09-16 01:25:21 -0700 | [diff] [blame] | 470 | if (paths.isEmpty()) { |
| 471 | // If there are no paths, flood and bail. |
| 472 | flood(context); |
| 473 | return; |
| 474 | } |
| 475 | |
| 476 | // Otherwise, pick a path that does not lead back to where we |
| 477 | // came from; if no such path, flood and bail. |
Thomas Vachuska | 320c58f | 2015-08-05 10:42:32 -0700 | [diff] [blame] | 478 | Path path = pickForwardPathIfPossible(paths, pkt.receivedFrom().port()); |
tom | c370ebd | 2014-09-16 01:25:21 -0700 | [diff] [blame] | 479 | if (path == null) { |
Thomas Vachuska | 320c58f | 2015-08-05 10:42:32 -0700 | [diff] [blame] | 480 | log.warn("Don't know where to go from here {} for {} -> {}", |
| 481 | pkt.receivedFrom(), ethPkt.getSourceMAC(), ethPkt.getDestinationMAC()); |
tom | c370ebd | 2014-09-16 01:25:21 -0700 | [diff] [blame] | 482 | flood(context); |
| 483 | return; |
| 484 | } |
| 485 | |
| 486 | // Otherwise forward and be done with it. |
alshabib | 7b2748f | 2014-09-16 20:21:11 -0700 | [diff] [blame] | 487 | installRule(context, path.src().port()); |
tom | c370ebd | 2014-09-16 01:25:21 -0700 | [diff] [blame] | 488 | } |
Thomas Vachuska | 01a6ec0 | 2014-11-05 09:54:09 -0800 | [diff] [blame] | 489 | |
| 490 | } |
| 491 | |
| 492 | // Indicates whether this is a control packet, e.g. LLDP, BDDP |
| 493 | private boolean isControlPacket(Ethernet eth) { |
| 494 | short type = eth.getEtherType(); |
| 495 | return type == Ethernet.TYPE_LLDP || type == Ethernet.TYPE_BSN; |
tom | c370ebd | 2014-09-16 01:25:21 -0700 | [diff] [blame] | 496 | } |
| 497 | |
Thomas Vachuska | 5dd52f7 | 2014-11-28 19:27:45 -0800 | [diff] [blame] | 498 | // Indicated whether this is an IPv6 multicast packet. |
| 499 | private boolean isIpv6Multicast(Ethernet eth) { |
| 500 | return eth.getEtherType() == Ethernet.TYPE_IPV6 && eth.isMulticast(); |
| 501 | } |
| 502 | |
tom | c370ebd | 2014-09-16 01:25:21 -0700 | [diff] [blame] | 503 | // Selects a path from the given set that does not lead back to the |
Thomas Vachuska | 320c58f | 2015-08-05 10:42:32 -0700 | [diff] [blame] | 504 | // specified port if possible. |
| 505 | private Path pickForwardPathIfPossible(Set<Path> paths, PortNumber notToPort) { |
| 506 | Path lastPath = null; |
tom | c370ebd | 2014-09-16 01:25:21 -0700 | [diff] [blame] | 507 | for (Path path : paths) { |
Thomas Vachuska | 320c58f | 2015-08-05 10:42:32 -0700 | [diff] [blame] | 508 | lastPath = path; |
tom | c370ebd | 2014-09-16 01:25:21 -0700 | [diff] [blame] | 509 | if (!path.src().port().equals(notToPort)) { |
| 510 | return path; |
| 511 | } |
| 512 | } |
Thomas Vachuska | 320c58f | 2015-08-05 10:42:32 -0700 | [diff] [blame] | 513 | return lastPath; |
tom | c370ebd | 2014-09-16 01:25:21 -0700 | [diff] [blame] | 514 | } |
| 515 | |
tom | 642b226 | 2014-09-17 13:52:55 -0700 | [diff] [blame] | 516 | // Floods the specified packet if permissible. |
tom | c370ebd | 2014-09-16 01:25:21 -0700 | [diff] [blame] | 517 | private void flood(PacketContext context) { |
tom | dc95b8a | 2014-09-17 08:07:26 -0700 | [diff] [blame] | 518 | if (topologyService.isBroadcastPoint(topologyService.currentTopology(), |
tom | c16656f | 2014-10-15 18:30:31 -0700 | [diff] [blame] | 519 | context.inPacket().receivedFrom())) { |
tom | 642b226 | 2014-09-17 13:52:55 -0700 | [diff] [blame] | 520 | packetOut(context, PortNumber.FLOOD); |
tom | c370ebd | 2014-09-16 01:25:21 -0700 | [diff] [blame] | 521 | } else { |
| 522 | context.block(); |
| 523 | } |
| 524 | } |
| 525 | |
tom | 642b226 | 2014-09-17 13:52:55 -0700 | [diff] [blame] | 526 | // Sends a packet out the specified port. |
| 527 | private void packetOut(PacketContext context, PortNumber portNumber) { |
alshabib | 010c31d | 2014-09-26 10:01:12 -0700 | [diff] [blame] | 528 | context.treatmentBuilder().setOutput(portNumber); |
alshabib | 7b2748f | 2014-09-16 20:21:11 -0700 | [diff] [blame] | 529 | context.send(); |
| 530 | } |
| 531 | |
| 532 | // Install a rule forwarding the packet to the specified port. |
| 533 | private void installRule(PacketContext context, PortNumber portNumber) { |
Dusan Pajin | 0d1d48f | 2015-02-20 16:05:11 +0100 | [diff] [blame] | 534 | // |
| 535 | // We don't support (yet) buffer IDs in the Flow Service so |
| 536 | // packet out first. |
| 537 | // |
| 538 | Ethernet inPkt = context.inPacket().parsed(); |
Jonathan Hart | 3b881aa | 2015-04-22 18:03:50 -0700 | [diff] [blame] | 539 | TrafficSelector.Builder selectorBuilder = DefaultTrafficSelector.builder(); |
Dusan Pajin | 0d1d48f | 2015-02-20 16:05:11 +0100 | [diff] [blame] | 540 | |
| 541 | // If PacketOutOnly or ARP packet than forward directly to output port |
| 542 | if (packetOutOnly || inPkt.getEtherType() == Ethernet.TYPE_ARP) { |
| 543 | packetOut(context, portNumber); |
| 544 | return; |
| 545 | } |
| 546 | |
| 547 | // |
| 548 | // If matchDstMacOnly |
| 549 | // Create flows matching dstMac only |
| 550 | // Else |
| 551 | // Create flows with default matching and include configured fields |
| 552 | // |
| 553 | if (matchDstMacOnly) { |
Jonathan Hart | 3b881aa | 2015-04-22 18:03:50 -0700 | [diff] [blame] | 554 | selectorBuilder.matchEthDst(inPkt.getDestinationMAC()); |
Dusan Pajin | 0d1d48f | 2015-02-20 16:05:11 +0100 | [diff] [blame] | 555 | } else { |
Jonathan Hart | 3b881aa | 2015-04-22 18:03:50 -0700 | [diff] [blame] | 556 | selectorBuilder.matchInPort(context.inPacket().receivedFrom().port()) |
Thomas Vachuska | bd7f4b3 | 2014-12-04 20:54:55 -0800 | [diff] [blame] | 557 | .matchEthSrc(inPkt.getSourceMAC()) |
Jonathan Hart | 430223a | 2015-04-22 17:39:02 -0700 | [diff] [blame] | 558 | .matchEthDst(inPkt.getDestinationMAC()); |
alshabib | 7b2748f | 2014-09-16 20:21:11 -0700 | [diff] [blame] | 559 | |
Dusan Pajin | 0d1d48f | 2015-02-20 16:05:11 +0100 | [diff] [blame] | 560 | // If configured Match Vlan ID |
| 561 | if (matchVlanId && inPkt.getVlanID() != Ethernet.VLAN_UNTAGGED) { |
Jonathan Hart | 3b881aa | 2015-04-22 18:03:50 -0700 | [diff] [blame] | 562 | selectorBuilder.matchVlanId(VlanId.vlanId(inPkt.getVlanID())); |
Dusan Pajin | 0d1d48f | 2015-02-20 16:05:11 +0100 | [diff] [blame] | 563 | } |
alshabib | 7b2748f | 2014-09-16 20:21:11 -0700 | [diff] [blame] | 564 | |
Dusan Pajin | 0d1d48f | 2015-02-20 16:05:11 +0100 | [diff] [blame] | 565 | // |
| 566 | // If configured and EtherType is IPv4 - Match IPv4 and |
| 567 | // TCP/UDP/ICMP fields |
| 568 | // |
| 569 | if (matchIpv4Address && inPkt.getEtherType() == Ethernet.TYPE_IPV4) { |
| 570 | IPv4 ipv4Packet = (IPv4) inPkt.getPayload(); |
| 571 | byte ipv4Protocol = ipv4Packet.getProtocol(); |
| 572 | Ip4Prefix matchIp4SrcPrefix = |
Thomas Vachuska | 27bee09 | 2015-06-23 19:03:10 -0700 | [diff] [blame] | 573 | Ip4Prefix.valueOf(ipv4Packet.getSourceAddress(), |
| 574 | Ip4Prefix.MAX_MASK_LENGTH); |
Dusan Pajin | 0d1d48f | 2015-02-20 16:05:11 +0100 | [diff] [blame] | 575 | Ip4Prefix matchIp4DstPrefix = |
Thomas Vachuska | 27bee09 | 2015-06-23 19:03:10 -0700 | [diff] [blame] | 576 | Ip4Prefix.valueOf(ipv4Packet.getDestinationAddress(), |
| 577 | Ip4Prefix.MAX_MASK_LENGTH); |
Charles M.C. Chan | 7b8a921 | 2015-04-26 01:25:53 +0800 | [diff] [blame] | 578 | selectorBuilder.matchEthType(Ethernet.TYPE_IPV4) |
Jonathan Hart | 430223a | 2015-04-22 17:39:02 -0700 | [diff] [blame] | 579 | .matchIPSrc(matchIp4SrcPrefix) |
| 580 | .matchIPDst(matchIp4DstPrefix); |
alshabib | 6eb438a | 2014-10-01 16:39:37 -0700 | [diff] [blame] | 581 | |
Dusan Pajin | 0d1d48f | 2015-02-20 16:05:11 +0100 | [diff] [blame] | 582 | if (matchIpv4Dscp) { |
Pavlin Radoslavov | bf23c55 | 2015-02-20 14:20:30 -0800 | [diff] [blame] | 583 | byte dscp = ipv4Packet.getDscp(); |
| 584 | byte ecn = ipv4Packet.getEcn(); |
Jonathan Hart | 3b881aa | 2015-04-22 18:03:50 -0700 | [diff] [blame] | 585 | selectorBuilder.matchIPDscp(dscp).matchIPEcn(ecn); |
Dusan Pajin | 0d1d48f | 2015-02-20 16:05:11 +0100 | [diff] [blame] | 586 | } |
| 587 | |
| 588 | if (matchTcpUdpPorts && ipv4Protocol == IPv4.PROTOCOL_TCP) { |
| 589 | TCP tcpPacket = (TCP) ipv4Packet.getPayload(); |
Jonathan Hart | 3b881aa | 2015-04-22 18:03:50 -0700 | [diff] [blame] | 590 | selectorBuilder.matchIPProtocol(ipv4Protocol) |
Hyunsun Moon | cf732fb | 2015-08-22 21:04:23 -0700 | [diff] [blame] | 591 | .matchTcpSrc(TpPort.tpPort(tcpPacket.getSourcePort())) |
| 592 | .matchTcpDst(TpPort.tpPort(tcpPacket.getDestinationPort())); |
Dusan Pajin | 0d1d48f | 2015-02-20 16:05:11 +0100 | [diff] [blame] | 593 | } |
| 594 | if (matchTcpUdpPorts && ipv4Protocol == IPv4.PROTOCOL_UDP) { |
| 595 | UDP udpPacket = (UDP) ipv4Packet.getPayload(); |
Jonathan Hart | 3b881aa | 2015-04-22 18:03:50 -0700 | [diff] [blame] | 596 | selectorBuilder.matchIPProtocol(ipv4Protocol) |
Hyunsun Moon | cf732fb | 2015-08-22 21:04:23 -0700 | [diff] [blame] | 597 | .matchUdpSrc(TpPort.tpPort(udpPacket.getSourcePort())) |
| 598 | .matchUdpDst(TpPort.tpPort(udpPacket.getDestinationPort())); |
Dusan Pajin | 0d1d48f | 2015-02-20 16:05:11 +0100 | [diff] [blame] | 599 | } |
| 600 | if (matchIcmpFields && ipv4Protocol == IPv4.PROTOCOL_ICMP) { |
| 601 | ICMP icmpPacket = (ICMP) ipv4Packet.getPayload(); |
Jonathan Hart | 3b881aa | 2015-04-22 18:03:50 -0700 | [diff] [blame] | 602 | selectorBuilder.matchIPProtocol(ipv4Protocol) |
Jonathan Hart | 430223a | 2015-04-22 17:39:02 -0700 | [diff] [blame] | 603 | .matchIcmpType(icmpPacket.getIcmpType()) |
Dusan Pajin | 0d1d48f | 2015-02-20 16:05:11 +0100 | [diff] [blame] | 604 | .matchIcmpCode(icmpPacket.getIcmpCode()); |
| 605 | } |
| 606 | } |
| 607 | |
| 608 | // |
| 609 | // If configured and EtherType is IPv6 - Match IPv6 and |
| 610 | // TCP/UDP/ICMP fields |
| 611 | // |
| 612 | if (matchIpv6Address && inPkt.getEtherType() == Ethernet.TYPE_IPV6) { |
| 613 | IPv6 ipv6Packet = (IPv6) inPkt.getPayload(); |
| 614 | byte ipv6NextHeader = ipv6Packet.getNextHeader(); |
| 615 | Ip6Prefix matchIp6SrcPrefix = |
Thomas Vachuska | 27bee09 | 2015-06-23 19:03:10 -0700 | [diff] [blame] | 616 | Ip6Prefix.valueOf(ipv6Packet.getSourceAddress(), |
| 617 | Ip6Prefix.MAX_MASK_LENGTH); |
Dusan Pajin | 0d1d48f | 2015-02-20 16:05:11 +0100 | [diff] [blame] | 618 | Ip6Prefix matchIp6DstPrefix = |
Thomas Vachuska | 27bee09 | 2015-06-23 19:03:10 -0700 | [diff] [blame] | 619 | Ip6Prefix.valueOf(ipv6Packet.getDestinationAddress(), |
| 620 | Ip6Prefix.MAX_MASK_LENGTH); |
Charles M.C. Chan | 7b8a921 | 2015-04-26 01:25:53 +0800 | [diff] [blame] | 621 | selectorBuilder.matchEthType(Ethernet.TYPE_IPV6) |
| 622 | .matchIPv6Src(matchIp6SrcPrefix) |
Jonathan Hart | 430223a | 2015-04-22 17:39:02 -0700 | [diff] [blame] | 623 | .matchIPv6Dst(matchIp6DstPrefix); |
Dusan Pajin | 0d1d48f | 2015-02-20 16:05:11 +0100 | [diff] [blame] | 624 | |
| 625 | if (matchIpv6FlowLabel) { |
Jonathan Hart | 3b881aa | 2015-04-22 18:03:50 -0700 | [diff] [blame] | 626 | selectorBuilder.matchIPv6FlowLabel(ipv6Packet.getFlowLabel()); |
Dusan Pajin | 0d1d48f | 2015-02-20 16:05:11 +0100 | [diff] [blame] | 627 | } |
| 628 | |
| 629 | if (matchTcpUdpPorts && ipv6NextHeader == IPv6.PROTOCOL_TCP) { |
| 630 | TCP tcpPacket = (TCP) ipv6Packet.getPayload(); |
Jonathan Hart | 3b881aa | 2015-04-22 18:03:50 -0700 | [diff] [blame] | 631 | selectorBuilder.matchIPProtocol(ipv6NextHeader) |
Hyunsun Moon | cf732fb | 2015-08-22 21:04:23 -0700 | [diff] [blame] | 632 | .matchTcpSrc(TpPort.tpPort(tcpPacket.getSourcePort())) |
| 633 | .matchTcpDst(TpPort.tpPort(tcpPacket.getDestinationPort())); |
Dusan Pajin | 0d1d48f | 2015-02-20 16:05:11 +0100 | [diff] [blame] | 634 | } |
| 635 | if (matchTcpUdpPorts && ipv6NextHeader == IPv6.PROTOCOL_UDP) { |
| 636 | UDP udpPacket = (UDP) ipv6Packet.getPayload(); |
Jonathan Hart | 3b881aa | 2015-04-22 18:03:50 -0700 | [diff] [blame] | 637 | selectorBuilder.matchIPProtocol(ipv6NextHeader) |
Hyunsun Moon | cf732fb | 2015-08-22 21:04:23 -0700 | [diff] [blame] | 638 | .matchUdpSrc(TpPort.tpPort(udpPacket.getSourcePort())) |
| 639 | .matchUdpDst(TpPort.tpPort(udpPacket.getDestinationPort())); |
Dusan Pajin | 0d1d48f | 2015-02-20 16:05:11 +0100 | [diff] [blame] | 640 | } |
| 641 | if (matchIcmpFields && ipv6NextHeader == IPv6.PROTOCOL_ICMP6) { |
| 642 | ICMP6 icmp6Packet = (ICMP6) ipv6Packet.getPayload(); |
Jonathan Hart | 3b881aa | 2015-04-22 18:03:50 -0700 | [diff] [blame] | 643 | selectorBuilder.matchIPProtocol(ipv6NextHeader) |
Jonathan Hart | 430223a | 2015-04-22 17:39:02 -0700 | [diff] [blame] | 644 | .matchIcmpv6Type(icmp6Packet.getIcmpType()) |
Dusan Pajin | 0d1d48f | 2015-02-20 16:05:11 +0100 | [diff] [blame] | 645 | .matchIcmpv6Code(icmp6Packet.getIcmpCode()); |
| 646 | } |
| 647 | } |
| 648 | } |
Jonathan Hart | 3b881aa | 2015-04-22 18:03:50 -0700 | [diff] [blame] | 649 | TrafficTreatment treatment = DefaultTrafficTreatment.builder() |
| 650 | .setOutput(portNumber) |
| 651 | .build(); |
Dusan Pajin | 0d1d48f | 2015-02-20 16:05:11 +0100 | [diff] [blame] | 652 | |
Jonathan Hart | 3b881aa | 2015-04-22 18:03:50 -0700 | [diff] [blame] | 653 | ForwardingObjective forwardingObjective = DefaultForwardingObjective.builder() |
| 654 | .withSelector(selectorBuilder.build()) |
| 655 | .withTreatment(treatment) |
| 656 | .withPriority(flowPriority) |
| 657 | .withFlag(ForwardingObjective.Flag.VERSATILE) |
| 658 | .fromApp(appId) |
| 659 | .makeTemporary(flowTimeout) |
| 660 | .add(); |
Dusan Pajin | 0d1d48f | 2015-02-20 16:05:11 +0100 | [diff] [blame] | 661 | |
Jonathan Hart | 3b881aa | 2015-04-22 18:03:50 -0700 | [diff] [blame] | 662 | flowObjectiveService.forward(context.inPacket().receivedFrom().deviceId(), |
| 663 | forwardingObjective); |
Dusan Pajin | 0d1d48f | 2015-02-20 16:05:11 +0100 | [diff] [blame] | 664 | |
| 665 | // |
| 666 | // If packetOutOfppTable |
| 667 | // Send packet back to the OpenFlow pipeline to match installed flow |
| 668 | // Else |
| 669 | // Send packet direction on the appropriate port |
| 670 | // |
| 671 | if (packetOutOfppTable) { |
| 672 | packetOut(context, PortNumber.TABLE); |
| 673 | } else { |
| 674 | packetOut(context, portNumber); |
Thomas Vachuska | bd7f4b3 | 2014-12-04 20:54:55 -0800 | [diff] [blame] | 675 | } |
tom | c370ebd | 2014-09-16 01:25:21 -0700 | [diff] [blame] | 676 | } |
Sahil Lele | a69534f | 2015-07-16 15:14:57 -0700 | [diff] [blame] | 677 | |
| 678 | private class InternalTopologyListener implements TopologyListener { |
| 679 | @Override |
| 680 | public void event(TopologyEvent event) { |
| 681 | List<Event> reasons = event.reasons(); |
| 682 | if (reasons != null) { |
| 683 | reasons.forEach(re -> { |
| 684 | if (re instanceof LinkEvent) { |
| 685 | LinkEvent le = (LinkEvent) re; |
| 686 | if (le.type() == LinkEvent.Type.LINK_REMOVED) { |
| 687 | fixBlackhole(le.subject().src()); |
| 688 | } |
| 689 | } |
| 690 | }); |
| 691 | } |
| 692 | } |
| 693 | } |
| 694 | |
| 695 | private void fixBlackhole(ConnectPoint egress) { |
Thomas Vachuska | 8d03367 | 2015-07-21 16:15:04 -0700 | [diff] [blame] | 696 | Set<FlowEntry> rules = getFlowRulesFrom(egress); |
Sahil Lele | a69534f | 2015-07-16 15:14:57 -0700 | [diff] [blame] | 697 | Set<SrcDstPair> pairs = findSrcDstPairs(rules); |
| 698 | |
Sahil Lele | 7b96166 | 2015-07-20 15:06:04 -0700 | [diff] [blame] | 699 | Map<DeviceId, Set<Path>> srcPaths = new HashMap<>(); |
| 700 | |
Thomas Vachuska | 8d03367 | 2015-07-21 16:15:04 -0700 | [diff] [blame] | 701 | for (SrcDstPair sd : pairs) { |
Sahil Lele | a69534f | 2015-07-16 15:14:57 -0700 | [diff] [blame] | 702 | // get the edge deviceID for the src host |
Sahil Lele | 0f8d00e | 2015-07-24 11:05:43 -0700 | [diff] [blame] | 703 | Host srcHost = hostService.getHost(HostId.hostId(sd.src)); |
| 704 | Host dstHost = hostService.getHost(HostId.hostId(sd.dst)); |
| 705 | if (srcHost != null && dstHost != null) { |
| 706 | DeviceId srcId = srcHost.location().deviceId(); |
| 707 | DeviceId dstId = dstHost.location().deviceId(); |
| 708 | log.trace("SRC ID is " + srcId + ", DST ID is " + dstId); |
Sahil Lele | a69534f | 2015-07-16 15:14:57 -0700 | [diff] [blame] | 709 | |
Sahil Lele | 0f8d00e | 2015-07-24 11:05:43 -0700 | [diff] [blame] | 710 | cleanFlowRules(sd, egress.deviceId()); |
Sahil Lele | a69534f | 2015-07-16 15:14:57 -0700 | [diff] [blame] | 711 | |
Sahil Lele | 0f8d00e | 2015-07-24 11:05:43 -0700 | [diff] [blame] | 712 | Set<Path> shortestPaths = srcPaths.get(srcId); |
| 713 | if (shortestPaths == null) { |
| 714 | shortestPaths = topologyService.getPaths(topologyService.currentTopology(), |
| 715 | egress.deviceId(), srcId); |
| 716 | srcPaths.put(srcId, shortestPaths); |
| 717 | } |
| 718 | backTrackBadNodes(shortestPaths, dstId, sd); |
Sahil Lele | 7b96166 | 2015-07-20 15:06:04 -0700 | [diff] [blame] | 719 | } |
Sahil Lele | a69534f | 2015-07-16 15:14:57 -0700 | [diff] [blame] | 720 | } |
| 721 | } |
| 722 | |
| 723 | // Backtracks from link down event to remove flows that lead to blackhole |
| 724 | private void backTrackBadNodes(Set<Path> shortestPaths, DeviceId dstId, SrcDstPair sd) { |
Thomas Vachuska | 8d03367 | 2015-07-21 16:15:04 -0700 | [diff] [blame] | 725 | for (Path p : shortestPaths) { |
Sahil Lele | a69534f | 2015-07-16 15:14:57 -0700 | [diff] [blame] | 726 | List<Link> pathLinks = p.links(); |
| 727 | for (int i = 0; i < pathLinks.size(); i = i + 1) { |
| 728 | Link curLink = pathLinks.get(i); |
| 729 | DeviceId curDevice = curLink.src().deviceId(); |
Sahil Lele | a69534f | 2015-07-16 15:14:57 -0700 | [diff] [blame] | 730 | |
| 731 | // skipping the first link because this link's src has already been pruned beforehand |
| 732 | if (i != 0) { |
| 733 | cleanFlowRules(sd, curDevice); |
| 734 | } |
| 735 | |
Thomas Vachuska | 8d03367 | 2015-07-21 16:15:04 -0700 | [diff] [blame] | 736 | Set<Path> pathsFromCurDevice = |
| 737 | topologyService.getPaths(topologyService.currentTopology(), |
| 738 | curDevice, dstId); |
Thomas Vachuska | 320c58f | 2015-08-05 10:42:32 -0700 | [diff] [blame] | 739 | if (pickForwardPathIfPossible(pathsFromCurDevice, curLink.src().port()) != null) { |
Sahil Lele | a69534f | 2015-07-16 15:14:57 -0700 | [diff] [blame] | 740 | break; |
| 741 | } else { |
| 742 | if (i + 1 == pathLinks.size()) { |
| 743 | cleanFlowRules(sd, curLink.dst().deviceId()); |
| 744 | } |
| 745 | } |
| 746 | } |
| 747 | } |
| 748 | } |
| 749 | |
| 750 | // Removes flow rules off specified device with specific SrcDstPair |
| 751 | private void cleanFlowRules(SrcDstPair pair, DeviceId id) { |
| 752 | log.trace("Searching for flow rules to remove from: " + id); |
| 753 | log.trace("Removing flows w/ SRC=" + pair.src + ", DST=" + pair.dst); |
| 754 | for (FlowEntry r : flowRuleService.getFlowEntries(id)) { |
| 755 | boolean matchesSrc = false, matchesDst = false; |
| 756 | for (Instruction i : r.treatment().allInstructions()) { |
| 757 | if (i.type() == Instruction.Type.OUTPUT) { |
Thomas Vachuska | 8d03367 | 2015-07-21 16:15:04 -0700 | [diff] [blame] | 758 | // if the flow has matching src and dst |
Sahil Lele | a69534f | 2015-07-16 15:14:57 -0700 | [diff] [blame] | 759 | for (Criterion cr : r.selector().criteria()) { |
| 760 | if (cr.type() == Criterion.Type.ETH_DST) { |
| 761 | if (((EthCriterion) cr).mac().equals(pair.dst)) { |
| 762 | matchesDst = true; |
| 763 | } |
| 764 | } else if (cr.type() == Criterion.Type.ETH_SRC) { |
| 765 | if (((EthCriterion) cr).mac().equals(pair.src)) { |
| 766 | matchesSrc = true; |
| 767 | } |
| 768 | } |
| 769 | } |
| 770 | } |
| 771 | } |
| 772 | if (matchesDst && matchesSrc) { |
| 773 | log.trace("Removed flow rule from device: " + id); |
| 774 | flowRuleService.removeFlowRules((FlowRule) r); |
| 775 | } |
| 776 | } |
| 777 | |
| 778 | } |
| 779 | |
| 780 | // Returns a set of src/dst MAC pairs extracted from the specified set of flow entries |
| 781 | private Set<SrcDstPair> findSrcDstPairs(Set<FlowEntry> rules) { |
| 782 | ImmutableSet.Builder<SrcDstPair> builder = ImmutableSet.builder(); |
Thomas Vachuska | 8d03367 | 2015-07-21 16:15:04 -0700 | [diff] [blame] | 783 | for (FlowEntry r : rules) { |
Sahil Lele | a69534f | 2015-07-16 15:14:57 -0700 | [diff] [blame] | 784 | MacAddress src = null, dst = null; |
Thomas Vachuska | 8d03367 | 2015-07-21 16:15:04 -0700 | [diff] [blame] | 785 | for (Criterion cr : r.selector().criteria()) { |
Sahil Lele | a69534f | 2015-07-16 15:14:57 -0700 | [diff] [blame] | 786 | if (cr.type() == Criterion.Type.ETH_DST) { |
| 787 | dst = ((EthCriterion) cr).mac(); |
| 788 | } else if (cr.type() == Criterion.Type.ETH_SRC) { |
| 789 | src = ((EthCriterion) cr).mac(); |
| 790 | } |
| 791 | } |
| 792 | builder.add(new SrcDstPair(src, dst)); |
| 793 | } |
| 794 | return builder.build(); |
| 795 | } |
| 796 | |
Thomas Vachuska | 320c58f | 2015-08-05 10:42:32 -0700 | [diff] [blame] | 797 | // Returns set of flow entries which were created by this application and |
| 798 | // which egress from the specified connection port |
Sahil Lele | a69534f | 2015-07-16 15:14:57 -0700 | [diff] [blame] | 799 | private Set<FlowEntry> getFlowRulesFrom(ConnectPoint egress) { |
| 800 | ImmutableSet.Builder<FlowEntry> builder = ImmutableSet.builder(); |
| 801 | flowRuleService.getFlowEntries(egress.deviceId()).forEach(r -> { |
| 802 | if (r.appId() == appId.id()) { |
| 803 | r.treatment().allInstructions().forEach(i -> { |
| 804 | if (i.type() == Instruction.Type.OUTPUT) { |
| 805 | if (((Instructions.OutputInstruction) i).port().equals(egress.port())) { |
| 806 | builder.add(r); |
| 807 | } |
| 808 | } |
| 809 | }); |
| 810 | } |
| 811 | }); |
| 812 | |
| 813 | return builder.build(); |
| 814 | } |
| 815 | |
| 816 | // Wrapper class for a source and destination pair of MAC addresses |
| 817 | private final class SrcDstPair { |
| 818 | final MacAddress src; |
| 819 | final MacAddress dst; |
| 820 | |
| 821 | private SrcDstPair(MacAddress src, MacAddress dst) { |
| 822 | this.src = src; |
| 823 | this.dst = dst; |
| 824 | } |
| 825 | |
| 826 | @Override |
| 827 | public boolean equals(Object o) { |
| 828 | if (this == o) { |
| 829 | return true; |
| 830 | } |
| 831 | if (o == null || getClass() != o.getClass()) { |
| 832 | return false; |
| 833 | } |
| 834 | SrcDstPair that = (SrcDstPair) o; |
| 835 | return Objects.equals(src, that.src) && |
| 836 | Objects.equals(dst, that.dst); |
| 837 | } |
| 838 | |
| 839 | @Override |
| 840 | public int hashCode() { |
| 841 | return Objects.hash(src, dst); |
| 842 | } |
| 843 | } |
alshabib | 030111e | 2014-09-15 15:56:42 -0700 | [diff] [blame] | 844 | } |