Search in sources :

Example 1 with ModArpEthInstruction

use of org.onosproject.net.flow.instructions.L3ModificationInstruction.ModArpEthInstruction 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);
    }
}
Also used : IpPrefix(org.onlab.packet.IpPrefix) ModArpEthInstruction(org.onosproject.net.flow.instructions.L3ModificationInstruction.ModArpEthInstruction) ModIPv6FlowLabelInstruction(org.onosproject.net.flow.instructions.L3ModificationInstruction.ModIPv6FlowLabelInstruction) IntentCompilationException(org.onosproject.net.intent.IntentCompilationException) ModArpOpInstruction(org.onosproject.net.flow.instructions.L3ModificationInstruction.ModArpOpInstruction) ModIPInstruction(org.onosproject.net.flow.instructions.L3ModificationInstruction.ModIPInstruction) ModArpIPInstruction(org.onosproject.net.flow.instructions.L3ModificationInstruction.ModArpIPInstruction)

Example 2 with ModArpEthInstruction

use of org.onosproject.net.flow.instructions.L3ModificationInstruction.ModArpEthInstruction 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;
}
Also used : ModArpEthInstruction(org.onosproject.net.flow.instructions.L3ModificationInstruction.ModArpEthInstruction) L3ModificationInstruction(org.onosproject.net.flow.instructions.L3ModificationInstruction) Ip4Address(org.onlab.packet.Ip4Address) ModIPInstruction(org.onosproject.net.flow.instructions.L3ModificationInstruction.ModIPInstruction) ModArpIPInstruction(org.onosproject.net.flow.instructions.L3ModificationInstruction.ModArpIPInstruction) Ip6Address(org.onlab.packet.Ip6Address) ModIPv6FlowLabelInstruction(org.onosproject.net.flow.instructions.L3ModificationInstruction.ModIPv6FlowLabelInstruction) ModArpOpInstruction(org.onosproject.net.flow.instructions.L3ModificationInstruction.ModArpOpInstruction) IpDscp(org.projectfloodlight.openflow.types.IpDscp)

Aggregations

ModArpEthInstruction (org.onosproject.net.flow.instructions.L3ModificationInstruction.ModArpEthInstruction)2 ModArpIPInstruction (org.onosproject.net.flow.instructions.L3ModificationInstruction.ModArpIPInstruction)2 ModArpOpInstruction (org.onosproject.net.flow.instructions.L3ModificationInstruction.ModArpOpInstruction)2 ModIPInstruction (org.onosproject.net.flow.instructions.L3ModificationInstruction.ModIPInstruction)2 ModIPv6FlowLabelInstruction (org.onosproject.net.flow.instructions.L3ModificationInstruction.ModIPv6FlowLabelInstruction)2 Ip4Address (org.onlab.packet.Ip4Address)1 Ip6Address (org.onlab.packet.Ip6Address)1 IpPrefix (org.onlab.packet.IpPrefix)1 L3ModificationInstruction (org.onosproject.net.flow.instructions.L3ModificationInstruction)1 IntentCompilationException (org.onosproject.net.intent.IntentCompilationException)1 IpDscp (org.projectfloodlight.openflow.types.IpDscp)1