sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | 43b5354 | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Laboratory |
sangho | 80f11cb | 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 | |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 18 | import org.onlab.packet.Ethernet; |
| 19 | import org.onlab.packet.ICMP; |
| 20 | import org.onlab.packet.IPv4; |
| 21 | import org.onlab.packet.Ip4Address; |
Pier Ventre | 1a65596 | 2016-11-28 16:48:06 -0800 | [diff] [blame^] | 22 | import org.onlab.packet.Ip6Address; |
Pier Ventre | adb4ae6 | 2016-11-23 09:57:42 -0800 | [diff] [blame] | 23 | import org.onlab.packet.IpAddress; |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 24 | import org.onlab.packet.IpPrefix; |
| 25 | import org.onlab.packet.MPLS; |
Pier Ventre | 1a65596 | 2016-11-28 16:48:06 -0800 | [diff] [blame^] | 26 | import org.onlab.packet.MacAddress; |
| 27 | import org.onlab.packet.VlanId; |
Pier Ventre | b6a7f34 | 2016-11-26 21:05:22 -0800 | [diff] [blame] | 28 | import org.onosproject.incubator.net.neighbour.NeighbourMessageContext; |
Pier Ventre | 1a65596 | 2016-11-28 16:48:06 -0800 | [diff] [blame^] | 29 | import org.onosproject.incubator.net.neighbour.NeighbourMessageType; |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 30 | import org.onosproject.net.ConnectPoint; |
| 31 | import org.onosproject.net.DeviceId; |
Pier Ventre | 1a65596 | 2016-11-28 16:48:06 -0800 | [diff] [blame^] | 32 | import org.onosproject.net.Host; |
| 33 | import org.onosproject.net.HostId; |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 34 | import org.onosproject.net.flow.DefaultTrafficTreatment; |
| 35 | import org.onosproject.net.flow.TrafficTreatment; |
Pier Ventre | 1a65596 | 2016-11-28 16:48:06 -0800 | [diff] [blame^] | 36 | import org.onosproject.net.host.HostService; |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 37 | import org.onosproject.net.packet.DefaultOutboundPacket; |
| 38 | import org.onosproject.net.packet.InboundPacket; |
| 39 | import org.onosproject.net.packet.OutboundPacket; |
Charles Chan | 319d1a2 | 2015-11-03 10:42:14 -0800 | [diff] [blame] | 40 | import org.onosproject.segmentrouting.config.DeviceConfigNotFoundException; |
| 41 | import org.onosproject.segmentrouting.config.DeviceConfiguration; |
Pier Ventre | 1a65596 | 2016-11-28 16:48:06 -0800 | [diff] [blame^] | 42 | import org.onosproject.segmentrouting.config.SegmentRoutingAppConfig; |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 43 | import org.slf4j.Logger; |
| 44 | import org.slf4j.LoggerFactory; |
| 45 | |
Jonathan Hart | d53ebc4 | 2015-04-07 16:46:33 -0700 | [diff] [blame] | 46 | import java.nio.ByteBuffer; |
Saurav Das | c28b343 | 2015-10-30 17:45:38 -0700 | [diff] [blame] | 47 | import java.util.Set; |
Jonathan Hart | d53ebc4 | 2015-04-07 16:46:33 -0700 | [diff] [blame] | 48 | |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 49 | import static com.google.common.base.Preconditions.checkNotNull; |
| 50 | |
Charles Chan | b7f75ac | 2016-01-11 18:28:54 -0800 | [diff] [blame] | 51 | /** |
| 52 | * Handler of ICMP packets that responses or forwards ICMP packets that |
| 53 | * are sent to the controller. |
| 54 | */ |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 55 | public class IcmpHandler { |
| 56 | |
| 57 | private static Logger log = LoggerFactory.getLogger(IcmpHandler.class); |
| 58 | private SegmentRoutingManager srManager; |
sangho | 9b169e3 | 2015-04-14 16:27:13 -0700 | [diff] [blame] | 59 | private DeviceConfiguration config; |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 60 | |
| 61 | /** |
| 62 | * Creates an IcmpHandler object. |
| 63 | * |
| 64 | * @param srManager SegmentRoutingManager object |
| 65 | */ |
| 66 | public IcmpHandler(SegmentRoutingManager srManager) { |
| 67 | this.srManager = srManager; |
sangho | 9b169e3 | 2015-04-14 16:27:13 -0700 | [diff] [blame] | 68 | this.config = checkNotNull(srManager.deviceConfiguration); |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 69 | } |
| 70 | |
Pier Ventre | 1a65596 | 2016-11-28 16:48:06 -0800 | [diff] [blame^] | 71 | ////////////////////////////////////// |
| 72 | // ICMP Echo/Reply Protocol // |
| 73 | ////////////////////////////////////// |
| 74 | |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 75 | /** |
| 76 | * Process incoming ICMP packet. |
| 77 | * If it is an ICMP request to router or known host, then sends an ICMP response. |
| 78 | * If it is an ICMP packet to known host and forward the packet to the host. |
| 79 | * If it is an ICMP packet to unknown host in a subnet, then sends an ARP request |
| 80 | * to the subnet. |
| 81 | * |
Thomas Vachuska | 8a07509 | 2015-04-15 18:20:08 -0700 | [diff] [blame] | 82 | * @param pkt inbound packet |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 83 | */ |
| 84 | public void processPacketIn(InboundPacket pkt) { |
| 85 | |
| 86 | Ethernet ethernet = pkt.parsed(); |
| 87 | IPv4 ipv4 = (IPv4) ethernet.getPayload(); |
| 88 | |
| 89 | ConnectPoint connectPoint = pkt.receivedFrom(); |
| 90 | DeviceId deviceId = connectPoint.deviceId(); |
| 91 | Ip4Address destinationAddress = |
| 92 | Ip4Address.valueOf(ipv4.getDestinationAddress()); |
Pier Ventre | b6a7f34 | 2016-11-26 21:05:22 -0800 | [diff] [blame] | 93 | Set<IpAddress> gatewayIpAddresses = config.getPortIPs(deviceId); |
Pier Ventre | adb4ae6 | 2016-11-23 09:57:42 -0800 | [diff] [blame] | 94 | IpAddress routerIp; |
Charles Chan | 319d1a2 | 2015-11-03 10:42:14 -0800 | [diff] [blame] | 95 | try { |
Pier Ventre | adb4ae6 | 2016-11-23 09:57:42 -0800 | [diff] [blame] | 96 | routerIp = config.getRouterIpv4(deviceId); |
Charles Chan | 319d1a2 | 2015-11-03 10:42:14 -0800 | [diff] [blame] | 97 | } catch (DeviceConfigNotFoundException e) { |
| 98 | log.warn(e.getMessage() + " Aborting processPacketIn."); |
| 99 | return; |
| 100 | } |
sangho | 9b169e3 | 2015-04-14 16:27:13 -0700 | [diff] [blame] | 101 | IpPrefix routerIpPrefix = IpPrefix.valueOf(routerIp, IpPrefix.MAX_INET_MASK_LENGTH); |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 102 | Ip4Address routerIpAddress = routerIpPrefix.getIp4Prefix().address(); |
| 103 | |
| 104 | // ICMP to the router IP or gateway IP |
| 105 | if (((ICMP) ipv4.getPayload()).getIcmpType() == ICMP.TYPE_ECHO_REQUEST && |
| 106 | (destinationAddress.equals(routerIpAddress) || |
Srikanth Vavilapalli | 37a461b | 2015-04-07 15:12:32 -0700 | [diff] [blame] | 107 | gatewayIpAddresses.contains(destinationAddress))) { |
Pier Ventre | adb4ae6 | 2016-11-23 09:57:42 -0800 | [diff] [blame] | 108 | sendIcmpResponse(ethernet, connectPoint); |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 109 | |
| 110 | // ICMP for any known host |
| 111 | } else if (!srManager.hostService.getHostsByIp(destinationAddress).isEmpty()) { |
Saurav Das | 2d94d31 | 2015-11-24 23:21:05 -0800 | [diff] [blame] | 112 | // TODO: known host packet should not be coming to controller - resend flows? |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 113 | srManager.ipHandler.forwardPackets(deviceId, destinationAddress); |
| 114 | |
| 115 | // ICMP for an unknown host in the subnet of the router |
| 116 | } else if (config.inSameSubnet(deviceId, destinationAddress)) { |
| 117 | srManager.arpHandler.sendArpRequest(deviceId, destinationAddress, connectPoint); |
| 118 | |
| 119 | // ICMP for an unknown host |
| 120 | } else { |
| 121 | log.debug("ICMP request for unknown host {} ", destinationAddress); |
| 122 | // Do nothing |
| 123 | } |
| 124 | } |
| 125 | |
Charles Chan | f458611 | 2015-11-09 16:37:23 -0800 | [diff] [blame] | 126 | /** |
| 127 | * Sends an ICMP reply message. |
| 128 | * |
| 129 | * Note: we assume that packets sending from the edge switches to the hosts |
| 130 | * have untagged VLAN. |
| 131 | * @param icmpRequest the original ICMP request |
| 132 | * @param outport the output port where the ICMP reply should be sent to |
| 133 | */ |
Pier Ventre | adb4ae6 | 2016-11-23 09:57:42 -0800 | [diff] [blame] | 134 | private void sendIcmpResponse(Ethernet icmpRequest, ConnectPoint outport) { |
Charles Chan | f458611 | 2015-11-09 16:37:23 -0800 | [diff] [blame] | 135 | // Note: We assume that packets arrive at the edge switches have |
| 136 | // untagged VLAN. |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 137 | Ethernet icmpReplyEth = new Ethernet(); |
| 138 | |
| 139 | IPv4 icmpRequestIpv4 = (IPv4) icmpRequest.getPayload(); |
| 140 | IPv4 icmpReplyIpv4 = new IPv4(); |
| 141 | |
| 142 | int destAddress = icmpRequestIpv4.getDestinationAddress(); |
| 143 | icmpReplyIpv4.setDestinationAddress(icmpRequestIpv4.getSourceAddress()); |
| 144 | icmpReplyIpv4.setSourceAddress(destAddress); |
| 145 | icmpReplyIpv4.setTtl((byte) 64); |
| 146 | icmpReplyIpv4.setChecksum((short) 0); |
| 147 | |
Jonathan Hart | d53ebc4 | 2015-04-07 16:46:33 -0700 | [diff] [blame] | 148 | ICMP icmpReply = new ICMP(); |
Saurav Das | a5bb7cb | 2015-09-30 10:00:49 -0700 | [diff] [blame] | 149 | icmpReply.setPayload(((ICMP) icmpRequestIpv4.getPayload()).getPayload()); |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 150 | icmpReply.setIcmpType(ICMP.TYPE_ECHO_REPLY); |
| 151 | icmpReply.setIcmpCode(ICMP.SUBTYPE_ECHO_REPLY); |
| 152 | icmpReply.setChecksum((short) 0); |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 153 | icmpReplyIpv4.setPayload(icmpReply); |
| 154 | |
| 155 | icmpReplyEth.setPayload(icmpReplyIpv4); |
| 156 | icmpReplyEth.setEtherType(Ethernet.TYPE_IPV4); |
| 157 | icmpReplyEth.setDestinationMACAddress(icmpRequest.getSourceMACAddress()); |
| 158 | icmpReplyEth.setSourceMACAddress(icmpRequest.getDestinationMACAddress()); |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 159 | |
| 160 | Ip4Address destIpAddress = Ip4Address.valueOf(icmpReplyIpv4.getDestinationAddress()); |
sangho | 9b169e3 | 2015-04-14 16:27:13 -0700 | [diff] [blame] | 161 | Ip4Address destRouterAddress = config.getRouterIpAddressForASubnetHost(destIpAddress); |
Pier Ventre | adb4ae6 | 2016-11-23 09:57:42 -0800 | [diff] [blame] | 162 | int destSid = config.getIPv4SegmentId(destRouterAddress); |
Charles Chan | 7066136 | 2016-12-09 12:54:49 -0800 | [diff] [blame] | 163 | if (destSid < 0) { |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 164 | log.warn("Cannot find the Segment ID for {}", destAddress); |
| 165 | return; |
| 166 | } |
| 167 | |
Charles Chan | 7066136 | 2016-12-09 12:54:49 -0800 | [diff] [blame] | 168 | sendPacketOut(outport, icmpReplyEth, destSid); |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 169 | |
| 170 | } |
| 171 | |
Charles Chan | 7066136 | 2016-12-09 12:54:49 -0800 | [diff] [blame] | 172 | private void sendPacketOut(ConnectPoint outport, Ethernet payload, int destSid) { |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 173 | |
| 174 | IPv4 ipPacket = (IPv4) payload.getPayload(); |
| 175 | Ip4Address destIpAddress = Ip4Address.valueOf(ipPacket.getDestinationAddress()); |
| 176 | |
Pier Ventre | adb4ae6 | 2016-11-23 09:57:42 -0800 | [diff] [blame] | 177 | if (destSid == -1 || config.getIPv4SegmentId(payload.getDestinationMAC()) == destSid || |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 178 | config.inSameSubnet(outport.deviceId(), destIpAddress)) { |
| 179 | TrafficTreatment treatment = DefaultTrafficTreatment.builder(). |
| 180 | setOutput(outport.port()).build(); |
| 181 | OutboundPacket packet = new DefaultOutboundPacket(outport.deviceId(), |
| 182 | treatment, ByteBuffer.wrap(payload.serialize())); |
| 183 | srManager.packetService.emit(packet); |
| 184 | } else { |
Saurav Das | d44e880 | 2016-10-21 14:06:29 -0700 | [diff] [blame] | 185 | log.debug("Send a MPLS packet as a ICMP response"); |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 186 | TrafficTreatment treatment = DefaultTrafficTreatment.builder() |
| 187 | .setOutput(outport.port()) |
| 188 | .build(); |
| 189 | |
| 190 | payload.setEtherType(Ethernet.MPLS_UNICAST); |
| 191 | MPLS mplsPkt = new MPLS(); |
Charles Chan | 7066136 | 2016-12-09 12:54:49 -0800 | [diff] [blame] | 192 | mplsPkt.setLabel(destSid); |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 193 | mplsPkt.setTtl(((IPv4) payload.getPayload()).getTtl()); |
| 194 | mplsPkt.setPayload(payload.getPayload()); |
| 195 | payload.setPayload(mplsPkt); |
| 196 | |
| 197 | OutboundPacket packet = new DefaultOutboundPacket(outport.deviceId(), |
| 198 | treatment, ByteBuffer.wrap(payload.serialize())); |
| 199 | |
| 200 | srManager.packetService.emit(packet); |
| 201 | } |
| 202 | } |
sangho | 9b169e3 | 2015-04-14 16:27:13 -0700 | [diff] [blame] | 203 | |
Pier Ventre | 1a65596 | 2016-11-28 16:48:06 -0800 | [diff] [blame^] | 204 | /////////////////////////////////////////// |
| 205 | // ICMPv6 Neighbour Discovery Protocol // |
| 206 | /////////////////////////////////////////// |
sangho | 9b169e3 | 2015-04-14 16:27:13 -0700 | [diff] [blame] | 207 | |
Pier Ventre | 1a65596 | 2016-11-28 16:48:06 -0800 | [diff] [blame^] | 208 | /** |
| 209 | * Process incoming NDP packet. |
| 210 | * |
| 211 | * If it is an NDP request for the router or for the gateway, then sends a NDP reply. |
| 212 | * If it is an NDP request to unknown host flood in the subnet. |
| 213 | * If it is an NDP packet to known host forward the packet to the host. |
| 214 | * |
| 215 | * FIXME If the NDP packets use link local addresses we fail. |
| 216 | * |
| 217 | * @param pkt inbound packet |
| 218 | * @param hostService the host service |
| 219 | */ |
| 220 | public void processPacketIn(NeighbourMessageContext pkt, HostService hostService) { |
| 221 | /* |
| 222 | * First we validate the ndp packet |
| 223 | */ |
| 224 | SegmentRoutingAppConfig appConfig = srManager.cfgService |
| 225 | .getConfig(srManager.appId, SegmentRoutingAppConfig.class); |
| 226 | if (appConfig != null && appConfig.suppressSubnet().contains(pkt.inPort())) { |
| 227 | // Ignore NDP packets come from suppressed ports |
| 228 | pkt.drop(); |
| 229 | return; |
| 230 | } |
| 231 | if (!validateSrcIp(pkt)) { |
| 232 | log.debug("Ignore NDP packet discovered on {} with unexpected src ip address {}.", |
| 233 | pkt.inPort(), pkt.sender()); |
| 234 | pkt.drop(); |
| 235 | return; |
| 236 | } |
| 237 | |
| 238 | if (pkt.type() == NeighbourMessageType.REQUEST) { |
| 239 | handleNdpRequest(pkt, hostService); |
| 240 | } else { |
| 241 | handleNdpReply(pkt, hostService); |
| 242 | } |
| 243 | |
| 244 | } |
| 245 | |
| 246 | /** |
| 247 | * Utility function to verify if the src ip belongs to the same |
| 248 | * subnet configured on the port it is seen. |
| 249 | * |
| 250 | * @param pkt the ndp packet and context information |
| 251 | * @return true if the src ip is a valid address for the subnet configured |
| 252 | * for the connect point |
| 253 | */ |
| 254 | private boolean validateSrcIp(NeighbourMessageContext pkt) { |
| 255 | ConnectPoint connectPoint = pkt.inPort(); |
| 256 | IpPrefix subnet = config.getPortIPv6Subnet( |
| 257 | connectPoint.deviceId(), |
| 258 | connectPoint.port() |
| 259 | ).getIp6Prefix(); |
| 260 | return subnet != null && subnet.contains(pkt.sender()); |
| 261 | } |
| 262 | |
| 263 | /** |
| 264 | * Helper method to handle the ndp requests. |
| 265 | * |
| 266 | * @param pkt the ndp packet request and context information |
| 267 | * @param hostService the host service |
| 268 | */ |
| 269 | private void handleNdpRequest(NeighbourMessageContext pkt, HostService hostService) { |
| 270 | /* |
| 271 | * ND request for the gateway. We have to reply on behalf |
| 272 | * of the gateway. |
| 273 | */ |
| 274 | if (isNdpForGateway(pkt)) { |
| 275 | log.debug("Sending NDP reply on behalf of the router"); |
| 276 | sendNdpReply(pkt, config.getRouterMacForAGatewayIp(pkt.target())); |
| 277 | } else { |
| 278 | /* |
| 279 | * ND request for an host. We do a search by Ip. |
| 280 | */ |
| 281 | Set<Host> hosts = hostService.getHostsByIp(pkt.target()); |
| 282 | /* |
| 283 | * Possible misconfiguration ? In future this case |
| 284 | * should be handled we can have same hosts in different |
| 285 | * vlans. |
| 286 | */ |
| 287 | if (hosts.size() > 1) { |
| 288 | log.warn("More than one host with IP {}", pkt.target()); |
| 289 | } |
| 290 | Host targetHost = hosts.stream().findFirst().orElse(null); |
| 291 | /* |
| 292 | * If we know the host forward to its attachment |
| 293 | * point. |
| 294 | */ |
| 295 | if (targetHost != null) { |
| 296 | log.debug("Forward NDP request to the target host"); |
| 297 | pkt.forward(targetHost.location()); |
| 298 | } else { |
| 299 | /* |
| 300 | * Flood otherwise. |
| 301 | */ |
| 302 | log.debug("Flood NDP request to the target subnet"); |
| 303 | flood(pkt); |
| 304 | } |
| 305 | } |
| 306 | } |
| 307 | |
| 308 | /** |
| 309 | * Helper method to handle the ndp replies. |
| 310 | * |
| 311 | * @param pkt the ndp packet reply and context information |
| 312 | * @param hostService the host service |
| 313 | */ |
| 314 | private void handleNdpReply(NeighbourMessageContext pkt, HostService hostService) { |
| 315 | if (isNdpForGateway(pkt)) { |
| 316 | log.debug("Forwarding all the ip packets we stored"); |
| 317 | Ip6Address hostIpAddress = pkt.sender().getIp6Address(); |
| 318 | srManager.ipHandler.forwardPackets(pkt.inPort().deviceId(), hostIpAddress); |
| 319 | } else { |
| 320 | HostId hostId = HostId.hostId(pkt.dstMac(), pkt.vlan()); |
| 321 | Host targetHost = hostService.getHost(hostId); |
| 322 | if (targetHost != null) { |
| 323 | log.debug("Forwarding the reply to the host"); |
| 324 | pkt.forward(targetHost.location()); |
| 325 | } else { |
| 326 | /* |
| 327 | * We don't have to flood towards spine facing ports. |
| 328 | */ |
| 329 | if (pkt.vlan().equals(VlanId.vlanId(SegmentRoutingManager.ASSIGNED_VLAN_NO_SUBNET))) { |
| 330 | return; |
| 331 | } |
| 332 | log.debug("Flooding the reply to the subnet"); |
| 333 | flood(pkt); |
| 334 | } |
| 335 | } |
| 336 | } |
| 337 | |
| 338 | /** |
| 339 | * Utility to verify if the ND are for the gateway. |
| 340 | * |
| 341 | * @param pkt the ndp packet |
| 342 | * @return true if the ndp is for the gateway. False otherwise |
| 343 | */ |
| 344 | private boolean isNdpForGateway(NeighbourMessageContext pkt) { |
| 345 | DeviceId deviceId = pkt.inPort().deviceId(); |
| 346 | Set<IpAddress> gatewayIpAddresses = null; |
| 347 | try { |
| 348 | if (pkt.target().equals(config.getRouterIpv6(deviceId))) { |
| 349 | return true; |
| 350 | } |
| 351 | gatewayIpAddresses = config.getPortIPs(deviceId); |
| 352 | } catch (DeviceConfigNotFoundException e) { |
| 353 | log.warn(e.getMessage() + " Aborting check for router IP in processing ndp"); |
| 354 | } |
| 355 | if (gatewayIpAddresses != null && |
| 356 | gatewayIpAddresses.contains(pkt.target())) { |
| 357 | return true; |
| 358 | } |
| 359 | return false; |
| 360 | } |
| 361 | |
| 362 | /** |
| 363 | * Utility to send a ND reply using the supplied information. |
| 364 | * |
| 365 | * @param pkt the ndp request |
| 366 | * @param targetMac the target mac |
| 367 | */ |
| 368 | private void sendNdpReply(NeighbourMessageContext pkt, MacAddress targetMac) { |
| 369 | HostId dstId = HostId.hostId(pkt.srcMac(), pkt.vlan()); |
| 370 | Host dst = srManager.hostService.getHost(dstId); |
| 371 | if (dst == null) { |
| 372 | log.warn("Cannot send NDP response to host {} - does not exist in the store", |
| 373 | dstId); |
| 374 | return; |
| 375 | } |
| 376 | pkt.reply(targetMac); |
| 377 | } |
| 378 | |
| 379 | /* |
| 380 | * Floods only on the port which have been configured with the subnet |
| 381 | * of the target address. The in port is excluded. |
| 382 | * |
| 383 | * @param pkt the ndp packet and context information |
| 384 | */ |
| 385 | private void flood(NeighbourMessageContext pkt) { |
| 386 | try { |
| 387 | srManager.deviceConfiguration |
| 388 | .getSubnetPortsMap(pkt.inPort().deviceId()) |
| 389 | .forEach((subnet, ports) -> { |
| 390 | if (subnet.contains(pkt.target())) { |
| 391 | ports.stream() |
| 392 | .filter(portNumber -> portNumber != pkt.inPort().port()) |
| 393 | .forEach(portNumber -> { |
| 394 | ConnectPoint outPoint = new ConnectPoint( |
| 395 | pkt.inPort().deviceId(), |
| 396 | portNumber |
| 397 | ); |
| 398 | pkt.forward(outPoint); |
| 399 | }); |
| 400 | } |
| 401 | }); |
| 402 | } catch (DeviceConfigNotFoundException e) { |
| 403 | log.warn(e.getMessage() |
| 404 | + " Cannot flood in subnet as device config not available" |
| 405 | + " for device: " + pkt.inPort().deviceId()); |
| 406 | } |
| 407 | } |
sangho | 80f11cb | 2015-04-01 13:05:26 -0700 | [diff] [blame] | 408 | } |