use of org.onosproject.k8snode.api.K8sNode in project onos by opennetworkinglab.
the class DefaultK8sHostHandler method processDeviceCreatedState.
@Override
public void processDeviceCreatedState(K8sHost k8sHost) {
try {
if (!isOvsdbConnected(k8sHost, ovsdbPortNum, ovsdbController, deviceService)) {
ovsdbController.connect(k8sHost.hostIp(), tpPort(ovsdbPortNum));
return;
}
// create patch ports into tunnel bridge face to integration bridge
for (K8sTunnelBridge bridge : k8sHost.tunBridges()) {
for (String node : k8sHost.nodeNames()) {
K8sNode k8sNode = k8sNodeAdminService.node(node);
if (k8sNode.segmentId() == bridge.tunnelId()) {
createTunnelPatchInterfaces(k8sHost.ovsdb(), bridge, k8sNode);
createInterPatchInterfaces(k8sHost.ovsdb(), k8sNode);
}
}
}
// create tunnel ports
for (K8sTunnelBridge bridge : k8sHost.tunBridges()) {
if (!isTunPortEnabled(bridge, bridge.vxlanPortName())) {
createVxlanTunnelInterface(k8sHost.ovsdb(), bridge);
}
if (!isTunPortEnabled(bridge, bridge.grePortName())) {
createGreTunnelInterface(k8sHost.ovsdb(), bridge);
}
if (!isTunPortEnabled(bridge, bridge.genevePortName())) {
createGeneveTunnelInterface(k8sHost.ovsdb(), bridge);
}
}
// create patch ports into router bridge face to external bridge
for (K8sRouterBridge bridge : k8sHost.routerBridges()) {
for (String node : k8sHost.nodeNames()) {
K8sNode k8sNode = k8sNodeAdminService.node(node);
if (k8sNode.segmentId() == bridge.segmentId()) {
createRouterPatchInterfaces(k8sHost.ovsdb(), bridge, k8sNode);
}
}
}
} catch (Exception e) {
log.error("Exception occurred because of {}", e);
}
}
use of org.onosproject.k8snode.api.K8sNode in project onos by opennetworkinglab.
the class K8sFlowRuleManager method setAnyRoutingRule.
private void setAnyRoutingRule(IpPrefix srcIpPrefix, MacAddress mac, K8sNetwork k8sNetwork) {
TrafficSelector.Builder sBuilder = DefaultTrafficSelector.builder().matchEthType(Ethernet.TYPE_IPV4).matchIPSrc(srcIpPrefix).matchIPDst(IpPrefix.valueOf(k8sNetwork.cidr()));
for (K8sNode node : k8sNodeService.completeNodes()) {
TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder().setTunnelId(Long.valueOf(k8sNetwork.segmentId()));
if (node.hostname().equals(k8sNetwork.name())) {
if (mac != null) {
tBuilder.setEthSrc(mac);
}
tBuilder.transition(STAT_EGRESS_TABLE);
} else {
K8sNode localNode = k8sNodeService.node(k8sNetwork.name());
tBuilder.setOutput(node.intgToTunPortNum());
// install flows into tunnel bridge
PortNumber portNum = tunnelPortNumByNetId(k8sNetwork.networkId(), k8sNetworkService, node);
TrafficTreatment treatmentToRemote = DefaultTrafficTreatment.builder().extension(buildExtension(deviceService, node.tunBridge(), localNode.dataIp().getIp4Address()), node.tunBridge()).setTunnelId(Long.valueOf(k8sNetwork.segmentId())).setOutput(portNum).build();
FlowRule remoteFlowRule = DefaultFlowRule.builder().forDevice(node.tunBridge()).withSelector(sBuilder.build()).withTreatment(treatmentToRemote).withPriority(PRIORITY_CIDR_RULE).fromApp(appId).makePermanent().forTable(TUN_ENTRY_TABLE).build();
applyRule(remoteFlowRule, true);
}
FlowRule flowRule = DefaultFlowRule.builder().forDevice(node.intgBridge()).withSelector(sBuilder.build()).withTreatment(tBuilder.build()).withPriority(PRIORITY_CIDR_RULE).fromApp(appId).makePermanent().forTable(ROUTING_TABLE).build();
applyRule(flowRule, true);
}
}
use of org.onosproject.k8snode.api.K8sNode in project onos by opennetworkinglab.
the class K8sNodeInitCommand method doExecute.
@Override
protected void doExecute() {
K8sNodeService nodeService = get(K8sNodeService.class);
K8sNodeAdminService nodeAdminService = get(K8sNodeAdminService.class);
if ((!isAll && !isIncomplete && hostnames == null) || (isAll && isIncomplete) || (isIncomplete && hostnames != null) || (hostnames != null && isAll)) {
print("Please specify one of hostname, --all, and --incomplete options.");
return;
}
if (isAll) {
hostnames = nodeService.nodes().stream().map(K8sNode::hostname).toArray(String[]::new);
} else if (isIncomplete) {
hostnames = nodeService.nodes().stream().filter(node -> node.state() != COMPLETE).map(K8sNode::hostname).toArray(String[]::new);
}
for (String hostname : hostnames) {
K8sNode node = nodeService.node(hostname);
if (node == null) {
print("Unable to find %s", hostname);
continue;
}
print("Initializing %s", hostname);
K8sNode updated = node.updateState(INIT);
nodeAdminService.updateNode(updated);
}
print("Done.");
}
use of org.onosproject.k8snode.api.K8sNode in project onos by opennetworkinglab.
the class K8sPurgeRulesCommand method doExecute.
@Override
protected void doExecute() {
FlowRuleService flowRuleService = get(FlowRuleService.class);
GroupService groupService = get(GroupService.class);
CoreService coreService = get(CoreService.class);
K8sNodeService k8sNodeService = get(K8sNodeService.class);
ApplicationId appId = coreService.getAppId(K8S_NETWORKING_APP_ID);
if (appId == null) {
error("Failed to purge kubernetes networking flow rules.");
return;
}
flowRuleService.removeFlowRulesById(appId);
print("Successfully purged flow rules installed by kubernetes networking app.");
boolean result = true;
long timeoutExpiredMs = System.currentTimeMillis() + TIMEOUT_MS;
// we make sure all flow rules are removed from the store
while (stream(flowRuleService.getFlowEntriesById(appId).spliterator(), false).count() > 0) {
long waitMs = timeoutExpiredMs - System.currentTimeMillis();
try {
sleep(SLEEP_MS);
} catch (InterruptedException e) {
log.error("Exception caused during rule purging...");
}
if (stream(flowRuleService.getFlowEntriesById(appId).spliterator(), false).count() == 0) {
break;
} else {
flowRuleService.removeFlowRulesById(appId);
print("Failed to purging flow rules, retrying rule purging...");
}
if (waitMs <= 0) {
result = false;
break;
}
}
for (K8sNode node : k8sNodeService.completeNodes()) {
for (Group group : groupService.getGroups(node.intgBridge(), appId)) {
groupService.removeGroup(node.intgBridge(), group.appCookie(), appId);
}
}
if (result) {
print("Successfully purged flow rules!");
} else {
error("Failed to purge flow rules.");
}
}
use of org.onosproject.k8snode.api.K8sNode in project onos by opennetworkinglab.
the class K8sServiceHandler method setCidrRoutingRule.
private void setCidrRoutingRule(IpPrefix prefix, MacAddress mac, K8sNetwork network, boolean install) {
TrafficSelector.Builder sBuilder = DefaultTrafficSelector.builder().matchEthType(Ethernet.TYPE_IPV4).matchIPSrc(prefix).matchIPDst(IpPrefix.valueOf(network.cidr()));
Set<K8sNode> nodes = install ? k8sNodeService.completeNodes() : k8sNodeService.nodes();
nodes.forEach(n -> {
TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder().setTunnelId(Long.valueOf(network.segmentId()));
if (n.hostname().equals(network.name())) {
if (mac != null) {
tBuilder.setEthSrc(mac);
}
tBuilder.transition(STAT_EGRESS_TABLE);
// install rules into tunnel bridge
TrafficTreatment treatment = DefaultTrafficTreatment.builder().setOutput(n.tunToIntgPortNum()).build();
k8sFlowRuleService.setRule(appId, n.tunBridge(), sBuilder.build(), treatment, PRIORITY_CIDR_RULE, TUN_ENTRY_TABLE, install);
} else {
tBuilder.setOutput(n.intgToTunPortNum());
}
k8sFlowRuleService.setRule(appId, n.intgBridge(), sBuilder.build(), tBuilder.build(), PRIORITY_CIDR_RULE, ROUTING_TABLE, install);
});
}
Aggregations