blob: 6ce5ade5214fef87be621bd5a5be95c17a3dee88 [file] [log] [blame]
Jonathan Hartd3003252013-11-15 09:44:46 -08001package net.onrc.onos.ofcontroller.proxyarp;
2
3import java.io.Serializable;
4import java.net.InetAddress;
5import java.util.ArrayList;
6import java.util.List;
7
pingping-lin017a8922013-12-11 11:15:33 +08008import net.floodlightcontroller.util.MACAddress;
Jonathan Hartd3003252013-11-15 09:44:46 -08009import net.onrc.onos.ofcontroller.util.SwitchPort;
10
11public 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-lin017a8922013-12-11 11:15:33 +080022 //ARP reply message needs MAC info
pingping-linb8757bf2013-12-13 01:48:58 +080023 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-lin017a8922013-12-11 11:15:33 +080027
28
Jonathan Hartd3003252013-11-15 09:44:46 -080029 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-linb8757bf2013-12-13 01:48:58 +080041 this.mac = null;
42 this.outSwitch = -1;
43 this.outPort = -1;
Jonathan Hartd3003252013-11-15 09:44:46 -080044 }
45
46 private ArpMessage(Type type, InetAddress address) {
47 this.type = type;
48 this.forAddress = address;
49 this.packetData = null;
pingping-linb8757bf2013-12-13 01:48:58 +080050 this.mac = null;
51 this.outSwitch = -1;
52 this.outPort = -1;
53
Jonathan Hartd3003252013-11-15 09:44:46 -080054 }
pingping-lin017a8922013-12-11 11:15:33 +080055 // 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-linb8757bf2013-12-13 01:48:58 +080060 this.mac = mac;
61 this.outSwitch = -1;
62 this.outPort = -1;
pingping-lin017a8922013-12-11 11:15:33 +080063 }
Jonathan Hartd3003252013-11-15 09:44:46 -080064
pingping-lin017a8922013-12-11 11:15:33 +080065 // 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-linb8757bf2013-12-13 01:48:58 +080070 this.packetData = arpRequest;
71 this.mac = null;
72 this.outSwitch = outSwitch;
73 this.outPort = outPort;
pingping-lin017a8922013-12-11 11:15:33 +080074 }
75
Jonathan Hartd3003252013-11-15 09:44:46 -080076 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-lin017a8922013-12-11 11:15:33 +080083 //ARP reply message with MAC
84 public static ArpMessage newReply(InetAddress forAddress, MACAddress mac) {
85 return new ArpMessage(Type.REPLY, forAddress, mac);
pingping-linb8757bf2013-12-13 01:48:58 +080086
pingping-lin017a8922013-12-11 11:15:33 +080087 }
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-linb8757bf2013-12-13 01:48:58 +080091
pingping-lin017a8922013-12-11 11:15:33 +080092 }
Jonathan Hartd3003252013-11-15 09:44:46 -080093
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-lin017a8922013-12-11 11:15:33 +0800105 public MACAddress getMAC() {
106 return mac;
107 }
108
109 public long getOutSwitch() {
110 return outSwitch;
111 }
112
pingping-lin017a8922013-12-11 11:15:33 +0800113 public short getOutPort() {
114 return outPort;
115 }
116
Jonathan Hartd3003252013-11-15 09:44:46 -0800117}