2 * Copyright © 2016 Red Hat, Inc. and others.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.genius.mdsalutil.actions;
10 import org.opendaylight.genius.mdsalutil.ActionInfo;
11 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix;
12 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetFieldCaseBuilder;
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.field._case.SetFieldBuilder;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionBuilder;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionKey;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv4MatchBuilder;
20 * Set source IP action.
22 public class ActionSetSourceIp extends ActionInfo {
24 private final Ipv4Prefix source;
26 public ActionSetSourceIp(String sourceIp) {
27 this(0, sourceIp, null);
30 public ActionSetSourceIp(int actionKey, String sourceIp) {
31 this(actionKey, sourceIp, null);
34 public ActionSetSourceIp(String sourceIp, String sourceMask) {
35 this(0, sourceIp, sourceMask);
38 public ActionSetSourceIp(int actionKey, String sourceIp, String sourceMask) {
39 this(actionKey, new Ipv4Prefix(sourceIp + "/" + (sourceMask != null ? sourceMask : "32")));
42 public ActionSetSourceIp(Ipv4Prefix source) {
46 public ActionSetSourceIp(int actionKey, Ipv4Prefix source) {
52 public Action buildAction() {
53 return buildAction(getActionKey());
57 public Action buildAction(int newActionKey) {
58 return new ActionBuilder()
59 .setAction(new SetFieldCaseBuilder()
60 .setSetField(new SetFieldBuilder()
61 .setLayer3Match(new Ipv4MatchBuilder()
62 .setIpv4Source(new Ipv4Prefix(source)).build())
65 .setKey(new ActionKey(newActionKey))
69 public Ipv4Prefix getSource() {
74 public boolean equals(Object other) {
78 if (other == null || getClass() != other.getClass()) {
81 if (!super.equals(other)) {
85 ActionSetSourceIp that = (ActionSetSourceIp) other;
87 return source != null ? source.equals(that.source) : that.source == null;
91 public int hashCode() {
92 int result = super.hashCode();
93 result = 31 * result + (source != null ? source.hashCode() : 0);
98 public String toString() {
99 return "ActionSetSourceIp [source=" + source + ", getActionKey()=" + getActionKey() + "]";