Search in sources :

Example 1 with PRIORITY_DEFAULT_RULE

use of org.onosproject.k8snetworking.api.Constants.PRIORITY_DEFAULT_RULE in project onos by opennetworkinglab.

the class K8sSwitchingHandler method setForwardingRulesForTunnel.

/**
 * Configures the flow rules which are used for L2 packet switching.
 * Note that these rules will be inserted in switching table (table 80).
 *
 * @param port      kubernetes port object
 * @param install   install flag, add the rule if true, remove it otherwise
 */
private void setForwardingRulesForTunnel(K8sPort port, boolean install) {
    // switching rules for the instPorts in the same node
    TrafficSelector selector = DefaultTrafficSelector.builder().matchEthType(Ethernet.TYPE_IPV4).matchIPDst(port.ipAddress().toIpPrefix()).build();
    TrafficTreatment treatment = DefaultTrafficTreatment.builder().setEthDst(port.macAddress()).setOutput(port.portNumber()).build();
    k8sFlowRuleService.setRule(appId, port.deviceId(), selector, treatment, PRIORITY_SWITCHING_RULE, FORWARDING_TABLE, install);
    // switching rules for the node in the remote node
    K8sNode localNode = k8sNodeService.node(port.deviceId());
    if (localNode == null) {
        final String error = String.format("Cannot find kubernetes node for %s", port.deviceId());
        throw new IllegalStateException(error);
    }
    k8sNodeService.completeNodes().stream().filter(remoteNode -> !remoteNode.intgBridge().equals(localNode.intgBridge())).forEach(remoteNode -> {
        TrafficTreatment treatmentToTunnel = DefaultTrafficTreatment.builder().setOutput(remoteNode.intgToTunPortNum()).build();
        k8sFlowRuleService.setRule(appId, remoteNode.intgBridge(), selector, treatmentToTunnel, PRIORITY_SWITCHING_RULE, FORWARDING_TABLE, install);
        PortNumber portNum = tunnelPortNumByNetId(port.networkId(), k8sNetworkService, remoteNode);
        TrafficTreatment treatmentToRemote = DefaultTrafficTreatment.builder().extension(buildExtension(deviceService, remoteNode.tunBridge(), localNode.dataIp().getIp4Address()), remoteNode.tunBridge()).setTunnelId(getVni(port)).setOutput(portNum).build();
        k8sFlowRuleService.setRule(appId, remoteNode.tunBridge(), selector, treatmentToRemote, PRIORITY_DEFAULT_RULE, TUN_ENTRY_TABLE, install);
    });
}
Also used : VXLAN(org.onosproject.k8snetworking.api.K8sNetwork.Type.VXLAN) ARP_TABLE(org.onosproject.k8snetworking.api.Constants.ARP_TABLE) CoreService(org.onosproject.core.CoreService) PortNumber(org.onosproject.net.PortNumber) DeviceService(org.onosproject.net.device.DeviceService) Tools.groupedThreads(org.onlab.util.Tools.groupedThreads) K8sNodeListener(org.onosproject.k8snode.api.K8sNodeListener) K8sNetworkListener(org.onosproject.k8snetworking.api.K8sNetworkListener) DriverService(org.onosproject.net.driver.DriverService) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) Ethernet(org.onlab.packet.Ethernet) ApplicationId(org.onosproject.core.ApplicationId) MastershipService(org.onosproject.mastership.MastershipService) NodeId(org.onosproject.cluster.NodeId) K8sNetworkingUtil.tunnelPortNumByNetId(org.onosproject.k8snetworking.util.K8sNetworkingUtil.tunnelPortNumByNetId) Deactivate(org.osgi.service.component.annotations.Deactivate) Set(java.util.Set) K8sFlowRuleService(org.onosproject.k8snetworking.api.K8sFlowRuleService) Executors.newSingleThreadExecutor(java.util.concurrent.Executors.newSingleThreadExecutor) GRE(org.onosproject.k8snetworking.api.K8sNetwork.Type.GRE) Objects(java.util.Objects) GENEVE(org.onosproject.k8snetworking.api.K8sNetwork.Type.GENEVE) ARP_BROADCAST_MODE(org.onosproject.k8snetworking.api.Constants.ARP_BROADCAST_MODE) TUN_ENTRY_TABLE(org.onosproject.k8snetworking.api.Constants.TUN_ENTRY_TABLE) ClusterService(org.onosproject.cluster.ClusterService) DeviceId(org.onosproject.net.DeviceId) IpPrefix(org.onlab.packet.IpPrefix) PRIORITY_DEFAULT_RULE(org.onosproject.k8snetworking.api.Constants.PRIORITY_DEFAULT_RULE) PRIORITY_TUNNEL_TAG_RULE(org.onosproject.k8snetworking.api.Constants.PRIORITY_TUNNEL_TAG_RULE) K8sNetworkService(org.onosproject.k8snetworking.api.K8sNetworkService) Strings(com.google.common.base.Strings) Component(org.osgi.service.component.annotations.Component) TrafficSelector(org.onosproject.net.flow.TrafficSelector) FORWARDING_TABLE(org.onosproject.k8snetworking.api.Constants.FORWARDING_TABLE) K8sNetworkEvent(org.onosproject.k8snetworking.api.K8sNetworkEvent) K8sPort(org.onosproject.k8snetworking.api.K8sPort) JUMP_TABLE(org.onosproject.k8snetworking.api.Constants.JUMP_TABLE) K8sNodeEvent(org.onosproject.k8snode.api.K8sNodeEvent) Activate(org.osgi.service.component.annotations.Activate) VTAG_TABLE(org.onosproject.k8snetworking.api.Constants.VTAG_TABLE) K8sNetworkingUtil.getPropertyValue(org.onosproject.k8snetworking.util.K8sNetworkingUtil.getPropertyValue) K8sNode(org.onosproject.k8snode.api.K8sNode) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) ExecutorService(java.util.concurrent.ExecutorService) K8S_NETWORKING_APP_ID(org.onosproject.k8snetworking.api.Constants.K8S_NETWORKING_APP_ID) ComponentConfigService(org.onosproject.cfg.ComponentConfigService) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) Logger(org.slf4j.Logger) K8sNetworkingUtil.tunnelPortNumByNetType(org.onosproject.k8snetworking.util.K8sNetworkingUtil.tunnelPortNumByNetType) RulePopulatorUtil.buildExtension(org.onosproject.k8snetworking.util.RulePopulatorUtil.buildExtension) PRIORITY_SWITCHING_RULE(org.onosproject.k8snetworking.api.Constants.PRIORITY_SWITCHING_RULE) ReferenceCardinality(org.osgi.service.component.annotations.ReferenceCardinality) ConfigProperty(org.onosproject.cfg.ConfigProperty) K8sNetwork(org.onosproject.k8snetworking.api.K8sNetwork) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) K8sNodeService(org.onosproject.k8snode.api.K8sNodeService) Reference(org.osgi.service.component.annotations.Reference) LeadershipService(org.onosproject.cluster.LeadershipService) K8sNode(org.onosproject.k8snode.api.K8sNode) 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)

Aggregations

Strings (com.google.common.base.Strings)1 Objects (java.util.Objects)1 Set (java.util.Set)1 ExecutorService (java.util.concurrent.ExecutorService)1 Executors.newSingleThreadExecutor (java.util.concurrent.Executors.newSingleThreadExecutor)1 Ethernet (org.onlab.packet.Ethernet)1 IpPrefix (org.onlab.packet.IpPrefix)1 Tools.groupedThreads (org.onlab.util.Tools.groupedThreads)1 ComponentConfigService (org.onosproject.cfg.ComponentConfigService)1 ConfigProperty (org.onosproject.cfg.ConfigProperty)1 ClusterService (org.onosproject.cluster.ClusterService)1 LeadershipService (org.onosproject.cluster.LeadershipService)1 NodeId (org.onosproject.cluster.NodeId)1 ApplicationId (org.onosproject.core.ApplicationId)1 CoreService (org.onosproject.core.CoreService)1 ARP_BROADCAST_MODE (org.onosproject.k8snetworking.api.Constants.ARP_BROADCAST_MODE)1 ARP_TABLE (org.onosproject.k8snetworking.api.Constants.ARP_TABLE)1 FORWARDING_TABLE (org.onosproject.k8snetworking.api.Constants.FORWARDING_TABLE)1 JUMP_TABLE (org.onosproject.k8snetworking.api.Constants.JUMP_TABLE)1 K8S_NETWORKING_APP_ID (org.onosproject.k8snetworking.api.Constants.K8S_NETWORKING_APP_ID)1