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.sal.action;
12 import javax.xml.bind.annotation.XmlAccessType;
13 import javax.xml.bind.annotation.XmlAccessorType;
14 import javax.xml.bind.annotation.XmlRootElement;
15 import javax.xml.bind.annotation.XmlSeeAlso;
16 import javax.xml.bind.annotation.XmlTransient;
18 import org.apache.commons.lang3.builder.EqualsBuilder;
19 import org.apache.commons.lang3.builder.HashCodeBuilder;
20 import org.slf4j.Logger;
21 import org.slf4j.LoggerFactory;
24 * Represents the generic action to be applied to the matched frame/packet/message
27 @XmlAccessorType(XmlAccessType.NONE)
28 @XmlSeeAlso({Controller.class, Drop.class, Flood.class, FloodAll.class, HwPath.class, Loopback.class, Output.class,
29 PopVlan.class, PushVlan.class, SetDlDst.class, SetDlSrc.class, SetDlType.class, SetNwDst.class, SetNwSrc.class,
30 SetNwTos.class, SetTpDst.class, SetTpSrc.class, SetVlanCfi.class, SetVlanId.class, SetVlanPcp.class, SwPath.class})
31 public abstract class Action {
32 private static final Logger logger = LoggerFactory.getLogger(Action.class);
33 private static boolean debug = false; // Enable to find where in the code an invalid assignment is made
35 protected ActionType type;
36 private transient boolean isValid = true;
38 /* Dummy constructor for JAXB */
43 public Action (ActionType type, Object value) {
50 * Checks if the passed value is in the valid range for this action
55 protected void checkValue(int value) {
56 if (type.isValidTarget(value) == false) {
58 throwValueException(value);
63 * Checks if the passed value is in the valid range for the passed action type
64 * This method is used for complex Action types which are
69 protected void checkValue(ActionType type, int value) {
70 if (type.isValidTarget(value) == false) {
72 throwValueException(value);
77 * Throw and handle the invalid value exception
82 private void throwValueException(int value) {
83 String error = "Invalid field value assignement. For type: "
84 + type.getId() + " Expected: " + type.getRange() + ", Got: 0x"
85 + Integer.toHexString(value);
87 throw new Exception(error);
88 } catch (Exception e) {
89 logger.error(e.getMessage());
97 * Returns the type of this action
101 public ActionType getType() {
106 * Returns the id of this action
110 public String getId() {
115 * Returns whether the Action is valid or not
119 public boolean isValid() {
124 public int hashCode() {
125 return HashCodeBuilder.reflectionHashCode(this);
129 public boolean equals(Object obj) {
130 return EqualsBuilder.reflectionEquals(this, obj);
134 public String toString() {
135 return type.toString();