Search in sources :

Example 21 with K8sNode

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);
    }
}
Also used : K8sNode(org.onosproject.k8snode.api.K8sNode) K8sRouterBridge(org.onosproject.k8snode.api.K8sRouterBridge) K8sTunnelBridge(org.onosproject.k8snode.api.K8sTunnelBridge)

Example 22 with K8sNode

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);
    }
}
Also used : K8sNode(org.onosproject.k8snode.api.K8sNode) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) FlowRule(org.onosproject.net.flow.FlowRule) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) PortNumber(org.onosproject.net.PortNumber)

Example 23 with K8sNode

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.");
}
Also used : K8sNode(org.onosproject.k8snode.api.K8sNode) K8sNodeService(org.onosproject.k8snode.api.K8sNodeService) K8sNodeAdminService(org.onosproject.k8snode.api.K8sNodeAdminService)

Example 24 with K8sNode

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.");
    }
}
Also used : Group(org.onosproject.net.group.Group) K8sNode(org.onosproject.k8snode.api.K8sNode) K8sNodeService(org.onosproject.k8snode.api.K8sNodeService) CoreService(org.onosproject.core.CoreService) FlowRuleService(org.onosproject.net.flow.FlowRuleService) ApplicationId(org.onosproject.core.ApplicationId) GroupService(org.onosproject.net.group.GroupService)

Example 25 with K8sNode

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);
    });
}
Also used : K8sNode(org.onosproject.k8snode.api.K8sNode) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment)

Aggregations

K8sNode (org.onosproject.k8snode.api.K8sNode)40 Path (javax.ws.rs.Path)8 Produces (javax.ws.rs.Produces)8 DefaultK8sNode (org.onosproject.k8snode.api.DefaultK8sNode)8 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)8 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)8 TrafficSelector (org.onosproject.net.flow.TrafficSelector)8 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)8 IpAddress (org.onlab.packet.IpAddress)6 ApplicationId (org.onosproject.core.ApplicationId)6 CoreService (org.onosproject.core.CoreService)6 DeviceId (org.onosproject.net.DeviceId)6 Objects (java.util.Objects)5 Set (java.util.Set)5 ExecutorService (java.util.concurrent.ExecutorService)5 Executors.newSingleThreadExecutor (java.util.concurrent.Executors.newSingleThreadExecutor)5 Consumes (javax.ws.rs.Consumes)5 Tools.groupedThreads (org.onlab.util.Tools.groupedThreads)5 ClusterService (org.onosproject.cluster.ClusterService)5 LeadershipService (org.onosproject.cluster.LeadershipService)5