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;
24 * This class is used to create IPv6 Vendor Extension messages. Specfically, It
25 * defines the methods used in creation of Vendor specific IPv6 Flow Mod message.
29 public class V6FlowMod extends OFVendor implements Cloneable {
30 private static final Logger logger = LoggerFactory
31 .getLogger(V6FlowMod.class);
32 private static final long serialVersionUID = 1L;
33 protected V6Match match;
34 protected long cookie;
35 protected short command;
36 protected short idleTimeout;
37 protected short hardTimeout;
38 protected short priority;
39 protected int bufferId;
40 protected short outPort;
41 protected short flags;
42 protected List<OFAction> actions;
47 private static int IPV6EXT_ADD_FLOW_MSG_TYPE = 13;
48 private static int IPV6_EXT_MIN_HDR_LEN = 36;
51 * Constructor for the V6FlowMod class. Initializes OFVendor (parent class)
52 * fields by calling the parent class' constructor.
59 * This method sets the match fields of V6FlowMod object
60 * @param match V6Match object for this V6FlowMod message
62 public void setMatch(V6Match match) {
67 * Sets the list of actions V6FlowMod message
68 * @param actions a list of ordered OFAction objects
70 public void setActions(List<OFAction> actions) {
71 this.actions = actions;
75 * Sets the priority field of V6FlowMod message
76 * @param priority Priority of the message
78 public void setPriority(short priority) {
79 this.priority = priority;
83 * Sets the cookie field of V6FlowMod message
84 * @param cookie Cookie of the message
86 public void setCookie(long cookie) {
91 * Sets the command field of V6FlowMod message
92 * @param command Command type of the message (ADD or DELETE)
94 public V6FlowMod setCommand(short command) {
95 this.command = command;
100 * Sets the outPort field of V6FlowMod message
101 * @param outPort outPort of the message
103 public V6FlowMod setOutPort(OFPort port) {
104 this.outPort = port.getValue();
109 * Sets the idle_timeout of V6FlowMod message
110 * @param idleTimeout idle timeout for this message
112 public void setIdleTimeout(short idleTimeout) {
113 this.idleTimeout = idleTimeout;
117 * Sets the hardTimeout field of V6FlowMod message
118 * @param hardTimeout hard timeout of the message
120 public void setHardTimeout(short hardTimeout) {
121 this.hardTimeout = hardTimeout;
125 * Returns the Flow Mod message subtype for V6FlowMod message
126 * @return message subtype
128 private int getIPv6ExtensionFlowModAddSubType() {
129 return IPV6EXT_ADD_FLOW_MSG_TYPE;
133 * Returns the minimum header size for V6Flow Message type
134 * @return minimum header size
137 public int getV6FlowModMinHdrSize() {
138 return IPV6_EXT_MIN_HDR_LEN;
142 * Sets the Vendor type in OFVendor message
145 public void setVendor() {
146 super.setVendor(V6StatsRequest.NICIRA_VENDOR_ID);
153 public short getFlags() {
161 public void setFlags(short flags) {
166 * This method forms the Vendor extension IPv6 Flow Mod message.It uses the
167 * fields in V6FlowMod class, and writes the data according to vendor
168 * extension format. The fields include flow properties (cookie, timeout,
169 * priority, etc), flow match, and action list. It also takes care of
174 public void writeTo(ByteBuffer data) {
176 data.putInt(getIPv6ExtensionFlowModAddSubType());
177 data.putLong(this.cookie);
178 data.putShort(command); /* should be OFPFC_ADD, OFPFC_DELETE_STRICT, etc*/
179 data.putShort(this.idleTimeout);
180 data.putShort(this.hardTimeout);
181 data.putShort(this.priority);
182 data.putInt(OFPacketOut.BUFFER_ID_NONE);
183 data.putShort(outPort); /* output_port */
184 data.putShort(flags); /* flags */
185 match_len = this.match.getIPv6MatchLen();
186 data.putShort(match_len);
187 byte[] pad = new byte[6];
189 this.match.writeTo(data);
191 pad_size = (short) (((match_len + 7) / 8) * 8 - match_len);
194 * action list should be preceded by a padding of 0 to 7 bytes based upon
198 byte[] pad2 = new byte[pad_size];
200 if (actions != null) {
201 for (OFAction action : actions) {
202 actions_len += action.getLength();
203 action.writeTo(data);
206 logger.trace("{}", this);
210 * Forms the clone of V6FlowMod Object. If Object is returned
211 * successfully, then returns the cloned object. Throws an
212 * exception if cloning is not supported.
215 public V6FlowMod clone() {
217 V6Match neoMatch = match.clone();
218 V6FlowMod v6flowMod = (V6FlowMod) super.clone();
219 v6flowMod.setMatch(neoMatch);
220 List<OFAction> neoActions = new LinkedList<OFAction>();
221 for (OFAction action : this.actions)
222 neoActions.add((OFAction) action.clone());
223 v6flowMod.setActions(neoActions);
225 } catch (CloneNotSupportedException e) {
227 throw new RuntimeException(e);
232 public String toString() {
233 return "V6FlowMod [match=" + match + ", cookie=" + cookie
234 + ", command=" + command + ", idleTimeout=" + idleTimeout
235 + ", hardTimeout=" + hardTimeout + ", priority=" + priority
236 + ", bufferId=" + bufferId + ", outPort=" + outPort
237 + ", flags=" + flags + ", actions=" + actions + ", match_len="
238 + match_len + ", actions_len=" + actions_len + ", pad_size="