Search in sources :

Example 6 with KubevirtNode

use of org.onosproject.kubevirtnode.api.KubevirtNode in project onos by opennetworkinglab.

the class KubevirtNetworkHandler method setGatewayInterNetworkRoutingFromNetworkToPort.

private void setGatewayInterNetworkRoutingFromNetworkToPort(KubevirtRouter router, KubevirtNetwork srcNetwork, KubevirtPort dstPort, KubevirtNode gatewayNode, boolean install) {
    Device gwDevice = deviceService.getDevice(gatewayNode.intgBridge());
    if (gwDevice == null) {
        log.warn("Failed to set internal network routing rule because " + "there's no device Id for device {}", gatewayNode.intgBridge());
        return;
    }
    MacAddress routerMacAddress = getRouterMacAddress(router);
    if (routerMacAddress == null) {
        log.warn("Failed to set internal network routing rule because " + "there's no br-int port for device {}", gatewayNode.intgBridge());
        return;
    }
    TrafficSelector.Builder sBuilder;
    TrafficTreatment treatment;
    if (srcNetwork.type() == FLAT || srcNetwork.type() == VLAN) {
        sBuilder = DefaultTrafficSelector.builder().matchEthType(Ethernet.TYPE_IPV4).matchEthDst(routerMacAddress).matchIPSrc(IpPrefix.valueOf(srcNetwork.cidr())).matchIPDst(IpPrefix.valueOf(dstPort.ipAddress(), 32));
        treatment = DefaultTrafficTreatment.builder().setEthSrc(routerMacAddress).setEthDst(dstPort.macAddress()).transition(FORWARDING_TABLE).build();
        flowService.setRule(appId, gwDevice.id(), sBuilder.build(), treatment, PRIORITY_INTERNAL_ROUTING_RULE, GW_ENTRY_TABLE, install);
    } else {
        KubevirtNetwork dstNetwork = kubevirtNetworkService.network(dstPort.networkId());
        if (dstNetwork == null) {
            return;
        }
        KubevirtNode dstPortWorkerNode = kubevirtNodeService.node(dstPort.deviceId());
        if (dstPortWorkerNode == null) {
            return;
        }
        sBuilder = DefaultTrafficSelector.builder().matchEthType(Ethernet.TYPE_IPV4).matchEthDst(routerMacAddress).matchTunnelId(Long.parseLong(srcNetwork.segmentId())).matchIPSrc(IpPrefix.valueOf(srcNetwork.cidr())).matchIPDst(IpPrefix.valueOf(dstPort.ipAddress(), 32));
        treatment = DefaultTrafficTreatment.builder().setTunnelId(Long.parseLong(dstNetwork.segmentId())).setEthSrc(routerMacAddress).setEthDst(dstPort.macAddress()).extension(buildExtension(deviceService, gatewayNode.tunBridge(), dstPortWorkerNode.dataIp().getIp4Address()), gatewayNode.tunBridge()).setOutput(PortNumber.IN_PORT).build();
        flowService.setRule(appId, gatewayNode.tunBridge(), sBuilder.build(), treatment, PRIORITY_INTERNAL_ROUTING_RULE, TUNNEL_DEFAULT_TABLE, install);
    }
}
Also used : KubevirtNode(org.onosproject.kubevirtnode.api.KubevirtNode) KubevirtNetwork(org.onosproject.kubevirtnetworking.api.KubevirtNetwork) KubevirtNetworkingUtil.getRouterForKubevirtNetwork(org.onosproject.kubevirtnetworking.util.KubevirtNetworkingUtil.getRouterForKubevirtNetwork) Device(org.onosproject.net.Device) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) KubevirtNetworkingUtil.getRouterMacAddress(org.onosproject.kubevirtnetworking.util.KubevirtNetworkingUtil.getRouterMacAddress) MacAddress(org.onlab.packet.MacAddress) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment)

Example 7 with KubevirtNode

use of org.onosproject.kubevirtnode.api.KubevirtNode in project onos by opennetworkinglab.

the class KubevirtFloatingIpHandler method setFloatingIpDownstreamRulesToGatewayTunBridge.

private void setFloatingIpDownstreamRulesToGatewayTunBridge(KubevirtFloatingIp floatingIp, KubevirtNode electedGw, KubevirtNetwork network, KubevirtPort port, boolean install) {
    KubevirtNode workerNode = kubevirtNodeService.node(port.deviceId());
    if (workerNode == null) {
        log.warn("Failed to install floating Ip rules for floating ip {} " + "because fail to fine the worker node that the associated port is running on", floatingIp.floatingIp());
        return;
    }
    PortNumber tunnelPortNumber = tunnelPort(electedGw, network);
    if (tunnelPortNumber == null) {
        return;
    }
    TrafficSelector.Builder sBuilder = DefaultTrafficSelector.builder().matchEthType(Ethernet.TYPE_IPV4).matchIPDst(IpPrefix.valueOf(port.ipAddress(), 32)).matchEthDst(port.macAddress());
    TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder().setTunnelId(Long.parseLong(network.segmentId())).extension(buildExtension(deviceService, electedGw.tunBridge(), workerNode.dataIp().getIp4Address()), electedGw.tunBridge()).setOutput(tunnelPortNumber);
    flowService.setRule(appId, electedGw.tunBridge(), sBuilder.build(), tBuilder.build(), PRIORITY_FLOATING_GATEWAY_TUN_BRIDGE_RULE, TUNNEL_DEFAULT_TABLE, install);
}
Also used : KubevirtNode(org.onosproject.kubevirtnode.api.KubevirtNode) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) PortNumber(org.onosproject.net.PortNumber) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment)

Example 8 with KubevirtNode

use of org.onosproject.kubevirtnode.api.KubevirtNode in project onos by opennetworkinglab.

the class KubevirtLbHandler method setLbDownStreamRulesForTunBridge.

private void setLbDownStreamRulesForTunBridge(KubevirtLoadBalancer loadBalancer, KubevirtNode gateway, boolean install) {
    Set<KubevirtPort> ports = portService.ports(loadBalancer.networkId());
    KubevirtNetwork network = networkService.network(loadBalancer.networkId());
    PortNumber tunnelPortNumber = tunnelPort(gateway, network);
    if (tunnelPortNumber == null) {
        return;
    }
    loadBalancer.members().forEach(ip -> {
        ports.stream().filter(port -> port.ipAddress().equals(ip) && port.macAddress() != null).findAny().ifPresent(port -> {
            KubevirtNode workerNode = nodeService.node(port.deviceId());
            TrafficSelector.Builder sBuilder = DefaultTrafficSelector.builder().matchEthType(Ethernet.TYPE_IPV4).matchIPDst(IpPrefix.valueOf(port.ipAddress(), 32)).matchEthDst(port.macAddress());
            TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder().setTunnelId(Long.parseLong(network.segmentId())).extension(buildExtension(deviceService, gateway.tunBridge(), workerNode.dataIp().getIp4Address()), gateway.tunBridge()).setOutput(tunnelPortNumber);
            flowRuleService.setRule(appId, gateway.tunBridge(), sBuilder.build(), tBuilder.build(), PRIORITY_LB_GATEWAY_TUN_BRIDGE_RULE, TUNNEL_DEFAULT_TABLE, install);
        });
    });
}
Also used : KubevirtNode(org.onosproject.kubevirtnode.api.KubevirtNode) KubevirtNetwork(org.onosproject.kubevirtnetworking.api.KubevirtNetwork) KubevirtNetworkingUtil.getRouterForKubevirtNetwork(org.onosproject.kubevirtnetworking.util.KubevirtNetworkingUtil.getRouterForKubevirtNetwork) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) KubevirtPort(org.onosproject.kubevirtnetworking.api.KubevirtPort) PortNumber(org.onosproject.net.PortNumber) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment)

Example 9 with KubevirtNode

use of org.onosproject.kubevirtnode.api.KubevirtNode in project onos by opennetworkinglab.

the class KubevirtRoutingSnatHandler method setDownStreamRulesToGatewayTunBridge.

private void setDownStreamRulesToGatewayTunBridge(KubevirtNetwork network, KubevirtNode electedGw, KubevirtPort port, boolean install) {
    KubevirtNode workerNode = kubevirtNodeService.node(port.deviceId());
    if (workerNode == null) {
        return;
    }
    PortNumber tunnelPortNumber = tunnelPort(electedGw, network);
    if (tunnelPortNumber == null) {
        return;
    }
    TrafficSelector.Builder sBuilder = DefaultTrafficSelector.builder().matchEthType(Ethernet.TYPE_IPV4).matchIPDst(IpPrefix.valueOf(port.ipAddress(), 32)).matchEthDst(port.macAddress());
    TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder().setTunnelId(Long.parseLong(network.segmentId())).extension(buildExtension(deviceService, electedGw.tunBridge(), workerNode.dataIp().getIp4Address()), electedGw.tunBridge()).setOutput(tunnelPortNumber);
    flowService.setRule(appId, electedGw.tunBridge(), sBuilder.build(), tBuilder.build(), PRIORITY_FORWARDING_RULE, TUNNEL_DEFAULT_TABLE, install);
}
Also used : KubevirtNode(org.onosproject.kubevirtnode.api.KubevirtNode) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) PortNumber(org.onosproject.net.PortNumber) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment)

Example 10 with KubevirtNode

use of org.onosproject.kubevirtnode.api.KubevirtNode in project onos by opennetworkinglab.

the class KubevirtSwitchingTenantHandler method setIngressRules.

private void setIngressRules(KubevirtNode node, boolean install) {
    for (KubevirtNetwork network : kubevirtNetworkService.tenantNetworks()) {
        if (node == null || node.type() != WORKER) {
            return;
        }
        while (true) {
            KubevirtNode updatedNode = kubevirtNodeService.node(node.hostname());
            if (tunnelToTenantPort(deviceService, updatedNode, network) != null) {
                break;
            } else {
                log.info("Waiting for tunnel to tenant patch port creation " + "on ingress rule setup on node {}", updatedNode);
                waitFor(3);
            }
        }
        PortNumber patchPortNumber = tunnelToTenantPort(deviceService, node, network);
        TrafficSelector.Builder sBuilder = DefaultTrafficSelector.builder().matchTunnelId(Long.parseLong(network.segmentId()));
        TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder().setOutput(patchPortNumber);
        flowRuleService.setRule(appId, node.tunBridge(), sBuilder.build(), tBuilder.build(), PRIORITY_TUNNEL_RULE, TUNNEL_DEFAULT_TABLE, install);
        log.debug("Install ingress rules for segment ID {}", network.segmentId());
    }
}
Also used : KubevirtNode(org.onosproject.kubevirtnode.api.KubevirtNode) KubevirtNetwork(org.onosproject.kubevirtnetworking.api.KubevirtNetwork) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) PortNumber(org.onosproject.net.PortNumber) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment)

Aggregations

KubevirtNode (org.onosproject.kubevirtnode.api.KubevirtNode)46 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)11 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)11 KubevirtNodeAdminService (org.onosproject.kubevirtnode.api.KubevirtNodeAdminService)10 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)10 TrafficSelector (org.onosproject.net.flow.TrafficSelector)10 DefaultKubevirtNode (org.onosproject.kubevirtnode.api.DefaultKubevirtNode)9 PortNumber (org.onosproject.net.PortNumber)9 Produces (javax.ws.rs.Produces)8 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)6 Path (javax.ws.rs.Path)6 Test (org.junit.Test)6 JsonNode (com.fasterxml.jackson.databind.JsonNode)5 GET (javax.ws.rs.GET)5 KubevirtNodeService (org.onosproject.kubevirtnode.api.KubevirtNodeService)5 KubevirtNodeJsonMatcher.matchesKubevirtNode (org.onosproject.kubevirtnode.codec.KubevirtNodeJsonMatcher.matchesKubevirtNode)5 MacAddress (org.onlab.packet.MacAddress)4 KubevirtPhyInterface (org.onosproject.kubevirtnode.api.KubevirtPhyInterface)4 Device (org.onosproject.net.Device)4 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)3