1 package org.openflow.protocol.action;
3 import java.net.Inet4Address;
4 import java.net.InetAddress;
5 import java.net.UnknownHostException;
6 import java.nio.ByteBuffer;
8 import org.openflow.util.HexString;
11 public class ActionVendorOutputNextHop extends OFActionVendor {
12 private static final long serialVersionUID = 1L;
13 private static int VENDOR_CISCO = 0xC;
14 private enum ONHLength {
21 private ONHLength(int value) {
24 public int getValue() {
28 private enum ONHActionType {
30 ONH_ACTION_OUTPUT_NH(1),
31 ONH_ACTION_NETFLOW(2);
33 private ONHActionType(int value) {
36 public int getValue() {
40 private enum ONHAddressType {
45 ONH_ADDRTYPE_MAC48(4);
47 private ONHAddressType(int value) {
50 public int getValue() {
54 private enum ONHXAddressType {
55 ONH_XADDRTYPE_NONE(0),
56 ONH_XADDRTYPE_PORT(1),
57 ONH_XADDRTYPE_VPNID(2);
59 private ONHXAddressType(int value) {
62 public int getValue() {
66 protected InetAddress address;
68 public ActionVendorOutputNextHop() {
70 super.setLength((short)ONHLength.ONH_LEN_MIN.getValue());
71 super.setVendor(VENDOR_CISCO);
75 public void setNextHop(InetAddress address) {
77 if (address instanceof Inet4Address) {
78 actionLen = (short)ONHLength.ONH_LEN_IPV4.getValue();
80 actionLen = (short)ONHLength.ONH_LEN_IPV6.getValue();
82 super.setLength(actionLen);
83 this.address = address;
85 public InetAddress getNextHop() {
89 public void readFrom(ByteBuffer data) {
91 * For now, only contains the next hop address
93 //super.readFrom(data); don't need this
95 if (data.remaining() < super.getLength()-8) {
97 * malformed element, skip over
99 data.position(data.remaining());
102 if ((super.getLength() != (short)ONHLength.ONH_LEN_IPV4.getValue()) &&
103 (super.getLength() != (short)ONHLength.ONH_LEN_IPV6.getValue())) {
105 * mal-formed element, skip over
107 data.position(super.getLength());
110 data.getShort(); // skip the ONH_ACTION_OUTPUT_NH
111 data.getShort(); // skip address and xtraaddress types
112 data.getInt(); // skip the extra address (8 bytes)
115 if (super.getLength() == (short)ONHLength.ONH_LEN_IPV4.getValue()) {
121 data.getInt(); //4 bytes pad
124 this.address = InetAddress.getByAddress(a);
125 } catch (UnknownHostException e) {
131 public void writeTo(ByteBuffer data) {
132 byte atype = (byte)(ONHAddressType.ONH_ADDRTYPE_NONE.getValue());
133 byte xatype = (byte)(ONHXAddressType.ONH_XADDRTYPE_NONE.getValue());
134 if (address instanceof Inet4Address)
135 atype = (byte)(ONHAddressType.ONH_ADDRTYPE_IPV4.getValue());
137 atype = (byte)(ONHAddressType.ONH_ADDRTYPE_IPV6.getValue());
138 super.writeTo(data); // this writes the standard 8byte ofp_action_vendor_header
139 data.putShort((short)(ONHActionType.ONH_ACTION_OUTPUT_NH.getValue()));
143 * write the xtra address. For now it is all 0
145 data.putInt(0); // 8-byte pad
148 * write the address only when address type is not P2P
150 if (atype == (byte)(ONHAddressType.ONH_ADDRTYPE_IPV4.getValue())) {
151 data.put(address.getAddress()); // no need to pad
152 //avnh.put(address.getAddress());
153 } else if (atype == (byte)(ONHAddressType.ONH_ADDRTYPE_IPV6.getValue())) {
154 data.put(address.getAddress());
155 //avnh.put(address.getAddress());
156 data.putInt(0); // 4-byte pad
159 ActionVendorOutputNextHop a = new ActionVendorOutputNextHop();
160 a.setLength((short)24);
164 public int hashCode() {
165 final int prime = 347;
166 int result = super.hashCode();
167 result = prime * result + address.hashCode();
172 public boolean equals(Object obj) {
176 if (!super.equals(obj)) {
179 if (!(obj instanceof ActionVendorOutputNextHop)) {
182 ActionVendorOutputNextHop other = (ActionVendorOutputNextHop) obj;
183 if (!other.address.equals(this.address))
188 public String toString() {
189 return ("OutputNextHop: " + address.getHostAddress());