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.slf4j.Logger;
19 import org.slf4j.LoggerFactory;
22 * Represents the generic action to be applied to the matched frame/packet/message
25 @XmlAccessorType(XmlAccessType.NONE)
26 @XmlSeeAlso({Controller.class, Drop.class, Flood.class, FloodAll.class, HwPath.class, Loopback.class, Output.class,
27 PopVlan.class, PushVlan.class, SetDlDst.class, SetDlSrc.class, SetDlType.class, SetNwDst.class, SetNwSrc.class,
28 SetNwTos.class, SetTpDst.class, SetTpSrc.class, SetVlanCfi.class, SetVlanId.class, SetVlanPcp.class, SwPath.class})
29 public abstract class Action {
30 private static final Logger logger = LoggerFactory.getLogger(Action.class);
31 private static boolean debug = false; // Enable to find where in the code an invalid assignment is made
33 protected ActionType type;
34 private transient boolean isValid = true;
36 /* Dummy constructor for JAXB */
41 public Action (ActionType type, Object value) {
48 * Checks if the passed value is in the valid range for this action
53 protected void checkValue(int value) {
54 if (type.isValidTarget(value) == false) {
56 throwValueException(value);
61 * Checks if the passed value is in the valid range for the passed action type
62 * This method is used for complex Action types which are
67 protected void checkValue(ActionType type, int value) {
68 if (type.isValidTarget(value) == false) {
70 throwValueException(value);
75 * Throw and handle the invalid value exception
80 private void throwValueException(int value) {
81 String error = "Invalid field value assignement. For type: "
82 + type.getId() + " Expected: " + type.getRange() + ", Got: 0x"
83 + Integer.toHexString(value);
85 throw new Exception(error);
86 } catch (Exception e) {
87 logger.error(e.getMessage());
95 * Returns the type of this action
99 public ActionType getType() {
104 * Returns the id of this action
108 public String getId() {
113 * Returns whether the Action is valid or not
117 public boolean isValid() {
122 public int hashCode() {
123 final int prime = 31;
125 result = prime * result + ((type == null) ? 0 : type.hashCode());
130 public boolean equals(Object obj) {
135 if (getClass() != obj.getClass())
137 Action other = (Action) obj;
138 if (type != other.type)
144 public String toString() {
145 return type.toString();