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