Search in sources :

Example 1 with OFActionNiciraResubmit

use of org.projectfloodlight.openflow.protocol.action.OFActionNiciraResubmit 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)

Aggregations

ArrayList (java.util.ArrayList)1 IpAddress (org.onlab.packet.IpAddress)1 ExtensionTreatment (org.onosproject.net.flow.instructions.ExtensionTreatment)1 OFAction (org.projectfloodlight.openflow.protocol.action.OFAction)1 OFActionExperimenter (org.projectfloodlight.openflow.protocol.action.OFActionExperimenter)1 OFActionNicira (org.projectfloodlight.openflow.protocol.action.OFActionNicira)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 OFActionSetField (org.projectfloodlight.openflow.protocol.action.OFActionSetField)1 OFOxmEncapEthDst (org.projectfloodlight.openflow.protocol.oxm.OFOxmEncapEthDst)1 OFOxmEncapEthSrc (org.projectfloodlight.openflow.protocol.oxm.OFOxmEncapEthSrc)1 OFOxmEncapEthType (org.projectfloodlight.openflow.protocol.oxm.OFOxmEncapEthType)1 OFOxmNshC1 (org.projectfloodlight.openflow.protocol.oxm.OFOxmNshC1)1 OFOxmNshC2 (org.projectfloodlight.openflow.protocol.oxm.OFOxmNshC2)1 OFOxmNshC3 (org.projectfloodlight.openflow.protocol.oxm.OFOxmNshC3)1 OFOxmNshC4 (org.projectfloodlight.openflow.protocol.oxm.OFOxmNshC4)1