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.openflow.protocol.OFPacketOut;
17 import org.openflow.protocol.OFPort;
18 import org.openflow.protocol.OFVendor;
19 import org.openflow.protocol.action.OFAction;
20 import org.slf4j.Logger;
21 import org.slf4j.LoggerFactory;
23 import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
26 * This class is used to create IPv6 Vendor Extension messages. Specfically, It
27 * defines the methods used in creation of Vendor specific IPv6 Flow Mod message.
31 public class V6FlowMod extends OFVendor implements Cloneable {
32 private static final Logger logger = LoggerFactory
33 .getLogger(V6FlowMod.class);
34 private static final long serialVersionUID = 1L;
35 protected V6Match match;
36 protected long cookie;
37 protected short command;
38 protected short idleTimeout;
39 protected short hardTimeout;
40 protected short priority;
41 protected int bufferId;
42 protected short outPort;
43 protected short flags;
44 protected List<OFAction> actions;
49 private static int IPV6EXT_ADD_FLOW_MSG_TYPE = 13;
50 private static int IPV6_EXT_MIN_HDR_LEN = 36;
53 * Constructor for the V6FlowMod class. Initializes OFVendor (parent class)
54 * fields by calling the parent class' constructor.
61 * This method sets the match fields of V6FlowMod object
62 * @param match V6Match object for this V6FlowMod message
64 public void setMatch(V6Match match) {
69 * Sets the list of actions V6FlowMod message
70 * @param actions a list of ordered OFAction objects
72 public void setActions(List<OFAction> actions) {
73 this.actions = actions;
77 * Sets the priority field of V6FlowMod message
78 * @param priority Priority of the message
80 public void setPriority(short priority) {
81 this.priority = priority;
85 * Sets the cookie field of V6FlowMod message
86 * @param cookie Cookie of the message
88 public void setCookie(long cookie) {
93 * Sets the command field of V6FlowMod message
94 * @param command Command type of the message (ADD or DELETE)
96 public V6FlowMod setCommand(short command) {
97 this.command = command;
102 * Sets the outPort field of V6FlowMod message
103 * @param outPort outPort of the message
105 public V6FlowMod setOutPort(OFPort port) {
106 this.outPort = port.getValue();
111 * Sets the idle_timeout of V6FlowMod message
112 * @param idleTimeout idle timeout for this message
114 public void setIdleTimeout(short idleTimeout) {
115 this.idleTimeout = idleTimeout;
119 * Sets the hardTimeout field of V6FlowMod message
120 * @param hardTimeout hard timeout of the message
122 public void setHardTimeout(short hardTimeout) {
123 this.hardTimeout = hardTimeout;
127 * Returns the Flow Mod message subtype for V6FlowMod message
128 * @return message subtype
130 private int getIPv6ExtensionFlowModAddSubType() {
131 return IPV6EXT_ADD_FLOW_MSG_TYPE;
135 * Returns the minimum header size for V6Flow Message type
136 * @return minimum header size
139 public int getV6FlowModMinHdrSize() {
140 return IPV6_EXT_MIN_HDR_LEN;
144 * Sets the Vendor type in OFVendor message
147 public void setVendor() {
148 super.setVendor(V6StatsRequest.NICIRA_VENDOR_ID);
152 * This method forms the Vendor extension IPv6 Flow Mod message.It uses the
153 * fields in V6FlowMod class, and writes the data according to vendor
154 * extension format. The fields include flow properties (cookie, timeout,
155 * priority, etc), flow match, and action list. It also takes care of
160 public void writeTo(ByteBuffer data) {
162 data.putInt(getIPv6ExtensionFlowModAddSubType());
163 data.putLong(this.cookie);
164 data.putShort(command); /* should be OFPFC_ADD, OFPFC_DELETE_STRICT, etc*/
165 data.putShort(this.idleTimeout);
166 data.putShort(this.hardTimeout);
167 data.putShort(this.priority);
168 data.putInt(OFPacketOut.BUFFER_ID_NONE);
169 data.putShort(outPort); /* output_port */
170 data.putShort((short) 0); /* flags */
171 match_len = this.match.getIPv6MatchLen();
172 data.putShort(match_len);
173 byte[] pad = new byte[6];
175 this.match.writeTo(data);
177 pad_size = (short) (((match_len + 7) / 8) * 8 - match_len);
180 * action list should be preceded by a padding of 0 to 7 bytes based upon
184 byte[] pad2 = new byte[pad_size];
186 if (actions != null) {
187 for (OFAction action : actions) {
188 actions_len += action.getLength();
189 action.writeTo(data);
192 logger.trace("{}", this.toString());
196 * Forms the clone of V6FlowMod Object. If Object is returned
197 * successfully, then returns the cloned object. Throws an
198 * exception if cloning is not supported.
201 public V6FlowMod clone() {
203 V6Match neoMatch = match.clone();
204 V6FlowMod v6flowMod = (V6FlowMod) super.clone();
205 v6flowMod.setMatch(neoMatch);
206 List<OFAction> neoActions = new LinkedList<OFAction>();
207 for (OFAction action : this.actions)
208 neoActions.add((OFAction) action.clone());
209 v6flowMod.setActions(neoActions);
211 } catch (CloneNotSupportedException e) {
213 throw new RuntimeException(e);
218 * Prints the contents of V6FlowMod in a string format.
221 public String toString() {
222 return "V6FlowMod[" + ReflectionToStringBuilder.toString(this) + "]";