blob: dd159fec3dc680194a32a7a8377a68b61fcd9a4a [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
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 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;
41 }
42
43 private ArpMessage(Type type, InetAddress address) {
44 this.type = type;
45 this.forAddress = address;
46 this.packetData = null;
47 }
pingping-lin017a8922013-12-11 11:15:33 +080048 // 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 Hartd3003252013-11-15 09:44:46 -080055
pingping-lin017a8922013-12-11 11:15:33 +080056 // 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 Hartd3003252013-11-15 09:44:46 -080066 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-lin017a8922013-12-11 11:15:33 +080073 //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 Hartd3003252013-11-15 09:44:46 -080083
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-lin017a8922013-12-11 11:15:33 +080095 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 Hartd3003252013-11-15 09:44:46 -0800114}