Search in sources :

Example 31 with ExtensionTreatment

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

the class K8sServiceHandler method buildBuckets.

private GroupBucket buildBuckets(DeviceId deviceId, String podIpStr, ServicePort sp) {
    TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder().setIpDst(IpAddress.valueOf(podIpStr));
    int targetPort;
    if (sp.getTargetPort().getIntVal() == null) {
        Pod pod = podByIp(k8sPodService, podIpStr);
        targetPort = portNumberByName(pod, sp.getTargetPort().getStrVal());
    } else {
        targetPort = sp.getTargetPort().getIntVal();
    }
    if (targetPort == 0) {
        return null;
    }
    if (TCP.equals(sp.getProtocol())) {
        tBuilder.setTcpDst(TpPort.tpPort(targetPort));
    } else if (UDP.equals(sp.getProtocol())) {
        tBuilder.setUdpDst(TpPort.tpPort(targetPort));
    }
    ExtensionTreatment resubmitTreatment = buildResubmitExtension(deviceService.getDevice(deviceId), ACL_TABLE);
    tBuilder.extension(resubmitTreatment, deviceId);
    // TODO: need to adjust group bucket weight by considering POD locality
    return buildGroupBucket(tBuilder.build(), SELECT, (short) -1);
}
Also used : Pod(io.fabric8.kubernetes.api.model.Pod) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) ExtensionTreatment(org.onosproject.net.flow.instructions.ExtensionTreatment)

Example 32 with ExtensionTreatment

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

the class K8sSwitchingGatewayHandler method setLocalBridgeRule.

private void setLocalBridgeRule(K8sNetwork k8sNetwork, K8sNode k8sNode, String type, boolean install) {
    TrafficSelector.Builder sBuilder = DefaultTrafficSelector.builder().matchEthType(Ethernet.TYPE_IPV4);
    TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder();
    ExtensionTreatment loadTreatment = null;
    if (REQUEST.equals(type)) {
        loadTreatment = buildLoadExtension(deviceService.getDevice(k8sNode.localBridge()), B_CLASS, SRC, SHIFTED_LOCAL_IP_PREFIX);
    }
    if (REPLY.equals(type)) {
        loadTreatment = buildLoadExtension(deviceService.getDevice(k8sNode.localBridge()), B_CLASS, DST, SHIFTED_IP_PREFIX);
    }
    tBuilder.extension(loadTreatment, k8sNode.localBridge());
    if (REQUEST.equals(type)) {
        sBuilder.matchIPDst(IpPrefix.valueOf(k8sNetwork.gatewayIp(), HOST_PREFIX));
        tBuilder.setOutput(PortNumber.LOCAL);
    }
    if (REPLY.equals(type)) {
        sBuilder.matchIPSrc(IpPrefix.valueOf(k8sNetwork.gatewayIp(), HOST_PREFIX));
        tBuilder.setOutput(k8sNode.localToIntgPatchPortNum());
    }
    k8sFlowRuleService.setRule(appId, k8sNode.localBridge(), sBuilder.build(), tBuilder.build(), PRIORITY_LOCAL_BRIDGE_RULE, LOCAL_ENTRY_TABLE, install);
}
Also used : TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) ExtensionTreatment(org.onosproject.net.flow.instructions.ExtensionTreatment)

Example 33 with ExtensionTreatment

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

the class RulePopulatorUtil method buildResubmitExtension.

/**
 * Returns the nicira resubmit extension treatment with given table ID.
 *
 * @param device        device instance
 * @param tableId       table identifier
 * @return resubmit extension treatment
 */
public static ExtensionTreatment buildResubmitExtension(Device device, int tableId) {
    if (!checkTreatmentResolver(device)) {
        return null;
    }
    ExtensionTreatmentResolver resolver = device.as(ExtensionTreatmentResolver.class);
    ExtensionTreatment treatment = resolver.getExtensionInstruction(NICIRA_RESUBMIT_TABLE.type());
    try {
        treatment.setPropertyValue(TABLE_EXTENSION, ((short) tableId));
        return treatment;
    } catch (ExtensionPropertyException e) {
        log.error("Failed to set nicira resubmit extension treatment for {}", device.id());
        return null;
    }
}
Also used : ExtensionTreatmentResolver(org.onosproject.net.behaviour.ExtensionTreatmentResolver) ExtensionTreatment(org.onosproject.net.flow.instructions.ExtensionTreatment) ExtensionPropertyException(org.onosproject.net.flow.instructions.ExtensionPropertyException)

Example 34 with ExtensionTreatment

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

the class K8sNodePortHandler method setServiceToNodeRules.

private void setServiceToNodeRules(K8sNode k8sNode, String clusterIp, ServicePort servicePort, boolean install) {
    String protocol = servicePort.getProtocol();
    int nodePort = servicePort.getNodePort();
    int svcPort = servicePort.getPort();
    DeviceId deviceId = k8sNode.extBridge();
    String nodeIp = k8sNode.nodeIp().toString();
    String nodeIpPrefix = getBclassIpPrefixFromCidr(nodeIp);
    if (nodeIpPrefix == null) {
        return;
    }
    TrafficSelector.Builder sBuilder = DefaultTrafficSelector.builder().matchEthType(Ethernet.TYPE_IPV4).matchInPort(k8sNode.extToIntgPatchPortNum()).matchIPSrc(IpPrefix.valueOf(IpAddress.valueOf(clusterIp), HOST_CIDR));
    TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder().setIpSrc(k8sNode.nodeIp()).setEthSrc(k8sNode.nodeMac());
    if (TCP.equals(protocol)) {
        sBuilder.matchIPProtocol(IPv4.PROTOCOL_TCP).matchTcpSrc(TpPort.tpPort(svcPort));
        tBuilder.setTcpSrc(TpPort.tpPort(nodePort));
    } else if (UDP.equals(protocol)) {
        sBuilder.matchIPProtocol(IPv4.PROTOCOL_UDP).matchUdpSrc(TpPort.tpPort(svcPort));
        tBuilder.setUdpSrc(TpPort.tpPort(nodePort));
    }
    ExtensionTreatment loadTreatment = buildLoadExtension(deviceService.getDevice(deviceId), B_CLASS, DST, nodeIpPrefix);
    tBuilder.extension(loadTreatment, deviceId);
    // in normal mode, we steer the traffic to the local port
    if (k8sNode.mode() == PASSTHROUGH) {
        PortNumber output = k8sNode.portNumByName(k8sNode.extBridge(), k8sNode.k8sExtToOsPatchPortName());
        if (output == null) {
            log.warn("Kubernetes external to OpenStack patch port is null");
            return;
        }
        tBuilder.setOutput(output);
    } else {
        tBuilder.setOutput(PortNumber.LOCAL);
    }
    k8sFlowRuleService.setRule(appId, deviceId, sBuilder.build(), tBuilder.build(), PRIORITY_NODE_PORT_RULE, EXT_ENTRY_TABLE, install);
}
Also used : DeviceId(org.onosproject.net.DeviceId) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) PortNumber(org.onosproject.net.PortNumber) ExtensionTreatment(org.onosproject.net.flow.instructions.ExtensionTreatment)

Example 35 with ExtensionTreatment

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

the class K8sNodePortHandler method setNodeToServiceRules.

private void setNodeToServiceRules(K8sNode k8sNode, String clusterIp, ServicePort servicePort, boolean install) {
    String protocol = servicePort.getProtocol();
    int nodePort = servicePort.getNodePort();
    int svcPort = servicePort.getPort();
    DeviceId deviceId = k8sNode.extBridge();
    TrafficSelector.Builder sBuilder = DefaultTrafficSelector.builder().matchEthType(Ethernet.TYPE_IPV4).matchIPDst(IpPrefix.valueOf(k8sNode.nodeIp(), HOST_CIDR));
    TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder().setIpDst(IpAddress.valueOf(clusterIp));
    if (TCP.equals(protocol)) {
        sBuilder.matchIPProtocol(IPv4.PROTOCOL_TCP).matchTcpDst(TpPort.tpPort(nodePort));
        tBuilder.setTcpDst(TpPort.tpPort(svcPort));
    } else if (UDP.equals(protocol)) {
        sBuilder.matchIPProtocol(IPv4.PROTOCOL_UDP).matchUdpDst(TpPort.tpPort(nodePort));
        tBuilder.setUdpDst(TpPort.tpPort(svcPort));
    }
    String podCidr = k8sNetworkService.network(k8sNode.hostname()).cidr();
    String prefix = NODE_IP_PREFIX + "." + podCidr.split("\\.")[2];
    ExtensionTreatment loadTreatment = buildLoadExtension(deviceService.getDevice(deviceId), B_CLASS, SRC, prefix);
    tBuilder.extension(loadTreatment, deviceId).setOutput(k8sNode.extToIntgPatchPortNum());
    k8sFlowRuleService.setRule(appId, k8sNode.extBridge(), sBuilder.build(), tBuilder.build(), PRIORITY_NODE_PORT_RULE, EXT_ENTRY_TABLE, install);
}
Also used : DeviceId(org.onosproject.net.DeviceId) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) ExtensionTreatment(org.onosproject.net.flow.instructions.ExtensionTreatment)

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