Search in sources :

Example 1 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 2 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 3 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 4 with K8sHost

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

the class K8sHostManager method removeHost.

@Override
public K8sHost removeHost(IpAddress hostIp) {
    checkArgument(hostIp != null, ERR_NULL_HOST_IP);
    K8sHost host = hostStore.removeHost(hostIp);
    log.info(String.format(MSG_HOST, hostIp.toString(), MSG_REMOVED));
    return host;
}
Also used : K8sHost(org.onosproject.k8snode.api.K8sHost)

Example 5 with K8sHost

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

the class K8sNodeWebResource method addNodesToHost.

/**
 * Add a set of new nodes into the existing host.
 *
 * @param hostIp host IP address
 * @param input kubernetes node names JSON input stream
 * @return 200 UPDATED if the JSON is correct, 400 BAD_REQUEST if the JSON
 * is malformed
 * @onos.rsModel K8sNodeNames
 */
@PUT
@Path("host/add/nodes/{hostIp}")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response addNodesToHost(@PathParam("hostIp") String hostIp, InputStream input) {
    log.trace(String.format(MESSAGE_HOST, UPDATE));
    Set<String> newNodeNames = readNodeNamesConfiguration(input);
    K8sHost host = hostAdminService.host(IpAddress.valueOf(hostIp));
    Set<String> existNodeNames = host.nodeNames();
    existNodeNames.addAll(newNodeNames);
    K8sHost updated = host.updateNodeNames(existNodeNames);
    hostAdminService.updateHost(updated);
    return Response.ok().build();
}
Also used : K8sHost(org.onosproject.k8snode.api.K8sHost) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) INDENT_OUTPUT(com.fasterxml.jackson.databind.SerializationFeature.INDENT_OUTPUT) PUT(javax.ws.rs.PUT)

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