Search in sources :

Example 1 with ExtensionSelector

use of org.onosproject.net.flow.criteria.ExtensionSelector in project onos by opennetworkinglab.

the class KubevirtSecurityGroupHandler method setConnTrackRule.

/**
 * Sets connection tracking rule using OVS extension commands.
 * It is not so graceful, but I don't want to make it more general because
 * it is going to be used only here.
 * The following is the usage of the function.
 *
 * @param deviceId Device ID
 * @param ctState ctState: please use RulePopulatorUtil.computeCtStateFlag()
 *                to build the value
 * @param ctMask crMask: please use RulePopulatorUtil.computeCtMaskFlag()
 *               to build the value
 * @param commit CT_COMMIT for commit action, CT_NO_COMMIT otherwise
 * @param recircTable table number for recirculation after CT actions.
 *                    CT_NO_RECIRC with no recirculation
 * @param action Additional actions. ACTION_DROP, ACTION_NONE,
 *               GOTO_XXX_TABLE are supported.
 * @param priority priority value for the rule
 * @param install true for insertion, false for removal
 */
private void setConnTrackRule(DeviceId deviceId, long ctState, long ctMask, int commit, short recircTable, int action, int priority, boolean install) {
    ExtensionSelector esCtSate = RulePopulatorUtil.buildCtExtensionSelector(driverService, deviceId, ctState, ctMask);
    TrafficSelector selector = DefaultTrafficSelector.builder().extension(esCtSate, deviceId).matchEthType(Ethernet.TYPE_IPV4).build();
    TrafficTreatment.Builder tb = DefaultTrafficTreatment.builder();
    if (commit == CT_COMMIT || recircTable > 0) {
        RulePopulatorUtil.NiciraConnTrackTreatmentBuilder natTreatmentBuilder = niciraConnTrackTreatmentBuilder(driverService, deviceId);
        natTreatmentBuilder.natAction(false);
        natTreatmentBuilder.commit(commit == CT_COMMIT);
        if (recircTable > 0) {
            natTreatmentBuilder.table(recircTable);
        }
        tb.extension(natTreatmentBuilder.build(), deviceId);
    } else if (action == ACTION_DROP) {
        tb.drop();
    }
    if (action != ACTION_NONE && action != ACTION_DROP) {
        tb.transition(action);
    }
    int tableType = ERROR_TABLE;
    if (priority == PRIORITY_CT_RULE || priority == PRIORITY_CT_DROP_RULE) {
        tableType = TENANT_ACL_CT_TABLE;
    } else if (priority == PRIORITY_CT_HOOK_RULE) {
        tableType = TENANT_ACL_INGRESS_TABLE;
    } else {
        log.error("Cannot an appropriate table for the conn track rule.");
    }
    flowRuleService.setRule(appId, deviceId, selector, tb.build(), priority, tableType, install);
}
Also used : ExtensionSelector(org.onosproject.net.flow.criteria.ExtensionSelector) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) RulePopulatorUtil(org.onosproject.kubevirtnetworking.util.RulePopulatorUtil)

Example 2 with ExtensionSelector

use of org.onosproject.net.flow.criteria.ExtensionSelector in project onos by opennetworkinglab.

the class RulePopulatorUtil method buildCtExtensionSelector.

/**
 * Builds OVS ConnTrack matches.
 *
 * @param driverService driver service
 * @param deviceId device ID
 * @param ctState connection tracking sate masking value
 * @param ctSateMask connection tracking sate masking value
 * @return OVS ConnTrack extension match
 */
public static ExtensionSelector buildCtExtensionSelector(DriverService driverService, DeviceId deviceId, long ctState, long ctSateMask) {
    DriverHandler handler = driverService.createHandler(deviceId);
    ExtensionSelectorResolver esr = handler.behaviour(ExtensionSelectorResolver.class);
    ExtensionSelector extensionSelector = esr.getExtensionSelector(ExtensionSelectorType.ExtensionSelectorTypes.NICIRA_MATCH_CONNTRACK_STATE.type());
    try {
        extensionSelector.setPropertyValue(CT_STATE, ctState);
        extensionSelector.setPropertyValue(CT_STATE_MASK, ctSateMask);
    } catch (Exception e) {
        log.error("Failed to set nicira match CT state because of {}", e);
        return null;
    }
    return extensionSelector;
}
Also used : ExtensionSelector(org.onosproject.net.flow.criteria.ExtensionSelector) DriverHandler(org.onosproject.net.driver.DriverHandler) ExtensionSelectorResolver(org.onosproject.net.behaviour.ExtensionSelectorResolver) ExtensionPropertyException(org.onosproject.net.flow.instructions.ExtensionPropertyException)

Example 3 with ExtensionSelector

use of org.onosproject.net.flow.criteria.ExtensionSelector in project onos by opennetworkinglab.

the class K8sServiceHandler method setTrackNew.

private void setTrackNew(DeviceId deviceId, long ctState, long ctMask, IpAddress dstIp, TpPort dstPort, int installTable, int groupId, int priority, boolean install) {
    ExtensionSelector esCtSate = RulePopulatorUtil.buildCtExtensionSelector(driverService, deviceId, ctState, ctMask);
    TrafficSelector selector = DefaultTrafficSelector.builder().matchEthType(Ethernet.TYPE_IPV4).matchIPDst(IpPrefix.valueOf(dstIp, HOST_CIDR_NUM)).matchIPProtocol(IPv4.PROTOCOL_TCP).matchTcpDst(dstPort).extension(esCtSate, deviceId).build();
    TrafficTreatment treatment = DefaultTrafficTreatment.builder().group(GroupId.valueOf(groupId)).build();
    k8sFlowRuleService.setRule(appId, deviceId, selector, treatment, priority, installTable, install);
}
Also used : ExtensionSelector(org.onosproject.net.flow.criteria.ExtensionSelector) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment)

Example 4 with ExtensionSelector

use of org.onosproject.net.flow.criteria.ExtensionSelector in project onos by opennetworkinglab.

the class K8sServiceHandler method setUntrack.

private void setUntrack(DeviceId deviceId, long ctState, long ctMask, String srcCidr, String dstCidr, int installTable, int transitTable, int priority, boolean install) {
    ExtensionSelector esCtSate = RulePopulatorUtil.buildCtExtensionSelector(driverService, deviceId, ctState, ctMask);
    TrafficSelector selector = DefaultTrafficSelector.builder().matchEthType(Ethernet.TYPE_IPV4).matchIPSrc(IpPrefix.valueOf(srcCidr)).matchIPDst(IpPrefix.valueOf(dstCidr)).extension(esCtSate, deviceId).build();
    NiciraConnTrackTreatmentBuilder connTreatmentBuilder = niciraConnTrackTreatmentBuilder(driverService, deviceId).natAction(false).commit(false).table((short) transitTable);
    TrafficTreatment treatment = DefaultTrafficTreatment.builder().extension(connTreatmentBuilder.build(), deviceId).build();
    k8sFlowRuleService.setRule(appId, deviceId, selector, treatment, priority, installTable, install);
}
Also used : NiciraConnTrackTreatmentBuilder(org.onosproject.k8snetworking.util.RulePopulatorUtil.NiciraConnTrackTreatmentBuilder) ExtensionSelector(org.onosproject.net.flow.criteria.ExtensionSelector) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment)

Example 5 with ExtensionSelector

use of org.onosproject.net.flow.criteria.ExtensionSelector in project onos by opennetworkinglab.

the class K8sServiceHandler method setTrackEstablish.

private void setTrackEstablish(DeviceId deviceId, long ctState, long ctMask, int installTable, int transitTable, int priority, boolean install) {
    ExtensionSelector esCtSate = RulePopulatorUtil.buildCtExtensionSelector(driverService, deviceId, ctState, ctMask);
    TrafficSelector selector = DefaultTrafficSelector.builder().extension(esCtSate, deviceId).build();
    TrafficTreatment treatment = DefaultTrafficTreatment.builder().transition(transitTable).build();
    k8sFlowRuleService.setRule(appId, deviceId, selector, treatment, priority, installTable, install);
}
Also used : ExtensionSelector(org.onosproject.net.flow.criteria.ExtensionSelector) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment)

Aggregations

ExtensionSelector (org.onosproject.net.flow.criteria.ExtensionSelector)9 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)5 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)5 TrafficSelector (org.onosproject.net.flow.TrafficSelector)5 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)5 ExtensionSelectorResolver (org.onosproject.net.behaviour.ExtensionSelectorResolver)4 DriverHandler (org.onosproject.net.driver.DriverHandler)4 ExtensionPropertyException (org.onosproject.net.flow.instructions.ExtensionPropertyException)3 ItemNotFoundException (org.onlab.util.ItemNotFoundException)1 NiciraConnTrackTreatmentBuilder (org.onosproject.k8snetworking.util.RulePopulatorUtil.NiciraConnTrackTreatmentBuilder)1 RulePopulatorUtil (org.onosproject.kubevirtnetworking.util.RulePopulatorUtil)1 DeviceId (org.onosproject.net.DeviceId)1 DefaultDriverData (org.onosproject.net.driver.DefaultDriverData)1 DefaultDriverHandler (org.onosproject.net.driver.DefaultDriverHandler)1 DriverService (org.onosproject.net.driver.DriverService)1 ExtensionSelectorType (org.onosproject.net.flow.criteria.ExtensionSelectorType)1 UnresolvedExtensionSelector (org.onosproject.net.flow.criteria.UnresolvedExtensionSelector)1 RulePopulatorUtil (org.onosproject.openstacknetworking.util.RulePopulatorUtil)1