use of org.onosproject.net.flow.instructions.L3ModificationInstruction.ModIPInstruction in project onos by opennetworkinglab.
the class LinkCollectionCompiler method updateBuilder.
/**
* Update the selector builder using a L3 instruction.
*
* @param builder the builder to update
* @param l3instruction the l3 instruction to use
*/
private void updateBuilder(TrafficSelector.Builder builder, L3ModificationInstruction l3instruction) {
// TODO check ethernet proto
switch(l3instruction.subtype()) {
case IPV4_SRC:
case IPV4_DST:
case IPV6_SRC:
case IPV6_DST:
ModIPInstruction ipInstr = (ModIPInstruction) l3instruction;
// TODO check if ip falls in original prefix
IpPrefix prefix = ipInstr.ip().toIpPrefix();
switch(ipInstr.subtype()) {
case IPV4_SRC:
builder.matchIPSrc(prefix);
break;
case IPV4_DST:
builder.matchIPSrc(prefix);
break;
case IPV6_SRC:
builder.matchIPv6Src(prefix);
break;
case IPV6_DST:
builder.matchIPv6Dst(prefix);
break;
default:
throw new IntentCompilationException(UNSUPPORTED_IP_SUBTYPE);
}
break;
case IPV6_FLABEL:
ModIPv6FlowLabelInstruction ipFlowInstr = (ModIPv6FlowLabelInstruction) l3instruction;
builder.matchIPv6FlowLabel(ipFlowInstr.flowLabel());
break;
case DEC_TTL:
// no-op
break;
case TTL_OUT:
// no-op
break;
case TTL_IN:
// no-op
break;
case ARP_SPA:
ModArpIPInstruction srcArpIpInstr = (ModArpIPInstruction) l3instruction;
if (srcArpIpInstr.ip().isIp4()) {
builder.matchArpSpa((Ip4Address) srcArpIpInstr.ip());
} else {
throw new IntentCompilationException(UNSUPPORTED_ARP);
}
break;
case ARP_SHA:
ModArpEthInstruction srcArpEthInstr = (ModArpEthInstruction) l3instruction;
builder.matchArpSha(srcArpEthInstr.mac());
break;
case ARP_TPA:
ModArpIPInstruction dstArpIpInstr = (ModArpIPInstruction) l3instruction;
if (dstArpIpInstr.ip().isIp4()) {
builder.matchArpTpa((Ip4Address) dstArpIpInstr.ip());
} else {
throw new IntentCompilationException(UNSUPPORTED_ARP);
}
break;
case ARP_THA:
ModArpEthInstruction dstArpEthInstr = (ModArpEthInstruction) l3instruction;
builder.matchArpTha(dstArpEthInstr.mac());
break;
case ARP_OP:
ModArpOpInstruction arpOpInstr = (ModArpOpInstruction) l3instruction;
// FIXME is the long to int cast safe?
builder.matchArpOp((int) arpOpInstr.op());
break;
default:
throw new IntentCompilationException(UNSUPPORTED_L3);
}
}
use of org.onosproject.net.flow.instructions.L3ModificationInstruction.ModIPInstruction in project onos by opennetworkinglab.
the class FlowModBuilderVer10 method buildL3Modification.
private OFAction buildL3Modification(Instruction i) {
L3ModificationInstruction l3m = (L3ModificationInstruction) i;
ModIPInstruction ip;
Ip4Address ip4;
switch(l3m.subtype()) {
case IPV4_SRC:
ip = (ModIPInstruction) i;
ip4 = ip.ip().getIp4Address();
return factory().actions().setNwSrc(IPv4Address.of(ip4.toInt()));
case IPV4_DST:
ip = (ModIPInstruction) i;
ip4 = ip.ip().getIp4Address();
return factory().actions().setNwDst(IPv4Address.of(ip4.toInt()));
default:
log.warn("Unimplemented action type {}.", l3m.subtype());
break;
}
return null;
}
use of org.onosproject.net.flow.instructions.L3ModificationInstruction.ModIPInstruction in project onos by opennetworkinglab.
the class InstructionJsonMatcher method matchesSafely.
@Override
public boolean matchesSafely(JsonNode jsonInstruction, Description description) {
// check type
final JsonNode jsonTypeNode = jsonInstruction.get("type");
final String jsonType = jsonTypeNode.textValue();
final String type = instruction.type().name();
if (!jsonType.equals(type)) {
description.appendText("type was " + type);
return false;
}
if (instruction instanceof ModMplsHeaderInstruction) {
return matchModMplsHeaderInstruction(jsonInstruction, description);
} else if (instruction instanceof OutputInstruction) {
return matchOutputInstruction(jsonInstruction, description);
} else if (instruction instanceof GroupInstruction) {
return matchGroupInstruction(jsonInstruction, description);
} else if (instruction instanceof MeterInstruction) {
return matchMeterInstruction(jsonInstruction, description);
} else if (instruction instanceof SetQueueInstruction) {
return matchSetQueueInstruction(jsonInstruction, description);
} else if (instruction instanceof ModOchSignalInstruction) {
return matchModOchSingalInstruction(jsonInstruction, description);
} else if (instruction instanceof ModEtherInstruction) {
return matchModEtherInstruction(jsonInstruction, description);
} else if (instruction instanceof ModVlanIdInstruction) {
return matchModVlanIdInstruction(jsonInstruction, description);
} else if (instruction instanceof ModVlanPcpInstruction) {
return matchModVlanPcpInstruction(jsonInstruction, description);
} else if (instruction instanceof ModIPInstruction) {
return matchModIpInstruction(jsonInstruction, description);
} else if (instruction instanceof ModIPv6FlowLabelInstruction) {
return matchModIPv6FlowLabelInstruction(jsonInstruction, description);
} else if (instruction instanceof ModMplsLabelInstruction) {
return matchModMplsLabelInstruction(jsonInstruction, description);
} else if (instruction instanceof ModOduSignalIdInstruction) {
return matchModOduSingalIdInstruction(jsonInstruction, description);
} else if (instruction instanceof PiInstruction) {
return matchPiInstruction(jsonInstruction, description);
} else if (instruction instanceof NoActionInstruction) {
return true;
}
return false;
}
use of org.onosproject.net.flow.instructions.L3ModificationInstruction.ModIPInstruction in project onos by opennetworkinglab.
the class InstructionJsonMatcher method matchModIpInstruction.
/**
* Matches the contents of a mod ip instruction.
*
* @param instructionJson JSON instruction to match
* @param description Description object used for recording errors
* @return true if contents match, false otherwise
*/
private boolean matchModIpInstruction(JsonNode instructionJson, Description description) {
ModIPInstruction instructionToMatch = (ModIPInstruction) instruction;
final String jsonSubtype = instructionJson.get("subtype").textValue();
if (!instructionToMatch.subtype().name().equals(jsonSubtype)) {
description.appendText("subtype was " + jsonSubtype);
return false;
}
final String jsonType = instructionJson.get("type").textValue();
if (!instructionToMatch.type().name().equals(jsonType)) {
description.appendText("type was " + jsonType);
return false;
}
final String jsonIp = instructionJson.get("ip").textValue();
final String ip = instructionToMatch.ip().toString();
if (!ip.equals(jsonIp)) {
description.appendText("ip was " + jsonIp);
return false;
}
return true;
}
use of org.onosproject.net.flow.instructions.L3ModificationInstruction.ModIPInstruction in project onos by opennetworkinglab.
the class FlowModBuilderVer13 method buildL3Modification.
protected OFAction buildL3Modification(Instruction i) {
L3ModificationInstruction l3m = (L3ModificationInstruction) i;
ModIPInstruction ip;
Ip4Address ip4;
Ip6Address ip6;
OFOxm<?> oxm = null;
switch(l3m.subtype()) {
case IPV4_SRC:
ip = (ModIPInstruction) i;
ip4 = ip.ip().getIp4Address();
oxm = factory().oxms().ipv4Src(IPv4Address.of(ip4.toInt()));
break;
case IPV4_DST:
ip = (ModIPInstruction) i;
ip4 = ip.ip().getIp4Address();
oxm = factory().oxms().ipv4Dst(IPv4Address.of(ip4.toInt()));
break;
case IP_DSCP:
L3ModificationInstruction.ModDscpInstruction dscp = (L3ModificationInstruction.ModDscpInstruction) i;
IpDscp ipDscp = IpDscp.of(dscp.dscp());
oxm = factory().oxms().ipDscp(ipDscp);
break;
case IPV6_SRC:
ip = (ModIPInstruction) i;
ip6 = ip.ip().getIp6Address();
oxm = factory().oxms().ipv6Src(IPv6Address.of(ip6.toOctets()));
break;
case IPV6_DST:
ip = (ModIPInstruction) i;
ip6 = ip.ip().getIp6Address();
oxm = factory().oxms().ipv6Dst(IPv6Address.of(ip6.toOctets()));
break;
case IPV6_FLABEL:
ModIPv6FlowLabelInstruction flowLabelInstruction = (ModIPv6FlowLabelInstruction) i;
int flowLabel = flowLabelInstruction.flowLabel();
oxm = factory().oxms().ipv6Flabel(IPv6FlowLabel.of(flowLabel));
break;
case ARP_SPA:
ModArpIPInstruction sAip = (ModArpIPInstruction) i;
ip4 = sAip.ip().getIp4Address();
oxm = factory().oxms().arpSpa(IPv4Address.of(ip4.toInt()));
break;
case ARP_SHA:
ModArpEthInstruction sAei = (ModArpEthInstruction) i;
oxm = factory().oxms().arpSha(MacAddress.of(sAei.mac().toLong()));
break;
case ARP_TPA:
ModArpIPInstruction dAip = (ModArpIPInstruction) i;
ip4 = dAip.ip().getIp4Address();
oxm = factory().oxms().arpTpa(IPv4Address.of(ip4.toInt()));
break;
case ARP_THA:
ModArpEthInstruction dAei = (ModArpEthInstruction) i;
oxm = factory().oxms().arpTha(MacAddress.of(dAei.mac().toLong()));
break;
case ARP_OP:
ModArpOpInstruction oi = (ModArpOpInstruction) i;
oxm = factory().oxms().arpOp(ArpOpcode.of((int) oi.op()));
break;
case DEC_TTL:
return factory().actions().decNwTtl();
case TTL_IN:
return factory().actions().copyTtlIn();
case TTL_OUT:
return factory().actions().copyTtlOut();
default:
log.warn("Unimplemented action type {}.", l3m.subtype());
break;
}
if (oxm != null) {
return factory().actions().buildSetField().setField(oxm).build();
}
return null;
}
Aggregations