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);
}
}
}
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);
}
}
}
}
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);
}
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;
}
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();
}
Aggregations