blob: 44b9ea0b7bcdf545dc1bb9db0584d36e3309bf8d [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
Jonathan Hartf9bd98d2013-12-13 11:40:55 -08007// TODO This is getting very messy!!! Needs refactoring
Jonathan Hartd3003252013-11-15 09:44:46 -08008public class ArpMessage implements Serializable {
9
Jonathan Hartd3003252013-11-15 09:44:46 -080010 private static final long serialVersionUID = 1L;
11
12 private final Type type;
13 private final InetAddress forAddress;
14 private final byte[] packetData;
15
Jonathan Hartf9bd98d2013-12-13 11:40:55 -080016 // ARP reply message needs MAC info
pingping-linb8757bf2013-12-13 01:48:58 +080017 private final MACAddress mac;
Jonathan Hartf9bd98d2013-12-13 11:40:55 -080018 // Only send the ARP request message to the device attachment needs the
19 // attachment switch and port.
pingping-linb8757bf2013-12-13 01:48:58 +080020 private final long outSwitch;
21 private final short outPort;
pingping-lin017a8922013-12-11 11:15:33 +080022
Jonathan Hartf9bd98d2013-12-13 11:40:55 -080023 private final long inSwitch;
24 private final short inPort;
pingping-lina2c8d9c2013-12-13 05:01:48 +080025
Jonathan Hartd3003252013-11-15 09:44:46 -080026 public enum Type {
27 REQUEST,
28 REPLY
29 }
30
Jonathan Hartf9bd98d2013-12-13 11:40:55 -080031 private ArpMessage(Type type, InetAddress address, byte[] eth,
32 long outSwitch, short outPort, long inSwitch, short inPort) {
Jonathan Hartd3003252013-11-15 09:44:46 -080033 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 Hartf9bd98d2013-12-13 11:40:55 -080039 this.inSwitch = inSwitch;
40 this.inPort = inPort;
Jonathan Hartd3003252013-11-15 09:44:46 -080041 }
42
43 private ArpMessage(Type type, InetAddress address) {
44 this.type = type;
45 this.forAddress = address;
46 this.packetData = null;
pingping-linb8757bf2013-12-13 01:48:58 +080047 this.mac = null;
48 this.outSwitch = -1;
49 this.outPort = -1;
50
Jonathan Hartf9bd98d2013-12-13 11:40:55 -080051 this.inSwitch = -1;
52 this.inPort = -1;
Jonathan Hartd3003252013-11-15 09:44:46 -080053 }
pingping-lin017a8922013-12-11 11:15:33 +080054 // 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-linb8757bf2013-12-13 01:48:58 +080059 this.mac = mac;
60 this.outSwitch = -1;
61 this.outPort = -1;
Jonathan Hartf9bd98d2013-12-13 11:40:55 -080062
63 this.inSwitch = -1;
64 this.inPort = -1;
pingping-lin017a8922013-12-11 11:15:33 +080065 }
Jonathan Hartd3003252013-11-15 09:44:46 -080066
pingping-lin017a8922013-12-11 11:15:33 +080067 // 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-linb8757bf2013-12-13 01:48:58 +080072 this.packetData = arpRequest;
73 this.mac = null;
74 this.outSwitch = outSwitch;
75 this.outPort = outPort;
Jonathan Hartf9bd98d2013-12-13 11:40:55 -080076
77 this.inSwitch = -1;
78 this.inPort = -1;
pingping-lin017a8922013-12-11 11:15:33 +080079 }
80
Jonathan Hartf9bd98d2013-12-13 11:40:55 -080081 // 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 Hartd3003252013-11-15 09:44:46 -080086 }
87
88 public static ArpMessage newReply(InetAddress forAddress) {
89 return new ArpMessage(Type.REPLY, forAddress);
90 }
Jonathan Hartf9bd98d2013-12-13 11:40:55 -080091
pingping-lin017a8922013-12-11 11:15:33 +080092 //ARP reply message with MAC
93 public static ArpMessage newReply(InetAddress forAddress, MACAddress mac) {
94 return new ArpMessage(Type.REPLY, forAddress, mac);
pingping-lin017a8922013-12-11 11:15:33 +080095 }
Jonathan Hartf9bd98d2013-12-13 11:40:55 -080096
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-lin017a8922013-12-11 11:15:33 +0800102 }
Jonathan Hartd3003252013-11-15 09:44:46 -0800103
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 Hartf9bd98d2013-12-13 11:40:55 -0800115
pingping-lin017a8922013-12-11 11:15:33 +0800116 public MACAddress getMAC() {
117 return mac;
118 }
119
120 public long getOutSwitch() {
121 return outSwitch;
122 }
123
pingping-lin017a8922013-12-11 11:15:33 +0800124 public short getOutPort() {
125 return outPort;
126 }
Jonathan Hartf9bd98d2013-12-13 11:40:55 -0800127
128 public long getInSwitch() {
129 return inSwitch;
130 }
pingping-lin017a8922013-12-11 11:15:33 +0800131
Jonathan Hartf9bd98d2013-12-13 11:40:55 -0800132 public short getInPort() {
133 return inPort;
134 }
Jonathan Hartd3003252013-11-15 09:44:46 -0800135}