3 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
5 * This program and the accompanying materials are made available under the
6 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
7 * and is available at http://www.eclipse.org/legal/epl-v10.html
10 package org.opendaylight.controller.protocol_plugin.openflow.vendorextension.v6extension;
12 import java.nio.ByteBuffer;
13 import java.util.LinkedList;
14 import java.util.List;
16 import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
17 import org.openflow.protocol.OFPacketOut;
18 import org.openflow.protocol.OFPort;
19 import org.openflow.protocol.OFVendor;
20 import org.openflow.protocol.action.OFAction;
21 import org.slf4j.Logger;
22 import org.slf4j.LoggerFactory;
25 * This class is used to create IPv6 Vendor Extension messages. Specfically, It
26 * defines the methods used in creation of Vendor specific IPv6 Flow Mod message.
30 public class V6FlowMod extends OFVendor implements Cloneable {
31 private static final Logger logger = LoggerFactory
32 .getLogger(V6FlowMod.class);
33 private static final long serialVersionUID = 1L;
34 protected V6Match match;
35 protected long cookie;
36 protected short command;
37 protected short idleTimeout;
38 protected short hardTimeout;
39 protected short priority;
40 protected int bufferId;
41 protected short outPort;
42 protected short flags;
43 protected List<OFAction> actions;
48 private static int IPV6EXT_ADD_FLOW_MSG_TYPE = 13;
49 private static int IPV6_EXT_MIN_HDR_LEN = 36;
52 * Constructor for the V6FlowMod class. Initializes OFVendor (parent class)
53 * fields by calling the parent class' constructor.
60 * This method sets the match fields of V6FlowMod object
61 * @param match V6Match object for this V6FlowMod message
63 public void setMatch(V6Match match) {
68 * Sets the list of actions V6FlowMod message
69 * @param actions a list of ordered OFAction objects
71 public void setActions(List<OFAction> actions) {
72 this.actions = actions;
76 * Sets the priority field of V6FlowMod message
77 * @param priority Priority of the message
79 public void setPriority(short priority) {
80 this.priority = priority;
84 * Sets the cookie field of V6FlowMod message
85 * @param cookie Cookie of the message
87 public void setCookie(long cookie) {
92 * Sets the command field of V6FlowMod message
93 * @param command Command type of the message (ADD or DELETE)
95 public V6FlowMod setCommand(short command) {
96 this.command = command;
101 * Sets the outPort field of V6FlowMod message
102 * @param outPort outPort of the message
104 public V6FlowMod setOutPort(OFPort port) {
105 this.outPort = port.getValue();
110 * Sets the idle_timeout of V6FlowMod message
111 * @param idleTimeout idle timeout for this message
113 public void setIdleTimeout(short idleTimeout) {
114 this.idleTimeout = idleTimeout;
118 * Sets the hardTimeout field of V6FlowMod message
119 * @param hardTimeout hard timeout of the message
121 public void setHardTimeout(short hardTimeout) {
122 this.hardTimeout = hardTimeout;
126 * Returns the Flow Mod message subtype for V6FlowMod message
127 * @return message subtype
129 private int getIPv6ExtensionFlowModAddSubType() {
130 return IPV6EXT_ADD_FLOW_MSG_TYPE;
134 * Returns the minimum header size for V6Flow Message type
135 * @return minimum header size
138 public int getV6FlowModMinHdrSize() {
139 return IPV6_EXT_MIN_HDR_LEN;
143 * Sets the Vendor type in OFVendor message
146 public void setVendor() {
147 super.setVendor(V6StatsRequest.NICIRA_VENDOR_ID);
154 public short getFlags() {
162 public void setFlags(short flags) {
167 * This method forms the Vendor extension IPv6 Flow Mod message.It uses the
168 * fields in V6FlowMod class, and writes the data according to vendor
169 * extension format. The fields include flow properties (cookie, timeout,
170 * priority, etc), flow match, and action list. It also takes care of
175 public void writeTo(ByteBuffer data) {
177 data.putInt(getIPv6ExtensionFlowModAddSubType());
178 data.putLong(this.cookie);
179 data.putShort(command); /* should be OFPFC_ADD, OFPFC_DELETE_STRICT, etc*/
180 data.putShort(this.idleTimeout);
181 data.putShort(this.hardTimeout);
182 data.putShort(this.priority);
183 data.putInt(OFPacketOut.BUFFER_ID_NONE);
184 data.putShort(outPort); /* output_port */
185 data.putShort(flags); /* flags */
186 match_len = this.match.getIPv6MatchLen();
187 data.putShort(match_len);
188 byte[] pad = new byte[6];
190 this.match.writeTo(data);
192 pad_size = (short) (((match_len + 7) / 8) * 8 - match_len);
195 * action list should be preceded by a padding of 0 to 7 bytes based upon
199 byte[] pad2 = new byte[pad_size];
201 if (actions != null) {
202 for (OFAction action : actions) {
203 actions_len += action.getLength();
204 action.writeTo(data);
207 logger.trace("{}", this.toString());
211 * Forms the clone of V6FlowMod Object. If Object is returned
212 * successfully, then returns the cloned object. Throws an
213 * exception if cloning is not supported.
216 public V6FlowMod clone() {
218 V6Match neoMatch = match.clone();
219 V6FlowMod v6flowMod = (V6FlowMod) super.clone();
220 v6flowMod.setMatch(neoMatch);
221 List<OFAction> neoActions = new LinkedList<OFAction>();
222 for (OFAction action : this.actions)
223 neoActions.add((OFAction) action.clone());
224 v6flowMod.setActions(neoActions);
226 } catch (CloneNotSupportedException e) {
228 throw new RuntimeException(e);
233 * Prints the contents of V6FlowMod in a string format.
236 public String toString() {
237 return "V6FlowMod[" + ReflectionToStringBuilder.toString(this) + "]";