Search in sources :

Example 71 with TrafficSelector

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

the class K8sRoutingSnatHandler method setRouterSnatUpstreamRule.

private void setRouterSnatUpstreamRule(K8sNode k8sNode, K8sRouterBridge bridge, boolean install) {
    if (k8sNode.routerPortNum() == null) {
        return;
    }
    TrafficSelector ipSelector = DefaultTrafficSelector.builder().matchEthType(Ethernet.TYPE_IPV4).matchInPort(k8sNode.routerToExtPortNum()).build();
    TrafficTreatment treatment = DefaultTrafficTreatment.builder().setOutput(k8sNode.routerPortNum()).build();
    k8sFlowRuleService.setRule(appId, bridge.deviceId(), ipSelector, treatment, PRIORITY_ROUTER_RULE, ROUTER_ENTRY_TABLE, install);
    TrafficSelector arpSelector = DefaultTrafficSelector.builder().matchEthType(Ethernet.TYPE_ARP).matchInPort(k8sNode.routerToExtPortNum()).build();
    k8sFlowRuleService.setRule(appId, bridge.deviceId(), arpSelector, treatment, PRIORITY_ROUTER_RULE, ROUTER_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)

Example 72 with TrafficSelector

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

the class K8sRoutingSnatHandler method setRouterSnatDownstreamRule.

private void setRouterSnatDownstreamRule(K8sNode k8sNode, K8sRouterBridge bridge, boolean install) {
    if (k8sNode.routerPortNum() == null) {
        return;
    }
    TrafficSelector ipSelector = DefaultTrafficSelector.builder().matchEthType(Ethernet.TYPE_IPV4).matchInPort(k8sNode.routerPortNum()).matchIPDst(IpPrefix.valueOf(k8sNode.extBridgeIp(), 32)).build();
    TrafficTreatment treatment = DefaultTrafficTreatment.builder().setOutput(k8sNode.routerToExtPortNum()).build();
    k8sFlowRuleService.setRule(appId, bridge.deviceId(), ipSelector, treatment, PRIORITY_ROUTER_RULE, ROUTER_ENTRY_TABLE, install);
    TrafficSelector arpSelector = DefaultTrafficSelector.builder().matchEthType(Ethernet.TYPE_ARP).matchInPort(k8sNode.routerPortNum()).matchArpTpa(Ip4Address.valueOf(k8sNode.extBridgeIp().toString())).build();
    k8sFlowRuleService.setRule(appId, bridge.deviceId(), arpSelector, treatment, PRIORITY_ROUTER_RULE, ROUTER_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)

Example 73 with TrafficSelector

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

the class K8sRoutingSnatHandler method setExtIntfArpRule.

private void setExtIntfArpRule(K8sNode k8sNode, boolean install) {
    k8sNodeService.completeNodes().forEach(n -> {
        Device device = deviceService.getDevice(n.extBridge());
        TrafficSelector selector = DefaultTrafficSelector.builder().matchEthType(Ethernet.TYPE_ARP).matchArpOp(ARP.OP_REQUEST).matchArpTpa(Ip4Address.valueOf(k8sNode.extBridgeIp().toString())).build();
        TrafficTreatment treatment = DefaultTrafficTreatment.builder().setArpOp(ARP.OP_REPLY).extension(buildMoveEthSrcToDstExtension(device), device.id()).extension(buildMoveArpShaToThaExtension(device), device.id()).extension(buildMoveArpSpaToTpaExtension(device), device.id()).setEthSrc(k8sNode.extBridgeMac()).setArpSha(k8sNode.extBridgeMac()).setArpSpa(Ip4Address.valueOf(k8sNode.extBridgeIp().toString())).setOutput(PortNumber.IN_PORT).build();
        k8sFlowRuleService.setRule(appId, n.extBridge(), selector, treatment, PRIORITY_STATEFUL_SNAT_RULE, EXT_ENTRY_TABLE, install);
    });
}
Also used : Device(org.onosproject.net.Device) 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 74 with TrafficSelector

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

the class K8sServiceHandler method setSrcDstCidrRules.

private void setSrcDstCidrRules(DeviceId deviceId, String srcCidr, String dstCidr, String cidrClass, String segId, String shiftPrefix, String shiftType, int installTable, int transitTable, int priority, boolean install) {
    TrafficSelector selector = DefaultTrafficSelector.builder().matchEthType(Ethernet.TYPE_IPV4).matchIPSrc(IpPrefix.valueOf(srcCidr)).matchIPDst(IpPrefix.valueOf(dstCidr)).build();
    TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder();
    if (segId != null) {
        tBuilder.setTunnelId(Long.valueOf(segId));
    }
    if (shiftPrefix != null && shiftType != null) {
        ExtensionTreatment loadTreatment = buildLoadExtension(deviceService.getDevice(deviceId), cidrClass, shiftType, shiftPrefix);
        tBuilder.extension(loadTreatment, deviceId);
    }
    tBuilder.transition(transitTable);
    k8sFlowRuleService.setRule(appId, deviceId, selector, tBuilder.build(), priority, installTable, 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 75 with TrafficSelector

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

the class K8sSwitchingGatewayHandler method setInterNodeRoutingRules.

private void setInterNodeRoutingRules(K8sNode srcNode, boolean install) {
    if (srcNode == null) {
        return;
    }
    for (K8sNode dstNode : k8sNodeService.nodes()) {
        if (StringUtils.equals(srcNode.hostname(), dstNode.hostname())) {
            continue;
        }
        boolean sameHost = false;
        for (K8sHost host : k8sHostService.completeHosts()) {
            Set<String> nodeNames = host.nodeNames();
            // we simply do not tunnel the traffic, instead we route the traffic
            if (nodeNames.contains(srcNode.hostname()) && nodeNames.contains(dstNode.hostname())) {
                sameHost = true;
            }
        }
        if (sameHost) {
            TrafficSelector originalSelector = DefaultTrafficSelector.builder().matchEthType(Ethernet.TYPE_IPV4).matchIPSrc(IpPrefix.valueOf(srcNode.podCidr())).matchIPDst(IpPrefix.valueOf(dstNode.podCidr())).build();
            TrafficTreatment treatment = DefaultTrafficTreatment.builder().setOutput(dstNode.tunToIntgPortNum()).build();
            k8sFlowRuleService.setRule(appId, dstNode.tunBridge(), originalSelector, treatment, PRIORITY_INTER_NODE_RULE, TUN_ENTRY_TABLE, install);
            TrafficSelector transformedSelector = DefaultTrafficSelector.builder().matchEthType(Ethernet.TYPE_IPV4).matchIPSrc(IpPrefix.valueOf(shiftIpDomain(srcNode.podCidr(), SHIFTED_IP_PREFIX))).matchIPDst(IpPrefix.valueOf(dstNode.podCidr())).build();
            k8sFlowRuleService.setRule(appId, dstNode.tunBridge(), transformedSelector, treatment, PRIORITY_INTER_NODE_RULE, TUN_ENTRY_TABLE, install);
            String nodeIpPrefix = NODE_IP_PREFIX + ".0.0.0/8";
            TrafficSelector nodePortSelector = DefaultTrafficSelector.builder().matchEthType(Ethernet.TYPE_IPV4).matchIPSrc(IpPrefix.valueOf(nodeIpPrefix)).matchIPDst(IpPrefix.valueOf(dstNode.podCidr())).build();
            k8sFlowRuleService.setRule(appId, dstNode.tunBridge(), nodePortSelector, treatment, PRIORITY_INTER_NODE_RULE, TUN_ENTRY_TABLE, install);
        }
    }
}
Also used : K8sNode(org.onosproject.k8snode.api.K8sNode) K8sHost(org.onosproject.k8snode.api.K8sHost) 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

TrafficSelector (org.onosproject.net.flow.TrafficSelector)396 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)354 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)249 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)235 FlowRule (org.onosproject.net.flow.FlowRule)94 Test (org.junit.Test)85 DefaultFlowRule (org.onosproject.net.flow.DefaultFlowRule)84 PiAction (org.onosproject.net.pi.runtime.PiAction)54 ConnectPoint (org.onosproject.net.ConnectPoint)51 ForwardingObjective (org.onosproject.net.flowobjective.ForwardingObjective)48 DeviceId (org.onosproject.net.DeviceId)43 PortNumber (org.onosproject.net.PortNumber)43 List (java.util.List)42 NextObjective (org.onosproject.net.flowobjective.NextObjective)41 FilteredConnectPoint (org.onosproject.net.FilteredConnectPoint)39 PiActionParam (org.onosproject.net.pi.runtime.PiActionParam)38 Instruction (org.onosproject.net.flow.instructions.Instruction)37 Criterion (org.onosproject.net.flow.criteria.Criterion)36 PiCriterion (org.onosproject.net.flow.criteria.PiCriterion)36 DefaultForwardingObjective (org.onosproject.net.flowobjective.DefaultForwardingObjective)35