Search in sources :

Example 1 with KubevirtNetwork

use of org.onosproject.kubevirtnetworking.api.KubevirtNetwork in project onos by opennetworkinglab.

the class KubevirtListIpAddressCommand method doExecute.

@Override
protected void doExecute() throws Exception {
    KubevirtNetworkService service = get(KubevirtNetworkService.class);
    if (networkId == null) {
        error("No network identifier was specified");
        return;
    }
    KubevirtNetwork network = service.network(networkId);
    if (network == null) {
        print("No network was found with the given network ID");
        return;
    }
    KubevirtIpPool pool = network.ipPool();
    if (pool == null) {
        print("No IP pool was found with the given network ID");
        return;
    }
    String format = genFormatString(ImmutableList.of(CLI_IP_ADDRESS_LENGTH, CLI_IP_ADDRESS_AVAILABILITY));
    print(format, "IP Address", "Availability");
    List<IpAddress> sortedAllocatedIps = new ArrayList<>(pool.allocatedIps());
    Collections.sort(sortedAllocatedIps);
    for (IpAddress ip : sortedAllocatedIps) {
        print(format, ip.toString(), "[ X ]");
    }
    List<IpAddress> sortedAvailableIps = new ArrayList<>(pool.availableIps());
    Collections.sort(sortedAvailableIps);
    for (IpAddress ip : sortedAvailableIps) {
        print(format, ip.toString(), "[ O ]");
    }
}
Also used : KubevirtNetworkService(org.onosproject.kubevirtnetworking.api.KubevirtNetworkService) KubevirtNetwork(org.onosproject.kubevirtnetworking.api.KubevirtNetwork) ArrayList(java.util.ArrayList) IpAddress(org.onlab.packet.IpAddress) KubevirtIpPool(org.onosproject.kubevirtnetworking.api.KubevirtIpPool) KubevirtNetworkingUtil.genFormatString(org.onosproject.kubevirtnetworking.util.KubevirtNetworkingUtil.genFormatString)

Example 2 with KubevirtNetwork

use of org.onosproject.kubevirtnetworking.api.KubevirtNetwork 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 3 with KubevirtNetwork

use of org.onosproject.kubevirtnetworking.api.KubevirtNetwork in project onos by opennetworkinglab.

the class KubevirtFloatingIpHandler method setFloatingIpRulesForFip.

private void setFloatingIpRulesForFip(KubevirtRouter router, KubevirtFloatingIp floatingIp, KubevirtNode electedGw, boolean install) {
    KubevirtPort kubevirtPort = getKubevirtPortByFloatingIp(floatingIp);
    if (kubevirtPort == null) {
        return;
    }
    KubevirtNetwork kubevirtNetwork = kubevirtNetworkService.network(kubevirtPort.networkId());
    if (kubevirtNetwork.type() == VXLAN || kubevirtNetwork.type() == GENEVE || kubevirtNetwork.type() == GRE) {
        setFloatingIpDownstreamRulesToGatewayTunBridge(floatingIp, electedGw, kubevirtNetwork, kubevirtPort, install);
    }
    setFloatingIpArpResponseRules(router, floatingIp, kubevirtPort, electedGw, install);
    setFloatingIpUpstreamRules(router, floatingIp, kubevirtPort, electedGw, install);
    setFloatingIpDownstreamRules(router, floatingIp, kubevirtPort, electedGw, install);
}
Also used : KubevirtNetwork(org.onosproject.kubevirtnetworking.api.KubevirtNetwork) KubevirtPort(org.onosproject.kubevirtnetworking.api.KubevirtPort)

Example 4 with KubevirtNetwork

use of org.onosproject.kubevirtnetworking.api.KubevirtNetwork 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 5 with KubevirtNetwork

use of org.onosproject.kubevirtnetworking.api.KubevirtNetwork in project onos by opennetworkinglab.

the class KubevirtNetworkManager method releaseIp.

@Override
public void releaseIp(String networkId, IpAddress ip) {
    checkArgument(!Strings.isNullOrEmpty(networkId), ERR_NULL_NETWORK_ID);
    checkArgument(ip != null, ERR_NULL_IP);
    try {
        KubevirtNetwork network = networkStore.network(networkId);
        network.ipPool().releaseIp(ip);
        networkStore.updateNetwork(network);
    } catch (Exception e) {
        log.error("Failed to allocate IP address");
    }
}
Also used : KubevirtNetwork(org.onosproject.kubevirtnetworking.api.KubevirtNetwork)

Aggregations

KubevirtNetwork (org.onosproject.kubevirtnetworking.api.KubevirtNetwork)25 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)6 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)6 TrafficSelector (org.onosproject.net.flow.TrafficSelector)6 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)6 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)5 KubevirtNetworkAdminService (org.onosproject.kubevirtnetworking.api.KubevirtNetworkAdminService)5 JsonNode (com.fasterxml.jackson.databind.JsonNode)4 Produces (javax.ws.rs.Produces)4 DefaultKubevirtNetwork (org.onosproject.kubevirtnetworking.api.DefaultKubevirtNetwork)4 KubevirtPort (org.onosproject.kubevirtnetworking.api.KubevirtPort)4 KubevirtNode (org.onosproject.kubevirtnode.api.KubevirtNode)4 IOException (java.io.IOException)3 GET (javax.ws.rs.GET)3 Path (javax.ws.rs.Path)3 IpAddress (org.onlab.packet.IpAddress)3 KubevirtHostRoute (org.onosproject.kubevirtnetworking.api.KubevirtHostRoute)3 KubevirtIpPool (org.onosproject.kubevirtnetworking.api.KubevirtIpPool)3 KubevirtNetworkJsonMatcher.matchesKubevirtNetwork (org.onosproject.kubevirtnetworking.codec.KubevirtNetworkJsonMatcher.matchesKubevirtNetwork)3 KubevirtNetworkingUtil.getRouterForKubevirtNetwork (org.onosproject.kubevirtnetworking.util.KubevirtNetworkingUtil.getRouterForKubevirtNetwork)3