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 | |
Jonathan Hart | f9bd98d | 2013-12-13 11:40:55 -0800 | [diff] [blame] | 7 | // TODO This is getting very messy!!! Needs refactoring |
Jonathan Hart | d300325 | 2013-11-15 09:44:46 -0800 | [diff] [blame] | 8 | public class ArpMessage implements Serializable { |
| 9 | |
Jonathan Hart | d300325 | 2013-11-15 09:44:46 -0800 | [diff] [blame] | 10 | private static final long serialVersionUID = 1L; |
| 11 | |
| 12 | private final Type type; |
| 13 | private final InetAddress forAddress; |
| 14 | private final byte[] packetData; |
| 15 | |
Jonathan Hart | f9bd98d | 2013-12-13 11:40:55 -0800 | [diff] [blame] | 16 | // ARP reply message needs MAC info |
pingping-lin | b8757bf | 2013-12-13 01:48:58 +0800 | [diff] [blame] | 17 | private final MACAddress mac; |
Jonathan Hart | f9bd98d | 2013-12-13 11:40:55 -0800 | [diff] [blame] | 18 | // Only send the ARP request message to the device attachment needs the |
| 19 | // attachment switch and port. |
pingping-lin | b8757bf | 2013-12-13 01:48:58 +0800 | [diff] [blame] | 20 | private final long outSwitch; |
| 21 | private final short outPort; |
pingping-lin | 017a892 | 2013-12-11 11:15:33 +0800 | [diff] [blame] | 22 | |
Jonathan Hart | f9bd98d | 2013-12-13 11:40:55 -0800 | [diff] [blame] | 23 | private final long inSwitch; |
| 24 | private final short inPort; |
pingping-lin | a2c8d9c | 2013-12-13 05:01:48 +0800 | [diff] [blame] | 25 | |
Jonathan Hart | d300325 | 2013-11-15 09:44:46 -0800 | [diff] [blame] | 26 | public enum Type { |
| 27 | REQUEST, |
| 28 | REPLY |
| 29 | } |
| 30 | |
Jonathan Hart | f9bd98d | 2013-12-13 11:40:55 -0800 | [diff] [blame] | 31 | private ArpMessage(Type type, InetAddress address, byte[] eth, |
| 32 | long outSwitch, short outPort, long inSwitch, short inPort) { |
Jonathan Hart | d300325 | 2013-11-15 09:44:46 -0800 | [diff] [blame] | 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 | f9bd98d | 2013-12-13 11:40:55 -0800 | [diff] [blame] | 39 | this.inSwitch = inSwitch; |
| 40 | this.inPort = inPort; |
Jonathan Hart | d300325 | 2013-11-15 09:44:46 -0800 | [diff] [blame] | 41 | } |
| 42 | |
| 43 | private ArpMessage(Type type, InetAddress address) { |
| 44 | this.type = type; |
| 45 | this.forAddress = address; |
| 46 | this.packetData = null; |
pingping-lin | b8757bf | 2013-12-13 01:48:58 +0800 | [diff] [blame] | 47 | this.mac = null; |
| 48 | this.outSwitch = -1; |
| 49 | this.outPort = -1; |
| 50 | |
Jonathan Hart | f9bd98d | 2013-12-13 11:40:55 -0800 | [diff] [blame] | 51 | this.inSwitch = -1; |
| 52 | this.inPort = -1; |
Jonathan Hart | d300325 | 2013-11-15 09:44:46 -0800 | [diff] [blame] | 53 | } |
pingping-lin | 017a892 | 2013-12-11 11:15:33 +0800 | [diff] [blame] | 54 | // the ARP reply message with MAC |
| 55 | private ArpMessage(Type type, InetAddress address, MACAddress mac) { |
| 56 | this.type = type; |
| 57 | this.forAddress = address; |
| 58 | this.packetData = null; |
pingping-lin | b8757bf | 2013-12-13 01:48:58 +0800 | [diff] [blame] | 59 | this.mac = mac; |
| 60 | this.outSwitch = -1; |
| 61 | this.outPort = -1; |
Jonathan Hart | f9bd98d | 2013-12-13 11:40:55 -0800 | [diff] [blame] | 62 | |
| 63 | this.inSwitch = -1; |
| 64 | this.inPort = -1; |
pingping-lin | 017a892 | 2013-12-11 11:15:33 +0800 | [diff] [blame] | 65 | } |
Jonathan Hart | d300325 | 2013-11-15 09:44:46 -0800 | [diff] [blame] | 66 | |
pingping-lin | 017a892 | 2013-12-11 11:15:33 +0800 | [diff] [blame] | 67 | // construct ARP request message with attachment switch and port |
| 68 | private ArpMessage(Type type, InetAddress address, byte[] arpRequest, |
| 69 | long outSwitch, short outPort) { |
| 70 | this.type = type; |
| 71 | this.forAddress = address; |
pingping-lin | b8757bf | 2013-12-13 01:48:58 +0800 | [diff] [blame] | 72 | this.packetData = arpRequest; |
| 73 | this.mac = null; |
| 74 | this.outSwitch = outSwitch; |
| 75 | this.outPort = outPort; |
Jonathan Hart | f9bd98d | 2013-12-13 11:40:55 -0800 | [diff] [blame] | 76 | |
| 77 | this.inSwitch = -1; |
| 78 | this.inPort = -1; |
pingping-lin | 017a892 | 2013-12-11 11:15:33 +0800 | [diff] [blame] | 79 | } |
| 80 | |
Jonathan Hart | f9bd98d | 2013-12-13 11:40:55 -0800 | [diff] [blame] | 81 | // TODO Awful quick fix - caller has to supply dummy outSwitch and outPort |
| 82 | public static ArpMessage newRequest(InetAddress forAddress, byte[] arpRequest, |
| 83 | long outSwitch, short outPort, long inSwitch, short inPort) { |
| 84 | return new ArpMessage(Type.REQUEST, forAddress, arpRequest, |
| 85 | outSwitch, outPort, inSwitch, inPort); |
Jonathan Hart | d300325 | 2013-11-15 09:44:46 -0800 | [diff] [blame] | 86 | } |
| 87 | |
| 88 | public static ArpMessage newReply(InetAddress forAddress) { |
| 89 | return new ArpMessage(Type.REPLY, forAddress); |
| 90 | } |
Jonathan Hart | f9bd98d | 2013-12-13 11:40:55 -0800 | [diff] [blame] | 91 | |
pingping-lin | 017a892 | 2013-12-11 11:15:33 +0800 | [diff] [blame] | 92 | //ARP reply message with MAC |
| 93 | public static ArpMessage newReply(InetAddress forAddress, MACAddress mac) { |
| 94 | return new ArpMessage(Type.REPLY, forAddress, mac); |
pingping-lin | 017a892 | 2013-12-11 11:15:33 +0800 | [diff] [blame] | 95 | } |
Jonathan Hart | f9bd98d | 2013-12-13 11:40:55 -0800 | [diff] [blame] | 96 | |
| 97 | //ARP request message with attachment switch and port |
| 98 | public static ArpMessage newRequest(InetAddress forAddress, |
| 99 | byte[] arpRequest, long outSwitch, short outPort ) { |
| 100 | return new ArpMessage(Type.REQUEST, forAddress, arpRequest, outSwitch, |
| 101 | outPort); |
pingping-lin | 017a892 | 2013-12-11 11:15:33 +0800 | [diff] [blame] | 102 | } |
Jonathan Hart | d300325 | 2013-11-15 09:44:46 -0800 | [diff] [blame] | 103 | |
| 104 | public Type getType() { |
| 105 | return type; |
| 106 | } |
| 107 | |
| 108 | public InetAddress getAddress() { |
| 109 | return forAddress; |
| 110 | } |
| 111 | |
| 112 | public byte[] getPacket() { |
| 113 | return packetData; |
| 114 | } |
Jonathan Hart | f9bd98d | 2013-12-13 11:40:55 -0800 | [diff] [blame] | 115 | |
pingping-lin | 017a892 | 2013-12-11 11:15:33 +0800 | [diff] [blame] | 116 | public MACAddress getMAC() { |
| 117 | return mac; |
| 118 | } |
| 119 | |
| 120 | public long getOutSwitch() { |
| 121 | return outSwitch; |
| 122 | } |
| 123 | |
pingping-lin | 017a892 | 2013-12-11 11:15:33 +0800 | [diff] [blame] | 124 | public short getOutPort() { |
| 125 | return outPort; |
| 126 | } |
Jonathan Hart | f9bd98d | 2013-12-13 11:40:55 -0800 | [diff] [blame] | 127 | |
| 128 | public long getInSwitch() { |
| 129 | return inSwitch; |
| 130 | } |
pingping-lin | 017a892 | 2013-12-11 11:15:33 +0800 | [diff] [blame] | 131 | |
Jonathan Hart | f9bd98d | 2013-12-13 11:40:55 -0800 | [diff] [blame] | 132 | public short getInPort() { |
| 133 | return inPort; |
| 134 | } |
Jonathan Hart | d300325 | 2013-11-15 09:44:46 -0800 | [diff] [blame] | 135 | } |