Search in sources :

Example 21 with KubevirtNetwork

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

the class KubevirtLbHandler method setBucketsToGroup.

private void setBucketsToGroup(KubevirtLoadBalancer loadBalancer, KubevirtNode gateway, boolean install) {
    int groupId = loadBalancer.hashCode();
    KubevirtNetwork network = networkService.network(loadBalancer.networkId());
    Set<KubevirtPort> ports = portService.ports(loadBalancer.networkId());
    List<GroupBucket> bkts = Lists.newArrayList();
    loadBalancer.members().forEach(ip -> {
        ports.stream().filter(port -> port.ipAddress().equals(ip) && port.macAddress() != null).findAny().ifPresent(port -> bkts.add(buildGroupBucket(port)));
    });
    groupRuleService.setBuckets(appId, gateway.intgBridge(), groupId, bkts, install);
}
Also used : KubevirtNetwork(org.onosproject.kubevirtnetworking.api.KubevirtNetwork) KubevirtNetworkingUtil.getRouterForKubevirtNetwork(org.onosproject.kubevirtnetworking.util.KubevirtNetworkingUtil.getRouterForKubevirtNetwork) GroupBucket(org.onosproject.net.group.GroupBucket) DefaultGroupBucket(org.onosproject.net.group.DefaultGroupBucket) KubevirtPort(org.onosproject.kubevirtnetworking.api.KubevirtPort)

Example 22 with KubevirtNetwork

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

the class KubevirtNetworkManager method allocateIp.

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

Example 23 with KubevirtNetwork

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

the class KubevirtListNetworkCommand method json.

private String json(List<KubevirtNetwork> networks) {
    ObjectMapper mapper = new ObjectMapper();
    ArrayNode result = mapper.createArrayNode();
    for (KubevirtNetwork network : networks) {
        result.add(jsonForEntity(network, KubevirtNetwork.class));
    }
    return prettyJson(mapper, result.toString());
}
Also used : KubevirtNetwork(org.onosproject.kubevirtnetworking.api.KubevirtNetwork) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 24 with KubevirtNetwork

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

the class KubevirtListNetworkCommand method doExecute.

@Override
protected void doExecute() throws Exception {
    KubevirtNetworkService service = get(KubevirtNetworkService.class);
    List<KubevirtNetwork> networks = Lists.newArrayList(service.networks());
    networks.sort(Comparator.comparing(KubevirtNetwork::name));
    String format = genFormatString(ImmutableList.of(CLI_ID_LENGTH, CLI_NAME_LENGTH, CLI_TYPE_LENGTH, CLI_SEG_ID_LENGTH, CLI_IP_ADDRESS_LENGTH));
    if (outputJson()) {
        print("%s", json(networks));
    } else {
        print(format, "ID", "Name", "Type", "SegId", "Gateway");
        for (KubevirtNetwork net : networks) {
            print(format, StringUtils.substring(net.networkId(), 0, CLI_ID_LENGTH - CLI_MARGIN_LENGTH), StringUtils.substring(net.name(), 0, CLI_NAME_LENGTH - CLI_MARGIN_LENGTH), net.type().toString(), net.segmentId() == null ? "N/A" : net.segmentId(), net.gatewayIp() == null ? "N/A" : net.gatewayIp().toString());
        }
    }
}
Also used : KubevirtNetworkService(org.onosproject.kubevirtnetworking.api.KubevirtNetworkService) KubevirtNetwork(org.onosproject.kubevirtnetworking.api.KubevirtNetwork) KubevirtNetworkingUtil.genFormatString(org.onosproject.kubevirtnetworking.util.KubevirtNetworkingUtil.genFormatString)

Example 25 with KubevirtNetwork

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

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