Pavlin Radoslavov

Updated the Flow Mod builders (FlowModBuilder, FlowModBuilderVer10,

and FlowModBuilderVer13) to use Ip4Address and Ip4Prefix
instead of the generic IpAddress and IpPrefix when handling
IPv4 source and destination.

Change-Id: If35d735efe4cf557c79dc04eccf38f6a909e4506
......@@ -30,8 +30,8 @@ import org.onlab.onos.net.flow.criteria.Criteria.TcpPortCriterion;
import org.onlab.onos.net.flow.criteria.Criteria.VlanIdCriterion;
import org.onlab.onos.net.flow.criteria.Criteria.VlanPcpCriterion;
import org.onlab.onos.net.flow.criteria.Criterion;
import org.onlab.packet.IpAddress;
import org.onlab.packet.IpPrefix;
import org.onlab.packet.Ip4Address;
import org.onlab.packet.Ip4Prefix;
import org.projectfloodlight.openflow.protocol.OFFactory;
import org.projectfloodlight.openflow.protocol.OFFlowAdd;
import org.projectfloodlight.openflow.protocol.OFFlowDelete;
......@@ -124,6 +124,7 @@ public abstract class FlowModBuilder {
Match.Builder mBuilder = factory.buildMatch();
EthCriterion eth;
IPCriterion ip;
Ip4Prefix ip4Prefix;
TcpPortCriterion tp;
for (Criterion c : selector.criteria()) {
switch (c.type()) {
......@@ -145,32 +146,32 @@ public abstract class FlowModBuilder {
break;
case IPV4_DST:
ip = (IPCriterion) c;
if (ip.ip().prefixLength() != IpPrefix.MAX_INET_MASK_LENGTH) {
IpAddress maskAddr =
IpAddress.makeMaskPrefix(ip.ip().address().version(),
ip.ip().prefixLength());
ip4Prefix = ip.ip().getIp4Prefix();
if (ip4Prefix.prefixLength() != Ip4Prefix.MAX_MASK_LENGTH) {
Ip4Address maskAddr =
Ip4Address.makeMaskPrefix(ip4Prefix.prefixLength());
Masked<IPv4Address> maskedIp =
Masked.of(IPv4Address.of(ip.ip().address().toInt()),
Masked.of(IPv4Address.of(ip4Prefix.address().toInt()),
IPv4Address.of(maskAddr.toInt()));
mBuilder.setMasked(MatchField.IPV4_DST, maskedIp);
} else {
mBuilder.setExact(MatchField.IPV4_DST,
IPv4Address.of(ip.ip().address().toInt()));
IPv4Address.of(ip4Prefix.address().toInt()));
}
break;
case IPV4_SRC:
ip = (IPCriterion) c;
if (ip.ip().prefixLength() != IpPrefix.MAX_INET_MASK_LENGTH) {
IpAddress maskAddr =
IpAddress.makeMaskPrefix(ip.ip().address().version(),
ip.ip().prefixLength());
ip4Prefix = ip.ip().getIp4Prefix();
if (ip4Prefix.prefixLength() != Ip4Prefix.MAX_MASK_LENGTH) {
Ip4Address maskAddr =
Ip4Address.makeMaskPrefix(ip4Prefix.prefixLength());
Masked<IPv4Address> maskedIp =
Masked.of(IPv4Address.of(ip.ip().address().toInt()),
Masked.of(IPv4Address.of(ip4Prefix.address().toInt()),
IPv4Address.of(maskAddr.toInt()));
mBuilder.setMasked(MatchField.IPV4_SRC, maskedIp);
} else {
mBuilder.setExact(MatchField.IPV4_SRC,
IPv4Address.of(ip.ip().address().toInt()));
IPv4Address.of(ip4Prefix.address().toInt()));
}
break;
case IP_PROTO:
......
......@@ -29,6 +29,7 @@ import org.onlab.onos.net.flow.instructions.L2ModificationInstruction.ModVlanIdI
import org.onlab.onos.net.flow.instructions.L2ModificationInstruction.ModVlanPcpInstruction;
import org.onlab.onos.net.flow.instructions.L3ModificationInstruction;
import org.onlab.onos.net.flow.instructions.L3ModificationInstruction.ModIPInstruction;
import org.onlab.packet.Ip4Address;
import org.projectfloodlight.openflow.protocol.OFFactory;
import org.projectfloodlight.openflow.protocol.OFFlowAdd;
import org.projectfloodlight.openflow.protocol.OFFlowDelete;
......@@ -166,13 +167,16 @@ public class FlowModBuilderVer10 extends FlowModBuilder {
private OFAction buildL3Modification(Instruction i) {
L3ModificationInstruction l3m = (L3ModificationInstruction) i;
ModIPInstruction ip;
Ip4Address ip4;
switch (l3m.subtype()) {
case IP_DST:
ip = (ModIPInstruction) i;
return factory().actions().setNwDst(IPv4Address.of(ip.ip().toInt()));
ip4 = ip.ip().getIp4Address();
return factory().actions().setNwDst(IPv4Address.of(ip4.toInt()));
case IP_SRC:
ip = (ModIPInstruction) i;
return factory().actions().setNwSrc(IPv4Address.of(ip.ip().toInt()));
ip4 = ip.ip().getIp4Address();
return factory().actions().setNwSrc(IPv4Address.of(ip4.toInt()));
default:
log.warn("Unimplemented action type {}.", l3m.subtype());
break;
......
......@@ -31,6 +31,7 @@ import org.onlab.onos.net.flow.instructions.L2ModificationInstruction.ModVlanIdI
import org.onlab.onos.net.flow.instructions.L2ModificationInstruction.ModVlanPcpInstruction;
import org.onlab.onos.net.flow.instructions.L3ModificationInstruction;
import org.onlab.onos.net.flow.instructions.L3ModificationInstruction.ModIPInstruction;
import org.onlab.packet.Ip4Address;
import org.projectfloodlight.openflow.protocol.OFFactory;
import org.projectfloodlight.openflow.protocol.OFFlowAdd;
import org.projectfloodlight.openflow.protocol.OFFlowDelete;
......@@ -230,14 +231,17 @@ public class FlowModBuilderVer13 extends FlowModBuilder {
private OFAction buildL3Modification(Instruction i) {
L3ModificationInstruction l3m = (L3ModificationInstruction) i;
ModIPInstruction ip;
Ip4Address ip4;
OFOxm<?> oxm = null;
switch (l3m.subtype()) {
case IP_DST:
ip = (ModIPInstruction) i;
oxm = factory().oxms().ipv4Dst(IPv4Address.of(ip.ip().toInt()));
ip4 = ip.ip().getIp4Address();
oxm = factory().oxms().ipv4Dst(IPv4Address.of(ip4.toInt()));
case IP_SRC:
ip = (ModIPInstruction) i;
oxm = factory().oxms().ipv4Src(IPv4Address.of(ip.ip().toInt()));
ip4 = ip.ip().getIp4Address();
oxm = factory().oxms().ipv4Src(IPv4Address.of(ip4.toInt()));
default:
log.warn("Unimplemented action type {}.", l3m.subtype());
break;
......