Search in sources :

Example 6 with K8sHost

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

the class K8sRoutingSnatHandler method setRouterSnatRules.

private void setRouterSnatRules(K8sNode k8sNode, boolean install) {
    for (K8sHost host : k8sHostService.completeHosts()) {
        if (host.nodeNames().contains(k8sNode.hostname())) {
            K8sRouterBridge bridge = host.routerBridges().stream().filter(b -> b.segmentId() == k8sNode.segmentId()).findAny().orElse(null);
            if (bridge != null) {
                setRouterSnatUpstreamRule(k8sNode, bridge, install);
                setRouterSnatDownstreamRule(k8sNode, bridge, install);
            }
        }
    }
}
Also used : K8sHost(org.onosproject.k8snode.api.K8sHost) K8sRouterBridge(org.onosproject.k8snode.api.K8sRouterBridge)

Example 7 with K8sHost

use of org.onosproject.k8snode.api.K8sHost 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 8 with K8sHost

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

the class DefaultK8sHostHandler method setState.

/**
 * Configures the kubernetes host with new state.
 *
 * @param k8sHost       kubernetes host
 * @param newState      a new state
 */
private void setState(K8sHost k8sHost, K8sHostState newState) {
    if (k8sHost.state() == newState) {
        return;
    }
    K8sHost updated = k8sHost.updateState(newState);
    k8sHostAdminService.updateHost(updated);
    log.info("Changed {} state: {}", k8sHost.hostIp(), newState);
}
Also used : K8sHost(org.onosproject.k8snode.api.K8sHost)

Example 9 with K8sHost

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

the class K8sHostListCommand method json.

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

Example 10 with K8sHost

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

the class K8sHostListCommand method doExecute.

@Override
protected void doExecute() {
    K8sHostService hostService = get(K8sHostService.class);
    List<K8sHost> hosts = Lists.newArrayList(hostService.hosts());
    hosts.sort(Comparator.comparing(K8sHost::hostIp));
    String format = genFormatString(ImmutableList.of(HOST_IP_LENGTH, TUNBRS_LENGTH, RTRBRS_LENGTH, STATUS_LENGTH));
    if (outputJson()) {
        print("%s", json(hosts));
    } else {
        print(format, "Host IP", "Tunnel Bridges", "Router Bridges", "State");
        for (K8sHost host : hosts) {
            print(format, host.hostIp().toString(), host.tunBridges().stream().map(K8sTunnelBridge::name).collect(Collectors.toSet()).toString(), host.routerBridges().stream().map(K8sRouterBridge::name).collect(Collectors.toSet()).toString(), host.state().toString());
        }
        print("Total %s hosts", hosts.size());
    }
}
Also used : K8sHost(org.onosproject.k8snode.api.K8sHost) K8sHostService(org.onosproject.k8snode.api.K8sHostService) K8sNodeUtil.genFormatString(org.onosproject.k8snode.util.K8sNodeUtil.genFormatString)

Aggregations

K8sHost (org.onosproject.k8snode.api.K8sHost)19 DefaultK8sHost (org.onosproject.k8snode.api.DefaultK8sHost)6 Test (org.junit.Test)5 Consumes (javax.ws.rs.Consumes)4 Path (javax.ws.rs.Path)4 Produces (javax.ws.rs.Produces)4 K8sHostJsonMatcher.matchesK8sHost (org.onosproject.k8snode.codec.K8sHostJsonMatcher.matchesK8sHost)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 INDENT_OUTPUT (com.fasterxml.jackson.databind.SerializationFeature.INDENT_OUTPUT)2 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2 HashSet (java.util.HashSet)2 PUT (javax.ws.rs.PUT)2 K8sHostService (org.onosproject.k8snode.api.K8sHostService)2 K8sRouterBridge (org.onosproject.k8snode.api.K8sRouterBridge)2 K8sTunnelBridge (org.onosproject.k8snode.api.K8sTunnelBridge)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ContainerPort (io.fabric8.kubernetes.api.model.ContainerPort)1 InputStream (java.io.InputStream)1 DELETE (javax.ws.rs.DELETE)1