Search in sources :

Example 26 with KubevirtNode

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

the class KubevirtNetworkHandler method setGatewayIcmpRulesForTenantNetwork.

private void setGatewayIcmpRulesForTenantNetwork(KubevirtNode node, KubevirtNetwork network) {
    KubevirtRouter router = getRouterForKubevirtNetwork(kubevirtRouterService, network);
    if (router == null) {
        return;
    }
    KubevirtNode electedGw = gatewayNodeForSpecifiedRouter(nodeService, router);
    if (electedGw == null) {
        return;
    }
    setGatewayIcmpRuleForTenantInternalNetwork(router, network, TENANT_ICMP_TABLE, electedGw.intgBridge(), network.tenantDeviceId(node.hostname()), true);
}
Also used : KubevirtNode(org.onosproject.kubevirtnode.api.KubevirtNode) KubevirtRouter(org.onosproject.kubevirtnetworking.api.KubevirtRouter)

Example 27 with KubevirtNode

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

the class KubevirtRoutingSnatHandler method initGatewayNodeSnatForRouter.

private void initGatewayNodeSnatForRouter(KubevirtRouter router, String gateway, boolean install) {
    if (gateway == null) {
        log.warn("Fail to initialize gateway node snat for router {} " + "because there's no gateway assigned to it", router.name());
        return;
    }
    KubevirtNode electedGw = kubevirtNodeService.node(gateway);
    if (electedGw == null) {
        log.warn("Fail to initialize gateway node snat for router {} " + "because there's no gateway assigned to it", router.name());
        return;
    }
    String routerSnatIp = router.external().keySet().stream().findAny().orElse(null);
    if (routerSnatIp == null) {
        log.warn("Fail to initialize gateway node snat for router {} " + "because there's no gateway snat ip assigned to it", router.name());
        return;
    }
    String externalNet = router.external().values().stream().findAny().orElse(null);
    if (externalNet == null) {
        return;
    }
    if (router.peerRouter() != null && router.peerRouter().ipAddress() != null && router.peerRouter().macAddress() != null) {
        setArpResponseToPeerRouter(electedGw, Ip4Address.valueOf(routerSnatIp), install);
        setStatefulSnatUpstreamRules(electedGw, router, Ip4Address.valueOf(routerSnatIp), router.peerRouter().macAddress(), install);
        setStatefulSnatDownstreamRuleForRouter(electedGw, router, Ip4Address.valueOf(routerSnatIp), kubevirtNetworkService.network(externalNet), install);
    }
}
Also used : KubevirtNode(org.onosproject.kubevirtnode.api.KubevirtNode)

Example 28 with KubevirtNode

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

the class KubevirtRoutingArpHandler method setRuleArpRequestToController.

/**
 * Sets default ARP flow rule to retrieve peer router mac address.
 *
 * @param routerSnatIp route Snat IP
 * @param peerRouterIp peer router IP
 * @param gatewayNodeId gateway node
 * @param install install if true, uninstall otherwise
 */
private void setRuleArpRequestToController(IpAddress routerSnatIp, IpAddress peerRouterIp, String gatewayNodeId, boolean install) {
    KubevirtNode gatewayNode = kubevirtNodeService.node(gatewayNodeId);
    if (gatewayNode == null) {
        return;
    }
    if (routerSnatIp == null) {
        return;
    }
    TrafficSelector selector = DefaultTrafficSelector.builder().matchEthType(EthType.EtherType.ARP.ethType().toShort()).matchArpOp(ARP.OP_REPLY).matchArpSpa(peerRouterIp.getIp4Address()).matchArpTpa(routerSnatIp.getIp4Address()).build();
    TrafficTreatment treatment = DefaultTrafficTreatment.builder().punt().build();
    kubevirtFlowRuleService.setRule(appId, gatewayNode.intgBridge(), selector, treatment, PRIORITY_ARP_GATEWAY_RULE, GW_ENTRY_TABLE, install);
}
Also used : KubevirtNode(org.onosproject.kubevirtnode.api.KubevirtNode) 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 29 with KubevirtNode

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

the class KubevirtRoutingArpHandler method retrievePeerRouterMac.

/**
 * Triggers ARP request to retrieve the peer router mac address.
 *
 * @param router kubevirt router
 * @param peerRouterIp peer router IP address
 */
private void retrievePeerRouterMac(KubevirtRouter router, IpAddress peerRouterIp) {
    log.info("Sending ARP request to the peer router {} to retrieve the MAC address.", peerRouterIp.getIp4Address().toString());
    String routerSnatIp = router.external().keySet().stream().findAny().orElse(null);
    if (routerSnatIp == null) {
        return;
    }
    IpAddress sourceIp = IpAddress.valueOf(routerSnatIp);
    MacAddress sourceMac = DEFAULT_GATEWAY_MAC;
    Ethernet ethRequest = ARP.buildArpRequest(sourceMac.toBytes(), sourceIp.toOctets(), peerRouterIp.toOctets(), VlanId.NO_VID);
    KubevirtNode gatewayNode = kubevirtNodeService.node(router.electedGateway());
    if (gatewayNode == null) {
        return;
    }
    PortNumber externalPatchPortNum = KubevirtNetworkingUtil.externalPatchPortNum(deviceService, gatewayNode);
    if (externalPatchPortNum == null) {
        return;
    }
    TrafficTreatment treatment = DefaultTrafficTreatment.builder().setOutput(externalPatchPortNum).build();
    packetService.emit(new DefaultOutboundPacket(gatewayNode.intgBridge(), treatment, ByteBuffer.wrap(ethRequest.serialize())));
}
Also used : KubevirtNode(org.onosproject.kubevirtnode.api.KubevirtNode) Ethernet(org.onlab.packet.Ethernet) IpAddress(org.onlab.packet.IpAddress) DefaultOutboundPacket(org.onosproject.net.packet.DefaultOutboundPacket) MacAddress(org.onlab.packet.MacAddress) PortNumber(org.onosproject.net.PortNumber) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment)

Example 30 with KubevirtNode

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

the class KubevirtSwitchingTenantHandler method setEgressRules.

private void setEgressRules(KubevirtPort port, boolean install) {
    if (port.ipAddress() == null) {
        return;
    }
    KubevirtNetwork network = kubevirtNetworkService.network(port.networkId());
    if (network == null) {
        return;
    }
    if (network.type() == FLAT || network.type() == VLAN) {
        return;
    }
    if (network.segmentId() == null) {
        return;
    }
    KubevirtNode localNode = kubevirtNodeService.node(port.deviceId());
    if (localNode == null || localNode.type() == MASTER) {
        return;
    }
    for (KubevirtNode remoteNode : kubevirtNodeService.completeNodes(WORKER)) {
        if (remoteNode.hostname().equals(localNode.hostname())) {
            continue;
        }
        while (true) {
            KubevirtNode updatedNode = kubevirtNodeService.node(localNode.hostname());
            if (tunnelToTenantPort(deviceService, updatedNode, network) != null) {
                break;
            } else {
                log.info("Waiting for tunnel to tenant patch port creation " + "on egress rule setup on node {}", updatedNode);
                waitFor(3);
            }
        }
        PortNumber patchPortNumber = tunnelToTenantPort(deviceService, remoteNode, network);
        PortNumber tunnelPortNumber = tunnelPort(remoteNode, network);
        if (tunnelPortNumber == null) {
            return;
        }
        TrafficSelector.Builder sIpBuilder = DefaultTrafficSelector.builder().matchInPort(patchPortNumber).matchEthType(Ethernet.TYPE_IPV4).matchIPDst(IpPrefix.valueOf(port.ipAddress(), 32));
        TrafficSelector.Builder sArpBuilder = DefaultTrafficSelector.builder().matchInPort(patchPortNumber).matchEthType(Ethernet.TYPE_ARP).matchArpTpa(Ip4Address.valueOf(port.ipAddress().toString()));
        TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder().setTunnelId(Long.parseLong(network.segmentId())).extension(buildExtension(deviceService, remoteNode.tunBridge(), localNode.dataIp().getIp4Address()), remoteNode.tunBridge()).setOutput(tunnelPortNumber);
        flowRuleService.setRule(appId, remoteNode.tunBridge(), sIpBuilder.build(), tBuilder.build(), PRIORITY_TUNNEL_RULE, TUNNEL_DEFAULT_TABLE, install);
        flowRuleService.setRule(appId, remoteNode.tunBridge(), sArpBuilder.build(), tBuilder.build(), PRIORITY_TUNNEL_RULE, TUNNEL_DEFAULT_TABLE, install);
    }
    log.debug("Install egress rules for instance {}, segment ID {}", port.ipAddress(), 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