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 |
Pier Ventre | f4b5fce | 2016-11-28 16:48:06 -0800 | [diff] [blame^] | 95 | pkt.drop(); |
Charles Chan | 03a73e0 | 2016-10-24 14:52:01 -0700 | [diff] [blame] | 96 | return; |
| 97 | } |
| 98 | |
Pier Ventre | 10bd8d1 | 2016-11-26 21:05:22 -0800 | [diff] [blame] | 99 | if (!validateArpSpa(pkt)) { |
Charles Chan | 505dfd8 | 2016-11-08 16:32:13 -0800 | [diff] [blame] | 100 | log.debug("Ignore ARP packet discovered on {} with unexpected src protocol address {}.", |
Pier Ventre | 10bd8d1 | 2016-11-26 21:05:22 -0800 | [diff] [blame] | 101 | pkt.inPort(), pkt.sender().getIp4Address()); |
Pier Ventre | f4b5fce | 2016-11-28 16:48:06 -0800 | [diff] [blame^] | 102 | pkt.drop(); |
Charles Chan | d2edd47 | 2016-10-17 18:03:37 -0700 | [diff] [blame] | 103 | return; |
| 104 | } |
| 105 | |
Pier Ventre | 10bd8d1 | 2016-11-26 21:05:22 -0800 | [diff] [blame] | 106 | if (pkt.type() == REQUEST) { |
| 107 | handleArpRequest(pkt, hostService); |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 108 | } else { |
Pier Ventre | 10bd8d1 | 2016-11-26 21:05:22 -0800 | [diff] [blame] | 109 | handleArpReply(pkt, hostService); |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 110 | } |
| 111 | } |
| 112 | |
Pier Ventre | 10bd8d1 | 2016-11-26 21:05:22 -0800 | [diff] [blame] | 113 | private void handleArpRequest(NeighbourMessageContext pkt, HostService hostService) { |
Charles Chan | 68aa62d | 2015-11-09 16:37:23 -0800 | [diff] [blame] | 114 | // ARP request for router. Send ARP reply. |
Pier Ventre | 10bd8d1 | 2016-11-26 21:05:22 -0800 | [diff] [blame] | 115 | if (isArpForRouter(pkt)) { |
| 116 | MacAddress targetMac = config.getRouterMacForAGatewayIp(pkt.target().getIp4Address()); |
| 117 | sendArpResponse(pkt, targetMac, hostService); |
Charles Chan | eb088e6 | 2015-10-15 10:48:13 -0700 | [diff] [blame] | 118 | } else { |
Pier Ventre | 10bd8d1 | 2016-11-26 21:05:22 -0800 | [diff] [blame] | 119 | Set<Host> hosts = hostService.getHostsByIp(pkt.target()); |
| 120 | if (hosts.size() > 1) { |
| 121 | log.warn("More than one host with the same ip {}", pkt.target()); |
| 122 | } |
| 123 | Host targetHost = hosts.stream().findFirst().orElse(null); |
Charles Chan | 68aa62d | 2015-11-09 16:37:23 -0800 | [diff] [blame] | 124 | // 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] | 125 | if (targetHost != null) { |
Pier Ventre | 10bd8d1 | 2016-11-26 21:05:22 -0800 | [diff] [blame] | 126 | pkt.forward(targetHost.location()); |
Charles Chan | 68aa62d | 2015-11-09 16:37:23 -0800 | [diff] [blame] | 127 | // ARP request for unknown host in the subnet. Flood in the subnet. |
| 128 | } else { |
Pier Ventre | 10bd8d1 | 2016-11-26 21:05:22 -0800 | [diff] [blame] | 129 | flood(pkt); |
Charles Chan | 68aa62d | 2015-11-09 16:37:23 -0800 | [diff] [blame] | 130 | } |
| 131 | } |
| 132 | } |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 133 | |
Pier Ventre | 10bd8d1 | 2016-11-26 21:05:22 -0800 | [diff] [blame] | 134 | private void handleArpReply(NeighbourMessageContext pkt, HostService hostService) { |
Charles Chan | 68aa62d | 2015-11-09 16:37:23 -0800 | [diff] [blame] | 135 | // ARP reply for router. Process all pending IP packets. |
Pier Ventre | 10bd8d1 | 2016-11-26 21:05:22 -0800 | [diff] [blame] | 136 | if (isArpForRouter(pkt)) { |
| 137 | Ip4Address hostIpAddress = pkt.sender().getIp4Address(); |
| 138 | srManager.ipHandler.forwardPackets(pkt.inPort().deviceId(), hostIpAddress); |
Charles Chan | 68aa62d | 2015-11-09 16:37:23 -0800 | [diff] [blame] | 139 | } else { |
Pier Ventre | 10bd8d1 | 2016-11-26 21:05:22 -0800 | [diff] [blame] | 140 | HostId targetHostId = HostId.hostId(pkt.dstMac(), pkt.vlan()); |
| 141 | Host targetHost = hostService.getHost(targetHostId); |
Charles Chan | 68aa62d | 2015-11-09 16:37:23 -0800 | [diff] [blame] | 142 | // ARP reply for known hosts. Forward to the host. |
| 143 | if (targetHost != null) { |
Pier Ventre | 10bd8d1 | 2016-11-26 21:05:22 -0800 | [diff] [blame] | 144 | pkt.forward(targetHost.location()); |
Charles Chan | 68aa62d | 2015-11-09 16:37:23 -0800 | [diff] [blame] | 145 | // ARP reply for unknown host, Flood in the subnet. |
| 146 | } else { |
| 147 | // Don't flood to non-edge ports |
Pier Ventre | 10bd8d1 | 2016-11-26 21:05:22 -0800 | [diff] [blame] | 148 | if (pkt.vlan().equals( |
Saurav Das | 4ce4596 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 149 | VlanId.vlanId(SegmentRoutingManager.ASSIGNED_VLAN_NO_SUBNET))) { |
Charles Chan | 68aa62d | 2015-11-09 16:37:23 -0800 | [diff] [blame] | 150 | return; |
| 151 | } |
Pier Ventre | 10bd8d1 | 2016-11-26 21:05:22 -0800 | [diff] [blame] | 152 | flood(pkt); |
Charles Chan | eb088e6 | 2015-10-15 10:48:13 -0700 | [diff] [blame] | 153 | } |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 154 | } |
| 155 | } |
| 156 | |
Charles Chan | d2edd47 | 2016-10-17 18:03:37 -0700 | [diff] [blame] | 157 | /** |
| 158 | * Check if the source protocol address of an ARP packet belongs to the same |
| 159 | * subnet configured on the port it is seen. |
| 160 | * |
Pier Ventre | 10bd8d1 | 2016-11-26 21:05:22 -0800 | [diff] [blame] | 161 | * @param pkt ARP packet and context information |
Charles Chan | d2edd47 | 2016-10-17 18:03:37 -0700 | [diff] [blame] | 162 | * @return true if the source protocol address belongs to the configured subnet |
| 163 | */ |
Pier Ventre | 10bd8d1 | 2016-11-26 21:05:22 -0800 | [diff] [blame] | 164 | private boolean validateArpSpa(NeighbourMessageContext pkt) { |
| 165 | Ip4Address spa = pkt.sender().getIp4Address(); |
| 166 | Set<IpPrefix> subnet = config.getPortSubnets(pkt.inPort().deviceId(), pkt.inPort().port()) |
| 167 | .stream() |
| 168 | .filter(ipPrefix -> ipPrefix.isIp4() && ipPrefix.contains(spa)) |
| 169 | .collect(Collectors.toSet()); |
| 170 | return !subnet.isEmpty(); |
Charles Chan | d2edd47 | 2016-10-17 18:03:37 -0700 | [diff] [blame] | 171 | } |
| 172 | |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 173 | |
Pier Ventre | 10bd8d1 | 2016-11-26 21:05:22 -0800 | [diff] [blame] | 174 | private boolean isArpForRouter(NeighbourMessageContext pkt) { |
| 175 | Ip4Address targetProtocolAddress = pkt.target().getIp4Address(); |
| 176 | Set<IpAddress> gatewayIpAddresses = null; |
Saurav Das | 4ce4596 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 177 | try { |
Pier Ventre | 10bd8d1 | 2016-11-26 21:05:22 -0800 | [diff] [blame] | 178 | if (targetProtocolAddress.equals(config.getRouterIpv4(pkt.inPort().deviceId()))) { |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 179 | return true; |
| 180 | } |
Pier Ventre | 10bd8d1 | 2016-11-26 21:05:22 -0800 | [diff] [blame] | 181 | gatewayIpAddresses = config.getPortIPs(pkt.inPort().deviceId()); |
Saurav Das | 4ce4596 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 182 | } catch (DeviceConfigNotFoundException e) { |
| 183 | log.warn(e.getMessage() + " Aborting check for router IP in processing arp"); |
| 184 | } |
| 185 | if (gatewayIpAddresses != null && |
| 186 | gatewayIpAddresses.contains(targetProtocolAddress)) { |
| 187 | return true; |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 188 | } |
| 189 | return false; |
| 190 | } |
| 191 | |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 192 | /** |
| 193 | * Sends an APR request for the target IP address to all ports except in-port. |
| 194 | * |
| 195 | * @param deviceId Switch device ID |
| 196 | * @param targetAddress target IP address for ARP |
| 197 | * @param inPort in-port |
| 198 | */ |
| 199 | public void sendArpRequest(DeviceId deviceId, IpAddress targetAddress, ConnectPoint inPort) { |
Charles Chan | 0b4e618 | 2015-11-03 10:42:14 -0800 | [diff] [blame] | 200 | byte[] senderMacAddress; |
| 201 | byte[] senderIpAddress; |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 202 | |
Charles Chan | 0b4e618 | 2015-11-03 10:42:14 -0800 | [diff] [blame] | 203 | try { |
| 204 | senderMacAddress = config.getDeviceMac(deviceId).toBytes(); |
Pier Ventre | 10bd8d1 | 2016-11-26 21:05:22 -0800 | [diff] [blame] | 205 | senderIpAddress = config.getRouterIpAddressForASubnetHost(targetAddress.getIp4Address()) |
| 206 | .toOctets(); |
Charles Chan | 0b4e618 | 2015-11-03 10:42:14 -0800 | [diff] [blame] | 207 | } catch (DeviceConfigNotFoundException e) { |
| 208 | log.warn(e.getMessage() + " Aborting sendArpRequest."); |
| 209 | return; |
| 210 | } |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 211 | |
| 212 | ARP arpRequest = new ARP(); |
| 213 | arpRequest.setHardwareType(ARP.HW_TYPE_ETHERNET) |
| 214 | .setProtocolType(ARP.PROTO_TYPE_IP) |
| 215 | .setHardwareAddressLength( |
| 216 | (byte) Ethernet.DATALAYER_ADDRESS_LENGTH) |
| 217 | .setProtocolAddressLength((byte) Ip4Address.BYTE_LENGTH) |
| 218 | .setOpCode(ARP.OP_REQUEST) |
| 219 | .setSenderHardwareAddress(senderMacAddress) |
| 220 | .setTargetHardwareAddress(MacAddress.ZERO.toBytes()) |
| 221 | .setSenderProtocolAddress(senderIpAddress) |
| 222 | .setTargetProtocolAddress(targetAddress.toOctets()); |
| 223 | |
| 224 | Ethernet eth = new Ethernet(); |
| 225 | eth.setDestinationMACAddress(MacAddress.BROADCAST.toBytes()) |
| 226 | .setSourceMACAddress(senderMacAddress) |
| 227 | .setEtherType(Ethernet.TYPE_ARP).setPayload(arpRequest); |
| 228 | |
Pier Ventre | 10bd8d1 | 2016-11-26 21:05:22 -0800 | [diff] [blame] | 229 | flood(eth, inPort); |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 230 | } |
| 231 | |
Pier Ventre | 10bd8d1 | 2016-11-26 21:05:22 -0800 | [diff] [blame] | 232 | private void sendArpResponse(NeighbourMessageContext pkt, MacAddress targetMac, HostService hostService) { |
| 233 | HostId dstId = HostId.hostId(pkt.srcMac(), pkt.vlan()); |
| 234 | Host dst = hostService.getHost(dstId); |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 235 | if (dst == null) { |
Pier Ventre | 10bd8d1 | 2016-11-26 21:05:22 -0800 | [diff] [blame] | 236 | log.warn("Cannot send ARP response to host {} - does not exist in the store", |
| 237 | dstId); |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 238 | return; |
| 239 | } |
Pier Ventre | 10bd8d1 | 2016-11-26 21:05:22 -0800 | [diff] [blame] | 240 | pkt.reply(targetMac); |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 241 | } |
| 242 | |
Charles Chan | 68aa62d | 2015-11-09 16:37:23 -0800 | [diff] [blame] | 243 | /** |
| 244 | * Remove VLAN tag and flood to all ports in the same subnet. |
| 245 | * |
| 246 | * @param packet packet to be flooded |
| 247 | * @param inPort where the packet comes from |
| 248 | */ |
Pier Ventre | 10bd8d1 | 2016-11-26 21:05:22 -0800 | [diff] [blame] | 249 | private void flood(Ethernet packet, ConnectPoint inPort) { |
Charles Chan | 68aa62d | 2015-11-09 16:37:23 -0800 | [diff] [blame] | 250 | Ip4Address targetProtocolAddress = Ip4Address.valueOf( |
| 251 | ((ARP) packet.getPayload()).getTargetProtocolAddress() |
| 252 | ); |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 253 | |
Saurav Das | 7a1ffca | 2016-03-28 19:00:18 -0700 | [diff] [blame] | 254 | try { |
| 255 | srManager.deviceConfiguration |
Pier Ventre | 10bd8d1 | 2016-11-26 21:05:22 -0800 | [diff] [blame] | 256 | .getSubnetPortsMap(inPort.deviceId()).forEach((subnet, ports) -> { |
| 257 | if (subnet.contains(targetProtocolAddress)) { |
| 258 | ports.stream() |
| 259 | .filter(port -> port != inPort.port()) |
| 260 | .forEach(port -> { |
| 261 | forward(packet, new ConnectPoint(inPort.deviceId(), port)); |
| 262 | }); |
| 263 | } |
| 264 | }); |
| 265 | } catch (DeviceConfigNotFoundException e) { |
| 266 | log.warn(e.getMessage() |
| 267 | + " Cannot flood in subnet as device config not available" |
| 268 | + " for device: " + inPort.deviceId()); |
| 269 | } |
| 270 | } |
| 271 | |
| 272 | /** |
| 273 | * Remove VLAN tag and flood to all ports in the same subnet. |
| 274 | * |
| 275 | * @param pkt arp packet to be flooded |
| 276 | */ |
| 277 | private void flood(NeighbourMessageContext pkt) { |
| 278 | try { |
| 279 | srManager.deviceConfiguration |
| 280 | .getSubnetPortsMap(pkt.inPort().deviceId()).forEach((subnet, ports) -> { |
| 281 | if (subnet.contains(pkt.target())) { |
Saurav Das | 7a1ffca | 2016-03-28 19:00:18 -0700 | [diff] [blame] | 282 | ports.stream() |
Pier Ventre | 10bd8d1 | 2016-11-26 21:05:22 -0800 | [diff] [blame] | 283 | .filter(port -> port != pkt.inPort().port()) |
Saurav Das | 7a1ffca | 2016-03-28 19:00:18 -0700 | [diff] [blame] | 284 | .forEach(port -> { |
Pier Ventre | 10bd8d1 | 2016-11-26 21:05:22 -0800 | [diff] [blame] | 285 | ConnectPoint outPoint = new ConnectPoint( |
| 286 | pkt.inPort().deviceId(), |
| 287 | port |
| 288 | ); |
| 289 | pkt.forward(outPoint); |
Saurav Das | 7a1ffca | 2016-03-28 19:00:18 -0700 | [diff] [blame] | 290 | }); |
| 291 | } |
| 292 | }); |
| 293 | } catch (DeviceConfigNotFoundException e) { |
| 294 | log.warn(e.getMessage() |
| 295 | + " Cannot flood in subnet as device config not available" |
Pier Ventre | 10bd8d1 | 2016-11-26 21:05:22 -0800 | [diff] [blame] | 296 | + " for device: " + pkt.inPort().deviceId()); |
Saurav Das | 7a1ffca | 2016-03-28 19:00:18 -0700 | [diff] [blame] | 297 | } |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 298 | } |
| 299 | |
Charles Chan | 68aa62d | 2015-11-09 16:37:23 -0800 | [diff] [blame] | 300 | /** |
| 301 | * Remove VLAN tag and packet out to given port. |
| 302 | * |
| 303 | * Note: In current implementation, we expect all communication with |
| 304 | * end hosts within a subnet to be untagged. |
| 305 | * <p> |
| 306 | * For those pipelines that internally assigns a VLAN, the VLAN tag will be |
| 307 | * removed before egress. |
| 308 | * <p> |
| 309 | * For those pipelines that do not assign internal VLAN, the packet remains |
| 310 | * untagged. |
| 311 | * |
| 312 | * @param packet packet to be forwarded |
| 313 | * @param outPort where the packet should be forwarded |
| 314 | */ |
Pier Ventre | 10bd8d1 | 2016-11-26 21:05:22 -0800 | [diff] [blame] | 315 | private void forward(Ethernet packet, ConnectPoint outPort) { |
Charles Chan | 68aa62d | 2015-11-09 16:37:23 -0800 | [diff] [blame] | 316 | packet.setEtherType(Ethernet.TYPE_ARP); |
Charles Chan | 68aa62d | 2015-11-09 16:37:23 -0800 | [diff] [blame] | 317 | ByteBuffer buf = ByteBuffer.wrap(packet.serialize()); |
| 318 | |
| 319 | TrafficTreatment.Builder tbuilder = DefaultTrafficTreatment.builder(); |
| 320 | tbuilder.setOutput(outPort.port()); |
| 321 | srManager.packetService.emit(new DefaultOutboundPacket(outPort.deviceId(), |
| 322 | tbuilder.build(), buf)); |
| 323 | } |
sangho | b35a619 | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 324 | } |