Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 1 | /* |
Ray Milkey | 34c9590 | 2015-04-15 09:47:53 -0700 | [diff] [blame] | 2 | * Copyright 2014-2015 Open Networking Laboratory |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -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 | */ |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 16 | package org.onosproject.net.host.impl; |
Jonathan Hart | fca736c | 2014-09-19 17:26:59 -0700 | [diff] [blame] | 17 | |
Jonathan Hart | fca736c | 2014-09-19 17:26:59 -0700 | [diff] [blame] | 18 | import org.jboss.netty.util.Timeout; |
| 19 | import org.jboss.netty.util.TimerTask; |
Jonathan Hart | 6cd2f35 | 2015-01-13 17:44:45 -0800 | [diff] [blame] | 20 | import org.onlab.packet.ARP; |
| 21 | import org.onlab.packet.Ethernet; |
Pavlin Radoslavov | 89edb54 | 2015-02-23 13:50:29 -0800 | [diff] [blame] | 22 | import org.onlab.packet.ICMP6; |
Jonathan Hart | 6cd2f35 | 2015-01-13 17:44:45 -0800 | [diff] [blame] | 23 | import org.onlab.packet.IpAddress; |
Pavlin Radoslavov | 89edb54 | 2015-02-23 13:50:29 -0800 | [diff] [blame] | 24 | import org.onlab.packet.IPv6; |
Jonathan Hart | 6cd2f35 | 2015-01-13 17:44:45 -0800 | [diff] [blame] | 25 | import org.onlab.packet.MacAddress; |
| 26 | import org.onlab.packet.VlanId; |
Pavlin Radoslavov | 89edb54 | 2015-02-23 13:50:29 -0800 | [diff] [blame] | 27 | import org.onlab.packet.ndp.NeighborDiscoveryOptions; |
| 28 | import org.onlab.packet.ndp.NeighborSolicitation; |
Jonathan Hart | 6cd2f35 | 2015-01-13 17:44:45 -0800 | [diff] [blame] | 29 | import org.onlab.util.Timer; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 30 | import org.onosproject.net.ConnectPoint; |
| 31 | import org.onosproject.net.Device; |
| 32 | import org.onosproject.net.DeviceId; |
| 33 | import org.onosproject.net.Host; |
| 34 | import org.onosproject.net.Port; |
| 35 | import org.onosproject.net.device.DeviceService; |
| 36 | import org.onosproject.net.flow.DefaultTrafficTreatment; |
| 37 | import org.onosproject.net.flow.TrafficTreatment; |
| 38 | import org.onosproject.net.flow.instructions.Instruction; |
| 39 | import org.onosproject.net.flow.instructions.Instructions; |
| 40 | import org.onosproject.net.host.HostProvider; |
| 41 | import org.onosproject.net.host.InterfaceIpAddress; |
| 42 | import org.onosproject.net.host.PortAddresses; |
| 43 | import org.onosproject.net.packet.DefaultOutboundPacket; |
| 44 | import org.onosproject.net.packet.OutboundPacket; |
| 45 | import org.onosproject.net.packet.PacketService; |
| 46 | import org.onosproject.net.provider.ProviderId; |
Jonathan Hart | 6cd2f35 | 2015-01-13 17:44:45 -0800 | [diff] [blame] | 47 | |
| 48 | import java.nio.ByteBuffer; |
| 49 | import java.util.ArrayList; |
| 50 | import java.util.Collections; |
| 51 | import java.util.List; |
| 52 | import java.util.Set; |
| 53 | import java.util.concurrent.ConcurrentHashMap; |
| 54 | import java.util.concurrent.ConcurrentMap; |
| 55 | import java.util.concurrent.TimeUnit; |
Jonathan Hart | fca736c | 2014-09-19 17:26:59 -0700 | [diff] [blame] | 56 | |
Jonathan Hart | 87fbbad | 2014-09-23 08:43:50 -0700 | [diff] [blame] | 57 | /** |
| 58 | * Monitors hosts on the dataplane to detect changes in host data. |
Thomas Vachuska | 4b42077 | 2014-10-30 16:46:17 -0700 | [diff] [blame] | 59 | * <p> |
Jonathan Hart | 87fbbad | 2014-09-23 08:43:50 -0700 | [diff] [blame] | 60 | * The HostMonitor can monitor hosts that have already been detected for |
| 61 | * changes. At an application's request, it can also monitor and actively |
| 62 | * probe for hosts that have not yet been detected (specified by IP address). |
Thomas Vachuska | 4b42077 | 2014-10-30 16:46:17 -0700 | [diff] [blame] | 63 | * </p> |
Jonathan Hart | 87fbbad | 2014-09-23 08:43:50 -0700 | [diff] [blame] | 64 | */ |
tom | 202175a | 2014-09-19 19:00:11 -0700 | [diff] [blame] | 65 | public class HostMonitor implements TimerTask { |
Jonathan Hart | 70da512 | 2014-10-01 16:37:42 -0700 | [diff] [blame] | 66 | private DeviceService deviceService; |
| 67 | private PacketService packetService; |
| 68 | private HostManager hostManager; |
Jonathan Hart | fca736c | 2014-09-19 17:26:59 -0700 | [diff] [blame] | 69 | |
Jonathan Hart | 87fbbad | 2014-09-23 08:43:50 -0700 | [diff] [blame] | 70 | private final Set<IpAddress> monitoredAddresses; |
Jonathan Hart | fca736c | 2014-09-19 17:26:59 -0700 | [diff] [blame] | 71 | |
Jonathan Hart | 34ed2fd | 2014-10-02 19:08:55 -0700 | [diff] [blame] | 72 | private final ConcurrentMap<ProviderId, HostProvider> hostProviders; |
Jonathan Hart | 70da512 | 2014-10-01 16:37:42 -0700 | [diff] [blame] | 73 | |
Jonathan Hart | 34ed2fd | 2014-10-02 19:08:55 -0700 | [diff] [blame] | 74 | private static final long DEFAULT_PROBE_RATE = 30000; // milliseconds |
Yuta HIGUCHI | 3e848a8 | 2014-11-02 20:19:42 -0800 | [diff] [blame] | 75 | private static final byte[] ZERO_MAC_ADDRESS = MacAddress.ZERO.toBytes(); |
Jonathan Hart | 34ed2fd | 2014-10-02 19:08:55 -0700 | [diff] [blame] | 76 | private long probeRate = DEFAULT_PROBE_RATE; |
Jonathan Hart | fca736c | 2014-09-19 17:26:59 -0700 | [diff] [blame] | 77 | |
Jonathan Hart | 8f6f1ea | 2014-10-03 16:05:19 -0700 | [diff] [blame] | 78 | private Timeout timeout; |
Jonathan Hart | fca736c | 2014-09-19 17:26:59 -0700 | [diff] [blame] | 79 | |
Jonathan Hart | 8f6f1ea | 2014-10-03 16:05:19 -0700 | [diff] [blame] | 80 | /** |
| 81 | * Creates a new host monitor. |
| 82 | * |
| 83 | * @param deviceService device service used to find edge ports |
| 84 | * @param packetService packet service used to send packets on the data plane |
Jonathan Hart | b4758a9 | 2014-09-24 10:46:45 -0700 | [diff] [blame] | 85 | * @param hostManager host manager used to look up host information and |
| 86 | * probe existing hosts |
Jonathan Hart | 8f6f1ea | 2014-10-03 16:05:19 -0700 | [diff] [blame] | 87 | */ |
Jonathan Hart | 34ed2fd | 2014-10-02 19:08:55 -0700 | [diff] [blame] | 88 | public HostMonitor(DeviceService deviceService, PacketService packetService, |
Jonathan Hart | b4758a9 | 2014-09-24 10:46:45 -0700 | [diff] [blame] | 89 | HostManager hostManager) { |
Jonathan Hart | 70da512 | 2014-10-01 16:37:42 -0700 | [diff] [blame] | 90 | |
Jonathan Hart | fca736c | 2014-09-19 17:26:59 -0700 | [diff] [blame] | 91 | this.deviceService = deviceService; |
Jonathan Hart | 87fbbad | 2014-09-23 08:43:50 -0700 | [diff] [blame] | 92 | this.packetService = packetService; |
Jonathan Hart | b4758a9 | 2014-09-24 10:46:45 -0700 | [diff] [blame] | 93 | this.hostManager = hostManager; |
Jonathan Hart | fca736c | 2014-09-19 17:26:59 -0700 | [diff] [blame] | 94 | |
Jonathan Hart | 8f6f1ea | 2014-10-03 16:05:19 -0700 | [diff] [blame] | 95 | monitoredAddresses = Collections.newSetFromMap( |
| 96 | new ConcurrentHashMap<IpAddress, Boolean>()); |
Jonathan Hart | 70da512 | 2014-10-01 16:37:42 -0700 | [diff] [blame] | 97 | hostProviders = new ConcurrentHashMap<>(); |
Jonathan Hart | 70da512 | 2014-10-01 16:37:42 -0700 | [diff] [blame] | 98 | } |
| 99 | |
Jonathan Hart | 8f6f1ea | 2014-10-03 16:05:19 -0700 | [diff] [blame] | 100 | /** |
| 101 | * Adds an IP address to be monitored by the host monitor. The monitor will |
| 102 | * periodically probe the host to detect changes. |
| 103 | * |
| 104 | * @param ip IP address of the host to monitor |
| 105 | */ |
Jonathan Hart | 70da512 | 2014-10-01 16:37:42 -0700 | [diff] [blame] | 106 | void addMonitoringFor(IpAddress ip) { |
Jonathan Hart | fca736c | 2014-09-19 17:26:59 -0700 | [diff] [blame] | 107 | monitoredAddresses.add(ip); |
| 108 | } |
| 109 | |
Jonathan Hart | 8f6f1ea | 2014-10-03 16:05:19 -0700 | [diff] [blame] | 110 | /** |
| 111 | * Stops monitoring the given IP address. |
| 112 | * |
| 113 | * @param ip IP address to stop monitoring on |
| 114 | */ |
Jonathan Hart | 70da512 | 2014-10-01 16:37:42 -0700 | [diff] [blame] | 115 | void stopMonitoring(IpAddress ip) { |
Jonathan Hart | fca736c | 2014-09-19 17:26:59 -0700 | [diff] [blame] | 116 | monitoredAddresses.remove(ip); |
| 117 | } |
| 118 | |
Jonathan Hart | 8f6f1ea | 2014-10-03 16:05:19 -0700 | [diff] [blame] | 119 | /** |
| 120 | * Starts the host monitor. Does nothing if the monitor is already running. |
| 121 | */ |
| 122 | void start() { |
| 123 | synchronized (this) { |
| 124 | if (timeout == null) { |
| 125 | timeout = Timer.getTimer().newTimeout(this, 0, TimeUnit.MILLISECONDS); |
| 126 | } |
| 127 | } |
Jonathan Hart | fca736c | 2014-09-19 17:26:59 -0700 | [diff] [blame] | 128 | } |
| 129 | |
Jonathan Hart | 8f6f1ea | 2014-10-03 16:05:19 -0700 | [diff] [blame] | 130 | /** |
| 131 | * Stops the host monitor. |
| 132 | */ |
| 133 | void shutdown() { |
| 134 | synchronized (this) { |
| 135 | timeout.cancel(); |
| 136 | timeout = null; |
| 137 | } |
| 138 | } |
| 139 | |
| 140 | /** |
| 141 | * Registers a host provider with the host monitor. The monitor can use the |
| 142 | * provider to probe hosts. |
| 143 | * |
| 144 | * @param provider the host provider to register |
| 145 | */ |
Jonathan Hart | 70da512 | 2014-10-01 16:37:42 -0700 | [diff] [blame] | 146 | void registerHostProvider(HostProvider provider) { |
| 147 | hostProviders.put(provider.id(), provider); |
| 148 | } |
| 149 | |
Jonathan Hart | fca736c | 2014-09-19 17:26:59 -0700 | [diff] [blame] | 150 | @Override |
| 151 | public void run(Timeout timeout) throws Exception { |
Jonathan Hart | 87fbbad | 2014-09-23 08:43:50 -0700 | [diff] [blame] | 152 | for (IpAddress ip : monitoredAddresses) { |
Pavlin Radoslavov | 33f228a | 2014-10-27 19:33:16 -0700 | [diff] [blame] | 153 | Set<Host> hosts = hostManager.getHostsByIp(ip); |
Jonathan Hart | fca736c | 2014-09-19 17:26:59 -0700 | [diff] [blame] | 154 | |
| 155 | if (hosts.isEmpty()) { |
Pavlin Radoslavov | 89edb54 | 2015-02-23 13:50:29 -0800 | [diff] [blame] | 156 | sendArpNdpRequest(ip); |
Jonathan Hart | fca736c | 2014-09-19 17:26:59 -0700 | [diff] [blame] | 157 | } else { |
| 158 | for (Host host : hosts) { |
Jonathan Hart | 70da512 | 2014-10-01 16:37:42 -0700 | [diff] [blame] | 159 | HostProvider provider = hostProviders.get(host.providerId()); |
Jonathan Hart | 34ed2fd | 2014-10-02 19:08:55 -0700 | [diff] [blame] | 160 | if (provider == null) { |
| 161 | hostProviders.remove(host.providerId(), null); |
| 162 | } else { |
Jonathan Hart | 70da512 | 2014-10-01 16:37:42 -0700 | [diff] [blame] | 163 | provider.triggerProbe(host); |
| 164 | } |
Jonathan Hart | fca736c | 2014-09-19 17:26:59 -0700 | [diff] [blame] | 165 | } |
| 166 | } |
| 167 | } |
| 168 | |
Jonathan Hart | 8f6f1ea | 2014-10-03 16:05:19 -0700 | [diff] [blame] | 169 | this.timeout = Timer.getTimer().newTimeout(this, probeRate, TimeUnit.MILLISECONDS); |
Jonathan Hart | fca736c | 2014-09-19 17:26:59 -0700 | [diff] [blame] | 170 | } |
| 171 | |
| 172 | /** |
Pavlin Radoslavov | 89edb54 | 2015-02-23 13:50:29 -0800 | [diff] [blame] | 173 | * Sends an ARP or Neighbor Discovery Protocol request for the given IP |
| 174 | * address. |
Jonathan Hart | fca736c | 2014-09-19 17:26:59 -0700 | [diff] [blame] | 175 | * |
Pavlin Radoslavov | 89edb54 | 2015-02-23 13:50:29 -0800 | [diff] [blame] | 176 | * @param targetIp IP address to send the request for |
Jonathan Hart | fca736c | 2014-09-19 17:26:59 -0700 | [diff] [blame] | 177 | */ |
Pavlin Radoslavov | 89edb54 | 2015-02-23 13:50:29 -0800 | [diff] [blame] | 178 | private void sendArpNdpRequest(IpAddress targetIp) { |
| 179 | // Find ports with an IP address in the target's subnet and sent ARP/ND |
Jonathan Hart | 87fbbad | 2014-09-23 08:43:50 -0700 | [diff] [blame] | 180 | // probes out those ports. |
| 181 | for (Device device : deviceService.getDevices()) { |
Jonathan Hart | fca736c | 2014-09-19 17:26:59 -0700 | [diff] [blame] | 182 | for (Port port : deviceService.getPorts(device.id())) { |
Jonathan Hart | 87fbbad | 2014-09-23 08:43:50 -0700 | [diff] [blame] | 183 | ConnectPoint cp = new ConnectPoint(device.id(), port.number()); |
Jonathan Hart | a887ba8 | 2014-11-03 15:20:52 -0800 | [diff] [blame] | 184 | Set<PortAddresses> portAddressSet = |
Pavlin Radoslavov | 76b0ae2 | 2014-10-27 15:33:19 -0700 | [diff] [blame] | 185 | hostManager.getAddressBindingsForPort(cp); |
Jonathan Hart | 87fbbad | 2014-09-23 08:43:50 -0700 | [diff] [blame] | 186 | |
Jonathan Hart | a887ba8 | 2014-11-03 15:20:52 -0800 | [diff] [blame] | 187 | for (PortAddresses portAddresses : portAddressSet) { |
| 188 | for (InterfaceIpAddress ia : portAddresses.ipAddresses()) { |
| 189 | if (ia.subnetAddress().contains(targetIp)) { |
Pavlin Radoslavov | 89edb54 | 2015-02-23 13:50:29 -0800 | [diff] [blame] | 190 | sendArpNdpProbe(device.id(), port, targetIp, |
| 191 | ia.ipAddress(), |
| 192 | portAddresses.mac(), |
| 193 | portAddresses.vlan()); |
Jonathan Hart | a887ba8 | 2014-11-03 15:20:52 -0800 | [diff] [blame] | 194 | } |
Jonathan Hart | 09585c6 | 2014-09-23 16:58:04 -0700 | [diff] [blame] | 195 | } |
Jonathan Hart | 70da512 | 2014-10-01 16:37:42 -0700 | [diff] [blame] | 196 | } |
Jonathan Hart | fca736c | 2014-09-19 17:26:59 -0700 | [diff] [blame] | 197 | } |
Jonathan Hart | 87fbbad | 2014-09-23 08:43:50 -0700 | [diff] [blame] | 198 | } |
Jonathan Hart | fca736c | 2014-09-19 17:26:59 -0700 | [diff] [blame] | 199 | } |
| 200 | |
Pavlin Radoslavov | 89edb54 | 2015-02-23 13:50:29 -0800 | [diff] [blame] | 201 | private void sendArpNdpProbe(DeviceId deviceId, Port port, |
| 202 | IpAddress targetIp, |
| 203 | IpAddress sourceIp, MacAddress sourceMac, |
| 204 | VlanId vlan) { |
| 205 | Ethernet probePacket = null; |
| 206 | |
Pavlin Radoslavov | 87dd930 | 2015-03-10 13:53:24 -0700 | [diff] [blame] | 207 | if (targetIp.isIp4()) { |
Pavlin Radoslavov | 89edb54 | 2015-02-23 13:50:29 -0800 | [diff] [blame] | 208 | // IPv4: Use ARP |
| 209 | probePacket = buildArpRequest(targetIp, sourceIp, sourceMac, |
| 210 | vlan); |
| 211 | } else { |
| 212 | // IPv6: Use Neighbor Discovery |
| 213 | probePacket = buildNdpRequest(targetIp, sourceIp, sourceMac, |
| 214 | vlan); |
| 215 | } |
Jonathan Hart | fca736c | 2014-09-19 17:26:59 -0700 | [diff] [blame] | 216 | |
Jonathan Hart | 87fbbad | 2014-09-23 08:43:50 -0700 | [diff] [blame] | 217 | List<Instruction> instructions = new ArrayList<>(); |
| 218 | instructions.add(Instructions.createOutput(port.number())); |
| 219 | |
tom | 9a693fd | 2014-10-03 11:32:19 -0700 | [diff] [blame] | 220 | TrafficTreatment treatment = DefaultTrafficTreatment.builder() |
Pavlin Radoslavov | 89edb54 | 2015-02-23 13:50:29 -0800 | [diff] [blame] | 221 | .setOutput(port.number()) |
| 222 | .build(); |
Jonathan Hart | 87fbbad | 2014-09-23 08:43:50 -0700 | [diff] [blame] | 223 | |
| 224 | OutboundPacket outboundPacket = |
Pavlin Radoslavov | 89edb54 | 2015-02-23 13:50:29 -0800 | [diff] [blame] | 225 | new DefaultOutboundPacket(deviceId, treatment, |
| 226 | ByteBuffer.wrap(probePacket.serialize())); |
Jonathan Hart | 87fbbad | 2014-09-23 08:43:50 -0700 | [diff] [blame] | 227 | |
| 228 | packetService.emit(outboundPacket); |
| 229 | } |
| 230 | |
Jonathan Hart | 70da512 | 2014-10-01 16:37:42 -0700 | [diff] [blame] | 231 | private Ethernet buildArpRequest(IpAddress targetIp, IpAddress sourceIp, |
Pavlin Radoslavov | 89edb54 | 2015-02-23 13:50:29 -0800 | [diff] [blame] | 232 | MacAddress sourceMac, VlanId vlan) { |
Jonathan Hart | 87fbbad | 2014-09-23 08:43:50 -0700 | [diff] [blame] | 233 | |
| 234 | ARP arp = new ARP(); |
| 235 | arp.setHardwareType(ARP.HW_TYPE_ETHERNET) |
Jonathan Hart | 70da512 | 2014-10-01 16:37:42 -0700 | [diff] [blame] | 236 | .setHardwareAddressLength((byte) Ethernet.DATALAYER_ADDRESS_LENGTH) |
| 237 | .setProtocolType(ARP.PROTO_TYPE_IP) |
Pavlin Radoslavov | 52307e6 | 2014-10-29 15:07:37 -0700 | [diff] [blame] | 238 | .setProtocolAddressLength((byte) IpAddress.INET_BYTE_LENGTH) |
Jonathan Hart | 70da512 | 2014-10-01 16:37:42 -0700 | [diff] [blame] | 239 | .setOpCode(ARP.OP_REQUEST); |
Jonathan Hart | 87fbbad | 2014-09-23 08:43:50 -0700 | [diff] [blame] | 240 | |
Yuta HIGUCHI | 3e848a8 | 2014-11-02 20:19:42 -0800 | [diff] [blame] | 241 | arp.setSenderHardwareAddress(sourceMac.toBytes()) |
Jonathan Hart | 70da512 | 2014-10-01 16:37:42 -0700 | [diff] [blame] | 242 | .setSenderProtocolAddress(sourceIp.toOctets()) |
Yuta HIGUCHI | 3e848a8 | 2014-11-02 20:19:42 -0800 | [diff] [blame] | 243 | .setTargetHardwareAddress(ZERO_MAC_ADDRESS) |
Jonathan Hart | 70da512 | 2014-10-01 16:37:42 -0700 | [diff] [blame] | 244 | .setTargetProtocolAddress(targetIp.toOctets()); |
Jonathan Hart | 87fbbad | 2014-09-23 08:43:50 -0700 | [diff] [blame] | 245 | |
| 246 | Ethernet ethernet = new Ethernet(); |
| 247 | ethernet.setEtherType(Ethernet.TYPE_ARP) |
Yuta HIGUCHI | 3e848a8 | 2014-11-02 20:19:42 -0800 | [diff] [blame] | 248 | .setDestinationMACAddress(MacAddress.BROADCAST) |
| 249 | .setSourceMACAddress(sourceMac) |
Jonathan Hart | 70da512 | 2014-10-01 16:37:42 -0700 | [diff] [blame] | 250 | .setPayload(arp); |
Jonathan Hart | 87fbbad | 2014-09-23 08:43:50 -0700 | [diff] [blame] | 251 | |
Jonathan Hart | 6cd2f35 | 2015-01-13 17:44:45 -0800 | [diff] [blame] | 252 | if (!vlan.equals(VlanId.NONE)) { |
| 253 | ethernet.setVlanID(vlan.toShort()); |
| 254 | } |
| 255 | |
Jonathan Hart | 87fbbad | 2014-09-23 08:43:50 -0700 | [diff] [blame] | 256 | return ethernet; |
Jonathan Hart | fca736c | 2014-09-19 17:26:59 -0700 | [diff] [blame] | 257 | } |
Pavlin Radoslavov | 89edb54 | 2015-02-23 13:50:29 -0800 | [diff] [blame] | 258 | |
| 259 | private Ethernet buildNdpRequest(IpAddress targetIp, IpAddress sourceIp, |
| 260 | MacAddress sourceMac, VlanId vlan) { |
| 261 | |
| 262 | // Create the Ethernet packet |
| 263 | Ethernet ethernet = new Ethernet(); |
| 264 | ethernet.setEtherType(Ethernet.TYPE_IPV6) |
| 265 | .setDestinationMACAddress(MacAddress.BROADCAST) |
| 266 | .setSourceMACAddress(sourceMac); |
| 267 | if (!vlan.equals(VlanId.NONE)) { |
| 268 | ethernet.setVlanID(vlan.toShort()); |
| 269 | } |
| 270 | |
| 271 | // |
| 272 | // Create the IPv6 packet |
| 273 | // |
| 274 | // TODO: The destination IP address should be the |
| 275 | // solicited-node multicast address |
| 276 | IPv6 ipv6 = new IPv6(); |
| 277 | ipv6.setSourceAddress(sourceIp.toOctets()); |
| 278 | ipv6.setDestinationAddress(targetIp.toOctets()); |
| 279 | ipv6.setHopLimit((byte) 255); |
| 280 | |
| 281 | // Create the ICMPv6 packet |
| 282 | ICMP6 icmp6 = new ICMP6(); |
| 283 | icmp6.setIcmpType(ICMP6.NEIGHBOR_SOLICITATION); |
| 284 | icmp6.setIcmpCode((byte) 0); |
| 285 | |
| 286 | // Create the Neighbor Solication packet |
| 287 | NeighborSolicitation ns = new NeighborSolicitation(); |
| 288 | ns.setTargetAddress(targetIp.toOctets()); |
| 289 | ns.addOption(NeighborDiscoveryOptions.TYPE_SOURCE_LL_ADDRESS, |
| 290 | sourceMac.toBytes()); |
| 291 | |
| 292 | icmp6.setPayload(ns); |
| 293 | ipv6.setPayload(icmp6); |
| 294 | ethernet.setPayload(ipv6); |
| 295 | |
| 296 | return ethernet; |
| 297 | } |
Jonathan Hart | fca736c | 2014-09-19 17:26:59 -0700 | [diff] [blame] | 298 | } |