blob: e8b72e7a9fc12ce63bf39bad5e602d124618b4a8 [file] [log] [blame]
/*
* Copyright 2014 Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onlab.onos.net.flow.instructions;
import static com.google.common.base.MoreObjects.toStringHelper;
import java.util.Objects;
import org.onlab.packet.IpAddress;
/**
* Abstraction of a single traffic treatment step.
*/
public abstract class L3ModificationInstruction implements Instruction {
/**
* Represents the type of traffic treatment.
*/
public enum L3SubType {
/**
* Ether src modification.
*/
IP_SRC,
/**
* Ether dst modification.
*/
IP_DST
//TODO: remaining types
}
/**
* Returns the subtype of the modification instruction.
* @return type of instruction
*/
public abstract L3SubType subtype();
@Override
public Type type() {
return Type.L3MODIFICATION;
}
/**
* Represents a L3 src/dst modification instruction.
*/
public static final class ModIPInstruction extends L3ModificationInstruction {
private final L3SubType subtype;
private final IpAddress ip;
public ModIPInstruction(L3SubType subType, IpAddress addr) {
this.subtype = subType;
this.ip = addr;
}
@Override
public L3SubType subtype() {
return this.subtype;
}
public IpAddress ip() {
return this.ip;
}
@Override
public String toString() {
return toStringHelper(subtype().toString())
.add("ip", ip).toString();
}
@Override
public int hashCode() {
return Objects.hash(type(), subtype(), ip);
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj instanceof ModIPInstruction) {
ModIPInstruction that = (ModIPInstruction) obj;
return Objects.equals(ip, that.ip) &&
Objects.equals(this.type(), that.type()) &&
Objects.equals(this.subtype(), that.subtype());
}
return false;
}
}
}