Search in sources :

Example 1 with TrafficTreatment

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

the class K8sFlowRuleManager method setAnyRoutingRule.

private void setAnyRoutingRule(IpPrefix srcIpPrefix, MacAddress mac, K8sNetwork k8sNetwork) {
    TrafficSelector.Builder sBuilder = DefaultTrafficSelector.builder().matchEthType(Ethernet.TYPE_IPV4).matchIPSrc(srcIpPrefix).matchIPDst(IpPrefix.valueOf(k8sNetwork.cidr()));
    for (K8sNode node : k8sNodeService.completeNodes()) {
        TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder().setTunnelId(Long.valueOf(k8sNetwork.segmentId()));
        if (node.hostname().equals(k8sNetwork.name())) {
            if (mac != null) {
                tBuilder.setEthSrc(mac);
            }
            tBuilder.transition(STAT_EGRESS_TABLE);
        } else {
            K8sNode localNode = k8sNodeService.node(k8sNetwork.name());
            tBuilder.setOutput(node.intgToTunPortNum());
            // install flows into tunnel bridge
            PortNumber portNum = tunnelPortNumByNetId(k8sNetwork.networkId(), k8sNetworkService, node);
            TrafficTreatment treatmentToRemote = DefaultTrafficTreatment.builder().extension(buildExtension(deviceService, node.tunBridge(), localNode.dataIp().getIp4Address()), node.tunBridge()).setTunnelId(Long.valueOf(k8sNetwork.segmentId())).setOutput(portNum).build();
            FlowRule remoteFlowRule = DefaultFlowRule.builder().forDevice(node.tunBridge()).withSelector(sBuilder.build()).withTreatment(treatmentToRemote).withPriority(PRIORITY_CIDR_RULE).fromApp(appId).makePermanent().forTable(TUN_ENTRY_TABLE).build();
            applyRule(remoteFlowRule, true);
        }
        FlowRule flowRule = DefaultFlowRule.builder().forDevice(node.intgBridge()).withSelector(sBuilder.build()).withTreatment(tBuilder.build()).withPriority(PRIORITY_CIDR_RULE).fromApp(appId).makePermanent().forTable(ROUTING_TABLE).build();
        applyRule(flowRule, true);
    }
}
Also used : K8sNode(org.onosproject.k8snode.api.K8sNode) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) FlowRule(org.onosproject.net.flow.FlowRule) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) PortNumber(org.onosproject.net.PortNumber)

Example 2 with TrafficTreatment

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

the class K8sRoutingArpHandler method setArpReplyRule.

private void setArpReplyRule(K8sNode k8sNode, boolean install) {
    TrafficSelector selector = DefaultTrafficSelector.builder().matchEthType(Ethernet.TYPE_ARP).matchArpOp(ARP.OP_REPLY).build();
    TrafficTreatment treatment = DefaultTrafficTreatment.builder().punt().build();
    k8sFlowRuleService.setRule(appId, k8sNode.extBridge(), selector, treatment, PRIORITY_ARP_REPLY_RULE, EXT_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 3 with TrafficTreatment

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

the class K8sRoutingArpHandler method setPodArpReplyRule.

private void setPodArpReplyRule(K8sNode k8sNode, boolean install) {
    TrafficSelector selector = DefaultTrafficSelector.builder().matchInPort(k8sNode.extBridgePortNum()).matchEthType(Ethernet.TYPE_ARP).matchArpOp(ARP.OP_REPLY).build();
    TrafficTreatment treatment = DefaultTrafficTreatment.builder().setOutput(k8sNode.extToIntgPatchPortNum()).build();
    k8sFlowRuleService.setRule(appId, k8sNode.extBridge(), selector, treatment, PRIORITY_ARP_POD_RULE, EXT_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 4 with TrafficTreatment

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

the class K8sServiceHandler method setStatefulGroupFlowRules.

private void setStatefulGroupFlowRules(DeviceId deviceId, long ctState, long ctMask, Service service, boolean install) {
    List<GroupBucket> buckets = Lists.newArrayList();
    String serviceName = service.getMetadata().getName();
    String serviceIp = service.getSpec().getClusterIP();
    // TODO: multi-ports case should be addressed
    Integer servicePort = service.getSpec().getPorts().get(0).getPort();
    String serviceProtocol = service.getSpec().getPorts().get(0).getProtocol();
    String svcStr = servicePortStr(serviceIp, servicePort, serviceProtocol);
    int groupId = svcStr.hashCode();
    List<Endpoints> endpointses = k8sEndpointsService.endpointses().stream().filter(ep -> serviceName.equals(ep.getMetadata().getName())).collect(Collectors.toList());
    Map<String, String> nodeIpGatewayIpMap = nodeIpGatewayIpMap(k8sNodeService, k8sNetworkService);
    for (Endpoints endpoints : endpointses) {
        for (EndpointSubset endpointSubset : endpoints.getSubsets()) {
            List<EndpointPort> ports = endpointSubset.getPorts().stream().filter(p -> p.getProtocol().equals(TCP)).collect(Collectors.toList());
            for (EndpointAddress address : endpointSubset.getAddresses()) {
                String podIp = nodeIpGatewayIpMap.containsKey(address.getIp()) ? nodeIpGatewayIpMap.get(address.getIp()) : address.getIp();
                NiciraConnTrackTreatmentBuilder connTreatmentBuilder = niciraConnTrackTreatmentBuilder(driverService, deviceId).commit(true).natAction(true).natIp(IpAddress.valueOf(podIp)).natFlag(CT_NAT_DST_FLAG);
                ports.forEach(p -> {
                    ExtensionTreatment ctNatTreatment = connTreatmentBuilder.natPortMin(TpPort.tpPort(p.getPort())).natPortMax(TpPort.tpPort(p.getPort())).build();
                    ExtensionTreatment resubmitTreatment = buildResubmitExtension(deviceService.getDevice(deviceId), ACL_TABLE);
                    TrafficTreatment treatment = DefaultTrafficTreatment.builder().extension(ctNatTreatment, deviceId).extension(resubmitTreatment, deviceId).build();
                    buckets.add(buildGroupBucket(treatment, SELECT, (short) -1));
                });
            }
        }
    }
    if (!buckets.isEmpty()) {
        k8sGroupRuleService.setRule(appId, deviceId, groupId, SELECT, buckets, install);
        setTrackNew(deviceId, ctState, ctMask, IpAddress.valueOf(serviceIp), TpPort.tpPort(servicePort), NAT_TABLE, groupId, PRIORITY_CT_RULE, install);
    }
}
Also used : DeviceService(org.onosproject.net.device.DeviceService) NODE_IP_PREFIX(org.onosproject.k8snetworking.api.Constants.NODE_IP_PREFIX) RulePopulatorUtil.niciraConnTrackTreatmentBuilder(org.onosproject.k8snetworking.util.RulePopulatorUtil.niciraConnTrackTreatmentBuilder) PRIORITY_CIDR_RULE(org.onosproject.k8snetworking.api.Constants.PRIORITY_CIDR_RULE) NiciraConnTrackTreatmentBuilder(org.onosproject.k8snetworking.util.RulePopulatorUtil.NiciraConnTrackTreatmentBuilder) K8sEndpointsEvent(org.onosproject.k8snetworking.api.K8sEndpointsEvent) DriverService(org.onosproject.net.driver.DriverService) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) StorageService(org.onosproject.store.service.StorageService) ROUTING_TABLE(org.onosproject.k8snetworking.api.Constants.ROUTING_TABLE) Map(java.util.Map) ApplicationId(org.onosproject.core.ApplicationId) RulePopulatorUtil.buildResubmitExtension(org.onosproject.k8snetworking.util.RulePopulatorUtil.buildResubmitExtension) NAT_STATEFUL(org.onosproject.k8snetworking.api.Constants.NAT_STATEFUL) SELECT(org.onosproject.net.group.GroupDescription.Type.SELECT) K8sEndpointsListener(org.onosproject.k8snetworking.api.K8sEndpointsListener) PRIORITY_CT_RULE(org.onosproject.k8snetworking.api.Constants.PRIORITY_CT_RULE) Deactivate(org.osgi.service.component.annotations.Deactivate) Set(java.util.Set) EndpointAddress(io.fabric8.kubernetes.api.model.EndpointAddress) PRIORITY_INTER_ROUTING_RULE(org.onosproject.k8snetworking.api.Constants.PRIORITY_INTER_ROUTING_RULE) SERVICE_IP_NAT_MODE(org.onosproject.k8snetworking.impl.OsgiPropertyConstants.SERVICE_IP_NAT_MODE) TUN_ENTRY_TABLE(org.onosproject.k8snetworking.api.Constants.TUN_ENTRY_TABLE) DeviceId(org.onosproject.net.DeviceId) Dictionary(java.util.Dictionary) Tools(org.onlab.util.Tools) K8sServiceService(org.onosproject.k8snetworking.api.K8sServiceService) ACL_TABLE(org.onosproject.k8snetworking.api.Constants.ACL_TABLE) ComponentContext(org.osgi.service.component.ComponentContext) K8sNetworkingUtil.portNumberByName(org.onosproject.k8snetworking.util.K8sNetworkingUtil.portNumberByName) GROUPING_TABLE(org.onosproject.k8snetworking.api.Constants.GROUPING_TABLE) Component(org.osgi.service.component.annotations.Component) Lists(com.google.common.collect.Lists) TrafficSelector(org.onosproject.net.flow.TrafficSelector) K8sNetworkEvent(org.onosproject.k8snetworking.api.K8sNetworkEvent) K8sNodeEvent(org.onosproject.k8snode.api.K8sNodeEvent) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) K8S_NETWORKING_APP_ID(org.onosproject.k8snetworking.api.Constants.K8S_NETWORKING_APP_ID) TpPort(org.onlab.packet.TpPort) ComponentConfigService(org.onosproject.cfg.ComponentConfigService) Endpoints(io.fabric8.kubernetes.api.model.Endpoints) EndpointSubset(io.fabric8.kubernetes.api.model.EndpointSubset) Pod(io.fabric8.kubernetes.api.model.Pod) RulePopulatorUtil.computeCtMaskFlag(org.onosproject.k8snetworking.util.RulePopulatorUtil.computeCtMaskFlag) SERVICE_IP_NAT_MODE_DEFAULT(org.onosproject.k8snetworking.impl.OsgiPropertyConstants.SERVICE_IP_NAT_MODE_DEFAULT) IPv4(org.onlab.packet.IPv4) GroupId(org.onosproject.core.GroupId) ExtensionSelector(org.onosproject.net.flow.criteria.ExtensionSelector) B_CLASS(org.onosproject.k8snetworking.api.Constants.B_CLASS) MacAddress(org.onlab.packet.MacAddress) RulePopulatorUtil.buildLoadExtension(org.onosproject.k8snetworking.util.RulePopulatorUtil.buildLoadExtension) K8sNodeService(org.onosproject.k8snode.api.K8sNodeService) LeadershipService(org.onosproject.cluster.LeadershipService) POD_TABLE(org.onosproject.k8snetworking.api.Constants.POD_TABLE) CT_NAT_DST_FLAG(org.onosproject.k8snetworking.util.RulePopulatorUtil.CT_NAT_DST_FLAG) SERVICE_FAKE_MAC_STR(org.onosproject.k8snetworking.api.Constants.SERVICE_FAKE_MAC_STR) CoreService(org.onosproject.core.CoreService) Tools.groupedThreads(org.onlab.util.Tools.groupedThreads) ServicePort(io.fabric8.kubernetes.api.model.ServicePort) K8sNodeListener(org.onosproject.k8snode.api.K8sNodeListener) NAMESPACE_TABLE(org.onosproject.k8snetworking.api.Constants.NAMESPACE_TABLE) K8sNetworkListener(org.onosproject.k8snetworking.api.K8sNetworkListener) NAT_STATELESS(org.onosproject.k8snetworking.api.Constants.NAT_STATELESS) Ethernet(org.onlab.packet.Ethernet) STAT_EGRESS_TABLE(org.onosproject.k8snetworking.api.Constants.STAT_EGRESS_TABLE) A_CLASS(org.onosproject.k8snetworking.api.Constants.A_CLASS) SERVICE_IP_CIDR_DEFAULT(org.onosproject.k8snetworking.impl.OsgiPropertyConstants.SERVICE_IP_CIDR_DEFAULT) K8sNetworkingUtil.podByIp(org.onosproject.k8snetworking.util.K8sNetworkingUtil.podByIp) K8sPodService(org.onosproject.k8snetworking.api.K8sPodService) K8sServiceEvent(org.onosproject.k8snetworking.api.K8sServiceEvent) NodeId(org.onosproject.cluster.NodeId) SERVICE_CIDR(org.onosproject.k8snetworking.impl.OsgiPropertyConstants.SERVICE_CIDR) DST(org.onosproject.k8snetworking.api.Constants.DST) RulePopulatorUtil.computeCtStateFlag(org.onosproject.k8snetworking.util.RulePopulatorUtil.computeCtStateFlag) K8sFlowRuleService(org.onosproject.k8snetworking.api.K8sFlowRuleService) Executors.newSingleThreadExecutor(java.util.concurrent.Executors.newSingleThreadExecutor) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) List(java.util.List) ClusterService(org.onosproject.cluster.ClusterService) PRIORITY_NAT_RULE(org.onosproject.k8snetworking.api.Constants.PRIORITY_NAT_RULE) IpPrefix(org.onlab.packet.IpPrefix) SRC(org.onosproject.k8snetworking.api.Constants.SRC) GroupBucket(org.onosproject.net.group.GroupBucket) K8sNetworkService(org.onosproject.k8snetworking.api.K8sNetworkService) K8sNetworkingUtil.getBclassIpPrefixFromCidr(org.onosproject.k8snetworking.util.K8sNetworkingUtil.getBclassIpPrefixFromCidr) K8sServiceListener(org.onosproject.k8snetworking.api.K8sServiceListener) Activate(org.osgi.service.component.annotations.Activate) Service(io.fabric8.kubernetes.api.model.Service) K8sNode(org.onosproject.k8snode.api.K8sNode) ExecutorService(java.util.concurrent.ExecutorService) IpAddress(org.onlab.packet.IpAddress) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) Logger(org.slf4j.Logger) RulePopulatorUtil(org.onosproject.k8snetworking.util.RulePopulatorUtil) SHIFTED_IP_PREFIX(org.onosproject.k8snetworking.api.Constants.SHIFTED_IP_PREFIX) EndpointPort(io.fabric8.kubernetes.api.model.EndpointPort) NAT_TABLE(org.onosproject.k8snetworking.api.Constants.NAT_TABLE) ExtensionTreatment(org.onosproject.net.flow.instructions.ExtensionTreatment) K8sGroupRuleService(org.onosproject.k8snetworking.api.K8sGroupRuleService) Maps(com.google.common.collect.Maps) SERVICE_TABLE(org.onosproject.k8snetworking.api.Constants.SERVICE_TABLE) K8sNetworkingUtil.nodeIpGatewayIpMap(org.onosproject.k8snetworking.util.K8sNetworkingUtil.nodeIpGatewayIpMap) ReferenceCardinality(org.osgi.service.component.annotations.ReferenceCardinality) RulePopulatorUtil.buildGroupBucket(org.onosproject.k8snetworking.util.RulePopulatorUtil.buildGroupBucket) K8sEndpointsService(org.onosproject.k8snetworking.api.K8sEndpointsService) SHIFTED_IP_CIDR(org.onosproject.k8snetworking.api.Constants.SHIFTED_IP_CIDR) K8sNetwork(org.onosproject.k8snetworking.api.K8sNetwork) Modified(org.osgi.service.component.annotations.Modified) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) Reference(org.osgi.service.component.annotations.Reference) EndpointPort(io.fabric8.kubernetes.api.model.EndpointPort) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) Endpoints(io.fabric8.kubernetes.api.model.Endpoints) NiciraConnTrackTreatmentBuilder(org.onosproject.k8snetworking.util.RulePopulatorUtil.NiciraConnTrackTreatmentBuilder) EndpointSubset(io.fabric8.kubernetes.api.model.EndpointSubset) GroupBucket(org.onosproject.net.group.GroupBucket) RulePopulatorUtil.buildGroupBucket(org.onosproject.k8snetworking.util.RulePopulatorUtil.buildGroupBucket) ExtensionTreatment(org.onosproject.net.flow.instructions.ExtensionTreatment) EndpointAddress(io.fabric8.kubernetes.api.model.EndpointAddress)

Example 5 with TrafficTreatment

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

the class K8sServiceHandler method setShiftDomainRules.

private void setShiftDomainRules(DeviceId deviceId, int installTable, int groupId, int priority, String serviceIp, int servicePort, String protocol, boolean install) {
    if (serviceIp == null || NONE.equals(serviceIp)) {
        return;
    }
    TrafficSelector.Builder sBuilder = DefaultTrafficSelector.builder().matchEthType(Ethernet.TYPE_IPV4).matchIPDst(IpPrefix.valueOf(IpAddress.valueOf(serviceIp), HOST_CIDR_NUM));
    if (TCP.equals(protocol)) {
        sBuilder.matchIPProtocol(IPv4.PROTOCOL_TCP).matchTcpDst(TpPort.tpPort(servicePort));
    } else if (UDP.equals(protocol)) {
        sBuilder.matchIPProtocol(IPv4.PROTOCOL_UDP).matchUdpDst(TpPort.tpPort(servicePort));
    }
    TrafficTreatment treatment = DefaultTrafficTreatment.builder().group(GroupId.valueOf(groupId)).build();
    k8sFlowRuleService.setRule(appId, deviceId, sBuilder.build(), treatment, 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)

Aggregations

TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)321 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)298 TrafficSelector (org.onosproject.net.flow.TrafficSelector)212 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)192 FlowRule (org.onosproject.net.flow.FlowRule)81 DefaultFlowRule (org.onosproject.net.flow.DefaultFlowRule)74 PortNumber (org.onosproject.net.PortNumber)60 Test (org.junit.Test)58 Instruction (org.onosproject.net.flow.instructions.Instruction)49 PiAction (org.onosproject.net.pi.runtime.PiAction)44 Ethernet (org.onlab.packet.Ethernet)38 DeviceId (org.onosproject.net.DeviceId)38 NextObjective (org.onosproject.net.flowobjective.NextObjective)37 PiActionParam (org.onosproject.net.pi.runtime.PiActionParam)35 Criterion (org.onosproject.net.flow.criteria.Criterion)33 List (java.util.List)32 ConnectPoint (org.onosproject.net.ConnectPoint)32 CoreService (org.onosproject.core.CoreService)31 ForwardingObjective (org.onosproject.net.flowobjective.ForwardingObjective)31 Set (java.util.Set)30