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