Thomas Vachuska | 781d18b | 2014-10-27 10:31:25 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2014-present 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; |
maojianwei | 8bf77b7 | 2016-02-15 15:18:24 +0800 | [diff] [blame] | 38 | import org.onlab.util.Tools; |
Thomas Vachuska | 6519e6f | 2015-03-11 02:29:31 -0700 | [diff] [blame] | 39 | import org.onosproject.cfg.ComponentConfigService; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 40 | import org.onosproject.core.ApplicationId; |
| 41 | import org.onosproject.core.CoreService; |
Sahil Lele | a69534f | 2015-07-16 15:14:57 -0700 | [diff] [blame] | 42 | import org.onosproject.event.Event; |
| 43 | import org.onosproject.net.ConnectPoint; |
| 44 | import org.onosproject.net.DeviceId; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 45 | import org.onosproject.net.Host; |
| 46 | import org.onosproject.net.HostId; |
Sahil Lele | a69534f | 2015-07-16 15:14:57 -0700 | [diff] [blame] | 47 | import org.onosproject.net.Link; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 48 | import org.onosproject.net.Path; |
| 49 | import org.onosproject.net.PortNumber; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 50 | import org.onosproject.net.flow.DefaultTrafficSelector; |
| 51 | import org.onosproject.net.flow.DefaultTrafficTreatment; |
Sahil Lele | a69534f | 2015-07-16 15:14:57 -0700 | [diff] [blame] | 52 | import org.onosproject.net.flow.FlowEntry; |
| 53 | import org.onosproject.net.flow.FlowRule; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 54 | import org.onosproject.net.flow.FlowRuleService; |
| 55 | import org.onosproject.net.flow.TrafficSelector; |
| 56 | import org.onosproject.net.flow.TrafficTreatment; |
Sahil Lele | a69534f | 2015-07-16 15:14:57 -0700 | [diff] [blame] | 57 | import org.onosproject.net.flow.criteria.Criterion; |
| 58 | import org.onosproject.net.flow.criteria.EthCriterion; |
| 59 | import org.onosproject.net.flow.instructions.Instruction; |
| 60 | import org.onosproject.net.flow.instructions.Instructions; |
Jonathan Hart | 3b881aa | 2015-04-22 18:03:50 -0700 | [diff] [blame] | 61 | import org.onosproject.net.flowobjective.DefaultForwardingObjective; |
| 62 | import org.onosproject.net.flowobjective.FlowObjectiveService; |
| 63 | import org.onosproject.net.flowobjective.ForwardingObjective; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 64 | import org.onosproject.net.host.HostService; |
Sahil Lele | a69534f | 2015-07-16 15:14:57 -0700 | [diff] [blame] | 65 | import org.onosproject.net.link.LinkEvent; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 66 | import org.onosproject.net.packet.InboundPacket; |
| 67 | import org.onosproject.net.packet.PacketContext; |
Jonathan Hart | 3cfce8e | 2015-01-14 16:43:27 -0800 | [diff] [blame] | 68 | import org.onosproject.net.packet.PacketPriority; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 69 | import org.onosproject.net.packet.PacketProcessor; |
| 70 | import org.onosproject.net.packet.PacketService; |
Sahil Lele | a69534f | 2015-07-16 15:14:57 -0700 | [diff] [blame] | 71 | import org.onosproject.net.topology.TopologyEvent; |
| 72 | import org.onosproject.net.topology.TopologyListener; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 73 | import org.onosproject.net.topology.TopologyService; |
tom | c16656f | 2014-10-15 18:30:31 -0700 | [diff] [blame] | 74 | import org.osgi.service.component.ComponentContext; |
tom | c370ebd | 2014-09-16 01:25:21 -0700 | [diff] [blame] | 75 | import org.slf4j.Logger; |
alshabib | 030111e | 2014-09-15 15:56:42 -0700 | [diff] [blame] | 76 | |
Jonathan Hart | 430223a | 2015-04-22 17:39:02 -0700 | [diff] [blame] | 77 | import java.util.Dictionary; |
Sahil Lele | 7b96166 | 2015-07-20 15:06:04 -0700 | [diff] [blame] | 78 | import java.util.HashMap; |
Sahil Lele | a69534f | 2015-07-16 15:14:57 -0700 | [diff] [blame] | 79 | import java.util.List; |
Sahil Lele | 7b96166 | 2015-07-20 15:06:04 -0700 | [diff] [blame] | 80 | import java.util.Map; |
Sahil Lele | a69534f | 2015-07-16 15:14:57 -0700 | [diff] [blame] | 81 | import java.util.Objects; |
Jonathan Hart | 430223a | 2015-04-22 17:39:02 -0700 | [diff] [blame] | 82 | import java.util.Set; |
| 83 | |
Jonathan Hart | 430223a | 2015-04-22 17:39:02 -0700 | [diff] [blame] | 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(); |
Jian Li | d9b5f55 | 2016-03-11 18:15:31 -0800 | [diff] [blame] | 254 | |
| 255 | Boolean packetOutOnlyEnabled = |
| 256 | Tools.isPropertyEnabled(properties, "packetOutOnly"); |
| 257 | if (packetOutOnlyEnabled == null) { |
| 258 | log.info("Packet-out is not configured, " + |
| 259 | "using current value of {}", packetOutOnly); |
| 260 | } else { |
Kunihiro Ishiguro | d37c9ca | 2014-12-31 16:05:40 +0900 | [diff] [blame] | 261 | packetOutOnly = packetOutOnlyEnabled; |
| 262 | log.info("Configured. Packet-out only forwarding is {}", |
Jian Li | d9b5f55 | 2016-03-11 18:15:31 -0800 | [diff] [blame] | 263 | packetOutOnly ? "enabled" : "disabled"); |
tom | c16656f | 2014-10-15 18:30:31 -0700 | [diff] [blame] | 264 | } |
Jian Li | d9b5f55 | 2016-03-11 18:15:31 -0800 | [diff] [blame] | 265 | |
| 266 | Boolean packetOutOfppTableEnabled = |
| 267 | Tools.isPropertyEnabled(properties, "packetOutOfppTable"); |
| 268 | if (packetOutOfppTableEnabled == null) { |
| 269 | log.info("OFPP_TABLE port is not configured, " + |
| 270 | "using current value of {}", packetOutOfppTable); |
| 271 | } else { |
Dusan Pajin | 0d1d48f | 2015-02-20 16:05:11 +0100 | [diff] [blame] | 272 | packetOutOfppTable = packetOutOfppTableEnabled; |
| 273 | log.info("Configured. Forwarding using OFPP_TABLE port is {}", |
Jian Li | d9b5f55 | 2016-03-11 18:15:31 -0800 | [diff] [blame] | 274 | packetOutOfppTable ? "enabled" : "disabled"); |
Dusan Pajin | 0d1d48f | 2015-02-20 16:05:11 +0100 | [diff] [blame] | 275 | } |
Jian Li | d9b5f55 | 2016-03-11 18:15:31 -0800 | [diff] [blame] | 276 | |
| 277 | Boolean ipv6ForwardingEnabled = |
| 278 | Tools.isPropertyEnabled(properties, "ipv6Forwarding"); |
| 279 | if (ipv6ForwardingEnabled == null) { |
| 280 | log.info("IPv6 forwarding is not configured, " + |
| 281 | "using current value of {}", ipv6Forwarding); |
| 282 | } else { |
Kunihiro Ishiguro | d37c9ca | 2014-12-31 16:05:40 +0900 | [diff] [blame] | 283 | ipv6Forwarding = ipv6ForwardingEnabled; |
| 284 | log.info("Configured. IPv6 forwarding is {}", |
Jian Li | d9b5f55 | 2016-03-11 18:15:31 -0800 | [diff] [blame] | 285 | ipv6Forwarding ? "enabled" : "disabled"); |
Kunihiro Ishiguro | d37c9ca | 2014-12-31 16:05:40 +0900 | [diff] [blame] | 286 | } |
Jian Li | d9b5f55 | 2016-03-11 18:15:31 -0800 | [diff] [blame] | 287 | |
| 288 | Boolean matchDstMacOnlyEnabled = |
| 289 | Tools.isPropertyEnabled(properties, "matchDstMacOnly"); |
| 290 | if (matchDstMacOnlyEnabled == null) { |
| 291 | log.info("Match Dst MAC is not configured, " + |
| 292 | "using current value of {}", matchDstMacOnly); |
| 293 | } else { |
Dusan Pajin | 0d1d48f | 2015-02-20 16:05:11 +0100 | [diff] [blame] | 294 | matchDstMacOnly = matchDstMacOnlyEnabled; |
| 295 | log.info("Configured. Match Dst MAC Only is {}", |
Jian Li | d9b5f55 | 2016-03-11 18:15:31 -0800 | [diff] [blame] | 296 | matchDstMacOnly ? "enabled" : "disabled"); |
Dusan Pajin | 0d1d48f | 2015-02-20 16:05:11 +0100 | [diff] [blame] | 297 | } |
Jian Li | d9b5f55 | 2016-03-11 18:15:31 -0800 | [diff] [blame] | 298 | |
| 299 | Boolean matchVlanIdEnabled = |
| 300 | Tools.isPropertyEnabled(properties, "matchVlanId"); |
| 301 | if (matchVlanIdEnabled == null) { |
| 302 | log.info("Matching Vlan ID is not configured, " + |
| 303 | "using current value of {}", matchVlanId); |
| 304 | } else { |
Dusan Pajin | 0d1d48f | 2015-02-20 16:05:11 +0100 | [diff] [blame] | 305 | matchVlanId = matchVlanIdEnabled; |
| 306 | log.info("Configured. Matching Vlan ID is {}", |
Jian Li | d9b5f55 | 2016-03-11 18:15:31 -0800 | [diff] [blame] | 307 | matchVlanId ? "enabled" : "disabled"); |
Dusan Pajin | 0d1d48f | 2015-02-20 16:05:11 +0100 | [diff] [blame] | 308 | } |
Jian Li | d9b5f55 | 2016-03-11 18:15:31 -0800 | [diff] [blame] | 309 | |
| 310 | Boolean matchIpv4AddressEnabled = |
| 311 | Tools.isPropertyEnabled(properties, "matchIpv4Address"); |
| 312 | if (matchIpv4AddressEnabled == null) { |
| 313 | log.info("Matching IPv4 Address is not configured, " + |
| 314 | "using current value of {}", matchIpv4Address); |
| 315 | } else { |
Dusan Pajin | 0d1d48f | 2015-02-20 16:05:11 +0100 | [diff] [blame] | 316 | matchIpv4Address = matchIpv4AddressEnabled; |
| 317 | log.info("Configured. Matching IPv4 Addresses is {}", |
Jian Li | d9b5f55 | 2016-03-11 18:15:31 -0800 | [diff] [blame] | 318 | matchIpv4Address ? "enabled" : "disabled"); |
Dusan Pajin | 0d1d48f | 2015-02-20 16:05:11 +0100 | [diff] [blame] | 319 | } |
Jian Li | d9b5f55 | 2016-03-11 18:15:31 -0800 | [diff] [blame] | 320 | |
| 321 | Boolean matchIpv4DscpEnabled = |
| 322 | Tools.isPropertyEnabled(properties, "matchIpv4Dscp"); |
| 323 | if (matchIpv4DscpEnabled == null) { |
| 324 | log.info("Matching IPv4 DSCP and ECN is not configured, " + |
| 325 | "using current value of {}", matchIpv4Dscp); |
| 326 | } else { |
Dusan Pajin | 0d1d48f | 2015-02-20 16:05:11 +0100 | [diff] [blame] | 327 | matchIpv4Dscp = matchIpv4DscpEnabled; |
| 328 | log.info("Configured. Matching IPv4 DSCP and ECN is {}", |
Jian Li | d9b5f55 | 2016-03-11 18:15:31 -0800 | [diff] [blame] | 329 | matchIpv4Dscp ? "enabled" : "disabled"); |
Dusan Pajin | 0d1d48f | 2015-02-20 16:05:11 +0100 | [diff] [blame] | 330 | } |
Jian Li | d9b5f55 | 2016-03-11 18:15:31 -0800 | [diff] [blame] | 331 | |
| 332 | Boolean matchIpv6AddressEnabled = |
| 333 | Tools.isPropertyEnabled(properties, "matchIpv6Address"); |
| 334 | if (matchIpv6AddressEnabled == null) { |
| 335 | log.info("Matching IPv6 Address is not configured, " + |
| 336 | "using current value of {}", matchIpv6Address); |
| 337 | } else { |
Dusan Pajin | 0d1d48f | 2015-02-20 16:05:11 +0100 | [diff] [blame] | 338 | matchIpv6Address = matchIpv6AddressEnabled; |
| 339 | log.info("Configured. Matching IPv6 Addresses is {}", |
Jian Li | d9b5f55 | 2016-03-11 18:15:31 -0800 | [diff] [blame] | 340 | matchIpv6Address ? "enabled" : "disabled"); |
Dusan Pajin | 0d1d48f | 2015-02-20 16:05:11 +0100 | [diff] [blame] | 341 | } |
Jian Li | d9b5f55 | 2016-03-11 18:15:31 -0800 | [diff] [blame] | 342 | |
| 343 | Boolean matchIpv6FlowLabelEnabled = |
| 344 | Tools.isPropertyEnabled(properties, "matchIpv6FlowLabel"); |
| 345 | if (matchIpv6FlowLabelEnabled == null) { |
| 346 | log.info("Matching IPv6 FlowLabel is not configured, " + |
| 347 | "using current value of {}", matchIpv6FlowLabel); |
| 348 | } else { |
Dusan Pajin | 0d1d48f | 2015-02-20 16:05:11 +0100 | [diff] [blame] | 349 | matchIpv6FlowLabel = matchIpv6FlowLabelEnabled; |
| 350 | log.info("Configured. Matching IPv6 FlowLabel is {}", |
Jian Li | d9b5f55 | 2016-03-11 18:15:31 -0800 | [diff] [blame] | 351 | matchIpv6FlowLabel ? "enabled" : "disabled"); |
Dusan Pajin | 0d1d48f | 2015-02-20 16:05:11 +0100 | [diff] [blame] | 352 | } |
Jian Li | d9b5f55 | 2016-03-11 18:15:31 -0800 | [diff] [blame] | 353 | |
| 354 | Boolean matchTcpUdpPortsEnabled = |
| 355 | Tools.isPropertyEnabled(properties, "matchTcpUdpPorts"); |
| 356 | if (matchTcpUdpPortsEnabled == null) { |
| 357 | log.info("Matching TCP/UDP fields is not configured, " + |
| 358 | "using current value of {}", matchTcpUdpPorts); |
| 359 | } else { |
Dusan Pajin | 0d1d48f | 2015-02-20 16:05:11 +0100 | [diff] [blame] | 360 | matchTcpUdpPorts = matchTcpUdpPortsEnabled; |
| 361 | log.info("Configured. Matching TCP/UDP fields is {}", |
Jian Li | d9b5f55 | 2016-03-11 18:15:31 -0800 | [diff] [blame] | 362 | matchTcpUdpPorts ? "enabled" : "disabled"); |
Dusan Pajin | 0d1d48f | 2015-02-20 16:05:11 +0100 | [diff] [blame] | 363 | } |
Jian Li | d9b5f55 | 2016-03-11 18:15:31 -0800 | [diff] [blame] | 364 | |
| 365 | Boolean matchIcmpFieldsEnabled = |
| 366 | Tools.isPropertyEnabled(properties, "matchIcmpFields"); |
| 367 | if (matchIcmpFieldsEnabled == null) { |
| 368 | log.info("Matching ICMP (v4 and v6) fields is not configured, " + |
| 369 | "using current value of {}", matchIcmpFields); |
| 370 | } else { |
Dusan Pajin | 0d1d48f | 2015-02-20 16:05:11 +0100 | [diff] [blame] | 371 | matchIcmpFields = matchIcmpFieldsEnabled; |
| 372 | log.info("Configured. Matching ICMP (v4 and v6) fields is {}", |
Jian Li | d9b5f55 | 2016-03-11 18:15:31 -0800 | [diff] [blame] | 373 | matchIcmpFields ? "enabled" : "disabled"); |
Dusan Pajin | 0d1d48f | 2015-02-20 16:05:11 +0100 | [diff] [blame] | 374 | } |
Rusty Eddy | 29acad6 | 2015-07-07 19:33:47 -0700 | [diff] [blame] | 375 | |
Jian Li | d9b5f55 | 2016-03-11 18:15:31 -0800 | [diff] [blame] | 376 | Boolean ignoreIpv4McastPacketsEnabled = |
| 377 | Tools.isPropertyEnabled(properties, "ignoreIpv4McastPackets"); |
| 378 | if (ignoreIpv4McastPacketsEnabled == null) { |
| 379 | log.info("Ignore IPv4 multi-cast packet is not configured, " + |
| 380 | "using current value of {}", ignoreIpv4McastPackets); |
| 381 | } else { |
Rusty Eddy | 29acad6 | 2015-07-07 19:33:47 -0700 | [diff] [blame] | 382 | ignoreIpv4McastPackets = ignoreIpv4McastPacketsEnabled; |
| 383 | log.info("Configured. Ignore IPv4 multicast packets is {}", |
Jian Li | d9b5f55 | 2016-03-11 18:15:31 -0800 | [diff] [blame] | 384 | ignoreIpv4McastPackets ? "enabled" : "disabled"); |
Rusty Eddy | 29acad6 | 2015-07-07 19:33:47 -0700 | [diff] [blame] | 385 | } |
Jian Li | d9b5f55 | 2016-03-11 18:15:31 -0800 | [diff] [blame] | 386 | flowTimeout = Tools.getIntegerProperty(properties, "flowTimeout", DEFAULT_TIMEOUT); |
Yoonseon Han | 2f011ad | 2016-08-08 17:06:56 -0700 | [diff] [blame] | 387 | log.info("Configured. Flow Timeout is configured to {} seconds", flowTimeout); |
Dusan Pajin | 0d1d48f | 2015-02-20 16:05:11 +0100 | [diff] [blame] | 388 | |
Jian Li | d9b5f55 | 2016-03-11 18:15:31 -0800 | [diff] [blame] | 389 | flowPriority = Tools.getIntegerProperty(properties, "flowPriority", DEFAULT_PRIORITY); |
| 390 | log.info("Configured. Flow Priority is configured to {}", flowPriority); |
tom | c16656f | 2014-10-15 18:30:31 -0700 | [diff] [blame] | 391 | } |
tom | c370ebd | 2014-09-16 01:25:21 -0700 | [diff] [blame] | 392 | |
| 393 | /** |
| 394 | * Packet processor responsible for forwarding packets along their paths. |
| 395 | */ |
| 396 | private class ReactivePacketProcessor implements PacketProcessor { |
| 397 | |
| 398 | @Override |
| 399 | public void process(PacketContext context) { |
tom | dc95b8a | 2014-09-17 08:07:26 -0700 | [diff] [blame] | 400 | // Stop processing if the packet has been handled, since we |
| 401 | // can't do any more to it. |
Sahil Lele | a69534f | 2015-07-16 15:14:57 -0700 | [diff] [blame] | 402 | |
Thomas Vachuska | bd7f4b3 | 2014-12-04 20:54:55 -0800 | [diff] [blame] | 403 | if (context.isHandled()) { |
alshabib | 7b2748f | 2014-09-16 20:21:11 -0700 | [diff] [blame] | 404 | return; |
| 405 | } |
tom | dc95b8a | 2014-09-17 08:07:26 -0700 | [diff] [blame] | 406 | |
tom | c370ebd | 2014-09-16 01:25:21 -0700 | [diff] [blame] | 407 | InboundPacket pkt = context.inPacket(); |
tom | 642b226 | 2014-09-17 13:52:55 -0700 | [diff] [blame] | 408 | Ethernet ethPkt = pkt.parsed(); |
alshabib | 6eb438a | 2014-10-01 16:39:37 -0700 | [diff] [blame] | 409 | |
Jonathan Hart | e8600eb | 2015-01-12 10:30:45 -0800 | [diff] [blame] | 410 | if (ethPkt == null) { |
| 411 | return; |
| 412 | } |
| 413 | |
Kunihiro Ishiguro | d37c9ca | 2014-12-31 16:05:40 +0900 | [diff] [blame] | 414 | // Bail if this is deemed to be a control packet. |
| 415 | if (isControlPacket(ethPkt)) { |
| 416 | return; |
| 417 | } |
| 418 | |
| 419 | // Skip IPv6 multicast packet when IPv6 forward is disabled. |
| 420 | if (!ipv6Forwarding && isIpv6Multicast(ethPkt)) { |
Thomas Vachuska | 01a6ec0 | 2014-11-05 09:54:09 -0800 | [diff] [blame] | 421 | return; |
| 422 | } |
| 423 | |
tom | 642b226 | 2014-09-17 13:52:55 -0700 | [diff] [blame] | 424 | HostId id = HostId.hostId(ethPkt.getDestinationMAC()); |
tom | c370ebd | 2014-09-16 01:25:21 -0700 | [diff] [blame] | 425 | |
Thomas Vachuska | e1bcb0b | 2014-10-27 17:45:10 -0700 | [diff] [blame] | 426 | // Do not process link-local addresses in any way. |
| 427 | if (id.mac().isLinkLocal()) { |
| 428 | return; |
| 429 | } |
| 430 | |
Rusty Eddy | 29acad6 | 2015-07-07 19:33:47 -0700 | [diff] [blame] | 431 | // Do not process IPv4 multicast packets, let mfwd handle them |
| 432 | if (ignoreIpv4McastPackets && ethPkt.getEtherType() == Ethernet.TYPE_IPV4) { |
| 433 | if (id.mac().isMulticast()) { |
| 434 | return; |
| 435 | } |
| 436 | } |
| 437 | |
tom | c370ebd | 2014-09-16 01:25:21 -0700 | [diff] [blame] | 438 | // Do we know who this is for? If not, flood and bail. |
| 439 | Host dst = hostService.getHost(id); |
| 440 | if (dst == null) { |
| 441 | flood(context); |
| 442 | return; |
| 443 | } |
| 444 | |
| 445 | // Are we on an edge switch that our destination is on? If so, |
| 446 | // simply forward out to the destination and bail. |
| 447 | if (pkt.receivedFrom().deviceId().equals(dst.location().deviceId())) { |
alshabib | 6eb438a | 2014-10-01 16:39:37 -0700 | [diff] [blame] | 448 | if (!context.inPacket().receivedFrom().port().equals(dst.location().port())) { |
| 449 | installRule(context, dst.location().port()); |
| 450 | } |
tom | c370ebd | 2014-09-16 01:25:21 -0700 | [diff] [blame] | 451 | return; |
| 452 | } |
| 453 | |
| 454 | // Otherwise, get a set of paths that lead from here to the |
| 455 | // destination edge switch. |
Dusan Pajin | 0d1d48f | 2015-02-20 16:05:11 +0100 | [diff] [blame] | 456 | Set<Path> paths = |
Thomas Vachuska | 27bee09 | 2015-06-23 19:03:10 -0700 | [diff] [blame] | 457 | topologyService.getPaths(topologyService.currentTopology(), |
| 458 | pkt.receivedFrom().deviceId(), |
| 459 | dst.location().deviceId()); |
tom | c370ebd | 2014-09-16 01:25:21 -0700 | [diff] [blame] | 460 | if (paths.isEmpty()) { |
| 461 | // If there are no paths, flood and bail. |
| 462 | flood(context); |
| 463 | return; |
| 464 | } |
| 465 | |
| 466 | // Otherwise, pick a path that does not lead back to where we |
| 467 | // came from; if no such path, flood and bail. |
Thomas Vachuska | 320c58f | 2015-08-05 10:42:32 -0700 | [diff] [blame] | 468 | Path path = pickForwardPathIfPossible(paths, pkt.receivedFrom().port()); |
tom | c370ebd | 2014-09-16 01:25:21 -0700 | [diff] [blame] | 469 | if (path == null) { |
Thomas Vachuska | 320c58f | 2015-08-05 10:42:32 -0700 | [diff] [blame] | 470 | log.warn("Don't know where to go from here {} for {} -> {}", |
| 471 | pkt.receivedFrom(), ethPkt.getSourceMAC(), ethPkt.getDestinationMAC()); |
tom | c370ebd | 2014-09-16 01:25:21 -0700 | [diff] [blame] | 472 | flood(context); |
| 473 | return; |
| 474 | } |
| 475 | |
| 476 | // Otherwise forward and be done with it. |
alshabib | 7b2748f | 2014-09-16 20:21:11 -0700 | [diff] [blame] | 477 | installRule(context, path.src().port()); |
tom | c370ebd | 2014-09-16 01:25:21 -0700 | [diff] [blame] | 478 | } |
Thomas Vachuska | 01a6ec0 | 2014-11-05 09:54:09 -0800 | [diff] [blame] | 479 | |
| 480 | } |
| 481 | |
| 482 | // Indicates whether this is a control packet, e.g. LLDP, BDDP |
| 483 | private boolean isControlPacket(Ethernet eth) { |
| 484 | short type = eth.getEtherType(); |
| 485 | return type == Ethernet.TYPE_LLDP || type == Ethernet.TYPE_BSN; |
tom | c370ebd | 2014-09-16 01:25:21 -0700 | [diff] [blame] | 486 | } |
| 487 | |
Thomas Vachuska | 5dd52f7 | 2014-11-28 19:27:45 -0800 | [diff] [blame] | 488 | // Indicated whether this is an IPv6 multicast packet. |
| 489 | private boolean isIpv6Multicast(Ethernet eth) { |
| 490 | return eth.getEtherType() == Ethernet.TYPE_IPV6 && eth.isMulticast(); |
| 491 | } |
| 492 | |
tom | c370ebd | 2014-09-16 01:25:21 -0700 | [diff] [blame] | 493 | // 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] | 494 | // specified port if possible. |
| 495 | private Path pickForwardPathIfPossible(Set<Path> paths, PortNumber notToPort) { |
| 496 | Path lastPath = null; |
tom | c370ebd | 2014-09-16 01:25:21 -0700 | [diff] [blame] | 497 | for (Path path : paths) { |
Thomas Vachuska | 320c58f | 2015-08-05 10:42:32 -0700 | [diff] [blame] | 498 | lastPath = path; |
tom | c370ebd | 2014-09-16 01:25:21 -0700 | [diff] [blame] | 499 | if (!path.src().port().equals(notToPort)) { |
| 500 | return path; |
| 501 | } |
| 502 | } |
Thomas Vachuska | 320c58f | 2015-08-05 10:42:32 -0700 | [diff] [blame] | 503 | return lastPath; |
tom | c370ebd | 2014-09-16 01:25:21 -0700 | [diff] [blame] | 504 | } |
| 505 | |
tom | 642b226 | 2014-09-17 13:52:55 -0700 | [diff] [blame] | 506 | // Floods the specified packet if permissible. |
tom | c370ebd | 2014-09-16 01:25:21 -0700 | [diff] [blame] | 507 | private void flood(PacketContext context) { |
tom | dc95b8a | 2014-09-17 08:07:26 -0700 | [diff] [blame] | 508 | if (topologyService.isBroadcastPoint(topologyService.currentTopology(), |
tom | c16656f | 2014-10-15 18:30:31 -0700 | [diff] [blame] | 509 | context.inPacket().receivedFrom())) { |
tom | 642b226 | 2014-09-17 13:52:55 -0700 | [diff] [blame] | 510 | packetOut(context, PortNumber.FLOOD); |
tom | c370ebd | 2014-09-16 01:25:21 -0700 | [diff] [blame] | 511 | } else { |
| 512 | context.block(); |
| 513 | } |
| 514 | } |
| 515 | |
tom | 642b226 | 2014-09-17 13:52:55 -0700 | [diff] [blame] | 516 | // Sends a packet out the specified port. |
| 517 | private void packetOut(PacketContext context, PortNumber portNumber) { |
alshabib | 010c31d | 2014-09-26 10:01:12 -0700 | [diff] [blame] | 518 | context.treatmentBuilder().setOutput(portNumber); |
alshabib | 7b2748f | 2014-09-16 20:21:11 -0700 | [diff] [blame] | 519 | context.send(); |
| 520 | } |
| 521 | |
| 522 | // Install a rule forwarding the packet to the specified port. |
| 523 | private void installRule(PacketContext context, PortNumber portNumber) { |
Dusan Pajin | 0d1d48f | 2015-02-20 16:05:11 +0100 | [diff] [blame] | 524 | // |
| 525 | // We don't support (yet) buffer IDs in the Flow Service so |
| 526 | // packet out first. |
| 527 | // |
| 528 | Ethernet inPkt = context.inPacket().parsed(); |
Jonathan Hart | 3b881aa | 2015-04-22 18:03:50 -0700 | [diff] [blame] | 529 | TrafficSelector.Builder selectorBuilder = DefaultTrafficSelector.builder(); |
Dusan Pajin | 0d1d48f | 2015-02-20 16:05:11 +0100 | [diff] [blame] | 530 | |
| 531 | // If PacketOutOnly or ARP packet than forward directly to output port |
| 532 | if (packetOutOnly || inPkt.getEtherType() == Ethernet.TYPE_ARP) { |
| 533 | packetOut(context, portNumber); |
| 534 | return; |
| 535 | } |
| 536 | |
| 537 | // |
| 538 | // If matchDstMacOnly |
| 539 | // Create flows matching dstMac only |
| 540 | // Else |
| 541 | // Create flows with default matching and include configured fields |
| 542 | // |
| 543 | if (matchDstMacOnly) { |
Jonathan Hart | 3b881aa | 2015-04-22 18:03:50 -0700 | [diff] [blame] | 544 | selectorBuilder.matchEthDst(inPkt.getDestinationMAC()); |
Dusan Pajin | 0d1d48f | 2015-02-20 16:05:11 +0100 | [diff] [blame] | 545 | } else { |
Jonathan Hart | 3b881aa | 2015-04-22 18:03:50 -0700 | [diff] [blame] | 546 | selectorBuilder.matchInPort(context.inPacket().receivedFrom().port()) |
Thomas Vachuska | bd7f4b3 | 2014-12-04 20:54:55 -0800 | [diff] [blame] | 547 | .matchEthSrc(inPkt.getSourceMAC()) |
Jonathan Hart | 430223a | 2015-04-22 17:39:02 -0700 | [diff] [blame] | 548 | .matchEthDst(inPkt.getDestinationMAC()); |
alshabib | 7b2748f | 2014-09-16 20:21:11 -0700 | [diff] [blame] | 549 | |
Dusan Pajin | 0d1d48f | 2015-02-20 16:05:11 +0100 | [diff] [blame] | 550 | // If configured Match Vlan ID |
| 551 | if (matchVlanId && inPkt.getVlanID() != Ethernet.VLAN_UNTAGGED) { |
Jonathan Hart | 3b881aa | 2015-04-22 18:03:50 -0700 | [diff] [blame] | 552 | selectorBuilder.matchVlanId(VlanId.vlanId(inPkt.getVlanID())); |
Dusan Pajin | 0d1d48f | 2015-02-20 16:05:11 +0100 | [diff] [blame] | 553 | } |
alshabib | 7b2748f | 2014-09-16 20:21:11 -0700 | [diff] [blame] | 554 | |
Dusan Pajin | 0d1d48f | 2015-02-20 16:05:11 +0100 | [diff] [blame] | 555 | // |
| 556 | // If configured and EtherType is IPv4 - Match IPv4 and |
| 557 | // TCP/UDP/ICMP fields |
| 558 | // |
| 559 | if (matchIpv4Address && inPkt.getEtherType() == Ethernet.TYPE_IPV4) { |
| 560 | IPv4 ipv4Packet = (IPv4) inPkt.getPayload(); |
| 561 | byte ipv4Protocol = ipv4Packet.getProtocol(); |
| 562 | Ip4Prefix matchIp4SrcPrefix = |
Thomas Vachuska | 27bee09 | 2015-06-23 19:03:10 -0700 | [diff] [blame] | 563 | Ip4Prefix.valueOf(ipv4Packet.getSourceAddress(), |
| 564 | Ip4Prefix.MAX_MASK_LENGTH); |
Dusan Pajin | 0d1d48f | 2015-02-20 16:05:11 +0100 | [diff] [blame] | 565 | Ip4Prefix matchIp4DstPrefix = |
Thomas Vachuska | 27bee09 | 2015-06-23 19:03:10 -0700 | [diff] [blame] | 566 | Ip4Prefix.valueOf(ipv4Packet.getDestinationAddress(), |
| 567 | Ip4Prefix.MAX_MASK_LENGTH); |
Charles M.C. Chan | 7b8a921 | 2015-04-26 01:25:53 +0800 | [diff] [blame] | 568 | selectorBuilder.matchEthType(Ethernet.TYPE_IPV4) |
Jonathan Hart | 430223a | 2015-04-22 17:39:02 -0700 | [diff] [blame] | 569 | .matchIPSrc(matchIp4SrcPrefix) |
| 570 | .matchIPDst(matchIp4DstPrefix); |
alshabib | 6eb438a | 2014-10-01 16:39:37 -0700 | [diff] [blame] | 571 | |
Dusan Pajin | 0d1d48f | 2015-02-20 16:05:11 +0100 | [diff] [blame] | 572 | if (matchIpv4Dscp) { |
Pavlin Radoslavov | bf23c55 | 2015-02-20 14:20:30 -0800 | [diff] [blame] | 573 | byte dscp = ipv4Packet.getDscp(); |
| 574 | byte ecn = ipv4Packet.getEcn(); |
Jonathan Hart | 3b881aa | 2015-04-22 18:03:50 -0700 | [diff] [blame] | 575 | selectorBuilder.matchIPDscp(dscp).matchIPEcn(ecn); |
Dusan Pajin | 0d1d48f | 2015-02-20 16:05:11 +0100 | [diff] [blame] | 576 | } |
| 577 | |
| 578 | if (matchTcpUdpPorts && ipv4Protocol == IPv4.PROTOCOL_TCP) { |
| 579 | TCP tcpPacket = (TCP) ipv4Packet.getPayload(); |
Jonathan Hart | 3b881aa | 2015-04-22 18:03:50 -0700 | [diff] [blame] | 580 | selectorBuilder.matchIPProtocol(ipv4Protocol) |
Hyunsun Moon | cf732fb | 2015-08-22 21:04:23 -0700 | [diff] [blame] | 581 | .matchTcpSrc(TpPort.tpPort(tcpPacket.getSourcePort())) |
| 582 | .matchTcpDst(TpPort.tpPort(tcpPacket.getDestinationPort())); |
Dusan Pajin | 0d1d48f | 2015-02-20 16:05:11 +0100 | [diff] [blame] | 583 | } |
| 584 | if (matchTcpUdpPorts && ipv4Protocol == IPv4.PROTOCOL_UDP) { |
| 585 | UDP udpPacket = (UDP) ipv4Packet.getPayload(); |
Jonathan Hart | 3b881aa | 2015-04-22 18:03:50 -0700 | [diff] [blame] | 586 | selectorBuilder.matchIPProtocol(ipv4Protocol) |
Hyunsun Moon | cf732fb | 2015-08-22 21:04:23 -0700 | [diff] [blame] | 587 | .matchUdpSrc(TpPort.tpPort(udpPacket.getSourcePort())) |
| 588 | .matchUdpDst(TpPort.tpPort(udpPacket.getDestinationPort())); |
Dusan Pajin | 0d1d48f | 2015-02-20 16:05:11 +0100 | [diff] [blame] | 589 | } |
| 590 | if (matchIcmpFields && ipv4Protocol == IPv4.PROTOCOL_ICMP) { |
| 591 | ICMP icmpPacket = (ICMP) ipv4Packet.getPayload(); |
Jonathan Hart | 3b881aa | 2015-04-22 18:03:50 -0700 | [diff] [blame] | 592 | selectorBuilder.matchIPProtocol(ipv4Protocol) |
Jonathan Hart | 430223a | 2015-04-22 17:39:02 -0700 | [diff] [blame] | 593 | .matchIcmpType(icmpPacket.getIcmpType()) |
Dusan Pajin | 0d1d48f | 2015-02-20 16:05:11 +0100 | [diff] [blame] | 594 | .matchIcmpCode(icmpPacket.getIcmpCode()); |
| 595 | } |
| 596 | } |
| 597 | |
| 598 | // |
| 599 | // If configured and EtherType is IPv6 - Match IPv6 and |
| 600 | // TCP/UDP/ICMP fields |
| 601 | // |
| 602 | if (matchIpv6Address && inPkt.getEtherType() == Ethernet.TYPE_IPV6) { |
| 603 | IPv6 ipv6Packet = (IPv6) inPkt.getPayload(); |
| 604 | byte ipv6NextHeader = ipv6Packet.getNextHeader(); |
| 605 | Ip6Prefix matchIp6SrcPrefix = |
Thomas Vachuska | 27bee09 | 2015-06-23 19:03:10 -0700 | [diff] [blame] | 606 | Ip6Prefix.valueOf(ipv6Packet.getSourceAddress(), |
| 607 | Ip6Prefix.MAX_MASK_LENGTH); |
Dusan Pajin | 0d1d48f | 2015-02-20 16:05:11 +0100 | [diff] [blame] | 608 | Ip6Prefix matchIp6DstPrefix = |
Thomas Vachuska | 27bee09 | 2015-06-23 19:03:10 -0700 | [diff] [blame] | 609 | Ip6Prefix.valueOf(ipv6Packet.getDestinationAddress(), |
| 610 | Ip6Prefix.MAX_MASK_LENGTH); |
Charles M.C. Chan | 7b8a921 | 2015-04-26 01:25:53 +0800 | [diff] [blame] | 611 | selectorBuilder.matchEthType(Ethernet.TYPE_IPV6) |
| 612 | .matchIPv6Src(matchIp6SrcPrefix) |
Jonathan Hart | 430223a | 2015-04-22 17:39:02 -0700 | [diff] [blame] | 613 | .matchIPv6Dst(matchIp6DstPrefix); |
Dusan Pajin | 0d1d48f | 2015-02-20 16:05:11 +0100 | [diff] [blame] | 614 | |
| 615 | if (matchIpv6FlowLabel) { |
Jonathan Hart | 3b881aa | 2015-04-22 18:03:50 -0700 | [diff] [blame] | 616 | selectorBuilder.matchIPv6FlowLabel(ipv6Packet.getFlowLabel()); |
Dusan Pajin | 0d1d48f | 2015-02-20 16:05:11 +0100 | [diff] [blame] | 617 | } |
| 618 | |
| 619 | if (matchTcpUdpPorts && ipv6NextHeader == IPv6.PROTOCOL_TCP) { |
| 620 | TCP tcpPacket = (TCP) ipv6Packet.getPayload(); |
Jonathan Hart | 3b881aa | 2015-04-22 18:03:50 -0700 | [diff] [blame] | 621 | selectorBuilder.matchIPProtocol(ipv6NextHeader) |
Hyunsun Moon | cf732fb | 2015-08-22 21:04:23 -0700 | [diff] [blame] | 622 | .matchTcpSrc(TpPort.tpPort(tcpPacket.getSourcePort())) |
| 623 | .matchTcpDst(TpPort.tpPort(tcpPacket.getDestinationPort())); |
Dusan Pajin | 0d1d48f | 2015-02-20 16:05:11 +0100 | [diff] [blame] | 624 | } |
| 625 | if (matchTcpUdpPorts && ipv6NextHeader == IPv6.PROTOCOL_UDP) { |
| 626 | UDP udpPacket = (UDP) ipv6Packet.getPayload(); |
Jonathan Hart | 3b881aa | 2015-04-22 18:03:50 -0700 | [diff] [blame] | 627 | selectorBuilder.matchIPProtocol(ipv6NextHeader) |
Hyunsun Moon | cf732fb | 2015-08-22 21:04:23 -0700 | [diff] [blame] | 628 | .matchUdpSrc(TpPort.tpPort(udpPacket.getSourcePort())) |
| 629 | .matchUdpDst(TpPort.tpPort(udpPacket.getDestinationPort())); |
Dusan Pajin | 0d1d48f | 2015-02-20 16:05:11 +0100 | [diff] [blame] | 630 | } |
| 631 | if (matchIcmpFields && ipv6NextHeader == IPv6.PROTOCOL_ICMP6) { |
| 632 | ICMP6 icmp6Packet = (ICMP6) ipv6Packet.getPayload(); |
Jonathan Hart | 3b881aa | 2015-04-22 18:03:50 -0700 | [diff] [blame] | 633 | selectorBuilder.matchIPProtocol(ipv6NextHeader) |
Jonathan Hart | 430223a | 2015-04-22 17:39:02 -0700 | [diff] [blame] | 634 | .matchIcmpv6Type(icmp6Packet.getIcmpType()) |
Dusan Pajin | 0d1d48f | 2015-02-20 16:05:11 +0100 | [diff] [blame] | 635 | .matchIcmpv6Code(icmp6Packet.getIcmpCode()); |
| 636 | } |
| 637 | } |
| 638 | } |
Jonathan Hart | 3b881aa | 2015-04-22 18:03:50 -0700 | [diff] [blame] | 639 | TrafficTreatment treatment = DefaultTrafficTreatment.builder() |
| 640 | .setOutput(portNumber) |
| 641 | .build(); |
Dusan Pajin | 0d1d48f | 2015-02-20 16:05:11 +0100 | [diff] [blame] | 642 | |
Jonathan Hart | 3b881aa | 2015-04-22 18:03:50 -0700 | [diff] [blame] | 643 | ForwardingObjective forwardingObjective = DefaultForwardingObjective.builder() |
| 644 | .withSelector(selectorBuilder.build()) |
| 645 | .withTreatment(treatment) |
| 646 | .withPriority(flowPriority) |
| 647 | .withFlag(ForwardingObjective.Flag.VERSATILE) |
| 648 | .fromApp(appId) |
| 649 | .makeTemporary(flowTimeout) |
| 650 | .add(); |
Dusan Pajin | 0d1d48f | 2015-02-20 16:05:11 +0100 | [diff] [blame] | 651 | |
Jonathan Hart | 3b881aa | 2015-04-22 18:03:50 -0700 | [diff] [blame] | 652 | flowObjectiveService.forward(context.inPacket().receivedFrom().deviceId(), |
| 653 | forwardingObjective); |
Dusan Pajin | 0d1d48f | 2015-02-20 16:05:11 +0100 | [diff] [blame] | 654 | |
| 655 | // |
| 656 | // If packetOutOfppTable |
| 657 | // Send packet back to the OpenFlow pipeline to match installed flow |
| 658 | // Else |
| 659 | // Send packet direction on the appropriate port |
| 660 | // |
| 661 | if (packetOutOfppTable) { |
| 662 | packetOut(context, PortNumber.TABLE); |
| 663 | } else { |
| 664 | packetOut(context, portNumber); |
Thomas Vachuska | bd7f4b3 | 2014-12-04 20:54:55 -0800 | [diff] [blame] | 665 | } |
tom | c370ebd | 2014-09-16 01:25:21 -0700 | [diff] [blame] | 666 | } |
Sahil Lele | a69534f | 2015-07-16 15:14:57 -0700 | [diff] [blame] | 667 | |
| 668 | private class InternalTopologyListener implements TopologyListener { |
| 669 | @Override |
| 670 | public void event(TopologyEvent event) { |
| 671 | List<Event> reasons = event.reasons(); |
| 672 | if (reasons != null) { |
| 673 | reasons.forEach(re -> { |
| 674 | if (re instanceof LinkEvent) { |
| 675 | LinkEvent le = (LinkEvent) re; |
| 676 | if (le.type() == LinkEvent.Type.LINK_REMOVED) { |
| 677 | fixBlackhole(le.subject().src()); |
| 678 | } |
| 679 | } |
| 680 | }); |
| 681 | } |
| 682 | } |
| 683 | } |
| 684 | |
| 685 | private void fixBlackhole(ConnectPoint egress) { |
Thomas Vachuska | 8d03367 | 2015-07-21 16:15:04 -0700 | [diff] [blame] | 686 | Set<FlowEntry> rules = getFlowRulesFrom(egress); |
Sahil Lele | a69534f | 2015-07-16 15:14:57 -0700 | [diff] [blame] | 687 | Set<SrcDstPair> pairs = findSrcDstPairs(rules); |
| 688 | |
Sahil Lele | 7b96166 | 2015-07-20 15:06:04 -0700 | [diff] [blame] | 689 | Map<DeviceId, Set<Path>> srcPaths = new HashMap<>(); |
| 690 | |
Thomas Vachuska | 8d03367 | 2015-07-21 16:15:04 -0700 | [diff] [blame] | 691 | for (SrcDstPair sd : pairs) { |
Sahil Lele | a69534f | 2015-07-16 15:14:57 -0700 | [diff] [blame] | 692 | // get the edge deviceID for the src host |
Sahil Lele | 0f8d00e | 2015-07-24 11:05:43 -0700 | [diff] [blame] | 693 | Host srcHost = hostService.getHost(HostId.hostId(sd.src)); |
| 694 | Host dstHost = hostService.getHost(HostId.hostId(sd.dst)); |
| 695 | if (srcHost != null && dstHost != null) { |
| 696 | DeviceId srcId = srcHost.location().deviceId(); |
| 697 | DeviceId dstId = dstHost.location().deviceId(); |
| 698 | log.trace("SRC ID is " + srcId + ", DST ID is " + dstId); |
Sahil Lele | a69534f | 2015-07-16 15:14:57 -0700 | [diff] [blame] | 699 | |
Sahil Lele | 0f8d00e | 2015-07-24 11:05:43 -0700 | [diff] [blame] | 700 | cleanFlowRules(sd, egress.deviceId()); |
Sahil Lele | a69534f | 2015-07-16 15:14:57 -0700 | [diff] [blame] | 701 | |
Sahil Lele | 0f8d00e | 2015-07-24 11:05:43 -0700 | [diff] [blame] | 702 | Set<Path> shortestPaths = srcPaths.get(srcId); |
| 703 | if (shortestPaths == null) { |
| 704 | shortestPaths = topologyService.getPaths(topologyService.currentTopology(), |
| 705 | egress.deviceId(), srcId); |
| 706 | srcPaths.put(srcId, shortestPaths); |
| 707 | } |
| 708 | backTrackBadNodes(shortestPaths, dstId, sd); |
Sahil Lele | 7b96166 | 2015-07-20 15:06:04 -0700 | [diff] [blame] | 709 | } |
Sahil Lele | a69534f | 2015-07-16 15:14:57 -0700 | [diff] [blame] | 710 | } |
| 711 | } |
| 712 | |
| 713 | // Backtracks from link down event to remove flows that lead to blackhole |
| 714 | private void backTrackBadNodes(Set<Path> shortestPaths, DeviceId dstId, SrcDstPair sd) { |
Thomas Vachuska | 8d03367 | 2015-07-21 16:15:04 -0700 | [diff] [blame] | 715 | for (Path p : shortestPaths) { |
Sahil Lele | a69534f | 2015-07-16 15:14:57 -0700 | [diff] [blame] | 716 | List<Link> pathLinks = p.links(); |
| 717 | for (int i = 0; i < pathLinks.size(); i = i + 1) { |
| 718 | Link curLink = pathLinks.get(i); |
| 719 | DeviceId curDevice = curLink.src().deviceId(); |
Sahil Lele | a69534f | 2015-07-16 15:14:57 -0700 | [diff] [blame] | 720 | |
| 721 | // skipping the first link because this link's src has already been pruned beforehand |
| 722 | if (i != 0) { |
| 723 | cleanFlowRules(sd, curDevice); |
| 724 | } |
| 725 | |
Thomas Vachuska | 8d03367 | 2015-07-21 16:15:04 -0700 | [diff] [blame] | 726 | Set<Path> pathsFromCurDevice = |
| 727 | topologyService.getPaths(topologyService.currentTopology(), |
| 728 | curDevice, dstId); |
Thomas Vachuska | 320c58f | 2015-08-05 10:42:32 -0700 | [diff] [blame] | 729 | if (pickForwardPathIfPossible(pathsFromCurDevice, curLink.src().port()) != null) { |
Sahil Lele | a69534f | 2015-07-16 15:14:57 -0700 | [diff] [blame] | 730 | break; |
| 731 | } else { |
| 732 | if (i + 1 == pathLinks.size()) { |
| 733 | cleanFlowRules(sd, curLink.dst().deviceId()); |
| 734 | } |
| 735 | } |
| 736 | } |
| 737 | } |
| 738 | } |
| 739 | |
| 740 | // Removes flow rules off specified device with specific SrcDstPair |
| 741 | private void cleanFlowRules(SrcDstPair pair, DeviceId id) { |
| 742 | log.trace("Searching for flow rules to remove from: " + id); |
| 743 | log.trace("Removing flows w/ SRC=" + pair.src + ", DST=" + pair.dst); |
| 744 | for (FlowEntry r : flowRuleService.getFlowEntries(id)) { |
| 745 | boolean matchesSrc = false, matchesDst = false; |
| 746 | for (Instruction i : r.treatment().allInstructions()) { |
| 747 | if (i.type() == Instruction.Type.OUTPUT) { |
Thomas Vachuska | 8d03367 | 2015-07-21 16:15:04 -0700 | [diff] [blame] | 748 | // if the flow has matching src and dst |
Sahil Lele | a69534f | 2015-07-16 15:14:57 -0700 | [diff] [blame] | 749 | for (Criterion cr : r.selector().criteria()) { |
| 750 | if (cr.type() == Criterion.Type.ETH_DST) { |
| 751 | if (((EthCriterion) cr).mac().equals(pair.dst)) { |
| 752 | matchesDst = true; |
| 753 | } |
| 754 | } else if (cr.type() == Criterion.Type.ETH_SRC) { |
| 755 | if (((EthCriterion) cr).mac().equals(pair.src)) { |
| 756 | matchesSrc = true; |
| 757 | } |
| 758 | } |
| 759 | } |
| 760 | } |
| 761 | } |
| 762 | if (matchesDst && matchesSrc) { |
| 763 | log.trace("Removed flow rule from device: " + id); |
| 764 | flowRuleService.removeFlowRules((FlowRule) r); |
| 765 | } |
| 766 | } |
| 767 | |
| 768 | } |
| 769 | |
| 770 | // Returns a set of src/dst MAC pairs extracted from the specified set of flow entries |
| 771 | private Set<SrcDstPair> findSrcDstPairs(Set<FlowEntry> rules) { |
| 772 | ImmutableSet.Builder<SrcDstPair> builder = ImmutableSet.builder(); |
Thomas Vachuska | 8d03367 | 2015-07-21 16:15:04 -0700 | [diff] [blame] | 773 | for (FlowEntry r : rules) { |
Sahil Lele | a69534f | 2015-07-16 15:14:57 -0700 | [diff] [blame] | 774 | MacAddress src = null, dst = null; |
Thomas Vachuska | 8d03367 | 2015-07-21 16:15:04 -0700 | [diff] [blame] | 775 | for (Criterion cr : r.selector().criteria()) { |
Sahil Lele | a69534f | 2015-07-16 15:14:57 -0700 | [diff] [blame] | 776 | if (cr.type() == Criterion.Type.ETH_DST) { |
| 777 | dst = ((EthCriterion) cr).mac(); |
| 778 | } else if (cr.type() == Criterion.Type.ETH_SRC) { |
| 779 | src = ((EthCriterion) cr).mac(); |
| 780 | } |
| 781 | } |
| 782 | builder.add(new SrcDstPair(src, dst)); |
| 783 | } |
| 784 | return builder.build(); |
| 785 | } |
| 786 | |
Thomas Vachuska | 320c58f | 2015-08-05 10:42:32 -0700 | [diff] [blame] | 787 | // Returns set of flow entries which were created by this application and |
| 788 | // which egress from the specified connection port |
Sahil Lele | a69534f | 2015-07-16 15:14:57 -0700 | [diff] [blame] | 789 | private Set<FlowEntry> getFlowRulesFrom(ConnectPoint egress) { |
| 790 | ImmutableSet.Builder<FlowEntry> builder = ImmutableSet.builder(); |
| 791 | flowRuleService.getFlowEntries(egress.deviceId()).forEach(r -> { |
| 792 | if (r.appId() == appId.id()) { |
| 793 | r.treatment().allInstructions().forEach(i -> { |
| 794 | if (i.type() == Instruction.Type.OUTPUT) { |
| 795 | if (((Instructions.OutputInstruction) i).port().equals(egress.port())) { |
| 796 | builder.add(r); |
| 797 | } |
| 798 | } |
| 799 | }); |
| 800 | } |
| 801 | }); |
| 802 | |
| 803 | return builder.build(); |
| 804 | } |
| 805 | |
| 806 | // Wrapper class for a source and destination pair of MAC addresses |
| 807 | private final class SrcDstPair { |
| 808 | final MacAddress src; |
| 809 | final MacAddress dst; |
| 810 | |
| 811 | private SrcDstPair(MacAddress src, MacAddress dst) { |
| 812 | this.src = src; |
| 813 | this.dst = dst; |
| 814 | } |
| 815 | |
| 816 | @Override |
| 817 | public boolean equals(Object o) { |
| 818 | if (this == o) { |
| 819 | return true; |
| 820 | } |
| 821 | if (o == null || getClass() != o.getClass()) { |
| 822 | return false; |
| 823 | } |
| 824 | SrcDstPair that = (SrcDstPair) o; |
| 825 | return Objects.equals(src, that.src) && |
| 826 | Objects.equals(dst, that.dst); |
| 827 | } |
| 828 | |
| 829 | @Override |
| 830 | public int hashCode() { |
| 831 | return Objects.hash(src, dst); |
| 832 | } |
| 833 | } |
alshabib | 030111e | 2014-09-15 15:56:42 -0700 | [diff] [blame] | 834 | } |