Search in sources :

Example 1 with K8sNode

use of org.onosproject.k8snode.api.K8sNode in project onos by opennetworkinglab.

the class K8sSyncRulesCommand method syncRulesBaseForNode.

private void syncRulesBaseForNode(K8sNodeAdminService adminService, K8sNode k8sNode) {
    K8sNode updated = k8sNode.updateState(INIT);
    adminService.updateNode(updated);
    boolean result = true;
    long timeoutExpiredMs = System.currentTimeMillis() + TIMEOUT_MS;
    while (adminService.node(k8sNode.hostname()).state() != COMPLETE) {
        long waitMs = timeoutExpiredMs - System.currentTimeMillis();
        try {
            sleep(SLEEP_MS);
        } catch (InterruptedException e) {
            error("Exception caused during node synchronization...");
        }
        if (adminService.node(k8sNode.hostname()).state() == COMPLETE) {
            break;
        } else {
            adminService.updateNode(updated);
            print("Failed to synchronize flow rules, retrying...");
        }
        if (waitMs <= 0) {
            result = false;
            break;
        }
    }
    if (result) {
        print(SUCCESS_MSG, k8sNode.hostname());
    } else {
        error(FAIL_MSG, k8sNode.hostname());
    }
}
Also used : K8sNode(org.onosproject.k8snode.api.K8sNode)

Example 2 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 3 with K8sNode

use of org.onosproject.k8snode.api.K8sNode in project onos by opennetworkinglab.

the class K8sRoutingArpHandler method processArpPacket.

private void processArpPacket(PacketContext context, Ethernet ethernet) {
    DeviceId deviceId = context.inPacket().receivedFrom().deviceId();
    if (!allK8sDevices(k8sNodeService, k8sHostService).contains(deviceId)) {
        return;
    }
    ARP arp = (ARP) ethernet.getPayload();
    if (arp.getOpCode() == ARP.OP_REPLY) {
        IpAddress spa = Ip4Address.valueOf(arp.getSenderProtocolAddress());
        MacAddress sha = MacAddress.valueOf(arp.getSenderHardwareAddress());
        log.info("ARP reply from ip: {}, mac: {}", spa, sha);
        Set<IpAddress> gatewayIps = k8sNodeService.completeNodes().stream().map(K8sNode::extGatewayIp).collect(Collectors.toSet());
        if (!gatewayIps.contains(spa)) {
            return;
        }
        log.info("ARP reply from external gateway ip: {}, mac: {}", spa, sha);
        k8sNodeService.completeNodes().stream().filter(n -> n.extGatewayMac() == null).forEach(n -> {
            K8sNode updated = n.updateExtGatewayMac(sha);
            k8sNodeService.updateNode(updated);
        });
    }
}
Also used : CoreService(org.onosproject.core.CoreService) K8sNodeAdminService(org.onosproject.k8snode.api.K8sNodeAdminService) Tools.groupedThreads(org.onlab.util.Tools.groupedThreads) ARP(org.onlab.packet.ARP) K8sNodeListener(org.onosproject.k8snode.api.K8sNodeListener) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) ByteBuffer(java.nio.ByteBuffer) Ethernet(org.onlab.packet.Ethernet) Component(org.osgi.service.component.annotations.Component) TrafficSelector(org.onosproject.net.flow.TrafficSelector) EXT_ENTRY_TABLE(org.onosproject.k8snetworking.api.Constants.EXT_ENTRY_TABLE) ApplicationId(org.onosproject.core.ApplicationId) Thread.sleep(java.lang.Thread.sleep) K8sNodeEvent(org.onosproject.k8snode.api.K8sNodeEvent) Activate(org.osgi.service.component.annotations.Activate) K8sNode(org.onosproject.k8snode.api.K8sNode) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) ExecutorService(java.util.concurrent.ExecutorService) K8S_NETWORKING_APP_ID(org.onosproject.k8snetworking.api.Constants.K8S_NETWORKING_APP_ID) IpAddress(org.onlab.packet.IpAddress) NodeId(org.onosproject.cluster.NodeId) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) Ip4Address(org.onlab.packet.Ip4Address) Logger(org.slf4j.Logger) Deactivate(org.osgi.service.component.annotations.Deactivate) VlanId(org.onlab.packet.VlanId) PacketProcessor(org.onosproject.net.packet.PacketProcessor) PRIORITY_ARP_REPLY_RULE(org.onosproject.k8snetworking.api.Constants.PRIORITY_ARP_REPLY_RULE) Set(java.util.Set) K8sFlowRuleService(org.onosproject.k8snetworking.api.K8sFlowRuleService) PacketService(org.onosproject.net.packet.PacketService) Executors.newSingleThreadExecutor(java.util.concurrent.Executors.newSingleThreadExecutor) Collectors(java.util.stream.Collectors) K8sHostAdminService(org.onosproject.k8snode.api.K8sHostAdminService) ReferenceCardinality(org.osgi.service.component.annotations.ReferenceCardinality) Objects(java.util.Objects) PRIORITY_ARP_POD_RULE(org.onosproject.k8snetworking.api.Constants.PRIORITY_ARP_POD_RULE) InboundPacket(org.onosproject.net.packet.InboundPacket) PacketContext(org.onosproject.net.packet.PacketContext) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) K8sNetworkingUtil.allK8sDevices(org.onosproject.k8snetworking.util.K8sNetworkingUtil.allK8sDevices) MacAddress(org.onlab.packet.MacAddress) ClusterService(org.onosproject.cluster.ClusterService) DeviceId(org.onosproject.net.DeviceId) Reference(org.osgi.service.component.annotations.Reference) LeadershipService(org.onosproject.cluster.LeadershipService) DefaultOutboundPacket(org.onosproject.net.packet.DefaultOutboundPacket) K8sNode(org.onosproject.k8snode.api.K8sNode) DeviceId(org.onosproject.net.DeviceId) IpAddress(org.onlab.packet.IpAddress) MacAddress(org.onlab.packet.MacAddress) ARP(org.onlab.packet.ARP)

Example 4 with K8sNode

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

Example 5 with K8sNode

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

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