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();
81 super.setLength(actionLen);
82 this.address = address;
84 public InetAddress getNextHop() {
88 public void readFrom(ByteBuffer data) {
90 * For now, only contains the next hop address
92 //super.readFrom(data); don't need this
94 if (data.remaining() < super.getLength()-8) {
96 * malformed element, skip over
98 data.position(data.remaining());
101 if ((super.getLength() != (short)ONHLength.ONH_LEN_IPV4.getValue()) &&
102 (super.getLength() != (short)ONHLength.ONH_LEN_IPV6.getValue())) {
104 * mal-formed element, skip over
106 data.position(super.getLength());
109 data.getShort(); // skip the ONH_ACTION_OUTPUT_NH
110 data.getShort(); // skip address and xtraaddress types
111 data.getInt(); // skip the extra address (8 bytes)
114 if (super.getLength() == (short)ONHLength.ONH_LEN_IPV4.getValue()) {
120 data.getInt(); //4 bytes pad
123 this.address = InetAddress.getByAddress(a);
124 } catch (UnknownHostException e) {
130 public void writeTo(ByteBuffer data) {
131 byte atype = (byte)(ONHAddressType.ONH_ADDRTYPE_NONE.getValue());
132 byte xatype = (byte)(ONHXAddressType.ONH_XADDRTYPE_NONE.getValue());
133 if (address instanceof Inet4Address)
134 atype = (byte)(ONHAddressType.ONH_ADDRTYPE_IPV4.getValue());
136 atype = (byte)(ONHAddressType.ONH_ADDRTYPE_IPV6.getValue());
137 super.writeTo(data); // this writes the standard 8byte ofp_action_vendor_header
138 data.putShort((short)(ONHActionType.ONH_ACTION_OUTPUT_NH.getValue()));
142 * write the xtra address. For now it is all 0
144 data.putInt(0); // 8-byte pad
147 * write the address only when address type is not P2P
149 if (atype == (byte)(ONHAddressType.ONH_ADDRTYPE_IPV4.getValue())) {
150 data.put(address.getAddress()); // no need to pad
151 //avnh.put(address.getAddress());
152 } else if (atype == (byte)(ONHAddressType.ONH_ADDRTYPE_IPV6.getValue())) {
153 data.put(address.getAddress());
154 //avnh.put(address.getAddress());
155 data.putInt(0); // 4-byte pad
158 ActionVendorOutputNextHop a = new ActionVendorOutputNextHop();
159 a.setLength((short)24);
163 public int hashCode() {
164 final int prime = 347;
165 int result = super.hashCode();
166 result = prime * result + address.hashCode();
171 public boolean equals(Object obj) {
175 if (!super.equals(obj)) {
178 if (!(obj instanceof ActionVendorOutputNextHop)) {
181 ActionVendorOutputNextHop other = (ActionVendorOutputNextHop) obj;
182 if (!other.address.equals(this.address))
187 public String toString() {
188 return ("OutputNextHop: " + address.getHostAddress());