Search in sources :

Example 1 with U16

use of org.projectfloodlight.openflow.types.U16 in project onos by opennetworkinglab.

the class NiciraExtensionTreatmentInterpreter method mapInstruction.

@Override
public OFAction mapInstruction(OFFactory factory, ExtensionTreatment extensionTreatment) {
    ExtensionTreatmentType type = extensionTreatment.type();
    if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_TUNNEL_DST.type())) {
        NiciraSetTunnelDst tunnelDst = (NiciraSetTunnelDst) extensionTreatment;
        return factory.actions().setField(factory.oxms().tunnelIpv4Dst(IPv4Address.of(tunnelDst.tunnelDst().toInt())));
    }
    if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_RESUBMIT.type())) {
        NiciraResubmit resubmit = (NiciraResubmit) extensionTreatment;
        return factory.actions().niciraResubmit((int) resubmit.inPort().toLong(), resubmit.table());
    }
    if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_RESUBMIT_TABLE.type())) {
        NiciraResubmitTable resubmitTable = (NiciraResubmitTable) extensionTreatment;
        return factory.actions().niciraResubmitTable((int) resubmitTable.inPort().toLong(), resubmitTable.table());
    }
    if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_SPI.type())) {
        NiciraSetNshSpi niciraNshSpi = (NiciraSetNshSpi) extensionTreatment;
        return factory.actions().setField(factory.oxms().nsp(U32.of(niciraNshSpi.nshSpi().servicePathId())));
    }
    if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_SI.type())) {
        NiciraSetNshSi niciraNshSi = (NiciraSetNshSi) extensionTreatment;
        return factory.actions().setField(factory.oxms().nsi(U8.of(niciraNshSi.nshSi().serviceIndex())));
    }
    if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_CH1.type())) {
        NiciraSetNshContextHeader niciraNshch = (NiciraSetNshContextHeader) extensionTreatment;
        return factory.actions().setField(factory.oxms().nshC1(U32.of(niciraNshch.nshCh().nshContextHeader())));
    }
    if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_CH2.type())) {
        NiciraSetNshContextHeader niciraNshch = (NiciraSetNshContextHeader) extensionTreatment;
        return factory.actions().setField(factory.oxms().nshC2(U32.of(niciraNshch.nshCh().nshContextHeader())));
    }
    if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_CH3.type())) {
        NiciraSetNshContextHeader niciraNshch = (NiciraSetNshContextHeader) extensionTreatment;
        return factory.actions().setField(factory.oxms().nshC3(U32.of(niciraNshch.nshCh().nshContextHeader())));
    }
    if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_CH4.type())) {
        NiciraSetNshContextHeader niciraNshch = (NiciraSetNshContextHeader) extensionTreatment;
        return factory.actions().setField(factory.oxms().nshC4(U32.of(niciraNshch.nshCh().nshContextHeader())));
    }
    if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_NSH_MDTYPE.type())) {
        NiciraNshMdType niciraNshMdType = (NiciraNshMdType) extensionTreatment;
        return factory.actions().setField(factory.oxms().nshMdtype(U8.of(niciraNshMdType.nshMdType())));
    }
    if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_NSH_NP.type())) {
        NiciraNshNp niciraNshNp = (NiciraNshNp) extensionTreatment;
        return factory.actions().setField(factory.oxms().nshNp(U8.of(niciraNshNp.nshNp())));
    }
    if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_ENCAP_ETH_SRC.type())) {
        NiciraEncapEthSrc niciraEncapEthSrc = (NiciraEncapEthSrc) extensionTreatment;
        return factory.actions().setField(factory.oxms().encapEthSrc(MacAddress.of(niciraEncapEthSrc.encapEthSrc().toBytes())));
    }
    if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_ENCAP_ETH_DST.type())) {
        NiciraEncapEthDst niciraEncapEthDst = (NiciraEncapEthDst) extensionTreatment;
        return factory.actions().setField(factory.oxms().encapEthDst(MacAddress.of(niciraEncapEthDst.encapEthDst().toBytes())));
    }
    if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_ENCAP_ETH_TYPE.type())) {
        NiciraEncapEthType niciraEncapEthType = (NiciraEncapEthType) extensionTreatment;
        return factory.actions().setField(factory.oxms().encapEthType(U16.of(niciraEncapEthType.encapEthType())));
    }
    if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_PUSH_NSH.type())) {
        return factory.actions().niciraPushNsh();
    }
    if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_POP_NSH.type())) {
        return factory.actions().niciraPopNsh();
    }
    if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_TUN_GPE_NP.type())) {
        NiciraTunGpeNp niciraTunGpeNp = (NiciraTunGpeNp) extensionTreatment;
        return factory.actions().setField(factory.oxms().tunGpeNp(U8.of(niciraTunGpeNp.tunGpeNp())));
    }
    if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_ARP_SHA_TO_THA.type()) || type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_ARP_SPA_TO_TPA.type()) || type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_ETH_SRC_TO_DST.type()) || type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_IP_SRC_TO_DST.type()) || type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_NSH_C1_TO_C1.type()) || type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_NSH_C2_TO_C2.type()) || type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_NSH_C3_TO_C3.type()) || type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_NSH_C4_TO_C4.type()) || type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_TUN_IPV4_DST_TO_TUN_IPV4_DST.type()) || type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_TUN_ID_TO_TUN_ID.type()) || type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_MOV_NSH_C2_TO_TUN_ID.type())) {
        MoveExtensionTreatment mov = (MoveExtensionTreatment) extensionTreatment;
        OFActionNiciraMove.Builder action = factory.actions().buildNiciraMove();
        action.setDstOfs(mov.dstOffset());
        action.setSrcOfs(mov.srcOffset());
        action.setNBits(mov.nBits());
        action.setSrc(mov.src());
        action.setDst(mov.dst());
        return action.build();
    }
    if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_LOAD.type())) {
        NiciraLoad load = (NiciraLoad) extensionTreatment;
        OFActionNiciraLoad.Builder action = factory.actions().buildNiciraLoad();
        action.setOfsNbits(load.ofsNbits());
        action.setDst(load.dst());
        action.setValue(U64.of(load.value()));
        return action.build();
    }
    if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_CT.type())) {
        NiciraCt niciraCt = (NiciraCt) extensionTreatment;
        OFActionNiciraCt.Builder ctAction = factory.actions().buildNiciraCt();
        ctAction.setFlags(niciraCt.niciraCtFlags());
        ctAction.setZoneSrc(niciraCt.niciraCtZoneSrc());
        ctAction.setZone(niciraCt.niciraCtZone());
        ctAction.setRecircTable(niciraCt.niciraCtRecircTable());
        ctAction.setAlg(niciraCt.niciraCtAlg());
        List<OFAction> actions = Lists.newArrayList();
        for (ExtensionTreatment nestedTreatment : niciraCt.niciraCtNestActions()) {
            if (nestedTreatment instanceof NiciraNat) {
                NiciraNat niciraNat = (NiciraNat) nestedTreatment;
                OFActionNiciraNat.Builder action = factory.actions().buildNiciraNat();
                action.setFlags(niciraNat.niciraNatFlags());
                int presetFlags = niciraNat.niciraNatPresentFlags();
                action.setRangePresent(presetFlags);
                List<IPv4Address> ipv4RangeList = Lists.newArrayList();
                List<IPv6Address> ipv6RangeList = Lists.newArrayList();
                List<U16> portRangeList = Lists.newArrayList();
                List<U8> padList = Lists.newArrayList();
                if ((presetFlags & NAT_RANGE_IPV4_MIN) != 0) {
                    ipv4RangeList.add(IPv4Address.of(niciraNat.niciraNatIpAddressMin().getIp4Address().toString()));
                }
                if ((presetFlags & NAT_RANGE_IPV4_MAX) != 0) {
                    ipv4RangeList.add(IPv4Address.of(niciraNat.niciraNatIpAddressMax().getIp4Address().toString()));
                }
                if ((presetFlags & NAT_RANGE_IPV6_MIN) != 0) {
                    ipv6RangeList.add(IPv6Address.of(niciraNat.niciraNatIpAddressMin().getIp6Address().toString()));
                }
                if ((presetFlags & NAT_RANGE_IPV6_MAX) != 0) {
                    ipv6RangeList.add(IPv6Address.of(niciraNat.niciraNatIpAddressMax().getIp6Address().toString()));
                }
                if ((presetFlags & NAT_RANGE_PROTO_MIN) != 0) {
                    portRangeList.add(U16.of(niciraNat.niciraNatPortMin()));
                }
                if ((presetFlags & NAT_RANGE_PROTO_MAX) != 0) {
                    portRangeList.add(U16.of(niciraNat.niciraNatPortMax()));
                }
                for (; (ipv6RangeList.size() * 16 + ipv4RangeList.size() * 4 + portRangeList.size() * 2 + padList.size()) % 8 != 0; ) {
                    padList.add(U8.ofRaw((byte) 0));
                }
                action.setIpv4Range(ipv4RangeList);
                action.setIpv6Range(ipv6RangeList);
                action.setPortRange(portRangeList);
                action.setPad(padList);
                // nat action must be nested in ct action
                actions.add(action.build());
            } else if (nestedTreatment instanceof NiciraLoad) {
                NiciraLoad niciraLoad = (NiciraLoad) nestedTreatment;
                OFActionNiciraLoad.Builder action = factory.actions().buildNiciraLoad();
                action.setDst(niciraLoad.dst());
                action.setOfsNbits(niciraLoad.ofsNbits());
                action.setValue(U64.of(niciraLoad.value()));
                actions.add(action.build());
            }
        }
        ctAction.setActions(actions);
        return ctAction.build();
    }
    if (type.equals(ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_CT_CLEAR.type())) {
        return factory.actions().niciraCtClear();
    }
    return null;
}
Also used : U8(org.projectfloodlight.openflow.types.U8) IPv6Address(org.projectfloodlight.openflow.types.IPv6Address) IPv4Address(org.projectfloodlight.openflow.types.IPv4Address) OFActionNiciraLoad(org.projectfloodlight.openflow.protocol.action.OFActionNiciraLoad) OFActionNiciraNat(org.projectfloodlight.openflow.protocol.action.OFActionNiciraNat) OFActionNiciraMove(org.projectfloodlight.openflow.protocol.action.OFActionNiciraMove) ExtensionTreatment(org.onosproject.net.flow.instructions.ExtensionTreatment) ExtensionTreatmentType(org.onosproject.net.flow.instructions.ExtensionTreatmentType) OFActionNiciraResubmit(org.projectfloodlight.openflow.protocol.action.OFActionNiciraResubmit) OFActionNiciraNat(org.projectfloodlight.openflow.protocol.action.OFActionNiciraNat) OFAction(org.projectfloodlight.openflow.protocol.action.OFAction) OFActionNiciraResubmitTable(org.projectfloodlight.openflow.protocol.action.OFActionNiciraResubmitTable) OFActionNiciraCt(org.projectfloodlight.openflow.protocol.action.OFActionNiciraCt) OFActionNiciraCt(org.projectfloodlight.openflow.protocol.action.OFActionNiciraCt) OFActionNiciraLoad(org.projectfloodlight.openflow.protocol.action.OFActionNiciraLoad) U16(org.projectfloodlight.openflow.types.U16)

Aggregations

ExtensionTreatment (org.onosproject.net.flow.instructions.ExtensionTreatment)1 ExtensionTreatmentType (org.onosproject.net.flow.instructions.ExtensionTreatmentType)1 OFAction (org.projectfloodlight.openflow.protocol.action.OFAction)1 OFActionNiciraCt (org.projectfloodlight.openflow.protocol.action.OFActionNiciraCt)1 OFActionNiciraLoad (org.projectfloodlight.openflow.protocol.action.OFActionNiciraLoad)1 OFActionNiciraMove (org.projectfloodlight.openflow.protocol.action.OFActionNiciraMove)1 OFActionNiciraNat (org.projectfloodlight.openflow.protocol.action.OFActionNiciraNat)1 OFActionNiciraResubmit (org.projectfloodlight.openflow.protocol.action.OFActionNiciraResubmit)1 OFActionNiciraResubmitTable (org.projectfloodlight.openflow.protocol.action.OFActionNiciraResubmitTable)1 IPv4Address (org.projectfloodlight.openflow.types.IPv4Address)1 IPv6Address (org.projectfloodlight.openflow.types.IPv6Address)1 U16 (org.projectfloodlight.openflow.types.U16)1 U8 (org.projectfloodlight.openflow.types.U8)1