Search in sources :

Example 16 with K8sNode

use of org.onosproject.k8snode.api.K8sNode in project onos by opennetworkinglab.

the class K8sSwitchingGatewayHandler method setLocalBridgeRules.

private void setLocalBridgeRules(K8sNetwork k8sNetwork, boolean install) {
    for (K8sNode node : k8sNodeService.completeNodes()) {
        if (node.hostname().equals(k8sNetwork.name())) {
            setLocalBridgeRule(k8sNetwork, node, REQUEST, install);
            setLocalBridgeRule(k8sNetwork, node, REPLY, install);
        }
    }
}
Also used : K8sNode(org.onosproject.k8snode.api.K8sNode)

Example 17 with K8sNode

use of org.onosproject.k8snode.api.K8sNode in project onos by opennetworkinglab.

the class K8sSwitchingGatewayHandler method setInterNodeRoutingRules.

private void setInterNodeRoutingRules(K8sNode srcNode, boolean install) {
    if (srcNode == null) {
        return;
    }
    for (K8sNode dstNode : k8sNodeService.nodes()) {
        if (StringUtils.equals(srcNode.hostname(), dstNode.hostname())) {
            continue;
        }
        boolean sameHost = false;
        for (K8sHost host : k8sHostService.completeHosts()) {
            Set<String> nodeNames = host.nodeNames();
            // we simply do not tunnel the traffic, instead we route the traffic
            if (nodeNames.contains(srcNode.hostname()) && nodeNames.contains(dstNode.hostname())) {
                sameHost = true;
            }
        }
        if (sameHost) {
            TrafficSelector originalSelector = DefaultTrafficSelector.builder().matchEthType(Ethernet.TYPE_IPV4).matchIPSrc(IpPrefix.valueOf(srcNode.podCidr())).matchIPDst(IpPrefix.valueOf(dstNode.podCidr())).build();
            TrafficTreatment treatment = DefaultTrafficTreatment.builder().setOutput(dstNode.tunToIntgPortNum()).build();
            k8sFlowRuleService.setRule(appId, dstNode.tunBridge(), originalSelector, treatment, PRIORITY_INTER_NODE_RULE, TUN_ENTRY_TABLE, install);
            TrafficSelector transformedSelector = DefaultTrafficSelector.builder().matchEthType(Ethernet.TYPE_IPV4).matchIPSrc(IpPrefix.valueOf(shiftIpDomain(srcNode.podCidr(), SHIFTED_IP_PREFIX))).matchIPDst(IpPrefix.valueOf(dstNode.podCidr())).build();
            k8sFlowRuleService.setRule(appId, dstNode.tunBridge(), transformedSelector, treatment, PRIORITY_INTER_NODE_RULE, TUN_ENTRY_TABLE, install);
            String nodeIpPrefix = NODE_IP_PREFIX + ".0.0.0/8";
            TrafficSelector nodePortSelector = DefaultTrafficSelector.builder().matchEthType(Ethernet.TYPE_IPV4).matchIPSrc(IpPrefix.valueOf(nodeIpPrefix)).matchIPDst(IpPrefix.valueOf(dstNode.podCidr())).build();
            k8sFlowRuleService.setRule(appId, dstNode.tunBridge(), nodePortSelector, treatment, PRIORITY_INTER_NODE_RULE, TUN_ENTRY_TABLE, install);
        }
    }
}
Also used : K8sNode(org.onosproject.k8snode.api.K8sNode) K8sHost(org.onosproject.k8snode.api.K8sHost) 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 18 with K8sNode

use of org.onosproject.k8snode.api.K8sNode in project onos by opennetworkinglab.

the class K8sManagementWebResource method syncRulesBaseForNode.

private void syncRulesBaseForNode(K8sNode k8sNode) {
    K8sNode updated = k8sNode.updateState(K8sNodeState.INIT);
    nodeAdminService.updateNode(updated);
    boolean result = true;
    long timeoutExpiredMs = System.currentTimeMillis() + TIMEOUT_MS;
    while (nodeAdminService.node(k8sNode.hostname()).state() != COMPLETE) {
        long waitMs = timeoutExpiredMs - System.currentTimeMillis();
        try {
            sleep(SLEEP_MS);
        } catch (InterruptedException e) {
            log.error("Exception caused during node synchronization...");
        }
        if (nodeAdminService.node(k8sNode.hostname()).state() == COMPLETE) {
            break;
        } else {
            nodeAdminService.updateNode(updated);
            log.info("Failed to synchronize flow rules, retrying...");
        }
        if (waitMs <= 0) {
            result = false;
            break;
        }
    }
    if (result) {
        log.info("Successfully synchronize flow rules for node {}!", k8sNode.hostname());
    } else {
        log.warn("Failed to synchronize flow rules for node {}.", k8sNode.hostname());
    }
}
Also used : K8sNode(org.onosproject.k8snode.api.K8sNode)

Example 19 with K8sNode

use of org.onosproject.k8snode.api.K8sNode in project onos by opennetworkinglab.

the class K8sNodeListCommand method doExecute.

@Override
protected void doExecute() {
    K8sNodeService nodeService = get(K8sNodeService.class);
    List<K8sNode> nodes = Lists.newArrayList(nodeService.nodes());
    nodes.sort(Comparator.comparing(K8sNode::hostname));
    String format = genFormatString(ImmutableList.of(HOSTNAME_LENGTH, TYPE_LENGTH, MANAGEMENT_IP_LENGTH, DATA_IP_LENGTH, STATUS));
    if (outputJson()) {
        print("%s", json(nodes));
    } else {
        print(format, "Hostname", "Type", "Management IP", "Data IP", "State");
        for (K8sNode node : nodes) {
            print(format, StringUtils.substring(node.hostname(), 0, HOSTNAME_LENGTH - MARGIN_LENGTH), node.type(), StringUtils.substring(node.managementIp().toString(), 0, MANAGEMENT_IP_LENGTH - MARGIN_LENGTH), node.dataIp() != null ? StringUtils.substring(node.dataIp().toString(), 0, DATA_IP_LENGTH - MARGIN_LENGTH) : "", node.state());
        }
        print("Total %s nodes", nodeService.nodes().size());
    }
}
Also used : K8sNode(org.onosproject.k8snode.api.K8sNode) K8sNodeService(org.onosproject.k8snode.api.K8sNodeService) K8sNodeUtil.genFormatString(org.onosproject.k8snode.util.K8sNodeUtil.genFormatString)

Example 20 with K8sNode

use of org.onosproject.k8snode.api.K8sNode in project onos by opennetworkinglab.

the class K8sNodeListCommand method json.

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

Aggregations

K8sNode (org.onosproject.k8snode.api.K8sNode)40 Path (javax.ws.rs.Path)8 Produces (javax.ws.rs.Produces)8 DefaultK8sNode (org.onosproject.k8snode.api.DefaultK8sNode)8 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)8 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)8 TrafficSelector (org.onosproject.net.flow.TrafficSelector)8 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)8 IpAddress (org.onlab.packet.IpAddress)6 ApplicationId (org.onosproject.core.ApplicationId)6 CoreService (org.onosproject.core.CoreService)6 DeviceId (org.onosproject.net.DeviceId)6 Objects (java.util.Objects)5 Set (java.util.Set)5 ExecutorService (java.util.concurrent.ExecutorService)5 Executors.newSingleThreadExecutor (java.util.concurrent.Executors.newSingleThreadExecutor)5 Consumes (javax.ws.rs.Consumes)5 Tools.groupedThreads (org.onlab.util.Tools.groupedThreads)5 ClusterService (org.onosproject.cluster.ClusterService)5 LeadershipService (org.onosproject.cluster.LeadershipService)5