Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -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 | 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.IPv6; |
Jonathan Hart | 4cb3988 | 2015-08-12 23:50:55 -0400 | [diff] [blame] | 23 | import org.onlab.packet.IpAddress; |
Jonathan Hart | 6cd2f35 | 2015-01-13 17:44:45 -0800 | [diff] [blame] | 24 | import org.onlab.packet.MacAddress; |
| 25 | import org.onlab.packet.VlanId; |
Pavlin Radoslavov | 89edb54 | 2015-02-23 13:50:29 -0800 | [diff] [blame] | 26 | import org.onlab.packet.ndp.NeighborSolicitation; |
Jonathan Hart | 6cd2f35 | 2015-01-13 17:44:45 -0800 | [diff] [blame] | 27 | import org.onlab.util.Timer; |
Jonathan Hart | 4cb3988 | 2015-08-12 23:50:55 -0400 | [diff] [blame] | 28 | import org.onosproject.incubator.net.intf.Interface; |
| 29 | import org.onosproject.incubator.net.intf.InterfaceService; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 30 | import org.onosproject.net.ConnectPoint; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 31 | import org.onosproject.net.Host; |
Jonathan Hart | fb32a6e | 2015-09-01 12:12:14 +0200 | [diff] [blame] | 32 | import org.onosproject.net.edge.EdgePortService; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 33 | import org.onosproject.net.flow.DefaultTrafficTreatment; |
| 34 | import org.onosproject.net.flow.TrafficTreatment; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 35 | import org.onosproject.net.host.HostProvider; |
| 36 | import org.onosproject.net.host.InterfaceIpAddress; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 37 | import org.onosproject.net.packet.DefaultOutboundPacket; |
| 38 | import org.onosproject.net.packet.OutboundPacket; |
| 39 | import org.onosproject.net.packet.PacketService; |
| 40 | import org.onosproject.net.provider.ProviderId; |
Jonathan Hart | fb32a6e | 2015-09-01 12:12:14 +0200 | [diff] [blame] | 41 | import org.slf4j.Logger; |
| 42 | import org.slf4j.LoggerFactory; |
Jonathan Hart | 6cd2f35 | 2015-01-13 17:44:45 -0800 | [diff] [blame] | 43 | |
| 44 | import java.nio.ByteBuffer; |
Jonathan Hart | 6cd2f35 | 2015-01-13 17:44:45 -0800 | [diff] [blame] | 45 | import java.util.Collections; |
Jonathan Hart | 6cd2f35 | 2015-01-13 17:44:45 -0800 | [diff] [blame] | 46 | import java.util.Set; |
| 47 | import java.util.concurrent.ConcurrentHashMap; |
| 48 | import java.util.concurrent.ConcurrentMap; |
| 49 | import java.util.concurrent.TimeUnit; |
Jonathan Hart | fca736c | 2014-09-19 17:26:59 -0700 | [diff] [blame] | 50 | |
Jonathan Hart | 87fbbad | 2014-09-23 08:43:50 -0700 | [diff] [blame] | 51 | /** |
| 52 | * Monitors hosts on the dataplane to detect changes in host data. |
Thomas Vachuska | 4b42077 | 2014-10-30 16:46:17 -0700 | [diff] [blame] | 53 | * <p> |
Jonathan Hart | 87fbbad | 2014-09-23 08:43:50 -0700 | [diff] [blame] | 54 | * The HostMonitor can monitor hosts that have already been detected for |
| 55 | * changes. At an application's request, it can also monitor and actively |
| 56 | * 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] | 57 | * </p> |
Jonathan Hart | 87fbbad | 2014-09-23 08:43:50 -0700 | [diff] [blame] | 58 | */ |
tom | 202175a | 2014-09-19 19:00:11 -0700 | [diff] [blame] | 59 | public class HostMonitor implements TimerTask { |
Jonathan Hart | fb32a6e | 2015-09-01 12:12:14 +0200 | [diff] [blame] | 60 | |
| 61 | private Logger log = LoggerFactory.getLogger(getClass()); |
| 62 | |
Jonathan Hart | 70da512 | 2014-10-01 16:37:42 -0700 | [diff] [blame] | 63 | private PacketService packetService; |
| 64 | private HostManager hostManager; |
Jonathan Hart | 4cb3988 | 2015-08-12 23:50:55 -0400 | [diff] [blame] | 65 | private InterfaceService interfaceService; |
Jonathan Hart | fb32a6e | 2015-09-01 12:12:14 +0200 | [diff] [blame] | 66 | private EdgePortService edgePortService; |
Jonathan Hart | fca736c | 2014-09-19 17:26:59 -0700 | [diff] [blame] | 67 | |
Jonathan Hart | 87fbbad | 2014-09-23 08:43:50 -0700 | [diff] [blame] | 68 | private final Set<IpAddress> monitoredAddresses; |
Jonathan Hart | fca736c | 2014-09-19 17:26:59 -0700 | [diff] [blame] | 69 | |
Jonathan Hart | 34ed2fd | 2014-10-02 19:08:55 -0700 | [diff] [blame] | 70 | private final ConcurrentMap<ProviderId, HostProvider> hostProviders; |
Jonathan Hart | 70da512 | 2014-10-01 16:37:42 -0700 | [diff] [blame] | 71 | |
Jonathan Hart | 34ed2fd | 2014-10-02 19:08:55 -0700 | [diff] [blame] | 72 | private static final long DEFAULT_PROBE_RATE = 30000; // milliseconds |
Yuta HIGUCHI | 3e848a8 | 2014-11-02 20:19:42 -0800 | [diff] [blame] | 73 | private static final byte[] ZERO_MAC_ADDRESS = MacAddress.ZERO.toBytes(); |
Jonathan Hart | 34ed2fd | 2014-10-02 19:08:55 -0700 | [diff] [blame] | 74 | private long probeRate = DEFAULT_PROBE_RATE; |
Jonathan Hart | fca736c | 2014-09-19 17:26:59 -0700 | [diff] [blame] | 75 | |
Jonathan Hart | 8f6f1ea | 2014-10-03 16:05:19 -0700 | [diff] [blame] | 76 | private Timeout timeout; |
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 | /** |
| 79 | * Creates a new host monitor. |
| 80 | * |
Jonathan Hart | 8f6f1ea | 2014-10-03 16:05:19 -0700 | [diff] [blame] | 81 | * @param packetService packet service used to send packets on the data plane |
Jonathan Hart | b4758a9 | 2014-09-24 10:46:45 -0700 | [diff] [blame] | 82 | * @param hostManager host manager used to look up host information and |
| 83 | * probe existing hosts |
Jonathan Hart | 4cb3988 | 2015-08-12 23:50:55 -0400 | [diff] [blame] | 84 | * @param interfaceService interface service for interface information |
Thomas Vachuska | 0ae4560 | 2015-09-22 17:06:19 -0700 | [diff] [blame] | 85 | * @param edgePortService edge port service |
Jonathan Hart | 8f6f1ea | 2014-10-03 16:05:19 -0700 | [diff] [blame] | 86 | */ |
Jonathan Hart | 4cb3988 | 2015-08-12 23:50:55 -0400 | [diff] [blame] | 87 | public HostMonitor(PacketService packetService, HostManager hostManager, |
Jonathan Hart | fb32a6e | 2015-09-01 12:12:14 +0200 | [diff] [blame] | 88 | InterfaceService interfaceService, |
| 89 | EdgePortService edgePortService) { |
Jonathan Hart | 70da512 | 2014-10-01 16:37:42 -0700 | [diff] [blame] | 90 | |
Jonathan Hart | 87fbbad | 2014-09-23 08:43:50 -0700 | [diff] [blame] | 91 | this.packetService = packetService; |
Jonathan Hart | b4758a9 | 2014-09-24 10:46:45 -0700 | [diff] [blame] | 92 | this.hostManager = hostManager; |
Jonathan Hart | 4cb3988 | 2015-08-12 23:50:55 -0400 | [diff] [blame] | 93 | this.interfaceService = interfaceService; |
Jonathan Hart | fb32a6e | 2015-09-01 12:12:14 +0200 | [diff] [blame] | 94 | this.edgePortService = edgePortService; |
Jonathan Hart | fca736c | 2014-09-19 17:26:59 -0700 | [diff] [blame] | 95 | |
Jonathan Hart | 4cb3988 | 2015-08-12 23:50:55 -0400 | [diff] [blame] | 96 | monitoredAddresses = Collections.newSetFromMap(new ConcurrentHashMap<>()); |
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); |
Jonathan Hart | 78613d2 | 2016-07-27 11:25:29 -0700 | [diff] [blame] | 108 | probe(ip); |
Jonathan Hart | fca736c | 2014-09-19 17:26:59 -0700 | [diff] [blame] | 109 | } |
| 110 | |
Jonathan Hart | 8f6f1ea | 2014-10-03 16:05:19 -0700 | [diff] [blame] | 111 | /** |
| 112 | * Stops monitoring the given IP address. |
| 113 | * |
| 114 | * @param ip IP address to stop monitoring on |
| 115 | */ |
Jonathan Hart | 70da512 | 2014-10-01 16:37:42 -0700 | [diff] [blame] | 116 | void stopMonitoring(IpAddress ip) { |
Jonathan Hart | fca736c | 2014-09-19 17:26:59 -0700 | [diff] [blame] | 117 | monitoredAddresses.remove(ip); |
| 118 | } |
| 119 | |
Jonathan Hart | 8f6f1ea | 2014-10-03 16:05:19 -0700 | [diff] [blame] | 120 | /** |
| 121 | * Starts the host monitor. Does nothing if the monitor is already running. |
| 122 | */ |
| 123 | void start() { |
| 124 | synchronized (this) { |
| 125 | if (timeout == null) { |
| 126 | timeout = Timer.getTimer().newTimeout(this, 0, TimeUnit.MILLISECONDS); |
| 127 | } |
| 128 | } |
Jonathan Hart | fca736c | 2014-09-19 17:26:59 -0700 | [diff] [blame] | 129 | } |
| 130 | |
Jonathan Hart | 8f6f1ea | 2014-10-03 16:05:19 -0700 | [diff] [blame] | 131 | /** |
| 132 | * Stops the host monitor. |
| 133 | */ |
| 134 | void shutdown() { |
| 135 | synchronized (this) { |
| 136 | timeout.cancel(); |
| 137 | timeout = null; |
| 138 | } |
| 139 | } |
| 140 | |
sdn | 94b0015 | 2016-08-30 02:12:32 -0700 | [diff] [blame] | 141 | /* |
| 142 | * Sets the probe rate. |
| 143 | */ |
| 144 | void setProbeRate(long probeRate) { |
| 145 | this.probeRate = probeRate; |
| 146 | } |
| 147 | |
Jonathan Hart | 8f6f1ea | 2014-10-03 16:05:19 -0700 | [diff] [blame] | 148 | /** |
| 149 | * Registers a host provider with the host monitor. The monitor can use the |
| 150 | * provider to probe hosts. |
| 151 | * |
| 152 | * @param provider the host provider to register |
| 153 | */ |
Jonathan Hart | 70da512 | 2014-10-01 16:37:42 -0700 | [diff] [blame] | 154 | void registerHostProvider(HostProvider provider) { |
| 155 | hostProviders.put(provider.id(), provider); |
| 156 | } |
| 157 | |
Jonathan Hart | fca736c | 2014-09-19 17:26:59 -0700 | [diff] [blame] | 158 | @Override |
| 159 | public void run(Timeout timeout) throws Exception { |
Jonathan Hart | 78613d2 | 2016-07-27 11:25:29 -0700 | [diff] [blame] | 160 | monitoredAddresses.forEach(this::probe); |
Jonathan Hart | fca736c | 2014-09-19 17:26:59 -0700 | [diff] [blame] | 161 | |
Satish K | e9d748f | 2015-11-24 19:05:01 +0530 | [diff] [blame] | 162 | synchronized (this) { |
| 163 | this.timeout = Timer.getTimer().newTimeout(this, probeRate, TimeUnit.MILLISECONDS); |
| 164 | } |
Jonathan Hart | fca736c | 2014-09-19 17:26:59 -0700 | [diff] [blame] | 165 | } |
| 166 | |
Jonathan Hart | 78613d2 | 2016-07-27 11:25:29 -0700 | [diff] [blame] | 167 | private void probe(IpAddress ip) { |
| 168 | Set<Host> hosts = hostManager.getHostsByIp(ip); |
| 169 | |
| 170 | if (hosts.isEmpty()) { |
| 171 | sendRequest(ip); |
| 172 | } else { |
| 173 | for (Host host : hosts) { |
| 174 | HostProvider provider = hostProviders.get(host.providerId()); |
| 175 | if (provider == null) { |
| 176 | hostProviders.remove(host.providerId(), null); |
| 177 | } else { |
| 178 | provider.triggerProbe(host); |
| 179 | } |
| 180 | } |
| 181 | } |
| 182 | } |
| 183 | |
Jonathan Hart | fca736c | 2014-09-19 17:26:59 -0700 | [diff] [blame] | 184 | /** |
Jonathan Hart | 39ee648 | 2015-08-31 16:00:19 +0200 | [diff] [blame] | 185 | * Sends an ARP or NDP request for the given IP address. |
Jonathan Hart | fca736c | 2014-09-19 17:26:59 -0700 | [diff] [blame] | 186 | * |
Pavlin Radoslavov | 89edb54 | 2015-02-23 13:50:29 -0800 | [diff] [blame] | 187 | * @param targetIp IP address to send the request for |
Jonathan Hart | fca736c | 2014-09-19 17:26:59 -0700 | [diff] [blame] | 188 | */ |
Jonathan Hart | 39ee648 | 2015-08-31 16:00:19 +0200 | [diff] [blame] | 189 | private void sendRequest(IpAddress targetIp) { |
Jonathan Hart | 4cb3988 | 2015-08-12 23:50:55 -0400 | [diff] [blame] | 190 | Interface intf = interfaceService.getMatchingInterface(targetIp); |
Jonathan Hart | 87fbbad | 2014-09-23 08:43:50 -0700 | [diff] [blame] | 191 | |
Jonathan Hart | 4cb3988 | 2015-08-12 23:50:55 -0400 | [diff] [blame] | 192 | if (intf == null) { |
| 193 | return; |
| 194 | } |
| 195 | |
Jonathan Hart | fb32a6e | 2015-09-01 12:12:14 +0200 | [diff] [blame] | 196 | if (!edgePortService.isEdgePoint(intf.connectPoint())) { |
| 197 | log.warn("Attempt to send probe out non-edge port: {}", intf); |
| 198 | return; |
| 199 | } |
| 200 | |
Yuta HIGUCHI | e50a56d | 2016-07-21 16:03:04 -0700 | [diff] [blame] | 201 | for (InterfaceIpAddress ia : intf.ipAddressesList()) { |
Jonathan Hart | 4cb3988 | 2015-08-12 23:50:55 -0400 | [diff] [blame] | 202 | if (ia.subnetAddress().contains(targetIp)) { |
Jonathan Hart | 39ee648 | 2015-08-31 16:00:19 +0200 | [diff] [blame] | 203 | sendProbe(intf.connectPoint(), targetIp, ia.ipAddress(), |
Jonathan Hart | 4cb3988 | 2015-08-12 23:50:55 -0400 | [diff] [blame] | 204 | intf.mac(), intf.vlan()); |
Jonathan Hart | fca736c | 2014-09-19 17:26:59 -0700 | [diff] [blame] | 205 | } |
Jonathan Hart | 87fbbad | 2014-09-23 08:43:50 -0700 | [diff] [blame] | 206 | } |
Jonathan Hart | fca736c | 2014-09-19 17:26:59 -0700 | [diff] [blame] | 207 | } |
| 208 | |
Jonathan Hart | 39ee648 | 2015-08-31 16:00:19 +0200 | [diff] [blame] | 209 | private void sendProbe(ConnectPoint connectPoint, |
| 210 | IpAddress targetIp, |
| 211 | IpAddress sourceIp, MacAddress sourceMac, |
| 212 | VlanId vlan) { |
Pier Ventre | 78e73f6 | 2016-12-02 19:59:28 -0800 | [diff] [blame] | 213 | Ethernet probePacket; |
Pavlin Radoslavov | 89edb54 | 2015-02-23 13:50:29 -0800 | [diff] [blame] | 214 | |
Pavlin Radoslavov | 87dd930 | 2015-03-10 13:53:24 -0700 | [diff] [blame] | 215 | if (targetIp.isIp4()) { |
Pavlin Radoslavov | 89edb54 | 2015-02-23 13:50:29 -0800 | [diff] [blame] | 216 | // IPv4: Use ARP |
Jonathan Hart | 39ee648 | 2015-08-31 16:00:19 +0200 | [diff] [blame] | 217 | probePacket = buildArpRequest(targetIp, sourceIp, sourceMac, vlan); |
Pavlin Radoslavov | 89edb54 | 2015-02-23 13:50:29 -0800 | [diff] [blame] | 218 | } else { |
Pier Ventre | 78e73f6 | 2016-12-02 19:59:28 -0800 | [diff] [blame] | 219 | /* |
| 220 | * IPv6: Use Neighbor Discovery. According to the NDP protocol, |
| 221 | * we should use the solicitation node address as IPv6 destination |
| 222 | * and the multicast mac address as Ethernet destination. |
| 223 | */ |
Pier Luigi | 37b687b | 2017-01-16 22:46:33 -0800 | [diff] [blame] | 224 | byte[] destIp = IPv6.getSolicitNodeAddress(targetIp.toOctets()); |
Pier Ventre | 78e73f6 | 2016-12-02 19:59:28 -0800 | [diff] [blame] | 225 | probePacket = NeighborSolicitation.buildNdpSolicit( |
| 226 | targetIp.toOctets(), |
| 227 | sourceIp.toOctets(), |
| 228 | destIp, |
| 229 | sourceMac.toBytes(), |
Pier Luigi | 37b687b | 2017-01-16 22:46:33 -0800 | [diff] [blame] | 230 | IPv6.getMCastMacAddress(destIp), |
Pier Ventre | 78e73f6 | 2016-12-02 19:59:28 -0800 | [diff] [blame] | 231 | vlan |
| 232 | ); |
| 233 | } |
| 234 | |
| 235 | if (probePacket == null) { |
| 236 | log.warn("Not able to build the probe packet"); |
| 237 | return; |
Pavlin Radoslavov | 89edb54 | 2015-02-23 13:50:29 -0800 | [diff] [blame] | 238 | } |
Jonathan Hart | fca736c | 2014-09-19 17:26:59 -0700 | [diff] [blame] | 239 | |
tom | 9a693fd | 2014-10-03 11:32:19 -0700 | [diff] [blame] | 240 | TrafficTreatment treatment = DefaultTrafficTreatment.builder() |
Jonathan Hart | 4cb3988 | 2015-08-12 23:50:55 -0400 | [diff] [blame] | 241 | .setOutput(connectPoint.port()) |
Pavlin Radoslavov | 89edb54 | 2015-02-23 13:50:29 -0800 | [diff] [blame] | 242 | .build(); |
Jonathan Hart | 87fbbad | 2014-09-23 08:43:50 -0700 | [diff] [blame] | 243 | |
| 244 | OutboundPacket outboundPacket = |
Jonathan Hart | 4cb3988 | 2015-08-12 23:50:55 -0400 | [diff] [blame] | 245 | new DefaultOutboundPacket(connectPoint.deviceId(), treatment, |
Pavlin Radoslavov | 89edb54 | 2015-02-23 13:50:29 -0800 | [diff] [blame] | 246 | ByteBuffer.wrap(probePacket.serialize())); |
Jonathan Hart | 87fbbad | 2014-09-23 08:43:50 -0700 | [diff] [blame] | 247 | |
| 248 | packetService.emit(outboundPacket); |
| 249 | } |
| 250 | |
Jonathan Hart | 70da512 | 2014-10-01 16:37:42 -0700 | [diff] [blame] | 251 | private Ethernet buildArpRequest(IpAddress targetIp, IpAddress sourceIp, |
Pavlin Radoslavov | 89edb54 | 2015-02-23 13:50:29 -0800 | [diff] [blame] | 252 | MacAddress sourceMac, VlanId vlan) { |
Jonathan Hart | 87fbbad | 2014-09-23 08:43:50 -0700 | [diff] [blame] | 253 | |
| 254 | ARP arp = new ARP(); |
| 255 | arp.setHardwareType(ARP.HW_TYPE_ETHERNET) |
Jonathan Hart | 70da512 | 2014-10-01 16:37:42 -0700 | [diff] [blame] | 256 | .setHardwareAddressLength((byte) Ethernet.DATALAYER_ADDRESS_LENGTH) |
| 257 | .setProtocolType(ARP.PROTO_TYPE_IP) |
Pavlin Radoslavov | 52307e6 | 2014-10-29 15:07:37 -0700 | [diff] [blame] | 258 | .setProtocolAddressLength((byte) IpAddress.INET_BYTE_LENGTH) |
Jonathan Hart | 70da512 | 2014-10-01 16:37:42 -0700 | [diff] [blame] | 259 | .setOpCode(ARP.OP_REQUEST); |
Jonathan Hart | 87fbbad | 2014-09-23 08:43:50 -0700 | [diff] [blame] | 260 | |
Yuta HIGUCHI | 3e848a8 | 2014-11-02 20:19:42 -0800 | [diff] [blame] | 261 | arp.setSenderHardwareAddress(sourceMac.toBytes()) |
Jonathan Hart | 70da512 | 2014-10-01 16:37:42 -0700 | [diff] [blame] | 262 | .setSenderProtocolAddress(sourceIp.toOctets()) |
Yuta HIGUCHI | 3e848a8 | 2014-11-02 20:19:42 -0800 | [diff] [blame] | 263 | .setTargetHardwareAddress(ZERO_MAC_ADDRESS) |
Jonathan Hart | 70da512 | 2014-10-01 16:37:42 -0700 | [diff] [blame] | 264 | .setTargetProtocolAddress(targetIp.toOctets()); |
Jonathan Hart | 87fbbad | 2014-09-23 08:43:50 -0700 | [diff] [blame] | 265 | |
| 266 | Ethernet ethernet = new Ethernet(); |
| 267 | ethernet.setEtherType(Ethernet.TYPE_ARP) |
Yuta HIGUCHI | 3e848a8 | 2014-11-02 20:19:42 -0800 | [diff] [blame] | 268 | .setDestinationMACAddress(MacAddress.BROADCAST) |
| 269 | .setSourceMACAddress(sourceMac) |
Jonathan Hart | 70da512 | 2014-10-01 16:37:42 -0700 | [diff] [blame] | 270 | .setPayload(arp); |
Jonathan Hart | 87fbbad | 2014-09-23 08:43:50 -0700 | [diff] [blame] | 271 | |
Jonathan Hart | 6cd2f35 | 2015-01-13 17:44:45 -0800 | [diff] [blame] | 272 | if (!vlan.equals(VlanId.NONE)) { |
| 273 | ethernet.setVlanID(vlan.toShort()); |
| 274 | } |
| 275 | |
alshabib | af734ff | 2015-07-01 16:35:26 -0700 | [diff] [blame] | 276 | ethernet.setPad(true); |
| 277 | |
Jonathan Hart | 87fbbad | 2014-09-23 08:43:50 -0700 | [diff] [blame] | 278 | return ethernet; |
Jonathan Hart | fca736c | 2014-09-19 17:26:59 -0700 | [diff] [blame] | 279 | } |
Pavlin Radoslavov | 89edb54 | 2015-02-23 13:50:29 -0800 | [diff] [blame] | 280 | |
Jonathan Hart | fca736c | 2014-09-19 17:26:59 -0700 | [diff] [blame] | 281 | } |