blob: ee8f23d5f348d4bb523548eb790fcdd30825d4b5 [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;
pingping-lin017a8922013-12-11 11:15:33 +08005import net.floodlightcontroller.util.MACAddress;
Jonathan Hartd3003252013-11-15 09:44:46 -08006
7public 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-lin017a8922013-12-11 11:15:33 +080018 //ARP reply message needs MAC info
pingping-linb8757bf2013-12-13 01:48:58 +080019 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-lin017a8922013-12-11 11:15:33 +080023
pingping-lina2c8d9c2013-12-13 05:01:48 +080024
25
Jonathan Hartd3003252013-11-15 09:44:46 -080026 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-linb8757bf2013-12-13 01:48:58 +080036 this.mac = null;
37 this.outSwitch = -1;
38 this.outPort = -1;
Jonathan Hartd3003252013-11-15 09:44:46 -080039 }
40
41 private ArpMessage(Type type, InetAddress address) {
42 this.type = type;
43 this.forAddress = address;
44 this.packetData = null;
pingping-linb8757bf2013-12-13 01:48:58 +080045 this.mac = null;
46 this.outSwitch = -1;
47 this.outPort = -1;
48
Jonathan Hartd3003252013-11-15 09:44:46 -080049 }
pingping-lin017a8922013-12-11 11:15:33 +080050 // 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-linb8757bf2013-12-13 01:48:58 +080055 this.mac = mac;
56 this.outSwitch = -1;
57 this.outPort = -1;
pingping-lin017a8922013-12-11 11:15:33 +080058 }
Jonathan Hartd3003252013-11-15 09:44:46 -080059
pingping-lin017a8922013-12-11 11:15:33 +080060 // 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-linb8757bf2013-12-13 01:48:58 +080065 this.packetData = arpRequest;
66 this.mac = null;
67 this.outSwitch = outSwitch;
68 this.outPort = outPort;
pingping-lin017a8922013-12-11 11:15:33 +080069 }
70
Jonathan Hartd3003252013-11-15 09:44:46 -080071 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-lin017a8922013-12-11 11:15:33 +080078 //ARP reply message with MAC
79 public static ArpMessage newReply(InetAddress forAddress, MACAddress mac) {
80 return new ArpMessage(Type.REPLY, forAddress, mac);
pingping-linb8757bf2013-12-13 01:48:58 +080081
pingping-lin017a8922013-12-11 11:15:33 +080082 }
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-linb8757bf2013-12-13 01:48:58 +080086
pingping-lin017a8922013-12-11 11:15:33 +080087 }
Jonathan Hartd3003252013-11-15 09:44:46 -080088
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-lin017a8922013-12-11 11:15:33 +0800100 public MACAddress getMAC() {
101 return mac;
102 }
103
104 public long getOutSwitch() {
105 return outSwitch;
106 }
107
pingping-lin017a8922013-12-11 11:15:33 +0800108 public short getOutPort() {
109 return outPort;
110 }
111
Jonathan Hartd3003252013-11-15 09:44:46 -0800112}