sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Laboratory |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | package org.onosproject.segmentrouting; |
| 17 | |
| 18 | import org.onlab.packet.ARP; |
| 19 | import org.onlab.packet.Ethernet; |
| 20 | import org.onlab.packet.Ip4Address; |
| 21 | import org.onlab.packet.IpAddress; |
Pier Ventre | 10bd8d1 | 2016-11-26 21:05:22 -0800 | [diff] [blame^] | 22 | import org.onlab.packet.IpPrefix; |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 23 | import org.onlab.packet.MacAddress; |
Charles Chan | 68aa62d | 2015-11-09 16:37:23 -0800 | [diff] [blame] | 24 | import org.onlab.packet.VlanId; |
Pier Ventre | 10bd8d1 | 2016-11-26 21:05:22 -0800 | [diff] [blame^] | 25 | import org.onosproject.incubator.net.neighbour.NeighbourMessageContext; |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 26 | import org.onosproject.net.ConnectPoint; |
| 27 | import org.onosproject.net.DeviceId; |
| 28 | import org.onosproject.net.Host; |
Pier Ventre | 10bd8d1 | 2016-11-26 21:05:22 -0800 | [diff] [blame^] | 29 | import org.onosproject.net.HostId; |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 30 | import org.onosproject.net.flow.DefaultTrafficTreatment; |
| 31 | import org.onosproject.net.flow.TrafficTreatment; |
Pier Ventre | 10bd8d1 | 2016-11-26 21:05:22 -0800 | [diff] [blame^] | 32 | import org.onosproject.net.host.HostService; |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 33 | import org.onosproject.net.packet.DefaultOutboundPacket; |
Charles Chan | 0b4e618 | 2015-11-03 10:42:14 -0800 | [diff] [blame] | 34 | import org.onosproject.segmentrouting.config.DeviceConfigNotFoundException; |
| 35 | import org.onosproject.segmentrouting.config.DeviceConfiguration; |
Charles Chan | 03a73e0 | 2016-10-24 14:52:01 -0700 | [diff] [blame] | 36 | import org.onosproject.segmentrouting.config.SegmentRoutingAppConfig; |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 37 | import org.slf4j.Logger; |
| 38 | import org.slf4j.LoggerFactory; |
| 39 | |
| 40 | import java.nio.ByteBuffer; |
Saurav Das | 837e0bb | 2015-10-30 17:45:38 -0700 | [diff] [blame] | 41 | import java.util.Set; |
Pier Ventre | 10bd8d1 | 2016-11-26 21:05:22 -0800 | [diff] [blame^] | 42 | import java.util.stream.Collectors; |
Saurav Das | 837e0bb | 2015-10-30 17:45:38 -0700 | [diff] [blame] | 43 | |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 44 | import static com.google.common.base.Preconditions.checkNotNull; |
Pier Ventre | 10bd8d1 | 2016-11-26 21:05:22 -0800 | [diff] [blame^] | 45 | import static org.onosproject.incubator.net.neighbour.NeighbourMessageType.REQUEST; |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 46 | |
Charles Chan | e849c19 | 2016-01-11 18:28:54 -0800 | [diff] [blame] | 47 | /** |
| 48 | * Handler of ARP packets that responses or forwards ARP packets that |
| 49 | * are sent to the controller. |
| 50 | */ |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 51 | public class ArpHandler { |
| 52 | |
| 53 | private static Logger log = LoggerFactory.getLogger(ArpHandler.class); |
| 54 | |
| 55 | private SegmentRoutingManager srManager; |
sangho | 666cd6d | 2015-04-14 16:27:13 -0700 | [diff] [blame] | 56 | private DeviceConfiguration config; |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 57 | |
| 58 | /** |
| 59 | * Creates an ArpHandler object. |
| 60 | * |
| 61 | * @param srManager SegmentRoutingManager object |
| 62 | */ |
| 63 | public ArpHandler(SegmentRoutingManager srManager) { |
| 64 | this.srManager = srManager; |
sangho | 666cd6d | 2015-04-14 16:27:13 -0700 | [diff] [blame] | 65 | this.config = checkNotNull(srManager.deviceConfiguration); |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | /** |
| 69 | * Processes incoming ARP packets. |
Charles Chan | 68aa62d | 2015-11-09 16:37:23 -0800 | [diff] [blame] | 70 | * |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 71 | * If it is an ARP request to router itself or known hosts, |
| 72 | * then it sends ARP response. |
| 73 | * If it is an ARP request to unknown hosts in its own subnet, |
| 74 | * then it flood the ARP request to the ports. |
| 75 | * If it is an ARP response, then set a flow rule for the host |
| 76 | * and forward any IP packets to the host in the packet buffer to the host. |
Charles Chan | 68aa62d | 2015-11-09 16:37:23 -0800 | [diff] [blame] | 77 | * <p> |
| 78 | * Note: We handles all ARP packet in, even for those ARP packets between |
| 79 | * hosts in the same subnet. |
| 80 | * For an ARP packet with broadcast destination MAC, |
| 81 | * some switches pipelines will send it to the controller due to table miss, |
Saurav Das | 4983164 | 2016-02-05 13:15:20 -0800 | [diff] [blame] | 82 | * other switches will flood the packets directly in the data plane without |
Charles Chan | 68aa62d | 2015-11-09 16:37:23 -0800 | [diff] [blame] | 83 | * packet in. |
| 84 | * We can deal with both cases. |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 85 | * |
Pier Ventre | 10bd8d1 | 2016-11-26 21:05:22 -0800 | [diff] [blame^] | 86 | * @param pkt incoming ARP packet and context information |
| 87 | * @param hostService the host service |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 88 | */ |
Pier Ventre | 10bd8d1 | 2016-11-26 21:05:22 -0800 | [diff] [blame^] | 89 | public void processPacketIn(NeighbourMessageContext pkt, HostService hostService) { |
Charles Chan | d2edd47 | 2016-10-17 18:03:37 -0700 | [diff] [blame] | 90 | |
Charles Chan | 03a73e0 | 2016-10-24 14:52:01 -0700 | [diff] [blame] | 91 | SegmentRoutingAppConfig appConfig = srManager.cfgService |
| 92 | .getConfig(srManager.appId, SegmentRoutingAppConfig.class); |
Pier Ventre | 10bd8d1 | 2016-11-26 21:05:22 -0800 | [diff] [blame^] | 93 | if (appConfig != null && appConfig.suppressSubnet().contains(pkt.inPort())) { |
Charles Chan | 03a73e0 | 2016-10-24 14:52:01 -0700 | [diff] [blame] | 94 | // Ignore ARP packets come from suppressed ports |
| 95 | return; |
| 96 | } |
| 97 | |
Pier Ventre | 10bd8d1 | 2016-11-26 21:05:22 -0800 | [diff] [blame^] | 98 | if (!validateArpSpa(pkt)) { |
Charles Chan | 505dfd8 | 2016-11-08 16:32:13 -0800 | [diff] [blame] | 99 | log.debug("Ignore ARP packet discovered on {} with unexpected src protocol address {}.", |
Pier Ventre | 10bd8d1 | 2016-11-26 21:05:22 -0800 | [diff] [blame^] | 100 | pkt.inPort(), pkt.sender().getIp4Address()); |
Charles Chan | d2edd47 | 2016-10-17 18:03:37 -0700 | [diff] [blame] | 101 | return; |
| 102 | } |
| 103 | |
Pier Ventre | 10bd8d1 | 2016-11-26 21:05:22 -0800 | [diff] [blame^] | 104 | if (pkt.type() == REQUEST) { |
| 105 | handleArpRequest(pkt, hostService); |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 106 | } else { |
Pier Ventre | 10bd8d1 | 2016-11-26 21:05:22 -0800 | [diff] [blame^] | 107 | handleArpReply(pkt, hostService); |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 108 | } |
| 109 | } |
| 110 | |
Pier Ventre | 10bd8d1 | 2016-11-26 21:05:22 -0800 | [diff] [blame^] | 111 | private void handleArpRequest(NeighbourMessageContext pkt, HostService hostService) { |
Charles Chan | 68aa62d | 2015-11-09 16:37:23 -0800 | [diff] [blame] | 112 | // ARP request for router. Send ARP reply. |
Pier Ventre | 10bd8d1 | 2016-11-26 21:05:22 -0800 | [diff] [blame^] | 113 | if (isArpForRouter(pkt)) { |
| 114 | MacAddress targetMac = config.getRouterMacForAGatewayIp(pkt.target().getIp4Address()); |
| 115 | sendArpResponse(pkt, targetMac, hostService); |
Charles Chan | eb088e6 | 2015-10-15 10:48:13 -0700 | [diff] [blame] | 116 | } else { |
Pier Ventre | 10bd8d1 | 2016-11-26 21:05:22 -0800 | [diff] [blame^] | 117 | Set<Host> hosts = hostService.getHostsByIp(pkt.target()); |
| 118 | if (hosts.size() > 1) { |
| 119 | log.warn("More than one host with the same ip {}", pkt.target()); |
| 120 | } |
| 121 | Host targetHost = hosts.stream().findFirst().orElse(null); |
Charles Chan | 68aa62d | 2015-11-09 16:37:23 -0800 | [diff] [blame] | 122 | // ARP request for known hosts. Send proxy ARP reply on behalf of the target. |
Charles Chan | eb088e6 | 2015-10-15 10:48:13 -0700 | [diff] [blame] | 123 | if (targetHost != null) { |
Pier Ventre | 10bd8d1 | 2016-11-26 21:05:22 -0800 | [diff] [blame^] | 124 | pkt.forward(targetHost.location()); |
Charles Chan | 68aa62d | 2015-11-09 16:37:23 -0800 | [diff] [blame] | 125 | // ARP request for unknown host in the subnet. Flood in the subnet. |
| 126 | } else { |
Pier Ventre | 10bd8d1 | 2016-11-26 21:05:22 -0800 | [diff] [blame^] | 127 | flood(pkt); |
Charles Chan | 68aa62d | 2015-11-09 16:37:23 -0800 | [diff] [blame] | 128 | } |
| 129 | } |
| 130 | } |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 131 | |
Pier Ventre | 10bd8d1 | 2016-11-26 21:05:22 -0800 | [diff] [blame^] | 132 | private void handleArpReply(NeighbourMessageContext pkt, HostService hostService) { |
Charles Chan | 68aa62d | 2015-11-09 16:37:23 -0800 | [diff] [blame] | 133 | // ARP reply for router. Process all pending IP packets. |
Pier Ventre | 10bd8d1 | 2016-11-26 21:05:22 -0800 | [diff] [blame^] | 134 | if (isArpForRouter(pkt)) { |
| 135 | Ip4Address hostIpAddress = pkt.sender().getIp4Address(); |
| 136 | srManager.ipHandler.forwardPackets(pkt.inPort().deviceId(), hostIpAddress); |
Charles Chan | 68aa62d | 2015-11-09 16:37:23 -0800 | [diff] [blame] | 137 | } else { |
Pier Ventre | 10bd8d1 | 2016-11-26 21:05:22 -0800 | [diff] [blame^] | 138 | HostId targetHostId = HostId.hostId(pkt.dstMac(), pkt.vlan()); |
| 139 | Host targetHost = hostService.getHost(targetHostId); |
Charles Chan | 68aa62d | 2015-11-09 16:37:23 -0800 | [diff] [blame] | 140 | // ARP reply for known hosts. Forward to the host. |
| 141 | if (targetHost != null) { |
Pier Ventre | 10bd8d1 | 2016-11-26 21:05:22 -0800 | [diff] [blame^] | 142 | pkt.forward(targetHost.location()); |
Charles Chan | 68aa62d | 2015-11-09 16:37:23 -0800 | [diff] [blame] | 143 | // ARP reply for unknown host, Flood in the subnet. |
| 144 | } else { |
| 145 | // Don't flood to non-edge ports |
Pier Ventre | 10bd8d1 | 2016-11-26 21:05:22 -0800 | [diff] [blame^] | 146 | if (pkt.vlan().equals( |
Saurav Das | 4ce4596 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 147 | VlanId.vlanId(SegmentRoutingManager.ASSIGNED_VLAN_NO_SUBNET))) { |
Charles Chan | 68aa62d | 2015-11-09 16:37:23 -0800 | [diff] [blame] | 148 | return; |
| 149 | } |
Pier Ventre | 10bd8d1 | 2016-11-26 21:05:22 -0800 | [diff] [blame^] | 150 | flood(pkt); |
Charles Chan | eb088e6 | 2015-10-15 10:48:13 -0700 | [diff] [blame] | 151 | } |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 152 | } |
| 153 | } |
| 154 | |
Charles Chan | d2edd47 | 2016-10-17 18:03:37 -0700 | [diff] [blame] | 155 | /** |
| 156 | * Check if the source protocol address of an ARP packet belongs to the same |
| 157 | * subnet configured on the port it is seen. |
| 158 | * |
Pier Ventre | 10bd8d1 | 2016-11-26 21:05:22 -0800 | [diff] [blame^] | 159 | * @param pkt ARP packet and context information |
Charles Chan | d2edd47 | 2016-10-17 18:03:37 -0700 | [diff] [blame] | 160 | * @return true if the source protocol address belongs to the configured subnet |
| 161 | */ |
Pier Ventre | 10bd8d1 | 2016-11-26 21:05:22 -0800 | [diff] [blame^] | 162 | private boolean validateArpSpa(NeighbourMessageContext pkt) { |
| 163 | Ip4Address spa = pkt.sender().getIp4Address(); |
| 164 | Set<IpPrefix> subnet = config.getPortSubnets(pkt.inPort().deviceId(), pkt.inPort().port()) |
| 165 | .stream() |
| 166 | .filter(ipPrefix -> ipPrefix.isIp4() && ipPrefix.contains(spa)) |
| 167 | .collect(Collectors.toSet()); |
| 168 | return !subnet.isEmpty(); |
Charles Chan | d2edd47 | 2016-10-17 18:03:37 -0700 | [diff] [blame] | 169 | } |
| 170 | |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 171 | |
Pier Ventre | 10bd8d1 | 2016-11-26 21:05:22 -0800 | [diff] [blame^] | 172 | private boolean isArpForRouter(NeighbourMessageContext pkt) { |
| 173 | Ip4Address targetProtocolAddress = pkt.target().getIp4Address(); |
| 174 | Set<IpAddress> gatewayIpAddresses = null; |
Saurav Das | 4ce4596 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 175 | try { |
Pier Ventre | 10bd8d1 | 2016-11-26 21:05:22 -0800 | [diff] [blame^] | 176 | if (targetProtocolAddress.equals(config.getRouterIpv4(pkt.inPort().deviceId()))) { |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 177 | return true; |
| 178 | } |
Pier Ventre | 10bd8d1 | 2016-11-26 21:05:22 -0800 | [diff] [blame^] | 179 | gatewayIpAddresses = config.getPortIPs(pkt.inPort().deviceId()); |
Saurav Das | 4ce4596 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 180 | } catch (DeviceConfigNotFoundException e) { |
| 181 | log.warn(e.getMessage() + " Aborting check for router IP in processing arp"); |
| 182 | } |
| 183 | if (gatewayIpAddresses != null && |
| 184 | gatewayIpAddresses.contains(targetProtocolAddress)) { |
| 185 | return true; |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 186 | } |
| 187 | return false; |
| 188 | } |
| 189 | |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 190 | /** |
| 191 | * Sends an APR request for the target IP address to all ports except in-port. |
| 192 | * |
| 193 | * @param deviceId Switch device ID |
| 194 | * @param targetAddress target IP address for ARP |
| 195 | * @param inPort in-port |
| 196 | */ |
| 197 | public void sendArpRequest(DeviceId deviceId, IpAddress targetAddress, ConnectPoint inPort) { |
Charles Chan | 0b4e618 | 2015-11-03 10:42:14 -0800 | [diff] [blame] | 198 | byte[] senderMacAddress; |
| 199 | byte[] senderIpAddress; |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 200 | |
Charles Chan | 0b4e618 | 2015-11-03 10:42:14 -0800 | [diff] [blame] | 201 | try { |
| 202 | senderMacAddress = config.getDeviceMac(deviceId).toBytes(); |
Pier Ventre | 10bd8d1 | 2016-11-26 21:05:22 -0800 | [diff] [blame^] | 203 | senderIpAddress = config.getRouterIpAddressForASubnetHost(targetAddress.getIp4Address()) |
| 204 | .toOctets(); |
Charles Chan | 0b4e618 | 2015-11-03 10:42:14 -0800 | [diff] [blame] | 205 | } catch (DeviceConfigNotFoundException e) { |
| 206 | log.warn(e.getMessage() + " Aborting sendArpRequest."); |
| 207 | return; |
| 208 | } |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 209 | |
| 210 | ARP arpRequest = new ARP(); |
| 211 | arpRequest.setHardwareType(ARP.HW_TYPE_ETHERNET) |
| 212 | .setProtocolType(ARP.PROTO_TYPE_IP) |
| 213 | .setHardwareAddressLength( |
| 214 | (byte) Ethernet.DATALAYER_ADDRESS_LENGTH) |
| 215 | .setProtocolAddressLength((byte) Ip4Address.BYTE_LENGTH) |
| 216 | .setOpCode(ARP.OP_REQUEST) |
| 217 | .setSenderHardwareAddress(senderMacAddress) |
| 218 | .setTargetHardwareAddress(MacAddress.ZERO.toBytes()) |
| 219 | .setSenderProtocolAddress(senderIpAddress) |
| 220 | .setTargetProtocolAddress(targetAddress.toOctets()); |
| 221 | |
| 222 | Ethernet eth = new Ethernet(); |
| 223 | eth.setDestinationMACAddress(MacAddress.BROADCAST.toBytes()) |
| 224 | .setSourceMACAddress(senderMacAddress) |
| 225 | .setEtherType(Ethernet.TYPE_ARP).setPayload(arpRequest); |
| 226 | |
Pier Ventre | 10bd8d1 | 2016-11-26 21:05:22 -0800 | [diff] [blame^] | 227 | flood(eth, inPort); |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 228 | } |
| 229 | |
Pier Ventre | 10bd8d1 | 2016-11-26 21:05:22 -0800 | [diff] [blame^] | 230 | private void sendArpResponse(NeighbourMessageContext pkt, MacAddress targetMac, HostService hostService) { |
| 231 | HostId dstId = HostId.hostId(pkt.srcMac(), pkt.vlan()); |
| 232 | Host dst = hostService.getHost(dstId); |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 233 | if (dst == null) { |
Pier Ventre | 10bd8d1 | 2016-11-26 21:05:22 -0800 | [diff] [blame^] | 234 | log.warn("Cannot send ARP response to host {} - does not exist in the store", |
| 235 | dstId); |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 236 | return; |
| 237 | } |
Pier Ventre | 10bd8d1 | 2016-11-26 21:05:22 -0800 | [diff] [blame^] | 238 | pkt.reply(targetMac); |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 239 | } |
| 240 | |
Charles Chan | 68aa62d | 2015-11-09 16:37:23 -0800 | [diff] [blame] | 241 | /** |
| 242 | * Remove VLAN tag and flood to all ports in the same subnet. |
| 243 | * |
| 244 | * @param packet packet to be flooded |
| 245 | * @param inPort where the packet comes from |
| 246 | */ |
Pier Ventre | 10bd8d1 | 2016-11-26 21:05:22 -0800 | [diff] [blame^] | 247 | private void flood(Ethernet packet, ConnectPoint inPort) { |
Charles Chan | 68aa62d | 2015-11-09 16:37:23 -0800 | [diff] [blame] | 248 | Ip4Address targetProtocolAddress = Ip4Address.valueOf( |
| 249 | ((ARP) packet.getPayload()).getTargetProtocolAddress() |
| 250 | ); |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 251 | |
Saurav Das | 7a1ffca | 2016-03-28 19:00:18 -0700 | [diff] [blame] | 252 | try { |
| 253 | srManager.deviceConfiguration |
Pier Ventre | 10bd8d1 | 2016-11-26 21:05:22 -0800 | [diff] [blame^] | 254 | .getSubnetPortsMap(inPort.deviceId()).forEach((subnet, ports) -> { |
| 255 | if (subnet.contains(targetProtocolAddress)) { |
| 256 | ports.stream() |
| 257 | .filter(port -> port != inPort.port()) |
| 258 | .forEach(port -> { |
| 259 | forward(packet, new ConnectPoint(inPort.deviceId(), port)); |
| 260 | }); |
| 261 | } |
| 262 | }); |
| 263 | } catch (DeviceConfigNotFoundException e) { |
| 264 | log.warn(e.getMessage() |
| 265 | + " Cannot flood in subnet as device config not available" |
| 266 | + " for device: " + inPort.deviceId()); |
| 267 | } |
| 268 | } |
| 269 | |
| 270 | /** |
| 271 | * Remove VLAN tag and flood to all ports in the same subnet. |
| 272 | * |
| 273 | * @param pkt arp packet to be flooded |
| 274 | */ |
| 275 | private void flood(NeighbourMessageContext pkt) { |
| 276 | try { |
| 277 | srManager.deviceConfiguration |
| 278 | .getSubnetPortsMap(pkt.inPort().deviceId()).forEach((subnet, ports) -> { |
| 279 | if (subnet.contains(pkt.target())) { |
Saurav Das | 7a1ffca | 2016-03-28 19:00:18 -0700 | [diff] [blame] | 280 | ports.stream() |
Pier Ventre | 10bd8d1 | 2016-11-26 21:05:22 -0800 | [diff] [blame^] | 281 | .filter(port -> port != pkt.inPort().port()) |
Saurav Das | 7a1ffca | 2016-03-28 19:00:18 -0700 | [diff] [blame] | 282 | .forEach(port -> { |
Pier Ventre | 10bd8d1 | 2016-11-26 21:05:22 -0800 | [diff] [blame^] | 283 | ConnectPoint outPoint = new ConnectPoint( |
| 284 | pkt.inPort().deviceId(), |
| 285 | port |
| 286 | ); |
| 287 | pkt.forward(outPoint); |
Saurav Das | 7a1ffca | 2016-03-28 19:00:18 -0700 | [diff] [blame] | 288 | }); |
| 289 | } |
| 290 | }); |
| 291 | } catch (DeviceConfigNotFoundException e) { |
| 292 | log.warn(e.getMessage() |
| 293 | + " Cannot flood in subnet as device config not available" |
Pier Ventre | 10bd8d1 | 2016-11-26 21:05:22 -0800 | [diff] [blame^] | 294 | + " for device: " + pkt.inPort().deviceId()); |
Saurav Das | 7a1ffca | 2016-03-28 19:00:18 -0700 | [diff] [blame] | 295 | } |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 296 | } |
| 297 | |
Charles Chan | 68aa62d | 2015-11-09 16:37:23 -0800 | [diff] [blame] | 298 | /** |
| 299 | * Remove VLAN tag and packet out to given port. |
| 300 | * |
| 301 | * Note: In current implementation, we expect all communication with |
| 302 | * end hosts within a subnet to be untagged. |
| 303 | * <p> |
| 304 | * For those pipelines that internally assigns a VLAN, the VLAN tag will be |
| 305 | * removed before egress. |
| 306 | * <p> |
| 307 | * For those pipelines that do not assign internal VLAN, the packet remains |
| 308 | * untagged. |
| 309 | * |
| 310 | * @param packet packet to be forwarded |
| 311 | * @param outPort where the packet should be forwarded |
| 312 | */ |
Pier Ventre | 10bd8d1 | 2016-11-26 21:05:22 -0800 | [diff] [blame^] | 313 | private void forward(Ethernet packet, ConnectPoint outPort) { |
Charles Chan | 68aa62d | 2015-11-09 16:37:23 -0800 | [diff] [blame] | 314 | packet.setEtherType(Ethernet.TYPE_ARP); |
Pier Ventre | 10bd8d1 | 2016-11-26 21:05:22 -0800 | [diff] [blame^] | 315 | |
Charles Chan | 68aa62d | 2015-11-09 16:37:23 -0800 | [diff] [blame] | 316 | ByteBuffer buf = ByteBuffer.wrap(packet.serialize()); |
| 317 | |
| 318 | TrafficTreatment.Builder tbuilder = DefaultTrafficTreatment.builder(); |
| 319 | tbuilder.setOutput(outPort.port()); |
| 320 | srManager.packetService.emit(new DefaultOutboundPacket(outPort.deviceId(), |
| 321 | tbuilder.build(), buf)); |
| 322 | } |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 323 | } |