Search in sources :

Example 16 with ExtensionTreatment

use of org.onosproject.net.flow.instructions.ExtensionTreatment in project onos by opennetworkinglab.

the class FlowViewMessageHandlerTest method renderExtensionInstruction.

@Test
public void renderExtensionInstruction() {
    title("renderExtensionInstruction");
    ExtensionTreatment extn = new Ofdpa3SetMplsType((short) 32);
    DeviceId devid = deviceId(DEV_OF_204);
    instr = Instructions.extension(extn, devid);
    string = instr.toString();
    render = handler.renderInstructionForDisplay(instr);
    print(string);
    print(render);
    assertEquals("unexpected toString", EXT_FULL_STR, string);
    assertEquals("unexpected short string", EXT_NO_DPID, render);
}
Also used : DeviceId(org.onosproject.net.DeviceId) ExtensionTreatment(org.onosproject.net.flow.instructions.ExtensionTreatment) Ofdpa3SetMplsType(org.onosproject.driver.extensions.Ofdpa3SetMplsType) Test(org.junit.Test)

Example 17 with ExtensionTreatment

use of org.onosproject.net.flow.instructions.ExtensionTreatment in project onos by opennetworkinglab.

the class DecodeInstructionCodecHelper method decodeExtension.

/**
 * Decodes a extension instruction.
 *
 * @return extension treatment
 */
private Instruction decodeExtension() {
    ObjectNode node = (ObjectNode) json.get(InstructionCodec.EXTENSION);
    if (node != null) {
        DeviceId deviceId = getDeviceId();
        ServiceDirectory serviceDirectory = new DefaultServiceDirectory();
        DeviceService deviceService = serviceDirectory.get(DeviceService.class);
        Device device = deviceService.getDevice(deviceId);
        if (device == null) {
            throw new IllegalArgumentException("Device not found");
        }
        if (device.is(ExtensionTreatmentCodec.class)) {
            ExtensionTreatmentCodec treatmentCodec = device.as(ExtensionTreatmentCodec.class);
            ExtensionTreatment treatment = treatmentCodec.decode(node, context);
            return Instructions.extension(treatment, deviceId);
        } else {
            throw new IllegalArgumentException("There is no codec to decode extension for device " + deviceId.toString());
        }
    }
    return null;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) DeviceId(org.onosproject.net.DeviceId) ServiceDirectory(org.onlab.osgi.ServiceDirectory) DefaultServiceDirectory(org.onlab.osgi.DefaultServiceDirectory) Device(org.onosproject.net.Device) ExtensionTreatmentCodec(org.onosproject.net.flow.ExtensionTreatmentCodec) DeviceService(org.onosproject.net.device.DeviceService) DefaultServiceDirectory(org.onlab.osgi.DefaultServiceDirectory) ExtensionTreatment(org.onosproject.net.flow.instructions.ExtensionTreatment)

Example 18 with ExtensionTreatment

use of org.onosproject.net.flow.instructions.ExtensionTreatment in project onos by opennetworkinglab.

the class ExtensionInstructionSerializer method read.

@Override
public Instructions.ExtensionInstructionWrapper read(Kryo kryo, Input input, Class<Instructions.ExtensionInstructionWrapper> type) {
    ExtensionTreatmentType exType = (ExtensionTreatmentType) kryo.readClassAndObject(input);
    DeviceId deviceId = (DeviceId) kryo.readClassAndObject(input);
    String driverName = (String) kryo.readClassAndObject(input);
    DriverService driverService = DefaultServiceDirectory.getService(DriverService.class);
    byte[] bytes = (byte[]) kryo.readClassAndObject(input);
    ExtensionTreatment instruction;
    try {
        DriverHandler handler = new DefaultDriverHandler(new DefaultDriverData(driverService.getDriver(driverName), deviceId));
        ExtensionTreatmentResolver resolver = handler.behaviour(ExtensionTreatmentResolver.class);
        instruction = resolver.getExtensionInstruction(exType);
        instruction.deserialize(bytes);
    } catch (ItemNotFoundException | IllegalArgumentException e) {
        instruction = new UnresolvedExtensionTreatment(bytes, exType);
    }
    return Instructions.extension(instruction, deviceId);
}
Also used : DeviceId(org.onosproject.net.DeviceId) DefaultDriverHandler(org.onosproject.net.driver.DefaultDriverHandler) ExtensionTreatmentResolver(org.onosproject.net.behaviour.ExtensionTreatmentResolver) UnresolvedExtensionTreatment(org.onosproject.net.flow.instructions.UnresolvedExtensionTreatment) DriverHandler(org.onosproject.net.driver.DriverHandler) DefaultDriverHandler(org.onosproject.net.driver.DefaultDriverHandler) ExtensionTreatment(org.onosproject.net.flow.instructions.ExtensionTreatment) UnresolvedExtensionTreatment(org.onosproject.net.flow.instructions.UnresolvedExtensionTreatment) ExtensionTreatmentType(org.onosproject.net.flow.instructions.ExtensionTreatmentType) DriverService(org.onosproject.net.driver.DriverService) DefaultDriverData(org.onosproject.net.driver.DefaultDriverData) ItemNotFoundException(org.onlab.util.ItemNotFoundException)

Example 19 with ExtensionTreatment

use of org.onosproject.net.flow.instructions.ExtensionTreatment in project onos by opennetworkinglab.

the class NiciraExtensionTreatmentInterpreter method mapAction.

@Override
public ExtensionTreatment mapAction(OFAction action) throws UnsupportedOperationException {
    if (action.getType().equals(OFActionType.SET_FIELD)) {
        OFActionSetField setFieldAction = (OFActionSetField) action;
        OFOxm<?> oxm = setFieldAction.getField();
        switch(oxm.getMatchField().id) {
            case TUNNEL_IPV4_DST:
                OFOxmTunnelIpv4Dst tunnelIpv4Dst = (OFOxmTunnelIpv4Dst) oxm;
                return new NiciraSetTunnelDst(Ip4Address.valueOf(tunnelIpv4Dst.getValue().getInt()));
            case NSP:
                OFOxmNsp nsp = (OFOxmNsp) oxm;
                return new NiciraSetNshSpi(NshServicePathId.of((nsp.getValue().getRaw())));
            case NSI:
                OFOxmNsi nsi = (OFOxmNsi) oxm;
                return new NiciraSetNshSi(NshServiceIndex.of((nsi.getValue().getRaw())));
            case NSH_C1:
                OFOxmNshC1 nshC1 = (OFOxmNshC1) oxm;
                return new NiciraSetNshContextHeader(NshContextHeader.of((nshC1.getValue().getRaw())), ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_CH1.type());
            case NSH_C2:
                OFOxmNshC2 nshC2 = (OFOxmNshC2) oxm;
                return new NiciraSetNshContextHeader(NshContextHeader.of((nshC2.getValue().getRaw())), ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_CH2.type());
            case NSH_C3:
                OFOxmNshC3 nshC3 = (OFOxmNshC3) oxm;
                return new NiciraSetNshContextHeader(NshContextHeader.of((nshC3.getValue().getRaw())), ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_CH3.type());
            case NSH_C4:
                OFOxmNshC4 nshC4 = (OFOxmNshC4) oxm;
                return new NiciraSetNshContextHeader(NshContextHeader.of((nshC4.getValue().getRaw())), ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_NSH_CH4.type());
            case NSH_MDTYPE:
                OFOxmNshMdtype nshMdType = (OFOxmNshMdtype) oxm;
                return new NiciraNshMdType((nshMdType.getValue().getRaw()));
            case NSH_NP:
                OFOxmNshNp nshNp = (OFOxmNshNp) oxm;
                return new NiciraNshNp((nshNp.getValue().getRaw()));
            case ENCAP_ETH_SRC:
                OFOxmEncapEthSrc encapEthSrc = (OFOxmEncapEthSrc) oxm;
                return new NiciraEncapEthSrc(org.onlab.packet.MacAddress.valueOf((encapEthSrc.getValue().getBytes())));
            case ENCAP_ETH_DST:
                OFOxmEncapEthDst encapEthDst = (OFOxmEncapEthDst) oxm;
                return new NiciraEncapEthDst(org.onlab.packet.MacAddress.valueOf((encapEthDst.getValue().getBytes())));
            case ENCAP_ETH_TYPE:
                OFOxmEncapEthType encapEthType = (OFOxmEncapEthType) oxm;
                return new NiciraEncapEthType((encapEthType.getValue().getRaw()));
            case TUN_GPE_NP:
                OFOxmTunGpeNp tunGpeNp = (OFOxmTunGpeNp) oxm;
                return new NiciraTunGpeNp((tunGpeNp.getValue().getRaw()));
            default:
                throw new UnsupportedOperationException("Driver does not support extension type " + oxm.getMatchField().id);
        }
    }
    if (action.getType().equals(OFActionType.EXPERIMENTER)) {
        OFActionExperimenter experimenter = (OFActionExperimenter) action;
        if (Long.valueOf(experimenter.getExperimenter()).intValue() == TYPE_NICIRA) {
            OFActionNicira nicira = (OFActionNicira) experimenter;
            switch(nicira.getSubtype()) {
                case SUB_TYPE_MOVE:
                    OFActionNiciraMove moveAction = (OFActionNiciraMove) nicira;
                    switch(Long.valueOf(moveAction.getSrc()).intValue()) {
                        case SRC_ARP_SHA:
                            return NiciraMoveTreatmentFactory.createNiciraMovArpShaToTha();
                        case SRC_ETH:
                            return NiciraMoveTreatmentFactory.createNiciraMovEthSrcToDst();
                        case SRC_IP:
                            return NiciraMoveTreatmentFactory.createNiciraMovIpSrcToDst();
                        case SRC_ARP_SPA:
                            return NiciraMoveTreatmentFactory.createNiciraMovArpSpaToTpa();
                        case NSH_C1:
                            return NiciraMoveTreatmentFactory.createNiciraMovNshC1ToC1();
                        case NSH_C2:
                            if (Long.valueOf(moveAction.getDst()).intValue() == TUN_ID) {
                                return NiciraMoveTreatmentFactory.createNiciraMovNshC2ToTunId();
                            }
                            return NiciraMoveTreatmentFactory.createNiciraMovNshC2ToC2();
                        case NSH_C3:
                            return NiciraMoveTreatmentFactory.createNiciraMovNshC3ToC3();
                        case NSH_C4:
                            return NiciraMoveTreatmentFactory.createNiciraMovNshC4ToC4();
                        case TUN_IPV4_DST:
                            return NiciraMoveTreatmentFactory.createNiciraMovTunDstToTunDst();
                        case TUN_ID:
                            return NiciraMoveTreatmentFactory.createNiciraMovTunIdToTunId();
                        default:
                            throw new UnsupportedOperationException("Driver does not support move from " + moveAction.getSrc() + " to " + moveAction.getDst() + "of length " + moveAction.getNBits());
                    }
                case SUB_TYPE_RESUBMIT:
                    OFActionNiciraResubmit resubmitAction = (OFActionNiciraResubmit) nicira;
                    return new NiciraResubmit(PortNumber.portNumber(resubmitAction.getInPort()));
                case SUB_TYPE_PUSH_NSH:
                    return new NiciraPushNsh();
                case SUB_TYPE_POP_NSH:
                    return new NiciraPopNsh();
                case SUB_TYPE_RESUBMIT_TABLE:
                    OFActionNiciraResubmitTable resubmitTable = (OFActionNiciraResubmitTable) nicira;
                    return new NiciraResubmitTable(PortNumber.portNumber(resubmitTable.getInPort()), resubmitTable.getTable());
                case SUB_TYPE_CT:
                    OFActionNiciraCt ctAction = (OFActionNiciraCt) nicira;
                    List<OFAction> actions = ctAction.getActions();
                    List<ExtensionTreatment> extensionActions = new ArrayList<>();
                    for (OFAction act : actions) {
                        OFActionExperimenter ctExperimenter = (OFActionExperimenter) act;
                        if (Long.valueOf(ctExperimenter.getExperimenter()).intValue() == TYPE_NICIRA) {
                            OFActionNicira actionNicira = (OFActionNicira) ctExperimenter;
                            switch(actionNicira.getSubtype()) {
                                case SUB_TYPE_LOAD:
                                    OFActionNiciraLoad loadAction = (OFActionNiciraLoad) actionNicira;
                                    extensionActions.add(new NiciraLoad(loadAction.getOfsNbits(), loadAction.getDst(), loadAction.getValue().getValue()));
                                    break;
                                case SUB_TYPE_NAT:
                                    OFActionNiciraNat natAction = (OFActionNiciraNat) actionNicira;
                                    int portMin = 0;
                                    int portMax = 0;
                                    IpAddress ipAddressMin = IpAddress.valueOf(0);
                                    IpAddress ipAddressMax = IpAddress.valueOf(0);
                                    // FIXME: we need to get ipv6 and port from list<ipv4> temporarily,
                                    // becase loxi don't know how to arrange these data to corresonding field.
                                    IPv4Address[] arrays = (IPv4Address[]) natAction.getIpv4Range().toArray(new IPv4Address[0]);
                                    int index = 0;
                                    if ((natAction.getRangePresent() & NAT_RANGE_IPV4_MIN) != 0) {
                                        ipAddressMin = IpAddress.valueOf(arrays[index++].toString());
                                    }
                                    if ((natAction.getRangePresent() & NAT_RANGE_IPV4_MAX) != 0) {
                                        ipAddressMax = IpAddress.valueOf(arrays[index++].toString());
                                    }
                                    if ((natAction.getRangePresent() & NAT_RANGE_IPV6_MIN) != 0) {
                                        byte[] bytes = Bytes.concat(arrays[index++].getBytes(), arrays[index++].getBytes(), arrays[index++].getBytes(), arrays[index++].getBytes());
                                        ipAddressMin = IpAddress.valueOf(IpAddress.Version.INET6, bytes);
                                    }
                                    if ((natAction.getRangePresent() & NAT_RANGE_IPV6_MAX) != 0) {
                                        byte[] bytes = Bytes.concat(arrays[index++].getBytes(), arrays[index++].getBytes(), arrays[index++].getBytes(), arrays[index++].getBytes());
                                        ipAddressMax = IpAddress.valueOf(IpAddress.Version.INET6, bytes);
                                    }
                                    if ((natAction.getRangePresent() & NAT_RANGE_PROTO_MIN) != 0) {
                                        portMin = arrays[index].getInt() >> 16 & 0x0000ffff;
                                    }
                                    if ((natAction.getRangePresent() & NAT_RANGE_PROTO_MAX) != 0) {
                                        portMax = arrays[index].getInt() & 0x0000ffff;
                                    }
                                    NiciraNat natTreatment = new NiciraNat(natAction.getFlags(), natAction.getRangePresent(), portMin, portMax, ipAddressMin, ipAddressMax);
                                    extensionActions.add(natTreatment);
                                    break;
                                default:
                                    throw new UnsupportedOperationException("Driver does not support nested" + " in ct action extension subtype " + actionNicira.getSubtype());
                            }
                        }
                    }
                    return new NiciraCt(ctAction.getFlags(), ctAction.getZoneSrc(), ctAction.getZone(), ctAction.getRecircTable(), ctAction.getAlg(), extensionActions);
                case SUB_TYPE_CT_CLEAR:
                    return new NiciraCtClear();
                case SUB_TYPE_LOAD:
                    OFActionNiciraLoad loadAction = (OFActionNiciraLoad) nicira;
                    return new NiciraLoad(loadAction.getOfsNbits(), loadAction.getDst(), loadAction.getValue().getValue());
                default:
                    throw new UnsupportedOperationException("Driver does not support extension subtype " + nicira.getSubtype());
            }
        }
    }
    return null;
}
Also used : OFActionExperimenter(org.projectfloodlight.openflow.protocol.action.OFActionExperimenter) ArrayList(java.util.ArrayList) IPv4Address(org.projectfloodlight.openflow.types.IPv4Address) OFActionNiciraLoad(org.projectfloodlight.openflow.protocol.action.OFActionNiciraLoad) OFOxmNshMdtype(org.projectfloodlight.openflow.protocol.oxm.OFOxmNshMdtype) OFActionSetField(org.projectfloodlight.openflow.protocol.action.OFActionSetField) ExtensionTreatment(org.onosproject.net.flow.instructions.ExtensionTreatment) OFOxmNsp(org.projectfloodlight.openflow.protocol.oxm.OFOxmNsp) OFOxmEncapEthType(org.projectfloodlight.openflow.protocol.oxm.OFOxmEncapEthType) OFOxmNsi(org.projectfloodlight.openflow.protocol.oxm.OFOxmNsi) OFOxmEncapEthDst(org.projectfloodlight.openflow.protocol.oxm.OFOxmEncapEthDst) OFOxmNshC3(org.projectfloodlight.openflow.protocol.oxm.OFOxmNshC3) OFOxmNshC4(org.projectfloodlight.openflow.protocol.oxm.OFOxmNshC4) OFOxmTunGpeNp(org.projectfloodlight.openflow.protocol.oxm.OFOxmTunGpeNp) OFOxmNshC1(org.projectfloodlight.openflow.protocol.oxm.OFOxmNshC1) OFOxmNshC2(org.projectfloodlight.openflow.protocol.oxm.OFOxmNshC2) OFActionNiciraNat(org.projectfloodlight.openflow.protocol.action.OFActionNiciraNat) OFOxmNshNp(org.projectfloodlight.openflow.protocol.oxm.OFOxmNshNp) OFActionNiciraMove(org.projectfloodlight.openflow.protocol.action.OFActionNiciraMove) OFActionNicira(org.projectfloodlight.openflow.protocol.action.OFActionNicira) OFActionNiciraResubmit(org.projectfloodlight.openflow.protocol.action.OFActionNiciraResubmit) OFActionNiciraNat(org.projectfloodlight.openflow.protocol.action.OFActionNiciraNat) OFAction(org.projectfloodlight.openflow.protocol.action.OFAction) OFOxmTunnelIpv4Dst(org.projectfloodlight.openflow.protocol.oxm.OFOxmTunnelIpv4Dst) OFActionNiciraResubmitTable(org.projectfloodlight.openflow.protocol.action.OFActionNiciraResubmitTable) OFOxmEncapEthSrc(org.projectfloodlight.openflow.protocol.oxm.OFOxmEncapEthSrc) OFActionNiciraResubmit(org.projectfloodlight.openflow.protocol.action.OFActionNiciraResubmit) OFActionNiciraCt(org.projectfloodlight.openflow.protocol.action.OFActionNiciraCt) OFActionNiciraCt(org.projectfloodlight.openflow.protocol.action.OFActionNiciraCt) OFActionNiciraLoad(org.projectfloodlight.openflow.protocol.action.OFActionNiciraLoad) IpAddress(org.onlab.packet.IpAddress) OFActionNiciraResubmitTable(org.projectfloodlight.openflow.protocol.action.OFActionNiciraResubmitTable)

Example 20 with ExtensionTreatment

use of org.onosproject.net.flow.instructions.ExtensionTreatment 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)35 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)17 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)17 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)16 TrafficSelector (org.onosproject.net.flow.TrafficSelector)16 ExtensionTreatmentResolver (org.onosproject.net.behaviour.ExtensionTreatmentResolver)12 ExtensionPropertyException (org.onosproject.net.flow.instructions.ExtensionPropertyException)11 DeviceId (org.onosproject.net.DeviceId)8 Device (org.onosproject.net.Device)7 MacAddress (org.onlab.packet.MacAddress)3 DriverHandler (org.onosproject.net.driver.DriverHandler)3 Pod (io.fabric8.kubernetes.api.model.Pod)2 IpAddress (org.onlab.packet.IpAddress)2 TpPort (org.onlab.packet.TpPort)2 KubevirtNetworkingUtil.getRouterMacAddress (org.onosproject.kubevirtnetworking.util.KubevirtNetworkingUtil.getRouterMacAddress)2 ExtensionTreatmentType (org.onosproject.net.flow.instructions.ExtensionTreatmentType)2 OFAction (org.projectfloodlight.openflow.protocol.action.OFAction)2 OFActionNiciraCt (org.projectfloodlight.openflow.protocol.action.OFActionNiciraCt)2 OFActionNiciraLoad (org.projectfloodlight.openflow.protocol.action.OFActionNiciraLoad)2 OFActionNiciraMove (org.projectfloodlight.openflow.protocol.action.OFActionNiciraMove)2