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