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 |
| 23 | private MACAddress mac; |
| 24 | //only send the ARP request message to the device attachment needs the attachement swith and port. |
| 25 | private long outSwitch=-1; |
| 26 | private short outPort=-1; |
| 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; |
| 41 | } |
| 42 | |
| 43 | private ArpMessage(Type type, InetAddress address) { |
| 44 | this.type = type; |
| 45 | this.forAddress = address; |
| 46 | this.packetData = null; |
| 47 | } |
pingping-lin | 017a892 | 2013-12-11 11:15:33 +0800 | [diff] [blame^] | 48 | // the ARP reply message with MAC |
| 49 | private ArpMessage(Type type, InetAddress address, MACAddress mac) { |
| 50 | this.type = type; |
| 51 | this.forAddress = address; |
| 52 | this.packetData = null; |
| 53 | this.mac=mac; |
| 54 | } |
Jonathan Hart | d300325 | 2013-11-15 09:44:46 -0800 | [diff] [blame] | 55 | |
pingping-lin | 017a892 | 2013-12-11 11:15:33 +0800 | [diff] [blame^] | 56 | // construct ARP request message with attachment switch and port |
| 57 | private ArpMessage(Type type, InetAddress address, byte[] arpRequest, |
| 58 | long outSwitch, short outPort) { |
| 59 | this.type = type; |
| 60 | this.forAddress = address; |
| 61 | this.packetData = arpRequest; |
| 62 | this.setOutSwitch(outSwitch); |
| 63 | this.setOutPort(outPort); |
| 64 | } |
| 65 | |
Jonathan Hart | d300325 | 2013-11-15 09:44:46 -0800 | [diff] [blame] | 66 | public static ArpMessage newRequest(InetAddress forAddress, byte[] arpRequest) { |
| 67 | return new ArpMessage(Type.REQUEST, forAddress, arpRequest); |
| 68 | } |
| 69 | |
| 70 | public static ArpMessage newReply(InetAddress forAddress) { |
| 71 | return new ArpMessage(Type.REPLY, forAddress); |
| 72 | } |
pingping-lin | 017a892 | 2013-12-11 11:15:33 +0800 | [diff] [blame^] | 73 | //ARP reply message with MAC |
| 74 | public static ArpMessage newReply(InetAddress forAddress, MACAddress mac) { |
| 75 | return new ArpMessage(Type.REPLY, forAddress, mac); |
| 76 | |
| 77 | } |
| 78 | //ARP reqsuest message with attachment switch and port |
| 79 | public static ArpMessage newRequest(InetAddress forAddress, byte[] arpRequest, long outSwitch, short outPort ) { |
| 80 | return new ArpMessage(Type.REQUEST, forAddress, arpRequest, outSwitch, outPort); |
| 81 | |
| 82 | } |
Jonathan Hart | d300325 | 2013-11-15 09:44:46 -0800 | [diff] [blame] | 83 | |
| 84 | public Type getType() { |
| 85 | return type; |
| 86 | } |
| 87 | |
| 88 | public InetAddress getAddress() { |
| 89 | return forAddress; |
| 90 | } |
| 91 | |
| 92 | public byte[] getPacket() { |
| 93 | return packetData; |
| 94 | } |
pingping-lin | 017a892 | 2013-12-11 11:15:33 +0800 | [diff] [blame^] | 95 | public MACAddress getMAC() { |
| 96 | return mac; |
| 97 | } |
| 98 | |
| 99 | public long getOutSwitch() { |
| 100 | return outSwitch; |
| 101 | } |
| 102 | |
| 103 | public void setOutSwitch(long outSwitch) { |
| 104 | this.outSwitch = outSwitch; |
| 105 | } |
| 106 | |
| 107 | public short getOutPort() { |
| 108 | return outPort; |
| 109 | } |
| 110 | |
| 111 | public void setOutPort(short outPort) { |
| 112 | this.outPort = outPort; |
| 113 | } |
Jonathan Hart | d300325 | 2013-11-15 09:44:46 -0800 | [diff] [blame] | 114 | } |