Jonathan Hart | d300325 | 2013-11-15 09:44:46 -0800 | [diff] [blame] | 1 | package net.onrc.onos.ofcontroller.proxyarp; |
| 2 | |
| 3 | import java.io.Serializable; |
| 4 | import java.net.InetAddress; |
pingping-lin | 017a892 | 2013-12-11 11:15:33 +0800 | [diff] [blame] | 5 | import net.floodlightcontroller.util.MACAddress; |
Jonathan Hart | d300325 | 2013-11-15 09:44:46 -0800 | [diff] [blame] | 6 | |
| 7 | public class ArpMessage implements Serializable { |
| 8 | |
| 9 | /** |
| 10 | * |
| 11 | */ |
| 12 | private static final long serialVersionUID = 1L; |
| 13 | |
| 14 | private final Type type; |
| 15 | private final InetAddress forAddress; |
| 16 | private final byte[] packetData; |
| 17 | |
pingping-lin | 017a892 | 2013-12-11 11:15:33 +0800 | [diff] [blame] | 18 | //ARP reply message needs MAC info |
pingping-lin | b8757bf | 2013-12-13 01:48:58 +0800 | [diff] [blame] | 19 | private final MACAddress mac; |
| 20 | //only send the ARP request message to the device attachment needs the attachment switch and port. |
| 21 | private final long outSwitch; |
| 22 | private final short outPort; |
pingping-lin | 017a892 | 2013-12-11 11:15:33 +0800 | [diff] [blame] | 23 | |
pingping-lin | a2c8d9c | 2013-12-13 05:01:48 +0800 | [diff] [blame^] | 24 | |
| 25 | |
Jonathan Hart | d300325 | 2013-11-15 09:44:46 -0800 | [diff] [blame] | 26 | public enum Type { |
| 27 | REQUEST, |
| 28 | REPLY |
| 29 | } |
| 30 | |
| 31 | private ArpMessage(Type type, InetAddress address, byte[] eth) { |
| 32 | // TODO Auto-generated constructor stub |
| 33 | this.type = type; |
| 34 | this.forAddress = address; |
| 35 | this.packetData = eth; |
pingping-lin | b8757bf | 2013-12-13 01:48:58 +0800 | [diff] [blame] | 36 | this.mac = null; |
| 37 | this.outSwitch = -1; |
| 38 | this.outPort = -1; |
Jonathan Hart | d300325 | 2013-11-15 09:44:46 -0800 | [diff] [blame] | 39 | } |
| 40 | |
| 41 | private ArpMessage(Type type, InetAddress address) { |
| 42 | this.type = type; |
| 43 | this.forAddress = address; |
| 44 | this.packetData = null; |
pingping-lin | b8757bf | 2013-12-13 01:48:58 +0800 | [diff] [blame] | 45 | this.mac = null; |
| 46 | this.outSwitch = -1; |
| 47 | this.outPort = -1; |
| 48 | |
Jonathan Hart | d300325 | 2013-11-15 09:44:46 -0800 | [diff] [blame] | 49 | } |
pingping-lin | 017a892 | 2013-12-11 11:15:33 +0800 | [diff] [blame] | 50 | // the ARP reply message with MAC |
| 51 | private ArpMessage(Type type, InetAddress address, MACAddress mac) { |
| 52 | this.type = type; |
| 53 | this.forAddress = address; |
| 54 | this.packetData = null; |
pingping-lin | b8757bf | 2013-12-13 01:48:58 +0800 | [diff] [blame] | 55 | this.mac = mac; |
| 56 | this.outSwitch = -1; |
| 57 | this.outPort = -1; |
pingping-lin | 017a892 | 2013-12-11 11:15:33 +0800 | [diff] [blame] | 58 | } |
Jonathan Hart | d300325 | 2013-11-15 09:44:46 -0800 | [diff] [blame] | 59 | |
pingping-lin | 017a892 | 2013-12-11 11:15:33 +0800 | [diff] [blame] | 60 | // construct ARP request message with attachment switch and port |
| 61 | private ArpMessage(Type type, InetAddress address, byte[] arpRequest, |
| 62 | long outSwitch, short outPort) { |
| 63 | this.type = type; |
| 64 | this.forAddress = address; |
pingping-lin | b8757bf | 2013-12-13 01:48:58 +0800 | [diff] [blame] | 65 | this.packetData = arpRequest; |
| 66 | this.mac = null; |
| 67 | this.outSwitch = outSwitch; |
| 68 | this.outPort = outPort; |
pingping-lin | 017a892 | 2013-12-11 11:15:33 +0800 | [diff] [blame] | 69 | } |
| 70 | |
Jonathan Hart | d300325 | 2013-11-15 09:44:46 -0800 | [diff] [blame] | 71 | public static ArpMessage newRequest(InetAddress forAddress, byte[] arpRequest) { |
| 72 | return new ArpMessage(Type.REQUEST, forAddress, arpRequest); |
| 73 | } |
| 74 | |
| 75 | public static ArpMessage newReply(InetAddress forAddress) { |
| 76 | return new ArpMessage(Type.REPLY, forAddress); |
| 77 | } |
pingping-lin | 017a892 | 2013-12-11 11:15:33 +0800 | [diff] [blame] | 78 | //ARP reply message with MAC |
| 79 | public static ArpMessage newReply(InetAddress forAddress, MACAddress mac) { |
| 80 | return new ArpMessage(Type.REPLY, forAddress, mac); |
pingping-lin | b8757bf | 2013-12-13 01:48:58 +0800 | [diff] [blame] | 81 | |
pingping-lin | 017a892 | 2013-12-11 11:15:33 +0800 | [diff] [blame] | 82 | } |
| 83 | //ARP reqsuest message with attachment switch and port |
| 84 | public static ArpMessage newRequest(InetAddress forAddress, byte[] arpRequest, long outSwitch, short outPort ) { |
| 85 | return new ArpMessage(Type.REQUEST, forAddress, arpRequest, outSwitch, outPort); |
pingping-lin | b8757bf | 2013-12-13 01:48:58 +0800 | [diff] [blame] | 86 | |
pingping-lin | 017a892 | 2013-12-11 11:15:33 +0800 | [diff] [blame] | 87 | } |
Jonathan Hart | d300325 | 2013-11-15 09:44:46 -0800 | [diff] [blame] | 88 | |
| 89 | public Type getType() { |
| 90 | return type; |
| 91 | } |
| 92 | |
| 93 | public InetAddress getAddress() { |
| 94 | return forAddress; |
| 95 | } |
| 96 | |
| 97 | public byte[] getPacket() { |
| 98 | return packetData; |
| 99 | } |
pingping-lin | 017a892 | 2013-12-11 11:15:33 +0800 | [diff] [blame] | 100 | public MACAddress getMAC() { |
| 101 | return mac; |
| 102 | } |
| 103 | |
| 104 | public long getOutSwitch() { |
| 105 | return outSwitch; |
| 106 | } |
| 107 | |
pingping-lin | 017a892 | 2013-12-11 11:15:33 +0800 | [diff] [blame] | 108 | public short getOutPort() { |
| 109 | return outPort; |
| 110 | } |
| 111 | |
Jonathan Hart | d300325 | 2013-11-15 09:44:46 -0800 | [diff] [blame] | 112 | } |